Example #1
0
 function HTML_QuickForm_commondata($elementName = null, $elementLabel = null, $commondata = null, $options = null, $attributes = null)
 {
     $this->HTML_QuickForm_select($elementName, $elementLabel, array(), $attributes);
     $this->_persistantFreeze = true;
     $this->_type = 'commondata';
     $this->_appendName = true;
     if (isset($commondata)) {
         if (is_array($commondata)) {
             $this->_cd = $commondata;
         } elseif (is_string($commondata)) {
             $this->_cd = array($commondata);
         }
     }
     if (isset($options['empty_option'])) {
         $this->_add_empty_fields = $options['empty_option'];
     }
     if (isset($options['order_by_key'])) {
         $this->_order_by_key = $options['order_by_key'];
     }
     if (count($this->_cd) == 1) {
         $root_data = Utils_CommonDataCommon::get_translated_array($this->_cd[0], $this->_order_by_key);
         if ($this->_add_empty_fields) {
             $root_data = array('' => '---') + $root_data;
         }
         $this->loadArray($root_data);
     }
 }
Example #2
0
 public static function status_filter($rb)
 {
     $sts = Utils_CommonDataCommon::get_translated_array('CRM/Status', true);
     $trans = array('__NULL__' => array(), '__NO_CLOSED__' => array('!status' => array(3, 4)));
     foreach ($sts as $k => $v) {
         $trans[$k] = array('status' => $k);
     }
     $rb->set_custom_filter('status', array('type' => 'select', 'label' => __('Status'), 'args' => array('__NULL__' => '[' . __('All') . ']', '__NO_CLOSED__' => '[' . __('Not closed') . ']') + $sts, 'trans' => $trans));
 }
Example #3
0
 public static function user_settings($settings_edit = false)
 {
     if ($settings_edit) {
         Base_ActionBarCommon::add(Base_ThemeCommon::get_template_file('Base_Notify', 'icon.png'), __('Browser Settings'), 'onClick="Base_Notify__notify (\'Notification\', {body: \'enabled\', icon: \'' . self::get_icon('Base_Notify') . '\'}, true);"', __('Click to set browser settings for tray notifications'));
     }
     $ret = array(array('name' => null, 'label' => __('General'), 'type' => 'header'), array('name' => 'general_timeout', 'reload' => 1, 'label' => __('Close Message Timeout'), 'type' => 'select', 'values' => Utils_CommonDataCommon::get_translated_array('Base_Notify/Timeout', true), 'default' => 0), array('name' => 'general_group', 'label' => __('Group Similar Notifications'), 'type' => 'checkbox', 'default' => 1), array('name' => null, 'label' => __('Module Specific Timeout'), 'type' => 'header'));
     $modules = ModuleManager::check_common_methods('tray_notification');
     foreach ($modules as $module) {
         $label = self::get_module_caption($module);
         $ret = array_merge($ret, array(array('name' => $module . '_timeout', 'label' => $label, 'type' => 'select', 'values' => array(-2 => _M('Use general setting')) + Utils_CommonDataCommon::get_translated_array('Base_Notify/Timeout', true), 'default' => -2)));
     }
     return array(__('Notify') => $ret);
 }
Example #4
0
 public static function drawLeightbox($prefix)
 {
     if (MOBILE_DEVICE) {
         return;
     }
     $meetings = CRM_MeetingInstall::is_installed();
     $tasks = CRM_TasksInstall::is_installed();
     $phonecall = CRM_PhoneCallInstall::is_installed();
     self::check_location();
     if (!isset(self::$leightbox_ready[$prefix])) {
         self::$leightbox_ready[$prefix] = true;
         $theme = Base_ThemeCommon::init_smarty();
         eval_js_once($prefix . '_followups_deactivate = function(){leightbox_deactivate(\'' . $prefix . '_followups_leightbox\');}');
         if ($meetings) {
             $theme->assign('new_meeting', array('open' => '<a id="' . $prefix . '_new_meeting_button" onclick="' . $prefix . '_set_action(\'new_meeting\');' . $prefix . '_submit_form();">', 'text' => __('New Meeting'), 'close' => '</a>'));
             eval_js('Event.observe(\'' . $prefix . '_new_meeting_button\',\'click\', ' . $prefix . '_followups_deactivate)');
         }
         if ($tasks) {
             $theme->assign('new_task', array('open' => '<a id="' . $prefix . '_new_task_button" onclick="' . $prefix . '_set_action(\'new_task\');' . $prefix . '_submit_form();">', 'text' => __('New Task'), 'close' => '</a>'));
             eval_js('Event.observe(\'' . $prefix . '_new_task_button\',\'click\', ' . $prefix . '_followups_deactivate)');
         }
         if ($phonecall) {
             $theme->assign('new_phonecall', array('open' => '<a id="' . $prefix . '_new_phonecall_button" onclick="' . $prefix . '_set_action(\'new_phonecall\');' . $prefix . '_submit_form();">', 'text' => __('New Phonecall'), 'close' => '</a>'));
             eval_js('Event.observe(\'' . $prefix . '_new_phonecall_button\',\'click\', ' . $prefix . '_followups_deactivate)');
         }
         $theme->assign('just_close', array('open' => '<a id="' . $prefix . '_just_close_button" onclick="' . $prefix . '_set_action(\'none\');' . $prefix . '_submit_form();">', 'text' => __('Save'), 'close' => '</a>'));
         eval_js('Event.observe(\'' . $prefix . '_just_close_button\',\'click\', ' . $prefix . '_followups_deactivate)');
         eval_js($prefix . '_submit_form = function () {' . '$(\'' . $prefix . '_follow_up_form\').submited.value=1;Epesi.href($(\'' . $prefix . '_follow_up_form\').serialize(), \'processing...\');$(\'' . $prefix . '_follow_up_form\').submited.value=0;' . '}');
         eval_js($prefix . '_set_action = function (arg) {' . 'document.forms["' . $prefix . '_follow_up_form"].action.value = arg;' . '}');
         eval_js($prefix . '_set_id = function (id) {' . 'document.forms["' . $prefix . '_follow_up_form"].id.value = id;' . '$("' . $prefix . '_closecancel").value=3;' . '$("' . $prefix . '_note").value="";' . '}');
         $theme->assign('form_open', '<form id="' . $prefix . '_follow_up_form" name="' . $prefix . '_follow_up_form" method="POST">' . '<input type="hidden" name="submited" value="0" />' . '<input type="hidden" name="form_name" value="' . $prefix . '_follow_up_form" />' . '<input type="hidden" name="id" value="" />' . '<input type="hidden" name="action" value="" />');
         $status_select_options = '';
         $statuses = Utils_CommonDataCommon::get_translated_array('CRM/Status');
         foreach ($statuses as $key => $value) {
             $status_select_options .= '<option value="' . htmlspecialchars($key) . '"' . ($key == 3 ? ' selected="1"' : '') . '>' . htmlspecialchars($value) . '</option>';
         }
         $theme->assign('form_closecancel', array('label' => __('Status'), 'html' => '<select name="closecancel" id="' . $prefix . '_closecancel" value="0">' . $status_select_options . '</select>'));
         $theme->assign('form_note', array('label' => __('Note'), 'html' => '<textarea name="note" id="' . $prefix . '_note"></textarea>'));
         $theme->assign('form_close', '</form>');
         ob_start();
         Base_ThemeCommon::display_smarty($theme, 'CRM_Followup', 'leightbox');
         $profiles_out = ob_get_clean();
         Libs_LeightboxCommon::display($prefix . '_followups_leightbox', $profiles_out, __('Follow-up'));
     }
 }
