Exemplo n.º 1
0
 function setupComponentCatids()
 {
     // if no catids from GET or POST default to the menu values
     // Note that module links must pass a non default value
     $Itemid = JEVHelper::getItemid();
     $this->myItemid = $Itemid;
     $menu =& JSite::getMenu();
     $active = $menu->getActive();
     if (!is_null($active) && $active->component == JEV_COM_COMPONENT) {
         $params =& JComponentHelper::getParams(JEV_COM_COMPONENT);
     } else {
         // If accessing this function from outside the component then I must load suitable parameters
         $params = $menu->getParams($this->myItemid);
     }
     $separator = $params->get("catseparator", "|");
     $catidsIn = JRequest::getVar('catids', 'NONE');
     $this->catids = array();
     if ($catidsIn == "NONE") {
         $this->catidList = "";
         for ($c = 0; $c < 999; $c++) {
             $nextCID = "catid{$c}";
             //  stop looking for more catids when you reach the last one!
             if (!($nextCatId = $params->get($nextCID, null))) {
                 break;
             }
             if (!in_array($nextCatId, $this->catids)) {
                 $this->catids[] = $nextCatId;
                 $this->catidList .= (strlen($this->catidList) > 0 ? ',' : '') . $nextCatId;
             }
         }
         $this->catidsOut = str_replace(',', $separator, $this->catidList);
     } else {
         $this->catids = explode($separator, $catidsIn);
         // hardening!
         $this->catidList = JEVHelper::forceIntegerArray($this->catids, true);
         $this->catidsOut = str_replace(',', $separator, $this->catidList);
     }
     // some functions e.g. JEventCal::viewDetailLink don't have access to a datamodel so set a global value
     // as a backup
     global $catidsOut;
     $catidsOut = $this->catidsOut;
 }
Exemplo n.º 2
0
 $cats = array();
 foreach ($categories as $cid) {
     $cid = intval($cid);
     // Make sure the user is authorised to view this category and the menu item doesn't block it!
     if (!in_array($cid, $accessiblecats) && ($cid = !0)) {
         continue;
     }
     $cats[] = $cid;
 }
 if (count($cats) == 0) {
     $cats[] = 0;
 }
 //$years  = str_replace(",","|",JEVHelper::forceIntegerArray(JRequest::getVar('years','','POST'),true));
 //$cats = implode("|",$cats);
 $jr_years = JRequest::getVar('years', array(0), 'POST');
 $years = JEVHelper::forceIntegerArray($jr_years, true);
 $cats = implode(",", $cats);
 $link = JURI::root() . "index.php?option=com_jevents&task=icals.export&format=ical";
 if (count($cats) > 0) {
     $link .= "&catids=" . $cats;
 }
 $link .= "&years=" . $years;
 if (JRequest::getInt("icalformatted", 0)) {
     $link .= "&icf=1";
 }
 $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
 if ($params->get("constrained", 0)) {
     $link .= "&Itemid=" . JRequest::getInt("Itemid", 1);
 }
 $icalkey = $params->get("icalkey", "secret phrase");
 $publiclink = $link . "&k=" . md5($icalkey . $cats . $years);
