public static function submit_task($values, $mode) { $me = CRM_ContactsCommon::get_my_record(); switch ($mode) { case 'display': $values['title'] = __('Follow-up') . ': ' . $values['title']; $values['status'] = 0; $values['deadline'] = date('Y-m-d', strtotime('+1 day')); $ret = array(); $cus = reset($values['customers']); if (ModuleManager::is_installed('CRM/Meeting') >= 0) { $ret['new']['event'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Meeting')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('crm_meeting', 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, 'employees' => $values['employees'], 'customers' => $values['customers'], 'status' => 0), 'none', false) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Calendar', 'icon-small.png') . '" /></a>'; } $ret['new']['task'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Task')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('task', $values) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Tasks', 'icon-small.png') . '" /></a>'; if (ModuleManager::is_installed('CRM/PhoneCall') >= 0) { $ret['new']['phonecall'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Phonecall')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('phonecall', 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'], 'customer' => $cus, 'status' => 0), '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('task/' . $values['id']); return $ret; case 'adding': $values['deadline_time'] = strtotime(date('Y-m-d') . ' 23:59:59'); $values['permission'] = Base_User_SettingsCommon::get('CRM_Common', 'default_record_permission'); break; case 'add': break; case 'edit': $old_values = Utils_RecordBrowserCommon::get_record('task', $values['id']); $old_related = array_merge($old_values['employees'], $old_values['customers']); case 'added': if (isset($values['follow_up'])) { CRM_FollowupCommon::add_tracing_notes($values['follow_up'][0], $values['follow_up'][1], $values['follow_up'][2], 'task', $values['id'], $values['title']); } self::subscribed_employees($values); $related = array_merge($values['employees'], $values['customers']); foreach ($related as $v) { if ($mode === 'edit' && in_array($v, $old_related)) { continue; } if (!is_numeric($v)) { list($t, $id) = explode(':', $v); } else { $t = 'P'; $id = $v; } if ($t == 'P') { $t = 'contact'; } else { $t = 'company'; } $subs = Utils_WatchdogCommon::get_subscribers($t, $id); foreach ($subs as $s) { Utils_WatchdogCommon::user_subscribe($s, 'task', $values['id']); } } break; } return $values; }
public static function applet_new_record_button($tab, $defaults = array()) { if (!self::get_access($tab, 'add')) { return ''; } return '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New record')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href($tab, $defaults) . '><img src="' . Base_ThemeCommon::get_template_file('Utils_RecordBrowser', 'add.png') . '" border="0"></a>'; }
public static function submit_meeting($values, $mode) { $me = CRM_ContactsCommon::get_my_record(); switch ($mode) { case 'delete': Utils_MessengerCommon::delete_by_id('CRM_Calendar_Event:' . $values['id']); break; case 'display': $pdf = Utils_RecordBrowser::$rb_obj->pack_module('Libs/TCPDF', 'L'); if ($pdf->prepare()) { $pdf->set_title($values['title']); $pdf->set_subject(''); $pdf->prepare_header(); $pdf->AddPage(); $v = CRM_Calendar_EventCommon::get(DB::GetOne('SELECT id FROM crm_calendar_custom_events_handlers WHERE group_name=%s', array('Meetings')) . '#' . $values['id']); $ev_mod = Utils_RecordBrowser::$rb_obj->init_module('CRM/Calendar/Event'); $ev_mod->make_event_PDF($pdf, $v, true, 'view'); } $pdf->add_actionbar_icon('Print'); if (isset($_REQUEST['day'])) { $values['date'] = $_REQUEST['day']; } $ret = array(); if ($values['time']) { // normal event $start = $values['time']; // time in unix timestamp UTC $start_disp = strtotime(Base_RegionalSettingsCommon::time2reg($start, true, true, true, false)); } else { // when event is timeless - all day event $time = $values['date'] . ' 00:00:01'; $start = Base_RegionalSettingsCommon::reg2time($time); $start_disp = strtotime($time); } $end = strtotime('+' . $values['duration'] . ' seconds', $start); $ret['day_details'] = array('start' => array('day' => '<a ' . Base_BoxCommon::create_href(null, 'CRM/Calendar', 'body', array(array('default_view' => 'day', 'default_date' => strtotime($values['date']))), array()) . '>' . date('j', $start_disp) . '</a>', 'month' => '<a ' . Base_BoxCommon::create_href(null, 'CRM/Calendar', 'body', array(array('default_view' => 'month', 'default_date' => strtotime($values['date']))), array()) . '>' . __date('F', $start_disp) . '</a>', 'year' => '<a ' . Base_BoxCommon::create_href(null, 'CRM/Calendar', 'body', array(array('default_view' => 'year', 'default_date' => strtotime($values['date']))), array()) . '>' . date('Y', $start_disp) . '</a>', 'weekday' => '<a ' . Base_BoxCommon::create_href(null, 'CRM/Calendar', 'body', array(array('default_view' => 'week', 'default_date' => strtotime($values['date']))), array()) . '>' . __date('l', $start_disp) . '</a>')); if (!isset($values['timeless']) || !$values['timeless']) { $ret['event_info'] = array('start_time' => Base_RegionalSettingsCommon::time2reg($start, 2, false), 'end_time' => Base_RegionalSettingsCommon::time2reg($end, 2, false), 'duration' => Base_RegionalSettingsCommon::seconds_to_words($values['duration']), 'start_date' => '-', 'end_date' => '-'); } $ret['form_data']['timeless'] = array('label' => __('Timeless'), 'html' => 'value'); $ret['toggle_duration'] = 'tog'; $ret['duration_block_id'] = '1'; $ret['event_end_block_id'] = '2'; $values['title'] = __('Follow-up') . ': ' . $values['title']; $values['status'] = 0; $cus = reset($values['customers']); if (ModuleManager::is_installed('CRM/Meeting') >= 0) { $ret['new']['event'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Meeting')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('crm_meeting', 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, 'employees' => $values['employees'], 'customers' => $values['customers'], 'status' => 0), 'none', false) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Calendar', 'icon-small.png') . '" /></a>'; } if (ModuleManager::is_installed('CRM/Tasks') >= 0) { $ret['new']['task'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Task')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('task', array('title' => $values['title'], 'permission' => $values['permission'], 'priority' => $values['priority'], 'description' => $values['description'], 'employees' => $values['employees'], 'customers' => $values['customers'], 'status' => 0, 'deadline' => date('Y-m-d', strtotime('+1 day')))) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Tasks', 'icon-small.png') . '"></a>'; } if (ModuleManager::is_installed('CRM/PhoneCall') >= 0) { $ret['new']['phonecall'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Phonecall')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('phonecall', 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'], 'customer' => $cus, 'status' => 0), '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('crm_meeting/' . $values['id']); return $ret; case 'edit': self::subscribed_employees($values); $alarms = Utils_MessengerCommon::get_alarms('CRM_Calendar_Event:' . $values['id']); $old = Utils_RecordBrowserCommon::get_record('crm_meeting', $values['id']); $old_time = strtotime($old['date'] . ' ' . date('H:i:s', strtotime($old['time']))); $new_time = strtotime($values['date'] . ' ' . date('H:i:s', strtotime($values['time']))); foreach ($alarms as $id => $time) { $time = strtotime($time); $diff = $old_time - $time; Utils_MessengerCommon::update_time($id, $new_time - $diff); } case 'add': if (isset($values['duration_switch']) && !$values['duration_switch']) { $values['duration'] = strtotime($values['end_time']) - strtotime($values['time']); if ($values['duration'] < 0) { $values['duration'] += 60 * 60 * 24; } // failsafe } if (isset($values['timeless']) && $values['timeless']) { $values['duration'] = -1; } $new = ''; foreach (array(0 => 'Mon', 1 => 'Tue', 2 => 'Wed', 3 => 'Thu', 4 => 'Fri', 5 => 'Sat', 6 => 'Sun') as $k => $v) { if (isset($values['recurrence_hash_' . $k]) && $values['recurrence_hash_' . $k]) { $new .= '1'; } else { $new .= '0'; } } if ($new != '0000000') { $values['recurrence_hash'] = $new; } if ($values['duration'] != -1) { if (isset($values['modded'])) { $time = Base_RegionalSettingsCommon::time2reg($values['time'], true, true, true, false); $reg_timestamp = $values['date'] . ' ' . date('H:i:s', strtotime($time)); $timestamp = Base_RegionalSettingsCommon::reg2time($reg_timestamp); $values['date'] = date('Y-m-d', $timestamp); $values['time'] = date('Y-m-d H:i:s', $timestamp); if (isset($values['recurrence_end']) && $values['recurrence_end']) { $values['recurrence_end'] = date('Y-m-d', Base_RegionalSettingsCommon::reg2time($values['recurrence_end'] . ' ' . date('H:i:s', strtotime($time)))); if ($values['recurrence_end'] < $values['date']) { $values['recurrence_end'] = $values['date']; } if ($values['recurrence_type'] == 8) { $date = date('Y-m-d', strtotime('+6 days', strtotime($values['date']))); if ($values['recurrence_end'] < $date) { $values['recurrence_end'] = $date; } } } } } else { $values['time'] = ''; } break; case 'adding': $values['permission'] = Base_User_SettingsCommon::get('CRM_Common', 'default_record_permission'); case 'editing': case 'view': $values['modded'] = 1; if (!isset($values['date'])) { $values['date'] = date('Y-m-d'); } if (!isset($values['time'])) { $values['time'] = time(); } if (!isset($values['duration'])) { $values['duration'] = 3600; } if (!is_numeric($values['time'])) { $values['time'] = strtotime($values['time']); } if ($values['duration'] != -1) { if (isset($values['date']) && $values['date']) { $values['date'] = Base_RegionalSettingsCommon::time2reg($values['date'] . ' ' . date('H:i:s', $values['time']), false, true, true, false); $values['time'] = Base_RegionalSettingsCommon::time2reg($values['date'] . ' ' . date('H:i:s', $values['time']), true, false, true, false); $values['time'] = Base_RegionalSettingsCommon::reg2time($values['date'] . ' ' . $values['time']); } if (isset($values['recurrence_end']) && $values['recurrence_end']) { $values['recurrence_end'] = Base_RegionalSettingsCommon::time2reg($values['recurrence_end'] . ' ' . date('H:i:s', $values['time']), false, true, true, false); } } break; case 'added': if (isset($values['follow_up'])) { CRM_FollowupCommon::add_tracing_notes($values['follow_up'][0], $values['follow_up'][1], $values['follow_up'][2], 'meeting', $values['id'], $values['title']); } self::subscribed_employees($values); $related = array_merge($values['employees'], $values['customers']); foreach ($related as $v) { if ($mode === 'edit' && in_array($v, $old_related)) { continue; } if (!is_numeric($v)) { list($t, $id) = explode(':', $v); } else { $t = 'P'; $id = $v; } if ($t == 'P') { $t = 'contact'; } else { $t = 'company'; } $subs = Utils_WatchdogCommon::get_subscribers($t, $id); foreach ($subs as $s) { Utils_WatchdogCommon::user_subscribe($s, 'crm_meeting', $values['id']); } } if (isset($values['messenger_on']) && $values['messenger_on'] != 'none') { $start = strtotime($values['date'] . ' ' . date('H:i:s', strtotime($values['time']))); if ($values['messenger_on'] == 'me') { Utils_MessengerCommon::add('CRM_Calendar_Event:' . $values['id'], 'CRM_Meeting', $values['messenger_message'], $start - $values['messenger_before'], array('CRM_MeetingCommon', 'get_alarm'), array($values['id'])); } else { $eee = array(); foreach ($values['employees'] as $v) { $c = CRM_ContactsCommon::get_contact($v); if (isset($c['login'])) { $eee[] = $c['login']; } } Utils_MessengerCommon::add('CRM_Calendar_Event:' . $values['id'], 'CRM_Meeting', $values['messenger_message'], $start - $values['messenger_before'], array('CRM_MeetingCommon', 'get_alarm'), array($values['id']), $eee); } } break; } return $values; }
public function show_data($crits = array(), $cols = array(), $order = array(), $admin = false, $special = false, $pdf = false, $limit = null) { $this->help('RecordBrowser','main'); if (Utils_RecordBrowserCommon::$admin_access) $admin = true; if (isset($_SESSION['client']['recordbrowser']['admin_access'])) Utils_RecordBrowserCommon::$admin_access = true; if (self::$clone_result!==null && $this->jump_to_new_record) { if (is_numeric(self::$clone_result)) $this->navigate('view_entry', 'view', self::$clone_result); $clone_result = self::$clone_result; self::$clone_result = null; if ($clone_result!='canceled') return; } if ($this->check_for_jump()) return; Utils_RecordBrowserCommon::$cols_order = $this->col_order; if ($this->get_access('browse')===false) { print(__('You are not authorised to browse this data.')); return; } $this->init(); $this->action = 'Browse'; if (!Base_AclCommon::i_am_admin() && $admin) { print(__('You don\'t have permission to access this data.')); } if ($this->data_gb!==null) $gb = $this->data_gb; else $gb = $this->init_module('Utils/GenericBrowser', null, $this->tab); if(!$pdf) $gb->set_expandable(true); if($pdf) $gb->set_resizable_columns(false); else $gb->set_fixed_columns_class($this->fixed_columns_class); if ($special) { $gb_per_page = Base_User_SettingsCommon::get('Utils/GenericBrowser','per_page'); $gb->set_per_page(Base_User_SettingsCommon::get('Utils/RecordBrowser/RecordPicker','per_page')); } if (!$this->disabled['search']) { $gb->is_adv_search_on(); $is_searching = $gb->get_module_variable('search',''); if (!empty($is_searching)) { if ($this->get_module_variable('browse_mode')!='all' // || $gb->get_module_variable('quickjump_to')!=null ) { $this->set_module_variable('browse_mode','all'); // $gb->set_module_variable('quickjump_to',null); location(array()); return; } } } if ($special) { $table_columns = array(array('name'=>__('Select'), 'width'=>'40px')); } else { $table_columns = array(); if (!$pdf && !$admin && $this->favorites) { $fav = array('name'=>' ', 'width'=>'24px', 'attrs'=>'class="Utils_RecordBrowser__favs"'); if (!isset($this->force_order)) $fav['order'] = ':Fav'; $table_columns[] = $fav; } if (!$pdf && !$admin && $this->watchdog) $table_columns[] = array('name'=>'', 'width'=>'24px', 'attrs'=>'class="Utils_RecordBrowser__watchdog"'); } if (!$this->disabled['quickjump']) $quickjump = DB::GetOne('SELECT quickjump FROM recordbrowser_table_properties WHERE tab=%s', array($this->tab)); else $quickjump = ''; $hash = array(); $query_cols = array(); foreach($this->table_rows as $field => $args) { $hash[$args['id']] = $field; if ($field === 'id') continue; if ((!$args['visible'] && (!isset($cols[$args['id']]) || $cols[$args['id']] === false))) continue; if (isset($cols[$args['id']]) && $cols[$args['id']] === false) continue; $query_cols[] = $args['id']; $arr = array('name'=>$args['name']); if (!$pdf && !isset($this->force_order) && $this->browse_mode!='recent' && $args['type']!=='multiselect' && ($args['type']!=='calculated' || $args['param']!='') && $args['type']!=='hidden') $arr['order'] = $field; if ($args['type']=='checkbox' || (($args['type']=='date' || $args['type']=='timestamp' || $args['type']=='time') && !$this->add_in_table) || $args['type']=='commondata') { $arr['wrapmode'] = 'nowrap'; $arr['width'] = 50; } else { $arr['width'] = 100; } $arr['name'] = _V($arr['name']); // ****** Translate field name for table header if (isset($this->more_table_properties[$args['id']])) { foreach (array('name','wrapmode','width','display','order') as $v) if (isset($this->more_table_properties[$args['id']][$v])) { if (is_numeric($this->more_table_properties[$args['id']][$v]) && $v=='width') $this->more_table_properties[$args['id']][$v] = $this->more_table_properties[$args['id']][$v]*10; $arr[$v] = $this->more_table_properties[$args['id']][$v]; } } if (is_array($args['param'])) $str = explode(';', $args['param']['array_id']); else $str = explode(';', $args['param']); $ref = explode('::', $str[0]); $each = array(); if (!$pdf && $quickjump!=='' && $args['name']===$quickjump) $each[] = 'quickjump'; if (!$pdf && !$this->disabled['search']) $each[] = 'search'; foreach ($each as $e) { if ($args['type']=='text' || $args['type']=='currency' || $args['type'] == 'autonumber' || ($args['type']=='calculated' && preg_match('/^[a-z]+(\([0-9]+\))?$/i',$args['param'])!==0)) $arr[$e] = $args['id']; if (isset($args['ref_field']) && $args['ref_field']) $arr[$e] = $args['id']; if ($args['commondata'] && (!is_array($args['param']) || strpos($args['param']['array_id'],':')===false)) { $arr[$e] = $args['id']; } } if (isset($arr['quickjump'])) $arr['quickjump'] = '"~'.$arr['quickjump']; if ($pdf) { $arr['attrs'] = 'style="border:1px solid black;font-weight:bold;text-align:center;color:white;background-color:gray"'; if (!isset($arr['width'])) $arr['width'] = 100; if ($arr['width']==1) $arr['width'] = 100; } $table_columns[] = $arr; } if ($pdf) { $max = 0; $width_sum = 0; foreach ($table_columns as $k=>$v) if ($v['width']>$max) $max = $v['width']; foreach ($table_columns as $k=>$v) { $table_columns[$k]['width'] = intval($table_columns[$k]['width']); if ($table_columns[$k]['width']<$max/2) $table_columns[$k]['width'] = $max/2; $width_sum += $table_columns[$k]['width']; } $fraction = 0; foreach ($table_columns as $k=>$v) { $table_columns[$k]['width'] = floor(100*$v['width']/$width_sum); $fraction += 100*$v['width']/$width_sum - $table_columns[$k]['width']; if ($fraction>1) { $table_columns[$k]['width'] += 1; $fraction -= 1; } $table_columns[$k]['width'] = $table_columns[$k]['width'].'%'; } } if (empty($table_columns)) { print('Invalid view, no fields to display'); return; } $gb->set_table_columns( $table_columns ); if (!$pdf) { $clean_order = array(); foreach ($order as $k => $v) { if ($k[0] == ':') { $clean_order[$k] = $v; continue; } if(!in_array($k,$query_cols)) continue; if (isset($this->more_table_properties[$k]) && isset($this->more_table_properties[$k]['name'])) $key = $this->more_table_properties[$k]['name']; elseif (isset($hash[$k])) $key = $hash[$k]; else $key = $k; $clean_order[_V($key)] = $v; // TRSL } if ($this->browse_mode != 'recent') $gb->set_default_order($clean_order, $this->changed_view); } $search = $gb->get_search_query(true); $search_res = array(); if ($this->search_calculated_callback) { $search_res = call_user_func($this->search_calculated_callback, $search); } if ($gb->is_adv_search_on()) { foreach ($search as $k=>$v) { $f_id = str_replace(array('"','~'),'',$k); $args = $this->table_rows[$hash[$f_id]]; if ($args['commondata']) $k = $k.'[]'; elseif (isset($args['ref_field']) && $args['ref_field']) $k = $k.'['.Utils_RecordBrowserCommon::get_field_id($args['ref_field']).']'; if ($k[0]=='"') { $search_res['~_'.$k] = $v; continue; } if (is_array($v)) $v = $v[0]; $v = explode(' ', $v); foreach ($v as $w) { if (!$args['commondata']) { $w = DB::Concat(DB::qstr('%'),DB::qstr($w),DB::qstr('%')); $op = '"'; } else { $op = ''; } $search_res = Utils_RecordBrowserCommon::merge_crits($search_res, array('~'.$op.$k =>$w)); } } } else { $val = reset($search); $isearch = $gb->get_module_variable('search'); if (empty($isearch)) $val = null; $val2 = explode(' ', $val[0]); $leftovers = array(); foreach ($val2 as $vv) { foreach ($search as $k=>$v) { if ($v!=$val) { $leftovers[$k] = $v; continue; } if ($k[0]=='"') { $search_res['~_'.$k] = $vv; continue; } $args = $this->table_rows[$hash[trim($k, '(|')]]; if ($args['commondata']) $k = $k.'[]'; elseif (isset($args['ref_field']) && $args['ref_field']) $k = $k.'['.Utils_RecordBrowserCommon::get_field_id($args['ref_field']).']'; if (!$args['commondata']) { $w = DB::Concat(DB::qstr('%'),DB::qstr($vv),DB::qstr('%')); $op = '"'; } else { $w = $vv; $op = ''; } $search_res = Utils_RecordBrowserCommon::merge_crits($search_res, array('~'.$op.$k =>$w)); } } $search_res = Utils_RecordBrowserCommon::merge_crits($search_res, $leftovers); } if (!$pdf) $order = $gb->get_order(); $crits = array_merge($crits, $search_res); if ($this->browse_mode == 'favorites') $crits[':Fav'] = true; if ($this->browse_mode == 'watchdog') $crits[':Sub'] = true; if ($this->browse_mode == 'recent') { $crits[':Recent'] = true; $order = array(':Visited_on'=>'DESC'); } if ($admin && !$pdf) { $order = array(':Edited_on'=>'DESC'); $form = $this->init_module('Libs/QuickForm', null, $this->tab.'_admin_filter'); $form->addElement('select', 'show_records', __('Show records'), array(0=>'['.__('All').']',1=>'['.__('All active').']',2=>'['.__('All deactivated').']'), array('onchange'=>$form->get_submit_form_js())); $f = $this->get_module_variable('admin_filter', 0); $form->setDefaults(array('show_records'=>$f)); $admin_filter = $form->exportValue('show_records'); $this->set_module_variable('admin_filter', $admin_filter); switch($admin_filter) { case 0: Utils_RecordBrowserCommon::$admin_filter = ''; break; case 1: Utils_RecordBrowserCommon::$admin_filter = 'active=1 AND '; break; case 2: Utils_RecordBrowserCommon::$admin_filter = 'active=0 AND '; break; } $form->display_as_row(); } if (isset($this->force_order)) $order = $this->force_order; if (!$order) $order = array(); $this->amount_of_records = Utils_RecordBrowserCommon::get_records_count($this->tab, $crits, $admin, $order); if ($limit === null && !$this->disabled['pagination']) $limit = $gb->get_limit($this->amount_of_records); if (!$this->disabled['pdf'] && !$pdf && $this->get_access('print')) { $limited_print_records = 200; $limited_print = ($this->amount_of_records >= $limited_print_records); $print_limit = $limited_print ? $limit : null; $key = md5(serialize($this->tab).serialize($crits).serialize($cols).serialize($order).serialize($admin).serialize($print_limit)); $_SESSION['client']['utils_recordbrowser'][$key] = array( 'tab'=>$this->tab, 'crits'=>$crits, 'cols'=>$cols, 'order'=>$order, 'admin'=>$admin, 'more_table_properties'=>$this->more_table_properties, 'limit' => $print_limit, ); $print_href = 'href="modules/Utils/RecordBrowser/print.php?'.http_build_query(array('key'=>$key, 'cid'=>CID)).'" target="_blank"'; $print_tooltip_text = $limited_print ? __('Due to more than %d records, you are allowed to print current view', array($limited_print_records)) : __('Print all records'); $print_tooltip = Utils_TooltipCommon::open_tag_attrs($print_tooltip_text, false); $this->new_button('print', __('Print'), "$print_href $print_tooltip"); } $records = Utils_RecordBrowserCommon::get_records($this->tab, $crits, array(), $order, $limit, $admin); if (($this->get_access('export') || $this->enable_export) && !$this->disabled['export']) $this->new_button('save',__('Export'), 'href="modules/Utils/RecordBrowser/csv_export.php?'.http_build_query(array('tab'=>$this->tab, 'admin'=>$admin, 'cid'=>CID, 'path'=>$this->get_path())).'"'); $this->set_module_variable('crits_stuff',$crits?$crits:array()); $this->set_module_variable('order_stuff',$order?$order:array()); $custom_label = ''; if (!$pdf && !$special && $this->get_access('add',$this->custom_defaults)!==false) { if ($this->add_button!==null) $label = $this->add_button; elseif (!$this->multiple_defaults) $label = $this->create_callback_href(array($this, 'navigate'), array('view_entry', 'add', null, $this->custom_defaults)); else $label = Utils_RecordBrowserCommon::create_new_record_href($this->tab,$this->custom_defaults,'multi',true,true); if ($label!==false && $label!=='') $custom_label = '<a '.$label.'><span class="record_browser_add_new" '.Utils_TooltipCommon::open_tag_attrs(__('Add new record')).'><img src="'.Base_ThemeCommon::get_template_file('Utils/RecordBrowser/add.png').'" /><div class="add_new">'.__('Add new').'</div></span></a>'; } if ($this->more_add_button_stuff) { if ($custom_label) $custom_label = '<table><tr><td>'.$custom_label.'</td><td>'.$this->more_add_button_stuff.'</td></tr></table>'; else $custom_label = $this->more_add_button_stuff; } $gb->set_custom_label($custom_label); if ($admin) $this->browse_mode = 'all'; if ($this->browse_mode == 'recent') { $ret = DB::Execute('SELECT * FROM '.$this->tab.'_recent WHERE user_id=%d ORDER BY visited_on DESC', array(Acl::get_user())); while ($row = $ret->FetchRow()) { if (!isset($records[$row[$this->tab.'_id']])) continue; $records[$row[$this->tab.'_id']]['visited_on'] = Base_RegionalSettingsCommon::time2reg(strtotime($row['visited_on'])); } } else { $this->set_module_variable('set_browsed_records',array('tab'=>$this->tab,'crits'=>$crits, 'order'=>$order, 'records'=>array())); } if ($special) $rpicker_ind = array(); if (!$pdf && !$admin && $this->favorites) { $favs = array(); $ret = DB::Execute('SELECT '.$this->tab.'_id FROM '.$this->tab.'_favorite WHERE user_id=%d', array(Acl::get_user())); while ($row=$ret->FetchRow()) $favs[$row[$this->tab.'_id']] = true; } self::$access_override['tab'] = $this->tab; if (isset($limit)) $i = $limit['offset']; $grid_enabled = $this->grid===null?Base_User_SettingsCommon::get('Utils/RecordBrowser','grid'):$this->grid; if ($grid_enabled) load_js('modules/Utils/RecordBrowser/grid.js'); $this->view_fields_permission = $this->get_access('add', $this->custom_defaults); if (!$pdf && !$special && $this->add_in_table && $this->view_fields_permission) { $form = $this->init_module('Libs/QuickForm',null, 'add_in_table__'.$this->tab); $form_name = $form->get_name(); } else $form_name = ''; foreach ($records as $row) { if ($this->browse_mode!='recent' && isset($limit)) { self::$browsed_records['records'][$row['id']] = $i; $i++; } $row = Utils_RecordBrowserCommon::record_processing($this->tab, $row, 'browse'); self::$access_override['id'] = $row['id']; $gb_row = $gb->get_new_row(); $row_data = array(); if (!$pdf && !$admin && $this->favorites) { $isfav = isset($favs[$row['id']]); $row_data[] = Utils_RecordBrowserCommon::get_fav_button($this->tab, $row['id'], $isfav); } if (!$pdf && !$admin && $this->watchdog) $row_data[] = Utils_WatchdogCommon::get_change_subscription_icon($this->tab,$row['id']); if ($special) { $element = $this->get_module_variable('element'); $format = $this->get_module_variable('format_func'); $row_data = array('<input type="checkbox" id="leightbox_rpicker_'.$element.'_'.$row['id'].'" formated_name="'.(is_callable($format)?strip_tags(call_user_func($format, $row, true)):'').'" />'); $rpicker_ind[] = $row['id']; } $r_access = $this->get_access('view', $row); foreach($query_cols as $k=>$argsid) { if (!$r_access || !$r_access[$argsid]) { $row_data[] = ''; continue; } $field = $hash[$argsid]; $args = $this->table_rows[$field]; $value = $this->get_val($field, $row, ($special || $pdf), $args); if (strip_tags($value)=='') $value .= ' '; if ($args['style']=='currency' || $args['style']=='number') $value = array('style'=>'text-align:right;','value'=>$value); if ($grid_enabled && !in_array($args['type'], array('calculated','multiselect','commondata'))) { $table = '<table class="Utils_RecordBrowser__grid_table" style="width:100%" cellpadding="0" cellspacing="0" border="0"><tr><td id="grid_form_field_'.$argsid.'_'.$row['id'].'" style="display:none;">Loading...</td><td id="grid_value_field_'.$argsid.'_'.$row['id'].'">'; $ed_icon = '</td><td style="min-width:18px;width:18px;padding:0px;margin:0px;">'. '<span id="grid_edit_'.$argsid.'_'.$row['id'].'" style="float:right;display:none;"><a href="javascript:void(0);" onclick="grid_enable_field_edit(\''.$argsid.'\','.$row['id'].',\''.$this->tab.'\',\''.$form_name.'\');"><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils/GenericBrowser', 'edit.png').'"></a></span>'. '<span id="grid_save_'.$argsid.'_'.$row['id'].'" style="float:right;display:none;"><a href="javascript:void(0);" onclick="grid_submit_field(\''.$argsid.'\','.$row['id'].',\''.$this->tab.'\');"><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils/RecordBrowser', 'save_grid.png').'"></a></span>'. '</td></tr></table>'; /* $table = '<span id="grid_form_field_'.$argsid.'_'.$row['id'].'" style="display:none;">Loading...</span><span id="grid_value_field_'.$argsid.'_'.$row['id'].'">'; $ed_icon = '</span>'. '<span id="grid_edit_'.$argsid.'_'.$row['id'].'" style="float:right;display:none;"><a href="javascript:void(0);" onclick="grid_enable_field_edit(\''.$argsid.'\','.$row['id'].',\''.$this->tab.'\',\''.$form_name.'\');"><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils/GenericBrowser', 'edit.png').'"></a></span>'. '<span id="grid_save_'.$argsid.'_'.$row['id'].'" style="float:right;display:none;"><a href="javascript:void(0);" onclick="grid_submit_field(\''.$argsid.'\','.$row['id'].',\''.$this->tab.'\');"><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils/RecordBrowser', 'save_grid.png').'"></a></span>';*/ $attrs = 'onmouseover="if(typeof(mouse_over_grid)!=\'undefined\')mouse_over_grid(\''.$argsid.'\',\''.$row['id'].'\');" onmouseout="if(typeof(mouse_out_grid)!=\'undefined\')mouse_out_grid(\''.$argsid.'\',\''.$row['id'].'\');"'; // $attrs = 'onmouseover="$(\'grid_edit_'.$argsid.'_'.$row['id'].'\').style.display=\'inline\'" onmouseout="$(\'grid_edit_'.$argsid.'_'.$row['id'].'\').style.display=\'none\'"'; } else { $table = ''; $ed_icon = ''; $attrs = ''; } if (is_array($value)) { $value['value'] = $table.$value['value'].$ed_icon; $value['attrs'] = $attrs; } else { $value = array( 'value'=>$table.$value.$ed_icon, 'attrs'=>$attrs ); } if ($pdf) { $value['overflow_box'] = false; $value['attrs'] = $attrs.' style="border:1px solid black;"'; $value['value'] = ' '.$value['value'].' '; } $row_data[] = $value; } $gb_row->add_data_array($row_data); if (!$pdf && $this->disabled['actions']!==true) { if ($this->disabled['actions']===false) $da = array(); else $da = array_flip($this->disabled['actions']); if (!$special) { if (!isset($da['view'])) $gb_row->add_action($this->create_callback_href(array($this,'navigate'),array('view_entry', 'view', $row['id'])),__('View'), null, 'view'); if (!isset($da['edit'])) { if ($this->get_access('edit',$row)) $gb_row->add_action($this->create_callback_href(array($this,'navigate'),array('view_entry', 'edit',$row['id'])),__('Edit'), null, 'edit'); else $gb_row->add_action('',__('Edit'),__('You don\'t have permission to edit this record.'),'edit',0,true); } if ($admin) { if (!$row[':active']) $gb_row->add_action($this->create_callback_href(array($this,'set_active'),array($row['id'],true)),__('Activate'), null, 'active-off'); else $gb_row->add_action($this->create_callback_href(array($this,'set_active'),array($row['id'],false)),__('Deactivate'), null, 'active-on'); $info = Utils_RecordBrowserCommon::get_record_info($this->tab, $row['id']); if ($info['edited_on']===null) $gb_row->add_action('',__('This record was never edited'),null,'history_inactive'); else $gb_row->add_action($this->create_callback_href(array($this,'navigate'),array('view_edit_history', $row['id'])),__('View edit history'),null,'history'); } else { if (!isset($da['delete'])) { if ($this->get_access('delete',$row)) $gb_row->add_action($this->create_confirm_callback_href(__('Are you sure you want to delete this record?'),array($this,'delete_record'),array($row['id'], false)),__('Delete'), null, 'delete'); else $gb_row->add_action('',__('Delete'),__('You don\'t have permission to delete this record'),'delete',0,true); } } } if (!isset($da['info'])) $gb_row->add_info(($this->browse_mode=='recent'?'<b>'.__('Visited on: %s', array($row['visited_on'])).'</b><br>':'').Utils_RecordBrowserCommon::get_html_record_info($this->tab, isset($info)?$info:$row['id'])); $this->call_additional_actions_methods($row, $gb_row); } } if (!$special && $this->add_in_table && $this->view_fields_permission) { $visible_cols = array(); foreach($this->table_rows as $field => $args){ if ((!$args['visible'] && (!isset($cols[$args['id']]) || $cols[$args['id']] === false))) continue; if (isset($cols[$args['id']]) && $cols[$args['id']] === false) continue; $visible_cols[$args['id']] = true; } self::$last_record = $this->record = $this->custom_defaults = Utils_RecordBrowserCommon::record_processing($this->tab, $this->custom_defaults, 'adding'); $this->prepare_view_entry_details($this->custom_defaults, 'add', null, $form, $visible_cols); $form->setDefaults($this->custom_defaults); if ($form->isSubmitted()) { $this->set_module_variable('force_add_in_table_after_submit', true); if ($form->validate()) { $values = $form->exportValues(); foreach ($this->custom_defaults as $k=>$v) if (!isset($values[$k])) $values[$k] = $v; $id = Utils_RecordBrowserCommon::new_record($this->tab, $values); location(array()); } else { $this->show_add_in_table = true; } } $form->addElement('submit', 'submit_qanr', __('Save'), array('style'=>'width:100%;height:19px;', 'class'=>'button')); $renderer = new HTML_QuickForm_Renderer_TCMSArraySmarty(); $form->accept($renderer); $data = $renderer->toArray(); $gb->set_prefix($data['javascript'].'<form '.$data['attributes'].'>'.$data['hidden']."\n"); $gb->set_postfix("</form>\n"); if (!$admin && $this->favorites) { $row_data= array(' '); } else $row_data= array(); if (!$admin && $this->watchdog) $row_data[] = ' '; $first = true; foreach($visible_cols as $k => $v) { if (isset($data[$k])) { $row_data[] = array('value'=>$data[$k]['error'].$data[$k]['html'], 'overflow_box'=>false); if ($first) eval_js('focus_on_field = "'.$k.'";'); $first = false; } else $row_data[] = ' '; } // if ($this->browse_mode == 'recent') // $row_data[] = ' '; $gb_row = $gb->get_new_row(); $gb_row->add_action('',$data['submit_qanr']['html'],'', null, 0, false, 7); $gb_row->set_attrs('id="add_in_table_row" style="display:'.($this->show_add_in_table?'':'none').';"'); $gb_row->add_data_array($row_data); } if ($special) { $this->set_module_variable('rpicker_ind',$rpicker_ind); $ret = $this->get_html_of_module($gb); Base_User_SettingsCommon::save('Utils/RecordBrowser/RecordPicker','per_page',$gb->get_module_variable('per_page')); Base_User_SettingsCommon::save('Utils/GenericBrowser','per_page',$gb_per_page); return $ret; } if ($pdf) { $gb->absolute_width(true); $args = array(Base_ThemeCommon::get_template_filename('Utils_GenericBrowser','pdf')); } else $args = array(); $this->display_module($gb, $args); }
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; }
public function companies_actions($r, $gb_row) { $me = CRM_ContactsCommon::get_my_record(); $emp = array($me['id']); $cus = array(); $cus[] = 'C:' . $r['id']; if (ModuleManager::is_installed('CRM/Meeting') !== -1 && Utils_RecordBrowserCommon::get_access('crm_meeting', 'add')) { $gb_row->add_action(Utils_RecordBrowserCommon::create_new_record_href('crm_meeting', array('employees' => $emp, 'customers' => $cus, 'status' => 0, 'priority' => 1, 'permission' => 0)), __('New Meeting'), null, Base_ThemeCommon::get_template_file('CRM_Calendar', 'icon-small.png')); } if (ModuleManager::is_installed('CRM/Tasks') !== -1 && Utils_RecordBrowserCommon::get_access('task', 'add')) { $gb_row->add_action(Utils_RecordBrowserCommon::create_new_record_href('task', array('employees' => $emp, 'customers' => $cus, 'status' => 0, 'priority' => 1, 'permission' => 0)), __('New Task'), null, Base_ThemeCommon::get_template_file('CRM_Tasks', 'icon-small.png')); } if (ModuleManager::is_installed('CRM/PhoneCall') !== -1 && Utils_RecordBrowserCommon::get_access('phonecall', 'add')) { $gb_row->add_action(Utils_RecordBrowserCommon::create_new_record_href('phonecall', array('date_and_time' => date('Y-m-d H:i:s'), 'customer' => 'C:' . $r['id'], 'employees' => $me['id'], 'status' => 0, 'permission' => 0, 'priority' => 1), 'none', array('date_and_time')), __('New Phonecall'), null, Base_ThemeCommon::get_template_file('CRM_PhoneCall', 'icon-small.png')); } $gb_row->add_action(Utils_RecordBrowser::$rb_obj->add_note_button_href('company/' . $r['id']), __('New Note'), null, Base_ThemeCommon::get_template_file('Utils_Attachment', 'icon_small.png')); }