Example #5
0
 public static function user_settings()
 {
     if (!Base_EpesiStoreCommon::admin_access()) {
         return array();
     }
     set_time_limit(0);
     // get default data from user contact
     $my_contact = ModuleManager::is_installed('CRM_Contacts') > -1 ? CRM_ContactsCommon::get_my_record() : array();
     // key = field name from contact => value = field name in settings
     $keys = self::get_payment_data_keys();
     $values = array();
     // do user setting entries from data
     foreach ($keys as $k => $v) {
         $x = array('name' => $v, 'label' => _V(ucwords(str_replace('_', ' ', $v))), 'type' => 'text', 'default' => isset($my_contact[$k]) ? $my_contact[$k] : '');
         if ($k == 'country') {
             $x['type'] = 'select';
             $x['values'] = Utils_CommonDataCommon::get_translated_array('Countries');
         }
         $values[] = $x;
     }
     return array(__('EPESI Store') => array_merge(array(array('name' => 'payments_header', 'label' => '', 'type' => 'header', 'default' => __('Payment credentials'))), $values));
 }
Example #6
0
 protected function hf_commondata($field, $operator, $value, $raw_sql_val, $field_def)
 {
     list($field, $sub_field) = Utils_RecordBrowser_CritsSingle::parse_subfield($field);
     if ($raw_sql_val) {
         return array("{$field} {$operator} {$value}", array());
     }
     if ($value === null || $value === false || $value === '') {
         return array("{$field} IS NULL OR {$field}=''", array());
     }
     if (!isset($field_def['ref_table'])) {
         // commondata type doesn't have this, only select/multiselect
         $field_def['ref_table'] = $field_def['param']['array_id'];
     }
     if ($sub_field !== false) {
         // may be empty string for value lookup with field[]
         $commondata_table = $field_def['ref_table'];
         $ret = Utils_CommonDataCommon::get_translated_array($commondata_table);
         $val_regex = $operator == DB::like() ? '/' . preg_quote($value, '/') . '/i' : '/^' . preg_quote($value, '/') . '$/i';
         $final_vals = array_keys(preg_grep($val_regex, $ret));
         if ($operator == DB::like()) {
             $operator = '=';
         }
     } else {
         $final_vals = array($value);
     }
     $multiselect = $field_def['type'] == 'multiselect';
     if ($multiselect) {
         $operator = DB::like();
     }
     $sql = array();
     $vals = array();
     foreach ($final_vals as $val) {
         $sql[] = "({$field} {$operator} %s AND {$field} IS NOT NULL)";
         if ($multiselect) {
             $val = "%\\_\\_{$val}\\_\\_%";
         }
         $vals[] = $val;
     }
     $sql_str = implode(' OR ', $sql);
     return array($sql_str, $vals);
 }
Example #7
0
 public function construct()
 {
     self::$access = Utils_CommonDataCommon::get_translated_array('CRM/Access');
     self::$priority = Utils_CommonDataCommon::get_translated_array('CRM/Priority');
 }
Example #8
0
 public static function get_translated_tree($col, $order_by_key = false, $deep = 0)
 {
     $data = Utils_CommonDataCommon::get_translated_array($col, $order_by_key, false, true);
     if (!$data) {
         return array();
     }
     $output = array();
     foreach ($data as $k => $v) {
         $output[$k] = $v;
         $sub = self::get_translated_tree($col . '/' . $k, $order_by_key, $deep + 1);
         if ($sub) {
             foreach ($sub as $k2 => $v2) {
                 $output[$k . '/' . $k2] = '* ' . $v2;
             }
         }
     }
     return $output;
 }
Example #9
0
 public static function get()
 {
     return Utils_CommonDataCommon::get_translated_array('Countries');
 }
Example #10
0
 /**
  * For internal use only.
  */
 public function browse($name = '', $root = true)
 {
     if ($this->is_back()) {
         return false;
     }
     if (isset($_REQUEST['node_position'])) {
         list($node_id, $position) = $_REQUEST['node_position'];
         Utils_CommonDataCommon::change_node_position($node_id, $position);
     }
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'browse' . md5($name));
     $gb->set_table_columns(array(array('name' => __('Position'), 'width' => 5, 'order' => 'position'), array('name' => __('Key'), 'width' => 20, 'order' => 'akey', 'search' => 1, 'quickjump' => 'akey'), array('name' => __('Value'), 'width' => 20, 'order' => 'value', 'search' => 1)));
     print '<h2>' . $name . '</h2><br>';
     $ret = Utils_CommonDataCommon::get_translated_array($name, true, true);
     foreach ($ret as $k => $v) {
         $gb_row = $gb->get_new_row();
         $gb_row->add_data($v['position'], $k, $v['value']);
         // ****** CommonData value translation
         $gb_row->add_action($this->create_callback_href(array($this, 'browse'), array($name . '/' . $k, false)), 'View');
         if (!$v['readonly']) {
             $gb_row->add_action($this->create_callback_href(array($this, 'edit'), array($name, $k)), 'Edit');
             $gb_row->add_action($this->create_confirm_callback_href(__('Delete array') . ' \'' . Epesi::escapeJS($name . '/' . $k, false) . '\'?', array('Utils_CommonData', 'remove_array'), array($name . '/' . $k)), 'Delete');
         }
         $node_id = $v['id'];
         $gb_row->add_action('class="move-handle"', 'Move', __('Drag to change node order'), 'move-up-down');
         $gb_row->set_attrs("node=\"{$node_id}\" class=\"sortable\"");
     }
     $gb->set_default_order(array(__('Position') => 'ASC'));
     //$this->display_module($gb);
     $this->display_module($gb, array(true), 'automatic_display');
     // sorting
     load_js($this->get_module_dir() . 'sort_nodes.js');
     $table_md5 = md5($gb->get_path());
     eval_js("utils_commondata_sort_nodes_init(\"{$table_md5}\")");
     Base_ActionBarCommon::add('settings', __('Reset Order By Key'), $this->create_callback_href(array('Utils_CommonDataCommon', 'reset_array_positions'), $name));
     Base_ActionBarCommon::add('add', __('Add array'), $this->create_callback_href(array($this, 'edit'), $name));
     if (!$root) {
         Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href());
     }
     return true;
 }
Example #11
0
<?php

/**
 * @author       Paul Bukowski <*****@*****.**>
 * @copyright Copyright &copy; 2006, Telaxus LLC
 * @version 1.0
 * @license MIT
 * @package epesi-utils
 * @subpackage CommonData
 */
if (!isset($_POST['value'])) {
    die('alert(\'Invalid request\')');
}
define('JS_OUTPUT', 1);
define('CID', false);
require_once '../../../include.php';
ModuleManager::load_modules();
if (!Base_AclCommon::is_user()) {
    die('alert(\'Invalid request\')');
}
$order = isset($_POST['order']) ? $_POST['order'] : false;
$ret = Utils_CommonDataCommon::get_translated_array($_POST['value'], $order);
if (!$ret) {
    $ret = array();
}
print json_encode($ret);
exit;
Example #12
0
	/**
	 * For internal use only.
	 */
	public function browse($name='',$root=true){
		if($this->is_back()) return false;

		$gb = $this->init_module('Utils/GenericBrowser',null,'browse'.md5($name));

		$gb->set_table_columns(array(
						array('name'=>__('Key'),'width'=>20, 'order'=>'akey','search'=>1,'quickjump'=>'akey'),
						array('name'=>__('Value'),'width'=>20, 'order'=>'value','search'=>1)
					));

		print('<h2>'.$name.'</h2><br>');
		$ret = Utils_CommonDataCommon::get_translated_array($name,true,true);
		foreach($ret as $k=>$v) {
			$gb_row = $gb->get_new_row();
			$gb_row->add_data($k,$v['value']); // ****** CommonData value translation
			$gb_row->add_action($this->create_callback_href(array($this,'browse'),array($name.'/'.$k,false)),'View');
			if(!$v['readonly']) {
				$gb_row->add_action($this->create_callback_href(array($this,'edit'),array($name,$k)),'Edit');
				$gb_row->add_action($this->create_confirm_callback_href(__('Delete array').' \''.Epesi::escapeJS($name.'/'.$k,false).'\'?',array('Utils_CommonData','remove_array'), array($name.'/'.$k)),'Delete');
			}
		}
		//$this->display_module($gb);
		$this->display_module($gb,array(true),'automatic_display');

		Base_ActionBarCommon::add('add',__('Add array'),$this->create_callback_href(array($this,'edit'),$name));
		if(!$root)
			Base_ActionBarCommon::add('back',__('Back'),$this->create_back_href());
		return true;
	}
