- $currentUrl = Yii::app()->createAbsoluteUrl($this->route,$context)

- $hasData = isset($periods) && count($periods->data)>0

- $customValidityPeriods = PlateAuthorizationController::getCustomValidityPeriods()

- $paramDescription = array_get($_REQUEST,"a_description",paramdeep('plateAuthorizations','default','validityPeriodDescription'))
- $paramType = array_get($_REQUEST,"a_type",paramdeep('plateAuthorizations','default','validityPeriodType'))
- $paramStartDate = array_get($_REQUEST,"a_startDate",date(getFormat_Date()))
- $paramEndDate = array_get($_REQUEST,"a_endDate",date(getFormat_Date()))

.page-header
  %h2
    %i.icon-time
    =t('Validity periods')
  
%h5
  - $navigate_url_list = Yii::app()->createAbsoluteUrl('plateAuthorization')
  %a(href="#{$navigate_url_list}")
    %i.icon-file-text-alt
    =$objList->name
  - $navigate_url_user = Yii::app()->createAbsoluteUrl($this->route,array('plateListId'=>$plateListId,'step'=>'1'))
  %i.icon-long-arrow-right 
  %a(href="#{$navigate_url_user}")
    %i.icon-user
    ="$objOwner->Nome $objOwner->Cognome"
  - $navigate_url_vehicle = Yii::app()->createAbsoluteUrl($this->route,array('plateListId'=>$plateListId,'step'=>'2','ownerId'=>$ownerId))
  %i.icon-long-arrow-right 
  %a(href="#{$navigate_url_vehicle}")
    %i.icon-truck
    =$objVehicle->Targa
  %i.icon-long-arrow-right 
  %i.icon-time
  =t('Select validity period')
  %i.icon-long-arrow-right 
  %font(color="gray")
    %i.icon-ok-circle
    =t('Select plate authorization')

- $goback_url = Yii::app()->createAbsoluteUrl($this->route,array('plateListId'=>$plateListId,'step'=>'2','ownerId'=>$ownerId))
  
.row
  .form-box 
    - $form = $this->beginWidget('bootstrap.widgets.TbActiveForm',       |
                array(                                                     |
                'id'=>'validityperiod-search-form',                                  |
                'action' => Yii::app()->createUrl($this->route),           |
                'method' => 'GET',           |
              ))                                                           |

    %input(type="hidden" name="plateListId" value="#{$plateListId}")
    %input(type="hidden" name="ownerId" value="#{$ownerId}")
    %input(type="hidden" name="vehicleId" value="#{$vehicleId}")
    %input(type="hidden" name="step" value="3")
    %input(type="hidden" name="action" value="search")

    %h3
      =t("Search validity periods")

    %input(type="text" name="what" value="#{$what}")
    %a(href="#{$currentUrl}")
      %i.icon-remove-sign
        
    - $this->endWidget()

    
    - if ($hasData)

      .tableContainer.pagination-data-container
        %table.table.table-condensed
          %thead
            %tr
              %th
              %th= ValidityPeriod::model()->getAttributeLabel('Descrizione')
              %th= ValidityPeriod::model()->getAttributeLabel('Tipo')
              %th= ValidityPeriod::model()->getAttributeLabel('DataInizio')
              %th= ValidityPeriod::model()->getAttributeLabel('DataFine')
              %th= ValidityPeriod::model()->getAttributeLabel('epoch')
              %th= t('Actions')
          
          %tbody
            - foreach($periods->data as $period)
              - $period_url = Yii::app()->createAbsoluteUrl($this->route,array('plateListId'=>$plateListId,'step'=>'4','ownerId'=>$ownerId,'vehicleId'=>$vehicleId,'validityPeriodId'=>$period->ID))
              - $delete_url = Yii::app()->createUrl('plateAuthorization/whiteListWizardDelete',array('listId'=>$plateListId, 'objType'=>'period', 'objId'=>$period->ID, 'returnUrl'=>$currentUrl))
              %tr
                %td
                  %a(href="#{$period_url}")
                    %i.icon-eye-open
                %td
                  %a(href="#{$period_url}")
                    = $period->Descrizione
                %td
                  = $period->Tipo
                %td
                  = DateHelper::formatISO9075DateTime($period->DataInizio)
                %td
                  = DateHelper::formatISO9075DateTime($period->DataFine)
                %td
                  = DateHelper::formatISO9075DateTime($period->epoch)
                %td
                  -if(Yii::app()->user->checkAccess("plate_auth_delete"))
                    %a(href="#{$delete_url}" onclick="return confirm('#{t('Are you sure you want to delete this item?')}')")
                      %i.icon-trash

      - if (isset($periods->pagination))
        .pagination.pagination-links-container
          - $this->widget('bootstrap.widgets.TbPager', array('pages' => $periods->pagination))

    - else

      %h4= Yii::t("app", "No results")
    
