Location: PHPKode > projects > v-creator > v-creator_1.3-pre3/modules/country.php
<?php
	/*
	 * Copyright (c) 2003 gencon Ltd, all rights reserved.
	 *
	 * This file is part of v-creator.
	 *
   * v-creator 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; either version 2 of the License, or
   * (at your option) any later version.
	 *
   * v-creator 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
	 */

	require_once(VC_ROOT."/classes/VCMaintenance.php");

	/**
	 * @ingroup VCmodules
	 * @brief Class for processing country table functionality.
	 *
	 * $Revision: 1.3 $  $Date: 2005-09-26 12:56:52 $
	 *
	 * @author Generated by GenMaint - Andrew 'Diddymus' Rolfe
	 *
	 * This module is used to maintain and access the country
	 * table.
	 *
	 **/
	class country extends VCMaintenance {

		/**
		 * @brief Function to setup defines.
		 *
		 * When called this function sets up the following
		 * defines for use with the country module:
		 *
		 * NONE
		 *
		 * @static
		 **/
		function defines() {}

		/**
		 * @brief Callback hook for VCMaintenance.
		 *
		 * This function implements the callback function required
		 * by VCMaintenance.
		 *
		 * @static
		 **/
		function process() {
			VCMaintenance::process(new country);
		}

		/**
		 * @brief Function to delete a row from the country table.
		 *
		 * This function is used to delete a country row based on the unique id.
		 * The following values from VC_data will be used if available:
		 *
		 * <dl>
		 *	<dt>country_id</dt>
		 *	<dd>This should be set to the unique id of the row to be deleted.</dd>
		 * </dl>
		 *
		 * @static
		 */
		function delete() {
			global $VC_data;

			$country_id = VCPage::getSafeVC_data('country_id');

			$sql = "DELETE FROM country where country_id=".$country_id;
			$VC_data['VC_link']->run($sql);

		}

		/**
		 * @brief Function to add a row to the country table.
		 *
		 * This function is used to add a country row. The following values
		 * from VC_data will be used if available:
		 *
		 * <dl>
		 *  <dt>country</dt>
		 *  <dd>Name of the country.</dd>
		 *  <dt>two_letter_code</dt>
		 *  <dd>Two letter ISO code for the country.</dd>
		 *  <dt>three_letter_code</dt>
		 *  <dd>Three letter ISO code for the country.</dd>
		 *  <dt>numeric_code</dt>
		 *  <dd>Numeric ISO code for the country.</dd>
		 * </dl>
		 *
		 * The following VC_data values will be set:
		 *
		 * <dl>
		 *  <dt>country_last_insert_id</dt>
		 *	<dd>This is set to the country_id of the last row to be added.</dd>
		 * </dl>
		 *
		 * @static
		 */
		function add() {
			global $VC_data;

			$country = VCPage::getSafeVC_data('country');
			$two_letter_code = VCPage::getSafeVC_data('two_letter_code');
			$three_letter_code = VCPage::getSafeVC_data('three_letter_code');
			$numeric_code = VCPage::getSafeVC_data('numeric_code');

			$sql = "INSERT INTO country (country, two_letter_code, three_letter_code, numeric_code) values ('$country', '$two_letter_code', '$three_letter_code', '$numeric_code')";
			$VC_data['VC_link']->run($sql);
			$VC_data['country_last_insert_id'] = $VC_data['VC_link']->getInsertId();
		}

		/**
		 * @brief Function to update a country row.
		 *
		 * This function is used to update a country row based on it's unique id.
		 * The following values from VC_data will be used if available:
		 *
		 * <dl>
		 *  <dt>country_id</dt>
		 *  <dd>Unique record id for the country.</dd>
		 *  <dt>country</dt>
		 *  <dd>Name of the country.</dd>
		 *  <dt>two_letter_code</dt>
		 *  <dd>Two letter ISO code for the country.</dd>
		 *  <dt>three_letter_code</dt>
		 *  <dd>Three letter ISO code for the country.</dd>
		 *  <dt>numeric_code</dt>
		 *  <dd>Numeric ISO code for the country.</dd>
		 * </dl>
		 *
		 * @static
		 */
		function update() {
			global $VC_data;
			$country_id = VCPage::getSafeVC_data('country_id');
			$country = VCPage::getSafeVC_data('country');
			$two_letter_code = VCPage::getSafeVC_data('two_letter_code');
			$three_letter_code = VCPage::getSafeVC_data('three_letter_code');
			$numeric_code = VCPage::getSafeVC_data('numeric_code');

			$sql = "UPDATE country SET country='".$country."', two_letter_code='".$two_letter_code."', three_letter_code='".$three_letter_code."', numeric_code='".$numeric_code."' WHERE country_id=".$country_id;
			$VC_data['VC_link']->run($sql);

		}

		/**
		 * @brief Function to retrieve user data.
		 *
		 * This function is used to retrieve data from the country table. The
		 * dataSet values returned are:
		 *
		 * <dl>
		 *  <dt>country_id</dt>
		 *  <dd>Unique record id for the country.</dd>
		 *  <dt>country</dt>
		 *  <dd>Name of the country.</dd>
		 *  <dt>two_letter_code</dt>
		 *  <dd>Two letter ISO code for the country.</dd>
		 *  <dt>three_letter_code</dt>
		 *  <dd>Three letter ISO code for the country.</dd>
		 *  <dt>numeric_code</dt>
		 *  <dd>Numeric ISO code for the country.</dd>
		 *  <dt>current</dt>
		 *  <dd>If country_current_id is set and country_id in the row is
		 *      set then this value for the row will be true indicating that
		 *      the value of country_id is the current value.</dd>
		 * </dl>
		 *
		 * The following values from VC_data will be used if available:
		 *
		 * <dl>
		 *	<dt>country_current_id</dt>
		 *	<dd>If set this value is used to itentify and flag the row matching the
		 *			specified country_id value.</dd>
		 *	<dt>country_id</dt>
		 *	<dd>If set only records where country_id matches are retrieved.</dd>
		 * </dl>
		 *
		 * @static
		 */
		function getDataSet() {
			global $VC_data;

			$country_current_id = VCPage::getSafeVC_data('country_current_id');
			$country_id = VCPage::getSafeVC_data('country_id');

			$dataSet = array(array('country_id', 'country', 'two_letter_code', 'three_letter_code', 'numeric_code', 'current'));

			$where = "";

			if ($country_id) {
				$where .= " country_id = '".$country_id."' ";
			}

			if ($where) $where = ' WHERE '.$where;

			$sql = 'SELECT country_id, country, two_letter_code, three_letter_code, numeric_code FROM country '.$where;
			$result = $VC_data['VC_link']->execute($sql);

			while ($row = $VC_data['VC_link']->getNextRow($result)) {
				$current = $country_current_id == $row['country_id']?VC_TRUE:VC_FALSE;
				$dataSet[] = array($row['country_id'], stripslashes($row['country']), stripslashes($row['two_letter_code']), stripslashes($row['three_letter_code']), $row['numeric_code'], $current);
			}

			return $dataSet;
		}
}

?>
Return current item: v-creator