Ejemplo n.º 1
0
 /**
  */
 public function configSpecialValues($what)
 {
     switch ($what) {
         case 'apps':
             $apps = Horde_Array::valuesToKeys($GLOBALS['registry']->listApps(array('active')));
             asort($apps);
             return $apps;
         case 'languages':
             $convert_numeric = function ($num) {
                 return Horde_String::convertCharset(pack('H*', $num[1]), 'ucs-2', 'UTF-8');
             };
             $convert_symbolic = function ($symbol) {
                 return Horde_String::convertCharset(html_entity_decode($symbol[1], ENT_COMPAT, 'iso-8859-1'), 'iso-8859-1', 'UTF-8');
             };
             return array_map(function ($val) {
                 return preg_replace_callback(array('/&#x([0-9a-f]{4});/i', '/(&[^;]+;)/'), array($convert_numeric, $convert_symbolic), $val);
             }, $GLOBALS['registry']->nlsconfig->languages);
         case 'blocks':
             return $GLOBALS['injector']->getInstance('Horde_Core_Factory_BlockCollection')->create()->getBlocksList();
         case 'mapsources':
             return array('Google' => 'Google', 'Bing' => 'Bing', 'Cloudmade' => 'CloudMade', 'Mytopo' => 'MyTopo', 'Osm' => 'OpenStreetMap', 'Ocm' => 'OpenCycleMap', 'Mapquest' => 'OpenMapquest');
         case 'geocoders':
             return array('None' => null, 'Google' => 'Google');
     }
 }
Ejemplo n.º 2
0
 public function __construct($vars)
 {
     /* Check if a form is being edited. */
     $editing = $vars->exists('domain_id');
     $domain = $GLOBALS['session']->get('vilma', 'domain');
     parent::__construct($vars, $editing ? _("Edit Domain") : _("New Domain"));
     if ($editing && !$this->isSubmitted()) {
         $domain = $GLOBALS['vilma']->driver->getDomain($vars->get('domain_id'));
     }
     $vars->add('name', $domain['domain_name']);
     $vars->add('transport', $domain['domain_transport']);
     $vars->add('max_users', $domain['domain_max_users']);
     $vars->add('quota', $domain['domain_quota']);
     /* Set up the form. */
     $this->setButtons(true, true);
     $this->addHidden('', 'domain_id', 'text', false);
     $this->addVariable(_("Domain"), 'name', 'text', true);
     $this->addVariable(_("Transport"), 'transport', 'enum', false, false, null, array(Horde_Array::valuesToKeys($GLOBALS['conf']['mta']['transports'])));
     $this->addVariable(_("Max users"), 'max_users', 'int', false);
     $this->addVariable(_("Quota"), 'quota', 'int', false, false, _("Value in MB"));
 }
