/**
  *  Get values of global attributes
  *
  *	On error this method returning FALSE.
  *
  *  Possible options:
  *	 - none
  *
  *	@return array
  */
 function get_global_attrs($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->global_attrs->table_name;
     /* col names */
     $c =& $config->data_sql->global_attrs->cols;
     /* flags */
     $f =& $config->data_sql->global_attrs->flag_values;
     $out = array();
     $errors = array();
     /*
      *	get global_attrs
      */
     $flags_val = $f['DB_FOR_SERWEB'];
     $q = "select " . $c->name . " as name,\n\t\t           " . $c->value . " as value \n\t\t    from " . $t_name . "\n\t\t\twhere (" . $c->flags . " & " . $flags_val . ") = " . $flags_val;
     if (isset($c->order)) {
         $q .= " order by " . $c->name . ", " . $c->order;
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         ErrorHandler::add_error($errors);
         return false;
     }
     $ats =& Attr_types::singleton();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         if (false === ($at =& $ats->get_attr_type($row['name']))) {
             return false;
         }
         if (is_object($at) and $at->is_multivalue()) {
             $out[$row['name']][] = $row['value'];
         } else {
             $out[$row['name']] = $row['value'];
         }
     }
     $res->free();
     return $out;
 }
 function export_to_xml($dtdfile = "")
 {
     $at_h =& Attr_types::singleton();
     if (false === ($attr_types = $at_h->get_attr_types())) {
         return false;
     }
     Header("Content-Disposition: attachment;filename=" . RawURLEncode("attr-types-" . date("Y-m-d") . ".xml"));
     header("Content-type: text/xml");
     echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?" . ">\n";
     if ($dtdfile) {
         echo "<!DOCTYPE attr_types SYSTEM \"" . $dtdfile . "\">\n";
     }
     echo "<attr_types>\n";
     foreach ($attr_types as $at) {
         echo $this->at_to_xml($at);
     }
     echo "</attr_types>\n";
     return true;
 }
 /**
  *  Update value of uri attribute
  *
  *	On error this method returning FALSE.
  *
  *  Possible options:
  *	 - old_value - old value of attribute. If not is set the attribute is 
  *	   inserted instead of updated.
  *
  *	@return bool
  */
 function update_uri_attr($scheme, $username, $did, $name, $value, $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->uri_attrs->table_name;
     /* col names */
     $c =& $config->data_sql->uri_attrs->cols;
     /* flags */
     $f =& $config->data_sql->uri_attrs->flag_values;
     $ats =& Attr_types::singleton();
     if (false === ($at =& $ats->get_attr_type($name))) {
         return false;
     }
     $type = $flags = 0;
     if (is_object($at)) {
         $type = $at->get_raw_type();
         $flags = $at->get_default_flags();
     }
     if (is_object($at) and $at->is_multivalue()) {
         if (!isset($opt['old_value'])) {
             $opt['old_value'] = array();
         }
         $q = "delete from " . $t_name . " \n\t\t\t      where " . $c->scheme . "   = " . $this->sql_format($scheme, "s") . " and \n\t\t\t\t        " . $c->name . "     = " . $this->sql_format($name, "s") . " and \n\t\t\t\t        " . $c->username . " = " . $this->sql_format($username, "s") . " and \n\t\t\t\t\t\t" . $c->did . "      = " . $this->sql_format($did, "s");
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             ErrorHandler::log_errors($res);
             return false;
         }
         $ion = isset($c->order) ? ", " . $c->order : "";
         $iov = 0;
         foreach ($value as $v) {
             $q = "insert into " . $t_name . "(\n\t\t\t\t             " . $c->scheme . ", " . $c->username . ", " . $c->did . ", " . $c->name . ", " . $c->value . ", " . $c->type . ", " . $c->flags . $ion . ")\n\t\t\t\t      values (" . $this->sql_format($scheme, "s") . ", \n\t\t\t\t\t          " . $this->sql_format($username, "s") . ", \n\t\t\t\t\t\t\t  " . $this->sql_format($did, "s") . ", \n\t\t\t\t\t          " . $this->sql_format($name, "s") . ", \n\t\t\t\t\t\t\t  " . $this->sql_format($v, "s") . ", \n\t\t\t\t\t\t\t  " . $this->sql_format($type, "n") . ", \n\t\t\t\t\t\t\t  " . $this->sql_format($flags, "n") . (isset($c->order) ? ", " . $iov++ : "") . ")";
             $res = $this->db->query($q);
             if (DB::isError($res)) {
                 ErrorHandler::log_errors($res);
                 return false;
             }
         }
     } else {
         if (!isset($opt['old_value'])) {
             $ion = isset($c->order) ? ", " . $c->order : "";
             $iov = isset($c->order) ? ", 0" : "";
             $q = "insert into " . $t_name . "(\n\t\t\t\t             " . $c->scheme . ", " . $c->username . ", " . $c->did . ", " . $c->name . ", " . $c->value . ", " . $c->type . ", " . $c->flags . $ion . ")\n\t\t\t\t      values (" . $this->sql_format($scheme, "s") . ", \n\t\t\t\t\t          " . $this->sql_format($username, "s") . ", \n\t\t\t\t\t\t\t  " . $this->sql_format($did, "s") . ", \n\t\t\t\t\t          " . $this->sql_format($name, "s") . ", \n\t\t\t\t\t\t\t  " . $this->sql_format($value, "s") . ", \n\t\t\t\t\t\t\t  " . $this->sql_format($type, "n") . ", \n\t\t\t\t\t\t\t  " . $this->sql_format($flags, "n") . $iov . ")";
         } elseif ($opt['old_value'] == $value) {
             /* don't need update DB */
             return true;
         } else {
             if ($value === "") {
                 $q = "delete from " . $t_name . " \n\t\t\t\t\t      where " . $c->scheme . "   = " . $this->sql_format($scheme, "s") . " and \n\t\t\t\t\t            " . $c->name . "     = " . $this->sql_format($name, "s") . " and \n\t\t\t\t\t\t\t\t" . $c->username . " = " . $this->sql_format($username, "s") . " and \n\t\t\t\t\t\t\t    " . $c->did . "      = " . $this->sql_format($did, "s");
             } else {
                 $q = "update " . $t_name . " \n\t\t\t\t\t      set " . $c->value . "      = " . $this->sql_format($value, "s") . "\n\t\t\t\t\t      where " . $c->scheme . "   = " . $this->sql_format($scheme, "s") . " and \n\t\t\t\t\t            " . $c->name . "     = " . $this->sql_format($name, "s") . " and \n\t\t\t\t\t\t\t\t" . $c->username . " = " . $this->sql_format($username, "s") . " and \n\t\t\t\t\t\t        " . $c->did . "      = " . $this->sql_format($did, "s");
             }
         }
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             ErrorHandler::log_errors($res);
             return false;
         }
     }
     return true;
 }
 function add_attrs_to_form()
 {
     //get attribute types
     $attr_types =& Attr_types::singleton();
     if (false === ($this->attr_types =& $attr_types->get_attr_types())) {
         return false;
     }
     //get list of attributes
     $this->attributes = array();
     foreach ($this->attr_types as $k => $v) {
         if ($v->fill_on_register()) {
             $this->attributes[] = $k;
         }
     }
     $opt = array();
     $opt['get_values'] = true;
     if (!is_null($this->opt['register_in_domain'])) {
         $opt['did'] = $this->opt['register_in_domain'];
     }
     if (false === Attributes::attrs_to_form($this->attributes, $this->f, $this->js_before, $this->js_after, $opt)) {
         return false;
     }
     $this->attr_values = $opt['attr_values'];
     return true;
 }
