[763] | 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'); |
---|
| 42 | for ($i=0; $i<count($clist); $i++) |
---|
| 43 | { |
---|
| 44 | $name = $clist[$i]['name']; |
---|
| 45 | $this->error_cols[$name] = array(); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | /* fields from phpgw_log_msg table */ |
---|
| 49 | $clist = $this->db->metadata('phpgw_log_msg'); |
---|
| 50 | for ($i=0; $i<count($clist); $i++) |
---|
| 51 | { |
---|
| 52 | $name = $clist[$i]['name']; |
---|
| 53 | $this->error_cols[$name] = array(); |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | return $this->error_cols; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | function get_error_cols_e() |
---|
| 60 | { |
---|
| 61 | if ($this->task_cols_e == '') |
---|
| 62 | { |
---|
| 63 | /* Get Columns for Errors */ |
---|
| 64 | $this->error_cols_e = $this->get_error_cols(); |
---|
| 65 | |
---|
| 66 | /* Enhance with Columns for phpgw_accounts */ |
---|
| 67 | $clist = $this->db->metadata('phpgw_accounts'); |
---|
| 68 | for ($i=0; $i<count($clist); $i++) |
---|
| 69 | { |
---|
| 70 | $name = $clist[$i]['name']; |
---|
| 71 | $this->error_cols_e[$name] = array(); |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | return $this->error_cols_e; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | function get_error_e($parms) |
---|
| 78 | { |
---|
| 79 | |
---|
| 80 | /* Fixed From */ |
---|
| 81 | if (!isset($parms['from'])) |
---|
| 82 | { |
---|
| 83 | $parms['from'] = array('phpgw_accounts'); |
---|
| 84 | } |
---|
| 85 | else |
---|
| 86 | { |
---|
| 87 | $parms['from'][] = 'phpgw_accounts'; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | /* Fix Where */ |
---|
| 91 | if (!isset($parms['where'])) |
---|
| 92 | { |
---|
| 93 | $parms['where'] = array('phpgw_log.log_user = phpgw_accounts.account_id'); |
---|
| 94 | } |
---|
| 95 | else |
---|
| 96 | { |
---|
| 97 | $parms['where'][] = 'phpgw_log.log_user = phpgw_accounts.account_id'; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | /* Fix Default Fields */ |
---|
| 101 | if (!isset($parms['fields'])) |
---|
| 102 | { |
---|
| 103 | $parms['fields'] = $this->get_error_cols_e(); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | return $this->get_error($parms); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | function get_no_errors() |
---|
| 110 | { |
---|
| 111 | /* Get max ErrorId */ |
---|
| 112 | $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__); |
---|
| 113 | $this->db->next_record(); |
---|
| 114 | return $this->db->f('max_id'); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | function get_error($parms) |
---|
| 118 | { |
---|
| 119 | /* Get parameter values */ |
---|
| 120 | $from = $parms['from']; |
---|
| 121 | $where = $parms['where']; |
---|
| 122 | $orderby = $parms['orderby']; |
---|
| 123 | $fields = $parms['fields']; |
---|
| 124 | |
---|
| 125 | /* Build From_Clause */ |
---|
| 126 | $from_clause = 'FROM phpgw_log, phpgw_log_msg '; |
---|
| 127 | if (isset($from)) |
---|
| 128 | { |
---|
| 129 | $from[] = 'phpgw_log'; |
---|
| 130 | $from[] = 'phpgw_log_msg'; |
---|
| 131 | $from_clause = 'FROM '.implode(', ' , $from).' '; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /* Build Where_Clause */ |
---|
| 135 | $where_clause = 'WHERE phpgw_log.log_id = phpgw_log_msg.log_msg_log_id '; |
---|
| 136 | if (isset($where)) |
---|
| 137 | { |
---|
| 138 | $where[] = 'phpgw_log.log_id = phpgw_log_msg.log_msg_log_id'; |
---|
| 139 | $where_clause = 'WHERE ' . implode(' AND ',$where) . ' '; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /* Build Order_By_Clause */ |
---|
| 143 | $orderby_clause = 'ORDER BY phpgw_log.log_id, phpgw_log_msg.log_msg_seq_no '; |
---|
| 144 | if (isset($orderby)) |
---|
| 145 | { |
---|
| 146 | $orderby_clause = 'ORDER BY ' . implode(', ',$orderby); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | /* If no Fields specified default to * */ |
---|
| 150 | if (!isset($fields)) |
---|
| 151 | { |
---|
| 152 | $fields = $this->get_error_cols(); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | $rows = array(); |
---|
| 156 | |
---|
| 157 | /* Do Select */ |
---|
| 158 | @reset($fields); |
---|
| 159 | while(list($key,$val) = @each($fields)) |
---|
| 160 | { |
---|
| 161 | $fkeys .= $key . ','; |
---|
| 162 | } |
---|
| 163 | $fkeys = substr($fkeys,0,-1); |
---|
| 164 | |
---|
| 165 | $select = 'SELECT ' . $fkeys . ' ' . $from_clause . $where_clause . $orderby_clause; |
---|
| 166 | $this->db->query($select,__LINE__,__FILE__); |
---|
| 167 | while($this->db->next_record()) |
---|
| 168 | { |
---|
| 169 | reset($fields); |
---|
| 170 | while(list($fname,$fopt) = each($fields)) |
---|
| 171 | { |
---|
| 172 | $this_row[$fname]['value'] = $this->db->f($fname); |
---|
| 173 | } |
---|
| 174 | $rows[] = $this_row; |
---|
| 175 | } |
---|
| 176 | return $rows; |
---|
| 177 | } |
---|
| 178 | } |
---|