[TASK] Add missing CSS class to table of sorting module
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_sortpages / Classes / View / SortPagesWizardModuleFunction.php
1 <?php
2 namespace TYPO3\CMS\WizardSortpages\View;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31
32 /**
33 * Creates the "Sort pages" wizard
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37 class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
38
39 /**
40 * Adds menu items... but I think this is not used at all. Looks very much like some testing code. If anyone cares to check it we can remove it some day...
41 *
42 * @return array
43 * @ignore
44 * @todo Define visibility
45 */
46 public function modMenu() {
47 global $LANG;
48 $modMenuAdd = array();
49 return $modMenuAdd;
50 }
51
52 /**
53 * Main function creating the content for the module.
54 *
55 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
56 * @todo Define visibility
57 */
58 public function main() {
59 $GLOBALS['LANG']->includeLLFile('EXT:wizard_sortpages/locallang.xlf');
60 $out = $this->pObj->doc->header($GLOBALS['LANG']->getLL('wiz_sort'));
61 if ($GLOBALS['BE_USER']->workspace === 0) {
62 $theCode = '';
63 // Check if user has modify permissions to
64 $sys_pages = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
65 $sortByField = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('sortByField');
66 if ($sortByField) {
67 $menuItems = array();
68 if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('title,subtitle,crdate,tstamp', $sortByField)) {
69 $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', $sortByField, '', FALSE);
70 } elseif ($sortByField == 'REV') {
71 $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', 'sorting', '', FALSE);
72 $menuItems = array_reverse($menuItems);
73 }
74 if (count($menuItems)) {
75 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
76 $tce->stripslashes_values = 0;
77 $menuItems = array_reverse($menuItems);
78 $cmd = array();
79 foreach ($menuItems as $r) {
80 $cmd['pages'][$r['uid']]['move'] = $this->pObj->id;
81 }
82 $tce->start(array(), $cmd);
83 $tce->process_cmdmap();
84 BackendUtility::setUpdateSignal('updatePageTree');
85 }
86 }
87 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', FALSE);
88
89 if (count($menuItems)) {
90 $lines = array();
91 $lines[] = '<tr class="t3-row-header">
92 <td>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_title'), 'title') . '</td>
93 ' . (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms') ? '<td> ' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_subtitle'), 'subtitle') . '</td>' : '') . '
94 <td>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tChange'), 'tstamp') . '</td>
95 <td>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tCreate'), 'crdate') . '</td>
96 </tr>';
97 foreach ($menuItems as $rec) {
98 $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(2);
99 // edit permissions for that page!
100 $pRec = BackendUtility::getRecord('pages', $rec['uid'], 'uid', ' AND ' . $m_perms_clause);
101 $lines[] = '<tr class="db_list_normal"><td nowrap="nowrap">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $rec) . (!is_array($pRec) ? $GLOBALS['TBE_TEMPLATE']->rfw('<strong>' . $GLOBALS['LANG']->getLL('wiz_W', TRUE) . '</strong> ') : '') . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '&nbsp;</td>
102 ' . (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms') ? '<td nowrap="nowrap">' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($rec['subtitle'], $GLOBALS['BE_USER']->uc['titleLen'])) . '&nbsp;</td>' : '') . '
103 <td nowrap="nowrap">' . BackendUtility::datetime($rec['tstamp']) . '&nbsp;&nbsp;</td>
104 <td nowrap="nowrap">' . BackendUtility::datetime($rec['crdate']) . '&nbsp;&nbsp;</td>
105 </tr>';
106 }
107 $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_currentPageOrder', TRUE) . '</h4>
108 <table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">' . implode('', $lines) . '</table><br />';
109 // Menu:
110 $lines = array();
111 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_title'), 'title');
112 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms')) {
113 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_subtitle'), 'subtitle');
114 }
115 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tChange'), 'tstamp');
116 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tCreate'), 'crdate');
117 $lines[] = '';
118 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_REVERSE'), 'REV');
119 $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_changeOrder') . '</h4>' . implode('<br />', $lines);
120 } else {
121 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('no_subpages'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE);
122 $theCode .= $flashMessage->render();
123 }
124 // CSH:
125 $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardsortpages', $GLOBALS['BACK_PATH'], '<br />|');
126 $out .= $this->pObj->doc->section('', $theCode, 0, 1);
127 } else {
128 $out .= $this->pObj->doc->section('', 'Sorry, this function is not available in the current draft workspace!', 0, 1, 1);
129 }
130 return $out;
131 }
132
133 /**
134 * Creates a link for the sorting order
135 *
136 * @param string $title Title of the link
137 * @param string $order Field to sort by
138 * @return string HTML string
139 * @todo Define visibility
140 */
141 public function wiz_linkOrder($title, $order) {
142 return '&nbsp; &nbsp;<a class="t3-link" href="' . htmlspecialchars(('index.php?id=' . $GLOBALS['SOBE']->id . '&sortByField=' . $order)) . '" onclick="return confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->getLL('wiz_changeOrder_msg1')) . ')">' . htmlspecialchars($title) . '</a>';
143 }
144
145 }