Ejemplo n.º 1
0
 private function auth($user, $pass)
 {
     $error = '';
     $t = Variable::get('host_ban_time');
     if ($t > 0) {
         $fails = DB::GetOne('SELECT count(*) FROM user_login_ban WHERE failed_on>%d AND from_addr=%s', array(time() - $t, $_SERVER['REMOTE_ADDR']));
         if ($fails >= 3) {
             $error = 'Host banned.';
         }
     }
     if ($error === '') {
         $ret = Base_User_LoginCommon::check_login($user, $pass);
         if (!$ret) {
             $error = 'Login failed.';
             if ($t > 0) {
                 DB::Execute('DELETE FROM user_login_ban WHERE failed_on<=%d', array(time() - $t));
                 DB::Execute('INSERT INTO user_login_ban(failed_on,from_addr) VALUES(%d,%s)', array(time(), $_SERVER['REMOTE_ADDR']));
                 $fails = DB::GetOne('SELECT count(*) FROM user_login_ban WHERE failed_on>%d AND from_addr=%s', array(time() - $t, $_SERVER['REMOTE_ADDR']));
                 if ($fails >= 3) {
                     $error .= ' Host banned.';
                 }
             }
         } else {
             $uid = Base_UserCommon::get_user_id($user);
             Acl::set_user($uid, true);
         }
     }
     return $error;
 }
Ejemplo n.º 2
0
 public function applet($v, $o)
 {
     $all = Tools_WhoIsOnlineCommon::get();
     $map = array();
     foreach ($all as $id => $x) {
         $c = CRM_ContactsCommon::get_contact_by_user_id(Base_UserCommon::get_user_id($x));
         if ($c) {
             $all[$id] = CRM_ContactsCommon::contact_format_no_company($c);
             $map[$id] = $c['last_name'];
         } else {
             $map[$id] = $x;
         }
     }
     asort($map);
     $c = count($all);
     if ($c == 1) {
         $o['title'] = __('%d user online', array($c));
     } else {
         $o['title'] = __('%d users online', array($c));
     }
     print '<ul>';
     foreach ($map as $id => $x) {
         print '<li>' . $all[$id] . '</li>';
     }
     print '</ul>';
 }
Ejemplo n.º 3
0
 public static function user_label($id)
 {
     $label = Base_UserCommon::get_user_login($id);
     $c = Utils_RecordBrowserCommon::get_id('contact', 'login', $id);
     if ($c) {
         $label = CRM_ContactsCommon::contact_format_no_company($c, true) . ' [' . $label . ']';
     }
     return $label;
 }
Ejemplo n.º 4
0
 public static function generate_file($key, $message = null)
 {
     $user = Base_UserCommon::get_my_user_login();
     $date = date('Y-m-d H:i:s');
     $str = "<?php\n";
     $str .= "// by {$user} on {$date}\n";
     $str .= '$maintenance_mode_key = ' . var_export($key, true);
     $str .= ";\n";
     $str .= '$maintenance_mode_message = ' . var_export($message, true);
     $str .= ";\n";
     file_put_contents(self::get_file(), $str);
 }
Ejemplo n.º 5
0
 public static function user_settings($just_retrieve = false)
 {
     if (!Variable::get('allow_lang_change')) {
         return null;
     }
     if (DEMO_MODE && Base_UserCommon::get_my_user_login() == 'admin') {
         $langs = array('en' => 'en');
     } else {
         $langs = Base_LangCommon::get_installed_langs();
     }
     if ($just_retrieve) {
         $group = $label1 = $label2 = '';
     } else {
         $group = __('Regional Settings');
         $label1 = __('Language');
         $label2 = __('Language you want to use');
     }
     return array($group => array(array('type' => 'header', 'label' => $label1, 'name' => null), array('name' => 'language', 'label' => $label2, 'type' => 'select', 'values' => $langs, 'default' => Variable::get('default_lang'))));
 }
Ejemplo n.º 6
0
 static function form()
 {
     try {
         $anonymous = Variable::get('anonymous_setup');
     } catch (NoSuchVariableException $e) {
         $anonymous = true;
     }
     if (!Base_AclCommon::is_user() && Base_User_LoginCommon::is_banned()) {
         return self::t('You have exceeded the number of allowed login attempts.');
     }
     require_once 'modules/Libs/QuickForm/requires.php';
     if (!Base_AclCommon::is_user() && !$anonymous) {
         Base_User_LoginCommon::autologin();
     }
     if (!Base_AclCommon::is_user() && !$anonymous) {
         $get = count($_GET) ? '?' . http_build_query($_GET) : '';
         $form = new HTML_QuickForm('loginform', 'post', $_SERVER['PHP_SELF'] . $get);
         $form->setRequiredNote('<span style="font-size:80%; color:#ff0000;">*</span><span style="font-size:80%;">' . self::t('denotes required field') . '</span>');
         $form->addElement('text', 'username', self::t('Username'));
         $form->addRule('username', 'Field required', 'required');
         $form->addElement('password', 'password', self::t('Password'));
         $form->addRule('password', 'Field required', 'required');
         // register and add a rule to check if user is banned
         $form->registerRule('check_user_banned', 'callback', 'rule_login_banned', 'Base_User_LoginCommon');
         $form->addRule('username', self::t('You have exceeded the number of allowed login attempts.'), 'check_user_banned');
         // register and add a rule to check if user and password exists
         $form->registerRule('check_login', 'callback', 'submit_login', 'Base_User_LoginCommon');
         $form->addRule(array('username', 'password'), self::t('Login or password incorrect'), 'check_login', $form);
         $form->addElement('submit', null, self::t('Login'));
         if ($form->validate()) {
             $user = $form->exportValue('username');
             Base_AclCommon::set_user(Base_UserCommon::get_user_id($user), true);
             // redirect below is used to better browser refresh behavior.
             header('Location: ' . $_SERVER['REQUEST_URI']);
         } else {
             return "<center>" . $form->toHtml() . "</center>";
         }
     }
 }
Ejemplo n.º 7
0
 public function history($uid = null)
 {
     $th = $this->init_module(Base_Theme::module_name());
     $th->assign('header', __('Shoutbox History'));
     $qf = $this->init_module(Libs_QuickForm::module_name());
     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) WHERE l.active=1 ORDER BY name');
     } else {
         $emps = DB::GetAssoc('SELECT id,login FROM user_login WHERE active=1 ORDER BY login');
     }
     $qf->addElement('select', 'user', __('User'), array('all' => '[' . __('All') . ']') + $emps);
     $qf->addElement('datepicker', 'from_date', __('From'));
     $qf->addElement('datepicker', 'to_date', __('To'));
     $qf->addElement('text', 'search', __('Search for'));
     $qf->addElement('submit', 'submit_button', __('Filter'));
     $to_date =& $this->get_module_variable('to_date');
     $from_date =& $this->get_module_variable('from_date');
     $user =& $this->get_module_variable('to', "all");
     $qf->setDefaults(array('from_date' => $from_date, 'to_date' => $to_date, 'user' => $uid));
     //if submited
     if ($qf->validate()) {
         $from_date = $qf->exportValue('from_date');
         $to_date = $qf->exportValue('to_date');
         $user = $qf->exportValue('user');
         $search_word = $qf->exportValue('search');
     }
     $qf->assign_theme('form', $th);
     $uid = is_numeric($user) ? $user : null;
     $date_where = '';
     if ($from_date) {
         $date_where .= 'AND posted_on>=' . DB::DBDate($from_date);
     }
     if ($to_date) {
         $date_where .= 'AND posted_on<=' . DB::DBDate($to_date);
     }
     if (isset($search_word) && $search_word) {
         $search_word = explode(' ', $search_word);
         foreach ($search_word as $word) {
             if ($word) {
                 $date_where .= ' AND message ' . DB::like() . ' ' . DB::Concat(DB::qstr('%'), DB::qstr(htmlspecialchars($word, ENT_QUOTES, 'UTF-8')), DB::qstr('%'));
             }
         }
     }
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'shoutbox_history');
     $gb->set_table_columns(array(array('name' => __('From'), 'width' => 10), array('name' => __('To'), 'width' => 10), array('name' => __('Message'), 'width' => 64), array('name' => __('Date'), 'width' => 16)));
     // $gb->set_default_order(array(__('Date')=>'DESC'));
     $myid = Base_AclCommon::get_user();
     $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 . ') OR (to_user_login_id is null AND base_user_login_id=' . $uid . ')' : 'to_user_login_id is null OR to_user_login_id=' . $myid . ' OR base_user_login_id=' . $myid) . ')' . $date_where;
     $query = 'SELECT base_user_login_id, to_user_login_id, message, posted_on FROM apps_shoutbox_messages WHERE ' . $where . ' ORDER BY posted_on DESC';
     $query_qty = 'SELECT count(id) FROM apps_shoutbox_messages WHERE ' . $where;
     $ret = $gb->query_order_limit($query, $query_qty);
     if ($ret) {
         while ($row = $ret->FetchRow()) {
             $ulogin = Base_UserCommon::get_user_label($row['base_user_login_id']);
             if ($row['to_user_login_id'] !== null) {
                 $tologin = Base_UserCommon::get_user_label($row['to_user_login_id']);
             } else {
                 $tologin = '******' . __('All') . ']';
             }
             $gb->add_row('<span class="author">' . $ulogin . '</span>', '<span class="author">' . $tologin . '</span>', array('value' => Utils_BBCodeCommon::parse($row['message']), 'overflow_box' => false), Base_RegionalSettingsCommon::time2reg($row['posted_on']));
         }
     }
     $gb->set_inline_display(true);
     $th->assign('messages', $this->get_html_of_module($gb));
     $th->display();
     return true;
 }
