Advertisement
Guest User

Untitled

a guest
Dec 24th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 67.00 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. ob_start();
  6.  
  7. include "./common.php";
  8.  
  9. $error = '';
  10.  
  11. Admin::checkAuth();
  12.  
  13. Admin::checkAccess( AdminAccess::ACCESS_VIEW );
  14.  
  15. if ( @$_GET['del'] && !empty( $_GET['id'] ) )
  16. {
  17.  
  18.     Admin::checkAccess( AdminAccess::ACCESS_DELETE );
  19.  
  20.     $tv_archive = new TvArchive();
  21.     $tv_archive->deleteTasks( intval( $_GET['id'] ) );
  22.  
  23.     $ch_links = Mysql::getInstance()->from( 'ch_links' )->where( array( 'ch_id' => intval( $_GET['id'] ) ) )->get()->all();
  24.  
  25.     foreach ( $ch_links as $ch_link )
  26.     {
  27.         Mysql::getInstance()->use_caching( array( 'ch_links.id=' . intval( $ch_link['id'] ) ) )->delete( 'ch_links', array( 'id' => intval( $ch_link['id'] ) ) );
  28.     }
  29.  
  30.     Mysql::getInstance()->use_caching( array( 'itv.id=' . intval( $_GET['id'] ) ) )->delete( 'itv', array( 'id' => intval( $_GET['id'] ) ) );
  31.  
  32.     header( "Location: add_itv.php" );
  33.     exit;
  34. }
  35.  
  36. if ( isset( $_GET['status'] ) && @$_GET['id'] )
  37. {
  38.  
  39.     Admin::checkAccess( AdminAccess::ACCESS_CONTEXT_ACTION );
  40.  
  41.     Mysql::getInstance()->use_caching( array( 'itv.id=' . intval( @$_GET['id'] ) ) )->update( 'itv', array( 'status' => intval( @$_GET['status'] ) ), array( 'id' => intval( @$_GET['id'] ) ) );
  42.  
  43.     header( "Location: add_itv.php" );
  44.     exit;
  45. }
  46.  
  47. if ( isset( $_GET['shift'] ) && isset( $_GET['from_num'] ) )
  48. {
  49.  
  50.     Admin::checkAccess( AdminAccess::ACCESS_CONTEXT_ACTION );
  51.  
  52.     $direction = ( int )$_GET['shift'];
  53.     $from_num = ( int )$_GET['from_num'];
  54.  
  55.     $channel_ids = Mysql::getInstance()->from( 'itv' )->where( array( 'number>=' => $from_num ) )->get()->all( 'id' );
  56.  
  57.     if ( $direction > 0 )
  58.     {
  59.         $direction = '+' . $direction;
  60.     }
  61.  
  62.     if ( !empty( $channel_ids ) )
  63.     {
  64.         $query = 'update itv set number=number' . $direction . ' where id in (' . implode( ', ', $channel_ids ) . ')';
  65.         Mysql::getInstance()->query( $query );
  66.     }
  67.  
  68.  
  69.     header( "Location: add_itv.php" );
  70.     exit;
  71. }
  72.  
  73. if ( @$_GET['restart_all_archives'] )
  74. {
  75.  
  76.     Admin::checkAccess( AdminAccess::ACCESS_PAGE_ACTION );
  77.  
  78.     $tv_archive = new TvArchive();
  79.     $result = true;
  80.     $current_tasks = Mysql::getInstance()->select( 'ch_id, storage_name' )->from( 'tv_archive' )->get()->all();
  81.     $new_tasks = array();
  82.     foreach ( $current_tasks as $task )
  83.         $new_tasks[$task['ch_id']][] = $task['storage_name'];
  84.     foreach ( array_keys( $new_tasks ) as $channel )
  85.     {
  86.         $tv_archive->deleteTasks( $channel );
  87.         $result = $tv_archive->createTasks( $channel, $new_tasks[$channel] ) && $result;
  88.     }
  89.     if ( !$result )
  90.         $error = _( 'TV Archive has NOT been restarted correctly.' );
  91.     else
  92.         $error = _( 'TV Archive has been restarted.' );
  93. }
  94.  
  95. if ( !$error )
  96. {
  97.  
  98.     if ( @$_POST['censored'] == 'on' )
  99.     {
  100.         $censored = 1;
  101.     }
  102.     else
  103.     {
  104.         $censored = 0;
  105.     }
  106.  
  107.     if ( @$_POST['use_http_tmp_link'] == 'on' )
  108.     {
  109.         $use_http_tmp_link = 1;
  110.     }
  111.     else
  112.     {
  113.         $use_http_tmp_link = 0;
  114.     }
  115.  
  116.     if ( @$_POST['wowza_tmp_link'] == 'on' )
  117.     {
  118.         $wowza_tmp_link = 1;
  119.     }
  120.     else
  121.     {
  122.         $wowza_tmp_link = 0;
  123.     }
  124.  
  125.     if ( @$_POST['nginx_secure_link'] == 'on' )
  126.     {
  127.         $nginx_secure_link = 1;
  128.     }
  129.     else
  130.     {
  131.         $nginx_secure_link = 0;
  132.     }
  133.  
  134.     if ( @$_POST['wowza_dvr'] == 'on' )
  135.     {
  136.         $wowza_dvr = 1;
  137.     }
  138.     else
  139.     {
  140.         $wowza_dvr = 0;
  141.     }
  142.  
  143.     if ( @$_POST['flussonic_dvr'] == 'on' )
  144.     {
  145.         $flussonic_dvr = 1;
  146.     }
  147.     else
  148.     {
  149.         $flussonic_dvr = 0;
  150.     }
  151.  
  152.     if ( @$_POST['wowza_dvr'] == 'on' )
  153.     {
  154.         $wowza_dvr = 1;
  155.     }
  156.     else
  157.     {
  158.         $wowza_dvr = 0;
  159.     }
  160.  
  161.     if ( @$_POST['enable_tv_archive'] == 'on' )
  162.     {
  163.         $enable_tv_archive = 1;
  164.     }
  165.     else
  166.     {
  167.         $enable_tv_archive = 0;
  168.     }
  169.  
  170.     $storage_names = empty( $_POST['storage_names'] ) ? array() : $_POST['storage_names'];
  171.  
  172.     $allow_pvr = @intval( $_POST['allow_pvr'] );
  173.  
  174.     if ( empty( $storage_names ) )
  175.     {
  176.         $enable_tv_archive = 0;
  177.         $flussonic_dvr = 0;
  178.         $wowza_dvr = 0;
  179.     }
  180.  
  181.     $pvr_storage_names = empty( $_POST['pvr_storage_names'] ) ? array() : $_POST['pvr_storage_names'];
  182.  
  183.     if ( empty( $pvr_storage_names ) )
  184.     {
  185.         $allow_pvr = 0;
  186.     }
  187.  
  188.     $enable_monitoring = @intval( $_POST['enable_monitoring'] );
  189.  
  190.     $allow_local_pvr = @intval( $_POST['allow_local_pvr'] );
  191.  
  192.     $allow_local_timeshift = @intval( $_POST['allow_local_timeshift'] );
  193.  
  194.     $enable_wowza_load_balancing = @intval( $_POST['enable_wowza_load_balancing'] );
  195.  
  196.     if ( @$_POST['base_ch'] == 'on' )
  197.     {
  198.         $base_ch = 1;
  199.     }
  200.     else
  201.     {
  202.         $base_ch = 0;
  203.     }
  204.  
  205.     if ( @$_POST['bonus_ch'] == 'on' )
  206.     {
  207.         $bonus_ch = 1;
  208.     }
  209.     else
  210.     {
  211.         $bonus_ch = 0;
  212.     }
  213.  
  214.     if ( @$_POST['hd'] == 'on' )
  215.     {
  216.         $hd = 1;
  217.     }
  218.     else
  219.     {
  220.         $hd = 0;
  221.     }
  222.  
  223.     if ( @$_POST['number'] && !check_number( $_POST['number'] ) && !@$_GET['update'] )
  224.     {
  225.         $error = sprintf( _( 'Error: channel with number "%s" is already in use' ) . ' <a href="#form">#</a>', intval( $_POST['number'] ) );
  226.     }
  227.  
  228.     $urls = empty( $_POST['cmd'] ) ? array() : $_POST['cmd'];
  229.  
  230.     $links = array();
  231.  
  232.     foreach ( $urls as $key => $value )
  233.     {
  234.  
  235.         if ( empty( $value ) )
  236.         {
  237.             continue;
  238.         }
  239.  
  240.         $links[] = array(
  241.             'url' => $value,
  242.             'priority' => array_key_exists( $key, $_POST['priority'] ) ? ( int )$_POST['priority'][$key] : 0,
  243.             'use_http_tmp_link' => !empty( $_POST['use_http_tmp_link'] ) && array_key_exists( $key, $_POST['use_http_tmp_link'] ) ? ( int )$_POST['use_http_tmp_link'][$key] : 0,
  244.             'wowza_tmp_link' => !empty( $_POST['wowza_tmp_link'] ) && array_key_exists( $key, $_POST['wowza_tmp_link'] ) ? ( int )$_POST['wowza_tmp_link'][$key] : 0,
  245.             'flussonic_tmp_link' => !empty( $_POST['flussonic_tmp_link'] ) && array_key_exists( $key, $_POST['flussonic_tmp_link'] ) ? ( int )$_POST['flussonic_tmp_link'][$key] : 0,
  246.             'xtream_codes_support' => !empty( $_POST['xtream_codes_support'] ) && array_key_exists( $key, $_POST['xtream_codes_support'] ) ? ( int )$_POST['xtream_codes_support'][$key] : 0,
  247.  
  248.             'nginx_secure_link' => !empty( $_POST['nginx_secure_link'] ) && array_key_exists( $key, $_POST['nginx_secure_link'] ) ? ( int )$_POST['nginx_secure_link'][$key] : 0,
  249.             'user_agent_filter' => array_key_exists( $key, $_POST['user_agent_filter'] ) ? $_POST['user_agent_filter'][$key] : '',
  250.             'monitoring_url' => array_key_exists( $key, $_POST['monitoring_url'] ) ? $_POST['monitoring_url'][$key] : '',
  251.             'use_load_balancing' => !empty( $_POST['stream_server'] ) && array_key_exists( $key, $_POST['stream_server'] ) && !empty( $_POST['use_load_balancing'] ) && array_key_exists( $key, $_POST['use_load_balancing'] ) ? ( int )$_POST['use_load_balancing'][$key] : 0,
  252.             'enable_monitoring' => !empty( $_POST['enable_monitoring'] ) && array_key_exists( $key, $_POST['enable_monitoring'] ) ? ( int )$_POST['enable_monitoring'][$key] : 0,
  253.             'enable_balancer_monitoring' => !empty( $_POST['enable_balancer_monitoring'] ) && array_key_exists( $key, $_POST['enable_balancer_monitoring'] ) ? ( int )$_POST['enable_balancer_monitoring'][$key] : 0,
  254.             'stream_servers' => !empty( $_POST['stream_server'] ) && array_key_exists( $key, $_POST['stream_server'] ) ? $_POST['stream_server'][$key] : array(),
  255.             );
  256.     }
  257.  
  258.  
  259.     $mc_cmd = @$_POST['mc_cmd'];
  260.  
  261.     if ( empty( $mc_cmd ) )
  262.     {
  263.         foreach ( $links as $link )
  264.         {
  265.             if ( ( strpos( $link['url'], 'rtp://' ) !== false || strpos( $link['url'], 'udp://' ) !== false || strpos( $link['url'], 'http://' ) !== false ) && preg_match( "/(\S+:\/\/\S+)/", $link['url'], $match ) )
  266.             {
  267.                 $mc_cmd = $match[1];
  268.                 break;
  269.             }
  270.         }
  271.     }
  272.  
  273.     if ( @$_GET['save'] && !$error && !empty( $_POST ) )
  274.     {
  275.  
  276.         Admin::checkAccess( AdminAccess::ACCESS_CREATE );
  277.  
  278.         if ( @$_GET['name'] && @$_POST['tv_genre_id'] > 0 )
  279.         {
  280.  
  281.             $ch_id = intval( @$_GET['id'] );
  282.  
  283.             $channel = Itv::getChannelById( $ch_id );
  284.  
  285.             if ( !empty( $channel ) && $channel['enable_tv_archive'] != $enable_tv_archive || $channel['wowza_dvr'] != $wowza_dvr || $channel['flussonic_dvr'] != $flussonic_dvr )
  286.             {
  287.  
  288.                 if ( $channel['enable_tv_archive'] )
  289.                 {
  290.  
  291.                     if ( $channel['flussonic_dvr'] )
  292.                     {
  293.                         $archive = new FlussonicTvArchive();
  294.                     }
  295.                     elseif ( $channel['wowza_dvr'] )
  296.                     {
  297.                         $archive = new WowzaTvArchive();
  298.                     }
  299.                     else
  300.                     {
  301.                         $archive = new TvArchive();
  302.                     }
  303.  
  304.                     $archive->deleteTasks( $ch_id );
  305.                 }
  306.             }
  307.  
  308.             $ch_id = Mysql::getInstance()->insert( 'itv', array(
  309.                 'name' => $_POST['name'],
  310.                 'number' => $_POST['number'],
  311.                 'use_http_tmp_link' => $use_http_tmp_link,
  312.                 'wowza_tmp_link' => $wowza_tmp_link,
  313.                 'nginx_secure_link' => $nginx_secure_link,
  314.                 'wowza_dvr' => $wowza_dvr,
  315.                 'flussonic_dvr' => $flussonic_dvr,
  316.                 'censored' => $censored,
  317.                 'base_ch' => $base_ch,
  318.                 'bonus_ch' => $bonus_ch,
  319.                 'hd' => $hd,
  320.                 'cost' => @$_POST['cost'],
  321.                 'cmd' => ( !empty( $_POST['cmd'][0] ) ? $_POST['cmd'][0] : "" ),
  322.                 'cmd_1' => @$_POST['cmd_1'],
  323.                 'cmd_2' => @$_POST['cmd_2'],
  324.                 'cmd_3' => @$_POST['cmd_3'],
  325.                 'mc_cmd' => $mc_cmd,
  326.                 'enable_wowza_load_balancing' => $enable_wowza_load_balancing,
  327.                 'enable_tv_archive' => $enable_tv_archive,
  328.                 'allow_pvr' => $allow_pvr,
  329.                 'allow_local_pvr' => $allow_local_pvr,
  330.                 'allow_local_timeshift' => $allow_local_timeshift,
  331.                 'enable_monitoring' => $enable_monitoring,
  332.                 'descr' => @$_POST['descr'],
  333.                 'tv_genre_id' => @$_POST['tv_genre_id'],
  334.                 'status' => 1,
  335.                 'xmltv_id' => @$_POST['xmltv_id'],
  336.                 'service_id' => trim( $_POST['service_id'] ),
  337.                 'volume_correction' => intval( $_POST['volume_correction'] ),
  338.                 'correct_time' => intval( $_POST['correct_time'] ),
  339.                 'modified' => 'NOW()',
  340.                 'tv_archive_duration' => $_POST['tv_archive_duration'] ) )->insert_id();
  341.  
  342.             foreach ( $links as $link )
  343.             {
  344.  
  345.                 $link['ch_id'] = $ch_id;
  346.  
  347.                 $links_on_server = $link['stream_servers'];
  348.  
  349.                 unset( $link['stream_servers'] );
  350.  
  351.                 $link_id = Mysql::getInstance()->insert( 'ch_links', $link )->insert_id();
  352.  
  353.                 if ( $link_id && $links_on_server )
  354.                 {
  355.                     foreach ( $links_on_server as $streamer_id )
  356.                     {
  357.                         Mysql::getInstance()->insert( 'ch_link_on_streamer', array( 'link_id' => $link_id, 'streamer_id' => $streamer_id ) );
  358.                     }
  359.                 }
  360.             }
  361.  
  362.             if ( $enable_tv_archive )
  363.             {
  364.  
  365.                 if ( !empty( $_POST['flussonic_dvr'] ) )
  366.                 {
  367.                     $archive = new FlussonicTvArchive();
  368.                 }
  369.                 elseif ( !empty( $_POST['wowza_dvr'] ) )
  370.                 {
  371.                     $archive = new WowzaTvArchive();
  372.                 }
  373.                 else
  374.                 {
  375.                     $archive = new TvArchive();
  376.                 }
  377.  
  378.                 $archive->createTasks( $ch_id, $storage_names );
  379.             }
  380.  
  381.             if ( $allow_pvr )
  382.             {
  383.                 RemotePvr::setAllowedStoragesForChannel( $ch_id, $pvr_storage_names );
  384.             }
  385.  
  386.             if ( !empty( $_FILES['logo'] ) )
  387.             {
  388.  
  389.                 if ( $logo = handle_upload_logo( $_FILES['logo'], $ch_id ) )
  390.                 {
  391.                     Mysql::getInstance()->update( 'itv', array( 'logo' => $logo ), array( 'id' => $ch_id ) );
  392.                 }
  393.                 else
  394.                 {
  395.                     $error = _( 'Error: could not save logo' ) . ' <a href="#form">#</a>';
  396.                 }
  397.             }
  398.  
  399.             header( "Location: add_itv.php" );
  400.             exit;
  401.         }
  402.         else
  403.         {
  404.             $error = _( 'Error: all fields are required' ) . ' <a href="#form">#</a>';
  405.         }
  406.     }
  407.  
  408.     if ( @$_GET['update'] && !$error && !empty( $_POST ) )
  409.     {
  410.  
  411.         Admin::checkAccess( AdminAccess::ACCESS_EDIT );
  412.  
  413.         if ( @$_GET['name'] && @$_POST['tv_genre_id'] > 0 )
  414.         {
  415.  
  416.             $ch_id = intval( @$_GET['id'] );
  417.  
  418.             $channel = Itv::getChannelById( $ch_id );
  419.  
  420.             if ( !empty( $channel ) && ( $channel['enable_tv_archive'] != $enable_tv_archive || $channel['wowza_dvr'] != $wowza_dvr || $channel['flussonic_dvr'] != $flussonic_dvr || $channel['tv_archive_duration'] != $_POST['tv_archive_duration'] ) )
  421.             {
  422.  
  423.                 if ( $channel['enable_tv_archive'] )
  424.                 {
  425.  
  426.                     if ( $channel['flussonic_dvr'] )
  427.                     {
  428.                         $archive = new FlussonicTvArchive();
  429.                     }
  430.                     elseif ( $channel['wowza_dvr'] )
  431.                     {
  432.                         $archive = new WowzaTvArchive();
  433.                     }
  434.                     else
  435.                     {
  436.                         $archive = new TvArchive();
  437.                     }
  438.  
  439.                     $archive->deleteTasks( $ch_id );
  440.                 }
  441.             }
  442.  
  443.             Mysql::getInstance()->update( 'itv', array(
  444.                 'name' => $_POST['name'],
  445.                 'cmd' => ( !empty( $_POST['cmd'][0] ) ? $_POST['cmd'][0] : "" ),
  446.                 'cmd_1' => @$_POST['cmd_1'],
  447.                 'cmd_2' => @$_POST['cmd_2'],
  448.                 'cmd_3' => @$_POST['cmd_3'],
  449.                 'mc_cmd' => $mc_cmd,
  450.                 'enable_wowza_load_balancing' => $enable_wowza_load_balancing,
  451.                 'enable_tv_archive' => $enable_tv_archive,
  452.                 'allow_pvr' => $allow_pvr,
  453.                 'allow_local_pvr' => $allow_local_pvr,
  454.                 'allow_local_timeshift' => $allow_local_timeshift,
  455.                 'enable_monitoring' => $enable_monitoring,
  456.                 'wowza_tmp_link' => $wowza_tmp_link,
  457.                 'nginx_secure_link' => $nginx_secure_link,
  458.                 'wowza_dvr' => $wowza_dvr,
  459.                 'flussonic_dvr' => $flussonic_dvr,
  460.                 'use_http_tmp_link' => $use_http_tmp_link,
  461.                 'censored' => $censored,
  462.                 'base_ch' => $base_ch,
  463.                 'bonus_ch' => $bonus_ch,
  464.                 'hd' => $hd,
  465.                 'cost' => $_POST['cost'],
  466.                 'number' => $_POST['number'],
  467.                 'descr' => $_POST['descr'],
  468.                 'tv_genre_id' => $_POST['tv_genre_id'],
  469.                 'xmltv_id' => $_POST['xmltv_id'],
  470.                 'service_id' => trim( $_POST['service_id'] ),
  471.                 'volume_correction' => intval( $_POST['volume_correction'] ),
  472.                 'correct_time' => intval( $_POST['correct_time'] ),
  473.                 'modified' => 'NOW()',
  474.                 'tv_archive_duration' => $_POST['tv_archive_duration'] ), array( 'id' => intval( @$_GET['id'] ) ) );
  475.  
  476.             if ( !$enable_monitoring )
  477.             {
  478.                 Mysql::getInstance()->update( 'itv', array( 'monitoring_status' => 1 ), array( 'id' => intval( @$_GET['id'] ) ) );
  479.             }
  480.  
  481.             $urls = $_POST['cmd'];
  482.             $priorities = $_POST['priority'];
  483.  
  484.             $current_urls = Mysql::getInstance()->from( 'ch_links' )->where( array( 'ch_id' => intval( $_GET['id'] ) ) )->get()->all( 'url' );
  485.             $current_links = Mysql::getInstance()->from( 'ch_links' )->where( array( 'ch_id' => intval( $_GET['id'] ) ) )->get()->all();
  486.  
  487.             $urls_str = "'" . implode( "','", $urls ) . "'";
  488.  
  489.             $need_to_delete_links = Mysql::getInstance()->query( "select * from ch_links where ch_id=" . intval( $_GET['id'] ) . " and url not in (" . $urls_str . ")" )->all( 'id' );
  490.  
  491.             if ( $need_to_delete_links )
  492.             {
  493.                 Mysql::getInstance()->query( "delete from ch_links where id in (" . implode( ",", $need_to_delete_links ) . ")" );
  494.                 Mysql::getInstance()->query( "delete from ch_link_on_streamer where link_id in (" . implode( ",", $need_to_delete_links ) . ")" );
  495.             }
  496.  
  497.             foreach ( $links as $link )
  498.             {
  499.  
  500.                 $link['ch_id'] = ( int )$_GET['id'];
  501.  
  502.                 $links_on_server = $link['stream_servers'];
  503.  
  504.                 unset( $link['stream_servers'] );
  505.  
  506.                 if ( !in_array( $link['url'], $current_urls ) )
  507.                 {
  508.                     $link_id = Mysql::getInstance()->insert( 'ch_links', $link )->insert_id();
  509.  
  510.                     if ( $link_id && $links_on_server )
  511.                     {
  512.                         foreach ( $links_on_server as $streamer_id )
  513.                         {
  514.                             Mysql::getInstance()->insert( 'ch_link_on_streamer', array( 'link_id' => $link_id, 'streamer_id' => $streamer_id ) );
  515.                         }
  516.                     }
  517.                 }
  518.                 else
  519.                 {
  520.  
  521.                     $link_id = Mysql::getInstance()->from( 'ch_links' )->where( array( 'ch_id' => ( int )$_GET['id'], 'url' => $link['url'] ) )->get()->first( 'id' );
  522.  
  523.                     if ( !$link['enable_monitoring'] )
  524.                     {
  525.                         $link['status'] = 1;
  526.                     }
  527.  
  528.                     if ( $link_id )
  529.                     {
  530.  
  531.                         Mysql::getInstance()->use_caching( array( 'ch_links.id=' . intval( $link_id ) ) )->update( 'ch_links', $link, array( 'id' => ( int )$link_id ) );
  532.  
  533.                         $on_streamers = Mysql::getInstance()->from( 'ch_link_on_streamer' )->where( array( 'link_id' => $link_id ) )->get()->all( 'streamer_id' );
  534.  
  535.                         if ( $on_streamers )
  536.                         {
  537.                             $need_to_delete = array_diff( $on_streamers, $links_on_server );
  538.                             $need_to_insert = array_diff( $links_on_server, $on_streamers );
  539.  
  540.                             if ( $need_to_delete )
  541.                             {
  542.                                 Mysql::getInstance()->query( "delete from ch_link_on_streamer where link_id=$link_id and streamer_id in (" . implode( ",", $need_to_delete ) . ")" );
  543.                             }
  544.  
  545.                             if ( $need_to_insert )
  546.                             {
  547.                                 foreach ( $need_to_insert as $streamer_id )
  548.                                 {
  549.                                     Mysql::getInstance()->insert( 'ch_link_on_streamer', array( 'link_id' => $link_id, 'streamer_id' => $streamer_id ) );
  550.                                 }
  551.                             }
  552.  
  553.                         }
  554.                         else
  555.                         {
  556.                             foreach ( $links_on_server as $streamer_id )
  557.                             {
  558.                                 Mysql::getInstance()->insert( 'ch_link_on_streamer', array( 'link_id' => $link_id, 'streamer_id' => $streamer_id ) );
  559.                             }
  560.                         }
  561.                     }
  562.                 }
  563.             }
  564.  
  565.             if ( $enable_tv_archive )
  566.             {
  567.  
  568.                 if ( !empty( $_POST['flussonic_dvr'] ) )
  569.                 {
  570.                     $archive = new FlussonicTvArchive();
  571.                 }
  572.                 elseif ( !empty( $_POST['wowza_dvr'] ) )
  573.                 {
  574.                     $archive = new WowzaTvArchive();
  575.                 }
  576.                 else
  577.                 {
  578.                     $archive = new TvArchive();
  579.                 }
  580.  
  581.                 $archive->createTasks( $ch_id, $storage_names );
  582.             }
  583.  
  584.             if ( $allow_pvr )
  585.             {
  586.                 RemotePvr::setAllowedStoragesForChannel( $ch_id, $pvr_storage_names );
  587.             }
  588.  
  589.             if ( !empty( $_FILES['logo']['name'] ) )
  590.             {
  591.  
  592.                 if ( $logo = handle_upload_logo( $_FILES['logo'], $ch_id ) )
  593.                 {
  594.                     Mysql::getInstance()->update( 'itv', array( 'logo' => $logo ), array( 'id' => $ch_id ) );
  595.                 }
  596.                 else
  597.                 {
  598.                     $error = _( 'Error: could not save logo' ) . ' <a href="#form">#</a>';
  599.                 }
  600.             }
  601.  
  602.             if ( empty( $error ) )
  603.             {
  604.                 header( "Location: add_itv.php?edit=1&id=" . intval( @$_GET['id'] ) . "#form" );
  605.                 exit;
  606.             }
  607.         }
  608.         else
  609.         {
  610.             $error = _( 'Error: all fields are required' ) . ' <a href="#form">#</a>';
  611.         }
  612.     }
  613. }
  614.  
  615. function handle_upload_logo( $file, $ch_id )
  616. {
  617.  
  618.     if ( empty( $file ) )
  619.     {
  620.         return true;
  621.     }
  622.  
  623.     $images = array(
  624.         'image/gif' => 'gif',
  625.         'image/jpeg' => 'jpg',
  626.         'image/png' => 'png' );
  627.  
  628.     if ( !array_key_exists( $file['type'], $images ) )
  629.     {
  630.         return false;
  631.     }
  632.  
  633.     $ext = $images[$file['type']];
  634.  
  635.     $path = realpath( PROJECT_PATH . "/../misc/logos/" );
  636.  
  637.     if ( !$path )
  638.     {
  639.         return false;
  640.     }
  641.  
  642.     $filename = $ch_id . "." . $ext;
  643.  
  644.     $resolutions = array(
  645.         '320' => array( 'height' => 96, 'width' => 96 ),
  646.         '240' => array( 'height' => 72, 'width' => 72 ),
  647.         '160' => array( 'height' => 48, 'width' => 48 ),
  648.         '120' => array( 'height' => 36, 'width' => 36 ) );
  649.  
  650.     umask( 0 );
  651.  
  652.     foreach ( $resolutions as $resolution => $dimension )
  653.     {
  654.  
  655.         $ico_path = $path . "/" . $resolution;
  656.  
  657.         if ( !is_dir( $ico_path ) )
  658.         {
  659.             mkdir( $ico_path, 0777 );
  660.         }
  661.  
  662.         $fullpath = $ico_path . "/" . $filename;
  663.  
  664.         try
  665.         {
  666.             $icon = new Imagick( $file['tmp_name'] );
  667.         }
  668.         catch ( ImagickException $e )
  669.         {
  670.             //$e->getMessage();
  671.             return false;
  672.         }
  673.  
  674.         if ( !$icon->resizeImage( $dimension['width'], $dimension['height'], Imagick::FILTER_LANCZOS, 1 ) )
  675.         {
  676.             return false;
  677.         }
  678.  
  679.         if ( !$icon->writeImage( $fullpath ) )
  680.         {
  681.             return false;
  682.         }
  683.  
  684.         $icon->destroy();
  685.  
  686.         chmod( $fullpath, 0666 );
  687.     }
  688.  
  689.     unlink( $file['tmp_name'] );
  690.  
  691.     return $filename;
  692. }
  693.  
  694. function check_number( $num )
  695. {
  696.  
  697.     $total_items = Mysql::getInstance()->from( 'itv' )->count()->where( array( 'number' => intval( $num ) ) )->get()->counter();
  698.  
  699.     if ( $total_items > 0 )
  700.     {
  701.         return 0;
  702.     }
  703.     else
  704.     {
  705.         return 1;
  706.     }
  707. }
  708.  
  709. function get_screen_name( $addr )
  710. {
  711.     preg_match( "/(\S+)\s(\S+):\/\/(\d+).(\d+).(\d+).(\d+):(\d+)/", $addr, $tmp_arr );
  712.     $img_str = '/iptv/mpg/' . $tmp_arr[6] . '_' . $tmp_arr[7] . '.mpg';
  713.     return $img_str;
  714. }
  715.  
  716. $tv_archive = new TvArchive();
  717. $storages = Mysql::getInstance()->from( 'storages' )->where( array(
  718.     'status' => 1,
  719.     'for_records' => 1,
  720.     'wowza_server' => 0 ) )->get()->all();
  721.  
  722. $stream_servers = StreamServer::getAll();
  723.  
  724. $selected_storages = $selected_pvr_storages = array();
  725.  
  726. if ( !empty( $_GET['id'] ) )
  727. {
  728.  
  729.     $tasks = TvArchive::getTasksByChannelId( ( int )$_GET['id'] );
  730.  
  731.     if ( !empty( $tasks ) )
  732.     {
  733.         $selected_storages = array_map( function ( $storage )
  734.         {
  735.             return $storage['storage_name']; }
  736.         , $tasks );
  737.     }
  738.  
  739.     $selected_pvr_storages = array_keys( RemotePvr::getStoragesForChannel( ( int )$_GET['id'] ) );
  740. }
  741.  
  742. ?>
  743. <html>
  744. <head>
  745. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  746. <style type="text/css">
  747.  
  748. body {
  749.     font-family: Arial, Helvetica, sans-serif;
  750.     font-weight: bold;
  751. }
  752. td {
  753.     font-family: Arial, Helvetica, sans-serif;
  754.     font-size: 14px;
  755.     text-decoration: none;
  756.     color: #000000;
  757. }
  758. .list{
  759.     border-width: 1px;
  760.     border-style: solid;
  761.     border-color: #E5E5E5;
  762. }
  763. a{
  764.     color:#0000FF;
  765.     font-weight: bold;
  766.     text-decoration:none;
  767. }
  768. a:link,a:visited {
  769.     color:#5588FF;
  770.     font-weight: bold;
  771. }
  772. a:hover{
  773.     color:#0000FF;
  774.     font-weight: bold;
  775.     text-decoration:underline;
  776. }
  777.  
  778. .shift_ch{
  779.     cursor:pointer
  780. }
  781.  
  782. .last_modified{
  783.     border-left-color: #F00;
  784. }
  785. </style>
  786. <title>
  787. <?=
  788.  
  789. _( 'IPTV channels' )
  790.  
  791. ?>
  792. </title>
  793. <script type="text/javascript" src="js.js"></script>
  794. <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
  795. <script type="text/javascript" src="js/jquery.tmpl.min.js"></script>
  796. <script type="text/javascript" src="js/jquery.cookies.2.2.0.js"></script>
  797.  
  798. <script id="link_item_tmpl" type="text/x-jquery-tmpl">
  799.     <div id="link_${idx}" class="link" link-id="${idx}">
  800.         <input name="cmd[${idx}]" size="50" type="text" value="${url}"
  801.                style="border-style:solid;border-color: {{if status==1}}#66A566{{else}}#F88787{{/if}}"><br>
  802.         <table>
  803.             <tr>
  804.                 <td><?=
  805.  
  806. _( 'priority' )
  807.  
  808. ?>:</td>
  809.                 <td><input type="text" name="priority[${idx}]" size="3" value="${priority}"></td>
  810.             </tr>
  811.             <tr>
  812.                 <td><?=
  813.  
  814. _( 'filter' )
  815.  
  816. ?>:</td>
  817.                 <td>
  818.                     <input type="text" name="user_agent_filter[${idx}]" value="${user_agent_filter}">
  819.                 </td>
  820.             </tr>
  821.             <tr>
  822.                 <td><?=
  823.  
  824. _( 'Temporary HTTP URL' )
  825.  
  826. ?>:</td>
  827.                 <td>
  828.                     <input type="checkbox" class="use_http_tmp_link" name="use_http_tmp_link[${idx}]" value="1" {{if use_http_tmp_link==="1"}}checked{{/if}}>
  829.                 </td>
  830.             </tr>
  831.             <tr style="display:{{if use_http_tmp_link==1}} {{else}}none{{/if}}; background-color:#f8f8f8">
  832.                 <td colspan="2">
  833.                     <table width="100%">
  834.                         <tr>
  835.                             <td>&nbsp;&nbsp;<?=
  836.  
  837. _( 'WOWZA support' )
  838.  
  839. ?>:</td>
  840.                             <td width="40%"><input type="checkbox" name="wowza_tmp_link[${idx}]" value="1" {{if wowza_tmp_link==="1"}}checked{{/if}}></td>
  841.                         </tr>
  842.                         <tr>
  843.                             <td>&nbsp;&nbsp;<?=
  844.  
  845. _( 'Flussonic support' )
  846.  
  847. ?>:</td>
  848.                             <td width="40%"><input type="checkbox" name="flussonic_tmp_link[${idx}]" value="1" {{if flussonic_tmp_link==="1"}}checked{{/if}}></td>
  849.                         </tr>
  850.                         <tr>
  851.                             <td>&nbsp;&nbsp;<?=
  852.  
  853. _( 'Xtream Codes IPTV Pro Support' )
  854.  
  855. ?>:</td>
  856.                             <td width="40%"><input type="checkbox" name="xtream_codes_support[${idx}]" value="1" {{if xtream_codes_support==="1"}}checked{{/if}}></td>
  857.                         </tr>
  858.                         <tr>
  859.                             <td>&nbsp;&nbsp;<?=
  860.  
  861. _( 'NGINX secure link' )
  862.  
  863. ?>:</td>
  864.                             <td><input type="checkbox" name="nginx_secure_link[${idx}]" value="1" {{if nginx_secure_link==="1"}}checked{{/if}}></td>
  865.                         </tr>
  866.                     </table>
  867.                 </td>
  868.             </tr>
  869.             <tr>
  870.                 <td colspan="2">
  871.                     <?=
  872.  
  873. _( 'Enable monitoring' )
  874.  
  875. ?>:
  876.                     <input type="checkbox" class="enable_monitoring"  name="enable_monitoring[${idx}]" value="1" {{if enable_monitoring==="1"}}checked{{/if}}>
  877.                     <span style="display:{{if use_load_balancing==1 && enable_monitoring==1}} {{else}}none{{/if}}">&nbsp;&nbsp;<?=
  878.  
  879. _( 'Balancer monitoring' )
  880.  
  881. ?>:<input type="checkbox" name="enable_balancer_monitoring[${idx}]" value="1" {{if enable_balancer_monitoring==="1"}}checked{{/if}}></span>
  882.                 </td>
  883.             </tr>
  884.             <tr class="monitoring_url_block" style="display:{{if enable_monitoring==1}} {{else}}none{{/if}}; background-color:#f8f8f8">
  885.                 <td colspan="2">
  886.                     <?=
  887.  
  888. _( 'Channel URL for monitoring' )
  889.  
  890. ?>:<br>
  891.                     <input type="text" size="48" name="monitoring_url[${idx}]" value="${monitoring_url}">
  892.                 </td>
  893.             </tr>
  894.             <tr>
  895.                 <td>load balancing:</td>
  896.                 <td>
  897.                     <input type="checkbox" class="use_load_balancing" name="use_load_balancing[${idx}]" value="1" {{if use_load_balancing==="1"}}checked{{/if}}>
  898.                 </td>
  899.             </tr>
  900.             <tr style="display:{{if use_load_balancing==1}} {{else}}none{{/if}}; background-color:#f8f8f8">
  901.                 <td colspan="2">
  902.                     <table width="100%">
  903.                         {{each(i, stream_server) stream_servers}}
  904.                         <tr>
  905.                             <td width="50%" style="color: {{if stream_server.monitoring_status==1 && stream_server.selected==1 && enable_monitoring==1 && enable_balancer_monitoring==1}}#079107{{else stream_server.monitoring_status==0 && stream_server.selected==1 && enable_monitoring==1 && enable_balancer_monitoring==1}}#D31919{{/if}}">${stream_server.name}:</td>
  906.                             <td width="50%">
  907.                                 <input type="checkbox" class="stream_server" name="stream_server[${idx}][]" value="${stream_server.id}" {{if stream_server.selected==1}}checked{{/if}}/>
  908.                             </td>
  909.                         </tr>
  910.                         {{/each}}
  911.                     </table>
  912.                 </td>
  913.             </tr>
  914.         </table>
  915.  
  916.         <button href="javascript://" class="add_ch_url"><?=
  917.  
  918. _( 'add new link' )
  919.  
  920. ?></button>
  921.         {{if idx>0}}
  922.         <button href="javascript://" class="del_ch_url"><?=
  923.  
  924. _( 'delete' )
  925.  
  926. ?></button>
  927.         {{/if}}
  928.         <hr>
  929.     </div>
  930. </script>
  931.  
  932. <script type="text/javascript">
  933.  
  934.     jQuery.fn.sortElements = (function(){
  935.  
  936.         var sort = [].sort;
  937.  
  938.         return function(comparator, getSortable) {
  939.  
  940.             getSortable = getSortable || function(){return this;};
  941.  
  942.             var placements = this.map(function(){
  943.  
  944.                 var sortElement = getSortable.call(this),
  945.                     parentNode = sortElement.parentNode,
  946.  
  947.                 // Since the element itself will change position, we have
  948.                 // to have some way of storing its original position in
  949.                 // the DOM. The easiest way is to have a 'flag' node:
  950.                     nextSibling = parentNode.insertBefore(
  951.                         document.createTextNode(''),
  952.                         sortElement.nextSibling
  953.                     );
  954.  
  955.                 return function() {
  956.  
  957.                     if (parentNode === this) {
  958.                         throw new Error(
  959.                             "You can't sort elements if any one is a descendant of another."
  960.                         );
  961.                     }
  962.  
  963.                     // Insert before flag:
  964.                     parentNode.insertBefore(this, nextSibling);
  965.                     // Remove flag:
  966.                     parentNode.removeChild(nextSibling);
  967.  
  968.                 };
  969.  
  970.             });
  971.  
  972.             return sort.call(this, comparator).each(function(i){
  973.                 placements[i].call(getSortable.call(this));
  974.             });
  975.         };
  976.  
  977.     })();
  978.  
  979.     $(function(){
  980.  
  981.         $('.add_ch_url').live('click', function(event){
  982.  
  983.             var idx = $('.links_block>div').length;
  984.  
  985.             var link = {"url":"","priority":0,"status":1,"use_http_tmp_link":0,"wowza_tmp_link":0,"flussonic_tmp_link":0,"nginx_secure_link":0,"user_agent_filter":"","idx":idx,"monitoring_url":"", "use_load_balancing":0,"enable_monitoring":0,"enable_balancer_monitoring":0};
  986.  
  987.             $("#link_item_tmpl").tmpl(link).appendTo('.links_block');
  988.  
  989.             return false;
  990.         });
  991.  
  992.         $('.del_ch_url').live('click', function(event){
  993.             if (confirm("<?=
  994.  
  995. htmlspecialchars( _( 'Do you really want to delete this record?' ), ENT_QUOTES )
  996.  
  997. ?>")){
  998.                 $(this).closest('div').remove();
  999.             }
  1000.             return false;
  1001.         });
  1002.  
  1003.         if (!links){
  1004.             links = [];
  1005.         }
  1006.  
  1007.         if (links.length == 0){
  1008.             links = [{"url":"","priority":0,"status":1,"use_http_tmp_link":0,"wowza_tmp_link":0,"flussonic_tmp_link":0,"nginx_secure_link":0,"user_agent_filter":"","monitoring_url":"","use_load_balancing":0,"enable_monitoring":0,"enable_balancer_monitoring":0}];
  1009.         }
  1010.  
  1011.         links = links.map(function(link, idx){
  1012.             link['idx'] = idx;
  1013.             return link;
  1014.         });
  1015.  
  1016.         $("#link_item_tmpl").tmpl(links).appendTo('.links_block');
  1017.  
  1018.         $('.use_http_tmp_link').live('click', function(event){
  1019.             if ($(this).attr('checked')){
  1020.                 $(this).parent().parent().next().show();
  1021.             }else{
  1022.                 $(this).parent().parent().next().hide();
  1023.             }
  1024.         });
  1025.  
  1026.         $('.use_load_balancing').live('click', function(event){
  1027.             if ($(this).attr('checked')){
  1028.  
  1029.                 $(this).parent().parent().next().show();
  1030.  
  1031.                 if ($('#link_'+$(this).parents('.link').attr('link-id')).find('.enable_monitoring').attr('checked')){
  1032.                     $(this).parent().parent().prev().prev().children().children('span').show();
  1033.                 }
  1034.             }else{
  1035.                 $(this).parent().parent().next().hide();
  1036.                 $(this).parent().parent().prev().prev().children().children('span').hide();
  1037.             }
  1038.         });
  1039.  
  1040.         $('.enable_monitoring').live('click', function(event){
  1041.             if ($(this).attr('checked')){
  1042.                 $(this).parent().parent().next().show();
  1043.                 if ($('#link_'+$(this).parents('.link').attr('link-id')).find('.use_load_balancing').attr('checked')){
  1044.                     $(this).next().show();
  1045.                 }
  1046.             }else{
  1047.                 $(this).parent().parent().next().hide();
  1048.                 $(this).next().hide();
  1049.             }
  1050.         });
  1051.  
  1052.         var table = $('.item_list');
  1053.  
  1054.         $('.item_list th')
  1055.             .each(function(){
  1056.  
  1057.                 var th = $(this),
  1058.                     thIndex = th.index(),
  1059.                     inverse = false;
  1060.  
  1061.                 if (thIndex == 1){
  1062.                     inverse = true;
  1063.                 }
  1064.  
  1065.                 th.click(function(eventObject){
  1066.  
  1067.                     //console.log(eventObject);
  1068.  
  1069.                     if (eventObject.hasOwnProperty("inverse")){
  1070.                         inverse = !eventObject.inverse;
  1071.                     }
  1072.  
  1073.                     table.find('td.list').filter(function(){
  1074.  
  1075.                         return $(this).index() === thIndex;
  1076.  
  1077.                     }).sortElements(function(a, b){
  1078.  
  1079.                         // todo: sort numbers
  1080.                         if (th.hasClass('number_row')){
  1081.                             return parseInt($.text([a]), 10) > parseInt($.text([b]), 10) ?
  1082.                                 inverse ? -1 : 1
  1083.                                 : inverse ? 1 : -1
  1084.                         }else{
  1085.                             return $.text([a]) > $.text([b]) ?
  1086.                                 inverse ? -1 : 1
  1087.                                 : inverse ? 1 : -1
  1088.                         }
  1089.  
  1090.                     }, function(){
  1091.  
  1092.                         // parentNode is the element we want to move
  1093.                         return this.parentNode;
  1094.  
  1095.                     });
  1096.  
  1097.                     inverse = !inverse;
  1098.  
  1099.                     $.cookies.set('sort_by_row', $(this).index());
  1100.                     $.cookies.set('sort_inverse', inverse);
  1101.  
  1102.                     if (sort_by_row == $(this).index() && inverse == true){
  1103.                         $('.shift_ch').show();
  1104.                     }else{
  1105.                         $('.shift_ch').hide();
  1106.                     }
  1107.  
  1108.                     $('.order').remove();
  1109.  
  1110.                     th.append(' <span class="order">' + (inverse ? '&darr;' : '&uarr;') + '</span>');
  1111.                 });
  1112.             });
  1113.  
  1114.         $('.add_btn').click(function(){
  1115.             var new_position = $('.itv_form').offset();
  1116.             window.scrollTo(new_position.left, new_position.top);
  1117.             return false;
  1118.         });
  1119.  
  1120.         var sort_by_row = $.cookies.get('sort_by_row');
  1121.         var sort_inverse = $.cookies.get('sort_inverse');
  1122.  
  1123.         if (sort_by_row !== null){
  1124.             $('.item_list th:eq('+sort_by_row+')').trigger(jQuery.Event("click", { inverse: $.cookies.get('sort_inverse') }));
  1125.         }else{
  1126.             sort_by_row = 1;
  1127.             sort_inverse = true;
  1128.         }
  1129.  
  1130.         if (sort_by_row == 1 && sort_inverse == true){
  1131.             $('.shift_ch').show();
  1132.         }else{
  1133.             $('.shift_ch').hide();
  1134.         }
  1135.  
  1136.         $('.add_btn').click(function(){
  1137.             $('#form_').get(0).reset();
  1138.             document.location.href = 'add_itv.php#form';
  1139.         });
  1140.  
  1141.         $('.shift_ch').click(function(){
  1142.  
  1143.             var direction = $(this).attr('data-direction');
  1144.             var from_num  = $(this).parent().parent().find('.number').html();
  1145.  
  1146.             var number_error = $('.number').toArray().some(function(dom_obj){
  1147.                 return $(dom_obj).html() == parseInt(from_num, 10) + parseInt(direction, 10);
  1148.             });
  1149.  
  1150.             if (direction < 0 && number_error){
  1151.                 alert('<?=
  1152.  
  1153. htmlspecialchars( _( 'Channel with same number already exists!' ), ENT_QUOTES )
  1154.  
  1155. ?>');
  1156.             }else{
  1157.                 if (confirm('<?=
  1158.  
  1159. htmlspecialchars( _( 'Shift channel list?' ), ENT_QUOTES )
  1160.  
  1161. ?>')){
  1162.                     window.location = 'add_itv.php?shift='+direction+'&from_num='+from_num;
  1163.                 }
  1164.             }
  1165.         });
  1166.  
  1167.         $('#enable_tv_archive').click(function(){
  1168.             if ($(this).attr('checked')){
  1169.                 $(this).next().show();
  1170.                 $(this).next().next().show();
  1171.                 $(this).next().next().next().show();
  1172.             }else{
  1173.                 $(this).next().hide();
  1174.                 $(this).next().next().hide();
  1175.                 $(this).next().next().next().hide();
  1176.             }
  1177.         });
  1178.  
  1179.         $('.flussonic_dvr').click(function(){
  1180.             if ($(this).attr('checked')){
  1181.                 $('.flussonic_stream_server').removeAttr('disabled');
  1182.                 $('.generic_stream_server').attr('disabled', 'disabled');
  1183.                 $('.wowza_stream_server').attr('disabled', 'disabled');
  1184.                 $('.wowza_dvr').attr('disabled', 'disabled');
  1185.             }else{
  1186.                 $('.flussonic_stream_server').attr('disabled', 'disabled');
  1187.                 $('.generic_stream_server').removeAttr('disabled');
  1188.                 $('.wowza_dvr').removeAttr('disabled');
  1189.             }
  1190.         });
  1191.  
  1192.         $('.wowza_dvr').click(function(){
  1193.             if ($(this).attr('checked')){
  1194.                 $('.wowza_stream_server').removeAttr('disabled');
  1195.                 $('.generic_stream_server').attr('disabled', 'disabled');
  1196.                 $('.flussonic_stream_server').attr('disabled', 'disabled');
  1197.                 $('.flussonic_dvr').attr('disabled', 'disabled');
  1198.             }else{
  1199.                 $('.wowza_stream_server').attr('disabled', 'disabled');
  1200.                 $('.generic_stream_server').removeAttr('disabled');
  1201.                 $('.flussonic_dvr').removeAttr('disabled');
  1202.             }
  1203.         })
  1204.     });
  1205. </script>
  1206. </head>
  1207. <body>
  1208. <table align="center" border="0" cellpadding="0" cellspacing="0">
  1209. <tr>
  1210.     <td align="center" valign="middle" width="100%" bgcolor="#88BBFF">
  1211.     <font size="5px" color="White"><b>&nbsp;<?=
  1212.  
  1213. _( 'IPTV channels' )
  1214.  
  1215. ?>&nbsp;</b></font>
  1216.     </td>
  1217. </tr>
  1218. <tr>
  1219.     <td width="100%" align="left" valign="bottom">
  1220.         <a href="index.php"><< <?=
  1221.  
  1222. _( 'Back' )
  1223.  
  1224. ?></a> | <a href="#" class="add_btn"><?=
  1225.  
  1226. _( 'Add' )
  1227.  
  1228. ?></a> | <a href="?restart_all_archives=1"><?=
  1229.  
  1230. _( 'Restart all TV archives' )
  1231.  
  1232. ?></a>
  1233.     </td>
  1234. </tr>
  1235. <tr>
  1236.     <td align="center">
  1237.     <font color="Red">
  1238.     <strong>
  1239.     <?
  1240.  
  1241. echo $error
  1242.  
  1243. ?>
  1244.     </strong>
  1245.     </font>
  1246.     <br>
  1247.     <br>
  1248.     </td>
  1249. </tr>
  1250. <tr>
  1251. <td align="center">
  1252.  
  1253. <?
  1254.  
  1255. $last_modified_id = Mysql::getInstance()->from( 'itv' )->where( array( 'modified!=' => '' ) )->orderby( 'modified', 'DESC' )->limit( 1, 0 )->get()->first( 'id' );
  1256.  
  1257. $all_channels = Mysql::getInstance()->query( "select itv.*, tv_genre.title as genres_name, media_claims.media_type, media_claims.media_id, media_claims.sound_counter, media_claims.video_counter, media_claims.no_epg, media_claims.wrong_epg from itv left join media_claims on itv.id=media_claims.media_id and media_claims.media_type='itv' left join tv_genre on itv.tv_genre_id=tv_genre.id group by itv.id order by number" );
  1258.  
  1259. echo "<center><table class='list item_list' cellpadding='3' cellspacing='0'>";
  1260. echo "<tr>";
  1261. echo "<th class='list number_row'><b>id</b></th>";
  1262. echo "<th class='list number_row'><b>" . _( 'Number' ) . "</b> <span class='order'>&darr;</span></th>";
  1263. echo "<th class='list'><b>" . _( 'Service code' ) . "</b></th>";
  1264. echo "<th class='list'><b>" . _( 'Name' ) . "</b></th>";
  1265. echo "<th class='list'><b>" . _( 'URL' ) . "</b></th>";
  1266. echo "<th class='list'><b>" . _( 'xmltv id' ) . "</b></th>";
  1267. echo "<th class='list'><b>" . _( 'Genre' ) . "</b></th>";
  1268. echo "<th class='list'><b>" . _( 'Archive' ) . "</b></th>";
  1269. echo "<th class='list'><b>" . _( 'Volume correction' ) . "</b></th>";
  1270. echo "<th class='list'><b>" . _( 'Claims about<br>audio/video/epg' ) . "</b></th>\n";
  1271. echo "<th class='list'><b>&nbsp;</b></th>";
  1272. echo "</tr>";
  1273. while ( $arr = $all_channels->next() )
  1274. {
  1275.     echo "<tr ";
  1276.     if ( $arr['bonus_ch'] == 1 )
  1277.     {
  1278.         echo 'bgcolor="#ffffec"';
  1279.     }
  1280.     else
  1281.     {
  1282.         if ( $arr['base_ch'] == 1 )
  1283.         {
  1284.  
  1285.         }
  1286.         else
  1287.         {
  1288.             if ( strlen( $arr['service_id'] ) < 5 )
  1289.             {
  1290.                 echo 'bgcolor="#f7f7f7"';
  1291.             }
  1292.             else
  1293.             {
  1294.                 echo 'bgcolor="#ffecec"';
  1295.             }
  1296.         }
  1297.     }
  1298.  
  1299.     echo ">";
  1300.     echo "<td class='list";
  1301.     if ( $last_modified_id == $arr['id'] )
  1302.     {
  1303.         echo ' last_modified';
  1304.     }
  1305.     echo "' height='36'>" . $arr['id'] . "</td>";
  1306.     echo "<td class='list'><span class='number'>" . $arr['number'] . "</span> <div style='float:right'><span class='shift_ch' data-direction='1'>&darr;</span> <span class='shift_ch' data-direction='-1'>&uarr;</span></div></td>";
  1307.     echo "<td class='list'>" . $arr['service_id'] . "</td>";
  1308.     echo "<td class='list'>";
  1309.  
  1310.     echo '<table cellpadding="0" cellspacing="0">';
  1311.     echo '<tr>';
  1312.     echo '<td>';
  1313.     if ( $ch_logo = Itv::getLogoUriById( intval( $arr['id'] ), 120 ) )
  1314.     {
  1315.         echo '<img src ="' . $ch_logo . '"/ >';
  1316.     }
  1317.     echo '</td>';
  1318.     echo '<td>';
  1319.     echo '<b style="color:' . get_color( $arr ) . '" title="' . get_hint( $arr ) . '">' . $arr['name'] . '</b>';
  1320.     echo '</td>';
  1321.     echo '</tr>';
  1322.     echo '</table>';
  1323.  
  1324.     echo "</td>";
  1325.     echo "<td class='list'>" . $arr['cmd'] . "</td>";
  1326.     echo "<td class='list'>" . $arr['xmltv_id'] . "</td>";
  1327.     echo "<td class='list'>" . ( !empty( $arr['genres_name'] ) ? _( $arr['genres_name'] ) : '----' ) . "</td>";
  1328.     echo "<td class='list' align='center'>" . ( $arr['enable_tv_archive'] == 1 ? '&bull;' : '' ) . "</td>";
  1329.     echo "<td class='list'>" . $arr['volume_correction'] . "</td>";
  1330.  
  1331.     echo "<td class='list' align='center'>\n";
  1332.     if ( Admin::isActionAllowed() )
  1333.     {
  1334.         echo "<a href='#' onclick='if(confirm(\"" . _( 'Do you really want to reset claims counter?' ) . "\")){document.location=\"claims.php?reset=1&media_id=" . $arr['media_id'] . "&media_type=" . $arr['media_type'] . "\"}'>";
  1335.     }
  1336.     echo "<span style='color:red;font-weight:bold'>" . $arr['video_counter'] . " / " . $arr['sound_counter'] . " / " . $arr['no_epg'], " / " . $arr['wrong_epg'] . "</span>";
  1337.     if ( Admin::isActionAllowed() )
  1338.     {
  1339.         echo "</a>";
  1340.     }
  1341.     echo "</td>\n";
  1342.  
  1343.     echo "<td class='list' nowrap><a href='?edit=1&id=" . $arr['id'] . "#form'>edit</a>&nbsp;&nbsp;";
  1344.     //echo "<a href='?del=1&id=".$arr['id']."' >del</a>&nbsp;&nbsp;";
  1345.     echo "<a href='#' onclick='if(confirm(\"" . htmlspecialchars( _( 'Do you really want to delete this record?' ), ENT_QUOTES ) . "\")){document.location=\"add_itv.php?del=1&id=" . $arr['id'] . "&letter=" . @$_GET['letter'] . "&search=" . @$_GET['search'] . "\"}'>del</a>&nbsp;&nbsp;\n";
  1346.     if ( $arr['status'] )
  1347.     {
  1348.         echo "<a href='?status=0&id=" . $arr['id'] . "'><font color='Green'>on</font></a>&nbsp;&nbsp;";
  1349.     }
  1350.     else
  1351.     {
  1352.         echo "<a href='?status=1&id=" . $arr['id'] . "'><font color='Red'>off</font></a>&nbsp;&nbsp;";
  1353.     }
  1354.     echo "<a href='add_epg.php?id=" . $arr['id'] . "'>EPG</a>&nbsp;&nbsp;</td>";
  1355.     echo "</tr>";
  1356. }
  1357. echo "</table></center>";
  1358.  
  1359. if ( @$_GET['edit'] )
  1360. {
  1361.  
  1362.     $arr = Itv::getById( intval( @$_GET['id'] ) );
  1363.  
  1364.     if ( !empty( $arr ) )
  1365.     {
  1366.  
  1367.         $name = $arr['name'];
  1368.         $number = $arr['number'];
  1369.         $cmd = $arr['cmd'];
  1370.         $mc_cmd = $arr['mc_cmd'];
  1371.         $tv_genre_id = $arr['tv_genre_id'];
  1372.         $descr = $arr['descr'];
  1373.         $status = $arr['status'];
  1374.         $status = $arr['status'];
  1375.         $censored = $arr['censored'];
  1376.         $base_ch = $arr['base_ch'];
  1377.         $bonus_ch = $arr['bonus_ch'];
  1378.         $cost = $arr['cost'];
  1379.         $hd = $arr['hd'];
  1380.         $xmltv_id = $arr['xmltv_id'];
  1381.         $service_id = $arr['service_id'];
  1382.         $volume_correction = $arr['volume_correction'];
  1383.         $correct_time = $arr['correct_time'];
  1384.         $use_http_tmp_link = $arr['use_http_tmp_link'];
  1385.         $wowza_tmp_link = $arr['wowza_tmp_link'];
  1386.         $wowza_dvr = $arr['wowza_dvr'];
  1387.         $flussonic_dvr = $arr['flussonic_dvr'];
  1388.         $enable_tv_archive = $arr['enable_tv_archive'];
  1389.         $tv_archive_duration = $arr['tv_archive_duration'];
  1390.         $allow_pvr = $arr['allow_pvr'];
  1391.         $allow_local_pvr = $arr['allow_local_pvr'];
  1392.         $allow_local_timeshift = $arr['allow_local_timeshift'];
  1393.         $enable_monitoring = $arr['enable_monitoring'];
  1394.         $monitoring_url = $arr['monitoring_url'];
  1395.         $enable_wowza_load_balancing = $arr['enable_wowza_load_balancing'];
  1396.         $logo = $arr['logo'];
  1397.  
  1398.         if ( $use_http_tmp_link )
  1399.         {
  1400.             $checked_http_tmp_link = 'checked';
  1401.         }
  1402.  
  1403.         if ( $wowza_tmp_link )
  1404.         {
  1405.             $checked_wowza_tmp_link = 'checked';
  1406.         }
  1407.  
  1408.         if ( $wowza_dvr )
  1409.         {
  1410.             $checked_wowza_dvr = 'checked';
  1411.         }
  1412.  
  1413.         if ( $flussonic_dvr )
  1414.         {
  1415.             $checked_flussonic_dvr = 'checked';
  1416.         }
  1417.  
  1418.         if ( $enable_tv_archive )
  1419.         {
  1420.             $checked_enable_tv_archive = 'checked';
  1421.         }
  1422.  
  1423.         if ( $allow_pvr )
  1424.         {
  1425.             $checked_allow_pvr = 'checked';
  1426.         }
  1427.  
  1428.         if ( $allow_local_pvr )
  1429.         {
  1430.             $checked_allow_local_pvr = 'checked';
  1431.         }
  1432.         else
  1433.         {
  1434.             $checked_allow_local_pvr = '';
  1435.         }
  1436.  
  1437.         if ( $allow_local_timeshift )
  1438.         {
  1439.             $checked_allow_local_timeshift = 'checked';
  1440.         }
  1441.         else
  1442.         {
  1443.             $checked_allow_local_timeshift = '';
  1444.         }
  1445.  
  1446.         if ( $enable_monitoring )
  1447.         {
  1448.             $checked_enable_monitoring = 'checked';
  1449.         }
  1450.  
  1451.         if ( $enable_wowza_load_balancing )
  1452.         {
  1453.             $checked_wowza_load_balancing = 'checked';
  1454.         }
  1455.  
  1456.         if ( $censored )
  1457.         {
  1458.             $checked = 'checked';
  1459.         }
  1460.         if ( $base_ch )
  1461.         {
  1462.             $checked_base = 'checked';
  1463.         }
  1464.         if ( $bonus_ch )
  1465.         {
  1466.             $checked_bonus = 'checked';
  1467.         }
  1468.         if ( $hd )
  1469.         {
  1470.             $checked_hd = 'checked';
  1471.         }
  1472.  
  1473.         $stream_servers = StreamServer::getAll();
  1474.  
  1475.         $links = Mysql::getInstance()->from( 'ch_links' )->where( array( 'ch_id' => ( int )$arr['id'] ) )->orderby( 'priority' )->get()->all();
  1476.  
  1477.         $links = array_map( function ( $link )use ( $stream_servers )
  1478.         {
  1479.  
  1480.             $streamers_map = StreamServer::getStreamersIdMapForLink( $link['id'] ); $link['stream_servers'] = array_map( function ( $server )use ( $streamers_map )
  1481.             {
  1482.  
  1483.                 if ( !empty( $streamers_map[$server['id']] ) )
  1484.                 {
  1485.                     $server['selected'] = 1; $server['monitoring_status'] = $streamers_map[$server['id']]['monitoring_status']; }
  1486.             else
  1487.             {
  1488.                 $server['selected'] = 0; $server['monitoring_status'] = 0; }
  1489.  
  1490.             return $server; }
  1491.         , $stream_servers ); return $link; }
  1492.     , $links );
  1493. }
  1494. }
  1495. else if ( !empty( $_POST ) )
  1496. {
  1497. $name = @$_POST['name'];
  1498. $number = @$_POST['number'];
  1499. $cmd = @$_POST['cmd'];
  1500. $mc_cmd = @$_POST['mc_cmd'];
  1501. $tv_genre_id = @$_POST['tv_genre_id'];
  1502. $descr = @$_POST['descr'];
  1503. $cost = @$_POST['cost'];
  1504. $xmltv_id = @$_POST['xmltv_id'];
  1505. $service_id = @$_POST['service_id'];
  1506. $volume_correction = @$_POST['volume_correction'];
  1507. $correct_time = @$_POST['correct_time'];
  1508. $monitoring_url = @$_POST['monitoring_url'];
  1509. $tv_archive_duration = @$_POST['tv_archive_duration'];
  1510.  
  1511. if ( @$_POST['use_http_tmp_link'] )
  1512. {
  1513.     $checked_http_tmp_link = 'checked';
  1514. }
  1515.  
  1516. if ( @$_POST['wowza_tmp_link'] )
  1517. {
  1518.     $checked_wowza_tmp_link = 'checked';
  1519. }
  1520.  
  1521. if ( @$_POST['wowza_dvr'] )
  1522. {
  1523.     $checked_wowza_dvr = 'checked';
  1524. }
  1525.  
  1526. if ( @$_POST['flussonic_dvr'] )
  1527. {
  1528.     $checked_flussonic_dvr = 'checked';
  1529. }
  1530.  
  1531. if ( @$_POST['enable_tv_archive'] )
  1532. {
  1533.     $checked_enable_tv_archive = 'checked';
  1534. }
  1535.  
  1536. if ( @$_POST['allow_local_pvr'] )
  1537. {
  1538.     $checked_allow_local_pvr = 'checked';
  1539. }
  1540. else
  1541. {
  1542.     $checked_allow_local_pvr = '';
  1543. }
  1544.  
  1545. if ( @$_POST['allow_local_timeshift'] )
  1546. {
  1547.     $checked_allow_local_timeshift = 'checked';
  1548. }
  1549. else
  1550. {
  1551.     $checked_allow_local_timeshift = '';
  1552. }
  1553.  
  1554. if ( @$_POST['enable_monitoring'] )
  1555. {
  1556.     $checked_enable_monitoring = 'checked';
  1557. }
  1558.  
  1559. if ( @$_POST['enable_wowza_load_balancing'] )
  1560. {
  1561.     $checked_wowza_load_balancing = 'checked';
  1562. }
  1563.  
  1564. if ( @$_POST['censored'] )
  1565. {
  1566.     $checked = 'checked';
  1567. }
  1568.  
  1569. if ( @$_POST['base_ch'] )
  1570. {
  1571.     $checked_base = 'checked';
  1572. }
  1573.  
  1574. if ( @$_POST['bonus_ch'] )
  1575. {
  1576.     $checked_bonus = 'checked';
  1577. }
  1578.  
  1579. if ( @$_POST['hd'] )
  1580. {
  1581.     $checked_hd = 'checked';
  1582. }
  1583. }
  1584.  
  1585. function get_genres()
  1586. {
  1587.  
  1588. global $tv_genre_id;
  1589.  
  1590. $genres = Mysql::getInstance()->from( 'tv_genre' )->get()->all();
  1591.  
  1592. $option = '';
  1593.  
  1594. foreach ( $genres as $arr )
  1595. {
  1596.     $selected = '';
  1597.  
  1598.     if ( $tv_genre_id == $arr['id'] )
  1599.     {
  1600.         $selected = 'selected';
  1601.     }
  1602.     $option .= "<option value={$arr['id']} $selected>" . _( $arr['title'] ) . "\n";
  1603. }
  1604. return $option;
  1605. }
  1606.  
  1607. function get_color( $channel )
  1608. {
  1609.  
  1610. if ( !$channel['enable_monitoring'] )
  1611. {
  1612.     return '#5588FF';
  1613. }
  1614.  
  1615. if ( time() - strtotime( $channel['monitoring_status_updated'] ) > 3600 )
  1616. {
  1617.     return '#8B8B8B';
  1618. }
  1619.  
  1620. if ( $channel['monitoring_status'] == 1 )
  1621. {
  1622.  
  1623.     $disabled_link = Mysql::getInstance()->from( 'ch_links' )->where( array(
  1624.         'ch_id' => $channel['id'],
  1625.         'enable_monitoring' => 1,
  1626.         'status' => 0,
  1627.         ) )->get()->all();
  1628.  
  1629.     if ( !empty( $disabled_link ) )
  1630.     {
  1631.         return '#f4c430';
  1632.     }
  1633.     else
  1634.     {
  1635.         return 'green';
  1636.     }
  1637.  
  1638. }
  1639. else
  1640. {
  1641.     return 'red';
  1642. }
  1643. }
  1644.  
  1645. function get_hint( $channel )
  1646. {
  1647.  
  1648. if ( !$channel['enable_monitoring'] )
  1649. {
  1650.     return _( 'monitoring off' );
  1651. }
  1652.  
  1653. $diff = time() - strtotime( $channel['monitoring_status_updated'] );
  1654.  
  1655. if ( $diff > 3600 )
  1656. {
  1657.     return _( 'more than an hour ago' );
  1658. }
  1659.  
  1660. if ( $diff < 60 )
  1661. {
  1662.     return _( 'less than a minute ago' );
  1663. }
  1664.  
  1665. return round( $diff / 60 ) . ' ' . _( 'minutes ago' );
  1666. }
  1667.  
  1668. ?>
  1669. <script type="text/javascript">
  1670. function save(){
  1671.     var form_ = document.getElementById('form_');
  1672.     var cmd = '';
  1673.     var name = document.getElementById('name').value;
  1674.     if (document.getElementById('cmd')){
  1675.         cmd = document.getElementById('cmd').value;
  1676.     }
  1677.     var id = document.getElementById('id').value;
  1678.     //descr = document.getElementById('descr').value
  1679.    
  1680.     var action = 'add_itv.php?name='+name+'&cmd='+cmd+'&id='+id;
  1681.     //alert(action)
  1682.     if(document.getElementById('action').value == 'edit'){
  1683.         action += '&update=1'
  1684.     }
  1685.     else{
  1686.         action += '&save=1'
  1687.     }
  1688.    
  1689.     //alert(action)
  1690.     form_.setAttribute('action', action);
  1691.     form_.setAttribute('method', 'POST');
  1692.     //document.location=action
  1693.     form_.submit()
  1694. }
  1695.  
  1696. function popup(src){
  1697.      window.open( src, 'win_'+src, 'width=300,height=200,toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=1,status=0,fullscreen=0')
  1698. }
  1699.  
  1700. function delete_logo(id){
  1701.     var req = new Subsys_JsHttpRequest_Js();
  1702.  
  1703.     req.onreadystatechange = function() {
  1704.         if (req.readyState == 4) {
  1705.  
  1706.             if (req.responseJS) {
  1707.  
  1708.                 var resp = req.responseJS.data;
  1709.                 if(req.responseJS){
  1710.                     //set_cat_genres(resp)
  1711.                     document.getElementById('logo_block').innerHTML = '';
  1712.                 }else{
  1713.                     alert('<?=
  1714.  
  1715. htmlspecialchars( _( 'Error deleting a logo' ), ENT_QUOTES )
  1716.  
  1717. ?>');
  1718.                 }
  1719.             }else{
  1720.                 alert('<?=
  1721.  
  1722. htmlspecialchars( _( 'Error deleting a logo' ), ENT_QUOTES )
  1723.  
  1724. ?>');
  1725.             }
  1726.         }
  1727.     };
  1728.  
  1729.     req.caching = false;
  1730.  
  1731.     req.open('POST', 'load.php?get=del_tv_logo&id='+id, true);
  1732.     req.send({data:'bar'});
  1733. }
  1734. </script>
  1735. <br>
  1736. <script type="text/javascript">
  1737.     var links = <?=
  1738.  
  1739. empty( $links ) ? '[]' : json_encode( $links )
  1740.  
  1741. ?>;
  1742.     var stream_servers = <?=
  1743.  
  1744. empty( $stream_servers ) ? '[]' : json_encode( $stream_servers )
  1745.  
  1746. ?>;
  1747. </script>
  1748.  
  1749. <a name="form"></a>
  1750. <table align="center" class='list'>
  1751. <tr>
  1752.     <td>
  1753.     &nbsp;
  1754.     </td>
  1755. </tr>
  1756. <tr>
  1757.     <td>
  1758.     <form id="form_" class="itv_form" method="POST" enctype="multipart/form-data">
  1759.     <table align="center">
  1760.         <tr>
  1761.            <td align="right">
  1762.             <?=
  1763.  
  1764. _( 'Number' )
  1765.  
  1766. ?>:
  1767.            </td>
  1768.            <td>
  1769.             <input type="text" name="number" id="number" value="<?
  1770.  
  1771. echo @$number
  1772.  
  1773. ?>"  maxlength="3">
  1774.            </td>
  1775.         </tr>
  1776.         <tr>
  1777.            <td align="right">
  1778.             <?=
  1779.  
  1780. _( 'Name' )
  1781.  
  1782. ?>:
  1783.            </td>
  1784.            <td>
  1785.             <input type="text" name="name" id="name" value="<?
  1786.  
  1787. echo @htmlspecialchars( $name )
  1788.  
  1789. ?>">
  1790.             <input type="hidden" id="id" value="<?
  1791.  
  1792. echo @$_GET['id']
  1793.  
  1794. ?>">
  1795.             <input type="hidden" id="action" value="<?
  1796.  
  1797. if ( @$_GET['edit'] || @$_GET['update'] )
  1798. {
  1799. echo 'edit';
  1800. }
  1801.  
  1802. ?>">
  1803.            </td>
  1804.         </tr>
  1805.        
  1806.         <!--<tr>
  1807.            <td align="right" valign="top">
  1808.            <?
  1809.  
  1810. /*= _('Temporary HTTP URL')*/
  1811.  
  1812. ?>:
  1813.            </td>
  1814.            <td>
  1815.             <input name="use_http_tmp_link" id="use_http_tmp_link" type="checkbox" <?
  1816.  
  1817. /* echo @$checked_http_tmp_link */
  1818.  
  1819. ?> onchange="this.checked ? document.getElementById('wowza_tmp_link_tr').style.display = '' : document.getElementById('wowza_tmp_link_tr').style.display = 'none'" >
  1820.             <span id="wowza_tmp_link_tr" style="display: <?
  1821.  
  1822. /*echo @$checked_http_tmp_link ? '' : 'none' */
  1823.  
  1824. ?>">
  1825.                 <?
  1826.  
  1827. /*= _('WOWZA support')*/
  1828.  
  1829. ?>:
  1830.                 <input name="wowza_tmp_link" id="wowza_tmp_link" type="checkbox" <?
  1831.  
  1832. /* echo @$checked_wowza_tmp_link */
  1833.  
  1834. ?> >
  1835.             </span>
  1836.            </td>
  1837.         </tr>-->
  1838.         <tr>
  1839.            <td align="right" valign="top">
  1840.            <?=
  1841.  
  1842. _( 'Age restriction' )
  1843.  
  1844. ?>:
  1845.            </td>
  1846.            <td>
  1847.             <input name="censored" id="censored" type="checkbox" <?
  1848.  
  1849. echo @$checked
  1850.  
  1851. ?> >
  1852.            </td>
  1853.         </tr>
  1854.         <tr>
  1855.            <td align="right" valign="top">
  1856.            HD:
  1857.            </td>
  1858.            <td>
  1859.             <input name="hd" id="hd" type="checkbox" <?
  1860.  
  1861. echo @$checked_hd
  1862.  
  1863. ?> >
  1864.            </td>
  1865.         </tr>
  1866.         <tr>
  1867.            <td align="right" valign="top">
  1868.            <?=
  1869.  
  1870. _( 'Base channel' )
  1871.  
  1872. ?>:
  1873.            </td>
  1874.            <td>
  1875.             <input name="base_ch" id="base_ch" type="checkbox" <?
  1876.  
  1877. echo @$checked_base
  1878.  
  1879. ?> >
  1880.            </td>
  1881.         </tr>
  1882.         <tr>
  1883.            <td align="right" valign="top">
  1884.            <?=
  1885.  
  1886. _( 'Bonus channel' )
  1887.  
  1888. ?>:
  1889.            </td>
  1890.            <td>
  1891.             <input name="bonus_ch" id="bonus_ch" type="checkbox" <?
  1892.  
  1893. echo @$checked_bonus
  1894.  
  1895. ?> >
  1896.            </td>
  1897.         </tr>
  1898.         <tr>
  1899.            <td align="right" valign="top">
  1900.            <?=
  1901.  
  1902. _( 'Price' )
  1903.  
  1904. ?>:
  1905.            </td>
  1906.            <td>
  1907.             <input name="cost" id="cost" type="text" value="<?
  1908.  
  1909. echo @$cost
  1910.  
  1911. ?>" size="5" maxlength="6">
  1912.            </td>
  1913.         </tr>
  1914.         <tr>
  1915.            <td align="right" valign="top">
  1916.             <?=
  1917.  
  1918. _( 'Genre' )
  1919.  
  1920. ?>:
  1921.            </td>
  1922.            <td>
  1923.             <select name="tv_genre_id">
  1924.                 <option value="0">-----------
  1925.                 <?
  1926.  
  1927. echo get_genres()
  1928.  
  1929. ?>
  1930.             </select>
  1931.            </td>
  1932.         </tr>
  1933.  
  1934.         <?
  1935.  
  1936. if ( Config::get( 'enable_tv_quality_filter' ) )
  1937. {
  1938.  
  1939. ?>
  1940.         <tr>
  1941.            <td align="right">
  1942.             URL (HQ):
  1943.            </td>
  1944.            <td>
  1945.             <input id="cmd_1" name="cmd_1" size="50" type="text" value="<?
  1946.  
  1947. echo @$arr['cmd_1']
  1948.  
  1949. ?>">
  1950.            </td>
  1951.         </tr>
  1952.         <tr>
  1953.            <td align="right">
  1954.             URL (Medium):
  1955.            </td>
  1956.            <td>
  1957.             <input id="cmd_2" name="cmd_2" size="50" type="text" value="<?
  1958.  
  1959. echo @$arr['cmd_2']
  1960.  
  1961. ?>">
  1962.            </td>
  1963.         </tr>
  1964.         <tr>
  1965.            <td align="right">
  1966.             URL (Low):
  1967.            </td>
  1968.            <td>
  1969.             <input id="cmd_3" name="cmd_3" size="50" type="text" value="<?
  1970.  
  1971. echo @$arr['cmd_3']
  1972.  
  1973. ?>">
  1974.            </td>
  1975.         </tr>
  1976.         <?
  1977.  
  1978. }
  1979. else
  1980. {
  1981.  
  1982. ?>
  1983.         <tr>
  1984.             <td align="right" valign="top">
  1985.                 <?=
  1986.  
  1987. _( 'Links' )
  1988.  
  1989. ?>:
  1990.             </td>
  1991.             <td class="links_block">
  1992.  
  1993.             </td>
  1994.         </tr>
  1995.         <?
  1996.  
  1997. }
  1998.  
  1999. ?>
  2000.  
  2001.         <tr style="display: none;">
  2002.            <td align="right" valign="top">
  2003.            WOWZA load balancing:
  2004.            </td>
  2005.            <td>
  2006.             <input name="enable_wowza_load_balancing" id="enable_wowza_load_balancing" value="1" type="checkbox" <?
  2007.  
  2008. echo @$checked_wowza_load_balancing
  2009.  
  2010. ?> >
  2011.            </td>
  2012.         </tr>
  2013.        
  2014.         <tr>
  2015.            <td align="right">
  2016.             <?=
  2017.  
  2018. _( 'URL for recording (multicast)' )
  2019.  
  2020. ?>:
  2021.            </td>
  2022.            <td>
  2023.             <input id="mc_cmd" name="mc_cmd" size="50" type="text" value="<?
  2024.  
  2025. echo @$mc_cmd
  2026.  
  2027. ?>">
  2028.            </td>
  2029.         </tr>
  2030.         <tr>
  2031.            <td align="right" valign="top">
  2032.             <?=
  2033.  
  2034. _( 'Enable TV archive' )
  2035.  
  2036. ?>:
  2037.            </td>
  2038.            <td>
  2039.             <input name="enable_tv_archive" id="enable_tv_archive" class="enable_tv_archive" type="checkbox" <?
  2040.  
  2041. echo @$checked_enable_tv_archive
  2042.  
  2043. ?> >
  2044.             <span class="flussonic_dvr_block" style="display: <?
  2045.  
  2046. echo @$checked_enable_tv_archive ? '' : 'none'
  2047.  
  2048. ?>"> <?=
  2049.  
  2050. _( 'Flussonic DVR' )
  2051.  
  2052. ?><input type="checkbox" class="flussonic_dvr" name="flussonic_dvr" <?=
  2053.  
  2054. @$checked_flussonic_dvr
  2055.  
  2056. ?>></span>
  2057.             <span class="wowza_dvr_block" style="display: <?
  2058.  
  2059. echo @$checked_enable_tv_archive ? '' : 'none'
  2060.  
  2061. ?>"> <?=
  2062.  
  2063. _( 'Wowza DVR' )
  2064.  
  2065. ?><input type="checkbox" class="wowza_dvr" name="wowza_dvr" <?=
  2066.  
  2067. @$checked_wowza_dvr
  2068.  
  2069. ?>></span>
  2070.             <span id="storage_name" style="display: <?
  2071.  
  2072. echo @$checked_enable_tv_archive ? '' : 'none'
  2073.  
  2074. ?>">
  2075.                 <table width="100%" style="background-color:#f8f8f8">
  2076.                     <?
  2077.  
  2078. foreach ( $storages as $storage )
  2079. {
  2080.  
  2081. ?>
  2082.                     <tr>
  2083.                         <td width="50%"><?=
  2084.  
  2085. $storage['storage_name']
  2086.  
  2087. ?>:</td>
  2088.                         <td width="50%">
  2089.                             <input type="checkbox"
  2090.                                    class="stream_server <?
  2091.  
  2092. if ( $storage['flussonic_dvr'] )
  2093. {
  2094.     echo "flussonic_stream_server";
  2095. }
  2096. elseif ( $storage['wowza_dvr'] )
  2097. {
  2098.     echo "wowza_stream_server";
  2099. }
  2100. else
  2101. {
  2102.     echo "generic_stream_server";
  2103. }
  2104.  
  2105. ?>"
  2106.                                    name="storage_names[]"
  2107.                                    value="<?=
  2108.  
  2109. $storage['storage_name']
  2110.  
  2111. ?>"
  2112.                                    <?=
  2113.  
  2114. ( in_array( $storage['storage_name'], $selected_storages ) ? 'checked' : '' )
  2115.  
  2116. ?>
  2117.                                    <?=
  2118.  
  2119. $storage['flussonic_dvr'] && !isset( $checked_flussonic_dvr ) || $storage['wowza_dvr'] && !isset( $checked_wowza_dvr ) || !$storage['flussonic_dvr'] && !$storage['wowza_dvr'] && isset( $checked_flussonic_dvr ) ? 'disabled' : ''
  2120.  
  2121. ?>
  2122.                                 />
  2123.                         </td>
  2124.                     </tr>
  2125.                     <?
  2126.  
  2127. }
  2128.  
  2129. ?>
  2130.                 </table>
  2131.             </span>
  2132.            </td>
  2133.         </tr>
  2134.         <tr>
  2135.             <td align="right">
  2136.                 <?=
  2137.  
  2138. _( 'TV archive duration, h' )
  2139.  
  2140. ?>:
  2141.             </td>
  2142.             <td>
  2143.                 <input name="tv_archive_duration" id="tv_archive_duration" type="text" value="<?=
  2144.  
  2145. isset( $_GET['id'] ) ? @$tv_archive_duration : Config::getSafe( 'tv_archive_parts_number', 168 )
  2146.  
  2147. ?>">
  2148.             </td>
  2149.         </tr>
  2150.         <tr>
  2151.             <td align="right" valign="top">
  2152.                 <?=
  2153.  
  2154. _( 'Allow nPVR' )
  2155.  
  2156. ?>:
  2157.             </td>
  2158.             <td>
  2159.                 <input name="allow_pvr" id="allow_pvr" type="checkbox" value="1" <?
  2160.  
  2161. echo @$checked_allow_pvr
  2162.  
  2163. ?> onchange="this.checked ? document.getElementById('pvr_storage_name').style.display = '' : document.getElementById('pvr_storage_name').style.display = 'none'">
  2164.  
  2165.                 <span id="pvr_storage_name" style="display: <?
  2166.  
  2167. echo @$checked_allow_pvr ? '' : 'none'
  2168.  
  2169. ?>">
  2170.                 <table width="100%" style="background-color:#f8f8f8">
  2171.                     <?
  2172.  
  2173. foreach ( $storages as $storage )
  2174. {
  2175. if ( $storage['flussonic_dvr'] || $storage['wowza_dvr'] )
  2176. {
  2177.     continue;
  2178. }
  2179.  
  2180. ?>
  2181.                     <tr>
  2182.                         <td width="50%"><?=
  2183.  
  2184. $storage['storage_name']
  2185.  
  2186. ?>:</td>
  2187.                         <td width="50%">
  2188.                             <input type="checkbox" class="stream_server" name="pvr_storage_names[]" value="<?=
  2189.  
  2190. $storage['storage_name']
  2191.  
  2192. ?>" <?=
  2193.  
  2194. ( in_array( $storage['storage_name'], $selected_pvr_storages ) ? 'checked' : '' )
  2195.  
  2196. ?>/>
  2197.                         </td>
  2198.                     </tr>
  2199.                     <?
  2200.  
  2201. }
  2202.  
  2203. ?>
  2204.                 </table>
  2205.             </span>
  2206.             </td>
  2207.         </tr>
  2208.         <tr>
  2209.             <td align="right" valign="top">
  2210.                 <?=
  2211.  
  2212. _( 'Allow USB TimeShift' )
  2213.  
  2214. ?>:
  2215.             </td>
  2216.             <td>
  2217.                 <input name="allow_local_timeshift" id="allow_local_timeshift" type="checkbox" value="1"  <?=
  2218.  
  2219. isset( $checked_allow_local_timeshift ) ? $checked_allow_local_timeshift : 'checked'
  2220.  
  2221. ?> >
  2222.                 <span style="color: #747474">(<?=
  2223.  
  2224. _( 'only for rtp and ffrt solutions' )
  2225.  
  2226. ?>)</span>
  2227.             </span>
  2228.             </td>
  2229.         </tr>
  2230.         <tr>
  2231.             <td align="right">
  2232.                 <?=
  2233.  
  2234. _( 'Allow USB PVR' )
  2235.  
  2236. ?>:
  2237.             </td>
  2238.             <td>
  2239.                 <input name="allow_local_pvr" id="allow_local_pvr" type="checkbox" value="1" <?=
  2240.  
  2241. isset( $checked_allow_local_pvr ) ? $checked_allow_local_pvr : 'checked'
  2242.  
  2243. ?> >
  2244.             </td>
  2245.         </tr>
  2246.         <!--<tr>
  2247.            <td align="right">
  2248.             <?
  2249.  
  2250. /*= _('Enable monitoring')*/
  2251.  
  2252. ?>:
  2253.            </td>
  2254.            <td>
  2255.             <input id="enable_monitoring" name="enable_monitoring" type="checkbox" value="1" <?
  2256.  
  2257. /* echo @$checked_enable_monitoring */
  2258.  
  2259. ?> onchange="this.checked ? document.getElementById('monitoring_url_tr').style.display = '' : document.getElementById('monitoring_url_tr').style.display = 'none'">
  2260.            </td>
  2261.         </tr>
  2262.         <tr id="monitoring_url_tr" style="display:<?
  2263.  
  2264. /* echo @$checked_enable_monitoring ? '' : 'none' */
  2265.  
  2266. ?>">
  2267.            <td align="right">
  2268.             <?
  2269.  
  2270. /*= _('Channel URL for monitoring')*/
  2271.  
  2272. ?>:
  2273.            </td>
  2274.            <td>
  2275.             <input id="monitoring_url" name="monitoring_url" size="50" type="text" value="<?
  2276.  
  2277. /* echo @$monitoring_url */
  2278.  
  2279. ?>"> * <?
  2280.  
  2281. /*= _('http only')*/
  2282.  
  2283. ?>
  2284.            </td>
  2285.         </tr>-->
  2286.         <tr>
  2287.            <td align="right">
  2288.             xmltv id:
  2289.            </td>
  2290.            <td>
  2291.             <input id="xmltv_id" name="xmltv_id" size="50" type="text" value="<?
  2292.  
  2293. echo @$xmltv_id
  2294.  
  2295. ?>">
  2296.            </td>
  2297.         </tr>
  2298.         <tr>
  2299.             <td align="right">
  2300.                 <?=
  2301.  
  2302. _( 'EPG correction' ) . ', ' . _( 'min' )
  2303.  
  2304. ?>:
  2305.             </td>
  2306.             <td>
  2307.                 <input id="correct_time" name="correct_time" size="50" type="text" value="<?
  2308.  
  2309. echo @$correct_time
  2310.  
  2311. ?>">
  2312.             </td>
  2313.         </tr>
  2314.         <tr>
  2315.            <td align="right">
  2316.             <?=
  2317.  
  2318. _( 'Service code' )
  2319.  
  2320. ?>:
  2321.            </td>
  2322.            <td>
  2323.             <input id="service_id" name="service_id" size="50" type="text" value="<?
  2324.  
  2325. echo @$service_id
  2326.  
  2327. ?>">
  2328.            </td>
  2329.         </tr>
  2330.         <tr>
  2331.            <td align="right">
  2332.             <?=
  2333.  
  2334. _( 'Volume correction' )
  2335.  
  2336. ?> (-20...20):
  2337.            </td>
  2338.            <td>
  2339.             <input id="volume_correction" name="volume_correction" size="50" type="text" value="<?
  2340.  
  2341. echo @$volume_correction
  2342.  
  2343. ?>">
  2344.            </td>
  2345.         </tr>
  2346.         <tr>
  2347.            <td align="right">
  2348.             <?=
  2349.  
  2350. _( 'Comments' )
  2351.  
  2352. ?>:
  2353.            </td>
  2354.            <td>
  2355.             <textarea id="descr"  name="descr" cols="39" rows="5"><?
  2356.  
  2357. echo @$descr
  2358.  
  2359. ?></textarea>
  2360.            </td>
  2361.         </tr>
  2362.         <?
  2363.  
  2364. if ( !empty( $logo ) )
  2365. {
  2366.  
  2367. ?>
  2368.         <tr>
  2369.             <td align="right"></td>
  2370.             <td valign="top" id="logo_block">
  2371.                 <img src="<?
  2372.  
  2373. echo Itv::getLogoUriById( intval( $_GET['id'] ) ) . '?' . time()
  2374.  
  2375. ?>" style="float: left;"/><a href="javascript://" onclick="delete_logo(<?
  2376.  
  2377. echo intval( $_GET['id'] )
  2378.  
  2379. ?>); return false;"  style="float: left;">[x]</a>
  2380.             </td>
  2381.         </tr>
  2382.         <?
  2383.  
  2384. }
  2385.  
  2386. ?>
  2387.         <tr>
  2388.             <td align="right">
  2389.                 <?=
  2390.  
  2391. _( 'Logo' )
  2392.  
  2393. ?>:
  2394.             </td>
  2395.             <td>
  2396.                 <input type="file" name="logo" id="logo"/>
  2397.             </td>
  2398.         </tr>
  2399.         <tr>
  2400.            <td>
  2401.            </td>
  2402.            <td>
  2403.             <input type="button" value="<?=
  2404.  
  2405. htmlspecialchars( _( 'Save' ), ENT_QUOTES )
  2406.  
  2407. ?>" onclick="save()">&nbsp;<input type="button" value="<?=
  2408.  
  2409. htmlspecialchars( _( 'Cancel' ), ENT_QUOTES )
  2410.  
  2411. ?>" onclick="document.location='add_itv.php'">
  2412.            </td>
  2413.         </tr>
  2414.     </table>
  2415.     </form>
  2416.     </td>
  2417. </tr>
  2418. </table>
  2419. </td>
  2420. </tr>
  2421. </table>
  2422. </body>
  2423. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement