PageRenderTime 29ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/mailz/lists/index.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 959 lines | 808 code | 71 blank | 80 comment | 212 complexity | d84f18d76205bd9b3454c546f41e91c4 MD5 | raw file
  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, Tincan 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. //zingiri
  449. $html .= '<div class="adminmessage"><p><b>You are logged in as administrator ('.$_SESSION["logindetails"]["adminname"].') of this phplist system</b></p>';
  450. $html .= '<p>You are therefore offered the following choice, which your users will not see when they load this page.</p>';
  451. $html .= '<p><a href="'.$GLOBALS['adminpages'].'">Go back to admin area</a></p>';
  452. $html .= '<p><b>Please choose</b>: <br/><input type=radio name="makeconfirmed" value="1"> Make this user confirmed immediately
  453. <br/><input type=radio name="makeconfirmed" value="0" checked> Send this user a request for confirmation email </p></div>';
  454. }
  455. $html .= '<table border=0>';
  456. $html .= ListAttributes($attributes,$attributedata,$data["htmlchoice"],0,$data['emaildoubleentry']);
  457. $html .= '</table>';
  458. if (ENABLE_RSS) {
  459. $html .= RssOptions($data);
  460. }
  461. $html .= ListAvailableLists("",$data["lists"]);
  462. if (empty($data['button'])) {
  463. $data['button'] = $GLOBALS['strSubmit'];
  464. }
  465. if (USE_SPAM_BLOCK)
  466. $html .= '<div style="display:none"><input type="text" name="VerificationCodeX" value="" size="20"></div>';
  467. $html .= '<p><input type=submit name="subscribe" value="'.$data["button"].'" onClick="return checkform();"></p>
  468. </form><br/><br/>
  469. <p><a href="'.getConfig("unsubscribeurl").'&id='.$id.'">'.$GLOBALS["strUnsubscribe"].'</a></p>
  470. '.$GLOBALS["PoweredBy"];
  471. $html .= $data["footer"];
  472. return $html;
  473. }
  474. function confirmPage($id) {
  475. global $data, $tables, $envelope;
  476. if (!$_GET["uid"]) {
  477. FileNotFound();
  478. }
  479. $req = Sql_Query("select * from {$tables["user"]} where uniqid = \"".$_GET["uid"]."\"");
  480. $userdata = Sql_Fetch_Array($req);
  481. if ($userdata["id"]) {
  482. $blacklisted = isBlackListed($userdata["email"]);
  483. $html = '<ul>';
  484. $lists = '';
  485. Sql_Query("update {$tables["user"]} set confirmed = 1,blacklisted = 0 where id = ".$userdata["id"]);
  486. $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']));
  487. if (!Sql_Affected_Rows()) {
  488. $lists = "\n * ".$GLOBALS["strNoLists"];
  489. $html .= '<li>'.$GLOBALS["strNoLists"].'</li>';
  490. }
  491. while ($row = Sql_fetch_array($req)) {
  492. $lists .= "\n *".stripslashes($row["name"]);
  493. $html .= '<li class="list">'.stripslashes($row["name"]).'<div class="listdescription">'.stripslashes($row["description"]).'</div></li>';
  494. }
  495. $html .= '</ul>';
  496. if ($blacklisted) {
  497. unBlackList($userdata['id']);
  498. addUserHistory($userdata["email"],"Confirmation","User removed from Blacklist for manual confirmation of subscription");
  499. }
  500. addUserHistory($userdata["email"],"Confirmation","Lists: $lists");
  501. $confirmationmessage = ereg_replace('\[LISTS\]', $lists, getUserConfig("confirmationmessage:$id",$userdata["id"]));
  502. if (!TEST) {
  503. sendMail($userdata["email"], getConfig("confirmationsubject:$id"), $confirmationmessage,system_messageheaders(),$envelope);
  504. $adminmessage = $userdata["email"] . " has confirmed their subscription";
  505. if ($blacklisted) {
  506. $adminmessage .= "\nUser has been removed from blacklist";
  507. }
  508. sendAdminCopy("List confirmation",$adminmessage);
  509. addSubscriberStatistics('confirmation',1);
  510. }
  511. $info = $GLOBALS["strConfirmInfo"];
  512. } else {
  513. logEvent("Request for confirmation for invalid user ID: ".substr($_GET["uid"],0,150));
  514. $html .= 'Error: '.$GLOBALS["strUserNotFound"];
  515. $info = $GLOBALS["strConfirmFailInfo"];
  516. }
  517. $res = '<title>'.$GLOBALS["strConfirmTitle"].'</title>';
  518. $res .= $data["header"];
  519. $res .= '<h1>'.$info.'</h1>';
  520. $res .= $html;
  521. $res .= "<P>".$GLOBALS["PoweredBy"].'</p>';
  522. $res .= $data["footer"];
  523. return $res;
  524. }
  525. function unsubscribePage($id) {
  526. global $data, $tables;
  527. $res = '<title>'.$GLOBALS["strUnsubscribeTitle"].'</title>'."\n";
  528. $res .= $data["header"];
  529. if (isset($_GET["uid"])) {
  530. $req = Sql_Query("select * from $tables[user] where uniqid = \"".$_GET["uid"]."\"");
  531. $userdata = Sql_Fetch_Array($req);
  532. $email = $userdata["email"];
  533. if (UNSUBSCRIBE_JUMPOFF) {
  534. $_POST["unsubscribe"] = 1;
  535. $_POST["email"] = $email;
  536. $_REQUEST['unsubscribeemail'] = $email;
  537. $_POST["unsubscribereason"] = '"Jump off" set, reason not requested';
  538. }
  539. } else {
  540. if (isset($_REQUEST['unsubscribeemail'])) {
  541. if (UNSUBSCRIBE_JUMPOFF) {
  542. $_POST["unsubscribe"] = 1;
  543. $_POST["unsubscribereason"] = '"Jump off" set, reason not requested';
  544. }
  545. $email = $_REQUEST['unsubscribeemail'];
  546. } else {
  547. if (isset($_REQUEST['email'])) {
  548. if (UNSUBSCRIBE_JUMPOFF) {
  549. $_POST["unsubscribe"] = 1;
  550. $_POST["unsubscribereason"] = '"Jump off" set, reason not requested';
  551. }
  552. $email = $_REQUEST['email'];
  553. }
  554. }
  555. #0013076: Blacklisting posibility for unknown users
  556. # Set flag for blacklisting
  557. $blacklist = $_GET['p'] == 'blacklist';
  558. # only proceed when user has confirm the form
  559. if ($blacklist && is_email($_REQUEST['unsubscribeemail']) ) {
  560. $_POST["unsubscribe"] = 1;
  561. $_POST["unsubscribereason"] = 'Forwarded receiver requested blacklist';
  562. }
  563. }
  564. $unsubscribeemail = (isset($_REQUEST['unsubscribeemail']))?$_REQUEST['unsubscribeemail']:$_REQUEST['email'];
  565. if ( is_email($unsubscribeemail) && isset($_POST['unsubscribe']) && (isset($_REQUEST['email']) || isset($_REQUEST['unsubscribeemail'])) && isset($_POST['unsubscribereason'])) {
  566. #0013076: Blacklisting posibility for unknown users
  567. if ( !$blacklist ) {
  568. // It would be better to do this above, where the email is set for the other cases.
  569. // But to prevent vulnaribilities let's keep it here for now. [bas]
  570. $query = Sql_Fetch_Row_Query("select id,email from {$tables["user"]} where email = \"$email\"");
  571. $userid = $query[0];
  572. $email = $query[1];
  573. }
  574. if (!$userid) {
  575. #0013076: Blacklisting posibility for unknown users
  576. if ( $blacklist ) {
  577. addUserToBlacklist($email,$_POST['unsubscribereason']);
  578. addSubscriberStatistics('forwardblacklist',1);
  579. } else {
  580. $res .= 'Error: '.$GLOBALS["strUserNotFound"];
  581. logEvent("Request to unsubscribe non-existent user: ".substr($_POST["email"],0,150));
  582. }
  583. } else {
  584. $result = Sql_query("delete from {$tables["listuser"]} where userid = \"$userid\"");
  585. $lists = " * ".$GLOBALS["strAllMailinglists"]."\n";
  586. # add user to blacklist
  587. addUserToBlacklist($email,nl2br(strip_tags($_POST['unsubscribereason'])));
  588. addUserHistory($email,"Unsubscription","Unsubscribed from $lists");
  589. $unsubscribemessage = ereg_replace("\[LISTS\]", $lists,getUserConfig("unsubscribemessage",$userid));
  590. sendMail($email, getConfig("unsubscribesubject"), stripslashes($unsubscribemessage), system_messageheaders($email));
  591. $reason = $_POST["unsubscribereason"] ? "Reason given:\n".stripslashes($_POST["unsubscribereason"]):"No Reason given";
  592. sendAdminCopy("List unsubscription",$email . " has unsubscribed\n$reason");
  593. addSubscriberStatistics('unsubscription',1);
  594. }
  595. if ($userid)
  596. $res .= '<h1>'.$GLOBALS["strUnsubscribeDone"] ."</h1><P>";
  597. #0013076: Blacklisting posibility for unknown users
  598. if ($blacklist)
  599. $res .= '<h1>'.$GLOBALS["strYouAreBlacklisted"] ."</h1><P>";
  600. $res .= $GLOBALS["PoweredBy"].'</p>';
  601. $res .= $data["footer"];
  602. return $res;
  603. } elseif ( isset($_POST["unsubscribe"]) && !is_email($_REQUEST['unsubscribeemail'])) {
  604. $msg = '<span class="error">'.$GLOBALS["strEnterEmail"]."</span><br>";
  605. } elseif (!empty($_GET["email"])) {
  606. $email = trim($_GET["email"]);
  607. } else {
  608. if (isset($_REQUEST["email"])) {
  609. $email = $_REQUEST["email"];
  610. } elseif (isset($_REQUEST['unsubscribeemail'])) {
  611. $email = $_REQUEST['unsubscribeemail'];
  612. } elseif (!isset($email)) {
  613. $email = '';
  614. }
  615. }
  616. if (!isset($msg)) {
  617. $msg = '';
  618. }
  619. $res .= '<b>'. $GLOBALS["strUnsubscribeInfo"].'</b><br>'.
  620. $msg.formStart();
  621. $res .= '<table>
  622. <tr><td>'.$GLOBALS["strEnterEmail"].':</td><td colspan=3><input type=text name="unsubscribeemail" value="'.$email.'" size=40></td></tr>
  623. </table>';
  624. if (!$email) {
  625. $res .= "<input type=submit name=unsubscribe value=\"$GLOBALS[strContinue]\"></form>\n";
  626. $res .= $GLOBALS["PoweredBy"];
  627. $res .= $data["footer"];
  628. return $res;
  629. }
  630. $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\"");
  631. $some = $current["listid"];
  632. if (ASKFORPASSWORD && !empty($user['password'])) {
  633. # it is safe to link to the preferences page, because it will still ask for
  634. # a password
  635. $hash = $current["userhash"];
  636. } elseif (isset($_GET['uid']) && $_GET['uid'] == $current['userhash']) {
  637. # they got to this page from a link in an email
  638. $hash = $current['userhash'];
  639. } else {
  640. $hash = '';
  641. }
  642. $finaltext = $GLOBALS["strUnsubscribeFinalInfo"];
  643. $pref_url = getConfig("preferencesurl");
  644. $sep = ereg('\?',$pref_url)?'&':'?';
  645. $finaltext = eregi_replace('\[preferencesurl\]',$pref_url.$sep.'uid='.$hash,$finaltext);
  646. if (!$some) {
  647. #0013076: Blacklisting posibility for unknown users
  648. if (!$blacklist) {
  649. $res .= "<b>".$GLOBALS["strNoListsFound"]."</b></ul>";
  650. }
  651. $res .= '<p><input type=submit value="'.$GLOBALS["strUnsubscribe"].'">';
  652. } else {
  653. if ($blacklist) {
  654. $res .= $GLOBALS["strExplainBlacklist"];
  655. } elseif (!UNSUBSCRIBE_JUMPOFF) {
  656. list($r,$c) = explode(",",getConfig("textarea_dimensions"));
  657. if (!$r) $r = 5;
  658. if (!$c) $c = 65;
  659. $res .= $GLOBALS["strUnsubscribeRequestForReason"];
  660. $res .= sprintf('<br/><textarea name="unsubscribereason" cols="%d" rows="%d" wrap="virtual"></textarea>',$c,$r) . $finaltext;
  661. }
  662. $res .= '<p><input type=submit name="unsubscribe" value="'.$GLOBALS["strUnsubscribe"].'"></p>';
  663. }
  664. $res .= '</form>';
  665. $res .= '<p>'.$GLOBALS["PoweredBy"].'</p>';
  666. $res .= $data["footer"];
  667. return $res;
  668. }
  669. ########################################
  670. if (!function_exists("htmlspecialchars_decode")) {
  671. function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT) {
  672. return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
  673. }
  674. }
  675. function forwardPage($id) {
  676. global $data, $tables, $envelope;
  677. $ok = true;
  678. $subtitle = '';
  679. $info = '';
  680. $html = '';
  681. $form = '';
  682. ## Check requirements
  683. # user
  684. if (!isset($_REQUEST["uid"]) || !$_REQUEST['uid'])
  685. FileNotFound();
  686. $firstpage = 1; ## is this the initial page or a followup
  687. # forward addresses
  688. $forwardemail = '';
  689. if (isset($_REQUEST['email']) && !empty($_REQUEST['email'])) {
  690. $firstpage = 0;
  691. $forwardPeriodCount = Sql_Fetch_Array_Query(sprintf('select count(user) from %s where date_add(time,interval %s) >= now() and user = %d and status ="sent" ',
  692. $tables['user_message_forward'],FORWARD_EMAIL_PERIOD, $userdata['id']));
  693. $forwardemail = stripslashes($_REQUEST['email']);
  694. $emails = explode("\n",$forwardemail);
  695. $emails = trimArray($emails);
  696. $forwardemail = implode("\n", $emails);
  697. #0011860: forward to friend, multiple emails
  698. $emailCount = $forwardPeriodCount[0];
  699. foreach ( $emails as $index => $email) {
  700. $emails[$index] = trim($email);
  701. if( is_email($email) ) {
  702. $emailCount++;
  703. } else {
  704. $info .= sprintf('<BR />' . $GLOBALS['strForwardInvalidEmail'], $email);
  705. $ok = false;
  706. }
  707. }
  708. if ( $emailCount > FORWARD_EMAIL_COUNT ) {
  709. $info.= '<BR />' . $GLOBALS["strForwardCountReached"];
  710. $ok = false;
  711. }
  712. } else {
  713. $ok = false;
  714. }
  715. # message
  716. $mid = 0;
  717. if (isset($_REQUEST['mid'])) {
  718. $mid = sprintf('%d',$_REQUEST['mid']);
  719. $req = Sql_Query(sprintf('select * from %s where id = %d',$tables["message"],$mid));
  720. $messagedata = Sql_Fetch_Array($req);
  721. $mid = $messagedata['id'];
  722. if ($mid) {
  723. $subtitle = $GLOBALS['strForwardSubtitle'].' '.stripslashes($messagedata['subject']);
  724. }
  725. } #mid set
  726. if (empty($mid)) {
  727. # print 'Mid empty'; exit;
  728. FileNotFound();
  729. }
  730. ## get userdata
  731. $req = Sql_Query("select * from {$tables["user"]} where uniqid = \"".sql_escape($_REQUEST["uid"])."\"");
  732. $userdata = Sql_Fetch_Array($req);
  733. $req = Sql_Query(sprintf('select * from %s where email = "%s"',$tables["user"],$forwardemail));
  734. $forwarduserdata = Sql_Fetch_Array($req);
  735. ## verify that this subscriber actually received this message to forward, otherwise they're not allowed
  736. $allowed = Sql_Fetch_Row_Query(sprintf('select userid from %s where userid = %d and messageid = %d',
  737. $GLOBALS['tables']['usermessage'],$userdata['id'],$mid));
  738. if ($allowed[0] != $userdata['id']) {
  739. ## when sending a test email from an admin, the entry isn't there yet
  740. if (empty($_SESSION['adminloggedin']) || $_SESSION['adminloggedin'] != $_SERVER['REMOTE_ADDR']) {
  741. FileNotFound();
  742. }
  743. }
  744. #0011996: forward to friend - personal message
  745. # text cannot be longer than max, to prevent very long text with only linefeeds total cannot be longer than twice max
  746. if (FORWARD_PERSONAL_NOTE_SIZE && isset($_REQUEST['personalNote']) ) {
  747. if (strlen(strip_newlines($_REQUEST['personalNote'])) > FORWARD_PERSONAL_NOTE_SIZE || strlen($_REQUEST['personalNote']) > FORWARD_PERSONAL_NOTE_SIZE * 2 ) {
  748. $info .= '<BR />' . $GLOBALS['strForwardNoteLimitReached'];
  749. $ok = false;
  750. }
  751. $personalNote = strip_tags(htmlspecialchars_decode(stripslashes($_REQUEST['personalNote'])));
  752. $userdata['personalNote'] = $personalNote;
  753. }
  754. if ($userdata["id"] && $mid) {
  755. if ($ok && count($emails)) { ## All is well, send it
  756. require 'admin/sendemaillib.php';
  757. #0013845 Lead Ref Scheme
  758. if (FORWARD_FRIEND_COUNT_ATTRIBUTE) {
  759. $iCountFriends = getAttributeIDbyName(FORWARD_FRIEND_COUNT_ATTRIBUTE);
  760. } else {
  761. $iCountFriends = 0;
  762. }
  763. if($iCountFriends) {
  764. $nFriends = intval(UserAttributeValue($userdata['id'], $iCountFriends));
  765. }
  766. #0011860: forward to friend, multiple emails
  767. foreach ( $emails as $index => $email) {
  768. #0011860: forward to friend, multiple emails
  769. $done = Sql_Fetch_Array_Query(sprintf('select user,status,time from %s where forward = "%s" and message = %d',
  770. $tables['user_message_forward'],$email,$mid));
  771. $info .= '<BR />' . $email . ': ';
  772. if ($done['status'] === 'sent') {
  773. $info .= $GLOBALS['strForwardAlreadyDone'];
  774. } elseif (isBlackListed($email)) {
  775. $info .= $GLOBALS['strForwardBlacklistedEmail'];
  776. } else {
  777. if (!TEST) {
  778. # forward the message
  779. # sendEmail will take care of blacklisting
  780. if (sendEmail($mid,$email,'forwarded',$userdata['htmlemail'],array(),$userdata)) {
  781. $info .= $GLOBALS["strForwardSuccessInfo"];
  782. sendAdminCopy("Message Forwarded",$userdata["email"] . " has forwarded a message $mid to $email");
  783. Sql_Query(sprintf('insert into %s (user,message,forward,status,time)
  784. values(%d,%d,"%s","sent",now())',
  785. $tables['user_message_forward'],$userdata['id'],$mid,$email));
  786. if( $iCountFriends ) $nFriends++;
  787. } else {
  788. $info .= $GLOBALS["strForwardFailInfo"];
  789. sendAdminCopy("Message Forwarded",$userdata["email"] . " tried forwarding a message $mid to $email but failed");
  790. Sql_Query(sprintf('insert into %s (user,message,forward,status,time)
  791. values(%d,%d,"%s","failed",now())',
  792. $tables['user_message_forward'],$userdata['id'],$mid,$email));
  793. $ok = false;
  794. }
  795. }
  796. }
  797. } # foreach friend
  798. if( $iCountFriends ) {
  799. saveUserAttribute($userdata['id'], $iCountFriends,
  800. array('name' => FORWARD_FRIEND_COUNT_ATTRIBUTE, 'value' => $nFriends));
  801. }
  802. } #ok & emails
  803. } else { # no valid sender
  804. logEvent("Forward request from invalid user ID: ".substr($_REQUEST["uid"],0,150));
  805. $info .= '<BR />' . $GLOBALS["strForwardFailInfo"];
  806. $ok = false;
  807. }
  808. $data = PageData($id);
  809. if (isset($data['language_file']) && is_file(dirname(__FILE__).'/texts/'.basename($data['language_file']))) {
  810. @include dirname(__FILE__).'/texts/'.basename($data['language_file']);
  811. }
  812. ## BAS Multiple Forward
  813. ## build response page
  814. $form = '<form method="post" action="">';
  815. $form .= sprintf('<input type=hidden name="mid" value="%d">',$mid);
  816. $form .= sprintf('<input type=hidden name="id" value="%d">',$id);
  817. $form .= sprintf('<input type=hidden name="uid" value="%s">',$userdata['uniqid']);
  818. $form .= sprintf('<input type=hidden name="p" value="forward">');
  819. if (!$ok) {
  820. #0011860: forward to friend, multiple emails
  821. if (FORWARD_EMAIL_COUNT == 1) {
  822. $form .= '<BR /><H2>' .$GLOBALS['strForwardEnterEmail'] . '</H2>';
  823. $form .= sprintf('<input type=text name="email" value="%s" size=50 class="attributeinput">',$forwardemail);
  824. } else {
  825. $form .= '<BR /><H2>' .sprintf($GLOBALS['strForwardEnterEmails'], FORWARD_EMAIL_COUNT) . '</H2>';
  826. $form .= sprintf('<textarea name="email" rows=10 cols=50 class="attributeinput">%s</textarea>', $forwardemail);
  827. }
  828. #0011996: forward to friend - personal message
  829. if (FORWARD_PERSONAL_NOTE_SIZE ) {
  830. $form .= sprintf('<h2>' . $GLOBALS['strForwardPersonalNote'] . '</H2>', FORWARD_PERSONAL_NOTE_SIZE);
  831. $cols=50;
  832. $rows=min(10,ceil(FORWARD_PERSONAL_NOTE_SIZE / 40));
  833. $form .=sprintf('<BR/><textarea type=text name="personalNote" rows=%d cols=%d class="attributeinput">%s</textarea>', $rows, $cols, $personalNote);
  834. }
  835. $form .= sprintf('<br /><input type=submit value="%s"></form>',$GLOBALS['strContinue']);
  836. }
  837. ### END BAS
  838. ### Michiel, remote response page
  839. $remote_content = '';
  840. if (preg_match("/\[URL:([^\s]+)\]/i",$messagedata['message'],$regs)) {
  841. if (isset($regs[1]) && strlen($regs[1])) {
  842. $url = $regs[1];
  843. if (!preg_match('/^http/i',$url)) {
  844. $url = 'http://'.$url;
  845. }
  846. $remote_content = fetchUrl($url);
  847. }
  848. }
  849. if (!empty($remote_content) && preg_match('/\[FORWARDFORM\]/',$remote_content,$regs)) {
  850. if ($firstpage) {
  851. ## this is the initial page, not a follow up one.
  852. $remote_content = str_replace($regs[0],$info.$form,$remote_content);
  853. } else {
  854. $remote_content = str_replace($regs[0],$info,$remote_content);
  855. }
  856. $res = $remote_content;
  857. } else {
  858. $res = '<title>'.$GLOBALS["strForwardTitle"].'</title>';
  859. $res .= $data["header"];
  860. $res .= '<h1>'.$subtitle.'</h1>';
  861. if ($ok) {
  862. $res .= '<h2>'.$info.'</h2>';
  863. } else {
  864. $res .= '<div class="missing">'.$info.'</div>';
  865. }
  866. $res .= $form;
  867. $res .= "<P>".$GLOBALS["PoweredBy"].'</p>';
  868. $res .= $data["footer"];
  869. }
  870. ### END MICHIEL
  871. return $res;
  872. }
  873. ?>