Ejemplo n.º 8
0
    public static function display_note($row, $nolink = false, $a=null,$view=false) {
        $inline_img = '';
        $link_href = '';
        $link_img = '';
        $icon = '';
        $crypted = Utils_RecordBrowserCommon::get_value('utils_attachment',$row['id'],'crypted');
        if(!$crypted || isset($_SESSION['client']['cp'.$row['id']])) {
            $files = DB::GetAll('SELECT id, created_by, created_on, original, (SELECT count(*) FROM utils_attachment_download uad WHERE uaf.id=uad.attach_file_id) as downloads FROM utils_attachment_file uaf WHERE uaf.attach_id=%d AND uaf.deleted=0', array($row['id']));
            foreach ($files as $f) {
                $f_filename = DATA_DIR.'/Utils_Attachment/'.$row['id'].'/'.$f['id'];
                if(file_exists($f_filename)) {
                    $filename = $f['original'];
                    $filetooltip = __('Filename: %s',array($filename)).'<br>'.__('File size: %s',array(filesize_hr($f_filename))).'<hr>'.
                        __('Last uploaded by %s', array(Base_UserCommon::get_user_label($f['created_by'], true))).'<br/>'.
                        __('On: %s',array(Base_RegionalSettingsCommon::time2reg($f['created_on']))).'<br/>'.
                        __('Number of downloads: %d',array($f['downloads']));
                    $view_link = '';
                    $lb = array();
                    $lb['aid'] = $row['id'];
                    $lb['crypted'] = $crypted;
                    $lb['original'] = $f['original'];
                    $lb['id'] = $f['id'];
                    $link_href = Utils_TooltipCommon::open_tag_attrs($filetooltip).' '.self::get_file_leightbox($lb,$view_link);
                    $link_img = Base_ThemeCommon::get_template_file('Utils_Attachment','z-attach.png');
                    if(Utils_AttachmentCommon::is_image($filename) && $view_link)
                        $inline_img .= '<hr><a href="'.$view_link.'" target="_blank"><img src="'.$view_link.'" style="max-width:700px" /></a><br>';
                } else {
                    $filename = __('Missing file: %s',array($f_filename));
                    $link_href = Utils_TooltipCommon::open_tag_attrs($filename);
                    $link_img = Base_ThemeCommon::get_template_file('Utils_Attachment','z-attach-off.png');
                }
                if ($link_href)
                    $icon .= '<div class="file_link"><a '.$link_href.'><img src="'.$link_img.'"><span class="file_name">'.$filename.'</span></a></div>';
            }
        }

        if($crypted) {
            $text = false;
            if(isset($_SESSION['client']['cp'.$row['id']])) {
                $note_pass = $_SESSION['client']['cp'.$row['id']];
                $decoded = Utils_AttachmentCommon::decrypt($row['note'],$note_pass);
                if($decoded!==false) {
                    $text = $decoded;
                    Utils_WatchdogCommon::notified('utils_attachment', $row['id']); // notified only when decrypted
                }
            }
            if($text===false) {
                $text = '<div id="note_value_'.$row['id'].'"><a href="javascript:void(0);" onclick="utils_attachment_password(\''.Epesi::escapeJS(__('Password').':').'\',\''.Epesi::escapeJS(__('OK')).'\','.$row['id'].')" style="color:red">'.__('Note encrypted').'</a></div>';
                $icon = '';
                $files = array();
            } else {
                $text = Utils_BBCodeCommon::parse($text);
            }
        } else {
            $text = $row['note'];
            $text = Utils_BBCodeCommon::parse($text);
            // mark as read all 'browsed' records
            foreach (self::$mark_as_read as $note_id) {
                Utils_WatchdogCommon::notified('utils_attachment', $note_id);
            }
            self::$mark_as_read = array();
        }

        $text = (!$view?'<b style="float:left;margin-right:30px;">'.$row['title'].'</b> ':'').$text.$icon.$inline_img;
        if($row['sticky']) $text = '<img src="'.Base_ThemeCommon::get_template_file('Utils_Attachment','sticky.png').'" hspace=3 align="left"> '.$text;

        return $text;
    }
Ejemplo n.º 9
0
    public static function prepare_header(& $tcpdf, $title='', $subject='', $printed_by=true, $logo_filename=null, $l = array()) {
        if ($title!==null) {
            if ($logo_filename===null) $logo_filename = Libs_TCPDFCommon::get_logo_filename();
            if ($logo_filename!==false && !file_exists($logo_filename)) {
                $logo_filename = Base_ThemeCommon::get_template_file('Libs/TCPDF','logo-small.png');
            }
            $margins = $tcpdf->getMargins();
            if($logo_filename) {
                $logo_size = getimagesize($logo_filename);
                $logo_height = $logo_size[1] * PDF_HEADER_LOGO_WIDTH / $logo_size[0];
            } else {
                $logo_height = 0;
            }
            $tcpdf->SetHeaderMargin(10);
            $tcpdf->SetTopMargin($logo_height + $margins['top']);
            $tcpdf->SetHeaderData($logo_filename, $logo_filename?PDF_HEADER_LOGO_WIDTH:0, $title, $subject);
        } else {
            $tcpdf->setPrintHeader(false);
        }

        //set some language-dependent strings
        $l['a_meta_charset'] = "UTF-8";
        $l['a_meta_dir'] = "ltr";
        $l['a_meta_language'] = "pl";

        $who = null;
        if (ModuleManager::is_installed('CRM/Contacts') >= 0) {
            $who = CRM_ContactsCommon::get_contact_by_user_id(Acl::get_user());
        }
        if ($who!==null) $who = $who['last_name'].' '.$who['first_name'];
        else $who= Base_UserCommon::get_user_login(Acl::get_user());
        $when = date('Y-m-d H:i:s');
        if (!isset($l['w_page'])) {
			$l['w_page'] = '';
			if ($printed_by) $l['w_page'] .= __('Printed with %s by %s, on %s, ',array('EPESI (http://epe.si)',$who,$when));
			$l['w_page'] .= __('Page');
		}
        $tcpdf->setLanguageArray($l);

        self::SetFont($tcpdf, self::$default_font, '', 9);
    }
Ejemplo n.º 10
0
 public static function watchdog_label($tab, $cat, $rid, $events = array(), $label = null, $details = true)
 {
     $ret = array('category' => $cat);
     if ($rid !== null) {
         $r = self::get_record($tab, $rid);
         if ($r === null) {
             return null;
         }
         if (!self::get_access($tab, 'view', $r)) {
             return null;
         }
         if (is_array($label)) {
             $label = Utils_RecordBrowserCommon::record_link_open_tag_r($tab, $r) . call_user_func($label, $r, true) . Utils_RecordBrowserCommon::record_link_close_tag();
             $label = self::create_default_record_tooltip_ajax($label, $tab, $rid);
         } elseif ($label) {
             $label = Utils_RecordBrowserCommon::create_linked_label_r($tab, $label, $r);
             $label = self::create_default_record_tooltip_ajax($label, $tab, $rid);
         } else {
             $label = Utils_RecordBrowserCommon::create_default_linked_label($tab, $rid, false, false);
         }
         $ret['title'] = $label;
         $ret['view_href'] = Utils_RecordBrowserCommon::create_record_href($tab, $rid);
         $events_display = array();
         $events = array_reverse($events);
         $other_events = array();
         $header = false;
         foreach ($events as $v) {
             if (count($events_display) > 20) {
                 $other_events[__('And more...')] = 1;
                 break;
             }
             $param = explode('_', $v);
             switch ($param[0]) {
                 case 'C':
                     $what = 'Created';
                     $event_display = array('who' => Base_UserCommon::get_user_label($r['created_by'], true), 'when' => Base_RegionalSettingsCommon::time2reg($r['created_on']), 'what' => _V($what));
                     break;
                 case 'D':
                     if (!isset($what)) {
                         $what = 'Deleted';
                     }
                 case 'R':
                     if (!isset($what)) {
                         $what = 'Restored';
                     }
                     if (!isset($param[1])) {
                         $event_display = array('who' => '', 'when' => '', 'what' => _V($what));
                         break;
                     }
                 case 'E':
                     $event_display = self::get_edit_details_modify_record($tab, $r['id'], $param[1], $details);
                     if (isset($event_display['what']) && !empty($event_display['what'])) {
                         $header = true;
                     }
                     break;
                 case 'N':
                     $event_display = false;
                     switch ($param[1]) {
                         case '+':
                             $action = __('Note linked');
                             break;
                         case '-':
                             $action = __('Note unlinked');
                             break;
                         default:
                             if (!isset($other_events[$param[1]])) {
                                 $other_events[$param[1]] = 0;
                             }
                             $other_events[$param[1]]++;
                             $event_display = null;
                             break;
                     }
                     if ($event_display === false) {
                         $date = isset($param[3]) ? Base_RegionalSettingsCommon::time2reg($param[3]) : '';
                         $who = isset($param[4]) ? Base_UserCommon::get_user_label($param[4], true) : '';
                         $action .= ' - ' . self::create_default_linked_label('utils_attachment', $param[2]);
                         $event_display = array('what' => $action, 'who' => $who, 'when' => $date);
                     }
                     break;
                 default:
                     $event_display = array('what' => _V($v));
             }
             if ($event_display) {
                 $events_display[] = $event_display;
             }
         }
         foreach ($other_events as $k => $v) {
             $events_display[] = array('what' => _V($k) . ($v > 1 ? ' [' . $v . ']' : ''));
         }
         if ($events_display) {
             $theme = Base_ThemeCommon::init_smarty();
             if ($header) {
                 $theme->assign('header', array(__('Field'), __('Old value'), __('New value')));
             }
             $theme->assign('events', $events_display);
             $tpl = 'changes_list';
             if (Utils_WatchdogCommon::email_mode()) {
                 $record_data = self::get_record_tooltip_data($tab, $rid);
                 $theme->assign('record', $record_data);
                 $tpl = 'changes_list_email';
             }
             ob_start();
             Base_ThemeCommon::display_smarty($theme, 'Utils_RecordBrowser', $tpl);
             $output = ob_get_clean();
             $ret['events'] = $output;
         } else {
             // if we've generated empty events for certain record, then
             // it's possible that some of the fields, that have changed,
             // are hidden so we have to check if there are any other events
             // If all events are the same and output is empty we can safely
             // mark all as notified.
             $all_events = Utils_WatchdogCommon::check_if_notified($tab, $rid);
             if (count($all_events) == count($events)) {
                 Utils_WatchdogCommon::notified($tab, $rid);
             }
             $ret = null;
         }
     }
     return $ret;
 }
