function b1n_regAddLink($sql, &$ret_msgs, &$reg_data, &$reg_config) { $reg_config['User'] = array("reg_data" => "usr_id", "db" => "usr_id", "check" => "none", "type" => "none"); $reg_data['usr_id'] = $_SESSION['user']['usr_id']; $ret = b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "link", "Link"); unset($reg_config['User']); return $ret; }
function b1n_regAddAirport($sql, &$ret_msgs, $reg_data, $reg_config) { if ($reg_data['apt_timezone'] > 0 && !strstr($reg_data['apt_timezone'], '+')) { $reg_data['apt_timezone'] = '+' . $reg_data['apt_timezone']; } $reg_data['apt_icao'] = strtoupper($reg_data['apt_icao']); $reg_data['apt_iata'] = strtoupper($reg_data['apt_iata']); return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "airport", "Airport"); }
function b1n_regAddPax_vst($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "pax_vst", "Pax Visa"); }
function b1n_regAddFoodtype($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "foodtype", "Food Type", "b1n_regAddFoodtypePlus"); }
function b1n_regAddOperator($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "operator", "Operator"); }
function b1n_regAddGroup($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "group", "Group", "b1n_regAddGroupPlus"); }
function b1n_regAddFood($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "food", "Food"); }
function b1n_regAddCaterer($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "caterer", "Caterer", "b1n_regAddCatererPlus"); }
function b1n_regAddOccupation($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "occupation", "Occupation"); }
function b1n_regAddHandler($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "handler", "Handler", "b1n_regAddHandlerPlus"); }
function b1n_regAddContact($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "contact", "Contact"); }
function b1n_regAddCountry($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "country", "Country"); }
function b1n_regAddUser($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "user", "User"); }
function b1n_regAddAircraft($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "aircraft", "Aircraft"); }
function b1n_regAddVisatype($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "visatype", "Visa Type"); }
function b1n_regAddService($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "service", "Service"); }
function b1n_regAddCmb($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "cmb", "Crew Member"); }
function b1n_regAddPax($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "pax", "Pax"); }
function b1n_regAddLeg($sql, &$ret_msgs, &$reg_data, &$reg_config) { $reg_config['Leg Trip'] = array("reg_data" => "leg_trip", "db" => "leg_trip", "check" => "none", "type" => "none"); $increment_trip_sequence = false; // Getting data from last leg if (b1n_checkNumeric($reg_data['last_leg_id'], true)) { // Getting Trip Number from Last Leg and seeing if it is a Trip Closure (Arrival at Aircraft's Homebase) $last = $sql->singleQuery("\n SELECT\n leg_trip,\n CASE WHEN apt_id_arrive IN\n (\n SELECT\n apt_id\n FROM\n \"aircraft\"\n JOIN \"leg\" ON (aircraft.acf_id = leg.acf_id)\n )\n THEN\n '1'\n ELSE\n '0'\n END AS is_trip_closure\n FROM\n \"leg\"\n WHERE\n leg_id = '" . b1n_inBd($reg_data['last_leg_id']) . "'"); // Could retrieve leg_trip of last leg if ($last && is_array($last)) { // Veryfing if current leg is a trip closure and this is the last trip (if it is not, this trip have, prolly, been closed already) $query = "\n SELECT\n 'is_trip_closure' AS current_leg \n FROM\n \"aircraft\",\n \"seq_trip\"\n WHERE\n acf_id = '" . $reg_data['acf_id'] . "' AND\n apt_id = '" . $reg_data['apt_id_arrive'] . "' AND\n '" . b1n_inBd($last['leg_trip']) . "' >= last_value"; $cur = $sql->singleQuery($query); if ($cur && $cur['current_leg'] == 'is_trip_closure') { // Yes, it is, so... increment Trip :) $increment_trip_sequence = true; } // If last leg was a trip closure, the current trip should be last_trip + 1 if ($last['is_trip_closure'] == '1') { $reg_data['leg_trip'] = $last['leg_trip'] + 1; } else { $reg_data['leg_trip'] = $last['leg_trip']; } } else { b1n_retMsg($ret_msgs, b1n_FIZZLES, "Could not get Trip of the Last Leg."); return false; } } else { // Veryfing if it is the first leg $rs = $sql->singleQuery("SELECT COUNT(leg_id) AS c FROM \"leg\""); if ($rs && $rs['c'] == 0) { // Yes, it is, so... nothing is wrong :) // Get the NextVal from Trip Sequence $rs = $sql->singleQuery("SELECT NEXTVAL('seq_trip') AS leg_trip"); if ($rs && b1n_checkNumeric($rs['leg_trip'], true)) { $reg_data['leg_trip'] = $rs['leg_trip']; } else { b1n_retMsg($ret_msgs, b1n_FIZZLES, "Could not get Current Value from Trip Sequence."); return false; } } else { b1n_retMsg($ret_msgs, b1n_FIZZLES, "It is not the very first leg and could not get trip of last leg."); return false; } } // Updating (*PUSH*) Next Legs of same Trip with ETD NULL $trip = b1n_inBd($reg_data['leg_trip']); $keeptrack = b1n_inBd($reg_data['leg_keeptrack_dt']); $query = "\n UPDATE\n \"leg\"\n SET\n leg_keeptrack_dt = leg_keeptrack_dt::timestamp + '" . b1n_formatHour($reg_data['leg_ete_i']) . "'::interval"; if (!empty($reg_data['leg_groundtime_i'])) { $query .= " + '" . $reg_data['leg_groundtime_i'] . "'::interval"; } // We want to Update just legs of this Trip and with ETD NULL $query .= "\n WHERE\n leg_trip = '" . $trip . "' AND\n leg_etd_dt IS NULL AND\n leg_keeptrack_dt > '" . $keeptrack . "'"; // select leg_id from leg where leg_etd_dt is null and leg_keeptrack_dt > '2003-01-02 07:15' and leg_keeptrack_dt + '10:10'::interval > (select leg_keeptrack_dt from leg where leg_etd_dt is not null and leg_keeptrack_dt > '2003-01-02 07:15'); // We cannot blow the all scheme up, so, we can increment legs just when the incremented result // do not overlaps the leg with non-NULL ETD (supposedelly one scheduled flight that cannot be change and/or overlapped) // So... lets get the data of this leg (if it really exists) $rs = $sql->singleQuery("\n SELECT\n leg_keeptrack_dt\n FROM\n \"leg\"\n WHERE\n leg_etd_dt IS NOT NULL AND\n leg_keeptrack_dt > '" . $keeptrack . "'"); // Seeing if we really have legs that have leg_keeptrack bigger than the one being added AND etd non-null if ($rs && is_array($rs)) { // Yeah baby, we do! // Well... now we have another problem // If we add the current leg (pushing the ones already there) will ya overlap the not null ETD leg? // We have to check for this situation if (empty($reg_data['leg_groundtime_i'])) { $groundtime = '00:00'; } else { $groundtime = $reg_data['leg_groundtime_i']; } $rs2 = $sql->singleQuery("\n SELECT \n func_get_leg_push_overflow(\n '" . $trip . "', \n '" . $keeptrack . "', \n '" . b1n_formatHour($reg_data['leg_ete_i']) . "', \n '" . $groundtime . "') AS overflow"); unset($groundtime); // If we have something from the Function that means we are overlapping someone (hmmm) if ($rs2 && !empty($rs2['overflow'])) { // Yep, we are trying to overlap someone, lets warn the user and abort the operation $msg = 'The leg you are trying to add overlaps a leg with arbitrary ETD in the '; $aux = explode('|', $rs2['overflow']); if ($trip != $aux[0]) { $msg .= $aux[0]; } else { $msg .= 'current(' . $trip . ')'; } $msg .= ' trip at ' . b1n_formatDateHourShow(b1n_formatDateHourFromDb($aux[1])) . '.<br />Process aborted.'; b1n_retMsg($ret_msgs, b1n_FIZZLES, $msg); return false; } } $rs = $sql->query($query); if ($rs) { if (b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "leg", "Leg", "b1n_regAddLegPlus")) { // If Add was successful, check if we need to increment the trip sequence if ($increment_trip_sequence) { $sql->query("SELECT NEXTVAL('seq_trip')"); } return true; } else { b1n_retMsg($ret_msgs, b1n_FIZZLES, "Could not Add new Leg."); } } else { b1n_retMsg($ret_msgs, b1n_FIZZLES, "Could not *PUSH* next Legs.<br />Add Process Aborted."); } return false; }
function b1n_regAddCitizenship($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "citizenship", "Citizenship"); }
function b1n_regAddPermit($sql, &$ret_msgs, $reg_data, $reg_config) { return b1n_regAdd($sql, $ret_msgs, $reg_data, $reg_config, "permit", "Permit", "b1n_regAddPermitPlus"); }