<?php

global $VERSION;

$VERSION = "mcweb 1.1";

function readconfig (){

    global $DBHOSTNAME;
    global $DBNAME;
    global $DBUSER;
    global $DBPASSWORD;
    global $RESNAME;
    global $DEBUG;

    $configfile = '/usr/local/etc/mcweb.conf';

    if (!file_exists($configfile) || !$configfh = fopen($configfile,"r")) {
        exit("error - cannot read config file $configfile, either file notexistent or wrong permissions");
    };
    
    while(!feof($configfh)) {
        $line = fgets($configfh);
        if (!ereg('^#.*', $line)) {
            $currentline = split('\s*=\s*', $line);
            if (trim($currentline[0]) == "dbhost"){
                $DBHOSTNAME = trim($currentline[1]);
            };
            if (trim($currentline[0]) == "dbname"){
                $DBNAME = trim($currentline[1]);
            };
            if (trim($currentline[0]) == "dbuser"){
                $DBUSER = trim($currentline[1]);
            };
            if (trim($currentline[0]) == "dbpassword"){
                $DBPASSWORD = trim($currentline[1]);
            };
            if (trim($currentline[0]) == "debug"){
                $DEBUG = trim($currentline[1]);
            };
        };
    };
    fclose($configfh);
};

function db_connect(){
    
    global $DBHOSTNAME;
    global $DBNAME;
    global $DBUSER;
    global $DBPASSWORD;
    global $DBCONN;
    global $ERRORTEXT;
    
    if (!($DBCONN = pg_connect("host=$DBHOSTNAME dbname=$DBNAME user=$DBUSER password=$DBPASSWORD"))) {
	$ERRORTEXT = 'Cannot Connect to PostgreSQL';
	include 'errorparam.php';
	return(1);
    };
    return(0);
};

function getrowclass($rownumber, $classone, $classtwo) {
    if ($rownumber / 2.0 - intval($rownumber / 2.0) > 0 ) {
        return($classone);
    } else {
        return($classtwo);
    };
};

function gettoday(){
    $datedata = localtime(time(),1);
    $datedata['tm_mon']++;
    $datedata['tm_year']= $datedata['tm_year'] + 1900;
    return(sprintf('%02d', $datedata['tm_mon']) . "/" . sprintf('%02d', $datedata['tm_mday']) . "/" . 
	$datedata['tm_year'] . " " . sprintf('%02d', $datedata['tm_hour']) . ":" . 
	sprintf('%02d', $datedata['tm_min']) . ":" . sprintf('%02d', $datedata['tm_sec']));
};

?>
