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

- $hasData = isset($auths) && count($auths->data)>0
- $types = paramdeep('plateAuthorizations','types')
- $gates = array('-1' => t('Every gate')) + PlateAuthorizationController::getGateObjects()
- $times = array('-1' => t('Always')) + TimeSchedule::getTimeScheduleArrayForPlateAuths()

- if(!array_key_exists(paramdeep('plateAuthorizations','default','plateAuthType'),$types))
  -$types[paramdeep('plateAuthorizations','default','plateAuthType')] = paramdeep('plateAuthorizations','default','plateAuthType')

- if(!array_key_exists(paramdeep('plateAuthorizations','default','time'),$times))
  -$times[paramdeep('plateAuthorizations','default','time')] = paramdeep('plateAuthorizations','default','time')

- if(!array_key_exists(paramdeep('plateAuthorizations','default','gate'),$gates))
  -$gates[paramdeep('plateAuthorizations','default','gate')] = paramdeep('plateAuthorizations','default','gate')

.page-header
  %h2
    %i.icon-ok-circle
    =t('Plate authorizations')

%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
  - $navigate_url_period = Yii::app()->createAbsoluteUrl($this->route,array('plateListId'=>$plateListId,'step'=>'3','ownerId'=>$ownerId,'vehicleId'=>$vehicleId))
  %i.icon-long-arrow-right 
  %a(href="#{$navigate_url_period}")
    %i.icon-time
    =$objPeriod->Descrizione
  %i.icon-long-arrow-right 
  %i.icon-ok-circle
  =t('Select plate authorization')

- $goback_url = Yii::app()->createAbsoluteUrl($this->route,array('plateListId'=>$plateListId,'step'=>'3','ownerId'=>$ownerId,'vehicleId'=>$vehicleId))
  