- if(true)
  %br
  .row
    .form-box 
      - $form = $this->beginWidget('bootstrap.widgets.TbActiveForm',       |
                array(                                                     |
                'id'=>'validityperiod-create-form',                                  |
                'action' => Yii::app()->createUrl($this->route),           |
                'method' => 'POST',           |
              ))                                                           |

      %input(type="hidden" name="plateListId" value="#{$plateListId}")
      %input(type="hidden" name="ownerId" value="#{$ownerId}")
      %input(type="hidden" name="vehicleId" value="#{$vehicleId}")
      %input(type="hidden" name="step" value="3")
      %input(type="hidden" name="action" value="create")

      %h3=t("Create validity period")

      .control-group     
        .btn-group#when-buttons
          %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='today' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
            = t('Today')
          %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='thisweek' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
            = t('This week')
          %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='thismonth' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
            = t('This month')
          %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='thisyear' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
            = t('This year')
      .control-group     
        .btn-group#when-buttons
          %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='tomorrow' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
            = t('Tomorrow')
          %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='nextweek' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
            = t('Next week')
          %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='nextmonth' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
            = t('Next month')
          %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='nextyear' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
            = t('Next year')
      -if(is_array_ex($customValidityPeriods,true))
        .control-group     
          .btn-group#when-buttons
            -$btnCVPindex=0
            -foreach($customValidityPeriods as $cvpLabel => $cvpDate)
              %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when="#{$cvpDate}" data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
                =$cvpLabel
              -$btnCVPindex++
              -if($btnCVPindex % 4 == 0 && $btnCVPindex > 0)
                %br

      %h5=ValidityPeriod::model()->getAttributeLabel('Descrizione')
      %input(type="text" name="a_description" value="#{$paramDescription}")
      =t("(for example: 'July 2012')")

      %h5=ValidityPeriod::model()->getAttributeLabel('Tipo')
      != CHtml::dropDownList('a_type', $paramType, paramdeep('plateAuthorizations','validityPeriodType'), array('class'=>'span2  chzn-select', 'data-placeholder' => Yii::t('app', 'Type...')));

      %h5=ValidityPeriod::model()->getAttributeLabel('DataInizio')
      %input#startDate.date-picker.span2(type='text' name='a_startDate' value="#{$paramStartDate}" readonly='true')
      %input#end-timestamp(type="hidden")
      %span.add-on.icon-calendar

      %h5=t('Start time')
      #datepicker-start-time.input-prepend.input-append.time-picker
        %span.add-on= t('From')
        %input#startTime.span1(data-format="#{Yii::app()->params['timeselect_format'][Yii::app()->language]['view']}" type="text"  name="a_startTime" value="#{date('H:i')}")
        %span.add-on
          %i(data-time-icon="icon-time" data-date-icon="icon-calendar")

      %h5=ValidityPeriod::model()->getAttributeLabel('DataFine')
      %input#endDate.date-picker.span2(type='text' name='a_endDate' value="#{$paramEndDate}" readonly='true')
      %input#start-timestamp(type="hidden")
      %span.add-on.icon-calendar

      %h5=t('End time')
      #datepicker-end-time.input-prepend.input-append.time-picker
        %span.add-on= t('To')
        %input#endTime.span1(data-format="#{Yii::app()->params['timeselect_format'][Yii::app()->language]['view']}" type="text"  name="a_endTime" value="#{date('H:i')}")
        %span.add-on
          %i(data-time-icon="icon-time" data-date-icon="icon-calendar")

      %br
      %br
      
      %input(type="submit" name="create" value="#{t('Create')}")
        
      - $this->endWidget()

%br
%a(href="#{$goback_url}")
  %h4=t('Go back')