- <?php
- /**
- * <b>Subscribe/Unsubscribe : Mailing List Section</b><br />
- * Allows a user to subscribe or unsubscribe from mailing list(s).
- * @author Kristen O'Brien <kristen_paristemi-com>
- * @copyright Copyright 2004, Kristen O'Brien
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @link http://www.paristemi.com Paristemi Main Site
- * @package paristemi
- * @subpackage paristemi_business_logic
- * @since Build 0.5
- * @version Build 0.7
- * @filesource
- */
- /**
- * Include the constants file and all of the files in the include list
- */
- if(ltrim(dirname($_SERVER['SCRIPT_FILENAME'])) == "" || !file_exists($_SERVER['DOCUMENT_ROOT']."/constants.php")) {
- if(!file_exists("../constants.php")) { require_once("../public_html/constants.php"); }
- else { require_once("../constants.php"); }
- }
- else { require_once($_SERVER['DOCUMENT_ROOT']."/constants.php"); }
- foreach($INCLUDE_LIST as $includefile) { require_once $includefile; }
-
- $db = new Database();
- $db_ml = $db->GetClass('mailinglist');
- $smarty = UtilSmarty::createSmarty();
-
- $type="";$id=null;$email="";$approve="";$printtype = "";
- if(count($HTTP_POST_VARS) > 0) {
- if(isset($HTTP_POST_VARS['Type'])) {$type = $HTTP_POST_VARS['Type'];}
- if(isset($HTTP_POST_VARS['Email'])) {$email = $HTTP_POST_VARS['Email'];}
- if(isset($HTTP_POST_VARS['ID'])) {$id = $HTTP_POST_VARS['ID'];}
- }
- else if(getenv("QUERY_STRING")) {
- if(isset($HTTP_GET_VARS['id'])) {$id = $HTTP_GET_VARS['id'];}
- if(isset($HTTP_GET_VARS['type'])) {$type = $HTTP_GET_VARS['type'];}
- if(isset($HTTP_GET_VARS['approve'])) {$approve = $HTTP_GET_VARS['approve'];}
- if(isset($HTTP_GET_VARS['email'])) {$email = $HTTP_GET_VARS['email'];}
- }
- switch($type) {
- case 'Subscribe' : $printtype = $S_SUBSCRIBE; break;
- case 'Unsubscribe' : $printtype = $S_UNSUBSCRIBE; break;
- }
- if($type != "") { $pagesubtitle = $type; }
- else { $pagesubtitle = $S_SUBSCRIBE." ".$S_AND." ".$S_UNSUBSCRIBE; }
-
- require_once $HTTP_DOCUMENT_ROOT.$INCLUDE_PATH.$HEADER.
- "?pagetitle=".str_replace(" ","%20",htmlentities($S_MAILING_LISTS)).
- "&pagesubtitle=".str_replace(" ","%20",htmlentities($pagesubtitle)).
- "&pagedesc=".str_replace(" ","%20",htmlentities($CHURCH_NAME." ".$S_DESC_MAILING_LISTS));
-
- $sidesection['Title'] = $S_MAILING_LISTS;
- $sidesection['Links'] = array(array(
- 'LinkPath'=>$HTTP_DOCUMENT_ROOT.$MAILING_LIST_DIR.$ML_SUBSCRIBE_FILE."?type=Subscribe",
- 'LinkText'=>$S_SUBSCRIBE), array(
- 'LinkPath'=>$HTTP_DOCUMENT_ROOT.$MAILING_LIST_DIR.$ML_SUBSCRIBE_FILE."?type=Unsubscribe",
- 'LinkText'=>$S_UNSUBSCRIBE), array(
- 'LinkPath'=>$HTTP_DOCUMENT_ROOT.$MAILING_LIST_DIR. $ML_ADMIN_FILE,
- 'LinkText'=>$S_ADMIN." ".$S_LOGIN));
- $smarty->assign('sidesections',array($sidesection));
-
- if(count($HTTP_POST_VARS) > 0) {
-
- if($id != null && $email != "" && $type != "") {
- $mailtitle = $CHURCH_NAME." ".$S_MAILING_LIST." ".$printtype;
- $ids = array();
- $idsarstr = implode(",",$id);
- foreach($id as $iditem) {
- $item = $db_ml->GetMailingListData($iditem);
- $ids[] = $item->Name; }
- $idsstring = implode(", ",$ids);
- $firsttext = $S_MSG_ML_REQUEST.$S_MSG_FOOTER."\r\n\r\n";
- $lasttext = $S_MAILING_LISTS.": ".$idsstring;
- $headers = "From: ".$FOOTER_CONTACT."\r\n"
- ."Reply-To: ".$FOOTER_CONTACT."\r\n"
- ."X-Mailer: PHP/" . phpversion();
- $mllink = $HTTP_DOCUMENT_ROOT.$MAILING_LIST_DIR.$ML_SUBSCRIBE_FILE.
- "?email=".$email."&type=".$type."&id=".$idsarstr."&approve=yes\r\n\r\n";
- $sent = mail($email,$mailtitle,
- $firsttext.$mllink.$lasttext,$headers);
- if($sent) {
- $smarty->assign('heading',$N_ML_MSG_SENT_HEAD);
- $smarty->assign('notice',$N_MSG_SENT_TO." ".$email." ".$N_ML_MSG_SENT_SUB.": ".$idsstring);
- $smarty->assign('returnlink',array('LinkPath'=>$HTTP_DOCUMENT_ROOT,'LinkText'=>$S_RETURN_SITE));
- }
- else if(!$sent) {
- $smarty->assign('heading',$E_ML_MSG_NOT_SENT_HEAD);
- $smarty->assign('error',$E_FILL_FORM_COMPLETE);
- $smarty->assign('returnlink',array(
- 'LinkPath'=>$HTTP_DOCUMENT_ROOT.$MAILING_LIST_DIR.$ML_SUBSCRIBE_FILE."?type=".$type,
- 'LinkText'=>$S_RETURN_FORM));
- }
- }
- else {
- $smarty->assign('heading',$E_ML_MSG_NOT_SENT_HEAD);
- $smarty->assign('error',$E_FILL_FORM_COMPLETE);
- $smarty->assign('returnlink',array(
- 'LinkPath'=>$HTTP_DOCUMENT_ROOT.$MAILING_LIST_DIR.$ML_SUBSCRIBE_FILE."?type=".$type,
- 'LinkText'=>$S_RETURN_FORM));
- }
- }
-
- else if(getenv("QUERY_STRING")) {
- $idarr = explode(",",$id);
-
- if($approve == "yes" && $email != "" && $idarr != "") {;
- foreach($idarr as $iditem) {
- $result = false; $exists = false;
- if($type == "Subscribe") {
- $tempml = $db_ml->GetMailingListData($iditem);
- if(strpos($tempml->Emails,$email) === false) {
- $result = $db_ml->AddEmailInMailingList($email,$iditem);
- }
- else { $exists = true; }
- }
- else if($type == "Unsubscribe") {
- $result = $db_ml->RemoveEmailInMailingList($email,$iditem); }
- if(!$result && !$exists) {
- $smarty->assign('heading',$E_ML_NOT_UNSUBSCRIBE_HEAD);
- $smarty->assign('error',$E_FILL_FORM_COMPLETE);
- $smarty->assign('returnlink',array(
- 'LinkPath'=>$HTTP_DOCUMENT_ROOT.$MAILING_LIST_DIR.$ML_SUBSCRIBE_FILE."?type=".$type,
- 'LinkText'=>$S_RETURN_FORM));
- break;
- }
- if($exists) {
- $smarty->assign('heading',$E_ML_EMAIL_EXISTS_HEAD);
- $smarty->assign('error',$E_ML_EMAIL_EXISTS);
- $smarty->assign('returnlink',array(
- 'LinkPath'=>$HTTP_DOCUMENT_ROOT.$MAILING_LIST_DIR.$MAILING_LIST_FILE,
- 'LinkText'=>$S_RETURN_TO." ".$S_MAILING_LISTS));
- break;
- }
- }
- if($result) {
- $listelements = array();
- $smarty->assign('heading',$N_ML_SUCCESS_HEAD);
- switch($type) {
- case 'Subscribe' : $smarty->assign('notice',$N_ML_SUCCESS_SUB.":"); break;
- case 'Unsubscribe' : $smarty->assign('notice',$N_ML_SUCCESS_UNS.":"); break;
- }
- foreach($idarr as $iditem) {
- $item = $db_ml->GetMailingListData($iditem);
- $listelements[] = array('Title'=>$item->Name);
- }
- $smarty->assign('listelements',$listelements);
- }
- }
-
- else if($type != null) {
- $smarty->assign('heading',$S_MAILING_LISTS." ".$printtype);
- $smarty->assign('bottomnote',$S_FORM_WAIT_NOTE." ".$S_FORM_ML);
- $mls = $db_ml->GetPublicMailingLists();
- if($mls != null) {
- $smarty->assign('formname','subscribe');
- $smarty->assign('formaction',$ML_SUBSCRIBE_FILE);
- $smarty->assign('hiddeninputs',array(array('name'=>'Type','value'=>$type)));
-
- $smarty->assign('checkboxtitle',$S_MAILING_LISTS.':');
- $checkboxes = array();
- foreach ($mls as $item) {
- if($id == $item->ID) { $checked = "yes"; }
- else { $checked = "no"; }
- $checkboxes[] = array('name'=>'ID[]','value'=>$item->ID,'checked'=>$checked,'Title'=>$item->Name);
- }
- $smarty->assign('checkboxes',$checkboxes);
- $smarty->assign('textinputs',array(array('name'=>'Email','heading'=>$S_FORM_EMAIL)));
- $smarty->assign('submitname',$printtype);
- }
- else {
- $smarty->assign('heading',$S_MAILING_LISTS);
- $smarty->assign('notice',$N_ML_NONE);
- }
- }
- }
-
- else { $smarty->assign('introstatements',array('Title'=>$S_MAILING_LISTS,'Text'=>$MAILING_LIST_INTRO)); }
-
- UtilSmarty::displaySectionPage($smarty);
- ?>
- <?php require_once $SERVER_DIRECTORY.$INCLUDE_PATH.$FOOTER; ?>