[ 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.Content_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.Content_UI.inc.php 20295 2006-02-15 12:31:25Z  $ */
  13  
  14      class Content_UI
  15      {
  16          var $common_ui;
  17          var $t;
  18          var $bo;
  19          var $modulebo;
  20          var $acl;
  21          var $viewable;
  22          var $sitelanguages;
  23          var $worklanguage;
  24          var $errormsg;
  25          var $langselect;
  26  
  27          var $public_functions = array
  28          (
  29              'manage' => True,
  30              'commit' => True,
  31              'archive' => True
  32          );
  33  
  34  		function Content_UI()
  35          {
  36              $this->common_ui =& CreateObject('sitemgr.Common_UI',True);
  37              $this->t = $GLOBALS['egw']->template;
  38              $this->t->egroupware_hack = False;
  39              $this->bo =& $GLOBALS['Common_BO']->content;
  40              $this->acl =& $GLOBALS['Common_BO']->acl;
  41              $this->modulebo =& $GLOBALS['Common_BO']->modules;
  42              $this->viewable =& $GLOBALS['Common_BO']->viewable;
  43  
  44              $this->sitelanguages = $GLOBALS['Common_BO']->sites->current_site['sitelanguages'];
  45              $savelanguage = $_POST['savelanguage'];
  46              $savelanguage = $savelanguage ? $savelanguage : 
  47                  ($GLOBALS['sitemgr_info']['userlang'] ? $GLOBALS['sitemgr_info']['userlang'] :
  48                  $GLOBALS['egw']->session->appsession('worklanguage','sitemgr') ?
  49                  $GLOBALS['egw']->session->appsession('worklanguage','sitemgr') : $this->sitelanguages[0]);
  50              //$GLOBALS['sitemgr_info']['userlang']=$savelanguage;
  51              $this->worklanguage = $savelanguage;
  52              //$GLOBALS['egw']->session->appsession('worklanguage','sitemgr',$savelanguage);
  53  
  54              $this->errormsg = array();
  55  
  56              if (count($this->sitelanguages) > 1)
  57              {
  58                  $this->langselect = lang('as') . ' <select name="savelanguage">';
  59                  foreach ($this->sitelanguages as $lang)
  60                  {
  61                      $selected= '';
  62                      if ($lang == $this->worklanguage)
  63                      {
  64                          $selected = 'selected="selected" ';
  65                      }
  66                      $this->langselect .= '<option ' . $selected .'value="' . $lang . '">'. $GLOBALS['Common_BO']->getlangname($lang) . '</option>';
  67                  }
  68                  $this->langselect .= '</select> ';
  69              }
  70          }
  71  
  72  		function manage()
  73          {
  74              $GLOBALS['Common_BO']->globalize(array(
  75                  'inputblockid','inputblocktitle','inputblocksort','inputblockview',
  76                  'inputstate','btnSaveBlock','btnApplyBlock','btnDeleteBlock','btnCreateVersion',
  77                  'btnDeleteVersion','inputmoduleid','inputarea','btnAddBlock','element'
  78              ));
  79              global $inputblockid, $inputblocktitle, $inputblocksort,$inputblockview;
  80              global $inputstate,$btnSaveBlock,$btnApplyBlock,$btnDeleteBlock,$btnCreateVersion;
  81              global $inputmoduleid, $inputarea, $btnAddBlock, $btnDeleteVersion, $element;
  82  
  83              global $page_id,$cat_id;
  84              $page_id = $_GET['page_id'];
  85              $cat_id = $_GET['cat_id'];
  86              $block_id = $_GET['block_id'];
  87  
  88              if ($block_id)
  89              {
  90                  $focus_reload_close = 'window.focus();';
  91              }
  92              elseif ($page_id)
  93              {
  94                  $page = $GLOBALS['Common_BO']->pages->getPage($page_id);
  95                  if (!$GLOBALS['Common_BO']->acl->can_write_category($page->cat_id))
  96                  {
  97                      $GLOBALS['egw']->redirect_link('/index.php','menuaction=sitemgr.Outline_UI.manage');
  98                  }
  99                  $page_or_cat_name = $page->name;
 100                  $cat_id = $page->cat_id;
 101                  $goto = lang('Page manager');
 102                  $scopename = lang('Page');
 103              }
 104              elseif ($cat_id && $cat_id != CURRENT_SITE_ID)
 105              {
 106                  $cat = $GLOBALS['Common_BO']->cats->getCategory($cat_id);
 107                  if (!$GLOBALS['Common_BO']->acl->can_write_category($cat_id))
 108                  {
 109                      $GLOBALS['egw']->redirect_link('/index.php','menuaction=sitemgr.Outline_UI.manage');
 110                  }
 111                  $page_or_cat_name = $cat->name;
 112                  $page_id = 0;
 113                  $goto = lang('Category manager');
 114                  $scopename = lang('Category');
 115              }
 116              else
 117              {
 118                  $page_id = 0;
 119                  $scopename = lang('Site');
 120              }
 121  
 122              if ($btnAddBlock || $_GET['add_block'])
 123              {
 124                  if ($_GET['add_block'])
 125                  {
 126                      $inputmoduleid = $_GET['add_block'];
 127                      $inputarea = $_GET['area'];
 128                  }
 129                  if ($inputmoduleid)
 130                  {
 131                      $block =& CreateObject('sitemgr.Block_SO',True);
 132                      $block->module_id = $inputmoduleid;
 133                      $block->area = $inputarea;
 134                      $block->page_id = $page_id;
 135                      $block->cat_id = $cat_id ? $cat_id : ($page_id ? $page->cat_id : CURRENT_SITE_ID);
 136  
 137                      $newblock = $this->bo->addblock($block);
 138                      if ($newblock)
 139                      {
 140                          $this->bo->createversion($newblock);
 141                          if ($_GET['add_block'])
 142                          {
 143                              $GLOBALS['egw']->redirect_link('/index.php',array(
 144                                  'menuaction' => 'sitemgr.Content_UI.manage',
 145                                  'block_id'   => $newblock
 146                              ));
 147                          }
 148                      }
 149                      else
 150                      {
 151                          $this->errormsg[] = lang("You are not entitled to create module %1 on this scope",$inputmoduleid);
 152                      }
 153                  }
 154                  else
 155                  {
 156                      $this->errormsg[] = lang("You did not choose a module.");
 157                  }
 158              }
 159              elseif ($btnSaveBlock || $btnApplyBlock || $_GET['sort_order'] && $block_id)
 160              {
 161                  if ($_GET['sort_order'])
 162                  {
 163                      $block = $this->bo->getblock($block_id,$this->worklanguage);
 164                      $block->sort_order += intval($_GET['sort_order']);
 165                      $element = array();
 166                      $inputstate = False;
 167                  }
 168                  else
 169                  {
 170                      $block =& CreateObject('sitemgr.Block_SO',True);
 171                      $block->id = $inputblockid;
 172                      $block->title = $inputblocktitle;
 173                      $block->sort_order = $inputblocksort;
 174                      $block->view = $inputblockview;
 175                  }
 176                  $result = $this->bo->saveblockdata($block,$element,$inputstate,$this->worklanguage,$_POST['scope']);
 177                  if ($result !== True)
 178                  {
 179                      //result should be an array of validationerrors
 180                      $this->errormsg = $result;
 181                  }
 182                  else
 183                  {
 184                      $this->errormsg[] = lang('Block saved');
 185                      $focus_reload_close = 'opener.location.reload();';
 186                  }
 187                  if ($_GET['sort_order'] || $block_id && $btnSaveBlock && $result === True)
 188                  {
 189                      echo '<html><head></head><body onload="opener.location.reload();self.close()"></body></html>';
 190                      $GLOBALS['egw']->common->egw_exit();
 191                  }
 192              }
 193              elseif ($btnReloadBlock && $block_id)
 194              {
 195                      $this->errormsg[] = lang('Block reloaded');
 196                      $focus_reload_close = 'opener.location.reload();';
 197              }
 198              elseif ($btnDeleteBlock || $_GET['deleteBlock'] && $block_id)
 199              {
 200                  if ($_GET['deleteBlock']) $inputblockid = $block_id;
 201                  if (!$this->bo->removeblock($inputblockid))
 202                  {
 203                      $this->errormsg[] =  lang("You are not entitled to edit block %1",$inputblockid);
 204                  }
 205                  //if we delete a block we were editing, there is nothing left to do
 206                  if ($block_id)
 207                  {
 208                      echo '<html><head></head><body onload="opener.location.reload();self.close()"></body></html>';
 209                  }
 210              }
 211              elseif ($btnCreateVersion)
 212              {
 213                  $this->bo->createversion($inputblockid);
 214              }
 215              elseif ($btnDeleteVersion)
 216              {
 217                  $version_id = array_keys($btnDeleteVersion);
 218                  $this->bo->deleteversion($version_id[0]);
 219              }
 220  
 221              //if we are called with a block_id GET parameter, it is from sitemgr-site edit mode or from archiv/commit
 222              //we are shown in a separate edit window, without navbar.
 223              if ($block_id)
 224              {
 225                  $block = $this->bo->getblock($block_id,$this->worklanguage);
 226  
 227                  if (!($block && $GLOBALS['Common_BO']->acl->can_write_category($block->cat_id)))
 228                  {
 229                      echo '<p><center><b>'.lang('Attempt to edit non-editable block').'</b></center>';
 230                      $GLOBALS['egw']->common->egw_exit(True);
 231                  }
 232                  $this->t->set_file('Blocks', 'edit_block.tpl');
 233                  $this->t->set_block('Blocks','Block');
 234                  $this->t->set_block('Block','Moduleeditor','MeBlock');
 235                  $this->t->set_block('Block','Moduleview','MvBlock');
 236                  $this->t->set_block('Moduleeditor','Version','EvBlock');
 237                  $this->t->set_block('Blocks','EditorElement','EeBlock');
 238                  $this->t->set_block('Blocks','EditorElementLarge','EeBlockLarge');
 239                  $this->t->set_block('Moduleview','ViewElement','VeBlock');
 240  
 241                  $action_vars = array('menuaction' => 'sitemgr.Content_UI.manage');
 242                  foreach(array('page_id','cat_id','block_id') as $name)
 243                  {
 244                      if ($$name) $action_vars[$name] = $$name;
 245                  }
 246                  $action_url = $GLOBALS['egw']->link('/index.php',$action_vars);
 247  
 248                  $this->t->set_var(array(
 249                      'action_url' => $action_url,
 250                      'validationerror' => implode('<br />',$this->errormsg),
 251                      'lang_save' => lang('Save'),
 252                      'lang_reload' => lang('Reload'),
 253                      'lang_delete' => lang('Delete'),
 254                      'lang_confirm' => lang('Do you realy want to delete this block?'),
 255                      'contentarea' => lang('Contentarea'),
 256                      'lang_createversion' => lang('Create new version'),
 257                      'standalone' => '<div id="divMain">',
 258                      'cancel_button' => '<input type="reset" value="'.lang('Cancel').'" onClick="self.close();" />',
 259                      'apply_button' => '<input type="submit" name="btnApplyBlock" value="'.lang('Apply').'" />',
 260                      'focus_reload_close' => $focus_reload_close,
 261                  ));
 262                  $this->showblock($block,True,True,True);
 263                  $GLOBALS['egw']->common->egw_header();
 264                  $this->t->pfp('out','Block');
 265                  $GLOBALS['egw']->common->egw_exit();
 266                  return;
 267              }
 268  
 269              $this->t->set_file('Managecontent', 'manage_content.tpl');
 270              $this->t->set_file('Blocks','edit_block.tpl');
 271              $this->t->set_block('Managecontent','Contentarea','CBlock');
 272              $this->t->set_block('Blocks','Block');
 273              $this->t->set_block('Block','Moduleeditor','MeBlock');
 274              $this->t->set_block('Block','Moduleview','MvBlock');
 275              $this->t->set_block('Moduleeditor','Version','EvBlock');
 276              $this->t->set_block('Blocks','EditorElement','EeBlock');
 277              $this->t->set_block('Blocks','EditorElementLarge','EeBlockLarge');
 278              $this->t->set_block('Moduleview','ViewElement','VeBlock');
 279  
 280              $contentareas = $this->bo->getContentAreas();
 281              if (is_array($contentareas))
 282              {
 283                  $this->t->set_var(array(
 284                      'help' => lang('You can override each content blocks default title. Be aware that not in all content areas the block title will be visible.'),
 285                      'lang_save' => lang('Save'),
 286                      'lang_delete' => lang('Delete'),
 287                      'contentarea' => lang('Contentarea'),
 288                      'lang_createversion' => lang('Create new version'),
 289                      'apply_button' => '',
 290                      'cancel_button' => '',
 291                  ));
 292  
 293                  foreach ($contentareas as $contentarea)
 294                  {
 295                      $permittedmodules = $this->modulebo->getcascadingmodulepermissions($contentarea,$cat_id);
 296  
 297                      $this->t->set_var(Array(
 298                          'area' => $contentarea,
 299                          'addblockform' =>
 300                              ($permittedmodules ?
 301                                  ('<form method="POST" action="' . $action_url . '"><input type="hidden" value="' . $contentarea . '" name="inputarea" />' .
 302                                      '<select style="vertical-align:middle" size="10" name="inputmoduleid">' .
 303                                      $this->inputmoduleselect($permittedmodules) .
 304                                      '</select><input type="submit" name="btnAddBlock" value="' .
 305                                      lang('Add block to content area %1',$contentarea) .
 306                                      '" /></form>') :
 307                                  lang('No modules permitted for this content area/category')
 308                              ),
 309                          'error' => (($contentarea == $inputarea) && $this->errormsg) ? join('<br>',$this->errormsg) : '',
 310                      ));
 311  
 312                      //we get all blocks for the page and its category, and site wide,
 313                      //but only the current scope is editable
 314                      //if we have just edited a block in a certain language, we request all blocks in this language
 315                      $blocks = $this->bo->getallblocksforarea($contentarea,$cat_id,$page_id,$this->worklanguage);
 316  
 317                      $this->t->set_var('blocks','');
 318  
 319                      if ($blocks)
 320                      {
 321                          while (list(,$block) = each($blocks))
 322                          {
 323                              //if the block is in our scope and we are entitled we edit it
 324                              $editable = ($block->page_id == $page_id && $block->cat_id == $cat_id);
 325                              $this->showblock($block,$editable);
 326                              $this->t->parse('blocks','Block', true);
 327                          }
 328                      }
 329                      $this->t->parse('CBlock','Contentarea', true);
 330                  }
 331              }
 332              else
 333              {
 334                  $this->t->set_var('CBlock',$contentareas);
 335              }
 336              $this->common_ui->DisplayHeader(lang('%1 content manager', $scopename).($page_or_cat_name ? (' - ' . $page_or_cat_name) : ''));
 337              $this->t->pfp('out', 'Managecontent');
 338              $this->common_ui->DisplayFooter();
 339          }
 340  
 341  		function commit()
 342          {
 343              if ($_POST['btnCommit'])
 344              {
 345                  while(list($cat_id,) = @each($_POST['cat']))
 346                  {
 347                      $GLOBALS['Common_BO']->cats->commit($cat_id);
 348                  }
 349                  while(list($page_id,) = @each($_POST['page']))
 350                  {
 351                      $GLOBALS['Common_BO']->pages->commit($page_id);
 352                  }
 353                  while(list($block_id,) = @each($_POST['block']))
 354                  {
 355                      $this->bo->commit($block_id);
 356                  }
 357              }
 358              $this->common_ui->DisplayHeader();
 359  
 360              $this->t->set_file('Commit','commit.tpl');
 361              $this->t->set_block('Commit','Category','Cblock');
 362              $this->t->set_block('Commit','Page','Pblock');
 363              $this->t->set_block('Commit','Block','Bblock');
 364              $this->t->set_var(array(
 365                  'commit_manager' => lang('Commit changes'),
 366                  'lang_categories' => lang('Categories'),
 367                  'lang_pages' => lang('Pages'),
 368                  'lang_blocks' => lang('Content blocks'),
 369                  'lang_commit' => lang('Commit changes'),
 370                  'action_url' => $GLOBALS['egw']->link('/index.php',array('menuaction'=>'sitemgr.Content_UI.commit')),
 371              ));
 372  
 373              //Categories
 374              $cats = $GLOBALS['Common_BO']->cats->getpermittedcatsCommitable();
 375              while (list(,$cat_id) = @each($cats))
 376              {
 377                  $cat = $GLOBALS['Common_BO']->cats->getCategory($cat_id,$this->sitelanguages[0]);
 378                  $this->t->set_var(array(
 379                      'category' => $cat->name,
 380                      'catid' => $cat_id,
 381                      'addedorremoved' => ($cat->state == SITEMGR_STATE_PREPUBLISH) ? 'added' : 'removed',
 382                      'edit' => $GLOBALS['egw']->link('/index.php',array(
 383                          'cat_id' => $cat_id,
 384                          'menuaction' => 'sitemgr.Categories_UI.edit'
 385                      ))
 386                  ));
 387                  $this->t->parse('Cblock','Category',True);
 388              }
 389  
 390              //Pages
 391              $pages = $GLOBALS['Common_BO']->pages->getpageIDListCommitable();
 392  
 393              while (list(,$page_id) = @each($pages))
 394              {
 395                  $page = $GLOBALS['Common_BO']->pages->getPage($page_id);
 396                  $this->t->set_var(array(
 397                      'page' => $page->name,
 398                      'pageid' => $page_id,
 399                      'addedorremoved' => ($page->state == SITEMGR_STATE_PREPUBLISH) ? 'added' : 'removed',
 400                      'edit' => $GLOBALS['egw']->link('/index.php',array(
 401                          'page_id' => $page_id,
 402                          'menuaction' => 'sitemgr.Pages_UI.edit'
 403                      ))
 404                  ));
 405                  $this->t->parse('Pblock','Page',True);
 406              }
 407  
 408              //Content Blocks
 409              $blocks = $this->bo->getcommitableblocks();
 410              while (list($block_id,$block) = @each($blocks))
 411              {
 412                  $this->t->set_var(array(
 413                      'block' => $this->bo->getlangblocktitle($block_id,$this->sitelanguages[0]),
 414                      'blockid' => $block_id,
 415                      'scope' => $this->blockscope($block->cat_id,$block->page_id),
 416                      'addedorremovedorreplaced' => ($block->cnt == 2) ? 'replaced' : 
 417                          (($block->state == SITEMGR_STATE_PREPUBLISH) ? 'added' : 'removed'),
 418                      'edit' =>  $GLOBALS['egw']->link('/index.php',array(
 419                          'block_id' => $block_id,
 420                          'menuaction' => 'sitemgr.Content_UI.manage'
 421                      ))
 422                  ));
 423                  $this->t->parse('Bblock','Block',True);
 424              }
 425  
 426              $this->t->pfp('out', 'Commit');
 427              $this->common_ui->DisplayFooter();
 428          }
 429  
 430  		function archive()
 431          {
 432              if ($_POST['btnReactivate'] || $_POST['btnDelete'])
 433              {
 434                  if (is_array($_POST['cat']) && count($_POST['cat']) > 0)
 435                  {
 436                      foreach($_POST['cat'] as $cat_id => $nul)
 437                      {
 438                          if ($_POST['btnReactivate'])
 439                          {
 440                              $GLOBALS['Common_BO']->cats->reactivate($cat_id);
 441                          }
 442                          elseif ($GLOBALS['Common_BO']->acl->is_admin()) // we need to do the ACL-check as we have to force
 443                          {
 444                              $GLOBALS['Common_BO']->cats->removeCategory($cat_id,True,True);
 445                          }
 446                      }
 447                  }
 448                  if (is_array($_POST['page']) && count($_POST['page']) > 0)
 449                  {
 450                      foreach($_POST['page'] as $page_id => $nul)
 451                      {
 452                          if ($_POST['btnReactivate'])
 453                          {
 454                              $GLOBALS['Common_BO']->pages->reactivate($page_id);
 455                          }
 456                          else
 457                          {
 458                              $GLOBALS['Common_BO']->pages->removePage($page_id);
 459                          }
 460                      }
 461                  }
 462                  if (is_array($_POST['block']) && count($_POST['block']) > 0)
 463                  {
 464                      foreach($_POST['block'] as $block_id => $nul)
 465                      {
 466                          if ($_POST['btnReactivate'])
 467                          {
 468                              $this->bo->reactivate($block_id);
 469                          }
 470                          else
 471                          {
 472                              $this->bo->removeBlock($block_id);
 473                          }
 474                      }
 475                  }
 476              }
 477  
 478              $this->common_ui->DisplayHeader();
 479  
 480              $this->t->set_file('Commit','archive.tpl');
 481              $this->t->set_block('Commit','Category','Cblock');
 482              $this->t->set_block('Commit','Page','Pblock');
 483              $this->t->set_block('Commit','Block','Bblock');
 484              $this->t->set_var(array(
 485                  'action_url' => $GLOBALS['egw']->link('/index.php',array('menuaction'=>'sitemgr.Content_UI.archive')),
 486                  'commit_manager' => lang('Archived content'),
 487                  'lang_categories' => lang('Categories'),
 488                  'lang_pages' => lang('Pages'),
 489                  'lang_blocks' => lang('Content blocks'),
 490                  'lang_reactivate' => lang('Reactivate content'),
 491                  'lang_delete' => lang('Delete'),
 492                  'lang_confirm' => lang('Do you realy want to delete the selected Categories (including all pages), Pages and Blocks?'),
 493              ));
 494  
 495              //Categories
 496              $cats = $GLOBALS['Common_BO']->cats->getpermittedcatsArchived();
 497              //we have to append the archived cats to the currentcats, in order to be able to access them later
 498              $GLOBALS['Common_BO']->cats->currentcats = array_merge($GLOBALS['Common_BO']->cats->currentcats,$cats);
 499              while (list(,$cat_id) = @each($cats))
 500              {
 501                  $cat = $GLOBALS['Common_BO']->cats->getCategory($cat_id,$this->sitelanguages[0],True);
 502                  $this->t->set_var(array(
 503                      'category' => $cat->name,
 504                      'catid' => $cat_id,
 505                      'edit' => $GLOBALS['egw']->link('/index.php',array(
 506                          'cat_id' => $cat_id,
 507                          'menuaction' => 'sitemgr.Categories_UI.edit'
 508                      ))
 509                  ));
 510                  $this->t->parse('Cblock','Category',True);
 511              }
 512  
 513              //Pages
 514              $pages = $GLOBALS['Common_BO']->pages->getpageIDListArchived();
 515  
 516              while (list(,$page_id) = @each($pages))
 517              {
 518                  $page = $GLOBALS['Common_BO']->pages->getPage($page_id);
 519                  $this->t->set_var(array(
 520                      'page' => $page->name,
 521                      'pageid' => $page_id,
 522                      'edit' => $GLOBALS['egw']->link('/index.php',array(
 523                          'page_id' => $page_id,
 524                          'menuaction' => 'sitemgr.Pages_UI.edit'
 525                      ))
 526                  ));
 527                  $this->t->parse('Pblock','Page',True);
 528              }
 529  
 530              //Content Blocks
 531              $blocks = $this->bo->getarchivedblocks();
 532              while (list($block_id,$block) = @each($blocks))
 533              {
 534                  $this->t->set_var(array(
 535                      'block' => $this->bo->getlangblocktitle($block_id,$this->sitelanguages[0]),
 536                      'blockid' => $block_id,
 537                      'scope' => $this->blockscope($block->cat_id,$block->page_id),
 538                      'edit' =>  $GLOBALS['egw']->link('/index.php',array(
 539                          'block_id' => $block_id,
 540                          'menuaction' => 'sitemgr.Content_UI.manage'
 541                      ))
 542                  ));
 543                  $this->t->parse('Bblock','Block',True);
 544              }
 545  
 546              $this->t->pfp('out', 'Commit');
 547              $this->common_ui->DisplayFooter();
 548          }
 549  
 550  		function inputmoduleselect($modules)
 551          {
 552              $returnValue = '';
 553              foreach($modules as $id => $module)
 554              { 
 555                  $returnValue.='<option title="' . lang($module['description']) . '" value="'.$id.'">'.
 556                      $module['module_name'].'</option>'."\n";
 557              }
 558              return $returnValue;
 559          }
 560  
 561  		function inputviewselect($default)
 562          {
 563              $returnValue = '';
 564              foreach($this->viewable as $value => $display)
 565              {
 566                  $selected = ($default == $value) ? $selected = 'selected="selected" ' : '';
 567                  $returnValue.='<option '.$selected.'value="'.$value.'">'.
 568                      $display.'</option>'."\n";
 569              }
 570              return $returnValue;
 571          }
 572  
 573  		function blockscope($cat_id,$page_id,$editable=False)
 574          {
 575              if ($editable)
 576              {
 577                  $scope = "$cat_id,$page_id";
 578                  $scopes = array();
 579                  if ($GLOBALS['Common_BO']->acl->can_write_category(CURRENT_SITE_ID))
 580                  {
 581                      $scopes[CURRENT_SITE_ID.',0'] = $this->blockscope(CURRENT_SITE_ID,0);
 582                  }
 583                  if ($cat_id != CURRENT_SITE_ID)
 584                  {
 585                      if ($GLOBALS['Common_BO']->acl->can_write_category($cat_id))
 586                      {
 587                          $scopes["$cat_id,0"] = $this->blockscope($cat_id,0);
 588                      }
 589                      if ($page_id)
 590                      {
 591                          $scopes[$scope] = $this->blockscope($cat_id,$page_id);
 592                      }
 593                  }
 594                  if (count($scopes) > 1)
 595                  {
 596                      if (!is_object($GLOBALS['egw']->html))
 597                      {
 598                          $GLOBALS['egw']->html =& CreateObject('phpgwapi.html');
 599                      }
 600                      return $GLOBALS['egw']->html->select('scope',array($scope),$scopes,True);
 601                  }
 602                  else
 603                  {
 604                      return $scopes[$scope];
 605                  }
 606              }
 607              if ($cat_id == CURRENT_SITE_ID)
 608              {
 609                  $scope = lang('Site wide');
 610              }
 611              else
 612              {
 613                  $cat = $GLOBALS['Common_BO']->cats->getCategory($cat_id);
 614                  $scope = lang('Category') . ' ' . $cat->name;
 615                  if ($page_id)
 616                  {
 617                      $page = $GLOBALS['Common_BO']->pages->getPage($page_id);
 618                      $scope .= ' - ' . lang('Page') . ' ' . $page->name;
 619                  }
 620              }
 621              return $scope;
 622          }
 623  
 624          //if the block is shown on its own ($standalone), we add information about its,scope
 625  		function showblock($block,$editable,$standalone=False)
 626          {
 627              global $page_id,$cat_id, $inputblockid;
 628              //TODO: wrap a module storage around createmodule as in template3,
 629              //TODO: so that we do not create the same module object twice
 630              $moduleobject =& $this->modulebo->createmodule($block->module_name);
 631              $this->t->set_var(array(
 632                  'moduleinfo' => $block->module_name,
 633                  'description' => lang($moduleobject->description),
 634                  'savelang' => $this->langselect
 635              ));
 636  
 637              //if the block is in our scope and we are entitled we edit it
 638              if ($editable)
 639              {
 640                  $editorstandardelements = array(
 641                      array('label' => lang('Title'),
 642                              'form' => ('<input type="text" name="inputblocktitle" value="' .
 643                              ($block->title ? $block->title : $moduleobject->title) . '" />')
 644                      ),
 645                      array('label' => lang('Seen by'),
 646                              'form' => ('<select name="inputblockview">' .
 647                              $this->inputviewselect((int)$block->view) . '</select>')
 648                      ),
 649                      array('label' => lang('Sort order'),
 650                              'form' => ('<input type="text" name="inputblocksort" size="2" value="' .
 651                              (int)$block->sort_order . '">')
 652                      )
 653                  );
 654                  if ($standalone)
 655                  {
 656                      $editorstandardelements[] = array(
 657                          'label' => lang('Scope'),
 658                          'form' => $this->blockscope($block->cat_id,$block->page_id,True)
 659                      );
 660                  }
 661  
 662                  $moduleobject->set_block($block);
 663  
 664                  $this->t->set_var(Array(
 665                      'blockid' => $block->id,
 666                      'validationerror' => (($block->id == $inputblockid) && $this->errormsg) ? join('<br>',$this->errormsg) : '',
 667                  ));
 668                  $this->t->set_var('standardelements','');
 669                  while (list(,$element) = each($editorstandardelements))
 670                  {
 671                      $this->t->set_var(Array(
 672                          'label' => $element['label'],
 673                          'form' => $element['form']
 674                      ));
 675                      $this->t->parse('standardelements','EditorElement', true);
 676                  }
 677  
 678                  $versions = $this->bo->getallversionsforblock($block->id,$this->worklanguage);
 679                  $this->t->set_var('EvBlock','');
 680                  while (list($version_id,$version) = each($versions))
 681                  {
 682                      //set the version of the block which is referenced by the moduleobject, 
 683                      //so that we retrieve a interface with the current version's arguments 
 684                      $block->set_version($version);
 685                      $editormoduleelements = $moduleobject->get_user_interface();
 686                      $this->t->set_var(array(
 687                          'version_id' => $version_id,
 688                          'state' => $GLOBALS['Common_BO']->inputstateselect($version['state']),
 689                          'deleteversion' => lang('Delete Version'),
 690                          'versionelements' => ''
 691                      ));
 692                      while (list(,$element) = each($editormoduleelements))
 693                      {
 694                          $this->t->set_var(Array(
 695                              'label' => $element['label'],
 696                              'form' => $element['form']
 697                          ));
 698                          $this->t->parse('versionelements',$element['large']?'EditorElementLarge':'EditorElement', true);
 699                      }
 700                      $this->t->parse('EvBlock','Version', true);
 701                  }
 702  
 703                  $this->t->parse('MeBlock','Moduleeditor');
 704                  $this->t->set_var('MvBlock','');
 705              }
 706              //otherwise we only show it
 707              else
 708              {
 709                  if ($block->page_id)
 710                  {
 711                      $blockscope = lang('Page');
 712                  }
 713                  elseif ($block->cat_id != CURRENT_SITE_ID)
 714                  {
 715                      $cat = $GLOBALS['Common_BO']->cats->getCategory($block->cat_id);
 716                      $blockscope =  lang('Category') . ' - ' . $cat->name;
 717                  }
 718                  else
 719                  {
 720                      $blockscope =  lang('Site');
 721                  }
 722  
 723                  $viewstandardelements = array(
 724                      array('label' => lang('Scope'),
 725                              'value' => $blockscope
 726                      ),
 727                      array('label' => lang('Title'),
 728                              'value' => ($block->title ? $block->title : $moduleobject->title)
 729                      ),
 730                      array('label' => lang('Seen by'),
 731                              'value' => $this->viewable[(int)$block->view]
 732                      ),
 733                      array('label' => lang('Sort order'),
 734                              'value' => (int)$block->sort_order
 735                      )
 736                  );
 737  //                $viewmoduleelements = array();
 738  //                while (list($argument,$argdef) = @each($moduleobject->arguments))
 739  //                {
 740  //                  $value = $block->arguments[$argument];
 741  //                  $viewmoduleelements[] = array(
 742  //                    'label' => $argdef['label'],
 743  //                    'value' => $GLOBALS['egw']->strip_html($value)
 744  //                  );
 745  //                }
 746  //                $interface = array_merge($viewstandardelements,$viewmoduleelements);
 747                  $interface = $viewstandardelements;
 748                  $this->t->set_var('VeBlock','');
 749                  while (list(,$element) = each($interface))
 750                  {
 751                      $this->t->set_var(Array(
 752                          'label' => $element['label'],
 753                          'value' => $element['value'])
 754                      );
 755                      $this->t->parse('VeBlock','ViewElement', true);
 756                  }
 757                  $this->t->parse('MvBlock','Moduleview');
 758                  $this->t->set_var('MeBlock','');
 759              }
 760          }
 761      }


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