Index: branches/5.2.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -N -r15049 -r15065 --- branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 15049) +++ branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 15065) @@ -1,6 +1,6 @@ getListSetting($event, 'Sortings'); $cur_sort1 = getArrayValue($sorting_settings, 'Sort1'); @@ -1380,8 +1381,10 @@ * Set sorting directly to session (used for category item sorting (front-end), grid sorting (admin, view menu) * * @param kEvent $event + * @return void + * @access protected */ - function OnSetSortingDirect(&$event) + protected function OnSetSortingDirect(kEvent &$event) { // used on Front-End in category item lists $prefix_special = $event->getPrefixSpecial(); @@ -1425,8 +1428,10 @@ * Reset grid sorting to default (from config) * * @param kEvent $event + * @return void + * @access protected */ - function OnResetSorting(&$event) + protected function OnResetSorting(kEvent &$event) { $this->setListSetting($event, 'Sortings'); } @@ -1435,48 +1440,52 @@ * Sets grid refresh interval * * @param kEvent $event + * @return void + * @access protected */ - function OnSetAutoRefreshInterval(&$event) + protected function OnSetAutoRefreshInterval(kEvent &$event) { $refresh_interval = $this->Application->GetVar('refresh_interval'); - $view_name = $this->Application->RecallVar($event->getPrefixSpecial().'_current_view'); - $this->Application->StorePersistentVar($event->getPrefixSpecial().'_refresh_interval.'.$view_name, $refresh_interval); + $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view'); + $this->Application->StorePersistentVar($event->getPrefixSpecial() . '_refresh_interval.' . $view_name, $refresh_interval); } /** * Changes auto-refresh state for grid * * @param kEvent $event + * @return void + * @access protected */ - function OnAutoRefreshToggle(&$event) + protected function OnAutoRefreshToggle(kEvent &$event) { $refresh_intervals = $this->Application->ConfigValue('AutoRefreshIntervals'); - if (!$refresh_intervals) { - return ; + if ( !$refresh_intervals ) { + return; } - $view_name = $this->Application->RecallVar($event->getPrefixSpecial().'_current_view'); - $auto_refresh = $this->Application->RecallPersistentVar($event->getPrefixSpecial().'_auto_refresh.'.$view_name); + $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view'); + $auto_refresh = $this->Application->RecallPersistentVar($event->getPrefixSpecial() . '_auto_refresh.' . $view_name); - if ($auto_refresh === false) { + if ( $auto_refresh === false ) { $refresh_intervals = explode(',', $refresh_intervals); - $this->Application->StorePersistentVar($event->getPrefixSpecial().'_refresh_interval.'.$view_name, $refresh_intervals[0]); + $this->Application->StorePersistentVar($event->getPrefixSpecial() . '_refresh_interval.' . $view_name, $refresh_intervals[0]); } - $this->Application->StorePersistentVar($event->getPrefixSpecial().'_auto_refresh.'.$view_name, $auto_refresh ? 0 : 1); + $this->Application->StorePersistentVar($event->getPrefixSpecial() . '_auto_refresh.' . $view_name, $auto_refresh ? 0 : 1); } /** * Creates needed sql query to load item, * if no query is defined in config for - * special requested, then use default - * query + * special requested, then use list query * * @param kEvent $event + * @return string * @access protected */ - function ItemPrepareQuery(&$event) + protected function ItemPrepareQuery(kEvent &$event) { $object =& $event->getObject(); /* @var $object kDBItem */ @@ -1496,16 +1505,17 @@ * query * * @param kEvent $event + * @return string * @access protected */ - function ListPrepareQuery(&$event) + protected function ListPrepareQuery(kEvent &$event) { $object =& $event->getObject(); /* @var $object kDBItem */ $sqls = $object->getFormOption('ListSQLs', Array ()); - return $sqls[ array_key_exists($event->Special, $sqls) ? $event->Special : '' ]; + return $sqls[array_key_exists($event->Special, $sqls) ? $event->Special : '']; } /** @@ -1516,7 +1526,7 @@ * @return void * @access protected */ - protected function customProcessing(&$event, $type) + protected function customProcessing(kEvent &$event, $type) { } @@ -1527,33 +1537,36 @@ * Creates new kDBItem * * @param kEvent $event + * @return void * @access protected */ - function OnCreate(&$event) + protected function OnCreate(kEvent &$event) { - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); /* @var $object kDBItem */ - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - if ($items_info) { - list($id,$field_values) = each($items_info); - $object->SetFieldsFromHash($field_values, $this->getRequestProtectedFields($field_values)); + $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); + + if ( !$items_info ) { + return; } - $this->customProcessing($event,'before'); + list($id, $field_values) = each($items_info); + $object->SetFieldsFromHash($field_values, $this->getRequestProtectedFields($field_values)); - //look at kDBItem' Create for ForceCreateId description, it's rarely used and is NOT set by default + $this->customProcessing($event, 'before'); + + // look at kDBItem' Create for ForceCreateId description, it's rarely used and is NOT set by default if ( $object->Create($event->getEventParam('ForceCreateId')) ) { - $this->customProcessing($event,'after'); - $event->status=kEvent::erSUCCESS; - $event->setRedirectParams(Array('opener'=>'u'), true); + $this->customProcessing($event, 'after'); + $event->SetRedirectParam('opener', 'u'); + return; } - else { - $event->status = kEvent::erFAIL; - $event->redirect = false; - $this->Application->SetVar($event->getPrefixSpecial().'_SaveEvent','OnCreate'); - $object->setID($id); - } + + $event->redirect = false; + $event->status = kEvent::erFAIL; + $this->Application->SetVar($event->getPrefixSpecial() . '_SaveEvent', 'OnCreate'); + $object->setID($id); } /** @@ -1612,16 +1625,17 @@ * Delete's kDBItem object * * @param kEvent $event + * @return void * @access protected */ - function OnDelete(&$event) + protected function OnDelete(kEvent &$event) { - if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { $event->status = kEvent::erFAIL; return; } - $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event)); + $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event)); /* @var $temp_handler kTempTablesHandler */ $temp_handler->DeleteItems($event->Prefix, $event->Special, Array ($this->getPassedID($event))); @@ -1631,14 +1645,16 @@ * Deletes all records from table * * @param kEvent $event + * @return void + * @access protected */ - function OnDeleteAll(&$event) + protected function OnDeleteAll(kEvent &$event) { $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName'); $ids = $this->Conn->GetCol($sql); - if ($ids) { + if ( $ids ) { $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event)); /* @var $temp_handler kTempTablesHandler */ @@ -1650,19 +1666,20 @@ * Prepares new kDBItem object * * @param kEvent $event + * @return void * @access protected */ - function OnNew(&$event) + protected function OnNew(kEvent &$event) { - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); /* @var $object kDBItem */ $object->Clear(0); - $this->Application->SetVar($event->getPrefixSpecial().'_SaveEvent', 'OnCreate'); + $this->Application->SetVar($event->getPrefixSpecial() . '_SaveEvent', 'OnCreate'); - if ($event->getEventParam('top_prefix') != $event->Prefix) { + if ( $event->getEventParam('top_prefix') != $event->Prefix ) { // this is subitem prefix, so use main item special - $table_info = $object->getLinkedInfo( $this->getMainSpecial($event) ); + $table_info = $object->getLinkedInfo($this->getMainSpecial($event)); } else { $table_info = $object->getLinkedInfo(); @@ -1680,7 +1697,7 @@ * @return void * @access protected */ - protected function OnCancel(&$event) + protected function OnCancel(kEvent &$event) { $object =& $event->getObject(Array ('skip_autoload' => true)); /* @var $object kDBItem */ @@ -1718,7 +1735,7 @@ * @return void * @access protected */ - protected function OnMassDelete(&$event) + protected function OnMassDelete(kEvent &$event) { if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { $event->status = kEvent::erFAIL; @@ -1745,8 +1762,10 @@ * Sets window id (of first opened edit window) to temp mark in uls * * @param kEvent $event + * @return void + * @access protected */ - function setTempWindowID(&$event) + protected function setTempWindowID(kEvent &$event) { $prefixes = Array ($event->Prefix, $event->getPrefixSpecial(true)); @@ -1766,18 +1785,20 @@ * with items selected in the grid * * @param kEvent $event + * @return void + * @access protected */ - function OnEdit(&$event) + protected function OnEdit(kEvent &$event) { $this->setTempWindowID($event); $ids = $this->StoreSelectedIDs($event); - $this->Application->RemoveVar( $this->_getPendingActionVariableName($event) ); + $this->Application->RemoveVar($this->_getPendingActionVariableName($event)); $changes_var_name = $this->Prefix . '_changes_' . $this->Application->GetTopmostWid($this->Prefix); $this->Application->RemoveVar($changes_var_name); - $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event)); + $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event)); /* @var $temp_handler kTempTablesHandler */ $temp_handler->PrepareEdit(); @@ -1795,12 +1816,12 @@ * @return void * @access protected */ - protected function OnSave(&$event) + protected function OnSave(kEvent &$event) { $event->CallSubEvent('OnPreSave'); - if ($event->status != kEvent::erSUCCESS) { - return ; + if ( $event->status != kEvent::erSUCCESS ) { + return; } $skip_master = false; @@ -1815,7 +1836,7 @@ if ( $live_ids === false ) { // coping from table failed, because we have another coping process to same table, that wasn't finished $event->status = kEvent::erFAIL; - return ; + return; } if ( $live_ids ) { @@ -1835,14 +1856,22 @@ $this->clearSelectedIDs($event); - $event->setRedirectParams(Array ('opener' => 'u'), true); + $event->SetRedirectParam('opener', 'u'); $this->Application->RemoveVar($event->getPrefixSpecial() . '_modified'); // all temp tables are deleted here => all after hooks should think, that it's live mode now $this->Application->SetVar($event->Prefix . '_mode', ''); } - function SaveLoggedChanges($changes_var_name, $save = true) + /** + * Saves changes made in temporary table to log + * + * @param string $changes_var_name + * @param bool $save + * @return void + * @access public + */ + public function SaveLoggedChanges($changes_var_name, $save = true) { // 1. get changes, that were made $changes = $this->Application->RecallVar($changes_var_name); @@ -1940,7 +1969,7 @@ * @return void * @access protected */ - protected function OnCancelEdit(&$event) + protected function OnCancelEdit(kEvent &$event) { $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event)); /* @var $temp_handler kTempTablesHandler */ @@ -1961,8 +1990,9 @@ * * @param kEvent $event * @return bool + * @access public */ - function isNewItemCreate(&$event) + public function isNewItemCreate(kEvent &$event) { $object =& $event->getObject( Array ('raise_warnings' => 0) ); /* @var $object kDBItem */ @@ -1978,7 +2008,7 @@ * @return void * @access protected */ - protected function OnPreSave(&$event) + protected function OnPreSave(kEvent &$event) { // if there is no id - it means we need to create an item if ( is_object($event->MasterEvent) ) { @@ -2003,13 +2033,15 @@ * [HOOK] Saves sub-item * * @param kEvent $event + * @return void + * @access protected */ - function OnPreSaveSubItem(&$event) + protected function OnPreSaveSubItem(kEvent &$event) { $not_created = $this->isNewItemCreate($event); $event->CallSubEvent($not_created ? 'OnCreate' : 'OnUpdate'); - if ($event->status == kEvent::erSUCCESS) { + if ( $event->status == kEvent::erSUCCESS ) { $object =& $event->getObject(); /* @var $object kDBItem */ @@ -2028,12 +2060,14 @@ * Used in Prev/Next buttons * * @param kEvent $event + * @return void + * @access protected */ - function OnPreSaveAndGo(&$event) + protected function OnPreSaveAndGo(kEvent &$event) { $event->CallSubEvent('OnPreSave'); - if ($event->status == kEvent::erSUCCESS) { + if ( $event->status == kEvent::erSUCCESS ) { $id = $this->Application->GetVar($event->getPrefixSpecial(true) . '_GoId'); $event->SetRedirectParam($event->getPrefixSpecial() . '_id', $id); } @@ -2044,12 +2078,15 @@ * to passed tabs, by redirecting to it with OnPreSave event * * @param kEvent $event + * @return void + * @access protected */ - function OnPreSaveAndGoToTab(&$event) + protected function OnPreSaveAndGoToTab(kEvent &$event) { $event->CallSubEvent('OnPreSave'); - if ($event->status==kEvent::erSUCCESS) { - $event->redirect=$this->Application->GetVar($event->getPrefixSpecial(true).'_GoTab'); + + if ( $event->status == kEvent::erSUCCESS ) { + $event->redirect = $this->Application->GetVar($event->getPrefixSpecial(true) . '_GoTab'); } } @@ -2058,13 +2095,16 @@ * by redirecting to it with empty event * * @param kEvent $event + * @return void + * @access protected */ - function OnUpdateAndGoToTab(&$event) + protected function OnUpdateAndGoToTab(kEvent &$event) { $event->setPseudoClass('_List'); $event->CallSubEvent('OnUpdate'); - if ($event->status==kEvent::erSUCCESS) { - $event->redirect=$this->Application->GetVar($event->getPrefixSpecial(true).'_GoTab'); + + if ( $event->status == kEvent::erSUCCESS ) { + $event->redirect = $this->Application->GetVar($event->getPrefixSpecial(true) . '_GoTab'); } } @@ -2077,13 +2117,13 @@ * @return void * @access protected */ - protected function OnPreCreate(&$event) + protected function OnPreCreate(kEvent &$event) { $this->setTempWindowID($event); $this->clearSelectedIDs($event); $this->Application->SetVar('m_lang', $this->Application->GetDefaultLanguageId()); - $object =& $event->getObject( Array ('skip_autoload' => true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); /* @var $object kDBItem */ $temp_handler =& $this->Application->recallObject($event->Prefix . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event)); @@ -2109,7 +2149,7 @@ * @return void * @access protected */ - protected function OnPreSaveCreated(&$event) + protected function OnPreSaveCreated(kEvent &$event) { $object =& $event->getObject( Array('skip_autoload' => true) ); /* @var $object kDBItem */ @@ -2137,7 +2177,7 @@ * @return void * @access protected */ - protected function OnReset(&$event) + protected function OnReset(kEvent &$event) { //do nothing - should reset :) if ( $this->isNewItemCreate($event) ) { @@ -2157,7 +2197,7 @@ * @return void * @access protected */ - protected function iterateItems(&$event) + protected function iterateItems(kEvent &$event) { if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { $event->status = kEvent::erFAIL; @@ -2213,15 +2253,17 @@ } /** - * Enter description here... + * Clones selected items in list * * @param kEvent $event + * @return void + * @access protected */ - function OnMassClone(&$event) + protected function OnMassClone(kEvent &$event) { if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { $event->status = kEvent::erFAIL; - return ; + return; } $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => &$event)); @@ -2236,13 +2278,23 @@ $this->clearSelectedIDs($event); } - function check_array($records, $field, $value) + /** + * Checks if given value is present in given array + * + * @param Array $records + * @param string $field + * @param mixed $value + * @return bool + * @access protected + */ + protected function check_array($records, $field, $value) { foreach ($records as $record) { if ($record[$field] == $value) { return true; } } + return false; } @@ -2253,7 +2305,7 @@ * @return void * @access protected */ - protected function OnPreSavePopup(&$event) + protected function OnPreSavePopup(kEvent &$event) { $object =& $event->getObject(); /* @var $object kDBItem */ @@ -2270,13 +2322,14 @@ // III. Events that allow to put some code before and after Update,Load,Create and Delete methods of item /** - * Occurse before loading item, 'id' parameter - * allows to get id of item beeing loaded + * Occurs before loading item, 'id' parameter + * allows to get id of item being loaded * * @param kEvent $event - * @access public + * @return void + * @access protected */ - function OnBeforeItemLoad(&$event) + protected function OnBeforeItemLoad(kEvent &$event) { } @@ -2289,7 +2342,7 @@ * @return void * @access protected */ - protected function OnAfterItemLoad(&$event) + protected function OnAfterItemLoad(kEvent &$event) { } @@ -2301,7 +2354,7 @@ * @return void * @access protected */ - protected function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(kEvent &$event) { } @@ -2313,7 +2366,7 @@ * @return void * @access protected */ - protected function OnAfterItemCreate(&$event) + protected function OnAfterItemCreate(kEvent &$event) { $object =& $event->getObject(); /* @var $object kDBItem */ @@ -2330,7 +2383,7 @@ * @return void * @access protected */ - protected function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(kEvent &$event) { } @@ -2339,9 +2392,10 @@ * Occurs after updating item * * @param kEvent $event - * @access public + * @return void + * @access protected */ - function OnAfterItemUpdate(&$event) + protected function OnAfterItemUpdate(kEvent &$event) { $object =& $event->getObject(); /* @var $object kDBItem */ @@ -2356,21 +2410,23 @@ * deleted is stored as 'id' event param * * @param kEvent $event - * @access public + * @return void + * @access protected */ - function OnBeforeItemDelete(&$event) + protected function OnBeforeItemDelete(kEvent &$event) { } /** - * Occurse after deleting item, id of deleted item + * Occurs after deleting item, id of deleted item * is stored as 'id' param of event * * @param kEvent $event - * @access public + * @return void + * @access protected */ - function OnAfterItemDelete(&$event) + protected function OnAfterItemDelete(kEvent &$event) { } @@ -2400,12 +2456,14 @@ } /** - * Occures after an item has been copied to temp + * Occurs after an item has been copied to temp * Id of copied item is passed as event' 'id' param * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterCopyToTemp(&$event) + protected function OnAfterCopyToTemp(kEvent &$event) { } @@ -2419,29 +2477,33 @@ * @return void * @access protected */ - protected function OnBeforeDeleteFromLive(&$event) + protected function OnBeforeDeleteFromLive(kEvent &$event) { } /** - * Occures before an item is copied to live table (after all foreign keys have been updated) + * Occurs before an item is copied to live table (after all foreign keys have been updated) * Id of item being copied is passed as event' 'id' param * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeCopyToLive(&$event) + protected function OnBeforeCopyToLive(kEvent &$event) { } /** - * Occures after an item has been copied to live table + * Occurs after an item has been copied to live table * Id of copied item is passed as event' 'id' param * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterCopyToLive(&$event) + protected function OnAfterCopyToLive(kEvent &$event) { $this->_proccessPendingActions($event); } @@ -2450,8 +2512,10 @@ * Processing file pending actions (e.g. delete scheduled files) * * @param kEvent $event + * @return void + * @access protected */ - function _proccessPendingActions(&$event) + protected function _proccessPendingActions(kEvent &$event) { $var_name = $this->_getPendingActionVariableName($event); $schedule = $this->Application->RecallVar($var_name); @@ -2461,7 +2525,7 @@ foreach ($schedule as $data) { if ( $data['action'] == 'delete' ) { - unlink( $data['file'] ); + unlink($data['file']); } } @@ -2474,8 +2538,9 @@ * * @param kEvent $event * @return string + * @access protected */ - function _getPendingActionVariableName(&$event) + protected function _getPendingActionVariableName(kEvent &$event) { $window_id = $this->Application->GetTopmostWid($event->Prefix); @@ -2490,28 +2555,32 @@ * @return void * @access protected */ - protected function OnBeforeClone(&$event) + protected function OnBeforeClone(kEvent &$event) { } /** - * Occures after an item has been cloned + * Occurs after an item has been cloned * Id of newly created item is passed as event' 'id' param * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterClone(&$event) + protected function OnAfterClone(kEvent &$event) { } /** - * Occures after list is queried + * Occurs after list is queried * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterListQuery(&$event) + protected function OnAfterListQuery(kEvent &$event) { } @@ -2526,7 +2595,7 @@ * @access protected * @deprecated */ - protected function finalizePopup(&$event) + protected function finalizePopup(kEvent &$event) { $event->SetRedirectParam('opener', 'u'); } @@ -2535,9 +2604,10 @@ * Create search filters based on search query * * @param kEvent $event + * @return void * @access protected */ - function OnSearch(&$event) + protected function OnSearch(kEvent &$event) { $event->setPseudoClass('_List'); @@ -2551,9 +2621,10 @@ * Clear search keywords * * @param kEvent $event + * @return void * @access protected */ - function OnSearchReset(&$event) + protected function OnSearchReset(kEvent &$event) { $search_helper =& $this->Application->recallObject('SearchHelper'); /* @var $search_helper kSearchHelper */ @@ -2565,18 +2636,21 @@ * Set's new filter value (filter_id meaning from config) * * @param kEvent $event + * @return void + * @access protected + * @deprecated */ - function OnSetFilter(&$event) + protected function OnSetFilter(kEvent &$event) { $filter_id = $this->Application->GetVar('filter_id'); $filter_value = $this->Application->GetVar('filter_value'); - $view_filter = $this->Application->RecallVar($event->getPrefixSpecial().'_view_filter'); - $view_filter = $view_filter ? unserialize($view_filter) : Array(); + $view_filter = $this->Application->RecallVar($event->getPrefixSpecial() . '_view_filter'); + $view_filter = $view_filter ? unserialize($view_filter) : Array (); $view_filter[$filter_id] = $filter_value; - $this->Application->StoreVar( $event->getPrefixSpecial().'_view_filter', serialize($view_filter) ); + $this->Application->StoreVar($event->getPrefixSpecial() . '_view_filter', serialize($view_filter)); } /** @@ -2586,7 +2660,7 @@ * @return void * @access protected */ - protected function OnSetFilterPattern(&$event) + protected function OnSetFilterPattern(kEvent &$event) { $filters = $this->Application->GetVar($event->getPrefixSpecial(true) . '_filters'); if ( !$filters ) { @@ -2611,28 +2685,37 @@ * Add/Remove all filters applied to list from "View" menu * * @param kEvent $event + * @return void + * @access protected */ - function FilterAction(&$event) + protected function FilterAction(kEvent &$event) { - $view_filter = Array(); - $filter_menu = $this->Application->getUnitOption($event->Prefix,'FilterMenu'); - switch ($event->Name) - { + $view_filter = Array (); + $filter_menu = $this->Application->getUnitOption($event->Prefix, 'FilterMenu'); + + switch ($event->Name) { case 'OnRemoveFilters': $filter_value = 1; break; case 'OnApplyFilters': $filter_value = 0; break; + + default: + $filter_value = 0; + break; } - foreach($filter_menu['Filters'] as $filter_key => $filter_params) - { - if(!$filter_params) continue; + foreach ($filter_menu['Filters'] as $filter_key => $filter_params) { + if ( !$filter_params ) { + continue; + } + $view_filter[$filter_key] = $filter_value; } - $this->Application->StoreVar( $event->getPrefixSpecial().'_view_filter', serialize($view_filter) ); + + $this->Application->StoreVar($event->getPrefixSpecial() . '_view_filter', serialize($view_filter)); } /** @@ -2641,7 +2724,7 @@ * @param kEvent $event * @access protected */ - protected function OnPreSaveAndOpenTranslator(&$event) + protected function OnPreSaveAndOpenTranslator(kEvent &$event) { $this->Application->SetVar('allow_translation', true); @@ -2682,7 +2765,7 @@ 'trans_multi_line' => $this->Application->GetVar('translator_multi_line'), ); - $event->setRedirectParams($redirect_params, true); + $event->setRedirectParams($redirect_params); // 1. SAVE LAST TEMPLATE TO SESSION (really needed here, because of tweaky redirect) $last_template = $this->Application->RecallVar('last_template'); @@ -2695,8 +2778,10 @@ * Makes all fields non-required * * @param kDBItem $object + * @return void + * @access protected */ - function RemoveRequiredFields(&$object) + protected function RemoveRequiredFields(&$object) { // making all field non-required to achieve successful presave $fields = array_keys( $object->getFields() ); @@ -2712,16 +2797,18 @@ * Saves selected user in needed field * * @param kEvent $event + * @return void + * @access protected */ - function OnSelectUser(&$event) + protected function OnSelectUser(kEvent &$event) { $object =& $event->getObject(); /* @var $object kDBItem */ $items_info = $this->Application->GetVar('u'); if ( $items_info ) { - $user_id = array_shift( array_keys($items_info) ); + $user_id = array_shift(array_keys($items_info)); $this->RemoveRequiredFields($object); @@ -2755,17 +2842,19 @@ * Shows export dialog * * @param kEvent $event + * @return void + * @access protected */ - function OnExport(&$event) + protected function OnExport(kEvent &$event) { $selected_ids = $this->StoreSelectedIDs($event); - if (implode(',', $selected_ids) == '') { + if ( implode(',', $selected_ids) == '' ) { // K4 fix when no ids found bad selected ids array is formed $selected_ids = false; } - $this->Application->StoreVar($event->Prefix.'_export_ids', $selected_ids ? implode(',', $selected_ids) : '' ); + $this->Application->StoreVar($event->Prefix . '_export_ids', $selected_ids ? implode(',', $selected_ids) : ''); $this->Application->LinkVar('export_finish_t'); $this->Application->LinkVar('export_progress_t'); @@ -2774,7 +2863,7 @@ $export_helper =& $this->Application->recallObject('CatItemExportHelper'); /*list ($index_file, $env) = explode('|', $this->Application->RecallVar('last_template')); - $finish_url = $this->Application->BaseURL('/admin').$index_file.'?'.ENV_VAR_NAME.'='.$env; + $finish_url = $this->Application->BaseURL('/admin') . $index_file . '?' . ENV_VAR_NAME . '=' . $env; $this->Application->StoreVar('export_finish_url', $finish_url);*/ $redirect_params = Array ( @@ -2810,8 +2899,9 @@ * * @param kEvent $event * @return Array + * @access public */ - function getCustomExportColumns(&$event) + public function getCustomExportColumns(kEvent &$event) { return Array(); } @@ -2820,20 +2910,25 @@ * Export form validation & processing * * @param kEvent $event + * @return void + * @access protected */ - function OnExportBegin(&$event) + protected function OnExportBegin(kEvent &$event) { $export_helper =& $this->Application->recallObject('CatItemExportHelper'); /* @var $export_helper kCatDBItemExportHelper */ + $export_helper->OnExportBegin($event); } /** * Enter description here... * * @param kEvent $event + * @return void + * @access protected */ - function OnExportCancel(&$event) + protected function OnExportCancel(kEvent &$event) { $this->OnGoBack($event); } @@ -2842,8 +2937,10 @@ * Allows configuring export options * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeExportBegin(&$event) + protected function OnBeforeExportBegin(kEvent &$event) { } @@ -2855,7 +2952,7 @@ * @return void * @access protected */ - protected function OnDeleteExportPreset(&$event) + protected function OnDeleteExportPreset(kEvent &$event) { $field_values = $this->getSubmittedFields($event); @@ -2895,19 +2992,21 @@ * Saves changes & changes language * * @param kEvent $event + * @return void + * @access protected */ - function OnPreSaveAndChangeLanguage(&$event) + protected function OnPreSaveAndChangeLanguage(kEvent &$event) { - if ($this->UseTempTables($event)) { + if ( $this->UseTempTables($event) ) { $event->CallSubEvent('OnPreSave'); } - if ($event->status == kEvent::erSUCCESS) { + if ( $event->status == kEvent::erSUCCESS ) { $this->Application->SetVar('m_lang', $this->Application->GetVar('language')); $data = $this->Application->GetVar('st_id'); - if ($data) { + if ( $data ) { $event->SetRedirectParam('st_id', $data); } } @@ -2920,43 +3019,43 @@ * @return void * @access protected */ - protected function OnUploadFile(&$event) + protected function OnUploadFile(kEvent &$event) { $event->status = kEvent::erSTOP; // define('DBG_SKIP_REPORTING', 0); $default_msg = "Flash requires that we output something or it won't fire the uploadSuccess event"; - if (!$this->Application->HttpQuery->Post) { + if ( !$this->Application->HttpQuery->Post ) { // Variables {field, id, flashsid} are always submitted through POST! // When file size is larger, then "upload_max_filesize" (in php.ini), // then these variables also are not submitted -> handle such case. header('HTTP/1.0 413 File size exceeds allowed limit'); echo $default_msg; - return ; + return; } - if (!$this->_checkFlashUploaderPermission($event)) { + if ( !$this->_checkFlashUploaderPermission($event) ) { // 403 Forbidden header('HTTP/1.0 403 You don\'t have permissions to upload'); echo $default_msg; - return ; + return; } $value = $this->Application->GetVar('Filedata'); - if (!$value || ($value['error'] != UPLOAD_ERR_OK)) { + if ( !$value || ($value['error'] != UPLOAD_ERR_OK) ) { // 413 Request Entity Too Large (file uploads disabled OR uploaded file was // to large for web server to accept, see "upload_max_filesize" in php.ini) header('HTTP/1.0 413 File size exceeds allowed limit'); echo $default_msg; - return ; + return; } $tmp_path = WRITEABLE . '/tmp/'; $fname = $value['name']; $id = $this->Application->GetVar('id'); - if ($id) { + if ( $id ) { $fname = $id . '_' . $fname; } @@ -2968,30 +3067,30 @@ $upload_dir = $field_options['upload_dir']; $storage_format = array_key_exists('storage_format', $field_options) ? $field_options['storage_format'] : false; - if (!is_writable($tmp_path)) { + if ( !is_writable($tmp_path) ) { // 500 Internal Server Error // check both temp and live upload directory header('HTTP/1.0 500 Write permissions not set on the server'); echo $default_msg; - return ; + return; } $file_helper =& $this->Application->recallObject('FileHelper'); /* @var $file_helper FileHelper */ $fname = $file_helper->ensureUniqueFilename($tmp_path, $fname); - if ($storage_format) { + if ( $storage_format ) { $image_helper =& $this->Application->recallObject('ImageHelper'); /* @var $image_helper ImageHelper */ move_uploaded_file($value['tmp_name'], $value['tmp_name'] . '.jpg'); // add extension, so ResizeImage can work $url = $image_helper->ResizeImage($value['tmp_name'] . '.jpg', $storage_format); $tmp_name = preg_replace('/^' . preg_quote($this->Application->BaseURL(), '/') . '/', '/', $url); - rename($tmp_name, $tmp_path.$fname); + rename($tmp_name, $tmp_path . $fname); } else { - move_uploaded_file($value['tmp_name'], $tmp_path.$fname); + move_uploaded_file($value['tmp_name'], $tmp_path . $fname); } echo preg_replace('/^' . preg_quote($id, '/') . '_/', '', $fname); @@ -3003,8 +3102,10 @@ * Delete temporary files, that won't be used for sure * * @param string $path + * @return void + * @access protected */ - function deleteTempFiles($path) + protected function deleteTempFiles($path) { $files = glob($path . '*.*'); $max_file_date = strtotime('-1 day'); @@ -3022,7 +3123,7 @@ * @param kEvent $event * @return bool */ - function _checkFlashUploaderPermission(&$event) + protected function _checkFlashUploaderPermission(kEvent &$event) { // Flash uploader does NOT send correct cookies, so we need to make our own check $cookie_name = 'adm_' . $this->Application->ConfigValue('SessionCookieName'); @@ -3035,7 +3136,7 @@ $admin_ses =& $this->Application->recallObject('Session.admin'); /* @var $admin_ses Session */ - if ($admin_ses->RecallVar('user_id') == USER_ROOT) { + if ( $admin_ses->RecallVar('user_id') == USER_ROOT ) { return true; } @@ -3059,20 +3160,22 @@ } /** - * Enter description here... + * Remembers, that file should be deleted on item's save from temp table * * @param kEvent $event + * @return void + * @access protected */ - function OnDeleteFile(&$event) + protected function OnDeleteFile(kEvent &$event) { $event->status = kEvent::erSTOP; - if (strpos($this->Application->GetVar('file'), '../') !== false) { - return ; + if ( strpos($this->Application->GetVar('file'), '../') !== false ) { + return; } - $object =& $event->getObject( Array ('skip_autoload' => true) ); - $options = $object->GetFieldOptions( $this->Application->GetVar('field') ); + $object =& $event->getObject(Array ('skip_autoload' => true)); + $options = $object->GetFieldOptions($this->Application->GetVar('field')); $var_name = $this->_getPendingActionVariableName($event); $schedule = $this->Application->RecallVar($var_name); @@ -3082,28 +3185,30 @@ } /** - * Enter description here... + * Returns url for viewing uploaded file * * @param kEvent $event + * @return void + * @access protected */ - function OnViewFile(&$event) + protected function OnViewFile(kEvent &$event) { $event->status = kEvent::erSTOP; $file = $this->Application->GetVar('file'); - if ((strpos($file, '../') !== false) || (trim($file) !== $file)) { + if ( (strpos($file, '../') !== false) || (trim($file) !== $file) ) { // when relative paths or special chars are found template names from url, then it's hacking attempt - return ; + return; } - $object =& $event->getObject( Array ('skip_autoload' => true)); + $object =& $event->getObject(Array ('skip_autoload' => true)); /* @var $object kDBItem */ $field = $this->Application->GetVar('field'); $options = $object->GetFieldOptions($field); // set current uploaded file - if ($this->Application->GetVar('tmp')) { + if ( $this->Application->GetVar('tmp') ) { $options['upload_dir'] = WRITEBALE_BASE . '/tmp/'; unset($options['include_path']); $object->SetFieldOptions($field, $options); @@ -3115,7 +3220,7 @@ } // get url to uploaded file - if ($this->Application->GetVar('thumb')) { + if ( $this->Application->GetVar('thumb') ) { $url = $object->GetField($field, $options['thumb_format']); } else { @@ -3127,7 +3232,7 @@ $path = $file_helper->urlToPath($url); - if (!file_exists($path)) { + if ( !file_exists($path) ) { exit; } @@ -3142,8 +3247,10 @@ * Validates MInput control fields * * @param kEvent $event + * @return void + * @access protected */ - function OnValidateMInputFields(&$event) + protected function OnValidateMInputFields(kEvent &$event) { $minput_helper =& $this->Application->recallObject('MInputHelper'); /* @var $minput_helper MInputHelper */ @@ -3155,8 +3262,10 @@ * Validates individual object field and returns the result * * @param kEvent $event + * @return void + * @access protected */ - function OnValidateField(&$event) + protected function OnValidateField(kEvent &$event) { $event->status = kEvent::erSTOP; $field = $this->Application->GetVar('field'); @@ -3203,13 +3312,15 @@ * Returns auto-complete values for ajax-dropdown * * @param kEvent $event + * @return void + * @access protected */ - function OnSuggestValues(&$event) + protected function OnSuggestValues(kEvent &$event) { - if (!$this->Application->isAdminUser) { + if ( !$this->Application->isAdminUser ) { // very careful here, because this event allows to // view every object field -> limit only to logged-in admins - return ; + return; } $event->status = kEvent::erSTOP; @@ -3220,19 +3331,19 @@ $object =& $event->getObject(); - if (!$field || !$cur_value || !$object->isField($field)) { - return ; + if ( !$field || !$cur_value || !$object->isField($field) ) { + return; } $limit = $this->Application->GetVar('limit'); - if (!$limit) { + if ( !$limit ) { $limit = 20; } - $sql = 'SELECT DISTINCT '.$field.' - FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' - WHERE '.$field.' LIKE '.$this->Conn->qstr($cur_value.'%').' - ORDER BY '.$field.' + $sql = 'SELECT DISTINCT ' . $field . ' + FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + WHERE ' . $field . ' LIKE ' . $this->Conn->qstr($cur_value . '%') . ' + ORDER BY ' . $field . ' LIMIT 0,' . $limit; $data = $this->Conn->GetCol($sql); @@ -3251,8 +3362,10 @@ * Enter description here... * * @param kEvent $event + * @return void + * @access protected */ - function OnSaveWidths(&$event) + protected function OnSaveWidths(kEvent &$event) { $event->status = kEvent::erSTOP; @@ -3277,8 +3390,10 @@ * Event status is preset from import script. * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeCSVLineImport(&$event) + protected function OnBeforeCSVLineImport(kEvent &$event) { // abstract, for hooking } @@ -3287,8 +3402,10 @@ * [HOOK] Allows to add cloned subitem to given prefix * * @param kEvent $event + * @return void + * @access protected */ - function OnCloneSubItem(&$event) + protected function OnCloneSubItem(kEvent &$event) { $clones = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'Clones'); @@ -3305,7 +3422,7 @@ * @see PriorityEventHandler * @access protected */ - protected function OnGetConstrainInfo(&$event) + protected function OnGetConstrainInfo(kEvent &$event) { $event->setEventParam('constrain_info', Array ('', '')); }