<?php

include_once(_DIR_TO_CLASS."/c_page.php");
class c_page_cab_client_car_create extends c_page
{
    public $h1='Добавление нового автомобиля' ;

    function block_main()
    { //damp_array($_POST) ;
      $this->page_title() ;
      $this->panel_car_create() ;
      $this->panel_last_create_car() ;
    }

    function panel_car_create()
    { $list_orgs=execSQL('select pkey,obj_name from obj_site_personals where clss=207 and enabled=1 and client_id='.MEMBER()->id) ;
      ?><div id="panel_car_create"><form>
        <table class="info">
         <tr><td>Собственник:</td><td><select name="car[org_id]"><?
                  if (_sizeof($list_orgs)) foreach($list_orgs as $rec_list) {?><option value="<?echo $rec_list['pkey']?>"><?echo $rec_list['obj_name']?></option><?}
              ?></select>
         </td></tr>
         <tr><td>Марка и модель авто:</td><td><input type="text"  data-required name="car[model]" class="big" value=""></td></tr>
         <tr><td>Госномер:</td><td><input type="text"  data-required name="car[gos_nomer]" class="email" value=""></td></tr>
         <tr><td>Класс авто:</td><td><input type="text" data-required  name="car[typ]" class="small" value=""></td></tr>
         <tr><td>Дата окончания полиса ОСАГО:</td><td><input type="text" id="e_osago" data-required name="car[e_osago]" class="small" value=""></td></tr>
         <tr><td>Дата окончания полиса СТС:</td><td><input type="text" id="e_sts" data-required name="car[e_sts]" class="small" value=""></td></tr>
         <tr><td>Дата окончания ГТО:</td><td><input type="text" id="e_to" data-required name="car[e_to]" class="small" value=""></td></tr>
         <tr><td>Номер лицензии:</td><td><input type="text"  data-required name="car[permit]" class="small" value=""></td></tr>
         <tr><td></td><td><input type="submit" class="v1" cmd="create_car" value="Добавить автомобиль" validate="form"></td></tr>
         </table></form>
       </form></div>
       <script type="text/javascript">
           $j('#e_osago').datepicker({dateFormat: 'dd.mm.yy',prevText: '<i class="fa fa-chevron-left"></i>',nextText: '<i class="fa fa-chevron-right"></i>',onSelect: function( selectedDate ) {/*$j('#finish').datepicker('option', 'minDate', selectedDate);*/}});
           $j('#e_sts').datepicker({dateFormat: 'dd.mm.yy',prevText: '<i class="fa fa-chevron-left"></i>',nextText: '<i class="fa fa-chevron-right"></i>',onSelect: function( selectedDate ) {/*$j('#finish').datepicker('option', 'minDate', selectedDate);*/}});
           $j('#e_to').datepicker({dateFormat: 'dd.mm.yy',prevText: '<i class="fa fa-chevron-left"></i>',nextText: '<i class="fa fa-chevron-right"></i>',onSelect: function( selectedDate ) {/*$j('#finish').datepicker('option', 'minDate', selectedDate);*/}});
       </script>

       <?
    }


    function CMD_create_car()
     { //damp_array($_POST) ;
       $data['clss']=361 ;
       $data['parent']=$_POST['car']['org_id'] ;
       $data['model']=$_POST['car']['model'] ;
       $data['obj_name']=$_POST['car']['gos_nomer'] ;
       $car_number=$_POST['car']['gos_nomer'] ;
       $car_number=str_replace(array("'",'"','(',')',' ',"\n"),'',$car_number) ;
       $data['obj_name']=ENGINE()->translit2($car_number) ;

       $data['typ']=$_POST['car']['typ'] ;
       $data['e_osago']=strtotime($_POST['car']['e_osago']) ;
       $data['e_sts']=strtotime($_POST['car']['e_sts']) ;
       $data['e_to']=strtotime($_POST['car']['e_to']) ;
       $data['permit']=$_POST['car']['permit'] ;
       $id=adding_rec_to_table('obj_site_personals_cars',$data) ;
       if ($id) {?><div class="green center">Автомобиль успешно добавлен</div><?}
       else     {?><div class="red center">Не удалоль добавить автомобиль</div><?}
     }

     function panel_last_create_car()
     {   ?><br><br><br><br><h2>Последние 10 добавленных автомобилей</h2><?
         $list_car=execSQL('select * from obj_site_personals_cars where clss=361 and enabled=1 order by c_data desc limit 10') ;
         print_template($list_car,'aspmo_client/list_cars_full') ;
     }

}



?>
