Advertisement
Guest User

Untitled

a guest
Jun 7th, 2023
65
0
28 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.56 KB | None | 0 0
  1. <?php
  2. //session_start();
  3.  
  4. include('classes/Core.php');
  5.  
  6.  
  7. function validateDate($date, $format = 'Y-m-d H:i:s')
  8. {
  9.     $d = DateTime::createFromFormat($format, $date);
  10.     return $d && $d->format($format) == $date;
  11. }
  12.  
  13. function parseBirthday($birthday, &$msg, $errMsg){
  14.    
  15.     if (validateDate($birthday, 'd.m.Y')) {
  16.         return $birthday = date("Y-m-d", strtotime(urldecode($birthday)));
  17.     } else {
  18.         $msg .= $errMsg;
  19.     }
  20.     return null;
  21. }
  22.  
  23. function parseTreatmentDateTime($treatmentDateTime, &$msg, $errMsg){
  24.     if(validateDate($treatmentDateTime, 'd.m.Y H:i')){
  25.         return $treatmentDateTime = date("Y-m-d H:i", strtotime(urldecode($treatmentDateTime)));
  26.     } else {
  27.         $msg .= $errMsg;
  28.     }
  29.     return null;
  30. }
  31.  
  32. function parseDate($date, &$msg, $errMsg){
  33.     if(validateDate($date, 'd.m.Y')){
  34.         return $date = date("Y-m-d", strtotime(urldecode($date)));
  35.     } else {
  36.         $msg .= $errMsg;
  37.     }
  38.     return null;
  39. }
  40.  
  41. function getPatientTreatmentDayAction($date){
  42.     $date = date("Y-m-d", strtotime(urldecode($date)));
  43.    
  44.     Core::connectDB();
  45.     $treatmentDates = Core::getTreatmentDate($date);
  46.     echo json_encode($treatmentDates);
  47.     Core::closeDB();
  48.    
  49.     exit;
  50. }
  51.  
  52. function insertWorkingTimeAction($id_staff, $beginning_date, $end_date, $matter = 'HOLIDAY'){
  53.  
  54.     echo $beginning_date;
  55.  
  56.     if(validateDate($beginning_date, 'd.m.Y H:i')){
  57.         $beginning_date = parseTreatmentDateTime($beginning_date, $msg, "Leider ist beim Parsen ein Fehler aufgetreten.");
  58.     }
  59.     else if(validateDate($beginning_date, 'd.m.Y')){
  60.         $beginning_date = parseDate($beginning_date, $msg, "Leider ist beim Parsen ein Fehler aufgetreten.");
  61.     }
  62.     else{
  63.         echo "Leider konnte das Anfangsdatum nicht geparst werden.";
  64.         exit;
  65.     }
  66.     //echo "'". $end_date. "'";
  67.     if(validateDate($end_date, 'd.m.Y H:i')){
  68.         $end_date = parseTreatmentDateTime($end_date, $msg, "Leider ist beim Parsen ein Fehler aufgetreten.");
  69.     }
  70.     else if(validateDate($end_date, 'd.m.Y')){
  71.         $end_date = parseDate($end_date, $msg, "Leider ist beim Parsen ein Fehler aufgetreten.");
  72.     }
  73.     else{
  74.         echo "Leider konnte das Enddatum nicht geparst werden.";
  75.         exit;
  76.     }
  77.    
  78.     Core::connectDB();
  79.  
  80.     if (Core::insertWorkingTime($id_staff, $beginning_date, $end_date, $matter)) {
  81.         // everything is ok. return msg to user.
  82.         echo "Zeiten wurde gespeichert.";
  83.         echo $msg;
  84.     } else {
  85.         // cannot insert
  86.         echo "Zeiten konnte nicht gespeichert werden.";
  87.         echo $msg;
  88.     }
  89.     Core::closeDB();
  90.    
  91.    
  92.  
  93.    
  94.     exit;
  95. }
  96.  
  97. function insertPatientTreatmentAction($id_patient, $id_staff, $id_treatment, $treatment_date, $treatment_time_end, $treatment_date_end, $description){
  98.     $description = (isset($description) ? urldecode($description) : '');
  99.     $description = trim($description);
  100.    
  101.     $treatment_date = parseTreatmentDateTime($treatment_date, $msg, 'Leider ist beim Parsen des Termins ein Fehler unterlaufen.');
  102.    
  103.     $t_start = explode(" ", $treatment_date);
  104.     $treatment_time_start = $t_start[1];
  105.  
  106.     $is_treatment_date_end = true;
  107.     if($treatment_date_end===""){
  108.         $treatment_date_end = $t_start[0];
  109.         $is_treatment_date_end = false;
  110.     }
  111.     else{
  112.         $treatment_date_end = date('Y-m-d', strtotime(urldecode($treatment_date_end)));
  113.        
  114.     }
  115.  
  116.    
  117.    
  118.     Core::connectDB();
  119.    
  120.     $treatment_obj = Core::getTreatment($id_treatment);
  121.     $is_multiple_patients = $treatment_obj['is_multiple_patients'];
  122.    
  123.     $i_date = strtotime($t_start[0]);
  124.  
  125.    
  126.     while ($i_date <= (strtotime($treatment_date_end))) {
  127.  
  128.        
  129.         $i_treatment_date = date('Y-m-d', $i_date) . ' ' . $treatment_time_start;
  130.  
  131.         $i_date = strtotime( date('Y-m-d', $i_date) . ' +1 week');
  132.  
  133.         $isOnHoliday = Core::isOnHoliday($id_staff, $i_treatment_date, $treatment_time_end);
  134.  
  135.         $isNotOverlapping = Core::checkOverlappingTreatmentDates($id_staff, $i_treatment_date, $treatment_time_end);
  136.         $isHitExactly = false;
  137.         if($is_multiple_patients === 'true'){
  138.             $isHitExactly = Core::isHitExactlyTreatmentDate($id_staff, $i_treatment_date, $treatment_time_end);
  139.         }
  140.  
  141.         if (!$isOnHoliday && ($isNotOverlapping || $isHitExactly)) {
  142.  
  143.             $msg_insert = Core::insertTreatmentDate($id_patient, $id_staff, $id_treatment, $i_treatment_date, $treatment_time_end, $description);
  144.             //$msg_insert=true;
  145.             if ($msg_insert === true) {
  146.                 // everything is ok. return msg to user.
  147.                 echo "Termin ".$i_treatment_date." wurde gespeichert.\n";
  148.                 echo $msg;
  149.             } else {
  150.                 // cannot insert
  151.                 echo "Fataler Fehler: Termin konnte nicht gespeichert werden.\n";
  152.                 echo $msg . '<br />' . $msg_insert;
  153.                 Core::closeDB();
  154.                 exit;
  155.             }
  156.         } else {
  157.             if($isOnHoliday){
  158.                 echo "Leider konnte der Termin am ".$i_treatment_date." nicht hinzugefügt werden, da sich der Mitarbeiter im Urlaub befindet.\n";
  159.             }
  160.             else{
  161.                 echo "Es existiert bereits ein Termin innerhalb des Zeitintervalls am ".$i_treatment_date.".\n";
  162.             }
  163.            
  164.             //exit;
  165.         }
  166.  
  167.        
  168.     }
  169.     Core::closeDB();
  170.     exit;
  171. }
  172.  
  173. function insertStaffAction($staff) {
  174.     $msg = "";
  175.     if( $staff['birthday'] !== null && $staff['birthday'] !== ""){
  176.         $birthday = parseBirthday($staff['birthday'], $msg, 'Leider ist beim Parsen des Geburtsdatums ein Fehler unterlaufen.');
  177.     }
  178.     $new_staff = array();
  179.     $new_staff['surname'] = (isset($staff['surname']) ? urldecode($staff['surname']) : '');
  180.     $new_staff['prename'] = (isset($staff['prename']) ? urldecode($staff['prename']) : '');
  181.     $new_staff['birthday'] = $birthday;
  182.     $new_staff['telephone'] = (isset($staff['telephone']) ? urldecode($staff['telephone']) : '');
  183.     $new_staff['description_text'] = (isset($staff['description']) ? urldecode($staff['description']) : '');
  184.  
  185.     Core::connectDB();
  186.     if (Core::addStaff($new_staff)) {
  187.         // everything is ok. return msg to user.
  188.         echo "Neuer Mitarbeiter wurde gespeichert.";
  189.         echo $msg;
  190.     } else {
  191.         // cannot insert
  192.         echo "Mitarbeiter konnte nicht gespeichert werden.";
  193.         echo $msg;
  194.     }
  195.     Core::closeDB();
  196.     exit;
  197. }
  198.  
  199.  
  200. function insertPatientAction($patient) {
  201.     $msg = "";
  202.     if (isset($patient['birthday']) && $patient['birthday'] !== "") {
  203.         $birthday = parseBirthday($patient['birthday'], $msg, 'Leider ist beim Parsen des Geburtsdatums ein Fehler unterlaufen.');
  204.     }
  205.     $new_patient = array();
  206.     $new_patient['surname'] = (isset($patient['surname']) ? urldecode($patient['surname']) : '');
  207.     $new_patient['prename'] = (isset($patient['prename']) ? urldecode($patient['prename']) : '');
  208.     //$new_patient['birthday'] = (isset($patient['birthday']) ? urldecode($patient['birthday']) : '');
  209.     $new_patient['birthday'] = $birthday;
  210.     $new_patient['telephone'] = (isset($patient['telephone']) ? urldecode($patient['telephone']) : '');
  211.     $new_patient['description_text'] = (isset($patient['description']) ? urldecode($patient['description']) : '');
  212.     $new_patient['town'] = (isset($patient['town']) ? urldecode($patient['town']) : '');
  213.     $new_patient['zipcode'] = (isset($patient['zipcode']) ? urldecode($patient['zipcode']) : '');
  214.     $new_patient['street'] = (isset($patient['street']) ? urldecode($patient['street']) : '');
  215.     Core::connectDB();
  216.     if (Core::addPatient($new_patient)) {
  217.         // everything is ok. return msg to user.
  218.         echo "Patient wurde gespeichert.";
  219.         echo $msg;
  220.     } else {
  221.         // cannot insert
  222.         echo "Patient konnte nicht gespeichert werden.";
  223.         echo $msg;
  224.     }
  225.     Core::closeDB();
  226.     exit;
  227. }
  228.  
  229.  
  230. function updatePatientAction($patient){
  231.     $msg = "";
  232.     if (isset($patient['birthday']) && $patient['birthday'] !== "") {
  233.         $birthday = parseBirthday($patient['birthday'], $msg, 'Leider ist beim Parsen des Geburtsdatums ein Fehler unterlaufen.');
  234.     }
  235.     $new_patient = array();
  236.     $new_patient['id_patient'] = $patient['id_patient'];
  237.     $new_patient['surname'] = (isset($patient['surname']) ? urldecode($patient['surname']) : '');
  238.     $new_patient['prename'] = (isset($patient['prename']) ? urldecode($patient['prename']) : '');
  239.     //$new_patient['birthday'] = (isset($patient['birthday']) ? urldecode($patient['birthday']) : '');
  240.     $new_patient['birthday'] = $birthday;
  241.     $new_patient['telephone'] = (isset($patient['telephone']) ? urldecode($patient['telephone']) : '');
  242.     $new_patient['description_text'] = (isset($patient['description']) ? urldecode($patient['description']) : '');
  243. $new_patient['town'] = (isset($patient['town']) ? urldecode($patient['town']) : '');
  244.     $new_patient['zipcode'] = (isset($patient['zipcode']) ? urldecode($patient['zipcode']) : '');
  245.     $new_patient['street'] = (isset($patient['street']) ? urldecode($patient['street']) : '');
  246.     Core::connectDB();
  247.     if (Core::updatePatient($new_patient)) {
  248.         // everything is ok. return msg to user.
  249.         echo "Änderungen wurden gespeichert.";
  250.         echo $msg;
  251.     } else {
  252.         // cannot insert
  253.         echo "Änderungen konnten nicht gespeichert werden.";
  254.         echo $msg;
  255.     }
  256.     Core::closeDB();
  257.     exit;
  258. }
  259.  
  260. function updateStaffAction($staff){
  261.     $msg = "";
  262.     if (isset($staff['birthday']) && $staff['birthday'] !== "") {
  263.         $birthday = parseBirthday($staff['birthday'], $msg, 'Leider ist beim Parsen des Geburtsdatums ein Fehler unterlaufen.');
  264.     }
  265.    
  266.     $new_staff = array();
  267.     $new_staff['id_staff'] = $staff['id_staff'];
  268.     $new_staff['active'] = (isset($staff['active']) ? urldecode($staff['active']) : 'true');
  269.     $new_staff['surname'] = (isset($staff['surname']) ? urldecode($staff['surname']) : '');
  270.     $new_staff['prename'] = (isset($staff['prename']) ? urldecode($staff['prename']) : '');
  271.    
  272.     $new_staff['birthday'] = $birthday;
  273.     $new_staff['telephone'] = (isset($staff['telephone']) ? urldecode($staff['telephone']) : '');
  274.     $new_staff['description_text'] = (isset($staff['description']) ? urldecode($staff['description']) : '');
  275.    
  276.     Core::connectDB();
  277.     if (Core::updateStaff($new_staff)) {
  278.         // everything is ok. return msg to user.
  279.         echo "Änderungen wurden gespeichert.";
  280.         echo $msg;
  281.     } else {
  282.         // cannot insert
  283.         echo "Änderungen konnten nicht gespeichert werden.";
  284.         echo $msg;
  285.     }
  286.     Core::closeDB();
  287.     exit;
  288. }
  289.  
  290.  
  291. function listPatientsAction(){
  292.     Core::connectDB();
  293.     $patients = Core::getPatients();
  294.     echo json_encode($patients);
  295.     //echo var_dump($patients);
  296.     Core::closeDB();
  297.     exit;
  298. }
  299.  
  300. function getPatientAction($id_patient){
  301.     Core::connectDB();
  302.     $patient = Core::getPatient($id_patient);
  303.     echo json_encode($patient);
  304.     Core::closeDB();
  305.     exit;
  306. }
  307.  
  308. function getPatientTreatmentAction($id_patient_treatment){
  309.     Core::connectDB();
  310.     $treatmentdate = Core::getPatientTreatment($id_patient_treatment);
  311.     echo json_encode($treatmentdate);
  312.     Core::closeDB();
  313.     exit;
  314. }
  315.  
  316. function getTreatmentAction($id_treatment){
  317.     Core::connectDB();
  318.     $treatment = Core::getTreatment($id_treatment);
  319.     echo json_encode($treatment);
  320.     Core::closeDB();
  321.     exit;
  322. }
  323.  
  324. function getStaffAction($id_staff){
  325.     Core::connectDB();
  326.     $staff = Core::getStaff($id_staff);
  327.     echo json_encode($staff);
  328.     Core::closeDB();
  329.     exit;
  330. }
  331.  
  332. function getTreatmentDatesAction($id_patient){
  333.     Core::connectDB();
  334.    $treatmentDates = Core::getTreatmentDates($id_patient);
  335.     echo json_encode($treatmentDates);
  336.     Core::closeDB();
  337.     exit;
  338. }
  339.  
  340. function getWorkingTimesAction($id_staff, $date=null){
  341.     Core::connectDB();
  342.     if(isset($date) && $date !== ""){
  343.         $date = date("Y-m-d", strtotime(urldecode($date)));
  344.     }
  345.     $workingtimes = Core::getWorkingTimes($id_staff, $date);
  346.     //$workingtimes = null;
  347.     echo json_encode($workingtimes);
  348.     Core::closeDB();
  349.     exit;
  350. }
  351.  
  352. function removePatientAction($id_patient){
  353.     Core::connectDB();
  354.     $result = Core::removePatient($id_patient);
  355.     echo $result;
  356.     //echo "Patient".$id_patient;
  357.     Core::closeDB();
  358.     exit;
  359. }
  360.  
  361. function removeStaffAction($id_staff){
  362.     Core::connectDB();
  363.     $result = Core::removeStaff($id_staff);
  364.     echo $result;
  365.     //echo "staff".$id_staff;
  366.     Core::closeDB();
  367.     exit;
  368. }
  369.  
  370. function removeWorkingTimeAction($id_staff_workingtime){
  371.     //echo "removeWorkingTimeAction: ". $id_staff_workingtime."\n";
  372.     Core::connectDB();
  373.     $result = Core::removeStaffWorkingTime($id_staff_workingtime);
  374.     //echo $result;
  375.     //echo "Patient".$id_patient;
  376.     Core::closeDB();
  377.     exit;
  378. }
  379.  
  380. function removePatientTreatmentAction($id_patient_treatment){
  381.     Core::connectDB();
  382.     $result = Core::removeTreatmentDate($id_patient_treatment);
  383.     echo $result;
  384.     //echo "testiyeah: ".$id_patient_treatment;
  385.     //echo "Patient".$id_patient;
  386.     Core::closeDB();
  387.     exit;
  388. }
  389. function getStaffListAction(){
  390.  
  391. session_start();
  392.     Core::connectDB();
  393.     $staff = Core::getStaffList($_SESSION);
  394.     echo json_encode($staff);
  395.     //echo var_dump($staff);
  396.     Core::closeDB();
  397.     exit;
  398. }
  399.  
  400. function getTreatmentsAction(){
  401.     Core::connectDB();
  402.     $treatments = Core::getTreatments();
  403.     echo json_encode($treatments);
  404.     //echo var_dump($treatments);
  405.     Core::closeDB();
  406.     exit;
  407. }
  408.  
  409. function setStaffActiveCheckAction($id_staff, $checked){
  410.     $isChecked = false;
  411.     if($checked === "true"){
  412.         $isChecked = true;
  413.     }
  414.    
  415.     Core::connectDB();
  416.     if (Core::updateStaffActiveCheck($id_staff, $checked)) {
  417.         // everything is ok. return msg to user.
  418.         echo "Änderungen wurden gespeichert.";
  419.  
  420.     } else {
  421.         // cannot insert
  422.         echo "Änderungen konnten nicht gespeichert werden.";
  423.  
  424.     }
  425.     Core::closeDB();
  426. }
  427.  
  428. function setPatientTreatmentCheckAction($id_patient_treatment, $checked){
  429.     $isChecked = false;
  430.     if($checked === "true"){
  431.         $isChecked = true;
  432.     }
  433.    
  434.     //exit;
  435.     Core::connectDB();
  436.     if (Core::updatePatientTreatmentCheck($id_patient_treatment, $checked)) {
  437.         // everything is ok. return msg to user.
  438.         echo "Änderungen wurden gespeichert.";
  439.         //echo $msg;
  440.     } else {
  441.         // cannot insert
  442.         echo "Änderungen konnten nicht gespeichert werden.";
  443.  
  444.     }
  445.     Core::closeDB();
  446.    
  447. }
  448.  
  449. function checkOverlappingPatientTreatmentAction($id_patient_treatment){
  450.     Core::connectDB();
  451.    
  452.     $patient_treatment = Core::getPatientTreatment($id_patient_treatment);
  453.     if(Core::checkOverlappingTreatmentDates($patient_treatment['id_staff'], $patient_treatment['treatment_date'], $patient_treatment['treatment_time_end'])){
  454.         echo "overlap";
  455.        
  456.     }
  457.     else {
  458.         echo "no overlap";
  459.     }
  460.     Core::closeDB();
  461.     exit;
  462. }
  463.  
  464. switch($_POST['action']){
  465.     case 'insert_patient':
  466.         //echo var_dump($_POST['patient']);
  467.         insertPatientAction($_POST['patient']);
  468.         break;
  469.     case 'remove_patient':
  470.         removePatientAction($_POST['id_patient']);
  471.         break;
  472.     case 'remove_staff':
  473.         removeStaffAction($_POST['id_staff']);
  474.         break;
  475.     case 'update_patient':
  476.         updatePatientAction($_POST['patient']);
  477.         break;
  478.     case 'update_staff':
  479.         updateStaffAction($_POST['staff']);
  480.         break;
  481.     case 'get_patients':
  482.         listPatientsAction();
  483.         break;
  484.     case 'get_patient':
  485.         getPatientAction($_POST['id_patient']);
  486.         break;
  487.     case 'get_staff':
  488.         getStaffAction($_POST['id_staff']);
  489.         break;
  490.     case 'get_stafflist':
  491.         getStaffListAction();
  492.         break;
  493.     case 'insert_staff':
  494.         insertStaffAction($_POST['staff']);
  495.         break;
  496.     case 'get_treatment':
  497.         getTreatmentAction($_POST['id_treatment']);
  498.         break;
  499.     case 'get_treatments':
  500.         getTreatmentsAction();
  501.         break;
  502.     case 'set_staff_active_check':
  503.         setStaffActiveCheckAction($_POST['id_staff'], $_POST['checked']);
  504.         break;
  505.     case 'set_patient_treatment_check':
  506.         setPatientTreatmentCheckAction($_POST['id_patient_treatment'], $_POST['checked']);
  507.         break;
  508.     case 'get_patient_treatment':
  509.         getPatientTreatmentAction($_POST['id_patient_treatment']);
  510.         break;
  511.     case 'insert_patient_treatment':
  512.         insertPatientTreatmentAction($_POST['id_patient'], $_POST['id_staff'], $_POST['id_treatment'], $_POST['treatment_date'], $_POST['treatment_time_end'], $_POST['treatment_date_end'], $_POST['description']);
  513.         break;
  514.     case 'remove_patient_treatment':
  515.         removePatientTreatmentAction($_POST['id_patient_treatment']);
  516.         break;
  517.     case 'get_treatment_dates':
  518.         getTreatmentDatesAction($_POST['id_patient']);
  519.         break;
  520.     case 'get_patient_treatment_day':
  521.         getPatientTreatmentDayAction($_POST['date']);
  522.         break;
  523.     case 'insert_working_time':
  524.         insertWorkingTimeAction($_POST['id_staff'], $_POST['beginning_date'], $_POST['end_date'], $_POST['matter']);
  525.         break;
  526.     case 'get_working_times':
  527.         getWorkingTimesAction((isset($_POST['id_staff']) ? $_POST['id_staff'] : null), $_POST['date']) ;
  528.         break;
  529.     case 'remove_staff_workingtime':
  530.         removeWorkingTimeAction($_POST['id_staff_workingtime']);
  531.         break;
  532.     default:
  533.         break;
  534. }
  535.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement