<?php
class extra{
	function contact($array){
		$mob="/^[789][0-9]{9}$/";
		$pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; 
		global $db;global $LinksDetails;$data=array();
		if(isset($array["name"]) && $array["name"]==""){
			$data["msg"]="Your name cannot blank";
			$data["status"]="error";
		}elseif(isset($array["email"]) && $array["email"]==""){
			$data["msg"]="Your email cannot blank";
			$data["status"]="error";
		}elseif(isset($array["phone"]) && $array["phone"]==""){
			$data["msg"]="Your phone no cannot blank";
			$data["status"]="error";
		}elseif (!preg_match_all($mob, $array["phone"])){	
			$data["msg"]="Mobile Number should be start with 7,8,9 and of 10 digit";
			$data["status"]="error";

		}elseif (!preg_match_all($pattern, $array["email"])){
			$data["msg"]="Please Enter Valid Email ID";
			$data["status"]="error";
		}
		elseif(isset($array["comments"]) && $array["comments"]==""){
			$data["msg"]="Please Leave your comment";
			$data["status"]="error";
		}else{
			$insAry=array(  "name"=>$array["name"],
							"email"=>$array["email"],
							"mobile"=>$array["phone"],
							"status"=>1,
							"comments"=>$array["comments"]);
			$ins=$db->insertAry(CONTACT,$insAry);
			$body="
					Dear Admin<br />
					<br />
					New User want to contact to you on your site.<br />
					<br />
					User details  are:<br />
					<br />
					Name : ".$array["name"]."<br />
					Email : ".$array["email"]."<br />
					phone : ".$array["phone"]."<br />
					Contact : ".$array["contact"]."<br />
					<br />
					<br />
					";
			mymail($LinksDetails["mail_sender_email"],$LinksDetails["contact_email"]," Notice ! New User want to contact to you on your site ".$LinksDetails["site_name"],$body,"CONTACT");
			$body="
					Dear ".$array["name"]."<br />
					<br />
					Thank you for contacting us.<br />
					<br />
					Your request has been successfully posted on our site ".$LinksDetails["site_name"]." We will get back you soon...
					<br />
					<br />
					";
			mymail($LinksDetails["mail_sender_email"],$array["email"]," Thank you for contacting us",$body,"CONTACT");
			notification("New contact on indiaGTS","dashboard",0);
			//return $data['error']=$db->getErMsg();
			$data["msg"]="Your request has been successfully posted on our site We will get back you soon...";
			//$data['msg']=$db->getErMsg();
			$data["status"]="ok";
		}
		return $data;
	}
	function query($array){
		global $db;global $LinksDetails;$data=array();
		$date=date("Y-m-d | h:i:sa");
		if(isset($array["name"]) && $array["name"]==""){
			$data["msg"]="Your name cannot blank";
			$data["status"]="error";
		}elseif(isset($array["email"]) && $array["email"]==""){
			$data["msg"]="Your email cannot blank";
			$data["status"]="error";
		}elseif(isset($array["phone"]) && $array["phone"]==""){
			$data["msg"]="Your phone no cannot blank";
			$data["status"]="error";
		}elseif(isset($array["comments"]) && $array["comments"]==""){
			$data["msg"]="Please Leave your comment";
			$data["status"]="error";
		}else{
			$insAry=array(  
							"address"=>$array["address"],
							"class"=>$array["classname"],
							"subject"=>$array["subject"],
							
							"name"=>$array["name"],
							"email"=>$array["email"],
							"contact"=>$array["phone"],
							"status"=>1,
							"date"=>$date,
							"message"=>$array["comments"]);
			$ins=$db->insertAry(QUERY,$insAry);
			$body="
					Dear Admin<br />
					<br />
					New query in your site.<br />
					<br />
					User details  are:<br />
					<br />
					Name : ".$array["name"]."<br />
					Email : ".$array["email"]."<br />
					phone : ".$array["phone"]."<br />
					Contact : ".$array["contact"]."<br />
					<br />
					<br />
					";
			mymail($LinksDetails["mail_sender_email"],$LinksDetails["contact_email"]," Notice ! New query in your site ".$LinksDetails["site_name"],$body,"CONTACT");
			notification("New query on indiaGTS","query",0);
			$data["msg"]="Your request has been successfully posted on our site We will get back you soon...";
			$data["status"]="ok";
		}
		return $data;
	}
	function complain($array){
		global $db;global $LinksDetails;$data=array();
		$date=date("Y-m-d | h:i:sa");

		if(isset($array["complain"]) && $array["complain"]==""){
			$data["msg"]="Your complain cannot blank";
			$data["status"]="error";
		}elseif(isset($array["topic"]) && $array["topic"]==""){
			$data["msg"]="Topic cannot blank";
			$data["status"]="error";
		}else{
			$insAry=array(  "student_id"=>$_SESSION['user']['uid'],
							"topic"=>$array["topic"],
							"detail"=>$array["complain"],
							"status"=>1,
							"udate"=>$date);
			$ins=$db->insertAry(COMPLAIN,$insAry);
			$uname=$db->getVal("select student_name from ".STUDENT." where id=".$_SESSION['user']['uid']);
			//$user=$db->userdetail($_SESSION['user']['uid'],student_name);
			notification("You Have New Complaint From $uname","complain",0);
			$data['msg']="Complain sent succesfully";
			$data['status']="ok";
			
		}
		return $data;
	}
	function cname($array){
		global $db;global $LinksDetails;$data=array();
		
		echo "==>error";print_r($array);exit;
		}
	function quote($array){
		global $db;global $LinksDetails;$data=array();
		if(isset($array["name"]) && $array["name"]==""){
			$data["msg"]="Your name cannot blank";
			$data["status"]="error";
		}elseif(isset($array["email"]) && $array["email"]==""){
			$data["msg"]="Your email cannot blank";
			$data["status"]="error";
		}elseif(isset($array["budget"]) && $array["budget"]==""){
			$data["msg"]="Your budget cannot blank";
			$data["status"]="error";
		}else{
			$insAry=array(  "name"=>$array["name"],
							"email"=>$array["email"],
							"mobile"=>$array["phone"],
							"detail"=>$array["detail"],
							"status"=>1,
							
							
							);
			if($array["budget"]==1){
								$insAry['budget']=$array["custom"];
								}else{
									$insAry['budget']=$array["budget"];
									}
			$ins=$db->insertAry(QUOTE,$insAry);
			$body="
					Dear Admin<br />
					<br />
					New User want to contact to you on your site.<br />
					<br />
					User details  are:<br />
					<br />
					Name : ".$array["name"]."<br />
					Email : ".$array["email"]."<br />
					phone : ".$array["phone"]."<br />
					Detail : ".$array["detail"]."<br />
					<br />
					<br />
					";
			mymail($LinksDetails["mail_sender_email"],$LinksDetails["contact_email"]," Notice ! New User want to contact to you on your site ".$LinksDetails["site_name"],$body,"CONTACT");
			$body="
					Dear ".$array["name"]."<br />
					<br />
					Thank you for quote us.<br />
					<br />
					Your quote has been successfully posted on our site ".$LinksDetails["site_name"]." We will get back you soon...
					<br />
					<br />
					";
			mymail($LinksDetails["mail_sender_email"],$array["email"]," Thank you for quote us",$body,"CONTACT");
			notification("New User want to contact to you.","contact",$ins);
			$data["msg"]="Your request has been successfully posted on our site We will get back you soon...";
			$data["status"]="ok";
		}
		return $data;
	}
	function career($array){
		global $db;global $LinksDetails;$data=array();
		if(isset($array["name"]) && $array["name"]==""){
			$data["msg"]="Your name cannot blank";
			$data["status"]="error";
		}elseif(isset($array["email"]) && $array["email"]==""){
			$data["msg"]="Your email cannot blank";
			$data["status"]="error";
		}elseif(isset($array["phone"]) && $array["phone"]==""){
			$data["msg"]="Your phone no cannot blank";
			$data["status"]="error";
		}else{
			$insAry=array(  "name"=>$array["name"],
							"email"=>$array["email"],
							"mobile"=>$array["phone"],
							"connect"=>$array["connect"],
							"cv"=>$array["file"]);
			$ins=$db->insertAry(CAREER,$insAry);
			if($ins!=""){
				$body="
					Dear Admin<br />
					<br />
					New User Send our CV to you on your site.<br />
					<br />
					User details  are:<br />
					<br />
					Name : ".$array["name"]."<br />
					Email : ".$array["email"]."<br />
					phone : ".$array["phone"]."<br />
					Contact : ".$array["contact"]."<br />
					CV	:	<a href='".URL_ROOT."uploads/cv/".$array["file"]."'>Download CV</a>	
					<br />
					<br />
					";
				mymail($LinksDetails["mail_sender_email"],$LinksDetails["contact_email"]," Notice ! New User Send our CV to  you on your site ".$LinksDetails["site_name"],$body,"CAREER");
				$body="
					Dear ".$array["name"]."<br />
					<br />
					Thank you for contacting us.<br />
					<br />
					Your CV has been successfully posted on our site ".$LinksDetails["site_name"]." We will get back you soon...
					<br />
					<br />
					";
				/*sms($array["phone"],"Dear ".$array["name"].", Thank you for contacting us, Your CV has been successfully posted on our site");
				sms($LinksDetails["contact_no"],"Dear ".$LinksDetails["admin_fname"].", New User(".$array["name"].") Send our CV to you on your site from career section");*/
		
				mymail($LinksDetails["mail_sender_email"],$array["email"]," Thank you for contacting us",$body,"CAREER");
				notification("New User send our CV  to you.","career",$ins);
				$data["msg"]="Your CV has been successfully posted We will get back you soon...";
				$data["status"]="ok";
			}else{
				$data["msg"]=$db->getErMsg();;
				$data["status"]="error";
			}
		}
		return $data;
	}
	function login($array){
		
		global $db, $LinksDetails;
		if($array['rolid']=="student")
		{ 
			$data=array();
			//$ua=getBrowser();
			//$yourbrowser= $ua['name'] . " " . $ua['version'] ;
			if(isset($array["username"]) && $array["username"]==""){
				 $data["msg"]="Your username cannot blank";
				$data["status"]="error";
			}elseif(isset($array["pwd"]) && $array["pwd"]==""){
				$data["msg"]="Your password cannot blank";
				$data["status"]="error";
			}else{
				$ids = $db->getRow("select * from  student where ( admissionno='".POST($array["username"])."' ) and password='".POST($array["pws"])."' and status=1 ");
	//$ids['error']=$db->getErMsg();return $ids ;
		
				if( count($ids)>0 )
				{
					$data=$ids;
					$_SESSION["user"]["uid"]=$ids['idno'];
					$_SESSION["user"]["school_id"]=$ids["school_id"];
					$_SESSION["user"]["session"]=$ids["session"];
					$_SESSION["admin"]["school_id"]=$ids["school_id"];
					$_SESSION["admin"]["session"]=$ids["session"];
					$_SESSION["latestlogin"]=true;
					$_SESSION["user"]["name"]=$ids['name'];
					$historyData=array('login_ip'=>$_SERVER['REMOTE_ADDR'],
										  'login_browser' =>$yourbrowser,
										  'userid' =>$_SESSION["user"]["uid"],
										  'uname' => $student["student_name"],
										  'email' =>$student["email"],
										  'status' =>1
						);
//	$db->insertAry(LOGIN_HISTORY,$historyData);
					//echo "error==>";echo"<pre>".$db->getlastQuery();
					
					$url=URL_ROOT."dashboard.php";
					if(trim($array["redirect"])!="")$url=base64_decode(base64_decode($array["redirect"]));
					$data=array("status"=>"success","msg"=>"login succesfully","url"=>$url);
				
				}
				else{
					$data["status"]="error";
					$data["msg"]="password incorrect";
				}
			}
		}
		else 
		{
			if(trim($array["username"])==""){
				echo "error==>Please enter admin name "; exit;
			}elseif($array["pws"]==""){
				echo "error==>Please enter admin password";  exit; 
			}elseif(POST(trim($array["username"]))==$LinksDetails["admin_uname"] && POST($array["pws"])==$LinksDetails["admin_pswd"])
			{
				$_SESSION["admin"]["uid"]=0;
				$_SESSION["admin"]["uname"]="Admin";
				$_SESSION["admin"]["adminroll"]=1;
				$data=array("status"=>"success","msg"=>"You are login successfully","url"=>PATH_ADMIN);
			}else{
				$ids = $db->getRow("select * from  ".SITE_USER." where (username ='".POST($array["username"])."' || email ='".POST($array["username"])."' ) and pass='".POST($array["pws"])."' and status=1");
				if(is_array($ids) && count($ids)>0)
				{
					$_SESSION["admin"]["uid"]=$ids['id'];
					$_SESSION["admin"]["uname"]=$array["username"];
					$_SESSION["admin"]["adminroll"]=$ids["role"];
					$historyData=array('f_ip'=>$_SERVER['REMOTE_ADDR'],
									  'f_browser' =>$yourbrowser,
									  'userid' =>$ids['id'],
									  'uname' => $_POST["uid"],
									  'email' =>$ids["email"]
					);
					$db->updateAry(SITE_USER,array("is_online"=>1)," where id='".$_SESSION["user"]["uid"]."'");
					$db->insertAry(LOGIN_HISTORY,$historyData);
					$data=array("status"=>"success","msg"=>"You are login successfully","url"=>PATH_ADMIN);
				}else{
					$data=array("status"=>"error","msg"=>"Invalid user id or password");
				}
			}
		}
		return $data;
	}
	function studentprofile($array,$img){
		global $db;
		global $LinksDetails;
		$data=array();
		if(isset($array["student_name"]) && $array["student_name"]==""){
			$data["msg"]="Your name cannot blank";
			$data["status"]="error";
		}elseif(isset($array["email"]) && $array["email"]==""){
			$data["msg"]="Your email cannot blank";
			$data["status"]="error";
		}else{
			$aryData=array(  "student_name"=>$array["student_name"],
							"email"=>$array["email"],
							"mobile"=>$array["mobile"],
							"dob"=>$array["dob"],
								
							"gender"=>$array["gender"]);
							
	                if($img!="")
			{	
			 $aryData["avatar"]=$img;
			}	

			$flgUp=$db->updateAry(STUDENT,$aryData,"where id='".$_SESSION['user']['uid']."'");
			
			//echo
			exit;
			if(!is_null($flgUp))
			{	
				$data['msg']='Saved Successfully';
				//unset($_SESSION['form']);
				$data['status']='ok';
				//echo "success==>msg==>Record save successfully";
			}
			else
			{
				echo "error==>".$db->getErMsg().$db->getLastQuery();
			}
		}
		return $data;
	}
	function changepassword($array){
		global $db; global $LinksDetails;
		$data=array();
		$password=$db->getVal("select password from  ".STUDENT." where id='".$_SESSION['user']['uid']."'");
		if(isset($array["opwd"]) && $array["opwd"]!=""){
			
			if($array["opwd"] == $password){
			
			
				if(isset($array["npwd"]) && $array["npwd"]!=""){
			
					if(isset($array["cpwd"]) && $array["cpwd"]!=""){
				
						if($array["npwd"]==$array["cpwd"]){
			$aryData=array("password"=>$array["cpwd"]);
							
			$flgUp=$db->updateAry(STUDENT,$aryData,"where id='".$_SESSION['user']['uid']."'");
				if(!is_null($flgUp))
				{	
					$_SESSION['msg']='Saved Successfully';
					unset($_SESSION['form']);
					$data["status"]="ok";
					$data["msg"]="record update successfully";
				}
				else
				{
					$data["status"]="error";
					$data["msg"]=$db->getErMsg().$db->getLastQuery();
				}
				
				
				
			}
							else{
							$data["status"]="error";
							$data["msg"]="conform Password and new password are different";
						}
					}
			
			
			else{
			$data["status"]="error";
			$data["msg"]="conform Password cannot blank";
		}
			}
				else{
			$data["status"]="error";
			$data["msg"]="New Password cannot blank";
		}
			
			}
			
			else{
			$data["status"]="error";
			$data["msg"]="Current Password is incorrect";
		}
			
		}else{
			$data["status"]="error";
			$data["msg"]="Password cannot blank";
		}
				
			
		return $data;
	}
	function faq(){
		global $db;
		$faqArray=array();
		$rw=$db->getRows("select * from  ".FAQ_CATEGORY." where status=1");
		if(is_array($rw) && count($rw)>0)
		{
			$j=0;
			foreach($rw as $row)
			{ $j++;
				$faqArray["category"][$j]["id"]=$row["faq_category_id"];
				$faqArray["category"][$j]["name"]=$row["category_name"];
				$faq=$db->getRows("select * from ".FAQ." where faq_category_id='".$row['faq_category_id']."'");
				if(is_array($faq) && count($faq)>0)
				{	
					foreach($faq as $fq)
					{
						$faqArray["category"][$j]["faq"][]=$fq;
					}
				}
			}
		}
		return $faqArray;
	}
	function exportMe($filename,$table,$fieldArray="",$where=""){
		$csv_terminated = "\n";
		$csv_separator = ",";
		$csv_enclosed = '"';
		$csv_escaped = "\\";
		$filter="*";
		if(is_array($fieldArray) && count($fieldArray)>0){
			$filt=array();
			foreach($fieldArray as $key => $value){
				$filt[]=$key." as ".$value;
			}
			$filter=implode(",",$filt);
			//echo $filter;print_r($fieldArray);exit;
		}
		$sql_query = "select $filter from $table $where";
		//echo $sql_query;exit;
		// Gets the data from the database
		$result = mysql_query($sql_query)or die(mysql_error()."<br>Last Query : <strong>".$sql_query."</strong>");
		$fields_cnt = mysql_num_fields($result); 
		$schema_insert = '';
		for ($i = 0; $i < $fields_cnt; $i++)
		{
			$l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
				stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
			$schema_insert .= $l;
			$schema_insert .= $csv_separator;
		} // end for
	 
		$out = trim(substr($schema_insert, 0, -1));
		$out .= $csv_terminated;
	 
		// Format the data
		while ($row = mysql_fetch_array($result))
		{
			$schema_insert = '';
			for ($j = 0; $j < $fields_cnt; $j++)
			{
				if ($row[$j] == '0' || $row[$j] != '')
				{
	 
					if ($csv_enclosed == '')
					{
						$schema_insert .= $row[$j];
					} else
					{
						$schema_insert .= $csv_enclosed .
						str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
					}
				} else
				{
					$schema_insert .= '';
				}
	 
				if ($j < $fields_cnt - 1)
				{
					$schema_insert .= $csv_separator;
				}
			} // end for
	 
			$out .= $schema_insert;
			$out .= $csv_terminated;
		} // end while
		//header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		//header("Content-Length: " . strlen($out));
		// Output to browser with appropriate mime type, you choose ;)
		header('Content-type: application/csv');
		//header("Content-type: text/x-csv");
		//header("Content-type: text/csv");
		header("Content-Disposition: attachment; filename=$filename");
		echo $out;
		exit;
	}
	function forgot($email){
		global $db;
//		return $email;
		
		if(trim($email)==""){
			$status=array("status"=>"error","msg"=>"Please enter email");
		}elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
			$status=array("status"=>"error","msg"=>"Please enter valid email id eg. example@domainname.com");
		}else{
			$logdata=$db->getRow("select * from ".STUDENT." where email='".$email."'");
			if(is_array($logdata) && count($logdata)>0){
				$vCode=md5(microtime());
				$db->updateAry(STUDENT,array("vcode"=>$vCode),"where id=".$logdata["0"]);
				$body="Dear ".$logdata["username"]."<br />
				Sorry you have forgotten your password at Indiagts. <br />
				 Your Login Id is: ".$_POST["email"]."       <br />
				To Reset your password, please '<a href='".URL_ROOT."resetPassword.php?code=".$vCode."'>click here</a><br />
				<br />
				 If you are unable to click on the link above, please paste this link in your browser window: <br />
				<a href='".URL_ROOT."resetPassword.php?code=".$vCode."'>click Here</a> <br />
				";
				mymail($LinksDetails["mail_sender_email"],$email,"Notification ! Sorry ".$logdata["username"]." for  losing your password ",$body,"FORGOT");
				$status=array("status"=>"success","msg"=>"Reset Password link has been sent to your email id");		
			}else{
				$status=array("status"=>"error","msg"=>"Invalid email Please try again");
			}			
		}
		return $status;
	}
	function resetPassword($POST){
		global $db;
		
		//$status=array("status"=>"error","msg"=>"Your reset Password link has been expired");exit;
		if(!isset($POST["pass"]) || trim($POST["pass"])==""){
			$status=array("status"=>"error","msg"=>"Please Enter password");
		}elseif (!preg_match_all('$\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])(?=\S*[\W])\S*$', $POST["pass"])){
			$status=array("status"=>"error","msg"=>"Input Password must contain min 8 characters which contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character");
		}elseif(!isset($POST["cpass"]) || trim($POST["cpass"])==""){
			$status=array("status"=>"error","msg"=>"Please Enter Confirm password");
		}elseif($POST["cpass"]!=$POST["pass"]){
			$status=array("status"=>"error","msg"=>"Confirm password must equeal to New Password");
		}else{
			$id=$db->getRow("select id,student_name,email from ".STUDENT." where vcode='".$POST["code"]."'");
			//echo $db->getLastQuery();exit;
			if(is_array($id) && count($id)>0){
				$logdata=$db->updateAry(STUDENT,array("password"=>$POST["pass"],"vcode"=>""),"where id=".$id["id"]);
				$body="
					Dear ".$id["username"]."<br />
					<br />
					Are You Forgot password on favorchat.<br />
					<br />
					Your can Login to our site with  Login ID: <strong>".$id["email"]."</strong><br />
					<br />
					<br />
					<br />
					Your Password has been successfully reset<br />
					<br />
					<br />
					<br />
					";
					mymail($LinksDetails["mail_sender_email"],$id["email"],"Notification ! password  has been reset successfully on ".$LinksDetails["site_name"],$body,"REGISTRATION");
					$status=array("status"=>"success","msg"=>"Your Password has been successfully reset","url"=>URL_ROOT);
				
			}else{
				$status=array("status"=>"error","msg"=>"Your reset Password link has been expired");//.$db->getLastQuery();
			}
		}
		return $status;
	}

	
	function forgota($email)
	{if($array['rolid']=="student")
		{ 
		 
		global $db;
//		return $email;
		
		if(trim($email)==""){
			$status=array("status"=>"error","msg"=>"Please enter email");
		}elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
			$status=array("status"=>"error","msg"=>"Please enter valid email id eg. example@domainname.com");
		}else{
			$logdata=$db->getRow("select * from ".STUDENT." where email='".$email."'");
			if(is_array($logdata) && count($logdata)>0){
				$vCode=md5(microtime());
				$db->updateAry(STUDENT,array("vcode"=>$vCode),"where id=".$logdata["0"]);
				$body="Dear ".$logdata["username"]."<br />
				Sorry you have forgotten your password at Indiagts. <br />
				 Your Login Id is: ".$_POST["email"]."       <br />
				To Reset your password, please '<a href='".URL_ROOT."resetPassword.php?code=".$vCode."'>click here</a><br />
				<br />
				 If you are unable to click on the link above, please paste this link in your browser window: <br />
				<a href='".URL_ROOT."resetPassword.php?code=".$vCode."'>click Here</a> <br />
				";
				mymail($LinksDetails["mail_sender_email"],$email,"Notification ! Sorry ".$logdata["username"]." for  losing your password ",$body,"FORGOT");
				$status=array("status"=>"success","msg"=>"Reset Password link has been sent to your email id");		
			}else{
				$status=array("status"=>"error","msg"=>"Invalid email Please try again");
			}			
		}
		return $status;
	}
	else{ 
		 
		global $db;
//		return $email;
		
		if(trim($email)==""){
			$status=array("status"=>"error","msg"=>"Please enter email");
		}elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
			$status=array("status"=>"error","msg"=>"Please enter valid email id eg. example@domainname.com");
		}else{
			$logdata=$db->getRow("select * from ".SITE_USER." where email='".$email."'");
			if(is_array($logdata) && count($logdata)>0){
				$vCode=md5(microtime());
				$db->updateAry(SITE_USER,array("vcode"=>$vCode),"where id=".$logdata["0"]);
				$body="Dear ".$logdata["username"]."<br />
				Sorry you have forgotten your password at Indiagts. <br />
				 Your Login Id is: ".$_POST["email"]."       <br />
				To Reset your password, please '<a href='".URL_ROOT."resetPassword.php?code=".$vCode."'>click here</a><br />
				<br />
				 If you are unable to click on the link above, please paste this link in your browser window: <br />
				<a href='".URL_ROOT."resetPassword.php?code=".$vCode."'>click Here</a> <br />
				";
				mymail($LinksDetails["mail_sender_email"],$email,"Notification ! Sorry ".$logdata["username"]." for  losing your password ",$body,"FORGOT");
				$status=array("status"=>"success","msg"=>"Reset Password link has been sent to your email id");		
			}else{
				$status=array("status"=>"error","msg"=>"Invalid email Please try again");
			}			
		}
		return $status;
	}
	}
	
	function resetPassworda($POST){
		global $db;
		{if($array['rolid']=="student"){
		//$status=array("status"=>"error","msg"=>"Your reset Password link has been expired");exit;
		if(!isset($POST["pass"]) || trim($POST["pass"])==""){
			$status=array("status"=>"error","msg"=>"Please Enter password");
		}elseif (!preg_match_all('$\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])(?=\S*[\W])\S*$', $POST["pass"])){
			$status=array("status"=>"error","msg"=>"Input Password must contain min 8 characters which contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character");
		}elseif(!isset($POST["cpass"]) || trim($POST["cpass"])==""){
			$status=array("status"=>"error","msg"=>"Please Enter Confirm password");
		}elseif($POST["cpass"]!=$POST["pass"]){
			$status=array("status"=>"error","msg"=>"Confirm password must equeal to New Password");
		}else{
			$id=$db->getRow("select id,student_name,email from ".STUDENT." where vcode='".$POST["code"]."'");
			//echo $db->getLastQuery();exit;
			if(is_array($id) && count($id)>0){
				$logdata=$db->updateAry(STUDENT,array("password"=>$POST["pass"],"vcode"=>""),"where id=".$id["id"]);
				$body="
					Dear ".$id["username"]."<br />
					<br />
					Are You Forgot password on favorchat.<br />
					<br />
					Your can Login to our site with  Login ID: <strong>".$id["email"]."</strong><br />
					<br />
					<br />
					<br />
					Your Password has been successfully reset<br />
					<br />
					<br />
					<br />
					";
					mymail($LinksDetails["mail_sender_email"],$id["email"],"Notification ! password  has been reset successfully on ".$LinksDetails["site_name"],$body,"REGISTRATION");
					$status=array("status"=>"success","msg"=>"Your Password has been successfully reset","url"=>URL_ROOT);
				
			}else{
				$status=array("status"=>"error","msg"=>"Your reset Password link has been expired");//.$db->getLastQuery();
			}
		}
		return $status;
	}
	else
	{
		
		
		if(!isset($POST["pass"]) || trim($POST["pass"])==""){
			$status=array("status"=>"error","msg"=>"Please Enter password");
		}elseif (!preg_match_all('$\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])(?=\S*[\W])\S*$', $POST["pass"])){
			$status=array("status"=>"error","msg"=>"Input Password must contain min 8 characters which contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character");
		}elseif(!isset($POST["cpass"]) || trim($POST["cpass"])==""){
			$status=array("status"=>"error","msg"=>"Please Enter Confirm password");
		}elseif($POST["cpass"]!=$POST["pass"]){
			$status=array("status"=>"error","msg"=>"Confirm password must equeal to New Password");
		}else{
			$id=$db->getRow("select id,username,email from ".SITE_USER." where vcode='".$POST["code"]."'");
			//echo $db->getLastQuery();exit;
			if(is_array($id) && count($id)>0){
				$logdata=$db->updateAry(SITE_USER,array("pass"=>$POST["pass"],"vcode"=>""),"where id=".$id["id"]);
				$body="
					Dear ".$id["username"]."<br />
					<br />
					Are You Forgot password on favorchat.<br />
					<br />
					Your can Login to our site with  Login ID: <strong>".$id["email"]."</strong><br />
					<br />
					<br />
					<br />
					Your Password has been successfully reset<br />
					<br />
					<br />
					<br />
					";
					mymail($LinksDetails["mail_sender_email"],$id["email"],"Notification ! password  has been reset successfully on ".$LinksDetails["site_name"],$body,"FORGOT");
					//echo "Your Password Updated Successfully Click <a href='".URL_ROOT."' Here To Login";
					$status=array("status"=>"success","msg"=>"Your Password has been successfully reset","url"=>URL_ROOT);
				
			}else{
				$status=array("status"=>"error","msg"=>"Your reset Password link has been expired");//.$db->getLastQuery();
			}
		}
		return $status;
	
		
		}
	
		}
	}

}