<?php
include_once('c_rmt_check_s.php') ;
class c_page_cab_rmt_check_s3 extends c_page_cab_rmt_check_s
{
  var $step=3 ;
  public $h1='3 из 3: Техническое состояние автомобиля' ;
  //  about:config   media.navigator.permission.disabled

    function body_work()
    {
        ?>
        <body class="<?echo $this->color_set ?> body_work <?echo $this->body_class ?>">
        <div class="body" style="margin:0 7px 20px 7px;">
            <aside>
                <?
                $this->panel_second_menu();
                ?>
                <table id="block_center">
                    <tr>
                        <td id="center_left"><? $this->panel_block_main(); ?></td>
                        <td id="center_right"><?
                            $this->panel_block_right(); ?></td>
                    </tr>
                </table>
            </aside>
        </div>
        <div id="div_print"></div>
        </body>
        <?
    }

  function menu_config()
  {
    $this->menu[$this->rec_to['__href'].'s1/']='Подтверждение личности водителя' ;
    $this->menu[$this->rec_to['__href'].'s3/']='Проверка технического состояния' ;
    $this->menu['/cab/rmt/']=array('title'=>'Закрыть') ;
  }


  function block_main()
  { //$this->page_title() ;
    $this->panel_check_car() ; ;
  }

  function panel_check_car()
  {
      $all_cnt=0 ; $yes_cnt=0 ;
    $access_type=($this->filter['access_type'])? 1:0;

    $params=$this->get_TO_params($access_type);

    $cur_pamar_group='';
    ?><script type="text/javascript" src="<?echo _PATH_TO_EXT.'/rmt/jquery.webcamera_capture_2.js'?>"></script>
      <script type="text/javascript" src="<?echo _PATH_TO_EXT.'/jquery/buzz.min.js'?>"></script>
      <form>
        <table class="basic fz_big full auto" id="TO_check">
            <tr><th colspan="3"><?echo $this->rec_to['car_model'].' '.$this->rec_to['car_number']?></th></tr>
            <tr><th>Проверяемый параметр</th><th colspan="2">Результат</th></tr>
            <?foreach($params as $rec_param)
            {
                if ($cur_pamar_group!=$rec_param['group_name']) {
                    $cur_pamar_group=$rec_param['group_name'];
                    ?>
                    <tr>
                        <th colspan="3"><?echo 'Группа: '.$cur_pamar_group?></th>
                    </tr>
                    <?
                }
                ?><tr class="<?if ($rec_param['notnull']) echo 'notnull'?>">
                   <td class="left" style="width:auto;"><?echo $rec_param['obj_name']?></td>
                     <? switch($rec_param['type'])
                         { case 0: ?><label class="ios7-switch" style=""><input type="hidden" name="param[<?echo $rec_param['pkey']?>]" value="0"><input type="checkbox" name="param[<?echo $rec_param['pkey']?>]" photo_on_no="<?echo $rec_param['photo']?>" value="1"><span></span></label><?  break ;
                           case 1: ?><td  style="width:100px;" class="radiobox yes <?if ($rec_param['notnull']) echo 'notnull'?>" param_id="<?echo $rec_param['pkey']?>"><input type="hidden" name="param[<?echo $rec_param['pkey']?>][yes]" value="0"><div>Да</div></td>
                                     <td  style="width:100px;" class="radiobox no <?if ($rec_param['photo']) echo 'photo'?> <?if ($rec_param['notnull']) echo 'notnull'?>" param_id="<?echo $rec_param['pkey']?>"><input type="hidden" name="param[<?echo $rec_param['pkey']?>][no]" photo_on_no="<?echo $rec_param['photo']?>" value="0"><div>Нет <?if ($rec_param['photo']) echo '<br><i class="fa fa-camera" aria-hidden="true"></i>'?></div></td>
                                    <?
                                    break ;
                           case 2: ?><td  style="width:200px;" colspan=2 class="string <?if ($rec_param['notnull']) echo 'notnull'?>"><input type="text" name="param[<?echo $rec_param['pkey']?>]"></td><? break ;
                           case 3: ?><td  style="width:200px;" colspan=2 class="textbox <?if ($rec_param['notnull']) echo 'notnull'?>"><textarea name="param[<?echo $rec_param['pkey']?>]"></textarea></td><? break ;
                         }
                     ?>
                 </tr>
                <?
                if ($rec_param['notnull']) $all_cnt++ ;
            }
            ?>
            <tr>
                <td class="right">Показания одометра:</td>
                <td colspan="2"><input id="odometr" type="text" name="param[odometr]" onkeypress='validateNumber(event)'></td>
            </tr>
            <tr>
                <td class="right gray">Отметить все</td>
                <td id="all_yes" colspan="2">ДА</td>
            </tr>
        </table>

        <div id="TO_status">Результаты проверки:<!--: <span id="yes_cnt"><?echo $yes_cnt?></span> из  <span id="all_cnt"><?echo $all_cnt?></span>--></div>
        <div class="buttons sky-form">
               <button class="v2 button no" cmd="rmt/check_car_denited"  to_id=<?echo $this->rec_to['pkey']?> >ТО не пройдено</button>
               <button id="button_allow" class="v2 button yes" cmd="rmt/check_car_allow" to_id=<?echo $this->rec_to['pkey']?> disabled="disabled">ТО пройдено</button>
        </div>
      </form>
      <script type="text/javascript">
          var cnt_yes=0 ; var cnt_all=<?echo $all_cnt?>;
          $j('div#TO_status').click(function(){$j('table#TO_check tr').show(300)}) ;
          $j('td.radiobox').click(function()
           { $j(this).closest('tr').find('td.radiobox').removeClass('active') ;
             $j(this).closest('tr').find('input[type=hidden]').val(0) ;
             $j(this).closest('td').find('input[type=hidden]').val(1) ;
             $j(this).addClass('active') ;
             if ($j(this).hasClass('no')&&$j(this).hasClass('active')&&$j(this).hasClass('photo')) send_ajax_request({cmd:'rmt/show_photo_panel',to_id:<?echo $this->rec_to['pkey']?>,param_id:$j(this).attr('param_id')}) ;
             if ($j(this).hasClass('yes')&&$j(this).hasClass('active')) $j(this).closest('tr').hide(300) ;

             check_full_field() ;

           });

          $j('td.textbox textarea').on('keyup',check_full_field) ;
          $j('td.string input').on('keyup',check_full_field) ;
          $j('#odometr').on('keyup',check_full_field);

          function check_full_field()
          {
              var cnt_full=0 ;
              $j.each($j('tr.notnull'),function(i,el)
              {  var v=0 ;
                  if ($j(this).find('td.radiobox.yes')&&$j(this).find('td.radiobox.yes').hasClass('active')) v=1 ;
                  if ($j(this).find('td.string').find('input[type=text]').length&&$j(this).find('td.string').find('input[type=text]').val()!="") v=1 ;
                  if ($j(this).find('td.textbox').find('textarea').length&&$j(this).find('td.textbox').find('textarea').val()!="") v=1 ;
                  if (v==1) cnt_full++ ;
               }) ;

              let odometr = $j('#odometr').val();
              if (cnt_full>=$j('tr.notnull').length && odometr)  $j('#button_allow').removeAttr('disabled') ;
              else                                    $j('#button_allow').attr('disabled','disabled') ;
          }

          $j('#all_yes').click(function()
          {
              $j('td.radiobox').removeClass('active') ;
              $j('td.radiobox.yes').click() ;
          });

          function validateNumber(evt) {
              var theEvent = evt || window.event;

              // Handle paste
              if (theEvent.type === 'paste') {
                  key = event.clipboardData.getData('text/plain');
              } else {
                  // Handle key press
                  var key = theEvent.keyCode || theEvent.which;
                  key = String.fromCharCode(key);
              }
              var regex = /[0-9]|\./;
              if( !regex.test(key) ) {
                  theEvent.returnValue = false;
                  if(theEvent.preventDefault) theEvent.preventDefault();
              }
          }
      </script>
      <style type="text/css">
          table#TO_check{font-size:20px;line-height:40px;}
          table#TO_check td{vertical-align:middle;min-height:50px;border-width:2px;}
          table#TO_check td.radiobox{width:100px;color:#aaaaaa;font-weight:lighter;background:#fafafa;min-height:100px;text-transform:uppercase;}
          table#TO_check td.radiobox div{width:100px;height:70px;padding-top:30px;text-align:center;}
          table#TO_check td.radiobox.yes.active{background:green;color:white;}
          table#TO_check td.radiobox.no.active{background:red;color:white;}
          table#TO_check td.radiobox{cursor: pointer;}
          table#TO_check td i{font-size:20px;line-height:20px;top:-15px;position:relative;}
          table#TO_check td.string{text-align:left;}
          table#TO_check td.string input{width:100%;height:40px;font-size:30px;}
          table#TO_check td.textbox{text-align:left;}
          table#TO_check td.textbox textarea{width:200px;height:80px;font-size:20px;}
          #all_yes{color:green;cursor: pointer;}

          div#TO_status{width:100%;margin:20px 0;font-size:40px;text-align:center;cursor:pointer;text-decoration:underline;}
          div#TO_status span#yes_cnt{color:green;font-size:30px;}
          div#TO_status span#all_cnt{color:green;font-size:30px;}

          div.buttons button{}
          div.buttons button.no{float:left;margin-left:0;}
          div.buttons button.yes{float:right;}
          .sky-form  button.button{width:200px;height:80px;font-size:22px;}
          .sky-form  button.button.no{background-color:red;}
          .sky-form  button.button.yes{background-color:green;}
      </style>
    <?
  }

    function get_TO_params($access_type)
    {
        $result=[];

        $params=execSQL('select * from obj_site_to_params where access='.$access_type.' and (car_type="'.$this->rec_car['type'].'" or car_type is null) order by  group_name,indx') ;

        if (_sizeof($params)) {
            $result=$params;
        } else {
            $result=execSQL('select * from obj_site_to_params where access='.$access_type.' and car_type is null order by indx') ;;
        }


        return $result;
    }

}

?>
