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_Account extends Mage_Adminhtml_Block_Widget_Form
35: {
36: 37: 38:
39: public function __construct()
40: {
41: parent::__construct();
42: }
43:
44: 45: 46: 47: 48:
49: public function initForm()
50: {
51: $form = new Varien_Data_Form();
52: $form->setHtmlIdPrefix('_account');
53: $form->setFieldNameSuffix('account');
54:
55: $customer = Mage::registry('current_customer');
56:
57:
58: $customerForm = Mage::getModel('customer/form');
59: $customerForm->setEntity($customer)
60: ->setFormCode('adminhtml_customer')
61: ->initDefaultValues();
62:
63: $fieldset = $form->addFieldset('base_fieldset', array(
64: 'legend' => Mage::helper('customer')->__('Account Information')
65: ));
66:
67: $attributes = $customerForm->getAttributes();
68: foreach ($attributes as $attribute) {
69:
70: $attribute->setFrontendLabel(Mage::helper('customer')->__($attribute->getFrontend()->getLabel()));
71: $attribute->unsIsVisible();
72: }
73:
74: $disableAutoGroupChangeAttributeName = 'disable_auto_group_change';
75: $this->_setFieldset($attributes, $fieldset, array($disableAutoGroupChangeAttributeName));
76:
77: $form->getElement('group_id')->setRenderer($this->getLayout()
78: ->createBlock('adminhtml/customer_edit_renderer_attribute_group')
79: ->setDisableAutoGroupChangeAttribute($customerForm->getAttribute($disableAutoGroupChangeAttributeName))
80: ->setDisableAutoGroupChangeAttributeValue($customer->getData($disableAutoGroupChangeAttributeName)));
81:
82: if ($customer->getId()) {
83: $form->getElement('website_id')->setDisabled('disabled');
84: $form->getElement('created_in')->setDisabled('disabled');
85: } else {
86: $fieldset->removeField('created_in');
87: $form->getElement('website_id')->addClass('validate-website-has-store');
88:
89: $websites = array();
90: foreach (Mage::app()->getWebsites(true) as $website) {
91: $websites[$website->getId()] = !is_null($website->getDefaultStore());
92: }
93: $prefix = $form->getHtmlIdPrefix();
94:
95: $form->getElement('website_id')->setAfterElementHtml(
96: '<script type="text/javascript">'
97: . "
98: var {$prefix}_websites = " . Mage::helper('core')->jsonEncode($websites) .";
99: Validation.add(
100: 'validate-website-has-store',
101: '" . Mage::helper('customer')->__('Please select a website which contains store view') . "',
102: function(v, elem){
103: return {$prefix}_websites[elem.value] == true;
104: }
105: );
106: Element.observe('{$prefix}website_id', 'change', function(){
107: Validation.validate($('{$prefix}website_id'))
108: }.bind($('{$prefix}website_id')));
109: "
110: . '</script>'
111: );
112: }
113: $renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
114: $form->getElement('website_id')->setRenderer($renderer);
115:
116:
117:
118:
119:
120:
121:
122:
123:
124: $customerStoreId = null;
125: if ($customer->getId()) {
126: $customerStoreId = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
127: }
128:
129: $prefixElement = $form->getElement('prefix');
130: if ($prefixElement) {
131: $prefixOptions = $this->helper('customer')->getNamePrefixOptions($customerStoreId);
132: if (!empty($prefixOptions)) {
133: $fieldset->removeField($prefixElement->getId());
134: $prefixField = $fieldset->addField($prefixElement->getId(),
135: 'select',
136: $prefixElement->getData(),
137: $form->getElement('group_id')->getId()
138: );
139: $prefixField->setValues($prefixOptions);
140: if ($customer->getId()) {
141: $prefixField->addElementValues($customer->getPrefix());
142: }
143:
144: }
145: }
146:
147: $suffixElement = $form->getElement('suffix');
148: if ($suffixElement) {
149: $suffixOptions = $this->helper('customer')->getNameSuffixOptions($customerStoreId);
150: if (!empty($suffixOptions)) {
151: $fieldset->removeField($suffixElement->getId());
152: $suffixField = $fieldset->addField($suffixElement->getId(),
153: 'select',
154: $suffixElement->getData(),
155: $form->getElement('lastname')->getId()
156: );
157: $suffixField->setValues($suffixOptions);
158: if ($customer->getId()) {
159: $suffixField->addElementValues($customer->getSuffix());
160: }
161: }
162: }
163:
164: if ($customer->getId()) {
165: if (!$customer->isReadonly()) {
166:
167: $newFieldset = $form->addFieldset(
168: 'password_fieldset',
169: array('legend' => Mage::helper('customer')->__('Password Management'))
170: );
171:
172: $field = $newFieldset->addField('new_password', 'text',
173: array(
174: 'label' => Mage::helper('customer')->__('New Password'),
175: 'name' => 'new_password',
176: 'class' => 'validate-new-password'
177: )
178: );
179: $field->setRenderer($this->getLayout()->createBlock('adminhtml/customer_edit_renderer_newpass'));
180:
181:
182: $confirmationKey = $customer->getConfirmation();
183: if ($confirmationKey || $customer->isConfirmationRequired()) {
184: $confirmationAttribute = $customer->getAttribute('confirmation');
185: if (!$confirmationKey) {
186: $confirmationKey = $customer->getRandomConfirmationKey();
187: }
188: $element = $fieldset->addField('confirmation', 'select', array(
189: 'name' => 'confirmation',
190: 'label' => Mage::helper('customer')->__($confirmationAttribute->getFrontendLabel()),
191: ))->setEntityAttribute($confirmationAttribute)
192: ->setValues(array('' => 'Confirmed', $confirmationKey => 'Not confirmed'));
193:
194:
195:
196: if ($customer->getConfirmation() && $customer->getWebsiteId()) {
197: $fieldset->addField('sendemail', 'checkbox', array(
198: 'name' => 'sendemail',
199: 'label' => Mage::helper('customer')->__('Send Welcome Email after Confirmation')
200: ));
201: $customer->setData('sendemail', '1');
202: }
203: }
204: }
205: } else {
206: $newFieldset = $form->addFieldset(
207: 'password_fieldset',
208: array('legend'=>Mage::helper('customer')->__('Password Management'))
209: );
210: $field = $newFieldset->addField('password', 'text',
211: array(
212: 'label' => Mage::helper('customer')->__('Password'),
213: 'class' => 'input-text required-entry validate-password',
214: 'name' => 'password',
215: 'required' => true
216: )
217: );
218: $field->setRenderer($this->getLayout()->createBlock('adminhtml/customer_edit_renderer_newpass'));
219:
220:
221: $fieldset->addField('sendemail', 'checkbox', array(
222: 'label' => Mage::helper('customer')->__('Send Welcome Email'),
223: 'name' => 'sendemail',
224: 'id' => 'sendemail',
225: ));
226: $customer->setData('sendemail', '1');
227: if (!Mage::app()->isSingleStoreMode()) {
228: $fieldset->addField('sendemail_store_id', 'select', array(
229: 'label' => $this->helper('customer')->__('Send From'),
230: 'name' => 'sendemail_store_id',
231: 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm()
232: ));
233: }
234: }
235:
236:
237: $isSingleMode = Mage::app()->isSingleStoreMode();
238: $sendEmailId = $isSingleMode ? 'sendemail' : 'sendemail_store_id';
239: $sendEmail = $form->getElement($sendEmailId);
240:
241: $prefix = $form->getHtmlIdPrefix();
242: if ($sendEmail) {
243: $_disableStoreField = '';
244: if (!$isSingleMode) {
245: $_disableStoreField = "$('{$prefix}sendemail_store_id').disabled=(''==this.value || '0'==this.value);";
246: }
247: $sendEmail->setAfterElementHtml(
248: '<script type="text/javascript">'
249: . "
250: $('{$prefix}website_id').disableSendemail = function() {
251: $('{$prefix}sendemail').disabled = ('' == this.value || '0' == this.value);".
252: $_disableStoreField
253: ."}.bind($('{$prefix}website_id'));
254: Event.observe('{$prefix}website_id', 'change', $('{$prefix}website_id').disableSendemail);
255: $('{$prefix}website_id').disableSendemail();
256: "
257: . '</script>'
258: );
259: }
260:
261: if ($customer->isReadonly()) {
262: foreach ($customer->getAttributes() as $attribute) {
263: $element = $form->getElement($attribute->getAttributeCode());
264: if ($element) {
265: $element->setReadonly(true, true);
266: }
267: }
268: }
269:
270: $form->setValues($customer->getData());
271: $this->setForm($form);
272: return $this;
273: }
274:
275: 276: 277: 278: 279:
280: protected function _getAdditionalElementTypes()
281: {
282: return array(
283: 'file' => Mage::getConfig()->getBlockClassName('adminhtml/customer_form_element_file'),
284: 'image' => Mage::getConfig()->getBlockClassName('adminhtml/customer_form_element_image'),
285: 'boolean' => Mage::getConfig()->getBlockClassName('adminhtml/customer_form_element_boolean'),
286: );
287: }
288: }
289: