[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/ -> groups.php (source)

   1  <?php
   2  /**
   3   * $Horde: horde/admin/groups.php,v 1.50.2.6 2006/07/13 09:01:53 jan Exp $
   4   *
   5   * Copyright 1999-2006 Chuck Hagenbuch <chuck@horde.org>
   6   *
   7   * See the enclosed file COPYING for license information (LGPL).  If you
   8   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
   9   */
  10  
  11  @define('HORDE_BASE', dirname(__FILE__) . '/..');
  12  require_once  HORDE_BASE . '/lib/base.php';
  13  require_once  'Horde/Menu.php';
  14  require_once  'Horde/Group.php';
  15  require_once 'Horde/Tree.php';
  16  
  17  if (!Auth::isAdmin()) {
  18      Horde::authenticationFailureRedirect();
  19  }
  20  
  21  $groups = &Group::singleton();
  22  $auth = &Auth::singleton($conf['auth']['driver']);
  23  
  24  $form = null;
  25  $reload = false;
  26  $actionID = Util::getFormData('actionID');
  27  $cid = Util::getFormData('cid');
  28  
  29  switch ($actionID) {
  30  case 'addchild':
  31      if ($cid == DATATREE_ROOT) {
  32          $form = 'addchild.inc';
  33          $gname = _("All Groups");
  34      } else {
  35          $group = &$groups->getGroupById($cid);
  36          if (!is_a($group, 'PEAR_Error')) {
  37              $gname = $group->getShortName();
  38              $form = 'addchild.inc';
  39          }
  40      }
  41      break;
  42  
  43  case 'addchildform':
  44      $parent = $cid;
  45      if ($parent == DATATREE_ROOT) {
  46          $child = &$groups->newGroup(Util::getFormData('child'));
  47          $result = $groups->addGroup($child);
  48      } else {
  49          $child = &$groups->newGroup(Util::getFormData('child'), $parent);
  50          $result = $groups->addGroup($child);
  51      }
  52      if (is_a($result, 'PEAR_Error')) {
  53          Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
  54          $notification->push(sprintf(_("\"%s\" was not created: %s."), $child->getShortName(), $result->getMessage()), 'horde.error');
  55      } else {
  56          $notification->push(sprintf(_("\"%s\" was added to the groups system."), $child->getShortName()), 'horde.success');
  57          $group = $child;
  58          $form = 'edit.inc';
  59          $reload = true;
  60      }
  61      break;
  62  
  63  case 'delete':
  64      $group = &$groups->getGroupById($cid);
  65      if (!is_a($group, 'PEAR_Error')) {
  66          $form = 'delete.inc';
  67      }
  68      break;
  69  
  70  case 'deleteform':
  71      if (Util::getFormData('confirm') == _("Delete")) {
  72          $group = &$groups->getGroupById($cid);
  73          if (is_a($group, 'PEAR_Error')) {
  74              $notification->push(_("Attempt to delete a non-existent group."), 'horde.error');
  75          } else {
  76              $result = $groups->removeGroup($group, true);
  77              if (is_a($result, 'PEAR_Error')) {
  78                  $notification->push(sprintf(_("Unable to delete \"%s\": %s."), $group->getShortName(), $result->getMessage()), 'horde.error');
  79               } else {
  80                  $notification->push(sprintf(_("Successfully deleted \"%s\"."), $group->getShortName()), 'horde.success');
  81                  $cid = null;
  82                  $reload = true;
  83              }
  84          }
  85      }
  86      break;
  87  
  88  case 'edit':
  89      $group = &$groups->getGroupById($cid);
  90      if (!is_a($group, 'PEAR_Error')) {
  91          $form = 'edit.inc';
  92      } elseif (($category = Util::getFormData('category')) !== null) {
  93          $group = &$groups->getGroup($category);
  94          if (!is_a($group, 'PEAR_Error')) {
  95              $form = 'edit.inc';
  96          } elseif (Util::getFormData('autocreate')) {
  97              $parent = Util::getFormData('parent');
  98              $group = &$groups->newGroup($category);
  99              $result = $groups->addGroup($group, $parent);
 100              if (!is_a($result, 'PEAR_Error')) {
 101                  $form = 'edit.inc';
 102              }
 103          }
 104      }
 105      break;
 106  
 107  case 'editform':
 108      $group = &$groups->getGroupById($cid);
 109  
 110      // make a copy of the group so we can restore it if there is an error.
 111      $restore = $group;
 112  
 113      // Add any new users.
 114      $newuser = Util::getFormData('new_user');
 115      if (!empty($newuser)) {
 116          if (is_array($newuser)) {
 117              foreach ($newuser as $new) {
 118                  $group->addUser($new, false);
 119              }
 120          } else {
 121              $group->addUser($newuser, false);
 122          }
 123      }
 124  
 125      // Remove any users marked for purging.
 126      $removes = Util::getFormData('remove');
 127      if (!empty($removes) && is_array($removes)) {
 128          foreach ($removes as $user => $junk) {
 129              $group->removeUser($user, false);
 130          }
 131      }
 132  
 133      // Set the email address of the group.
 134      $group->set('email', Util::getFormData('email'));
 135  
 136      // Save the group to the backend.
 137      $result = $group->save();
 138  
 139      if (is_a($result, 'PEAR_Error')) {
 140          $notification->push($result->getMessage(), 'horde.error');
 141          // restore backup copy
 142          $group = $restore;
 143      } else {
 144          $notification->push(sprintf(_("Updated \"%s\"."), $group->getShortName()), 'horde.success');
 145      }
 146  
 147      $form = 'edit.inc';
 148      $reload = true;
 149      break;
 150  }
 151  
 152  switch ($form) {
 153  case 'addchild.inc':
 154      $notification->push('document.add_child.child.focus()', 'javascript');
 155      break;
 156  
 157  case 'edit.inc':
 158      /* Set up the lists. */
 159      $users = $group->listUsers();
 160      if (is_a($users, 'PEAR_Error')) {
 161          $notification->push($users, 'horde.error');
 162          $users = array();
 163      }
 164      $all_users = $group->listAllUsers();
 165      if (is_a($all_users, 'PEAR_Error')) {
 166          $notification->push($all_users, 'horde.error');
 167          $all_users = array();
 168      }
 169      $inherited_users = array_diff($all_users, $users);
 170  
 171      if ($auth->hasCapability('list')) {
 172          $user_list = $auth->listUsers();
 173          if (is_a($user_list, 'PEAR_Error')) {
 174              $notification->push($user_list, 'horde.error');
 175              $user_list = array();
 176          }
 177          sort($user_list);
 178      } else {
 179          $user_list = array();
 180      }
 181      break;
 182  
 183  }
 184  
 185  $title = _("Group Administration");
 186  require  HORDE_TEMPLATES . '/common-header.inc';
 187  require  HORDE_TEMPLATES . '/admin/common-header.inc';
 188  $notification->notify(array('listeners' => 'status'));
 189  if (!empty($form)) {
 190      require HORDE_TEMPLATES . '/admin/groups/' . $form;
 191  }
 192  
 193  /* Get the perms tree. */
 194  $nodes = $groups->listGroups(true);
 195  $nodes[DATATREE_ROOT] = DATATREE_ROOT;
 196  
 197  /* Set up some node params. */
 198  $spacer = '&nbsp;&nbsp;&nbsp;&nbsp;';
 199  $icondir = array('icondir' => $registry->getImageDir());
 200  $group_node = $icondir + array('icon' => 'group.png');
 201  $add = Horde::applicationUrl('admin/groups.php?actionID=addchild');
 202  $edit = Horde::applicationUrl('admin/groups.php?actionID=edit');
 203  $delete = Horde::applicationUrl('admin/groups.php?actionID=delete');
 204  $edit_img = Horde::img('edit.png', _("Edit Group"));
 205  $delete_img = Horde::img('delete.png', _("Delete Group"));
 206  
 207  /* Set up the tree. */
 208  $tree = Horde_Tree::factory('admin_groups', 'javascript');
 209  $tree->setOption(array('alternate' => true, 'hideHeaders' => true));
 210  $tree->setHeader(array(array('width' => '50%')));
 211  
 212  /* Explicitly check for > 0 since we can be called with current = -1
 213   * for the root node. */
 214  if ($cid > 0) {
 215      $cid_parents = $groups->getGroupParentList($cid);
 216      if (is_a($cid_parents, 'PEAR_ERror')) {
 217          Horde::fatal($cid_parents, __FILE__, __LINE__);
 218      }
 219  }
 220  
 221  foreach ($nodes as $id => $node) {
 222      $node_params = ($cid == $id) ? array('class' => 'selected') : array();
 223      if ($id == DATATREE_ROOT) {
 224          $add_img = Horde::img('group.png', _("Add New Group"));
 225          $add_link = Horde::link(Util::addParameter($add, 'cid', $id), _("Add New Group")) . $add_img . '</a>';
 226  
 227          $base_node_params = $icondir + array('icon' => 'administration.png');
 228          $tree->addNode($id, null, _("All Groups"), 0, true, $base_node_params + $node_params, array($spacer, $add_link));
 229      } else {
 230          $node_params['url'] = Util::addParameter($edit, 'cid', $id);
 231          $add_img = Horde::img('group.png', _("Add Child Group"));
 232          $add_link = Horde::link(Util::addParameter($add, 'cid', $id), _("Add Child Group")) . $add_img . '</a>';
 233          $delete_link = Horde::link(Util::addParameter($delete, 'cid', $id), _("Delete Group")) . $delete_img . '</a>';
 234  
 235          $parent_id = $groups->getGroupParent($id);
 236          $group_extra = array($spacer, $add_link, $delete_link);
 237          $tree->addNode($id, $parent_id, $groups->getGroupShortName($node), $groups->getLevel($id) + 1, (isset($cid_parents[$id])) ? true : false, $group_node + $node_params, $group_extra);
 238      }
 239  }
 240  
 241  echo '<h1 class="header">' . Horde::img('group.png') . ' ' . _("Groups") . '</h1>';
 242  $tree->renderTree();
 243  require  HORDE_TEMPLATES . '/common-footer.inc';


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7