function checkRepeatOverlaps($repeat, &$returnData, $eventid, $requestObject) { $params =& JComponentHelper::getParams("com_jevents"); $db = JFactory::getDBO(); $overlaps = array(); if ($params->get("noclashes", 0)) { $sql = "SELECT * FROM #__jevents_repetition as rpt "; $sql .= " LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id=rpt.eventdetail_id "; $sql .= " WHERE rpt.rp_id<>" . intval($repeat->rp_id) . " AND rpt.startrepeat<" . $db->Quote($repeat->endrepeat) . " AND rpt.endrepeat>" . $db->Quote($repeat->startrepeat); $sql .= " LIMIT 100"; $db->setQuery($sql); $conflicts = $db->loadObjectList(); if ($conflicts && count($conflicts) > 0) { foreach ($conflicts as &$conflict) { $conflict->conflictCause = JText::_("JEV_GENERAL_OVERLAP"); } unset($conflict); $overlaps = array_merge($overlaps, $conflicts); } } else { if ($params->get("checkclashes", 0)) { $dataModel = new JEventsDataModel(); $dbModel = new JEventsDBModel($dataModel); $skipCatTest = false; $catinfo = $dbModel->getCategoryInfo(array($repeat->event->catid())); if ($catinfo && count($catinfo) == 1) { $catinfo = current($catinfo); if (JVersion::isCompatible("1.6.0")) { $catparams = json_decode($catinfo->params); if (!$catparams->overlaps) { $skipCatTest = true; } } else { if (!$catinfo->overlaps) { $skipCatTest = true; } } } if (!$skipCatTest) { $sql = "SELECT * FROM #__jevents_repetition as rpt "; $sql .= " LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id=rpt.eventdetail_id "; $sql .= " LEFT JOIN #__jevents_vevent as evt ON evt.ev_id=rpt.eventid "; $sql .= " WHERE rpt.rp_id<>" . intval($repeat->rp_id) . " AND rpt.startrepeat<" . $db->Quote($repeat->endrepeat) . " AND rpt.endrepeat>" . $db->Quote($repeat->startrepeat); //$sql .= " AND (evt.catid=".$repeat->event->catid()." OR evt.icsid=".$repeat->event->icsid().") GROUP BY rpt.rp_id"; $sql .= " AND (evt.catid=" . $repeat->event->catid() . ") GROUP BY rpt.rp_id"; $sql .= " LIMIT 100"; $db->setQuery($sql); $conflicts = $db->loadObjectList(); if ($conflicts && count($conflicts) > 0) { foreach ($conflicts as &$conflict) { $conflict->conflictCause = JText::sprintf("JEV_CATEGORY_CLASH", $repeat->event->getCategoryName()); } unset($conflict); $overlaps = array_merge($overlaps, $conflicts); } } } } $dispatcher =& JDispatcher::getInstance(); $dispatcher->trigger('onCheckRepeatOverlaps', array(&$repeat, &$overlaps, $eventid, $requestObject)); return $overlaps; }
function checkRepeatOverlaps($repeat, &$returnData, $eventid, $requestObject) { $params = JComponentHelper::getParams("com_jevents"); $db = JFactory::getDBO(); $overlaps = array(); if ($params->get("noclashes", 0)) { $sql = "SELECT *, ev.state FROM #__jevents_repetition as rpt "; $sql .= " LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id=rpt.eventdetail_id "; $sql .= " LEFT JOIN #__jevents_vevent as ev ON ev.ev_id=rpt.eventid "; $sql .= " WHERE rpt.rp_id<>" . intval($repeat->rp_id) . " AND rpt.startrepeat<" . $db->Quote($repeat->endrepeat) . " AND rpt.endrepeat>" . $db->Quote($repeat->startrepeat); $sql .= " AND ev.state=1"; $sql .= " LIMIT 100"; $db->setQuery($sql); $conflicts = $db->loadObjectList(); if ($conflicts && count($conflicts) > 0) { foreach ($conflicts as &$conflict) { $conflict->conflictCause = JText::_("JEV_GENERAL_OVERLAP"); } unset($conflict); $overlaps = array_merge($overlaps, $conflicts); } } else { if ($params->get("checkclashes", 0)) { $dataModel = new JEventsDataModel(); $dbModel = new JEventsDBModel($dataModel); $catids = $repeat->event->catids(); if (!$catids) { $catids = array($repeat->event->catid()); } $skipCatTest = false; $catinfo = $dbModel->getCategoryInfo($catids); if ($catinfo && count($catinfo) > 0) { for ($c = 0; $c < count($catids); $c++) { if (isset($catinfo[$catids[$c]])) { $cinfo = $catinfo[$catids[$c]]; $catparams = json_decode($cinfo->params); if (!$catparams->overlaps) { unset($catids[$c]); } } } if (count($catids) == 0) { $skipCatTest = true; } } else { $skipCatTest = true; } if (!$skipCatTest) { $sql = "SELECT *, evt.catid, evt.state "; if ($params->get("multicategory", 0)) { $sql .= ", GROUP_CONCAT(DISTINCT catmap.catid SEPARATOR ',') as catids"; } $sql .= " FROM #__jevents_repetition as rpt "; $sql .= " LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id=rpt.eventdetail_id "; $sql .= " LEFT JOIN #__jevents_vevent as evt ON evt.ev_id=rpt.eventid "; if ($params->get("multicategory", 0)) { $sql .= " LEFT JOIN #__jevents_catmap as catmap ON catmap.evid = rpt.eventid"; $sql .= " LEFT JOIN #__categories AS catmapcat ON catmap.catid = catmapcat.id"; } $sql .= " WHERE rpt.rp_id<>" . intval($repeat->rp_id) . " AND rpt.startrepeat<" . $db->Quote($repeat->endrepeat) . " AND rpt.endrepeat>" . $db->Quote($repeat->startrepeat); $sql .= " AND evt.state=1"; if ($params->get("multicategory", 0)) { $sql .= " AND catmap.catid IN(" . implode(",", $catids) . ") GROUP BY rpt.rp_id"; } else { $sql .= " AND (evt.catid=" . $repeat->event->catid() . ") GROUP BY rpt.rp_id"; } $sql .= " LIMIT 100"; $db->setQuery($sql); $conflicts = $db->loadObjectList(); if ($conflicts && count($conflicts) > 0) { foreach ($conflicts as &$conflict) { $conflictCats = isset($conflict->catids) ? explode(",", $conflict->catids) : array($conflict->catid); $catname = array(); foreach ($conflictCats as $cc) { if (isset($catinfo[$cc])) { $catname[] = $catinfo[$cc]->title; } } $cat = count($catname) > 0 ? implode(", ", $catname) : $testevent->getCategoryName(); $conflict->conflictCause = JText::sprintf("JEV_CATEGORY_CLASH", $cat); } unset($conflict); $overlaps = array_merge($overlaps, $conflicts); } } } } $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onCheckRepeatOverlaps', array(&$repeat, &$overlaps, $eventid, $requestObject)); return $overlaps; }
function notifyAuthorPublished($event) { JLoader::register('JEventsCategory', JEV_ADMINPATH . "/libraries/categoryClass.php"); $db = JFactory::getDBO(); $cat = new JEventsCategory($db); $cat->load($event->catid()); $adminuser = $cat->getAdminUser(); $adminEmail = $adminuser->email; $adminName = $adminuser->name; $config = new JConfig(); $sitename = $config->sitename; $subject = JText::sprintf('JEV_NOTIFY_AUTHOR_SUBJECT', $sitename); $Itemid = JEVHelper::getItemid(); // reload the event to get the reptition ids $evid = intval($event->ev_id()); $dataModel = new JEventsDataModel("JEventsAdminDBModel"); $queryModel = new JEventsDBModel($dataModel); $testevent = $queryModel->getEventById($evid, 1, "icaldb"); // attach anonymous creator etc. JPluginHelper::importPlugin('jevents'); $dispatcher =& JDispatcher::getInstance(); $dispatcher->trigger('onDisplayCustomFields', array(&$event)); $rp_id = $testevent->rp_id(); list($year, $month, $day) = JEVHelper::getYMD(); $uri =& JURI::getInstance(JURI::base()); if (JFactory::getApplication()->isAdmin()) { $root = $uri->toString(array('scheme', 'host', 'port', 'path')); $root = str_replace("/administrator", "", $root); $detaillink = '<a href="' . $root . 'index.php?option=' . JEV_COM_COMPONENT . '&task=icalrepeat.detail&rp_id=' . $evid . '&rp_id=' . $rp_id . '&Itemid=' . $Itemid . "&year={$year}&month={$month}&day={$day}" . '">' . $event->title() . '</a>' . "\n"; } else { $root = $uri->toString(array('scheme', 'host', 'port')); $detaillink = '<a href="' . $root . JRoute::_('index.php?option=' . JEV_COM_COMPONENT . '&task=icalrepeat.detail&rp_id=' . $evid . '&rp_id=' . $rp_id . '&Itemid=' . $Itemid . "&year={$year}&month={$month}&day={$day}") . '">' . $event->title() . '</a>' . "\n"; } $content = sprintf(JText::_('JEV_NOTIFY_AUTHOR_Message'), $detaillink, $sitename); $authorname = ""; $authoremail = ""; if ($event->created_by() > 0) { $author = JFactory::getUser($event->created_by()); if (!$author) { return; } $authorname = $author->name; $authoremail = $author->email; } else { if (isset($event->authoremail) && $event->authoremail != "") { $authorname = $event->authorname; $authoremail = $event->authoremail; } } if ($authoremail == "") { return; } // mail function $mail =& JFactory::getMailer(); $mail->setSender(array(0 => $adminEmail, 1 => $adminName)); $mail->addRecipient($authoremail); $mail->setSubject($subject); $mail->setBody($content); $mail->IsHTML(true); $mail->send(); }
public static function canPublishOwnEvents($evid) { $params = JComponentHelper::getParams(JEV_COM_COMPONENT); $authorisedonly = $params->get("authorisedonly", 1); $publishown = $params->get("jevpublishown", 0); $jevuser = JEVHelper::getAuthorisedUser(); $user = JFactory::getUser(); if (!$authorisedonly && $publishown) { // can publish all? if (JEVHelper::isEventPublisher(true)) { return true; } else { if ($evid == 0) { return true; } } $dataModel = new JEventsDataModel("JEventsAdminDBModel"); $queryModel = new JEventsDBModel($dataModel); $evid = intval($evid); $testevent = $queryModel->getEventById($evid, 1, "icaldb"); if ($testevent->ev_id() == $evid && $testevent->created_by() == $user->id) { return true; } } if ($authorisedonly && $jevuser && $jevuser->canpublishown) { $dataModel = new JEventsDataModel("JEventsAdminDBModel"); $queryModel = new JEventsDBModel($dataModel); $evid = intval($evid); $testevent = $queryModel->getEventById($evid, 1, "icaldb"); if ($testevent->ev_id() == $evid && $testevent->created_by() == $user->id) { return true; } } return false; }
function listEventsByKeyword($keyword, $order, &$limit, &$limitstart, &$total, $useRegX = false) { $user = JFactory::getUser(); $adminuser = JEVHelper::isAdminUser($user); $db = JFactory::getDBO(); $keyword = $db->escape($keyword, true); // Use alternative data source $rows = array(); $skipJEvents = false; $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('fetchListEventsByKeyword', array(&$skipJEvents, &$rows, $keyword, $order, &$limit, &$limitstart, &$total, $useRegX)); if ($skipJEvents) { return $rows; } $rows_per_page = $limit; if (empty($limitstart) || !$limitstart) { $limitstart = 0; } $limitstring = ""; if ($rows_per_page > 0) { $limitstring = "LIMIT {$limitstart}, {$rows_per_page}"; } $where = ""; $having = ""; if (!JRequest::getInt('showpast', 0)) { $datenow = JevDate::getDate("-12 hours"); $having = " AND rpt.endrepeat>'" . $datenow->toSql() . "'"; } $total = 0; // process the new plugins // get extra data and conditionality from plugins $extrawhere = array(); $extrajoin = array(); $extrafields = ""; // must have comma prefix $needsgroup = false; $filterarray = array("published"); // If there are extra filters from the module then apply them now $reg = JFactory::getConfig(); $modparams = $reg->get("jev.modparams", false); if ($modparams && $modparams->get("extrafilters", false)) { $filterarray = array_merge($filterarray, explode(",", $modparams->get("extrafilters", false))); } $filters = jevFilterProcessing::getInstance($filterarray); $filters->setWhereJoin($extrawhere, $extrajoin); $needsgroup = $filters->needsGroupBy(); JPluginHelper::importPlugin('jevents'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onListIcalEvents', array(&$extrafields, &$extratables, &$extrawhere, &$extrajoin, &$needsgroup)); $catwhere = "\n WHERE ev.catid IN(" . $this->accessibleCategoryList() . ")"; $params = JComponentHelper::getParams("com_jevents"); if ($params->get("multicategory", 0)) { $extrajoin[] = "\n #__jevents_catmap as catmap ON catmap.evid = rpt.eventid"; $extrajoin[] = "\n #__categories AS catmapcat ON catmap.catid = catmapcat.id"; $extrafields .= ", GROUP_CONCAT(DISTINCT catmap.catid SEPARATOR ',') as catids"; $extrawhere[] = " catmapcat.access IN (" . JEVHelper::getAid($user) . ")"; $extrawhere[] = " catmap.catid IN(" . $this->accessibleCategoryList() . ")"; $needsgroup = true; $catwhere = "\n WHERE 1 "; } $extrajoin = count($extrajoin) ? " \n LEFT JOIN " . implode(" \n LEFT JOIN ", $extrajoin) : ''; $extrawhere = count($extrawhere) ? ' AND ' . implode(' AND ', $extrawhere) : ''; // NB extrajoin is a string from now on $extrasearchfields = array(); $dispatcher->trigger('onSearchEvents', array(&$extrasearchfields, &$extrajoin, &$needsgroup)); if (count($extrasearchfields) > 0) { $extraor = implode(" OR ", $extrasearchfields); $extraor = " OR " . $extraor; // replace the ### placeholder with the keyword $extraor = str_replace("###", $keyword, $extraor); $searchpart = $useRegX ? "(det.summary RLIKE '{$keyword}' OR det.description RLIKE '{$keyword}' OR det.location RLIKE '{$keyword}' OR det.extra_info RLIKE '{$keyword}' {$extraor})\n" : " (MATCH (det.summary, det.description, det.extra_info) AGAINST ('{$keyword}' IN BOOLEAN MODE) {$extraor})\n"; } else { $searchpart = $useRegX ? "(det.summary RLIKE '{$keyword}' OR det.description RLIKE '{$keyword}' OR det.location RLIKE '{$keyword}' OR det.extra_info RLIKE '{$keyword}')\n" : "MATCH (det.summary, det.description, det.extra_info) AGAINST ('{$keyword}' IN BOOLEAN MODE)\n"; } // Now Search Icals $query = "SELECT count( distinct det.evdet_id) FROM #__jevents_vevent as ev" . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid" . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id" . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id" . $extrajoin . $catwhere . "\n AND icsf.state=1 AND icsf.access IN (" . JEVHelper::getAid($user) . ")" . "\n AND ev.access IN (" . JEVHelper::getAid($user) . ")" . "\n AND "; $query .= $searchpart; $query .= $extrawhere; $query .= $having; $db->setQuery($query); //echo $db->explain(); $total += intval($db->loadResult()); if ($total < $limitstart) { $limitstart = 0; } $rows = array(); if ($total == 0) { return $rows; } // Now Search Icals // New version $query = "SELECT DISTINCT det.evdet_id FROM #__jevents_vevdetail as det" . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventdetail_id = det.evdet_id" . "\n LEFT JOIN #__jevents_vevent as ev ON ev.ev_id = rpt.eventid" . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid" . $extrajoin . $catwhere . "\n AND icsf.state=1 AND icsf.access IN (" . JEVHelper::getAid($user) . ")" . "\n AND ev.access IN (" . JEVHelper::getAid($user) . ")"; $query .= " AND "; $query .= $searchpart; $query .= $extrawhere; $query .= $having; $query .= "\n ORDER BY rpt.startrepeat ASC "; $query .= "\n {$limitstring}"; $db->setQuery($query); if ($adminuser) { //echo $db->_sql; //echo $db->explain(); } //echo $db->explain(); $details = $db->loadColumn(); $icalrows = array(); foreach ($details as $detid) { $query2 = "SELECT ev.*, rpt.*, det.* {$extrafields}" . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup" . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn" . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup" . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn" . "\n FROM #__jevents_vevent as ev" . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id" . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id" . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid" . $extrajoin . "\n WHERE rpt.eventdetail_id = {$detid}" . $extrawhere . $having . "\n ORDER BY rpt.startrepeat ASC limit 1"; $db->setQuery($query2); //echo $db->explain(); $data = $db->loadObject(); // belts and braces - some servers have a MYSQLK bug on the user of DISTINCT! if (!$data->ev_id) { continue; } $icalrows[] = $data; } $num_events = count($icalrows); for ($i = 0; $i < $num_events; $i++) { // convert rows to jevents $icalrows[$i] = new jIcalEventRepeat($icalrows[$i]); } JEventsDBModel::translateEvents($icalrows); JEVHelper::onDisplayCustomFieldsMultiRow($icalrows); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onDisplayCustomFieldsMultiRowUncached', array(&$icalrows)); return $icalrows; }
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; }