diff --git a/_config.php b/_config.php index 3e5245eb..a13a758c 100644 --- a/_config.php +++ b/_config.php @@ -10,7 +10,6 @@ Director::addRules(50, array( 'cms' => '->admin', 'admin/security/$Action/$ID/$OtherID' => 'SecurityAdmin', 'admin/help/$Action/$ID' => 'CMSHelp', - 'admin/newsletter/$Action/$ID' => 'NewsletterAdmin', 'admin/reports/$Action/$ID' => 'ReportAdmin', 'admin/assets/$Action/$ID' => 'AssetAdmin', 'admin/comments/$Action' => 'CommentAdmin', @@ -18,7 +17,6 @@ Director::addRules(50, array( 'admin/bulkload/$Action/$ID/$OtherID' => 'BulkLoaderAdmin', 'admin/ImageEditor/$Action' => 'ImageEditor', 'admin/$Action/$ID/$OtherID' => 'CMSMain', - 'unsubscribe/$Email/$MailingList' => 'Unsubscribe_Controller' )); // Built-in modules diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 85c790d1..59f1f2ef 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -853,12 +853,6 @@ JS; "admin/assets/", "AssetAdmin" ); - self::add_menu_item( - "newsletter", - _t('LeftAndMain.NEWSLETTERS',"Newsletters",PR_HIGH,"Menu title"), - "admin/newsletter/", - "NewsletterAdmin" - ); if(ReportAdmin::has_reports()) { self::add_menu_item( "report", diff --git a/code/Newsletter/BatchProcess.php b/code/Newsletter/BatchProcess.php deleted file mode 100755 index e360c0e7..00000000 --- a/code/Newsletter/BatchProcess.php +++ /dev/null @@ -1,106 +0,0 @@ -current = 0; - - if( $collection ) { - if( is_array( $collection ) ) - $this->objects = $collection; - elseif( is_a( $collection, 'DataObjectSet' ) ) { - $this->objects = $collection->toArray(); - - } else - $this->objects = array( $collection ); - } - } - - function runToCompletion() { - $this->scriptOutput = false; - $this->current = 0; - $ignore = $this->next( count( $this->objects ) ); - - $this->complete(); - } - - function getID() { - return $this->id; - } - - function next() { - self::addProcess( $this ); - return $this->id.':'.$this->current.'/'.count( $this->objects ); - } - - function start() { - $this->current = 0; - $this->id = self::generateID(); - - if( !$this->objects || count( $this->objects ) === 0 ) - return $this->complete(); - - return $this->next(); - } - - function complete() { - self::removeProcess( $this ); - } - - static function generateID() { - return count(Session::get('BatchProcesses')) + 1; - } - - static function addProcess( $process ) { - Session::set('BatchProcesses.' . ($process->getID() - 1), serialize($process)); - } - - static function removeProcess( $process ) { - Session::clear('BatchProcesses.' . ($process->getID() - 1)); - } -} - -/** - * Controller for calling the batch processes via Ajax. - * @package cms - * @subpackage newsletter - */ -class BatchProcess_Controller extends Controller { - - function next() { - - $processID = $this->urlParams['ID']; - - if( !$processID ) { - return _t('BatchProcess_Controller.ERROR', 'ERROR: Could not continue process'); - } - - $process = unserialize(Session::get('BatchProcesses.' . ($this->urlParams['ID'] - 1))); - - if( !$process ) { - return _t('BatchProcess_Controller.ERROR', 'ERROR:Could not continue process'); - } - - if( $this->urlParams['Batch'] ) - return $process->next( $this->urlParams['Batch'] ); - else - return $process->next(); - } -} -?> diff --git a/code/Newsletter/BouncedList.php b/code/Newsletter/BouncedList.php deleted file mode 100755 index cc38a168..00000000 --- a/code/Newsletter/BouncedList.php +++ /dev/null @@ -1,58 +0,0 @@ -nlType = $newsletterType; - else - $this->nlType = DataObject::get_by_id( 'NewsletterType', $newsletterType ); - } - - function setController($controller) { - $this->controller = $controller; - } - - function FieldHolder() { - return $this->renderWith( 'NewsletterAdmin_BouncedList' ); - } - - function Entries() { - - $id = $this->nlType->GroupID; - - $bounceRecords = DataObject::get( 'Email_BounceRecord', "`GroupID`='$id'", null, "INNER JOIN `Group_Members` USING(`MemberID`)" ); - - //user_error($id, E_USER_ERROR ); - - if( !$bounceRecords ) - return null; - - foreach( $bounceRecords as $bounceRecord ) { - if( $bounceRecord ) { - $bouncedUsers[] = new ArrayData( array( - 'Record' => $bounceRecord, - 'GroupID' => $id, - 'Member' => DataObject::get_by_id( 'Member', $bounceRecord->MemberID ) - )); - } - } - - return new DataObjectSet( $bouncedUsers ); - } -} -?> \ No newline at end of file diff --git a/code/Newsletter/Newsletter.php b/code/Newsletter/Newsletter.php deleted file mode 100755 index 79fa6d54..00000000 --- a/code/Newsletter/Newsletter.php +++ /dev/null @@ -1,192 +0,0 @@ -Parent()->GroupID); - $sent_status_report = $this->renderWith("Newsletter_SentStatusReport"); - $ret = new FieldSet( - new TabSet("Root", - $mailTab = new Tab(_t('Newsletter.NEWSLETTER', 'Newsletter'), - new TextField("Subject", _t('Newsletter.SUBJECT', 'Subject'), $this->Subject), - new HtmlEditorField("Content", _t('Newsletter.CONTENT', 'Content')) - ), - $sentToTab = new Tab(_t('Newsletter.SENTREPORT', 'Sent Status Report'), - new LiteralField("Sent Status Report", $sent_status_report) - ) - ) - ); - - if( $this->Status != 'Draft' ) { - $mailTab->push( new ReadonlyField("SendDate", _t('Newsletter.SENTAT', 'Sent at'), $this->SendDate) ); - } - - - return $ret; - } - - /** - * Returns a DataObject listing the recipients for the given status for this newsletter - * - * @param string $result 3 possible values: "Sent", (mail() returned TRUE), "Failed" (mail() returned FALSE), or "Bounced" ({@see $email_bouncehandler}). - */ - function SentRecipients($result) { - $SQL_result = Convert::raw2sql($result); - return DataObject::get("Newsletter_SentRecipient",array("ParentID='".$this->ID."'", "Result='".$SQL_result."'")); - } - - /** - * Returns a DataObjectSet containing the subscribers who have never been sent this Newsletter - * - */ - function UnsentSubscribers() { - // Get a list of everyone who has been sent this newsletter - $sent_recipients = DataObject::get("Newsletter_SentRecipient","ParentID='".$this->ID."'"); - // If this Newsletter has not been sent to anyone yet, $sent_recipients will be null - if ($sent_recipients != null) { - $sent_recipients_array = $sent_recipients->toNestedArray('MemberID'); - } else { - $sent_recipients_array = array(); - } - - // Get a list of all the subscribers to this newsletter - $subscribers = DataObject::get( 'Member', "`GroupID`='".$this->Parent()->GroupID."'", null, "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`" ); - // If this Newsletter has no subscribers, $subscribers will be null - if ($subscribers != null) { - $subscribers_array = $subscribers->toNestedArray(); - } else { - $subscribers_array = array(); - } - - // Get list of subscribers who have not been sent this newsletter: - $unsent_subscribers_array = array_diff_key($subscribers_array, $sent_recipients_array); - - // Create new data object set containing the subscribers who have not been sent this newsletter: - $unsent_subscribers = new DataObjectSet(); - foreach($unsent_subscribers_array as $key => $data) { - $unsent_subscribers->push(new ArrayData($data)); - } - - return $unsent_subscribers; - } - - function getTitle() { - return $this->getField('Subject'); - } - - function getNewsletterType() { - return DataObject::get_by_id('NewsletterType', $this->ParentID); - } - - static $db = array( - "Status" => "Enum('Draft, Send', 'Draft')", - "Content" => "HTMLText", - "Subject" => "Varchar(255)", - "SentDate" => "Datetime", - - ); - - static $has_one = array( - "Parent" => "NewsletterType", - ); - - static $has_many = array( - "Recipients" => "Newsletter_Recipient", - "SentRecipients" => "Newsletter_SentRecipient", - ); - - static function newDraft( $parentID, $subject, $content ) { - if( is_numeric( $parentID ) ) { - $newsletter = new Newsletter(); - $newsletter->Status = 'Draft'; - $newsletter->Title = $newsletter->Subject = $subject; - $newsletter->ParentID = $parentID; - $newsletter->Content = $content; - $newsletter->write(); - } else { - user_error( $parentID, E_USER_ERROR ); - } - - return $newsletter; - } -} - -/** - * Database record for recipients that have had the newsletter sent to them. - * @package cms - * @subpackage newsletter - */ -class Newsletter_SentRecipient extends DataObject { - /** - * The DB schema for Newsletter_SentRecipient. - * - * ParentID is the the Newsletter - * Email and MemberID keep track of the recpients information - * Result has 4 possible values: "Sent", (mail() returned TRUE), "Failed" (mail() returned FALSE), - * "Bounced" ({@see $email_bouncehandler}), or "BlackListed" (sending to is disabled). - */ - static $db = array( - "ParentID" => "Int", - "Email" => "Varchar(255)", - "Result" => "Enum('Sent, Failed, Bounced, BlackListed', 'Sent')", - ); - static $has_one = array( - "Member" => "Member", - ); -} - -/** - * Single recipient of the newsletter - * @package cms - * @subpackage newsletter - */ -class Newsletter_Recipient extends DataObject { - static $db = array( - "ParentID" => "Int", - ); - static $has_one = array( - "Member" => "Member", - ); -} - -/** - * Email object for sending newsletters. - * @package cms - * @subpackage newsletter - */ -class Newsletter_Email extends Email_Template { - protected $nlType; - - function __construct($nlType) { - $this->nlType = $nlType; - parent::__construct(); - } - - function setTemplate( $template ) { - $this->ss_template = $template; - } - - function UnsubscribeLink(){ - $emailAddr = $this->To(); - $nlTypeID = $this->nlType->ID; - return Director::absoluteBaseURL()."unsubscribe/$emailAddr/$nlTypeID"; - } -} -?> \ No newline at end of file diff --git a/code/Newsletter/NewsletterEmailProcess.php b/code/Newsletter/NewsletterEmailProcess.php deleted file mode 100755 index 0fb9e4c8..00000000 --- a/code/Newsletter/NewsletterEmailProcess.php +++ /dev/null @@ -1,143 +0,0 @@ -subject = $subject; - $this->body = $body; - $this->from = $from; - $this->newsletter = $newsletter; - $this->nlType = $nlType; - $this->messageID = $messageID; - - parent::__construct( $recipients ); - - } - - function next( $count = 10 ) { - $max = $this->current + $count; - - $max = $max < count( $this->objects ) ? $max : count( $this->objects ); - - while($this->current < $max) { - $index = $this->current++; - $member = $this->objects[$index]; - - // check to see if the user has unsubscribed from the mailing list - // TODO Join in the above query first - $unsubscribeRecord = DataObject::get_one('Member_UnsubscribeRecord', "`MemberID`='{$member->ID}' AND `NewsletterTypeID`='{$this->nlType->ID}'"); - - if( !$unsubscribeRecord ) { - - $address = $member->Email; - - /** - * Email Blacklisting Support - */ - if($member->BlacklistedEmail && Email_BlackList::isBlocked($address)){ - $bounceRecord = new Email_BounceRecord(); - $bounceRecord->BounceEmail = $member->Email; - $bounceRecord->BounceTime = date("Y-m-d H:i:s",time()); - $bounceRecord->BounceMessage = "BlackListed Email"; - $bounceRecord->MemberID = $member->ID; - $bounceRecord->write(); - - // Log the blacklist for this specific Newsletter - $newsletter = new Newsletter_SentRecipient(); - $newsletter->Email = $address; - $newsletter->MemberID = $member->ID; - $newsletter->Result = 'BlackListed'; - $newsletter->ParentID = $this->newsletter->ID; - $newsletter->write(); - - } else { - $e = new Newsletter_Email($this->nlType); - $e->setBody( $this->body ); - $e->setSubject( $this->subject ); - $e->setFrom( $this->from ); - $e->setTemplate( $this->nlType->Template ); - - if(method_exists($member, "getNameForEmail")) - $nameForEmail = $member->getNameForEmail(); - - $e->populateTemplate( array( 'Member' => $member, 'FirstName' => $member->FirstName, 'NameForEmail'=>$nameForEmail ) ); - $this->sendToAddress( $e, $address, $this->messageID, $member); - } - } - } - - if( $this->current >= count( $this->objects ) ) - return $this->complete(); - else - return parent::next(); - } - - /* - * Sends a Newsletter email to the specified address - * - * @param $member The object containing information about the member being emailed - */ - private function sendToAddress( $email, $address, $messageID = null, $member) { - $email->setTo( $address ); - $result = $email->send( $messageID ); - // Log result of the send - $newsletter = new Newsletter_SentRecipient(); - $newsletter->Email = $address; - $newsletter->MemberID = $member->ID; - // If Sending is successful - if ($result == true) { - $newsletter->Result = 'Sent'; - } else { - $newsletter->Result = 'Failed'; - } - $newsletter->ParentID = $this->newsletter->ID; - $newsletter->write(); - // Adding a pause between email sending can be useful for debugging purposes - // sleep(10); - } - - function complete() { - parent::complete(); - - if( $this->newsletter->SentDate ) { - $resent = true; - } else { - $resent = false; - } - - $this->newsletter->SentDate = 'now'; - $this->newsletter->Status = 'Send'; - $this->newsletter->write(); - - // Call the success message JS function with the Newsletter information - if( $resent ) { - return "resent_ok( '{$this->nlType->ID}', '{$this->newsletter->ID}', '".count( $this->objects )."' )"; - } else { - return "draft_sent_ok( '{$this->nlType->ID}', '{$this->newsletter->ID}', '".count( $this->objects )."' )"; - } - } -} -?> \ No newline at end of file diff --git a/code/Newsletter/NewsletterList.php b/code/Newsletter/NewsletterList.php deleted file mode 100755 index cd06e8e2..00000000 --- a/code/Newsletter/NewsletterList.php +++ /dev/null @@ -1,55 +0,0 @@ -mailType = $mailtype; - else $this->mailType = DataObject::get_by_id('NewsletterType',$mailtype); - $this->status = $status; - parent::__construct(null); - } - - function FieldHolder() { - return $this->renderWith("NewsletterList"); - } - - - function setMailType($mailtype) { - $this->mailType = $mailtype; - } - - function setController($controller) { - $this->controller = $controller; - } - /* No longer used - function Newsletters() { - return DataObject::get( 'Newsletter', "`ParentID`='{$this->mailType->ID}' AND `Status`='{$this->status}'" ); - } - */ - - function DraftNewsletters() { - return $this->mailType->DraftNewsletters(); - } - - function SentNewsletters() { - return $this->mailType->SentNewsletters(); - } - - function Status() { - return $this->status; - } - function mailTypeID() { - return $this->mailType->ID; - } -} - -?> \ No newline at end of file diff --git a/code/Newsletter/NewsletterType.php b/code/Newsletter/NewsletterType.php deleted file mode 100755 index 03120d84..00000000 --- a/code/Newsletter/NewsletterType.php +++ /dev/null @@ -1,137 +0,0 @@ - "Varchar", - "Template" => "Varchar", - "FromEmail" => "Varchar", - "Sent" => "Datetime" - ); - static $has_one = array( - "Parent" => "SiteTree", - "Group" => "Group", - ); - static $has_many = array( - "Newsletters" => "Newsletter", - ); - - function DraftNewsletters() { - return DataObject::get("Newsletter","ParentID={$this->ID} AND Status ='Draft'"); - } - - function SentNewsletters() { - return DataObject::get("Newsletter","ParentID={$this->ID} AND Status ='Send'"); - } - - function Recipients() { - return DataObject::get("Member", "Group_Members.GroupID = {$this->GroupID}", "", "JOIN Group_Members on Group_Members.MemberID = Member.ID"); - } - - function delete() { - foreach( $this->Newsletters() as $newsletter ) - $newsletter->delete(); - - parent::delete(); - } - - /** - * Updates the group so the security section is also in sync with - * the curent newsletters. - */ - function onBeforeWrite(){ - if($this->ID){ - $group = $this->Group(); - if($group->Title != "$this->Title"){ - $group->Title = _t('NewsletterType.MAILINGLIST', 'Mailing List:').' '. $this->Title; - // Otherwise the code would have mailing list in it too :-( - $group->Code = SiteTree::generateURLSegment($this->Title); - $group->write(); - } - } - parent::onBeforeWrite(); - } - - /** - * Get the fieldset to display in the administration section - */ - function getCMSFields() { - $group = null; - if($this->GroupID) { - $group = DataObject::get_one("Group", "ID = $this->GroupID"); - } - - $fields = new FieldSet( - new TextField("Title", _t('NewsletterType.NEWSLETTERTYPE', 'Newsletter Type')), - new TextField("FromEmail", _t('NewsletterType.SENDFROM', 'Send newsletters from')), - new TabSet("Root", - new Tab(_t('NewsletterType.DRAFTS', 'Drafts'), - $draftList = new NewsletterList("Draft", $this, _t('NewsletterType.DRAFT', 'Draft')) - ), - new TabSet('Sent', - new Tab(_t('NewsletterType.SENT', 'Sent'), - $sendList = new NewsletterList("Send", $this, _t('NewsletterType.SEND', 'Send')) - ), - new Tab(_t('NewsletterType.UNSUBSCRIBED', 'Unsubscribed'), - $unsubscribedList = new UnsubscribedList("Unsubscribed", $this) - ), - new Tab(_t('NewsletterType.BOUNCED', 'Bounced'), - $bouncedList = new BouncedList("Bounced", $this ) - ) - ) - ) - ); - - if($this->GroupID) { - $fields->addFieldToTab('Root', - new TabSet("Recipients", - new Tab( _t('NewsletterType.RECIPIENTS', 'Recipients'), - $recipients = new MemberTableField( - $this, - "Recipients", - $group - ) - ), - new Tab( _t('NewsletterType.IMPORT', 'Import'), - $importField = new RecipientImportField("ImportFile", _t('NewsletterType.IMPORTFROM', 'Import from file'), $group ) - ) - ) - ); - - $recipients->setController($this); - $importField->setController($this); - $importField->setTypeID( $this->ID ); - } - - $fields->addFieldToTab('Root', - new Tab(_t('NewsletterType.TEMPLATE', 'Template'), - $templates = new TemplateList("Template","Template", $this->Template, NewsletterAdmin::template_path()) - ) - ); - - $draftList->setController($this); - $sendList->setController($this); - - $templates->setController($this); - $unsubscribedList->setController($this); - $bouncedList->setController($this); - - $fields->push($idField = new HiddenField("ID")); - $fields->push( new HiddenField( "executeForm", "", "TypeEditForm" ) ); - $idField->setValue($this->ID); - - return $fields; - } -} -?> diff --git a/code/Newsletter/RecipientImportField.php b/code/Newsletter/RecipientImportField.php deleted file mode 100755 index 3b43ba56..00000000 --- a/code/Newsletter/RecipientImportField.php +++ /dev/null @@ -1,391 +0,0 @@ - array( 'title', 'salutation' ), - 'FirstName' => array( 'firstname', 'christianname', 'givenname' ), - 'Surname' => array( 'lastname','surname', 'familyname' ), - 'Email' => array( 'email', 'emailaddress' ), - 'Address' => array( 'address' ), - 'PhoneNumber' => array('phone','phonenumber'), - 'JobTitle' => array( 'jobtitle' ), - 'Organisation' => array( 'organisation', 'organization' ), - 'EmailType' => array( 'htmlorplaintext', 'emailtype' ) - ); - - static $custom_set_fields = array(); - - public static function setCustomField( $getMapCode, $fieldName ) { - self::$custom_set_fields[] = array( - 'Code' => $getMapCode, - 'Field' => $fieldName - ); - } - - function __construct( $name, $title, $memberGroup, $memberClass = 'Member', $form = null ) { - $this->memberGroup = $memberGroup; - $this->memberClass = $memberClass; - parent::__construct( $name, $title, null, $form ); - } - - function Field() { - $frameURL = Director::absoluteBaseURL() . 'admin/newsletter/displayfilefield/' . $this->typeID; - - return ""; - } - - function setTypeID( $id ) { - $this->typeID = $id; - } - - function CustomSetFields() { - $fields = new FieldSet(); - - - - foreach( self::$custom_set_fields as $customField ) { - eval( '$map = ' . $customField['Code'] .';' ); - - $noneMap = array( 0 => '(Not set)' ); - - $map = $noneMap + $map; - - $fields->push( new DropdownField( 'Set['.$customField['Field'].']', $customField['Field'], $map ) ); - } - - return $fields; - } - - /** - * Returns HTML to be displayed inside the IFrame - */ - static function fileupload() { - - } - - /** - * Returns the table of results to be displayed in the table of - * details loaded from the file - */ - function displaytable() { - - // Check that a file was uploaded - - $tempFile = fopen( $_FILES['ImportFile']['tmp_name'], 'r' ); - - // display some error if the file cannot be opened - - $this->clientFileName = $_FILES['ImportFile']['name']; - - while( ( $row = fgetcsv( $tempFile ) ) !== false ) { - - if( !$this->tableColumns ) { - $this->parseTableHeader( $row ); - } else { - $newRow = array(); - $newSessionTableRow = array(); - - foreach( $row as $cell ) { - $newRow[] = $this->parseCSVCell( $cell ); - $newSessionTableRow[] = $cell; - } - - $cells = new DataObjectSet( $newRow ); - $table[] = $cells->customise( array( 'Cells' => $cells ) ); - - $sessionTable[] = $newSessionTableRow; - } - } - - fclose( $tempFile ); - - $this->table = new DataObjectSet( $table ); - - Session::set("ImportFile.{$_REQUEST['ID']}", $sessionTable); - - return $this->renderWith( 'Newsletter_RecipientImportField_Table' ); - } - - /** - * Determines what type each column is - */ - function parseTableHeader( $columns ) { - - $columnSource = array_combine( - array_keys( self::$column_types ), - array_keys( self::$column_types ) - ); - - $columnSource = array_merge( array( 'Unknown' => 'Unknown' ), $columnSource ); - $colCount = 0; - foreach( $columns as $cell ) { - $columnType = $this->getColumnType( $this->parseCSVCell( $cell )->Value() ); - $this->tableColumns[] = new DropdownField( 'ImportFileColumns[' . (string)( $colCount++ ) . ']', '', $columnSource, $columnType ); - } - } - - function parseCSVCell( $cell ) { - return new RecipientImportField_Cell( $cell ); - } - - function getColumnType( $cell ) { - $cell = strtolower( $cell ); - $escapedValue = preg_replace( '/[^a-z]/', '', $cell ); - - foreach( self::$column_types as $type => $aliases ) { - if( in_array( $escapedValue, $aliases ) ) - return $type; - } - - return 'Unknown'; - } - - function setController( $controller ) { - $this->controller = $controller; - } - - /** - * Set of table column headers - */ - function ColumnHeaders() { - return new DataObjectSet( $this->tableColumns ); - } - - function Rows() { - return $this->table; - } - - function FileName() { - return $this->clientFileName; - } - - function TypeID() { - return $this->typeID; - } -} - -/** - * Single cell of the recipient import field - * @package cms - * @subpackage newsletter - */ -class RecipientImportField_Cell extends ViewableData { - protected $value; - - function __construct( $value ) { - $this->value = $value; - } - - function Value() { - return $this->value; - } -} - -/** - * Upload form that appears in the iframe - * @package cms - * @subpackage newsletter - */ -class RecipientImportField_UploadForm extends Form { - function import( $data, $form ) { - $id = $data['ID']; - $mailType = DataObject::get_one("NewsletterType", "ID = $id"); - if($mailType->GroupID) - $group = DataObject::get_one("Group", "ID = $mailType->GroupID"); - - $recipientField = new RecipientImportField("ImportFile","Import from file", $group ); - $recipientField->setTypeID( $id ); - - // if the file is not valid, then return an error - if( empty( $_FILES ) || empty( $_FILES['ImportFile'] ) || $_FILES['ImportFile']['size'] == 0 ) - return $this->customise( array( 'ID' => $id, "UploadForm" => $this->controller->UploadForm( $id ), 'ErrorMessage' => 'Please choose a CSV file to import' ) )->renderWith('Newsletter_RecipientImportField'); - elseif( !$this->isValidCSV( $_FILES['ImportFile'] ) ) { - /*if( file_exists( $_FILES['ImportFile']['tmp_name'] ) ) unlink( $_FILES['ImportFile']['tmp_name'] ); - unset( $_FILES['ImportFile'] );*/ - return $this->customise( array( 'ID' => $id, "UploadForm" => $this->controller->UploadForm( $id ), 'ErrorMessage' => 'The selected file was not a CSV file' ) )->renderWith('Newsletter_RecipientImportField'); - } else - return $recipientField->displaytable(); - } - - function isValidCSV( $file ) { - return preg_match( '/.*\.csv$/i', $file['name'] ) > 0; - } - - function confirm( $data, $form ) { - $id = $data['ID']; - $mailType = DataObject::get_one("NewsletterType", "ID = $id"); - if($mailType->GroupID) - $group = DataObject::get_one("Group", "ID = $mailType->GroupID"); - // @TODO Look into seeing if $data['Set'] should be removed since it seems to be undefined - return $this->importMembers( $id, $group, $data['ImportFileColumns'], $data['Set'] ); - } - - function cancel( $data, $form ) { - $newForm = $this->controller->UploadForm( $data['ID'] ); - return $newForm->forTemplate(); - } - - function action_import( $data, $form ) { - return $this->import( $data, $form ); - } - - function action_confirm( $data, $form ) { - return $this->confirm( $data, $form ); - } - - function action_cancel( $data, $form ) { - return $this->cancel( $data, $form ); - } - - /** - * Import members from the uploaded file - */ - protected function importMembers( $id, $group, $cols, $setFields, $primaryColType = 'Email' ) { - - $startTime = time(); - - $importData = Session::get("ImportFile.{$id}"); - - $validColumns = array_keys( RecipientImportField::$column_types ); - - $columnMap = array_flip( $cols ); - - // Debug::show($columnMap); - - // locate the primary column's index - $primaryColumn = /*array_search( $primaryColType, $validColumns );*/ $columnMap[$primaryColType]; - - // changed fields - $changedFields = array(); - - // intersect the list of valid columns with the column map to find the columns we need - $importColumns = array_intersect( $validColumns, $cols ); - - // statistics - $newMembers = 0; - $changedMembers = 0; - $skippedMembers = 0; - - // the class that the imported members will become - $newMemberClass = Object::getCustomClass( 'Member' ); - - // for each row, add a new member or overwrite an existing member - foreach( $importData as $newMemberRow ) { - - // skip rows with an empty value for the primary column - if( empty( $newMemberRow[$primaryColumn] ) ) { - $skippedMembers++; - continue; - } - - // remember to check if the user has unsubscribed - $trackChanges = true; - - // TODO: Write DataObject::update - $member = $this->findMember( $newMemberRow[$primaryColumn] ); - - if( !$member ) { - $newMembers++; - $trackChanges = false; - $member = Object::create("Member"); - } else { - // skip this member if the are unsubscribed - if( $member->Unsubscribed ) { - $skippedMembers++; - continue; - } - - if( $member->class != $newMemberClass ) - $member->setClassName( $newMemberClass ); - - $changedMembers++; - } - - // add each of the valid columns - foreach( $importColumns as $datum ) { - - // perform any required conversions - $newValue = trim( $newMemberRow[$columnMap[$datum]] ); - $oldValue = trim( $member->$datum ); - - // Debug::message( "$datum@{$columnMap[$datum]}" ); - - // track the modifications to the member data - if( $trackChanges && $newValue != $oldValue && $datum != $primaryColumn ) { - $changedFields[] = array( - $newMemberRow[$primaryColumn], - "$datum:\n$oldValue", - "$datum:\n$newValue" - ); - - $numChangedFields++; - } - - $member->$datum = $newValue; - } - - // set any set fields - if( $setFields ) - foreach( $setFields as $fieldName => $fieldValue ) - $member->$fieldName = $fieldValue; - - // add member to group - $member->write(); - $member->Groups()->add( $group->ID ); - } - - $numChangedFields = count( $changedFields ); - $this->notifyChanges( $changedFields ); - - // TODO Refresh window - $customData = array( - 'ID' => $id, - "UploadForm" => $this->controller->UploadForm( $id ), - 'ImportMessage' => 'Imported new members', - 'NewMembers' => (string)$newMembers, - 'ChangedMembers' => (string)$changedMembers, - 'ChangedFields' => (string)$numChangedFields, - 'SkippedRecords' => (string)$skippedMembers, - 'Time' => time() - $startTime - ); - return $this->customise( $customData )->renderWith('Newsletter_RecipientImportField'); - } - - function findMember( $email ) { - $email = addslashes( $email ); - return DataObject::get_one( 'Member', "`Email`='$email'" ); - } - - function notifyChanges( $changes ) { - $email = new Email( Email::getAdminEmail(), Email::getAdminEmail(), 'Changed Fields' ); - - $body = ""; - - foreach( $changes as $change ) { - $body .= "-------------------------------\n"; - $body .= implode( ' ', $change ) . "\n"; - } - - $email->setBody( $body ); - $email->send(); - } -} -?> \ No newline at end of file diff --git a/code/Newsletter/SubscribeForm.php b/code/Newsletter/SubscribeForm.php deleted file mode 100755 index 4f22f885..00000000 --- a/code/Newsletter/SubscribeForm.php +++ /dev/null @@ -1,278 +0,0 @@ - 'EditableEmailField(CustomParameter=Email,CanDelete=0)', - 'First name' => 'EditableTextField(CustomParameter=FirstName)', - 'Last name' => 'EditableTextField(CustomParameter=Surname)', - 'Address' => 'EditableTextField(Rows=3,CustomParameter=Address)', - 'Job title' => 'EditableTextField(CustomParameter=JobTitle)', - 'Organisation' => 'EditableTextField(CustomParameter=Organisation)', - 'Mail format' => 'EditableRadioField(Options=1:HTML,Options=0:Text__only,CustomParameter=HTMLEmail)' - ); - - static $db = array( - 'Subscribe' => 'Boolean', - 'AllNewsletters' => 'Boolean', - 'Subject' => 'Varchar' - ); - - static $defaults = array( - "OnCompleteMessage" => "
Thanks, you have been added to our mailing list.
", - ); - - static $has_many = array( - 'Newsletters' => 'NewsletterType' - ); - - function __construct( $data = null, $isSingleton = false ) { - parent::__construct( $data, $isSingleton ); - - if( $data || $isSingleton ) - return; - - $this->addDefaultFields(); - } - - private function addDefaultFields() { - $f = $this->Fields(); - - // check that the required fields exist - $count = 1; - - foreach( self::$required_fields as $defaultName => $typeString ) { - - list( $type, $typeValue ) = $this->parseType( $typeString ); - $newField = new $type(); - $newField->Name = "Field" . (string)$count; - $newField->Title = $defaultName; - - // TODO Map the field to a particular action - - if( !empty( $typeValue ) ) { - $newField->prepopulate( $typeValue ); - } - - $newField->ParentID = $this->ID; - $newField->Sort = $count; - $newField->write(); - $count++; - } - } - - public function write($showDebug = false, $forceInsert = false, $forceWrite = false) { - $isNew = (!$this->ID); - parent::write($showDebug, $forceInsert, $forceWrite); - if($isNew) $this->addDefaultFields(); - } - - public function Newsletters() { - $components = $this->getComponents('Newsletters'); - return $components; - } - - public function customFormActions( $isReadonly = false ) { - - $fields = parent::customFormActions( $isReadonly ); - - // get the newsletters in the system - $newsletterTypes = DataObject::get( 'NewsletterType' ); - - $availableNewsletters = array(); - $nlCheckboxes = array(); - - - foreach( $this->Newsletters() as $subscribeTo ) - $availableNewsletters[] = $subscribeTo->ID; - - - - // create a checkbox for each newsletter - if($newsletterTypes && is_object($newsletterTypes)) { - foreach( $newsletterTypes as $newsletterType ) - $nlCheckboxes[] = new CheckboxField( "CustomNewsletters[{$newsletterType->ID}]", $newsletterType->Title, in_array( $newsletterType->ID, $availableNewsletters ) ); - } - $fields->push( new OptionsetField( 'AllNewsletters', '', array( - 1 => 'All newsletters', - 0 => 'Specific newsletters' - ), - $this->AllNewsletters - )); - - $fields->push( new CompositeField( $nlCheckboxes )); - $fields->push( new TextField( 'Subject', 'Subject line on confirmation', $this->Subject ) ); - - return $fields; - } - - function parseType( $typeString ) { - if( preg_match('/^([A-Za-z_]+)\(([^)]+)\)$/', $typeString, $match ) ) - return array( $match[1], $match[2] ); - - return array( $typeString, null ); - } - - /** - * - */ - public function processNewFormFields() { - - } - - /** - * Saves data related to any custom actions this form performs when submitted - */ - public function customFormSave( $data, $form ) { - - $newsletters = $this->Newsletters(); - - $this->Subscribe = !empty( $data['Subscribe'] ); - $this->AllNewsletters = !empty( $data['AllNewsletters'] ); - $this->Subject = $data['Subject']; - // Note: $data['CustomNewsletters'] was changed to $_REQUEST['CustomNewsletters'] in order to fix - // to fix "'Specific newsletters' option in 'newsletter subscription form' page type does not work" bug - // See: http://www.silverstripe.com/bugs/flat/1675 - if( !empty( $_REQUEST['CustomNewsletters'] ) ) { - /*foreach( $newsletters as $newsletter ) { - if( $data['CustomNewsletters'][$newsletter->ID] == 'on' ) { - $newsletters->add( $newsletter->ID ); - } else { - $newsletters->remove( $newsletter->ID ); - } - }*/ - - if( isset($_REQUEST['CustomNewsletters'][0]) ) - unset( $_REQUEST['CustomNewsletters'][0] ); - - $newsletters->setByIDList( array_keys( $_REQUEST['CustomNewsletters'] ) ); - } else { - $this->AllNewsletters = true; - $newsletters->removeAll(); - } - } -} - -/** - * Email for sending subscribe form submissions. - * @package cms - * @subpackage newsletter - */ -class SubscribeForm_SubscribeEmail extends Email_Template { - protected $to = '$Email'; - protected $subject = '$Subject'; - protected $ss_template = 'SubscribeEmail'; - protected $from = ''; -} - -/** - * Controller for the SubscribeForm page - * @package cms - * @subpackage newsletter - */ -class SubscribeForm_Controller extends UserDefinedForm_Controller { - - function process( $data, $form ) { - // Add the user to the mailing list - $member = Object::create("Member"); - - // $_REQUEST['showqueries'] = 1; - - // map the editables to the data - - foreach( $this->Fields() as $editable ) { - $field = $editable->CustomParameter; - if( !$field ) - continue; - - // Debug::message( $editable->Name . '->' . $field ); - - // if( $member->hasField( $field ) ) - $member->$field = $data[$editable->Name]; - } - - // need to write the member record before adding the user to groups - $member->write(); - - $newsletters = array(); - - // Add member to the selected newsletters - if( isset($data['Newsletters'])) foreach( $data['Newsletters'] as $listID ) { - - if( !is_numeric( $listID ) ) - continue; - - // get the newsletter - $newsletter = DataObject::get_by_id( 'NewsletterType', $listID ); - - if( !$newsletter ) - continue; - - $newsletters[] = $newsletter; - // Debug::show( $newsletter->GroupID ); - - $member->Groups()->add( $newsletter->GroupID ); - } - - // email the user with their details - $templateData = array( - 'Email' => $member->Email, - 'FirstName' => $member->FirstName, - 'Newsletters' => new DataObjectSet( $newsletters ), - 'UnsubscribeLink' => Director::baseURL() . 'unsubscribe/' . $member->Email - ); - - $email = new SubscribeForm_SubscribeEmail(); - $email->setFrom( Email::getAdminEmail() ); - $email->setSubject( $this->Subject ); - - $email->populateTemplate( $templateData ); - $email->send(); - - $parentHTML = parent::process( $data, $form ); - - $templateData['Link'] = $data['Referrer']; - $templateData['UnsubscribeLink'] = Director::baseURL() . 'unsubscribe'; - - $custom = $this->customise(array( - "Content" => $this->customise( $templateData )->renderWith('SubscribeSubmission') - )); - - return $custom->renderWith('Page'); - } - - function Form() { - $form = parent::Form(); - - if( $this->AllNewsletters ) - $newsletterList = DataObject::get('NewsletterType'); - else - $newsletterList = $this->Newsletters(); - - $newsletters = array(); - - // get the newsletter types to display on the form - foreach( $newsletterList as $newsletter ) - $newsletters[$newsletter->ID] = $newsletter->Title; - - $form->Fields()->push( new CheckboxSetField( 'Newsletters', 'Subscribe to lists', $newsletters ) ); - - $validator = $form->getValidator(); - $validator->addRequiredField( 'Newsletters' ); - $form->setValidator( $validator ); - - return $form; - } -} -?> \ No newline at end of file diff --git a/code/Newsletter/TemplateList.php b/code/Newsletter/TemplateList.php deleted file mode 100755 index c5c598d5..00000000 --- a/code/Newsletter/TemplateList.php +++ /dev/null @@ -1,48 +0,0 @@ -templatePath = $path; - parent::__construct( $name, $title, $this->getTemplates(), $value, $form ); - } - - private function getTemplates() { - $templates = array( "" => _t('TemplateList.NONE', 'None') ); - - $absPath = Director::baseFolder(); - if( $absPath{strlen($absPath)-1} != "/" ) - $absPath .= "/"; - - $absPath .= $this->templatePath; - if(is_dir($absPath)) { - $templateDir = opendir( $absPath ); - - // read all files in the directory - while( ( $templateFile = readdir( $templateDir ) ) !== false ) { - // *.ss files are templates - if( preg_match( '/(.*)\.ss$/', $templateFile, $match ) ) - $templates[$match[1]] = $match[1]; - } - } - - return $templates; - } - - function setController( $controller ) { - $this->controller = $controller; - } -} -?> \ No newline at end of file diff --git a/code/Newsletter/Unsubscribe.php b/code/Newsletter/Unsubscribe.php deleted file mode 100755 index 6dc542f0..00000000 --- a/code/Newsletter/Unsubscribe.php +++ /dev/null @@ -1,206 +0,0 @@ -urlParams['Email'] ); - $mailingListID = addslashes( $this->urlParams['MailingList'] ); - - if(is_numeric($mailingListID)) { - $mailingList = DataObject::get_by_id("NewsletterType", $mailingListID); - } - - // try to find the user - if($emailAddress) - $member = DataObject::get_one( 'Member', "`Email`='$emailAddress'" ); - - // if the email address and mailing list is given in the URL and both are valid, - // then unsubscribe the user - if( $member && $mailingList && $member->inGroup( $mailingList->GroupID ) ) { - $this->unsubscribeFromList( $member, $mailingList ); - $url = "unsubscribe"."/done/".$member->Email."/".$mailingList->Title; - Director::redirect($url); - } elseif( $member ) { - $listForm = $this->MailingListForm( $member ); - } else { - $listForm = $this->EmailAddressForm(); - } - - if($this->urlParams['Email'] == "done") - $listForm->sessionMessage(_t('Unsubscribe.SUCCESS', 'Thank you. You have been removed from the selected groups'), "good"); - - return $this->customise( array( 'Content' => $listForm->forTemplate() ) )->renderWith('Page'); - } - - /** - * Display a form with all the mailing lists that the user is subscribed to - */ - function MailingListForm( $member = null ) { - $email = $this->urlParams['Email']; - return new Unsubscribe_MailingListForm($this, 'MailingListForm', $member, $email); - } - - /** - * Display a form allowing the user to input their email address - */ - function EmailAddressForm() { - return new Unsubscribe_EmailAddressForm( $this, 'EmailAddressForm' ); - } - - /** - * Show the lists for the user with the given email address - */ - function showlists( $data, $form ) { - $member = DataObject::get_one( 'Member', "`Email`='{$data['Email']}'" ); - - - $mailingListForm = new Unsubscribe_MailingListForm( $this, 'MailingListForm', $member, $data['Email']); - - return $this->customise( array( 'Content' => $mailingListForm->forTemplate() ) )->renderWith('Page'); - } - - /** - * Unsubscribe the user from the given lists. - */ - function unsubscribe($data, $form) { - $email = $this->urlParams['Email']; - $member = DataObject::get_one( 'Member', "`Email`='$email'" ); - if(!$member){ - $member = DataObject::get_one('Member', "`EmailAddress` = '$email'"); - } - - if( $data['MailingLists'] ) { - foreach( array_keys( $data['MailingLists'] ) as $listID ){ - - $nlType = DataObject::get_by_id( 'NewsletterType', $listID ); - $nlTypeTitles[]= $nlType->Title; - $this->unsubscribeFromList( $member, DataObject::get_by_id( 'NewsletterType', $listID ) ); - } - - $sORp = (sizeof($nlTypeTitles)>1)?"newsletters ":"newsletter "; - //means single or plural - $nlTypeTitles = $sORp.implode(", ", $nlTypeTitles); - $url = "unsubscribe/done/".$member->Email."/".$nlTypeTitles; - Director::redirect($url); - } else { - $form->addErrorMessage('MailingLists', _t('Unsubscribe.NOMLSELECTED', 'You need to select at least one mailing list to unsubscribe from.'), 'bad'); - Director::redirectBack(); - } - } - - protected function unsubscribeFromList( $member, $list ) { - // track unsubscriptions - $member->Groups()->remove( $list->GroupID ); - $unsubscribeRecord = new Member_UnsubscribeRecord(); - $unsubscribeRecord->unsubscribe($member, $list); - } -} - -/** - * 2nd step form for the Unsubcribe page. - * The form will list all the mailing lists that the user is subscribed to. - * @package cms - * @subpackage newsletter - */ -class Unsubscribe_MailingListForm extends Form { - - protected $memberEmail; - - function __construct( $controller, $name, $member, $email ) { - - $this->memberEmail = $member->Email; - - $fields = new FieldSet(); - $actions = new FieldSet(); - - // get all the mailing lists for this user - $lists = $this->getMailingLists( $member ); - - if( $lists ) { - $fields->push( new LabelField( _t('Unsubcribe.SUBSCRIBEDTO', 'You are subscribed to the following lists:')) ); - - foreach( $lists as $list ) { - $fields->push( new CheckboxField( "MailingLists[{$list->ID}]", $list->Title ) ); - } - - $actions->push( new FormAction('unsubscribe', _t('Unsubscribe.UNSUBSCRIBE', 'Unsubscribe') ) ); - } else { - $fields->push( new LabelField(sprintf(_t('Unsubscribe.NOTSUBSCRIBED', 'I\'m sorry, but %s doesn\'t appear to be in any of our mailing lists.'), $email) ) ); - } - - parent::__construct( $controller, $name, $fields, $actions ); - } - - function FormAction() { - return $this->controller->Link() . "{$this->memberEmail}?executeForm=" . $this->name; - } - - protected function getMailingLists( $member ) { - // get all the newsletter types that the member is subscribed to - return DataObject::get( 'NewsletterType', "`MemberID`='{$member->ID}'", null, "LEFT JOIN `Group_Members` USING(`GroupID`)" ); - } -} - -/** - * 1st step form for the Unsubcribe page. - * The form will let people enter an email address and press a button to continue. - * @package cms - * @subpackage newsletter - */ -class Unsubscribe_EmailAddressForm extends Form { - - function __construct( $controller, $name ) { - - $fields = new FieldSet( - new EmailField( 'Email', _t('Unsubscribe.EMAILADDR', 'Email address') ) - ); - - $actions = new FieldSet( - new FormAction( 'showlists', _t('Unsubscribe.SHOWLISTS', 'Show lists') ) - ); - - parent::__construct( $controller, $name, $fields, $actions ); - } - - function FormAction() { - return parent::FormAction() . ( $_REQUEST['showqueries'] ? '&showqueries=1' : '' ); - } -} - -/** - * Final stage form for the Unsubcribe page. - * The form just gives you a success message. - * @package cms - * @subpackage newsletter - */ -class Unsubscribe_Successful extends Form { - function __construct($controller, $name){ - $fields = new FieldSet(); - $actions = new FieldSet(); - parent::__construct($controller, $name, $fields, $actions); - } - function setSuccessfulMessage($email, $newsletterTypes) { - Requirements::themedCSS("form"); - $this->setMessage(sprintf(_t('Unsubscribe.REMOVESUCCESS', 'Thank you. %s will no longer receive the %s.'), $email, $newsletterTypes), "good"); - } -} - -?> diff --git a/code/Newsletter/UnsubscribedList.php b/code/Newsletter/UnsubscribedList.php deleted file mode 100755 index 9d96f8d2..00000000 --- a/code/Newsletter/UnsubscribedList.php +++ /dev/null @@ -1,57 +0,0 @@ -nlType = $newsletterType; - else - $this->nlType = DataObject::get_by_id( 'NewsletterType', $newsletterType ); - } - - function FieldHolder() { - return $this->renderWith( 'NewsletterAdmin_UnsubscribedList' ); - } - - function Entries() { - - $id = $this->nlType->ID; - - $unsubscribeRecords = DataObject::get( 'Member_UnsubscribeRecord', "`NewsletterTypeID`='$id'" ); - - // user_error($id, E_USER_ERROR ); - - if( !$unsubscribeRecords ) - return null; - - foreach( $unsubscribeRecords as $unsubscribeRecord ) { - if( $unsubscribeRecord ) { - $unsubscribedUsers[] = new ArrayData( array( - 'Record' => $unsubscribeRecord, - 'Member' => DataObject::get_by_id( 'Member', $unsubscribeRecord->MemberID ) - )); - } - } - - return new DataObjectSet( $unsubscribedUsers ); - } - - function setController($controller) { - $this->controller = $controller; - } -} -?> diff --git a/code/NewsletterAdmin.php b/code/NewsletterAdmin.php deleted file mode 100755 index 44526e67..00000000 --- a/code/NewsletterAdmin.php +++ /dev/null @@ -1,801 +0,0 @@ -isAdmin()) Security::permissionFailure($this); - - parent::init(); - /* - if(!$this->can('AdminCMS')) { - $messageSet = array( - 'default' => "Please choose an authentication method and enter your credentials to access the CMS.", - 'alreadyLoggedIn' => "I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below", - 'logInAgain' => "You have been logged out of the CMS. If you would like to log in again, enter a username and password below.", - ); - - Security::permissionFailure($this, $messageSet); - return; - }*/ - - Requirements::javascript(MCE_ROOT . "tiny_mce_src.js"); - Requirements::javascript("jsparty/tiny_mce_improvements.js"); - - Requirements::javascript("jsparty/hover.js"); - Requirements::javascript("jsparty/scriptaculous/controls.js"); - - Requirements::javascript("cms/javascript/SecurityAdmin.js"); - - Requirements::javascript("cms/javascript/LeftAndMain_left.js"); - Requirements::javascript("cms/javascript/LeftAndMain_right.js"); - Requirements::javascript("cms/javascript/CMSMain_left.js"); - - Requirements::javascript("cms/javascript/NewsletterAdmin_left.js"); - Requirements::javascript("cms/javascript/NewsletterAdmin_right.js"); - Requirements::javascript("sapphire/javascript/ProgressBar.js"); - - // We don't want this showing up in every ajax-response, it should always be present in a CMS-environment - if(!Director::is_ajax()) { - Requirements::javascriptTemplate("cms/javascript/tinymce.template.js", array( - "ContentCSS" => project() . "/css/editor.css", - "BaseURL" => Director::absoluteBaseURL(), - "Lang" => i18n::get_tinymce_lang() - )); - } - - // needed for MemberTableField (Requirements not determined before Ajax-Call) - Requirements::javascript("cms/javascript/MemberTableField.js"); - - Requirements::css("cms/css/NewsletterAdmin.css"); - } - - public function remove() { - $ids = explode( ',', $_REQUEST['csvIDs'] ); - - $count = 0; - foreach( $ids as $id ) { - if( preg_match( '/^mailtype_(\d+)$/', $id, $matches ) ) - $record = DataObject::get_by_id( 'NewsletterType', $matches[1] ); - else if( preg_match( '/^[a-z]+_\d+_(\d+)$/', $id, $matches ) ) - $record = DataObject::get_by_id( 'Newsletter', $matches[1] ); - - if($record) { - $record->delete(); - } - - FormResponse::add("removeTreeNodeByIdx(\$('sitetree'), '$id' );"); - // Don't allow a deleted draft to be edited - FormResponse::add("$('Form_EditForm').closeIfSetTo('$matches[1]');"); - $count++; - } - - FormResponse::status_message('Deleted '.$count.' items','good'); - - return FormResponse::respond(); - } - - public function getformcontent(){ - Session::set('currentPage', $_REQUEST['ID']); - Session::set('currentType', $_REQUEST['type']); - if($_REQUEST['otherID']) - Session::set('currentOtherID', $_REQUEST['otherID']); - SSViewer::setOption('rewriteHashlinks', false); - $result = $this->renderWith($this->class . "_right"); - return $this->getLastFormIn($result); - } - - /** - * Called when a mailing list is clicked on the left menu - */ - public function showrecipients($params) { - return $this->showWithEditForm( $params, $this->getMailingListEditForm( $params['ID'] ) ); - } - - /** - * Called when a draft or sent newsletter is clicked on the left menu and when a new one is added - */ - public function shownewsletter($params) { - return $this->showWithEditForm( $params, $this->getNewsletterEditForm( $params['ID'] ) ); - } - - /** - * Called when a newsletter type is clicked on the left menu - */ - public function showmailtype($params) { - return $this->showWithEditForm( $params, $this->getNewsletterTypeEditForm( $params['ID'] ) ); - } - - /** - * Called when a 'Drafts' folder is clicked on the left menu - */ - public function showdrafts($params) { - return $this->ShowNewsletterFolder($params, 'Draft'); - } - - /** - * Called when a 'Sent Items' folder is clicked on the left menu - */ - public function showsent($params) { - return $this->ShowNewsletterFolder($params, 'Sent'); - } - - /** - * Shows either the 'Sent' or 'Drafts' folder using the NewsletterList template - */ - public function ShowNewsletterFolder($params, $type) { - $id = $params['ID']; - if(!is_numeric($id)) { - $id = Session::get('currentPage'); - } - if( is_a( $id, 'NewsletterType' ) ) { - $mailType = $id; - $id = $mailType->ID; - } else { - if($id && is_numeric($id)) { - $mailType = DataObject::get_by_id( 'NewsletterType', $id ); - } - } - $draftList = new NewsletterList($type, $mailType, $type); - return $draftList->renderWith("NewsletterList"); - } - - public function removenewsletter($params) { - if( !is_numeric( $params['ID'] ) ) - return ''; - - $newsletter = DataObject::get_by_id( 'Newsletter', $params['ID'] ); - $newsletter->delete(); - return 'letter-' . $params['ID']; - } - - private function showWithEditForm( $params, $editForm ) { - if(isset($params['ID'])) { - Session::set('currentPage', $params['ID']); - } - if(isset($params['OtherID'])) { - Session::set('currentMember', $params['OtherID']); - } - if(Director::is_ajax()) { - SSViewer::setOption('rewriteHashlinks', false); - return $editForm->formHtmlContent(); - } else { - return array(); - } - } - - public function getEditForm( $id ) { - return $this->getNewsletterTypeEditForm( $id ); - } - - /** - * Get the EditForm - */ - public function EditForm() { - if((isset($_REQUEST['ID']) && isset($_REQUEST['Type']) && $_REQUEST['Type'] == 'Newsletter') || isset($_REQUEST['action_savenewsletter'])) { - return $this->NewsletterEditForm(); - } else { - // If a mailing list member is being added to a group, then call the Recipient form - if (isset($_REQUEST['fieldName']) && 'Recipients' == $_REQUEST['fieldName']) { - return $this->MailingListEditForm(); - } else { - return $this->TypeEditForm(); - } - } - } - - public function NewsletterEditForm() { - $id = $_REQUEST['ID'] ? $_REQUEST['ID'] : $this->currentPageID(); - if(!is_numeric($id)) { - $id = 0; - } - return $this->getNewsletterEditForm($id); - } - - public function TypeEditForm() { - $id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : $this->currentPageID(); - if(!is_numeric($id)) { - $id = 0; - } - return $this->getNewsletterTypeEditForm($id); - } - public function MailingListEditForm() { - $id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : $this->currentPageID(); - return $this->getMailingListEditForm($id); - } - - public function getNewsletterTypeEditForm($id) { - if(!is_numeric($id)) { - $id = Session::get('currentPage'); - } - if( is_a( $id, 'NewsletterType' ) ) { - $mailType = $id; - $id = $mailType->ID; - } else { - if($id && is_numeric($id)) { - $mailType = DataObject::get_by_id( 'NewsletterType', $id ); - } - } - - if(isset($mailType) && is_object($mailType) && $mailType->GroupID) { - $group = DataObject::get_one("Group", "ID = $mailType->GroupID"); - } - if(isset($mailType)&&$mailType) { - $fields = new FieldSet( - new TabSet("Root", - new Tab(_t('NewsletterAdmin.NLSETTINGS', 'Newsletter Settings'), - new TextField("Title", _t('NewsletterAdmin.NEWSLTYPE','Newsletter Type')), - new TextField("FromEmail", _t('NewsletterAdmin.FROMEM','From email address')), - $templates = new TemplateList("Template", _t('NewsletterAdmin.TEMPLATE', 'Template'), $mailType->Template, self::template_path()) - ) - ) - ); - - $templates->setController($this); - - $fields->push($idField = new HiddenField("ID")); - $fields->push( new HiddenField( "executeForm", "", "TypeEditForm" ) ); - $idField->setValue($id); - - $actions = new FieldSet(new FormAction('save', _t('NewsletterAdmin.SAVE', 'Save'))); - - $form = new Form($this, "EditForm", $fields, $actions); - $form->loadDataFrom(array( - 'Title' => $mailType->Title, - 'FromEmail' => $mailType->FromEmail - )); - } else { - $form = false; - } - - return $form; - } - - public function getMailingListEditForm($id) { - if(!is_numeric($id)) { - $id = Session::get('currentPage'); - } - if( is_a( $id, 'NewsletterType' ) ) { - $mailType = $id; - $id = $mailType->ID; - } else { - if($id && is_numeric($id)) { - $mailType = DataObject::get_by_id( 'NewsletterType', $id ); - } - } - - if(isset($mailType) && is_object($mailType) && $mailType->GroupID) { - $group = DataObject::get_one("Group", "ID = $mailType->GroupID"); - } - - if(isset($mailType) && is_object($mailType)) { - $fields = new FieldSet( - new TabSet("Root", - new Tab(_t('NewsletterAdmin.RECIPIENTS', 'Recipients'), - $recipients = new MemberTableField( - $this, - "Recipients", - $group - ) - ), - new Tab(_t('NewsletterAdmin.IMPORT', 'Import'), - $importField = new RecipientImportField("ImportFile",_t('NewsletterAdmin.IMPORTFROM', 'Import from file'), $group ) - ), - new Tab(_t('NewsletterAdmin.UNSUBSCRIBERS', 'Unsubscribers'), - $unsubscribedList = new UnsubscribedList("Unsubscribed", $mailType) - ), - new Tab(_t('NewsletterAdmin.BOUNCED','Bounced'), $bouncedList = new BouncedList("Bounced", $mailType ) - ) - ) - ); - - $recipients->setController($this); - $importField->setController($this); - $unsubscribedList->setController($this); - $bouncedList->setController($this); - - $importField->setTypeID( $id ); - - $fields->push($idField = new HiddenField("ID")); - $fields->push( new HiddenField( "executeForm", "", "MailingListEditForm" ) ); - $idField->setValue($id); - // Save button is not used in Mailing List section - $actions = new FieldSet(new HiddenField("save")); - - $form = new Form($this, "EditForm", $fields, $actions); - $form->loadDataFrom(array( - 'Title' => $mailType->Title, - 'FromEmail' => $mailType->FromEmail - )); - } else { - $form = false; - } - - return $form; - - } - - /** - * Removes a bounced member from the mailing list - * - * @return String - */ - function removebouncedmember($urlParams) { - // First remove the Bounce entry - $id = Convert::raw2sql($urlParams['ID']); - if (is_numeric($id)) { - $bounceObject = DataObject::get_by_id('Email_BounceRecord', $id); - if($bounceObject) { - // Remove this bounce record - $bounceObject->delete(); - - $memberObject = DataObject::get_by_id('Member', $bounceObject->MemberID); - $groupID = Convert::raw2sql($_REQUEST['GroupID']); - if(is_numeric($groupID) && is_object($memberObject)) { - // Remove the member from the mailing list - $memberObject->Groups()->remove($groupID); - } else { - user_error("NewsletterAdmin::removebouncedmember: Bad parameters: Group=$groupID, Member=".$bounceObject->MemberID, E_USER_ERROR); - } - FormResponse::status_message($memberObject->Email.' '._t('NewsletterAdmin.REMOVEDSUCCESS', 'was removed from the mailing list'), 'good'); - FormResponse::add("$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value, 'recipients');"); - return FormResponse::respond(); - } - } else { - user_error("NewsletterAdmin::removebouncedmember: Bad parameters: Group=$groupID, Member=".$bounceObject->MemberID, E_USER_ERROR); - } - } - - /** - * Reloads the "Sent Status Report" tab via ajax - */ - function getsentstatusreport($params) { - if(Director::is_ajax()) { - $newsletter = DataObject::get_by_id( 'Newsletter', $params['ID'] ); - $sent_status_report = $newsletter->renderWith("Newsletter_SentStatusReport"); - return $sent_status_report; - } - } - - public static function template_path() { - if(self::$template_path) return self::$template_path; - else return self::$template_path = project() . '/templates/email'; - } - - /* Does not seem to be used - public function showdraft( $params ) { - return $this->showWithEditForm( $params, $this->getNewsletterEditForm( $params['ID'] ) ); - } - */ - - public function getNewsletterEditForm($myId){ - - $email = DataObject::get_by_id("Newsletter", $myId); - if($email) { - - $fields = $email->getCMSFields($this); - $fields->push($idField = new HiddenField("ID")); - $idField->setValue($myId); - $fields->push($ParentidField = new HiddenField("ParentID")); - $ParentidField->setValue($email->ParentID); - $fields->push($typeField = new HiddenField("Type")); - $typeField->setValue('Newsletter'); - //$fields->push(new HiddenField("executeForm", "", "EditForm") ); - - $actions = new FieldSet(); - - if( $email->SentDate ) - $actions->push(new FormAction('send',_t('NewsletterAdmin.RESEND','Resend'))); - else - $actions->push(new FormAction('send',_t('NewsletterAdmin.SEND','Send...'))); - - $actions->push(new FormAction('save',_t('NewsletterAdmin.SAVE','Save'))); - - $form = new Form($this, "EditForm", $fields, $actions); - $form->loadDataFrom($email); - - if($email->Status != 'Draft') { - $form->makeReadonly(); - } - - // user_error( $form->FormAction(), E_USER_ERROR ); - - return $form; - } else { - user_error( 'Unknown Email ID: ' . $myId, E_USER_ERROR ); - } - } - - public function SendProgressBar() { - $progressBar = new ProgressBar( 'SendProgressBar', _t('NewsletterAdmin.SENDING','Sending emails...') ); - return $progressBar->FieldHolder(); - } - - public function sendnewsletter( /*$data, $form = null*/ ) { - - $id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : $_REQUEST['NewsletterID']; - - if( !$id ) { - FormResponse::status_message(_t('NewsletterAdmin.NONLSPECIFIED', 'No newsletter specified'),'bad'); - return FormResponse::respond(); - } - - $newsletter = DataObject::get_by_id("Newsletter", $id); - $nlType = $newsletter->getNewsletterType(); - - $e = new Newsletter_Email($nlType); - $e->Body = $body = $newsletter->Content; - $e->Subject = $subject = $newsletter->Subject; - - // TODO Make this dynamic - - if( $nlType && $nlType->FromEmail ) - $e->From = $from = $nlType->FromEmail; - else - $e->From = $from = Email::getAdminEmail(); - - if(isset($_REQUEST['TestEmail'])) $e->To = $_REQUEST['TestEmail']; - $e->setTemplate( $nlType->Template ); - - $messageID = base64_encode( $newsletter->ID . '_' . date( 'd-m-Y H:i:s' ) ); - - switch($_REQUEST['SendType']) { - case "Test": - if($_REQUEST['TestEmail']) { - $e->To = $_REQUEST['TestEmail']; - $e->setTemplate( $nlType->Template ); - - self::sendToAddress( $e, $_REQUEST['TestEmail'], $messageID ); - FormResponse::status_message(_t('NewsletterAdmin.SENTTESTTO','Sent test to ') . $_REQUEST['TestEmail'],'good'); - } else { - FormResponse::status_message(_t('NewsletterAdmin.PLEASEENTERMAIL','Please enter an email address'),'bad'); - } - break; - case "List": - // Send to the entire mailing list. - $groupID = $nlType->GroupID; - echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID, - DataObject::get( 'Member', "`GroupID`='$groupID'", null, "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`" ) - ); - break; - case "Unsent": - // Send to only those who have not already been sent this newsletter. - $only_to_unsent = 1; - echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID, $newsletter->UnsentSubscribers()); - break; - } - - return FormResponse::respond(); - } - - - static function sendToAddress( $email, $address, $messageID = null ) { - $email->To = $address; - $email->send(); - } - - static function sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID = null, $recipients) { - $emailProcess = new NewsletterEmailProcess( $subject, $body, $from, $newsletter, $nlType, $messageID, $recipients); - return $emailProcess->start(); - } - - public function save($urlParams, $form) { - // Both the Newsletter type and the Newsletter draft call save() when "Save" button is clicked - if( isset($_REQUEST['Type']) && $_REQUEST['Type'] == 'Newsletter' ) - return $this->savenewsletter( $urlParams, $form ); - - $id = $_REQUEST['ID']; - $className = 'NewsletterType'; - $record = DataObject::get_one($className, "`$className`.ID = $id"); - - // Is the template attached to the type, or the newsletter itself? - - $record->Template = addslashes( $_REQUEST['Template'] ); - - $form->saveInto($record); - $record->write(); - - FormResponse::set_node_title("mailtype_$id", $record->Title); - FormResponse::status_message(_t('NewsletterAdmin.SAVED','Saved'), 'good'); - $result = $this->getActionUpdateJS($record); - return FormResponse::respond(); - } - - public function savenewsletter($urlParams, $form) { - $id = $_REQUEST['ID']; - - $className = 'Newsletter'; - $record = DataObject::get_one($className, "`$className`.ID = $id"); - - // Is the template attached to the type, or the newsletter itself? - $type = $record->getNewsletterType(); - - $record->Subject = $urlParams['Subject']; - $record->Content = $urlParams['Content']; - - $record->write(); - - $id = 'draft_'.$record->ParentID.'_'.$record->ID; - - FormResponse::set_node_title($id, $record->Title); - FormResponse::status_message('Saved', 'good'); - // Get the new action buttons - $actionList = ''; - foreach($form->Actions() as $action) { - $actionList .= $action->Field() . ' '; - } - FormResponse::add("$('Form_EditForm').loadActionsFromString('" . Convert::raw2js($actionList) . "');"); - return FormResponse::respond(); - } - - /* - * Saves the settings on the 'Bounced' tab of the 'Mailing List' allowing members to be added to Email_BlackList - * - */ - public function memberblacklisttoggle($urlParams) { - $id = $urlParams['ID']; - $bounceObject = DataObject::get_by_id('Email_BounceRecord', $id); - $memberObject = DataObject::get_by_id('Member', $bounceObject->MemberID); - // If the email is currently not blocked, block it - if (FALSE == $memberObject->BlacklistedEmail) { - $memberObject->setBlacklistedEmail(TRUE); - FormResponse::status_message($memberObject->Email.' '._t('NewsletterAdmin.ADDEDTOBL', 'was added to blacklist'), 'good'); - } else { - // Unblock the email - $memberObject->setBlacklistedEmail(FALSE); - FormResponse::status_message($memberObject->Email.' '._t('NewsletterAdmin.REMOVEDFROMBL','was removed from blacklist'), 'good'); - } - return FormResponse::respond(); - } - - function NewsletterAdminSiteTree() { - return $this->getsitetree(); - } - - function getsitetree() { - return $this->renderWith('NewsletterAdmin_SiteTree'); - } - - public function AddRecordForm() { - $m = new MemberTableField($this,"Members", $this->currentPageID()); - return $m->AddRecordForm(); - } - - /** - * Ajax autocompletion - */ - public function autocomplete() { - $fieldName = $this->urlParams['ID']; - $fieldVal = $_REQUEST[$fieldName]; - - $matches = DataObject::get("Member","$fieldName LIKE '" . addslashes($fieldVal) . "%'"); - if($matches) { - echo "Choose a member from above.
"; - } - }, - select_success : function(response) { - Element.removeClassName(this, 'loading'); - $('Form_MemberForm').loadNewPage(response.responseText); - - statusMessage('loaded','good'); - // for (var n in tinyMCE.instances) tinyMCE.removeMCEControl(n); - } - }, - - '#MemberList thead tr' : { - onmouseover : null, - onmouseout : null, - onclick : null - }, - - '#MemberList' : { - initialise : function() { - this.headerMap = []; - - var i, item, headers = this.getElementsByTagName('thead')[0].getElementsByTagName('tr')[0].getElementsByTagName('td'); - for(i=0;item=headers[i];i++) { - this.headerMap[i] = item.className; - } - }, - - setRecordDetails : function(id, details, groupID) { - var row = document.getElementById('member-' + id); - if(row) { - var i, item, cells = row.getElementsByTagName('td'); - for(i=0;item=cells[i];i++) { - if(details[this.headerMap[i]]) { - item.innerHTML = details[this.headerMap[i]]; - } - } - } else { - this.createRecord(id, details, groupID); - } - }, - - createRecord : function (id, details, groupId) { - var row = document.createElement('tr'); - row.id = 'member-' + id; - var i, cell, cellField; - for(i=0;cellField=this.headerMap[i];i++) { - cell = document.createElement('td') - if(details[cellField]) { - cell.innerHTML = details[cellField]; - } - row.appendChild(cell); - } - - // Add the delete icon - if(typeof groupId == 'undefined') - var groupId = $('Form_EditForm').elements.ID.value; - cell = document.createElement('td') - cell.innerHTML = ''; - cell.getElementsByTagName('0'); - row.appendChild(cell); - - var tbody = this.getElementsByTagName('tbody')[0]; - var addRow = document.getElementsByClassName('addrow',tbody)[0]; - if(addRow) tbody.insertBefore(row, addRow); - else tbody.appendChild(row); - Behaviour.apply(row, true); - }, - - clearAddForm : function() { - var tbody = this.getElementsByTagName('tbody')[0]; - var addRow = document.getElementsByClassName('addrow',tbody)[0]; - if(addRow) { - var i,field,fields = addRow.getElementsByTagName('input'); - for(i=0;field=fields[i];i++) { - if(field.type != 'hidden' && field.type != 'submit') field.value = ''; - } - } - }, - - removeMember : function(memberID) { - var record; - if(record = $('member-' + memberID)) { - record.parentNode.removeChild(record); - } - } - }, - - '#MemberList input' : AjaxMemberLookup, - - '#MemberList a.deletelink' : { - onclick : function(event) { - if(confirm("Do you want to remove this member from the group?")) { - this.getElementsByTagName('img')[0].src = 'cms/images/network-save.gif'; - ajaxLink(this.href); - } - Event.stop(event); - return false; - } - }, - - '#MemberList tr.addrow' : { - onmouseover : null, - onmouseout : null, - onclick : null - }, - - '#MemberList tr.addrow td.actions input' : { - onclick : function(event) { - data = this.parentNode.parentNode.getElementsByTagName('input'); - var i,item,error = []; - for(i=0;item=data[i];i++) { - if(item.name == 'Email' && !item.value) error[error.length] = "Email"; - if(item.name == 'Password' && !item.value) error[error.length] = "Password"; - } - if(error.length > 0) { - alert('Please enter a ' + error.join(' and a ') + ' to add a member.'); - - } else { - ajaxSubmitFieldSet('admin/newsletter/addmember', data); - } - - return false; - } - } -}); diff --git a/javascript/Newsletter_UploadForm.js b/javascript/Newsletter_UploadForm.js deleted file mode 100755 index 6d85f4ef..00000000 --- a/javascript/Newsletter_UploadForm.js +++ /dev/null @@ -1,13 +0,0 @@ -Behaviour.register({ - 'body' : { - onload: function() { - top.getElementById('ImportFile').frameLoaded( document ); - } - }, - - 'form input[type=file]' : { - onchange: function() { - this.form.submit(); - } - } -}); \ No newline at end of file diff --git a/templates/Includes/NewsletterAdmin_BouncedList.ss b/templates/Includes/NewsletterAdmin_BouncedList.ss deleted file mode 100755 index 83ca53e7..00000000 --- a/templates/Includes/NewsletterAdmin_BouncedList.ss +++ /dev/null @@ -1,39 +0,0 @@ -<% if Entries %> -<% _t('INSTRUCTIONS', 'Instructions:') %>
-<% _t('NOBOUNCED','No emails sent have bounced.') %>
-<% end_if %> diff --git a/templates/Includes/NewsletterAdmin_SiteTree.ss b/templates/Includes/NewsletterAdmin_SiteTree.ss deleted file mode 100755 index ef0bfdbc..00000000 --- a/templates/Includes/NewsletterAdmin_SiteTree.ss +++ /dev/null @@ -1,33 +0,0 @@ -<% if NewsletterTypes %> -<% _t('UNAME','User name') %> | -<% _t('UNSUBON','Unsubscribed on') %> | -
$Member.FirstName $Member.Surname | -$Record.Created.Long | -
- <% _t('NOUNSUB','No users have unsubscribed from this newsletter.') %> - -
-<% end_if %> diff --git a/templates/Includes/NewsletterAdmin_left.ss b/templates/Includes/NewsletterAdmin_left.ss deleted file mode 100755 index 426057b5..00000000 --- a/templates/Includes/NewsletterAdmin_left.ss +++ /dev/null @@ -1,48 +0,0 @@ - - -<% _t('CHOOSEDRAFT1','Please choose a draft on the left, or') %> <% _t('CHOOSEDRAFT2','add one') %>.
-<% end_if %> -<% if Status = Sent %> -<% _t('CHOOSESENT','Please choose a sent item on the left.') %>
-<% end_if %> diff --git a/templates/Newsletter_RecipientImportField.ss b/templates/Newsletter_RecipientImportField.ss deleted file mode 100755 index d31248a8..00000000 --- a/templates/Newsletter_RecipientImportField.ss +++ /dev/null @@ -1,51 +0,0 @@ - - - - <% base_tag %> - $MetaTags - - - - - - -<% if ImportMessage %> - -<% end_if %> - - -<% if ImportMessage %> -- $ImportMessage -
Note:<% _t('MLRELOAD1', 'To see the new members on the Recipients tab, you need to') %> <% _t('MLRELOAD2', 'reload the Mailing List') %>.
-<% _t('EMAIL','Email') %> | -<% _t('DATE','Date') %> | -<% _t('RES','Result') %> | -
---|---|---|
$LastEdited | -$Result | -
<% _t('EMAIL') %> | -<% _t('DATE') %> | -<% _t('RES') %> | -
---|---|---|
$LastEdited | -$Result | -
<% _t('EMAIL') %> | -<% _t('DATE') %> | -<% _t('RES') %> | -
---|---|---|
$LastEdited | -$Result | -
<% _t('EMAIL') %> | -<% _t('FN','Firstname') %> | -<% _t('SN','Surname') %> | -
---|---|---|
$FirstName | -$Surname | -
<% _t('EMAIL') %> | -<% _t('DATE') %> | -<% _t('RES') %> | -
---|---|---|
$LastEdited | -$Result | -
Dear $FirstName,
-Thanks for signing up to our mailing list. The following data was submitted:
- -First name: $FirstName
-Email: $Email
-Password: $Password (we've generated this password for you)
- - <% if Newsletters %> -You're subscribed to the following mailing lists:
-