Exemplo n.º 3
0
 function export()
 {
     $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
     $years = JRequest::getVar('years', 'NONE');
     $cats = JRequest::getVar('catids', 'NONE');
     // validate the key
     $icalkey = $params->get("icalkey", "secret phrase");
     $outlook2003icalexport = JRequest::getInt("outlook2003", 0) && $params->get("outlook2003icalexport", 0);
     if ($outlook2003icalexport) {
         JRequest::setVar("icf", 1);
     }
     $privatecalendar = false;
     $k = JRequest::getString("k", "NONE");
     $pk = JRequest::getString("pk", "NONE");
     $userid = JRequest::getInt("i", 0);
     if ($pk != "NONE") {
         if (!$userid) {
             throw new Exception(JText::_('JEV_ERROR'), 403);
             return false;
         }
         $privatecalendar = true;
         $puser = JUser::getInstance($userid);
         $key = md5($icalkey . $cats . $years . $puser->password . $puser->username . $puser->id);
         if ($key != $pk) {
             throw new Exception(JText::_('JEV_ERROR'), 403);
             return false;
         }
         // ensure "user" can access non-public categories etc.
         $this->dataModel->aid = JEVHelper::getAid($puser);
         $this->dataModel->accessuser = $puser->get('id');
         $registry = JRegistry::getInstance("jevents");
         $registry->set("jevents.icaluser", $puser);
     } else {
         if ($k != "NONE") {
             if ($params->get("disableicalexport", 0)) {
                 throw new Exception(JText::_('ALERTNOTAUTH'), 403);
                 return false;
             }
             $key = md5($icalkey . $cats . $years);
             if ($key != $k) {
                 throw new Exception(JText::_('JEV_ERROR'), 403);
                 return false;
             }
         } else {
             throw new Exception(JText::_('JEV_ERROR'), 403);
             return false;
         }
     }
     // Fix the cats
     $cats = explode(',', $cats);
     // hardening!
     JEVHelper::forceIntegerArray($cats, false);
     if ($cats != array(0)) {
         JRequest::setVar("catids", implode("|", $cats));
     } else {
         JRequest::setVar("catids", '');
     }
     //Parsing variables from URL
     //Year
     // All years
     if ($years == 0) {
         $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
         $years = array();
         for ($y = JEVHelper::getMinYear(); $y <= JEVHelper::getMaxYear(); $y++) {
             if (!in_array($y, $years)) {
                 $years[] = $y;
             }
         }
         JArrayHelper::toInteger($years);
     } else {
         if ($years != "NONE") {
             $years = explode(",", JRequest::getVar('years'));
             if (!is_array($years) || count($years) == 0) {
                 list($y, $m, $d) = JEVHelper::getYMD();
                 $years = array($y);
             }
             JArrayHelper::toInteger($years);
         } else {
             list($y, $m, $d) = JEVHelper::getYMD();
             $years = array($y);
         }
     }
     // Lockin hte categories from the URL
     $Itemid = JRequest::getInt("Itemid", 0);
     if (!$Itemid) {
         JRequest::setVar("Itemid", 1);
     }
     $this->dataModel->setupComponentCatids();
     $dispatcher = JDispatcher::getInstance();
     // just incase we don't have jevents plugins registered yet
     JPluginHelper::importPlugin("jevents");
     //And then the real work
     // Force all only the one repeat
     $cfg = JEVConfig::getInstance();
     $cfg->set('com_showrepeats', 0);
     $icalEvents = array();
     foreach ($years as $year) {
         $startdate = $year . "-01-01";
         $enddate = $year . "-12-31";
         $rows = $this->dataModel->getRangeData($startdate, $enddate, 0, 0);
         if (!isset($rows["rows"])) {
             continue;
         }
         foreach ($rows["rows"] as $row) {
             if (!array_key_exists($row->ev_id(), $icalEvents)) {
                 $dispatcher->trigger('onExportRow', array(&$row));
                 $icalEvents[$row->ev_id()] = $row;
             }
         }
         unset($rows);
     }
     if ($userid) {
         $user = JUser::getInstance($userid);
     }
     $mainframe = JFactory::getApplication();
     // get the view
     $this->view = $this->getView("icals", "html");
     $this->view->setLayout("export");
     $this->view->assign("dataModel", $this->dataModel);
     $this->view->assign("outlook2003icalexport", $outlook2003icalexport);
     $this->view->assign("icalEvents", $icalEvents);
     $this->view->assign("withrepeats", true);
     $this->view->export();
     return;
 }
Exemplo n.º 4
0
 function &getCategoryEvents($Itemid, &$catids)
 {
     static $datamodel;
     if (!isset($datamodel)) {
         $datamodel = new JEventsDataModel();
         $reg =& JevRegistry::getInstance("jevents");
         $reg->setReference("jevents.datamodel", $datamodel);
     }
     $datamodel->catidList = JEVHelper::forceIntegerArray($catids, true);
     $datamodel->catids = $catids;
     $datamodel->catidsOut = implode('|', $catids);
     JRequest::setVar('category_fv', $datamodel->catidList);
     $filter = new jevFilterProcessing(array('category'));
     $rows = $datamodel->queryModel->listEventsByCat($catids, 0, 10000);
     $icalrows = $datamodel->queryModel->listIcalEventsByCat($catids, false, 0, 0, 10000, " ORDER BY rpt.startrepeat asc", $filter, '', '');
     $rows = array_merge($icalrows, $rows);
     return $rows;
 }
