Ejemplo n.º 1
0
 public function getOutput()
 {
     $output = new JsonOutput();
     $td_code = gfGetVar('td_code', null);
     if (!$td_code) {
         $output->setContent(array('result' => 'error'));
         return $output;
     }
     // check td existence and activation
     $td = TopicalDomain::fromDatabaseByCode($td_code);
     if (!$td) {
         $output->setContent(array('result' => 'error'));
         return $output;
     }
     if (!$td->getActive()) {
         $output->setContent(array('result' => 'error'));
         return $output;
     }
     $ticket = Ticket::nextNewTicket($td_code, 'totem');
     $ticket->save();
     list($queueLength, $eta) = $ticket->getPeopleAndEta();
     $content = array('code' => $ticket->getCode(), 'number' => $ticket->getNumber(), 'eta' => $eta, 'queueLength' => $queueLength);
     $jsonOutput = new JsonOutput();
     $jsonOutput->setContent($content);
     return $jsonOutput;
 }
Ejemplo n.º 2
0
 public function execute()
 {
     global $gvOfficeCode, $gvQueueLengthAppLimit, $gvQueueEtaAppLimit;
     if (empty($_POST['queueCode']) || empty($_POST['noticeBefore'])) {
         throw new InvalidParamException();
     } else {
         $td_code = $_POST['queueCode'];
         $noticeBefore = $_POST['noticeBefore'];
     }
     if ($noticeBefore <= 0) {
         throw new InvalidParamException();
     } else {
         $noticeBefore = (int) $noticeBefore;
     }
     if (Ticket::fromDatabaseBySourceId($this->token)) {
         return array('ErrorCode' => "AE???", 'ErrorMsg' => "Ticket already exists for this token");
     }
     $td = TopicalDomain::fromDatabaseByCode($td_code);
     if (!$td || !$td->getActive()) {
         return array('ErrorCode' => "AE003", 'ErrorMsg' => "Queue specified does not exist");
     }
     if ($td->getEta() < $gvQueueEtaAppLimit || Ticket::getNumberTicketInQueue($td_code) < $gvQueueLengthAppLimit) {
         return array('ErrorCode' => "AE???", 'ErrorMsg' => "Queue limit not satisfied");
     }
     $ticket = Ticket::nextNewTicket($td_code, 'app', $this->token, $noticeBefore);
     $ticket->save();
     list($people, $eta) = $ticket->getPeopleAndEta();
     $content = array();
     $content['OfficeCode'] = $gvOfficeCode;
     $content['Ticket'] = $ticket->getTextString();
     $content['Eta'] = (int) ($eta / 60);
     $content['PeopleBefore'] = $people;
     $content['AssignedNoticeBefore'] = $noticeBefore;
     return $content;
 }
Ejemplo n.º 3
0
 public function afterPermissionCheck()
 {
     if (gfGetVar('reset', false)) {
         Session::setupWebSession();
     }
     $this->redirect = Session::redirectLastStep(0);
     $this->tdList = TopicalDomain::fromDatabaseCompleteList();
 }
Ejemplo n.º 4
0
 private function removeTopicalDomain()
 {
     $td_id = $_GET['td_id'];
     $td = TopicalDomain::fromDatabaseById($td_id);
     if ($td) {
         if ($td->getActive()) {
             return 'notDeactivated';
         }
         if ($td->delete()) {
             return 'true';
         }
     }
     return 'false';
 }
Ejemplo n.º 5
0
 public function getOutput()
 {
     $tds = TopicalDomain::fromDatabaseCompleteList(true);
     $content = array();
     $i = 0;
     foreach ($tds as $td) {
         $content[$i]['code'] = $td->getCode();
         $content[$i]['name'] = $td->getName();
         $content[$i]['description'] = $td->getDescription();
         $content[$i]['color'] = $td->getColor();
         $i++;
     }
     $jsonOutput = new JsonOutput();
     $jsonOutput->setContent($content);
     return $jsonOutput;
 }
