<?php

include_once("_nemo.list.cls.php");

class Clients extends NemoList
{
	private $ID = 0;

	public function __construct($DataKey)
	{
		$this->Filters[frSearch]->tag = "input";
	   	$this->Filters[frSearch]->html->value = "";
	   	$this->Filters[frSearch]->html->type = "text";
	   	$this->Filters[frSearch]->html->class = "controlText";

	   	parent::__construct($DataKey);
	}

	public function getList()
	{
		global $SystemSettings;

		$Where = "";
		if ($this->Filters[frSearch]->html->value != ""){
			$like = "LIKE(". $this->db->qs("%".$this->Filters[frSearch]->html->value."%") .")";
			$Where .= "AND (tblClient.ClientID $like
				OR tblClient.strClient $like
				OR tblClient.strShortCode $like
				OR tblClient.strContactPerson $like
				OR tblClient.strContactEmail $like
				OR tblClient.strTel $like)";
		}

		$this->ListSQL("
         SELECT ClientID, strClient AS Client, strShortCode AS 'Short Code', strContactPerson AS 'Contact Person', strContactEmail AS Email, strTel AS Tel, blnActive AS Active, strLastUser AS 'Last User', dtLastEdit AS 'Last Edit'
         FROM tblClient
         WHERE 1=1 $Where
         ORDER BY strClient ASC", 0, "client.php");

		return $this->renderTable("Client List");
	}


	public static function Save(&$ClientID)
	{
		global $SystemSettings;

		//print_rr($_POST);

		$cdb = new NemoDatabase("tblClient", $ClientID, null, 0);
	   	$cdb->SetValues($_POST);
	   	$cdb->Fields[strLastUser] = $_SESSION["USER"]->USERNAME;
	   	$rst = $cdb->Save();

		if($ClientID == 0) $ClientID = $cdb->ID[ClientID];

		if($rst->Error == 1)
		 return $rst->Message;
		else
		 return "Details Saved. ";

	}

	public static function Delete($chkSelect)
	{
		global $SystemSettings, $xdb;

		if(count($chkSelect) > 0){
			foreach($chkSelect as $key => $value){
				$xdb->doQuery("DELETE FROM tblClient WHERE ClientID = ". $xdb->qs($key));
			}
			return "Records Deleted. ";
		}

	}
}

?>