DasErsteDE: handle rating attribute, ignore end times for now, leads to DataStore...
[nonametv.git] / web-admin / editchannel.php
blob8cb85ead5954c020388184a40f901ce1ff0280d1
1 <?php
3 require "config.php";
4 require "common.php";
5 require "mysql.php";
6 require "channels.php";
8 $debug=false;
10 $action='none';
11 $found = false;
13 //
14 // connect to main database
15 //
16 switch( $dconf['dbtype'] ){
17 case 'mysql':
18 $myc = sql_doconnect();
19 if( !$myc ) exit;
20 break;
24 <html>
25 <head>
26 <title>Channel details</title>
27 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
28 <link href="css/nonametv.css" rel=stylesheet>
29 <script language="JavaScript1.2" src="js/common.js"></script>
30 </head>
31 <body bgcolor="#FFFFFF" text="#000000">
33 <?php
35 function channelform( $ch )
37 global $action;
38 global $dconf;
39 global $chgdb;
41 print "<h1>Edit channel details: " . $ch['id'] . "</h1>\n";
42 print "<form name=channel action=\"editchannel.php\" method=post>\n";
43 switch( $action ){
44 case 'none':
45 case 'add':
46 case 'update':
47 case 'delete':
48 print " <input type=\"hidden\" name=\"id\" value=\"" . $ch['id'] . "\">\n";
49 break;
51 print " <table>\n";
53 print " <tr class=\"tableTitle\">\n";
54 print " <td colspan=\"2\">General channel settings</td>\n";
55 print " </tr>\n";
57 print " <tr>\n";
58 print " <td class=\"tableBody\">\n";
59 print " <div align=\"right\">ID</div>\n";
60 print " </td>\n";
61 print " <td class=\"tableBody\">";
62 switch( $action ){
63 case 'none':
64 case 'add':
65 case 'update':
66 case 'delete':
67 print $ch['id'];
68 break;
69 case 'new':
70 print "<input type=\"text\" name=\"id\" value=\"" . $ch['id'] . "\" size=\"12\" maxlength=\"12\">\n";
71 break;
73 print "</td>\n";
74 print " </tr>\n";
75 print " <tr>\n";
76 print " <td class=\"tableBody\">\n";
77 print " <div align=\"right\">Display Name</div>\n";
78 print " </td>\n";
79 print " <td class=\"tableBody\">\n";
80 print " <input type=\"text\" name=\"display_name\" value=\"" . $ch['display_name'] . "\" size=\"100\" maxlength=\"100\">\n";
81 print " </td>\n";
82 print " </tr>\n";
84 print " <tr>\n";
85 print " <td class=\"tableBody\">\n";
86 print " <div align=\"right\">XMLTV ID</div>\n";
87 print " </td>\n";
88 print " <td class=\"tableBody\">\n";
89 print " <input type=\"text\" name=\"xmltvid\" value=\"" . $ch['xmltvid'] . "\" size=\"100\" maxlength=\"100\">\n";
90 print " </td>\n";
91 print " </tr>\n";
93 print " <tr>\n";
94 print " <td class=\"tableBody\">\n";
95 print " <div align=\"right\">Channel group</div>\n";
96 print " </td>\n";
97 print " <td class=\"tableBody\">\n";
98 print " <select name=\"chgroup\">\n";
99 reset($chgdb);
100 while( list( $gk , $gv ) = each($chgdb) ){
101 print " <option value=\"" . $gv['abr'] . "\">" . $gv['display_name'] . "</option>\n";
103 print " </select>\n";
104 print " </td>\n";
105 print " </tr>\n";
107 print " <tr class=\"tableTitle\">\n";
108 print " <td colspan=\"2\">Importer settings</td>\n";
109 print " </tr>\n";
111 print " <tr>\n";
112 print " <td class=\"tableBody\">\n";
113 print " <div align=\"right\">Grabber</div>\n";
114 print " </td>\n";
115 print " <td class=\"tableBody\">\n";
116 print " <input type=\"text\" name=\"grabber\" value=\"" . $ch['grabber'] . "\" size=\"100\" maxlength=\"100\">\n";
117 print " </td>\n";
118 print " </tr>\n";
120 print " <tr>\n";
121 print " <td class=\"tableBody\">\n";
122 print " <div align=\"right\">Grabber Info</div>\n";
123 print " </td>\n";
124 print " <td class=\"tableBody\">\n";
125 print " <input type=\"text\" name=\"grabber_info\" value=\"" . $ch['grabber_info'] . "\" size=\"100\" maxlength=\"100\">\n";
126 print " </td>\n";
127 print " </tr>\n";
129 print " <tr class=\"tableTitle\">\n";
130 print " <td colspan=\"2\">Exporter settings</td>\n";
131 print " </tr>\n";
133 print " <tr>\n";
134 print " <td class=\"tableBody\">\n";
135 print " <div align=\"right\">Export</div>\n";
136 print " </td>\n";
137 print " <td class=\"tableBody\">\n";
138 print " <input type=\"checkbox\" name=\"export\" value=\"1\"" ;
139 if( $ch['export'] == '1' ) print " checked";
140 print "> check if you want to export this channel\n";
141 print " </td>\n";
142 print " </tr>\n";
144 print " <tr>\n";
145 print " <td class=\"tableBody\">\n";
146 print " <div align=\"right\">Logo</div>\n";
147 print " </td>\n";
148 print " <td class=\"tableBody\">\n";
149 print " <input type=\"checkbox\" name=\"logo\" value=\"1\"" ;
150 if( $ch['logo'] == '1' ) print " checked";
151 print "> check if you have logo available for this channel<br>\n";
152 print " </td>\n";
153 print " </tr>\n";
155 print " <tr class=\"tableTitle\">\n";
156 print " <td colspan=\"2\">Additional settings</td>\n";
157 print " </tr>\n";
159 print " <tr>\n";
160 print " <td class=\"tableBody\">\n";
161 print " <div align=\"right\">Default Program Type</div>\n";
162 print " </td>\n";
163 print " <td class=\"tableBody\">\n";
164 print " <input type=\"text\" name=\"def_pty\" value=\"" . $ch['def_pty'] . "\" size=\"100\" maxlength=\"100\">\n";
165 print " </td>\n";
166 print " </tr>\n";
168 print " <tr>\n";
169 print " <td class=\"tableBody\">\n";
170 print " <div align=\"right\">Default Category</div>\n";
171 print " </td>\n";
172 print " <td class=\"tableBody\">\n";
173 print " <input type=\"text\" name=\"def_cat\" value=\"" . $ch['def_cat'] . "\" size=\"100\" maxlength=\"100\">\n";
174 print " </td>\n";
175 print " </tr>\n";
177 print " <tr>\n";
178 print " <td class=\"tableBody\">\n";
179 print " <div align=\"right\">Language used for schedules</div>\n";
180 print " </td>\n";
181 print " <td class=\"tableBody\">\n";
182 print " <input type=\"text\" name=\"sched_lang\" value=\"" . $ch['sched_lang'] . "\" size=\"100\" maxlength=\"100\">\n";
183 print " </td>\n";
184 print " </tr>\n";
186 print " <tr>\n";
187 print " <td class=\"tableBody\">\n";
188 print " <div align=\"right\">OK if empty</div>\n";
189 print " </td>\n";
190 print " <td class=\"tableBody\">\n";
191 print " <input type=\"checkbox\" name=\"empty_ok\" value=\"1\"" ;
192 if( $ch['empty_ok'] == '1' ) print " checked";
193 print "> check if it is ok to have no data for this channel<br>\n";
194 print " </td>\n";
195 print " </tr>\n";
197 print " <tr>\n";
198 print " <td class=\"tableBody\">\n";
199 print " <div align=\"right\">Channel url</div>\n";
200 print " </td>\n";
201 print " <td class=\"tableBody\">\n";
202 print " <input type=\"text\" name=\"url\" value=\"" . $ch['url'] . "\" size=\"100\" maxlength=\"100\">\n";
203 print " </td>\n";
204 print " </tr>\n";
206 print " </table>\n";
208 if( $action == 'new' ){
209 print " <input type=\"submit\" value=\"Add\" class=\"gumb\" name=\"Add\">\n";
211 if( $action == 'none' ){
212 print " <input type=\"submit\" value=\"Update\" class=\"gumb\" name=\"Update\">\n";
213 print " <input type=\"submit\" value=\"Delete\" class=\"gumb\" name=\"Delete\">\n";
215 print " <input type=\"button\" value=\"Cancel\" class=\"gumb\" onClick=\"javascript:window.history.back()\">\n";
216 print "</form>\n";
218 print "<script language=javascript>\n";
219 print " setCtrlValue( window.document.channel.chgroup , \"" . $ch['chgroup'] . "\" );\n";
220 print "</script>\n";
224 // main
227 // arguments from the command line/url
228 if( $debug ) dbg( "REQUEST" , $_REQUEST );
229 if( isset($_REQUEST['action']) ) $action = $_REQUEST['action'];
230 if( isset($_REQUEST['channel']) ) $channelarg = $_REQUEST['channel'];
232 // posted data
233 if( $debug ) dbg( "_POST" , $_POST );
235 if(isset($_POST['id'])) $channelpost['id'] = $_POST['id'];
236 if(isset($_POST['display_name'])) $channelpost['display_name'] = $_POST['display_name'];
237 if(isset($_POST['xmltvid'])) $channelpost['xmltvid'] = $_POST['xmltvid'];
238 if(isset($_POST['chgroup'])) $channelpost['chgroup'] = $_POST['chgroup'];
239 if(isset($_POST['grabber'])) $channelpost['grabber'] = $_POST['grabber'];
240 if(isset($_POST['export'])) $channelpost['export'] = $_POST['export'];
241 if(isset($_POST['grabber_info'])) $channelpost['grabber_info'] = $_POST['grabber_info'];
242 if(isset($_POST['logo'])) $channelpost['logo'] = $_POST['logo'];
243 if(isset($_POST['def_pty'])) $channelpost['def_pty'] = $_POST['def_pty'];
244 if(isset($_POST['def_cat'])) $channelpost['def_cat'] = $_POST['def_cat'];
245 if(isset($_POST['sched_lang'])) $channelpost['sched_lang'] = $_POST['sched_lang'];
246 if(isset($_POST['empty_ok'])) $channelpost['empty_ok'] = $_POST['empty_ok'];
247 if(isset($_POST['url'])) $channelpost['url'] = $_POST['url'];
249 if( $debug ) dbg( "channelpost" , $channelpost );
251 // set default values if not set
252 if( isset($channelpost) ) $channelpost = set_channel_defaults( $channelpost );
254 // convert to lowercase
255 if( $dconf['lowercase'] && isset($channelpost) ){
256 $channelpost['xmltvid'] = strtolower( $channelpost['xmltvid'] );
260 // action from form
262 if( isset($_POST['Add']) && $_POST['Add'] == 'Add' ) $action = 'add';
263 if( isset($_POST['Update']) && $_POST['Update'] == 'Update' ) $action = 'update';
264 if( isset($_POST['Delete']) && $_POST['Delete'] == 'Delete' ) $action = 'delete';
267 // check if there is already a channel with this name
269 if( $action != 'new' ){
270 switch( $dconf['dbtype'] ){
271 case 'mysql':
273 // first try to find from posted data
274 if( !$found && isset($channelpost['id']) ) $found = sql_findChannel( $myc , 'id' , $channelpost['id'] );
275 if( $debug && $found ){
276 dbg( "sql: found from posted data" , $found );
279 // if !found with posted data
280 // try to find with data from arguments
281 if( !$found && $channelarg ) $found = sql_findChannel( $myc , 'id' , $channelarg );
282 if( $debug && $found ){
283 dbg( "sql: found from arguments" , $found );
285 break;
291 // not found
293 if( $found == false ){
294 switch( $action ){
295 case 'none': // if action==none -> this is edit, so it must be found
296 print ("<h3>Invalid channel: " . $channelarg . " </h3>\n");
297 exit;
298 case 'new': // if action==new -> we need blank form for new channel
299 if( $channelarg ) $channel['id'] = $channelarg; else $channel['id'] = '';
300 $channel = set_channel_defaults( $channel );
301 break;
302 default:
303 //dbg($action,"...");
304 break;
307 else $channel = $found;
309 // remember current dhcp group
310 // on delete or update channel should be removed from old group
311 //$channel[olddhcpgroup] = $channel[dhcpgroup];
313 switch( $action ){
314 case 'none':
315 case 'new':
316 $chgdb = load_channelgroups( $myc );
317 channelform( $channel );
318 break;
319 case 'add':
320 if( $found && !strcasecmp($found['id'],$channelpost['id'] )){
321 print "<h1>Channel with ID " . $channelpost['id'] . " exists</h1>\n";
322 reloadUrl('Continue','channelslist.php');
323 print "<script language=\"javascript\">\n";
324 print " url = 'showchannel.php?name=" . $found[name] . "';\n";
325 print " openDialog( url , 'showchannel' , 'width=300,height=300,resizable=yes,scrollbars=yes,status=yes' );\n";
326 print "</script>\n";
327 break;
329 switch( $dconf['dbtype'] ){
330 case 'mysql':
331 sql_addChannel( $myc , $channelpost );
332 break;
335 print "<h1>Channel " . $channelpost['id'] . " added</h1>\n";
336 reloadUrl('Continue','channelslist.php');
337 addlog(true,"Channel " . $channelpost['id'] . " added" );
338 break;
339 case 'update':
340 switch( $dconf['dbtype'] ){
341 case 'mysql':
342 sql_updateChannel( $myc , $channelpost );
343 break;
346 print "<h1>Channel " . $channelpost['id'] . " updated</h1>\n";
347 reloadUrl('Continue','channelslist.php');
348 addlog(true,"Channel " . $channelpost['id'] . " updated" );
349 break;
350 case 'delete':
351 switch( $dconf['dbtype'] ){
352 case 'mysql':
353 sql_deleteChannel( $myc , $channelpost );
354 break;
356 print "<h1>Channel " . $channelpost['id'] . " deleted</h1>\n";
357 reloadUrl('Continue','channelslist.php');
358 addlog(true,"Channel " . $channelpost['id'] . " deleted" );
359 break;
363 // disconnect from main database
365 switch( $dconf['dbtype'] ){
366 case 'mysql':
367 sql_dodisconnect( $myc );
368 break;
373 </body>
374 </html>