[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/sitemgr/inc/ -> class.Sites_BO.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare SiteMgr - Web Content Management                              *
   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.Sites_BO.inc.php 20295 2006-02-15 12:31:25Z  $ */
  13  
  14      class Sites_BO
  15      {
  16  
  17          var $xml_functions  = array();
  18          var $soap_functions = array();
  19  
  20          var $debug = False;
  21  
  22          var $so    = '';
  23          var $start = 0;
  24          var $query = '';
  25          var $sort  = '';
  26          var $order = '';
  27          var $total = 0;
  28  
  29          var $current_site;
  30          var $number_of_sites;
  31  
  32          var $use_session = False;
  33  
  34  		function Sites_BO($session=False)
  35          {
  36              //Web site definitions are stored as top level categories
  37              $this->so =& CreateObject('sitemgr.Sites_SO');
  38  
  39              if($session)
  40              {
  41                  $this->read_sessiondata();
  42                  $this->use_session = True;
  43              }
  44  
  45              foreach(array('start','query','sort','order') as $var)
  46              {
  47                  if (isset($_POST[$var]))
  48                  {
  49                      $this->$var = $_POST[$var];
  50                  }
  51                  elseif (isset($_GET[$var]))
  52                  {
  53                      $this->$var = $_GET[$var];
  54                  }
  55              }
  56          }
  57  
  58  		function save_sessiondata($data)
  59          {
  60              if ($this->use_session)
  61              {
  62                  if($this->debug) { echo '<br>Save:'; _debug_array($data); }
  63                  $GLOBALS['egw']->session->appsession('session_data','sitemgr_sites',$data);
  64              }
  65          }
  66  
  67  		function read_sessiondata()
  68          {
  69              $data = $GLOBALS['egw']->session->appsession('session_data','sitemgr_sites');
  70              if($this->debug) { echo '<br>Read:'; _debug_array($data); }
  71  
  72              $this->start  = $data['start'];
  73              $this->query  = $data['query'];
  74              $this->sort   = $data['sort'];
  75              $this->order  = $data['order'];
  76          }
  77  
  78  		function list_sites($limit=True)
  79          {
  80              return $this->so->getWebsites($limit,$this->start,$this->sort,$this->order,$this->query,$this->total);
  81          }
  82  
  83  		function getnumberofsites()
  84          {
  85              return $this->so->getnumberofsites();
  86          }
  87  
  88  		function read($id)
  89          {
  90              $result = $this->so->read($id);
  91              if ($result)
  92              {
  93                  $result['sitelanguages'] = $result['site_languages'] ? explode(',',$result['site_languages']) : array('en');;
  94                  foreach($result['sitelanguages'] as $lang)
  95                  {
  96                      $langinfo = $GLOBALS['Common_BO']->cats->getCategory($id,$lang,True);
  97                      $result['site_name_' . $lang] = $langinfo->name;
  98                      $result['site_desc_' . $lang] = $langinfo->description;
  99                  }
 100                  $result['default_theme'] = $result['themesel'];    // set the new name
 101                  $result['app'] = 'sitemgr'; // we need this for ImageUpload in htmlarea
 102                  $result['admin_method'] = $GLOBALS['phpgw']->link('/index.php', 'menuaction=sitemgr.Common_UI.DisplayPrefs');
 103                  $GLOBALS['phpgw']->session->appsession('UploadImage','phpgwapi',$result);
 104                  return $result;
 105              }
 106              else
 107              {
 108                  return False;
 109              }
 110          }
 111  
 112  		function get_adminlist($site_id)
 113          {
 114              return $GLOBALS['Common_BO']->acl->get_permission_list($site_id);
 115          }
 116  
 117  		function add($site)
 118          {
 119              $site_id = $this->so->add($site);
 120              //$GLOBALS['Common_BO']->cats->saveCategoryLang($site_id, $site['name'],$site['description'],$site['savelang']);
 121              $GLOBALS['Common_BO']->acl->set_adminlist($site_id,$site['adminlist']);
 122              return $site_id;
 123          }
 124  
 125  		function update($site_id,$site)
 126          {
 127              $this->so->update($site_id,$site);
 128  
 129              $GLOBALS['Common_BO']->acl->set_adminlist($site_id,$site['adminlist']);
 130          }
 131  
 132  		function saveprefs($prefs,$site_id=CURRENT_SITE_ID)
 133          {
 134              if (isset($prefs['default_theme']))
 135              {
 136                  $prefs['themesel'] = $prefs['default_theme'];    // use the new name
 137              }
 138              $this->so->saveprefs($prefs,$site_id);
 139              $site_languages = $prefs['site_languages'] ? $prefs['site_languages'] : $this->current_site['site_languages'];
 140              $site_languages = $site_languages ? explode(',',$site_languages) : array('en');
 141              foreach ($site_languages as $lang)
 142              {
 143                  $GLOBALS['Common_BO']->cats->saveCategoryLang(
 144                      $site_id,
 145                      $prefs['site_name_' . $lang],
 146                      $prefs['site_desc_' . $lang],
 147                      $lang
 148                  );
 149              }
 150              $this->current_site = $this->read($site_id);
 151          }
 152  
 153  		function delete($id)
 154          {
 155              if (!$GLOBALS['egw']->acl->check('run',1,'admin'))
 156              {
 157                  return False;
 158              }
 159               $GLOBALS['Common_BO']->cats->removeCategory($id,True,True);
 160               $this->so->delete($id);
 161              return True;
 162          }
 163  
 164  		function urltoid($url)
 165          {
 166              $site_id = $this->so->urltoid($url);
 167  
 168              if ($site_id === False)    // nothing found, try only the path
 169              {
 170                  $parts = parse_url($url);
 171  
 172                  $site_id = $this->so->urltoid($parts['path']);
 173              }
 174              return $site_id;
 175          }
 176  
 177  
 178  		function set_currentsite($site_url,$mode)
 179          {
 180              if ($site_url)
 181              {
 182                  $this->current_site = $this->read($this->urltoid($site_url));
 183              }
 184              else
 185              {
 186                  $GLOBALS['egw']->preferences->read_repository();
 187                  $siteswitch = get_var('siteswitch');
 188                  if ($siteswitch)
 189                  {
 190                      $this->current_site = $this->read($siteswitch);
 191                      $GLOBALS['egw']->preferences->change('sitemgr','currentsite',$siteswitch);
 192                      $GLOBALS['egw']->preferences->save_repository(True);
 193                  }
 194                  else
 195                  {
 196                      $currentsite = $GLOBALS['egw_info']['user']['preferences']['sitemgr']['currentsite'];
 197                      if($currentsite)
 198                      {
 199                          $this->current_site = $this->read($currentsite);
 200                      }
 201                  }
 202              }
 203              if (!$this->current_site)
 204              {
 205                  $allsites = $this->so->list_siteids();
 206                  if ($allsites)
 207                  {
 208                      $this->current_site = $this->read($allsites[0]);
 209                      $GLOBALS['egw']->preferences->change('sitemgr','currentsite',$allsites[0]);
 210                      $GLOBALS['egw']->preferences->save_repository(True);
 211                  }
 212                  else
 213                  {
 214                      return False;
 215                  }
 216              }
 217              // overwrite selected theme by user
 218              if (isset($_GET['themesel']) && ($theme_info = $GLOBALS['Common_BO']->theme->getThemeInfos($_GET['themesel'])))
 219              {
 220                  $GLOBALS['egw']->session->appsession('themesel','sitemgr-site',$theme_info['value']);
 221                  $this->current_site['themesel'] = $theme_info['value'];
 222              }
 223              elseif ($theme = $GLOBALS['egw']->session->appsession('themesel','sitemgr-site'))
 224              {
 225                  $this->current_site['themesel'] = $theme;
 226              }
 227              define('CURRENT_SITE_ID',$this->current_site['site_id']);
 228              $this->setmode($mode);
 229              return True;
 230          }
 231  
 232  		function setmode($mode)
 233          {
 234              $this->current_site['mode'] = $mode;
 235              $GLOBALS['Common_BO']->setvisiblestates($mode);
 236              $GLOBALS['Common_BO']->cats->setcurrentcats();
 237          }
 238  
 239          //this function is here so that we can retrieve basic info from sitemgr-link without creating COMMON_BO
 240  		function get_currentsiteinfo()
 241          {
 242              $GLOBALS['egw']->preferences->read_repository();
 243              $currentsite = $GLOBALS['egw_info']['user']['preferences']['sitemgr']['currentsite'];
 244              if($currentsite)
 245              {
 246                  $info = $this->so->read2($currentsite);
 247              }
 248              if (!$info)
 249              {
 250                  $allsites = $this->so->list_siteids();
 251                  $info = $this->so->read2($allsites[0]);
 252                  $GLOBALS['egw']->preferences->change('sitemgr','currentsite',$allsites[0]);
 253                  $GLOBALS['egw']->preferences->save_repository(True);
 254              }
 255              return $info;
 256          }
 257      }


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