<?php
class mainClass {
	
	private $dbHost;
	private $dbUser;
	private $dbPass;
	private $dbName;
	private $templates;
	
	function mainClass() {
		
		$this->dbHost = "localhost";
		/*$this->dbUser = "musewmr2_sap123";
		$this->dbPass = "sg3524!@#";
		$this->dbName = "musewmr2_certification";*/
		$this->dbUser = "wwwsapce_sap123";
		$this->dbPass = "sg3524!@#";
		$this->dbName = "wwwsapce_certification";
		
	}
	
	/*===========================================================*/
	// Database Connection Functions
	/*===========================================================*/
	function mysqlConnect($db="") {
		@mysql_connect($this->dbHost, $this->dbUser, $this->dbPass) or $this->returnError("Unable to connect to SQL server");
		@mysql_select_db(!$db ? $this->dbName : $db);
	}
	
	function mysqlDisconnect() {
		@mysql_close();
	}
	
	function mysqlQuery($query) {
		$result = mysql_query($query) or $this->returnError(mysql_error());
		return $result;
	}
	
	function mysqlArray($query) {
		$result = mysql_fetch_array($this->mysqlQuery($query));
		return $result;
	}
	
	function mysqlAssoc($query) {
		$result = mysql_fetch_assoc($this->mysqlQuery($query));
		return $result;
	}
	
	function mysqlRow($query) {
		$result = mysql_fetch_row($this->mysqlQuery($query));
		return $result;
	}
	
	function mysqlNum($query) {
		$result = mysql_num_rows($this->mysqlQuery($query));
		return $result;
	}
	
	function formatSQLValue($value) {
		$value = (!get_magic_quotes_gpc()) ? addslashes($value) : $value;
		$value = trim($value);
		$value = ($value != "") ? "'" . $value . "'" : "NULL";
		
		return $value;
	}
	
	function mysqlFetchRow($query){
		$result = mysql_fetch_row($this->mysqlQuery($query));
		return $result;
	}
	
	/*===========================================================*/
	// Misc Functions
	/*===========================================================*/
	function trimArrayValues($array) {//use mysql_escape_string() instead
		if (is_array($array)) {
			foreach ($array as $key => $value) {
				if (is_array($value)) {  // do not trim if $value is an array
					$data[$key] = $value;
				} else {
					$data[$key] = trim($value);
				}
			}
		}

		return $data;
	}
	
	function jump($url) {
		$url = (!$url) ? "/" : $url;

		// this is a netscape refresh BUG
		if ($this->isMicrosoftBrowser()) {
			header("Location: $url");
		} else {
			echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=$url\">\n";
		}

		exit;
	}
	
	function isMicrosoftBrowser() {
		global $HTTP_USER_AGENT;
		
		if (strstr(strtolower($HTTP_USER_AGENT), "msie")) {
			return true;
		} else {
			return false;
		}
	}
	
	function returnError($msg) {
		echo $msg;
		exit;
	}
	
	
}
?>