[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - Polls * 4 * http://www.egroupware.org * 5 * Copyright (c) 1999 Till Gerken (tig@skv.org) * 6 * Modified by Greg Haygood (shrykedude@bellsouth.net) * 7 * ----------------------------------------------- * 8 * This program is free software; you can redistribute it and/or modify it * 9 * under the terms of the GNU General Public License as published by the * 10 * Free Software Foundation; either version 2 of the License, or (at your * 11 * option) any later version. * 12 \**************************************************************************/ 13 14 /* $Id: class.so.inc.php 19418 2005-10-14 16:10:00Z ralfbecker $ */ 15 16 class so 17 { 18 var $debug = False; 19 var $db; 20 21 var $total = 0; 22 23 function so($args='') 24 { 25 $this->db = clone($GLOBALS['egw']->db); 26 } 27 28 function load_settings() 29 { 30 $this->db->query('SELECT * FROM phpgw_polls_settings'); 31 while($this->db->next_record()) 32 { 33 $GLOBALS['poll_settings'][$this->db->f('setting_name')] = $this->db->f('setting_value'); 34 } 35 return $GLOBALS['poll_settings']; 36 } 37 38 function save_settings($data) 39 { 40 if(isset($data) && is_array($data)) 41 { 42 $this->db->query('DELETE FROM phpgw_polls_settings',__LINE__,__FILE__); 43 while(list($name,$value) = each($data)) 44 { 45 $this->db->query("INSERT INTO phpgw_polls_settings VALUES ('$name','$value')",__LINE__,__FILE__); 46 } 47 } 48 } 49 50 function get_user_votecount($poll_id) 51 { 52 return (int)$this->get_value_('SELECT COUNT(*) FROM phpgw_polls_user WHERE user_id=' 53 . (int)($GLOBALS['egw_info']['user']['account_id']) 54 . ' AND poll_id=' . (int)$poll_id,0); 55 } 56 57 function get_poll_title($poll_id) 58 { 59 return stripslashes($this->get_value_('SELECT poll_title FROM phpgw_polls_desc WHERE poll_id=' . (int)$poll_id,0)); 60 } 61 62 function get_poll_total($poll_id) 63 { 64 return (int)$this->get_value_('SELECT SUM(option_count) AS sum FROM phpgw_polls_data' 65 . ' WHERE poll_id=' . (int)$poll_id,0); 66 } 67 68 function get_poll_data($poll_id,$vote_id=-1) 69 { 70 $options = array(); 71 $query = 'SELECT * FROM phpgw_polls_data WHERE poll_id=' . (int)$poll_id; 72 if($vote_id >= 0) 73 { 74 $query .= ' AND vote_id=' . (int)$vote_id; 75 } 76 $query .= ' ORDER BY LOWER(option_text)'; 77 if($this->debug) { print("QUERY: $query<br>"); } 78 $this->db->query($query,__LINE__,__FILE__); 79 while($this->db->next_record()) 80 { 81 $options[] = array( 82 'vote_id' => (int)$this->db->f('vote_id'), 83 'text' => stripslashes($this->db->f('option_text')), 84 'votes' => $this->db->f('option_count') 85 ); 86 } 87 return $options; 88 } 89 90 function get_latest_poll() 91 { 92 return $this->get_value_('SELECT MAX(poll_id) FROM phpgw_polls_desc', 0); 93 } 94 95 function add_answer($poll_id,$answer) 96 { 97 $vote_id = (int)$this->get_value_('SELECT MAX(vote_id)+1 FROM phpgw_polls_data' 98 . ' WHERE poll_id=' . (int)$poll_id,0); 99 $answer = addslashes($answer); 100 $result = $this->db->query('INSERT INTO phpgw_polls_data (poll_id,option_text,option_count,vote_id)' 101 . ' VALUES (' . (int)$poll_id . ",'" . $answer . "',0," . (int)$vote_id . ')',__LINE__,__FILE__); 102 if($result) 103 { 104 return $this->db->get_last_insert_id('phpgw_polls_desc','poll_id'); 105 } 106 return -1; 107 } 108 109 function add_question($title) 110 { 111 $result = $this->db->query("INSERT INTO phpgw_polls_desc (poll_title,poll_timestamp) VALUES ('" 112 . addslashes($title) . "','" . time() . "')",__LINE__,__FILE__); 113 return $result; 114 if($result) 115 { 116 return $this->db->get_last_insert_id('phpgw_polls_desc','poll_id'); 117 } 118 return -1; 119 } 120 121 function get_last_added_poll() 122 { 123 return $this->db->get_last_insert_id('phpgw_polls_desc','poll_id'); 124 } 125 126 function delete_answer($poll_id,$vote_id) 127 { 128 $this->db->query('DELETE FROM phpgw_polls_data WHERE vote_id=' . (int)$vote_id . ' AND poll_id=' . (int)$poll_id); 129 } 130 131 function delete_question($poll_id) 132 { 133 $this->db->query('DELETE FROM phpgw_polls_desc WHERE poll_id=' . (int)$poll_id); 134 $this->db->query('DELETE FROM phpgw_polls_data WHERE poll_id=' . (int)$poll_id); 135 $this->db->query('DELETE FROM phpgw_polls_user WHERE poll_id=' . (int)$poll_id); 136 if($GLOBALS['currentpoll'] == $poll_id) 137 { 138 $this->db->query('SELECT MAX(poll_id) AS max FROM phpgw_polls_desc'); 139 $max = $this->db->f(0); 140 $this->db->query("UPDATE phpgw_polls_settings SET setting_value='$max'" 141 . " WHERE setting_name='currentpoll'"); 142 } 143 } 144 145 function add_vote($poll_id,$vote_id,$user_id) 146 { 147 // verify that we're adding a valid vote before update 148 $this->db->query('SELECT option_count FROM phpgw_polls_data' 149 . ' WHERE poll_id=' . (int) $poll_id . ' AND vote_id=' . (int)$vote_id); 150 $count = $this->db->f(0); 151 if($count >= 0) 152 { 153 $this->db->query('UPDATE phpgw_polls_data SET option_count=option_count+1 WHERE' 154 . ' poll_id=' . (int)$poll_id . ' AND vote_id=' . (int)$vote_id,__LINE__,__FILE__); 155 $this->db->query('INSERT INTO phpgw_polls_user VALUES (' . (int)$poll_id . ',0,' 156 . $GLOBALS['egw_info']['user']['account_id'] . ',' . time() . ')',__LINE__,__FILE__); 157 } 158 } 159 160 function update_answer($poll_id,$vote_id,$answer) 161 { 162 $this->db->query('UPDATE phpgw_polls_data SET poll_id=' . (int)$poll_id . ",option_text='" 163 . addslashes($answer) . "' WHERE vote_id=" . (int)$vote_id,__LINE__,__FILE__); 164 } 165 166 function update_question($poll_id,$question) 167 { 168 $this->db->query("UPDATE phpgw_polls_desc SET poll_title='" . addslashes($question) 169 . "' WHERE poll_id=" . (int)$poll_id,__LINE__,__FILE__); 170 } 171 172 function get_value_($query,$field) 173 { 174 $this->db->query($query,__LINE__,__FILE__); 175 $this->db->next_record(); 176 return $this->db->f($field); 177 } 178 179 function get_data_($query,$key,$args) 180 { 181 $data = array(); 182 if(!empty($query) && !empty($key)) 183 { 184 $result = $this->db->query($query,__LINE__,__FILE__); 185 $this->total = $this->db->num_rows(); 186 187 if($args && is_array($args) && !empty($args['limit'])) 188 { 189 $start = (int)$args['start']; 190 $result = $this->db->limit_query($query,$start,__LINE__,__FILE__); 191 } 192 193 while($this->db->next_record()) 194 { 195 $info = array(); 196 foreach($this->db->Record as $key => $val) 197 { 198 $info[$key] = $val; 199 } 200 $data[] = $info; 201 } 202 } 203 return $data; 204 } 205 206 function list_questions($args) 207 { 208 $query = 'SELECT * FROM phpgw_polls_desc ORDER BY ' . $args['order'] . ' ' . $args['sort']; 209 if($this->debug) { print("QUERY: $query<br>"); } 210 $data = $this->get_data_($query,'poll_id',$args); 211 return $data; 212 } 213 214 function list_answers($args) 215 { 216 $query = 'SELECT phpgw_polls_data.*, phpgw_polls_desc.poll_title ' 217 . 'FROM phpgw_polls_data,phpgw_polls_desc ' 218 . 'WHERE phpgw_polls_desc.poll_id = phpgw_polls_data.poll_id ' 219 . 'ORDER BY '.$args['order'].' '.$args['sort']; 220 if($this->debug) { print("QUERY: $query<br>"); } 221 $data = $this->get_data_($query,'vote_id',$args); 222 return $data; 223 } 224 225 function somestoragefunc() 226 { 227 //nothing to be added yet 228 } 229 } 230 ?>
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 |