Iframe functionality in taskcenter updated. sys_action adjusted to the changes in...
[Packages/TYPO3.CMS.git] / typo3 / sysext / sys_action / class.tx_sysaction.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 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
29 */
30
31 require_once(PATH_t3lib."class.t3lib_tceforms.php");
32 require_once(PATH_t3lib."class.t3lib_tcemain.php");
33
34 require_once(PATH_t3lib."class.t3lib_fullsearch.php");
35 require_once(PATH_t3lib."class.t3lib_xml.php");
36 require_once(PATH_t3lib."class.t3lib_loaddbgroup.php");
37
38 class tx_sysaction extends mod_user_task {
39 var $todoTypesCache = array();
40 var $insCounter=0;
41 var $xCol;
42 var $t3lib_TCEforms;
43
44 function overview_main() {
45 $mC = $this->renderActionList();
46 if ($mC) {
47 $icon = '<img src="'.$this->backPath.t3lib_extMgm::extRelPath("sys_action").'ext_icon.gif" width=18 height=16 class="absmiddle">';
48 return $this->mkMenuConfig($icon.$this->headLink("tx_sysaction",1),'',$mC);
49 }
50 }
51 function main() {
52 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
53
54 return $this->renderActions();
55 }
56 function JScode() {
57 $this->t3lib_TCEforms = t3lib_div::makeInstance("t3lib_TCEforms");
58 $this->t3lib_TCEforms->backPath = $GLOBALS["BACK_PATH"];
59 return $this->t3lib_TCEforms->dbFileCon();
60 }
61
62 // ************************
63 // ACTIONS
64 // ***********************
65 function renderActions() {
66 global $LANG;
67 $uid = t3lib_div::intInRange(t3lib_div::_GP("sys_action_uid"),0);
68 $out="";
69 $header="";
70 if ($uid) {
71 $res = $this->getActionResPointer($uid);
72 if($actionRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
73
74 // Action header:
75 $header = t3lib_iconworks::getIconImage("sys_action",$actionRow,$this->backPath,'hspace="2" class="absmiddle"').'<b>'.$actionRow["title"].'</b>';
76 $out.='<table border=0 cellpadding=0 cellspacing=1 width=100%>
77 <tr><td colspan=2 class="bgColor5">'.fw($header).'</td></tr>
78 <tr>
79 <td width=1% valign=top class="bgColor4">'.fw($LANG->sL(t3lib_BEfunc::getItemLabel("sys_action","type"))."&nbsp;").'</td>
80 <td valign=top class="bgColor4">'.fw(htmlspecialchars(t3lib_BEfunc::getProcessedValue("sys_action","type",$actionRow["type"]))).'</td>
81 </tr>
82 <tr>
83 <td width=1% valign=top class="bgColor4">'.fw($LANG->sL(t3lib_BEfunc::getItemLabel("sys_action","description"))."&nbsp;").'</td>
84 <td valign=top class="bgColor4">'.fw(nl2br($actionRow["description"])).'</td>
85 </tr>';
86 $out.='</table>';
87 $theCode = $this->pObj->doc->section("",$out,0,1);
88
89
90
91 // Types of actions:
92 switch($actionRow["type"]) {
93 case 1:
94 $actionContent="";
95 $beRec = t3lib_BEfunc::getRecord("be_users",intval($actionRow["t1_copy_of_user"]));
96 if (is_array($beRec)) {
97 // Create or update:
98 $inData = t3lib_div::_GP("data");
99 // debug($inData);
100 $userRecord="";
101 $newFlag=0;
102 if (is_array($inData["be_users"])) {
103 $nId = $this->action_t1_createUpdateBeUser($inData["be_users"],$actionRow);
104 $userRecord=t3lib_BEfunc::getRecord("be_users",$nId);
105 }
106 if (t3lib_div::_GP("be_users_uid")) {
107 $userRecord=t3lib_BEfunc::getRecord("be_users",t3lib_div::_GP("be_users_uid"));
108 }
109 if (!is_array($userRecord)) {
110 $userRecord=array();
111 if (is_array($inData["be_users"]["NEW"])) { $userRecord=$inData["be_users"]["NEW"]; }
112 $userRecord["uid"]="NEW";
113 $newFlag=1;
114 }
115
116
117
118 // List of users...
119 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'be_users', 'pid=0 AND cruser_id='.intval($this->BE_USER->user['uid']).' AND createdByAction='.intval($actionRow['uid']).t3lib_BEfunc::deleteClause('be_users'), '', 'username');
120 $lines = array();
121 while($uRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
122 $lines[] = "<nobr>".($uRow["uid"]==$userRecord["uid"]?"<b>":"").$this->action_linkUserName(t3lib_iconworks::getIconImage("be_users",$uRow,$this->backPath,'title="uid='.$uRow["uid"].'" hspace="2" align="top"').$uRow["username"]." (".$uRow["realName"].")".($uRow["uid"]==$userRecord["uid"]?"</b>":"")."</nobr>",$actionRow["uid"],$uRow["uid"])."<br>";
123 }
124 if (count($lines)) {
125 $theCode.= $this->pObj->doc->section($LANG->getLL("action_t1_listOfUsers"),implode("",$lines),0,1);
126 }
127
128 $formA=Array();
129 $opt=array();
130
131 $grList = t3lib_div::trimExplode(",",$actionRow["t1_allowed_groups"],1);
132 reset($grList);
133 $opt[]='<option value=""></option>';
134 while(list(,$gu)=each($grList)) {
135 $checkGr = t3lib_BEfunc::getRecord("be_groups",$gu);
136 if (is_array($checkGr)) $opt[]='<option value="'.$checkGr["uid"].'"'.(t3lib_div::inList($userRecord["usergroup"],$checkGr["uid"])?" selected":"").'>'.htmlspecialchars($checkGr["title"]).'</option>';
137 }
138
139 $formA[]=array($LANG->getLL("action_BEu_hidden").":&nbsp;", '<input type="checkbox" name="data[be_users]['.$userRecord["uid"].'][disable]" value=1'.($userRecord["disable"]?" checked":"").'>');
140 $formA[]=array($LANG->getLL("action_BEu_username").":&nbsp;", '<input type="text" name="data[be_users]['.$userRecord["uid"].'][username]" max=15 value="'.htmlspecialchars($userRecord["username"]).'"'.$this->pObj->doc->formWidth(15).'>');
141 $formA[]=array($LANG->getLL("action_BEu_password").":&nbsp;", '<input type="password" name="data[be_users]['.$userRecord["uid"].'][password]" max=40'.$this->pObj->doc->formWidth(15).'>');
142 $formA[]=array($LANG->getLL("action_BEu_realName").":&nbsp;", '<input type="text" name="data[be_users]['.$userRecord["uid"].'][realName]" value="'.htmlspecialchars($userRecord["realName"]).'"'.$this->pObj->doc->formWidth(30).'>');
143 $formA[]=array($LANG->getLL("action_BEu_email").":&nbsp;", '<input type="text" name="data[be_users]['.$userRecord["uid"].'][email]" value="'.htmlspecialchars($userRecord["email"]).'"'.$this->pObj->doc->formWidth(30).'>');
144 if (count($grList)) {
145 $formA[]=array($LANG->getLL("action_BEu_usergroups").":&nbsp;", '<select size='.t3lib_div::intInRange(count($opt),2).' multiple name="data[be_users]['.$userRecord["uid"].'][usergroups][]">'.implode("",$opt).'</select>');
146 }
147 // DB mounts:
148 $loadDB = t3lib_div::makeInstance("t3lib_loadDBGroup");
149 $loadDB->start($userRecord["db_mountpoints"],"pages");
150 $params=array(
151 "size" => 3
152 );
153 $formA[]=array($LANG->getLL("action_BEu_db_mount").":&nbsp;", $this->t3lib_TCEforms->dbFileIcons('data[be_users]['.$userRecord["uid"].'][db_mountpoints]','db','pages',$loadDB->itemArray,"",$params));
154
155 $formA[]=array("&nbsp;","&nbsp;");
156 $formA[]=array("&nbsp;", '<input type=hidden value="'.$uid.'" name="sys_action_uid"><input type=hidden value="'.t3lib_div::_GP("be_users_uid").'" name="be_users_uid"><input type=hidden value="'.$uid.'" name="sys_action_uid"><input type="submit" name="submit" value="'.$LANG->getLL($newFlag?"lCreate":"lUpdate").'">'.(!$newFlag?' <input type="submit" name="_delete_" value="'.$LANG->getLL("lDelete").'" onClick="return confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL("lDelete_warning")).');">':''));
157
158 if (!$newFlag) {
159 $p = 'uid='.$userRecord["uid"].", ".$LANG->getLL("lHomedir").": ";
160 $hPath=$this->action_getUserMainDir();
161 if ($hPath && @is_dir($hPath.$userRecord["uid"]."/")) {
162 $p.= $hPath;
163 } else {
164 $p.= $LANG->getLL("lNone");
165 }
166 $actionContent.=t3lib_iconworks::getIconImage("be_users",$userRecord,$this->backPath,'title="'.htmlspecialchars($p).'" hspace=2 align=top').$userRecord["username"]." (".$userRecord["realName"].")";
167 }
168 $actionContent.=$this->pObj->doc->table($formA);
169 $theCode.= $this->pObj->doc->section($LANG->getLL($newFlag?"action_Create":"action_Update"),$actionContent,0,1);
170 } else {
171 $theCode.= $this->pObj->doc->section($LANG->getLL("action_error"),'<span class="typo3-red">'.$LANG->getLL("action_notReady").'</span>',0,1);
172 }
173 break;
174 case 2:
175 if (t3lib_extMgm::isLoaded("lowlevel")) {
176 $sql_query = unserialize($actionRow["t2_data"]);
177 if (is_array($sql_query) && strtoupper(substr(trim($sql_query["qSelect"]),0,6))=="SELECT") {
178 $fullsearch = t3lib_div::makeInstance("t3lib_fullsearch");
179 $fullsearch->formW = 40;
180 $fullsearch->noDownloadB=1;
181 $actionContent="";
182 // debug($sql_query);
183 $type = $sql_query["qC"]["search_query_makeQuery"];
184 $res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db,$sql_query["qSelect"]);
185 if (!$GLOBALS['TYPO3_DB']->sql_error()) {
186 $fullsearch->formW=48;
187 $cP=$fullsearch->getQueryResultCode($type,$res,$sql_query["qC"]["queryTable"]);
188 $actionContent=$cP["content"];
189 if ($type=="csv" || $type=="xml") {
190 $actionContent.='<BR><BR><a href="'.t3lib_div::getIndpEnv("REQUEST_URI").'&download_file=1"><strong>'.$LANG->getLL("action_download_file").'</strong></a>';
191 }
192 } else {
193 $actionContent.=$GLOBALS['TYPO3_DB']->sql_error();
194 }
195 if ($this->BE_USER->isAdmin()) {
196 $actionContent.="<HR>".$fullsearch->tableWrap($sql_query["qSelect"]);
197 $actionContent.='<BR><strong><a href="'.$this->backPath.t3lib_extMgm::extRelPath("lowlevel").'dbint/index.php?id='.
198 '&SET[function]=search'.
199 '&SET[search]=query'.
200 '&storeControl[STORE]=-'.$actionRow["uid"].
201 '&storeControl[LOAD]=1'.
202 '">Edit Query</a></strong>';
203 }
204 $theCode.= $this->pObj->doc->section($LANG->getLL("action_t2_result"),$actionContent,0,1);
205 } else {
206 $theCode.= $this->pObj->doc->section($LANG->getLL("action_error"),'<span class="typo3-red">'.$LANG->getLL("action_notReady").'</span>',0,1);
207 }
208 } else {
209 $theCode.= $this->pObj->doc->section($LANG->getLL("action_error"),'<span class="typo3-red">The extension "lowlevel" must be installed in order to create a quiry</span>',0,1);
210 }
211 break;
212 case 3:
213 Header("Location: ".t3lib_div::locationHeaderUrl($this->backPath."db_list.php?id=".intval($actionRow["t3_listPid"])."&table=".$actionRow["t3_tables"]));
214 exit;
215 break;
216 case 4:
217 $dbAnalysis = t3lib_div::makeInstance("t3lib_loadDBGroup");
218 $dbAnalysis->fromTC=0;
219 $dbAnalysis->start($actionRow["t4_recordsToEdit"],"*");
220 $dbAnalysis->getFromDB();
221
222 $lines=array();
223 reset($dbAnalysis->itemArray);
224 while(list(,$el)=each($dbAnalysis->itemArray)) {
225 $path = t3lib_BEfunc::getRecordPath ($el["id"],$this->perms_clause,$this->BE_USER->uc["titleLen"]);
226 $lines[]='<tr>
227 <td nowrap class="bgColor4">'.
228 '<a href="'.$this->backPath.'alt_doc.php?returnUrl='.rawurlencode(t3lib_div::getIndpEnv("REQUEST_URI")).'&edit['.$el["table"].']['.$el["id"].']=edit">'.
229 t3lib_iconworks::getIconImage($el["table"],$dbAnalysis->results[$el["table"]][$el["id"]],$this->backPath,'hspace="2" align="top" title="'.htmlspecialchars($path).'"').
230 t3lib_BEfunc::getRecordTitle($el["table"],$dbAnalysis->results[$el["table"]][$el["id"]],1).'</a></td>
231 </tr>';
232 }
233 $actionContent = '<table border=0 cellpadding=0 cellspacing=2>'.implode("",$lines).'</table>';
234 $theCode.= $this->pObj->doc->section($LANG->getLL("action_t4_edit"),$actionContent,0,1);
235 break;
236 case 5:
237 Header('Location: '.t3lib_div::locationHeaderUrl($this->backPath.'alt_doc.php?returnUrl='.rawurlencode('db_list.php?id='.intval($actionRow['t3_listPid']).'&table='.$actionRow['t3_tables']).'&edit['.$actionRow['t3_tables'].']['.intval($actionRow['t3_listPid']).']=new'));
238 exit;
239 break;
240 default:
241 $theCode.= $this->pObj->doc->section($LANG->getLL("action_error"),'<span class="typo3-red">'.$LANG->getLL("action_noType").'</span>',0,1);
242 break;
243 }
244
245 }
246 }
247 return $theCode;
248 }
249 function getActionResPointer($uid=0) {
250 if ($this->BE_USER->isAdmin()) {
251 $wQ='';
252 if (intval($uid)>0) $wQ.=' AND sys_action.uid='.intval($uid);
253
254 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_action', 'sys_action.pid=0'.$wQ, '', 'sys_action.title');
255 } else {
256 $wQ = 'be_groups.uid IN ('.($this->BE_USER->groupList?$this->BE_USER->groupList:0).')';
257 $hQ = 'AND sys_action.hidden=0 ';
258 if (intval($uid)>0) $wQ.=' AND sys_action.uid='.intval($uid);
259
260 $res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
261 'sys_action.*',
262 'sys_action',
263 'sys_action_asgr_mm',
264 'be_groups',
265 ' AND '.$wQ.' AND sys_action.pid=0 '.$hQ,
266 'sys_action.uid',
267 'sys_action.title'
268 );
269 }
270
271 return $res;
272 }
273 function renderActionList() {
274 global $LANG;
275
276 $res = $this->getActionResPointer();
277 $lines=array();
278 while($actionRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
279 $lines[]='<nobr>'.t3lib_iconworks::getIconImage("sys_action",$actionRow,$this->backPath,'hspace="2" align="top"').$this->action_link($this->fixed_lgd($actionRow["title"]),$actionRow["uid"],$actionRow["description"]).'</nobr><BR>';
280 }
281 $out = implode("",$lines);
282 return $out;
283 }
284 function action_link($str,$id,$title="") {
285 $str='<a href="index.php?SET[function]=tx_sysaction&sys_action_uid='.$id.'" onClick="this.blur();" title="'.htmlspecialchars($title).'">'.$str.'</a>';
286 return $str;
287 }
288 function action_linkUserName($str,$id,$bid) {
289 $str='<a href="index.php?sys_action_uid='.$id.'&be_users_uid='.$bid.'" onClick="this.blur();">'.$str.'</a>';
290 return $str;
291 }
292 function action_t1_createUpdateBeUser($arr,$actionRow=array()) {
293 reset($arr);
294 $key = key($arr);
295 $data="";
296 $nId=0;
297 $BEuid = $actionRow["t1_copy_of_user"];
298 if ($key=="NEW") {
299 $beRec = t3lib_BEfunc::getRecord("be_users",intval($BEuid));
300 if (is_array($beRec) && trim($arr[$key]["password"]) && $this->fixUsername($arr[$key]["username"],$actionRow["t1_userprefix"])) {
301 // debug($arr[$key]);
302 $data=array();
303 $data["be_users"][$key]=$beRec;
304 $data["be_users"][$key]["username"]=$this->fixUsername($arr[$key]["username"],$actionRow["t1_userprefix"]);
305 $data["be_users"][$key]["password"]=md5(trim($arr[$key]["password"]));
306 $data["be_users"][$key]["realName"]=$arr[$key]["realName"];
307 $data["be_users"][$key]["email"]=$arr[$key]["email"];
308 $data["be_users"][$key]["disable"]=intval($arr[$key]["disable"]);
309 $data["be_users"][$key]["admin"]=0;
310 $data["be_users"][$key]["usergroup"] = $this->fixUserGroup($data["be_users"][$key]["usergroup"],$actionRow["t1_allowed_groups"],$arr[$key]["usergroups"]);
311 $data["be_users"][$key]["db_mountpoints"]=$arr[$key]["db_mountpoints"];
312 $data["be_users"][$key]["createdByAction"]=$actionRow["uid"];
313 }
314 } else {
315 $beRec = t3lib_BEfunc::getRecord("be_users",intval($key));
316 if (is_array($beRec) && $beRec["cruser_id"]==$this->BE_USER->user["uid"]) {
317 if (t3lib_div::_GP("_delete_")) {
318 // delete... ?
319 $cmd=array();
320 $cmd["be_users"][$key]["delete"]=1;
321
322 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
323 $tce->stripslashes_values=0;
324 $tce->start(Array(),$cmd,$this->BE_USER);
325 $tce->admin=1;
326 $tce->process_cmdmap();
327 // debug($cmd);
328 $nId = 0;
329 } elseif ($this->fixUsername($arr[$key]["username"],$actionRow["t1_userprefix"])) {
330 // check ownership...
331 $data=array();
332 $data["be_users"][$key]["username"]=$this->fixUsername($arr[$key]["username"],$actionRow["t1_userprefix"]);
333 if (trim($arr[$key]["password"])) {$data["be_users"][$key]["password"]=md5(trim($arr[$key]["password"]));}
334
335 $data["be_users"][$key]["realName"]=$arr[$key]["realName"];
336 $data["be_users"][$key]["email"]=$arr[$key]["email"];
337 $data["be_users"][$key]["disable"]=intval($arr[$key]["disable"]);
338 $data["be_users"][$key]["admin"]=0;
339 $data["be_users"][$key]["usergroup"] = $this->fixUserGroup($beRec["usergroup"],$actionRow["t1_allowed_groups"],$arr[$key]["usergroups"]);
340 $data["be_users"][$key]["db_mountpoints"]=$arr[$key]["db_mountpoints"];
341 $nId=$key;
342 }
343 }
344 }
345
346
347 if (is_array($data)) {
348 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
349 $tce->stripslashes_values=0;
350 $tce->start($data,Array(),$this->BE_USER);
351 $tce->admin=1;
352 $tce->process_datamap();
353 $nId = intval($tce->substNEWwithIDs["NEW"]);
354 if ($nId) { // Create
355 $this->action_createDir($nId);
356 } else { // update
357 $nId=intval($key);
358 }
359 unset($tce);
360 }
361 return $nId;
362 }
363 function fixUsername($username,$prefix) {
364 $username=trim($username);
365 $prefix=trim($prefix);
366 $username=ereg_replace("^".quotemeta($prefix),"",$username);
367
368 if ($username) {
369 return $prefix.$username;
370 } else return false;
371 }
372 function fixUserGroup($curUserGroup,$allowedGroups,$inGroups) {
373 // User group:
374 // All current groups:
375 $cGroups = array_flip(t3lib_div::trimExplode(",",$curUserGroup,1));
376 $grList = t3lib_div::intExplode(",",$allowedGroups);
377 reset($grList);
378 while(list(,$gu)=each($grList)) {
379 unset($cGroups[$gu]); // Remove the group if it's in the array for some reason...
380 }
381 // reverse array again and set incoming groups:
382 $cGroups=array_keys($cGroups);
383 if (is_array($inGroups)) {
384 reset($inGroups);
385 while(list(,$gu)=each($inGroups)) {
386 $checkGr = t3lib_BEfunc::getRecord("be_groups",$gu);
387 if (is_array($checkGr) && in_array($gu,$grList)) {
388 $cGroups[]=$gu;
389 }
390 }
391 }
392 return implode(",",$cGroups);
393 }
394 function action_createDir($uid) {
395 $path = $this->action_getUserMainDir();
396 if ($path) {
397 @mkdir($path.$uid,0755);
398 @mkdir($path.$uid."/_temp_",0755);
399 // debug($path);
400 }
401 }
402 function action_getUserMainDir() {
403 $path = $GLOBALS["TYPO3_CONF_VARS"]["BE"]["userHomePath"];
404 if ($path && @is_dir($path) &&
405 $GLOBALS["TYPO3_CONF_VARS"]["BE"]["lockRootPath"] &&
406 t3lib_div::isFirstPartOfStr($path,$GLOBALS["TYPO3_CONF_VARS"]["BE"]["lockRootPath"]) &&
407 substr($path,-1)=="/"
408 ) {
409 return $path;
410 }
411 }
412 }
413
414 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/sys_action/class.tx_sysaction.php"]) {
415 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/sys_action/class.tx_sysaction.php"]);
416 }
417
418 ?>