-$canSeeBlack = user()->checkAccess('blacklist_visibility')
-$canSeeWhite = user()->checkAccess('whitelist_visibility')

-$listShown = array()

%h2
  .icon-file-text-alt
  = getBWListsLabels()

%table.table.table-striped
  %thead
    %th
    %th=t('Name')
    %th=t('Source')    
    %th=t('Description')
    %th
      -if(Yii::app()->user->checkAccess("plate_list_management") && user()->checkAccess("create_plate_list"))
        %a.btn.btn-mini.pull-right(href="#{Yii::app()->createAbsoluteUrl('plateList/create')}")        
          =Yii::t('app', 'New List')    
      -else
        =Yii::t('app', 'Actions')
    
  %tbody    
    - foreach($plateLists as $plateList)
      -if(Yii::app()->user->checkAccess("plate_list_management") || $plateList->userHasAccess())
        -if(($canSeeBlack && $plateList->mode==PlateList::MODE_BLACK_LIST) || ($canSeeWhite && $plateList->mode==PlateList::MODE_WHITE_LIST))
          -$listShown[] = $plateList
          %tr(class="#{(($plateList->editable)? '':'platelist-non-editable')}")
            %td
              -if($plateList->mode==PlateList::MODE_BLACK_LIST)
                %i.icon-file-text
              -else
                %i.icon-file-text-alt
              %a(href="#{Yii::app()->createUrl('plateList/view', array('id' => $plateList->id))}" target="_blank" title="#{t('Details')}")
                -if($plateList->visible)
                  %i.icon-eye-open
                -else
                  %i.icon-eye-close
              -if(user()->checkAccess("plate_auth_export_list_$code"))
                %a(href="#{Yii::app()->createUrl('plateAuthorization/PlateAuthInfoExportList', array('code' => $plateList->code))}")
                  .icon-download(title="#{t('Export')}")
            %td(title="#{t('Code').': '.$plateList->code}")
              = $plateList->name
            %td
              = $plateList->source
            %td
              = $plateList->title
            %td
              .pull-right
                .btn-group
                  -if($plateList->editable)
                    -if($plateList->mode==PlateList::MODE_WHITE_LIST && user()->checkAccess('plate_auth_insert') && (user()->checkAccess('plate_auth_insert_wizard') || user()->checkAccess('plate_auth_insert_fast') || user()->checkAccess('plate_auth_insert_profile')))
                      %a.btn.btn-small.dropdown-toggle(data-toggle="dropdown" href="#")
                        =t('New plate authorization')
                        %span.caret
                      %ul.dropdown-menu.pull-right
                        -if($plateList->maxsize > 0 && user()->checkAccess('plate_auth_scheduler'))
                          %li
                            %a.icon-table(href="#{url('plateAuthorization/scheduler',array('plateListId' => $plateList->id))}")
                              = t("Scheduler")
                        -if(user()->checkAccess('plate_auth_insert') && user()->checkAccess('plate_auth_insert_fast'))
                          %li
                            %a(href="#{Yii::app()->createUrl('plateAuthorization/newWhitelist', array('plateListId' => $plateList->id))}" target="_blank")
                              = Yii::t("app", ("Fast insert"))             
                        -if(user()->checkAccess('plate_auth_insert') && user()->checkAccess('plate_auth_insert_wizard'))
                          %li
                            %a(href="#{Yii::app()->createUrl('plateAuthorization/whiteListWizard', array('plateListId' => $plateList->code))}" target="_blank")
                              = Yii::t("app", ("Wizard"))              
                        -if(user()->checkAccess('plate_auth_insert') && user()->checkAccess('plate_auth_insert_profile'))
                          -foreach(PlateAuthInsertProfile::model()->findAll() as $paip)
                            -if(user()->checkAccess("plate_auth_insert_profile_".$paip->id) && ($paip->list_code==-1 || $paip->list_code==$plateList->code))
                              %li
                                %a(href="#{Yii::app()->createUrl('plateAuthorization/NewPlateAuthProfile', array('plateListId' => $plateList->code, 'profileId'=>$paip->id))}" target="_blank")
                                  = Yii::t("app", $paip->description)
                    -if($plateList->mode==PlateList::MODE_BLACK_LIST)
                      -if(user()->checkAccess('plate_auth_insert'))
                        %a.btn.btn-small.dropdown-toggle(data-toggle="dropdown" href="#")
                          =t('New blacklist vehicle')
                          %span.caret
                        %ul.dropdown-menu.pull-right
                          -if(user()->checkAccess('plate_auth_insert_fast'))
                            %li
                              %a(target='_blank' href="#{Yii::app()->createUrl('plateAuthorization/newBlacklist', array('plateListId' => $plateList->id))}")
                                = Yii::t("app", ("Add vehicle"))
                          -if(user()->checkAccess('plate_auth_insert_profile'))
                            -foreach(PlateAuthInsertProfile::model()->findAll() as $paip)
                              -if(user()->checkAccess("plate_auth_insert_profile_".$paip->id) && ($paip->list_code==-1 || $paip->list_code==$plateList->code))
                                %li
                                  %a(href="#{Yii::app()->createUrl('plateAuthorization/NewPlateAuthProfile', array('plateListId' => $plateList->code, 'profileId'=>$paip->id))}" target="_blank")
                                    = Yii::t("app", $paip->description)
      
                -if(user()->checkAccess('plate_auth_status'))
                  .btn-group
                    %a.btn.btn-small(href="#{url('plateAuthorization/whitelistStatus', array('plateListId'=>$plateList->code))}")
                      -if($plateList->isWhitelist()) 
                        = Yii::t("app", ("Manage plate authorizations"))
                      -else
                        = Yii::t("app", ("Manage blacklists"))
                .btn-group
                  %a.btn.btn-small(href="#{url('plateAuthorization/list', array('plateListId'=>$plateList->id))}")
                    = Yii::t("app", ("Manage list"))

-if(user()->checkAccess('plate_auth_status') && user()->checkAccess('plate_auth_status_global'))
  %h4
    %a.btn.btn-mini.pull-right(href="#{url('plateAuthorization/whitelistStatus', array('plateListId'=>-1))}" style="margin-left: 10px;")
      -if($plateList->mode==PlateList::MODE_BLACK_LIST)
        =t('Manage all vehicles in all blacklists')
      -else
        =t('Manage plate authorizations for all lists')

-if(user()->checkAccess('plate_auth_import'))
  %h4
    %a.btn.btn-mini.pull-right(href="#{url('plateAuthorization/PlateAuthInfoImport')}" style="margin-left: 10px;")
      =t('Import plate authorizations')

-if(user()->checkAccess('plate_auth_export_all'))
  %h4
    %a.btn.btn-mini.pull-right(href="#{url('plateAuthorization/PlateAuthInfoExportAll')}" style="margin-left: 10px;" onclick="return confirm('#{t('Confirm operation?')}');")
      =t('Export all plate authorizations')

-if(user()->checkAccess('plate_simulate_transit'))
  %h4
    %a.btn.btn-mini.pull-right(href="#{url('plateAuthorization/TransitSimulation')}" style="margin-left: 10px;")
      =t('Simulate transit')

- if( count($listShown)<=0 && !(user()->checkAccess("plate_list_management") || user()->checkAccess("plate_list_view")) )
  - $this->redirect(Yii::app()->createUrl())

- if( count($listShown) == 1 && !user()->checkAccess("plate_list_management") )
  - $this->redirect(Yii::app()->createUrl('plateAuthorization/list', array('plateListId' => $listShown[0]->id)))
                        