Index: /extensions/Piwecard/admin/admin_consult.php
===================================================================
--- /extensions/Piwecard/admin/admin_consult.php	(revision 19967)
+++ /extensions/Piwecard/admin/admin_consult.php	(revision 19968)
@@ -36,5 +36,5 @@
 $result = pwg_query($query);
 
-while($file = mysql_fetch_assoc($result)) {
+while($file = pwg_db_fetch_assoc($result)) {
 	$ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$file['id']);
 
Index: /extensions/Piwecard/admin/admin_manage.php
===================================================================
--- /extensions/Piwecard/admin/admin_manage.php	(revision 19967)
+++ /extensions/Piwecard/admin/admin_manage.php	(revision 19968)
@@ -4,93 +4,63 @@
 global $template, $page;
  
-$me = get_plugin_data($plugin_id);
+$piwecard = get_plugin_data($plugin_id);
 
- $template->set_filenames( 
-		array('plugin_admin_content' => ECARD_ROOT.'/admin/template/admin_manage.tpl',
-			  'double_select' => 'double_select.tpl'
-			) );
+$template->set_filenames(array(
+	'plugin_admin_content' 	=> ECARD_ROOT.'/admin/template/admin_manage.tpl',
+	'double_select' 		=> 'double_select.tpl'
+));
 
+// Switch on right side (=>)	
+if (isset($_POST['falsify']) and isset($_POST['cat_true']) and count($_POST['cat_true']) > 0) {
+	foreach ($_POST['cat_true'] as $cat)
+		unset($piwecard->my_config['cats'][array_search($cat, $piwecard->my_config['cats'])]);
+	$piwecard->save_config();
+}
 
-
-		
-// Switch  on right side (=> )
-if ( isset($_POST['falsify']) and !is_adviser() 
-    and isset($_POST['cat_true']) and count($_POST['cat_true']) > 0) 
-{
-	foreach ($_POST['cat_true'] as $cat)
-		unset($me->my_config['cats'][array_search($cat,$me->my_config['cats'])]);
-
-	$me->save_config();
-
-}
-// Switch  on left side ( <=)
-if ( isset($_POST['trueify']) and !is_adviser() 
-    and isset($_POST['cat_false']) and count($_POST['cat_false']) > 0) 
-{
-
-	$query = '
-	  SELECT id, name, uppercats, global_rank
-	  FROM '.CATEGORIES_TABLE.
-	  ' WHERE id IN ("'.implode('","', $_POST['cat_false']).'");';
-
+// Switch on left side (<=)
+if (isset($_POST['trueify']) and isset($_POST['cat_false']) and count($_POST['cat_false']) > 0) {
+	$query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id IN ("'.implode('","', $_POST['cat_false']).'");';
 	$result = pwg_query($query);
 	$categories = array();
-	if (!empty($result))
-	{
-		while ($row = mysql_fetch_assoc($result))
+
+	if (!empty($result)) {
+		while ($row = pwg_db_fetch_assoc($result))
 			array_push($categories, $row);			
 	}
 	usort($categories, 'global_rank_compare');
 
-	if (!empty($result))
-	{
-		foreach ($categories as $cat)
-		{
-			array_push($me->my_config['cats'], $cat['id']);
+	if (!empty($result)) {
+		foreach ($categories as $cat) {
+			array_push($piwecard->my_config['cats'], $cat['id']);
 		}
 	}
-
-	$me->save_config();
+	$piwecard->save_config();
 }
-			
 
 if (isset($_POST['submit'])) { 
-
-	$me->my_config['allcats'] = isset($_POST['allcats']);
-	$me->my_config['user_cat'] = isset($_POST['user_cat']);
-	$me->my_config['recursive'] = isset($_POST['recursiv']);
-	$me->my_config['groups'] = isset($_POST['groups']) ? 
-                          array_map("mysql_escape_string", $_POST['groups']) :
-                          array(); 
-
-	$me->save_config();
+	$piwecard->my_config['allcats'] = isset($_POST['allcats']);
+	$piwecard->my_config['user_cat'] = isset($_POST['user_cat']);
+	$piwecard->my_config['recursive'] = isset($_POST['recursiv']);
+	if ($piwecard->my_config['groups'] = isset($_POST['groups']))
+		array_map("mysql_escape_string", $_POST['groups']);
+	else
+		array(); 
+	$piwecard->save_config();
 	array_push($page['infos'], l10n('ecard_admin_saveOK'));
-	
 }
-
-
 
 // Groups selection
 $groups = get_all_groups();
-if (!empty($groups))
-{
-  $template->assign('group_perm', array('GROUPSELECTION' => get_html_groups_selection($groups, 'groups', (isset($me->my_config['groups']) ? $me->my_config['groups'] : array()))));
-  
+if (!empty($groups)) {
+  $template->assign('group_perm', array('GROUPSELECTION' => get_html_groups_selection($groups, 'groups', (isset($piwecard->my_config['groups']) ? $piwecard->my_config['groups'] : array()))));
 }
-
-
 	
 // Test double select wall categories 
 // Categories non prises en compte
-$query = '
-  SELECT id, name, uppercats, global_rank
-  FROM '.CATEGORIES_TABLE.
-  ' WHERE id not IN ("'.implode('","', $me->my_config['cats']).'");';
-
-  $result = pwg_query($query);
-  $categories = array();
-if (!empty($result))
-{
-	while ($row = mysql_fetch_assoc($result))
+$query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id not IN ("'.implode('","', $piwecard->my_config['cats']).'");';
+$result = pwg_query($query);
+$categories = array();
+if (!empty($result)) {
+	while ($row = pwg_db_fetch_assoc($result))
 		array_push($categories, $row);
 }
@@ -98,12 +68,7 @@
 
 $tpl = array();
-if (!empty($result))
-{
-		foreach ($categories as $cat)
-	{
-      		$tpl[$cat['id']] = get_cat_display_name_cache($cat['uppercats'],
-                                           null,
-                                           false);
-	
+if (!empty($result)) {
+	foreach ($categories as $cat) {
+      	$tpl[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], null, false);
 	}
 }
@@ -111,31 +76,18 @@
 $template->assign( 'category_option_false_selected', array());
 
-
-
-
 // Categories prises en compte
-
-$query = '
-  SELECT id, name, uppercats, global_rank
-  FROM '.CATEGORIES_TABLE.
-  ' WHERE id IN ("'.implode('","', $me->my_config['cats']).'");';
-
+$query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id IN ("'.implode('","', $piwecard->my_config['cats']).'");';
 $result = pwg_query($query);
-  $categories = array();
+$categories = array();
 if (!empty($result))
 {
-	while ($row = mysql_fetch_assoc($result))
+	while ($row = pwg_db_fetch_assoc($result))
 		array_push($categories, $row);
 }
 usort($categories, 'global_rank_compare');
 $tpl2 = array();
-if (!empty($result))
-{
-		foreach ($categories as $cat)
-	{
-      		$tpl2[$cat['id']] = get_cat_display_name_cache($cat['uppercats'],
-                                           null,
-                                           false);
-	
+if (!empty($result)) {
+	foreach ($categories as $cat) {
+      	$tpl2[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], null, false);
 	}
 }
@@ -143,8 +95,7 @@
 $template->assign( 'category_option_true_selected', array());
 
-$template->assign('ECARD_ALLCATS', ($me->my_config['allcats'] ? 'checked="checked"' : ''));
-$template->assign('ECARD_USERCAT', ($me->my_config['user_cat'] ? 'checked="checked"' : ''));
-$template->assign('ECARD_RECURSIV', ($me->my_config['recursive'] ? 'checked="checked"' : ''));
-
+$template->assign('ECARD_ALLCATS', ($piwecard->my_config['allcats'] ? 'checked="checked"' : ''));
+$template->assign('ECARD_USERCAT', ($piwecard->my_config['user_cat'] ? 'checked="checked"' : ''));
+$template->assign('ECARD_RECURSIV', ($piwecard->my_config['recursive'] ? 'checked="checked"' : ''));
 
 $template->assign(Array(
@@ -154,71 +105,42 @@
 ));
 
-
-
 $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
 $template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content');
 
+function get_html_groups_selection($groups, $fieldname, $selecteds = array()) {
+	global $conf;
+	
+	if (count ($groups) == 0) {
+		return '';
+	}
+	
+	$output = '<div id="'.$fieldname.'">';
+	$id = 1;
+	
+	foreach ($groups as $group) {
+		$output.= '<input type="checkbox" name="'.$fieldname.'[]" id="group_'.$id++.'" value="'.$group['id'].'"';
 
+		if (in_array($group['id'], $selecteds)) {
+		  $output.= ' checked="checked"';
+		}
 
-function get_html_groups_selection(
-  $groups,
-  $fieldname,
-  $selecteds = array()
-  )
-{
-  global $conf;
-  if (count ($groups) == 0 )
-  {
-    return '';
-  }
-  $output = '<div id="'.$fieldname.'">';
-  $id = 1;
-  foreach ($groups as $group)
-  {
-    $output.=
+		$output.= '><label>&nbsp;'. $group['name'].'</label>\n';
+	}
+	$output.= '</div>';
 
-      '<input type="checkbox" name="'.$fieldname.'[]"'
-      .' id="group_'.$id++.'"'
-      .' value="'.$group['id'].'"'
-      ;
-
-    if (in_array($group['id'], $selecteds))
-    {
-      $output.= ' checked="checked"';
-    }
-
-    $output.=
-      '><label>'
-      .'&nbsp;'. $group['name']
-      .'</label>'
-      ."\n"
-      ;
-  }
-  $output.= '</div>';
-
-  return $output;
+	return $output;
 }
 
+function get_all_groups() {
+	$query = 'SELECT id, name FROM '.GROUPS_TABLE.'	ORDER BY name ASC;';
+	$result = pwg_query($query);
 
+	$groups = array();
+	while ($row = pwg_db_fetch_assoc($result)) {
+		array_push($groups, $row);
+	}
+	uasort($groups, 'name_compare');
 
-function get_all_groups()
-{
-$query = '
-SELECT id, name
-  FROM '.GROUPS_TABLE.'
-  ORDER BY name ASC
-;';
-$result = pwg_query($query);
-
-$groups = array();
-  while ($row = mysql_fetch_assoc($result))
-  {
-    array_push($groups, $row);
-  }
-
-  uasort($groups, 'name_compare');
-  return $groups;
+	return $groups;
 }
-
-
 ?>
Index: /extensions/Piwecard/admin/template/admin_manage.tpl
===================================================================
--- /extensions/Piwecard/admin/template/admin_manage.tpl	(revision 19967)
+++ /extensions/Piwecard/admin/template/admin_manage.tpl	(revision 19968)
@@ -1,65 +1,48 @@
+{footer_script}
+{literal}
+$(document).ready(function(){
+	if ($("#ecard_selected_cats").attr('checked') == "checked") {
+			$("#ecard_selected_cats_options").css("display","block");
+		} else {
+			$("#ecard_selected_cats_options").css("display","none");
+		}
+
+	$("#ECardAdminManage").click(function(){
+		if ($("#ecard_selected_cats").attr('checked') == "checked") {
+			$("#ecard_selected_cats_options").show("fast");
+		} else {
+			$("#ecard_selected_cats_options").hide("fast");
+		}
+	});
+});
+{/literal}
+{/footer_script}
+
 <div class="titrePage">
-  <h2>{$ECARD_VERSION}</h2>
+	<h2>{'ecard'|@translate}</h2>
 </div>
 <form method="post" action="" class="properties"  ENCTYPE="multipart/form-data">
-<fieldset>
-	<legend>{'ecard_manage'|@translate}</legend>
-	<table>
-		<tr><td colspan="2"><br></td></tr>
-		<TR>
-			<TD colspan="2">
-				<b><u>{'ecard_manage'|@translate} 1 :</u></b> <input type="checkbox" name="user_cat" {$ECARD_USERCAT}/> {'ecard_active_user_cat'|@translate} 
-				<br/>
-			</TD>
-		</TR>
-		<TR>
-			<TD colspan="2">
-				<b><u>{'ecard_manage'|@translate} 2 :</u></b> <input type="checkbox" name="allcats" {$ECARD_ALLCATS}/> {'ecard_active_all_cats'|@translate} 
-				<br/>
-			</TD>
-		</TR>
-			<TD colspan="2">
-				<b><u>{'ecard_manage'|@translate} 3 :</u></b>  {'ecard_active_spec_cats'|@translate} 
-				<br/>
-			</TD>
-		</TR>
-		<TR>
-			<TD colspan="2">
-			<table>
-				<tr>
-					<td colspan ="2">
-						{'option'|@translate} : <input type="checkbox" name="recursiv" {$ECARD_RECURSIV}/> {'ecard_recursiv'|@translate} 
-						<br/>
-					</TD>
-				</TR>
-				<TR>
-					<TD colspan="2"><br>
-					<td>
-				</tr>
-				<TR >
-					<td align="left" colspan="2">
-						<div id="cat_select0">
-						{'option'|@translate} : <b>{'ecard_cat'|@translate}&nbsp;</b>
-						</div>
-					</td>
-				</tr>
-				<tr>
-					<td class="categoryList1" colspan="2">
-					<div id="cat_select">
+	<fieldset>
+		<legend>{'ecard_manage'|@translate}</legend>
+		<div id="ECardAdminManage">
+			<div>
+				<input type="radio" name="ecard_manage" id="ecard_user_cats" value="ecard_user_cats" {$ecard.user_cats} /><label for="ecard_user_cats">{'ecard_active_user_cat'|@translate}</label><br />
+			</div>
+			<div>
+				<input type="radio" name="ecard_manage" id="ecard_all_cats" value="ecard_all_cats" {$ecard.all_cats} /><label for="ecard_all_cats">{'ecard_active_all_cats'|@translate}</label><br />
+			</div>
+			<div>
+				<input type="radio" name="ecard_manage" id="ecard_selected_cats" value="ecard_selected_cats" {$ecard.selected_cats}><label for="ecard_selected_cats">{'ecard_active_spec_cats'|@translate}</label><br />
+				<div id="ecard_selected_cats_options">
+					<input type="checkbox" name="ecard_selected_cats_recursive" id="ecard_selected_cats_recursive" {$ecard.selected_cats_recursive} /><label for="ecard_selected_cats_recursive">{'ecard_recursive'|@translate}</label><br />
+					<div id="ecard_cat_select">
 						{$DOUBLE_SELECT}
 					</div>
-					</td>
-				</tr>
-			</table>
-			</td>
-		</tr>
-
-	</table>
-
-	
-<br/>
-</fieldset>
- 
-<p><input type="submit" name="submit" value="{'ecard_admin_submit'|@translate}" /></p>
-
+				</div>
+			</div>
+			<div>
+				<input type="submit" name="submit" value="{'Submit'|@translate}" />
+			</div>
+		</div>
+	</fieldset>
 </form>
Index: /extensions/Piwecard/admin/template/admin_params.tpl
===================================================================
--- /extensions/Piwecard/admin/template/admin_params.tpl	(revision 19967)
+++ /extensions/Piwecard/admin/template/admin_params.tpl	(revision 19968)
@@ -1,82 +1,76 @@
 <div class="titrePage">
-  <h2>{$ECARD_VERSION}</h2>
+  <h2>{$ecard}</h2>
 </div>
 <form method="post" action=""   ENCTYPE="multipart/form-data">
+	<div id="ECardAdminParams">
+		<fieldset>
+			<legend>{'ecard_config'|@translate}</legend>
+			<div>
+				{'ecard_activ_nb'|@translate}
+				<select id="ecard_activ" name="ecard_activ">
+					{foreach from=$ECARD_ACTIV item=ECARD_ACTIV}
+						<option value="{$ECARD_ACTIV.ID}" {$ECARD_ACTIV.SELECTED}>{$ECARD_ACTIV.NAME}</option>
+					{/foreach}
+				</select>
+			</div>
+			<div>
+				<input type="checkbox" name="ecard_sendcopy" {$ECARD_SENDCOPY}/> {'ecard_send_copy'|@translate}
+			</div>
+			<div>
+				<input type="checkbox" name="ecard_modifexpmail" {$ECARD_MODIFEXPMAIL}/> {'ecard_nomodif_expmail'|@translate}
+			</div>
+			<div>
+				<input type="checkbox" name="ecard_sendhtml" {$ECARD_SENDHTML}/> {'ecard_send_HTML'|@translate}
+			</div>
+			<div>
+				<input type="checkbox" name="ecard_showinfos" {$ECARD_SHOWINFOS}/> {'ecard_show_infos'|@translate} 
+			</div>
+			<div>
+				{'ecard_admin_nb_page'|@translate}
+				<select id="ecard_nb_page" name="ecard_nb_page">
+					{foreach from=$ECARD_NB_PAGE item=ECARD_NB_PAGE}
+						<option value="{$ECARD_NB_PAGE.ID}" {$ECARD_NB_PAGE.SELECTED}>{$ECARD_NB_PAGE.NAME}</option>
+					{/foreach}
+				</select>
+			</div>
+			<div>
+				{'ecard_default_mail'|@translate}
+				<input type="text" maxlength="50" size="50" name="defaultmail" id="defaultmail" value="{$ECARD_DEFAULT_MAIL}" />
+			</div>
+		</fieldset>
 
-<fieldset>
-	<legend>{'ecard_config'|@translate}</legend>
-  <ul>
-    <li>
-		  {'ecard_activ_nb'|@translate}
-		  <select id="ecard_activ" name="ecard_activ">
-			 {foreach from=$ECARD_ACTIV item=ECARD_ACTIV}
-			  <option value="{$ECARD_ACTIV.ID}" {$ECARD_ACTIV.SELECTED}>{$ECARD_ACTIV.NAME}</option>
-			{/foreach}
-		  </select>
-    </li>
-    <li>
-			<input type="checkbox" name="ecard_sendcopy" {$ECARD_SENDCOPY}/> {'ecard_send_copy'|@translate} 
-				<br/>
-	</li>
-    <li>
-			<input type="checkbox" name="ecard_modifexpmail" {$ECARD_MODIFEXPMAIL}/> {'ecard_nomodif_expmail'|@translate} 
-				<br/>
-	</li>
-    <li>
-			<input type="checkbox" name="ecard_sendhtml" {$ECARD_SENDHTML}/> {'ecard_send_HTML'|@translate} 
-				<br/>
-	</li>
-    <li>
-			<input type="checkbox" name="ecard_showinfos" {$ECARD_SHOWINFOS}/> {'ecard_show_infos'|@translate} 
-				<br/>
-	</li>
-    <li>
-		  {'ecard_admin_nb_page'|@translate}
-		  <select id="ecard_nb_page" name="ecard_nb_page">
-			 {foreach from=$ECARD_NB_PAGE item=ECARD_NB_PAGE}
-			  <option value="{$ECARD_NB_PAGE.ID}" {$ECARD_NB_PAGE.SELECTED}>{$ECARD_NB_PAGE.NAME}</option>
-			{/foreach}
-		  </select>
-    </li>
-    <li>
-		  {'ecard_default_mail'|@translate}     <input type="text" maxlength="50" size="50" name="defaultmail" id="defaultmail" value="{$ECARD_DEFAULT_MAIL}" />
+		<fieldset>
+			<legend>{'ecard_mail_config'|@translate}</legend>
+		</br>
+		  <ul>
+			<li>
+			  <span class="property">
+				<label for="ecard_subject_link">{'ecard_subject_link'|@translate}</label>
+			  </span>
+			  <input type="text" maxlength="255" size="50" name="ecard_subject_link" id="ecard_subject_link" value="{$ECARD_SUBJECT_LINK}" />
+			</li>
+			<li>
 
-    </li>
-  </ul>
+			  <span class="property">
+				<label for="page_banner">{'ecard_message_link'|@translate}</label>
+			  </span>
+			  <textarea name="ecard_message_link" id="ecard_message_link"  rows="10" cols="50" style="width:100%; height: 150px;">{$ECARD_MESSAGE_LINK}</textarea>
+			</li>
+			<li>
 
-</fieldset>
-
-<fieldset>
-	<legend>{'ecard_mail_config'|@translate}</legend>
-</br>
-  <ul>
-    <li>
-      <span class="property">
-        <label for="ecard_subject_link">{'ecard_subject_link'|@translate}</label>
-      </span>
-      <input type="text" maxlength="255" size="50" name="ecard_subject_link" id="ecard_subject_link" value="{$ECARD_SUBJECT_LINK}" />
-    </li>
-    <li>
-
-      <span class="property">
-        <label for="page_banner">{'ecard_message_link'|@translate}</label>
-      </span>
-      <textarea name="ecard_message_link" id="ecard_message_link"  rows="10" cols="50" style="width:100%; height: 150px;">{$ECARD_MESSAGE_LINK}</textarea>
-    </li>
-    <li>
-
-      <span class="property">
-        <label for="page_banner">{'ecard_message_html'|@translate}</label>
-      </span>
-      <textarea name="ecard_message_html" id="ecard_message_html" rows="10" cols="50" style="width:100%; height: 200px;">{$ECARD_MESSAGE_HTML}</textarea>
-    </li>
-	<p><div align="left">
-	<small>{'ecard_parameters'|@translate}<small>
-	</div></p>
-  </ul>
-	  
-</fieldset>
-
-<p><input type="submit" name="submit" value="{'ecard_admin_submit'|@translate}" /></p>
-
+			  <span class="property">
+				<label for="page_banner">{'ecard_message_html'|@translate}</label>
+			  </span>
+			  <textarea name="ecard_message_html" id="ecard_message_html" rows="10" cols="50" style="width:100%; height: 200px;">{$ECARD_MESSAGE_HTML}</textarea>
+			</li>
+			<p><div align="left">
+			<small>{'ecard_parameters'|@translate}<small>
+			</div></p>
+		  </ul>
+			  
+		</fieldset>
+		<div>
+			<input type="submit" name="submit" value="{'Submit'|@translate}" />
+		</div>
+	</div>
 </form>
Index: tensions/Piwecard/include/ecard.class.php
===================================================================
--- /extensions/Piwecard/include/ecard.class.php	(revision 19967)
+++ 	(revision )
@@ -1,423 +1,0 @@
-<?php
-global $user, $conf;
-
-class ecard {
-	var $my_config;
-	var $user_groups = array();
-	
-	// Class constructor
-	function __construct() {
-		$this->load_config();
-	}
-	
-	// Load general configuration from config_database
-	function load_config() {
-		$query = 'SELECT value FROM '.CONFIG_TABLE.' WHERE param="piwecard";';
-		$result = pwg_query($query);
-
-	    if(isset($result)) {
-			$row = mysql_fetch_row($result);
-			if(is_string($row[0])) {
-				$this->my_config = unserialize(($row[0]));
-			}
-	    }
-		$this->load_default_config();
-	}
-	
-	// Initialize default values of params
-	private function load_default_config() {
-	    include ECARD_INC_PATH.'default_values.inc.php';
-	    foreach ($ecard_default_values as $key => $value) {
-		    if (!isset($this->my_config[$key]))
-				$this->my_config[$key] = $value;
-		}
-	}
-
-	// Save  general configuration to config_database
-	function save_config() {
-		$query = 'UPDATE '.CONFIG_TABLE.' SET value="'.serialize($this->my_config).'" WHERE param="piwecard";';
-		$result = pwg_query($query);
-
-		if($result) 
-		  return true;
-		else
-		  return false;
-	}
-	
-
-	// Retrieve user groups 
-	function get_user_groups() {
-		global $user;
-		
-		$query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id=' . $user['id'] . ';';
-
-		$result = pwg_query($query);
-		while ($row = mysql_fetch_assoc($result)) {
-			array_push($this->user_groups, $row['group_id']);
-		}
-	}
-
-
-	function section_init_ecard() {
-		global $tokens, $page;
-		
-		if ($tokens[0] == 'ecard')
-			$page['section'] = 'ecard';
-	}
-	
-	function index_ecard() {
-		global $page;
-		
-		if (isset($page['section']) and $page['section'] == 'ecard') {
-			include(ECARD_PATH . 'publish.php');
-		}
-	}
-
-	//Générer une chaine de caractère unique et aléatoire
-	private function random($car) {
-		$string = "";
-		$chaine = "abcdefghijklmnpqrstuvwxy0123456789";
-		srand((double)microtime()*1000000);
-		for($i=0; $i<$car; $i++) {
-			$string .= $chaine[rand()%strlen($chaine)];
-		}
-		return $string;
-	}
-
-	// NB of days between 2 dates "AAAA-MM-JJ HH:hh:ss"
-	/* function NbJours($debut, $fin) {
-		$tDeb = explode("-", substr($debut,0,strpos($debut, ' ')));
-		$tFin = explode("-", substr($fin,0,strpos($fin, ' ')));
-
-		$diff = mktime(0, 0, 0, $tFin[1], $tFin[2], $tFin[0]) - mktime(0, 0, 0, $tDeb[1], $tDeb[2], $tDeb[0]);
-
-		return(($diff / 86400));
-	}
-
-	function AjoutJours($debut, $jours, $soustrait = false) {
-		$tDeb = explode("-", substr($debut,0,strpos($debut, ' ')));
-		$tDebH = explode(":", substr($debut,strpos($debut, ' ')+1));
-		$tFin = "";
-
-		$nb_ans = (int)(($jours)/365);
-		$nb_mois = (int)(( ($jours)%365) / 31);
-		$nb_jours = (int)(( ($jours)%365) % 31);		
-
-		if ($soustrait)
-			$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));
-		else
-			$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));
-
-		return($tFin);
-	} */
-	
-	function parse($data, $_POST = NULL, $image_element = NULL) {
-		include (ECARD_PATH.'include/config_param.inc.php');
-
-		$patterns = array();
-		$replacements = array();
-		foreach ($ecard_parse as $key => $value) {
-			array_push($patterns, $key); 
-			array_push($replacements, $value);
-		}
-
-		return str_replace($patterns, $replacements, $data);
-	}
-	
-	// Get the number of ecard in the database
-	function get_nb_ecard() {
-		$query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.ECARD_TABLE.' ORDER BY date_creation;';
-		$result = pwg_query($query);
-		
-		if ($result) {
-			$nb=mysql_fetch_assoc($result);
-			return $nb['nb'];
-		} else 
-			return 0;
-	}
-
-	// Get the number of valid ecard in the database
-	function get_nb_valid_ecard() {
-		$query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.ECARD_TABLE.' WHERE date_validity IS NULL OR date_validity > NOW();';
-		$result = pwg_query($query);
-		
-		if ($result) {
-			$nb=mysql_fetch_assoc($result);
-			return $nb['nb'];
-		} else 
-			return 0;
-	}
-	
-	
-	// Get ecard information into array
-	function get_ecard($ecard_id = null) {
-		if ($ecard_id!== null) {
-			$query = 'SELECT * FROM ' . ECARD_TABLE .' WHERE id ="' . $ecard_id . '" LIMIT 1;';
-
-			$result = pwg_query($query);
-			if ($result)
-				return 	mysql_fetch_assoc($result);
-			else 
-				return false;
-		}
-	}
-
-	function is_valid($ecard_id = null) {
-		if (isset($ecard_id)) {
-			$ecard_info = $this->get_ecard($ecard_id);
-			if (isset($ecard_info)) {
-				// Valid duration for an ecard
-				$date_validity = $ecard_info['date_validity'];
-				
-				if (isset($date_validity)) {
-					$now = new DateTime(date("Y-m-d H:i:s")); 
-					$date_validity = new DateTime($date_validity); 
-					if ($date_validity > $now)
-						return true;
-					else
-						return false;
-				} else {
-					return true;
-				}
-			} else
-				return false;
-		} else {
-			return false;
-		}
-	}
-	
-	// delete one ecard
-	// force to delete valid ecard
-	function delete_ecard($ecard_id = null) {
-		if (isset($ecard_id)) {
-			$query = 'DELETE FROM ' . ECARD_TABLE .' WHERE id="' . $ecard_id  . '";';
-			pwg_query($query);
-		} else
-			return false;
-	}
-	
-	// Delete all invalid ecard
-	function delete_allinvalid_ecard() {
-		$query = 'DELETE FROM ' . ECARD_TABLE .' WHERE date_validity < NOW();';
-		pwg_query($query);
-	}
-	
-	// Add tpl to picture.php page to display ecard informations 
-	function display_ecard_to_picture() {
-		global $page, $user, $template;
-		
-		// Init user groups
-		$this->get_user_groups();
-
-		// Only on category page!
-		if (isset($page['section'])) {
-			$upper_names = null;
-			
-			if (!empty($page['category'])) {
-				// Gets all upper categories from the image category to test 
-				//	- if the parameter for "recursive" is OK
-				//	- if the upper category is activated for this function
-				$query = 'SELECT *
-							FROM '.CATEGORIES_TABLE.'
-							WHERE id = '.pwg_db_real_escape_string($page['category']['id']).'
-							;';
-				$cat = mysql_fetch_assoc(pwg_query($query));
-				
-				if (empty($cat)) {
-					$upper_ids = null;
-				} else {
-					foreach ($cat as $k => $v) {
-						// If the field is true or false, the variable is transformed into a
-						// boolean value.
-						if ($cat[$k] == 'true' or $cat[$k] == 'false') {
-						  $cat[$k] = get_boolean($cat[$k]);
-						}
-					}
-					$upper_ids = explode(',', $cat['uppercats']);
-				}
-			}
-			
-			if ($this->my_config['user_cat']) {	// !Function only allowed on user image 
-				// Check the category name, user name et img author
-				// Get all name for upper categories and current category
-				if (isset($cat) and !empty($cat)) {
-					$catname[0] = $cat['name'];
-					if (isset($upper_ids) and $upper_ids != null) {
-						$nb=1;
-						foreach ($upper_ids as $upper_cat) {
-							// Get upper cat info and store the name
-							$cat_info = get_cat_info($upper_cat);
-							$catname[$nb++] = $cat_info['name'];
-						}
-					}
-				}
-				// Username or the current user
-				$username = $user['username'];
-				
-				// author of the photo
-				$query = 'SELECT author FROM '.IMAGES_TABLE.' WHERE id = '.$page['image_id'].' LIMIT 1;';
-				$result = pwg_query($query);
-				if (isset($result)) {
-					$img_infos = mysql_fetch_array($result);
-					$authorname = $img_infos['author'];
-				}
-			}		
-		
-			// Only on available cats
-			if ($this->my_config['allcats']		// Available on all cats
-				OR (!empty($page['category']) AND in_array($page['category']['id'], $this->my_config['cats']))	// Available on specific cats
-				OR ($this->my_config['recursive'] AND isset($upper_ids) AND 				// Available on upper cats this recursiv mode
-						(array_intersect($upper_ids, $this->my_config['cats']) != array()))
-				OR	// Available based on usename
-					($this->my_config['user_cat']
-						AND (in_array($username, $catname)	// Available user categories
-								OR $username == $authorname)
-
-					) 
-				)
-			{
-			// And only available groups
-				if (empty($this->my_config['groups']) 
-					OR (!empty($this->my_config['groups'])
-						AND (array_intersect($this->user_groups, $this->my_config['groups']) != array())) 
-					)
-				{
-				
-				// Check if user is guest. 
-				// In this case, force mail to default mail (in params)
-				if (is_a_guest()) {
-					if (!empty($this->my_config['defaultmail']))
-						$user['email'] = $this->my_config['defaultmail'];
-				}
-			
-				// Template informations
-				$template->assign('ecard', array(
-						'subject'			=> l10n('ecard_send_title'),
-						'message' 			=> l10n('ecard_send_message'),
-						'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"')
-						));
-
-				// Template add for the active parameter choice by the user
-				if ($this->my_config['active_parameter']) {	// Allowed for the user
-					$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_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_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_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_method'];
-					
-					// If conf doesn't allow to modify the %votremail param, force it to user mail
-					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
-					$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(64);
-
-					// Image infos
-					if ($this->my_config['ecard_showinfos']) {
-						if (isset($image_element['name'])) {
-							$image_element['picture_infos'] = $image_element['name'];
-							if (isset($image_element['author']))
-								$image_element['picture_infos'] .= ' ('.$image_element['author'].')';
-						}
-					}
-
-					$insert = array(
-								'id' 				=> $image_element['next_element_id'],
-								'sender_name' 		=> $_POST['ecard_sender_name'],
-								'recipient_name' 	=> $_POST['ecard_recipient_name'],
-								'sender_email' 		=> $_POST['ecard_sender_email'],
-								'recipient_email' 	=> $_POST['ecard_recipient_email'],
-								'subject' 			=> $_POST['ecard_subject'],
-								'message' 			=> $_POST['ecard_message'],
-								'image' 			=> $image_element['id'],
-								'date_creation' 	=> date("Y-m-d H:i:s"),
-					);
-					if ($_POST['ecard_validity'] != '0') {
-						$date = new DateTime();
-						$date->modify("+".$_POST['ecard_validity']." day");
-						$insert['date_validity'] = $date->format('Y-m-d H:i:s');
-					}
-					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();
-					$ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$image_element['next_element_id']);
-					$image_element['ecard_url'] = $ecard_url;
-					unset_make_full_url();
-
-					// Complete the image_element with the url to point to the image url
-					set_make_full_url();
-					$image_element['picture_url'] = duplicate_picture_url(
-						array(
-							'image_id' => $image_element['id'],
-							'image_file' => $image_element['file']
-						),
-						array('start')
-					);
-					unset_make_full_url();
-
-					$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
-						$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"
-										);
-					
-						break;
-					case 1 : // html
-						$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"
-										);
-						break;
-					}
-					
-					// Add the copy to expe if param.
-					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['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));
-				}
-			}
-		}
-	}
-}
-?>
Index: /extensions/Piwecard/include/piwecard.class.php
===================================================================
--- /extensions/Piwecard/include/piwecard.class.php	(revision 19968)
+++ /extensions/Piwecard/include/piwecard.class.php	(revision 19968)
@@ -0,0 +1,397 @@
+<?php
+global $user, $conf;
+
+class Piwecard {
+	var $my_config;
+	var $user_groups = array();
+	
+	// Class constructor
+	function __construct() {
+		$this->load_config();
+	}
+	
+	// Load general configuration from config_database
+	function load_config() {
+		$query = 'SELECT value FROM '.CONFIG_TABLE.' WHERE param="piwecard";';
+		$result = pwg_query($query);
+
+	    if(isset($result)) {
+			$row = pwg_db_fetch_row($result);
+			if(is_string($row[0])) {
+				$this->my_config = unserialize(($row[0]));
+			}
+	    }
+		$this->load_default_config();
+	}
+	
+	// Initialize default values of params
+	private function load_default_config() {
+	    require_once(ECARD_INSTALL_PATH.'default_values.inc.php');
+	    foreach ($ecard_default_values as $key => $value) {
+		    if (!isset($this->my_config[$key]))
+				$this->my_config[$key] = $value;
+		}
+	}
+
+	// Save  general configuration to config_database
+	function save_config() {
+		$query = 'UPDATE '.CONFIG_TABLE.' SET value="'.pwg_db_real_escape_string(serialize($this->my_config)).'" WHERE param="piwecard";';
+		$result = pwg_query($query);
+
+		if($result) 
+		  return true;
+		else
+		  return false;
+	}
+	
+
+	// Retrieve user groups 
+	function get_user_groups() {
+		global $user;
+		
+		$query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id=' . $user['id'] . ';';
+
+		$result = pwg_query($query);
+		while ($row = pwg_db_fetch_assoc($result)) {
+			array_push($this->user_groups, $row['group_id']);
+		}
+	}
+
+
+	function section_init_ecard() {
+		global $tokens, $page;
+		
+		if ($tokens[0] == 'ecard')
+			$page['section'] = 'ecard';
+	}
+	
+	function index_ecard() {
+		global $page;
+		
+		if (isset($page['section']) and $page['section'] == 'ecard') {
+			include(ECARD_PATH . 'publish.php');
+		}
+	}
+
+	//Générer une chaine de caractère unique et aléatoire
+	private function random($car) {
+		$string = "";
+		$chaine = "abcdefghijklmnpqrstuvwxy0123456789";
+		srand((double)microtime()*1000000);
+		for($i=0; $i<$car; $i++) {
+			$string .= $chaine[rand()%strlen($chaine)];
+		}
+		return $string;
+	}
+	
+	function parse($data, $_POST = NULL, $image_element = NULL) {
+		include (ECARD_PATH.'include/config_param.inc.php');
+
+		$patterns = array();
+		$replacements = array();
+		foreach ($ecard_parse as $key => $value) {
+			array_push($patterns, $key); 
+			array_push($replacements, $value);
+		}
+
+		return str_replace($patterns, $replacements, $data);
+	}
+	
+	// Get the number of ecard in the database
+	function get_nb_ecard() {
+		$query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.ECARD_TABLE.' ORDER BY date_creation;';
+		$result = pwg_query($query);
+		
+		if ($result) {
+			$nb=pwg_db_fetch_assoc($result);
+			return $nb['nb'];
+		} else 
+			return 0;
+	}
+
+	// Get the number of valid ecard in the database
+	function get_nb_valid_ecard() {
+		$query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.ECARD_TABLE.' WHERE date_validity IS NULL OR date_validity > NOW();';
+		$result = pwg_query($query);
+		
+		if ($result) {
+			$nb=pwg_db_fetch_assoc($result);
+			return $nb['nb'];
+		} else 
+			return 0;
+	}
+	
+	
+	// Get ecard information into array
+	function get_ecard($ecard_id = null) {
+		if ($ecard_id!== null) {
+			$query = 'SELECT * FROM ' . ECARD_TABLE .' WHERE id ="' . $ecard_id . '" LIMIT 1;';
+
+			$result = pwg_query($query);
+			if ($result)
+				return 	pwg_db_fetch_assoc($result);
+			else 
+				return false;
+		}
+	}
+
+	function is_valid($ecard_id = null) {
+		if (isset($ecard_id)) {
+			$ecard_info = $this->get_ecard($ecard_id);
+			if (isset($ecard_info)) {
+				// Valid duration for an ecard
+				$date_validity = $ecard_info['date_validity'];
+				
+				if (isset($date_validity)) {
+					$now = new DateTime(date("Y-m-d H:i:s")); 
+					$date_validity = new DateTime($date_validity); 
+					if ($date_validity > $now)
+						return true;
+					else
+						return false;
+				} else {
+					return true;
+				}
+			} else
+				return false;
+		} else {
+			return false;
+		}
+	}
+	
+	// delete one ecard
+	// force to delete valid ecard
+	function delete_ecard($ecard_id = null) {
+		if (isset($ecard_id)) {
+			$query = 'DELETE FROM ' . ECARD_TABLE .' WHERE id="' . $ecard_id  . '";';
+			pwg_query($query);
+		} else
+			return false;
+	}
+	
+	// Delete all invalid ecard
+	function delete_allinvalid_ecard() {
+		$query = 'DELETE FROM ' . ECARD_TABLE .' WHERE date_validity < NOW();';
+		pwg_query($query);
+	}
+	
+	// Add tpl to picture.php page to display ecard informations 
+	function display_ecard_to_picture() {
+		global $page, $user, $template;
+		
+		// Init user groups
+		$this->get_user_groups();
+
+		// Only on category page!
+		if (isset($page['section'])) {
+			$upper_names = null;
+			
+			if (!empty($page['category'])) {
+				// Gets all upper categories from the image category to test 
+				//	- if the parameter for "recursive" is OK
+				//	- if the upper category is activated for this function
+				$query = 'SELECT *
+							FROM '.CATEGORIES_TABLE.'
+							WHERE id = '.pwg_db_real_escape_string($page['category']['id']).'
+							;';
+				$cat = pwg_db_fetch_assoc(pwg_query($query));
+				
+				if (empty($cat)) {
+					$upper_ids = null;
+				} else {
+					foreach ($cat as $k => $v) {
+						// If the field is true or false, the variable is transformed into a
+						// boolean value.
+						if ($cat[$k] == 'true' or $cat[$k] == 'false') {
+						  $cat[$k] = get_boolean($cat[$k]);
+						}
+					}
+					$upper_ids = explode(',', $cat['uppercats']);
+				}
+			}
+			
+			if ($this->my_config['user_cat']) {	// !Function only allowed on user image 
+				// Check the category name, user name et img author
+				// Get all name for upper categories and current category
+				if (isset($cat) and !empty($cat)) {
+					$catname[0] = $cat['name'];
+					if (isset($upper_ids) and $upper_ids != null) {
+						$nb=1;
+						foreach ($upper_ids as $upper_cat) {
+							// Get upper cat info and store the name
+							$cat_info = get_cat_info($upper_cat);
+							$catname[$nb++] = $cat_info['name'];
+						}
+					}
+				}
+				// Username or the current user
+				$username = $user['username'];
+				
+				// author of the photo
+				$query = 'SELECT author FROM '.IMAGES_TABLE.' WHERE id = '.$page['image_id'].' LIMIT 1;';
+				$result = pwg_query($query);
+				if (isset($result)) {
+					$img_infos = mysql_fetch_array($result);
+					$authorname = $img_infos['author'];
+				}
+			}		
+		
+			// Only on available cats
+			if ($this->my_config['allcats']		// Available on all cats
+				OR (!empty($page['category']) AND in_array($page['category']['id'], $this->my_config['cats']))	// Available on specific cats
+				OR ($this->my_config['recursive'] AND isset($upper_ids) AND 				// Available on upper cats this recursiv mode
+						(array_intersect($upper_ids, $this->my_config['cats']) != array()))
+				OR	// Available based on usename
+					($this->my_config['user_cat']
+						AND (in_array($username, $catname)	// Available user categories
+								OR $username == $authorname)
+
+					) 
+				)
+			{
+			// And only available groups
+				if (empty($this->my_config['groups']) 
+					OR (!empty($this->my_config['groups'])
+						AND (array_intersect($this->user_groups, $this->my_config['groups']) != array())) 
+					)
+				{
+				
+					// Check if user is guest. 
+					// In this case, force mail to default mail (in params)
+					if (is_a_guest()) {
+						if (!empty($this->my_config['defaultmail']))
+							$user['email'] = $this->my_config['defaultmail'];
+					}
+				
+					// Template informations
+					$template->assign('ecard', array(
+							'subject'			=> l10n('ecard_send_title'),
+							'message' 			=> l10n('ecard_send_message'),
+							'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"')
+							));
+
+					// Template add for the active parameter choice by the user
+					if ($this->my_config['active_parameter']) {	// Allowed for the user
+						$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_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_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_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_method'];
+						
+						// If conf doesn't allow to modify the %votremail param, force it to user mail
+						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
+						$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(64);
+
+						// Image infos
+						if ($this->my_config['ecard_showinfos']) {
+							if (isset($image_element['name'])) {
+								$image_element['picture_infos'] = $image_element['name'];
+								if (isset($image_element['author']))
+									$image_element['picture_infos'] .= ' ('.$image_element['author'].')';
+							}
+						}
+
+						$insert = array(
+									'id' 				=> $image_element['next_element_id'],
+									'sender_name' 		=> $_POST['ecard_sender_name'],
+									'recipient_name' 	=> $_POST['ecard_recipient_name'],
+									'sender_email' 		=> $_POST['ecard_sender_email'],
+									'recipient_email' 	=> $_POST['ecard_recipient_email'],
+									'subject' 			=> $_POST['ecard_subject'],
+									'message' 			=> $_POST['ecard_message'],
+									'image' 			=> $image_element['id'],
+									'date_creation' 	=> date("Y-m-d H:i:s"),
+						);
+						if ($_POST['ecard_validity'] != '0') {
+							$date = new DateTime();
+							$date->modify("+".$_POST['ecard_validity']." day");
+							$insert['date_validity'] = $date->format('Y-m-d H:i:s');
+						}
+						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();
+						$ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$image_element['next_element_id']);
+						$image_element['ecard_url'] = $ecard_url;
+						unset_make_full_url();
+						
+						// Complete the image_element with the url to point to the image url
+						set_make_full_url();
+						$image_element['picture_url'] = duplicate_picture_url(
+							array(
+								'image_id' => $image_element['id'],
+								'image_file' => $image_element['file']
+							),
+							array('start')
+						);
+						unset_make_full_url();
+
+						$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
+								$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"
+												);
+								break;
+							case 1 : // html
+								$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"
+												);
+								break;
+							default:
+								break;
+						}
+						
+						// Add the copy to expe if param.
+						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['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));
+				}
+			}
+		}
+	}
+}
+?>
Index: /extensions/Piwecard/install/functions.inc.php
===================================================================
--- /extensions/Piwecard/install/functions.inc.php	(revision 19967)
+++ /extensions/Piwecard/install/functions.inc.php	(revision 19968)
@@ -26,5 +26,5 @@
 	$result = pwg_query($query);
 	
-	while($data = mysql_fetch_assoc($result)) {
+	while($data = pwg_db_fetch_assoc($result)) {
 		$insert = array(
 					'id' => $data['numero'],
Index: /extensions/Piwecard/install/index.php
===================================================================
--- /extensions/Piwecard/install/index.php	(revision 19968)
+++ /extensions/Piwecard/install/index.php	(revision 19968)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/Piwecard/main.inc.php
===================================================================
--- /extensions/Piwecard/main.inc.php	(revision 19967)
+++ /extensions/Piwecard/main.inc.php	(revision 19968)
@@ -5,10 +5,6 @@
  * Description: envoi de Cartes Virtuelles
  * Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=487
- * Author: Tiico
- * Author URI: 
+ * Author: Tiico & Julien1311
  * */
-/********* Fichier main.inc.php  *********/
-
-/* See CHANGELOG for release informations */
  
 if (!defined('PHPWG_ROOT_PATH'))  die('Hacking attempt!');
@@ -18,20 +14,17 @@
 define('ECARD_VERSION', '1.1.0');
 
-define('ECARD_NAME', 'Piwecard');
 define('ECARD_ROOT', dirname(__FILE__));
-define('ECARD_DIR' , basename(dirname(__FILE__)));
-define('ECARD_CFG_DB' , ECARD_DIR);
-define('ECARD_PATH' , PHPWG_PLUGINS_PATH . ECARD_DIR . '/');
-define('ECARD_INC_PATH' , PHPWG_PLUGINS_PATH . ECARD_DIR . '/include/');
-define('ECARD_IMG_PATH' , PHPWG_PLUGINS_PATH . ECARD_DIR . '/img/');
-define('ECARD_ADMIN_PATH' , PHPWG_PLUGINS_PATH . ECARD_DIR . '/admin/');
-define('ECARD_TABLE' , $prefixeTable . 'piwecard');
+define('ECARD_DIR', basename(dirname(__FILE__)));
+define('ECARD_PATH', PHPWG_PLUGINS_PATH.ECARD_DIR.'/');
+define('ECARD_INC_PATH', PHPWG_PLUGINS_PATH . ECARD_DIR . '/include/');
+define('ECARD_INSTALL_PATH', PHPWG_PLUGINS_PATH . ECARD_DIR . '/install/');
+define('ECARD_TABLE', $prefixeTable . 'piwecard');
 define('ECARD_ADMIN',   get_root_url() . 'admin.php?page=plugin-'.ECARD_DIR);
 
 load_language('plugin.lang', ECARD_PATH);
 
-include_once ECARD_INC_PATH.'ecard.class.php';
-include_once( PHPWG_ROOT_PATH.'include/functions_mail.inc.php' );
-include_once( PHPWG_ROOT_PATH.'include/functions_picture.inc.php' );
+include_once(ECARD_INC_PATH.'piwecard.class.php');
+include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
+include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
 global $page, $template;
 
@@ -39,5 +32,5 @@
 load_language('plugin.lang', ECARD_PATH);	
 
-$ecard = new ecard();
+$ecard = new Piwecard();
 
 // Add ecard to picture page
Index: /extensions/Piwecard/publish.php
===================================================================
--- /extensions/Piwecard/publish.php	(revision 19967)
+++ /extensions/Piwecard/publish.php	(revision 19968)
@@ -4,5 +4,5 @@
 global $template;
 
-$ecard = new ecard();
+$ecard = new Piwecard();
 
 $ecard_id = explode('ecard/', $_SERVER['REQUEST_URI']);
@@ -12,5 +12,5 @@
 	$query = 'SELECT * FROM '.ECARD_TABLE.' WHERE numero = "'.$ecard_id.'";';
 	$result = pwg_query($query);
-	$result_array = mysql_fetch_assoc($result);
+	$result_array = pwg_db_fetch_assoc($result);
 
 	if (isset($result_array['numero'])) {
@@ -19,5 +19,5 @@
 		$result = pwg_query($query);
 
-		$row = mysql_fetch_assoc($result);
+		$row = pwg_db_fetch_assoc($result);
 		set_make_full_url();
 		$url = duplicate_picture_url(
