#!/usr/bin/php -q deviceOpen("a+b"); } $numReg = 0; $arquivo = ''; $bilhetesSerial = array(); $rows = @ClassificaBilhetes($data, $metodo); //ramal,data,duracao,numero,rota,tronco,ramaltransfer,tpLigacao,contaSenha,ramalOrig,procid,reg,uid,id, foreach ($rows as $row) { $ignorado = " "; if ($metodo == INTEGRA_SERIAL) { $bilhetesSerial[$row["id"]] = $data; } //$id_bilhetes = $row["uid"]; $ramal = substr(trim($row["ramal"]), -4); //if(strlen($ramal) > 4)$ramal = substr ($ramal, -4); $ramal = str_pad($ramal, 5, " ", STR_PAD_RIGHT); $dataBil = $row["data"]; $duracao = SecondToStrTime($row["duracao"]); $rota = ""; $tronco = str_pad(trim(AjustaTronco($row["tronco"])), 4, "0", STR_PAD_LEFT); $numero = trim($row["numero"]); $numero = (substr($numero, 0, 1) == "0") ? substr($numero, 1) : $numero; $numero = str_pad($numero, 16, " ", STR_PAD_RIGHT); $ramaltransfer = str_pad("", 4, " ", STR_PAD_RIGHT); $tpLigacao = trim(strtoupper($row["tpLigacao"])); $sep = " "; $ramalVerifica = trim($ramal); if (($tpLigacao == 'O') && (is_numeric($ramalVerifica))) { $linha = sprintf('%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s', $ignorado, $ramal, $sep, $dataBil, $sep, $duracao, $sep, $rota, $sep, $tronco, $sep, $numero, $sep, $ramaltransfer, $sep, $tpLigacao, "\n"); $arquivo .= $linha; if ($metodo == INTEGRA_SERIAL) { $recurso->sendMessage($linha, 0.2); $retSck = true; LogTrf("GeraBilhetes", "sendMessage", $linha); } else { $retSck = fwrite($recurso, $linha); } if (!$retSck) break; $numReg++; } if ($metodo == INTEGRA_SOCKET) usleep(200000); } if ($retSck) { if ($metodo == INTEGRA_SERIAL) { AtulizaInfo($conn, 0, $bilhetesSerial, '', INTEGRA_SERIAL); } else { if (!GetIsDataInfo()) { AtulizaInfo($conn, $numReg, $arquivo, $data); } } LogTrf("GeraBilhetes", "Geração dos Bilhetes", "Arquivo exportado: " . $GLOBALS["data"]); } else { $erro_info = error_get_last(); $erro = $erro_info['message']; LogTrf("GeraBilhetes", "Geração dos Bilhetes", "Erro ao Atualizar Arquivo! Erro: " . $erro); } } else { if ($metodo == INTEGRA_SERIAL) LogTrf("Conexao", "Acesso Tarifador", "Erro ao conectar a porta Serial"); else LogTrf("Conexao", "Acesso Tarifador", "Erro ao conectar servidor de socket"); } if ($metodo == INTEGRA_SERIAL) $recurso->deviceClose(); else @fclose($recurso); } function GetDataInfo($argv, &$isDataInfo, $type = 0) { $dataUser = isset($argv[1]) ? trim($argv[1]) : ''; $dataInfo = ($type == INTEGRA_SERIAL) ? ($dataUser ? $dataUser : date('Y-m-d') ) : $dataUser; $isDataInfo = !empty($dataInfo); return array($dataInfo); } function GetIsDataInfo() { return $GLOBALS["isDataInfo"]; } function VerificaFileExists($metodo, $data) { return ($metodo == INTEGRA_FILE) && file_exists(GetPathFile($data)); } ?>