1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter extends Mage_Adminhtml_Block_Widget_Form
35: {
36:
37: public function __construct()
38: {
39: parent::__construct();
40: $this->setTemplate('customer/tab/newsletter.phtml');
41: }
42:
43: public function initForm()
44: {
45: $form = new Varien_Data_Form();
46: $form->setHtmlIdPrefix('_newsletter');
47: $customer = Mage::registry('current_customer');
48: $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer);
49: Mage::register('subscriber', $subscriber);
50:
51: if ($customer->getWebsiteId() == 0) {
52: $this->setForm($form);
53: return $this;
54: }
55:
56: $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('customer')->__('Newsletter Information')));
57:
58: $fieldset->addField('subscription', 'checkbox',
59: array(
60: 'label' => Mage::helper('customer')->__('Subscribed to Newsletter?'),
61: 'name' => 'subscription'
62: )
63: );
64:
65: if ($customer->isReadonly()) {
66: $form->getElement('subscription')->setReadonly(true, true);
67: }
68:
69: $form->getElement('subscription')->setIsChecked($subscriber->isSubscribed());
70:
71: if($changedDate = $this->getStatusChangedDate()) {
72: $fieldset->addField('change_status_date', 'label',
73: array(
74: 'label' => $subscriber->isSubscribed() ? Mage::helper('customer')->__('Last Date Subscribed') : Mage::helper('customer')->__('Last Date Unsubscribed'),
75: 'value' => $changedDate,
76: 'bold' => true
77: )
78: );
79: }
80:
81: $this->setForm($form);
82: return $this;
83: }
84:
85: public function getStatusChangedDate()
86: {
87: $subscriber = Mage::registry('subscriber');
88: if($subscriber->getChangeStatusAt()) {
89: return $this->formatDate(
90: $subscriber->getChangeStatusAt(),
91: Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true
92: );
93: }
94:
95: return null;
96: }
97:
98: protected function _prepareLayout()
99: {
100: $this->setChild('grid',
101: $this->getLayout()->createBlock('adminhtml/customer_edit_tab_newsletter_grid','newsletter.grid')
102: );
103: return parent::_prepareLayout();
104: }
105:
106: }
107: