2007-07-19 12:40:05 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Security section of the CMS
|
|
|
|
* @package cms
|
|
|
|
* @subpackage security
|
|
|
|
*/
|
2007-08-31 02:31:49 +02:00
|
|
|
class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
2008-10-08 01:27:07 +02:00
|
|
|
|
2008-11-02 22:27:55 +01:00
|
|
|
static $url_segment = 'security';
|
|
|
|
|
|
|
|
static $url_rule = '/$Action/$ID/$OtherID';
|
|
|
|
|
|
|
|
static $menu_title = 'Security';
|
|
|
|
|
2008-10-08 01:27:07 +02:00
|
|
|
static $tree_class = 'Group';
|
|
|
|
|
|
|
|
static $subitem_class = 'Member';
|
2008-02-25 03:10:37 +01:00
|
|
|
|
|
|
|
static $allowed_actions = array(
|
|
|
|
'addgroup',
|
|
|
|
'addmember',
|
|
|
|
'autocomplete',
|
|
|
|
'getmember',
|
|
|
|
'newmember',
|
|
|
|
'removememberfromgroup',
|
|
|
|
'savemember',
|
2008-08-09 05:54:55 +02:00
|
|
|
'AddRecordForm',
|
|
|
|
'MemberForm'
|
2008-02-25 03:10:37 +01:00
|
|
|
);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
public function init() {
|
|
|
|
parent::init();
|
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/hover.js");
|
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/controls.js");
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
// needed for MemberTableField (Requirements not determined before Ajax-Call)
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TableListField.js");
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TableField.js");
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/ComplexTableField.js");
|
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/MemberTableField.js");
|
|
|
|
Requirements::css(THIRDPARTY_DIR . "/greybox/greybox.css");
|
|
|
|
Requirements::css(SAPPHIRE_DIR . "/css/ComplexTableField.css");
|
2007-09-14 21:40:56 +02:00
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/SecurityAdmin.js");
|
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/SecurityAdmin_left.js");
|
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/SecurityAdmin_right.js");
|
2007-09-14 21:40:56 +02:00
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/greybox/AmiJS.js");
|
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/greybox/greybox.js");
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getEditForm($id) {
|
2008-04-09 13:46:27 +02:00
|
|
|
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
|
2008-04-09 13:34:10 +02:00
|
|
|
if(!$record) return false;
|
|
|
|
|
|
|
|
$fields = $record->getCMSFields();
|
|
|
|
|
|
|
|
$actions = new FieldSet(
|
|
|
|
new FormAction('addmember',_t('SecurityAdmin.ADDMEMBER','Add Member')),
|
|
|
|
new FormAction('save',_t('SecurityAdmin.SAVE','Save'))
|
|
|
|
);
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2008-04-09 13:34:10 +02:00
|
|
|
$form = new Form($this, "EditForm", $fields, $actions);
|
|
|
|
$form->loadDataFrom($record);
|
|
|
|
|
|
|
|
return $form;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function AddRecordForm() {
|
2008-08-10 23:41:10 +02:00
|
|
|
$m = Object::create('MemberTableField',
|
2007-07-19 12:40:05 +02:00
|
|
|
$this,
|
2007-09-14 21:40:56 +02:00
|
|
|
"Members",
|
2007-07-19 12:40:05 +02:00
|
|
|
$this->currentPageID()
|
|
|
|
);
|
|
|
|
return $m->AddRecordForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajax autocompletion
|
|
|
|
*/
|
|
|
|
public function autocomplete() {
|
|
|
|
$fieldName = $this->urlParams['ID'];
|
|
|
|
$fieldVal = $_REQUEST[$fieldName];
|
2008-02-25 03:10:37 +01:00
|
|
|
$result = '';
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2008-10-08 04:00:39 +02:00
|
|
|
$matches = DataObject::get($this->stat('subitem_class'),"$fieldName LIKE '" . addslashes($fieldVal) . "%'");
|
2007-07-19 12:40:05 +02:00
|
|
|
if($matches) {
|
|
|
|
$result .= "<ul>";
|
|
|
|
foreach($matches as $match) {
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$data = $match->FirstName;
|
|
|
|
$data .= ",$match->Surname";
|
|
|
|
$data .= ",$match->Email";
|
|
|
|
$data .= ",$match->Password";
|
|
|
|
$result .= "<li>" . $match->$fieldName . "<span class=\"informal\">($match->FirstName $match->Surname, $match->Email)</span><span class=\"informal data\">$data</span></li>";
|
|
|
|
}
|
|
|
|
$result .= "</ul>";
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getmember() {
|
|
|
|
Session::set('currentMember', $_REQUEST['ID']);
|
|
|
|
SSViewer::setOption('rewriteHashlinks', false);
|
2007-12-18 22:38:01 +01:00
|
|
|
$result = $this->renderWith("LeftAndMain_rightbottom");
|
2007-07-19 12:40:05 +02:00
|
|
|
$parts = split('</?form[^>]*>', $result);
|
|
|
|
echo $parts[1];
|
|
|
|
}
|
2007-09-14 21:40:56 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function MemberForm() {
|
|
|
|
$id = $_REQUEST['ID'] ? $_REQUEST['ID'] : Session::get('currentMember');
|
|
|
|
if($id)
|
|
|
|
return $this->getMemberForm($id);
|
|
|
|
}
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function getMemberForm($id) {
|
2008-11-01 14:55:23 +01:00
|
|
|
if($id && $id != 'new') $record = DataObject::get_by_id("Member",$id);
|
2007-07-19 12:40:05 +02:00
|
|
|
if($record || $id == 'new') {
|
|
|
|
$fields = new FieldSet(
|
|
|
|
new HiddenField('MemberListBaseGroup', '', $this->currentPageID() )
|
|
|
|
);
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if( $extraFields = $record->getCMSFields() )
|
|
|
|
foreach( $extraFields as $extra )
|
|
|
|
$fields->push( $extra );
|
|
|
|
|
|
|
|
$fields->push($idField = new HiddenField("ID"));
|
|
|
|
$fields->push($groupIDField = new HiddenField("GroupID"));
|
|
|
|
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$actions = new FieldSet();
|
2007-09-16 18:33:05 +02:00
|
|
|
$actions->push(new FormAction('savemember',_t('SecurityAdmin.SAVE')));
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$form = new Form($this, "MemberForm", $fields, $actions);
|
|
|
|
if($record) $form->loadDataFrom($record);
|
|
|
|
|
|
|
|
$idField->setValue($id);
|
|
|
|
$groupIDField->setValue($this->currentPageID());
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
function savemember() {
|
|
|
|
$data = $_REQUEST;
|
2007-09-14 21:40: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:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if($id) {
|
|
|
|
$record = DataObject::get_one($className, "`$className`.ID = $id");
|
|
|
|
} else {
|
|
|
|
$record = new $className();
|
|
|
|
}
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$record->update($data);
|
|
|
|
$record->ID = $id;
|
|
|
|
$record->write();
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$record->Groups()->add($data['GroupID']);
|
|
|
|
|
|
|
|
|
|
|
|
FormResponse::add("reloadMemberTableField();");
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
|
|
|
|
|
|
|
function addmember($className=null) {
|
|
|
|
$data = $_REQUEST;
|
|
|
|
unset($data['ID']);
|
2007-09-14 21:40:56 +02:00
|
|
|
if($className == null)
|
2007-07-19 12:40:05 +02:00
|
|
|
$className = $this->stat('subitem_class');
|
|
|
|
$record = new $className();
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
$record->update($data);
|
|
|
|
$record->write();
|
|
|
|
if($data['GroupID'])
|
2007-09-14 21:40:56 +02:00
|
|
|
$record->Groups()->add($data['GroupID']);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
FormResponse::add("reloadMemberTableField();");
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function removememberfromgroup() {
|
|
|
|
$groupID = $this->urlParams['ID'];
|
|
|
|
$memberID = $this->urlParams['OtherID'];
|
|
|
|
if(is_numeric($groupID) && is_numeric($memberID)) {
|
|
|
|
$member = DataObject::get_by_id('Member', $memberID);
|
|
|
|
$member->Groups()->remove($groupID);
|
|
|
|
FormResponse::add("reloadMemberTableField();");
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
} else {
|
|
|
|
user_error("SecurityAdmin::removememberfromgroup: Bad parameters: Group=$groupID, Member=$memberID", E_USER_ERROR);
|
|
|
|
}
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
/**
|
|
|
|
* Return the entire site tree as a nested set of ULs
|
|
|
|
*/
|
|
|
|
public function SiteTreeAsUL() {
|
2008-04-09 13:46:27 +02:00
|
|
|
$obj = singleton($this->stat('tree_class'));
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
// getChildrenAsUL is a flexible and complex way of traversing the tree
|
2008-10-31 03:45:19 +01:00
|
|
|
$siteTreeItem = $obj->getChildrenAsUL("",
|
2007-07-19 12:40:05 +02:00
|
|
|
' "<li id=\"record-$child->ID\" class=\"$child->class " . ($child->Locked ? " nodelete" : "") . ' .
|
2007-09-14 21:40:56 +02:00
|
|
|
' ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' .
|
2008-10-08 00:59:47 +02:00
|
|
|
' "<a href=\"admin/security/show/$child->ID\" >" . $child->TreeTitle() . "</a>" ',$this);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
$siteTree = "<ul id=\"sitetree\" class=\"tree unformatted\">" .
|
|
|
|
"<li id=\"record-0\" class=\"Root\">" .
|
2007-11-02 02:12:31 +01:00
|
|
|
"<a href=\"admin/security/show/0\" ><strong>"._t('SecurityAdmin.SGROUPS',"Security groups")."</strong></a>"
|
2008-10-31 03:45:19 +01:00
|
|
|
. $siteTreeItem .
|
2007-07-19 12:40:05 +02:00
|
|
|
"</li>" .
|
|
|
|
"</ul>";
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
return $siteTree;
|
|
|
|
|
|
|
|
}
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function addgroup() {
|
2008-04-09 13:46:27 +02:00
|
|
|
$newGroup = Object::create($this->stat('tree_class'));
|
|
|
|
$newGroup->Title = _t('SecurityAdmin.NEWGROUP',"New Group");
|
|
|
|
$newGroup->Code = "new-group";
|
|
|
|
$newGroup->ParentID = (is_numeric($_REQUEST['ParentID'])) ? (int)$_REQUEST['ParentID'] : 0;
|
|
|
|
$newGroup->write();
|
|
|
|
|
|
|
|
return $this->returnItemToUser($newGroup);
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
public function newmember() {
|
|
|
|
Session::clear('currentMember');
|
|
|
|
$newMemberForm = array(
|
|
|
|
"MemberForm" => $this->getMemberForm('new'),
|
|
|
|
);
|
|
|
|
// This should be using FormResponse ;-)
|
|
|
|
if(Director::is_ajax()) {
|
|
|
|
SSViewer::setOption('rewriteHashlinks', false);
|
2007-09-14 21:40: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);
|
|
|
|
return $parts[1];
|
2007-09-14 21:40:56 +02:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
} else {
|
|
|
|
return $newMemberForm;
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 21:40: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:40:56 +02:00
|
|
|
|
2008-11-02 22:27:55 +01:00
|
|
|
public function getMenuTitle() {
|
|
|
|
return _t('LeftAndMain.SECURITY', 'Security', PR_HIGH, 'Menu title');
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-08-31 02:31:49 +02:00
|
|
|
|
|
|
|
function providePermissions() {
|
|
|
|
return array(
|
2008-04-26 08:27:53 +02:00
|
|
|
'EDIT_PERMISSIONS' => _t('SecurityAdmin.EDITPERMISSIONS', 'Edit permissions and IP addresses on each group'),
|
2007-08-31 02:31:49 +02:00
|
|
|
);
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
2007-11-15 23:42:22 +01:00
|
|
|
?>
|