<?php
error_reporting(0);
session_start();
/*
	.:: AUTHOR: 	JEREMY STANSFIELD
	.:: DATE:			APRIL 1, 2003
	.:: ORIGINAL PURPOSE:
				The original purpose of these two classes was to allow for a standard record set object.
				A database access class was used so that if the database was changed from mysql to a 
				different type all that would be need was a new data access class written.  The code below
				has strayed from this a little.......
	.:: THE POLARIS GROUP WEB SERVICES INC ::.		
*/
// defined globals

define("MYSQL_DB","337978_nandjyachts");								// mysql database you want to use
define("MYSQL_SERVER","mysql4-6.wc1:3306");		// mysql server
define("MYSQL_USER","337978_admin");							// mysql username
define("MYSQL_PASS","AbcD321");							// mysql password


//define("MYSQL_DB","db");								// mysql database you want to use
//define("MYSQL_SERVER","localhost:3306");		// mysql server
//define("MYSQL_USER","root");							// mysql username
//define("MYSQL_PASS","sajid");							// mysql password
define("DEBUG_ENABLED",1);						// show errors? 1=Yes, 0=No
// this function will return a record set object from a sql text

function left($str, $length) 
{
return substr($str, 0, $length);
}


function striReplace($string,$find,$new)
	{
        /*$r  = $string;
		echo strpos($r,$find); 
		if (strpos($r,$find)>=0)
		{
		$r=str_replace($r,$new,$find);
		}
		return $r;
		*/
		
		if ($string==$find)
		{
			return "-";
		}
		else
		{
			return $string;
		}
		
    }

function redirect($url){
			echo("<script>");	
			echo("document.location='".$url."'");
			echo("</script>");	
			die();
		}
// object record_set RS( string $sql)
function RS($sql) {
  $rs = new record_set($sql);
  return $rs;
}





// preforms a query with out return any result objs.
// if an insert was used in the sql text, a insert id will
// be returned

// int Q( string $sql)
function Q($sql) {
  $rtrn = "";
  global $db;
  $db->query($sql);
  if (strstr(strtoupper(substr(trim($sql),0,7)),"INSERT")) {
    $rtrn = @mysql_insert_id();
  }
  return $rtrn;
}

function get_name($id)
{
  $rtrn = "";
  $rsObj1 = RS("select user_name from users where user_id=".$id."");
  if (!$rsObj1->eof)
  {
  $rtrn=$rsObj1->field['user_name'];
  }
  return $rtrn;
}

function get_email($id)
{
  $rtrn = "";
  $rsObj1 = RS("select user_email from users where user_id=".$id."");
  if (!$rsObj1->eof)
  {
  $rtrn=$rsObj1->field['user_email'];
  }
  return $rtrn;
}

///user_email
function get_curr($curr)
{
  $rtrn = "$";
  if ($curr=="USD")
  {
  $rtrn="$";
  }
  elseif($curr=="EUR")
  {
  $rtrn="&euro;";
  }
  elseif ($curr=="%")
  {
  $rtrn="%";
  }
  return $rtrn;
}




//allows to add to date using y,q,m,w,d,h,n or s as interval
function DateAdd($v,$d=null , $f="d/m/Y"){ 
  $d=($d?$d:date("Y-m-d")); 
  return date($f,strtotime($v." days",strtotime($d))); 
}



// record set class constructor
class record_set {
  var $name = "record_set";
  var $field = array();
  var $row_count = 0;
  var $link_id = 0;
  var $_pointer = 0;
  var $eof = true;
  var $bof = true;
  var $num_fields = 0;

  function record_set($sql_text) {
    global $db;
    $db->connect();
    $this->link_id = $db->query($sql_text);
    $this->_pointer = -1;
    $this->row_count = $db->num_rows($this->link_id);
    $this->move_next();
    $this->num_fields = $this->get_num_fields();
  }

  function move_next() {
    global $db;
    if($this->_pointer < $this->row_count) {
      $this->field = $db->fetch_array($this->link_id);
      $this->pointer_next();
    }
  }

