[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare API - Record history logging * 4 * This file written by Joseph Engo <jengo@phpgroupware.org> * 5 * Copyright (C) 2001 Joseph Engo * 6 * -------------------------------------------------------------------------* 7 * This library is part of the eGroupWare API * 8 * http://www.egroupware.org/api * 9 * ------------------------------------------------------------------------ * 10 * This library is free software; you can redistribute it and/or modify it * 11 * under the terms of the GNU Lesser General Public License as published by * 12 * the Free Software Foundation; either version 2.1 of the License, * 13 * or any later version. * 14 * This library is distributed in the hope that it will be useful, but * 15 * WITHOUT ANY WARRANTY; without even the implied warranty of * 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 17 * See the GNU Lesser General Public License for more details. * 18 * You should have received a copy of the GNU Lesser General Public License * 19 * along with this library; if not, write to the Free Software Foundation, * 20 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 21 \**************************************************************************/ 22 23 // $Id: class.historylog.inc.php 20295 2006-02-15 12:31:25Z $ 24 25 class historylog 26 { 27 var $db; 28 var $table = 'egw_history_log'; 29 var $appname; 30 var $template; 31 var $nextmatchs; 32 var $types = array( 33 'C' => 'Created', 34 'D' => 'Deleted', 35 'E' => 'Edited' 36 ); 37 var $alternate_handlers = array(); 38 39 function historylog($appname='') 40 { 41 if (!$appname) 42 { 43 $appname = $GLOBALS['egw_info']['flags']['currentapp']; 44 } 45 $this->appname = $appname; 46 47 if (is_object($GLOBALS['egw_setup']->db)) 48 { 49 $this->db = clone($GLOBALS['egw_setup']->db); 50 } 51 else 52 { 53 $this->db = clone($GLOBALS['egw']->db); 54 } 55 $this->db->set_app('phpgwapi'); 56 } 57 58 function delete($record_id) 59 { 60 if (is_array($record_id) || is_numeric($record_id)) 61 { 62 $where = array( 63 'history_record_id' => $record_id, 64 'history_appname' => $this->appname, 65 ); 66 } 67 else 68 { 69 $where = array('history_appname' => $record_id); 70 } 71 $this->db->delete($this->table,$where,__LINE__,__FILE__); 72 73 return $this->db->affected_rows(); 74 } 75 76 function add($status,$record_id,$new_value,$old_value) 77 { 78 if ($new_value != $old_value) 79 { 80 $this->db->insert($this->table,array( 81 'history_record_id' => $record_id, 82 'history_appname' => $this->appname, 83 'history_owner' => $GLOBALS['egw_info']['user']['account_id'], 84 'history_status' => $status, 85 'history_new_value' => $new_value, 86 'history_old_value' => $old_value, 87 'history_timestamp' => time(), 88 ),false,__LINE__,__FILE__); 89 } 90 } 91 92 // array $filter_out 93 function return_array($filter_out,$only_show,$_orderby = '',$sort = '', $record_id) 94 { 95 96 if (!$_orderby || !preg_match('/^[a-z0-9_]+$/i',$_orderby) || !preg_match('/^(asc|desc)?$/i',$sort)) 97 { 98 $orderby = 'ORDER BY history_timestamp,history_id'; 99 } 100 else 101 { 102 $orderby = "ORDER BY $_orderby $sort"; 103 } 104 105 $where = array( 106 'history_appname' => $this->appname, 107 'history_record_id' => $record_id, 108 ); 109 if (is_array($filter_out)) 110 { 111 foreach($filter_out as $_filter) 112 { 113 $where[] = 'history_status != '.$this->db->quote($_filter); 114 } 115 } 116 if (is_array($only_show) && count($only_show)) 117 { 118 $to_or = array(); 119 foreach($only_show as $_filter) 120 { 121 $to_or[] = 'history_status = '.$this->db->quote($_filter); 122 } 123 $where[] = '('.implode(' OR ',$to_or).')'; 124 } 125 126 $this->db->select($this->table,'*',$where,__LINE__,__FILE__,false,$orderby); 127 while ($this->db->next_record()) 128 { 129 $return_values[] = array( 130 'id' => $this->db->f('history_id'), 131 'record_id' => $this->db->f('history_record_id'), 132 'owner' => $GLOBALS['egw']->accounts->id2name($this->db->f('history_owner')), 133 'status' => str_replace(' ','',$this->db->f('history_status')), 134 'new_value' => $this->db->f('history_new_value'), 135 'old_value' => $this->db->f('history_old_value'), 136 'datetime' => $this->db->from_timestamp($this->db->f('history_timestamp')) 137 ); 138 } 139 return $return_values; 140 } 141 142 function return_html($filter_out,$orderby = '',$sort = '', $record_id) 143 { 144 $this->template =& CreateObject('phpgwapi.Template',EGW_TEMPLATE_DIR); 145 $this->nextmatchs =& CreateObject('phpgwapi.nextmatchs'); 146 147 $this->template->set_file('_history','history_list.tpl'); 148 149 $this->template->set_block('_history','row_no_history'); 150 $this->template->set_block('_history','list'); 151 $this->template->set_block('_history','row'); 152 153 $this->template->set_var('lang_user',lang('User')); 154 $this->template->set_var('lang_date',lang('Date')); 155 $this->template->set_var('lang_action',lang('Action')); 156 $this->template->set_var('lang_new_value',lang('New Value')); 157 158 $this->template->set_var('th_bg',$GLOBALS['egw_info']['theme']['th_bg']); 159 $this->template->set_var('sort_date',lang('Date')); 160 $this->template->set_var('sort_owner',lang('User')); 161 $this->template->set_var('sort_status',lang('Status')); 162 $this->template->set_var('sort_new_value',lang('New value')); 163 $this->template->set_var('sort_old_value',lang('Old value')); 164 165 $values = $this->return_array($filter_out,array(),$orderby,$sort,$record_id); 166 167 if (!is_array($values)) 168 { 169 $this->template->set_var('tr_color',$GLOBALS['egw_info']['theme']['row_off']); 170 $this->template->set_var('lang_no_history',lang('No history for this record')); 171 $this->template->fp('rows','row_no_history'); 172 return $this->template->fp('out','list'); 173 } 174 175 foreach($values as $value) 176 { 177 $this->nextmatchs->template_alternate_row_color($this->template); 178 179 $this->template->set_var('row_date',$GLOBALS['egw']->common->show_date($value['datetime'])); 180 $this->template->set_var('row_owner',$value['owner']); 181 182 if ($this->alternate_handlers[$value['status']]) 183 { 184 eval('\$s = ' . $this->alternate_handlers[$value['status']] . '(' . $value['new_value'] . ');'); 185 $this->template->set_var('row_new_value',$s); 186 unset($s); 187 188 eval('\$s = ' . $this->alternate_handlers[$value['status']] . '(' . $value['old_value'] . ');'); 189 $this->template->set_var('row_old_value',$s); 190 unset($s); 191 } 192 else 193 { 194 $this->template->set_var('row_new_value',$value['new_value']); 195 $this->template->set_var('row_old_value',$value['old_value']); 196 } 197 198 $this->template->set_var('row_status',$this->types[$value['status']]); 199 200 $this->template->fp('rows','row',True); 201 } 202 return $this->template->fp('out','list'); 203 } 204 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |