
	<?php
	/*
	* =======================================================================
	* CLASSNAME:        mailusers_model
	* DATE CREATED:  	13-03-2014
	* FOR TABLE:  		mailusers
	* PRODUCED BY:		HEZECOM UltimateSpeed PHP CODE GENERATOR
	* AUTHOR:			Hezecom (http://hezecom.com) info@hezecom.net
	* =======================================================================
	*/
	if(!defined('VALID_DIR')) die('You are not allowed to execute this file directly');
	
	include_once(APP_FOLDER.'/models/classes/class_mailusers.php');
	
	class mailusers_model{
	
	// SELECT ALL
	public function SelectAll($limit=null)
	{
	$dbc = new dboptions();
	if($limit){
	$startpg = pageparam($limit);
	$record = $dbc->rawSelect ("SELECT * FROM mailusers LIMIT {$startpg} , {$limit}");
	}else{
	$record = $dbc->rawSelect ("SELECT * FROM mailusers");	
	}
	return $record->fetchAll(PDO::FETCH_OBJ);
	}
	
	//Select Count for Pagination
	public function CountRow()
	{
	$dbc = new dboptions();
	return $dbc->SelectCount('SELECT COUNT(*) as num FROM mailusers');
	}
	
	// SELECT ONE
	public function SelectOne($id)
	{
	$db=DB::getInstance();
    $sql = "SELECT * FROM mailusers WHERE uid=:id";
	$stmt=$db->prepare($sql);
	$stmt->bindParam(':id',$id, PDO::PARAM_INT);
	$stmt->execute();
	return $stmt->fetch(PDO::FETCH_OBJ);
	}
	
	// TRUNCATE TABLE
	public function TruncateTable($redirect_to)
	{
	$db=DB::getInstance();
   	$sql=$db->prepare("TRUNCATE mailusers");
	$sql->execute();
	send_to($redirect_to);
	}
	
	// DELETE
	public function Delete($id,$redirect_to)
	{
	$dbc = new dboptions();
	$dbc->dbDelete('mailusers', 'uid',$id);
	send_to($redirect_to);
	}
	
	// INSERT
	public function Insert($cfname,$clname,$cusername,$cpassword,$cbirthday,$cgender,$cphone,$cemail,$clocation,$rdate)
	{
	$dbc=new dboptions();

	$newupload = new UploadControl;
	$uploadname=$newupload->ImageUplaodResize('user_image',THUMB_IMAGE_WIDTH,BIG_IMAGE_WIDTH,UPLOAD_PATH,THUMB_PATH,90);
	if($uploadname==''){
	$values = array(array( 'cfname'=>$cfname,'clname'=>$clname,'cusername'=>$cusername,'cpassword'=>$cpassword,'cbirthday'=>$cbirthday,'cgender'=>$cgender,'cphone'=>$cphone,'cemail'=>$cemail,'clocation'=>$clocation,'rdate'=>$rdate,'user_status'=>1 ));
	}else{
	
	$values = array(array( 'user_image'=>$uploadname,'cfname'=>$cfname,'clname'=>$clname,'cusername'=>$cusername,'cpassword'=>$cpassword,'cbirthday'=>$cbirthday,'cgender'=>$cgender,'cphone'=>$cphone,'cemail'=>$cemail,'clocation'=>$clocation,'rdate'=>$rdate,'user_status'=>1 ));
	}
	
	$dbc->dbInsert('mailusers', $values);
	}
	
	// UPDATE
	public function Update($u_image,$cfname,$clname,$cbirthday,$cgender,$cphone,$cemail,$clocation,$id)
	{
	$db=DB::getInstance();
	$newupload = new UploadControl;
	$uploadname=$newupload->ImageUplaodResize('user_image',THUMB_IMAGE_WIDTH,BIG_IMAGE_WIDTH,UPLOAD_PATH,THUMB_PATH,90);
	if($uploadname==''){
	$sql = " UPDATE mailusers SET  cfname =:cfname,clname =:clname,cbirthday =:cbirthday,cgender =:cgender,cphone =:cphone,cemail =:cemail,clocation =:clocation WHERE uid = :id ";
	$data = array(':cfname'=>$cfname,':clname'=>$clname,':cbirthday'=>$cbirthday,':cgender'=>$cgender,':cphone'=>$cphone,':cemail'=>$cemail,':clocation'=>$clocation,':id'=>$id);
	}else{
	if($u_image!='') if(file_exists(UPLOAD_PATH.$u_image))unlink(UPLOAD_PATH.$u_image); unlink(THUMB_PATH.$u_image);
	$sql = " UPDATE mailusers SET  user_image=:user_image,cfname =:cfname,clname =:clname,cbirthday =:cbirthday,cgender =:cgender,cphone =:cphone,cemail =:cemail,clocation =:clocation  WHERE uid = :id ";
	$data = array(':user_image'=>$uploadname,':cfname'=>$cfname,':clname'=>$clname,':cbirthday'=>$cbirthday,':cgender'=>$cgender,':cphone'=>$cphone,':cemail'=>$cemail,':clocation'=>$clocation, ':id'=>$id);
	}
	$stmt=$db->prepare($sql);
	$stmt->execute($data);
	
	}
	
	
	} // end class
	
	?>
	
	