Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. $variables->getSafeVars(array_keys($_REQUEST));
  2. $matrix = array();
  3. if (empty($med_id) || empty($firstIndex) || empty($daysInMonth) || empty($month) || empty($year)) {
  4.     echo json_encode($matrix);
  5.     exit;
  6. }
  7.  
  8. $day_index = 0;
  9. for ($i = $firstIndex; $i < ($daysInMonth + $firstIndex); $i++) {
  10.     $day_index++;
  11.     $day = get_day_name($i % 7);
  12.     $q = "select `hours` from `hours_matrix` where `med_id`='$med_id' and `day`='$day'";
  13.     $hours = $db->getRecord($q, false);
  14.     if($hours) {
  15.         $exception_date = $day_index . '-' . $month . '-' . $year;
  16.         $q = "select `hours` from `hours_matrix_exceptions` where `med_id`='$med_id' and `exception_date`='$exception_date'";
  17.         $exceptions = $db->getRecord($q, false);
  18.         if($exceptions) {
  19.             $original = json_decode($hours['hours']);
  20.             $exc = json_decode($exceptions['hours']);
  21.             $result['hours'] = array_diff($original, $exc);
  22.             $diff['hours'] = json_encode(array_values($result['hours']));
  23.             $hours = ($diff['hours'] == '[]') ? array('hours' => '["' . t("Ακυρωμένο ωράριο") . '"]') : $diff;
  24.         }
  25.     }
  26.     $matrix[$day_index . '_' . $day] = $hours;
  27.  
  28. }
  29. echo json_encode($matrix, JSON_UNESCAPED_UNICODE);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement