<?php
/* **
 * @application PhpMyShopping
 * @part        Admin Boutique (AB)
 * @file        class.personnalisation.php
 * @path        ./admin/include/
 * @author      Stephane DINE <stephane@phpmyshopping.org>
 * @site        http://www.phpmyshopping.org
 * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
 *
 * PHP version 5
 *
 * Classe Personnalisation
 *
 * Gestion dse parametres persos de la boutique
 */

require_once 'class.lib.php';

class Personnalisation extends Lib
{




	/** ****************************************************************************************************
	 * Constructeur
	 */
	public function __construct()
	{

	}




	/** *****************************************************************************************************************************
	 * Methode modifShopDescription
	 *
	 * @desc   Formulaire de modification de la description courte de la boutique
	 * @return string
	 * @access public
	 */
	public function modifShopDescription()
	{
		$sql = 'SELECT ShopName, ShopDescription, Logo FROM Shop';
		$query = $this->query($sql);
		$result = mysql_fetch_array($query);

		if ($result['Logo'] == '1') {
			$img = $this->printImage('../images/', 'logo');
			$logo = '<div id="deleteImgLogo">
			[ <a href="javascript:execAction(\'deleteImgLogo\', \''.$img['name'].'\')">Supprimer cette image</a> ]<br /><br />
			<img src="../images/'.$img['name'].'" border="0" /></div>';
		} else {
			$logo = 'Aucun logo n\'est d&eacute;fini';
		}

		$form = '
		<div class="heading">Descriptif et logo de votre boutique</div>
		<div id="list">
		  <table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5">
			<form action="" method="POST" id="modifShopDescription">
			  <input type="hidden" name="C1" value="CO">
			  <input type="hidden" name="C2" value="PE">
			  <input type="hidden" name="C3" value="DE_update">

			  <tr bgcolor="#F1F3F5">
				<td colspan="2" class="h1" align="left">Saisissez ci-dessous une courte description de votre boutique :</td>
			  </tr>'.
			  $this->create_field('Nom de la boutique :', array('R','T','L','M','ShopName'), 'input', 'text', 'data[ShopName]', 50, 60, $result['ShopName']).
			  $this->create_field('Description :', array('R','T','L','M','ShopDescription'), 'input', 'text', 'ShopDescription', 110, 200, $this->myutf8_encode($result['ShopDescription'])).'
			  <tr bgcolor="#FFFFFF">
				<td colspan="2">Cette description sera affich&eacute;e &agrave; droite de votre logo en haut de toutes les pages de votre boutique.</td>
			  </tr>
			  <tr bgcolor="#F1F3F5">
				<td align="center" colspan="2">
				  <a href="#" onClick="checkForm(\'modifShopDescription\')" class="formButton">Enregistrer</a>
				  <b>::</b>
				  <a href="?C1=CO&C2=PE&C3=DE" class="formButton">Annuler</a>
				</td>
			  </tr>

			</form>

			<tr>
			  <td colspan="2" bgcolor="#FFFFFF">&nbsp;</td>
			</tr>

			<form action="" method="POST" enctype="multipart/form-data" id="modifShopLogo">
			  <input type="hidden" name="C1" value="CO">
			  <input type="hidden" name="C2" value="PE">
			  <input type="hidden" name="C3" value="LO_update">

			  <tr bgcolor="#F1F3F5">
				<td colspan="2" class="h1" align="left">Affichez votre logo sur votre boutique <b class="blue">(votre image doit &ecirc;tre au format JPG ou JPEG)</b> :</td>
			  </tr>
			  <tr bgcolor="#FFFFFF">
				<td align="right">Logo actuel :</td>
				<td align="left">'.$logo.'</td>
			  </tr>'.
			  $this->create_field('Logo :', array('R','T','L','M'), 'input', 'file', 'logo', 100, 200, '').'
			  <tr bgcolor="#F1F3F5">
				<td align="center" colspan="2">
				  <a href="#" onClick="checkForm(\'modifShopLogo\')" class="formButton">Enregistrer</a>
				  <b>::</b>
				  <a href="?C1=CO&C2=PE&C3=DE" class="formButton">Annuler</a>
				</td>
			  </tr>

			</form>

		  </table>
		</div>';

		return $form;
	}