Ejemplo n.º 11
0
 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>';
 }
Ejemplo n.º 12
0
 public function done($d)
 {
     @set_time_limit(0);
     if (count($this->ini) == 1) {
         $pkgs = reset($this->ini);
         $pkgs = $pkgs['package'];
     } else {
         $pkgs = isset($this->ini[$d[0]['setup_type']]['package']) ? $this->ini[$d[0]['setup_type']]['package'] : array();
     }
     $t = microtime(true);
     error_log(date('Y-m-d H:i:s') . ': installing "Base" ...' . "\n", 3, DATA_DIR . '/firstrun.log');
     if (!ModuleManager::install('Base', null, false)) {
         print 'Unable to install Base module pack.';
         return false;
     }
     error_log(date('Y-m-d H:i:s') . ': done (' . (microtime(true) - $t) . "s).\n", 3, DATA_DIR . '/firstrun.log');
     $t = microtime(true);
     error_log(date('Y-m-d H:i:s') . ': creating admin user ...' . "\n", 3, DATA_DIR . '/firstrun.log');
     if (!Base_UserCommon::add_user($d['simple_user']['login'])) {
         print 'Unable to create user';
         return false;
     }
     $user_id = Base_UserCommon::get_user_id($d['simple_user']['login']);
     if ($user_id === false) {
         print 'Unable to get admin user id';
         return false;
     }
     if (!DB::Execute('INSERT INTO user_password(user_login_id,password,mail) VALUES(%d,%s, %s)', array($user_id, md5($d['simple_user']['pass']), $d['simple_user']['mail']))) {
         print 'Unable to set user password';
         return false;
     }
     if (!Base_UserCommon::change_admin($user_id, 2)) {
         print 'Unable to update admin account data (groups).';
         return false;
     }
     Acl::set_user($user_id, true);
     Variable::set('anonymous_setup', false);
     error_log(date('Y-m-d H:i:s') . ': done (' . (microtime(true) - $t) . "s).\n", 3, DATA_DIR . '/firstrun.log');
     $t = microtime(true);
     error_log(date('Y-m-d H:i:s') . ': setting mail server ...' . "\n", 3, DATA_DIR . '/firstrun.log');
     $method = $d['simple_mail']['mail_method'];
     Variable::set('mail_method', $method);
     Variable::set('mail_from_addr', $d['simple_user']['mail']);
     Variable::set('mail_from_name', $d['simple_user']['login']);
     if ($method == 'smtp') {
         Variable::set('mail_host', $d['simple_mail_smtp']['mail_host']);
         if ($d['simple_mail_smtp']['mail_user'] !== '' && $d['simple_mail_smtp']['mail_user'] !== '') {
             $auth = true;
         } else {
             $auth = false;
         }
         Variable::set('mail_auth', $auth);
         if ($auth) {
             Variable::set('mail_user', $d['simple_mail_smtp']['mail_user']);
             Variable::set('mail_password', $d['simple_mail_smtp']['mail_password']);
         }
     }
     error_log(date('Y-m-d H:i:s') . ': done (' . (microtime(true) - $t) . "s).\n", 3, DATA_DIR . '/firstrun.log');
     $t = microtime(true);
     error_log(date('Y-m-d H:i:s') . ': Installing modules ...' . "\n", 3, DATA_DIR . '/firstrun.log');
     foreach ($pkgs as $p) {
         if (!is_dir('modules/' . $p)) {
             continue;
         }
         $t2 = microtime(true);
         error_log(' * ' . date('Y-m-d H:i:s') . ' - ' . $p . ' (', 3, DATA_DIR . '/firstrun.log');
         if (!ModuleManager::install(str_replace('/', '_', $p), null, false)) {
             print '<b>Unable to install ' . str_replace('_', '/', $p) . ' module.</b>';
         }
         error_log(microtime(true) - $t2 . "s)\n", 3, DATA_DIR . '/firstrun.log');
     }
     error_log(date('Y-m-d H:i:s') . ': done (' . (microtime(true) - $t) . "s).\n", 3, DATA_DIR . '/firstrun.log');
     $t = microtime(true);
     error_log(date('Y-m-d H:i:s') . ': Refreshing cache of modules ...' . "\n", 3, DATA_DIR . '/firstrun.log');
     ModuleManager::create_load_priority_array();
     Base_SetupCommon::refresh_available_modules();
     error_log(date('Y-m-d H:i:s') . ': done (' . (microtime(true) - $t) . "s).\n", 3, DATA_DIR . '/firstrun.log');
     $t = microtime(true);
     error_log(date('Y-m-d H:i:s') . ': Creating cache of template files ...' . "\n", 3, DATA_DIR . '/firstrun.log');
     Base_ThemeCommon::create_cache();
     error_log(date('Y-m-d H:i:s') . ': done (' . (microtime(true) - $t) . "s).\n", 3, DATA_DIR . '/firstrun.log');
     $t = microtime(true);
     error_log(date('Y-m-d H:i:s') . ': Updating translation files ...' . "\n", 3, DATA_DIR . '/firstrun.log');
     Base_LangCommon::update_translations();
     error_log(date('Y-m-d H:i:s') . ': done (' . (microtime(true) - $t) . "s).\n", 3, DATA_DIR . '/firstrun.log');
     $processed = ModuleManager::get_processed_modules();
     $_SESSION['first-run_post-install'] = $processed['install'];
     location();
 }
Ejemplo n.º 13
0
 public static function display_epesi_user($record, $nolink, $desc)
 {
     return Base_UserCommon::get_user_login($record['epesi_user']);
 }
Ejemplo n.º 14
0
 public function change_user_active_state($user, $state)
 {
     Base_UserCommon::change_active_state($user, $state);
     return false;
 }
Ejemplo n.º 15
0
 public function submit_edit_user_form($data)
 {
     $mail = $data['mail'];
     $username = $data['username'];
     if (DEMO_MODE) {
         print 'You cannot change user password or e-mail address in demo';
         return false;
     }
     $pass = $data['pass'];
     $edit_id = $this->get_unique_href_variable('edit_user');
     if ($edit_id < 0) {
         if (!Base_User_LoginCommon::add_user($username, $mail, $pass)) {
             return false;
         }
         $edit_id = Base_UserCommon::get_user_id($username);
     } else {
         Base_UserCommon::rename_user($edit_id, $username);
         if (Base_User_LoginCommon::change_user_preferences($edit_id, $mail, $pass) === false) {
             print __('Unable to update account data (password and mail).');
             return false;
         }
         if (!Base_UserCommon::change_active_state($edit_id, $data['active'])) {
             print __('Unable to update account data (active).');
             return false;
         }
     }
     if (!Base_UserCommon::change_admin($edit_id, $data['admin'])) {
         print __('Unable to update account data (admin).');
         return false;
     }
     return true;
 }
Ejemplo n.º 16
0
 public static function create_write_to_link($uid)
 {
     $ret = Base_UserCommon::get_user_label($uid, true);
     if (Acl::get_user() != $uid) {
         $ret = "<a href=\"javascript:void(0);\" onclick=\"autoselect_add_value('shoutbox_to', " . $uid . ", '" . Epesi::escapeJS($ret) . "');autoselect_stop_searching('shoutbox_to');\$('shoutbox_to').onchange();\">" . $ret . '</a>';
     }
     return $ret;
 }
Ejemplo n.º 17
0
 public static function telegram()
 {
     $tokens = DB::GetAssoc('SELECT token,single_cache_uid FROM base_notify WHERE telegram=1 AND single_cache_uid is not null');
     if (!$tokens) {
         return;
     }
     $ret = array();
     $map = array();
     $refresh_time = time();
     $notified_cache = array();
     foreach ($tokens as $token => $uid) {
         $msgs = array();
         if (Base_NotifyCommon::is_refresh_due_telegram($token)) {
             Base_AclCommon::set_user($uid);
             $notified_cache[$token] = array();
             $notifications = Base_NotifyCommon::get_notifications($token);
             foreach ($notifications as $module => $module_new_notifications) {
                 foreach ($module_new_notifications as $id => $message) {
                     $notified_cache[$token][$module][] = $id;
                     $title = EPESI . ' ' . Base_NotifyCommon::strip_html($message['title']);
                     $body = Base_NotifyCommon::strip_html($message['body']);
                     //$icon = Base_NotifyCommon::get_icon($module, $message);
                     $msgs[] = array('title' => $title, 'body' => $body);
                 }
             }
         }
         $remote_token = md5($uid . '#' . Base_UserCommon::get_user_login($uid) . '#' . $token);
         $ret[$remote_token] = $msgs ? $msgs : '0';
         $map[$remote_token] = $token;
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "https://telegram.epesicrm.com/");
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($ret));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $status = curl_exec($ch);
     curl_close($ch);
     $status = @json_decode($status);
     if (is_array($status)) {
         foreach ($status as $remove) {
             if (isset($map[$remove])) {
                 DB::Execute('UPDATE base_notify SET telegram=0 WHERE token=%s', array($map[$remove]));
                 unset($notified_cache[$map[$remove]]);
             }
         }
         foreach ($notified_cache as $token => $nc) {
             Base_NotifyCommon::set_notified_cache($nc, $token, $refresh_time);
         }
     }
 }
