protected function format_values($tab, $record_id) { $rb_obj = new RBO_RecordsetAccessor($tab); $record = $rb_obj->get_record($record_id); if (!$record) { return array(); } $access = Utils_RecordBrowserCommon::get_access($tab, 'view', $record); if (!$access) { return array(); } // use RB object instance for better display callback compatibility // some of them uses Utils_RecordBrowser::$rb_obj instance $rb = ModuleManager::new_instance('Utils_RecordBrowser', null, 'rb'); $rb->construct($tab); $rb->init($tab); $fields = Utils_RecordBrowserCommon::init($tab); $printable_data = array(); foreach ($fields as $f) { if ($access[$f['id']]) { $printable_data[] = array('label' => _V($f['name']), 'value' => $record->get_val($f['id'], true)); } } // fill rows - it's easier here than in template if ($this->fill_empty_rows()) { while (count($printable_data) % $this->cols() != 0) { $printable_data[] = array('label' => '', 'value' => ''); } } return $printable_data; }
$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 = ''; if (is_array($limit)) { $offset = $limit['offset']; $per_page = $limit['numrows']; $start = $offset + 1; $end = $offset + $per_page;
/** * Creates root(first) module instance. * * Do not use directly. */ public static function create_root() { ob_start(); try { $default_module = Variable::get('default_module'); self::$root = ModuleManager::new_instance($default_module, null, '0'); } catch (Exception $e) { self::$root = ModuleManager::new_instance(FIRST_RUN, null, '0'); } $ret = trim(ob_get_contents()); if (strlen($ret) > 0 || self::$root == null) { trigger_error($ret, E_USER_ERROR); } ob_end_clean(); return self::$root; }
/** * Creates module instance which name is given as first parameter. * * Created module instance will be a child to the module which called this function. * * @param string $module_type module name * @param mixed $args arguments for module constructor * @param string $name unique name for the instance, will be assigned automatically by default * @param boolean $clear_vars clean module variables * @return mixed if access denied returns null, else child module object */ public final function init_module($module_type, $args = null, $name = null, $clear_vars = false) { if (strpos($module_type, '#') === 0) { $module_type = $this->get_type() . $module_type; } $module_type = str_replace('/', '_', $module_type); $m =& ModuleManager::new_instance($module_type, $this, $name, $clear_vars || $this->clear_child_vars); if ($args === null) { $args = array(); } elseif (!is_array($args)) { $args = array($args); } if (method_exists($m, 'construct')) { ob_start(); call_user_func_array(array($m, 'construct'), $args); ob_end_clean(); } return $m; }
private static function copy_company_data_subroutine($values) { $access = Utils_RecordBrowserCommon::get_access('contact', 'edit', $values); if (!$access) { return; } /* First click should generate html code for leightbox and show it. * This function is rarely used and we don't want to increase page size. * To do this we use REQUEST variable UCD. * * We use module variable UCD to indicate that form was shown and we * must check if it was submitted. If yes - do action. If it wasn't * we should come back to initial state - do not print LB. */ if (!(isset($_REQUEST['UCD']) || Module::static_get_module_variable('CRM/Contacts', 'UCD', 0))) { if (isset($values['company_name']) && $values['company_name']) { Base_ActionBarCommon::add('edit', __('Copy company data'), Module::create_href(array('UCD' => true))); } } if (isset($_REQUEST['UCD']) || Module::static_get_module_variable('CRM/Contacts', 'UCD', 0)) { $ucd = Module::static_get_module_variable('CRM/Contacts', 'UCD', 0); $ucd++; if ($ucd > 1) { Module::static_unset_module_variable('CRM/Contacts', 'UCD'); } else { Module::static_set_module_variable('CRM/Contacts', 'UCD', $ucd); } $lid = 'UCDprompt'; $form = ModuleManager::new_instance('Libs_QuickForm', null, 'QFUCDprompt'); $form->construct(); $sel_val = array(); foreach (array_merge(array($values['company_name']), is_array($values['related_companies']) ? $values['related_companies'] : array()) as $id) { $sel_val[$id] = self::company_format_default(self::get_company($id), true); } $form->addElement('select', 'company', __('Select company:'), $sel_val); unset($sel_val); $form->addElement('html', __('Select which fields should be copied:')); $data = array(array('sid' => 'address_1', 'tid' => 'address_1', 'text' => __('Address 1'), 'checked' => true), array('sid' => 'address_2', 'tid' => 'address_2', 'text' => __('Address 2'), 'checked' => true), array('sid' => 'city', 'tid' => 'city', 'text' => __('City'), 'checked' => true), array('sid' => 'country', 'tid' => 'country', 'text' => __('Country'), 'checked' => true), array('sid' => 'zone', 'tid' => 'zone', 'text' => __('Zone'), 'checked' => true), array('sid' => 'postal_code', 'tid' => 'postal_code', 'text' => __('Postal Code'), 'checked' => true), array('sid' => 'phone', 'tid' => 'work_phone', 'text' => __('Phone as Work Phone'), 'checked' => false), array('sid' => 'fax', 'tid' => 'fax', 'text' => __('Fax'), 'checked' => false)); foreach ($data as $row) { if (is_array($access) && isset($access[$row['tid']]) && $access[$row['tid']]) { $form->addElement('checkbox', $row['sid'], $row['text'], '', $row['checked'] ? array('checked' => 'checked') : array()); } } $ok = $form->createElement('submit', 'submit', __('Confirm'), array('onclick' => 'leightbox_deactivate("' . $lid . '")')); $cancel = $form->createElement('button', 'cancel', __('Cancel'), array('onclick' => 'leightbox_deactivate("' . $lid . '")')); $form->addGroup(array($ok, $cancel)); if ($form->validate()) { $Uvalues = $form->exportValues(); $fields = array(); foreach ($data as $row) { if (array_key_exists($row['sid'], $Uvalues)) { $fields[$row['tid']] = $row['sid']; } } if (isset($Uvalues['company'])) { $company = CRM_ContactsCommon::get_company($Uvalues['company']); $new_data = array(); foreach ($fields as $k => $v) { $new_data[$k] = $company[$v]; } Utils_RecordBrowserCommon::update_record('contact', $values['id'], $new_data); } Module::static_unset_module_variable('CRM/Contacts', 'UCD'); location(array()); } // set default to main company if ($mc = self::get_main_company()) { $form->setDefaults(array('company' => $mc)); } $html = $form->toHtml(); Libs_LeightboxCommon::display($lid, $html); Base_ActionBarCommon::add('edit', __('Copy company data'), Libs_LeightboxCommon::get_open_href($lid)); if (isset($_REQUEST['UCD'])) { eval_js('leightbox_activate(\'' . $lid . '\')'); } unset($_REQUEST['UCD']); } }