Ejemplo n.º 6
0
 public function execute()
 {
     global $gvOfficeCode;
     $tdList = TopicalDomain::fromDatabaseCompleteList();
     $content = array();
     if (!$tdList) {
         $content['ErrorCode'] = "AE003";
         $content['ErrorMsg'] = "No queues in this office";
         return $content;
     }
     $content['OfficeCode'] = $gvOfficeCode;
     $content['NumQueues'] = count($tdList);
     $content['Queues'] = array();
     foreach ($tdList as $td) {
         $queueObj = array('Code' => $td->getCode(), 'Name' => $td->getName(), 'Description' => $td->getDescription(), 'Eta' => (int) ($td->getEta() / 60), 'PeopleWaiting' => Ticket::getNumberTicketInQueue($td->getCode()));
         $content['Queues'][] = $queueObj;
     }
     return $content;
 }
Ejemplo n.º 7
0
 private function performRequest()
 {
     $resultFalse = array('result' => 'false');
     if (!isset($_GET['td_id'])) {
         return $resultFalse;
     }
     $td_id = $_GET['td_id'];
     $td = TopicalDomain::fromDatabaseById($td_id);
     if (!$td) {
         return $resultFalse;
     }
     if ($td->getActive() == 1 && !$td->canBeDeactivated()) {
         return array('result' => 'ticketInQueue');
     }
     $td->setActive($td->getActive() ? 0 : 1);
     if ($td->save()) {
         return array('result' => 'true');
     }
     return $resultFalse;
 }
Ejemplo n.º 8
0
    private function getTdStatsRows()
    {
        $rows = '';
        $tdList = TopicalDomain::fromDatabaseCompleteList(false);
        foreach ($tdList as $td) {
            $tickets = TicketStats::fromDatabaseListByCode($td->getCode(), $this->dateFrom, $this->dateTo);
            $accumulatorWait = 0;
            $accumulatorService = 0;
            $counter = 0;
            foreach ($tickets as $ticket) {
                // Do not count canceled ticket
                if (!$ticket->getTimeExec()) {
                    continue;
                }
                $wait = $ticket->getTimeExec() - $ticket->getTimeIn();
                $accumulatorWait += $wait;
                $service = $ticket->getTimeOut() - $ticket->getTimeExec();
                $accumulatorService += $service;
                $counter++;
            }
            if ($counter) {
                $averageWait = (int) ($accumulatorWait / $counter / 60);
                $averageService = (int) ($accumulatorService / $counter / 60);
            } else {
                $averageWait = 0;
                $averageService = 0;
            }
            $rows .= <<<EOS
<tr>
    <td>{$td->getCode()}</td>
    <td>{$counter}</td>
    <td>{$averageWait} min</td>
    <td>{$averageService} min</td>
</tr>
EOS;
        }
        if (!$rows) {
            $rows = '<tr><td colspan="3">Nessuna statistica disponibile</td></tr>';
        }
        return $rows;
    }
Ejemplo n.º 9
0
 public function execute()
 {
     global $gvPath, $gvPhoneCodeLength;
     if ($this->redirect) {
         return $this->redirect;
     }
     $this->message = '';
     $phone_code = gfPostVar('phone_code', '');
     $phone_code = strtoupper($phone_code);
     if (!$phone_code) {
         $this->message = 'Il campo è obbligatorio.';
         return true;
     }
     if ($phone_code != $this->phone_code) {
         $this->message = 'Il codice inserito non è corretto.';
         return true;
     }
     // check td existence and activation
     $td_code = gfSessionVar('td_code', '');
     $td = TopicalDomain::fromDatabaseByCode($td_code);
     if (!$td || !$td->getActive()) {
         // This is very improbable in this
         // case start again the wizard
         $_SESSION['step'] = 0;
         return true;
     }
     $ticket = Ticket::nextNewTicket($td_code, 'web', gfSessionVar('phone'));
     $ticket->save();
     $sender = new SmsSender(gfSessionVar('phone'));
     if (!$sender->sendNewTicket($ticket)) {
         // False means error while sending
         $this->message = "Errore nella prenotazione. Assicurarsi di aver inserito il numero corretto.";
         return true;
     }
     $_SESSION['step'] = 3;
     $_SESSION['ticket'] = $ticket;
     $redirect = new RedirectOutput("{$gvPath}/web/complete");
     return $redirect;
 }