Ejemplo n.º 18
0
 public static function get_html_record_info($created_by, $created_on, $edited_by = null, $edited_on = null, $id = null)
 {
     if ($created_by !== null) {
         $contact = CRM_ContactsCommon::contact_format_no_company(CRM_ContactsCommon::get_contact_by_user_id($created_by), true);
         if ($contact != '') {
             $created_by = $contact;
         } else {
             $created_by = Base_UserCommon::get_user_login($created_by);
         }
     } else {
         $created_by = '';
     }
     // If the record was edited get user contact info
     if ($edited_by != null) {
         if ($edited_by != $created_by) {
             $contact = CRM_ContactsCommon::contact_format_no_company(CRM_ContactsCommon::get_contact_by_user_id($edited_by), true);
         }
         if ($contact != '') {
             $edited_by = $contact;
         } else {
             $edited_by = Base_UserCommon::get_user_login($edited_by);
         }
     }
     $htmlinfo = array();
     if ($id) {
         $htmlinfo[__('Record ID') . ':'] = $id;
     }
     $htmlinfo[__('Created by') . ':'] = $created_by;
     $htmlinfo[__('Created on') . ':'] = Base_RegionalSettingsCommon::time2reg($created_on);
     if ($edited_by != null) {
         $htmlinfo = $htmlinfo + array(__('Edited by') . ':' => $edited_by, __('Edited on') . ':' => Base_RegionalSettingsCommon::time2reg($edited_on));
     }
     return Utils_TooltipCommon::format_info_tooltip($htmlinfo);
 }
Ejemplo n.º 19
0
 public static function new_autologin_id($old_autologin_id = null)
 {
     $uid = Acl::get_user();
     $user = Base_UserCommon::get_my_user_login();
     $autologin_id = md5(mt_rand() . md5($user . $uid) . mt_rand());
     setcookie('autologin_id', $user . ' ' . $autologin_id, time() + 60 * 60 * 24 * 30);
     $ip = get_client_ip_address();
     if ($old_autologin_id) {
         DB::Execute('DELETE FROM user_autologin WHERE user_login_id=%d AND autologin_id=%s', array($uid, $old_autologin_id));
     }
     DB::Execute('INSERT INTO user_autologin(user_login_id,autologin_id,description,last_log) VALUES(%d,%s,%s,%T)', array($uid, $autologin_id, $ip, time()));
     self::clean_old_autologins();
 }
Ejemplo n.º 20
0
	public static function crits_to_words($tab, $crits, $inline_joints=true) {
		$ret = array();
		$or_started = false;
        foreach($crits as $k=>$v){
            self::init($tab, false);
			$next = '';
            $negative = $noquotes = $or_start = $or = false;
            $operator = '=';
            while (($k[0]<'a' || $k[0]>'z') && ($k[0]<'A' || $k[0]>'Z') && $k[0]!=':') {
				if ($k[0]=='!') $negative = true;
				if ($k[0]=='"') $noquotes = true;
				if ($k[0]=='(') $or_start = true;
				if ($k[0]=='|') $or = true;
				if ($k[0]=='<') $operator = '<';
				if ($k[0]=='>') $operator = '>';
				if ($k[0]=='~') $operator = DB::like();
				if ($k[1]=='=' && $operator!=DB::like()) {
					$operator .= '=';
					$k = substr($k, 2);
				} else $k = substr($k, 1);
				if (!isset($k[0])) trigger_error('Invalid criteria in build query: missing word. Crits:'.print_r($crits,true), E_USER_ERROR);
			}
			$or |= $or_start;

			if (!isset($r[$k]) && $k[strlen($k)-1]==']') {
				list($ref, $sub_field) = explode('[', trim($k, ']'));
				$args = self::$table_rows[self::$hash[$ref]];
				$commondata = $args['commondata'];
				if (!$commondata) {
					if (!isset($args['ref_table'])) trigger_error('Invalid crits, field '.$ref.' is not a reference; crits: '.print_r($crits,true),E_USER_ERROR);
					$is_multiselect = ($args['type']=='multiselect');
					$tab2 = $tab;
					$col2 = $k;
					$tab = $args['ref_table'];
					$k = $sub_field;
					
					$f_dis = self::$table_rows[self::$hash[$ref]]['name'];
					self::init($tab);
					$next .= '<b>'._V($f_dis).'</b> '.' is set to record with ';
				}
			}

            if ($k[0]!=':' && $k!=='id' && !isset(self::$table_rows[$k]) && (!isset(self::$hash[$k]) || !isset(self::$table_rows[self::$hash[$k]]))) continue; //failsafe

			if (!empty($ret)) {
				if ($or_start) $joint = 'and';
				elseif ($or) $joint = 'or';
				else $joint = 'and';
				if ($inline_joints) $next .= _V($joint).' ';
				else $ret[] = $joint;
			}

            if ($k[0]==':') {
                switch ($k) {
                    case ':Fav' :   		$next .= (!$v || ($negative && $v))?__('is not on %sfavorites%s', array('<b>','</b>')):__('is on %sfavorites%s', array('<b>','</b>'));
											$ret[] = $next;
											continue 2;
                    case ':Recent'  :   	$next .= (!$v || ($negative && $v))?__('wasn\'t %srecently%s viewed', array('<b>','</b>')):__('was %srecently%s viewed', array('<b>','</b>'));
											$ret[] = $next;
											continue 2;
                    case ':Sub'  :          $next .= (!$v || ($negative && $v))?__('is not %swatched%s', array('<b>','</b>')):__('is %swatched%s', array('<b>','</b>'));
                                            $ret[] = $next;
                                            continue 2;
                    case ':Created_on'  :	$next .= '<b>'.__('Created on').'</b> ';
											break;
                    case ':Created_by'  :	$next .= '<b>'.__('Created by').'</b> ';
											break;
                    case ':Edited_on'   :	$next .= '<b>'.__('Edited on').'</b> ';
											break;
				}
			} else {
				if ($k=='id') $next .= '<b>'.__('ID').'</b> ';
				else $next .= '<b>'._V(self::$table_rows[self::$hash[$k]]['name']).'</b> ';
			}
			$operand = '';
			if (!isset($tab2)) {
				if ($negative) $operand .= '<i>'.__('is not').'</i> ';
				else $operand .= __('is').' ';
			}
			if ($v==='') {
				$next .= $operand.__('empty');
			} else {
				switch ($operator) {
					case '<':	$operand .= __('smaller than'); break;
					case '<=':	$operand .= __('smaller or equal to'); break;
					case '>':	$operand .= __('greater than'); break;
					case '>=':	$operand .= __('greater or equal to'); break;
					case DB::like(): 
								$operand = $negative?__('does not contain'):__('contains'); 
								$v = str_replace(array('||', "'%'"), '', $v); // FIXME doesn't differentiate between "begins with", "contains" or "ends with"
								break;
					default:	$operand .= __('equal to');
				}
				$operand = $operand.' ';
				$next .= $operand;
				
				switch ($k) {
					case 'id':			if (!is_array($v)) $v = array($v); break;
                    case ':Created_by': $v = array(is_numeric($v)?Base_UserCommon::get_user_login($v):$v); break;
					case ':Created_on': 
                    case ':Edited_on':  if (isset(self::$date_values[$v])) $v = array(self::$date_values[$v]);
										else $v = array(Base_RegionalSettingsCommon::time2reg($v)); break;
					default: 			if (!is_array($v) && isset(self::$date_values[$v])) {
											$v = array(self::$date_values[$v]);
											break;
										}
										if (!is_array($v)) $v = array($v);
										$args = self::$table_rows[self::$hash[$k]];
										if($args['type']=='checkbox' && count($v)==2 && !$v[0] && !$v[1]) unset($v[1]);
										foreach ($v as $kk=>$vv) {
											if (!is_numeric($vv) && !$args['commondata'] && isset($args['ref_table'])) {
												continue;
											}
											$v[$kk] = self::get_val($tab, $k, array($k=>$vv), true);
										}	
				}
				foreach ($v as $kk=>$vv)
					$v[$kk] = '<b>'.$vv.'</b>';
				$next .= implode(' or ', $v);
			}

			$ret[] = $next;
			if (isset($tab2)) {
				$tab = $tab2;
				unset($tab2);
			}
		}
//		$ret[] = print_r($crits,true);
		return $ret;
	}
