PageRenderTime 53ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/phplist/admin/send_core.php

https://github.com/radicaldesigns/amp
PHP | 1510 lines | 1186 code | 147 blank | 177 comment | 285 complexity | 5b352982b37fa45b2b3de5fa165bacee MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // 2004-1-7 This function really isn't quite ready for register globals.
  3. require_once dirname(__FILE__).'/accesscheck.php';
  4. #initialisation###############
  5. // Verify that FCKeditor is available
  6. if (USEFCK && file_exists("./FCKeditor/fckeditor.php")) {
  7. include("./FCKeditor/fckeditor.php") ;
  8. // Create the editor object here so we can check to see if *it* wants us to use it (this
  9. // does a browser check, etc.
  10. $oFCKeditor = new FCKeditor('message') ;
  11. $usefck = $oFCKeditor->IsCompatible();
  12. unset($oFCKeditor); // This object is *very* short-lived. Thankfully, it's also light-weight
  13. } else {
  14. $usefck = 0;
  15. }
  16. // Verify that TinyMCE is available
  17. $useTinyMCE = 0;
  18. if (USETINYMCEMESG && file_exists(TINYMCEPATH)) {
  19. $useTinyMCE = 1;
  20. }
  21. include $GLOBALS["coderoot"] . "date.php";
  22. $errormsg = '';
  23. $rss_content = '';
  24. $done = 0;
  25. $messageid = 0;
  26. $embargo = new date("embargo");
  27. $embargo->useTime = true;
  28. $repeatuntil = new date("repeatuntil");
  29. $repeatuntil->useTime = true;
  30. if (empty($_GET['id'])) {
  31. $_GET['id'] = '';
  32. }
  33. $baseurl = PageURL2($_GET["page"].'&id='.$_GET["id"]);
  34. echo '<script language="Javascript" src="js/jslib.js" type="text/javascript"></script><hr><p>';
  35. // load some variables in a register globals-safe fashion
  36. if (isset($_POST['send'])) {
  37. $send = $_POST["send"]; // Only get this from the POST variable (not session or anywhere else)
  38. } else {
  39. $send = '';
  40. }
  41. if (isset($_POST['prepare'])) {
  42. $prepare = $_POST["prepare"];
  43. } else {
  44. $prepage = '';
  45. }
  46. if (isset($_GET['id'])) {
  47. $id = sprintf('%d',$_GET["id"]); // Only get this from the GET variable
  48. } else {
  49. $id = 0;
  50. }
  51. if (isset($_POST['save'])) {
  52. $save = $_POST["save"]; // Save button pressed?
  53. } else {
  54. $save = '';
  55. }
  56. if (isset($_POST['sendtest'])) {
  57. $sendtest = $_POST["sendtest"];
  58. } else {
  59. $sendtest = '';
  60. }
  61. if (!isset($_GET['tab'])) $_GET['tab'] = '';
  62. if (!$id) {
  63. $defaulttemplate = getConfig('defaultmessagetemplate');
  64. Sql_Query(sprintf('insert into %s (subject,status,entered,sendformat,embargo,repeatuntil,owner,template)
  65. values("(no subject)","draft",now(),"text and HTML",now(),now(),%d,%d)',$GLOBALS["tables"]["message"],$_SESSION["logindetails"]["id"],$defaulttemplate));
  66. $id = Sql_Insert_id();
  67. Redirect($_GET["page"]."&id=$id");
  68. exit;
  69. }
  70. if (isset($_GET['deleterule']) && $_GET["deleterule"]) {
  71. Sql_Query(sprintf('delete from %s where name = "criterion%d" and id = %d',$GLOBALS["tables"]["messagedata"],$_GET["deleterule"],$_GET["id"]));
  72. Redirect($_GET["page"]."&id=$id&tab=".$_GET["tab"]);
  73. }
  74. ob_end_flush();
  75. #load database data###########################
  76. // If we were passed an ID in the get, and we *weren't* posted a send, then
  77. // initialize the variables from the database.
  78. #if (((!$send) && (!$save) && (!$sendtest)) && ($id)) {
  79. if ($id) {
  80. // Load message attributes / values
  81. require $GLOBALS["coderoot"] . "structure.php"; // This gets the database structures into DBStruct
  82. $result = Sql_query("SELECT * FROM {$tables["message"]} where id = $id $ownership");
  83. if (!Sql_Affected_Rows()) {
  84. print $GLOBALS['I18N']->get("noaccess");
  85. $done = 1;
  86. return;
  87. }
  88. while ($msg = Sql_fetch_array($result)) {
  89. foreach ($DBstruct["message"] as $field => $rec) {
  90. if (!isset($_POST[$field])) {
  91. # print "Db: $field = $msg[$field]<br/>";
  92. $_POST[$field] = $msg[$field];
  93. }
  94. }
  95. }
  96. if (!isset($_POST['targetlist']) || !is_array($_POST["targetlist"])) {
  97. $_POST["targetlist"] = array();
  98. // Load lists that were targetted with message...
  99. $result = Sql_Query("select $tables[list].name,$tables[list].id from $tables[listmessage],$tables[list] where $tables[listmessage].messageid = $id and $tables[listmessage].listid = $tables[list].id");
  100. while ($lst = Sql_fetch_array($result)) {
  101. $_POST["targetlist"][$lst["id"]] = 1;
  102. }
  103. }
  104. // A bit of additional cleanup
  105. if (!isset($_POST["from"]))
  106. $_POST["from"] = $_POST["fromfield"]; // Database field name doesn't match form fieldname...
  107. if (!isset($_POST["msgsubject"])) {
  108. $_POST["msgsubject"] = $_POST["subject"];
  109. } else {
  110. $_POST['subject'] = $_POST['msgsubject'];
  111. }
  112. if ((!isset($_POST["year"]) || !is_array($_POST["year"])) && $_POST["embargo"] && $_POST["embargo"] != "0000-00-00 00:00:00") {
  113. $embargo->setDateTime($_POST["embargo"]);
  114. }
  115. if ((!isset($_POST["year"]) || !is_array($_POST["year"])) && $_POST["repeatuntil"] && $_POST["repeatuntil"] != "0000-00-00 00:00:00") {
  116. $repeatuntil->setDateTime($_POST["repeatuntil"]);
  117. }
  118. # not sure why this is here, but it breaks things when tables are used in the
  119. # message, so for now disable it.
  120. if (0) {#$usefck) {
  121. $_POST["message"] = nl2br($_POST["message"]);
  122. }
  123. // Load the criteria settings...
  124. }
  125. // If we've got magic quotes on, then we need to get rid of the slashes - either
  126. // from the database or from the previous $_POST
  127. #if (get_magic_quotes_gpc()) {
  128. $_POST["msgsubject"] = stripslashes($_POST["msgsubject"]);
  129. $_POST["from"] = stripslashes($_POST["from"]);
  130. $_POST["tofield"] = stripslashes($_POST["tofield"]);
  131. $_POST["replyto"] = stripslashes($_POST["replyto"]);
  132. $_POST["message"] = stripslashes($_POST["message"]);
  133. $_POST["textmessage"] = stripslashes($_POST["textmessage"]);
  134. $_POST["footer"] = stripslashes($_POST["footer"]);
  135. #}
  136. #input checking#######################
  137. # check the criterias, one attribute can only exist once
  138. if ($send) {
  139. $used_attributes = array();
  140. for ($i=1;$i<=NUMCRITERIAS;$i++) {
  141. if (isset($_POST["use"][$i])) {
  142. $attribute = $_POST["criteria"][$i];
  143. if (!in_array($attribute,$used_attributes))
  144. array_push($used_attributes,$attribute);
  145. else
  146. $duplicate_attribute = 1;
  147. }
  148. }
  149. }
  150. if (!isset($id)) { $id = $_POST["id"]; }; // Pull in the id value from the post if it wasnt in the get
  151. #if ($_POST["htmlformatted"] == "auto")
  152. $htmlformatted = strip_tags($_POST["message"]) != $_POST["message"];
  153. #else
  154. # $htmlformatted = $_POST["htmlformatted"];
  155. # sanitise the header fields, what else do we need to check on?
  156. if (preg_match("/\n|\r/",$_POST["from"])) {
  157. $from = "";
  158. } else {
  159. $from = $_POST["from"];
  160. }
  161. if (preg_match("/\n|\r/",$_POST["msgsubject"])) {
  162. $subject = "";
  163. } else {
  164. $subject = $_POST["msgsubject"];
  165. }
  166. $message = $_POST["message"];
  167. // If the variable isn't filled in, then the input fields don't default to the
  168. // values selected. Need to fill it in so a post will correctly display.
  169. if ((isset($_POST['year']) && is_array($_POST["year"])) || $_POST["embargo"] || $_POST["embargo"] == "0000-00-00 00:00:00") {
  170. $_POST["embargo"] = $embargo->getDate() ." ".$embargo->getTime().':00';
  171. }
  172. if ((isset($_POST['year']) && is_array($_POST["year"])) || !$_POST["repeatuntil"] || $_POST["repeatuntil"] == "0000-00-00 00:00:00") {
  173. $_POST["repeatuntil"] = $repeatuntil->getDate() ." ".$repeatuntil->getTime().':00';
  174. }
  175. if (!isset($_SESSION["fckeditor_height"])) {
  176. $_SESSION["fckeditor_height"] = getConfig("fckeditor_height");
  177. }
  178. if (isset($_POST['expand']) && $_POST["expand"]) {
  179. // request to expand editor area
  180. // $defaultheight = getConfig("fckeditor_height");
  181. // SaveConfig("fckeditor_height",$curheight+100,1);
  182. $_SESSION["fckeditor_height"] += 100;
  183. }
  184. if (isset($_REQUEST['prepare'])) {
  185. $prepare = $_REQUEST['prepare'];
  186. } else {
  187. $prepare = '';
  188. }
  189. #actions and store in database#######################
  190. if ($send || $sendtest || $prepare || $save) {
  191. if ($save || $sendtest) {
  192. // We're just saving, not sending.
  193. if (!isset($_POST['status']) || $_POST["status"] == "") {
  194. // No status - move to draft state
  195. $status = "draft";
  196. } else {
  197. // Keep the status the same
  198. $status = $_POST["status"];
  199. }
  200. } elseif ($send) {
  201. // We're sending - change state to "send-it" status!
  202. if (is_array($_POST["targetlist"]) && sizeof($_POST["targetlist"]) && $subject && $from && $message && !$duplicate_attribute) {
  203. $status = "submitted";
  204. } else {
  205. if (USE_PREPARE) {
  206. $status = "prepared";
  207. } else {
  208. $status = "draft";
  209. }
  210. }
  211. }
  212. if (ENABLE_RSS && $_POST["rsstemplate"]) {
  213. # mark previous RSS templates with this frequency and owner as sent
  214. # this should actually be much more complex than this:
  215. # templates should be allowed by list and therefore a subset of lists, but
  216. # for now we leave it like this
  217. # the trouble is that this may duplicate RSS messages to users, because
  218. # it can cause multiple template for lists. The user_rss should handle that, but it is
  219. # not guaranteed which message will be used.
  220. # Sql_Query(sprintf('update %s set status = "sent" where rsstemplate = "%s" and owner = %d',
  221. # $tables["message"],$_POST["rsstemplate"],$_SESSION["logindetails"]["id"]));
  222. # with RSS message we enforce repeat
  223. switch ($_POST["rsstemplate"]) {
  224. case "weekly": $_POST["repeatinterval"] = 10080; break;
  225. case "monthly": $_POST["repeatinterval"] = 40320; break;
  226. case "daily":
  227. default: $_POST["repeatinterval"] = 1440; break;
  228. }
  229. $_POST["repeatuntil"] = date("Y-m-d H:i:00",mktime(0,0,0,date("m"),date("d"),date("Y")+1));
  230. }
  231. if (!$htmlformatted && strip_tags($_POST["message"]) != $_POST["message"])
  232. $errormsg = '<span class="error">'.$GLOBALS['I18N']->get("htmlusedwarning").'</span>';
  233. $query = sprintf('update %s set '.
  234. 'subject = "%s", '.
  235. 'fromfield = "%s", '.
  236. 'tofield = "%s", '.
  237. 'replyto = "%s", '.
  238. 'embargo = "%s", '.
  239. 'repeatinterval = %d, '.
  240. 'repeatuntil = "%s", '.
  241. 'message = "%s", '.
  242. 'textmessage = "%s", '.
  243. 'footer = "%s", '.
  244. 'status = "%s", '.
  245. 'htmlformatted = %d, '.
  246. 'sendformat = "%s", '.
  247. 'template = %d, '.
  248. 'rsstemplate = "%s" '.
  249. 'where id = %d',
  250. $tables["message"],
  251. addslashes($subject),
  252. addslashes($from),
  253. addslashes($_POST["tofield"]),
  254. addslashes($_POST["replyto"]),
  255. $_POST["embargo"],
  256. $_POST["repeatinterval"],
  257. $_POST["repeatuntil"],
  258. addslashes($_POST["message"]),
  259. addslashes($_POST["textmessage"]),
  260. addslashes($_POST["footer"]),
  261. $status,
  262. $htmlformatted,
  263. $_POST["sendformat"],
  264. $_POST["template"],
  265. $_POST["rsstemplate"],
  266. $id);
  267. # print $query;
  268. $result = Sql_query($query);
  269. $messageid = $id;
  270. # print "Message ID: $id";
  271. # exit;
  272. if (!$GLOBALS["has_pear_http_request"] && preg_match("/\[URL:/i",$_POST["message"])) {
  273. print Warn($GLOBALS['I18N']->get('warnnopearhttprequest'));
  274. }
  275. // More "Insert only" stuff here (no need to change it on an edit!)
  276. if (isset($_POST["targetlist"]) && is_array($_POST["targetlist"])) {
  277. Sql_query("delete from {$tables["listmessage"]} where messageid = $messageid");
  278. if (isset($_POST["targetlist"]["all"]) && $_POST["targetlist"]["all"] == "on") {
  279. $res = Sql_query("select * from $tables[list] $subselect");
  280. while($row = Sql_fetch_array($res)) {
  281. $listid = $row["id"];
  282. if ($row["active"]) {
  283. $result = Sql_query("insert ignore into $tables[listmessage] (messageid,listid,entered) values($messageid,$listid,now())");
  284. }
  285. }
  286. } else {
  287. foreach($_POST["targetlist"] as $listid => $val) {
  288. $result = Sql_query("insert ignore into $tables[listmessage] (messageid,listid,entered) values($messageid,$listid,now())");
  289. }
  290. }
  291. } else {
  292. # mark this message as listmessage for list 0
  293. $result = Sql_query("insert ignore into $tables[listmessage] (messageid,listid,entered) values($messageid,0,now())");
  294. }
  295. if (isset($_POST["excludelist"]) && is_array($_POST["excludelist"])) {
  296. $exclude = join(",",$_POST["excludelist"]);
  297. Sql_Query(sprintf('replace into %s (name,id,data) values("excludelist",%d,"%s")',$tables["messagedata"],$messageid,$exclude));
  298. }
  299. # we want to create a join on tables as follows, in order to find users who have their attributes to the values chosen
  300. # (independent of their list membership).
  301. # select
  302. # table1.userid from user_attribute as table1
  303. # left join user_attribute as table2 on table1.userid = table2.userid
  304. # left join user_attribute as table3 on table1.userid = table3.userid
  305. # ...
  306. # where
  307. # table1.attributeid = 2 and table1.value in (1,2,3,4)
  308. # and table2.attributeid = 1 and table2.value in (3,15)
  309. # and table3.attributeid = 3 and table3.value in (4,5,6)
  310. # ...
  311. # check the criterias, create the selection query
  312. $used_tables = array();
  313. for ($i=1;$i<=NUMCRITERIAS;$i++) {
  314. if (isset($_POST["use"][$i])) {
  315. $attribute = $_POST["criteria"][$i];
  316. $type = $_POST["attrtype"][$attribute];
  317. switch($type) {
  318. case "checkboxgroup":
  319. $values = "attr$attribute$i";
  320. $or_clause = '';
  321. if (isset($where_clause)) {
  322. $where_clause .= " and ";
  323. $select_clause .= " left join $tables[user_attribute] as table$i on table$first.userid = table$i.userid ";
  324. } else {
  325. $select_clause = "table$i.userid from $tables[user_attribute] as table$i ";
  326. $first = $i;
  327. }
  328. $where_clause .= "table$i.attributeid = $attribute and (";
  329. if (is_array($_POST[$values])) {
  330. foreach ($_POST[$values] as $val) {
  331. if ($or_clause != '') {
  332. $or_clause .= " or ";
  333. }
  334. $or_clause .= "find_in_set('$val',table$i.value) > 0";
  335. }
  336. }
  337. $where_clause .= $or_clause . ")";
  338. break;
  339. case "checkbox":
  340. $values = "attr$attribute$i";
  341. $value = $_POST[$values][0];
  342. if (isset($where_clause)) {
  343. $where_clause .= " and ";
  344. $select_clause .= " left join $tables[user_attribute] as table$i on table$first.userid = table$i.userid ";
  345. } else {
  346. $select_clause = "table$i.userid from $tables[user_attribute] as table$i ";
  347. $first = $i;
  348. }
  349. $where_clause .= "table$i.attributeid = $attribute and ";
  350. if ($value) {
  351. $where_clause .= "( length(table$i.value) and table$i.value != \"off\" and table$i.value != \"0\") ";
  352. } else {
  353. $where_clause .= "( table$i.value = \"\" or table$i.value = \"0\" or table$i.value = \"off\") ";
  354. }
  355. break;
  356. default:
  357. $values = "attr$attribute$i";
  358. if (isset($where_clause)) {
  359. $where_clause .= " and ";
  360. $select_clause .= " left join $tables[user_attribute] as table$i on table$first.userid = table$i.userid ";
  361. } else {
  362. $select_clause = "table$i.userid from $tables[user_attribute] as table$i ";
  363. $first = $i;
  364. }
  365. $where_clause .= "table$i.attributeid = $attribute and table$i.value in (";
  366. $list = array();
  367. if (is_array($_POST[$values])) {
  368. while (list($key,$val) = each ($_POST[$values]))
  369. array_push($list,$val);
  370. }
  371. $where_clause .= join(", ",$list) . ")";
  372. }
  373. }
  374. }
  375. # if no selection was made, use all
  376. if (!isset($where_clause)) {
  377. $count_query = "";
  378. # $count_query = addslashes("select distinct userid from $tables[user_attribute]");
  379. } else {
  380. $count_query = addslashes("select $select_clause where $where_clause");
  381. Sql_query("update $tables[message] set userselection = \"$count_query\" where id = $messageid");
  382. }
  383. # commented, because this could take too long
  384. # Sql_Query($count_query);
  385. # $num = Sql_Affected_rows();
  386. # new criteria system, add one by one:
  387. if (isset($_POST["criteria_attribute"]) && $_POST["criteria_attribute"]) {
  388. $operator = $_POST["criteria_operator"];
  389. if (is_array($_POST["criteria_values"])) {
  390. $values = join(", ",$_POST["criteria_values"]);
  391. } else {
  392. $values = $_POST["criteria_values"];
  393. }
  394. foreach ($_POST["attribute_names"] as $key => $val) {
  395. $att_names[$key] = $val;
  396. }
  397. $newcriterion = array(
  398. "attribute" => sprintf('%d',$_POST["criteria_attribute"]),
  399. "attribute_name" => $att_names[$_POST["criteria_attribute"]],
  400. "operator" => $operator,
  401. "values" => $values,
  402. );
  403. # find out what number we are
  404. $numarr = Sql_Fetch_Row_Query(sprintf('select data from %s where id = %d and name = "numcriteria"',
  405. $tables["messagedata"],$messageid));
  406. $num = sprintf('%d',$numarr[0]+1);
  407. # store this one
  408. # print $att_names[$_POST["criteria_attribute"]];
  409. # print $_POST["attribute_names[".$_POST["criteria_attribute"]."]"];
  410. print "<p>".$GLOBALS['I18N']->get("adding")." ".$newcriterion["attribute_name"]." ".$newcriterion["operator"]." ".$newcriterion["values"]."</p>";
  411. Sql_Query(sprintf('insert into %s (name,id,data) values("criterion%d",%d,"%s")',
  412. $tables["messagedata"],$num,$messageid,delimited($newcriterion)));
  413. # increase number
  414. Sql_Query(sprintf('replace into %s (name,id,data) values("numcriteria",%d,"%s")',
  415. $tables["messagedata"],$messageid,$num));
  416. # save overall operator
  417. }
  418. if (isset($_POST["criteria_match"])) {
  419. Sql_Query(sprintf('replace into %s (name,id,data) values("criteria_overall_operator",%d,"%s")',
  420. $tables["messagedata"],$messageid,$_POST["criteria_match"]));
  421. }
  422. if (isset($_POST['notify_start']) && $_POST['notify_start']) {
  423. Sql_Query(sprintf('replace into %s set name = "notify_start",id = %d,data = "%s"',
  424. $GLOBALS['tables']['messagedata'],$id,$_POST['notify_start']));
  425. }
  426. if (isset($_POST['notify_end']) && $_POST['notify_end']) {
  427. Sql_Query(sprintf('replace into %s set name = "notify_end",id = %d,data = "%s"',
  428. $GLOBALS['tables']['messagedata'],$id,$_POST['notify_end']));
  429. }
  430. if (ALLOW_ATTACHMENTS) {
  431. for ($att_cnt = 1;$att_cnt <= NUMATTACHMENTS;$att_cnt++) {
  432. $fieldname = "attachment".$att_cnt;
  433. $tmpfile = $_FILES[$fieldname]['tmp_name'];
  434. $remotename = $_FILES[$fieldname]["name"];
  435. $type = $_FILES[$fieldname]["type"];
  436. if (strlen($_POST[$type]) > 255)
  437. print Warn($GLOBALS['I18N']->get("longmimetype"));
  438. $description = $_POST[$fieldname."_description"];
  439. if ($tmpfile && filesize($tmpfile) && $tmpfile != "none") {
  440. list($name,$ext) = explode(".",basename($remotename));
  441. # create a temporary file to make sure to use a unique file name to store with
  442. $newfile = tempnam($GLOBALS["attachment_repository"],$name);
  443. $newfile .= ".".$ext;
  444. $newfile = basename($newfile);
  445. $file_size = filesize($tmpfile);
  446. $fd = fopen( $tmpfile, "r" );
  447. $contents = fread( $fd, filesize( $tmpfile ) );
  448. fclose( $fd );
  449. if ($file_size) {
  450. # this may seem odd, but it allows for a remote (ftp) repository
  451. # also, "copy" does not work across filesystems
  452. $fd = fopen($GLOBALS["attachment_repository"]."/".$newfile, "w" );
  453. fwrite( $fd, $contents );
  454. fclose( $fd );
  455. Sql_query(sprintf('insert into %s (filename,remotefile,mimetype,description,size) values("%s","%s","%s","%s",%d)',
  456. $tables["attachment"],
  457. basename($newfile),$remotename,$type,$description,$file_size)
  458. );
  459. $attachmentid = Sql_Insert_id();
  460. Sql_query(sprintf('insert into %s (messageid,attachmentid) values(%d,%d)',
  461. $tables["message_attachment"],$messageid,$attachmentid));
  462. # do a final check
  463. if (filesize($GLOBALS["attachment_repository"]."/".$newfile))
  464. print Info($GLOBALS['I18N']->get("addingattachment")." ".$att_cnt . " .. ok");
  465. else
  466. print Info($GLOBALS['I18N']->get("addingattachment")." ".$att_cnt." .. failed");
  467. } else {
  468. print Warn($GLOBALS['I18N']->get("uploadfailed"));
  469. }
  470. } elseif ($_POST["localattachment".$att_cnt]) {
  471. $type = findMime(basename($_POST["localattachment".$att_cnt]));
  472. Sql_query(sprintf('insert into %s (remotefile,mimetype,description,size) values("%s","%s","%s",%d)',
  473. $tables["attachment"],
  474. $_POST["localattachment".$att_cnt],$type,$description,filesize($_POST["localattachment".$att_cnt]))
  475. );
  476. $attachmentid = Sql_Insert_id();
  477. Sql_query(sprintf('insert into %s (messageid,attachmentid) values(%d,%d)',
  478. $tables["message_attachment"],$messageid,$attachmentid));
  479. print Info($GLOBALS['I18N']->get("addingattachment")." ".$att_cnt. " mime: $type");
  480. }
  481. }
  482. }
  483. if ($_POST["id"]) {
  484. print "<h3>".$GLOBALS['I18N']->get("saved")."</H3><br/>";
  485. } else {
  486. $id = $messageid; // New ID - need to set it for later use (test email).
  487. print "<h3>".$GLOBALS['I18N']->get("added")."</H3><br/>";
  488. }
  489. // If we're sending the message, just return now to the calling script
  490. # we only need to check that everything is there, once we actually want to send
  491. if ($send && $subject && $from && $message && !$duplicate_atribute && sizeof($_POST["targetlist"])) {
  492. if ($status == "submitted") {
  493. print "<h3>".$GLOBALS['I18N']->get("queued")."</h3>";
  494. print '<p>'.PageLink2("processqueue",$GLOBALS['I18N']->get("processqueue")).'</p>';
  495. }
  496. $done = 1;
  497. return;
  498. } elseif ($send || $sendtest) {
  499. $errormessage = "";
  500. if ($subject != stripslashes($_POST["subject"])) {
  501. $errormessage = $GLOBALS['I18N']->get("errorsubject"). "S: $subject, P".$_POST["subject"];
  502. } elseif ($from != $_POST["from"]) {
  503. $errormessage = $GLOBALS['I18N']->get("errorfrom");
  504. } elseif (!$from) {
  505. $errormessage = $GLOBALS['I18N']->get("enterfrom");
  506. } elseif (!$message) {
  507. $errormessage = $GLOBALS['I18N']->get("entermessage");
  508. } elseif (!$subject) {
  509. $errormessage = $GLOBALS['I18N']->get("entersubject");
  510. } elseif ($duplicate_attribute) {
  511. $errormessage = $GLOBALS['I18N']->get("duplicateattribute");
  512. } elseif ($send && !is_array($_POST["targetlist"])) {
  513. $errormessage = $GLOBALS['I18N']->get("selectlist");
  514. }
  515. echo "<font color=red size=+2>$errormessage</font><br>\n";
  516. }
  517. // OK, the message has been saved, now check to see if we need to send a test message
  518. if ($sendtest) {
  519. echo "<HR>";
  520. // Let's send test messages to everyone that was specified in the
  521. if ($_POST["testtarget"] == "") {
  522. print "<font color=red size=+2>".$GLOBALS['I18N']->get("notargetemail")."</font><br>";
  523. }
  524. unset($cached[$id]);
  525. include "sendemaillib.php";
  526. // OK, let's get to sending!
  527. $emailaddresses = split('[/,,/;]', $_POST["testtarget"]);
  528. foreach ($emailaddresses as $address) {
  529. $address = trim($address);
  530. $result = Sql_query(sprintf('select id,email,uniqid,htmlemail,rssfrequency,confirmed from %s where email = "%s"',$tables["user"],$address));
  531. if ($user = Sql_fetch_array($result)) {
  532. $success = sendEmail($id, $address, $user["uniqid"], 1) && sendEmail($id, $address, $user["uniqid"], 0);
  533. ;
  534. print $GLOBALS['I18N']->get("sentemailto").": $address ";
  535. if (!$success) {
  536. print $GLOBALS['I18N']->get('failed');
  537. } else {
  538. print $GLOBALS['I18N']->get('success');
  539. }
  540. print '<br/>';
  541. } else {
  542. print "<font color=red>".$GLOBALS['I18N']->get("emailnotfound").": $address</font><br>";
  543. }
  544. }
  545. echo "<HR>";
  546. }
  547. } elseif (isset($_POST["deleteattachments"]) && is_array($_POST["deleteattachments"]) && $id) {
  548. if (ALLOW_ATTACHMENTS) {
  549. // Delete Attachment button hit...
  550. $deleteattachments = $_POST["deleteattachments"];
  551. foreach($deleteattachments as $attid)
  552. {
  553. $result = Sql_Query(sprintf("Delete from %s where id = %d and messageid = %d",
  554. $tables["message_attachment"],
  555. $attid,
  556. $id));
  557. print Info($GLOBALS['I18N']->get("removedattachment")." ".$att_cnt);
  558. // NOTE THAT THIS DOESN'T ACTUALLY DELETE THE ATTACHMENT FROM THE DATABASE, OR
  559. // FROM THE FILE SYSTEM - IT ONLY REMOVES THE MESSAGE / ATTACHMENT LINK. THIS
  560. // SHOULD PROBABLY BE CORRECTED, BUT I (Pete Ness) AM NOT SURE WHAT OTHER IMPACTS
  561. // THIS MAY HAVE.
  562. // (My thoughts on this are to check for any orphaned attachment records and if
  563. // there are any, to remove it from the disk and then delete it from the database).
  564. }
  565. }
  566. }
  567. # load all message data
  568. $messagedata = loadMessageData($id);
  569. ##############################
  570. # Stacked attributes, processing and calculation
  571. ##############################
  572. if (STACKED_ATTRIBUTE_SELECTION) {
  573. # read criteria and parse it into a user query
  574. $num = sprintf('%d',isset($messagedata['numcriteria']) ? $messagedata['numcriteria']: 0);
  575. # print '<br/>'.$num . " criteria already defined";
  576. $ls = new WebblerListing($GLOBALS['I18N']->get("existingcriteria"));
  577. $used_attributes = array();
  578. $delete_base = sprintf('%s&amp;id=%d&amp;tab=%s',$_GET["page"],$_GET["id"],$_GET["tab"]);
  579. $tc = 0; # table counter
  580. if (!isset($messagedata['criteria_overall_operator'])) {
  581. $messagedata['criteria_overall_operator'] = '';
  582. }
  583. $mainoperator = $messagedata['criteria_overall_operator'] == "all"? ' and ':' or ';
  584. $subqueries = array();
  585. for ($i = 1; $i<=$num;$i++) {
  586. $crit_data = parseDelimitedData($messagedata[sprintf('criterion%d',$i)]);
  587. if ($crit_data["attribute"]) {
  588. array_push($used_attributes,$crit_data["attribute"]);
  589. $ls->addElement('<!--'.$crit_data["attribute"].'-->'.$crit_data["attribute_name"]);
  590. $ls->addColumn('<!--'.$crit_data["attribute"].'-->'.$crit_data["attribute_name"],$GLOBALS['I18N']->get('operator'),$GLOBALS['I18N']->get($crit_data["operator"]));
  591. $ls->addColumn('<!--'.$crit_data["attribute"].'-->'.$crit_data["attribute_name"],$GLOBALS['I18N']->get('values'),$crit_data["values"]);
  592. $ls->addColumn('<!--'.$crit_data["attribute"].'-->'.$crit_data["attribute_name"],$GLOBALS['I18N']->get('remove'),PageLink2($delete_base."&amp;deleterule=".$i,$GLOBALS['I18N']->get("remove")));
  593. $attribute = $_POST["criteria"][$i];
  594. # hmm, rather get is some other way, this is a bit unnecessary
  595. $type = Sql_Fetch_Row_Query("select type from {$tables["attribute"]} where id = ".$crit_data["attribute"]);
  596. $operator = "";
  597. switch($type[0]) {
  598. case "checkboxgroup":
  599. $or_clause = '';
  600. if ($tc) {
  601. $where_clause .= " $mainoperator ";
  602. $select_clause .= " left join $tables[user_attribute] as table$tc on table0.userid = table$tc.userid ";
  603. } else {
  604. $select_clause = "table$tc.userid from $tables[user_attribute] as table$tc ";
  605. }
  606. $where_clause .= " ( table$tc.attributeid = ".$crit_data["attribute"]." and (";
  607. if ($crit_data["operator"] == "is") {
  608. $operator = ' or ';
  609. $compare = ' > ';
  610. } else {
  611. $operator = ' and ';
  612. $compare = ' < ';
  613. }
  614. foreach (explode(",",$crit_data["values"]) as $val) {
  615. if ($or_clause != '') {
  616. $or_clause .= " $operator ";
  617. }
  618. $or_clause .= "find_in_set('$val',table$tc.value) $compare 0";
  619. }
  620. $where_clause .= $or_clause . ") ) ";
  621. $subqueries[$i]['query'] = sprintf('select userid from %s as table%d where attributeid = %d
  622. and %s',$GLOBALS['tables']['user_attribute'],$tc,$crit_data['attribute'],$or_clause);
  623. break;
  624. case "checkbox":
  625. $value = $crit_data["values"][0];
  626. if ($tc) {
  627. $where_clause .= " $mainoperator ";
  628. $select_clause .= " left join $tables[user_attribute] as table$tc on table0.userid = table$tc.userid ";
  629. } else {
  630. $select_clause = "table$tc.userid from $tables[user_attribute] as table$tc";
  631. }
  632. $where_clause .= " ( table$tc.attributeid = ".$crit_data["attribute"]." and ";
  633. if ($crit_data["operator"] == "isnot") {
  634. $where_clause .= ' not ';
  635. }
  636. $valueselect = '';
  637. if ($value) {
  638. $valueselect = " length(table$tc.value) and table$tc.value != \"off\" and table$tc.value != \"0\" ";
  639. } else {
  640. $valueselect = " table$tc.value = \"\" or table$tc.value = \"0\" or table$tc.value = \"off\" ";
  641. }
  642. $where_clause .= '( '.$valueselect . ') ) ';
  643. $subqueries[$i]['query'] = sprintf('select userid from %s as table%d where attributeid = %d
  644. and %s',$GLOBALS['tables']['user_attribute'],$tc,$crit_data['attribute'],$valueselect);
  645. break;
  646. case "date":
  647. $date_value = parseDate($crit_data["values"]);
  648. if (!$date_value) {
  649. break;
  650. }
  651. if (isset($where_clause)) {
  652. $where_clause .= " $mainoperator ";
  653. $select_clause .= " left join $tables[user_attribute] as table$tc on table0.userid = table$tc.userid ";
  654. } else {
  655. $select_clause = " table$tc.userid from $tables[user_attribute] as table$tc ";
  656. }
  657. $where_clause .= ' ( table'.$tc.'.attributeid = '.$crit_data["attribute"].' and table'.$tc.'.value != "" and table'.$tc.'.value ';
  658. $dateoperator = '';
  659. switch ($crit_data["operator"]) {
  660. case "is":
  661. $where_clause .= ' = "'.$date_value . '" )';$dateoperator = '=';break;
  662. case "isnot":
  663. $where_clause .= ' != "'.$date_value . '" )';$dateoperator = '!=';break;
  664. case "isbefore":
  665. $where_clause .= ' <= "'.$date_value . '" )';$dateoperator = '<=';break;
  666. case "isafter":
  667. $where_clause .= ' >= "'.$date_value . '" )';$dateoperator = '>=';break;
  668. }
  669. # $where_clause .= " )";
  670. $subqueries[$i]['query'] = sprintf('select userid from %s where attributeid = %d and value != "" and value %s "%s" ',$GLOBALS['tables']['user_attribute'],
  671. $crit_data['attribute'],
  672. $dateoperator,
  673. $date_value);
  674. break;
  675. default:
  676. if (isset($where_clause)) {
  677. $where_clause .= " $mainoperator ";
  678. $select_clause .= " left join $tables[user_attribute] as table$tc on table0.userid = table$tc.userid ";
  679. } else {
  680. $select_clause = " table$tc.userid from $tables[user_attribute] as table$tc ";
  681. }
  682. $where_clause .= " ( table$tc.attributeid = ".$crit_data["attribute"]." and table$tc.value ";
  683. if ($crit_data["operator"] == "isnot") {
  684. $where_clause .= ' not in (';
  685. } else {
  686. $where_clause .= ' in (';
  687. }
  688. $where_clause .= $crit_data["values"] . ") )";
  689. $subqueries[$i]['query'] = sprintf('select userid from %s
  690. where attributeid = %d and
  691. value %s in (%s) ',$GLOBALS['tables']['user_attribute'],
  692. $crit_data['attribute'],
  693. $crit_data["operator"] == "isnot" ? 'not' :'',
  694. $crit_data["values"]);
  695. }
  696. $tc++;
  697. }
  698. }
  699. $existing_criteria = '';
  700. if (sizeof($subqueries)) {
  701. # $count_query = "select distinct $select_clause where $where_clause";
  702. # $count_query = addslashes($count_query);
  703. if ($_GET["calculate"]) {
  704. ob_end_flush();
  705. # print "<h1>$count_query</h1>";
  706. print "<p>".$GLOBALS['I18N']->get("calculating")." ...";
  707. flush();
  708. }
  709. foreach ($subqueries as $qid => $querydetails) {
  710. $req = Sql_Query($querydetails['query']);
  711. $subqueries[$qid]['results'] = array();
  712. while ($row = Sql_Fetch_Row($req)) {
  713. array_push($subqueries[$qid]['results'],$row[0]);
  714. }
  715. }
  716. $first = array_shift($subqueries);
  717. $userids = $first['results'];
  718. foreach ($subqueries as $subquery) {
  719. if ($messagedata['criteria_overall_operator'] == 'all') {
  720. $userids = array_intersect($userids,$subquery['results']);
  721. } else {
  722. $userids = array_merge($userids,$subquery['results']);
  723. }
  724. }
  725. $userids = array_unique($userids);
  726. $num_users = sizeof($userids);
  727. $count_query = sprintf('select * from %s where id in (%s)',$GLOBALS['tables']['user'],join(', ',$userids));
  728. if ($_GET["calculate"]) {
  729. printf('.. '.$GLOBALS['I18N']->get('%d users apply'),$num).'</p>';
  730. }
  731. if ($messageid) {
  732. Sql_query(sprintf('update %s set userselection = "%s" where id = %d',
  733. $tables["message"],addslashes($count_query),$messageid));
  734. }
  735. if (!isset($_GET['calculate'])) {
  736. $ls->addButton($GLOBALS['I18N']->get("calculate"),$baseurl.'&amp;tab='.$_GET["tab"].'&amp;calculate=1');
  737. } else {
  738. $ls->addButton($GLOBALS['I18N']->get("reload"),$baseurl.'&amp;tab='.$_GET["tab"]);
  739. }
  740. $existing_criteria = $ls->display();
  741. } else {
  742. if ($messageid) {
  743. Sql_query(sprintf('update %s set userselection = "" where id = %d',
  744. $tables["message"],$messageid));
  745. }
  746. }
  747. } // end of define STACKED_ATTRIBUTES
  748. ##############################
  749. # Stacked attributes, end
  750. ##############################
  751. // Pull in $footer variable from post
  752. if (isset($_POST["footer"]))
  753. $footer = $_POST["footer"];
  754. // If $id wasn't passed in (if it was passed, then $_POST should have
  755. // the database value in it already, and if it's empty, then we should
  756. // leave it empty) and $footer is blank, load the default.
  757. if (!$footer)
  758. $footer = getConfig("messagefooter");
  759. echo $errormsg;
  760. if (!$done) {
  761. if (ALLOW_ATTACHMENTS) {
  762. $enctype = 'enctype="multipart/form-data"';
  763. } else {
  764. $enctype = '';
  765. }
  766. #$baseurl = sprintf('./?page=%s&amp;id=%d',$_GET["page"],$_GET["id"]);
  767. if ($_GET["id"]) {
  768. $tabs = new WebblerTabs();
  769. $tabs->addTab($GLOBALS['I18N']->get("Content"),"$baseurl&amp;tab=Content");
  770. $tabs->addTab($GLOBALS['I18N']->get("Format"),"$baseurl&amp;tab=Format");
  771. if (ALLOW_ATTACHMENTS) {
  772. $tabs->addTab($GLOBALS['I18N']->get("Attach"),"$baseurl&amp;tab=Attach");
  773. }
  774. $tabs->addTab($GLOBALS['I18N']->get("Scheduling"),"$baseurl&amp;tab=Scheduling");
  775. # if (USE_RSS) {
  776. # $tabs->addTab("RSS","$baseurl&amp;tab=RSS");
  777. # }
  778. $tabs->addTab($GLOBALS['I18N']->get("Criteria"),"$baseurl&amp;tab=Criteria");
  779. $tabs->addTab($GLOBALS['I18N']->get("Lists"),"$baseurl&amp;tab=Lists");
  780. # $tabs->addTab("Review and Send","$baseurl&amp;tab=Review");
  781. $tabs->addTab($GLOBALS['I18N']->get("Misc"),"$baseurl&amp;tab=Misc");
  782. if ($_GET["tab"]) {
  783. $tabs->setCurrent($GLOBALS['I18N']->get($_GET["tab"]));
  784. } else {
  785. $tabs->setCurrent($GLOBALS['I18N']->get("Content"));
  786. }
  787. if (defined("WARN_SAVECHANGES")) {
  788. $tabs->addLinkCode(' onClick="return savechanges();" ');
  789. }
  790. print $tabs->display();
  791. }
  792. ?>
  793. <p></p>
  794. <script language="Javascript">
  795. // some debugging stuff to see what happens
  796. function checkForm() {
  797. return true;
  798. for (var i=0;i<document.sendmessageform.elements.length;i++) {
  799. alert(document.sendmessageform.elements[i].name+" "+document.sendmessageform.elements[i].value);
  800. }
  801. return true;
  802. }
  803. // detection of unsaved changes,
  804. var browser = navigator.appName.substring ( 0, 9 );
  805. var changed = 0; function haschanged() {changed = 1; }
  806. function savechanges() { if (changed) { if (confirm("<?php echo str_replace('"','&quot',reverse_htmlentities($GLOBALS['I18N']->get("unsavedchanges")))?>")) return true; else return false; return false;}}
  807. //'
  808. var event_number = 0;if (browser=="Microsoft") { document.onkeydown=haschanged; document.onchange=haschanged;} else if (browser=="Netscape") { document.captureEvents(Event.KEYDOWN); document.captureEvents(Event.CHANGE); document.onkeydown=haschanged;document.onchange=haschanged;}
  809. function submitform() { document.sendmessageform.submit() }
  810. </script>
  811. <?php
  812. print formStart($enctype . ' name="sendmessageform"');
  813. #print '<form method="post" enctype="multipart/form-data" name="sendmessageform" onSubmit="return checkForm()">';
  814. print '<input type=hidden name="workaround_fck_bug" value="1">';
  815. if ($_GET["page"] == "preparemessage")
  816. print Help("preparemessage",$GLOBALS['I18N']->get("whatisprepare"));
  817. if (!defined("IN_WEBBLER")) {
  818. if (!$from) {
  819. $adminemail = $GLOBALS["admin_auth"]->adminEmail($_SESSION["logindetails"]["id"]);
  820. if ($adminemail && USE_ADMIN_DETAILS_FOR_MESSAGES) {
  821. $from = $GLOBALS["admin_auth"]->adminName($_SESSION["logindetails"]["id"]).' '.$adminemail;
  822. } else {
  823. $from = getConfig("message_from_name") . ' '.getConfig("message_from_address");
  824. }
  825. }
  826. }
  827. $formatting_content = '<table>';
  828. $maincontent = '<table>';
  829. $scheduling_content = '<table>';
  830. $maincontent .= '
  831. <tr><td>'.Help("subject").' '.$GLOBALS['I18N']->get("Subject").':</td>
  832. <td><input type=text name="msgsubject"
  833. value="'.htmlentities($subject).'" size=40></td></tr>
  834. <tr>
  835. <td colspan=2>
  836. </td></tr>
  837. <tr><td>'.Help("from").' '.$GLOBALS['I18N']->get("fromline").':</td>
  838. <td><input type=text name=from
  839. value="'.htmlentities($from).'" size=40></td></tr>
  840. <tr><td colspan=2>
  841. </td></tr>';
  842. $scheduling_content .= '
  843. <tr><td>'.Help("embargo").' '.$GLOBALS['I18N']->get("embargoeduntil").':</td>
  844. <td>'.$embargo->showInput("embargo","",$_POST["embargo"]).'</td></tr>
  845. </td></tr>';
  846. if (USE_REPETITION) {
  847. $repeatinterval = $_POST["repeatinterval"];
  848. $scheduling_content .= '
  849. <tr><td>'.Help("repetition").' '.$GLOBALS['I18N']->get("repeatevery").':</td><td>
  850. <select name="repeatinterval">
  851. <option value="0"';
  852. if ($repeatinterval == 0) { $scheduling_content .= " SELECTED"; }
  853. $scheduling_content .= '>-- '.$GLOBALS['I18N']->get("norepetition").'</option>
  854. <option value="60"';
  855. if ($repeatinterval == 60) { $scheduling_content .= " SELECTED"; }
  856. $scheduling_content .= '>'.$GLOBALS['I18N']->get("hour").'</option>
  857. <option value="1440"';
  858. if ($repeatinterval == 1440) { $scheduling_content .= " SELECTED"; }
  859. $scheduling_content .= '>'.$GLOBALS['I18N']->get("day").'</option>
  860. <option value="10080"';
  861. if ($repeatinterval == 10080) { $scheduling_content .= " SELECTED"; }
  862. $scheduling_content .= '>'.$GLOBALS['I18N']->get("week").'</option>
  863. </select>
  864. </td></tr>
  865. </td></tr>
  866. <tr><td> '.$GLOBALS['I18N']->get("repeatuntil").':</td><td>'.$repeatuntil->showInput("repeatuntil","",$_POST["repeatuntil"]).'</td></tr>
  867. </td></tr>';
  868. }
  869. /*
  870. $formatting_content .= '
  871. <tr><td colspan=2>'.Help("format").' '.$GLOBALS['I18N']->get("format").': <b>'.$GLOBALS['I18N']->get("autodetect").'</b>
  872. <input type=radio name="htmlformatted" value="auto" ';
  873. $formatting_content .= !isset($htmlformatted) || $htmlformatted == "auto"?"checked":"";
  874. $formatting_content .= '>
  875. <b>'.$GLOBALS['I18N']->get("html").'</b> <input type=radio name="htmlformatted" value="1" ';
  876. $formatting_content .= $htmlformatted == "1" ?"checked":"";
  877. $formatting_content .= '>
  878. <b>'.$GLOBALS['I18N']->get("text").'</b> <input type=radio name="htmlformatted" value="0" ';
  879. $formatting_content .= $htmlformatted == "0" ?"checked":"";
  880. $formatting_content .= '></td></tr>';
  881. */
  882. $formatting_content .= '<input type=hidden name="htmlformatted" value="auto">';
  883. $formatting_content .= '
  884. <tr><td colspan=2>'.Help("sendformat").' '.$GLOBALS['I18N']->get("sendas").':
  885. '.$GLOBALS['I18N']->get("html").' <input type=radio name="sendformat" value="HTML" ';
  886. $formatting_content .= $_POST["sendformat"]=="HTML"?"checked":"";
  887. $formatting_content .= '>
  888. '.$GLOBALS['I18N']->get("text").' <input type=radio name="sendformat" value="text" ';
  889. $formatting_content .= $_POST["sendformat"]=="text"?"checked":"";
  890. $formatting_content .= '>
  891. ';
  892. if (USE_PDF) {
  893. $formatting_content .= $GLOBALS['I18N']->get("pdf").' <input type=radio name="sendformat" value="PDF" ';
  894. $formatting_content .= $_POST["sendformat"]=="PDF"?"checked":"";
  895. $formatting_content .= '>';
  896. }
  897. $formatting_content .= $GLOBALS['I18N']->get("textandhtml").' <input type=radio name="sendformat" value="text and HTML" ';
  898. $formatting_content .= $_POST["sendformat"]=="text and HTML" || !isset($_POST["sendformat"]) ?"checked":"";
  899. $formatting_content .= '>';
  900. if (USE_PDF) {
  901. $formatting_content .= $GLOBALS['I18N']->get("textandpdf").' <input type=radio name="sendformat" value="text and PDF" ';
  902. $formatting_content .= $_POST["sendformat"]=="text and PDF" ?"checked":"";
  903. $formatting_content .= ' >';
  904. }
  905. $formatting_content .= '</td></tr>';
  906. $req = Sql_Query("select id,title from {$tables["template"]} order by listorder");
  907. if (Sql_affected_Rows()) {
  908. $formatting_content .= '<tr><td>'.Help("usetemplate").' '.$GLOBALS['I18N']->get("usetemplate").': </td>
  909. <td><select name="template"><option value=0>-- '.$GLOBALS['I18N']->get("selectone").'</option>';
  910. $req = Sql_Query("select id,title from {$tables["template"]} order by listorder");
  911. while ($row = Sql_Fetch_Array($req)) {
  912. $formatting_content .= sprintf('<option value="%d" %s>%s</option>',$row["id"], $row["id"]==$_POST["template"]?'SELECTED':'',$row["title"]);
  913. }
  914. $formatting_content .= '</select></td></tr>';
  915. }
  916. if (ENABLE_RSS) {
  917. $rss_content .= '<tr><td colspan=2>'.$GLOBALS['I18N']->get("rssintro").'
  918. </td></tr>';
  919. $rss_content .= '<tr><td colspan=2><input type=radio name="rsstemplate" value="none">'.$GLOBALS['I18N']->get("none").' ';
  920. foreach ($rssfrequencies as $key => $val) {
  921. $rss_content .= sprintf('<input type=radio name="rsstemplate" value="%s" %s>%s ',$key,$_POST["rsstemplate"] == $key ? "checked":"",$val);
  922. }
  923. $rss_content .= '</td></tr>';
  924. }
  925. $maincontent .= '<tr><td colspan=2>'.Help("message").' '.$GLOBALS['I18N']->get("message").'. </td></tr>
  926. <tr><td colspan=2>';
  927. if ($usefck) {
  928. $oFCKeditor = new FCKeditor('message') ;
  929. $oFCKeditor->BasePath = './FCKeditor/';
  930. //$oFCKeditor->ToolbarSet = 'Accessibility' ;
  931. $oFCKeditor->ToolbarSet = 'Default' ;
  932. $oFCKeditor->Value = stripslashes($_POST["message"]);
  933. $w = getConfig("fckeditor_width");
  934. $h = getConfig("fckeditor_height");
  935. if ($_SESSION["fckeditor_height"]) {
  936. $h = sprintf('%d',$_SESSION["fckeditor_height"]);
  937. }
  938. # version 1.4
  939. # $maincontent .= $oFCKeditor->ReturnFCKeditor( 'message', $w.'px', $h.'px' ) ;
  940. # for version 2.0
  941. if ($h < 400) {
  942. $h = 400;
  943. }
  944. $oFCKeditor->Height = $h;
  945. $oFCKeditor->Width = $w;
  946. $maincontent .= $oFCKeditor->CreateHtml() ;
  947. $maincontent .= '</td></tr>';
  948. $maincontent .= '<script language="Javascript" type="text/javascript">
  949. function expand() {
  950. document.sendmessageform.expand.value = 1;
  951. document.sendmessageform.save.value = 1
  952. document.sendmessageform.submit();
  953. }
  954. </script>';
  955. $maincontent .= '<tr><td colspan=2 align=right><a href="javascript:expand();" class="button">'.$GLOBALS['I18N']->get("expand").'</a></td></tr>';
  956. } elseif ($useTinyMCE) {
  957. $tinyMCE_path = TINYMCEPATH;
  958. $tinyMCE_lang = TINYMCELANG;
  959. $tinyMCE_theme = TINYMCETHEME;
  960. $tinyMCE_opts = TINYMCEOPTS;
  961. $maincontent .= "<script language='javascript' type='text/javascript' src='{$tinyMCE_path}'></script>\n"
  962. ."<script language='javascript' type='text/javascript'>\n"
  963. ." tinyMCE.init({\n"
  964. ." mode : 'exact',\n"
  965. ." elements : 'message',\n"
  966. ." language : '{$tinyMCE_lang}',\n"
  967. ." theme : '{$tinyMCE_theme}'\n"
  968. ." {$tinyMCE_opts}\n"
  969. ." });\n"
  970. ."</script>\n"
  971. ."<textarea name='message' id='message' cols='65' rows='20'>{$_POST['message']}</textarea>";
  972. } else {
  973. $maincontent .= '<textarea name=message cols=65 rows=20>'.htmlspecialchars($_POST["message"]).'</textarea>';
  974. }
  975. $maincontent .= '
  976. </td></tr>
  977. ';
  978. if (USE_MANUAL_TEXT_PART) {
  979. $maincontent .= '<tr><td colspan=2>
  980. '.$GLOBALS['I18N']->get("plaintextversion").'
  981. </td></tr>
  982. <tr><td colspan=2>
  983. <textarea name=textmessage cols=65 rows=20>'.$_POST["textmessage"].'</textarea>
  984. </td></tr>';
  985. }
  986. $maincontent .= '<tr><td colspan=2>'.$GLOBALS['I18N']->get("messagefooter").'. <br/>
  987. '.$GLOBALS['I18N']->get("messagefooterexplanation").'.</td></tr>
  988. <tr><td colspan=2><textarea name=footer cols=65 rows=5>'.$footer.'</textarea></td></tr>
  989. </table>';
  990. if (ALLOW_ATTACHMENTS) {
  991. // If we have a message id saved, we want to query the attachments that are associated with this
  992. // message and display that (and allow deletion of!)
  993. $att_content = '<table><tr><td colspan=2>'.Help("attachments").' '.$GLOBALS['I18N']->get("addattachments").' </td></tr>';
  994. $att_content .= '<tr><td colspan=2>
  995. '.$GLOBALS['I18N']->get("uploadlimits").':<br/>
  996. '.$GLOBALS['I18N']->get("maxtotaldata").': '.ini_get("post_max_size").'<br/>
  997. '.$GLOBALS['I18N']->get("maxfileupload").': '.ini_get("upload_max_filesize").'</td></tr>';
  998. if ($id) {
  999. $result = Sql_Query(sprintf("Select Att.id, Att.filename, Att.remotefile, Att.mimetype, Att.description, Att.size, MsgAtt.id linkid".
  1000. " from %s Att, %s MsgAtt where Att.id = MsgAtt.attachmentid and MsgAtt.messageid = %d",
  1001. $tables["attachment"],
  1002. $tables["message_attachment"],
  1003. $id));
  1004. $tabletext = "";
  1005. $ls = new WebblerListing($GLOBALS['I18N']->get('currentattachments'));
  1006. while ($row = Sql_fetch_array($result)) {
  1007. # $tabletext .= "<tr><td>".$row["remotefile"]."</td><td>".$row["description"]."&nbsp;</td><td>".$row["size"]."</td>";
  1008. $ls->addElement($row["id"]);
  1009. $ls->addColumn($row["id"],$GLOBALS['I18N']->get('filename'),$row["remotefile"]);
  1010. $ls->addColumn($row["id"],$GLOBALS['I18N']->get('desc'),$row["description"]);
  1011. $ls->addColumn($row["id"],$GLOBALS['I18N']->get('size'),$row["size"]);
  1012. $phys_file = $GLOBALS["attachment_repository"]."/".$row["filename"];
  1013. if (is_file($phys_file) && filesize($phys_file)) {
  1014. $ls->addColumn($row["id"],$GLOBALS['I18N']->get('file'),$GLOBALS["img_tick"]);
  1015. } else {
  1016. $ls->addColumn($row["id"],$GLOBALS['I18N']->get('file'),$GLOBALS["img_cross"]);
  1017. }
  1018. $ls->addColumn($row["id"],$GLOBALS['I18N']->get('del'),sprintf('<input type=checkbox name="deleteattachments[]" value="%s">',$row["linkid"]));
  1019. // Probably need to check security rights here...
  1020. # $tabletext .= "<td><input type=checkbox name=\"deleteattachments[]\" value=\"".$row["linkid"]."\"></td>";
  1021. # $tabletext .= "</tr>\n";
  1022. }
  1023. $ls->addButton($GLOBALS['I18N']->get('delchecked'),"javascript:document.sendmessageform.submit()");
  1024. $att_content .= '<tr><td colspan=2>'.$ls->display().'</td></tr>';
  1025. # if ($tabletext) {
  1026. # print "<tr><td colspan=2><table border=1><tr><td>Filename</td><td>Description</td><td>Size</td><td>&nbsp;</td></tr>\n";
  1027. # print "$tabletext";
  1028. # print "<tr><td colspan=4 align=\"center\"><input type=submit name=deleteatt value=\"Delete Checked\"></td></tr>";
  1029. # print "</table></td></tr>\n";
  1030. # }
  1031. }
  1032. for ($att_cnt = 1;$att_cnt <= NUMATTACHMENTS;$att_cnt++) {
  1033. $att_content .=sprintf ('<tr><td>%s</td><td><input type=file name="attachment%d">&nbsp;&nbsp;<input type=submit name="save" value="%s"></td></tr>',$GLOBALS['I18N']->get('newattachment'),$att_cnt,$GLOBALS['I18N']->get('addandsave'));
  1034. if (FILESYSTEM_ATTACHMENTS) {
  1035. $att_content .= sprintf('<tr><td><b>%s</b> %s:</td><td><input type=text name="localattachment%d" size="50"></td></tr>',$GLOBALS['I18N']->get('or'),$GLOBALS['I18N']->get('pathtofile'),$att_cnt,$att_cnt);
  1036. }
  1037. $att_content .= sprintf ('<tr><td colspan=2>%s:</td></tr>
  1038. <tr><td colspan=2><textarea name="attachment%d_description" cols=65 rows=3 wrap="virtual"></textarea></td></tr>',$GLOBALS['I18N']->get('attachmentdescription'),$att_cnt);
  1039. }
  1040. $att_content .= '</table>';
  1041. # $shader = new WebblerShader("Attachments");
  1042. # $shader->addContent($att_content);
  1043. # $shader->initialstate = 'closed';
  1044. # print $shader->display();
  1045. }
  1046. // Load the email address for the admin user so we can use that as the default value in the testtarget field
  1047. # @@@ this only works with phplist authentication, needs to be abstracted
  1048. if (!isset($_POST["testtarget"])) {
  1049. $res = Sql_Query(sprintf("Select email from %s where id = %d", $tables["admin"], $_SESSION["logindetails"]["id"]));
  1050. $admin_details = Sql_Fetch_Array($res);
  1051. $_POST["testtarget"] = $admin_details["email"];
  1052. }
  1053. // if there isn't one, load the developer one, just being lazy here :-)
  1054. if (!$_POST["testtarget"]) {
  1055. $_POST["testtarget"] = $GLOBALS["developer_email"];
  1056. }
  1057. // Display the HTML for the "Send Test" button, and the input field for the email addresses
  1058. $sendtest_content = sprintf('<hr /><table><tr><td valign="top">
  1059. <input type=submit name=sendtest value="%s"> %s: </td>
  1060. <td><input type=text name="testtarget" size=40 value="'.$_POST["testtarget"].'"><br />%s
  1061. </td></tr></table><hr />',
  1062. $GLOBALS['I18N']->get('sendtestmessage'),$GLOBALS['I18N']->get('toemailaddresses'),
  1063. $GLOBALS['I18N']->get('sendtestexplain'));
  1064. $criteria_content = $GLOBALS['I18N']->get('criteriaexplanation').'
  1065. <table>
  1066. ';
  1067. $any = 0;
  1068. for ($i=1;$i<=NUMCRITERIAS;$i++) {
  1069. $criteria_content .= sprintf('<tr><td colspan=2><hr><h3>%s %d</h3></td>
  1070. <td>%s <input type=checkbox name="use[%d]"></tr>',$GLOBALS['I18N']->get('criterion'),$i,
  1071. $GLOBALS['I18N']->get('usethisone'),$i);
  1072. $attributes_request = Sql_Query("select * from $tables[attribute]");
  1073. while ($attribute = Sql_Fetch_array($attributes_request)) {
  1074. $criteria_content .= "\n\n";
  1075. $criteria_content .= sprintf('<input type=hidden name="attrtype[%d]" value="%s">',
  1076. $attribute["id"],$attribute["type"]);
  1077. switch ($attribute["type"]) {
  1078. case "checkbox":
  1079. $any = 1;
  1080. $criteria_content .= sprintf ('<tr><td><input type="radio" name="criteria[%d]" value="%d">
  1081. %s</td><td><b>%s</b></td><td><select name="attr%d%d[]">
  1082. <option value="0">Not checked
  1083. <option value="1">Checked</select></td></tr>',
  1084. $i,$attribute["id"],
  1085. $attribute["name"],$GLOBALS['I18N']->get('is'),$attribute["id"],$i);
  1086. break;
  1087. case "select":
  1088. case "radio":

Large files files are truncated, but you can click here to view the full file