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; }
function __construct($tab, $tab_alias = 'rest', $admin_mode = false) { $this->tab = $tab; $this->fields = Utils_RecordBrowserCommon::init($tab); $this->fields_by_id = Utils_RecordBrowserCommon::$hash; $this->tab_alias = $tab_alias; $this->admin_mode = $admin_mode; }
public static function mobile_rb_edit($tab, $id) { if ($id === false) { $rec = array(); } else { $rec = self::get_record($tab, $id); } $cols = Utils_RecordBrowserCommon::init($tab); $defaults = array(); if ($id === false) { $mode = 'add'; $access = array(); $defaults = self::record_processing($tab, $defaults, 'adding'); } else { $mode = 'edit'; $access = Utils_RecordBrowserCommon::get_access($tab, 'view', $rec); if (is_array($access)) { foreach ($access as $k => $v) { if (!$v) { unset($rec[$k]); } } } $defaults = $rec = self::record_processing($tab, $rec, 'editing'); } $QFfield_callback_table = array(); $ret = DB::Execute('SELECT * FROM ' . $tab . '_callback WHERE freezed=0'); while ($row = $ret->FetchRow()) { $QFfield_callback_table[$row['field']] = $row['callback']; } $defaults = array_merge($defaults, $_SESSION['rb_' . $tab . '_defaults']); $qf = new HTML_QuickForm('rb_edit', 'post', 'mobile.php?' . http_build_query($_GET)); foreach ($cols as $field => $args) { if (isset($access[$args['id']]) && !$access[$args['id']]) { continue; } if (isset($rec[$args['id']])) { $val = $rec[$args['id']]; } elseif (isset($defaults[$args['id']])) { $val = $defaults[$args['id']]; } else { $val = null; } $label = _V($args['name']); // TRSL if (isset($QFfield_callback_table[$field])) { $mobile_rb = new Utils_RecordBrowserMobile($tab, $rec); self::call_QFfield_callback($QFfield_callback_table[$field], $qf, $args['id'], $label, $mode, $val, $args, $mobile_rb, null); if ($mode == 'edit') { unset($defaults[$args['id']]); } continue; } switch ($args['type']) { case 'calculated': $qf->addElement('static', $args['id'], $label); if (!is_array($rec)) { $values = $defaults; } else { $values = $rec; if (is_array($defaults)) { $values = $values + $defaults; } } if (!isset($values[$args['id']])) { $values[$args['id']] = ''; } $val = Utils_RecordBrowserCommon::get_val($tab, $field, $values, true, $args); if ($val !== null) { $qf->setDefaults(array($args['id'] => $val)); } break; case 'integer': case 'float': $qf->addElement('text', $args['id'], $label); if ($args['type'] == 'integer') { $qf->addRule($args['id'], __('Only integer numbers are allowed.'), 'regex', '/^[0-9]*$/'); } else { $qf->addRule($args['id'], __('Only numbers are allowed.'), 'numeric'); } if ($val !== null) { $qf->setDefaults(array($args['id'] => $val)); } break; case 'checkbox': $qf->addElement('checkbox', $args['id'], $label, ''); if ($val !== null) { $qf->setDefaults(array($args['id'] => $val)); } break; case 'currency': $qf->addElement('currency', $args['id'], $label); if ($val !== null) { $qf->setDefaults(array($args['id'] => $val)); } break; case 'text': $qf->addElement('text', $args['id'], $label, array('maxlength' => $args['param'])); $qf->addRule($args['id'], __('Maximum length for this field is %s characters.', array($args['param'])), 'maxlength', $args['param']); if ($val !== null) { $qf->setDefaults(array($args['id'] => $val)); } break; case 'long text': $qf->addElement('textarea', $args['id'], $label, array('maxlength' => 200)); $qf->addRule($args['id'], __('Maximum length for this field in mobile edition is 200 chars.'), 'maxlengt', 200); if ($val !== null) { $qf->setDefaults(array($args['id'] => $val)); } break; case 'commondata': $param = explode('::', $args['param']['array_id']); foreach ($param as $k => $v) { if ($k != 0) { $param[$k] = self::get_field_id($v); } } if (count($param) == 1) { $qf->addElement($args['type'], $args['id'], $label, $param, array('empty_option' => true, 'id' => $args['id'], 'order_by_key' => $args['param']['order_by_key'])); if ($val !== null) { $qf->setDefaults(array($args['id'] => $val)); } } break; case 'select': $comp = array(); $ref = explode(';', $args['param']); if (isset($ref[1])) { $crits_callback = $ref[1]; } else { $crits_callback = null; } if (isset($ref[2])) { $multi_adv_params = call_user_func(explode('::', $ref[2])); } else { $multi_adv_params = null; } if (!isset($multi_adv_params) || !is_array($multi_adv_params)) { $multi_adv_params = array(); } if (!isset($multi_adv_params['order'])) { $multi_adv_params['order'] = array(); } if (!isset($multi_adv_params['cols'])) { $multi_adv_params['cols'] = array(); } if (!isset($multi_adv_params['format_callback'])) { $multi_adv_params['format_callback'] = array(); } $ref = $ref[0]; @(list($tab2, $col) = explode('::', $ref)); if (!isset($col)) { trigger_error($field); } if ($tab2 == '__RECORDSETS__') { continue; } //skip multi recordsets chained selector if ($tab2 == '__COMMON__') { $data = Utils_CommonDataCommon::get_translated_tree($col); if (!is_array($data)) { $data = array(); } $comp = $comp + $data; } else { if (isset($crits_callback)) { $crit_callback = explode('::', $crits_callback); if (is_callable($crit_callback)) { $crits = call_user_func($crit_callback, false, $rec); $adv_crits = call_user_func($crit_callback, true, $rec); } else { $crits = $adv_crits = array(); } if ($adv_crits === $crits) { $adv_crits = null; } if ($adv_crits !== null) { continue; //skip record picker } } else { $crits = array(); } $col = explode('|', $col); $col_id = array(); foreach ($col as $c) { $col_id[] = self::get_field_id($c); } $records = Utils_RecordBrowserCommon::get_records($tab2, $crits, empty($multi_adv_params['format_callback']) ? $col_id : array(), !empty($multi_adv_params['order']) ? $multi_adv_params['order'] : array()); $ext_rec = array(); if (isset($rec[$args['id']])) { if (!is_array($rec[$args['id']])) { if ($rec[$args['id']] != '') { $rec[$args['id']] = array($rec[$args['id']] => $rec[$args['id']]); } else { $rec[$args['id']] = array(); } } } if (isset($defaults[$args['id']])) { if (!is_array($defaults[$args['id']])) { $rec[$args['id']][$defaults[$args['id']]] = $defaults[$args['id']]; } else { foreach ($defaults[$args['id']] as $v) { $rec[$args['id']][$v] = $v; } } } $single_column = count($col_id) == 1; if (isset($rec[$args['id']])) { $ext_rec = array_flip($rec[$args['id']]); foreach ($ext_rec as $k => $v) { $c = Utils_RecordBrowserCommon::get_record($tab2, $k); if (!empty($multi_adv_params['format_callback'])) { $n = call_user_func($multi_adv_params['format_callback'], $c); } else { if ($single_column) { $n = $c[$col_id[0]]; } else { $n = array(); foreach ($col_id as $cid) { $n[] = $c[$cid]; } $n = implode(' ', $n); } } $comp[$k] = $n; } } if (!empty($multi_adv_params['order'])) { natcasesort($comp); } foreach ($records as $k => $v) { if (!empty($multi_adv_params['format_callback'])) { $n = call_user_func($multi_adv_params['format_callback'], $v); } else { // $n = $v[$col_id]; if ($single_column) { $n = $v[$col_id[0]]; } else { $n = array(); foreach ($col_id as $cid) { $n[] = $v[$cid]; } $n = implode(' ', $n); } } $comp[$k] = $n; unset($ext_rec[$v['id']]); } if (empty($multi_adv_params['order'])) { natcasesort($comp); } } if ($args['type'] === 'select') { $comp = array('' => '---') + $comp; } $qf->addElement($args['type'], $args['id'], $label, $comp, array('id' => $args['id'])); if ($id !== false) { $qf->setDefaults(array($args['id'] => $rec[$args['id']])); } break; case 'date': $qf->addElement('date', $args['id'], $label, array('format' => 'd M Y', 'minYear' => date('Y') - 95, 'maxYear' => date('Y') + 5, 'addEmptyOption' => true, 'emptyOptionText' => '--')); if ($val) { $qf->setDefaults(array($args['id'] => $val)); } break; case 'timestamp': $qf->addElement('date', $args['id'], $label, array('format' => 'd M Y H:i', 'minYear' => date('Y') - 95, 'maxYear' => date('Y') + 5, 'addEmptyOption' => true, 'emptyOptionText' => '--')); if ($val) { $default = Base_RegionalSettingsCommon::time2reg($val, true, true, true, false); $qf->setDefaults(array($args['id'] => $default)); } break; case 'time': $qf->addElement('date', $args['id'], $label, array('format' => 'H:i', 'addEmptyOption' => true, 'emptyOptionText' => '--')); if ($val) { $default = Base_RegionalSettingsCommon::time2reg($val, true, true, true, false); $qf->setDefaults(array($args['id'] => $default)); } break; case 'multiselect': //ignore if ($id === false) { continue; } $val = Utils_RecordBrowserCommon::get_val($tab, $field, $rec, true, $args); if ($val === '') { continue; } $qf->addElement('static', $args['id'], $label); $qf->setDefaults(array($args['id'] => $val)); unset($defaults[$args['id']]); break; } if ($args['required']) { $qf->addRule($args['id'], __('Field required'), 'required'); } } $qf->addElement('submit', 'submit_button', __('Save'), IPHONE ? 'class="button white"' : ''); if ($qf->validate()) { $values = $qf->exportValues(); foreach ($cols as $v) { if ($v['type'] == 'checkbox' && !isset($values[$v['id']])) { $values[$v['id']] = 0; } elseif ($v['type'] == 'date') { if (is_array($values[$v['id']]) && $values[$v['id']]['Y'] !== '' && $values[$v['id']]['M'] !== '' && $values[$v['id']]['d'] !== '') { $values[$v['id']] = sprintf("%d-%02d-%02d", $values[$v['id']]['Y'], $values[$v['id']]['M'], $values[$v['id']]['d']); } else { $values[$v['id']] = ''; } } elseif ($v['type'] == 'timestamp') { if ($values[$v['id']]['Y'] !== '' && $values[$v['id']]['M'] !== '' && $values[$v['id']]['d'] !== '' && $values[$v['id']]['H'] !== '' && $values[$v['id']]['i'] !== '') { $timestamp = $values[$v['id']]['Y'] . '-' . $values[$v['id']]['M'] . '-' . $values[$v['id']]['d'] . ' ' . $values[$v['id']]['H'] . ':' . $values[$v['id']]['i']; $values[$v['id']] = Base_RegionalSettingsCommon::reg2time($timestamp, true); } else { $values[$v['id']] = ''; } } elseif ($v['type'] == 'time') { if ($values[$v['id']]['H'] !== '' && $values[$v['id']]['i'] !== '') { $time = recalculate_time(date('Y-m-d'), $values[$v['id']]); $timestamp = Base_RegionalSettingsCommon::reg2time(date('1970-01-01 H:i:s', $time), true); $values[$v['id']] = date('1970-01-01 H:i:s', $timestamp); } else { $values[$v['id']] = ''; } } } foreach ($defaults as $k => $v) { if (!isset($values[$k])) { $values[$k] = $v; } } if ($id !== false) { $values['id'] = $id; Utils_RecordBrowserCommon::update_record($tab, $id, $values); } else { $id = Utils_RecordBrowserCommon::new_record($tab, $values); } return false; } $renderer =& $qf->defaultRenderer(); $qf->accept($renderer); print $renderer->toHtml(); }
public function init($admin=false, $force=false) { if($this->tab=='__RECORDSETS__' || preg_match('/,/',$this->tab)) $params=array('','',0,0,0); else $params = DB::GetRow('SELECT caption, icon, recent, favorites, full_history FROM recordbrowser_table_properties WHERE tab=%s', array($this->tab)); if ($params==false) trigger_error('There is no such recordSet as '.$this->tab.'.', E_USER_ERROR); list($this->caption,$this->icon,$this->recent,$this->favorites,$this->full_history) = $params; $this->favorites &= !$this->disabled['fav']; $this->watchdog = Utils_WatchdogCommon::category_exists($this->tab) && !$this->disabled['watchdog']; $this->clipboard_pattern = Utils_RecordBrowserCommon::get_clipboard_pattern($this->tab); //If Caption or icon not specified assign default values if ($this->caption=='') $this->caption='Record Browser'; if ($this->icon=='') $this->icon = Base_ThemeCommon::get_template_file('Base_ActionBar','icons/settings.png'); else $this->icon = Base_ThemeCommon::get_template_file($this->icon); $this->table_rows = Utils_RecordBrowserCommon::init($this->tab, $admin, $force); $this->requires = array(); $this->display_callback_table = array(); $this->QFfield_callback_table = array(); if($this->tab=='__RECORDSETS__' || preg_match('/,/',$this->tab)) return; $ret = DB::Execute('SELECT * FROM '.$this->tab.'_callback'); while ($row = $ret->FetchRow()) if ($row['freezed']==1) $this->display_callback_table[$row['field']] = explode('::',$row['callback']); else $this->QFfield_callback_table[$row['field']] = explode('::',$row['callback']); }
function __construct($tab) { $this->tab = $tab; $this->fields = Utils_RecordBrowserCommon::init($tab); $this->fields_by_id = Utils_RecordBrowserCommon::$hash; }
$admin = $_REQUEST['admin']; $path = $_REQUEST['path']; define('CID', $cid); define('READ_ONLY_SESSION', true); require_once '../../../include.php'; $crits = Module::static_get_module_variable($path, 'crits_stuff', null); $order = Module::static_get_module_variable($path, 'order_stuff', null); if ($crits === null || $order === null) { $crits = $order = array(); } ModuleManager::load_modules(); if (!Utils_RecordBrowserCommon::get_access($tab, 'export') && !Base_AclCommon::i_am_admin()) { die('Access denied'); } set_time_limit(0); $tab_info = Utils_RecordBrowserCommon::init($tab); $records = Utils_RecordBrowserCommon::get_records($tab, $crits, array(), $order, array(), $admin); header('Content-Type: text/csv'); //header('Content-Length: '.strlen($buffer)); header('Content-disposition: attachement; filename="' . $tab . '_export_' . date('Y_m_d__H_i_s') . '.csv"'); if (headers_sent()) { die('Some data has already been output to browser, can\'t send the file'); } $cols = array(__('Record ID'), __('Created on'), __('Created by'), __('Edited on'), __('Edited by')); foreach ($tab_info as $v) { if (!$v['export']) { continue; } $cols[] = _V($v['name']); if ($v['style'] == 'currency') { $cols[] = _V($v['name']) . ' - ' . __('Currency');
<?php ob_start(); define('CID', false); require_once '../../../include.php'; ModuleManager::load_modules(); if (isset($_GET['tbName']) && $_GET['tbName'] != "" && (isset($_GET['tbCaption']) && $_GET['tbCaption'] != "")) { $tbName = $_GET['tbName']; $tbCaption = $_GET['tbCaption']; $arrayFields = Utils_RecordBrowserCommon::init($tbName); foreach ($arrayFields as $key => $value) { print "<option value=" . $tbName . ":" . $value['id'] . ">" . $tbCaption . " - " . $value['name'] . "</option>"; } } $content = ob_get_contents(); ob_end_clean(); require_once 'libs/minify/HTTP/Encoder.php'; $he = new HTTP_Encoder(array('content' => $content)); if (MINIFY_ENCODE) { $he->encode(); } $he->sendAll(); exit;
* @package epesi-utils * @subpackage RecordBrowser */ //!!! $table,$crits and sort variables are passed globally defined("_VALID_ACCESS") || die; //init $ret = DB::GetRow('SELECT caption, recent, favorites FROM recordbrowser_table_properties WHERE tab=%s', array($table)); if (isset($_GET['search']) && $_GET['search'] !== "Search" && $_GET['search'] !== "") { $type = 'all'; } else { $type = isset($_GET['type']) ? $_GET['type'] : Base_User_SettingsCommon::get('Utils_RecordBrowser', $table . '_default_view'); } $order_num = isset($_GET['order']) && isset($_GET['order_dir']) ? $_GET['order'] : -1; $order = false; //cols $cols = Utils_RecordBrowserCommon::init($table); $cols_out = array(); foreach ($cols as $k => $col) { if (!$col['visible'] && (!isset($info[$col['id']]) || !$info[$col['id']])) { continue; } if (isset($info[$col['id']]) && !$info[$col['id']]) { continue; } if (count($cols_out) == $order_num) { $order = $col['id']; } $col['name'] = _V($col['name']); if ($type != 'recent') { $cols_out[] = array('name' => $col['name'], 'order' => $col['id'], 'record' => $col, 'key' => $k); } else {
public static function map_rb_field_to_query_builder_filters($tab, $f, $in_depth = true, $prefix = '', $sufix = '', $label_prefix = '') { $filters = array(); $type = null; $values = null; $input = null; $opts = array(); $opts['id'] = $prefix . $f['id'] . $sufix; $opts['field'] = $opts['id']; $opts['label'] = $label_prefix . _V($f['name']); if ($tab == 'contact' && $f['id'] == 'login' || $tab == 'rc_accounts' && $f['id'] == 'epesi_user') { $type = 'boolean'; // just for valid operators $input = 'select'; $values = array('' => '[' . __('Empty') . ']', 'USER_ID' => __('User Login')); } else { switch ($f['type']) { case 'text': $type = 'string'; break; case 'multiselect': case 'select': $param = explode(';', $f['param']); $ref = explode('::', $param[0]); $tabs = $ref[0]; if ($tabs == '__RECORDSETS__') { $single_tab = false; } else { $tabs = explode(',', $tabs); $single_tab = count($tabs) == 1; } $type = 'boolean'; $input = 'select'; $values = self::permissions_get_field_values($tab, $f, $in_depth); if ($in_depth && $single_tab) { $one_tab = reset($tabs); if (Utils_RecordBrowserCommon::check_table_name($one_tab, false, false)) { $fields = Utils_RecordBrowserCommon::init($one_tab); foreach ($fields as $k => $v) { if ($v['type'] == 'calculated' || $v['type'] == 'hidden') { } else { $new_label_prefix = _V($f['name']) . ' ' . __('is set to record where') . ' '; $sub_filter = self::map_rb_field_to_query_builder_filters($tab, $v, false, $f['id'] . '[', ']', $new_label_prefix); if ($sub_filter) { $sub_filter = reset($sub_filter); $sub_filter['optgroup'] = $new_label_prefix; $filters[] = $sub_filter; } } } } } break; case 'commondata': $type = 'boolean'; $input = 'select'; $array_id = is_array($f['param']) ? $f['param']['array_id'] : $f['ref_table']; $values = array('' => '[' . __('Empty') . ']'); if (strpos($array_id, '::') === false) { $values = $values + Utils_CommonDataCommon::get_translated_array($array_id, is_array($f['param']) ? $f['param']['order_by_key'] : false); } break; case 'integer': $type = 'integer'; break; case 'float': $type = 'double'; break; case 'timestamp': $type = 'datetime'; case 'date': if (!$type) { $type = 'date'; } // absolute value filter $opts['plugin'] = 'datepicker'; $opts['plugin_config'] = array('dateFormat' => 'yy-mm-dd'); // relative value filter $filt2 = $opts; $filt2['id'] .= '_relative'; $filt2['label'] .= ' (' . __('relative') . ')'; $filt2['type'] = 'date'; $filt2['input'] = 'select'; $filt2['values'] = self::permissions_get_field_values($tab, $f); $filters[] = $filt2; break; case 'time': $type = 'time'; break; case 'long text': $type = 'string'; $input = 'textarea'; break; case 'hidden': break; case 'calculated': break; case 'checkbox': $type = 'boolean'; break; case 'currency': $type = 'double'; break; case 'autonumber': break; } } if ($type) { $opts['type'] = $type; if ($values) { $opts['values'] = $values; } if ($input) { $opts['input'] = $input; } $filters[] = $opts; return $filters; } return null; }
public static function QFfield_identifierfields(&$form, $field, $label, $mode, $default, $desc, $rb_obj) { //print "<br>MODE on QFfield_recordfields == ". $mode; if ($mode == 'add') { $recordset_form = $form->addElement('multiselect', $field, $label, null); $recordset_form->on_add_js('call_js_add_result(\'add\');'); $recordset_form->on_remove_js('call_js_remove_fields();'); } else { if ($mode == 'edit' || $mode == 'view') { $arrayAllValues = array(); $dataField = self::getRecordsetsOnly($default); foreach ($dataField as $tbName) { $arrayFields = Utils_RecordBrowserCommon::init($tbName); foreach ($arrayFields as $key => $value) { $arrayAllValues[$tbName . ":" . $value['id']] = Utils_RecordBrowserCommon::get_caption($tbName) . " - " . $value['name']; } } $recordset_form = $form->addElement('multiselect', $field, $label, $arrayAllValues); $recordset_form->on_add_js('call_js_add_result(\'edit\');'); $recordset_form->on_remove_js('call_js_remove_fields();'); $form->setDefaults(array($field => self::parse_array($default))); eval_js('changeAddedRecordset(\'search_field_for_identifier__to\')'); } } }