public function display($tpl = null) { // @rule: Test for user access if on 1.6 and above if (DiscussHelper::getJoomlaVersion() >= '1.6') { if (!JFactory::getUser()->authorise('discuss.manage.settings', 'com_easydiscuss')) { JFactory::getApplication()->redirect('index.php', JText::_('JERROR_ALERTNOAUTHOR'), 'error'); JFactory::getApplication()->close(); } } // Initialise variables $config = DiscussHelper::getConfig(); $jconfig = DiscussHelper::getJConfig(); $defaultSAId = DiscussHelper::getDefaultSAIds(); $joomlaVersion = DiscussHelper::getJoomlaVersion(); $joomlaGroups = DiscussHelper::getJoomlaUserGroups(); $this->assignRef('config', $config); $this->assignRef('jconfig', $jconfig); $this->assignRef('defaultSAId', $defaultSAId); $this->assignRef('defaultLength', $defaultLength); $this->assignRef('joomlaversion', $joomlaVersion); $this->assignRef('joomlaGroups', $joomlaGroups); if ($this->getLayout() == 'default') { $app = JFactory::getApplication(); $app->redirect('index.php?option=com_easydiscuss&view=settings&layout=default_main_workflow&child=general'); } parent::display($tpl); }
public function display($tpl = null) { // Initialise variables $config = DiscussHelper::getConfig(); $catId = JRequest::getVar('catid', ''); $cat = JTable::getInstance('Category', 'Discuss'); $cat->load($catId); $this->cat = $cat; $this->addPathway('Home', 'index.php?option=com_easydiscuss'); $this->addPathway(JText::_('Categories'), 'index.php?option=com_easydiscuss&view=categories'); if ($catId) { $this->addPathway('Edit Category'); } else { $this->addPathway('New Category'); } // Set default values for new entries. if (empty($cat->created)) { $date = DiscussDateHelper::getDate(); $now = DiscussDateHelper::toFormat($date); $cat->created = $now; $cat->published = true; } $catRuleItems = JTable::getInstance('CategoryAclItem', 'Discuss'); $categoryRules = $catRuleItems->getAllRuleItems(); $assignedGroupACL = $cat->getAssignedACL('group'); $assignedUserACL = $cat->getAssignedACL('user'); $assignedGroupMod = $cat->getAssignedModerator('group'); $assignedUserMod = $cat->getAssignedModerator('user'); $joomlaGroups = DiscussHelper::getJoomlaUserGroups(); $parentList = DiscussHelper::populateCategories('', '', 'select', 'parent_id', $cat->parent_id); $jConfig = DiscussHelper::getJConfig(); $editor = JFactory::getEditor($jConfig->get('editor')); $this->assignRef('editor', $editor); $this->assignRef('cat', $cat); $this->assignRef('config', $config); $this->assignRef('acl', $acl); $this->assignRef('parentList', $parentList); $this->assignRef('categoryRules', $categoryRules); $this->assignRef('assignedGroupACL', $assignedGroupACL); $this->assignRef('assignedUserACL', $assignedUserACL); $this->assignRef('assignedGroupMod', $assignedGroupMod); $this->assignRef('assignedUserMod', $assignedUserMod); $this->assignRef('joomlaGroups', $joomlaGroups); parent::display($tpl); }
public function diplayRole() { // Initialise variables $mainframe = JFactory::getApplication(); $roleId = JRequest::getVar('role_id', ''); $role = DiscussHelper::getTable('Role'); $role->load($roleId); $role->title = JString::trim($role->title); $this->role = $role; // Set default values for new entries. if (empty($role->created_time)) { $date = DiscussHelper::getHelper('Date')->dateWithOffSet(); $role->created_time = $date->toFormat(); $role->published = true; } $groups = DiscussHelper::getJoomlaUserGroups(); // Remove the selected usergroups $db = DiscussHelper::getDbo(); $query = 'SELECT `usergroup_id` FROM `#__discuss_roles`'; $db->setQuery($query); $result = $db->loadResultArray(); if (!empty($result)) { foreach ($groups as $key => $group) { if (in_array($group->id, $result) && $group->id != $role->usergroup_id) { unset($groups[$key]); } } } $usergroupList = JHTML::_('select.genericlist', $groups, 'usergroup_id', 'class="full-width"', 'id', 'name', $role->usergroup_id); $this->assignRef('role', $role); $this->assignRef('usergroupList', $usergroupList); $colors = array(); $colors[] = JHTML::_('select.option', 'success', JText::_('COM_EASYDISCUSS_LABEL_COLORCODE_SUCCESS')); $colors[] = JHTML::_('select.option', 'warning', JText::_('COM_EASYDISCUSS_LABEL_COLORCODE_WARNING')); $colors[] = JHTML::_('select.option', 'important', JText::_('COM_EASYDISCUSS_LABEL_COLORCODE_IMPORTANT')); $colors[] = JHTML::_('select.option', 'info', JText::_('COM_EASYDISCUSS_LABEL_COLORCODE_INFO')); $colors[] = JHTML::_('select.option', 'inverse', JText::_('COM_EASYDISCUSS_LABEL_COLORCODE_INVERSE')); $colorList = JHTML::_('select.genericlist', $colors, 'colorcode', 'class="full-width"', 'value', 'text', $role->colorcode); $this->assignRef('colorList', $colorList); parent::display('edit'); }
public function form() { $app = JFactory::getApplication(); $id = JRequest::getInt('id', ''); $field = DiscussHelper::getTable('CustomFields'); $field->load($id); $this->addPathway('Home', 'index.php?option=com_easydiscuss'); $this->addPathway('Custom Fields', 'index.php?option=com_easydiscuss&view=customfields'); $field->title = JString::trim($field->title); $this->id = $field; if (!$field) { JToolBarHelper::title(JText::_('COM_EASYDISCUSS_ADD_NEW_CUSTOMFIELDS'), 'customs'); $this->addPathway('New Field', ''); } else { JToolBarHelper::title(JText::_('COM_EASYDISCUSS_EDITING_CUSTOMFIELDS'), 'customs'); $this->addPathway('Editing Field', ''); } JHTML::_('behavior.modal'); // Set default values for new entries. if (empty($field->created_time)) { $date = DiscussHelper::getHelper('Date')->dateWithOffSet(); $field->created_time = $date->toFormat(); $field->published = true; } $customAclItems = JTable::getInstance('CustomFieldsACL', 'Discuss'); $customFieldsAcl = $customAclItems->getCustomFieldsACL(); $assignedGroupACL = $field->getAssignedACL('group'); $assignedUserACL = $field->getAssignedACL('user'); $joomlaGroups = DiscussHelper::getJoomlaUserGroups(); $this->assignRef('field', $field); $this->assignRef('assignedGroupACL', $assignedGroupACL); $this->assignRef('assignedUserACL', $assignedUserACL); $this->assignRef('customFieldsAcl', $customFieldsAcl); $this->assignRef('joomlaGroups', $joomlaGroups); parent::display(); }
public function saveACL($post) { $catRuleItems = JTable::getInstance('CategoryAclItem', 'Discuss'); $categoryRules = $catRuleItems->getAllRuleItems(); $itemtypes = array('group', 'user'); $added = 0; foreach ($categoryRules as $rule) { foreach ($itemtypes as $type) { $key = 'acl_' . $type . '_' . $rule->action; if (isset($post[$key])) { if (count($post[$key]) > 0) { foreach ($post[$key] as $contendid) { //now we reinsert again. $catRule = JTable::getInstance('CategoryAclMap', 'Discuss'); $catRule->category_id = $this->id; $catRule->acl_id = $rule->id; $catRule->type = $type; $catRule->content_id = $contendid; $catRule->status = '1'; $catRule->store(); $added++; } //end foreach } //end if } //end if } } // we need to handle if user forget to set the acl, we will assign a default // set here using Joomla group. if (empty($added)) { // let assign this category a default acl items. $defaultKeys = array('1', '2', '3', '4'); $joomlaGroups = DiscussHelper::getJoomlaUserGroups(); foreach ($defaultKeys as $ruleId) { foreach ($joomlaGroups as $joomlaGroup) { $catRule = JTable::getInstance('CategoryAclMap', 'Discuss'); $catRule->category_id = $this->id; $catRule->acl_id = $ruleId; $catRule->type = 'group'; $catRule->content_id = $joomlaGroup->id; $catRule->status = '1'; $catRule->store(); } } } }
public function saveCustomFieldRule($fieldId = null, $form = null) { if ($fieldId == null || $form == null) { return false; } $db = DiscussHelper::getDBO(); $types = array('user', 'group'); $acls = $this->getAllCustomFieldsACL(); $query = 'DELETE FROM ' . $db->nameQuote('#__discuss_customfields_rule') . ' WHERE ' . $db->nameQuote('field_id') . '=' . $db->quote($fieldId); $db->setQuery($query); $db->Query(); // If nobody assign any permission in the permission tab, everybody can use. $allowAll = true; foreach ($types as $type) { foreach ($acls as $acl) { // Check is it set and count does it have items inside the array if (isset($form['acl_' . $type . '_' . $acl->action]) && count($form['acl_' . $type . '_' . $acl->action]) > 0) { // EG: $form[ 'acl_user_view' ] foreach ($form['acl_' . $type . '_' . $acl->action] as $myContentId) { $table = DiscussHelper::getTable('CustomFieldsRule'); $table->field_id = $fieldId; $table->acl_id = $acl->id; $table->content_id = $myContentId; $table->content_type = $type; $table->status = '1'; $table->store(); // If there is at least one permission is set, do not allow eveybody to use. $allowAll = false; } } } } if ($allowAll) { foreach ($acls as $acl) { // Allow all group to use $joomlaGroups = DiscussHelper::getJoomlaUserGroups(); foreach ($joomlaGroups as $joomlaGroup) { $table = DiscussHelper::getTable('CustomFieldsRule'); $table->field_id = $fieldId; $table->acl_id = $acl->id; $table->content_id = $joomlaGroup->id; $table->content_type = 'group'; $table->status = '1'; $table->store(); } } } return true; }
public function getAssignedACL($type = 'group') { $db = DiscussHelper::getDBO(); $acl = array(); $query = 'SELECT' . ' a.' . $db->nameQuote('field_id') . ',' . ' a.' . $db->nameQuote('content_id') . ',' . ' a.' . $db->nameQuote('status') . ',' . ' b.' . $db->nameQuote('id') . ' AS `acl_id`' . ' FROM ' . $db->nameQuote('#__discuss_customfields_rule') . ' AS a' . ' LEFT JOIN ' . $db->nameQuote('#__discuss_customfields_acl') . ' AS b' . ' ON a.' . $db->nameQuote('acl_id') . '=' . 'b.' . $db->nameQuote('id') . ' WHERE a.' . $db->nameQuote('field_id') . '=' . $db->Quote($this->id) . ' AND a.' . $db->nameQuote('content_type') . '=' . $db->Quote($type); $db->setQuery($query); $result = $db->loadObjectList(); if (count($result) > 0) { $acl = null; if ($type == 'group') { $joomlaGroups = DiscussHelper::getJoomlaUserGroups(); $acl = $this->_mapRules($result, $joomlaGroups); } else { $users = $this->getAclUsers($result); $acl = $this->_mapRules($result, $users); } return $acl; } else { return null; } }