public function UpdateForm()
 {
     $member = singleton('SecurityContext')->getMember();
     if (!$member) {
         return '';
     }
     // if there's a member profile page availble, use it
     $filter = array();
     if (class_exists('Multisites')) {
         $filter = array('SiteID' => Multisites::inst()->getCurrentSiteId());
     }
     // use member profile page if possible
     if (class_exists('MemberProfilePage') && ($profilePage = MemberProfilePage::get()->filter($filter)->first())) {
         $controller = MemberProfilePage_Controller::create($profilePage);
         $form = $controller->ProfileForm();
         $form->addExtraClass('ajax-form');
         $form->loadDataFrom($member);
         return $form;
     } else {
         $password = new ConfirmedPasswordField('Password', $member->fieldLabel('Password'), null, null, (bool) $this->ID);
         $password->setCanBeEmpty(true);
         $fields = FieldList::create(TextField::create('FirstName', $member->fieldLabel('FirstName')), TextField::create('Surname', $member->fieldLabel('Surname')), EmailField::create('Email', $member->fieldLabel('Email')), $password);
         $actions = FieldList::create($update = FormAction::create('updateprofile', 'Update'));
         $form = Form::create($this, 'UpdateForm', $fields, $actions);
         $form->loadDataFrom($member);
         $this->extend('updateProfileDashletForm', $form);
         return $form;
     }
     return;
 }
コード例 #2
0
 function __construct($controller, $name)
 {
     $member = Member::currentUser();
     $requiredFields = null;
     if ($member && $member->exists()) {
         $fields = $member->getEcommerceFields();
         $passwordField = new ConfirmedPasswordField('Password', _t('MemberForm.PASSWORD', 'Password'));
         if ($member->Password != '') {
             $passwordField->setCanBeEmpty(true);
         }
         //TODO:is this necessary?
         $fields->push(new LiteralField('LogoutNote', "<p class=\"message warning\">" . _t("MemberForm.LOGGEDIN", "You are currently logged in as ") . $member->FirstName . ' ' . $member->Surname . ". " . _t('MemberForm.LOGOUT', 'Click <a href="Security/logout">here</a> to log out.') . "</p>"));
         $fields->push(new HeaderField('Login Details', _t('MemberForm.LOGINDETAILS', 'Login Details'), 3));
         $fields->push($passwordField);
         $requiredFields = new ShopAccountFormValidator($member->getEcommerceRequiredFields());
     } else {
         $fields = new FieldSet();
     }
     if (get_class($controller) == 'AccountPage_Controller') {
         $actions = new FieldSet(new FormAction('submit', _t('MemberForm.SAVE', 'Save Changes')));
     } else {
         $actions = new FieldSet(new FormAction('submit', _t('MemberForm.SAVE', 'Save Changes')), new FormAction('proceed', _t('MemberForm.SAVEANDPROCEED', 'Save and proceed to checkout')));
     }
     if ($record = $controller->data()) {
         $record->extend('updateShopAccountForm', $fields, $actions, $requiredFields);
     }
     parent::__construct($controller, $name, $fields, $actions, $requiredFields);
     if ($member) {
         $member->Password = "";
         //prevents password field from being populated with encrypted password data
         $this->loadDataFrom($member);
     }
 }
コード例 #3
0
 function updateCMSFields(FieldList $fields)
 {
     $fields->removeFieldFromTab('Root.Members', 'Members');
     $fieldList = array('FirstName' => 'Name', 'Surname' => 'Last Name');
     $password = new ConfirmedPasswordField('Password', null, null, null, true);
     $password->setCanBeEmpty(true);
     $detailFormFields = new FieldList(new TabSet("Root", new Tab('Main', 'Main', new HeaderField('MemberDetailsHeader', "Personal Details"), new TextField("FirstName", "First Name"), new TextField("Surname", "Last Name"), new HeaderField('MemberUserDetailsHeader', "User Details"), $password, new TextField("Email", "Email"), new TextField("SecondEmail", "Second Email"), new TextField("Third Email", "Third Email"), new TextField("FoodPreference", "Food Preference"), new TextField("OtherFood", "Other Food"), new TextField("IRCHandle", "IRC Handle"), new TextField("TwitterName", "Twitter Name"), new TextField("LinkedInProfile", "LinkedIn Profile"), new TextField("JobTitle", "Job Title"), new TextField("Role", "Role"), new TextareaField("StatementOfInterest", "Statement Of Interest"), new HtmlEditorField("Bio", "Bio"))));
     // make table sortable for foundation-staff and supporting-cast
     if ($this->owner->Code == 'openstack-foundation-staff' || $this->owner->Code == 'supporting-cast') {
         $config = GridFieldConfig_RelationEditor::create(10);
         $config->getComponentByType('GridFieldDetailForm')->setFields($detailFormFields);
         $sort = new GridFieldSortableRows('SortOrder');
         $config->addComponent($sort);
         $config->removeComponentsByType('GridFieldPageCount');
         $config->removeComponentsByType('GridFieldPaginator');
         $dataColumns = $config->getComponentByType('GridFieldDataColumns');
         $dataColumns->setDisplayFields(array('SortOrder' => 'Order', 'FirstName' => 'Name', 'Surname' => 'Surname', 'Email' => 'Email'));
     } else {
         $config = GridFieldConfig_RelationEditor::create(10);
         $config->getComponentByType('GridFieldDetailForm')->setFields($detailFormFields);
     }
     $manager = new GridField('Members', 'Members', $this->owner->Members(), $config);
     $fields->addFieldToTab('Root.Members', $manager);
     $fields->push(new HiddenField("GroupEdtion", "GroupEdtion", "1"));
 }
