Source for file basic_control.php

Documentation is available at basic_control.php


1 <?php
2
3 class basic_control {
4 var $context;
5 var $otype;
6 var $data;
7 var $objectid;
8 var $ret;
9 var $parentid;
10 var $relcol;
11 var $relval;
12
13 function getview($view) {
14 $uh =& getUserHandler();
15 $app = $uh->getAppName();
16 if (file_exists(dirname(__FILE__).'/basic_view_'.$view.'.php'))
17 require_once('basic_view_'.$view.'.php');
18 if (file_exists(dirname(__FILE__).'/'.$this->otype.'_view_'.$view.'.php')) {
19 require_once($this->otype.'_view_'.$view.'.php');
20 } elseif ($view == 'init' && file_exists(dirname(__FILE__).'/'.$this->otype.'_view_list.php')) {
21 $view = 'list';
22 require_once($this->otype.'_view_list.php');
23 }
24 if (!empty($app)) {
25 if (file_exists(dirname(__FILE__).'/app/'.$app.'/'.$app.'_basic_view_'.$view.'.php')) {
26 require_once('app/'.$app.'/'.$app.'_basic_view_'.$view.'.php');
27 }
28 if (file_exists(dirname(__FILE__).'/app/'.$app.'/'.$app.'_'.$this->otype.'_view_'.$view.'.php')) {
29 require_once('app/'.$app.'/'.$app.'_'.$this->otype.'_view_'.$view.'.php');
30 }
31 }
32
33 $s = 'basic_view_'.$view;
34 if (!empty($app)) {
35 if (class_exists($app.'_'.$this->otype.'_view_'.$view)) {
36 $s = $app.'_'.$this->otype.'_view_'.$view;
37 } elseif (class_exists($this->otype.'_view_'.$view)) {
38 $s = $this->otype.'_view_'.$view;
39 } elseif (class_exists($app.'_basic_view_'.$view)) {
40 $s = $app.'_basic_view_'.$view;
41 }
42 } elseif (class_exists($this->otype.'_view_'.$view)) {
43 $s = $this->otype.'_view_'.$view;
44 }
45 $obj = new $s;
46 $obj->data = $this->data;
47 $obj->otype = $this->otype;
48 $obj->context = &$this->context;
49 $obj->objectid = $this->objectid;
50 $obj->ret = $this->ret;
51 $obj->view = $view;
52 $obj->parentid = $this->parentid;
53 $obj->relcol = $this->relcol;
54 $obj->relval = $this->relval;
55 # $obj->isextendeddatatype = owIsExtendedDatatype($this->otype);
56 # $obj->extension_basedatatype = owGetBasedatatype($this->otype);
57 $obj->loadLanguage();
58 return $obj;
59 }
60
61 function getmodel($model) {
62 $uh =& getUserHandler();
63 $app = $uh->getAppName();
64 if (file_exists(dirname(__FILE__).'/basic_model_'.$model.'.php'))
65 require_once('basic_model_'.$model.'.php');
66 if (file_exists(dirname(__FILE__).'/'.$this->otype.'_model_'.$model.'.php')) {
67 require_once($this->otype.'_model_'.$model.'.php');
68 }
69 if (!empty($app)) {
70 if (file_exists(dirname(__FILE__).'/app/'.$app.'/'.$app.'_basic_model_'.$model.'.php')) {
71 require_once(dirname(__FILE__).'/app/'.$app.'/'.$app.'_basic_model_'.$model.'.php');
72 }
73 if (file_exists(dirname(__FILE__).'/app/'.$app.'/'.$app.'_'.$this->otype.'_model_'.$model.'.php')) {
74 require_once('app/'.$app.'/'.$app.'_'.$this->otype.'_model_'.$model.'.php');
75 }
76 }
77
78 $s = 'basic_model_'.$model;
79 if (!empty($app)) {
80 if (class_exists($app.'_'.$this->otype.'_model_'.$model)) {
81 $s = $app.'_'.$this->otype.'_model_'.$model;
82 } elseif (class_exists($this->otype.'_model_'.$model)) {
83 $s = $this->otype.'_model_'.$model;
84 } elseif (class_exists($app.'_basic_model_'.$model)) {
85 $s = $app.'_basic_model_'.$model;
86 }
87 } elseif (class_exists($this->otype.'_model_'.$model)) {
88 $s = $this->otype.'_model_'.$model;
89 }
90 $obj = new $s;
91 $obj->data = $this->data;
92 $obj->otype = $this->otype;
93 $obj->context = &$this->context;
94 $obj->objectid = $this->objectid;
95 $obj->control = $model;
96 $obj->parentid = $this->parentid;
97 return $obj;
98 }
99
100 function model($cmd) {
101 foreach($cmd as $curcmd) {
102 $obj = $this->getmodel($curcmd);
103 $obj->model();
104 $userhandler =& getUserHandler();
105 $eventhandler =& GetEventHandler();
106 if ($userhandler->getObjectIdStack()) {
107 $eventhandler->event($curcmd, $this->otype, $userhandler->getObjectIdStack());
108 } else {
109 $eventhandler->event($curcmd, $this->otype, $this->objectid);
110 }
111 unset($obj);
112 }
113 }
114
115 function view($view) {
116 $errorhandler =& getErrorHandler();
117 if ($errorhandler->haserror()) {
118 echo nl2br($errorhandler->outputError());
119 die();
120 }
121 $userhandler =& getUserHandler();
122
123 $filtercols = array();
124 if (!empty($this->otype)) {
125 $filtercols = array_keys(owDatatypeCols($this->otype));
126 } else if (!empty($this->objectid)) {
127
128 $filtercols = array_keys(owDatatypeCols(owGetDatatype($this->type)));
129 }
130
131 if ($_SERVER['REQUEST_METHOD'] == 'POST' && !isset($_POST['_DONTCONVERT_'])) {
132 $variables = array();
133 foreach ($_GET as $key=>$val) {
134 $variables[$key] = $val;
135 }
136
137 unset($_POST['cmd']);
138 unset($_POST['MAX_FILE_SIZE']);
139
140 foreach ($_POST as $key=>$val) {
141 $variables[$key] = $val;
142 }
143
144 foreach($filtercols as $remove) {
145 unset($variables[$remove]);
146 }
147
148 $variables['_FROMPOST_'] = 1;
149 $querystring = '';
150 foreach ($variables as $key => $val) {
151 if (is_array($val)) {
152 /** DO WE WANT THIS? */
153 //foreach ($val as $val2) {
154 // $querystring .= ($key . '[]=' . $val2 . '&');
155 //}
156 } else {
157 $querystring .= ($key . '=' . $val . '&');
158 }
159 }
160
161 $_SESSION['objectstack'] = $userhandler->getObjectIdStack();
162 if ($errorhandler->haserror()) {
163 $_SESSION['errorhandler'] = $errorhandler->outputError();;
164 }
165 header('Location: '.$this->getGuiUrl().$querystring);
166 die();
167 } else {
168 if (@$_GET['_FROMPOST_'] == 1) {
169 $userhandler->setObjectidStack($_SESSION['objectstack']);
170 unset($_SESSION['objectstack']);
171 if (isset($_SESSION['errorhandler'])) {
172 $errorhandler->seterror($_SESSION['errorhandler']);
173 unset($_SESSION['errorhandler']);
174 }
175 }
176 }
177
178 ob_start();
179
180 foreach($view as $curview) {
181 $obj = $this->getview($curview);
182 echo $obj->view();
183 $userhandler->clearObjectIdStack();
184 unset($obj);
185 }
186 $theview = ob_get_contents();
187 ob_end_clean();
188 return $theview;
189 }
190
191 function viewcomplete($view) {
192 $theview = $this->view($view);
193 $context =& $this->context;
194 ob_start();
195 echo $context->header_start();
196 echo $context->header_end();
197 echo $context->body();
198 echo $theview;
199 $errorhandler =& GetErrorHandler();
200 if ( $errorhandler->haserror()) echo '<script language="javascript">alert(\'' . str_replace("'", "\\'",$errorhandler->outputerror() ) . "');</script>";
201 echo $context->footer();
202 ob_end_flush();
203 }
204
205
206 function getGuiUrl() {
207 $userhandler =& getUserHandler();
208 if ($userhandler->getWebUser()) {
209 return $_SERVER['PHP_SELF'].'?pageid='.$_REQUEST['pageid']."&";
210 } else {
211 return $_SERVER['PHP_SELF'].'?w=1&';
212 }
213 }
214 }
215
216 function getcontrol($otype,$objectid,&$context,$parentid='') {
217 if (file_exists($otype.'_control.php')) {
218 @require_once($otype.'_control.php');
219 }
220 if (class_exists($otype.'_control')) {
221 $s = $otype.'_control';
222 } else {
223 $s = 'basic_control';
224 }
225 $obj = new $s;
226 $obj->data = $_REQUEST;
227 $obj->ret = @$_REQUEST['_ret'];
228 $obj->otype = $otype;
229 $obj->context = &$context;
230 $obj->objectid = $objectid;
231 if (isset($_REQUEST['_parentid'])) $obj->parentid = $_REQUEST['_parentid'];
232 if ($parentid) $obj->parentid = $parentid;
233 if (isset($_REQUEST['_relcol'])) $obj->relcol = $_REQUEST['_relcol'];
234 if (isset($_REQUEST['_relval'])) $obj->relval = $_REQUEST['_relval'];
235 return $obj;
236 }
237
238 ?>

Documentation generated on Thu, 9 Jun 2005 06:51:03 +0200 by phpDocumentor 1.2.3