<?
include_once(_DIR_EXT.'/HTML/c_page_TXT.php');
class c_services_post_shift_poll_session extends c_page_TXT
{
public $content_view_id=0;
public $is_vurtual_term=0;

function __construct($options=array())
{
	parent::__construct($options);
	$this->content_view_id=_CUR_ID;
}

function show(&$options=array())
{// ob_start();
    // данные
    //$rec_content_view=execSQL_van('select * from media_content_view where pkey='.$this->content_view_id);
    //if ($rec_content_view['pkey'])
    {   // определяем откуда пришел запрос на контент - если виртуальный терминал - то видеo надо запускать сразу
    $arr_refferer=parse_url($_SERVER['HTTP_REFERER']);
    $this->is_vurtual_term=($arr_refferer['host']==_MAIN_DOMAIN)? 1:0;

    //LOG_JSON('event_pass')->reg('get_media_content','Получен запрос на медиаконтент ID '.$this->content_view_id);

    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>ЭСМО</title>
        <link rel="stylesheet" type="text/css" href="<? echo _PATH_TO_EXT ?>/interface/bootstrap-4.4.1/css/bootstrap.css" charset="utf-8">
        <link rel="stylesheet" type="text/css" href="<? echo _PATH_TO_EXT ?>/interface/bootstrap-4.4.1/jBootstrap.css" charset="utf-8">
        <link rel="stylesheet" type="text/css" href="/AddOns/font-awesome-4.7.1/css/font-awesome.css" charset="utf-8">
        <link rel="stylesheet" type="text/css" href="/AddOns/fontawesome-free-5.12.0/css/all.css" charset="utf-8">
        <link rel="stylesheet" type="text/css" href="<? echo _PATH_TO_EXT ?>/post_shift_poll/style_frame.css?r=<?= rand() ?>" charset="utf-8">
        <link rel="stylesheet" type="text/css" href="<? echo _PATH_TO_EXT ?>/post_shift_poll/style_button.css" charset="utf-8">
        <link rel="stylesheet" type="text/css" href="/<? echo _CLASS_ ?>/style.css?r=<?= rand() ?>" charset="utf-8">
        <link rel="stylesheet" type="text/css" href="/<? echo _CLASS_ ?>/style.css?r=<?= rand() ?>" charset="utf-8">

        <script type="text/javascript">let server_url = "<?echo _PATH_TO_SITE?>";</script>
        <script type="text/javascript">let post_shift_poll_question_len = <?echo $GLOBALS['LS_post_shift_poll_question_len']?>;</script>

        <SCRIPT type="text/javascript" src="<? echo _PATH_TO_EXT ?>/jquery/jquery-3.4.1.min.js"></SCRIPT>
        <SCRIPT type="text/javascript" src="<? echo _PATH_TO_EXT ?>/jquery/jquery.timers-1.2.js"></SCRIPT>
        <SCRIPT type="text/javascript" src="<? echo _PATH_TO_EXT ?>/interface/bootstrap-4.4.1/js/bootstrap.js"></SCRIPT>
        <SCRIPT type="text/javascript" src="<? echo _PATH_TO_EXT ?>/interface/bootstrap-4.4.1/jBootstrap.js"></SCRIPT>
        <SCRIPT type="text/javascript" src="<? echo _PATH_TO_EXT ?>/interface/bootstrap-4.4.1/ajax.bootstrap.js"></SCRIPT>
        <SCRIPT type="text/javascript" src="<? echo _PATH_TO_EXT ?>/jquery/jquery.form.min.js"></SCRIPT>
        <SCRIPT type="text/javascript" src="<? echo _PATH_TO_EXT ?>/post_shift_poll/frame.js?r=<?= rand() ?>"></SCRIPT>
        <script type="text/javascript" src="<? echo _PATH_TO_EXT ?>/events_media/terminal-ipc.js?r=<? echo rand() ?>"></script>

        <link rel="stylesheet" type="text/css" href="<? echo _PATH_TO_EXT ?>/interface/jQuery-Countdown-Timer-Digital-Clock-Plugin-timeTo/timeTo.css" charset="utf-8">
        <script src="<? echo _PATH_TO_EXT ?>/interface/jQuery-Countdown-Timer-Digital-Clock-Plugin-timeTo/jquery.time-to.js" defer></script>

    </head>
    <body class="_shadow">
    <form id=form method="post" action="">
        <div class="content" id="content">
            <input type="hidden" name="poll_id" value="<? echo _CUR_ID ?>">

                <?
                $rec_session=POST_SHIFT_POLL()->get_poll_by_id(_CUR_ID);//damp_array($rec_session);
                if($rec_session['pkey'] and $rec_session['status']<=1)
                {
                    $now=getdate();
                    $data['status']=1;
                    $data['c_data']=time();
                    $data['c_data_m']=mktime($now['hours'],$now['minutes'],0,$now['mon'],$now['mday'],$now['year']);
                    $data['c_data_h']=mktime($now['hours'],0,0,$now['mon'],$now['mday'],$now['year']);
                    $data['c_data_d']=mktime(0,0,0,$now['mon'],$now['mday'],$now['year']);

                    update_rec_in_table('poll_sessions',$data,'pkey='.$rec_session['pkey']);

                    //$arr_questions_ids=execSQL_line('select question_id from post_shift_poll where parent='.$rec_session['pkey'].' and status=0');
                    // используется отдельная панель, так как в опросах был показ влоенных вопросов
                    include_once('i_post_shift_poll_questions_panel.php');
                    $panel=new i_post_shift_poll_questions_panel([]);
                    $panel->panel_questions();
                    //echo 'LS_post_shift_poll_question_len='.$GLOBALS['LS_post_shift_poll_question_len'].'<br>' ;

                    ?>
              <div id="the_end"><h1 class="display-4" style="font-size:2em;">Опрос завершен</h1>
                  <div class="icon">
                      <div class="spinner-border m-5" role="status">
                          <span class="sr-only">Loading...</span>
                      </div>
                  </div>
                  <div class="status">Идет сохранение результатов...</div>
              </div><?
                ?>
              <script type="text/javascript">
                  // Сообщение терминалу что страница готова.

              </script>        <?
                }
                else if($rec_session['status']>1)
                {
                    ?><table class="by_center">
                  <tr>
                      <td>
                          <strong>Сессия опроса ID <? echo $rec_session['pkey'] ?> уже завершена.</strong><br>
                          <small>Опрос пройден <? echo date('d.m.Y H:i',$rec_session['c_data']) ?></small>
                      </td>
                  </tr>
              </table><?
                }
                else
                {
                    ?><table class="by_center">
                  <tr>
                      <td>
                          <strong>Сессия опроса ID <? echo _CUR_ID ?> не найдена</strong><br> <small></small>
                      </td>
                  </tr>
              </table><?
                }
                ?></div>
        <div id="countdown"></div>
    </form>
    </body>
    <script type="text/javascript">
        // Сообщение терминалу что страница готова.
        $j(document).ready(function () {
            sendAppEvent('media-content-ready');
        });
    </script>
    </html>
    <?

    LOG_JSON('mo_session')->reg('/services/post_shift_poll/session/','Показан фрейм послесменного опроса');
    LOG_JSON('mo_session')->flush('mo_trace_'.$rec_session['mo_id']);
}
//$text=ob_get_clean();
//echo $text;
//LOGS()->reg_log('$rec_content_view',$text);
}
}

?>
