Augmenter: hook Augmenters into DataStore and enable augmenting for some Importers
[nonametv.git] / web-admin / programs.php
blobd2f1ff7607468bab5d282f4f35794404d2eedb52
1 <?php
3 function db_loadPrograms( $tvid )
5 global $dconf;
6 global $myc;
8 switch( $dconf['dbtype'] ){
9 case 'mysql':
10 $tdb = sql_loadPrograms( $myc , 'xmltvid' , $tvid );
11 return $tdb;
14 return false;
17 function sql_addProgram( $myc , $s )
19 global $debug;
21 $tblname = 'programs';
24 // prvo insert novog programa (name je unique)...
26 $q = "INSERT INTO " . $tblname . " SET name='" . $s[name] . "'";
27 if( $debug ) dbg( "INSERT INTO" , $q );
28 if( !mysql_query( $q , $myc ) ) {
29 print "<h4>MySQL: Can't add program " . $s[name] . " to " . $tblname . "</h4>\n";
30 print mysql_error( $myc ) . "\n";
31 return false;
34 print "<pre>MySQL: Program " . $s[name] . " added</pre>\n";
37 // nakon inserta azuriranje podataka...
39 sql_updateProgram( $myc , $s );
41 return true;
44 function sql_updateProgram( $myc , $s )
46 global $debug;
48 $tblname = 'programs';
50 $ak = array_keys( $s );
51 reset( $ak );
52 while( list( $sak , $sav ) = each( $ak ) ){
54 // fields that we don't update in mysql database
55 if( $sav == 'oldsharedname' ) continue;
56 if( $sav == 'oldfailover' ) continue;
58 switch( $sav ){
59 case 'fwrules': // multiline text fields
60 case 'ranges':
61 case 'unranges':
62 case 'routers':
63 case 'staticroutes':
64 case 'nameservers':
65 case 'unnameservers':
66 case 'winsservers':
67 case 'unwinsservers':
68 $q = "UPDATE " . $tblname . " SET " . $sav . "='" . join( "\n" , $s[$sav] ) . "' WHERE name='" . $s[name] . "'";
69 break;
70 default: // simple fields
71 $q = "UPDATE " . $tblname . " SET " . $sav . "='" . $s[$sav] . "' WHERE name='" . $s[name] . "'";
74 if( $debug ) dbg( "UPDATE" , $q );
76 if( !mysql_query( $q , $myc ) ) {
77 print "<h4>MySQL: Can't update field " . $sav . " of program " . $s[name] . "</h4>\n";
78 print mysql_error( $myc ) . "\n";
79 return false;
83 print "<pre>MySQL: Program " . $s[name] . " updated</pre>\n";
85 return true;
88 function sql_deleteProgram( $myc , $s )
90 global $debug;
92 $tblname = 'programs';
94 $q = "DELETE FROM " . $tblname . " WHERE name='" . $s[name] . "'";
95 if( $debug ) dbg( "DELETE" , $q );
96 if( !mysql_query( $q , $myc ) ) {
97 print "<h4>Can't delete program " . $s[name] . "</h4>\n";
98 print mysql_error( $myc ) . "\n";
99 return false;
102 print "<h4>MySQL: Program " . $s[name] . " deleted</h4>\n";
104 return true;
107 function sql_loadPrograms( $myc , $kaj , $vrijednost )
109 global $dconf,$debug;
111 if( strlen(trim($kaj)) ) $cond = $kaj . "='" . $vrijednost . "'";
113 $prgdb = sql_readtable( $myc , 'programs' , $cond );
114 if( ! $prgdb ) return false;
116 //array_sort( $prgdb , "name" );
118 return $prgdb;
121 function sql_findProgram( $myc , $channel , $kaj , $vrijednost )
123 global $dconf,$debug;
125 $cond = "channel_id='" . $channel . "'";
127 if( strlen(trim( $kaj )) ){
128 switch( $kaj ){
129 case 'fwrules': // walk through multiline text fields
130 case 'ranges':
131 case 'unranges':
132 case 'routers':
133 case 'staticroutes':
134 case 'nameservers':
135 case 'unnameservers':
136 case 'winsservers':
137 case 'unwinsservers':
138 $cond .= " AND " . $kaj . " LIKE '%" . $vrijednost . "%'";
139 return false; // ??????????
140 default:
141 $cond .= " AND " . $kaj . "='" . $vrijednost . "'";
142 break;
146 $sn = sql_readtable( $myc , 'programs' , $cond );
147 if( $debug ) dbg("sql_findProgram" , $sn );
149 return $sn;
153 function listPrograms( $chanid , $prgdb )
155 global $dconf;
157 $prgdb = array_sort( $prgdb , "start_time" );
159 reset( $prgdb );
160 while( list( $chk , $chv ) = each( $prgdb ) ){
162 print "<tr class=\"tableBody\">\n";
164 print " <td>\n";
165 print $chv['start_time'];
166 print " </td>\n";
168 print " <td>\n";
169 print $chv['end_time'];
170 print " </td>\n";
172 print "<td><a href=\"viewprogram.php?channel=" . $chanid . "&time=" . str2time($chv['start_time'], 0 ) . "\">";
173 print $chv['title'];
174 print "</a></td>\n";
176 print " <td>\n";
177 $predesc = ereg_replace( "\n" , "<br>" , $chv['description'] );
178 print $predesc;
179 print " </td>\n";
181 print " <td class=\"cat_" . $chv['category'] . "\">\n";
182 print $chv['category'];
183 print " </td>\n";
185 print "</tr>\n";
189 function extract_programs( $chanid , $from , $to )
191 global $dconf;
192 global $myc;
194 $pdb = sql_loadPrograms( $myc , 'channel_id' , $chanid );
195 if( !$pdb ) return false;
197 // programs in database are stored
198 // with start and end times in UTC
199 reset( $pdb );
200 while( list( $pk , $pv ) = each( $pdb ) ){
202 $stt = str2time( $pv['start_time'] , 1 );
203 $ent = str2time( $pv['end_time'] , 1 );
205 if( ( $stt < $from ) && ( $ent > $from ) ){ // program started before, but ends inside of window
206 $chunk[] = $pv;
207 } else if( ( $stt >= $from ) && ( $stt < $to ) ){ // whole program in time window
208 $chunk[] = $pv;
212 if( isset( $chunk ) ) return( $chunk );
213 else return false;
216 function fix_programs( $prgs , $from , $to )
218 global $dconf;
219 global $lngstrns;
221 $prg = array_sort( $prgs , "start_time" );
222 //dbg("programi na pocetku",$prg);
224 // fill the holes with no data
225 $lastend = $from;
226 reset( $prg );
227 while( list( $k , $v ) = each( $prg ) ){
229 $st = str2time( $v['start_time'] , 1 );
230 $et = str2time( $v['end_time'] , 1 );
232 if( $st < $from && $et >= $from ){ // now running show
233 //dbg("dodati trenutni program",$v);
234 $np[] = $v;
235 $lastend = $et;
236 } else if( ( $st >= $from ) && ( $st < $to ) ){ // whole program in time window
237 if( $st == $lastend ){
238 //dbg("dodati - nema rupe",$v);
239 $np[] = $v;
240 $lastend = $et;
241 } else if( $st > $lastend ){
242 //dbg("dodati - RUPA","od " . $lastend . " do " . $st );
244 // insert hole
245 $hole['channel_id'] = $v['channel_id'];
246 $hole['start_time'] = gmdate( "Y-m-d H:i:s" , $lastend );
247 $hole['end_time'] = gmdate( "Y-m-d H:i:s" , $st );
248 $hole['title'] = $lngstrns['nodata'];
249 $hole['description'] = $lngstrns['nodatadesc'];
250 $hole['category'] = "hole";
251 $np[] = $hole;
253 // add program after the hole
254 $np[] = $v;
255 $lastend = $et;
259 if( $lastend < $to ){
260 // insert hole
261 $hole['channel_id'] = $v['channel_id'];
262 $hole['start_time'] = gmdate( "Y-m-d H:i:s" , $lastend );
263 $hole['end_time'] = gmdate( "Y-m-d H:i:s" , $to );
264 $hole['title'] = $lngstrns['nodata'];
265 $hole['description'] = $lngstrns['nodatadesc'];
266 $hole['category'] = "hole";
267 $np[] = $hole;
268 //dbg("dodati - RUPA NA KRAJU od " . $lastend . " do " . $to , $hole);
270 //dbg("programi nakon filanja rupa",$np);
272 $prg = $np;
274 // join programs that are shorter than
275 // grancell
276 reset( $prg );
277 while( list( $k , $v ) = each( $prg ) ){
279 $st = str2time( $v['start_time'] , 1 );
280 $et = str2time( $v['end_time'] , 1 );
282 // calculate the time for the program that falls
283 // in the window to be displayed
284 // check if this is a currently showing program
285 // or the program will start during the time window
286 if( $st < $from && $et >= $from ){
287 $duration = $et - $from;
288 } else {
289 $duration = $et - $st;
292 // duration of the current show in minutes
293 $durmins = $duration / 60;
295 // check if show duration is less than smallest cell duration
296 if( $durmins < $dconf['grancell'] ){
300 return($prg);
304 // calculate cell width (%) and cell span
306 function cellwidth( $pcv , $fromtime , $window )
308 global $dconf;
309 $c = Array();
311 $st = str2time( $pcv['start_time'] , 1 );
312 $et = str2time( $pcv['end_time'] , 1 );
314 // total width available for programs (%)
315 $tw = 100 - $dconf['firstcellwidth'] - $dconf['lastcellwidth'];
317 // calculate the time for the program that falls
318 // in the window to be displayed
319 // check if this is a currently showing program
320 // or the program will start during the time window
321 if( ($st < $fromtime) && ($et >= $fromtime) && ($et <= ( $fromtime + $window * 60 )) ){
322 // started before, ends in window
323 $duration = $et - $fromtime;
324 } else if( ($st >= $fromtime) && ($st < ( $fromtime + $window * 60 )) && ($et > ( $fromtime + $window * 60 ) ) ){
325 // started in window, ends later
326 $duration = $fromtime + $window * 60 - $st;
327 } else if( ($st < $fromtime) && ($et > ( $fromtime + $window * 60 ) ) ){
328 // started before, ends later
329 $duration = $window * 60;
330 } else {
331 // whole show inside of the time window
332 $duration = $et - $st;
335 // duration of the current show in minutes
336 $durmins = $duration / 60;
338 // find the width of the curent show
339 $c['w'] = (int)( $durmins / $window * $tw );
341 // find the span of the curent show
342 $c['s'] = (int)( $durmins / $dconf['grancell'] );
344 //dbg("span " . $durmins . " " . $dconf['grancell'] ,$c['s']);
346 return( $c );
350 // draw the time bar (above programs list)
352 function draw_timebar( $start , $window , $gran , $grantime )
354 global $dconf;
355 global $lngstrns;
357 print "<tr>\n";
359 print " <td class=\"nowshowing_tabletitle\" width=\"" . $dconf['firstcellwidth'] . "%\" align=\"right\">\n";
360 print " <table>\n";
361 print " <tr>\n";
362 print " <td align=\"left\" width=\"10%\"><a href=\"nowshowing.php?time=" . ( $start - $dconf['shiftarrow'] * 60 ) . "\"><img src=\"images/left.gif\" border=\"0\" alt=\"left\"></a></td>\n";
363 print " <td align=\"center\"><a href=\"#\" id=\"catlegend\" onmouseover=\"popup('catlegend'); return true;\">" . $lngstrns['categories'] . "</a></td>\n";
364 print " <td align=\"right\" width=\"10%\"><a href=\"nowshowing.php?time=" . ( $start - $dconf['shiftarrow'] * 60 ) . "\"><img src=\"images/left.gif\" border=\"0\" alt=\"left\"></a></td>\n";
365 print " </tr>\n";
366 print " </table>\n";
367 print " </td>\n";
369 // find first time display point before $start
370 $da = getdate($start);
371 $da['minutes'] = (int)($da['minutes'] / $grantime) * $grantime;
372 $da['seconds'] = 0;
373 $tg = mktime ( $da['hours'] , $da['minutes'] , $da['seconds'] , $da['mon'] , $da['mday'] , $da['year'] );
374 $stop = $tg + $window * 60;
376 // calculate the number of time display points
377 // and the cell span of one time display point
378 // and the width of it
379 $cnt = $window / $grantime;
380 $tdps = $grantime / $gran;
381 $tdpw = ( 100 - $dconf['firstcellwidth'] - $dconf['lastcellwidth'] ) / $cnt;
384 $da = getdate( $tg );
385 print " <td nowrap class=\"nowshowing_tabletitle\" colspan=\"" . $tdps . "\" width=\"" . $tdpw . "%\" align=\"left\"><a href=\"nowshowing.php?time=" . $tg . "\">" . $da['hours'] . ":" . $da['minutes'] . "</a></td>\n";
386 $tg += ( $grantime * 60 );
387 } while( $tg < $stop );
389 print " <td nowrap class=\"nowshowing_tabletitle\" width=\"" . $dconf['lastcellwidth'] . "%\"><a href=\"nowshowing.php?time=" . ( $start + $window + $dconf['shiftarrow'] * 60 ) . "\"><img src=\"images/right.gif\" border=\"0\" alt=\"right\"></a></td>\n";
390 print "</tr>\n";
395 // draw_catlegend
397 function draw_catlegend()
401 <div id="catlegend_popup">
402 <table class="categories" width="400" bgcolor="#003060" class="small" cellpadding="5" cellspacing="5">
403 <tr>
404 <td colspan="3">Category Legend:</td>
405 </tr>
406 <tr>
407 <td class="cat_Action" align="center"><b>Action</b></td>
408 <td class="cat_Adult" align="center"><b>Adult</b></td>
409 <td class="cat_Animals" align="center"><b>Animals</b></td>
410 </tr>
411 <tr>
412 <td class="cat_Art_Music" align="center"><b>Art_Music</b></td>
413 <td class="cat_Business" align="center"><b>Business</b></td>
414 <td class="cat_Children" align="center"><b>Children</b></td>
415 </tr>
416 <tr>
417 <td class="cat_Comedy" align="center"><b>Comedy</b></td>
418 <td class="cat_Crime_Mystery" align="center"><b>Crime / Mystery</b></td>
419 <td class="cat_Documentary" align="center"><b>Documentary</b></td>
420 </tr>
421 <tr>
422 <td class="cat_Drama" align="center"><b>Drama</b></td>
423 <td class="cat_Educational" align="center"><b>Educational</b></td>
424 <td class="cat_Food" align="center"><b>Food</b></td>
425 </tr>
426 <tr>
427 <td class="cat_Game" align="center"><b>Game</b></td>
428 <td class="cat_Health_Medical" align="center"><b>Health / Medical</b></td>
429 <td class="cat_History" align="center"><b>History</b></td>
430 </tr>
431 <tr>
432 <td class="cat_Horror" align="center"><b>Horror</b></td>
433 <td class="cat_HowTo" align="center"><b>HowTo</b></td>
434 <td class="cat_Misc" align="center"><b>Misc</b></td>
435 </tr>
436 <tr>
437 <td class="cat_News" align="center"><b>News</b></td>
438 <td class="cat_Reality" align="center"><b>Reality</b></td>
439 <td class="cat_Romance" align="center"><b>Romance</b></td>
440 </tr>
441 <tr>
442 <td class="cat_SciFi_Fantasy" align="center"><b>SciFi / Fantasy</b></td>
443 <td class="cat_Science_Nature" align="center"><b>Science / Nature</b></td>
444 <td class="cat_Shopping" align="center"><b>Shopping</b></td>
445 </tr>
446 <tr>
447 <td class="cat_Soaps" align="center"><b>Soaps</b></td>
448 <td class="cat_Spiritual" align="center"><b>Spiritual</b></td>
449 <td class="cat_Sports" align="center"><b>Sports</b></td>
450 </tr>
451 <tr>
452 <td class="cat_Talk" align="center"><b>Talk</b></td>
453 <td class="cat_Travel" align="center"><b>Travel</b></td>
454 <td class="cat_War" align="center"><b>War</b></td>
455 </tr>
456 <tr>
457 <td class="cat_Western" align="center"><b>Western</b></td>
458 <td class="cat_Unknown" align="center"><b>Unknown</b></td>
459 <td class="cat_movie" align="center"><b>Movie</b></td>
460 </tr>
461 </table>
462 </div>
464 <?php
468 // set the class for a cell
469 // depends on program category
471 function cellclass_category( $p , $def )
473 switch( $p['category'] ){
474 case "hole":
475 $c = "cat_hole";
476 break;
477 case "Movie":
478 $c = "cat_movie";
479 break;
480 case "Action":
481 $c = "cat_Action";
482 break;
483 case "Adult":
484 $c = "cat_Adult";
485 break;
486 case "Animals":
487 $c = "cat_Animals";
488 break;
490 case "Documentary":
491 $c = "cat_Documentary";
492 break;
494 case "Reality":
495 $c = "cat_Reality";
496 break;
498 case "Romance":
499 $c = "cat_Romance";
500 break;
502 case "Sports":
503 $c = "cat_Sports";
504 break;
506 default:
507 if( $def ) $c = "cat_" . $def;
508 else $c = "cat_default";
512 </tr><tr>
513 <td class="cat_Art_Music" align="center"><b>Art_Music</b></td>
514 <td class="cat_Business" align="center"><b>Business</b></td>
515 <td class="cat_Children" align="center"><b>Children</b></td>
517 </tr><tr>
518 <td class="cat_Comedy" align="center"><b>Comedy</b></td>
520 <td class="cat_Crime_Mystery" align="center"><b>Crime / Mystery</b></td>
521 <td class="cat_Documentary" align="center"><b>Documentary</b></td>
523 </tr><tr>
524 <td class="cat_Drama" align="center"><b>Drama</b></td>
526 <td class="cat_Educational" align="center"><b>Educational</b></td>
527 <td class="cat_Food" align="center"><b>Food</b></td>
529 </tr><tr>
530 <td class="cat_Game" align="center"><b>Game</b></td>
531 <td class="cat_Health_Medical" align="center"><b>Health / Medical</b></td>
532 <td class="cat_History" align="center"><b>History</b></td>
534 </tr><tr>
535 <td class="cat_Horror" align="center"><b>Horror</b></td>
537 <td class="cat_HowTo" align="center"><b>HowTo</b></td>
538 <td class="cat_Misc" align="center"><b>Misc</b></td>
540 </tr><tr>
541 <td class="cat_News" align="center"><b>News</b></td>
543 <td class="cat_Reality" align="center"><b>Reality</b></td>
544 <td class="cat_Romance" align="center"><b>Romance</b></td>
546 </tr><tr>
547 <td class="cat_SciFi_Fantasy" align="center"><b>SciFi / Fantasy</b></td>
548 <td class="cat_Science_Nature" align="center"><b>Science / Nature</b></td>
549 <td class="cat_Shopping" align="center"><b>Shopping</b></td>
551 </tr><tr>
552 <td class="cat_Soaps" align="center"><b>Soaps</b></td>
554 <td class="cat_Spiritual" align="center"><b>Spiritual</b></td>
555 <td class="cat_Sports" align="center"><b>Sports</b></td>
557 </tr><tr>
558 <td class="cat_Talk" align="center"><b>Talk</b></td>
560 <td class="cat_Travel" align="center"><b>Travel</b></td>
561 <td class="cat_War" align="center"><b>War</b></td>
563 </tr><tr>
564 <td class="cat_Western" align="center"><b>Western</b></td>
565 <td class="cat_Unknown" align="center"><b>Unknown</b></td>
567 return( $c );