	/** *****************************************************************************************************************************
	 * Methode paramForm
	 *
	 * @desc   Affichage du formulaire pour editer les differents parametres de la boutique
	 * @param  bool $result true  = Modification effectuee -> Affichage message de confirmation
	 *                      false = Pas de modif
	 * @return string
	 * @access public
	 */
	public function paramForm($result = false)
	{
		include '../ident.php';

		if ($result == true) {
			$message = '<b class="green">Modification(s) enregistr&eacute;e(s)</b>';
		} else {
			$message = '&nbsp;';
		}

		$mtd              = 'mtd_'.$ManageTradeMark;
		$$mtd             = ' selected="selected"';
		$TradeMarkOptions = '<option value="0"'.$mtd_0.'>Non</option><option value="1"'.$mtd_1.'>Oui</option>';

		$form = '
		<div class="heading">Edition des diff&eacute;rents param&egrave;tres de votre boutique</div>
		<div id="list">

		  <form action="" method="POST" id="formViewNbProduct">
			<input type="hidden" name="C1" value="CO" />
			<input type="hidden" name="C2" value="PE" />
			<input type="hidden" name="C3" value="NA_update" />

			<table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5">
			  <tr bgcolor="#F1F3F5">
				<td colspan="3">'.$message.'</td>
			  </tr>

			  <tr bgcolor="#FFFFFF">
				<td align="right">Nombre d\'articles affich&eacute;s par page : </td>
				<td align="left"><input type="number" name="NbProduct" id="NbProduct" size="3" style="text-align: center;" value="'.$NbProduct.'" maxlength="2" /></td>
				<td class="td_info">C\'est le nombre d\'articles maximum affich&eacute;s sur la premi&egrave;re page de votre boutique.</td>
			  </tr>

			  <tr bgcolor="#F1F3F5">
				<td align="center" colspan="3">
				  <a href="#" onClick="checkForm(\'formViewNbProduct\')" class="formButton">Enregistrer</a>
				  <b>::</b>
				  <a href="?C1=CO&C2=PE&C3=NA" class="formButton">Annuler</a>
				</td>
			  </tr>
			</table>

		  </form>

		</div>';

		return $form;
	}




	/** *****************************************************************************************************************************
	 * Methode viewMenuAvailable
	 *
	 * @desc   Affichage des onglets de menus disponibles sur la boutique
	 * @return string
	 * @access public
	 */
	public function viewMenuAvailable()
	{
		$listMenu = '
		<div class="heading">Edition / activation / d&eacute;sactivation des pages disponibles sur votre boutique</div>
		<div id="list">

		  <table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5">
			<tr bgcolor="#F1F3F5">
			  <td colspan="4" class="h1" align="left">&nbsp;</td>
			</tr>';

		$arrayMenu = array('MenuContact'        => 'Contact',
						   'MenuConditionVente' => 'Conditions de vente',
						   'MenuPaiement'       => 'Modalit&eacute;s de paiement',
						   'MenuSav'            => 'Sarvice apr&egrave;s-vente',
						   'MenuLivraison'      => 'Livraison',
						   'EndPage'            => 'Retour apr&egrave;s paiement');

		$sql = 'SELECT MenuContact, MenuConditionVente, MenuPaiement, MenuSav, MenuLivraison, EndPage FROM Shop';

		$query = $this->query($sql);
		$result = mysql_fetch_array($query);

		foreach ($arrayMenu as $key => $val) {
			if ($key != 'EndPage') {
				if ($result[$key] == "1") {
					$title = 'Menu '.$val.' affcih&eacute;';
					$value = "0";
					$submit = 'D&eacute;sactiver cette page';
				} else {
					$title = 'Menu '.$val.' non affcih&eacute;';
					$value = "1";
					$submit = 'Activer cette page';
				}

				$td = '
				<td align="left">Menu "'.$val.'"</td>
				<td align="center"><img src="./images/'.$result[$key].'.png" alt="'.$result[$key].'" title="'.$title.'" /></td>
				<td align="center">
				  <form action="" method="POST">
					<input type="hidden" name="C1" value="CO" />
					<input type="hidden" name="C2" value="PE" />
					<input type="hidden" name="C3" value="AP" />
					<input type="hidden" name="C4" value="update" />
					<input type="hidden" name="Field" value="'.$key.'" />
					<input type="hidden" name="Value" value="'.$value.'" />
					<input type="submit" name="Submit" value="'.$submit.'" />
				</form>
				</td>
				<td align="right">';
			} else {
				$td = '
				<td align="left">Page "'.$val.'"</td>
				<td align="right" colspan="3">';
			}

			switch ($key) {
			case 'MenuPaiement':
				$linkEdit = '-[ <a href="?C1=CO&C2=PE&C3=CP_edit&f=Ct">Editer le contenu de cette page</a> ]-';
				break;

			case 'MenuConditionVente':
				$linkEdit = '-[ <a href="?C1=CO&C2=PE&C3=CP_edit&f=Cv">Editer le contenu de cette page</a> ]-';
				break;

			case 'MenuSav':
				$linkEdit = '-[ <a href="?C1=CO&C2=PE&C3=CP_edit&f=Sa">Editer le contenu de cette page</a> ]-';
				break;

			case 'MenuLivraison':
				$linkEdit = '-[ <a href="?C1=CO&C2=PE&C3=CP_edit&f=Li">Editer le contenu de cette page</a> ]-';
				break;

			case 'EndPage':
				$linkEdit = '-[ <a href="?C1=CO&C2=PE&C3=CP_edit&f=Ep">Editer le contenu de cette page</a> ]-';
				break;

			default:
				$linkEdit = '&nbsp;';
			}

			$listMenu .= '<tr bgcolor="#F9F9F9">'.$td.$linkEdit.'</td></tr>';
		}

		$listMenu .= '
			<tr bgcolor="#F1F3F5">
			  <td colspan="4">
			  <img src="./images/1.png" alt="Affich&eacute;" title="Affich&eacute;" /> Page visible (activ&eacute;e)<br />
			  <img src="./images/0.png" alt="Non affich&eacute;" title="Non affich&eacute;" /> Page non visible (d&eacute;sactiv&eacute;e)
			</td>
		  </tr>
		</table>

	  </div>';

		return $listMenu;
	}




