00001 <?php
00002
00015 import('lib.pkp.classes.form.Form');
00016
00017 class UserForm extends Form {
00018
00020 var $userId;
00021
00028 function UserForm($template, $userId = null) {
00029 parent::Form($template);
00030
00031 $this->userId = isset($userId) ? (int) $userId : null;
00032
00033 if (!is_null($userId)) {
00034 $this->addCheck(new FormValidatorListBuilder($this, 'roles', 'manager.users.roleRequired'));
00035 }
00036 }
00037
00041 function readInputData() {
00042 $this->readUserVars(array('roles'));
00043 }
00044
00048 function execute($request) {
00049 ListbuilderHandler::unpack($request, $this->getData('roles'));
00050 }
00051
00056 function insertEntry(&$request, $newRowId) {
00057 $press =& $request->getPress();
00058 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00059
00060 $userGroupId = (int) $newRowId['name'];
00061 $userId = (int) $this->userId;
00062
00063
00064
00065
00066
00067 if (
00068 empty($userGroupId) ||
00069 !$userGroupDao->contextHasGroup($press->getId(), $userGroupId) ||
00070 $userGroupDao->userInGroup($userId, $userGroupId)
00071 ) {
00072 return false;
00073 } else {
00074
00075 $userGroupDao->assignUserToGroup($userId, $userGroupId);
00076 }
00077
00078 return true;
00079 }
00080
00085 function deleteEntry(&$request, $rowId) {
00086 $userGroupId = (int) $rowId;
00087 $userId = (int) $this->userId;
00088
00089 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00090 $press =& $request->getPress();
00091
00092 $userGroupDao->removeUserFromGroup(
00093 $userId,
00094 (int) $userGroupId,
00095 $press->getId()
00096 );
00097
00098 return true;
00099 }
00100
00101 }
00102
00103 ?>