/** * 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')); }
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)); */ } } }