<?php
/* **
 * @application PhpMyShopping
 * @part        Admin Boutique (AB)
 * @file        class.admin.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 Admin
 */

require_once 'class.lib.php';

class Template extends Lib
{
	/** *****************************************************************************************************************************
	 * Constructeur
	 *
	 * @access public
	 */
	public function __construct()
	{
	}




	/** *****************************************************************************************************************************
	 * Methode viewTemplateList
	 *
	 * @desc   Affichage de la liste des templates actives
	 * @return string
	 * @access public
	 */
	public function viewTemplateList()
	{
		$list = '
		<div class="heading">Liste des templates disponibles</div>
		<div id="list">

		<table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5" width="800">';

		/**
		 * Recuperation des donnees pour l'affichage
		 */
		$ID_Template = $this->getField('Shop', 'ID_Template', 'ID_Shop', 1);

		$sql = 'SELECT * FROM Template WHERE Status = "A" ORDER BY ID_Template ASC';
		$query = $this->query($sql);

		while ($result = mysql_fetch_array($query)) {
			if ($result['ID_Template'] == $ID_Template) {
				$imgStatus = '1';
				$class     = 'unactiveTemplate';
				$status    = 'Template actuel';
			} else {
				$imgStatus = '0';
				$class     = 'activeTemplate';
				$status    = 'Activer ce template';
			}

			if (file_exists('../tpl/template/template.jpg')) {
				$img = '<img src="../tpl/template/template.jpg" width="100" height="75" border="0" />';
			} else {
				$img = '&nbsp;'; //'<img src="./images/empty.gif" width="100" height="75" border="0" />';
			}

			$list .= '
			<tr class="row2" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'row2\'">
			  <td align="left" width="25%" valign="top"><b class="blue">'.$result['TemplateName'].'</b></td>
			  <td align="left" width="65%" valign="top">
				<img src="./images/'.$imgStatus.'.png" border="0" />
				[ <a href="?C1=CO&C2=TP&C3=update&IDT='.$result['ID_Template'].'" class="'.$class.'">'.$status.'</a> ]
				<br /><br />
				'.$result['TemplateNote'].'
			  </td>
			  <td align="center" width="10%">'.$img.'</td>
			</tr>';
		}

		$list .= '</table>
		</div>';

		return $list;
	}




	/** *****************************************************************************************************************************
	 * Methode modifTemplateShop
	 *
	 * @desc   Modification du template de la boutique
	 * @param  int $ID_Template Identifiant du template
	 * @return bool
	 * @access public
	 */
	public function modifTemplateShop($ID_Template)
	{
		if ($this->query('UPDATE Shop SET ID_Template = '.$ID_Template)) {
			return true;
		} else {
			return false;
		}
	}
}
?>