Example #13
0
 public static function user_settings()
 {
     $ret = array(array('name' => null, 'label' => __('General'), 'type' => 'header'), array('name' => 'one_cache', 'label' => __('Show each notification'), 'type' => 'select', 'values' => array(0 => __('multiple times every login and on each device'), 1 => __('only once and only on one device')), 'default' => 1), array('name' => null, 'label' => __('Browser Notification') . ' - ' . __('General'), 'type' => 'header'), array('name' => 'general_timeout', 'reload' => 1, 'label' => __('Close Message Timeout'), 'type' => 'select', 'values' => Utils_CommonDataCommon::get_translated_array('Base_Notify/Timeout', true), 'default' => 0), array('name' => 'general_group', 'label' => __('Group Similar Notifications'), 'type' => 'checkbox', 'default' => 1), array('name' => 'browser_settings', 'label' => '', 'type' => 'static', 'values' => '<a class="button" onClick="Base_Notify.notify (\'Notification\', {body: \'enabled\', icon: \'' . self::get_icon('Base_Notify') . '\'}, true);">' . __('Browser Settings') . '</a>'), array('name' => null, 'label' => __('Browser Notification') . ' - ' . __('Module Specific Timeout'), 'type' => 'header'));
     $modules = ModuleManager::check_common_methods('notification');
     foreach ($modules as $module) {
         $label = self::get_module_caption($module);
         $ret = array_merge($ret, array(array('name' => $module . '_timeout', 'label' => $label, 'type' => 'select', 'values' => array(-2 => _M('Use general setting')) + Utils_CommonDataCommon::get_translated_array('Base_Notify/Timeout', true), 'default' => -2)));
     }
     $ret[] = array('name' => null, 'label' => __('Telegram Notification'), 'type' => 'header');
     $telegram = DB::GetOne('SELECT 1 FROM base_notify WHERE single_cache_uid=%d AND telegram=1', array(Base_AclCommon::get_user()));
     if ($telegram && isset($_GET['telegram'])) {
         $telegram = 0;
         DB::Execute('UPDATE base_notify SET telegram=0 WHERE single_cache_uid=%d', array(Base_AclCommon::get_user()));
     }
     $ret[] = array('name' => 'telegram_url', 'label' => '<a class="button" href="modules/Base/Notify/telegram.php" target="_blank">' . ($telegram ? __('Connect to another telegram account') : __('Connect to your telegram account')) . '</a>', 'type' => 'static', 'values' => $telegram ? '<a class="button" ' . Module::create_href(array('telegram' => 1)) . '>' . __('Disconnect telegram') . '</a>' : '');
     return array(__('Notifications') => $ret);
 }
Example #14
0
 public static function QFfield_category(&$form, $field, $label, $mode, $default, $desc, $rb_obj)
 {
     load_js('modules/CRM/Assets/change.js');
     eval_js('change(' . $default . ');');
     $data = Utils_CommonDataCommon::get_translated_array('crm_assets_category');
     if ($mode != 'view') {
         ksort($data);
         $form->addElement('select', $field, $label, $data, array('onchange' => 'change(this.selectedIndex);', 'id' => $field));
         $form->setDefaults(array($field => $default));
     } else {
         $form->addElement('static', $field, $label, $data[$default]);
     }
 }
 private static function permissions_get_field_values($tab, $args, $first_level = true)
 {
     $arr = array('' => '[' . __('Empty') . ']');
     $field = $args['id'];
     switch (true) {
         case $args['type'] == 'text' && $args['filter']:
             $arr_add = @DB::GetAssoc('SELECT f_' . $args['id'] . ', f_' . $args['id'] . ' FROM ' . $tab . '_data_1 GROUP BY f_' . $args['id'] . ' ORDER BY count(*) DESC LIMIT 20');
             if ($arr_add) {
                 $arr += $arr_add;
             }
             break;
         case $args['commondata']:
             $array_id = is_array($args['param']) ? $args['param']['array_id'] : $args['ref_table'];
             if (strpos($array_id, '::') === false) {
                 $arr = $arr + Utils_CommonDataCommon::get_translated_array($array_id, is_array($args['param']) ? $args['param']['order_by_key'] : false);
             }
             break;
         case $tab == 'contact' && $field == 'login' || $tab == 'rc_accounts' && $field == 'epesi_user':
             // just a quickfix, better solution will be needed
             $arr = $arr + array('USER_ID' => __('User Login'));
             break;
         case $args['type'] == 'date' || $args['type'] == 'timestamp':
             $arr = $arr + Utils_RecordBrowserCommon::$date_values;
             break;
         case ($args['type'] == 'multiselect' || $args['type'] == 'select') && (!isset($args['ref_table']) || !$args['ref_table']):
             $arr = $arr + array('USER' => __('User Contact'));
             $arr = $arr + array('USER_COMPANY' => __('User Company'));
             break;
         case $args['type'] == 'checkbox':
             $arr = array('1' => __('Yes'), '0' => __('No'));
             break;
         case ($args['type'] == 'select' || $args['type'] == 'multiselect') && isset($args['ref_table']):
             if ($args['ref_table'] == 'contact') {
                 $arr = $arr + array('USER' => __('User Contact'));
             }
             if ($args['ref_table'] == 'company') {
                 $arr = $arr + array('USER_COMPANY' => __('User Company'));
             }
             if ($first_level) {
                 if ($args['type'] == 'multiselect') {
                     $arr = $arr + array('ACCESS_VIEW' => __('Allow view any record'), 'ACCESS_VIEW_ALL' => __('Allow view all records'), 'ACCESS_EDIT' => __('Allow edit any record'), 'ACCESS_EDIT_ALL' => __('Allow edit all records'), 'ACCESS_PRINT' => __('Allow print any record'), 'ACCESS_PRINT_ALL' => __('Allow print all records'), 'ACCESS_DELETE' => __('Allow delete any record'), 'ACCESS_DELETE_ALL' => __('Allow delete all records'));
                 } else {
                     $arr = $arr + array('ACCESS_VIEW' => __('Allow view record'), 'ACCESS_EDIT' => __('Allow edit record'), 'ACCESS_PRINT' => __('Allow print record'), 'ACCESS_DELETE' => __('Allow delete record'));
                 }
             }
             break;
     }
     return $arr;
 }
