Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 public static function user_settings()
 {
     if (Utils_RecordBrowserCommon::get_access('rc_accounts', 'browse')) {
         return array(__('E-mail Accounts') => 'account_manager');
     }
     return array();
 }
Esempio n. 3
0
 public static function menu()
 {
     if (Utils_RecordBrowserCommon::get_access('crm_assets', 'browse')) {
         return array(_M('CRM') => array('__submenu__' => 1, _M('Assets') => array()));
     } else {
         return array();
     }
 }
 public static function menu()
 {
     $tabs = DB::GetAssoc('SELECT menu, tab FROM recordbrowser_custom_recordsets WHERE active=1');
     $result = array();
     foreach ($tabs as $k => $v) {
         if (!$k) {
             continue;
         }
         if (!Utils_RecordBrowserCommon::get_access($v, 'browse')) {
             continue;
         }
         $k = explode(self::$sep, $k);
         $menu = self::build_menu($k, array('tab' => $v));
         $result = array_merge_recursive($menu, $result);
     }
     return $result;
 }
Esempio n. 5
0
// date in the past
if (!isset($_GET['mail_id']) || !is_numeric($_GET['mail_id']) || !isset($_GET['mime_id']) || !is_numeric($_GET['mime_id']) && strlen($_GET['mime_id']) != 32) {
    die('Invalid request');
}
define('CID', false);
define('READ_ONLY_SESSION', true);
require_once '../../../include.php';
ModuleManager::load_modules();
if (!Acl::is_user()) {
    die('Not logged in');
}
$rec = Utils_RecordBrowserCommon::get_record('rc_mails', $_GET['mail_id']);
if (!$rec) {
    die('Invalid e-mail id.');
}
$access_fields = Utils_RecordBrowserCommon::get_access('rc_mails', 'view', $rec);
if (!isset($access_fields['body']) || !$access_fields['body']) {
    die('Access forbidden');
}
list($mimetype, $name, $attachment) = DB::GetRow('SELECT type,name,attachment FROM rc_mails_attachments WHERE mail_id=%d AND mime_id=%s', array($_GET['mail_id'], $_GET['mime_id']));
$disposition = $attachment ? 'attachment' : 'inline';
$filename = DATA_DIR . '/CRM_Roundcube/attachments/' . $_GET['mail_id'] . '/' . $_GET['mime_id'];
if (headers_sent()) {
    die('Some data has already been output to browser, can\'t send file');
}
if (!file_exists($filename)) {
    die('File doesn\'t exists');
}
$buffer = file_get_contents($filename);
header('Content-Type: ' . $mimetype);
header('Content-Length: ' . strlen($buffer));
Esempio n. 6
0
fputcsv($f, $cols);
$currency_codes = DB::GetAssoc('SELECT symbol, code FROM utils_currency');
function rb_csv_export_format_currency_value($v, $symbol)
{
    static $currency_decimal_signs = null;
    static $currency_thou_signs;
    if ($currency_decimal_signs === null) {
        $currency_decimal_signs = DB::GetAssoc('SELECT symbol, decimal_sign FROM utils_currency');
        $currency_thou_signs = DB::GetAssoc('SELECT symbol, thousand_sign FROM utils_currency');
    }
    $v = str_replace($currency_thou_signs[$symbol], '', $v);
    $v = str_replace($currency_decimal_signs[$symbol], '.', $v);
    return $v;
}
foreach ($records as $r) {
    $has_access = Utils_RecordBrowserCommon::get_access($tab, 'view', $r);
    if (!$has_access) {
        continue;
    }
    $rec = array($r['id']);
    $details = Utils_RecordBrowserCommon::get_record_info($tab, $r['id']);
    $rec[] = $details['created_on'];
    $rec[] = Base_UserCommon::get_user_label($details['created_by'], true);
    $rec[] = $details['edited_on'];
    $rec[] = $details['edited_by'] ? Base_UserCommon::get_user_label($details['edited_by'], true) : '';
    foreach ($tab_info as $field_name => $v) {
        if (!$v['export']) {
            continue;
        }
        ob_start();
        if (!isset($has_access[$v['id']]) || !$has_access[$v['id']]) {
Esempio n. 7
0
$cid = $_REQUEST['cid'];
$id = $_REQUEST['id'];
$disposition = isset($_REQUEST['view']) && $_REQUEST['view'] ? 'inline' : 'attachment';
define('CID', $cid);
define('READ_ONLY_SESSION', true);
require_once '../../../include.php';
ModuleManager::load_modules();
if (!Acl::is_user()) {
    die('Permission denied');
}
$file = DB::GetRow('SELECT uaf.attach_id, uaf.original, uaf.filestorage_id FROM utils_attachment_file uaf WHERE uaf.id=%d', array($id));
$rec = Utils_RecordBrowserCommon::get_record('utils_attachment', $file['attach_id']);
if (!$rec) {
    die('Invalid attachment.');
}
$access_fields = Utils_RecordBrowserCommon::get_access('utils_attachment', 'view', $rec);
if (!isset($access_fields['note']) || !$access_fields['note']) {
    die('Access forbidden');
}
$original = $file['original'];
$local = $rec['id'];
$fsid = $file['filestorage_id'];
$crypted = $rec['crypted'];
$meta = Utils_FileStorageCommon::meta($fsid);
require_once 'mime.php';
if (headers_sent()) {
    die('Some data has already been output to browser, can\'t send file');
}
$password = '';
if ($crypted) {
    $password = $_SESSION['client']['cp' . $rec['id']];
Esempio n. 8
0
 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 .= '&nbsp;';
                 $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);
 }
Esempio n. 9
0
 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();
 }
Esempio n. 10
0
 public static function contact_activities_access()
 {
     return Utils_RecordBrowserCommon::get_access('contact', 'browse');
 }
Esempio n. 11
0
 public function companies_actions($r, $gb_row)
 {
     $me = CRM_ContactsCommon::get_my_record();
     $emp = array($me['id']);
     $cus = array();
     $cus[] = 'C:' . $r['id'];
     if (ModuleManager::is_installed('CRM/Meeting') !== -1 && Utils_RecordBrowserCommon::get_access('crm_meeting', 'add')) {
         $gb_row->add_action(Utils_RecordBrowserCommon::create_new_record_href('crm_meeting', array('employees' => $emp, 'customers' => $cus, 'status' => 0, 'priority' => 1, 'permission' => 0)), __('New Meeting'), null, Base_ThemeCommon::get_template_file('CRM_Calendar', 'icon-small.png'));
     }
     if (ModuleManager::is_installed('CRM/Tasks') !== -1 && Utils_RecordBrowserCommon::get_access('task', 'add')) {
         $gb_row->add_action(Utils_RecordBrowserCommon::create_new_record_href('task', array('employees' => $emp, 'customers' => $cus, 'status' => 0, 'priority' => 1, 'permission' => 0)), __('New Task'), null, Base_ThemeCommon::get_template_file('CRM_Tasks', 'icon-small.png'));
     }
     if (ModuleManager::is_installed('CRM/PhoneCall') !== -1 && Utils_RecordBrowserCommon::get_access('phonecall', 'add')) {
         $gb_row->add_action(Utils_RecordBrowserCommon::create_new_record_href('phonecall', array('date_and_time' => date('Y-m-d H:i:s'), 'customer' => 'C:' . $r['id'], 'employees' => $me['id'], 'status' => 0, 'permission' => 0, 'priority' => 1), 'none', array('date_and_time')), __('New Phonecall'), null, Base_ThemeCommon::get_template_file('CRM_PhoneCall', 'icon-small.png'));
     }
     $gb_row->add_action(Utils_RecordBrowser::$rb_obj->add_note_button_href('company/' . $r['id']), __('New Note'), null, Base_ThemeCommon::get_template_file('Utils_Attachment', 'icon_small.png'));
 }
Esempio n. 12
0
<?php
if(!isset($_REQUEST['cid']) || !isset($_REQUEST['id']) || !isset($_REQUEST['pass']))
    die('Invalid usage');
$cid = $_REQUEST['cid'];
$id = $_REQUEST['id'];
$pass = $_REQUEST['pass'];

define('CID', $cid);
define('READ_ONLY_SESSION',false);
require_once('../../../include.php');
ModuleManager::load_modules();

$row = Utils_RecordBrowserCommon::get_record('utils_attachment',$id);
if(!Utils_RecordBrowserCommon::get_access('utils_attachment','view',$row)) die(json_encode(array('error'=>__('Access denied'))));

$decoded = Utils_AttachmentCommon::decrypt($row['note'],$pass);
if($decoded!==false) {
    $_SESSION['client']['cp'.$row['id']] = $pass;
    ob_start();
    $note = Utils_AttachmentCommon::display_note($row,false, null, true);
    $note = ob_get_clean().$note;
    die(json_encode(array(
        'note'=>$note,
        'js'=>Epesi::get_output()
    )));
}
die(json_encode(array('error'=>__('Invalid password'))));
Esempio n. 13
0
    $col['name'] = _V($col['name']);
    if ($type != 'recent') {
        $cols_out[] = array('name' => $col['name'], 'order' => $col['id'], 'record' => $col, 'key' => $k);
    } else {
        $cols_out[] = array('name' => $col['name'], 'record' => $col, 'key' => $k);
    }
}
//views
/*if($ret['recent'] && $type!='recent') print('<a '.(IPHONE?'class="button red" ':'').'href="mobile.php?'.http_build_query(array_merge($_GET,array('type'=>'recent','rb_offset'=>0))).'">'.__('Recent').'</a>'.(IPHONE?'':'<br>'));
if($ret['favorites'] && $type!='favorites') print('<a '.(IPHONE?'class="button green" ':'').'href="mobile.php?'.http_build_query(array_merge($_GET,array('type'=>'favorites','rb_offset'=>0))).'">'.__('Favorites').'</a>'.(IPHONE?'':'<br>'));
if(($ret['recent'] || $ret['favorites']) && $type!='all') print('<a '.(IPHONE?'class="button white" ':'').'href="mobile.php?'.http_build_query(array_merge($_GET,array('type'=>'all','rb_offset'=>0))).'">'.__('All').'</a>'.(IPHONE?'':'<br>'));*/
print '<form method="GET" action="mobile.php?' . http_build_query($_GET) . '">';
if (!IPHONE) {
    print '<table width="100%"><tr><td>';
}
if (Utils_RecordBrowserCommon::get_access($table, 'add')) {
    if (IPHONE) {
        print '<a ' . 'class="button green" ' . mobile_stack_href(array('Utils_RecordBrowserCommon', 'mobile_rb_edit'), array($table, false), __('Add record')) . '>' . __('Add') . '</a>';
    } else {
        print '<a ' . mobile_stack_href(array('Utils_RecordBrowserCommon', 'mobile_rb_edit'), array($table, false), __('Add record')) . '><img src="' . Base_ThemeCommon::get_template_file('Utils_RecordBrowser', 'mobile_add.png') . '" border="0"></a>';
    }
}
if (!IPHONE) {
    print '</td><td align="right">';
}
if (IPHONE) {
    print '<ul class="form">';
}
print '<input type="hidden" name="rb_offset" value="0">';
print (IPHONE ? '<li>' : '') . '<select onchange="form.elements[\'search\'].value=\'Search\';form.submit()" name="type"><option value="all"' . ($type == 'all' ? ' selected=1' : '') . '>' . __('All') . '</option><option value="recent"' . ($type == 'recent' ? ' selected=1' : '') . '>' . __('Recent') . '</option><option value="favorites"' . ($type == 'favorites' ? ' selected=1' : '') . '>' . __('Favorites') . '</option></select>' . (IPHONE ? '</li>' : '');
print (IPHONE ? '<li>' : '') . '<input type="text" name="search" value="' . (isset($_GET['search']) ? $_GET['search'] : 'Search') . '" onclick="clickclear(this, \'Search\')" onblur="clickrecall(this,\'Search\')" />' . (IPHONE ? '</li>' : '');
Esempio n. 14
0
    public function check_new_record_access($data) {
		$problems = array();
		$ret = array();
        if (is_array(Utils_RecordBrowser::$last_record))
		    foreach (Utils_RecordBrowser::$last_record as $k=>$v) if (!isset($data[$k])) $data[$k] = $v;
//		$crits = Utils_RecordBrowserCommon::get_access($this->tab,'add',null, true);
		$crits2 = Utils_RecordBrowserCommon::get_access($this->tab,'add',null, true, true);
		foreach($crits2 as $crits) {
		    $problems = array();
    		Utils_RecordBrowserCommon::check_record_against_crits($this->tab, $data, $crits, $problems);
    		foreach ($problems as $f) {
	    		$f = explode('[', $f);
		    	$ret[$f[0]] = __('Invalid value');
		    }
    		if($problems) continue;
    		return true;
    	}
		return $ret;
    }
