public static function admin_access() { if (DEMO_MODE) { return false; } if (Variable::get('anonymous_setup')) { return true; } return Base_AclCommon::i_am_admin(); }
private function create_admin_modules_instances() { foreach (get_declared_classes() as $class) { $rclass = new ReflectionClass($class); if ($rclass->isSubclassOf("AdminModule") && !$rclass->isAbstract()) { $module = new $class(); if (Base_AclCommon::i_am_sa() || Base_AclCommon::i_am_admin() && $module->access_admin() || Base_AclCommon::i_am_user() && $module->access_user()) { $this->admin_modules[$class] = $module; } } } ksort($this->admin_modules); }
public function user_admin() { if ($this->is_back()) { if ($this->parent->parent->get_type() == 'Base_Admin') { $this->parent->parent->reset(); } else { location(array()); } return; } if (!Base_AclCommon::i_am_admin()) { return false; } Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); $this->rb = $this->init_module('Utils/RecordBrowser', 'contact', 'contact'); $logins = DB::GetAll('SELECT * FROM user_login'); $active_logins = array(); $inactive_logins = array(); $user_logins = array(); $admin_logins = array(); $sa_logins = array(); foreach ($logins as $i) { if ($i['active']) { $active_logins[] = $i['id']; } else { $inactive_logins[] = $i['id']; } if ($i['admin'] == 0) { $user_logins[] = $i['id']; } elseif ($i['admin'] == 1) { $admin_logins[] = $i['id']; } else { $sa_logins[] = $i['id']; } } $this->rb->set_custom_filter('username', array('type' => 'select', 'label' => __('Active'), 'args' => array('__NULL__' => '---', 1 => __('Yes'), 2 => __('No')), 'trans' => array('__NULL__' => array(), 1 => array('login' => $active_logins), 2 => array('login' => $inactive_logins)))); $this->rb->set_custom_filter('admin', array('type' => 'select', 'label' => __('Admin'), 'args' => array('__NULL__' => '---', 0 => __('No'), 1 => __('Administrator'), 2 => __('Super Administrator')), 'trans' => array('__NULL__' => array(), 0 => array('login' => $user_logins), 1 => array('login' => $admin_logins), 2 => array('login' => $sa_logins)))); $this->rb->set_defaults(array('country' => Base_User_SettingsCommon::get('Base_RegionalSettings', 'default_country'), 'zone' => Base_User_SettingsCommon::get('Base_RegionalSettings', 'default_state'), 'permission' => Base_User_SettingsCommon::get('CRM_Common', 'default_record_permission'), 'home_country' => Base_User_SettingsCommon::get('Base_RegionalSettings', 'default_country'), 'home_zone' => Base_User_SettingsCommon::get('Base_RegionalSettings', 'default_state'), 'login' => 'new')); $this->rb->set_default_order(array('last_name' => 'ASC', 'first_name' => 'ASC')); $this->rb->set_additional_actions_method(array($this, 'user_actions')); $this->rb->set_additional_caption(__('Users')); $this->rb->disable_pdf(); $this->rb->disable_export(); $this->display_module($this->rb, array(array(), array('!login' => ''), array('work_phone' => false, 'admin' => true, 'mobile_phone' => false, 'city' => false, 'zone' => false, 'login' => true, 'access' => true, 'email' => true), array('username' => true, 'admin' => true, 'access' => true, 'related_companies' => false))); Base_ActionBarCommon::add('edit', __('E-mail header'), $this->create_callback_href(array('Base_BoxCommon', 'push_module'), array($this->get_type(), 'change_email_header')), __('Edit the header of the message that is sent to each newly created user')); }
public function addon($arg, $rb) { $rs = $rb->tab; $id = $arg['id']; if ($rs == 'contact' && Base_AclCommon::i_am_admin()) { Base_ActionBarCommon::add('reload', __('Reload mails'), $this->create_callback_href(array($this, 'reload_mails'), $arg['id'])); } if (isset($_SESSION['rc_mails_cp']) && is_array($_SESSION['rc_mails_cp']) && !empty($_SESSION['rc_mails_cp'])) { $ok = true; $mails = Utils_RecordBrowserCommon::get_records('rc_mails', array('id' => $_SESSION['rc_mails_cp']), array('related', 'employee', 'contacts')); if (count($mails) != count($_SESSION['rc_mails_cp'])) { $ok = false; } if ($ok) { foreach ($mails as $mail) { if (in_array($rs . '/' . $id, $mail['related']) || ($rs == 'contact' || $rs == 'company') && (in_array(($rs == 'contact' ? 'P:' : 'C:') . $id, $mail['contacts']) || $rs == 'contact' && $id == $mail['employee'])) { $ok = false; break; } } } if ($ok) { $this->lp = $this->init_module('Utils_LeightboxPrompt'); $this->lp->add_option('cancel', __('Cancel'), Base_ThemeCommon::get_template_file('Base_ActionBar', 'icons/back.png'), null); $this->lp->add_option('paste', __('Paste'), Base_ThemeCommon::get_template_file($this->get_type(), 'copy.png'), null); $content = ''; foreach ($_SESSION['rc_mails_cp'] as $mid) { $mail = Utils_RecordBrowserCommon::get_record('rc_mails', $mid); $content .= '<div style="text-align:left"><b>' . __('From') . ':</b> <i>' . $mail['from'] . '</i><br /><b>' . __('To') . ':</b> <i>' . $mail['to'] . '</i><br /><b>' . __('Subject') . ':</b> <i>' . $mail['subject'] . '</i><br />' . substr(strip_tags($mail['body'], '<br><hr>'), 0, 200) . (strlen($mail['body']) > 200 ? '...' : '') . '</div>'; } $this->display_module($this->lp, array(__('Paste e-mail'), array(), $content, false)); $vals = $this->lp->export_values(); if ($vals) { if ($vals['option'] == 'paste') { $this->paste($rs, $id); } } Base_ActionBarCommon::add(Base_ThemeCommon::get_template_file($this->get_type(), 'copy.png'), __('Paste mail'), $this->lp->get_href()); //$this->create_confirm_callback_href(__('Paste following email?'),array($this,'paste'),array($rs,$id))); } } $tb = $this->init_module('Utils/TabbedBrowser'); $tb->set_tab(__('Threaded'), array($this, 'addon_threaded'), array($rs, $id)); $tb->set_tab(__('Flat'), array($this, 'addon_flat'), array($rs, $id)); $this->display_module($tb); }
public static function display_status($record, $nolink, $desc) { $prefix = 'crm_tasks_leightbox'; $v = $record[$desc['id']]; if (!$v) { $v = 0; } $status = Utils_CommonDataCommon::get_translated_array('CRM/Status'); if ($v >= 3 || $nolink) { return $status[$v]; } CRM_FollowupCommon::drawLeightbox($prefix); if (!Utils_RecordBrowserCommon::get_access('task', 'edit', $record) && !Base_AclCommon::i_am_admin()) { return $status[$v]; } if (isset($_REQUEST['form_name']) && $_REQUEST['form_name'] == $prefix . '_follow_up_form' && $_REQUEST['id'] == $record['id']) { unset($_REQUEST['form_name']); $v = $_REQUEST['closecancel']; $action = $_REQUEST['action']; $note = $_REQUEST['note']; if ($note) { if (get_magic_quotes_gpc()) { $note = stripslashes($note); } $note = str_replace("\n", '<br />', $note); Utils_AttachmentCommon::add('task/' . $record['id'], 0, Acl::get_user(), $note); } if ($action == 'set_in_progress') { $v = 1; } Utils_RecordBrowserCommon::update_record('task', $record['id'], array('status' => $v)); if ($action == 'set_in_progress') { location(array()); } $values = $record; $values['date_and_time'] = date('Y-m-d H:i:s'); $values['title'] = __('Follow-up') . ': ' . $values['title']; $values['status'] = 0; if ($action != 'none') { $x = ModuleManager::get_instance('/Base_Box|0'); $values['follow_up'] = array('task', $record['id'], $record['title']); if ($action == 'new_task') { $x->push_main('Utils/RecordBrowser', 'view_entry', array('add', null, $values), array('task')); } if ($action == 'new_meeting') { $x->push_main('Utils/RecordBrowser', 'view_entry', array('add', null, 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, 'status' => 0, 'employees' => $values['employees'], 'customers' => $values['customers'], 'follow_up' => $values['follow_up'])), array('crm_meeting')); } if ($action == 'new_phonecall') { $x->push_main('Utils/RecordBrowser', 'view_entry', array('add', null, 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'], 'status' => 0, 'customer' => !empty($values['customers']) ? array_pop($values['customers']) : '', 'follow_up' => $values['follow_up'])), array('phonecall')); } return false; } location(array()); } if ($v == 0) { return '<a href="javascript:void(0)" onclick="' . $prefix . '_set_action(\'set_in_progress\');' . $prefix . '_set_id(\'' . $record['id'] . '\');' . $prefix . '_submit_form();">' . $status[$v] . '</a>'; } return '<a href="javascript:void(0)" class="lbOn" rel="' . $prefix . '_followups_leightbox" onMouseDown="' . $prefix . '_set_id(' . $record['id'] . ');">' . $status[$v] . '</a>'; }
public static function get_access($tab, $action, $record = null, $return_crits = false, $return_in_array = false) { if (!$return_crits && self::$admin_access && Base_AclCommon::i_am_admin()) { $ret = true; } elseif (isset($record[':active']) && !$record[':active'] && ($action == 'edit' || $action == 'delete' || $action == 'clone')) { return false; } else { static $cache = array(); $cache_key = "{$tab}__USER_" . Base_AclCommon::get_user(); if (!isset($cache[$cache_key])) { self::check_table_name($tab); $user_clearance = Base_AclCommon::get_clearance(); $r = DB::Execute('SELECT * FROM ' . $tab . '_access AS acs WHERE NOT EXISTS (SELECT * FROM ' . $tab . '_access_clearance WHERE rule_id=acs.id AND ' . implode(' AND ', array_fill(0, count($user_clearance), 'clearance!=%s')) . ')', array_values($user_clearance)); $crits = array('view' => null, 'edit' => null, 'delete' => null, 'add' => null, 'print' => null, 'export' => null, 'selection' => null); $crits_raw = array('view' => array(), 'edit' => array(), 'delete' => array(), 'add' => array(), 'print' => array(), 'export' => array(), 'selection' => array()); $fields = array(); while ($row = $r->FetchRow()) { $fields[$row['id']] = array(); $new = self::parse_access_crits($row['crits']); $crits_raw[$row['action']][$row['id']] = $new; // if new or existing crit is empty, then we have access to all records if ($new->is_empty()) { $crits[$row['action']] = $new; } if ($crits[$row['action']] instanceof Utils_RecordBrowser_Crits && $crits[$row['action']]->is_empty()) { continue; } $crits[$row['action']] = self::merge_crits($crits[$row['action']], $new, true); } $r = DB::Execute('SELECT * FROM ' . $tab . '_access_fields'); while ($row = $r->FetchRow()) { $fields[$row['rule_id']][$row['block_field']] = $row['block_field']; } $cache[$cache_key]['crits'] = $crits; $cache[$cache_key]['crits_raw'] = $crits_raw; $cache[$cache_key]['fields'] = $fields; } else { $crits = $cache[$cache_key]['crits']; $crits_raw = $cache[$cache_key]['crits_raw']; $fields = $cache[$cache_key]['fields']; } if ($return_crits) { if ($action == 'browse') { $action = 'view'; } if ($return_in_array) { return $crits_raw[$action]; } return $crits[$action]; } if ($action == 'browse') { return $crits['view'] !== null ? true : false; } $ret = false; $blocked_fields = array(); if ($action != 'browse' && $action != 'clone') { foreach ($crits_raw[$action] as $rule_id => $c) { if ($record != null && !self::check_record_against_crits($tab, $record, $c)) { continue; } if (!$ret) { $ret = true; $blocked_fields = $fields[$rule_id]; } else { foreach ($blocked_fields as $f => $v) { if (!isset($fields[$rule_id][$f])) { unset($blocked_fields[$f]); } } } } } } if ($action !== 'browse' && $action !== 'delete') { self::init($tab); if ($ret === false) { return false; } if ($ret === true) { $ret = array(); } foreach (self::$table_rows as $field => $args) { if (!isset($ret[$args['id']])) { if (isset($blocked_fields[$args['id']])) { $ret[$args['id']] = false; } else { $ret[$args['id']] = true; } } } } return $ret; }
require_once('../../../include.php'); if (!isset($_SESSION['client']['utils_recordbrowser'][$key])) { die('Invalid request'); } $crits = $_SESSION['client']['utils_recordbrowser'][$key]['crits']; $cols = $_SESSION['client']['utils_recordbrowser'][$key]['cols']; $order = $_SESSION['client']['utils_recordbrowser'][$key]['order']; $admin = $_SESSION['client']['utils_recordbrowser'][$key]['admin']; $tab = $_SESSION['client']['utils_recordbrowser'][$key]['tab']; $more_table_properties = $_SESSION['client']['utils_recordbrowser'][$key]['more_table_properties']; $limit = $_SESSION['client']['utils_recordbrowser'][$key]['limit']; ModuleManager::load_modules(); if (!Utils_RecordBrowserCommon::get_access($tab, 'print') && !Base_AclCommon::i_am_admin()) die('Access denied'); set_time_limit(0); $rb = ModuleManager::new_instance('Utils_RecordBrowser', null, 'print_rb'); $rb->construct($tab); $rb->set_inline_display(); $rb->set_header_properties($more_table_properties); $rb->disable_pagination(); ob_start(); $rb->show_data($crits, $cols, $order, $admin, false, true, $limit); $html = ob_get_clean(); $limit_info = '';
<?php /** * @author Arkadiusz Bisaga <*****@*****.**> * @copyright Copyright © 2008, Telaxus LLC * @license MIT * @version 1.0 * @package epesi-lang * @subpackage timesheet */ if (!isset($_POST['cid']) || !isset($_POST['lang'])) { die('alert(\'Invalid request\')'); } define('JS_OUTPUT', 1); define('CID', $_POST['cid']); define('READ_ONLY_SESSION', true); require_once '../../../../include.php'; ModuleManager::load_modules(); if (!Base_AclCommon::i_am_admin()) { die(''); } $lang = $_POST['lang']; Base_Lang_AdministratorCommon::send_lang($lang);
public function view_entry($mode='view', $id = null, $defaults = array(), $show_actions=true) { Base_HelpCommon::screen_name('rb_'.$mode.'_'.$this->tab); if (isset($_SESSION['client']['recordbrowser']['admin_access'])) Utils_RecordBrowserCommon::$admin_access = true; self::$mode = $mode; if ($this->navigation_executed) { $this->navigation_executed = false; return true; } if ($this->check_for_jump()) return; $theme = $this->init_module('Base/Theme'); if ($this->isset_module_variable('id')) { $id = $this->get_module_variable('id'); $this->unset_module_variable('id'); } self::$browsed_records = null; Utils_RecordBrowserCommon::$cols_order = array(); $js = ($mode!='view'); $time = microtime(true); if ($this->is_back()) { self::$clone_result = 'canceled'; return $this->back(); } $this->init(); if (is_numeric($id)) { $id = intVal($id); self::$last_record = $this->record = Utils_RecordBrowserCommon::get_record($this->tab, $id, $mode!=='edit'); } else { self::$last_record = $this->record = $id; $id = intVal($this->record['id']); } if ($id===0) $id = null; if ($id!==null && is_numeric($id)) Utils_WatchdogCommon::notified($this->tab,$id); if($mode=='add') { foreach ($defaults as $k=>$v) $this->custom_defaults[$k] = $v; foreach($this->table_rows as $field => $args) if (!isset($this->custom_defaults[$args['id']])) $this->custom_defaults[$args['id']] = $args['type'] == 'multiselect' ? array() : ''; $this->custom_defaults['created_by'] = Acl::get_user(); } $access = $this->get_access($mode=='history'?'view':$mode, isset($this->record)?$this->record:$this->custom_defaults); if ($mode=='edit' || $mode=='add') $this->view_fields_permission = $this->get_access('view', isset($this->record)?$this->record:$this->custom_defaults); else $this->view_fields_permission = $access; if ($mode!='add' && (!$access || $this->record==null)) { if (Base_AclCommon::i_am_admin()) { Utils_RecordBrowserCommon::$admin_access = true; $access = $this->get_access($mode, isset($this->record)?$this->record:$this->custom_defaults); if ($mode=='edit' || $mode=='add') $this->view_fields_permission = $this->get_access('view', isset($this->record)?$this->record:$this->custom_defaults); else $this->view_fields_permission = $access; } else { print(__('You don\'t have permission to view this record.')); if ($show_actions===true || (is_array($show_actions) && (!isset($show_actions['back']) || $show_actions['back']))) { Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); //Utils_ShortcutCommon::add(array('esc'), 'function(){'.$this->create_back_href_js().'}'); } return true; } } if ($mode=='add' && !$access) { print(__('You don\'t have permission to perform this action.')); if ($show_actions===true || (is_array($show_actions) && (!isset($show_actions['back']) || $show_actions['back']))) { Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); //Utils_ShortcutCommon::add(array('esc'), 'function(){'.$this->create_back_href_js().'}'); } return true; } if($mode == 'add' || $mode == 'edit') { $theme -> assign('click2fill', '<div id="c2fBox"></div>'); load_js('modules/Utils/RecordBrowser/click2fill.js'); eval_js('initc2f("'.__('Scan/Edit').'","'.__('Paste data here with Ctrl-v, click button below, then click on separated words in specific order and click in text field where you want put those words. They will replace text in that field.').'")'); Base_ActionBarCommon::add('clone', __('Click 2 Fill'), 'href="javascript:void(0)" onclick="c2f()"'); } // if ($mode!='add' && !$this->record[':active'] && !Base_AclCommon::i_am_admin()) return $this->back(); $tb = $this->init_module('Utils/TabbedBrowser', null, 'recordbrowser_addons'); if ($mode=='history') $tb->set_inline_display(); self::$tab_param = $tb->get_path(); $form = $this->init_module('Libs/QuickForm',null, $mode); if(Base_User_SettingsCommon::get($this->get_type(), 'confirm_leave') && ($mode == 'add' || $mode == 'edit')) $form->set_confirm_leave_page(); $this->form = $form; if($mode!='add') Utils_RecordBrowserCommon::add_recent_entry($this->tab, Acl::get_user(),$id); $dp = Utils_RecordBrowserCommon::record_processing($this->tab, $mode!='add'?$this->record:$this->custom_defaults, ($mode=='view' || $mode=='history')?'view':$mode.'ing'); if($dp===false) return false; if (is_array($dp)) $defaults = $this->custom_defaults = self::$last_record = $this->record = $dp; if (self::$last_record===null) self::$last_record = $defaults; if($mode=='add') $form->setDefaults($defaults); switch ($mode) { case 'add': $this->action = _M('New record'); break; case 'edit': $this->action = _M('Edit record'); break; case 'view': $this->action = _M('View record'); break; case 'history': $this->action = _M('Record history view'); break; } $this->prepare_view_entry_details($this->record, $mode=='history'?'view':$mode, $id, $form); if ($mode==='edit' || $mode==='add') foreach($this->table_rows as $field => $args) { if (!$access[$args['id']]) $form->freeze($args['id']); } if ($form->exportValue('submited') && $form->validate()) { $values = $form->exportValues(); foreach ($defaults as $k=>$v) { if (!isset($values[$k]) && isset($this->view_fields_permission[$k]) && !$this->view_fields_permission[$k]) $values[$k] = $v; if (isset($access[$k]) && !$access[$k]) $values[$k] = $v; } foreach ($this->table_rows as $v) { if ($v['type']=='checkbox' && !isset($values[$v['id']])) $values[$v['id']]=0; } $values['id'] = $id; foreach ($this->custom_defaults as $k=>$v) if (!isset($values[$k])) $values[$k] = $v; if ($mode=='add') { $id = Utils_RecordBrowserCommon::new_record($this->tab, $values); self::$clone_result = $id; self::$clone_tab = $this->tab; return $this->back(); } $time_from = date('Y-m-d H:i:s', $this->get_module_variable('edit_start_time')); $ret = DB::Execute('SELECT * FROM '.$this->tab.'_edit_history WHERE edited_on>=%T AND edited_on<=%T AND '.$this->tab.'_id=%d',array($time_from, date('Y-m-d H:i:s'), $id)); if ($ret->EOF) { $this->update_record($id,$values); return $this->back(); } $this->dirty_read_changes($id, $time_from); } $form->add_error_closing_buttons(); if (($mode=='edit' || $mode=='add') && $show_actions!==false) { Utils_ShortcutCommon::add(array('Ctrl','S'), 'function(){'.$form->get_submit_form_js().'}'); } if ($mode=='edit') { $this->set_module_variable('edit_start_time',$time); } if ($show_actions!==false) { if ($mode=='view') { if ($this->get_access('edit',$this->record)) { Base_ActionBarCommon::add('edit', __('Edit'), $this->create_callback_href(array($this,'navigate'), array('view_entry','edit',$id))); Utils_ShortcutCommon::add(array('Ctrl','E'), 'function(){'.$this->create_callback_href_js(array($this,'navigate'), array('view_entry','edit',$id)).'}'); } if ($this->get_access('delete',$this->record)) { Base_ActionBarCommon::add('delete', __('Delete'), $this->create_confirm_callback_href(__('Are you sure you want to delete this record?'),array($this,'delete_record'),array($id))); } if ($this->get_access('add',$this->record)) { Base_ActionBarCommon::add('clone',__('Clone'), $this->create_confirm_callback_href(__('You are about to create a copy of this record. Do you want to continue?'),array($this,'clone_record'),array($id))); } /** @var Base_Print_Printer $printer */ $printer = Utils_RecordBrowserCommon::get_printer($this->tab); if ($printer) { Base_ActionBarCommon::add('print', __('Print'), $printer->get_href(array('tab' => $this->tab, 'record_id' => $this->record['id']))); } if ($show_actions===true || (is_array($show_actions) && (!isset($show_actions['back']) || $show_actions['back']))) Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); } elseif($mode!='history') { Base_ActionBarCommon::add('save', __('Save'), $form->get_submit_form_href()); Base_ActionBarCommon::add('delete', __('Cancel'), $this->create_back_href()); } //Utils_ShortcutCommon::add(array('esc'), 'function(){'.$this->create_back_href_js().'}'); } if ($mode!='add') { $theme -> assign('info_tooltip', '<a '.Utils_TooltipCommon::open_tag_attrs(Utils_RecordBrowserCommon::get_html_record_info($this->tab, $id)).'><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils_RecordBrowser','info.png').'" /></a>'); $row_data= array(); if ($mode!='history') { if ($this->favorites) $theme -> assign('fav_tooltip', Utils_RecordBrowserCommon::get_fav_button($this->tab, $id)); if ($this->watchdog) $theme -> assign('subscription_tooltip', Utils_WatchdogCommon::get_change_subscription_icon($this->tab, $id)); if ($this->full_history) { $info = Utils_RecordBrowserCommon::get_record_info($this->tab, $id); if ($info['edited_on']===null) $theme -> assign('history_tooltip', '<a '.Utils_TooltipCommon::open_tag_attrs(__('This record was never edited')).'><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils_RecordBrowser','history_inactive.png').'" /></a>'); else $theme -> assign('history_tooltip', '<a '.Utils_TooltipCommon::open_tag_attrs(__('Click to view edit history of currently displayed record')).' '.$this->create_callback_href(array($this,'navigate'), array('view_edit_history', $id)).'><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils_RecordBrowser','history.png').'" /></a>'); } if ($this->clipboard_pattern) { $theme -> assign('clipboard_tooltip', '<a '.Utils_TooltipCommon::open_tag_attrs(__('Click to export values to copy')).' '.Libs_LeightboxCommon::get_open_href('clipboard').'><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils_RecordBrowser','clipboard.png').'" /></a>'); $text = $this->clipboard_pattern; $record = Utils_RecordBrowserCommon::get_record($this->tab, $id); /* for every field name store its value */ $data = array(); foreach($this->table_rows as $val) { $fval = Utils_RecordBrowserCommon::get_val($this->tab, $val['id'], $record, true); if(strlen($fval)) $data[$val['id']] = $fval; } /* some complicate preg match to find every occurence * of %{ .. {f_name} .. } pattern */ if (preg_match_all('/%\{(([^%\}\{]*?\{[^%\}\{]+?\}[^%\}\{]*?)+?)\}/', $text, $match)) { // match for all patterns %{...{..}...} foreach ($match[0] as $k => $matched_string) { $text_replace = $match[1][$k]; $changed = false; while(preg_match('/\{(.+?)\}/', $text_replace, $second_match)) { // match for keys in braces {key} $replace_value = ''; if(array_key_exists($second_match[1], $data)) { $replace_value = $data[$second_match[1]]; $changed = true; } $text_replace = str_replace($second_match[0], $replace_value, $text_replace); } if(! $changed ) $text_replace = ''; $text = str_replace($matched_string, $text_replace, $text); } } load_js("modules/Utils/RecordBrowser/selecttext.js"); /* remove all php new lines, replace <br>|<br/> to new lines and quote all special chars */ $ftext = htmlspecialchars(preg_replace('#<[bB][rR]/?>#', "\n", str_replace("\n", '', $text))); $flash_copy = '<object width="60" height="20">'. '<param name="FlashVars" value="txtToCopy='.$ftext.'">'. '<param name="movie" value="'.$this->get_module_dir().'copyButton.swf">'. '<embed src="'.$this->get_module_dir().'copyButton.swf" flashvars="txtToCopy='.$ftext.'" width="60" height="20">'. '</embed>'. '</object>'; $text = '<h3>'.__('Click Copy under the box or move mouse over box below to select text and hit Ctrl-c to copy it.').'</h3><div onmouseover="fnSelect(this)" style="border: 1px solid gray; margin: 15px; padding: 20px;">'.$text.'</div>'.$flash_copy; Libs_LeightboxCommon::display('clipboard',$text,__('Copy')); } } } if ($mode=='view') { $dp = Utils_RecordBrowserCommon::record_processing($this->tab, $this->record, 'display'); if ($dp && is_array($dp)) foreach ($dp as $k=>$v) $theme->assign($k, $v); } if ($mode=='view' || $mode=='history') $form->freeze(); $renderer = new HTML_QuickForm_Renderer_TCMSArraySmarty(); $form->accept($renderer); $data = $renderer->toArray(); print($data['javascript'].'<form '.$data['attributes'].'>'.$data['hidden']."\n"); $last_page = DB::GetOne('SELECT MIN(position) FROM '.$this->tab.'_field WHERE type = \'page_split\' AND field != \'General\''); if (!$last_page) $last_page = DB::GetOne('SELECT MAX(position) FROM '.$this->tab.'_field')+1; $label = DB::GetRow('SELECT field, param FROM '.$this->tab.'_field WHERE position=%s', array($last_page)); if ($label) { $cols = $label['param']; $label = $label['field']; } else $cols = false; $this->view_entry_details(1, $last_page, $data, $theme, true); $ret = DB::Execute('SELECT position, field, param FROM '.$this->tab.'_field WHERE type = \'page_split\' AND position > %d ORDER BY position', array($last_page)); $row = true; if ($mode=='view') print("</form>\n"); $tab_counter=-1; $additional_tabs = 0; $default_tab = null; while ($row) { $row = $ret->FetchRow(); if ($row) $pos = $row['position']; else $pos = DB::GetOne('SELECT MAX(position) FROM '.$this->tab.'_field WHERE active=1')+1; $valid_page = false; $hide_page = ($mode=='view' && Base_User_SettingsCommon::get('Utils/RecordBrowser','hide_empty')); foreach($this->table_rows as $field => $args) { if (!isset($data[$args['id']]) || $data[$args['id']]['type']=='hidden') continue; if ($args['position'] >= $last_page && ($pos+1 == -1 || $args['position'] < $pos+1)) { $valid_page = true; if ($hide_page && !$this->field_is_empty($this->record, $args['id'])) $hide_page = false; break; } } if ($valid_page && $pos - $last_page>1 && !isset($this->hide_tab[$label])) { $tb->set_tab(_V($label),array($this,'view_entry_details'), array($last_page, $pos+1, $data, null, false, $cols, _V($label)), $js); // TRSL if ($hide_page) { eval_js('$("'.$tb->get_tab_id(_V($label)).'").style.display="none";'); if ($default_tab===($tab_counter+1) || $tb->get_tab()==($tab_counter+1)) $default_tab = $tab_counter+2; } else $additional_tabs++; } $cols = $row['param']; $last_page = $pos; if ($row) $label = $row['field']; $tab_counter++; } if ($default_tab!==null) $tb->set_default_tab($default_tab); if ($mode!='history') { $ret = DB::Execute('SELECT * FROM recordbrowser_addon WHERE tab=%s AND enabled=1 ORDER BY pos', array($this->tab)); $addons_mod = array(); while ($row = $ret->FetchRow()) { if (ModuleManager::is_installed($row['module'])==-1) continue; if (is_callable(explode('::',$row['label']))) { $result = call_user_func(explode('::',$row['label']), $this->record, $this); if (!isset($result['show'])) $result['show']=true; if (($mode=='add' || $mode=='edit') && (!isset($result['show_in_edit']) || !$result['show_in_edit'])) continue; if ($result['show']==false) continue; if (!isset($result['label'])) $result['label']=''; $row['label'] = $result['label']; } else { if ($mode=='add' || $mode=='edit') continue; $labels = explode('#',$row['label']); foreach($labels as $i=>$label) $labels[$i] = _V($label); // translate labels from database $row['label'] = implode('#',$labels); } $mod_id = md5(serialize($row)); if (method_exists($row['module'].'Common',$row['func'].'_access') && !call_user_func(array($row['module'].'Common',$row['func'].'_access'), $this->record, $this)) continue; $addons_mod[$mod_id] = $this->init_module($row['module']); if (!method_exists($addons_mod[$mod_id],$row['func'])) $tb->set_tab($row['label'],array($this, 'broken_addon'), array(), $js); else $tb->set_tab($row['label'],array($this, 'display_module'), array(& $addons_mod[$mod_id], array($this->record, $this), $row['func']), $js); } } if ($additional_tabs==0 && ($mode=='add' || $mode=='edit' || $mode=='history')) print("</form>\n"); $this->display_module($tb); $tb->tag(); foreach ($this->fields_in_tabs as $label=>$fields) { $highlight = false; foreach ($fields as $f) { $err = $form->getElementError($f); if ($err) { $highlight = true; break; } } if ($highlight) $tb->tab_icon($label, Base_ThemeCommon::get_template_file('Utils_RecordBrowser','notify_error.png')); } if ($this->switch_to_addon) { $this->set_module_variable('switch_to_addon',false); if($tab_counter<0) $tab_counter=0; $ret = DB::Execute('SELECT * FROM recordbrowser_addon WHERE tab=%s AND enabled=1 ORDER BY pos', array($this->tab)); while ($row = $ret->FetchRow()) { if (ModuleManager::is_installed($row['module'])==-1) continue; if (is_callable(explode('::',$row['label']))) { $result = call_user_func(explode('::',$row['label']), $this->record,$this); if (isset($result['show']) && $result['show']==false) continue; $row['label'] = $result['label']; } if ($row['label']==$this->switch_to_addon) $this->switch_to_addon = $tab_counter; $tab_counter++; } $tb->switch_tab($this->switch_to_addon); location(array()); } if ($additional_tabs!=0 && ($mode=='add' || $mode=='edit' || $mode=='history')) print("</form>\n"); return true; } //view_entry
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 static function admin_access() { return Base_AclCommon::i_am_admin(); }
public static function basic_clearance($all = false) { $user_clearance = array(__('All users') => 'ALL'); if ($all || Base_AclCommon::i_am_admin()) { $user_clearance[__('Admin')] = 'ADMIN'; } if ($all || Base_AclCommon::i_am_sa()) { $user_clearance[__('Superadmin')] = 'SUPERADMIN'; } return $user_clearance; }