PageRenderTime 76ms CodeModel.GetById 42ms RepoModel.GetById 0ms app.codeStats 1ms

/lists/index.php

https://bitbucket.org/bontiv/insomnia
PHP | 968 lines | 818 code | 71 blank | 79 comment | 212 complexity | 948f30ce8db5960409e002d2d706691f MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-3.0, BSD-3-Clause, GPL-2.0
  1. <?php
  2. ob_start();
  3. $er = error_reporting(0);
  4. require_once dirname(__FILE__) .'/admin/commonlib/lib/unregister_globals.php';
  5. require_once dirname(__FILE__) .'/admin/commonlib/lib/magic_quotes.php';
  6. require_once dirname(__FILE__).'/admin/init.php';
  7. ## none of our parameters can contain html for now
  8. $_GET = removeXss($_GET);
  9. $_POST = removeXss($_POST);
  10. $_REQUEST = removeXss($_REQUEST);
  11. $_SERVER = removeXss($_SERVER);
  12. if (isset($_SERVER["ConfigFile"]) && is_file($_SERVER["ConfigFile"])) {
  13. # print '<!-- using '.$_SERVER["ConfigFile"].'-->'."\n";
  14. include $_SERVER["ConfigFile"];
  15. } elseif (isset($_ENV["CONFIG"]) && is_file($_ENV["CONFIG"])) {
  16. # print '<!-- using '.$_ENV["CONFIG"].'-->'."\n";
  17. include $_ENV["CONFIG"];
  18. } elseif (is_file("config/config.php")) {
  19. # print '<!-- using config/config.php -->'."\n";
  20. include "config/config.php";
  21. } else {
  22. print "Error, cannot find config file\n";
  23. exit;
  24. }
  25. if (0) {#isset($GLOBALS["developer_email"]) && $GLOBALS['show_dev_errors']) {
  26. error_reporting(E_ALL);
  27. } else {
  28. error_reporting(0);
  29. }
  30. require_once dirname(__FILE__).'/admin/'.$GLOBALS["database_module"];
  31. # load default english and language
  32. require_once dirname(__FILE__)."/texts/english.inc";
  33. include_once dirname(__FILE__)."/texts/".$GLOBALS["language_module"];
  34. # Allow customisation per installation
  35. if (is_file($_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS["language_module"])) {
  36. include_once $_SERVER['DOCUMENT_ROOT'].'/'.$GLOBALS["language_module"];
  37. }
  38. require_once dirname(__FILE__)."/admin/defaultconfig.inc";
  39. require_once dirname(__FILE__).'/admin/connect.php';
  40. include_once dirname(__FILE__)."/admin/languages.php";
  41. include_once dirname(__FILE__)."/admin/lib.php";
  42. $I18N= new phplist_I18N();
  43. if ($require_login || ASKFORPASSWORD) {
  44. # we need session info if an admin subscribes a user
  45. if (!empty($GLOBALS["SessionTableName"])) {
  46. require_once dirname(__FILE__).'/admin/sessionlib.php';
  47. }
  48. @session_start(); # it may have been started already in languages
  49. }
  50. if (!isset($_POST) && isset($HTTP_POST_VARS)) {
  51. require "admin/commonlib/lib/oldphp_vars.php";
  52. }
  53. /*
  54. We request you retain the inclusion of pagetop below. This will add invisible
  55. additional information to your public pages.
  56. This not only gives respect to the large amount of time given freely
  57. by the developers but also helps build interest, traffic and use of
  58. PHPlist, which is beneficial to it's future development.
  59. Michiel Dethmers, phpList Ltd 2000,2006
  60. */
  61. include "admin/pagetop.php";
  62. if (isset($_GET['id'])) {
  63. $id = sprintf('%d',$_GET['id']);
  64. } else {
  65. $id = 0;
  66. }
  67. // What is id,
  68. // What is uid
  69. // What is userid
  70. // Why is there GET(id) and REQUEST(id)?
  71. $userid = "";
  72. $userpassword = "";
  73. $emailcheck = "";
  74. if (isset($_GET['uid']) && $_GET["uid"]) {
  75. $req = Sql_Fetch_Row_Query(sprintf('select subscribepage,id,password,email from %s where uniqid = "%s"',
  76. $tables["user"],$_GET["uid"]));
  77. $id = $req[0];
  78. $userid = $req[1];
  79. $userpassword = $req[2];
  80. $emailcheck = $req[3];
  81. } elseif ($_GET['p'] == 'unsubscribe' || $_GET['p'] == 'blacklist' || $_GET['p'] == 'subscribe') {
  82. if (isset($_GET["email"]) && validateEmail($_GET['email'])) {
  83. $req = Sql_Fetch_Row_Query(sprintf('select subscribepage,id,password,email from %s where email = "%s"',
  84. $tables["user"],$_GET["email"]));
  85. $id = $req[0];
  86. $userid = $req[1];
  87. $userpassword = $req[2];
  88. $emailcheck = $req[3];
  89. } elseif (isset($_REQUEST["unsubscribeemail"]) && validateEmail($_REQUEST['unsubscribeemail'])) {
  90. $req = Sql_Fetch_Row_Query(sprintf('select subscribepage,id,password,email from %s where email = "%s"',
  91. $tables["user"],$_REQUEST["unsubscribeemail"]));
  92. $id = $req[0];
  93. $userid = $req[1];
  94. $userpassword = $req[2];
  95. $emailcheck = $req[3];
  96. /*
  97. } elseif ($_SESSION["userloggedin"] && $_SESSION["userid"]) {
  98. $req = Sql_Fetch_Row_Query(sprintf('select subscribepage,id,password,email from %s where id = %d',
  99. $tables["user"],$_SESSION["userid"]));
  100. $id = $req[0];
  101. $userid = $req[1];
  102. $userpassword = $req[2];
  103. $emailcheck = $req[3];
  104. */
  105. }
  106. }
  107. if (isset($_REQUEST['id']) && $_REQUEST["id"]){
  108. $id = sprintf('%d',$_REQUEST["id"]);
  109. }
  110. # make sure the subscribe page still exists
  111. $req = Sql_fetch_row_query(sprintf('select id from %s where id = %d',$tables["subscribepage"],$id));
  112. $id = $req[0];
  113. $msg = "";
  114. if (!empty($_POST["sendpersonallocation"])) {
  115. if (isset($_POST['email']) && $_POST["email"]) {
  116. $uid = Sql_Fetch_Row_Query(sprintf('select uniqid,email,id from %s where email = "%s"',
  117. $tables["user"],$_POST["email"]));
  118. if ($uid[0]) {
  119. sendMail ($uid[1],getConfig("personallocation_subject"),getUserConfig("personallocation_message",$uid[2]),system_messageheaders(),$GLOBALS["envelope"]);
  120. $msg = $GLOBALS["strPersonalLocationSent"];
  121. addSubscriberStatistics('personal location sent',1);
  122. } else {
  123. $msg = $GLOBALS["strUserNotFound"];
  124. }
  125. }
  126. }
  127. if (isset($_GET['p']) && $_GET["p"] == "subscribe") {
  128. $_SESSION["userloggedin"] = 0;
  129. $_SESSION["userdata"] = array();
  130. }
  131. $login_required =
  132. (ASKFORPASSWORD && $userpassword && $_GET["p"] == "preferences") ||
  133. (ASKFORPASSWORD && UNSUBSCRIBE_REQUIRES_PASSWORD && $userpassword && $_GET["p"] == "unsubscribe");
  134. if ($login_required && empty($_SESSION["userloggedin"])) {
  135. $canlogin = 0;
  136. if (!empty($_POST["login"])) {
  137. # login button pushed, let's check formdata
  138. if (empty($_POST["email"])) {
  139. $msg = $strEnterEmail;
  140. } elseif (empty($_POST["password"])) {
  141. $msg = $strEnterPassword;
  142. } else {
  143. if (ENCRYPTPASSWORD) {
  144. $canlogin = md5($_POST["password"]) == $userpassword && $_POST["email"] == $emailcheck;
  145. } else {
  146. $canlogin = $_POST["password"] == $userpassword && $_POST["email"] == $emailcheck;
  147. }
  148. }
  149. if (!$canlogin) {
  150. $msg = $strInvalidPassword;
  151. } else {
  152. loadUser($emailcheck);
  153. $_SESSION["userloggedin"] = $_SERVER["REMOTE_ADDR"];
  154. }
  155. } elseif (!empty($_POST["forgotpassword"])) {
  156. # forgot password button pushed
  157. if (!empty($_POST["email"]) && $_POST["email"] == $emailcheck) {
  158. sendMail ($emailcheck,$GLOBALS["strPasswordRemindSubject"],$GLOBALS["strPasswordRemindMessage"]." ".$userpassword,system_messageheaders());
  159. $msg = $GLOBALS["strPasswordSent"];
  160. } else {
  161. $msg = $strPasswordRemindInfo;
  162. }
  163. } elseif (isset($_SESSION["userdata"]["email"]["value"]) && $_SESSION["userdata"]["email"]["value"] == $emailcheck) {
  164. # Entry without any button pushed (first time) test and, if needed, ask for password
  165. $canlogin = $_SESSION["userloggedin"];
  166. $msg = $strEnterPassword;
  167. }
  168. } else {
  169. # Logged into session or login not required
  170. $canlogin = 1;
  171. }
  172. if (!$id) {
  173. # find the default one:
  174. $id = getConfig("defaultsubscribepage");
  175. # fix the true/false issue
  176. if ($id == "true") $id = 1;
  177. if ($id == "false") $id = 0;
  178. if (!$id) {
  179. # pick a first
  180. $req = Sql_Fetch_row_Query(sprintf('select ID from %s where active',$tables["subscribepage"]));
  181. $id = $req[0];
  182. }
  183. }
  184. if ($login_required && empty($_SESSION["userloggedin"]) && !$canlogin) {
  185. print LoginPage($id,$userid,$emailcheck,$msg);
  186. } elseif (isset($_GET['p']) && preg_match("/(\w+)/",$_GET["p"],$regs)) {
  187. if ($id) {
  188. $data = PageData($id);
  189. if (isset($data['language_file']) && is_file(dirname(__FILE__).'/texts/'.basename($data['language_file']))) {
  190. @include dirname(__FILE__).'/texts/'.basename($data['language_file']);
  191. # Allow customisation per installation
  192. if (is_file($_SERVER['DOCUMENT_ROOT'].'/'.basename($data['language_file']))) {
  193. include_once $_SERVER['DOCUMENT_ROOT'].'/'.basename($data['language_file']);
  194. }
  195. }
  196. switch ($_GET["p"]) {
  197. case "subscribe":
  198. $success = require "admin/subscribelib2.php";
  199. if ($success != 2) {
  200. print SubscribePage($id);
  201. }
  202. break;
  203. case "preferences":
  204. if (!isset($_GET["id"]) || !$_GET['id']) $_GET["id"] = $id;
  205. $success = require "admin/subscribelib2.php";
  206. if (!$userid) {
  207. # print "Userid not set".$_SESSION["userid"];
  208. print sendPersonalLocationPage($id);
  209. } elseif (ASKFORPASSWORD && $userpassword && !$canlogin) {
  210. print LoginPage($id,$userid,$emailcheck);
  211. } elseif ($success != 3) {
  212. print PreferencesPage($id,$userid);
  213. }
  214. break;
  215. case "forward":
  216. print ForwardPage($id);
  217. break;
  218. case "confirm":
  219. print ConfirmPage($id);
  220. break;
  221. #0013076: Blacklisting posibility for unknown users
  222. case "blacklist":
  223. case "unsubscribe":
  224. print UnsubscribePage($id);
  225. break;
  226. default:
  227. FileNotFound();
  228. }
  229. } else {
  230. FileNotFound();
  231. }
  232. } else {
  233. if ($id) $data = PageData($id);
  234. if (isset($data['language_file']) && is_file(dirname(__FILE__).'/texts/'.basename($data['language_file']))) {
  235. @include dirname(__FILE__).'/texts/'.basename($data['language_file']);
  236. }
  237. print '<title>'.$GLOBALS["strSubscribeTitle"].'</title>';
  238. print $data["header"];
  239. $req = Sql_Query(sprintf('select * from %s where active',$tables["subscribepage"]));
  240. if (Sql_Affected_Rows()) {
  241. while ($row = Sql_Fetch_Array($req)) {
  242. $intro = Sql_Fetch_Row_Query(sprintf('select data from %s where id = %d and name = "intro"',$tables["subscribepage_data"],$row["id"]));
  243. print $intro[0];
  244. printf('<p><a href="./?p=subscribe&id=%d">%s</a></p>',$row["id"],$row["title"]);
  245. }
  246. } else {
  247. printf('<p><a href="./?p=subscribe">%s</a></p>',$strSubscribeTitle);
  248. }
  249. printf('<p><a href="./?p=unsubscribe">%s</a></p>',$strUnsubscribeTitle);
  250. print $PoweredBy;
  251. print $data["footer"];
  252. }
  253. function LoginPage($id,$userid,$email = "",$msg = "") {
  254. $data = PageData($id);
  255. list($attributes,$attributedata) = PageAttributes($data);
  256. $html = '<title>'.$GLOBALS["strLoginTitle"].'</title>';
  257. $html .= $data["header"];
  258. $html .= '<b>'.$GLOBALS["strLoginInfo"].'</b><br/>';
  259. $html .= $msg;
  260. if (isset($_REQUEST["email"])) {
  261. $email = $_REQUEST["email"];
  262. }
  263. if (!isset($_POST["password"])) {
  264. $_POST["password"] = '';
  265. }
  266. $html .= formStart('name="loginform"');
  267. $html .= '<table border=0>';
  268. $html .= '<tr><td>'.$GLOBALS["strEmail"].'</td><td><input type=text name="email" value="'.$email.'" size="30"></td></tr>';
  269. $html .= '<tr><td>'.$GLOBALS["strPassword"].'</td><td><input type="password" name="password" value="'.$_POST["password"].'" size="30"></td></tr>';
  270. $html .= '</table>';
  271. $html .= '<p><input type=submit name="login" value="'.$GLOBALS["strLogin"].'"></p>';
  272. if (ENCRYPTPASSWORD) {
  273. $html .= sprintf('<a href="mailto:%s?subject=%s">%s</a>',getConfig("admin_address"),$GLOBALS["strForgotPassword"],$GLOBALS["strForgotPassword"]);
  274. } else {
  275. $html .= '<input type=submit name="forgotpassword" value="'.$GLOBALS["strForgotPassword"].'">';
  276. }
  277. $html .= '<br/><br/>
  278. <p><a href="'.getConfig("unsubscribeurl").'&id='.$id.'">'.$GLOBALS["strUnsubscribe"].'</a></p>';
  279. $html .= '</form>'.$GLOBALS["PoweredBy"];
  280. $html .= $data["footer"];
  281. return $html;
  282. }
  283. function sendPersonalLocationPage($id) {
  284. global $data ;
  285. list($attributes,$attributedata) = PageAttributes($data);
  286. $html = '<title>'.$GLOBALS["strPreferencesTitle"].'</title>';
  287. $html .= $data["header"];
  288. $html .= '<b>'.$GLOBALS["strPreferencesTitle"].'</b><br/>';
  289. $html .= $GLOBALS["msg"];
  290. if ($_REQUEST["email"]) {
  291. $email = $_REQUEST["email"];
  292. } elseif ($_SESSION["userdata"]["email"]["value"]) {
  293. $email = $_SESSION["userdata"]["email"]["value"];
  294. }
  295. $html .= $GLOBALS["strPersonalLocationInfo"];
  296. $html .= formStart('name="form"');
  297. $html .= '<table border=0>';
  298. $html .= '<tr><td>'.$GLOBALS["strEmail"].'</td><td><input type=text name="email" value="'.$email.'" size="30"></td></tr>';
  299. $html .= '</table>';
  300. $html .= '<p><input type=submit name="sendpersonallocation" value="'.$GLOBALS["strContinue"].'"></p>';
  301. $html .= '<br/><br/>
  302. <p><a href="'.getConfig("unsubscribeurl").'&id='.$id.'">'.$GLOBALS["strUnsubscribe"].'</a></p>';
  303. $html .= '</form>'.$GLOBALS["PoweredBy"];
  304. $html .= $data["footer"];
  305. return $html;
  306. }
  307. function preferencesPage($id,$userid) {
  308. global $data;
  309. list($attributes,$attributedata) = PageAttributes($data);
  310. $selected_lists = explode(',',$data["lists"]);
  311. $html = '<title>'.$GLOBALS["strPreferencesTitle"].'</title>';
  312. $html .= $data["header"];
  313. $html .= '<b>'.$GLOBALS["strPreferencesInfo"].'</b>';
  314. $html .= '
  315. <br/><font class="required">'.$GLOBALS["strRequired"].'</font><br/>
  316. '.$GLOBALS["msg"].'
  317. <script language="Javascript" type="text/javascript">
  318. var fieldstocheck = new Array();
  319. fieldnames = new Array();
  320. function checkform() {
  321. for (i=0;i<fieldstocheck.length;i++) {
  322. if (eval("document.subscribeform.elements[\'"+fieldstocheck[i]+"\'].value") == "") {
  323. alert("'.$GLOBALS["strPleaseEnter"].' "+fieldnames[i]);
  324. eval("document.subscribeform.elements[\'"+fieldstocheck[i]+"\'].focus()");
  325. return false;
  326. }
  327. }
  328. ';
  329. if ($data['emaildoubleentry']=='yes')
  330. {
  331. $html .='
  332. if(! compareEmail())
  333. {
  334. alert("Email addresses you entered do not match");
  335. return false;
  336. }';
  337. }
  338. $html .='
  339. return true;
  340. }
  341. function addFieldToCheck(value,name) {
  342. fieldstocheck[fieldstocheck.length] = value;
  343. fieldnames[fieldnames.length] = name;
  344. }
  345. function compareEmail()
  346. {
  347. return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
  348. }
  349. </script>';
  350. $html .= formStart('name="subscribeform"');
  351. $html .= '<table border=0>';
  352. $html .= ListAttributes($attributes,$attributedata,$data["htmlchoice"],$userid,$data['emaildoubleentry']);
  353. $html .= '</table>';
  354. if (ENABLE_RSS) {
  355. $html .= RssOptions($data,$userid);
  356. }
  357. $html .= ListAvailableLists($userid,$data["lists"]);
  358. if (isBlackListedID($userid)) {
  359. $html .= $GLOBALS["strYouAreBlacklisted"];
  360. }
  361. $html .= '<p><input type=submit name="update" value="'.$GLOBALS["strUpdatePreferences"].'" onClick="return checkform();"></p>
  362. </form><br/><br/>
  363. <p><a href="'.getConfig("unsubscribeurl").'&id='.$id.'">'.$GLOBALS["strUnsubscribe"].'</a></p>
  364. '.$GLOBALS["PoweredBy"];
  365. $html .= $data["footer"];
  366. return $html;
  367. }
  368. function subscribePage($id) {
  369. global $data;
  370. list($attributes,$attributedata) = PageAttributes($data);
  371. $selected_lists = explode(',',$data["lists"]);
  372. $html = '<title>'.$GLOBALS["strSubscribeTitle"].'</title>';
  373. $html .= $data["header"];
  374. $html .= $data["intro"];
  375. $html .= '
  376. <br/><font class="required">'.$GLOBALS["strRequired"].'</font><br/>
  377. '.$GLOBALS["msg"].'
  378. <script language="Javascript" type="text/javascript">
  379. function checkform() {
  380. for (i=0;i<fieldstocheck.length;i++) {
  381. if (eval("document.subscribeform.elements[\'"+fieldstocheck[i]+"\'].type") == "checkbox") {
  382. if (document.subscribeform.elements[fieldstocheck[i]].checked) {
  383. } else {
  384. alert("'.$GLOBALS["strPleaseEnter"].' "+fieldnames[i]);
  385. eval("document.subscribeform.elements[\'"+fieldstocheck[i]+"\'].focus()");
  386. return false;
  387. }
  388. }
  389. else {
  390. if (eval("document.subscribeform.elements[\'"+fieldstocheck[i]+"\'].value") == "") {
  391. alert("'.$GLOBALS["strPleaseEnter"].' "+fieldnames[i]);
  392. eval("document.subscribeform.elements[\'"+fieldstocheck[i]+"\'].focus()");
  393. return false;
  394. }
  395. }
  396. }
  397. for (i=0;i<groupstocheck.length;i++) {
  398. if (!checkGroup(groupstocheck[i],groupnames[i])) {
  399. return false;
  400. }
  401. }
  402. ';
  403. if ($data['emaildoubleentry']=='yes')
  404. {
  405. $html .='
  406. if(! compareEmail())
  407. {
  408. alert("'.str_replace('"','\"',$GLOBALS["strEmailsNoMatch"]).'");
  409. return false;
  410. }';
  411. }
  412. $html .='
  413. return true;
  414. }
  415. var fieldstocheck = new Array();
  416. var fieldnames = new Array();
  417. function addFieldToCheck(value,name) {
  418. fieldstocheck[fieldstocheck.length] = value;
  419. fieldnames[fieldnames.length] = name;
  420. }
  421. var groupstocheck = new Array();
  422. var groupnames = new Array();
  423. function addGroupToCheck(value,name) {
  424. groupstocheck[groupstocheck.length] = value;
  425. groupnames[groupnames.length] = name;
  426. }
  427. function compareEmail()
  428. {
  429. return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
  430. }
  431. function checkGroup(name,value) {
  432. option = -1;
  433. for (i=0;i<document.subscribeform.elements[name].length;i++) {
  434. if (document.subscribeform.elements[name][i].checked) {
  435. option = i;
  436. }
  437. }
  438. if (option == -1) {
  439. alert ("'.$GLOBALS["strPleaseEnter"].' "+value);
  440. return false;
  441. }
  442. return true;
  443. }
  444. </script>';
  445. $html .= formStart('name="subscribeform"');
  446. # @@@ update
  447. if (isset($_SESSION["adminloggedin"]) && $_SESSION["adminloggedin"]) {
  448. $html .= '<style type="text/css">
  449. div.adminmessage {
  450. width: 100%;
  451. border: 2px dashed #000000;
  452. padding: 10px;
  453. margin-bottom: 15px;
  454. background-color: #E7BE8F;
  455. }
  456. </style>';
  457. $html .= '<div class="adminmessage"><p><b>You are logged in as administrator ('.$_SESSION["logindetails"]["adminname"].') of this phplist system</b></p>';
  458. $html .= '<p>You are therefore offered the following choice, which your users will not see when they load this page.</p>';
  459. $html .= '<p><a href="'.$GLOBALS['adminpages'].'">Go back to admin area</a></p>';
  460. $html .= '<p><b>Please choose</b>: <br/><input type=radio name="makeconfirmed" value="1"> Make this user confirmed immediately
  461. <br/><input type=radio name="makeconfirmed" value="0" checked> Send this user a request for confirmation email </p></div>';
  462. }
  463. $html .= '<table border=0>';
  464. $html .= ListAttributes($attributes,$attributedata,$data["htmlchoice"],0,$data['emaildoubleentry']);
  465. $html .= '</table>';
  466. if (ENABLE_RSS) {
  467. $html .= RssOptions($data);
  468. }
  469. $html .= ListAvailableLists("",$data["lists"]);
  470. if (empty($data['button'])) {
  471. $data['button'] = $GLOBALS['strSubmit'];
  472. }
  473. if (USE_SPAM_BLOCK)
  474. $html .= '<div style="display:none"><input type="text" name="VerificationCodeX" value="" size="20"></div>';
  475. $html .= '<p><input type=submit name="subscribe" value="'.$data["button"].'" onClick="return checkform();"></p>
  476. </form><br/><br/>
  477. <p><a href="'.getConfig("unsubscribeurl").'&id='.$id.'">'.$GLOBALS["strUnsubscribe"].'</a></p>
  478. '.$GLOBALS["PoweredBy"];
  479. $html .= $data["footer"];
  480. return $html;
  481. }
  482. function confirmPage($id) {
  483. global $data, $tables, $envelope;
  484. if (!$_GET["uid"]) {
  485. FileNotFound();
  486. }
  487. $req = Sql_Query("select * from {$tables["user"]} where uniqid = \"".$_GET["uid"]."\"");
  488. $userdata = Sql_Fetch_Array($req);
  489. if ($userdata["id"]) {
  490. $blacklisted = isBlackListed($userdata["email"]);
  491. $html = '<ul>';
  492. $lists = '';
  493. Sql_Query("update {$tables["user"]} set confirmed = 1,blacklisted = 0 where id = ".$userdata["id"]);
  494. $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']));
  495. if (!Sql_Affected_Rows()) {
  496. $lists = "\n * ".$GLOBALS["strNoLists"];
  497. $html .= '<li>'.$GLOBALS["strNoLists"].'</li>';
  498. }
  499. while ($row = Sql_fetch_array($req)) {
  500. $lists .= "\n *".stripslashes($row["name"]);
  501. $html .= '<li class="list">'.stripslashes($row["name"]).'<div class="listdescription">'.stripslashes($row["description"]).'</div></li>';
  502. }
  503. $html .= '</ul>';
  504. if ($blacklisted) {
  505. unBlackList($userdata['id']);
  506. addUserHistory($userdata["email"],"Confirmation","User removed from Blacklist for manual confirmation of subscription");
  507. }
  508. addUserHistory($userdata["email"],"Confirmation","Lists: $lists");
  509. $confirmationmessage = ereg_replace('\[LISTS\]', $lists, getUserConfig("confirmationmessage:$id",$userdata["id"]));
  510. if (!TEST) {
  511. sendMail($userdata["email"], getConfig("confirmationsubject:$id"), $confirmationmessage,system_messageheaders(),$envelope);
  512. $adminmessage = $userdata["email"] . " has confirmed their subscription";
  513. if ($blacklisted) {
  514. $adminmessage .= "\nUser has been removed from blacklist";
  515. }
  516. sendAdminCopy("List confirmation",$adminmessage);
  517. addSubscriberStatistics('confirmation',1);
  518. }
  519. $info = $GLOBALS["strConfirmInfo"];
  520. } else {
  521. logEvent("Request for confirmation for invalid user ID: ".substr($_GET["uid"],0,150));
  522. $html .= 'Error: '.$GLOBALS["strUserNotFound"];
  523. $info = $GLOBALS["strConfirmFailInfo"];
  524. }
  525. $res = '<title>'.$GLOBALS["strConfirmTitle"].'</title>';
  526. $res .= $data["header"];
  527. $res .= '<h1>'.$info.'</h1>';
  528. $res .= $html;
  529. $res .= "<P>".$GLOBALS["PoweredBy"].'</p>';
  530. $res .= $data["footer"];
  531. return $res;
  532. }
  533. function unsubscribePage($id) {
  534. global $data, $tables;
  535. $res = '<title>'.$GLOBALS["strUnsubscribeTitle"].'</title>'."\n";
  536. $res .= $data["header"];
  537. if (isset($_GET["uid"])) {
  538. $req = Sql_Query("select * from $tables[user] where uniqid = \"".$_GET["uid"]."\"");
  539. $userdata = Sql_Fetch_Array($req);
  540. $email = $userdata["email"];
  541. if (UNSUBSCRIBE_JUMPOFF) {
  542. $_POST["unsubscribe"] = 1;
  543. $_POST["email"] = $email;
  544. $_REQUEST['unsubscribeemail'] = $email;
  545. $_POST["unsubscribereason"] = '"Jump off" set, reason not requested';
  546. }
  547. } else {
  548. if (isset($_REQUEST['unsubscribeemail'])) {
  549. if (UNSUBSCRIBE_JUMPOFF) {
  550. $_POST["unsubscribe"] = 1;
  551. $_POST["unsubscribereason"] = '"Jump off" set, reason not requested';
  552. }
  553. $email = $_REQUEST['unsubscribeemail'];
  554. } else {
  555. if (isset($_REQUEST['email'])) {
  556. if (UNSUBSCRIBE_JUMPOFF) {
  557. $_POST["unsubscribe"] = 1;
  558. $_POST["unsubscribereason"] = '"Jump off" set, reason not requested';
  559. }
  560. $email = $_REQUEST['email'];
  561. }
  562. }
  563. #0013076: Blacklisting posibility for unknown users
  564. # Set flag for blacklisting
  565. $blacklist = $_GET['p'] == 'blacklist';
  566. # only proceed when user has confirm the form
  567. if ($blacklist && is_email($_REQUEST['unsubscribeemail']) ) {
  568. $_POST["unsubscribe"] = 1;
  569. $_POST["unsubscribereason"] = 'Forwarded receiver requested blacklist';
  570. }
  571. }
  572. $unsubscribeemail = (isset($_REQUEST['unsubscribeemail']))?$_REQUEST['unsubscribeemail']:$_REQUEST['email'];
  573. if ( is_email($unsubscribeemail) && isset($_POST['unsubscribe']) && (isset($_REQUEST['email']) || isset($_REQUEST['unsubscribeemail'])) && isset($_POST['unsubscribereason'])) {
  574. #0013076: Blacklisting posibility for unknown users
  575. if ( !$blacklist ) {
  576. // It would be better to do this above, where the email is set for the other cases.
  577. // But to prevent vulnaribilities let's keep it here for now. [bas]
  578. $query = Sql_Fetch_Row_Query("select id,email from {$tables["user"]} where email = \"$email\"");
  579. $userid = $query[0];
  580. $email = $query[1];
  581. }
  582. if (!$userid) {
  583. #0013076: Blacklisting posibility for unknown users
  584. if ( $blacklist ) {
  585. addUserToBlacklist($email,$_POST['unsubscribereason']);
  586. addSubscriberStatistics('forwardblacklist',1);
  587. } else {
  588. $res .= 'Error: '.$GLOBALS["strUserNotFound"];
  589. logEvent("Request to unsubscribe non-existent user: ".substr($_POST["email"],0,150));
  590. }
  591. } else {
  592. $result = Sql_query("delete from {$tables["listuser"]} where userid = \"$userid\"");
  593. $lists = " * ".$GLOBALS["strAllMailinglists"]."\n";
  594. # add user to blacklist
  595. addUserToBlacklist($email,nl2br(strip_tags($_POST['unsubscribereason'])));
  596. addUserHistory($email,"Unsubscription","Unsubscribed from $lists");
  597. $unsubscribemessage = ereg_replace("\[LISTS\]", $lists,getUserConfig("unsubscribemessage",$userid));
  598. sendMail($email, getConfig("unsubscribesubject"), stripslashes($unsubscribemessage), system_messageheaders($email));
  599. $reason = $_POST["unsubscribereason"] ? "Reason given:\n".stripslashes($_POST["unsubscribereason"]):"No Reason given";
  600. sendAdminCopy("List unsubscription",$email . " has unsubscribed\n$reason");
  601. addSubscriberStatistics('unsubscription',1);
  602. }
  603. if ($userid)
  604. $res .= '<h1>'.$GLOBALS["strUnsubscribeDone"] ."</h1><P>";
  605. #0013076: Blacklisting posibility for unknown users
  606. if ($blacklist)
  607. $res .= '<h1>'.$GLOBALS["strYouAreBlacklisted"] ."</h1><P>";
  608. $res .= $GLOBALS["PoweredBy"].'</p>';
  609. $res .= $data["footer"];
  610. return $res;
  611. } elseif ( isset($_POST["unsubscribe"]) && !is_email($_REQUEST['unsubscribeemail'])) {
  612. $msg = '<span class="error">'.$GLOBALS["strEnterEmail"]."</span><br>";
  613. } elseif (!empty($_GET["email"])) {
  614. $email = trim($_GET["email"]);
  615. } else {
  616. if (isset($_REQUEST["email"])) {
  617. $email = $_REQUEST["email"];
  618. } elseif (isset($_REQUEST['unsubscribeemail'])) {
  619. $email = $_REQUEST['unsubscribeemail'];
  620. } elseif (!isset($email)) {
  621. $email = '';
  622. }
  623. }
  624. if (!isset($msg)) {
  625. $msg = '';
  626. }
  627. $res .= '<b>'. $GLOBALS["strUnsubscribeInfo"].'</b><br>'.
  628. $msg.formStart();
  629. $res .= '<table>
  630. <tr><td>'.$GLOBALS["strEnterEmail"].':</td><td colspan=3><input type=text name="unsubscribeemail" value="'.$email.'" size=40></td></tr>
  631. </table>';
  632. if (!$email) {
  633. $res .= "<input type=submit name=unsubscribe value=\"$GLOBALS[strContinue]\"></form>\n";
  634. $res .= $GLOBALS["PoweredBy"];
  635. $res .= $data["footer"];
  636. return $res;
  637. }
  638. $current = Sql_Fetch_Array_query("SELECT list.id as listid,user.uniqid as userhash, user.password as password 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\"");
  639. $some = $current["listid"];
  640. if (ASKFORPASSWORD && !empty($user['password'])) {
  641. # it is safe to link to the preferences page, because it will still ask for
  642. # a password
  643. $hash = $current["userhash"];
  644. } elseif (isset($_GET['uid']) && $_GET['uid'] == $current['userhash']) {
  645. # they got to this page from a link in an email
  646. $hash = $current['userhash'];
  647. } else {
  648. $hash = '';
  649. }
  650. $finaltext = $GLOBALS["strUnsubscribeFinalInfo"];
  651. $pref_url = getConfig("preferencesurl");
  652. $sep = ereg('\?',$pref_url)?'&':'?';
  653. $finaltext = eregi_replace('\[preferencesurl\]',$pref_url.$sep.'uid='.$hash,$finaltext);
  654. if (!$some) {
  655. #0013076: Blacklisting posibility for unknown users
  656. if (!$blacklist) {
  657. $res .= "<b>".$GLOBALS["strNoListsFound"]."</b></ul>";
  658. }
  659. $res .= '<p><input type=submit value="'.$GLOBALS["strUnsubscribe"].'">';
  660. } else {
  661. if ($blacklist) {
  662. $res .= $GLOBALS["strExplainBlacklist"];
  663. } elseif (!UNSUBSCRIBE_JUMPOFF) {
  664. list($r,$c) = explode(",",getConfig("textarea_dimensions"));
  665. if (!$r) $r = 5;
  666. if (!$c) $c = 65;
  667. $res .= $GLOBALS["strUnsubscribeRequestForReason"];
  668. $res .= sprintf('<br/><textarea name="unsubscribereason" cols="%d" rows="%d" wrap="virtual"></textarea>',$c,$r) . $finaltext;
  669. }
  670. $res .= '<p><input type=submit name="unsubscribe" value="'.$GLOBALS["strUnsubscribe"].'"></p>';
  671. }
  672. $res .= '</form>';
  673. $res .= '<p>'.$GLOBALS["PoweredBy"].'</p>';
  674. $res .= $data["footer"];
  675. return $res;
  676. }
  677. ########################################
  678. if (!function_exists("htmlspecialchars_decode")) {
  679. function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT) {
  680. return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
  681. }
  682. }
  683. function forwardPage($id) {
  684. global $data, $tables, $envelope;
  685. $ok = true;
  686. $subtitle = '';
  687. $info = '';
  688. $html = '';
  689. $form = '';
  690. ## Check requirements
  691. # user
  692. if (!isset($_REQUEST["uid"]) || !$_REQUEST['uid'])
  693. FileNotFound();
  694. $firstpage = 1; ## is this the initial page or a followup
  695. # forward addresses
  696. $forwardemail = '';
  697. if (isset($_REQUEST['email']) && !empty($_REQUEST['email'])) {
  698. $firstpage = 0;
  699. $forwardPeriodCount = Sql_Fetch_Array_Query(sprintf('select count(user) from %s where date_add(time,interval %s) >= now() and user = %d and status ="sent" ',
  700. $tables['user_message_forward'],FORWARD_EMAIL_PERIOD, $userdata['id']));
  701. $forwardemail = stripslashes($_REQUEST['email']);
  702. $emails = explode("\n",$forwardemail);
  703. $emails = trimArray($emails);
  704. $forwardemail = implode("\n", $emails);
  705. #0011860: forward to friend, multiple emails
  706. $emailCount = $forwardPeriodCount[0];
  707. foreach ( $emails as $index => $email) {
  708. $emails[$index] = trim($email);
  709. if( is_email($email) ) {
  710. $emailCount++;
  711. } else {
  712. $info .= sprintf('<BR />' . $GLOBALS['strForwardInvalidEmail'], $email);
  713. $ok = false;
  714. }
  715. }
  716. if ( $emailCount > FORWARD_EMAIL_COUNT ) {
  717. $info.= '<BR />' . $GLOBALS["strForwardCountReached"];
  718. $ok = false;
  719. }
  720. } else {
  721. $ok = false;
  722. }
  723. # message
  724. $mid = 0;
  725. if (isset($_REQUEST['mid'])) {
  726. $mid = sprintf('%d',$_REQUEST['mid']);
  727. $req = Sql_Query(sprintf('select * from %s where id = %d',$tables["message"],$mid));
  728. $messagedata = Sql_Fetch_Array($req);
  729. $mid = $messagedata['id'];
  730. if ($mid) {
  731. $subtitle = $GLOBALS['strForwardSubtitle'].' '.stripslashes($messagedata['subject']);
  732. }
  733. } #mid set
  734. if (empty($mid)) {
  735. # print 'Mid empty'; exit;
  736. FileNotFound();
  737. }
  738. ## get userdata
  739. $req = Sql_Query("select * from {$tables["user"]} where uniqid = \"".sql_escape($_REQUEST["uid"])."\"");
  740. $userdata = Sql_Fetch_Array($req);
  741. $req = Sql_Query(sprintf('select * from %s where email = "%s"',$tables["user"],$forwardemail));
  742. $forwarduserdata = Sql_Fetch_Array($req);
  743. ## verify that this subscriber actually received this message to forward, otherwise they're not allowed
  744. $allowed = Sql_Fetch_Row_Query(sprintf('select userid from %s where userid = %d and messageid = %d',
  745. $GLOBALS['tables']['usermessage'],$userdata['id'],$mid));
  746. if ($allowed[0] != $userdata['id']) {
  747. ## when sending a test email from an admin, the entry isn't there yet
  748. if (empty($_SESSION['adminloggedin']) || $_SESSION['adminloggedin'] != $_SERVER['REMOTE_ADDR']) {
  749. FileNotFound();
  750. }
  751. }
  752. #0011996: forward to friend - personal message
  753. # text cannot be longer than max, to prevent very long text with only linefeeds total cannot be longer than twice max
  754. if (FORWARD_PERSONAL_NOTE_SIZE && isset($_REQUEST['personalNote']) ) {
  755. if (strlen(strip_newlines($_REQUEST['personalNote'])) > FORWARD_PERSONAL_NOTE_SIZE || strlen($_REQUEST['personalNote']) > FORWARD_PERSONAL_NOTE_SIZE * 2 ) {
  756. $info .= '<BR />' . $GLOBALS['strForwardNoteLimitReached'];
  757. $ok = false;
  758. }
  759. $personalNote = strip_tags(htmlspecialchars_decode(stripslashes($_REQUEST['personalNote'])));
  760. $userdata['personalNote'] = $personalNote;
  761. }
  762. if ($userdata["id"] && $mid) {
  763. if ($ok && count($emails)) { ## All is well, send it
  764. require 'admin/sendemaillib.php';
  765. #0013845 Lead Ref Scheme
  766. if (FORWARD_FRIEND_COUNT_ATTRIBUTE) {
  767. $iCountFriends = getAttributeIDbyName(FORWARD_FRIEND_COUNT_ATTRIBUTE);
  768. } else {
  769. $iCountFriends = 0;
  770. }
  771. if($iCountFriends) {
  772. $nFriends = intval(UserAttributeValue($userdata['id'], $iCountFriends));
  773. }
  774. #0011860: forward to friend, multiple emails
  775. foreach ( $emails as $index => $email) {
  776. #0011860: forward to friend, multiple emails
  777. $done = Sql_Fetch_Array_Query(sprintf('select user,status,time from %s where forward = "%s" and message = %d',
  778. $tables['user_message_forward'],$email,$mid));
  779. $info .= '<BR />' . $email . ': ';
  780. if ($done['status'] === 'sent') {
  781. $info .= $GLOBALS['strForwardAlreadyDone'];
  782. } elseif (isBlackListed($email)) {
  783. $info .= $GLOBALS['strForwardBlacklistedEmail'];
  784. } else {
  785. if (!TEST) {
  786. # forward the message
  787. # sendEmail will take care of blacklisting
  788. if (sendEmail($mid,$email,'forwarded',$userdata['htmlemail'],array(),$userdata)) {
  789. $info .= $GLOBALS["strForwardSuccessInfo"];
  790. sendAdminCopy("Message Forwarded",$userdata["email"] . " has forwarded a message $mid to $email");
  791. Sql_Query(sprintf('insert into %s (user,message,forward,status,time)
  792. values(%d,%d,"%s","sent",now())',
  793. $tables['user_message_forward'],$userdata['id'],$mid,$email));
  794. if( $iCountFriends ) $nFriends++;
  795. } else {
  796. $info .= $GLOBALS["strForwardFailInfo"];
  797. sendAdminCopy("Message Forwarded",$userdata["email"] . " tried forwarding a message $mid to $email but failed");
  798. Sql_Query(sprintf('insert into %s (user,message,forward,status,time)
  799. values(%d,%d,"%s","failed",now())',
  800. $tables['user_message_forward'],$userdata['id'],$mid,$email));
  801. $ok = false;
  802. }
  803. }
  804. }
  805. } # foreach friend
  806. if( $iCountFriends ) {
  807. saveUserAttribute($userdata['id'], $iCountFriends,
  808. array('name' => FORWARD_FRIEND_COUNT_ATTRIBUTE, 'value' => $nFriends));
  809. }
  810. } #ok & emails
  811. } else { # no valid sender
  812. logEvent("Forward request from invalid user ID: ".substr($_REQUEST["uid"],0,150));
  813. $info .= '<BR />' . $GLOBALS["strForwardFailInfo"];
  814. $ok = false;
  815. }
  816. $data = PageData($id);
  817. if (isset($data['language_file']) && is_file(dirname(__FILE__).'/texts/'.basename($data['language_file']))) {
  818. @include dirname(__FILE__).'/texts/'.basename($data['language_file']);
  819. }
  820. ## BAS Multiple Forward
  821. ## build response page
  822. $form = '<form method="post" action="">';
  823. $form .= sprintf('<input type=hidden name="mid" value="%d">',$mid);
  824. $form .= sprintf('<input type=hidden name="id" value="%d">',$id);
  825. $form .= sprintf('<input type=hidden name="uid" value="%s">',$userdata['uniqid']);
  826. $form .= sprintf('<input type=hidden name="p" value="forward">');
  827. if (!$ok) {
  828. #0011860: forward to friend, multiple emails
  829. if (FORWARD_EMAIL_COUNT == 1) {
  830. $form .= '<BR /><H2>' .$GLOBALS['strForwardEnterEmail'] . '</H2>';
  831. $form .= sprintf('<input type=text name="email" value="%s" size=50 class="attributeinput">',$forwardemail);
  832. } else {
  833. $form .= '<BR /><H2>' .sprintf($GLOBALS['strForwardEnterEmails'], FORWARD_EMAIL_COUNT) . '</H2>';
  834. $form .= sprintf('<textarea name="email" rows=10 cols=50 class="attributeinput">%s</textarea>', $forwardemail);
  835. }
  836. #0011996: forward to friend - personal message
  837. if (FORWARD_PERSONAL_NOTE_SIZE ) {
  838. $form .= sprintf('<h2>' . $GLOBALS['strForwardPersonalNote'] . '</H2>', FORWARD_PERSONAL_NOTE_SIZE);
  839. $cols=50;
  840. $rows=min(10,ceil(FORWARD_PERSONAL_NOTE_SIZE / 40));
  841. $form .=sprintf('<BR/><textarea type=text name="personalNote" rows=%d cols=%d class="attributeinput">%s</textarea>', $rows, $cols, $personalNote);
  842. }
  843. $form .= sprintf('<br /><input type=submit value="%s"></form>',$GLOBALS['strContinue']);
  844. }
  845. ### END BAS
  846. ### Michiel, remote response page
  847. $remote_content = '';
  848. if (preg_match("/\[URL:([^\s]+)\]/i",$messagedata['message'],$regs)) {
  849. if (isset($regs[1]) && strlen($regs[1])) {
  850. $url = $regs[1];
  851. if (!preg_match('/^http/i',$url)) {
  852. $url = 'http://'.$url;
  853. }
  854. $remote_content = fetchUrl($url);
  855. }
  856. }
  857. if (!empty($remote_content) && preg_match('/\[FORWARDFORM\]/',$remote_content,$regs)) {
  858. if ($firstpage) {
  859. ## this is the initial page, not a follow up one.
  860. $remote_content = str_replace($regs[0],$info.$form,$remote_content);
  861. } else {
  862. $remote_content = str_replace($regs[0],$info,$remote_content);
  863. }
  864. $res = $remote_content;
  865. } else {
  866. $res = '<title>'.$GLOBALS["strForwardTitle"].'</title>';
  867. $res .= $data["header"];
  868. $res .= '<h1>'.$subtitle.'</h1>';
  869. if ($ok) {
  870. $res .= '<h2>'.$info.'</h2>';
  871. } else {
  872. $res .= '<div class="missing">'.$info.'</div>';
  873. }
  874. $res .= $form;
  875. $res .= "<P>".$GLOBALS["PoweredBy"].'</p>';
  876. $res .= $data["footer"];
  877. }
  878. ### END MICHIEL
  879. return $res;
  880. }
  881. ?>