Ejemplo n.º 3
0
 /**
  * Parses one level of the configuration XML tree into the associative
  * array containing the traversed configuration tree.
  *
  * @param array &$conf           The already existing array where the
  *                               processed XML tree portion should be
  *                               appended to.
  * @param DOMNodeList $children  The XML nodes of the level that should
  *                               be parsed.
  * @param string $ctx            A string representing the current
  *                               position (context prefix) inside the
  *                               configuration XML file.
  */
 protected function _parseLevel(&$conf, $children, $ctx)
 {
     foreach ($children as $node) {
         if ($node->nodeType != XML_ELEMENT_NODE) {
             continue;
         }
         $name = $node->getAttribute('name');
         $desc = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($node->getAttribute('desc'), 'linkurls');
         $required = !($node->getAttribute('required') == 'false');
         $quote = !($node->getAttribute('quote') == 'false');
         $curctx = empty($ctx) ? $name : $ctx . '|' . $name;
         switch ($node->tagName) {
             case 'configdescription':
                 if (empty($name)) {
                     $name = uniqid(mt_rand());
                 }
                 $conf[$name] = array('_type' => 'description', 'desc' => $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($this->_default($curctx, $this->_getNodeOnlyText($node)), 'linkurls'));
                 break;
             case 'configheader':
                 if (empty($name)) {
                     $name = uniqid(mt_rand());
                 }
                 $conf[$name] = array('_type' => 'header', 'desc' => $this->_default($curctx, $this->_getNodeOnlyText($node)));
                 break;
             case 'configswitch':
                 $values = $this->_getSwitchValues($node, $ctx);
                 list($default, $isDefault) = $quote ? $this->__default($curctx, $this->_getNodeOnlyText($node)) : $this->__defaultRaw($curctx, $this->_getNodeOnlyText($node));
                 if ($default === '') {
                     $default = key($values);
                 }
                 if (is_bool($default)) {
                     $default = $default ? 'true' : 'false';
                 }
                 $conf[$name] = array('desc' => $desc, 'switch' => $values, 'default' => $default, 'is_default' => $isDefault, 'quote' => $quote);
                 break;
             case 'configenum':
                 $values = $this->_getEnumValues($node);
                 list($default, $isDefault) = $quote ? $this->__default($curctx, $this->_getNodeOnlyText($node)) : $this->__defaultRaw($curctx, $this->_getNodeOnlyText($node));
                 if ($default === '') {
                     $default = key($values);
                 }
                 if (is_bool($default)) {
                     $default = $default ? 'true' : 'false';
                 }
                 $conf[$name] = array('_type' => 'enum', 'required' => $required, 'quote' => $quote, 'values' => $values, 'desc' => $desc, 'default' => $default, 'is_default' => $isDefault);
                 break;
             case 'configlist':
                 list($default, $isDefault) = $this->__default($curctx, null);
                 if (is_null($default)) {
                     $default = $this->_getNodeOnlyText($node);
                 } elseif (is_array($default)) {
                     $default = implode(', ', $default);
                 }
                 $conf[$name] = array('_type' => 'stringlist', 'required' => $required, 'desc' => $desc, 'default' => $default, 'is_default' => $isDefault);
                 break;
             case 'configmultienum':
                 $default = $this->_getNodeOnlyText($node);
                 if (strlen($default)) {
                     $default = explode(',', $default);
                 } else {
                     $default = array();
                 }
                 list($default, $isDefault) = $this->__default($curctx, $default);
                 $conf[$name] = array('_type' => 'multienum', 'required' => $required, 'values' => $this->_getEnumValues($node), 'desc' => $desc, 'default' => Horde_Array::valuesToKeys($default), 'is_default' => $isDefault);
                 break;
             case 'configpassword':
                 $conf[$name] = array('_type' => 'password', 'required' => $required, 'desc' => $desc, 'default' => $this->_default($curctx, $this->_getNodeOnlyText($node)), 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)));
                 break;
             case 'configstring':
                 $conf[$name] = array('_type' => 'text', 'required' => $required, 'desc' => $desc, 'default' => $this->_default($curctx, $this->_getNodeOnlyText($node)), 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)));
                 if ($conf[$name]['default'] === false) {
                     $conf[$name]['default'] = 'false';
                 } elseif ($conf[$name]['default'] === true) {
                     $conf[$name]['default'] = 'true';
                 }
                 break;
             case 'configboolean':
                 $default = $this->_getNodeOnlyText($node);
                 $default = !(empty($default) || $default === 'false');
                 $conf[$name] = array('_type' => 'boolean', 'required' => $required, 'desc' => $desc, 'default' => $this->_default($curctx, $default), 'is_default' => $this->_isDefault($curctx, $default));
                 break;
             case 'configinteger':
                 $values = $this->_getEnumValues($node);
                 $conf[$name] = array('_type' => 'int', 'required' => $required, 'values' => $values, 'desc' => $desc, 'default' => $this->_default($curctx, $this->_getNodeOnlyText($node)), 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)));
                 if ($node->getAttribute('octal') == 'true' && $conf[$name]['default'] != '') {
                     $conf[$name]['_type'] = 'octal';
                     $conf[$name]['default'] = sprintf('0%o', $this->_default($curctx, octdec($this->_getNodeOnlyText($node))));
                 }
                 break;
             case 'configldap':
                 $conf[$node->getAttribute('switchname')] = $this->_configLDAP($ctx, $node);
                 break;
             case 'configldapuser':
                 $conf = array_merge($conf, $this->_configLDAPUser($ctx, $node));
                 break;
             case 'configphp':
                 $conf[$name] = array('_type' => 'php', 'required' => $required, 'quote' => false, 'desc' => $desc, 'default' => $this->_defaultRaw($curctx, $this->_getNodeOnlyText($node)), 'is_default' => $this->_isDefaultRaw($curctx, $this->_getNodeOnlyText($node)));
                 break;
             case 'configsecret':
                 $conf[$name] = array('_type' => 'text', 'required' => true, 'desc' => $desc, 'default' => $this->_default($curctx, strval(new Horde_Support_Uuid())), 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)));
                 break;
             case 'configsql':
                 $conf[$node->getAttribute('switchname')] = $this->configSQL($ctx, $node);
                 break;
             case 'confignosql':
                 $conf[$node->getAttribute('switchname')] = $this->configNoSQL($ctx, $node);
                 break;
             case 'configvfs':
                 $conf[$node->getAttribute('switchname')] = $this->_configVFS($ctx, $node);
                 break;
             case 'configsection':
                 $conf[$name] = array();
                 $cur =& $conf[$name];
                 if ($node->hasChildNodes()) {
                     $this->_parseLevel($cur, $node->childNodes, $curctx);
                 }
                 break;
             case 'configtab':
                 $key = uniqid(mt_rand());
                 $conf[$key] = array('tab' => $name, 'desc' => $desc);
                 if ($node->hasChildNodes()) {
                     $this->_parseLevel($conf, $node->childNodes, $ctx);
                 }
                 break;
             case 'configplaceholder':
                 $conf[uniqid(mt_rand())] = 'placeholder';
                 break;
             default:
                 $conf[$name] = array();
                 $cur =& $conf[$name];
                 if ($node->hasChildNodes()) {
                     $this->_parseLevel($cur, $node->childNodes, $curctx);
                 }
                 break;
         }
     }
 }
