Exemplo n.º 1
0
 public static function set_profile($prof)
 {
     if (preg_match('/^c([0-9,]+)$/', $prof, $reqs)) {
         $ret = $reqs[1];
         if (strpos($ret, ',') === false) {
             $desc = CRM_ContactsCommon::contact_format_no_company($ret, true);
         } else {
             $desc = __('Custom filter');
         }
     } elseif (is_numeric($prof)) {
         $cids = DB::GetAssoc('SELECT contact_id, contact_id FROM crm_filters_contacts');
         $c = DB::GetCol('SELECT p.contact_id FROM crm_filters_contacts p WHERE p.group_id=%d', array($prof));
         if ($c) {
             $ret = implode(',', $c);
         } else {
             $ret = '-1';
         }
         $desc = DB::GetOne('SELECT name FROM crm_filters_group WHERE id=%d', array($prof));
     } elseif ($prof == 'my') {
         $ret = CRM_FiltersCommon::get_my_profile();
         $desc = __('My records');
     } else {
         //all and undefined
         $ret = '';
         /*$contacts = Utils_RecordBrowserCommon::get_records('contact', array(), array(), array('last_name'=>'ASC'));
         		$contacts_select = array();
         		foreach($contacts as $v)
         			$contacts_select[] = $v['id'];
         		if($contacts_select)
         			$ret = implode(',',$contacts_select);
         		else
         			$ret = '-1';*/
         $desc = __('All records');
     }
     //		$this->set_module_variable('profile',$ret);
     $_SESSION['client']['filter_' . Acl::get_user()]['value'] = $ret;
     $_SESSION['client']['filter_' . Acl::get_user()]['desc'] = $desc;
     location(array());
 }
Exemplo n.º 2
0
 public function body()
 {
     if (!Acl::is_user()) {
         return;
     }
     $th = $this->init_module('Base/Theme');
     eval_js_once('crm_filters_deactivate = function(){leightbox_deactivate(\'crm_filters\');}');
     $th->assign('my', '<a ' . $this->create_callback_href(array('CRM_FiltersCommon', 'set_profile'), 'my') . ' id="crm_filters_my">' . __('My records') . '</a>');
     eval_js('Event.observe(\'crm_filters_my\',\'click\', crm_filters_deactivate)');
     /*$th->assign('all','<a '.$this->create_callback_href(array('CRM_FiltersCommon','set_profile'),'all').' id="crm_filters_all">'.__('All records').'</a>');
     		eval_js('Event.observe(\'crm_filters_all\',\'click\', crm_filters_deactivate)');*/
     $th->assign('manage', '<a ' . $this->create_callback_href(array($this, 'manage_filters')) . ' id="crm_filters_manage">' . __('Manage presets') . '</a>');
     eval_js('Event.observe(\'crm_filters_manage\',\'click\', crm_filters_deactivate)');
     $ret = DB::Execute('SELECT id,name,description FROM crm_filters_group WHERE user_login_id=%d', array(Acl::get_user()));
     $filters = array();
     while ($row = $ret->FetchRow()) {
         $filters[] = array('title' => $row['name'], 'description' => '', 'open' => '<a ' . Utils_TooltipCommon::open_tag_attrs($row['description'], false) . ' ' . $this->create_callback_href(array('CRM_FiltersCommon', 'set_profile'), $row['id']) . ' id="crm_filters_' . $row['id'] . '">', 'close' => '</a>');
         eval_js('Event.observe(\'crm_filters_' . $row['id'] . '\',\'click\', crm_filters_deactivate)');
     }
     $th->assign('filters', $filters);
     $qf = $this->init_module('Libs/QuickForm');
     $fcallback = array('CRM_ContactsCommon', 'contact_format_no_company');
     $recent_crits = array();
     if (!Base_User_SettingsCommon::get('CRM_Contacts', 'show_all_contacts_in_filters')) {
         $recent_crits = array('(company_name' => CRM_ContactsCommon::get_main_company(), '|related_companies' => array(CRM_ContactsCommon::get_main_company()));
     }
     if (Base_User_SettingsCommon::get('CRM_Contacts', 'show_only_users_in_filters')) {
         $recent_crits['!login'] = '';
     }
     $contacts = CRM_ContactsCommon::get_contacts($recent_crits, array(), array(), 15);
     $cont = array();
     foreach ($contacts as $v) {
         $cont[$v['id']] = call_user_func($fcallback, $v, true);
     }
     asort($cont);
     $crits = array();
     if (!Base_User_SettingsCommon::get('CRM_Contacts', 'show_all_contacts_in_filters')) {
         $crits = array('(company_name' => CRM_ContactsCommon::get_main_company(), '|related_companies' => array(CRM_ContactsCommon::get_main_company()));
     }
     $qf->addElement('autoselect', 'crm_filter_contact', __('Records of'), $cont, array(array('CRM_ContactsCommon', 'autoselect_contact_suggestbox'), array($crits, $fcallback, false)), $fcallback);
     if (isset($_SESSION['client']['filter_' . Acl::get_user()]['value'])) {
         $qf->setDefaults(array('crm_filter_contact' => explode(',', $_SESSION['client']['filter_' . Acl::get_user()]['value'])));
     }
     $qf->addElement('submit', 'submit', __('Show'), array('onclick' => 'crm_filters_deactivate()'));
     if ($qf->validate()) {
         $c = $qf->exportValue('crm_filter_contact');
         CRM_FiltersCommon::set_profile('c' . $c);
         location(array());
     }
     $th->assign('saved_filters', __('Saved Presets'));
     $qf->assign_theme('contacts', $th);
     //$th->assign('contacts',$qf->toHtml());
     ob_start();
     $th->display();
     $profiles_out = ob_get_clean();
     Libs_LeightboxCommon::display('crm_filters', $profiles_out, __('Perspective'), true);
     if (!isset($_SESSION['client']['filter_' . Acl::get_user()]['desc'])) {
         CRM_FiltersCommon::set_profile('my');
     }
     //Base_ActionBarCommon::add('folder',__('Filters'),'class="lbOn" rel="crm_filters"',$this->get_module_variable('profile_desc',__('My records')));
     if (isset($_REQUEST['__location'])) {
         $in_use = CRM_FiltersCommon::$in_use === $_REQUEST['__location'];
     } else {
         $in_use = CRM_FiltersCommon::$in_use;
     }
     print '<a class="lbOn' . ($in_use ? '' : ' disabled') . ' button" rel="crm_filters">' . __('Perspective') . ': ' . '<b>' . $_SESSION['client']['filter_' . Acl::get_user()]['desc'] . '</b><div class="filter_icon_img"></div></a>';
 }
