2012-03-02 18:27:10 +01:00
|
|
|
<?php
|
2013-10-15 00:26:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package framework
|
|
|
|
* @subpackage admin
|
|
|
|
*/
|
2012-03-02 18:27:10 +01:00
|
|
|
class CMSProfileController extends LeftAndMain {
|
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $url_segment = 'myprofile';
|
2012-11-06 23:41:48 +01:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $menu_title = 'My Profile';
|
2012-11-06 23:41:48 +01:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $required_permission_codes = false;
|
2013-06-20 11:40:55 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $tree_class = 'Member';
|
2012-03-02 18:27:10 +01:00
|
|
|
|
2012-10-08 04:02:01 +02:00
|
|
|
public function getEditForm($id = null, $fields = null) {
|
|
|
|
$this->setCurrentPageID(Member::currentUserID());
|
|
|
|
|
|
|
|
$form = parent::getEditForm($id, $fields);
|
|
|
|
|
2013-10-15 00:26:23 +02:00
|
|
|
if($form instanceof SS_HTTPResponse) {
|
|
|
|
return $form;
|
|
|
|
}
|
2013-10-16 00:29:43 +02:00
|
|
|
|
2013-06-13 15:01:23 +02:00
|
|
|
$form->Fields()->removeByName('LastVisited');
|
2012-10-08 04:02:01 +02:00
|
|
|
$form->Fields()->push(new HiddenField('ID', null, Member::currentUserID()));
|
|
|
|
$form->Actions()->push(
|
|
|
|
FormAction::create('save',_t('CMSMain.SAVE', 'Save'))
|
2012-12-08 12:20:20 +01:00
|
|
|
->addExtraClass('ss-ui-button ss-ui-action-constructive')
|
|
|
|
->setAttribute('data-icon', 'accept')
|
|
|
|
->setUseButtonTag(true)
|
|
|
|
);
|
2013-10-15 00:26:23 +02:00
|
|
|
|
2012-12-15 20:02:17 +01:00
|
|
|
$form->Actions()->removeByName('action_delete');
|
2013-10-16 00:29:43 +02:00
|
|
|
|
|
|
|
if($member = Member::currentUser()) {
|
|
|
|
$form->setValidator($member->getValidator());
|
|
|
|
} else {
|
|
|
|
$form->setValidator(Injector::inst()->get('Member')->getValidator());
|
|
|
|
}
|
|
|
|
|
|
|
|
if($form->Fields()->hasTabset()) {
|
|
|
|
$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
|
|
|
|
}
|
|
|
|
|
2013-11-07 16:19:40 +01:00
|
|
|
$form->addExtraClass('member-profile-form root-form cms-edit-form center');
|
2012-10-08 04:02:01 +02:00
|
|
|
|
|
|
|
return $form;
|
2012-03-02 18:27:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function canView($member = null) {
|
2015-08-26 16:46:52 +02:00
|
|
|
if(!$member && $member !== false) $member = Member::currentUser();
|
|
|
|
|
2012-03-02 18:27:10 +01:00
|
|
|
// cms menus only for logged-in members
|
|
|
|
if(!$member) return false;
|
2015-08-26 16:46:52 +02:00
|
|
|
|
|
|
|
// Check they can access the CMS and that they are trying to edit themselves
|
2012-03-02 18:27:10 +01:00
|
|
|
if(
|
2015-08-26 16:46:52 +02:00
|
|
|
Permission::checkMember($member, "CMS_ACCESS")
|
|
|
|
&& $member->ID === Member::currentUserID()
|
2012-03-02 18:27:10 +01:00
|
|
|
) {
|
2015-08-26 16:46:52 +02:00
|
|
|
return true;
|
2012-03-02 18:27:10 +01:00
|
|
|
}
|
2015-08-26 16:46:52 +02:00
|
|
|
|
|
|
|
return false;
|
2012-03-02 18:27:10 +01:00
|
|
|
}
|
2012-10-08 04:02:01 +02:00
|
|
|
|
|
|
|
public function save($data, $form) {
|
|
|
|
$member = DataObject::get_by_id("Member", $data['ID']);
|
|
|
|
if(!$member) return $this->httpError(404);
|
|
|
|
$origLocale = $member->Locale;
|
|
|
|
|
2012-10-30 17:28:27 +01:00
|
|
|
if(!$member->canEdit()) {
|
|
|
|
$form->sessionMessage(_t('Member.CANTEDIT', 'You don\'t have permission to do that'), 'bad');
|
2012-10-30 18:03:49 +01:00
|
|
|
return $this->redirectBack();
|
2012-10-30 17:28:27 +01:00
|
|
|
}
|
|
|
|
|
2012-10-08 04:02:01 +02:00
|
|
|
$response = parent::save($data, $form);
|
2012-10-30 17:28:27 +01:00
|
|
|
|
2012-10-08 04:02:01 +02:00
|
|
|
if($origLocale != $data['Locale']) {
|
|
|
|
$response->addHeader('X-Reload', true);
|
|
|
|
$response->addHeader('X-ControllerURL', $this->Link());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Only show first element, as the profile form is limited to editing
|
|
|
|
* the current member it doesn't make much sense to show the member name
|
|
|
|
* in the breadcrumbs.
|
|
|
|
*/
|
|
|
|
public function Breadcrumbs($unlinked = false) {
|
|
|
|
$items = parent::Breadcrumbs($unlinked);
|
|
|
|
return new ArrayList(array($items[0]));
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|