More workspace stuff for beta.
[Packages/TYPO3.CMS.git] / typo3 / mod / user / ws / index.php
index 37746ed..8be9725 100755 (executable)
  *
  *
  *
- *  103: class SC_mod_user_ws_index extends t3lib_SCbase
+ *  107: class SC_mod_user_ws_index extends t3lib_SCbase
  *
  *              SECTION: Standard module initialization
- *  136:     function menuConfig()
- *  181:     function init()
- *  236:     function main()
- *  268:     function printContent()
+ *  142:     function menuConfig()
+ *  188:     function init()
+ *  250:     function main()
+ *  282:     function printContent()
  *
  *              SECTION: Module content: Publish
- *  298:     function moduleContent_publish()
- *  381:     function displayVersionDetails($details)
- *  390:     function displayWorkspaceOverview()
- *  454:     function displayWorkspaceOverview_list($pArray, $tableRows=array(), $c=0)
- *  604:     function displayWorkspaceOverview_pageTreeIconTitle($pageUid, $title, $indentCount)
- *  621:     function displayWorkspaceOverview_commandLinks($table,&$rec_on,&$rec_off)
- *  654:     function displayWorkspaceOverview_setInPageArray(&$pArray,$rlArr,$table,$row)
- *  683:     function subElements($uid,$treeLevel,$origId=0)
- *  785:     function subElements_getNonPageRecords($tN, $uid, &$recList)
- *  814:     function subElements_renderItem(&$tCell,$tN,$uid,$rec,$origId,$iconMode,$HTMLdata)
- *  880:     function markupNewOriginals()
- *  902:     function createDiffView($table, $diff_1_record, $diff_2_record)
+ *  312:     function moduleContent_publish()
+ *  410:     function displayVersionDetails($details)
+ *  419:     function displayWorkspaceOverview()
+ *  491:     function displayWorkspaceOverview_list($pArray, $tableRows=array(), $c=0, $warnAboutVersions=FALSE)
+ *  679:     function displayWorkspaceOverview_pageTreeIconTitle($pageUid, $title, $indentCount)
+ *  694:     function displayWorkspaceOverview_stageCmd($table,&$rec_off)
+ *  779:     function displayWorkspaceOverview_commandLinks($table,&$rec_on,&$rec_off,$vType)
+ *  849:     function displayWorkspaceOverview_commandLinksSub($table,$rec,$origId)
+ *  897:     function displayWorkspaceOverview_setInPageArray(&$pArray,$rlArr,$table,$row)
+ *  928:     function subElements($uid,$treeLevel,$origId=0)
+ * 1031:     function subElements_getNonPageRecords($tN, $uid, &$recList)
+ * 1061:     function subElements_renderItem(&$tCell,$tN,$uid,$rec,$origId,$iconMode,$HTMLdata)
+ * 1130:     function markupNewOriginals()
+ * 1152:     function createDiffView($table, $diff_1_record, $diff_2_record)
  *
  *              SECTION: Module content: Workspace list
- *  995:     function moduleContent_workspaceList()
+ * 1284:     function moduleContent_workspaceList()
  *
  *              SECTION: Helper functions
- * 1043:     function formatVerId($verId)
- * 1053:     function formatWorkspace($wsid)
- * 1080:     function formatCount($count)
+ * 1332:     function formatVerId($verId)
+ * 1342:     function formatWorkspace($wsid)
+ * 1369:     function formatCount($count)
+ * 1396:     function versionsInOtherWS($table,$uid)
+ * 1426:     function showStageChangeLog($table,$id,$stageCommands)
  *
  *              SECTION: Processing
- * 1121:     function publishAction()
+ * 1485:     function publishAction()
  *
- * TOTAL FUNCTIONS: 21
+ * TOTAL FUNCTIONS: 25
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
@@ -121,7 +125,8 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
        var $targets = array();         // Accumulation of online targets.
        var $pageModule = '';
        var $publishAccess = FALSE;