Exemplo n.º 3
0
 public static function crm_event_get_all($start, $end, $filter = null, $customers = null)
 {
     $start = date('Y-m-d', Base_RegionalSettingsCommon::reg2time($start));
     $crits = array();
     if ($filter === null) {
         $filter = CRM_FiltersCommon::get();
     }
     $f_array = explode(',', trim($filter, '()'));
     if ($filter != '()' && $filter) {
         $crits['(' . 'employees'] = $f_array;
     }
     if ($customers && !empty($customers)) {
         $crits['|customers'] = $customers;
     } elseif ($filter != '()' && $filter) {
         $crits['|customers'] = $f_array;
         foreach ($crits['|customers'] as $k => $v) {
             $crits['|customers'][$k] = 'P:' . $v;
         }
     }
     $crits['<=deadline'] = $end;
     $crits['>=deadline'] = $start;
     $ret = Utils_RecordBrowserCommon::get_records('task', $crits, array(), array(), CRM_CalendarCommon::$events_limit);
     $result = array();
     foreach ($ret as $r) {
         $result[] = self::crm_event_get($r);
     }
     return $result;
 }
Exemplo n.º 4
0
 public static function crm_event_get_all($start, $end, $filter = null, $customers = null)
 {
     $start = date('Y-m-d', Base_RegionalSettingsCommon::reg2time($start));
     $crits = array();
     if ($filter === null) {
         $filter = CRM_FiltersCommon::get();
     }
     $f_array = explode(',', trim($filter, '()'));
     if ($filter != '()' && $filter) {
         $crits['(' . 'employees'] = $f_array;
     }
     if ($customers && !empty($customers)) {
         $crits['|customers'] = $customers;
     } elseif ($filter != '()' && $filter) {
         $crits['|customers'] = $f_array;
         foreach ($crits['|customers'] as $k => $v) {
             $crits['|customers'][$k] = 'P:' . $v;
         }
     }
     $critsb = $crits;
     $crits['<=date'] = $end;
     $crits['>=date'] = $start;
     $crits['recurrence_type'] = '';
     $count = 0;
     $ret = Utils_RecordBrowserCommon::get_records('crm_meeting', $crits, array(), array('date' => 'DESC', 'time' => 'DESC'), CRM_CalendarCommon::$events_limit);
     $result = array();
     foreach ($ret as $r) {
         $result[] = self::crm_event_get($r);
     }
     $count += count($result);
     $crits = $critsb;
     $crits['<=date'] = $end;
     $crits['(>=recurrence_end'] = $start;
     $crits['|recurrence_end'] = '';
     $crits['!recurrence_type'] = '';
     $ret = Utils_RecordBrowserCommon::get_records('crm_meeting', $crits, array(), array(), CRM_CalendarCommon::$events_limit);
     $day = strtotime($start);
     $end = strtotime($end);
     while ($day <= $end) {
         foreach ($ret as $r) {
             $next = self::crm_event_get($r, date('Y-m-d', $day));
             if ($next) {
                 $result[] = $next;
                 $count++;
                 if ($count == CRM_CalendarCommon::$events_limit) {
                     break;
                 }
             }
         }
         $day = strtotime('+1 day', $day);
     }
     return $result;
 }
