changeset 23:f3bf1be1a51b

Change: using ajax in custom reservation method
author yoneda <yoneda@recorder.localnet.mda.or.jp>
date Thu, 23 Jul 2009 23:35:43 +0900
parents 95629ba1f043
children f0ef6fb63aa4
files customReservation.php reservationform.php templates/index.html templates/programTable.html templates/reservationform.html
diffstat 5 files changed, 275 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/customReservation.php	Fri Jul 17 22:40:41 2009 +0900
+++ b/customReservation.php	Thu Jul 23 23:35:43 2009 +0900
@@ -7,16 +7,36 @@
 $program_id = 0;
 if( isset( $_POST['program_id'] ) ) $program_id = $_POST['program_id'];
 
+
+if(!(
+   isset($_POST['shour'])       && 
+   isset($_POST['smin'])        &&
+   isset($_POST['smonth'])      &&
+   isset($_POST['sday'])        &&
+   isset($_POST['syear'])       &&
+   isset($_POST['ehour'])       &&
+   isset($_POST['emin'])        &&
+   isset($_POST['emonth'])      &&
+   isset($_POST['eday'])        &&
+   isset($_POST['eyear'])       &&
+   isset($_POST['channel_id'])  &&
+   isset($_POST['title'])       &&
+   isset($_POST['description']) &&
+   isset($_POST['category_id']) &&
+   isset($_POST['record_mode']))
+) {
+	exit("Error:予約に必要な値がセットされていません");
+}
+
+
 $start_time = @mktime( $_POST['shour'], $_POST['smin'], 0, $_POST['smonth'], $_POST['sday'], $_POST['syear'] );
 if( ($start_time < 0) || ($start_time === false) ) {
-	if( $program_id ) jdialog( "開始時間が不正です" , "reservation.php?program_id=".$program_id );
-	else jdialog("開始時間が不正です" );
+	exit("Error:開始時間が不正です" );
 }
 
 $end_time = @mktime( $_POST['ehour'], $_POST['emin'], 0, $_POST['emonth'], $_POST['eday'], $_POST['eyear'] );
 if( ($end_time < 0) || ($end_time === false) ) {
-	if( $program_id ) jdialog( "終了時間が不正です" , "reservation.php?program_id=".$program_id );
-	else jdialog("終了時間が不正です" );
+	exit("Error:終了時間が不正です" );
 }
 
 $channel_id = $_POST['channel_id'];
@@ -41,10 +61,7 @@
 	);
 }
 catch( Exception $e ) {
-	if( $progarm_id ) jdialog( $e->getMessage(), "reservation.php?program_id=".$program_id );
-	else jdialog( $e->getMessage() );
+	exit( "Error:".$e->getMessage() );
 }
-
-jdialog("予約しました:job番号".$rval);
-
+exit( "".$program_id );
 ?>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/reservationform.php	Thu Jul 23 23:35:43 2009 +0900
