Fixed issue #13670: Performance optimization: change while(list() to foreach() (thank...
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_sortpages / class.tx_wizardsortpages_webfunc_2.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Contains class for "Sort pages" wizard
29 *
30 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
31 * XHTML compliant
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 67: class tx_wizardsortpages_webfunc_2 extends t3lib_extobjbase
41 * 75: function modMenu()
42 * 88: function main()
43 * 175: function wiz_linkOrder($title,$order)
44 *
45 * TOTAL FUNCTIONS: 3
46 * (This index is automatically created/updated by the extension "extdeveval")
47 *
48 */
49 /**
50 * Creates the "Sort pages" wizard
51 *
52 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
53 * @package TYPO3
54 * @subpackage tx_wizardsortpages
55 */
56 class tx_wizardsortpages_webfunc_2 extends t3lib_extobjbase {
57
58 /**
59 * 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...
60 *
61 * @return array
62 * @ignore
63 */
64 function modMenu() {
65 global $LANG;
66
67 $modMenuAdd = array(
68 );
69 return $modMenuAdd;
70 }
71
72 /**
73 * Main function creating the content for the module.
74 *
75 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
76 */
77 function main() {
78 global $SOBE,$LANG;
79
80 if ($GLOBALS['BE_USER']->workspace===0) {
81
82 $theCode='';
83
84 // check if user has modify permissions to
85 $sys_pages = t3lib_div::makeInstance('t3lib_pageSelect');
86 $sortByField = t3lib_div::_GP('sortByField');
87 if ($sortByField) {
88 $menuItems=array();
89 if (t3lib_div::inList('title,subtitle,crdate,tstamp',$sortByField)) {
90 $menuItems = $sys_pages->getMenu($this->pObj->id,'uid,pid,title',$sortByField,'',0);
91 } elseif ($sortByField=='REV') {
92 $menuItems = $sys_pages->getMenu($this->pObj->id,'uid,pid,title','sorting','',0);
93 $menuItems = array_reverse($menuItems);
94 }
95 if (count($menuItems)) {
96 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
97 $tce->stripslashes_values=0;
98 $menuItems = array_reverse($menuItems);
99 $cmd=array();
100 foreach ($menuItems as $r) {
101 $cmd['pages'][$r['uid']]['move']=$this->pObj->id;
102 }
103 $tce->start(array(),$cmd);
104 $tce->process_cmdmap();
105 t3lib_BEfunc::setUpdateSignal('updatePageTree');
106 }
107 }
108
109 //
110 $menuItems = $sys_pages->getMenu($this->pObj->id,'*','sorting','',0);
111 $lines=array();
112 $lines[]= '<tr>
113 <td class="bgColor5"><b>'.$this->wiz_linkOrder($LANG->getLL('wiz_changeOrder_title'),'title').'</b></td>
114 '.(t3lib_extMgm::isLoaded('cms')?'<td class="bgColor5"><b>'.$this->wiz_linkOrder($LANG->getLL('wiz_changeOrder_subtitle'),'subtitle').'</b></td>':'').'
115 <td class="bgColor5"><b>'.$this->wiz_linkOrder($LANG->getLL('wiz_changeOrder_tChange'),'tstamp').'</b></td>
116 <td class="bgColor5"><b>'.$this->wiz_linkOrder($LANG->getLL('wiz_changeOrder_tCreate'),'crdate').'</b></td>
117 </tr>';
118 foreach ($menuItems as $rec) {
119 $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(2); // edit permissions for that page!
120 $pRec = t3lib_BEfunc::getRecord ('pages',$rec['uid'],'uid',' AND '.$m_perms_clause);
121 $lines[]= '<tr><td nowrap="nowrap">'.t3lib_iconWorks::getIconImage('pages',$rec,$GLOBALS['BACK_PATH'],'align="top" '.t3lib_BEfunc::titleAttribForPages($rec)).
122 (!is_array($pRec)?$GLOBALS['TBE_TEMPLATE']->rfw('<b>'.$LANG->getLL('wiz_W',1).'</b> '):'').
123 htmlspecialchars(t3lib_div::fixed_lgd_cs($rec['title'],$GLOBALS['BE_USER']->uc['titleLen'])).'&nbsp;</td>
124 '.(t3lib_extMgm::isLoaded('cms')?'<td nowrap="nowrap">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($rec['subtitle'],$GLOBALS['BE_USER']->uc['titleLen'])).'&nbsp;</td>':'').'
125 <td nowrap="nowrap">'.t3lib_Befunc::datetime($rec['tstamp']).'&nbsp;&nbsp;</td>
126 <td nowrap="nowrap">'.t3lib_Befunc::datetime($rec['crdate']).'&nbsp;&nbsp;</td>
127 </tr>';
128 }
129
130 $theCode.= '<b>'.$LANG->getLL('wiz_currentPageOrder',1).':</b><br /><br />
131 <table border="0" cellpadding="0" cellspacing="0">'.implode('',$lines).'</table><br />';
132
133 if (count($menuItems)) {
134 // Menu:
135 $lines=array();
136 $lines[] = $this->wiz_linkOrder($LANG->getLL('wiz_changeOrder_title'),'title');
137 if (t3lib_extMgm::isLoaded('cms')) $lines[] = $this->wiz_linkOrder($LANG->getLL('wiz_changeOrder_subtitle'),'subtitle');
138 $lines[] = $this->wiz_linkOrder($LANG->getLL('wiz_changeOrder_tChange'),'tstamp');
139 $lines[] = $this->wiz_linkOrder($LANG->getLL('wiz_changeOrder_tCreate'),'crdate');
140 $lines[] = '';
141 $lines[] = $this->wiz_linkOrder($LANG->getLL('wiz_changeOrder_REVERSE'),'REV');
142 $theCode.= '<b>'.$LANG->getLL('wiz_changeOrder').':</b><br /><br />'.implode('<br />',$lines);
143 }
144
145 // CSH:
146 $theCode.= t3lib_BEfunc::cshItem('_MOD_web_func', 'tx_wizardsortpages', $GLOBALS['BACK_PATH'], '<br />|');
147
148 $out=$this->pObj->doc->section($LANG->getLL('wiz_sort'),$theCode,0,1);
149 } else {
150 $out=$this->pObj->doc->section($LANG->getLL('wiz_sort'),'Sorry, this function is not available in the current draft workspace!',0,1,1);
151 }
152 return $out;
153 }
154
155 /**
156 * Creates a link for the sorting order
157 *
158 * @param string Title of the link
159 * @param string Field to sort by
160 * @return string HTML string
161 */
162 function wiz_linkOrder($title,$order) {
163 return '&nbsp; &nbsp;<a 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>';
164 }
165 }
166
167 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/wizard_sortpages/class.tx_wizardsortpages_webfunc_2.php']) {
168 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/wizard_sortpages/class.tx_wizardsortpages_webfunc_2.php']);
169 }
170 ?>