Ejemplo n.º 1
0
 function save()
 {
     $authorised = false;
     if (JFactory::getApplication()->isAdmin()) {
         $redirect_task = "icals.list";
     } else {
         $redirect_task = "month.calendar";
     }
     // clean this up later - this is a quick fix for frontend reloading
     $autorefresh = 0;
     $icsid = intval(JRequest::getVar('icsid', 0));
     if ($icsid > 0) {
         $query = "SELECT icsf.* FROM #__jevents_icsfile as icsf WHERE ics_id={$icsid}";
         $db =& JFactory::getDBO();
         $db->setQuery($query);
         $currentICS = $db->loadObjectList();
         if (count($currentICS) > 0) {
             $currentICS = $currentICS[0];
             if ($currentICS->autorefresh) {
                 $authorised = true;
                 $autorefresh = 1;
             }
         }
     }
     $user =& JFactory::getUser();
     if (!($authorised || JEVHelper::isAdminUser($user))) {
         $this->setRedirect("index.php?option=" . JEV_COM_COMPONENT . "&task={$redirect_task}", "Not Authorised - must be super admin");
         return;
     }
     $cid = JRequest::getVar('cid', array(0));
     JArrayHelper::toInteger($cid);
     if (is_array($cid) && count($cid) > 0) {
         $cid = $cid[0];
     } else {
         $cid = 0;
     }
     $db =& JFactory::getDBO();
     // include ical files
     if ($icsid > 0 || $cid != 0) {
         $icsid = $icsid > 0 ? $icsid : $cid;
         $query = "SELECT icsf.* FROM #__jevents_icsfile as icsf WHERE ics_id={$icsid}";
         $db->setQuery($query);
         $currentICS = $db->loadObjectList();
         if (count($currentICS) > 0) {
             $currentICS = $currentICS[0];
             if ($currentICS->autorefresh) {
                 $authorised = true;
                 $autorefresh = 1;
             }
         } else {
             $this->setRedirect("index.php?option=" . JEV_COM_COMPONENT . "&task={$redirect_task}", "Invalid Ical Details");
             $this->redirect();
         }
         $catid = JRequest::getInt('catid', $currentICS->catid);
         if ($catid <= 0 && $currentICS->catid > 0) {
             $catid = intval($currentICS->catid);
         }
         $access = intval(JRequest::getVar('access', $currentICS->access));
         if ($access < 0 && $currentICS->access >= 0) {
             $access = intval($currentICS->access);
         }
         $icsLabel = JRequest::getVar('icsLabel', $currentICS->label);
         if ($icsLabel == "" && strlen($currentICS->icsLabel) >= 0) {
             $icsLabel = $currentICS->icsLabel;
         }
         $isdefault = JRequest::getInt('isdefault', $currentICS->isdefault);
         $autorefresh = JRequest::getInt('autorefresh', $autorefresh);
         $ignoreembedcat = JRequest::getInt('ignoreembedcat', $currentICS->ignoreembedcat);
         // This is a native ical - so we are only updating identifiers etc
         if ($currentICS->icaltype == 2) {
             $ics = new iCalICSFile($db);
             $ics->load($icsid);
             $ics->catid = $catid;
             $ics->isdefault = $isdefault;
             $ics->access = $access;
             $ics->label = $icsLabel;
             // TODO update access and state
             $ics->updateDetails();
             $this->setRedirect("index.php?option=" . JEV_COM_COMPONENT . "&task={$redirect_task}", JText::_('ICS_SAVED'));
             $this->redirect();
         }
         $state = 1;
         if (strlen($currentICS->srcURL) == 0) {
             echo "Can only reload URL based subscriptions";
             return;
         }
         $uploadURL = $currentICS->srcURL;
     } else {
         $catid = JRequest::getInt('catid', 0);
         $ignoreembedcat = JRequest::getInt('ignoreembedcat', 0);
         // Should come from the form or existing item
         $access = JRequest::getInt('access', 0);
         $state = 1;
         $uploadURL = JRequest::getVar('uploadURL', '');
         $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'));
         $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 (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);
             }
         }
     }
     // preserve ownership
     if (isset($currentICS) && $currentICS->created_by > 0) {
         $icsFile->created_by = $currentICS->created_by;
     }
     $message = '';
     if ($icsFile !== false) {
         $icsFileid = $icsFile->store();
         $message = JText::_('ICS_FILE_IMPORTED');
     }
     $this->setRedirect("index.php?option=" . JEV_COM_COMPONENT . "&task={$redirect_task}", $message);
 }
Ejemplo n.º 2
0
    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;
    }