} } $msg = JText::_('User(s) successfully unassigned from Groups/Roles'); $mainframe->redirect('index.php?option=com_community_acl&mode=manage_users', $msg); } function saveAssignUsers($option, $cid) { global $mainframe; $db =& JFactory::getDBO(); $query = "SELECT `id` FROM `#__community_acl_sites` WHERE `is_main` = '1'"; $db->setQuery($query); $sid = (int) $db->loadResult(); if ($sid > 0) { $main = new CACL_site($db); $main->load($sid); $config = new CACL_config($main->_site_db); $config->load(); } $cacl_group_id = JRequest::getVar('cacl_group_id', array(), '', 'array'); JArrayHelper::toInteger($cacl_group_id, array()); $cacl_role_id = JRequest::getVar('cacl_role_id', array(), '', 'array'); JArrayHelper::toInteger($cacl_role_id, array()); $cacl_func_id = JRequest::getVar('cacl_func_id', array(), '', 'array'); JArrayHelper::toInteger($cacl_func_id, array()); if (is_array($cid) && count($cid) > 0) { foreach ($cid as $user_id) { $query = "DELETE FROM `#__community_acl_users` WHERE `user_id` = '" . $user_id . "'"; $db->setQuery($query); $db->query(); if (is_array($cacl_group_id) && count($cacl_group_id)) { foreach ($cacl_group_id as $i => $v) { $cacl_usr = new CACL_user($db); $cacl_usr->user_id = $user_id; $cacl_usr->group_id = isset($cacl_group_id[$i]) ? $cacl_group_id[$i] : 0; $cacl_usr->role_id = isset($cacl_role_id[$i]) ? $cacl_role_id[$i] : 0; $cacl_usr->function_id = isset($cacl_func_id[$i]) ? $cacl_func_id[$i] : 0; $cacl_usr->store(); } } if ($sid > 0) { if ($config->synchronize && $config->users_and_cb) { $sync = new CACL_syncronize($main); $sync->syncronize($user_id, 'user'); $sync->syncronize($user_id, 'cb_user'); } }
/** * Saves the record */ function save() { global $mainframe; // Check for request forgeries JRequest::checkToken() or die('Invalid Token'); #-Kobby edits this section #-Insert the user redirects urls over here #-User Detail for our Redirects $redirect_URL_FRONT = JRequest::getVar('redirect_URL_FRONT'); $redirect_URL_ADMIN = JRequest::getVar('redirect_URL_ADMIN'); $user = new JUser(JRequest::getVar('id', 0, 'post', 'int')); $option = JRequest::getCmd('option'); // Initialize some variables $db =& JFactory::getDBO(); $me =& JFactory::getUser(); $acl =& JFactory::getACL(); $MailFrom = $mainframe->getCfg('mailfrom'); $FromName = $mainframe->getCfg('fromname'); $SiteName = $mainframe->getCfg('sitename'); // Create a new JUser object $user = new JUser(JRequest::getVar('id', 0, 'post', 'int')); $original_gid = $user->get('gid'); $post = JRequest::get('post'); $post['username'] = JRequest::getVar('username', '', 'post', 'username'); $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW); $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW); if (!$user->bind($post)) { $mainframe->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message'); $mainframe->enqueueMessage($user->getError(), 'error'); //$mainframe->redirect( 'index.php?option=com_users', $user->getError() ); //return false; return $this->execute('edit'); } $objectID = $acl->get_object_id('users', $user->get('id'), 'ARO'); $groups = $acl->get_object_groups($objectID, 'ARO'); $this_group = strtolower($acl->get_group_name($groups[0], 'ARO')); if ($user->get('id') == $me->get('id') && $user->get('block') == 1) { $msg = JText::_('You cannot block Yourself!'); $mainframe->enqueueMessage($msg, 'message'); return $this->execute('edit'); } else { if ($this_group == 'super administrator' && $user->get('block') == 1) { $msg = JText::_('You cannot block a Super Administrator'); $mainframe->enqueueMessage($msg, 'message'); return $this->execute('edit'); } else { if ($this_group == 'administrator' && $me->get('gid') == 24 && $user->get('block') == 1) { $msg = JText::_('WARNBLOCK'); $mainframe->enqueueMessage($msg, 'message'); return $this->execute('edit'); } else { if ($this_group == 'super administrator' && $me->get('gid') != 25) { $msg = JText::_('You cannot edit a super administrator account'); $mainframe->enqueueMessage($msg, 'message'); return $this->execute('edit'); } } } } // Are we dealing with a new user which we need to create? $isNew = $user->get('id') < 1; if (!$isNew) { // if group has been changed and where original group was a Super Admin if ($user->get('gid') != $original_gid && $original_gid == 25) { // count number of active super admins $query = 'SELECT COUNT( id )' . ' FROM #__users' . ' WHERE gid = 25' . ' AND block = 0'; $db->setQuery($query); $count = $db->loadResult(); if ($count <= 1) { // disallow change if only one Super Admin exists $this->setRedirect('index.php?option=com_community_acl&mode=manage_users', JText::_('WARN_ONLY_SUPER')); return false; } } } /* * Lets save the JUser object */ if (!$user->save()) { $mainframe->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message'); $mainframe->enqueueMessage($user->getError(), 'error'); return $this->execute('edit'); } /* * Time for the email magic so get ready to sprinkle the magic dust... */ if ($isNew) { $adminEmail = $me->get('email'); $adminName = $me->get('name'); $subject = JText::_('NEW_USER_MESSAGE_SUBJECT'); $message = sprintf(JText::_('NEW_USER_MESSAGE'), $user->get('name'), $SiteName, JURI::root(), $user->get('username'), $user->password_clear); if ($MailFrom != '' && $FromName != '') { $adminName = $FromName; $adminEmail = $MailFrom; } JUtility::sendMail($adminEmail, $adminName, $user->get('email'), $subject, $message); } // If updating self, load the new user object into the session if ($user->get('id') == $me->get('id')) { // Get an ACL object $acl =& JFactory::getACL(); // Get the user group from the ACL $grp = $acl->getAroGroup($user->get('id')); // Mark the user as logged in $user->set('guest', 0); $user->set('aid', 1); // Fudge Authors, Editors, Publishers and Super Administrators into the special access group if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) { $user->set('aid', 2); } // Set the usertype based on the ACL group name $user->set('usertype', $grp->name); $session =& JFactory::getSession(); $session->set('user', $user); } $cacl_group_id = JRequest::getVar('cacl_group_id', array(), '', 'array'); JArrayHelper::toInteger($cacl_group_id, array()); $cacl_role_id = JRequest::getVar('cacl_role_id', array(), '', 'array'); JArrayHelper::toInteger($cacl_role_id, array()); $cacl_func_id = JRequest::getVar('cacl_func_id', array(), '', 'array'); JArrayHelper::toInteger($cacl_func_id, array()); $publisher_notification = (int) JRequest::getInt('publisher_notification'); $query = "DELETE FROM `#__community_acl_user_params` WHERE `user_id` = '" . $user->get('id') . "' AND `name` = '" . $publisher_notification . "'"; $db->setQuery($query); $db->query(); $query = "INSERT INTO `#__community_acl_user_params` " . " SET `user_id` = '" . $user->get('id') . "', " . " `name` = 'publisher_notification', " . " `value` = '" . $publisher_notification . "' "; $db->setQuery($query); $db->query(); $query = "DELETE FROM `#__community_acl_users` WHERE `user_id` = '" . $user->get('id') . "'"; $db->setQuery($query); $db->query(); if (is_array($cacl_group_id) && count($cacl_group_id)) { foreach ($cacl_group_id as $i => $v) { $cacl_usr = new CACL_user($db); $cacl_usr->user_id = $user->get('id'); $cacl_usr->group_id = isset($cacl_group_id[$i]) ? $cacl_group_id[$i] : 0; $cacl_usr->role_id = isset($cacl_role_id[$i]) ? $cacl_role_id[$i] : 0; $cacl_usr->function_id = isset($cacl_func_id[$i]) ? $cacl_func_id[$i] : 0; $cacl_usr->redirect_FRONT = $redirect_URL_FRONT; $cacl_usr->redirect_ADMIN = $redirect_URL_ADMIN; $cacl_usr->store(); } } $query = "SELECT `id` FROM `#__community_acl_sites` WHERE `is_main` = '1'"; $db->setQuery($query); $sid = (int) $db->loadResult(); if ($sid > 0) { $main = new CACL_site($db); $main->load($sid); $config = new CACL_config($main->_site_db); $config->load(); if ($config->synchronize && $config->users_and_cb) { $sync = new CACL_syncronize($main); $sync->syncronize($user->get('id'), 'user'); $sync->syncronize($user->get('id'), 'cb_user'); } } switch ($this->getTask()) { case 'apply': $msg = JText::sprintf('Successfully Saved changes to User', $user->get('name')); $this->setRedirect('index.php?option=com_community_acl&mode=manage_users&view=user&task=edit&cid[]=' . $user->get('id'), $msg); break; case 'save': default: $msg = JText::sprintf('Successfully Saved User', $user->get('name')); $this->setRedirect('index.php?option=com_community_acl&mode=manage_users', $msg); break; } }