/** * This function load's all user groups * **/ function init() { $sql = "SELECT * FROM #__byjg_groups WHERE ownerid=" . $this->_ownerID; $this->_db->setQuery($sql); if ($this->_db->query() === false) { ByJGError::Alert(JText::_('BYJG_SQLQUERY_ERROR')); exit; } $lst = $this->_db->loadObjectList(); foreach ($lst as $l) { $g = new ByJGGroup(); $g->init($l->name); $this->_groups[] = $g; } }
/** * Add a new user group */ function DoAddusergroup() { //check if user canceld action, if true return if (isset($_REQUEST['back_button'])) { ByJGRedirect($this->CreateRedirectUrl()); } //now get min and max id set defaults to -99 $minID = JRequest::getVar('minID', -99); $maxID = JRequest::getVar('maxID', -99); //something strange, abrot here if ($minID == -99 || $maxID == -99) { $this->errorHandler->Alert(JText::_('BYJG_ADD_GROUP_FAILED')); } //in request are checkboxes, the values are the userids ( userid=id from phonebook entry ) //now collect userids from request $userIDS = array(); for ($i = $minID; $i <= $maxID; $i++) { $id = 'userid_' . $i; if (isset($_POST[$id])) { $t = JRequest::getVar($id, -99); if ($id == -99) { $this->errorHandler->Alert(JText::_('BYJG_ADD_GROUP_FAILED')); } else { $userIDS[] = $t; } } } //nothing selected if (count($userIDS) == 0) { $this->errorHandler->Alert(JText::_('BYJG_ADD_GROUP_NO_SELECTION')); } $groupName = JRequest::getVar('groupname', ''); if (strlen($groupName) <= 1) { $this->errorHandler->Alert(JText::_('BYJG_GROUPNAME_MISSING')); } $this->Filter($groupName); //create a new user group, if group exists it will be loaded otherwise it will be created //if init is called with a non numeric value $group = new ByJGGroup(); $group->init($groupName); //now add every entry foreach ($userIDS as $userid) { if ($group->addMember($userid) === false) { $this->errorHandler->Alert(JText::_('BYJG_GROUP_ADD_MEMBER_FAILED')); } } //reload sms user groups $this->user->_groups->reload(); ByJGRedirect($this->CreateRedirectUrl('usergroup')); }