Exemplo n.º 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');
    }
Exemplo n.º 6
0
 public function applet($conf, &$opts)
 {
     $opts['go'] = true;
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'agendaX');
     $columns = array(array('name' => __('Start'), 'order' => 'e.starts', 'width' => 25, 'wrapmode' => 'nowrap'), array('name' => __('Title'), 'order' => 'e.title', 'width' => 50));
     $gb->set_table_columns($columns);
     $start = date('Y-m-d', time());
     $end = date('Y-m-d', time() + $conf['days'] * 24 * 60 * 60);
     $gb->set_default_order(array(__('Start') => 'ASC'));
     CRM_Calendar_EventCommon::$filter = '(' . CRM_FiltersCommon::get_my_profile() . ')';
     $data = array();
     Base_ThemeCommon::load_css('CRM_Calendar', 'agenda');
     $custom_events = DB::GetAssoc('SELECT id, handler_callback FROM crm_calendar_custom_events_handlers ORDER BY group_name');
     $ret = array();
     if (!empty($custom_events)) {
         $c = 0;
         foreach ($custom_events as $id => $cb) {
             if ($conf['events_handlers__' . $id]) {
                 $cb = explode('::', $cb);
                 if (!is_callable($cb)) {
                     continue;
                 }
                 $add = call_user_func($cb, 'get_all', $start, $end, CRM_Calendar_EventCommon::$filter);
                 foreach ($add as $v) {
                     $ret[str_pad($v['start'], 16, '0', STR_PAD_LEFT) . '__' . $c] = $v;
                     $c++;
                 }
             }
         }
     }
     ksort($ret);
     foreach ($ret as $row) {
         if (isset($row['status']) && $row['status'] == 'closed') {
             continue;
         }
         if (!isset($row['view_action'])) {
             $ex = Utils_CalendarCommon::process_event($row);
             $view_action = '<a ' . $this->create_callback_href(array($this, 'view_event'), $row['id']) . '>';
             $ev_id = explode('_', $row['id'], 2);
             $ev_id = $ev_id[0];
         } else {
             $tmp = Utils_CalendarCommon::process_event($row);
             $ex = $row;
             $ex['start'] = $tmp['start'];
             $view_action = '<a ' . $row['view_action'] . '>';
         }
         //////////////////////////
         // left column
         $date = $ex['start'];
         ///////////////////
         // right column
         $title = Utils_TooltipCommon::create($row['title'], $row['custom_tooltip']);
         $day = isset($row['timeless']) && $row['timeless'] ? $row['timeless'] : Base_RegionalSettingsCommon::time2reg($row['start'], false, true, true, false);
         if ($day < date('Y-m-d')) {
             $class = 'past';
         } elseif ($day == date('Y-m-d')) {
             $class = 'today';
         } elseif ($day == date('Y-m-d', strtotime('+1 day'))) {
             $class = 'tomorrow';
         } else {
             $class = 'other';
         }
         $gb_row = $gb->get_new_row();
         $gb_row->set_attrs('class="CRM_Calendar_applet__' . $class . '"');
         $gb_row->add_data(array('value' => $date, 'order_value' => isset($row['timeless']) && $row['timeless'] ? strtotime($row['timeless']) : $row['start']), array('value' => $view_action . $title . '</a>'));
     }
     $this->display_module($gb, array(false), 'automatic_display');
 }