@@ -0,0 +1,57 @@
+<?php
+include_once('config.php');
+include_once( INSTALL_PATH . "/DBRecord.class.php" );
+include_once( INSTALL_PATH . "/Smarty/Smarty.class.php" );
+include_once( INSTALL_PATH . "/reclib.php" );
+
+if( ! isset( $_GET['program_id'] ) ) exit("Error: 番組IDが指定されていません" );
+$program_id = $_GET['program_id'];
+
+try {
+  $prec = new DBRecord( TBL_PREFIX.PROGRAM_TBL, "id", $program_id );
+  
+  sscanf( $prec->starttime, "%4d-%2d-%2d %2d:%2d:%2d", $syear, $smonth, $sday, $shour, $smin, $ssec );
+  sscanf( $prec->endtime, "%4d-%2d-%2d %2d:%2d:%2d", $eyear, $emonth, $eday, $ehour, $emin, $esec );
+  
+  $crecs = DBRecord::createRecords( TBL_PREFIX.CATEGORY_TBL );
+  $cats = array();
+  foreach( $crecs as $crec ) {
+	$cat = array();
+	$cat['id'] = $crec->id;
+	$cat['name'] = $crec->name_jp;
+	$cat['selected'] = $prec->category_id == $cat['id'] ? "selected" : "";
+	
+	array_push( $cats , $cat );
+  }
+  
+  $smarty = new Smarty();
+  
+  $smarty->assign( "syear", $syear );
+  $smarty->assign( "smonth", $smonth );
+  $smarty->assign( "sday", $sday );
+  $smarty->assign( "shour", $shour );
+  $smarty->assign( "smin" ,$smin );
+  $smarty->assign( "eyear", $eyear );
+  $smarty->assign( "emonth", $emonth );
+  $smarty->assign( "eday", $eday );
+  $smarty->assign( "ehour", $ehour );
+  $smarty->assign( "emin" ,$emin );
+  
+  $smarty->assign( "type", $prec->type );
+  $smarty->assign( "channel", $prec->channel );
+  $smarty->assign( "channel_id", $prec->channel_id );
+  $smarty->assign( "record_mode" , $RECORD_MODE );
+  
+  $smarty->assign( "title", $prec->title );
+  $smarty->assign( "description", $prec->description );
+  
+  $smarty->assign( "cats" , $cats );
+  
+  $smarty->assign( "program_id", $prec->id );
+  
+  $smarty->display("reservationform.html");
+}
+catch( exception $e ) {
+	exit( "Error:". $e->getMessage() );
+}
+?>
\ No newline at end of file
--- a/templates/index.html	Fri Jul 17 22:40:41 2009 +0900
+++ b/templates/index.html	Thu Jul 23 23:35:43 2009 +0900
@@ -53,7 +53,7 @@
 			if ($(this).hasClass('prg_rec')) {
 				str += '<div style="margin:2em 0 1em 0;text-align:center;"><a href="javascript:PRG.cancel(' + prgID + ')" class="ui-state-default ui-corner-all ui-dialog-buttonpane button">予約キャンセル</a></div>';
 			} else {
-				str += '<div style="margin:2em 0 1em 0;text-align:center;"><a href="javascript:PRG.rec(' + prgID + ')" class="ui-state-default ui-corner-all ui-dialog-buttonpane button">簡易予約</a> <a href="reservation.php?program_id=' + prgID + '" style="color:red;">予約カスタマイズ</a></div>';
+				str += '<div style="margin:2em 0 1em 0;text-align:center;"><a href="javascript:PRG.rec(' + prgID + ')" class="ui-state-default ui-corner-all ui-dialog-buttonpane button">簡易予約</a> <a href="javascript:PRG.customform(' + prgID + ')" class="ui-state-default ui-corner-all ui-dialog-buttonpane button">予約カスタマイズ</a></div>';
 			}
 			$('#floatBox4Dialog').html(str);
 			$('#floatBox4Dialog').dialog('open', 'center');
@@ -100,6 +100,70 @@
 					$('#floatBox4Dialog').dialog('close');
 				}
 			});
