[!!!][CLEANUP] Move t3-table and t3-button to bootstrap
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_sortpages / Classes / View / SortPagesWizardModuleFunction.php
1 <?php
2 namespace TYPO3\CMS\WizardSortpages\View;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Creates the "Sort pages" wizard
22 *
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
24 */
25 class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
26
27 /**
28 * Main function creating the content for the module.
29 *
30 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
31 */
32 public function main() {
33 $GLOBALS['LANG']->includeLLFile('EXT:wizard_sortpages/locallang.xlf');
34 $out = $this->pObj->doc->header($GLOBALS['LANG']->getLL('wiz_sort'));
35 if ($GLOBALS['BE_USER']->workspace === 0) {
36 $theCode = '';
37 // Check if user has modify permissions to
38 $sys_pages = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
39 $sortByField = GeneralUtility::_GP('sortByField');
40 if ($sortByField) {
41 $menuItems = array();
42 if (GeneralUtility::inList('title,subtitle,crdate,tstamp', $sortByField)) {
43 $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', $sortByField, '', FALSE);
44 } elseif ($sortByField === 'REV') {
45 $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', 'sorting', '', FALSE);
46 $menuItems = array_reverse($menuItems);
47 }
48 if (!empty($menuItems)) {
49 $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
50 $tce->stripslashes_values = 0;
51 $menuItems = array_reverse($menuItems);
52 $cmd = array();
53 foreach ($menuItems as $r) {
54 $cmd['pages'][$r['uid']]['move'] = $this->pObj->id;
55 }
56 $tce->start(array(), $cmd);
57 $tce->process_cmdmap();
58 BackendUtility::setUpdateSignal('updatePageTree');
59 }
60 }
61 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', FALSE);
62
63 if (!empty($menuItems)) {
64 $lines = array();
65 $lines[] = '<thead><tr>';
66 $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_title'), 'title') . '</th>';
67 $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_subtitle'), 'subtitle') . '</th>';
68 $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tChange'), 'tstamp') . '</th>';
69 $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tCreate'), 'crdate') . '</th>';
70 $lines[] = '</tr></thead>';
71
72 foreach ($menuItems as $rec) {
73 $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(2);
74 // edit permissions for that page!
75 $pRec = BackendUtility::getRecord('pages', $rec['uid'], 'uid', ' AND ' . $m_perms_clause);
76 $lines[] = '<tr><td nowrap="nowrap">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $rec) . (!is_array($pRec) ? '<strong class="text-danger">' . $GLOBALS['LANG']->getLL('wiz_W', TRUE) . '</strong></span> ' : '') . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
77 <td nowrap="nowrap">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['subtitle'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
78 <td nowrap="nowrap">' . BackendUtility::datetime($rec['tstamp']) . '</td>
79 <td nowrap="nowrap">' . BackendUtility::datetime($rec['crdate']) . '</td>
80 </tr>';
81 }
82 $theCode .= '<h2>' . $GLOBALS['LANG']->getLL('wiz_currentPageOrder', TRUE) . '</h2>';
83 $theCode .= '<div class="table-fit"><table class="table table-striped table-hover">' . implode('', $lines) . '</table></div>';
84
85 // Menu:
86 $lines = array();
87 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_title'), 'title');
88 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_subtitle'), 'subtitle');
89 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tChange'), 'tstamp');
90 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tCreate'), 'crdate');
91 $lines[] = '';
92 $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_REVERSE'), 'REV');
93 $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_changeOrder') . '</h4>' . implode('<br />', $lines);
94 } else {
95 $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, $GLOBALS['LANG']->getLL('no_subpages'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE);
96 $theCode .= $flashMessage->render();
97 }
98 // CSH:
99 $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardsortpages', NULL, '<br />|');
100 $out .= $this->pObj->doc->section('', $theCode, FALSE, TRUE);
101 } else {
102 $out .= $this->pObj->doc->section('', 'Sorry, this function is not available in the current draft workspace!', FALSE, TRUE, 1);
103 }
104 return $out;
105 }
106
107 /**
108 * Creates a link for the sorting order
109 *
110 * @param string $title Title of the link
111 * @param string $order Field to sort by
112 * @return string HTML string
113 */
114 protected function wiz_linkOrder($title, $order) {
115 return '<a class="t3-link" href="' . htmlspecialchars(
116 BackendUtility::getModuleUrl('web_func',
117 array(
118 'id' => $GLOBALS['SOBE']->id,
119 'sortByField' => $order
120 )
121 )
122 ) . '" onclick="return confirm(' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->getLL('wiz_changeOrder_msg1')) . ')">' . htmlspecialchars($title) . '</a>';
123 }
124
125 }