Exemplo n.º 5
0
 $categories = JRequest::getVar('categories', array(0), 'POST');
 $cats = array();
 foreach ($categories as $cid) {
     $cid = intval($cid);
     // Make sure the user is authorised to view this category and the menu item doesn't block it!
     if (!in_array($cid, $accessiblecats) && ($cid = !0)) {
         continue;
     }
     $cats[] = $cid;
 }
 if (count($cats) == 0) {
     $cats[] = 0;
 }
 //$years  = str_replace(",","|",JEVHelper::forceIntegerArray(JRequest::getVar('years','','POST'),true));
 //$cats = implode("|",$cats);
 $years = JEVHelper::forceIntegerArray(JRequest::getVar('years', array(0), 'POST'), true);
 $cats = implode(",", $cats);
 $link = JURI::root() . "index.php?option=com_jevents&task=icals.export&format=ical";
 if (count($cats) > 0) {
     $link .= "&catids=" . $cats;
 }
 $link .= "&years=" . $years;
 if (JRequest::getInt("icalformatted", 0)) {
     $link .= "&icf=1";
 }
 $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
 if ($params->get("constrained", 0)) {
     $link .= "&Itemid=" . JRequest::getInt("Itemid", 1);
 }
 $icalkey = $params->get("icalkey", "secret phrase");
 $publiclink = $link . "&k=" . md5($icalkey . $cats . $years);
Exemplo n.º 6
0
 function setupComponentCatids()
 {
     // if no catids from GET or POST default to the menu values
     // Note that module links must pass a non default value
     $Itemid = JEVHelper::getItemid();
     $this->myItemid = $Itemid;
     $menu = JFactory::getApplication()->getMenu();
     $active = $menu->getActive();
     if (!is_null($active) && $active->component == JEV_COM_COMPONENT) {
         $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
     } else {
         // If accessing this function from outside the component then I must load suitable parameters
         // We may be calling from a Jevents module so we should use the target menu item if available
         $registry = JRegistry::getInstance("jevents");
         $moduleparams = $registry->get("jevents.moduleparams", false);
         $moduleid = $registry->get("jevents.moduleid", "");
         if ($moduleparams && $moduleparams->get("target_itemid", 0) > 0 && $moduleid) {
             $menuitem = $menu->getItem($moduleparams->get("target_itemid", 0));
             if (!is_null($menuitem) && $menuitem->component == JEV_COM_COMPONENT) {
                 $this->myItemid = $moduleparams->get("target_itemid", 0);
             }
         }
         $params = $menu->getParams($this->myItemid);
     }
     $separator = $params->get("catseparator", "|");
     $catidsIn = JRequest::getVar('catids', 'NONE');
     if ($catidsIn == "NONE" || $catidsIn == 0) {
         $catidsIn = JRequest::getVar('category_fv', 'NONE');
     }
     // set menu/module constraint values for later use
     $this->mmcatids = array();
     // New system
     $newcats = $params->get("catidnew", false);
     if ($newcats && is_array($newcats)) {
         foreach ($newcats as $newcat) {
             if (!in_array($newcat, $this->mmcatids)) {
                 $this->mmcatids[] = $newcat;
             }
         }
     } else {
         for ($c = 0; $c < 999; $c++) {
             $nextCID = "catid{$c}";
             //  stop looking for more catids when you reach the last one!
             if (!($nextCatId = $params->get($nextCID, null))) {
                 break;
             }
             if (!in_array($nextCatId, $this->mmcatids)) {
                 $this->mmcatids[] = $nextCatId;
             }
         }
     }
     $this->mmcatidList = implode(",", $this->mmcatids);
     // if resettting then always reset to module/menu value
     if (intval(JRequest::getVar('filter_reset', 0))) {
         $this->catids = $this->mmcatids;
         $this->catidList = $this->mmcatidList;
     } else {
         $this->catids = array();
         if ($catidsIn == "NONE" || $catidsIn == 0) {
             $this->catidList = "";
             // New system
             $newcats = $params->get("catidnew", false);
             if ($newcats && is_array($newcats)) {
                 foreach ($newcats as $newcat) {
                     if (!in_array($newcat, $this->catids)) {
                         $this->catids[] = $newcat;
                     }
                 }
             } else {
                 for ($c = 0; $c < 999; $c++) {
                     $nextCID = "catid{$c}";
                     //  stop looking for more catids when you reach the last one!
                     if (!($nextCatId = $params->get($nextCID, null))) {
                         break;
                     }
                     if (!in_array($nextCatId, $this->catids)) {
                         $this->catids[] = $nextCatId;
                     }
                 }
             }
             $this->catidList = implode(",", $this->catids);
             // no need to set catidsOut for menu item since the menu item knows this information already!
             //$this->catidsOut = str_replace( ',', $separator, $this->catidList );
         } else {
             $this->catids = explode($separator, $catidsIn);
             // hardening!
             $this->catidList = JEVHelper::forceIntegerArray($this->catids, true);
             $this->catidsOut = str_replace(',', $separator, $this->catidList);
         }
     }
     // some functions e.g. JEventCal::viewDetailLink don't have access to a datamodel so set a global value
     // as a backup
     global $catidsOut;
     $catidsOut = $this->catidsOut;
 }
