Esempio n. 1
0
 /**
  * @param $default
  * @param $v
  *
  * @return string filter
  */
 protected function rangeFilter($default, $v)
 {
     $params = $this->getParams();
     $format = $params->get('date_table_format', 'Y-m-d');
     if (empty($default)) {
         $default = array('', '');
     } else {
         $d = new FabDate($default[0]);
         $default[0] = $d->format($format);
         $d = new FabDate($default[1]);
         $default[1] = $d->format($format);
     }
     // Add wrapper div for list filter toggling
     $return[] = '<div class="fabrik_filter_container">';
     $layout = $this->getLayout('list-filter-range');
     $displayData = new stdClass();
     $displayData->htmlId = $this->getHTMLId();
     $displayData->class = $this->filterClass();
     $displayData->j3 = FabrikWorker::j3();
     $from = new stdClass();
     $from->id = $this->getFilterHtmlId(0);
     $from->value = $default[0];
     $from->name = $v . '[0]';
     $imageOpts = $displayData->j3 ? array('alt' => 'calendar') : array('alt' => 'calendar', 'class' => 'calendarbutton', 'id' => $from->id . '_cal_img');
     $from->img = FabrikHelperHTML::image('calendar.png', 'form', @$this->tmpl, $imageOpts);
     $displayData->from = $from;
     $displayData->format = $format;
     $displayData->calOpts = $this->filterCalendarOpts();
     $to = new stdClass();
     $to->id = $this->getFilterHtmlId(1);
     $to->value = $default[1];
     $to->name = $v . '[1]';
     $imageOpts = $displayData->j3 ? array('alt' => 'calendar') : array('alt' => 'calendar', 'class' => 'calendarbutton', 'id' => $to->id . '_cal_img');
     $to->img = FabrikHelperHTML::image('calendar.png', 'form', @$this->tmpl, $imageOpts);
     $displayData->to = $to;
     $displayData->filterType = $this->getFilterType();
     return $layout->render($displayData);
 }
