function handler_ajax_modify($page, $type) { $json = json_decode(Env::v('json')); if ($type == 'instance') { $id = $json->admin_id; $ai = new ActivityInstance($id); $ai->select(ActivityInstanceSelect::base()); if (!S::user()->hasRights($ai->target()->group(), Rights::admin())) { throw new Exception("Invalid credentials"); } S::assert_xsrf_token(); try { $begin = new FrankizDateTime($json->begin); $end = new FrankizDateTime($json->end); if ($ai->regular()) { $ai->comment($json->activity_comment); $ai->begin($begin); $ai->end($end); } else { $ai->begin($begin); $ai->end($end); $a = $ai->activity(); $a->title($json->title); $a->description($json->activity_description); } $page->jsonAssign('success', true); } catch (Exception $e) { $page->jsonAssign('success', false); } } else { if ($type == 'regular') { $id = $json->aid; $a = new Activity($id); $a->select(ActivitySelect::base()); if (!S::user()->hasRights($a->target()->group(), Rights::admin())) { throw new Exception("Invalid credentials"); } S::assert_xsrf_token(); if (preg_match('`^\\d{2}:\\d{2}:\\d{2}$`', $json->begin) && strtotime($json->begin) !== false && preg_match('`^\\d{2}:\\d{2}:\\d{2}$`', $json->end) && strtotime($json->end) !== false) { $a->title($json->title); $a->description($json->activity_description); $key = 'days[]'; $days = unflatten($json->{$key}); $a->days(implode(',', $days)); $a->default_begin($json->begin); $a->default_end($json->end); $page->jsonAssign('success', true); } else { $page->jsonAssign('success', false); } } } return PL_JSON; }