Beispiel #5
0
 function set_attribute($name, $value)
 {
     /* get attributes in order to know if attribute shuld be inserted or updated */
     if (false === $this->get_attributes()) {
         return false;
     }
     if (false === $this->save_attr($name, $value)) {
         return false;
     }
     $this->attributes[$name] = $value;
     /* call on_update method of attribute */
     $attr_types =& Attr_types::singleton();
     if (false === ($att =& $attr_types->get_attr_type($name))) {
         return false;
     }
     if (is_object($att) and false === $att->on_update($value)) {
         return false;
     }
     return true;
 }
 /**
  *	Method perform action default
  *
  *	@param array $errors	array with error messages
  *	@return array			return array of $_GET params fo redirect or FALSE on failure
  */
 function action_default(&$errors)
 {
     //get list of all atributes which could be displayed on tihis page
     $avail_attrs = $this->apu_attrs->get_all_avaiable_attributes();
     $at =& Attr_types::singleton();
     if (false === ($grps = $at->get_attr_groups())) {
         return false;
     }
     if (false === ($types = $at->get_attr_types())) {
         return false;
     }
     //make list of not empty groups
     $avail_grps = array();
     foreach ($avail_attrs as $attr) {
         $avail_grps[$types[$attr]->get_group()] = true;
     }
     $tabs = array();
     foreach ($grps as $k => $v) {
         //skip group with no attributes
         if (empty($avail_grps[$v])) {
             continue;
         }
         $page = $_SERVER['PHP_SELF'] . "?attr_grp=" . RawURLEncode($v);
         $label = $at->get_attr_group_label($v);
         $tabs[] = new Ctab(true, $label, $page);
         if ($v == $this->session['selected_grp']) {
             $this->selected_grp['tab'] = $page;
         }
     }
     $this->selected_grp['grp'] = $this->session['selected_grp'];
     $this->tabs =& $tabs;
     return true;
 }
 function create_html_form(&$errors)
 {
     global $data, $config;
     parent::create_html_form($errors);
     $attr_types =& Attr_types::singleton();
     //get list of attributes
     if (false === ($this->attr_types =& $attr_types->get_attr_types())) {
         return false;
     }
     switch ($this->opt['attrs_kind']) {
         case "uri":
             // get uri_attrs
             $this->uri_attrs =& Uri_Attrs::singleton($this->uri_scheme, $this->uri_uname, $this->uri_did);
             if (false === ($uri_attrs = $this->uri_attrs->get_attributes())) {
                 return false;
             }
         case "user":
             // get user_attrs
             $this->user_attrs =& User_Attrs::singleton($this->uid);
             if (false === ($user_attrs = $this->user_attrs->get_attributes())) {
                 return false;
             }
         case "domain":
             // get domain_attrs
             $this->domain_attrs =& Domain_Attrs::singleton($this->did);
             if (false === ($domain_attrs = $this->domain_attrs->get_attributes())) {
                 return false;
             }
         case "global":
             // get global_attrs
             $this->global_attrs =& Global_Attrs::singleton();
             if (false === ($global_attrs = $this->global_attrs->get_attributes())) {
                 return false;
             }
     }
     $this->attr_values = array();
     foreach ($this->attr_types as $k => $v) {
         if ($this->opt['attrs_kind'] == 'uri' and !$this->attr_types[$k]->is_for_URIs()) {
             continue;
         } elseif ($this->opt['attrs_kind'] == 'user' and !$this->attr_types[$k]->is_for_users()) {
             continue;
         } elseif ($this->opt['attrs_kind'] == 'domain' and !$this->attr_types[$k]->is_for_domains()) {
             continue;
         } elseif ($this->opt['attrs_kind'] == 'global' and !$this->attr_types[$k]->is_for_globals()) {
             continue;
         }
         switch ($this->opt['attrs_kind']) {
             case "uri":
                 if (isset($uri_attrs[$k])) {
                     $this->attr_values[$k] = $uri_attrs[$k];
                     break;
                 }
             case "user":
                 if (isset($user_attrs[$k])) {
                     $this->attr_values[$k] = $user_attrs[$k];
                     break;
                 }
             case "domain":
                 if (isset($domain_attrs[$k])) {
                     $this->attr_values[$k] = $domain_attrs[$k];
                     break;
                 }
             case "global":
                 if (isset($global_attrs[$k])) {
                     $this->attr_values[$k] = $global_attrs[$k];
                     break;
                 }
         }
         /*
          *	If the value of attribute is not found, set it as null
          */
         if (!isset($this->attr_values[$k])) {
             $this->attr_values[$k] = null;
         }
     }
     // if option 'atributes' is not given, that mean we will work with all attributes
     if (empty($this->opt['attributes'])) {
         foreach ($this->attr_values as $k => $v) {
             // work only with attributes which have access to read
             if ($this->access_to_read($k)) {
                 $this->opt['attributes'][] = $k;
             }
         }
     } else {
         foreach ($this->opt['attributes'] as $k => $v) {
             if (!array_key_exists($v, $this->attr_values)) {
                 log_errors(PEAR::RaiseError("Attribute named '" . $v . "' does not exists"), $errors);
                 unset($this->opt['attributes'][$k]);
             }
         }
     }
     //except unwanted arguments
     $this->opt['attributes'] = array_diff($this->opt['attributes'], $this->opt['exclude_attributes']);
     //save avaiable attrs before are filtered by group
     $this->all_avaiable_attrs = $this->opt['attributes'];
     if (!empty($this->opt['attrs_group'])) {
         foreach ($this->opt['attributes'] as $k => $v) {
             // work only with attributes from specified group
             if ($this->attr_types[$v]->get_group() != $this->opt['attrs_group']) {
                 unset($this->opt['attributes'][$k]);
             }
         }
     }
     //set options to attributes
     foreach ($this->opt['attributes'] as $att) {
         if (isset($this->opt['attrs_options'][$att]) and is_array($this->opt['attrs_options'][$att])) {
             foreach ($this->opt['attrs_options'][$att] as $k => $v) {
                 $this->attr_types[$att]->set_opt($k, $v);
             }
         }
     }
     // add elements to form object
     foreach ($this->opt['attributes'] as $att) {
         if (!$this->access_to_change($att)) {
             continue;
         }
         //if attribute cannot be changed, do not add it ot the form
         $opt = array();
         $opt['err_msg'] = isset($this->opt['error_messages'][$att]) ? $this->opt['error_messages'][$att] : null;
         $this->attr_types[$att]->form_element($this->f, $this->attr_values[$att], $opt);
         $this->js_on_subm .= $this->attr_types[$att]->validation_js_before();
         $this->js_on_subm_2 .= $this->attr_types[$att]->validation_js_after();
     }
     if (!empty($this->opt['validate_js_funct'])) {
         $this->js_on_subm_2 .= $this->opt['validate_js_funct'];
     }
 }