Ejemplo n.º 21
0
 public function make_event_PDF($pdf, $id, $no_details = false, $type = 'Event')
 {
     $custom_event = false;
     if (!is_array($id)) {
         $check = explode('#', $id);
         if (isset($check[1])) {
             $callback = DB::GetOne('SELECT handler_callback FROM crm_calendar_custom_events_handlers WHERE id=%d', $check[0]);
             $callback = explode('::', $callback);
             $ev = call_user_func($callback, 'get', $check[1]);
             $no_details = true;
             $custom_event = true;
         } else {
             trigger_error('Invalid event id: ' . $id, E_USER_ERROR);
         }
     } else {
         $ev = $id;
         $id = $ev['id'];
         $id = explode('_', $id);
         $id = $id[0];
         /*			$ev_details = DB::GetRow('SELECT *, starts AS start, ends AS end FROM crm_calendar_event WHERE id=%d', array($id));
         			foreach ($ev_details as $k=>$v)
         				if (!isset($ev[$k])) $ev[$k] = $v;*/
         $ev['title'] = strip_tags($ev['title']);
         $check = explode('#', $id);
         if (isset($check[1])) {
             $no_details = true;
             $custom_event = true;
         }
     }
     $pdf_theme = $this->pack_module('Base/Theme');
     $pdf_theme->assign('description', array('label' => __('Description'), 'value' => str_replace("\n", '<br/>', htmlspecialchars($ev['description']))));
     if (!$no_details) {
         $ev['status'] = Utils_CommonDataCommon::get_value('CRM/Status/' . $ev['status'], true);
         $ev['access'] = self::$access[$ev['access']];
         $ev['priority'] = self::$priority[$ev['priority']];
         foreach (array('access' => __('Access'), 'priority' => __('Priority'), 'status' => __('Status')) as $v => $label) {
             $pdf_theme->assign($v, array('label' => $label, 'value' => $ev[$v]));
         }
         $created_by = CRM_ContactsCommon::get_contact_by_user_id($ev['created_by']);
         if ($created_by !== null) {
             $created_by = $created_by['last_name'] . ' ' . $created_by['first_name'];
         } else {
             $created_by = Base_UserCommon::get_user_login($ev['created_by']);
         }
         $created_on = Base_RegionalSettingsCommon::time2reg($ev['created_on'], false);
         $pdf_theme->assign('created_on', array('label' => __('Created on'), 'value' => $created_on));
         $pdf_theme->assign('created_by', array('label' => __('Created by'), 'value' => $created_by));
         if ($ev['edited_by'] != null) {
             $edited_by = CRM_ContactsCommon::get_contact_by_user_id($ev['edited_by']);
             if ($edited_by !== null) {
                 $edited_by = $edited_by['last_name'] . ' ' . $edited_by['first_name'];
             } else {
                 $edited_by = Base_UserCommon::get_user_login($ev['edited_by']);
             }
             $edited_on = Base_RegionalSettingsCommon::time2reg($ev['edited_on'], false);
         } else {
             $edited_by = '--';
             $edited_on = '--';
         }
         $pdf_theme->assign('edited_on', array('label' => __('Edited on'), 'value' => $edited_on));
         $pdf_theme->assign('edited_by', array('label' => __('Edited by'), 'value' => $edited_by));
         $pdf_theme->assign('printed_on', array('label' => __('Printed on'), 'value' => Base_RegionalSettingsCommon::time2reg(time())));
     }
     $emps = array();
     $cuss = array();
     $cus_cmps = array();
     if (isset($ev['employees']) && !empty($ev['employees'])) {
         foreach ($ev['employees'] as $v) {
             $c = CRM_ContactsCommon::get_contact($v);
             $emps[] = array('name' => $c['last_name'] . ' ' . $c['first_name'], 'mphone' => $c['mobile_phone'], 'wphone' => $c['work_phone'], 'hphone' => $c['home_phone']);
         }
     }
     if (isset($ev['customers']) && !empty($ev['customers'])) {
         foreach ($ev['customers'] as $v) {
             $det = explode(':', $v);
             if (isset($det[1])) {
                 $v = $det[1];
             } else {
                 $v = $det[0];
                 $det[0] = 'P';
             }
             if ($det[0] == 'P') {
                 $c = CRM_ContactsCommon::get_contact($v);
                 $company_name = isset($c['company_name']) && is_numeric($c['company_name']) ? array(Utils_RecordBrowserCommon::get_value('company', $c['company_name'], 'Company Name')) : '---';
                 $cuss[] = array('name' => $c['last_name'] . ' ' . $c['first_name'], 'mphone' => $c['mobile_phone'], 'wphone' => $c['work_phone'], 'hphone' => $c['home_phone'], 'company_name' => $company_name);
             }
             if ($det[0] == 'C') {
                 $c = array('company_name' => array($v));
             }
             if (is_array($c['company_name'])) {
                 foreach ($c['company_name'] as $v2) {
                     if (!isset($cus_cmps[$v2])) {
                         $cus_cmps[$v2] = CRM_ContactsCommon::get_company($v2);
                     }
                 }
             }
         }
     }
     $pdf_theme->assign('employees', array('main_label' => __('Employees'), 'name_label' => __('Name'), 'mphone_label' => __('Mobile Phone'), 'wphone_label' => __('Work Phone'), 'hphone_label' => __('Home Phone'), 'lp_label' => __('Lp'), 'data' => $emps));
     $pdf_theme->assign('customers', array('main_label' => __('Customers'), 'name_label' => __('Name'), 'mphone_label' => __('Mobile Phone'), 'wphone_label' => __('Work Phone'), 'hphone_label' => __('Home Phone'), 'company_name' => __('Company Name'), 'lp_label' => __('Lp'), 'data' => $cuss));
     $pdf_theme->assign('customers_companies', array('main_label' => __('Customers Companies'), 'name_label' => __('Company Name'), 'phone_label' => __('Phone'), 'fax_label' => __('Fax'), 'address_label' => __('Address'), 'city_label' => __('City'), 'lp_label' => __('Lp'), 'data' => $cus_cmps));
     $pdf_theme->assign('title', array('label' => __('Title'), 'value' => $ev['title']));
     $start = Base_RegionalSettingsCommon::time2reg($ev['start'], false);
     $pdf_theme->assign('start_date', array('label' => __('Start Date'), 'value' => $start, 'details' => array('weekday' => __date('l', strtotime($start)))));
     if (!isset($ev['timeless'])) {
         $pdf_theme->assign('start_time', array('label' => __('Start Time'), 'value' => Base_RegionalSettingsCommon::time2reg($ev['start'], true, false)));
         if (!isset($ev['end'])) {
             trigger_error(print_r($ev, true));
         }
         $pdf_theme->assign('end_time', array('label' => __('End Time'), 'value' => Base_RegionalSettingsCommon::time2reg($ev['end'], true, false)));
         $hours = floor(($ev['end'] - $ev['start']) / 3600);
         $format = __('%d hours', array($hours));
         $minutes = ($ev['end'] - $ev['start']) % 3600;
         if ($minutes != 0) {
             if ($hours == 0) {
                 $format = '';
             } else {
                 $format .= ', ';
             }
             $format .= __('%d minutes', array($minutes / 60));
         }
         $pdf_theme->assign('duration', array('label' => __('Duration'), 'value' => $format));
         if (date('Y-m-d', $ev['start']) != date('Y-m-d', $ev['end'])) {
             $pdf_theme->assign('end_date', array('label' => __('End Date'), 'value' => Base_RegionalSettingsCommon::time2reg($ev['end'], false)));
         }
     } else {
         $pdf_theme->assign('timeless', array('label' => __('Timeless'), 'value' => __('Yes')));
     }
     $pdf_theme->assign('type', $type);
     ob_start();
     $pdf_theme->display('pdf_version');
     $cont = ob_get_clean();
     $pdf->writeHTML($cont);
 }
Ejemplo n.º 22
0
 public function submit_recover($data)
 {
     $mail = $data['mail'];
     $username = $data['username'];
     if (DEMO_MODE && $username == 'admin') {
         print 'In demo you cannot recover \'admin\' user password. If you want to login please type \'admin\' as password.';
         return false;
     }
     $user_id = Base_UserCommon::get_user_id($username);
     DB::Execute('DELETE FROM user_reset_pass WHERE created_on<%T', array(time() - 3600 * 2));
     if ($user_id === false) {
         print 'No such user!';
         return false;
     }
     $hash = md5($user_id . '' . time());
     DB::Execute('INSERT INTO user_reset_pass(user_login_id,hash_id,created_on) VALUES (%d,%s,%T)', array($user_id, $hash, time()));
     $subject = __('Password recovery');
     $message = __('A password recovery for the account with the e-mail address %s has been requested.', array($mail)) . "\n\n" . __('If you want to reset your password, visit the following URL:') . "\n" . get_epesi_url() . '/modules/Base/User/Login/reset_pass.php?hash=' . $hash . "\n" . __('or just ignore this message and your login and password will remain unchanged.') . "\n\n" . __('If you did not use the Password Recovery form, inform your administrator about a potential unauthorized attempt to login using your credentials.') . "\n\n" . __('This e-mail was generated automatically and you do not need to respond to it.');
     $sendMail = Base_MailCommon::send_critical($mail, $subject, $message);
     return true;
 }
