public function update_observer($type, $message, $errfile, $errline, $errcontext, $backtrace) { $mail = Variable::get('error_mail'); if ($mail) { $backtrace = htmlspecialchars_decode(str_replace(array('<br />', ' '), array("\n", ' '), $backtrace)); $x = "who=" . Base_AclCommon::get_user() . "\ntype=" . $type . "\nmessage=" . $message . "\nerror file=" . $errfile . "\nerror line=" . $errline . "\n" . $backtrace; $d = ModuleManager::get_data_dir('Base/Error') . md5($x) . '.txt'; file_put_contents($d, $x); $url = get_epesi_url(); Base_MailCommon::send($mail, 'Epesi Error - ' . $url, substr($x, 0, strpos($x, "error backtrace")) . "\n" . $url . '/' . $d, null, null, false, true); } return true; }
/** * Replace all registered special values. * * Object will be cloned. Current object will not be changed. * * @param bool $human_readable Use special value or it's human readable form * * @return Utils_RecordBrowser_CritsInterface New object with replaced values */ public function replace_special_values($human_readable = false) { $new = clone $this; $user = Base_AclCommon::get_user(); $replace_values = self::get_replace_values($user); /** @var Utils_RecordBrowser_ReplaceValue $rv */ foreach ($replace_values as $rv) { $replacement = $human_readable ? $rv->get_human_readable() : $rv->get_replace(); $deactivate = $human_readable ? false : $rv->get_deactivate(); $new->replace_value($rv->get_value(), $replacement, $deactivate); } return $new; }
public static function notification() { $time = time() - 24 * 3600; $arr = DB::GetAll('SELECT ul.login, ul.id as user_id, asm.id, asm.message, asm.posted_on, asm.to_user_login_id FROM apps_shoutbox_messages asm LEFT JOIN user_login ul ON ul.id=asm.base_user_login_id WHERE asm.posted_on>=%T AND asm.base_user_login_id!=%d AND (asm.to_user_login_id=%d OR asm.to_user_login_id is null) ORDER BY asm.posted_on DESC LIMIT 10', array($time, Base_AclCommon::get_user(), Base_AclCommon::get_user())); if (empty($arr)) { return array(); } //print it out $ret = array(); $tray = array(); foreach ($arr as $row) { if (!$row['login']) { $row['login'] = '******'; } $ret['shoutbox_' . $row['id']] = vsprintf('<font color="gray">[%s]</font><font color="blue">%s</font>: %s', array(Base_RegionalSettingsCommon::time2reg($row['posted_on']), $row['login'], $row['message'])); $tray['shoutbox_' . $row['id']] = array('title' => __('Shoutbox Message'), 'body' => $row['to_user_login_id'] ? __('%s wrote to you: %s', array(Base_UserCommon::get_user_label($row['user_id'], true), $row['message'])) : __('%s wrote to all: %s', array(Base_UserCommon::get_user_label($row['user_id'], true), $row['message']))); } return array('notifications' => $ret, 'tray' => $tray); }
public static function set_default_applets() { $tabs = DB::GetAll('SELECT id,pos,name FROM base_dashboard_default_tabs'); foreach ($tabs as $tab) { DB::Execute('INSERT INTO base_dashboard_tabs(user_login_id,pos,name) VALUES(%d,%d,%s)', array(Base_AclCommon::get_user(), $tab['pos'], $tab['name'])); $id = DB::Insert_ID('base_dashboard_tabs', 'id'); $ret = DB::GetAll('SELECT id,module_name,col,color,tab FROM base_dashboard_default_applets WHERE tab=%d ORDER BY pos', array($tab['id'])); foreach ($ret as $row) { DB::Execute('INSERT INTO base_dashboard_applets(module_name,col,user_login_id,color,tab) VALUES(%s,%d,%d,%d,%d)', array($row['module_name'], $row['col'], Base_AclCommon::get_user(), $row['color'], $id)); $ins_id = DB::Insert_ID('base_dashboard_applets', 'id'); $ret_set = DB::GetAll('SELECT name,value FROM base_dashboard_default_settings WHERE applet_id=%d', array($row['id'])); foreach ($ret_set as $row_set) { DB::Execute('INSERT INTO base_dashboard_settings(applet_id,value,name) VALUES(%d,%s,%s)', array($ins_id, $row_set['value'], $row_set['name'])); } } } }
/** * @author Paul Bukowski <*****@*****.**> * @copyright Copyright © 2008, Telaxus LLC * @license MIT * @version 1.0 * @package epesi-apps * @subpackage shoutbox */ ob_start(); define('CID', false); require_once '../../../include.php'; ModuleManager::load_modules(); if (!Base_AclCommon::is_user()) { exit; } $myid = Base_AclCommon::get_user(); $uid = isset($_GET['uid']) && is_numeric($_GET['uid']) ? $_GET['uid'] : null; //get last 20 messages $arr = DB::GetAll('SELECT asm.base_user_login_id as from_login_id, asm.to_user_login_id as to_login_id,asm.message, asm.posted_on FROM apps_shoutbox_messages asm WHERE ' . ($uid ? '(base_user_login_id=' . $myid . ' AND to_user_login_id=' . $uid . ') OR (base_user_login_id=' . $uid . ' AND to_user_login_id=' . $myid . ')' : 'to_user_login_id is null OR to_user_login_id=' . $myid . ' OR base_user_login_id=' . $myid) . ' ORDER BY asm.posted_on DESC LIMIT 20'); //print it out foreach ($arr as $row) { $daydiff = floor((time() - strtotime($row['posted_on'])) / 86400); switch (true) { case $daydiff < 1: $fcolor = '#000000'; break; case $daydiff < 3: $fcolor = '#444444'; break; case $daydiff < 7: $fcolor = '#888888';
protected function build_order_part($order) { foreach ($order as $k => $v) { if (!is_string($k)) { break; } if ($k[0] == ':') { $order[] = array('column' => $k, 'order' => $k, 'direction' => $v); } else { $field_label = isset($this->fields_by_id[$k]) ? $this->fields_by_id[$k] : $k; if (isset($this->fields[$field_label])) { $order[] = array('column' => $field_label, 'order' => $field_label, 'direction' => $v); } } unset($order[$k]); } $orderby = array(); $user_id = Base_AclCommon::get_user(); foreach ($order as $v) { if ($v['order'][0] != ':' && !isset($this->fields[$v['order']])) { continue; } if ($v['order'][0] == ':') { switch ($v['order']) { case ':id': $orderby[] = ' id ' . $v['direction']; break; case ':Fav': $orderby[] = ' (SELECT COUNT(*) FROM ' . $this->tab . '_favorite WHERE ' . $this->tab . '_id=' . $this->tab_alias . '.id AND user_id=' . $user_id . ') ' . $v['direction']; break; case ':Visited_on': $orderby[] = ' (SELECT MAX(visited_on) FROM ' . $this->tab . '_recent WHERE ' . $this->tab . '_id=' . $this->tab_alias . '.id AND user_id=' . $user_id . ') ' . $v['direction']; break; case ':Edited_on': $orderby[] = ' (CASE WHEN (SELECT MAX(edited_on) FROM ' . $this->tab . '_edit_history WHERE ' . $this->tab . '_id=' . $this->tab_alias . '.id) IS NOT NULL THEN (SELECT MAX(edited_on) FROM ' . $this->tab . '_edit_history WHERE ' . $this->tab . '_id=' . $this->tab_alias . '.id) ELSE ' . $this->tab_alias . '.created_on END) ' . $v['direction']; break; default: $orderby[] = ' ' . substr($v['order'], 1) . ' ' . $v['direction']; } } else { $field_def = $this->get_field_definition($v['order']); $field_sql_id = $this->tab_alias . '.f_' . $field_def['id']; if (isset($field_def['ref_table']) && !$field_def['commondata']) { $tab2 = $field_def['ref_table']; $cols2 = $field_def['ref_field']; $cols2 = explode('|', $cols2); $cols2 = $cols2[0]; $field_id = Utils_RecordBrowserCommon::get_field_id($cols2); $val = '(SELECT rdt.f_' . $field_id . ' FROM ' . $this->tab . '_data_1 AS rd LEFT JOIN ' . $tab2 . '_data_1 AS rdt ON rdt.id=rd.f_' . $field_def['id'] . ' WHERE ' . $this->tab_alias . '.id=rd.id)'; $orderby[] = ' ' . $val . ' ' . $v['direction']; } elseif ($field_def['commondata']) { $sort = $field_def['commondata_order']; $sorted = false; if ($sort == 'position' || $sort == 'value') { $sort_field = $sort == 'position' ? 'position' : 'value'; $parent_id = Utils_CommonDataCommon::get_id($field_def['commondata_array']); if ($parent_id) { $orderby[] = " (SELECT {$sort_field} FROM utils_commondata_tree AS uct WHERE uct.parent_id={$parent_id} AND uct.akey={$field_sql_id}) " . $v['direction']; $sorted = true; } } if ($sorted == false) { // key or if position or value failed $orderby[] = ' ' . $field_sql_id . ' ' . $v['direction']; } } else { if ($field_def['type'] == 'currency') { if (DB::is_mysql()) { $field_sql_id = "CAST({$field_sql_id} as DECIMAL(64,5))"; } elseif (DB::is_postgresql()) { $field_sql_id = "CAST(COALESCE(NULLIF(split_part({$field_sql_id}, '__', 1),''),'0') as DECIMAL)"; } } $orderby[] = ' ' . $field_sql_id . ' ' . $v['direction']; } } } if (!empty($orderby)) { $orderby = ' ORDER BY' . implode(', ', $orderby); } else { $orderby = ''; } return $orderby; }
* * @author Pawel Bukowski <*****@*****.**> * @copyright Copyright © 2015, Telaxus LLC * @license MIT * @version 2.0 * @package epesi-notify * */ define('CID', false); define('READ_ONLY_SESSION', true); require_once '../../../include.php'; ModuleManager::load_modules(); if (!Acl::is_user()) { exit; } $token = Base_NotifyCommon::get_session_token(true); if (!$token) { exit; } DB::Execute('UPDATE base_notify SET telegram=1 WHERE token=%s', array($token)); $domain_name = Base_UserCommon::get_my_user_login(); if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']) { $domain_name .= '-' . $_SERVER['HTTP_HOST']; } else { if (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME']) { $domain_name .= '-' . $_SERVER['SERVER_NAME']; } } $domain_name = preg_replace('/[^a-z0-9\\-\\_]/i', '-', $domain_name); header('Location: https://telegram.me/EpesiBot?' . http_build_query(array('start' => md5(Base_AclCommon::get_user() . '#' . Base_UserCommon::get_my_user_login() . '#' . $token) . '-' . substr($domain_name, 0, 31))));
public static function get_change_subscription_icon_tags($category_name, $id) { $category_id = self::get_category_id($category_name); if (!$category_id) { return; } $last_seen = self::check_if_notified($category_name, $id); load_js('modules/Utils/Watchdog/subscribe.js'); $tag_id = 'watchdog_sub_button_' . $category_name . '_' . $id; $href = ' onclick="utils_watchdog_set_subscribe(' . ($last_seen === null ? 1 : 0) . ',\'' . $category_name . '\',' . $id . ',\'' . $tag_id . '\')" href="javascript:void(0);"'; if ($last_seen === null) { $icon = Base_ThemeCommon::get_template_file('Utils_Watchdog', 'not_watching_small.png'); $tooltip = __('Click to watch this record for changes.'); } else { if ($last_seen === true) { $icon = Base_ThemeCommon::get_template_file('Utils_Watchdog', 'watching_small.png'); $tooltip = __('You are watching this record, click to stop watching this record for changes.'); } else { $icon = Base_ThemeCommon::get_template_file('Utils_Watchdog', 'watching_small_new_events.png'); $ev = self::display_events($category_id, $last_seen, $id); $tooltip = __('You are watching this record, click to stop watching this record for changes.') . ($ev ? '<br>' . __('The following changes were made since the last time you were viewing this record:') . '<br><br>' . $ev['events'] : ''); } } $subscribers = self::get_subscribers($category_name, $id); $my_user = Base_AclCommon::get_user(); if ($subscribers) { $icon_on = ' src="' . Base_ThemeCommon::get_template_file('Utils_Watchdog', 'watching_small.png') . '"'; $icon_off = ' src="' . Base_ThemeCommon::get_template_file('Utils_Watchdog', 'watching_small_new_events.png') . '"'; $other_subscribers = array(); foreach ($subscribers as $subscriber) { if ($subscriber == $my_user) { continue; } if (class_exists('CRM_ContactsCommon')) { $contact = CRM_ContactsCommon::get_user_label($subscriber, true); } else { $contact = Base_UserCommon::get_user_login($subscriber); } $notified = self::user_check_if_notified($subscriber, $category_name, $id); $icon2 = $notified === true ? $icon_on : $icon_off; $other_subscribers[] = '<img style="margin-right:4px;" ' . $icon2 . ' /><a>' . Utils_RecordBrowserCommon::no_wrap($contact) . '</a>'; } if ($other_subscribers) { $tooltip .= '<hr />' . implode('<br>', $other_subscribers); } } $tooltip = Utils_TooltipCommon::open_tag_attrs($tooltip); return '<a ' . $href . ' ' . $tooltip . '><img border="0" src="' . $icon . '"></a>'; }
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 static function process($url, $history_call = false, $refresh = false) { if (MODULE_TIMES) { $time = microtime(true); } $url = str_replace('&', '&', $url); //do we need this if we set arg_separator.output to &? if ($url) { $_POST = array(); parse_str($url, $_POST); if (get_magic_quotes_gpc()) { $_POST = undoMagicQuotes($_POST); } $_GET = $_REQUEST =& $_POST; } ModuleManager::load_modules(); self::check_firstrun(); if ($history_call === '0') { History::clear(); } elseif ($history_call) { History::set_id($history_call); } //on init call methods... $ret = on_init(null, null, null, true); foreach ($ret as $k) { call_user_func_array($k['func'], $k['args']); } $root =& ModuleManager::create_root(); self::go($root); //go somewhere else? $loc = location(null, true); //on exit call methods... $ret = on_exit(null, null, null, true, $loc === false); foreach ($ret as $k) { call_user_func_array($k['func'], $k['args']); } if ($loc !== false) { if (isset($_REQUEST['__action_module__'])) { $loc['__action_module__'] = $_REQUEST['__action_module__']; } //clean up foreach (self::$content as $k => $v) { unset(self::$content[$k]); } foreach (self::$jses as $k => $v) { if ($v[1]) { unset(self::$jses[$k]); } } //go $loc['__location'] = microtime(true); return self::process(http_build_query($loc), false, true); } $debug = ''; if (DEBUG && ($debug_diff = @(include_once 'tools/Diff.php'))) { require_once 'tools/Text/Diff/Renderer/inline.php'; $diff_renderer = new Text_Diff_Renderer_inline(); } //clean up old modules if (isset($_SESSION['client']['__module_content__'])) { $to_cleanup = array_keys($_SESSION['client']['__module_content__']); foreach ($to_cleanup as $k) { $mod = ModuleManager::get_instance($k); if ($mod === null) { $xx = explode('/', $k); $yy = explode('|', $xx[count($xx) - 1]); $mod = $yy[0]; if (is_callable(array($mod . 'Common', 'destroy'))) { call_user_func(array($mod . 'Common', 'destroy'), $k, isset($_SESSION['client']['__module_vars__'][$k]) ? $_SESSION['client']['__module_vars__'][$k] : null); } if (DEBUG) { $debug .= 'Clearing mod vars & module content ' . $k . '<br>'; } unset($_SESSION['client']['__module_vars__'][$k]); unset($_SESSION['client']['__module_content__'][$k]); } } } $reloaded = array(); foreach (self::$content as $k => $v) { $reload = $v['module']->get_reload(); $parent = $v['module']->get_parent_path(); if (DEBUG && REDUCING_TRANSFER) { $debug .= '<hr style="height: 3px; background-color:black">'; $debug .= '<b> Checking ' . $k . ', parent=' . $v['module']->get_parent_path() . '</b><ul>' . '<li>Force - ' . (isset($reload) ? print_r($reload, true) : 'not set') . '</li>' . '<li>First display - ' . (isset($_SESSION['client']['__module_content__'][$k]) ? 'no</li>' . '<li>Content changed - ' . ($_SESSION['client']['__module_content__'][$k]['value'] !== $v['value'] ? 'yes' : 'no') . '</li>' . '<li>JS changed - ' . ($_SESSION['client']['__module_content__'][$k]['js'] !== $v['js'] ? 'yes' : 'no') : 'yes') . '</li>' . '<li>Parent reloaded - ' . (isset($reloaded[$parent]) ? 'yes' : 'no') . '</li>' . '<li>History call - ' . ($history_call ? 'yes' : 'no') . '</li>' . '</ul>'; } if (!REDUCING_TRANSFER || (!isset($reload) && (!isset($_SESSION['client']['__module_content__'][$k]) || $_SESSION['client']['__module_content__'][$k]['value'] !== $v['value'] || $_SESSION['client']['__module_content__'][$k]['js'] !== $v['js']) || $history_call || $reload == true || isset($reloaded[$parent]))) { //force reload or parent reloaded if (DEBUG && isset($_SESSION['client']['__module_content__'])) { $debug .= '<b>Reloading: ' . (isset($v['span']) ? '; span=' . $v['span'] . ',' : '') . ' triggered=' . ($reload == true ? 'force' : 'auto') . ', </b><hr><b>New value:</b><br><pre>' . htmlspecialchars($v['value']) . '</pre>' . (isset($_SESSION['client']['__module_content__'][$k]['value']) ? '<hr><b>Old value:</b><br><pre>' . htmlspecialchars($_SESSION['client']['__module_content__'][$k]['value']) . '</pre>' : ''); if ($debug_diff && isset($_SESSION['client']['__module_content__'][$k]['value'])) { $xxx = new Text_Diff(explode("\n", $_SESSION['client']['__module_content__'][$k]['value']), explode("\n", $v['value'])); $debug .= '<hr><b>Diff:</b><br><pre>' . $diff_renderer->render($xxx) . '</pre>'; } $debug .= '<hr style="height: 5px; background-color:black">'; } if (isset($v['span'])) { self::text($v['value'], $v['span']); } if ($v['js']) { self::js(join(";", $v['js'])); } if (REDUCING_TRANSFER) { $_SESSION['client']['__module_content__'][$k]['value'] = $v['value']; $_SESSION['client']['__module_content__'][$k]['js'] = $v['js']; } $_SESSION['client']['__module_content__'][$k]['parent'] = $parent; $reloaded[$k] = true; if (method_exists($v['module'], 'reloaded')) { $v['module']->reloaded(); } } } foreach ($_SESSION['client']['__module_content__'] as $k => $v) { if (!array_key_exists($k, self::$content) && isset($reloaded[$v['parent']])) { if (DEBUG) { $debug .= 'Reloading missing ' . $k . '<hr>'; } if (isset($v['span'])) { self::text($v['value'], $v['span']); } if (isset($v['js']) && $v['js']) { self::js(join(";", $v['js'])); } $reloaded[$k] = true; } } if (DEBUG) { $debug .= 'vars ' . CID . ': ' . print_r($_SESSION['client']['__module_vars__'], true) . '<br>'; $debug .= 'user='******'<br>'; if (isset($_REQUEST['__action_module__'])) { $debug .= 'action module=' . $_REQUEST['__action_module__'] . '<br>'; } } $debug .= self::debug(); if (MODULE_TIMES) { foreach (self::$content as $k => $v) { $style = 'color:red;font-weight:bold'; if ($v['time'] < 0.5) { $style = 'color:orange;font-weight:bold'; } if ($v['time'] < 0.05) { $style = 'color:green;font-weight:bold'; } $debug .= 'Time of loading module <b>' . $k . '</b>: <i>' . '<span style="' . $style . ';">' . number_format($v['time'], 4) . '</span>' . '</i><br>'; } $debug .= 'Page renderered in ' . (microtime(true) - $time) . 's<hr>'; } if (SQL_TIMES) { $debug .= '<font size="+1">QUERIES</font><br>'; $queries = DB::GetQueries(); $sum = 0; $qty = 0; foreach ($queries as $kk => $q) { $style = 'color:red;font-weight:bold'; if ($q['time'] < 0.5) { $style = 'color:orange;font-weight:bold'; } if ($q['time'] < 0.05) { $style = 'color:green'; } for ($kkk = 0; $kkk < $kk; $kkk++) { if ($queries[$kkk]['args'] == $q['args']) { $style .= ';text-decoration:underline'; } } $debug .= '<span style="' . $style . ';">' . '<b>' . $q['func'] . '</b> ' . htmlspecialchars(var_export($q['args'], true)) . ' <i><b>' . number_format($q['time'], 4) . '</b></i>' . (isset($q['caller']) ? ', ' . $q['caller'] : '') . '<br>' . '</span>'; $sum += $q['time']; $qty++; } $debug .= '<b>Number of queries:</b> ' . $qty . '<br>'; $debug .= '<b>Queries times:</b> ' . $sum . '<br>'; } if (!isset($_SESSION['client']['custom_debug']) || $debug != $_SESSION['client']['custom_debug']) { self::text($debug, 'debug'); if ($debug) { Epesi::js("\$('debug_content').style.display='block';"); } $_SESSION['client']['custom_debug'] = $debug; } if (!$history_call && !History::soft_call()) { History::set(); } if (!$history_call) { self::js('Epesi.history_add(' . History::get_id() . ')'); } self::send_output(); }
private function get_values($id, $mod) { if (!isset(self::$settings_cache)) { self::$settings_cache = array('default' => array(), 'user' => array()); $ret = DB::Execute('SELECT applet_id,name,value FROM base_dashboard_default_settings'); while ($row = $ret->FetchRow()) { self::$settings_cache['default'][$row['applet_id']][] = $row; } self::$settings_cache['user'] = array(); if (Base_AclCommon::is_user()) { $ret = DB::Execute('SELECT s.applet_id,s.name,s.value FROM base_dashboard_settings s INNER JOIN base_dashboard_applets a ON a.id=s.applet_id WHERE a.user_login_id=%d', array(Base_AclCommon::get_user())); while ($row = $ret->FetchRow()) { self::$settings_cache['user'][$row['applet_id']][] = $row; } } } if ($this->get_module_variable('default')) { $c = self::$settings_cache['default']; } else { $c = self::$settings_cache['user']; } if (!isset($c[$id])) { $c = array(); } else { $c = $c[$id]; } $variables = $this->get_default_values($mod); foreach ($c as $v) { $variables[$v['name']] = $v['value']; } return $variables; }
public function user_actions($r, $gb_row) { static $admin_levels = false; static $my_level = false; if ($admin_levels === false) { $admin_levels = DB::GetAssoc('SELECT id,admin FROM user_login'); } if ($my_level === false) { $my_level = isset($admin_levels[Base_AclCommon::get_user()]) ? $admin_levels[Base_AclCommon::get_user()] : 0; } $mod = 'Base_User_Administrator'; $log_as_user = Base_AdminCommon::get_access($mod, 'log_as_user'); $log_as_admin = Base_AdminCommon::get_access($mod, 'log_as_admin'); $user_level = isset($admin_levels[$r['login']]) ? $admin_levels[$r['login']] : 0; // 2 is superadmin, 1 admin, 0 user if ($my_level == 2 || $my_level == 1 && ($user_level == 0 && $log_as_user || $user_level == 1 && $log_as_admin)) { // contact is admin and I can login as admin if (Base_UserCommon::is_active($r['login'])) { $gb_row->add_action($this->create_callback_href(array($this, 'change_user_active_state'), array($r['login'], false)), 'Deactivate user', null, Base_ThemeCommon::get_template_file('Utils_GenericBrowser', 'active-on.png')); $gb_row->add_action(Module::create_href(array('log_as_user' => $r['login'])), 'Log as user', null, Base_ThemeCommon::get_template_file('Utils_GenericBrowser', 'restore.png')); // action! if (isset($_REQUEST['log_as_user']) && $_REQUEST['log_as_user'] == $r['login']) { Acl::set_user($r['login'], true); Epesi::redirect(); return; } } else { $gb_row->add_action($this->create_callback_href(array($this, 'change_user_active_state'), array($r['login'], true)), 'Activate user', null, Base_ThemeCommon::get_template_file('Utils_GenericBrowser', 'active-off.png')); } } }
public static function user_settings() { $ret = array(array('name' => null, 'label' => __('General'), 'type' => 'header'), array('name' => 'one_cache', 'label' => __('Show each notification'), 'type' => 'select', 'values' => array(0 => __('multiple times every login and on each device'), 1 => __('only once and only on one device')), 'default' => 1), array('name' => null, 'label' => __('Browser Notification') . ' - ' . __('General'), 'type' => 'header'), array('name' => 'general_timeout', 'reload' => 1, 'label' => __('Close Message Timeout'), 'type' => 'select', 'values' => Utils_CommonDataCommon::get_translated_array('Base_Notify/Timeout', true), 'default' => 0), array('name' => 'general_group', 'label' => __('Group Similar Notifications'), 'type' => 'checkbox', 'default' => 1), array('name' => 'browser_settings', 'label' => '', 'type' => 'static', 'values' => '<a class="button" onClick="Base_Notify.notify (\'Notification\', {body: \'enabled\', icon: \'' . self::get_icon('Base_Notify') . '\'}, true);">' . __('Browser Settings') . '</a>'), array('name' => null, 'label' => __('Browser Notification') . ' - ' . __('Module Specific Timeout'), 'type' => 'header')); $modules = ModuleManager::check_common_methods('notification'); foreach ($modules as $module) { $label = self::get_module_caption($module); $ret = array_merge($ret, array(array('name' => $module . '_timeout', 'label' => $label, 'type' => 'select', 'values' => array(-2 => _M('Use general setting')) + Utils_CommonDataCommon::get_translated_array('Base_Notify/Timeout', true), 'default' => -2))); } $ret[] = array('name' => null, 'label' => __('Telegram Notification'), 'type' => 'header'); $telegram = DB::GetOne('SELECT 1 FROM base_notify WHERE single_cache_uid=%d AND telegram=1', array(Base_AclCommon::get_user())); if ($telegram && isset($_GET['telegram'])) { $telegram = 0; DB::Execute('UPDATE base_notify SET telegram=0 WHERE single_cache_uid=%d', array(Base_AclCommon::get_user())); } $ret[] = array('name' => 'telegram_url', 'label' => '<a class="button" href="modules/Base/Notify/telegram.php" target="_blank">' . ($telegram ? __('Connect to another telegram account') : __('Connect to your telegram account')) . '</a>', 'type' => 'static', 'values' => $telegram ? '<a class="button" ' . Module::create_href(array('telegram' => 1)) . '>' . __('Disconnect telegram') . '</a>' : ''); return array(__('Notifications') => $ret); }
public static function get_access($tab, $action, $record = null, $return_crits = false, $return_in_array = false) { if (!$return_crits && self::$admin_access && Base_AclCommon::i_am_admin()) { $ret = true; } elseif (isset($record[':active']) && !$record[':active'] && ($action == 'edit' || $action == 'delete' || $action == 'clone')) { return false; } else { static $cache = array(); $cache_key = "{$tab}__USER_" . Base_AclCommon::get_user(); if (!isset($cache[$cache_key])) { self::check_table_name($tab); $user_clearance = Base_AclCommon::get_clearance(); $r = DB::Execute('SELECT * FROM ' . $tab . '_access AS acs WHERE NOT EXISTS (SELECT * FROM ' . $tab . '_access_clearance WHERE rule_id=acs.id AND ' . implode(' AND ', array_fill(0, count($user_clearance), 'clearance!=%s')) . ')', array_values($user_clearance)); $crits = array('view' => null, 'edit' => null, 'delete' => null, 'add' => null, 'print' => null, 'export' => null, 'selection' => null); $crits_raw = array('view' => array(), 'edit' => array(), 'delete' => array(), 'add' => array(), 'print' => array(), 'export' => array(), 'selection' => array()); $fields = array(); while ($row = $r->FetchRow()) { $fields[$row['id']] = array(); $new = self::parse_access_crits($row['crits']); $crits_raw[$row['action']][$row['id']] = $new; // if new or existing crit is empty, then we have access to all records if ($new->is_empty()) { $crits[$row['action']] = $new; } if ($crits[$row['action']] instanceof Utils_RecordBrowser_Crits && $crits[$row['action']]->is_empty()) { continue; } $crits[$row['action']] = self::merge_crits($crits[$row['action']], $new, true); } $r = DB::Execute('SELECT * FROM ' . $tab . '_access_fields'); while ($row = $r->FetchRow()) { $fields[$row['rule_id']][$row['block_field']] = $row['block_field']; } $cache[$cache_key]['crits'] = $crits; $cache[$cache_key]['crits_raw'] = $crits_raw; $cache[$cache_key]['fields'] = $fields; } else { $crits = $cache[$cache_key]['crits']; $crits_raw = $cache[$cache_key]['crits_raw']; $fields = $cache[$cache_key]['fields']; } if ($return_crits) { if ($action == 'browse') { $action = 'view'; } if ($return_in_array) { return $crits_raw[$action]; } return $crits[$action]; } if ($action == 'browse') { return $crits['view'] !== null ? true : false; } $ret = false; $blocked_fields = array(); if ($action != 'browse' && $action != 'clone') { foreach ($crits_raw[$action] as $rule_id => $c) { if ($record != null && !self::check_record_against_crits($tab, $record, $c)) { continue; } if (!$ret) { $ret = true; $blocked_fields = $fields[$rule_id]; } else { foreach ($blocked_fields as $f => $v) { if (!isset($fields[$rule_id][$f])) { unset($blocked_fields[$f]); } } } } } } if ($action !== 'browse' && $action !== 'delete') { self::init($tab); if ($ret === false) { return false; } if ($ret === true) { $ret = array(); } foreach (self::$table_rows as $field => $args) { if (!isset($ret[$args['id']])) { if (isset($blocked_fields[$args['id']])) { $ret[$args['id']] = false; } else { $ret[$args['id']] = true; } } } } return $ret; }
/** * Create new watchdog event for record if $group denotes record. * * @param string $group <Recordset>/<Id> * @param string $action Action string * @param int $note_id Note id * * @return bool True if events has been created, false otherwise */ public static function new_watchdog_event($group, $action, $note_id) { $param = explode('/', $group); if (count($param)==2 && preg_match('/^[1-9][0-9]*$/', $param[1])) { Utils_WatchdogCommon::new_event($param[0], $param[1], implode('_', array('N', $action, $note_id, time(), Base_AclCommon::get_user()))); return true; } return false; }
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; } else { $table = 'base_dashboard_applets'; $val = $user; } foreach ($x['ab_item'] as $pos => $id) {
public static function get_my_user_label($nolink = false) { return self::get_user_label(Base_AclCommon::get_user(), $nolink); }