/** * Get value of attribute * * This function search in order uri, user, domain and global tracks * for attribute value and return value from the first track where find it. * * Alowed options: * - uid (string) - uid of user track * - did (string) - did of domain track * - uri (array) - identifies uri track. Have to have three * components: scheme, username and did * * @param string $name name of the attribute * @param array $opt options * @return mixed value of attribute or FALSE on error */ function get_attribute($name, $opt) { /* set default values for options */ $opt_uid = isset($opt["uid"]) ? $opt["uid"] : null; $opt_did = isset($opt["did"]) ? $opt["did"] : null; $opt_uri = isset($opt["uri"]) ? $opt["uri"] : null; if (!is_null($opt_uri)) { $attrs =& Uri_Attrs::singleton($opt_uri['scheme'], $opt_uri['username'], $opt_uri['did']); if (false === ($attr = $attrs->get_attribute($name))) { return false; } if (!is_null($attr)) { return $attr; } } if (!is_null($opt_uid)) { $attrs =& User_Attrs::singleton($opt_uid); if (false === ($attr = $attrs->get_attribute($name))) { return false; } if (!is_null($attr)) { return $attr; } } if (!is_null($opt_did)) { $attrs =& Domain_Attrs::singleton($opt_did); if (false === ($attr = $attrs->get_attribute($name))) { return false; } if (!is_null($attr)) { return $attr; } } $attrs =& Global_Attrs::singleton(); if (false === ($attr = $attrs->get_attribute($name))) { return false; } if (!is_null($attr)) { return $attr; } /* attribute not found */ return null; }
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']; } }