function b1n_regChangeLegPlus($sql, &$ret_msgs, $reg_data, $reg_config) { // Deleting Pax if ($sql->query("DELETE FROM \"leg_pax\" WHERE leg_id = '" . b1n_inBd($reg_data["id"]) . "'")) { // Adding New $ret = b1n_regAddLegPlus($sql, $ret_msgs, $reg_data, $reg_config); } else { b1n_retMsg($ret_msgs, b1n_FIZZLES, "Could not delete entries in leg_pax."); $ret = false; } if ($ret) { $ete_signal = ''; $groudtime_signal = ''; // Seeing if we had no GroundTime and then, changed if ($reg_data['old_values']['leg_groundtime_i'] == '' && $reg_data['leg_groundtime_i'] != '') { // TODO // Hmmm... special case! // We had no groundtime and now the user did set one // We have to check if we have legs after this one, if we do, complain and abort operation b1n_retMsg($ret_msgs, b1n_FIZZLES, 'You cannot set GroundTime for this leg (Because it has none).'); return false; } $tmp['ete'] = strtotime(b1n_formatHour($reg_data['leg_ete_i'])); $tmp['groundtime'] = strtotime($reg_data['leg_groundtime_i']); $ete_old = strtotime($reg_data['old_values']['leg_ete_i']); $groundtime_old = strtotime($reg_data['old_values']['leg_groundtime_i']); $tmp['ete_signal'] = ''; $tmp['groundtime_signal'] = ''; // Seeing if ETE changed if ($tmp['ete'] > $ete_old) { // The new is bigger than the older // We have to *PUSH*(+) the next legs $tmp['ete_signal'] = '+'; } elseif ($tmp['ete'] < $ete_old) { // The new is smaller than the older // We have to *PULL*(-) the next legs $tmp['ete_signal'] = '-'; } // Seeing if Groundtime changed if ($tmp['groundtime'] > $groundtime_old) { // The new is bigger than the older // We have to *PUSH*(+) the next legs $tmp['groundtime_signal'] = '+'; } elseif ($tmp['groundtime'] < $groundtime_old) { // The new is smaller than the older // We have to *PULL*(-) the next legs $tmp['groundtime_signal'] = '-'; } if (!empty($tmp['ete_signal']) || !empty($tmp['groundtime_signal'])) { $r['trip'] = $reg_data['old_values']['leg_trip']; $r['keeptrack'] = $reg_data['leg_keeptrack_dt']; $r['ete_signal'] = $tmp['ete_signal']; $r['groundtime_signal'] = $tmp['groundtime_signal']; $r['ete_diff_ts'] = abs($tmp['ete'] - $ete_old) + b1n_TIMESTAMP_BEGGINING; $r['groundtime_diff_ts'] = abs($tmp['groundtime'] - $groundtime_old) + b1n_TIMESTAMP_BEGGINING; $ret = b1n_regUpdateNextLegs($sql, $ret_msgs, $r); } // Changing leg_trip value // Checking if it changed $query = "SELECT leg_trip FROM leg WHERE leg_id = '" . b1n_inBd($reg_data['id']) . "'"; if ($rs = $sql->singleQuery($query)) { if ($rs['leg_trip'] != $reg_data['leg_trip']) { // Checking if there are trips with there are trips with the // trip we are trying to change this leg to $query = "SELECT COUNT(leg_id) AS c FROM leg WHERE \n leg_trip = '" . b1n_inBd($reg_data['leg_trip']) . "'"; $aux = $sql->singleQuery($query); if ($aux['c'] > 0) { // Yes we have legs with this trip number already, aborting b1n_retMsg($ret_msgs, b1n_FIZZLES, "There are legs with trip number '" . $reg_data['leg_trip'] . "' already. Please, change this legs before trying again."); return false; } else { // No, we don't, update the legs for the new trip $query = "\n UPDATE leg SET\n leg_trip = '" . b1n_inBd($reg_data['leg_trip']) . "'\n WHERE\n leg_trip = '" . b1n_inBd($rs['leg_trip']) . "'"; if (!($ret = $sql->query($query))) { b1n_retMsg($ret_msgs, b1n_FIZZLES, "Cannot update trip to " . $reg_data['leg_trip'] . " where trip = " . $rs['leg_trip']); } } } } else { b1n_retMsg($ret_msgs, b1n_FIZZLES, "Cannot get trip for leg " . $reg_data['id']); $ret = false; } } return $ret; }
function b1n_regChange($sql, &$ret_msgs, $reg_data, $reg_config, $table, $msg, $module_function = "") { $rs = $sql->query("BEGIN TRANSACTION"); if ($rs) { $query = "SELECT * FROM \"" . $table . "\" WHERE " . $reg_config["ID"]["db"] . " = '" . b1n_inBd($reg_data['id']) . "'"; $update = ""; $old_values = $sql->singleQuery($query); foreach ($reg_config as $t => $r) { $value = $reg_data[$r['reg_data']]; $aux = ""; // Fields if ($r['db'] == 'none') { continue; } // Values switch ($r['type']) { case "select": switch ($r['extra']['seltype']) { case "date": case "date_check_exp": case "date_check_dob": $aux = b1n_formatDate($value); $old_values[$r['db']] = b1n_formatDate(b1n_formatDateFromDb($old_values[$r['db']])); break; case "date_hour": $aux = b1n_formatDateHour($value); $old_values[$r['db']] = b1n_formatDateHour(b1n_formatDateHourFromDb($old_values[$r['db']])); break; case "hour": $aux = b1n_formatHour($value); $old_values[$r['db']] = b1n_formatHour(b1n_formatHourFromDb($old_values[$r['db']])); break; default: $aux = $value; break; } break; case "password": if (empty($value)) { // For some reason, switch counts as a loop, so we need to use 'continue(2)' instead of just 'continue' continue 2; } $aux = b1n_crypt($value); break; default: $aux = $value; break; } // Only update if the values changed ($aux != $old...) if ($aux != $old_values[$r['db']]) { if (b1n_checkFilled($aux)) { $aux = $r['db'] . " = '" . b1n_inBd($aux) . "'"; } else { $aux = $r['db'] . " = NULL"; } // Setting update array $update[] = $aux; } } if (is_array($update)) { $update = implode(", ", $update); $query = "UPDATE \"" . $table . "\" SET " . $update . " WHERE " . $reg_config['ID']['db'] . " = '" . b1n_inBd($reg_data['id']) . "'"; $rs = $sql->query($query); } else { $rs = true; } if ($rs) { $aux = true; if (!empty($module_function)) { $reg_data['old_values'] = $old_values; $aux = $module_function($sql, $ret_msgs, $reg_data, $reg_config); } if ($aux) { b1n_retMsg($ret_msgs, b1n_SUCCESS, $msg . ' changed successfully!'); return $sql->query('COMMIT TRANSACTION'); } } } else { b1n_retMsg($ret_msgs, b1n_FIZZLES, 'Could not begin transaction.'); } $sql->query('ROLLBACK TRANSACTION'); return false; }