예제 #1
0
 /**
  * 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();
     }
 }
예제 #2
0
 public function getUserSelection($tree_id, $usr_id, $grp_id = NULL, $usr_used = NULL)
 {
     $user = $this->director->systemUser;
     // get user selection combobox
     //if($view->isType(Reservation::VIEW_USER_GROUP_EDIT) && $request->getRequestType() == Request::GET)
     if ($grp_id && !$usr_used) {
         $userLink = new ReservationUserLink();
         $usrlist = $userLink->getList(array('grp_id' => $grp_id));
         $search = array();
         foreach ($usrlist['data'] as $item) {
             $search[] = $item['usr_id'];
         }
         $tmp = $user->getList(array('id' => $search));
         $usr_used = $tmp['data'];
     }
     $groupList = $this->getGroupList($tree_id);
     if (!$usr_used) {
         $usr_used = array();
     }
     $usr_used_free_search = $usr_used;
     /*
      		if(is_array(current($usr_used_free_search)))
     $usr_used_free_search[] = array('id' => $usr_id);
     		else
     */
     $usr_used_free_search[] = $usr_id;
     $search_used = $usr_used ? array('id' => $usr_used) : NULL;
     $search_free = $usr_used ? array('grp_id' => $groupList, 'no_id' => $usr_used_free_search) : array('grp_id' => $groupList, 'no_id' => $usr_id);
     $user_used = $usr_used ? $user->getList($search_used) : array('data' => '');
     $user_free = $user->getList($search_free);
     $template = new TemplateEngine($this->getPath() . "templates/reservationusergroupselect.tpl");
     $template->setVariable('cbo_usr_used', Utils::getHtmlCombo($user_used['data'], NULL, NULL, 'id', 'formatName'));
     $template->setVariable('cbo_usr_free', Utils::getHtmlCombo($user_free['data'], NULL, NULL, 'id', 'formatName'));
     return $template;
 }