comparison programTable.php @ 117:f5d58cf2842f

merged with upstream
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sun, 14 Mar 2010 16:31:50 +0900
parents 9b9e22be8407 7a64d5e3baee
children 66eabfc1b118
comparison
equal deleted inserted replaced
113:9b9e22be8407 117:f5d58cf2842f
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 $search = mb_convert_kana($search, "A", "UTF-8");
50 $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($search)."%'";
51 }
52 } 42 }
53 } 43 }
54 if( isset($_POST['type'])){ 44 if( isset($_POST['type'])){
55 if( $_POST['type'] != "*" ) { 45 $type = $_POST['type'];
56 $type = $_POST['type'];
57 $options .= " AND type = '".$_POST['type']."'";
58 }
59 } 46 }
60 if( isset($_POST['category_id'])) { 47 if( isset($_POST['category_id'])) {
61 if( $_POST['category_id'] != 0 ) { 48 $category_id = (int)($_POST['category_id']);
62 $category_id = $_POST['category_id'];
63 $options .= " AND category_id = '".$_POST['category_id']."'";
64 }
65 } 49 }
66 if( isset($_POST['station'])) { 50 if( isset($_POST['station'])) {
67 if( $_POST['station'] != 0 ) { 51 $channel_id = (int)($_POST['station']);
68 $station = $_POST['station'];
69 $options .= " AND channel_id = '".$_POST['station']."'";
70 }
71 } 52 }
72 if( isset($_POST['weekofday']) ) { 53 if( isset($_POST['weekofday']) ) {
73 $weekofday = $_POST['weekofday']; 54 $weekofday = (int)($_POST['weekofday']);
74 if( $weekofday != 7 ) {
75 $options .= " AND WEEKDAY(starttime) = '".$weekofday."'";
76 }
77 } 55 }
78 if( isset($_POST['prgtime']) ) { 56 if( isset($_POST['prgtime']) ) {
79 $prgtime = (int)($_POST['prgtime']); 57 $prgtime = (int)($_POST['prgtime']);
80 if( $prgtime != 24 ) {
81 $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)";
82 }
83 } 58 }
84 } 59 }
85 $options .= " ORDER BY starttime ASC LIMIT 300";
86
87 60
88 $do_keyword = 0; 61 $do_keyword = 0;
89 if( ($search != "") || ($type != "*") || ($category_id != 0) || ($station != 0) ) 62 if( ($search != "") || ($type != "*") || ($category_id != 0) || ($channel_id != 0) )
90 $do_keyword = 1; 63 $do_keyword = 1;
91 64
92 try{ 65 try{
93 $precs = DBRecord::createRecords(PROGRAM_TBL, $options ); 66 $precs = Keyword::search( $search, $use_regexp, $type, $category_id, $channel_id, $weekofday, $prgtime );
94 67
95 $programs = array(); 68 $programs = array();
96 foreach( $precs as $p ) { 69 foreach( $precs as $p ) {
97 $ch = new DBRecord(CHANNEL_TBL, "id", $p->channel_id ); 70 $ch = new DBRecord(CHANNEL_TBL, "id", $p->channel_id );
98 $cat = new DBRecord(CATEGORY_TBL, "id", $p->category_id ); 71 $cat = new DBRecord(CATEGORY_TBL, "id", $p->category_id );
156 $k_station_name = ""; 129 $k_station_name = "";
157 $crecs = DBRecord::createRecords(CHANNEL_TBL); 130 $crecs = DBRecord::createRecords(CHANNEL_TBL);
158 $stations = array(); 131 $stations = array();
159 $stations[0]['id'] = 0; 132 $stations[0]['id'] = 0;
160 $stations[0]['name'] = "すべて"; 133 $stations[0]['name'] = "すべて";
161 $stations[0]['selected'] = (! $station) ? "selected" : ""; 134 $stations[0]['selected'] = (! $channel_id) ? "selected" : "";
162 foreach( $crecs as $c ) { 135 foreach( $crecs as $c ) {
163 $arr = array(); 136 $arr = array();
164 $arr['id'] = $c->id; 137 $arr['id'] = $c->id;
165 $arr['name'] = $c->name; 138 $arr['name'] = $c->name;
166 $arr['selected'] = $station == $c->id ? "selected" : ""; 139 $arr['selected'] = $channel_id == $c->id ? "selected" : "";
167 if( $station == $c->id ) $k_station_name = $c->name; 140 if( $channel_id == $c->id ) $k_station_name = $c->name;
168 array_push( $stations, $arr ); 141 array_push( $stations, $arr );
169 } 142 }
170 $weekofdays["$weekofday"]["selected"] = "selected" ; 143 $weekofdays["$weekofday"]["selected"] = "selected" ;
171 144
172 // 時間帯 145 // 時間帯
191 $smarty->assign( "types", $types ); 164 $smarty->assign( "types", $types );
192 $smarty->assign( "k_type", $type ); 165 $smarty->assign( "k_type", $type );
193 $smarty->assign( "search" , $search ); 166 $smarty->assign( "search" , $search );
194 $smarty->assign( "use_regexp", $use_regexp ); 167 $smarty->assign( "use_regexp", $use_regexp );
195 $smarty->assign( "stations", $stations ); 168 $smarty->assign( "stations", $stations );
196 $smarty->assign( "k_station", $station ); 169 $smarty->assign( "k_station", $channel_id );
197 $smarty->assign( "k_station_name", $k_station_name ); 170 $smarty->assign( "k_station_name", $k_station_name );
198 $smarty->assign( "weekofday", $weekofday ); 171 $smarty->assign( "weekofday", $weekofday );
199 $smarty->assign( "k_weekofday", $weekofdays["$weekofday"]["name"] ); 172 $smarty->assign( "k_weekofday", $weekofdays["$weekofday"]["name"] );
200 $smarty->assign( "weekofday", $weekofday ); 173 $smarty->assign( "weekofday", $weekofday );
201 $smarty->assign( "weekofdays", $weekofdays ); 174 $smarty->assign( "weekofdays", $weekofdays );