<?
include_once('baseModel.php');

class subconModel extends baseModel {


	/* QUERYING FUNCTIONS */


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

	function getlist_subcons($subconname="", $sortby="subconname", $sortdir="ASC") {

		$listdata=array();

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


	/* ********************************************************************************
	Select a particular subcon
	******************************************************************************** */

	function getdata_subcon($subconpkey){

		$data=array();

		$sql="Select SS.* from settings_subcontractors SS where SS.subconmasterpkey='".$subconpkey."'";
		$data=$this->getextendedrow($sql);
		return $data;
	}


	/* FUNCTIONS TO INSERT RECORDS */


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

	function insertdata_subcon($p_subconmasterpkey, $p_subconname, $p_subconpic, $p_subconpicdesignation, $p_subconpicphone, $p_subconpicext, $p_subconpicmobile, $p_subconaddress, $p_subconphone1, $p_subconphone2, $p_subconfax) {

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

		// update data..
		$sa = $this->add_data("Subcon [Add]", "settings_subcontractors", "subconmasterpkey, subconname, subconpic, subconpicdesignation, subconpicphone, subconpicext, subconpicmobile, subconaddress, subconphone1, subconphone2, subconfax",
			"'".$new_subconmasterpkey."','".$p_subconname."','".$p_subconpic.
			"','".$p_subconpicdesignation."','".$p_subconpicphone.
			"','".$p_subconpicext."','".$p_subconpicmobile.
			"','".$p_subconaddress."','".$p_subconphone1.
			"','".$p_subconphone2."','".$p_subconfax."'");

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


	/* FUNCTIONS TO UPDATE RECORDS */


	/* ********************************************************************************
	Update/Override a subcon
	> 
	******************************************************************************** */

	function updatedata_subcon($p_subconmasterpkey, $p_subconname, $p_subconpic, $p_subconpicdesignation,  $p_subconpicphone, $p_subconpicext, $p_subconpicmobile, $p_subconaddress, $p_subconphone1, $p_subconphone2, $p_subconfax) {

		// convert params..

		// update data..
		$sa = $this->update_data("Subcon [Edit]", "settings_subcontractors", "subconname = '".$p_subconname.
			"', subconpic = '".$p_subconpic.
			"', subconpicdesignation = '".$p_subconpicdesignation.
			"', subconpicphone = '".$p_subconpicphone.
			"', subconpicext = '".$p_subconpicext.
			"', subconpicmobile = '".$p_subconpicmobile.
			"', subconaddress = '".$p_subconaddress.
			"', subconphone1 = '".$p_subconphone1.
			"', subconphone2 = '".$p_subconphone2.
			"', subconfax = '".$p_subconfax."'",
			"where subconmasterpkey = '".$p_subconmasterpkey."'");

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


	/* FUNCTIONS TO DELETE RECORDS */


	/* ********************************************************************************
	Delete an existing subcon
	******************************************************************************** */

	function deletedata_subcon($p_subconmasterpkey) {

		// delete subject..
		$sa = $this->delete_data("Subcon [Delete]", "settings_subcontractors", "where subconmasterpkey = '".$p_subconmasterpkey."'");

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

}
?>