$page_attributes['selected_tab'] = "attr_types.php";
/*
 *	Get name of attribute 
 */
if (isset($_GET['attrib_name'])) {
    $attr_name = $_GET['attrib_name'];
} else {
    $attr_name = $_SESSION['edit_type_spec']['attrib_name'];
}
if (!$attr_name) {
    die("Internal error - unknown attribute name");
}
/*
 *	Get type of attribute
 */
$attrs =& Attr_types::singleton();
if (false === ($at = $attrs->get_attr_type($attr_name))) {
    die("Internal error - can't get type of attribute");
}
if (is_null($at)) {
    die("Internal error - unknown attribute");
}
/*
 *	Get name of APU for edit 'type_spec'
 */
$apu_name = $at->apu_edit();
if (!$apu_name) {
    die("Internal error - unknown APU");
}
/*
 *	Load apu
 /**
  *	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);
 }
 /**
  *  Method perform action import
  *
  *  @param array $errors    array with error messages
  *  @return array           return array of $_GET params fo redirect or FALSE on failure
  */
 function action_import(&$errors)
 {
     global $data;
     $import_obj = new attr_types_import();
     $result = $import_obj->setInputFile($_FILES['at_file']['tmp_name']);
     if (PEAR::isError($result)) {
         ErrorHandler::log_errors($result);
         return false;
     }
     $result = $import_obj->parse();
     if (PEAR::isError($result)) {
         ErrorHandler::log_errors($result);
         return false;
     }
     if ($err = $import_obj->get_errors()) {
         ErrorHandler::add_error($err);
         return false;
     }
     $new_at = $import_obj->get_attr_types();
     $at_h =& Attr_types::singleton();
     if (false === ($current_at = $at_h->get_attr_types())) {
         return false;
     }
     $current_at_names = array_keys($current_at);
     if (!empty($_POST['at_purge'])) {
         /* purge old attribute types */
         foreach ($current_at_names as $v) {
             if (false === $data->del_attr_type($v, null)) {
                 return false;
             }
         }
     }
     foreach ($new_at as $v) {
         if (empty($_POST['at_purge']) and in_array($v->get_name(), $current_at_names)) {
             /* if current attribute already exists */
             if ($_POST['at_exists'] == "update") {
                 if (false === $data->del_attr_type($v->get_name(), null)) {
                     return false;
                 }
             } else {
                 continue;
             }
         }
         /* store attr type to DB */
         if (false === $data->update_attr_type($v, null, null)) {
             return false;
         }
     }
     if ($this->opt['redirect_on_import']) {
         $this->controler->change_url_for_reload($this->opt['redirect_on_import']);
     }
     $get = array('at_imported=' . RawURLEncode($this->opt['instance_id']));
     return $get;
 }