Exemplo n.º 7
0
 public static function crits_special_values()
 {
     $perspective = trim(CRM_FiltersCommon::get(), '()');
     $perspective = empty($perspective) ? null : explode(',', $perspective);
     return new Utils_RecordBrowser_ReplaceValue('__PERSPECTIVE__', __('Perspective'), $perspective, true);
 }
Exemplo n.º 8
0
 public static function submit_contact($values, $mode)
 {
     switch ($mode) {
         case 'cloning':
             $values['login'] = '';
             return $values;
         case 'display':
             // display copy company data button and do update if needed
             self::copy_company_data_subroutine($values);
             $is_employee = false;
             if (isset($values['related_companies']) && is_array($values['related_companies']) && in_array(CRM_ContactsCommon::get_main_company(), $values['related_companies'])) {
                 $is_employee = true;
             }
             if (isset($values['company_name']) && $values['company_name'] == CRM_ContactsCommon::get_main_company()) {
                 $is_employee = true;
             }
             $me = CRM_ContactsCommon::get_my_record();
             $emp = array($me['id']);
             $cus = array();
             if ($is_employee) {
                 $emp[] = $values['id'];
             } else {
                 $cus[] = 'P:' . $values['id'];
             }
             $ret = array();
             $ret['new'] = array();
             $ret['new']['crm_filter'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('Set CRM Filter')) . ' ' . Module::create_href(array('set_crm_filter' => 1)) . '>F</a>';
             if (isset($_REQUEST['set_crm_filter'])) {
                 CRM_FiltersCommon::set_profile('c' . $values['id']);
             }
             if (ModuleManager::is_installed('CRM/Meeting') !== -1 && Utils_RecordBrowserCommon::get_access('crm_meeting', 'add')) {
                 $ret['new']['event'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Meeting')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('crm_meeting', array('employees' => $emp, 'customers' => $cus, 'status' => 0, 'priority' => 1, 'permission' => 0)) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Calendar', 'icon-small.png') . '"></a>';
             }
             if (ModuleManager::is_installed('CRM/Tasks') !== -1 && Utils_RecordBrowserCommon::get_access('task', 'add')) {
                 $ret['new']['task'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Task')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('task', array('employees' => $emp, 'customers' => $cus, 'status' => 0, 'priority' => 1, 'permission' => 0)) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Tasks', 'icon-small.png') . '"></a>';
             }
             if (ModuleManager::is_installed('CRM/PhoneCall') !== -1 && Utils_RecordBrowserCommon::get_access('phonecall', 'add')) {
                 $ret['new']['phonecall'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Phonecall')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('phonecall', array('date_and_time' => date('Y-m-d H:i:s'), 'customer' => 'P:' . $values['id'], 'employees' => $me['id'], 'status' => 0, 'permission' => 0, 'priority' => 1), 'none', false) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_PhoneCall', 'icon-small.png') . '"></a>';
             }
             $ret['new']['note'] = Utils_RecordBrowser::$rb_obj->add_note_button('contact/' . $values['id']);
             return $ret;
         case 'adding':
             $values['permission'] = Base_User_SettingsCommon::get('CRM_Common', 'default_record_permission');
             break;
         case 'add':
             if (isset($values['email']) && $values['email'] == '' && $values['login'] != 0 && $mode == 'add') {
                 $values['email'] = DB::GetOne('SELECT mail FROM user_password WHERE user_login_id=%d', array($values['login']));
             }
         case 'edit':
             if (isset($values['create_company'])) {
                 $comp_id = Utils_RecordBrowserCommon::new_record('company', array('company_name' => $values['create_company_name'], 'address_1' => $values['address_1'], 'address_2' => $values['address_2'], 'country' => $values['country'], 'city' => $values['city'], 'zone' => isset($values['zone']) ? $values['zone'] : '', 'postal_code' => $values['postal_code'], 'phone' => $values['work_phone'], 'fax' => $values['fax'], 'web_address' => $values['web_address'], 'permission' => $values['permission']));
                 if (!isset($values['company_name'])) {
                     $values['company_name'] = null;
                 }
                 if (!isset($values['related_companies'])) {
                     $values['related_companies'] = array();
                 }
                 if (!is_array($values['related_companies'])) {
                     $values['related_companies'] = array($values['related_companies']);
                 }
                 if (!$values['company_name']) {
                     $values['company_name'] = $comp_id;
                 } else {
                     $values['related_companies'][] = $comp_id;
                 }
             }
             if (Base_AclCommon::i_am_admin()) {
                 if ($values['login'] == 'new') {
                     if (!$values['set_password']) {
                         $values['set_password'] = null;
                     }
                     Base_User_LoginCommon::add_user($values['username'], $values['email'], $values['set_password']);
                     $values['login'] = Base_UserCommon::get_user_id($values['username']);
                 } else {
                     if ($values['login']) {
                         Base_User_LoginCommon::change_user_preferences($values['login'], isset($values['email']) ? $values['email'] : '', isset($values['set_password']) ? $values['set_password'] : null);
                         if (isset($values['username']) && $values['username']) {
                             Base_UserCommon::rename_user($values['login'], $values['username']);
                         }
                     }
                 }
                 if (Base_AclCommon::i_am_sa() && $values['login'] && isset($values['admin']) && $values['admin'] !== '') {
                     $old_admin = Base_AclCommon::get_admin_level($values['login']);
                     if ($old_admin != $values['admin']) {
                         $admin_arr = array(0 => 'No', 1 => 'Administrator', 2 => 'Super Administrator');
                         if (Base_UserCommon::change_admin($values['login'], $values['admin']) !== true) {
                             Utils_RecordBrowserCommon::new_record_history('contact', $values['id'], 'Admin set from "' . $admin_arr[$old_admin] . '" to "' . $admin_arr[$values['admin']]);
                         }
                     }
                 }
             }
             unset($values['admin']);
             unset($values['username']);
             unset($values['set_password']);
             unset($values['confirm_password']);
     }
     return $values;
 }
