Index: trunk/core/units/configuration/configuration_event_handler.php =================================================================== diff -u -N --- trunk/core/units/configuration/configuration_event_handler.php (revision 0) +++ trunk/core/units/configuration/configuration_event_handler.php (revision 1310) @@ -0,0 +1,102 @@ +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->SetWhereClause('%1$s.ModuleOwner="'.$module_owner.'" AND %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'))); + } + } + } + + /** + * 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); + $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 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; + } + + } + +?> \ No newline at end of file Index: trunk/kernel/units/custom_fields/custom_fields_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/custom_fields/custom_fields_event_handler.php (revision 0) +++ trunk/kernel/units/custom_fields/custom_fields_event_handler.php (revision 1310) @@ -0,0 +1,84 @@ +getObject(); + + $item_type=$this->Application->GetVar('cf_type'); + $object->SetWhereClause('%1$s.Type='.$item_type); + $object->AddOrderField('DisplayOrder', 'ASC'); + } + + /** + * Prevents from duplicate item creation + * + * @param kEvent $event + */ + function OnBeforeItemCreate(&$event) + { + $object =& $event->getObject(); + $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); + + $new_field_name=$items_info[0]['FieldName']; + + $table = $this->Application->getUnitOption($event->Prefix,'TableName'); + $found = $this->Conn->GetOne("SELECT count(*) FROM ".$table." WHERE FieldName='".$new_field_name."'"); + + if($found){ + $event->status=erFAIL; + $object->FieldErrors['FieldName']['pseudo'] = $this->Application->Phrase('la_error_CustomExists'); + } + else { + $item_type=$this->Application->GetVar('cf_type'); + + $object->SetDBField('Type', $this->Application->GetVar('cf_type')); + } + } + + function OnAfterItemCreate(&$event) + { + $this->Application->SetVar('cf_id', ''); + } + + function OnAfterItemUpdate(&$event) + { + $this->Application->SetVar('cf_id', ''); + } + + function OnCancelEdit(&$event){ + $this->Application->SetVar('cf_id', ''); + } + /** + * Occurse after deleting item, id of deleted item + * is stored as 'id' param of event + * + * @param kEvent $event + * @access public + */ + function OnAfterItemDelete(&$event) + { + $object =& $event->getObject(); + $custom_field_id=$event->getEventParam('id'); + $this->Application->SetVar('cf_id', ''); + + $sql='DELETE FROM '.TABLE_PREFIX.'CustomMetaData WHERE CustomFieldId='.$custom_field_id; + $this->Conn->Query($sql); + + + } + + function OnMassDelete(&$event) + { + parent::OnMassDelete($event); + $event->redirect_params = Array('opener' => 's'); + } + } +?> \ No newline at end of file Index: trunk/kernel/units/general/cat_dblist.php =================================================================== diff -u -N --- trunk/kernel/units/general/cat_dblist.php (revision 0) +++ trunk/kernel/units/general/cat_dblist.php (revision 1310) @@ -0,0 +1,12 @@ +Special != 'showall' ? '('.TABLE_PREFIX.'CategoryItems.CategoryId = '.$this->Application->GetVar('m_cat_id').') ' : ''; + } + +} + +?> \ No newline at end of file Index: trunk/core/units/categories/categories_config.php =================================================================== diff -u -N --- trunk/core/units/categories/categories_config.php (revision 0) +++ trunk/core/units/categories/categories_config.php (revision 1310) @@ -0,0 +1,59 @@ + 'c', + 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'CategoriesEventHandler','file'=>'categories_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'CategoriesTagProcessor','file'=>'categories_tag_processor.php','build_event'=>'OnBuild'), + 'AutoLoad' => true, + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + 'IDField' => 'CategoryId', + 'TableName' => TABLE_PREFIX.'Category', + + 'ListSQLs' => Array( ''=> 'SELECT * FROM %s'), + // key - special, value - list select sql + 'ItemSQLs' => Array( ''=> 'SELECT * FROM %s'), + + 'Fields' => Array + ( + 'CategoryId' => Array('type' => 'int','not_null' => '1','default' => ''), + 'Type' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'ParentId' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'Name' => Array('type' => 'string','not_null' => '1','default' => ''), + 'Description' => Array('type' => 'string','not_null' => '1','default' => ''), + 'CreatedOn' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'EditorsPick' => Array('type' => 'int','default' => ''), + 'Status' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'Pop' => Array('type' => 'int','default' => ''), + 'Priority' => Array('type' => 'int','default' => ''), + 'MetaKeywords' => Array('type' => 'string','default' => ''), + 'CachedDescendantCatsQty' => Array('type' => 'int','default' => ''), + 'CachedNavbar' => Array('type' => 'string','not_null' => '1','default' => ''), + 'CreatedById' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'ResourceId' => Array('type' => 'int','default' => ''), + 'ParentPath' => Array('type' => 'string','not_null' => '1','default' => ''), + 'MetaDescription' => Array('type' => 'string','default' => ''), + 'HotItem' => Array('type' => 'int','not_null' => '1','default' => '2'), + 'NewItem' => Array('type' => 'int','not_null' => '1','default' => '2'), + 'PopItem' => Array('type' => 'int','not_null' => '1','default' => '2'), + 'Modified' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'ModifiedById' => Array('type' => 'int','not_null' => '1','default' => '0'), + ), + + 'Grids' => Array( + 'Default' => Array( + 'Icons' => Array('default'=>'icon16_cat.gif'), + 'Fields' => Array( + 'Name' => Array( 'width'=>150, 'title'=>'la_col_Title', 'data_block'=>'category_td' ), + ), + + ), + ), + ); + +?> \ No newline at end of file Index: trunk/kernel/units/custom_values/custom_values_config.php =================================================================== diff -u -N --- trunk/kernel/units/custom_values/custom_values_config.php (revision 0) +++ trunk/kernel/units/custom_values/custom_values_config.php (revision 1310) @@ -0,0 +1,90 @@ + 'cv', + 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'CustomValuesEventHandler','file'=>'custom_value_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'), + + 'AutoLoad' => true, + 'Hooks' => Array( + Array( + 'Mode' => hAFTER, + 'Conditional' => true, + 'HookToPrefix' => 'p', + 'HookToSpecial' => '', + 'HookToEvent' => Array( 'onPreSave' ), + 'DoPrefix' => '', + 'DoSpecial' => '', + 'DoEvent' => 'onPreSave', + ), + Array( + 'Mode' => hAFTER, + 'Conditional' => true, + 'HookToPrefix' => 'p', + 'HookToSpecial' => '', + 'HookToEvent' => Array( 'onPreSave' ), + 'DoPrefix' => '', + 'DoSpecial' => 'general', + 'DoEvent' => 'onPreSave', + ), + ), + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + + 'TableName' => TABLE_PREFIX.'CustomMetaData', + 'IDField' => 'CustomDataId', // in this case idfield doesn't exit in destination table + + 'ParentTableKey'=> 'ResourceId', + 'ForeignKey' => 'ResourceId', + 'ParentPrefix' => 'p', + 'AutoDelete' => true, + 'AutoClone' => true, + + 'ListSQLs' => Array( + '' => " + SELECT + cf.FieldName, cf.Prompt, cf.CustomFieldId, cf.ElementType, cf.ValueList, cf.DisplayOrder, + %1\$s as ResourceId, + cmd.CustomDataId, cmd.Value + FROM inp_CustomField AS cf + LEFT JOIN %%1\$s AS cmd + ON cmd.CustomFieldId = cf.CustomFieldId AND ResourceId = %1\$s", + ), // key - special, value - list select sql + + + + 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', + ), + + 'Fields' => Array( + 'CustomDataId' => Array(), + 'CustomFieldId' => Array('not_null' => '1', 'default'=>''), + 'ResourceId' => Array('not_null' => 1, 'default' => 0), + 'Value' => Array('not_null' => true, 'default' => ''), + ), + 'VirtualFields' => Array( + 'FieldName' => Array(), + 'Prompt' => Array(), + 'ElementType' => Array(), + 'ValueList' => Array(), + + ), + + 'Grids' => Array( + 'Default' => Array( + 'Icons' => Array('default'=>'icon16_custom.gif'), // icons for each StatusField values, if no matches or no statusfield selected, then "default" icon is used + 'Fields' => Array( + 'FieldName' => Array( 'title'=>'la_col_FieldName', 'data_block' => 'grid_icon_td'), + 'Prompt' => Array( 'title'=>'la_col_Prompt', 'data_block' => 'grid_data_label_td' ), + 'Value' => Array( 'title'=>'la_col_Value', 'data_block' => 'edit_custom_td'), + ), + ), + ), + ); + +?> \ No newline at end of file Index: trunk/kernel/units/category_items/category_items_config.php =================================================================== diff -u -N --- trunk/kernel/units/category_items/category_items_config.php (revision 0) +++ trunk/kernel/units/category_items/category_items_config.php (revision 1310) @@ -0,0 +1,51 @@ + 'ci', + 'ItemClass' => Array('class'=>'CategoryItems_DBItem','file'=>'category_items_dbitem.php','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'CategoryItemsEventHander','file'=>'category_items_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'CategoryItemsTagProcessor','file'=>'category_items_tag_processor.php','build_event'=>'OnBuild'), + 'AutoLoad' => true, + 'hooks' => Array(), + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + 'IDField' => 'CategoryId', // in this case idfield doesn't exit in destination table + 'TableName' => TABLE_PREFIX.'CategoryItems', + 'ParentTableKey'=> 'ResourceId', + 'ForeignKey' => 'ItemResourceId', + 'ParentPrefix' => 'p', + 'AutoDelete' => true, + 'AutoClone' => false, // Critical !!! + + 'ListSQLs' => Array( ''=>" SELECT ci.*, c.CachedNavbar AS CategoryName, IF(ISNULL(c.CategoryId),0,c.CategoryId) AS DummyId + FROM %1\$s ci + LEFT JOIN ".TABLE_PREFIX."Category AS c ON c.CategoryId = ci.CategoryId", + ), // key - special, value - list select sql + 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', + ), + + 'Fields' => Array( + 'DummyId' => Array(), + 'CategoryId' => Array('type'=>'int','not_null'=>1,'default'=>0), + 'ItemResourceId' => Array('not_null' => 1, 'default' => 0), + 'PrimaryCat' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), + ), + 'VirtualFields' => Array('DummyId'=>1 + ), + + 'Grids' => Array( + 'Default' => Array( + 'Icons' => Array('default'=>'icon16_custom.gif'), // icons for each StatusField values, if no matches or no statusfield selected, then "default" icon is used + 'Fields' => Array( + 'CategoryName' => Array( 'title'=>'la_col_Category', 'data_block' => 'grid_checkbox_category_td'), + ), + + ), + ), + ); + +?> \ No newline at end of file Index: trunk/core/units/configuration/configuration_tag_processor.php =================================================================== diff -u -N --- trunk/core/units/configuration/configuration_tag_processor.php (revision 0) +++ trunk/core/units/configuration/configuration_tag_processor.php (revision 1310) @@ -0,0 +1,57 @@ +Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List',$params); + $id_field = $this->Application->getUnitOption($this->Prefix,'IDField'); + + $list->PerPage=-1; + $list->Query(); + $o = ''; + $list->GoFirst(); + + $block_params=$this->prepareTagParams($params); + $block_params['name']=$params['block']; + $block_params['pass_params']='true'; + $block_params['IdField'] = $id_field; + + $next_block=$params['full_block']; + + $prev_title=""; + + while (!$list->EOL()) + { + $nextItemPrompt=$list->Records[$list->CurrentIndex+1]['prompt']; + $thisItemPrompt=$list->Records[$list->CurrentIndex]['prompt']; + + $this_title=$list->Records[$list->CurrentIndex]['heading']; + + if ($this_title!=$prev_title){ + $prev_title=$this_title; + $section_header_params=array(); + $section_header_params['name']='config_section_header'; + $section_header_params['title']=$this->Application->Phrase($this_title); + $o.= $this->Application->ParseBlock($section_header_params, 1); + } + + if ($nextItemPrompt==$thisItemPrompt){ + $curr_block=$params['half_block1']; + $next_block=$params['half_block2']; + }else{ + $curr_block=$next_block; + $next_block=$params['full_block']; + } + $block_params['name']=$curr_block; + + $this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); + $o.= $this->Application->ParseBlock($block_params, 1); + + $list->GoNext(); + } + return $o; + } +} + +?> \ No newline at end of file Index: trunk/kernel/units/general/inp1_parser.php =================================================================== diff -u -N --- trunk/kernel/units/general/inp1_parser.php (revision 0) +++ trunk/kernel/units/general/inp1_parser.php (revision 1310) @@ -0,0 +1,155 @@ +InportalInited) { + $this->InitInPortal(); + } + global $objTemplate; + $template_body = $objTemplate->ParseTemplateFromBuffer($tname, $template_body); + return $template_body; + } + + + function InitInPortal() + { + $this->InportalInited = true; + /*global $pathtoroot, $FrontEnd, $indexURL, $rootURL, $secureURL, $var_list, $CurrentTheme, + $objThemes, $objConfig, $m_var_list, $timeout, $objLanguages, $objLanguageCache, + $TemplateRoot, $objTemplate, $html, $objSession, $Errors, $objCatList, $objUsers, + $env, $mod_prefix, $ExtraVars, $timestart, $timeend, $timeout, $sqlcount, $totalsql, + $template_path, $modules_loaded, $mod_root_cats, $objModules, $objItemTypes;*/ + + + global $sec, $usec, $timestart, $pathtoroot, $FrontEnd, $indexURL, $kernel_version, $FormError, + $FormValues, $ItemTables, $KeywordIgnore, $debuglevel, + $LogLevel, $LogFile, $rq_value, $rq_name, $dbg_constMap, $dbg_constValue, $dbg_constName, + $debugger, $g_LogFile, $LogData, $Errors, + $g_DebugMode, $totalsql, $sqlcount, $objConfig, $ItemTypePrefixes, $ItemTagFiles, $objModules, + $objSystemCache, $objBanList, $objItemTypes, $objThemes, $objLanguages, $objImageList, $objFavorites, + $objUsers, $objGroups, $DownloadId, $objPermissions, $objPermCache, $m_var_list, $objCatList, + $objCustomFieldList, $objCustomDataList, $objCountCache, $CRLF, $objMessageList, $objEmailQueue, + $ExtraVars, $adodbConnection, $sql, $rs, $mod_prefix, $modules_loaded, $name, + $template_path, $mod_root_cats, $value, $mod, $ItemTypes, + $ParserFiles, $SessionQueryString, $var_list, $objSession, + $orderByClause, $TemplateRoot, $ip, $UseSession, $Action, $CookieTest, $sessionId, + $var_list_update, $CurrentTheme, $UserID, $objCurrentUser, $objLanguageCache, + $folder_name, $objLinkList, $tag_override, $timeZones, $siteZone, $serverZone, + $lastExpire, $diffZone, $date, $nowDate, $lastExpireDate, $SearchPerformed, + $TotalMessagesSent, $ado, $adminDir, $rootURL, $secureURL, $html, $timeout, + $pathchar, $objTemplate; + + $pathtoroot = "./"; + $pathtoroot = realpath($pathtoroot)."/"; + + if (!file_exists($pathtoroot."config.php")) { + echo "In-Portal is probably not installed, or configuration file is missing.
"; + echo "Please use the installation script to fix the problem.

"; + echo "Go to installation script

"; + flush(); + die(); + } + + //ob_start(); + $FrontEnd=1; + + $indexURL="../../index.php"; //Set to relative URL from the theme directory + + /* initalize the in-portal system */ + include_once(FULL_PATH."/kernel/startup.php"); + + $rootURL="http://".ThisDomain().$objConfig->Get("Site_Path"); + + //$secureURL = "https://".ThisDomain().$objConfig->Get("Site_Path"); + $secureURL = $rootURL; + + $html= ''; + + if( !$var_list['t'] ) $var_list['t'] = 'index'; + + if( !isset($CurrentTheme) ) $CurrentTheme = null; + if( !is_object($CurrentTheme) ) $CurrentTheme = $objThemes->GetItem($m_var_list["theme"]); + + if(is_object($CurrentTheme)) + { + if(!$CurrentTheme->Get("Enabled")) + { + $CurrentTheme = $objThemes->GetItem($objThemes->GetPrimaryTheme()); + } + if((int)$CurrentTheme->Get("ThemeId")>0) + { + $timeout = $CurrentTheme->Get("CacheTimeout"); + $objLanguageCache->LoadTemplateCache($var_list["t"],$timeout,$CurrentTheme->Get("ThemeId")); + $objLanguageCache->LoadCachedVars($objSession->Get("Language")); + + $TemplateRoot = $CurrentTheme->ThemeDirectory()."/"; + + $objTemplate = new clsTemplateList($TemplateRoot); + //$html = $objTemplate->ParseTemplate($var_list["t"]); + } + else + { + echo "No Primary Theme Selected"; + die(); + } + } + else + { + echo "No Primary Theme Selected\n"; + die(); + } + + if(is_object($objSession)) + { + + $objSession->SetVariable("Template_Referer", $_local_t); + } + if($objTemplate->ErrorNo == -1) + { + $html = $objTemplate->ParseTemplate('error_template'); + } + //$html = replacePngTags($html); + LogEntry("Output Start\n"); + $html .= ""; + if( IsDebugMode() ) + { + if($Action) $debugger->setHTMLByIndex(1,'Front Action: '.$Action.'','append'); + $html = 'Show Debugger
'.$html; + } + else + { + header("Content-length: ".strlen($html)); + } + header("Connection-Type: Keep-Alive"); + echo $html; + + LogEntry("Output End\n"); + + if( isset($template) && $template->ErrorNo != 0 ) + { + print "\n(".$objTemplate->ErrorNo.") ".$objTemplate->ErrorStr."\n"; + } + + LogEntry("Output Complete\n"); + $objLanguageCache->SaveTemplateCache(); + LogEntry("Templates Cached\n"); + + //if($objSession->SessionEnabled()) + // $objSession->SaveSessionData(); + //echo "Cookie:
"; print_r($_COOKIE); echo "

