<?php
/**
 * Functions to deal with tables.
 *
 * PHPGEN 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.
 *
 * PHPGEN 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 PHPGEN; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @copyright   EasySoft R&D Team (C) 2006
 * @author      Chunsheng Wang <wwccss@263.net>
 * @link        http://www.phpgen.com
 * @package     Include
 * @version     $Id: FuncTable.php,v 1.3 2006/08/15 14:36:35 wangcs Exp $
 */

/**
 * Get the full path of one project's tables's config files saving dir of a user.
 *
 * @author                      wwccss <wwccss@263.net>
 * @param   string  $UserName
 * @param   int     $ProjectID
 * @return  string              the full path of the tables' config file save dir.
 */
function tblGetHome($UserName, $ProjectID)
{
    global $_CFG;
    return prjGetHome($UserName, $ProjectID) . $_CFG["TableHome"];
}

/**
 * Get full path of tables index file of a project.
 *
 * @author                      wwccss <wwccss@263.net>
 * @param   string  $UserName
 * @param   int     $ProjectID
 * @return  string              the full path of the index file.
 */
function tblGetIndexFile($UserName, $ProjectID)
{
    global $_CFG;
    return prjGetHome($UserName, $ProjectID) . $_CFG["IndexTBL"];
}

/**
 * Save tables indexes to file.
 *
 * @author                          wwccss <wwccss@263.net>
 * @param   string  $UserName
 * @param   int     $ProjectID
 * @param   string  $ArrayString    the array string created by array2String function.
 */
function tblSaveIndexFile($UserName, $ProjectID, $ArrayString)
{
    $IndexPage = tblGetIndexFile($UserName, $ProjectID);
    $FileID    = fopen($IndexPage, "w+");
    fwrite($FileID, $ArrayString);
    fclose($FileID);
}

/**
 * Get tables list of a project.
 *
 * @author                          wwccss <wwccss@263.net>
 * @param   string  $UserName
 * @param   int     $ProjectID
 * @return  array                   the pages list array.
 */
function tblGetList($UserName, $ProjectID)
{
    $IndexFile  = tblGetIndexFile($UserName, $ProjectID);
    if(file_exists($IndexFile))
    {
        require($IndexFile);
        return $Tables;
    }
    else
    {
        return false;
    }
}
/**
 * Get the full path of the config file of a table.
 *
 * @author                      wwccss <wwccss@263.net>
 * @param   string  $UserName
 * @param   int     $ProjectID
 * @param   string  $TableName
 * @return  string              the full path of the table's config file.
 */
function tblGetConfigFile($UserName, $ProjectID, $TableName)
{
    return tblGetHome($UserName, $ProjectID). $TableName .".php";
}

/**
 * Write defination of a table to file.
 *
 * @author                          wwccss <wwccss@263.net>
 * @param   string  $UserName
 * @param   int     $ProjectID
 * @param   string  $TableName
 * @param   $String $ArrayString    the string created by array2String function.
 */
function tblSaveConfigFile($UserName, $ProjectID, $TableName, $ArrayString)
{
    $TableCFG = tblGetConfigFile($UserName, $ProjectID, $TableName);         // Get config file's full path.
    !file_exists(dirname($TableCFG)) ? sysMkdir(dirname($TableCFG)) : "";    // Create the dir.
    $FileID  = fopen($TableCFG, "w+");
    fwrite($FileID, $ArrayString);
    fclose($FileID);
}

/**
 * Get defination of a table.
 *
 * @author                          wwccss <wwccss@263.net>
 * @param   string  $UserName
 * @param   int     $ProjectID
 * @param   string  $TableName
 * @return  array                   the config array of the table.
 */
function tblGetInfo($UserName, $ProjectID, $TableName)
{
    $TableCFG = tblGetConfigFile($UserName, $ProjectID, $TableName);
    if(file_exists($TableCFG))
    {
        require($TableCFG);
        return $Table;
    }
    else
    {
        return false;
    }
}
/**
 * Get label of a table.
 *
 * @author                          wwccss <wwccss@263.net>
 * @param   string  $UserName
 * @param   int     $ProjectID
 * @param   string  $TableName
 * @return  string                  the label of the table.
 */
function tblGetLabel($UserName, $ProjectID, $TableName)
{
    $Tables = tblGetList($UserName, $ProjectID);
    if(!empty($Tables[$TableName]["Label"]))
    {
        return $Tables[$TableName]["Label"];
    }
    else
    {
        return $TableName;
    }
}
?>
<?php
/**
 * $Log: FuncTable.php,v $
 * Revision 1.3  2006/08/15 14:36:35  wangcs
 *  * Add copyright info.
 *
 * Revision 1.2  2006/04/22 03:54:54  wangcs
 *  * Change to PHPGEN.
 *
 * Revision 1.1  2006/01/23 09:27:30  wangcs
 * *** empty log message ***
 *
 */
?>