function form_element(&$form, $value, $opt = array()) { parent::form_element($form, $value, $opt); global $lang_str; /* set default values for options */ $opt_err_msg = isset($opt["err_msg"]) ? $opt["err_msg"] : null; $form->add_element(array("type" => "text", "name" => $this->name, "size" => 16, "maxlength" => 255, "value" => $value, "minlength" => $this->is_required() ? 1 : 0, "length_e" => $opt_err_msg ? $opt_err_msg : "'" . $this->get_description() . "' " . $lang_str['fe_empty_not_allowed'])); }
function form_element(&$form, $value, $opt = array()) { parent::form_element($form, $value, $opt); global $lang_str; /* set default values for options */ $opt_err_msg = isset($opt["err_msg"]) ? $opt["err_msg"] : null; $reg =& CReg::Singleton(); $form->add_element(array("type" => "text", "name" => $this->name, "size" => 16, "maxlength" => 255, "value" => $value, "valid_regex" => $this->is_required() ? "^" . $reg->sip_address . "\$" : "^(" . $reg->sip_address . ")?\$", "valid_e" => $opt_err_msg ? $opt_err_msg : "'" . $this->get_description() . "' " . $lang_str['fe_is_not_sip_adr'], "extrahtml" => "onBlur='sip_address_completion(this)'")); }
function form_element(&$form, $value, $opt = array()) { parent::form_element($form, $value, $opt); $items = $this->get_items(); if (!is_array($items)) { $items = array(); } $opt = array(); foreach ($items as $item) { $opt[] = array("label" => $item->label, "value" => $item->value); } $form->add_element(array("type" => "select", "name" => $this->name, "size" => 1, "value" => $value, "options" => $opt)); }
function form_element(&$form, $value, $opt = array()) { global $data; parent::form_element($form, $value, $opt); if (false === ($timezones = $this->get_timezones())) { return false; } $options = array(); foreach ($timezones as $v) { $options[] = array("label" => $v, "value" => $v); } $form->add_element(array("type" => "select", "name" => $this->name, "options" => $options, "size" => 1, "value" => $value)); }
function form_element(&$form, $value, $opt = array()) { parent::form_element($form, $value, $opt); $form->add_element(array("type" => "checkbox", "name" => $this->name, "value" => "1", "checked" => $value)); }
/** * 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); }
/** * 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; }
/** * return list of all attribute types * * * Possible options: * - order_by (string) name of column the result is sorted by * - order_desc (bool) sort the result in descending order * - filter (array) filter criteria * - group_by_groups (bool) if true, the result entries are grouped by * attribute type groups * - use_pager (bool) if true, the number of entries is limited by * the paging feature * * @param array $opt options * @return bool */ function get_attr_types($opt) { global $config; $errors = array(); if (!$this->connect_to_db($errors)) { ErrorHandler::add_error($errors); return false; } /* table's name */ $t_at =& $config->data_sql->attr_types->table_name; /* col names */ $c =& $config->data_sql->attr_types->cols; /* default flag values */ $dfv =& $config->data_sql->user_attrs->flag_values; /* flag values */ $fv =& $config->data_sql->attr_types->flag_values; /* priority values */ $pv =& $config->data_sql->attr_types->priority_values; $o_order_by = isset($opt['order_by']) ? $opt['order_by'] : "order"; $o_order_desc = !empty($opt['order_desc']) ? "desc" : ""; /* construct where clause */ $qw = array(); if (!empty($opt['filter']['order'])) { $qw[] = $opt['filter']['order']->to_sql($c->order); } if (!empty($opt['filter']['at_name'])) { $qw[] = $opt['filter']['at_name']->to_sql($c->name); } if (!empty($opt['filter']['rich_type'])) { $qw[] = $opt['filter']['rich_type']->to_sql($c->rich_type); } if (!empty($opt['filter']['desc'])) { $qw[] = $opt['filter']['desc']->to_sql($c->desc); } if (!empty($opt['filter']['group'])) { $qw[] = $opt['filter']['group']->to_sql($c->group); } // if (!empty($opt['filter']['priority_r'])) $qw[] = $opt['filter']['priority_r']->to_sql_bool($c->priority."&".$pv['URI']); if (!empty($opt['filter']['priority_u'])) { $qw[] = $opt['filter']['priority_u']->to_sql_bool($c->priority . "&" . $pv['USER']); } if (!empty($opt['filter']['priority_d'])) { $qw[] = $opt['filter']['priority_d']->to_sql_bool($c->priority . "&" . $pv['DOMAIN']); } if (!empty($opt['filter']['priority_g'])) { $qw[] = $opt['filter']['priority_g']->to_sql_bool($c->priority . "&" . $pv['GLOBAL']); } if (!empty($opt['filter']['d_flags_s'])) { $qw[] = $opt['filter']['d_flags_s']->to_sql_bool($c->default_flags . "&" . $dfv['DB_LOAD_SER']); } if (!empty($opt['filter']['d_flags_sw'])) { $qw[] = $opt['filter']['d_flags_sw']->to_sql_bool($c->default_flags . "&" . $dfv['DB_FOR_SERWEB']); } if (!empty($opt['filter']['flags_r'])) { $qw[] = $opt['filter']['flags_r']->to_sql_bool($c->flags . "&" . $fv['DB_FILL_ON_REG']); } if (!empty($opt['filter']['flags_m'])) { $qw[] = $opt['filter']['flags_m']->to_sql_bool($c->flags . "&" . $fv['DB_MULTIVALUE']); } if (!empty($opt['filter']['flags_e'])) { $qw[] = $opt['filter']['flags_e']->to_sql_bool($c->flags . "&" . $fv['DB_REQUIRED']); } if ($qw) { $qw = " where " . implode(' and ', $qw); } else { $qw = ""; } /* construct 'order by' rules */ $qo = array(); if (!empty($opt['group_by_groups'])) { $qo[] = $c->group; } if ($o_order_by) { if (isset($c->{$o_order_by})) { $qo[] = $c->{$o_order_by} . " " . $o_order_desc; } elseif (substr($o_order_by, 0, 8) == "d_flags_") { switch (substr($o_order_by, 8)) { case "s": $qo[] = "(" . $c->default_flags . " & " . $dfv['DB_LOAD_SER'] . ") " . $o_order_desc; break; case "sw": $qo[] = "(" . $c->default_flags . " & " . $dfv['DB_FOR_SERWEB'] . ") " . $o_order_desc; break; default: sw_log("Unknown column '" . $o_order_by . "' in table 'attr_types'", PEAR_LOG_INFO); } } elseif (substr($o_order_by, 0, 9) == "priority_") { switch (substr($o_order_by, 9)) { case "r": $qo[] = "(" . $c->priority . " & " . $pv['URI'] . ") " . $o_order_desc; break; case "u": $qo[] = "(" . $c->priority . " & " . $pv['USER'] . ") " . $o_order_desc; break; case "d": $qo[] = "(" . $c->priority . " & " . $pv['DOMAIN'] . ") " . $o_order_desc; break; case "g": $qo[] = "(" . $c->priority . " & " . $pv['GLOBAL'] . ") " . $o_order_desc; break; default: sw_log("Unknown column '" . $o_order_by . "' in table 'attr_types'", PEAR_LOG_INFO); } } elseif (substr($o_order_by, 0, 6) == "flags_") { switch (substr($o_order_by, 6)) { case "r": $qo[] = "(" . $c->flags . " & " . $fv['DB_FILL_ON_REG'] . ") " . $o_order_desc; break; case "m": $qo[] = "(" . $c->flags . " & " . $fv['DB_MULTIVALUE'] . ") " . $o_order_desc; break; case "e": $qo[] = "(" . $c->flags . " & " . $fv['DB_REQUIRED'] . ") " . $o_order_desc; break; default: sw_log("Unknown column '" . $o_order_by . "' in table 'attr_types'", PEAR_LOG_INFO); } } else { sw_log("Unknown column '" . $o_order_by . "' in table 'attr_types'", PEAR_LOG_INFO); } } if (!empty($opt['use_pager'])) { $q = "select count(*)\n\t\t from " . $t_at . " " . $qw; $res = $this->db->query($q); if (DB::isError($res)) { ErrorHandler::log_errors($res); return false; } $row = $res->fetchRow(DB_FETCHMODE_ORDERED); $this->set_num_rows($row[0]); $res->free(); /* if act_row is bigger then num_rows, correct it */ $this->correct_act_row(); } $q = "select " . $c->name . ", " . $c->raw_type . ", " . $c->rich_type . ", " . $c->type_spec . ", \n\t\t " . $c->desc . ", " . $c->default_flags . ", " . $c->flags . ", " . $c->priority . ", \n\t\t " . $c->access . ", " . $c->order . ", " . $c->group . "\n\t\t from " . $t_at . $qw; if ($qo) { $q .= " order by " . implode(", ", $qo); } $q .= !empty($opt['use_pager']) ? $this->get_sql_limit_phrase() : ""; $res = $this->db->query($q); if (DB::isError($res)) { ErrorHandler::log_errors($res); return false; } $out = array(); while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) { $out[$row[$c->name]] =& Attr_type::factory($row[$c->name], $row[$c->raw_type], $row[$c->rich_type], is_string($row[$c->type_spec]) ? unserialize($row[$c->type_spec]) : null, $row[$c->desc], $row[$c->default_flags], $row[$c->flags], $row[$c->priority], $row[$c->access], $row[$c->order]); $out[$row[$c->name]]->set_group($row[$c->group]); } $res->free(); return $out; }
function form_element(&$form, $value, $opt = array()) { global $available_languages, $lang_str; parent::form_element($form, $value, $opt); $options = array(); if (false === ($languages = $this->get_languages())) { return false; } if ($value) { /* lookup for given $value in $available_languages */ foreach ($available_languages as $k => $v) { if ($v[2] == substr($value, 0, 2) and isset($languages[$k])) { $value = $k; break; } } } else { /* if attribute has not value, add option 'not selected' */ $options[] = array("label" => "--- " . $lang_str['o_lang_not_selected'] . " ---", "value" => ""); } foreach ($languages as $k => $v) { $options[] = array("label" => $v, "value" => $k); } $form->add_element(array("type" => "select", "name" => $this->name, "options" => $options, "size" => 1, "value" => $value)); }
function set_type($str) { if (false === ($raw = Attr_type::get_raw_for_rich($str))) { return false; } $this->rich_type = $str; $this->raw_type = $raw; }
function form_element(&$form, $value, $opt = array()) { parent::form_element($form, $value, $opt); global $lang_str; /* set default values for options */ $opt_err_msg = isset($opt["err_msg"]) ? $opt["err_msg"] : null; $form->add_element(array("type" => "text", "name" => $this->name, "size" => 16, "maxlength" => 16, "value" => $value, "valid_regex" => $this->is_required() ? "^-?[0-9]+\$" : "^-?[0-9]*\$", "valid_e" => $opt_err_msg ? $opt_err_msg : "'" . $this->get_description() . "' " . $lang_str['fe_is_not_number'])); }