PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/iCagenda/admin/models/fields/modal/evt.php

https://gitlab.com/Alzakath/icagenda
PHP | 332 lines | 252 code | 49 blank | 31 comment | 48 complexity | 93feabeae7a7beefc0943061248aedff MD5 | raw file
  1. <?php
  2. /**
  3. *------------------------------------------------------------------------------
  4. * iCagenda v3 by Jooml!C - Events Management Extension for Joomla! 2.5 / 3.x
  5. *------------------------------------------------------------------------------
  6. * @package com_icagenda
  7. * @copyright Copyright (c)2012-2015 Cyril Rezé, Jooml!C - All rights reserved
  8. *
  9. * @license GNU General Public License version 3 or later; see LICENSE.txt
  10. * @author Cyril Rezé (Lyr!C)
  11. * @link http://www.joomlic.com
  12. *
  13. * @version 3.5.9 2015-08-01
  14. * @since 3.3.3
  15. *------------------------------------------------------------------------------
  16. */
  17. // No direct access to this file
  18. defined('_JEXEC') or die();
  19. jimport( 'joomla.filesystem.path' );
  20. jimport('joomla.form.formfield');
  21. class JFormFieldModal_evt extends JFormField
  22. {
  23. protected $type = 'modal_evt';
  24. protected function getInput()
  25. {
  26. $jinput = JFactory::getApplication()->input;
  27. $view = $jinput->get('view');
  28. $id = $jinput->get('id', null);
  29. $eventid = $jinput->get('eventid', $this->value);
  30. $class = isset($this->class) ? ' class="' . $this->class . '"' : '';
  31. $typeReg = $db_date = $db_period = $db_date_is_valid = '';
  32. $db = JFactory::getDbo();
  33. $query = $db->getQuery(true);
  34. $query->select('e.title, e.state, e.id, e.weekdays, e.params')
  35. ->from('`#__icagenda_events` AS e');
  36. if ($view == 'mail')
  37. {
  38. // Join Total of registrations
  39. $query->select('r.count AS registered');
  40. $sub_query = $db->getQuery(true);
  41. $sub_query->select('r.state, r.date AS reg_date, r.period AS reg_period, r.eventid, sum(r.people) AS count');
  42. $sub_query->from('`#__icagenda_registration` AS r');
  43. $sub_query->where('r.state = 1');
  44. $sub_query->where('r.email <> ""');
  45. $sub_query->group('r.eventid');
  46. $query->leftJoin('(' . (string) $sub_query . ') AS r ON (e.id = r.eventid)');
  47. $query->where('r.count > 0');
  48. }
  49. $query->order('e.title ASC');
  50. $db->setQuery($query);
  51. $events = $db->loadObjectList();
  52. if ($eventid != 0 && $view == 'registration')
  53. {
  54. $query = $db->getQuery(true);
  55. $query->select('r.date AS reg_date, r.period AS reg_period')
  56. ->from('`#__icagenda_registration` AS r');
  57. $query->where('r.eventid = ' . (int) $eventid);
  58. $query->where('r.id = ' . (int) $id);
  59. $db->setQuery($query);
  60. $reg = $db->loadObject();
  61. $db_date = $reg->reg_date;
  62. $db_date_is_valid = iCDate::isDate($db_date);
  63. $db_period = $reg->reg_period;
  64. }
  65. // User state used in Newsletter
  66. $data = JFactory::getApplication()->getUserState('com_icagenda.mail.data', array());
  67. $session_eventid = isset($data['eventid']) ? $data['eventid'] : $eventid;
  68. $session_date = isset($data['date']) ? $data['date'] : '';
  69. $html = '<div style="margin-bottom: 10px">';
  70. $html.= '<select id="' . $this->id . '_id"' . $class . ' name="' .
  71. $this->name . '">';
  72. $value = isset($this->value) ? $this->value : '';
  73. $html.= '<option value=""';
  74. if ( ! $id || ! $this->value)
  75. {
  76. $html.= ' selected="selected"';
  77. }
  78. $html.= '>' . JText::_('COM_ICAGENDA_SELECT_EVENT') . '</option>';
  79. foreach ($events as $e)
  80. {
  81. if ($e->state == '1')
  82. {
  83. $html.= '<option value="' . $e->id . '"';
  84. if ($eventid == $e->id)
  85. {
  86. $eventparam = new JRegistry($e->params);
  87. $typeReg = $eventparam->get('typeReg', 1);
  88. $weekdays = $e->weekdays;
  89. $html.= ' selected="selected"';
  90. }
  91. if ($view == 'registration')
  92. {
  93. $html.= '>' . $e->title . ' (id:' . $e->id . ')</option>';
  94. }
  95. else
  96. {
  97. $html.= '>' . $e->title . ' (&#10003;' . $e->registered . ' - id:' . $e->id . ')</option>';
  98. }
  99. }
  100. elseif ($eventid == $e->id)
  101. {
  102. $html.= '<option value="' . $value . '"';
  103. $html.= ' selected="selected"';
  104. $html.= '>' . JText::_('COM_ICAGENDA_REGISTRATION_EVENT_NOT_PUBLISHED') . '</option>';
  105. }
  106. }
  107. $html.= '</select>';
  108. $html.= '</div>';
  109. $id_display = $id ? '&id=' . (int) $id : '';
  110. if ($view == 'registration')
  111. {
  112. // Info message with 'Registration Type' option setting, if the saved date is not in the list of dates for selected event.
  113. if ($typeReg == 1)
  114. {
  115. $reg_type = JText::_('COM_ICAGENDA_REG_BY_INDIVIDUAL_DATE');
  116. }
  117. elseif ($typeReg == 2)
  118. {
  119. $reg_type = JText::_('COM_ICAGENDA_REG_FOR_ALL_DATES');
  120. }
  121. else
  122. {
  123. $reg_type = JText::_('COM_ICAGENDA_REG_BY_DATE_OR_PERIOD');
  124. }
  125. $registration_type = '<strong>' . $reg_type . '</strong>';
  126. $alert_reg_type = '<div class="alert alert-info">';
  127. $alert_reg_type.= '<small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_TYPE_FOR_THIS_EVENT', $registration_type) . '</small>';
  128. $alert_reg_type.= '</div>';
  129. $alert_reg_type = addslashes($alert_reg_type);
  130. // Alert message for a date saved with a version before 3.3.3 (date not formatted as expected in sql format)
  131. $date_no_longer_exists = '<strong>"' . $db_date . '"</strong>';
  132. $alert_date_format = '<div class="ic-alert ic-alert-note"><span class="iCicon-info"></span> <strong>' . JText::_('NOTICE') . '</strong><br />' . JText::sprintf('COM_ICAGENDA_REGISTRATION_ERROR_DATE_CONTROL', $date_no_longer_exists) . '</div>';
  133. $alert_date_format = addslashes($alert_date_format);
  134. // Alert message if a date does not exist anymore for the selected event
  135. $alert_date_no_longer_exists = '<div class="alert alert-error"><strong>' . JText::_('COM_ICAGENDA_FORM_WARNING') . '</strong><br /><small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_DATE_NO_LONGER_EXISTS', $date_no_longer_exists) . '</small></div>';
  136. $alert_date_no_longer_exists = addslashes($alert_date_no_longer_exists);
  137. // Alert message if a date does not exist anymore for the selected event
  138. $alert_full_period_no_longer_exists = '<div class="alert alert-error"><strong>' . JText::_('COM_ICAGENDA_FORM_WARNING') . '</strong><br /><small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_PERIOD_NO_LONGER_EXISTS', $date_no_longer_exists) . '</small></div>';
  139. $alert_full_period_no_longer_exists = addslashes($alert_full_period_no_longer_exists);
  140. // Alert message if a date or period is set for the registration, but event registration type is now 'for all dates of the event'
  141. $for_all_dates = '<strong>' . JText::_('COM_ICAGENDA_ADMIN_REGISTRATION_FOR_ALL_DATES') . '</strong>';
  142. $alert_by_date_no_longer_possible = '<div class="alert alert-error"><strong>' . JText::_('COM_ICAGENDA_FORM_WARNING') . '</strong><br /><small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_BY_DATE_NO_LONGER_POSSIBLE', $for_all_dates, $for_all_dates) . '</small></div>';
  143. $alert_by_date_no_longer_possible = addslashes($alert_by_date_no_longer_possible);
  144. // Alert message if registration for all dates of the event, but event registration type is now 'select list of dates'
  145. $by_date = '<strong>' . JText::_('COM_ICAGENDA_ADMIN_REGISTRATION_BY_INDIVIDUAL_DATE') . '</strong>';
  146. $alert_for_all_dates_no_longer_possible = '<div class="alert alert-error"><strong>' . JText::_('COM_ICAGENDA_FORM_WARNING') . '</strong><br /><small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_FOR_ALL_DATES_NO_LONGER_POSSIBLE', $by_date) . '</small></div>';
  147. $alert_for_all_dates_no_longer_possible = addslashes($alert_for_all_dates_no_longer_possible);
  148. $html.= '<div id="date-alert">';
  149. $html.= '</div>';
  150. if ($typeReg == '1')
  151. {
  152. ?>
  153. <script type="text/javascript">
  154. jQuery(document).ready(function($) {
  155. var value = $('#jform_date_id').val(),
  156. db_date = '<?php echo $db_date; ?>',
  157. db_period = '<?php echo $db_period; ?>',
  158. db_weekdays = '<?php echo $weekdays; ?>',
  159. db_date_is_valid = '<?php echo $db_date_is_valid; ?>',
  160. alert_reg_type = '<?php echo $alert_reg_type; ?>',
  161. alert_date_format = '<?php echo $alert_date_format; ?>',
  162. alert_date_no_longer_exists = '<?php echo $alert_date_no_longer_exists; ?>',
  163. alert_full_period_no_longer_exists = '<?php echo $alert_full_period_no_longer_exists; ?>',
  164. alert_for_all_dates_no_longer_possible = '<?php echo $alert_for_all_dates_no_longer_possible; ?>';
  165. if ( db_date == '' && db_period == '1' ) {
  166. // Registration for all dates, not possible if registration type is per date
  167. $('#date-alert').html(alert_reg_type+alert_for_all_dates_no_longer_possible);
  168. }
  169. else if ( !db_date_is_valid && db_date !== '' ) {
  170. // Date is not empty, but not a valid sql format (registration before release 3.3.3)
  171. $('#date-alert').html(alert_reg_type+alert_date_format);
  172. }
  173. else if ( db_date !== value && db_period !== '0') {
  174. // Date is not empty, but date is not anymore set for this event
  175. $('#date-alert').html(alert_date_no_longer_exists);
  176. }
  177. else if ( db_date == '' && db_period == '0' &&
  178. db_weekdays !== '' && db_weekdays !== '0') {
  179. // Date is not empty, but date is not anymore set for this event
  180. $('#date-alert').html(alert_full_period_no_longer_exists);
  181. }
  182. $('#jform_date_id').change(function(e) {
  183. $('#jform_period').val('0');
  184. $('#date-alert').html('');
  185. });
  186. });
  187. </script>
  188. <?php
  189. }
  190. elseif ($typeReg == '2')
  191. {
  192. ?>
  193. <script type="text/javascript">
  194. jQuery(document).ready(function($) {
  195. var value = $('#jform_date_id').val(),
  196. db_date = '<?php echo $db_date; ?>',
  197. db_period = '<?php echo $db_period; ?>',
  198. alert_reg_type = '<?php echo $alert_reg_type; ?>',
  199. alert_by_date_no_longer_possible = '<?php echo $alert_by_date_no_longer_possible; ?>';
  200. $('#date-alert').html(alert_reg_type);
  201. if ( db_period !== '1' ) {
  202. // Date is empty, not possible if registration type is per date
  203. $('#date-alert').html(alert_reg_type+alert_by_date_no_longer_possible);
  204. }
  205. $('#jform_date_id').change(function(e) {
  206. // if ( value == 'update' ) {
  207. $('#jform_period').val('1');
  208. $('#date-alert').html('');
  209. // }
  210. });
  211. });
  212. </script>
  213. <?php
  214. }
  215. }
  216. ?>
  217. <script type="text/javascript">
  218. jQuery(document).ready(function($) {
  219. var view = '<?php echo $view; ?>',
  220. regid = '<?php echo $id; ?>',
  221. eventid = '<?php echo $session_eventid; ?>',
  222. date = '<?php echo $session_date; ?>',
  223. list_target_id = 'jform_date_id',
  224. list_select_id = '<?php echo $this->id; ?>_id',
  225. initial_target_html = '<option value=""><?php echo JText::_("COM_ICAGENDA_SELECT_NO_EVENT_SELECTED"); ?>...</option>',
  226. loading = '<?php echo JText::_("IC_LOADING"); ?>';
  227. if (eventid) {
  228. $('#'+list_target_id).removeAttr('readonly');
  229. $('#'+list_target_id).val(date);
  230. $.ajax({url: 'index.php?option=com_icagenda&task='+view+'.dates&eventid='+eventid+'&regid='+regid,
  231. success: function(output) {
  232. $('#'+list_target_id).html(output);
  233. },
  234. error: function (xhr, ajaxOptions, thrownError) {
  235. alert(xhr.status + " "+ thrownError);
  236. }
  237. });
  238. $('#'+list_select_id).change(function(e) {
  239. $('#'+list_target_id).removeAttr('readonly');
  240. var selectvalue = $(this).val();
  241. $('#'+list_target_id).html('<option value="">'+loading+'</option>');
  242. if (selectvalue == "") {
  243. $('#'+list_target_id).attr('readonly', 'true');
  244. $('#'+list_target_id).html(initial_target_html);
  245. } else {
  246. $.ajax({url: 'index.php?option=com_icagenda&task='+view+'.dates&eventid='+selectvalue+'&regid='+regid,
  247. success: function(output) {
  248. $('#'+list_target_id).html(output);
  249. },
  250. error: function (xhr, ajaxOptions, thrownError) {
  251. alert(xhr.status + " "+ thrownError);
  252. }
  253. });
  254. }
  255. });
  256. } else {
  257. $('#'+list_target_id).attr('readonly', 'true');
  258. $('#'+list_target_id).html(initial_target_html);
  259. $('#'+list_select_id).change(function(e) {
  260. $('#'+list_target_id).removeAttr('readonly');
  261. var selectvalue = $(this).val();
  262. $('#'+list_target_id).html('<option value="">'+loading+'</option>');
  263. if (selectvalue == "") {
  264. $('#'+list_target_id).attr('readonly', 'true');
  265. $('#'+list_target_id).html(initial_target_html);
  266. } else {
  267. $.ajax({url: 'index.php?option=com_icagenda&task='+view+'.dates&eventid='+selectvalue+'&regid='+regid,
  268. success: function(output) {
  269. $('#'+list_target_id).html(output);
  270. },
  271. error: function (xhr, ajaxOptions, thrownError) {
  272. alert(xhr.status + " "+ thrownError);
  273. }
  274. });
  275. }
  276. });
  277. }
  278. });
  279. </script>
  280. <?php
  281. return $html;
  282. }
  283. }