PageRenderTime 23ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/Alzakath/icagenda
PHP | 166 lines | 95 code | 26 blank | 45 comment | 12 complexity | 39d909d12132b343f2ee3e85a25d17ac 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.10 2015-08-13
  14. * @since 1.0
  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. /**
  22. * Supports unlimited modal datetime picker (add / delete).
  23. *
  24. * @package iCagenda
  25. * @subpackage com_icagenda
  26. * @since 1.0
  27. */
  28. class JFormFieldModal_date extends JFormField
  29. {
  30. protected $type = 'modal_date';
  31. protected function getInput()
  32. {
  33. $lang = JFactory::getLanguage();
  34. $id_suffix = ($lang->getTag() == 'fa-IR') ? '_jalali' : '';
  35. if ($lang->getTag() == 'fa-IR')
  36. {
  37. // Including fallback code for HTML5 non supported browsers.
  38. JHtml::_('jquery.framework');
  39. JHtml::_('script', 'system/html5fallback.js', false, true);
  40. }
  41. $id = JRequest::getInt('id');
  42. $class = !empty($this->class) ? ' ' . $this->class : '';
  43. $session = JFactory::getSession();
  44. $datesDB = $session->get('ic_submit_dates', '');
  45. if ($id && empty($datesDB))
  46. {
  47. $db = JFactory::getDBO();
  48. $db->setQuery(
  49. 'SELECT a.dates' .
  50. ' FROM #__icagenda_events AS a' .
  51. ' WHERE a.id = '.(int) $id
  52. );
  53. $datesDB = $db->loadResult();
  54. }
  55. $dates = iCString::isSerialized($datesDB) ? unserialize($datesDB) : false;
  56. // if ($lang->getTag() == 'fa-IR'
  57. // && $dates
  58. // && $dates != array('0000-00-00 00:00'))
  59. // {
  60. // $dates_to_sql = array();
  61. // foreach ($dates AS $date)
  62. // {
  63. // if (iCDate::isDate($date))
  64. // {
  65. // $year = date('Y', strtotime($date));
  66. // $month = date('m', strtotime($date));
  67. // $day = date('d', strtotime($date));
  68. // $time = date('H:i', strtotime($date));
  69. // $dates_to_sql[] = iCGlobalizeConvert::gregorianToJalali($year, $month, $day, true) . ' ' . $time;
  70. // }
  71. // }
  72. // $dates = $dates_to_sql;
  73. // }
  74. $html = '<table id="dTable' . $id_suffix . '" style="border:0px">';
  75. $html.= '<thead>';
  76. $html.= '<tr>';
  77. $html.= '<th width="70%">';
  78. $html.= JText::_('COM_ICAGENDA_TB_DATE');
  79. $html.= '</th>';
  80. $html.= '<th width="30%">';
  81. // $html.= JText::_('COM_ICAGENDA_TB_ACT');
  82. $html.= '</th>';
  83. $html.= '</tr>';
  84. $html.= '</thead>';
  85. $add_counter = 0;
  86. if ($dates
  87. && $dates != array('0000-00-00 00:00'))
  88. {
  89. foreach ($dates as $date)
  90. {
  91. $html.= '<tr>';
  92. $html.= '<td>';
  93. if ($lang->getTag() == 'fa-IR')
  94. {
  95. $add_counter = $add_counter+1;
  96. // $this_number = $add_counter ? $add_counter : '';
  97. $html.= JHtml::_('calendar', $date, 'd', 'date_jalali' . $add_counter, '%Y-%m-%d %H:%M', ' class="ic-date-input' . $id_suffix . '"');
  98. }
  99. else
  100. {
  101. $html.= '<input class="ic-date-input' . $id_suffix . '" type="text" name="d" value="' . $date . '" />';
  102. }
  103. $html.= '</td>';
  104. $html.= '<td>';
  105. $html.= '<a class="del btn btn-danger btn-mini" href="#">' . JText::_('COM_ICAGENDA_DELETE_DATE') . '</a>';
  106. $html.= '</td>';
  107. $html.= '</tr>';
  108. }
  109. // clear the data so we don't process it again
  110. $session->clear('ic_submit_dates');
  111. }
  112. else
  113. {
  114. $html.= '<tr>';
  115. $html.= '<td>';
  116. if ($lang->getTag() == 'fa-IR')
  117. {
  118. $html.= JHtml::_('calendar', '0000-00-00 00:00', 'd', 'date_jalali', '%Y-%m-%d %H:%M', ' class="ic-date-input' . $id_suffix . '"');
  119. }
  120. else
  121. {
  122. $html.= '<input class="ic-date-input' . $id_suffix . '" type="text" name="d" value="0000-00-00 00:00" />';
  123. }
  124. $html.= '</td>';
  125. $html.= '<td>';
  126. $html.= '<a class="del btn btn-danger btn-mini" href="#">' . JText::_('COM_ICAGENDA_DELETE_DATE') . '</a>';
  127. $html.= '</td>';
  128. $html.= '</tr>';
  129. }
  130. $html.= '</table>';
  131. $html.= '<a id="add" href="#"><span class="btn btn-success btn-small input-medium" style="float:left"><strong>' . JText::_('COM_ICAGENDA_ADD_DATE') . '</strong></span></a><br/>';
  132. $html.= '<input type="hidden"';
  133. $html.= ' class="date' . $class . '"';
  134. $html.= ' id="' . $this->id . '_id"';
  135. $html.= ' name="' . $this->name . '"';
  136. $html.= ' value=\''.$datesDB.'\'';
  137. $html.= '/>';
  138. return $html;
  139. }
  140. }