/** * Gets domains from driver for which the user has the specified * permission. * * @param int $perms Permissions filter for domain result set * * @return array Possibly empty array of domain information */ function getDomains($perms = Horde_Perms::SHOW) { try { $domains = $this->_getDomains(); } catch (Exception $e) { $GLOBALS['notification']->push($e->getMessage(), 'horde.warning'); return array(); } if (empty($domains)) { return array(); } if (!$GLOBALS['registry']->isAdmin() && !$GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('beatnik:domains', $GLOBALS['registry']->getAuth(), $perms)) { foreach ($domains as $id => $domain) { if (!$GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('beatnik:domains:' . $domain['zonename'], $GLOBALS['registry']->getAuth(), $perms)) { unset($domains[$id]); } } } if (empty($domains)) { $GLOBALS['notification']->push(_("You are not permitted to view any domains."), 'horde.warning'); return array(); } // Sort the resulting list by domain name // TODO: Allow sorting by other columns Horde_Array::arraySort($domains, 'zonename'); return $domains; }
/** */ 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'); } }
/** * Fetch the field values from a given array of variables. * * @access private * * @param array $variables An array of Horde_Form_Variable objects to * fetch from. * @param object $vars The Variables object. * @param array $info The array to be filled with the submitted * field values. */ function _getInfoFromVariables($variables, &$vars, &$info) { foreach ($variables as $var) { $value = $var->getValue($vars); if (empty($value)) { continue; } require_once 'Horde/Array.php'; if (Horde_Array::getArrayParts($var->getVarName(), $base, $keys)) { if (!isset($info[$base])) { $info[$base] = array(); } $pointer =& $info[$base]; while (count($keys)) { $key = array_shift($keys); if (!isset($pointer[$key])) { $pointer[$key] = array(); } $pointer =& $pointer[$key]; } $var->getInfo($vars, $pointer); } else { $var->getInfo($vars, $info[$var->getVarName()]); } } }
/** * List Stock items as versions for a queue (category) * @param integer $queue_id The category id (queue) for which we want to fetch versions * @return array A hash containing stock id as id, stock name as name, stock note as description */ public function listVersions($queue_id) { $inventory = $GLOBALS['backend']->findStock(array('categories' => $queue_id)); $versions = array(); foreach ($inventory as $item) { $versions[] = array('id' => $item->stock_id, 'name' => $item->stock_name, 'description' => $item->note, 'readonly' => true); } Horde_Array::arraySort($versions, 'name', 0, false); return $versions; }
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")); }
/** * Returns the available permissions for a given level. * * @param string $name The permission's name. * * @return array An array of available permissions and their titles or * false if not sub permissions exist for this level. * @throws Horde_Perms_Exception */ public function getAvailable($name) { if ($name == Horde_Perms::ROOT) { $name = ''; } if (empty($name)) { /* No name passed, so top level permissions are requested. These * can only be applications. */ $apps = $this->_registry->listApps(array('notoolbar', 'active', 'hidden'), true); foreach (array_keys($apps) as $app) { $apps[$app] = $this->_registry->get('name', $app) . ' (' . $app . ')'; } asort($apps); return $apps; } /* Name has been passed, explode the name to get all the levels in * permission being requisted, with the app as the first level. */ $levels = explode(':', $name); /* First level is always app. */ $app = $levels[0]; /* Call the app's permission function to return the permissions * specific to this app. */ $perms = $this->getApplicationPermissions($app); if (!count($perms)) { return false; } /* Get the part of the app's permissions based on the permission * name requested. */ $children = Horde_Array::getElement($perms['tree'], $levels); if ($children === false || !is_array($children) || !count($children)) { /* No array of children available for this permission name. */ return false; } $perms_list = array(); foreach (array_keys($children) as $perm_key) { $perms_list[$perm_key] = $perms['title'][$name . ':' . $perm_key]; } return $perms_list; }
/** * Determines if the file was uploaded or not. If not, will return the * appropriate error message. * * @param string $field The name of the field containing the uploaded * file. * @param string $name The file description string to use in the error * message. Default: 'file'. * * @throws Horde_Browser_Exception */ public function wasFileUploaded($field, $name = null) { if (is_null($name)) { $name = 'file'; } if (!($uploadSize = self::allowFileUploads())) { throw new Horde_Browser_Exception(Horde_Browser_Translation::t("File uploads not supported.")); } /* Get any index on the field name. */ $index = Horde_Array::getArrayParts($field, $base, $keys); if ($index) { /* Index present, fetch the error var to check. */ $keys_path = array_merge(array($base, 'error'), $keys); $error = Horde_Array::getElement($_FILES, $keys_path); /* Index present, fetch the tmp_name var to check. */ $keys_path = array_merge(array($base, 'tmp_name'), $keys); $tmp_name = Horde_Array::getElement($_FILES, $keys_path); } else { /* No index, simple set up of vars to check. */ if (!isset($_FILES[$field])) { throw new Horde_Browser_Exception(Horde_Browser_Translation::t("No file uploaded"), UPLOAD_ERR_NO_FILE); } $error = $_FILES[$field]['error']; $tmp_name = $_FILES[$field]['tmp_name']; } if (empty($_FILES) || $error == UPLOAD_ERR_NO_FILE) { throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: No %s was uploaded."), $name), UPLOAD_ERR_NO_FILE); } elseif ($error == UPLOAD_ERR_OK && is_uploaded_file($tmp_name)) { if (!filesize($tmp_name)) { throw new Horde_Browser_Exception(Horde_Browser_Translation::t("The uploaded file appears to be empty. It may not exist on your computer."), UPLOAD_ERR_NO_FILE); } // SUCCESS } elseif ($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE) { throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, $uploadSize), $error); } elseif ($error == UPLOAD_ERR_PARTIAL) { throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error); } }
/** * Return a Horde_Tree representation of the permissions tree. * * @return string The html showing the permissions as a Horde_Tree. * @throws Horde_Perms_Exception */ public function renderTree($current = Horde_Perms::ROOT) { /* Get the perms tree. */ $nodes = $this->_perms->getTree(); $perms_node = array('icon' => Horde_Themes::img('perms.png')); $add = Horde::url('admin/perms/addchild.php'); $add_img = Horde_Themes_Image::tag('plus.png', array('alt' => Horde_Core_Translation::t("Add Permission"))); $edit = Horde::url('admin/perms/edit.php'); $delete = Horde::url('admin/perms/delete.php'); $edit_img = Horde_Themes_Image::tag('edit.png', array('alt' => Horde_Core_Translation::t("Edit Permission"))); $delete_img = Horde_Themes_Image::tag('delete.png', array('alt' => Horde_Core_Translation::t("Delete Permission"))); $blank_img = Horde_Themes_Image::tag('blank.gif', array('attr' => array('width' => 16, 'height' => 16))); /* Set up the tree. */ $tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('perms_ui', 'Javascript', array('alternate' => true, 'hideHeaders' => true)); $tree->setHeader(array(array('class' => 'horde-tree-spacer'))); foreach ($nodes as $perm_id => $node) { $node_class = $current == $perm_id ? array('class' => 'selected') : array(); if ($perm_id == Horde_Perms::ROOT) { $add_link = $add->add('perm_id', $perm_id)->link(array('class' => 'permsAdd', 'title' => Horde_Core_Translation::t("Add New Permission"))) . $add_img . '</a>'; $base_node_params = array('icon' => Horde_Themes::img('administration.png')); $tree->addNode(array('id' => $perm_id, 'label' => Horde_Core_Translation::t("All Permissions"), 'expanded' => true, 'params' => $base_node_params + $node_class, 'right' => array($add_link))); } else { $parent_id = $this->_perms->getParent($node); $perms_extra = array(); $parents = explode(':', $node); if (!in_array($parents[0], $GLOBALS['registry']->listApps(array('notoolbar', 'active', 'hidden')))) { // This backend has permissions for an application that is // not installed. Perhaps the application has been removed // or the backend is shared with other Horde installations. // Skip this app and do not include it in the tree. continue; } try { $app_perms = $this->_corePerms->getApplicationPermissions($parents[0]); } catch (Horde_Perms_Exception $e) { $GLOBALS['notification']->push($e); continue; } if (isset($app_perms['tree']) && is_array(Horde_Array::getElement($app_perms['tree'], $parents))) { $add_link = $add->add('perm_id', $perm_id)->link(array('class' => 'permsAdd', 'title' => Horde_Core_Translation::t("Add Child Permission"))) . $add_img . '</a>'; $perms_extra[] = $add_link; } else { $perms_extra[] = $blank_img; } $edit_link = $edit->add('perm_id', $perm_id)->link(array('class' => 'permsEdit', 'title' => Horde_Core_Translation::t("Edit Permission"))) . $edit_img . '</a>'; $perms_extra[] = $edit_link; $delete_link = $delete->add('perm_id', $perm_id)->link(array('class' => 'permsDelete', 'title' => Horde_Core_Translation::t("Delete Permission"))) . $delete_img . '</a>'; $perms_extra[] = $delete_link; $name = $this->_corePerms->getTitle($node); $expanded = isset($nodes[$current]) && strpos($nodes[$current], $node) === 0 && $nodes[$current] != $node; $tree->addNode(array('id' => $perm_id, 'parent' => $parent_id, 'label' => $name, 'expanded' => $expanded, 'params' => $perms_node + $node_class, 'right' => $perms_extra)); } } $tree->sort('label'); return $tree->renderTree(); }
/** * Returns a list of all users, aliases, or groups and forwards for a * domain. * * @param string $domain Domain on which to search. * @param string $type Only return a specific type. One of 'all', * 'user', 'alias', 'forward', or 'group'. * @param string $key Sort list by this key. * @param integer $direction Sort direction. * * @return array Account information for this domain. */ public function getAddresses($domain, $type = 'all', $key = 'user_name', $direction = 0) { $addresses = $this->_getAddresses($domain, $type); Horde_Array::arraySort($addresses, $key, $direction, true); return $addresses; }
/** * 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; } } }
/** * Returns the driver parameters for the specified backend. * * @param mixed $backend The backend system (e.g. 'prefs', 'categories', * 'contacts') being used. * The used configuration array will be * $conf[$backend]. If an array gets passed, it will * be $conf[$key1][$key2]. * @param string $type The type of driver. * * @return array The connection parameters. */ function getDriverConfig($backend, $type = 'sql') { global $conf; $c = null; if (is_array($backend)) { require_once 'Horde/Array.php'; $c = Horde_Array::getElement($conf, $backend); } elseif (isset($conf[$backend])) { $c = $conf[$backend]; } if (!is_null($c) && isset($c['params'])) { $c['params']['umask'] = $conf['umask']; if (isset($conf[$type])) { return array_merge($conf[$type], $c['params']); } else { return $c['params']; } } return isset($conf[$type]) ? $conf[$type] : array(); }
public function getCostObjectType($vars) { global $registry; $clients = $vars->get('clients'); if (count($clients) == 0) { $clients = array(''); } $costobjects = array(); foreach ($clients as $client) { $criteria = array('user' => $GLOBALS['registry']->getAuth(), 'active' => true, 'client_id' => $client); foreach ($registry->listApps() as $app) { if ($registry->hasMethod('listCostObjects', $app)) { try { $res = $registry->callByPackage($app, 'listCostObjects', array($criteria)); } catch (Horde_Exception $e) { $GLOBALS['notification']->push(sprintf(_("Error retrieving cost objects from \"%s\": %s"), $registry->get('name', $app), $res->getMessage()), 'horde.error'); continue; } foreach (array_keys($res) as $catkey) { foreach (array_keys($res[$catkey]['objects']) as $okey) { $res[$catkey]['objects'][$okey]['id'] = $app . ':' . $res[$catkey]['objects'][$okey]['id']; } } $costobjects = array_merge($costobjects, $res); } } } $elts = array(); $counter = 0; foreach ($costobjects as $category) { Horde_Array::arraySort($category['objects'], 'name'); foreach ($category['objects'] as $object) { $name = $object['name']; if (Horde_String::length($name) > 80) { $name = Horde_String::substr($name, 0, 76) . ' ...'; } $elts[$object['id']] = $name; } } return $elts; }
$apps[$i]['dbstatus'] = $apps[$i]['db'] = array(); $apps[$i]['status'] = $apps[$i]['icon'] = $apps[$i]['conf'] = ''; if (!isset($versions[$app])) { $apps[$i]['load'] = $warning; $apps[$i]['vstatus'] = _("No stable version exists yet."); } elseif (version_compare(preg_replace('/H\\d \\((.*)\\)/', '$1', $versions[$app]['version']), $apps[$i]['version'], '>')) { $apps[$i]['load'] = $error; $apps[$i]['vstatus'] = Horde::link($versions[$app]['url'], sprintf(_("Download %s"), $app), '', '_blank') . sprintf(_("A newer version (%s) exists."), $versions[$app]['version']) . '</a> '; } else { $apps[$i]['load'] = $success; $apps[$i]['vstatus'] = _("Module is up-to-date."); } } } /* Sort the apps by name. */ Horde_Array::arraySort($apps, 'sort'); /* Set up any actions that may be offered. */ $actions = array(); $ftpform = ''; if ($session->get('horde', 'config/')) { $url = Horde::url('admin/config/diff.php'); $action = _("Show differences between currently saved and the newly generated configuration."); $actions[] = array('icon' => Horde_Themes_Image::tag('search.png', array('attr' => array('align' => 'middle'))), 'link' => Horde::link('#', '', '', '', Horde::popupJs($url, array('height' => 480, 'width' => 640, 'urlencode' => true)) . 'return false;') . $action . '</a>'); /* Action to download the configuration upgrade PHP script. */ $url = Horde::url('admin/config/scripts.php')->add(array('setup' => 'conf', 'type' => 'php')); $action = _("Download generated configuration as PHP script."); $actions[] = array('icon' => Horde_Themes_Image::tag('download.png', array('attr' => array('align' => 'middle'))), 'link' => Horde::link($url) . $action . '</a>'); /* Action to save the configuration upgrade PHP script. */ $action = _("Save generated configuration as a PHP script to your server's temporary directory."); $actions[] = array('icon' => Horde_Themes_Image::tag('save.png', array('attr' => array('align' => 'middle'))), 'link' => Horde::link($url->add('save', 'tmp')) . $action . '</a>'); /* Set up the form for FTP upload of scripts. */
/** * Returns the driver parameters for the specified backend. * * @param mixed $backend The backend system (e.g. 'prefs', 'categories', * 'contacts') being used. * The used configuration array will be * $conf[$backend]. If an array gets passed, it will * be $conf[$key1][$key2]. * @param string $type The type of driver. If null, will not merge with * base config. * * @return array The connection parameters. */ public static function getDriverConfig($backend, $type = 'sql') { global $conf; if (!is_null($type)) { $type = Horde_String::lower($type); } if (is_array($backend)) { $c = Horde_Array::getElement($conf, $backend); } elseif (isset($conf[$backend])) { $c = $conf[$backend]; } else { $c = null; } if (!is_null($c) && isset($c['params'])) { $c['params']['umask'] = $conf['umask']; return !is_null($type) && isset($conf[$type]) ? array_merge($conf[$type], $c['params']) : $c['params']; } return !is_null($type) && isset($conf[$type]) ? $conf[$type] : array(); }
/** * Return data for costobjects, optionally filtered by client_ids. * * @param mixed $client_ids A client id or an array of client ids to * filter cost obejcts by. * * @return array An array of cost objects data. */ public static function getCostObjectType($client_ids = null) { $elts = array('' => _("--- No Cost Object ---")); $counter = 0; foreach (self::getCostObjects($client_ids) as $category) { Horde_Array::arraySort($category['objects'], 'name'); $elts['category%' . $counter++] = sprintf('--- %s ---', $category['category']); foreach ($category['objects'] as $object) { $name = Horde_String::truncate($object['name'], 80); $hours = 0.0; $filter = array('costobject' => $object['id']); if (!empty($GLOBALS['conf']['time']['sum_billable_only'])) { $filter['billable'] = true; } $result = $GLOBALS['injector']->getInstance('Hermes_Driver')->getHours($filter, array('hours')); foreach ($result as $entry) { if (!empty($entry['hours'])) { $hours += $entry['hours']; } } /* Show summary of hours versus estimate for this * deliverable. */ if (empty($object['estimate'])) { $name .= sprintf(_(" (%0.2f hours)"), $hours); } else { $name .= sprintf(_(" (%d%%, %0.2f of %0.2f hours)"), (int) ($hours / $object['estimate'] * 100), $hours, $object['estimate']); } $elts[$object['id']] = $name; } } return $elts; }
/** * Fetch the requested variable ($varname) into $value, and return * whether or not the variable was set in $array. * * @param array $array The array to search in (usually either * $this->_vars or $this->_expected). * @param string $varname The name of the variable to look for. * @param mixed &$value $varname's value gets assigned to this variable. * * @return boolean Whether or not the variable was set (or, if we've * checked $this->_expected, should have been set). */ protected function _getExists($array, $varname, &$value) { if (Horde_Array::getArrayParts($varname, $base, $keys)) { if (!isset($array[$base])) { $value = null; return false; } $searchspace =& $array[$base]; $i = count($keys); while ($i--) { $key = array_shift($keys); if (!isset($searchspace[$key])) { $value = null; return false; } $searchspace =& $searchspace[$key]; } $value = $searchspace; return true; } $value = isset($array[$varname]) ? $array[$varname] : null; return !is_null($value); }
/** * Fetch the field values from a given array of variables. * * @access private * * @param array $variables An array of Horde_Form_Variable objects to * fetch from. * @param object $vars The Variables object. * @param array $info The array to be filled with the submitted * field values. */ function _getInfoFromVariables($variables, &$vars, &$info) { foreach ($variables as $var) { if ($var->isDisabled()) { // Disabled fields are not submitted by some browsers, so don't // pretend they were. continue; } if ($var->isArrayVal()) { $var->getInfo($vars, $values); if (is_array($values)) { $varName = str_replace('[]', '', $var->getVarName()); foreach ($values as $i => $val) { $info[$i][$varName] = $val; } } } else { if (Horde_Array::getArrayParts($var->getVarName(), $base, $keys)) { if (!isset($info[$base])) { $info[$base] = array(); } $pointer =& $info[$base]; while (count($keys)) { $key = array_shift($keys); if (!isset($pointer[$key])) { $pointer[$key] = array(); } $pointer =& $pointer[$key]; } $var->getInfo($vars, $pointer); } else { $var->getInfo($vars, $info[$var->getVarName()]); } } } }
/** * Get the list of Hermes-only deliverables for the requested client. * - c: The client id * - id: The optional deliverable id, if requesting a specific deliverable. */ public function listDeliverables() { global $injector; if (!empty($this->vars->id)) { $params = array('id' => $this->vars->id); return array_values($injector->getInstance('Hermes_Driver')->listDeliverables($params)); } // Only poll Hermes' deliverables if we have a client id since they // are ALWAYS tied to a client. Otherwise, just return the list of // external cost objects. $client_id = !empty($this->vars->c) ? $this->vars->c : null; if (!empty($client_id)) { $objs = array_values($injector->getInstance('Hermes_Driver')->listDeliverables(array('client_id' => $client_id))); foreach ($objs as &$obj) { $obj['id'] = 'hermes:' . $obj['id']; $obj['hours'] = 0; foreach ($injector->getInstance('Hermes_Driver')->getHours(array('costobject' => $obj['id'])) as $slice) { $obj['hours'] += $slice['hours']; } } return $objs; } $elts = array(); foreach (Hermes::getCostObjects($client_id, true) as $category) { Horde_Array::arraySort($category['objects'], 'name'); foreach ($category['objects'] as $object) { $hours = 0; foreach ($injector->getInstance('Hermes_Driver')->getHours(array('costobject' => $object['id'])) as $slice) { $hours += $slice['hours']; } $elts[] = array('id' => $object['id'], 'client_id' => false, 'name' => sprintf('%s (%s)', htmlspecialchars(Horde_String::truncate($object['name'], 80)), htmlspecialchars($category['category'])), 'parent' => empty($object['parent']) ? 0 : $object['parent'], 'estimate' => empty($object['estimate']) ? 0 : $object['estimate'], 'active' => true, 'is_external' => true, 'hours' => $hours); } } return array_values($elts); }
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>'; }
/** * Moves a block one column right. * * @param integer $row A layout row. * @param integer $col A layout column. * * @throws Horde_Exception */ public function moveRight($row, $col) { $height = $this->getHeight($row, $col); $lastcol = $col + $this->getWidth($row, $col); if ($this->colExists($lastcol)) { // See if there's room to move into. for ($i = 0; $i < $height; $i++) { if (!$this->isEmpty($row + $i, $lastcol)) { $in_way = $this->getBlockAt($row + $i, $lastcol); if (!is_null($in_way) && $in_way[0] == $row && $this->getHeight($in_way[0], $in_way[1]) == $height) { // We need to swap the blocks. $rec1 = Horde_Array::getRectangle($this->_layout, $row, $col, $this->getHeight($row, $col), $this->getWidth($row, $col)); $rec2 = Horde_Array::getRectangle($this->_layout, $in_way[0], $in_way[1], $this->getHeight($in_way[0], $in_way[1]), $this->getWidth($in_way[0], $in_way[1])); for ($j = 0; $j < count($rec2); $j++) { for ($k = 0; $k < count($rec2[$j]); $k++) { $this->_layout[$row + $j][$col + $k] = $rec2[$j][$k]; } } for ($j = 0; $j < count($rec1); $j++) { for ($k = 0; $k < count($rec1[$j]); $k++) { $this->_layout[$row + $j][$col + count($rec2[$j]) + $k] = $rec1[$j][$k]; } } $this->_changedRow = $in_way[0]; $this->_changedCol = $in_way[1]; return; } // No where to go throw new Horde_Exception('Shrink or move neighboring block(s) out of the way first'); } } } else { // Make room to move into. $this->addCol($lastcol); } for ($i = 0; $i < $height; $i++) { if (!isset($this->_layout[$row + $i][$col])) { continue; } $prev = $this->_layout[$row + $i][$col]; // Move right hand edge $this->_layout[$row + $i][$lastcol] = 'covered'; // Move left hand edge $this->_layout[$row + $i][$col + 1] = $prev; $this->_layout[$row + $i][$col] = 'empty'; } $this->_changedRow = $row; $this->_changedCol = $col + 1; }
/** * Fetch the field values from a given array of variables. * * @access private * * @param array $variables An array of Horde_Core_Form_Variable objects to * fetch from. * @param array $info The array to be filled with the submitted * field values. */ protected function _getInfoFromVariables($variables, &$info) { foreach ($variables as $var) { if ($var->isArrayVal()) { $var->getInfo($this->_vars, $values); if (is_array($values)) { $varName = str_replace('[]', '', $var->getVarName()); foreach ($values as $i => $val) { $info[$i][$varName] = $val; } } } else { if (Horde_Array::getArrayParts($var->getVarName(), $base, $keys)) { if (!isset($info[$base])) { $info[$base] = array(); } $pointer =& $info[$base]; while (count($keys)) { $key = array_shift($keys); if (!isset($pointer[$key])) { $pointer[$key] = array(); } $pointer =& $pointer[$key]; } $var->getInfo($this->_vars, $pointer); } else { $var->getInfo($this->_vars, $info[$var->getVarName()]); } } } }
public function testArraySortKey() { Horde_Array::arraySort($this->array, 'desc'); $this->assertEquals(array(1 => array('name' => 'aaaa', 'desc' => 'aaa foo long desc'), 0 => array('name' => 'foo', 'desc' => 'foo long desc'), 4 => array('name' => 'umbrage', 'desc' => 'resentment'), 3 => array('name' => 'zebra', 'desc' => 'Striped armadillos'), 2 => array('name' => 'baby', 'desc' => 'The test data was boring')), $this->array); }
/** * Determines if the file was uploaded or not. If not, will return the * appropriate error message. * * @param string $field The name of the field containing the uploaded * file. * @param string $name The file description string to use in the error * message. Default: 'file'. * * @throws Horde_Browser_Exception */ public function wasFileUploaded($field, $name = null) { if (is_null($name)) { $name = 'file'; } if (!($uploadSize = self::allowFileUploads())) { throw new Horde_Browser_Exception(Horde_Browser_Translation::t("File uploads not supported.")); } /* Get any index on the field name. */ $index = Horde_Array::getArrayParts($field, $base, $keys); if ($index) { /* Index present, fetch the error var to check. */ $keys_path = array_merge(array($base, 'error'), $keys); $error = Horde_Array::getElement($_FILES, $keys_path); /* Index present, fetch the tmp_name var to check. */ $keys_path = array_merge(array($base, 'tmp_name'), $keys); $tmp_name = Horde_Array::getElement($_FILES, $keys_path); } else { /* No index, simple set up of vars to check. */ if (!isset($_FILES[$field])) { throw new Horde_Browser_Exception(Horde_Browser_Translation::t("No file uploaded"), UPLOAD_ERR_NO_FILE); } $error = $_FILES[$field]['error']; if (is_array($error)) { $error = reset($error); } $tmp_name = $_FILES[$field]['tmp_name']; if (is_array($tmp_name)) { $tmp_name = reset($tmp_name); } } if (empty($_FILES)) { $error = UPLOAD_ERR_NO_FILE; } switch ($error) { case UPLOAD_ERR_NO_FILE: throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: No %s was uploaded."), $name), UPLOAD_ERR_NO_FILE); case UPLOAD_ERR_OK: if (is_uploaded_file($tmp_name) && !filesize($tmp_name)) { throw new Horde_Browser_Exception(Horde_Browser_Translation::t("The uploaded file appears to be empty. It may not exist on your computer."), UPLOAD_ERR_NO_FILE); } // SUCCESS break; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, $uploadSize), $error); case UPLOAD_ERR_PARTIAL: throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error); case UPLOAD_ERR_NO_TMP_DIR: throw new Horde_Browser_Exception(Horde_Browser_Translation::t("There was a problem with the file upload: The temporary folder used to store the upload data is missing."), $error); case UPLOAD_ERR_CANT_WRITE: // No reason to try to explain to user what a "PHP extension" is. // No reason to try to explain to user what a "PHP extension" is. case UPLOAD_ERR_EXTENSION: throw new Horde_Browser_Exception(Horde_Browser_Translation::t("There was a problem with the file upload: Can't write the uploaded data to the server."), $error); } }
$sorted[$decl['declaration']][] = array('filename' => $decl['filename'], 'line' => $decl['line']); } $ds = array(); foreach ($sorted as $type => $locations) { $d = array(); $d['title'] = sprintf(_("Declared as a %s"), $type); $d['files'] = array(); Horde_Array::arraySort($locations, 'filename', 0, false); foreach ($locations as $loc) { $href = Luxor::url($loc['filename'], array(), 'l' . $loc['line']); $d['files'][] = '<a href="' . $href . '">' . $loc['filename'] . ' ' . sprintf(_("Line %s"), $loc['line']) . '</a>'; } $ds[] = $d; } $references = $index->getReference($ident); Horde_Array::arraySort($references, 'filename', 0, false); $curfile = ''; $rs = array(); $r = array(); foreach ($references as $info) { if ($curfile != $info['filename']) { if ($r) { $rs[] = $r; } $curfile = $info['filename']; $r = array(); $r['file'] = '<a href="' . Luxor::url($info['filename']) . '">' . htmlspecialchars($info['filename']) . '</a>'; $r['lines'] = array(); } $r['lines'][] = '<a href="' . Luxor::url($info['filename'], array(), 'l' . $info['line']) . '">' . sprintf(_("Line %s"), $info['line']) . '</a>'; }
function getUploadedFileType($field) { /* Get any index on the field name. */ $index = Horde_Array::getArrayParts($field, $base, $keys); if ($index) { /* Index present, fetch the mime type var to check. */ $keys_path = array_merge(array($base, 'type'), $keys); $type = Horde_Array::getElement($_FILES, $keys_path); $keys_path = array_merge(array($base, 'tmp_name'), $keys); $tmp_name = Horde_Array::getElement($_FILES, $keys_path); } else { /* No index, simple set up of vars to check. */ $type = $_FILES[$field]['type']; $tmp_name = $_FILES[$field]['tmp_name']; } if (empty($type) || $type == 'application/octet-stream') { /* Type wasn't set on upload, try analising the upload. */ if (!($type = Horde_Mime_Magic::analyzeFile($tmp_name, isset($GLOBALS['conf']['mime']['magic_db']) ? $GLOBALS['conf']['mime']['magic_db'] : null))) { if ($index) { /* Get the name value. */ $keys_path = array_merge(array($base, 'name'), $keys); $name = Horde_Array::getElement($_FILES, $keys_path); /* Work out the type from the file name. */ $type = Horde_Mime_Magic::filenameToMime($name); /* Set the type. */ $keys_path = array_merge(array($base, 'type'), $keys); Horde_Array::getElement($_FILES, $keys_path, $type); } else { /* Work out the type from the file name. */ $type = Horde_Mime_Magic::filenameToMime($_FILES[$field]['name']); /* Set the type. */ $_FILES[$field]['type'] = Horde_Mime_Magic::filenameToMime($_FILES[$field]['name']); } } } return $type; }
function xtract() { global $cmd_options, $apps, $dirs, $debug, $test, $c, $gettext_version, $silence, $curdir; foreach ($cmd_options[0] as $option) { switch ($option[0]) { case 'h': usage(); footer(); case 'm': case '--module': $module = $option[1]; break; } } require_once HORDE_LIBS . 'Horde/Array.php'; if ($GLOBALS['php_support']) { $language = 'PHP'; } else { $language = 'C++'; } for ($i = 0; $i < count($dirs); $i++) { if (!empty($module) && $module != $apps[$i]) { continue; } echo sprintf(_("Extracting from %s... "), $apps[$i]); if ($apps[$i] == 'horde') { chdir(BASE); $files = search_ext('php', '.', true); foreach (array('admin', 'framework', 'lib', 'services', 'templates', 'util', 'config' . DS . 'themes') as $search_dir) { $files = array_merge($files, search_ext('(php|inc|js)', $search_dir)); } $files = array_merge($files, search_ext('dist', 'config')); $sh = $GLOBALS['xgettext'] . ' --language=' . $language . ' --from-code=iso-8859-1 --keyword=_ --sort-output --copyright-holder="Horde Project"'; if ($gettext_version[0] > 0 || $gettext_version[1] > 11) { $sh .= ' --msgid-bugs-address="*****@*****.**"'; } $file = $dirs[$i] . DS . 'po' . DS . $apps[$i] . '.pot'; $sh .= ' -o ' . $file . '.tmp ' . implode(' ', $files); if (@file_exists(BASE . '/po/translation.php')) { $sh .= ' po/translation.php'; } if (!$debug) { $sh .= $silence; } if ($debug || $test) { $c->writeln(_("Executing:")); $c->writeln($sh); } if (!$test) { exec($sh); } } else { chdir($dirs[$i]); $files = search_ext('(php|inc|js)'); $files = array_filter($files, create_function('$file', 'return substr($file, 0, 9) != "." . DS . "config" . DS;')); $files = array_merge($files, search_ext('dist', 'config')); $sh = $GLOBALS['xgettext'] . ' --language=' . $language . ' --keyword=_ --sort-output --copyright-holder="Horde Project"'; if ($gettext_version[0] > 0 || $gettext_version[1] > 11) { $sh .= ' --msgid-bugs-address="*****@*****.**"'; } $file = 'po' . DS . $apps[$i] . '.pot'; $sh .= ' -o ' . $file . '.tmp ' . implode(' ', $files) . ($debug ? '' : $silence); if ($debug || $test) { $c->writeln(_("Executing:")); $c->writeln($sh); } if (!$test) { exec($sh); } } if (file_exists($file)) { $diff = array_diff(file($file . '.tmp'), file($file)); $diff = Horde_Array::grep($diff, '^"POT-Creation-Date:', false); } if (!file_exists($file) || count($diff)) { @unlink($file); rename($file . '.tmp', $file); $c->writeln($c->green(_("updated"))); } else { @unlink($file . '.tmp'); $c->writeln($c->bold(_("not changed"))); } chdir($curdir); } }