Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <?php
  2. $rootPath = "";
  3. $counter = 0;
  4. $file = "factory.php"; // this file is unique in root
  5. while ($counter <= 10) {
  6.     if (is_file($rootPath . $file)) break;
  7.     $counter++;
  8.     $rootPath .= "../";
  9.  
  10. }
  11. @include($rootPath . "factory.php");
  12. /***********************************************************************************/
  13.  
  14. function get_day_name($index) {
  15.     $day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
  16.     return $day_names[$index];
  17. }
  18.  
  19. $variables->getSafeVars(array_keys($_REQUEST));
  20. $matrix = array();
  21. if (empty($med_id) || empty($firstIndex) || empty($daysInMonth) || empty($month) || empty($year)) {
  22.     echo json_encode($matrix);
  23.     exit;
  24. }
  25.  
  26. $day_index = 0;
  27. for ($i = $firstIndex; $i < ($daysInMonth + $firstIndex); $i++) {
  28.     $day_index++;
  29.     $day = get_day_name($i % 7);
  30.     $q = "select `hours` from `hours_matrix` where `med_id`='$med_id' and `day`='$day'";
  31.     $hours = $db->getRecord($q, false);
  32.     if($hours) {
  33.         $exception_date = $day_index . '-' . $month . '-' . $year;
  34.         $q = "select `hours` from `hours_matrix_exceptions` where `med_id`='$med_id' and `exception_date`='$exception_date'";
  35.         $exceptions = $db->getRecord($q, false);
  36.         if($exceptions) {
  37.             $original = json_decode($hours['hours']);
  38.             $exc = json_decode($exceptions['hours']);
  39.             $result['hours'] = array_diff($original, $exc);
  40.             $diff['hours'] = json_encode(array_values($result['hours']));
  41.             $hours = ($diff['hours'] == '[]') ? array('hours' => '["' . t("Ακυρωμένο ωράριο") . '"]') : $diff;
  42.         }
  43.     }
  44.     $matrix[$day_index . '_' . $day] = $hours;
  45.  
  46. }
  47. echo json_encode($matrix, JSON_UNESCAPED_UNICODE);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement