[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - solog * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * This application written by Jerry Westrick <jerry@westrick.com> * |
---|
| 6 | * -------------------------------------------- * |
---|
| 7 | * Funding for this program was provided by http://www.checkwithmom.com * |
---|
| 8 | * -------------------------------------------- * |
---|
| 9 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 10 | * under the terms of the GNU General Public License as published by the * |
---|
| 11 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 12 | * option) any later version. * |
---|
| 13 | \**************************************************************************/ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | class solog |
---|
| 17 | { |
---|
| 18 | var $db; |
---|
| 19 | var $owner; |
---|
| 20 | var $error_cols = ''; |
---|
| 21 | var $error_cols_e = ''; |
---|
| 22 | var $public_functions = array( |
---|
| 23 | 'get_error_cols' => True, |
---|
| 24 | 'get_error_cols_e' => True, |
---|
| 25 | 'get_error' => True, |
---|
| 26 | 'get_error_e' => True |
---|
| 27 | ); |
---|
| 28 | |
---|
| 29 | function solog() |
---|
| 30 | { |
---|
| 31 | $this->db = $GLOBALS['phpgw']->db; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | function get_error_cols() |
---|
| 35 | { |
---|
| 36 | if ($this->error_cols == '') |
---|
| 37 | { |
---|
| 38 | $this->error_cols = array(); |
---|
| 39 | |
---|
| 40 | /* fields from phpgw_log table */ |
---|
| 41 | $clist = $this->db->metadata('phpgw_log'); |
---|
[7673] | 42 | $clist_count = count($clist); |
---|
| 43 | for ($i=0; $i<$clist_count; ++$i) |
---|
[2] | 44 | { |
---|
| 45 | $name = $clist[$i]['name']; |
---|
| 46 | $this->error_cols[$name] = array(); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | /* fields from phpgw_log_msg table */ |
---|
| 50 | $clist = $this->db->metadata('phpgw_log_msg'); |
---|
[7673] | 51 | $clist_count = count($clist); |
---|
| 52 | for ($i=0; $i<$clist_count; ++$i) |
---|
[2] | 53 | { |
---|
| 54 | $name = $clist[$i]['name']; |
---|
| 55 | $this->error_cols[$name] = array(); |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | return $this->error_cols; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | function get_error_cols_e() |
---|
| 62 | { |
---|
| 63 | if ($this->task_cols_e == '') |
---|
| 64 | { |
---|
| 65 | /* Get Columns for Errors */ |
---|
| 66 | $this->error_cols_e = $this->get_error_cols(); |
---|
| 67 | |
---|
| 68 | /* Enhance with Columns for phpgw_accounts */ |
---|
| 69 | $clist = $this->db->metadata('phpgw_accounts'); |
---|
[7673] | 70 | $clist_count = count($clist); |
---|
| 71 | for ($i=0; $i<$clist_count; ++$i) |
---|
[2] | 72 | { |
---|
| 73 | $name = $clist[$i]['name']; |
---|
| 74 | $this->error_cols_e[$name] = array(); |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | return $this->error_cols_e; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | function get_error_e($parms) |
---|
| 81 | { |
---|
| 82 | |
---|
| 83 | /* Fixed From */ |
---|
| 84 | if (!isset($parms['from'])) |
---|
| 85 | { |
---|
| 86 | $parms['from'] = array('phpgw_accounts'); |
---|
| 87 | } |
---|
| 88 | else |
---|
| 89 | { |
---|
| 90 | $parms['from'][] = 'phpgw_accounts'; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | /* Fix Where */ |
---|
| 94 | if (!isset($parms['where'])) |
---|
| 95 | { |
---|
| 96 | $parms['where'] = array('phpgw_log.log_user = phpgw_accounts.account_id'); |
---|
| 97 | } |
---|
| 98 | else |
---|
| 99 | { |
---|
| 100 | $parms['where'][] = 'phpgw_log.log_user = phpgw_accounts.account_id'; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /* Fix Default Fields */ |
---|
| 104 | if (!isset($parms['fields'])) |
---|
| 105 | { |
---|
| 106 | $parms['fields'] = $this->get_error_cols_e(); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | return $this->get_error($parms); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | function get_no_errors() |
---|
| 113 | { |
---|
| 114 | /* Get max ErrorId */ |
---|
| 115 | $this->db->query("select count(*) as max_id from phpgw_log, phpgw_log_msg WHERE phpgw_log.log_id = phpgw_log_msg.log_msg_log_id",__LINE__,__FILE__); |
---|
| 116 | $this->db->next_record(); |
---|
| 117 | return $this->db->f('max_id'); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | function get_error($parms) |
---|
| 121 | { |
---|
| 122 | /* Get parameter values */ |
---|
| 123 | $from = $parms['from']; |
---|
| 124 | $where = $parms['where']; |
---|
| 125 | $orderby = $parms['orderby']; |
---|
| 126 | $fields = $parms['fields']; |
---|
| 127 | |
---|
| 128 | /* Build From_Clause */ |
---|
| 129 | $from_clause = 'FROM phpgw_log, phpgw_log_msg '; |
---|
| 130 | if (isset($from)) |
---|
| 131 | { |
---|
| 132 | $from[] = 'phpgw_log'; |
---|
| 133 | $from[] = 'phpgw_log_msg'; |
---|
| 134 | $from_clause = 'FROM '.implode(', ' , $from).' '; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | /* Build Where_Clause */ |
---|
| 138 | $where_clause = 'WHERE phpgw_log.log_id = phpgw_log_msg.log_msg_log_id '; |
---|
| 139 | if (isset($where)) |
---|
| 140 | { |
---|
| 141 | $where[] = 'phpgw_log.log_id = phpgw_log_msg.log_msg_log_id'; |
---|
| 142 | $where_clause = 'WHERE ' . implode(' AND ',$where) . ' '; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | /* Build Order_By_Clause */ |
---|
| 146 | $orderby_clause = 'ORDER BY phpgw_log.log_id, phpgw_log_msg.log_msg_seq_no '; |
---|
| 147 | if (isset($orderby)) |
---|
| 148 | { |
---|
| 149 | $orderby_clause = 'ORDER BY ' . implode(', ',$orderby); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | /* If no Fields specified default to * */ |
---|
| 153 | if (!isset($fields)) |
---|
| 154 | { |
---|
| 155 | $fields = $this->get_error_cols(); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | $rows = array(); |
---|
| 159 | |
---|
| 160 | /* Do Select */ |
---|
| 161 | @reset($fields); |
---|
| 162 | while(list($key,$val) = @each($fields)) |
---|
| 163 | { |
---|
| 164 | $fkeys .= $key . ','; |
---|
| 165 | } |
---|
| 166 | $fkeys = substr($fkeys,0,-1); |
---|
| 167 | |
---|
| 168 | $select = 'SELECT ' . $fkeys . ' ' . $from_clause . $where_clause . $orderby_clause; |
---|
| 169 | $this->db->query($select,__LINE__,__FILE__); |
---|
| 170 | while($this->db->next_record()) |
---|
| 171 | { |
---|
| 172 | reset($fields); |
---|
| 173 | while(list($fname,$fopt) = each($fields)) |
---|
| 174 | { |
---|
| 175 | $this_row[$fname]['value'] = $this->db->f($fname); |
---|
| 176 | } |
---|
| 177 | $rows[] = $this_row; |
---|
| 178 | } |
---|
| 179 | return $rows; |
---|
| 180 | } |
---|
| 181 | } |
---|