Exemplo n.º 7
0
 function export()
 {
     $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
     if ($params->get("disableicalexport", 0)) {
         JError::raiseError(403, JText::_('ALERTNOTAUTH'));
     }
     $years = JRequest::getVar('years', 'NONE');
     $cats = JRequest::getVar('catids', 'NONE');
     // validate the key
     $icalkey = $params->get("icalkey", "secret phrase");
     $outlook2003icalexport = JRequest::getInt("outlook2003", 0) && $params->get("outlook2003icalexport", 0);
     if ($outlook2003icalexport) {
         JRequest::setVar("icf", 1);
     }
     $privatecalendar = false;
     $k = JRequest::getString("k", "NONE");
     $pk = JRequest::getString("pk", "NONE");
     $userid = JRequest::getInt("i", 0);
     if ($pk != "NONE") {
         if (!$userid) {
             JError::raiseError(403, "JEV_ERROR");
         }
         $privatecalendar = true;
         $puser = JUser::getInstance($userid);
         $key = md5($icalkey . $cats . $years . $puser->password . $puser->username . $puser->id);
         if ($key != $pk) {
             JError::raiseError(403, "JEV_ERROR");
         }
         if (JVersion::isCompatible("1.6.0")) {
             // ensure "user" can access non-public categories etc.
             $this->dataModel->aid = JEVHelper::getAid($puser);
             $this->dataModel->accessuser = $puser->get('id');
         } else {
             // Get an ACL object
             $acl =& JFactory::getACL();
             // Get the user group from the ACL
             $grp = $acl->getAroGroup($puser->get('id'));
             //Mark the user as logged in
             $puser->set('guest', 0);
             $puser->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')) {
                 $puser->set('aid', 2);
             }
             // ensure "user" can access non-public categories etc.
             $this->dataModel->aid = $puser->aid;
             $this->dataModel->accessuser = $puser->get('id');
         }
         $registry =& JRegistry::getInstance("jevents");
         $registry->setValue("jevents.icaluser", $puser);
     } else {
         if ($k != "NONE") {
             $key = md5($icalkey . $cats . $years);
             if ($key != $k) {
                 JError::raiseError(403, "JEV_ERROR");
             }
         } else {
             JError::raiseError(403, "JEV_ERROR");
         }
     }
     // Fix the cats
     $cats = explode(',', $cats);
     // hardening!
     JEVHelper::forceIntegerArray($cats, false);
     if ($cats != array(0)) {
         JRequest::setVar("catids", implode("|", $cats));
     } else {
         JRequest::setVar("catids", '');
     }
     //Parsing variables from URL
     //Year
     // All years
     if ($years == 0) {
         $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
         $years = array();
         for ($y = $params->get("com_earliestyear", date('Y')); $y <= $params->get("com_latestyear", date('Y')); $y++) {
             if (!in_array($y, $years)) {
                 $years[] = $y;
             }
         }
         JArrayHelper::toInteger($years);
     } else {
         if ($years != "NONE") {
             $years = explode(",", JRequest::getVar('years'));
             if (!is_array($years) || count($years) == 0) {
                 list($y, $m, $d) = JEVHelper::getYMD();
                 $years = array($y);
             }
             JArrayHelper::toInteger($years);
         } else {
             list($y, $m, $d) = JEVHelper::getYMD();
             $years = array($y);
         }
     }
     // Lockin hte categories from the URL
     $this->dataModel->setupComponentCatids();
     $dispatcher =& JDispatcher::getInstance();
     // just incase we don't have jevents plugins registered yet
     JPluginHelper::importPlugin("jevents");
     //And then the real work
     // Force all only the one repeat
     $cfg =& JEVConfig::getInstance();
     $cfg->set('com_showrepeats', 0);
     $icalEvents = array();
     foreach ($years as $year) {
         $startdate = $year . "-01-01";
         $enddate = $year . "-12-31";
         $rows = $this->dataModel->getRangeData($startdate, $enddate, 0, 0);
         if (!isset($rows["rows"])) {
             continue;
         }
         foreach ($rows["rows"] as $row) {
             if (!array_key_exists($row->ev_id(), $icalEvents)) {
                 $dispatcher->trigger('onExportRow', array(&$row));
                 $icalEvents[$row->ev_id()] = $row;
             }
         }
         unset($rows);
     }
     if ($userid) {
         $user = JUser::getInstance($userid);
     }
     $mainframe = JFactory::getApplication();
     // get the view
     $this->view =& $this->getView("icals", "html");
     $this->view->setLayout("export");
     $this->view->assign("dataModel", $this->dataModel);
     $this->view->assign("outlook2003icalexport", $outlook2003icalexport);
     $this->view->assign("icalEvents", $icalEvents);
     $this->view->export();
     return;
 }
