/** * Create a blank group and return it. * * @return Zikula_Response_Ajax */ public function creategroup() { $this->checkAjaxToken(); $this->throwForbiddenUnless(SecurityUtil::checkPermission('Groups::', '::', ACCESS_ADD)); $groupsCommon = new Groups_Helper_Common(); $typelabel = $groupsCommon->gtypeLabels(); $statelabel = $groupsCommon->stateLabels(); // Default values $obj = array('name' => '', 'gtype' => Groups_Helper_Common::GTYPE_CORE, 'state' => Groups_Helper_Common::STATE_CLOSED, 'nbumax' => 0, 'description' => ''); $newgroup = ModUtil::apiFunc('Groups', 'admin', 'create', $obj); if ($newgroup == false) { throw new Zikula_Exception_Fatal($this->__('Error! Could not create the new group.')); } // temporary group name $updobj = array('name' => $this->__f('Group %s', $newgroup), 'gid' => $newgroup); DBUtil::updateObject($updobj, 'groups', null, 'gid'); // finally select the new group $obj = DBUtil::selectObjectByID('groups', $newgroup, 'gid', null, null, null, false); $obj['statelbl'] = $statelabel[$obj['state']]; $obj['gtypelbl'] = $typelabel[$obj['gtype']]; $obj['membersurl'] = ModUtil::url('Groups', 'admin', 'groupmembership', array('gid' => $newgroup)); return new Zikula_Response_Ajax($obj); }
/** * Modify a group. * * This is a standard function that is called whenever an administrator * wishes to modify a current group item. * * @param int 'gid' the id of the group to be modified. * @param int 'objectid' generic object id mapped onto gid if present. * * @return string HTML output string. */ public function modify($args) { // Get parameters from whatever input we need. $gid = (int) FormUtil::getPassedValue('gid', isset($args['gid']) ? $args['gid'] : null, 'GET'); $objectid = (int) FormUtil::getPassedValue('objectid', isset($args['objectid']) ? $args['objectid'] : null, 'GET'); // At this stage we check to see if we have been passed $objectid if (!empty($objectid)) { $gid = $objectid; } // The user API function is called. $item = ModUtil::apiFunc('Groups', 'user', 'get', array('gid' => $gid)); if ($item == false) { return LogUtil::registerError($this->__('Sorry! No such group found.'), 404); } // Security check $this->throwForbiddenUnless(SecurityUtil::checkPermission('Groups::', $item['gid'] . '::', ACCESS_EDIT)); // Add a hidden variable for the item id. $this->view->assign('gid', $gid); // assign the item $this->view->assign($item); // Setting various defines $groupsCommon = new Groups_Helper_Common(); $grouptype = $groupsCommon->gtypeLabels(); $groupstate = $groupsCommon->stateLabels(); $this->view->assign('grouptype', $grouptype)->assign('groupstate', $groupstate); // Return the output that has been generated by this function return $this->view->fetch('groups_admin_modify.tpl'); }
/** * display the membership of a group * */ public function memberslist() { $gid = (int)FormUtil::getPassedValue('gid', null, 'GET'); $startnum = (int)FormUtil::getPassedValue('startnum', 1, 'GET'); if (!is_numeric($startnum)) { return LogUtil::registerArgsError(); } $itemsperpage = $this->getVar('itemsperpage'); $this->throwForbiddenUnless(SecurityUtil::checkPermission('Groups::memberslist', '::', ACCESS_OVERVIEW)); $group = ModUtil::apiFunc('Groups', 'user', 'get', array('gid' => $gid, 'numitems' => $itemsperpage, 'startnum' => $startnum)); if (!$group) { return DataUtil::formatForDisplay($this->__('Error! Could not load data.')); } $uid = UserUtil::getVar('uid'); $typelabel = array(); $statelabel = array(); $groupsCommon = new Groups_Helper_Common(); $typelabel = $groupsCommon->gtypeLabels(); $statelabel = $groupsCommon->stateLabels(); $group['typelbl'] = $typelabel[$group['gtype']]; $group['statelbl'] = $statelabel[$group['state']]; $this->view->assign('mainpage', false); $this->view->assign('group', $group); if ($group['members']) { $onlines = ModUtil::apiFunc('Groups', 'user', 'whosonline', array()); $members = array(); foreach ($group['members'] as $userid) { $userinfo = UserUtil::getVars($userid['uid']); $isonline = false; if (is_array($onlines)) { foreach ($onlines as $online) { if ($online['uid'] == $userid['uid']) { $isonline = true; } } } if ($isonline) { $userinfo['isonline'] = 'greenled.png'; $userinfo['isonlinelbl'] = $this->__('on-line'); } else { $userinfo['isonline'] = 'redled.png'; $userinfo['isonlinelbl'] = $this->__('off-line'); } $members[] = $userinfo; } // test of sorting data if (!empty($members)) { foreach ($members as $res) { $sortAarr[] = strtolower($res['uname']); } array_multisort($sortAarr, SORT_ASC, $members); } $this->view->assign('members', $members); } else { $this->view->assign('members', false); } if (UserUtil::isLoggedIn()) { $this->view->assign('ismember', ModUtil::apiFunc('Groups', 'user', 'isgroupmember', array('gid' => $gid, 'uid' => $uid))); } else { $this->view->assign('ismember', false); } $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('Groups', 'user', 'countgroupmembers', array('gid' => $gid)), 'itemsperpage' => $itemsperpage)); $profileModule = System::getVar('profilemodule', ''); $this->view->assign('useProfileModule', (!empty($profileModule) && $profileModule == 'Profile' && ModUtil::available($profileModule))); return $this->view->fetch('groups_user_memberslist.tpl'); }