. */ include_once (RYAPI_PATH.'/common/ryformBases.php'); class ryVar extends basicRyForm { public $formName = ''; public $varName = ''; public $varValue = ''; function getFormDefs() { return array( new ryFormDef('varName', DEF_TYPE_TEXT), new ryFormDef('varValue', DEF_TYPE_TEXT), ); } function getHtmlRepr() { return $this->varName.' => '.$this->varValue; } } class ryForm { private $name = ''; private $defines = array(); private $template = ''; static private $forms; static private $ryformsIcons = array(); function __construct($dir, $name) { $this->name = $name; self::$forms[$dir.'/'.$name] = $this; } static function addRyFormIcon($ryform_name, $icon) { self::$ryformsIcons[$ryform_name] = $icon; } function addDefine($def) { $this->defines[$def->name] = $def; } function setTemplate($template) { $this->template = $template; } function getTemplate() { return $this->template; } function addValue($name, $value) { if (array_key_exists($name, $this->defines)) $this->defines[$name]->value = $value; else return false; return true; } function addExtraValues($name, $value) { if (array_key_exists($name, $this->defines)) $this->defines[$name]->extraValues = $value; else return false; return true; } function getForm($params) { if (isset($params['ryform_action']) && $params['ryform_action']) { $res = $this->doAction($params); return $res; } if (@$params['validate'] == $this->name) return array(DATA_FORM_VALUES, $_POST); if (isset($params['ryform_parent'])) $parent_ryform_name = $params['ryform_parent'].'/'; else $parent_ryform_name = ''; $action =_url(ryzom_get_params(), array('validate' => $this->name)); $ret = ''; $ret .= '
'."\n"; if (!$this->getTemplate()) { $ret .= ' '."\n"; $ret .= ' '._s('t header', '')."\n"; $tmpl = ''; } else { $tmpl = $this->getTemplate(); } $i = 0; foreach ($this->defines as $def_id => $def) { if ($def->name == 'name') $def->name = '_name'; $deffullname = $def->name; $url_params = ryzom_get_params(); $type = $def->type; $infos = $def->infos; $value = ($def->value !== NULL)?$def->value:$def->defaultValue; if (!is_object($value) && !is_array($value)) $str_value = _h(strval($value)); else $str_value = ''; if ($def->hidden) $type = DEF_TYPE_HIDDEN; $hidden = false; $input = ''; switch ($type) { case DEF_TYPE_HIDDEN: $input = ''."\n"; $hidden = true; break; case DEF_TYPE_TEXT: $input = ''; break; case DEF_TYPE_NAMEID: $input = ''; break; case DEF_TYPE_ID: case DEF_TYPE_INT: case DEF_TYPE_FLOAT: $input = ''; break; case DEF_TYPE_BOOL: $input = ''; break; case DEF_TYPE_OPTION_FUNCTION: case DEF_TYPE_OPTION: if ($type == DEF_TYPE_OPTION) $options = $def->params; else { if (is_array($def->defaultValue)) $options = call_user_func_array($def->params, $def->defaultValue); else $options = call_user_func($def->params); } $input = ''; break; case DEF_TYPE_COMBO_FUNCTION: case DEF_TYPE_COMBO: if ($type == DEF_TYPE_COMBO) $options = $def->params; else { if (is_array($def->defaultValue)) $options = call_user_func_array($def->params, $def->defaultValue); else $options = call_user_func($def->params); } if (_user()->ig) { // TODO : try to do it with lua } else { // HTML 4 $input .= ''; } break; case DEF_TYPE_TEXTAREA: if (!$value) $value = ""; $input = '
'.($type == DEF_TYPE_BBCODE?'- BBCode -
':'').'
'; break; case DEF_TYPE_TRAD: $base = ''; $param = $def->name; $value = array_merge(array('en' => '', 'fr' => '', 'de' => '', 'ru' => '', 'es' => ''), $value); $base = ryzom_get_param('select_base', ''); $edit = $display = $input_header = ''; foreach (array('en', 'fr', 'de', 'ru', 'es') as $lang) { if (_user()->lang == $lang) $edit = _i($lang == 'en'?API_URL.'data/img/lang/us.png':API_URL.'data/img/lang/'.$lang.'.png').' '; if ((!$base && $value[$lang]) || $base == $lang) { $base = $lang; $display = strtoupper($lang).' = '.str_replace("\n", '
', _h($value[$lang])).'
'; } $input .= ''; $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)).'  '; } $input = $input_header.$input.'   '.$display.'
'.$edit; break; case DEF_TYPE_RYFORM: case DEF_TYPE_RYFORMS_ARRAY: $savedRyform = $value; if (is_array($savedRyform)) { $to_clean = array(); foreach ($savedRyform as $id => $ryform) { if (!is_object($ryform)) $to_clean[] = $id; } foreach ($to_clean as $id) unset($savedRyform[$id]); $savedRyform = array_values($savedRyform); } else if (is_object($savedRyform)) { $savedRyform = array($savedRyform); } else $savedRyform = array(); $input .= '
'._t('parameter').''._t('value').'
'; if ($savedRyform) { foreach ($savedRyform as $id => $ryform) { if (!is_object($ryform)) { p('!!! ERROR !!!', $ryform); continue; } $ryform->id = $id+1; if (!isset($ryform->formName) || !$ryform->formName) $ryform->formName = 'Element '.$id; if (count($savedRyform) > 1) $display_id = ''.strval(intval($id)+1).''; else $display_id = ''; $script_up = ($id != 0)?_l(_i('16/arrow_up', _t('up')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'up')).' ':''; $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')).' ':''; $icon = (isset(self::$ryformsIcons[get_class($ryform)]))?self::$ryformsIcons[get_class($ryform)]:_i('32/brick'); $input .= _s('t row '.($id%2), ''. ''. ''); } } $input .= '
'._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.''.$script_up.$script_down.'
'.$icon.' '. _l($ryform->formName, $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'edit')).' '. '
'._t(get_class($ryform).'_short_description').'
'.$ryform->getHtmlRepr().'
'. _l(_i('16/script_edit', _t('edit')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'edit')).' '. _l(_i('16/script_code', _t('edit_source')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'source')).'      '. _l(_i('16/script_delete', _t('del')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'del')).' 
'; if (count($savedRyform) == 0 || $def->type != DEF_TYPE_RYFORM) { if (is_string($def->params)) $infos = _l(_i('16/add', _t('add')), $url_params, array('new_ryform' => $def->params, 'ryform_name' => $parent_ryform_name.$deffullname.':0', 'ryform_action' => 'add')); else if (count($def->params) == 1) $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')); else $infos = _l(_i('16/add', _t('add')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':0', 'ryform_action' => 'list')); if ($type == DEF_TYPE_RYFORMS_ARRAY) $infos .= '   '._l(_i('16/application_form_add', _t('multiadd')), $url_params, array('ryform_name' => $deffullname, 'ryform_action' => 'list_multiadd')); } break; case DEF_TYPE_FUNCTION: if (is_array($def->defaultValue)) list($result_type, $value) = call_user_func_array($def->params, $def->defaultValue); else list($result_type, $value) = call_user_func($def->params); if ($result_type == DATA_HTML_FORM) { return array(DATA_HTML_FORM, $value); } else { unset($url_params[$deffullname.'_action']); $input = $value; } break; default: $input = ''.$value."\n"; $hidden = true; } if ($hidden) $ret .= $input; else { if ($tmpl) { $tmpl = str_replace('{'.$def->name.'}', 'ig?'color="orange" size="11"':'style="color:orange;"').'>'._t($def->prefixTrad.$def->name).'', $tmpl); $tmpl = str_replace('{'.$def->name.'.input}', $input, $tmpl); $tmpl = str_replace('{'.$def->name.'.infos}', $infos, $tmpl); } else $ret .= _s('t row '.strval($i % 2), ' '.(!$def->optional?'*':'').($def->superAdmin?'##':'').($def->admin?'#':'')._t($def->prefixTrad.$def->name).''.$input.''.$infos.'')."\n"; $i++; } } if ($tmpl) { $tmpl = str_replace('{submit.input}', '', $tmpl); $ret .= $tmpl; $ret .= ''._s('t row '.strval($i % 2), '').'
     '._t('required_fields').'
'; } else { $ret .= _s('t row '.strval($i % 2), '     '._t('required_fields').''); $ret .= ''; } $ret .= '

'; return array(DATA_HTML_FORM, $ret."\n"); } function doAction($url_params) { if (!$url_params['ryform_name']) return array(DATA_RYFORM_VALUE, array()); $ret = ''; $ryforms = explode('/', $url_params['ryform_name']); $this_ryform_name = array_shift($ryforms); list($ryform_name,$ryform_pos) = explode(':', $this_ryform_name); if (!isset($this->defines[$ryform_name])) return 'Bad ryform name'; $def = $this->defines[$ryform_name]; if ($ryforms) { $action = 'edit'; $next_action = $url_params['ryform_action']; } else { $action = $url_params['ryform_action']; $next_action = ''; } switch ($action) { case 'list': if (isset($url_params['ryform_parent']) && $url_params['ryform_parent']) $ryform_parent = $url_params['ryform_parent'].'/'; else $ryform_parent = ''; $ret .= ''; foreach ($def->params as $id => $ryform) { if (is_array($ryform)) { $ret .= _s('t row 1', ''); foreach ($ryform as $subid => $subryform) { $ret .= _s('t row '.($subid%2), ''); } } else $ret .= _s('t row '.($id%2), ''); } $ret .= '
'.ryzom_font(_t('ryform_cat_'.$id), '', '12').''.self::$ryformsIcons[$subryform].'  '. _l(_t($subryform.'_short_description'), $url_params, array('ryform_name' => $ryform_parent.$url_params['ryform_name'], 'ryform_action' => 'add', 'new_ryform' => $subryform)).''.$subryform.''.self::$ryformsIcons[$ryform].'  '. _l(_t($ryform.'_short_description'), $url_params, array('ryform_name' => $ryform_parent.$url_params['ryform_name'], 'ryform_action' => 'add', 'new_ryform' => $ryform)).''.$ryform.'
'; return array(DATA_HTML_FORM, $ret); break; case 'list_multiadd': // TODO /* unset($url_params[$deffullname.'_action']); $ret .= ''; foreach ($def->params as $ryform) { $ret .= ''; } $ret .= '
'._l($ryform, $url_params, array('ryform_action' => 'multiadd', 'new_ryform' => $ryform)).'
'; return array(DATA_HTML_FORM, $ret);*/ break; case 'add': $new_ryform = ryzom_get_param('new_ryform'); $valid_ryform = false; if ($new_ryform) { if ((is_string($def->params) && $new_ryform == $def->params) || in_array($new_ryform, $def->params)) $valid_ryform = true; else { foreach ($def->params as $param) { if (is_array($param) && in_array($new_ryform, $param)) $valid_ryform = true; } } if (!$valid_ryform) return array(DATA_HTML_FORM, 'Bad ryform'); } else { $new_ryform = $def->params; } $ryform = new $new_ryform($new_ryform, ''); $ryform->preSerialization(); if ($def->type != DEF_TYPE_RYFORM) { p($def->value); if (!is_array($def->value)) $savedRyform = array($def->value); else $savedRyform = $def->value; if ($ryform_pos === 0) { $value = array_values(array_merge(array($ryform), $savedRyform)); } else if ($ryform_pos !== NULL) { $begin = array_slice($savedRyform, 0, $ryform_pos); $end = array_slice($savedRyform, $ryform_pos, count($savedRyform)-$ryform_pos); $value = array_values(array_merge($begin, array($ryform), $end)); } else $value[] = $ryform; p($ryform_name, $value); //return array(DATA_RYFORM_VALUE, array('stages' => array())); return array(DATA_RYFORM_VALUE, array($ryform_name => $value)); } else { p($ryform_name, $ryform); return array(DATA_RYFORM_VALUE, array($ryform_name => $ryform)); } break; case 'edit': $a_ryforms = $def->value; if (is_array($a_ryforms)) $ryform = $a_ryforms[$ryform_pos]; else $ryform = $a_ryforms; $ryform->postSerialization(); $validate = isset($url_params['validate']) && $url_params['validate']; $form = new ryForm('', $def->name); foreach ($ryform->getFormDefs() as $form_def) { $form->addDefine($form_def); $name = $form_def->name; // Init form with ryfom values if (property_exists($ryform, $name)) { $form->addValue($form_def->name, $ryform->$name); } } foreach ($ryform->getFormDefsExtraValues() as $def_name => $extra_values) $form->addExtraValues($def_name, $extra_values); $form->setTemplate($ryform->getTemplate()); 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)); if ($result_type == DATA_HTML_FORM) { return array(DATA_HTML_FORM, $value); } else { if ($result_type == DATA_FORM_VALUES) $value = $form->validateFormPost($value); $ryform->setFormParams($value); $ryform->preSerialization(); } if (is_array($a_ryforms)) $a_ryforms[$ryform_pos] = $ryform; else $a_ryforms = $ryform; $value = array($ryform_name => $a_ryforms); return array(DATA_RYFORM_VALUE, $value); break; case 'del': $id = $ryform_pos; p($def->value); if (!is_array($def->value)) $def->value = array(); else unset($def->value[$id]); $value = array_values($def->value); return array(DATA_RYFORM_VALUE, array($ryform_name => $value)); break; case 'up': $a_ryforms = $def->value; if (!is_array($a_ryforms)) ryzom_redirect(_url($url_params, array('ryform_action' => ''))); $temp_ryform = $a_ryforms[$ryform_pos-1]; $a_ryforms[$ryform_pos-1] = $a_ryforms[$ryform_pos]; $a_ryforms[$ryform_pos] = $temp_ryform; $a_ryforms = array_values($a_ryforms); p($ryform_name, $a_ryforms); return array(DATA_RYFORM_VALUE, array($ryform_name => $a_ryforms)); break; case 'down': $a_ryforms = $def->value; if (!is_array($a_ryforms)) ryzom_redirect(_url($url_params, array('ryform_action' => ''))); $temp_ryform = $a_ryforms[$ryform_pos+1]; $a_ryforms[$ryform_pos+1] = $a_ryforms[$ryform_pos]; $a_ryforms[$ryform_pos] = $temp_ryform; $a_ryforms = array_values($a_ryforms); return array(DATA_RYFORM_VALUE, array($ryform_name => $a_ryforms)); break; case 'source': $a_ryforms = $def->value; if (is_array($a_ryforms)) $ryform = $a_ryforms[$ryform_pos]; else $ryform = $a_ryforms; $ryform->postSerialization(); $form = new ryForm('', $def->name); $form->addDefine(new ryFormDef('ryform_source', DEF_TYPE_TEXTAREA, '', base64_encode(serialize($ryform)))); $validate = isset($url_params['validate']) && $url_params['validate']; list($result_type, $value) = $form->getForm(array('ryform_action' => $next_action, 'ryform_parent' => $this_ryform_name, 'ryform_name' => implode('/', $ryforms), 'validate' => $validate)); if ($result_type == DATA_HTML_FORM) { return array(DATA_HTML_FORM, $value); } else { if ($result_type == DATA_FORM_VALUES) $params = $form->validateFormPost($value); else $params = $value; $ryform = unserialize(base64_decode($params['ryform_source'])); if (!is_object($ryform)) { unset($url_params['validate']); ryzom_redirect(_url($url_params, array('ryform_action' => '', 'message' => 'bad_paste'))); } $is_valid = false; p($def->params); foreach ($def->params as $id => $ryform_class) { if (is_array($ryform_class)) { if (in_array(get_class($ryform), array_values($ryform_class))) $is_valid = true; } else if (get_class($ryform) == $ryform_class) $is_valid = true; } if (!$is_valid) { p(get_class($ryform), $def->params); ryzom_redirect(_url($url_params, array($deffullname.'_action' => '', 'message' => 'not_valid_stage'))); return; } if (is_array($a_ryforms)) $a_ryforms[$ryform_pos] = $ryform; else $a_ryforms = $ryform; $value = array($ryform_name => $a_ryforms); return array(DATA_RYFORM_VALUE, $value); } return; break; } return $ret; } function validateFormPost($params, $use_default=true) { $final = array(); foreach ($this->defines as $def) { $name = $def->name; if ($def->name == 'name') $def->name = '_name'; $type = $def->type; if ($def->hidden) $type = DEF_TYPE_HIDDEN; if (isset($params[$def->name])) { $value = $params[$def->name]; } else if (!$use_default) { continue; } else { $value = ''; } switch ($type) { case DEF_TYPE_HIDDEN: case DEF_TYPE_TEXT: case DEF_TYPE_OPTION: case DEF_TYPE_TEXTAREA: $final[$name] = $value; break; case DEF_TYPE_TRAD: if (!$value[_user()->lang] && $value['europeanunion']) $value[_user()->lang] = $value['europeanunion']; $final[$name] = $value; break; case DEF_TYPE_NAMEID: $final[$name] = cleanNameID($value); break; case DEF_TYPE_COMBO: $final[$name] = $value; break; case DEF_TYPE_ID: case DEF_TYPE_INT: // TODO $final[$name] = intval($value); break; case DEF_TYPE_FLOAT: // TODO $final[$name] = floatval($value); break; case DEF_TYPE_BOOL: $final[$name] = $value == 'on'; break; case DEF_TYPE_RYFORM: if (is_array($value)) $final[$name] = $value[0]; break; case DEF_TYPE_RYFORMS_ARRAY: break; default: $final[$name] = $value; } } return $final; } /* function reset() { // Clean all temp files $userDatas = _tools()->listAppDataFiles($this->dir); foreach ($userDatas as $userData) { if (substr($userData, 0, strlen($this->name)) == $this->name) _tools()->saveAppData($this->dir.'/'.$userData, NULL); } }*/ } ?>