comparison 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
comparison
equal deleted inserted replaced
114:f854f6606fa5 115:7a64d5e3baee
1 <?php 1 <?php
2 include_once('config.php'); 2 include_once('config.php');
3 include_once( INSTALL_PATH . '/DBRecord.class.php' ); 3 include_once( INSTALL_PATH . '/DBRecord.class.php' );
4 include_once( INSTALL_PATH . '/Smarty/Smarty.class.php' ); 4 include_once( INSTALL_PATH . '/Smarty/Smarty.class.php' );
5 include_once( INSTALL_PATH . '/Settings.class.php' ); 5 include_once( INSTALL_PATH . '/Settings.class.php' );
6 include_once( INSTALL_PATH . '/Keyword.class.php' );
6 7
7 $settings = Settings::factory(); 8 $settings = Settings::factory();
8 9
9 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + 300 )."'"; 10 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + 300 )."'";
10 11
22 23
23 24
24 $autorec_modes = $RECORD_MODE; 25 $autorec_modes = $RECORD_MODE;
25 $autorec_modes[(int)($settings->autorec_mode)]['selected'] = "selected"; 26 $autorec_modes[(int)($settings->autorec_mode)]['selected'] = "selected";
26 27
27 $weekofday = 7;
28 $search = ""; 28 $search = "";
29 $use_regexp = 0; 29 $use_regexp = 0;
30 $type = "*"; 30 $type = "*";
31 $category_id = 0; 31 $category_id = 0;
32 $station = 0; 32 $channel_id = 0;
33 $weekofday = 7;
33 $prgtime = 24; 34 $prgtime = 24;
34 35
35 36 // <若帥
36 // mysql_real_escape_string・膓鏆荀
37 $dbh = @mysql_connect($settings->db_host, $settings->db_user, $settings->db_pass );
38
39 // <若帥
40 if(isset( $_POST['do_search'] )) { 37 if(isset( $_POST['do_search'] )) {
41 if( isset($_POST['search'])){ 38 if( isset($_POST['search'])){
42 if( $_POST['search'] != "" ) { 39 $search = $_POST['search'];
43 $search = $_POST['search']; 40 if( isset($_POST['use_regexp']) && ($_POST['use_regexp']) ) {
44 if( isset($_POST['use_regexp']) && ($_POST['use_regexp']) ) { 41 $use_regexp = (int)($_POST['use_regexp']);
45 $use_regexp = $_POST['use_regexp'];
46 $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($search)."'";
47 }
48 else {
49 $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($search)."%'";
50 }
51 } 42 }
52 } 43 }
53 if( isset($_POST['type'])){ 44 if( isset($_POST['type'])){
54 if( $_POST['type'] != "*" ) { 45 $type = $_POST['type'];
55 $type = $_POST['type'];
56 $options .= " AND type = '".$_POST['type']."'";
57 }
58 } 46 }
59 if( isset($_POST['category_id'])) { 47 if( isset($_POST['category_id'])) {
60 if( $_POST['category_id'] != 0 ) { 48 $category_id = (int)($_POST['category_id']);
61 $category_id = $_POST['category_id'];
62 $options .= " AND category_id = '".$_POST['category_id']."'";
63 }
64 } 49 }
65 if( isset($_POST['station'])) { 50 if( isset($_POST['station'])) {
66 if( $_POST['station'] != 0 ) { 51 $channel_id = (int)($_POST['station']);
67 $station = $_POST['station'];
68 $options .= " AND channel_id = '".$_POST['station']."'";
69 }
70 } 52 }
71 if( isset($_POST['weekofday']) ) { 53 if( isset($_POST['weekofday']) ) {
72 $weekofday = $_POST['weekofday']; 54 $weekofday = (int)($_POST['weekofday']);
73 if( $weekofday != 7 ) {
74 $options .= " AND WEEKDAY(starttime) = '".$weekofday."'";
75 }
76 } 55 }
77 if( isset($_POST['prgtime']) ) { 56 if( isset($_POST['prgtime']) ) {
78 $prgtime = (int)($_POST['prgtime']); 57 $prgtime = (int)($_POST['prgtime']);
79 if( $prgtime != 24 ) {
80 $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)";
81 }
82 } 58 }
83 } 59 }
84 $options .= " ORDER BY starttime ASC LIMIT 300";
85
86 60
87 $do_keyword = 0; 61 $do_keyword = 0;
88 if( ($search != "") || ($type != "*") || ($category_id != 0) || ($station != 0) ) 62 if( ($search != "") || ($type != "*") || ($category_id != 0) || ($channel_id != 0) )
89 $do_keyword = 1; 63 $do_keyword = 1;
90 64
91 try{ 65 try{
92 $precs = DBRecord::createRecords(PROGRAM_TBL, $options ); 66 $precs = Keyword::search( $search, $use_regexp, $type, $category_id, $channel_id, $weekofday, $prgtime );
93 67
94 $programs = array(); 68 $programs = array();
95 foreach( $precs as $p ) { 69 foreach( $precs as $p ) {
96 $ch = new DBRecord(CHANNEL_TBL, "id", $p->channel_id ); 70 $ch = new DBRecord(CHANNEL_TBL, "id", $p->channel_id );
97 $cat = new DBRecord(CATEGORY_TBL, "id", $p->category_id ); 71 $cat = new DBRecord(CATEGORY_TBL, "id", $p->category_id );
155 $k_station_name = ""; 129 $k_station_name = "";
156 $crecs = DBRecord::createRecords(CHANNEL_TBL); 130 $crecs = DBRecord::createRecords(CHANNEL_TBL);
157 $stations = array(); 131 $stations = array();
158 $stations[0]['id'] = 0; 132 $stations[0]['id'] = 0;
159 $stations[0]['name'] = "鴻"; 133 $stations[0]['name'] = "鴻";
160 $stations[0]['selected'] = (! $station) ? "selected" : ""; 134 $stations[0]['selected'] = (! $channel_id) ? "selected" : "";
161 foreach( $crecs as $c ) { 135 foreach( $crecs as $c ) {
162 $arr = array(); 136 $arr = array();
163 $arr['id'] = $c->id; 137 $arr['id'] = $c->id;
164 $arr['name'] = $c->name; 138 $arr['name'] = $c->name;
165 $arr['selected'] = $station == $c->id ? "selected" : ""; 139 $arr['selected'] = $channel_id == $c->id ? "selected" : "";
166 if( $station == $c->id ) $k_station_name = $c->name; 140 if( $channel_id == $c->id ) $k_station_name = $c->name;
167 array_push( $stations, $arr ); 141 array_push( $stations, $arr );
168 } 142 }
169 $weekofdays["$weekofday"]["selected"] = "selected" ; 143 $weekofdays["$weekofday"]["selected"] = "selected" ;
170 144
171 // 絽 145 // 絽
190 $smarty->assign( "types", $types ); 164 $smarty->assign( "types", $types );
191 $smarty->assign( "k_type", $type ); 165 $smarty->assign( "k_type", $type );
192 $smarty->assign( "search" , $search ); 166 $smarty->assign( "search" , $search );
193 $smarty->assign( "use_regexp", $use_regexp ); 167 $smarty->assign( "use_regexp", $use_regexp );
194 $smarty->assign( "stations", $stations ); 168 $smarty->assign( "stations", $stations );
195 $smarty->assign( "k_station", $station ); 169 $smarty->assign( "k_station", $channel_id );
196 $smarty->assign( "k_station_name", $k_station_name ); 170 $smarty->assign( "k_station_name", $k_station_name );
197 $smarty->assign( "weekofday", $weekofday ); 171 $smarty->assign( "weekofday", $weekofday );
198 $smarty->assign( "k_weekofday", $weekofdays["$weekofday"]["name"] ); 172 $smarty->assign( "k_weekofday", $weekofdays["$weekofday"]["name"] );
199 $smarty->assign( "weekofday", $weekofday ); 173 $smarty->assign( "weekofday", $weekofday );
200 $smarty->assign( "weekofdays", $weekofdays ); 174 $smarty->assign( "weekofdays", $weekofdays );