+		},
+		customform:function(id) {
+			$('#floatBox4Dialog').dialog('close');
+			$.get('reservationform.php', { program_id: id }, function(data) {
+				if(data.match(/^error/i)){
+					alert(data);
+				}
+				else {
+					var str = data;
+					str += '<div style="margin:2em 0 1em 0;text-align:center;"><a href="javascript:PRG.customrec()" class="ui-state-default ui-corner-all ui-dialog-buttonpane button">予約する</a></div>';
+					$('#floatBox4Dialog').html(str);
+					$('#floatBox4Dialog').dialog('open', 'center');
+				}
+			});
+		},
+		customrec:function() {
+			var id_syear = $('#id_syear').val();
+			var id_smonth = $('#id_smonth').val();
+			var id_sday = $('#id_sday').val();
+			var id_shour = $('#id_shour').val();
+			var id_smin = $('#id_smin').val();
+			var id_eyear = $('#id_eyear').val();
+			var id_emonth = $('#id_emonth').val();
+			var id_eday = $('#id_eday').val();
+			var id_ehour = $('#id_ehour').val();
+			var id_emin = $('#id_emin').val();
+			var id_channel_id = $('#id_channel_id').val();
+			var id_record_mode = $('#id_record_mode').val();
+			var id_title = $('#id_title').val();
+			var id_description = $('#id_description').val();
+			var id_category_id = $('#id_category_id ').val();
+			var id_program_id = $('#id_program_id').val();
+			var with_program_id = $('#id_program_id').attr('checked');
+			
+			if( ! with_program_id ) id_program_id = 0;
+			
+			$.post('customReservation.php', { syear: id_syear,
+							  smonth: id_smonth,
+							  sday: id_sday,
+							  shour: id_shour,
+							  smin: id_smin,
+							  eyear: id_eyear,
+							  emonth: id_emonth,
+							  eday: id_eday,
+							  ehour: id_ehour,
+							  emin: id_emin,
+							  channel_id: id_channel_id,
+							  record_mode: id_record_mode,
+							  title: id_title,
+							  description: id_description,
+							  category_id: id_category_id,
+							  program_id: id_program_id }, function(data) {
+				if(data.match(/^error/i)){
+					$('#floatBox4Dialog').dialog('close');
+					alert(data);
+				}
+				else {
+					var id = parseInt(data);
+					if( id ) {
+						$('#prgID_' + id).addClass('prg_rec');
+					}
+					$('#floatBox4Dialog').dialog('close');
+				}
+			});
 		}
 	}
 	var CTG = {
@@ -223,7 +287,7 @@
 		tvtimes_scroll();
 		prg_hover();
 		var DG = $('#floatBox4Dialog');
-		DG.dialog({title:'録画予約',width:500});
+		DG.dialog({title:'録画予約',width:600});
 		DG.dialog('close');
 		nowBar.INI();
 		CTG.INI();
--- a/templates/programTable.html	Fri Jul 17 22:40:41 2009 +0900
+++ b/templates/programTable.html	Thu Jul 23 23:35:43 2009 +0900
@@ -9,6 +9,9 @@
 
 {literal}
 <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
+<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
+<link rel="stylesheet" href="start/jquery-ui-1.7.2.custom.css" type="text/css">
+<script type="text/javascript" src="js/mdabasic.js"></script>
 <script type="text/javascript">
 	var PRG = {
 		rec:function(id){
@@ -19,8 +22,78 @@
 					$('#resid_' + id).addClass('prg_rec');
 				}
 			});
+		},
+		customform:function(id) {
+			$('#floatBox4Dialog').dialog('close');
+			$.get('reservationform.php', { program_id: id }, function(data) {
+				if(data.match(/^error/i)){
+					alert(data);
+				}
+				else {
+					var str = data;
+					str += '<div style="margin:2em 0 1em 0;text-align:center;"><a href="javascript:PRG.customrec()" class="ui-state-default ui-corner-all ui-dialog-buttonpane button">予約する</a></div>';
+					$('#floatBox4Dialog').html(str);
+					$('#floatBox4Dialog').dialog('open', 'center');
+				}
+			});
+		},
+		customrec:function() {
+			var id_syear = $('#id_syear').val();
+			var id_smonth = $('#id_smonth').val();
+			var id_sday = $('#id_sday').val();
+			var id_shour = $('#id_shour').val();
+			var id_smin = $('#id_smin').val();
+			var id_eyear = $('#id_eyear').val();
+			var id_emonth = $('#id_emonth').val();
+			var id_eday = $('#id_eday').val();
+			var id_ehour = $('#id_ehour').val();
+			var id_emin = $('#id_emin').val();
+			var id_channel_id = $('#id_channel_id').val();
+			var id_record_mode = $('#id_record_mode').val();
+			var id_title = $('#id_title').val();
+			var id_description = $('#id_description').val();
+			var id_category_id = $('#id_category_id ').val();
+			var id_program_id = $('#id_program_id').val();
+			var with_program_id = $('#id_program_id').attr('checked');
+			
+			if( ! with_program_id ) id_program_id = 0;
+			
+			$.post('customReservation.php', { syear: id_syear,
+							  smonth: id_smonth,
+							  sday: id_sday,
+							  shour: id_shour,
+							  smin: id_smin,
+							  eyear: id_eyear,
+							  emonth: id_emonth,
+							  eday: id_eday,
+							  ehour: id_ehour,
+							  emin: id_emin,
+							  channel_id: id_channel_id,
+							  record_mode: id_record_mode,
+							  title: id_title,
+							  description: id_description,
+							  category_id: id_category_id,
+							  program_id: id_program_id }, function(data) {
+				if(data.match(/^error/i)){
+					$('#floatBox4Dialog').dialog('close');
+					alert(data);
+				}
+				else {
+					var id = parseInt(data);
+					if( id ) {
+						$('#resid_' + id).addClass('prg_rec');
+					}
+					$('#floatBox4Dialog').dialog('close');
+				}
+			});
 		}
 	}
