function addNode(&$params, $item) { // Get menu item data $data = $this->_getItemData($params, $item); // Get permission on item $user = Jfactory::getUSER(); $db = JFactory::getDBO(); $prequery1 = "select gid, usertype from jos_users where id = " . $user->id; $db->setQuery($prequery1); $row = $db->loadObject(); $arrGroupIds[] = $row->gid; $arrGroupNames[] = $row->usertype; $prequery2 = "select id_group, name from jos_noixacl_multigroups, jos_core_acl_aro_groups where id_user = "******" and id_group != " . $row->gid . " and id_group = id"; $db->setQuery($prequery2); $rows = $db->loadObjectList(); if (!empty($rows)) { foreach ($rows as $row) { $arrGroupIds[] = $row->id_group; $arrGroupNames[] = $row->name; } } $inGroups = ""; foreach ($arrGroupNames as $name) { $inGroups .= "'" . $name . "'" . ", "; } $inGroups = substr($inGroups, 0, strlen($inGroups) - 2); $query = "select * from jos_noixacl_rules where axo_value = " . $item->id . " and aro_value in (" . $inGroups; $query .= ") and aco_value = 'access' and aco_section = 'com_menus' and aro_section = 'users'"; $db->setQuery($query); $row = $db->loadObject(); $specialaccess = true; if (empty($row)) { $specialaccess = false; } $query = "select access from jos_menu where id = " . $item->id; $db->setQuery($query); $row = $db->loadObject(); $publicaccess = false; if ($row->access == 0) { $publicaccess = true; } if (!$publicaccess && !$specialaccess) { return; } // Create the node and add it $node = new JMenuNoixNode($item->id, $item->name, $item->access, $data); if (isset($item->mid)) { $nid = $item->mid; } else { $nid = $item->id; } $this->_nodeHash[$nid] =& $node; $this->_current =& $this->_nodeHash[$item->parent]; if ($this->_current) { $this->addChild($node, true); } else { // sanity check JError::raiseError(500, 'Orphan Error. Could not find parent for Item ' . $item->id); } }
/** * Do load rulles and start checking function */ public function onAfterRoute() { $option = JRequest::getCMD('option'); $adapterLibFile = JPATH_ADMINISTRATOR . DS . "components" . DS . "com_noixacl" . DS . "libraries" . DS . "adapter.php"; //return false if not exists file if (!file_exists($adapterLibFile)) { return false; } if ($option == 'com_installer' || $option == 'com_noixacl') { $pathFile = JPATH_ADMINISTRATOR . DS . "components" . DS . "com_noixacl" . DS . "libraries" . DS . 'installer' . DS . 'adapters' . DS . 'adapter.php'; if (file_exists($pathFile)) { require_once $pathFile; // Get an installer instance $installer =& JInstaller::getInstance(); $adapterInstaller = new JInstallerAdapter($installer); $installer->setAdapter('adapter', $adapterInstaller); } } $db = JFactory::getDBO(); $app =& JFactory::getApplication(); $user = Jfactory::getUSER(); $acl =& JFactory::getACL(); //if user not logged return false; if ($user->id == 0) { return false; } //geting usertype from user $arrMultiGroups[] = $user->usertype; $arrUserGroupId = array($user->gid); //get multigrop names if user have it $sqlGetMultigroups = "SELECT grp.name, grp.id FROM #__core_acl_aro_groups as grp, #__noixacl_multigroups multigrp WHERE grp.id = multigrp.id_group AND multigrp.id_user = {$user->id}"; $db->setQuery($sqlGetMultigroups); $multiGroups = $db->loadObjectList(); if (!empty($multiGroups)) { foreach ($multiGroups as $mgrp) { $arrMultiGroups[] = $mgrp->name; $arrUserGroupId[] = $mgrp->id; } } //rrr $this->globArrMultiGroups = $arrMultiGroups; //get access level $groupList = implode(',', $arrUserGroupId); $query = "SELECT id_levels FROM #__noixacl_groups_level WHERE id_group IN ({$groupList})"; $db->setQuery($query); $glevels = $db->loadObjectList(); if (!empty($glevels)) { foreach ($glevels as $glevel) { $arrUserLevels = explode(',', $glevel->id_levels); if (!empty($arrUserLevels)) { foreach ($arrUserLevels as $groupLevel) { if ($groupLevel > $user->get('aid')) { $user->aid = $groupLevel; } } } } } //geting rules from multigroups // $acl_sql = "SELECT aco_section,aco_value,aro_section,aro_value,axo_section,axo_value FROM #__noixacl_rules WHERE ACO_VALUE<>'BLOCK' AND aro_section = 'users' AND aro_value IN ('". implode("','",$arrMultiGroups) ."')"; $acl_sql = "SELECT aco_section,aco_value,aro_section,aro_value,axo_section,axo_value FROM #__noixacl_rules WHERE aro_section = 'users' AND aro_value IN ('" . implode("','", $arrMultiGroups) . "')"; $db->setQuery($acl_sql); $rulles = $db->loadObjectList(); if (count($rulles) > 0) { /** * Adding a rule to joomlaACL */ foreach ($rulles as $r) { $acl->addACL($r->aco_section, $r->aco_value, $r->aro_section, $user->usertype, $r->axo_section, $r->axo_value); } } $this->controlAdapterAccess(); }
function afteradministrator() { $task = JRequest::getCMD('task'); if ($task == 'edit' || $task == 'add' || $task == 'new') { $db =& JFactory::getDBO(); if ($task == 'new') { $task = 'add'; } //get id from content $cid = JRequest::getVar('cid', array(0), '', 'array'); JArrayHelper::toInteger($cid, array(0)); $id = JRequest::getVar('id', $cid[0], '', 'int'); $catid = JRequest::getVar('catid', -1, '', 'int'); $sectionid = JRequest::getVar('sectionid', -1, '', 'int'); if ($sectionid == -1) { $sqlContent = "SELECT sectionid FROM #__content WHERE id = {$id}"; $db->setQuery($sqlContent); $sectionid = $db->loadResult(); if ($sectionid == "") { $sectionid = -1; } } if ($catid == -1) { $sqlContent = "SELECT catid FROM #__content WHERE id = {$id}"; $db->setQuery($sqlContent); $catid = $db->loadResult(); if ($catid == "") { $catid = -1; } } $user = Jfactory::getUSER(); //geting usertype from user $arrMultiGroups[] = $user->usertype; //get multigrop names if user have it $sqlGetMultigroups = "SELECT grp.name FROM #__core_acl_aro_groups as grp, #__noixacl_multigroups multigrp WHERE grp.id = multigrp.id_group AND multigrp.id_user = {$user->id}"; $db->setQuery($sqlGetMultigroups); $multiGroups = $db->loadObjectList(); if (!empty($multiGroups)) { foreach ($multiGroups as $mgrp) { $arrMultiGroups[] = $mgrp->name; } } //geting categories from multigroups $acl_sql = "SELECT DISTINCT axo_section FROM #__noixacl_rules WHERE aro_section = 'users' AND aro_value IN ('" . implode("','", $arrMultiGroups) . "') AND axo_value ='" . $task . "'"; $db->setQuery($acl_sql); $cats = $db->loadObjectList(); $catids = array(); if (!empty($cats)) { foreach ($cats as $cat) { $catids[] = $cat->axo_section; } } $cat_list = implode('\', \'', $catids); $javascript = "onchange=\"changeDynaList( 'catid', sectioncategories, document.adminForm.sectionid.options[document.adminForm.sectionid.selectedIndex].value, 0, 0);\""; $query = 'SELECT DISTINCT s.id, s.title' . ' FROM #__sections AS s' . ' , #__categories AS c' . ' WHERE s.id = c.section' . ' AND c.id IN ( \'' . $cat_list . '\' )' . ' ORDER BY s.ordering'; $db->setQuery($query); $sections[] = JHTML::_('select.option', '-1', '- ' . JText::_('Select Section') . ' -', 'id', 'title'); $sections[] = JHTML::_('select.option', '0', JText::_('Uncategorized'), 'id', 'title'); $sections = array_merge($sections, $db->loadObjectList()); $lists['sectionid'] = JHTML::_('select.genericlist', $sections, 'sectionid', 'class="inputbox" size="1" ' . $javascript, 'id', 'title', intval($sectionid)); foreach ($sections as $section) { $section_list[] = (int) $section->id; // get the type name - which is a special category if ($sectionid) { if ($section->id == $sectionid) { $contentSection = $section->title; } } else { if ($section->id == $sectionid) { $contentSection = $section->title; } } } $sectioncategories = array(); $sectioncategories[-1] = array(); $sectioncategories[-1][] = JHTML::_('select.option', '-1', JText::_('Select Category'), 'id', 'title'); $section_list = implode('\', \'', $section_list); $query = 'SELECT id, title, section' . ' FROM #__categories' . ' WHERE section IN ( \'' . $section_list . '\' )' . ' AND id IN ( \'' . $cat_list . '\' )' . ' ORDER BY ordering'; $db->setQuery($query); $cat_list = $db->loadObjectList(); // Uncategorized category mapped to uncategorized section $uncat = new stdClass(); $uncat->id = 0; $uncat->title = JText::_('Uncategorized'); $uncat->section = 0; $cat_list[] = $uncat; foreach ($sections as $section) { $sectioncategories[$section->id] = array(); $rows2 = array(); foreach ($cat_list as $cat) { if ($cat->section == $section->id) { $rows2[] = $cat; } } foreach ($rows2 as $row2) { $sectioncategories[$section->id][] = JHTML::_('select.option', $row2->id, $row2->title, 'id', 'title'); } } $sectioncategories['-1'][] = JHTML::_('select.option', '-1', JText::_('Select Category'), 'id', 'title'); $categories = array(); foreach ($cat_list as $cat) { if ($cat->section == $sectionid) { $categories[] = $cat; } } $categories[] = JHTML::_('select.option', '-1', JText::_('Select Category'), 'id', 'title'); $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox" size="1"', 'id', 'title', intval($catid)); $i = 0; $catjavacode = "var sectioncategories = new Array;\n\t\t"; foreach ($sectioncategories as $k => $items) { foreach ($items as $v) { $catjavacode .= "sectioncategories[" . $i++ . "] = new Array( '{$k}','" . addslashes($v->id) . "','" . addslashes($v->title) . "' );\n\t\t"; } } // Replace $document =& JFactory::getDocument(); $buf = $document->getBuffer('component'); $start = strpos($buf, '<select name="catid" id="catid"'); if ($start != 0) { $end = strpos($buf, '</option></select>', $start); $buf = substr($buf, 0, $start - 1) . $lists['catid'] . substr($buf, $end); } $start = strpos($buf, '<select name="sectionid" id="sectionid"'); if ($start != 0) { $end = strpos($buf, '</option></select>', $start); $buf = substr($buf, 0, $start - 1) . $lists['sectionid'] . substr($buf, $end); } $start = strpos($buf, 'var sectioncategories = new Array;'); if ($start != 0) { $end = strpos($buf, 'function submitbutton(pressbutton)', $start); $buf = substr($buf, 0, $start - 1) . $catjavacode . substr($buf, $end); } $document->setBuffer($buf, 'component'); } }