/** * Test to see if user can create event within the specified category * * @param unknown_type $row * @param unknown_type $user * @return unknown */ public static function canCreateEvent($row, $user = null) { // TODO make this call a plugin if ($user == null) { $user = JFactory::getUser(); } $params = JComponentHelper::getParams(JEV_COM_COMPONENT); $authorisedonly = $params->get("authorisedonly", 0); if (!$authorisedonly) { if ($user->authorise('core.create', 'com_jevents')) { return true; } $allowedcats = JEVHelper::getAuthorisedCategories($user, 'com_jevents', 'core.create'); if (!in_array($row->_catid, $allowedcats)) { return false; } // check multi cats too if (JEVHelper::rowCatids($row)) { if (count(array_diff(JEVHelper::rowCatids($row), $allowedcats))) { return false; } } } else { // are we authorised to do anything with this category or calendar $jevuser = JEVHelper::getAuthorisedUser(); if ($row->_icsid > 0 && $jevuser && $jevuser->calendars != "" && $jevuser->calendars != "all") { $allowedcals = explode("|", $jevuser->calendars); if (!in_array($row->_icsid, $allowedcals)) { return false; } } if ($row->_catid > 0 && $jevuser && $jevuser->categories != "" && $jevuser->categories != "all") { $allowedcats = explode("|", $jevuser->categories); if (!in_array($row->_catid, $allowedcats)) { return false; } // check multi cats too if (JEVHelper::rowCatids($row)) { if (count(array_diff(JEVHelper::rowCatids($row), $allowedcats))) { return false; } } } } return true; }
/** * Test to see if user can create event within the specified category * * @param unknown_type $row * @param unknown_type $user * @return unknown */ public static function canCreateEvent($row, $user = null) { // TODO make this call a plugin if ($user == null) { $user = JFactory::getUser(); } $params = JComponentHelper::getParams(JEV_COM_COMPONENT); $authorisedonly = $params->get("authorisedonly", 0); if (!$authorisedonly) { if ($user->authorise('core.create', 'com_jevents')) { return true; } $allowedcats = JEVHelper::getAuthorisedCategories($user, 'com_jevents', 'core.create'); // anon user event creation if ($user->id == 0 && count($allowedcats) == 0) { $jevtask = JRequest::getString("task"); // This allows savenew through too! if (strpos($jevtask, "icalevent.save") !== false || strpos($jevtask, "icalevent.apply") !== false) { JRequest::setVar("task", "icalevent.edit"); $catids = JEVHelper::rowCatids($row) ? JEVHelper::rowCatids($row) : array(intval($row->_catid)); $catids = implode(",", $catids); $dispatcher = JEventDispatcher::getInstance(); $dispatcher->trigger('onGetAccessibleCategories', array(&$catids)); $allowedcats = explode(",", $catids); JRequest::setVar("task", $jevtask); } } if (!in_array($row->_catid, $allowedcats)) { return false; } // check multi cats too if (JEVHelper::rowCatids($row)) { if (count(array_diff(JEVHelper::rowCatids($row), $allowedcats))) { return false; } } } else { // are we authorised to do anything with this category or calendar $jevuser = JEVHelper::getAuthorisedUser(); if ($row->_icsid > 0 && $jevuser && $jevuser->calendars != "" && $jevuser->calendars != "all") { $allowedcals = explode("|", $jevuser->calendars); if (!in_array($row->_icsid, $allowedcals)) { return false; } } if ($row->_catid > 0 && $jevuser && $jevuser->categories != "" && $jevuser->categories != "all") { $allowedcats = explode("|", $jevuser->categories); if (!in_array($row->_catid, $allowedcats)) { return false; } // check multi cats too if (JEVHelper::rowCatids($row)) { if (count(array_diff(JEVHelper::rowCatids($row), $allowedcats))) { return false; } } } } return true; }