Esempio n. 15
0
<?php

if (!isset($_REQUEST['cid']) || !isset($_REQUEST['id']) || !isset($_REQUEST['pass'])) {
    die('Invalid usage');
}
$cid = $_REQUEST['cid'];
$id = $_REQUEST['id'];
$pass = $_REQUEST['pass'];
define('CID', $cid);
define('READ_ONLY_SESSION', false);
require_once '../../../include.php';
ModuleManager::load_modules();
$row = Utils_RecordBrowserCommon::get_record('utils_attachment', $id);
if (!Utils_RecordBrowserCommon::get_access('utils_attachment', 'view', $row)) {
    die(json_encode(array('error' => __('Access denied'))));
}
$decoded = Utils_AttachmentCommon::decrypt($row['note'], $pass);
if ($decoded !== false) {
    $_SESSION['client']['cp' . $row['id']] = $pass;
    ob_start();
    $note = Utils_AttachmentCommon::display_note($row, false, null, 'utils_attachment', true);
    $note = ob_get_clean() . $note;
    die(json_encode(array('note' => $note, 'js' => Epesi::get_output())));
}
die(json_encode(array('error' => __('Invalid password'))));
Esempio n. 16
0
 public static function mobile_menu()
 {
     if (!Utils_RecordBrowserCommon::get_access('crm_meeting', 'browse')) {
         return array();
     }
     return array(__('Meetings') => array('func' => 'mobile_meetings', 'color' => 'blue'));
 }
