function prepare_data($permission = 0, $is_altered = false, $are_nonrequired_filled = false)
 {
     $ra_task = new RBO_RecordsetAccessor('task');
     $tasks_number = 2;
     $tasks = array_keys($ra_task->get_records(array(), array(), array(), $tasks_number));
     while (count($tasks) < $tasks_number) {
         $t = $ra_task->new_record(array('title' => 'Sample task ' . (count($tasks) + 1), 'status' => 0, 'priority' => 0, 'permission' => 0, 'employees' => array(1)));
         $tasks[] = $t->id;
     }
     $data_required = array('text_required' => 'Sample text required', 'long_text_required' => 'Permission:' . $permission . ' Not required fields full:' . $are_nonrequired_filled . ' Altered:false', 'integer_required' => 123, 'float_required' => 123.45, 'checkbox' => 0, 'date_required' => date('Y-m-d'), 'timestamp_required' => date('Y-m-d H:i:s'), 'time_required' => date('Y-m-d 12:23:45'), 'currency_required' => Utils_CurrencyFieldCommon::format_default(100, 1), 'select_required' => $tasks[0], 'select_commondata_required' => 2, 'multiselect_required' => array($tasks[0]), 'multiselect_commondata_required' => array(0, 1, 2), 'permission' => $permission);
     $data_other = array('text' => 'Sample text', 'long_text' => 'A sample of long text', 'integer' => 1234, 'float' => 123.4567, 'checkbox' => 1, 'date' => date('Y-m-d', strtotime('+2 days')), 'timestamp' => date('Y-m-d H:i:s', strtotime('-3 days')), 'time' => date('Y-m-d 12:24:46'), 'currency' => Utils_CurrencyFieldCommon::format_default(200, 1), 'select' => $tasks[1], 'select_commondata' => 1, 'multiselect' => array($tasks[0]), 'multiselect_commondata' => array(0, 1, 2));
     $data_required_altered = array('text_required' => 'Sample text required altered', 'long_text_required' => 'Permission:' . $permission . ' Not required fields full:' . $are_nonrequired_filled . ' Altered:true', 'integer_required' => 111111, 'float_required' => 11111.1111, 'checkbox' => 1, 'date_required' => date('Y-m-d', strtotime('+2 days')), 'timestamp_required' => date('Y-m-d H:i:s', strtotime('-3 days')), 'time_required' => date('Y-m-d 12:26:47'), 'currency_required' => Utils_CurrencyFieldCommon::format_default(10, 1), 'select_required' => $tasks[0], 'select_commondata_required' => 3, 'multiselect_required' => array($tasks[0], $tasks[1]), 'multiselect_commondata_required' => array(1, 2, 3), 'permission' => $permission);
     $data_other_altered = array('text' => 'Sample text altered', 'long_text' => 'A sample of long altered text', 'integer' => 1234, 'float' => 123.4567, 'checkbox' => 0, 'date' => date('Y-m-d'), 'timestamp' => date('Y-m-d H:i:s'), 'time' => date('Y-m-d 12:27:47'), 'currency' => Utils_CurrencyFieldCommon::format_default(20, 1), 'select' => $tasks[0], 'select_commondata' => 3, 'multiselect' => array($tasks[0], $tasks[1]), 'multiselect_commondata' => array(1, 2, 3));
     if ($is_altered) {
         $data1 = $data_required_altered;
         $data2 = $data_other_altered;
     } else {
         $data1 = $data_required;
         $data2 = $data_other;
     }
     if ($are_nonrequired_filled) {
         return $data1 + $data2;
     } else {
         return $data1;
     }
 }
