<?php if(!is_bool($canEdit)) { ?>
  <?php $canEdit = ServiceController::canEdit(); ?>
<?php } ?>
<!-- *Modificato argomento if a seguito di rilevazione campo report islanda mancante-> modificato con nuova tabella delle verità che aggiunge il caso : Tutti gli eventi validi e parametro completeService(true) e confermati > 0 e task NON esportato/registrato, 03/01/2019 NGasbarro */  -->
<?php /*if (Yii::app()->user->checkAccess('create_events_report') &&  ($service->areAllEventsValidatedAndNotSuspended() || (!paramdeep('report','completeService') && $service->toBeConfirmed > 0 )) && (!$service->isRegistered() && !paramdeep('report','completeService')) )*/ { ?>
  <?php /*$readyForReport = true*/; ?>
<?php } ?>
<?php if (Yii::app()->user->checkAccess('create_events_report') &&  (!$service->isRegistered() && ($service->areAllEventsValidatedAndNotSuspended()&& ($service->toBeConfirmed > 0) || ($service->toBeConfirmed > 0) && (!paramdeep('report','completeService')) || $service->areAllEventsValidatedAndNotSuspended() && (!paramdeep('report','completeService')) ))) { ?>
  <?php $readyForReport = true; ?>
<?php } ?>
<?php if($canEdit) { ?>
  <?php if($service->status == Service::STATUS_READY_TO_EVALUATE) { ?>
    <?php if($service->isAssignedTo(user()->id)) { ?>
      <div class="btn-group">
        <?php if($readyForReport) { ?>
          <a class="btn btn-small btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
            <?php echo htmlspecialchars(Yii::t("app", "Actions")     ,ENT_QUOTES,'UTF-8'); ?>
            <span class="caret"></span>
          </a>
        <?php } else { ?>
          <a class="btn btn-small dropdown-toggle" data-toggle="dropdown" href="#">
            <?php echo htmlspecialchars(Yii::t("app", "Actions")     ,ENT_QUOTES,'UTF-8'); ?>
            <span class="caret"></span>
          </a>
        <?php } ?>
        <ul class="dropdown-menu pull-right">
          <?php if (user()->checkAccess('check_events') && !user()->checkAccess('verify_all_events')) { ?>
            <li>
              <a <?php echo MtHaml\Runtime::renderAttributes(array(array('href', (Yii::app()->createUrl('event/indexFilter', array('service' => $service->ID, 'scope' => 'newEvents'))))), 'html5', 'UTF-8'); ?>>
                <?php echo htmlspecialchars(Yii::t("app", ("to be checked")),ENT_QUOTES,'UTF-8'); ?>
              </a>
            </li>
          <?php } ?>
          <?php if (user()->checkAccess('verify_all_events')) { ?>
            <?php if (user()->checkAccess('verify_suspended_events')) { ?>
              <li>
                <a <?php echo MtHaml\Runtime::renderAttributes(array(array('href', (Yii::app()->createUrl('event/indexFilter', array('service' => $service->ID, 'scope' => 'notClosedEvents', 'toValidateOnly' => true))))), 'html5', 'UTF-8'); ?>>
                  <?php echo htmlspecialchars(Yii::t("app", "all"),ENT_QUOTES,'UTF-8'); ?>
                </a>
              </li>
            <?php } else  { ?>
              <li>
                <a <?php echo MtHaml\Runtime::renderAttributes(array(array('href', (Yii::app()->createUrl('event/indexFilter', array('service' => $service->ID, 'scope' => 'notClosedNotPendingEvents'))))), 'html5', 'UTF-8'); ?>>
                  <?php echo htmlspecialchars(Yii::t("app", "all"),ENT_QUOTES,'UTF-8'); ?>
                </a>
              </li>
            <?php } ?>
          <?php } ?>
          <?php if (user()->checkAccess('verify_checked_events')) { ?>
            <?php if (user()->checkAccess('verify_suspended_events')) { ?>
              <li>
                <a <?php echo MtHaml\Runtime::renderAttributes(array(array('href', (Yii::app()->createUrl('event/indexFilter', array('service' => $service->ID, 'scope' => 'examinedNotClosedEvents'))))), 'html5', 'UTF-8'); ?>>
                  <?php echo htmlspecialchars(Yii::t("app", "checked"),ENT_QUOTES,'UTF-8'); ?>
                </a>
              </li>
            <?php } else { ?>
              <li>
                <a <?php echo MtHaml\Runtime::renderAttributes(array(array('href', (Yii::app()->createUrl('event/indexFilter', array('service' => $service->ID, 'scope' => 'examinedNotClosedNotPendingEvents'))))), 'html5', 'UTF-8'); ?>>
                  <?php echo htmlspecialchars(Yii::t("app", "checked"),ENT_QUOTES,'UTF-8'); ?>
                </a>
              </li>
            <?php } ?>
          <?php } ?>
          <?php if (user()->checkAccess('verify_suspended_events')) { ?>
            <li>
              <a <?php echo MtHaml\Runtime::renderAttributes(array(array('href', (Yii::app()->createUrl('event/indexFilter', array('service' => $service->ID, 'scope' => 'pendingNotClosedEvents'))))), 'html5', 'UTF-8'); ?>>
                <?php echo htmlspecialchars(Yii::t("app", "suspended"),ENT_QUOTES,'UTF-8'); ?>
              </a>
            </li>
          <?php } ?>
          <?php if (user()->checkAccess('confirm_all_events')) { ?>
            <li>
              <a <?php echo MtHaml\Runtime::renderAttributes(array(array('href', (Yii::app()->createUrl('service/confirmAllEvents', array('id' => $service->ID, 'url'=>$this->createUrl('service/index')))))), 'html5', 'UTF-8'); ?>>
                <?php echo htmlspecialchars(Yii::t("app", "confirm all"),ENT_QUOTES,'UTF-8'); ?>
              </a>
            </li>
          <?php } ?>
          <?php if (Yii::app()->user->checkAccess('create_events_report') && !paramdeep('report','byWorkPeriod') && $readyForReport )       { ?>
            <?php if (($service->areAllEventsValidatedAndNotSuspended() || (!$service->isRegistered() && !paramdeep('report','completeService')))) { ?>
              <?php if(paramdeep('report','showPreviewButton')) { ?>
                <li>
                  <?php if(paramdeep('report','showReportPreviewPage')) { ?>
                    <a <?php echo MtHaml\Runtime::renderAttributes(array(array('href', (Yii::app()->createAbsoluteUrl('report/previewByService', array('serviceID' => $service->ID))))), 'html5', 'UTF-8'); ?>>
                      <?php echo htmlspecialchars(t("Report"),ENT_QUOTES,'UTF-8'); ?>
                    </a>
                  <?php } else { ?>
                    <a <?php echo MtHaml\Runtime::renderAttributes(array(array('href', (Yii::app()->createAbsoluteUrl('report/createByService', array('serviceID' => $service->ID))))), 'html5', 'UTF-8'); ?>>
                      <?php echo htmlspecialchars(t("Report"),ENT_QUOTES,'UTF-8'); ?>
                    </a>
                  <?php } ?>
                </li>
              <?php } ?>
            <?php } ?>
          <?php } ?>
        </ul>
      </div>
    <?php } ?>
  <?php } else if($service->status == Service::STATUS_TERMINATION_CONFIRMED) { ?>
    <?php if (user()->checkAccess('can_set_service_ready_to_evaluate')) { ?>
      <button <?php echo MtHaml\Runtime::renderAttributes(array(array('class', ('to-evaluate' . ' ' . 'btn' . ' ' . 'btn-small')), array('data-service-id', ($service->ID)), array('data-confirm-text', (Yii::t('app', 'Confirm?')))), 'html5', 'UTF-8'); ?>>
        <?php echo htmlspecialchars(Yii::t("app", "Evaluate"),ENT_QUOTES,'UTF-8'); ?>
      </button>
    <?php } ?>
  <?php } ?>
<?php } ?>
