* Added Karsten D.s patches for DBAL.
[Packages/TYPO3.CMS.git] / typo3 / wizard_rte.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 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 * Wizard to display the RTE in "full screen" mode
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 81: class SC_wizard_rte
42 * 99: function init()
43 * 123: function main()
44 * 279: function printContent()
45 * 290: function checkEditAccess($table,$uid)
46 *
47 * TOTAL FUNCTIONS: 4
48 * (This index is automatically created/updated by the extension "extdeveval")
49 *
50 */
51
52
53
54 $BACK_PATH='';
55 require ('init.php');
56 require ('template.php');
57 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
58 require_once (PATH_t3lib.'class.t3lib_tceforms.php');
59 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
60 require_once (PATH_t3lib.'class.t3lib_transferdata.php');
61
62 t3lib_BEfunc::lockRecords();
63
64
65
66
67
68
69
70
71
72
73
74 /**
75 * Script Class for rendering the full screen RTE display
76 *
77 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
78 * @package TYPO3
79 * @subpackage core
80 */
81 class SC_wizard_rte {
82
83 // Internal, dynamic:
84 var $doc; // Document template object
85 var $content; // Content accumulation for the module.
86
87 // Internal, static: GPvars
88 var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
89 var $popView; // If set, launch a new window with the current records pid.
90
91
92
93
94 /**
95 * Initialization of the class
96 *
97 * @return void
98 */
99 function init() {
100 global $BACK_PATH;
101
102 // Setting GPvars:
103 $this->P = t3lib_div::_GP('P');
104 $this->popView = t3lib_div::_GP('popView');
105
106 // "Module name":
107 $this->MCONF['name']='xMOD_wizard_rte.php';
108
109 // Starting the document template object:
110 $this->doc = t3lib_div::makeInstance('mediumDoc');
111 $this->doc->docType = 'xhtml_trans';
112 $this->doc->divClass = ''; // Need to NOT have the page wrapped in DIV since if we do that we destroy the feature that the RTE spans the whole height of the page!!!
113 $this->doc->form='<form action="tce_db.php" method="post" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'" name="editform" onsubmit="return TBE_EDITOR_checkSubmit(1);">';
114 $this->doc->backPath = $BACK_PATH;
115
116 }
117
118 /**
119 * Main function, rendering the document with the iframe with the RTE in.
120 *
121 * @return void
122 */
123 function main() {
124 global $BE_USER,$LANG;
125
126 // If all parameters are available:
127 if ($this->P['table'] && $this->P['field'] && $this->P['uid'] && $this->checkEditAccess($this->P['table'],$this->P['uid'])) {
128
129 // Getting the raw record (we need only the pid-value from here...)
130 $rawRec = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
131
132 // Setting JavaScript, including the pid value for viewing:
133 $this->doc->JScode = $this->doc->wrapScriptTags('
134 function jumpToUrl(URL,formEl) { //
135 if (document.editform) {
136 if (!TBE_EDITOR_isFormChanged()) {
137 document.location = URL;
138 } else if (formEl) {
139 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
140 }
141 } else document.location = URL;
142 }
143 '.($this->popView ? t3lib_BEfunc::viewOnClick($rawRec['pid'],'',t3lib_BEfunc::BEgetRootLine($rawRec['pid'])) : '').'
144 ');
145
146 // Create page HTML header:
147 $this->content.=$this->doc->startPage('');
148
149
150 // Initialize TCeforms - for rendering the field:
151 $tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
152 $tceforms->initDefaultBEMode(); // Init...
153 $tceforms->disableWizards = 1; // SPECIAL: Disables all wizards - we are NOT going to need them.
154 $tceforms->colorScheme[0]=$this->doc->bgColor; // SPECIAL: Setting background color of the RTE to ordinary background
155
156 // Initialize style for RTE object:
157 $RTEobj = &t3lib_BEfunc::RTEgetObj(); // Getting reference to the RTE object used to render the field!
158 if ($RTEobj->ID == 'rte') {
159 $RTEobj->RTEdivStyle = 'position:relative; left:0px; top:0px; height:100%; width:100%; border:solid 0px;'; // SPECIAL: Setting style for the RTE <DIV> layer containing the IFRAME
160 # $RTEobj->RTEdivStyle = 'position:relative; left:0px; top:0px; height:600px; width:100%; border:solid 0px;'; // SPECIAL: Setting style for the RTE <DIV> layer containing the IFRAME
161 }
162
163 // Fetching content of record:
164 $trData = t3lib_div::makeInstance('t3lib_transferData');
165 $trData->lockRecords=1;
166 $trData->fetchRecord($this->P['table'],$this->P['uid'],'');
167
168 // Getting the processed record content out:
169 reset($trData->regTableItems_data);
170 $rec = current($trData->regTableItems_data);
171 $rec['uid'] = $this->P['uid'];
172 $rec['pid'] = $rawRec['pid'];
173
174 // Making the toolbar:
175 $closeUrl = $this->P['returnUrl'];
176 $R_URI=t3lib_div::linkThisScript(array('popView'=>''));
177
178 // Getting settings for the undo button:
179 $undoButton = 0;
180 $undoRes = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp', 'sys_history', 'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->P['table'], 'sys_history').' AND recuid='.intval($this->P['uid']), '', 'tstamp DESC', '1');
181 if ($undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes)) {
182 $undoButton = 1;
183 }
184
185 // ShortCut
186 if ($BE_USER->mayMakeShortcut()) {
187 $sCut = $this->doc->makeShortcutIcon('P','',$this->MCONF['name'],1);
188 } else {
189 $sCut ='';
190 }
191
192
193 // Make Toolbar of buttons:
194 $toolBarButtons=array();
195
196 // Save:
197 $toolBarButtons[]=
198 '<a href="#" onclick="TBE_EDITOR_checkAndDoSubmit(1); return false;">'.
199 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc',1).'" alt="" />'.
200 '</a>';
201
202 // Save/View:
203 if (t3lib_extMgm::isLoaded('cms')) {
204 $toolBarButtons[]=
205 '<a href="#" onclick="'.htmlspecialchars('document.editform.redirect.value+=\'&popView=1\'; TBE_EDITOR_checkAndDoSubmit(1); return false;').'">'.
206 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedokshow.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDocShow',1).'" alt="" />'.
207 '</a>';
208 }
209 // Close:
210 $toolBarButtons[]=
211 '<a href="#" onclick="'.htmlspecialchars('jumpToUrl(unescape(\''.rawurlencode($closeUrl).'\')); return false;').'">'.
212 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/closedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'" alt="" />'.
213 '</a>';
214
215 // Undo/Revert:
216 if ($undoButton) {
217 $toolBarButtons[]=
218 '<a href="#" onclick="'.htmlspecialchars('document.location=\'show_rechis.php?element='.rawurlencode($this->P['table'].':'.$this->P['uid']).'&revert='.rawurlencode('field:'.$this->P['field']).'&sumUp=-1&returnUrl='.rawurlencode($R_URI).'\'; return false;').'">'.
219 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/undo.gif','width="21" height="16"').' class="c-inputButton" title="'.htmlspecialchars(sprintf($LANG->getLL('rte_undoLastChange'),t3lib_BEfunc::calcAge(time()-$undoButtonR['tstamp'],$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')))).'" alt="" />'.
220 '</a>';
221 }
222
223 $panel = '<span class="c-saveButtons">'.implode('',$toolBarButtons).'</span>';
224
225
226 // TSconfig, setting width:
227 $fieldTSConfig = $tceforms->setTSconfig($this->P['table'],$rec,$this->P['field']);
228 if (strcmp($fieldTSConfig['RTEfullScreenWidth'],'')) {
229 $width=$fieldTSConfig['RTEfullScreenWidth'];
230 } else {
231 $width='500';
232 }
233
234 // Get the form field and wrap it in the table with the buttons:
235 $formContent = $tceforms->getSoloField($this->P['table'],$rec,$this->P['field']);
236 $formContent = '
237
238
239 <!--
240 RTE wizard:
241 -->
242 <table border="0" cellpadding="0" cellspacing="0" width="'.$width.'" id="typo3-rtewizard">
243 <tr>
244 <td>'.$panel.'</td>
245 <td align="right">'.$sCut.'</td>
246 <td></td>
247 </tr>
248 <tr>
249 <td width="'.$width.'" colspan="2" id="c-formContent">'.$formContent.'</td>
250 <td></td>
251 </tr>
252 </table>';
253
254 // Adding hidden fields:
255 $formContent.= '<input type="hidden" name="redirect" value="'.htmlspecialchars($R_URI).'" />
256 <input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />';
257
258
259 // Finally, add the whole setup:
260 $this->content.=
261 $tceforms->printNeededJSFunctions_top().
262 $formContent.
263 $tceforms->printNeededJSFunctions();
264 } else {
265 // ERROR:
266 $this->content.=$this->doc->startPage('');
267 $this->content.=$this->doc->section($LANG->getLL('forms_title'),'<span class="typo3-red">'.$LANG->getLL('table_noData',1).'</span>',0,1);
268 }
269
270 // Ending page:
271 $this->content.=$this->doc->endPage();
272 }
273
274 /**
275 * Outputting the accumulated content to screen
276 *
277 * @return void
278 */
279 function printContent() {
280 echo $this->content;
281 }
282
283 /**
284 * Checks access for element
285 *
286 * @param string Table name
287 * @param integer Record uid
288 * @return void
289 */
290 function checkEditAccess($table,$uid) {
291 global $BE_USER;
292
293 $calcPRec = t3lib_BEfunc::getRecord($table,$uid);
294 t3lib_BEfunc::fixVersioningPid($table,$uid);
295 if (is_array($calcPRec)) {
296 if ($table=='pages') { // If pages:
297 $CALC_PERMS = $BE_USER->calcPerms($calcPRec);
298 $hasAccess = $CALC_PERMS&2 ? TRUE : FALSE;
299 } else {
300 $CALC_PERMS = $BE_USER->calcPerms(t3lib_BEfunc::getRecord('pages',$calcPRec['pid'])); // Fetching pid-record first.
301 $hasAccess = $CALC_PERMS&16 ? TRUE : FALSE;
302 }
303
304 // Check internals regarding access:
305 if ($hasAccess) {
306 $hasAccess = $BE_USER->recordEditAccessInternals($table, $calcPRec);
307 }
308 } else $hasAccess = FALSE;
309
310 return $hasAccess;
311 }
312 }
313
314 // Include extension?
315 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_rte.php']) {
316 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_rte.php']);
317 }
318
319
320
321
322
323
324
325
326
327
328
329
330 // Make instance:
331 $SOBE = t3lib_div::makeInstance('SC_wizard_rte');
332 $SOBE->init();
333 $SOBE->main();
334 $SOBE->printContent();
335 ?>