Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1058782
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
Thu, Jul 10, 9:33 PM
Size
56 KB
Mime Type
text/x-diff
Expires
Sat, Jul 12, 9:33 PM (3 h, 3 m)
Engine
blob
Format
Raw Data
Handle
683809
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/kernel/admin_templates/incs/script.js
===================================================================
--- trunk/kernel/admin_templates/incs/script.js (revision 4356)
+++ trunk/kernel/admin_templates/incs/script.js (revision 4357)
@@ -1,853 +1,883 @@
if ( !( isset($init_made) && $init_made ) ) {
var Grids = new Array();
var Toolbars = new Array();
var $Menus = new Array();
var $ViewMenus = new Array();
var $form_name = 'kernel_form';
if(!$fw_menus) var $fw_menus = new Array();
var $env = '';
var submitted = false;
var $edit_mode = false;
var $init_made = true; // in case of double inclusion of script.js :)
-
+
// hook processing
var hBEFORE = 1; // this is const, but including this twice causes errors
var hAFTER = 2; // this is const, but including this twice causes errors
var $hooks = new Array();
}
function getArrayValue()
{
var $value = arguments[0];
var $current_key = 0;
$i = 1;
while ($i < arguments.length) {
$current_key = arguments[$i];
if (isset($value[$current_key])) {
$value = $value[$current_key];
}
else {
return false;
}
$i++;
}
return $value;
}
function setArrayValue()
{
// first argument - array, other arguments - keys (arrays too), last argument - value
var $array = arguments[0];
var $current_key = 0;
$i = 1;
while ($i < arguments.length - 1) {
$current_key = arguments[$i];
if (!isset($array[$current_key])) {
$array[$current_key] = new Array();
}
$array = $array[$current_key];
$i++;
}
$array[$array.length] = arguments[arguments.length - 1];
}
function processHooks($function_name, $hook_type, $prefix_special)
{
var $i = 0;
var $local_hooks = getArrayValue($hooks, $function_name, $hook_type);
-
+
while($i < $local_hooks.length) {
$local_hooks[$i]($function_name, $prefix_special);
$i++;
}
}
function registerHook($function_name, $hook_type, $hook_body)
{
setArrayValue($hooks, $function_name, $hook_type, $hook_body);
}
function resort_grid(prefix_special,field,form_action)
{
set_hidden_field(prefix_special+'_Sort1', field);
submit_event(prefix_special,'OnSetSorting',null,form_action);
}
function direct_sort_grid($prefix_special,$field,$direction,$field_pos)
{
if(!isset($field_pos)) $field_pos = 1;
set_hidden_field($prefix_special+'_Sort'+$field_pos,$field);
set_hidden_field($prefix_special+'_Sort'+$field_pos+'_Dir',$direction);
set_hidden_field($prefix_special+'_SortPos',$field_pos);
submit_event($prefix_special,'OnSetSortingDirect');
}
function reset_sorting($prefix_special)
{
submit_event($prefix_special,'OnResetSorting');
}
function set_per_page($prefix_special,$per_page)
{
set_hidden_field($prefix_special+'_PerPage',$per_page);
submit_event($prefix_special,'OnSetPerPage');
}
function submit_event(prefix_special,event,t,form_action)
{
if (isset(event)) {
set_hidden_field('events['+prefix_special+']', event);
}
if(isset(t)) set_hidden_field('t', t);
if( isset(form_action) )
{
var old_env = '';
if ( !form_action.match(/\?/) ) {
document.getElementById($form_name).action.match(/.*(\?.*)/);
old_env = RegExp.$1;
}
document.getElementById($form_name).action = form_action+old_env;
}
submit_kernel_form();
}
function show_form_data()
{
var $kf = document.getElementById($form_name);
$ret = '';
for(var i in $kf.elements)
{
$elem = $kf.elements[i];
$ret += $elem.id + ' = ' + $elem.value + "\n";
}
alert($ret);
}
function submit_kernel_form()
{
if (submitted) {
return;
}
submitted = true;
var $form = document.getElementById($form_name);
processHooks('SubmitKF', hBEFORE);
if (typeof $form.onsubmit == "function") {
$form.onsubmit();
}
$form.submit();
processHooks('SubmitKF', hAFTER);
$form.target = '';
$form.t.value = t;
window.setTimeout(function() {submitted = false}, 500);
}
function set_event(prefix_special, event)
{
var event_field=document.getElementById('events[' + prefix_special + ']');
if(isset(event_field))
{
event_field.value = event;
}
}
function isset(variable)
{
if(variable==null) return false;
return (typeof(variable)=='undefined')?false:true;
}
-function print_pre(variable)
+function in_array(needle, haystack)
+{
+ return array_search(needle, haystack) != -1;
+}
+
+function array_search(needle, haystack)
+{
+ for (var i=0; i<haystack.length; i++)
+ {
+ if (haystack[i] == needle) return i;
+ }
+ return -1;
+}
+
+function print_pre(variable, msg)
{
- var s = "";
+ if (!isset(msg)) msg = '';
+ var s = msg;
for (prop in variable) {
- s += prop+" => "+variable[prop] + "";
+ s += prop+" => "+variable[prop] + "\n";
}
alert(s);
}
function go_to_page(prefix_special, page)
{
set_hidden_field(prefix_special+'_Page', page);
submit_event(prefix_special);
}
function go_to_list(prefix_special, tab)
{
set_hidden_field(prefix_special+'_GoTab', tab);
submit_event(prefix_special,'OnUpdateAndGoToTab',null);
}
function go_to_tab(prefix_special, tab)
{
set_hidden_field(prefix_special+'_GoTab', tab);
submit_event(prefix_special,'OnPreSaveAndGoToTab',null);
}
function go_to_id(prefix_special, id)
{
set_hidden_field(prefix_special+'_GoId', id);
submit_event(prefix_special,'OnPreSaveAndGo')
}
// in-portal compatibility functions: begin
function getScriptURL($script_name)
{
var $asid = get_hidden_field('sid');
return base_url+$script_name+'?env='+( isset($env)&&$env?$env:$asid )+'&en=0';
}
function OpenEditor(extra_env,TargetForm,TargetField)
{
var $url = getScriptURL('admin/editor/editor_new.php');
$url = $url+'&TargetForm='+TargetForm+'&TargetField='+TargetField+'&destform=popup';
if(extra_env.length>0) $url += extra_env;
openwin($url,'html_edit',800,575);
}
function OpenUserSelector(extra_env,TargetForm,TargetField)
{
var $url = getScriptURL('admin/users/user_select.php');
$url += '&destform='+TargetForm+'&Selector=radio&destfield='+TargetField+'&IdField=Login';
if(extra_env.length>0) $url += extra_env;
openwin($url,'user_select',800,575);
return false;
}
function OpenCatSelector(extra_env)
{
var $url = getScriptURL('admin/cat_select.php');
if(extra_env.length>0) $url += extra_env;
openwin($url,'catselect',750,400);
}
function OpenItemSelector(extra_env,$TargetForm)
{
var $url = getScriptURL('admin/relation_select.php') + '&destform='+$TargetForm;
if(extra_env.length>0) $url += extra_env;
openwin($url,'groupselect',750,400);
}
function OpenUserEdit($user_id, $extra_env)
{
var $url = getScriptURL('admin/users/adduser.php') + '&direct_id=' + $user_id;
if( isset($extra_env) ) $url += $extra_env;
window.location.href = $url;
}
function OpenLinkEdit($link_id, $extra_env)
{
var $url = getScriptURL('in-link/admin/addlink.php') + '&item=' + $link_id;
if( isset($extra_env) ) $url += $extra_env;
window.location.href = $url;
}
function OpenHelp($help_link)
{
// $help_link.match('http://(.*).lv/in-commerce/admin(.*)');
// alert(RegExp.$2);
openwin($help_link,'HelpPopup',750,400);
}
// in-portal compatibility functions: end
function PreSaveAndOpenTranslator(prefix,field,t,multi_line,$width,$height)
{
if(!isset($window_name)) var $window_name = 'select_'+t.replace(/(\/|-)/g, '_');
if(!isset($width)) $width=750;
if(!isset($height)) $height=400;
if(!isset(multi_line)) multi_line=0;
openwin('',$window_name,$width,$height);
set_hidden_field('return_template', document.kernel_form.elements['t'].value); // where should return after popup is done
set_hidden_field('translator_wnd_name', $window_name);
set_hidden_field('translator_field', field);
set_hidden_field('translator_t', t);
set_hidden_field('translator_prefixes', prefix);
set_hidden_field('translator_multi_line', multi_line);
document.kernel_form.target=$window_name;
var split_prefix = prefix.split(',');
submit_event(split_prefix[0],'OnPreSaveAndOpenTranslator');
}
function PreSaveAndOpenTranslatorCV(prefix,field,t,resource_id,multi_line)
{
if(!isset($window_name)) var $window_name = 'select_'+t.replace(/(\/|-)/g, '_');
if(!isset(multi_line)) multi_line=0;
openwin('',$window_name,750,400);
set_hidden_field('return_template', document.kernel_form.elements['t'].value); // where should return after popup is done
set_hidden_field('translator_wnd_name', $window_name);
set_hidden_field('translator_field', field);
set_hidden_field('translator_t', t);
set_hidden_field('translator_prefixes', prefix);
set_hidden_field('translator_resource_id', resource_id);
set_hidden_field('translator_multi_line', multi_line);
document.kernel_form.target = $window_name;
var split_prefix = prefix.split(',');
submit_event(split_prefix[0],'OnPreSaveAndOpenTranslator');
}
function openTranslator(prefix,field,url,wnd)
{
set_hidden_field('trans_prefix', prefix);
set_hidden_field('trans_field', field);
set_hidden_field('events[trans]', 'OnLoad');
var $regex = new RegExp('(.*)\?env=' + document.getElementById('sid').value + '-(.*?):(.*)');
var $t = $regex.exec(url)[2];
document.kernel_form.target = wnd;
submit_event(prefix,'',$t,url);
}
function openSelector($prefix, $url, $dst_field, $window_size, $event)
{
var $kf = document.getElementById($form_name);
var $regex = new RegExp('(.*)\?env=' + document.getElementById('sid').value + '-(.*?):(.*)');
var $t = $regex.exec($url)[2];
var $window_name = 'select_'+$t.replace(/(\/|-)/g, '_');
if (!isset($window_size)) $window_size = '750x400';
$window_size = $window_size.split('x');
if(!isset($event)) $event='';
processHooks('openSelector', hBEFORE);
var $prev_action = $kf.action;
var $prev_opener = get_hidden_field('m_opener');
set_hidden_field('m_opener', 'p');
set_hidden_field('main_prefix', $prefix);
set_hidden_field('dst_field', $dst_field);
set_hidden_field('return_template', $kf.elements['t'].value); // where should return after popup is done
openwin('',$window_name,$window_size[0],$window_size[1]);
document.kernel_form.action = $url;
document.kernel_form.target = $window_name;
submit_event($prefix, $event, $t);
processHooks('openSelector', hAFTER);
$kf.action = $prev_action;
set_hidden_field('m_opener', $prev_opener);
}
function openwin($url,$name,$width,$height)
{
var $window_params = 'width='+$width+',height='+$height+',status=yes,resizable=yes,menubar=no,scrollbars=yes,toolbar=no';
return window.open($url,$name,$window_params);
}
function opener_action(new_action)
{
set_hidden_field('m_opener', new_action);
}
function std_precreate_item(prefix_special, edit_template)
{
opener_action('d');
set_hidden_field(prefix_special+'_mode', 't');
submit_event(prefix_special,'OnPreCreate', edit_template)
}
function std_new_item(prefix_special, edit_template)
{
opener_action('d');
submit_event(prefix_special,'OnNew', edit_template)
}
function std_edit_item(prefix_special, edit_template)
{
opener_action('d');
set_hidden_field(prefix_special+'_mode', 't');
submit_event(prefix_special,'OnEdit',edit_template)
}
function std_edit_temp_item(prefix_special, edit_template)
{
opener_action('d');
submit_event(prefix_special,'',edit_template)
}
function std_delete_items(prefix_special)
{
if (inpConfirm('Are you sure you want to delete selected items?'))
submit_event(prefix_special,'OnMassDelete')
}
// sets hidden field value
// if the field does not exist - creates it
function set_hidden_field($field_id, $value)
{
// alert('form: '+$form_name);
var $kf = document.getElementById($form_name);
var $field = $kf.elements[$field_id];
if($field)
{
$field.value = $value;
return true;
}
$field = document.createElement('INPUT');
$field.type = 'hidden';
$field.name = $field_id;
$field.id = $field_id;
$field.value = $value;
$kf.appendChild($field);
return false;
}
function get_hidden_field($field)
{
var $kf = document.getElementById($form_name);
return $kf.elements[$field] ? $kf.elements[$field].value : false;
}
function search($prefix_special, $grid_name)
{
set_hidden_field('grid_name', $grid_name);
submit_event($prefix_special,'OnSearch');
}
function search_reset($prefix_special, $grid_name)
{
set_hidden_field('grid_name', $grid_name);
submit_event($prefix_special,'OnSearchReset');
}
function search_keydown($event)
{
if(!$event && window.event) $event = window.event;
if($event.keyCode == 13)
{
var $prefix_special = this.getAttribute('PrefixSpecial');
var $grid = this.getAttribute('Grid');
search($prefix_special,$grid);
}
}
function getRealLeft(el)
{
xPos = el.offsetLeft;
tempEl = el.offsetParent;
while (tempEl != null)
{
xPos += tempEl.offsetLeft;
tempEl = tempEl.offsetParent;
}
return xPos;
}
function getRealTop(el)
{
yPos = el.offsetTop;
tempEl = el.offsetParent;
while (tempEl != null)
{
yPos += tempEl.offsetTop;
tempEl = tempEl.offsetParent;
}
return yPos;
}
function show_viewmenu($toolbar, $button_id)
{
var $img = $toolbar.GetButtonImage($button_id);
var $pos_x = getRealLeft($img) - ((document.all) ? 6 : -2);
var $pos_y = getRealTop($img) + 32;
var $prefix_special = '';
window.triedToWriteMenus = false;
if($ViewMenus.length == 1)
{
$prefix_special = $ViewMenus[$ViewMenus.length-1];
$fw_menus[$prefix_special+'_view_menu']();
$Menus[$prefix_special+'_view_menu'].writeMenus('MenuContainers['+$prefix_special+']');
window.FW_showMenu($Menus[$prefix_special+'_view_menu'], $pos_x, $pos_y);
}
else
{
// prepare menus
for(var $i in $ViewMenus)
{
$prefix_special = $ViewMenus[$i];
$fw_menus[$prefix_special+'_view_menu']();
}
$Menus['mixed'] = new Menu('ViewMenu_mixed');
// merge menus into new one
for(var $i in $ViewMenus)
{
$prefix_special = $ViewMenus[$i];
$Menus['mixed'].addMenuItem( $Menus[$prefix_special+'_view_menu'] );
}
$Menus['mixed'].writeMenus('MenuContainers[mixed]');
window.FW_showMenu($Menus['mixed'], $pos_x, $pos_y);
}
}
function set_window_title($title)
{
var $window = window;
if($window.parent) $window = $window.parent;
$window.document.title = (main_title.length ? main_title + ' - ' : '') + $title;
}
function set_filter($prefix_special, $filter_id, $filter_value)
{
set_hidden_field('filter_id',$filter_id);
set_hidden_field('filter_value',$filter_value);
submit_event($prefix_special,'OnSetFilter');
}
function filters_remove_all($prefix_special)
{
submit_event($prefix_special,'OnRemoveFilters');
}
function filters_apply_all($prefix_special)
{
submit_event($prefix_special,'OnApplyFilters');
}
function RemoveTranslationLink($string, $escaped)
{
if (!isset($escaped)) $escaped = true;
if ($escaped) {
return $string.match(/<a href="(.*)">(.*)<\/a>/) ? RegExp.$2 : $string;
}
else {
return $string.match(/<a href="(.*)">(.*)<\/a>/) ? RegExp.$2 : $string;
}
}
function redirect($url)
{
window.location.href = $url;
}
function update_checkbox_options($cb_mask, $hidden_id)
{
var $kf = document.getElementById($form_name);
var $tmp = '';
for (var i = 0; i < $kf.elements.length; i++)
{
if ( $kf.elements[i].id.match($cb_mask) )
{
if ($kf.elements[i].checked) $tmp += '|'+$kf.elements[i].value;
}
}
if($tmp.length > 0) $tmp += '|';
document.getElementById($hidden_id).value = $tmp.replace(/,$/, '');
}
// related to lists operations (moving)
function move_selected($from_list, $to_list)
{
if (typeof($from_list) != 'object') $from_list = document.getElementById($from_list);
if (typeof($to_list) != 'object') $to_list = document.getElementById($to_list);
if (has_selected_options($from_list))
{
var $from_array = select_to_array($from_list);
var $to_array = select_to_array($to_list);
var $new_from = Array();
var $cur = null;
for (var $i = 0; $i < $from_array.length; $i++)
{
$cur = $from_array[$i];
if ($cur[2]) // If selected - add to To array
{
$to_array[$to_array.length] = $cur;
}
else //Else - keep in new From
{
$new_from[$new_from.length] = $cur;
}
}
$from_list = array_to_select($new_from, $from_list);
$to_list = array_to_select($to_array, $to_list);
}
else
{
alert('Please select items to perform moving!');
}
}
function select_to_array($aSelect)
{
var $an_array = new Array();
var $cur = null;
for (var $i = 0; $i < $aSelect.length; $i++)
{
$cur = $aSelect.options[$i];
$an_array[$an_array.length] = new Array($cur.text, $cur.value, $cur.selected);
}
return $an_array;
}
function array_to_select($anArray, $aSelect)
{
var $initial_length = $aSelect.length;
for (var $i = $initial_length - 1; $i >= 0; $i--)
{
$aSelect.options[$i] = null;
}
for (var $i = 0; $i < $anArray.length; $i++)
{
$cur = $anArray[$i];
$aSelect.options[$aSelect.length] = new Option($cur[0], $cur[1]);
}
}
function select_compare($a, $b)
{
if ($a[0] < $b[0])
return -1;
if ($a[0] > $b[0])
return 1;
return 0;
}
function select_to_string($aSelect)
{
var $result = '';
var $cur = null;
if (typeof($aSelect) != 'object') $aSelect = document.getElementById($aSelect);
for (var $i = 0; $i < $aSelect.length; $i++)
{
$result += $aSelect.options[$i].value + '|';
}
return $result.length ? '|' + $result : '';
}
function selected_to_string($aSelect)
{
var $result = '';
var $cur = null;
if (typeof($aSelect) != 'object') $aSelect = document.getElementById($aSelect);
for (var $i = 0; $i < $aSelect.length; $i++)
{
$cur = $aSelect.options[$i];
if ($cur.selected && $cur.value != '')
{
$result += $cur.value + '|';
}
}
return $result.length ? '|' + $result : '';
}
function string_to_selected($str, $aSelect)
{
var $cur = null;
for (var $i = 0; i < $aSelect.length; $i++)
{
$cur = $aSelect.options[$i];
$aSelect.options[$i].selected = $str.match(',' + $cur.value + ',') ? true : false;
}
}
function set_selected($selected_options, $aSelect)
{
if (!$selected_options.length) return false;
for (var $i = 0; $i < $aSelect.length; $i++)
{
for (var $k = 0; $k < $selected_options.length; $k++)
{
if ($aSelect.options[$i].value == $selected_options[$k])
{
$aSelect.options[$i].selected = true;
}
}
}
}
function get_selected_count($theList)
{
var $count = 0;
var $cur = null;
for (var $i = 0; $i < $theList.length; $i++)
{
$cur = $theList.options[$i];
if ($cur.selected) $count++;
}
return $count;
}
function get_selected_index($aSelect, $typeIndex)
{
var $index = 0;
for (var $i = 0; $i < $aSelect.length; $i++)
{
if ($aSelect.options[$i].selected)
{
$index = $i;
if ($typeIndex == 'firstSelected') break;
}
}
return $index;
}
function has_selected_options($theList)
{
var $ret = false;
var $cur = null;
for (var $i = 0; $i < $theList.length; $i++)
{
$cur = $theList.options[$i];
if ($cur.selected) $ret = true;
}
return $ret;
}
function select_sort($aSelect)
{
if (typeof($aSelect) != 'object') $aSelect = document.getElementById($aSelect);
var $to_array = select_to_array($aSelect);
$to_array.sort(select_compare);
array_to_select($to_array, $aSelect);
}
function move_options_up($aSelect, $interval)
{
if (typeof($aSelect) != 'object') $aSelect = document.getElementById($aSelect);
if (has_selected_options($aSelect))
{
var $selected_options = Array();
var $first_selected = get_selected_index($aSelect, 'firstSelected');
for (var $i = 0; $i < $aSelect.length; $i++)
{
if ($aSelect.options[$i].selected && ($first_selected > 0) )
{
swap_options($aSelect, $i, $i - $interval);
$selected_options[$selected_options.length] = $aSelect.options[$i - $interval].value;
}
else if ($first_selected == 0)
{
//alert('Begin of list');
break;
}
}
set_selected($selected_options, $aSelect);
}
else
{
//alert('Check items from moving');
}
}
function move_options_down($aSelect, $interval)
{
if (typeof($aSelect) != 'object') $aSelect = document.getElementById($aSelect);
if (has_selected_options($aSelect))
{
var $last_selected = get_selected_index($aSelect, 'lastSelected');
var $selected_options = Array();
for (var $i = $aSelect.length - 1; $i >= 0; $i--)
{
if ($aSelect.options[$i].selected && ($aSelect.length - ($last_selected + 1) > 0))
{
swap_options($aSelect, $i, $i + $interval);
$selected_options[$selected_options.length] = $aSelect.options[$i + $interval].value;
}
else if ($last_selected + 1 == $aSelect.length)
{
//alert('End of list');
break;
}
}
set_selected($selected_options, $aSelect);
}
else
{
//alert('Check items from moving');
}
}
function swap_options($aSelect, $src_num, $dst_num)
{
var $src_html = $aSelect.options[$src_num].innerHTML;
var $dst_html = $aSelect.options[$dst_num].innerHTML;
var $src_value = $aSelect.options[$src_num].value;
var $dst_value = $aSelect.options[$dst_num].value;
-
+
var $src_option = document.createElement('OPTION');
var $dst_option = document.createElement('OPTION');
-
+
$aSelect.remove($src_num);
$aSelect.options.add($dst_option, $src_num);
$dst_option.innerText = $dst_html;
$dst_option.value = $dst_value;
$dst_option.innerHTML = $dst_html;
-
+
$aSelect.remove($dst_num);
$aSelect.options.add($src_option, $dst_num);
$src_option.innerText = $src_html;
$src_option.value = $src_value;
$src_option.innerHTML = $src_html;
}
-
- function getXMLHTTPObject()
+
+ function getXMLHTTPObject(content_type)
{
+ if (!isset(content_type)) content_type = 'text/plain';
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
- http_request.overrideMimeType('text/plain');
+ http_request.overrideMimeType(content_type);
// See note below about this line
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
return http_request;
}
-
- function str_repeat($symbol, $count)
+
+ function str_repeat($symbol, $count)
{
var $i = 0;
var $ret = '';
while($i < $count) {
$ret += $symbol;
$i++;
}
return $ret;
+ }
+
+ function getDocumentFromXML(xml)
+ {
+ if (window.ActiveXObject) {
+ var doc = new ActiveXObject("Microsoft.XMLDOM");
+ doc.async=false;
+ doc.loadXML(xml);
+ }
+ else {
+ var parser = new DOMParser();
+ var doc = parser.parseFromString(xml,"text/xml");
+ }
+ return doc;
}
\ No newline at end of file
Property changes on: trunk/kernel/admin_templates/incs/script.js
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.17
\ No newline at end of property
+1.18
\ No newline at end of property
Index: trunk/kernel/admin_templates/incs/tree.js
===================================================================
--- trunk/kernel/admin_templates/incs/tree.js (nonexistent)
+++ trunk/kernel/admin_templates/incs/tree.js (revision 4357)
@@ -0,0 +1,349 @@
+function TreeItem(title, url, icon)
+{
+ this.Title = title;
+ this.Url = url;
+ this.Rendered = false;
+ this.Displayed = false;
+ this.Level = 0;
+ this.Icon = icon;
+}
+
+TreeItem.prototype.Render = function(before)
+{
+ if (!this.Rendered) {
+ if (!isset(before)) {before = null}
+
+ tr = document.createElement('tr');
+ this.ParentElement.insertBefore(tr, before);
+ if (!this.Displayed) { tr.style.display = 'none' }
+ td = document.createElement('td');
+ td.TreeElement = this;
+ tr.appendChild(td);
+
+ this.appendLevel(td);
+ if (this.ParentFolder != null) this.appendNodeImage(td);
+ this.appendIcon(td);
+ this.appendLink(td);
+
+ this.Tr = tr;
+ this.Rendered = true;
+ }
+}
+
+TreeItem.prototype.appendLevel = function(td)
+{
+ for (var i=0; i < this.Level; i++)
+ {
+ img = document.createElement('img');
+ img.src = TREE_ICONS_PATH+'ftv2blank.gif';
+ img.style.verticalAlign = 'middle';
+ td.appendChild(img);
+ }
+}
+
+TreeItem.prototype.getNodeImage = function(is_last)
+{
+ return is_last ? TREE_ICONS_PATH+'/ftv2lastnode.gif' : TREE_ICONS_PATH+'/ftv2node.gif';
+}
+
+TreeItem.prototype.appendNodeImage = function(td)
+{
+ img = document.createElement('img');
+ img.src = this.getNodeImage();
+ img.style.verticalAlign = 'middle';
+ td.appendChild(img);
+}
+
+TreeItem.prototype.appendIcon = function (td)
+{
+ img = document.createElement('img');
+ if (this.Icon.indexOf('http://') != -1) {
+ img.src = this.Icon;
+ }
+ else {
+ img.src = 'icons/'+this.Icon;
+ }
+ img.style.verticalAlign = 'middle';
+ td.appendChild(img);
+}
+
+TreeItem.prototype.appendLink = function (td)
+{
+ link = document.createElement('a');
+ link.nodeValue = this.Title;
+ link.href = this.Url;
+ link.target = 'main';
+ link.appendChild( document.createTextNode(this.Title) )
+ td.appendChild( link );
+// td.appendChild( document.createTextNode(this.Title) );
+}
+
+TreeItem.prototype.display = function()
+{
+ this.Tr.style.display = 'block';
+ this.Displayed = true;
+}
+
+TreeItem.prototype.hide = function()
+{
+ this.Tr.style.display = 'none';
+ this.Displayed = false;
+}
+
+TreeItem.prototype.expand = function() { this.display() }
+
+TreeItem.prototype.collapse = function() { this.hide() }
+
+TreeItem.prototype.updateLastNodes = function(is_last, lines_pattern)
+{
+ if (!isset(is_last)) is_last = true;
+ if (!isset(this.Tr)) return;
+ if (!isset(lines_pattern)) { var lines_pattern = new Array() }
+
+ imgs = this.Tr.getElementsByTagName('img');
+ found = false;
+ for (var i=0; i<imgs.length; i++)
+ {
+ the_img = imgs.item(i);
+ if (in_array(i, lines_pattern) && the_img.src.indexOf('ftv2blank.gif') != -1) {
+ the_img.src = TREE_ICONS_PATH+'/ftv2vertline.gif';
+ }
+ if (this.isNodeImage(the_img))
+ {
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ the_img.src = this.getNodeImage(is_last);
+ }
+ this.isLast = is_last;
+ return lines_pattern;
+}
+
+TreeItem.prototype.isNodeImage = function(img)
+{
+ return (
+ img.src.indexOf('ftv2node.gif') != -1 ||
+ img.src.indexOf('ftv2lastnode.gif') != -1
+ )
+
+}
+
+TreeItem.prototype.locateLastItem = function()
+{
+ return this;
+}
+/* FOLDER */
+
+function TreeFolder(parent_id, title, url, icon, late_load_url)
+{
+ var render = false;
+ if (isset(parent_id)) {
+ this.ParentElement = document.getElementById(parent_id);
+ render = true;
+ }
+
+ this.Title = title;
+ this.Url = url;
+ this.Rendered = false;
+ this.Displayed = false;
+ this.Expanded = false;
+ this.Level = 0;
+ this.Tr = null;
+ this.Icon = icon;
+ this.LateLoadURL = isset(late_load_url) ? late_load_url : false;
+ this.Loaded = false;
+
+ this.Children = new Array();
+ this.ChildIndex = 0;
+ if (render) {
+ this.Expanded = true;
+ this.Displayed = true;
+ this.Render();
+ this.expand();
+ }
+}
+
+TreeFolder.prototype = new TreeItem;
+
+TreeFolder.prototype.locateLastItem = function()
+{
+ if (this.Children.length == 0) return this;
+
+ for (var i=0; i<this.Children.length; i++)
+ {
+ last_item = this.Children[i].locateLastItem()
+ }
+ return last_item;
+}
+
+TreeFolder.prototype.locateTopItem = function()
+{
+ if (this.ParentFolder == null) return this;
+ return this.ParentFolder.locateTopItem();
+}
+
+TreeFolder.prototype.AddItem = function(an_item, render, display) {
+ an_item.ParentElement = this.ParentElement;
+ an_item.Level = this.ParentFolder != null ? this.Level + 1 : 0;
+ an_item.ParentFolder = this;
+
+ last_item = this.locateLastItem();
+ this.Children.push(an_item);
+ an_item.Render(last_item.Tr.nextSibling);
+ this.locateTopItem().updateLastNodes();
+ if (this.Expanded)
+ {
+ an_item.display();
+ }
+ return an_item;
+}
+
+TreeFolder.prototype.AddFromXML = function(xml, render)
+{
+ if (!isset(render)) render = true;
+ doc = getDocumentFromXML(xml);
+ this.LastFolder = this;
+ this.ProcessXMLNode(doc, render);
+}
+
+TreeFolder.prototype.ProcessXMLNode = function(node, render)
+{
+ if (!isset(render)) render = true;
+ if (!isset(this.LastFolder)) this.LastFolder = this;
+ for (var i=0; i<node.childNodes.length; i++)
+ {
+ child = node.childNodes.item(i);
+ if (child.tagName == 'folder') {
+ this.LastFolder = this.LastFolder.AddItem(new TreeFolder(null, child.getAttribute('name'), child.getAttribute('href'), child.getAttribute('icon'), child.getAttribute('load_url')), render);
+ if (child.hasChildNodes) {
+ this.ProcessXMLNode(child);
+ }
+ this.LastFolder = this;
+ }
+ else if (child.tagName == 'item') {
+ this.LastFolder.AddItem(new TreeItem(child.firstChild.nodeValue, child.getAttribute('href'), child.getAttribute('icon')), render)
+ }
+ else if (child.tagName == 'tree') {
+ this.ProcessXMLNode(child);
+ }
+ }
+}
+
+TreeFolder.prototype.getNodeImage = function(is_last)
+{
+ if (is_last) {
+ return this.Expanded ? TREE_ICONS_PATH+'/ftv2mlastnode.gif' : TREE_ICONS_PATH+'/ftv2plastnode.gif';
+ }
+ else {
+ return this.Expanded ? TREE_ICONS_PATH+'/ftv2mnode.gif' : TREE_ICONS_PATH+'/ftv2pnode.gif';
+ }
+}
+
+TreeFolder.prototype.appendNodeImage = function(td, is_last)
+{
+ img = document.createElement('img');
+ img.src = this.getNodeImage(is_last);
+ img.style.cursor = 'hand';
+ img.style.cursor = 'pointer';
+ img.style.verticalAlign = 'middle';
+ img.onclick = function() { this.parentNode.TreeElement.folderClick(this) }
+ this.Img = img;
+ td.appendChild(img);
+}
+
+TreeFolder.prototype.updateLastNodes = function(is_last, lines_pattern)
+{
+ if (!isset(is_last)) is_last = true;
+ if (!isset(lines_pattern)) { var lines_pattern = new Array() }
+ if (!is_last && !in_array(this.Level, lines_pattern)) { lines_pattern.push(this.Level) }
+
+ lines_pattern = TreeItem.prototype.updateLastNodes.apply(this, new Array(is_last, lines_pattern))
+
+ for (var i=0; i<this.Children.length; i++)
+ {
+ lines_pattern = this.Children[i].updateLastNodes((i+1) == this.Children.length, lines_pattern)
+ }
+ lines_pattern[array_search(this.Level, lines_pattern)] = -1;
+ return lines_pattern;
+}
+
+TreeFolder.prototype.isNodeImage = function(img)
+{
+ return (
+ img.src.indexOf('ftv2mlastnode.gif') != -1 ||
+ img.src.indexOf('ftv2plastnode.gif') != -1 ||
+ img.src.indexOf('ftv2mnode.gif') != -1 ||
+ img.src.indexOf('ftv2pnode.gif') != -1
+ )
+
+}
+
+TreeFolder.prototype.folderClick = function(img)
+{
+ if (this.LateLoadURL && !this.Loaded) {
+
+ request = getXMLHTTPObject('text/xml');
+
+ if (request && request.readyState != 0) {
+ request.abort();
+ }
+ request.open('POST', this.LateLoadURL, true);
+ request.setRequestHeader("referer", this.LateLoadURL);
+ obj = this;
+ function processLateLoad() {
+ if (request.readyState == 4) {
+ if (request.status == 200) {
+ obj.ProcessXMLNode(request.responseXML);
+ obj.Loaded = true;
+ obj.Render();
+ obj.expand();
+ }
+ }
+ }
+ request.onreadystatechange = processLateLoad;
+ request.send('is_xml=1');
+ }
+
+ if (this.Expanded) {
+ this.collapse();
+ }
+ else {
+ this.expand();
+ }
+}
+
+TreeFolder.prototype.expand = function(mode)
+{
+ if (!isset(mode)) mode = 0;
+ this.display();
+ if (mode == 0 || this.Expanded ) {
+ for (var i=0; i<this.Children.length; i++)
+ {
+ this.Children[i].expand(mode+1);
+ }
+ }
+ if (mode == 0) {
+ this.Expanded = true;
+ if (isset(this.Img)) {
+ this.Img.src = this.getNodeImage(this.isLast);
+ }
+ }
+}
+
+TreeFolder.prototype.collapse = function(mode)
+{
+ if (!isset(mode)) mode = 0;
+ for (var i=0; i<this.Children.length; i++)
+ {
+ this.Children[i].collapse(mode+1);
+ this.Children[i].hide();
+ }
+ if (mode == 0) {
+ this.Expanded = false;
+ if (isset(this.Img)) {
+ this.Img.src = this.getNodeImage(this.isLast);
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/kernel/admin_templates/incs/tree.js
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/kernel/processors/main_processor.php
===================================================================
--- trunk/core/kernel/processors/main_processor.php (revision 4356)
+++ trunk/core/kernel/processors/main_processor.php (revision 4357)
@@ -1,899 +1,911 @@
<?php
class kMainTagProcessor extends TagProcessor {
function Init($prefix,$special)
{
parent::Init($prefix,$special);
$actions =& $this->Application->recallObject('kActions');
$actions->Set('t', $this->Application->GetVar('t'));
$actions->Set('sid', $this->Application->GetSID());
$actions->Set('m_opener', $this->Application->GetVar('m_opener') );
}
/**
* Used to handle calls where tag name
* match with existing php function name
*
* @param Tag $tag
* @return string
*/
function ProcessTag(&$tag)
{
if ($tag->Tag=='include') $tag->Tag='MyInclude';
return parent::ProcessTag($tag);
}
/**
* Creates <base href ..> HTML tag for all templates
* affects future css, js files and href params of links
*
* @return string
* @access public
*/
function Base_Ref()
{
$url = $this->Application->BaseURL().substr(THEMES_PATH,1).'/';
return '<base href="'.$url.'" />';
}
/**
* Returns base url for web-site
*
* @return string
* @access public
*/
function BaseURL()
{
return $this->Application->BaseURL();
}
function TemplatesBase($params)
{
return $this->Application->BaseURL().THEMES_PATH;
}
function ProjectBase($params)
{
return $this->Application->BaseURL();
}
/*function Base($params)
{
return $this->Application->BaseURL().$params['add'];
}*/
/**
* Used to create link to any template.
* use "pass" paramter if "t" tag to specify
* prefix & special of object to be represented
* in resulting url
*
* @param Array $params
* @return string
* @access public
*/
function T($params)
{
//by default link to current template
$t = $this->SelectParam($params, 't,template');
unset($params['t']);
unset($params['template']);
$prefix=isset($params['prefix']) ? $params['prefix'] : ''; unset($params['prefix']);
$index_file = isset($params['index_file']) ? $params['index_file'] : null; unset($params['index_file']);
return $this->Application->HREF($t, $prefix, $params, $index_file);
}
function Link($params)
{
if (isset($params['template'])) {
$params['t'] = $params['template'];
unset($params['template']);
}
if (!isset($params['pass']) && !isset($params['no_pass'])) $params['pass'] = 'm';
if (isset($params['no_pass'])) unset($params['no_pass']);
if( $this->Application->GetVar('admin') ) $params['admin'] = 1;
return $this->T($params);
}
function Env($params)
{
$t = $params['template'];
unset($params['template']);
return $this->Application->BuildEnv($t, $params, 'm', null, false);
}
function FormAction($params)
{
return $this->Application->ProcessParsedTag('m', 't', Array( 'pass'=>'all,m' ) );
}
/*// NEEDS TEST
function Config($params)
{
return $this->Application->ConfigOption($params['var']);
}
function Object($params)
{
$name = $params['name'];
$method = $params['method'];
$tmp =& $this->Application->recallObject($name);
if ($tmp != null) {
if (method_exists($tmp, $method))
return $tmp->$method($params);
else
echo "Method $method does not exist in object ".get_class($tmp)." named $name<br>";
}
else
echo "Object $name does not exist in the appliaction<br>";
}*/
/**
* Tag, that always returns true.
* For parser testing purposes
*
* @param Array $params
* @return bool
* @access public
*/
function True($params)
{
return true;
}
/**
* Tag, that always returns false.
* For parser testing purposes
*
* @param Array $params
* @return bool
* @access public
*/
function False($params)
{
return false;
}
/**
* Returns block parameter by name
*
* @param Array $params
* @return stirng
* @access public
*/
function Param($params)
{
//$parser =& $this->Application->recallObject('TemplateParser');
$res = $this->Application->Parser->GetParam($params['name']);
if ($res === false) $res = '';
if (isset($params['plus']))
$res += $params['plus'];
return $res;
}
/**
* Gets value of specified field from specified prefix_special and set it as parser param
*
* @param Array $params
*/
/*function SetParam($params)
{
// <inp2:m_SetParam param="custom_name" src="cf:FieldName"/>
list($prefix_special, $field_name) = explode(':', $params['src']);
-
+
$object =& $this->Application->recallObject($prefix_special);
$name = $this->SelectParam($params, 'param,name,var');
-
+
$this->Application->Parser->SetParam($name, $object->GetField($field_name) );
}*/
-
+
/**
* Compares block parameter with value specified
*
* @param Array $params
* @return bool
* @access public
*/
function ParamEquals($params)
{
//$parser =& $this->Application->recallObject('TemplateParser');
$name = $this->SelectParam($params, 'name,var,param');
$value = $params['value'];
return ($this->Application->Parser->GetParam($name) == $value);
}
/*function PHP_Self($params)
{
return $HTTP_SERVER_VARS['PHP_SELF'];
}
*/
/**
* Returns session variable value by name
*
* @param Array $params
* @return string
* @access public
*/
function Recall($params)
{
$ret = $this->Application->RecallVar( $this->SelectParam($params,'name,var,param') );
$ret = ($ret === false && isset($params['no_null'])) ? '' : $ret;
if( getArrayValue($params,'special') || getArrayValue($params,'htmlchars')) $ret = htmlspecialchars($ret);
if ( getArrayValue($params, 'urlencode') ) $ret = urlencode($ret);
return $ret;
}
// bad style to store something from template to session !!! (by Alex)
// Used here only to test how session works, nothing more
function Store($params)
{
//echo"Store $params[name]<br>";
$name = $params['name'];
$value = $params['value'];
$this->Application->StoreVar($name,$value);
}
/**
* Sets application variable value(-s)
*
* @param Array $params
* @access public
*/
function Set($params)
{
foreach ($params as $param => $value) {
$this->Application->SetVar($param, $value);
}
}
/**
* Increment application variable
* specified by number specified
*
* @param Array $params
* @access public
*/
function Inc($params)
{
$this->Application->SetVar($params['param'], $this->Application->GetVar($params['param']) + $params['by']);
}
/**
* Retrieves application variable
* value by name
*
* @param Array $params
* @return string
* @access public
*/
function Get($params)
{
$ret = $this->Application->GetVar($this->SelectParam($params, 'name,var,param'), '');
return getArrayValue($params, 'htmlchars') ? htmlspecialchars($ret) : $ret;
}
/**
* Retrieves application constant
* value by name
*
* @param Array $params
* @return string
* @access public
*/
function GetConst($params)
{
return defined($this->SelectParam($params, 'name,const')) ? constant($this->SelectParam($params, 'name,const,param')) : '';
}
/**
* Retrieves configuration variable value by name
*
* @param Array $params
* @return string
* @access public
*/
function GetConfig($params)
{
$config_name = $this->SelectParam($params, 'name,var');
$ret = $this->Application->ConfigValue($config_name);
if( getArrayValue($params, 'escape') ) $ret = addslashes($ret);
return $ret;
}
function ConfigEquals($params)
{
$option = $this->SelectParam($params, 'name,option,var');
return $this->Application->ConfigValue($option) == getArrayValue($params, 'value');
}
/**
* Creates all hidden fields
* needed for kernel_form
*
* @param Array $params
* @return string
* @access public
*/
function DumpSystemInfo($params)
{
$actions =& $this->Application->recallObject('kActions');
$actions->Set('t', $this->Application->GetVar('t') );
$params = $actions->GetParams();
$o='';
foreach ($params AS $name => $val)
{
$o .= "<input type='hidden' name='$name' id='$name' value='$val'>\n";
}
return $o;
}
function GetFormHiddens($params)
{
$sid = $this->Application->GetSID();
$t = $this->SelectParam($params, 'template,t');
unset($params['template']);
$env = $this->Application->BuildEnv($t, $params, 'm', null, false);
$o = '';
if ( $this->Application->RewriteURLs() )
{
$session =& $this->Application->recallObject('Session');
if ($session->NeedQueryString()) {
$o .= "<input type='hidden' name='sid' id='sid' value='$sid'>\n";
}
}
else {
$o .= "<input type='hidden' name='env' id='env' value='$env'>\n";
}
return $o;
}
function Odd_Even($params)
{
$odd = $params['odd'];
$even = $params['even'];
if (!isset($params['var'])) {
$var = 'odd_even';
}
else {
$var = $params['var'];
}
if ($this->Application->GetVar($var) == 'even') {
if (!isset($params['readonly']) || !$params['readonly']) {
$this->Application->SetVar($var, 'odd');
}
return $even;
}
else {
if (!isset($params['readonly']) || !$params['readonly']) {
$this->Application->SetVar($var, 'even');
}
return $odd;
}
}
/**
* Returns phrase translation by name
*
* @param Array $params
* @return string
* @access public
*/
function Phrase($params)
{
// m:phrase name="phrase_name" default="Tr-alala" updated="2004-01-29 12:49"
if (array_key_exists('default', $params)) return $params['default']; //backward compatibility
$translation = $this->Application->Phrase($this->SelectParam($params, 'label,name,title'));
if (getArrayValue($params, 'escape')) {
$translation = htmlspecialchars($translation);
$translation = str_replace('\'', ''', $translation);
$translation = addslashes($translation);
}
return $translation;
}
// for tabs
function is_active($params)
{
$test_templ = $this->SelectParam($params, 'templ,template,t');
if ( !getArrayValue($params,'allow_empty') )
{
$if_true=getArrayValue($params,'true') ? $params['true'] : 1;
$if_false=getArrayValue($params,'false') ? $params['false'] : 0;
}
else
{
$if_true=$params['true'];
$if_false=$params['false'];
}
if ( preg_match("/^".str_replace('/', '\/', $test_templ)."/", $this->Application->GetVar('t'))) {
return $if_true;
}
else {
return $if_false;
}
}
function IsNotActive($params)
{
return !$this->is_active($params);
}
function IsActive($params)
{
return $this->is_active($params);
}
function is_t_active($params)
{
return $this->is_active($params);
}
function CurrentTemplate($params)
{
return $this->is_active($params);
}
/**
* Checks if session variable
* specified by name value match
* value passed as parameter
*
* @param Array $params
* @return string
* @access public
*/
function RecallEquals($params)
{
$name = $this->SelectParam($params, 'name,var');
$value = $params['value'];
return ($this->Application->RecallVar($name) == $value);
}
/**
* Checks if application variable
* specified by name value match
* value passed as parameter
*
* @param Array $params
* @return bool
* @access public
*/
function GetEquals($params)
{
$name = $this->SelectParam($params, 'var,name,param');
$value = $params['value'];
if ($this->Application->GetVar($name) == $value) {
return 1;
}
}
/**
* Includes template
* and returns it's
* parsed version
*
* @param Array $params
* @return string
* @access public
*/
function MyInclude($params)
{
$BlockParser =& $this->Application->makeClass('TemplateParser');
$BlockParser->SetParams($params);
$parser =& $this->Application->Parser;
$this->Application->Parser =& $BlockParser;
$t = $this->SelectParam($params, 't,template,block,name');
$t = eregi_replace("\.tpl$", '', $t);
-
+
$templates_cache =& $this->Application->recallObject('TemplatesCache');
$res = $BlockParser->Parse( $templates_cache->GetTemplateBody($t, getArrayValue($params, 'is_silent')), $t );
if ( !$BlockParser->DataExists && (isset($params['data_exists']) || isset($params['block_no_data'])) ) {
if ($block_no_data = getArrayValue($params, 'block_no_data')) {
$res = $BlockParser->Parse(
$templates_cache->GetTemplateBody($block_no_data, getArrayValue($params, 'is_silent') ),
$t
);
}
else {
$res = '';
}
}
$this->Application->Parser =& $parser;
$this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists;
return $res;
}
function ModuleInclude($params)
{
$ret = '';
$block_params = Array('is_silent' => 1); // don't make fatal errors in case if template is missing
$current_template = $this->Application->GetVar('t');
foreach ($this->Application->ModuleInfo as $module_name => $module_data) {
if (!$module_data['Loaded']) continue;
$module_key = strtolower($module_name);
if ($module_name == 'In-Portal') {
$module_prefix = '';
}
else {
$module_prefix = $this->Application->IsAdmin() ? $module_key.'/' : $module_data['TemplatePath'].'/';
}
$block_params['t'] = $module_prefix.$this->SelectParam($params, $module_key.'_template,'.$module_key.'_t,template,t');
if ($block_params['t'] == $current_template) continue;
$no_data = $this->SelectParam($params, $module_key.'_block_no_data,block_no_data');
if ($no_data) {
$block_params['block_no_data'] = $module_prefix.'/'.$no_data;
}
$ret .= $this->MyInclude($block_params);
}
return $ret;
}
/*function Kernel_Scripts($params)
{
return '<script type="text/javascript" src="'.PROTOCOL.SERVER_NAME.BASE_PATH.'/kernel3/js/grid.js"></script>';
}*/
/*function GetUserPermission($params)
{
// echo"GetUserPermission $params[name]";
if ($this->Application->RecallVar('user_type') == 1)
return 1;
else {
$perm_name = $params[name];
$aPermissions = unserialize($this->Application->RecallVar('user_permissions'));
if ($aPermissions)
return $aPermissions[$perm_name];
}
}*/
/**
* Set's parser block param value
*
* @param Array $params
* @access public
*/
function AddParam($params)
{
$parser =& $this->Application->Parser; // recallObject('TemplateParser');
foreach ($params as $param => $value) {
$this->Application->SetVar($param, $value);
$parser->SetParam($param, $value);
$parser->AddParam('/\$'.$param.'/', $value);
}
}
/*function ParseToVar($params)
{
$var = $params['var'];
$tagdata = $params['tag'];
$parser =& $this->Application->Parser; //recallObject('TemplateParser');
$res = $this->Application->ProcessTag($tagdata);
$parser->SetParam($var, $res);
$parser->AddParam('/\$'.$var.'/', $res);
return '';
}*/
/*function TagNotEmpty($params)
{
$tagdata = $params['tag'];
$res = $this->Application->ProcessTag($tagdata);
return $res != '';
}*/
/*function TagEmpty($params)
{
return !$this->TagNotEmpty($params);
}*/
/**
* Parses block and returns result
*
* @param Array $params
* @return string
* @access public
*/
function ParseBlock($params)
{
$parser =& $this->Application->Parser; // recallObject('TemplateParser');
return $parser->ParseBlock($params);
}
function RenderElement($params)
{
return $this->ParseBlock($params);
}
/**
* Checks if debug mode is on
*
* @return bool
* @access public
*/
function IsDebugMode()
{
return $this->Application->isDebugMode();
}
function MassParse($params)
{
$qty = $params['qty'];
$block = $params['block'];
$mode = $params['mode'];
$o = '';
if ($mode == 'func') {
$func = create_function('$params', '
$o = \'<tr>\';
$o.= \'<td>a\'.$params[\'param1\'].\'</td>\';
$o.= \'<td>a\'.$params[\'param2\'].\'</td>\';
$o.= \'<td>a\'.$params[\'param3\'].\'</td>\';
$o.= \'<td>a\'.$params[\'param4\'].\'</td>\';
$o.= \'</tr>\';
return $o;
');
for ($i=1; $i<$qty; $i++) {
$block_params['param1'] = rand(1, 10000);
$block_params['param2'] = rand(1, 10000);
$block_params['param3'] = rand(1, 10000);
$block_params['param4'] = rand(1, 10000);
$o .= $func($block_params);
}
return $o;
}
$block_params['name'] = $block;
for ($i=0; $i<$qty; $i++) {
$block_params['param1'] = rand(1, 10000);
$block_params['param2'] = rand(1, 10000);
$block_params['param3'] = rand(1, 10000);
$block_params['param4'] = rand(1, 10000);
$block_params['passed'] = $params['passed'];
$block_params['prefix'] = 'm';
$o.= $this->Application->ParseBlock($block_params, 1);
}
return $o;
}
function AfterScript($params)
{
$after_script = $this->Application->GetVar('after_script');
if ( $after_script ) {
return '<script type="text/javascript">'.$after_script.'</script>';
}
return '';
}
function LoggedIn($params)
{
return $this->Application->LoggedIn();
}
/**
* Checks if user is logged in and if not redirects it to template passed
*
* @param Array $params
*/
function RequireLogin($params)
{
+ $t = $this->Application->GetVar('t');
+ if ($next_t = getArrayValue($params, 'next_template')) {
+ $t = $next_t;
+ }
+
if($permission_groups = getArrayValue($params, 'permissions'))
{
$permission_groups = explode('|', $permission_groups);
$group_has_permission = false;
foreach($permission_groups as $permission_group)
{
$permissions = explode(',', $permission_group);
$has_permission = true;
foreach($permissions as $permission)
{
$has_permission = $has_permission && $this->Application->CheckPermission($permission);
}
$group_has_permission = $group_has_permission || $has_permission;
if($group_has_permission)
{
return;
}
}
if( !$this->Application->LoggedIn() )
{
- $t = $this->Application->GetVar('t');
- $this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
+ $this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
}
else
{
$this->Application->Redirect( $params['no_permissions_template'] );
}
}
$condition = getArrayValue($params,'condition');
if(!$condition)
{
$condition = true;
}
else
{
if( substr($condition,0,1) == '!' )
{
$condition = !$this->Application->ConfigValue( substr($condition,1) );
}
else
{
$condition = $this->Application->ConfigValue($condition);
}
}
$group = $this->SelectParam($params, 'group');
$group_access = true;
if ($group) {
$conn =& $this->Application->DB;
$group_id = $conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'PortalGroup WHERE Name = '.$conn->qstr($group));
if ($group_id) {
$groups = explode(',', $this->Application->RecallVar('UserGroups'));
$group_access = in_array($group_id, $groups);
}
}
if( (!$this->Application->LoggedIn() || !$group_access) && $condition )
{
- $t = $this->Application->GetVar('t');
+ if ( $this->Application->LoggedIn() && !$group_access) {
+ $this->Application->Redirect( $params['no_group_perm_template'], Array('next_template'=>$t) );
+ }
$this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
}
}
/**
* Checks if SSL is on and redirects to SSL URL if needed
* If SSL_URL is not defined in config - the tag does not do anything
* If for_logged_in_only="1" exits if user is not logged in.
* If called without params forces https right away. If called with by_config="1" checks the
* Require SSL setting from General Config and if it is ON forces https
*
* @param unknown_type $params
*/
function CheckSSL($params)
{
$ssl = $this->Application->ConfigValue('SSL_URL');
if (!$ssl) return; //SSL URL is not set - no way to require SSL
$require = false;
if ($params['mode'] == 'required') {
$require = true;
if (isset($params['for_logged_in_only']) && $params['for_logged_in_only'] && !$this->Application->LoggedIn()) {
$require = false;
}
if (isset($params['condition'])) {
if (!$this->Application->ConfigValue($params['condition'])) {
$require = false;
}
}
}
$http_query =& $this->Application->recallObject('HTTPQuery');
$pass = $http_query->getRedirectParams();
if ($require) {
if (PROTOCOL == 'https://') {
$this->Application->SetVar('__KEEP_SSL__', 1);
return;
}
$this->Application->Redirect('', array_merge_recursive2($pass, Array('__SSL__' => 1)));
}
else {
if (PROTOCOL == 'https://' && $this->Application->ConfigValue('Force_HTTP_When_SSL_Not_Required')) {
if ($this->Application->GetVar('__KEEP_SSL__')) return;
$this->Application->Redirect('', array_merge_recursive2($pass, Array('__SSL__' => 0)));
}
}
}
function SaveReturnScript($params)
{
// admin/save_redirect.php?do=
$url = str_replace($this->Application->BaseURL(), '', $this->Link($params) );
$url = explode('?', $url, 2);
$url = 'save_redirect.php?'.$url[1].'&do='.$url[0];
$this->Application->StoreVar('ReturnScript', $url);
}
function ConstOn($params)
{
$name = $this->SelectParam($params,'name,const');
return ConstOn($name);
}
function SetDefaultCategory($params)
{
$module_name = $params['module'];
$module =& $this->Application->recallObject('mod.'.$module_name);
$this->Application->SetVar('m_cat_id', $module->GetDBField('RootCat') );
}
-
+
function ImportRedirect($params)
{
$import_id = $this->Application->GetVar('import_id');
if ($import_id) {
// redirect forward to step3 (import parameters coosing)
$this->Application->StoreVar('ImportScriptID', $import_id);
-
+
$sql = 'SELECT *
FROM '.TABLE_PREFIX.'ImportScripts
WHERE is_id = '.$import_id;
-
+
$db =& $this->Application->GetADODBConnection();
$is_params = $db->GetRow($sql);
-
+
if ($is_params['is_type'] == 'db') {
$this->Application->Redirect('', null, '', 'import/step3.php');
}
elseif ($is_params['is_type'] == 'csv') {
$module = strtolower($is_params['is_Module']);
$template = $module.'/import';
$sql = 'SELECT Var
FROM '.TABLE_PREFIX.'Modules
WHERE LOWER(Name) = '.$db->qstr($module);
$item_prefix = $db->GetOne($sql);
$pass_params = Array('m_opener' => 'd', $item_prefix.'.import_id' => 0, $item_prefix.'.import_event' => 'OnNew', 'pass' => 'm,'.$item_prefix.'.import');
$this->Application->Redirect($template, $pass_params);
}
}
else {
// redirect back to step2 (import type choosing)
$this->Application->Redirect('', null, '', 'import/step2.php');
}
}
function GetSectionTitle($params)
{
$params['name'] = replaceModuleSection($params['phrase']);
return $this->Phrase($params);
}
function GetSectionIcon($params)
{
return replaceModuleSection($params['icon']);
}
-
+
function StoreSystemVars($params)
{
// save theese variables to session, because they are useful for most configuration templates
$this->Application->LinkVar('module');
$this->Application->LinkVar('section');
}
function StoreMainPrefix($params)
{
$this->Application->LinkVar('main_prefix'); // window prefix, that opener selector
$this->Application->LinkVar('dst_field'); // field to set value choosed in selector
$this->Application->LinkVar('return_template'); // template to go, when something was coosen from popup (from finalizePopup)
+ }
+
+ function XMLTemplate($params)
+ {
+ define('DBG_SKIP_REPORTING', 1);
+ header('Content-type: text/xml');
}
}
?>
Property changes on: trunk/core/kernel/processors/main_processor.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.42
\ No newline at end of property
+1.43
\ No newline at end of property
Event Timeline
Log In to Comment