phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] sitemgr/inc class.module.inc.php, 1.8.2.2.4.1 class.C


From: skwashd
Subject: [Phpgroupware-cvs] sitemgr/inc class.module.inc.php, 1.8.2.2.4.1 class.Content_UI.inc.php, 1.3.2.4.2.1
Date: Sat, 12 Nov 2005 15:11:00 +0100

Update of sitemgr/inc

Modified Files:
     Branch: skwashd-16-compat
            class.module.inc.php lines: +20 -8
            class.Content_UI.inc.php lines: +7 -0

Log Message:
.

====================================================
Index: sitemgr/inc/class.module.inc.php
diff -u sitemgr/inc/class.module.inc.php:1.8 
sitemgr/inc/class.module.inc.php:1.8.2.2.4.1
--- sitemgr/inc/class.module.inc.php:1.8        Mon Mar 10 07:02:06 2003
+++ sitemgr/inc/class.module.inc.php    Sat Nov 12 14:11:58 2005
@@ -18,6 +18,7 @@

 class Module
 {
+       var $i18n; //flag a module must use if it wants its content to be 
translatable
        var $validation_error;
        var $transformer_chain;
        var $arguments;
@@ -34,9 +35,9 @@
                $this->description = "Parent class that all modules should 
extend";
        }

-       function add_transformer($transformer)
+       function add_transformer(&$transformer)
        {
-               $this->transformer_chain[] = $transformer;
+               $this->transformer_chain[] =& $transformer;
        }

        //before calling the functions get_user_interface, get_output,
@@ -45,13 +46,13 @@
        //this function can be overriden (but do not forget to call 
parent::set_block) in order to do some configuration
        //that depends on the blocks arguments
        //the produce argument is set when content is generated, so we can do 
