Index: branches/5.2.x/units/coupons/coupons_event_handler.php =================================================================== diff -u -N -r14677 -r14986 --- branches/5.2.x/units/coupons/coupons_event_handler.php (.../coupons_event_handler.php) (revision 14677) +++ branches/5.2.x/units/coupons/coupons_event_handler.php (.../coupons_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('self' => true), - 'OnApplyClone' => Array('self' => 'add'), - 'OnPrepareClone' => Array('self' => 'view'), + + $permissions = Array ( + 'OnItemBuild' => Array ('self' => true), + 'OnApplyClone' => Array ('self' => 'add'), + 'OnPrepareClone' => Array ('self' => 'view'), ); $this->permMapping = array_merge($this->permMapping, $permissions); Index: branches/5.2.x/units/affiliate_payment_types/affiliate_payment_types_event_handler.php =================================================================== diff -u -N -r14625 -r14986 --- branches/5.2.x/units/affiliate_payment_types/affiliate_payment_types_event_handler.php (.../affiliate_payment_types_event_handler.php) (revision 14625) +++ branches/5.2.x/units/affiliate_payment_types/affiliate_payment_types_event_handler.php (.../affiliate_payment_types_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Application->isAdmin ) { $object =& $event->getObject(); /* @var $object kDBList */ @@ -41,6 +43,8 @@ function OnSetPrimary(&$event) { $object =& $event->getObject(); + /* @var $object kDBItem */ + $object->SetDBField('IsPrimary', 1); $object->Update(); } Index: branches/5.2.x/units/product_options/product_options_event_handler.php =================================================================== diff -u -N -r14625 -r14986 --- branches/5.2.x/units/product_options/product_options_event_handler.php (.../product_options_event_handler.php) (revision 14625) +++ branches/5.2.x/units/product_options/product_options_event_handler.php (.../product_options_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ getObject(); $selectable_only = $event->getEventParam('selectable_only'); - if ($selectable_only) { + + if ( $selectable_only ) { + $object =& $event->getObject(); + /* @var $object kDBList */ + $object->addFilter('types_filter', 'OptionType IN (1,3,6)'); } - } /** Index: branches/5.2.x/units/product_option_combinations/product_option_combinations_event_handler.php =================================================================== diff -u -N -r14957 -r14986 --- branches/5.2.x/units/product_option_combinations/product_option_combinations_event_handler.php (.../product_option_combinations_event_handler.php) (revision 14957) +++ branches/5.2.x/units/product_option_combinations/product_option_combinations_event_handler.php (.../product_option_combinations_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ getObject(); - $this->dbBuild($object,$event); + /* @var $object kDBItem */ + $this->dbBuild($object, $event); + $sql = $this->ItemPrepareQuery($event); $sql = $this->Application->ReplaceLanguageTags($sql); $object->setSelectSQL($sql); // 2. loads if allowed - $auto_load = $this->Application->getUnitOption($event->Prefix,'AutoLoad'); - $skip_autload = $event->getEventParam('skip_autoload'); + $auto_load = $this->Application->getUnitOption($event->Prefix, 'AutoLoad'); + $skip_autoload = $event->getEventParam('skip_autoload'); - if($auto_load && !$skip_autload) $this->LoadItem($event); + if ( $auto_load && !$skip_autoload ) { + $this->LoadItem($event); + } $actions =& $this->Application->recallObject('kActions'); - $actions->Set($event->getPrefixSpecial().'_GoTab', ''); + /* @var $actions Params */ - $actions->Set($event->getPrefixSpecial().'_GoId', ''); + $actions->Set($event->getPrefixSpecial() . '_GoTab', ''); + $actions->Set($event->getPrefixSpecial() . '_GoId', ''); } /** @@ -259,7 +266,7 @@ * @return void * @access protected */ - protected function LoadItem(&$event) + protected function LoadItem(kEvent &$event) { $object =& $event->getObject(); /* @var $object kDBItem */ @@ -269,7 +276,7 @@ if ( !$id ) { $event->CallSubEvent('OnNew'); - return ; + return; } if ( $object->Load($id) ) { @@ -281,21 +288,24 @@ } /** - * Get's special of main item for linking with subitem + * Returns special of main item for linking with sub-item * * @param kEvent $event * @return string + * @access protected */ - function getMainSpecial(&$event) + protected function getMainSpecial(kEvent &$event) { $special = $event->getEventParam('main_special'); - if($special === false || $special == '$main_special') - { + + if ( $special === false || $special == '$main_special' ) { $special = $event->Special; } - if ($special == 'grid') { + + if ( $special == 'grid' ) { $special = ''; } + return $special; } Index: branches/5.2.x/units/affiliate_payments/affiliate_payments_event_handler.php =================================================================== diff -u -N -r14655 -r14986 --- branches/5.2.x/units/affiliate_payments/affiliate_payments_event_handler.php (.../affiliate_payments_event_handler.php) (revision 14655) +++ branches/5.2.x/units/affiliate_payments/affiliate_payments_event_handler.php (.../affiliate_payments_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Special == 'log' ) { return ; @@ -103,28 +103,29 @@ * @access protected * @see kDBEventHandler::OnListBuild() */ - protected function SetCustomQuery(&$event) + protected function SetCustomQuery(kEvent &$event) { + parent::SetCustomQuery($event); + $object =& $event->getObject(); - if($event->Special == 'log') - { + /* @var $object kDBList */ + + if ( $event->Special == 'log' ) { $object->removeFilter('parent_filter'); } $types = $event->getEventParam('types'); - if ($types=='my_payments') - { + if ( $types == 'my_payments' ) { $user_id = $this->Application->RecallVar('user_id'); $object->removeFilter('parent_filter'); - $object->addFilter('my_payments', 'au.PortalUserId = '.$user_id); + $object->addFilter('my_payments', 'au.PortalUserId = ' . $user_id); } - if ($types=='myvisitororders') - { + if ( $types == 'myvisitororders' ) { $user_id = $this->Application->RecallVar('user_id'); - $object->addFilter('myitems_orders','ord.OrderId IS NOT NULL'); - $object->addFilter('myitems_user1','au.PortalUserId = '.$user_id); - $object->addFilter('myitems_user2','au.PortalUserId > 0'); + $object->addFilter('myitems_orders', 'ord.OrderId IS NOT NULL'); + $object->addFilter('myitems_user1', 'au.PortalUserId = ' . $user_id); + $object->addFilter('myitems_user2', 'au.PortalUserId > 0'); } } Index: branches/5.2.x/units/coupon_items/coupon_items_event_handler.php =================================================================== diff -u -N -r14849 -r14986 --- branches/5.2.x/units/coupon_items/coupon_items_event_handler.php (.../coupon_items_event_handler.php) (revision 14849) +++ branches/5.2.x/units/coupon_items/coupon_items_event_handler.php (.../coupon_items_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('subitem' => 'add|edit'), - ); + + $permissions = Array ( + 'OnEntireOrder' => Array ('subitem' => 'add|edit'), + ); + $this->permMapping = array_merge($this->permMapping, $permissions); } Index: branches/5.2.x/units/affiliates/affiliates_event_handler.php =================================================================== diff -u -N -r14767 -r14986 --- branches/5.2.x/units/affiliates/affiliates_event_handler.php (.../affiliates_event_handler.php) (revision 14767) +++ branches/5.2.x/units/affiliates/affiliates_event_handler.php (.../affiliates_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array ('self' => true), ); @@ -37,7 +40,7 @@ * @return bool * @access public */ - public function CheckPermission(&$event) + public function CheckPermission(kEvent &$event) { if ( $event->Name == 'OnBecomeAffiliate' || $event->Name == 'OnChangePaymentType' ) { return $this->Application->LoggedIn() && $this->Application->ConfigValue('Comm_RegisterAsAffiliate'); @@ -51,17 +54,18 @@ * * @param kEvent $event * @return int + * @access public */ - function getPassedID(&$event) + public function getPassedID(kEvent &$event) { if ( $event->Special == 'user' ) { $event->setEventParam('raise_warnings', 0); - + $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' WHERE PortalUserId = ' . (int)$this->Application->RecallVar('user_id'); $id = $this->Conn->GetOne($sql); - + if ( $id ) { return $id; } @@ -163,17 +167,17 @@ function OnStoreAffiliate(&$event) { $event->Init($event->Prefix, '-item'); - $object =& $event->getObject( Array('skip_autoload'=>true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); + /* @var $object kDBItem */ + $affiliate_storage_method = $this->Application->ConfigValue('Comm_AffiliateStorageMethod'); $affiliate = $this->Application->GetVar('affiliate'); - if($affiliate) - { + if ( $affiliate ) { $object->Load($affiliate, 'AffiliateCode'); } - elseif($affiliate_storage_method == 2) - { + elseif ( $affiliate_storage_method == 2 ) { $affiliate_id = $this->Application->GetVar('affiliate_id'); $object->Load($affiliate_id); } @@ -221,26 +225,32 @@ */ function OnOrderApprove(&$event) { - $order =& $this->Application->recallObject( $event->getEventParam('Order_PrefixSpecial') ); + $order =& $this->Application->recallObject($event->getEventParam('Order_PrefixSpecial')); + /* @var $order OrdersItem */ + $affiliate_id = $order->GetDBField('AffiliateId'); - if(!$affiliate_id) return false; + if ( !$affiliate_id ) { + return false; + } - $object =& $event->getObject( Array('ship_autoload' => true) ); - if( $object->Load($affiliate_id) ) - { - $affiliate_plan =& $this->Application->recallObject('ap', null, Array('skip_autoload'=>true) ); - $affiliate_plan->Load( $object->GetDBField('AffiliatePlanId') ); - if( $affiliate_plan->isLoaded() ) - { + $object =& $event->getObject(Array ('ship_autoload' => true)); + /* @var $object kDBItem */ + + if ( $object->Load($affiliate_id) ) { + $affiliate_plan =& $this->Application->recallObject('ap', null, Array ('skip_autoload' => true)); + /* @var $affiliate_plan kDBItem */ + + $affiliate_plan->Load($object->GetDBField('AffiliatePlanId')); + + if ( $affiliate_plan->isLoaded() ) { $sql = 'SELECT SUM(Quantity) FROM %s WHERE OrderId = %s'; $orderitems_table = $this->Application->getUnitOption('orditems', 'TableName'); - $items_sold = $this->Conn->GetOne( sprintf($sql, $orderitems_table, $order->GetID() ) ); + $items_sold = $this->Conn->GetOne(sprintf($sql, $orderitems_table, $order->GetID())); - $object->SetDBField('AccumulatedAmount', $object->GetDBField('AccumulatedAmount') + $order->GetDBField('TotalAmount') ); + $object->SetDBField('AccumulatedAmount', $object->GetDBField('AccumulatedAmount') + $order->GetDBField('TotalAmount')); $object->SetDBField('ItemsSold', $object->GetDBField('ItemsSold') + $items_sold); - switch( $affiliate_plan->GetDBField('PlanType') ) - { + switch ($affiliate_plan->GetDBField('PlanType')) { case 1: // by amount $value = $object->GetDBField('AccumulatedAmount'); break; @@ -252,32 +262,33 @@ $apb_table = $this->Application->getUnitOption('apbrackets', 'TableName'); $sql = 'SELECT Percent FROM %1$s WHERE (%2$s >= FromAmount) AND ( (%2$s <= ToAmount) OR (ToAmount = -1) ) AND (AffiliatePlanId = %3$s)'; - $commission_percent = $this->Conn->GetOne( sprintf($sql, $apb_table, $this->Conn->qstr($value), $affiliate_plan->GetID() ) ); + $commission_percent = $this->Conn->GetOne(sprintf($sql, $apb_table, $this->Conn->qstr($value), $affiliate_plan->GetID())); // process only orders of current affiliate from period start to this order date $period_ends = $order->GetDBField('OrderDate'); - $period_starts = $this->getPeriodStartTS( $period_ends, $affiliate_plan->GetDBField('ResetInterval') ); - $sql = 'SELECT AffiliateCommission, (SubTotal+ShippingCost+VAT) AS TotalAmount, OrderId FROM '.$order->TableName.' WHERE OrderDate >= %s AND OrderDate <= %s AND AffiliateId = ' . $affiliate_id; + $period_starts = $this->getPeriodStartTS($period_ends, $affiliate_plan->GetDBField('ResetInterval')); + $sql = 'SELECT AffiliateCommission, (SubTotal+ShippingCost+VAT) AS TotalAmount, OrderId + FROM ' . $order->TableName . ' + WHERE OrderDate >= %s AND OrderDate <= %s AND AffiliateId = ' . $affiliate_id; + $amount_to_pay_before = 0; $amount_to_pay_after = 0; - $order_update_sql = 'UPDATE '.$order->TableName.' SET AffiliateCommission = %s WHERE '.$order->IDField.' = %s'; - $orders = $this->Conn->Query( sprintf($sql, $period_starts, $period_ends), 'OrderId' ); - if($orders) - { - foreach($orders as $order_id => $order_data) - { + $order_update_sql = 'UPDATE ' . $order->TableName . ' SET AffiliateCommission = %s WHERE ' . $order->IDField . ' = %s'; + $orders = $this->Conn->Query(sprintf($sql, $period_starts, $period_ends), 'OrderId'); + if ( $orders ) { + foreach ($orders as $order_id => $order_data) { $amount_to_pay_before += $order_data['AffiliateCommission']; $commission = $order_data['TotalAmount'] * ($commission_percent / 100); - $this->Conn->Query( sprintf($order_update_sql, $this->Conn->qstr($commission), $order_id) ); + $this->Conn->Query(sprintf($order_update_sql, $this->Conn->qstr($commission), $order_id)); $amount_to_pay_after += $commission; } } - $object->SetDBField('AmountToPay', $object->GetDBField('AmountToPay') - $amount_to_pay_before + $amount_to_pay_after ); - $object->SetDBField('LastOrderDate_date', $order->GetDBField('OrderDate_date') ); - $object->SetDBField('LastOrderDate_time', $order->GetDBField('OrderDate_time') ); + $object->SetDBField('AmountToPay', $object->GetDBField('AmountToPay') - $amount_to_pay_before + $amount_to_pay_after); + $object->SetDBField('LastOrderDate_date', $order->GetDBField('OrderDate_date')); + $object->SetDBField('LastOrderDate_time', $order->GetDBField('OrderDate_time')); $object->Update(); $order->SetDBField('AffiliateCommission', $commission); // set last commission to this order, because ApproveEvent was called for him @@ -297,7 +308,7 @@ if ( $this->Application->GetVar('RegisterAsAffiliate') != 'on' || $event->MasterEvent->status != kEvent::erSUCCESS ) { return; } - + $object =& $event->getObject( Array('form_name' => 'registration', 'skip_autoload' => true) ); /* @var $object kDBItem */ @@ -617,15 +628,18 @@ * * @param kEvent $event * @return bool + * @access protected */ - function checkItemStatus(&$event) + protected function checkItemStatus(kEvent &$event) { - if ($this->Application->isAdminUser) { + if ( $this->Application->isAdminUser ) { return true; } $object =& $event->getObject(); - if (!$object->isLoaded()) { + /* @var $object kDBItem */ + + if ( !$object->isLoaded() ) { return true; } Index: branches/5.2.x/units/discount_items/discount_items_event_handler.php =================================================================== diff -u -N -r14849 -r14986 --- branches/5.2.x/units/discount_items/discount_items_event_handler.php (.../discount_items_event_handler.php) (revision 14849) +++ branches/5.2.x/units/discount_items/discount_items_event_handler.php (.../discount_items_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('subitem' => 'add|edit'), - ); + 'OnEntireOrder' => Array ('subitem' => 'add|edit'), + ); + $this->permMapping = array_merge($this->permMapping, $permissions); } Index: branches/5.2.x/units/order_items/order_items_event_handler.php =================================================================== diff -u -N -r14957 -r14986 --- branches/5.2.x/units/order_items/order_items_event_handler.php (.../order_items_event_handler.php) (revision 14957) +++ branches/5.2.x/units/order_items/order_items_event_handler.php (.../order_items_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Application->isAdmin ) { return true; Index: branches/5.2.x/units/shipping_costs/shipping_costs_event_handler.php =================================================================== diff -u -N -r14872 -r14986 --- branches/5.2.x/units/shipping_costs/shipping_costs_event_handler.php (.../shipping_costs_event_handler.php) (revision 14872) +++ branches/5.2.x/units/shipping_costs/shipping_costs_event_handler.php (.../shipping_costs_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('subitem' => 'add|edit'), - 'OnClearAll' => Array('subitem' => 'add|edit'), - 'OnSaveCreated' => Array('subitem' => 'add|edit'), - ); + 'OnPropagate' => Array('subitem' => 'add|edit'), + 'OnClearAll' => Array('subitem' => 'add|edit'), + 'OnSaveCreated' => Array('subitem' => 'add|edit'), + ); + $this->permMapping = array_merge($this->permMapping, $permissions); } Index: branches/5.2.x/units/reports/reports_event_handler.php =================================================================== diff -u -N -r14723 -r14986 --- branches/5.2.x/units/reports/reports_event_handler.php (.../reports_event_handler.php) (revision 14723) +++ branches/5.2.x/units/reports/reports_event_handler.php (.../reports_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array ('self' => 'view'), 'OnUpdateConfig' => Array ('self' => 'view'), Index: branches/5.2.x/units/payment_type/payment_type_event_handler.php =================================================================== diff -u -N -r14849 -r14986 --- branches/5.2.x/units/payment_type/payment_type_event_handler.php (.../payment_type_event_handler.php) (revision 14849) +++ branches/5.2.x/units/payment_type/payment_type_event_handler.php (.../payment_type_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ 'iterateItems', 'OnMassDecline'=>'OnMassDecline', @@ -31,12 +39,16 @@ /** * Allows to override standard permission mapping * + * @return void + * @access protected + * @see kEventHandler::$permMapping */ - function mapPermissions() + protected function mapPermissions() { parent::mapPermissions(); - $permissions = Array( - 'OnItemBuild' => Array('self' => true), + + $permissions = Array ( + 'OnItemBuild' => Array ('self' => true), ); $this->permMapping = array_merge($this->permMapping, $permissions); @@ -221,10 +233,11 @@ * * @param kEvent $event * @return int + * @access public */ - function getPassedID(&$event) + public function getPassedID(kEvent &$event) { - if ($event->Special == 'auto-ord') { + if ( $event->Special == 'auto-ord' ) { $main_object =& $this->Application->recallObject('ord'); /* @var $main_object kDBItem */ @@ -234,7 +247,7 @@ // returns first matched enabled payment type return Array ( 'Status' => STATUS_ACTIVE, - TABLE_PREFIX . 'Gateways.Name' => $event->getEventParam('gateway'), + TABLE_PREFIX . 'Gateways.Name' => $event->getEventParam('gateway') ); } @@ -249,20 +262,20 @@ * @access protected * @see kDBEventHandler::OnListBuild() */ - protected function SetCustomQuery(&$event) + protected function SetCustomQuery(kEvent &$event) { parent::SetCustomQuery($event); $object =& $event->getObject(); /* @var $object kDBList */ - if (in_array($event->Special, Array ('enabled', 'selected', 'available')) || !$this->Application->isAdminUser) { + if ( in_array($event->Special, Array ('enabled', 'selected', 'available')) || !$this->Application->isAdminUser ) { // "enabled" special or Front-End $object->addFilter('enabled_filter', '%1$s.Status = ' . STATUS_ACTIVE); } // site domain payment type picker - if ($event->Special == 'selected' || $event->Special == 'available') { + if ( $event->Special == 'selected' || $event->Special == 'available' ) { $edit_picker_helper =& $this->Application->recallObject('EditPickerHelper'); /* @var $edit_picker_helper EditPickerHelper */ @@ -272,7 +285,7 @@ // apply domain-based payment type filtering $payment_types = $this->Application->siteDomainField('PaymentTypes'); - if (strlen($payment_types)) { + if ( strlen($payment_types) ) { $payment_types = explode('|', substr($payment_types, 1, -1)); $object->addFilter('domain_filter', '%1$s.PaymentTypeId IN (' . implode(',', $payment_types) . ')'); } Index: branches/5.2.x/units/brackets/brackets_event_handler.php =================================================================== diff -u -N -r14872 -r14986 --- branches/5.2.x/units/brackets/brackets_event_handler.php (.../brackets_event_handler.php) (revision 14872) +++ branches/5.2.x/units/brackets/brackets_event_handler.php (.../brackets_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Application->GetVar('s_id') === false ) { return; Index: branches/5.2.x/units/orders/orders_event_handler.php =================================================================== diff -u -N -r14957 -r14986 --- branches/5.2.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 14957) +++ branches/5.2.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Application->isAdminUser) { - if ($event->Name == 'OnCreate') { + if ( !$this->Application->isAdminUser ) { + if ( $event->Name == 'OnCreate' ) { // user can't initiate custom order creation directly return false; } $user_id = $this->Application->RecallVar('user_id'); $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); - if ($items_info) { + if ( $items_info ) { // when POST is present, then check when is beeing submitted - $order_session_id = $this->Application->RecallVar($event->getPrefixSpecial(true).'_id'); + $order_session_id = $this->Application->RecallVar($event->getPrefixSpecial(true) . '_id'); - $order_dummy =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true)); + $order_dummy =& $this->Application->recallObject($event->Prefix . '.-item', null, Array ('skip_autoload' => true)); /* @var $order_dummy OrdersItem */ foreach ($items_info as $id => $field_values) { - if ($order_session_id != $id) { + if ( $order_session_id != $id ) { // user is trying update not his order, even order from other guest return false; } $order_dummy->Load($id); // session_id matches order_id from submit - if ($order_dummy->GetDBField('PortalUserId') != $user_id) { + if ( $order_dummy->GetDBField('PortalUserId') != $user_id ) { // user performs event on other user order return false; } $status_field = array_shift($this->Application->getUnitOption($event->Prefix, 'StatusField')); - if (isset($field_values[$status_field]) && $order_dummy->GetDBField($status_field) != $field_values[$status_field]) { + if ( isset($field_values[$status_field]) && $order_dummy->GetDBField($status_field) != $field_values[$status_field] ) { // user can't change status by himself return false; } - if ($order_dummy->GetDBField($status_field) != ORDER_STATUS_INCOMPLETE) { + if ( $order_dummy->GetDBField($status_field) != ORDER_STATUS_INCOMPLETE ) { // user can't edit orders being processed return false; } - if ($event->Name == 'OnUpdate') { + if ( $event->Name == 'OnUpdate' ) { // all checks were ok -> it's user's order -> allow to modify return true; } } } } - if ($event->Name == 'OnQuietPreSave') { + if ( $event->Name == 'OnQuietPreSave' ) { $section = $event->getSection(); - if ($this->isNewItemCreate($event)) { - return $this->Application->CheckPermission($section.'.add', 1); + if ( $this->isNewItemCreate($event) ) { + return $this->Application->CheckPermission($section . '.add', 1); } else { - return $this->Application->CheckPermission($section.'.add', 1) || $this->Application->CheckPermission($section.'.edit', 1); + return $this->Application->CheckPermission($section . '.add', 1) || $this->Application->CheckPermission($section . '.edit', 1); } } @@ -90,74 +90,87 @@ /** * Allows to override standard permission mapping * + * @return void + * @access protected + * @see kEventHandler::$permMapping */ - function mapPermissions() + protected function mapPermissions() { parent::mapPermissions(); - $permissions = Array( - // admin - 'OnRecalculateItems' => Array('self' => 'add|edit'), - 'OnResetToUser' => Array('self' => 'add|edit'), - 'OnResetToBilling' => Array('self' => 'add|edit'), - 'OnResetToShipping' => Array('self' => 'add|edit'), - 'OnMassOrderApprove' => Array('self' => 'advanced:approve'), - 'OnMassOrderDeny' => Array('self' => 'advanced:deny'), - 'OnMassOrderArchive' => Array('self' => 'advanced:archive'), - 'OnMassPlaceOrder' => Array('self' => 'advanced:place'), - 'OnMassOrderProcess' => Array('self' => 'advanced:process'), - 'OnMassOrderShip' => Array('self' => 'advanced:ship'), - 'OnResetToPending' => Array('self' => 'advanced:reset_to_pending'), - 'OnLoadSelected' => Array('self' => 'view'), // print in this case - 'OnGoToOrder' => Array('self' => 'view'), - // front-end - 'OnViewCart' => Array('self' => true), - 'OnAddToCart' => Array('self' => true), - 'OnRemoveFromCart' => Array('self' => true), - 'OnUpdateCart' => Array('self' => true), - 'OnUpdateCartJSON' => Array('self' => true), - 'OnUpdateItemOptions' => Array('self' => true), - 'OnCleanupCart' => Array('self' => true), - 'OnContinueShopping' => Array('self' => true), - 'OnCheckout' => Array('self' => true), - 'OnSelectAddress' => Array('self' => true), - 'OnProceedToBilling' => Array('self' => true), - 'OnProceedToPreview' => Array('self' => true), - 'OnCompleteOrder' => Array('self' => true), - 'OnUpdateAjax' => Array('self' => true), + $permissions = Array ( + // admin + 'OnRecalculateItems' => Array('self' => 'add|edit'), + 'OnResetToUser' => Array('self' => 'add|edit'), + 'OnResetToBilling' => Array('self' => 'add|edit'), + 'OnResetToShipping' => Array('self' => 'add|edit'), + 'OnMassOrderApprove' => Array('self' => 'advanced:approve'), + 'OnMassOrderDeny' => Array('self' => 'advanced:deny'), + 'OnMassOrderArchive' => Array('self' => 'advanced:archive'), + 'OnMassPlaceOrder' => Array('self' => 'advanced:place'), + 'OnMassOrderProcess' => Array('self' => 'advanced:process'), + 'OnMassOrderShip' => Array('self' => 'advanced:ship'), + 'OnResetToPending' => Array('self' => 'advanced:reset_to_pending'), + 'OnLoadSelected' => Array('self' => 'view'), // print in this case + 'OnGoToOrder' => Array('self' => 'view'), - 'OnRemoveCoupon' => Array('self' => true), - 'OnRemoveGiftCertificate' => Array('self' => true), + // front-end + 'OnViewCart' => Array('self' => true), + 'OnAddToCart' => Array('self' => true), + 'OnRemoveFromCart' => Array('self' => true), + 'OnUpdateCart' => Array('self' => true), + 'OnUpdateCartJSON' => Array('self' => true), + 'OnUpdateItemOptions' => Array('self' => true), + 'OnCleanupCart' => Array('self' => true), + 'OnContinueShopping' => Array('self' => true), + 'OnCheckout' => Array('self' => true), + 'OnSelectAddress' => Array('self' => true), + 'OnProceedToBilling' => Array('self' => true), + 'OnProceedToPreview' => Array('self' => true), + 'OnCompleteOrder' => Array('self' => true), + 'OnUpdateAjax' => Array('self' => true), - 'OnCancelRecurring' => Array('self' => true), - 'OnAddVirtualProductToCart' => Array('self' => true), - 'OnItemBuild' => Array('self' => true), - 'OnDownloadLabel' => Array('self' => true, 'subitem' => true), + 'OnRemoveCoupon' => Array('self' => true), + 'OnRemoveGiftCertificate' => Array('self' => true), - ); + 'OnCancelRecurring' => Array('self' => true), + 'OnAddVirtualProductToCart' => Array('self' => true), + 'OnItemBuild' => Array('self' => true), + 'OnDownloadLabel' => Array('self' => true, 'subitem' => true), + ); + $this->permMapping = array_merge($this->permMapping, $permissions); } - function mapEvents() + /** + * Define alternative event processing method names + * + * @return void + * @see kEventHandler::$eventMethods + * @access protected + */ + protected function mapEvents() { parent::mapEvents(); - $common_events = Array( - 'OnResetToUser' => 'OnResetAddress', - 'OnResetToBilling' => 'OnResetAddress', - 'OnResetToShipping' => 'OnResetAddress', - 'OnMassOrderProcess' => 'MassInventoryAction', - 'OnMassOrderApprove' => 'MassInventoryAction', - 'OnMassOrderDeny' => 'MassInventoryAction', - 'OnMassOrderArchive' => 'MassInventoryAction', - 'OnMassOrderShip' => 'MassInventoryAction', + $common_events = Array ( + 'OnResetToUser' => 'OnResetAddress', + 'OnResetToBilling' => 'OnResetAddress', + 'OnResetToShipping' => 'OnResetAddress', - 'OnOrderProcess' => 'InventoryAction', - 'OnOrderApprove' => 'InventoryAction', - 'OnOrderDeny' => 'InventoryAction', - 'OnOrderArchive' => 'InventoryAction', - 'OnOrderShip' => 'InventoryAction', - ); + 'OnMassOrderProcess' => 'MassInventoryAction', + 'OnMassOrderApprove' => 'MassInventoryAction', + 'OnMassOrderDeny' => 'MassInventoryAction', + 'OnMassOrderArchive' => 'MassInventoryAction', + 'OnMassOrderShip' => 'MassInventoryAction', + + 'OnOrderProcess' => 'InventoryAction', + 'OnOrderApprove' => 'InventoryAction', + 'OnOrderDeny' => 'InventoryAction', + 'OnOrderArchive' => 'InventoryAction', + 'OnOrderShip' => 'InventoryAction', + ); + $this->eventMethods = array_merge($this->eventMethods, $common_events); } @@ -979,6 +992,18 @@ } /** + * Returns table prefix from event (temp or live) + * + * @param kEvent $event + * @return string + * @todo Needed? Should be refactored (by Alex) + */ + function TablePrefix(kEvent &$event) + { + return $this->UseTempTables($event) ? $this->Application->GetTempTablePrefix('prefix:' . $event->Prefix) . TABLE_PREFIX : TABLE_PREFIX; + } + + /** * Check if required options are selected & selected option combination is in stock * * @param kEvent $event @@ -1286,7 +1311,7 @@ function OnRemoveFromCart(&$event) { $ord_item_id = $this->Application->GetVar('orditems_id'); - $ord_id = $this->getPassedId($event); + $ord_id = $this->getPassedID($event); $this->Conn->Query('DELETE FROM '.TABLE_PREFIX.'OrderItems WHERE OrderId = '.$ord_id.' AND OrderItemId = '.$ord_item_id); $this->OnRecalculateItems($event); } @@ -1310,48 +1335,47 @@ * * @param kEvent $event * @return int + * @access public */ - function getPassedId(&$event) + public function getPassedID(kEvent &$event) { $event->setEventParam('raise_warnings', 0); $passed = parent::getPassedID($event); - if ($this->Application->isAdminUser) { + if ( $this->Application->isAdminUser ) { // work as usual in admin return $passed; } - if ($event->Special == 'last') { + if ( $event->Special == 'last' ) { // return last order id (for using on thank you page) $order_id = $this->Application->RecallVar('front_order_id'); return $order_id > 0 ? $order_id : FAKE_ORDER_ID; // FAKE_ORDER_ID helps to keep parent filter for order items set in "kDBList::linkToParent" } - $ses_id = $this->Application->RecallVar( $event->getPrefixSpecial(true) . '_id' ); - if ($passed && ($passed != $ses_id)) { + $ses_id = $this->Application->RecallVar($event->getPrefixSpecial(true) . '_id'); + + if ( $passed && ($passed != $ses_id) ) { // order id given in url doesn't match our current order id $sql = 'SELECT PortalUserId FROM ' . TABLE_PREFIX . 'Orders WHERE OrderId = ' . $passed; $user_id = $this->Conn->GetOne($sql); - if ($user_id == $this->Application->RecallVar('user_id')) { + if ( $user_id == $this->Application->RecallVar('user_id') ) { // current user is owner of order with given id -> allow him to view order details return $passed; } else { // current user is not owner of given order -> hacking attempt - $this->Application->SetVar($event->getPrefixSpecial().'_id', 0); + $this->Application->SetVar($event->getPrefixSpecial() . '_id', 0); return 0; } } - else { - // not passed or equals to ses_id - return $ses_id > 0 ? $ses_id : FAKE_ORDER_ID; // FAKE_ORDER_ID helps to keep parent filter for order items set in "kDBList::linkToParent" - } - return $passed; + // not passed or equals to ses_id + return $ses_id > 0 ? $ses_id : FAKE_ORDER_ID; // FAKE_ORDER_ID helps to keep parent filter for order items set in "kDBList::linkToParent" } /** @@ -1361,7 +1385,7 @@ * @return void * @access protected */ - protected function LoadItem(&$event) + protected function LoadItem(kEvent &$event) { $id = $this->getPassedID($event); @@ -1373,7 +1397,7 @@ /* @var $object kDBItem */ $object->Clear($id); - return ; + return; } parent::LoadItem($event); @@ -2494,41 +2518,42 @@ * @access protected * @see kDBEventHandler::OnListBuild() */ - protected function SetCustomQuery(&$event) + protected function SetCustomQuery(kEvent &$event) { + parent::SetCustomQuery($event); + $object =& $event->getObject(); /* @var $object kDBList */ $types = $event->getEventParam('types'); - if($types == 'myorders' || $types == 'myrecentorders') - { + if ( $types == 'myorders' || $types == 'myrecentorders' ) { $user_id = $this->Application->RecallVar('user_id'); - $object->addFilter('myitems_user1','%1$s.PortalUserId = '.$user_id); - $object->addFilter('myitems_user2','%1$s.PortalUserId > 0'); - $object->addFilter('Status','%1$s.Status != 0'); + $object->addFilter('myitems_user1', '%1$s.PortalUserId = ' . $user_id); + $object->addFilter('myitems_user2', '%1$s.PortalUserId > 0'); + $object->addFilter('Status', '%1$s.Status != 0'); } else if ($event->Special == 'returns') { // $object->addFilter('returns_filter',TABLE_PREFIX.'Orders.Status = '.ORDER_STATUS_PROCESSED.' AND ( // SELECT SUM(ReturnType) // FROM '.TABLE_PREFIX.'OrderItems oi // WHERE oi.OrderId = '.TABLE_PREFIX.'Orders.OrderId // ) > 0'); - $object->addFilter('returns_filter',TABLE_PREFIX.'Orders.Status = '.ORDER_STATUS_PROCESSED.' AND '.TABLE_PREFIX.'Orders.ReturnTotal > 0'); + $object->addFilter('returns_filter', TABLE_PREFIX . 'Orders.Status = ' . ORDER_STATUS_PROCESSED . ' AND ' . TABLE_PREFIX . 'Orders.ReturnTotal > 0'); } - else if ($event->Special == 'user') { + else if ( $event->Special == 'user' ) { $user_id = $this->Application->GetVar('u_id'); - $object->addFilter('user_filter','%1$s.PortalUserId = '.$user_id); + $object->addFilter('user_filter', '%1$s.PortalUserId = ' . $user_id); } else { $special = $event->Special ? $event->Special : $this->Application->GetVar('order_type'); - if ($special != 'search') { + if ( $special != 'search' ) { // don't filter out orders by special in case of search tab - $object->addFilter( 'status_filter', '%1$s.Status='.$this->getTypeBySpecial($special) ); + $object->addFilter('status_filter', '%1$s.Status=' . $this->getTypeBySpecial($special)); } if ( $event->getEventParam('selected_only') ) { $ids = $this->StoreSelectedIDs($event); - $object->addFilter( 'selected_filter', '%1$s.OrderId IN ('.implode(',', $ids).')'); + $object->addFilter('selected_filter', '%1$s.OrderId IN (' . implode(',', $ids) . ')'); } } } @@ -3766,10 +3791,11 @@ * * @param kEvent $event * @return bool + * @access protected */ - function checkItemStatus(&$event) + protected function checkItemStatus(kEvent &$event) { - if ($this->Application->isAdminUser) { + if ( $this->Application->isAdminUser ) { return true; } Index: branches/5.2.x/units/affiliate_plans_brackets/affiliate_plans_brackets_event_handler.php =================================================================== diff -u -N -r14677 -r14986 --- branches/5.2.x/units/affiliate_plans_brackets/affiliate_plans_brackets_event_handler.php (.../affiliate_plans_brackets_event_handler.php) (revision 14677) +++ branches/5.2.x/units/affiliate_plans_brackets/affiliate_plans_brackets_event_handler.php (.../affiliate_plans_brackets_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('subitem' => 'add|edit'), - 'OnInfinity' => Array('subitem' => 'add|edit'), - 'OnArrange' => Array('subitem' => 'add|edit'), - ); + + $permissions = Array ( + 'OnMoreBrackets' => Array ('subitem' => 'add|edit'), + 'OnInfinity' => Array ('subitem' => 'add|edit'), + 'OnArrange' => Array ('subitem' => 'add|edit'), + ); + $this->permMapping = array_merge($this->permMapping, $permissions); } Index: branches/5.2.x/units/shipping/shipping_event_handler.php =================================================================== diff -u -N -r14702 -r14986 --- branches/5.2.x/units/shipping/shipping_event_handler.php (.../shipping_event_handler.php) (revision 14702) +++ branches/5.2.x/units/shipping/shipping_event_handler.php (.../shipping_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('self' => 'add|edit'), - 'OnApplyModifier' => Array('self' => 'add|edit'), - ); + + $permissions = Array ( + 'OnFlip' => Array ('self' => 'add|edit'), + 'OnApplyModifier' => Array ('self' => 'add|edit'), + ); + $this->permMapping = array_merge($this->permMapping, $permissions); } Index: branches/5.2.x/units/currencies/currencies_event_handler.php =================================================================== diff -u -N -r14849 -r14986 --- branches/5.2.x/units/currencies/currencies_event_handler.php (.../currencies_event_handler.php) (revision 14849) +++ branches/5.2.x/units/currencies/currencies_event_handler.php (.../currencies_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('self' => 'add|edit'), - 'OnUpdateRates' => Array('self' => 'advanced:update_rate|add|edit'), - 'OnDisableUnused' => Array('self' => 'edit'), + 'OnUpdateRate' => Array ('self' => 'add|edit'), + 'OnUpdateRates' => Array ('self' => 'advanced:update_rate|add|edit'), + 'OnDisableUnused' => Array ('self' => 'edit'), // front - 'OnChangeCurrency' => Array('self' => true), - 'OnItemBuild' => Array('self' => true), + 'OnChangeCurrency' => Array ('self' => true), + 'OnItemBuild' => Array ('self' => true), ); $this->permMapping = array_merge($this->permMapping, $permissions); } /** - * Returns ID of current item to be edited - * by checking ID passed in get/post as prefix_id - * or by looking at first from selected ids, stored. - * Returned id is also stored in Session in case - * it was explicitly passed as get/post - * - * @param kEvent $event - * @return int - */ - function getPassedID(&$event) - { - if ( $event->Special == 'current' ) { - return Array ('ISO' => $this->Application->RecallVar('curr_iso')); - } - - return parent::getPassedID($event); + * Returns ID of current item to be edited + * by checking ID passed in get/post as prefix_id + * or by looking at first from selected ids, stored. + * Returned id is also stored in Session in case + * it was explicitly passed as get/post + * + * @param kEvent $event + * @return int + * @access public + */ + public function getPassedID(kEvent &$event) + { + if ( $event->Special == 'current' ) { + return Array ('ISO' => $this->Application->RecallVar('curr_iso')); } + return parent::getPassedID($event); + } + /** * Enter description here... * @@ -116,8 +120,10 @@ * @access protected * @see kDBEventHandler::OnListBuild() */ - protected function SetCustomQuery(&$event) + protected function SetCustomQuery(kEvent &$event) { + parent::SetCustomQuery($event); + $object =& $event->getObject(); /* @var $object kDBList */ Index: branches/5.2.x/units/products/products_event_handler.php =================================================================== diff -u -N -r14908 -r14986 --- branches/5.2.x/units/products/products_event_handler.php (.../products_event_handler.php) (revision 14908) +++ branches/5.2.x/units/products/products_event_handler.php (.../products_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('self' => true), - 'OnRateProduct' => Array('self' => true), - 'OnClearRecent' => Array('self' => true), - 'OnRecommendProduct' => Array('self' => true), - 'OnAddToCompare' => Array('self' => true), - 'OnRemoveFromCompare' => Array('self' => true), - 'OnCancelCompare' => Array('self' => true), + // front + 'OnCancelAction' => Array('self' => true), + 'OnRateProduct' => Array('self' => true), + 'OnClearRecent' => Array('self' => true), + 'OnRecommendProduct' => Array('self' => true), + 'OnAddToCompare' => Array('self' => true), + 'OnRemoveFromCompare' => Array('self' => true), + 'OnCancelCompare' => Array('self' => true), - // admin - 'OnQtyAdd' => Array('self' => 'add|edit'), - 'OnQtyRemove' => Array('self' => 'add|edit'), - 'OnQtyOrder' => Array('self' => 'add|edit'), - 'OnQtyReceiveOrder' => Array('self' => 'add|edit'), - 'OnQtyCancelOrder' => Array('self' => 'add|edit'), + // admin + 'OnQtyAdd' => Array('self' => 'add|edit'), + 'OnQtyRemove' => Array('self' => 'add|edit'), + 'OnQtyOrder' => Array('self' => 'add|edit'), + 'OnQtyReceiveOrder' => Array('self' => 'add|edit'), + 'OnQtyCancelOrder' => Array('self' => 'add|edit'), + ); - ); $this->permMapping = array_merge($this->permMapping, $permissions); } - function mapEvents() + /** + * Define alternative event processing method names + * + * @return void + * @see kEventHandler::$eventMethods + * @access protected + */ + protected function mapEvents() { parent::mapEvents(); // ensure auto-adding of approve/decine and so on events - $product_events = Array( 'OnQtyAdd'=>'InventoryAction', - 'OnQtyRemove'=>'InventoryAction', - 'OnQtyOrder'=>'InventoryAction', - 'OnQtyReceiveOrder'=>'InventoryAction', - 'OnQtyCancelOrder'=>'InventoryAction',); + $product_events = Array ( + 'OnQtyAdd'=>'InventoryAction', + 'OnQtyRemove'=>'InventoryAction', + 'OnQtyOrder'=>'InventoryAction', + 'OnQtyReceiveOrder'=>'InventoryAction', + 'OnQtyCancelOrder'=>'InventoryAction', + ); + $this->eventMethods = array_merge($this->eventMethods, $product_events); } @@ -325,9 +339,18 @@ $temp->Update(); } - function clearSelectedIDs(&$event) + /** + * Removes any information about current/selected ids + * from Application variables and Session + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function clearSelectedIDs(kEvent &$event) { parent::clearSelectedIDs($event); + $this->Application->SetVar('inventory_actions', $this->Application->RecallVar('inventory_actions')); $this->Application->RemoveVar('inventory_actions'); } @@ -377,25 +400,32 @@ $event->CallSubEvent('OnPreSave'); $this->LoadItem($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ + $from_type = $object->GetDBField('Type'); - if ($event->status==kEvent::erSUCCESS) { - $this->Application->SetVar($event->getPrefixSpecial().'_id', $this->Application->GetVar($event->getPrefixSpecial(true).'_GoId')); + if ( $event->status == kEvent::erSUCCESS ) { + $this->Application->SetVar($event->getPrefixSpecial() . '_id', $this->Application->GetVar($event->getPrefixSpecial(true) . '_GoId')); $this->LoadItem($event); $to_type = $object->GetDBField('Type'); - if ($from_type != $to_type) { + if ( $from_type != $to_type ) { $from_tabs = $this->GetTabs($from_type); $from_tab_i = array_search($this->Application->GetVar('t'), $from_tabs); $to_tabs = $this->GetTabs($to_type); $to_tab = $this->Application->GetVar('t'); $found = false; - while ( !isset($to_tabs[$from_tab_i]) && $from_tab_i < count($to_tabs)) { + while (!isset($to_tabs[$from_tab_i]) && $from_tab_i < count($to_tabs)) { $from_tab_i++; } - if ( !isset($to_tabs[$from_tab_i]) ) $from_tab_i = 0; + + if ( !isset($to_tabs[$from_tab_i]) ) { + $from_tab_i = 0; + } + $to_tab = $to_tabs[$from_tab_i]; $event->redirect = $to_tab; @@ -823,12 +853,14 @@ */ function OnDeleteListingType(&$event) { - $listing_type = $event->MasterEvent->getObject(); + $listing_type =& $event->MasterEvent->getObject(); + /* @var $listing_type kDBItem */ + $product_id = $listing_type->GetDBField('VirtualProductId'); - if ($product_id) { - $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); - $temp_handler->DeleteItems($event->Prefix, $event->Special, Array($product_id)); + if ( $product_id ) { + $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler'); + $temp_handler->DeleteItems($event->Prefix, $event->Special, Array ($product_id)); } } @@ -1303,7 +1335,9 @@ parent::setCustomExportColumns($event); $object =& $event->getObject(); - $this->setPrimaryPrice($object->GetID(), (double)$object->GetDBField('Price'), Array('Cost' => (double)$object->GetDBField('Cost')) ); + /* @var $object kDBItem */ + + $this->setPrimaryPrice($object->GetID(), (double)$object->GetDBField('Price'), Array ('Cost' => (double)$object->GetDBField('Cost'))); } function OnPreSaveAndOpenPopup(&$event) @@ -1321,20 +1355,32 @@ } - function getPassedID(&$event) + /** + * Returns ID of current item to be edited + * by checking ID passed in get/post as prefix_id + * or by looking at first from selected ids, stored. + * Returned id is also stored in Session in case + * it was explicitly passed as get/post + * + * @param kEvent $event + * @return int + * @access public + */ + public function getPassedID(kEvent &$event) { $event->setEventParam('raise_warnings', 0); $passed = parent::getPassedID($event); - if ($passed) { + if ( $passed ) { return $passed; } - if ($this->Application->isAdminUser) { + if ( $this->Application->isAdminUser ) { // we may get product id out of OrderItem, if it exists $ord_item =& $this->Application->recallObject('orditems', null, Array ('raise_warnings' => 0)); + /* @var $ord_item OrdersItem */ - if ($ord_item->GetDBField('ProductId')) { + if ( $ord_item->GetDBField('ProductId') ) { $passed = $ord_item->GetDBField('ProductId'); } } Index: branches/5.2.x/units/addresses/addresses_event_handler.php =================================================================== diff -u -N -r14953 -r14986 --- branches/5.2.x/units/addresses/addresses_event_handler.php (.../addresses_event_handler.php) (revision 14953) +++ branches/5.2.x/units/addresses/addresses_event_handler.php (.../addresses_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Application->isAdminUser ) { return; } @@ -58,7 +68,7 @@ /* @var $object kDBList */ $user_id = $this->Application->RecallVar('user_id'); - $object->addFilter('myitems_user','%1$s.PortalUserId = '.$user_id); + $object->addFilter('myitems_user', '%1$s.PortalUserId = ' . $user_id); } /** @@ -312,8 +322,9 @@ * * @param kEvent $event * @return bool + * @access protected */ - function checkItemStatus(&$event) + protected function checkItemStatus(kEvent &$event) { if ( $this->Application->isAdminUser ) { return true; Index: branches/5.2.x/units/manufacturers/manufacturers_event_handler.php =================================================================== diff -u -N -r14677 -r14986 --- branches/5.2.x/units/manufacturers/manufacturers_event_handler.php (.../manufacturers_event_handler.php) (revision 14677) +++ branches/5.2.x/units/manufacturers/manufacturers_event_handler.php (.../manufacturers_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('self' => true), ); @@ -37,40 +41,43 @@ * @access protected * @see kDBEventHandler::OnListBuild() */ - protected function SetCustomQuery(&$event) + protected function SetCustomQuery(kEvent &$event) { - if ($this->Application->isAdminUser) { - return ; + parent::SetCustomQuery($event); + + if ( $this->Application->isAdminUser ) { + return; } $category_id = $this->Application->GetVar('m_cat_id'); $parent_category_id = $event->getEventParam('parent_cat_id'); - if ($parent_category_id) { - if ($parent_category_id != 'any' && $parent_category_id > 0) { + if ( $parent_category_id ) { + if ( $parent_category_id != 'any' && $parent_category_id > 0 ) { $category_id = $parent_category_id; } } $sql = 'SELECT m.ManufacturerId, COUNT(p.ProductId) - FROM '.TABLE_PREFIX.'Manufacturers m - LEFT JOIN '.TABLE_PREFIX.'Products p ON p.ManufacturerId = m.ManufacturerId - LEFT JOIN '.TABLE_PREFIX.'CategoryItems ci ON ci.ItemResourceId = p.ResourceId - LEFT JOIN '.TABLE_PREFIX.'Category c ON c.CategoryId = ci.CategoryId + FROM ' . TABLE_PREFIX . 'Manufacturers m + LEFT JOIN ' . TABLE_PREFIX . 'Products p ON p.ManufacturerId = m.ManufacturerId + LEFT JOIN ' . TABLE_PREFIX . 'CategoryItems ci ON ci.ItemResourceId = p.ResourceId + LEFT JOIN ' . TABLE_PREFIX . 'Category c ON c.CategoryId = ci.CategoryId WHERE (ci.PrimaryCat = 1) AND (p.Status = ' . STATUS_ACTIVE . ') AND (c.Status = ' . STATUS_ACTIVE . ') GROUP BY m.ManufacturerId'; // add category filter $tree_indexes = $this->Application->getTreeIndex($category_id); // if category_id is 0 returs false - if ($tree_indexes) { - $sql .= ' AND c.TreeLeft BETWEEN '.$tree_indexes['TreeLeft'].' AND '.$tree_indexes['TreeRight']; + if ( $tree_indexes ) { + $sql .= ' AND c.TreeLeft BETWEEN ' . $tree_indexes['TreeLeft'] . ' AND ' . $tree_indexes['TreeRight']; } $manufacturers = $this->Conn->GetCol($sql); $object =& $event->getObject(); + /* @var $object kDBList */ $object->addFilter('category_manufacturer_filter', $manufacturers ? '%1$s.ManufacturerId IN (' . implode(',', $manufacturers) . ')' : 'FALSE'); } Index: branches/5.2.x/units/pricing/pricing_event_handler.php =================================================================== diff -u -N -r14750 -r14986 --- branches/5.2.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 14750) +++ branches/5.2.x/units/pricing/pricing_event_handler.php (.../pricing_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('subitem' => 'add|edit'), - 'OnInfinity' => Array('subitem' => 'add|edit'), - 'OnArrange' => Array('subitem' => 'add|edit'), - 'OnDeleteBrackets' => Array('subitem' => 'add|edit'), + + $permissions = Array ( + 'OnMoreBrackets' => Array ('subitem' => 'add|edit'), + 'OnInfinity' => Array ('subitem' => 'add|edit'), + 'OnArrange' => Array ('subitem' => 'add|edit'), + 'OnDeleteBrackets' => Array ('subitem' => 'add|edit'), ); + $this->permMapping = array_merge($this->permMapping, $permissions); } - function mapEvents() + /** + * Define alternative event processing method names + * + * @return void + * @see kEventHandler::$eventMethods + * @access protected + */ + protected function mapEvents() { - parent::mapEvents(); // ensure auto-adding of approve/decine and so on events + parent::mapEvents(); // ensure auto-adding of approve/decline and so on events + $brackets_events = Array( 'OnMoreBrackets' => 'PricingBracketsAction', 'OnArrange' => 'PricingBracketsAction', @@ -448,12 +461,13 @@ * @access protected * @see kDBEventHandler::OnListBuild() */ - protected function SetCustomQuery(&$event) + protected function SetCustomQuery(kEvent &$event) { $object =& $event->getObject(); + /* @var $object kDBList */ - if ($this->Application->isAdminUser) { - return ; + if ( $this->Application->isAdminUser ) { + return; } if ( $this->Application->ConfigValue('Comm_PriceBracketCalculation') == 1 ) { @@ -462,7 +476,7 @@ WHERE PortalUserId = ' . $this->Application->GetVar('u_id'); $pricing_group = $this->Conn->GetOne($sql); - if ($pricing_group) { + if ( $pricing_group ) { $sql = 'SELECT COUNT(*) FROM ' . TABLE_PREFIX . 'ProductsPricing WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND GroupId = ' . $pricing_group . ' AND Price IS NOT NULL'; @@ -484,28 +498,28 @@ ORDER BY GroupId ASC, MinQty ASC'; $effective_brackets = $this->Conn->Query($sql, 'PriceId'); - $group_prices = array(); + $group_prices = array (); $min_price = -1; $cheapest_group = 0; foreach ($effective_brackets as $bracket) { - if (!isset($group_prices[$bracket['GroupId']])) { + if ( !isset($group_prices[$bracket['GroupId']]) ) { $group_prices[$bracket['GroupId']] = $bracket['Price']; - if ($bracket['Price'] < $min_price || $min_price == -1) { + if ( $bracket['Price'] < $min_price || $min_price == -1 ) { $min_price = $bracket['Price']; $cheapest_group = $bracket['GroupId']; } } } - if (!$cheapest_group) { + if ( !$cheapest_group ) { $cheapest_group = $this->Application->ConfigValue('User_LoggedInGroup'); } $pricing_group = $cheapest_group; } - $object->addFilter('price_user_group', $object->TableName.'.GroupId='.$pricing_group); + $object->addFilter('price_user_group', $object->TableName . '.GroupId=' . $pricing_group); } } \ No newline at end of file Index: branches/5.2.x/units/zones/zones_event_handler.php =================================================================== diff -u -N -r14677 -r14986 --- branches/5.2.x/units/zones/zones_event_handler.php (.../zones_event_handler.php) (revision 14677) +++ branches/5.2.x/units/zones/zones_event_handler.php (.../zones_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('subitem' => 'add|edit'), - 'OnCountryChange' => Array('subitem' => 'add|edit'), - 'OnLoadZoneForm' => Array('subitem' => 'add|edit'), - ); + 'OnTypeChange' => Array('subitem' => 'add|edit'), + 'OnCountryChange' => Array('subitem' => 'add|edit'), + 'OnLoadZoneForm' => Array('subitem' => 'add|edit'), + ); + $this->permMapping = array_merge($this->permMapping, $permissions); } - function mapEvents() + /** + * Define alternative event processing method names + * + * @return void + * @see kEventHandler::$eventMethods + * @access protected + */ + protected function mapEvents() { - parent::mapEvents(); // ensure auto-adding of approve/decine and so on events - $zones_events = Array( 'OnAddLocation' => 'DestinationAction', - 'OnRemoveLocation' => 'DestinationAction', - 'OnLoadZoneForm' => 'DestinationAction', - /*'OnCountryChange' => 'DestinationAction',*/); + parent::mapEvents(); // ensure auto-adding of approve/decline and so on events + $zones_events = Array( + 'OnAddLocation' => 'DestinationAction', + 'OnRemoveLocation' => 'DestinationAction', + 'OnLoadZoneForm' => 'DestinationAction', + /*'OnCountryChange' => 'DestinationAction',*/ + ); + $this->eventMethods = array_merge($this->eventMethods, $zones_events); } Index: branches/5.2.x/units/files/files_event_handler.php =================================================================== diff -u -N -r14594 -r14986 --- branches/5.2.x/units/files/files_event_handler.php (.../files_event_handler.php) (revision 14594) +++ branches/5.2.x/units/files/files_event_handler.php (.../files_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Special == 'downl') { + if ( $event->Special == 'downl' ) { return ''; } @@ -38,11 +39,14 @@ * @access protected * @see kDBEventHandler::OnListBuild() */ - protected function SetCustomQuery(&$event) + protected function SetCustomQuery(kEvent &$event) { + parent::SetCustomQuery($event); + $object =& $event->getObject(); - switch ($event->Special) - { + /* @var $object kDBList */ + + switch ($event->Special) { case 'downl': $object->addFilter('is_active', '%1$s.Status = 1'); break; @@ -80,7 +84,7 @@ /* @var $object kDBItem */ $parent_info = $object->getLinkedInfo($event->Special); - + $sql = 'SELECT FileId FROM ' . $object->TableName . ' WHERE IsPrimary = 1 AND ' . $parent_info['ForeignKey'] . ' = ' . $parent_info['ParentId']; Index: branches/5.2.x/units/affiliate_plans/affiliate_plans_event_handler.php =================================================================== diff -u -N -r14625 -r14986 --- branches/5.2.x/units/affiliate_plans/affiliate_plans_event_handler.php (.../affiliate_plans_event_handler.php) (revision 14625) +++ branches/5.2.x/units/affiliate_plans/affiliate_plans_event_handler.php (.../affiliate_plans_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Special == 'active') - { + parent::SetCustomQuery($event); + + if ( $event->Special == 'active' ) { $object =& $event->getObject(); + /* @var $object kDBList */ + $object->addFilter('active', '%1$s.Enabled = 1'); } } Index: branches/5.2.x/units/taxes/taxes_event_handler.php =================================================================== diff -u -N -r14677 -r14986 --- branches/5.2.x/units/taxes/taxes_event_handler.php (.../taxes_event_handler.php) (revision 14677) +++ branches/5.2.x/units/taxes/taxes_event_handler.php (.../taxes_event_handler.php) (revision 14986) @@ -1,6 +1,6 @@ Array('self' => 'add|edit'), - 'OnCountryChange' => Array('self' => 'add|edit'), - ); + 'OnTypeChange' => Array('self' => 'add|edit'), + 'OnCountryChange' => Array('self' => 'add|edit'), + ); + $this->permMapping = array_merge($this->permMapping, $permissions); } - function mapEvents() + /** + * Define alternative event processing method names + * + * @return void + * @see kEventHandler::$eventMethods + * @access protected + */ + protected function mapEvents() { parent::mapEvents(); // ensure auto-adding of approve/decine and so on events - $zones_events = Array( 'OnAddLocation' => 'DestinationAction', - 'OnRemoveLocation' => 'DestinationAction', - 'OnLoadZoneForm' => 'DestinationAction', - /*'OnCountryChange' => 'DestinationAction',*/ - 'OnNew' => 'DestinationAction'); + $zones_events = Array ( + 'OnAddLocation' => 'DestinationAction', + 'OnRemoveLocation' => 'DestinationAction', + 'OnLoadZoneForm' => 'DestinationAction', + /*'OnCountryChange' => 'DestinationAction',*/ + 'OnNew' => 'DestinationAction' + ); + $this->eventMethods = array_merge($this->eventMethods, $zones_events); } Index: branches/5.2.x/units/gift_certificates/gift_certificates_eh.php =================================================================== diff -u -N -r14940 -r14986 --- branches/5.2.x/units/gift_certificates/gift_certificates_eh.php (.../gift_certificates_eh.php) (revision 14940) +++ branches/5.2.x/units/gift_certificates/gift_certificates_eh.php (.../gift_certificates_eh.php) (revision 14986) @@ -1,6 +1,6 @@ Array('self' => true), + + $permissions = Array ( + 'OnItemBuild' => Array ('self' => true), ); $this->permMapping = array_merge($this->permMapping, $permissions);