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