/** * create new ICAL from scratch */ function newical() { // include ical files $catid = intval(JRequest::getVar('catid', 0)); // Should come from the form or existing item $access = JRequest::getInt('access', 0); $state = 1; $icsLabel = JRequest::getVar('icsLabel', ''); if ($catid == 0) { // Paranoia, should not be here, validation is done by java script JError::raiseError('Fatal error', JText::_('JEV_E_WARNCAT')); JFactory::getApplication()->redirect('index.php?option=' . $option); return; } $icsid = 0; $icsFile = iCalICSFile::editICalendar($icsid, $catid, $access, $state, $icsLabel); $icsFileid = $icsFile->store(); $this->setRedirect("index.php?option=" . JEV_COM_COMPONENT . "&task=icals.list", JText::_('ICAL_FILE_CREATED')); }
/** * Used to create Ical from raw strring */ function newICSFileFromString($rawtext, $icsid, $catid, $access = 0, $state = 1, $label = "", $autorefresh = 0, $ignoreembedcat = 0) { $db = JFactory::getDBO(); $temp = null; $temp = new iCalICSFile($db); if ($icsid > 0) { $temp->load($icsid); $temp->icaltype = 2; // i.e. from file } else { $temp->_setup($icsid, $catid, $access, $state, $autorefresh, $ignoreembedcat); $temp->srcURL = ""; $temp->filename = "_from_events_cat" . $catid; $temp->icaltype = 2; // i.e. from file if ($label != "") { $temp->label = $label; } else { $temp->label = $temp->filename; } } $temp->_icalInfo =& JEVHelper::iCalInstance("", $rawtext); return $temp; }
function importdata() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); // Can only do this if can add an event // Must be at least an event creator to edit or create events $is_event_editor = JEVHelper::isEventCreator(); if (!$is_event_editor) { $user = JFactory::getUser(); if ($user->id) { $this->setRedirect(JURI::root(), JText::_('JEV_NOTAUTH_CREATE_EVENT')); $this->redirect(); } else { $comuser = version_compare(JVERSION, '1.6.0', '>=') ? "com_users" : "com_user"; $this->setRedirect(JRoute::_("index.php?option={$comuser}&view=login"), JText::_('JEV_NOTAUTH_CREATE_EVENT')); $this->redirect(); } return; } $params = JComponentHelper::getParams(JEV_COM_COMPONENT); if (!$params->get("feimport", 0)) { return; } $catid = JRequest::getInt('catid', 0); $ignoreembedcat = JRequest::getInt('ignoreembedcat', 0); // Should come from the form or existing item $access = 0; $state = 1; $uploadURL = JRequest::getVar('uploadURL', ''); $icsLabel = uniqid('icsLabel'); $icsid = JRequest::getInt('icsid', 0); $autorefresh = 0; if ($catid == 0) { // Paranoia, should not be here, validation is done by java script // Just load the ical event list on redirect for now. $redirect_task = "icalevent.list"; JError::raiseError('Fatal error', JText::_('JEV_E_WARNCAT')); $this->setRedirect("index.php?option=" . JEV_COM_COMPONENT . "&task={$redirect_task}", JText::_('JEV_E_WARNCAT')); $this->redirect(); return; } // I need a better check and expiry information etc. if (JString::strlen($uploadURL) > 0) { $icsFile = iCalICSFile::newICSFileFromURL($uploadURL, $icsid, $catid, $access, $state, $icsLabel, $autorefresh, $ignoreembedcat); } else { if (isset($_FILES['upload']) && is_array($_FILES['upload'])) { $file = $_FILES['upload']; if ($file['size'] == 0) { //|| !($file['type']=="text/calendar" || $file['type']=="application/octet-stream")){ JError::raiseWarning(0, 'empty upload file'); $icsFile = false; } else { $icsFile = iCalICSFile::newICSFileFromFile($file, $icsid, $catid, $access, $state, $icsLabel, 0, $ignoreembedcat); } } } $count = 0; if ($icsFile !== false) { $count = $icsFile->storeEvents(); } list($year, $month, $day) = JEVHelper::getYMD(); ob_end_clean(); ?> <script type="text/javascript"> window.alert("<?php echo JText::sprintf("JEV_EVENTS_IMPORTED", $count); ?> "); try { window.parent.jQuery('#myImportModal').modal('hide'); } catch (e){} try { window.parent.SqueezeBox.close(); } catch (e){} //window.parent.location.reload(); </script> <?php exit; }
function convertjcal() { global $task; $cfg =& JEVConfig::getInstance(); $option = $cfg->get("com_componentname", "com_events"); $db =& JFactory::getDBO(); /** * Categories first **/ $query = "SELECT * FROM #__jcalpro_categories"; $db->setQuery($query); $cats = $db->loadObjectList(); foreach ($cats as $ec) { // Remove identical category first !! // First remove the extra jevents category information $query = "SELECT id FROM #__categories" . "\n WHERE title='{$ec->cat_name} (jcal)' and section='com_events'"; $db->setQuery($query); $ids = $db->loadResultArray(); $idlist = implode(",", $ids); if (count($ids) > 0) { $idlist = implode(",", $ids); $query = "DELETE FROM #__events_categories WHERE id IN ({$idlist})"; $db->setQuery($query); if (!$db->query()) { $error = array($db->getErrorMsg(), $query); echo "Error in - " . $error[1] . "<br/>"; echo "Error message is " . $error[0] . "<hr/>"; } $query = "DELETE FROM #__categories" . "\n WHERE id IN ({$idlist})"; $db->setQuery($query); if (!$db->query()) { $error = array($db->getErrorMsg(), $query); echo "Error in - " . $error[1] . "<br/>"; echo "Error message is " . $error[0] . "<hr/>"; } } // Assume for time being all parents = 0!! $query = "INSERT INTO #__categories" . "\n (parent_id, title, name, image, section, image_position, description, published, checked_out, checked_out_time, editor, ordering, access, count, params)" . "\n VALUES (0, '{$ec->cat_name} (jcal)', '{$ec->cat_name} (jcal)', '', 'com_events' ,'left', '{$ec->description}', {$ec->published}, {$ec->checked_out}, '{$ec->checked_out_time}','',0,0,0,'') "; $db->setQuery($query); if (!$db->query()) { $error = array($db->getErrorMsg(), $query); echo "Error in - " . $error[1] . "<br/>"; echo "Error message is " . $error[0] . "<hr/>"; } // Now set the extra jevents category information $query = "SELECT id FROM #__categories" . "\n WHERE title='{$ec->cat_name} (jcal)'"; $db->setQuery($query); $id = $db->loadResult(); if ($id > 0) { $query = "INSERT INTO #__events_categories" . "\n (id, color)" . "\n VALUES ({$id}, '{$ec->color}')"; $db->setQuery($query); if (!$db->query()) { $error = array($db->getErrorMsg(), $query); echo "Error in - " . $error[1] . "<br/>"; echo "Error message is " . $error[0] . "<hr/>"; } } } /** * Now to convert the events put them in a special series of icals from scratch called by their category names */ include_once JPATH_SITE . "/components/" . JEV_COM_COMPONENT . "/libraries/iCalImport.php"; foreach ($cats as $ec) { // clean out any aborter migration attempts $query = "DELETE FROM #__jevents_icsfile" . "\n WHERE label='{$ec->cat_name} (jcal)'" . "\n AND icaltype=2"; $db->setQuery($query); if (!$db->query()) { $error = array($db->getErrorMsg(), $query); echo "Error in - " . $error[1] . "<br/>"; echo "Error message is " . $error[0] . "<hr/>"; } $query = "SELECT id FROM #__categories" . "\n WHERE title='{$ec->cat_name} (jcal)' and section='com_events'"; $db->setQuery($query); $catid = $db->loadResult(); if (is_null($catid) || $catid == 0) { echo "missing category selection<br/>"; return; } // Should come from the form or existing item $access = 0; $state = 1; $icsLabel = "{$ec->cat_name} (jcal)"; $icsid = 0; $icsFile = iCalICSFile::editICalendar($icsid, $catid, $access, $state, $icsLabel); $icsFileid = $icsFile->store(); $query = "SELECT * FROM #__jcalpro_events" . "\n WHERE cat={$ec->cat_id}"; $db->setQuery($query); $exevents = $db->loadObjectList(); foreach ($exevents as $xv) { $temp = new stdClass(); $icalevent = new jEventCal($temp); $icalevent['uid'] = md5(uniqid(rand(), true)); $icalevent['adresse_info'] = ""; // TODO check this $icalevent['allDayEvent'] = "off"; $icalevent['contact_info'] = $ec->contact . " " . $ec->email; $icalevent['content'] = $ec->description . "<hr/>" . $ec->url; //$icalevent['publish_down'] //$icalevent['publish_up'] $icalevent['rinterval'] = $ec->recur_val; $icalevent['title'] = $ec->title; $icalevent['ics_id'] = $icsFileid; /* $icalevent['start_time'] = JArrayHelper::getValue( $array, "start_time","08:00"); else $end_time = JArrayHelper::getValue( $array, "end_time","15:00"); $countuntil = JArrayHelper::getValue( $array, "countuntil","count"); $count = intval(JArrayHelper::getValue( $array, "count",1); $until = JArrayHelper::getValue($array, "until",$data["publish_down"]); $whichby = JArrayHelper::getValue($array, "whichby","bd"); $byd_direction = JArrayHelper::getValue($array, "byd_direction","off")=="off"?"+":"-"; $byyearday = JArrayHelper::getValue($array, "byyearday",""); $bm_direction = JArrayHelper::getValue($array, "bm_direction","off")=="off"?"+":"-"; $bymonth = JArrayHelper::getValue($array, "bymonth",""); $bwn_direction = JArrayHelper::getValue($array, "bwn_direction","off")=="off"?"+":"-"; $byweekno = JArrayHelper::getValue($array, "byweekno",""); $bmd_direction = JArrayHelper::getValue($array, "bmd_direction","off")=="off"?"+":"-"; $bymonthday = JArrayHelper::getValue($array, "bymonthday",""); $bd_direction = JArrayHelper::getValue($array, "bd_direction","off")=="off"?"+":"-"; $weekdays = JArrayHelper::getValue($array, "weekdays",array()); $weeknums = JArrayHelper::getValue($array, "weeknums",array()); $vevent->catid = JArrayHelper::getValue($array, "catid",0); $vevent->access = JArrayHelper::getValue($array, "access",0); $vevent->state = intval(JArrayHelper::getValue($array, "state",0)); */ } } }