コード例 #4
0
ファイル: Customer.php プロジェクト: vinstah/body
 /**
  * Add some fields for managing Members in the CMS.
  * 
  * @return FieldList
  */
 public function getCMSFields()
 {
     $fields = new FieldList();
     $fields->push(new TabSet('Root', Tab::create('Customer')));
     $password = new ConfirmedPasswordField('Password', null, null, null, true);
     $password->setCanBeEmpty(true);
     if (!$this->ID) {
         $password->showOnClick = false;
     }
     $fields->addFieldsToTab('Root.Customer', array(new TextField('FirstName'), new TextField('Surname'), new EmailField('Email'), new ConfirmedPasswordField('Password'), $password));
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
コード例 #5
0
 function updateCMSFields(FieldList $fields)
 {
     $fields->removeFieldFromTab('Root.Members', 'Members');
     $fieldList = array('FirstName' => 'Name', 'Surname' => 'Last Name');
     $password = new ConfirmedPasswordField('Password', null, null, null, true);
     $password->setCanBeEmpty(true);
     $detailFormFields = new FieldList(new TabSet("Root", new Tab('Main', 'Main', new HeaderField('MemberDetailsHeader', "Personal Details"), new TextField("FirstName", "First Name"), new TextField("Surname", "Last Name"), new HeaderField('MemberUserDetailsHeader', "User Details"), $password, new TextField("Email", "Email"), new TextField("SecondEmail", "Second Email"), new TextField("Third Email", "Third Email"), new TextField("FoodPreference", "Food Preference"), new TextField("OtherFood", "Other Food"), new TextField("IRCHandle", "IRC Handle"), new TextField("TwitterName", "Twitter Name"), new TextField("LinkedInProfile", "LinkedIn Profile"), new TextField("JobTitle", "Job Title"), new TextField("Role", "Role"), new TextareaField("StatementOfInterest", "Statement Of Interest"), new HtmlEditorField("Bio", "Bio"))));
     $config = GridFieldConfig_RelationEditor::create(10);
     $config->getComponentByType('GridFieldDetailForm')->setFields($detailFormFields);
     $manager = new GridField('Members', 'Members', $this->owner->Members(), $config);
     $fields->addFieldToTab('Root.Members', $manager);
     $fields->push(new HiddenField("GroupEdtion", "GroupEdtion", "1"));
 }
コード例 #6
0
 public function testHashHidden()
 {
     $field = new ConfirmedPasswordField('Password', 'Password', 'valueA');
     $field->setCanBeEmpty(true);
     $this->assertEquals('valueA', $field->Value());
     $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_Password]')->Value());
     $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value());
     $member = new Member();
     $member->Password = "******";
     $member->write();
     $form = new Form($this, 'Form', new FieldList($field), new FieldList());
     $form->loadDataFrom($member);
     $this->assertEquals('', $field->Value());
     $this->assertEquals('', $field->children->fieldByName($field->getName() . '[_Password]')->Value());
     $this->assertEquals('', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value());
 }
コード例 #7
0
 function __construct($controller, $name)
 {
     $member = Member::currentUser();
     if ($member && $member->exists()) {
         $fields = $member->getEcommerceFields();
         $passwordField = new ConfirmedPasswordField('Password', 'Password');
         if ($member->Password != '') {
             $passwordField->setCanBeEmpty(true);
         }
         $fields->push(new LiteralField('LogoutNote', "<p class=\"message good\">" . _t("MemberForm.LOGGEDIN", "You are currently logged in as ") . $member->FirstName . ' ' . $member->Surname . ". Click <a href=\"Security/logout\" title=\"Click here to log out\">here</a> to log out.</p>"));
         $fields->push(new HeaderField('Login Details', 3));
         $fields->push($passwordField);
         $requiredFields = new RequiredFields($member->getEcommerceRequiredFields());
     } else {
         $fields = new FieldSet();
     }
     $actions = new FieldSet(new FormAction('submit', 'Save Changes'), new FormAction('proceed', 'Save and proceed to checkout'));
     parent::__construct($controller, $name, $fields, $actions, $requiredFields);
     if ($member) {
         $this->loadDataFrom($member);
     }
 }
