Advertisement
Guest User

Untitled

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