Exemple #2
0
 public function body()
 {
     $ra_task = new RBO_RecordsetAccessor('task');
     $tasks = array_keys($ra_task->get_records(array(), array(), array(), 2));
     $defaults = array('text_required' => 'Default text', 'long_text_required' => 'Default long test', 'integer_required' => 129, 'float_required' => 129.129, 'checkbox' => 0, 'date_required' => date('Y-m-d'), 'timestamp_required' => date('Y-m-d H:i:s'), 'time_required' => date('Y-m-d 12:29:45'), 'currency_required' => Utils_CurrencyFieldCommon::format_default(129.129, 1), 'select_required' => $tasks[0], 'select_commondata_required' => 2, 'multiselect_required' => array($tasks[0], $tasks[1]), 'multiselect_commondata_required' => array(0, 1, 2), 'permission' => 5, 'text' => 'Default text', 'long_text' => 'Default long test', 'integer' => 129, 'float' => 129.129, 'date' => date('Y-m-d', strtotime('+2 days')), 'timestamp' => date('Y-m-d H:i:s', strtotime('-3 days')), 'time' => date('Y-m-d 12:29:46'), 'currency' => Utils_CurrencyFieldCommon::format_default(257.257, 1), 'select' => $tasks[1], 'select_commondata' => 1, 'multiselect' => array($tasks[0], $tasks[1]), 'multiselect_commondata' => array(0, 1, 2));
     $rs = new Tests_RecordBrowser_Recordset();
     $this->rb = $rs->create_rb_module($this);
     $this->rb->set_defaults($defaults);
     $this->display_module($this->rb);
 }
 public static function get_val($tab, $field, $record, $links_not_recommended = false, $args = null)
 {
     static $recurrence_call_stack = array();
     self::init($tab);
     $commondata_sep = '/';
     if (!isset(self::$table_rows[$field])) {
         if (!isset(self::$hash[$field])) {
             trigger_error('Unknown field "' . $field . '" for recordset "' . $tab . '"', E_USER_ERROR);
         }
         $field = self::$hash[$field];
     }
     if ($args === null) {
         $args = self::$table_rows[$field];
     }
     if (!array_key_exists('id', $record)) {
         $record['id'] = null;
     }
     if (!array_key_exists($args['id'], $record)) {
         trigger_error($args['id'] . ' - unknown field for record ' . serialize($record), E_USER_ERROR);
     }
     $val = $record[$args['id']];
     $function_call_id = implode('|', array($tab, $field, serialize($val)));
     if (isset($recurrence_call_stack[$function_call_id])) {
         return '!! ' . __('recurrence issue') . ' !!';
     } else {
         $recurrence_call_stack[$function_call_id] = true;
     }
     self::display_callback_cache($tab);
     if (isset(self::$display_callback_table[$tab][$field])) {
         $ret = self::call_display_callback(self::$display_callback_table[$tab][$field], $record, $links_not_recommended, self::$table_rows[$field], $tab);
     } else {
         $ret = $val;
         if ($args['type'] == 'select' || $args['type'] == 'multiselect') {
             if (is_array($val) && empty($val) || !is_array($val) && $val == '') {
                 $ret = '---';
                 unset($recurrence_call_stack[$function_call_id]);
                 return $ret;
             }
             $param = explode(';', $args['param']);
             $pp = explode('::', $param[0]);
             $tab = $pp[0];
             if (isset($pp[1])) {
                 $col = $pp[1];
             } else {
                 $col = null;
             }
             //return;//trigger_error("\"param\" attribute of field \"$field\" is not valid. Please set <recordset>::<field>");
             if (!$col && $tab == '__COMMON__') {
                 unset($recurrence_call_stack[$function_call_id]);
                 return;
             }
             if (!is_array($val)) {
                 $val = array($val);
             }
             //              if ($tab=='__COMMON__') $data = Utils_CommonDataCommon::get_translated_array($col, true);
             if ($tab == '__RECORDSETS__') {
                 $single_tab = false;
             } else {
                 $tabs = explode(',', $tab);
                 $single_tab = count($tabs) == 1;
             }
             $ret = '';
             $first = true;
             foreach ($val as $k => $v) {
                 //                  if ($tab=='__COMMON__' && !isset($data[$v])) continue;
                 if ($tab == '__COMMON__') {
                     $path = explode('/', $v);
                     $tooltip = '';
                     $res = '';
                     if (count($path) > 1) {
                         $res .= Utils_CommonDataCommon::get_value($col . '/' . $path[0], true);
                         if (count($path) > 2) {
                             $res .= $commondata_sep . '...';
                             $tooltip = '';
                             $full_path = $col;
                             foreach ($path as $w) {
                                 $full_path .= '/' . $w;
                                 $tooltip .= ($tooltip ? $commondata_sep : '') . Utils_CommonDataCommon::get_value($full_path, true);
                             }
                         }
                         $res .= $commondata_sep;
                     }
                     $val = Utils_CommonDataCommon::get_value($col . '/' . $v, true);
                     if (!$val) {
                         continue;
                     }
                     $res .= $val;
                     if ($first) {
                         $first = false;
                     } else {
                         $ret .= '<br>';
                     }
                     $res = self::no_wrap($res);
                     if ($tooltip) {
                         $res = '<span ' . Utils_TooltipCommon::open_tag_attrs($tooltip, false) . '>' . $res . '</span>';
                     }
                     $ret .= $res;
                 } else {
                     if (!$single_tab) {
                         list($tab, $v) = explode('/', $v, 2);
                     }
                     if ($first) {
                         $first = false;
                     } else {
                         $ret .= '<br>';
                     }
                     if ($col) {
                         $columns = explode('|', $col);
                         $ret .= Utils_RecordBrowserCommon::create_linked_label($tab, $columns, $v, $links_not_recommended);
                     } else {
                         $ret .= Utils_RecordBrowserCommon::create_default_linked_label($tab, $v, $links_not_recommended);
                     }
                 }
             }
             if ($ret == '') {
                 $ret = '---';
             }
         } elseif ($args['type'] == 'commondata') {
             if (!isset($val) || $val === '') {
                 $ret = '';
             } else {
                 $arr = explode('::', $args['param']['array_id']);
                 $path = array_shift($arr);
                 foreach ($arr as $v) {
                     $path .= '/' . $record[self::get_field_id($v)];
                 }
                 $path .= '/' . $record[$args['id']];
                 $ret = Utils_CommonDataCommon::get_value($path, true);
             }
             /*            } elseif ($args['type']=='record') {
                           if (!isset($val) || $val==='') {
                               $ret = '';
                           } else {
                               @list($rs,$rid) = explode('#',$record[$args['id']],2);
                               if(!$rid) $ret = '';
                               else {
                                   $ret = self::create_default_linked_label($rs,$rid,$links_not_recommended);
                               }
                           }*/
         } elseif ($args['type'] == 'autonumber') {
             if (!$links_not_recommended && isset($record['id']) && $record['id']) {
                 $ret = self::record_link_open_tag_r($tab, $record) . $val . self::record_link_close_tag();
             }
         } elseif ($args['type'] == 'currency') {
             $val = Utils_CurrencyFieldCommon::get_values($val);
             $ret = Utils_CurrencyFieldCommon::format($val[0], $val[1]);
         } elseif ($args['type'] == 'checkbox') {
             $ret = $ret ? __('Yes') : __('No');
         } elseif ($args['type'] == 'date') {
             if ($val != '') {
                 $ret = Base_RegionalSettingsCommon::time2reg($val, false, true, false);
             }
         } elseif ($args['type'] == 'timestamp') {
             if ($val != '') {
                 $ret = Base_RegionalSettingsCommon::time2reg($val, 'without_seconds');
             }
         } elseif ($args['type'] == 'time') {
             if ($val != '') {
                 $ret = Base_RegionalSettingsCommon::time2reg($val, 'without_seconds', false);
             }
         } elseif ($args['type'] == 'long text') {
             $ret = htmlspecialchars($val);
             $ret = str_replace("\n", '<br>', $ret);
             $ret = Utils_BBCodeCommon::parse($ret);
         }
     }
     unset($recurrence_call_stack[$function_call_id]);
     return $ret;
 }
