adminVehicle.php 3.45 KB
<? include $_SERVER["DOCUMENT_ROOT"] . "/common/classes/AdminBase.php" ;
include $_SERVER[DOCUMENT_ROOT] . "/common/php/LoginUtil.php";

if (! class_exists("AdminVehicle")){
	class AdminVehicle extends AdminBase{
		
		function __construct($req)
		{
			parent::__construct($req);
		}
		
		function getListOfVehicle(){
			$vehicleType=$this->req["vehicleType"];
			

			
			$sql="
				SELECT COUNT(*) AS rn
				FROM tblVehicle
				WHERE vehicleType='{$vehicleType}' AND status=1
			";
			$this->initPage();
			$this->rownum=$this->getValue($sql, 'rn');
			$this->setPage($this->rownum);
			$limit=" LIMIT {$this->startNum}, {$this->endNum} ;";
			
			
			
			$sql="
				SELECT vehicleNo, name
				FROM tblVehicle
				WHERE vehicleType='{$vehicleType}' AND status=1
				ORDER BY regDate DESC
				{$limit}
			";
			$result=$this->getArray($sql);
			return $result;
		}
		
		function getInfoOfVehicle(){
			$vehicleNo=$this->req["vehicleNo"];
			
			$sql="
				SELECT *
				FROM tblVehicle
				WHERE vehicleNo='{$vehicleNo}' AND status=1
			";
			$result=$this->getRow($sql);
			return $result;
		}
		
		
		function saveVehicle(){
			$vehicleType=$this->req["vehicleType"];
			$vehicleNo=$this->req["vehicleNo"];
			$name=$this->req["name"];
			$spec=$this->req["spec"];
			$videoURL=$this->req["videoURL"];
			$imgResult = $this->inFn_Common_fileSave($_FILES);
			
			
			$imgPathVehicle1 = $imgResult["imgPathVehicle1"]["saveURL"] != "" ? $imgResult["imgPathVehicle1"]["saveURL"] : $this->req["imgPathVehicle1"];
			$imgPathVehicle2 = $imgResult["imgPathVehicle2"]["saveURL"] != "" ? $imgResult["imgPathVehicle2"]["saveURL"] : $this->req["imgPathVehicle2"];
			$imgPathVehicle3 = $imgResult["imgPathVehicle3"]["saveURL"] != "" ? $imgResult["imgPathVehicle3"]["saveURL"] : $this->req["imgPathVehicle3"];
			$imgPathVehicle4 = $imgResult["imgPathVehicle4"]["saveURL"] != "" ? $imgResult["imgPathVehicle4"]["saveURL"] : $this->req["imgPathVehicle4"];
			$imgPathVehicle5 = $imgResult["imgPathVehicle5"]["saveURL"] != "" ? $imgResult["imgPathVehicle5"]["saveURL"] : $this->req["imgPathVehicle5"];
			
			if($vehicleNo == ""){
				$sql="
				INSERT INTO tblVehicle(vehicleType, name, spec, videoURL, status, regDate)
				VALUES
				(
				'{$vehicleType}',
				'{$name}',
				'{$spec}',
				'{$videoURL}',
				1,
				NOW()
				)
				";
				$this->update($sql);
				
				$lastNo=$this->mysql_insert_id();
				
				$sql="
					UPDATE tblVehicle
					SET
						imgPathVehicle1='{$imgPathVehicle1}',
						imgPathVehicle2='{$imgPathVehicle2}',
						imgPathVehicle3='{$imgPathVehicle3}',
						imgPathVehicle4='{$imgPathVehicle4}',
						imgPathVehicle5='{$imgPathVehicle5}'
					WHERE vehicleNo='{$lastNo}'
				";
				$this->update($sql);
				
				return $this->makeResultJson(1, "저장되었습니다");
			}
			else{
				$sql="
					UPDATE tblVehicle
					SET 
						name='{$name}',
						spec='{$spec}',
						videoURL='{$videoURL}',
						imgPathVehicle1='{$imgPathVehicle1}',
						imgPathVehicle2='{$imgPathVehicle2}',
						imgPathVehicle3='{$imgPathVehicle3}',
						imgPathVehicle4='{$imgPathVehicle4}',
						imgPathVehicle5='{$imgPathVehicle5}'
					WHERE vehicleNo='{$vehicleNo}'
				";
				$this->update($sql);
				
				return $this->makeResultJson(1, "수정되었습니다");
			}			
		}
		
		function deleteVehicle()
		{
			$noArr = $this->req["no"];
		
			$noStr = implode(',', $noArr);
		
			$sql = "
			UPDATE tblVehicle
			SET status = 0
			WHERE `vehicleNo` IN({$noStr})
			";
			$this->update($sql);
		}
		
		
		
	}
}

?>