private static function notify_client($buffer) { if (JS_OUTPUT && class_exists('Epesi')) { chdir(dirname(dirname(__FILE__))); Epesi::clean(); if (DISPLAY_ERRORS) { Epesi::js("\$('debug_content').style.display='block';"); Epesi::text($buffer . '<hr>', 'error_box', 'prepend'); } Epesi::alert('There was an error in one of epesi modules.' . (DISPLAY_ERRORS ? ' Details are displayed at the bottom of the page, please send this information to system administrator.' : '')); return Epesi::get_output(); } return $buffer; }
header("Content-type: text/javascript"); define('JS_OUTPUT', 1); define('CID', false); //don't load user session define('READ_ONLY_SESSION', true); require_once '../../../include.php'; ModuleManager::load_modules(); if (!Base_AclCommon::is_user()) { Epesi::alert('Session expired, logged out - reloading epesi.'); Epesi::redirect(''); Epesi::send_output(); exit; } $default = isset($_POST['default_dash']) && $_POST['default_dash']; if ($default && !Base_AdminCommon::get_access('Base_Dashboard') || !isset($_POST['col']) || !isset($_POST['data'])) { Epesi::alert('Permission denied'); Epesi::send_output(); exit; } if (!$default) { $user = Base_AclCommon::get_user(); } $tab = json_decode($_POST['tab']); parse_str($_POST['data'], $x); if (!isset($x['ab_item'])) { exit; } if (is_numeric($_POST['col']) && $_POST['col'] < 3 && $_POST['col'] >= 0) { if ($default) { $table = 'base_dashboard_default_applets'; $val = null;
public static function search($search, $categories) { if (!$categories) { return; } $token_length = self::get_token_length(); $limit = Base_SearchCommon::get_recordset_limit_records(); $tabs_priority = DB::GetAssoc('SELECT id,search_priority FROM recordbrowser_table_properties WHERE search_include>0'); $categories = array_intersect($categories, array_keys($tabs_priority)); $categories = array_map(create_function('$a', 'return DB::qstr($a);'), $categories); $texts = array_filter(preg_split('/[^\\p{L}0-9]/u', mb_strtolower($search))); $total_results = array(); $total_max_score = 0; foreach ($texts as $text) { //for each word $len = mb_strlen($text); if ($len < $token_length) { continue; } //if word is less then token lenght - ignore it $results = array(); $max_score = $len - $token_length + 1; $total_max_score += $len; for ($i = 0; $i <= $len - $token_length; $i++) { $word = mb_substr($text, $i, $token_length); $ret = DB::Execute('SELECT m.tab_id,m.record_id,m.field_id,m.position FROM recordbrowser_words_index w INNER JOIN recordbrowser_words_map m ON w.id=m.word_id WHERE w.word=%s AND m.tab_id IN (' . implode(',', $categories) . ')', array($word)); while ($row = $ret->FetchRow()) { $score = 1; for ($k = 1; $k <= $token_length + 1; $k++) { if (isset($results[$row['tab_id']][$row['record_id']][$row['field_id']][$row['position'] - $k])) { $score += $results[$row['tab_id']][$row['record_id']][$row['field_id']][$row['position'] - $k]; break; } } $results[$row['tab_id']][$row['record_id']][$row['field_id']][$row['position']] = min($max_score, $score); } } foreach ($results as $tab_id => $records) { foreach ($records as $record => $fields) { //get max score for each field... if max score is 50% or more equal save it foreach ($fields as $field => $scores) { $max_score_local = max($scores); if ($max_score_local > $max_score / 2) { $results[$tab_id][$record][$field] = $max_score_local; } else { unset($results[$tab_id][$record][$field]); } } //if some fields was saved if ($results[$tab_id][$record]) { $max = 0; //get max score of all fields where the "word" was found $max_fields = array(); //get field names with maximal score foreach ($results[$tab_id][$record] as $field => $score) { if ($max < $score) { $max = $score; $max_fields = array($field); } elseif ($max == $score) { $max_fields[] = $field; } } $max += $token_length - 1; if (!isset($total_results[$tab_id . '#' . $record])) { $total_results[$tab_id . '#' . $record] = array('score' => 0, 'fields' => array(), 'fields_score' => array(), 'priority' => $tabs_priority[$tab_id]); } $total_results[$tab_id . '#' . $record]['score'] += $max; $total_results[$tab_id . '#' . $record]['fields_score'][] = $max; $total_results[$tab_id . '#' . $record]['fields'][] = $max_fields; } else { unset($results[$tab_id][$record]); } } } unset($results); } if ($total_max_score == 0) { Epesi::alert(__('Displaying only partial results - please enter at least one word of 3 or more letters')); return; } //sort with score... if score is the same sort with qty of fields where the "word" was found uasort($total_results, create_function('$a,$b', 'return $a["score"]>$b["score"]?-1:($a["score"]<$b["score"]?1:($a["priority"]>$b["priority"]?-1:($a["priority"]<$b["priority"]?1:($a["fields"]>$b["fields"]?-1:1))));')); $tabs = DB::GetAssoc('SELECT id,tab FROM recordbrowser_table_properties WHERE search_include>0'); $ret = array(); $cols_cache = array(); $count = 0; foreach ($total_results as $rec => $score) { list($tab_id, $id) = explode('#', $rec, 2); $tab = $tabs[$tab_id]; $record = self::get_record($tab, $id); //get fields names translations if (!isset($cols_cache[$tab])) { $table_rows = self::init($tab); $cols_cache[$tab] = array(); foreach ($table_rows as $col) { $cols_cache[$tab][$col['pkey']] = array('name' => $col['name'], 'id' => $col['id']); } } //get access $has_access = self::get_access($tab, 'view', $record); if (!$has_access) { continue; } //no access at all //if there are fields that should not be visible, remove them from results list and recalculate score foreach ($score['fields'] as $fields_group => $fields) { foreach ($fields as $field_pos => $field_id) { if (isset($cols_cache[$tab][$field_id])) { $field = $cols_cache[$tab][$field_id]['id']; } else { $field = ''; } if (!isset($has_access[$field]) || !$has_access[$field]) { unset($score['fields'][$fields_group][$field_pos]); } } if (empty($score['fields'][$fields_group])) { $score['score'] -= $score['fields_score'][$fields_group]; unset($score['fields'][$fields_group]); unset($score['fields_score'][$fields_group]); } } if (!$score['fields']) { continue; } $fields = array(); foreach ($score['fields'] as $fields_group) { foreach ($fields_group as $field) { $fields[] = _V($cols_cache[$tab][$field]['name']); } } //create link with default label $ret[] = self::create_default_linked_label($tab, $id) . ' <span style="color: red">' . round($score['score'] * 100 / $total_max_score) . '%</span> (' . implode(', ', $fields) . ')'; $count++; if ($count >= $limit) { break; } } return $ret; }
if(!isset($_POST['url']) || !isset($_SERVER['HTTP_X_CLIENT_ID'])) die('alert(\'Invalid request\');'); define('JS_OUTPUT',1); define('EPESI_PROCESS',1); require_once('include.php'); if (epesi_requires_update()) { die ('window.location = "index.php";'); } if(!isset($_SESSION['num_of_clients'])) { Epesi::alert('Session expired, restarting epesi'); Epesi::redirect(); Epesi::send_output(); define('SESSION_EXPIRED',1); //session_commit(); //DBSession::destroy(session_id()); } else { Epesi::process($_POST['url'],isset($_POST['history'])?$_POST['history']:false); } $content = ob_get_contents(); ob_end_clean(); require_once('libs/minify/HTTP/Encoder.php'); $he = new HTTP_Encoder(array('content' => $content)); if (MINIFY_ENCODE) $he->encode();
public function send($file) { if ($this->is_back()) { return $this->go_back($file); } $qf = $this->init_module(Libs_QuickForm::module_name(), null, 'send_fax'); list($providers, $providers_arr) = self::get_providers($file); if (empty($providers)) { $this->go_back($file); Epesi::alert(__('No fax providers installed or configured for this type of file.')); return; } $qf->addElement('header', null, __('Faxing file: %s', array(basename($file)))); $qf->addElement('select', 'provider', __('Provider'), $providers); $qf->addElement('header', null, __('Contact')); $fav_contact = CRM_ContactsCommon::get_contacts(array(':Fav' => true, '!fax' => '')); $fav_contact2 = array(); foreach ($fav_contact as $v) { $fav_contact2[$v['id']] = CRM_ContactsCommon::contact_format_default($v, true); } $rb_contact = $this->init_module(Utils_RecordBrowser_RecordPicker::module_name()); $this->display_module($rb_contact, array('contact', 'dest_contact', array('CRM_FaxCommon', 'rpicker_contact_format'), array('!fax' => ''), array('fax' => true))); $qf->addElement('multiselect', 'dest_contact', '', $fav_contact2); $qf->addElement('static', null, $rb_contact->create_open_link('Add contact')); $qf->addElement('header', null, __('Company')); $fav_company = CRM_ContactsCommon::get_companies(array(':Fav' => true, '!fax' => ''), array('id', 'company_name')); $fav_company2 = array(); foreach ($fav_company as $v) { $fav_company2[$v['id']] = $v['company_name']; } $rb_company = $this->init_module(Utils_RecordBrowser_RecordPicker::module_name()); $this->display_module($rb_company, array('company', 'dest_company', array('CRM_FaxCommon', 'rpicker_company_format'), array('!fax' => ''), array('fax' => true))); $qf->addElement('multiselect', 'dest_company', '', $fav_company2); $qf->addElement('static', null, $rb_company->create_open_link('Add company')); $qf->addElement('header', null, __('Other')); $qf->addElement('text', 'dest_other', __('Other fax numbers (comma separated)')); $qf->addFormRule(array($this, 'check_numbers')); if ($qf->validate()) { $data = $qf->exportValues(); if (!isset($providers_arr[$data['provider']]['send_func'])) { Epesi::alert(__('Invalid fax provider.')); } else { $fax_func = array($data['provider'] . 'Common', $providers_arr[$data['provider']]['send_func']); $numbers = array(); $contacts = Utils_RecordBrowserCommon::get_records('contact', array('id' => $data['dest_contact']), array('fax')); foreach ($contacts as $row) { $numbers[] = $row['fax']; } $companies = Utils_RecordBrowserCommon::get_records('company', array('id' => $data['dest_company']), array('fax')); foreach ($companies as $row) { $numbers[] = $row['fax']; } $numbers += explode(',', $data['dest_other']); $ret = call_user_func($fax_func, $file, $numbers); if ($ret) { return $this->go_back($file); } } } $qf->display(); Base_ActionBarCommon::add('send', __('Send'), $qf->get_submit_form_href()); Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); }
public static function submit_attachment($values, $mode) { static $new_values, $old_password; switch ($mode) { case 'browse': if (isset($values['id']) && isset($values['crypted']) && $values['crypted'] == false) { // store to mark as read. Do not mark it here, because // we won't get red eye in the table view self::$mark_as_read[] = $values['id']; } return $values; case 'index': if($values['crypted']) unset($values['note']); return $values; case 'adding': $values['edited_on'] = time(); return $values; case 'add': case 'edit': if(isset($values['__date'])) $values['edited_on'] = $values['__date']; else $values['edited_on'] = time(); $crypted = 0; $old_pass = ($mode=='edit' && isset($_SESSION['client']['cp'.$values['id']]))?$_SESSION['client']['cp'.$values['id']]:($mode=='add' && isset($values['clone_id']) && isset($_SESSION['client']['cp'.$values['clone_id']])?$_SESSION['client']['cp'.$values['clone_id']]:''); if((is_array($values['crypted']) && isset($values['crypted']['crypted']) && $values['crypted']['crypted']) || (!is_array($values['crypted']) && $values['crypted'])) { if(is_array($values['crypted']) && isset($values['crypted']['note_password'])) { if($values['crypted']['note_password']=='*@#old@#*') $values['crypted']['note_password'] = $old_pass; } $crypted = 1; } if(is_array($values['crypted']) && isset($values['crypted']['note_password']) && $mode=='edit' && $old_pass!=$values['crypted']['note_password']) { //reencrypt old revisions $old_notes = DB::GetAssoc('SELECT hd.edit_id,hd.old_value FROM utils_attachment_edit_history h INNER JOIN utils_attachment_edit_history_data hd ON h.id=hd.edit_id WHERE h.utils_attachment_id=%d AND hd.field="note"', array($values['id'])); foreach($old_notes as $old_id=>$old_note) { if($old_pass!=='') $old_note = Utils_AttachmentCommon::decrypt($old_note,$old_pass); if($old_note===false) continue; if($crypted && $values['crypted']['note_password']) $old_note = Utils_AttachmentCommon::encrypt($old_note,$values['crypted']['note_password']); if($old_note===false) continue; DB::Execute('UPDATE utils_attachment_edit_history_data SET old_value=%s WHERE edit_id=%d AND field="note"',array($old_note,$old_id)); } //file reencryption $old_files = DB::GetCol('SELECT uaf.id as id FROM utils_attachment_file uaf WHERE uaf.attach_id=%d',array($values['id'])); foreach($old_files as $old_id) { $filename = DATA_DIR.'/Utils_Attachment/'.$values['id'].'/'.$old_id; $content = @file_get_contents($filename); if($content===false) continue; if($old_pass!=='') $content = Utils_AttachmentCommon::decrypt($content,$old_pass); if($content===false) continue; if($crypted && $values['crypted']['note_password']) $content = Utils_AttachmentCommon::encrypt($content,$values['crypted']['note_password']); if($content===false) continue; file_put_contents($filename,$content); } } if($crypted) { if(is_array($values['crypted']) && isset($values['crypted']['note_password'])) { $values['note'] = Utils_AttachmentCommon::encrypt($values['note'],$values['crypted']['note_password']); $values['note_password']=$values['crypted']['note_password']; } $values['crypted'] = 1; } else { $values['crypted'] = 0; } $new_values = $values; break; case 'cloning': $values['clone_id']=$values['id']; break; case 'added': if(isset($values['local'])) DB::Execute('INSERT INTO utils_attachment_local(attachment,local,func,args) VALUES(%d,%s,%s,%s)',array($values['id'],$values['local'],$values['func'],$values['args'])); $new_values = $values; break; case 'edit_changes': if(isset($values['note']) && isset($values['crypted']) && $new_values['crypted']!=$values['crypted']) { if($new_values['crypted'] && isset($new_values['note_password'])) { $values['note'] = Utils_AttachmentCommon::encrypt($values['note'],$new_values['note_password']); } elseif(!$new_values['crypted'] && isset($_SESSION['client']['cp'.$new_values['id']])) { $values['note'] = Utils_AttachmentCommon::decrypt($values['note'],$_SESSION['client']['cp'.$new_values['id']]); unset($_SESSION['client']['cp'.$new_values['id']]); } } elseif(isset($new_values['note_password']) && isset($old_password) && $new_values['note_password']!=$old_password) { $values['note'] = Utils_AttachmentCommon::decrypt($values['note'],$old_password); $values['note'] = Utils_AttachmentCommon::encrypt($values['note'],$new_values['note_password']); } break; case 'view': $ret = self::get_access($values['id']); if(!$ret) print(__('Access denied')); return $ret; case 'display': if(DB::GetOne('SELECT 1 FROM utils_attachment_file WHERE attach_id=%d',array($values['id']))) { $ret = array(); $ret['new'] = array(); $ret['new']['crm_filter'] = '<a '.Utils_TooltipCommon::open_tag_attrs(__('File history')).' '.Module::create_href(array('file_history'=>1)).'>F</a>'; if (isset($_REQUEST['file_history']) && (!$values['crypted'] || isset($_SESSION['client']['cp'.$values['id']]))) Base_BoxCommon::push_module('Utils_Attachment','file_history',array($values)); // CRM_FiltersCommon::set_profile('c'.$values['id']); return $ret; } break; case 'delete': if($values['crypted'] && !isset($_SESSION['client']['cp'.$values['id']])) { Epesi::alert(__('Cannot delete encrypted note')); return false; } $count_locals = DB::GetOne('SELECT count(DISTINCT local) FROM utils_attachment_local WHERE attachment=%d',array($values['id'])); if($count_locals>1) { $is_local = false; if(isset($_SESSION['client']['utils_attachment_group'])) $is_local = DB::GetOne('SELECT 1 FROM utils_attachment_local WHERE attachment=%d AND local=%s',array($values['id'],$_SESSION['client']['utils_attachment_group'])); if($is_local) { DB::Execute('DELETE FROM utils_attachment_local WHERE attachment=%d AND local=%s',array($values['id'],$_SESSION['client']['utils_attachment_group'])); self::new_watchdog_event($_SESSION['client']['utils_attachment_group'], '-', $values['id']); } else Epesi::alert(__('This note is attached to multiple records - please go to record and delete note there.')); location(array()); return false; } location(array()); return true; } switch($mode) { case 'edit': case 'added': if(isset($values['note_password'])) { $old_password = isset($_SESSION['client']['cp' . $values['id']]) ? $_SESSION['client']['cp' . $values['id']] : ''; $_SESSION['client']['cp'.$values['id']] = $values['note_password']; } $note_id = $values['id']; $files_dir = self::Instance()->get_data_dir().$note_id; if(isset($values['delete_files'])) $deleted_files = array_filter(explode(';',$values['delete_files'])); else $deleted_files = array(); foreach ($deleted_files as $k=>$v) $deleted_files[$k] = intVal($v); if($deleted_files) $deleted_files = array_combine($deleted_files,$deleted_files); if($mode=='added' && isset($values['clone_id'])) { //on cloning $locals = DB::Execute('SELECT local,func,args FROM utils_attachment_local WHERE attachment=%d',array($values['clone_id'])); while($local = $locals->FetchRow()) DB::Execute('INSERT INTO utils_attachment_local(attachment,local,func,args) VALUES(%d,%s,%s,%s)',array($note_id,$local['local'],$local['func'],$local['args'])); $clone_files = DB::GetAll('SELECT id,original,created_by,created_on FROM utils_attachment_file uaf WHERE uaf.attach_id=%d AND uaf.deleted=0', array($values['clone_id'])); foreach($clone_files as $file) { $cf = self::Instance()->get_data_dir().$values['clone_id'].'/'.$file['id']; if(!file_exists($cf)) continue; if(!file_exists($files_dir)) mkdir($files_dir,0777,true); DB::Execute('INSERT INTO utils_attachment_file (attach_id,deleted,original,created_by,created_on) VALUES(%d,0,%s,%d,%T)',array($note_id,$file['original'],$file['created_by'],$file['created_on'])); $new_file_id = DB::Insert_ID('utils_attachment_file','id'); if(isset($deleted_files[$file['id']])) $deleted_files[$file['id']] = $new_file_id; $cf2 = $files_dir.'/'.$new_file_id; copy($cf,$cf2); if(isset($_SESSION['client']['cp'.$values['clone_id']]) && $_SESSION['client']['cp'.$values['clone_id']]) file_put_contents($cf2,Utils_AttachmentCommon::decrypt(file_get_contents($cf2),$_SESSION['client']['cp'.$values['clone_id']])); if($values['crypted']) file_put_contents($cf2,Utils_AttachmentCommon::encrypt(file_get_contents($cf2),$values['note_password'])); } } $current_files = DB::GetAssoc('SELECT id, id FROM utils_attachment_file uaf WHERE uaf.attach_id=%d AND uaf.deleted=0', array($note_id)); $remaining_files = $current_files; foreach ($deleted_files as $k=>$v) { if (!isset($remaining_files[$v])) unset($deleted_files[$k]); else unset($remaining_files[$v]); } foreach ($deleted_files as $v) DB::Execute('UPDATE utils_attachment_file SET deleted=1 WHERE id=%d', array($v)); if(isset($values['clipboard_files'])) { $clipboard_files = array_filter(explode(';',$values['clipboard_files'])); foreach ($clipboard_files as $cf_id) { $cf = DB::GetOne('SELECT filename FROM utils_attachment_clipboard WHERE id=%d', array($cf_id)); if($values['crypted']) file_put_contents($cf,Utils_AttachmentCommon::encrypt(file_get_contents($cf),$values['note_password'])); Utils_AttachmentCommon::add_file($note_id, Acl::get_user(), __('clipboard').'.png', $cf); } } $files = isset($_SESSION['client']['utils_attachment'][CID]['files'])?$_SESSION['client']['utils_attachment'][CID]['files']:array(); $_SESSION['client']['utils_attachment'][CID]['files'] = array(); foreach ($files as $f) { $file_path = $f['path']; $file_name = $f['name']; if($values['crypted']) file_put_contents($file_path,Utils_AttachmentCommon::encrypt(file_get_contents($file_path),$values['note_password'])); Utils_AttachmentCommon::add_file($note_id, Acl::get_user(), $file_name, $file_path); } $locals = DB::GetCol('SELECT local FROM utils_attachment_local WHERE attachment=%d',array($note_id)); foreach ($locals as $local) { $param = explode('/', $local); if (count($param) == 2 && preg_match('/^[1-9][0-9]*$/', $param[1])) { $subscribers = Utils_WatchdogCommon::get_subscribers($param[0], $param[1]); foreach ($subscribers as $user_id) { Utils_WatchdogCommon::user_subscribe($user_id, 'utils_attachment', $note_id); } } } break; } return $values; }
public static function set_id($id) { $c = DB::GetRow('SELECT max(page_id) as max,min(page_id) as min FROM history WHERE session_name=%s AND client_id=%d', array(self::session_id(), CID)); if ($id < 1 || $id < $c['min']) { $id = $c['min']; } elseif ($id > $c['max']) { $id = $c['max']; } $_SESSION['client']['__history_id__'] = intval($id); $data = DB::GetOne('SELECT data FROM history WHERE session_name=%s AND client_id=%d AND page_id=%d', array(self::session_id(), CID, $_SESSION['client']['__history_id__'] - 1)); if ($data === false) { Epesi::alert('History expired.'); return; } // $data = DB::BlobDecode($data); if (GZIP_HISTORY && function_exists('gzuncompress')) { $data = gzuncompress($data); } $_SESSION['client']['__module_vars__'] = unserialize($data); }
} define('JS_OUTPUT', 1); define('EPESI_PROCESS', 1); require_once 'include.php'; if (epesi_requires_update()) { die('window.location = "index.php";'); } if (!isset($_SESSION['num_of_clients'])) { Epesi::alert('Session expired, restarting Epesi'); Epesi::redirect(); Epesi::send_output(); define('SESSION_EXPIRED', 1); //session_commit(); //DBSession::destroy(session_id()); } elseif ((!isset($_POST['history']) || !is_numeric($_POST['history']) || $_POST['history'] > 0) && !isset($_SESSION['client']['__history_id__'])) { Epesi::alert('Too many Epesi tabs open - session expired, restarting Epesi'); Epesi::redirect(); Epesi::send_output(); define('SESSION_EXPIRED', 1); //session_commit(); DBSession::destroy_client(session_id(), CID); } else { Epesi::process($_POST['url'], isset($_POST['history']) ? $_POST['history'] : false); } $content = ob_get_contents(); ob_end_clean(); require_once 'libs/minify/HTTP/Encoder.php'; $he = new HTTP_Encoder(array('content' => $content)); if (MINIFY_ENCODE) { $he->encode(); }