Esempio n. 17
0
 public static function get_access($id) {
     $locals = DB::GetCol('SELECT local FROM utils_attachment_local WHERE attachment=%d',array($id));
     $ret = false;
     foreach($locals as $local) {
         list($recordset,$key) = explode('/',$local,2);
         if(!Utils_RecordBrowserCommon::check_table_name($recordset, false, false)
            || !is_numeric($key)
            || Utils_RecordBrowserCommon::get_access($recordset,'view',$key)) {
             $ret = true;
             break;
         }
     }
     return $ret;
 }
Esempio n. 18
0
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 = '';
Esempio n. 19
0
 public static function applet_caption()
 {
     $br_contact = Utils_RecordBrowserCommon::get_access('contact', 'browse');
     if ($br_contact === true || !isset($br_contact['login'])) {
         return __('Recent Contacts');
     }
     return false;
 }
Esempio n. 20
0
 public static function crm_event_get($id)
 {
     if (!is_array($id)) {
         $r = Utils_RecordBrowserCommon::get_record('task', $id);
     } else {
         $r = $id;
         $id = $r['id'];
     }
     $r = Utils_RecordBrowserCommon::filter_record_by_access('task', $r);
     if (!$r) {
         return null;
     }
     $next = array('type' => __('Task'));
     $day = $r['deadline'];
     $iday = strtotime($day);
     $next['id'] = $r['id'];
     $base_unix_time = strtotime(date('1970-01-01 00:00:00'));
     $next['start'] = $iday;
     $next['timeless'] = $day;
     $next['duration'] = -1;
     $next['title'] = (string) $r['title'];
     $next['description'] = (string) $r['description'];
     $next['color'] = 'gray';
     if ($r['status'] == 0 || $r['status'] == 1) {
         switch ($r['priority']) {
             case 0:
                 $next['color'] = 'green';
                 break;
             case 1:
                 $next['color'] = 'yellow';
                 break;
             case 2:
                 $next['color'] = 'red';
                 break;
         }
     }
     if ($r['status'] == 2) {
         $next['color'] = 'blue';
     }
     if ($r['status'] == 3) {
         $next['color'] = 'gray';
     }
     $next['view_action'] = Utils_RecordBrowserCommon::create_record_href('task', $r['id'], 'view');
     if (Utils_RecordBrowserCommon::get_access('task', 'edit', $r) !== false) {
         $next['edit_action'] = Utils_RecordBrowserCommon::create_record_href('task', $r['id'], 'edit');
     } else {
         $next['edit_action'] = false;
         $next['move_action'] = false;
     }
     if (Utils_RecordBrowserCommon::get_access('task', 'delete', $r) == false) {
         $next['delete_action'] = false;
     }
     /*		$r_new = $r;
     		if ($r['status']==0) $r_new['status'] = 1;
     		if ($r['status']<=1) $next['actions'] = array(
     			array('icon'=>Base_ThemeCommon::get_template_file('CRM/Meeting', 'close_event.png'), 'href'=>self::get_status_change_leightbox_href($r_new, false, array('id'=>'status')))
     		);*/
     $start_time = Base_RegionalSettingsCommon::time2reg($next['start'], 2, false, false);
     $event_date = Base_RegionalSettingsCommon::time2reg($next['start'], false, 3, false);
     $inf2 = array(__('Date') => '<b>' . $event_date . '</b>');
     $emps = array();
     foreach ($r['employees'] as $e) {
         $e = CRM_ContactsCommon::contact_format_no_company($e, true);
         $e = str_replace('&nbsp;', ' ', $e);
         if (mb_strlen($e, 'UTF-8') > 33) {
             $e = mb_substr($e, 0, 30, 'UTF-8') . '...';
         }
         $emps[] = $e;
     }
     $next['busy_label'] = $r['employees'];
     $cuss = array();
     foreach ($r['customers'] as $c) {
         $c = CRM_ContactsCommon::display_company_contact(array('customers' => $c), true, array('id' => 'customers'));
         $cuss[] = str_replace('&nbsp;', ' ', $c);
     }
     $inf2 += array(__('Task') => '<b>' . $next['title'] . '</b>', __('Description') => $next['description'], __('Assigned to') => implode('<br>', $emps), __('Contacts') => implode('<br>', $cuss), __('Status') => Utils_CommonDataCommon::get_value('CRM/Status/' . $r['status'], true), __('Access') => Utils_CommonDataCommon::get_value('CRM/Access/' . $r['permission'], true), __('Priority') => Utils_CommonDataCommon::get_value('CRM/Priority/' . $r['priority'], true), __('Notes') => Utils_AttachmentCommon::count('task/' . $r['id']));
     $next['employees'] = $r['employees'];
     $next['customers'] = $r['customers'];
     $next['status'] = $r['status'] <= 2 ? 'active' : 'closed';
     $next['custom_tooltip'] = '<center><b>' . __('Task') . '</b></center><br>' . Utils_TooltipCommon::format_info_tooltip($inf2) . '<hr>' . CRM_ContactsCommon::get_html_record_info($r['created_by'], $r['created_on'], null, null);
     return $next;
 }