  function pointer_next() {
    $this->_pointer++;
    if($this->_pointer == $this->row_count) $this->eof = true;
    else $this->eof = false;
    if($this->_pointer == 0) $this->bof = true;
    else $this->bof = false;
  }

  function get_row_count() {
    return $this->row_count;
  }

  function get_field_type($x) {
    global $db;
    if($x >= 0 && $x < $this->num_fields) {
      return $db->field_type($this->link_id,$x);
    }
  }

  function get_field_name($x) {
    global $db;
    if($x >= 0 && $x < $this->num_fields) {
      return $db->field_name($this->link_id,$x);
    }
  }

  function move_first() {
    global $db;
    if(!$this->bof){
      $this->_pointer = 0;
      if($this->row_count > 0) {
        $this->eof = false;
      }
      $this->bof = true;
      if($db->seek_data($this->link_id,0)){
        $this->field = $db->fetch_array($this->link_id);
        return true;
      } else {
        return false;
      }
    } else { return true; }
  }

  function get_num_fields() {
    global $db;
    return $db->num_fields($this->link_id);
  }

  // unset the recordset
  function free() {
    global $db;
    $db->free_result($this->link_id);
  }
}

// mysql class constructor
class mysql_access {
  var $database = "";
  var $link_id  = 0;
  var $query_id = 0;
  var $record   = array();
  var $errdesc    = "";
  var $errno   = 0;
  var $show_error = DEBUG_ENABLED;
  var $server   = "";
  var $user     = "";
  var $password = "";
  var $appname  = "";
  var $connected = 0;

  function mysql_access($dbname,$dbserver,$dbuser,$dbpassword) {
    $this->database = $dbname;
    $this->server = $dbserver;
    $this->user = $dbuser;
    $this->password = $dbpassword;
  }

  function connect() {
    if($this->connected == 0) {
      $this->link_id = @mysql_connect($this->server,$this->user,$this->password);
      if (!$this->link_id) {
        $this->print_error("Link-ID == false, connect failed");
      } else {
        if ($this->database != "") {
          $this->select_db($this->database);
          $this->connected = 1;
        }
      }
    }
  }

  function geterrdesc() {
    $this->error=@mysql_error();
    return $this->error;
  }

  function geterrno() {
    $this->errno=@mysql_errno();
    return $this->errno;
  }

  function select_db($database="") {
    if ($database!="") {
      $this->database=$database;
    }
    if(!@mysql_select_db($this->database, $this->link_id)) {
      $this->print_error("cannot use database ".$this->database);
    }
  }

  function query($query_string) {
    $this->connect();
    $this->query_id = @mysql_query($query_string);
    if (!$this->query_id) {
      $this->print_error("Invalid SQL: ".$query_string);
    }
    return $this->query_id;
  }

  function seek_data($query_id,$row){
    return @mysql_data_seek($query_id,$row);
  }

  function fetch_array($query_id) {
    $record = @mysql_fetch_array($query_id);
    return $record;
  }

  function free_result($query_id) {
    return @mysql_free_result($this->query_id);
  }

  function num_rows($query_id) {
    return @mysql_num_rows($query_id);
  }

  function field_type($query_id,$x) {
    return @mysql_field_type($query_id,$x);
  }

  function field_name($query_id,$x) {
    return @mysql_field_name($query_id, $x);
  }

  function num_fields($query_id) {
    return @mysql_num_fields($query_id);
  }

  function insert_id() {
    return @mysql_insert_id($this->link_id);
  }

  function print_error($msg) {
    $this->errdesc = @mysql_error();
    $this->errno = @mysql_errno();
    $message ="Database error in $this->appname: $msg\n<br>";
    $message.="mysql error: $this->errdesc\n<br>";
    $message.="mysql error number: $this->errno\n<br>";
    $message.="Date: ".date("d.m.Y @ H:i")."\n<br>";
    $message.="Script: ".getenv("REQUEST_URI")."\n<br>";
    $message.="Referer: ".getenv("HTTP_REFERER")."\n<br><br>";
    if($this->show_error) echo "$message";
  }
}
?>