Exemplo n.º 9
0
 public static function mobile_agenda($time_shift = 0)
 {
     print '<center>' . Base_RegionalSettingsCommon::time2reg(time() + $time_shift, false, true) . ' - ' . Base_RegionalSettingsCommon::time2reg(time() + 7 * 24 * 3600 + $time_shift, false, true) . '</center>';
     CRM_Calendar_EventCommon::$filter = CRM_FiltersCommon::get();
     if ($time_shift) {
         print '<a ' . (IPHONE ? 'class="button red" ' : '') . mobile_stack_href(array('CRM_CalendarCommon', 'mobile_agenda'), array(0)) . '>' . __('Show current week') . '</a>';
     } else {
         print '<a ' . (IPHONE ? 'class="button green" ' : '') . mobile_stack_href(array('CRM_CalendarCommon', 'mobile_agenda'), array(7 * 24 * 60 * 60)) . '>' . __('Show next week') . '</a>';
     }
     Utils_CalendarCommon::mobile_agenda(CRM_Calendar_Event::module_name(), array('custom_agenda_cols' => array(__('Description'), __('Assigned to'), __('Related with'))), $time_shift, array('CRM_CalendarCommon', 'mobile_view_event'));
 }
Exemplo n.º 10
0
 public static function get_slot_crits($slot, $tray_settings)
 {
     $crits = array();
     $trans_callbacks = isset($tray_settings['__trans_callbacks__']) ? $tray_settings['__trans_callbacks__'] : null;
     $record_filters = isset($slot['__filters__']) ? $slot['__filters__'] : array();
     foreach ($record_filters as $field => $val) {
         $trans_callback = null;
         if (isset($trans_callbacks[$field])) {
             $trans_callback = is_array($trans_callbacks[$field]) ? implode('::', $trans_callbacks[$field]) : $trans_callbacks[$field];
         }
         $record_crits = is_callable($trans_callback) ? call_user_func($trans_callback, $val, $field) : array($field => $val);
         $crits += is_array($record_crits) ? $record_crits : array();
     }
     foreach ($crits as $k => $c) {
         if ($c === '__PERSPECTIVE__') {
             $crits[$k] = explode(',', trim(CRM_FiltersCommon::get(), '()'));
             if (isset($crits[$k][0]) && $crits[$k][0] == '') {
                 unset($crits[$k]);
             }
         }
     }
     return $crits;
 }