Ejemplo n.º 23
0
    }
    $v = str_replace($currency_thou_signs[$symbol], '', $v);
    $v = str_replace($currency_decimal_signs[$symbol], '.', $v);
    return $v;
}
foreach ($records as $r) {
    $has_access = Utils_RecordBrowserCommon::get_access($tab, 'view', $r);
    if (!$has_access) {
        continue;
    }
    $rec = array($r['id']);
    $details = Utils_RecordBrowserCommon::get_record_info($tab, $r['id']);
    $rec[] = $details['created_on'];
    $rec[] = Base_UserCommon::get_user_label($details['created_by'], true);
    $rec[] = $details['edited_on'];
    $rec[] = $details['edited_by'] ? Base_UserCommon::get_user_label($details['edited_by'], true) : '';
    foreach ($tab_info as $field_name => $v) {
        if (!$v['export']) {
            continue;
        }
        ob_start();
        if (!isset($has_access[$v['id']]) || !$has_access[$v['id']]) {
            $val = '';
        } else {
            $val = Utils_RecordBrowserCommon::get_val($tab, $field_name, $r, true, $v);
        }
        ob_end_clean();
        $val = str_replace('&nbsp;', ' ', htmlspecialchars_decode(strip_tags(preg_replace('/\\<[Bb][Rr]\\/?\\>/', "\n", $val))));
        if ($v['style'] == 'currency') {
            $val = str_replace(' ', '_', $val);
            $val = explode(';', $val);
Ejemplo n.º 24
0
 public function body()
 {
     if (!Base_AclCommon::check_permission('View Activity Report')) {
         return;
     }
     $rb_tabs = DB::GetAssoc('SELECT tab, caption FROM recordbrowser_table_properties ORDER BY caption');
     foreach ($rb_tabs as $k => $v) {
         $rb_tabs[$k] = Utils_RecordBrowserCommon::get_caption($k);
     }
     $form = $this->init_module('Libs/QuickForm');
     $users_count = DB::GetOne('SELECT COUNT(id) FROM user_login') > Base_User_SettingsCommon::get('Utils_RecordBrowser', 'enable_autocomplete');
     if ($users_count) {
         $crits = array('!login' => '');
         $fcallback = array('CRM_ContactsCommon', 'contact_format_no_company');
         $form->addElement('autoselect', 'user', __('User'), array(), array(array('CRM_ContactsCommon', 'autoselect_contact_suggestbox'), array($crits, $fcallback)), $fcallback);
     } else {
         $users = DB::GetAssoc('SELECT id, id FROM user_login');
         foreach ($users as $k => $u) {
             $users[$k] = Base_UserCommon::get_user_label($u, true);
         }
         asort($users);
         $users = array('' => '[' . __('All') . ']') + $users;
         $form->addElement('select', 'user', __('User'), $users);
     }
     $form->addElement('multiselect', 'recordsets', __('Record Type'), $rb_tabs);
     $form->addElement('checkbox', 'new', __('New record'));
     $form->addElement('checkbox', 'edit', __('Record edit'));
     $form->addElement('checkbox', 'delete_restore', __('Record Delete/restore'));
     $form->addElement('checkbox', 'file', __('Files'));
     $form->addElement('datepicker', 'start_date', __('Start Date'));
     $form->addElement('datepicker', 'end_date', __('End Date'));
     //$form->addElement('submit', 'submit', __('Show'));
     Base_ActionBarCommon::add('search', __('Show'), $form->get_submit_form_href());
     $filters = $this->get_module_variable('filters', array('user' => '', 'new' => 1, 'edit' => 1, 'delete_restore' => 1, 'recordsets' => array_keys($rb_tabs), 'start_date' => date('Y-m-01'), 'end_date' => date('Y-m-d')));
     if ($form->validate()) {
         $filters = $form->exportValues();
         $this->set_module_variable('filters', $filters);
     }
     $form->setDefaults($filters);
     $theme = $this->init_module('Base/Theme');
     $form->assign_theme('form', $theme);
     $theme->display();
     $filters['recordsets'] = array_flip($filters['recordsets']);
     foreach ($rb_tabs as $k => $v) {
         if (!isset($filters['recordsets'][$k])) {
             unset($rb_tabs[$k]);
         }
     }
     $gb = $this->init_module('Utils/GenericBrowser', null, 'activity_report');
     $gb->set_table_columns(array(array('name' => __('Date'), 'width' => 40), array('name' => __('User'), 'width' => 40), array('name' => __('Type'), 'width' => 40), array('name' => __('Label')), array('name' => __('Actions taken'), 'width' => 40)));
     $tables = array();
     if ($users_count) {
         $filters['user'] = CRM_ContactsCommon::get_contact($filters['user']);
         $filters['user'] = $filters['user']['login'];
     }
     $af_where = array();
     foreach ($rb_tabs as $k => $t) {
         $af_where[] = 'ual.local ' . DB::like() . ' ' . DB::Concat(DB::qstr($k . '/'), DB::qstr('%'));
     }
     $af_where = count($af_where) ? ' (' . implode(' OR ', $af_where) . ')' : 'TRUE ';
     $e_where = array();
     $c_where = '';
     if ($filters['user']) {
         $e_where[] = ' edited_by = ' . $filters['user'];
         $c_where = ' created_by = ' . $filters['user'];
         $af_where .= ' AND uaf.created_by = ' . $filters['user'];
     }
     if (isset($filters['edit'])) {
         if (!isset($filters['delete_restore'])) {
             $e_where[] = ' ehd.field!=' . DB::qstr('id');
         }
     } else {
         if (isset($filters['delete_restore'])) {
             $e_where[] = ' ehd.field=' . DB::qstr('id');
         }
     }
     if ($filters['start_date']) {
         $date = DB::qstr(date('Y-m-d', strtotime($filters['start_date'])));
         $af_where .= ' AND uaf.created_on >= ' . $date;
         $c_where .= ($c_where ? ' AND' : '') . ' created_on >= ' . $date;
         $e_where[] = ' edited_on >= ' . $date;
     }
     if ($filters['end_date']) {
         $date = DB::qstr(date('Y-m-d 23:59:59', strtotime($filters['end_date'])));
         $af_where .= ' AND uaf.created_on <= ' . $date;
         $c_where .= ($c_where ? ' AND' : '') . ' created_on <= ' . $date;
         $e_where[] = ' edited_on <= ' . $date;
     }
     if (!empty($e_where)) {
         $e_where = ' WHERE' . implode(' AND', $e_where);
     } else {
         $e_where = '';
     }
     if ($c_where) {
         $c_where = ' WHERE' . $c_where;
     }
     $postgre_cast_type = DB::is_postgresql() ? '::varchar' : '';
     // **** files ****
     if (isset($filters['file'])) {
         $tables[] = 'SELECT uaf.id AS id,uaf.created_on AS edited_on,uaf.created_by AS edited_by, ual.local AS r_id, ' . DB::qstr('') . ' AS tab, ' . DB::qstr('file') . ' AS action FROM utils_attachment_file uaf INNER JOIN utils_attachment_data_1 ua ON uaf.attach_id=ua.id INNER JOIN utils_attachment_local ual ON ua.id=ual.attachment WHERE original!=' . DB::qstr('') . ' AND ' . $af_where;
     }
     // **** edit ****
     if (isset($filters['edit']) || isset($filters['delete_restore'])) {
         foreach ($rb_tabs as $k => $t) {
             $tables[] = 'SELECT id, edited_on, edited_by, ' . $k . '_id' . $postgre_cast_type . ' as r_id, ' . DB::qstr($k) . ' as tab, ' . DB::qstr('edit') . ' as action FROM ' . $k . '_edit_history eh LEFT JOIN ' . $k . '_edit_history_data ehd ON ehd.edit_id=eh.id' . $e_where;
         }
     }
     // **** create ****
     if (isset($filters['new'])) {
         foreach ($rb_tabs as $k => $t) {
             $tables[] = 'SELECT 0 AS id, created_on AS edited_on, created_by AS edited_by, id' . $postgre_cast_type . ' as r_id, ' . DB::qstr($k) . ' as tab, ' . DB::qstr('create') . ' as action FROM ' . $k . '_data_1' . $c_where;
         }
     }
     if (!empty($tables)) {
         $tables = implode(' UNION ', $tables);
         $limit = DB::GetOne('SELECT COUNT(*) FROM (' . $tables . ') AS tmp');
         $limit = $gb->get_limit($limit);
         $ret = DB::SelectLimit('SELECT * FROM (' . $tables . ') AS tmp ORDER BY edited_on DESC', $limit['numrows'], $limit['offset']);
         while ($row = $ret->FetchRow()) {
             $user = Base_UserCommon::get_user_label($row['edited_by']);
             $action = '';
             $link = '';
             switch ($row['action']) {
                 case 'edit':
                     $details = DB::GetAssoc('SELECT field, old_value FROM ' . $row['tab'] . '_edit_history_data WHERE edit_id=%d', array($row['id']));
                     if (isset($details['id'])) {
                         $action = $details['id'] == 'DELETED' ? __('Deleted') : __('Restored');
                     } else {
                         $action = __('Edited');
                         $action = '<a ' . Utils_TooltipCommon::tooltip_leightbox_mode() . ' ' . Utils_TooltipCommon::ajax_open_tag_attrs(array('Utils_RecordBrowserCommon', 'get_edit_details_label'), array($row['tab'], $row['r_id'], $row['id']), 500) . '>' . $action . '</a>';
                     }
                     $r_id = $row['r_id'];
                     break;
                 case 'create':
                     $action = __('Created');
                     $r_id = $row['r_id'];
                     break;
                 case 'file':
                     $action = __('Attachment') . ': ';
                     $action .= $row['id'] == 0 ? __('New') : __('Updated');
                     $id = explode('/', $row['r_id']);
                     $row['tab'] = $id[0];
                     $r_id = $id[1];
                     break;
                 case 'note':
                     $action = __('Note') . ': ';
                     $action .= $row['id'] == 0 ? __('New') : __('Updated');
                     $id = explode('/', $row['r_id']);
                     $row['tab'] = $id[0];
                     $r_id = $id[1];
                     break;
             }
             if (!Utils_RecordBrowserCommon::get_access($row['tab'], 'view', Utils_RecordBrowserCommon::get_record($row['tab'], $r_id))) {
                 $link = __('Access restricted');
                 $action = strip_tags($action);
             } else {
                 $link = Utils_TooltipCommon::create('<img src="' . Base_ThemeCommon::get_template_file('Utils_RecordBrowser', 'info.png') . '">', Utils_RecordBrowserCommon::get_html_record_info($row['tab'], $r_id), false);
                 $link .= '&nbsp;';
                 $link .= Utils_RecordBrowserCommon::create_default_linked_label($row['tab'], $r_id, false, false);
             }
             $gb->add_row(Base_RegionalSettingsCommon::time2reg($row['edited_on']), $user, $rb_tabs[$row['tab']], $link, $action);
         }
     }
     Base_ThemeCommon::load_css('Utils_RecordBrowser', 'changes_list');
     $this->display_module($gb);
 }
Ejemplo n.º 25
0
 * 
 * @author Pawel Bukowski <*****@*****.**>
 * @copyright Copyright &copy; 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))));
