Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- ini_set("display_errors", 1);
- ini_set('display_startup_errors', '1');
- error_reporting(E_ALL);
- //echo php_sapi_name();
- include('classes/Core.php');
- function validateDate($date, $format = 'Y-m-d H:i:s')
- {
- $d = DateTime::createFromFormat($format, $date);
- return $d && $d->format($format) == $date;
- }
- function parseBirthday($birthday, &$msg, $errMsg){
- if (validateDate($birthday, 'd.m.Y')) {
- return $birthday = date("Y-m-d", strtotime(urldecode($birthday)));
- } else {
- $msg .= $errMsg;
- }
- return null;
- }
- function parseTreatmentDateTime($treatmentDateTime, &$msg, $errMsg){
- if(validateDate($treatmentDateTime, 'd.m.Y H:i')){
- return $treatmentDateTime = date("Y-m-d H:i", strtotime(urldecode($treatmentDateTime)));
- } else {
- $msg .= $errMsg;
- }
- return null;
- }
- function parseDate($date, &$msg, $errMsg){
- if(validateDate($date, 'd.m.Y')){
- return $date = date("Y-m-d", strtotime(urldecode($date)));
- } else {
- $msg .= $errMsg;
- }
- return null;
- }
- function getPatientTreatmentDayAction($date){
- $date = date("Y-m-d", strtotime(urldecode($date)));
- Core::connectDB();
- $treatmentDates = Core::getTreatmentDate($date);
- echo json_encode($treatmentDates);
- Core::closeDB();
- exit;
- }
- function insertWorkingTimeAction($id_staff, $beginning_date, $end_date, $matter = 'HOLIDAY'){
- echo $beginning_date;
- if(validateDate($beginning_date, 'd.m.Y H:i')){
- $beginning_date = parseTreatmentDateTime($beginning_date, $msg, "Leider ist beim Parsen ein Fehler aufgetreten.");
- }
- else if(validateDate($beginning_date, 'd.m.Y')){
- $beginning_date = parseDate($beginning_date, $msg, "Leider ist beim Parsen ein Fehler aufgetreten.");
- }
- else{
- echo "Leider konnte das Anfangsdatum nicht geparst werden.";
- exit;
- }
- //echo "'". $end_date. "'";
- if(validateDate($end_date, 'd.m.Y H:i')){
- $end_date = parseTreatmentDateTime($end_date, $msg, "Leider ist beim Parsen ein Fehler aufgetreten.");
- }
- else if(validateDate($end_date, 'd.m.Y')){
- $end_date = parseDate($end_date, $msg, "Leider ist beim Parsen ein Fehler aufgetreten.");
- }
- else{
- echo "Leider konnte das Enddatum nicht geparst werden.";
- exit;
- }
- Core::connectDB();
- if (Core::insertWorkingTime($id_staff, $beginning_date, $end_date, $matter)) {
- // everything is ok. return msg to user.
- echo "Zeiten wurde gespeichert.";
- echo $msg;
- } else {
- // cannot insert
- echo "Zeiten konnte nicht gespeichert werden.";
- echo $msg;
- }
- Core::closeDB();
- exit;
- }
- function insertPatientTreatmentAction($id_patient, $id_staff, $id_treatment, $treatment_date, $treatment_time_end, $treatment_date_end, $description){
- $description = (isset($description) ? urldecode($description) : '');
- $description = trim($description);
- $treatment_date = parseTreatmentDateTime($treatment_date, $msg, 'Leider ist beim Parsen des Termins ein Fehler unterlaufen.');
- $t_start = explode(" ", $treatment_date);
- $treatment_time_start = $t_start[1];
- $is_treatment_date_end = true;
- if($treatment_date_end===""){
- $treatment_date_end = $t_start[0];
- $is_treatment_date_end = false;
- }
- else{
- $treatment_date_end = date('Y-m-d', strtotime(urldecode($treatment_date_end)));
- }
- Core::connectDB();
- $treatment_obj = Core::getTreatment($id_treatment);
- $is_multiple_patients = $treatment_obj['is_multiple_patients'];
- $i_date = strtotime($t_start[0]);
- while ($i_date <= (strtotime($treatment_date_end))) {
- $i_treatment_date = date('Y-m-d', $i_date) . ' ' . $treatment_time_start;
- $i_date = strtotime( date('Y-m-d', $i_date) . ' +1 week');
- $isOnHoliday = Core::isOnHoliday($id_staff, $i_treatment_date, $treatment_time_end);
- $isNotOverlapping = Core::checkOverlappingTreatmentDates($id_staff, $i_treatment_date, $treatment_time_end);
- $isHitExactly = false;
- if($is_multiple_patients === 'true'){
- $isHitExactly = Core::isHitExactlyTreatmentDate($id_staff, $i_treatment_date, $treatment_time_end);
- }
- if (!$isOnHoliday && ($isNotOverlapping || $isHitExactly)) {
- $msg_insert = Core::insertTreatmentDate($id_patient, $id_staff, $id_treatment, $i_treatment_date, $treatment_time_end, $description);
- //$msg_insert=true;
- if ($msg_insert === true) {
- // everything is ok. return msg to user.
- echo "Termin ".$i_treatment_date." wurde gespeichert.\n";
- echo $msg;
- } else {
- // cannot insert
- echo "Fataler Fehler: Termin konnte nicht gespeichert werden.\n";
- echo $msg . '<br />' . $msg_insert;
- Core::closeDB();
- exit;
- }
- } else {
- if($isOnHoliday){
- echo "Leider konnte der Termin am ".$i_treatment_date." nicht hinzugefügt werden, da sich der Mitarbeiter im Urlaub befindet.\n";
- }
- else{
- echo "Es existiert bereits ein Termin innerhalb des Zeitintervalls am ".$i_treatment_date.".\n";
- }
- //exit;
- }
- }
- Core::closeDB();
- exit;
- }
- function insertStaffAction($staff) {
- $msg = "";
- if( $staff['birthday'] !== null && $staff['birthday'] !== ""){
- $birthday = parseBirthday($staff['birthday'], $msg, 'Leider ist beim Parsen des Geburtsdatums ein Fehler unterlaufen.');
- }
- $new_staff = array();
- $new_staff['surname'] = (isset($staff['surname']) ? urldecode($staff['surname']) : '');
- $new_staff['prename'] = (isset($staff['prename']) ? urldecode($staff['prename']) : '');
- $new_staff['birthday'] = $birthday;
- $new_staff['telephone'] = (isset($staff['telephone']) ? urldecode($staff['telephone']) : '');
- $new_staff['description_text'] = (isset($staff['description']) ? urldecode($staff['description']) : '');
- Core::connectDB();
- if (Core::addStaff($new_staff)) {
- // everything is ok. return msg to user.
- echo "Neuer Mitarbeiter wurde gespeichert.";
- echo $msg;
- } else {
- // cannot insert
- echo "Mitarbeiter konnte nicht gespeichert werden.";
- echo $msg;
- }
- Core::closeDB();
- exit;
- }
- function insertPatientAction($patient) {
- $msg = "";
- if (isset($patient['birthday']) && $patient['birthday'] !== "") {
- $birthday = parseBirthday($patient['birthday'], $msg, 'Leider ist beim Parsen des Geburtsdatums ein Fehler unterlaufen.');
- }
- $new_patient = array();
- $new_patient['surname'] = (isset($patient['surname']) ? urldecode($patient['surname']) : '');
- $new_patient['prename'] = (isset($patient['prename']) ? urldecode($patient['prename']) : '');
- //$new_patient['birthday'] = (isset($patient['birthday']) ? urldecode($patient['birthday']) : '');
- $new_patient['birthday'] = $birthday;
- $new_patient['telephone'] = (isset($patient['telephone']) ? urldecode($patient['telephone']) : '');
- $new_patient['description_text'] = (isset($patient['description']) ? urldecode($patient['description']) : '');
- $new_patient['town'] = (isset($patient['town']) ? urldecode($patient['town']) : '');
- $new_patient['zipcode'] = (isset($patient['zipcode']) ? urldecode($patient['zipcode']) : '');
- $new_patient['street'] = (isset($patient['street']) ? urldecode($patient['street']) : '');
- Core::connectDB();
- if (Core::addPatient($new_patient)) {
- // everything is ok. return msg to user.
- echo "Patient wurde gespeichert.";
- echo $msg;
- } else {
- // cannot insert
- echo "Patient konnte nicht gespeichert werden.";
- echo $msg;
- }
- Core::closeDB();
- exit;
- }
- function updatePatientAction($patient){
- $msg = "";
- if (isset($patient['birthday']) && $patient['birthday'] !== "") {
- $birthday = parseBirthday($patient['birthday'], $msg, 'Leider ist beim Parsen des Geburtsdatums ein Fehler unterlaufen.');
- }
- $new_patient = array();
- $new_patient['id_patient'] = $patient['id_patient'];
- $new_patient['surname'] = (isset($patient['surname']) ? urldecode($patient['surname']) : '');
- $new_patient['prename'] = (isset($patient['prename']) ? urldecode($patient['prename']) : '');
- //$new_patient['birthday'] = (isset($patient['birthday']) ? urldecode($patient['birthday']) : '');
- $new_patient['birthday'] = $birthday;
- $new_patient['telephone'] = (isset($patient['telephone']) ? urldecode($patient['telephone']) : '');
- $new_patient['description_text'] = (isset($patient['description']) ? urldecode($patient['description']) : '');
- $new_patient['town'] = (isset($patient['town']) ? urldecode($patient['town']) : '');
- $new_patient['zipcode'] = (isset($patient['zipcode']) ? urldecode($patient['zipcode']) : '');
- $new_patient['street'] = (isset($patient['street']) ? urldecode($patient['street']) : '');
- Core::connectDB();
- if (Core::updatePatient($new_patient)) {
- // everything is ok. return msg to user.
- echo "Änderungen wurden gespeichert.";
- echo $msg;
- } else {
- // cannot insert
- echo "Änderungen konnten nicht gespeichert werden.";
- echo $msg;
- }
- Core::closeDB();
- exit;
- }
- function updateStaffAction($staff){
- $msg = "";
- if (isset($staff['birthday']) && $staff['birthday'] !== "") {
- $birthday = parseBirthday($staff['birthday'], $msg, 'Leider ist beim Parsen des Geburtsdatums ein Fehler unterlaufen.');
- }
- $new_staff = array();
- $new_staff['id_staff'] = $staff['id_staff'];
- $new_staff['active'] = (isset($staff['active']) ? urldecode($staff['active']) : 'true');
- $new_staff['surname'] = (isset($staff['surname']) ? urldecode($staff['surname']) : '');
- $new_staff['prename'] = (isset($staff['prename']) ? urldecode($staff['prename']) : '');
- $new_staff['birthday'] = $birthday;
- $new_staff['telephone'] = (isset($staff['telephone']) ? urldecode($staff['telephone']) : '');
- $new_staff['description_text'] = (isset($staff['description']) ? urldecode($staff['description']) : '');
- Core::connectDB();
- if (Core::updateStaff($new_staff)) {
- // everything is ok. return msg to user.
- echo "Änderungen wurden gespeichert.";
- echo $msg;
- } else {
- // cannot insert
- echo "Änderungen konnten nicht gespeichert werden.";
- echo $msg;
- }
- Core::closeDB();
- exit;
- }
- function listPatientsAction(){
- Core::connectDB();
- $patients = Core::getPatients();
- echo json_encode($patients);
- //echo var_dump($patients);
- Core::closeDB();
- exit;
- }
- function getPatientAction($id_patient){
- Core::connectDB();
- $patient = Core::getPatient($id_patient);
- echo json_encode($patient);
- Core::closeDB();
- exit;
- }
- function getPatientTreatmentAction($id_patient_treatment){
- Core::connectDB();
- $treatmentdate = Core::getPatientTreatment($id_patient_treatment);
- echo json_encode($treatmentdate);
- Core::closeDB();
- exit;
- }
- function getTreatmentAction($id_treatment){
- Core::connectDB();
- $treatment = Core::getTreatment($id_treatment);
- echo json_encode($treatment);
- Core::closeDB();
- exit;
- }
- function getStaffAction($id_staff){
- Core::connectDB();
- $staff = Core::getStaff($id_staff);
- echo json_encode($staff);
- Core::closeDB();
- exit;
- }
- function getTreatmentDatesAction($id_patient){
- Core::connectDB();
- $treatmentDates = Core::getTreatmentDates($id_patient);
- echo json_encode($treatmentDates);
- Core::closeDB();
- exit;
- }
- function getWorkingTimesAction($id_staff, $date=null){
- Core::connectDB();
- if(isset($date) && $date !== ""){
- $date = date("Y-m-d", strtotime(urldecode($date)));
- }
- $workingtimes = Core::getWorkingTimes($id_staff, $date);
- //$workingtimes = null;
- echo json_encode($workingtimes);
- Core::closeDB();
- exit;
- }
- function removePatientAction($id_patient){
- Core::connectDB();
- $result = Core::removePatient($id_patient);
- echo $result;
- //echo "Patient".$id_patient;
- Core::closeDB();
- exit;
- }
- function removeStaffAction($id_staff){
- Core::connectDB();
- $result = Core::removeStaff($id_staff);
- echo $result;
- //echo "staff".$id_staff;
- Core::closeDB();
- exit;
- }
- function removeWorkingTimeAction($id_staff_workingtime){
- //echo "removeWorkingTimeAction: ". $id_staff_workingtime."\n";
- Core::connectDB();
- $result = Core::removeStaffWorkingTime($id_staff_workingtime);
- //echo $result;
- //echo "Patient".$id_patient;
- Core::closeDB();
- exit;
- }
- function removePatientTreatmentAction($id_patient_treatment){
- Core::connectDB();
- $result = Core::removeTreatmentDate($id_patient_treatment);
- echo $result;
- //echo "testiyeah: ".$id_patient_treatment;
- //echo "Patient".$id_patient;
- Core::closeDB();
- exit;
- }
- function getStaffListAction(){
- Core::connectDB();
- $staff = Core::getStaffList($_SESSION);
- echo json_encode($staff);
- Core::closeDB();
- exit;
- }
- function getTreatmentsAction(){
- Core::connectDB();
- $treatments = Core::getTreatments();
- echo json_encode($treatments);
- //echo var_dump($treatments);
- Core::closeDB();
- exit;
- }
- function setStaffActiveCheckAction($id_staff, $checked){
- $isChecked = false;
- if($checked === "true"){
- $isChecked = true;
- }
- Core::connectDB();
- if (Core::updateStaffActiveCheck($id_staff, $checked)) {
- // everything is ok. return msg to user.
- echo "Änderungen wurden gespeichert.";
- } else {
- // cannot insert
- echo "Änderungen konnten nicht gespeichert werden.";
- }
- Core::closeDB();
- }
- function setPatientTreatmentCheckAction($id_patient_treatment, $checked){
- $isChecked = false;
- if($checked === "true"){
- $isChecked = true;
- }
- //exit;
- Core::connectDB();
- if (Core::updatePatientTreatmentCheck($id_patient_treatment, $checked)) {
- // everything is ok. return msg to user.
- echo "Änderungen wurden gespeichert.";
- //echo $msg;
- } else {
- // cannot insert
- echo "Änderungen konnten nicht gespeichert werden.";
- }
- Core::closeDB();
- }
- function checkOverlappingPatientTreatmentAction($id_patient_treatment){
- Core::connectDB();
- $patient_treatment = Core::getPatientTreatment($id_patient_treatment);
- if(Core::checkOverlappingTreatmentDates($patient_treatment['id_staff'], $patient_treatment['treatment_date'], $patient_treatment['treatment_time_end'])){
- echo "overlap";
- }
- else {
- echo "no overlap";
- }
- Core::closeDB();
- exit;
- }
- switch($_POST['action']){
- case 'insert_patient':
- //echo var_dump($_POST['patient']);
- insertPatientAction($_POST['patient']);
- break;
- case 'remove_patient':
- removePatientAction($_POST['id_patient']);
- break;
- case 'remove_staff':
- removeStaffAction($_POST['id_staff']);
- break;
- case 'update_patient':
- updatePatientAction($_POST['patient']);
- break;
- case 'update_staff':
- updateStaffAction($_POST['staff']);
- break;
- case 'get_patients':
- listPatientsAction();
- break;
- case 'get_patient':
- getPatientAction($_POST['id_patient']);
- break;
- case 'get_staff':
- getStaffAction($_POST['id_staff']);
- break;
- case 'get_stafflist':
- getStaffListAction();
- break;
- case 'insert_staff':
- insertStaffAction($_POST['staff']);
- break;
- case 'get_treatment':
- getTreatmentAction($_POST['id_treatment']);
- break;
- case 'get_treatments':
- getTreatmentsAction();
- break;
- case 'set_staff_active_check':
- setStaffActiveCheckAction($_POST['id_staff'], $_POST['checked']);
- break;
- case 'set_patient_treatment_check':
- setPatientTreatmentCheckAction($_POST['id_patient_treatment'], $_POST['checked']);
- break;
- case 'get_patient_treatment':
- getPatientTreatmentAction($_POST['id_patient_treatment']);
- break;
- case 'insert_patient_treatment':
- insertPatientTreatmentAction($_POST['id_patient'], $_POST['id_staff'], $_POST['id_treatment'], $_POST['treatment_date'], $_POST['treatment_time_end'], $_POST['treatment_date_end'], $_POST['description']);
- break;
- case 'remove_patient_treatment':
- removePatientTreatmentAction($_POST['id_patient_treatment']);
- break;
- case 'get_treatment_dates':
- getTreatmentDatesAction($_POST['id_patient']);
- break;
- case 'get_patient_treatment_day':
- getPatientTreatmentDayAction($_POST['date']);
- break;
- case 'insert_working_time':
- insertWorkingTimeAction($_POST['id_staff'], $_POST['beginning_date'], $_POST['end_date'], $_POST['matter']);
- break;
- case 'get_working_times':
- getWorkingTimesAction((isset($_POST['id_staff']) ? $_POST['id_staff'] : null), $_POST['date']) ;
- break;
- case 'remove_staff_workingtime':
- removeWorkingTimeAction($_POST['id_staff_workingtime']);
- break;
- default:
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement