Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / api / common / ryform.php
blob40373febd56ac5c39834c4d59bf633d772a63d70
1 <?php
3 /* Copyright (C) 2009 Winch Gate Property Limited
5 * This file is part of ryzom_api.
6 * ryzom_api is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * ryzom_api is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
20 include_once (RYAPI_PATH.'/common/ryformBases.php');
22 class ryVar extends basicRyForm {
23 public $formName = '';
24 public $varName = '';
25 public $varValue = '';
27 function getFormDefs() {
28 return array(
29 new ryFormDef('varName', DEF_TYPE_TEXT),
30 new ryFormDef('varValue', DEF_TYPE_TEXT),
34 function getHtmlRepr() {
35 return $this->varName.' =&gt; '.$this->varValue;
39 class ryForm {
41 private $name = '';
42 private $defines = array();
43 private $template = '';
45 static private $forms;
46 static private $ryformsIcons = array();
48 function __construct($dir, $name) {
49 $this->name = $name;
50 self::$forms[$dir.'/'.$name] = $this;
53 static function addRyFormIcon($ryform_name, $icon) {
54 self::$ryformsIcons[$ryform_name] = $icon;
57 function addDefine($def) {
58 $this->defines[$def->name] = $def;
61 function setTemplate($template) {
62 $this->template = $template;
65 function getTemplate() {
66 return $this->template;
69 function addValue($name, $value) {
70 if (array_key_exists($name, $this->defines))
71 $this->defines[$name]->value = $value;
72 else
73 return false;
74 return true;
77 function addExtraValues($name, $value) {
78 if (array_key_exists($name, $this->defines))
79 $this->defines[$name]->extraValues = $value;
80 else
81 return false;
82 return true;
85 function getForm($params) {
87 if (isset($params['ryform_action']) && $params['ryform_action']) {
88 $res = $this->doAction($params);
89 return $res;
92 if (@$params['validate'] == $this->name)
93 return array(DATA_FORM_VALUES, $_POST);
95 if (isset($params['ryform_parent']))
96 $parent_ryform_name = $params['ryform_parent'].'/';
97 else
98 $parent_ryform_name = '';
100 $action =_url(ryzom_get_params(), array('validate' => $this->name));
101 $ret = '';
102 $ret .= '<form action="'.$action.'" method="POST">'."\n";
104 if (!$this->getTemplate()) {
105 $ret .= ' <table width="100%" cellpadding="0" cellspacing="0">'."\n";
106 $ret .= ' '._s('t header', '<td height="24px">'._t('parameter').'</td><td>'._t('value').'</td><td></td>')."\n";
107 $tmpl = '';
108 } else {
109 $tmpl = $this->getTemplate();
112 $i = 0;
114 foreach ($this->defines as $def_id => $def) {
115 if ($def->name == 'name')
116 $def->name = '_name';
118 $deffullname = $def->name;
119 $url_params = ryzom_get_params();
120 $type = $def->type;
121 $infos = $def->infos;
122 $value = ($def->value !== NULL)?$def->value:$def->defaultValue;
124 if (!is_object($value) && !is_array($value))
125 $str_value = _h(strval($value));
126 else
127 $str_value = '';
129 if ($def->hidden)
130 $type = DEF_TYPE_HIDDEN;
132 $hidden = false;
133 $input = '';
134 switch ($type) {
136 case DEF_TYPE_HIDDEN:
137 $input = '<input type="hidden" name="'.$def->name.'" value="'.$str_value.'" />'."\n";
138 $hidden = true;
139 break;
141 case DEF_TYPE_TEXT:
142 $input = '<input style="width:250px" type="text" name="'.$def->name.'" value="'.$str_value.'" size="25'.(_user()->ig?'0':'').'" />';
143 break;
144 case DEF_TYPE_NAMEID:
145 $input = '<input style="width:250px" type="text" name="'.$def->name.'" value="'.getNameId($str_value).'" size="25'.(_user()->ig?'0':'').'" />';
146 break;
148 case DEF_TYPE_ID:
149 case DEF_TYPE_INT:
150 case DEF_TYPE_FLOAT:
151 $input = '<input style="width:100px" type="text" name="'.$def->name.'" value="'.$str_value.'" size="10'.(_user()->ig?'0':'').'" />';
152 break;
154 case DEF_TYPE_BOOL:
155 $input = '<select name="'.$def->name.'">'."\n";
156 if ($value)
157 $input .= '<option selected="selected" value="on">'._t('yes').'</option>'."\n".'<option value="off">'._t('no').'</option>';
158 else
159 $input .= '<option value="on">'._t('yes').'</option>'."\n".'<option selected="selected" value="off">'._t('no').'</option>';
160 $input .= '</select>';
161 break;
163 case DEF_TYPE_OPTION_FUNCTION:
164 case DEF_TYPE_OPTION:
165 if ($type == DEF_TYPE_OPTION)
166 $options = $def->params;
167 else {
168 if (is_array($def->defaultValue))
169 $options = call_user_func_array($def->params, $def->defaultValue);
170 else
171 $options = call_user_func($def->params);
173 $input = '<select name="'.$def->name.'">'."\n";
174 $options_html = '';
175 foreach ($options as $option => $text) {
176 $option = strval($option);
177 if ($option && $option[0] === '<' && $option[1] === '/')
178 $options_html .= '</optgroup>';
179 else if ($option && $option[0] === '<')
180 $options_html .= '<optgroup label="'.$text.'">';
181 else {
182 if ($value !== NULL and (strval($value) == $option))
183 $options_html .= '<option selected="selected" value="'.$option.'">'.$text.'</option>'."\n";
184 else
185 $options_html .= '<option value="'.$option.'">'.$text.'</option>'."\n";
188 $input .= $options_html;
189 $input .= '</select>';
190 break;
192 case DEF_TYPE_COMBO_FUNCTION:
193 case DEF_TYPE_COMBO:
194 if ($type == DEF_TYPE_COMBO)
195 $options = $def->params;
196 else {
197 if (is_array($def->defaultValue))
198 $options = call_user_func_array($def->params, $def->defaultValue);
199 else
200 $options = call_user_func($def->params);
202 if (_user()->ig) {
203 // TODO : try to do it with lua
204 } else { // HTML 4
205 $input .= '<input style="width:400px" type="text" id="'.$def->name.'" name="'.$def->name.'" value="'.$str_value.'" />
206 <select onChange="combo(this, \''.$def->name.'\')" onMouseOut="comboInit(this, \''.$def->name.'\')" >';
207 $options_html = '';
208 $have_selected = false;
209 foreach ($options as $option => $text) {
210 if ($option && $option[0] === '<' && $option[1] === '/')
211 $options_html .= '</optgroup>';
212 else if ($option && $option[0] === '<')
213 $options_html .= '<optgroup label="'.$text.'">';
214 else {
216 if ($value and ($value == $option)) {
217 $have_selected = true;
218 $options_html .= '<option selected="selected" value="'.$option.'">'.$text.'</option>'."\n";
219 } else
220 $options_html .= '<option value="'.$option.'">'.$text.'</option>'."\n";
223 if ($have_selected)
224 $input .= '<option value=""></option>';
225 else
226 $input .= '<option selected="selected" value=""></option>';
227 $input .= $options_html;
228 $input .= '</select>';
230 break;
232 case DEF_TYPE_TEXTAREA:
233 if (!$value)
234 $value = "";
235 $input = '<pre>'.($type == DEF_TYPE_BBCODE?'<font color="orange">- BBCode -</font><br />':'').'<textarea name="'.$def->name.'" rows="3">'._h($value).'</textarea></pre>';
236 break;
238 case DEF_TYPE_TRAD:
239 $base = '';
240 $param = $def->name;
241 $value = array_merge(array('en' => '', 'fr' => '', 'de' => '', 'ru' => '', 'es' => ''), $value);
242 $base = ryzom_get_param('select_base', '');
243 $edit = $display = $input_header = '';
244 foreach (array('en', 'fr', 'de', 'ru', 'es') as $lang) {
245 if (_user()->lang == $lang)
246 $edit = _i($lang == 'en'?API_URL.'data/img/lang/us.png':API_URL.'data/img/lang/'.$lang.'.png').' <textarea style="width: 90%" rows="3" name="'.$param.'['.$lang.']">'._h($value[$lang]).'</textarea>';
247 if ((!$base && $value[$lang]) || $base == $lang) {
248 $base = $lang;
249 $display = strtoupper($lang).' = <font color="orange">'.str_replace("\n", '<br />', _h($value[$lang])).'</font>';
251 $input .= '<input type="hidden" name="'.$param.'['.$lang.']" value="'.$value[$lang].'" />';
252 $input_header .= _l(_i($lang == 'en'?API_URL.'data/img/lang/us.png':API_URL.'data/img/lang/'.$lang.'.png'), $url_params, array('select_base' => $lang)).'&nbsp;&nbsp;';
255 $input = $input_header.$input.' &nbsp; '.$display.'<br />'.$edit;
256 break;
258 case DEF_TYPE_RYFORM:
259 case DEF_TYPE_RYFORMS_ARRAY:
260 $savedRyform = $value;
261 if (is_array($savedRyform)) {
262 $to_clean = array();
263 foreach ($savedRyform as $id => $ryform) {
264 if (!is_object($ryform))
265 $to_clean[] = $id;
267 foreach ($to_clean as $id)
268 unset($savedRyform[$id]);
269 $savedRyform = array_values($savedRyform);
270 } else if (is_object($savedRyform)) {
271 $savedRyform = array($savedRyform);
272 } else
273 $savedRyform = array();
275 $input .= '<table width="100%" cellspacing="0" cellpadding="0" >';
276 if ($savedRyform) {
277 foreach ($savedRyform as $id => $ryform) {
278 if (!is_object($ryform)) {
279 p('!!! ERROR !!!', $ryform);
280 continue;
282 $ryform->id = $id+1;
283 if (!isset($ryform->formName) || !$ryform->formName)
284 $ryform->formName = 'Element '.$id;
285 if (count($savedRyform) > 1)
286 $display_id = '<font size="12px" style="font-weight: bold; font-size: 14px" color="#FFAA55">'.strval(intval($id)+1).'</font>';
287 else
288 $display_id = '';
290 $script_up = ($id != 0)?_l(_i('16/arrow_up', _t('up')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'up')).' ':'';
291 $script_down = ($id != count($savedRyform)-1)?_l(_i('16/arrow_down', _t('down')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'down')).' ':'';
293 $icon = (isset(self::$ryformsIcons[get_class($ryform)]))?self::$ryformsIcons[get_class($ryform)]:_i('32/brick');
294 $input .= _s('t row '.($id%2),
295 '<td width="36px">'._l(($def->type == DEF_TYPE_RYFORM?_i('16/arrow_redo', _t('change')):_i('16/add', _t('add'))), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.strval(intval($id)+1), 'ryform_action' => 'list')).' '.$display_id.'</td>'.
296 '<td width="10px">'.$script_up.$script_down.'</td>'.
297 '<td ><table width="100%"><tr>
298 <td width="40px">'.$icon.'</td>
299 <td valign="middle" width="300px"><font size="12px" style="font-size: 13px;font-weight: bold;" color="#FFAA55">'.
300 _l($ryform->formName, $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'edit')).' '.
301 '</font><br />'._t(get_class($ryform).'_short_description').'</td>
302 <td align="left" valign="middle" bgcolor="#000000">'.$ryform->getHtmlRepr().'</td>
303 </tr></table><td width="70px" align="right">'.
304 _l(_i('16/script_edit', _t('edit')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'edit')).' '.
305 _l(_i('16/script_code', _t('edit_source')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'source')).'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.
306 _l(_i('16/script_delete', _t('del')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'del')).'</td><td>&nbsp;</td>');
309 $input .= '</table>';
310 if (count($savedRyform) == 0 || $def->type != DEF_TYPE_RYFORM) {
311 if (is_string($def->params))
312 $infos = _l(_i('16/add', _t('add')), $url_params, array('new_ryform' => $def->params, 'ryform_name' => $parent_ryform_name.$deffullname.':0', 'ryform_action' => 'add'));
313 else if (count($def->params) == 1)
314 $infos = _l(_i('16/add', _t('add')), $url_params, array('new_ryform' => $def->params[0], 'ryform_name' => $parent_ryform_name.$deffullname.':0', 'ryform_action' => 'add'));
315 else
317 $infos = _l(_i('16/add', _t('add')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':0', 'ryform_action' => 'list'));
319 if ($type == DEF_TYPE_RYFORMS_ARRAY)
320 $infos .= '&nbsp;&nbsp;&nbsp;'._l(_i('16/application_form_add', _t('multiadd')), $url_params, array('ryform_name' => $deffullname, 'ryform_action' => 'list_multiadd'));
322 break;
324 case DEF_TYPE_FUNCTION:
325 if (is_array($def->defaultValue))
326 list($result_type, $value) = call_user_func_array($def->params, $def->defaultValue);
327 else
328 list($result_type, $value) = call_user_func($def->params);
329 if ($result_type == DATA_HTML_FORM) {
330 return array(DATA_HTML_FORM, $value);
331 } else {
332 unset($url_params[$deffullname.'_action']);
333 $input = $value;
335 break;
337 default:
338 $input = '<input type="hidden" name="'.$def->name.'" value="'.$value.'" />'.$value."\n";
339 $hidden = true;
343 if ($hidden)
344 $ret .= $input;
345 else
347 if ($tmpl) {
348 $tmpl = str_replace('{'.$def->name.'}', '<font '.(_user()->ig?'color="orange" size="11"':'style="color:orange;"').'>'._t($def->prefixTrad.$def->name).'</font>', $tmpl);
349 $tmpl = str_replace('{'.$def->name.'.input}', $input, $tmpl);
350 $tmpl = str_replace('{'.$def->name.'.infos}', $infos, $tmpl);
351 } else
352 $ret .= _s('t row '.strval($i % 2), '<td height="32px" width="200px">&nbsp;'.(!$def->optional?'*':'').($def->superAdmin?'##':'').($def->admin?'#':'')._t($def->prefixTrad.$def->name).'</td><td valign="center">'.$input.'</td><td>'.$infos.'</td>')."\n";
353 $i++;
357 if ($tmpl) {
358 $tmpl = str_replace('{submit.input}', '<input type="submit" value="'._t('submit').'" />', $tmpl);
359 $ret .= $tmpl;
360 $ret .= '<table width="100%" cellspacing="0" cellpadding="0" ><tr>'._s('t row '.strval($i % 2), '<td height="32px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'._t('required_fields').'</td><td></td><td align="middle"><input type="submit" value="'._t('submit').'" /></td>').'</tr></table>';
361 } else {
362 $ret .= _s('t row '.strval($i % 2), '<td height="32px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'._t('required_fields').'</td><td></td><td><input type="submit" value="'._t('submit').'" /></td>');
363 $ret .= '</table>';
365 $ret .= '</form><br />';
366 return array(DATA_HTML_FORM, $ret."\n");
370 function doAction($url_params) {
371 if (!$url_params['ryform_name'])
372 return array(DATA_RYFORM_VALUE, array());
373 $ret = '';
374 $ryforms = explode('/', $url_params['ryform_name']);
375 $this_ryform_name = array_shift($ryforms);
376 list($ryform_name,$ryform_pos) = explode(':', $this_ryform_name);
377 if (!isset($this->defines[$ryform_name]))
378 return 'Bad ryform name';
379 $def = $this->defines[$ryform_name];
381 if ($ryforms) {
382 $action = 'edit';
383 $next_action = $url_params['ryform_action'];
384 } else {
385 $action = $url_params['ryform_action'];
386 $next_action = '';
389 switch ($action) {
390 case 'list':
391 if (isset($url_params['ryform_parent']) && $url_params['ryform_parent'])
392 $ryform_parent = $url_params['ryform_parent'].'/';
393 else
394 $ryform_parent = '';
395 $ret .= '<table cellpadding="0" cellspacing="0" width="100%">';
396 foreach ($def->params as $id => $ryform) {
397 if (is_array($ryform)) {
398 $ret .= _s('t row 1', '<td height="28px" width="22px" bgcolor='.ryzom_get_color_style('section').'></td><td bgcolor='.ryzom_get_color_style('section').'>'.ryzom_font(_t('ryform_cat_'.$id), '', '12').'</td><td bgcolor='.ryzom_get_color_style('section').'></td>');
399 foreach ($ryform as $subid => $subryform) {
400 $ret .= _s('t row '.($subid%2), '<td width="22px" height="34px">'.self::$ryformsIcons[$subryform].'</td><td>&nbsp;&nbsp;'.
401 _l(_t($subryform.'_short_description'), $url_params, array('ryform_name' => $ryform_parent.$url_params['ryform_name'], 'ryform_action' => 'add', 'new_ryform' => $subryform)).'</td><td>'.$subryform.'</td>');
403 } else
404 $ret .= _s('t row '.($id%2), '<td width="22px" height="34px">'.self::$ryformsIcons[$ryform].'</td><td>&nbsp;&nbsp;'.
405 _l(_t($ryform.'_short_description'), $url_params, array('ryform_name' => $ryform_parent.$url_params['ryform_name'], 'ryform_action' => 'add', 'new_ryform' => $ryform)).'</td><td>'.$ryform.'</td>');
407 $ret .= '</table>';
408 return array(DATA_HTML_FORM, $ret);
409 break;
411 case 'list_multiadd':
412 // TODO
414 unset($url_params[$deffullname.'_action']);
415 $ret .= '<table cellpadding="5"><tr>';
416 foreach ($def->params as $ryform) {
417 $ret .= '<td bgcolor="#000000">'._l($ryform, $url_params, array('ryform_action' => 'multiadd', 'new_ryform' => $ryform)).'</td>';
419 $ret .= '</tr></table>';
420 return array(DATA_HTML_FORM, $ret);*/
421 break;
423 case 'add':
424 $new_ryform = ryzom_get_param('new_ryform');
425 $valid_ryform = false;
426 if ($new_ryform) {
428 if ((is_string($def->params) && $new_ryform == $def->params) || in_array($new_ryform, $def->params))
429 $valid_ryform = true;
430 else {
431 foreach ($def->params as $param) {
432 if (is_array($param) && in_array($new_ryform, $param))
433 $valid_ryform = true;
436 if (!$valid_ryform)
437 return array(DATA_HTML_FORM, 'Bad ryform');
439 } else {
440 $new_ryform = $def->params;
442 $ryform = new $new_ryform($new_ryform, '');
443 $ryform->preSerialization();
444 if ($def->type != DEF_TYPE_RYFORM) {
445 p($def->value);
446 if (!is_array($def->value))
447 $savedRyform = array($def->value);
448 else
449 $savedRyform = $def->value;
450 if ($ryform_pos === 0) {
451 $value = array_values(array_merge(array($ryform), $savedRyform));
452 } else if ($ryform_pos !== NULL) {
453 $begin = array_slice($savedRyform, 0, $ryform_pos);
454 $end = array_slice($savedRyform, $ryform_pos, count($savedRyform)-$ryform_pos);
455 $value = array_values(array_merge($begin, array($ryform), $end));
456 } else
457 $value[] = $ryform;
458 p($ryform_name, $value);
459 //return array(DATA_RYFORM_VALUE, array('stages' => array()));
460 return array(DATA_RYFORM_VALUE, array($ryform_name => $value));
461 } else {
462 p($ryform_name, $ryform);
463 return array(DATA_RYFORM_VALUE, array($ryform_name => $ryform));
465 break;
467 case 'edit':
468 $a_ryforms = $def->value;
469 if (is_array($a_ryforms))
470 $ryform = $a_ryforms[$ryform_pos];
471 else
472 $ryform = $a_ryforms;
473 $ryform->postSerialization();
474 $validate = isset($url_params['validate']) && $url_params['validate'];
476 $form = new ryForm('', $def->name);
477 foreach ($ryform->getFormDefs() as $form_def) {
478 $form->addDefine($form_def);
479 $name = $form_def->name;
480 // Init form with ryfom values
481 if (property_exists($ryform, $name)) {
482 $form->addValue($form_def->name, $ryform->$name);
485 foreach ($ryform->getFormDefsExtraValues() as $def_name => $extra_values)
486 $form->addExtraValues($def_name, $extra_values);
487 $form->setTemplate($ryform->getTemplate());
489 list($result_type, $value) = $form->getForm(array('action' => $url_params['action'], 'script' => $url_params['script'], 'ryform_action' => $next_action, 'ryform_parent' => $this_ryform_name, 'ryform_name' => implode('/', $ryforms), 'validate' => $validate));
490 if ($result_type == DATA_HTML_FORM) {
491 return array(DATA_HTML_FORM, $value);
492 } else {
493 if ($result_type == DATA_FORM_VALUES)
494 $value = $form->validateFormPost($value);
495 $ryform->setFormParams($value);
496 $ryform->preSerialization();
499 if (is_array($a_ryforms))
500 $a_ryforms[$ryform_pos] = $ryform;
501 else
502 $a_ryforms = $ryform;
504 $value = array($ryform_name => $a_ryforms);
505 return array(DATA_RYFORM_VALUE, $value);
506 break;
509 case 'del':
510 $id = $ryform_pos;
511 p($def->value);
512 if (!is_array($def->value))
513 $def->value = array();
514 else
515 unset($def->value[$id]);
516 $value = array_values($def->value);
517 return array(DATA_RYFORM_VALUE, array($ryform_name => $value));
518 break;
520 case 'up':
521 $a_ryforms = $def->value;
522 if (!is_array($a_ryforms))
523 ryzom_redirect(_url($url_params, array('ryform_action' => '')));
525 $temp_ryform = $a_ryforms[$ryform_pos-1];
526 $a_ryforms[$ryform_pos-1] = $a_ryforms[$ryform_pos];
527 $a_ryforms[$ryform_pos] = $temp_ryform;
528 $a_ryforms = array_values($a_ryforms);
529 p($ryform_name, $a_ryforms);
530 return array(DATA_RYFORM_VALUE, array($ryform_name => $a_ryforms));
531 break;
533 case 'down':
534 $a_ryforms = $def->value;
535 if (!is_array($a_ryforms))
536 ryzom_redirect(_url($url_params, array('ryform_action' => '')));
538 $temp_ryform = $a_ryforms[$ryform_pos+1];
539 $a_ryforms[$ryform_pos+1] = $a_ryforms[$ryform_pos];
540 $a_ryforms[$ryform_pos] = $temp_ryform;
541 $a_ryforms = array_values($a_ryforms);
542 return array(DATA_RYFORM_VALUE, array($ryform_name => $a_ryforms));
543 break;
545 case 'source':
546 $a_ryforms = $def->value;
547 if (is_array($a_ryforms))
548 $ryform = $a_ryforms[$ryform_pos];
549 else
550 $ryform = $a_ryforms;
551 $ryform->postSerialization();
553 $form = new ryForm('', $def->name);
554 $form->addDefine(new ryFormDef('ryform_source', DEF_TYPE_TEXTAREA, '', base64_encode(serialize($ryform))));
555 $validate = isset($url_params['validate']) && $url_params['validate'];
556 list($result_type, $value) = $form->getForm(array('ryform_action' => $next_action, 'ryform_parent' => $this_ryform_name, 'ryform_name' => implode('/', $ryforms), 'validate' => $validate));
557 if ($result_type == DATA_HTML_FORM) {
558 return array(DATA_HTML_FORM, $value);
559 } else {
560 if ($result_type == DATA_FORM_VALUES)
561 $params = $form->validateFormPost($value);
562 else
563 $params = $value;
564 $ryform = unserialize(base64_decode($params['ryform_source']));
565 if (!is_object($ryform)) {
566 unset($url_params['validate']);
567 ryzom_redirect(_url($url_params, array('ryform_action' => '', 'message' => 'bad_paste')));
570 $is_valid = false;
571 p($def->params);
572 foreach ($def->params as $id => $ryform_class) {
573 if (is_array($ryform_class)) {
574 if (in_array(get_class($ryform), array_values($ryform_class)))
575 $is_valid = true;
576 } else if (get_class($ryform) == $ryform_class)
577 $is_valid = true;
579 if (!$is_valid) {
580 p(get_class($ryform), $def->params);
581 ryzom_redirect(_url($url_params, array($deffullname.'_action' => '', 'message' => 'not_valid_stage')));
582 return;
584 if (is_array($a_ryforms))
585 $a_ryforms[$ryform_pos] = $ryform;
586 else
587 $a_ryforms = $ryform;
588 $value = array($ryform_name => $a_ryforms);
589 return array(DATA_RYFORM_VALUE, $value);
591 return;
592 break;
595 return $ret;
598 function validateFormPost($params, $use_default=true) {
599 $final = array();
600 foreach ($this->defines as $def) {
601 $name = $def->name;
602 if ($def->name == 'name')
603 $def->name = '_name';
605 $type = $def->type;
606 if ($def->hidden)
607 $type = DEF_TYPE_HIDDEN;
609 if (isset($params[$def->name])) {
610 $value = $params[$def->name];
611 } else if (!$use_default) {
612 continue;
613 } else {
614 $value = '';
618 switch ($type) {
620 case DEF_TYPE_HIDDEN:
621 case DEF_TYPE_TEXT:
622 case DEF_TYPE_OPTION:
623 case DEF_TYPE_TEXTAREA:
624 $final[$name] = $value;
625 break;
627 case DEF_TYPE_TRAD:
628 if (!$value[_user()->lang] && $value['europeanunion'])
629 $value[_user()->lang] = $value['europeanunion'];
630 $final[$name] = $value;
631 break;
633 case DEF_TYPE_NAMEID:
634 $final[$name] = cleanNameID($value);
635 break;
637 case DEF_TYPE_COMBO:
638 $final[$name] = $value;
639 break;
641 case DEF_TYPE_ID:
642 case DEF_TYPE_INT: // TODO
643 $final[$name] = intval($value);
644 break;
645 case DEF_TYPE_FLOAT: // TODO
646 $final[$name] = floatval($value);
647 break;
649 case DEF_TYPE_BOOL:
650 $final[$name] = $value == 'on';
651 break;
653 case DEF_TYPE_RYFORM:
654 if (is_array($value))
655 $final[$name] = $value[0];
656 break;
657 case DEF_TYPE_RYFORMS_ARRAY:
658 break;
660 default:
661 $final[$name] = $value;
665 return $final;
669 function reset() {
671 // Clean all temp files
672 $userDatas = _tools()->listAppDataFiles($this->dir);
673 foreach ($userDatas as $userData) {
674 if (substr($userData, 0, strlen($this->name)) == $this->name)
675 _tools()->saveAppData($this->dir.'/'.$userData, NULL);