diff --git a/scripts/calendar/sync_calender_rights.php b/scripts/calendar/sync_calender_rights.php new file mode 100644 index 000000000..88f98a4c0 --- /dev/null +++ b/scripts/calendar/sync_calender_rights.php @@ -0,0 +1,109 @@ +id); +define("INTERNAL_USER_USERNAME", $me->username); + +$calendar = CalendarModel::search(array("checkSubscriptions" => 1)); +$adminUser = array(89, 173, 167, 8, 6, 9, 5,123); + + +foreach ($calendar as $cal) { + $allCalendar[$cal->go_calendar_id] = $cal->user_id; +} + +foreach ($calendar as $cal) { + $update = 0; + $allCalendarUser = $allCalendar; + unset($newrights); + if (in_array($cal->user_id, $adminUser)) { + $admin = 1; + } else { + $admin = 0; + } + + foreach ($allCalendarUser as $key => $value) { + if ($admin == 1 || $key == $cal->go_calendar_id) { + $newrights[$key] = "all"; + } else { + $newrights[$key] = "read"; + } + } + if (json_encode($newrights) != $cal->rights) { + $cal->update(array("rights" => json_encode($newrights))); + $update = 1; + } + + if ($cal->colors) { + $stdColors = CalendarModel::$standardCalendarColors; + $colorsArray = json_decode($cal->colors, true); + $colors = $colorsArray; + foreach ($allCalendarUser as $key => $value) { + if ($colors[$key]) { + unset($colors[$key]); + } else { + $colorsArray[$key]['bgcolor'] = $stdColors[$key]; + $colorsArray[$key]['txtcolor'] = "#000000"; + } + } + if ($colors) { + foreach ($colors as $key => $value) { + if ($key != "998" && $key != "997") { + unset($colorsArray[$key]); + } + } + } + + if (json_encode($colorsArray) != $cal->colors) { + $cal->update(array("colors" => json_encode($colorsArray))); + $update = 1; + } + + } + if ($cal->groups) { + $groupArray = json_decode($cal->groups, true); + $groups = $groupArray; + foreach ($groups as $key => $value) { + foreach ($value["calendars"] as $key2 => $value2) { + if ((!$allCalendarUser[$value2['calendar_id']] && $value2['calendar_id'] != 997 && $value2['calendar_id'] != 998)) { + unset($groupArray[$key]["calendars"][$key2]); + } else { + unset($allCalendarUser[$value2['calendar_id']]); + } + + + } + } + if ($allCalendarUser) { + foreach ($groups as $key => $value) { + if ($value['name'] == "Persönlich") { + foreach ($allCalendarUser as $key2 => $value2) { + $groupArray[$key]["calendars"][] = array("calendar_id" => "$key2", "checked" => 0, "origin" => 1); + } + } + } + } + if (json_encode($groupArray, JSON_UNESCAPED_UNICODE) != $cal->groups) { + echo "groups"; + $cal->update(array("groups" => json_encode($groupArray, JSON_UNESCAPED_UNICODE))); + $update = 1; + } + } + + if ($update == 1) { + echo "save" . $cal->id . "\n"; + + $cal->save(); + } + +} \ No newline at end of file