Exemple #4
0
 public function format_cell($format, $val, $type = 'none')
 {
     if (!is_array($format)) {
         $format = array($format => '');
     } else {
         $format = array_flip($format);
     }
     $ret = array();
     if (!is_array($val)) {
         $val = array($val);
     }
     if (isset($format['currency']) || isset($format['numeric']) || isset($format['percent'])) {
         $format['fade_out_zero'] = 1;
     }
     if (isset($format['currency']) && empty($val)) {
         $val = array(Base_User_SettingsCommon::get('Utils_CurrencyField', 'default_currency') => 0);
     }
     $css_class = '';
     $style = '';
     $attrs = '';
     foreach ($val as $k => $v) {
         $next = $v;
         if ((double) $v == 0 && strlen($v) > 0 && $v != (string) (double) $v) {
             unset($format['fade_out_zero']);
         } else {
             if (isset($format['currency'])) {
                 $v = strip_tags($v);
                 $next = Utils_CurrencyFieldCommon::format($v, $k);
             }
             if (isset($format['currency']) || isset($format['numeric'])) {
                 if ((double) $v != 0) {
                     unset($format['fade_out_zero']);
                 }
             }
         }
         if (isset($format['percent'])) {
             if ($type == 'row_total' || $type == 'total_all') {
                 $cols = count($this->gb_captions) - 2;
                 if (!empty($this->categories)) {
                     $cols--;
                 }
                 if (!$v) {
                     $v = '--';
                 }
             }
             if ($type == 'col_total' || $type == 'total_all') {
                 $rows = count($this->ref_records);
                 if (!$v) {
                     $v = '--';
                 }
             }
             if (is_numeric($v)) {
                 $v = number_format($v, 2);
             }
             $next = $v . ' %';
             if ($v != 0) {
                 unset($format['fade_out_zero']);
             }
         }
         $ret[] = $next;
     }
     if (isset($format['currency'])) {
         foreach ($ret as $k => $v) {
             if (count($ret) == 1) {
                 break;
             }
             $value = Utils_CurrencyFieldCommon::parse_currency($v);
             if ($value[0] == 0) {
                 unset($ret[$k]);
             }
         }
     }
     if (isset($format['currency']) || isset($format['numeric']) || isset($format['percent'])) {
         $css_class .= ' number';
         if (isset($format['fade_out_zero'])) {
             $css_class .= ' fade-out-zero';
         }
     }
     if ($this->first) {
         $css_class .= ' top-row';
     }
     if (isset($format['total-row_desc'])) {
         $css_class .= ' total-row_desc';
     }
     if (isset($format['row_desc'])) {
         $css_class .= ' row-desc';
     }
     if (isset($format['total_all'])) {
         $css_class .= ' total-all';
     } elseif (isset($format['total'])) {
         $css_class .= ' total';
     }
     $ret = implode('<br>', $ret);
     if ($this->pdf) {
         $ret = array('value' => $ret, 'style' => $format, 'attrs' => '', 'class' => '');
     } else {
         $ret = array('value' => $ret, 'style' => $style, 'attrs' => $attrs, 'class' => $css_class);
     }
     return $ret;
 }
Exemple #5
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', null, $this->tab);
        if (empty($filters_all)) {
            $this->crits = array();
            return '';
        } // TODO: move it
        $form = $this->init_module('Libs/QuickForm', 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();
        $text_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;
            }
            $arr = array();
            $autoselect = false;
            if ($this->table_rows[$filter]['type']=='timestamp' || $this->table_rows[$filter]['type']=='date') {
				$form->addElement('datepicker', $field_id.'__from', _V($filter).' ('.__('From').')', array('label'=>false)); // TRSL
				$form->addElement('datepicker', $field_id.'__to', _V($filter).' ('.__('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', _V($filter).' ('.__('From').')', array('label'=>false)); // TRSL
		    $form->addElement('text', $field_id.'__to', _V($filter).' ('.__('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', _V($filter).' ('.__('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']);
					while (!empty($parts)) {
						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;
					}
                    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) {
                                $ret2 = Utils_RecordBrowserCommon::get_records($tab,$crits,$col);
                                if (count($col)!=1) {
                                    foreach ($ret2 as $k=>$v) {
                                        $txt = array();
                                        foreach ($col as $kk=>$vv)
                                            $txt[] = $v[$vv];
                                        $arr[$k] = implode(' ',$txt);
                                    }
                                } else {
                                    foreach ($ret2 as $k=>$v) {
                                        $arr[$k] = $v[$col[0]];
                                    }
                                }
                                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, _V($filter), $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, _V($filter), $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();

        $form->setDefaults($def_filt);

        $external_filters = array();

        $dont_hide = Base_User_SettingsCommon::get('Utils/RecordBrowser',$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']);
            $next_dont_hide = false; // FIXME deprecated, to be removed
            $this->display_module($m, array(& $form, & $external_filters, & $vals, & $this->crits, & $next_dont_hide, $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)
                        $this->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__")
                        $this->crits["~$filter"] = "%__" . $vals[$field_id.'__currency'];
                    if (isset($vals[$field_id.'__from']) && $vals[$field_id.'__from'] !== "")
                        $this->crits[">=\"$filter"] = floatval($vals[$field_id.'__from']);
                    if (isset($vals[$field_id.'__to']) && $vals[$field_id.'__to'] !== "")
                        $this->crits["<=\"$filter"] = 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'])
						$this->crits['>='.$filter_id] = $vals[$field_id.'__from'].' 00:00:00';
					if (isset($vals[$field_id.'__to']) && $vals[$field_id.'__to'])
						$this->crits['<='.$filter_id] = $vals[$field_id.'__to'].' 23:59:59';
					continue;
				}
                if (!isset($text_filters[$filter_id])) {
                    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)
							$this->crits[preg_replace('/[^a-z0-9]/','_',strtolower(array_shift($param)))] = $v;
					} else {
						$this->crits[$filter_id] = $vals['filter__'.$filter_id];
                        if ($this->table_rows[$filter]['type']=='checkbox' && $this->crits[$filter_id]=='') $this->crits[$filter_id] = array(null,0);
					}
                } else {
                    if (!isset($vals['filter__'.$filter_id])) $vals['filter__'.$filter_id]='';
                    if ($vals['filter__'.$filter_id]!=='') {
                        $args = $this->table_rows[$filter];
                        $str = explode(';', $args['param']);
                        $ref = explode('::', $str[0]);
                        if ($ref[0]!='' && isset($ref[1])) $this->crits['_"'.$args['id'].'['.$args['ref_field'].']'] = DB::Concat(DB::qstr($vals['filter__'.$filter_id]),DB::qstr('%'));;
                        if ($args['type']=='commondata' || $ref[0]=='__COMMON__') {
							$val = array_pop(explode('/',$vals['filter__'.$filter_id]));
                            if (!isset($ref[1]) || $ref[0]=='__COMMON__') $this->crits['_"'.$args['id'].'['.$args['ref_field'].']'] = DB::Concat(DB::qstr($val),DB::qstr('%'));;
                        }
                    }
                }
            }
        }
		foreach ($this->crits as $k=>$c) if ($c===$this->crm_perspective_default()) {
			$this->crits[$k] = explode(',',trim(CRM_FiltersCommon::get(),'()'));
			if (isset($this->crits[$k][0]) && $this->crits[$k][0]=='') unset($this->crits[$k]);
		}

        $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');
        $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 (!$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');
    }
