form.php
4.35 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
N2Loader::import('libraries.xml.helper');
class N2FormAbstract extends N2Data {
public static $documentation = '';
public $appType;
var $_xml;
var $_xmlfile;
var $_tabs;
public static $importPaths = array();
public $xmlFolder = '';
/**
*
* App type must be decalred if you need to route in the parameters. Route is needed for example for subform!!!
*
* @param $appType N2ApplicationType|bool
*/
public function __construct($appType = false) {
$this->appType = $appType;
$this->_xml = null;
$this->_tabs = array();
parent::__construct();
}
function initTabs($removeImportPath = true) {
if ($this->xmlFolder) {
N2Form::$importPaths[] = $this->xmlFolder;
}
if (count($this->_tabs) == 0 && $this->_xml->params && count($this->_xml->params)) {
foreach ($this->_xml->params as $tab) {
$type = N2XmlHelper::getAttribute($tab, 'type');
if ($type == '') {
$type = 'default';
}
$class = self::importTab($type);
$this->_tabs[N2XmlHelper::getAttribute($tab, 'name')] = new $class($this, $tab);
}
}
if ($removeImportPath && $this->xmlFolder) {
array_pop(N2Form::$importPaths);
}
}
function render($control_name) {
$this->initTabs(false);
$this->decorateFormStart();
foreach ($this->_tabs AS $tabname => $tab) {
$tab->render($control_name);
}
$this->decorateFormEnd();
if ($this->xmlFolder) {
array_pop(N2Form::$importPaths);
}
}
function decorateFormStart() {
echo N2Html::openTag("div", array("class" => "n2-form"));
}
function decorateFormEnd() {
echo N2Html::closeTag("div");
}
function loadXMLFile($file) {
if (!N2Filesystem::existsFile($file)) {
throw new Exception("xml file not found ('{$file}')! <br /><strong>" . __FILE__ . ":" . __LINE__ . "</strong>");
}
if (!function_exists('simplexml_load_string')) {
throw new Exception(n2_("SimpleXML extension must be enabled in php.ini. Please contact your server administrator to enable it for you."));
}
// @fix Warning: simplexml_load_file(): I/O warning : failed to load external entity
$this->_xml = simplexml_load_string(file_get_contents($file));
$this->_xmlfile = $file;
$this->xmlFolder = dirname($file);
}
function setXML(&$xml) {
$this->_xml = $xml;
}
function getSubFormAjax($tab, $name) {
$tabsFound = $this->_xml->xpath('//params[@name="' . $tab . '"]');
if (count($tabsFound) > 0) {
if ($this->xmlFolder) {
N2Form::$importPaths[] = $this->xmlFolder;
}
$type = N2XmlHelper::getAttribute($tabsFound[0], 'type');
if ($type == '') {
$type = 'default';
}
$class = self::importTab($type);
$tabObject = new $class($this, $tabsFound[0]);
if (isset($tabObject->_elements[$name])) {
return $tabObject->_elements[$name];
}
}
return null;
}
public function makeTest($key) {
if ($key != '' && (!defined($key) || !constant($key))) {
return false;
}
return true;
}
public static function importTab($type) {
$class = 'N2Tab' . $type;
if (!class_exists($class, false)) {
for ($i = count(N2Form::$importPaths) - 1; $i >= 0; $i--) {
if (N2Loader::importPath(N2Form::$importPaths[$i] . '/tabs/' . $type)) {
break;
}
}
}
return $class;
}
public static function importElement($type) {
$class = 'N2Element' . $type;
if (!class_exists($class, false)) {
for ($i = count(N2Form::$importPaths) - 1; $i >= 0; $i--) {
if (N2Loader::importPath(N2Form::$importPaths[$i] . '/element/' . $type)) {
break;
}
}
}
return $class;
}
}
N2Loader::import('libraries.form.form', 'platform');
N2Form::$importPaths[] = dirname(__FILE__);