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