Ejemplo n.º 26
0
 public function admin()
 {
     if ($this->is_back()) {
         if ($this->parent->get_type() == 'Base_Admin') {
             $this->parent->reset();
         } else {
             location(array());
         }
         return;
     }
     Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href());
     $user = $this->get_module_variable('filter_user', '');
     $form = $this->init_module(Libs_QuickForm::module_name(), null, 'filter');
     $form->setDefaults(array('users' => $user));
     $count = DB::GetOne('SELECT COUNT(*) FROM user_login');
     if ($count > Base_User_SettingsCommon::get('Utils_RecordBrowser', 'enable_autocomplete')) {
         $f_callback = array('CRM_LoginAuditCommon', 'user_label');
         $form->addElement('autoselect', 'users', __('Select user'), array(), array(array('CRM_LoginAuditCommon', 'user_suggestbox'), array($f_callback)), $f_callback, array('onChange' => $form->get_submit_form_js(), 'style' => 'width:200px'));
     } else {
         $ret = DB::Execute('SELECT id, active FROM user_login ORDER BY active DESC, login ASC');
         $el = $form->addElement('select', 'users', __('Select user'), array(), array('onChange' => $form->get_submit_form_js(), 'style' => 'width:200px'));
         $el->addOption(__('All'), '');
         $contacts_raw = CRM_ContactsCommon::get_contacts(array('!login' => ''));
         $contacts = array();
         foreach ($contacts_raw as $c) {
             $contacts[$c['login']] = $c;
         }
         $active = array();
         $inactive = array();
         while ($row = $ret->FetchRow()) {
             $label = '[' . Base_UserCommon::get_user_login($row['id']) . ']';
             if (isset($contacts[$row['id']])) {
                 $label = CRM_ContactsCommon::contact_format_no_company($contacts[$row['id']], true) . ' ' . $label;
             }
             if ($row['active']) {
                 $active[$row['id']] = $label;
             } else {
                 $inactive[$row['id']] = $label;
             }
         }
         asort($active);
         asort($inactive);
         foreach ($active as $id => $label) {
             $el->addOption($label, $id);
         }
         foreach ($inactive as $id => $label) {
             $el->addOption($label, $id, array('style' => 'background-color: lightgray;'));
         }
     }
     $user = $form->exportValue('users');
     $form->display_as_row();
     $this->set_module_variable('filter_user', $user);
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'login_audit');
     $gb->set_table_columns(array(array('name' => '<b>' . __('Login') . '</b> ' . __('[uid] -> User Name'), 'order' => 'b.user_login_id', 'width' => 20), array('name' => __('Start'), 'order' => 'b.start_time', 'width' => 15), array('name' => __('End'), 'order' => 'b.end_time', 'width' => 15), array('name' => __('Duration'), 'width' => 10), array('name' => __('IP Address'), 'order' => 'b.ip_address', 'width' => 10), array('name' => __('Host Name'), 'order' => 'b.host_name', 'width' => 30)));
     $gb->set_default_order(array(__('End') => 'DESC'));
     if ($user > 0) {
         $query = 'SELECT b.user_login_id, b.start_time, b.end_time, b.ip_address, b.host_name FROM base_login_audit b WHERE b.user_login_id=' . $user;
         $query_qty = 'SELECT count(b.id) FROM base_login_audit b WHERE b.user_login_id=' . $user;
     } else {
         $query = 'SELECT b.user_login_id, b.start_time, b.end_time, b.ip_address, b.host_name FROM base_login_audit b';
         $query_qty = 'SELECT count(b.id) FROM base_login_audit b';
     }
     $ret = $gb->query_order_limit($query, $query_qty);
     if ($ret) {
         while ($row = $ret->FetchRow()) {
             $c = CRM_ContactsCommon::get_contact_by_user_id($row['user_login_id']);
             $ulogin = Base_UserCommon::get_user_login($row['user_login_id']);
             $uid = __('Contact not set');
             if ($c) {
                 $uid = $c['first_name'] . ' ' . $c['last_name'];
             }
             $offset = strtotime("1970-01-01 00:00:00");
             $sess_time = date("G:i:s", strtotime($row['end_time']) - strtotime($row['start_time']) + $offset);
             $gb->add_row('<b>' . $ulogin . ' [' . $row['user_login_id'] . ']</b> -> ' . $uid, $row['start_time'], $row['end_time'], $sess_time, $row['ip_address'], $row['host_name']);
         }
     }
     $this->display_module($gb);
     if (!DEMO_MODE) {
         Base_ActionBarCommon::add('settings', __('Maintenance'), $this->create_callback_href(array($this, 'purge_log')));
     }
     return true;
 }
Ejemplo n.º 27
0
    public function view_edit_history($id){
		load_js('modules/Utils/RecordBrowser/edit_history.js');
        if ($this->is_back())
            return $this->back();
        $this->init();
		$tb = $this->init_module('Utils_TabbedBrowser');		
        $gb_cha = $this->init_module('Utils/GenericBrowser', null, $this->tab.'__changes');
		$form = $this->init_module('Libs_QuickForm');

        $table_columns_changes = array( array('name'=>__('Date'), 'width'=>10, 'wrapmode'=>'nowrap'),
                                        array('name'=>__('Username'), 'width'=>10, 'wrapmode'=>'nowrap'),
                                        array('name'=>__('Field'), 'width'=>10, 'wrapmode'=>'nowrap'),
                                        array('name'=>__('Old value'), 'width'=>10, 'wrapmode'=>'nowrap'),
                                        array('name'=>__('New value'), 'width'=>10, 'wrapmode'=>'nowrap'));

        $gb_cha->set_table_columns( $table_columns_changes );

        $gb_cha->set_inline_display();

        $created = Utils_RecordBrowserCommon::get_record($this->tab, $id, true);
        $access = $this->get_access('view', $created);
        $field_hash = array();
        $edited = DB::GetRow('SELECT ul.login, c.edited_on FROM '.$this->tab.'_edit_history AS c LEFT JOIN user_login AS ul ON ul.id=c.edited_by WHERE c.'.$this->tab.'_id=%d ORDER BY edited_on DESC',array($id));
        foreach($this->table_rows as $field => $args)
            $field_hash[$args['id']] = $field;

        $ret = DB::Execute('SELECT ul.login, c.id, c.edited_on, c.edited_by FROM '.$this->tab.'_edit_history AS c LEFT JOIN user_login AS ul ON ul.id=c.edited_by WHERE c.'.$this->tab.'_id=%d ORDER BY edited_on DESC, id DESC',array($id));
		$dates_select = array();
		$tb_path = escapeJS($tb->get_path());
        while ($row = $ret->FetchRow()) {
			$user = Base_UserCommon::get_user_label($row['edited_by']);
			$date_and_time = Base_RegionalSettingsCommon::time2reg($row['edited_on']);
            $changed = array();
            $ret2 = DB::Execute('SELECT * FROM '.$this->tab.'_edit_history_data WHERE edit_id=%d',array($row['id']));
            while($row2 = $ret2->FetchRow()) {
                if ($row2['field']!='id' && (!isset($access[$row2['field']]) || !$access[$row2['field']])) continue;
                $changed[$row2['field']] = $row2['old_value'];
                $last_row = $row2;
                $dates_select[$row['edited_on']] = $date_and_time;
            }
            foreach($changed as $k=>$v) {
                if ($k=='id') {
					$gb_cha->add_row(
						$date_and_time, 
						$user, 
						array('value'=>_V($last_row['old_value']), 'attrs'=>'colspan="3" style="text-align:center;font-weight:bold;"'),
						array('value'=>'', 'dummy'=>true),
						array('value'=>'', 'dummy'=>true)
					);
                } else {
                    if (!isset($field_hash[$k])) continue;
                    $new = $this->get_val($field_hash[$k], $created, false, $this->table_rows[$field_hash[$k]]);
                    if ($this->table_rows[$field_hash[$k]]['type']=='multiselect') $v = Utils_RecordBrowserCommon::decode_multi($v);
                    $created[$k] = $v;
                    $old = $this->get_val($field_hash[$k], $created, false, $this->table_rows[$field_hash[$k]]);
					$gb_row = $gb_cha->get_new_row();
					$gb_row->add_action('href="javascript:void(0);" onclick="recordbrowser_edit_history_jump(\''.$row['edited_on'].'\',\''.$this->tab.'\','.$created['id'].',\''.$form->get_name().'\');tabbed_browser_switch(1,2,null,\''.$tb_path.'\')"','View');
                    $gb_row->add_data(
                        $date_and_time,
                        $row['edited_by']!==null?$user:'',
                        _V($this->table_rows[$field_hash[$k]]['name']), // TRSL
                        $old,
                        $new
                    );
                }
            }
        }

		$gb_row = $gb_cha->get_new_row();
		$gb_row->add_data(
			Base_RegionalSettingsCommon::time2reg($created['created_on']),
			$created['created_by']!==null?Base_UserCommon::get_user_label($created['created_by']):'',
			array('value'=>__('RECORD CREATED'), 'attrs'=>'colspan="3" style="text-align:center;font-weight:bold;"'),
			array('value'=>'', 'dummy'=>true),
			array('value'=>'', 'dummy'=>true)
		);


//		$tb->set_tab(__('Record historical view'), array($this, 'record_historical_view'), array($created, $access, $form, $dates_select), true);
		$tb->start_tab(__('Changes History'));
		$this->display_module($gb_cha);
		$tb->end_tab();

		$tb->start_tab(__('Record historical view'));
		$dates_select[$created['created_on']] = Base_RegionalSettingsCommon::time2reg($created['created_on']);
        foreach($this->table_rows as $field => $args) {
            if (!$access[$args['id']]) continue;
            $val = $this->get_val($field, $created, false, $args);
        }
		$form->addElement('select', 'historical_view_pick_date', __('View the record as of'), $dates_select, array('onChange'=>'recordbrowser_edit_history("'.$this->tab.'",'.$created['id'].',"'.$form->get_name().'");', 'id'=>'historical_view_pick_date'));
		$form->setDefaults(array('historical_view_pick_date'=>$created['created_on']));
		$form->display();
		$this->view_entry('history', $created);
		$tb->end_tab();

		
		$this->display_module($tb);
        Base_ActionBarCommon::add('back',__('Back'),$this->create_back_href());
        return true;
    }
