Advertisement
Guest User

Untitled

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