public function display_activities($events, $tasks, $phonecalls) { $gb = $this->init_module(Utils_GenericBrowser::module_name(), 'activities', 'activities'); $gb->set_table_columns(array(array('name' => __('Type'), 'wrapmode' => 'nowrap', 'width' => 8), array('name' => __('Subject'), 'width' => 20), array('name' => __('Date/Deadline'), 'wrapmode' => 'nowrap', 'width' => 8), array('name' => __('Employees'), 'width' => 11), array('name' => __('Customers'), 'width' => 11), array('name' => __('Attachments'), 'width' => 4))); $amount = 0; if ($this->display['events']) { $amount += count($events); } if ($this->display['tasks']) { $amount += count($tasks); } if ($this->display['phonecalls']) { $amount += count($phonecalls); } $limit = $gb->get_limit($amount); for ($i = 0; $i < $limit['offset'] + $limit['numrows'] && $i < $amount; $i++) { if ($this->display['events'] && count($events)) { $ev = current($events); } else { $ev = array('start' => -1); } if ($this->display['tasks'] && count($tasks)) { $t = current($tasks); if (!$t['deadline']) { $t['deadline'] = 0; } else { $t['deadline'] = strtotime($t['deadline']); } } else { $t = array('deadline' => -1); } if ($this->display['phonecalls'] && count($phonecalls)) { $ph = current($phonecalls); $ph['date_and_time'] = strtotime($ph['date_and_time']); } else { $ph = array('date_and_time' => -1); } $maxt = max($ev['start'], $t['deadline'], $ph['date_and_time']); $gb_row = $gb->get_new_row(); if ($ev['start'] == $maxt) { $v = array_shift($events); if ($i >= $limit['offset'] && $v) { if (isset($v['view_action'])) { $view_href = $v['view_action']; } else { $view_href = $this->create_callback_href(array($this, 'view_event'), array($v['id'])); } $title = '<a ' . $view_href . '>' . $v['title'] . '</a>'; if (isset($v['description']) && $v['description'] != '') { $title = '<span ' . Utils_TooltipCommon::open_tag_attrs($v['description'], false) . '>' . $title . '</span>'; } $gb_row->add_info(Utils_RecordBrowserCommon::get_html_record_info('crm_meeting', $v['id'])); $gb_row->add_data(__('Meeting'), $title, Base_RegionalSettingsCommon::time2reg($v['start'], $v['duration'] == -1 ? false : 2), CRM_ContactsCommon::display_contact(array('employees' => $v['employees']), false, array('id' => 'employees', 'param' => ';CRM_ContactsCommon::contact_format_no_company')), CRM_ContactsCommon::display_company_contact(array('customers' => $v['customers']), false, array('id' => 'customers', 'param' => ';::')), Utils_AttachmentCommon::count('crm_meeting/' . $v['id'])); } } elseif ($t['deadline'] == $maxt) { $v = array_shift($tasks); $v = Utils_RecordBrowserCommon::filter_record_by_access('task', $v); if ($i >= $limit['offset'] && $v) { $gb_row->add_info(Utils_RecordBrowserCommon::get_html_record_info('task', $v['id'])); $gb_row->add_data(__('Task'), CRM_TasksCommon::display_title($v, false), !isset($v['deadline']) || !$v['deadline'] ? __('No deadline') : Base_RegionalSettingsCommon::time2reg($v['deadline'], false, true, false), CRM_ContactsCommon::display_contact($v, false, array('id' => 'employees', 'param' => ';CRM_ContactsCommon::contact_format_no_company')), CRM_ContactsCommon::display_company_contact($v, false, array('id' => 'customers')), Utils_AttachmentCommon::count('task/' . $v['id'])); } } else { $v = array_shift($phonecalls); $v = Utils_RecordBrowserCommon::filter_record_by_access('phonecall', $v); if ($i >= $limit['offset'] && $v) { $gb_row->add_info(Utils_RecordBrowserCommon::get_html_record_info('phonecall', $v['id'])); $gb_row->add_data(__('Phonecall'), CRM_PhoneCallCommon::display_subject($v), Base_RegionalSettingsCommon::time2reg($v['date_and_time'], 2), CRM_ContactsCommon::display_contact($v, false, array('id' => 'employees', 'param' => ';CRM_ContactsCommon::contact_format_no_company')), CRM_PhoneCallCommon::display_contact_name($v, false), Utils_AttachmentCommon::count('phonecall/' . $v['id'])); } } } $this->display_module($gb); }
/** * Get html formatted info about record * @param int $id Record's ID * @return string html with info about record */ public function get_html_record_info($id) { return Utils_RecordBrowserCommon::get_html_record_info($this->tab, $id); }
public function mini_view($cols, $crits, $order, $info=null, $limit=null, $conf = array('actions_edit'=>true, 'actions_info'=>true), & $opts = array()){ unset($_SESSION['client']['recordbrowser']['admin_access']); $this->init(); $gb = $this->init_module('Utils/GenericBrowser',$this->tab,$this->tab); $field_hash = array(); foreach($this->table_rows as $field => $args) $field_hash[$args['id']] = $field; $header = array(); $callbacks = array(); foreach($cols as $k=>$v) { if (isset($v['callback'])) $callbacks[] = $v['callback']; else $callbacks[] = null; if (is_array($v)) { $arr = array('name'=>_V($field_hash[$v['field']])); // TRSL if (isset($v['width'])) $arr['width'] = $v['width']; $cols[$k] = $v['field']; } else { $arr = array('name'=>_V($field_hash[$v])); // TRSL $cols[$k] = $v; } if (isset($v['label'])) $arr['name'] = $v['label']; $arr['wrapmode'] = 'nowrap'; $header[] = $arr; } $gb->set_table_columns($header); $gb->set_fixed_columns_class($this->fixed_columns_class); $clean_order = array(); foreach($order as $k=>$v) { if ($k==':Visited_on') $field_hash[$k] = $k; if ($k==':Fav') $field_hash[$k] = $k; if ($k==':Edited_on') $field_hash[$k] = $k; if ($k==':id') $field_hash[$k] = $k; $clean_order[] = array('column'=>$field_hash[$k],'order'=>$field_hash[$k],'direction'=>$v); } if ($limit!=null && !isset($conf['force_limit'])) { $limit = array('offset'=>0, 'numrows'=>$limit); $records_qty = Utils_RecordBrowserCommon::get_records_count($this->tab, $crits); if ($records_qty>$limit['numrows']) { if ($this->get_module_variable('no_limit_in_mini_view',false)) { $opts['actions'][] = '<a '.Utils_TooltipCommon::open_tag_attrs(__('Display first %d records', array($limit['numrows']))).' '.$this->create_callback_href(array($this, 'set_no_limit_in_mini_view'), array(false)).'><img src="'.Base_ThemeCommon::get_template_file('Utils_RecordBrowser','show_some.png').'" border="0"></a>'; $limit = null; } else { print(__('Displaying %s of %s records', array($limit['numrows'], $records_qty))); $opts['actions'][] = '<a '.Utils_TooltipCommon::open_tag_attrs(__('Display all records')).' '.$this->create_callback_href(array($this, 'set_no_limit_in_mini_view'), array(true)).'><img src="'.Base_ThemeCommon::get_template_file('Utils_RecordBrowser','show_all.png').'" border="0"></a>'; } } } $records = Utils_RecordBrowserCommon::get_records($this->tab, $crits, array(), $clean_order, $limit); foreach($records as $v) { $gb_row = $gb->get_new_row(); $arr = array(); foreach($cols as $k=>$w) { if (!isset($callbacks[$k])) $s = $this->get_val($field_hash[$w], $v, false, $this->table_rows[$field_hash[$w]]); else $s = call_user_func($callbacks[$k], $v); $arr[] = $s; } $gb_row->add_data_array($arr); if (is_callable($info)) { $additional_info = call_user_func($info, $v); } else $additional_info = ''; if (!is_array($additional_info) && isset($additional_info)) $additional_info = array('notes'=>$additional_info); if (isset($additional_info['notes'])) $additional_info['notes'] = $additional_info['notes'].'<hr />'; if (isset($additional_info['row_attrs'])) $gb_row->set_attrs($additional_info['row_attrs']); if (isset($conf['actions_info']) && $conf['actions_info']) $gb_row->add_info($additional_info['notes'].Utils_RecordBrowserCommon::get_html_record_info($this->tab, $v['id'])); if (isset($conf['actions_view']) && $conf['actions_view']) $gb_row->add_action($this->create_callback_href(array($this,'navigate'),array('view_entry', 'view',$v['id'])),'View'); if (isset($conf['actions_edit']) && $conf['actions_edit']) if ($this->get_access('edit',$v)) $gb_row->add_action($this->create_callback_href(array($this,'navigate'),array('view_entry', 'edit',$v['id'])),'Edit'); if (isset($conf['actions_delete']) && $conf['actions_delete']) if ($this->get_access('delete',$v)) $gb_row->add_action($this->create_confirm_callback_href(__('Are you sure you want to delete this record?'),array($this,'delete_record'),array($v['id'], false)),'Delete'); if (isset($conf['actions_history']) && $conf['actions_history']) { $r_info = Utils_RecordBrowserCommon::get_record_info($this->tab, $v['id']); if ($r_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', $v['id'])),'View edit history',null,'history'); } $this->call_additional_actions_methods($v, $gb_row); } $this->display_module($gb); }
public function body() { if (!Base_AclCommon::check_permission('View Activity Report')) { return; } $rb_tabs = DB::GetAssoc('SELECT tab, caption FROM recordbrowser_table_properties ORDER BY caption'); foreach ($rb_tabs as $k => $v) { $rb_tabs[$k] = Utils_RecordBrowserCommon::get_caption($k); } $form = $this->init_module('Libs/QuickForm'); $users_count = DB::GetOne('SELECT COUNT(id) FROM user_login') > Base_User_SettingsCommon::get('Utils_RecordBrowser', 'enable_autocomplete'); if ($users_count) { $crits = array('!login' => ''); $fcallback = array('CRM_ContactsCommon', 'contact_format_no_company'); $form->addElement('autoselect', 'user', __('User'), array(), array(array('CRM_ContactsCommon', 'autoselect_contact_suggestbox'), array($crits, $fcallback)), $fcallback); } else { $users = DB::GetAssoc('SELECT id, id FROM user_login'); foreach ($users as $k => $u) { $users[$k] = Base_UserCommon::get_user_label($u, true); } asort($users); $users = array('' => '[' . __('All') . ']') + $users; $form->addElement('select', 'user', __('User'), $users); } $form->addElement('multiselect', 'recordsets', __('Record Type'), $rb_tabs); $form->addElement('checkbox', 'new', __('New record')); $form->addElement('checkbox', 'edit', __('Record edit')); $form->addElement('checkbox', 'delete_restore', __('Record Delete/restore')); $form->addElement('checkbox', 'file', __('Files')); $form->addElement('datepicker', 'start_date', __('Start Date')); $form->addElement('datepicker', 'end_date', __('End Date')); //$form->addElement('submit', 'submit', __('Show')); Base_ActionBarCommon::add('search', __('Show'), $form->get_submit_form_href()); $filters = $this->get_module_variable('filters', array('user' => '', 'new' => 1, 'edit' => 1, 'delete_restore' => 1, 'recordsets' => array_keys($rb_tabs), 'start_date' => date('Y-m-01'), 'end_date' => date('Y-m-d'))); if ($form->validate()) { $filters = $form->exportValues(); $this->set_module_variable('filters', $filters); } $form->setDefaults($filters); $theme = $this->init_module('Base/Theme'); $form->assign_theme('form', $theme); $theme->display(); $filters['recordsets'] = array_flip($filters['recordsets']); foreach ($rb_tabs as $k => $v) { if (!isset($filters['recordsets'][$k])) { unset($rb_tabs[$k]); } } $gb = $this->init_module('Utils/GenericBrowser', null, 'activity_report'); $gb->set_table_columns(array(array('name' => __('Date'), 'width' => 40), array('name' => __('User'), 'width' => 40), array('name' => __('Type'), 'width' => 40), array('name' => __('Label')), array('name' => __('Actions taken'), 'width' => 40))); $tables = array(); if ($users_count) { $filters['user'] = CRM_ContactsCommon::get_contact($filters['user']); $filters['user'] = $filters['user']['login']; } $af_where = array(); foreach ($rb_tabs as $k => $t) { $af_where[] = 'ual.local ' . DB::like() . ' ' . DB::Concat(DB::qstr($k . '/'), DB::qstr('%')); } $af_where = count($af_where) ? ' (' . implode(' OR ', $af_where) . ')' : 'TRUE '; $e_where = array(); $c_where = ''; if ($filters['user']) { $e_where[] = ' edited_by = ' . $filters['user']; $c_where = ' created_by = ' . $filters['user']; $af_where .= ' AND uaf.created_by = ' . $filters['user']; } if (isset($filters['edit'])) { if (!isset($filters['delete_restore'])) { $e_where[] = ' ehd.field!=' . DB::qstr('id'); } } else { if (isset($filters['delete_restore'])) { $e_where[] = ' ehd.field=' . DB::qstr('id'); } } if ($filters['start_date']) { $date = DB::qstr(date('Y-m-d', strtotime($filters['start_date']))); $af_where .= ' AND uaf.created_on >= ' . $date; $c_where .= ($c_where ? ' AND' : '') . ' created_on >= ' . $date; $e_where[] = ' edited_on >= ' . $date; } if ($filters['end_date']) { $date = DB::qstr(date('Y-m-d 23:59:59', strtotime($filters['end_date']))); $af_where .= ' AND uaf.created_on <= ' . $date; $c_where .= ($c_where ? ' AND' : '') . ' created_on <= ' . $date; $e_where[] = ' edited_on <= ' . $date; } if (!empty($e_where)) { $e_where = ' WHERE' . implode(' AND', $e_where); } else { $e_where = ''; } if ($c_where) { $c_where = ' WHERE' . $c_where; } $postgre_cast_type = DB::is_postgresql() ? '::varchar' : ''; // **** files **** if (isset($filters['file'])) { $tables[] = 'SELECT uaf.id AS id,uaf.created_on AS edited_on,uaf.created_by AS edited_by, ual.local AS r_id, ' . DB::qstr('') . ' AS tab, ' . DB::qstr('file') . ' AS action FROM utils_attachment_file uaf INNER JOIN utils_attachment_data_1 ua ON uaf.attach_id=ua.id INNER JOIN utils_attachment_local ual ON ua.id=ual.attachment WHERE original!=' . DB::qstr('') . ' AND ' . $af_where; } // **** edit **** if (isset($filters['edit']) || isset($filters['delete_restore'])) { foreach ($rb_tabs as $k => $t) { $tables[] = 'SELECT id, edited_on, edited_by, ' . $k . '_id' . $postgre_cast_type . ' as r_id, ' . DB::qstr($k) . ' as tab, ' . DB::qstr('edit') . ' as action FROM ' . $k . '_edit_history eh LEFT JOIN ' . $k . '_edit_history_data ehd ON ehd.edit_id=eh.id' . $e_where; } } // **** create **** if (isset($filters['new'])) { foreach ($rb_tabs as $k => $t) { $tables[] = 'SELECT 0 AS id, created_on AS edited_on, created_by AS edited_by, id' . $postgre_cast_type . ' as r_id, ' . DB::qstr($k) . ' as tab, ' . DB::qstr('create') . ' as action FROM ' . $k . '_data_1' . $c_where; } } if (!empty($tables)) { $tables = implode(' UNION ', $tables); $limit = DB::GetOne('SELECT COUNT(*) FROM (' . $tables . ') AS tmp'); $limit = $gb->get_limit($limit); $ret = DB::SelectLimit('SELECT * FROM (' . $tables . ') AS tmp ORDER BY edited_on DESC', $limit['numrows'], $limit['offset']); while ($row = $ret->FetchRow()) { $user = Base_UserCommon::get_user_label($row['edited_by']); $action = ''; $link = ''; switch ($row['action']) { case 'edit': $details = DB::GetAssoc('SELECT field, old_value FROM ' . $row['tab'] . '_edit_history_data WHERE edit_id=%d', array($row['id'])); if (isset($details['id'])) { $action = $details['id'] == 'DELETED' ? __('Deleted') : __('Restored'); } else { $action = __('Edited'); $action = '<a ' . Utils_TooltipCommon::tooltip_leightbox_mode() . ' ' . Utils_TooltipCommon::ajax_open_tag_attrs(array('Utils_RecordBrowserCommon', 'get_edit_details_label'), array($row['tab'], $row['r_id'], $row['id']), 500) . '>' . $action . '</a>'; } $r_id = $row['r_id']; break; case 'create': $action = __('Created'); $r_id = $row['r_id']; break; case 'file': $action = __('Attachment') . ': '; $action .= $row['id'] == 0 ? __('New') : __('Updated'); $id = explode('/', $row['r_id']); $row['tab'] = $id[0]; $r_id = $id[1]; break; case 'note': $action = __('Note') . ': '; $action .= $row['id'] == 0 ? __('New') : __('Updated'); $id = explode('/', $row['r_id']); $row['tab'] = $id[0]; $r_id = $id[1]; break; } if (!Utils_RecordBrowserCommon::get_access($row['tab'], 'view', Utils_RecordBrowserCommon::get_record($row['tab'], $r_id))) { $link = __('Access restricted'); $action = strip_tags($action); } else { $link = Utils_TooltipCommon::create('<img src="' . Base_ThemeCommon::get_template_file('Utils_RecordBrowser', 'info.png') . '">', Utils_RecordBrowserCommon::get_html_record_info($row['tab'], $r_id), false); $link .= ' '; $link .= Utils_RecordBrowserCommon::create_default_linked_label($row['tab'], $r_id, false, false); } $gb->add_row(Base_RegionalSettingsCommon::time2reg($row['edited_on']), $user, $rb_tabs[$row['tab']], $link, $action); } } Base_ThemeCommon::load_css('Utils_RecordBrowser', 'changes_list'); $this->display_module($gb); }