00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00031 require_once(PATH_t3lib."class.t3lib_tceforms.php");
00032 require_once(PATH_t3lib."class.t3lib_tcemain.php");
00033
00034 require_once(PATH_t3lib."class.t3lib_fullsearch.php");
00035 require_once(PATH_t3lib."class.t3lib_xml.php");
00036 require_once(PATH_t3lib."class.t3lib_loaddbgroup.php");
00037
00038 class tx_sysaction extends mod_user_task {
00039 var $todoTypesCache = array();
00040 var $insCounter=0;
00041 var $xCol;
00042 var $t3lib_TCEforms;
00043
00044 function overview_main() {
00045 $mC = $this->renderActionList();
00046 if ($mC) {
00047 $icon = '<img src="'.$this->backPath.t3lib_extMgm::extRelPath("sys_action").'ext_icon.gif" width=18 height=16 class="absmiddle">';
00048 return $this->mkMenuConfig($icon.$this->headLink("tx_sysaction",1),'',$mC);
00049 }
00050 }
00051 function main() {
00052 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
00053
00054 return $this->renderActions();
00055 }
00056 function JScode() {
00057 $this->t3lib_TCEforms = t3lib_div::makeInstance("t3lib_TCEforms");
00058 $this->t3lib_TCEforms->backPath = $GLOBALS["BACK_PATH"];
00059 return $this->t3lib_TCEforms->dbFileCon();
00060 }
00061
00062
00063
00064
00065 function renderActions() {
00066 global $LANG;
00067 $uid = t3lib_div::intInRange(t3lib_div::_GP("sys_action_uid"),0);
00068 $out="";
00069 $header="";
00070 if ($uid) {
00071 $res = $this->getActionResPointer($uid);
00072 if($actionRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00073
00074
00075 $header = t3lib_iconworks::getIconImage("sys_action",$actionRow,$this->backPath,'hspace="2" class="absmiddle"').'<b>'.$actionRow["title"].'</b>';
00076 $out.='<table border=0 cellpadding=0 cellspacing=1 width=100%>
00077 <tr><td colspan=2 class="bgColor5">'.fw($header).'</td></tr>
00078 <tr>
00079 <td width=1% valign=top class="bgColor4">'.fw($LANG->sL(t3lib_BEfunc::getItemLabel("sys_action","type"))." ").'</td>
00080 <td valign=top class="bgColor4">'.fw(htmlspecialchars(t3lib_BEfunc::getProcessedValue("sys_action","type",$actionRow["type"]))).'</td>
00081 </tr>
00082 <tr>
00083 <td width=1% valign=top class="bgColor4">'.fw($LANG->sL(t3lib_BEfunc::getItemLabel("sys_action","description"))." ").'</td>
00084 <td valign=top class="bgColor4">'.fw(nl2br($actionRow["description"])).'</td>
00085 </tr>';
00086 $out.='</table>';
00087 $theCode = $this->pObj->doc->section("",$out,0,1);
00088
00089
00090
00091
00092 switch($actionRow["type"]) {
00093 case 1:
00094 $actionContent="";
00095 $beRec = t3lib_BEfunc::getRecord("be_users",intval($actionRow["t1_copy_of_user"]));
00096 if (is_array($beRec)) {
00097
00098 $inData = t3lib_div::_GP("data");
00099
00100 $userRecord="";
00101 $newFlag=0;
00102 if (is_array($inData["be_users"])) {
00103 $nId = $this->action_t1_createUpdateBeUser($inData["be_users"],$actionRow);
00104 $userRecord=t3lib_BEfunc::getRecord("be_users",$nId);
00105 }
00106 if (t3lib_div::_GP("be_users_uid")) {
00107 $userRecord=t3lib_BEfunc::getRecord("be_users",t3lib_div::_GP("be_users_uid"));
00108 }
00109 if (!is_array($userRecord)) {
00110 $userRecord=array();
00111 if (is_array($inData["be_users"]["NEW"])) { $userRecord=$inData["be_users"]["NEW"]; }
00112 $userRecord["uid"]="NEW";
00113 $newFlag=1;
00114 }
00115
00116
00117
00118
00119 $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');
00120 $lines = array();
00121 while($uRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00122 $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>";
00123 }
00124 if (count($lines)) {
00125 $theCode.= $this->pObj->doc->section($LANG->getLL("action_t1_listOfUsers"),implode("",$lines),0,1);
00126 }
00127
00128 $formA=Array();
00129 $opt=array();
00130
00131 $grList = t3lib_div::trimExplode(",",$actionRow["t1_allowed_groups"],1);
00132 reset($grList);
00133 $opt[]='<option value=""></option>';
00134 while(list(,$gu)=each($grList)) {
00135 $checkGr = t3lib_BEfunc::getRecord("be_groups",$gu);
00136 if (is_array($checkGr)) $opt[]='<option value="'.$checkGr["uid"].'"'.(t3lib_div::inList($userRecord["usergroup"],$checkGr["uid"])?" selected":"").'>'.htmlspecialchars($checkGr["title"]).'</option>';
00137 }
00138
00139 $formA[]=array($LANG->getLL("action_BEu_hidden").": ", '<input type="checkbox" name="data[be_users]['.$userRecord["uid"].'][disable]" value=1'.($userRecord["disable"]?" checked":"").'>');
00140 $formA[]=array($LANG->getLL("action_BEu_username").": ", '<input type="text" name="data[be_users]['.$userRecord["uid"].'][username]" max=15 value="'.htmlspecialchars($userRecord["username"]).'"'.$this->pObj->doc->formWidth(15).'>');
00141 $formA[]=array($LANG->getLL("action_BEu_password").": ", '<input type="password" name="data[be_users]['.$userRecord["uid"].'][password]" max=40'.$this->pObj->doc->formWidth(15).'>');
00142 $formA[]=array($LANG->getLL("action_BEu_realName").": ", '<input type="text" name="data[be_users]['.$userRecord["uid"].'][realName]" value="'.htmlspecialchars($userRecord["realName"]).'"'.$this->pObj->doc->formWidth(30).'>');
00143 $formA[]=array($LANG->getLL("action_BEu_email").": ", '<input type="text" name="data[be_users]['.$userRecord["uid"].'][email]" value="'.htmlspecialchars($userRecord["email"]).'"'.$this->pObj->doc->formWidth(30).'>');
00144 if (count($grList)) {
00145 $formA[]=array($LANG->getLL("action_BEu_usergroups").": ", '<select size='.t3lib_div::intInRange(count($opt),2).' multiple name="data[be_users]['.$userRecord["uid"].'][usergroups][]">'.implode("",$opt).'</select>');
00146 }
00147
00148 $loadDB = t3lib_div::makeInstance("t3lib_loadDBGroup");
00149 $loadDB->start($userRecord["db_mountpoints"],"pages");
00150 $params=array(
00151 "size" => 3
00152 );
00153 $formA[]=array($LANG->getLL("action_BEu_db_mount").": ", $this->t3lib_TCEforms->dbFileIcons('data[be_users]['.$userRecord["uid"].'][db_mountpoints]','db','pages',$loadDB->itemArray,"",$params));
00154
00155 $formA[]=array(" "," ");
00156 $formA[]=array(" ", '<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")).');">':''));
00157
00158 if (!$newFlag) {
00159 $p = 'uid='.$userRecord["uid"].", ".$LANG->getLL("lHomedir").": ";
00160 $hPath=$this->action_getUserMainDir();
00161 if ($hPath && @is_dir($hPath.$userRecord["uid"]."/")) {
00162 $p.= $hPath;
00163 } else {
00164 $p.= $LANG->getLL("lNone");
00165 }
00166 $actionContent.=t3lib_iconworks::getIconImage("be_users",$userRecord,$this->backPath,'title="'.htmlspecialchars($p).'" hspace=2 align=top').$userRecord["username"]." (".$userRecord["realName"].")";
00167 }
00168 $actionContent.=$this->pObj->doc->table($formA);
00169 $theCode.= $this->pObj->doc->section($LANG->getLL($newFlag?"action_Create":"action_Update"),$actionContent,0,1);
00170 } else {
00171 $theCode.= $this->pObj->doc->section($LANG->getLL("action_error"),'<span class="typo3-red">'.$LANG->getLL("action_notReady").'</span>',0,1);
00172 }
00173 break;
00174 case 2:
00175 if (t3lib_extMgm::isLoaded("lowlevel")) {
00176 $sql_query = unserialize($actionRow["t2_data"]);
00177 if (is_array($sql_query) && strtoupper(substr(trim($sql_query["qSelect"]),0,6))=="SELECT") {
00178 $fullsearch = t3lib_div::makeInstance("t3lib_fullsearch");
00179 $fullsearch->formW = 40;
00180 $fullsearch->noDownloadB=1;
00181 $actionContent="";
00182
00183 $type = $sql_query["qC"]["search_query_makeQuery"];
00184 $res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db,$sql_query["qSelect"]);
00185 if (!$GLOBALS['TYPO3_DB']->sql_error()) {
00186 $fullsearch->formW=48;
00187 $cP=$fullsearch->getQueryResultCode($type,$res,$sql_query["qC"]["queryTable"]);
00188 $actionContent=$cP["content"];
00189 if ($type=="csv" || $type=="xml") {
00190 $actionContent.='<BR><BR><a href="'.t3lib_div::getIndpEnv("REQUEST_URI").'&download_file=1"><strong>'.$LANG->getLL("action_download_file").'</strong></a>';
00191 }
00192 } else {
00193 $actionContent.=$GLOBALS['TYPO3_DB']->sql_error();
00194 }
00195 if ($this->BE_USER->isAdmin()) {
00196 $actionContent.="<HR>".$fullsearch->tableWrap($sql_query["qSelect"]);
00197 $actionContent.='<BR><strong><a href="'.$this->backPath.t3lib_extMgm::extRelPath("lowlevel").'dbint/index.php?id='.
00198 '&SET[function]=search'.
00199 '&SET[search]=query'.
00200 '&storeControl[STORE]=-'.$actionRow["uid"].
00201 '&storeControl[LOAD]=1'.
00202 '">Edit Query</a></strong>';
00203 }
00204 $theCode.= $this->pObj->doc->section($LANG->getLL("action_t2_result"),$actionContent,0,1);
00205 } else {
00206 $theCode.= $this->pObj->doc->section($LANG->getLL("action_error"),'<span class="typo3-red">'.$LANG->getLL("action_notReady").'</span>',0,1);
00207 }
00208 } else {
00209 $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);
00210 }
00211 break;
00212 case 3:
00213 Header("Location: ".t3lib_div::locationHeaderUrl($this->backPath."db_list.php?id=".intval($actionRow["t3_listPid"])."&table=".$actionRow["t3_tables"]));
00214 exit;
00215 break;
00216 case 4:
00217 $dbAnalysis = t3lib_div::makeInstance("t3lib_loadDBGroup");
00218 $dbAnalysis->fromTC=0;
00219 $dbAnalysis->start($actionRow["t4_recordsToEdit"],"*");
00220 $dbAnalysis->getFromDB();
00221
00222 $lines=array();
00223 reset($dbAnalysis->itemArray);
00224 while(list(,$el)=each($dbAnalysis->itemArray)) {
00225 $path = t3lib_BEfunc::getRecordPath ($el["id"],$this->perms_clause,$this->BE_USER->uc["titleLen"]);
00226 $lines[]='<tr>
00227 <td nowrap class="bgColor4">'.
00228 '<a href="'.$this->backPath.'alt_doc.php?returnUrl='.rawurlencode(t3lib_div::getIndpEnv("REQUEST_URI")).'&edit['.$el["table"].']['.$el["id"].']=edit">'.
00229 t3lib_iconworks::getIconImage($el["table"],$dbAnalysis->results[$el["table"]][$el["id"]],$this->backPath,'hspace="2" align="top" title="'.htmlspecialchars($path).'"').
00230 t3lib_BEfunc::getRecordTitle($el["table"],$dbAnalysis->results[$el["table"]][$el["id"]],1).'</a></td>
00231 </tr>';
00232 }
00233 $actionContent = '<table border=0 cellpadding=0 cellspacing=2>'.implode("",$lines).'</table>';
00234 $theCode.= $this->pObj->doc->section($LANG->getLL("action_t4_edit"),$actionContent,0,1);
00235 break;
00236 case 5:
00237 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'));
00238 exit;
00239 break;
00240 default:
00241 $theCode.= $this->pObj->doc->section($LANG->getLL("action_error"),'<span class="typo3-red">'.$LANG->getLL("action_noType").'</span>',0,1);
00242 break;
00243 }
00244
00245 }
00246 }
00247 return $theCode;
00248 }
00249 function getActionResPointer($uid=0) {
00250 if ($this->BE_USER->isAdmin()) {
00251 $wQ='';
00252 if (intval($uid)>0) $wQ.=' AND sys_action.uid='.intval($uid);
00253
00254 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_action', 'sys_action.pid=0'.$wQ, '', 'sys_action.title');
00255 } else {
00256 $wQ = 'be_groups.uid IN ('.($this->BE_USER->groupList?$this->BE_USER->groupList:0).')';
00257 $hQ = 'AND sys_action.hidden=0 ';
00258 if (intval($uid)>0) $wQ.=' AND sys_action.uid='.intval($uid);
00259
00260 $res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
00261 'sys_action.*',
00262 'sys_action',
00263 'sys_action_asgr_mm',
00264 'be_groups',
00265 ' AND '.$wQ.' AND sys_action.pid=0 '.$hQ,
00266 'sys_action.uid',
00267 'sys_action.title'
00268 );
00269 }
00270
00271 return $res;
00272 }
00273 function renderActionList() {
00274 global $LANG;
00275
00276 $res = $this->getActionResPointer();
00277 $lines=array();
00278 while($actionRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00279 $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>';
00280 }
00281 $out = implode("",$lines);
00282 return $out;
00283 }
00284 function action_link($str,$id,$title="") {
00285 $str='<a href="index.php?SET[function]=tx_sysaction&sys_action_uid='.$id.'" onClick="this.blur();" title="'.htmlspecialchars($title).'">'.$str.'</a>';
00286 return $str;
00287 }
00288 function action_linkUserName($str,$id,$bid) {
00289 $str='<a href="index.php?sys_action_uid='.$id.'&be_users_uid='.$bid.'" onClick="this.blur();">'.$str.'</a>';
00290 return $str;
00291 }
00292 function action_t1_createUpdateBeUser($arr,$actionRow=array()) {
00293 reset($arr);
00294 $key = key($arr);
00295 $data="";
00296 $nId=0;
00297 $BEuid = $actionRow["t1_copy_of_user"];
00298 if ($key=="NEW") {
00299 $beRec = t3lib_BEfunc::getRecord("be_users",intval($BEuid));
00300 if (is_array($beRec) && trim($arr[$key]["password"]) && $this->fixUsername($arr[$key]["username"],$actionRow["t1_userprefix"])) {
00301
00302 $data=array();
00303 $data["be_users"][$key]=$beRec;
00304 $data["be_users"][$key]["username"]=$this->fixUsername($arr[$key]["username"],$actionRow["t1_userprefix"]);
00305 $data["be_users"][$key]["password"]=md5(trim($arr[$key]["password"]));
00306 $data["be_users"][$key]["realName"]=$arr[$key]["realName"];
00307 $data["be_users"][$key]["email"]=$arr[$key]["email"];
00308 $data["be_users"][$key]["disable"]=intval($arr[$key]["disable"]);
00309 $data["be_users"][$key]["admin"]=0;
00310 $data["be_users"][$key]["usergroup"] = $this->fixUserGroup($data["be_users"][$key]["usergroup"],$actionRow["t1_allowed_groups"],$arr[$key]["usergroups"]);
00311 $data["be_users"][$key]["db_mountpoints"]=$arr[$key]["db_mountpoints"];
00312 $data["be_users"][$key]["createdByAction"]=$actionRow["uid"];
00313 }
00314 } else {
00315 $beRec = t3lib_BEfunc::getRecord("be_users",intval($key));
00316 if (is_array($beRec) && $beRec["cruser_id"]==$this->BE_USER->user["uid"]) {
00317 if (t3lib_div::_GP("_delete_")) {
00318
00319 $cmd=array();
00320 $cmd["be_users"][$key]["delete"]=1;
00321
00322 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
00323 $tce->stripslashes_values=0;
00324 $tce->start(Array(),$cmd,$this->BE_USER);
00325 $tce->admin=1;
00326 $tce->process_cmdmap();
00327
00328 $nId = 0;
00329 } elseif ($this->fixUsername($arr[$key]["username"],$actionRow["t1_userprefix"])) {
00330
00331 $data=array();
00332 $data["be_users"][$key]["username"]=$this->fixUsername($arr[$key]["username"],$actionRow["t1_userprefix"]);
00333 if (trim($arr[$key]["password"])) {$data["be_users"][$key]["password"]=md5(trim($arr[$key]["password"]));}
00334
00335 $data["be_users"][$key]["realName"]=$arr[$key]["realName"];
00336 $data["be_users"][$key]["email"]=$arr[$key]["email"];
00337 $data["be_users"][$key]["disable"]=intval($arr[$key]["disable"]);
00338 $data["be_users"][$key]["admin"]=0;
00339 $data["be_users"][$key]["usergroup"] = $this->fixUserGroup($beRec["usergroup"],$actionRow["t1_allowed_groups"],$arr[$key]["usergroups"]);
00340 $data["be_users"][$key]["db_mountpoints"]=$arr[$key]["db_mountpoints"];
00341 $nId=$key;
00342 }
00343 }
00344 }
00345
00346
00347 if (is_array($data)) {
00348 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
00349 $tce->stripslashes_values=0;
00350 $tce->start($data,Array(),$this->BE_USER);
00351 $tce->admin=1;
00352 $tce->process_datamap();
00353 $nId = intval($tce->substNEWwithIDs["NEW"]);
00354 if ($nId) {
00355 $this->action_createDir($nId);
00356 } else {
00357 $nId=intval($key);
00358 }
00359 unset($tce);
00360 }
00361 return $nId;
00362 }
00363 function fixUsername($username,$prefix) {
00364 $username=trim($username);
00365 $prefix=trim($prefix);
00366 $username=ereg_replace("^".quotemeta($prefix),"",$username);
00367
00368 if ($username) {
00369 return $prefix.$username;
00370 } else return false;
00371 }
00372 function fixUserGroup($curUserGroup,$allowedGroups,$inGroups) {
00373
00374
00375 $cGroups = array_flip(t3lib_div::trimExplode(",",$curUserGroup,1));
00376 $grList = t3lib_div::intExplode(",",$allowedGroups);
00377 reset($grList);
00378 while(list(,$gu)=each($grList)) {
00379 unset($cGroups[$gu]);
00380 }
00381
00382 $cGroups=array_keys($cGroups);
00383 if (is_array($inGroups)) {
00384 reset($inGroups);
00385 while(list(,$gu)=each($inGroups)) {
00386 $checkGr = t3lib_BEfunc::getRecord("be_groups",$gu);
00387 if (is_array($checkGr) && in_array($gu,$grList)) {
00388 $cGroups[]=$gu;
00389 }
00390 }
00391 }
00392 return implode(",",$cGroups);
00393 }
00394 function action_createDir($uid) {
00395 $path = $this->action_getUserMainDir();
00396 if ($path) {
00397 @mkdir($path.$uid,0755);
00398 @mkdir($path.$uid."/_temp_",0755);
00399
00400 }
00401 }
00402 function action_getUserMainDir() {
00403 $path = $GLOBALS["TYPO3_CONF_VARS"]["BE"]["userHomePath"];
00404 if ($path && @is_dir($path) &&
00405 $GLOBALS["TYPO3_CONF_VARS"]["BE"]["lockRootPath"] &&
00406 t3lib_div::isFirstPartOfStr($path,$GLOBALS["TYPO3_CONF_VARS"]["BE"]["lockRootPath"]) &&
00407 substr($path,-1)=="/"
00408 ) {
00409 return $path;
00410 }
00411 }
00412 }
00413
00414 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/sys_action/class.tx_sysaction.php"]) {
00415 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/sys_action/class.tx_sysaction.php"]);
00416 }
00417
00418 ?>