<?
include_once('baseModel.php');

class clientModel extends baseModel {


	/* QUERYING FUNCTIONS */


	/* ********************************************************************************
	Select list of clients (get from CMS!)
	******************************************************************************** */

	function getlist_clients($clientname="", $sortby="clientname", $sortdir="ASC") {

		$listdata=array();

		$sql="Select SC.* from settings_clients SC where SC.clientname like '%".$clientname."%' order by SC.".$sortby." ".$sortdir;
		$listdata=$this->getextendedrows($sql);
		return $listdata;
	}


	/* ********************************************************************************
	Select a particular client
	******************************************************************************** */

	function getdata_client($clientpkey){

		$data=array();

		$sql="Select SC.* from settings_clients SC where SC.clientpkey='".$clientpkey."'";
		$data=$this->getextendedrow($sql);
		return $data;
	}


	/* FUNCTIONS TO INSERT RECORDS */


	/* ********************************************************************************
	Insert/Create a new client
	Duplicate issue?
	******************************************************************************** */

	function insertdata_client($p_clientpkey, $p_clientname, $p_clientpic, $p_clientpicdesignation, $p_clientaddress, $p_clientphone1, $p_clientphone2, $p_clientmobile1, $p_clientmobile2, $p_clientfax) {

		// convert params..
		$new_clientpkey=md5(microtime());

		// update data..
		$sa = $this->add_data("Client [Add]", "settings_clients", "clientpkey, clientname, clientpic, clientpicdesignation, clientaddress, clientphone1, clientphone2, clientmobile1, clientmobile2, clientfax",
			"'".$new_clientpkey."','".$p_clientname."','".$p_clientpic.
			"','".$p_clientpicdesignation."','".$p_clientaddress."','".$p_clientphone1.
			"','".$p_clientphone2."','".$p_clientmobile1."','".$p_clientmobile2.
			"','".$p_clientfax."'");

		// return result..
		if ($sa==1) {
			//$m=msg_n_goto("index.php?module=settings&task=clients","Client Added Successfully!");
			//echo $m;
			return $new_clientpkey;
		} else {
			//$e=error_n_goto(-1,"Error: Unable to Add Client!");
			//echo $e;
			return false;
		}
	}


	/* FUNCTIONS TO UPDATE RECORDS */


	/* ********************************************************************************
	Update/Override an client
	> 
	******************************************************************************** */

	function updatedata_client($p_clientpkey, $p_clientname, $p_clientpic, $p_clientpicdesignation, $p_clientaddress, $p_clientphone1, $p_clientphone2, $p_clientmobile1, $p_clientmobile2, $p_clientfax) {

		// convert params..

		// update data..
		$sa = $this->update_data("Client [Edit]", "settings_clients", "clientname = '".$p_clientname.
			"', clientpic = '".$p_clientpic.
			"', clientpicdesignation = '".$p_clientpicdesignation.
			"', clientaddress = '".$p_clientaddress.
			"', clientphone1 = '".$p_clientphone1.
			"', clientphone2 = '".$p_clientphone2.
			"', clientmobile1 = '".$p_clientmobile1.
			"', clientmobile2 = '".$p_clientmobile2.
			"', clientfax = '".$p_clientfax."'",
			"where clientpkey = '".$p_clientpkey."'");

		// return result..
		if ($sa==1) {
			//$m=msg_n_goto("index.php?module=settings&task=clients","Client Updated Successfully!");
			//echo $m;
			return $p_clientpkey;
		} else {
			//$e=error_n_goto(-1,"Error: Unable to Update Client!");
			//echo $e;
			return false;
		}
	}


	/* FUNCTIONS TO DELETE RECORDS */


	/* ********************************************************************************
	Delete an existing client
	******************************************************************************** */

	function deletedata_client($p_clientpkey) {

		// delete subject..
		$sa = $this->delete_data("Client [Delete]", "settings_clients", "where clientpkey = '".$p_clientpkey."'");

		// return result..
		if ($sa==1) {
			return $p_clientpkey;
		} else {
			return false;
		}
	}

}
?>