public static function user_suggestbox($str) { $wild = DB::Concat(DB::qstr('%'), DB::qstr($str), DB::qstr('%')); $contacts_raw = CRM_ContactsCommon::get_contacts(array('!login' => '', '(~"first_name' => $wild, '|~"last_name' => $wild)); $contacts = array(); $contacts_login_ids = array(); foreach ($contacts_raw as $c) { $contacts_login_ids[] = $c['login']; $contacts[$c['login']] = $c; } if (!empty($contacts_login_ids)) { $qry_ids = ' OR id IN (' . implode(',', $contacts_login_ids) . ')'; } else { $qry_ids = ''; } $ret = DB::SelectLimit('SELECT id, active FROM user_login WHERE login ' . DB::like() . ' ' . $wild . $qry_ids . ' ORDER BY active DESC', 10); $result = array(); while ($row = $ret->FetchRow()) { $result[$row['id']] = self::user_label($row['id']); if (!$row['active']) { $result[$row['id']] .= ' (' . __('Inactive') . ')'; } } asort($result); return $result; }
public static function set() { if (self::$action) { return; } if (!isset($_SESSION['client']['__history_id__'])) { $_SESSION['client']['__history_id__'] = 0; } $data = serialize($_SESSION['client']['__module_vars__']); if (GZIP_HISTORY && function_exists('gzcompress')) { $data = gzcompress($data); } if (DB::is_postgresql()) { $data = '\'' . DB::BlobEncode($data) . '\''; } else { $data = DB::qstr($data); } DB::StartTrans(); DB::Replace('history', array('data' => $data, 'page_id' => $_SESSION['client']['__history_id__'], 'session_name' => DB::qstr(self::session_id()), 'client_id' => CID), array('session_name', 'page_id')); $_SESSION['client']['__history_id__']++; $ret = DB::Execute('SELECT page_id FROM history WHERE session_name=%s AND (page_id>=%d OR page_id<%d) AND client_id=%d', array(self::session_id(), $_SESSION['client']['__history_id__'], $_SESSION['client']['__history_id__'] - 20, CID)); while ($row = $ret->FetchRow()) { DB::Execute('DELETE FROM history WHERE session_name=%s AND page_id=%d AND client_id=%d', array(self::session_id(), $row['page_id'], CID)); } DB::CompleteTrans(); }
public static function createLikeSQL($value, $fieldArray) { if (is_array($fieldArray)) { $count = count($fieldArray); $sqText = ""; $int = 0; foreach ($fieldArray as $field) { $sqlText .= '(f_' . $field . ' ' . DB::like() . ' ' . DB::Concat(DB::qstr('%'), DB::qstr($value), DB::qstr('%')) . ') OR '; } return $sqlText; } else { return false; } }
public function applet($conf, &$opts) { //available applet options: toggle,href,title,go,go_function,go_arguments,go_contruct_arguments $opts['go'] = false; // enable/disable full screen $opts['title'] = $conf['title']; // initialize the recordset $rb = $this->init_module('Utils/RecordBrowser', 'contact', 'contact'); $me = CRM_ContactsCommon::get_my_record(); // $conds - parameters for the applet // 1st - table field names, width, truncate // 2nd - criteria (filter) // 3rd - sorting // 4th - function to return tooltip // 5th - limit how many records are returned, null = no limit // 6th - Actions icons - default are view + info (with tooltip) // 1st - table field names $cols = array(array('field' => 'last_name', 'width' => 15), array('field' => 'first_name', 'width' => 15), array('field' => 'birth_date', 'width' => 15)); // 2nd - criteria (filter) // TO DO - filter date - today through today+2 weeks $dates = array(); for ($i = 0; $i < $conf['no_of_days']; $i++) { $dates[] = DB::Concat(DB::qstr('%'), DB::qstr(date('-m-d', strtotime(Base_RegionalSettingsCommon::time2reg(strtotime('+' . $i . ' days'), false, true, true, false))))); } if (isset($conf['cont_type']) && $conf['cont_type'] == 'f') { $crits = array(':Fav' => true, '"~birth_date' => $dates); } else { $crits = array('"~birth_date' => $dates); } // 3rd - sorting $sorting = array('last_name' => 'ASC'); // 4th - function to return tooltip $tooltip = 'test'; // 5th - limit how many records are returned, null = no limit $limit = null; // 6th - Actions icons - default are view + info (with tooltip) $conds = array($cols, $crits, $sorting, $tooltip, $limit, $conf, &$opts); // initialize miniview print __('Birthdays upcoming in the next: %d days.', array($conf['no_of_days'])); $this->display_module($rb, $conds, 'mini_view'); }
function look_contact($addr) { global $E_SESSION; $ret = array(); $fields = DB::GetCol('SELECT field FROM contact_field WHERE active=1 AND type=\'text\' AND field LIKE \'%mail%\' ORDER BY field'); foreach ($fields as &$f) { $f = 'c.f_' . preg_replace('/[^a-z0-9]/', '_', strtolower($f)); } $contact = DB::GetCol('SELECT c.id FROM contact_data_1 c LEFT JOIN rc_multiple_emails_data_1 m ON (m.f_record_id=c.id AND m.f_record_type=%s) WHERE c.active=1 AND (' . implode('=' . DB::qstr($addr) . ' OR ', $fields) . '=' . DB::qstr($addr) . ' OR m.f_email=%s) AND (c.f_permission<%s OR c.created_by=%d)', array('contact', $addr, '2', $E_SESSION['user'])); foreach ($contact as $contact_id) { $ret[] = 'P:' . $contact_id; } $fields = DB::GetCol('SELECT field FROM company_field WHERE active=1 AND type=\'text\' AND field LIKE \'%mail%\' ORDER BY field'); foreach ($fields as &$f) { $f = 'c.f_' . preg_replace('/[^a-z0-9]/', '_', strtolower($f)); } $company = DB::GetCol('SELECT c.id FROM company_data_1 c LEFT JOIN rc_multiple_emails_data_1 m ON (m.f_record_id=c.id AND m.f_record_type=%s) WHERE c.active=1 AND (' . implode('=' . DB::qstr($addr) . ' OR ', $fields) . '=' . DB::qstr($addr) . ' OR m.f_email=%s) AND (c.f_permission<%s OR c.created_by=%d)', array('company', $addr, 2, $E_SESSION['user'])); foreach ($company as $company_id) { $ret[] = 'C:' . $company_id; } return $ret; }
public static function user_search($search = null) { $myid = Base_AclCommon::get_user(); if (Base_User_SettingsCommon::get('Apps_Shoutbox', 'enable_im')) { $adm = Base_User_SettingsCommon::get_admin('Apps_Shoutbox', 'enable_im'); if (ModuleManager::is_installed('CRM_Contacts') >= 0) { $emps = DB::GetAssoc('SELECT l.id,' . DB::ifelse('cd.f_last_name!=\'\'', DB::concat('cd.f_last_name', DB::qstr(' '), 'cd.f_first_name'), 'l.login') . ' as name FROM user_login l LEFT JOIN contact_data_1 cd ON (cd.f_login=l.id AND cd.active=1) LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is ' . ($adm ? '' : 'not ') . 'null) AND (cd.f_first_name ' . DB::like() . ' ' . DB::concat(DB::qstr("%%"), "%s", DB::qstr("%%")) . ' OR cd.f_last_name ' . DB::like() . ' ' . DB::concat(DB::qstr("%%"), "%s", DB::qstr("%%")) . ') ORDER BY name', array($myid, serialize(1), $search, $search)); } else { $emps = DB::GetAssoc('SELECT l.id,l.login FROM user_login l LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is ' . ($adm ? '' : 'not ') . 'null) AND l.login ' . DB::like() . ' ' . DB::concat(DB::qstr("%%"), "%s", DB::qstr("%%")) . ' ORDER BY l.login', array($myid, serialize(1), $search)); } } else { $emps = array(); } if (ModuleManager::is_installed('Tools_WhoIsOnline') >= 0) { $online = Tools_WhoIsOnlineCommon::get_ids(); foreach ($online as $id) { if (isset($emps[$id])) { $emps[$id] = '* ' . $emps[$id]; } } } return $emps; }
/** * Create an SQL string for a given table and hash * * @param $table string * @param $isNew boolean | 'auto' * @param $hash array * @param $primaryKeys array * * @return unknown_type */ public static function CreateSQLFromHash($table, $isNew, $hashTable, $primaryKeys = array()) { if ($isNew === true) { // If isNew is true $query = "INSERT INTO `$table` "; $q1 = ''; $q2 = ''; foreach ($hashTable as $key => $val) { $q1 .= ($q1 == '') ? $key : ', ' . $key; $q2 .= (($q2 == '') ? '' : ', ') . DB::qstr($val); } return "$query \n($q1) \nVALUES \n($q2)"; } elseif ($isNew === false) { $query = "UPDATE `$table` SET "; $q1 = ''; foreach ($hashTable as $key => $val) { $q1 .= (($q1 == '') ? '' : ", \n") . "`$key` = " . DB::qstr($val); } $q2 = ''; foreach ($primaryKeys as $pKey => $pVal) { $q2 .= ($q2 == '') ? "WHERE `$pKey` = " . DB::qstr($pVal) : " AND `$pKey` = " . DB::qstr($pVal); } return "$query \n$q1 \n$q2"; } elseif (strtolower($isNew) == 'auto') { $query = "INSERT INTO `$table`"; $q1 = ''; $q2 = ''; $q3 = ''; foreach (array_merge($hashTable, $primaryKeys) as $key => $val) { $q1 .= (($q1 == '') ? '' : ", \n") . "`$key`"; $q2 .= (($q2 == '') ? '' : ", \n") . DB::qstr($val); } //$query .= "\n($q1) \nVALUES \n($q2) " . "ON DUPLICATE KEY UPDATE "; foreach ($hashTable as $key => $val) { $q3 .= (($q3 == '') ? '' : ", \n") . "`$key` = " . DB::qstr($val); } return "$query \n($q1) \nVALUES \n($q2) \nON DUPLICATE KEY UPDATE \n$q3"; } else { return false; // What do I do?!? } }
public static function autoselect_company_suggestbox($str, $crits, $format_callback) { $str = explode(' ', trim($str)); foreach ($str as $k => $v) { if ($v) { $v = DB::Concat(DB::qstr('%'), DB::qstr($v), DB::qstr('%')); $crits = Utils_RecordBrowserCommon::merge_crits($crits, array('~"company_name' => $v)); } } $recs = Utils_RecordBrowserCommon::get_records('company', $crits, array(), array('company_name' => 'ASC'), 10); $ret = array(); foreach ($recs as $v) { $ret[$v['id']] = call_user_func($format_callback, $v, true); } return $ret; }
public function chat($big = false, $uid = null) { $to =& $this->get_module_variable('to', "all"); eval_js('shoutbox_uid="' . $to . '"'); if (Base_AclCommon::is_user()) { //initialize HTML_QuickForm $qf = $this->init_module(Libs_QuickForm::module_name()); /* $myid = Base_AclCommon::get_user(); if(Base_User_SettingsCommon::get('Apps_Shoutbox','enable_im')) { $adm = Base_User_SettingsCommon::get_admin('Apps_Shoutbox','enable_im'); if(ModuleManager::is_installed('CRM_Contacts')>=0) { $emps = DB::GetAssoc('SELECT l.id,IF(cd.f_last_name!=\'\',CONCAT(cd.f_last_name,\' \',cd.f_first_name,\' (\',l.login,\')\'),l.login) as name FROM user_login l LEFT JOIN contact_data_1 cd ON (cd.f_login=l.id AND cd.active=1) LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is '.($adm?'':'not ').'null) ORDER BY name',array($myid,serialize(1))); } else $emps = DB::GetAssoc('SELECT l.id,l.login FROM user_login l LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is '.($adm?'':'not ').'null) ORDER BY l.login',array($myid,serialize(1))); } else $emps = array(); if(ModuleManager::is_installed('Tools_WhoIsOnline')>=0) { $online = Tools_WhoIsOnlineCommon::get_ids(); foreach($online as $id) { if(isset($emps[$id])) $emps[$id] = '* '.$emps[$id] ; } } $qf->addElement('select','to',__('To'),array('all'=>'['.__('All').']')+$emps,array('id'=>'shoutbox_to'.($big?'_big':''),'onChange'=>'shoutbox_uid=this.value;shoutbox_refresh'.($big?'_big':'').'()'));*/ $myid = Base_AclCommon::get_user(); if (Base_User_SettingsCommon::get('Apps_Shoutbox', 'enable_im') && ModuleManager::is_installed('Tools_WhoIsOnline') >= 0) { $adm = Base_User_SettingsCommon::get_admin('Apps_Shoutbox', 'enable_im'); $online = Tools_WhoIsOnlineCommon::get_ids(); if ($online) { if (ModuleManager::is_installed('CRM_Contacts') >= 0) { $emps = DB::GetAssoc('SELECT l.id,' . DB::Concat(DB::qstr("* "), DB::ifelse('cd.f_last_name!=\'\'', DB::concat('cd.f_last_name', DB::qstr(' '), 'cd.f_first_name', DB::qstr(' ('), 'l.login', DB::qstr(')')), 'l.login')) . ' as name FROM user_login l LEFT JOIN contact_data_1 cd ON (cd.f_login=l.id AND cd.active=1) LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is ' . ($adm ? '' : 'not ') . 'null) AND l.id IN (' . implode(',', $online) . ') ORDER BY name', array($myid, serialize(1))); } else { $emps = DB::GetAssoc('SELECT l.id,' . DB::Concat(DB::qstr("* "), 'l.login') . ' FROM user_login l LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is ' . ($adm ? '' : 'not ') . 'null) AND l.id IN (' . implode(',', $online) . ') ORDER BY l.login', array($myid, serialize(1))); } } else { $emps = array(); } } else { $emps = array(); } $e = $qf->addElement('autoselect', 'shoutbox_to', __('To'), array('all' => '[' . __('All') . ']') + $emps, array(array($this->get_type() . 'Common', 'user_search'), array()), array($this->get_type() . 'Common', 'user_format')); $e->setAttribute('id', 'shoutbox_to' . ($big ? '_big' : '')); $e->setAttribute('onChange', 'shoutbox_uid=this.value;shoutbox_refresh' . ($big ? '_big' : '') . '()'); if (!Base_User_SettingsCommon::get('Apps_Shoutbox', 'enable_im')) { $qf->freeze(array('shoutbox_to')); } //create text box $qf->addElement($big ? 'textarea' : 'textarea', 'post', __('Message'), 'class="border_radius_6px" id="shoutbox_text' . ($big ? '_big' : '') . '"'); $qf->addRule('post', __('Field required'), 'required'); //create submit button $qf->addElement('submit', 'submit_button', __('Send'), 'id="shoutbox_button' . ($big ? '_big' : '') . '"'); //add it $qf->setRequiredNote(null); $qf->setDefaults(array('shoutbox_to' => $to)); $theme = $this->init_module(Base_Theme::module_name()); $qf->assign_theme('form', $theme); //confirm when sending messages to all eval_js("jq('#shoutbox_button, #shoutbox_button_big').click(function() {\n \t\t\t\t\tvar submit = true;\n\t\t \t\t\tif (jq('#shoutbox_to').val() == 'all' && !confirm('" . __('Send message to all?') . "')) {\n \t\t\t\t\tsubmit = false;\n \t\t\t\t\t}\n\t\t \n\t\t \t\t\treturn submit;\t\t \t\t\t\n\t\t\t\t\t});"); //if submited if ($qf->validate()) { //get post group $msg = $qf->exportValue('post'); $to = $qf->exportValue('shoutbox_to'); //get msg from post group $msg = Utils_BBCodeCommon::optimize($msg); //get logged user id $user_id = Base_AclCommon::get_user(); //clear text box and focus it eval_js('$(\'shoutbox_text' . ($big ? '_big' : '') . '\').value=\'\';focus_by_id(\'shoutbox_text' . ($big ? '_big' : '') . '\');shoutbox_uid="' . $to . '"'); //insert to db DB::Execute('INSERT INTO apps_shoutbox_messages(message,base_user_login_id,to_user_login_id) VALUES(%s,%d,%d)', array(htmlspecialchars($msg, ENT_QUOTES, 'UTF-8'), $user_id, is_numeric($to) ? $to : null)); } } else { print __('Please log in to post message') . '<br>'; return; } $theme->assign('board', '<div id=\'shoutbox_board' . ($big ? '_big' : '') . '\'></div>'); $theme->assign('header', __('Shoutbox')); $theme->display('chat_form' . ($big ? '_big' : '')); //if shoutbox is diplayed, call myFunctions->refresh from refresh.php file every 5s eval_js_once('shoutbox_refresh' . ($big ? '_big' : '') . ' = function(){if(!$(\'shoutbox_board' . ($big ? '_big' : '') . '\')) return;' . 'new Ajax.Updater(\'shoutbox_board' . ($big ? '_big' : '') . '\',\'modules/Apps/Shoutbox/refresh.php\',{method:\'get\', parameters: { uid: shoutbox_uid }});' . '};setInterval(\'shoutbox_refresh' . ($big ? '_big' : '') . '()\',' . ($big ? '10000' : '30000') . ')'); eval_js('shoutbox_refresh' . ($big ? '_big' : '') . '()'); }
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 .= ' '; $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); }
public static function automulti_suggestbox($str, $tab, $crits, $f_callback, $params) { $param = explode(';', $params); $ref = explode('::', $param[0]); $words = array_filter(explode(' ', $str)); $words_db = $words; self::$automulti_order_tabs = array(); foreach ($words_db as &$w) { if (mb_strlen($w) >= 3) { self::$automulti_order_tabs[] = preg_quote($w, '/'); } $w = "%{$w}%"; } self::$automulti_order_tabs = '/(' . implode('|', self::$automulti_order_tabs) . ')/i'; $tabs = $ref[0]; if ($tabs == '__RECORDSETS__') { $tabs = DB::GetAssoc('SELECT tab,caption FROM recordbrowser_table_properties'); } else { $tabs = explode(',', $tabs); foreach ($tabs as &$t) { $t = DB::qstr($t); } $tabs = DB::GetAssoc('SELECT tab,caption FROM recordbrowser_table_properties WHERE tab IN (' . implode(',', $tabs) . ')'); } $single_tab = count($tabs) == 1; uasort($tabs, array('Utils_RecordBrowserCommon', 'automulti_order_by')); $ret = array(); foreach ($tabs as $t => $caption) { if (!empty($crits) && !$single_tab && !isset($crits[$t])) { continue; } $access = self::get_access($t, 'selection', null, true); if ($access === false) { continue; } if ($access !== true && is_array($access)) { if ($single_tab) { $crits = self::merge_crits($crits, $access); } elseif (isset($crits[$t]) && is_array($crits[$t]) && $crits[$t]) { $crits[$t] = self::merge_crits($crits[$t], $access); } else { $crits[$t] = $access; } } $fields = array_filter(explode('|', $ref[1])); if (!$fields) { $fields = DB::GetCol("SELECT field FROM {$t}_field WHERE active=1 AND visible=1 AND (type NOT IN ('calculated','page_split','hidden') OR (type='calculated' AND param is not null AND param!=''))"); } $words_db_tmp = $words_db; $words_tmp = $words; foreach ($words_tmp as $pos => $word) { $expr = '/' . preg_quote($word, '/') . '/i'; if (preg_match($expr, $caption) || preg_match($expr, _V($caption))) { unset($words_db_tmp[$pos]); unset($words_tmp[$pos]); } } $str_db = '%' . implode(' ', $words_tmp) . '%'; if (empty($f_callback) || !is_callable($f_callback)) { $f_callback = array('Utils_RecordBrowserCommon', 'autoselect_label'); } $crits2A = array(); $crits2B = array(); $op = '('; foreach ($fields as $f) { $crits2A[$op . '~' . self::get_field_id($f)] = $str_db; $crits2B[$op . '~' . self::get_field_id($f)] = $words_db_tmp; $op = '|'; } $crits3A = self::merge_crits($single_tab ? $crits : (isset($crits[$t]) ? $crits[$t] : array()), $crits2A); $crits3B = self::merge_crits($single_tab ? $crits : (isset($crits[$t]) ? $crits[$t] : array()), $crits2B); $records = self::get_records($t, $crits3A, array(), array(), 10); foreach ($records as $r) { if (!self::get_access($t, 'view', $r)) { continue; } $ret[($single_tab ? '' : $t . '/') . $r['id']] = call_user_func($f_callback, $t . '/' . $r['id'], array($tab, $crits3A, $f_callback, $params)); } $records = self::get_records($t, $crits3B, array(), array(), 10); foreach ($records as $r) { if (isset($ret[($single_tab ? '' : $t . '/') . $r['id']]) || !self::get_access($t, 'view', $r)) { continue; } $ret[($single_tab ? '' : $t . '/') . $r['id']] = call_user_func($f_callback, $t . '/' . $r['id'], array($tab, $crits3B, $f_callback, $params)); } if (count($ret) >= 10) { break; } } return $ret; }
function GetTripDetail($tripId) { //----------------------------------------- // selected trip $trip = new trip(); $trip->retrieve($tripId); // get all waypoints for this trip $waypoint = new waypoint(); $waypoints = $waypoint->getAllObjectsArray('tripid = ' . DB::qstr($tripId), null, 'objid'); /* $wpdistance = ''; $totaldistance = 0; $wptypical = ''; $totaltypical = 0; $wpconsumption = ''; $totalconsumption = 0; $wpaverage = ''; $wpdrivetime = ''; $totaldrivetime = 0; $wpchargetime = ''; $totalchargetime = 0; $startdrivetime = $trip->att('theoreticalstarttime'); $wpchargeneeded = 0; $wpchargestarted = 0; $wparrivaltime = ''; $wpdeparturetime = ''; $wpchargestart = 0; */ // declare and initialize all variables $wpnbr = -1; $statusid = WaypointStatus::STATUS_LEFT; // build the waypoints array $dwp = null; //foreach ($waypoints as &$wp) { for ($i = 0; $i < count($waypoints); $i++) { // get the needed waypoints $wp = $waypoints[array_keys($waypoints)[$i]]; if ($i > 0) { $prevwp = $waypoints[array_keys($waypoints)[$i - 1]]; } if ($i < count($waypoints) - 1) { $nextwp = $waypoints[array_keys($waypoints)[$i + 1]]; } // get the active waypoint (etappe) and status if ($statusid == WaypointStatus::STATUS_LEFT) { $wpnbr++; $statusid = $wp['statusid']; } // calculate all values // first position : O overview (effective), T theoretical, F formatting // second position : A distance, T Typical, V consumption G Average // third position : 1 waypoint-value, 2 sum CalculateDistance($i, $wp, $prevwp, $oa1, $ta1, $oa2, $ta2, $ot1, $tt1, $ot2, $tt2, $ov1, $tv1, $ov2, $tv2, $og1, $tg1, $og2, $tg2, $fa1, $fa2, $ft1, $ft2, $fv1, $fv2, $fg1, $fg2); $oa1 = format($oa1, 1); $foa2 = format($oa2, 1); $ta1 = format($ta1, 1); $fta2 = format($ta2, 1); $ot1 = format($ot1, 0); $fot2 = format($ot2, 0); $tt1 = format($tt1, 0); $ftt2 = format($tt2, 0); $ov1 = format($ov1, 1); $fov2 = format($ov2, 1); $tv1 = format($tv1, 1); $ftv2 = format($tv2, 1); $og1 = format($og1, 0); $fog2 = format($og2, 0); $tg1 = format($tg1, 0); $ftg2 = format($tg2, 0); CalculateTimes($trip, $i, $wp, $prevwp, $nextwp, $or1, $tr1, $or2, $tr2, $ol1, $tl1, $ol2, $tl2, $ocn, $tcn, $oat, $tat, $ovt, $tvt, $fr1, $fr2, $fl1, $fl2, $fcn, $fat, $fvt); // build the waypoint output result $dwp[] = array('id' => $wp['objid'], 'location' => '', 'name' => $wp['destination'], 'statusid' => $wp['statusid'], 'overview' => array('distance' => $oa1, 'totaldistance' => $foa2, 'typical' => $ot1, 'totaltypical' => $fot2, 'consumption' => $ov1, 'totalconsumption' => $fov2, 'average' => $og1, 'totalaverage' => $fog2, 'drivetime' => $or1, 'totaldrivetime' => $or2, 'chargetime' => $ol1, 'totalchargetime' => $ol2, 'chargeneeded' => $ocn, 'arrivaltime' => $oat, 'departuretime' => $ovt), 'theoretical' => array('distance' => $ta1, 'totaldistance' => $fta2, 'typical' => $tt1, 'totaltypical' => $ftt2, 'consumption' => $tv1, 'totalconsumption' => $ftv2, 'average' => $tg1, 'totalaverage' => $ftg2, 'drivetime' => $tr1, 'totaldrivetime' => $tr2, 'chargetime' => $tl1, 'totalchargetime' => $tl2, 'chargeneeded' => $tcn, 'arrivaltime' => $tat, 'departuretime' => $tvt), 'formating' => array('distance' => $fa1, 'totaldistance' => $fa2, 'typical' => $ft1, 'totaltypical' => $ft2, 'consumption' => $fv1, 'totalconsumption' => $fv2, 'average' => $fg1, 'totalaverage' => $fg2, 'drivetime' => $tr1, 'totaldrivetime' => $tr2, 'chargetime' => $tl1, 'totalchargetime' => $tl2, 'chargeneeded' => $tcn, 'arrivaltime' => $tat, 'departuretime' => $tvt)); //$wpchargestarted = $wpchargeneeded; } // final result $d = array('id' => $tripId, 'desc' => $trip->att('name'), 'statusid' => $statusid, 'etape' => $wpnbr, 'waypoints' => $dwp); return array("key" => "trip", "data" => $d); //return $d; }
function GetTripDetail($tripId) { //----------------------------------------- // selected trip $trip = new trip(); $trip->retrieve($tripId); $waypoint = new waypoint(); $waypoints = $waypoint->getAllObjectsArray('tripid = ' . DB::qstr($tripId), null, 'objid'); // make the result array $wpnbr = -1; $statusid = 4; $wpdistance = ''; $totaldistance = 0; $wptypical = ''; $totaltypical = 0; $wpconsumption = ''; $totalconsumption = 0; $wpaverage = ''; $wpdrivetime = ''; $totaldrivetime = 0; $wpchargetime = ''; $totalchargetime = 0; $startdrivetime = $trip->att('theoreticalstarttime'); $wpchargeneeded = 0; $wpchargestarted = 0; $wparrivaltime = ''; $wpdeparturetime = ''; $wpchargestart = 0; // build the waypoints array $dwp = null; //foreach ($waypoints as &$wp) { for ($i = 0; $i < count($waypoints); $i++) { $wp = $waypoints[array_keys($waypoints)[$i]]; //var_dump($wp); exit(); if ($statusid == 4) { $wpnbr++; $statusid = $wp['statusid']; } if ($i == 0) { // first waypoint initialize counters if ($wp['statusid'] < 4) { $startdrivetime = $trip->att('date'); $wpchargeneeded = $wp['theoreticalchargeneeded']; } else { $startdrivetime = $wp['departuretime']; $wpchargeneeded = $wp['departuretypical']; } $wpdeparturetime = date('H:i', $startdrivetime); $wpchargestarted = $wpchargeneeded; } else { // make running totals if ($wp['statusid'] == 0) { $wpdistance = $wp['theoreticaldistance']; $wptypical = $wp['theoreticaltypical']; $wpconsumption = $wp['theoreticalconsumption']; $wparrivaltime = $startdrivetime + $wp['theoreticaldrivetime'] * 60; $wpchargestart = $wpchargestarted - $wp['theoreticaltypical']; } else { $wpdistance = $wp['arrivaldistance']; $wptypical = $wpchargestarted - $wp['arrivaltypical']; $wpconsumption = $wp['arrivalconsumption']; $wparrivaltime = $wp['arrivaltime']; $wpchargestart = intval($wp['arrivaltypical']); } $totaldistance += $wpdistance; $totaltypical += $wptypical; $totalconsumption += $wpconsumption; $startdrivetime = $wparrivaltime; if ($wpdistance != 0) { $wpaverage = round($wpconsumption * 1000 / $wpdistance, 0); } else { $wpaverage = ''; } if ($wp['statusid'] < 3) { //$startdrivetime = $wparrivaltime + ($wp['theoreticalchargetime'] * 60); $startdrivetime = $wparrivaltime + CalculateChargeTime(0, $wp['theoreticalchargeneeded']) * 60; $wpchargeneeded = $wp['theoreticalchargeneeded']; } if ($wp['statusid'] == 3) { $startdrivetime = $wp['chargeendtime']; $wpchargeneeded = $wp['chargeendtypical']; } if ($wp['statusid'] == 4) { $wpchargeneeded = $wp['departuretypical']; $startdrivetime = $wp['departuretime']; } // to calculate $wpdrivetime = $wp['theoreticaldrivetime']; $totaldrivetime += $wpdrivetime; //$wpchargetime = $wp['theoreticalchargetime']; $wpchargetime = CalculateChargeTime(0, $wp['theoreticalchargeneeded']); $totalchargetime += $wpchargetime; //format the output $wpdistance = number_format($wpdistance, 1, ',', '.'); $wptypical = number_format($wptypical, 0); $wpconsumption = number_format($wpconsumption, 1, ',', '.'); $wpdrivetime = date('H:i', mktime(0, $wpdrivetime, 0, 1, 1, 2000)); if ($wpchargetime > 0) { $wpchargetime = date('H:i', mktime(0, $wpchargetime, 0, 1, 1, 2000)); } else { $wpchargetime = ''; } $wparrivaltime = date('H:i', $wparrivaltime); $wpdeparturetime = date('H:i', $startdrivetime); } // build the waypoint $dwp[] = array('id' => $wp['objid'], 'location' => '', 'name' => $wp['destination'], 'statusid' => $wp['statusid'], 'overview' => array('distance' => $wpdistance, 'totaldistance' => number_format($totaldistance, 1, ',', '.'), 'typical' => $wptypical, 'totaltypical' => $totaltypical, 'consumption' => $wpconsumption, 'totalconsumption' => number_format($totalconsumption, 1, ',', '.'), 'averageconsumption' => $wpaverage, 'drivetime' => $wpdrivetime, 'totaldrivetime' => date('H:i', mktime(0, $totaldrivetime, 0, 1, 1, 2000)), 'chargetime' => $wpchargetime, 'totalchargetime' => date('H:i', mktime(0, $totalchargetime, 0, 1, 1, 2000)), 'chargeneeded' => $wpchargeneeded, 'arrivaltime' => $wparrivaltime, 'departuretime' => $wpdeparturetime), 'theoretical' => array('arrival' => array('distance' => $wpdistance + 0.0, 'typical' => $wpchargestarted - $wp['theoreticaltypical'], 'consumption' => $wp['theoreticalconsumption'] + 0.0, 'time' => $wp['theoreticaldrivetime']), 'chargestart' => array('typical' => $wpchargestart, 'time' => ''), 'chargeend' => array('typical' => $wp['theoreticalchargeneeded'] + 0, 'time' => ''), 'departure' => array('distance' => 0.0, 'typical' => $wpchargeneeded + 0, 'consumption' => 0.0, 'time' => '')), 'effective' => array('arrival' => array('distance' => $wp['arrivaldistance'], 'typical' => $wp['arrivaltypical'], 'consumption' => $wp['arrivalconsumption'], 'time' => $wp['arrivaltime']), 'chargestart' => array('typical' => $wp['chargestarttypical'], 'time' => $wp['chargestarttime']), 'chargeend' => array('typical' => $wp['chargeendtypical'], 'time' => $wp['chargeendtime']), 'departure' => array('distance' => $wp['departuredistance'], 'typical' => $wp['departuretypical'], 'consumption' => $wp['departureconsumption'], 'time' => $wp['departuretime']))); $wpchargestarted = $wpchargeneeded; } // final result $d = array('id' => $tripId, 'desc' => $trip->att('name'), 'statusid' => $statusid, 'etape' => $wpnbr, 'waypoints' => $dwp); return array("key" => "trip", "data" => $d); //return $d; }
/** * Returns statement that should be used in 'WHERE' caluse * to select elements that were searched for. * * The statement generated using search criteria is enclosed with parenthesis * and does not include keyword 'WHERE'. * * If no conditions where spcified returns empty string. * * @return string part of sql statement */ public function get_search_query( $array = false, $separate=false){ $search = $this->get_module_variable('search'); $this->get_module_variable_or_unique_href_variable('quickjump_to'); $quickjump = $this->get_module_variable('quickjump'); $quickjump_to = $this->get_module_variable('quickjump_to'); $this->set_module_variable('quickjump_to',$quickjump_to); if (!$array) { $where = ''; } else { $where = array(); } if(!$this->columns) trigger_error('columns array empty, please call set_table_columns',E_USER_ERROR); if(!$this->is_adv_search_on()) { if(isset($search['__keyword__'])) { if(!$array) { if($separate) $search = explode(' ',$search['__keyword__']); else $search = array($search['__keyword__']); } foreach($this->columns as $k=>$v){ if (isset($v['search'])) if (!$array) { $t_where = ''; foreach($search as $s) { $t_where .= ($t_where?' AND':'').' '.$v['search'].' '.DB::like().' '.DB::Concat(DB::qstr('%'),sprintf('%s',DB::qstr($s)),DB::qstr('%')); } $where .= ($where?' OR':'').' ('.$t_where.')'; } else $where[(empty($where)?'(':'|').$v['search']][] = sprintf('%s',$search['__keyword__']); } } } else { foreach($this->columns as $k=>$v) if (isset($v['search']) && isset($search[$v['search']])) { if (!$array) $where .= ($where?' AND':'').' '.$v['search'].' '.DB::like().' '.DB::Concat(DB::qstr('%'),sprintf('%s',DB::qstr($search[$v['search']])),DB::qstr('%')); else $where[$v['search']][] = $search[$v['search']]; } } if (isset($quickjump) && $quickjump_to!='') { if ($quickjump_to=='0') { if (!$array) { $where = ($where?'('.$where.') AND':'').' (false'; foreach(range(0,9) as $v) $where .= ' OR ' .$quickjump.' '.DB::like().' '.DB::Concat(sprintf('%s',DB::qstr($v)),'\'%\''); $where .= ')'; if ($where) $where = ' ('.$where.')'; } else { $where[$quickjump] = array(); foreach(range(0,9) as $v) $where[$quickjump][] = DB::qstr($v.'%'); } } else { if (!$array) { $where = ($where?'('.$where.') AND':'').' (' .$quickjump.' '.DB::like().' '.DB::Concat(sprintf('%s',DB::qstr($quickjump_to)),'\'%\'') .' OR ' .$quickjump.' '.DB::like().' '.DB::Concat(sprintf('%s',DB::qstr(strtolower($quickjump_to))),'\'%\''). ')'; if ($where) $where = ' ('.$where.')'; } else { $where[$quickjump] = array(DB::Concat(DB::qstr($quickjump_to),DB::qstr('%')),DB::Concat(DB::qstr(strtolower($quickjump_to)),DB::qstr('%'))); } } } return $where; }
public static function write($name, $data) { if (READ_ONLY_SESSION || defined('SESSION_EXPIRED')) { return true; } $name = self::truncated_session_id($name); $ret = 1; if (CID !== false && isset($_SESSION['client'])) { $data = serialize($_SESSION['client']); switch (self::$session_type) { case 'file': ftruncate(self::$session_client_fp, 0); // truncate file rewind(self::$session_client_fp); fwrite(self::$session_client_fp, $data); fflush(self::$session_client_fp); // flush output before releasing the lock flock(self::$session_client_fp, LOCK_UN); // release the lock fclose(self::$session_client_fp); break; case 'memcache': if (self::$memcached->is_lock(MEMCACHE_SESSION_TOKEN . $name . '_' . CID, self::$memcached_lock_time)) { $data = str_split($data, 1000000); //something little less then 1MB $data[] = ''; foreach ($data as $i => $d) { self::$memcached->set(MEMCACHE_SESSION_TOKEN . $name . '_' . CID . '/' . $i, $d, self::$lifetime); } self::$memcached->unlock(MEMCACHE_SESSION_TOKEN . $name . '_' . CID); } break; case 'sql': if (DB::is_mysql()) { $data = DB::qstr($data); } else { $data = '\'' . DB::BlobEncode($data) . '\''; } $ret &= DB::Replace('session_client', array('data' => $data, 'session_name' => DB::qstr($name), 'client_id' => CID), array('session_name', 'client_id')); break; } } if (isset($_SESSION['client'])) { unset($_SESSION['client']); } $data = serialize($_SESSION); switch (self::$session_type) { case 'file': ftruncate(self::$session_fp, 0); // truncate file rewind(self::$session_fp); fwrite(self::$session_fp, $data); fflush(self::$session_fp); // flush output before releasing the lock flock(self::$session_fp, LOCK_UN); // release the lock fclose(self::$session_fp); $ret &= DB::Replace('session', array('expires' => time(), 'name' => DB::qstr($name)), 'name'); break; case 'memcache': if (self::$memcached->is_lock(MEMCACHE_SESSION_TOKEN . $name, self::$memcached_lock_time)) { $data = str_split($data, 1000000); //something little less then 1MB $data[] = ''; foreach ($data as $i => $d) { self::$memcached->set(MEMCACHE_SESSION_TOKEN . $name . '/' . $i, $d, self::$lifetime); } self::$memcached->unlock(MEMCACHE_SESSION_TOKEN . $name); $ret &= DB::Replace('session', array('expires' => time(), 'name' => DB::qstr($name)), 'name'); } break; case 'sql': if (DB::is_mysql()) { $data = DB::qstr($data); } else { $data = '\'' . DB::BlobEncode($data) . '\''; } $ret &= DB::Replace('session', array('expires' => time(), 'data' => $data, 'name' => DB::qstr($name)), 'name'); break; } return $ret > 0 ? true : false; }
if (Utils_RecordBrowserCommon::delete_addon('premium_ecommerce_pages_data', 'Premium/Warehouse/eCommerce', 'attachment_page_addon')) { Utils_AttachmentCommon::new_addon('premium_ecommerce_pages_data'); } if (Utils_RecordBrowserCommon::delete_addon('premium_ecommerce_pages_data', 'Premium/Warehouse/eCommerce', 'attachment_page_desc_addon')) { Utils_AttachmentCommon::new_addon('premium_ecommerce_pages_data'); } if (Utils_RecordBrowserCommon::delete_addon('premium_ecommerce_products', 'Premium/Warehouse/eCommerce', 'attachment_product_addon')) { Utils_AttachmentCommon::new_addon('premium_ecommerce_products'); } if (Utils_RecordBrowserCommon::delete_addon('premium_ecommerce_descriptions', 'Premium/Warehouse/eCommerce', 'attachment_product_desc_addon')) { Utils_AttachmentCommon::new_addon('premium_ecommerce_descriptions'); } if (Utils_RecordBrowserCommon::delete_addon('premium_warehouse_items', 'Premium/Warehouse/Items', 'attachment_addon')) { Utils_AttachmentCommon::new_addon('premium_warehouse_items'); } if (Utils_RecordBrowserCommon::delete_addon('premium_warehouse_items_orders', 'Premium/Warehouse/Items/Orders', 'attachment_addon')) { Utils_AttachmentCommon::new_addon('premium_warehouse_items_orders'); } if (Utils_RecordBrowserCommon::delete_addon('premium_warehouse', 'Premium/Warehouse', 'attachment_addon')) { Utils_AttachmentCommon::new_addon('premium_warehouse'); } if (Utils_RecordBrowserCommon::delete_addon('premium_warehouse_distributor', 'Premium/Warehouse/Wholesale', 'attachment_addon')) { Utils_AttachmentCommon::new_addon('premium_warehouse_distributor'); } if (Utils_RecordBrowserCommon::delete_addon('bugtrack', 'Tests/Bugtrack', 'bugtrack_attachment_addon')) { Utils_AttachmentCommon::new_addon('bugtrack'); } if (Utils_RecordBrowserCommon::delete_addon('premium_schoolregister_lesson', 'Premium/SchoolRegister', 'lesson_notes_addon')) { Utils_AttachmentCommon::new_addon('premium_schoolregister_lesson'); DB::Execute('UPDATE utils_attachment_link SET local=' . DB::Concat(DB::qstr('premium_schoolregister_lesson/'), 'local') . ' WHERE local NOT LIKE ' . DB::Concat(DB::qstr('%'), DB::qstr('/'), DB::qstr('%'))); }
public static function cron2() { $interval = DB::is_postgresql() ? DB::qstr('4 minute') : '4 minute'; $arr = DB::GetAll('SELECT m.*,u.* FROM utils_messenger_message m INNER JOIN utils_messenger_users u ON u.message_id=m.id WHERE u.follow=0 AND m.alert_on+INTERVAL ' . $interval . ' <%T',array(time())); foreach($arr as $row) { Acl::set_user($row['user_login_id']); $always_follow = Base_User_SettingsCommon::get('Utils_Messenger','always_follow_me'); if(!$always_follow && $row['done']) continue; ob_start(); $fret = call_user_func_array(unserialize($row['callback_method']),unserialize($row['callback_args'])); ob_end_clean(); DB::Execute('UPDATE utils_messenger_users SET follow=1 WHERE message_id=%d AND user_login_id=%d',array($row['id'],$row['user_login_id'])); $mail = Base_User_SettingsCommon::get('Utils_Messenger','mail'); if($mail) { $msg = __('Alert on: %s',array(Base_RegionalSettingsCommon::time2reg($row['alert_on'],2)))."\n".$fret."\n".($row['message']?__('Alarm comment: %s',array($row['message'])):''); Base_MailCommon::send($mail,'Alert!',$msg); } Acl::set_user(); } return ''; }
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>' : ''); if (IPHONE) { print '</ul>'; } else { print '<input type="submit" value="OK"/>'; } if (!IPHONE) { print '</td></tr></table>'; } print '</form>'; if (isset($_GET['search']) && $_GET['search'] !== "Search" && $_GET['search'] !== "") { $search_crits = array(); $search_string = $_GET['search']; $search_string = DB::Concat(DB::qstr('%'), DB::qstr($search_string), DB::qstr('%')); $chr = '('; foreach ($cols_out as $col) { if (array_key_exists($col['record']['id'], $info)) { continue; } $args = $col['record']; $c = $args['id']; if ($args['type'] == 'text' || $args['type'] == 'currency' || $args['type'] == 'calculated' && $args['param'] != '') { $search_crits[$chr . '"~' . $c] = $search_string; $chr = '|'; continue; } if ($args['type'] != 'commondata' && $args['type'] != 'multiselect' && $args['type'] != 'select') { continue; }
public function save() { if ($this->isPersistent) { return true; } //TODO: add validation // Begin database transaction DB::BeginTransaction(); $success = true; if ($this->att('objid')) { // we are in UPDATE modus if (!$this->_deactivate()) { $success = false; } } // insert new version of the object... $sql = 'INSERT INTO ' . $this->tableName() . "(objid, isActive, created, createdby, modified, modifiedby, IPv4"; foreach ($this->attributes as $att) { if (!in_array($att->name, $this->metaattributes)) { $sql .= ", " . $att->name; } } $sql .= ") VALUES ("; // objid if (!$this->att("objid")) { $minimumID = date("Ymd") * 100000 + rand(0, 50000); $minimumID = 1; $sql .= "ifnull((SELECT newID FROM (SELECT MAX(objID) + 1 as 'newID' FROM " . $this->tableName() . " WHERE objID >= " . $minimumID . ") as x), " . $minimumID . ")"; $this->att("created", time()); $this->att("createdby", 1); // TODO: effectieve gebruiker invullen! $this->att("modified", $this->att("created")); $this->att("modifiedBy", 1); // TODO: effectieve gebruiker invullen! } else { $sql .= DB::qstr($this->att("objid")); $this->att("modified", time()); $this->att("modifiedBy", 1); // TODO: effectieve gebruiker invullen! if (!$this->att("created")) { $this->att("created", time()); } } // isActive $sql .= ", 1"; // created $sql .= ', FROM_UNIXTIME(' . $this->att('created') . ')'; // createdby $sql .= ', ' . DB::qstr($this->att('createdby')); // modified $sql .= ", NOW()"; // modifiedBy $sql .= ", " . DB::qstr($this->att("modifiedby")); // IPvq adres van de modification $sql .= ", " . DB::qstr($_SERVER["REMOTE_ADDR"]); // loop over the attributes here... foreach ($this->attributes as $att) { if (!in_array($att->name, $this->metaattributes)) { switch ($att->type) { case "datetime": case "date": case "time": if ($this->att($att->name) == null) { $sql .= ", NULL"; break; } else { // timestamps are in unixtimestamp in php $sql .= ", FROM_UNIXTIME(" . $this->att($att->name) . ")"; break; } case "varchar": case "bigint": case "int": case "tinyint": case "text": case "decimal": $sql .= ", " . DB::qstr($this->att($att->name)); break; default: throw new Exception("Datatype " . $att->type . " not supported for " . get_class($this) . "." . $att->name); } } } $sql .= ")"; // end of values try { DB::Execute($sql); } catch (Exception $e) { // catching exception and returning false... echo $e->getMessage(); $success = false; } if ($success && !$this->att("objID")) { // we have a new object id... // let's get it from the database $sql = "SELECT objId as id FROM " . $this->tableName() . " WHERE seqid = " . DB::Insert_ID(); $rs = DB::Execute($sql); $this->att("objID", $rs->fields["id"]); } DB::Commit($success); return $success; }
function get_acl_user_id($user_id) { $sql = 'SELECT id FROM aro WHERE section_value=' . DB::qstr('Users') . ' AND value=' . DB::qstr($user_id); return DB::GetOne($sql); }
public function search($fields_to_search, $value, $strict = false, $select = true, $nocount = false, $required = array()) { if ($fields_to_search === 'ID') { return $this->get_record($value); } $vals = array('name' => '-=-=-=-', 'firstname' => '-=-=-=-', 'surname' => '-=-=-=-', 'email' => '-=-=-=-'); if ($fields_to_search === '*') { $fields_to_search = array('name', 'firstname', 'surname', 'email'); } elseif (!is_array($fields_to_search)) { $fields_to_search = array($fields_to_search); } foreach ($fields_to_search as $i => $field) { $vals[$field] = is_array($value) ? $value[$i] : $value; } global $E_SESSION; $this->result = $this->count(); $fields = DB::GetCol('SELECT field FROM company_field WHERE field LIKE \'%mail%\''); $m_cols = array(); $m_cols2 = array(); foreach ($fields as $k => $f) { $i = 'f_' . preg_replace('/[^a-z0-9]/', '_', strtolower($f)); $m_cols[] = 'c.' . $i; $m_cols2[] = $i; } if ($strict) { $ret = DB::Execute('SELECT c.id as ID,c.f_company_name, m.f_email as memails, m.id as mid' . ($m_cols ? ', ' . implode(', ', $m_cols) : '') . ' FROM company_data_1 c LEFT JOIN rc_multiple_emails_data_1 m ON (m.f_record_id=c.id AND m.f_record_type=\'company\') WHERE c.active=1 AND (CAST(c.f_permission AS decimal)<2 OR c.created_by=%d) AND (' . ($m_cols ? implode('=' . DB::qstr($vals['email']) . ' OR ', $m_cols) . '=' . DB::qstr($vals['email']) . ' OR ' : '') . 'c.f_company_name=%s OR c.f_short_name=%s OR m.f_email=%s) ORDER BY c.f_company_name', array($E_SESSION['user'], $vals['name'], $vals['name'], $vals['email'])); } else { $ret = DB::Execute('SELECT c.id as ID,c.f_company_name, m.f_email as memails, m.id as mid' . ($m_cols ? ', ' . implode(', ', $m_cols) : '') . ' FROM company_data_1 c LEFT JOIN rc_multiple_emails_data_1 m ON (m.f_record_id=c.id AND m.f_record_type=\'company\') WHERE c.active=1 AND (CAST(c.f_permission AS decimal)<2 OR c.created_by=%d) AND (' . ($m_cols ? implode(' LIKE ' . DB::concat(DB::qstr("%%"), DB::qstr($vals['email']), DB::qstr("%%")) . ' OR ', $m_cols) . ' LIKE ' . DB::concat(DB::qstr("%%"), DB::qstr($vals['email']), DB::qstr("%%")) . ' OR ' : '') . 'c.f_company_name LIKE ' . DB::concat(DB::qstr("%%"), '%s', DB::qstr("%%")) . ' OR c.f_short_name LIKE ' . DB::concat(DB::qstr("%%"), '%s', DB::qstr("%%")) . ' OR m.f_email LIKE ' . DB::concat(DB::qstr("%%"), '%s', DB::qstr("%%")) . ') ORDER BY c.f_company_name', array($E_SESSION['user'], $vals['name'], $vals['name'], $vals['email'])); } $done_ids = array(); while ($row = $ret->FetchRow()) { if (!isset($row['ID']) && isset($row['id'])) { $row['ID'] = $row['id']; } $row2 = array('name' => $row['f_company_name']); $id = $row['ID']; if (!isset($done_ids[$id])) { $done_ids[$id] = 1; foreach ($m_cols2 as $k => $m) { if (!$row[$m]) { continue; } $row2['email'] = $row[$m]; $row2['ID'] = $id . '_' . $k; $this->result->add($row2); } } if ($row['memails']) { $row2['email'] = $row['memails']; $row2['ID'] = $id . '_' . -$row['mid']; $this->result->add($row2); } } $this->cache['search'] = 1; return $this->result; }
* @copyright Copyright © 2008, Telaxus LLC * @license MIT * @version 1.0 * @package epesi-utils * @subpackage attachment */ if (!isset($_REQUEST['token']) || !isset($_REQUEST['id'])) { die('Invalid usage'); } $id = $_REQUEST['id']; $token = $_REQUEST['token']; define('CID', false); define('READ_ONLY_SESSION', true); require_once '../../../include.php'; ModuleManager::load_modules(); $query = 'SELECT ual.id as aid,uaf.id,uaf.filestorage_id,uaf.attach_id,uaf.original,uad.ip_address,uad.attach_file_id,uad.created_by,uad.created_on,uad.description FROM (utils_attachment_file uaf INNER JOIN utils_attachment_download uad ON uad.attach_file_id=uaf.id) INNER JOIN utils_attachment_data_1 ual ON uaf.attach_id=ual.id WHERE uad.id=' . DB::qstr($id) . ' AND uad.token=' . DB::qstr($token) . ' AND uad.expires_on>' . DB::DBTimeStamp(time()) . ' AND uad.remote='; $row = DB::GetRow($query . '1'); if ($row == false) { $row = DB::GetRow($query . '2'); if ($row == false) { die('No such file'); } $duplicate = true; } else { $duplicate = false; } $original = $row['original']; $file_id = $row['id']; $local = $row['aid']; $fsid = $row['filestorage_id']; $filename = $local . '/' . $file_id;
public function show_data($crits = array(), $cols = array(), $order = array(), $admin = false, $special = false, $pdf = false, $limit = null) { $this->help('RecordBrowser','main'); if (Utils_RecordBrowserCommon::$admin_access) $admin = true; if (isset($_SESSION['client']['recordbrowser']['admin_access'])) Utils_RecordBrowserCommon::$admin_access = true; if (self::$clone_result!==null && $this->jump_to_new_record) { if (is_numeric(self::$clone_result)) $this->navigate('view_entry', 'view', self::$clone_result); $clone_result = self::$clone_result; self::$clone_result = null; if ($clone_result!='canceled') return; } if ($this->check_for_jump()) return; Utils_RecordBrowserCommon::$cols_order = $this->col_order; if ($this->get_access('browse')===false) { print(__('You are not authorised to browse this data.')); return; } $this->init(); $this->action = 'Browse'; if (!Base_AclCommon::i_am_admin() && $admin) { print(__('You don\'t have permission to access this data.')); } if ($this->data_gb!==null) $gb = $this->data_gb; else $gb = $this->init_module('Utils/GenericBrowser', null, $this->tab); if(!$pdf) $gb->set_expandable(true); if($pdf) $gb->set_resizable_columns(false); else $gb->set_fixed_columns_class($this->fixed_columns_class); if ($special) { $gb_per_page = Base_User_SettingsCommon::get('Utils/GenericBrowser','per_page'); $gb->set_per_page(Base_User_SettingsCommon::get('Utils/RecordBrowser/RecordPicker','per_page')); } if (!$this->disabled['search']) { $gb->is_adv_search_on(); $is_searching = $gb->get_module_variable('search',''); if (!empty($is_searching)) { if ($this->get_module_variable('browse_mode')!='all' // || $gb->get_module_variable('quickjump_to')!=null ) { $this->set_module_variable('browse_mode','all'); // $gb->set_module_variable('quickjump_to',null); location(array()); return; } } } if ($special) { $table_columns = array(array('name'=>__('Select'), 'width'=>'40px')); } else { $table_columns = array(); if (!$pdf && !$admin && $this->favorites) { $fav = array('name'=>' ', 'width'=>'24px', 'attrs'=>'class="Utils_RecordBrowser__favs"'); if (!isset($this->force_order)) $fav['order'] = ':Fav'; $table_columns[] = $fav; } if (!$pdf && !$admin && $this->watchdog) $table_columns[] = array('name'=>'', 'width'=>'24px', 'attrs'=>'class="Utils_RecordBrowser__watchdog"'); } if (!$this->disabled['quickjump']) $quickjump = DB::GetOne('SELECT quickjump FROM recordbrowser_table_properties WHERE tab=%s', array($this->tab)); else $quickjump = ''; $hash = array(); $query_cols = array(); foreach($this->table_rows as $field => $args) { $hash[$args['id']] = $field; if ($field === 'id') continue; if ((!$args['visible'] && (!isset($cols[$args['id']]) || $cols[$args['id']] === false))) continue; if (isset($cols[$args['id']]) && $cols[$args['id']] === false) continue; $query_cols[] = $args['id']; $arr = array('name'=>$args['name']); if (!$pdf && !isset($this->force_order) && $this->browse_mode!='recent' && $args['type']!=='multiselect' && ($args['type']!=='calculated' || $args['param']!='') && $args['type']!=='hidden') $arr['order'] = $field; if ($args['type']=='checkbox' || (($args['type']=='date' || $args['type']=='timestamp' || $args['type']=='time') && !$this->add_in_table) || $args['type']=='commondata') { $arr['wrapmode'] = 'nowrap'; $arr['width'] = 50; } else { $arr['width'] = 100; } $arr['name'] = _V($arr['name']); // ****** Translate field name for table header if (isset($this->more_table_properties[$args['id']])) { foreach (array('name','wrapmode','width','display','order') as $v) if (isset($this->more_table_properties[$args['id']][$v])) { if (is_numeric($this->more_table_properties[$args['id']][$v]) && $v=='width') $this->more_table_properties[$args['id']][$v] = $this->more_table_properties[$args['id']][$v]*10; $arr[$v] = $this->more_table_properties[$args['id']][$v]; } } if (is_array($args['param'])) $str = explode(';', $args['param']['array_id']); else $str = explode(';', $args['param']); $ref = explode('::', $str[0]); $each = array(); if (!$pdf && $quickjump!=='' && $args['name']===$quickjump) $each[] = 'quickjump'; if (!$pdf && !$this->disabled['search']) $each[] = 'search'; foreach ($each as $e) { if ($args['type']=='text' || $args['type']=='currency' || $args['type'] == 'autonumber' || ($args['type']=='calculated' && preg_match('/^[a-z]+(\([0-9]+\))?$/i',$args['param'])!==0)) $arr[$e] = $args['id']; if (isset($args['ref_field']) && $args['ref_field']) $arr[$e] = $args['id']; if ($args['commondata'] && (!is_array($args['param']) || strpos($args['param']['array_id'],':')===false)) { $arr[$e] = $args['id']; } } if (isset($arr['quickjump'])) $arr['quickjump'] = '"~'.$arr['quickjump']; if ($pdf) { $arr['attrs'] = 'style="border:1px solid black;font-weight:bold;text-align:center;color:white;background-color:gray"'; if (!isset($arr['width'])) $arr['width'] = 100; if ($arr['width']==1) $arr['width'] = 100; } $table_columns[] = $arr; } if ($pdf) { $max = 0; $width_sum = 0; foreach ($table_columns as $k=>$v) if ($v['width']>$max) $max = $v['width']; foreach ($table_columns as $k=>$v) { $table_columns[$k]['width'] = intval($table_columns[$k]['width']); if ($table_columns[$k]['width']<$max/2) $table_columns[$k]['width'] = $max/2; $width_sum += $table_columns[$k]['width']; } $fraction = 0; foreach ($table_columns as $k=>$v) { $table_columns[$k]['width'] = floor(100*$v['width']/$width_sum); $fraction += 100*$v['width']/$width_sum - $table_columns[$k]['width']; if ($fraction>1) { $table_columns[$k]['width'] += 1; $fraction -= 1; } $table_columns[$k]['width'] = $table_columns[$k]['width'].'%'; } } if (empty($table_columns)) { print('Invalid view, no fields to display'); return; } $gb->set_table_columns( $table_columns ); if (!$pdf) { $clean_order = array(); foreach ($order as $k => $v) { if ($k[0] == ':') { $clean_order[$k] = $v; continue; } if(!in_array($k,$query_cols)) continue; if (isset($this->more_table_properties[$k]) && isset($this->more_table_properties[$k]['name'])) $key = $this->more_table_properties[$k]['name']; elseif (isset($hash[$k])) $key = $hash[$k]; else $key = $k; $clean_order[_V($key)] = $v; // TRSL } if ($this->browse_mode != 'recent') $gb->set_default_order($clean_order, $this->changed_view); } $search = $gb->get_search_query(true); $search_res = array(); if ($this->search_calculated_callback) { $search_res = call_user_func($this->search_calculated_callback, $search); } if ($gb->is_adv_search_on()) { foreach ($search as $k=>$v) { $f_id = str_replace(array('"','~'),'',$k); $args = $this->table_rows[$hash[$f_id]]; if ($args['commondata']) $k = $k.'[]'; elseif (isset($args['ref_field']) && $args['ref_field']) $k = $k.'['.Utils_RecordBrowserCommon::get_field_id($args['ref_field']).']'; if ($k[0]=='"') { $search_res['~_'.$k] = $v; continue; } if (is_array($v)) $v = $v[0]; $v = explode(' ', $v); foreach ($v as $w) { if (!$args['commondata']) { $w = DB::Concat(DB::qstr('%'),DB::qstr($w),DB::qstr('%')); $op = '"'; } else { $op = ''; } $search_res = Utils_RecordBrowserCommon::merge_crits($search_res, array('~'.$op.$k =>$w)); } } } else { $val = reset($search); $isearch = $gb->get_module_variable('search'); if (empty($isearch)) $val = null; $val2 = explode(' ', $val[0]); $leftovers = array(); foreach ($val2 as $vv) { foreach ($search as $k=>$v) { if ($v!=$val) { $leftovers[$k] = $v; continue; } if ($k[0]=='"') { $search_res['~_'.$k] = $vv; continue; } $args = $this->table_rows[$hash[trim($k, '(|')]]; if ($args['commondata']) $k = $k.'[]'; elseif (isset($args['ref_field']) && $args['ref_field']) $k = $k.'['.Utils_RecordBrowserCommon::get_field_id($args['ref_field']).']'; if (!$args['commondata']) { $w = DB::Concat(DB::qstr('%'),DB::qstr($vv),DB::qstr('%')); $op = '"'; } else { $w = $vv; $op = ''; } $search_res = Utils_RecordBrowserCommon::merge_crits($search_res, array('~'.$op.$k =>$w)); } } $search_res = Utils_RecordBrowserCommon::merge_crits($search_res, $leftovers); } if (!$pdf) $order = $gb->get_order(); $crits = array_merge($crits, $search_res); if ($this->browse_mode == 'favorites') $crits[':Fav'] = true; if ($this->browse_mode == 'watchdog') $crits[':Sub'] = true; if ($this->browse_mode == 'recent') { $crits[':Recent'] = true; $order = array(':Visited_on'=>'DESC'); } if ($admin && !$pdf) { $order = array(':Edited_on'=>'DESC'); $form = $this->init_module('Libs/QuickForm', null, $this->tab.'_admin_filter'); $form->addElement('select', 'show_records', __('Show records'), array(0=>'['.__('All').']',1=>'['.__('All active').']',2=>'['.__('All deactivated').']'), array('onchange'=>$form->get_submit_form_js())); $f = $this->get_module_variable('admin_filter', 0); $form->setDefaults(array('show_records'=>$f)); $admin_filter = $form->exportValue('show_records'); $this->set_module_variable('admin_filter', $admin_filter); switch($admin_filter) { case 0: Utils_RecordBrowserCommon::$admin_filter = ''; break; case 1: Utils_RecordBrowserCommon::$admin_filter = 'active=1 AND '; break; case 2: Utils_RecordBrowserCommon::$admin_filter = 'active=0 AND '; break; } $form->display_as_row(); } if (isset($this->force_order)) $order = $this->force_order; if (!$order) $order = array(); $this->amount_of_records = Utils_RecordBrowserCommon::get_records_count($this->tab, $crits, $admin, $order); if ($limit === null && !$this->disabled['pagination']) $limit = $gb->get_limit($this->amount_of_records); if (!$this->disabled['pdf'] && !$pdf && $this->get_access('print')) { $limited_print_records = 200; $limited_print = ($this->amount_of_records >= $limited_print_records); $print_limit = $limited_print ? $limit : null; $key = md5(serialize($this->tab).serialize($crits).serialize($cols).serialize($order).serialize($admin).serialize($print_limit)); $_SESSION['client']['utils_recordbrowser'][$key] = array( 'tab'=>$this->tab, 'crits'=>$crits, 'cols'=>$cols, 'order'=>$order, 'admin'=>$admin, 'more_table_properties'=>$this->more_table_properties, 'limit' => $print_limit, ); $print_href = 'href="modules/Utils/RecordBrowser/print.php?'.http_build_query(array('key'=>$key, 'cid'=>CID)).'" target="_blank"'; $print_tooltip_text = $limited_print ? __('Due to more than %d records, you are allowed to print current view', array($limited_print_records)) : __('Print all records'); $print_tooltip = Utils_TooltipCommon::open_tag_attrs($print_tooltip_text, false); $this->new_button('print', __('Print'), "$print_href $print_tooltip"); } $records = Utils_RecordBrowserCommon::get_records($this->tab, $crits, array(), $order, $limit, $admin); if (($this->get_access('export') || $this->enable_export) && !$this->disabled['export']) $this->new_button('save',__('Export'), 'href="modules/Utils/RecordBrowser/csv_export.php?'.http_build_query(array('tab'=>$this->tab, 'admin'=>$admin, 'cid'=>CID, 'path'=>$this->get_path())).'"'); $this->set_module_variable('crits_stuff',$crits?$crits:array()); $this->set_module_variable('order_stuff',$order?$order:array()); $custom_label = ''; if (!$pdf && !$special && $this->get_access('add',$this->custom_defaults)!==false) { if ($this->add_button!==null) $label = $this->add_button; elseif (!$this->multiple_defaults) $label = $this->create_callback_href(array($this, 'navigate'), array('view_entry', 'add', null, $this->custom_defaults)); else $label = Utils_RecordBrowserCommon::create_new_record_href($this->tab,$this->custom_defaults,'multi',true,true); if ($label!==false && $label!=='') $custom_label = '<a '.$label.'><span class="record_browser_add_new" '.Utils_TooltipCommon::open_tag_attrs(__('Add new record')).'><img src="'.Base_ThemeCommon::get_template_file('Utils/RecordBrowser/add.png').'" /><div class="add_new">'.__('Add new').'</div></span></a>'; } if ($this->more_add_button_stuff) { if ($custom_label) $custom_label = '<table><tr><td>'.$custom_label.'</td><td>'.$this->more_add_button_stuff.'</td></tr></table>'; else $custom_label = $this->more_add_button_stuff; } $gb->set_custom_label($custom_label); if ($admin) $this->browse_mode = 'all'; if ($this->browse_mode == 'recent') { $ret = DB::Execute('SELECT * FROM '.$this->tab.'_recent WHERE user_id=%d ORDER BY visited_on DESC', array(Acl::get_user())); while ($row = $ret->FetchRow()) { if (!isset($records[$row[$this->tab.'_id']])) continue; $records[$row[$this->tab.'_id']]['visited_on'] = Base_RegionalSettingsCommon::time2reg(strtotime($row['visited_on'])); } } else { $this->set_module_variable('set_browsed_records',array('tab'=>$this->tab,'crits'=>$crits, 'order'=>$order, 'records'=>array())); } if ($special) $rpicker_ind = array(); if (!$pdf && !$admin && $this->favorites) { $favs = array(); $ret = DB::Execute('SELECT '.$this->tab.'_id FROM '.$this->tab.'_favorite WHERE user_id=%d', array(Acl::get_user())); while ($row=$ret->FetchRow()) $favs[$row[$this->tab.'_id']] = true; } self::$access_override['tab'] = $this->tab; if (isset($limit)) $i = $limit['offset']; $grid_enabled = $this->grid===null?Base_User_SettingsCommon::get('Utils/RecordBrowser','grid'):$this->grid; if ($grid_enabled) load_js('modules/Utils/RecordBrowser/grid.js'); $this->view_fields_permission = $this->get_access('add', $this->custom_defaults); if (!$pdf && !$special && $this->add_in_table && $this->view_fields_permission) { $form = $this->init_module('Libs/QuickForm',null, 'add_in_table__'.$this->tab); $form_name = $form->get_name(); } else $form_name = ''; foreach ($records as $row) { if ($this->browse_mode!='recent' && isset($limit)) { self::$browsed_records['records'][$row['id']] = $i; $i++; } $row = Utils_RecordBrowserCommon::record_processing($this->tab, $row, 'browse'); self::$access_override['id'] = $row['id']; $gb_row = $gb->get_new_row(); $row_data = array(); if (!$pdf && !$admin && $this->favorites) { $isfav = isset($favs[$row['id']]); $row_data[] = Utils_RecordBrowserCommon::get_fav_button($this->tab, $row['id'], $isfav); } if (!$pdf && !$admin && $this->watchdog) $row_data[] = Utils_WatchdogCommon::get_change_subscription_icon($this->tab,$row['id']); if ($special) { $element = $this->get_module_variable('element'); $format = $this->get_module_variable('format_func'); $row_data = array('<input type="checkbox" id="leightbox_rpicker_'.$element.'_'.$row['id'].'" formated_name="'.(is_callable($format)?strip_tags(call_user_func($format, $row, true)):'').'" />'); $rpicker_ind[] = $row['id']; } $r_access = $this->get_access('view', $row); foreach($query_cols as $k=>$argsid) { if (!$r_access || !$r_access[$argsid]) { $row_data[] = ''; continue; } $field = $hash[$argsid]; $args = $this->table_rows[$field]; $value = $this->get_val($field, $row, ($special || $pdf), $args); if (strip_tags($value)=='') $value .= ' '; if ($args['style']=='currency' || $args['style']=='number') $value = array('style'=>'text-align:right;','value'=>$value); if ($grid_enabled && !in_array($args['type'], array('calculated','multiselect','commondata'))) { $table = '<table class="Utils_RecordBrowser__grid_table" style="width:100%" cellpadding="0" cellspacing="0" border="0"><tr><td id="grid_form_field_'.$argsid.'_'.$row['id'].'" style="display:none;">Loading...</td><td id="grid_value_field_'.$argsid.'_'.$row['id'].'">'; $ed_icon = '</td><td style="min-width:18px;width:18px;padding:0px;margin:0px;">'. '<span id="grid_edit_'.$argsid.'_'.$row['id'].'" style="float:right;display:none;"><a href="javascript:void(0);" onclick="grid_enable_field_edit(\''.$argsid.'\','.$row['id'].',\''.$this->tab.'\',\''.$form_name.'\');"><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils/GenericBrowser', 'edit.png').'"></a></span>'. '<span id="grid_save_'.$argsid.'_'.$row['id'].'" style="float:right;display:none;"><a href="javascript:void(0);" onclick="grid_submit_field(\''.$argsid.'\','.$row['id'].',\''.$this->tab.'\');"><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils/RecordBrowser', 'save_grid.png').'"></a></span>'. '</td></tr></table>'; /* $table = '<span id="grid_form_field_'.$argsid.'_'.$row['id'].'" style="display:none;">Loading...</span><span id="grid_value_field_'.$argsid.'_'.$row['id'].'">'; $ed_icon = '</span>'. '<span id="grid_edit_'.$argsid.'_'.$row['id'].'" style="float:right;display:none;"><a href="javascript:void(0);" onclick="grid_enable_field_edit(\''.$argsid.'\','.$row['id'].',\''.$this->tab.'\',\''.$form_name.'\');"><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils/GenericBrowser', 'edit.png').'"></a></span>'. '<span id="grid_save_'.$argsid.'_'.$row['id'].'" style="float:right;display:none;"><a href="javascript:void(0);" onclick="grid_submit_field(\''.$argsid.'\','.$row['id'].',\''.$this->tab.'\');"><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils/RecordBrowser', 'save_grid.png').'"></a></span>';*/ $attrs = 'onmouseover="if(typeof(mouse_over_grid)!=\'undefined\')mouse_over_grid(\''.$argsid.'\',\''.$row['id'].'\');" onmouseout="if(typeof(mouse_out_grid)!=\'undefined\')mouse_out_grid(\''.$argsid.'\',\''.$row['id'].'\');"'; // $attrs = 'onmouseover="$(\'grid_edit_'.$argsid.'_'.$row['id'].'\').style.display=\'inline\'" onmouseout="$(\'grid_edit_'.$argsid.'_'.$row['id'].'\').style.display=\'none\'"'; } else { $table = ''; $ed_icon = ''; $attrs = ''; } if (is_array($value)) { $value['value'] = $table.$value['value'].$ed_icon; $value['attrs'] = $attrs; } else { $value = array( 'value'=>$table.$value.$ed_icon, 'attrs'=>$attrs ); } if ($pdf) { $value['overflow_box'] = false; $value['attrs'] = $attrs.' style="border:1px solid black;"'; $value['value'] = ' '.$value['value'].' '; } $row_data[] = $value; } $gb_row->add_data_array($row_data); if (!$pdf && $this->disabled['actions']!==true) { if ($this->disabled['actions']===false) $da = array(); else $da = array_flip($this->disabled['actions']); if (!$special) { if (!isset($da['view'])) $gb_row->add_action($this->create_callback_href(array($this,'navigate'),array('view_entry', 'view', $row['id'])),__('View'), null, 'view'); if (!isset($da['edit'])) { if ($this->get_access('edit',$row)) $gb_row->add_action($this->create_callback_href(array($this,'navigate'),array('view_entry', 'edit',$row['id'])),__('Edit'), null, 'edit'); else $gb_row->add_action('',__('Edit'),__('You don\'t have permission to edit this record.'),'edit',0,true); } if ($admin) { if (!$row[':active']) $gb_row->add_action($this->create_callback_href(array($this,'set_active'),array($row['id'],true)),__('Activate'), null, 'active-off'); else $gb_row->add_action($this->create_callback_href(array($this,'set_active'),array($row['id'],false)),__('Deactivate'), null, 'active-on'); $info = Utils_RecordBrowserCommon::get_record_info($this->tab, $row['id']); if ($info['edited_on']===null) $gb_row->add_action('',__('This record was never edited'),null,'history_inactive'); else $gb_row->add_action($this->create_callback_href(array($this,'navigate'),array('view_edit_history', $row['id'])),__('View edit history'),null,'history'); } else { if (!isset($da['delete'])) { if ($this->get_access('delete',$row)) $gb_row->add_action($this->create_confirm_callback_href(__('Are you sure you want to delete this record?'),array($this,'delete_record'),array($row['id'], false)),__('Delete'), null, 'delete'); else $gb_row->add_action('',__('Delete'),__('You don\'t have permission to delete this record'),'delete',0,true); } } } if (!isset($da['info'])) $gb_row->add_info(($this->browse_mode=='recent'?'<b>'.__('Visited on: %s', array($row['visited_on'])).'</b><br>':'').Utils_RecordBrowserCommon::get_html_record_info($this->tab, isset($info)?$info:$row['id'])); $this->call_additional_actions_methods($row, $gb_row); } } if (!$special && $this->add_in_table && $this->view_fields_permission) { $visible_cols = array(); foreach($this->table_rows as $field => $args){ if ((!$args['visible'] && (!isset($cols[$args['id']]) || $cols[$args['id']] === false))) continue; if (isset($cols[$args['id']]) && $cols[$args['id']] === false) continue; $visible_cols[$args['id']] = true; } self::$last_record = $this->record = $this->custom_defaults = Utils_RecordBrowserCommon::record_processing($this->tab, $this->custom_defaults, 'adding'); $this->prepare_view_entry_details($this->custom_defaults, 'add', null, $form, $visible_cols); $form->setDefaults($this->custom_defaults); if ($form->isSubmitted()) { $this->set_module_variable('force_add_in_table_after_submit', true); if ($form->validate()) { $values = $form->exportValues(); foreach ($this->custom_defaults as $k=>$v) if (!isset($values[$k])) $values[$k] = $v; $id = Utils_RecordBrowserCommon::new_record($this->tab, $values); location(array()); } else { $this->show_add_in_table = true; } } $form->addElement('submit', 'submit_qanr', __('Save'), array('style'=>'width:100%;height:19px;', 'class'=>'button')); $renderer = new HTML_QuickForm_Renderer_TCMSArraySmarty(); $form->accept($renderer); $data = $renderer->toArray(); $gb->set_prefix($data['javascript'].'<form '.$data['attributes'].'>'.$data['hidden']."\n"); $gb->set_postfix("</form>\n"); if (!$admin && $this->favorites) { $row_data= array(' '); } else $row_data= array(); if (!$admin && $this->watchdog) $row_data[] = ' '; $first = true; foreach($visible_cols as $k => $v) { if (isset($data[$k])) { $row_data[] = array('value'=>$data[$k]['error'].$data[$k]['html'], 'overflow_box'=>false); if ($first) eval_js('focus_on_field = "'.$k.'";'); $first = false; } else $row_data[] = ' '; } // if ($this->browse_mode == 'recent') // $row_data[] = ' '; $gb_row = $gb->get_new_row(); $gb_row->add_action('',$data['submit_qanr']['html'],'', null, 0, false, 7); $gb_row->set_attrs('id="add_in_table_row" style="display:'.($this->show_add_in_table?'':'none').';"'); $gb_row->add_data_array($row_data); } if ($special) { $this->set_module_variable('rpicker_ind',$rpicker_ind); $ret = $this->get_html_of_module($gb); Base_User_SettingsCommon::save('Utils/RecordBrowser/RecordPicker','per_page',$gb->get_module_variable('per_page')); Base_User_SettingsCommon::save('Utils/GenericBrowser','per_page',$gb_per_page); return $ret; } if ($pdf) { $gb->absolute_width(true); $args = array(Base_ThemeCommon::get_template_filename('Utils_GenericBrowser','pdf')); } else $args = array(); $this->display_module($gb, $args); }
<?php defined("_VALID_ACCESS") || die('Direct access forbidden'); if (ModuleManager::is_installed('CRM_Roundcube') >= 0) { foreach (DB::GetCol('SELECT id FROM user_login') as $id) { $identity = DB::GetOne("SELECT " . DB::Concat('f_first_name', DB::qstr(' '), 'f_last_name') . " FROM contact_data_1 WHERE f_login =%d", array($id)); foreach (DB::GetCol("SELECT f_email FROM rc_accounts_data_1 WHERE f_epesi_user=%d", array($id)) as $f_email) { DB::Execute('UPDATE rc_identities SET name=%s WHERE email=%s', array($identity, $f_email)); } } }
<?php defined("_VALID_ACCESS") || die('Direct access forbidden'); Utils_CommonDataCommon::extend_array('Contacts/Access', array('employee' => _M('Employee'))); $cmp = Variable::get('main_company', null); if ($cmp) { set_time_limit(0); $conts = DB::GetAll('SELECT * FROM contact_data_1 WHERE f_company_name=%d OR f_related_companies ' . DB::like() . ' ' . DB::Concat(DB::qstr('\\_\\_'), DB::qstr($cmp), DB::qstr('\\_\\_')), array($cmp)); foreach ($conts as $k => $v) { $v['access'] = Utils_RecordBrowserCommon::decode_multi($v['f_access']); $v['access'][] = 'employee'; Utils_RecordBrowserCommon::update_record('contact', $v['id'], array('access' => $v['access'])); } Variable::delete('main_company', false); } $tab = DB::GetAssoc('SELECT tab, tab FROM recordbrowser_table_properties'); foreach ($tab as $t) { DB::Execute('UPDATE ' . $t . '_access_clearance SET clearance=%s WHERE clearance=%s', array('ACCESS:employee', 'EMPLOYEE')); }
public static function search($word, $types) { if(!$types) return; $r = null; $limit = Base_SearchCommon::get_recordset_limit_records(); $ret = array(); foreach($types as $type) { if($type=='files') { $r = DB::SelectLimit('SELECT ua.id,uaf.original,ual.func,ual.args,ual.local,ua.f_title FROM utils_attachment_data_1 ua INNER JOIN utils_attachment_local AS ual ON ual.attachment=ua.id INNER JOIN utils_attachment_file AS uaf ON uaf.attach_id=ua.id WHERE ua.active=1 AND '. ' uaf.original '.DB::like().' '.DB::Concat(DB::qstr('%'),'%s',DB::qstr('%')).' AND uaf.deleted=0', $limit, -1, array($word)); } elseif($type=='downloads') { if(strlen($word)==32) { $query = 'SELECT ua.id,uaf.original,ual.func,ual.args,ual.local,ua.f_title FROM utils_attachment_file uaf INNER JOIN utils_attachment_download uad ON uad.attach_file_id=uaf.id INNER JOIN utils_attachment_data_1 ua ON uaf.attach_id=ua.id INNER JOIN utils_attachment_local AS ual ON ual.attachment=ua.id WHERE uad.token='.DB::qstr($word); $r = DB::Execute($query); } else { $query = parse_url($word,PHP_URL_QUERY); if($query) { $vars = array(); parse_str($query,$vars); if($vars && isset($vars['id']) && isset($vars['token'])) { $query = 'SELECT ua.id,uaf.original,ual.func,ual.args,ual.local,ua.f_title FROM utils_attachment_file uaf INNER JOIN utils_attachment_download uad ON uad.attach_file_id=uaf.id INNER JOIN utils_attachment_data_1 ua ON uaf.attach_id=ua.id INNER JOIN utils_attachment_local AS ual ON ual.attachment=ua.id WHERE uad.id='.DB::qstr($vars['id']).' AND uad.token='.DB::qstr($vars['token']); $r = DB::Execute($query); } } } } if($r) { while($row = $r->FetchRow()) { if(!self::get_access($row['id'])) continue; $func = unserialize($row['func']); $record = $func ? call_user_func_array($func, unserialize($row['args'])) : ''; if(!$record) continue; $title = $row['original'].' - '.self::description_callback(Utils_RecordBrowserCommon::get_record('utils_attachment',$row['id'])); $title = Utils_RecordBrowserCommon::record_link_open_tag('utils_attachment', $row['id']) . __('Files').': ' . $title . Utils_RecordBrowserCommon::record_link_close_tag(); $ret[$row['id'].'#'.$row['local']] = $title . " ($record)"; } } } return $ret; }
public function addon_threaded($rs, $id) { $rb = $this->init_module('Utils/RecordBrowser', 'rc_mail_threads', 'rc_mails_threaded'); $rb->set_header_properties(array('date' => array('width' => 10), 'contacts' => array('name' => __('Involved contacts'), 'width' => 20), 'subject' => array('name' => __('Message'), 'width' => 40), 'attachments' => array('width' => 5), 'count' => array('width' => 5))); //set order by threads: //1 - if there is reference sort by parent message date, else sort by this message date ("group" messages by "parent" date) //2 - if there is reference sort by parent message id, else sort by "my" message_id /* $rb->force_order(array(':CASE WHEN f_references is null OR (SELECT rx.f_date FROM rc_mails_data_1 rx WHERE rx.active=1 AND r.f_references LIKE '.DB::Concat('\'%\'','rx.f_message_id','\'%\'').' LIMIT 1) is null THEN (SELECT rx.f_date FROM rc_mails_data_1 rx WHERE rx.active=1 AND rx.f_references LIKE '.DB::Concat('\'%\'','r.f_message_id','\'%\'').' ORDER BY rx.f_date DESC LIMIT 1) ELSE (SELECT rx2.f_date FROM rc_mails_data_1 rx2 WHERE rx2.active=1 AND rx2.f_references LIKE '.DB::Concat('\'%\'','(SELECT rx.f_message_id FROM rc_mails_data_1 rx WHERE rx.active=1 AND r.f_references LIKE '.DB::Concat('\'%\'','rx.f_message_id','\'%\'').' ORDER BY rx.f_date ASC LIMIT 1)','\'%\'').' ORDER BY rx2.f_date DESC LIMIT 1) END'=>'DESC', ':CASE WHEN f_references is null THEN f_message_id ELSE (SELECT rx.f_message_id FROM rc_mails_data_1 rx WHERE rx.f_references is null AND r.f_references LIKE '.DB::Concat('\'%\'','rx.f_message_id','\'%\'').' ORDER BY rx.f_date ASC LIMIT 1) END'=>'DESC', ':CASE WHEN f_references is null OR (SELECT rx.f_date FROM rc_mails_data_1 rx WHERE rx.active=1 AND r.f_references LIKE '.DB::Concat('\'%\'','rx.f_message_id','\'%\'').' LIMIT 1) is null THEN 0 ELSE 1 END'=>'ASC', 'date'=>'DESC' ));*/ $assoc_threads_ids = DB::GetCol('SELECT m.f_thread FROM rc_mails_data_1 m WHERE m.active=1 AND m.f_related ' . DB::like() . ' ' . DB::Concat(DB::qstr('%\\_\\_'), '%s', DB::qstr('\\_\\_%')), array($rs . '/' . $id)); if ($rs == 'contact') { //$ids = DB::GetCol('SELECT id FROM rc_mails_data_1 WHERE f_employee=%d OR (f_recordset=%s AND f_object=%d)',array($id,$rs,$id)); $this->display_module($rb, array(array('(contacts' => array('P:' . $id), '|id' => $assoc_threads_ids), array(), array('last_date' => 'DESC')), 'show_data'); } elseif ($rs == 'company') { $form = $this->init_module('Libs/QuickForm'); $form->addElement('checkbox', 'include_related', __('Include related e-mails'), null, array('onchange' => $form->get_submit_form_js())); if ($form->validate()) { $show_related = $form->exportValue('include_related'); $this->set_module_variable('include_related', $show_related); } $show_related = $this->get_module_variable('include_related'); $form->setDefaults(array('include_related' => $show_related)); ob_start(); $form->display_as_row(); $html = ob_get_clean(); $rb->set_button(false, $html); $customers = array('C:' . $id); if ($show_related) { $conts = CRM_ContactsCommon::get_contacts(array('company_name' => $id)); foreach ($conts as $c) { $customers[] = 'P:' . $c['id']; } } $this->display_module($rb, array(array('(contacts' => $customers, '|id' => $assoc_threads_ids), array(), array('last_date' => 'DESC')), 'show_data'); } else { $this->display_module($rb, array(array('id' => $assoc_threads_ids), array(), array('last_date' => 'DESC')), 'show_data'); } //Epesi::load_js('modules/CRM/Roundcube/utils.js'); //eval_js('CRM_RC.create_msg_tree("'.escapeJS($rb->get_path().'|0content',true).'")'); }
<?php defined("_VALID_ACCESS") || die('Direct access forbidden'); @set_time_limit(0); // both mysql and postgresql should have this function $substr_func = 'substr'; $time_field = 'f_time'; $date_field = 'f_date'; if (DB::is_postgresql()) { // apply types cast required by postgres $time_field .= '::text'; $date_field .= '::text'; } $new_time_sql = DB::Concat($date_field, DB::qstr(' '), "{$substr_func}({$time_field},12)"); if (DB::is_postgresql()) { // apply type cast again for postgres $new_time_sql = "cast({$new_time_sql} as timestamp)"; } $sql = "UPDATE crm_meeting_data_1 SET f_time = {$new_time_sql} WHERE f_time IS NOT NULL AND LENGTH({$time_field})=19"; DB::Execute($sql);