[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/admin/inc/ -> class.uiserver.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare - phpgroupware Peer Servers                                   *
   4      * http://www.egroupware.org                                                *
   5      * -----------------------------------------------                          *
   6      *  This program is free software; you can redistribute it and/or modify it *
   7      *  under the terms of the GNU General Public License as published by the   *
   8      *  Free Software Foundation; either version 2 of the License, or (at your  *
   9      *  option) any later version.                                              *
  10      \**************************************************************************/
  11  
  12      /* $Id: class.uiserver.inc.php 20295 2006-02-15 12:31:25Z  $ */
  13  
  14      class uiserver
  15      {
  16          var $public_functions = array(
  17              'list_servers' => True,
  18              'edit'         => True,
  19              'add'          => True,
  20              'delete'       => True
  21          );
  22  
  23          var $start = 0;
  24          var $limit = 0;
  25          var $query = '';
  26          var $sort  = '';
  27          var $order = '';
  28  
  29          var $debug = False;
  30  
  31          var $bo = '';
  32          var $nextmatchs = '';
  33  
  34  		function uiserver()
  35          {
  36              if ($GLOBALS['egw']->acl->check('peer_server_access',1,'admin'))
  37              {
  38                  $GLOBALS['egw']->redirect_link('/index.php');
  39              }
  40              $this->acl_search = !$GLOBALS['egw']->acl->check('peer_server_access',2,'admin');
  41              $this->acl_add    = !$GLOBALS['egw']->acl->check('peer_server_access',4,'admin');
  42              $this->acl_view   = !$GLOBALS['egw']->acl->check('peer_server_access',8,'admin');
  43              $this->acl_edit   = !$GLOBALS['egw']->acl->check('peer_server_access',16,'admin');
  44              $this->acl_delete = !$GLOBALS['egw']->acl->check('peer_server_access',32,'admin');
  45  
  46              $this->bo =& CreateObject('admin.boserver',True);
  47              $this->nextmatchs =& CreateObject('phpgwapi.nextmatchs');
  48  
  49              $this->start = $this->bo->start;
  50              $this->limit = $this->bo->limit;
  51              $this->query = $this->bo->query;
  52              $this->sort  = $this->bo->sort;
  53              $this->order = $this->bo->order;
  54              if($this->debug) { $this->_debug_sqsof(); }
  55              /* _debug_array($this); */
  56          }
  57  
  58  		function _debug_sqsof()
  59          {
  60              $data = array(
  61                  'start' => $this->start,
  62                  'limit' => $this->limit,
  63                  'query' => $this->query,
  64                  'sort'  => $this->sort,
  65                  'order' => $this->order
  66              );
  67              echo '<br>UI:';
  68              _debug_array($data);
  69          }
  70  
  71  		function save_sessiondata()
  72          {
  73              $data = array(
  74                  'start' => $this->start,
  75                  'limit' => $this->limit,
  76                  'query' => $this->query,
  77                  'sort'  => $this->sort,
  78                  'order' => $this->order
  79              );
  80              $this->bo->save_sessiondata($data);
  81          }
  82  
  83  		function formatted_list($name,$list,$id='',$default=False)
  84          {
  85              $select  = "\n" .'<select name="' . $name . '"' . ">\n";
  86              if($default)
  87              {
  88                  $select .= '<option value="">' . lang('Please Select') . '</option>'."\n";
  89              }
  90              while (list($val,$key) = each($list))
  91              {
  92                  $select .= '<option value="' . $key . '"';
  93                  if ($key == $id && $id != '')
  94                  {
  95                      $select .= ' selected';
  96                  }
  97                  $select .= '>' . lang($val) . '</option>'."\n";
  98              }
  99  
 100              $select .= '</select>'."\n";
 101  
 102              return $select;
 103          }
 104  
 105  		function list_servers()
 106          {
 107              $GLOBALS['egw_info']['flags']['app_header'] = lang('Admin').' - '.lang('Peer Servers');
 108              $GLOBALS['egw']->common->egw_header();
 109              echo parse_navbar();
 110  
 111              $GLOBALS['egw']->template->set_file(array('server_list_t' => 'listservers.tpl'));
 112              $GLOBALS['egw']->template->set_block('server_list_t','server_list','list');
 113              if (!$this->acl_search)
 114              {
 115                  $GLOBALS['egw']->template->set_block('server_list_t','search','searchhandle');
 116              }
 117              if (!$this->acl_add)
 118              {
 119                  $GLOBALS['egw']->template->set_block('server_list_t','add','addhandle');
 120              }
 121  
 122              $GLOBALS['egw']->template->set_var('lang_action',lang('Server List'));
 123              $GLOBALS['egw']->template->set_var('add_action',$GLOBALS['egw']->link('/index.php','menuaction=admin.uiserver.edit'));
 124              $GLOBALS['egw']->template->set_var('lang_add',lang('Add'));
 125              $GLOBALS['egw']->template->set_var('lang_search',lang('Search'));
 126              $GLOBALS['egw']->template->set_var('actionurl',$GLOBALS['egw']->link('/index.php','menuaction=admin.uiserver.list_servers'));
 127              $GLOBALS['egw']->template->set_var('lang_done',lang('Cancel'));
 128              $GLOBALS['egw']->template->set_var('doneurl',$GLOBALS['egw']->link('/admin/index.php'));
 129  
 130              if(!$this->start)
 131              {
 132                  $this->start = 0;
 133              }
 134  
 135              if($GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] &&
 136                  $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] > 0)
 137              {
 138                  $this->limit = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
 139              }
 140              else
 141              {
 142                  $this->limit = 15;
 143              }
 144  
 145              $this->save_sessiondata();
 146              $servers = $this->bo->list_servers();
 147  
 148              $left  = $this->nextmatchs->left('/index.php',$this->start,$this->bo->total,'menuaction=admin.uiserver.list_servers');
 149              $right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->total,'menuaction=admin.uiserver.list_servers');
 150              $GLOBALS['egw']->template->set_var('left',$left);
 151              $GLOBALS['egw']->template->set_var('right',$right);
 152  
 153              $GLOBALS['egw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bo->total,$this->start));
 154              $GLOBALS['egw']->template->set_var('th_bg',$GLOBALS['egw_info']['theme']['th_bg']);
 155  
 156              $GLOBALS['egw']->template->set_var('sort_name',
 157                  $this->nextmatchs->show_sort_order($this->sort,'server_name',$this->order,'/index.php',lang('Name'),'&menuaction=admin.uiserver.list_servers'));
 158              $GLOBALS['egw']->template->set_var('sort_url',
 159                  $this->nextmatchs->show_sort_order($this->sort,'server_url',$this->order,'/index.php',lang('URL'),'&menuaction=admin.uiserver.list_servers'));
 160              $GLOBALS['egw']->template->set_var('sort_mode',
 161                  $this->nextmatchs->show_sort_order($this->sort,'server_mode',$this->order,'/index.php',lang('Mode'),'&menuaction=admin.uiserver.list_servers'));
 162              $GLOBALS['egw']->template->set_var('sort_security',
 163                  $this->nextmatchs->show_sort_order($this->sort,'server_security',$this->order,'/index.php',lang('Security'),'&menuaction=admin.uiserver.list_servers'));
 164              $GLOBALS['egw']->template->set_var('lang_default',lang('Default'));
 165              $GLOBALS['egw']->template->set_var('lang_edit',lang('Edit'));
 166              $GLOBALS['egw']->template->set_var('lang_delete',lang('Delete'));
 167  
 168              while(list($key,$server) = @each($servers))
 169              {
 170                  $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
 171                  $GLOBALS['egw']->template->set_var('tr_color',$tr_color);
 172                  $server_id = $server['server_id'];
 173  
 174                  $GLOBALS['egw']->template->set_var(array(
 175                      'server_name' => $GLOBALS['egw']->strip_html($server['server_name']),
 176                      'server_url'  => $GLOBALS['egw']->strip_html($server['server_url']),
 177                      'server_security' => $server['server_security'] ? strtoupper($server['server_security']) : lang('none'),
 178                      'server_mode' => strtoupper($server['server_mode'])
 179                  ));
 180  
 181                  $GLOBALS['egw']->template->set_var('edit','');
 182                  $GLOBALS['egw']->template->set_var('delete','');
 183                  if ($this->acl_edit)
 184                  {
 185                      $GLOBALS['egw']->template->set_var('edit','<a href="'.$GLOBALS['egw']->link('/index.php','menuaction=admin.uiserver.edit&server_id=' . $server_id).
 186                          '">'.lang('Edit').'</a>');
 187                  }
 188                  if ($this->acl_delete)
 189                  {
 190                      $GLOBALS['egw']->template->set_var('delete','<a href="'.$GLOBALS['egw']->link('/index.php','menuaction=admin.uiserver.delete&server_id=' . $server_id).
 191                          '">'.lang('Delete').'</a>');
 192                  }
 193                  $GLOBALS['egw']->template->parse('list','server_list',True);
 194              }
 195  
 196              $GLOBALS['egw']->template->parse('out','server_list_t',True);
 197              $GLOBALS['egw']->template->p('out');
 198          }
 199  
 200          /* This function handles add or edit */
 201  		function edit()
 202          {
 203              if ($_POST['done'])
 204              {
 205                  return $this->list_servers();
 206              }
 207              if ($_POST['delete'])
 208              {
 209                  return $this->delete();
 210                  
 211              }
 212              $server_id = get_var('server_id',array('POST','GET'));
 213  
 214              if (!$server_id && !$this->acl_add || $server_id && !$this->acl_edit)
 215              {
 216                  $GLOBALS['egw']->redirect_link('/index.php');
 217              }
 218              $is =& CreateObject('phpgwapi.interserver');
 219  
 220              $GLOBALS['egw']->template->set_file(array('form' => 'server_form.tpl'));
 221  
 222              if (!$this->acl_delete || !$server_id)
 223              {
 224                  $GLOBALS['egw']->template->set_block('form','delete','deletehandle');
 225                  $GLOBALS['egw']->template->set_var('deletehandle','');
 226              }
 227              $server = $this->bo->read($server_id);
 228  
 229              if ($_POST['save'])
 230              {
 231                  $errorcount = 0;
 232  
 233                  $tmp = $is->name2id($_POST['server_name']);
 234                  
 235                  if($tmp && $server_id != $tmp)
 236                  {
 237                      $error[$errorcount++] = lang('That server name has been used already !');
 238                  }
 239  
 240                  if (!$_POST['server_name'])
 241                  {
 242                      $error[$errorcount++] = lang('Please enter a name for that server !');
 243                  }
 244  
 245                  if (!$error)
 246                  {
 247                      $server_info = array(
 248                          'server_name' => addslashes($_POST['server_name']),
 249                          'server_url'  => addslashes($_POST['server_url']),
 250                          'trust_level' => (int)$_POST['trust_level'],
 251                          'trust_rel'   => (int)$_POST['trust_rel'],
 252                          'username'    => addslashes($_POST['server_username']),
 253                          'password'    => $_POST['server_password'] ? $_POST['server_password'] : $server['password'],
 254                          'server_mode' => addslashes($_POST['server_mode']),
 255                          'server_security' => addslashes($_POST['server_security']),
 256                          'admin_name'  => addslashes($_POST['admin_name']),
 257                          'admin_email' => addslashes($_POST['admin_email'])
 258                      );
 259                      if($server_id)
 260                      {
 261                          $server_info['server_id'] = $server_id;
 262                      }
 263                      $newid = $this->bo->edit($server_info);
 264                      $server = $this->bo->read($newid ? $newid : $server_info['server_id']);
 265                  }
 266              }
 267  
 268              if ($errorcount)
 269              {
 270                  $GLOBALS['egw']->template->set_var('message',$GLOBALS['egw']->common->error_list($error));
 271              }
 272              if (($_POST['save']) && (!$error) && (!$errorcount))
 273              {
 274                  if($server_id)
 275                  {
 276                      $GLOBALS['egw']->template->set_var('message',lang('Server %1 has been updated',$_POST['server_name']));
 277                  }
 278                  else
 279                  {
 280                      $GLOBALS['egw']->template->set_var('message',lang('Server %1 has been added',$_POST['server_name']));
 281                  }
 282              }
 283              if ((!$_POST['save']) && (!$error) && (!$errorcount))
 284              {
 285                  $GLOBALS['egw']->template->set_var('message','');
 286              }
 287  
 288              $GLOBALS['egw_info']['flags']['app_header'] = lang('Admin').' - '.($server_id ? lang('Edit Peer Server') : lang('Add Peer Server'));
 289              $GLOBALS['egw']->common->egw_header();
 290              echo parse_navbar();
 291  
 292              $GLOBALS['egw']->template->set_var('actionurl',$GLOBALS['egw']->link('/index.php','menuaction=admin.uiserver.edit'));
 293  
 294              $GLOBALS['egw']->template->set_var('lang_name',lang('Server name'));
 295              $GLOBALS['egw']->template->set_var('lang_url',lang('Server URL'));
 296              $GLOBALS['egw']->template->set_var('lang_trust',lang('Trust Level'));
 297              $GLOBALS['egw']->template->set_var('lang_relationship',lang('Trust Relationship'));
 298              $GLOBALS['egw']->template->set_var('lang_username',lang('Server Username'));
 299              $GLOBALS['egw']->template->set_var('lang_password',lang('Server Password'));
 300              $GLOBALS['egw']->template->set_var('lang_mode',lang('Server Type(mode)'));
 301              $GLOBALS['egw']->template->set_var('lang_security',lang('Security'));
 302              $GLOBALS['egw']->template->set_var('lang_admin_name',lang('Admin Name'));
 303              $GLOBALS['egw']->template->set_var('lang_admin_email',lang('Admin Email'));
 304              $GLOBALS['egw']->template->set_var('lang_save',lang('Save'));
 305              $GLOBALS['egw']->template->set_var('lang_add',lang('Add'));
 306              $GLOBALS['egw']->template->set_var('lang_default',lang('Default'));
 307              $GLOBALS['egw']->template->set_var('lang_reset',lang('Clear Form'));
 308              $GLOBALS['egw']->template->set_var('lang_done',lang('Cancel'));
 309              $GLOBALS['egw']->template->set_var('lang_delete',lang('Delete'));
 310  
 311              $GLOBALS['egw']->template->set_var('server_name',$server['server_name']);
 312              $GLOBALS['egw']->template->set_var('server_url',$server['server_url']);
 313              $GLOBALS['egw']->template->set_var('server_username',$server['username']);
 314              $GLOBALS['egw']->template->set_var('server_mode',$this->formatted_list('server_mode',$is->server_modes,$server['server_mode']));
 315              $GLOBALS['egw']->template->set_var('server_security',$this->formatted_list('server_security',$is->security_types,$server['server_security']));
 316              $GLOBALS['egw']->template->set_var('ssl_note', function_exists('curl_init') ? '&nbsp;' : lang('Note: SSL available only if PHP is compiled with curl support'));
 317              $GLOBALS['egw']->template->set_var('pass_note',$server_id ? '<br>'.lang('(Stored password will not be shown here)') : '');
 318              $GLOBALS['egw']->template->set_var('trust_level',$this->formatted_list('trust_level',$is->trust_levels,$server['trust_level']));
 319              $GLOBALS['egw']->template->set_var('trust_relationship',$this->formatted_list('trust_rel',$is->trust_relationships,$server['trust_rel'],True));
 320              $GLOBALS['egw']->template->set_var('admin_name',$GLOBALS['egw']->strip_html($server['admin_name']));
 321              $GLOBALS['egw']->template->set_var('admin_email',$GLOBALS['egw']->strip_html($server['admin_email']));
 322              $GLOBALS['egw']->template->set_var('server_id',$server_id);
 323  
 324              $GLOBALS['egw']->template->set_var(array(
 325                  'th'      => $GLOBALS['egw_info']['theme']['th_bg'],
 326                  'row_on'  => $GLOBALS['egw_info']['theme']['row_on'],
 327                  'row_off' => $GLOBALS['egw_info']['theme']['row_off']
 328              ));
 329              $GLOBALS['egw']->template->pparse('phpgw_body','form');
 330          }
 331  
 332  		function delete()
 333          {
 334              if (!$this->acl_delete)
 335              {
 336                  $GLOBALS['egw']->redirect_link('/index.php');
 337              }
 338              $server_id = get_var('server_id',array('POST','GET'));
 339              if ($_POST['yes'] || $_POST['no'])
 340              {
 341                  if ($_POST['yes'])
 342                  {
 343                      $this->bo->delete($server_id);
 344                  }
 345                  $GLOBALS['egw']->redirect_link('/index.php','menuaction=admin.uiserver.list_servers');
 346              }
 347              else
 348              {
 349                  $GLOBALS['egw']->common->egw_header();
 350                  echo parse_navbar();
 351  
 352                  $GLOBALS['egw']->template->set_file(array('server_delete' => 'delete_common.tpl'));
 353  
 354                  $GLOBALS['egw']->template->set_var(array(
 355                      'form_action' => $GLOBALS['egw']->link('/index.php','menuaction=admin.uiserver.delete'),
 356                      'hidden_vars' => '<input type="hidden" name="server_id" value="' . $server_id . '"><script>document.yesbutton.yesbutton.focus()</script>',
 357                      'messages' => lang('Are you sure you want to delete this server?'),
 358                      'no' => lang('No'),
 359                      'yes' => lang('Yes'),
 360                  ));
 361                  $GLOBALS['egw']->template->pparse('phpgw_body','server_delete');
 362              }
 363          }
 364      }
 365  ?>


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