コード例 #8
0
    function __construct($controller, $name)
    {
        $member = Member::currentUser();
        if ($member && $member->exists()) {
            $fields = $member->getCleanUpMemberRoleFields();
            $passwordField = new ConfirmedPasswordField('Password', 'Password');
            if ($member->Password != '') {
                $passwordField->setCanBeEmpty(true);
            }
            $fields->push($passwordField);
            $fields->push(new LiteralField('LogoutNote', "<div class=\"clear\"></div><p class=\"message good\">" . _t("MemberForm.LOGGEDIN", "You are currently logged in as ") . $member->FirstName . ' ' . $member->Surname . ". Click <a href=\"Security/logout\" title=\"Click here to log out\">here</a> to log out.</p>"));
            //$fields->push(new HeaderField('Login Details', 3));
            $requiredFields = '';
        } else {
            $fields = new FieldSet();
        }
        Requirements::customScript('
			jQuery(document).ready(function() {
				
				jQuery("#AccountForm_MemberForm_FirstName").addClass("validate[required,custom[onlyLetter],length[0,100]] text-input");
				jQuery("#AccountForm_MemberForm_Surname").addClass("validate[required,custom[onlyLetter],length[0,100]] text-input");
				jQuery("#AccountForm_MemberForm_Address").addClass("validate[required,length[6,300]] text-input");
				jQuery("#AccountForm_MemberForm_Email").addClass("validate[required,custom[email]] text-input");
				jQuery("#AccountForm_MemberForm #Password input").addClass("validate[required,length[6,100]] text-input");
				
				jQuery("#AccountForm_MemberForm").validationEngine()
				
			});
		');
        $requiredFields = '';
        $actions = new FieldSet(new FormAction('submit', 'Save Changes'));
        parent::__construct($controller, $name, $fields, $actions, $requiredFields);
        if ($member) {
            $this->loadDataFrom($member);
        }
    }
コード例 #9
0
ファイル: Member.php プロジェクト: nicmart/comperio-site
 /**
  * Return a {@link FieldSet} of fields that would appropriate for editing
  * this member.
  *
  * @return FieldSet Return a FieldSet of fields that would appropriate for
  *                  editing this member.
  */
 public function getCMSFields()
 {
     require_once 'Zend/Date.php';
     $fields = parent::getCMSFields();
     $mainFields = $fields->fieldByName("Root")->fieldByName("Main")->Children;
     $password = new ConfirmedPasswordField('Password', null, null, null, true);
     $password->setCanBeEmpty(true);
     if (!$this->ID) {
         $password->showOnClick = false;
     }
     $mainFields->replaceField('Password', $password);
     $mainFields->insertBefore(new HeaderField('MemberDetailsHeader', _t('Member.PERSONALDETAILS', "Personal Details", PR_MEDIUM, 'Headline for formfields')), 'FirstName');
     $mainFields->insertBefore(new HeaderField('MemberUserDetailsHeader', _t('Member.USERDETAILS', "User Details", PR_MEDIUM, 'Headline for formfields')), 'Email');
     $mainFields->replaceField('Locale', new DropdownField("Locale", _t('Member.INTERFACELANG', "Interface Language", PR_MEDIUM, 'Language of the CMS'), i18n::get_existing_translations()));
     $mainFields->removeByName('Bounced');
     $mainFields->removeByName('RememberLoginToken');
     $mainFields->removeByName('AutoLoginHash');
     $mainFields->removeByName('AutoLoginExpired');
     $mainFields->removeByName('PasswordEncryption');
     $mainFields->removeByName('PasswordExpiry');
     $mainFields->removeByName('LockedOutUntil');
     if (!self::$lock_out_after_incorrect_logins) {
         $mainFields->removeByName('FailedLoginCount');
     }
     $mainFields->removeByName('Salt');
     $mainFields->removeByName('NumVisit');
     $mainFields->removeByName('LastVisited');
     $fields->removeByName('Subscriptions');
     // Groups relation will get us into logical conflicts because
     // Members are displayed within  group edit form in SecurityAdmin
     $fields->removeByName('Groups');
     if (Permission::check('EDIT_PERMISSIONS')) {
         $groupsField = new TreeMultiselectField('Groups', false, 'Group');
         $fields->findOrMakeTab('Root.Groups', singleton('Group')->i18n_plural_name());
         $fields->addFieldToTab('Root.Groups', $groupsField);
         // Add permission field (readonly to avoid complicated group assignment logic).
         // This should only be available for existing records, as new records start
         // with no permissions until they have a group assignment anyway.
         if ($this->ID) {
             $permissionsField = new PermissionCheckboxSetField_Readonly('Permissions', singleton('Permission')->i18n_plural_name(), 'Permission', 'GroupID', $this->getManyManyComponents('Groups'));
             $fields->findOrMakeTab('Root.Permissions', singleton('Permission')->i18n_plural_name());
             $fields->addFieldToTab('Root.Permissions', $permissionsField);
         }
     }
     $defaultDateFormat = Zend_Locale_Format::getDateFormat($this->Locale);
     $dateFormatMap = array('MMM d, yyyy' => Zend_Date::now()->toString('MMM d, yyyy'), 'yyyy/MM/dd' => Zend_Date::now()->toString('yyyy/MM/dd'), 'MM/dd/yyyy' => Zend_Date::now()->toString('MM/dd/yyyy'), 'dd/MM/yyyy' => Zend_Date::now()->toString('dd/MM/yyyy'));
     $dateFormatMap[$defaultDateFormat] = Zend_Date::now()->toString($defaultDateFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
     $mainFields->push($dateFormatField = new Member_DatetimeOptionsetField('DateFormat', $this->fieldLabel('DateFormat'), $dateFormatMap));
     $dateFormatField->setValue($this->DateFormat);
     $defaultTimeFormat = Zend_Locale_Format::getTimeFormat($this->Locale);
     $timeFormatMap = array('h:mm a' => Zend_Date::now()->toString('h:mm a'), 'H:mm' => Zend_Date::now()->toString('H:mm'));
     $timeFormatMap[$defaultTimeFormat] = Zend_Date::now()->toString($defaultTimeFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
     $mainFields->push($timeFormatField = new Member_DatetimeOptionsetField('TimeFormat', $this->fieldLabel('TimeFormat'), $timeFormatMap));
     $timeFormatField->setValue($this->TimeFormat);
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
コード例 #10
0
ファイル: Member.php プロジェクト: hemant-chakka/awss
 /**
  * Return a {@link FieldList} of fields that would appropriate for editing
  * this member.
  *
  * @return FieldList Return a FieldList of fields that would appropriate for
  *                   editing this member.
  */
 public function getCMSFields()
 {
     require_once 'Zend/Date.php';
     $self = $this;
     $this->beforeUpdateCMSFields(function ($fields) use($self) {
         $mainFields = $fields->fieldByName("Root")->fieldByName("Main")->Children;
         $password = new ConfirmedPasswordField('Password', null, null, null, true);
         $password->setCanBeEmpty(true);
         if (!$self->ID) {
             $password->showOnClick = false;
         }
         $mainFields->replaceField('Password', $password);
         $mainFields->replaceField('Locale', new DropdownField("Locale", _t('Member.INTERFACELANG', "Interface Language", 'Language of the CMS'), i18n::get_existing_translations()));
         $mainFields->removeByName('RememberLoginToken');
         $mainFields->removeByName('AutoLoginHash');
         $mainFields->removeByName('AutoLoginExpired');
         $mainFields->removeByName('PasswordEncryption');
         $mainFields->removeByName('PasswordExpiry');
         $mainFields->removeByName('LockedOutUntil');
         if (!$self->config()->lock_out_after_incorrect_logins) {
             $mainFields->removeByName('FailedLoginCount');
         }
         $mainFields->removeByName('Salt');
         $mainFields->removeByName('NumVisit');
         $mainFields->makeFieldReadonly('LastVisited');
         $fields->removeByName('Subscriptions');
         // Groups relation will get us into logical conflicts because
         // Members are displayed within  group edit form in SecurityAdmin
         $fields->removeByName('Groups');
         if (Permission::check('EDIT_PERMISSIONS')) {
             $groupsMap = array();
             foreach (Group::get() as $group) {
                 // Listboxfield values are escaped, use ASCII char instead of &raquo;
                 $groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
             }
             asort($groupsMap);
             $fields->addFieldToTab('Root.Main', ListboxField::create('DirectGroups', singleton('Group')->i18n_plural_name())->setMultiple(true)->setSource($groupsMap)->setAttribute('data-placeholder', _t('Member.ADDGROUP', 'Add group', 'Placeholder text for a dropdown')));
             // Add permission field (readonly to avoid complicated group assignment logic).
             // This should only be available for existing records, as new records start
             // with no permissions until they have a group assignment anyway.
             if ($self->ID) {
                 $permissionsField = new PermissionCheckboxSetField_Readonly('Permissions', false, 'Permission', 'GroupID', $self->getManyManyComponents('Groups'));
                 $fields->findOrMakeTab('Root.Permissions', singleton('Permission')->i18n_plural_name());
                 $fields->addFieldToTab('Root.Permissions', $permissionsField);
             }
         }
         $permissionsTab = $fields->fieldByName("Root")->fieldByName('Permissions');
         if ($permissionsTab) {
             $permissionsTab->addExtraClass('readonly');
         }
         $defaultDateFormat = Zend_Locale_Format::getDateFormat(new Zend_Locale($self->Locale));
         $dateFormatMap = array('MMM d, yyyy' => Zend_Date::now()->toString('MMM d, yyyy'), 'yyyy/MM/dd' => Zend_Date::now()->toString('yyyy/MM/dd'), 'MM/dd/yyyy' => Zend_Date::now()->toString('MM/dd/yyyy'), 'dd/MM/yyyy' => Zend_Date::now()->toString('dd/MM/yyyy'));
         $dateFormatMap[$defaultDateFormat] = Zend_Date::now()->toString($defaultDateFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
         $mainFields->push($dateFormatField = new MemberDatetimeOptionsetField('DateFormat', $self->fieldLabel('DateFormat'), $dateFormatMap));
         $dateFormatField->setValue($self->DateFormat);
         $defaultTimeFormat = Zend_Locale_Format::getTimeFormat(new Zend_Locale($self->Locale));
         $timeFormatMap = array('h:mm a' => Zend_Date::now()->toString('h:mm a'), 'H:mm' => Zend_Date::now()->toString('H:mm'));
         $timeFormatMap[$defaultTimeFormat] = Zend_Date::now()->toString($defaultTimeFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
         $mainFields->push($timeFormatField = new MemberDatetimeOptionsetField('TimeFormat', $self->fieldLabel('TimeFormat'), $timeFormatMap));
         $timeFormatField->setValue($self->TimeFormat);
     });
     return parent::getCMSFields();
 }
コード例 #11
0
ファイル: Member.php プロジェクト: ramziammar/websites
 /**
  * Return a {@link FieldSet} of fields that would appropriate for editing
  * this member.
  *
  * @return FieldSet Return a FieldSet of fields that would appropriate for
  *                  editing this member.
  */
 public function getCMSFields()
 {
     $locale = $this->Locale ? $this->Locale : i18n::get_locale();
     $password = new ConfirmedPasswordField('Password', 'Password');
     $password->setCanBeEmpty(true);
     $fields = new FieldSet(new HeaderField(_t('Member.PERSONALDETAILS', "Personal Details", PR_MEDIUM, 'Headline for formfields')), new TextField("FirstName", _t('Member.FIRSTNAME')), new TextField("Surname", _t('Member.SURNAME')), new HeaderField(_t('Member.USERDETAILS', "User Details", PR_MEDIUM, 'Headline for formfields')), new TextField("Email", _t('Member.EMAIL')), new DropdownField("Locale", _t('Member.INTERFACELANG', "Interface Language", PR_MEDIUM, 'Language of the CMS'), i18n::get_existing_translations(), $locale), $password);
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
コード例 #12
0
ファイル: Member.php プロジェクト: neopba/silverstripe-book
	/**
	 * Return a {@link FieldSet} of fields that would appropriate for editing
	 * this member.
	 *
	 * @return FieldSet Return a FieldSet of fields that would appropriate for
	 *                  editing this member.
	 */
	public function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$mainFields = $fields->fieldByName("Root")->fieldByName("Main")->Children;
		
		$password = new ConfirmedPasswordField(
			'Password', 
			null, 
			null, 
			null, 
			true // showOnClick
		);
		$password->setCanBeEmpty(true);
		if(!$this->ID) $password->showOnClick = false;
		$mainFields->replaceField('Password', $password);
		
		$mainFields->insertBefore(
			new HeaderField('MemberDetailsHeader',_t('Member.PERSONALDETAILS', "Personal Details", PR_MEDIUM, 'Headline for formfields')),
			'FirstName'
		);
		
		$mainFields->insertBefore(
			new HeaderField('MemberUserDetailsHeader',_t('Member.USERDETAILS', "User Details", PR_MEDIUM, 'Headline for formfields')),
			'Email'
		);
		
		$locale = ($this->Locale) ? $this->Locale : i18n::get_locale();
		$mainFields->replaceField('Locale', new DropdownField(
			"Locale", 
			_t('Member.INTERFACELANG', "Interface Language", PR_MEDIUM, 'Language of the CMS'), 
			i18n::get_existing_translations(), 
			$locale
		));
		
		$mainFields->removeByName('Bounced');
		$mainFields->removeByName('RememberLoginToken');
		$mainFields->removeByName('AutoLoginHash');
		$mainFields->removeByName('AutoLoginExpired');
		$mainFields->removeByName('PasswordEncryption');
		$mainFields->removeByName('PasswordExpiry');
		$mainFields->removeByName('LockedOutUntil');
		$mainFields->removeByName('Salt');
		$mainFields->removeByName('NumVisit');
		$mainFields->removeByName('LastVisited');
	
		$fields->removeByName('Subscriptions');
		// Groups relation will get us into logical conflicts because
		// Members are displayed within  group edit form in SecurityAdmin
		$fields->removeByName('Groups');

		$this->extend('updateCMSFields', $fields);
		
		return $fields;
	}
コード例 #13
0
 function __construct($controller, $name)
 {
     //requirements
     Requirements::javascript('ecommerce/javascript/EcomOrderFormAddress.js');
     // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         Requirements::javascript('ecommerce/javascript/EcomOrderFormShipping.js');
         // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     }
     //set basics
     $order = ShoppingCart::current_order();
     $requiredFields = array();
     //  ________________ 1) Member + Address fields
     //find member
     $this->orderMember = $order->CreateOrReturnExistingMember(false);
     $this->loggedInMember = Member::currentUser();
     //strange security situation...
     if ($this->orderMember->exists() && $this->loggedInMember) {
         if ($this->orderMember->ID != $this->loggedInMember->ID) {
             if (!$this->loggedInMember->IsShopAdmin()) {
                 $this->loggedInMember->logOut();
             }
         }
     }
     $addressFieldsBilling = new FieldSet();
     //member fields
     if ($this->orderMember) {
         $memberFields = $this->orderMember->getEcommerceFields();
         $requiredFields = array_merge($requiredFields, $this->orderMember->getEcommerceRequiredFields());
         $addressFieldsBilling->merge($memberFields);
     }
     //billing address field
     $billingAddress = $order->CreateOrReturnExistingAddress("BillingAddress");
     $billingAddressFields = $billingAddress->getFields($this->orderMember);
     $requiredFields = array_merge($requiredFields, $billingAddress->getRequiredFields());
     $addressFieldsBilling->merge($billingAddressFields);
     //shipping address field
     $addressFieldsShipping = null;
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         $addressFieldsShipping = new FieldSet();
         //add the important CHECKBOX
         $useShippingAddressField = new FieldSet(new CheckboxField("UseShippingAddress", _t("OrderForm.USESHIPPINGADDRESS", "Use an alternative shipping address")));
         $addressFieldsShipping->merge($useShippingAddressField);
         //now we can add the shipping fields
         $shippingAddress = $order->CreateOrReturnExistingAddress("ShippingAddress");
         $shippingAddressFields = $shippingAddress->getFields($this->orderMember);
         //we have left this out for now as it was giving a lot of grief...
         //$requiredFields = array_merge($requiredFields, $shippingAddress->getRequiredFields());
         //finalise left fields
         $addressFieldsShipping->merge($shippingAddressFields);
     }
     $leftFields = new CompositeField($addressFieldsBilling);
     $leftFields->setID('LeftOrderBilling');
     $allLeftFields = new CompositeField($leftFields);
     $allLeftFields->setID('LeftOrder');
     if ($addressFieldsShipping) {
         $leftFieldsShipping = new CompositeField($addressFieldsShipping);
         $leftFieldsShipping->setID('LeftOrderShipping');
         $allLeftFields->push($leftFieldsShipping);
     }
     //  ________________  2) Log in / vs Create Account fields - RIGHT-HAND-SIDE fields
     $rightFields = new CompositeField();
     $rightFields->setID('RightOrder');
     //to do: simplify
     if (EcommerceConfig::get("EcommerceRole", "allow_customers_to_setup_accounts")) {
         if ($this->orderDoesNotHaveFullyOperationalMember()) {
             //general header
             if (!$this->loggedInMember) {
                 $rightFields->push(new LiteralField('MemberInfo', '<p class="message good">' . _t('OrderForm.MEMBERINFO', 'If you are already have an account then please') . " <a href=\"Security/login/?BackURL=" . urlencode($controller->Link()) . "\">" . _t('OrderForm.LOGIN', 'log in') . '</a>.</p>'));
             }
             $passwordField = new ConfirmedPasswordField('Password', _t('OrderForm.PASSWORD', 'Password'));
             //login invite right on the top
             if (EcommerceConfig::get("EcommerceRole", "automatic_membership")) {
                 $rightFields->push(new HeaderField('CreateAnAccount', _t('OrderForm.CREATEANACCONTOPTIONAL', 'Create an account (optional)'), 3));
                 //allow people to purchase without creating a password
                 $passwordField->setCanBeEmpty(true);
             } else {
                 $rightFields->push(new HeaderField('SetupYourAccount', _t('OrderForm.SETUPYOURACCOUNT', 'Setup your account'), 3));
                 //dont allow people to purchase without creating a password
                 $passwordField->setCanBeEmpty(false);
             }
             $requiredFields[] = 'Password[_Password]';
             $requiredFields[] = 'Password[_ConfirmPassword]';
             Requirements::customScript('jQuery("#ChoosePassword").click();', "EommerceChoosePassword");
             // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
             $rightFields->push(new LiteralField('AccountInfo', '<p>' . _t('OrderForm.ACCOUNTINFO', 'Please <a href="#Password" class="choosePassword">choose a password</a>; this will allow you can log in and check your order history in the future.') . '</p>'));
             $rightFields->push(new FieldGroup($passwordField));
         } else {
             if ($this->loggedInMember) {
                 $rightFields->push(new LiteralField('LoginNote', "<p class=\"message good\">" . _t("Account.LOGGEDIN", "You are logged in as ") . $this->loggedInMember->FirstName . ' ' . $this->loggedInMember->Surname . ' (' . $this->loggedInMember->Email . ').</p>'));
             }
         }
         if ($this->orderMember->exists()) {
             if ($this->loggedInMember) {
                 if ($this->loggedInMember->ID != $this->orderMember->ID) {
                     $rightFields->push(new LiteralField('OrderAddedTo', "<p class=\"message good\">" . _t("Account.ORDERADDEDTO", "Order will be added to ") . $this->orderMember->FirstName . ' ' . $this->orderMember->Surname . ' (' . $this->orderMember->Email . ').</p>'));
                 }
             }
         }
     }
     //  ________________  5) Put all the fields in one FieldSet
     $fields = new FieldSet($rightFields, $allLeftFields);
     //  ________________  6) Actions and required fields creation + Final Form construction
     $nextButton = new FormAction('saveAddress', _t('OrderForm.NEXT', 'Next'));
     $nextButton->addExtraClass("next");
     $actions = new FieldSet($nextButton);
     $validator = new OrderFormAddress_Validator($requiredFields);
     //TODO: do we need this here?
     $validator->setJavascriptValidationHandler("prototype");
     parent::__construct($controller, $name, $fields, $actions, $validator);
     //extensions need to be set after __construct
     if ($this->extend('updateFields', $fields) !== null) {
         $this->setFields($fields);
     }
     if ($this->extend('updateActions', $actions) !== null) {
         $this->setActions($actions);
     }
     if ($this->extend('updateValidator', $validator) !== null) {
         $this->setValidator($validator);
     }
     //  ________________  7)  Load saved data
     //we do this first so that Billing and Shipping Address can override this...
     if ($this->orderMember) {
         $this->loadDataFrom($this->orderMember);
     }
     if ($order) {
         $this->loadDataFrom($order);
         if ($billingAddress) {
             $this->loadDataFrom($billingAddress);
         }
         if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
             if ($shippingAddress) {
                 $this->loadDataFrom($shippingAddress);
             }
         }
     }
     //allow updating via decoration
     $this->extend('updateOrderFormAddress', $this);
 }
コード例 #14
0
 function __construct($controller, $name)
 {
     //Requirements::themedCSS('OrderForm');
     // 1) Member and shipping fields
     $member = Member::currentUser();
     $memberFields = new CompositeField(singleton('Member')->getEcommerceFields());
     $requiredFields = singleton('Member')->getEcommerceRequiredFields();
     if (ShoppingCart::uses_different_shipping_address()) {
         $countryField = new DropdownField('ShippingCountry', _t('OrderForm.Country', 'Country'), Geoip::getCountryDropDown(), EcommerceRole::find_country());
         $shippingFields = new CompositeField(new HeaderField(_t('OrderForm.SendGoodsToDifferentAddress', 'Send goods to different address'), 3), new LiteralField('ShippingNote', '<p class="message warning">' . _t('OrderForm.ShippingNote', 'Your goods will be sent to the address below.') . '</p>'), new LiteralField('Help', '<p>' . _t('OrderForm.Help', 'You can use this for gift giving. No billing information will be disclosed to this address.') . '</p>'), new TextField('ShippingName', _t('OrderForm.Name', 'Name')), new TextField('ShippingAddress', _t('OrderForm.Address', 'Address')), new TextField('ShippingAddress2', _t('OrderForm.Address2', '')), new TextField('ShippingCity', _t('OrderForm.City', 'City')), $countryField, new HiddenField('UseShippingAddress', '', true), $changeshippingbutton = new FormAction_WithoutLabel('useMemberShippingAddress', _t('OrderForm.UseBillingAddress', 'Use Billing Address for Shipping')));
         //Need to to this because 'FormAction_WithoutLabel' has no text on the actual button
         $changeshippingbutton->setButtonContent(_t('OrderForm.UseBillingAddress', 'Use Billing Address for Shipping'));
         $changeshippingbutton->useButtonTag = true;
         $requiredFields[] = 'ShippingName';
         $requiredFields[] = 'ShippingAddress';
         $requiredFields[] = 'ShippingCity';
         $requiredFields[] = 'ShippingCountry';
     } else {
         $countryField = $memberFields->fieldByName('Country');
         $shippingFields = new FormAction_WithoutLabel('useDifferentShippingAddress', _t('OrderForm.useDifferentShippingAddress', 'Use Different Shipping Address'));
         //Need to to this because 'FormAction_WithoutLabel' has no text on the actual button
         $shippingFields->setButtonContent(_t('OrderForm.useDifferentShippingAddress', 'Use Different Shipping Address'));
         $shippingFields->useButtonTag = true;
     }
     if ($countryField) {
         $countryField->addExtraClass('ajaxCountryField');
         $setCountryLinkID = $countryField->id() . '_SetCountryLink';
         $setContryLink = ShoppingCart::set_country_link();
         $memberFields->push(new HiddenField($setCountryLinkID, '', $setContryLink));
     }
     $leftFields = new CompositeField($memberFields, $shippingFields);
     $leftFields->setID('LeftOrder');
     $rightFields = new CompositeField();
     $rightFields->setID('RightOrder');
     if (!$member) {
         $rightFields->push(new HeaderField(_t('OrderForm.MembershipDetails', 'Membership Details'), 3));
         $rightFields->push(new LiteralField('MemberInfo', '<p class="message warning">' . _t('OrderForm.MemberInfo', 'If you are already a member please') . " <a href=\"Security/login?BackURL=" . CheckoutPage::find_link(true) . "/\">" . _t('OrderForm.LogIn', 'log in') . '</a>.</p>'));
         $rightFields->push(new LiteralField('AccountInfo', '<p>' . _t('OrderForm.AccountInfo', 'Please choose a password, so you can login and check your order history in the future') . '</p><br/>'));
         $rightFields->push(new FieldGroup($pwf = new ConfirmedPasswordField('Password', _t('OrderForm.Password', 'Password'))));
         //if user doesn't fill out password, we assume they don't want to become a member
         //TODO: allow different ways of specifying that you want to become a member
         if (self::$user_membership_optional) {
             $pwf->setCanBeEmpty(true);
         }
         if (self::$force_membership || !self::$user_membership_optional) {
             $requiredFields[] = 'Password[_Password]';
             $requiredFields[] = 'Password[_ConfirmPassword]';
             //TODO: allow extending this to provide other ways of indicating that you want to become a member
         }
     } else {
         $rightFields->push(new LiteralField('MemberInfo', '<p class="message good">' . sprintf(_t('OrderForm.LoggedInAs', 'You are logged in as %s.'), $member->getName()) . " <a href=\"Security/logout?BackURL=" . CheckoutPage::find_link(true) . "/\">" . _t('OrderForm.LogOut', 'log out') . '</a>.</p>'));
     }
     // 2) Payment fields
     $currentOrder = ShoppingCart::current_order();
     $totalobj = DBField::create('Currency', $currentOrder->Total());
     //should instead be $totalobj = $currentOrder->dbObject('Total');
     $paymentFields = Payment::combined_form_fields($totalobj->Nice());
     foreach ($paymentFields as $field) {
         $rightFields->push($field);
     }
     if ($paymentRequiredFields = Payment::combined_form_requirements()) {
         $requiredFields = array_merge($requiredFields, $paymentRequiredFields);
     }
     // 3) Put all the fields in one FieldSet
     $fields = new FieldSet($leftFields, $rightFields);
     // 4) Terms and conditions field
     // If a terms and conditions page exists, we need to create a field to confirm the user has read it
     if ($controller->TermsPageID && ($termsPage = $controller->TermsPage())) {
         $bottomFields = new CompositeField(new CheckboxField('ReadTermsAndConditions', sprintf(_t('OrderForm.TERMSANDCONDITIONS', "I agree to the terms and conditions stated on the <a href=\"%s\" title=\"Read the shop terms and conditions for this site\">terms and conditions</a> page"), $termsPage->Link())));
         $bottomFields->setID('BottomOrder');
         $fields->push($bottomFields);
         $requiredFields[] = 'ReadTermsAndConditions';
         //TODO: this doesn't work for check-boxes
     }
     // 5) Actions and required fields creation
     $actions = new FieldSet(new FormAction('processOrder', _t('OrderForm.processOrder', 'Place order and make payment')));
     $requiredFields = new CustomRequiredFields($requiredFields);
     $this->extend('updateValidator', $requiredFields);
     $this->extend('updateFields', $fields);
     // 6) Form construction
     parent::__construct($controller, $name, $fields, $actions, $requiredFields);
     // 7) Member details loading
     if ($member && $member->ID) {
         $this->loadDataFrom($member);
     }
     // 8) Country field value update
     if ($countryField) {
         $currentOrder = ShoppingCart::current_order();
         $currentOrderCountry = $currentOrder->findShippingCountry(true);
         $countryField->setValue($currentOrderCountry);
     }
     //allow updating via decoration
     $this->extend('updateForm', $this);
 }