BxEventsModule.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Events Events
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Groups profiles module.
  13. */
  14. class BxEventsModule extends BxBaseModGroupsModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. }
  20. public function actionCalendarData()
  21. {
  22. // check permissions
  23. $iContentId = (int)bx_get('event');
  24. if ($iContentId) {
  25. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  26. if (CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedView($aContentInfo)) {
  27. $this->_oTemplate->displayAccessDenied();
  28. exit;
  29. }
  30. $aSQLPart = array();
  31. }
  32. else {
  33. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  34. $aSQLPart = $oPrivacy ? $oPrivacy->getContentPublicAsSQLPart(0, $oPrivacy->getPartiallyVisiblePrivacyGroups()) : array();
  35. }
  36. // get entries
  37. $aEntries = $this->_oDb->getEntriesByDate(bx_get('start'), bx_get('end'), bx_get('event'), $aSQLPart);
  38. header('Content-Type: application/json; charset=utf-8');
  39. echo json_encode($aEntries);
  40. }
  41. public function serviceCalendar($aData = array(), $sTemplate = 'calendar.html')
  42. {
  43. if (isset($aData['event'])) {
  44. $aContentInfo = $this->_oDb->getContentInfoById ((int)$aData['event']);
  45. if ('' == $aContentInfo['repeat_stop']) // don't display calendar for non repeating events
  46. return '';
  47. }
  48. $o = new BxTemplCalendar(array(
  49. 'eventSources' => array (
  50. 'url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'calendar_data',
  51. 'data' => $aData,
  52. ),
  53. ), $this->_oTemplate);
  54. return $o->display($sTemplate);
  55. }
  56. public function actionIntervals()
  57. {
  58. $sAction = bx_get('a');
  59. $sMethodName = 'subaction' . ucfirst($sAction);
  60. if (!method_exists($this, $sMethodName)) {
  61. $this->_oTemplate->pageNotFound();
  62. return;
  63. }
  64. $this->$sMethodName();
  65. }
  66. public function subactionRestore($iContentId = 0)
  67. {
  68. if (!$iContentId)
  69. $iContentId = (int)bx_get('c');
  70. if (!($aContentInfo = $this->_oDb->getContentInfoById($iContentId))) {
  71. $this->_oTemplate->displayPageNotFound();
  72. exit;
  73. }
  74. if (CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedEdit ($aContentInfo)) {
  75. $this->_oTemplate->displayAccessDenied();
  76. exit;
  77. }
  78. $a = $this->_oDb->getIntervals($iContentId);
  79. foreach ($a as $iIntervalId => $r) {
  80. $a[$iIntervalId]['file_id'] = $r['interval_id'];
  81. $a[$iIntervalId]['repeat_stop'] = bx_process_output ($r['repeat_stop'], BX_DATA_DATE_TS);
  82. }
  83. if ('json' == bx_get('f')) {
  84. header('Content-type: text/html; charset=utf-8');
  85. echo json_encode($a);
  86. }
  87. }
  88. public function subactionDelete()
  89. {
  90. header('Content-type: text/html; charset=utf-8');
  91. $iIntervalId = (int)bx_get('id');
  92. if (!($aContentInfo = $this->_oDb->getContentInfoByIntervalId($iIntervalId))) {
  93. echo _t('_sys_request_page_not_found_cpt');
  94. }
  95. elseif (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedEdit ($aContentInfo))) {
  96. echo $sMsg;
  97. }
  98. elseif (!$this->_oDb->deleteIntervalById($iIntervalId)) {
  99. echo _t('_sys_txt_error_occured');
  100. }
  101. else {
  102. echo 'ok';
  103. }
  104. }
  105. }
  106. /** @} */