Example #16
0
	private function permissions_get_field_values($field, $in_depth=true) {
		static $all_fields = array();
		if (!isset($all_fields[$this->tab]))
			foreach ($this->table_rows as $k=>$v)
				$all_fields[$this->tab][$v['id']] = $k;
		$args = $this->table_rows[$all_fields[$this->tab][$field]];
		$arr = array(''=>'['.__('Empty').']');
		switch (true) {
			case $args['type']=='text' && $args['filter']:
				$arr_add = @DB::GetAssoc('SELECT f_'.$args['id'].', f_'.$args['id'].' FROM '.$this->tab.'_data_1 GROUP BY f_'.$args['id'].' ORDER BY count(*) DESC LIMIT 20');
				if($arr_add) $arr += $arr_add;
				break;
			case $args['commondata']:
				$array_id = is_array($args['param']) ? $args['param']['array_id'] : $args['ref_table'];
				if (strpos($array_id, '::')===false) 
					$arr = $arr + Utils_CommonDataCommon::get_translated_array($array_id, is_array($args['param'])?$args['param']['order_by_key']:false);
				break;
			case $this->tab=='contact' && $field=='login' ||
				 $this->tab=='rc_accounts' && $field=='epesi_user': // just a quickfix, better solution will be needed
				$arr = $arr + array('USER_ID'=>__('User Login'));
				break;
			case $args['type']=='date' || $args['type']=='timestamp':
				$arr = $arr + Utils_RecordBrowserCommon::$date_values;
				break;
			case ($args['type']=='multiselect' || $args['type']=='select') && (!isset($args['ref_table']) || !$args['ref_table']):
				$arr = $arr + array('USER'=>__('User Contact'));
				$arr = $arr + array('USER_COMPANY'=>__('User Company'));
				break;
			case $args['type']=='checkbox':
				$arr = array('1'=>__('Yes'),'0'=>__('No'));
				break;
			case ($args['type']=='select' || $args['type']=='multiselect') && isset($args['ref_table']):
				if ($args['ref_table']=='contact') $arr = $arr + array('USER'=>__('User Contact'));
				if ($args['ref_table']=='company') $arr = $arr + array('USER_COMPANY'=>__('User Company'));
				if (!$in_depth) continue;

				$last_tab = $this->tab;
                $tabs = explode(',', $args['ref_table']);
                if (count($tabs) != 1) break;
                $one_tab = reset($tabs);
                if ($one_tab != '__RECORDSETS__'
                        && Utils_RecordBrowserCommon::check_table_name($one_tab, false, false)) {
                    $this->tab = $one_tab;
                    $this->init();
                    if (!isset($all_fields[$this->tab]))
                        foreach ($this->table_rows as $k=>$v)
                            $all_fields[$this->tab][$v['id']] = $k;


                    foreach ($all_fields[$this->tab] as $k=>$v) {
                        if ($this->table_rows[$v]['type']=='calculated' || $this->table_rows[$v]['type']=='hidden') unset($all_fields[$this->tab][$k]);
                        else {
                            $arr2 = $this->permissions_get_field_values($k, false, $this->tab);
                            foreach ($arr2 as $k2=>$v2)
                                $arr2[$k2] = '"'.$k2.'":"'.$v2.'"';
                            eval_js('utils_recordbrowser__field_sub_values["'.$field.'__'.$k.'"] = {'.implode(',',$arr2).'};');
                        }
                    }
                    foreach ($all_fields[$this->tab] as $k=>$v) {
                        $arr[$k] = __(' records with %s set to ', array(_V($v)));
                    }
                }

				$this->tab = $last_tab;
				$this->init();
				break;
		}
		return $arr;
	}
Example #17
0
 public static function display_status($record, $nolink, $desc)
 {
     $v = $record[$desc['id']];
     if (!$v) {
         $v = 0;
     }
     $status = Utils_CommonDataCommon::get_translated_array('CRM/Status');
     $href = self::get_status_change_leightbox_href($record, $nolink, $desc);
     $ret = $status[$v];
     if ($href !== false) {
         $ret = '<a ' . $href . '>' . $ret . '</a>';
     }
     return $ret;
 }
Example #18
0
    public static function build_query( $tab, $crits = null, $admin = false, $order = array()) {
		if (!is_array($order)) $order = array();
        $cache_key=$tab.'__'.serialize($crits).'__'.$admin.'__'.serialize($order);
        static $cache = array();
        self::init($tab, $admin);
		if (isset($cache[$cache_key])) return $cache[$cache_key];
        if (!$tab) return false;
		$postgre = DB::is_postgresql();
        $having = '';
        $fields = '';
        $final_tab = $tab.'_data_1 AS r';
        $vals = array();
        if (!$crits) $crits = array();
		$access = $admin ? true : self::get_access($tab, 'browse');
		if ($access===false) return array();
		elseif ($access!==true && is_array($access))
			$crits = self::merge_crits($crits, $access);
        $iter = 0;
        self::init($tab, $admin);
        foreach($order as $k=>$v) {
            if (!is_string($k)) break;
            if ($k[0]==':') $order[] = array('column'=>$k, 'order'=>$k, 'direction'=>$v);
            else $order[] = array('column'=>self::$hash[$k], 'order'=>self::$hash[$k], 'direction'=>$v);
            unset($order[$k]);
        }
        $or_started = false;
        $sep = DB::qstr('::');
		$group_or_start = $group_or = false;
		$special_chars = str_split('!"(|<>=~]^');
        foreach($crits as $k=>$v){
            self::init($tab, $admin);
			$f = explode('[',$k);
			$f = str_replace($special_chars,'',$f[0]);
			while ($f[0]=='_') $f = substr($f, 1);
            if (!isset(self::$table_rows[$f]) && $f[0]!=':' && $f!=='id' && (!isset(self::$hash[$f]) || !isset(self::$table_rows[self::$hash[$f]]))) continue; //failsafe
            $negative = $noquotes = $or_start = $or = false;
            $operator = '=';
            while (($k[0]<'a' || $k[0]>'z') && ($k[0]<'A' || $k[0]>'Z') && $k[0]!=':') {
                if ($k[0]=='!') $negative = true;
                if ($k[0]=='"') $noquotes = true;
                if ($k[0]=='(') $or_start = true;
                if ($k[0]=='|') $or = true;
                if ($k[0]=='<') $operator = '<';
                if ($k[0]=='>') $operator = '>';
                if ($k[0]=='~') $operator = DB::like();
                if ($k[0]=='^') $group_or_start = true;
                if ($k[1]=='=' && $operator!=DB::like()) {
                    $operator .= '=';
                    $k = substr($k, 2);
                } else $k = substr($k, 1);
                if (!isset($k[0])) trigger_error('Invalid criteria in build query: missing word. Crits:'.print_r($crits,true), E_USER_ERROR);
            }
            $or |= $or_start;
			if ($group_or && $group_or_start)
				$having .= ')';
			if ($or_start && $or_started || ($or_started && !$or)) {
				$having .= ')';
				$or_started = false;
			}
            if ($or) {
				if ($having!='') {
					if ($group_or && $group_or_start || $or_started) $having .= ' OR ';
					else $having .= ' AND ';
				}
				if ($group_or_start) $having .= '(';
				if (!$or_started) $having .= '(';
                $or_started = true;
            } else {
				if ($having!='' && $group_or && $group_or_start) $having .= ' OR ';
				if ($having!='' && (!$group_or || !$group_or_start)) $having .= ' AND ';
				if ($group_or_start) $having .= '(';
            }
			if ($group_or_start) {
				if (!$group_or) $having .= '(';
				$group_or = true;
				$group_or_start = false;
			}
			if ($k[strlen($k)-1]==']') {
				list($ref, $sub_field) = explode('[', trim($k, ']'));
				$args = self::$table_rows[self::$hash[$ref]];
				$commondata = $args['commondata'];
				if (is_array($args['param'])) {
					if (isset($args['param']['array_id']))
						$args['ref_table'] = $args['param']['array_id'];
					else
						$args['ref_table'] = $args['param'][1];
				}
				if (!isset($args['ref_table'])) trigger_error('Invalid crits, field '.$ref.' is not a reference; crits: '.print_r($crits,true),E_USER_ERROR);
				$is_multiselect = ($args['type']=='multiselect');
				$tab2 = $args['ref_table'];
				$col2 = $sub_field;
				if ($commondata) {
					$ret = Utils_CommonDataCommon::get_translated_array($tab2);
					$allowed_cd = array();
					if (!is_array($v)) $v = array($v);
					foreach ($ret as $kkk=>$vvv)
						foreach ($v as $w) if ($w!='') {
							if ($operator==DB::like())
								$w = '/'.preg_quote($w, '/').'/i';
							else
								$w = '/^'.preg_quote($w, '/').'$/i';
							if (preg_match($w,$vvv)!==0) {
								$allowed_cd[] = $kkk;
								break;
							}
						}
					if (empty($allowed_cd)) {
						$having .= $negative?'true':'false';
						continue;
					}
				} else {
					self::init($tab2);
					$det = explode('/', $col2);
					$col2 = explode('|', $det[0]);
					//self::init($tab);
					if (!is_array($v)) $v = array($v);
					$poss_vals = '';
					$col2s = array();
					$col2m = array();
					
					$conv = '';
					if ($postgre) $conv = '::varchar';
					foreach ($col2 as $c) {
						if (self::$table_rows[self::$hash[$c]]['type']=='multiselect')
							$col2m[] = $c.$conv;
						else
							$col2s[] = $c.$conv;
					}

					foreach ($v as $w) {
						if ($w==='') {
							$poss_vals .= 'OR f_'.implode(' IS NULL OR f_', $col2);
							break;
						} else {
							if (!$noquotes) $w = DB::qstr($w);
							if (!empty($col2s)) $poss_vals .= ' OR f_'.implode(' '.DB::like().' '.$w.' OR f_', $col2s).' '.DB::like().' '.$w;
							if (!empty($col2m)) {
								$w = DB::Concat(DB::qstr('%'),DB::qstr('\_\_'),$w,DB::qstr('\_\_'),DB::qstr('%'));
								$poss_vals .= ' OR f_'.implode(' '.DB::like().' '.$w.' OR f_', $col2m).' '.DB::like().' '.$w;
							}
						}
					}
					$allowed_cd = DB::GetAssoc('SELECT id, id FROM '.$tab2.'_data_1 WHERE false '.$poss_vals);

					if (empty($allowed_cd)) {
						$having .= $negative?'true':'false';
						continue;
					}
				}
				if ($operator==DB::like())
					$operator = '=';
				$v = $allowed_cd;
				$k = $ref;
			}
			self::init($tab);
            if ($k[0]==':') {
                switch ($k) {
                    case ':Fav' :   $final_tab = '('.$final_tab.') LEFT JOIN '.$tab.'_favorite AS fav ON fav.'.$tab.'_id=r.id';
                                    $having .= ' (fav.user_id='.Acl::get_user().' AND fav.user_id IS NOT NULL)';
                                    break;
                    case ':Sub' :   $final_tab = '('.$final_tab.') LEFT JOIN utils_watchdog_subscription AS sub ON sub.internal_id=r.id AND sub.category_id='.Utils_WatchdogCommon::get_category_id($tab);
                                    $having .= ' (sub.user_id='.Acl::get_user().' AND sub.user_id IS NOT NULL)';
                                    break;
                    case ':Recent'  :   $final_tab = '('.$final_tab.') LEFT JOIN '.$tab.'_recent AS rec ON rec.'.$tab.'_id=r.id';
                                        $having .= ' (rec.user_id='.Acl::get_user().' AND rec.user_id IS NOT NULL)';
                                        break;
                    case ':Created_on'  :
                        $inj = $operator.'%T';
                        $timestamp = Base_RegionalSettingsCommon::reg2time($v, false);
                        $vals[] = $timestamp;
                        $having .= ' created_on '.$inj;
                        break;
                    case ':Created_by'  :
                            $having .= ' created_by = '.$v;
                            break;
                    case ':Edited_on'   :
                        $inj = $operator.'%T';
                        $having .= ' (((SELECT MAX(edited_on) FROM '.$tab.'_edit_history WHERE '.$tab.'_id=r.id) '.$inj.') OR'.
                                     '((SELECT MAX(edited_on) FROM '.$tab.'_edit_history WHERE '.$tab.'_id=r.id) IS NULL AND created_on '.$inj.'))';
                        $timestamp = Base_RegionalSettingsCommon::reg2time($v, false);
                        $vals[] = $timestamp;
                        $vals[] = $timestamp;
                        break;
                    default:
                        trigger_error('Unknow paramter given to get_records criteria: '.$k, E_USER_ERROR);
                }
            } else {
                if ($k == 'id') {
                    if (!is_array($v)) $v = array($v);
                    $having .= '('.($negative?'true':'false');
                    foreach($v as $w) {
                        if (!$noquotes) $w = DB::qstr($w);
                        $having .= ' '.($negative?'AND':'OR').($negative?' NOT':'').' id '.$operator.' '.$w;
                    }
                    $having .= ')';
                } else {
					// Postgres compatibility fix
                    if (!is_array($v)) $v = array($v);
                    if ($negative) $having .= 'NOT ';
                    $having .= '(false';
                    foreach($v as $w) {
                        if (isset(self::$hash[$k])) {
                            $f = self::$hash[$k];
                            $key = $k;
                        } elseif (isset(self::$table_rows[$k])) {
                            $f = $k;
                            $key = self::$table_rows[$k]['id'];
                        } else trigger_error('In table "'.$tab.'" - unknow column "'.$k.'" in criteria "'.print_r($crits,true).'". Available columns are: "'.print_r(self::$table_rows,true).'"', E_USER_ERROR);

						if ($w && self::$table_rows[self::$hash[$key]]['type']=='timestamp' && $operator != DB::like()) {
                            $w = Base_RegionalSettingsCommon::reg2time($w, false);
                            $w = date('Y-m-d H:i:s', $w);
                        } elseif ($w && self::$table_rows[self::$hash[$key]]['type']=='date' && $operator != DB::like()) {
                            $w = Base_RegionalSettingsCommon::reg2time($w, false);
                            $w = date('Y-m-d', $w);
                        }

						if ($postgre && $operator==DB::like()) $key .= '::varchar';
                        if (self::$table_rows[$f]['type']=='checkbox' && !$w) {
                            if($operator=='=')
                                $having .= ' OR r.f_'.$key.' IS NULL OR r.f_'.$key.'=0';
                            else
                                $having .= ' OR (r.f_'.$key.' IS NOT NULL AND r.f_'.$key.'!=0)';
                        } elseif (self::$table_rows[$f]['type']!='text' && self::$table_rows[$f]['type']!='long text' && ($w==='' || $w===null || $w===false)) {
                            if($operator=='=')
                                $having .= ' OR r.f_'.$key.' IS NULL';
                            else
                                $having .= ' OR r.f_'.$key.' IS NOT NULL';
                        } elseif ($w==='') {
                            $having .= ' OR r.f_'.$k.' IS NULL OR r.f_'.$k.'=\'\'';
                        } else {
                            if (self::$table_rows[$f]['type']=='multiselect') {
                                $operator = DB::like();
                                $param = explode('::',self::$table_rows[$f]['param']);
                                $w = DB::Concat(DB::qstr('%'),DB::qstr('\_\_'.$w.'\_\_'),DB::qstr('%'));
                            }
                            elseif (!$noquotes) $w = DB::qstr($w);

                            if (false || $postgre && ($operator=='<' || $operator=='<=' || $operator=='>' || $operator=='>=')) {
                                $field_full_name = 'r.f_' . $key;
								switch (self::$table_rows[$f]['type']) {
									case 'timestamp': $cast_type = 'timestamp'; break;
									case 'date': $cast_type = 'date'; break;
                                    case 'currency': $field_full_name = "split_part($field_full_name, '__', 1)";
                                                     $cast_type = 'integer';
                                                     break;
									default: $cast_type = 'integer';
								}
								$c_field = 'CAST('.$field_full_name.' AS '.$cast_type.')';
							} else $c_field = 'r.f_'.$key;
                            $having .= ' OR ('.$c_field.' '.$operator.' '.$w.' ';
                            if ($operator=='<' || $operator=='<=') {
								$having .= 'OR r.f_'.$key.' IS NULL)';
							} else {
								$having .= 'AND r.f_'.$key.' IS NOT NULL)';
							}
                        }
                    }
                    $having .= ')';
                }
            }
        }
        if ($or_started) $having .= ')';
		if ($group_or) $having  .= '))';
        $orderby = array();
        self::init($tab);
        foreach($order as $v){
            if ($v['order'][0]!=':' && !isset(self::$table_rows[$v['order']])) continue; //failsafe
            if ($v['order'][0]==':') {
				if (!is_numeric(Acl::get_user())) trigger_error('Invalid user id.');
                switch ($v['order']) {
                    case ':id':
                        $orderby[] = ' id ' . $v['direction'];
                    case ':Fav' :
                        $orderby[] = ' (SELECT COUNT(*) FROM '.$tab.'_favorite WHERE '.$tab.'_id=r.id AND user_id='.Acl::get_user().') '.$v['direction'];
                        break;
                    case ':Visited_on'  :
                        $orderby[] = ' (SELECT MAX(visited_on) FROM '.$tab.'_recent WHERE '.$tab.'_id=r.id AND user_id='.Acl::get_user().') '.$v['direction'];
                        break;
                    case ':Edited_on'   :
                        $orderby[] = ' (CASE WHEN (SELECT MAX(edited_on) FROM '.$tab.'_edit_history WHERE '.$tab.'_id=r.id) IS NOT NULL THEN (SELECT MAX(edited_on) FROM '.$tab.'_edit_history WHERE '.$tab.'_id=r.id) ELSE created_on END) '.$v['direction'];
                        break;
                    default     :
                        $orderby[] = ' '.substr($v['order'],1).' ' . $v['direction'];
                        //trigger_error('Unknow paramter given to get_records order: '.$v, E_USER_ERROR);
                }
            } else {
                self::init($tab);
                if (is_array(self::$table_rows[$v['order']]['param']))
                    $param = explode(';', self::$table_rows[$v['order']]['param']['array_id']);
                else
                    $param = explode(';', self::$table_rows[$v['order']]['param']);
                $param = explode('::',$param[0]);
                if (isset($param[1]) && $param[1]!='') {
                    if (self::$table_rows[$v['order']]['type']!='commondata') {
                        if (!isset($param[1])) $cols = $param[0];
                        else if ($param[0]!='__COMMON__') {
                            $tab2 = $param[0];
                            $cols2 = $param[1];
                            $cols2 = explode('|', $cols2);
                            $cols2 = $cols2[0];
                            $cols2 = explode('/', $cols2);
                            if (isset($cols2[1])) $data_col = self::$table_rows[$cols2[1]]['id']; else $data_col = self::$table_rows[$v['order']]['id'];
                            $cols2 = $cols2[0];
                            $val = '(SELECT rdt.f_'.self::get_field_id($cols2).' FROM '.$tab.'_data_1 AS rd LEFT JOIN '.$tab2.'_data_1 AS rdt ON rdt.id=rd.f_'.$data_col.' WHERE r.id=rd.id)';
                            $orderby[] = ' '.$val.' '.$v['direction'];
                            $iter++;
                            continue;
                        }
                    }
                }
                $val = 'f_'.self::$table_rows[$v['order']]['id'];
                if (self::$table_rows[$v['order']]['type'] == 'currency') {
                    if (DB::is_mysql()) {
                        $val = "CAST($val as INT)";
                    } elseif (DB::is_postgresql()) {
                        $val = "CAST(split_part($val, '__', 1) as integer)";
                    }
                }
                $orderby[] = ' '.$val.' '.$v['direction'];
                $iter++;
            }
        }
        if (!empty($orderby)) $orderby = ' ORDER BY'.implode(', ',$orderby);
        else $orderby = '';
		if (!$having) $having = 'true';
        $final_tab = str_replace('('.$tab.'_data_1 AS r'.')',$tab.'_data_1 AS r',$final_tab);
        $ret = array('sql'=>' '.$final_tab.' WHERE '.($admin?self::$admin_filter:'active=1 AND ').$having,'order'=>$orderby,'vals'=>$vals);
        return $cache[$cache_key] = $ret;
    }