\n"; + //ob_end_flush(); + $timeend = getmicrotime(); + $diff = $timeend - $timestart; + + LogEntry("\nTotal Queries Executed: $sqlcount in $totalsql seconds\n"); + LogEntry("\nPage Execution Time: $diff seconds\n", true); + if($LogFile) + fclose($LogFile); + } +} + +?> \ No newline at end of file Index: trunk/kernel/units/general/inp_temp_handler.php =================================================================== diff -u -N --- trunk/kernel/units/general/inp_temp_handler.php (revision 0) +++ trunk/kernel/units/general/inp_temp_handler.php (revision 1310) @@ -0,0 +1,158 @@ +GetTempName($table), + $table, + $IdField, + $ids); + $this->Conn->Query($query); + if (isset($autoincrement) && !empty($autoincrement)) { + $query = sprintf("ALTER TABLE %s + CHANGE %s %s INT(11) NOT NULL AUTO_INCREMENT, + ADD PRIMARY KEY (%s)", + $this->GetTempName($table), + $autoincrement, + $autoincrement, + $autoincrement, + $this->GetTempName($table)); + echo $query.'
'; + $this->Conn->Query($query); + } + + if($table == TABLE_PREFIX.'Images') + { + $query = sprintf('SELECT LocalPath,ThumbPath FROM %s WHERE %s IN (%s)',$table,$IdField,$ids); + $res = $this->Conn->Query($query); + + foreach ($res as $record) + { + foreach ($record as $field => $field_value) + { + $source_file = DOC_ROOT.BASE_PATH.$field_value; + $dest_file = DOC_ROOT.BASE_PATH.str_replace(IMAGES_PATH, IMAGES_PENDING_PATH, $field_value); + copy($source_file, $dest_file); + } + } + + $update_sql = 'UPDATE '.$this->GetTempName($table).' SET LocalPath = REPLACE(LocalPath, + "'.IMAGES_PATH.'", "'.IMAGES_PENDING_PATH.'"), + ThumbPath = REPLACE(ThumbPath, + "'.IMAGES_PATH.'","'.IMAGES_PENDING_PATH.'") + WHERE '.$IdField.' IN ('.$ids.')'; + $this->Conn->Query($update_sql); + + } + + } + + function CopyTempToOriginal($table, $IdField, $autoincrement=null) + { + if (isset($autoincrement) && !empty($autoincrement)) + { + $this->RemoveAutoincrement($table, $autoincrement); + } + + if( $table != $this->MasterTable ) + { + // get main ids + $sql = 'SELECT '.$this->Tables[$table]['ForeignKey']. + ' FROM '.$this->MasterTable. + ' WHERE '.$this->Tables[$this->MasterTable]['IdField'].' IN ('.implode(',',$this->MasterIDs).')'; + $main_ids = $this->Conn->GetCol($sql); + + if($main_ids) + { + if ($table == TABLE_PREFIX.'Images') + { + $sql = 'SELECT LocalPath, ThumbPath FROM '.$table. + ' WHERE '.$IdField.' IN ('.implode(',', $main_ids).')'; + $res = $this->Conn->Query($sql); + + foreach ($res as $record) + { + foreach ($record as $field => $field_value) + { + $source_file = DOC_ROOT.BASE_PATH.$field_value; + unlink($source_file); + } + } + } + + // delete all related to main table records from subtable + $sql = 'DELETE FROM '.$table.' WHERE '.$IdField.' IN ('.implode(',',$main_ids).')'; + $this->Conn->Query($sql); + } + + $subtable_idfield = $this->Tables[$table]['SubIDField']; + $this->Conn->Query('UPDATE '.$this->GetTempName($table).' SET '.$subtable_idfield.' = 0 WHERE '.$subtable_idfield.' < 0'); + } + else + { + // get IDs, that exist in temp table + $query = sprintf('SELECT %s FROM %s', + $IdField, + $this->GetTempName($table)); + $this->MasterIDs = $this->Conn->GetCol($query); // were $temp_ids before + if($this->MasterIDs) + { + // delete original records from master table + $query = sprintf('DELETE FROM %s WHERE %s IN (%s)', + $table, + $IdField, + implode(',',$this->MasterIDs) ); + $this->Conn->Query($query); + } + } + + $query = sprintf("INSERT INTO %s + SELECT * FROM %s", + $table, + $this->GetTempName($table)); + $this->Conn->Query($query); + + + if($table == TABLE_PREFIX.'Images' && count($main_ids) > 0) + { + $query = sprintf(' SELECT LocalPath, ThumbPath FROM %s + WHERE %s IN (%s)', + $table, + $IdField, + implode(',',$this->MasterIDs)); + $res = $this->Conn->Query($query); + + foreach ($res as $record) + { + foreach ($record as $field => $field_value) + { + $source_file = DOC_ROOT.BASE_PATH.$field_value; + $dest_file = DOC_ROOT.BASE_PATH.str_replace(IMAGES_PENDING_PATH, IMAGES_PATH, $field_value); + rename($source_file, $dest_file); + } + } + + $update_sql = 'UPDATE '.$table.' SET LocalPath = REPLACE(LocalPath, + "'.IMAGES_PENDING_PATH.'", "'.IMAGES_PATH.'"), + ThumbPath = REPLACE(ThumbPath, + "'.IMAGES_PENDING_PATH.'", "'.IMAGES_PATH.'") + WHERE '.$IdField.' IN ('.implode(',', $this->MasterIDs).')'; + $this->Conn->Query($update_sql); + + } + + return $this->Conn->getInsertID(); + } + +} + + +?> \ No newline at end of file Index: trunk/kernel/units/category_items/category_items_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/category_items/category_items_event_handler.php (revision 0) +++ trunk/kernel/units/category_items/category_items_event_handler.php (revision 1310) @@ -0,0 +1,101 @@ +Application->GetVar('cat_list'), ','); + //if(!$cat_list) return true; + + $cat_id = (int)$this->Conn->GetOne('SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE ResourceId='.$cat_list); + + $this->Application->setUnitOption($event->Prefix,'AutoLoad',false); + $object =& $event->getObject(); + + $table_info = $object->getLinkedInfo(); + + // don't allow duplicate records + $already_added = $this->Conn->GetOne('SELECT * FROM '.$object->TableName.' WHERE CategoryId='.$cat_id.' AND '.$table_info['ForeignKey'].'='.$table_info['ParentId']); + if($already_added === false) + { + $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); + $items_info[0]['CategoryId'] = $cat_id; + $items_info[0][ $table_info['ForeignKey'] ] = $table_info['ParentId']; + $this->Application->SetVar( $event->getPrefixSpecial(true), $items_info ); + + $rp_backup = $event->redirect_params; // save opener state + + $event->setEventParam('ForceCreateId', true); + $this->OnCreate($event); + + $event->redirect_params = $rp_backup; // restore opener state + } + } + + /** + * Set's new category as primary for product + * + * @param kEvent $event + */ + function OnSetPrimary(&$event) + { + $this->Application->setUnitOption($event->Prefix,'AutoLoad',false); + $object =& $event->getObject(); + $this->StoreSelectedIDs($event); + $ids=$this->getSelectedIDs($event); + if($ids) + { + $id = array_shift($ids); + $table_info = $object->getLinkedInfo(); + + $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 0 WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']); + $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$id.')'); + } + $event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay! + } + + /** + * Apply custom processing to item + * + * @param kEvent $event + */ + function customProcessing(&$event, $type) + { + if($event->Name == 'onMassDelete') + { + $object =& $event->getObject(); + $table_info = $object->getLinkedInfo(); + + switch ($type) + { + case 'before': + $ids = $event->getEventParam('ids'); + if($ids) + { + $ids = $this->Conn->GetCol('SELECT CategoryId FROM '.$object->TableName.' WHERE (PrimaryCat=0) AND ('.$table_info['ForeignKey'].'='.$table_info['ParentId'].') AND CategoryId IN ('.implode(',',$ids).')'); + $event->setEventParam('ids',$ids); + } + break; + + // not needed because 'before' does not allow to delete primary cat! + /*case 'after': + // set 1st not deleted category as primary + $has_primary = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE (PrimaryCat=1) AND ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].')'); + if(!$has_primary) + { + $cat_id = $this->Conn->GetOne('SELECT CategoryId FROM '.$object->TableName.' WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']); + $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$cat_id.')'); + } + break;*/ + } + } + } + + } + +?> \ No newline at end of file Index: trunk/core/units/general/inp_login_event_handler.php =================================================================== diff -u -N --- trunk/core/units/general/inp_login_event_handler.php (revision 0) +++ trunk/core/units/general/inp_login_event_handler.php (revision 1310) @@ -0,0 +1,18 @@ +Application->ConfigValue('AdminDirectory'); + if(!$admin_dir) $admin_dir = 'admin'; + $location = $this->Application->BaseURL().$admin_dir.'/index.php?expired=1'; + header('Location: '.$location); + exit; + } + + + } + + +?> \ No newline at end of file Index: trunk/core/units/categories/categories_event_handler.php =================================================================== diff -u -N --- trunk/core/units/categories/categories_event_handler.php (revision 0) +++ trunk/core/units/categories/categories_event_handler.php (revision 1310) @@ -0,0 +1,36 @@ +Application->recallObject( $event->Prefix ); + $current_cat = $this->Application->GetVar('m_cat_id'); + if($current_cat) + { + $sql = 'SELECT ParentId FROM '.$cat_object->TableName.' WHERE CategoryId='.$current_cat; + $cat_to_go = $this->Conn->GetOne($sql); + } + else + { + $cat_to_go = 0; + } + $event->redirect = 'in-commerce/product_selector'; + $event->redirect_params = Array('m_cat_id' => $cat_to_go); + } + + function OnGoHome(&$event) + { + $cat_to_go = 0; + $event->redirect = 'in-commerce/product_selector'; + $event->redirect_params = Array('m_cat_id' => $cat_to_go); + } + +} + +?> \ No newline at end of file Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N --- trunk/core/units/general/cat_event_handler.php (revision 0) +++ trunk/core/units/general/cat_event_handler.php (revision 1310) @@ -0,0 +1,65 @@ +Factory->includeClassFile('kDBEventHandler'); + +class kCatDBEventHandler extends InpDBEventHandler { + + function OnCopy(&$event) + { + $object = $event->getObject(); + $this->StoreSelectedIDs($event); + $ids = $this->getSelectedIDs($event); + $this->Application->StoreVar($this->getPrefixSpecial().'_clipboard', implode(',', $ids)); + $this->Application->StoreVar($this->getPrefixSpecial().'_clipboard_mode', 'copy'); + + $this->Application->StoreVar('clipboard', 'COPY-0.'.TABLE_PREFIX.'Products.ResourceId=0'); + $event->redirect_params = Array('opener' => 's', 'pass_events'=>true); //do not go up - STAY + } + + function OnCut(&$event) + { + $object = $event->getObject(); + $this->StoreSelectedIDs($event); + $ids = $this->getSelectedIDs($event); + $this->Application->StoreVar($this->getPrefixSpecial().'_clipboard', implode(',', $ids)); + $this->Application->StoreVar($this->getPrefixSpecial().'_clipboard_mode', 'cut'); + + $this->Application->StoreVar('clipboard', 'CUT-0.'.TABLE_PREFIX.'Products.ResourceId=0'); + $event->redirect_params = Array('opener' => 's', 'pass_events'=>true); //do not go up - STAY + } + + function OnPaste(&$event) + { + $ids = $this->Application->RecallVar($this->getPrefixSpecial().'_clipboard'); + if ($ids == '') { + $event->redirect = false; + return; + } + + //recalling by different name, because we may get kDBList, if we recall just by prefix + $object =& $this->Application->recallObject($event->getPrefixSpecial().'.item', $event->Prefix); + $this->prepareObject(&$object,&$event); + + if ($this->Application->RecallVar($this->getPrefixSpecial().'_clipboard_mode') == 'copy') { + $ids_arr = explode(',', $ids); + + $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + + if($ids_arr) + { + $temp->CloneItems($event->Prefix, $event->Special, $ids_arr); + } + } + else { // mode == cut + $ids_arr = explode(',', $ids); + foreach ($ids_arr as $id) { + $object->Load($id); + $object->MoveToCat(); + } + } + $event->redirect = true; + } +} + +?> \ No newline at end of file Index: trunk/core/units/general/cat_dbitem.php =================================================================== diff -u -N --- trunk/core/units/general/cat_dbitem.php (revision 0) +++ trunk/core/units/general/cat_dbitem.php (revision 1310) @@ -0,0 +1,113 @@ +Validate()) return false; + + $this->SetDBField('ResourceId', $this->Application->NextResourceId()); + $this->SetDBField('Modified', mktime()); + + $ret = parent::Create(); + if($ret) + { + if ( kTempTablesHandler::IsTempTable($this->TableName) ) { + $table = kTempTablesHandler::GetTempName(TABLE_PREFIX.'CategoryItems'); + } + else { + $table = TABLE_PREFIX.'CategoryItems'; + } + $cat_id = $this->Application->GetVar('m_cat_id'); + $query = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat) + VALUES ('.$cat_id.','.$this->GetField('ResourceId').',1)'; + $this->Conn->Query($query); + } + return $ret; + } + + function Update($id=null) + { + $this->VirtualFields['ResourceId'] = true; + $this->SetDBField('Modified', mktime()); + return parent::Update($id); + } + + function Copy($cat_id=null) + { + if (!isset($cat_id)) $cat_id = $this->Application->GetVar('m_cat_id'); + $this->NameCopy($cat_id); + return $this->Create($cat_id); + } + + function NameCopy($master=null, $foreign_key=null) + { + $title_field = $this->Application->getUnitOption($this->Prefix, 'TitleField'); + if (!$title_field) return; + + $new_name = $this->GetDBField('Name'); + $cat_id = $this->Application->GetVar('m_cat_id'); + $original_checked = false; + do { + if ( preg_match("/Copy ([0-9]*)[ ]*of(.*)/", $new_name, $regs) ) { + $new_name = 'Copy '.($regs[1]+1).' of '.$regs[2]; + } + elseif ($original_checked) { + $new_name = 'Copy of '.$new_name; + } + $query = 'SELECT '.$title_field.' FROM '.$this->TableName.' + LEFT JOIN '.TABLE_PREFIX.'CategoryItems ON + ('.TABLE_PREFIX.'CategoryItems.ItemResourceId = '.$this->TableName.'.ResourceId) + WHERE ('.TABLE_PREFIX.'CategoryItems.CategoryId = '.$cat_id.') AND '. + $title_field.' = '.$this->Conn->qstr($new_name); + $res = $this->Conn->GetOne($query); + $original_checked = true; + } while ($res !== false); + $this->SetDBField($title_field, $new_name); + } + + function MoveToCat($cat_id=null) + { +// $this->NameCopy(); + $cat_id = $this->Application->GetVar('m_cat_id'); + // check if the product already exists in destination cat + $query = 'SELECT PrimaryCat FROM '.TABLE_PREFIX.'CategoryItems + WHERE CategoryId = '.$cat_id.' AND ItemResourceId = '.$this->GetDBField('ResourceId'); + // if it's not found is_primary will be FALSE, if it's found but not primary it will be int 0 + $is_primary = $this->Conn->GetOne($query); + $exists = $is_primary !== false; + + if ($exists) { // if the Product already exists in destination category + if ($is_primary) return; // do nothing when we paste to primary + // if it's not primary - delete it from destination category, + // as we will move it from current primary below + $query = 'DELETE FROM '.TABLE_PREFIX.'CategoryItems + WHERE ItemResourceId = '.$this->GetDBField('ResourceId').' AND CategoryId = '.$cat_id; + $this->Conn->Query($query); + + } + $query = 'UPDATE '.TABLE_PREFIX.'CategoryItems SET CategoryId = '.$cat_id. + ' WHERE ItemResourceId = '.$this->GetDBField('ResourceId').' AND PrimaryCat = 1'; + $this->Conn->Query($query); + $this->Update(); + } + + // We need to delete CategoryItems record when deleting product + function Delete($id=null) + { + if( isset($id) ) { + $this->setID($id); + } + $this->Load($this->GetID()); + + $ret = parent::Delete(); + if ($ret) { + $query = 'DELETE FROM '.TABLE_PREFIX.'CategoryItems WHERE ItemResourceId = '.$this->GetDBField('ResourceId'); + $this->Conn->Query($query); + } + + return $ret; + } +} + +?> \ No newline at end of file Index: trunk/kernel/units/general/inp_db_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/general/inp_db_event_handler.php (revision 0) +++ trunk/kernel/units/general/inp_db_event_handler.php (revision 1310) @@ -0,0 +1,145 @@ +'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) + { + $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) + { + $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; + } + + /** + * Split one timestamp field into 2 virtual fields + * + * @param kEvent $event + * @access public + */ + function loadTSField(&$event, $ts_field, $date_field, $time_field) + { + $object =& $event->getObject(); + $timestamp = $object->GetDBField($ts_field); + if( isset($timestamp) && $timestamp ) + { + $options = $object->GetFieldOptions($date_field); + $formatter =& $this->Application->recallObject($options['formatter']); + $object->SetField( $date_field, $formatter->Format($timestamp, $options, $errors) ); + + $options = $object->GetFieldOptions($time_field); + $formatter =& $this->Application->recallObject($options['formatter']); + $object->SetField( $time_field, $formatter->Format($timestamp, $options, $errors) ); + } + } + + /** + * Save date & time virtual fields back to timestamp field + * + * @param kEvent $event + * @access public + */ + function saveTSField(&$event, $ts_field, $date_field, $time_field) + { + $object =& $event->getObject(); + $date_value = $object->GetDBField($date_field); + $time_value = $object->GetDBField($time_field); + $time_zone_offset = date('Z', time() ); // !!! this is important + + $object->SetDBField($ts_field, $date_value+$time_value+$time_zone_offset); + } + + } + + +?> \ No newline at end of file Index: trunk/kernel/units/general/inp_unit_config_reader.php =================================================================== diff -u -N --- trunk/kernel/units/general/inp_unit_config_reader.php (revision 0) +++ trunk/kernel/units/general/inp_unit_config_reader.php (revision 1310) @@ -0,0 +1,19 @@ +processFolder(DOC_ROOT.BASE_PATH); + } + } + + +?> \ No newline at end of file Index: trunk/kernel/units/general/general_config.php =================================================================== diff -u -N --- trunk/kernel/units/general/general_config.php (revision 0) +++ trunk/kernel/units/general/general_config.php (revision 1310) @@ -0,0 +1,21 @@ + 'm', + 'hooks' => Array(), + 'QueryString' => Array( + 1 => 'cat_id', + 2 => 'cat_page', + 3 => 'lang', + 4 => 'theme', + 5 => 'opener', + ), + 'TitleField' => 'CachedNavbar', + 'TitlePhrase' => 'la_Text_Category', + 'ItemType' => 1, + 'TableName' => TABLE_PREFIX.'Category', + + 'PortalStyleEnv' => true, + ); + +?> \ No newline at end of file Index: trunk/kernel/units/category_items/category_items_dbitem.php =================================================================== diff -u -N --- trunk/kernel/units/category_items/category_items_dbitem.php (revision 0) +++ trunk/kernel/units/category_items/category_items_dbitem.php (revision 1310) @@ -0,0 +1,36 @@ +getLinkedInfo(); + return '(CategoryId='.$this->ID.' AND '.$table_info['ForeignKey'].'='.$table_info['ParentId'].')'; + } + + /** + * Generate and set new temporary id + * + * @access private + */ + function setTempID() + { + // don't set temp id for this item + } + + } + + +?> \ No newline at end of file Index: trunk/kernel/units/custom_fields/custom_fields_config.php =================================================================== diff -u -N --- trunk/kernel/units/custom_fields/custom_fields_config.php (revision 0) +++ trunk/kernel/units/custom_fields/custom_fields_config.php (revision 1310) @@ -0,0 +1,74 @@ + 'cf', + 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'CustomFieldsEventHandler','file'=>'custom_fields_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'), + 'AutoLoad' => true, + 'hooks' => Array(), + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + 4 => 'type', + 5 => 'mode', + ), + 'IDField' => 'CustomFieldId', + + 'TitleField' => 'FieldName', // field, used in bluebar when editing existing item + + 'TitlePhrase' => 'la_title_CustomFields', + + 'TitlePresets' => Array( + 'default' => Array( 'new_status_labels' => Array('cf'=>'!la_title_addingCustom!'), + 'edit_status_labels' => Array('cf'=>'!la_title_Editing_CustomField!'), + 'new_titlefield' => Array('cf'=>'!la_title_NewCustomField!'), + ), + + 'custom_fields_list'=>Array( 'prefixes' => Array('cf_List'), + 'format' => "!la_tab_ConfigCustom! (#cf_recordcount#)", + ), + + 'custom_fields_edit'=>Array( 'prefixes' => Array('cf'), + 'new_titlefield' => Array('cf'=>'!la_title_NewCustomField!'), + 'format' => "#cf_status# '#cf_titlefield#'", + ), + ), + + 'TableName' => TABLE_PREFIX.'CustomField', + + 'ListSQLs' => Array( ''=>"SELECT %1\$s.* FROM %s", + ), // key - special, value - list select sql + 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', + ), + + 'Fields' => Array( + 'CustomFieldId' => Array('type' => 'int','not_null' => '1','default' => ''), + 'Type' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'FieldName' => Array('type' => 'string','not_null' => 1,'default' => ''), + 'FieldLabel' => Array('type' => 'string','default' => ''), + 'Heading' => Array('type' => 'string','default' => ''), + 'Prompt' => Array('type' => 'string','default' => ''), + 'ElementType' => Array('type'=>'string', 'not_null'=>1, 'default'=>'NULL', 'formatter'=>'kOptionsFormatter', 'use_phrases' => 1, 'options'=>Array('text' => 'la_type_text', 'select' => 'la_type_select', 'radio' => 'la_type_radio', 'password' => 'la_type_password', 'textarea' => 'la_type_textarea', 'label' => 'la_type_label')), + 'ValueList' => Array('type' => 'string','default' => ''), + 'DisplayOrder' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'OnGeneralTab' => Array('type' => 'int','not_null' => '1','default' => '0'), + ), + 'VirtualFields' => Array(), + + 'Grids' => Array( + 'Default' => Array( + 'Icons' => Array('default'=>'icon16_custom.gif'), + 'Fields' => Array( + 'CustomFieldId' => Array( 'title'=>'la_prompt_FieldId', 'data_block' => 'grid_checkbox_td' ), + 'FieldName' => Array( 'title'=>'la_prompt_FieldName'), + 'FieldLabel' => Array( 'title'=>'la_prompt_FieldLabel' ), + ), + + ), + ), + ); + +?> \ No newline at end of file Index: trunk/core/units/configuration/configuration_config.php =================================================================== diff -u -N --- trunk/core/units/configuration/configuration_config.php (revision 0) +++ trunk/core/units/configuration/configuration_config.php (revision 1310) @@ -0,0 +1,52 @@ + 'conf', + 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'ConfigurationEventHandler','file'=>'configuration_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'ConfigurationTagProcessor','file'=>'configuration_tag_processor.php','build_event'=>'OnBuild'), + 'AutoLoad' => true, + 'hooks' => Array(), + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + 4 => 'module', + 5 => 'section', + ), + 'IDField' => 'VariableName', + + 'TitlePresets' => Array( + 'config_list' => Array('prefixes' => Array('conf_List'), 'format' => "!la_updating_config!"), + ), + + 'TableName' => TABLE_PREFIX.'ConfigurationValues', + 'ListSQLs' => Array(''=>'SELECT * FROM '.TABLE_PREFIX.'ConfigurationAdmin LEFT JOIN '.TABLE_PREFIX.'ConfigurationValues Using(VariableName) '), + + + 'ItemSQLs' => Array(''=>'SELECT * FROM '.TABLE_PREFIX.'ConfigurationAdmin LEFT JOIN '.TABLE_PREFIX.'ConfigurationValues Using(VariableName) '), + + 'SubTables' => Array(), + + 'Fields' => Array( + 'VariableName' => Array('type' => 'string','not_null' => '1','default' => ''), + 'VariableValue' => array('type'=>'string', 'default'=>''), + 'ModuleOwner' => array('type'=>'string', 'default'=>'In-Portal'), + 'Section' => array('type'=>'string','not_null' => '1','default'=>''), + ), + + 'VirtualFields' => Array( + 'heading' => Array('type' => 'string','default' => ''), + 'prompt' => Array('type' => 'string','default' => ''), + 'element_type' => Array('type' => 'string','not_null' => '1','default' => ''), + 'validation' => Array('type' => 'string','default' => ''), + 'ValueList' => Array('type' => 'string','default' => ''), + 'DisplayOrder' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'Install' => Array('type' => 'int','not_null' => '1','default' => '1'), + ), + + 'Grids' => Array(), + ); + +?> \ No newline at end of file Index: trunk/kernel/units/category_items/category_items_tag_processor.php =================================================================== diff -u -N --- trunk/kernel/units/category_items/category_items_tag_processor.php (revision 0) +++ trunk/kernel/units/category_items/category_items_tag_processor.php (revision 1310) @@ -0,0 +1,26 @@ +Application->ConfigValue('Root_Name'); + $value = $this->Field($params); + $ret = $this->Application->Phrase($root_phrase).( $value ? ' > ' : '').$value; + if( $this->Field( Array('field'=> 'PrimaryCat') ) == 1 ) + { + $ret .= ' ('.$params['primary_title'].')'; + } + return $ret; + } + + function GetMainID() + { + $object =& $this->Application->recallObject( $this->getPrefixSpecial() ); + $table_info = $object->getLinkedInfo(); + return $table_info['ParentId']; + } + } + + +?> \ No newline at end of file Index: trunk/kernel/units/general/my_application.php =================================================================== diff -u -N --- trunk/kernel/units/general/my_application.php (revision 0) +++ trunk/kernel/units/general/my_application.php (revision 1310) @@ -0,0 +1,289 @@ + + * + * @return string + */ + function FindTag() + { + $tagOpen = strpos($this->Template, '<%', $this->Position); //Finding tag start + + $inp_tag = false; + $tagOpenLen = 2; + $inpOpen = strpos($this->Template, 'Position); + if ($inpOpen !== false && ($tagOpen === false || $inpOpen < $tagOpen)) { + $tagOpen = $inpOpen; + $inp_tag = true; + $tagOpenLen = 6; + } + + if ($tagOpen === false) { //If not tags left - adding all other data + $this->AppendOutput(substr($this->Template, $this->Position)); + return false; + } + + //Adding all data before tag open + $this->AppendOutput(substr($this->Template, $this->Position, $tagOpen - $this->Position)); + + //Finding tag end + $tagCloseLen = 2; + if ($inp_tag) { + $tagClose = strpos($this->Template, "/>", $tagOpen); + $inpClose = strpos($this->Template, "", $tagOpen); + if ($inpClose !== false && $inpClose < $tagClose) { + $tagClose = $inpClose; + $tagCloseLen = 7; + } + } + else { + $tagClose = strpos($this->Template, "%>", $tagOpen); + } + + if ($tagClose === false) die ("Can't find tag closing"); + + //Cutting out the tag itself + $tag = substr($this->Template, $tagOpen + $tagOpenLen, $tagClose - $tagOpen - $tagOpenLen); + + if ($inp_tag) { + if (strpos($tag, '_') !== false) { + list($prefix, $the_tag) = explode('_', $tag, 2); + $tag = $prefix.':'.$the_tag; + } + else $tag .= ':'; + } + + //Seting current position right after the tag + $this->Position = $tagClose + $tagCloseLen; + return $tag; + } + + function Parse($template, $name='unknown') + { + $this->Template = $template; + $this->TemplateName = $name; + $this->Position = 0; + $this->Output = ''; + + //While we have more tags + while ($tag_data = $this->FindTag()) + { + //Create tag object from passed tag data + if (defined('DEBUG_TAGS')&&DEBUG_TAGS) { + global $debugger; + $debugger->appendHTML("mode: ".$this->SkipModeName()." tag ".$debugger->highlightString($tag_data)." in ".$debugger->getFileLink($debugger->getLocalFile(DOC_ROOT.BASE_PATH.THEMES_PATH.'/'.$this->TemplateName).'.tpl', $this->CurrentLineNumber(), '', true)); + } + $tag =& new MyTag($tag_data, $this); + if (!$this->CheckRecursion($tag)) //we do NOT process closing tags + { + $tag->Process(); + } + } + + if ( !$this->GetParam('from_inportal') ) { + if ( strpos($this->Output, 'Application->recallObject('Inp1Parser'); + $this->Output = $inp1_parser->Parse($name, $this->Output); + } + } + return $this->Output; + } + + function ParseBlock($params, $force_pass_params=0, $as_template=false) + { + if (defined('EXPERIMENTAL_PRE_PARSE')) { + if (isset($this->Application->PreParsedBlocks[$params['name']]) ) { + $f = $this->Application->PreParsedBlocks[$params['name']]; + //$this->SetParams($params); + return $f($params); + } + } + + $BlockParser =& $this->Application->Factory->makeClass('TemplateParser'); + if (isset($params['pass_params']) || $force_pass_params) { + $BlockParser->SetParams(array_merge($this->Params, $params)); + } + else + $BlockParser->SetParams($params); + $this->Application->Parser =& $BlockParser; + if (!isset($params['name'])) die("***Error: Block name not passed to ParseBlock
"); + $templates_cache =& $this->Application->recallObject('TemplatesCache'); + + $template_name = $as_template ? $params['name'] : $templates_cache->GetTemplateFileName($params['name']) . '-block:'.$params['name']; + + $silent = getArrayValue($params, 'from_inportal') && !defined('DBG_TEMPLATE_FAILURE'); + + $o = $BlockParser->Parse( + $templates_cache->GetTemplateBody($params['name'], $silent), + $template_name + ); + $this->Application->Parser =& $this; + return $o; + } + } + + class MyTag extends Tag { + + /** + * Set's Prefix and Special for Tag object + * based on ones from tagname + * + * @param string $tag_data + * @access protected + */ + function ParseTagData($tag_data) + { + $tag_data = $this->ReplaceParams($tag_data) . ' '; + $tag_data = $this->Application->ReplaceLanguageTags($tag_data); + + + list ($key_data, $params) = explode(' ', $tag_data, 2); + + //cand.test_TagProcessor:PrintList + + $tmp=explode(':',$key_data); + $this->Tag=$tmp[1]; + + $tmp=$this->Application->processPrefix($tmp[0]); + $this->Prefix=$tmp['prefix']; + $this->Special=$tmp['special']; + $this->Processor=$this->Prefix; + + if ($params != '') $this->ParseNamedParams($params); + } + + /** + * Set's Prefix and Special for TagProcessor + * based on tag beeing processed + * + * @return string + * @access protected + */ + function DoProcessTag() + { + // $tag->Prefix - l_TagProcessor + $tmp = $this->Application->processPrefix($this->Processor); + + $processor =& $this->Application->recallObject($tmp['prefix'].'_TagProcessor'); // $this->Processor + + $tmp=explode('_',$tmp['prefix'],2); + $processor->Prefix=$tmp[0]; + $processor->Special=$this->Special; + + return $processor->ProcessTag($this); + } + + /** + * Process IF tags in specific way + * + */ + function Process() + { + if ($this->Processor == 'm' || $this->Processor == 'm_TagProcessor') { //if we are procssing Main tags + if ($this->Tag == 'block') { + $tag =& new BlockTag('', $this->Parser); + $tag->CopyFrom($this); + $tag->Process(); + } + elseif ($this->Parser->SkipMode == skip_tags) { + return; + } + elseif ( + $this->Tag == 'if' || + $this->Tag == 'ifnot' || + $this->Tag == 'else' || + $this->Tag == 'elseif' + ) { + $tag =& new MyConstructTag('', $this->Parser); + $tag->CopyFrom($this); + $tag->Process(); + } + elseif ($this->Tag == 'xml') { + $tag =& new XMLTag('', $this->Parser); + $tag->CopyFrom($this); + $tag->Process(); + } + else { + if ($this->Parser->SkipMode == skip) return; + //if (!$this->ProcessMainTag()) //other main tags + $this->ProcessTag(); + } + } + else { //normal tags - processors other than main + if ($this->Parser->SkipMode == skip_tags || $this->Parser->SkipMode == skip) return; //do not parse if we skipping tags + $this->ProcessTag(); + //$this->Parser->AppendOutput(''.$this->Tag.''); + } + } + + + + } + + class MyConstructTag extends ConstructTag { + + function GetLogic() + { + $prefix = $this->GetParam('prefix'); + $function = $this->GetParam('function'); + + if ($prefix !== false) { + $tag =& new MyTag('', $this->Parser); + $tag->Tag = $function; + + $tmp = $this->Application->processPrefix($prefix); + $tag->Processor = $tmp['prefix']; + + $tag->Prefix=$tmp['prefix']; + $tag->Special=$tmp['special']; + $tag->NamedParams = $this->NP; + $this->Logic = $tag->DoProcessTag(); + // echo " this->Logic : ".$this->Logic."
"; + } + else + { + $this->Logic = $function; + } + } + + } + + class MyApplication extends kApplication { + + function RegisterDefaultClasses() + { + parent::RegisterDefaultClasses(); + $this->registerClass('InpTemplateParser',MODULES_PATH.'/in-commerce/general/my_application.php','TemplateParser'); + + $this->registerClass('Inp1Parser',MODULES_PATH.'/in-commerce/general/inp1_parser.php','Inp1Parser'); + + $this->registerClass('InpSessionStorage',MODULES_PATH.'/in-commerce/general/inp_ses_storage.php','SessionStorage'); + $this->registerClass('kCatDBItem',MODULES_PATH.'/in-commerce/general/cat_dbitem.php'); + $this->registerClass('kCatDBList',MODULES_PATH.'/in-commerce/general/cat_dblist.php'); + $this->registerClass('kCatDBEventHandler',MODULES_PATH.'/in-commerce/general/cat_event_handler.php'); + $this->registerClass('InpLoginEventHandler',MODULES_PATH.'/in-commerce/general/inp_login_event_handler.php','login_EventHandler'); + $this->registerClass('InpDBEventHandler',MODULES_PATH.'/in-commerce/general/inp_db_event_handler.php','kDBEventHandler'); + $this->registerClass('InpTempTablesHandler',MODULES_PATH.'/in-commerce/general/inp_temp_handler.php','kTempTablesHandler'); + $this->registerClass('InpUnitConfigReader',MODULES_PATH.'/in-commerce/general/inp_unit_config_reader.php','kUnitConfigReader'); + + $this->registerClass('InpCustomFieldsHelper',MODULES_PATH.'/in-commerce/general/custom_fields.php','InpCustomFieldsHelper'); + } + + function KernelDie($message) + { + $this->trigerError($message,E_USER_ERROR); + exit; + } + + function ConfigValue($name) + { + return $this->DB->GetOne('SELECT VariableValue FROM '.TABLE_PREFIX.'ConfigurationValues WHERE VariableName = '.$this->DB->qstr($name) ); + } + } + +?> \ No newline at end of file Index: trunk/core/units/categories/categories_tag_processor.php =================================================================== diff -u -N --- trunk/core/units/categories/categories_tag_processor.php (revision 0) +++ trunk/core/units/categories/categories_tag_processor.php (revision 1310) @@ -0,0 +1,73 @@ +Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List',$params); + $id_field = $this->Application->getUnitOption($this->Prefix,'IDField'); + + $cat_id = $this->Application->GetVar('m_cat_id') ? $this->Application->GetVar('m_cat_id') : 0; + $list->SetWhereClause( 'ParentId='.$this->Application->GetVar('m_cat_id') ); + $list->Query(); + $o = ''; + $list->GoFirst(); + + $block_params=$this->prepareTagParams($params); + $block_params['name']=$params['block']; + $block_params['pass_params']='true'; + + while (!$list->EOL()) + { + $block_params['cat_id'] = $list->GetDBField('CategoryId'); + + $this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); // for edit/delete links using GET + $o.= $this->Application->ParseBlock($block_params, 1); + $list->GoNext(); + } + + $this->Application->SetVar( $this->getPrefixSpecial().'_id', ''); + return $o; + } + + function RootCategoryName($params) + { + $root_phrase = $this->Application->ConfigValue('Root_Name'); + $ret = $this->Application->Phrase($root_phrase); + return $ret; + } + + function CategoryPath($params) + { + if(!isset($params['cat_id'])) + { + $params['cat_id'] = $this->Application->GetVar('m_cat_id'); + $block_params['current'] = 1; + } + $block_params['separator'] = $params['separator']; + if($params['cat_id'] == 0) + { + $block_params['name'] = $params['rootcatblock']; + return $this->Application->ParseBlock($block_params); + } + else + { + $cat_object = $this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List' ); + $sql = 'SELECT CategoryId, ParentId, Name FROM '.$cat_object->TableName.' WHERE CategoryId='.$params['cat_id']; + $res = $this->Conn->GetRow($sql); + $block_params['name'] = $params['block']; + $block_params['cat_name'] = $res['Name']; + $block_params['separator'] = $params['separator']; + $block_params['cat_id'] = $res['CategoryId']; + $next_params['separator'] = $params['separator']; + $next_params['rootcatblock'] = $params['rootcatblock']; + $next_params['block'] = $params['block']; + $next_params['cat_id'] = $res['ParentId']; + return $this->CategoryPath($next_params).$this->Application->ParseBlock($block_params); + } + } + +} + + +?> \ No newline at end of file Index: trunk/kernel/units/custom_values/custom_value_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/custom_values/custom_value_event_handler.php (revision 0) +++ trunk/kernel/units/custom_values/custom_value_event_handler.php (revision 1310) @@ -0,0 +1,93 @@ +getObject(); + + $top_prefix = $this->GetTopmostPrefix($event); + $item_type = $this->Application->getUnitOption($top_prefix, 'ItemType'); + + $item_resource_id = $this->GetParentResourceId($event); + + // there is no ResourceId when creating new item, but we need some id for SQL to work + if (!$item_resource_id) $item_resource_id = 0; + + $sql = $object->SelectClause; + $sql = sprintf($sql, $item_resource_id); + $object->setSelectSQL($sql); + + $where_clause='Type = '.$item_type; + if ($event->Special=="general"){ + $where_clause.=' AND OnGeneralTab=1'; + } + $object->SetWhereClause($where_clause); + + $object->AddOrderField('DisplayOrder', 'ASC'); + $object->SetPerPage(-1); + } + + function GetParentResourceId(&$event) + { + $top_object = $this->Application->RecallObject( $this->GetTopmostPrefix($event) ); + return $top_object->GetDBField('ResourceId'); + } + + function OnPreSave(&$event) + { + $object =& $event->getObject(); + + $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); + if($items_info) + { + foreach($items_info as $custom_field_id => $values) + { + $set_values = Array( + 'CustomFieldId' => $custom_field_id, + 'Value' => $values['Value'], + 'ResourceId' => $values['ResourceId'] != 0 ? $values['ResourceId'] : $this->GetParentResourceId($event), + ); + + // ResourceId will be -1 if we are creating new product, then we get ID directly, + // because it should be already set by parent' event, as we are in hAFTER hook + + $id = $values['CustomDataId']; + if ($id) { //if it's already existing custom field record - update id + $object->SetDefaultValues(); + $object->Load($id); + $object->SetFieldsFromHash($set_values); + if( $object->Update($id) ) + { + $event->status=erSUCCESS; + } + else + { + $event->status=erFAIL; + $event->redirect=false; + break; + } + } + else { //new custom field record - create it and set temp id! + $object->SetDefaultValues(); + $object->SetFieldsFromHash($set_values); + if( $object->Create() ) + { + $object->setTempID(); + $event->status=erSUCCESS; + } + } + } + } + + // this is critical, as the object here is Item, but if something fails, the template could use the same name as grid + // the problem appeared on products general tab, when validation does not go through for product, + // and the templates is getting parsed + $this->Application->removeObject($event->Prefix_Special); + + } + +} + +?> \ No newline at end of file Index: trunk/core/units/general/custom_fields.php =================================================================== diff -u -N --- trunk/core/units/general/custom_fields.php (revision 0) +++ trunk/core/units/general/custom_fields.php (revision 1310) @@ -0,0 +1,69 @@ +ParseConfigSQL($values_list); + $optionValuesTmp=explode(',', $optionValuesStr); + $optionValues=array(); + foreach ($optionValuesTmp as $optionValue){ + list($key, $val) = explode("=", $optionValue); + + if (substr($val,0,1)=="+") + $val = substr($val, 1); + else + $val = $this->Application->Phrase($val); + + $optionValues[$key]=$val; + } + return $optionValues; + } + + function ParseConfigSQL($valueString){ + $string = trim(str_replace("",TABLE_PREFIX,$valueString)); + + $start = strpos($string,""); + + while($start){ + $end = strpos($string,""); + if(!$end){ + $end = strlen($string); + } + $len = $end - $start; + $sql = substr($string,$start+5,$len-5); + + $sql_val = $this->QueryConfigSQL($sql); + + /*if ($start>0 && $sql_val!='') + $sql_val=",".$sql_val;*/ + if ($end < strlen($string)-6 && $sql_val!='') + $sql_val.=","; + + $chunk1=substr($string,0,$start); + $chunk2=substr($string,$end+6); + $s = $chunk1.$sql_val.$chunk2; + + + $string = $s; + $start = strpos($string,""); + } + return $string; + } + + function QueryConfigSQL($sql){ + $db =& $this->Application->GetADODBConnection(); + + $valArray=$db->Query($sql); + for ($i=0; $i \ No newline at end of file Index: trunk/kernel/units/configuration/configuration_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/configuration/configuration_event_handler.php (revision 0) +++ trunk/kernel/units/configuration/configuration_event_handler.php (revision 1310) @@ -0,0 +1,102 @@ +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->SetWhereClause('%1$s.ModuleOwner="'.$module_owner.'" AND %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'))); + } + } + } + + /** + * 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); + $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 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; + } + + } + +?> \ No newline at end of file Index: trunk/core/units/general/inp_ses_storage.php =================================================================== diff -u -N --- trunk/core/units/general/inp_ses_storage.php (revision 0) +++ trunk/core/units/general/inp_ses_storage.php (revision 1310) @@ -0,0 +1,61 @@ +setTableName(TABLE_PREFIX.'UserSession'); + $this->SessionDataTable = TABLE_PREFIX.'SessionData'; + $this->setIDField('SessionKey'); + $this->TimestampField = 'LastAccessed'; + $this->DataValueField = 'VariableValue'; + $this->DataVarField = 'VariableName'; + } + + function LocateSession($sid) + { + $query = ' SELECT '.$this->TimestampField.' FROM '.$this->TableName.' WHERE '.$this->IDField.' = '.$this->Conn->qstr($sid); + $result = $this->Conn->GetOne($query); + + if($result===false) return false; + + $this->Expiration = $result + $this->SessionTimeout; + return true; + } + + function UpdateSession(&$session) + { + $query = ' UPDATE '.$this->TableName.' SET '.$this->TimestampField.' = unix_timestamp() WHERE '.$this->IDField.' = '.$this->Conn->qstr($session->SID); + $this->Conn->Query($query); + } + + function GetExpiredSIDs() + { + $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.time().' - '.$this->TimestampField.' > '.$this->SessionTimeout; + $ret = $this->Conn->GetCol($query); + if($ret) $this->DeleteEditTables(); + return $ret; + + } + + function DeleteEditTables() + { + $tables = $this->Conn->GetCol('SHOW TABLES'); + $mask = '/'.TABLE_PREFIX.'ses_(.*)_edit_(.*)/'; + $sql='SELECT COUNT(*) FROM '.$this->TableName.' WHERE '.$this->IDField.' = \'%s\''; + foreach($tables as $table) + { + if( preg_match($mask,$table,$rets) ) + { + $sid=$rets[1]; + $is_alive = $this->Conn->GetOne( sprintf($sql,$sid) ); + if(!$is_alive) $this->Conn->Query('DROP TABLE IF EXISTS '.$table); + } + } + } +} + +?> \ No newline at end of file Index: trunk/core/units/general/cat_dblist.php =================================================================== diff -u -N --- trunk/core/units/general/cat_dblist.php (revision 0) +++ trunk/core/units/general/cat_dblist.php (revision 1310) @@ -0,0 +1,12 @@ +Special != 'showall' ? '('.TABLE_PREFIX.'CategoryItems.CategoryId = '.$this->Application->GetVar('m_cat_id').') ' : ''; + } + +} + +?> \ No newline at end of file Index: trunk/core/units/custom_fields/custom_fields_event_handler.php =================================================================== diff -u -N --- trunk/core/units/custom_fields/custom_fields_event_handler.php (revision 0) +++ trunk/core/units/custom_fields/custom_fields_event_handler.php (revision 1310) @@ -0,0 +1,84 @@ +getObject(); + + $item_type=$this->Application->GetVar('cf_type'); + $object->SetWhereClause('%1$s.Type='.$item_type); + $object->AddOrderField('DisplayOrder', 'ASC'); + } + + /** + * Prevents from duplicate item creation + * + * @param kEvent $event + */ + function OnBeforeItemCreate(&$event) + { + $object =& $event->getObject(); + $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); + + $new_field_name=$items_info[0]['FieldName']; + + $table = $this->Application->getUnitOption($event->Prefix,'TableName'); + $found = $this->Conn->GetOne("SELECT count(*) FROM ".$table." WHERE FieldName='".$new_field_name."'"); + + if($found){ + $event->status=erFAIL; + $object->FieldErrors['FieldName']['pseudo'] = $this->Application->Phrase('la_error_CustomExists'); + } + else { + $item_type=$this->Application->GetVar('cf_type'); + + $object->SetDBField('Type', $this->Application->GetVar('cf_type')); + } + } + + function OnAfterItemCreate(&$event) + { + $this->Application->SetVar('cf_id', ''); + } + + function OnAfterItemUpdate(&$event) + { + $this->Application->SetVar('cf_id', ''); + } + + function OnCancelEdit(&$event){ + $this->Application->SetVar('cf_id', ''); + } + /** + * Occurse after deleting item, id of deleted item + * is stored as 'id' param of event + * + * @param kEvent $event + * @access public + */ + function OnAfterItemDelete(&$event) + { + $object =& $event->getObject(); + $custom_field_id=$event->getEventParam('id'); + $this->Application->SetVar('cf_id', ''); + + $sql='DELETE FROM '.TABLE_PREFIX.'CustomMetaData WHERE CustomFieldId='.$custom_field_id; + $this->Conn->Query($sql); + + + } + + function OnMassDelete(&$event) + { + parent::OnMassDelete($event); + $event->redirect_params = Array('opener' => 's'); + } + } +?> \ No newline at end of file Index: trunk/core/units/category_items/category_items_config.php =================================================================== diff -u -N --- trunk/core/units/category_items/category_items_config.php (revision 0) +++ trunk/core/units/category_items/category_items_config.php (revision 1310) @@ -0,0 +1,51 @@ + 'ci', + 'ItemClass' => Array('class'=>'CategoryItems_DBItem','file'=>'category_items_dbitem.php','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'CategoryItemsEventHander','file'=>'category_items_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'CategoryItemsTagProcessor','file'=>'category_items_tag_processor.php','build_event'=>'OnBuild'), + 'AutoLoad' => true, + 'hooks' => Array(), + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + 'IDField' => 'CategoryId', // in this case idfield doesn't exit in destination table + 'TableName' => TABLE_PREFIX.'CategoryItems', + 'ParentTableKey'=> 'ResourceId', + 'ForeignKey' => 'ItemResourceId', + 'ParentPrefix' => 'p', + 'AutoDelete' => true, + 'AutoClone' => false, // Critical !!! + + 'ListSQLs' => Array( ''=>" SELECT ci.*, c.CachedNavbar AS CategoryName, IF(ISNULL(c.CategoryId),0,c.CategoryId) AS DummyId + FROM %1\$s ci + LEFT JOIN ".TABLE_PREFIX."Category AS c ON c.CategoryId = ci.CategoryId", + ), // key - special, value - list select sql + 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', + ), + + 'Fields' => Array( + 'DummyId' => Array(), + 'CategoryId' => Array('type'=>'int','not_null'=>1,'default'=>0), + 'ItemResourceId' => Array('not_null' => 1, 'default' => 0), + 'PrimaryCat' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), + ), + 'VirtualFields' => Array('DummyId'=>1 + ), + + 'Grids' => Array( + 'Default' => Array( + 'Icons' => Array('default'=>'icon16_custom.gif'), // icons for each StatusField values, if no matches or no statusfield selected, then "default" icon is used + 'Fields' => Array( + 'CategoryName' => Array( 'title'=>'la_col_Category', 'data_block' => 'grid_checkbox_category_td'), + ), + + ), + ), + ); + +?> \ No newline at end of file Index: trunk/kernel/units/configuration/configuration_tag_processor.php =================================================================== diff -u -N --- trunk/kernel/units/configuration/configuration_tag_processor.php (revision 0) +++ trunk/kernel/units/configuration/configuration_tag_processor.php (revision 1310) @@ -0,0 +1,57 @@ +Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List',$params); + $id_field = $this->Application->getUnitOption($this->Prefix,'IDField'); + + $list->PerPage=-1; + $list->Query(); + $o = ''; + $list->GoFirst(); + + $block_params=$this->prepareTagParams($params); + $block_params['name']=$params['block']; + $block_params['pass_params']='true'; + $block_params['IdField'] = $id_field; + + $next_block=$params['full_block']; + + $prev_title=""; + + while (!$list->EOL()) + { + $nextItemPrompt=$list->Records[$list->CurrentIndex+1]['prompt']; + $thisItemPrompt=$list->Records[$list->CurrentIndex]['prompt']; + + $this_title=$list->Records[$list->CurrentIndex]['heading']; + + if ($this_title!=$prev_title){ + $prev_title=$this_title; + $section_header_params=array(); + $section_header_params['name']='config_section_header'; + $section_header_params['title']=$this->Application->Phrase($this_title); + $o.= $this->Application->ParseBlock($section_header_params, 1); + } + + if ($nextItemPrompt==$thisItemPrompt){ + $curr_block=$params['half_block1']; + $next_block=$params['half_block2']; + }else{ + $curr_block=$next_block; + $next_block=$params['full_block']; + } + $block_params['name']=$curr_block; + + $this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); + $o.= $this->Application->ParseBlock($block_params, 1); + + $list->GoNext(); + } + return $o; + } +} + +?> \ No newline at end of file Index: trunk/kernel/units/categories/categories_config.php =================================================================== diff -u -N --- trunk/kernel/units/categories/categories_config.php (revision 0) +++ trunk/kernel/units/categories/categories_config.php (revision 1310) @@ -0,0 +1,59 @@ + 'c', + 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'CategoriesEventHandler','file'=>'categories_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'CategoriesTagProcessor','file'=>'categories_tag_processor.php','build_event'=>'OnBuild'), + 'AutoLoad' => true, + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + 'IDField' => 'CategoryId', + 'TableName' => TABLE_PREFIX.'Category', + + 'ListSQLs' => Array( ''=> 'SELECT * FROM %s'), + // key - special, value - list select sql + 'ItemSQLs' => Array( ''=> 'SELECT * FROM %s'), + + 'Fields' => Array + ( + 'CategoryId' => Array('type' => 'int','not_null' => '1','default' => ''), + 'Type' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'ParentId' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'Name' => Array('type' => 'string','not_null' => '1','default' => ''), + 'Description' => Array('type' => 'string','not_null' => '1','default' => ''), + 'CreatedOn' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'EditorsPick' => Array('type' => 'int','default' => ''), + 'Status' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'Pop' => Array('type' => 'int','default' => ''), + 'Priority' => Array('type' => 'int','default' => ''), + 'MetaKeywords' => Array('type' => 'string','default' => ''), + 'CachedDescendantCatsQty' => Array('type' => 'int','default' => ''), + 'CachedNavbar' => Array('type' => 'string','not_null' => '1','default' => ''), + 'CreatedById' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'ResourceId' => Array('type' => 'int','default' => ''), + 'ParentPath' => Array('type' => 'string','not_null' => '1','default' => ''), + 'MetaDescription' => Array('type' => 'string','default' => ''), + 'HotItem' => Array('type' => 'int','not_null' => '1','default' => '2'), + 'NewItem' => Array('type' => 'int','not_null' => '1','default' => '2'), + 'PopItem' => Array('type' => 'int','not_null' => '1','default' => '2'), + 'Modified' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'ModifiedById' => Array('type' => 'int','not_null' => '1','default' => '0'), + ), + + 'Grids' => Array( + 'Default' => Array( + 'Icons' => Array('default'=>'icon16_cat.gif'), + 'Fields' => Array( + 'Name' => Array( 'width'=>150, 'title'=>'la_col_Title', 'data_block'=>'category_td' ), + ), + + ), + ), + ); + +?> \ No newline at end of file Index: trunk/core/units/general/inp_temp_handler.php =================================================================== diff -u -N --- trunk/core/units/general/inp_temp_handler.php (revision 0) +++ trunk/core/units/general/inp_temp_handler.php (revision 1310) @@ -0,0 +1,158 @@ +GetTempName($table), + $table, + $IdField, + $ids); + $this->Conn->Query($query); + if (isset($autoincrement) && !empty($autoincrement)) { + $query = sprintf("ALTER TABLE %s + CHANGE %s %s INT(11) NOT NULL AUTO_INCREMENT, + ADD PRIMARY KEY (%s)", + $this->GetTempName($table), + $autoincrement, + $autoincrement, + $autoincrement, + $this->GetTempName($table)); + echo $query.'
'; + $this->Conn->Query($query); + } + + if($table == TABLE_PREFIX.'Images') + { + $query = sprintf('SELECT LocalPath,ThumbPath FROM %s WHERE %s IN (%s)',$table,$IdField,$ids); + $res = $this->Conn->Query($query); + + foreach ($res as $record) + { + foreach ($record as $field => $field_value) + { + $source_file = DOC_ROOT.BASE_PATH.$field_value; + $dest_file = DOC_ROOT.BASE_PATH.str_replace(IMAGES_PATH, IMAGES_PENDING_PATH, $field_value); + copy($source_file, $dest_file); + } + } + + $update_sql = 'UPDATE '.$this->GetTempName($table).' SET LocalPath = REPLACE(LocalPath, + "'.IMAGES_PATH.'", "'.IMAGES_PENDING_PATH.'"), + ThumbPath = REPLACE(ThumbPath, + "'.IMAGES_PATH.'","'.IMAGES_PENDING_PATH.'") + WHERE '.$IdField.' IN ('.$ids.')'; + $this->Conn->Query($update_sql); + + } + + } + + function CopyTempToOriginal($table, $IdField, $autoincrement=null) + { + if (isset($autoincrement) && !empty($autoincrement)) + { + $this->RemoveAutoincrement($table, $autoincrement); + } + + if( $table != $this->MasterTable ) + { + // get main ids + $sql = 'SELECT '.$this->Tables[$table]['ForeignKey']. + ' FROM '.$this->MasterTable. + ' WHERE '.$this->Tables[$this->MasterTable]['IdField'].' IN ('.implode(',',$this->MasterIDs).')'; + $main_ids = $this->Conn->GetCol($sql); + + if($main_ids) + { + if ($table == TABLE_PREFIX.'Images') + { + $sql = 'SELECT LocalPath, ThumbPath FROM '.$table. + ' WHERE '.$IdField.' IN ('.implode(',', $main_ids).')'; + $res = $this->Conn->Query($sql); + + foreach ($res as $record) + { + foreach ($record as $field => $field_value) + { + $source_file = DOC_ROOT.BASE_PATH.$field_value; + unlink($source_file); + } + } + } + + // delete all related to main table records from subtable + $sql = 'DELETE FROM '.$table.' WHERE '.$IdField.' IN ('.implode(',',$main_ids).')'; + $this->Conn->Query($sql); + } + + $subtable_idfield = $this->Tables[$table]['SubIDField']; + $this->Conn->Query('UPDATE '.$this->GetTempName($table).' SET '.$subtable_idfield.' = 0 WHERE '.$subtable_idfield.' < 0'); + } + else + { + // get IDs, that exist in temp table + $query = sprintf('SELECT %s FROM %s', + $IdField, + $this->GetTempName($table)); + $this->MasterIDs = $this->Conn->GetCol($query); // were $temp_ids before + if($this->MasterIDs) + { + // delete original records from master table + $query = sprintf('DELETE FROM %s WHERE %s IN (%s)', + $table, + $IdField, + implode(',',$this->MasterIDs) ); + $this->Conn->Query($query); + } + } + + $query = sprintf("INSERT INTO %s + SELECT * FROM %s", + $table, + $this->GetTempName($table)); + $this->Conn->Query($query); + + + if($table == TABLE_PREFIX.'Images' && count($main_ids) > 0) + { + $query = sprintf(' SELECT LocalPath, ThumbPath FROM %s + WHERE %s IN (%s)', + $table, + $IdField, + implode(',',$this->MasterIDs)); + $res = $this->Conn->Query($query); + + foreach ($res as $record) + { + foreach ($record as $field => $field_value) + { + $source_file = DOC_ROOT.BASE_PATH.$field_value; + $dest_file = DOC_ROOT.BASE_PATH.str_replace(IMAGES_PENDING_PATH, IMAGES_PATH, $field_value); + rename($source_file, $dest_file); + } + } + + $update_sql = 'UPDATE '.$table.' SET LocalPath = REPLACE(LocalPath, + "'.IMAGES_PENDING_PATH.'", "'.IMAGES_PATH.'"), + ThumbPath = REPLACE(ThumbPath, + "'.IMAGES_PENDING_PATH.'", "'.IMAGES_PATH.'") + WHERE '.$IdField.' IN ('.implode(',', $this->MasterIDs).')'; + $this->Conn->Query($update_sql); + + } + + return $this->Conn->getInsertID(); + } + +} + + +?> \ No newline at end of file Index: trunk/core/units/general/inp1_parser.php =================================================================== diff -u -N --- trunk/core/units/general/inp1_parser.php (revision 0) +++ trunk/core/units/general/inp1_parser.php (revision 1310) @@ -0,0 +1,155 @@ +InportalInited) { + $this->InitInPortal(); + } + global $objTemplate; + $template_body = $objTemplate->ParseTemplateFromBuffer($tname, $template_body); + return $template_body; + } + + + function InitInPortal() + { + $this->InportalInited = true; + /*global $pathtoroot, $FrontEnd, $indexURL, $rootURL, $secureURL, $var_list, $CurrentTheme, + $objThemes, $objConfig, $m_var_list, $timeout, $objLanguages, $objLanguageCache, + $TemplateRoot, $objTemplate, $html, $objSession, $Errors, $objCatList, $objUsers, + $env, $mod_prefix, $ExtraVars, $timestart, $timeend, $timeout, $sqlcount, $totalsql, + $template_path, $modules_loaded, $mod_root_cats, $objModules, $objItemTypes;*/ + + + global $sec, $usec, $timestart, $pathtoroot, $FrontEnd, $indexURL, $kernel_version, $FormError, + $FormValues, $ItemTables, $KeywordIgnore, $debuglevel, + $LogLevel, $LogFile, $rq_value, $rq_name, $dbg_constMap, $dbg_constValue, $dbg_constName, + $debugger, $g_LogFile, $LogData, $Errors, + $g_DebugMode, $totalsql, $sqlcount, $objConfig, $ItemTypePrefixes, $ItemTagFiles, $objModules, + $objSystemCache, $objBanList, $objItemTypes, $objThemes, $objLanguages, $objImageList, $objFavorites, + $objUsers, $objGroups, $DownloadId, $objPermissions, $objPermCache, $m_var_list, $objCatList, + $objCustomFieldList, $objCustomDataList, $objCountCache, $CRLF, $objMessageList, $objEmailQueue, + $ExtraVars, $adodbConnection, $sql, $rs, $mod_prefix, $modules_loaded, $name, + $template_path, $mod_root_cats, $value, $mod, $ItemTypes, + $ParserFiles, $SessionQueryString, $var_list, $objSession, + $orderByClause, $TemplateRoot, $ip, $UseSession, $Action, $CookieTest, $sessionId, + $var_list_update, $CurrentTheme, $UserID, $objCurrentUser, $objLanguageCache, + $folder_name, $objLinkList, $tag_override, $timeZones, $siteZone, $serverZone, + $lastExpire, $diffZone, $date, $nowDate, $lastExpireDate, $SearchPerformed, + $TotalMessagesSent, $ado, $adminDir, $rootURL, $secureURL, $html, $timeout, + $pathchar, $objTemplate; + + $pathtoroot = "./"; + $pathtoroot = realpath($pathtoroot)."/"; + + if (!file_exists($pathtoroot."config.php")) { + echo "In-Portal is probably not installed, or configuration file is missing.
"; + echo "Please use the installation script to fix the problem.

