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
00078 class mod_web_dmail {
00079 var $TSconfPrefix = "mod.web_modules.dmail.";
00080 var $fieldList="uid,name,title,email,phone,www,address,company,city,zip,country,fax,module_sys_dmail_category,module_sys_dmail_html,description";
00081
00082 var $modList="";
00083 var $params=array();
00084 var $perms_clause="";
00085 var $pageinfo="";
00086 var $sys_dmail_uid;
00087 var $CMD;
00088 var $pages_uid;
00089 var $categories;
00090 var $id;
00091 var $urlbase;
00092 var $back;
00093 var $noView;
00094 var $url_plain;
00095 var $url_html;
00096 var $mode;
00097 var $implodedParams=array();
00098 var $userTable;
00099
00100 function mod_web_dmail ($id,$pageinfo,$perms_clause,$CMD,$sys_dmail_uid,$pages_uid,$modTSconfig) {
00101 $this->id = $id;
00102 $this->pageinfo = $pageinfo;
00103 $this->perms_clause = $perms_clause;
00104 $this->CMD=$CMD;
00105 $this->sys_dmail_uid=$sys_dmail_uid;
00106 $this->pages_uid=$pages_uid;
00107 $this->modList = t3lib_BEfunc::getListOfBackendModules(array("dmail"),$this->perms_clause,$GLOBALS["BACK_PATH"]);
00108 $this->params=$modTSconfig["properties"];
00109 $this->implodedParams = t3lib_BEfunc::implodeTSParams($this->params);
00110 if ($this->params["userTable"] && is_array($GLOBALS["TCA"][$this->params["userTable"]])) {
00111 $this->userTable = $this->params["userTable"];
00112 t3lib_div::loadTCA($this->userTable);
00113 }
00114
00115 t3lib_div::loadTCA("sys_dmail");
00116
00117
00118
00119 include (t3lib_extMgm::extPath("direct_mail")."mod/locallang.php");
00120 $GLOBALS["LOCAL_LANG"] = t3lib_div::array_merge_recursive_overrule($GLOBALS["LOCAL_LANG"],$LOCAL_LANG_DMAIL);
00121
00122
00123
00124
00125
00126
00127 }
00128 function createDMail() {
00129 global $TCA;
00130 if ($createMailFrom = t3lib_div::_GP("createMailFrom")) {
00131
00132 $dmail = array();
00133 $dmail["sys_dmail"]["NEW"] = array (
00134 "from_email" => $this->params["from_email"],
00135 "from_name" => $this->params["from_name"],
00136 "replyto_email" => $this->params["replyto_email"],
00137 "replyto_name" => $this->params["replyto_name"],
00138 "return_path" => $this->params["return_path"],
00139 "long_link_rdct_url" => $this->params["long_link_rdct_url"],
00140 "long_link_mode" => $this->params["long_link_mode"],
00141 "organisation" => $this->params["organisation"]
00142 );
00143 $dmail["sys_dmail"]["NEW"]["sendOptions"] = $TCA["sys_dmail"]["columns"]["sendOptions"]["config"]["default"];
00144
00145 if (isset($this->params["sendOptions"])) $dmail["sys_dmail"]["NEW"]["sendOptions"] = $this->params["sendOptions"];
00146 if (isset($this->params["HTMLParams"])) $dmail["sys_dmail"]["NEW"]["HTMLParams"] = $this->params["HTMLParams"];
00147 if (isset($this->params["plainParams"])) $dmail["sys_dmail"]["NEW"]["plainParams"] = $this->params["plainParams"];
00148
00149
00150 if (t3lib_div::testInt($createMailFrom)) {
00151 $createFromMailRec = t3lib_BEfunc::getRecord ("pages",$createMailFrom);
00152 if (t3lib_div::inList($GLOBALS["TYPO3_CONF_VARS"]["FE"]["content_doktypes"],$createFromMailRec["doktype"])) {
00153 $dmail["sys_dmail"]["NEW"]["subject"] = $createFromMailRec["title"];
00154 $dmail["sys_dmail"]["NEW"]["type"] = 0;
00155 $dmail["sys_dmail"]["NEW"]["page"] = $createFromMailRec["uid"];
00156 $dmail["sys_dmail"]["NEW"]["pid"]=$this->pageinfo["uid"];
00157 }
00158 } else {
00159 $dmail["sys_dmail"]["NEW"]["subject"] = $createMailFrom;
00160 $dmail["sys_dmail"]["NEW"]["type"] = 1;
00161 $dmail["sys_dmail"]["NEW"]["sendOptions"] = 0;
00162
00163 $dmail["sys_dmail"]["NEW"]["plainParams"] = t3lib_div::_GP("createMailFrom_plainUrl");
00164 $this->params["enablePlain"] = $dmail["sys_dmail"]["NEW"]["plainParams"] ? 1 : 0;
00165
00166 $dmail["sys_dmail"]["NEW"]["HTMLParams"] = t3lib_div::_GP("createMailFrom_HTMLUrl");
00167 $this->params["enableHTML"] = $dmail["sys_dmail"]["NEW"]["HTMLParams"] ? 1 : 0;
00168
00169 $dmail["sys_dmail"]["NEW"]["pid"]=$this->pageinfo["uid"];
00170 }
00171
00172
00173 if (isset($this->params["enablePlain"])) {if ($this->params["enablePlain"]) {$dmail["sys_dmail"]["NEW"]["sendOptions"]|=1;} else {$dmail["sys_dmail"]["NEW"]["sendOptions"]&=254;}}
00174 if (isset($this->params["enableHTML"])) {if ($this->params["enableHTML"]) {$dmail["sys_dmail"]["NEW"]["sendOptions"]|=2;} else {$dmail["sys_dmail"]["NEW"]["sendOptions"]&=253;}}
00175
00176 if ($dmail["sys_dmail"]["NEW"]["pid"]) {
00177 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
00178 $tce->stripslashes_values=0;
00179 $tce->start($dmail,Array());
00180 $tce->process_datamap();
00181
00182 $this->sys_dmail_uid = $tce->substNEWwithIDs["NEW"];
00183 } else {
00184
00185 }
00186 }
00187 }
00188
00189
00190
00191
00192 function main() {
00193
00194 if (t3lib_div::inList($GLOBALS["TYPO3_CONF_VARS"]["FE"]["content_doktypes"],$this->pageinfo["doktype"])) {
00195 if ($this->pageinfo["group_id"]>0 || $this->pageinfo["hidden"]) {
00196 $theOutput.= $GLOBALS["SOBE"]->doc->section($GLOBALS["LANG"]->getLL("dmail_newsletters"),'<span class="typo3-red">'.$GLOBALS["LANG"]->getLL("dmail_noCreateAccess").'</span>',0,1);
00197 } else {
00198 $isNewsletterPage=0;
00199 if (is_array($this->modList["rows"])) {
00200 reset($this->modList["rows"]);
00201 while(list(,$rData)=each($this->modList["rows"])) {
00202 if ($rData["uid"]==$this->pageinfo["pid"]) {
00203 $isNewsletterPage=1;
00204 }
00205 }
00206 }
00207 if ($isNewsletterPage) {
00208 header('Location: index.php?id='.$this->pageinfo["pid"].'&CMD=displayPageInfo&pages_uid='.$this->pageinfo["uid"].'&SET[dmail_mode]=news');
00209 exit;
00210 }
00211 }
00212 } elseif ($this->pageinfo["doktype"]==254 && $this->pageinfo["module"]=="dmail") {
00213 $theOutput.= $this->mailModule_main();
00214 } elseif ($this->id!=0) {
00215 $theOutput.= $GLOBALS["SOBE"]->doc->section($GLOBALS["LANG"]->getLL("dmail_newsletters"),'<span class="typo3-red">'.$GLOBALS["LANG"]->getLL("dmail_noRegular").'</span>',0,1);
00216 }
00217
00218 if ($this->id!=0) {
00219 $theOutput.=$GLOBALS["SOBE"]->doc->spacer(10);
00220 }
00221 return $theOutput;
00222 }
00223 function mailModule_main() {
00224
00225 $menuHTML = t3lib_BEfunc::getFuncMenu($GLOBALS["SOBE"]->id,"SET[dmail_mode]",$GLOBALS["SOBE"]->MOD_SETTINGS["dmail_mode"],$GLOBALS["SOBE"]->MOD_MENU["dmail_mode"]);
00226
00227 $theOutput.=$GLOBALS["SOBE"]->doc->divider(5);
00228 $theOutput.=$GLOBALS["SOBE"]->doc->section("",$menuHTML);
00229
00230 $mode = $GLOBALS["SOBE"]->MOD_SETTINGS["dmail_mode"];
00231
00232 if (!$this->sys_dmail_uid || $mode!="direct") {
00233 $this->makeCategories();
00234
00235
00236 switch($this->CMD) {
00237 case "displayPageInfo":
00238 $theOutput.= $this->cmd_displayPageInfo();
00239 break;
00240 case "displayUserInfo":
00241 $theOutput.= $this->cmd_displayUserInfo();
00242 break;
00243 case "displayMailGroup":
00244 $result = $this->cmd_compileMailGroup(intval(t3lib_div::_GP("group_uid")));
00245 $theOutput.= $this->cmd_displayMailGroup($result);
00246 break;
00247 case "displayImport":
00248 $theOutput.= $this->cmd_displayImport();
00249 break;
00250 default:
00251 $theOutput.= $this->cmd_default($mode);
00252 break;
00253 }
00254 } else {
00255
00256 $this->urlbase = substr(t3lib_div::getIndpEnv("TYPO3_REQUEST_DIR"),0,-(strlen(TYPO3_MOD_PATH)+strlen(TYPO3_mainDir)));
00257 $this->sys_dmail_uid = intval($this->sys_dmail_uid);
00258
00259 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_dmail', 'pid='.intval($this->id).' AND uid='.intval($this->sys_dmail_uid).t3lib_BEfunc::deleteClause('sys_dmail'));
00260
00261 $this->noView = 0;
00262 $this->back = '<input type="Submit" value="< BACK" onClick="jumpToUrlD(\'index.php?id='.$this->id.'&sys_dmail_uid='.$this->sys_dmail_uid.'\'); return false;">';
00263 if($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00264
00265 switch((string)$row["type"]) {
00266 case 1:
00267 $this->url_html = $row["HTMLParams"];
00268 $this->url_plain = $row["plainParams"];
00269 break;
00270 default:
00271 $this->url_html = $this->urlbase."?id=".$row["page"].$row["HTMLParams"];
00272 $this->url_plain = $this->urlbase."?id=".$row["page"].$row["plainParams"];
00273 break;
00274 }
00275 if (!($row["sendOptions"]&1) || !$this->url_plain) {
00276 $this->url_plain="";
00277 } else {
00278 $urlParts = parse_url($this->url_plain);
00279 if (!$urlParts["scheme"]) {
00280 $this->url_plain="http://".$this->url_plain;
00281 }
00282 }
00283 if (!($row["sendOptions"]&2) || !$this->url_html) {
00284 $this->url_html="";
00285 } else {
00286 $urlParts = parse_url($this->url_html);
00287 if (!$urlParts["scheme"]) {
00288 $this->url_html="http://".$this->url_html;
00289 }
00290 }
00291
00292
00293 switch($this->CMD) {
00294 case "fetch":
00295 $theOutput.=$this->cmd_fetch($row);
00296 $row = t3lib_befunc::getRecord("sys_dmail",$row["uid"]);
00297 break;
00298 case "prefetch":
00299 $theOutput.=$this->cmd_prefetch($row);
00300 break;
00301 case "testmail":
00302 $theOutput.=$this->cmd_testmail($row);
00303 break;
00304 case "finalmail":
00305 $theOutput.=$this->cmd_finalmail($row);
00306 break;
00307 case "send_mail_test":
00308 case "send_mail_final":
00309 $theOutput.=$this->cmd_send_mail($row);
00310 break;
00311 case "stats":
00312 $theOutput.=$this->cmd_stats($row);
00313 break;
00314 }
00315 if (!$this->noView) {
00316 $theOutput.=$this->directMail_defaultView($row);
00317 }
00318 }
00319 }
00320 return $theOutput;
00321 }
00322 function makeCategories() {
00323 $this->categories = array();
00324 if (is_array($this->params["categories."])) {
00325 reset($this->params["categories."]);
00326 while(list($pKey,$pVal)=each($this->params["categories."])) {
00327 if (trim($pVal)) {
00328 $catNum = intval($pKey);
00329 if ($catNum>=0 && $catNum<=30) {
00330 $this->categories[$catNum] = $pVal;
00331 }
00332 }
00333 }
00334 }
00335 }
00336
00337
00338
00339
00340 function cmd_displayPageInfo() {
00341 global $TCA, $LANG;
00342
00343
00344 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00345 'uid,pid,subject,tstamp,issent,renderedsize,attachment,type',
00346 'sys_dmail',
00347 'pid='.intval($this->id).' AND type=0 AND page='.intval($this->pages_uid).t3lib_BEfunc::deleteClause('sys_dmail'),
00348 '',
00349 $GLOBALS['TYPO3_DB']->stripOrderBy($TCA['sys_dmail']['ctrl']['default_sortby'])
00350 );
00351 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
00352 $onClick = ' onClick="return confirm('.$GLOBALS['LANG']->JScharCode(sprintf($LANG->getLL("nl_l_warning"),$GLOBALS['TYPO3_DB']->sql_num_rows($res))).');"';
00353 } else {
00354 $onClick = "";
00355 }
00356
00357
00358
00359 $out="";
00360 $out.='<a href="#" onClick="'.t3lib_BEfunc::viewOnClick($this->pages_uid,$GLOBALS["BACK_PATH"]).'"><img src="'.$GLOBALS["BACK_PATH"].'gfx/zoom.gif" width="12" height="12" hspace=3 vspace=2 border="0" align=top>'.$LANG->getLL("nl_viewPage").'</a><BR>';
00361 $out.='<a href="#" onClick="'.t3lib_BEfunc::editOnClick('&edit[pages]['.$this->pages_uid.']=edit&edit_content=1',$GLOBALS["BACK_PATH"],"").'"><img src="'.$GLOBALS["BACK_PATH"].'gfx/edit2.gif" width="11" height="12" hspace=3 vspace=2 border="0" align=top>'.$LANG->getLL("nl_editPage").'</a><BR>';
00362 $out.='<a href="index.php?id='.$this->id.'&createMailFrom='.$this->pages_uid.'&SET[dmail_mode]=direct"'.$onClick.'><img src="'.$GLOBALS["BACK_PATH"].'/gfx/newmail.gif" width="18" height="16" border="0" align=top>'.$LANG->getLL("nl_createDmailFromPage").'</a><BR>';
00363
00364 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
00365 $out.="<BR><b>".$LANG->getLL("nl_alreadyBasedOn").":</b><BR><BR>";
00366 $out.="<table border=0 cellpadding=0 cellspacing=0>";
00367 $out.='<tr>
00368 <td class="bgColor5">'.fw(" ").'</td>
00369 <td class="bgColor5"><b>'.fw($LANG->getLL("nl_l_subject")." ").'</b></td>
00370 <td class="bgColor5"><b>'.fw($LANG->getLL("nl_l_lastM")." ").'</b></td>
00371 <td class="bgColor5"><b>'.fw($LANG->getLL("nl_l_sent")." ").'</b></td>
00372 <td class="bgColor5"><b>'.fw($LANG->getLL("nl_l_size")." ").'</b></td>
00373 <td class="bgColor5"><b>'.fw($LANG->getLL("nl_l_attach")." ").'</b></td>
00374 <td class="bgColor5"><b>'.fw($LANG->getLL("nl_l_type")." ").'</b></td>
00375 </tr>';
00376 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00377 $out.='<tr>
00378 <td><img src="'.$GLOBALS["BACK_PATH"].'gfx/i/mail.gif" width=18 height=16 border=0 align="top"></td>
00379 <td>'.$this->linkDMail_record(fw(t3lib_div::fixed_lgd($row["subject"],30)." "),$row["uid"]).'</td>
00380 <td>'.fw(t3lib_BEfunc::date($row["tstamp"])." ").'</td>
00381 <td>'.($row["issent"] ? fw("YES") : "").'</td>
00382 <td>'.($row["renderedsize"] ? fw(t3lib_div::formatSize($row["renderedsize"])." ") : "").'</td>
00383 <td>'.($row["attachment"] ? '<img src="attach.gif" width=9 height=13>' : "").'</td>
00384 <td>'.fw($row["type"] ? $LANG->getLL("nl_l_tUrl") : $LANG->getLL("nl_l_tPage")).'</td>
00385 </tr>';
00386
00387 }
00388 $out.='</table>';
00389 }
00390
00391 $theOutput.= $GLOBALS["SOBE"]->doc->section($LANG->getLL("nl_info"),$out,0,1);
00392 $theOutput.= $GLOBALS["SOBE"]->doc->divider(20);
00393
00394
00395
00396
00397 if (is_array($_POST["indata"]["categories"])) {
00398 $data=array();
00399 reset($_POST["indata"]["categories"]);
00400 while(list($recUid,$recValues)=each($_POST["indata"]["categories"])) {
00401
00402 reset($recValues);
00403 $data["tt_content"][$recUid]["module_sys_dmail_category"]=0;
00404 while(list($k,$b)=each($recValues)) {
00405 if ($b) {$data["tt_content"][$recUid]["module_sys_dmail_category"]|= pow (2,$k);}
00406 }
00407 }
00408 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
00409 $tce->stripslashes_values=0;
00410 $tce->start($data,Array());
00411 $tce->process_datamap();
00412
00413 }
00414
00415 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00416 'colPos, CType, uid, header, bodytext, module_sys_dmail_category',
00417 'tt_content',
00418 'pid='.intval($this->pages_uid).t3lib_BEfunc::deleteClause('tt_content').' AND NOT hidden',
00419 '',
00420 'colPos,sorting'
00421 );
00422 if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
00423 $theOutput.= $GLOBALS["SOBE"]->doc->section($LANG->getLL("nl_cat"),$LANG->getLL("nl_cat_msg1"));
00424 } else {
00425 $out="";
00426 $colPosVal=99;
00427 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00428 $out.='<tr><td colspan=3><img src="clear.gif" width=1 height=15></td></tr>';
00429 if ($colPosVal!=$row["colPos"]) {
00430 $out.='<tr><td colspan=3 class="bgColor5">'.fw($LANG->getLL("nl_l_column").": <strong>".htmlspecialchars(t3lib_BEfunc::getProcessedValue("tt_content","colPos",$row["colPos"]))."</strong>").'</td></tr>';
00431 $colPosVal=$row["colPos"];
00432 }
00433 $out.='<tr>';
00434 $out.='<td valign=top width=75%>'.fw('<img src="'.$GLOBALS["BACK_PATH"].t3lib_iconWorks::getIcon("tt_content",$row).'" width=18 height=16 border=0 title="'.htmlspecialchars(t3lib_BEfunc::getProcessedValue("tt_content","CType",$row["CType"])).'" align=top> '.
00435 $row["header"].'<BR>'.t3lib_div::fixed_lgd(strip_tags($row["bodytext"]),200).'<BR>').'</td>';
00436
00437 $out.='<td> </td><td nowrap valign=top>';
00438 $out_check="";
00439 if ($row["module_sys_dmail_category"]) {
00440 $out_check.='<font color=red><strong>'.$LANG->getLL("nl_l_ONLY").'</strong></font>';
00441 } else {
00442 $out_check.='<font color=green><strong>'.$LANG->getLL("nl_l_ALL").'</strong></font>';
00443 }
00444 $out_check.="<BR>";
00445 reset($this->categories);
00446 while(list($pKey,$pVal)=each($this->categories)) {
00447 $out_check.='<input type="hidden" name="indata[categories]['.$row["uid"].']['.$pKey.']" value="0"><input type="checkbox" name="indata[categories]['.$row["uid"].']['.$pKey.']" value="1"'.(($row["module_sys_dmail_category"]&pow (2,$pKey)) ?" checked":"").'> '.$pVal.'<BR>';
00448 }
00449 $out.=fw($out_check).'</td></tr>';
00450 }
00451 $out='<table border=0 cellpadding=0 cellspacing=0>'.$out.'</table>';
00452 $out.='<input type="hidden" name="pages_uid" value="'.$this->pages_uid.'"><input type="hidden" name="CMD" value="'.$this->CMD.'"><BR><input type="submit" value="'.$LANG->getLL("nl_l_update").'">';
00453 $theOutput.= $GLOBALS["SOBE"]->doc->section($LANG->getLL("nl_cat"),$LANG->getLL("nl_cat_msg2")."<BR><BR>".$out);
00454 }
00455 return $theOutput;
00456 }
00457 function getCsvValues($str,$sep=",") {
00458 $fh=tmpfile();
00459 fwrite ($fh, trim($str));
00460 fseek ($fh,0);
00461 $lines=array();
00462 while ($data = fgetcsv ($fh, 1000, $sep)) {
00463 $lines[]=$data;
00464 }
00465 return $lines;
00466 }
00467 function rearrangeCsvValues($lines) {
00468 $out=array();
00469 if (is_array($lines) && count($lines)>0) {
00470
00471
00472
00473 $first = $lines[0];
00474 $fieldListArr = explode(",",$this->fieldList);
00475
00476 reset($first);
00477 $fieldName=1;
00478 $fieldOrder=array();
00479 while(list(,$v)=each($first)) {
00480 list($fName,$fConf) = split("\[|\]",$v);
00481 $fName =trim($fName);
00482 $fConf =trim($fConf);
00483
00484 $fieldOrder[]=array($fName,$fConf);
00485 if ($fName && substr($fName,0,5)!="user_" && !in_array($fName,$fieldListArr)) {$fieldName=0; break;}
00486 }
00487
00488 if (!$fieldName) {
00489 $fieldOrder = array(array("name"),array("email"));
00490 }
00491
00492
00493
00494
00495 reset($lines);
00496 if ($fieldName) {
00497 next($lines);
00498 }
00499 $c=0;
00500 while(list(,$data)=each($lines)) {
00501 if (count($data)>1 || $data[0]) {
00502
00503
00504 reset($fieldOrder);
00505 while(list($kk,$fN)=each($fieldOrder)) {
00506 if ($fN[0]) {
00507 if ($fN[1]) {
00508 if (trim($data[$kk])) {
00509 if (substr($fN[1],0,1)=="=") {
00510 $out[$c][$fN[0]]=trim(substr($fN[1],1));
00511 } elseif (substr($fN[1],0,1)=="+") {
00512 $out[$c][$fN[0]]+=substr($fN[1],1);
00513 }
00514 }
00515 } else {
00516 $out[$c][$fN[0]]=$data[$kk];
00517 }
00518 }
00519 }
00520 $c++;
00521 }
00522 }
00523 }
00524 return $out;
00525 }
00526 function rearrangePlainMails($plainMails) {
00527 $out=array();
00528 if (is_array($plainMails)) {
00529 reset($plainMails);
00530 $c=0;
00531 while(list(,$v)=each($plainMails)) {
00532 $out[$c]["email"]=$v;
00533 $out[$c]["name"]="";
00534 $c++;
00535 }
00536 }
00537 return $out;
00538 }
00539 function makePidListQuery($table,$pidList,$fields,$cat) {
00540 $cat = intval($cat);
00541 if ($cat>0) {
00542 $addQ = ' AND module_sys_dmail_category&'.$cat.' > 0';
00543 } else {
00544 $addQ = '';
00545 }
00546
00547 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
00548 $fields,
00549 $table,
00550 'pid IN ('.$pidList.')'.
00551 $addQ.
00552 t3lib_BEfunc::deleteClause($table).
00553 t3lib_pageSelect::enableFields($table)
00554 );
00555
00556 return $query;
00557 }
00558 function getIdList($table,$pidList,$cat) {
00559 $query = $this->makePidListQuery($table,$pidList,"uid",$cat);
00560 $res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db,$query);
00561 $outArr = array();
00562 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00563 $outArr[] = $row["uid"];
00564 }
00565 return $outArr;
00566 }
00567 function makeStaticListQuery($table,$uid,$fields) {
00568 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
00569 $fields,
00570 $table.',sys_dmail_group,sys_dmail_group_mm',
00571 'sys_dmail_group_mm.uid_local=sys_dmail_group.uid AND
00572 sys_dmail_group_mm.uid_foreign='.$table.'.uid AND sys_dmail_group_mm.tablenames="'.$table.'"'.
00573 t3lib_pageSelect::enableFields($table).
00574 t3lib_pageSelect::enableFields("sys_dmail_group")
00575 );
00576 return $query;
00577 }
00578 function getStaticIdList($table,$uid) {
00579 $query = $this->makeStaticListQuery($table,$uid,$table.".uid");
00580 $res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db,$query);
00581 $outArr=array();
00582 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00583 $outArr[]=$row["uid"];
00584 }
00585 return $outArr;
00586 }
00587 function getMailGroups($list,$parsedGroups) {
00588 $groupIdList = t3lib_div::intExplode(",",$list);
00589 $groups = array();
00590
00591 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('sys_dmail_group.*', 'sys_dmail_group,pages', '
00592 sys_dmail_group.uid IN ('.implode(',',$groupIdList).')
00593 AND pages.uid=sys_dmail_group.pid
00594 AND '.$this->perms_clause.
00595 t3lib_BEfunc::deleteClause('pages').
00596
00597
00598 t3lib_pageSelect::enableFields('sys_dmail_group'));
00599
00600 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00601 if ($row["type"]==4) {
00602 if (!in_array($row["uid"],$parsedGroups)) {
00603 $parsedGroups[]=$row["uid"];
00604 $groups=array_merge($groups,$this->getMailGroups($row["mail_groups"],$parsedGroups));
00605 }
00606 } else {
00607 $groups[]=$row["uid"];
00608 }
00609 }
00610 return $groups;
00611 }
00612 function cmd_displayMailGroup($result) {
00613 $count=0;
00614 $idLists = $result["queryInfo"]["id_lists"];
00615 if (is_array($idLists["tt_address"])) $count+=count($idLists["tt_address"]);
00616 if (is_array($idLists["fe_users"])) $count+=count($idLists["fe_users"]);
00617 if (is_array($idLists["PLAINLIST"])) $count+=count($idLists["PLAINLIST"]);
00618 if (is_array($idLists[$this->userTable])) $count+=count($idLists[$this->userTable]);
00619
00620 $group = t3lib_befunc::getRecord("sys_dmail_group",t3lib_div::_GP("group_uid"));
00621 $out=t3lib_iconWorks::getIconImage("sys_dmail_group",$group,$GLOBALS["BACK_PATH"],'align="top"').$group["title"]."<BR>";
00622
00623 $lCmd=t3lib_div::_GP("lCmd");
00624
00625 $mainC = $out."Total number of recipients: <strong>".$count."</strong>";
00626 if (!$lCmd) {
00627 $mainC.= '<BR>';
00628 $mainC.= '<BR>';
00629 $mainC.= '<a href="'.t3lib_div::linkThisScript(array("lCmd"=>"listall")).'">List all recipients</a>';
00630 }
00631
00632 $theOutput.= $GLOBALS["SOBE"]->doc->section("Recipients from group:",$mainC);
00633 $theOutput.= $GLOBALS["SOBE"]->doc->spacer(20);
00634
00635 switch($lCmd) {
00636 case "listall":
00637 $theOutput.= $GLOBALS["SOBE"]->doc->section("ADDRESS TABLE",$this->getRecordList($this->fetchRecordsListValues($idLists["tt_address"],"tt_address"),"tt_address"));
00638 $theOutput.= $GLOBALS["SOBE"]->doc->spacer(20);
00639 $theOutput.= $GLOBALS["SOBE"]->doc->section("WEBSITE USERS TABLE",$this->getRecordList($this->fetchRecordsListValues($idLists["fe_users"],"fe_users"),"fe_users"));
00640 $theOutput.= $GLOBALS["SOBE"]->doc->spacer(20);
00641 $theOutput.= $GLOBALS["SOBE"]->doc->section("PLAIN LIST",$this->getRecordList($idLists["PLAINLIST"],"default",1));
00642 $theOutput.= $GLOBALS["SOBE"]->doc->spacer(20);
00643 $theOutput.= $GLOBALS["SOBE"]->doc->section($this->userTable." TABLE",$this->getRecordList($this->fetchRecordsListValues($idLists[$this->userTable],$this->userTable),$this->userTable));
00644 break;
00645 default:
00646 if (t3lib_div::_GP("csv")) {
00647 $csvValue=t3lib_div::_GP("csv");
00648 if ($csvValue=="PLAINLIST") {
00649 $this->downloadCSV($idLists["PLAINLIST"]);
00650 } elseif (t3lib_div::inList("tt_address,fe_users,".$this->userTable, $csvValue)) {
00651 $this->downloadCSV($this->fetchRecordsListValues($idLists[$csvValue],$csvValue,$this->fieldList.",tstamp"));
00652 }
00653 } else {
00654 $theOutput.= $GLOBALS["SOBE"]->doc->section("ADDRESS TABLE","Recipients: ".(is_array($idLists["tt_address"])?count($idLists["tt_address"]):0).'<BR><a href="'.t3lib_div::linkThisScript(array("csv"=>"tt_address")).'">Download CSV file</a>');
00655 $theOutput.= $GLOBALS["SOBE"]->doc->spacer(20);
00656 $theOutput.= $GLOBALS["SOBE"]->doc->section("WEBSITE USERS TABLE","Recipients: ".(is_array($idLists["fe_users"])?count($idLists["fe_users"]):0).'<BR><a href="'.t3lib_div::linkThisScript(array("csv"=>"fe_users")).'">Download CSV file</a>');
00657 $theOutput.= $GLOBALS["SOBE"]->doc->spacer(20);
00658 $theOutput.= $GLOBALS["SOBE"]->doc->section("PLAIN LIST","Recipients: ".(is_array($idLists["PLAINLIST"])?count($idLists["PLAINLIST"]):0).'<BR><a href="'.t3lib_div::linkThisScript(array("csv"=>"PLAINLIST")).'">Download CSV file</a>');
00659 $theOutput.= $GLOBALS["SOBE"]->doc->spacer(20);
00660 $theOutput.= $GLOBALS["SOBE"]->doc->section($this->userTable." TABLE","Recipients: ".(is_array($idLists[$this->userTable])?count($idLists[$this->userTable]):0).'<BR><a href="'.t3lib_div::linkThisScript(array("csv"=>$this->userTable)).'">Download CSV file</a>');
00661 }
00662 break;
00663 }
00664 return $theOutput;
00665 }
00666 function downloadCSV($idArr) {
00667 $lines=array();
00668 #debug($idArr);
00669 if (is_array($idArr) && count($idArr)) {
00670 reset($idArr);
00671 $lines[]=t3lib_div::csvValues(array_keys(current($idArr)),",","");
00672
00673 reset($idArr);
00674 while(list($i,$rec)=each($idArr)) {
00675
00676 $lines[]=t3lib_div::csvValues($rec);
00677 }
00678 }
00679
00680 $filename="DirectMail_export_".date("dmy-Hi").".csv";
00681 $mimeType = "application/octet-stream";
00682 Header("Content-Type: ".$mimeType);
00683 Header("Content-Disposition: attachment; filename=".$filename);
00684 echo implode(chr(13).chr(10),$lines);
00685 exit;
00686 }
00687 function cmd_displayMailGroup_test($result) {
00688 $count=0;
00689 $idLists = $result["queryInfo"]["id_lists"];
00690 $out="";
00691 if (is_array($idLists["tt_address"])) {$out.=$this->getRecordList($this->fetchRecordsListValues($idLists["tt_address"],"tt_address"),"tt_address");}
00692 if (is_array($idLists["fe_users"])) {$out.=$this->getRecordList($this->fetchRecordsListValues($idLists["fe_users"],"fe_users"),"fe_users");}
00693 if (is_array($idLists["PLAINLIST"])) {$out.=$this->getRecordList($idLists["PLAINLIST"],"default",1);}
00694 if (is_array($idLists[$this->userTable])) {$out.=$this->getRecordList($this->fetchRecordsListValues($idLists[$this->userTable],$this->userTable),$this->userTable);}
00695
00696 return $out;
00697 }
00698 function cmd_compileMailGroup($group_uid,$makeIdLists=1) {
00699
00700 $queries=array();
00701 $id_lists=array();
00702 if ($group_uid) {
00703 $mailGroup=t3lib_BEfunc::getRecord("sys_dmail_group",$group_uid);
00704 if (is_array($mailGroup) && $mailGroup["pid"]==$this->id) {
00705 $head = '<img src="'.$GLOBALS["BACK_PATH"].t3lib_iconWorks::getIcon("sys_dmail_group").'" width=18 height=16 border=0 align="top">'.t3lib_div::fixed_lgd($mailGroup["title"],30)."<BR>";
00706 $theOutput.=$head;
00707 switch($mailGroup["type"]) {
00708 case 0:
00709 $thePages = $mailGroup["pages"] ? $mailGroup["pages"] : $this->id;
00710 $pages = t3lib_div::intExplode(",",$thePages);
00711 reset($pages);
00712 $pageIdArray=array();
00713 while(list(,$pageUid)=each($pages)) {
00714 if ($pageUid>0) {
00715 $pageinfo = t3lib_BEfunc::readPageAccess($pageUid,$this->perms_clause);
00716 if (is_array($pageinfo)) {
00717 $info["fromPages"][]=$pageinfo;
00718 $pageIdArray[]=$pageUid;
00719 if ($mailGroup["recursive"]) {
00720 $pageIdArray=array_merge($pageIdArray,$GLOBALS["SOBE"]->getRecursiveSelect($pageUid,$this->perms_clause));
00721 }
00722 }
00723 }
00724
00725 }
00726
00727 $pageIdArray=array_unique($pageIdArray);
00728 $pidList = implode(",",$pageIdArray);
00729 $info["recursive"]=$mailGroup["recursive"];
00730
00731
00732
00733 if ($pidList) {
00734 $whichTables = intval($mailGroup["whichtables"]);
00735 if ($whichTables&1) {
00736 $queries["tt_address"]=$this->makePidListQuery("tt_address",$pidList,"*",$mailGroup["select_categories"]);
00737 if ($makeIdLists) $id_lists["tt_address"]=$this->getIdList("tt_address",$pidList,$mailGroup["select_categories"]);
00738 }
00739 if ($whichTables&2) {
00740 $queries["fe_users"]=$this->makePidListQuery("fe_users",$pidList,"*",$mailGroup["select_categories"]);
00741 if ($makeIdLists) $id_lists["fe_users"]=$this->getIdList("fe_users",$pidList,$mailGroup["select_categories"]);
00742 }
00743 if ($this->userTable && ($whichTables&4)) {
00744 $queries[$this->userTable]=$this->makePidListQuery($this->userTable,$pidList,"*",$mailGroup["select_categories"]);
00745 if ($makeIdLists) $id_lists[$this->userTable]=$this->getIdList($this->userTable,$pidList,$mailGroup["select_categories"]);
00746 }
00747 }
00748
00749
00750 break;
00751 case 1:
00752 if ($mailGroup["csv"]==1) {
00753 $recipients = $this->rearrangeCsvValues($this->getCsvValues($mailGroup["list"]));
00754
00755 } else {
00756 $recipients = $this->rearrangePlainMails(array_unique(split("[[:space:],;]+",$mailGroup["list"])));
00757
00758 }
00759 $id_lists["PLAINLIST"] = $this->cleanPlainList($recipients);
00760
00761 break;
00762 case 2:
00763 $queries["tt_address"] = $this->makeStaticListQuery("tt_address",$group_uid,"tt_address.*");
00764 if ($makeIdLists) $id_lists["tt_address"] = $this->getStaticIdList("tt_address",$group_uid);
00765 $queries["fe_users"] = $this->makeStaticListQuery("fe_users",$group_uid,"fe_users.*");
00766 if ($makeIdLists) $id_lists["fe_users"] = $this->getStaticIdList("fe_users",$group_uid);
00767 if ($this->userTable) {
00768 $queries[$this->userTable] = $this->makeStaticListQuery($this->userTable,$group_uid,$this->userTable."*");
00769 if ($makeIdLists) $id_lists[$this->userTable] = $this->getStaticIdList($this->userTable,$group_uid);
00770 }
00771
00772
00773 break;
00774 case 3:
00775
00776 $theOutput.=$GLOBALS["SOBE"]->doc->section("Special Query","UNDER CONSTRUCTION...");
00777 break;
00778 case 4:
00779 $groups = array_unique($this->getMailGroups($mailGroup["mail_groups"],array($mailGroup["uid"])));
00780 reset($groups);
00781 $queries=array();
00782 $id_lists=array();
00783 while(list(,$v)=each($groups)) {
00784 $collect=$this->cmd_compileMailGroup($v);
00785 if (is_array($collect["queryInfo"]["queries"])) {
00786 $queries=t3lib_div::array_merge_recursive_overrule($queries,$collect["queryInfo"]["queries"]);
00787 }
00788 if (is_array($collect["queryInfo"]["id_lists"])) {
00789 $id_lists=t3lib_div::array_merge_recursive_overrule($id_lists,$collect["queryInfo"]["id_lists"]);
00790 }
00791 }
00792
00793 if (is_array($id_lists["tt_address"])) $id_lists["tt_address"] = array_unique($id_lists["tt_address"]);
00794 if (is_array($id_lists["fe_users"])) $id_lists["fe_users"] = array_unique($id_lists["fe_users"]);
00795 if (is_array($id_lists[$this->userTable]) && $this->userTable) $id_lists[$this->userTable] = array_unique($id_lists[$this->userTable]);
00796 if (is_array($id_lists["PLAINLIST"])) {$id_lists["PLAINLIST"] = $this->cleanPlainList($id_lists["PLAINLIST"]);}
00797
00798
00799
00800
00801
00802 break;
00803 }
00804
00805 }
00806 }
00807 $outputArray=array(
00808 "code"=>$theOutput,
00809 "queryInfo" => array("id_lists"=>$id_lists, "queries"=>$queries)
00810 );
00811 return $outputArray;
00812 }
00813 function cleanPlainList($plainlist) {
00814 reset($plainlist);
00815 $emails=array();
00816 while(list($k,$v)=each($plainlist)) {
00817 if (in_array($v["email"],$emails)) { unset($plainlist[$k]); }
00818 $emails[]=$v["email"];
00819 }
00820 return $plainlist;
00821 }
00822 function cmd_query($dgUid) {
00823 $GLOBALS["SOBE"]->MOD_SETTINGS=array();
00824 $GLOBALS["SOBE"]->MOD_SETTINGS["dmail_queryConfig"]=serialize($_POST["dmail_queryConfig"]);
00825 $GLOBALS["SOBE"]->MOD_SETTINGS["dmail_queryTable"]=$_POST["SET"]["dmail_queryTable"];
00826 $GLOBALS["SOBE"]->MOD_SETTINGS["dmail_search_query_smallparts"]=1;
00827
00828 $qGen = t3lib_div::makeInstance("mailSelect");
00829 $qGen->init("queryConfig",$GLOBALS["SOBE"]->MOD_SETTINGS["queryTable"]);
00830 $qGen->noWrap="";
00831 if ($this->userTable) $qGen->allowedTables[]=$this->userTable;
00832 $tmpCode=$qGen->makeSelectorTable($GLOBALS["SOBE"]->MOD_SETTINGS,"table,query");
00833 $tmpCode.='<input type="hidden" name="CMD" value="displayMailGroup"><input type="hidden" name="group_uid" value="'.$dgUid.'">';
00834 $theOutput.=$GLOBALS["SOBE"]->doc->section("Make Query",$tmpCode);
00835
00836
00837
00838
00839
00840 $out = $qGen->getQuery($qGen->queryConfig);
00841 $theOutput.=$GLOBALS["SOBE"]->doc->section("QUERY",$out);
00842
00843 return $theOutput;
00844 }
00845 function importRecords_sort($records,$syncSelect,$tstampFlag) {
00846 reset($records);
00847 $kinds=array();
00848 while(list(,$recdata)=each($records)) {
00849 if ($syncSelect && !t3lib_div::testInt($syncSelect)) {
00850 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,tstamp', 'tt_address', 'pid='.intval($this->id).' AND '.$syncSelect.'="'.$GLOBALS['TYPO3_DB']->quoteStr($recdata[$syncSelect], 'tt_address').'"'.t3lib_befunc::deleteClause('tt_address'), '', '', '1');
00851 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00852 if ($tstampFlag) {
00853 if ($row["tstamp"]>intval($recdata["tstamp"])) {
00854 $kinds["newer_version_detected"][]=$recdata;
00855 } else {$kinds["update"][$row["uid"]]=$recdata;}
00856 } else {$kinds["update"][$row["uid"]]=$recdata;}
00857 } else {$kinds["insert"][]=$recdata;}
00858 } else {$kinds["insert"][]=$recdata;}
00859 }
00860 return $kinds;
00861 }
00862 function importRecords($categorizedRecords,$removeExisting) {
00863 $cmd = array();
00864 $data = array();
00865 if ($removeExisting) {
00866 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tt_address', 'pid='.intval($this->id).t3lib_BEfunc::deleteClause('tt_address'));
00867 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00868 $cmd["tt_address"][$row["uid"]]["delete"] = 1;
00869 }
00870 }
00871 if (is_array($categorizedRecords["insert"])) {
00872 reset($categorizedRecords["insert"]);
00873 $c=0;
00874 while(list(,$rec)=each($categorizedRecords["insert"])) {
00875 $c++;
00876 $data["tt_address"]["NEW".$c] = $rec;
00877 $data["tt_address"]["NEW".$c]["pid"] = $this->id;
00878 }
00879 }
00880 if (is_array($categorizedRecords["update"])) {
00881 reset($categorizedRecords["update"]);
00882 $c=0;
00883 while(list($rUid,$rec)=each($categorizedRecords["update"])) {
00884 $c++;
00885 $data["tt_address"][$rUid]=$rec;
00886 }
00887 }
00888
00889 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
00890 $tce->stripslashes_values=0;
00891 $tce->enableLogging=0;
00892 $tce->start(