Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sun, Feb 2, 10:11 PM

in-portal

Index: trunk/kernel/units/config_search/config_search_event_handler.php
===================================================================
--- trunk/kernel/units/config_search/config_search_event_handler.php (revision 1820)
+++ trunk/kernel/units/config_search/config_search_event_handler.php (revision 1821)
@@ -1,139 +1,141 @@
<?php
class ConfigSearchEventHandler extends InpDBEventHandler {
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
$module_owner=$this->Application->GetVar('module');
if ($module_owner===false) {
$module_owner=$this->myUrlDecode($this->Application->GetVar('confs_module'));
$this->Application->SetVar("module", $module_owner);
}
$section=$this->Application->GetVar('section');
if ($section===false){
$section=$this->myUrlDecode($this->Application->GetVar('confs_section'));
$this->Application->SetVar("section", $section);
}
$object->addFilter('module_filter', '%1$s.ModuleName = "'.$module_owner.'"');
}
function OnUpdate(&$event)
{
- parent::OnUpdate($event);
+ if (!$this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ parent::OnUpdate($event);
+ }
$module_owner=$this->Application->GetVar('module');
$module_section=$this->Application->GetVar('section');
$conf_update = new kEvent( );
$conf_update->Init('conf');
$conf_update->Name = 'OnUpdate';
$conf_update->redirect = false;
$this->Application->HandleEvent($conf_update);
$event->redirect_params = Array('opener' => 's','confs_module'=>$this->myUrlEncode($module_owner),'confs_section'=>$this->myUrlEncode($module_section),'conf_module'=>$this->myUrlEncode($module_owner),'conf_section'=>$this->myUrlEncode($module_section),'pass'=>'all,confs,conf'); //stay!
}
function OnCancel(&$event)
{
parent::OnCancel($event);
$module_owner=$this->Application->GetVar('module');
$module_section=$this->Application->GetVar('section');
$event->redirect_params = Array('opener' => 's','confs_module'=>$this->myUrlEncode($module_owner),'confs_section'=>$this->myUrlEncode($module_section),'conf_module'=>$this->myUrlEncode($module_owner),'conf_section'=>$this->myUrlEncode($module_section),'pass'=>'all,confs,conf'); //stay!
}
function myUrlDecode($str){
$str=str_replace(';',':', $str);
$str=str_replace('!','-', $str);
return $str;
}
function myUrlEncode($str){
$str=str_replace('-', '!', $str);
$str=str_replace(':', ';', $str);
return $str;
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnCreateCustomField(&$event)
{
$cf_object =& $event->MasterEvent->getObject();
$is_new = $event->MasterEvent->getEventParam('IsNew');
$cf_search = array();
$cf_search['DisplayOrder'] = $cf_object->FieldValues['DisplayOrder'];
$cf_search['ElementType'] = $cf_object->FieldValues['ElementType'];
$cf_search['DisplayName'] = $cf_object->FieldValues['FieldLabel'];
$cf_search['FieldName'] = $cf_object->FieldValues['FieldName'];
$cf_search['Description'] = $cf_object->FieldValues['Prompt'];
$cf_search['ConfigHeader'] = 'la_Text_CustomFields';
$cf_search['TableName'] = "CustomField";
$cf_search['ModuleName'] = "In-Commerce";
$cf_search['ForeignField'] = "CustomMetaData.Value";
$cf_search['JoinClause'] = "{ForeignTable}.ResourceId={LocalTable}.ResourceId";
if($is_new)
{
$live_id = $this->Conn->GetOne("SELECT CustomFieldId FROM ".TABLE_PREFIX."CustomField WHERE FieldName='".$cf_search['FieldName']."'");
$cf_search['CustomFieldId'] = $live_id;
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$confs_item = $event->getObject();
$confs_item->SetFieldsFromHash($cf_search);
$confs_item->Create();
}else{
$cf_search['CustomFieldId'] = $cf_object->FieldValues['CustomFieldId'];
$search_config_id = $this->Conn->GetOne("SELECT SearchConfigId FROM ".TABLE_PREFIX."SearchConfig WHERE CustomFieldId='".$cf_object->FieldValues['CustomFieldId']."'");
$cf_search['SearchConfigId'] = $search_config_id;
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$confs_item = $event->getObject();
$confs_item->SetFieldsFromHash($cf_search);
$confs_item->Update($search_config_id);
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnDeleteCustomField(&$event){
$custom_field_id =&$event->MasterEvent->getEventParam('id');
$this->Conn->Query("DELETE FROM ".TABLE_PREFIX."SearchConfig WHERE CustomFieldId=".$custom_field_id);
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/config_search/config_search_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2
\ No newline at end of property
+1.3
\ No newline at end of property
Index: trunk/kernel/units/configuration/configuration_event_handler.php
===================================================================
--- trunk/kernel/units/configuration/configuration_event_handler.php (revision 1820)
+++ trunk/kernel/units/configuration/configuration_event_handler.php (revision 1821)
@@ -1,163 +1,165 @@
<?php
class ConfigurationEventHandler extends InpDBEventHandler {
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
$module_owner=$this->Application->GetVar('module');
if ($module_owner===false) {
$module_owner=$this->myUrlDecode($this->Application->GetVar('conf_module'));
$this->Application->SetVar("module", $module_owner);
}
$section=$this->Application->GetVar('section');
if ($section===false){
$section=$this->myUrlDecode($this->Application->GetVar('conf_section'));
$this->Application->SetVar("section", $section);
}
$object->addFilter('module_filter', '%1$s.ModuleOwner = "'.$module_owner.'"');
$object->addFilter('section_filter', '%1$s.Section = "'.$section.'"');
$object->AddOrderField('DisplayOrder', 'ASC');
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnBeforeItemUpdate(&$event)
{
$object =& $event->getObject();
if($object->GetDBField('element_type') == 'password')
{
if (trim($object->GetDBField('VariableValue'))=='') {
$field_options=$object->GetFieldOptions('VariableValue');
$field_options['skip_empty']=1;
$object->SetFieldOptions('VariableValue', $field_options);
}else{
$object->SetDBField('VariableValue', md5($object->GetDBField('VariableValue')));
}
}
$this->country_state_pairs = Array('Comm_Country' => 'Comm_State', 'Comm_Shipping_Country' => 'Comm_Shipping_State');
if ( isset($this->country_state_pairs[$object->GetDBField('VariableName')]) ){
$this->state_country_codes[$this->country_state_pairs[$object->GetDBField('VariableName')]]=$object->GetDBField('VariableValue');
}
if( isset($this->state_country_codes[$object->GetDBField('VariableName')]) )
{
$cs_helper = &$this->Application->recallObject('CountryStatesHelper');
$state_valid_code = $cs_helper->CheckState( $object->GetDBField('VariableValue'), $this->state_country_codes[$object->GetDBField('VariableName')] );
if ($state_valid_code !== false)
{
$object->SetDBField('VariableValue', $state_valid_code);
}
else
{
$errormsgs = $this->Application->GetVar('errormsgs');
$errors = !$errormsgs || !isset($errormsgs[$event->Prefix_Special]) ? Array() : $errormsgs[$event->Prefix_Special];
$errors[ $object->GetDBField('VariableName') ] = 'la_InvalidState';
$errormsgs[$event->Prefix_Special] = $errors;
$this->Application->SetVar('errormsgs', $errormsgs);
$event->redirect = false;
$event->status = erFAIL;
}
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnAfterItemUpdate(&$event)
{
$object =& $event->getObject();
if($object->GetDBField('element_type') == 'password')
{
if (trim($object->GetDBField('VariableValue'))=='') {
$field_options=$object->GetFieldOptions('VariableValue');
unset($field_options['skip_empty']);
$object->SetFieldOptions('VariableValue', $field_options);
}
}
}
function OnUpdate(&$event)
{
- parent::OnUpdate($event);
+ if (!$this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ parent::OnUpdate($event);
+ }
$module_owner=$this->Application->GetVar('module');
$section=$this->Application->GetVar('section');
$event->redirect_params = Array('opener' => 's','conf_section'=>$this->myUrlEncode($section), 'conf_module'=>$this->myUrlEncode($module_owner),'pass'=>'all,conf'); //stay!
if ($this->Application->GetVar('errormsgs')){
$event->redirect = false;
}
}
function OnCancel(&$event)
{
parent::OnCancel($event);
$module_owner=$this->Application->GetVar('module');
$section=$this->Application->GetVar('section');
$event->redirect_params = Array('opener' => 's','conf_section'=>$this->myUrlEncode($section), 'conf_module'=>$this->myUrlEncode($module_owner),'pass'=>'all,conf'); //stay!
}
function myUrlDecode($str){
$str=str_replace(';',':', $str);
$str=str_replace('!','-', $str);
return $str;
}
function myUrlEncode($str){
$str=str_replace('-', '!', $str);
$str=str_replace(':', ';', $str);
return $str;
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnChangeCountry(&$event)
{
$event->setPseudoClass('_List');
$object = &$event->getObject( Array('per_page'=>-1) );
$object->Query();
//$object->SetDBField('');
$array_records = &$object->Records;
foreach($array_records as $i=>$record){
if ($record['VariableName']=='Comm_Country'){
$values = $this->Application->GetVar('conf');
$array_records[$i]['VariableValue'] = $values['Comm_Country']['VariableValue'];
}
}
$event->redirect_params = Array('opener' => 's', 'pass'=>'all,conf'); //stay!
$event->redirect = false;
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/configuration/configuration_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.6
\ No newline at end of property
+1.7
\ No newline at end of property
Index: trunk/kernel/units/general/inp_db_event_handler.php
===================================================================
--- trunk/kernel/units/general/inp_db_event_handler.php (revision 1820)
+++ trunk/kernel/units/general/inp_db_event_handler.php (revision 1821)
@@ -1,107 +1,115 @@
<?php
class InpDBEventHandler extends kDBEventHandler
{
function mapEvents()
{
parent::mapEvents();
$common_events = Array( 'OnMassApprove'=>'iterateItems',
'OnMassDecline'=>'iterateItems',
'OnMassMoveUp'=>'iterateItems',
'OnMassMoveDown'=>'iterateItems',
);
$this->eventMethods = array_merge($this->eventMethods, $common_events);
}
/**
* Apply same processing to each item beeing selected in grid
*
* @param kEvent $event
* @access private
*/
function iterateItems(&$event)
{
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ return;
+ }
+
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$object =& $event->getObject();
$this->StoreSelectedIDs($event);
$ids=$this->getSelectedIDs($event);
if($ids)
{
$status_field = array_shift( $this->Application->getUnitOption($event->Prefix,'StatusField') );
foreach($ids as $id)
{
$object->Load($id);
switch ($event->Name)
{
case 'OnMassApprove':
$object->SetDBField($status_field, 1);
break;
case 'OnMassDecline':
$object->SetDBField($status_field, 0);
break;
case 'OnMassMoveUp':
$object->SetDBField('Priority', $object->GetDBField('Priority') + 1);
break;
case 'OnMassMoveDown':
$object->SetDBField('Priority', $object->GetDBField('Priority') - 1);
break;
}
if( $object->Update() )
{
$event->status=erSUCCESS;
$event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay!
}
else
{
$event->status=erFAIL;
$event->redirect=false;
break;
}
}
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnMassClone(&$event)
{
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ return;
+ }
+
$event->status=erSUCCESS;
$temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
$this->StoreSelectedIDs($event);
$ids=$this->getSelectedIDs($event);
if($ids)
{
$temp->CloneItems($event->Prefix, $event->Special, $ids);
}
}
function check_array($records, $field, $value)
{
foreach ($records as $record)
{
if ($record[$field] == $value)
{
return true;
}
}
return false;
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/general/inp_db_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.4
\ No newline at end of property
+1.5
\ No newline at end of property
Index: trunk/core/kernel/db/db_event_handler.php
===================================================================
--- trunk/core/kernel/db/db_event_handler.php (revision 1820)
+++ trunk/core/kernel/db/db_event_handler.php (revision 1821)
@@ -1,1435 +1,1441 @@
<?php
define('EH_CUSTOM_PROCESSING_BEFORE',1);
define('EH_CUSTOM_PROCESSING_AFTER',2);
/**
* Note:
* 1. When adressing variables from submit containing
* Prefix_Special as part of their name use
* $event->getPrefixSpecial(true) instead of
* $event->Prefix_Special as usual. This is due PHP
* is converting "." symbols in variable names during
* submit info "_". $event->getPrefixSpecial optional
* 1st parameter returns correct corrent Prefix_Special
* for variables beeing submitted such way (e.g. variable
* name that will be converted by PHP: "users.read_only_id"
* will be submitted as "users_read_only_id".
*
* 2. When using $this->Application-LinkVar on variables submitted
* from form which contain $Prefix_Special then note 1st item. Example:
* LinkVar($event->getPrefixSpecial(true).'_varname',$event->Prefix_Special.'_varname')
*
*/
/**
* EventHandler that is used to process
* any database related events
*
*/
class kDBEventHandler extends kEventHandler {
/**
* Description
*
* @var DBConnection
* @access public
*/
var $Conn;
/**
* Adds ability to address db connection
*
* @return kDBEventHandler
* @access public
*/
function kDBEventHandler()
{
parent::kBase();
$this->Conn =& $this->Application->GetADODBConnection();
}
function mapEvents()
{
$events_map = Array('OnRemoveFilters' => 'FilterAction',
'OnApplyFilters' => 'FilterAction');
$this->eventMethods = array_merge($this->eventMethods, $events_map);
}
/**
* 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)
{
//$ret = $this->Application->GetLinkedVar($event->getPrefixSpecial(true).'_id', $event->getPrefixSpecial().'_id');
// ?? We don't need to store selected id in session, as long as we have pass=all by default, which
// means that main item id will be passed to all sub-item screens by default
// another prove of that is that sub-items relay on main item '_mode' = 't' for switching to temp tables
// Also having id in session raised problems with the id of deleted item stuck in session
// 1. get id from post (used in admin)
$ret = $this->Application->GetVar($event->getPrefixSpecial(true).'_id');
if($ret) return $ret;
// 2. get id from env (used in front)
$ret = $this->Application->GetVar($event->getPrefixSpecial().'_id');
if($ret) return $ret;
// recall selected ids array and use the first one
$ids=$this->Application->GetVar($event->getPrefixSpecial().'_selected_ids');
if ($ids != '') {
$ids=explode(',',$ids);
if($ids) $ret=array_shift($ids);
}
else { // if selected ids are not yet stored
$this->StoreSelectedIDs($event);
return $this->Application->GetVar($event->getPrefixSpecial(true).'_id'); // StoreSelectedIDs sets this variable
}
return $ret;
}
/**
* Prepares and stores selected_ids string
* in Session and Application Variables
* by getting all checked ids from grid plus
* id passed in get/post as prefix_id
*
* @param kEvent $event
*/
function StoreSelectedIDs(&$event)
{
$ret = Array();
// May be we don't need this part: ?
$passed = $this->Application->GetVar($event->getPrefixSpecial(true).'_id');
if($passed !== false && $passed != '')
{
array_push($ret, $passed);
}
$ids = Array();
// get selected ids from post & save them to session
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
$id_field = $this->Application->getUnitOption($event->Prefix,'IDField');
foreach($items_info as $id => $field_values)
{
if( getArrayValue($field_values,$id_field) ) array_push($ids,$id);
}
//$ids=array_keys($items_info);
}
$ret = array_unique(array_merge($ret, $ids));
$this->Application->SetVar($event->getPrefixSpecial().'_selected_ids',implode(',',$ret));
$this->Application->LinkVar($event->getPrefixSpecial().'_selected_ids');
// This is critical - otherwise getPassedID will return last ID stored in session! (not exactly true)
// this smells... needs to be refactored
$first_id = getArrayValue($ret,0);
if($first_id === false) trigger_error('Requested ID for prefix <b>'.$event->getPrefixSpecial().'</b> <span class="debug_error">not passed</span>',E_USER_NOTICE);
$this->Application->SetVar($event->getPrefixSpecial(true).'_id', $first_id);
}
/**
* Returns stored selected ids as an array
*
* @param kEvent $event
* @return array
*/
function getSelectedIDs(&$event)
{
return explode(',', $this->Application->GetVar($event->getPrefixSpecial().'_selected_ids'));
}
/**
* Returs associative array of submitted fields for current item
* Could be used while creating/editing single item -
* meaning on any edit form, except grid edit
*
* @param kEvent $event
*/
function getSubmittedFields(&$event)
{
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
$field_values = $items_info ? array_shift($items_info) : Array();
return $field_values;
}
/**
* Removes any information about current/selected ids
* from Application variables and Session
*
* @param kEvent $event
*/
function clearSelectedIDs(&$event)
{
$prefix_special = $event->getPrefixSpecial();
$ids = $this->Application->RecallVar($prefix_special.'_selected_ids');
$event->setEventParam('ids', $ids);
$this->Application->RemoveVar($prefix_special.'_selected_ids');
$this->Application->SetVar($prefix_special.'_selected_ids', '');
$this->Application->SetVar($prefix_special.'_id', ''); // $event->getPrefixSpecial(true).'_id' too may be
}
/*function SetSaveEvent(&$event)
{
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnUpdate');
$this->Application->LinkVar($event->Prefix_Special.'_SaveEvent');
}*/
/**
* Common builder part for Item & List
*
* @param kDBBase $object
* @param kEvent $event
* @access private
*/
function dbBuild(&$object,&$event)
{
$object->Configure();
$live_table = $event->getEventParam('live_table');
if( $this->UseTempTables($event) && !$live_table )
{
$object->SwitchToTemp();
}
// This strange constuction creates hidden field for storing event name in form submit
// It pass SaveEvent to next screen, otherwise after unsuccsefull create it will try to update rather than create
$current_event = $this->Application->GetVar($event->Prefix_Special.'_event');
// $this->Application->setEvent($event->Prefix_Special, $current_event);
$this->Application->setEvent($event->Prefix_Special, '');
$save_event = $this->UseTempTables($event) && $this->Application->GetTopmostPrefix($event->Prefix) == $event->Prefix ? 'OnSave' : 'OnUpdate';
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent',$save_event);
}
/**
* Builds item (loads if needed)
*
* @param kEvent $event
* @access protected
*/
function OnItemBuild(&$event)
{
$object =& $event->getObject();
$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');
if($auto_load) $this->LoadItem($event);
$actions =& $this->Application->recallObject('kActions');
$actions->Set($event->Prefix_Special.'_GoTab', '');
$actions->Set($event->Prefix_Special.'_GoId', '');
}
/**
* Build subtables array from configs
*
* @param kEvent $event
*/
function OnTempHandlerBuild(&$event)
{
$object =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
$object->BuildTables( $event->Prefix, $this->getSelectedIDs($event) );
}
/**
* Enter description here...
*
* @param kEvent $event
* @return unknown
*/
function UseTempTables(&$event)
{
$object = &$event->getObject();
$top_prefix = $this->Application->GetTopmostPrefix($event->Prefix);
return $this->Application->GetVar($top_prefix.'_mode') == 't';
}
/**
* Returns table prefix from event (temp or live)
*
* @param kEvent $event
* @return string
* @todo Needed? Should be refactored (by Alex)
*/
function TablePrefix(&$event)
{
return $this->UseTempTables($event) ? kTempTablesHandler::GetTempTablePrefix().TABLE_PREFIX : TABLE_PREFIX;
}
function LoadItem(&$event)
{
$object =& $event->getObject();
if ( $event->getEventParam('ByParent') ) {
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix');
$parent_table_key = $this->Application->getUnitOption($event->Prefix, 'ParentTableKey');
$parent_object =& $this->Application->recallObject($parent_prefix);
$id = $parent_object->GetDBField($parent_table_key);
$id_field = $this->Application->getUnitOption($event->Prefix, 'ForeignKey');
}
else {
$id = $this->getPassedID($event);
$id_field = null;
}
if ($object->Load($id, $id_field)) {
$actions =& $this->Application->recallObject('kActions');
$actions->Set($event->Prefix_Special.'_id', $object->GetId());
}
}
/**
* Builds list
*
* @param kEvent $event
* @access protected
*/
function OnListBuild(&$event)
{
//$event->setPseudoClass('_List');
$object =& $event->getObject();
$this->dbBuild($object,$event);
$sql = $this->ListPrepareQuery($event);
$sql = $this->Application->ReplaceLanguageTags($sql);
$object->setSelectSQL($sql);
$object->linkToParent( $this->getMainSpecial($event) );
// $object->linkToParent($special);
$this->AddFilters($event);
$this->SetCustomQuery($event); // new!, use this for dynamic queries based on specials for ex.
$this->SetPagination($event);
$this->SetSorting($event);
$actions =& $this->Application->recallObject('kActions');
$actions->Set('remove_specials['.$event->Prefix_Special.']', '0');
$actions->Set($event->Prefix_Special.'_GoTab', '');
}
/**
* Get's special of main item for linking with subitem
*
* @param kEvent $event
* @return string
*/
function getMainSpecial(&$event)
{
$special = $event->getEventParam('main_special');
if($special === false || $special == '$main_special')
{
$special = $event->Special;
}
return $special;
}
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
}
/**
* Set's new perpage for grid
*
* @param kEvent $event
*/
function OnSetPerPage(&$event)
{
$per_page = $this->Application->GetVar($event->getPrefixSpecial(true).'_PerPage');
$this->Application->StoreVar( $event->getPrefixSpecial().'_PerPage', $per_page );
}
/**
* Set's correct page for list
* based on data provided with event
*
* @param kEvent $event
* @access private
* @see OnListBuild
*/
function SetPagination(&$event)
{
// get PerPage (forced -> session -> config -> 10)
$per_page = $event->getEventParam('per_page');
$config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping');
if ( $config_mapping ) {
switch ( $per_page ){
case 'short_list' :
$per_page = $this->Application->ConfigValue($config_mapping['ShortListPerPage']);
break;
case 'default' :
$per_page = $this->Application->ConfigValue($config_mapping['PerPage']);
break;
}
}
if(!$per_page)
{
$per_page_var = $event->getPrefixSpecial().'_PerPage';
$per_page = $this->Application->RecallVar($per_page_var);
if(!$per_page)
{
if ( $config_mapping ) {
$per_page = $this->Application->ConfigValue($config_mapping['PerPage']);
}
if(!$per_page) $per_page = 10;
}
}
$object =& $event->getObject();
$object->SetPerPage($per_page);
$this->Application->StoreVarDefault($event->getPrefixSpecial().'_Page', 1);
$page = $this->Application->GetVar($event->getPrefixSpecial().'_Page');
if (!$page) {
$page = $this->Application->GetVar($event->getPrefixSpecial(true).'_Page');
}
if (!$page) {
$page = $this->Application->RecallVar($event->getPrefixSpecial().'_Page');
}
else {
$this->Application->StoreVar($event->getPrefixSpecial().'_Page', $page);
}
// $page = $this->Application->GetLinkedVar($event->getPrefixSpecial(true).'_Page', $event->getPrefixSpecial().'_Page');
if( !$event->getEventParam('skip_counting') )
{
$pages = $object->GetTotalPages();
if($page > $pages)
{
$this->Application->StoreVar($event->getPrefixSpecial().'_Page', 1);
$page = 1;
}
}
$object->SetPage($page);
}
/**
* Set's correct sorting for list
* based on data provided with event
*
* @param kEvent $event
* @access private
* @see OnListBuild
*/
function SetSorting(&$event)
{
$event->setPseudoClass('_List');
$object =& $event->getObject();
$cur_sort1 = $this->Application->RecallVar($event->Prefix_Special.'_Sort1');
$cur_sort1_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort1_Dir');
$cur_sort2 = $this->Application->RecallVar($event->Prefix_Special.'_Sort2');
$cur_sort2_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort2_Dir');
$sorting_configs = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping');
$list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings');
$sorting_prefix = getArrayValue($list_sortings, $event->Special) ? $event->Special : '';
$tag_sort_by = $event->getEventParam('sort_by');
if ($tag_sort_by) {
list($by, $dir) = explode(',', $tag_sort_by);
if ($by == 'random') $by = 'RAND()';
$object->AddOrderField($by, $dir);
}
if ($sorting_configs && isset ($sorting_configs['DefaultSorting1Field'])){
$list_sortings[$sorting_prefix]['Sorting'] = Array(
$this->Application->ConfigValue($sorting_configs['DefaultSorting1Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting1Dir']),
$this->Application->ConfigValue($sorting_configs['DefaultSorting2Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting2Dir']),
);
}
// Use default if not specified
if ( !$cur_sort1 || !$cur_sort1_dir)
{
if ( $sorting = getArrayValue($list_sortings, $sorting_prefix, 'Sorting') ) {
reset($sorting);
$cur_sort1 = key($sorting);
$cur_sort1_dir = current($sorting);
if (next($sorting)) {
$cur_sort2 = key($sorting);
$cur_sort2_dir = current($sorting);
}
}
}
if ( $forced_sorting = getArrayValue($list_sortings, $sorting_prefix, 'ForcedSorting') ) {
foreach ($forced_sorting as $field => $dir) {
$object->AddOrderField($field, $dir);
}
}
if($cur_sort1 != '' && $cur_sort1_dir != '')
{
$object->AddOrderField($cur_sort1, $cur_sort1_dir);
}
if($cur_sort2 != '' && $cur_sort2_dir != '')
{
$object->AddOrderField($cur_sort2, $cur_sort2_dir);
}
}
/**
* Add filters found in session
*
* @param kEvent $event
*/
function AddFilters(&$event)
{
$object =& $event->getObject();
$search_filter = $this->Application->RecallVar($event->getPrefixSpecial().'_search_filter');
if($search_filter)
{
$search_filter = unserialize($search_filter);
foreach($search_filter as $search_field => $filter_params)
{
$filter_type = ($filter_params['type'] == 'having') ? HAVING_FILTER : WHERE_FILTER;
$object->addFilter($search_field, $filter_params['value'], $filter_type, FLT_SEARCH);
}
}
$view_filter = $this->Application->RecallVar($event->getPrefixSpecial().'_view_filter');
if($view_filter)
{
$view_filter = unserialize($view_filter);
$temp_filter =& $this->Application->makeClass('kMultipleFilter');
$filter_menu = $this->Application->getUnitOption($event->Prefix,'FilterMenu');
$group_key = 0; $group_count = count($filter_menu['Groups']);
while($group_key < $group_count)
{
$group_info = $filter_menu['Groups'][$group_key];
$temp_filter->setType( constant('FLT_TYPE_'.$group_info['mode']) );
$temp_filter->clearFilters();
foreach ($group_info['filters'] as $flt_id)
{
$sql_key = getArrayValue($view_filter,$flt_id) ? 'on_sql' : 'off_sql';
if ($filter_menu['Filters'][$flt_id][$sql_key] != '')
{
$temp_filter->addFilter('view_filter_'.$flt_id, $filter_menu['Filters'][$flt_id][$sql_key]);
}
}
$object->addFilter('view_group_'.$group_key, $temp_filter, $group_info['type'] , FLT_VIEW);
$group_key++;
}
}
}
/**
* Set's new sorting for list
*
* @param kEvent $event
* @access protected
*/
function OnSetSorting(&$event)
{
$cur_sort1 = $this->Application->RecallVar($event->Prefix_Special.'_Sort1');
$cur_sort1_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort1_Dir');
$cur_sort2 = $this->Application->RecallVar($event->Prefix_Special.'_Sort2');
$cur_sort2_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort2_Dir');
$passed_sort1 = $this->Application->GetVar($event->getPrefixSpecial(true).'_Sort1');
if ($cur_sort1 == $passed_sort1) {
$cur_sort1_dir = $cur_sort1_dir == 'asc' ? 'desc' : 'asc';
}
else {
$cur_sort2 = $cur_sort1;
$cur_sort2_dir = $cur_sort1_dir;
$cur_sort1 = $passed_sort1;
$cur_sort1_dir = 'asc';
}
$this->Application->StoreVar($event->Prefix_Special.'_Sort1', $cur_sort1);
$this->Application->StoreVar($event->Prefix_Special.'_Sort1_Dir', $cur_sort1_dir);
$this->Application->StoreVar($event->Prefix_Special.'_Sort2', $cur_sort2);
$this->Application->StoreVar($event->Prefix_Special.'_Sort2_Dir', $cur_sort2_dir);
}
/**
* Set sorting directly to session
*
* @param kEvent $event
*/
function OnSetSortingDirect(&$event)
{
$combined = $this->Application->GetVar($event->getPrefixSpecial(true).'_CombinedSorting');
if ($combined) {
list($field,$dir) = explode('|',$combined);
$this->Application->StoreVar($event->Prefix_Special.'_Sort1', $field);
$this->Application->StoreVar($event->Prefix_Special.'_Sort1_Dir', $dir);
return;
}
$field_pos = $this->Application->GetVar($event->getPrefixSpecial(true).'_SortPos');
$this->Application->LinkVar( $event->getPrefixSpecial(true).'_Sort'.$field_pos, $event->Prefix_Special.'_Sort'.$field_pos);
$this->Application->LinkVar( $event->getPrefixSpecial(true).'_Sort'.$field_pos.'_Dir', $event->Prefix_Special.'_Sort'.$field_pos.'_Dir');
}
/**
* Reset grid sorting to default (from config)
*
* @param kEvent $event
*/
function OnResetSorting(&$event)
{
$this->Application->RemoveVar($event->Prefix_Special.'_Sort1');
$this->Application->RemoveVar($event->Prefix_Special.'_Sort1_Dir');
$this->Application->RemoveVar($event->Prefix_Special.'_Sort2');
$this->Application->RemoveVar($event->Prefix_Special.'_Sort2_Dir');
}
/**
* Creates needed sql query to load item,
* if no query is defined in config for
* special requested, then use default
* query
*
* @param kEvent $event
* @access protected
*/
function ItemPrepareQuery(&$event)
{
$sqls = $this->Application->getUnitOption($event->Prefix,'ItemSQLs');
return isset($sqls[$event->Special]) ? $sqls[$event->Special] : $sqls[''];
}
/**
* Creates needed sql query to load list,
* if no query is defined in config for
* special requested, then use default
* query
*
* @param kEvent $event
* @access protected
*/
function ListPrepareQuery(&$event)
{
$sqls = $this->Application->getUnitOption($event->Prefix,'ListSQLs');
return isset( $sqls[$event->Special] ) ? $sqls[$event->Special] : $sqls[''];
}
/**
* Apply custom processing to item
*
* @param kEvent $event
*/
function customProcessing(&$event, $type)
{
}
/* Edit Events mostly used in Admin */
/**
* Creates new kDBItem
*
* @param kEvent $event
* @access protected
*/
function OnCreate(&$event)
{
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$object =& $event->getObject();
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
list($id,$field_values) = each($items_info);
$object->SetFieldsFromHash($field_values);
}
$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')) )
{
if( $object->IsTempTable() ) $object->setTempID();
$this->customProcessing($event,'after');
$event->status=erSUCCESS;
$event->redirect_params = Array('opener'=>'u');
}
else
{
$event->status=erFAIL;
$event->redirect=false;
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnCreate');
$object->setID($id);
}
}
/**
* Updates kDBItem
*
* @param kEvent $event
* @access protected
*/
function OnUpdate(&$event)
{
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$object =& $event->getObject();
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
foreach($items_info as $id => $field_values)
{
$object->Load($id);
$object->SetFieldsFromHash($field_values);
$this->customProcessing($event, 'before');
if( $object->Update($id) )
{
$this->customProcessing($event, 'after');
$event->status=erSUCCESS;
}
else
{
$event->status=erFAIL;
$event->redirect=false;
break;
}
}
}
$event->redirect_params = Array('opener'=>'u');
}
/**
* Delete's kDBItem object
*
* @param kEvent $event
* @access protected
*/
function OnDelete(&$event)
{
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$object =& $event->getObject();
$object->ID = $this->getPassedID($event);
if( $object->Delete() )
{
$event->status = erSUCCESS;
}
else
{
$event->status = erFAIL;
$event->redirect = false;
}
}
/**
* Prepares new kDBItem object
*
* @param kEvent $event
* @access protected
*/
function OnNew(&$event)
{
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$object =& $event->getObject();
$object->setID(0);
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnCreate');
$table_info = $object->getLinkedInfo();
$object->SetDBField($table_info['ForeignKey'], $table_info['ParentId']);
$this->Application->setUnitOption($event->Prefix,'AutoLoad',true);
$event->redirect = false;
}
/**
* Cancel's kDBItem Editing/Creation
*
* @param kEvent $event
* @access protected
*/
function OnCancel(&$event)
{
$event->redirect_params = Array('opener'=>'u');
}
/**
* Deletes all selected items.
* Automatically recurse into sub-items using temp handler, and deletes sub-items
* by calling its Delete method if sub-item has AutoDelete set to true in its config file
*
* @param kEvent $event
*/
function OnMassDelete(&$event)
{
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ return;
+ }
+
$event->status=erSUCCESS;
$temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
$this->StoreSelectedIDs($event);
$event->setEventParam('ids', $this->getSelectedIDs($event) );
$this->customProcessing($event, 'before');
$ids = $event->getEventParam('ids');
if($ids)
{
$temp->DeleteItems($event->Prefix, $event->Special, $ids);
}
$this->clearSelectedIDs($event);
}
/**
* Prepare temp tables and populate it
* with items selected in the grid
*
* @param kEvent $event
*/
function OnEdit(&$event)
{
$this->StoreSelectedIDs($event);
$temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
$temp->PrepareEdit();
$event->redirect=false;
}
/**
* Saves content of temp table into live and
* redirects to event' default redirect (normally grid template)
*
* @param kEvent $event
*/
function OnSave(&$event)
{
$event->CallSubEvent('OnPreSave');
if ($event->status==erSUCCESS) {
$skip_master=false;
$temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
// newly created item
/*if($this->getPassedID($event) == 0)
{
$master_id = $temp->CopyMasterToOriginal();
$temp->UpdateForeignKeys($master_id); // save linked field values
$skip_master = true; //we've already copied master table to get the id
}*/
- $temp->SaveEdit($skip_master);
+ if (!$this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ $temp->SaveEdit($skip_master);
+ }
$this->clearSelectedIDs($event);
$event->redirect_params = Array('opener'=>'u');
$this->Application->RemoveVar($event->getPrefixSpecial().'_modified');
}
}
/**
* Cancels edit
* Removes all temp tables and clears selected ids
*
* @param kEvent $event
*/
function OnCancelEdit(&$event)
{
$temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
$temp->CancelEdit();
$this->clearSelectedIDs($event);
$event->redirect_params = Array('opener'=>'u');
$this->Application->RemoveVar($event->getPrefixSpecial().'_modified');
}
/**
* Saves edited item into temp table
* If there is no id, new item is created in temp table
*
* @param kEvent $event
*/
function OnPreSave(&$event)
{
//$event->redirect = false;
// if there is no id - it means we need to create an item
if (is_object($event->MasterEvent)) {
$event->MasterEvent->setEventParam('IsNew',false);
}
$item_id = $this->getPassedID($event);
if($item_id == '')
{
$event->CallSubEvent('OnPreSaveCreated');
if (is_object($event->MasterEvent)) {
$event->MasterEvent->setEventParam('IsNew',true);
}
return;
}
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$object =& $event->getObject();
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
foreach($items_info as $id => $field_values)
{
$object->SetDefaultValues();
$object->Load($id);
$object->SetFieldsFromHash($field_values);
if( $object->Update($id) )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFAIL;
$event->redirect=false;
break;
}
}
}
}
/**
* Saves edited item in temp table and loads
* item with passed id in current template
* Used in Prev/Next buttons
*
* @param kEvent $event
*/
function OnPreSaveAndGo(&$event)
{
$event->CallSubEvent('OnPreSave');
if ($event->status==erSUCCESS) {
$event->redirect_params[$event->getPrefixSpecial(true).'_id'] = $this->Application->GetVar($event->Prefix_Special.'_GoId');
}
}
/**
* Saves edited item in temp table and goes
* to passed tabs, by redirecting to it with OnPreSave event
*
* @param kEvent $event
*/
function OnPreSaveAndGoToTab(&$event)
{
$event->CallSubEvent('OnPreSave');
if ($event->status==erSUCCESS) {
$event->redirect=$this->Application->GetVar($event->getPrefixSpecial(true).'_GoTab');
}
}
/**
* Saves editable list and goes to passed tab,
* by redirecting to it with empty event
*
* @param kEvent $event
*/
function OnUpdateAndGoToTab(&$event)
{
$event->setPseudoClass('_List');
$event->CallSubEvent('OnUpdate');
if ($event->status==erSUCCESS) {
$event->redirect=$this->Application->GetVar($event->getPrefixSpecial(true).'_GoTab');
}
}
/**
* Prepare temp tables for creating new item
* but does not create it. Actual create is
* done in OnPreSaveCreated
*
* @param kEvent $event
*/
function OnPreCreate(&$event)
{
$this->clearSelectedIDs($event);
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$object =& $event->getObject();
$temp =& $this->Application->recallObject($event->Prefix.'_TempHandler', 'kTempTablesHandler');
$temp->PrepareEdit();
$object->setID(0);
$event->redirect=false;
}
/**
* Creates a new item in temp table and
* stores item id in App vars and Session on succsess
*
* @param kEvent $event
*/
function OnPreSaveCreated(&$event)
{
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info) $field_values = array_shift($items_info);
$object =& $event->getObject();
$object->SetFieldsFromHash($field_values);
$this->customProcessing($event, 'before');
if( $object->Create() )
{
$this->customProcessing($event, 'after');
$event->redirect_params[$event->getPrefixSpecial(true).'_id'] = $object->GetId();
$event->status=erSUCCESS;
}
else
{
$event->status=erFAIL;
$event->redirect=false;
$object->setID(0);
}
}
/* End of Edit events */
// 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
*
* @param kEvent $event
* @access public
*/
function OnBeforeItemLoad(&$event)
{
}
/**
* Occurse after loading item, 'id' parameter
* allows to get id of item that was loaded
*
* @param kEvent $event
* @access public
*/
function OnAfterItemLoad(&$event)
{
}
/**
* Occurse before creating item
*
* @param kEvent $event
* @access public
*/
function OnBeforeItemCreate(&$event)
{
}
/**
* Occurse after creating item
*
* @param kEvent $event
* @access public
*/
function OnAfterItemCreate(&$event)
{
}
/**
* Occurse before updating item
*
* @param kEvent $event
* @access public
*/
function OnBeforeItemUpdate(&$event)
{
}
/**
* Occurse after updating item
*
* @param kEvent $event
* @access public
*/
function OnAfterItemUpdate(&$event)
{
}
/**
* Occurse before deleting item, id of item beeing
* deleted is stored as 'id' event param
*
* @param kEvent $event
* @access public
*/
function OnBeforeItemDelete(&$event)
{
}
/**
* Occurse after deleting item, id of deleted item
* is stored as 'id' param of event
*
* @param kEvent $event
* @access public
*/
function OnAfterItemDelete(&$event)
{
}
/**
* Occurs after successful item validation
*
* @param kEvent $event
*/
function OnAfterItemValidate(&$event)
{
}
/**
* Occures after an item has been copied to temp
* Id of copied item is passed as event' 'id' param
*
* @param kEvent $event
*/
function OnAfterCopyToTemp(&$event)
{
}
/**
* Occures before an item is deleted from live table when copying from temp
* (temp handler deleted all items from live and then copy over all items from temp)
* Id of item being deleted is passed as event' 'id' param
*
* @param kEvent $event
*/
function OnBeforeDeleteFromLive(&$event)
{
}
/**
* Occures 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
*/
function OnBeforeCopyToLive(&$event)
{
}
/**
* !!! NOT FULLY IMPLEMENTED - SEE TEMP HANDLER COMMENTS (search by event name)!!!
* Occures after an item has been copied to live table
* Id of copied item is passed as event' 'id' param
*
* @param kEvent $event
*/
function OnAfterCopyToLive(&$event)
{
}
/**
* Occures before an item is cloneded
* Id of ORIGINAL item is passed as event' 'id' param
* Do not call object' Update method in this event, just set needed fields!
*
* @param kEvent $event
*/
function OnBeforeClone(&$event)
{
}
/**
* Occures after an item has been cloned
* Id of newly created item is passed as event' 'id' param
*
* @param kEvent $event
*/
function OnAfterClone(&$event)
{
}
/**
* Ensures that popup will be closed automatically
* and parent window will be refreshed with template
* passed
*
* @param kEvent $event
* @access public
*/
function finalizePopup(&$event, $main_prefix, $t)
{
$event->redirect = 'incs/close_popup';
// 2. substitute opener
$opener_stack = $this->Application->RecallVar('opener_stack');
$opener_stack = $opener_stack ? unserialize($opener_stack) : Array();
//array_pop($opener_stack);
$new_level = 'index4.php|'.ltrim($this->Application->BuildEnv($t, Array('m_opener' => 'u'), 'all'), ENV_VAR_NAME.'=');
array_push($opener_stack,$new_level);
$this->Application->StoreVar('opener_stack',serialize($opener_stack));
}
/**
* Create search filters based on search query
*
* @param kEvent $event
* @access protected
*/
function OnSearch(&$event)
{
$event->setPseudoClass('_List');
$object =& $event->getObject();
$keyword = $this->Application->GetVar( $event->getPrefixSpecial(true).'_search_keyword');
$this->Application->StoreVar( $event->getPrefixSpecial().'_search_keyword', $keyword);
if(!$keyword)
{
$this->OnSearchReset($event);
return true;
}
$grid_name = $this->Application->GetVar('grid_name');
$grids = $this->Application->getUnitOption($event->Prefix,'Grids');
$search_fields = array_keys($grids[$grid_name]['Fields']);
$search_filter = Array();
foreach($search_fields as $search_field)
{
$filter_type = isset($object->VirtualFields[$search_field]) ? 'having' : 'where';
$field_type = getArrayValue($object->Fields[$search_field],'type');
if(!$field_type) $field_type = 'string'; // default LIKE filter for all fields without type
$keyword = trim($keyword);
$keyword = str_replace(Array('"',"'"),'',$keyword);
$filter_value = '';
$table_name = ($filter_type == 'where') ? '`'.$object->TableName.'`.' : '';
// get field clause by formatter name and/or parameters
$formatter = getArrayValue($object->Fields[$search_field],'formatter');
switch ($formatter)
{
case 'kOptionsFormatter':
$search_keys = Array();
$use_phrases = getArrayValue($object->Fields[$search_field], 'use_phrases');
foreach($object->Fields[$search_field]['options'] as $key => $val)
{
$pattern = '#'.$keyword.'#i';
if ( preg_match($pattern, $use_phrases ? $this->Application->Phrase($val) : $val) ) {
array_push($search_keys, $key);
}
}
if (count($search_keys) > 0) {
$filter_value = $table_name.'`'.$search_field.'` IN ('.implode(',', $search_keys).')';
}
$field_processed = true;
break;
default:
$field_processed = false;
break;
}
// if not already processed by formatter, then get clause by field type
if(!$field_processed)
{
switch($field_type)
{
case 'int':
case 'integer':
case 'numeric':
if( !is_numeric($keyword) ) break;
$filter_value = $table_name.'`'.$search_field.'` = \''.$keyword.'\'';
break;
case 'double':
case 'float':
case 'real':
if( !is_numeric($keyword) ) break;
$filter_value = 'ABS('.$table_name.'`'.$search_field.'` - \''.str_replace(',','.',$keyword).'\') <= 0.0001';
break;
case 'string':
$like_keyword = preg_replace( '/\'(.*)\'/U', '\\1', $this->Conn->qstr( str_replace('\\','\\\\', $keyword) ) );
$keywords = explode(' ', $like_keyword);
foreach($keywords as $keyword_pos => $keyword_value)
{
$keyword_value = trim($keyword_value);
if($keyword_value)
{
$keywords[$keyword_pos] = $table_name.'`'.$search_field.'` LIKE \'%'.$keyword_value.'%\'';
}
else
{
unset($keywords[$keyword_pos]);
}
}
$filter_value = '('.implode(') OR (',$keywords).')';
break;
}
}
if($filter_value) $search_filter[$search_field] = Array('type' => $filter_type, 'value' => $filter_value);
}
$this->Application->StoreVar($event->getPrefixSpecial().'_search_filter', serialize($search_filter) );
}
/**
* Clear search keywords
*
* @param kEvent $event
* @access protected
*/
function OnSearchReset(&$event)
{
$this->Application->RemoveVar($event->getPrefixSpecial().'_search_filter');
$this->Application->RemoveVar($event->getPrefixSpecial().'_search_keyword');
}
/**
* Set's new filter value (filter_id meaning from config)
*
* @param kEvent $event
*/
function OnSetFilter(&$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[$filter_id] = $filter_value;
$this->Application->StoreVar( $event->getPrefixSpecial().'_view_filter', serialize($view_filter) );
}
/**
* Add/Remove all filters applied to list from "View" menu
*
* @param kEvent $event
*/
function FilterAction(&$event)
{
$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;
}
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) );
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnPreSaveAndOpenTranslator(&$event)
{
$this->Application->SetVar('allow_translation', true);
$object =& $event->getObject();
$this->RemoveRequiredFields($object);
$event->CallSubEvent('OnPreSave');
if ($event->status == erSUCCESS) {
// $url = $this->Application->HREF($t, '', Array('pass'=>'all', $event->getPrefixSpecial(true).'_id' => $object->GetId()));
// $field = $this->Application->GetVar('translator_field');
$event->redirect = $this->Application->GetVar('translator_t');
$event->redirect_params = Array('pass'=>'all,trans,'.$this->Application->GetVar('translator_prefixes'),
$event->getPrefixSpecial(true).'_id' => $object->GetId(),
'trans_event'=>'OnLoad',
'trans_prefix'=> $this->Application->GetVar('translator_prefixes'),
'trans_field'=>$this->Application->GetVar('translator_field'),
);
//$after_script = "openTranslator('".$event->getPrefixSpecial()."', '".$field."', '".$url."', '".$wnd_name."')";
}
// $this->Application->SetVar('after_script', $after_script);
// $event->redirect = false;
}
function RemoveRequiredFields(&$object)
{
// making all field non-required to achieve successful presave
foreach($object->Fields as $field => $options)
{
if(isset($options['required']))
{
unset($object->Fields[$field]['required']);
}
}
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/db/db_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.11
\ No newline at end of property
+1.12
\ No newline at end of property
Index: trunk/core/kernel/application.php
===================================================================
--- trunk/core/kernel/application.php (revision 1820)
+++ trunk/core/kernel/application.php (revision 1821)
@@ -1,1297 +1,1300 @@
<?php
/**
* Basic class for Kernel3-based Application
*
* This class is a Facade for any other class which needs to deal with Kernel3 framework.<br>
* The class incapsulates the main run-cycle of the script, provide access to all other objects in the framework.<br>
* <br>
* The class is a singleton, which means that there could be only one instance of KernelApplication in the script.<br>
* This could be guranteed by NOT calling the class constuctor directly, but rather calling KernelApplication::Instance() method,
* which returns an instance of the application. The method gurantees that it will return exactly the same instance for any call.<br>
* See singleton pattern by GOF.
* @package kernel4
*/
class kApplication {
/**
* Is true, when Init method was called already, prevents double initialization
*
* @var bool
*/
var $InitDone = false;
/**
* Holds internal TemplateParser object
* @access private
* @var TemplateParser
*/
var $Parser;
/**
* Holds parser output buffer
* @access private
* @var string
*/
var $HTML;
/**
* Prevents request from beeing proceeded twice in case if application init is called mere then one time
*
* @var bool
* @todo This is not good anyway (by Alex)
*/
var $RequestProcessed = false;
/**
* The main Factory used to create
* almost any class of kernel and
* modules
*
* @access private
* @var kFactory
*/
var $Factory;
/**
* Holds all phrases used
* in code and template
*
* @var PhrasesCache
*/
var $Phrases;
/**
* Holds DBConnection
*
* @var kDBConnection
*/
var $DB;
/**
* Returns kApplication instance anywhere in the script.
*
* This method should be used to get single kApplication object instance anywhere in the
* Kernel-based application. The method is guranteed to return the SAME instance of kApplication.
* Anywhere in the script you could write:
* <code>
* $application =& kApplication::Instance();
* </code>
* or in an object:
* <code>
* $this->Application =& kApplication::Instance();
* </code>
* to get the instance of kApplication. Note that we call the Instance method as STATIC - directly from the class.
* To use descendand of standard kApplication class in your project you would need to define APPLICATION_CLASS constant
* BEFORE calling kApplication::Instance() for the first time. If APPLICATION_CLASS is not defined the method would
* create and return default KernelApplication instance.
* @static
* @access public
* @return kApplication
*/
function &Instance()
{
static $instance = false;
if(!$instance)
{
if (!defined('APPLICATION_CLASS')) define('APPLICATION_CLASS', 'kApplication');
$class = APPLICATION_CLASS;
$instance = new $class();
}
return $instance;
}
/**
* Initializes the Application
*
* @access public
* @see HTTPQuery
* @see Session
* @see TemplatesCache
* @return bool Was Init actually made now or before
*/
function Init()
{
if($this->InitDone) return false;
if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
global $debugger;
$debugger->appendMemoryUsage('Application before Init:');
}
if( !$this->isDebugMode() ) set_error_handler( Array(&$this,'handleError') );
$this->DB = new kDBConnection(SQL_TYPE, Array(&$this,'handleSQLError') );
$this->DB->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB);
$this->DB->debugMode = $this->isDebugMode();
$this->SetDefaultConstants();
$this->Factory = new kFactory();
$this->registerDefaultClasses();
// 1. to read configs before doing any recallObject
$config_reader =& $this->recallObject('kUnitConfigReader');
if( !$this->GetVar('m_lang') ) $this->SetVar('m_lang', $this->GetDefaultLanguageId() );
if( !$this->GetVar('m_theme') ) $this->SetVar('m_theme', $this->GetDefaultThemeId() );
$this->Phrases = new PhrasesCache( $this->GetVar('m_lang') );
$this->SetVar('lang.current_id', $this->GetVar('m_lang') );
$language =& $this->recallObject('lang.current', null, Array('live_table'=>true) );
if( !$this->GetVar('m_theme') ) $this->SetVar('m_theme', $this->GetDefaultThemeId() );
$this->SetVar('theme.current_id', $this->GetVar('m_theme') );
if( !$this->RecallVar('UserGroups') )
{
- $this->StoreVar('UserGroups', $this->ConfigValue('User_GuestGroup'));
+ $ses =& $this->recallObject('Session');
+ $user_groups = trim($ses->GetField('GroupList'), ',');
+ if (!$user_groups) $user_groups = $this->ConfigValue('User_GuestGroup');
+ $this->StoreVar('UserGroups', $user_groups);
}
if( !$this->RecallVar('curr_iso') ) $this->StoreVar('curr_iso', $this->GetPrimaryCurrency() );
$this->ValidateLogin(); // TODO: write that method
if( $this->isDebugMode() )
{
global $debugger;
$debugger->profileFinish('kernel4_startup');
}
$this->InitDone = true;
return true;
}
function GetDefaultLanguageId()
{
$table = $this->getUnitOption('lang','TableName');
$id_field = $this->getUnitOption('lang','IDField');
return $this->DB->GetOne('SELECT '.$id_field.' FROM '.$table.' WHERE PrimaryLang = 1');
}
function GetDefaultThemeId()
{
if (defined('DBG_FORCE_THEME') && DBG_FORCE_THEME){
return DBG_FORCE_THEME;
}
$table = $this->getUnitOption('theme','TableName');
$id_field = $this->getUnitOption('theme','IDField');
return $this->DB->GetOne('SELECT '.$id_field.' FROM '.$table.' WHERE PrimaryTheme = 1');
}
function GetPrimaryCurrency()
{
$this->setUnitOption('mod','AutoLoad',false);
$module =& $this->recallObject('mod');
$this->setUnitOption('mod','AutoLoad',true);
if( $module->Load('In-Commerce') )
{
$table = $this->getUnitOption('curr','TableName');
return $this->DB->GetOne('SELECT ISO FROM '.$table.' WHERE IsPrimary = 1');
}
else
{
return 'USD';
}
}
/**
* Registers default classes such as ItemController, GridController and LoginController
*
* Called automatically while initializing Application
* @access private
* @return void
*/
function RegisterDefaultClasses()
{
//$this->registerClass('Utilites',KERNEL_PATH.'/utility/utilities.php');
$this->registerClass('HTTPQuery',KERNEL_PATH.'/utility/http_query.php');
$this->registerClass('Session',KERNEL_PATH.'/session/session.php');
$this->registerClass('SessionStorage',KERNEL_PATH.'/session/session.php');
$this->registerClass('LoginEventHandler',KERNEL_PATH.'/session/login_event_handler.php','login_EventHandler');
$this->registerClass('kEventManager',KERNEL_PATH.'/event_manager.php','EventManager');
$this->registerClass('kUnitConfigReader',KERNEL_PATH.'/utility/unit_config_reader.php');
$this->registerClass('Params',KERNEL_PATH.'/utility/params.php','kActions');
$this->registerClass('kArray',KERNEL_PATH.'/utility/params.php','kArray');
$this->registerClass('kFormatter', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kOptionsFormatter', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kPictureFormatter', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kDateFormatter', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kLEFTFormatter', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kMultiLanguage', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kPasswordFormatter', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kCCDateFormatter', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kUnitFormatter', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kTempTablesHandler', KERNEL_PATH.'/utility/temp_handler.php');
$event_manager =& $this->recallObject('EventManager');
$event_manager->registerBuildEvent('kTempTablesHandler','OnTempHandlerBuild');
//$this->registerClass('Configuration',KERNEL_PATH.'/utility/configuration.php');
$this->registerClass('TemplatesCache',KERNEL_PATH.'/parser/template.php');
$this->registerClass('Template',KERNEL_PATH.'/parser/template.php');
$this->registerClass('TemplateParser',KERNEL_PATH.'/parser/template_parser.php');
$this->registerClass('MainProcessor', KERNEL_PATH.'/processors/main_processor.php','m_TagProcessor');
$this->registerClass('kMultipleFilter', KERNEL_PATH.'/utility/filters.php');
$this->registerClass('kDBList', KERNEL_PATH.'/db/dblist.php');
$this->registerClass('kDBItem', KERNEL_PATH.'/db/dbitem.php');
$this->registerClass('kDBEventHandler', KERNEL_PATH.'/db/db_event_handler.php');
$this->registerClass('kDBTagProcessor', KERNEL_PATH.'/db/db_tag_processor.php');
$this->registerClass('kTagProcessor', KERNEL_PATH.'/processors/tag_processor.php');
$this->registerClass('kEmailMessage',KERNEL_PATH.'/utility/email.php');
$this->registerClass('kSmtpClient',KERNEL_PATH.'/utility/smtp_client.php');
if (file_exists(MODULES_PATH.'/in-commerce/units/rates/currency_rates.php')) {
$this->registerClass('kCurrencyRates',MODULES_PATH.'/in-commerce/units/rates/currency_rates.php');
}
$this->registerClass('FCKeditor', DOC_ROOT.BASE_PATH.'/'.ADMIN_DIR.'/editor/cmseditor/fckeditor.php');
/*$this->RegisterClass('LoginController', KERNEL_PATH.'/users/login_controller.php');*/
}
/**
* Defines default constants if it's not defined before - in config.php
*
* Called automatically while initializing Application and defines:
* LOGIN_CONTROLLER, XML_FACTORY etc.
* @access private
* @return void
*/
function SetDefaultConstants()
{
if (!defined('SERVER_NAME')) define('SERVER_NAME', $_SERVER['HTTP_HOST']);
$admin_dir = $this->ConfigValue('AdminDirectory');
if(!$admin_dir) $admin_dir = 'admin';
safeDefine('ADMIN_DIR', $admin_dir);
}
function ProcessRequest()
{
$event_manager =& $this->recallObject('EventManager');
if( $this->isDebugMode() && dbg_ConstOn('DBG_SHOW_HTTPQUERY') )
{
global $debugger;
$http_query =& $this->recallObject('HTTPQuery');
$debugger->appendHTML('HTTPQuery:');
$debugger->dumpVars($http_query->_Params);
}
$event_manager->ProcessRequest();
$this->RequestProcessed = true;
}
/**
* Actually runs the parser against current template and stores parsing result
*
* This method gets t variable passed to the script, loads the template given in t variable and
* parses it. The result is store in {@link $this->HTML} property.
* @access public
* @return void
*/
function Run()
{
if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
global $debugger;
$debugger->appendMemoryUsage('Application before Run:');
}
if (!$this->RequestProcessed) $this->ProcessRequest();
$this->InitParser();
$template_cache =& $this->recallObject('TemplatesCache');
$t = $this->GetVar('t');
if (defined('CMS') && CMS) {
$cms_handler =& $this->recallObject('cms_EventHandler');
if (!$template_cache->TemplateExists($t)) {
$t = $cms_handler->GetDesignTemplate();
}
else {
$cms_handler->SetCatByTemplate();
}
}
if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
global $debugger;
$debugger->appendMemoryUsage('Application before Parsing:');
}
$this->HTML = $this->Parser->Parse( $template_cache->GetTemplateBody($t), $t );
if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
global $debugger;
$debugger->appendMemoryUsage('Application after Parsing:');
}
}
function InitParser()
{
if( !is_object($this->Parser) ) $this->Parser =& $this->recallObject('TemplateParser');
}
/**
* Send the parser results to browser
*
* Actually send everything stored in {@link $this->HTML}, to the browser by echoing it.
* @access public
* @return void
*/
function Done()
{
if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
global $debugger;
$debugger->appendMemoryUsage('Application before Done:');
}
if ($this->GetVar('admin')) {
$reg = '/('.preg_quote(BASE_PATH, '/').'.*\.html)(#.*){0,1}(")/sU';
$this->HTML = preg_replace($reg, "$1?admin=1$2$3", $this->HTML);
}
//eval("?".">".$this->HTML);
echo $this->HTML;
$this->Phrases->UpdateCache();
$session =& $this->recallObject('Session');
$session->SaveData();
//$this->SaveBlocksCache();
}
function SaveBlocksCache()
{
if (defined('EXPERIMENTAL_PRE_PARSE')) {
$data = serialize($this->PreParsedCache);
$this->DB->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("blocks_cache", '.$this->DB->qstr($data).', '.time().')');
}
}
// Facade
/**
* Returns current session id (SID)
* @access public
* @return longint
*/
function GetSID()
{
$session =& $this->recallObject('Session');
return $session->GetID();
}
function DestroySession()
{
$session =& $this->recallObject('Session');
$session->Destroy();
}
/**
* Returns variable passed to the script as GET/POST/COOKIE
*
* @access public
* @param string $var Variable name
* @return mixed
*/
function GetVar($var,$mode=FALSE_ON_NULL)
{
$http_query =& $this->recallObject('HTTPQuery');
return $http_query->Get($var,$mode);
}
/**
* Returns ALL variables passed to the script as GET/POST/COOKIE
*
* @access public
* @return array
*/
function GetVars()
{
$http_query =& $this->recallObject('HTTPQuery');
return $http_query->GetParams();
}
/**
* Set the variable 'as it was passed to the script through GET/POST/COOKIE'
*
* This could be useful to set the variable when you know that
* other objects would relay on variable passed from GET/POST/COOKIE
* or you could use SetVar() / GetVar() pairs to pass the values between different objects.<br>
*
* This method is formerly known as $this->Session->SetProperty.
* @param string $var Variable name to set
* @param mixed $val Variable value
* @access public
* @return void
*/
function SetVar($var,$val)
{
$http_query =& $this->recallObject('HTTPQuery');
$http_query->Set($var,$val);
}
/**
* Deletes Session variable
*
* @param string $var
*/
function RemoveVar($var)
{
$session =& $this->recallObject('Session');
return $session->RemoveVar($var);
}
/**
* Deletes HTTPQuery variable
*
* @param string $var
* @todo think about method name
*/
function DeleteVar($var)
{
$http_query =& $this->recallObject('HTTPQuery');
return $http_query->Remove($var);
}
/**
* Returns session variable value
*
* Return value of $var variable stored in Session. An optional default value could be passed as second parameter.
*
* @see SimpleSession
* @access public
* @param string $var Variable name
* @param mixed $default Default value to return if no $var variable found in session
* @return mixed
*/
function RecallVar($var,$default=false)
{
$session =& $this->recallObject('Session');
return $session->RecallVar($var,$default);
}
/**
* Stores variable $val in session under name $var
*
* Use this method to store variable in session. Later this variable could be recalled.
* @see RecallVar
* @access public
* @param string $var Variable name
* @param mixed $val Variable value
*/
function StoreVar($var, $val)
{
$session =& $this->recallObject('Session');
$session->StoreVar($var, $val);
}
function StoreVarDefault($var, $val)
{
$session =& $this->recallObject('Session');
$session->StoreVarDefault($var, $val);
}
/**
* Links HTTP Query variable with session variable
*
* If variable $var is passed in HTTP Query it is stored in session for later use. If it's not passed it's recalled from session.
* This method could be used for making sure that GetVar will return query or session value for given
* variable, when query variable should overwrite session (and be stored there for later use).<br>
* This could be used for passing item's ID into popup with multiple tab -
* in popup script you just need to call LinkVar('id', 'current_id') before first use of GetVar('id').
* After that you can be sure that GetVar('id') will return passed id or id passed earlier and stored in session
* @access public
* @param string $var HTTP Query (GPC) variable name
* @param mixed $ses_var Session variable name
* @param mixed $default Default variable value
*/
function LinkVar($var, $ses_var=null, $default='')
{
if (!isset($ses_var)) $ses_var = $var;
if ($this->GetVar($var) !== false)
{
$this->StoreVar($ses_var, $this->GetVar($var));
}
else
{
$this->SetVar($var, $this->RecallVar($ses_var, $default));
}
}
/**
* Returns variable from HTTP Query, or from session if not passed in HTTP Query
*
* The same as LinkVar, but also returns the variable value taken from HTTP Query if passed, or from session if not passed.
* Returns the default value if variable does not exist in session and was not passed in HTTP Query
*
* @see LinkVar
* @access public
* @param string $var HTTP Query (GPC) variable name
* @param mixed $ses_var Session variable name
* @param mixed $default Default variable value
* @return mixed
*/
function GetLinkedVar($var, $ses_var=null, $default='')
{
if (!isset($ses_var)) $ses_var = $var;
$this->LinkVar($var, $ses_var, $default);
return $this->GetVar($var);
}
/*function ExtractByMask($array, $mask, $key_id=1, $ret_mode=1)
{
$utils =& $this->recallObject('Utilities');
return $utils->ExtractByMask($array, $mask, $key_id, $ret_mode);
}
function GetSelectedIDs($mask, $format)
{
$http_query =& $this->recallObject('HTTPQuery');
return $http_query->GetSelectedIDs($mask, $format);
}
function GetSelectedIDsArray($mask, $value_mask="%s,")
{
$http_query =& $this->recallObject('HTTPQuery');
return $http_query->GetSelectedIDsArray($mask, $value_mask);
}*/
/**
* Returns configurtion option
*
* @param string $option
* @return string
* @access public
*/
/*function ConfigOption($option)
{
$config =& $this->recallObject('Configuration');
return $config->Get($option);
}*/
/**
* Sets configuration option
*
* @param string $option
* @param string $value
* @return bool
* @access public
*/
/*function SetConfigOption($option,$value)
{
$config =& $this->recallObject('Configuration');
return $config->Set($option, $value);
}*/
function AddBlock($name, $tpl)
{
$this->cache[$name] = $tpl;
}
function SetTemplateBody($title,$body)
{
$templates_cache =& $this->recallObject('TemplatesCache');
$templates_cache->SetTemplateBody($title,$body);
}
function ProcessTag($tag_data)
{
$a_tag = new Tag($tag_data,$this->Parser);
return $a_tag->DoProcessTag();
}
function ProcessParsedTag($prefix, $tag, $params)
{
$a_tag = new Tag('',$this->Parser);
$a_tag->Tag = $tag;
$a_tag->Processor = $prefix;
$a_tag->NamedParams = $params;
return $a_tag->DoProcessTag();
}
/* DEFINETLY NEEDS TO BE MOVED AWAY!!!!! */
/*var $email_body;
function Email($params)
{
$this->email_body = $this->ParseBlock($params);
$from = $this->GetVar('email_from');
$to = $this->GetVar('email_to');
$replay = $this->GetVar('email_replay');
if ( $replay == "" ) $replay = $from;
$subject = $this->GetVar('email_subject');
$charset = $this->GetVar('email_charset');
// $display = $this->GetVar('email_display');
$display = 0;
if (!isset($charset) || $charset == '') $charset = 'US-ASCII';
$mime = $this->GetVar('email_mime');
if ($mime == 'yes') {
$mime_mail = new MIMEMail($to, $from, $subject, $charset);
$mime_mail->mailbody($this->email_body);
if ($f_name = $this->GetVar('email_attach')) {
$full_path = DOC_ROOT.BASE_PATH.'/'.$f_name;
$data = '';
if(file_exists($full_path)) {
$fd = fopen($full_path, "r");
$data = fread($fd, filesize($full_path));
fclose($fd);
}
else exit;
$filename = $this->GetVar('email_attach_filename');
$type = $this->GetVar('email_attach_type');
$mime_mail->attachfile_raw($data, $filename, $type);
$mime_mail->send();
}
}
else {
$headers.="From: $from\n";
$headers.="Reply-To: $replay\n";
$headers.="Content-Type: text/html; charset=\"$charset\"\n";
if ( $display == 1 ) {
echo "<pre>";
echo " from : $from <br>";
echo " to : $to <br>";
echo " replay : $replay <br>";
echo " subject : $subject <br>";
echo " this->email_body : $this->email_body <br>";
echo " headers : $headers <br>";
echo "</pre>";
}
mail($to, $subject, $this->email_body, $headers);
}
}*/
/**
* Return ADODB Connection object
*
* Returns ADODB Connection object already connected to the project database, configurable in config.php
* @access public
* @return ADODBConnection
*/
function &GetADODBConnection()
{
return $this->DB;
}
function ParseBlock($params,$pass_params=0,$as_template=false)
{
if (substr($params['name'], 0, 5) == 'html:') return substr($params['name'], 6);
return $this->Parser->ParseBlock($params, $pass_params, $as_template);
}
function &GetXMLFactory()
{
return $this->XMLFactory;
}
/**
* Return href for template
*
* @access public
* @param string $t Template path
* @var string $prefix index.php prefix - could be blank, 'admin'
*/
function HREF($t, $prefix='', $params=null, $index_file=null)
{
global $HTTP_SERVER_VARS;
if (defined('ADMIN') && $prefix == '') $prefix='/admin';
if (defined('ADMIN') && $prefix == '_FRONT_END_') $prefix = '';
$index_file = isset($index_file) ? $index_file : (defined('INDEX_FILE') ? INDEX_FILE : basename($_SERVER['PHP_SELF']));
if( isset($params['index_file']) ) $index_file = $params['index_file'];
if (getArrayValue($params, 'opener') == 'u') {
$opener_stack=$this->RecallVar('opener_stack');
if($opener_stack) {
$opener_stack=unserialize($opener_stack);
if (count($opener_stack) > 0) {
list($index_file, $env) = explode('|', $opener_stack[count($opener_stack)-1]);
$ret = $this->BaseURL($prefix).$index_file.'?'.ENV_VAR_NAME.'='.$env;
if( getArrayValue($params,'escape') ) $ret = addslashes($ret);
return $ret;
}
else {
//define('DBG_REDIRECT', 1);
$t = $this->GetVar('t');
}
}
else {
//define('DBG_REDIRECT', 1);
$t = $this->GetVar('t');
}
}
$pass = isset($params['pass']) ? $params['pass'] : '';
$pass_events = isset($params['pass_events']) ? $params['pass_events'] : false; // pass events with url
if (defined('MOD_REWRITE') && MOD_REWRITE) {
$env = $this->BuildEnv('', $params, $pass, $pass_events, false);
$env = ltrim($env, ':-');
$session =& $this->recallObject('Session');
$sid = $session->NeedQueryString() ? '?sid='.$this->GetSID() : '';
// $env = str_replace(':', '/', $env);
$ret = rtrim($this->BaseURL($prefix).$t.'.html/'.$env.'/'.$sid, '/');
}
else {
$env = $this->BuildEnv($t, $params, $pass, $pass_events);
$ret = $this->BaseURL($prefix).$index_file.'?'.$env;
}
return $ret;
}
function BuildEnv($t, $params, $pass='all', $pass_events=false, $env_var=true)
{
$session =& $this->recallObject('Session');
$sid = $session->NeedQueryString() && !(defined('MOD_REWRITE') && MOD_REWRITE) ? $this->GetSID() : '';
if( getArrayValue($params,'admin') == 1 ) $sid = $this->GetSID();
$ret = '';
if ($env_var) {
$ret = ENV_VAR_NAME.'=';
}
$ret .= defined('INPORTAL_ENV') ? $sid.'-'.$t : $sid.':'.$t;
$pass = str_replace('all', trim($this->GetVar('passed'), ','), $pass);
if(strlen($pass) > 0)
{
$pass_info = array_unique( explode(',',$pass) ); // array( prefix[.special], prefix[.special] ...
foreach($pass_info as $pass_element)
{
$ret.=':';
list($prefix)=explode('.',$pass_element);
$query_vars = $this->getUnitOption($prefix,'QueryString');
//if pass events is off and event is not implicity passed
if(!$pass_events && !isset($params[$pass_element.'_event'])) {
$params[$pass_element.'_event'] = ''; // remove event from url if requested
//otherwise it will use value from get_var
}
if($query_vars)
{
$tmp_string=Array(0=>$pass_element);
foreach($query_vars as $index => $var_name)
{
//if value passed in params use it, otherwise use current from application
$tmp_string[$index] = isset( $params[$pass_element.'_'.$var_name] ) ? $params[$pass_element.'_'.$var_name] : $this->GetVar($pass_element.'_'.$var_name);
if ( isset($params[$pass_element.'_'.$var_name]) ) {
unset( $params[$pass_element.'_'.$var_name] );
}
}
$escaped = array();
foreach ($tmp_string as $tmp_val) {
$escaped[] = str_replace(Array('-',':'), Array('\-','\:'), $tmp_val);
}
if ($this->getUnitOption($prefix, 'PortalStyleEnv') == true) {
$ret.= array_shift($escaped).array_shift($escaped).'-'.implode('-',$escaped);
}
else {
$ret.=implode('-',$escaped);
}
}
}
}
unset($params['pass']);
unset($params['opener']);
unset($params['m_event']);
if ($this->GetVar('admin') && !isset($params['admin'])) {
$params['admin'] = 1;
}
if( getArrayValue($params,'escape') )
{
$ret = addslashes($ret);
unset($params['escape']);
}
foreach ($params as $param => $value)
{
$ret .= '&'.$param.'='.$value;
}
return $ret;
}
function BaseURL($prefix='')
{
return PROTOCOL.SERVER_NAME.(defined('PORT')?':'.PORT : '').BASE_PATH.$prefix.'/';
}
function Redirect($t='', $params=null, $prefix='', $index_file=null)
{
if ($t == '' || $t === true) $t = $this->GetVar('t');
// pass prefixes and special from previous url
if (!isset($params['pass'])) $params['pass'] = 'all';
$location = $this->HREF($t, $prefix, $params, $index_file);
$a_location = $location;
$location = "Location: $location";
//echo " location : $location <br>";
if (headers_sent() != '' || ($this->isDebugMode() && dbg_ConstOn('DBG_REDIRECT')) ) {
/*$GLOBALS['debugger']->appendTrace();
echo "<b>Debug output above!!!</b> Proceed to redirect: <a href=\"$a_location\">$a_location</a><br>";*/
echo '<script language="javascript" type="text/javascript">window.location.href = \''.$a_location.'\';</script>';
}
else {
header("$location");
}
$session =& $this->recallObject('Session');
$session->SaveData();
$this->SaveBlocksCache();
exit;
}
function Phrase($label)
{
return $this->Phrases->GetPhrase($label);
}
/**
* Replace language tags in exclamation marks found in text
*
* @param string $text
* @param bool $force_escape force escaping, not escaping of resulting string
* @return string
* @access public
*/
function ReplaceLanguageTags($text, $force_escape=null)
{
return $this->Phrases->ReplaceLanguageTags($text,$force_escape);
}
/**
* Validtates user in session if required
*
*/
function ValidateLogin()
{
if (defined('LOGIN_REQUIRED'))
{
// Original Kostja call
//$login_controller =& $this->Factory->MakeClass(LOGIN_CONTROLLER, Array('model' => USER_MODEL, 'prefix' => 'login'));
// Call proposed by Alex
//$login_controller =& $this->RecallObject(LOGIN_CONTROLLER, Array('model' => USER_MODEL, 'prefix' => 'login'));
//$login_controller->CheckLogin();
}
}
/**
* Returns configuration option value by name
*
* @param string $name
* @return string
*/
function ConfigValue($name)
{
return $this->DB->GetOne('SELECT VariableValue FROM '.TABLE_PREFIX.'ConfigurationValues WHERE VariableName = '.$this->DB->qstr($name) );
}
/**
* Allows to process any type of event
*
* @param kEvent $event
* @access public
* @author Alex
*/
function HandleEvent(&$event, $params=null, $specificParams=null)
{
if ( isset($params) ) {
$event = new kEvent( $params, $specificParams );
}
$event_manager =& $this->recallObject('EventManager');
$event_manager->HandleEvent($event);
}
/**
* Registers new class in the factory
*
* @param string $real_class
* @param string $file
* @param string $pseudo_class
* @access public
* @author Alex
*/
function registerClass($real_class,$file,$pseudo_class=null)
{
$this->Factory->registerClass($real_class,$file,$pseudo_class);
}
/**
* Registers Hook from subprefix event to master prefix event
*
* @param string $hookto_prefix
* @param string $hookto_special
* @param string $hookto_event
* @param string $mode
* @param string $do_prefix
* @param string $do_special
* @param string $do_event
* @param string $conditional
* @access public
* @todo take care of a lot parameters passed
* @author Kostja
*/
function registerHook($hookto_prefix, $hookto_special, $hookto_event, $mode, $do_prefix, $do_special, $do_event, $conditional)
{
$event_manager =& $this->recallObject('EventManager');
$event_manager->registerHook($hookto_prefix, $hookto_special, $hookto_event, $mode, $do_prefix, $do_special, $do_event, $conditional);
}
/**
* Allows one TagProcessor tag act as other TagProcessor tag
*
* @param Array $tag_info
* @author Kostja
*/
function registerAggregateTag($tag_info)
{
$aggregator =& $this->recallObject('TagsAggregator', 'kArray');
$aggregator->SetArrayValue($tag_info['AggregateTo'], $tag_info['AggregatedTagName'], Array($tag_info['LocalPrefix'], $tag_info['LocalTagName']));
}
/**
* Returns object using params specified,
* creates it if is required
*
* @param string $name
* @param string $pseudo_class
* @param Array $event_params
* @return Object
* @author Alex
*/
function &recallObject($name,$pseudo_class=null,$event_params=Array())
{
$o1 =& $this->Factory->getObject($name,$pseudo_class,$event_params);
//$o1->param1 = 'one';
/*$func_args = func_get_args();
$factory =& $this->Factory;
$o2 =& call_user_func_array( Array(&$factory, 'getObject'), $func_args );*/
//$o2->param1 = 'two';
return $o1;
}
/**
* Checks if object with prefix passes was already created in factory
*
* @param string $name object presudo_class, prefix
* @return bool
* @author Kostja
*/
function hasObject($name)
{
return isset($this->Factory->Storage[$name]);
}
/**
* Removes object from storage by given name
*
* @param string $name Object's name in the Storage
* @author Kostja
*/
function removeObject($name)
{
$this->Factory->DestroyObject($name);
}
/**
* Get's real class name for pseudo class,
* includes class file and creates class
* instance
*
* @param string $pseudo_class
* @return Object
* @access public
* @author Alex
*/
function &makeClass($pseudo_class)
{
$func_args = func_get_args();
return call_user_func_array( Array(&$this->Factory, 'makeClass'), $func_args);
}
/**
* Checks if application is in debug mode
*
* @return bool
* @access public
* @author Alex
*/
function isDebugMode()
{
return defined('DEBUG_MODE') && DEBUG_MODE;
}
/**
* Checks if it is admin
*
* @return bool
* @author Alex
*/
function IsAdmin()
{
return defined('ADMIN') && ADMIN;
}
/**
* Reads unit (specified by $prefix)
* option specified by $option
*
* @param string $prefix
* @param string $option
* @return string
* @access public
* @author Alex
*/
function getUnitOption($prefix,$option)
{
$unit_config_reader =& $this->recallObject('kUnitConfigReader');
return $unit_config_reader->getUnitOption($prefix,$option);
}
/**
* Set's new unit option value
*
* @param string $prefix
* @param string $name
* @param string $value
* @author Alex
* @access public
*/
function setUnitOption($prefix,$option,$value)
{
$unit_config_reader =& $this->recallObject('kUnitConfigReader');
return $unit_config_reader->setUnitOption($prefix,$option,$value);
}
/**
* Read all unit with $prefix options
*
* @param string $prefix
* @return Array
* @access public
* @author Alex
*/
function getUnitOptions($prefix)
{
$unit_config_reader =& $this->recallObject('kUnitConfigReader');
return $unit_config_reader->getUnitOptions($prefix);
}
/**
* Splits any mixing of prefix and
* special into correct ones
*
* @param string $prefix_special
* @return Array
* @access public
* @author Alex
*/
function processPrefix($prefix_special)
{
return $this->Factory->processPrefix($prefix_special);
}
/**
* Set's new event for $prefix_special
* passed
*
* @param string $prefix_special
* @param string $event_name
* @access public
*/
function setEvent($prefix_special,$event_name)
{
$event_manager =& $this->recallObject('EventManager');
$event_manager->setEvent($prefix_special,$event_name);
}
/**
* SQL Error Handler
*
* @param int $code
* @param string $msg
* @param string $sql
* @return bool
* @access private
* @author Alex
*/
function handleSQLError($code,$msg,$sql)
{
global $debugger;
if($debugger)
{
$errorLevel=defined('DBG_SQL_FAILURE') && DBG_SQL_FAILURE ? E_USER_ERROR : E_USER_WARNING;
$debugger->dumpVars($_REQUEST);
$debugger->appendTrace();
$error_msg = '<span class="debug_error">'.$msg.' ('.$code.')</span><br><a href="javascript:SetClipboard(\''.htmlspecialchars($sql).'\');"><b>SQL</b></a>: '.$debugger->formatSQL($sql);
$long_id=$debugger->mapLongError($error_msg);
trigger_error( substr($msg.' ('.$code.') ['.$sql.']',0,1000).' #'.$long_id, $errorLevel);
return true;
}
else
{
$errorLevel = defined('IS_INSTALL') && IS_INSTALL ? E_USER_WARNING : E_USER_ERROR;
trigger_error('<b>SQL Error</b> in sql: '.$sql.', code <b>'.$code.'</b> ('.$msg.')', $errorLevel);
/*echo '<b>xProcessing SQL</b>: '.$sql.'<br>';
echo '<b>Error ('.$code.'):</b> '.$msg.'<br>';*/
return $errorLevel == E_USER_ERROR ? false : true;
}
}
/**
* Default error handler
*
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param Array $errcontext
*/
function handleError($errno, $errstr, $errfile = '', $errline = '', $errcontext = '')
{
$fp = fopen(DOC_ROOT.BASE_PATH.'/silent_log.txt','a');
$time = date('d/m/Y H:i:s');
fwrite($fp, '['.$time.'] #'.$errno.': '.strip_tags($errstr).' in ['.$errfile.'] on line '.$errline."\n");
fclose($fp);
}
/**
* Returns & blocks next ResourceId available in system
*
* @return int
* @access public
* @author Eduard
*/
function NextResourceId()
{
$this->DB->Query('LOCK TABLES '.TABLE_PREFIX.'IdGenerator WRITE');
$this->DB->Query('UPDATE '.TABLE_PREFIX.'IdGenerator SET lastid = lastid+1');
$id = $this->DB->GetOne("SELECT lastid FROM ".TABLE_PREFIX."IdGenerator");
$this->DB->Query('UNLOCK TABLES');
return $id;
}
/**
* Returns main prefix for subtable prefix passes
*
* @param string $current_prefix
* @return string
* @access public
* @author Kostja
*/
function GetTopmostPrefix($current_prefix)
{
while ( $parent_prefix = $this->getUnitOption($current_prefix, 'ParentPrefix') )
{
$current_prefix = $parent_prefix;
}
return $current_prefix;
}
function EmailEventAdmin($email_event_name, $to_user_id = -1, $send_params = false)
{
return $this->EmailEvent($email_event_name, 1, $to_user_id, $send_params);
}
function EmailEventUser($email_event_name, $to_user_id = -1, $send_params = false)
{
return $this->EmailEvent($email_event_name, 0, $to_user_id, $send_params);
}
function EmailEvent($email_event_name, $email_event_type, $to_user_id = -1, $send_params = false)
{
$event = new kEvent('emailevents:OnEmailEvent');
$event->setEventParam('EmailEventName', $email_event_name);
$event->setEventParam('EmailEventToUserId', $to_user_id);
$event->setEventParam('EmailEventType', $email_event_type);
if ($send_params){
$event->setEventParam('DirectSendParams', $send_params);
}
$this->HandleEvent($event);
return $event;
}
function LoggedIn()
{
$user =& $this->recallObject('u');
return ($user->GetDBField('PortalUserId') > 0);
}
function CheckPermission($name, $cat_id = null)
{
if( !isset($cat_id) )
{
$cat_id = $this->GetVar('m_cat_id');
}
if( $cat_id == 0 )
{
$cat_hierarchy = Array(0);
}
else
{
$sql = 'SELECT ParentPath FROM '.$this->getUnitOption('c', 'TableName').' WHERE CategoryId = '.$cat_id;
$cat_hierarchy = $this->DB->GetOne($sql);
$cat_hierarchy = explode('|', $cat_hierarchy);
array_shift($cat_hierarchy);
array_pop($cat_hierarchy);
$cat_hierarchy = array_reverse($cat_hierarchy);
array_push($cat_hierarchy, 0);
}
$groups = $this->RecallVar('UserGroups');
foreach($cat_hierarchy as $category_id)
{
$sql = 'SELECT PermissionValue FROM '.TABLE_PREFIX.'Permissions
WHERE Permission = "'.$name.'"
AND CatId = '.$category_id.'
AND GroupId IN ('.$groups.')';
$res = $this->DB->GetOne($sql);
if($res !== false)
{
return $res;
}
}
return 0;
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/application.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.26
\ No newline at end of property
+1.27
\ No newline at end of property
Index: trunk/core/units/config_search/config_search_event_handler.php
===================================================================
--- trunk/core/units/config_search/config_search_event_handler.php (revision 1820)
+++ trunk/core/units/config_search/config_search_event_handler.php (revision 1821)
@@ -1,139 +1,141 @@
<?php
class ConfigSearchEventHandler extends InpDBEventHandler {
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
$module_owner=$this->Application->GetVar('module');
if ($module_owner===false) {
$module_owner=$this->myUrlDecode($this->Application->GetVar('confs_module'));
$this->Application->SetVar("module", $module_owner);
}
$section=$this->Application->GetVar('section');
if ($section===false){
$section=$this->myUrlDecode($this->Application->GetVar('confs_section'));
$this->Application->SetVar("section", $section);
}
$object->addFilter('module_filter', '%1$s.ModuleName = "'.$module_owner.'"');
}
function OnUpdate(&$event)
{
- parent::OnUpdate($event);
+ if (!$this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ parent::OnUpdate($event);
+ }
$module_owner=$this->Application->GetVar('module');
$module_section=$this->Application->GetVar('section');
$conf_update = new kEvent( );
$conf_update->Init('conf');
$conf_update->Name = 'OnUpdate';
$conf_update->redirect = false;
$this->Application->HandleEvent($conf_update);
$event->redirect_params = Array('opener' => 's','confs_module'=>$this->myUrlEncode($module_owner),'confs_section'=>$this->myUrlEncode($module_section),'conf_module'=>$this->myUrlEncode($module_owner),'conf_section'=>$this->myUrlEncode($module_section),'pass'=>'all,confs,conf'); //stay!
}
function OnCancel(&$event)
{
parent::OnCancel($event);
$module_owner=$this->Application->GetVar('module');
$module_section=$this->Application->GetVar('section');
$event->redirect_params = Array('opener' => 's','confs_module'=>$this->myUrlEncode($module_owner),'confs_section'=>$this->myUrlEncode($module_section),'conf_module'=>$this->myUrlEncode($module_owner),'conf_section'=>$this->myUrlEncode($module_section),'pass'=>'all,confs,conf'); //stay!
}
function myUrlDecode($str){
$str=str_replace(';',':', $str);
$str=str_replace('!','-', $str);
return $str;
}
function myUrlEncode($str){
$str=str_replace('-', '!', $str);
$str=str_replace(':', ';', $str);
return $str;
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnCreateCustomField(&$event)
{
$cf_object =& $event->MasterEvent->getObject();
$is_new = $event->MasterEvent->getEventParam('IsNew');
$cf_search = array();
$cf_search['DisplayOrder'] = $cf_object->FieldValues['DisplayOrder'];
$cf_search['ElementType'] = $cf_object->FieldValues['ElementType'];
$cf_search['DisplayName'] = $cf_object->FieldValues['FieldLabel'];
$cf_search['FieldName'] = $cf_object->FieldValues['FieldName'];
$cf_search['Description'] = $cf_object->FieldValues['Prompt'];
$cf_search['ConfigHeader'] = 'la_Text_CustomFields';
$cf_search['TableName'] = "CustomField";
$cf_search['ModuleName'] = "In-Commerce";
$cf_search['ForeignField'] = "CustomMetaData.Value";
$cf_search['JoinClause'] = "{ForeignTable}.ResourceId={LocalTable}.ResourceId";
if($is_new)
{
$live_id = $this->Conn->GetOne("SELECT CustomFieldId FROM ".TABLE_PREFIX."CustomField WHERE FieldName='".$cf_search['FieldName']."'");
$cf_search['CustomFieldId'] = $live_id;
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$confs_item = $event->getObject();
$confs_item->SetFieldsFromHash($cf_search);
$confs_item->Create();
}else{
$cf_search['CustomFieldId'] = $cf_object->FieldValues['CustomFieldId'];
$search_config_id = $this->Conn->GetOne("SELECT SearchConfigId FROM ".TABLE_PREFIX."SearchConfig WHERE CustomFieldId='".$cf_object->FieldValues['CustomFieldId']."'");
$cf_search['SearchConfigId'] = $search_config_id;
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$confs_item = $event->getObject();
$confs_item->SetFieldsFromHash($cf_search);
$confs_item->Update($search_config_id);
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnDeleteCustomField(&$event){
$custom_field_id =&$event->MasterEvent->getEventParam('id');
$this->Conn->Query("DELETE FROM ".TABLE_PREFIX."SearchConfig WHERE CustomFieldId=".$custom_field_id);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/config_search/config_search_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2
\ No newline at end of property
+1.3
\ No newline at end of property
Index: trunk/core/units/configuration/configuration_event_handler.php
===================================================================
--- trunk/core/units/configuration/configuration_event_handler.php (revision 1820)
+++ trunk/core/units/configuration/configuration_event_handler.php (revision 1821)
@@ -1,163 +1,165 @@
<?php
class ConfigurationEventHandler extends InpDBEventHandler {
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
$object =& $event->getObject();
$module_owner=$this->Application->GetVar('module');
if ($module_owner===false) {
$module_owner=$this->myUrlDecode($this->Application->GetVar('conf_module'));
$this->Application->SetVar("module", $module_owner);
}
$section=$this->Application->GetVar('section');
if ($section===false){
$section=$this->myUrlDecode($this->Application->GetVar('conf_section'));
$this->Application->SetVar("section", $section);
}
$object->addFilter('module_filter', '%1$s.ModuleOwner = "'.$module_owner.'"');
$object->addFilter('section_filter', '%1$s.Section = "'.$section.'"');
$object->AddOrderField('DisplayOrder', 'ASC');
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnBeforeItemUpdate(&$event)
{
$object =& $event->getObject();
if($object->GetDBField('element_type') == 'password')
{
if (trim($object->GetDBField('VariableValue'))=='') {
$field_options=$object->GetFieldOptions('VariableValue');
$field_options['skip_empty']=1;
$object->SetFieldOptions('VariableValue', $field_options);
}else{
$object->SetDBField('VariableValue', md5($object->GetDBField('VariableValue')));
}
}
$this->country_state_pairs = Array('Comm_Country' => 'Comm_State', 'Comm_Shipping_Country' => 'Comm_Shipping_State');
if ( isset($this->country_state_pairs[$object->GetDBField('VariableName')]) ){
$this->state_country_codes[$this->country_state_pairs[$object->GetDBField('VariableName')]]=$object->GetDBField('VariableValue');
}
if( isset($this->state_country_codes[$object->GetDBField('VariableName')]) )
{
$cs_helper = &$this->Application->recallObject('CountryStatesHelper');
$state_valid_code = $cs_helper->CheckState( $object->GetDBField('VariableValue'), $this->state_country_codes[$object->GetDBField('VariableName')] );
if ($state_valid_code !== false)
{
$object->SetDBField('VariableValue', $state_valid_code);
}
else
{
$errormsgs = $this->Application->GetVar('errormsgs');
$errors = !$errormsgs || !isset($errormsgs[$event->Prefix_Special]) ? Array() : $errormsgs[$event->Prefix_Special];
$errors[ $object->GetDBField('VariableName') ] = 'la_InvalidState';
$errormsgs[$event->Prefix_Special] = $errors;
$this->Application->SetVar('errormsgs', $errormsgs);
$event->redirect = false;
$event->status = erFAIL;
}
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnAfterItemUpdate(&$event)
{
$object =& $event->getObject();
if($object->GetDBField('element_type') == 'password')
{
if (trim($object->GetDBField('VariableValue'))=='') {
$field_options=$object->GetFieldOptions('VariableValue');
unset($field_options['skip_empty']);
$object->SetFieldOptions('VariableValue', $field_options);
}
}
}
function OnUpdate(&$event)
{
- parent::OnUpdate($event);
+ if (!$this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ parent::OnUpdate($event);
+ }
$module_owner=$this->Application->GetVar('module');
$section=$this->Application->GetVar('section');
$event->redirect_params = Array('opener' => 's','conf_section'=>$this->myUrlEncode($section), 'conf_module'=>$this->myUrlEncode($module_owner),'pass'=>'all,conf'); //stay!
if ($this->Application->GetVar('errormsgs')){
$event->redirect = false;
}
}
function OnCancel(&$event)
{
parent::OnCancel($event);
$module_owner=$this->Application->GetVar('module');
$section=$this->Application->GetVar('section');
$event->redirect_params = Array('opener' => 's','conf_section'=>$this->myUrlEncode($section), 'conf_module'=>$this->myUrlEncode($module_owner),'pass'=>'all,conf'); //stay!
}
function myUrlDecode($str){
$str=str_replace(';',':', $str);
$str=str_replace('!','-', $str);
return $str;
}
function myUrlEncode($str){
$str=str_replace('-', '!', $str);
$str=str_replace(':', ';', $str);
return $str;
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnChangeCountry(&$event)
{
$event->setPseudoClass('_List');
$object = &$event->getObject( Array('per_page'=>-1) );
$object->Query();
//$object->SetDBField('');
$array_records = &$object->Records;
foreach($array_records as $i=>$record){
if ($record['VariableName']=='Comm_Country'){
$values = $this->Application->GetVar('conf');
$array_records[$i]['VariableValue'] = $values['Comm_Country']['VariableValue'];
}
}
$event->redirect_params = Array('opener' => 's', 'pass'=>'all,conf'); //stay!
$event->redirect = false;
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/configuration/configuration_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.6
\ No newline at end of property
+1.7
\ No newline at end of property
Index: trunk/core/units/general/inp_db_event_handler.php
===================================================================
--- trunk/core/units/general/inp_db_event_handler.php (revision 1820)
+++ trunk/core/units/general/inp_db_event_handler.php (revision 1821)
@@ -1,107 +1,115 @@
<?php
class InpDBEventHandler extends kDBEventHandler
{
function mapEvents()
{
parent::mapEvents();
$common_events = Array( 'OnMassApprove'=>'iterateItems',
'OnMassDecline'=>'iterateItems',
'OnMassMoveUp'=>'iterateItems',
'OnMassMoveDown'=>'iterateItems',
);
$this->eventMethods = array_merge($this->eventMethods, $common_events);
}
/**
* Apply same processing to each item beeing selected in grid
*
* @param kEvent $event
* @access private
*/
function iterateItems(&$event)
{
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ return;
+ }
+
$this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
$object =& $event->getObject();
$this->StoreSelectedIDs($event);
$ids=$this->getSelectedIDs($event);
if($ids)
{
$status_field = array_shift( $this->Application->getUnitOption($event->Prefix,'StatusField') );
foreach($ids as $id)
{
$object->Load($id);
switch ($event->Name)
{
case 'OnMassApprove':
$object->SetDBField($status_field, 1);
break;
case 'OnMassDecline':
$object->SetDBField($status_field, 0);
break;
case 'OnMassMoveUp':
$object->SetDBField('Priority', $object->GetDBField('Priority') + 1);
break;
case 'OnMassMoveDown':
$object->SetDBField('Priority', $object->GetDBField('Priority') - 1);
break;
}
if( $object->Update() )
{
$event->status=erSUCCESS;
$event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay!
}
else
{
$event->status=erFAIL;
$event->redirect=false;
break;
}
}
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnMassClone(&$event)
{
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ return;
+ }
+
$event->status=erSUCCESS;
$temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
$this->StoreSelectedIDs($event);
$ids=$this->getSelectedIDs($event);
if($ids)
{
$temp->CloneItems($event->Prefix, $event->Special, $ids);
}
}
function check_array($records, $field, $value)
{
foreach ($records as $record)
{
if ($record[$field] == $value)
{
return true;
}
}
return false;
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/general/inp_db_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.4
\ No newline at end of property
+1.5
\ No newline at end of property

Event Timeline