2007-07-19 12:40:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class NewsletterAdmin extends LeftAndMain {
|
|
|
|
static $subitem_class = "Member";
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
static $template_path = null; // defaults to (project)/templates/email
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function init() {
|
|
|
|
// Check permissions
|
|
|
|
// if(!Member::currentUser() || !Member::currentUser()->isAdmin()) Security::permissionFailure($this);
|
|
|
|
|
|
|
|
parent::init();
|
|
|
|
/*
|
|
|
|
if(!$this->can('AdminCMS')) {
|
|
|
|
$messageSet = array(
|
2007-09-14 21:26:56 +02:00
|
|
|
'default' => "Please choose an authentication method and enter your credentials to access the CMS.",
|
2007-07-19 12:40:05 +02:00
|
|
|
'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");
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
Requirements::javascript("cms/javascript/SecurityAdmin.js");
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
Requirements::javascript("cms/javascript/LeftAndMain_left.js");
|
|
|
|
Requirements::javascript("cms/javascript/LeftAndMain_right.js");
|
|
|
|
Requirements::javascript("cms/javascript/CMSMain_left.js");
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
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(),
|
|
|
|
));
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
// needed for MemberTableField (Requirements not determined before Ajax-Call)
|
|
|
|
Requirements::javascript("jsparty/greybox/AmiJS.js");
|
|
|
|
Requirements::javascript("jsparty/greybox/greybox.js");
|
|
|
|
Requirements::javascript("sapphire/javascript/TableListField.js");
|
|
|
|
Requirements::javascript("sapphire/javascript/TableField.js");
|
|
|
|
Requirements::javascript("sapphire/javascript/ComplexTableField.js");
|
|
|
|
Requirements::javascript("cms/javascript/MemberTableField.js");
|
|
|
|
Requirements::css("jsparty/greybox/greybox.css");
|
|
|
|
Requirements::css("sapphire/css/ComplexTableField.css");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function remove() {
|
|
|
|
$ids = explode( ',', $_REQUEST['csvIDs'] );
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-15 02:51:37 +02:00
|
|
|
$count = 0;
|
2007-07-19 12:40:05 +02:00
|
|
|
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] );
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if($record) {
|
|
|
|
$record->delete();
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
FormResponse::add("removeTreeNodeByIdx(\$('sitetree'), '$id' );");
|
2007-09-15 02:51:37 +02:00
|
|
|
$count++;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-15 02:51:37 +02:00
|
|
|
FormResponse::status_message('Deleted '.$count.' items','good');
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return FormResponse::respond();
|
2007-09-14 21:26:56 +02:00
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2007-09-14 19:29:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
public function shownewsletter($params) {
|
2007-09-14 21:26:56 +02:00
|
|
|
return $this->showWithEditForm( $params, $this->getNewsletterEditForm( $params['ID'] ) );
|
2007-09-14 19:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a newsletter type is clicked on the left menu
|
|
|
|
*/
|
|
|
|
public function showmailtype($params) {
|
2007-09-14 21:26:56 +02:00
|
|
|
return $this->showWithEditForm( $params, $this->getNewsletterTypeEditForm( $params['ID'] ) );
|
2007-09-14 19:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2007-09-14 21:26:56 +02:00
|
|
|
return $this->ShowNewsletterFolder($params, 'Sent');
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
2007-09-14 21:26:56 +02:00
|
|
|
return $draftList->renderWith("NewsletterList");
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 19:29:08 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function removenewsletter($params) {
|
|
|
|
if( !is_numeric( $params['ID'] ) )
|
|
|
|
return '';
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$newsletter = DataObject::get_by_id( 'Newsletter', $params['ID'] );
|
|
|
|
$newsletter->delete();
|
2007-09-14 21:26:56 +02:00
|
|
|
return 'letter-' . $params['ID'];
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function getEditForm( $id ) {
|
|
|
|
return $this->getNewsletterTypeEditForm( $id );
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
/**
|
|
|
|
* Get the EditForm
|
|
|
|
*/
|
|
|
|
public function EditForm() {
|
2007-08-28 03:55:45 +02:00
|
|
|
if((isset($_REQUEST['ID']) && isset($_REQUEST['Type']) && $_REQUEST['Type'] == 'Newsletter') || isset($_REQUEST['action_savenewsletter'])) {
|
2007-07-19 12:40:05 +02:00
|
|
|
return $this->NewsletterEditForm();
|
|
|
|
} else {
|
2007-09-14 19:29:08 +02:00
|
|
|
// 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();
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function NewsletterEditForm() {
|
|
|
|
$id = $_REQUEST['ID'] ? $_REQUEST['ID'] : $this->currentPageID();
|
|
|
|
if(!is_numeric($id)) {
|
|
|
|
$id = 0;
|
|
|
|
}
|
|
|
|
return $this->getNewsletterEditForm($id);
|
2007-09-14 21:26:56 +02:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function TypeEditForm() {
|
|
|
|
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : $this->currentPageID();
|
|
|
|
if(!is_numeric($id)) {
|
|
|
|
$id = 0;
|
|
|
|
}
|
|
|
|
return $this->getNewsletterTypeEditForm($id);
|
|
|
|
}
|
2007-09-14 19:29:08 +02:00
|
|
|
public function MailingListEditForm() {
|
|
|
|
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : $this->currentPageID();
|
|
|
|
return $this->getMailingListEditForm($id);
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
if(isset($mailType) && is_object($mailType) && $mailType->GroupID) {
|
|
|
|
$group = DataObject::get_one("Group", "ID = $mailType->GroupID");
|
2007-09-14 21:26:56 +02:00
|
|
|
}
|
2007-08-28 03:55:45 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
if(isset($mailType)) {
|
|
|
|
$fields = new FieldSet(
|
2007-09-15 23:13:53 +02:00
|
|
|
new TabSet("Root",
|
|
|
|
new Tab("Newsletter Settings",
|
|
|
|
new TextField("Title", "Newsletter Type"),
|
|
|
|
new TextField("FromEmail", "From email address"),
|
|
|
|
$templates = new TemplateList("Template","Template", $mailType->Template, self::template_path())
|
|
|
|
)
|
|
|
|
)
|
2007-09-14 19:29:08 +02:00
|
|
|
);
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
$templates->setController($this);
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
$fields->push($idField = new HiddenField("ID"));
|
|
|
|
$fields->push( new HiddenField( "executeForm", "", "TypeEditForm" ) );
|
|
|
|
$idField->setValue($id);
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$actions = new FieldSet(new FormAction('save','Save'));
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$form = new Form($this, "EditForm", $fields, $actions);
|
|
|
|
$form->loadDataFrom(array(
|
|
|
|
'Title' => $mailType->Title,
|
|
|
|
'FromEmail' => $mailType->FromEmail
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
$form = false;
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
if(isset($mailType) && is_object($mailType) && $mailType->GroupID) {
|
|
|
|
$group = DataObject::get_one("Group", "ID = $mailType->GroupID");
|
2007-09-14 21:26:56 +02:00
|
|
|
}
|
2007-09-14 19:29:08 +02:00
|
|
|
|
|
|
|
if(isset($mailType) && is_object($mailType)) {
|
|
|
|
$fields = new FieldSet(
|
|
|
|
new TabSet("Root",
|
|
|
|
new Tab( "Recipients",
|
|
|
|
$recipients = new MemberTableField(
|
|
|
|
$this,
|
2007-09-14 21:26:56 +02:00
|
|
|
"Recipients",
|
2007-09-14 19:29:08 +02:00
|
|
|
$group
|
|
|
|
)
|
|
|
|
),
|
|
|
|
new Tab( "Import",
|
|
|
|
$importField = new RecipientImportField("ImportFile","Import from file", $group )
|
|
|
|
),
|
|
|
|
new Tab("Unsubscribers",
|
2007-09-14 21:26:56 +02:00
|
|
|
$unsubscribedList = new UnsubscribedList("Unsubscribed", $mailType)
|
2007-09-14 19:29:08 +02:00
|
|
|
),
|
|
|
|
new Tab("Bounced",
|
|
|
|
$bouncedList = new BouncedList("Bounced", $mailType )
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
$recipients->setController($this);
|
|
|
|
$importField->setController($this);
|
|
|
|
$unsubscribedList->setController($this);
|
|
|
|
$bouncedList->setController($this);
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
$importField->setTypeID( $id );
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
$fields->push($idField = new HiddenField("ID"));
|
|
|
|
$fields->push( new HiddenField( "executeForm", "", "MailingListEditForm" ) );
|
|
|
|
$idField->setValue($id);
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
$actions = new FieldSet(new FormAction('save','Save'));
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-16 00:02:06 +02:00
|
|
|
$form = new Form($this, "EditForm", $fields, $actions);
|
2007-09-14 19:29:08 +02:00
|
|
|
$form->loadDataFrom(array(
|
|
|
|
'Title' => $mailType->Title,
|
|
|
|
'FromEmail' => $mailType->FromEmail
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
$form = false;
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
return $form;
|
|
|
|
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
/**
|
|
|
|
* Reloads the list of recipients via ajax
|
|
|
|
*/
|
|
|
|
function getrecipientslist() {
|
|
|
|
if( $_REQUEST['ajax'] ) {
|
|
|
|
$newsletterType = DataObject::get_by_id('NewsletterType', $this->urlParams['ID'] );
|
2007-09-16 00:02:06 +02:00
|
|
|
$fields = new FieldSet($memberList = new MemberTableField($this, "Recipients", $newsletterType->Group() ));
|
|
|
|
$memberList->setController($this);
|
|
|
|
$actions = new FieldSet(new FormAction('save','Save'));
|
|
|
|
$form = new Form($this, "EditForm", $fields, $actions);
|
2007-07-19 12:40:05 +02:00
|
|
|
return $memberList->FieldHolder();
|
2007-09-14 21:26:56 +02:00
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public static function template_path() {
|
|
|
|
if(self::$template_path) return self::$template_path;
|
|
|
|
else return self::$template_path = project() . '/templates/email';
|
|
|
|
}
|
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
/* Does not seem to be used
|
|
|
|
public function showdraft( $params ) {
|
2007-09-14 21:26:56 +02:00
|
|
|
return $this->showWithEditForm( $params, $this->getNewsletterEditForm( $params['ID'] ) );
|
2007-09-14 19:29:08 +02:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function getNewsletterEditForm($myId){
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$email = DataObject::get_by_id("Newsletter", $myId);
|
|
|
|
if($email) {
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$fields = $email->getCMSFields($this);
|
|
|
|
$fields->push($idField = new HiddenField("ID"));
|
|
|
|
$idField->setValue($myId);
|
|
|
|
$fields->push($typeField = new HiddenField("Type"));
|
|
|
|
$typeField->setValue('Newsletter');
|
|
|
|
//$fields->push(new HiddenField("executeForm", "", "EditForm") );
|
|
|
|
|
|
|
|
$actions = new FieldSet();
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if( $email->SentDate )
|
|
|
|
$actions->push(new FormAction('send','Resend'));
|
|
|
|
else
|
2007-09-14 21:28:03 +02:00
|
|
|
$actions->push(new FormAction('send','Send...'));
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$actions->push(new FormAction('save','Save'));
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-15 02:53:38 +02:00
|
|
|
$form = new Form($this, "EditForm", $fields, $actions);
|
2007-07-19 12:40:05 +02:00
|
|
|
$form->loadDataFrom($email);
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if($email->Status != 'Draft') {
|
|
|
|
$form->makeReadonly();
|
|
|
|
}
|
|
|
|
|
|
|
|
// user_error( $form->FormAction(), E_USER_ERROR );
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return $form;
|
|
|
|
} else {
|
|
|
|
user_error( 'Unknown Email ID: ' . $myId, E_USER_ERROR );
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function SendProgressBar() {
|
|
|
|
$progressBar = new ProgressBar( 'SendProgressBar', 'Sending emails...' );
|
|
|
|
return $progressBar->FieldHolder();
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function sendnewsletter( /*$data, $form = null*/ ) {
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-14 19:29:08 +02:00
|
|
|
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : $_REQUEST['NewsletterID'];
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if( !$id ) {
|
|
|
|
FormResponse::status_message('No newsletter specified','bad');
|
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$newsletter = DataObject::get_by_id("Newsletter", $id);
|
|
|
|
$nlType = $newsletter->getNewsletterType();
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$e = new Newsletter_Email($nlType);
|
|
|
|
$e->Body = $body = $newsletter->Content;
|
|
|
|
$e->Subject = $subject = $newsletter->Subject;
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
// TODO Make this dynamic
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if( $nlType && $nlType->FromEmail )
|
|
|
|
$e->From = $from = $nlType->FromEmail;
|
|
|
|
else
|
|
|
|
$e->From = $from = Email::getAdminEmail();
|
|
|
|
|
2007-08-28 03:55:45 +02:00
|
|
|
if(isset($_REQUEST['TestEmail'])) $e->To = $_REQUEST['TestEmail'];
|
2007-07-19 12:40:05 +02:00
|
|
|
$e->setTemplate( $nlType->Template );
|
|
|
|
|
|
|
|
$messageID = base64_encode( $newsletter->ID . '_' . date( 'd-m-Y H:i:s' ) );
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
switch($_REQUEST['SendType']) {
|
|
|
|
case "Test":
|
|
|
|
if($_REQUEST['TestEmail']) {
|
|
|
|
if( $nlType->Template ) {
|
|
|
|
self::sendToAddress( $e, $_REQUEST['TestEmail'], $messageID );
|
|
|
|
FormResponse::status_message('Sent test to ' . $_REQUEST['TestEmail'],'good');
|
|
|
|
} else {
|
|
|
|
FormResponse::status_message('No template selected','bad');
|
2007-09-14 21:26:56 +02:00
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
} else {
|
|
|
|
FormResponse::status_message('Please enter an email address','bad');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "List":
|
|
|
|
echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID );
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
static function sendToAddress( $email, $address, $messageID = null ) {
|
|
|
|
$email->To = $address;
|
2007-09-14 21:26:56 +02:00
|
|
|
$email->send();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
static function sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID = null ) {
|
|
|
|
$emailProcess = new NewsletterEmailProcess( $subject, $body, $from, $newsletter, $nlType, $messageID );
|
|
|
|
return $emailProcess->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save($urlParams, $form) {
|
2007-08-28 03:55:45 +02:00
|
|
|
if( isset($_REQUEST['Type']) && $_REQUEST['Type'] == 'Newsletter' )
|
2007-07-19 12:40:05 +02:00
|
|
|
return $this->savenewsletter( $urlParams, $form );
|
|
|
|
|
|
|
|
$id = $_REQUEST['ID'];
|
2007-09-14 20:12:00 +02:00
|
|
|
$className = 'NewsletterType';
|
|
|
|
$record = DataObject::get_one($className, "`$className`.ID = $id");
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
// 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('Saved', 'good');
|
2007-09-15 03:11:25 +02:00
|
|
|
$result = $this->getActionUpdateJS($record);
|
2007-07-19 12:40:05 +02:00
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function savenewsletter($urlParams, $form) {
|
|
|
|
$id = $_REQUEST['ID'];
|
2007-09-14 20:12:00 +02:00
|
|
|
|
|
|
|
$className = 'Newsletter';
|
|
|
|
$record = DataObject::get_one($className, "`$className`.ID = $id");
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
// Is the template attached to the type, or the newsletter itself?
|
|
|
|
$type = $record->getNewsletterType();
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$record->Subject = $urlParams['Subject'];
|
2007-09-14 21:26:56 +02:00
|
|
|
$record->Content = $urlParams['Content'];
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$record->write();
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$id = 'draft_'.$record->ParentID.'_'.$record->ID;
|
|
|
|
|
|
|
|
FormResponse::set_node_title($id, $record->Title);
|
|
|
|
FormResponse::status_message('Saved', 'good');
|
2007-09-15 03:11:25 +02:00
|
|
|
// Get the new action buttons
|
|
|
|
$actionList = '';
|
|
|
|
foreach($form->Actions() as $action) {
|
|
|
|
$actionList .= $action->Field() . ' ';
|
|
|
|
}
|
|
|
|
FormResponse::add("$('Form_EditForm').loadActionsFromString('" . Convert::raw2js($actionList) . "');");
|
2007-07-19 12:40:05 +02:00
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
|
|
|
|
|
|
|
function NewsletterAdminSiteTree() {
|
2007-09-14 21:26:56 +02:00
|
|
|
return $this->getsitetree();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
function getsitetree() {
|
2007-09-14 21:26:56 +02:00
|
|
|
return $this->renderWith('NewsletterAdmin_SiteTree');
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
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];
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$matches = DataObject::get("Member","$fieldName LIKE '" . addslashes($fieldVal) . "%'");
|
|
|
|
if($matches) {
|
|
|
|
echo "<ul>";
|
|
|
|
foreach($matches as $match) {
|
|
|
|
$data = $match->FirstName;
|
|
|
|
$data .= ",$match->Surname";
|
|
|
|
$data .= ",$match->Email";
|
|
|
|
$data .= ",$match->Password";
|
|
|
|
echo "<li>" . $match->$fieldName . "<span class=\"informal\">($match->FirstName $match->Surname, $match->Email)</span><span class=\"informal data\">$data</li>";
|
|
|
|
}
|
|
|
|
echo "</ul>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function savemember() {
|
|
|
|
$data = $_REQUEST;
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$className = $this->stat('subitem_class');
|
|
|
|
|
|
|
|
$id = $_REQUEST['ID'];
|
|
|
|
if($id == 'new') $id = null;
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if($id) {
|
|
|
|
$record = DataObject::get_one($className, "`$className`.ID = $id");
|
|
|
|
} else {
|
|
|
|
// send out an email to notify the user that they have been subscribed
|
|
|
|
$record = new $className();
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$record->update($data);
|
|
|
|
$record->ID = $id;
|
|
|
|
$record->write();
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$record->Groups()->add($data['GroupID']);
|
|
|
|
|
|
|
|
$FirstName = Convert::raw2js($record->FirstName);
|
|
|
|
$Surname = Convert::raw2js($record->Surname);
|
|
|
|
$Email = Convert::raw2js($record->Email);
|
|
|
|
$Password = Convert::raw2js($record->Password);
|
|
|
|
$response = <<<JS
|
|
|
|
$('MemberList').setRecordDetails($record->ID, {
|
|
|
|
FirstName : "$FirstName",
|
|
|
|
Surname : "$Surname",
|
|
|
|
Email : "$Email"
|
|
|
|
});
|
|
|
|
$('MemberList').clearAddForm();
|
|
|
|
JS;
|
|
|
|
FormResponse::add($response);
|
|
|
|
FormResponse::status_message('Saved', 'good');
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
|
|
|
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function NewsletterTypes() {
|
|
|
|
return DataObject::get("NewsletterType","");
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function addgroup() {
|
2007-09-14 21:26:56 +02:00
|
|
|
$parent = $_REQUEST['ParentID'] ? $_REQUEST['ParentID'] : 0;
|
2007-07-19 12:40:05 +02:00
|
|
|
$p = new Group();
|
|
|
|
$p->Title = "New Group";
|
|
|
|
$p->Code = "new-group";
|
|
|
|
$p->ParentID = $parent;
|
|
|
|
$p->write();
|
|
|
|
|
|
|
|
$this->returnItemToUser($p);
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
|
|
|
public function addtype( $params ) {
|
2007-07-19 12:40:05 +02:00
|
|
|
switch( $_REQUEST['PageType'] ) {
|
|
|
|
case 'type':
|
|
|
|
$form = $this->getNewsletterTypeEditForm( $this->newNewsletterType() );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$form = $this->getNewsletterEditForm( $this->newDraft( $_REQUEST['ParentID'] ) );
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
|
|
|
return $this->showWithEditForm( $_REQUEST, $form );
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function adddraft( $data, $form ) {
|
|
|
|
$this->save( $data, $form );
|
|
|
|
$draftID = $this->newDraft( $_REQUEST['ID'] );
|
2007-09-14 21:26:56 +02:00
|
|
|
return $this->getNewsletterEditForm( $draftID );
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
/**
|
|
|
|
* Create a new newsletter type
|
|
|
|
*/
|
2007-09-14 21:26:56 +02:00
|
|
|
private function newNewsletterType() {
|
2007-07-19 12:40:05 +02:00
|
|
|
// create a new group for the newsletter
|
|
|
|
$newGroup = new Group();
|
|
|
|
$newGroup->Title = "New mailing list";
|
|
|
|
$newGroup->Code = "new-mailing-list";
|
|
|
|
$newGroup->write();
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
// create the new type
|
|
|
|
$newsletterType = new NewsletterType();
|
|
|
|
$newsletterType->Title = 'New newsletter type';
|
|
|
|
$newsletterType->GroupID = $newGroup->ID;
|
|
|
|
$newsletterType->write();
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-09-15 23:14:17 +02:00
|
|
|
// BUGFIX: Return only the ID of the new newsletter type
|
|
|
|
return $newsletterType->ID;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
private function newDraft( $parentID ) {
|
|
|
|
if(!$parentID || !is_numeric( $parentID)) {
|
|
|
|
$parent = DataObject::get_one("NewsletterType");
|
|
|
|
$parentID = $parent->ID;
|
|
|
|
}
|
|
|
|
if( $parentID && is_numeric( $parentID ) ) {
|
|
|
|
$newsletter = new Newsletter();
|
|
|
|
$newsletter->Status = 'Draft';
|
|
|
|
$newsletter->Title = $newsletter->Subject = 'New draft newsletter';
|
|
|
|
$newsletter->ParentID = $parentID;
|
|
|
|
$newsletter->write();
|
|
|
|
} else {
|
2007-09-14 21:26:56 +02:00
|
|
|
user_error( "You must first create a newsletter type before creating a draft", E_USER_ERROR );
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
|
|
|
return $newsletter->ID;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function newmember() {
|
|
|
|
Session::clear('currentMember');
|
|
|
|
$newMemberForm = array(
|
|
|
|
"MemberForm" => $this->getMemberForm('new'),
|
|
|
|
);
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if(Director::is_ajax()) {
|
|
|
|
SSViewer::setOption('rewriteHashlinks', false);
|
2007-09-14 21:26:56 +02:00
|
|
|
$customised = $this->customise($newMemberForm);
|
2007-07-19 12:40:05 +02:00
|
|
|
$result = $customised->renderWith($this->class . "_rightbottom");
|
|
|
|
$parts = split('</?form[^>]*>', $result);
|
|
|
|
echo $parts[1];
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
} else {
|
|
|
|
return $newMemberForm;
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function EditedMember() {
|
|
|
|
if(Session::get('currentMember'))
|
|
|
|
return DataObject::get_by_id("Member", Session::get('currentMember'));
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function Link($action = null) {
|
|
|
|
if(!$action) $action = "index";
|
|
|
|
return "admin/newsletter/$action/" . $this->currentPageID();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function displayfilefield() {
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$id = $this->urlParams['ID'];
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return $this->customise( array( 'ID' => $id, "UploadForm" => $this->UploadForm() ) )->renderWith('Newsletter_RecipientImportField');
|
|
|
|
}
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
function UploadForm( $id = null ) {
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if( !$id )
|
|
|
|
$id = $this->urlParams['ID'];
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$fields = new FieldSet(
|
|
|
|
new FileField( "ImportFile", "" ),
|
|
|
|
//new HiddenField( "action_import", "", "1" ),
|
|
|
|
new HiddenField( "ID", "", $id )
|
|
|
|
);
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$actions = new FieldSet(
|
|
|
|
new FormAction( "action_import", "Show contents" )
|
|
|
|
);
|
2007-09-14 21:26:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return new RecipientImportField_UploadForm( $this, "UploadForm", $fields, $actions );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|