<?php

require_once('MDB2.php');
require_once('DB/Table.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/script/DbTables/Error404.table.php');

class Error404Mod{
	var $ArrMsSp = '';
	var $VarSmarty = '';
	var $VarTableError404 = '';
	
	function Error404Mod($ArrMsSp, $VarSmarty){
		$this->ArrMsSp = $ArrMsSp;
		$this->VarSmarty = $VarSmarty;
		$this->VarTableError404 = $this->ArrMsSp->Sp_DbConf['cu_register_cert']['DbPref'] .'_error404';
		return true;
	}
	
	function GetFromDb($VarSql = 'GetAll', $VarWhere = '', $VarOrder = '', $UserId = ''){
 		$db =& MDB2::connect($this->ArrMsSp->Sp_DbConf['cu_register_cert']['DbDsn']);
		if (PEAR::isError($db)) {
			die($db->getMessage());
		}
    SiteLibs::DbSetCharset($db);
		$ObjTable =& new Error404Table($db, '', false);
		if ($ObjTable->error) {
			die($ObjTable->error);
		}
		$ObjTable->fetchmode = MDB2_FETCHMODE_ASSOC;
		$ObjTable->sql = array(
      'GetAll'	=> array(
      	'get'	=> 'all',
      	'select'	=> 't1.error404_id, t1.error404_page, t1.error404_date',
      	'from' => $this->VarTableError404 .' AS t1'
      ),
      'GetById'	=> array(
      	'get'	=> 'row',
      	'select'	=> 't1.error404_id, t1.error404_page, t1.error404_date',
      	'from' => $this->VarTableError404 .' AS t1'
      )
  	);
  	$VarReturn = $ObjTable->select($VarSql, $VarWhere, $VarOrder);
		if (PEAR::isError($VarReturn)) {
			die($VarReturn->getMessage());
		}
		$db->disconnect();
  	return $VarReturn;
	}
	
	function add($VarPage = ''){
    if('' != $VarPage){
      $db =& MDB2::connect($this->ArrMsSp->Sp_DbConf['cu_register_cert']['DbDsn']);
      if (PEAR::isError($db)) {
        die($db->getMessage());
      }
      SiteLibs::DbSetCharset($db);
      $ObjTable =& new Error404Table($db, $this->VarTableError404, false);
      if ($ObjTable->error) {
        die($ObjTable->error);
      }
      $VarNextId = $ObjTable->nextID();
      $cols_vals['error404_id'] = $VarNextId;
      $cols_vals['error404_page'] = $VarPage;
      $cols_vals['error404_date'] = date("Y.m.d G:i:s");

      $result = $ObjTable->insert($cols_vals);
      if (PEAR::isError($result)) {
        die($result->getMessage());
      }
      $db->disconnect();
    }
	}
	
}
?>