Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2023
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.54 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. Core::connectDB();
  392. $staff = Core::getStaffList();
  393. echo json_encode($staff);
  394. //echo var_dump($staff);
  395. Core::closeDB();
  396. exit;
  397. }
  398.  
  399. function getTreatmentsAction(){
  400. Core::connectDB();
  401. $treatments = Core::getTreatments();
  402. echo json_encode($treatments);
  403. //echo var_dump($treatments);
  404. Core::closeDB();
  405. exit;
  406. }
  407.  
  408. function setStaffActiveCheckAction($id_staff, $checked){
  409. $isChecked = false;
  410. if($checked === "true"){
  411. $isChecked = true;
  412. }
  413.  
  414. Core::connectDB();
  415. if (Core::updateStaffActiveCheck($id_staff, $checked)) {
  416. // everything is ok. return msg to user.
  417. echo "Änderungen wurden gespeichert.";
  418.  
  419. } else {
  420. // cannot insert
  421. echo "Änderungen konnten nicht gespeichert werden.";
  422.  
  423. }
  424. Core::closeDB();
  425. }
  426.  
  427. function setPatientTreatmentCheckAction($id_patient_treatment, $checked){
  428. $isChecked = false;
  429. if($checked === "true"){
  430. $isChecked = true;
  431. }
  432.  
  433. //exit;
  434. Core::connectDB();
  435. if (Core::updatePatientTreatmentCheck($id_patient_treatment, $checked)) {
  436. // everything is ok. return msg to user.
  437. echo "Änderungen wurden gespeichert.";
  438. //echo $msg;
  439. } else {
  440. // cannot insert
  441. echo "Änderungen konnten nicht gespeichert werden.";
  442.  
  443. }
  444. Core::closeDB();
  445.  
  446. }
  447.  
  448. function checkOverlappingPatientTreatmentAction($id_patient_treatment){
  449. Core::connectDB();
  450.  
  451. $patient_treatment = Core::getPatientTreatment($id_patient_treatment);
  452. if(Core::checkOverlappingTreatmentDates($patient_treatment['id_staff'], $patient_treatment['treatment_date'], $patient_treatment['treatment_time_end'])){
  453. echo "overlap";
  454.  
  455. }
  456. else {
  457. echo "no overlap";
  458. }
  459. Core::closeDB();
  460. exit;
  461. }
  462.  
  463. switch($_POST['action']){
  464. case 'insert_patient':
  465. //echo var_dump($_POST['patient']);
  466. insertPatientAction($_POST['patient']);
  467. break;
  468. case 'remove_patient':
  469. removePatientAction($_POST['id_patient']);
  470. break;
  471. case 'remove_staff':
  472. removeStaffAction($_POST['id_staff']);
  473. break;
  474. case 'update_patient':
  475. updatePatientAction($_POST['patient']);
  476. break;
  477. case 'update_staff':
  478. updateStaffAction($_POST['staff']);
  479. break;
  480. case 'get_patients':
  481. listPatientsAction();
  482. break;
  483. case 'get_patient':
  484. getPatientAction($_POST['id_patient']);
  485. break;
  486. case 'get_staff':
  487. getStaffAction($_POST['id_staff']);
  488. break;
  489. case 'get_stafflist':
  490. getStaffListAction();
  491. break;
  492. case 'insert_staff':
  493. insertStaffAction($_POST['staff']);
  494. break;
  495. case 'get_treatment':
  496. getTreatmentAction($_POST['id_treatment']);
  497. break;
  498. case 'get_treatments':
  499. getTreatmentsAction();
  500. break;
  501. case 'set_staff_active_check':
  502. setStaffActiveCheckAction($_POST['id_staff'], $_POST['checked']);
  503. break;
  504. case 'set_patient_treatment_check':
  505. setPatientTreatmentCheckAction($_POST['id_patient_treatment'], $_POST['checked']);
  506. break;
  507. case 'get_patient_treatment':
  508. getPatientTreatmentAction($_POST['id_patient_treatment']);
  509. break;
  510. case 'insert_patient_treatment':
  511. insertPatientTreatmentAction($_POST['id_patient'], $_POST['id_staff'], $_POST['id_treatment'], $_POST['treatment_date'], $_POST['treatment_time_end'], $_POST['treatment_date_end'], $_POST['description']);
  512. break;
  513. case 'remove_patient_treatment':
  514. removePatientTreatmentAction($_POST['id_patient_treatment']);
  515. break;
  516. case 'get_treatment_dates':
  517. getTreatmentDatesAction($_POST['id_patient']);
  518. break;
  519. case 'get_patient_treatment_day':
  520. getPatientTreatmentDayAction($_POST['date']);
  521. break;
  522. case 'insert_working_time':
  523. insertWorkingTimeAction($_POST['id_staff'], $_POST['beginning_date'], $_POST['end_date'], $_POST['matter']);
  524. break;
  525. case 'get_working_times':
  526. getWorkingTimesAction((isset($_POST['id_staff']) ? $_POST['id_staff'] : null), $_POST['date']) ;
  527. break;
  528. case 'remove_staff_workingtime':
  529. removeWorkingTimeAction($_POST['id_staff_workingtime']);
  530. break;
  531. default:
  532. break;
  533. }
  534.  
  535.  
  536.  
  537. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement