Index: extensions/Piwecard/include/ecard.class.php
===================================================================
--- extensions/Piwecard/include/ecard.class.php	(revision 19737)
+++ extensions/Piwecard/include/ecard.class.php	(revision 19923)
@@ -274,5 +274,5 @@
 	function display_ecard_to_picture() {
 		global $page, $user, $template;
-
+		
 		// Init user groups
 		$this->get_user_groups();
@@ -366,11 +366,11 @@
 			
 				// Template informations
-				$template->assign( 'ecard', array(
-						'sujet' => l10n('ecard_send_title'),
+				$template->assign('ecard', array(
+						'subject' => l10n('ecard_send_title'),
 						'message' => l10n('ecard_send_message'),
-						'votrenom' => $user['username'],	//"votre nom",
-						'votremail' => $user['email'], 		//"votre mail (test@test.com)",
-						'sonnom' => l10n('ecard_send_dest_name'),
-						'sonmail' => l10n('ecard_send_dest_mail'),
+						'sender_name' => $user['username'],
+						'sender_email' => $user['email'],
+						'recipient_name' => l10n('ecard_send_dest_name'),
+						'recipient_email' => l10n('ecard_send_dest_mail'),
 						'copy'	=> $this->my_config['send_copy'] ? 'checked="checked"' : '',
 						'changemail' => ($this->my_config['expmail_change'] ? '' : 'disabled="disabled"')
@@ -379,40 +379,35 @@
 				// Template add for the active parameter choice by the user
 				if ($this->my_config['active_parameter']) {	// Allowed for the user
-					$template->append('ECARD_ACTIV',array('ID' => 0,'NAME' => l10n('ecard_nolimit'),'SELECTED' => ($this->my_config['activ'] == 0 ? 'checked' : '')));
+					$template->append('ecard_validity',array('id' => 0, 'name' => l10n('ecard_nolimit'), 'selected' => ($this->my_config['activ'] == 0 ? 'checked' : '')));
 					for($jj=5; $jj < 30; $jj+=5)
-						$template->append('ECARD_ACTIV',array('ID' => $jj,'NAME' => $jj ,'SELECTED' => ($this->my_config['activ'] == $jj ? 'checked' : '')));
+						$template->append('ecard_validity',array('id' => $jj, 'name' => $jj , 'selected' => ($this->my_config['activ'] == $jj ? 'checked' : '')));
 				}
 							
 				// Template add for the send method to be chose, by the user
 				// default : text
-				$template->append('ECARD_SEND',array('ID' => 0,'NAME' => l10n('ecard_maillink'),'SELECTED' => ($this->my_config['send_HTML'] ?  '' : 'checked')));
+				$template->append('ecard_send_method',array('id' => 0, 'name' => l10n('ecard_maillink'), 'selected' => ($this->my_config['send_HTML'] ?  '' : 'checked')));
 				if ($this->my_config['send_HTML']) {	// Allowed for the user
-					$template->append('ECARD_SEND',array('ID' => 1,'NAME' => l10n('ecard_mailhtml') ,'SELECTED' => ($this->my_config['send_HTML'] ? 'checked' : '')));
+					$template->append('ecard_send_method',array('id' => 1, 'name' => l10n('ecard_mailhtml'), 'selected' => ($this->my_config['send_HTML'] ? 'checked' : '')));
 				}
 
 				// Send the card
 				if (isset($_POST['ecard_submit'])) {
-					$send_method = $_POST['ecard_send'];
+					$send_method = $_POST['ecard_send_method'];
+					
 					// If conf doesn't allow to modify the %votremail param, force it to user mail
-					if (!isset($_POST['votremail']))
-						$_POST['votremail'] = $user['email'];
+					if (!isset($_POST['ecard_sender_email']))
+						$_POST['ecard_sender_email'] = $user['email'];
 					
 					// Initialize the array for image element
 					$image_element = array();
 
-					// Get all image informations - to be replaced by a Core PWG function
-					$query = '
-					SELECT *
-					  FROM '.IMAGES_TABLE.'
-					  WHERE id = '.$page['image_id']
-					  .' LIMIT 1'
-					  .';';
-
+					// Get all image informations
+					$query = 'SELECT * FROM '.IMAGES_TABLE.' WHERE id='.$page['image_id'].' LIMIT 1;';
 					$result = pwg_query($query);
 					if (isset($result))
 						$image_element = mysql_fetch_array($result);
 					
-					// Generate random number 
-					$image_element['next_element_id']  = $this->random(15);
+					// Generate random number
+					$image_element['next_element_id']  = $this->random(64);
 
 					// Image infos
@@ -423,52 +418,47 @@
 								$image_element['imginfos'] .= ' ('.$image_element['author'].')';
 						}
-							
 					}
-						
-					if ($this->debug)	echo "Next_element=".$image_element['next_element_id']."\n";
-
-					$query = '
-					INSERT INTO ' . ECARD_TABLE .'
-					VALUES ( "'.$image_element['next_element_id'].'","'
-							 .$_POST['votrenom'].'","'
-							 .$_POST['sonnom'].'","'
-							 .$_POST['votremail'].'","'
-							 .$_POST['sonmail'].'","'
-							 .$_POST['sujet'].'","'
-							 .$_POST['message'].'",'
-							 .$image_element['id'].',
-							 now(),'
-							 .(isset($_POST['ecard_activ']) ? $_POST['ecard_activ'] : $this->my_config['activ'])
-							 .');';
+
+					$insert = array(
+								'numero' => $image_element['next_element_id'],
+								'nomexp' => $_POST['ecard_sender_name'],
+								'nomdest' => $_POST['ecard_recipient_name'],
+								'adrexp' => $_POST['ecard_sender_email'],
+								'adrdest' => $_POST['ecard_recipient_email'],
+								'sujet' => $_POST['ecard_subject'],
+								'message' => $_POST['ecard_message'],
+								'image' => $image_element['id'],
+								'date' => date("Y-m-d H:i:s"),
+								'duration' => (isset($_POST['ecard_validity']) ? $_POST['ecard_validity'] : $this->my_config['activ']),
+					);
 					// TO DO : add valid date (end date or duration) / add number (increment number) / 
-
-					pwg_query($query);
+					single_insert(ECARD_TABLE, $insert);
 
 					// Complete the image_element array with Link for the ecard url to be added in the mail
 					set_make_full_url();
-					$chemin = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$image_element['next_element_id']);
-					$image_element['chemin'] = $chemin;
+					$mail_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$image_element['next_element_id']);
+					$image_element['mail_url'] = $mail_url;
 					unset_make_full_url();
 
 					// Complete the image_element with the url to point to the image url
 					set_make_full_url();
-					$image_element['url_picture'] = duplicate_picture_url(
-					  array(
-						'image_id' => $image_element['id'],
-						'image_file' => $image_element['file']
-					  ),
-					  array('start')
+					$image_element['picture_url'] = duplicate_picture_url(
+						array(
+							'image_id' => $image_element['id'],
+							'image_file' => $image_element['file']
+						),
+						array('start')
 					);
 					unset_make_full_url();
 
-					$sujetdumail = htmlspecialchars_decode($this->parse( $this->my_config['subject_link'], $_POST));
+					$mail_subject = htmlspecialchars_decode($this->parse( $this->my_config['subject_link'], $_POST));
 					
 					switch($send_method) {
 					case 0 : // text
 						// Get the standard message (in admin param) and parse it with the informations
-						$messagemail =  stripslashes(htmlspecialchars_decode($this->parse($this->my_config['message_link'], $_POST, $image_element)));
-						$mail_arg=array('from' => $_POST['votremail'],
-										'subject' => $sujetdumail,
-										'content' => $messagemail,
+						$mail_message =  stripslashes(htmlspecialchars_decode($this->parse($this->my_config['message_link'], $_POST, $image_element)));
+						$mail_arg=array('from' => $_POST['ecard_sender_email'],
+										'subject' => $mail_subject,
+										'content' => $mail_message,
 										'content_format' => "text/plain",
 										'email_format' => "text/html"
@@ -477,25 +467,24 @@
 						break;
 					case 1 : // html
-						$messagemailHTML =  stripslashes(htmlspecialchars_decode($this->parse($this->my_config['message_HTML'], $_POST, $image_element)));
-						$mail_arg=array('from' => $_POST['votremail'],
-										'subject' => $sujetdumail,
-										'content' => $messagemailHTML,
+						$mail_message_HTML =  stripslashes(htmlspecialchars_decode($this->parse($this->my_config['message_HTML'], $_POST, $image_element)));
+						$mail_arg=array('from' => $_POST['ecard_sender_email'],
+										'subject' => $mail_subject,
+										'content' => $mail_message_HTML,
 										'content_format' => "text/html",
 										'email_format' => "text/html"
 										);
-						if ($this->debug)		echo "messagemailHTML=".$messagemailHTML."\n";
 						break;
 					}
 					
 					// Add the copy to expe if param.
-					if (isset($_POST['copy']))	// send copy to sender
-						$mail_arg['Bcc'] = array((isset($_POST['votremail']) ? $_POST['votremail'] : $user['email']));
+					if (isset($_POST['ecard_copy']))	// send copy to sender
+						$mail_arg['Bcc'] = array((isset($_POST['ecard_sender_email']) ? $_POST['ecard_sender_email'] : $user['email']));
 					
 					// Send the mail
-					pwg_mail($_POST['sonmail'], $mail_arg);
-				}
-				
-				$template->set_filenames(array('ecard' =>  ECARD_ROOT.'/template/ecard.tpl'));
-				$template->concat('COMMENT_IMG', $template->parse('ecard', true));
+					pwg_mail($_POST['ecard_recipient_email'], $mail_arg);
+				}
+				
+				$template->set_filenames(array('ecard_template' =>  ECARD_ROOT.'/template/ecard.tpl'));
+				$template->concat('COMMENT_IMG', $template->parse('ecard_template', true));
 				}
 			}