Example #19
0
 public static function display_status($record, $nolink, $desc)
 {
     $prefix = 'crm_tasks_leightbox';
     $v = $record[$desc['id']];
     if (!$v) {
         $v = 0;
     }
     $status = Utils_CommonDataCommon::get_translated_array('CRM/Status');
     if ($v >= 3 || $nolink) {
         return $status[$v];
     }
     CRM_FollowupCommon::drawLeightbox($prefix);
     if (!Utils_RecordBrowserCommon::get_access('task', 'edit', $record) && !Base_AclCommon::i_am_admin()) {
         return $status[$v];
     }
     if (isset($_REQUEST['form_name']) && $_REQUEST['form_name'] == $prefix . '_follow_up_form' && $_REQUEST['id'] == $record['id']) {
         unset($_REQUEST['form_name']);
         $v = $_REQUEST['closecancel'];
         $action = $_REQUEST['action'];
         $note = $_REQUEST['note'];
         if ($note) {
             if (get_magic_quotes_gpc()) {
                 $note = stripslashes($note);
             }
             $note = str_replace("\n", '<br />', $note);
             Utils_AttachmentCommon::add('task/' . $record['id'], 0, Acl::get_user(), $note);
         }
         if ($action == 'set_in_progress') {
             $v = 1;
         }
         Utils_RecordBrowserCommon::update_record('task', $record['id'], array('status' => $v));
         if ($action == 'set_in_progress') {
             location(array());
         }
         $values = $record;
         $values['date_and_time'] = date('Y-m-d H:i:s');
         $values['title'] = __('Follow-up') . ': ' . $values['title'];
         $values['status'] = 0;
         if ($action != 'none') {
             $x = ModuleManager::get_instance('/Base_Box|0');
             $values['follow_up'] = array('task', $record['id'], $record['title']);
             if ($action == 'new_task') {
                 $x->push_main('Utils/RecordBrowser', 'view_entry', array('add', null, $values), array('task'));
             }
             if ($action == 'new_meeting') {
                 $x->push_main('Utils/RecordBrowser', 'view_entry', array('add', null, array('title' => $values['title'], 'permission' => $values['permission'], 'priority' => $values['priority'], 'description' => $values['description'], 'date' => date('Y-m-d'), 'time' => date('H:i:s'), 'duration' => 3600, 'status' => 0, 'employees' => $values['employees'], 'customers' => $values['customers'], 'follow_up' => $values['follow_up'])), array('crm_meeting'));
             }
             if ($action == 'new_phonecall') {
                 $x->push_main('Utils/RecordBrowser', 'view_entry', array('add', null, array('subject' => $values['title'], 'permission' => $values['permission'], 'priority' => $values['priority'], 'description' => $values['description'], 'date_and_time' => date('Y-m-d H:i:s'), 'employees' => $values['employees'], 'status' => 0, 'customer' => !empty($values['customers']) ? array_pop($values['customers']) : '', 'follow_up' => $values['follow_up'])), array('phonecall'));
             }
             return false;
         }
         location(array());
     }
     if ($v == 0) {
         return '<a href="javascript:void(0)" onclick="' . $prefix . '_set_action(\'set_in_progress\');' . $prefix . '_set_id(\'' . $record['id'] . '\');' . $prefix . '_submit_form();">' . $status[$v] . '</a>';
     }
     return '<a href="javascript:void(0)" class="lbOn" rel="' . $prefix . '_followups_leightbox" onMouseDown="' . $prefix . '_set_id(' . $record['id'] . ');">' . $status[$v] . '</a>';
 }
