Actions()->insertBefore( new FormAction('addmember',_t('SecurityAdmin.ADDMEMBER','Add Member')), 'action_save' ); return $form; } /** * @return Form */ function AddForm() { $class = $this->stat('tree_class'); $typeMap = array('Folder' => singleton($class)->i18n_singular_name()); $typeField = new DropdownField('Type', false, $typeMap, 'Folder'); $form = new Form( $this, 'AddForm', new FieldSet( new HiddenField('ParentID'), $typeField->performReadonlyTransformation() ), new FieldSet( new FormAction('doAdd', _t('AssetAdmin_left.ss.GO','Go')) ) ); $form->setValidator(null); $form->addExtraClass('actionparams'); return $form; } /** * Add a new group and return its details suitable for ajax. */ public function doAdd($data, $form) { $parentID = (isset($data['ParentID']) && is_numeric($data['ParentID'])) ? (int)$data['ParentID'] : 0; if(!singleton($this->stat('tree_class'))->canCreate()) return Security::permissionFailure($this); $record = Object::create($this->stat('tree_class')); $record->Title = _t('SecurityAdmin.NEWGROUP',"New Group"); $record->ParentID = $parentID; $record->write(); $form = $this->getEditForm($record->ID); return $form->formHtmlContent(); } public function AddRecordForm() { $m = Object::create('MemberTableField', $this, "Members", $this->currentPageID() ); return $m->AddRecordForm(); } /** * Ajax autocompletion */ public function autocomplete() { $fieldName = $this->urlParams['ID']; $fieldVal = $_REQUEST[$fieldName]; $result = ''; // Make sure we only autocomplete on keys that actually exist, and that we don't autocomplete on password if(!singleton($this->stat('subitem_class'))->hasDatabaseField($fieldName) || $fieldName == 'Password') return; $matches = DataObject::get($this->stat('subitem_class'),"\"$fieldName\" LIKE '" . Convert::raw2sql($fieldVal) . "%'"); if($matches) { $result .= ""; return $result; } } public function MemberForm() { $id = $_REQUEST['ID'] ? $_REQUEST['ID'] : Session::get('currentMember'); if($id) return $this->getMemberForm($id); } public function getMemberForm($id) { if($id && $id != 'new') $record = DataObject::get_by_id('Member', (int) $id); if($record || $id == 'new') { $fields = new FieldSet( new HiddenField('MemberListBaseGroup', '', $this->currentPageID() ) ); if($extraFields = $record->getCMSFields()) { foreach($extraFields as $extra) { $fields->push( $extra ); } } $fields->push($idField = new HiddenField('ID')); $fields->push($groupIDField = new HiddenField('GroupID')); $actions = new FieldSet(); $actions->push(new FormAction('savemember', _t('SecurityAdmin.SAVE'))); $form = new Form($this, 'MemberForm', $fields, $actions); if($record) $form->loadDataFrom($record); $idField->setValue($id); $groupIDField->setValue($this->currentPageID()); if($record && !$record->canEdit()) { $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); } return $form; } } function savemember() { $data = $_REQUEST; $className = $this->stat('subitem_class'); $id = $_REQUEST['ID']; if($id == 'new') $id = null; if($id) { $record = DataObject::get_by_id($className, $id); if($record && !$record->canEdit()) return Security::permissionFailure($this); } else { if(!singleton($this->stat('subitem_class'))->canCreate()) return Security::permissionFailure($this); $record = new $className(); } $record->update($data); $record->ID = $id; $record->write(); $record->Groups()->add($data['GroupID']); FormResponse::add("reloadMemberTableField();"); return FormResponse::respond(); } function addmember($className=null) { $data = $_REQUEST; unset($data['ID']); if($className == null) $className = $this->stat('subitem_class'); if(!singleton($this->stat('subitem_class'))->canCreate()) return Security::permissionFailure($this); $record = new $className(); $record->update($data); $record->write(); if($data['GroupID']) $record->Groups()->add((int)$data['GroupID']); FormResponse::add("reloadMemberTableField();"); return FormResponse::respond(); } public function removememberfromgroup() { $groupID = $this->urlParams['ID']; $memberID = $this->urlParams['OtherID']; if(is_numeric($groupID) && is_numeric($memberID)) { $member = DataObject::get_by_id('Member', (int) $memberID); if(!$member->canDelete()) return Security::permissionFailure($this); $member->Groups()->remove((int)$groupID); FormResponse::add("reloadMemberTableField();"); } else { user_error("SecurityAdmin::removememberfromgroup: Bad parameters: Group=$groupID, Member=$memberID", E_USER_ERROR); } return FormResponse::respond(); } /** * Delete a number of items */ public function deleteitems() { $ids = split(' *, *', $_REQUEST['csvIDs']); $script = "st = \$('sitetree'); \n"; foreach($ids as $id) { if(is_numeric($id)) { $record = DataObject::get_by_id($this->stat('tree_class'), $id); if($record && !$record->canDelete()) return Security::permissionFailure($this); DataObject::delete_by_id($this->stat('tree_class'), $id); $script .= "node = st.getTreeNodeByIdx($id); if(node) node.parentTreeNode.removeTreeNode(node); $('Form_EditForm').closeIfSetTo($id); \n"; } } FormResponse::add($script); return FormResponse::respond(); } /** * Return the entire site tree as a nested set of ULs. * @return string Unordered list