[ 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.Categories_UI.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.Categories_UI.inc.php 20295 2006-02-15 12:31:25Z  $ */
  13  
  14  class Categories_UI
  15  {
  16      var $common_ui;
  17      var $cat_bo;
  18      var $acl;
  19      var $isadmin;
  20      var $t;
  21      var $sitelanguages;
  22      
  23      var $public_functions = array
  24      (
  25          'edit' => True,
  26          'delete' => True
  27      );
  28          
  29  	function Categories_UI()
  30      {
  31          $this->common_ui =& CreateObject('sitemgr.Common_UI',True);
  32          $this->t = $GLOBALS['egw']->template;
  33          $this->cat_bo = $GLOBALS['Common_BO']->cats;
  34          $this->cat =& CreateObject('sitemgr.Category_SO', True);
  35          $this->acl = $GLOBALS['Common_BO']->acl;
  36          $this->isadmin = $this->acl->is_admin();
  37          $this->sitelanguages = $GLOBALS['Common_BO']->sites->current_site['sitelanguages'];
  38      }
  39  
  40  	function edit()
  41      {
  42          if (!$this->isadmin)
  43          {
  44              $GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=sitemgr.Outline_UI.manage'));
  45              return False;
  46          }
  47      
  48          $GLOBALS['Common_BO']->globalize(array(
  49              'inputcatname','inputcatdesc','inputcatid','inputsortorder','inputparent','inputstate',
  50              'inputindexpage','inputparentold','savelanguage','inputgetparentpermissions','inputapplypermissionstosubs',
  51              'inputgroupaccessread','inputgroupaccesswrite','inputindividualaccessread','inputindividualaccesswrite'
  52          ));
  53          
  54          global $btnSave, $inputcatid,$inputcatname,$inputcatdesc,$inputsortorder,$inputparent,$inputparentold,$inputindexpage,$inputstate;
  55          global $inputgroupaccessread, $inputgroupaccesswrite, $inputindividualaccessread, $inputindividualaccesswrite;
  56          global $savelanguage, $inputgetparentpermissions,$inputapplypermissionstosubs;
  57          $cat_id = $inputcatid ? $inputcatid : $_GET['cat_id'];
  58          
  59          if ($_POST['btnDelete'])
  60          {
  61              return $this->delete($cat_id);
  62          }
  63          $focus_reload_close = 'window.focus();';
  64          
  65          if ($_POST['btnSave'] || $_POST['btnApply'])
  66          {
  67              if ($inputcatname == '' || $inputcatdesc == '')
  68              {
  69                  $error = lang('You failed to fill in one or more required fields.');
  70                  $this->t->set_var('message',$error);
  71              }
  72              else
  73              {
  74                  $cat_id =  $cat_id ? $cat_id : $this->cat_bo->addCategory('','');
  75                  
  76                  $groupaccess = array_merge_recursive((array)$inputgroupaccessread, (array)$inputgroupaccesswrite);
  77                  $individualaccess = array_merge_recursive((array)$inputindividualaccessread, (array)$inputindividualaccesswrite);
  78                  $savelanguage = $savelanguage ? $savelanguage : $this->sitelanguages[0];
  79                  $this->cat_bo->saveCategoryInfo($cat_id, $inputcatname, $inputcatdesc, $savelanguage, $inputsortorder, $inputstate, $inputparent, $inputparentold,$inputindexpage);
  80                  if ($inputgetparentpermissions)
  81                  {
  82                      $this->cat_bo->saveCategoryPermsfromparent($cat_id);
  83                  }
  84                  else
  85                  {
  86                      $this->cat_bo->saveCategoryPerms($cat_id, $groupaccess, $individualaccess);
  87                  }
  88                  if ($inputapplypermissionstosubs)
  89                  {
  90                      $this->cat_bo->applyCategoryPermstosubs($cat_id);
  91                  }
  92                  $this->t->set_var('message',lang('Category saved'));
  93                  $focus_reload_close = 'opener.location.reload();';
  94                  if ($_POST['btnSave'])
  95                  {
  96                      $focus_reload_close .= 'self.close();';
  97                  }
  98              }
  99          }
 100          
 101          if ($cat_id)
 102          {
 103              //we use force here since we might edit an archive category
 104              $cat = $this->cat_bo->getCategory($cat_id,$savelanguage,True);
 105          }
 106          
 107          $GLOBALS['egw']->common->egw_header();
 108          $this->t->set_file('EditCategory', 'edit_category.tpl');
 109          $this->t->set_block('EditCategory','GroupBlock', 'GBlock');
 110          
 111          if (count($this->sitelanguages) > 1)
 112          {
 113              $select = lang('as') . ' <select name="savelanguage">';
 114              foreach ($this->sitelanguages as $lang)
 115              {
 116                  $selected= '';
 117                  if ($lang == $savelanguage)
 118                  {
 119                      $selected = 'selected="selected" ';
 120                  }
 121                  $select .= '<option ' . $selected .'value="' . $lang . '">'. $GLOBALS['Common_BO']->getlangname($lang) . '</option>';
 122              }
 123              $select .= '</select> ';
 124              $this->t->set_var('savelang',$select);
 125          }
 126          $indexpageselect = '';
 127          $pages = $GLOBALS['Common_BO']->pages->getPageOptionList($cat_id,'Automatic index',$cat->state ? $cat->state : 'Production');
 128          foreach($pages as $page)
 129          {
 130              $indexpageselect .= '<option value="'.$page[value].'"'.
 131                  ($page['value'] == $cat->index_page_id ? ' selected="1"' : '').'>'.$page[display]."</option>\n";
 132          }
 133          $this->t->set_var(array(
 134              'action_url' => $GLOBALS['egw']->link('/index.php',array('menuaction'=>'sitemgr.Categories_UI.edit')),
 135              'focus_reload_close' => $focus_reload_close,
 136              'add_edit' => ($cat_id ? lang('Edit Category') : lang('Add Category')),
 137              'cat_id' => $cat_id,
 138              'catname' => $cat->name,
 139              'catdesc' => $cat->description,
 140              'indexpageselect' => $indexpageselect,
 141              'sort_order' => $cat->sort_order,
 142              'parent_dropdown' => $this->getParentOptions($_GET['addsub'] ? $_GET['addsub'] : $cat->parent,$cat_id),
 143              'stateselect' => $GLOBALS['Common_BO']->inputstateselect($cat->state),
 144              'old_parent' => $cat->parent,
 145              'lang_basic' => lang('Basic Settings'),
 146              'lang_catname' => lang('Category Name'),
 147              'lang_catsort' => lang('Sort Order'),
 148              'lang_catparent' => lang('Parent'),
 149              'lang_catdesc' => lang('Category Description'),
 150              'lang_indexpage' => lang('Index'),
 151              'lang_groupaccess' => lang('Group Access Permissions'),
 152              'lang_groupname' => lang('Group Name'),
 153              'lang_readperm' => lang('Read Permission'),
 154              'lang_writeperm' => lang('Write Permission'),
 155              'lang_implies' => lang('implies read permission'),
 156              'lang_useraccess' => lang('Individual Access Permissions'),
 157              'lang_username' => lang('User Name'),
 158              'lang_apply' => lang('Apply'),
 159              'lang_reload' => lang('Reload'),
 160              'lang_cancel' => lang('Cancel'),
 161              'lang_save' => lang('Save'),
 162              'lang_delete' => lang('Delete'),
 163              'lang_confirm' => lang('Are you sure you want to delete the category %1 and all of its associated pages?  You cannot retrieve the deleted pages if you continue.',$cat->name),
 164              'lang_state' => lang('State'),
 165              'lang_getparentpermissions' => lang('Fill in permissions from parent category? If you check this, below values will be ignored'),
 166              'lang_applypermissionstosubs' => lang('Apply permissions also to subcategories?'),
 167              'lang_required' => lang('Required Fields'),
 168          ));
 169          
 170          $acct =& CreateObject('phpgwapi.accounts');
 171          $grouplist = $this->acl->get_group_list();
 172          $permissionlist = ($cat_id ? $this->acl->get_group_permission_list($cat_id) : array());
 173          if($grouplist)
 174          {
 175              for($i = 0; $i < count($grouplist); $i++ )
 176              {
 177                  //$account_name = $acct->id2name($permissionlist[$i]['account_id']);
 178                  //$this->t->set_var('group_id',$permissionlist[$i]['account_id']);
 179                  $account_name = $grouplist[$i]['account_lid'];
 180                  $account_id = $grouplist[$i]['account_id'];
 181                  $this->t->set_var('group_id',$account_id);
 182                  if ($cat_id)
 183                  {
 184                      $permission_id = $permissionlist[$account_id];
 185                  }
 186                  else
 187                  {
 188                      $permission_id = 0;
 189                  }
 190                  
 191                  $this->t->set_var('groupname', $account_name);
 192                  if ($permission_id & EGW_ACL_READ)  
 193                  {
 194                      $this->t->set_var('checkedgroupread','CHECKED="1"');
 195                  }
 196                  else
 197                  {
 198                      $this->t->set_var('checkedgroupread','');
 199                  }
 200                  if ($permission_id & EGW_ACL_ADD)
 201                  {
 202                      $this->t->set_var('checkedgroupwrite','CHECKED="1"');
 203                  }
 204                  else
 205                  {
 206                      $this->t->set_var('checkedgroupwrite','');
 207                  }
 208                  
 209                  $this->t->parse('GBlock', 'GroupBlock', True);
 210              }
 211          }
 212          else
 213          {
 214              $this->t->set_var('groupname',lang("No groups defined."));
 215          }
 216          
 217          $this->t->set_block('EditCategory','UserBlock', 'UBlock');
 218          
 219          $userlist = $this->acl->get_user_list();
 220          $userpermissionlist = $this->acl->get_user_permission_list($cat_id);
 221          if($userlist)
 222          {
 223              for($i = 0; $i < count($userlist); $i++ )
 224              {
 225                  $user_name = $userlist[$i]['account_lid'];
 226                  $user_id = $userlist[$i]['account_id'];
 227                  if ($cat_id)
 228                  {
 229                      $user_permission_id = $userpermissionlist[$user_id];
 230                  }
 231                  else
 232                  {
 233                      $user_permission_id = 0;
 234                  }
 235                  $this->t->set_var('user_id', $user_id);
 236                  
 237                  $this->t->set_var('username', $user_name);
 238                  if ($user_permission_id & EGW_ACL_READ )
 239                  {
 240                      $this->t->set_var('checkeduserread','CHECKED="1"');
 241                  }
 242                  else
 243                  {
 244                      $this->t->set_var('checkeduserread','');
 245                  }
 246                  if ($user_permission_id & EGW_ACL_ADD )
 247                  {
 248                      $this->t->set_var('checkeduserwrite','CHECKED="1"');
 249                  }
 250                  else
 251                  {
 252                      $this->t->set_var('checkeduserwrite','');
 253                  }
 254                  $this->t->parse('UBlock', 'UserBlock', True);
 255              }
 256          }
 257          else
 258          {
 259              $this->t->set_var('username',lang("No users defined."));
 260          }
 261          
 262          $this->t->pfp('out','EditCategory');
 263          
 264          $this->common_ui->DisplayFooter();
 265      }
 266      
 267  	function getParentOptions($selected_id=0,$skip_id=0)
 268      {
 269          $option_list=$this->cat_bo->getCategoryOptionList();
 270          if (!$skip_id)
 271          {
 272              $skip_id = -1;
 273          }
 274          $retval="\n".'<SELECT NAME="inputparent">'."\n";
 275          foreach($option_list as $option)
 276          {
 277              if ($option['value']!=$skip_id)
 278              {
 279                  $selected='';
 280                  if ($option['value']==$selected_id)
 281                  {
 282                      $selected=' SELECTED="1"';
 283                  }
 284                  $retval.='<OPTION VALUE="'.$option['value'].'"'.$selected.'>'.
 285                  $option['display'].'</OPTION>'."\n";
 286              }
 287          }
 288          $retval.='</SELECT>';
 289          return $retval;
 290      }
 291      
 292  	function delete($cat_id = 0)
 293      {
 294          if (!$this->isadmin)
 295          {
 296              $GLOBALS['egw']->redirect($GLOBALS['egw']->link('/index.php','menuaction=sitemgr.Outline_UI.manage'));
 297              return;
 298          }
 299          
 300          $standalone = $_GET['standalone'] || $cat_id; // standalone => close this window after deleting
 301          
 302          if (!$cat_id) $cat_id = $_GET['cat_id'];
 303          
 304          if ($_POST['btnDelete'] || $_POST['btnCancel'] || $standalone)
 305          {
 306              if ($_POST['btnDelete'] || $standalone)
 307              {
 308                  $cat = $this->cat_bo->getCategory($cat_id,False,True);
 309                  $this->cat_bo->removeCategory($cat_id);
 310                  $parent_url = $GLOBALS['Common_BO']->sites->current_site['site_url'].'?category_id='.$cat->parent;
 311                  if (!isset($GLOBALS['egw_info']['server']['usecookies']) || !$GLOBALS['egw_info']['server']['usecookies'])
 312                  {
 313                      $parent_url .= '&sessionid='. @$GLOBALS['egw_info']['user']['sessionid'];
 314                      $parent_url .= '&kp3='.($_GET['kp3'] ? $_GET['kp3'] : $GLOBALS['egw_info']['user']['kp3']);
 315                      $parent_url .= '&domain='.@$GLOBALS['egw_info']['user']['domain'];
 316                  }
 317                  $reload = "opener.location.href='$parent_url';";
 318              }
 319              if ($standalone)
 320              {
 321                  echo '<html><head></head><body onload="'.$reload.'self.close()"></body></html>';
 322                  return;
 323              }
 324              $GLOBALS['egw']->redirect_link('/index.php','menuaction=sitemgr.Outline_UI.manage');
 325          }
 326          
 327          $this->common_ui->DisplayHeader();
 328          
 329          $cat = $this->cat_bo->getCategory($cat_id,$this->sitelanguages[0]);
 330          $this->t->set_file('ConfirmDelete','confirmdelete.tpl');
 331          $this->t->set_var('deleteheader',lang('Are you sure you want to delete the category %1 and all of its associated pages?  You cannot retrieve the deleted pages if you continue.',$cat->name));
 332          $this->t->set_var('cat_id',$cat_id);
 333          $this->t->set_var('lang_yes',lang('Yes, please delete it'));
 334          $this->t->set_var('lang_no',lang('Cancel the delete'));
 335          $this->t->set_var('standalone',$_GET['standalone']);
 336          $this->t->set_var('action_url',$GLOBALS['egw']->link('/index.php',array('menuaction'=>'sitemgr.Categories_UI.delete','cat_id'=>$cat_id)));
 337          $this->t->pfp('out','ConfirmDelete');
 338      }
 339  }
 340  ?>


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