function simulateSaveRepeat($requestObject)
{
    include_once JPATH_SITE . "/components/com_jevents/jevents.defines.php";
    if (!JEVHelper::isEventCreator()) {
        throwerror(JText::_('ALERTNOTAUTH'));
    }
    // Convert formdata to array
    $formdata = array();
    foreach (get_object_vars($requestObject->formdata) as $k => $v) {
        $k = str_replace("[]", "", $k);
        $formdata[$k] = $v;
    }
    $array = JRequest::_cleanVar($formdata, JREQUEST_ALLOWHTML);
    if (!array_key_exists("rp_id", $array) || intval($array["rp_id"]) <= 0) {
        throwerror(JText::_("Not a repeat", true));
    }
    $rp_id = intval($array["rp_id"]);
    $dataModel = new JEventsDataModel("JEventsAdminDBModel");
    $queryModel = new JEventsDBModel($dataModel);
    // I should be able to do this in one operation but that can come later
    $event = $queryModel->listEventsById(intval($rp_id), 1, "icaldb");
    if (!JEVHelper::canEditEvent($event)) {
        throwerror(JText::_('ALERTNOTAUTH'));
    }
    $db =& JFactory::getDBO();
    $rpt = new iCalRepetition($db);
    $rpt->load($rp_id);
    $query = "SELECT detail_id FROM #__jevents_vevent WHERE ev_id={$rpt->eventid}";
    $db->setQuery($query);
    $eventdetailid = $db->loadResult();
    $data["UID"] = valueIfExists($array, "uid", md5(uniqid(rand(), true)));
    $data["X-EXTRAINFO"] = valueIfExists($array, "extra_info", "");
    $data["LOCATION"] = valueIfExists($array, "location", "");
    $data["allDayEvent"] = valueIfExists($array, "allDayEvent", "off");
    $data["CONTACT"] = valueIfExists($array, "contact_info", "");
    // allow raw HTML (mask =2)
    $data["DESCRIPTION"] = valueIfExists($array, "jevcontent", "", 'request', 'html', 2);
    $data["publish_down"] = valueIfExists($array, "publish_down", "2006-12-12");
    $data["publish_up"] = valueIfExists($array, "publish_up", "2006-12-12");
    $interval = valueIfExists($array, "rinterval", 1);
    $data["SUMMARY"] = valueIfExists($array, "title", "");
    $data["MULTIDAY"] = intval(valueIfExists($array, "multiday", "1"));
    $data["NOENDTIME"] = intval(valueIfExists($array, "noendtime", 0));
    $ics_id = valueIfExists($array, "ics_id", 0);
    if ($data["allDayEvent"] == "on") {
        $start_time = "00:00";
    } else {
        $start_time = valueIfExists($array, "start_time", "08:00");
    }
    $publishstart = $data["publish_up"] . ' ' . $start_time . ':00';
    $data["DTSTART"] = JevDate::strtotime($publishstart);
    if ($data["allDayEvent"] == "on") {
        $end_time = "23:59";
        $publishend = $data["publish_down"] . ' ' . $end_time . ':59';
    } else {
        $end_time = valueIfExists($array, "end_time", "15:00");
        $publishend = $data["publish_down"] . ' ' . $end_time . ':00';
    }
    $data["DTEND"] = JevDate::strtotime($publishend);
    // iCal for whole day uses 00:00:00 on the next day JEvents uses 23:59:59 on the same day
    list($h, $m, $s) = explode(":", $end_time . ':00');
    if ($h + $m + $s == 0 && $data["allDayEvent"] == "on" && $data["DTEND"] > $data["DTSTART"]) {
        $publishend = JevDate::strftime('%Y-%m-%d 23:59:59', $data["DTEND"] - 86400);
        $data["DTEND"] = JevDate::strtotime($publishend);
    }
    $data["X-COLOR"] = valueIfExists($array, "color", "");
    // Add any custom fields into $data array
    foreach ($array as $key => $value) {
        if (strpos($key, "custom_") === 0) {
            $data[$key] = $value;
        }
    }
    // populate rpt with data
    $start = $data["DTSTART"];
    $end = $data["DTEND"];
    $rpt->startrepeat = JevDate::strftime('%Y-%m-%d %H:%M:%S', $start);
    $rpt->endrepeat = JevDate::strftime('%Y-%m-%d %H:%M:%S', $end);
    $rpt->duplicatecheck = md5($rpt->eventid . $start);
    $rpt->rp_id = $rp_id;
    $rpt->event = $event;
    return $rpt;
}
示例#2
0
 private function doSave(&$msg)
 {
     if (!JEVHelper::isEventCreator()) {
         throw new Exception(JText::_('ALERTNOTAUTH'), 403);
         return false;
     }
     // clean out the cache
     $cache = JFactory::getCache('com_jevents');
     $cache->clean(JEV_COM_COMPONENT);
     $option = JEV_COM_COMPONENT;
     $rp_id = intval(JRequest::getVar("rp_id", "0"));
     $cid = JRequest::getVar("cid", array());
     if (count($cid) > 0 && $rp_id == 0) {
         $rp_id = intval($cid[0]);
     }
     if ($rp_id == 0) {
         $this->setRedirect('index.php?option=' . $option . '&task=icalrepeat.list&cid[]=' . $rp_id, "1Cal rpt NOT SAVED");
         $this->redirect();
     }
     // I should be able to do this in one operation but that can come later
     $event = $this->queryModel->listEventsById(intval($rp_id), 1, "icaldb");
     if (!JEVHelper::canEditEvent($event)) {
         throw new Exception(JText::_('ALERTNOTAUTH'), 403);
         return false;
     }
     $db = JFactory::getDBO();
     $rpt = new iCalRepetition($db);
     $rpt->load($rp_id);
     $query = "SELECT detail_id FROM #__jevents_vevent WHERE ev_id={$rpt->eventid}";
     $db->setQuery($query);
     $eventdetailid = $db->loadResult();
     $data["UID"] = JRequest::getVar("uid", md5(uniqid(rand(), true)));
     $data["X-EXTRAINFO"] = JRequest::getVar("extra_info", "");
     $data["LOCATION"] = JRequest::getVar("location", "");
     $data["allDayEvent"] = JRequest::getVar("allDayEvent", "off");
     $data["CONTACT"] = JRequest::getVar("contact_info", "");
     // allow raw HTML (mask =2)
     $data["DESCRIPTION"] = JRequest::getVar("jevcontent", "", 'request', 'html', 2);
     $data["publish_down"] = JRequest::getVar("publish_down", "2006-12-12");
     $data["publish_up"] = JRequest::getVar("publish_up", "2006-12-12");
     // Alternative date format handling
     if (JRequest::getVar("publish_up2", false)) {
         $data["publish_up"] = JRequest::getVar("publish_up2", $data["publish_up"]);
     }
     if (JRequest::getVar("publish_down2", false)) {
         $data["publish_down"] = JRequest::getVar("publish_down2", $data["publish_down"]);
     }
     $interval = JRequest::getVar("rinterval", 1);
     $data["SUMMARY"] = JRequest::getVar("title", "");
     $data["MULTIDAY"] = JRequest::getInt("multiday", "1");
     $data["NOENDTIME"] = JRequest::getInt("noendtime", 0);
     $ics_id = JRequest::getVar("ics_id", 0);
     if ($data["allDayEvent"] == "on") {
         $start_time = "00:00";
     } else {
         $start_time = JRequest::getVar("start_time", "08:00");
     }
     $publishstart = $data["publish_up"] . ' ' . $start_time . ':00';
     $data["DTSTART"] = JevDate::strtotime($publishstart);
     if ($data["allDayEvent"] == "on") {
         $end_time = "23:59";
         $publishend = $data["publish_down"] . ' ' . $end_time . ':59';
     } else {
         $end_time = JRequest::getVar("end_time", "15:00");
         $publishend = $data["publish_down"] . ' ' . $end_time . ':00';
     }
     $data["DTEND"] = JevDate::strtotime($publishend);
     // iCal for whole day uses 00:00:00 on the next day JEvents uses 23:59:59 on the same day
     list($h, $m, $s) = explode(":", $end_time . ':00');
     if ($h + $m + $s == 0 && $data["allDayEvent"] == "on" && $data["DTEND"] > $data["DTSTART"]) {
         $publishend = JevDate::strftime('%Y-%m-%d 23:59:59', $data["DTEND"] - 86400);
         $data["DTEND"] = JevDate::strtotime($publishend);
     }
     $data["X-COLOR"] = JRequest::getVar("color", "");
     // Add any custom fields into $data array - allowing HTML (which can be cleaned up later by plugins)
     $array = JRequest::get("post", 2);
     foreach ($array as $key => $value) {
         if (strpos($key, "custom_") === 0) {
             $data[$key] = $value;
         }
         // convert jform data to data format used before
         if (strpos($key, "jform") === 0 && is_array($value)) {
             foreach ($value as $cfkey => $cfvalue) {
                 $data["custom_" . $cfkey] = $cfvalue;
             }
         }
     }
     $detail = iCalEventDetail::iCalEventDetailFromData($data);
     // if we already havea unique event detail then edit this one!
     if ($eventdetailid != $rpt->eventdetail_id) {
         $detail->evdet_id = $rpt->eventdetail_id;
     }
     $detail->priority = intval(JArrayHelper::getValue($array, "priority", 0));
     $detail->store();
     // KEEP THE ORIGINAL START REPEAT FOR THE EXCEPTION HANDLING
     $original_start = $rpt->startrepeat;
     // populate rpt with data
     //$start = JevDate::strtotime($data["publish_up"] . ' ' . $start_time . ':00');
     //$end = JevDate::strtotime($data["publish_down"] . ' ' . $end_time . ':00');
     $start = $data["DTSTART"];
     $end = $data["DTEND"];
     $rpt->startrepeat = JevDate::strftime('%Y-%m-%d %H:%M:%S', $start);
     $rpt->endrepeat = JevDate::strftime('%Y-%m-%d %H:%M:%S', $end);
     $rpt->duplicatecheck = md5($rpt->eventid . $start);
     $rpt->eventdetail_id = $detail->evdet_id;
     $rpt->rp_id = $rp_id;
     $rpt->store();
     // I may also need to process repeat changes
     $dispatcher = JDispatcher::getInstance();
     // just incase we don't have jevents plugins registered yet
     JPluginHelper::importPlugin("jevents");
     $res = $dispatcher->trigger('onStoreCustomRepeat', array(&$rpt));
     $exception = iCalException::loadByRepeatId($rp_id);
     if (!$exception) {
         $exception = new iCalException($db);
         $exception->bind(get_object_vars($rpt));
         // ONLY set the old start repeat when first creating the exception
         $exception->oldstartrepeat = $original_start;
     }
     $exception->exception_type = 1;
     // modified
     $exception->store();
     return $rpt;
 }