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>'; }
function lookup_user_name($args) { global $account; $rec = CRM_ContactsCommon::get_contact_by_user_id($account['f_epesi_user']); if ($rec) { $args['user_name'] = $rec['first_name'] . ' ' . $rec['last_name']; } $args['user_email'] = $account['f_email']; return $args; }
/** * Get first(by id) user that is super administrator and get it's first * and last name from crm_contacts * * This function uses DB query to get users and generally it should be * easier way to get super admin. * * @return array with keys admin_email, admin_first_name, admin_last_name */ public static function get_possible_admin() { $users = DB::GetAll('select id, mail from user_login inner join user_password on user_login_id = id where admin=2'); foreach ($users as $u) { $x = array('admin_email' => $u['mail']); if (ModuleManager::is_installed('CRM_Contacts') > -1) { $contact = CRM_ContactsCommon::get_contact_by_user_id($u['id']); if ($contact) { $x['admin_first_name'] = $contact['first_name']; $x['admin_last_name'] = $contact['last_name']; } } return $x; } return null; }
public function make_event_PDF($pdf, $id, $no_details = false, $type = 'Event') { $custom_event = false; if (!is_array($id)) { $check = explode('#', $id); if (isset($check[1])) { $callback = DB::GetOne('SELECT handler_callback FROM crm_calendar_custom_events_handlers WHERE id=%d', $check[0]); $callback = explode('::', $callback); $ev = call_user_func($callback, 'get', $check[1]); $no_details = true; $custom_event = true; } else { trigger_error('Invalid event id: ' . $id, E_USER_ERROR); } } else { $ev = $id; $id = $ev['id']; $id = explode('_', $id); $id = $id[0]; /* $ev_details = DB::GetRow('SELECT *, starts AS start, ends AS end FROM crm_calendar_event WHERE id=%d', array($id)); foreach ($ev_details as $k=>$v) if (!isset($ev[$k])) $ev[$k] = $v;*/ $ev['title'] = strip_tags($ev['title']); $check = explode('#', $id); if (isset($check[1])) { $no_details = true; $custom_event = true; } } $pdf_theme = $this->pack_module('Base/Theme'); $pdf_theme->assign('description', array('label' => __('Description'), 'value' => str_replace("\n", '<br/>', htmlspecialchars($ev['description'])))); if (!$no_details) { $ev['status'] = Utils_CommonDataCommon::get_value('CRM/Status/' . $ev['status'], true); $ev['access'] = self::$access[$ev['access']]; $ev['priority'] = self::$priority[$ev['priority']]; foreach (array('access' => __('Access'), 'priority' => __('Priority'), 'status' => __('Status')) as $v => $label) { $pdf_theme->assign($v, array('label' => $label, 'value' => $ev[$v])); } $created_by = CRM_ContactsCommon::get_contact_by_user_id($ev['created_by']); if ($created_by !== null) { $created_by = $created_by['last_name'] . ' ' . $created_by['first_name']; } else { $created_by = Base_UserCommon::get_user_login($ev['created_by']); } $created_on = Base_RegionalSettingsCommon::time2reg($ev['created_on'], false); $pdf_theme->assign('created_on', array('label' => __('Created on'), 'value' => $created_on)); $pdf_theme->assign('created_by', array('label' => __('Created by'), 'value' => $created_by)); if ($ev['edited_by'] != null) { $edited_by = CRM_ContactsCommon::get_contact_by_user_id($ev['edited_by']); if ($edited_by !== null) { $edited_by = $edited_by['last_name'] . ' ' . $edited_by['first_name']; } else { $edited_by = Base_UserCommon::get_user_login($ev['edited_by']); } $edited_on = Base_RegionalSettingsCommon::time2reg($ev['edited_on'], false); } else { $edited_by = '--'; $edited_on = '--'; } $pdf_theme->assign('edited_on', array('label' => __('Edited on'), 'value' => $edited_on)); $pdf_theme->assign('edited_by', array('label' => __('Edited by'), 'value' => $edited_by)); $pdf_theme->assign('printed_on', array('label' => __('Printed on'), 'value' => Base_RegionalSettingsCommon::time2reg(time()))); } $emps = array(); $cuss = array(); $cus_cmps = array(); if (isset($ev['employees']) && !empty($ev['employees'])) { foreach ($ev['employees'] as $v) { $c = CRM_ContactsCommon::get_contact($v); $emps[] = array('name' => $c['last_name'] . ' ' . $c['first_name'], 'mphone' => $c['mobile_phone'], 'wphone' => $c['work_phone'], 'hphone' => $c['home_phone']); } } if (isset($ev['customers']) && !empty($ev['customers'])) { foreach ($ev['customers'] as $v) { $det = explode(':', $v); if (isset($det[1])) { $v = $det[1]; } else { $v = $det[0]; $det[0] = 'P'; } if ($det[0] == 'P') { $c = CRM_ContactsCommon::get_contact($v); $company_name = isset($c['company_name']) && is_numeric($c['company_name']) ? array(Utils_RecordBrowserCommon::get_value('company', $c['company_name'], 'Company Name')) : '---'; $cuss[] = array('name' => $c['last_name'] . ' ' . $c['first_name'], 'mphone' => $c['mobile_phone'], 'wphone' => $c['work_phone'], 'hphone' => $c['home_phone'], 'company_name' => $company_name); } if ($det[0] == 'C') { $c = array('company_name' => array($v)); } if (is_array($c['company_name'])) { foreach ($c['company_name'] as $v2) { if (!isset($cus_cmps[$v2])) { $cus_cmps[$v2] = CRM_ContactsCommon::get_company($v2); } } } } } $pdf_theme->assign('employees', array('main_label' => __('Employees'), 'name_label' => __('Name'), 'mphone_label' => __('Mobile Phone'), 'wphone_label' => __('Work Phone'), 'hphone_label' => __('Home Phone'), 'lp_label' => __('Lp'), 'data' => $emps)); $pdf_theme->assign('customers', array('main_label' => __('Customers'), 'name_label' => __('Name'), 'mphone_label' => __('Mobile Phone'), 'wphone_label' => __('Work Phone'), 'hphone_label' => __('Home Phone'), 'company_name' => __('Company Name'), 'lp_label' => __('Lp'), 'data' => $cuss)); $pdf_theme->assign('customers_companies', array('main_label' => __('Customers Companies'), 'name_label' => __('Company Name'), 'phone_label' => __('Phone'), 'fax_label' => __('Fax'), 'address_label' => __('Address'), 'city_label' => __('City'), 'lp_label' => __('Lp'), 'data' => $cus_cmps)); $pdf_theme->assign('title', array('label' => __('Title'), 'value' => $ev['title'])); $start = Base_RegionalSettingsCommon::time2reg($ev['start'], false); $pdf_theme->assign('start_date', array('label' => __('Start Date'), 'value' => $start, 'details' => array('weekday' => __date('l', strtotime($start))))); if (!isset($ev['timeless'])) { $pdf_theme->assign('start_time', array('label' => __('Start Time'), 'value' => Base_RegionalSettingsCommon::time2reg($ev['start'], true, false))); if (!isset($ev['end'])) { trigger_error(print_r($ev, true)); } $pdf_theme->assign('end_time', array('label' => __('End Time'), 'value' => Base_RegionalSettingsCommon::time2reg($ev['end'], true, false))); $hours = floor(($ev['end'] - $ev['start']) / 3600); $format = __('%d hours', array($hours)); $minutes = ($ev['end'] - $ev['start']) % 3600; if ($minutes != 0) { if ($hours == 0) { $format = ''; } else { $format .= ', '; } $format .= __('%d minutes', array($minutes / 60)); } $pdf_theme->assign('duration', array('label' => __('Duration'), 'value' => $format)); if (date('Y-m-d', $ev['start']) != date('Y-m-d', $ev['end'])) { $pdf_theme->assign('end_date', array('label' => __('End Date'), 'value' => Base_RegionalSettingsCommon::time2reg($ev['end'], false))); } } else { $pdf_theme->assign('timeless', array('label' => __('Timeless'), 'value' => __('Yes'))); } $pdf_theme->assign('type', $type); ob_start(); $pdf_theme->display('pdf_version'); $cont = ob_get_clean(); $pdf->writeHTML($cont); }
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; }
public function admin() { if (ModuleManager::is_installed('CRM_Contacts') >= 0) { $this->pack_module('CRM_Contacts', array(), 'user_admin'); $this->banning_form(); return; } 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()); Base_ActionBarCommon::add('edit', __('E-mail header'), $this->create_callback_href(array($this, 'change_email_header'))); $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'user_list'); //$gb->set_module_variable('adv_search',false); $cols = array(); $cols[] = array('name' => __('ID'), 'order' => 'u.id', 'width' => 6, 'search' => 'id'); $cols[] = array('name' => __('Login'), 'order' => 'u.login', 'width' => 20, 'search' => 'login'); $is_contacts = CRM_ContactsInstall::is_installed(); if ($is_contacts) { $cols[] = array('name' => __('Contact'), 'width' => 27); } $cols[] = array('name' => __('Active'), 'order' => 'u.active', 'width' => 5); $cols[] = array('name' => __('Mail'), 'order' => 'p.mail', 'width' => 20, 'search' => 'mail'); $cols[] = array('name' => __('Access'), 'width' => '27'); if (Base_AclCommon::i_am_sa()) { $cols[] = array('name' => __('Actions'), 'width' => '80px'); } $gb->set_table_columns($cols); $gb->set_default_order(array(__('Login') => 'ASC')); $search = $gb->get_search_query(); $query = 'SELECT u.login, p.mail, u.id, u.active, u.admin FROM user_login u INNER JOIN user_password p on p.user_login_id=u.id' . ($search ? ' WHERE ' . $search : ''); $query_qty = 'SELECT count(u.id) FROM user_login u INNER JOIN user_password p on p.user_login_id=u.id' . ($search ? ' WHERE ' . $search : ''); $ret = $gb->query_order_limit($query, $query_qty); $yes = '<span style="color:green;">' . __('Yes') . '</span>'; $no = '<span style="color:red;">' . __('No') . '</span>'; if ($ret) { while ($row = $ret->FetchRow()) { $gb_row = array(); $gb_row[] = $row['id']; $gb_row[] = '<a ' . $this->create_callback_href(array($this, 'edit_user_form'), array($row['id'])) . '>' . $row['login'] . '</a>'; if ($is_contacts) { $c = CRM_ContactsCommon::get_contact_by_user_id($row['id']); $gb_row[] = $c ? CRM_ContactsCommon::contact_format_default($c) : '---'; } $gb_row[] = $row['active'] ? $yes : $no; $gb_row[] = $row['mail']; switch ($row['admin']) { case 2: $admin = __('Super Administrator'); break; case 1: $admin = __('Administrator'); break; default: $admin = __('User'); break; } $gb_row[] = $admin; if (Base_AclCommon::i_am_sa()) { $gb_row[] = '<a ' . $this->create_callback_href(array($this, 'log_as_user'), $row['id']) . '>' . __('Log as user') . '</a>'; } $gb->add_row_array($gb_row); } } $this->display_module($gb); $this->banning_form(); Base_ActionBarCommon::add('add', __('New user'), $this->create_callback_href(array($this, 'edit_user_form'), array(-1))); }
public static function prepare_header(& $tcpdf, $title='', $subject='', $printed_by=true, $logo_filename=null, $l = array()) { if ($title!==null) { if ($logo_filename===null) $logo_filename = Libs_TCPDFCommon::get_logo_filename(); if ($logo_filename!==false && !file_exists($logo_filename)) { $logo_filename = Base_ThemeCommon::get_template_file('Libs/TCPDF','logo-small.png'); } $margins = $tcpdf->getMargins(); if($logo_filename) { $logo_size = getimagesize($logo_filename); $logo_height = $logo_size[1] * PDF_HEADER_LOGO_WIDTH / $logo_size[0]; } else { $logo_height = 0; } $tcpdf->SetHeaderMargin(10); $tcpdf->SetTopMargin($logo_height + $margins['top']); $tcpdf->SetHeaderData($logo_filename, $logo_filename?PDF_HEADER_LOGO_WIDTH:0, $title, $subject); } else { $tcpdf->setPrintHeader(false); } //set some language-dependent strings $l['a_meta_charset'] = "UTF-8"; $l['a_meta_dir'] = "ltr"; $l['a_meta_language'] = "pl"; $who = null; if (ModuleManager::is_installed('CRM/Contacts') >= 0) { $who = CRM_ContactsCommon::get_contact_by_user_id(Acl::get_user()); } if ($who!==null) $who = $who['last_name'].' '.$who['first_name']; else $who= Base_UserCommon::get_user_login(Acl::get_user()); $when = date('Y-m-d H:i:s'); if (!isset($l['w_page'])) { $l['w_page'] = ''; if ($printed_by) $l['w_page'] .= __('Printed with %s by %s, on %s, ',array('EPESI (http://epe.si)',$who,$when)); $l['w_page'] .= __('Page'); } $tcpdf->setLanguageArray($l); self::SetFont($tcpdf, self::$default_font, '', 9); }