/** * Update attribute type * * On error this method returning FALSE. * * Possible options: * - none * * @param Attr_type $at * @param string $old_name Old name of attribute. If is set, attr. type is updated otherwise is created new * @param array $opt Array of options * @return bool */ function update_attr_type($at, $old_name, $opt) { global $config; $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return false; } /* table's name */ $t_name =& $config->data_sql->attr_types->table_name; /* col names */ $c =& $config->data_sql->attr_types->cols; if (is_null($old_name)) { $q = "insert into " . $t_name . "(\n\t\t\t " . $c->name . ", \n\t\t\t\t\t\t " . $c->rich_type . ", \n\t\t\t\t\t\t " . $c->raw_type . ", \n\t\t\t\t\t\t " . $c->type_spec . ", \n\t\t\t\t\t\t " . $c->desc . ", \n\t\t\t\t\t\t " . $c->default_flags . ", \n\t\t\t\t\t\t " . $c->flags . ", \n\t\t\t\t\t\t " . $c->priority . ", \n\t\t\t\t\t\t " . $c->access . ", \n\t\t\t\t\t\t " . $c->group . ", \n\t\t\t\t\t\t " . $c->order . ")\n\t\t\t values (" . $this->sql_format($at->get_name(), "s") . ", \n\t\t\t\t " . $this->sql_format($at->get_type(), "s") . ", \n\t\t\t\t\t\t " . $this->sql_format($at->get_raw_type(), "n") . ", \n\t\t\t\t\t\t " . $this->sql_format(serialize($at->get_type_spec()), "s") . ", \n\t\t\t\t\t\t " . $this->sql_format($at->get_raw_description(), "s") . ", \n\t\t\t\t\t\t " . $this->sql_format($at->get_default_flags(), "n") . ", \n\t\t\t\t\t\t " . $this->sql_format($at->get_flags(), "n") . ", \n\t\t\t\t\t\t " . $this->sql_format($at->get_priority(), "n") . ", \n\t\t\t\t\t\t " . $this->sql_format($at->get_access(), "n") . ", \n\t\t\t\t\t\t " . $this->sql_format($at->get_group(), "s") . ", \n\t\t\t\t\t\t " . $this->sql_format($at->get_order(), "n") . ")"; } else { $q = "update " . $t_name . " \n\t\t\t set " . $c->name . " = " . $this->sql_format($at->get_name(), "s") . ",\n\t\t\t " . $c->rich_type . " = " . $this->sql_format($at->get_type(), "s") . ",\n\t\t\t " . $c->raw_type . " = " . $this->sql_format($at->get_raw_type(), "n") . ",\n\t\t\t " . $c->type_spec . " = " . $this->sql_format(serialize($at->get_type_spec()), "s") . ",\n\t\t\t " . $c->desc . " = " . $this->sql_format($at->get_raw_description(), "s") . ",\n\t\t\t " . $c->default_flags . " = " . $this->sql_format($at->get_default_flags(), "n") . ",\n\t\t\t " . $c->flags . " = " . $this->sql_format($at->get_flags(), "n") . ",\n\t\t\t " . $c->priority . " = " . $this->sql_format($at->get_priority(), "n") . ",\n\t\t\t " . $c->access . " = " . $this->sql_format($at->get_access(), "n") . ",\n\t\t\t " . $c->group . " = " . $this->sql_format($at->get_group(), "s") . ",\n\t\t\t " . $c->order . " = " . $this->sql_format($at->get_order(), "n") . "\n\t\t\t where " . $c->name . " = " . $this->sql_format($old_name, "s"); } $res = $this->db->query($q); if (DB::isError($res)) { ErrorHandler::log_errors($res); return false; } return true; }
/** * create html form * * @param array $errors array with error messages * @return null FALSE on failure */ function create_html_form(&$errors) { global $lang_str, $sess; parent::create_html_form($errors); /* get list of attributes */ $this->attrs =& Attr_types::singleton(); if (false === ($at = $this->attrs->get_attr_types())) { return false; } if (false === ($grp = $this->attrs->get_attr_groups())) { return false; } $this->attr_groups = $grp; $grp[] = array("label" => "< " . $lang_str['attr_grp_create_new'] . " >", "value" => "__new__"); $grp_cnt = count($grp) - 1; /* default values for form elements */ if ($this->edit_id and isset($at[$this->edit_id])) { $atr =& $at[$this->edit_id]; } else { $atr = new Attr_type("", 2, "string", "", "", 0, 0, 0, 0, 0); } $this->f->add_element(array("type" => "text", "name" => "attr_name", "size" => 16, "maxlength" => 32, "value" => $atr->get_name(), "minlength" => 1, "length_e" => $lang_str['fe_not_filled_name_of_attribute'])); $this->f->add_element(array("type" => "select", "name" => "attr_type", "size" => 1, "options" => Attr_types::get_all_types(), "value" => $atr->get_type())); $this->f->add_element(array("type" => "text", "name" => "attr_order", "size" => 16, "maxlength" => 5, "value" => $atr->get_order(), "valid_regex" => "^[0-9]+\$", "valid_e" => $lang_str['fe_order_is_not_number'])); $this->f->add_element(array("type" => "text", "name" => "attr_label", "size" => 16, "maxlength" => 255, "value" => $atr->get_raw_description())); $this->f->add_element(array("type" => "select", "name" => "attr_access", "size" => 1, "options" => $atr->get_access_options(), "value" => $atr->get_access())); $this->f->add_element(array("type" => "select", "name" => "attr_group", "size" => 1, "options" => $grp, "value" => $atr->get_group(), "extrahtml" => "onchange='if (this.selectedIndex==" . $grp_cnt . "){this.form.attr_new_group.disabled=false; this.form.attr_new_group.focus();}else{this.form.attr_new_group.disabled=true;}'")); $this->f->add_element(array("type" => "text", "name" => "attr_new_group", "size" => 16, "value" => "", "disabled" => true)); $this->f->add_element(array("type" => "checkbox", "name" => "for_ser", "value" => "1", "checked" => $atr->is_for_ser())); $this->f->add_element(array("type" => "checkbox", "name" => "for_serweb", "value" => "1", "checked" => $atr->is_for_serweb())); $this->f->add_element(array("type" => "checkbox", "name" => "pr_uri", "value" => "1", "checked" => $atr->is_for_URIs())); $this->f->add_element(array("type" => "checkbox", "name" => "pr_user", "value" => "1", "checked" => $atr->is_for_users())); $this->f->add_element(array("type" => "checkbox", "name" => "pr_domain", "value" => "1", "checked" => $atr->is_for_domains())); $this->f->add_element(array("type" => "checkbox", "name" => "pr_global", "value" => "1", "checked" => $atr->is_for_globals())); $this->f->add_element(array("type" => "checkbox", "name" => "multivalue", "value" => "1", "checked" => $atr->is_multivalue())); $this->f->add_element(array("type" => "checkbox", "name" => "registration", "value" => "1", "checked" => $atr->fill_on_register())); $this->f->add_element(array("type" => "checkbox", "name" => "required", "value" => "1", "checked" => $atr->is_required())); $this->f->add_element(array("type" => "hidden", "name" => "edit_id", "value" => $this->edit_id)); if ($atr->apu_edit()) { $this->f->add_extra_submit('extended_settings', $this->opt['form_submit_extended']); } /* Instantiate page controler object */ $onload_js = "\n var at_ctl;\n at_ctl = new Attr_types_ctl('at_ctl', " . my_JSON_encode($lang_str) . ", '" . js_escape($sess->url($_SERVER['PHP_SELF'] . "?kvrk=" . uniqID("") . "&rename_group=1")) . "');"; $this->controler->set_onload_js($onload_js); }