-
+       var $be_user_Array = array();
+       var $stageIndex = array();
 
 
        /*********************************
@@ -149,10 +154,10 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                                0 => 'All',
                        ),
                        'display' => array(
-                               0 => '[ONLINE]',
-                               -98 => 'Workspaces',
+                               0 => '[Live workspace]',
+                               -98 => 'Draft Workspaces',
                                -99 => 'All',
-                               -1 => '[Offline]'
+                               -1 => '[Default Draft]'
                        ),
                        'diff' => array(
                                0 => 'No diff.',
@@ -349,9 +354,9 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                $actionLinks = '';
                if ($GLOBALS['BE_USER']->workspace!==0) {
                        if ($this->publishAccess)       {
-                               $actionLinks.= '<input type="submit" name="_publish" value="Publish workspace" onclick="return confirm(\'Are you sure you want to publish all content of the workspace?\');"/>';
+                               $actionLinks.= '<input type="submit" name="_publish" value="Publish workspace" onclick="return confirm(\'Are you sure you want to publish all content '.($GLOBALS['BE_USER']->workspaceRec['publish_access']&1 ? 'in &quot;Publish&quot; stage ':'').'from the workspace?\');"/>';
                                if ($GLOBALS['BE_USER']->workspaceSwapAccess()) {
-                                       $actionLinks.= '<input type="submit" name="_swap" value="Swap workspace" onclick="return confirm(\'Are you sure you want to publish (swap) all content of the workspace?\');" />';
+                                       $actionLinks.= '<input type="submit" name="_swap" value="Swap workspace" onclick="return confirm(\'Are you sure you want to publish (swap) all content '.($GLOBALS['BE_USER']->workspaceRec['publish_access']&1 ? 'in &quot;Publish&quot; stage ':'').'from the workspace?\');" />';
                                }
                        } else {
                                $actionLinks.= $this->doc->icons(1).'You are not permitted to publish from this workspace';
@@ -417,6 +422,12 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                        // Initialize variables:
                $this->showWorkspaceCol = $GLOBALS['BE_USER']->workspace===0 && $this->MOD_SETTINGS['display']<=-98;
 
+                       // Get usernames and groupnames
+               $be_group_Array = t3lib_BEfunc::getListGroupNames('title,uid');
+               $groupArray = array_keys($be_group_Array);
+               $this->be_user_Array = t3lib_BEfunc::getUserNames();
+               if (!$GLOBALS['BE_USER']->isAdmin())            $this->be_user_Array = t3lib_BEfunc::blindUserNames($this->be_user_Array,$groupArray,1);
+
                        // Initialize Workspace ID and filter-value:
                if ($GLOBALS['BE_USER']->workspace===0) {
                        $wsid = $this->MOD_SETTINGS['display'];         // Set wsid to the value from the menu (displaying content of other workspaces)
@@ -451,8 +462,8 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                $tableRows[] = '
                        <tr class="bgColor5 tableheader">
                                <td nowrap="nowrap" width="100">Pagetree:</td>
-                               <td nowrap="nowrap" colspan="2">Online Version:</td>
-                               <td nowrap="nowrap" colspan="2">Offline Versions:</td>
+                               <td nowrap="nowrap" colspan="2">Live Version:</td>
+                               <td nowrap="nowrap" colspan="2">Draft Versions:</td>
                                <td nowrap="nowrap">Stage:</td>
                                <td nowrap="nowrap">Publish:</td>
                                <td>Lifecycle:</td>
@@ -464,7 +475,6 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
 
                $table = '<table border="0" cellpadding="0" cellspacing="1" class="lrPadding workspace-overview">'.implode('',$tableRows).'</table>';
 
-
                return $table.$this->markupNewOriginals();
        }
 
@@ -475,6 +485,7 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
         * @param       array           Hierarchical storage of the elements to display (see displayWorkspaceOverview() / displayWorkspaceOverview_setInPageArray())
         * @param       array           Existing array of table rows to add to
         * @param       array           Depth counter
+        * @param       boolean         If set, a warning is shown if versions are found (internal flag)
         * @return      array           Table rows, see displayWorkspaceOverview()
         */
        function displayWorkspaceOverview_list($pArray, $tableRows=array(), $c=0, $warnAboutVersions=FALSE)     {
@@ -603,9 +614,9 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                                                                        $versionsInOtherWS = $this->versionsInOtherWS($table, $rec_on['uid']);
                                                                        $versionsInOtherWSWarning = $versionsInOtherWS && $GLOBALS['BE_USER']->workspace!==0 ? '<br/>'.$this->doc->icons(2).'Other version(s) in workspace '.$versionsInOtherWS : '';
                                                                        $multipleWarning = (!$mainCell && $GLOBALS['BE_USER']->workspace!==0? '<br/>'.$this->doc->icons(3).'<b>Multiple versions in same workspace!</b>' : '');
-                                                                       $verWarning = $warnAboutVersions || $warnAboutVersions_nonPages ? '<br/>'.$this->doc->icons(3).'<b>Version inside version!</b>' : '';
+                                                                       $verWarning = $warnAboutVersions || ($warnAboutVersions_nonPages && $GLOBALS['TCA'][$table]['ctrl']['versioning_followPages'])? '<br/>'.$this->doc->icons(3).'<b>Version inside version!</b>' : '';
                                                                        $verElement = $icon.
-                                                                               '<a href="'.htmlspecialchars('index.php?details='.rawurlencode($table.':'.$rec_off['uid'])).'">'.
+                                                                               '<a href="'.htmlspecialchars($this->doc->backPath.t3lib_extMgm::extRelPath('version').'cm1/index.php?id='.($table==='pages'?$rec_on['uid']:$rec_on['pid']).'&details='.rawurlencode($table.':'.$rec_off['uid']).'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
                                                                                t3lib_BEfunc::getRecordTitle($table,$rec_off,TRUE).
                                                                                '</a>'.
                                                                                $versionsInOtherWSWarning.
@@ -633,7 +644,7 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                                                                        $tableRows[] = '
                                                                                <tr class="bgColor4">
                                                                                        '.$mainCell.$verCell.'
-                                                                                       <td nowrap="nowrap">'.$this->displayWorkspaceOverview_stageCmd($table,$rec_off).'</td>
+                                                                                       <td nowrap="nowrap">'.$this->showStageChangeLog($table,$rec_off['uid'],$this->displayWorkspaceOverview_stageCmd($table,$rec_off)).'</td>
                                                                                        <td nowrap="nowrap" class="'.$swapClass.'">'.
                                                                                                $this->displayWorkspaceOverview_commandLinks($table,$rec_on,$rec_off,$vType).
                                                                                                htmlspecialchars($swapLabel).
@@ -687,11 +698,15 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                                $sId = 1;
                                $sLabel = 'Editing';
                                $color = '#666666';
+                               $label = 'Comment for Reviewer:';
+                               $titleAttrib = 'Send to Review';
                        break;
                        case 1:
                                $sId = 10;
                                $sLabel = 'Review';
                                $color = '#6666cc';
+                               $label = 'Comment for Publisher:';
+                               $titleAttrib = 'Approve for Publishing';
                        break;
                        case 10:
                                $sLabel = 'Publish';
@@ -701,6 +716,8 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                                $sLabel = $this->doc->icons(2).'Rejected';
                                $sId = 0;
                                $color = '#ff0000';
+                               $label = 'Comment:';
+                               $titleAttrib = 'Reset stage';
                        break;
                        default:
                                $sLabel = 'Undefined';
@@ -712,13 +729,16 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
 
                $raiseOk = !$GLOBALS['BE_USER']->workspaceCannotEditOfflineVersion($table,$rec_off);
 
-               if ($raiseOk)   {
+               if ($raiseOk && $rec_off['t3ver_stage']!=-1)    {
+                       $onClick = 'var commentTxt=window.prompt("Please explain why you reject:","");
+                                                       if (commentTxt!=null) {document.location="'.$this->doc->issueCommand(
+                                                       '&cmd['.$table.']['.$rec_off['uid'].'][version][action]=setStage'.
+                                                       '&cmd['.$table.']['.$rec_off['uid'].'][version][stageId]=-1'
+                                                       ).'&cmd['.$table.']['.$rec_off['uid'].'][version][comment]="+escape(commentTxt);}'.
+                                                       ' return false;';
                                // Reject:
                        $actionLinks.=
-                               '<a href="'.htmlspecialchars($this->doc->issueCommand(
-                                               '&cmd['.$table.']['.$rec_off['uid'].'][version][action]=setStage'.
-                                               '&cmd['.$table.']['.$rec_off['uid'].'][version][stageId]=-1'
-                                               )).'">'.
+                               '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
                                '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/down.gif','width="14" height="14"').' alt="" align="top" title="Reject" />'.
                                '</a>';
                } else {
@@ -731,16 +751,22 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
 
                        // Raise
                if ($raiseOk)   {
-                       if ($rec_off['t3ver_stage']!=10)        {
-                               $actionLinks.=
-                                       '<a href="'.htmlspecialchars($this->doc->issueCommand(
+                       $onClick = 'var commentTxt=window.prompt("'.$label.'","");
+                                                       if (commentTxt!=null) {document.location="'.$this->doc->issueCommand(
                                                        '&cmd['.$table.']['.$rec_off['uid'].'][version][action]=setStage'.
                                                        '&cmd['.$table.']['.$rec_off['uid'].'][version][stageId]='.$sId
-                                                       )).'">'.
-                                       '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/up.gif','width="14" height="14"').' alt="" align="top" title="Raise" />'.
+                                                       ).'&cmd['.$table.']['.$rec_off['uid'].'][version][comment]="+escape(commentTxt);}'.
+                                                       ' return false;';
+                       if ($rec_off['t3ver_stage']!=10)        {
+                               $actionLinks.=
+                                       '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
+                                       '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/up.gif','width="14" height="14"').' alt="" align="top" title="'.htmlspecialchars($titleAttrib).'" />'.
                                        '</a>';
+
+                               $this->stageIndex[$sId][$table][] = $rec_off['uid'];
                        }
                }
+
                return $actionLinks;
        }
 
@@ -754,7 +780,7 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
         * @return      string          HTML content, mainly link tags and images.
         */
        function displayWorkspaceOverview_commandLinks($table,&$rec_on,&$rec_off,$vType)        {
-               if ($this->publishAccess)       {
+               if ($this->publishAccess && (!($GLOBALS['BE_USER']->workspaceRec['publish_access']&1) || (int)$rec_off['t3ver_stage']===10))    {
                        $actionLinks =
                                '<a href="'.htmlspecialchars($this->doc->issueCommand(
                                                '&cmd['.$table.']['.$rec_on['uid'].'][version][action]=swap'.
@@ -762,7 +788,7 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                                                )).'">'.
                                '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert1.gif','width="14" height="14"').' alt="" align="top" title="Publish" />'.
                                '</a>';
-                       if ($GLOBALS['BE_USER']->workspaceSwapAccess()) {
+                       if ($GLOBALS['BE_USER']->workspaceSwapAccess() && (int)$rec_on['t3ver_state']!==1 && (int)$rec_off['t3ver_state']!==2)  {
                                $actionLinks.=
                                        '<a href="'.htmlspecialchars($this->doc->issueCommand(
                                                        '&cmd['.$table.']['.$rec_on['uid'].'][version][action]=swap'.
@@ -819,6 +845,8 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
         * Links to publishing etc of a version
         *
         * @param       string          Table name
+        * @param       array           Record
+        * @param       integer         The uid of the online version of $uid. If zero it means we are drawing a row for the online version itself while a value means we are drawing display for an offline version.
         * @return      string          HTML content, mainly link tags and images.
         */
        function displayWorkspaceOverview_commandLinksSub($table,$rec,$origId)  {
@@ -907,7 +935,8 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                        return '<br/>
                                        <img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/joinbottom.gif','width="18" height="16"').' align="top" alt="" title="" />'.
                                        ($origId ?
-                                               '<a href="index.php?details='.$uid.'"><span class="typo3-dimmed"><em>[Sub elements, click for details]</em><span></a>' :
+                                               '<a href="'.htmlspecialchars($this->doc->backPath.t3lib_extMgm::extRelPath('version').'cm1/index.php?id='.$uid.'&details='.rawurlencode('pages:'.$uid).'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
+                                               '<span class="typo3-dimmed"><em>[Sub elements, click for details]</em><span></a>' :
                                                '<span class="typo3-dimmed"><em>[Sub elements]</em><span>');
                } else {        // For an offline workspace, show sub elements:
 
@@ -1088,7 +1117,7 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                                                                        t3lib_iconWorks::getIconImage($tN, $rec, $this->doc->backPath,'') : '').
                                                                t3lib_BEfunc::getRecordTitle($tN, $rec, TRUE).
                                                        '</td>
-                                                       <td>'.
+                                                       <td class="cmdCell">'.
                                                                $this->displayWorkspaceOverview_commandLinksSub($tN,$rec,$origId).
                                                        '</td>'.($origId ? '<td class="diffCell">'.
                                                                $diffCode.
@@ -1319,7 +1348,7 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                if (!isset($this->formatWorkspace_cache[$wsid]))        {
                        switch($wsid)   {
                                case -1:
-                                       $this->formatWorkspace_cache[$wsid] = '[Offline]';
+                                       $this->formatWorkspace_cache[$wsid] = '[Draft]';
                                break;
                                case 0:
                                        $this->formatWorkspace_cache[$wsid] = '';       // Does not output anything for ONLINE because it might confuse people to think that the elemnet IS online which is not the case - only that it exists as an offline version in the online workspace...
@@ -1362,6 +1391,10 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
 
        /**
         * Looking for versions of a record in other workspaces than the current
+        *
+        * @param       string          Table name
+        * @param       integer         Record uid
+        * @return      string          List of other workspace IDs
         */
        function versionsInOtherWS($table,$uid) {
 
@@ -1385,6 +1418,54 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                }
        }
 
+       /**
+        * Looks up stage changes for version and displays a formatted view on mouseover.
+        *
+        * @param       string          Table name
+        * @param       integer         Record ID
+        * @param       string          HTML string to wrap the mouseover around (should be stage change links)
+        * @return      string          HTML code.
+        */
+       function showStageChangeLog($table,$id,$stageCommands)  {
+               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                       'log_data,tstamp,userid',
+                       'sys_log',
+                       'action=6 and details_nr=30
+                               AND tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_log').'
+                               AND recuid='.intval($id)
+               );
+
+               $entry = array();
+               foreach($rows as $dat)  {
+                       $data = unserialize($dat['log_data']);
+                       $username = $this->be_user_Array[$dat['userid']] ? $this->be_user_Array[$dat['userid']]['username'] : '['.$dat['userid'].']';
+
+                       switch($data['stage'])  {
+                               case 1:
+                                       $text = 'sent element to "Review"';
+                               break;
+                               case 10:
+                                       $text = 'approved for "Publish"';
+                               break;
+                               case -1:
+                                       $text = 'rejected element!';
+                               break;
+                               case 0:
+                                       $text = 'reset to "Editing"';
+                               break;
+                               default:
+                                       $text = '[undefined]';
+                               break;
+                       }
+                       $text = t3lib_BEfunc::dateTime($dat['tstamp']).': "'.$username.'" '.$text;
+                       $text.= ($data['comment']?'<br/>User Comment: <em>'.$data['comment'].'</em>':'');
+
+                       $entry[] = $text;
+               }
+
+               return count($entry) ? '<span onmouseover="document.getElementById(\'log_'.$table.$id.'\').style.visibility = \'visible\';" onmouseout="document.getElementById(\'log_'.$table.$id.'\').style.visibility = \'hidden\';">'.$stageCommands.' ('.count($entry).')</span>'.
+                               '<div class="logLayer" style="visibility: hidden; position: absolute;" id="log_'.$table.$id.'">'.implode('<hr/>',$entry).'</div>' : $stageCommands;
+       }