Ejemplo n.º 28
0
<?php

if (!isset($_GET['hash'])) {
    die('');
}
header("Content-Type: text/html; charset=UTF-8");
define('READ_ONLY_SESSION', true);
define('CID', false);
require_once '../../../../include.php';
ModuleManager::load_modules();
DB::Execute('DELETE FROM user_reset_pass WHERE created_on<%T', array(time() - 3600 * 2));
$user_id = DB::GetOne('SELECT user_login_id FROM user_reset_pass WHERE hash_id=%s', array($_GET['hash']));
if ($user_id == false) {
    die(__('Request failed. Authentication link is valid for 2 hours since sending request.'));
}
$pass = generate_password();
$pass_hash = function_exists('password_hash') ? password_hash($pass, PASSWORD_DEFAULT) : md5($pass);
if (!DB::Execute('UPDATE user_password SET password=%s WHERE user_login_id=%d', array($pass_hash, $user_id))) {
    die(__('Unable to update password. Please contact system administrator.'));
}
if (!Base_User_LoginCommon::send_mail_with_password(Base_UserCommon::get_user_login($user_id), $pass, Base_User_LoginCommon::get_mail($user_id), true)) {
    die(__('Unable to send e-mail with password. Mail module configuration invalid. Please contact system administrator.'));
}
DB::Execute('DELETE FROM user_reset_pass WHERE hash_id =%s', array($_GET['hash']));
header('Location: ' . get_epesi_url() . '?' . http_build_query(array('password_recovered' => 1)));
Ejemplo n.º 29
0
 public function file_history($attachment)
 {
     if ($this->is_back()) {
         $x = ModuleManager::get_instance('/Base_Box|0');
         if (!$x) {
             trigger_error('There is no base box module instance', E_USER_ERROR);
         }
         return $x->pop_main();
     }
     Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href());
     $id = $attachment['id'];
     $tb =& $this->init_module(Utils_TabbedBrowser::module_name());
     $tb->start_tab('File history');
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'hua' . $id);
     $gb->set_inline_display();
     $gb->set_table_columns(array(array('name' => __('Deleted'), 'order' => 'deleted', 'width' => 10), array('name' => __('Date'), 'order' => 'upload_on', 'width' => 25), array('name' => __('Who'), 'order' => 'upload_by', 'width' => 25), array('name' => __('Attachment'), 'order' => 'uaf.original')));
     $gb->set_default_order(array(__('Date') => 'DESC'));
     $ret = $gb->query_order_limit('SELECT uaf.id,uaf.deleted,uaf.filestorage_id,uaf.created_on as upload_on,uaf.created_by as upload_by,uaf.original FROM utils_attachment_file uaf WHERE uaf.attach_id=' . $id, 'SELECT count(*) FROM utils_attachment_file uaf WHERE uaf.attach_id=' . $id);
     while ($row = $ret->FetchRow()) {
         $r = $gb->get_new_row();
         if ($row['deleted']) {
             $r->add_action($this->create_confirm_callback_href(__('Are you sure you want to restore attached file?'), array($this, 'restore_file'), array($row['id'])), 'restore', __('Restore'));
         }
         $view_link = '';
         $lb = array();
         $lb['aid'] = $id;
         $lb['crypted'] = $attachment['crypted'];
         $lb['original'] = $row['original'];
         $lb['id'] = $row['id'];
         $lb['filestorage_id'] = $row['filestorage_id'];
         $file = '<a ' . Utils_AttachmentCommon::get_file_leightbox($lb, $view_link) . '>' . $row['original'] . '</a>';
         $r->add_data($row['deleted'] ? __('Yes') : __('No'), Base_RegionalSettingsCommon::time2reg($row['upload_on']), Base_UserCommon::get_user_label($row['upload_by']), $file);
     }
     $this->display_module($gb);
     $tb->end_tab();
     $tb->start_tab('File access history');
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'hda' . $id);
     $gb->set_inline_display();
     $gb->set_table_columns(array(array('name' => __('Create date'), 'order' => 'created_on', 'width' => 15), array('name' => __('Download date'), 'order' => 'download_on', 'width' => 15), array('name' => __('Who'), 'order' => 'created_by', 'width' => 15), array('name' => __('IP Address'), 'order' => 'ip_address', 'width' => 15), array('name' => __('Host Name'), 'order' => 'host_name', 'width' => 15), array('name' => __('Method description'), 'order' => 'description', 'width' => 20), array('name' => __('Remote'), 'order' => 'remote', 'width' => 10)));
     $gb->set_default_order(array(__('Create date') => 'DESC'));
     $query = 'SELECT uad.created_on,uad.download_on,(SELECT l.login FROM user_login l WHERE uad.created_by=l.id) as created_by,uad.remote,uad.ip_address,uad.host_name,uad.description FROM utils_attachment_download uad INNER JOIN utils_attachment_file uaf ON uaf.id=uad.attach_file_id WHERE uaf.attach_id=' . $id;
     $query_qty = 'SELECT count(*) FROM utils_attachment_download uad INNER JOIN utils_attachment_file uaf ON uaf.id=uad.attach_file_id WHERE uaf.attach_id=' . $id;
     if (Base_AclCommon::check_permission('Attachments - view full download history')) {
         $ret = $gb->query_order_limit($query, $query_qty);
     } else {
         print 'You are allowed to see your own downloads only';
         $who = ' AND uad.created_by=' . Acl::get_user();
         $ret = $gb->query_order_limit($query . $who, $query_qty . $who);
     }
     while ($row = $ret->FetchRow()) {
         $r = $gb->get_new_row();
         $r->add_data(Base_RegionalSettingsCommon::time2reg($row['created_on']), $row['remote'] != 1 ? Base_RegionalSettingsCommon::time2reg($row['download_on']) : '', $row['created_by'], $row['ip_address'], $row['host_name'], $row['description'], $row['remote'] == 0 ? 'no' : 'yes');
     }
     $this->display_module($gb);
     $tb->end_tab();
     $this->display_module($tb);
     $this->caption = 'Note history';
     return true;
 }
Ejemplo n.º 30
0
	public function body() {
		$gb = $this->init_module('Utils/GenericBrowser',null,'messages');
		$gb->set_table_columns(array(
			array('name'=>__('Alert on'), 'width'=>20),
			array('name'=>__('Message'), 'width'=>50),
			array('name'=>__('Users'), 'width'=>30)
				));
		$data = DB::GetAll('SELECT * FROM utils_messenger_message WHERE page_id=\''.$this->mid.'\'');
		foreach($data as & $row) {
			$row['users'] = DB::GetCol('SELECT user_login_id FROM utils_messenger_users WHERE message_id=\''.$row['id'].'\'');
			$r = & $gb->get_new_row();
			if(is_array($this->users)) {
				$us = '';
				foreach($row['users'] as $rr)
					if(isset($this->users[$rr])) 
						$us .= $this->users[$rr].'<br>';
			} else
				$us = Base_UserCommon::get_user_login($this->users);
				
			$r->add_data(Base_RegionalSettingsCommon::time2reg($row['alert_on']),$row['message'],$us);
			$r->add_action($this->create_callback_href(array($this,'push_box0'),array('edit',array($row),array($this->real_id,$this->callback_method,$this->callback_args,$this->def_date,$this->users))),'Edit');
			$r->add_action($this->create_confirm_callback_href(__('Are you sure?'),array($this,'delete_entry'),$row['id']),'Delete');
		}
		$this->display_module($gb);
		
		Base_ActionBarCommon::add('add',__('New alert'),$this->create_callback_href(array($this,'push_box0'),array('edit',array(false),array($this->real_id,$this->callback_method,$this->callback_args,$this->def_date,$this->users))));	
	}