+	
+	$(document).ready(function () {
+		var DG = $('#floatBox4Dialog');
+		DG.dialog({title:'録画予約',width:600});
+		DG.dialog('close');
+	});
 </script>
 <style type="text/css">
 <!--
@@ -126,7 +199,7 @@
   <td>{$program.title|escape}</td>
   <td>{$program.description|escape}</td>
   <td><input type="button" value="録画" onClick="javascript:PRG.rec('{$program.id}')" /></td>
-  <td><a href="reservation.php?program_id={$program.id}">詳細へ</a></td>
+  <td><input type="button" value="詳細" onClick="javascript:PRG.customform('{$program.id}')" /></td>
  </tr>
 {/foreach}
 </table>
@@ -157,8 +230,7 @@
 {/if}
 {/if}
 
-
-
+<div id="floatBox4Dialog">jQuery UI Dialog</div>
 
 {literal}
 <script type="text/javascript">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/reservationform.html	Thu Jul 23 23:35:43 2009 +0900
@@ -0,0 +1,51 @@
+<form method="post" action="customReservation.php">
+<div>
+<span class="labelLeft">開始日時</span>
+        <input type="text" size="4" name="syear" id="id_syear" value="{$syear}" />年
+        <input type="text" size="2" name="smonth" id="id_smonth" value="{$smonth}" />月
+        <input type="text" size="2" name="sday" id="id_sday" value="{$sday}" />日
+        <input type="text" size="2" name="shour" id="id_shour" value="{$shour}" />時
+        <input type="text" size="2" name="smin" id="id_smin" value="{$smin}" />分~
+    </div>
+<div>
+    <span class="labelLeft">終了日時</span>
+        <input type="text" size="4" name="eyear" id="id_eyear" value="{$eyear}" />年
+        <input type="text" size="2" name="emonth" id="id_emonth" value="{$emonth}" />月
+        <input type="text" size="2" name="eday" id="id_eday" value="{$eday}" />日
+        <input type="text" size="2" name="ehour" id="id_ehour" value="{$ehour}" />時
+        <input type="text" size="2" name="emin" id="id_emin" value="{$emin}" />分
+    </div>
+<div>
+<span class="labelLeft">種別/ch</span>
+   {$type}:{$channel}ch
+       <input type="hidden" name="channel_id" id="id_channel_id" value="{$channel_id}" />
+   </div>
+<div>
+<span class="labelLeft">録画モード</span>
+    <select name="record_mode" id="id_record_mode">
+        {section name=mode loop=$record_mode }
+          <option value="{$smarty.section.mode.index}">{$record_mode[mode].name}</option>
+        {/section}
+        </select>
+     </div>
+<div>
+<span class="labelLeft">タイトル</span>
+   <input type="text" size="40" name="title" id="id_title" value="{$title}" /></div>
+
+<div>
+<span class="labelLeft">概要</span>
+    <textarea name="description" id="id_description" rows="4" cols="40" >{$description}</textarea></div>
+
+<div>
+<span class="labelLeft">カテゴリ</span>
+      <select name="category_id" id="id_category_id">
+      {foreach from=$cats item=cat}
+        <option value="{$cat.id}" {$cat.selected}>{$cat.name}</option>
+      {/foreach}
+      </select>
+    </div>
+
+<div>
+<span class="labelLeft">番組ID保持</span>
+  <input type="checkbox" name="program_id" id="id_program_id" value="{$program_id}" checked /></div>
+</form>