Example #20
0
 public function show_filters($filters_set = array(), $f_id = '')
 {
     $this->init();
     if ($this->get_access('browse') === false) {
         return;
     }
     $access = $this->get_access('view');
     $filters_all = array();
     foreach ($this->table_rows as $k => $v) {
         if (isset($access[$v['id']]) && $access[$v['id']]) {
             if (!isset($filters_set[$v['id']]) && $v['filter'] || isset($filters_set[$v['id']]) && $filters_set[$v['id']]) {
                 $filters_all[] = $k;
                 if (isset($filters_set[$v['id']])) {
                     unset($filters_set[$v['id']]);
                 }
             }
         }
     }
     if (!$this->data_gb) {
         $this->data_gb = $this->init_module(Utils_GenericBrowser::module_name(), null, $this->tab);
     }
     if (empty($filters_all)) {
         $this->crits = array();
         return '';
     }
     // TODO: move it
     $form = $this->init_module(Libs_QuickForm::module_name(), null, $this->tab . 'filters');
     //        $form_sub = $form->get_submit_form_js_by_name(array($form->get_name(), $this->data_gb->form_s->get_name()),true,null)."return false;";
     //        $this->data_gb->form_s->updateAttributes(array('onsubmit'=>$form_sub));
     //	      $form->updateAttributes(array('onsubmit'=>$form_sub));
     $empty_defaults = array();
     $filters = array();
     foreach ($filters_all as $filter) {
         $filter_id = preg_replace('/[^a-z0-9]/', '_', strtolower($filter));
         $field_id = 'filter__' . $filter_id;
         if (isset($this->custom_filters[$filter_id])) {
             $f = $this->custom_filters[$filter_id];
             if ($this->data_gb->show_all()) {
                 if (isset($f['trans'])) {
                     foreach ($f['trans'] as $k => $v) {
                         if (empty($v)) {
                             $empty_defaults[$field_id] = $k;
                         }
                     }
                 }
             }
             if (!isset($f['label'])) {
                 $f['label'] = $filter;
             }
             if (!isset($f['args'])) {
                 $f['args'] = null;
             }
             if (!isset($f['args_2'])) {
                 $f['args_2'] = null;
             }
             if (!isset($f['args_3'])) {
                 $f['args_3'] = null;
             }
             $form->addElement($f['type'], $field_id, $f['label'], $f['args'], $f['args_2'], $f['args_3']);
             $filters[] = $filter_id;
             continue;
         }
         $field_label = _V($this->table_rows[$filter]['name']);
         $arr = array();
         $autoselect = false;
         if ($this->table_rows[$filter]['type'] == 'timestamp' || $this->table_rows[$filter]['type'] == 'date') {
             $form->addElement('datepicker', $field_id . '__from', $field_label . ' (' . __('From') . ')', array('label' => false));
             // TRSL
             $form->addElement('datepicker', $field_id . '__to', $field_label . ' (' . __('To') . ')', array('label' => false));
             // TRSL
             $filters[] = $filter_id . '__from';
             $filters[] = $filter_id . '__to';
             continue;
         } elseif ($this->table_rows[$filter]['type'] == 'checkbox') {
             $arr = array('' => __('No'), 1 => __('Yes'));
         } elseif (in_array($this->table_rows[$filter]['type'], array('currency', 'float', 'integer', 'autonumber')) || $this->table_rows[$filter]['type'] == 'calculated' && $this->table_rows[$filter]['param'] != '' && in_array($this->table_rows[$filter]['style'], array('currency', 'float', 'integer', 'autonumber'))) {
             $form->addElement('text', $field_id . '__from', $field_label . ' (' . __('From') . ')', array('label' => false));
             // TRSL
             $form->addElement('text', $field_id . '__to', $field_label . ' (' . __('To') . ')', array('label' => false));
             // TRSL
             $form->addRule($field_id . '__from', __('Only numbers are allowed.'), 'numeric');
             $form->addRule($field_id . '__to', __('Only numbers are allowed.'), 'numeric');
             $filters[] = $filter_id . '__from';
             $filters[] = $filter_id . '__to';
             if ($this->table_rows[$filter]['type'] == 'currency' || $this->table_rows[$filter]['type'] == 'calculated' && $this->table_rows[$filter]['param'] != '' && $this->table_rows[$filter]['style'] == 'currency') {
                 $arr = Utils_CurrencyFieldCommon::get_currencies();
                 if (count($arr) > 1) {
                     $arr = array('__NULL__' => '---') + $arr;
                     $form->addElement('select', $field_id . '__currency', $field_label . ' (' . __('Currency') . ')', $arr);
                     // TRSL
                     $filters[] = $filter_id . '__currency';
                 }
             }
             continue;
         } else {
             if ($this->table_rows[$filter]['type'] == 'commondata') {
                 $parts = explode('::', $this->table_rows[$filter]['param']['array_id']);
                 $array_id = array_shift($parts);
                 $arr = Utils_CommonDataCommon::get_translated_array($array_id, $this->table_rows[$filter]['param']['order_by_key']);
                 $made_of_parts = false;
                 while (!empty($parts)) {
                     $made_of_parts = true;
                     array_shift($parts);
                     $next_arr = array();
                     foreach ($arr as $k => $v) {
                         $next = Utils_CommonDataCommon::get_translated_array($array_id . '/' . $k, $this->table_rows[$filter]['param']['order_by_key']);
                         foreach ($next as $k2 => $v2) {
                             $next_arr[$k . '/' . $k2] = $v . ' / ' . $v2;
                         }
                     }
                     $arr = $next_arr;
                 }
                 if ($made_of_parts) {
                     natcasesort($arr);
                 }
             } else {
                 $param = explode(';', $this->table_rows[$filter]['param']);
                 $x = explode('::', $param[0]);
                 if (!isset($x[1])) {
                     continue;
                 }
                 list($tab, $col) = $x;
                 if ($tab == '__COMMON__') {
                     $arr = Utils_CommonDataCommon::get_translated_tree($col);
                 } else {
                     $col = explode('|', $col);
                     Utils_RecordBrowserCommon::check_table_name($tab);
                     foreach ($col as $k => $v) {
                         $col[$k] = preg_replace('/[^a-z0-9]/', '_', strtolower($v));
                     }
                     $crits = array();
                     if (isset($this->filter_crits[$this->table_rows[$filter]['id']])) {
                         $crits = $this->filter_crits[$this->table_rows[$filter]['id']];
                     } else {
                         if (isset($param[1])) {
                             $callback = explode('::', $param[1]);
                             if (is_callable($callback)) {
                                 $crits = call_user_func($callback, true);
                             }
                         }
                         if (!is_array($crits)) {
                             $crits = array();
                             if (isset($param[2])) {
                                 $callback = explode('::', $param[2]);
                                 if (is_callable($callback)) {
                                     $crits = call_user_func($callback, true);
                                 }
                             }
                             if (!is_array($crits)) {
                                 $crits = array();
                             }
                         }
                     }
                     if ($tab != '__RECORDSETS__' && !preg_match('/,/', $tab)) {
                         $qty = Utils_RecordBrowserCommon::get_records_count($tab, $crits);
                         if ($qty <= Utils_RecordBrowserCommon::$options_limit) {
                             $tpro = DB::GetRow('SELECT description_callback FROM recordbrowser_table_properties WHERE tab=%s', array($tab));
                             if ($tpro) {
                                 $descr = $tpro['description_callback'];
                                 if ($descr) {
                                     if (preg_match('/::/', $descr)) {
                                         $descr = explode('::', $descr);
                                     }
                                     if (!is_callable($descr)) {
                                         $descr = '';
                                     }
                                 }
                             }
                             $ret2 = Utils_RecordBrowserCommon::get_records($tab, $crits);
                             foreach ($ret2 as $k => $v) {
                                 if (empty($descr)) {
                                     $txt = array();
                                     foreach ($col as $kk => $vv) {
                                         $txt[] = Utils_RecordBrowserCommon::get_val($tab, $vv, $v, true);
                                     }
                                     $option_label = implode(' ', $txt);
                                 } else {
                                     $option_label = call_user_func($descr, $v, true);
                                 }
                                 $arr[$k] = $option_label;
                             }
                             natcasesort($arr);
                         } else {
                             $arr = array();
                             $autoselect = true;
                             $param = array($tab, $crits);
                         }
                     } else {
                         $arr = array();
                         $autoselect = true;
                         $param = array($tab, $crits);
                     }
                     if ($tab == 'contact') {
                         $arr = array($this->crm_perspective_default() => '[' . __('Perspective') . ']') + $arr;
                     }
                 }
             }
         }
         if ($autoselect) {
             $f_callback = array('Utils_RecordBrowserCommon', 'autoselect_label');
             $arr = array('__NULL__' => '---') + $arr;
             $form->addElement('autoselect', $field_id, $field_label, $arr, array(array('Utils_RecordBrowserCommon', 'automulti_suggestbox'), array_merge($param, array($f_callback, $this->table_rows[$filter]['param']))), $f_callback);
             $form->setDefaults(array($field_id => '__NULL__'));
         } else {
             $arr = array('__NULL__' => '---') + $arr;
             $form->addElement('select', $field_id, $field_label, $arr);
             // TRSL
         }
         $filters[] = $filter_id;
     }
     $form->addElement('submit', 'submit', __('Show'));
     $use_saving_filters = Base_User_SettingsCommon::get($this->get_type(), 'save_filters');
     if ($this->data_gb->show_all()) {
         $this->set_module_variable('def_filter', $empty_defaults);
         if ($use_saving_filters) {
             Base_User_SettingsCommon::save($this->get_type(), $this->tab . '_filters', $empty_defaults);
         }
         print '<span style="display:none;">' . microtime(true) . '</span>';
     }
     $def_filt = $this->get_module_variable('def_filter', array());
     if ($use_saving_filters) {
         $saved_filters = Base_User_SettingsCommon::get($this->get_type(), $this->tab . '_filters');
         if ($saved_filters) {
             $def_filt = $saved_filters;
         }
     }
     $this->crits = array();
     $filter_crits = array();
     $form->setDefaults($def_filt);
     $external_filters = array();
     $dont_hide = Base_User_SettingsCommon::get(Utils_RecordBrowser::module_name(), $this->tab . '_show_filters');
     $vals = $form->exportValues();
     $ret = DB::Execute('SELECT * FROM recordbrowser_browse_mode_definitions WHERE tab=%s', array($this->tab));
     while ($row = $ret->FetchRow()) {
         $m = $this->init_module($row['module']);
         $this->display_module($m, array(&$form, &$external_filters, &$vals, &$filter_crits, $this), $row['func']);
     }
     foreach ($filters_all as $filter) {
         if (in_array(strtolower($filter), $external_filters)) {
             continue;
         }
         $filter_id = preg_replace('/[^a-z0-9]/', '_', strtolower($filter));
         $field_id = 'filter__' . $filter_id;
         if (isset($this->custom_filters[$filter_id])) {
             if (!isset($vals['filter__' . $filter_id])) {
                 if ($this->custom_filters[$filter_id]['type'] != 'autoselect') {
                     $vals['filter__' . $filter_id] = '__NULL__';
                 } else {
                     $vals['filter__' . $filter_id] = '';
                 }
             }
             if (isset($this->custom_filters[$filter_id]['trans'][$vals['filter__' . $filter_id]])) {
                 foreach ($this->custom_filters[$filter_id]['trans'][$vals['filter__' . $filter_id]] as $k => $v) {
                     $filter_crits[$k] = $v;
                 }
             } elseif (isset($this->custom_filters[$filter_id]['trans_callback'])) {
                 $new_crits = call_user_func($this->custom_filters[$filter_id]['trans_callback'], $vals['filter__' . $filter_id], $filter_id);
                 $this->crits = Utils_RecordBrowserCommon::merge_crits($this->crits, $new_crits);
             }
         } else {
             if (in_array($this->table_rows[$filter]['type'], array('currency', 'float', 'integer', 'autonumber')) || $this->table_rows[$filter]['type'] == 'calculated' && $this->table_rows[$filter]['param'] != '' && in_array($this->table_rows[$filter]['style'], array('currency', 'float', 'integer', 'autonumber'))) {
                 if (isset($vals[$field_id . '__currency']) && $vals[$field_id . '__currency'] != "__NULL__") {
                     $filter_crits["~{$filter_id}"] = "%\\_\\_" . $vals[$field_id . '__currency'];
                 }
                 if (isset($vals[$field_id . '__from']) && $vals[$field_id . '__from'] !== "") {
                     $filter_crits[">={$filter_id}"] = floatval($vals[$field_id . '__from']);
                 }
                 if (isset($vals[$field_id . '__to']) && $vals[$field_id . '__to'] !== "") {
                     $filter_crits["<={$filter_id}"] = floatval($vals[$field_id . '__to']);
                 }
                 continue;
             }
             if ($this->table_rows[$filter]['type'] == 'timestamp' || $this->table_rows[$filter]['type'] == 'date') {
                 if (isset($vals[$field_id . '__from']) && $vals[$field_id . '__from']) {
                     $filter_crits['>=' . $filter_id] = $vals[$field_id . '__from'] . ' 00:00:00';
                 }
                 if (isset($vals[$field_id . '__to']) && $vals[$field_id . '__to']) {
                     $filter_crits['<=' . $filter_id] = $vals[$field_id . '__to'] . ' 23:59:59';
                 }
                 continue;
             }
             if (!isset($vals['filter__' . $filter_id]) || $this->table_rows[$filter]['type'] == 'select' && $vals['filter__' . $filter_id] === '') {
                 $vals['filter__' . $filter_id] = '__NULL__';
             }
             if ($vals['filter__' . $filter_id] === '__NULL__') {
                 continue;
             }
             if ($this->table_rows[$filter]['type'] == 'commondata') {
                 $vals2 = explode('/', $vals['filter__' . $filter_id]);
                 $param = explode('::', $this->table_rows[$filter]['param']['array_id']);
                 array_shift($param);
                 $param[] = $filter_id;
                 foreach ($vals2 as $v) {
                     $filter_crits[preg_replace('/[^a-z0-9]/', '_', strtolower(array_shift($param)))] = $v;
                 }
             } else {
                 $filter_crits[$filter_id] = $vals['filter__' . $filter_id];
             }
         }
     }
     $this->crits = Utils_RecordBrowserCommon::merge_crits($this->crits, $filter_crits);
     $this->set_module_variable('crits', $this->crits);
     $filters = array_merge($filters, $external_filters);
     foreach ($filters as $k => $v) {
         $filters[$k] = 'filter__' . $v;
     }
     foreach ($vals as $k => $v) {
         $c = str_replace('filter__', '', $k);
         if (isset($this->custom_filters[$c]) && $this->custom_filters[$c]['type'] == 'checkbox' && $v === '__NULL__') {
             unset($vals[$k]);
         }
     }
     if ($use_saving_filters && isset($vals['submited']) && $vals['submited']) {
         unset($vals['submited']);
         unset($vals['submit']);
         Base_User_SettingsCommon::save($this->get_type(), $this->tab . '_filters', $vals);
     }
     $this->set_module_variable('def_filter', $vals);
     $theme = $this->init_module(Base_Theme::module_name());
     $form->assign_theme('form', $theme);
     $theme->assign('filters', $filters);
     load_js('modules/Utils/RecordBrowser/filters.js');
     $theme->assign('show_filters', array('attrs' => 'onclick="rb_show_filters(\'' . $this->tab . '\',\'' . $f_id . '\');" id="show_filter_b_' . $f_id . '"', 'label' => __('Show filters')));
     $theme->assign('hide_filters', array('attrs' => 'onclick="rb_hide_filters(\'' . $this->tab . '\',\'' . $f_id . '\');" id="hide_filter_b_' . $f_id . '"', 'label' => __('Hide filters')));
     $theme->assign('id', $f_id);
     if (!$use_saving_filters) {
         if (!$this->isset_module_variable('filters_defaults')) {
             $this->set_module_variable('filters_defaults', $this->crits);
         } elseif ($this->crits != $this->get_module_variable('filters_defaults')) {
             $theme->assign('dont_hide', true);
         }
     }
     if ($dont_hide) {
         $theme->assign('dont_hide', true);
     }
     return $this->get_html_of_module($theme, 'Filter', 'display');
 }