Changeset 19956 for extensions/Piwecard/include/ecard.class.php
- Timestamp:
- Jan 7, 2013, 10:26:35 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Piwecard/include/ecard.class.php
r19924 r19956 1 1 <?php 2 /*3 * Plugin Name: Piwecard4 * File : ecard.php5 */6 7 2 global $user, $conf; 8 3 9 4 class ecard { 10 var $debug = false; 11 var $my_config ; 12 var $infos = array(); // contains all the info of the ecard : message, subject.... 5 var $my_config; 13 6 var $user_groups = array(); 14 7 15 8 // Class constructor 16 function ecard() {9 function __construct() { 17 10 $this->load_config(); 18 11 } 19 20 12 21 13 // Load general configuration from config_database 22 14 function load_config() { 23 $query = ' 24 SELECT value 25 FROM '.CONFIG_TABLE.' 26 WHERE param = \'ecard\' 27 ;'; 28 15 $query = 'SELECT value FROM '.CONFIG_TABLE.' WHERE param="piwecard";'; 29 16 $result = pwg_query($query); 30 17 … … 48 35 49 36 // Save general configuration to config_database 50 function save_config() 51 { 52 $query = ' 53 REPLACE INTO '.CONFIG_TABLE.' 54 VALUES( 55 \'ecard\', 56 \''.serialize($this->my_config).'\', 57 \'Configuration ecard\') 58 ;'; 59 37 function save_config() { 38 $query = 'UPDATE '.CONFIG_TABLE.' SET value="'.serialize($this->my_config).'" WHERE param="piwecard";'; 60 39 $result = pwg_query($query); 61 40 … … 71 50 global $user; 72 51 73 $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id =' . $user['id'] . ';';52 $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id=' . $user['id'] . ';'; 74 53 75 54 $result = pwg_query($query); … … 107 86 108 87 // NB of days between 2 dates "AAAA-MM-JJ HH:hh:ss" 109 function NbJours($debut, $fin) {88 /* function NbJours($debut, $fin) { 110 89 $tDeb = explode("-", substr($debut,0,strpos($debut, ' '))); 111 90 $tFin = explode("-", substr($fin,0,strpos($fin, ' '))); … … 131 110 132 111 return($tFin); 133 } 112 } */ 134 113 135 114 function parse($data, $_POST = NULL, $image_element = NULL) { … … 138 117 $patterns = array(); 139 118 $replacements = array(); 140 foreach ($ecard_parse as $key => $value) 141 { 119 foreach ($ecard_parse as $key => $value) { 142 120 array_push($patterns, $key); 143 121 array_push($replacements, $value); … … 149 127 // Get the number of ecard in the database 150 128 function get_nb_ecard() { 151 $query = 'SELECT COUNT(DISTINCT numero) as nb FROM '.ECARD_TABLE 152 . ' ORDER BY date' 153 .';'; 129 $query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.ECARD_TABLE.' ORDER BY date_creation;'; 154 130 $result = pwg_query($query); 131 155 132 if ($result) { 156 133 $nb=mysql_fetch_assoc($result); 157 134 return $nb['nb']; 158 } 159 else 135 } else 160 136 return 0; 161 137 } … … 163 139 // Get the number of valid ecard in the database 164 140 function get_nb_valid_ecard() { 165 $query = 'SELECT numero,date,duration FROM '.ECARD_TABLE 166 .';'; 141 $query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.ECARD_TABLE.' WHERE date_validity IS NULL OR date_validity > NOW();'; 167 142 $result = pwg_query($query); 168 $count = 0;169 while($ecard_info = mysql_fetch_assoc($result)) {170 if ($ecard_info['duration'] == 0 OR $this->NbJours($ecard_info['date'], date("Y-m-d H:m:s")) <= $ecard_info['duration']) // activ ecard171 $count++;172 } 173 return $count;143 144 if ($result) { 145 $nb=mysql_fetch_assoc($result); 146 return $nb['nb']; 147 } else 148 return 0; 174 149 } 175 150 … … 178 153 function get_ecard($ecard_id = null) { 179 154 if ($ecard_id!== null) { 180 $query = ' 181 SELECT * 182 FROM ' . ECARD_TABLE .' 183 WHERE numero ="' . $ecard_id . '" 184 LIMIT 1 185 '; 155 $query = 'SELECT * FROM ' . ECARD_TABLE .' WHERE id ="' . $ecard_id . '" LIMIT 1;'; 186 156 187 157 $result = pwg_query($query); … … 191 161 return false; 192 162 } 193 194 } 195 196 // Get ecard information into array 197 function is_valid($ecard_id = null, $param_date=false) { 198 if ($ecard_id!== null) { 163 } 164 165 function is_valid($ecard_id = null) { 166 if (isset($ecard_id)) { 199 167 $ecard_info = $this->get_ecard($ecard_id); 200 if ($ecard_info != false) 201 { 202 168 if (isset($ecard_info)) { 203 169 // Valid duration for an ecard 204 $duration = ($param_date ? $this->my_config['activ'] : $ecard_info['duration']); 205 if ($this->debug) 206 { 207 foreach ($ecard_info as $i=>$v) 208 echo "ecard[".$i."]=".$v." \ "; 209 echo "NBjours = ".$this->NbJours($ecard_info['date'], date("Y-m-d H:m:s"))." -"; 210 echo "Activenb=".$this->my_config['activ']." -"; 211 } 170 $date_validity = $ecard_info['date_validity']; 212 171 213 214 if (isset ($ecard_info)215 AND $duration != 0 // 0 means always activ216 AND ($this->NbJours($ecard_info['date'], date("Y-m-d H:m:s")) > $duration) // Inactiv ecard217 )218 {219 return false;172 if (isset($date_validity)) { 173 $now = new DateTime(date("Y-m-d H:i:s")); 174 $date_validity = new DateTime($date_validity); 175 if ($date_validity > $now) 176 return true; 177 else 178 return false; 220 179 } else { 221 180 return true; 222 181 } 223 } 224 else 182 } else 225 183 return false; 226 184 } else { 227 return true; 228 } 229 } 230 185 return false; 186 } 187 } 231 188 232 189 // delete one ecard 233 190 // force to delete valid ecard 234 function delete_ecard($ecard_id = null, $force = false) { 235 if ($ecard_id!== null) { 236 $ecard_info = $this->get_ecard($ecard_id); 237 if ($this->debug) 238 { 239 foreach ($ecard_info as $i=>$v) 240 echo "ecard[".$i."]=".$v." \ "; 241 } 242 if (isset ($ecard_info) 243 and ( ($this->NbJours($ecard_info['date'], date("Y-m-d H:m:s")) > $this->my_config['activ']) // Inactiv ecard 244 OR $force // Or force to delete even if activ 245 ) 246 ) 247 248 $query = ' 249 DELETE 250 FROM ' . ECARD_TABLE .' 251 WHERE numero ="' . $ecard_id . '" 252 '; 191 function delete_ecard($ecard_id = null) { 192 if (isset($ecard_id)) { 193 $query = 'DELETE FROM ' . ECARD_TABLE .' WHERE id="' . $ecard_id . '";'; 253 194 pwg_query($query); 254 } 255 else 195 } else 256 196 return false; 257 197 } … … 259 199 // Delete all invalid ecard 260 200 function delete_allinvalid_ecard() { 261 $date = $this->AjoutJours(date("Y-m-d H:m:s"), $this->my_config['activ'], true); 262 263 $query = ' 264 DELETE 265 FROM ' . ECARD_TABLE .' 266 WHERE date < "' . $date . '" 267 '; 268 201 $query = 'DELETE FROM ' . ECARD_TABLE .' WHERE date_validity < NOW();'; 269 202 pwg_query($query); 270 271 203 } 272 204 … … 324 256 325 257 // author of the photo 326 $authorname = ""; 327 $query = ' 328 SELECT author 329 FROM '.IMAGES_TABLE.' 330 WHERE id = '.$page['image_id'] 331 .' LIMIT 1' 332 .';'; 258 $query = 'SELECT author FROM '.IMAGES_TABLE.' WHERE id = '.$page['image_id'].' LIMIT 1;'; 333 259 $result = pwg_query($query); 334 260 if (isset($result)) { … … 367 293 // Template informations 368 294 $template->assign('ecard', array( 369 'subject' 370 'message' => l10n('ecard_send_message'),371 'sender_name' => $user['username'],372 'sender_email' => $user['email'],373 'recipient_name' 374 'recipient_email' => l10n('ecard_send_dest_mail'),375 'copy' => $this->my_config['send_copy'] ? 'checked="checked"' : '',376 'changemail' => ($this->my_config['expmail_change'] ? '' : 'disabled="disabled"')295 'subject' => l10n('ecard_send_title'), 296 'message' => l10n('ecard_send_message'), 297 'sender_name' => $user['username'], 298 'sender_email' => $user['email'], 299 'recipient_name' => l10n('ecard_send_dest_name'), 300 'recipient_email' => l10n('ecard_send_dest_mail'), 301 'copy' => $this->my_config['send_copy'] ? 'checked="checked"' : '', 302 'changemail' => ($this->my_config['expmail_change'] ? '' : 'disabled="disabled"') 377 303 )); 378 304 … … 421 347 422 348 $insert = array( 423 'numero' => $image_element['next_element_id'], 424 'nomexp' => $_POST['ecard_sender_name'], 425 'nomdest' => $_POST['ecard_recipient_name'], 426 'adrexp' => $_POST['ecard_sender_email'], 427 'adrdest' => $_POST['ecard_recipient_email'], 428 'sujet' => $_POST['ecard_subject'], 429 'message' => $_POST['ecard_message'], 430 'image' => $image_element['id'], 431 'date' => date("Y-m-d H:i:s"), 432 'duration' => (isset($_POST['ecard_validity']) ? $_POST['ecard_validity'] : $this->my_config['activ']), 349 'id' => $image_element['next_element_id'], 350 'sender_name' => $_POST['ecard_sender_name'], 351 'recipient_name' => $_POST['ecard_recipient_name'], 352 'sender_email' => $_POST['ecard_sender_email'], 353 'recipient_email' => $_POST['ecard_recipient_email'], 354 'subject' => $_POST['ecard_subject'], 355 'message' => $_POST['ecard_message'], 356 'image' => $image_element['id'], 357 'date_creation' => date("Y-m-d H:i:s"), 433 358 ); 434 // TO DO : add valid date (end date or duration) / add number (increment number) / 359 if ($_POST['ecard_validity'] != '0') { 360 $date = new DateTime(); 361 $date->modify("+".$_POST['ecard_validity']." day"); 362 $insert['date_validity'] = $date->format('Y-m-d H:i:s'); 363 } 435 364 single_insert(ECARD_TABLE, $insert); 436 365
Note: See TracChangeset
for help on using the changeset viewer.