Advertisement
Guest User

Untitled

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