Beispiel #11
0
 function action_login(&$errors)
 {
     global $lang_str, $config;
     unset($_SESSION['auth']);
     // set cookie only if not doing http redirect because
     // $_POST['remember_uname'] is not set during redirect
     if (!isset($_GET["redir_id"])) {
         if (isset($_POST['remember_uname']) and $_POST['remember_uname']) {
             setcookie('serwebuser', $_POST['uname'], time() + 31536000, null, $this->opt['cookie_domain']);
         } else {
             setcookie('serwebuser', '', time(), null, $this->opt['cookie_domain']);
         }
         //delete cookie
     }
     if (isModuleLoaded('xxl') and $this->opt['xxl_redirect_after_login']) {
         xxl_http_redirect(array("get_params" => array("uname" => $this->username, "realm" => $this->realm, "pass" => $this->password, "redir_id" => $this->opt['instance_id'])));
     }
     $_SESSION['auth'] = new $this->opt['auth_class']();
     $_SESSION['auth']->authenticate_as($this->uid, $this->username, $this->did, $this->realm);
     if (is_array($this->perms)) {
         $_SESSION['auth']->set_perms($this->perms);
     }
     sw_log("User login: redirecting to page: " . $this->opt['redirect_on_login'], PEAR_LOG_DEBUG);
     $this->controler->change_url_for_reload($this->opt['redirect_on_login']);
     if ($this->opt['set_lang_attr']) {
         $an =& $config->attr_names;
         /* get the lang attribute */
         $ua_handler =& User_Attrs::singleton($this->uid);
         if (false === ($u_lang = $ua_handler->get_attribute($an['lang']))) {
             return false;
         }
         /* if lang attribute is not set, set it */
         if (is_null($u_lang)) {
             $u_lang = $_SESSION['lang'];
             /* get the attr_type of the lang attribute */
             $at_handler =& Attr_types::singleton();
             if (false === ($lang_type = $at_handler->get_attr_type($an['lang']))) {
                 return false;
             }
             if (is_null($lang_type)) {
                 ErrorHandler::add_error("Type of attribute 'lang' doesn't exists");
                 return false;
             }
             /* format the value */
             $lang_type->check_value($u_lang);
             /* store lang into DB */
             if (false === $ua_handler->set_attribute($an['lang'], $u_lang)) {
                 return false;
             }
         }
     }
     if ($this->opt['unset_lang_on_login']) {
         unset($_SESSION['lang']);
     }
     return true;
 }
 /**
  *	create html form 
  *
  *	@param array $errors	array with error messages
  *	@return null			FALSE on failure
  */
 function create_html_form(&$errors)
 {
     parent::create_html_form($errors);
     global $lang_str;
     /* get info about edited attribute */
     $attrs =& Attr_types::singleton();
     if (false === ($this->at = $attrs->get_attr_type($this->opt['attr_name']))) {
         $errors[] = "unknown attribute";
         return false;
     }
     /* store items of list */
     $this->item_list = $this->at->get_type_spec();
     if (!$this->item_list) {
         $this->item_list = array();
     }
     $label = $value = "";
     /* if editing, set default values of form elements */
     if ($this->action['action'] == 'edit') {
         $label = isset($this->item_list[$this->item_id]) ? $this->item_list[$this->item_id] : "";
         $value = $this->item_id;
     }
     $this->f->add_element(array("type" => "text", "name" => "at_item_label", "value" => $label, "size" => 16, "maxlength" => 255, "minlength" => 1, "length_e" => $lang_str['fe_not_filled_item_label']));
     $this->f->add_element(array("type" => "text", "name" => "at_item_value", "value" => $value, "size" => 16, "maxlength" => 255, "minlength" => 1, "length_e" => $lang_str['fe_not_filled_item_value']));
     $this->f->add_element(array("type" => "hidden", "name" => "at_item_id", "value" => $this->item_id));
 }
 /**
  *	create html form 
  *
  *	@param array $errors	array with error messages
  *	@return null			FALSE on failure
  */
 function create_html_form(&$errors)
 {
     parent::create_html_form($errors);
     global $lang_str;
     /* get info about edited attribute */
     $attrs =& Attr_types::singleton();
     if (false === ($this->at = $attrs->get_attr_type($this->opt['attr_name']))) {
         $errors[] = "unknown attribute";
         return false;
     }
     /* store items of list */
     $this->type_spec = $this->at->get_type_spec();
     if (!$this->type_spec) {
         $this->type_spec = array();
     }
     if (!isset($this->type_spec['min'])) {
         $this->type_spec['min'] = null;
     }
     if (!isset($this->type_spec['max'])) {
         $this->type_spec['max'] = null;
     }
     if (!isset($this->type_spec['err'])) {
         $this->type_spec['err'] = null;
     }
     $this->f->add_element(array("type" => "text", "name" => "at_int_min", "value" => $this->type_spec['min'], "size" => 16, "maxlength" => 16, "valid_regex" => "^-?[0-9]*\$", "valid_e" => "'" . $lang_str['ff_at_int_min'] . "' " . $lang_str['fe_is_not_number']));
     $this->f->add_element(array("type" => "text", "name" => "at_int_max", "value" => $this->type_spec['max'], "size" => 16, "maxlength" => 16, "valid_regex" => "^-?[0-9]*\$", "valid_e" => "'" . $lang_str['ff_at_int_max'] . "' " . $lang_str['fe_is_not_number']));
     $this->f->add_element(array("type" => "text", "name" => "at_int_err", "value" => $this->type_spec['err'], "size" => 16, "maxlength" => 64));
 }
Beispiel #14
0
 /**
  *	Validate new values of attributes received from html form
  *	
  *	Alowed options:
  *	 - none for now
  *	
  *	@param	array	$attributes		list of attributes
  *	@param	array	$opt			options
  *	@param 	array	$errors			error messages if any errors has been found
  *	@return	bool					TRUE on success or FALSE on error
  */
 function validate_form_attrs($attributes, $opt, &$errors)
 {
     global $lang_str;
     //get list of attributes
     $at_h =& Attr_types::singleton();
     if (false === ($attr_types =& $at_h->get_attr_types())) {
         return false;
     }
     foreach ($attributes as $att) {
         if (!isset($attr_types[$att])) {
             $msg = __FILE__ . ":" . __LINE__ . " - Attribute named '" . $att . "' do not exists - exiting";
             sw_log($msg, PEAR_LOG_CRIT);
             die($msg);
         }
         if (!isset($_POST[$att])) {
             $_POST[$att] = null;
         }
         if (!$attr_types[$att]->check_value($_POST[$att])) {
             if (!is_null($attr_types[$att]->get_err_msg())) {
                 $errors[] = $attr_types[$att]->get_err_msg();
             } else {
                 $errors[] = $lang_str['fe_invalid_value_of_attribute'] . " " . $attr_types[$att]->get_description();
             }
             return false;
         }
     }
     return true;
 }