$readonly = ''; $submissionValue = 'register'; $postType = util::getParam($_POST, 'submissionType'); if (!empty($postType) && ($postType == 'register' || $postType == 'update')) { $matricule = util::cleanup($_POST['user']); if ($postType == "register") { $password = util::cleanup($_POST['passw']); } $email = util::cleanup($_POST['email']); $emailconf = util::cleanup($_POST['emailconf']); $firstName = util::cleanup($_POST['firstname']); $lastName = util::cleanup($_POST['lastname']); $phone = util::cleanup($_POST['phone']); $address = util::cleanup($_POST['addr']); $city = util::cleanup($_POST['city']); $postalCode = util::cleanup($_POST['postal']); $isSubmissionValid = true; // Username check if (empty($matricule) || strlen($matricule) != MATRICULE_LENGTH || !is_numeric($matricule)) { // Must be a valid 7 digit valid number $errMessagesArray["matricule"] = "L'identifiant doit être un matricule valide" . is_numeric($matricule); $isSubmissionValid = false; } else { if ($postType == 'register') { $usernameCheck = $database->requete("SELECT * FROM st_authentication WHERE matricule = '" . $matricule . "'"); if (mysql_num_rows($usernameCheck) != 0) { $errMessagesArray["matricule"] = "Le matricule existe déjà"; $isSubmissionValid = false; } } }
public function saveToDatabase($matricule) { try { $this->database->beginTransaction(); $result = $this->database->requete("SELECT * FROM st_demande WHERE matricule = '" . $matricule . "'"); $hasDemandInDatabase = mysql_num_rows($result) != 0; $resultsArray = mysql_fetch_array($result); // Saving first car $firstCarId = $resultsArray[demande::CAR1_DB_FIELD]; $doesFirstCarExistInDatabse = isset($firstCarId); $this->car1->saveToDatabase($firstCarId, $doesFirstCarExistInDatabse); // Saving second car $secondCarId = $resultsArray[demande::CAR2_DB_FIELD]; $doesSecondCarExistInDatabse = isset($secondCarId); // Trip info $this->tripInfo = new tripInfo($this->userData->getAddress(), $this->userData->getCity(), $this->userData->getZipCode()); $this->tripInfo->computeValues(); $this->tripInfo->saveToDatabase($resultsArray[demande::TRIP_DB_FIELD]); $save_car2 = false; if ($this->car2->hasValuesInAtLeastOneField()) { $this->car2->saveToDatabase($secondCarId, $doesSecondCarExistInDatabse); $save_car2 = true; } $query = ""; if (!$hasDemandInDatabase) { $this->creationDate = date("Y-m-d"); $this->modificationDate = date("Y-m-d"); $this->drivingLicense->saveToServer($resultsArray[demande::DRIVING_LICENSE_DB_FIELD]); $this->proofOfResidence->saveToServer($resultsArray[demande::PROOF_OF_RESIDENCE_DB_FIELD]); if ($save_car2) { $car2_field = "," . demande::CAR2_DB_FIELD; $car2_value = "','" . util::cleanup($this->car2->getId()); } $query = "INSERT INTO st_demande \n\t \t\t\t (" . demande::MATRICULE_DB_FIELD . ",\n\t \t\t\t " . demande::CREATION_DATE_DB_FIELD . ",\n\t \t\t\t " . demande::MODIF_DATE_DB_FIELD . ",\n\t \t\t\t " . demande::PAYMENT_METHOD_DB_FIELD . ",\n\t \t\t\t " . demande::CARPOOLING_DB_FIELD . ",\n\t \t\t\t " . demande::DETAILS_DB_FIELD . ",\n\t \t\t\t " . demande::CARPOOLING_OTHERS_DB_FIELD . ",\n\t \t\t\t " . demande::DRIVING_LICENSE_DB_FIELD . ",\n\t \t\t\t " . demande::PROOF_OF_RESIDENCE_DB_FIELD . ",\n\t \t\t\t " . demande::TRIP_DB_FIELD . ",\n\t \t\t\t " . demande::CAR1_DB_FIELD . $car2_field . ") \n\t \t\t\t VALUES\n\t \t\t\t ('" . util::cleanup($matricule) . "',\n\t \t\t\t '" . util::cleanup($this->creationDate) . "',\n\t \t\t\t '" . util::cleanup($this->modificationDate) . "',\n\t \t\t\t '" . util::cleanup($this->paymentMethod) . "',\n\t \t\t\t '" . util::cleanup($this->carpooling) . "',\n\t \t\t\t '" . util::cleanup($this->details) . "',\n\t\t\t\t\t\t '" . util::cleanup($this->carpoolingOthers) . "',\n\t\t\t\t\t\t '" . util::cleanup($this->drivingLicense->getOutputLocation()) . "',\n\t\t\t\t\t\t '" . util::cleanup($this->proofOfResidence->getOutputLocation()) . "',\n\t\t\t\t\t\t '" . util::cleanup($this->tripInfo->getId()) . "',\n '" . util::cleanup($this->car1->getId()) . $car2_value . "')"; } else { $this->modificationDate = date("Y-m-d"); // Server and database URLs for this file may differ at this point, in which case we update the DB $licenseHasChangedOnServer = $this->drivingLicense->saveToServer($resultsArray[demande::DRIVING_LICENSE_DB_FIELD]); $licenseColumnString = $licenseHasChangedOnServer ? demande::DRIVING_LICENSE_DB_FIELD . " = " : ""; $licenseValuesString = $licenseHasChangedOnServer ? "'" . util::cleanup($this->drivingLicense->getOutputLocation()) . "', " : ""; // Server and database URLs for this file may differ at this point, in which case we update the DB $proofOfResidenceHasChangedOnServer = $this->proofOfResidence->saveToServer($resultsArray[demande::PROOF_OF_RESIDENCE_DB_FIELD]); $proofOfResidenceColumnString = $proofOfResidenceHasChangedOnServer ? demande::PROOF_OF_RESIDENCE_DB_FIELD . " = " : ""; $proofOfResidenceValuesString = $proofOfResidenceHasChangedOnServer ? "'" . util::cleanup($this->proofOfResidence->getOutputLocation()) . "', " : ""; if ($save_car2) { $car2_field = "," . demande::CAR2_DB_FIELD; $car2_value = " = '" . util::cleanup($this->car2->getId()) . "'"; } $query = "UPDATE st_demande\n\t\t\t\t\t\t SET\n\t \t\t\t " . demande::MODIF_DATE_DB_FIELD . " = '" . util::cleanup($this->modificationDate) . "',\n\t \t\t\t " . demande::PAYMENT_METHOD_DB_FIELD . " = '" . util::cleanup($this->paymentMethod) . "',\n\t \t\t\t " . $licenseColumnString . $licenseValuesString . "\n\t \t\t\t " . $proofOfResidenceColumnString . $proofOfResidenceValuesString . "\n\t \t\t\t " . demande::CARPOOLING_DB_FIELD . " = '" . util::cleanup($this->carpooling) . "',\n\t \t\t\t " . demande::DETAILS_DB_FIELD . " = '" . util::cleanup($this->details) . "',\n " . demande::CARPOOLING_OTHERS_DB_FIELD . " = '" . util::cleanup($this->carpoolingOthers) . "',\n\t \t\t\t " . demande::CAR1_DB_FIELD . " = '" . util::cleanup($this->car1->getId()) . "'\n\t \t\t\t " . $car2_field . $car2_value . " \n\t \t\t\t WHERE \n\t \t\t\t matricule = '" . $matricule . "'"; } $this->database->requete($query); $this->database->commitTransaction(); } catch (Exception $e) { $this->database->abortTransaction(); return false; } return true; }
public function saveToDatabase($id, $doesCarExistInDatabase) { $database = database::instance(); if ($doesCarExistInDatabase) { $this->id = $id; // TODO: POTENTIALLY PUT THIS IN FILE SUBCLASS METHOD SAVETOSERVER $results = $database->requete("SELECT * FROM st_car WHERE " . car::CAR_ID_DB_FIELD . " = '" . $this->id . "'"); $resultsArray = mysql_fetch_array($results); // Server and database URLs may differ at this point, in which case we update the DB $insuranceHasChangedOnServer = $this->insurance->saveToServer($resultsArray[car::INSURANCE_DB_FIELD]); $insuranceColumnString = $insuranceHasChangedOnServer ? car::INSURANCE_DB_FIELD . " = " : ""; $insuranceValuesString = $insuranceHasChangedOnServer ? "'" . util::cleanup($this->insurance->getOutputLocation()) . "', " : ""; $database->requete("UPDATE st_car\n\t\t\t\t\t\t\t SET \t\t\t \n\t\t \t\t\t " . car::MODEL_DB_FIELD . " = '" . util::cleanup($this->model) . "',\n\t\t \t\t\t " . car::COLOR_DB_FIELD . " = '" . util::cleanup($this->color) . "',\n\t\t \t\t\t " . car::YEAR_DB_FIELD . " = '" . util::cleanup($this->year) . "',\n\t\t \t\t\t " . $insuranceColumnString . $insuranceValuesString . "\n " . car::LICENSE_DB_FIELD . " = '" . util::cleanup($this->license) . "',\n " . car::ELECTRIC_DB_FIELD . " = '" . util::cleanup($this->isElectric) . "' \n\t\t \t\t\t WHERE \n\t\t \t\t\t " . car::CAR_ID_DB_FIELD . " = '" . $this->id . "'"); } else { $this->insurance->saveToServer(car::INSURANCE_DB_FIELD); $database->requete("INSERT INTO st_car \n\t\t\t\t\t\t\t\t(" . car::CAR_ID_DB_FIELD . ",\n\t\t\t\t\t\t\t\t" . car::MODEL_DB_FIELD . ",\n\t\t\t\t\t\t\t\t" . car::COLOR_DB_FIELD . ",\n\t\t\t\t\t\t\t\t" . car::YEAR_DB_FIELD . ",\n\t\t\t\t\t\t\t\t" . car::INSURANCE_DB_FIELD . ",\n " . car::LICENSE_DB_FIELD . ",\n " . car::ELECTRIC_DB_FIELD . ") \n\t\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t\t(NULL, \n\t\t\t\t\t\t\t\t '" . $this->model . "',\n\t\t\t\t\t\t\t\t '" . $this->color . "', \n\t\t\t\t\t\t\t\t '" . $this->year . "',\n\t\t\t\t\t\t\t\t '" . $this->insurance->getOutputLocation() . "',\n '" . $this->license . "',\n '" . $this->isElectric . "')", true, true); $this->id = $database->dernierInsertId; } return $this->id; }