*** empty log message ***
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / web_info / class.tx_cms_webinfo_lang.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@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 a class with functions for page related overview of translations.
29 *
30 * $Id$
31 *
32 * @author Kasper Skaarhoj <kasper@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 66: class tx_cms_webinfo_page extends t3lib_extobjbase
40 * 73: function modMenu()
41 * 100: function main()
42 *
43 *
44 * 191: class tx_cms_webinfo_hits extends tx_cms_webinfo_page
45 *
46 * TOTAL FUNCTIONS: 2
47 * (This index is automatically created/updated by the extension "extdeveval")
48 *
49 */
50
51 require_once(PATH_t3lib.'class.t3lib_pagetree.php');
52 require_once(PATH_t3lib.'class.t3lib_extobjbase.php');
53
54
55
56
57 /**
58 * Class for displaying translation status of pages in the tree.
59 *
60 * @author Kasper Skaarhoj <kasper@typo3.com>
61 * @package TYPO3
62 * @subpackage tx_cms
63 */
64 class tx_cms_webinfo_lang extends t3lib_extobjbase {
65
66 /**
67 * Returns the menu array
68 *
69 * @return array
70 */
71 function modMenu() {
72 global $LANG;
73
74 return array (
75 'depth' => array(
76 0 => $LANG->getLL('depth_0'),
77 1 => $LANG->getLL('depth_1'),
78 2 => $LANG->getLL('depth_2'),
79 3 => $LANG->getLL('depth_3')
80 )
81 );
82 }
83
84 /**
85 * MAIN function for page information display (including hit statistics)
86 *
87 * @return string Output HTML f or the module.
88 */
89 function main() {
90 global $BACK_PATH,$LANG,$SOBE;
91
92 if ($this->pObj->id) {
93 $theOutput = '';
94
95 // Depth selector:
96 $h_func = t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[depth]',$this->pObj->MOD_SETTINGS['depth'],$this->pObj->MOD_MENU['depth'],'index.php');
97 $theOutput.= $h_func;
98
99 // Showing the tree:
100 // Initialize starting point of page tree:
101 $treeStartingPoint = intval($this->pObj->id);
102 $treeStartingRecord = t3lib_BEfunc::getRecord('pages', $treeStartingPoint);
103 $depth = $this->pObj->MOD_SETTINGS['depth'];
104
105 // Initialize tree object:
106 $tree = t3lib_div::makeInstance('t3lib_pageTree');
107 $tree->init('AND '.$GLOBALS['BE_USER']->getPagePermsClause(1));
108 $tree->addField('l18n_cfg');
109
110 // Creating top icon; the current page
111 $HTML = t3lib_iconWorks::getIconImage('pages', $treeStartingRecord, $GLOBALS['BACK_PATH'],'align="top"');
112 $tree->tree[] = array(
113 'row' => $treeStartingRecord,
114 'HTML'=>$HTML
115 );
116
117 // Create the tree from starting point:
118 $tree->getTree($treeStartingPoint, $depth, '');
119 #debug($tree->tree);
120
121 // Add CSS needed:
122 $css_content = '
123 TABLE#langTable TR TD {
124 padding-left : 2px;
125 padding-right : 2px;
126 white-space: nowrap;
127 }
128 TD.c-blocked { background-color: red; }
129 TD.c-ok { background-color: #669966; }
130 TD.c-fallback { }
131 TD.c-leftLine {border-left: 2px solid black; }
132 .bgColor5 { font-weight: bold; }
133 ';
134 $marker = '/*###POSTCSSMARKER###*/';
135 $this->pObj->content = str_replace($marker,$css_content.chr(10).$marker,$this->pObj->content);
136
137
138 // Render information table:
139 $theOutput = $this->renderL10nTable($tree);
140 }
141
142 return $theOutput;
143 }
144
145 function renderL10nTable(&$tree) {
146
147 // System languages retrieved:
148 $languages = $this->getSystemLanguages();
149
150 // Title length:
151 $titleLen = $GLOBALS['BE_USER']->uc['titleLen'];
152
153 // Put together the TREE:
154 $output = '';
155 $newOL_js = array();
156 foreach($tree->tree as $data) {
157 $tCells = array();
158
159 // Page icons / titles etc.
160 $tCells[] = '<td>'.$data['HTML'].htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['title'],$titleLen)).'</td>';
161
162 // DEFAULT language:
163 // "View page" link is created:
164 $viewPageLink= '<a href="#" onclick="'.
165 htmlspecialchars(t3lib_BEfunc::viewOnClick($data['row']['uid'],$GLOBALS['BACK_PATH'],'','','','&L=###LANG_UID###')).'">'.
166 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/zoom.gif','width="12" height="12"').' title="View page" border="0" alt="" />'.
167 '</a>';
168 $status = $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-ok';
169
170 // Create links:
171 $info = '';
172 $editUid = $data['row']['uid'];
173 $params = '&edit[pages]['.$editUid.']=edit';
174 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
175 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="Edit default language page header" border="0" alt="" />'.
176 '</a>';
177 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]=0"); return false;').'">'.
178 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit_page.gif','width="12" height="12"').' title="Edit page" border="0" alt="" />'.
179 '</a>';
180 $info.=str_replace('###LANG_UID###','0',$viewPageLink);
181
182 // Put into cell:
183 $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
184
185 foreach($languages as $langRow) {
186 $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
187 $info = '';
188
189 if (is_array($row)) {
190 $status = $row['hidden'] ? 'c-fallback' : 'c-ok';
191 $icon = t3lib_iconWorks::getIconImage(
192 'pages_language_overlay',
193 $row,
194 $GLOBALS['BACK_PATH'],
195 'align="top" class="c-recIcon"'
196 );
197
198 $info = $icon.htmlspecialchars($row['title']).
199 ($row['_COUNT']>1 ? '<div>BAD THING, there are TWO or more records for this language!!!</div>':'');
200 $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
201
202 // Edit whole record:
203 $info = '';
204 $editUid = $row['uid'];
205 $params = '&edit[pages_language_overlay]['.$editUid.']=edit';
206 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
207 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="Edit language overlay record" border="0" alt="" />'.
208 '</a>';
209
210 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]='.$langRow['uid'].'"); return false;').'">'.
211 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit_page.gif','width="12" height="12"').' title="Edit page" border="0" alt="" />'.
212 '</a>';
213 $info.= str_replace('###LANG_UID###',$langRow['uid'],$viewPageLink);
214
215 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
216 $tCells[] = '<td class="'.$status.'">&nbsp;</td>';
217 } else {
218 $status = $data['row']['l18n_cfg']&2 || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback';
219 $tCells[] = '<td class="'.$status.' c-leftLine">&nbsp;</td>';
220 $tCells[] = '<td class="'.$status.'">&nbsp;</td>';
221
222 $info = '';
223 $info.= '<input type="checkbox" name="newOL['.$langRow['uid'].']['.$data['row']['uid'].']" value="1" />';
224 $newOL_js[$langRow['uid']].= '
225 +(document.webinfoForm[\'newOL['.$langRow['uid'].']['.$data['row']['uid'].']\'].checked ? \'&edit[pages_language_overlay]['.$data['row']['uid'].']=new\' : \'\')
226 ';
227 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
228 }
229 }
230
231 $output.= '
232 <tr class="bgColor4">
233 '.implode('
234 ',$tCells).'
235 </tr>';
236 }
237
238 // Put together HEADER:
239 $tCells = array();
240 $tCells[] = '<td>Page:</td>';
241 $tCells[] = '<td class="c-leftLine">Default:</td>';
242 foreach($languages as $langRow) {
243 $params = "'".$newOL_js[$langRow['uid']]."+'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=".$langRow['uid'];
244 $tCells[] = '<td class="c-leftLine">'.htmlspecialchars($langRow['title']).'</td>';
245 $tCells[] = '<td><img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="Edit default language page header" border="0" alt="" /></td>';
246 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
247 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/new_el.gif','width="11" height="12"').' title="Create new translation headers" border="0" alt="" />
248 </a></td>';
249 }
250
251 $output = '
252 <tr class="bgColor5">
253 '.implode('
254 ',$tCells).'
255 </tr>'.$output;
256
257 $output = '<table border="0" cellspacing="0" cellpadding="0" id="langTable">'.$output.'</table>';
258
259 return $output;
260 }
261
262 function getSystemLanguages() {
263 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
264 '*',
265 'sys_language',
266 '1'.t3lib_BEfunc::deleteClause('sys_language')
267 );
268
269 $outputArray = array();
270 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
271 $outputArray[] = $row;
272 }
273
274 return $outputArray;
275 }
276
277 function getLangStatus($pageId, $langId) {
278 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
279 '*',
280 'pages_language_overlay',
281 'pid='.intval($pageId).
282 ' AND sys_language_uid='.intval($langId).
283 t3lib_BEfunc::deleteClause('pages_language_overlay')
284 );
285
286 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
287 if (is_array($row)) {
288 $row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
289 }
290
291 return $row;
292 }
293 }
294
295
296 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']) {
297 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']);
298 }
299 ?>