/**
 * Function for embedding a date control in html.
 *
 * @author Peter C. Verhage <*****@*****.**>
 */
function smarty_function_atkdatefield($params, $smarty)
{
    $name = isset($params['name']) ? $params['name'] : 'date';
    $format = isset($params['format']) ? $params['format'] : Tools::atktext('date_format_edit', 'atk', '', '', '', true);
    $mandatory = isset($params['mandatory']) && $params['mandatory'] || isset($params['obligatory']) && $params['obligatory'];
    $noweekday = isset($params['noweekday']) && $params['noweekday'];
    $calendar = isset($params['calendar']) && $params['calendar'];
    $time = isset($params['time']) ? $params['time'] : ($mandatory ? mktime() : null);
    $min = isset($params['min']) ? $params['min'] : 0;
    $max = isset($params['max']) ? $params['max'] : 0;
    if (is_array($time)) {
        $date = $time;
    } else {
        if ($time == null) {
            $date = null;
        } else {
            if (is_numeric($time)) {
                $date = getdate($time);
                $date = array('day' => $date['mday'], 'month' => $date['mon'], 'year' => $date['year']);
            } else {
                if (preg_match('/([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})/', $time, $matches)) {
                    $date = array('day' => (int) $matches[1], 'month' => (int) $matches[2], 'year' => $matches[3]);
                } else {
                    $date = getdate(strtotime($time));
                    $date = array('day' => $date['mday'], 'month' => $date['mon'], 'year' => $date['year']);
                }
            }
        }
    }
    $attr = new DateAttribute($name, $format, '', $min, $max, ($noweekday ? DateAttribute::AF_DATE_EDIT_NO_DAY : 0) | ($mandatory ? Attribute::AF_OBLIGATORY : 0) | ($calendar ? 0 : DateAttribute::AF_DATE_NO_CALENDAR));
    $html = $attr->edit(array($name => $date), '', '');
    return $html;
}
 /**
  * This method returns an html page that can be used as a search form.
  *
  * @param string $name
  * @param array $criteria
  *
  * @return string The html search page.
  */
 public function smartSearchPage($name = '', $criteria = array())
 {
     $node = $this->m_node;
     $page = $this->getPage();
     $ui = $this->getUi();
     $sm = SessionManager::getInstance();
     $page->register_script(Config::getGlobal('assets_url') . 'javascript/tools.js');
     $page->register_script(Config::getGlobal('assets_url') . 'javascript/class.atksmartsearchhandler.js');
     Tools::useattrib('atkdateattribute');
     DateAttribute::registerScriptsAndStyles();
     $params = [];
     $params['formstart'] = '<form name="entryform" action="' . Config::getGlobal('dispatcher') . '" method="post" class="form">' . $sm->formState(SessionManager::SESSION_REPLACE) . '<input type="hidden" name="atkaction" value="smartsearch">' . '<input type="hidden" name="atknodeuri" value="' . $node->atkNodeUri() . '">';
     $params['content'] = $this->invoke('smartSearchForm', $name, $criteria);
     $params['buttons'][] = '<input type="submit" class="btn btn-default btn_search" name="atkdosearch" value="' . Tools::atktext('search', 'atk') . '">';
     $params['formend'] = '</form>';
     $action = $ui->renderAction('smartsearch', $params);
     $box = $ui->renderBox(array('title' => $node->actionTitle('smartsearch'), 'content' => $action));
     return $box;
 }
 public function getSearchCondition(Query $query, $table, $value, $searchmode, $fieldname = '')
 {
     // If we are accidentally mistaken for a relation and passed an array
     // we only take our own attribute value from the array
     if ($this->m_searchmode) {
         $searchmode = $this->m_searchmode;
     }
     $expression = '(' . str_replace('[table]', $table, $this->m_expression) . ')';
     if ($this->getSearchType() == 'date') {
         $attr = new DateAttribute($this->fieldName());
         return $attr->getSearchCondition($query, $table, $value, $searchmode, $expression);
     }
     if ($this->getSearchType() == 'number') {
         $attr = new NumberAttribute($this->fieldName());
         $value = $attr->processSearchValue($value, $searchmode);
         if ($searchmode == 'between') {
             return $attr->getBetweenCondition($query, $expression, $value);
         }
         if (isset($value['from']) && $value['from'] != '') {
             $value = $value['from'];
         } else {
             if (isset($value['to']) && $value['to'] != '') {
                 $value = $value['to'];
             } else {
                 return '';
             }
         }
     }
     $func = $searchmode . 'Condition';
     if (method_exists($query, $func) && $value !== '' && $value !== null) {
         return $query->{$func}($expression, $this->escapeSQL($value));
     }
     return '';
 }
Exemple #4
0
 /**
  * Parse the string to convert a datetime string to an array.
  *
  * @param string $stringvalue
  *
  * @return array with date and time information
  */
 public function parseStringValue($stringvalue)
 {
     $datetime = explode(' ', $stringvalue);
     $formatsdate = array('dd-mm-yyyy', 'dd-mm-yy', 'd-mm-yyyy', 'dd-m-yyyy', 'd-m-yyyy', 'yyyy-mm-dd', 'yyyy-mm-d', 'yyyy-m-dd', 'yyyy-m-d');
     $retval = array_merge(DateAttribute::parseDate($datetime[0], $formatsdate), TimeAttribute::parseTime($datetime[1]));
     return $retval;
 }