Esempio n. 21
0
if (!isset($_POST['tab']) || !isset($_POST['id']) || !isset($_POST['cid'])) {
    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::is_user()) {
    die;
}
$id = $_POST['id'];
$tab = $_POST['tab'];
$now = $_POST['date'];
$created = Utils_RecordBrowserCommon::get_record($tab, $id, true);
$access = Utils_RecordBrowserCommon::get_access($tab, 'view', $created);
$created['created_by_login'] = Base_UserCommon::get_user_login($created['created_by']);
$field_hash = array();
$edited = DB::GetRow('SELECT ul.login, c.edited_on FROM ' . $tab . '_edit_history AS c LEFT JOIN user_login AS ul ON ul.id=c.edited_by WHERE c.' . $tab . '_id=%d ORDER BY edited_on DESC', array($id));
Utils_RecordBrowserCommon::init($tab);
$table_rows = Utils_RecordBrowserCommon::$table_rows;
foreach ($table_rows as $field => $args) {
    $field_hash[$args['id']] = $field;
}
$ret = DB::Execute('SELECT ul.login, c.id, c.edited_on, c.edited_by FROM ' . $tab . '_edit_history AS c LEFT JOIN user_login AS ul ON ul.id=c.edited_by WHERE c.' . $tab . '_id=%d AND edited_on>%T ORDER BY edited_on DESC, id DESC', array($id, $now));
while ($row = $ret->FetchRow()) {
    $changed = array();
    $ret2 = DB::Execute('SELECT * FROM ' . $tab . '_edit_history_data WHERE edit_id=%d', array($row['id']));
    while ($row2 = $ret2->FetchRow()) {
        if ($row2['field'] != 'id' && (!isset($access[$row2['field']]) || !$access[$row2['field']])) {
            continue;