<?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 i18n_messages 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 i18n_messages
* table. This it to support internationalization (i18n) text and
* messages and is used with the LANG tag. As an example if we wanted
* the message 'Welcome' in English, German and French then we would
* setup the following record data:
*
* <table>
* <tr>
* <th>language_id</th>
* <th>message_id</th>
* <th>message</th>
* </tr>
* <tr>
* <td>EN</td>
* <td>WELCOME</td>
* <td>Welcome</td>
* </tr>
* <tr>
* <td>DE</td>
* <td>WELCOME</td>
* <td>Willkommen</td>
* </tr>
* <tr>
* <td>FR</td>
* <td>WELCOME</td>
* <td>Bienvenue</td>
* </tr>
* </table>
*
* This would setup the message_id 'WELCOME' and make it available in the
* three languages specified by the language_id field.
*
* Then in the web page we would use |{LANG:WELCOME}|. This can be used
* anywhere text can be used such as normal text and form elements to set
* button text. When the tage is evaluated the user's language will be
* determined by the value of the session variable 'VCSession_language'. If
* it is not set or there is not an entry for that language then value of
* VC_DEFAULT_LANGUAGE from the configuration file will be used.
**/
class i18n_messages extends VCMaintenance {
/**
* @brief Function to setup defines.
*
* When called this function sets up the following
* defines for use with the i18n_messages module:
*
* NONE
*
* @static
**/
function defines() {
if (!defined('I18N_MESSAGES_SESSION_LANGUAGE')) {
define('I18N_MESSAGES_SESSION_LANGUAGE', 'VCSession_language');
}
}
/**
* @brief Callback hook for VCMaintenance.
*
* This function implements the callback function required
* by VCMaintenance.
*
* @static
**/
function process() {
VCMaintenance::process(new i18n_messages);
}
/**
* @brief Function to delete a row from the i18n_messages table.
*
* This function is used to delete a i18n_messages row based on the unique id.
* The following values from VC_data will be used if available:
*
* <dl>
* <dt>i18n_messages_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;
$i18n_messages_id = VCPage::getSafeVC_data('i18n_messages_id');
$sql = "DELETE FROM i18n_messages where i18n_messages_id=".$i18n_messages_id;
$VC_data['VC_link']->run($sql);
}
/**
* @brief Function to add a row to the i18n_messages table.
*
* This function is used to add a i18n_messages row. The following values
* from VC_data will be used if available:
*
* <dl>
* <dt>language_id</dt>
* <dd>The two letter ISO language code for the language the message is
* in.</dd>
* <dt>message</dt>
* <dd>The text of the message in the language specified by
* language_id.</dd>
* <dt>message_id</dt>
* <dd>The message identifier which should be the same for the message in
* each language being used.</dd>
* </dl>
*
* The following VC_data values will be set:
*
* <dl>
* <dt>i18n_messages_last_insert_id</dt>
* <dd>This is set to the i18n_messages_id of the last row to be added.</dd>
* </dl>
*
* @static
*/
function add() {
global $VC_data;
$language_id = VCPage::getSafeVC_data('language_id');
$message = VCPage::getSafeVC_data('message');
$message_id = VCPage::getSafeVC_data('message_id');
$sql = "INSERT INTO i18n_messages (language_id, message, message_id) values ('$language_id', '$message', '$message_id')";
$VC_data['VC_link']->run($sql);
$VC_data['i18n_messages_last_insert_id'] = $VC_data['VC_link']->getInsertId();
}
/**
* @brief Function to update a i18n_messages row.
*
* This function is used to update a i18n_messages row based on it's unique id.
* The following values from VC_data will be used if available:
*
* <dl>
* <dt>i18n_messages_id</dt>
* <dd>The unique id for a specific message.</dd>
* <dt>language_id</dt>
* <dd>The two letter ISO language code for the language the message is
* in.</dd>
* <dt>message</dt>
* <dd>The text of the message in the language specified by
* language_id.</dd>
* <dt>message_id</dt>
* <dd>The message identifier which should be the same for the message in
* each language being used.</dd>
* <dt>current</dt>
* <dd>If i18n_messages_current_id is set and i18n_messages_id in the row
* is set then this value for the row will be true indicating that the
* value of i18n_messages_id is the current value.</dd>
* </dl>
*
* @static
*/
function update() {
global $VC_data;
$language_id = VCPage::getSafeVC_data('language_id');
$message = VCPage::getSafeVC_data('message');
$message_id = VCPage::getSafeVC_data('message_id');
$i18n_messages_id = VCPage::getSafeVC_data('i18n_messages_id');
$sql = "UPDATE i18n_messages SET language_id='".$language_id."', message='".$message."', message_id='".$message_id."' WHERE i18n_messages_id=".$i18n_messages_id;
$VC_data['VC_link']->run($sql);
}
/**
* @brief Function to retrieve user data.
*
* This function is used to retrieve data from the i18n_messages table. The
* dataSet values returned are:
*
* <dl>
* <dt>i18n_messages_id</dt>
* <dd>The unique id for a specific message.</dd>
* <dt>language_id</dt>
* <dd>The two letter ISO language code for the language the message is
* in.</dd>
* <dt>message</dt>
* <dd>The text of the message in the language specified by
* language_id.</dd>
* <dt>message_id</dt>
* <dd>The message identifier which should be the same for the message in
* each language being used.</dd>
* <dt>current</dt>
* <dd>If i18n_messages_current_id is set and i18n_messages_id in the row
* is set then this value for the row will be true indicating that the
* value of i18n_messages_id is the current value.</dd>
* </dl>
*
* The following values from VC_data will be used if available:
*
* <dl>
* <dt>i18n_messages_current_id</dt>
* <dd>If set this value is used to itentify and flag the row matching the
* specified i18n_messages_id value.</dd>
* <dt>i18n_messages_id</dt>
* <dd>If set only records where i18n_messages_id matches are
* retrieved.</dd>
* </dl>
*
* @static
*/
function getDataSet() {
global $VC_data;
$i18n_messages_current_id = VCPage::getSafeVC_data('i18n_messages_current_id');
$i18n_messages_id = VCPage::getSafeVC_data('i18n_messages_id');
$message_id = VCPage::getSafeVC_data('message_id');
$language_id = VCPage::getSafeVC_data('language_id');
$dataSet = array(array('language_id', 'message', 'message_id', 'i18n_messages_id', 'current'));
$where = "";
if ($i18n_messages_id) {
$where .= " i18n_messages_id = '" . $i18n_messages_id . "' ";
}
if ($message_id) {
if ($where) $where .= " AND ";
$where .= " message_id = '" . $message_id . "' ";
}
if ($language_id) {
if ($where) $where .= " AND ";
$where .= " language_id = '" . $language_id . "' ";
}
if ($where) $where = ' WHERE '.$where;
$sql = 'SELECT language_id, message, message_id, i18n_messages_id FROM i18n_messages '.$where;
$result = $VC_data['VC_link']->execute($sql);
while ($row = $VC_data['VC_link']->getNextRow($result)) {
$current = $i18n_messages_current_id == $row['i18n_messages_id']?VC_TRUE:VC_FALSE;
$dataSet[] = array(stripslashes($row['language_id']), stripslashes($row['message']), stripslashes($row['message_id']), $row['i18n_messages_id'], $current);
}
return $dataSet;
}
}
?>