function detail()
 {
     // Do we have to be logged in to see this event
     $user =& JFactory::getUser();
     if (JRequest::getInt("login", 0) && $user->id == 0) {
         $uri = JURI::getInstance();
         $link = $uri->toString();
         $comuser = version_compare(JVERSION, '1.6.0', '>=') ? "com_users" : "com_user";
         $link = 'index.php?option=' . $comsser . '&view=login&return=' . base64_encode($link);
         $link = JRoute::_($link);
         $this->setRedirect($link, JText::_('JEV_LOGIN_TO_VIEW_EVENT'));
         return;
     }
     $evid = JRequest::getInt("rp_id", 0);
     if ($evid == 0) {
         $evid = JRequest::getInt("evid", 0);
         // if cancelling from save of copy and edit use the old event id
         if ($evid == 0) {
             $evid = JRequest::getInt("old_evid", 0);
         }
         // In this case I do not have a repeat id so I find the first one that matches
         $datamodel = new JEventsDataModel("JEventsAdminDBModel");
         $vevent = $datamodel->queryModel->getVEventById($evid);
         $event = new jIcalEventDB($vevent);
         //$repeat = $event->getFirstRepeat();
         $repeat = $event->getNextRepeat();
         if ($repeat) {
             $evid = $repeat->rp_id();
         }
     }
     $pop = intval(JRequest::getVar('pop', 0));
     $uid = urldecode(JRequest::getVar('uid', ""));
     list($year, $month, $day) = JEVHelper::getYMD();
     $Itemid = JEVHelper::getItemid();
     $document =& JFactory::getDocument();
     $viewType = $document->getType();
     $cfg =& JEVConfig::getInstance();
     $theme = JEV_CommonFunctions::getJEventsViewName();
     $view = "icalevent";
     $this->addViewPath($this->_basePath . DS . "views" . DS . $theme);
     $this->view =& $this->getView($view, $viewType, $theme, array('base_path' => $this->_basePath, "template_path" => $this->_basePath . DS . "views" . DS . $theme . DS . $view . DS . 'tmpl', "name" => $theme . DS . $view));
     // Set the layout
     $this->view->setLayout("detail");
     $this->view->assign("Itemid", $Itemid);
     $this->view->assign("month", $month);
     $this->view->assign("day", $day);
     $this->view->assign("year", $year);
     $this->view->assign("task", $this->_task);
     $this->view->assign("pop", $pop);
     $this->view->assign("evid", $evid);
     $this->view->assign("jevtype", "icaldb");
     $this->view->assign("uid", $uid);
     // View caching logic -- simple... are we logged in?
     $cfg =& JEVConfig::getInstance();
     $useCache = intval($cfg->get('com_cache', 0));
     $user =& JFactory::getUser();
     if ($user->get('id') || !$useCache) {
         $this->view->display();
     } else {
         $cache =& JFactory::getCache(JEV_COM_COMPONENT, 'view');
         $cache->get($this->view, 'display');
     }
 }
 function edit()
 {
     // get the view
     $this->view =& $this->getView("icalevent", "html");
     $cid = JRequest::getVar('cid', array(0));
     JArrayHelper::toInteger($cid);
     if (is_array($cid) && count($cid) > 0) {
         $id = $cid[0];
     } else {
         $id = 0;
     }
     // front end passes the id as evid
     if ($id == 0) {
         $id = JRequest::getInt("evid", 0);
     }
     if (!JEVHelper::isEventCreator()) {
         JError::raiseError(403, JText::_('ALERTNOTAUTH'));
     }
     $repeatId = 0;
     $db = JFactory::getDBO();
     // iCal agid uses GUID or UUID as identifier
     if ($id > 0) {
         if ($repeatId == 0) {
             // this version gives us a repeat not an event so
             //$row = $this->queryModel->getEventById($id, true, "icaldb");
             $vevent = $this->dataModel->queryModel->getVEventById($id);
             if (!$vevent) {
                 $Itemid = JRequest::getInt("Itemid");
                 JFactory::getApplication()->redirect(JRoute::_("index.php?option=" . JEV_COM_COMPONENT . "&Itemid={$Itemid}", false), JText::_("JEV_SORRY_UPDATED"));
             }
             $row = new jIcalEventDB($vevent);
             $row->fixDtstart();
         } else {
             $row = $this->queryModel->listEventsById($repeatId, true, "icaldb");
         }
         if (!JEVHelper::canEditEvent($row)) {
             JError::raiseError(403, JText::_('ALERTNOTAUTH'));
         }
     } else {
         $vevent = new iCalEvent($db);
         $vevent->set("freq", "DAILY");
         $vevent->set("description", "");
         $vevent->set("summary", "");
         list($year, $month, $day) = JEVHelper::getYMD();
         $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
         $defaultstarttime = $params->get("defaultstarttime", "08:00");
         $defaultendtime = $params->get("defaultendtime", "17:00");
         list($starthour, $startmin) = explode(":", $defaultstarttime);
         list($endhour, $endmin) = explode(":", $defaultendtime);
         $vevent->set("dtstart", JevDate::mktime($starthour, $startmin, 0, $month, $day, $year));
         $vevent->set("dtend", JevDate::mktime($endhour, $endmin, 0, $month, $day, $year));
         $row = new jIcalEventDB($vevent);
         // TODO - move this to class!!
         // populate with meaningful initial values
         $row->starttime($defaultstarttime);
         $row->endtime($defaultendtime);
     }
     /*
     $db =& JFactory::getDBO();
     // get list of groups
     $query = "SELECT id AS value, name AS text"
     . "\n FROM #__groups"
     . "\n ORDER BY id"	;
     $db->setQuery( $query );
     $groups = $db->loadObjectList();
     
     // build the html select list
     $glist = JHTML::_('select.genericlist', $groups, 'access', 'class="inputbox" size="1"',	'value', 'text', intval( $row->access() ) );
     */
     $glist = JEventsHTML::buildAccessSelect(intval($row->access()), 'class="inputbox" size="1"');
     // get all the raw native calendars
     $nativeCals = $this->dataModel->queryModel->getNativeIcalendars();
     // Strip this list down based on user permissions
     $jevuser =& JEVHelper::getAuthorisedUser();
     if ($jevuser && $jevuser->calendars != "" && $jevuser->calendars != "all") {
         $cals = array_keys($nativeCals);
         $allowedcals = explode("|", $jevuser->calendars);
         foreach ($cals as $calid) {
             if (!in_array($calid, $allowedcals)) {
                 unset($nativeCals[$calid]);
             }
         }
     }
     // Are we allowed to edit events within a URL based iCal
     $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
     if ($params->get("allowedit", 0) && $row->icsid() > 0) {
         $calsql = 'SELECT * FROM #__jevents_icsfile WHERE ics_id=' . intval($row->icsid());
         $db->setQuery($calsql);
         $cal = $db->loadObject();
         if ($cal && $cal->icaltype == 0) {
             $nativeCals[$cal->ics_id] = $cal;
             $this->view->assign("offerlock", 1);
         }
     }
     $excats = "0";
     if ($jevuser && $jevuser->categories != "" && $jevuser->categories != "all") {
         // Find which categories to exclude
         if (JVersion::isCompatible("1.6.0")) {
             $catsql = 'SELECT id  FROM #__categories WHERE id NOT IN (' . str_replace("|", ",", $jevuser->categories) . ') AND extension="com_jevents"';
         } else {
             $catsql = 'SELECT id  FROM #__categories WHERE id NOT IN (' . str_replace("|", ",", $jevuser->categories) . ') AND section="com_jevents"';
         }
         $db->setQuery($catsql);
         $excats = implode(",", $db->loadResultArray());
     }
     // only offer a choice of native calendars if it exists!
     if (count($nativeCals) > 1) {
         $icalList = array();
         $icalList[] = JHTML::_('select.option', '0', JText::_('JEV_EVENT_CHOOSE_ICAL'), 'ics_id', 'label');
         $icalList = array_merge($icalList, $nativeCals);
         $clist = JHTML::_('select.genericlist', $icalList, 'ics_id', " onchange='preselectCategory(this);'", 'ics_id', 'label', $row->icsid());
         $this->view->assign('clistChoice', true);
         $this->view->assign('defaultCat', 0);
     } else {
         if (count($nativeCals) == 0 || !is_array($nativeCals)) {
             JError::raiseWarning(870, JText::_('INVALID_CALENDAR_STRUCTURE'));
         }
         $icsid = $row->icsid() > 0 ? $row->icsid() : current($nativeCals)->ics_id;
         $clist = '<input type="hidden" name="ics_id" value="' . $icsid . '" />';
         $this->view->assign('clistChoice', false);
         $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
         if ($params->get("defaultcat", false)) {
             $this->view->assign('defaultCat', current($nativeCals)->catid);
         } else {
             $this->view->assign('defaultCat', 0);
         }
     }
     // Set the layout
     $this->view->setLayout('edit');
     $this->view->assign('editCopy', $this->editCopy);
     $this->view->assign('id', $id);
     $this->view->assign('row', $row);
     $this->view->assign('excats', $excats);
     $this->view->assign('nativeCals', $nativeCals);
     $this->view->assign('clist', $clist);
     $this->view->assign('repeatId', $repeatId);
     $this->view->assign('glist', $glist);
     // only those who can publish globally can set priority field
     if (JEVHelper::isEventPublisher(true)) {
         $list = array();
         for ($i = 0; $i < 10; $i++) {
             $list[] = JHTML::_('select.option', $i, $i, 'val', 'text');
         }
         $priorities = JHTML::_('select.genericlist', $list, 'priority', "", 'val', 'text', $row->priority());
         $this->view->assign('setPriority', true);
         $this->view->assign('priority', $priorities);
     } else {
         $this->view->assign('setPriority', false);
     }
     $this->view->assignRef('dataModel', $this->dataModel);
     // for Admin interface only
     $this->view->assign('with_unpublished_cat', JFactory::getApplication()->isAdmin());
     $this->view->display();
 }
 function nextLink()
 {
     $cfg = JEVConfig::getInstance();
     $result = parent::previousnextLinks();
     if ($this->nextRepeat()) {
         $result .= "<div class='ev_nextrepeat'>";
         $result .= "<a href='" . $this->nextRepeat() . "' title='" . JText::_('JEV_NEXTREPEAT') . "' class='" . $cfg->get('com_navbarcolor') . "'>" . JText::_('JEV_NEXTREPEAT') . "</a>";
         $result .= "</div>";
     }
     return $result;
 }