	/** *****************************************************************************************************************************
	 * Methode editInfosContact
	 *
	 * @desc   Affichage des infos de contact en mode edition
	 * @param  string $f Champ dans lequel prendre les donnees
	 * @return string
	 * @access public
	 */
	public function editInfos($f)
	{
		switch ($f) {
		case 'Ct':
			$field     = 'InfosPaiement';
			$pageTitle = 'Modes de paiement';

			break;

		case 'Cv':
			$field     = 'InfosConditionsVente';
			$pageTitle = 'Conditions de vente';

			break;

		case 'Sa':
			$field     = 'InfosSav';
			$pageTitle = 'SAV';

			break;

		case 'Li':
			$field     = 'InfosLivraison';
			$pageTitle = 'Livraison';

			break;

		case 'Ep':
			$field     = 'EndPage';
			$pageTitle = 'Retour apr&egrave;s paiement';

			break;
		}

		$sql    = 'SELECT '.$field.' FROM Shop';
		$result = mysql_fetch_array($this->query($sql));

		$buttonMessage = 'Enregistrer les modifications apport&eacute;es au contenu de la page "'.$pageTitle.'"';

		$form = '
		<div class="heading">Edition des infos affich&eacute;es sur la page <b class="green">"'.$pageTitle.'"</b></div>
		<div id="list">

		<form action="" method="POST">
		  <input type="hidden" name="C1" value="CO">
		  <input type="hidden" name="C2" value="PE">
		  <input type="hidden" name="C3" value="CP_update">

		  <table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5">
			<tr bgcolor="#F1F3F5">
			  <td colspan="2" class="h1" align="left">&nbsp;</td>
			</tr>
			<tr bgcolor="#F1F1F1">
			  <td align="center" colspan="2"><input type="submit" name="SaveData" value="'.$buttonMessage.'"></td>
			</tr>
			'.$this->create_field('Infos :', array('R','T','L','M'), 'textarea', '', 'data['.$field.']', 0, 0, $result[$field], 120, 40).'
			<tr bgcolor="#F1F3F5">
			  <td align="center" colspan="2"><input type="submit" name="SaveData" value="'.$buttonMessage.'"></td>
			</tr>
		  </table>

		</form>
		</div>';

		return $form;
	}




	/** *****************************************************************************************************************************
	 * Methode saveInfos
	 *
	 * @desc   Enregistrement des infos de contact, conditions de vente, S.A.V. et livraison
	 * @param  array $data Donnees a modifier concernant le champ InfosContact de la table Shop
	 * @return string
	 * @access public
	 */
	public function saveInfos($data)
	{
		$this->update_sql('Shop', $data, 1);
	}