Esempio n. 2
0
 /**
  * Get the list filter for the element
  * Note: uses FabDate as if date element first to be found in advanced search, and advanced search run on another element
  * the list model in getAdvancedSearchElementList() builds the first filter (this element) with the data from the first search
  * which was throwing '"500 - DateTime::__construct() ' errors
  *
  * see: http://fabrikar.com/forums/showthread.php?t=28231
  *
  * @param   int   $counter  Filter order
  * @param   bool  $normal   Do we render as a normal filter or as an advanced search filter
  * if normal include the hidden fields as well (default true, use false for advanced filter rendering)
  *
  * @return  string	filter html
  */
 public function getFilter($counter = 0, $normal = true)
 {
     $params = $this->getParams();
     $listModel = $this->getListModel();
     $table = $listModel->getTable();
     $element = $this->getElement();
     $origTable = $table->db_table_name;
     $fabrikDb = $listModel->getDb();
     $elName = $this->getFullName(true, false);
     $elName2 = $this->getFullName(false, false);
     $v = $this->filterName($counter, $normal);
     $class = $this->filterClass();
     // Correct default got
     $default = $this->getDefaultFilterVal($normal, $counter);
     $format = $params->get('date_table_format', 'Y-m-d');
     $fromTable = $origTable;
     // $$$ hugh - in advanced search, _aJoins wasn't getting set
     $joins = $listModel->getJoins();
     foreach ($joins as $aJoin) {
         // Not sure why the group id key wasn't found - but put here to remove error
         if (array_key_exists('group_id', $aJoin)) {
             if ($aJoin->group_id == $element->group_id && $aJoin->element_id == 0) {
                 $fromTable = $aJoin->table_join;
                 $elName = str_replace($origTable . '.', $fromTable . '.', $elName);
             }
         }
     }
     $where = $listModel->buildQueryPrefilterWhere($this);
     $elName = FabrikString::safeColName($elName);
     $requestName = $elName . '___filter';
     if (array_key_exists($elName, $_REQUEST)) {
         if (is_array($_REQUEST[$elName]) && array_key_exists('value', $_REQUEST[$elName])) {
             $_REQUEST[$requestName] = $_REQUEST[$elName]['value'];
         }
     }
     $htmlid = $this->getHTMLId();
     $fType = $this->getFilterType();
     $timeZone = new DateTimeZone(JFactory::getConfig()->get('offset'));
     if (in_array($fType, array('dropdown', 'checkbox', 'multiselect'))) {
         $rows = $this->filterValueList($normal);
     }
     $calOpts = $this->filterCalendarOpts();
     $return = array();
     switch ($fType) {
         case 'checkbox':
             $return[] = $this->checkboxFilter($rows, $default, $v);
             break;
         case 'range':
         case 'range-hidden':
             FabrikHelperHTML::loadcalendar();
             if (empty($default)) {
                 $default = array('', '');
             } else {
                 $d = new FabDate($default[0]);
                 $default[0] = $d->format($format);
                 $d = new FabDate($default[1]);
                 $default[1] = $d->format($format);
             }
             // Add wrapper div for list filter toggling
             $return[] = '<div class="fabrik_filter_container">';
             if ($fType === 'range-hidden') {
                 $return[] = '<input type="hidden" name="' . $v . '[0]' . '" class="' . $class . '" value="' . $default[0] . '" id="' . $htmlid . '-0" />';
                 $return[] = '<input type="hidden" name="' . $v . '[1]' . '" class="' . $class . '" value="' . $default[1] . '" id="' . $htmlid . '-1" />';
                 $return[] = '</div>';
             } else {
                 $return[] = JText::_('COM_FABRIK_DATE_RANGE_BETWEEN') . $this->calendar($default[0], $v . '[0]', $this->getFilterHtmlId(0), $format, $calOpts);
                 $return[] = '<br />' . JText::_('COM_FABRIK_DATE_RANGE_AND') . $this->calendar($default[1], $v . '[1]', $this->getFilterHtmlId(1), $format, $calOpts);
                 $return[] = '</div>';
             }
             break;
         case 'dropdown':
         case 'multiselect':
             /**
              *  cant do the format in the MySQL query as its not the same formatting
              *  e.g. M in MySQL is month and J's date code its minute
              */
             $max = count($rows) < 7 ? count($rows) : 7;
             $size = $element->filter_type === 'multiselect' ? 'multiple="multiple" size="' . $max . '"' : 'size="1"';
             $v = $fType === 'multiselect' ? $v . '[]' : $v;
             jimport('joomla.utilities.date');
             $ddData = array();
             foreach ($rows as $k => $o) {
                 if ($fabrikDb->getNullDate() === $o->text) {
                     $o->text = '';
                     $o->value = '';
                 } else {
                     $d = new FabDate($o->text);
                     $d->setTimeZone($timeZone);
                     $o->value = $d->toSql(true);
                     $o->text = $d->format($format, true);
                 }
                 if (!array_key_exists($o->value, $ddData)) {
                     $ddData[$o->value] = $o;
                 }
             }
             array_unshift($ddData, JHTML::_('select.option', '', $this->filterSelectLabel()));
             $return[] = JHTML::_('select.genericlist', $ddData, $v, 'class="' . $class . '" ' . $size . ' maxlength="19"', 'value', 'text', $default, $htmlid . '0');
             break;
         default:
         case 'field':
             FabrikHelperHTML::loadcalendar();
             if (is_array($default)) {
                 $default = array_shift($default);
             }
             if ($default !== '') {
                 $d = new FabDate($default);
                 $default = $d->format($format);
             }
             // Add wrapper div for list filter toggling
             $return[] = '<div class="fabrik_filter_container">';
             $return[] = $this->calendar($default, $v, $this->getFilterHtmlId(0), $format, $calOpts);
             $return[] = '</div>';
             break;
         case 'hidden':
             if (is_array($default)) {
                 $default = array_shift($default);
             }
             if (get_magic_quotes_gpc()) {
                 $default = stripslashes($default);
             }
             $default = htmlspecialchars($default);
             // Don't add id as caused issues with inline edit plugin and clashing ids.
             $return[] = '<input type="hidden" name="' . $v . '" class="' . $class . '" value="' . $default . '" />';
             break;
         case 'auto-complete':
             if (get_magic_quotes_gpc()) {
                 $default = stripslashes($default);
             }
             $default = htmlspecialchars($default);
             $return[] = '<input type="hidden" name="' . $v . '" class="' . $class . '" value="' . $default . '" id="' . $htmlid . '" />';
             $return[] = '<input type="text" name="' . $v . '-auto-complete" class="' . $class . ' autocomplete-trigger" value="' . $default . '" id="' . $htmlid . '-auto-complete" />';
             $autoId = '#' . $htmlid . '-auto-complete';
             if (!$normal) {
                 $autoId = '.advanced-search-list .autocomplete-trigger';
             }
             FabrikHelperHTML::autoComplete($autoId, $this->getElement()->id, $this->getFormModel()->getId(), 'date');
             break;
     }
     if ($normal) {
         $return[] = $this->getFilterHiddenFields($counter, $elName);
     } else {
         $return[] = $this->getAdvancedFilterHiddenFields();
     }
     return implode("\n", $return);
 }