PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/jeventstemp/site/libraries/dbmodel.php

https://github.com/bhavan/newv1
PHP | 1802 lines | 1297 code | 278 blank | 227 comment | 162 complexity | 7c28775b2adc47c4262dbe77848f6335 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * JEvents Component for Joomla 1.5.x
  4. *
  5. * @version $Id: dbmodel.php 1861 2010-11-05 09:58:44Z geraint $
  6. * @package JEvents
  7. * @copyright Copyright (C) 2008-2009 GWE Systems Ltd, 2006-2008 JEvents Project Group
  8. * @license GNU/GPLv2, see http://www.gnu.org/licenses/gpl-2.0.html
  9. * @link http://www.jevents.net
  10. */
  11. defined( '_JEXEC' ) or die( 'Restricted access' );
  12. // load language constants
  13. JEVHelper::loadLanguage('front');
  14. class JEventsDBModel {
  15. var $cfg = null;
  16. var $datamodel = null;
  17. var $legacyEvents = null;
  18. function JEventsDBModel(&$datamodel){
  19. $this->cfg = & JEVConfig::getInstance();
  20. // TODO - remove legacy code
  21. $this->legacyEvents = 0;
  22. $this->datamodel =& $datamodel;
  23. }
  24. function accessibleCategoryList($aid=null, $catids=null, $catidList=null) {
  25. global $mainframe;
  26. $db =& JFactory::getDBO();
  27. if (is_null($aid)) {
  28. $aid = $this->datamodel->aid;
  29. }
  30. if (is_null($catids)) {
  31. $catids = $this->datamodel->catids;
  32. }
  33. if (is_null($catidList)) {
  34. $catidList = $this->datamodel->catidList;
  35. }
  36. $cfg = & JEVConfig::getInstance();
  37. $sectionname = JEV_COM_COMPONENT;
  38. static $instances;
  39. if (!$instances) {
  40. $instances = array();
  41. }
  42. // calculate unique index identifier
  43. $index = $aid . '+' . $catidList;
  44. // if catidList = 0 then the result is the same as a blank so slight time saving
  45. if (is_null($catidList) || $catidList==0) {
  46. $index = $aid . '+';
  47. }
  48. $where = "";
  49. if (!array_key_exists($index,$instances)) {
  50. if (count($catids)>0 && !is_null($catidList) && $catidList!="0") {
  51. $where = ' AND (c.id IN (' . $catidList .') OR p.id IN (' . $catidList .') OR gp.id IN (' . $catidList .') OR ggp.id IN (' . $catidList .'))';
  52. }
  53. $q_published = $mainframe->isAdmin() ? "\n AND c.published >= 0" : "\n AND c.published = 1";
  54. $query = "SELECT c.id"
  55. . "\n FROM #__categories AS c"
  56. . ' LEFT JOIN #__categories AS p ON p.id=c.parent_id'
  57. . ' LEFT JOIN #__categories AS gp ON gp.id=p.parent_id '
  58. . ' LEFT JOIN #__categories AS ggp ON ggp.id=gp.parent_id '
  59. . "\n WHERE c.access <= $aid"
  60. . $q_published
  61. . "\n AND c.section = '".$sectionname."'"
  62. . "\n " . $where;
  63. ;
  64. $db->setQuery($query);
  65. $catlist = $db->loadResultArray();
  66. $instances[$index] = implode(',', array_merge(array(-1), $catlist));
  67. $dispatcher =& JDispatcher::getInstance();
  68. $dispatcher->trigger('onGetAccessibleCategories', array (& $instances[$index]));
  69. }
  70. return $instances[$index];
  71. }
  72. function getCategoryInfo($catids=null,$aid=null){
  73. global $mainframe;
  74. $db =& JFactory::getDBO();
  75. if (is_null($aid)) {
  76. $aid = $this->datamodel->aid;
  77. }
  78. if (is_null($catids)) {
  79. $catids = $this->datamodel->catids;
  80. }
  81. $catidList = implode(",", $catids);
  82. $cfg = & JEVConfig::getInstance();
  83. $sectionname = JEV_COM_COMPONENT;
  84. static $instances;
  85. if (!$instances) {
  86. $instances = array();
  87. }
  88. // calculate unique index identifier
  89. $index = $aid . '+' . $catidList;
  90. $where = null;
  91. if (!array_key_exists($index,$instances)) {
  92. if (count($catids)>0 && $catidList!="0" && strlen($catidList)!="") {
  93. $where = ' AND c.id IN (' . $catidList .') ';
  94. }
  95. $q_published = $mainframe->isAdmin() ? "\n AND c.published >= 0" : "\n AND c.published = 1";
  96. $query = "SELECT c.*"
  97. . "\n FROM #__categories AS c"
  98. . "\n WHERE c.access <= $aid"
  99. . $q_published
  100. . "\n AND c.section = '".$sectionname."'"
  101. . "\n " . $where;
  102. ;
  103. $db->setQuery($query);
  104. $catlist = $db->loadObjectList('id');
  105. $instances[$index] = $catlist;
  106. }
  107. return $instances[$index];
  108. }
  109. function getChildCategories($catids=null,$levels=1,$aid=null){
  110. global $mainframe;
  111. $db =& JFactory::getDBO();
  112. if (is_null($aid)) {
  113. $aid = $this->datamodel->aid;
  114. }
  115. if (is_null($catids)) {
  116. $catids = $this->datamodel->catids;
  117. }
  118. $catidList = implode(",", $catids);
  119. $cfg = & JEVConfig::getInstance();
  120. $sectionname = JEV_COM_COMPONENT;
  121. static $instances;
  122. if (!$instances) {
  123. $instances = array();
  124. }
  125. // calculate unique index identifier
  126. $index = $aid . '+' . $catidList;
  127. $where = null;
  128. if (!array_key_exists($index,$instances)) {
  129. if (count($catids)>0 && $catidList!="0" && strlen($catidList)!="") {
  130. $where = ' AND (p.id IN (' . $catidList .') '.($levels>1?' OR gp.id IN (' . $catidList .')':'').($levels>2?' OR ggp.id IN (' . $catidList .')':'').')';
  131. }
  132. // TODO check if this should also check abncestry based on $levels
  133. $where .= ' AND p.id IS NOT NULL ';
  134. $q_published = $mainframe->isAdmin() ? "\n AND c.published >= 0" : "\n AND c.published = 1";
  135. $query = "SELECT c.*"
  136. . "\n FROM #__categories AS c"
  137. . ' LEFT JOIN #__categories AS p ON p.id=c.parent_id'
  138. . ($levels>1?' LEFT JOIN #__categories AS gp ON gp.id=p.parent_id ':'')
  139. . ($levels>2?' LEFT JOIN #__categories AS ggp ON ggp.id=gp.parent_id ':'')
  140. . "\n WHERE c.access <= $aid"
  141. . $q_published
  142. . "\n AND c.section = '".$sectionname."'"
  143. . "\n " . $where;
  144. ;
  145. $db->setQuery($query);
  146. $catlist = $db->loadObjectList('id');
  147. $instances[$index] = $catlist;
  148. }
  149. return $instances[$index];
  150. }
  151. function listEvents( $startdate, $enddate, $order=""){
  152. if (!$this->legacyEvents) {
  153. return array();
  154. }
  155. }
  156. function _cachedlistEvents($query, $langtag,$count=false){
  157. $db =& JFactory::getDBO();
  158. $db->setQuery( $query );
  159. if ($count){
  160. $db->query();
  161. return $db->getNumRows();
  162. }
  163. $rows = $db->loadObjectList();
  164. $rowcount = count($rows);
  165. if ($rowcount>0) {
  166. usort( $rows, array('JEventsDBModel','sortEvents') );
  167. }
  168. for( $i = 0; $i < $rowcount; $i++ ){
  169. $rows[$i] = new jEventCal($rows[$i]);
  170. }
  171. return $rows;
  172. }
  173. /**
  174. * Fetch recently created events
  175. */
  176. // Allow the passing of filters directly into this function for use in 3rd party extensions etc.
  177. function recentIcalEvents($startdate,$enddate, $limit=10, $noRepeats=0){
  178. $user =& JFactory::getUser();
  179. $db =& JFactory::getDBO();
  180. $lang =& JFactory::getLanguage();
  181. $langtag = $lang->getTag();
  182. if (strpos($startdate,"-")===false) {
  183. $startdate = strftime('%Y-%m-%d 00:00:00',$startdate);
  184. $enddate = strftime('%Y-%m-%d 23:59:59',$enddate);
  185. }
  186. // process the new plugins
  187. // get extra data and conditionality from plugins
  188. $extrawhere =array();
  189. $extrajoin = array();
  190. $extrafields = ""; // must have comma prefix
  191. $extratables = ""; // must have comma prefix
  192. $needsgroup = false;
  193. $filterarray = array("published","justmine","category","search");
  194. // If there are extra filters from the module then apply them now
  195. $reg =& JFactory::getConfig();
  196. $modparams = $reg->getValue("jev.modparams",false);
  197. if ($modparams && $modparams->getValue("extrafilters",false)){
  198. $filterarray = array_merge($filterarray, explode(",",$modparams->getValue("extrafilters",false)));
  199. }
  200. $filters = jevFilterProcessing::getInstance($filterarray);
  201. $filters->setWhereJoin($extrawhere,$extrajoin );
  202. $needsgroup = $filters->needsGroupBy();
  203. $dispatcher =& JDispatcher::getInstance();
  204. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  205. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  206. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  207. // get the event ids first
  208. $query = "SELECT ev.ev_id FROM #__jevents_repetition as rpt"
  209. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  210. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  211. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  212. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  213. . $extrajoin
  214. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  215. . "\n AND ev.created >= '$startdate' AND ev.created <= '$enddate'"
  216. . $extrawhere
  217. . "\n AND ev.access <= ".$user->aid
  218. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  219. // published state is now handled by filter
  220. . "\n GROUP BY ev.ev_id";
  221. // always in reverse created date order!
  222. $query .= " ORDER BY ev.created DESC ";
  223. // This limit will always be enough
  224. $query .= " LIMIT ".$limit;
  225. $db = JFactory::getDBO();
  226. $db->setQuery($query);
  227. $ids = $db->loadResultArray();
  228. array_push($ids,0);
  229. $ids = implode(",",$ids);
  230. $groupby = "\n GROUP BY rpt.rp_id";
  231. if ($noRepeats) $groupby = "\n GROUP BY ev.ev_id";
  232. // This version picks the details from the details table
  233. // ideally we should check if the event is a repeat but this involves extra queries unfortunately
  234. $query = "SELECT rpt.*, ev.*, rr.*, det.*, ev.state as published, ev.created as created $extrafields"
  235. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  236. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  237. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  238. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  239. . "\n FROM #__jevents_repetition as rpt"
  240. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  241. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  242. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  243. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  244. . $extrajoin
  245. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  246. . "\n AND ev.created >= '$startdate' AND ev.created <= '$enddate'"
  247. . $extrawhere
  248. . "\n AND ev.access <= ".$user->aid
  249. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  250. . " AND ev.ev_id IN (".$ids.")"
  251. // published state is now handled by filter
  252. //. "\n AND ev.state=1"
  253. . ($needsgroup?$groupby:"");
  254. $query .= " ORDER BY ev.created DESC ";
  255. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  256. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag );
  257. $dispatcher =& JDispatcher::getInstance();
  258. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  259. return $rows;
  260. }
  261. /* Special version for Latest events module */
  262. function listLatestIcalEvents($startdate,$enddate, $limit=10, $noRepeats=0){
  263. $user =& JFactory::getUser();
  264. $db =& JFactory::getDBO();
  265. $lang =& JFactory::getLanguage();
  266. $langtag = $lang->getTag();
  267. if (strpos($startdate,"-")===false) {
  268. $startdate = strftime('%Y-%m-%d 00:00:00',$startdate);
  269. $enddate = strftime('%Y-%m-%d 23:59:59',$enddate);
  270. }
  271. // process the new plugins
  272. // get extra data and conditionality from plugins
  273. $extrawhere =array();
  274. $extrajoin = array();
  275. $extrafields = ""; // must have comma prefix
  276. $extratables = ""; // must have comma prefix
  277. $needsgroup = false;
  278. $filterarray = array("published","justmine","category","search");
  279. // If there are extra filters from the module then apply them now
  280. $reg =& JFactory::getConfig();
  281. $modparams = $reg->getValue("jev.modparams",false);
  282. if ($modparams && $modparams->getValue("extrafilters",false)){
  283. $filterarray = array_merge($filterarray, explode(",",$modparams->getValue("extrafilters",false)));
  284. }
  285. $filters = jevFilterProcessing::getInstance($filterarray);
  286. $filters->setWhereJoin($extrawhere,$extrajoin );
  287. $needsgroup = $filters->needsGroupBy();
  288. $dispatcher =& JDispatcher::getInstance();
  289. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  290. // What if join multiplies the rows?
  291. // Useful MySQL link http://forums.mysql.com/read.php?10,228378,228492#msg-228492
  292. // concat with group
  293. // http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/
  294. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  295. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  296. // get the event ids first - split into 2 queries to pick up the ones after now and the ones before
  297. $t_datenow = JEVHelper::getNow();
  298. $t_datenowSQL = $t_datenow->toMysql();
  299. /*
  300. $query = "SELECT ev.ev_id FROM #__jevents_repetition as rpt"
  301. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  302. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  303. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  304. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  305. . $extrajoin
  306. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  307. // New equivalent but simpler test
  308. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  309. // We only show events on their first day if they are not to be shown on multiple days so also add this condition
  310. . "\n AND ((rpt.startrepeat >= '$startdate' AND det.multiday=0) OR det.multiday=1)"
  311. . $extrawhere
  312. . "\n AND ev.access <= ".$user->aid
  313. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  314. // published state is now handled by filter
  315. . "\n GROUP BY ev.ev_id";
  316. // This limit will always be enough
  317. $query .= " LIMIT ".$limit;
  318. */
  319. // Find the ones after now
  320. $query = "SELECT DISTINCT rpt.eventid FROM #__jevents_repetition as rpt"
  321. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  322. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  323. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  324. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  325. . $extrajoin
  326. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  327. // New equivalent but simpler test
  328. . "\n AND rpt.endrepeat >= '$t_datenowSQL' AND rpt.startrepeat <= '$enddate'"
  329. // We only show events on their first day if they are not to be shown on multiple days so also add this condition
  330. . "\n AND ((rpt.startrepeat >= '$t_datenowSQL' AND det.multiday=0) OR det.multiday=1)"
  331. . $extrawhere
  332. . "\n AND ev.access <= ".$user->aid
  333. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  334. // published state is now handled by filter
  335. . "\n AND rpt.startrepeat=(SELECT MIN(startrepeat) FROM #__jevents_repetition as rpt2 WHERE rpt2.eventid=rpt.eventid AND rpt2.startrepeat >= '$t_datenowSQL' AND rpt2.endrepeat <= '$enddate')"
  336. //. "\n GROUP BY rpt.eventid"
  337. . "\n ORDER BY rpt.startrepeat ASC"
  338. ;
  339. // This limit will always be enough
  340. $query .= " LIMIT ".$limit;
  341. $db = JFactory::getDBO();
  342. $db->setQuery($query);
  343. //echo $db->explain();
  344. //echo $db->_sql."<br/>";
  345. $ids1 = $db->loadResultArray();
  346. // Before now
  347. $query = "SELECT rpt.eventid FROM #__jevents_repetition as rpt"
  348. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  349. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  350. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  351. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  352. . $extrajoin
  353. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  354. // New equivalent but simpler test
  355. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$t_datenowSQL'"
  356. // We only show events on their first day if they are not to be shown on multiple days so also add this condition
  357. . "\n AND ((rpt.startrepeat >= '$startdate' AND det.multiday=0) OR det.multiday=1)"
  358. . $extrawhere
  359. . "\n AND ev.access <= ".$user->aid
  360. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  361. // published state is now handled by filter
  362. . "\n AND rpt.startrepeat=(SELECT MAX(startrepeat) FROM #__jevents_repetition as rpt2 WHERE rpt2.eventid=rpt.eventid AND rpt2.startrepeat <= '$t_datenowSQL' AND rpt2.startrepeat >= '$startdate')"
  363. . "\n GROUP BY rpt.eventid "
  364. . "\n ORDER BY rpt.startrepeat DESC"
  365. ;
  366. // This limit will always be enough
  367. $query .= " LIMIT ".$limit;
  368. $db = JFactory::getDBO();
  369. $db->setQuery($query);
  370. //echo $db->explain();die();
  371. //echo $db->_sql; die();
  372. $ids2 = $db->loadResultArray();
  373. $ids = array_merge($ids1, $ids2);
  374. array_push($ids,0);
  375. $ids = array_unique($ids);
  376. // As an alternative to avoid the temporary table we could use php array_unique and array_slice to get the list of ids - with no memory issues.
  377. $ids = implode(",",$ids);
  378. $groupby = "\n GROUP BY rpt.rp_id";
  379. if ($noRepeats) $groupby = "\n GROUP BY ev.ev_id";
  380. // This version picks the details from the details table
  381. // ideally we should check if the event is a repeat but this involves extra queries unfortunately
  382. $query = "SELECT rpt.*, ev.*, rr.*, det.*, ev.state as published, ev.created as created $extrafields"
  383. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  384. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  385. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  386. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  387. . "\n FROM #__jevents_repetition as rpt"
  388. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  389. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  390. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  391. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  392. . $extrajoin
  393. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  394. // New equivalent but simpler test
  395. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  396. . $extrawhere
  397. . "\n AND ev.access <= ".$user->aid
  398. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  399. . " AND ev.ev_id IN (".$ids.")"
  400. // published state is now handled by filter
  401. . ($needsgroup?$groupby:"");
  402. ;
  403. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  404. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag );
  405. $dispatcher =& JDispatcher::getInstance();
  406. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  407. return $rows;
  408. }
  409. // Allow the passing of filters directly into this function for use in 3rd party extensions etc.
  410. function listIcalEvents($startdate,$enddate, $order="", $filters = false, $extrafields="", $extratables="", $limit=""){
  411. $user =& JFactory::getUser();
  412. $db =& JFactory::getDBO();
  413. $lang =& JFactory::getLanguage();
  414. $langtag = $lang->getTag();
  415. if (strpos($startdate,"-")===false) {
  416. $startdate = strftime('%Y-%m-%d 00:00:00',$startdate);
  417. $enddate = strftime('%Y-%m-%d 23:59:59',$enddate);
  418. }
  419. // process the new plugins
  420. // get extra data and conditionality from plugins
  421. $extrawhere =array();
  422. $extrajoin = array();
  423. // $extrafields = ""; // must have comma prefix
  424. // $extratables = ""; // must have comma prefix
  425. $needsgroup = false;
  426. if (!$filters){
  427. $filterarray = array("published","justmine","category","search");
  428. // If there are extra filters from the module then apply them now
  429. $reg =& JFactory::getConfig();
  430. $modparams = $reg->getValue("jev.modparams",false);
  431. if ($modparams && $modparams->getValue("extrafilters",false)){
  432. $filterarray = array_merge($filterarray, explode(",",$modparams->getValue("extrafilters",false)));
  433. }
  434. $filters = jevFilterProcessing::getInstance($filterarray);
  435. $filters->setWhereJoin($extrawhere,$extrajoin );
  436. $needsgroup = $filters->needsGroupBy();
  437. $dispatcher =& JDispatcher::getInstance();
  438. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  439. // What if join multiplies the rows?
  440. // Useful MySQL link http://forums.mysql.com/read.php?10,228378,228492#msg-228492
  441. // concat with group
  442. // http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/
  443. }
  444. else {
  445. $filters->setWhereJoin($extrawhere,$extrajoin);
  446. }
  447. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  448. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  449. // This version picks the details from the details table
  450. // ideally we should check if the event is a repeat but this involves extra queries unfortunately
  451. $query = "SELECT rpt.*, ev.*, rr.*, det.*, ev.state as published, ev.created as created $extrafields"
  452. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  453. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  454. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  455. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  456. . "\n FROM #__jevents_repetition as rpt"
  457. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  458. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  459. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  460. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  461. . $extrajoin
  462. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  463. // New equivalent but simpler test
  464. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  465. /*
  466. . "\n AND ((rpt.startrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate')"
  467. . "\n OR (rpt.endrepeat >= '$startdate' AND rpt.endrepeat <= '$enddate')"
  468. // This is redundant!!
  469. //. "\n OR (rpt.startrepeat >= '$startdate' AND rpt.endrepeat <= '$enddate')"
  470. // This slows the query down
  471. . "\n OR (rpt.startrepeat <= '$startdate' AND rpt.endrepeat >= '$enddate')"
  472. . "\n )"
  473. */
  474. // Radical alternative - seems slower though
  475. /*
  476. . "\n WHERE rpt.rp_id IN (SELECT rbd.rp_id
  477. FROM jos_jevents_repbyday as rbd
  478. WHERE rbd.catid IN(".$this->accessibleCategoryList().")
  479. AND rbd.rptday >= '$startdate' AND rbd.rptday <= '$enddate' )"
  480. */
  481. . $extrawhere
  482. . "\n AND ev.access <= ".$user->aid
  483. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  484. // published state is now handled by filter
  485. //. "\n AND ev.state=1"
  486. . ($needsgroup?"\n GROUP BY rpt.rp_id":"")
  487. ;
  488. if ($order !="") {
  489. $query .= " ORDER BY ".$order;
  490. }
  491. if ($limit !="") {
  492. $query .= " LIMIT ".$limit;
  493. }
  494. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  495. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag );
  496. $dispatcher =& JDispatcher::getInstance();
  497. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  498. return $rows;
  499. }
  500. function _cachedlistIcalEvents($query, $langtag,$count=false){
  501. $db =& JFactory::getDBO();
  502. $db->setQuery( $query );
  503. $user = JFactory::getUser();
  504. if ($user->usertype=="Super Administrator"){
  505. //echo $db->_sql;
  506. //echo $db->explain();
  507. }
  508. //echo $db->_sql;
  509. if ($count){
  510. $db->query();
  511. return $db->getNumRows();
  512. }
  513. $icalrows = $db->loadObjectList();
  514. if ($user->usertype=="Super Administrator"){
  515. echo $db->getErrorMsg();
  516. }
  517. $icalcount = count($icalrows);
  518. $valid = true;
  519. for( $i = 0; $i < $icalcount ; $i++ ){
  520. // only convert rows when necessary
  521. if ($i==0 && count(get_object_vars($icalrows[$i]))<5) {
  522. $valid = false;
  523. break;
  524. }
  525. // convert rows to jIcalEvents
  526. $icalrows[$i] = new jIcalEventRepeat($icalrows[$i]);
  527. }
  528. if (!$valid) return $icalrows;
  529. $dispatcher =& JDispatcher::getInstance();
  530. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRow', array( &$icalrows ));
  531. return $icalrows;
  532. }
  533. function listEventsByDateNEW( $select_date ){
  534. return $this->listEvents($select_date." 00:00:00",$select_date." 23:59:59");
  535. }
  536. function listIcalEventsByDay($targetdate){
  537. // targetdate is midnight at start of day - but just in case
  538. list ($y,$m,$d) = explode(":",strftime( '%Y:%m:%d',$targetdate));
  539. $startdate = mktime( 0, 0, 0, $m, $d, $y );
  540. $enddate = mktime( 23, 59, 59, $m, $d, $y );
  541. return $this->listIcalEvents($startdate,$enddate);
  542. }
  543. function listEventsByWeekNEW( $weekstart, $weekend){
  544. return $this->listEvents($weekstart, $weekend);
  545. }
  546. function listIcalEventsByWeek( $weekstart, $weekend){
  547. return $this->listIcalEvents( $weekstart, $weekend);
  548. }
  549. function listEventsByMonthNew( $year, $month, $order){
  550. $db =& JFactory::getDBO();
  551. $month = str_pad($month, 2, '0', STR_PAD_LEFT);
  552. $select_date = $year.'-'.$month.'-01 00:00:00';
  553. $select_date_fin = $year.'-'.$month.'-'.date('t',mktime(0,0,0,($month+1),0,$year)).' 23:59:59';
  554. return $this->listEvents($select_date,$select_date_fin,$order);
  555. }
  556. function listIcalEventsByMonth( $year, $month){
  557. $startdate = mktime( 0, 0, 0, $month, 1, $year );
  558. $enddate = mktime( 23, 59, 59, $month, date( 't', $startdate), $year );
  559. return $this->listIcalEvents($startdate,$enddate,"");
  560. }
  561. function listEventsByYearNEW( $year, $limitstart=0, $limit=0 ) {
  562. if (!$this->legacyEvents) {
  563. return array();
  564. }
  565. }
  566. // Allow the passing of filters directly into this function for use in 3rd party extensions etc.
  567. function listIcalEventsByYear( $year, $limitstart, $limit, $showrepeats = true, $order="", $filters = false, $extrafields="", $extratables="", $count=false) {
  568. list($xyear,$month,$day) = JEVHelper::getYMD();
  569. $thisyear = new JDate("+0 seconds");
  570. list($thisyear,$thismonth,$thisday) = explode("-",$thisyear->toFormat("%Y-%m-%d"));
  571. if (!$this->cfg->getValue("showyearpast",1) && $year<$thisyear){
  572. return array();
  573. }
  574. $startdate = ($this->cfg->getValue("showyearpast",1) || $year>$thisyear)?mktime( 0, 0, 0, 1, 1, $year ):mktime( 0, 0, 0,$thismonth,$thisday, $thisyear );
  575. $enddate = mktime( 23, 59, 59, 12, 31, $year );
  576. if (!$count){
  577. $order = "rpt.startrepeat asc";
  578. }
  579. $user =& JFactory::getUser();
  580. $db =& JFactory::getDBO();
  581. $lang =& JFactory::getLanguage();
  582. $langtag = $lang->getTag();
  583. if (strpos($startdate,"-")===false) {
  584. $startdate = strftime('%Y-%m-%d 00:00:00',$startdate);
  585. $enddate = strftime('%Y-%m-%d 23:59:59',$enddate);
  586. }
  587. // process the new plugins
  588. // get extra data and conditionality from plugins
  589. $extrawhere =array();
  590. $extrajoin = array();
  591. $extrafields = ""; // must have comma prefix
  592. $extratables = ""; // must have comma prefix
  593. $needsgroup = false;
  594. if (!$filters){
  595. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","search"));
  596. $filters->setWhereJoin($extrawhere,$extrajoin);
  597. $needsgroup = $filters->needsGroupBy();
  598. $dispatcher =& JDispatcher::getInstance();
  599. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  600. }
  601. else {
  602. $filters->setWhereJoin($extrawhere,$extrajoin);
  603. }
  604. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  605. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  606. // This version picks the details from the details table
  607. if ($count){
  608. $query = "SELECT rpt.rp_id";
  609. }
  610. else {
  611. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published $extrafields"
  612. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  613. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  614. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  615. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn";
  616. }
  617. $query .= "\n FROM #__jevents_repetition as rpt"
  618. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  619. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  620. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  621. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  622. . $extrajoin
  623. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  624. // New equivalent but simpler test
  625. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  626. /*
  627. . "\n AND ((rpt.startrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate')"
  628. . "\n OR (rpt.endrepeat >= '$startdate' AND rpt.endrepeat <= '$enddate')"
  629. //. "\n OR (rpt.startrepeat >= '$startdate' AND rpt.endrepeat <= '$enddate')"
  630. . "\n OR (rpt.startrepeat <= '$startdate' AND rpt.endrepeat >= '$enddate'))"
  631. */
  632. . $extrawhere
  633. . "\n AND ev.access <= ".$user->aid
  634. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  635. // published state is not handled by filter
  636. //. "\n AND ev.state=1"
  637. ;
  638. if (!$showrepeats){
  639. $query .="\n GROUP BY ev.ev_id";
  640. }
  641. else if ($needsgroup){
  642. $query .="\n GROUP BY rpt.rp_id";
  643. }
  644. if ($order !="") {
  645. $query .= " ORDER BY ".$order;
  646. }
  647. if ($limit !="" && $limit!=0) {
  648. $query .= " LIMIT ".($limitstart!=""?$limitstart.",":"").$limit;
  649. }
  650. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  651. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag, $count );
  652. $dispatcher =& JDispatcher::getInstance();
  653. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  654. return $rows;
  655. }
  656. // Allow the passing of filters directly into this function for use in 3rd party extensions etc.
  657. function listIcalEventsByRange( $startdate, $enddate, $limitstart, $limit, $showrepeats = true, $order="rpt.startrepeat ASC ", $filters = false, $extrafields="", $extratables="", $count=false) {
  658. list($year, $month, $day) = explode('-', $startdate);
  659. list($thisyear, $thismonth, $thisday) = JEVHelper::getYMD();
  660. //$startdate = $this->cfg->getValue("showyearpast",1)?mktime( 0, 0, 0, intval($month),intval($day),intval($year) ):mktime( 0, 0, 0, $thismonth,$thisday, $thisyear );
  661. $startdate =mktime( 0, 0, 0, intval($month),intval($day),intval($year) );
  662. $startdate = strftime('%Y-%m-%d',$startdate);
  663. if (strlen($startdate)==10) $startdate.= " 00:00:00";
  664. if (strlen($enddate)==10) $enddate.= " 23:59:59";
  665. // This code is used by the iCals code with a spoofed user so check if this is what is happening
  666. if (JRequest::getString("jevtask","")=="icals.export"){
  667. $registry =& JRegistry::getInstance("jevents");
  668. $user = $registry->getValue("jevents.icaluser",false);
  669. if (!$user) $user = JFactory::getUser();
  670. }
  671. else {
  672. $user = JFactory::getUser();
  673. }
  674. $db =& JFactory::getDBO();
  675. $lang =& JFactory::getLanguage();
  676. $langtag = $lang->getTag();
  677. // process the new plugins
  678. // get extra data and conditionality from plugins
  679. $extrawhere =array();
  680. $extrajoin = array();
  681. $extrafields = ""; // must have comma prefix
  682. $extratables = ""; // must have comma prefix
  683. $needsgroup = false;
  684. if (!$filters){
  685. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","search"));
  686. $filters->setWhereJoin($extrawhere,$extrajoin);
  687. $needsgroup = $filters->needsGroupBy();
  688. $dispatcher =& JDispatcher::getInstance();
  689. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  690. }
  691. else {
  692. $filters->setWhereJoin($extrawhere,$extrajoin);
  693. }
  694. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  695. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  696. // This version picks the details from the details table
  697. if ($count){
  698. $query = "SELECT rpt.rp_id";
  699. }
  700. else {
  701. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published $extrafields"
  702. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  703. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  704. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  705. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn";
  706. }
  707. $query .= "\n FROM #__jevents_repetition as rpt"
  708. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  709. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  710. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  711. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  712. . $extrajoin
  713. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  714. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  715. // Must suppress multiday events that have already started
  716. . "\n AND NOT (rpt.startrepeat < '$startdate' AND det.multiday=0) "
  717. . $extrawhere
  718. . "\n AND ev.access <= ".$user->aid
  719. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  720. ;
  721. if (!$showrepeats){
  722. $query .="\n GROUP BY ev.ev_id";
  723. }
  724. else if ($needsgroup){
  725. $query .="\n GROUP BY rpt.rp_id";
  726. }
  727. if ($order !="") {
  728. $query .= " ORDER BY ".$order;
  729. }
  730. if ($limit !="" && $limit!=0) {
  731. $query .= " LIMIT ".($limitstart!=""?$limitstart.",":"").$limit;
  732. }
  733. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  734. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag, $count );
  735. $dispatcher =& JDispatcher::getInstance();
  736. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  737. return $rows;
  738. }
  739. function countIcalEventsByYear( $year,$showrepeats = true) {
  740. $startdate = mktime( 0, 0, 0, 1, 1, $year );
  741. $enddate = mktime( 23, 59, 59, 12, 31, $year );
  742. return $this->listIcalEventsByYear($year,"","",$showrepeats,"",false,"","",true);
  743. }
  744. function countIcalEventsByRange( $startdate, $enddate,$showrepeats = true) {
  745. return $this->listIcalEventsByRange($startdate, $enddate,"","",$showrepeats,"",false,"","",true);
  746. }
  747. function listEventsById( $rpid, $includeUnpublished=0, $jevtype="icaldb" ) {
  748. $user =& JFactory::getUser();
  749. $db =& JFactory::getDBO();
  750. $frontendPublish = JEVHelper::isEventPublisher();
  751. if ($jevtype=="icaldb"){
  752. // process the new plugins
  753. // get extra data and conditionality from plugins
  754. $extrafields = ""; // must have comma prefix
  755. $extratables = ""; // must have comma prefix
  756. $extrawhere =array();
  757. $extrajoin = array();
  758. $dispatcher =& JDispatcher::getInstance();
  759. $dispatcher->trigger('onListEventsById', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin));
  760. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ".implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  761. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  762. $query = "SELECT ev.*, ev.state as published, rpt.*, rr.*, det.* $extrafields, ev.created as created "
  763. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  764. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  765. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  766. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  767. . "\n FROM (#__jevents_vevent as ev $extratables)"
  768. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  769. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  770. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  771. . $extrajoin
  772. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  773. . "\n AND ev.access <= ".$user->aid
  774. . $extrawhere
  775. . "\n AND rpt.rp_id = '$rpid'";
  776. $query .="\n GROUP BY rpt.rp_id";
  777. }
  778. else {
  779. die("invalid jevtype in listEventsById - more changes needed");
  780. }
  781. $db->setQuery( $query );
  782. //echo $db->_sql;
  783. $rows = $db->loadObjectList();
  784. // iCal agid uses GUID or UUID as identifier
  785. if( $rows ){
  786. if (strtolower($jevtype)=="icaldb"){
  787. $row = new jIcalEventRepeat($rows[0]);
  788. }
  789. else if (strtolower($jevtype)=="jevent"){
  790. $row = new jEventCal($rows[0]);
  791. }
  792. }else{
  793. $row=null;
  794. }
  795. return $row;
  796. }
  797. /**
  798. * Get Event by ID (not repeat Id) result is based on first repeat
  799. *
  800. * @param event_id $evid
  801. * @param boolean $includeUnpublished
  802. * @param string $jevtype
  803. * @return jeventcal (or desencent)
  804. */
  805. function getEventById( $evid, $includeUnpublished=0, $jevtype="icaldb" ) {
  806. $user =& JFactory::getUser();
  807. $db =& JFactory::getDBO();
  808. $frontendPublish = JEVHelper::isEventPublisher();
  809. if ($jevtype=="icaldb"){
  810. // process the new plugins
  811. // get extra data and conditionality from plugins
  812. $extrafields = ""; // must have comma prefix
  813. $extratables = ""; // must have comma prefix
  814. $extrawhere =array();
  815. $extrajoin = array();
  816. $dispatcher =& JDispatcher::getInstance();
  817. $dispatcher->trigger('onListEventsById', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin));
  818. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ".implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  819. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  820. // make sure we pick up the event state
  821. $query = "SELECT ev.*, rpt.*, rr.*, det.* $extrafields , ev.state as state "
  822. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  823. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  824. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  825. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  826. . "\n FROM (#__jevents_vevent as ev $extratables)"
  827. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  828. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  829. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  830. . $extrajoin
  831. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  832. . "\n AND ev.access <= ".$user->aid
  833. . $extrawhere
  834. . "\n AND ev.ev_id = '$evid'"
  835. . "\n GROUP BY rpt.rp_id"
  836. . "\n LIMIT 1";
  837. }
  838. else {
  839. die("invalid jevtype in listEventsById - more changes needed");
  840. }
  841. $db->setQuery( $query );
  842. //echo $db->_sql;
  843. $rows = $db->loadObjectList();
  844. // iCal agid uses GUID or UUID as identifier
  845. if( $rows ){
  846. if (strtolower($jevtype)=="icaldb"){
  847. $row = new jIcalEventRepeat($rows[0]);
  848. }
  849. else if (strtolower($jevtype)=="jevent"){
  850. $row = new jEventCal($rows[0]);
  851. }
  852. }else{
  853. $row=null;
  854. }
  855. return $row;
  856. }
  857. function listEventsByCreator( $creator_id, $limitstart, $limit ){
  858. if (!$this->legacyEvents) {
  859. return array();
  860. }
  861. }
  862. function listIcalEventsByCreator ( $creator_id, $limitstart, $limit ){
  863. $user =& JFactory::getUser();
  864. $db =& JFactory::getDBO();
  865. $cfg = & JEVConfig::getInstance();
  866. $rows_per_page = $limit;
  867. if( empty( $limitstart) || !$limitstart ){
  868. $limitstart = 0;
  869. }
  870. $limit = "";
  871. if ($limitstart>0 || $rows_per_page>0){
  872. $limit = "LIMIT $limitstart, $rows_per_page";
  873. }
  874. $frontendPublish = JEVHelper::isEventPublisher();
  875. $adminCats = JEVHelper::categoryAdmin();
  876. $where = '';
  877. if( $creator_id == 'ADMIN' ){
  878. $where = "";
  879. }
  880. else if ( $adminCats && count($adminCats)>0){
  881. //$adminCats = " OR (ev.state=0 AND ev.catid IN(".implode(",",$adminCats)."))";
  882. $adminCats = " OR ev.catid IN(".implode(",",$adminCats).")";
  883. $where = " AND ( ev.created_by = ".$user->id. $adminCats. ")";
  884. }
  885. else {
  886. $where = " AND ev.created_by = '$creator_id' ";
  887. }
  888. // State is manged by plugin
  889. /*
  890. $state = "\n AND ev.state=1";
  891. if ($frontendPublish){
  892. $state = "";
  893. }
  894. */
  895. $extrawhere =array();
  896. $extrajoin = array();
  897. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","startdate","search"));
  898. $filters->setWhereJoin($extrawhere,$extrajoin);
  899. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  900. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  901. $query = "SELECT ev.*, rr.*, det.*, ev.state as published, count(rpt.rp_id) as rptcount"
  902. . "\n , YEAR(dtstart) as yup, MONTH(dtstart ) as mup, DAYOFMONTH(dtstart ) as dup"
  903. . "\n , YEAR(dtend ) as ydn, MONTH(dtend ) as mdn, DAYOFMONTH(dtend ) as ddn"
  904. . "\n , HOUR(dtstart) as hup, MINUTE(dtstart) as minup, SECOND(dtstart ) as sup"
  905. . "\n , HOUR(dtend ) as hdn, MINUTE(dtend ) as mindn, SECOND(dtend ) as sdn"
  906. . "\n FROM #__jevents_vevent as ev"
  907. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  908. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  909. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = ev.detail_id"
  910. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  911. . $extrajoin
  912. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  913. . $extrawhere
  914. . $where
  915. //. "\n AND ev.access <= ".$user->aid
  916. . "\n AND icsf.state=1"
  917. . "\n GROUP BY ev.ev_id"
  918. . "\n ORDER BY dtstart ASC"
  919. . "\n $limit";
  920. $db->setQuery( $query );
  921. //echo $db->explain();
  922. $icalrows = $db->loadObjectList();
  923. echo $db->getErrorMsg();
  924. $icalcount = count($icalrows);
  925. for( $i = 0; $i < $icalcount ; $i++ ){
  926. // convert rows to jIcalEvents
  927. $icalrows[$i] = new jIcalEventDB($icalrows[$i]);
  928. }
  929. return $icalrows;
  930. }
  931. function listIcalEventRepeatsByCreator ( $creator_id, $limitstart, $limit ){
  932. $user =& JFactory::getUser();
  933. $db =& JFactory::getDBO();
  934. $cfg = & JEVConfig::getInstance();
  935. $rows_per_page = $limit;
  936. if( empty( $limitstart) || !$limitstart ){
  937. $limitstart = 0;
  938. }
  939. $limit = "";
  940. if ($limitstart>0 || $rows_per_page>0){
  941. $limit = "LIMIT $limitstart, $rows_per_page";
  942. }
  943. $adminCats = JEVHelper::categoryAdmin();
  944. $where = '';
  945. if( $creator_id == 'ADMIN' ){
  946. $where = "";
  947. }
  948. else if ( $adminCats && count($adminCats)>0){
  949. //$adminCats = " OR (ev.state=0 AND ev.catid IN(".implode(",",$adminCats)."))";
  950. $adminCats = " OR ev.catid IN(".implode(",",$adminCats).")";
  951. $where = " AND ( ev.created_by = ".$user->id. $adminCats. ")";
  952. }
  953. else {
  954. $where = " AND ev.created_by = '$creator_id' ";
  955. }
  956. $frontendPublish = JEVHelper::isEventPublisher();
  957. $extrawhere =array();
  958. $extrajoin = array();
  959. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","startdate","search"));
  960. $filters->setWhereJoin($extrawhere,$extrajoin);
  961. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  962. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  963. if( $frontendPublish ){
  964. // TODO fine a single query way of doing this !!!
  965. $query = "SELECT rp_id"
  966. . "\n FROM #__jevents_repetition as rpt "
  967. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  968. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  969. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  970. . $extrajoin
  971. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  972. . $extrawhere
  973. . $where
  974. . "\n AND icsf.state=1"
  975. //. "\n AND ev.access <= ".$user->aid
  976. . "\n GROUP BY rpt.rp_id"
  977. . "\n ORDER BY rpt.startrepeat"
  978. . "\n $limit";
  979. ;
  980. $db->setQuery( $query );
  981. $rplist = $db->loadResultArray();
  982. //echo $db->explain();
  983. $rplist = implode(',', array_merge(array(-1), $rplist));
  984. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published"
  985. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  986. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  987. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  988. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  989. . "\n FROM #__jevents_vevent as ev "
  990. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  991. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  992. . "\n AND rpt.eventid = ev.ev_id"
  993. . "\n AND rpt.rp_id IN($rplist)"
  994. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  995. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  996. . $extrajoin
  997. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  998. . $extrawhere
  999. . $where
  1000. . "\n AND icsf.state=1"
  1001. //. "\n AND ev.access <= ".$user->aid
  1002. . "\n GROUP BY rpt.rp_id"
  1003. . "\n ORDER BY rpt.startrepeat"
  1004. ;
  1005. }
  1006. else {
  1007. // TODO fine a single query way of doing this !!!
  1008. $query = "SELECT rp_id"
  1009. . "\n FROM #__jevents_vevent as ev "
  1010. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1011. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  1012. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  1013. . $extrajoin
  1014. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  1015. . $extrawhere
  1016. . "\n AND icsf.state=1"
  1017. . $where
  1018. //. "\n AND ev.access <= ".$user->aid
  1019. . "\n GROUP BY rpt.rp_id"
  1020. . "\n ORDER BY rpt.startrepeat"
  1021. . "\n $limit";
  1022. ;
  1023. $db->setQuery( $query );
  1024. $rplist = $db->loadResultArray();
  1025. $rplist = implode(',', array_merge(array(-1), $rplist));
  1026. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published"
  1027. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  1028. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  1029. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  1030. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  1031. . "\n FROM #__jevents_vevent as ev "
  1032. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1033. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  1034. . "\n AND rpt.rp_id IN($rplist)"
  1035. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  1036. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  1037. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  1038. . $where
  1039. //. "\n AND ev.access <= ".$user->aid
  1040. . "\n AND icsf.state=1"
  1041. . "\n GROUP BY rpt.rp_id"
  1042. . "\n ORDER BY rpt.startrepeat"
  1043. ;
  1044. }
  1045. $db->setQuery( $query );
  1046. $icalrows = $db->loadObjectList();
  1047. $icalcount = count($icalrows);
  1048. for( $i = 0; $i < $icalcount ; $i++ ){
  1049. // convert rows to jIcalEvents
  1050. $icalrows[$i] = new jIcalEventRepeat($icalrows[$i]);
  1051. }
  1052. return $icalrows;
  1053. }
  1054. function countEventsByCreator($creator_id){
  1055. if (!$this->legacyEvents) {
  1056. return 0;
  1057. }
  1058. }
  1059. function countIcalEventsByCreator($creator_id){
  1060. $user =& JFactory::getUser();
  1061. $db =& JFactory::getDBO();
  1062. $adminCats = JEVHelper::categoryAdmin();
  1063. $where = '';
  1064. if( $creator_id == 'ADMIN' ){
  1065. $where = "";
  1066. }
  1067. else if ( $adminCats && count($adminCats)>0){
  1068. //$adminCats = " OR (ev.state=0 AND ev.catid IN(".implode(",",$adminCats)."))";
  1069. $adminCats = " OR ev.catid IN(".implode(",",$adminCats).")";
  1070. $where = " AND ( ev.created_by = ".$user->id. $adminCats. ")";
  1071. }
  1072. else {
  1073. $where = " AND ev.created_by = '$creator_id' ";
  1074. }
  1075. // State is managed by plugin
  1076. /*
  1077. $frontendPublish = JEVHelper::isEventPublisher();
  1078. $state = "\n AND ev.state=1";
  1079. if ($frontendPublish){
  1080. $state = "";
  1081. }
  1082. */
  1083. $extrawhere =array();
  1084. $extrajoin = array();
  1085. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","startdate","search"));
  1086. $filters->setWhereJoin($extrawhere,$extrajoin);
  1087. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  1088. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  1089. $query = "SELECT MIN(rpt.rp_id) as rp_id"
  1090. . "\n FROM #__jevents_vevent as ev "
  1091. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1092. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  1093. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  1094. . $extrajoin
  1095. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  1096. . $extrawhere
  1097. . $where
  1098. . "\n AND icsf.state=1"
  1099. . "\n GROUP BY ev.ev_id";
  1100. $db->setQuery( $query );
  1101. $db->query();
  1102. return $db->getNumRows();
  1103. }
  1104. function countIcalEventRepeatsByCreator($creator_id){
  1105. $user =& JFactory::getUser();
  1106. $db =& JFactory::getDBO();
  1107. $adminCats = JEVHelper::categoryAdmin();
  1108. $where = '';
  1109. if( $creator_id == 'ADMIN' ){
  1110. $where = "";
  1111. }
  1112. else if ( $adminCats && count($adminCats)>0){
  1113. //$adminCats = " OR (ev.state=0 AND ev.catid IN(".implode(",",$adminCats)."))";
  1114. $adminCats = " OR ev.catid IN(".implode(",",$adminCats).")";
  1115. $where = " AND ( ev.created_by = ".$user->id. $adminCats. ")";
  1116. }
  1117. else {
  1118. $where = " AND ev.created_by = '$creator_id' ";
  1119. }
  1120. // State is managed by plugin
  1121. $extrawhere =array();
  1122. $extrajoin = array();
  1123. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","startdate","search"));
  1124. $filters->setWhereJoin($extrawhere,$extrajoin);
  1125. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  1126. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  1127. $query = "SELECT rpt.rp_id, ev.catid"
  1128. . "\n FROM #__jevents_repetition as rpt "
  1129. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  1130. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1131. . "\n LEFT JOIN #__jevents_rrule as r…

Large files files are truncated, but you can click here to view the full file