Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
    $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>';
}
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 /**
  * 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);
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
        $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. */
Esempio n. 9
0
 /**
  * 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;
 }