	/** *****************************************************************************************************************************
	 * Methode editCompanyInfo
	 *
	 * @desc   Affichage en mode edition des infos concernant la societe
	 * @param  bool $resultEdit
	 * @return string
	 * @access public
	 */
	public function editCompanyInfo($resultEdit = false)
	{
		/**
		 * Recuperation des donnees de la boutique
		 */
		$sql = 'SELECT City.ID_City, CityName, State.ID_State, StateName, Country.ID_Country, CountryName,
					   ShopName, CompanyName, Address, Telephone, Fax, Gsm, Email, ApeCode, SirenCode
				FROM Shop
				LEFT JOIN City ON Shop.ID_City = City.ID_City
				LEFT JOIN State ON City.ID_State = State.ID_State
				LEFT JOIN Country ON State.ID_Country = Country.ID_Country';

		$query = $this->query($sql);
		$result = mysql_fetch_array($query);

		/**
		 * Recuperation des donnees pour les listes des pays, etats et villes
		 */
		$country_sql  = 'SELECT ID_Country, CountryName FROM Country WHERE Status = "A" ORDER BY CountryName ASC';
		$country_list = $this->liste_select('ID_Country', array('ID_Country', 'CountryName'), '', '', $result['ID_Country'], false, '', $country_sql, false);
		$state_sql    = 'SELECT ID_State, StateName FROM State WHERE ID_Country = '.$result['ID_Country'].' ORDER BY StateName ASC';
		$state_list   = $this->liste_select('ID_State', array('ID_State', 'StateName'), '', '', $result['ID_State'], false, '', $state_sql, false);
		$city_sql     = 'SELECT ID_City, CityName, PostCode FROM City WHERE ID_State = '.$result['ID_State'].' ORDER BY CityName ASC';
		$city_list    = $this->liste_select('ID_City', array('ID_City', 'CityName', 'PostCode'), '', '', $result['ID_City'], false, '', $city_sql, false, ' - ');

		/**
		 * Generation du formulaire
		 */
		if ($resultEdit == true) {
			$rsultEdit = '<b class="green">Modifications enregistr&eacute;es</b>';
		} else {
			$rsultEdit = '&nbsp;';
		}

		$SiretCode = $result['SirenCode'].$result['SiretCode'];

		$form = '
		<div class="heading">Edition des infos soci&eacute;t&eacute;</div>
		<div id="list">

		<form action="" method="POST" name="editCompanyInfo" id="editCompanyInfo">
		  <input type="hidden" name="C1" value="CO">
		  <input type="hidden" name="C2" value="PE">
		  <input type="hidden" name="C3" value="IF_update">

		  <table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5">
			<tr bgcolor="#F1F3F5">
			  <td colspan="2" class="h1" align="left">'.$rsultEdit.'</td>
			</tr>';

		$form .= $this->create_field('Nom de votre soci&eacute;t&eacute; :', array('R','T','L','M','CompanyName'), 'input', 'text', 'data[CompanyName]', 50, 50, $result['CompanyName']);
		$form .= $this->create_field('Adresse :', array('R','T','L','M','Address'), 'textarea', '', 'data[Address]', 0, 0, $result['Address'], 60, 5);

		$form .= '
			<tr bgcolor="#FFFFFF">
			  <td align="right">Pays :</td>
			  <td align="left"><select name="ID_Country" id="ID_Country" onChange="geoData(\'stateList\', \'ID_Country\')">'.$country_list.'</td>
			</tr>

			<tr bgcolor="#FFFFFF">
			  <td align="right">D&eacute;partement :</td>
			  <td align="left"><div id="stateList"><select name="ID_State" id="ID_State" onChange="geoData(\'cityList\', \'ID_State\')">'.$state_list.'</div></td>
			</tr>

			<tr bgcolor="#FFFFFF">
			  <td align="right">Ville :</td>
			  <td align="left"><div id="cityList"><select name="data[ID_City]" id="ID_City">'.$city_list.'</div></td>
			</tr>';

		$form .= $this->create_field('T&eacute;l&eacute;phone :', array('R','T','L','M','Telephone'), 'input', 'text', 'data[Telephone]', 30, 20, $result['Telephone']);
		$form .= $this->create_field('Fax :', array('R','T','L','M','Fax'), 'input', 'text', 'data[Fax]', 30, 20, $result['Fax']);
		$form .= $this->create_field('Portable :', array('R','T','L','M','Gsm'), 'input', 'text', 'data[Gsm]', 30, 20, $result['Gsm']);
		$form .= $this->create_field('Adresse email :', array('R','T','L','M','Email'), 'input', 'text', 'data[Email]', 50, 50, $result['Email']);
		$form .= $this->create_field('Code APE (NAF) :', array('R','T','L','M','ApeCode'), 'input', 'text', 'data[ApeCode]', 7, 6, $result['ApeCode']);
		$form .= $this->create_field('Code SIREN :', array('R','T','L','M','SirenCode'), 'input', 'text', 'data[SirenCode]', 10, 9, $result['SirenCode']);
		//$form .= $this->create_field('Code SIRET :', array('R','T','L','M','SiretCode'), 'input', 'text', 'data[SiretCode]', 15, 14, $SiretCode);
		$form .= '
			<tr bgcolor="#F1F3F5">
			  <td colspan="2" align="center">
				<a href="#" onClick="checkForm(\'editCompanyInfo\')" class="formButton">Enregistrer</a>
				<b>::</b>
				<a href="?C1=CO&C2=PE&C3=IF" class="formButton">Annuler</a>
			  </td>
			</tr>
		  </table>

		</form>
		</div>';

		return $form;
	}




