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; }
public function view_entry($mode='view', $id = null, $defaults = array(), $show_actions=true) { Base_HelpCommon::screen_name('rb_'.$mode.'_'.$this->tab); if (isset($_SESSION['client']['recordbrowser']['admin_access'])) Utils_RecordBrowserCommon::$admin_access = true; self::$mode = $mode; if ($this->navigation_executed) { $this->navigation_executed = false; return true; } if ($this->check_for_jump()) return; $theme = $this->init_module('Base/Theme'); if ($this->isset_module_variable('id')) { $id = $this->get_module_variable('id'); $this->unset_module_variable('id'); } self::$browsed_records = null; Utils_RecordBrowserCommon::$cols_order = array(); $js = ($mode!='view'); $time = microtime(true); if ($this->is_back()) { self::$clone_result = 'canceled'; return $this->back(); } $this->init(); if (is_numeric($id)) { $id = intVal($id); self::$last_record = $this->record = Utils_RecordBrowserCommon::get_record($this->tab, $id, $mode!=='edit'); } else { self::$last_record = $this->record = $id; $id = intVal($this->record['id']); } if ($id===0) $id = null; if ($id!==null && is_numeric($id)) Utils_WatchdogCommon::notified($this->tab,$id); if($mode=='add') { foreach ($defaults as $k=>$v) $this->custom_defaults[$k] = $v; foreach($this->table_rows as $field => $args) if (!isset($this->custom_defaults[$args['id']])) $this->custom_defaults[$args['id']] = $args['type'] == 'multiselect' ? array() : ''; $this->custom_defaults['created_by'] = Acl::get_user(); } $access = $this->get_access($mode=='history'?'view':$mode, isset($this->record)?$this->record:$this->custom_defaults); if ($mode=='edit' || $mode=='add') $this->view_fields_permission = $this->get_access('view', isset($this->record)?$this->record:$this->custom_defaults); else $this->view_fields_permission = $access; if ($mode!='add' && (!$access || $this->record==null)) { if (Base_AclCommon::i_am_admin()) { Utils_RecordBrowserCommon::$admin_access = true; $access = $this->get_access($mode, isset($this->record)?$this->record:$this->custom_defaults); if ($mode=='edit' || $mode=='add') $this->view_fields_permission = $this->get_access('view', isset($this->record)?$this->record:$this->custom_defaults); else $this->view_fields_permission = $access; } else { print(__('You don\'t have permission to view this record.')); if ($show_actions===true || (is_array($show_actions) && (!isset($show_actions['back']) || $show_actions['back']))) { Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); //Utils_ShortcutCommon::add(array('esc'), 'function(){'.$this->create_back_href_js().'}'); } return true; } } if ($mode=='add' && !$access) { print(__('You don\'t have permission to perform this action.')); if ($show_actions===true || (is_array($show_actions) && (!isset($show_actions['back']) || $show_actions['back']))) { Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); //Utils_ShortcutCommon::add(array('esc'), 'function(){'.$this->create_back_href_js().'}'); } return true; } if($mode == 'add' || $mode == 'edit') { $theme -> assign('click2fill', '<div id="c2fBox"></div>'); load_js('modules/Utils/RecordBrowser/click2fill.js'); eval_js('initc2f("'.__('Scan/Edit').'","'.__('Paste data here with Ctrl-v, click button below, then click on separated words in specific order and click in text field where you want put those words. They will replace text in that field.').'")'); Base_ActionBarCommon::add('clone', __('Click 2 Fill'), 'href="javascript:void(0)" onclick="c2f()"'); } // if ($mode!='add' && !$this->record[':active'] && !Base_AclCommon::i_am_admin()) return $this->back(); $tb = $this->init_module('Utils/TabbedBrowser', null, 'recordbrowser_addons'); if ($mode=='history') $tb->set_inline_display(); self::$tab_param = $tb->get_path(); $form = $this->init_module('Libs/QuickForm',null, $mode); if(Base_User_SettingsCommon::get($this->get_type(), 'confirm_leave') && ($mode == 'add' || $mode == 'edit')) $form->set_confirm_leave_page(); $this->form = $form; if($mode!='add') Utils_RecordBrowserCommon::add_recent_entry($this->tab, Acl::get_user(),$id); $dp = Utils_RecordBrowserCommon::record_processing($this->tab, $mode!='add'?$this->record:$this->custom_defaults, ($mode=='view' || $mode=='history')?'view':$mode.'ing'); if($dp===false) return false; if (is_array($dp)) $defaults = $this->custom_defaults = self::$last_record = $this->record = $dp; if (self::$last_record===null) self::$last_record = $defaults; if($mode=='add') $form->setDefaults($defaults); switch ($mode) { case 'add': $this->action = _M('New record'); break; case 'edit': $this->action = _M('Edit record'); break; case 'view': $this->action = _M('View record'); break; case 'history': $this->action = _M('Record history view'); break; } $this->prepare_view_entry_details($this->record, $mode=='history'?'view':$mode, $id, $form); if ($mode==='edit' || $mode==='add') foreach($this->table_rows as $field => $args) { if (!$access[$args['id']]) $form->freeze($args['id']); } if ($form->exportValue('submited') && $form->validate()) { $values = $form->exportValues(); foreach ($defaults as $k=>$v) { if (!isset($values[$k]) && isset($this->view_fields_permission[$k]) && !$this->view_fields_permission[$k]) $values[$k] = $v; if (isset($access[$k]) && !$access[$k]) $values[$k] = $v; } foreach ($this->table_rows as $v) { if ($v['type']=='checkbox' && !isset($values[$v['id']])) $values[$v['id']]=0; } $values['id'] = $id; foreach ($this->custom_defaults as $k=>$v) if (!isset($values[$k])) $values[$k] = $v; if ($mode=='add') { $id = Utils_RecordBrowserCommon::new_record($this->tab, $values); self::$clone_result = $id; self::$clone_tab = $this->tab; return $this->back(); } $time_from = date('Y-m-d H:i:s', $this->get_module_variable('edit_start_time')); $ret = DB::Execute('SELECT * FROM '.$this->tab.'_edit_history WHERE edited_on>=%T AND edited_on<=%T AND '.$this->tab.'_id=%d',array($time_from, date('Y-m-d H:i:s'), $id)); if ($ret->EOF) { $this->update_record($id,$values); return $this->back(); } $this->dirty_read_changes($id, $time_from); } $form->add_error_closing_buttons(); if (($mode=='edit' || $mode=='add') && $show_actions!==false) { Utils_ShortcutCommon::add(array('Ctrl','S'), 'function(){'.$form->get_submit_form_js().'}'); } if ($mode=='edit') { $this->set_module_variable('edit_start_time',$time); } if ($show_actions!==false) { if ($mode=='view') { if ($this->get_access('edit',$this->record)) { Base_ActionBarCommon::add('edit', __('Edit'), $this->create_callback_href(array($this,'navigate'), array('view_entry','edit',$id))); Utils_ShortcutCommon::add(array('Ctrl','E'), 'function(){'.$this->create_callback_href_js(array($this,'navigate'), array('view_entry','edit',$id)).'}'); } if ($this->get_access('delete',$this->record)) { Base_ActionBarCommon::add('delete', __('Delete'), $this->create_confirm_callback_href(__('Are you sure you want to delete this record?'),array($this,'delete_record'),array($id))); } if ($this->get_access('add',$this->record)) { Base_ActionBarCommon::add('clone',__('Clone'), $this->create_confirm_callback_href(__('You are about to create a copy of this record. Do you want to continue?'),array($this,'clone_record'),array($id))); } /** @var Base_Print_Printer $printer */ $printer = Utils_RecordBrowserCommon::get_printer($this->tab); if ($printer) { Base_ActionBarCommon::add('print', __('Print'), $printer->get_href(array('tab' => $this->tab, 'record_id' => $this->record['id']))); } if ($show_actions===true || (is_array($show_actions) && (!isset($show_actions['back']) || $show_actions['back']))) Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); } elseif($mode!='history') { Base_ActionBarCommon::add('save', __('Save'), $form->get_submit_form_href()); Base_ActionBarCommon::add('delete', __('Cancel'), $this->create_back_href()); } //Utils_ShortcutCommon::add(array('esc'), 'function(){'.$this->create_back_href_js().'}'); } if ($mode!='add') { $theme -> assign('info_tooltip', '<a '.Utils_TooltipCommon::open_tag_attrs(Utils_RecordBrowserCommon::get_html_record_info($this->tab, $id)).'><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils_RecordBrowser','info.png').'" /></a>'); $row_data= array(); if ($mode!='history') { if ($this->favorites) $theme -> assign('fav_tooltip', Utils_RecordBrowserCommon::get_fav_button($this->tab, $id)); if ($this->watchdog) $theme -> assign('subscription_tooltip', Utils_WatchdogCommon::get_change_subscription_icon($this->tab, $id)); if ($this->full_history) { $info = Utils_RecordBrowserCommon::get_record_info($this->tab, $id); if ($info['edited_on']===null) $theme -> assign('history_tooltip', '<a '.Utils_TooltipCommon::open_tag_attrs(__('This record was never edited')).'><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils_RecordBrowser','history_inactive.png').'" /></a>'); else $theme -> assign('history_tooltip', '<a '.Utils_TooltipCommon::open_tag_attrs(__('Click to view edit history of currently displayed record')).' '.$this->create_callback_href(array($this,'navigate'), array('view_edit_history', $id)).'><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils_RecordBrowser','history.png').'" /></a>'); } if ($this->clipboard_pattern) { $theme -> assign('clipboard_tooltip', '<a '.Utils_TooltipCommon::open_tag_attrs(__('Click to export values to copy')).' '.Libs_LeightboxCommon::get_open_href('clipboard').'><img border="0" src="'.Base_ThemeCommon::get_template_file('Utils_RecordBrowser','clipboard.png').'" /></a>'); $text = $this->clipboard_pattern; $record = Utils_RecordBrowserCommon::get_record($this->tab, $id); /* for every field name store its value */ $data = array(); foreach($this->table_rows as $val) { $fval = Utils_RecordBrowserCommon::get_val($this->tab, $val['id'], $record, true); if(strlen($fval)) $data[$val['id']] = $fval; } /* some complicate preg match to find every occurence * of %{ .. {f_name} .. } pattern */ if (preg_match_all('/%\{(([^%\}\{]*?\{[^%\}\{]+?\}[^%\}\{]*?)+?)\}/', $text, $match)) { // match for all patterns %{...{..}...} foreach ($match[0] as $k => $matched_string) { $text_replace = $match[1][$k]; $changed = false; while(preg_match('/\{(.+?)\}/', $text_replace, $second_match)) { // match for keys in braces {key} $replace_value = ''; if(array_key_exists($second_match[1], $data)) { $replace_value = $data[$second_match[1]]; $changed = true; } $text_replace = str_replace($second_match[0], $replace_value, $text_replace); } if(! $changed ) $text_replace = ''; $text = str_replace($matched_string, $text_replace, $text); } } load_js("modules/Utils/RecordBrowser/selecttext.js"); /* remove all php new lines, replace <br>|<br/> to new lines and quote all special chars */ $ftext = htmlspecialchars(preg_replace('#<[bB][rR]/?>#', "\n", str_replace("\n", '', $text))); $flash_copy = '<object width="60" height="20">'. '<param name="FlashVars" value="txtToCopy='.$ftext.'">'. '<param name="movie" value="'.$this->get_module_dir().'copyButton.swf">'. '<embed src="'.$this->get_module_dir().'copyButton.swf" flashvars="txtToCopy='.$ftext.'" width="60" height="20">'. '</embed>'. '</object>'; $text = '<h3>'.__('Click Copy under the box or move mouse over box below to select text and hit Ctrl-c to copy it.').'</h3><div onmouseover="fnSelect(this)" style="border: 1px solid gray; margin: 15px; padding: 20px;">'.$text.'</div>'.$flash_copy; Libs_LeightboxCommon::display('clipboard',$text,__('Copy')); } } } if ($mode=='view') { $dp = Utils_RecordBrowserCommon::record_processing($this->tab, $this->record, 'display'); if ($dp && is_array($dp)) foreach ($dp as $k=>$v) $theme->assign($k, $v); } if ($mode=='view' || $mode=='history') $form->freeze(); $renderer = new HTML_QuickForm_Renderer_TCMSArraySmarty(); $form->accept($renderer); $data = $renderer->toArray(); print($data['javascript'].'<form '.$data['attributes'].'>'.$data['hidden']."\n"); $last_page = DB::GetOne('SELECT MIN(position) FROM '.$this->tab.'_field WHERE type = \'page_split\' AND field != \'General\''); if (!$last_page) $last_page = DB::GetOne('SELECT MAX(position) FROM '.$this->tab.'_field')+1; $label = DB::GetRow('SELECT field, param FROM '.$this->tab.'_field WHERE position=%s', array($last_page)); if ($label) { $cols = $label['param']; $label = $label['field']; } else $cols = false; $this->view_entry_details(1, $last_page, $data, $theme, true); $ret = DB::Execute('SELECT position, field, param FROM '.$this->tab.'_field WHERE type = \'page_split\' AND position > %d ORDER BY position', array($last_page)); $row = true; if ($mode=='view') print("</form>\n"); $tab_counter=-1; $additional_tabs = 0; $default_tab = null; while ($row) { $row = $ret->FetchRow(); if ($row) $pos = $row['position']; else $pos = DB::GetOne('SELECT MAX(position) FROM '.$this->tab.'_field WHERE active=1')+1; $valid_page = false; $hide_page = ($mode=='view' && Base_User_SettingsCommon::get('Utils/RecordBrowser','hide_empty')); foreach($this->table_rows as $field => $args) { if (!isset($data[$args['id']]) || $data[$args['id']]['type']=='hidden') continue; if ($args['position'] >= $last_page && ($pos+1 == -1 || $args['position'] < $pos+1)) { $valid_page = true; if ($hide_page && !$this->field_is_empty($this->record, $args['id'])) $hide_page = false; break; } } if ($valid_page && $pos - $last_page>1 && !isset($this->hide_tab[$label])) { $tb->set_tab(_V($label),array($this,'view_entry_details'), array($last_page, $pos+1, $data, null, false, $cols, _V($label)), $js); // TRSL if ($hide_page) { eval_js('$("'.$tb->get_tab_id(_V($label)).'").style.display="none";'); if ($default_tab===($tab_counter+1) || $tb->get_tab()==($tab_counter+1)) $default_tab = $tab_counter+2; } else $additional_tabs++; } $cols = $row['param']; $last_page = $pos; if ($row) $label = $row['field']; $tab_counter++; } if ($default_tab!==null) $tb->set_default_tab($default_tab); if ($mode!='history') { $ret = DB::Execute('SELECT * FROM recordbrowser_addon WHERE tab=%s AND enabled=1 ORDER BY pos', array($this->tab)); $addons_mod = array(); while ($row = $ret->FetchRow()) { if (ModuleManager::is_installed($row['module'])==-1) continue; if (is_callable(explode('::',$row['label']))) { $result = call_user_func(explode('::',$row['label']), $this->record, $this); if (!isset($result['show'])) $result['show']=true; if (($mode=='add' || $mode=='edit') && (!isset($result['show_in_edit']) || !$result['show_in_edit'])) continue; if ($result['show']==false) continue; if (!isset($result['label'])) $result['label']=''; $row['label'] = $result['label']; } else { if ($mode=='add' || $mode=='edit') continue; $labels = explode('#',$row['label']); foreach($labels as $i=>$label) $labels[$i] = _V($label); // translate labels from database $row['label'] = implode('#',$labels); } $mod_id = md5(serialize($row)); if (method_exists($row['module'].'Common',$row['func'].'_access') && !call_user_func(array($row['module'].'Common',$row['func'].'_access'), $this->record, $this)) continue; $addons_mod[$mod_id] = $this->init_module($row['module']); if (!method_exists($addons_mod[$mod_id],$row['func'])) $tb->set_tab($row['label'],array($this, 'broken_addon'), array(), $js); else $tb->set_tab($row['label'],array($this, 'display_module'), array(& $addons_mod[$mod_id], array($this->record, $this), $row['func']), $js); } } if ($additional_tabs==0 && ($mode=='add' || $mode=='edit' || $mode=='history')) print("</form>\n"); $this->display_module($tb); $tb->tag(); foreach ($this->fields_in_tabs as $label=>$fields) { $highlight = false; foreach ($fields as $f) { $err = $form->getElementError($f); if ($err) { $highlight = true; break; } } if ($highlight) $tb->tab_icon($label, Base_ThemeCommon::get_template_file('Utils_RecordBrowser','notify_error.png')); } if ($this->switch_to_addon) { $this->set_module_variable('switch_to_addon',false); if($tab_counter<0) $tab_counter=0; $ret = DB::Execute('SELECT * FROM recordbrowser_addon WHERE tab=%s AND enabled=1 ORDER BY pos', array($this->tab)); while ($row = $ret->FetchRow()) { if (ModuleManager::is_installed($row['module'])==-1) continue; if (is_callable(explode('::',$row['label']))) { $result = call_user_func(explode('::',$row['label']), $this->record,$this); if (isset($result['show']) && $result['show']==false) continue; $row['label'] = $result['label']; } if ($row['label']==$this->switch_to_addon) $this->switch_to_addon = $tab_counter; $tab_counter++; } $tb->switch_tab($this->switch_to_addon); location(array()); } if ($additional_tabs!=0 && ($mode=='add' || $mode=='edit' || $mode=='history')) print("</form>\n"); return true; } //view_entry
<?php /** * * @author Arkadiusz Bisaga <*****@*****.**> * @copyright Copyright © 2008, Telaxus LLC * @license MIT * @version 1.0 * @package epesi-utils * @subpackage Watchdog */ if (!isset($_POST['key']) || !isset($_POST['cid']) || !is_numeric($_POST['cid'])) { die('alert(\'Invalid request\')'); } define('CID', $_POST['cid']); define('READ_ONLY_SESSION', true); require_once '../../../include.php'; ModuleManager::load_modules(); if (!Acl::is_user()) { die('Unauthorized access'); } list($cat_id, $id) = explode('__', $_POST['key']); if (!is_numeric($cat_id) || !is_numeric($id)) { die('Invalid use'); } Utils_WatchdogCommon::notified($cat_id, $id);
public static function notification() { /*$methods = DB::GetAssoc('SELECT id,callback FROM utils_watchdog_category'); foreach ($methods as $k=>$v) { $methods[$k] = explode('::',$v); } $time_sql = $time ? ' AND uwe.event_time > %T' : ''; $only_new = " AND last_seen_event<(SELECT MAX(id) FROM utils_watchdog_event AS uwe WHERE uwe.internal_id=uws.internal_id AND uwe.category_id=uws.category_id$time_sql)"; $args = array(Acl::get_user()); if ($time) { $args[] = $time; } $records = DB::GetAll('SELECT internal_id,category_id,last_seen_event FROM utils_watchdog_subscription AS uws WHERE user_id=%d '.$only_new, $args); $ret = array(); $tray = array(); if ($records) { $last_event_id = DB::GetOne('SELECT MAX(id) FROM utils_watchdog_event'); foreach ($records as $v) { $changes = Utils_WatchdogCommon::check_if_notified($v['category_id'], $v['internal_id']); if (!is_array($changes)) $changes = array(); $data = call_user_func($methods[$v['category_id']], $v['internal_id'], $changes, false); if ($data==null) continue; $msg = __("You've got unread notifications"); $ret['watchdog_'. $last_event_id] = '<b>'.__('Watchdog - %s', array($msg)).'</b> '; $tray['watchdog_' . $last_event_id] = array('title'=>__('Watchdog'), 'body'=>$msg); break; } }*/ $ret = array(); $tray = array(); $methods = DB::GetAssoc('SELECT id,callback FROM utils_watchdog_category'); $only_new = ' AND last_seen_event<(SELECT MAX(id) FROM utils_watchdog_event AS uwe WHERE uwe.internal_id=uws.internal_id AND uwe.category_id=uws.category_id)'; $records = DB::GetAll('SELECT internal_id,category_id FROM utils_watchdog_subscription AS uws WHERE user_id=%d ' . $only_new, array(Acl::get_user())); foreach ($records as $rec_key => $w) { $k = $w['internal_id']; $v = $w['category_id']; $changes = Utils_WatchdogCommon::check_if_notified($v, $k); if (!is_array($changes)) { $changes = array(); } $data = call_user_func($methods[$v], $k, $changes); if ($data == null) { // mark events as seen when user can't see them Utils_WatchdogCommon::notified($v, $k); unset($records[$rec_key]); continue; } $ret['watchdog_' . $v . '_' . $k] = '<b>' . __('Watchdog - %s: %s', array($data['category'], $data['title'])) . '</b>' . (isset($data['events']) ? '<br />' . $data['events'] : ''); $tray['watchdog_' . $v . '_' . $k] = array('title' => __('Watchdog - %s', array($data['category'])), 'body' => $data['title']); } return array('notifications' => $ret, 'tray' => $tray); }
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; }
public function applet($conf, &$opts) { $categories = array(); $methods = DB::GetAssoc('SELECT id,callback FROM utils_watchdog_category'); foreach ($methods as $k => $v) { $methods[$k] = explode('::', $v); if (isset($conf['category_' . $k]) && $conf['category_' . $k] && is_numeric($k)) { $categories[] = $k; } } if (empty($categories)) { print __('No category selected'); return; } $records_limit = isset($conf['records_limit']) ? $conf['records_limit'] : 15; if ($records_limit == '__all__') { $records_limit = null; } $header = array(array('name' => __('Cat.'), 'width' => 5), array('name' => __('Title'), 'width' => 15)); if (count($categories) == 1) { $title = call_user_func($methods[$categories[0]]); $opts['title'] = __('Watchdog - %s', array($title['category'])); $header = array(array('name' => __('Title'))); } elseif (count($categories) == count($methods)) { $opts['title'] = __('Watchdog - All'); } else { $opts['title'] = __('Watchdog - Selection'); } $only_new = ' AND last_seen_event<(SELECT MAX(id) FROM utils_watchdog_event AS uwe WHERE uwe.internal_id=uws.internal_id AND uwe.category_id=uws.category_id)'; $records = DB::GetAll('SELECT internal_id,category_id FROM utils_watchdog_subscription AS uws WHERE user_id=%d ' . $only_new . 'AND category_id IN (' . implode(',', $categories) . ')', array(Acl::get_user())); $gb = $this->init_module(Utils_GenericBrowser::module_name(), 'subscriptions', 'subscriptions'); $gb->set_table_columns($header); $something_to_purge = false; $count = 0; foreach ($records as $rec_key => $w) { $k = $w['internal_id']; $v = $w['category_id']; $changes = Utils_WatchdogCommon::check_if_notified($v, $k); if (!is_array($changes)) { $changes = array(); } $data = call_user_func($methods[$v], $k, $changes); if ($data == null) { // mark events as seen when user can't see them Utils_WatchdogCommon::notified($v, $k); unset($records[$rec_key]); continue; } $gb_row = $gb->get_new_row(); if (count($categories) == 1) { $gb_row->add_data($data['title']); } else { $gb_row->add_data($data['category'], $data['title']); } $gb_row->add_action(Utils_WatchdogCommon::get_confirm_change_subscr_href($v, $k), 'Stop Watching', __('Click to stop watching this record for changes'), Base_ThemeCommon::get_template_file(Utils_Watchdog::module_name(), 'watching_small_new_events.png')); $gb_row->add_action($data['view_href'], 'View'); if ($only_new || Utils_WatchdogCommon::check_if_notified($v, $k) !== true) { $gb_row->set_attrs('name="watchdog_table_row_' . $v . '__' . $k . '"'); load_js('modules/Utils/Watchdog/applet_mark_as_read.js'); $gb_row->add_action('href="javascript:void(0);" onclick="watchdog_applet_mark_as_read(\'' . $v . '__' . $k . '\')"', 'Mark as Read', __('Mark as read'), Base_ThemeCommon::get_template_file(Utils_Watchdog::module_name(), 'mark_as_read.png')); $something_to_purge = true; } if (isset($data['events']) && $data['events']) { $gb_row->add_info($data['events'], true); } $count++; if ($records_limit && $count >= $records_limit) { break; } } $records_qty = count($records); if ($records_limit && $count < $records_qty) { print __('Displaying %s of %s records', array($count, $records_qty)); } $this->set_module_variable('display_at_time', time()); if ($something_to_purge) { $opts['actions'][] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('Mark all entries as read')) . ' ' . $this->create_confirm_callback_href(__('This will mark all entries in selected categories as read, are you sure you want to continue?'), array($this, 'purge_subscriptions_applet'), array($categories)) . '><img src="' . Base_ThemeCommon::get_template_file('Utils_Watchdog', 'purge.png') . '" border="0"></a>'; } $this->display_module($gb); }
public function notified($cat_id, $id) { Utils_WatchdogCommon::notified($cat_id, $id); location(array()); return false; }
public static function new_event($category_name, $id, $message) { if(self::$disabled) return; $category_id = self::get_category_id($category_name, false); if (!$category_id) return; DB::Execute('INSERT INTO utils_watchdog_event (category_id, internal_id, message, event_time) VALUES (%d,%d,%s,%T)',array($category_id,$id,$message,time())); $event_id = DB::Insert_ID('utils_watchdog_event', 'id'); Utils_WatchdogCommon::notified($category_name,$id); $count = DB::GetOne('SELECT COUNT(*) FROM utils_watchdog_event WHERE category_id=%d AND internal_id=%d', array($category_id,$id)); if ($count==1) { $subscribers = self::get_subscribers($category_id); foreach ($subscribers as $s) self::user_subscribe($s, $category_name, $id); } $subscribers = self::get_subscribers($category_name, $id); $c_user = Acl::get_user(); self::email_mode(true); foreach ($subscribers as $user_id) { if ($user_id==$c_user) continue; $wants_email = Base_User_SettingsCommon::get('Utils_Watchdog', 'email', $user_id); if (!$wants_email) continue; Acl::set_user($user_id); Base_LangCommon::load(); $email_data = self::display_events($category_id, array($event_id => $message), $id, true); if (!$email_data) continue; $contact = Utils_RecordBrowserCommon::get_id('contact', 'login', $user_id); if (!$contact) continue; $email = Utils_RecordBrowserCommon::get_value('contact', $contact, 'email'); if (!$email) continue; $title = __('%s notification - %s - %s', array(EPESI, $email_data['category'], strip_tags($email_data['title']))); Base_MailCommon::send($email, $title, $email_data['events'], null, null, true); } Acl::set_user($c_user); Base_LangCommon::load(); self::email_mode(false); }