Exemplo n.º 8
0
 function export()
 {
     $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
     if ($params->get("disableicalexport", 0)) {
         JError::raiseError(403, JText::_('ALERTNOTAUTH'));
     }
     $years = JRequest::getVar('years', 'NONE');
     $cats = JRequest::getVar('catids', 'NONE');
     // validate the key
     $icalkey = $params->get("icalkey", "secret phrase");
     $outlook2003icalexport = JRequest::getInt("outlook2003", 0) && $params->get("outlook2003icalexport", 0);
     if ($outlook2003icalexport) {
         JRequest::setVar("icf", 1);
     }
     $privatecalendar = false;
     $k = JRequest::getString("k", "NONE");
     $pk = JRequest::getString("pk", "NONE");
     $userid = JRequest::getInt("i", 0);
     if ($pk != "NONE") {
         if (!$userid) {
             JError::raiseError(403, "JEV_ERROR");
         }
         $privatecalendar = true;
         $puser = JUser::getInstance($userid);
         $key = md5($icalkey . $cats . $years . $puser->password . $puser->username . $puser->id);
         if ($key != $pk) {
             JError::raiseError(403, "JEV_ERROR");
         }
         if (!JVersion::isCompatible("1.6.0")) {
             // Get an ACL object
             $acl =& JFactory::getACL();
             // Get the user group from the ACL
             $grp = $acl->getAroGroup($puser->get('id'));
             //Mark the user as logged in
             $puser->set('guest', 0);
             $puser->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')) {
                 $puser->set('aid', 2);
             }
             // ensure "user" can access non-public categories etc.
             $this->dataModel->aid = $puser->aid;
         }
         $registry =& JRegistry::getInstance("jevents");
         $registry->setValue("jevents.icaluser", $puser);
     } else {
         if ($k != "NONE") {
             $key = md5($icalkey . $cats . $years);
             if ($key != $k) {
                 JError::raiseError(403, "JEV_ERROR");
             }
         } else {
             JError::raiseError(403, "JEV_ERROR");
         }
     }
     // Fix the cats
     $cats = explode(',', $cats);
     // hardening!
     JEVHelper::forceIntegerArray($cats, false);
     if ($cats != array(0)) {
         JRequest::setVar("catids", implode("|", $cats));
     } else {
         JRequest::setVar("catids", '');
     }
     //Parsing variables from URL
     //Year
     // All years
     if ($years == 0) {
         $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
         $years = array();
         for ($y = $params->get("com_earliestyear", date('Y')); $y <= $params->get("com_latestyear", date('Y')); $y++) {
             if (!in_array($y, $years)) {
                 $years[] = $y;
             }
         }
         JArrayHelper::toInteger($years);
     } else {
         if ($years != "NONE") {
             $years = explode(",", JRequest::getVar('years'));
             if (!is_array($years) || count($years) == 0) {
                 list($y, $m, $d) = JEVHelper::getYMD();
                 $years = array($y);
             }
             JArrayHelper::toInteger($years);
         } else {
             list($y, $m, $d) = JEVHelper::getYMD();
             $years = array($y);
         }
     }
     // Lockin hte categories from the URL
     $this->dataModel->setupComponentCatids();
     $dispatcher =& JDispatcher::getInstance();
     // just incase we don't have jevents plugins registered yet
     JPluginHelper::importPlugin("jevents");
     //And then the real work
     // Force all only the one repeat
     $cfg =& JEVConfig::getInstance();
     $cfg->set('com_showrepeats', 0);
     $icalEvents = array();
     foreach ($years as $year) {
         $startdate = $year . "-01-01";
         $enddate = $year . "-12-31";
         $rows = $this->dataModel->getRangeData($startdate, $enddate, 0, 0);
         if (!isset($rows["rows"])) {
             continue;
         }
         foreach ($rows["rows"] as $row) {
             if (!array_key_exists($row->ev_id(), $icalEvents)) {
                 $dispatcher->trigger('onExportRow', array(&$row));
                 $icalEvents[$row->ev_id()] = $row;
             }
         }
         unset($rows);
     }
     if ($userid) {
         $user = JUser::getInstance($userid);
     }
     $mainframe = JFactory::getApplication();
     // get the view
     $this->view =& $this->getView("icals", "html");
     $this->view->setLayout("export");
     $this->view->assign("outlook2003icalexport", $outlook2003icalexport);
     $this->view->assign("icalEvents", $icalEvents);
     $this->view->export();
     return;
     /*
      ob_end_clean();
     
      // Define the file as an iCalendar file
      //header('Content-Type: text/calendar; method=request; charset=UTF-8');
      header('Content-Type: application/octet-stream; charset=UTF-8');
      // Give the file a name and force download
      header('Content-Disposition: attachment; filename=calendar.ics');
     
      if ($outlook2003icalexport)
      echo "BEGIN:VCALENDAR\nPRODID:-//jEvents 2.0 for Joomla//EN\n";
      else
      echo "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//jEvents 2.0 for Joomla//EN\n";
     
      echo "CALSCALE:GREGORIAN\nMETHOD:PUBLISH\n";
      if (!empty($icalEvents))
      {
     
      $tzid = $this->vtimezone($icalEvents);
     
      // Build Exceptions dataset - all done in big batches to save multiple queries
      $exceptiondata = array();
      $ids = array();
      foreach ($icalEvents as $a)
      {
      $ids[] = $a->ev_id();
      if (count($ids) > 100)
      {
      $db = JFactory::getDBO();
      $db->setQuery("SELECT * FROM #__jevents_exception where eventid IN (" . implode(",", $ids) . ")");
      $rows = $db->loadObjectList();
      foreach ($rows as $row)
      {
      if (!isset($exceptiondata[$row->eventid]))
      {
      $exceptiondata[$row->eventid] = array();
      }
      $exceptiondata[$row->eventid][$row->rp_id] = $row;
      }
      $ids = array();
      }
      }
      // mop up the last ones
      if (count($ids) > 0)
      {
      $db = JFactory::getDBO();
      $db->setQuery("SELECT * FROM #__jevents_exception where eventid IN (" . implode(",", $ids) . ")");
      $rows = $db->loadObjectList();
      foreach ($rows as $row)
      {
      if (!isset($exceptiondata[$row->eventid]))
      {
      $exceptiondata[$row->eventid] = array();
      }
      $exceptiondata[$row->eventid][$row->rp_id] = $row;
      }
      }
     
      foreach ($icalEvents as $a)
      {
      // if event has repetitions I must find the first one to confirm the dates
      if ($a->hasrepetition())
      {
      $a = $a->getOriginalFirstRepeat();
      }
      echo "BEGIN:VEVENT\n";
      echo "UID:" . $a->uid()."\n";
      echo "CATEGORIES:" . $a->catname()."\n";
      if (!empty($a->_class))
      echo "CLASS:" . $a->_class."\n";
      echo "SUMMARY:" . $a->title() . "\n";
      echo "LOCATION:" . $this->wraplines($this->replacetags($a->location())) . "\n";
      // We Need to wrap this according to the specs
      // echo "DESCRIPTION:".preg_replace("'<[\/\!]*?[^<>]*?>'si","",preg_replace("/\n|\r\n|\r$/","",$a->content()))."\n";
      echo $this->setDescription($a->content())."\n";
     
      if ($a->hasContactInfo())
      echo "CONTACT:" . $this->replacetags($a->contact_info()) . "\n";
      if ($a->hasExtraInfo())
      echo "X-EXTRAINFO:" . $this->wraplines($this->replacetags($a->_extra_info)) . "\n";
     
      // No doing true timezones!
      if ($tzid=="" && is_callable("date_default_timezone_set"))
      {
      // UTC!
      $start = $a->getUnixStartTime();
      $end = $a->getUnixEndTime();
     
      // in case the first repeat has been changed
      if (array_key_exists($a->_eventid, $exceptiondata) && array_key_exists($a->rp_id(), $exceptiondata[$a->_eventid]))
      {
      $start = JevDate::strtotime($exceptiondata[$a->_eventid][$a->rp_id()]->oldstartrepeat);
      }
     
      // Change timezone to UTC
      $current_timezone = date_default_timezone_get();
     
      // If all day event then don't show the start time or end time either
      if ($a->alldayevent())
      {
      $startformat = "%Y%m%d";
      $endformat = "%Y%m%d";
     
      // add 10 seconds to make sure its not midnight the previous night
      $start += 10;
      $end += 10;
      }
      else
      {
      date_default_timezone_set("UTC");
     
      $startformat = "%Y%m%dT%H%M%SZ";
      $endformat = "%Y%m%dT%H%M%SZ";
      }
     
      $start = JevDate::strftime($startformat, $start);
      $end = JevDate::strftime($endformat, $end);
     
      $stamptime = JevDate::strftime("%Y%m%dT%H%M%SZ", time());
     
      // Change back
      date_default_timezone_set($current_timezone);
      }
      else
      {
      $start = $a->getUnixStartTime();
      $end = $a->getUnixEndTime();
     
      // If all day event then don't show the start time or end time either
      if ($a->alldayevent())
      {
      $startformat = "%Y%m%d";
      $endformat = "%Y%m%d";
     
     
      // add 10 seconds to make sure its not midnight the previous night
      $start += 10;
      $end += 10;
      }
      else
      {
      $startformat = "%Y%m%dT%H%M%S";
      $endformat = "%Y%m%dT%H%M%S";
      }
     
      $start = JevDate::strftime($startformat, $start);
      $end = JevDate::strftime($endformat, $end);
      $stamptime = JevDate::strftime("%Y%m%dT%H%M%S", time());
     
      // in case the first repeat is changed
      if (array_key_exists($a->_eventid, $exceptiondata) && array_key_exists($a->rp_id(), $exceptiondata[$a->_eventid]))
      {
      $start = JevDate::strftime($startformat, JevDate::strtotime($exceptiondata[$a->_eventid][$a->rp_id()]->oldstartrepeat));
      }
      }
     
      echo "DTSTAMP$tzid:" . $stamptime . "\n";
      echo "DTSTART$tzid:" . $start . "\n";
      // events with no end time don't give a DTEND
      if (!$a->noendtime())
      {
      echo "DTEND$tzid:" . $end . "\n";
      }
      echo "SEQUENCE:" . $a->_sequence . "\n";
      if ($a->hasrepetition())
      {
      echo 'RRULE:';
     
      // TODO MAKE SURE COMPAIBLE COMBINATIONS
      echo 'FREQ=' . $a->_freq;
      if ($a->_until != "" && $a->_until != 0)
      {
      echo ';UNTIL=' . JevDate::strftime("%Y%m%dT235959Z", $a->_until);
      }
      else if ($a->_count != "")
      {
      echo ';COUNT=' . $a->_count;
      }
      if ($a->_rinterval != "")
      echo ';INTERVAL=' . $a->_rinterval;
      if ($a->_freq == "DAILY")
      {
     
      }
      else if ($a->_freq == "WEEKLY")
      {
      if ($a->_byday != "")
      echo ';BYDAY=' . $a->_byday;
      }
      else if ($a->_freq == "MONTHLY")
      {
      if ($a->_bymonthday != "")
      {
      echo ';BYMONTHDAY=' . $a->_bymonthday;
      if ($a->_byweekno != "")
      echo ';BYWEEKNO=' . $a->_byweekno;
      }
      else if ($a->_byday != "")
      {
      echo ';BYDAY=' . $a->_byday;
      if ($a->_byweekno != "")
      echo ';BYWEEKNO=' . $a->_byweekno;
      }
      }
      else if ($a->_freq == "YEARLY")
      {
      if ($a->_byyearday != "")
      echo ';BYYEARDAY=' . $a->_byyearday;
      }
      echo "\n";
      }
     
      // Now handle Exceptions
      $exceptions = array();
      if (array_key_exists($a->ev_id(), $exceptiondata))
      {
      $exceptions = $exceptiondata[$a->ev_id()];
      }
     
      $deletes = array();
      $changed = array();
      $changedexceptions = array();
      if (count($exceptions) > 0)
      {
      foreach ($exceptions as $exception)
      {
      if ($exception->exception_type == 0)
      {
      $exceptiondate = JevDate::strtotime($exception->startrepeat);
     
      // No doing true timezones!
      if ($tzid=="" && is_callable("date_default_timezone_set"))
      {
     
      // Change timezone to UTC
      $current_timezone = date_default_timezone_get();
      date_default_timezone_set("UTC");
     
      $deletes[] = JevDate::strftime("%Y%m%dT%H%M%SZ", $exceptiondate);
     
      // Change back
      date_default_timezone_set($current_timezone);
      }
      else
      {
      $deletes[] = JevDate::strftime("%Y%m%dT%H%M%S", $exceptiondate);
      }
      }
      else
      {
      $changed[] = $exception->rp_id;
      $changedexceptions[$exception->rp_id] = $exception;
      }
      }
      if (count($deletes) > 0)
      {
      echo "EXDATE:" . $this->wraplines(implode(",", $deletes)) . "\n";
      }
      }
     
      echo "TRANSP:OPAQUE\n";
      echo "END:VEVENT\n";
     
     
      if (count($changed) > 0)
      {
      foreach ($changed as $rpid)
      {
      $a = $this->dataModel->getEventData($rpid, "icaldb", 0, 0, 0);
      if ($a && isset($a["row"]))
      {
      $a = $a["row"];
     
      $dispatcher = & JDispatcher::getInstance();
      $dispatcher->trigger('onDisplayCustomFields', array(& $a));
     
      echo "BEGIN:VEVENT\n";
      echo "UID:" . $a->uid()."\n";
      echo "CATEGORIES:" . $a->catname()."\n";
      if (!empty($a->_class))
      echo "CLASS:" . $a->_class."\n";
      echo  "SUMMARY:" . $a->title() . "\n";
      echo "LOCATION:" . $this->wraplines($this->replacetags($a->location())) . "\n";
      // We Need to wrap this according to the specs
      echo $this->setDescription($a->content()) . "\n";
     
      if ($a->hasContactInfo())
      echo "CONTACT:" . $this->replacetags($a->contact_info()) . "\n";
      if ($a->hasExtraInfo())
      echo "X-EXTRAINFO:" . $this->wraplines($this->replacetags($a->_extra_info)); echo "\n";
     
      $exception = $changedexceptions[$rpid];
      $originalstart = JevDate::strtotime($exception->oldstartrepeat);
      $chstart = $a->getUnixStartTime();
      $chend = $a->getUnixEndTime();
     
      // No doing true timezones!
      if ($tzid=="" && is_callable("date_default_timezone_set"))
      {
      // UTC!
      // Change timezone to UTC
      $current_timezone = date_default_timezone_get();
      date_default_timezone_set("UTC");
     
      $chstart = JevDate::strftime("%Y%m%dT%H%M%SZ", $chstart);
      $chend = JevDate::strftime("%Y%m%dT%H%M%SZ", $chend);
      $stamptime = JevDate::strftime("%Y%m%dT%H%M%SZ", time());
      $originalstart = JevDate::strftime("%Y%m%dT%H%M%SZ", $originalstart);
      // Change back
      date_default_timezone_set($current_timezone);
      }
      else
      {
      $chstart = JevDate::strftime("%Y%m%dT%H%M%S", $chstart);
      $chend = JevDate::strftime("%Y%m%dT%H%M%S", $chend);
      $stamptime = JevDate::strftime("%Y%m%dT%H%M%S", time());
      $originalstart = JevDate::strftime("%Y%m%dT%H%M%S", $originalstart);
      }
      echo "DTSTAMP$tzid:" . $stamptime . "\n";
      echo "DTSTART$tzid:" . $chstart . "\n";
      echo "DTEND$tzid:" . $chend . "\n";
      echo "RECURRENCE-ID:" . $originalstart . "\n";
      echo "SEQUENCE:" . $a->_sequence . "\n";
      echo "TRANSP:OPAQUE\n";
      echo "END:VEVENT\n";
      }
      }
      }
      }
      }
     
     
      echo "END:VCALENDAR";
      exit();
     */
 }