Ejemplo n.º 10
0
    private function getTableBody()
    {
        global $gvPath;
        $topDomains = TopicalDomain::fromDatabaseCompleteList(false);
        if (count($topDomains) === 0) {
            return '<tr><td colspan="5" class="noEntry">Nessuna area tematica</td></tr>';
        }
        $ret = "";
        foreach ($topDomains as $topDomain) {
            $checkbox = $this->getCheckbox($topDomain);
            $ret .= <<<EOS
<tr>
        <td>{$topDomain->getCode()}</td>
        <td>{$topDomain->getName()}</td>
        <td>{$topDomain->getDescription()}</td>
        <td>{$checkbox}</td>
\t<td><a href="{$gvPath}/application/adminTopicalDomainEdit?td_id={$topDomain->getId()}" class="tdEditLink">Modifica</a>&nbsp;&nbsp;
        <a class="ajaxRemove" href="{$gvPath}/ajax/removeRecord?td_id={$topDomain->getId()}">Rimuovi</a></td>
</tr>
EOS;
        }
        return $ret;
    }
Ejemplo n.º 11
0
 private function getTableBody()
 {
     $topicalDomains = TopicalDomain::fromDatabaseCompleteList(true);
     $tableBody = '';
     for ($i = 0; $i < count($topicalDomains); $i++) {
         $td = $topicalDomains[$i];
         $description = $td->getCode() . " - " . htmlspecialchars($td->getName());
         $queueLength = Ticket::getNumberTicketInQueue($td->getCode());
         $checkbox = $this->getCheckBox($td->getCode(), $description, $queueLength, in_array($td->getCode(), $this->td_served));
         if ($i % 4 === 0) {
             $tableBody .= "<tr>\n";
         }
         $tableBody .= "<td style=\"padding: 5px;\">{$checkbox}</td>\n";
         if (($i + 1) % 4 === 0) {
             $tableBody .= "</tr>\n";
         }
     }
     // Close row if not closed
     if (substr($tableBody, -6) !== "</tr>\n") {
         $tableBody .= "</tr>\n";
     }
     return $tableBody;
 }
Ejemplo n.º 12
0
 private function getComboboxTd()
 {
     $ret = '<select name="dev_td_code" id="dev_td_code">';
     $ret .= PHP_EOL . '<option value="0">Tutte</option>';
     foreach (TopicalDomain::fromDatabaseCompleteList() as $td) {
         $code = $td->getCode();
         $selected = $this->dev_td_code === $code ? ' selected' : '';
         $ret .= "\n<option value=\"{$code}\"{$selected}>{$code}</option>";
     }
     $ret .= "\n</select>";
     return $ret;
 }
Ejemplo n.º 13
0
 private function getComboBoxForCode()
 {
     $ret = '<select name="td_code" id="td_code">';
     $availableCodes = TopicalDomain::getAvailableCodes();
     if ($this->td_code) {
         // Let be sure to always list the actual code
         if (!in_array($this->td_code, $availableCodes)) {
             $availableCodes[] = $this->td_code;
             sort($availableCodes);
         }
     }
     foreach ($availableCodes as $code) {
         $selected = $this->td_code === $code ? ' selected' : '';
         $ret .= "\n<option value=\"{$code}\"{$selected}>{$code}</option>";
     }
     $ret .= "\n</select>";
     return $ret;
 }
Ejemplo n.º 14
0
 public static function nextNewTicket($td_code, $source = 'totem', $source_id = '', &$noticeBefore = -1)
 {
     if (!in_array($source, array('totem', 'web', 'app'))) {
         throw new Exception(__METHOD__ . " Invalid source value");
     }
     if ($source == 'totem') {
         $noticeBefore = -1;
         $source_id = '';
     } else {
         if (!$source_id) {
             throw new Exception(__METHOD__ . " web and app tickets need a source_id");
         }
     }
     $ticket = self::newRecord('ticket_in');
     $ticket->setCode($td_code);
     $ticket->setTimeIn(time());
     $ticket->setSource($source);
     $ticket->setSourceId($source_id);
     // Check existence of topical domain
     $td = TopicalDomain::fromDatabaseByCode($td_code);
     if (!$td || !$td->getActive()) {
         throw new Exception(__METHOD__ . " td_code not valid");
     }
     $number = $td->incrementNextGeneratedTicket();
     $td->save();
     $ticket->setNumber($number);
     if ($source != 'totem') {
         $ticketBefore = self::countTicketBefore($td_code, $number);
         if ($source == 'web') {
             $ticket->setNoticeCounter((int) ($ticketBefore / 2));
         } else {
             $ticket->setNoticeBeforeForApp($noticeBefore, $ticketBefore);
         }
     }
     return $ticket;
 }