"; + echo "Go to installation script

"; + flush(); + die(); + } + + //ob_start(); + $FrontEnd=1; + + $indexURL="../../index.php"; //Set to relative URL from the theme directory + + /* initalize the in-portal system */ + include_once(FULL_PATH."/kernel/startup.php"); + + $rootURL="http://".ThisDomain().$objConfig->Get("Site_Path"); + + //$secureURL = "https://".ThisDomain().$objConfig->Get("Site_Path"); + $secureURL = $rootURL; + + $html= ''; + + if( !$var_list['t'] ) $var_list['t'] = 'index'; + + if( !isset($CurrentTheme) ) $CurrentTheme = null; + if( !is_object($CurrentTheme) ) $CurrentTheme = $objThemes->GetItem($m_var_list["theme"]); + + if(is_object($CurrentTheme)) + { + if(!$CurrentTheme->Get("Enabled")) + { + $CurrentTheme = $objThemes->GetItem($objThemes->GetPrimaryTheme()); + } + if((int)$CurrentTheme->Get("ThemeId")>0) + { + $timeout = $CurrentTheme->Get("CacheTimeout"); + $objLanguageCache->LoadTemplateCache($var_list["t"],$timeout,$CurrentTheme->Get("ThemeId")); + $objLanguageCache->LoadCachedVars($objSession->Get("Language")); + + $TemplateRoot = $CurrentTheme->ThemeDirectory()."/"; + + $objTemplate = new clsTemplateList($TemplateRoot); + //$html = $objTemplate->ParseTemplate($var_list["t"]); + } + else + { + echo "No Primary Theme Selected"; + die(); + } + } + else + { + echo "No Primary Theme Selected\n"; + die(); + } + + if(is_object($objSession)) + { + + $objSession->SetVariable("Template_Referer", $_local_t); + } + if($objTemplate->ErrorNo == -1) + { + $html = $objTemplate->ParseTemplate('error_template'); + } + //$html = replacePngTags($html); + LogEntry("Output Start\n"); + $html .= ""; + if( IsDebugMode() ) + { + if($Action) $debugger->setHTMLByIndex(1,'Front Action: '.$Action.'','append'); + $html = 'Show Debugger
'.$html; + } + else + { + header("Content-length: ".strlen($html)); + } + header("Connection-Type: Keep-Alive"); + echo $html; + + LogEntry("Output End\n"); + + if( isset($template) && $template->ErrorNo != 0 ) + { + print "\n(".$objTemplate->ErrorNo.") ".$objTemplate->ErrorStr."\n"; + } + + LogEntry("Output Complete\n"); + $objLanguageCache->SaveTemplateCache(); + LogEntry("Templates Cached\n"); + + //if($objSession->SessionEnabled()) + // $objSession->SaveSessionData(); + //echo "Cookie:
"; print_r($_COOKIE); echo "

\n"; + //ob_end_flush(); + $timeend = getmicrotime(); + $diff = $timeend - $timestart; + + LogEntry("\nTotal Queries Executed: $sqlcount in $totalsql seconds\n"); + LogEntry("\nPage Execution Time: $diff seconds\n", true); + if($LogFile) + fclose($LogFile); + } +} + +?> \ No newline at end of file Index: trunk/kernel/units/general/inp_login_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/general/inp_login_event_handler.php (revision 0) +++ trunk/kernel/units/general/inp_login_event_handler.php (revision 1310) @@ -0,0 +1,18 @@ +Application->ConfigValue('AdminDirectory'); + if(!$admin_dir) $admin_dir = 'admin'; + $location = $this->Application->BaseURL().$admin_dir.'/index.php?expired=1'; + header('Location: '.$location); + exit; + } + + + } + + +?> \ No newline at end of file Index: trunk/kernel/units/general/cat_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/general/cat_event_handler.php (revision 0) +++ trunk/kernel/units/general/cat_event_handler.php (revision 1310) @@ -0,0 +1,65 @@ +Factory->includeClassFile('kDBEventHandler'); + +class kCatDBEventHandler extends InpDBEventHandler { + + function OnCopy(&$event) + { + $object = $event->getObject(); + $this->StoreSelectedIDs($event); + $ids = $this->getSelectedIDs($event); + $this->Application->StoreVar($this->getPrefixSpecial().'_clipboard', implode(',', $ids)); + $this->Application->StoreVar($this->getPrefixSpecial().'_clipboard_mode', 'copy'); + + $this->Application->StoreVar('clipboard', 'COPY-0.'.TABLE_PREFIX.'Products.ResourceId=0'); + $event->redirect_params = Array('opener' => 's', 'pass_events'=>true); //do not go up - STAY + } + + function OnCut(&$event) + { + $object = $event->getObject(); + $this->StoreSelectedIDs($event); + $ids = $this->getSelectedIDs($event); + $this->Application->StoreVar($this->getPrefixSpecial().'_clipboard', implode(',', $ids)); + $this->Application->StoreVar($this->getPrefixSpecial().'_clipboard_mode', 'cut'); + + $this->Application->StoreVar('clipboard', 'CUT-0.'.TABLE_PREFIX.'Products.ResourceId=0'); + $event->redirect_params = Array('opener' => 's', 'pass_events'=>true); //do not go up - STAY + } + + function OnPaste(&$event) + { + $ids = $this->Application->RecallVar($this->getPrefixSpecial().'_clipboard'); + if ($ids == '') { + $event->redirect = false; + return; + } + + //recalling by different name, because we may get kDBList, if we recall just by prefix + $object =& $this->Application->recallObject($event->getPrefixSpecial().'.item', $event->Prefix); + $this->prepareObject(&$object,&$event); + + if ($this->Application->RecallVar($this->getPrefixSpecial().'_clipboard_mode') == 'copy') { + $ids_arr = explode(',', $ids); + + $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + + if($ids_arr) + { + $temp->CloneItems($event->Prefix, $event->Special, $ids_arr); + } + } + else { // mode == cut + $ids_arr = explode(',', $ids); + foreach ($ids_arr as $id) { + $object->Load($id); + $object->MoveToCat(); + } + } + $event->redirect = true; + } +} + +?> \ No newline at end of file Index: trunk/kernel/units/categories/categories_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/categories/categories_event_handler.php (revision 0) +++ trunk/kernel/units/categories/categories_event_handler.php (revision 1310) @@ -0,0 +1,36 @@ +Application->recallObject( $event->Prefix ); + $current_cat = $this->Application->GetVar('m_cat_id'); + if($current_cat) + { + $sql = 'SELECT ParentId FROM '.$cat_object->TableName.' WHERE CategoryId='.$current_cat; + $cat_to_go = $this->Conn->GetOne($sql); + } + else + { + $cat_to_go = 0; + } + $event->redirect = 'in-commerce/product_selector'; + $event->redirect_params = Array('m_cat_id' => $cat_to_go); + } + + function OnGoHome(&$event) + { + $cat_to_go = 0; + $event->redirect = 'in-commerce/product_selector'; + $event->redirect_params = Array('m_cat_id' => $cat_to_go); + } + +} + +?> \ No newline at end of file Index: trunk/core/units/category_items/category_items_event_handler.php =================================================================== diff -u -N --- trunk/core/units/category_items/category_items_event_handler.php (revision 0) +++ trunk/core/units/category_items/category_items_event_handler.php (revision 1310) @@ -0,0 +1,101 @@ +Application->GetVar('cat_list'), ','); + //if(!$cat_list) return true; + + $cat_id = (int)$this->Conn->GetOne('SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE ResourceId='.$cat_list); + + $this->Application->setUnitOption($event->Prefix,'AutoLoad',false); + $object =& $event->getObject(); + + $table_info = $object->getLinkedInfo(); + + // don't allow duplicate records + $already_added = $this->Conn->GetOne('SELECT * FROM '.$object->TableName.' WHERE CategoryId='.$cat_id.' AND '.$table_info['ForeignKey'].'='.$table_info['ParentId']); + if($already_added === false) + { + $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); + $items_info[0]['CategoryId'] = $cat_id; + $items_info[0][ $table_info['ForeignKey'] ] = $table_info['ParentId']; + $this->Application->SetVar( $event->getPrefixSpecial(true), $items_info ); + + $rp_backup = $event->redirect_params; // save opener state + + $event->setEventParam('ForceCreateId', true); + $this->OnCreate($event); + + $event->redirect_params = $rp_backup; // restore opener state + } + } + + /** + * Set's new category as primary for product + * + * @param kEvent $event + */ + function OnSetPrimary(&$event) + { + $this->Application->setUnitOption($event->Prefix,'AutoLoad',false); + $object =& $event->getObject(); + $this->StoreSelectedIDs($event); + $ids=$this->getSelectedIDs($event); + if($ids) + { + $id = array_shift($ids); + $table_info = $object->getLinkedInfo(); + + $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 0 WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']); + $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$id.')'); + } + $event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay! + } + + /** + * Apply custom processing to item + * + * @param kEvent $event + */ + function customProcessing(&$event, $type) + { + if($event->Name == 'onMassDelete') + { + $object =& $event->getObject(); + $table_info = $object->getLinkedInfo(); + + switch ($type) + { + case 'before': + $ids = $event->getEventParam('ids'); + if($ids) + { + $ids = $this->Conn->GetCol('SELECT CategoryId FROM '.$object->TableName.' WHERE (PrimaryCat=0) AND ('.$table_info['ForeignKey'].'='.$table_info['ParentId'].') AND CategoryId IN ('.implode(',',$ids).')'); + $event->setEventParam('ids',$ids); + } + break; + + // not needed because 'before' does not allow to delete primary cat! + /*case 'after': + // set 1st not deleted category as primary + $has_primary = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE (PrimaryCat=1) AND ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].')'); + if(!$has_primary) + { + $cat_id = $this->Conn->GetOne('SELECT CategoryId FROM '.$object->TableName.' WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']); + $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$cat_id.')'); + } + break;*/ + } + } + } + + } + +?> \ No newline at end of file Index: trunk/core/units/general/inp_db_event_handler.php =================================================================== diff -u -N --- trunk/core/units/general/inp_db_event_handler.php (revision 0) +++ trunk/core/units/general/inp_db_event_handler.php (revision 1310) @@ -0,0 +1,145 @@ +'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) + { + $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) + { + $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; + } + + /** + * Split one timestamp field into 2 virtual fields + * + * @param kEvent $event + * @access public + */ + function loadTSField(&$event, $ts_field, $date_field, $time_field) + { + $object =& $event->getObject(); + $timestamp = $object->GetDBField($ts_field); + if( isset($timestamp) && $timestamp ) + { + $options = $object->GetFieldOptions($date_field); + $formatter =& $this->Application->recallObject($options['formatter']); + $object->SetField( $date_field, $formatter->Format($timestamp, $options, $errors) ); + + $options = $object->GetFieldOptions($time_field); + $formatter =& $this->Application->recallObject($options['formatter']); + $object->SetField( $time_field, $formatter->Format($timestamp, $options, $errors) ); + } + } + + /** + * Save date & time virtual fields back to timestamp field + * + * @param kEvent $event + * @access public + */ + function saveTSField(&$event, $ts_field, $date_field, $time_field) + { + $object =& $event->getObject(); + $date_value = $object->GetDBField($date_field); + $time_value = $object->GetDBField($time_field); + $time_zone_offset = date('Z', time() ); // !!! this is important + + $object->SetDBField($ts_field, $date_value+$time_value+$time_zone_offset); + } + + } + + +?> \ No newline at end of file Index: trunk/core/units/general/inp_unit_config_reader.php =================================================================== diff -u -N --- trunk/core/units/general/inp_unit_config_reader.php (revision 0) +++ trunk/core/units/general/inp_unit_config_reader.php (revision 1310) @@ -0,0 +1,19 @@ +processFolder(DOC_ROOT.BASE_PATH); + } + } + + +?> \ No newline at end of file Index: trunk/core/units/general/general_config.php =================================================================== diff -u -N --- trunk/core/units/general/general_config.php (revision 0) +++ trunk/core/units/general/general_config.php (revision 1310) @@ -0,0 +1,21 @@ + 'm', + 'hooks' => Array(), + 'QueryString' => Array( + 1 => 'cat_id', + 2 => 'cat_page', + 3 => 'lang', + 4 => 'theme', + 5 => 'opener', + ), + 'TitleField' => 'CachedNavbar', + 'TitlePhrase' => 'la_Text_Category', + 'ItemType' => 1, + 'TableName' => TABLE_PREFIX.'Category', + + 'PortalStyleEnv' => true, + ); + +?> \ No newline at end of file Index: trunk/core/units/category_items/category_items_dbitem.php =================================================================== diff -u -N --- trunk/core/units/category_items/category_items_dbitem.php (revision 0) +++ trunk/core/units/category_items/category_items_dbitem.php (revision 1310) @@ -0,0 +1,36 @@ +getLinkedInfo(); + return '(CategoryId='.$this->ID.' AND '.$table_info['ForeignKey'].'='.$table_info['ParentId'].')'; + } + + /** + * Generate and set new temporary id + * + * @access private + */ + function setTempID() + { + // don't set temp id for this item + } + + } + + +?> \ No newline at end of file Index: trunk/core/units/custom_fields/custom_fields_config.php =================================================================== diff -u -N --- trunk/core/units/custom_fields/custom_fields_config.php (revision 0) +++ trunk/core/units/custom_fields/custom_fields_config.php (revision 1310) @@ -0,0 +1,74 @@ + 'cf', + 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'CustomFieldsEventHandler','file'=>'custom_fields_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'), + 'AutoLoad' => true, + 'hooks' => Array(), + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + 4 => 'type', + 5 => 'mode', + ), + 'IDField' => 'CustomFieldId', + + 'TitleField' => 'FieldName', // field, used in bluebar when editing existing item + + 'TitlePhrase' => 'la_title_CustomFields', + + 'TitlePresets' => Array( + 'default' => Array( 'new_status_labels' => Array('cf'=>'!la_title_addingCustom!'), + 'edit_status_labels' => Array('cf'=>'!la_title_Editing_CustomField!'), + 'new_titlefield' => Array('cf'=>'!la_title_NewCustomField!'), + ), + + 'custom_fields_list'=>Array( 'prefixes' => Array('cf_List'), + 'format' => "!la_tab_ConfigCustom! (#cf_recordcount#)", + ), + + 'custom_fields_edit'=>Array( 'prefixes' => Array('cf'), + 'new_titlefield' => Array('cf'=>'!la_title_NewCustomField!'), + 'format' => "#cf_status# '#cf_titlefield#'", + ), + ), + + 'TableName' => TABLE_PREFIX.'CustomField', + + 'ListSQLs' => Array( ''=>"SELECT %1\$s.* FROM %s", + ), // key - special, value - list select sql + 'ItemSQLs' => Array( ''=>'SELECT * FROM %s', + ), + + 'Fields' => Array( + 'CustomFieldId' => Array('type' => 'int','not_null' => '1','default' => ''), + 'Type' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'FieldName' => Array('type' => 'string','not_null' => 1,'default' => ''), + 'FieldLabel' => Array('type' => 'string','default' => ''), + 'Heading' => Array('type' => 'string','default' => ''), + 'Prompt' => Array('type' => 'string','default' => ''), + 'ElementType' => Array('type'=>'string', 'not_null'=>1, 'default'=>'NULL', 'formatter'=>'kOptionsFormatter', 'use_phrases' => 1, 'options'=>Array('text' => 'la_type_text', 'select' => 'la_type_select', 'radio' => 'la_type_radio', 'password' => 'la_type_password', 'textarea' => 'la_type_textarea', 'label' => 'la_type_label')), + 'ValueList' => Array('type' => 'string','default' => ''), + 'DisplayOrder' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'OnGeneralTab' => Array('type' => 'int','not_null' => '1','default' => '0'), + ), + 'VirtualFields' => Array(), + + 'Grids' => Array( + 'Default' => Array( + 'Icons' => Array('default'=>'icon16_custom.gif'), + 'Fields' => Array( + 'CustomFieldId' => Array( 'title'=>'la_prompt_FieldId', 'data_block' => 'grid_checkbox_td' ), + 'FieldName' => Array( 'title'=>'la_prompt_FieldName'), + 'FieldLabel' => Array( 'title'=>'la_prompt_FieldLabel' ), + ), + + ), + ), + ); + +?> \ No newline at end of file Index: trunk/kernel/units/general/cat_dbitem.php =================================================================== diff -u -N --- trunk/kernel/units/general/cat_dbitem.php (revision 0) +++ trunk/kernel/units/general/cat_dbitem.php (revision 1310) @@ -0,0 +1,113 @@ +Validate()) return false; + + $this->SetDBField('ResourceId', $this->Application->NextResourceId()); + $this->SetDBField('Modified', mktime()); + + $ret = parent::Create(); + if($ret) + { + if ( kTempTablesHandler::IsTempTable($this->TableName) ) { + $table = kTempTablesHandler::GetTempName(TABLE_PREFIX.'CategoryItems'); + } + else { + $table = TABLE_PREFIX.'CategoryItems'; + } + $cat_id = $this->Application->GetVar('m_cat_id'); + $query = 'INSERT INTO '.$table.' (CategoryId,ItemResourceId,PrimaryCat) + VALUES ('.$cat_id.','.$this->GetField('ResourceId').',1)'; + $this->Conn->Query($query); + } + return $ret; + } + + function Update($id=null) + { + $this->VirtualFields['ResourceId'] = true; + $this->SetDBField('Modified', mktime()); + return parent::Update($id); + } + + function Copy($cat_id=null) + { + if (!isset($cat_id)) $cat_id = $this->Application->GetVar('m_cat_id'); + $this->NameCopy($cat_id); + return $this->Create($cat_id); + } + + function NameCopy($master=null, $foreign_key=null) + { + $title_field = $this->Application->getUnitOption($this->Prefix, 'TitleField'); + if (!$title_field) return; + + $new_name = $this->GetDBField('Name'); + $cat_id = $this->Application->GetVar('m_cat_id'); + $original_checked = false; + do { + if ( preg_match("/Copy ([0-9]*)[ ]*of(.*)/", $new_name, $regs) ) { + $new_name = 'Copy '.($regs[1]+1).' of '.$regs[2]; + } + elseif ($original_checked) { + $new_name = 'Copy of '.$new_name; + } + $query = 'SELECT '.$title_field.' FROM '.$this->TableName.' + LEFT JOIN '.TABLE_PREFIX.'CategoryItems ON + ('.TABLE_PREFIX.'CategoryItems.ItemResourceId = '.$this->TableName.'.ResourceId) + WHERE ('.TABLE_PREFIX.'CategoryItems.CategoryId = '.$cat_id.') AND '. + $title_field.' = '.$this->Conn->qstr($new_name); + $res = $this->Conn->GetOne($query); + $original_checked = true; + } while ($res !== false); + $this->SetDBField($title_field, $new_name); + } + + function MoveToCat($cat_id=null) + { +// $this->NameCopy(); + $cat_id = $this->Application->GetVar('m_cat_id'); + // check if the product already exists in destination cat + $query = 'SELECT PrimaryCat FROM '.TABLE_PREFIX.'CategoryItems + WHERE CategoryId = '.$cat_id.' AND ItemResourceId = '.$this->GetDBField('ResourceId'); + // if it's not found is_primary will be FALSE, if it's found but not primary it will be int 0 + $is_primary = $this->Conn->GetOne($query); + $exists = $is_primary !== false; + + if ($exists) { // if the Product already exists in destination category + if ($is_primary) return; // do nothing when we paste to primary + // if it's not primary - delete it from destination category, + // as we will move it from current primary below + $query = 'DELETE FROM '.TABLE_PREFIX.'CategoryItems + WHERE ItemResourceId = '.$this->GetDBField('ResourceId').' AND CategoryId = '.$cat_id; + $this->Conn->Query($query); + + } + $query = 'UPDATE '.TABLE_PREFIX.'CategoryItems SET CategoryId = '.$cat_id. + ' WHERE ItemResourceId = '.$this->GetDBField('ResourceId').' AND PrimaryCat = 1'; + $this->Conn->Query($query); + $this->Update(); + } + + // We need to delete CategoryItems record when deleting product + function Delete($id=null) + { + if( isset($id) ) { + $this->setID($id); + } + $this->Load($this->GetID()); + + $ret = parent::Delete(); + if ($ret) { + $query = 'DELETE FROM '.TABLE_PREFIX.'CategoryItems WHERE ItemResourceId = '.$this->GetDBField('ResourceId'); + $this->Conn->Query($query); + } + + return $ret; + } +} + +?> \ No newline at end of file Index: trunk/core/units/general/my_application.php =================================================================== diff -u -N --- trunk/core/units/general/my_application.php (revision 0) +++ trunk/core/units/general/my_application.php (revision 1310) @@ -0,0 +1,289 @@ + + * + * @return string + */ + function FindTag() + { + $tagOpen = strpos($this->Template, '<%', $this->Position); //Finding tag start + + $inp_tag = false; + $tagOpenLen = 2; + $inpOpen = strpos($this->Template, 'Position); + if ($inpOpen !== false && ($tagOpen === false || $inpOpen < $tagOpen)) { + $tagOpen = $inpOpen; + $inp_tag = true; + $tagOpenLen = 6; + } + + if ($tagOpen === false) { //If not tags left - adding all other data + $this->AppendOutput(substr($this->Template, $this->Position)); + return false; + } + + //Adding all data before tag open + $this->AppendOutput(substr($this->Template, $this->Position, $tagOpen - $this->Position)); + + //Finding tag end + $tagCloseLen = 2; + if ($inp_tag) { + $tagClose = strpos($this->Template, "/>", $tagOpen); + $inpClose = strpos($this->Template, "", $tagOpen); + if ($inpClose !== false && $inpClose < $tagClose) { + $tagClose = $inpClose; + $tagCloseLen = 7; + } + } + else { + $tagClose = strpos($this->Template, "%>", $tagOpen); + } + + if ($tagClose === false) die ("Can't find tag closing"); + + //Cutting out the tag itself + $tag = substr($this->Template, $tagOpen + $tagOpenLen, $tagClose - $tagOpen - $tagOpenLen); + + if ($inp_tag) { + if (strpos($tag, '_') !== false) { + list($prefix, $the_tag) = explode('_', $tag, 2); + $tag = $prefix.':'.$the_tag; + } + else $tag .= ':'; + } + + //Seting current position right after the tag + $this->Position = $tagClose + $tagCloseLen; + return $tag; + } + + function Parse($template, $name='unknown') + { + $this->Template = $template; + $this->TemplateName = $name; + $this->Position = 0; + $this->Output = ''; + + //While we have more tags + while ($tag_data = $this->FindTag()) + { + //Create tag object from passed tag data + if (defined('DEBUG_TAGS')&&DEBUG_TAGS) { + global $debugger; + $debugger->appendHTML("mode: ".$this->SkipModeName()." tag ".$debugger->highlightString($tag_data)." in ".$debugger->getFileLink($debugger->getLocalFile(DOC_ROOT.BASE_PATH.THEMES_PATH.'/'.$this->TemplateName).'.tpl', $this->CurrentLineNumber(), '', true)); + } + $tag =& new MyTag($tag_data, $this); + if (!$this->CheckRecursion($tag)) //we do NOT process closing tags + { + $tag->Process(); + } + } + + if ( !$this->GetParam('from_inportal') ) { + if ( strpos($this->Output, 'Application->recallObject('Inp1Parser'); + $this->Output = $inp1_parser->Parse($name, $this->Output); + } + } + return $this->Output; + } + + function ParseBlock($params, $force_pass_params=0, $as_template=false) + { + if (defined('EXPERIMENTAL_PRE_PARSE')) { + if (isset($this->Application->PreParsedBlocks[$params['name']]) ) { + $f = $this->Application->PreParsedBlocks[$params['name']]; + //$this->SetParams($params); + return $f($params); + } + } + + $BlockParser =& $this->Application->Factory->makeClass('TemplateParser'); + if (isset($params['pass_params']) || $force_pass_params) { + $BlockParser->SetParams(array_merge($this->Params, $params)); + } + else + $BlockParser->SetParams($params); + $this->Application->Parser =& $BlockParser; + if (!isset($params['name'])) die("***Error: Block name not passed to ParseBlock
"); + $templates_cache =& $this->Application->recallObject('TemplatesCache'); + + $template_name = $as_template ? $params['name'] : $templates_cache->GetTemplateFileName($params['name']) . '-block:'.$params['name']; + + $silent = getArrayValue($params, 'from_inportal') && !defined('DBG_TEMPLATE_FAILURE'); + + $o = $BlockParser->Parse( + $templates_cache->GetTemplateBody($params['name'], $silent), + $template_name + ); + $this->Application->Parser =& $this; + return $o; + } + } + + class MyTag extends Tag { + + /** + * Set's Prefix and Special for Tag object + * based on ones from tagname + * + * @param string $tag_data + * @access protected + */ + function ParseTagData($tag_data) + { + $tag_data = $this->ReplaceParams($tag_data) . ' '; + $tag_data = $this->Application->ReplaceLanguageTags($tag_data); + + + list ($key_data, $params) = explode(' ', $tag_data, 2); + + //cand.test_TagProcessor:PrintList + + $tmp=explode(':',$key_data); + $this->Tag=$tmp[1]; + + $tmp=$this->Application->processPrefix($tmp[0]); + $this->Prefix=$tmp['prefix']; + $this->Special=$tmp['special']; + $this->Processor=$this->Prefix; + + if ($params != '') $this->ParseNamedParams($params); + } + + /** + * Set's Prefix and Special for TagProcessor + * based on tag beeing processed + * + * @return string + * @access protected + */ + function DoProcessTag() + { + // $tag->Prefix - l_TagProcessor + $tmp = $this->Application->processPrefix($this->Processor); + + $processor =& $this->Application->recallObject($tmp['prefix'].'_TagProcessor'); // $this->Processor + + $tmp=explode('_',$tmp['prefix'],2); + $processor->Prefix=$tmp[0]; + $processor->Special=$this->Special; + + return $processor->ProcessTag($this); + } + + /** + * Process IF tags in specific way + * + */ + function Process() + { + if ($this->Processor == 'm' || $this->Processor == 'm_TagProcessor') { //if we are procssing Main tags + if ($this->Tag == 'block') { + $tag =& new BlockTag('', $this->Parser); + $tag->CopyFrom($this); + $tag->Process(); + } + elseif ($this->Parser->SkipMode == skip_tags) { + return; + } + elseif ( + $this->Tag == 'if' || + $this->Tag == 'ifnot' || + $this->Tag == 'else' || + $this->Tag == 'elseif' + ) { + $tag =& new MyConstructTag('', $this->Parser); + $tag->CopyFrom($this); + $tag->Process(); + } + elseif ($this->Tag == 'xml') { + $tag =& new XMLTag('', $this->Parser); + $tag->CopyFrom($this); + $tag->Process(); + } + else { + if ($this->Parser->SkipMode == skip) return; + //if (!$this->ProcessMainTag()) //other main tags + $this->ProcessTag(); + } + } + else { //normal tags - processors other than main + if ($this->Parser->SkipMode == skip_tags || $this->Parser->SkipMode == skip) return; //do not parse if we skipping tags + $this->ProcessTag(); + //$this->Parser->AppendOutput(''.$this->Tag.''); + } + } + + + + } + + class MyConstructTag extends ConstructTag { + + function GetLogic() + { + $prefix = $this->GetParam('prefix'); + $function = $this->GetParam('function'); + + if ($prefix !== false) { + $tag =& new MyTag('', $this->Parser); + $tag->Tag = $function; + + $tmp = $this->Application->processPrefix($prefix); + $tag->Processor = $tmp['prefix']; + + $tag->Prefix=$tmp['prefix']; + $tag->Special=$tmp['special']; + $tag->NamedParams = $this->NP; + $this->Logic = $tag->DoProcessTag(); + // echo " this->Logic : ".$this->Logic."
"; + } + else + { + $this->Logic = $function; + } + } + + } + + class MyApplication extends kApplication { + + function RegisterDefaultClasses() + { + parent::RegisterDefaultClasses(); + $this->registerClass('InpTemplateParser',MODULES_PATH.'/in-commerce/general/my_application.php','TemplateParser'); + + $this->registerClass('Inp1Parser',MODULES_PATH.'/in-commerce/general/inp1_parser.php','Inp1Parser'); + + $this->registerClass('InpSessionStorage',MODULES_PATH.'/in-commerce/general/inp_ses_storage.php','SessionStorage'); + $this->registerClass('kCatDBItem',MODULES_PATH.'/in-commerce/general/cat_dbitem.php'); + $this->registerClass('kCatDBList',MODULES_PATH.'/in-commerce/general/cat_dblist.php'); + $this->registerClass('kCatDBEventHandler',MODULES_PATH.'/in-commerce/general/cat_event_handler.php'); + $this->registerClass('InpLoginEventHandler',MODULES_PATH.'/in-commerce/general/inp_login_event_handler.php','login_EventHandler'); + $this->registerClass('InpDBEventHandler',MODULES_PATH.'/in-commerce/general/inp_db_event_handler.php','kDBEventHandler'); + $this->registerClass('InpTempTablesHandler',MODULES_PATH.'/in-commerce/general/inp_temp_handler.php','kTempTablesHandler'); + $this->registerClass('InpUnitConfigReader',MODULES_PATH.'/in-commerce/general/inp_unit_config_reader.php','kUnitConfigReader'); + + $this->registerClass('InpCustomFieldsHelper',MODULES_PATH.'/in-commerce/general/custom_fields.php','InpCustomFieldsHelper'); + } + + function KernelDie($message) + { + $this->trigerError($message,E_USER_ERROR); + exit; + } + + function ConfigValue($name) + { + return $this->DB->GetOne('SELECT VariableValue FROM '.TABLE_PREFIX.'ConfigurationValues WHERE VariableName = '.$this->DB->qstr($name) ); + } + } + +?> \ No newline at end of file Index: trunk/kernel/units/categories/categories_tag_processor.php =================================================================== diff -u -N --- trunk/kernel/units/categories/categories_tag_processor.php (revision 0) +++ trunk/kernel/units/categories/categories_tag_processor.php (revision 1310) @@ -0,0 +1,73 @@ +Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List',$params); + $id_field = $this->Application->getUnitOption($this->Prefix,'IDField'); + + $cat_id = $this->Application->GetVar('m_cat_id') ? $this->Application->GetVar('m_cat_id') : 0; + $list->SetWhereClause( 'ParentId='.$this->Application->GetVar('m_cat_id') ); + $list->Query(); + $o = ''; + $list->GoFirst(); + + $block_params=$this->prepareTagParams($params); + $block_params['name']=$params['block']; + $block_params['pass_params']='true'; + + while (!$list->EOL()) + { + $block_params['cat_id'] = $list->GetDBField('CategoryId'); + + $this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); // for edit/delete links using GET + $o.= $this->Application->ParseBlock($block_params, 1); + $list->GoNext(); + } + + $this->Application->SetVar( $this->getPrefixSpecial().'_id', ''); + return $o; + } + + function RootCategoryName($params) + { + $root_phrase = $this->Application->ConfigValue('Root_Name'); + $ret = $this->Application->Phrase($root_phrase); + return $ret; + } + + function CategoryPath($params) + { + if(!isset($params['cat_id'])) + { + $params['cat_id'] = $this->Application->GetVar('m_cat_id'); + $block_params['current'] = 1; + } + $block_params['separator'] = $params['separator']; + if($params['cat_id'] == 0) + { + $block_params['name'] = $params['rootcatblock']; + return $this->Application->ParseBlock($block_params); + } + else + { + $cat_object = $this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List' ); + $sql = 'SELECT CategoryId, ParentId, Name FROM '.$cat_object->TableName.' WHERE CategoryId='.$params['cat_id']; + $res = $this->Conn->GetRow($sql); + $block_params['name'] = $params['block']; + $block_params['cat_name'] = $res['Name']; + $block_params['separator'] = $params['separator']; + $block_params['cat_id'] = $res['CategoryId']; + $next_params['separator'] = $params['separator']; + $next_params['rootcatblock'] = $params['rootcatblock']; + $next_params['block'] = $params['block']; + $next_params['cat_id'] = $res['ParentId']; + return $this->CategoryPath($next_params).$this->Application->ParseBlock($block_params); + } + } + +} + + +?> \ No newline at end of file Index: trunk/kernel/units/configuration/configuration_config.php =================================================================== diff -u -N --- trunk/kernel/units/configuration/configuration_config.php (revision 0) +++ trunk/kernel/units/configuration/configuration_config.php (revision 1310) @@ -0,0 +1,52 @@ + 'conf', + 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'ConfigurationEventHandler','file'=>'configuration_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'ConfigurationTagProcessor','file'=>'configuration_tag_processor.php','build_event'=>'OnBuild'), + 'AutoLoad' => true, + 'hooks' => Array(), + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + 4 => 'module', + 5 => 'section', + ), + 'IDField' => 'VariableName', + + 'TitlePresets' => Array( + 'config_list' => Array('prefixes' => Array('conf_List'), 'format' => "!la_updating_config!"), + ), + + 'TableName' => TABLE_PREFIX.'ConfigurationValues', + 'ListSQLs' => Array(''=>'SELECT * FROM '.TABLE_PREFIX.'ConfigurationAdmin LEFT JOIN '.TABLE_PREFIX.'ConfigurationValues Using(VariableName) '), + + + 'ItemSQLs' => Array(''=>'SELECT * FROM '.TABLE_PREFIX.'ConfigurationAdmin LEFT JOIN '.TABLE_PREFIX.'ConfigurationValues Using(VariableName) '), + + 'SubTables' => Array(), + + 'Fields' => Array( + 'VariableName' => Array('type' => 'string','not_null' => '1','default' => ''), + 'VariableValue' => array('type'=>'string', 'default'=>''), + 'ModuleOwner' => array('type'=>'string', 'default'=>'In-Portal'), + 'Section' => array('type'=>'string','not_null' => '1','default'=>''), + ), + + 'VirtualFields' => Array( + 'heading' => Array('type' => 'string','default' => ''), + 'prompt' => Array('type' => 'string','default' => ''), + 'element_type' => Array('type' => 'string','not_null' => '1','default' => ''), + 'validation' => Array('type' => 'string','default' => ''), + 'ValueList' => Array('type' => 'string','default' => ''), + 'DisplayOrder' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'Install' => Array('type' => 'int','not_null' => '1','default' => '1'), + ), + + 'Grids' => Array(), + ); + +?> \ No newline at end of file Index: trunk/core/units/category_items/category_items_tag_processor.php =================================================================== diff -u -N --- trunk/core/units/category_items/category_items_tag_processor.php (revision 0) +++ trunk/core/units/category_items/category_items_tag_processor.php (revision 1310) @@ -0,0 +1,26 @@ +Application->ConfigValue('Root_Name'); + $value = $this->Field($params); + $ret = $this->Application->Phrase($root_phrase).( $value ? ' > ' : '').$value; + if( $this->Field( Array('field'=> 'PrimaryCat') ) == 1 ) + { + $ret .= ' ('.$params['primary_title'].')'; + } + return $ret; + } + + function GetMainID() + { + $object =& $this->Application->recallObject( $this->getPrefixSpecial() ); + $table_info = $object->getLinkedInfo(); + return $table_info['ParentId']; + } + } + + +?> \ No newline at end of file Index: trunk/kernel/units/general/custom_fields.php =================================================================== diff -u -N --- trunk/kernel/units/general/custom_fields.php (revision 0) +++ trunk/kernel/units/general/custom_fields.php (revision 1310) @@ -0,0 +1,69 @@ +ParseConfigSQL($values_list); + $optionValuesTmp=explode(',', $optionValuesStr); + $optionValues=array(); + foreach ($optionValuesTmp as $optionValue){ + list($key, $val) = explode("=", $optionValue); + + if (substr($val,0,1)=="+") + $val = substr($val, 1); + else + $val = $this->Application->Phrase($val); + + $optionValues[$key]=$val; + } + return $optionValues; + } + + function ParseConfigSQL($valueString){ + $string = trim(str_replace("",TABLE_PREFIX,$valueString)); + + $start = strpos($string,""); + + while($start){ + $end = strpos($string,""); + if(!$end){ + $end = strlen($string); + } + $len = $end - $start; + $sql = substr($string,$start+5,$len-5); + + $sql_val = $this->QueryConfigSQL($sql); + + /*if ($start>0 && $sql_val!='') + $sql_val=",".$sql_val;*/ + if ($end < strlen($string)-6 && $sql_val!='') + $sql_val.=","; + + $chunk1=substr($string,0,$start); + $chunk2=substr($string,$end+6); + $s = $chunk1.$sql_val.$chunk2; + + + $string = $s; + $start = strpos($string,""); + } + return $string; + } + + function QueryConfigSQL($sql){ + $db =& $this->Application->GetADODBConnection(); + + $valArray=$db->Query($sql); + for ($i=0; $i \ No newline at end of file Index: trunk/kernel/units/general/inp_ses_storage.php =================================================================== diff -u -N --- trunk/kernel/units/general/inp_ses_storage.php (revision 0) +++ trunk/kernel/units/general/inp_ses_storage.php (revision 1310) @@ -0,0 +1,61 @@ +setTableName(TABLE_PREFIX.'UserSession'); + $this->SessionDataTable = TABLE_PREFIX.'SessionData'; + $this->setIDField('SessionKey'); + $this->TimestampField = 'LastAccessed'; + $this->DataValueField = 'VariableValue'; + $this->DataVarField = 'VariableName'; + } + + function LocateSession($sid) + { + $query = ' SELECT '.$this->TimestampField.' FROM '.$this->TableName.' WHERE '.$this->IDField.' = '.$this->Conn->qstr($sid); + $result = $this->Conn->GetOne($query); + + if($result===false) return false; + + $this->Expiration = $result + $this->SessionTimeout; + return true; + } + + function UpdateSession(&$session) + { + $query = ' UPDATE '.$this->TableName.' SET '.$this->TimestampField.' = unix_timestamp() WHERE '.$this->IDField.' = '.$this->Conn->qstr($session->SID); + $this->Conn->Query($query); + } + + function GetExpiredSIDs() + { + $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.time().' - '.$this->TimestampField.' > '.$this->SessionTimeout; + $ret = $this->Conn->GetCol($query); + if($ret) $this->DeleteEditTables(); + return $ret; + + } + + function DeleteEditTables() + { + $tables = $this->Conn->GetCol('SHOW TABLES'); + $mask = '/'.TABLE_PREFIX.'ses_(.*)_edit_(.*)/'; + $sql='SELECT COUNT(*) FROM '.$this->TableName.' WHERE '.$this->IDField.' = \'%s\''; + foreach($tables as $table) + { + if( preg_match($mask,$table,$rets) ) + { + $sid=$rets[1]; + $is_alive = $this->Conn->GetOne( sprintf($sql,$sid) ); + if(!$is_alive) $this->Conn->Query('DROP TABLE IF EXISTS '.$table); + } + } + } +} + +?> \ No newline at end of file