Esempio n. 1
0
    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 .= '<form action="' . $action . '" method="POST">' . "\n";
        if (!$this->getTemplate()) {
            $ret .= '	<table width="100%" cellpadding="0" cellspacing="0">' . "\n";
            $ret .= '	' . _s('t header', '<td height="24px">' . _t('parameter') . '</td><td>' . _t('value') . '</td><td></td>') . "\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 = '<input type="hidden" name="' . $def->name . '" value="' . $str_value . '" />' . "\n";
                    $hidden = true;
                    break;
                case DEF_TYPE_TEXT:
                    $input = '<input style="width:250px" type="text" name="' . $def->name . '" value="' . $str_value . '" size="25' . (_user()->ig ? '0' : '') . '" />';
                    break;
                case DEF_TYPE_NAMEID:
                    $input = '<input style="width:250px" type="text" name="' . $def->name . '" value="' . getNameId($str_value) . '" size="25' . (_user()->ig ? '0' : '') . '" />';
                    break;
                case DEF_TYPE_ID:
                case DEF_TYPE_INT:
                case DEF_TYPE_FLOAT:
                    $input = '<input style="width:100px"  type="text" name="' . $def->name . '" value="' . $str_value . '" size="10' . (_user()->ig ? '0' : '') . '" />';
                    break;
                case DEF_TYPE_BOOL:
                    $input = '<select name="' . $def->name . '">' . "\n";
                    if ($value) {
                        $input .= '<option selected="selected" value="on">' . _t('yes') . '</option>' . "\n" . '<option value="off">' . _t('no') . '</option>';
                    } else {
                        $input .= '<option value="on">' . _t('yes') . '</option>' . "\n" . '<option selected="selected" value="off">' . _t('no') . '</option>';
                    }
                    $input .= '</select>';
                    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 = '<select name="' . $def->name . '">' . "\n";
                    $options_html = '';
                    foreach ($options as $option => $text) {
                        $option = strval($option);
                        if ($option && $option[0] === '<' && $option[1] === '/') {
                            $options_html .= '</optgroup>';
                        } else {
                            if ($option && $option[0] === '<') {
                                $options_html .= '<optgroup label="' . $text . '">';
                            } else {
                                if ($value !== NULL and strval($value) == $option) {
                                    $options_html .= '<option selected="selected" value="' . $option . '">' . $text . '</option>' . "\n";
                                } else {
                                    $options_html .= '<option value="' . $option . '">' . $text . '</option>' . "\n";
                                }
                            }
                        }
                    }
                    $input .= $options_html;
                    $input .= '</select>';
                    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 .= '<input style="width:400px"  type="text" id="' . $def->name . '" name="' . $def->name . '"  value="' . $str_value . '" />
							<select onChange="combo(this, \'' . $def->name . '\')" onMouseOut="comboInit(this, \'' . $def->name . '\')" >';
                        $options_html = '';
                        $have_selected = false;
                        foreach ($options as $option => $text) {
                            if ($option && $option[0] === '<' && $option[1] === '/') {
                                $options_html .= '</optgroup>';
                            } else {
                                if ($option && $option[0] === '<') {
                                    $options_html .= '<optgroup label="' . $text . '">';
                                } else {
                                    if ($value and $value == $option) {
                                        $have_selected = true;
                                        $options_html .= '<option selected="selected" value="' . $option . '">' . $text . '</option>' . "\n";
                                    } else {
                                        $options_html .= '<option value="' . $option . '">' . $text . '</option>' . "\n";
                                    }
                                }
                            }
                        }
                        if ($have_selected) {
                            $input .= '<option value=""></option>';
                        } else {
                            $input .= '<option selected="selected"  value=""></option>';
                        }
                        $input .= $options_html;
                        $input .= '</select>';
                    }
                    break;
                case DEF_TYPE_TEXTAREA:
                    if (!$value) {
                        $value = "";
                    }
                    $input = '<pre>' . ($type == DEF_TYPE_BBCODE ? '<font color="orange">- BBCode -</font><br />' : '') . '<textarea name="' . $def->name . '" rows="3">' . _h($value) . '</textarea></pre>';
                    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') . ' <textarea style="width: 90%" rows="3" name="' . $param . '[' . $lang . ']">' . _h($value[$lang]) . '</textarea>';
                        }
                        if (!$base && $value[$lang] || $base == $lang) {
                            $base = $lang;
                            $display = strtoupper($lang) . ' = <font color="orange">' . str_replace("\n", '<br />', _h($value[$lang])) . '</font>';
                        }
                        $input .= '<input type="hidden" name="' . $param . '[' . $lang . ']" value="' . $value[$lang] . '" />';
                        $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;';
                    }
                    $input = $input_header . $input . ' &nbsp; ' . $display . '<br />' . $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 .= '<table width="100%" cellspacing="0" cellpadding="0" >';
                    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 = '<font size="12px" style="font-weight: bold; font-size: 14px" color="#FFAA55">' . strval(intval($id) + 1) . '</font>';
                            } 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, '<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>' . '<td width="10px">' . $script_up . $script_down . '</td>' . '<td ><table width="100%"><tr>
										<td width="40px">' . $icon . '</td>
										<td valign="middle" width="300px"><font size="12px" style="font-size: 13px;font-weight: bold;"  color="#FFAA55">' . _l($ryform->formName, $url_params, array('ryform_name' => $parent_ryform_name . $deffullname . ':' . $id, 'ryform_action' => 'edit')) . ' ' . '</font><br />' . _t(get_class($ryform) . '_short_description') . '</td>
										<td align="left" valign="middle" bgcolor="#000000">' . $ryform->getHtmlRepr() . '</td>
									</tr></table><td width="70px" align="right">' . _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')) . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . _l(_i('16/script_delete', _t('del')), $url_params, array('ryform_name' => $parent_ryform_name . $deffullname . ':' . $id, 'ryform_action' => 'del')) . '</td><td>&nbsp;</td>');
                        }
                    }
                    $input .= '</table>';
                    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 .= '&nbsp;&nbsp;&nbsp;' . _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 = '<input type="hidden" name="' . $def->name . '" value="' . $value . '" />' . $value . "\n";
                    $hidden = true;
            }
            if ($hidden) {
                $ret .= $input;
            } else {
                if ($tmpl) {
                    $tmpl = str_replace('{' . $def->name . '}', '<font ' . (_user()->ig ? 'color="orange" size="11"' : 'style="color:orange;"') . '>' . _t($def->prefixTrad . $def->name) . '</font>', $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), '<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";
                }
                $i++;
            }
        }
        if ($tmpl) {
            $tmpl = str_replace('{submit.input}', '<input type="submit" value="' . _t('submit') . '" />', $tmpl);
            $ret .= $tmpl;
            $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>';
        } else {
            $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>');
            $ret .= '</table>';
        }
        $ret .= '</form><br />';
        return array(DATA_HTML_FORM, $ret . "\n");
    }
Esempio n. 2
0
function callAction($action)
{
    $c = '';
    ryActionPage::call($action, ryzom_get_params());
    $msgs = ryActionPage::getMSGs();
    foreach ($msgs as $msg) {
        if ($msg[0] == 'HEADER') {
            $c .= $msg[1];
        }
    }
    foreach ($msgs as $msg) {
        if ($msg[0] == 'ERR') {
            $c .= _s('message error', $msg[1]);
        } else {
            if ($msg[0] == 'MSG') {
                $c .= _s('message', $msg[1]);
            } else {
                if ($msg[0] == 'WARNING') {
                    $c .= _s('message warning', $msg[1]);
                } else {
                    if ($msg[0] != 'HEADER') {
                        $c .= $msg[1];
                    }
                }
            }
        }
    }
    return $c;
}