/** * Returns protected var $oberserver. * @param string observer key * @return array */ public function getUserList($search) { try { if (!array_key_exists('tree_id', $search)) { throw new Exception('Tree node not set'); } if (!array_key_exists('tag', $search)) { throw new Exception('Template tag not set'); } if (!array_key_exists('date', $search)) { throw new Exception('Date not set'); } if (!array_key_exists('hour', $search)) { throw new Exception('Hour not set'); } $maxpage = 10; $page = array_key_exists('page', $search) ? intval($search['page']) : 0; $hour = $search['hour']; $date = $search['date'] ? $search['date'] : date('Y-m-d'); $authentication = Authentication::getInstance(); $user = $authentication->getUserId(); $usr_id = $user['id']; $canEdit = $authentication->canEdit($search['tree_id']); $canView = $authentication->canView($search['tree_id']); if (!$canEdit && !$canView) { throw new Exception('Access denied'); } $subObj = $this->getObject(self::TYPE_DEFAULT); $settingObj = $this->getObject(self::TYPE_SETTINGS); $settings = $settingObj->getSettings($search['tree_id'], $search['tag']); // get linked users $userLink = new ReservationUserLink(); $list = $userLink->getList(array('own_id' => $usr_id)); $userList = array($usr_id); foreach ($list['data'] as $item) { $userList[] = $item['usr_id']; } $vipCount = $subObj->getVipCount($search); $legitimateUserList = $canEdit ? array() : $subObj->getLegitimateUserList($userList, $settings['max_subscribe']); // check if there are any users that are allowed to make a reservation if (!$legitimateUserList && !$canEdit) { throw new Exception("Reservation count exceeded."); } // user is super user, let him be able to make reservations for his self //if(!$legitimateUserList) $legitimateUserList = array($usr_id); // COMMENTED OUT BECAUSE SUPER USER CAN MAKE RESERVATIONS FOR ALL MEMBERS $userSearch = array('id' => $legitimateUserList); //if($vipCount >= $settings['vip_slots']) $userSearch['no_grp_id'] = $settings['vip_grp_id']; // vip_grp_id is not used anymore // add search string for user if (array_key_exists('user', $search) && $search['user']) { $userSearch['search'] = $search['user']; } $userObj = $this->director->systemUser; // backup pager url $tmppagerUrl = $userObj->getPagerUrl(); $tmppagerKey = $userObj->getPagerKey(); $url = new JsUrl(); $url->setPath('javascript:userSearch'); $url->setParameter('date', "'{$date}'"); $url->setParameter('hour', $hour); $url->setParameter('user', "'{$search['user']}'"); $userObj->setPagerUrl($url); $users = $userObj->getList($userSearch, $maxpage, $page); // restore pager url $userObj->setPagerUrl($tmppagerUrl); $userObj->setPagerKey($tmppagerKey); $template = new TemplateEngine($this->getPath() . "templates/reservationuserselect.tpl"); $template->setVariable('users', $users); $template->setVariable('date', $date); $template->setVariable('hour', $hour); $template->setVariable('htdocs_path', $this->getHtdocsPath(false)); $template->setVariable('include_vip', $vipCount < $settings['vip_slots']); $template->setVariable('usersearch', array_key_exists('user', $search) ? $search['user'] : ''); return $template->fetch(); } catch (Exception $e) { return $e->getMessage(); } }
private function handleEditPost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { if (!$request->exists('id')) { throw new Exception('Reservation is missing.'); } $id = intval($request->getValue('id')); $key = array('id' => $id); $this->update($key, $values); $key = array('grp_id' => $id); $user = $this->director->systemUser; $usr_used = $request->getValue('usr_used'); if (!$usr_used) { $usr_used = array(); } $userLink = new ReservationUserLink(); // remove users from group $userLink->delete($key); foreach ($usr_used as $item) { $key['usr_id'] = $item; $userLink->insert($key); } viewManager::getInstance()->setType(Reservation::VIEW_USER_GROUP_OVERVIEW); $this->handleOverview(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleEditGet(false); } }