Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1101716
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Aug 17, 2:38 AM
Size
39 KB
Mime Type
text/x-diff
Expires
Tue, Aug 19, 2:38 AM (8 h, 37 m)
Engine
blob
Format
Raw Data
Handle
713584
Attached To
rINP In-Portal
in-portal
View Options
Index: branches/unlabeled/unlabeled-1.31.2/kernel/admin_templates/incs/catalog.js
===================================================================
--- branches/unlabeled/unlabeled-1.31.2/kernel/admin_templates/incs/catalog.js (nonexistent)
+++ branches/unlabeled/unlabeled-1.31.2/kernel/admin_templates/incs/catalog.js (revision 7858)
@@ -0,0 +1,329 @@
+function Catalog($url_mask, $cookie_prefix, $tab_shift) {
+ this.CookiePrefix = $cookie_prefix ? $cookie_prefix : '';
+ this.BusyRequest = new Array();
+ this.URLMask = $url_mask;
+ this.Separator = '#separator#';
+ this.ParentCategoryID = 0;
+ this.OnResponceMethod = null;
+ this.TabShift = isset($tab_shift) ? $tab_shift : 1; // start from 2nd tab (index starting from 0)
+
+ this.TabRegistry = new Array();
+ this.ActivePrefix = getCookie(this.CookiePrefix + 'active_prefix');
+ this.PreviousPrefix = this.ActivePrefix;
+ $ViewMenus = new Array('c');
+}
+
+Catalog.prototype.Init = function () {
+ var $prefix = this.queryTabRegistry('prefix', this.ActivePrefix, 'prefix');
+ if ($prefix !== this.ActivePrefix && this.TabRegistry.length > this.TabShift) {
+ // ActivePrefix not set or has non-existing prefix value
+ this.ActivePrefix = this.TabRegistry[this.TabShift]['prefix'];
+ }
+ this.SetAlternativeTabs();
+ this.AfterInit();
+}
+
+Catalog.prototype.AfterInit = function () {
+ this.go_to_cat();
+}
+
+Catalog.prototype.SetAlternativeTabs = function () {
+ // set alternative grids between all items (catalog is set when tab is loaded via AJAX first time)
+ var $i = this.TabShift;
+ while ($i < this.TabRegistry.length) {
+ // run through all prefixes
+ var $j = this.TabShift;
+ while ($j < this.TabRegistry.length) {
+ if (this.TabRegistry[$i]['prefix'] == this.TabRegistry[$j]['prefix']) {
+ $j++;
+ continue;
+ }
+ // and set alternative to all other prefixes
+ $GridManager.AddAlternativeGrid(this.TabRegistry[$i]['prefix'], this.TabRegistry[$j]['prefix']);
+ $j++;
+ }
+ $i++;
+ }
+}
+
+Catalog.prototype.submit_kernel_form = function($tab_id) {
+ var $prefix = 'dummy';
+ var $result_div = '';
+
+ if (isset($tab_id)) {
+ // responce result + progress are required
+ $prefix = this.queryTabRegistry('tab_id', $tab_id, 'prefix');
+ $result_div = $tab_id + '_div';
+ }
+
+ var $kf = document.getElementById($form_name);
+
+ Request.params = Request.serializeForm($kf);
+ Request.method = $kf.method.toUpperCase();
+
+ this.BusyRequest[$prefix] = false;
+ Request.makeRequest($kf.action, this.BusyRequest[$prefix], $result_div, this.successCallback, this.errorCallback, $result_div, this);
+
+ $form_name = 'kernel_form'; // restore back to main form with current category id of catalog
+};
+
+Catalog.prototype.successCallback = function($request, $params, $object) {
+
+ var $text = $request.responseText;
+
+ var $match_redirect = new RegExp('^#redirect#(.*)').exec($text);
+ if ($match_redirect != null) {
+ // redirect to external template requested
+ window.location.href = $match_redirect[1];
+ return false;
+ }
+
+ $params = $params.split(',');
+
+
+ var $js_end = $text.indexOf($object.Separator);
+ if ($js_end != -1) {
+
+ // allow to detect if output is permitted by ajax request parameters
+ var $request_visible = '$request_visible = ' + ($params[0].length ? 'true' : 'false') + "\n";
+
+ if ($params[0].length) {
+ document.getElementById($params[0]).innerHTML = $text.substring($js_end + $object.Separator.length);
+ eval($request_visible + $text.substring(0, $js_end));
+ }
+ else {
+ // eval JS only & set mark that js should not use HTML as usual in grids
+ eval($request_visible + $text.substring(0, $js_end));
+ }
+ }
+
+ else if ($params[0].length) {
+ document.getElementById($params[0]).innerHTML = $text;
+ }
+
+ if (typeof($object.OnResponceMethod) == 'function') {
+ $object.OnResponceMethod($object);
+ $object.OnResponceMethod = null;
+ }
+
+ if (typeof($Debugger) != 'undefined') {
+ $Debugger.Clear();
+ }
+}
+
+Catalog.prototype.errorCallback = function($request, $params, $object) {
+// $Debugger.ShowProps($request, 'req');
+ alert('AJAX Error; class: Catalog; ' + Request.getErrorHtml($request));
+}
+
+Catalog.prototype.submit_event = function($prefix_special, $event, $t, $OnResponceMethod) {
+ if (typeof($OnResponceMethod) == 'function') {
+ this.OnResponceMethod = $OnResponceMethod;
+ }
+
+ var $prev_template = get_hidden_field('t');
+ if (!isset($prefix_special)) $prefix_special = this.getCurrentPrefix();
+ var $tab_id = this.queryTabRegistry('prefix', $prefix_special, 'tab_id');
+
+ $form_name = $tab_id + '_form'; // set firstly, because set_hidden_field uses it
+ if (isset($event)) set_hidden_field('events[' + $prefix_special + ']', $event);
+ if (isset($t)) set_hidden_field('t', $t);
+
+ this.submit_kernel_form($tab_id);
+ set_hidden_field('t', $prev_template);
+}
+
+
+Catalog.prototype.go_to_cat = function($cat_id) {
+ if (!isset($cat_id)) {
+ // gets current category
+ $cat_id = get_hidden_field('m_cat_id');
+ }
+ else {
+ // sets new category to kernel_form in case if item tab
+ // loads faster and will check if it's category is same
+ // as parent category of categories list
+
+ if (get_hidden_field('m_cat_id') == $cat_id) {
+ // it's the same category, then don't reload category list
+ return ;
+ }
+ set_hidden_field('m_cat_id', $cat_id);
+ }
+
+ this.resetTabs(false);
+
+ // query sub categories of $cat_id
+ var $url = this.URLMask.replace('#TEMPLATE_NAME#', 'in-portal/xml/categories_list').replace('#CATEGORY_ID#', $cat_id);
+
+ var $prefix = this.TabRegistry[0]['prefix'];
+ var $tab_id = this.TabRegistry[0]['tab_id'];
+ this.BusyRequest[$prefix] = false;
+ Request.makeRequest($url, this.BusyRequest[$prefix], $tab_id + '_div', this.successCallback, this.errorCallback, $tab_id + '_div', this);
+ this.switchTab(); // refresh current item tab
+}
+
+// set all item tabs counters to "?" before quering catagories
+Catalog.prototype.resetTabs = function($reset_content) {
+ var $i = this.TabShift;
+ while ($i < this.TabRegistry.length) {
+ this.setItemCount(this.TabRegistry[$i]['prefix'], '?');
+ $i++;
+ }
+
+ if ($reset_content) {
+ // set category for all tabs to -1 (forces reload next time)
+ $i = this.TabShift;
+ while ($i < this.TabRegistry.length) {
+ document.getElementById(this.TabRegistry[$i]['tab_id'] + '_div').setAttribute('category_id', -1);
+ $i++;
+ }
+ }
+}
+
+Catalog.prototype.switchTab = function($prefix, $force) {
+ if (this.queryTabRegistry('prefix', this.ActivePrefix, 'prefix') != this.ActivePrefix) {
+ // active prefix is not registred -> cookie left, but not modules installed/enabled at the moment
+ return false;
+ }
+
+ if (!isset($prefix)) $prefix = this.ActivePrefix;
+
+ if (this.BusyRequest[$prefix]) {
+ alert('prefix: ['+$prefix+']; request busy: ['+this.BusyRequest[$prefix]+']');
+ }
+
+ if (this.ActivePrefix != $prefix) {
+ // hide source tab
+ this.PreviousPrefix = this.ActivePrefix;
+ document.getElementById(this.PreviousPrefix + '_tab').className = 'catalog-tab-unselected';
+ document.getElementById(this.queryTabRegistry('prefix', this.PreviousPrefix, 'tab_id') + '_div').style.display = 'none';
+ this.HideDependentButtons(this.PreviousPrefix);
+ }
+
+ // show destination tab
+ this.ActivePrefix = $prefix;
+ document.getElementById(this.ActivePrefix + '_tab').className = 'catalog-tab-selected';
+ var $div_id = this.queryTabRegistry('prefix', this.ActivePrefix, 'tab_id') + '_div'; // destination tab
+ document.getElementById($div_id).style.display = 'block';
+ this.ShowDependentButtons(this.ActivePrefix);
+ this.setViewMenu(this.ActivePrefix);
+ setCookie(this.CookiePrefix + 'active_prefix', this.ActivePrefix);
+
+ this.refreshTab($prefix, $div_id, $force);
+}
+
+Catalog.prototype.refreshTab = function($prefix, $div_id, $force) {
+ var $cat_id = get_hidden_field('m_cat_id');
+ var $tab_cat_id = document.getElementById($div_id).getAttribute('category_id');
+ if ($cat_id != $tab_cat_id || $force) {
+ // query tab content only in case if not queried or category don't match
+ var $url = this.URLMask.replace('#TEMPLATE_NAME#', this.queryTabRegistry('prefix', $prefix, 'module_path') + '/catalog_tab');
+ $url = $url.replace('#CATEGORY_ID#', $cat_id);
+ $url = $url.replace('#PREFIX#', $prefix);
+
+ this.BusyRequest[$prefix] = false;
+ Request.makeRequest($url, this.BusyRequest[$prefix], $div_id, this.successCallback, this.errorCallback, $div_id, this);
+ }
+ /*else {
+ alert('refresh disabled = {tab: '+this.ActivePrefix+'; cat_id: '+$cat_id+'; form_name: '+$form_name+'}');
+ }*/
+}
+
+// adds information about tab to tab_registry
+Catalog.prototype.registerTab = function($tab_id) {
+ var $tab = document.getElementById($tab_id + '_div');
+ var $index = this.TabRegistry.length;
+ this.TabRegistry[$index] = new Array();
+ this.TabRegistry[$index]['tab_id'] = $tab_id;
+ this.TabRegistry[$index]['prefix'] = $tab.getAttribute('prefix');
+ if ($tab_id == 'categories') {
+ this.TabRegistry[$index]['module_path'] = 'in-portal/';
+ }
+ else {
+ this.TabRegistry[$index]['module_path'] = $tab.getAttribute('edit_template').substring(0, $tab.getAttribute('edit_template').indexOf('/'));
+ }
+ this.TabRegistry[$index]['view_template'] = $tab.getAttribute('view_template');
+ this.TabRegistry[$index]['edit_template'] = $tab.getAttribute('edit_template');
+ this.TabRegistry[$index]['dep_buttons'] = $tab.getAttribute('dep_buttons').length > 0 ? $tab.getAttribute('dep_buttons').split(',') : new Array();
+ this.TabRegistry[$index]['index'] = $index;
+}
+
+// allows to get any information about tab
+Catalog.prototype.queryTabRegistry = function($search_key, $search_value, $return_key) {
+ var $i = 0;
+// alert('looking in '+$search_key+' for '+$search_value+' will return '+$return_key)
+ while ($i < this.TabRegistry.length) {
+ if (this.TabRegistry[$i][$search_key] == $search_value) {
+// alert('got '+this.TabRegistry[$i][$return_key])
+ return this.TabRegistry[$i][$return_key];
+ break;
+ }
+ $i++;
+ }
+ return false;
+}
+
+Catalog.prototype.ShowDependentButtons = function($prefix) {
+ /*var $tab_id = this.queryTabRegistry('prefix', $prefix, 'tab_id')
+ if (!document.getElementById($tab_id + '_form')) {
+ // tab form not found => no permission to view -> no permission to do any actions
+ alert('no form: ['+$tab_id + '_form'+']');
+ return ;
+ }
+ else {
+ alert('has form: ['+$tab_id + '_form'+']');
+ }*/
+
+ var $dep_buttons = this.queryTabRegistry('prefix', $prefix, 'dep_buttons');
+ var $i = 0;
+ while ($i < $dep_buttons.length) {
+ a_toolbar.ShowButton($dep_buttons[$i]);
+ $i++;
+ }
+}
+
+Catalog.prototype.HideDependentButtons = function($prefix) {
+ var $dep_buttons = this.queryTabRegistry('prefix', $prefix, 'dep_buttons');
+ var $i = 0;
+ while ($i < $dep_buttons.length) {
+ a_toolbar.HideButton($dep_buttons[$i]);
+ $i++;
+ }
+}
+
+Catalog.prototype.setItemCount = function($prefix, $count) {
+ setInnerHTML($prefix + '_item_count', $count);
+}
+
+Catalog.prototype.setCurrentCategory = function($prefix, $category_id) {
+ var $tab_id = this.queryTabRegistry('prefix', $prefix, 'tab_id');
+// alert('setting current category for prefix: ['+$prefix+']; tab_id ['+$tab_id+'] = ['+$category_id+']');
+ document.getElementById($tab_id + '_div').setAttribute('category_id', $category_id);
+}
+
+
+Catalog.prototype.getCurrentPrefix = function() {
+ if (isset(Grids[this.ActivePrefix]) && (Grids[this.ActivePrefix].SelectedCount > 0)) {
+ // item tab grid exists and some items are selected
+ return this.ActivePrefix;
+ }
+ else {
+ // return prefix of first registred tab -> categories
+ return this.TabRegistry[0]['prefix'];
+ }
+}
+
+Catalog.prototype.setViewMenu = function($item_prefix) {
+ if (this.TabShift == 1) {
+ $ViewMenus = isset($item_prefix) ? new Array('c', $item_prefix) : new Array('c');
+ }
+ else {
+ $ViewMenus = isset($item_prefix) ? new Array($item_prefix) : new Array();
+ }
+}
+
+Catalog.prototype.reflectPasteButton = function($status) {
+ a_toolbar.SetEnabled('paste', $status);
+ a_toolbar.SetEnabled('clear_clipboard', $status);
+}
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.31.2/kernel/admin_templates/incs/catalog.js
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.31
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.31.2/core/units/languages/languages_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.31.2/core/units/languages/languages_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.31.2/core/units/languages/languages_event_handler.php (revision 7858)
@@ -0,0 +1,461 @@
+<?php
+
+ class LanguagesEventHandler extends kDBEventHandler
+ {
+ /**
+ * Allows to override standart permission mapping
+ *
+ */
+ function mapPermissions()
+ {
+ parent::mapPermissions();
+ $permissions = Array(
+ 'OnChangeLanguage' => Array('self' => true),
+ 'OnSetPrimary' => Array('self' => 'advanced:set_primary|add|edit'),
+ 'OnImportLanguage' => Array('self' => 'advanced:import'),
+ 'OnImportProgress' => Array('self' => 'advanced:import'),
+ 'OnExportLanguage' => Array('self' => 'advanced:export'),
+ 'OnExportProgress' => Array('self' => 'advanced:export'),
+
+ );
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
+ /**
+ * Updates table structure on new language adding/removing language
+ *
+ * @param kEvent $event
+ */
+ function OnReflectMultiLingualFields($event)
+ {
+ $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper');
+
+ $this->Application->UnitConfigReader->includeConfigFiles(MODULES_PATH); //make sure to re-read all configs
+ $this->Application->UnitConfigReader->AfterConfigRead();
+ foreach ($this->Application->UnitConfigReader->configData as $prefix => $config_data) {
+ $ml_helper->createFields($prefix);
+ }
+ }
+
+ /**
+ * Allows to set selected language as primary
+ *
+ * @param kEvent $event
+ */
+ function OnSetPrimary(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
+ return;
+ }
+
+ $this->StoreSelectedIDs($event);
+ $ids = $this->getSelectedIDs($event);
+ if ($ids) {
+ $id = array_shift($ids);
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $object->Load($id);
+ $object->setPrimary();
+ }
+ }
+
+ /**
+ * [HOOK] Reset primary status of other languages if we are saving primary language
+ *
+ * @param kEvent $event
+ */
+ function OnUpdatePrimary(&$event)
+ {
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $object->SwitchToLive();
+
+ // set primary for each languages, that have this checkbox checked
+ $ids = explode(',', $event->MasterEvent->getEventParam('ids'));
+ foreach ($ids as $id) {
+ $object->Load($id);
+ if ($object->GetDBField('PrimaryLang')) {
+ $object->setPrimary();
+ }
+
+ }
+
+ // if no primary language left, then set primary last language (not to load again) from edited list
+ $sql = 'SELECT '.$object->IDField.'
+ FROM '.$object->TableName.'
+ WHERE PrimaryLang = 1';
+ $primary_language = $this->Conn->GetOne($sql);
+
+ if (!$primary_language) {
+ $object->setPrimary(false);
+ }
+ }
+
+
+ /**
+ * Occurse before updating item
+ *
+ * @param kEvent $event
+ * @access public
+ */
+ function OnBeforeItemUpdate(&$event)
+ {
+ $object =& $event->getObject();
+ $status_field = array_shift( $this->Application->getUnitOption($event->Prefix, 'StatusField') );
+
+ if ($object->GetDBField('PrimaryLang') == 1 && $object->GetDBField($status_field) == 0) {
+ $object->SetDBField($status_field, 1);
+ }
+ }
+
+ /**
+ * Shows only enabled languages on front
+ *
+ * @param kEvent $event
+ */
+ function SetCustomQuery(&$event)
+ {
+ if($event->Special == 'enabled')
+ {
+ $object =& $event->getObject();
+ $object->addFilter('enabled_filter', '%1$s.Enabled = 1');
+ }
+ }
+
+ /**
+ * Copy labels from another language
+ *
+ * @param kEvent $event
+ */
+ function OnCopyLabels(&$event)
+ {
+ $object =& $event->getObject();
+ $from_lang_id = $object->GetDBField('CopyFromLanguage');
+
+ if( ($event->MasterEvent->status == erSUCCESS) && $object->GetDBField('CopyLabels') == 1 && ($from_lang_id > 0) )
+ {
+ $lang_id = $object->GetID();
+
+ // 1. phrases import
+ $phrases_live = $this->Application->getUnitOption('phrases','TableName');
+ $phrases_temp = $this->Application->GetTempName($phrases_live, 'prefix:phrases');
+ $sql = 'INSERT INTO '.$phrases_temp.'
+ SELECT Phrase, Translation, PhraseType, 0-PhraseId, '.$lang_id.', '.adodb_mktime().', "", Module
+ FROM '.$phrases_live.'
+ WHERE LanguageId='.$from_lang_id;
+ $this->Conn->Query($sql);
+
+ // 2. events import
+ $em_table_live = $this->Application->getUnitOption('emailmessages','TableName');
+ $em_table_temp = $this->Application->GetTempName($em_table_live, 'prefix:emailmessages');
+
+ $sql = 'SELECT * FROM '.$em_table_live.' WHERE LanguageId = '.$from_lang_id;
+ $email_messages = $this->Conn->Query($sql);
+ if($email_messages)
+ {
+ $id = $this->Conn->GetOne('SELECT MIN(EmailMessageId) FROM '.$em_table_live);
+ if($id > 0) $id = 0;
+ $id--;
+
+ $sqls = Array();
+ foreach($email_messages as $email_message)
+ {
+ $sqls[] = $id.','.$this->Conn->qstr($email_message['Template']).','.$this->Conn->qstr($email_message['MessageType']).','.$lang_id.','.$email_message['EventId'];
+ $id--;
+ }
+ $sql = 'INSERT INTO '.$em_table_temp.'(EmailMessageId,Template,MessageType,LanguageId,EventId) VALUES ('.implode('),(',$sqls).')';
+ $this->Conn->Query($sql);
+ }
+
+ $object->SetDBField('CopyLabels', 0);
+ }
+ }
+
+ /**
+ * Prepare temp tables for creating new item
+ * but does not create it. Actual create is
+ * done in OnPreSaveCreated
+ *
+ * @param kEvent $event
+ */
+ function OnPreCreate(&$event)
+ {
+ parent::OnPreCreate($event);
+
+ $object =& $event->getObject();
+ $object->SetDBField('CopyLabels', 1);
+
+ $live_table = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ $primary_lang_id = $this->Conn->GetOne('SELECT '.$object->IDField.' FROM '.$live_table.' WHERE PrimaryLang = 1');
+
+ $object->SetDBField('CopyFromLanguage', $primary_lang_id);
+ }
+
+
+ function OnChangeLanguage(&$event)
+ {
+ $this->Application->SetVar('m_lang', $this->Application->GetVar('language'));
+
+ //$this->Application->LinkVar('language', 'm_lang');
+ }
+
+ /**
+ * Parse language XML file into temp tables and redirect to progress bar screen
+ *
+ * @param kEvent $event
+ */
+ function OnImportLanguage(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
+ return;
+ }
+
+ $items_info = $this->Application->GetVar('phrases_import');
+ if($items_info)
+ {
+ list($id,$field_values) = each($items_info);
+ $object =& $this->Application->recallObject('phrases.import', 'phrases', Array('skip_autoload' => true) );
+ $object->SetFieldsFromHash($field_values);
+
+ $filename = getArrayValue($field_values, 'LangFile', 'tmp_name');
+ if( filesize($filename) )
+ {
+ $modules = getArrayValue($field_values,'Module');
+ $lang_xml =& $this->Application->recallObject('LangXML');
+ /* @var $lang_xml LangXML_Parser */
+ $lang_xml->Parse($filename, $field_values['PhraseType'], $modules, $field_values['ImportOverwrite']);
+
+ $event->redirect = true;
+ $event->SetRedirectParams( Array('lang_event' => 'OnImportProgress', 'pass' => 'all,lang', 'mode'=>$field_values['ImportOverwrite']) );
+ }
+ else
+ {
+ $object =& $this->Application->recallObject('phrases.import');
+ $object->SetError('LangFile', 'la_empty_file', 'la_EmptyFile');
+ $event->redirect = false;
+ }
+ }
+ }
+
+ /**
+ * Copies imported from xml file from temp table to live table
+ *
+ * @param kEvent $event
+ */
+ function OnImportProgress(&$event)
+ {
+ define('IMPORT_BY', 300); // import this much records per step
+ $template_name = 'regional/languages_import_step2';
+
+ $import_mode = (int)$this->Application->GetVar('mode'); // 1 - overwrite existing phrases, 0 - don't overwrite existing phrases
+ $import_source = (int)$this->Application->GetVar('source');
+ $import_steps = Array(0 => 'lang', 1 => 'phrases', 2 => 'emailmessages', 3 => 'finish');
+
+ $key_fields = Array(0 => 'PackName', 1 => 'Phrase', 2 => 'EventId'); // by what field should we search record match
+
+ $import_titles = Array(0 => 'la_ImportingLanguages', 1 => 'la_ImportingPhrases', 2 => 'la_ImportingEmailEvents', 3 => 'la_Done');
+
+ // --- BEFORE ---
+ $import_prefix = $import_steps[$import_source];
+ $import_start = (int)$this->Application->GetVar('start');
+ $id_field = $this->Application->getUnitOption($import_prefix,'IDField');
+ $dst_table = $this->Application->getUnitOption($import_prefix,'TableName');
+ $src_table = $this->Application->GetTempName($dst_table);
+
+ $import_total = $this->Application->GetVar('total');
+ if(!$import_total) $import_total = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$src_table);
+ // --- AFTER ---
+
+ if($import_start == $import_total)
+ {
+ $import_source++;
+ $import_prefix = $import_steps[$import_source];
+ if($import_prefix == 'finish')
+ {
+ $event->SetRedirectParam('opener','u');
+ return true;
+ }
+
+ $import_start = 0;
+ $id_field = $this->Application->getUnitOption($import_prefix,'IDField');
+ $dst_table = $this->Application->getUnitOption($import_prefix,'TableName');
+ $src_table = $this->Application->GetTempName($dst_table);
+ $import_total = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$src_table);
+ }
+
+ if($import_total > 0)
+ {
+ $done_percent = ($import_start * 100) / $import_total;
+ }
+ else
+ {
+ $done_percent = 100;
+ }
+
+ $block_params = Array( 'name' => $template_name,
+ 'title' => $import_titles[$import_source],
+ 'percent_done' => $done_percent,
+ 'percent_left' => 100 - $done_percent);
+
+ $this->Application->InitParser();
+ $this->Application->setUnitOption('phrases','AutoLoad',false);
+ echo $this->Application->ParseBlock($block_params);
+
+ //break out of buffering
+ $buffer_content = Array();
+ while (ob_get_level()) {
+ $buffer_content[] = ob_get_clean();
+ }
+ $ret = implode('', array_reverse($buffer_content));
+ echo $ret;
+ flush();
+
+
+ $sql = 'SELECT * FROM %s LIMIT %s,%s';
+ $rows = $this->Conn->Query( sprintf($sql,$src_table,$import_start,IMPORT_BY) );
+
+ $values_sql = '';
+
+ // if found and mode = 1 (overwrite)
+ $search_sql = 'SELECT '.$id_field.' FROM '.$dst_table.' WHERE '.$key_fields[$import_source].' = %s AND LanguageId = %s';
+ $update_sql = 'UPDATE '.$dst_table.' SET %s WHERE '.$id_field.' = %s';
+
+ foreach($rows as $row)
+ {
+ $tmp_sql = sprintf($search_sql, $this->Conn->qstr($row[ $key_fields[$import_source] ]), $row['LanguageId'] );
+ $tmp_id = $this->Conn->GetOne($tmp_sql);
+ if($tmp_id > 0 && $import_mode == 1)
+ {
+ // update
+ $update_fields = '';
+ foreach($row as $field_name => $field_value)
+ {
+ if($field_name == $id_field) continue;
+ $update_fields .= '`'.$field_name.'` = '.$this->Conn->qstr($field_value).',';
+ }
+ $update_fields = preg_replace('/(.*),$/', '\\1', $update_fields);
+ $this->Conn->Query( sprintf($update_sql, $update_fields, $tmp_id) );
+ }
+ elseif(!$tmp_id)
+ {
+ $values_sql .= '(';
+ foreach($row as $field_value)
+ {
+ $values_sql .= $this->Conn->qstr($field_value).',';
+ }
+ $values_sql = preg_replace('/(.*),$/', '\\1', $values_sql).'),';
+ }
+ }
+
+ if($values_sql)
+ {
+ $fields_sql = '';
+ $fields = array_keys( $this->Application->getUnitOption($import_prefix,'Fields') );
+ foreach($fields as $field_name)
+ {
+ $fields_sql .= '`'.$field_name.'`,';
+ }
+ $fields_sql = preg_replace('/(.*),$/', '\\1', $fields_sql);
+
+ $values_sql = preg_replace('/(.*),$/', '\\1', $values_sql);
+ $sql = sprintf('INSERT INTO %s (%s) VALUES %s', $dst_table, $fields_sql, $values_sql);
+ $this->Conn->Query($sql);
+ }
+ $event->setRedirectParams( Array('lang_event' => 'OnImportProgress', 'pass' => 'all,lang', 'start' => $import_start += count($rows), 'total' => $import_total, 'source' => $import_source, 'mode' => $import_mode) );
+ }
+
+ /**
+ * Stores ids of selected languages and redirects to export language step 1
+ *
+ * @param kEvent $event
+ */
+ function OnExportLanguage(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
+ return;
+ }
+
+ $this->Application->setUnitOption('phrases','AutoLoad',false);
+
+ $this->StoreSelectedIDs($event);
+ $this->Application->StoreVar('export_language_ids', implode(',', $this->getSelectedIDs($event)) );
+
+ $event->setRedirectParams( Array('m_opener'=>'d','phrases.export_event'=>'OnNew','pass'=>'all,phrases.export') );
+ $event->redirect = 'regional/languages_export';
+ }
+
+ /**
+ * Saves selected languages to xml file passed
+ *
+ * @param kEvent $event
+ */
+ function OnExportProgress(&$event)
+ {
+ $items_info = $this->Application->GetVar('phrases_export');
+ if($items_info)
+ {
+ list($id,$field_values) = each($items_info);
+ $object =& $this->Application->recallObject('phrases.export', 'phrases', Array('skip_autoload' => true) );
+ $object->SetFieldsFromHash($field_values);
+
+ $lang_ids = explode(',', $this->Application->RecallVar('export_language_ids') );
+
+ if( !getArrayValue($field_values,'LangFile') )
+ {
+ $object->SetError('LangFile', 'required');
+ $event->redirect = false;
+ return false;
+ }
+ if( !is_writable(EXPORT_PATH) )
+ {
+ $object->SetError('LangFile', 'write_error', 'la_ExportFolderNotWritable');
+ $event->redirect = false;
+ return false;
+ }
+ if( substr($field_values['LangFile'], -5) != '.lang' ) $field_values['LangFile'] .= '.lang';
+ $filename = EXPORT_PATH.'/'.$field_values['LangFile'];
+
+ $lang_xml =& $this->Application->recallObject('LangXML');
+ if ($object->GetDBField('DoNotEncode')) {
+ $lang_xml->SetEncoding('plain');
+ }
+ $lang_xml->Create($filename, $field_values['PhraseType'], $lang_ids, $field_values['Module']);
+
+ }
+
+ $event->redirect = 'regional/languages_export_step2';
+ $event->SetRedirectParam('export_file', $field_values['LangFile']);
+ }
+
+ /**
+ * Returns to previous template in opener stack
+ *
+ * @param kEvent $event
+ */
+ function OnGoBack(&$event)
+ {
+ $event->redirect_params['opener'] = 'u';
+ }
+
+ function OnScheduleTopFrameReload(&$event)
+ {
+ $this->Application->StoreVar('RefreshTopFrame',1);
+ }
+
+ /**
+ * Do now allow deleting current language
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemDelete(&$event)
+ {
+ $del_id = $event->getEventParam('id');
+ $object =& $event->getObject(array('skip_autload' => true));
+ $object->Load($del_id);
+
+ if ($object->GetDBField('PrimaryLang') || $del_id == $this->Application->GetVar('m_lang')) {
+ $event->status = erFAIL;
+ }
+ }
+
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.31.2/core/units/languages/languages_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.31
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.31.2/core/admin_templates/js/catalog.js
===================================================================
--- branches/unlabeled/unlabeled-1.31.2/core/admin_templates/js/catalog.js (nonexistent)
+++ branches/unlabeled/unlabeled-1.31.2/core/admin_templates/js/catalog.js (revision 7858)
@@ -0,0 +1,329 @@
+function Catalog($url_mask, $cookie_prefix, $tab_shift) {
+ this.CookiePrefix = $cookie_prefix ? $cookie_prefix : '';
+ this.BusyRequest = new Array();
+ this.URLMask = $url_mask;
+ this.Separator = '#separator#';
+ this.ParentCategoryID = 0;
+ this.OnResponceMethod = null;
+ this.TabShift = isset($tab_shift) ? $tab_shift : 1; // start from 2nd tab (index starting from 0)
+
+ this.TabRegistry = new Array();
+ this.ActivePrefix = getCookie(this.CookiePrefix + 'active_prefix');
+ this.PreviousPrefix = this.ActivePrefix;
+ $ViewMenus = new Array('c');
+}
+
+Catalog.prototype.Init = function () {
+ var $prefix = this.queryTabRegistry('prefix', this.ActivePrefix, 'prefix');
+ if ($prefix !== this.ActivePrefix && this.TabRegistry.length > this.TabShift) {
+ // ActivePrefix not set or has non-existing prefix value
+ this.ActivePrefix = this.TabRegistry[this.TabShift]['prefix'];
+ }
+ this.SetAlternativeTabs();
+ this.AfterInit();
+}
+
+Catalog.prototype.AfterInit = function () {
+ this.go_to_cat();
+}
+
+Catalog.prototype.SetAlternativeTabs = function () {
+ // set alternative grids between all items (catalog is set when tab is loaded via AJAX first time)
+ var $i = this.TabShift;
+ while ($i < this.TabRegistry.length) {
+ // run through all prefixes
+ var $j = this.TabShift;
+ while ($j < this.TabRegistry.length) {
+ if (this.TabRegistry[$i]['prefix'] == this.TabRegistry[$j]['prefix']) {
+ $j++;
+ continue;
+ }
+ // and set alternative to all other prefixes
+ $GridManager.AddAlternativeGrid(this.TabRegistry[$i]['prefix'], this.TabRegistry[$j]['prefix']);
+ $j++;
+ }
+ $i++;
+ }
+}
+
+Catalog.prototype.submit_kernel_form = function($tab_id) {
+ var $prefix = 'dummy';
+ var $result_div = '';
+
+ if (isset($tab_id)) {
+ // responce result + progress are required
+ $prefix = this.queryTabRegistry('tab_id', $tab_id, 'prefix');
+ $result_div = $tab_id + '_div';
+ }
+
+ var $kf = document.getElementById($form_name);
+
+ Request.params = Request.serializeForm($kf);
+ Request.method = $kf.method.toUpperCase();
+
+ this.BusyRequest[$prefix] = false;
+ Request.makeRequest($kf.action, this.BusyRequest[$prefix], $result_div, this.successCallback, this.errorCallback, $result_div, this);
+
+ $form_name = 'kernel_form'; // restore back to main form with current category id of catalog
+};
+
+Catalog.prototype.successCallback = function($request, $params, $object) {
+
+ var $text = $request.responseText;
+
+ var $match_redirect = new RegExp('^#redirect#(.*)').exec($text);
+ if ($match_redirect != null) {
+ // redirect to external template requested
+ window.location.href = $match_redirect[1];
+ return false;
+ }
+
+ $params = $params.split(',');
+
+
+ var $js_end = $text.indexOf($object.Separator);
+ if ($js_end != -1) {
+
+ // allow to detect if output is permitted by ajax request parameters
+ var $request_visible = '$request_visible = ' + ($params[0].length ? 'true' : 'false') + "\n";
+
+ if ($params[0].length) {
+ document.getElementById($params[0]).innerHTML = $text.substring($js_end + $object.Separator.length);
+ eval($request_visible + $text.substring(0, $js_end));
+ }
+ else {
+ // eval JS only & set mark that js should not use HTML as usual in grids
+ eval($request_visible + $text.substring(0, $js_end));
+ }
+ }
+
+ else if ($params[0].length) {
+ document.getElementById($params[0]).innerHTML = $text;
+ }
+
+ if (typeof($object.OnResponceMethod) == 'function') {
+ $object.OnResponceMethod($object);
+ $object.OnResponceMethod = null;
+ }
+
+ if (typeof($Debugger) != 'undefined') {
+ $Debugger.Clear();
+ }
+}
+
+Catalog.prototype.errorCallback = function($request, $params, $object) {
+// $Debugger.ShowProps($request, 'req');
+ alert('AJAX Error; class: Catalog; ' + Request.getErrorHtml($request));
+}
+
+Catalog.prototype.submit_event = function($prefix_special, $event, $t, $OnResponceMethod) {
+ if (typeof($OnResponceMethod) == 'function') {
+ this.OnResponceMethod = $OnResponceMethod;
+ }
+
+ var $prev_template = get_hidden_field('t');
+ if (!isset($prefix_special)) $prefix_special = this.getCurrentPrefix();
+ var $tab_id = this.queryTabRegistry('prefix', $prefix_special, 'tab_id');
+
+ $form_name = $tab_id + '_form'; // set firstly, because set_hidden_field uses it
+ if (isset($event)) set_hidden_field('events[' + $prefix_special + ']', $event);
+ if (isset($t)) set_hidden_field('t', $t);
+
+ this.submit_kernel_form($tab_id);
+ set_hidden_field('t', $prev_template);
+}
+
+
+Catalog.prototype.go_to_cat = function($cat_id) {
+ if (!isset($cat_id)) {
+ // gets current category
+ $cat_id = get_hidden_field('m_cat_id');
+ }
+ else {
+ // sets new category to kernel_form in case if item tab
+ // loads faster and will check if it's category is same
+ // as parent category of categories list
+
+ if (get_hidden_field('m_cat_id') == $cat_id) {
+ // it's the same category, then don't reload category list
+ return ;
+ }
+ set_hidden_field('m_cat_id', $cat_id);
+ }
+
+ this.resetTabs(false);
+
+ // query sub categories of $cat_id
+ var $url = this.URLMask.replace('#TEMPLATE_NAME#', 'in-portal/xml/categories_list').replace('#CATEGORY_ID#', $cat_id);
+
+ var $prefix = this.TabRegistry[0]['prefix'];
+ var $tab_id = this.TabRegistry[0]['tab_id'];
+ this.BusyRequest[$prefix] = false;
+ Request.makeRequest($url, this.BusyRequest[$prefix], $tab_id + '_div', this.successCallback, this.errorCallback, $tab_id + '_div', this);
+ this.switchTab(); // refresh current item tab
+}
+
+// set all item tabs counters to "?" before quering catagories
+Catalog.prototype.resetTabs = function($reset_content) {
+ var $i = this.TabShift;
+ while ($i < this.TabRegistry.length) {
+ this.setItemCount(this.TabRegistry[$i]['prefix'], '?');
+ $i++;
+ }
+
+ if ($reset_content) {
+ // set category for all tabs to -1 (forces reload next time)
+ $i = this.TabShift;
+ while ($i < this.TabRegistry.length) {
+ document.getElementById(this.TabRegistry[$i]['tab_id'] + '_div').setAttribute('category_id', -1);
+ $i++;
+ }
+ }
+}
+
+Catalog.prototype.switchTab = function($prefix, $force) {
+ if (this.queryTabRegistry('prefix', this.ActivePrefix, 'prefix') != this.ActivePrefix) {
+ // active prefix is not registred -> cookie left, but not modules installed/enabled at the moment
+ return false;
+ }
+
+ if (!isset($prefix)) $prefix = this.ActivePrefix;
+
+ if (this.BusyRequest[$prefix]) {
+ alert('prefix: ['+$prefix+']; request busy: ['+this.BusyRequest[$prefix]+']');
+ }
+
+ if (this.ActivePrefix != $prefix) {
+ // hide source tab
+ this.PreviousPrefix = this.ActivePrefix;
+ document.getElementById(this.PreviousPrefix + '_tab').className = 'catalog-tab-unselected';
+ document.getElementById(this.queryTabRegistry('prefix', this.PreviousPrefix, 'tab_id') + '_div').style.display = 'none';
+ this.HideDependentButtons(this.PreviousPrefix);
+ }
+
+ // show destination tab
+ this.ActivePrefix = $prefix;
+ document.getElementById(this.ActivePrefix + '_tab').className = 'catalog-tab-selected';
+ var $div_id = this.queryTabRegistry('prefix', this.ActivePrefix, 'tab_id') + '_div'; // destination tab
+ document.getElementById($div_id).style.display = 'block';
+ this.ShowDependentButtons(this.ActivePrefix);
+ this.setViewMenu(this.ActivePrefix);
+ setCookie(this.CookiePrefix + 'active_prefix', this.ActivePrefix);
+
+ this.refreshTab($prefix, $div_id, $force);
+}
+
+Catalog.prototype.refreshTab = function($prefix, $div_id, $force) {
+ var $cat_id = get_hidden_field('m_cat_id');
+ var $tab_cat_id = document.getElementById($div_id).getAttribute('category_id');
+ if ($cat_id != $tab_cat_id || $force) {
+ // query tab content only in case if not queried or category don't match
+ var $url = this.URLMask.replace('#TEMPLATE_NAME#', this.queryTabRegistry('prefix', $prefix, 'module_path') + '/catalog_tab');
+ $url = $url.replace('#CATEGORY_ID#', $cat_id);
+ $url = $url.replace('#PREFIX#', $prefix);
+
+ this.BusyRequest[$prefix] = false;
+ Request.makeRequest($url, this.BusyRequest[$prefix], $div_id, this.successCallback, this.errorCallback, $div_id, this);
+ }
+ /*else {
+ alert('refresh disabled = {tab: '+this.ActivePrefix+'; cat_id: '+$cat_id+'; form_name: '+$form_name+'}');
+ }*/
+}
+
+// adds information about tab to tab_registry
+Catalog.prototype.registerTab = function($tab_id) {
+ var $tab = document.getElementById($tab_id + '_div');
+ var $index = this.TabRegistry.length;
+ this.TabRegistry[$index] = new Array();
+ this.TabRegistry[$index]['tab_id'] = $tab_id;
+ this.TabRegistry[$index]['prefix'] = $tab.getAttribute('prefix');
+ if ($tab_id == 'categories') {
+ this.TabRegistry[$index]['module_path'] = 'in-portal/';
+ }
+ else {
+ this.TabRegistry[$index]['module_path'] = $tab.getAttribute('edit_template').substring(0, $tab.getAttribute('edit_template').indexOf('/'));
+ }
+ this.TabRegistry[$index]['view_template'] = $tab.getAttribute('view_template');
+ this.TabRegistry[$index]['edit_template'] = $tab.getAttribute('edit_template');
+ this.TabRegistry[$index]['dep_buttons'] = $tab.getAttribute('dep_buttons').length > 0 ? $tab.getAttribute('dep_buttons').split(',') : new Array();
+ this.TabRegistry[$index]['index'] = $index;
+}
+
+// allows to get any information about tab
+Catalog.prototype.queryTabRegistry = function($search_key, $search_value, $return_key) {
+ var $i = 0;
+// alert('looking in '+$search_key+' for '+$search_value+' will return '+$return_key)
+ while ($i < this.TabRegistry.length) {
+ if (this.TabRegistry[$i][$search_key] == $search_value) {
+// alert('got '+this.TabRegistry[$i][$return_key])
+ return this.TabRegistry[$i][$return_key];
+ break;
+ }
+ $i++;
+ }
+ return false;
+}
+
+Catalog.prototype.ShowDependentButtons = function($prefix) {
+ /*var $tab_id = this.queryTabRegistry('prefix', $prefix, 'tab_id')
+ if (!document.getElementById($tab_id + '_form')) {
+ // tab form not found => no permission to view -> no permission to do any actions
+ alert('no form: ['+$tab_id + '_form'+']');
+ return ;
+ }
+ else {
+ alert('has form: ['+$tab_id + '_form'+']');
+ }*/
+
+ var $dep_buttons = this.queryTabRegistry('prefix', $prefix, 'dep_buttons');
+ var $i = 0;
+ while ($i < $dep_buttons.length) {
+ a_toolbar.ShowButton($dep_buttons[$i]);
+ $i++;
+ }
+}
+
+Catalog.prototype.HideDependentButtons = function($prefix) {
+ var $dep_buttons = this.queryTabRegistry('prefix', $prefix, 'dep_buttons');
+ var $i = 0;
+ while ($i < $dep_buttons.length) {
+ a_toolbar.HideButton($dep_buttons[$i]);
+ $i++;
+ }
+}
+
+Catalog.prototype.setItemCount = function($prefix, $count) {
+ setInnerHTML($prefix + '_item_count', $count);
+}
+
+Catalog.prototype.setCurrentCategory = function($prefix, $category_id) {
+ var $tab_id = this.queryTabRegistry('prefix', $prefix, 'tab_id');
+// alert('setting current category for prefix: ['+$prefix+']; tab_id ['+$tab_id+'] = ['+$category_id+']');
+ document.getElementById($tab_id + '_div').setAttribute('category_id', $category_id);
+}
+
+
+Catalog.prototype.getCurrentPrefix = function() {
+ if (isset(Grids[this.ActivePrefix]) && (Grids[this.ActivePrefix].SelectedCount > 0)) {
+ // item tab grid exists and some items are selected
+ return this.ActivePrefix;
+ }
+ else {
+ // return prefix of first registred tab -> categories
+ return this.TabRegistry[0]['prefix'];
+ }
+}
+
+Catalog.prototype.setViewMenu = function($item_prefix) {
+ if (this.TabShift == 1) {
+ $ViewMenus = isset($item_prefix) ? new Array('c', $item_prefix) : new Array('c');
+ }
+ else {
+ $ViewMenus = isset($item_prefix) ? new Array($item_prefix) : new Array();
+ }
+}
+
+Catalog.prototype.reflectPasteButton = function($status) {
+ a_toolbar.SetEnabled('paste', $status);
+ a_toolbar.SetEnabled('clear_clipboard', $status);
+}
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.31.2/core/admin_templates/js/catalog.js
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.31
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Event Timeline
Log In to Comment