Changeset 19968 for extensions/Piwecard/include/piwecard.class.php
- Timestamp:
- Jan 8, 2013, 12:32:56 AM (11 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
extensions/Piwecard/include/piwecard.class.php
r19956 r19968 2 2 global $user, $conf; 3 3 4 class ecard {4 class Piwecard { 5 5 var $my_config; 6 6 var $user_groups = array(); … … 17 17 18 18 if(isset($result)) { 19 $row = mysql_fetch_row($result);19 $row = pwg_db_fetch_row($result); 20 20 if(is_string($row[0])) { 21 21 $this->my_config = unserialize(($row[0])); … … 27 27 // Initialize default values of params 28 28 private function load_default_config() { 29 include ECARD_INC_PATH.'default_values.inc.php';29 require_once(ECARD_INSTALL_PATH.'default_values.inc.php'); 30 30 foreach ($ecard_default_values as $key => $value) { 31 31 if (!isset($this->my_config[$key])) … … 36 36 // Save general configuration to config_database 37 37 function save_config() { 38 $query = 'UPDATE '.CONFIG_TABLE.' SET value="'. serialize($this->my_config).'" WHERE param="piwecard";';38 $query = 'UPDATE '.CONFIG_TABLE.' SET value="'.pwg_db_real_escape_string(serialize($this->my_config)).'" WHERE param="piwecard";'; 39 39 $result = pwg_query($query); 40 40 … … 53 53 54 54 $result = pwg_query($query); 55 while ($row = mysql_fetch_assoc($result)) {55 while ($row = pwg_db_fetch_assoc($result)) { 56 56 array_push($this->user_groups, $row['group_id']); 57 57 } … … 84 84 return $string; 85 85 } 86 87 // NB of days between 2 dates "AAAA-MM-JJ HH:hh:ss"88 /* function NbJours($debut, $fin) {89 $tDeb = explode("-", substr($debut,0,strpos($debut, ' ')));90 $tFin = explode("-", substr($fin,0,strpos($fin, ' ')));91 92 $diff = mktime(0, 0, 0, $tFin[1], $tFin[2], $tFin[0]) - mktime(0, 0, 0, $tDeb[1], $tDeb[2], $tDeb[0]);93 94 return(($diff / 86400));95 }96 97 function AjoutJours($debut, $jours, $soustrait = false) {98 $tDeb = explode("-", substr($debut,0,strpos($debut, ' ')));99 $tDebH = explode(":", substr($debut,strpos($debut, ' ')+1));100 $tFin = "";101 102 $nb_ans = (int)(($jours)/365);103 $nb_mois = (int)(( ($jours)%365) / 31);104 $nb_jours = (int)(( ($jours)%365) % 31);105 106 if ($soustrait)107 $tFin = date("Y-m-d H:m:s", mktime($tDebH[0], $tDebH[1], $tDebH[2], $tDeb[1] - $nb_mois, $tDeb[2] - $nb_jours, $tDeb[0] - $nb_ans));108 else109 $tFin = date("Y-m-d H:m:s", mktime($tDebH[0], $tDebH[1], $tDebH[2], $tDeb[1] + $nb_mois, $tDeb[2] + $nb_jours, $tDeb[0] + $nb_ans));110 111 return($tFin);112 } */113 86 114 87 function parse($data, $_POST = NULL, $image_element = NULL) { … … 131 104 132 105 if ($result) { 133 $nb= mysql_fetch_assoc($result);106 $nb=pwg_db_fetch_assoc($result); 134 107 return $nb['nb']; 135 108 } else … … 143 116 144 117 if ($result) { 145 $nb= mysql_fetch_assoc($result);118 $nb=pwg_db_fetch_assoc($result); 146 119 return $nb['nb']; 147 120 } else … … 157 130 $result = pwg_query($query); 158 131 if ($result) 159 return mysql_fetch_assoc($result);132 return pwg_db_fetch_assoc($result); 160 133 else 161 134 return false; … … 222 195 WHERE id = '.pwg_db_real_escape_string($page['category']['id']).' 223 196 ;'; 224 $cat = mysql_fetch_assoc(pwg_query($query));197 $cat = pwg_db_fetch_assoc(pwg_query($query)); 225 198 226 199 if (empty($cat)) { … … 284 257 { 285 258 286 // Check if user is guest. 287 // In this case, force mail to default mail (in params) 288 if (is_a_guest()) { 289 if (!empty($this->my_config['defaultmail'])) 290 $user['email'] = $this->my_config['defaultmail']; 291 } 292 293 // Template informations 294 $template->assign('ecard', array( 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"') 303 )); 304 305 // Template add for the active parameter choice by the user 306 if ($this->my_config['active_parameter']) { // Allowed for the user 307 $template->append('ecard_validity',array('id' => 0, 'name' => l10n('ecard_nolimit'), 'selected' => ($this->my_config['activ'] == 0 ? 'checked' : ''))); 308 for($jj=5; $jj < 30; $jj+=5) 309 $template->append('ecard_validity',array('id' => $jj, 'name' => $jj , 'selected' => ($this->my_config['activ'] == $jj ? 'checked' : ''))); 310 } 311 312 // Template add for the send method to be chose, by the user 313 // default : text 314 $template->append('ecard_send_method',array('id' => 0, 'name' => l10n('ecard_maillink'), 'selected' => ($this->my_config['send_HTML'] ? '' : 'checked'))); 315 if ($this->my_config['send_HTML']) { // Allowed for the user 316 $template->append('ecard_send_method',array('id' => 1, 'name' => l10n('ecard_mailhtml'), 'selected' => ($this->my_config['send_HTML'] ? 'checked' : ''))); 317 } 318 319 // Send the card 320 if (isset($_POST['ecard_submit'])) { 321 $send_method = $_POST['ecard_send_method']; 259 // Check if user is guest. 260 // In this case, force mail to default mail (in params) 261 if (is_a_guest()) { 262 if (!empty($this->my_config['defaultmail'])) 263 $user['email'] = $this->my_config['defaultmail']; 264 } 265 266 // Template informations 267 $template->assign('ecard', array( 268 'subject' => l10n('ecard_send_title'), 269 'message' => l10n('ecard_send_message'), 270 'sender_name' => $user['username'], 271 'sender_email' => $user['email'], 272 'recipient_name' => l10n('ecard_send_dest_name'), 273 'recipient_email' => l10n('ecard_send_dest_mail'), 274 'copy' => $this->my_config['send_copy'] ? 'checked="checked"' : '', 275 'changemail' => ($this->my_config['expmail_change'] ? '' : 'disabled="disabled"') 276 )); 277 278 // Template add for the active parameter choice by the user 279 if ($this->my_config['active_parameter']) { // Allowed for the user 280 $template->append('ecard_validity',array('id' => 0, 'name' => l10n('ecard_nolimit'), 'selected' => ($this->my_config['activ'] == 0 ? 'checked' : ''))); 281 for($jj=5; $jj < 30; $jj+=5) 282 $template->append('ecard_validity',array('id' => $jj, 'name' => $jj , 'selected' => ($this->my_config['activ'] == $jj ? 'checked' : ''))); 283 } 284 285 // Template add for the send method to be chose, by the user 286 // default : text 287 $template->append('ecard_send_method',array('id' => 0, 'name' => l10n('ecard_maillink'), 'selected' => ($this->my_config['send_HTML'] ? '' : 'checked'))); 288 if ($this->my_config['send_HTML']) { // Allowed for the user 289 $template->append('ecard_send_method',array('id' => 1, 'name' => l10n('ecard_mailhtml'), 'selected' => ($this->my_config['send_HTML'] ? 'checked' : ''))); 290 } 291 292 // Send the card 293 if (isset($_POST['ecard_submit'])) { 294 $send_method = $_POST['ecard_send_method']; 295 296 // If conf doesn't allow to modify the %votremail param, force it to user mail 297 if (!isset($_POST['ecard_sender_email'])) 298 $_POST['ecard_sender_email'] = $user['email']; 299 300 // Initialize the array for image element 301 $image_element = array(); 302 303 // Get all image informations 304 $query = 'SELECT * FROM '.IMAGES_TABLE.' WHERE id='.$page['image_id'].' LIMIT 1;'; 305 $result = pwg_query($query); 306 if (isset($result)) 307 $image_element = mysql_fetch_array($result); 308 309 // Generate random number 310 $image_element['next_element_id'] = $this->random(64); 311 312 // Image infos 313 if ($this->my_config['ecard_showinfos']) { 314 if (isset($image_element['name'])) { 315 $image_element['picture_infos'] = $image_element['name']; 316 if (isset($image_element['author'])) 317 $image_element['picture_infos'] .= ' ('.$image_element['author'].')'; 318 } 319 } 320 321 $insert = array( 322 'id' => $image_element['next_element_id'], 323 'sender_name' => $_POST['ecard_sender_name'], 324 'recipient_name' => $_POST['ecard_recipient_name'], 325 'sender_email' => $_POST['ecard_sender_email'], 326 'recipient_email' => $_POST['ecard_recipient_email'], 327 'subject' => $_POST['ecard_subject'], 328 'message' => $_POST['ecard_message'], 329 'image' => $image_element['id'], 330 'date_creation' => date("Y-m-d H:i:s"), 331 ); 332 if ($_POST['ecard_validity'] != '0') { 333 $date = new DateTime(); 334 $date->modify("+".$_POST['ecard_validity']." day"); 335 $insert['date_validity'] = $date->format('Y-m-d H:i:s'); 336 } 337 single_insert(ECARD_TABLE, $insert); 338 339 // Complete the image_element array with Link for the ecard url to be added in the mail 340 set_make_full_url(); 341 $ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$image_element['next_element_id']); 342 $image_element['ecard_url'] = $ecard_url; 343 unset_make_full_url(); 344 345 // Complete the image_element with the url to point to the image url 346 set_make_full_url(); 347 $image_element['picture_url'] = duplicate_picture_url( 348 array( 349 'image_id' => $image_element['id'], 350 'image_file' => $image_element['file'] 351 ), 352 array('start') 353 ); 354 unset_make_full_url(); 355 356 $mail_subject = htmlspecialchars_decode($this->parse( $this->my_config['subject_link'], $_POST)); 357 358 switch($send_method) { 359 case 0 : // text 360 // Get the standard message (in admin param) and parse it with the informations 361 $mail_message = stripslashes(htmlspecialchars_decode($this->parse($this->my_config['message_link'], $_POST, $image_element))); 362 $mail_arg=array('from' => $_POST['ecard_sender_email'], 363 'subject' => $mail_subject, 364 'content' => $mail_message, 365 'content_format' => "text/plain", 366 'email_format' => "text/html" 367 ); 368 break; 369 case 1 : // html 370 $mail_message_HTML = stripslashes(htmlspecialchars_decode($this->parse($this->my_config['message_HTML'], $_POST, $image_element))); 371 $mail_arg=array('from' => $_POST['ecard_sender_email'], 372 'subject' => $mail_subject, 373 'content' => $mail_message_HTML, 374 'content_format' => "text/html", 375 'email_format' => "text/html" 376 ); 377 break; 378 default: 379 break; 380 } 381 382 // Add the copy to expe if param. 383 if (isset($_POST['ecard_copy'])) // send copy to sender 384 $mail_arg['Bcc'] = array((isset($_POST['ecard_sender_email']) ? $_POST['ecard_sender_email'] : $user['email'])); 385 386 // Send the mail 387 pwg_mail($_POST['ecard_recipient_email'], $mail_arg); 388 } 322 389 323 // If conf doesn't allow to modify the %votremail param, force it to user mail 324 if (!isset($_POST['ecard_sender_email'])) 325 $_POST['ecard_sender_email'] = $user['email']; 326 327 // Initialize the array for image element 328 $image_element = array(); 329 330 // Get all image informations 331 $query = 'SELECT * FROM '.IMAGES_TABLE.' WHERE id='.$page['image_id'].' LIMIT 1;'; 332 $result = pwg_query($query); 333 if (isset($result)) 334 $image_element = mysql_fetch_array($result); 335 336 // Generate random number 337 $image_element['next_element_id'] = $this->random(64); 338 339 // Image infos 340 if ($this->my_config['ecard_showinfos']) { 341 if (isset($image_element['name'])) { 342 $image_element['picture_infos'] = $image_element['name']; 343 if (isset($image_element['author'])) 344 $image_element['picture_infos'] .= ' ('.$image_element['author'].')'; 345 } 346 } 347 348 $insert = array( 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"), 358 ); 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 } 364 single_insert(ECARD_TABLE, $insert); 365 366 // Complete the image_element array with Link for the ecard url to be added in the mail 367 set_make_full_url(); 368 $ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$image_element['next_element_id']); 369 $image_element['ecard_url'] = $ecard_url; 370 unset_make_full_url(); 371 372 // Complete the image_element with the url to point to the image url 373 set_make_full_url(); 374 $image_element['picture_url'] = duplicate_picture_url( 375 array( 376 'image_id' => $image_element['id'], 377 'image_file' => $image_element['file'] 378 ), 379 array('start') 380 ); 381 unset_make_full_url(); 382 383 $mail_subject = htmlspecialchars_decode($this->parse( $this->my_config['subject_link'], $_POST)); 384 385 switch($send_method) { 386 case 0 : // text 387 // Get the standard message (in admin param) and parse it with the informations 388 $mail_message = stripslashes(htmlspecialchars_decode($this->parse($this->my_config['message_link'], $_POST, $image_element))); 389 $mail_arg=array('from' => $_POST['ecard_sender_email'], 390 'subject' => $mail_subject, 391 'content' => $mail_message, 392 'content_format' => "text/plain", 393 'email_format' => "text/html" 394 ); 395 396 break; 397 case 1 : // html 398 $mail_message_HTML = stripslashes(htmlspecialchars_decode($this->parse($this->my_config['message_HTML'], $_POST, $image_element))); 399 $mail_arg=array('from' => $_POST['ecard_sender_email'], 400 'subject' => $mail_subject, 401 'content' => $mail_message_HTML, 402 'content_format' => "text/html", 403 'email_format' => "text/html" 404 ); 405 break; 406 } 407 408 // Add the copy to expe if param. 409 if (isset($_POST['ecard_copy'])) // send copy to sender 410 $mail_arg['Bcc'] = array((isset($_POST['ecard_sender_email']) ? $_POST['ecard_sender_email'] : $user['email'])); 411 412 // Send the mail 413 pwg_mail($_POST['ecard_recipient_email'], $mail_arg); 414 } 415 416 $template->set_filenames(array('ecard_template' => ECARD_ROOT.'/template/ecard.tpl')); 417 $template->concat('COMMENT_IMG', $template->parse('ecard_template', true)); 390 $template->set_filenames(array('ecard_template' => ECARD_ROOT.'/template/ecard.tpl')); 391 $template->concat('COMMENT_IMG', $template->parse('ecard_template', true)); 418 392 } 419 393 }
Note: See TracChangeset
for help on using the changeset viewer.