<?php
/* **
 * @application PhpMyShopping
 * @part        Admin boutique
 * @file        personalisation.php
 * @path        ./admin/
 * @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
 */

if ((!isset($_SESSION['LoginOk']) or $_SESSION['LoginOk'] != 'IdentOk')) {
    header('Location: ./login.php');
}

require_once 'include/class.personnalisation.php';
$perso = new Personnalisation();

switch ($C3) {
/** -------------------------------------------------------------------------------------
 * Descriptif de la boutique
 */
case 'DE':
	echo $perso->modifShopDescription();
	break;

/** -------------------------------------------------------------------------------------
 * Mise en place / remplacement du logo
 */
case 'LO_update':
	if ($_FILES['logo']['name']) {
		$img_info = @getimagesize($_FILES['logo']['tmp_name']);

		if ($img_info[2] == 2) {
			$width = ($img_info[0] < 180) ? $img_info[0] : 180;
			$height = ($img_info[1] < 90) ? $img_info[1] : 90;

			system('rm -f ../images/logo.*');
			$admin->writeImage($_FILES['logo']['tmp_name'], 'logo', array(array($width, $height, '../images')));
			$data['Logo'] = '1';
			$admin->update_sql('Shop', $data, 1);
		} else {
			echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;<b class="red">
			Votre image n\'a pas &eacute;t&eacute; mise en place car elle n\'est pas au format JPG</b><br /><br />';
		}
	}

	echo $perso->modifShopDescription();
	break;


/** -------------------------------------------------------------------------------------
 * Prise en compte de la modification de la description courte
 */
case 'DE_update':
	if ($_POST['ShopDescription']) {
		$data['ShopDescription'] = $perso->myutf8_decode($_POST['ShopDescription']);
	} else {
		$data['ShopDescription'] = '';
	}

	$perso->update_sql('Shop', $data);
	echo '&nbsp;&nbsp;&nbsp;&nbsp;<b class="green">Modification effectu&eacute;e</b>';
	echo $perso->modifShopDescription();
	break;

/** -------------------------------------------------------------------------------------
 * Definition du nombre d'articles affiches sur la page d'acceuil
 */
case 'NA':
	echo $perso->paramForm();
	break;

/** -------------------------------------------------------------------------------------
 * Enregistrement du nombre d'article affiches sur la page index.php
 */
case 'NA_update':
	include '../ident.php';

	$data = '<?php
$NbProduct = '.$_POST['NbProduct'].';
?>';

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

	echo $perso->paramForm(true);
	break;

/** -------------------------------------------------------------------------------------
 * Affichage des menus disponible sur la boutique avec possibilite d'activation ou non
 */
case 'AP':
	if ($_POST['C4'] == 'update') {
		/**
		 * Modification de l'etat d'affichage d'un menu
		 */
		$sql = 'UPDATE Shop SET '.$_POST['Field'].' = "'.$_POST['Value'].'"';
		$perso->query($sql);
	}

	echo $perso->viewMenuAvailable();
	break;

/** -------------------------------------------------------------------------------------
 * Affichage des infos de contact en mode edition
 */
case 'CP_edit':
	echo $perso->editInfos($_GET['f']);
	break;

/** -------------------------------------------------------------------------------------
 * Enregistrement des modification des infos de contact
 */
case 'CP_update':
	echo $perso->saveInfos($_POST['data']);
	echo $perso->viewMenuAvailable();
	break;

/** -------------------------------------------------------------------------------------
 * Edition des infos de la societe
 */
case 'IF':
	echo $perso->editCompanyInfo();
	break;

/** -------------------------------------------------------------------------------------
 * Mise a jour des infos de la societe
 */
case 'IF_update':
	$result = $perso->updateCompanyInfo($_POST['data']);
	echo $perso->editCompanyInfo($result);
	break;

/** -------------------------------------------------------------------------------------
 * Mise a jour des infos de la societe
 */
case 'RE':
	if ($_POST['data']) {
		$result = $perso->update_metatags($_POST['data']);
	}

	echo $perso->edit_metatags($result);
	break;
}
?>
