Ejemplo n.º 1
0
 public function ProcessFlight($extId)
 {
     if (is_int($extId)) {
         $flightId = $extId;
         $avaliableFlights = $this->_user->GetAvaliableFlights($this->_user->username);
         if (in_array($flightId, $avaliableFlights)) {
             $Fl = new Flight();
             $flightInfo = $Fl->GetFlightInfo($flightId);
             $apTableName = $flightInfo["apTableName"];
             $bpTableName = $flightInfo["bpTableName"];
             $excEventsTableName = $flightInfo["exTableName"];
             $startCopyTime = $flightInfo["startCopyTime"];
             $tableGuid = substr($apTableName, 0, 14);
             unset($Fl);
             $Bru = new Bru();
             $bruInfo = $Bru->GetBruInfo($flightInfo["bruType"]);
             $excListTableName = $bruInfo["excListTableName"];
             $apGradiTableName = $bruInfo["gradiApTableName"];
             $bpGradiTableName = $bruInfo["gradiBpTableName"];
             $stepLength = $bruInfo["stepLength"];
             if ($excListTableName != "") {
                 $bruInfo = $Bru->GetBruInfo($flightInfo["bruType"]);
                 $excListTableName = $bruInfo["excListTableName"];
                 $apGradiTableName = $bruInfo["gradiApTableName"];
                 $bpGradiTableName = $bruInfo["gradiBpTableName"];
                 $FEx = new FlightException();
                 $FEx->DropFlightExceptionTable($excEventsTableName);
                 $flightExTableName = $FEx->CreateFlightExceptionTable($flightId, $tableGuid);
                 //Get exc refParam list
                 $excRefParamsList = $FEx->GetFlightExceptionRefParams($excListTableName);
                 $exList = $FEx->GetFlightExceptionTable($excListTableName);
                 //file can be accesed by ajax what can cause warning
                 error_reporting(E_ALL ^ E_WARNING);
                 //perform proc be cached table
                 for ($i = 0; $i < count($exList); $i++) {
                     //                   $fp = fopen($tempFilePath, "w");
                     //                   fwrite($fp, json_encode($exList[$i]["code"]));
                     //                         fclose($fp);
                     $curExList = $exList[$i];
                     $FEx->PerformProcessingByExceptions($curExList, $flightInfo, $flightExTableName, $apTableName, $bpTableName, $startCopyTime, $stepLength);
                 }
                 error_reporting(E_ALL);
                 //                unlink($tempFilePath);
             } else {
                 //                unlink($tempFilePath);
             }
             unset($Bru);
             $result = true;
             return $result;
         } else {
             error_log("Not avaliable for current user. ProcessFlight id - " . $id . ". " . "Username - " . $this->_user->username . ". Page FlightsController.php");
             $result['status'] = false;
             return $result['status'];
         }
     } else {
         error_log("Incorrect input data. DeleteFlight id - " . json_encode($extId) . ". Page FlightsController.php");
         $result['status'] = false;
         return $result['status'];
     }
 }
 public function ImportFlight($importedFileName)
 {
     $copiedFilesDir = UPLOADED_FILES_PATH;
     $copiedFilePath = $copiedFilesDir . $importedFileName;
     $zip = new ZipArchive();
     $res = $zip->open($copiedFilePath);
     $importFolderName = sprintf("Imported_%s", date('Y-m-d'));
     $needToCreateImportedFolder = true;
     $Fl = new Flight();
     $Bru = new Bru();
     $Fr = new Frame();
     $FlE = new FlightException();
     $Fd = new Folder();
     $folderInfo = [];
     $userId = $this->_user->GetUserIdByName($this->_user->username);
     if ($res === TRUE) {
         $i = 0;
         $headerFiles = [];
         do {
             $fileName = $zip->getNameIndex($i);
             if (strpos($fileName, "header") !== false) {
                 $headerFiles[] = $fileName;
             }
             $i++;
         } while ($i < $zip->numFiles);
         foreach ($headerFiles as $name) {
             $zip->extractTo($copiedFilesDir, $name);
             $json = file_get_contents($copiedFilesDir . "/" . $name);
             unlink($copiedFilesDir . "/" . $name);
             $flightInfoImported = json_decode($json, true);
             $bruType = $flightInfoImported['bruType'];
             $flightId = $Fl->InsertNewFlight($flightInfoImported['bort'], $flightInfoImported['voyage'], $flightInfoImported['startCopyTime'], $flightInfoImported['bruType'], $flightInfoImported['performer'], $flightInfoImported['departureAirport'], $flightInfoImported['arrivalAirport'], $importedFileName, $flightInfoImported['flightAditionalInfo']);
             $flightInfo = $Fl->GetFlightInfo($flightId);
             $tableNameAp = $flightInfo['apTableName'];
             $tableNameBp = $flightInfo['bpTableName'];
             $bruInfo = $Bru->GetBruInfo($bruType);
             $apPrefixes = $Bru->GetBruApCycloPrefixes($bruType);
             $bpPrefixes = $Bru->GetBruBpCycloPrefixes($bruType);
             $apCyclo = $Bru->GetBruApCycloPrefixOrganized($bruType);
             $tables = $Fl->CreateFlightParamTables($flightId, $apCyclo, $bpPrefixes);
             $apTables = $flightInfoImported["apTables"];
             for ($j = 0; $j < count($apTables); $j++) {
                 $zip->extractTo($copiedFilesDir, $apTables[$j]["file"]);
                 if (file_exists($copiedFilesDir . $apTables[$j]["file"])) {
                     $Fr->LoadFileToTable($tableNameAp . "_" . $apTables[$j]["pref"], $copiedFilesDir . $apTables[$j]["file"]);
                     unlink($copiedFilesDir . $apTables[$j]["file"]);
                 }
             }
             $bpTables = $flightInfoImported["bpTables"];
             for ($j = 0; $j < count($bpTables); $j++) {
                 $zip->extractTo($copiedFilesDir, $bpTables[$j]["file"]);
                 if (file_exists($copiedFilesDir . $bpTables[$j]["file"])) {
                     $Fr->LoadFileToTable($tableNameBp . "_" . $bpTables[$j]["pref"], $copiedFilesDir . $bpTables[$j]["file"]);
                     unlink($copiedFilesDir . $bpTables[$j]["file"]);
                 }
             }
             if (isset($flightInfoImported["exTableName"]) && $flightInfoImported["exTableName"] != "") {
                 $tableGuid = substr($tableNameAp, 0, 14);
                 $FlE->CreateFlightExceptionTable($flightId, $tableGuid);
                 $flightInfo = $Fl->GetFlightInfo($flightId);
                 $exTables = $flightInfoImported["exTables"];
                 $zip->extractTo($copiedFilesDir, $exTables);
                 $Fr->LoadFileToTable($flightInfo["exTableName"], $copiedFilesDir . $exTables);
                 if (file_exists($copiedFilesDir . $exTables)) {
                     unlink($copiedFilesDir . $exTables);
                 }
             }
             $this->_user->SetFlightAvaliable($this->_user->username, $flightId);
             if (count($headerFiles) > 1) {
                 if ($needToCreateImportedFolder) {
                     $folderInfo = $Fd->CreateFolder($importFolderName, 0, $userId);
                     $needToCreateImportedFolder = false;
                 }
                 if (isset($folderInfo['folderId'])) {
                     $Fd->PutFlightInFolder($flightId, $folderInfo['folderId'], $userId);
                 } else {
                     $Fd->PutFlightInFolder($flightId, 0, $userId);
                     //we put currently uploaded file in root
                 }
             } else {
                 //into root if only one
                 $Fd->PutFlightInFolder($flightId, 0, $userId);
                 //we put currently uploaded file in root
             }
         }
         $zip->close();
         unlink($copiedFilePath);
         unset($zip);
         unset($Fl);
         unset($FlE);
         unset($Fr);
         unset($Fd);
         unset($Bru);
         if (count($headerFiles) <= 0) {
             return false;
         }
         return true;
     } else {
         return false;
     }
 }