<?php
	/**
          * check if email is in the db
          * @params string $email
          * @params MySQL object $db
          ***> TODO: add check for syntax
         */
	function emailCheck($email,$db){
                if(emailInDB($email,$db)){
                        echo "<br/>you've already used this email - try another<br/>";
                }
                else{
                     	$newuser = array("email"=>$email);
                        $db->Insert($newuser,'Users');
                }

                //echo "<br/>emailcheck(): query result: ";
                //print_r($db->ArrayResults());
        }


        /**
          * check if email is in the db
          * @params string $sEmail
          * @params MySQL object $oDB
          * @return boolean
          ****> TODO: should be calling db->recordExists()
         */
	function emailInDB($sEmail,$oDB){
	                $dbtable = "Users";
	                //$query = "SELECT * FROM $dbtable WHERE email='$email'";
	                //$res = $db->ExecuteSQL($query);
	     	        $whereArr = array("email"=>$sEmail);
	                $res = $oDB->Select($dbtable,$whereArr);
	                return $res;
	}

	/**
	  * write email validation result to db
	  * @params string $sEmail
	  * @params string $sVres
	  * @params MySQL object $oDB  
	  * @return boolean
	  */
	  function vMark($sEmail,$sVres,$oDB){
	                $dbtable = "Users";
		        $setArr = array('validation'=>$sVres);  //prepare for db as key:value pair
	                $whereArr = array('email'=>$sEmail);
	                $res = $oDB->Update($dbtable,$setArr,$whereArr);
	                return $res;
	   }


?>