some stuff we do not need when editing the block
-       function set_block($block,$produce=False)
+       function set_block(&$block,$produce=False)
        {
                if ($produce)
                {
                        if ($this->session)
                        {
-                               $sessionarguments = 
$GLOBALS['phpgw']->session->appsession($block->module_name,'sitemgr-site');
+                               $sessionarguments = 
$GLOBALS['phpgw']->session->appsession('block[' . $block->id . ']', 
'sitemgr-site');
                                while (list(,$argument) = @each($this->session))
                                {
                                        if (isset($sessionarguments[$argument]))
@@ -62,36 +63,38 @@
                        }
                        while (list(,$argument) = @each($this->get))
                        {
-                               if 
(isset($_GET[$block->module_name][$argument]))
+                               if 
(isset($_GET['block'][$block->id][$argument]))
                                {
-                                       $block->arguments[$argument] = 
$_GET[$block->module_name][$argument];
+                                       $block->arguments[$argument] = 
$_GET['block'][$block->id][$argument];
                                }
                        }
                        //contrary to $this->get, cookie and session, the 
argument name is the key in $this->post because this array also
                        //defines the form element
+
                        while (list($argument,) = @each($this->post))
                        {
-                               if 
(isset($_POST[$block->module_name][$argument]))
+                               if 
(isset($_POST['block'][$block->id][$argument]))
                                {
-                                       $block->arguments[$argument] = 
$_POST[$block->module_name][$argument];
+                                       $block->arguments[$argument] = 
$_POST['block'][$block->id][$argument];
                                }
                        }
                        while (list(,$argument) = @each($this->cookie))
                        {
-                               if 
(isset($_COOKIE[$block->module_name][$argument]))
+                               if 
(isset($_COOKIE['block'][$block->id][$argument]))
                                {
-                                       $block->arguments[$argument] = 
$_COOKIE[$block->module_name][$argument];
+                                       $block->arguments[$argument] = 
$_COOKIE['block'][$block->id][$argument];
                                }
                        }
                }
-               $this->block = $block;
+               $this->block =& $block;
        }

        function link($modulevars=array())
        {
                while (list($key,$value) = @each($modulevars))
                {
-                       $extravars[$this->block->module_name.'['.$key.']'] = 
$value;
+                       //%5B and %5D are urlencoded [ and ]
+                       $extravars['block' . '%5B'. $this->block->id  .'%5D%5B' 
. $key . '%5D'] = $value;
                }
                if ($GLOBALS['page']->name)
                {
@@ -114,7 +117,7 @@

        function find_template_dir()
        {
-               $templaterootformat = 
$GLOBALS['sitemgr_info']['sitemgr-site-dir']. SEP . 'templates' . SEP . '%s' . 
SEP . 'modules' . SEP . $this->block->module_name;
+               $templaterootformat = $GLOBALS['sitemgr_info']['site_dir']. SEP 
. 'templates' . SEP . '%s' . SEP . 'modules' . SEP . $this->block->module_name;
                $themetemplatedir = 
sprintf($templaterootformat,$GLOBALS['sitemgr_info']['themesel']);
                if (is_dir($themetemplatedir))
                {
@@ -128,22 +131,29 @@

        function get_properties($cascading=True)
        {
-               if ($cascading)
+               if ($this->properties)
                {
-                       return 
$GLOBALS['Common_BO']->modules->getcascadingmoduleproperties(
-                               $this->block->module_id,
-                               $this->block->area,
-                               $this->block->cat_id,
-                               $this->block->module_name
-                       );
+                       if ($cascading)
+                       {
+                               return 
$GLOBALS['Common_BO']->modules->getcascadingmoduleproperties(
+                                       $this->block->module_id,
+                                       $this->block->area,
+                                       $this->block->cat_id,
+                                       $this->block->module_name
+                               );
+                       }
+                       else
+                       {
+                               return 
$GLOBALS['Common_BO']->modules->getmoduleproperties(
+                                       $this->block->module_id,
+                                       $this->block->area,
+                                       $this->block->cat_id
+                               );
+                       }
                }
                else
                {
-                       return 
$GLOBALS['Common_BO']->modules->getmoduleproperties(
-                               $this->block->module_id,
-                               $this->block->area,
-                               $this->block->cat_id
-                       );
+                       return False;
                }
        }

@@ -155,7 +165,8 @@
                reset($this->arguments);
                while (list($key,$input) = @each($this->arguments))
                {
-                       $elementname = ($input['i18n'] ? ('element[i18n][' 
.$key . ']') : ('element[' .$key . ']'));
+                       $elementname = 'element[' . $this->block->version . ']';
+                       $elementname .= ($input['i18n'] ? ('[i18n][' .$key . 
']') : ('[' .$key . ']'));
                        //arrays of input elements are only implemented for the 
user interface
                        if ($input['type'] == 'array')
                        {
@@ -171,7 +182,8 @@
                        else
                        {
                                $element['label'] = $input['label'];
-                               $element['form'] = 
$this->build_input_element($input,$this->block->arguments[$key],$elementname);
+                               $element['label_for'] = 'sitemgr_element_' . 
$this->block->version;
+                               $element['form'] = 
$this->build_input_element($input,$this->block->arguments[$key],$elementname, 
$element['label_for']);
                                $interface[] = $element;
                        }
                }
@@ -189,7 +201,7 @@
                {
                        if ($input['i18n'])
                        {
-                               $elementname = 'element[i18n][' .$key . ']';
+                               $elementname = 'element[' . 
$this->block->version . '][i18n][' .$key . ']';
                                //arrays of input elements are only implemented 
for the user interface
                                if ($input['type'] == 'array')
                                {
@@ -219,10 +231,10 @@
        function get_admin_interface()
        {
                $properties = $this->get_properties(False);
-               $elementname = 'element[' .$key . ']';
                $interface = array();
                while (list($key,$input) = @each($this->properties))
                {
+                       $elementname = 'element[' .$key . ']';
                        $element['label'] = $input['label'];
                        $element['form'] = 
$this->build_input_element($input,$properties[$key],$elementname);
                        $interface[$key] = $element;
@@ -235,7 +247,7 @@
                return $this->build_input_element(
                        $this->post[$key],
                        ($default !== False) ? $default : 
$this->block->arguments[$key],
-                       ($this->block->module_name . '[' . $key . ']')
+                       ('block[' . $this->block->id  . '][' . $key . ']')
                );
        }

@@ -258,7 +270,7 @@
                }
        }

-       function build_input_element($input,$default,$elementname)
+       function build_input_element($input,$default,$elementname, $element_id)
        {
                if ($default)
                {
@@ -273,13 +285,13 @@
                switch($input['type'])
                {
                        case 'textarea':
-                               return '<textarea ' . $inputdef . '>' . 
$default . '</textarea>';
+                               return '<textarea id="'.$element_id.'" ' . 
$inputdef . '>' . $default . '</textarea>';
                        case 'textfield':
-                               return '<input type="text" ' . $inputdef . ' 
value ="' . $default . '" />';
+                               return '<input id="'.$element_id.'" type="text" 
' . $inputdef . ' value ="' . $default . '" />';
                        case 'checkbox':
-                               return '<input type="checkbox" ' . $inputdef . 
($default ? 'checked="checked"' :'') . '" />';
+                               return '<input id="'.$element_id.'" 
type="checkbox" ' . $inputdef . ($default ? 'checked="checked"' :'') . '" />';
                        case 'select':
-                               $select = '<select ' .($input['multiple'] ? 
'multiple="multiple"' : '') . $inputdef . '>';
+                               $select = '<select id="'.$element_id.'" ' 
.($input['multiple'] ? 'multiple="multiple"' : '') . $inputdef . '>';
                                foreach ($input['options'] as $value => 
$display)
                                {
                                        $selected='';
@@ -295,10 +307,21 @@
                                }
                                $select .= '</select>';
                                return $select;
+
                        case 'submit':
-                               return '<input type="submit" ' . $inputdef .' 
value ="' . $input['value'] . '" />';
+                               return '<button id="'.$element_id.'" 
type="submit" ' . $inputdef .' value ="1">' . $input['value'] . '</button>';
+
                        case 'image':
-                               return '<input type="image" ' . $inputdef .' 
src ="' . $input['src'] . '" />';
+                               return '<input id="'.$element_id.'" 
type="image" ' . $inputdef .' src ="' . $input['src'] . '" />';
+
+                       case 'richtext':
+
+                               return "<textarea 
id=\"{$element_id}\"{$inputdef}>{$default}</textarea>\n"
+                                       . "<script>\n\nvar 
oFCKEditor_{$this->block->version} = new FCKeditor('{$elementname}');
+                                                
oFCKEditor_{$this->block->version}.BasePath = 
'{$GLOBALS['phpgw_info']['server']['webserver_url']}/news_admin/js/fckeditor/';
+                                                
oFCKEditor_{$this->block->version}.SpellChecker = '" . 
(extension_loaded('pspell') ? 'SpellerPages' : 'ieSpell') . "';
+                                                
oFCKEditor_{$this->block->version}.ReplaceTextarea();
+                                       \n</script>\n";
                }
        }

@@ -307,6 +330,11 @@
                return true;
        }

+       function validate_properties(&$data)
+       {
+               return true;
+       }
+
        //never call get_content directly, get_output takes care of passing it 
the right arguments
        function get_content(&$arguments,$properties)
        {
@@ -326,12 +354,9 @@
                }
                else
                {
-                       if ($this->transformer_chain)
+                       for ( $i = 0; $i < count( $this->transformer_chain ); 
++$i )
                        {
-                               foreach ($this->transformer_chain as 
$transformer)
-                               {
-                                       $content = 
$transformer->apply_transform($this->block->title,$content);
-                               }
+                               $content = 
$this->transformer_chain[$i]->apply_transform($this->block->title,$content);
                        }
                        //store session variables
                        if ($this->session)
@@ -344,7 +369,7 @@
                                                $sessionarguments[$argument] = 
$this->block->arguments[$argument];
                                        }
                                }
-                               
$GLOBALS['phpgw']->session->appsession($this->block->module_name,'sitemgr-site',$sessionarguments);
+                               $GLOBALS['phpgw']->session->appsession('block[' 
. $this->block->id . ']','sitemgr-site',$sessionarguments);
                        }
                        return $content;
                }

====================================================
Index: sitemgr/inc/class.Content_UI.inc.php
diff -u sitemgr/inc/class.Content_UI.inc.php:1.3 
sitemgr/inc/class.Content_UI.inc.php:1.3.2.4.2.1
--- sitemgr/inc/class.Content_UI.inc.php:1.3    Mon Mar 10 07:01:20 2003
+++ sitemgr/inc/class.Content_UI.inc.php        Sat Nov 12 14:11:58 2005
@@ -11,10 +11,13 @@
                var $sitelanguages;
                var $worklanguage;
                var $errormsg;
+               var $langselect;

                var $public_functions = array
                (
-                       '_manageContent' => True
+                       'manage' => True,
+                       'commit' => True,
+                       'archive' => True
                );

                function Content_UI()
@@ -25,80 +28,118 @@
                        $this->acl = &$GLOBALS['Common_BO']->acl;
                        $this->modulebo = &$GLOBALS['Common_BO']->modules;
                        $this->viewable = array(
-                               '0' => 'everybody',
-                               '1' => 'phpgw users',
-                               '2' => 'administrators',
-                               '3' => 'anonymous'
+                               SITEMGR_VIEWABLE_EVERBODY => lang('everybody'),
+                               SITEMGR_VIEWABLE_USER => lang('phpgw users'),
+                               SITEMGR_VIEWABLE_ADMIN => 
lang('administrators'),
+                               SITEMGR_VIEWABLE_ANONYMOUS => lang('anonymous')
                        );
-                       $preferenceso = 
CreateObject('sitemgr.sitePreference_SO', true);
-                       $this->sitelanguages = 
explode(',',$preferenceso->getPreference('sitelanguages'));
-                       $sessionlang = 
$GLOBALS['phpgw']->session->appsession('worklanguage','sitemgr');
-                       $this->worklanguage = $sessionlang ? $sessionlang : 
$this->sitelanguages[0];
+
+                       $this->sitelanguages = 
$GLOBALS['Common_BO']->sites->current_site['sitelanguages'];
+                       $savelanguage = $_POST['savelanguage'];
+                       if ($savelanguage)
+                       {
+                               //we save the language the user chooses as 
session variable
+                               $this->worklanguage = $savelanguage;
+                               
$GLOBALS['phpgw']->session->appsession('worklanguage','sitemgr',$savelanguage);
+                       }
+                       else
+                       {
+                               $sessionlang = 
$GLOBALS['phpgw']->session->appsession('worklanguage','sitemgr');
+                               $this->worklanguage = $sessionlang ? 
$sessionlang : $this->sitelanguages[0];
+                       }
                        $this->errormsg = array();
+
+                       if (count($this->sitelanguages) > 1)
+                       {
+                               $this->langselect = lang('as') . ' <select 
name="savelanguage">';
+                               foreach ($this->sitelanguages as $lang)
+                               {
+                                       $selected= '';
+                                        if ($lang == $this->worklanguage)
+                                        {
+                                                $selected = 
'selected="selected" ';
+                                        }
+                                        $this->langselect .= '<option ' . 
$selected .'value="' . $lang . '">'. $GLOBALS['Common_BO']->getlangname($lang) 
. '</option>';
+                                }
+                                $this->langselect .= '</select> ';
+                        }
                }

-               function _manageContent()
+               function manage()
                {
-                       $this->common_ui->DisplayHeader();
+                       //This allows us to use FCKeditor for WYSIWYG html 
editing - skwashd
+                       if ( !isset($GLOBALS['phpgw']->js) || 
!is_object($GLOBALS['phpgw']->js) )
+                       {
+                               $GLOBALS['phpgw']->js = 
createObject('phpgwapi.javascript');
+                       }
+                       $GLOBALS['phpgw']->js->validate_file('fckeditor', 
'fckeditor', 'news_admin');
+
+                       $GLOBALS['Common_BO']->globalize(array(
+                               
'inputblockid','inputblocktitle','inputblocksort','inputblockview',
+                               
'inputstate','btnSaveBlock','btnDeleteBlock','btnCreateVersion',
+                               
'btnDeleteVersion','inputmoduleid','inputarea','btnAddBlock','element'
+                       ));
+                       global $inputblockid, $inputblocktitle, 
$inputblocksort,$inputblockview;
+                       global 
$inputstate,$btnSaveBlock,$btnDeleteBlock,$btnCreateVersion;
+                       global $inputmoduleid, $inputarea, $btnAddBlock, 
$btnDeleteVersion, $element;

-                       
$GLOBALS['Common_BO']->globalize(array('blockid','blocktitle','blocksort','blockview','blockactif','btnSaveBlock','btnDeleteBlock','module_id','area','btnAddBlock','element','savelanguage'));
-                       global $blockid, $blocktitle, 
$blocksort,$blockview,$blockactif,$btnSaveBlock,$btnDeleteBlock, $module_id, 
$area, $btnAddBlock, $element, $savelanguage;
+                       global $page_id,$cat_id;
                        $page_id = $_GET['page_id'];
                        $cat_id = $_GET['cat_id'];
-                       $scopename = $page_id ? lang('Page') : ($cat_id ? 
lang('Category') : lang('Site'));
+                       $block_id = $_GET['block_id'];

-                       if ($page_id)
+                       if ($block_id)
+                       {}
+                       elseif ($page_id)
                        {
                                $page = 
$GLOBALS['Common_BO']->pages->getPage($page_id);
+                               if 
(!$GLOBALS['Common_BO']->acl->can_write_category($page->cat_id))
+                               {
+                                       
$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/index.php','menuaction=sitemgr.Outline_UI.manage'));
+                                       return;
+                               }
                                $page_or_cat_name = $page->name;
                                $cat_id = $page->cat_id;
-                               $managelink = 
$GLOBALS['phpgw']->link('/index.php','menuaction=sitemgr.Pages_UI._managePage');
                                $goto = lang('Page manager');
                                $scopename = lang('Page');
                        }
-                       elseif ($cat_id)
+                       elseif ($cat_id != CURRENT_SITE_ID)
                        {
                                $cat = 
$GLOBALS['Common_BO']->cats->getCategory($cat_id);
+                               if 
(!$GLOBALS['Common_BO']->acl->can_write_category($cat_id))
+                               {
+                                       
$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/index.php','menuaction=sitemgr.Outline_UI.manage'));
+                                       return;
+                               }
                                $page_or_cat_name = $cat->name;
                                $page_id = 0;
-                               $managelink = 
$GLOBALS['phpgw']->link('/index.php','menuaction=sitemgr.Categories_UI._manageCategories');
                                $goto = lang('Category manager');
                                $scopename = lang('Category');
                        }
                        else
                        {
-                               $cat_id = 0;
                                $page_id = 0;
+                               $scopename = lang('Site');
                        }

-                       $this->t->set_file('Managecontent', 
'manage_content.tpl');
-                       
$this->t->set_block('Managecontent','Contentarea','CBlock');
-                       $this->t->set_block('Contentarea','Module','MBlock');
-                       $this->t->set_block('Module','Moduleeditor','MeBlock');
-                       $this->t->set_block('Module','Moduleview','MvBlock');
-                       
$this->t->set_block('Moduleeditor','EditorElement','EeBlock');
-                       
$this->t->set_block('Moduleview','ViewElement','VeBlock');
-                       $this->t->set_var(Array(
-                               'lang_reset' => lang('Reset'),
-                               'lang_save' => lang('Save'),
-                               'content_manager' => lang('%1 content manager', 
$scopename),
-                               'page_or_cat_name' => ($page_or_cat_name ? (' - 
' . $page_or_cat_name) : ''),
-                               'managelink' => ($managelink ? ('<a href="' . 
$managelink . '">&lt; ' . lang('Go to') . ' ' . $goto . ' &gt;</a>') : '')
-                               ));
-
                        if ($btnAddBlock)
                        {
-                               if ($module_id)
+                               if ($inputmoduleid)
                                {
                                        $block = 
CreateObject('sitemgr.Block_SO',True);
-                                       $block->module_id = $module_id;
-                                       $block->area = $area;
+                                       $block->module_id = $inputmoduleid;
+                                       $block->area = $inputarea;
                                        $block->page_id = $page_id;
                                        $block->cat_id = $cat_id;

-                                       if (!$this->bo->addblock($block))
+                                       $newblock = $this->bo->addblock($block);
+                                       if ($newblock)
                                        {
-                                               $this->errormsg[] = lang("You 
are not entitled to create module %1 on this scope",$module_id);
+                                               
$this->bo->createversion($newblock);
+                                       }
+                                       else
+                                       {
+                                               $this->errormsg[] = lang("You 
are not entitled to create module %1 on this scope",$inputmoduleid);
                                        }
                                }
                                else
@@ -108,45 +149,105 @@
                        }
                        elseif ($btnSaveBlock)
                        {
-                               $moduleobject = 
$this->bo->getblockmodule($blockid);
-
-                               if ($moduleobject->validate($element))
+                               if ( !isset($GLOBALS['data_cleaner']) || 
!is_object($GLOVALS['data_cleaner']) )
                                {
-                                       if ($savelanguage)
-                                       {
-                                               //we save the language the user 
chooses as session variable
-                                               $this->worklanguage = 
$savelanguage;
-                                               
$GLOBALS['phpgw']->session->appsession('worklanguage','sitemgr',$savelanguage);
-                                       }
-
-                                       $block = 
CreateObject('sitemgr.Block_SO',True);
-                                       $block->id = $blockid;
-                                       $block->title = $blocktitle;
-                                       $block->sort_order = $blocksort;
-                                       $block->view = $blockview;
-                                       $block->actif = $blockactif ? 1 : 0;
-                                       if 
(!$this->bo->saveblockdata($block,$element,$this->worklanguage))
-                                       {
-                                               $this->errormsg[] = lang("You 
are not entitled to edit block %1",$blockid);
-                                       }
+                                       $GLOBALS['data_cleaner'] = 
createObject('phpgwapi.data_cleaner', '');
                                }
-                               if ($moduleobject->validation_error)
+
+                               $element = 
clean_vars($GLOBALS['RAW_REQUEST']['element'], false);
+
+                               $block = CreateObject('sitemgr.Block_SO',True);
+                               $block->id = $inputblockid;
+                               $block->title = $inputblocktitle;
+                               $block->sort_order = $inputblocksort;
+                               $block->view = $inputblockview;
+                               $result = 
$this->bo->saveblockdata($block,$element,$inputstate,$this->worklanguage);
+                               if ($result !== True)
                                {
-                                       $this->errormsg[] = 
$moduleobject->validation_error;
+                                       //result should be an array of 
validationerrors
+                                       $this->errormsg = $result;
                                }
                        }
                        elseif ($btnDeleteBlock)
                        {
-                               if (!$this->bo->removeblock($blockid))
+                               if (!$this->bo->removeblock($inputblockid))
+                               {
+                                       $this->errormsg[] =  lang("You are not 
entitled to edit block %1",$inputblockid);
+                               }
+                               //if we delete a block we were editing, there 
is nothing left to do
+                               if ($block_id)
                                {
-                                       $this->errormsg[] =  lang("You are not 
entitled to edit block %1",$blockid);
+                                       echo '<html><head></head><body 
onload="opener.location.reload();self.close()"></body></html>';
                                }
                        }
+                       elseif ($btnCreateVersion)
+                       {
+                               $this->bo->createversion($inputblockid);
+                       }
+                       elseif ($btnDeleteVersion)
+                       {
+                               $version_id = array_keys($btnDeleteVersion);
+                               $this->bo->deleteversion($version_id[0]);
+                       }
+
+                       //if we are called with a block_id GET parameter, it is 
from sitemgr-site edit mode or from archiv/commit
+                       //we are shown in a separate edit window, without 
navbar.
+                       if ($block_id)
+                       {
+                               $block = 
$this->bo->getblock($block_id,$this->worklanguage);
+                               if (!($block && 
$GLOBALS['Common_BO']->acl->can_write_category($block->cat_id)))
+                               {
+                                       echo '<p><center><b>'.lang('Attempt to 
edit non-editable block').'</b></center>';
+                                       
$GLOBALS['phpgw']->common->phpgw_exit(True);
+                               }
+                               $this->t->set_file('Blocks', 'edit_block.tpl');
+                               $this->t->set_block('Blocks','Block');
+                               
$this->t->set_block('Block','Moduleeditor','MeBlock');
+                               
$this->t->set_block('Block','Moduleview','MvBlock');
+                               
$this->t->set_block('Moduleeditor','Version','EvBlock');
+                               
$this->t->set_block('Blocks','EditorElement','EeBlock');
+                               
$this->t->set_block('Moduleview','ViewElement','VeBlock');
+
+                               $this->t->set_var(array(
+                                       'savebutton' => lang('Save block'),
+                                       'deletebutton' => lang('Delete block'),
+                                       'contentarea' => lang('Contentarea'),
+                                       'createbutton' => lang('Create new 
version'),
+                                       'standalone' => 
"<html><head></head><body>",
+                                       'donebutton' => '<input type="reset" 
onclick="opener.location.reload();self.close()" value="' . lang('Done') . '"  
/>'
+                               ));
+                               $this->showblock($block,True,True);
+                               $this->t->pfp('out','Block');
+                               return;
+                       }
+
+                       $this->common_ui->DisplayHeader();
+
+                       $this->t->set_file('Managecontent', 
'manage_content.tpl');
+                       $this->t->set_file('Blocks','edit_block.tpl');
+                       
$this->t->set_block('Managecontent','Contentarea','CBlock');
+                       $this->t->set_block('Blocks','Block');
+                       $this->t->set_block('Block','Moduleeditor','MeBlock');
+                       $this->t->set_block('Block','Moduleview','MvBlock');
+                       $this->t->set_block('Moduleeditor','Version','EvBlock');
+                       $this->t->set_block('Blocks','EditorElement','EeBlock');
+                       
$this->t->set_block('Moduleview','ViewElement','VeBlock');
+                       $this->t->set_var(Array(
+                               'content_manager' => lang('%1 content manager', 
$scopename),
+                               'page_or_cat_name' => ($page_or_cat_name ? (' - 
' . $page_or_cat_name) : '')
+                               ));
+

                        $contentareas = $this->bo->getContentAreas();
-                       if ($contentareas)
+                       if (is_array($contentareas))
                        {
-                               $this->t->set_var('help', lang('You can 
override each content blocks default title. Be aware that not in all content 
areas the block title will be visible.'));
+                               $this->t->set_var(array(
+                                       'help' => lang('You can override each 
content blocks default title. Be aware that not in all content areas the block 
title will be visible.'),
+                                       'savebutton' => lang('Save block'),
+                                       'deletebutton' => lang('Delete block'),
+                                       'contentarea' => lang('Contentarea'),
+                                       'createbutton' => lang('Create new 
version'),
+                               ));

                                foreach ($contentareas as $contentarea)
                                {
@@ -156,15 +257,15 @@
                                                'area' => $contentarea,
                                                'addblockform' =>
                                                        ($permittedmodules ?
-                                                               ('<form 
method="POST"><input type="hidden" value="' . $contentarea . '" name="area" />' 
.
-                                                                       
'<select style="vertical-align:middle" size="10" name="module_id">' .
+                                                               ('<form 
method="POST"><input type="hidden" value="' . $contentarea . '" 
name="inputarea" />' .
+                                                                       
'<select style="vertical-align:middle" size="10" name="inputmoduleid">' .
                                                                        
$this->inputmoduleselect($permittedmodules) .
                                                                        
'</select><input type="submit" name="btnAddBlock" value="' .
                                                                        
lang('Add block to content area %1',$contentarea) .
                                                                        '" 
/></form>') :
                                                                lang('No 
modules permitted for this content area/category')
                                                        ),
-                                               'error' => ($contentarea == 
$area && $this->errormsg) ? join('<br>',$this->errormsg) : '',
+                                               'error' => (($contentarea == 
$inputarea) && $this->errormsg) ? join('<br>',$this->errormsg) : '',
                                        ));

                                        //we get all blocks for the page and 
its category, and site wide,
@@ -172,136 +273,16 @@
                                        //if we have just edited a block in a 
certain language, we request all blocks in this language
                                        $blocks = 
$this->bo->getallblocksforarea($contentarea,$cat_id,$page_id,$this->worklanguage);

-                                       $this->t->set_var('MBlock','');
+                                       $this->t->set_var('blocks','');

                                        if ($blocks)
                                        {
-                                               if (count($this->sitelanguages) 
> 1)
-                                               {
-                                                       $select = lang('as') . 
' <select name="savelanguage">';
-
-                                                       foreach 
($this->sitelanguages as $lang)
-                                                       {
-                                                               $selected= '';
-                                                               if ($lang == 
$this->worklanguage)
-                                                               {
-                                                                       
$selected = 'selected="selected" ';
-                                                               }
-                                                                       $select 
.= '<option ' . $selected .'value="' . $lang . '">'. 
$GLOBALS['Common_BO']->getlangname($lang) . '</option>';
-                                                               }
-                                                               $select .= 
'</select> ';
-                                                               
$this->t->set_var('savelang',$select);
-                                               }
-                                               while (list($id,$block) = 
each($blocks))
+                                               while (list(,$block) = 
each($blocks))
                                                {
-                                                       //TODO: wrap a module 
storage around createmodule as in template3,
-                                                       //TODO: so that we do 
not create the same module object twice
-                                                       $moduleobject = 
$this->modulebo->createmodule($block->module_name);
-                                                       $this->t->set_var(array(
-                                                               'moduleinfo' => 
($block->module_name),
-                                                               'description' 
=> $moduleobject->description,
-                                                       ));
-
                                                        //if the block is in 
our scope and we are entitled we edit it
-                                                       if ($block->page_id == 
$page_id &&
-                                                               $block->cat_id 
== $cat_id)
-                                                       {
-                                                               
$editorstandardelements = array(
-                                                                       
array('label' => lang('Title'),
-                                                                               
  'form' => ('<input type="text" name="blocktitle" value="' .
-                                                                               
        ($block->title ? $block->title : $moduleobject->title) . '" />')
-                                                                       ),
-                                                                       
array('label' => lang('Actif'),
-                                                                               
  'form' => ('<input type="checkbox" name="blockactif"' .
-                                                                               
         ($block->actif ? 'checked="checked"' : '') . '">')
-                                                                       ),
-                                                                       
array('label' => lang('Seen by'),
-                                                                               
  'form' => ('<select name="blockview">' .
-                                                                               
        $this->inputviewselect((int)$block->view) . '</select>')
-                                                                       ),
-                                                                       
array('label' => lang('Sort order'),
-                                                                               
  'form' => ('<input type="text" name="blocksort" size="2" value="' .
-                                                                               
        (int)$block->sort_order . '">')
-                                                                       )
-                                                               );
-                                                               
$moduleobject->set_block($block);
-                                                               
$editormoduleelements = $moduleobject->get_user_interface();
-                                                               $interface = 
array_merge($editorstandardelements,$editormoduleelements);
-                                                               
$this->t->set_var(Array(
-                                                                       
'blockid' => $id,
-                                                                       
'savebutton' => '<input type="submit" value="Save" name="btnSaveBlock" />',
-                                                                       
'deletebutton' => '<input type="submit" value="Delete" name="btnDeleteBlock" 
/>',
-                                                                       
'validationerror' => ($id == $blockid && $this->errormsg) ? 
join('<br>',$this->errormsg) : '',
-                                                               ));
-                                                               
$this->t->set_var('EeBlock','');
-                                                               while 
(list(,$element) = each($interface))
-                                                               {
-                                                                       
$this->t->set_var(Array(
-                                                                               
'label' => $element['label'],
-                                                                               
'form' => $element['form']
-                                                                       ));
-                                                                       
$this->t->parse('EeBlock','EditorElement', true);
-                                                               }
-                                                               
$this->t->parse('MeBlock','Moduleeditor');
-                                                               
$this->t->set_var('MvBlock','');
-                                                       }
-                                                       //otherwise we only 
show it
-                                                       else
-                                                       {
-                                                               if 
($block->page_id)
-                                                               {
-                                                                       
$blockscope = lang('Page');
-                                                               }
-                                                               elseif 
($block->cat_id)
-                                                               {
-                                                                       $cat = 
$GLOBALS['Common_BO']->cats->getCategory($block->cat_id);
-                                                                       
$blockscope =  lang('Category') . ' - ' . $cat->name;
-                                                               }
-                                                               else
-                                                               {
-                                                                       
$blockscope =  lang('Site');
-                                                               }
-
-                                                               
$viewstandardelements = array(
-                                                                       
array('label' => lang('Scope'),
-                                                                               
  'value' => $blockscope
-                                                                       ),
-                                                                       
array('label' => lang('Title'),
-                                                                               
  'value' => ($block->title ? $block->title : $moduleobject->title)
-                                                                       ),
-                                                                       
array('label' => lang('Actif'),
-                                                                               
  'value' => ($block->actif ? lang('Yes') : lang('No'))
-                                                                       ),
-                                                                       
array('label' => lang('Seen by'),
-                                                                               
  'value' => $this->viewable[(int)$block->view]
-                                                                       ),
-                                                                       
array('label' => lang('Sort order'),
-                                                                               
  'value' => (int)$block->sort_order
-                                                                       )
-                                                               );
-                                                               
$viewmoduleelements = array();
-                                                               while 
(list($argument,$argdef) = @each($moduleobject->arguments))
-                                                               {
-                                                                       $value 
= $block->arguments[$argument];
-                                                                       
$viewmoduleelements[] = array(
-                                                                               
'label' => $argdef['label'],
-                                                                               
'value' => $GLOBALS['phpgw']->strip_html($value)
-                                                                       );
-                                                               }
-                                                               $interface = 
array_merge($viewstandardelements,$viewmoduleelements);
-                                                               
$this->t->set_var('VeBlock','');
-                                                               while 
(list(,$element) = each($interface))
-                                                               {
-                                                                       
$this->t->set_var(Array(
-                                                                               
'label' => $element['label'],
-                                                                               
'value' => $element['value'])
-                                                                       );
-                                                                       
$this->t->parse('VeBlock','ViewElement', true);
-                                                               }
-                                                               
$this->t->parse('MvBlock','Moduleview');
-                                                               
$this->t->set_var('MeBlock','');
-                                                       }
-                                               
$this->t->parse('MBlock','Module', true);
+                                                       $editable = 
($block->page_id == $page_id && $block->cat_id == $cat_id);
+                                                       
$this->showblock($block,$editable);
+                                                       
$this->t->parse('blocks','Block', true);
                                                }
                                        }
                                        $this->t->parse('CBlock','Contentarea', 
true);
@@ -309,10 +290,186 @@
                        }
                        else
                        {
-                               $this->t->set_var('CBlock',lang('No content 
areas found in selected template'));
+                               $this->t->set_var('CBlock',$contentareas);
                        }
                        $this->t->pfp('out', 'Managecontent');
-                       $this->common_ui->DisplayFooter();
+                       $this->common_ui->DisplayFooter();
+               }
+
+               function commit()
+               {
+                       if ($_POST['btnCommit'])
+                       {
+                               while(list($cat_id,) = @each($_POST['cat']))
+                               {
+                                       
$GLOBALS['Common_BO']->cats->commit($cat_id);
+                               }
+                               while(list($page_id,) = @each($_POST['page']))
+                               {
+                                       
$GLOBALS['Common_BO']->pages->commit($page_id);
+                               }
+                               while(list($block_id,) = @each($_POST['block']))
+                               {
+                                       $this->bo->commit($block_id);
+                               }
+                       }
+                       $this->common_ui->DisplayHeader();
+
+                       $this->t->set_file('Commit','commit.tpl');
+                       $this->t->set_block('Commit','Category','Cblock');
+                       $this->t->set_block('Commit','Page','Pblock');
+                       $this->t->set_block('Commit','Block','Bblock');
+                       $this->t->set_var(array(
+                               'commit_manager'        => lang('Commit 
changes'),
+                               'lang_categories'       => lang('Categories'),
+                               'lang_pages'            => lang('Pages'),
+                               'lang_blocks'           => lang('Content 
blocks'),
+                               'lang_commit'           => lang('Commit 
changes'),
+                               'lang_select_all'       => lang('select all')
+                       ));
+
+                       //Categories
+                       $cats = 
$GLOBALS['Common_BO']->cats->getpermittedcatsCommitable();
+                       while (list(,$cat_id) = @each($cats))
+                       {
+                               $cat = 
$GLOBALS['Common_BO']->cats->getCategory($cat_id,$this->sitelanguages[0]);
+                               $this->t->set_var(array(
+                                       'category' => $cat->name,
+                                       'catid' => $cat_id,
+                                       'addedorremoved' => ($cat->state == 
SITEMGR_STATE_PREPUBLISH) ? 'added' : 'removed',
+                                       'edit' => 
$GLOBALS['phpgw']->link('/index.php',array(
+                                               'cat_id' => $cat_id,
+                                               'menuaction' => 
'sitemgr.Categories_UI.edit'
+                                       ))
+                               ));
+                               $this->t->parse('Cblock','Category',True);
+                       }
+
+                       //Pages
+                       $pages = 
$GLOBALS['Common_BO']->pages->getpageIDListCommitable();
+
+                       while (list(,$page_id) = @each($pages))
+                       {
+                               $page = 
$GLOBALS['Common_BO']->pages->getPage($page_id);
+                               $this->t->set_var(array(
+                                       'page' => $page->name,
+                                       'pageid' => $page_id,
+                                       'addedorremoved' => ($page->state == 
SITEMGR_STATE_PREPUBLISH) ? 'added' : 'removed',
+                                       'edit' => 
$GLOBALS['phpgw']->link('/index.php',array(
+                                               'page_id' => $page_id,
+                                               'menuaction' => 
'sitemgr.Pages_UI.edit'
+                                       ))
+                               ));
+                               $this->t->parse('Pblock','Page',True);
+                       }
+
+                       //Content Blocks
+                       $blocks = $this->bo->getcommitableblocks();
+                       while (list($block_id,$block) = @each($blocks))
+                       {
+                               $this->t->set_var(array(
+                                       'block' => 
$this->bo->getlangblocktitle($block_id,$this->sitelanguages[0]),
+                                       'blockid' => $block_id,
+                                       'scope' => 
$this->blockscope($block->cat_id,$block->page_id),
+                                       'addedorremovedorreplaced' => 
($block->cnt == 2) ? 'replaced' :
+                                               (($block->state == 
SITEMGR_STATE_PREPUBLISH) ? 'added' : 'removed'),
+                                       'edit' =>  
$GLOBALS['phpgw']->link('/index.php',array(
+                                               'block_id' => $block_id,
+                                               'menuaction' => 
'sitemgr.Content_UI.manage'
+                                       ))
+                               ));
+                               $this->t->parse('Bblock','Block',True);
+                       }
+
+                       $this->t->pfp('out', 'Commit');
+                       $this->common_ui->DisplayFooter();
+               }
+
+               function archive()
+               {
+                       if ($_POST['btnReactivate'])
+                       {
+                               while(list($cat_id,) = @each($_POST['cat']))
+                               {
+                                       
$GLOBALS['Common_BO']->cats->reactivate($cat_id);
+                               }
+                               while(list($page_id,) = @each($_POST['page']))
+                               {
+                                       
$GLOBALS['Common_BO']->pages->reactivate($page_id);
+                               }
+                               while(list($block_id,) = @each($_POST['block']))
+                               {
+                                       $this->bo->reactivate($block_id);
+                               }
+                       }
+
+                       $this->common_ui->DisplayHeader();
+
+                       $this->t->set_file('Commit','archive.tpl');
+                       $this->t->set_block('Commit','Category','Cblock');
+                       $this->t->set_block('Commit','Page','Pblock');
+                       $this->t->set_block('Commit','Block','Bblock');
+                       $this->t->set_var(array(
+                               'commit_manager' => lang('Archived content'),
+                               'lang_categories' => lang('Categories'),
+                               'lang_pages' => lang('Pages'),
+                               'lang_blocks' => lang('Content blocks'),
+                               'lang_reactivate' => lang('Reactivate content')
+                       ));
+
+                       //Categories
+                       $cats = 
$GLOBALS['Common_BO']->cats->getpermittedcatsArchived();
+                       //we have to append the archived cats to the 
currentcats, in order to be able to access them later
+                       $GLOBALS['Common_BO']->cats->currentcats = 
array_merge($GLOBALS['Common_BO']->cats->currentcats,$cats);
+                       while (list(,$cat_id) = @each($cats))
+                       {
+                               $cat = 
$GLOBALS['Common_BO']->cats->getCategory($cat_id,$this->sitelanguages[0],True);
+                               $this->t->set_var(array(
+                                       'category' => $cat->name,
+                                       'catid' => $cat_id,
+                                       'edit' => 
$GLOBALS['phpgw']->link('/index.php',array(
+                                               'cat_id' => $cat_id,
+                                               'menuaction' => 
'sitemgr.Categories_UI.edit'
+                                       ))
+                               ));
+                               $this->t->parse('Cblock','Category',True);
+                       }
+
+                       //Pages
+                       $pages = 
$GLOBALS['Common_BO']->pages->getpageIDListArchived();
+
+                       while (list(,$page_id) = @each($pages))
+                       {
+                               $page = 
$GLOBALS['Common_BO']->pages->getPage($page_id);
+                               $this->t->set_var(array(
+                                       'page' => $page->name,
+                                       'pageid' => $page_id,
+                                       'edit' => 
$GLOBALS['phpgw']->link('/index.php',array(
+                                               'page_id' => $page_id,
+                                               'menuaction' => 
'sitemgr.Pages_UI.edit'
+                                       ))
+                               ));
+                               $this->t->parse('Pblock','Page',True);
+                       }
+
+                       //Content Blocks
+                       $blocks = $this->bo->getarchivedblocks();
+                       while (list($block_id,$block) = @each($blocks))
+                       {
+                               $this->t->set_var(array(
+                                       'block' => 
$this->bo->getlangblocktitle($block_id,$this->sitelanguages[0]),
+                                       'blockid' => $block_id,
+                                       'scope' => 
$this->blockscope($block->cat_id,$block->page_id),
+                                       'edit' =>  
$GLOBALS['phpgw']->link('/index.php',array(
+                                               'block_id' => $block_id,
+                                               'menuaction' => 
'sitemgr.Content_UI.manage'
+                                       ))
+                               ));
+                               $this->t->parse('Bblock','Block',True);
+                       }
+
+                       $this->t->pfp('out', 'Commit');
+                       $this->common_ui->DisplayFooter();
                }

                function inputmoduleselect($modules)
@@ -336,6 +493,164 @@
                                        $display.'</option>'."\n";
                        }
                        return $returnValue;
+               }
+
+               function blockscope($cat_id,$page_id)
+               {
+                       if ($cat_id == CURRENT_SITE_ID)
+                       {
+                               $scope = lang('Site wide');
+                       }
+                       else
+                       {
+                               $cat = 
$GLOBALS['Common_BO']->cats->getCategory($cat_id);
+                               $scope = lang('Category') . ' ' . $cat->name;
+                               if ($page_id)
+                               {
+                                       $page = 
$GLOBALS['Common_BO']->pages->getPage($page_id);
+                                       $scope .= ' - ' . lang('Page') . ' ' . 
$page->name;
+                               }
+                       }
+                       return $scope;
+               }
+
+               //if the block is shown on its own ($standalone), we add 
information about its,scope
+               function showblock($block,$editable,$standalone=False)
+               {
+                       global $page_id,$cat_id, $inputblockid;
+                       //TODO: wrap a module storage around createmodule as in 
template3,
+                       //TODO: so that we do not create the same module object 
twice
+                       $moduleobject = 
$this->modulebo->createmodule($block->module_name);
+
+                       $this->t->set_var(array(
+                               'moduleinfo' => ($block->module_name),
+                               'description' => $moduleobject->description,
+                               'savelang' => $this->langselect
+                       ));
+
+                       //if the block is in our scope and we are entitled we 
edit it
+                       if ($editable)
+                       {
+                               $editorstandardelements = array(
+                                       array('label' => lang('Title'),
+                                                 'form' => ('<input 
type="text" name="inputblocktitle" value="' .
+                                                       ($block->title ? 
$block->title : $moduleobject->title) . '" />')
+                                       ),
+                                       array('label' => lang('Seen by'),
+                                                 'form' => ('<select 
name="inputblockview">' .
+                                                       
$this->inputviewselect((int)$block->view) . '</select>')
+                                       ),
+                                       array('label' => lang('Sort order'),
+                                                 'form' => ('<input 
type="text" name="inputblocksort" size="2" value="' .
+                                                       (int)$block->sort_order 
. '">')
+                                       )
+                               );
+                               if ($standalone)
+                               {
+                                       $editorstandardelements[] = array(
+                                               'label' => lang('Scope'),
+                                               'form' => 
$this->blockscope($block->cat_id,$block->page_id)
+                                       );
+                               }
+
+                               $moduleobject->set_block($block);
+
+                               $this->t->set_var(Array(
+                                       'blockid' => $block->id,
+                                       'validationerror' => (($block->id == 
$inputblockid) && $this->errormsg) ? join('<br>',$this->errormsg) : '',
+                               ));
+                               $this->t->set_var('standardelements','');
+                               while (list(,$element) = 
each($editorstandardelements))
+                               {
+                                       $this->t->set_var(Array(
+                                               'label' => $element['label'],
+                                               'form' => $element['form']
+                                       ));
+                                       
$this->t->parse('standardelements','EditorElement', true);
+                               }
+
+                               $versions = 
$this->bo->getallversionsforblock($block->id,$this->worklanguage);
+                               $this->t->set_var('EvBlock','');
+                               while (list($version_id,$version) = 
each($versions))
+                               {
+                                       //set the version of the block which is 
referenced by the moduleobject,
+                                       //so that we retrieve a interface with 
the current version's arguments
+                                       $block->set_version($version);
+                                       $editormoduleelements = 
$moduleobject->get_user_interface();
+                                       $this->t->set_var(array(
+                                               'version_id' => $version_id,
+                                               'state' => 
$GLOBALS['Common_BO']->inputstateselect($version['state']),
+                                               'deleteversion' => lang('Delete 
Version'),
+                                               'versionelements' => ''
+                                       ));
+                                       while (list(,$element) = 
each($editormoduleelements))
+                                       {
+                                               $this->t->set_var(Array(
+                                                       'label' => 
$element['label'],
+                                                       'form' => 
$element['form']
+                                               ));
+                                               
$this->t->parse('versionelements','EditorElement', true);
+                                       }
+                                       $this->t->parse('EvBlock','Version', 
true);
+                               }
+
+                               $this->t->parse('MeBlock','Moduleeditor');
+                               $this->t->set_var('MvBlock','');
+                       }
+                       //otherwise we only show it
+                       else
+                       {
+                               if ($block->page_id)
+                               {
+                                       $blockscope = lang('Page');
+                               }
+                               elseif ($block->cat_id != CURRENT_SITE_ID)
+                               {
+                                       $cat = 
$GLOBALS['Common_BO']->cats->getCategory($block->cat_id);
+                                       $blockscope =  lang('Category') . ' - ' 
. $cat->name;
+                               }
+                               else
+                               {
+                                       $blockscope =  lang('Site');
+                               }
+
+                               $viewstandardelements = array(
+                                       array('label' => lang('Scope'),
+                                                 'value' => $blockscope
+                                       ),
+                                       array('label' => lang('Title'),
+                                                 'value' => ($block->title ? 
$block->title : $moduleobject->title)
+                                       ),
+                                       array('label' => lang('Seen by'),
+                                                 'value' => 
$this->viewable[(int)$block->view]
+                                       ),
+                                       array('label' => lang('Sort order'),
+                                                 'value' => 
(int)$block->sort_order
+                                       )
+                               );
+//                                                             
$viewmoduleelements = array();
+//                                                             while 
(list($argument,$argdef) = @each($moduleobject->arguments))
+//                                                             {
+//                                                                     $value 
= $block->arguments[$argument];
+//                                                                     
$viewmoduleelements[] = array(
+//                                                                             
'label' => $argdef['label'],
+//                                                                             
'value' => $GLOBALS['phpgw']->strip_html($value)
+//                                                                     );
+//                                                             }
+//                                                             $interface = 
array_merge($viewstandardelements,$viewmoduleelements);
+$interface = $viewstandardelements;
+                               $this->t->set_var('VeBlock','');
+                               while (list(,$element) = each($interface))
+                               {
+                                       $this->t->set_var(Array(
+                                               'label' => $element['label'],
+                                               'value' => $element['value'])
+                                       );
+                                       
$this->t->parse('VeBlock','ViewElement', true);
+                               }
+                               $this->t->parse('MvBlock','Moduleview');
+                               $this->t->set_var('MeBlock','');
+                       }
                }
        }







reply via email to

[Prev in Thread] Current Thread [Next in Thread]