public function create_contact($r) { global $OUTPUT; $mail = $r['record']['email']; require_once dirname(__FILE__) . '/epesi_contacts_addressbook_backend.php'; $contacts = new epesi_contacts_addressbook_backend('CRM Contacts'); $ret = $contacts->search('email', $mail, true, false); if (count($ret->records)) { $OUTPUT->show_message('contactexists', 'warning'); } else { require_once dirname(__FILE__) . '/epesi_companies_addressbook_backend.php'; $companies = new epesi_companies_addressbook_backend('CRM Companies'); $ret = $companies->search('email', $mail, true, false); if (count($ret->records)) { $OUTPUT->show_message('contactexists', 'warning'); } else { if (isset($r['record']['firstname']) && $r['record']['firstname'] !== "" && isset($r['record']['surname']) && $r['record']['surname'] !== "") { $name = array($r['record']['firstname'], $r['record']['surname']); } else { $name = explode(' ', $r['record']['name'], 2); } if (count($name) < 2) { $OUTPUT->show_message('errorsavingcontact', 'warning'); } else { $loc = Base_RegionalSettingsCommon::get_default_location(); Utils_RecordBrowserCommon::new_record('contact', array('first_name' => $name[0], 'last_name' => $name[1], 'email' => $mail, 'permission' => 0, 'country' => $loc['country'])); $OUTPUT->show_message('addedsuccessfully', 'confirmation'); } } } $OUTPUT->send(); // return array('abort'=>true); }
public function install() { Base_ThemeCommon::install_default_theme($this->get_type()); $fields = array(array('name' => _M('Name'), 'type' => 'text', 'required' => true, 'param' => 16, 'extra' => false, 'visible' => true), array('name' => _M('Description'), 'type' => 'long text', 'required' => false, 'extra' => false), array('name' => _M('Percentage'), 'type' => 'float', 'required' => true, 'extra' => false, 'visible' => true)); Utils_RecordBrowserCommon::install_new_recordset('data_tax_rates', $fields); Utils_RecordBrowserCommon::new_record('data_tax_rates', array('name' => 'Non-taxable', 'percentage' => 0)); Utils_RecordBrowserCommon::set_caption('data_tax_rates', _M('Tax Rates')); Utils_RecordBrowserCommon::set_icon('data_tax_rates', Base_ThemeCommon::get_template_filename('Data/TaxRates', 'icon.png')); Utils_RecordBrowserCommon::add_access('data_tax_rates', 'view', 'ACCESS:employee'); Utils_RecordBrowserCommon::add_access('data_tax_rates', 'add', array('ACCESS:employee', 'ACCESS:manager')); Utils_RecordBrowserCommon::add_access('data_tax_rates', 'edit', array('ACCESS:employee', 'ACCESS:manager')); Utils_RecordBrowserCommon::add_access('data_tax_rates', 'delete', array('ACCESS:employee', 'ACCESS:manager')); return true; }
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 static function post_install_process($val) { $comp_id = Utils_RecordBrowserCommon::new_record('company', array('company_name' => $val['cname'], 'short_name' => isset($val['sname']) ? $val['sname'] : '', 'address_1' => isset($val['address1']) ? $val['address1'] : '', 'address_2' => isset($val['address2']) ? $val['address2'] : '', 'country' => isset($val['country']) ? $val['country'] : '', 'zone' => isset($val['state']) ? $val['state'] : '', 'city' => isset($val['city']) ? $val['city'] : '', 'postal_code' => isset($val['postal']) ? $val['postal'] : '', 'phone' => isset($val['phone']) ? $val['phone'] : '', 'fax' => isset($val['fax']) ? $val['fax'] : '', 'permission' => '0', 'web_address' => isset($val['web']) ? $val['web'] : '', 'group' => array('other'))); if (Acl::is_user()) { $mail = DB::GetOne('SELECT up.mail FROM user_password up WHERE up.user_login_id=%d', array(Acl::get_user())); Utils_RecordBrowserCommon::new_record('contact', array('first_name' => $val['fname'], 'last_name' => $val['lname'], 'address_1' => isset($val['address1']) ? $val['address1'] : '', 'address_2' => isset($val['address2']) ? $val['address2'] : '', 'country' => isset($val['country']) ? $val['country'] : '', 'zone' => isset($val['state']) ? $val['state'] : '', 'city' => isset($val['city']) ? $val['city'] : '', 'postal_code' => isset($val['postal']) ? $val['postal'] : '', 'work_phone' => isset($val['phone']) ? $val['phone'] : '', 'fax' => isset($val['fax']) ? $val['fax'] : '', 'web_address' => isset($val['web']) ? $val['web'] : '', 'company_name' => $comp_id, 'login' => Acl::get_user(), 'permission' => '0', 'email' => $mail, 'group' => array('office', 'field'))); } }
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
/** * Add new record to recordset, when array is supplied and return it's object * or just returns empty data object to fill it with data and perform save() * method. * @param array|null $array_or_null associative array of data to or null. * @return RBO_Record|null */ public function new_record($array_or_null = null) { if (is_array($array_or_null)) { $id = Utils_RecordBrowserCommon::new_record($this->tab, $array_or_null); if (!is_numeric($id)) { return null; } $array_or_null['id'] = $id; $array_or_null['created_by'] = Acl::get_user(); $array_or_null[':active'] = true; return $this->record_to_object($array_or_null); } return $this->record_to_object(array()); }
private function archive($uids, $verbose = true) { global $E_SESSION; $rcmail = rcmail::get_instance(); $path = getcwd(); chdir(str_replace(array('/modules/CRM/Roundcube/RC', '\\modules\\CRM\\Roundcube\\RC'), '', $path)); $msgs = array(); if (!is_array($uids)) { $uids = $uids->get(); } foreach ($uids as $uid) { $msg = new rcube_message($uid); if ($msg === null || empty($msg->headers)) { if ($verbose) { $rcmail->output->command('display_message', 'messageopenerror', 'error'); } return false; } else { $msgs[$uid] = $msg; } } $map = array(); foreach ($msgs as $k => $msg) { $sends = $rcmail->storage->decode_address_list($msg->headers->to); $map[$k] = array(); foreach ($sends as $send) { $addr = $send['mailto']; $ret = $this->look_contact($addr); $map[$k] = array_merge($map[$k], $ret); } $addr = $rcmail->storage->decode_address_list($msg->headers->from); if ($addr) { $addr = array_shift($addr); } if (!isset($addr['mailto']) || !$addr['mailto']) { $map[$k] = false; continue; } $ret = $this->look_contact($addr['mailto']); $map[$k] = array_merge($map[$k], $ret); } if (!isset($_SESSION['force_archive'])) { $_SESSION['force_archive'] = array(); } foreach ($map as $k => $ret) { if (!$ret && !isset($_SESSION['force_archive'][$k]) && $verbose) { $_SESSION['force_archive'][$k] = 1; $rcmail->output->command('display_message', $this->gettext('contactnotfound'), 'error'); return false; } } $attachments_dir = DATA_DIR . '/CRM_Roundcube/attachments/'; $epesi_mails = array(); if (!file_exists($attachments_dir)) { mkdir($attachments_dir); } foreach ($msgs as $k => $msg) { $contacts = $map[$k]; $mime_map = array(); foreach ($msg->mime_parts as $mid => $m) { $mime_map[$m->mime_id] = md5($k . microtime(true) . $mid); } if ($msg->has_html_part()) { // $body = $msg->first_html_part(); foreach ($msg->mime_parts as $mime_id => $part) { $mimetype = strtolower($part->ctype_primary . '/' . $part->ctype_secondary); if ($mimetype == 'text/html') { $body = $rcmail->storage->get_message_part($msg->uid, $mime_id, $part); if (isset($part->replaces)) { $cid_map = $part->replaces; } else { $cid_map = array(); } break; } } foreach ($cid_map as $k => &$v) { if (preg_match('/_part=(.*?)&/', $v, $matches)) { $mid = $matches[1]; if (isset($mime_map[$mid])) { $v = 'get.php?' . http_build_query(array('mail_id' => '__MAIL_ID__', 'mime_id' => $mime_map[$mid])); } } else { unset($cid_map[$k]); } } $body = rcmail_wash_html($body, array('safe' => true, 'inline_html' => true), $cid_map); } else { $body = '<pre>' . $msg->first_text_part() . '</pre>'; } $date = rcube_imap_generic::strToTime($msg->get_header('DATE')); $headers = array(); foreach ($msg->headers as $k => $v) { if (is_string($v) && $k != 'from' && $k != 'to' && $k != 'body_structure') { $headers[] = $k . ': ' . rcube_mime::decode_mime_string((string) $v); } } $message_id = str_replace(array('<', '>'), '', $msg->get_header('MESSAGE-ID')); if (Utils_RecordBrowserCommon::get_records_count('rc_mails', array('message_id' => $message_id)) > 0) { $rcmail->output->command('display_message', $this->gettext('archived_duplicate'), 'warning'); return false; } $employee = DB::GetOne('SELECT id FROM contact_data_1 WHERE active=1 AND f_login=%d', array($E_SESSION['user'])); $data = array('message_id' => $message_id, 'references' => $msg->get_header('REFERENCES'), 'contacts' => $contacts, 'date' => $date, 'subject' => substr($msg->subject, 0, 256), 'body' => $body, 'headers_data' => implode("\n", $headers), 'from' => $rcmail->storage->decode_header($msg->headers->from), 'to' => $rcmail->storage->decode_header($msg->headers->to), 'employee' => $employee); $id = Utils_RecordBrowserCommon::new_record('rc_mails', $data); $epesi_mails[] = $id; foreach ($contacts as $c) { list($rs, $con_id) = explode(':', $c); if ($rs == 'P') { Utils_WatchdogCommon::new_event('contact', $con_id, 'N_New mail'); } else { Utils_WatchdogCommon::new_event('company', $con_id, 'N_New mail'); } } Utils_WatchdogCommon::new_event('contact', $employee, 'N_New mail'); /*DB::Execute('INSERT INTO rc_mails_data_1(created_on,created_by,f_contacts,f_date,f_employee,f_subject,f_body,f_headers_data,f_direction) VALUES(%T,%d,%s,%T,%d,%s,%s,%s,%b)',array( time(),$E_SESSION['user'],$contacts,$date,$employee,substr($msg->subject,0,256),$body,implode("\n",$headers),$sent_mbox)); $id = DB::Insert_ID('rc_mails_data_1','id');*/ foreach ($msg->mime_parts as $mid => $m) { if (!$m->disposition) { continue; } if (isset($cid_map['cid:' . $m->content_id])) { $attachment = 0; } else { $attachment = 1; } DB::Execute('INSERT INTO rc_mails_attachments(mail_id,type,name,mime_id,attachment) VALUES(%d,%s,%s,%s,%b)', array($id, $m->mimetype, $m->filename, $mime_map[$m->mime_id], $attachment)); if (!file_exists($attachments_dir . $id)) { mkdir($attachments_dir . $id); } $fp = fopen($attachments_dir . $id . '/' . $mime_map[$m->mime_id], 'w'); $msg->get_part_content($m->mime_id, $fp); fclose($fp); } } //$rcmail->output->command('delete_messages'); $E_SESSION['rc_mails_cp'] = $epesi_mails; chdir($path); return true; }
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 add($group,$permission,$user,$note=null,$oryg=null,$file=null,$func=null,$args=null,$sticky=false,$note_title='',$crypted=false) { if(($oryg && !$file) || ($file && !$oryg)) trigger_error('Invalid add attachment call: missing original filename or temporary filepath',E_USER_ERROR); $old_user = Acl::get_user(); if($old_user!=$user) Acl::set_user($user); $id = Utils_RecordBrowserCommon::new_record('utils_attachment',array('local'=>$group,'note'=>$note,'permission'=>$permission,'func'=>serialize($func),'args'=>serialize($args),'sticky'=>$sticky?1:0,'title'=>$note_title,'crypted'=>$crypted?1:0)); if($old_user!=$user) Acl::set_user($old_user); if($file) self::add_file($id, $user, $oryg, $file); return $id; }
public function install() { $this->create_data_dir(); // create htaccess to prevent logs to be available on the internet $htaccess = $this->get_data_dir() . '.htaccess'; $f = fopen($htaccess, 'w'); if ($f === false) { print "Cannot create .htaccess file ({$htaccess}). " . "Your Roundcube logs may be available on the internet!"; } else { fwrite($f, "deny from all\n"); fclose($f); } Base_ThemeCommon::install_default_theme($this->get_type()); $this->drop_all_rc_tables(); if (DB::is_mysql()) { $f = file_get_contents('modules/CRM/Roundcube/RC/SQL/mysql.initial.sql'); } else { $f = file_get_contents('modules/CRM/Roundcube/RC/SQL/postgres.initial.sql'); } foreach (explode(';', $f) as $q) { $q = trim($q); if (!$q) { continue; } DB::Execute($q); } Utils_CommonDataCommon::new_array('CRM/Roundcube/Security', array('tls' => _M('TLS'), 'ssl' => _M('SSL')), true, true); //addons table $fields = array(array('name' => _M('Recordset'), 'type' => 'text', 'param' => 64, 'display_callback' => array($this->get_type() . 'Common', 'display_recordset'), 'QFfield_callback' => array($this->get_type() . 'Common', 'QFfield_recordset'), 'required' => true, 'extra' => false, 'visible' => true)); Utils_RecordBrowserCommon::install_new_recordset('rc_related', $fields); Utils_RecordBrowserCommon::set_caption('rc_related', _M('Mail Related Recordsets')); Utils_RecordBrowserCommon::register_processing_callback('rc_related', array('CRM_RoundcubeCommon', 'processing_related')); Utils_RecordBrowserCommon::add_access('rc_related', 'view', 'ACCESS:employee'); Utils_RecordBrowserCommon::add_access('rc_related', 'add', 'ADMIN'); Utils_RecordBrowserCommon::add_access('rc_related', 'edit', 'SUPERADMIN'); Utils_RecordBrowserCommon::add_access('rc_related', 'delete', 'SUPERADMIN'); Utils_RecordBrowserCommon::new_record('rc_related', array('recordset' => 'company')); Utils_RecordBrowserCommon::new_record('rc_related', array('recordset' => 'contact')); //accounts table $fields = array(array('name' => _M('EPESI User'), 'type' => 'integer', 'extra' => false, 'visible' => true, 'required' => true, 'display_callback' => array('CRM_RoundcubeCommon', 'display_epesi_user'), 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_epesi_user')), array('name' => _M('Email'), 'type' => 'text', 'extra' => false, 'visible' => true, 'required' => true, 'param' => 128), array('name' => _M('Account Name'), 'type' => 'text', 'extra' => false, 'visible' => true, 'required' => true, 'param' => 32, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_account_name')), array('name' => _M('Server'), 'type' => 'text', 'extra' => false, 'visible' => true, 'param' => '255', 'required' => true), array('name' => _M('Login'), 'type' => 'text', 'required' => true, 'param' => '255', 'extra' => false, 'visible' => true), array('name' => _M('Password'), 'type' => 'text', 'required' => true, 'extra' => false, 'param' => '255', 'visible' => false, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_password'), 'display_callback' => array('CRM_RoundcubeCommon', 'display_password')), array('name' => _M('Security'), 'type' => 'commondata', 'param' => array('CRM/Roundcube/Security'), 'extra' => false, 'visible' => false, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_security')), array('name' => _M('SMTP Server'), 'type' => 'text', 'extra' => false, 'visible' => false, 'param' => '255', 'required' => true), array('name' => _M('SMTP Auth'), 'type' => 'checkbox', 'extra' => false, 'visible' => false, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_smtp_auth')), array('name' => _M('SMTP Login'), 'type' => 'text', 'required' => false, 'param' => '255', 'extra' => false, 'visible' => false, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_smtp_login')), array('name' => _M('SMTP Password'), 'type' => 'text', 'extra' => false, 'param' => '255', 'visible' => false, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_smtp_password'), 'display_callback' => array('CRM_RoundcubeCommon', 'display_password')), array('name' => _M('SMTP Security'), 'type' => 'commondata', 'param' => array('CRM/Roundcube/Security'), 'extra' => false, 'visible' => false, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_smtp_security')), array('name' => _M('Default Account'), 'type' => 'checkbox', 'extra' => false, 'visible' => true, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_default_account')), array('name' => _M('Advanced'), 'type' => 'page_split'), array('name' => _M('Archive on sending'), 'type' => 'checkbox', 'extra' => true, 'visible' => false), array('name' => _M('Use EPESI Archive directories'), 'type' => 'checkbox', 'extra' => true, 'visible' => false), array('name' => _M('IMAP Root'), 'type' => 'text', 'param' => 32, 'extra' => true, 'visible' => false), array('name' => _M('IMAP Delimiter'), 'type' => 'text', 'param' => 8, 'extra' => true, 'visible' => false)); Utils_RecordBrowserCommon::install_new_recordset('rc_accounts', $fields); Utils_RecordBrowserCommon::set_caption('rc_accounts', _M('Mail accounts')); Utils_RecordBrowserCommon::register_processing_callback('rc_accounts', array('CRM_RoundcubeCommon', 'submit_account')); $fields = array(array('name' => _M('Subject'), 'type' => 'text', 'param' => '256', 'extra' => false, 'visible' => true, 'required' => false, 'display_callback' => array('CRM_RoundcubeCommon', 'display_subject')), array('name' => _M('Count'), 'type' => 'calculated', 'extra' => false, 'visible' => true, 'required' => false, 'display_callback' => array('CRM_RoundcubeCommon', 'display_thread_count'), 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_thread_count')), array('name' => _M('Contacts'), 'type' => 'crm_company_contact', 'param' => array('field_type' => 'multiselect'), 'required' => false, 'extra' => false, 'visible' => true), array('name' => _M('First Date'), 'type' => 'timestamp', 'extra' => false, 'visible' => true, 'required' => false), array('name' => _M('Last Date'), 'type' => 'timestamp', 'extra' => false, 'visible' => true, 'required' => false), array('name' => _M('Attachments'), 'type' => 'calculated', 'extra' => false, 'visible' => true, 'display_callback' => array('CRM_RoundcubeCommon', 'display_thread_attachments'), 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_thread_attachments'))); Utils_RecordBrowserCommon::install_new_recordset('rc_mail_threads', $fields); Utils_RecordBrowserCommon::set_caption('rc_mail_threads', _M('Mail Thread')); Utils_RecordBrowserCommon::new_addon('rc_mail_threads', 'CRM/Roundcube', 'thread_addon', _M('E-mails')); Utils_RecordBrowserCommon::set_search('rc_mail_threads', 2, -1); $fields = array(array('name' => _M('Subject'), 'type' => 'text', 'param' => '256', 'extra' => false, 'visible' => true, 'required' => false, 'display_callback' => array('CRM_RoundcubeCommon', 'display_subject')), array('name' => _M('Contacts'), 'type' => 'crm_company_contact', 'param' => array('field_type' => 'multiselect'), 'required' => false, 'extra' => false, 'visible' => true), array('name' => _M('Employee'), 'type' => 'crm_contact', 'param' => array('field_type' => 'select'), 'extra' => false, 'visible' => true, 'required' => false), array('name' => _M('Related'), 'type' => 'multiselect', 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_related'), 'param' => '__RECORDSETS__::;CRM_RoundcubeCommon::related_crits', 'extra' => false, 'required' => false, 'visible' => true), array('name' => _M('Date'), 'type' => 'timestamp', 'extra' => false, 'visible' => true, 'required' => false), array('name' => _M('Attachments'), 'type' => 'calculated', 'extra' => false, 'visible' => true, 'display_callback' => array('CRM_RoundcubeCommon', 'display_attachments'), 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_attachments')), array('name' => _M('Headers Data'), 'type' => 'long text', 'extra' => false, 'visible' => false, 'required' => false), array('name' => _M('Body'), 'type' => 'long text', 'extra' => false, 'visible' => false, 'required' => false, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_body')), array('name' => _M('From'), 'type' => 'text', 'param' => 128, 'extra' => false, 'visible' => false, 'required' => false), array('name' => _M('To'), 'type' => 'text', 'param' => 4096, 'extra' => false, 'visible' => false, 'required' => false), array('name' => _M('Thread'), 'type' => 'select', 'param' => 'rc_mail_threads::Count', 'extra' => false, 'visible' => false, 'required' => false, 'display_callback' => array('CRM_RoundcubeCommon', 'display_mail_thread'), 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_mail_thread')), array('name' => _M('Message ID'), 'type' => 'text', 'param' => 128, 'extra' => false, 'visible' => false, 'required' => false, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_hidden')), array('name' => _M('References'), 'type' => 'text', 'param' => 4096 * 4, 'extra' => false, 'visible' => false, 'required' => false, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_hidden'))); Utils_RecordBrowserCommon::install_new_recordset('rc_mails', $fields); Utils_RecordBrowserCommon::set_caption('rc_mails', _M('Mails')); Utils_RecordBrowserCommon::set_tpl('rc_mails', Base_ThemeCommon::get_template_filename('CRM/Roundcube', 'mails')); Utils_RecordBrowserCommon::register_processing_callback('rc_mails', array('CRM_RoundcubeCommon', 'submit_mail')); Utils_RecordBrowserCommon::set_search('rc_mails', 2, -1); DB::CreateIndex('rc_mails_thread_idx', 'rc_mails_data_1', 'f_thread'); DB::CreateIndex('rc_mails_msgid_idx', 'rc_mails_data_1', 'f_message_id'); Utils_RecordBrowserCommon::new_addon('rc_mails', 'CRM/Roundcube', 'mail_body_addon', _M('Body')); Utils_RecordBrowserCommon::new_addon('rc_mails', 'CRM/Roundcube', 'attachments_addon', _M('Attachments')); Utils_RecordBrowserCommon::new_addon('rc_mails', 'CRM/Roundcube', 'mail_headers_addon', _M('Headers')); @DB::DropTable('rc_mails_attachments'); DB::CreateTable('rc_mails_attachments', ' mail_id I4 NOTNULL, type C(32), name C(255), mime_id C(32), attachment I1 DEFAULT 1', array('constraints' => ', FOREIGN KEY (mail_id) REFERENCES rc_mails_data_1(ID)')); DB::CreateTable('rc_mails_attachments_download', ' mail_id I4 NOTNULL, hash C(32), created_on T DEFTIMESTAMP', array('constraints' => ', FOREIGN KEY (mail_id) REFERENCES rc_mails_data_1(ID)')); Utils_RecordBrowserCommon::new_addon('contact', 'CRM/Roundcube', 'addon', _M('E-mails')); Utils_RecordBrowserCommon::new_addon('company', 'CRM/Roundcube', 'addon', _M('E-mails')); $fields = array(array('name' => _M('Record Type'), 'type' => 'hidden', 'param' => Utils_RecordBrowserCommon::actual_db_type('text', 64), 'required' => false, 'visible' => false, 'filter' => true, 'extra' => false), array('name' => _M('Record ID'), 'type' => 'hidden', 'param' => Utils_RecordBrowserCommon::actual_db_type('integer'), 'filter' => false, 'required' => false, 'extra' => false, 'visible' => false), array('name' => _M('Nickname'), 'type' => 'text', 'required' => true, 'param' => '64', 'extra' => false, 'visible' => true, 'QFfield_callback' => array('CRM_RoundcubeCommon', 'QFfield_nickname')), array('name' => _M('Email'), 'type' => 'email', 'required' => true, 'param' => array('unique' => true), 'extra' => false, 'visible' => true)); Utils_RecordBrowserCommon::install_new_recordset('rc_multiple_emails', $fields); Utils_RecordBrowserCommon::set_favorites('rc_multiple_emails', true); Utils_RecordBrowserCommon::set_caption('rc_multiple_emails', _M('Mail addresses')); Utils_RecordBrowserCommon::set_icon('rc_multiple_emails', Base_ThemeCommon::get_template_filename('CRM/Roundcube', 'icon.png')); Utils_RecordBrowserCommon::set_search('rc_multiple_emails', 2, 0); Utils_RecordBrowserCommon::new_addon('contact', 'CRM/Roundcube', 'mail_addresses_addon', _M('E-mail addresses')); Utils_RecordBrowserCommon::new_addon('company', 'CRM/Roundcube', 'mail_addresses_addon', _M('E-mail addresses')); Variable::set('crm_roundcube_global_signature', "Message sent with EPESI - managing business your way!<br /><a href=\"http://epe.si\">http://epe.si</a>"); Utils_RecordBrowserCommon::add_access('rc_accounts', 'view', 'ACCESS:employee', array('epesi_user' => 'USER_ID')); Utils_RecordBrowserCommon::add_access('rc_accounts', 'add', 'ACCESS:employee'); Utils_RecordBrowserCommon::add_access('rc_accounts', 'edit', 'ACCESS:employee', array(), array('epesi_user')); Utils_RecordBrowserCommon::add_access('rc_accounts', 'delete', 'ACCESS:employee', array('epesi_user' => 'USER_ID')); Utils_RecordBrowserCommon::add_access('rc_mails', 'view', 'ACCESS:employee', array(), array('headers_data')); Utils_RecordBrowserCommon::add_access('rc_mails', 'delete', 'ACCESS:employee'); Utils_RecordBrowserCommon::add_access('rc_mails', 'edit', 'ACCESS:employee', array(), array('subject', 'employee', 'date', 'headers_data', 'body', 'from', 'to', 'thread', 'message_id', 'references')); Utils_RecordBrowserCommon::add_access('rc_mail_threads', 'view', 'ACCESS:employee'); Utils_RecordBrowserCommon::add_access('rc_mail_threads', 'delete', 'ACCESS:employee'); Utils_RecordBrowserCommon::add_access('rc_multiple_emails', 'view', 'ACCESS:employee'); Utils_RecordBrowserCommon::add_access('rc_multiple_emails', 'add', 'ACCESS:employee'); Utils_RecordBrowserCommon::add_access('rc_multiple_emails', 'edit', 'ACCESS:employee'); Utils_RecordBrowserCommon::add_access('rc_multiple_emails', 'delete', 'ACCESS:employee'); return true; }
public static function create_thread($id) { $m = Utils_RecordBrowserCommon::get_record('rc_mails', $id); $thread = $m['thread']; if (!$thread && $m['message_id']) { $thread = DB::GetOne('SELECT f_thread FROM rc_mails_data_1 WHERE f_references is not null AND f_references LIKE ' . DB::Concat('\'%%\'', '%s', '\'%%\'') . ' AND active=1', array($m['message_id'])); } if (!$thread && $m['references']) { $thread = DB::GetOne('SELECT f_thread FROM rc_mails_data_1 WHERE f_message_id is not null AND %s LIKE ' . DB::Concat('\'%%\'', 'f_message_id', '\'%%\'') . ' AND active=1', array($m['references'])); } if (!$thread) { $thread = Utils_RecordBrowserCommon::new_record('rc_mail_threads', array('subject' => $m['subject'], 'contacts' => array_unique(array_merge($m['contacts'], array('P:' . $m['employee']))), 'first_date' => $m['date'], 'last_date' => $m['date'])); } Utils_RecordBrowserCommon::update_record('rc_mails', $id, array('thread' => $thread), false, null, true); $t = Utils_RecordBrowserCommon::get_record('rc_mail_threads', $thread); Utils_RecordBrowserCommon::update_record('rc_mail_threads', $thread, array('contacts' => array_unique(array_merge($t['contacts'], $m['contacts'], array('P:' . $m['employee']))), 'first_date' => strtotime($m['date']) < strtotime($t['first_date']) ? $m['date'] : $t['first_date'], 'last_date' => strtotime($m['date']) > strtotime($t['last_date']) ? $m['date'] : $t['last_date'], 'subject' => trim($m['references']) == '' || mb_strlen($m['subject']) < mb_strlen($t['subject']) ? $m['subject'] : $t['subject'])); }
$links_qty = $old_checkpoint->get('links_qty'); } else { $links_qty = DB::GetOne('SELECT count(*) FROM utils_attachment_link'); $old_checkpoint->set('links_qty', $links_qty); } while ($ret = DB::SelectLimit('SELECT * FROM utils_attachment_link ORDER BY id', 1, $links++)) { $link = $ret->FetchRow(); if (!$link) { break; } Patch::set_message('Processing note: ' . $links . '/' . $links_qty); $old_checkpoint->require_time(2); $notes = DB::GetAll('SELECT * FROM utils_attachment_note WHERE attach_id=%d ORDER BY revision', $link['id']); $note = array_shift($notes); Acl::set_user($note['created_by']); $rid = Utils_RecordBrowserCommon::new_record('utils_attachment', array('title' => $link['title'], 'note' => $note['text'], 'permission' => $link['permission'], 'sticky' => $link['sticky'], 'crypted' => array('crypted' => $link['crypted']), 'func' => $link['func'], 'args' => $link['args'], '__date' => $note['created_on'], 'local' => $link['local'])); // DB::Execute('INSERT INTO utils_attachment_local(local,attachment) VALUES(%s,%d)',array($link['local'],$rid)); $map[$link['id']] = $rid; foreach ($notes as $note) { Acl::set_user($note['created_by']); Utils_RecordBrowserCommon::update_record('utils_attachment', $rid, array('note' => $note['text'], '__date' => $note['created_on'])); } Acl::set_user($us); $old_checkpoint->set('links', $links); $old_checkpoint->set('map', $map); } } $old_checkpoint->done(); Patch::set_message('Updating database'); $delete_old_fk_checkpoint = Patch::checkpoint('delete_old_fk'); if (!$delete_old_fk_checkpoint->is_done()) {
$rs_checkpoint->done(); } Patch::set_message('Processing addons'); $old_checkpoint = Patch::checkpoint('old'); if (!$old_checkpoint->is_done()) { $old = $old_checkpoint->get('old', array()); if (empty($old) && ModuleManager::is_installed('Premium/RoundcubeCustomAddons') >= 0) { $old = Utils_RecordBrowserCommon::get_records('premium_roundcube_custom_addon'); ModuleManager::uninstall('Premium/RoundcubeCustomAddons'); } foreach ($old as $i => $r) { if ($r['recordset'] == 'company' || $r['recordset'] == 'contact') { continue; } $old_checkpoint->require_time(2); Utils_RecordBrowserCommon::new_record('rc_related', array('recordset' => $r['recordset'])); unset($old[$i]); $old_checkpoint->set('old', $old); } $old_checkpoint->done(); } Patch::set_message('Processing related'); $related_checkpoint = Patch::checkpoint('related'); if (!$related_checkpoint->is_done()) { while (1) { $related = $related_checkpoint->get('related', array()); if (empty($related)) { $related = Utils_RecordBrowserCommon::get_records('rc_mails_assoc', array(), array(), array(), 10); if (empty($related)) { break; }