Exemple #6
0
	function setValue($value) {
		$val = explode('__',$value);
		$this->updateAttributes(array('value'=>str_replace('.',Utils_CurrencyFieldCommon::get_decimal_point(),$val[0])));
		if (isset($val[1])) $this->currency = $val[1];
		// TODO: float or string? If float is to be accepted, then conversion is neccessary
	} // end func setValue
 public static function load_js()
 {
     self::load_cache();
     load_js('modules/Utils/CurrencyField/currency.js');
     $currencies = Utils_CurrencyFieldCommon::get_all_currencies();
     $js = 'Utils_CurrencyField.currencies=new Array();';
     foreach ($currencies as $k => $v) {
         $symbol = Utils_CurrencyFieldCommon::get_symbol($k);
         $position = Utils_CurrencyFieldCommon::get_symbol_position($k);
         $curr_format = '-?([0-9]*)\\' . Utils_CurrencyFieldCommon::get_decimal_point($k) . '?[0-9]{0,' . Utils_CurrencyFieldCommon::get_precission($k) . '}';
         $js .= 'Utils_CurrencyField.currencies[' . $k . ']={' . '"decp":"' . Utils_CurrencyFieldCommon::get_decimal_point($k) . '",' . '"thop":"' . Utils_CurrencyFieldCommon::get_thousand_point($k) . '",' . '"symbol_before":"' . ($position ? $symbol : '') . '",' . '"symbol_after":"' . (!$position ? $symbol : '') . '",' . '"dec_digits":' . Utils_CurrencyFieldCommon::get_precission($k) . ',' . '"regex":' . json_encode($curr_format) . '};';
     }
     eval_js_once($js);
 }
 /**
  * Parse currency using existing currencies set in the system.
  *
  * @param $string Currency string to parse
  *
  * @return array|null null on failure and array(value, currency_id) on success - like get_values returns.
  */
 public static function parse_currency($string) {
     $string = html_entity_decode($string);
     $string = preg_replace('/[\pZ\pC\s]/u', '', $string); // remove whitespaces, including unicode nbsp
     $currencies = Utils_CurrencyFieldCommon::get_currencies();
     foreach (array_keys($currencies) as $cur_id) {
         $symbol = Utils_CurrencyFieldCommon::get_symbol($cur_id);
         $symbol_pos_before = Utils_CurrencyFieldCommon::get_symbol_position($cur_id);
         // check for symbol
         if ($symbol_pos_before) {
             if (strpos($string, $symbol) === 0) {
                 $string = substr($string, strlen($symbol));
             } else continue;
         } else {
             $pos_of_sym = strlen($string) - strlen($symbol);
             if (strrpos($string, $symbol) == $pos_of_sym) {
                 $string = substr($string, 0, $pos_of_sym);
             } else continue;
         }
         // separate by decimal point
         $exp = explode(Utils_CurrencyFieldCommon::get_decimal_point($cur_id), $string);
         if (count($exp) > 2)
             continue;
         $fraction = count($exp) == 2 ? $exp[1] : '0';
         $int = $exp[0];
         if (!preg_match('/^\d+$/', $fraction))
             continue;
         $th_point = Utils_CurrencyFieldCommon::get_thousand_point($cur_id);
         if (strlen($th_point)) {
             $thparts = explode($th_point, $int);
             if (count($thparts) > 1) {
                 for ($i = 1; $i < count($thparts); $i++)
                     if (strlen($thparts[$i]) != 3)
                         continue 2;
             }
             $int = str_replace($th_point, '', $int);
         }
         if (preg_match('/^\d+$/', $int)) {
             return array($int . '.' . $fraction, $cur_id);
         }
     }
     return null;
 }
Exemple #9
0
 protected static function get_currency_by_code($currency_code)
 {
     $currency_id = Utils_CurrencyFieldCommon::get_id_by_code($currency_code);
     if (!is_numeric($currency_id)) {
         $msg = "Currency with code: {$currency_code} doesn't exist in the system.";
         throw new Utils_CurrencyField_CurrencyNotFoundException($msg);
     }
     return $currency_id;
 }