{include file="header.html"} {$text.db_selected} {$f_db}
{$table}
{$text.see_log}
{$message_log}

# {$text.generate_tool_version} {$generating_version}

    //{$text.add_in_obj_loader}
    /**
     * {$class_name}
     *
     * @return {$class_name}
     */
    function &get{$class_name}() {literal}{{/literal}
    	$object_name = "{$class_name}";

    	$object =& $this->xLoadThisObjectV2($object_name, $this->m_is_for_front );

    	$object =& $this->xLoadThisObjectV2($object_name, $this->m_is_for_back );

    	if (is_null($object)) {literal}{{/literal}

    		require_once("internal_components/front_sites/{$table_name}/{$table_name}_fo.class.php");

    		require_once("internal_components/admin_sites/{$table_name}/{$table_name}.class.php");

    		require_once("internal_components/admin_plici/{$table_name}/{$table_name}.class.php");

    		$object = new {$class_name}();
    		$this->xSetNewObject($object, $object_name);
    	}
    	return $object;
    }

    //{$text.error_request}

    <?php

    /**
     * {$class_name} Class
     *
     *
     * @author SimpliciWeb
     * @version $Id: _generating.html 781 2007-12-27 13:07:16Z stephanet $

     * @package FrontOffice

     * @package BackOffice

     * @package @ACHANGER@

     * @subpackage @ACHANGER@
     */
    /**
     * @ACHANGER@Description
     *
     *
     *
     *	Table Name : {$table_name}
     *

     *	{$value.name} ({$value.type},{$value.length})

     *
     *
     *
     * @author SimpliciWeb
     * @version $Id: _generating.html 781 2007-12-27 13:07:16Z stephanet $

     * @package FrontOffice

     * @package BackOffice

     * @package @ACHANGER@

     * @subpackage @ACHANGER@
     */
    class {$class_name} {literal}{{/literal}

    	// member object
    	/**
    	 * Format Object
    	 *
    	 * @var Format
    	 */
    	var $m_object_format 			= NULL;
    	/**
    	 * Database Connexion object
    	 *
    	 * @var DbConnexion
    	 */
    	var $m_object_dbconnexion 		= NULL;

    	// member request
    	/**
    	 * SQL Request : Select by primary key
    	 *
    	 * @var string
    	 */
    	var $req_select_by_primary_key	= "";
    	/**
    	 * SQL Request : Select
    	 *
    	 * @var string
    	 */
    	var $req_select 				= "";
    	/**
    	 * SQL Request : Count
    	 *
    	 * @var string
    	 */
    	var $req_count 					= "";

    	/**
    	 * SQL Request : Insert
    	 *
    	 * @var string
    	 */
        var $req_insert					= "";
    	/**
    	 * SQL Request : Delete
    	 *
    	 * @var string
    	 */
    	var $req_delete					= "";
    	/**
    	 * SQL Request : Update
    	 *
    	 * @var string
    	 */
    	var $req_update					= "";

        /**
         * The name of the class when printing errors
         *
         * @var string
         */
    	var $class_name_for_error		= "{$class_name}::";

    	/**
    	 * Constructor, init the requests and objects
    	 *
    	 * @return {$class_name}
    	 */
    	function __construct() {literal}{{/literal}
    		global $g_object_loader;
    		$this->m_object_format =& $g_object_loader->getFormat();
    		$this->m_object_dbconnexion =& $g_object_loader->getDbConnexion();

    		$this->req_select_by_primary_key	=
    "SELECT {$string_champs}
    FROM {$table_name}
    WHERE {$string_primary_to_set}
    LIMIT 0,1;";

    		$this->req_select 					=
    "SELECT {$string_champs}
    FROM {$table_name}
    ORDER BY {$string_to_change};";

    		$this->req_count 					=
    "SELECT COUNT(*)
    FROM {$table_name};";

    		$this->req_insert					=
    "INSERT INTO {$table_name}({$string_champs_insert})
    VALUES({$string_sprintf_insert});";

    		$this->req_delete					=
    "DELETE
    FROM {$table_name}
    WHERE {$string_primary_to_set};";

    		$this->req_update					=
    "UPDATE {$table_name}
    SET {$string_update_to_set}
    WHERE {$string_primary_to_set};";

    	}

    	/**
    	 * Php5 Destructor
    	 *
    	 */
    	function __destruct() {literal}{{/literal}
    	}

    	/**
    	 * Constructor, init the requests and objects
    	 *
    	 * @return {$class_name}
    	 */
    	function {$class_name}() {literal}{{/literal}
    		$this->__construct();
    	}

    	/**
    	 * Parameter Integrity checker @CHANGER@
    	 *
    	 * @access private
    	 * @param string $p_value
    	 * @return  bool TRUE if not valid
    	 */
    	function xIsNotValid{$value.nameLiteral}($p_value) {literal}{{/literal}
    		global $g_object_loader;
    		$object_tmp =& $g_object_loader->get@ACHANGER@();
    		return $object_tmp->xIsNotValid@ACHANGER@($p_value);
    	}

    	/**
    	 * Parameter Integrity checker :  {$value.formatIsValid}
    	 *
    	 * @access private
    	 * @param string $p_value
    	 * @return  bool TRUE if not valid
    	 */
    	function xIsNotValid{$value.nameLiteral}($p_value) {literal}{{/literal}
    		return $this->m_object_format->{$value.formatIsValid};
    	}

    	/**
    	 * Get one {$class_name}
    	 *

    	 * @param {$value.type_phpdoc} {$value.param_name}

    	 * @return bool TRUE on error
    	 */
    	function getOne{$class_name}(&$r_result, {$string_primary_params}) {literal}{{/literal}

    		// Set result to empty
    		$r_result = array();

    		// Valid input

    		if ($this->xIsNotValid{$value.nameLiteral}({$value.param_name}))
    			return onErrorThrow(true, plici_lang("lang_error_field"));

    		// Set request parameter
    		$parameters = array({$string_primary_params});

    		// Declare database request result
    		$result = "";

    		// Execute request
    		if ($this->m_object_dbconnexion->makeSqlQuery($this->req_select_by_primary_key, $parameters, $result)) {literal}{{/literal}
    			return onErrorThrow(true, plici_lang("lang_error_internal"));
    		}

    		// Arrange result
    		while ($row = mysql_fetch_row($result)) {literal}{{/literal}
    	  		$this->xRowToArray($row, $r_result);

    		}

    		// Return no error code
    		return false;
    	}

    	/**
    	 * Get list
    	 *
    	 * @param array $r_result
    	 * @return bool TRUE on error
    	 */
    	function getList{$class_name}(&$r_result) {literal}{{/literal}

    		// Set result to empty
    		$r_result = array();

    		// Set request parameter
    		$parameters = array();

    		// Declare database request result
    		$result = "";

    		// Execute request
    		if ($this->m_object_dbconnexion->makeSqlQuery($this->req_select, $parameters, $result)) {literal}{{/literal}
    			return onErrorThrow(true, plici_lang("lang_error_internal"));
    		}

    		// Arrange result
    		while ($row = mysql_fetch_row($result)) {literal}{{/literal}
    	  		$this->xRowToArray($row, $r_result[]);
    		}

    		// Return no error code
    		return false;
    	}

    	/**
    	 * Get count
    	 *
    	 * @param integer $r_result_count
    	 * @return bool TRUE on error
    	 */
    	function getCount{$class_name}(&$r_result_count) {literal}{{/literal}

    		// Set result to empty
    		$r_result_count = 0;

    		// Set request parameter
    		$parameters = array();

    		// Declare database request result
    		$result = "";

    		// Execute request
    		if ($this->m_object_dbconnexion->makeSqlQuery($this->req_count, $parameters, $result)) {literal}{{/literal}
    			return onErrorThrow(true, plici_lang("lang_error_internal"));
    		}

    		// Arrange result
    		while ($row = mysql_fetch_row($result)) {literal}{{/literal}
    			$r_result_count  = $row[0];
    		}

    		// Return no error code
    		return false;
    	}

    	/**
    	 * Test if exist
    	 *
    	 * @param bool $r_is_existing

    	 * @param {$value.type_phpdoc} {$value.param_name}

    	 * @return bool TRUE on error
    	 */
    	function exist{$class_name}(&$r_is_existing, {$string_primary_params}) {literal}{{/literal}

    		// Set result to empty
    		$r_result = "";
    		$there_is_an_error = $this->getOne{$class_name}($r_result, {$string_primary_params});
    		$r_is_existing = sizeof($r_result) > 0;

    		return $there_is_an_error;
    	}

    	/**
    	 * Insert
    	 *

    	 * @param {$value.type_phpdoc} {$value.param_name}

    	 * @return bool TRUE on error
    	 */
    	function insert{$class_name}({$string_params_insert}/*, &$r_result_id*/) {literal}{{/literal}

    		// Set result to empty
    		/*$r_result_id = "";*/

    		global $g_object_loader;
    		$g_object_message =& $g_object_loader->getMessage();

    		// Valid input

    		onErrorThrow($this->xIsNotValid{$value.nameLiteral}({$value.param_name}), plici_lang("lang_error_field"));

    		if ($g_object_message->thereIsAnError()) {literal}{{/literal}
    			return true;
    		}

    		// Set request parameter
    		$parameters = array();

    		$parameters[] = {$value.param_name};

    		// Declare database request result
    		$result = "";

    		// Execute request
    		$this->m_object_dbconnexion->makeSqlQuery($this->req_insert, $parameters, $result);

    		/*$r_result_id = mysql_insert_id();*/

    		return onErrorThrow(!$result, plici_lang("lang_error_internal"));
    	}

    	/**
    	 * Update
    	 *

    	 * @param {$value.type_phpdoc} {$value.param_name}

    	 * @param {$value.type_phpdoc} {$value.param_name}

    	 * @param integer $r_nb_row_affected
    	 * @return bool TRUE on error
    	 */
    	function update{$class_name}({$string_params_update}, {$string_primary_params}, &$r_nb_row_affected) {literal}{{/literal}

    		// Set result to empty
    		$r_nb_row_affected = 0;

    		global $g_object_loader;
    		$g_object_message =& $g_object_loader->getMessage();

    		// Valid input

    		onErrorThrow($this->xIsNotValid{$value.nameLiteral}({$value.param_name}), plici_lang("lang_error_field"));

    		onErrorThrow($this->xIsNotValid{$value.nameLiteral}({$value.param_name}), plici_lang("lang_error_field"));

    		if ($g_object_message->thereIsAnError()) {literal}{{/literal}
    			return true;
    		}

    		// Set request parameter
    		$parameters = array();

    		$parameters[] = {$value.param_name};

    		$parameters[] = {$value.param_name};

    		// Declare database request result
    		$result = "";

    		// Execute request
    		if ($this->m_object_dbconnexion->makeSqlQuery($this->req_update, $parameters, $result)) {literal}{{/literal}
    			return onErrorThrow(true, 'sqlUpdate', plici_lang("lang_error_internal"));
    		}

    		$r_nb_row_affected = mysql_affected_rows();

    		// Return no error code
    		return false;
    	}

    	/**
    	 * Delete {$class_name}
    	 *

    	 * @param {$value.type_phpdoc} {$value.param_name}

         * @param integer $r_nb_row_affected
    	 * @return bool TRUE on error
    	 */
    	function delete{$class_name}({$string_primary_params}, &$r_nb_row_affected) {literal}{{/literal}

    		// Set result to empty
    		$r_nb_row_affected = 0;

    		global $g_object_loader;
    		$g_object_message =& $g_object_loader->getMessage();

    		// Valid input

    		onErrorThrow($this->xIsNotValid{$value.nameLiteral}({$value.param_name}), plici_lang("lang_error_field"));

    		if ($g_object_message->thereIsAnError()) {literal}{{/literal}
    			return true;
    		}

    		// Set request parameter
    		$parameters = array();

    		$parameters[] = {$value.param_name};

    		// Declare database request result
    		$result = "";

    		// Execute request
    		if ($this->m_object_dbconnexion->makeSqlQuery($this->req_delete, $parameters, $result)) {literal}{{/literal}
    			return onErrorThrow(true, 'sqlDelete', plici_lang("lang_error_internal"));
    		}

    		$r_nb_row_affected = mysql_affected_rows();

    		// Return no error code
    		return false;
    	}

    	/**
    	 * Convert a number indexed array to an fieldname indexed array
    	 *
    	 * @access private
    	 * @param array $p_row
    	 * @param array $r_result
    	 */
    	function xRowToArray($p_row, &$r_result) {literal}{{/literal}
    				$r_result = array(

    								'{$value.name}'	=>	$this->m_object_dbconnexion->translate("DB_TO_HTML", $p_row[{$i}]),

    								'{$value.name}'	=>	$p_row[{$i}],

    								 );
    	}

    }

    	?>

{include file="footer.html"}