<?php
// $Id: pninit.php,v 1.2 2005/02/19 18:47:01 markwest Exp $
// ----------------------------------------------------------------------
// PostNuke Content Management System
// Copyright (C) 2002 by the PostNuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program 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.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------


/**
 * initialise the languages module
 *
 * This function is only ever called once during the lifetime of a particular
 * module instance.
 * This function MUST exist in the pninit file for a module
 *
 * @author       Mark West
 * @version      $Revision: 1.2 $
 * @return       bool       true on success, false otherwise
 */
function Languages_init()
{
    // Get database information
    $dbconn =& pnDBGetConn(true);
    $pntable =& pnDBGetTables();

    // Create tables
    $languages_constant_table = $pntable['languages_constant'];
    $languages_constant_column = &$pntable['languages_constant_column'];
    $sql = "CREATE TABLE $languages_constant_table (
		  	$languages_constant_column[constant] varchar(32) NOT NULL default '',
  			$languages_constant_column[file] varchar(64) NOT NULL default '',
			PRIMARY KEY  (pn_constant))";
    $dbconn->Execute($sql);
    // Check database result
    if ($dbconn->ErrorNo() != 0) {
        // Report failed initialisation attempt
        return false;
    }

    $languages_file_table = $pntable['languages_file'];
    $languages_file_column = &$pntable['languages_file_column'];
    $sql = "CREATE TABLE $languages_file_table (
			$languages_file_column[target] varchar(64) NOT NULL default '',
			$languages_file_column[source] varchar(64) NOT NULL default '',
			PRIMARY KEY  (pn_target,pn_source),
			UNIQUE KEY source (pn_source))";
    $dbconn->Execute($sql);
    // Check database result
    if ($dbconn->ErrorNo() != 0) {
        // Report failed initialisation attempt
        return false;
    }

    $languages_translation_table = $pntable['languages_translation'];
    $languages_translation_column = &$pntable['languages_translation_column'];
    $sql = "CREATE TABLE $languages_translation_table (
  			$languages_translation_column[language] varchar(32) NOT NULL default '',
			$languages_translation_column[constant] varchar(32) NOT NULL default '',
			$languages_translation_column[translation] longblob NOT NULL default '',
			$languages_translation_column[level] tinyint(4) NOT NULL default '0',
			PRIMARY KEY  (pn_constant,pn_language))";
    $dbconn->Execute($sql);
    // Check database result
    if ($dbconn->ErrorNo() != 0) {
        // Report failed initialisation attempt
        return false;
    }
    // Initialisation successful
    return true;
}


/**
 * upgrade the Languages module from an old version
 *
 * This function can be called multiple times
 * This function MUST exist in the pninit file for a module
 *
 * @author       Mark West
 * @version      $Revision: 1.2 $
 * @return       bool       true on success, false otherwise
 */
function Languages_upgrade($oldversion)
{
    // Upgrade dependent on old version number
    switch($oldversion) {
        case 1.2:
            // Version 1.2 didn't have a the autodetect falg
			pnConfigSetVar('language_detect', 0);
            return Languages_upgrade(1.3);
            break;
    }

    // Update successful
    return true;
}


/**
 * delete the Languages module
 *
 * This function is only ever called once during the lifetime of a particular
 * module instance
 * This function MUST exist in the pninit file for a module
 *
 * @author       Mark West
 * @version      $Revision: 1.2 $
 * @return       bool       true on success, false otherwise
 */
function Languages_delete()
{
    // Get database information
    $dbconn =& pnDBGetConn(true);
    $pntable =& pnDBGetTables();

    // Delete tables
    $sql = "DROP TABLE $pntable[languages_constant];";
    $dbconn->Execute($sql);
    // Check database result
    if ($dbconn->ErrorNo() != 0) {
        // Report failed deletion attempt
        return false;
    }

    $sql = "DROP TABLE $pntable[languages_file];";
    $dbconn->Execute($sql);
    // Check database result
    if ($dbconn->ErrorNo() != 0) {
        // Report failed deletion attempt
        return false;
    }

    $sql = "DROP TABLE $pntable[languages_translation];";
    $dbconn->Execute($sql);
    // Check database result
    if ($dbconn->ErrorNo() != 0) {
        // Report failed deletion attempt
        return false;
    }

    // Deletion successful
    return true;
}

?>