diff programTable.php @ 115:7a64d5e3baee

mod: キーワード検索を整理
author yoneda <epgrec@park.mda.or.jp>
date Sat, 13 Mar 2010 23:00:51 +0900
parents 57676bb30f64
children f5d58cf2842f
line wrap: on
line diff
--- a/programTable.php	Sat Mar 13 21:37:27 2010 +0900
+++ b/programTable.php	Sat Mar 13 23:00:51 2010 +0900
@@ -3,6 +3,7 @@
 include_once( INSTALL_PATH . '/DBRecord.class.php' );
 include_once( INSTALL_PATH . '/Smarty/Smarty.class.php' );
 include_once( INSTALL_PATH . '/Settings.class.php' );
+include_once( INSTALL_PATH . '/Keyword.class.php' );
 
 $settings = Settings::factory();
 
@@ -24,72 +25,45 @@
 $autorec_modes = $RECORD_MODE;
 $autorec_modes[(int)($settings->autorec_mode)]['selected'] = "selected";
 
-$weekofday = 7;
 $search = "";
 $use_regexp = 0;
 $type = "*";
 $category_id = 0;
-$station = 0;
+$channel_id = 0;
+$weekofday = 7;
 $prgtime = 24;
 
-
-// mysql_real_escape_string・膓鏆荀
-$dbh = @mysql_connect($settings->db_host, $settings->db_user, $settings->db_pass );
-
-	// <若帥
+// <若帥
 if(isset( $_POST['do_search'] )) {
 	if( isset($_POST['search'])){
-		if( $_POST['search'] != "" ) {
-			$search = $_POST['search'];
-			if( isset($_POST['use_regexp']) && ($_POST['use_regexp']) ) {
-				$use_regexp = $_POST['use_regexp'];
-				$options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($search)."'";
-			}
-			else {
-				$options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($search)."%'";
-			}
+		$search = $_POST['search'];
+		if( isset($_POST['use_regexp']) && ($_POST['use_regexp']) ) {
+			$use_regexp = (int)($_POST['use_regexp']);
 		}
 	}
 	if( isset($_POST['type'])){
-		if( $_POST['type'] != "*" ) {
-			$type = $_POST['type'];
-			$options .= " AND type = '".$_POST['type']."'";
-		}
+		$type = $_POST['type'];
 	}
 	if( isset($_POST['category_id'])) {
-		if( $_POST['category_id'] != 0 ) {
-			$category_id = $_POST['category_id'];
-			$options .= " AND category_id = '".$_POST['category_id']."'";
-		}
+		$category_id = (int)($_POST['category_id']);
 	}
 	if( isset($_POST['station'])) {
-		if( $_POST['station'] != 0 ) {
-			$station = $_POST['station'];
-			$options .= " AND channel_id = '".$_POST['station']."'";
-		}
+		$channel_id = (int)($_POST['station']);
 	}
 	if( isset($_POST['weekofday']) ) {
-		$weekofday = $_POST['weekofday'];
-		if( $weekofday != 7 ) {
-			$options .= " AND WEEKDAY(starttime) = '".$weekofday."'";
-		}
+		$weekofday = (int)($_POST['weekofday']);
 	}
 	if( isset($_POST['prgtime']) ) {
 		$prgtime = (int)($_POST['prgtime']);
-		if( $prgtime != 24 ) {
-			$options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)";
-		}
 	}
 }
-$options .= " ORDER BY starttime ASC LIMIT 300";
-
 
 $do_keyword = 0;
-if( ($search != "") || ($type != "*") || ($category_id != 0) || ($station != 0) )
+if( ($search != "") || ($type != "*") || ($category_id != 0) || ($channel_id != 0) )
 	$do_keyword = 1;
 	
 try{
-	$precs = DBRecord::createRecords(PROGRAM_TBL, $options );
+	$precs = Keyword::search( $search, $use_regexp, $type, $category_id, $channel_id, $weekofday, $prgtime );
 	
 	$programs = array();
 	foreach( $precs as $p ) {
@@ -157,13 +131,13 @@
 	$stations = array();
 	$stations[0]['id'] = 0;
 	$stations[0]['name'] = "鴻";
-	$stations[0]['selected'] = (! $station) ? "selected" : "";
+	$stations[0]['selected'] = (! $channel_id) ? "selected" : "";
 	foreach( $crecs as $c ) {
 		$arr = array();
 		$arr['id'] = $c->id;
 		$arr['name'] = $c->name;
-		$arr['selected'] = $station == $c->id ? "selected" : "";
-		if( $station == $c->id ) $k_station_name = $c->name;
+		$arr['selected'] = $channel_id == $c->id ? "selected" : "";
+		if( $channel_id == $c->id ) $k_station_name = $c->name;
 		array_push( $stations, $arr );
 	}
 	$weekofdays["$weekofday"]["selected"] = "selected" ;
@@ -192,7 +166,7 @@
 	$smarty->assign( "search" , $search );
 	$smarty->assign( "use_regexp", $use_regexp );
 	$smarty->assign( "stations", $stations );
-	$smarty->assign( "k_station", $station );
+	$smarty->assign( "k_station", $channel_id );
 	$smarty->assign( "k_station_name", $k_station_name );
 	$smarty->assign( "weekofday", $weekofday );
 	$smarty->assign( "k_weekofday", $weekofdays["$weekofday"]["name"] );
@@ -206,4 +180,4 @@
 catch( exception $e ) {
 	exit( $e->getMessage() );
 }
-?>
+?>
\ No newline at end of file