<?php

class Store_timing {

	public static function getByStore($store_uid=false) {
		$response=false;
		if (false !== $store_uid) {
			$sql="SELECT * FROM `store_timing` WHERE `store_uid` = '".(int) $store_uid."' ORDER BY `uid` DESC ";
			$res=mysql_query($sql) or die(mysql_error());
			if (mysql_num_rows($res)) {
				while ($row=mysql_fetch_assoc($res)) {
					$response[]=$row;
				}
			}
		}
		return $response;
	}

	public static function saveTimings($store_uid=false, $arrStoreTiming=false) {
		$response=false;
		if (false !== $store_uid && false !== $arrStoreTiming && count($arrStoreTiming) > 0) {
			#self::delete($store_uid);
			$sql	="INSERT INTO `store_timing` (`store_uid`,`day_of_week`,`day_number`,`offence_start_time`,`offence_end_time`,`period_allowed`,`period_grace`,`out_of_hours_offence`) VALUES ";
			$values	='';
			foreach ($arrStoreTiming as $row) {
				$values.="('".(int) ($store_uid)."', '".mysql_real_escape_string($row['DayOfWeek'])."', '".(int) ($row['DayNumber'])."', '".mysql_real_escape_string($row['OffenceStartTime'])."', '".mysql_real_escape_string($row['OffenceEndTime'])."', '".mysql_real_escape_string($row['PeriodAllowed'])."', '".mysql_real_escape_string($row['PeriodGrace'])."', '".mysql_real_escape_string($row['OutOfHoursOffence'])."'),";
			}
			$sql .= rtrim($values, ",");
			$res		=mysql_query($sql) or die(mysql_error());
			$response	=mysql_insert_id();
		}
		return $response;
	}

	public static function delete($store_uid=false) {
		if (false !== $store_uid) {
			$sql		="DELETE FROM `store_timing` WHERE `store_uid` = '".(int) $store_uid."' ";
			echo $sql."<br/>";
			$response	=mysql_query($sql) or die(mysql_error());
		}
		return $response;
	}

	public static function deleteAll() {
		$sql		="DELETE FROM `store_timing` ";
		$response	=mysql_query($sql) or die(mysql_error());

		return $response;
	}

}

?>