<?php
/************************************************************************** *
 *																			*
 * Copyright (c) 2005 ISPG Technologies (I) Pvt Ltd. All rights reserved.	*
 *																			*
 * This  is  commercial  software,  only  users  who have purchased a valid *
 * license  and  accept  to the terms of the  License Agreement can install *
 * and use this program.													*
 *																			*
 ****************************************************************************
 * PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
 * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.			*
 ****************************************************************************/
//
//$Id: TestrideModel.php
//
class TestrideModel extends Model {
    public function saveTestride($languageIDs,$POST) {
            $phone  = $this->encryptDecrypt("encrypt","+" . $POST['countrycode']." ".$POST['phone']);
            $sql    = "
					INSERT INTO " . DB_PREFIX . "testride 
						(
						languageID,
						showroomID,
						subtitle,
						userFirstName,
						userLastName,
						phone,
                        emailID,
						model,
						whenBuy,
						currentbike,
						CreatedDate
						)
					VALUES
						(
						'" . $languageIDs['Current'] . "',
						'" . $POST['showroomID'] . "',
						'" . $POST['subtitleid'] . "',
						'" . $this->encryptDecrypt("encrypt",$POST['userFirstName']). "',
						'" . $this->encryptDecrypt("encrypt",$POST['userLastName']). "',
						'" . $phone. "',
                        '" . $this->encryptDecrypt("encrypt",$POST['emailID']) . "',
						'" . $POST['model'] . "',
						'" . $POST['whenTobuy'] . "',
						'" . $POST['currentbike'] . "',
						NOW()
						)
					";
					//echo  $sql;exit; 
            $this->ObjDatabase->setQuery($sql);
            $testdriveID	 = $this->ObjDatabase->getInsertId();
            return $testdriveID;
    }
     public function listTestride($limitFrom=0,$limitTo='',$languageIDs,$searchName='',$searchEmail='',$searchShowroom='',$searchModel='',$export='') {
                $sql = "	
					SELECT ";
		if ($limitTo)
		{
			$sql .= " 	
						SQL_CALC_FOUND_ROWS ";
		}
                $sql .= " 
                    testDrive.*,showDet.name 
                    FROM " . DB_PREFIX . "testride as testDrive 
                    JOIN " . DB_PREFIX . "showrooms showrom ON testDrive.showroomID=showrom.showroomID
                        JOIN 
                    " . DB_PREFIX . "showroom_details as showDet ON showrom.showroomID=showDet.showroomID AND showDet.languageID='".$languageIDs['Current']."' WHERE 1 AND showrom.brandID=4";
                if($searchName){
                      $sql .= " AND testDrive.userFirstName like '%" . $this->escape($this->encryptDecrypt("encrypt",$searchName)) . "%'" ;
                }
                 if($searchEmail){
                      $sql .= " AND testDrive.emailID like '%" . $this->escape($this->encryptDecrypt("encrypt",$searchEmail)) . "%'";
                }
                 if($searchShowroom){
                      $sql .= " AND showDet.name like '%" . $this->escape($searchShowroom) . "%'";
                }
                 if($searchModel){
                      $sql .= " AND testDrive.model like '%" . $this->escape($searchModel) . "%'";
                }
				$sql .= " ORDER BY testDrive.testrideID DESC";
				
                if ($limitTo)
		{
			$sql .= " 
					LIMIT  
						" . $limitFrom . "," . $limitTo . "";
		}
		if ($export) {
            return $this->ObjDatabase->readValuesObject($sql, MYSQLI_ASSOC);
        }
                //echo $sql;exit;
                $result= $this->ObjDatabase->readValues($sql);
                return $result;
     }
     
    
}
		