.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="validityPeriodId" value="#{$validityPeriodId}")
    %input(type="hidden" name="step" value="4")
    %input(type="hidden" name="action" value="search")

    %h3
      =t("Plate authorizations list")

    - $this->endWidget()
    
    - if ($hasData)

      .tableContainer.pagination-data-container
        %table.table.table-condensed
          %thead
            %tr
              %th
              %th= PlateAuthorization::model()->getAttributeLabel('Descrizione')
              %th= PlateAuthorization::model()->getAttributeLabel('GateID')
              %th= PlateAuthorization::model()->getAttributeLabel('TimeID')
              %th= PlateAuthorization::model()->getAttributeLabel('type')
              %th= PlateAuthorization::model()->getAttributeLabel('epoch')
              %th= t('Status')
              %th= t('Submitted by')
              %th= t('Actions')
          
          %tbody
            - foreach($auths->data as $plateAuth)              
              - $da = new DateTime();
              - $a = $plateAuth->validityPeriod->DataFine;
              - $diff = $da->diff($a);
              - $expired = ($diff->format('%R') == '-');
              - $item_url = Yii::app()->createUrl('plateAuthorization/'.$plateAuth->ID, array('fromWizard'=>1))
              - $delete_url = Yii::app()->createUrl('plateAuthorization/whiteListWizardDelete',array('listId'=>$plateListId, 'objType'=>'auth', 'objId'=>$plateAuth->ID, 'returnUrl'=>$currentUrl))
              - $renew_url = Yii::app()->createUrl('plateAuthorization/renew',array('plateAuthId'=>$plateAuth->ID, 'returnUrl'=>$currentUrl))
              - $revoke_url = Yii::app()->createUrl('plateAuthorization/revoke',array('plateAuthId'=>$plateAuth->ID, 'returnUrl'=>$currentUrl))
              - $enable_url = Yii::app()->createUrl('plateAuthorization/activate',array('plateAuthId'=>$plateAuth->ID, 'returnUrl'=>$currentUrl))
              - $confirm_url = Yii::app()->createUrl('plateAuthorization/confirm',array('plateAuthId'=>$plateAuth->ID, 'returnUrl'=>$currentUrl))
              - $print_url = Yii::app()->createUrl('plateAuthorization/print',array('id'=>$plateAuth->ID))
              
              %tr
                %td
                  %a(href="#{$item_url}" title="#{t('View')}")
                    %i.icon-eye-open
                %td
                  %a(href="#{$item_url}") = $plateAuth->Descrizione
                %td
                  != SystemInfoHelper::getPlateAuthGateCoolName($plateAuth->GateID,$plateAuth->GateID_type)
                %td
                  != SystemInfoHelper::getTimeScheduleCoolName($plateAuth->TimeID)
                %td
                  = $types[$plateAuth->type]
                %td
                  = $plateAuth->epoch
                %td
                  -if($plateAuth->to_be_confirmed)
                    =t('To be confirmed')
                  -else if($plateAuth->enabled != 1)
                    =t('Disabled')
                  -else if($expired)
                    =t('Expired')
                  -else
                    =t('Activated')
                %td 
                  -if(Yii::app()->user->checkAccess('user_view') && $plateAuth->insertid>0)
                    %a(href="#{Yii::app()->createUrl('user/'.$plateAuth->insertid)}")
                      %i
                        = $plateAuth->getSubmitter()
                  -else
                    %i
                      = $plateAuth->getSubmitter()
                %td
                  -$this->printPrintBtn($plateAuth)
                  -if(Yii::app()->user->checkAccess('plate_auth_enable'))
                    -if($plateAuth->enabled == 1)
                      %a(href="#{$revoke_url}" title="#{t('Revoke')}")
                        %i.icon-stop
                    -else
                      %a(href="#{$enable_url}" title="#{t('Activate')}")
                        %i.icon-play
                  -if($plateAuth->to_be_confirmed == 1 && Yii::app()->user->checkAccess('plate_auth_confirmed'))
                    %a(href="#{$confirm_url}" title="#{t('Confirm')}")
                      %i.icon-unlock-alt
                  -if(Yii::app()->user->checkAccess('plate_auth_renew'))
                    %a(href="#{$renew_url}" title="#{t('Renew')}")
                      %i.icon-repeat
                  -if(Yii::app()->user->checkAccess('plate_auth_delete'))
                    %a(href="#{$delete_url}" title="#{t('Delete')}" onclick="return confirm('#{t('Are you sure you want to delete this item?')}')")
                      %i.icon-trash


      - if (isset($auths->pagination))
        .pagination.pagination-links-container
          - $this->widget('bootstrap.widgets.TbPager', array('pages' => $auths->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="validityPeriodId" value="#{$validityPeriodId}")
      %input(type="hidden" name="step" value="4")
      %input(type="hidden" name="action" value="create")

      %h3=t("Create plate authorization")

      %h5=PlateAuthorization::model()->getAttributeLabel('Descrizione')
      %input(type="text" name="p_description" value="#{paramdeep('plateAuthorizations','default','plateAuthDescription')}")
      =t("(for example: 'Harry Potter, FIAT Panda, July 2012')")

      %h5
        =PlateAuthorization::model()->getAttributeLabel('type')
        %font(color="red")='*'
      != CHtml::dropDownList('p_type', paramdeep('plateAuthorizations','default','plateAuthType'), $types, array('class'=>'span2  chzn-select', 'data-placeholder' => Yii::t('app', 'Type...')));

      %h5
        =PlateAuthorization::model()->getAttributeLabel('GateID')
        %font(color="red")='*'
      != CHtml::dropDownList('p_gate', paramdeep('plateAuthorizations','default','gate'), $gates, array('class'=>'span2  chzn-select', 'data-placeholder' => Yii::t('app', 'Gate...')));

      %h5
        =PlateAuthorization::model()->getAttributeLabel('TimeID')
        %font(color="red")='*'
      != CHtml::dropDownList('p_time', paramdeep('plateAuthorizations','default','time'), $times, array('class'=>'span2  chzn-select', 'data-placeholder' => Yii::t('app', 'Time zone...')));

      %h5=PlateAuthorization::model()->getAttributeLabel('action')
      != CHtml::textArea('p_action', paramdeep('plateAuthorizations','default','plateAuthAction'), array('class'=>'span2', 'maxlength' => '250'));

      %h5=PlateAuthorization::model()->getAttributeLabel('Note')
      != CHtml::textArea('p_note', paramdeep('plateAuthorizations','default','plateAuthNote'), array('class'=>'span2', 'maxlength' => '250'));

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

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