	/** *****************************************************************************************************************************
	 * Methode updateCompanyInfo
	 *
	 * @desc   Affichage en mode edition des infos concernant la societe
	 * @param  array $data Tableau contenant les donnees retournees par le formulaire de modif
	 * @return string
	 * @access public
	 */
	public function updateCompanyInfo($data)
	{
		trim($data['SiretCode']);

		$fields['ID_City']     = $data['ID_City'];
		$fields['CompanyName'] = trim($data['CompanyName']);
		$fields['Address']     = trim($data['Address']);
		$fields['Telephone']   = trim($data['Telephone']);
		$fields['Fax']         = trim($data['Fax']);
		$fields['Gsm']         = trim($data['Gsm']);
		$fields['Email']       = trim(strtolower($data['Email']));
		$fields['ApeCode']     = trim(strtoupper($data['ApeCode']));
		$fields['SirenCode']   = trim($data['SirenCode']);
		//$fields['SiretCode']   = substr($data['SiretCode'], 9);

		$this->update_sql('Shop', $fields, 1);

		return true;
	}




	/** *****************************************************************************************************************************
	 * Methode edit_metatags
	 *
	 * @desc   Affichage en mode edition les donnees presentes dans les meta-tags
     * @param  bool $result_edit
	 * @return string
	 * @access public
	 */
	public function edit_metatags($result_edit = false)
	{
		/**
		 * Generation du formulaire
		 */
		if ($result_edit == true) {
			$result_edit = '<b class="green">Modifications enregistr&eacute;es</b>';
		} else {
			$result_edit = '&nbsp;';
		}

		include '../metatags.php';

		$form = '
		<div class="heading">Edition des m&eacute;tadonn&eacute;es</div>
		<div id="list">

		<form action="" method="post" name="edit_metatags" id="edit_metatags">
		  <input type="hidden" name="C1" value="CO">
		  <input type="hidden" name="C2" value="PE">
		  <input type="hidden" name="C3" value="RE">

		  <table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5">
			<tr bgcolor="#F1F3F5">
			  <td colspan="2" class="h1" align="left">'.$result_edit.'</td>
			</tr>';

		$form .= $this->create_field('Titre du site :', array('R','T','L','M','Title'), 'input', 'text', 'data[Title]', 80, 255, $meta['Title']);
		$form .= $this->create_field('Sujet du site :', array('R','T','L','M','Subject'), 'input', 'text', 'data[Subject]', 80, 255, $meta['Subject']);
		$form .= $this->create_field('Courte description :', array('R','T','L','M','Description'), 'input', 'text', 'data[Description]', 80, 255, $meta['Description']);
		$form .= $this->create_field('Mots cl&eacute; :', array('R','T','L','M','Keywords'), 'input', 'text', 'data[Keywords]', 80, 255, $meta['Keywords'], 0, 0, '<br /><b class="green">Les mots doivent &ecirc;tres s&eacute;par&eacute;s par des virgules</b>');
		$form .= '
			<tr bgcolor="#F1F3F5">
			  <td colspan="2" align="center">
				<a href="#" onClick="checkForm(\'edit_metatags\')" class="formButton">Enregistrer</a>
				<b>::</b>
				<a href="?C1=CO&C2=PE&C3=RE" class="formButton">Annuler</a>
			  </td>
			</tr>
		  </table>

		</form>
		</div>';

		return $form;
	}