Ejemplo n.º 4
0
 function _renderVarInput_mlenum($form, $var, $vars)
 {
     $varname = $var->getVarName();
     $values = $var->getValues();
     $prompts = $var->type->prompts;
     $selected = $var->getValue($vars);
     /* If passing a non-array value need to get the keys. */
     if (!is_array($selected)) {
         foreach ($values as $key_1 => $values_2) {
             if (isset($values_2[$selected])) {
                 $selected = array('1' => $key_1, '2' => $selected);
                 break;
             }
         }
     }
     /* Hidden tag to store the current first level. */
     $html = sprintf('    <input type="hidden" name="%1$s[old]" id="%1$s[old]" value="%2$s" />', $varname, htmlspecialchars($selected['1']));
     /* First level. */
     $values_1 = Horde_Array::valuesToKeys(array_keys($values));
     $html .= sprintf('    <select id="%1$s[1]" name="%1$s[1]" onchange="%2$s"%3$s>', $varname, 'if (this.value) { document.' . $form->getName() . '.formname.value=\'\';' . 'document.' . $form->getName() . '.submit() }', $var->hasAction() ? ' ' . $this->_genActionScript($form, $var->_action, $varname) : '');
     if (!empty($prompts)) {
         $html .= '<option value="">' . htmlspecialchars($prompts[0]) . '</option>';
     }
     $html .= $this->_selectOptions($values_1, $selected['1']);
     $html .= '    </select>';
     /* Second level. */
     $html .= sprintf('    <select id="%1$s[2]" name="%1$s[2]"%2$s>', $varname, $var->hasAction() ? ' ' . $this->_genActionScript($form, $var->_action, $varname) : '');
     if (!empty($prompts)) {
         $html .= '<option value="">' . htmlspecialchars($prompts[1]) . '</option>';
     }
     $values_2 = array();
     if (!empty($selected['1'])) {
         $values_2 = $values[$selected['1']];
     }
     return $html . $this->_selectOptions($values_2, $selected['2']) . '    </select>';
 }