public function applet($v, $o) { $all = Tools_WhoIsOnlineCommon::get(); $map = array(); foreach ($all as $id => $x) { $c = CRM_ContactsCommon::get_contact_by_user_id(Base_UserCommon::get_user_id($x)); if ($c) { $all[$id] = CRM_ContactsCommon::contact_format_no_company($c); $map[$id] = $c['last_name']; } else { $map[$id] = $x; } } asort($map); $c = count($all); if ($c == 1) { $o['title'] = __('%d user online', array($c)); } else { $o['title'] = __('%d users online', array($c)); } print '<ul>'; foreach ($map as $id => $x) { print '<li>' . $all[$id] . '</li>'; } print '</ul>'; }
public static function user_label($id) { $label = Base_UserCommon::get_user_login($id); $c = Utils_RecordBrowserCommon::get_id('contact', 'login', $id); if ($c) { $label = CRM_ContactsCommon::contact_format_no_company($c, true) . ' [' . $label . ']'; } return $label; }
public static function get_all($start, $end, $filter = null) { if ($filter === null) { $filter = self::$filter; } $custom_handlers = DB::GetAssoc('SELECT id, handler_callback FROM crm_calendar_custom_events_handlers'); $result = array(); if (self::$events_handlers === null) { self::$events_handlers = array_keys($custom_handlers); } $count = 0; foreach (self::$events_handlers as $handler) { $callback = explode('::', $custom_handlers[$handler]); $result_ext = call_user_func($callback, 'get_all', $start, $end, $filter); foreach ($result_ext as $v) { if ($v !== null) { $v['id'] = $handler . '#' . $v['id']; $v['custom_agenda_col_0'] = isset($v['type']) ? $v['type'] : '---'; if (isset($v['description'])) { $v['custom_agenda_col_1'] = $v['description']; } if (isset($v['employees'])) { $emps = array(); if (is_array($v['employees'])) { foreach ($v['employees'] as $e) { $emps[] = CRM_ContactsCommon::contact_format_no_company($e); } } $v['custom_agenda_col_2'] = implode('<br>', $emps); } if (isset($v['customers'])) { $cuss = array(); if (is_array($v['customers'])) { foreach ($v['customers'] as $c) { $cuss[] = CRM_ContactsCommon::display_company_contact(array('customers' => $c), true, array('id' => 'customers')); } } $v['custom_agenda_col_3'] = implode('<br>', $cuss); } $result[] = $v; $count++; if ($count == CRM_CalendarCommon::$events_limit) { break; } } } if ($count == CRM_CalendarCommon::$events_limit) { break; } } if ($count == CRM_CalendarCommon::$events_limit) { print '<b>There were too many events to display on the Calendar, please change CRM Filter</b>'; } return $result; }
public function messanger_addon($arg) { $emp = array(); $ret = CRM_ContactsCommon::get_contacts(array('id' => $arg['employees']), array(), array('last_name' => 'ASC', 'first_name' => 'ASC')); foreach ($ret as $c_id => $data) { if (is_numeric($data['login'])) { $emp[$data['login']] = CRM_ContactsCommon::contact_format_no_company($data); } } $mes = $this->init_module('Utils/Messenger', array('CRM_PhoneCall:' . $arg['id'], array('CRM_PhoneCallCommon', 'get_alarm'), array($arg['id']), strtotime($arg['date_and_time']), $emp)); // $mes->set_inline_display(); $this->display_module($mes); }
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()); }
public function edit($user_settings_nav = true) { if ($user_settings_nav) { Base_ActionBarCommon::add('back', __('Back'), $this->create_main_href('Base_User_Settings')); } Base_ActionBarCommon::add('add', __('Add preset'), $this->create_callback_href(array($this, 'edit_group'))); $gb = $this->init_module('Utils/GenericBrowser', null, 'edit'); $gb->set_table_columns(array(array('name' => __('Name'), 'width' => 20, 'order' => 'g.name'), array('name' => __('Description'), 'width' => 30, 'order' => 'g.description'), array('name' => __('Users in category'), 'width' => 50, 'order' => ''))); $ret = DB::Execute('SELECT g.name,g.id,g.description FROM crm_filters_group g WHERE g.user_login_id=' . Acl::get_user()); while ($row = $ret->FetchRow()) { $gb_row =& $gb->get_new_row(); $gb_row->add_action($this->create_confirm_callback_href(__('Delete this group?'), array('CRM_Filters', 'delete_group'), $row['id']), 'Delete'); $gb_row->add_action($this->create_callback_href(array($this, 'edit_group'), $row['id']), 'Edit'); $cids = DB::GetAssoc('SELECT c.contact_id, c.contact_id FROM crm_filters_contacts c WHERE c.group_id=%d', array($row['id'])); $users = array(); foreach ($cids as $v) { $users[] = CRM_ContactsCommon::contact_format_no_company(CRM_ContactsCommon::get_contact($v), true); } $gb_row->add_data($row['name'], $row['description'], implode(', ', $users)); } $this->display_module($gb); $qf = $this->init_module('Libs/QuickForm', null, 'default_filter'); $qf->addElement('checkbox', 'show_all_contacts_in_filters', __('Show all contacts in Perspective selection'), null, array('onChange' => $qf->get_submit_form_js())); $qf->addElement('checkbox', 'show_only_users_in_filters', __('Show only users in Perspective selection'), null, array('onChange' => $qf->get_submit_form_js())); $qf->setDefaults(array('show_all_contacts_in_filters' => Base_User_SettingsCommon::get('CRM_Contacts', 'show_all_contacts_in_filters'), 'show_only_users_in_filters' => Base_User_SettingsCommon::get('CRM_Contacts', 'show_only_users_in_filters'))); if ($qf->validate()) { $vals = $qf->exportValues(); if (!isset($vals['show_all_contacts_in_filters'])) { $vals['show_all_contacts_in_filters'] = 0; } if (!isset($vals['show_only_users_in_filters'])) { $vals['show_only_users_in_filters'] = 0; } Base_User_SettingsCommon::save('CRM_Contacts', 'show_all_contacts_in_filters', $vals['show_all_contacts_in_filters']); Base_User_SettingsCommon::save('CRM_Contacts', 'show_only_users_in_filters', $vals['show_only_users_in_filters']); } $qf->display(); }
public static function crm_event_get($id) { if (!is_array($id)) { $r = Utils_RecordBrowserCommon::get_record('task', $id); } else { $r = $id; $id = $r['id']; } $r = Utils_RecordBrowserCommon::filter_record_by_access('task', $r); if (!$r) { return null; } $next = array('type' => __('Task')); $day = $r['deadline']; $iday = strtotime($day); $next['id'] = $r['id']; $base_unix_time = strtotime(date('1970-01-01 00:00:00')); $next['start'] = $iday; $next['timeless'] = $day; $next['duration'] = -1; $next['title'] = (string) $r['title']; $next['description'] = (string) $r['description']; $next['color'] = 'gray'; if ($r['status'] == 0 || $r['status'] == 1) { switch ($r['priority']) { case 0: $next['color'] = 'green'; break; case 1: $next['color'] = 'yellow'; break; case 2: $next['color'] = 'red'; break; } } if ($r['status'] == 2) { $next['color'] = 'blue'; } if ($r['status'] == 3) { $next['color'] = 'gray'; } $next['view_action'] = Utils_RecordBrowserCommon::create_record_href('task', $r['id'], 'view'); if (Utils_RecordBrowserCommon::get_access('task', 'edit', $r) !== false) { $next['edit_action'] = Utils_RecordBrowserCommon::create_record_href('task', $r['id'], 'edit'); } else { $next['edit_action'] = false; $next['move_action'] = false; } if (Utils_RecordBrowserCommon::get_access('task', 'delete', $r) == false) { $next['delete_action'] = false; } /* $r_new = $r; if ($r['status']==0) $r_new['status'] = 1; if ($r['status']<=1) $next['actions'] = array( array('icon'=>Base_ThemeCommon::get_template_file('CRM/Meeting', 'close_event.png'), 'href'=>self::get_status_change_leightbox_href($r_new, false, array('id'=>'status'))) );*/ $start_time = Base_RegionalSettingsCommon::time2reg($next['start'], 2, false, false); $event_date = Base_RegionalSettingsCommon::time2reg($next['start'], false, 3, false); $inf2 = array(__('Date') => '<b>' . $event_date . '</b>'); $emps = array(); foreach ($r['employees'] as $e) { $e = CRM_ContactsCommon::contact_format_no_company($e, true); $e = str_replace(' ', ' ', $e); if (mb_strlen($e, 'UTF-8') > 33) { $e = mb_substr($e, 0, 30, 'UTF-8') . '...'; } $emps[] = $e; } $next['busy_label'] = $r['employees']; $cuss = array(); foreach ($r['customers'] as $c) { $c = CRM_ContactsCommon::display_company_contact(array('customers' => $c), true, array('id' => 'customers')); $cuss[] = str_replace(' ', ' ', $c); } $inf2 += array(__('Task') => '<b>' . $next['title'] . '</b>', __('Description') => $next['description'], __('Assigned to') => implode('<br>', $emps), __('Contacts') => implode('<br>', $cuss), __('Status') => Utils_CommonDataCommon::get_value('CRM/Status/' . $r['status'], true), __('Access') => Utils_CommonDataCommon::get_value('CRM/Access/' . $r['permission'], true), __('Priority') => Utils_CommonDataCommon::get_value('CRM/Priority/' . $r['priority'], true), __('Notes') => Utils_AttachmentCommon::count('task/' . $r['id'])); $next['employees'] = $r['employees']; $next['customers'] = $r['customers']; $next['status'] = $r['status'] <= 2 ? 'active' : 'closed'; $next['custom_tooltip'] = '<center><b>' . __('Task') . '</b></center><br>' . Utils_TooltipCommon::format_info_tooltip($inf2) . '<hr>' . CRM_ContactsCommon::get_html_record_info($r['created_by'], $r['created_on'], null, null); return $next; }
public static function crm_event_get($id, $day = null) { if (!is_array($id)) { $id = explode('_', $id); if (isset($id[1]) && $day === null) { $day = $id[1]; } $id = reset($id); $r = Utils_RecordBrowserCommon::get_record('crm_meeting', $id); } else { $r = $id; $id = $r['id']; } $r = Utils_RecordBrowserCommon::filter_record_by_access('crm_meeting', $r); if ($r === false) { return null; } $next = array('type' => __('Meeting')); // if ($r['duration']!=-1) { // $r['date'] = Base_RegionalSettingsCommon::time2reg($r['date'].' '.date('H:i:s', strtotime($r['time'])),false,true,true,false); // $r['recurrence_end'] = Base_RegionalSettingsCommon::time2reg($r['recurrence_end'].' '.date('H:i:s', strtotime($r['time'])),false,true,true,false); // } if ($day === null) { $day = $r['date']; $iday = strtotime($day); $next['id'] = $r['id']; } else { $iday = strtotime($day); if ($day < $r['date']) { return null; } if ($r['recurrence_end'] && $day > $r['recurrence_end']) { return null; } if ($r['recurrence_type'] <= 7 && $r['recurrence_type'] > 0) { $diff = round(($iday - strtotime($r['date'])) / (3600 * 24)); if ($diff < 0 || $diff % $r['recurrence_type'] != 0) { return null; } } if ($r['recurrence_type'] == 8) { if (isset($r['recurrence_hash'][date('N', $iday) - 1]) && !$r['recurrence_hash'][date('N', $iday) - 1]) { return null; } } if ($r['recurrence_type'] == 9) { $diff = round(($iday - strtotime($r['date'])) / (3600 * 24)); if ($diff < 0 || $diff % 14 != 0) { return null; } } if ($r['recurrence_type'] == 10) { $numdays = date('t', $iday); $cday = date('d', $iday); $tday = date('d', strtotime($r['date'])); if ($cday != $tday && ($tday <= $numdays || $numdays != $cday)) { return null; } } if ($r['recurrence_type'] == 11) { $cmonth = date('m', $iday); $tmonth = date('m', strtotime($r['date'])); if ($cmonth != $tmonth) { return null; } $numdays = date('t', $iday); $cday = date('d', $iday); $tday = date('d', strtotime($r['date'])); if ($cday != $tday && ($tday <= $numdays || $numdays != $cday)) { return null; } } $next['id'] = $r['id']; } if ($r['recurrence_type'] > 0) { $next['id'] = $r['id'] . '_' . $day; } $base_unix_time = strtotime(date('1970-01-01 00:00:00')); // $next['start'] = Base_RegionalSettingsCommon::reg2time(Base_RegionalSettingsCommon::time2reg(date('Y-m-d',$iday).' '.date('H:i:s',strtotime($r['time'])), true, false, true, false)); // $next['end'] = Base_RegionalSettingsCommon::reg2time(date('Y-m-d',$iday).' '.Base_RegionalSettingsCommon::time2reg(date('Y-m-d',$iday).' '.date('H:i:s',strtotime($r['time'])+$r['duration']), true, false, true, false)); $next['start'] = date('Y-m-d', $iday) . ' ' . date('H:i:s', strtotime($r['time'])); $next['end'] = date('Y-m-d', $iday) . ' ' . date('H:i:s', strtotime($r['time']) + $r['duration']); $next['start'] = strtotime($next['start']); $next['end'] = strtotime($next['end']); if ($r['duration'] == -1) { $next['timeless'] = $day; } $next['duration'] = intval($r['duration']); $next['title'] = (string) $r['title']; $next['description'] = (string) $r['description']; $next['color'] = 'gray'; if ($r['status'] == 0 || $r['status'] == 1) { switch ($r['priority']) { case 0: $next['color'] = 'green'; break; case 1: $next['color'] = 'yellow'; break; case 2: $next['color'] = 'red'; break; } } if ($r['status'] == 2) { $next['color'] = 'blue'; } if ($r['status'] == 3) { $next['color'] = 'gray'; } if ($r['recurrence_type']) { $next['title'] = '<img src="' . Base_ThemeCommon::get_template_file('CRM_Calendar_Event', 'recurrence.png') . '" border=0 hspace=0 vspace=0 align=left>' . $next['title']; } $next['view_action'] = Utils_RecordBrowserCommon::create_record_href('crm_meeting', $r['id'], 'view', array('day' => $day)); if (Utils_RecordBrowserCommon::get_access('crm_meeting', 'edit', $r) !== false) { $next['edit_action'] = Utils_RecordBrowserCommon::create_record_href('crm_meeting', $r['id'], 'edit'); if ($r['status'] <= 1) { $r_new = $r; if ($r['status'] == 0) { $r_new['status'] = 1; } $next['actions'] = array(array('icon' => Base_ThemeCommon::get_template_file('CRM/Meeting', 'close_event.png'), 'href' => self::get_status_change_leightbox_href($r_new, false, array('id' => 'status')))); } } else { $next['edit_action'] = false; $next['move_action'] = false; } if (Utils_RecordBrowserCommon::get_access('crm_meeting', 'delete', $r) == false) { $next['delete_action'] = false; } $start_time = Base_RegionalSettingsCommon::time2reg($next['start'], 2, false, $r['duration'] != -1); $event_date = Base_RegionalSettingsCommon::time2reg($next['start'], false, 3, $r['duration'] != -1); $end_time = Base_RegionalSettingsCommon::time2reg($next['end'], 2, false, $r['duration'] != -1); $inf2 = array(__('Date') => '<b>' . $event_date . '</b>'); if ($r['duration'] == -1) { $inf2 += array(__('Time') => __('Timeless event')); } else { $inf2 += array(__('Time') => $start_time . ' - ' . $end_time, __('Duration') => Base_RegionalSettingsCommon::seconds_to_words($r['duration'])); } $emps = array(); foreach ($r['employees'] as $e) { $e = CRM_ContactsCommon::contact_format_no_company($e, true); $e = str_replace(' ', ' ', $e); if (mb_strlen($e, 'UTF-8') > 33) { $e = mb_substr($e, 0, 30, 'UTF-8') . '...'; } $emps[] = $e; } $next['busy_label'] = $r['employees']; $cuss = array(); foreach ($r['customers'] as $c) { $c = CRM_ContactsCommon::display_company_contact(array('customers' => $c), true, array('id' => 'customers')); $cuss[] = str_replace(' ', ' ', $c); } $inf2 += array(__('Event') => '<b>' . $next['title'] . '</b>', __('Description') => $next['description'], __('Assigned to') => implode('<br>', $emps), __('Contacts') => implode('<br>', $cuss), __('Status') => Utils_CommonDataCommon::get_value('CRM/Status/' . $r['status'], true), __('Access') => Utils_CommonDataCommon::get_value('CRM/Access/' . $r['permission'], true), __('Priority') => Utils_CommonDataCommon::get_value('CRM/Priority/' . $r['priority'], true), __('Notes') => Utils_AttachmentCommon::count('crm_meeting/' . $r['id'])); // $next['employees'] = implode('<br>',$emps); // $next['customers'] = implode('<br>',$cuss); $next['employees'] = $r['employees']; $next['customers'] = $r['customers']; $next['status'] = $r['status'] <= 2 ? 'active' : 'closed'; $next['custom_tooltip'] = '<center><b>' . __('Meeting') . '</b></center><br>' . Utils_TooltipCommon::format_info_tooltip($inf2) . '<hr>' . CRM_ContactsCommon::get_html_record_info($r['created_by'], $r['created_on'], null, null); return $next; }
public static function get_html_record_info($created_by, $created_on, $edited_by = null, $edited_on = null, $id = null) { if ($created_by !== null) { $contact = CRM_ContactsCommon::contact_format_no_company(CRM_ContactsCommon::get_contact_by_user_id($created_by), true); if ($contact != '') { $created_by = $contact; } else { $created_by = Base_UserCommon::get_user_login($created_by); } } else { $created_by = ''; } // If the record was edited get user contact info if ($edited_by != null) { if ($edited_by != $created_by) { $contact = CRM_ContactsCommon::contact_format_no_company(CRM_ContactsCommon::get_contact_by_user_id($edited_by), true); } if ($contact != '') { $edited_by = $contact; } else { $edited_by = Base_UserCommon::get_user_login($edited_by); } } $htmlinfo = array(); if ($id) { $htmlinfo[__('Record ID') . ':'] = $id; } $htmlinfo[__('Created by') . ':'] = $created_by; $htmlinfo[__('Created on') . ':'] = Base_RegionalSettingsCommon::time2reg($created_on); if ($edited_by != null) { $htmlinfo = $htmlinfo + array(__('Edited by') . ':' => $edited_by, __('Edited on') . ':' => Base_RegionalSettingsCommon::time2reg($edited_on)); } return Utils_TooltipCommon::format_info_tooltip($htmlinfo); }
public function admin() { if ($this->is_back()) { if ($this->parent->get_type() == 'Base_Admin') { $this->parent->reset(); } else { location(array()); } return; } Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); $user = $this->get_module_variable('filter_user', ''); $form = $this->init_module(Libs_QuickForm::module_name(), null, 'filter'); $form->setDefaults(array('users' => $user)); $count = DB::GetOne('SELECT COUNT(*) FROM user_login'); if ($count > Base_User_SettingsCommon::get('Utils_RecordBrowser', 'enable_autocomplete')) { $f_callback = array('CRM_LoginAuditCommon', 'user_label'); $form->addElement('autoselect', 'users', __('Select user'), array(), array(array('CRM_LoginAuditCommon', 'user_suggestbox'), array($f_callback)), $f_callback, array('onChange' => $form->get_submit_form_js(), 'style' => 'width:200px')); } else { $ret = DB::Execute('SELECT id, active FROM user_login ORDER BY active DESC, login ASC'); $el = $form->addElement('select', 'users', __('Select user'), array(), array('onChange' => $form->get_submit_form_js(), 'style' => 'width:200px')); $el->addOption(__('All'), ''); $contacts_raw = CRM_ContactsCommon::get_contacts(array('!login' => '')); $contacts = array(); foreach ($contacts_raw as $c) { $contacts[$c['login']] = $c; } $active = array(); $inactive = array(); while ($row = $ret->FetchRow()) { $label = '[' . Base_UserCommon::get_user_login($row['id']) . ']'; if (isset($contacts[$row['id']])) { $label = CRM_ContactsCommon::contact_format_no_company($contacts[$row['id']], true) . ' ' . $label; } if ($row['active']) { $active[$row['id']] = $label; } else { $inactive[$row['id']] = $label; } } asort($active); asort($inactive); foreach ($active as $id => $label) { $el->addOption($label, $id); } foreach ($inactive as $id => $label) { $el->addOption($label, $id, array('style' => 'background-color: lightgray;')); } } $user = $form->exportValue('users'); $form->display_as_row(); $this->set_module_variable('filter_user', $user); $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'login_audit'); $gb->set_table_columns(array(array('name' => '<b>' . __('Login') . '</b> ' . __('[uid] -> User Name'), 'order' => 'b.user_login_id', 'width' => 20), array('name' => __('Start'), 'order' => 'b.start_time', 'width' => 15), array('name' => __('End'), 'order' => 'b.end_time', 'width' => 15), array('name' => __('Duration'), 'width' => 10), array('name' => __('IP Address'), 'order' => 'b.ip_address', 'width' => 10), array('name' => __('Host Name'), 'order' => 'b.host_name', 'width' => 30))); $gb->set_default_order(array(__('End') => 'DESC')); if ($user > 0) { $query = 'SELECT b.user_login_id, b.start_time, b.end_time, b.ip_address, b.host_name FROM base_login_audit b WHERE b.user_login_id=' . $user; $query_qty = 'SELECT count(b.id) FROM base_login_audit b WHERE b.user_login_id=' . $user; } else { $query = 'SELECT b.user_login_id, b.start_time, b.end_time, b.ip_address, b.host_name FROM base_login_audit b'; $query_qty = 'SELECT count(b.id) FROM base_login_audit b'; } $ret = $gb->query_order_limit($query, $query_qty); if ($ret) { while ($row = $ret->FetchRow()) { $c = CRM_ContactsCommon::get_contact_by_user_id($row['user_login_id']); $ulogin = Base_UserCommon::get_user_login($row['user_login_id']); $uid = __('Contact not set'); if ($c) { $uid = $c['first_name'] . ' ' . $c['last_name']; } $offset = strtotime("1970-01-01 00:00:00"); $sess_time = date("G:i:s", strtotime($row['end_time']) - strtotime($row['start_time']) + $offset); $gb->add_row('<b>' . $ulogin . ' [' . $row['user_login_id'] . ']</b> -> ' . $uid, $row['start_time'], $row['end_time'], $sess_time, $row['ip_address'], $row['host_name']); } } $this->display_module($gb); if (!DEMO_MODE) { Base_ActionBarCommon::add('settings', __('Maintenance'), $this->create_callback_href(array($this, 'purge_log'))); } return true; }