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