	/** *****************************************************************************************************************************
	 * Methode update_metatags
	 *
	 * @desc   Affichage en mode edition des infos concernant la societe
	 * @param  array $data Tableau contenant les donnees retournees par le formulaire de modification
	 * @return string
	 * @access public
	 */
	public function update_metatags($data)
	{
		$data_file = '<?php
$meta[\'Title\']       = \''.$data['Title'].'\';
$meta[\'Subject\']     = \''.$data['Subject'].'\';
$meta[\'Description\'] = \''.$data['Description'].'\';
$meta[\'Keywords\']    = \''.$data['Keywords'].'\';
?>';

		$fp = fopen('../metatags.php', 'w+');
		fwrite($fp, $data_file);
		fclose($fp);

		return true;
	}




    /** *****************************************************************************************************************************
     * Methode config_list
     *
     * @desc   Affichage des parametres de configuration
     * @return string
     * @access public
     */
    public function config_list()
    {
        $log_level = ($this->getParam('param', 'log_level') == '1') ? 'Inactif' : 'Actif';
        $table = '
        <div class="heading">Param&egrave;tres de configuration</div>
        <div id="list">
        <table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5">
          <tr bgcolor="#F1F3F5"><td class="h1" align="left">Param&egrave;tre</td><td class="h1" align="left">Valeur</td></tr>
          <tr bgcolor="#FFFFFF"><td align="right">Serveur :</td><td align="left">'.$this->getParam('database', 'host').'</td></tr>
          <tr bgcolor="#FFFFFF"><td align="right">Base de donn&eacute;es :</td><td align="left">'.$this->getParam('database', 'data').'</td></tr>
          <tr bgcolor="#FFFFFF"><td align="right">Identifiant :</td><td align="left">'.$this->getParam('database', 'user').'</td></tr>
          <tr bgcolor="#FFFFFF"><td align="right">Adresse du site :</td><td align="left">'.$this->getParam('param', 'domain_name').'</td></tr>
          <tr bgcolor="#FFFFFF"><td align="right">Niveau de log :</td><td align="left">'.$log_level.'</td></tr>
          <tr bgcolor="#FFFFFF"><td align="right">Mail 1 (to) :</td><td align="left">'.htmlspecialchars($this->getParam('mail', 'mail_0')).'</td></tr>
          <tr bgcolor="#FFFFFF"><td align="right">Mail 2 (to) :</td><td align="left">'.htmlspecialchars($this->getParam('mail', 'mail_1')).'</td></tr>
          <tr bgcolor="#FFFFFF"><td align="right">Mail 3 (to) :</td><td align="left">'.htmlspecialchars($this->getParam('mail', 'mail_2')).'</td></tr>
          <tr bgcolor="#FFFFFF"><td align="right">Mail (from) :</td><td align="left">'.htmlspecialchars($this->getParam('mail', 'from')).'</td></tr>
          <tr bgcolor="#F1F3F5"><td class="h1" align="center" colspan="2"><a href="?C1=CO&C2=CO&C3=0">Editer ces param&egrave;tres</a></td></tr>
        </table>
        </div>';

        return $table;
    }




    /** *****************************************************************************************************************************
     * Methode config_form
     *
     * @desc   Affichage du formulaire d'edition de la configuration
     * @return string
     * @access public
     */
    public function config_form()
    {
        $form = '
        <div class="heading">Edition des param&egrave;tres de configuration</div>
        <div id="list">

        <form action="" method="post" name="configuration" id="configuration">
          <input type="hidden" name="C1" value="CO">
          <input type="hidden" name="C2" value="CO">
          <input type="hidden" name="C3" value="1">

          <table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5">
            <tr bgcolor="#F1F3F5"><td colspan="2" class="h1" align="left">Base de donn&eacute;es</td></tr>';

        $form .= $this->create_field('Serveur :', array('R','T','L','M','database_host'), 'input', 'text', 'database_host', 40, 50, $this->getParam('database', 'host'));
        $form .= $this->create_field('Base de donn&eacute;es :', array('R','T','L','M','database_data'), 'input', 'text', 'database_data', 40, 50, $this->getParam('database', 'data'));
        $form .= $this->create_field('Identifiant :', array('R','T','L','M','database_user'), 'input', 'text', 'database_user', 40, 50, $this->getParam('database', 'user'));
        $form .= $this->create_field('Mot de passe :', array('R','T','L','M','database_pass'), 'input', 'password', 'database_pass', 40, 50, $this->getParam('database', 'pass'));

        $form .= '<tr bgcolor="#F1F3F5"><td colspan="2" class="h1" align="left">Autres param&egrave;tres</td></tr>';
        $form .= $this->create_field('Adresse du site :', array('R','T','L','M','param_domain_name'), 'input', 'text', 'param_domain_name', 40, 50, $this->getParam('param', 'domain_name'));
        $s = 's'.$this->getParam('param', 'log_level');
        $$s = ' selected="selected"';
        $form .= '
        <tr bgcolor="#FFFFFF">
          <td align="right">Niveau de log :</td>
          <td align="left"><select name="param_log_level"><option value="0"'.$s0.'>Actif</option><option value="1"'.$s1.'>Inactif</option></select></td>
        </tr>';

        $form .= '<tr bgcolor="#F1F3F5"><td colspan="2" class="h1" align="left">Mails</td></tr>';
        $form .= $this->create_field('Mail 1 (to) :', array('R','T','L','M','mail_mail_0'), 'input', 'text', 'mail_mail_0', 60, 60, $this->getParam('mail', 'mail_0'));
        $form .= $this->create_field('Mail 2 (to) :', array('R','T','L','M','mail_mail_1'), 'input', 'text', 'mail_mail_1', 60, 60, $this->getParam('mail', 'mail_1'));
        $form .= $this->create_field('Mail 3 (to) :', array('R','T','L','M','mail_mail_2'), 'input', 'text', 'mail_mail_2', 60, 60, $this->getParam('mail', 'mail_2'));
        $form .= $this->create_field('Mail (from) :', array('R','T','L','M','mail_from'), 'input', 'text', 'mail_from', 60, 60, $this->getParam('mail', 'from'));

        $form .= '
            <tr bgcolor="#F1F3F5">
              <td colspan="2" align="center">
                <a href="#" onClick="checkForm(\'configuration\')" class="formButton">Enregistrer</a> <b>::</b> <a href="?C1=CO&C2=CO" class="formButton">Annuler</a>
              </td>
            </tr>
          </table>

        </form>
        </div>';

        return $form;
    }




    /** *****************************************************************************************************************************
     * Methode config_update
     *
     * @desc   Enregistrement des modifs apportees a la configuration
     * @param  array $form Donnees a enregistrer
     * @return bool
     * @access public
     */
    public function config_update($form)
    {
        $data = '<?php
$cfg[\'param\'][\'domain_name\']   = \''.$form['param_domain_name'].'\';
$cfg[\'param\'][\'apps_name\']     = \''.$this->getParam('param', 'apps_name').'\';
$cfg[\'param\'][\'log_level\']     = '.$form['param_log_level'].';
$cfg[\'database\'][\'host\']       = \''.$form['database_host'].'\';
$cfg[\'database\'][\'data\']       = \''.$form['database_data'].'\';
$cfg[\'database\'][\'user\']       = \''.$form['database_user'].'\';
$cfg[\'database\'][\'pass\']       = \''.$form['database_pass'].'\';
/*$cfg[\'path\'][\'root\']           = \'\';*/
/*$cfg[\'path\'][\'lib\']            = \'\';*/
/*$cfg[\'url\'][\'root\']            = \'http://'.$form['param_domain_name'].'\';*/
$cfg[\'mail\'][\'mail_0\']         = \''.$form['mail_mail_0'].'\';
$cfg[\'mail\'][\'mail_1\']         = \''.$form['mail_mail_1'].'\';
$cfg[\'mail\'][\'mail_2\']         = \''.$form['mail_mail_2'].'\';
$cfg[\'mail\'][\'from\']           = \''.$form['mail_from'].'\';
?>';

        $fp = fopen('../config.php', 'w+');
        $result = fwrite($fp, $data);
        fclose($fp); 
        
        if ($result == true) {
            return true;
        } else {
            return false;
        }
    }





}
?>
