forked from yakamara/redaxo_xform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.xform.text.inc.php
92 lines (72 loc) · 3.26 KB
/
class.xform.text.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* XForm
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/
class rex_xform_text extends rex_xform_abstract
{
function enterObject()
{
$this->setValue((string) $this->getValue());
if ($this->getValue() == '' && !$this->params['send']) {
$this->setValue($this->getElement(3));
}
$this->params['form_output'][$this->getId()] = $this->parse('value.text.tpl.php');
$this->params['value_pool']['email'][$this->getName()] = stripslashes($this->getValue());
if ($this->getElement(4) != 'no_db') {
$this->params['value_pool']['sql'][$this->getName()] = $this->getValue();
}
}
function getDescription()
{
return 'text -> Beispiel: text|name|label|defaultwert|[no_db]|cssclassname|dbtype';
}
function getDefinitions()
{
return array(
'type' => 'value',
'name' => 'text',
'values' => array(
'name' => array( 'type' => 'name', 'label' => 'Feld' ),
'label' => array( 'type' => 'text', 'label' => 'Bezeichnung'),
'default' => array( 'type' => 'text', 'label' => 'Defaultwert'),
'no_db' => array( 'type' => 'no_db', 'label' => 'Datenbank', 'default' => 0),
'css_class' => array( 'type' => 'text', 'label' => 'cssclassname'),
'dbtype' => array( 'type' => 'select', 'label' => 'Datenbanktyp', 'default' => 'text', 'options' => array('text' => 'text', 'mediumtext' => 'mediumtext', 'longtext' => 'longtext', 'varchar(50)' => 'varchar(50)', 'varchar(100)' => 'varchar(100)', 'varchar(255)' => 'varchar(255)', 'date' => 'date', 'datetime' => 'datetime', 'int' => 'int')),
),
'description' => 'Ein einfaches Textfeld als Eingabe',
'dbtype' => 'text',
'famous' => true,
'hooks' => array(
'preCreate' => 'rex_xform_text::getDBType'
)
);
}
public static function getDBType($params)
{
return $params['dbtype'] ?: 'text';
}
public static function getSearchField($params)
{
$params['searchForm']->setValueField('text', array('name' => $params['field']->getName(), 'label' => $params['field']->getLabel()));
}
public static function getSearchFilter($params)
{
$value = $params['value'];
$field = $params['field']->getName();
if ($value == '(empty)') {
return ' (`' . mysql_real_escape_string($field) . '` = "" or `' . mysql_real_escape_string($field) . '` IS NULL) ';
} elseif ($value == '!(empty)') {
return ' (`' . mysql_real_escape_string($field) . '` <> "" and `' . mysql_real_escape_string($field) . '` IS NOT NULL) ';
}
$pos = strpos($value, '*');
if ($pos !== false) {
$value = str_replace('%', '\%', $value);
$value = str_replace('*', '%', $value);
return ' `' . mysql_real_escape_string($field) . "` LIKE '" . mysql_real_escape_string($value) . "'";
} else {
return ' `' . mysql_real_escape_string($field) . "` = '" . mysql_real_escape_string($value) . "'";
}
}
}