PageRenderTime 63ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/phplist/index.php

https://github.com/radicaldesigns/amp
PHP | 700 lines | 621 code | 46 blank | 33 comment | 138 complexity | b5c8f076a8831a64b82eae7a914c4efc 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
  1. <?php
  2. ob_start();
  3. $er = error_reporting(0); # some ppl have warnings on
  4. if (isset($_SERVER["ConfigFile"]) && is_file($_SERVER["ConfigFile"])) {
  5. # print '<!-- using '.$_SERVER["ConfigFile"].'-->'."\n";
  6. include $_SERVER["ConfigFile"];
  7. } elseif (isset($_ENV["CONFIG"]) && is_file($_ENV["CONFIG"])) {
  8. # print '<!-- using '.$_ENV["CONFIG"].'-->'."\n";
  9. include $_ENV["CONFIG"];
  10. } elseif (is_file("config/config.php")) {
  11. # print '<!-- using config/config.php -->'."\n";
  12. include "config/config.php";
  13. } else {
  14. print "Error, cannot find config file\n";
  15. exit;
  16. }
  17. if (isset($GLOBALS["developer_email"])) {
  18. error_reporting(E_ALL);
  19. } else {
  20. error_reporting(0);
  21. }
  22. require_once dirname(__FILE__) .'/admin/commonlib/lib/magic_quotes.php';
  23. require_once dirname(__FILE__).'/admin/init.php';
  24. require_once dirname(__FILE__).'/admin/'.$GLOBALS["database_module"];
  25. require_once dirname(__FILE__)."/texts/english.inc";
  26. include_once dirname(__FILE__)."/texts/".$GLOBALS["language_module"];
  27. require_once dirname(__FILE__)."/admin/defaultconfig.inc";
  28. require_once dirname(__FILE__).'/admin/connect.php';
  29. include_once dirname(__FILE__)."/admin/languages.php";
  30. include_once dirname(__FILE__)."/admin/lib.php";
  31. $I18N= new phplist_I18N();
  32. if ($require_login || ASKFORPASSWORD) {
  33. # we need session info if an admin subscribes a user
  34. if (!empty($GLOBALS["SessionTableName"])) {
  35. require_once dirname(__FILE__).'/admin/sessionlib.php';
  36. }
  37. @session_start(); # it may have been started already in languages
  38. }
  39. if (!isset($_POST) && isset($HTTP_POST_VARS)) {
  40. require "admin/commonlib/lib/oldphp_vars.php";
  41. }
  42. /*
  43. We request you retain the inclusion of pagetop below. This will add invisible
  44. additional information to your public pages.
  45. This not only gives respect to the large amount of time given freely
  46. by the developers but also helps build interest, traffic and use of
  47. PHPlist, which is beneficial to it's future development.
  48. Michiel Dethmers, Tincan Ltd 2000,2004
  49. */
  50. include "admin/pagetop.php";
  51. if (isset($_GET['id'])) {
  52. $id = sprintf('%d',$_GET['id']);
  53. } else {
  54. $id = 0;
  55. }
  56. if (isset($_GET['uid']) && $_GET["uid"]) {
  57. $req = Sql_Fetch_Row_Query(sprintf('select subscribepage,id,password,email from %s where uniqid = "%s"',
  58. $tables["user"],$_GET["uid"]));
  59. $id = $req[0];
  60. $userid = $req[1];
  61. $userpassword = $req[2];
  62. $emailcheck = $req[3];
  63. } elseif (isset($_GET["email"])) {
  64. $req = Sql_Fetch_Row_Query(sprintf('select subscribepage,id,password,email from %s where email = "%s"',
  65. $tables["user"],$_GET["email"]));
  66. $id = $req[0];
  67. $userid = $req[1];
  68. $userpassword = $req[2];
  69. $emailcheck = $req[3];
  70. } elseif (isset($_REQUEST["unsubscribeemail"])) {
  71. $req = Sql_Fetch_Row_Query(sprintf('select subscribepage,id,password,email from %s where email = "%s"',
  72. $tables["user"],$_REQUEST["unsubscribeemail"]));
  73. $id = $req[0];
  74. $userid = $req[1];
  75. $userpassword = $req[2];
  76. $emailcheck = $req[3];
  77. /*
  78. } elseif ($_SESSION["userloggedin"] && $_SESSION["userid"]) {
  79. $req = Sql_Fetch_Row_Query(sprintf('select subscribepage,id,password,email from %s where id = %d',
  80. $tables["user"],$_SESSION["userid"]));
  81. $id = $req[0];
  82. $userid = $req[1];
  83. $userpassword = $req[2];
  84. $emailcheck = $req[3];
  85. */
  86. } else {
  87. $userid = "";
  88. $userpassword = "";
  89. $emailcheck = "";
  90. }
  91. if (isset($_REQUEST['id']) && $_REQUEST["id"]){
  92. $id = sprintf('%d',$_REQUEST["id"]);
  93. }
  94. # make sure the subscribe page still exists
  95. $req = Sql_fetch_row_query(sprintf('select id from %s where id = %d',$tables["subscribepage"],$id));
  96. $id = $req[0];
  97. $msg = "";
  98. if (!empty($_POST["sendpersonallocation"])) {
  99. if (isset($_POST['email']) && $_POST["email"]) {
  100. $uid = Sql_Fetch_Row_Query(sprintf('select uniqid,email,id from %s where email = "%s"',
  101. $tables["user"],$_POST["email"]));
  102. if ($uid[0]) {
  103. sendMail ($uid[1],getConfig("personallocation_subject"),getUserConfig("personallocation_message",$uid[2]),system_messageheaders(),$GLOBALS["envelope"]);
  104. $msg = $GLOBALS["strPersonalLocationSent"];
  105. addSubscriberStatistics('personal location sent',1);
  106. } else {
  107. $msg = $GLOBALS["strUserNotFound"];
  108. }
  109. }
  110. }
  111. if (isset($_GET['p']) && $_GET["p"] == "subscribe") {
  112. $_SESSION["userloggedin"] = 0;
  113. $_SESSION["userdata"] = array();
  114. }
  115. $login_required =
  116. (ASKFORPASSWORD && $userpassword && $_GET["p"] == "preferences") ||
  117. (ASKFORPASSWORD && UNSUBSCRIBE_REQUIRES_PASSWORD && $userpassword && $_GET["p"] == "unsubscribe");
  118. if ($login_required && empty($_SESSION["userloggedin"])) {
  119. $canlogin = 0;
  120. if (!empty($_POST["login"])) {
  121. if (empty($_POST["email"])) {
  122. $msg = $strEnterEmail;
  123. } elseif (empty($_POST["password"])) {
  124. $msg = $strEnterPassword;
  125. } else {
  126. if (ENCRYPTPASSWORD) {
  127. $canlogin = md5($_POST["password"]) == $userpassword && $_POST["email"] == $emailcheck;
  128. } else {
  129. $canlogin = $_POST["password"] == $userpassword && $_POST["email"] == $emailcheck;
  130. }
  131. }
  132. if (!$canlogin) {
  133. $msg = $strInvalidPassword;
  134. } else {
  135. loadUser($emailcheck);
  136. $_SESSION["userloggedin"] = $_SERVER["REMOTE_ADDR"];
  137. }
  138. } elseif (!empty($_POST["forgotpassword"])) {
  139. if (!empty($_POST["email"]) && $_POST["email"] == $emailcheck) {
  140. sendMail ($emailcheck,$GLOBALS["strPasswordRemindSubject"],$GLOBALS["strPasswordRemindMessage"]." ".$userpassword,system_messageheaders());
  141. $msg = $GLOBALS["strPasswordSent"];
  142. } else {
  143. $msg = $strPasswordRemindInfo;
  144. }
  145. } elseif (isset($_SESSION["userdata"]["email"]["value"]) && $_SESSION["userdata"]["email"]["value"] == $emailcheck) {
  146. $canlogin = $_SESSION["userloggedin"];
  147. $msg = $strEnterPassword;
  148. }
  149. } else {
  150. $canlogin = 1;
  151. }
  152. if (!$id) {
  153. # find the default one:
  154. $id = getConfig("defaultsubscribepage");
  155. # fix the true/false issue
  156. if ($id == "true") $id = 1;
  157. if ($id == "false") $id = 0;
  158. if (!$id) {
  159. # pick a first
  160. $req = Sql_Fetch_row_Query(sprintf('select ID from %s where active',$tables["subscribepage"]));
  161. $id = $req[0];
  162. }
  163. }
  164. if ($login_required && empty($_SESSION["userloggedin"]) && !$canlogin) {
  165. print LoginPage($id,$userid,$emailcheck,$msg);
  166. } elseif (isset($_GET['p']) && preg_match("/(\w+)/",$_GET["p"],$regs)) {
  167. if ($id) {
  168. switch ($_GET["p"]) {
  169. case "subscribe":
  170. require "admin/subscribelib2.php";
  171. print SubscribePage($id);
  172. break;
  173. case "preferences":
  174. if (!isset($_GET["id"]) || !$_GET['id']) $_GET["id"] = $id;
  175. require "admin/subscribelib2.php";
  176. if (!$userid) {
  177. # print "Userid not set".$_SESSION["userid"];
  178. print sendPersonalLocationPage($id);
  179. } elseif (ASKFORPASSWORD && $passwordcheck && !$canlogin) {
  180. print LoginPage($id,$userid,$emailcheck);
  181. } else {
  182. print PreferencesPage($id,$userid);
  183. }
  184. break;
  185. case "forward":
  186. print ForwardPage($id);
  187. break;
  188. case "confirm":
  189. print ConfirmPage($id);
  190. break;
  191. case "unsubscribe":
  192. print UnsubscribePage($id);
  193. break;
  194. default:
  195. FileNotFound();
  196. }
  197. } else {
  198. FileNotFound();
  199. }
  200. } else {
  201. if ($id) $data = PageData($id);
  202. print '<title>'.$GLOBALS["strSubscribeTitle"].'</title>';
  203. print $data["header"];
  204. $req = Sql_Query(sprintf('select * from %s where active',$tables["subscribepage"]));
  205. if (Sql_Affected_Rows()) {
  206. while ($row = Sql_Fetch_Array($req)) {
  207. $intro = Sql_Fetch_Row_Query(sprintf('select data from %s where id = %d and name = "intro"',$tables["subscribepage_data"],$row["id"]));
  208. print $intro[0];
  209. printf('<p><a href="./?p=subscribe&id=%d">%s</a></p>',$row["id"],$row["title"]);
  210. }
  211. } else {
  212. printf('<p><a href="./?p=subscribe">%s</a></p>',$strSubscribeTitle);
  213. }
  214. printf('<p><a href="./?p=unsubscribe">%s</a></p>',$strUnsubscribeTitle);
  215. print $PoweredBy;
  216. print $data["footer"];
  217. }
  218. function LoginPage($id,$userid,$email = "",$msg = "") {
  219. $data = PageData($id);
  220. list($attributes,$attributedata) = PageAttributes($data);
  221. $html = '<title>'.$GLOBALS["strLoginTitle"].'</title>';
  222. $html .= $data["header"];
  223. $html .= '<b>'.$GLOBALS["strLoginInfo"].'</b><br/>';
  224. $html .= $msg;
  225. if (isset($_REQUEST["email"])) {
  226. $email = $_REQUEST["email"];
  227. }
  228. if (!isset($_POST["password"])) {
  229. $_POST["password"] = '';
  230. }
  231. $html .= formStart('name="loginform"');
  232. $html .= '<table border=0>';
  233. $html .= '<tr><td>'.$GLOBALS["strEmail"].'</td><td><input type=text name="email" value="'.$email.'" size="30"></td></tr>';
  234. $html .= '<tr><td>'.$GLOBALS["strPassword"].'</td><td><input type=password name="password" value="'.$_POST["password"].'" size="30"></td></tr>';
  235. $html .= '</table>';
  236. $html .= '<p><input type=submit name="login" value="'.$GLOBALS["strLogin"].'"></p>';
  237. if (ENCRYPTPASSWORD) {
  238. $html .= sprintf('<a href="mailto:%s?subject=%s">%s</a>',getConfig("admin_address"),$GLOBALS["strForgotPassword"],$GLOBALS["strForgotPassword"]);
  239. } else {
  240. $html .= '<input type=submit name="forgotpassword" value="'.$GLOBALS["strForgotPassword"].'">';
  241. }
  242. $html .= '<br/><br/>
  243. <p><a href="'.getConfig("unsubscribeurl").'&id='.$id.'">'.$GLOBALS["strUnsubscribe"].'</a></p>';
  244. $html .= '</form>'.$GLOBALS["PoweredBy"];
  245. $html .= $data["footer"];
  246. return $html;
  247. }
  248. function sendPersonalLocationPage($id) {
  249. $data = PageData($id);
  250. list($attributes,$attributedata) = PageAttributes($data);
  251. $html = '<title>'.$GLOBALS["strPreferencesTitle"].'</title>';
  252. $html .= $data["header"];
  253. $html .= '<b>'.$GLOBALS["strPreferencesTitle"].'</b><br/>';
  254. $html .= $GLOBALS["msg"];
  255. if ($_REQUEST["email"]) {
  256. $email = $_REQUEST["email"];
  257. } elseif ($_SESSION["userdata"]["email"]["value"]) {
  258. $email = $_SESSION["userdata"]["email"]["value"];
  259. }
  260. $html .= $GLOBALS["strPersonalLocationInfo"];
  261. $html .= formStart('name="form"');
  262. $html .= '<table border=0>';
  263. $html .= '<tr><td>'.$GLOBALS["strEmail"].'</td><td><input type=text name="email" value="'.$email.'" size="30"></td></tr>';
  264. $html .= '</table>';
  265. $html .= '<p><input type=submit name="sendpersonallocation" value="'.$GLOBALS["strContinue"].'"></p>';
  266. $html .= '<br/><br/>
  267. <p><a href="'.getConfig("unsubscribeurl").'&id='.$id.'">'.$GLOBALS["strUnsubscribe"].'</a></p>';
  268. $html .= '</form>'.$GLOBALS["PoweredBy"];
  269. $html .= $data["footer"];
  270. return $html;
  271. }
  272. function preferencesPage($id,$userid) {
  273. $data = PageData($id);
  274. list($attributes,$attributedata) = PageAttributes($data);
  275. $selected_lists = explode(',',$data["lists"]);
  276. $html = '<title>'.$GLOBALS["strPreferencesTitle"].'</title>';
  277. $html .= $data["header"];
  278. $html .= '<b>'.$GLOBALS["strPreferencesInfo"].'</b>';
  279. $html .= '
  280. <br/><font class="required">'.$GLOBALS["strRequired"].'</font><br/>
  281. '.$GLOBALS["msg"].'
  282. <script language="Javascript" type="text/javascript">
  283. var fieldstocheck = new Array();
  284. fieldnames = new Array();
  285. function checkform() {
  286. for (i=0;i<fieldstocheck.length;i++) {
  287. if (eval("document.subscribeform.elements[\'"+fieldstocheck[i]+"\'].value") == "") {
  288. alert("'.$GLOBALS["strPleaseEnter"].' "+fieldnames[i]);
  289. eval("document.subscribeform.elements[\'"+fieldstocheck[i]+"\'].focus()");
  290. return false;
  291. }
  292. }
  293. ';
  294. if ($data['emaildoubleentry']=='yes')
  295. {
  296. $html .='
  297. if(! compareEmail())
  298. {
  299. alert("Email addresses you entered do not match");
  300. return false;
  301. }';
  302. }
  303. $html .='
  304. return true;
  305. }
  306. function addFieldToCheck(value,name) {
  307. fieldstocheck[fieldstocheck.length] = value;
  308. fieldnames[fieldnames.length] = name;
  309. }
  310. function compareEmail()
  311. {
  312. return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
  313. }
  314. </script>';
  315. $html .= formStart('name="subscribeform"');
  316. $html .= '<table border=0>';
  317. $html .= ListAttributes($attributes,$attributedata,$data["htmlchoice"],$userid,$data['emaildoubleentry']);
  318. $html .= '</table>';
  319. if (ENABLE_RSS) {
  320. $html .= RssOptions($data,$userid);
  321. }
  322. $html .= ListAvailableLists($userid,$data["lists"]);
  323. if (isBlackListedID($userid)) {
  324. $html .= $GLOBALS["strYouAreBlacklisted"];
  325. }
  326. $html .= '<p><input type=submit name="update" value="'.$GLOBALS["strUpdatePreferences"].'" onClick="return checkform();"></p>
  327. </form><br/><br/>
  328. <p><a href="'.getConfig("unsubscribeurl").'&id='.$id.'">'.$GLOBALS["strUnsubscribe"].'</a></p>
  329. '.$GLOBALS["PoweredBy"];
  330. $html .= $data["footer"];
  331. return $html;
  332. }
  333. function subscribePage($id) {
  334. $data = PageData($id);
  335. list($attributes,$attributedata) = PageAttributes($data);
  336. $selected_lists = explode(',',$data["lists"]);
  337. $html = '<title>'.$GLOBALS["strSubscribeTitle"].'</title>';
  338. $html .= $data["header"];
  339. $html .= $data["intro"];
  340. $html .= '
  341. <br/><font class="required">'.$GLOBALS["strRequired"].'</font><br/>
  342. '.$GLOBALS["msg"].'
  343. <script language="Javascript" type="text/javascript">
  344. var fieldstocheck = new Array();
  345. fieldnames = new Array();
  346. function checkform() {
  347. for (i=0;i<fieldstocheck.length;i++) {
  348. if (eval("document.subscribeform.elements[\'"+fieldstocheck[i]+"\'].value") == "") {
  349. alert("'.$GLOBALS["strPleaseEnter"].' "+fieldnames[i]);
  350. eval("document.subscribeform.elements[\'"+fieldstocheck[i]+"\'].focus()");
  351. return false;
  352. }
  353. }
  354. ';
  355. if ($data['emaildoubleentry']=='yes')
  356. {
  357. $html .='
  358. if(! compareEmail())
  359. {
  360. alert("Email addresses you entered do not match");
  361. return false;
  362. }';
  363. }
  364. $html .='
  365. return true;
  366. }
  367. function addFieldToCheck(value,name) {
  368. fieldstocheck[fieldstocheck.length] = value;
  369. fieldnames[fieldnames.length] = name;
  370. }
  371. function compareEmail()
  372. {
  373. return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
  374. }
  375. </script>';
  376. $html .= formStart('name="subscribeform"');
  377. # @@@ update
  378. if (isset($_SESSION["adminloggedin"]) && $_SESSION["adminloggedin"]) {
  379. $html .= '<style type="text/css">
  380. div.adminmessage {
  381. width: 100%;
  382. border: 2px dashed #000000;
  383. padding: 10px;
  384. margin-bottom: 15px;
  385. background-color: #E7BE8F;
  386. }
  387. </style>';
  388. $html .= '<div class="adminmessage"><p><b>You are logged in as administrator ('.$_SESSION["logindetails"]["adminname"].') of this phplist system</b></p>';
  389. $html .= '<p>You are therefore offered the following choice, which your users will not see when they load this page.</p>';
  390. $html .= '<p><b>Please choose</b>: <br/><input type=radio name="makeconfirmed" value="1"> Make this user confirmed immediately
  391. <br/><input type=radio name="makeconfirmed" value="0" checked> Send this user a request for confirmation email </p></div>';
  392. }
  393. $html .= '<table border=0>';
  394. $html .= ListAttributes($attributes,$attributedata,$data["htmlchoice"],0,$data['emaildoubleentry']);
  395. $html .= '</table>';
  396. if (ENABLE_RSS) {
  397. $html .= RssOptions($data);
  398. }
  399. $html .= ListAvailableLists("",$data["lists"]);
  400. $html .= '<p><input type=submit name="subscribe" value="'.$data["button"].'" onClick="return checkform();"></p>
  401. </form><br/><br/>
  402. <p><a href="'.getConfig("unsubscribeurl").'&id='.$id.'">'.$GLOBALS["strUnsubscribe"].'</a></p>
  403. '.$GLOBALS["PoweredBy"];
  404. $html .= $data["footer"];
  405. return $html;
  406. }
  407. function confirmPage($id) {
  408. global $tables,$envelope;
  409. if (!$_GET["uid"]) {
  410. FileNotFound();
  411. }
  412. $req = Sql_Query("select * from {$tables["user"]} where uniqid = \"".$_GET["uid"]."\"");
  413. $userdata = Sql_Fetch_Array($req);
  414. if ($userdata["id"]) {
  415. $blacklisted = isBlackListed($userdata["email"]);
  416. $html = '<ul>';
  417. $lists = '';
  418. Sql_Query("update {$tables["user"]} set confirmed = 1,blacklisted = 0 where id = ".$userdata["id"]);
  419. $req = Sql_Query(sprintf('select name,description from %s list, %s listuser where listuser.userid = %d and listuser.listid = list.id and list.active',$tables['list'],$tables['listuser'],$userdata['id']));
  420. if (!Sql_Affected_Rows()) {
  421. $lists = "\n * ".$GLOBALS["strNoLists"];
  422. $html .= '<li>'.$GLOBALS["strNoLists"].'</li>';
  423. }
  424. while ($row = Sql_fetch_array($req)) {
  425. $lists .= "\n *".$row["name"];
  426. $html .= '<li class="list">'.$row["name"].'<div class="listdescription">'.stripslashes($row["description"]).'</div></li>';
  427. }
  428. $html .= '</ul>';
  429. if ($blacklisted) {
  430. unBlackList($userdata['id']);
  431. addUserHistory($userdata["email"],"Confirmation","User removed from Blacklist for manual confirmation of subscription");
  432. }
  433. addUserHistory($userdata["email"],"Confirmation","Lists: $lists");
  434. $spage = $userdata["subscribepage"];
  435. $confirmationmessage = ereg_replace('\[LISTS\]', $lists, getUserConfig("confirmationmessage:$spage",$userdata["id"]));
  436. if (!TEST) {
  437. sendMail($userdata["email"], getConfig("confirmationsubject:$spage"), $confirmationmessage,system_messageheaders(),$envelope);
  438. $adminmessage = $userdata["email"] . " has confirmed their subscription";
  439. if ($blacklisted) {
  440. $adminmessage .= "\nUser has been removed from blacklist";
  441. }
  442. sendAdminCopy("List confirmation",$adminmessage);
  443. addSubscriberStatistics('confirmation',1);
  444. }
  445. $info = $GLOBALS["strConfirmInfo"];
  446. } else {
  447. logEvent("Request for confirmation for invalid user ID: ".substr($_GET["uid"],0,150));
  448. $html .= 'Error: '.$GLOBALS["strUserNotFound"];
  449. $info = $GLOBALS["strConfirmFailInfo"];
  450. }
  451. $data = PageData($id);
  452. $res = '<title>'.$GLOBALS["strConfirmTitle"].'</title>';
  453. $res .= $data["header"];
  454. $res .= '<h1>'.$info.'</h1>';
  455. $res .= $html;
  456. $res .= "<P>".$GLOBALS["PoweredBy"].'</p>';
  457. $res .= $data["footer"];
  458. return $res;
  459. }
  460. function unsubscribePage($id) {
  461. $pagedata = pageData($id);
  462. global $tables;
  463. $res = $pagedata["header"];
  464. $res .= '<title>'.$GLOBALS["strUnsubscribeTitle"].'</title>';
  465. if (isset($_GET["uid"])) {
  466. $req = Sql_Query("select * from $tables[user] where uniqid = \"".$_GET["uid"]."\"");
  467. $userdata = Sql_Fetch_Array($req);
  468. $email = $userdata["email"];
  469. if (UNSUBSCRIBE_JUMPOFF) {
  470. $_POST["unsubscribe"] = 1;
  471. $_POST["email"] = $email;
  472. $_POST["unsubscribereason"] = '"Jump off" set, reason not requested';
  473. }
  474. }
  475. if (isset($_POST["unsubscribe"]) && (isset($_POST["email"]) || isset($_POST["unsubscribeemail"])) && isset($_POST["unsubscribereason"])) {
  476. if (isset($_POST["email"])) {
  477. $email = trim($_POST["email"]);
  478. } else {
  479. $email = $_POST["unsubscribeemail"];
  480. }
  481. $query = Sql_Fetch_Row_Query("select id,email from {$tables["user"]} where email = \"$email\"");
  482. $userid = $query[0];
  483. $email = $query[1];
  484. if (!$userid) {
  485. $res .= 'Error: '.$GLOBALS["strUserNotFound"];
  486. logEvent("Request to unsubscribe non-existent user: ".substr($_POST["email"],0,150));
  487. } else {
  488. $result = Sql_query("delete from {$tables["listuser"]} where userid = \"$userid\"");
  489. $lists = " * ".$GLOBALS["strAllMailinglists"]."\n";
  490. # add user to blacklist
  491. addUserToBlacklist($email,$_POST['unsubscribereason']);
  492. addUserHistory($email,"Unsubscription","Unsubscribed from $lists");
  493. $unsubscribemessage = ereg_replace("\[LISTS\]", $lists,getUserConfig("unsubscribemessage",$userid));
  494. sendMail($email, getConfig("unsubscribesubject"), stripslashes($unsubscribemessage), system_messageheaders($email));
  495. $reason = $_POST["unsubscribereason"] ? "Reason given:\n".stripslashes($_POST["unsubscribereason"]):"No Reason given";
  496. sendAdminCopy("List unsubscription",$email . " has unsubscribed\n$reason");
  497. addSubscriberStatistics('unsubscription',1);
  498. }
  499. if ($userid)
  500. $res .= '<h1>'.$GLOBALS["strUnsubscribeDone"] ."</h1><P>";
  501. $res .= $GLOBALS["PoweredBy"].'</p>';
  502. $res .= $pagedata["footer"];
  503. return $res;
  504. } elseif (isset($_POST["unsubscribe"]) && !$_POST["unsubscribeemail"]) {
  505. $msg = '<span class="error">'.$GLOBALS["strEnterEmail"]."</span><br>";
  506. } elseif (!empty($_GET["email"])) {
  507. $email = trim($_GET["email"]);
  508. } else {
  509. if (isset($_REQUEST["email"])) {
  510. $email = $_REQUEST["email"];
  511. } elseif (isset($_REQUEST['unsubscribeemail'])) {
  512. $email = $_REQUEST['unsubscribeemail'];
  513. } elseif (!isset($email)) {
  514. $email = '';
  515. }
  516. }
  517. if (!isset($msg)) {
  518. $msg = '';
  519. }
  520. $res .= '<b>'. $GLOBALS["strUnsubscribeInfo"].'</b><br>'.
  521. $msg.formStart();
  522. $res .= '<table>
  523. <tr><td>'.$GLOBALS["strEnterEmail"].':</td><td colspan=3><input type=text name="unsubscribeemail" value="'.$email.'" size=40></td></tr>
  524. </table>';
  525. if (!$email) {
  526. $res .= "<input type=submit name=unsubscribe value=\"$GLOBALS[strContinue]\"></form>\n";
  527. $res .= $GLOBALS["PoweredBy"];
  528. $res .= $pagedata["footer"];
  529. return $res;
  530. }
  531. $current = Sql_Fetch_Array_query("SELECT list.id as listid,user.uniqid as userhash FROM $tables[list] as list,$tables[listuser] as listuser,$tables[user] as user where list.id = listuser.listid and user.id = listuser.userid and user.email = \"$email\"");
  532. $some = $current["listid"];
  533. $hash = $current["userhash"];
  534. $finaltext = $GLOBALS["strUnsubscribeFinalInfo"];
  535. $pref_url = getConfig("preferencesurl");
  536. $sep = ereg('\?',$pref_url)?'&':'?';
  537. $finaltext = eregi_replace('\[preferencesurl\]',$pref_url.$sep.'uid='.$hash,$finaltext);
  538. if (!$some) {
  539. $res .= "<b>".$GLOBALS["strNoListsFound"]."</b></ul>";
  540. $res .= '<p><input type=submit value="'.$GLOBALS["strResubmit"].'">';
  541. } else {
  542. list($r,$c) = explode(",",getConfig("textarea_dimensions"));
  543. if (!$r) $r = 5;
  544. if (!$c) $c = 65;
  545. $res .= $GLOBALS["strUnsubscribeRequestForReason"];
  546. $res .= sprintf('<br/><textarea name="unsubscribereason" cols="%d" rows="%d" wrap="virtual"></textarea>',$c,$r).'
  547. '.$finaltext.'
  548. <p><input type=submit name="unsubscribe" value="'.$GLOBALS["strUnsubscribe"].'"></p>';
  549. }
  550. $res .= '<p>'.$GLOBALS["PoweredBy"].'</p>';
  551. $res .= $pagedata["footer"];
  552. return $res;
  553. }
  554. function forwardPage($id) {
  555. global $tables,$envelope;
  556. $html = '';
  557. $subtitle = '';
  558. if (!isset($_GET["uid"]) || !$_GET['uid'])
  559. FileNotFound();
  560. $forwardemail = '';
  561. if (isset($_GET['email'])) {
  562. $forwardemail = $_GET['email'];
  563. }
  564. $mid = 0;
  565. if (isset($_GET['mid'])) {
  566. $mid = sprintf('%d',$_GET['mid']);
  567. $req = Sql_Query(sprintf('select * from %s where id = %d',$tables["message"],$mid));
  568. $messagedata = Sql_Fetch_Array($req);
  569. $mid = $messagedata['id'];
  570. if ($mid) {
  571. $subtitle = $GLOBALS['strForwardSubtitle'].' '.stripslashes($messagedata['subject']);
  572. }
  573. }
  574. $req = Sql_Query("select * from {$tables["user"]} where uniqid = \"".$_GET["uid"]."\"");
  575. $userdata = Sql_Fetch_Array($req);
  576. $req = Sql_Query(sprintf('select * from %s where email = "%s"',$tables["user"],$forwardemail));
  577. $forwarduserdata = Sql_Fetch_Array($req);
  578. if ($userdata["id"] && $mid) {
  579. if (!is_email($forwardemail)) {
  580. $info = $GLOBALS['strForwardEnterEmail'];
  581. $html .= '<form method="get">';
  582. $html .= sprintf('<input type=hidden name="mid" value="%d">',$mid);
  583. $html .= sprintf('<input type=hidden name="id" value="%d">',$id);
  584. $html .= sprintf('<input type=hidden name="uid" value="%s">',$userdata['uniqid']);
  585. $html .= sprintf('<input type=hidden name="p" value="forward">');
  586. $html .= sprintf('<input type=text name="email" value="%s" size=35 class="attributeinput">',$forwardemail);
  587. $html .= sprintf('<input type=submit value="%s"></form>',$GLOBALS['strContinue']);
  588. } else {
  589. # check whether the email to forward exists and whether they have received the message
  590. if ($forwarduserdata['id']) {
  591. $sent = Sql_Fetch_Row_Query(sprintf('select entered from %s where userid = %d and messageid = %d',
  592. $tables['usermessage'],$forwarduserdata['id'],$mid));
  593. # however even if that's the case, we don't want to reveal this information
  594. }
  595. $done = Sql_Fetch_Array_Query(sprintf('select user,status,time from %s where forward = "%s" and message = %d',
  596. $tables['user_message_forward'],$forwardemail,$mid));
  597. if ($done['status'] === 'sent') {
  598. $info = $GLOBALS['strForwardAlreadyDone'];
  599. } else {
  600. if (!TEST) {
  601. # forward the message
  602. require 'admin/sendemaillib.php';
  603. # sendEmail will take care of blacklisting
  604. if (sendEmail($mid,$forwardemail,'forwarded',$userdata['htmlemail'],array(),$userdata)) {
  605. $info = $GLOBALS["strForwardSuccessInfo"];
  606. sendAdminCopy("Message Forwarded",$userdata["email"] . " has forwarded a message $mid to $forwardemail");
  607. Sql_Query(sprintf('insert into %s (user,message,forward,status,time)
  608. values(%d,%d,"%s","sent",now())',
  609. $tables['user_message_forward'],$userdata['id'],$mid,$forwardemail));
  610. } else {
  611. $info = $GLOBALS["strForwardFailInfo"];
  612. sendAdminCopy("Message Forwarded",$userdata["email"] . " tried forwarding a message $mid to $forwardemail but failed");
  613. Sql_Query(sprintf('insert into %s (user,message,forward,status,time)
  614. values(%d,%d,"%s","failed",now())',
  615. $tables['user_message_forward'],$userdata['id'],$mid,$forwardemail));
  616. }
  617. }
  618. }
  619. }
  620. } else {
  621. logEvent("Forward request from invalid user ID: ".substr($_GET["uid"],0,150));
  622. $info = $GLOBALS["strForwardFailInfo"];
  623. }
  624. $data = PageData($id);
  625. $res = '<title>'.$GLOBALS["strForwardTitle"].'</title>';
  626. $res .= $data["header"];
  627. $res .= '<h1>'.$subtitle.'</h1>';
  628. $res .= '<h2>'.$info.'</h2>';
  629. $res .= $html;
  630. $res .= "<P>".$GLOBALS["PoweredBy"].'</p>';
  631. $res .= $data["footer"];
  632. return $res;
  633. }
  634. ?>