From: Bharat M. <bh...@us...> - 2002-10-16 06:27:44
|
Update of /cvsroot/gallery/gallery2/modules/core In directory usw-pr-cvs1:/tmp/cvs-serv19811 Modified Files: AdminCreateUser.inc AdminDeleteUser.inc AdminEditUser.inc AdminModules.inc AdminUsers.inc Added Files: AdminCreateGroup.inc AdminCreateGroupConfirmation.inc AdminDeleteGroup.inc AdminDeleteGroupConfirmation.inc AdminEditGroup.inc AdminEditGroupConfirmation.inc AdminEditGroupUsers.inc AdminGroups.inc Log Message: User administration is functionally complete. You can add and delete users, add and delete groups, and add/remove users from groups. --- NEW FILE --- <?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2002 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class AdminCreateGroupController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $results = array(); $redirectParams = array(); $form = GalleryUtilities::getFormVariables('form.'); if (isset($form['action']['cancel'])) { /* Go back to the AdminGroups view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminGroups'); } else if (isset($form['action']['create'])) { /* * If all the right fields are in place then go ahead and * create the group. */ if (!empty($form['groupName'])) { list ($ret, $group) = $gallery->newEntity('GalleryGroup'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $ret = $group->create($form['groupName']); if ($ret->isError()) { if ($ret->getErrorCode() & ERROR_COLLISION) { /* * Fall through -- the view will let the group know about * the duplication. */ } else { return array($ret->wrap(__FILE__, __LINE__), null); } } else { $ret = $group->save(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Request a redirect to the confirmation screen */ $redirectParams['view'] = 'core:SiteAdmin'; $redirectParams['subView'] = 'core:AdminCreateGroupConfirmation'; $redirectParams['groupName'] = $form['groupName']; } } } if (!empty($redirectParams)) { $templateAdapter = $gallery->getTemplateAdapter(); $results['redirect'] = $templateAdapter->url($redirectParams); } else { if (empty($results['view'])) { $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminCreateGroup'); } } return array(GalleryStatus::success(), $results); } } class AdminCreateGroupView extends GalleryView { /** * @see GalleryView::renderBody */ function renderBody() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $formName = GalleryUtilities::getRequestVariables('formName'); $form = GalleryUtilities::getFormVariables('form.'); if ($formName == 'AdminCreateGroup') { if (empty($form['groupName'])) { $form['error']['groupName']['missing'] = 1; } if (!empty($form['groupName'])) { list ($ret, $group) = GalleryGroupHelper::fetchGroupByGroupname($form['groupName']); if ($ret->isError()) { if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { /* We're good -- no use by that name */ } else { return array($ret->wrap(__FILE__, __LINE__), null); } } else { /* A group exists by that name */ $form['error']['groupName']['exists'] = 1; } } } else { /* * Otherwise we just arrived at this page the first time so set * defaults */ $form['groupName'] = ''; } /* Render the HTML body */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->assign('form', $form); $smarty->assign('controller', 'core:AdminCreateGroup'); $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('AdminCreateGroup.tpl'); return array(GalleryStatus::success(), $html); } } ?> --- NEW FILE --- <?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2002 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class AdminCreateGroupConfirmationView extends GalleryView { /** * @see GalleryView::renderBody */ function renderBody() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $groupName = GalleryUtilities::getRequestVariables('groupName'); /* Render the HTML body */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->assign('groupName', $groupName); $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('AdminCreateGroupConfirmation.tpl'); return array(GalleryStatus::success(), $html); } } ?> --- NEW FILE --- <?php /* * Gallery - a web based photo album viewer and deleteor * Copyright (C) 2000-2002 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class AdminDeleteGroupController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $results = array(); $redirectParams = array(); $groupId = GalleryUtilities::getRequestVariables('groupId'); $form = GalleryUtilities::getFormVariables('form.'); if (isset($form['action']['cancel'])) { /* Go back to the AdminGroups view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminGroups'); } else if (isset($form['action']['delete'])) { /* * Check to see if we're trying to delete the anonymous group, or * ourself (can't do either of those). */ list ($ret, $group) = $gallery->loadEntitiesById($groupId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } if ($group->getGroupType() == GROUP_NORMAL) { /* Delete the group */ list ($ret, $lockId) = $gallery->acquireWriteLock($groupId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $ret = $group->delete(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $ret = $gallery->releaseLocks($lockId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Request a redirect to the confirmation screen */ $redirectParams['view'] = 'core:SiteAdmin'; $redirectParams['subView'] = 'core:AdminDeleteGroupConfirmation'; $redirectParams['groupName'] = $group->getGroupName(); } } if (!empty($redirectParams)) { $templateAdapter = $gallery->getTemplateAdapter(); $results['redirect'] = $templateAdapter->url($redirectParams); } else { if (empty($results['view'])) { $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminDeleteGroup'); } } return array(GalleryStatus::success(), $results); } } class AdminDeleteGroupView extends GalleryView { /** * @see GalleryView::renderBody */ function renderBody() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $groupId = GalleryUtilities::getRequestVariables('groupId'); /* * Check to see if we're trying to delete the anonymous group, or * ourself (can't do either of those). */ list ($ret, $group) = $gallery->loadEntitiesById($groupId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $isAllUsers = ($group->getGroupType() == GROUP_ALL_USERS); $isAllAdmins = ($group->getGroupType() == GROUP_ALL_ADMINS); /* Render the HTML body */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->assign('groupId', $groupId); $smarty->assign('groupName', $group->getGroupName()); $smarty->assign('isAllUsers', $isAllUsers); $smarty->assign('isAllAdmins', $isAllAdmins); $smarty->assign('controller', 'core:AdminDeleteGroup'); $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('AdminDeleteGroup.tpl'); return array(GalleryStatus::success(), $html); } } ?> --- NEW FILE --- <?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2002 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class AdminDeleteGroupConfirmationView extends GalleryView { /** * @see GalleryView::renderBody */ function renderBody() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $groupName = GalleryUtilities::getRequestVariables('groupName'); /* Render the HTML body */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->assign('groupName', $groupName); $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('AdminDeleteGroupConfirmation.tpl'); return array(GalleryStatus::success(), $html); } } ?> --- NEW FILE --- <?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2002 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class AdminEditGroupController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $results = array(); $redirectParams = array(); $formName = GalleryUtilities::getRequestVariables('formName'); $form = GalleryUtilities::getFormVariables('form.'); list ($ret, $group) = $gallery->loadEntitiesById($form['groupId']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } if (isset($form['action']['cancel'])) { /* Go back to the AdminGroups view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminGroups'); } else if (isset($form['action']['undo'])) { /* Reset our form */ GalleryUtilities::putRequestVariable('form.groupName', $group->getGroupName()); } else if (isset($form['action']['save'])) { if (!empty($form['groupName'])) { /* Save our changes */ list ($ret, $lockId) = $gallery->acquireWriteLock($form['groupId']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Refresh our object, now that it's locked */ $ret = $group->refresh(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $group->setGroupName($form['groupName']); $ret = $group->save(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $ret = $gallery->releaseLocks($lockId); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Request a redirect to the confirmation screen */ $redirectParams['view'] = 'core:SiteAdmin'; $redirectParams['subView'] = 'core:AdminEditGroupConfirmation'; $redirectParams['groupName'] = $form['groupName']; } } if (!empty($redirectParams)) { $templateAdapter = $gallery->getTemplateAdapter(); $results['redirect'] = $templateAdapter->url($redirectParams); } else { if (empty($results['view'])) { $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminEditGroup'); } } return array(GalleryStatus::success(), $results); } } class AdminEditGroupView extends GalleryView { /** * @see GalleryView::renderBody */ function renderBody() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $groupid = GalleryUtilities::getRequestVariables('groupId'); $form = GalleryUtilities::getFormVariables('form.'); if (!empty($groupid)) { $form['groupId'] = $groupid; } list ($ret, $group) = $gallery->loadEntitiesById($form['groupId']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Load the form with group data */ if (empty($form['groupName'])) { $form['groupName'] = $group->getGroupName(); } if (empty($form['groupType'])) { $form['groupType'] = $group->getGroupType(); } /* Render the HTML body */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->assign('form', $form); $smarty->assign('controller', 'core:AdminEditGroup'); $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('AdminEditGroup.tpl'); return array(GalleryStatus::success(), $html); } } ?> --- NEW FILE --- <?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2002 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class AdminEditGroupConfirmationView extends GalleryView { /** * @see GalleryView::renderBody */ function renderBody() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $groupName = GalleryUtilities::getRequestVariables('groupName'); /* Render the HTML body */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->assign('groupName', $groupName); $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('AdminEditGroupConfirmation.tpl'); return array(GalleryStatus::success(), $html); } } ?> --- NEW FILE --- <?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2002 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class AdminEditGroupUsersController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $results = array(); $redirectParams = array(); $formName = GalleryUtilities::getRequestVariables('formName'); $form = GalleryUtilities::getFormVariables('form.'); list ($ret, $group) = $gallery->loadEntitiesById($form['groupId']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } if (isset($form['action']['done'])) { /* Go back to the AdminGroups view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminGroups'); } else if (isset($form['action']['remove'])) { /* Remove the user from the group */ if (!empty($form['list']['userId'])) { list ($ret, $user) = $gallery->loadEntitiesById($form['list']['userId']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } if ($ret->isError()) { if (!($ret->getErrorCode() & ERROR_MISSING_OBJECT)) { return array($ret->wrap(__FILE__, __LINE__), null); } } else { $ret = GalleryUserGroupMap::removeUserFromGroup($user->getId(), $form['groupId']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Request a redirect back to this page */ $redirectParams['view'] = 'core:SiteAdmin'; $redirectParams['subView'] = 'core:AdminEditGroupUsers'; $redirectParams['groupId'] = $group->getId(); $redirectParams['userRemoved'] = $user->getUsername(); } } } else if (isset($form['action']['add'])) { /* Remove the user from the group */ if (!empty($form['text']['userName'])) { list ($ret, $user) = GalleryUserHelper::fetchUserByUsername($form['text']['userName']); if ($ret->isError()) { if (!($ret->getErrorCode() & ERROR_MISSING_OBJECT)) { return array($ret->wrap(__FILE__, __LINE__), null); } } else { $ret = GalleryUserGroupMap::addUserToGroup($user->getId(), $form['groupId']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Request a redirect back to this page */ $redirectParams['view'] = 'core:SiteAdmin'; $redirectParams['subView'] = 'core:AdminEditGroupUsers'; $redirectParams['groupId'] = $group->getId(); $redirectParams['userAdded'] = $user->getUsername(); } } } if (!empty($redirectParams)) { $templateAdapter = $gallery->getTemplateAdapter(); $results['redirect'] = $templateAdapter->url($redirectParams); } else { if (empty($results['view'])) { $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminEditGroupUsers'); } } return array(GalleryStatus::success(), $results); } } class AdminEditGroupUsersView extends GalleryView { /** * @see GalleryView::renderBody */ function renderBody() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $userAdded = GalleryUtilities::getRequestVariables('userAdded'); $userRemoved = GalleryUtilities::getRequestVariables('userRemoved'); $groupId = GalleryUtilities::getRequestVariables('groupId'); $formName = GalleryUtilities::getRequestVariables('formName'); $form = GalleryUtilities::getFormVariables('form.'); if (!empty($groupId)) { $form['groupId'] = $groupId; } list ($ret, $userIds) = GalleryUserGroupMap::fetchUsersForGroup($form['groupId']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Load the group */ list ($ret, $group) = $gallery->loadEntitiesById($form['groupId']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Load the form with group data */ if (empty($form['groupName'])) { $form['groupName'] = $group->getGroupName(); } /* * If the last form submitted wasn't our form, then we don't expect the * form data to line up (ie, this is the first time we've been on this * view */ if ($formName != 'AdminEditGroupUsers') { $form['text']['userName'] = ''; } else { /* * But if it does match, then we should audit the form data. */ if (empty($form['text']['userName'])) { $form['error']['text']['missingUserName'] = 1; } else { list ($ret, $user) = GalleryUserHelper::fetchUserByUsername($form['text']['userName']); if ($ret->isError()) { if ($ret->getErrorCode() & ERROR_OBJECT_MISSING) { $form['error']['noSuchUser'] = 1; } else { return array($ret->wrap(__FILE__, __LINE__), null); } } } } list ($ret, $users) = GalleryUserGroupMap::fetchUsersForGroup($group->getId()); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $userCount = sizeof($users); $form['list']['users'] = $users; /* Render the HTML body */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->assign('form', $form); $smarty->assign('userCount', $userCount); $smarty->assign('userAdded', $userAdded); $smarty->assign('userRemoved', $userRemoved); $smarty->assign('controller', 'core:AdminEditGroupUsers'); $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('AdminEditGroupUsers.tpl'); return array(GalleryStatus::success(), $html); } } ?> --- NEW FILE --- <?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2002 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class AdminGroupsController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $results = array(); $form = GalleryUtilities::getFormVariables('form.'); $group = null; if (!empty($form['text']['groupName'])) { list ($ret, $group) = GalleryGroupHelper::fetchGroupByGroupName($form['text']['groupName']); if ($ret->isError()) { if (!($ret->getErrorCode() & ERROR_MISSING_OBJECT)) { return array($ret->wrap(__FILE__, __LINE__), null); } } } if (isset($form['action']['firstPage'])) { /* Go to the first page */ $form['list']['page'] = 1; } else if (isset($form['action']['backPage'])) { /* Go back a page */ $form['list']['page'] = max(0, $form['list']['page']-1); } else if (isset($form['action']['nextPage'])) { /* Go forward a page */ $form['list']['page'] = min($form['list']['page']+1, $form['list']['maxPages']); } else if (isset($form['action']['lastPage'])) { /* Go to the last page */ $form['list']['page'] = $form['list']['maxPages']; } else if (isset($form['action']['filterClear'])) { /* Clear the filter */ GalleryUtilities::putRequestVariable('form.list.filter', null); } else if (isset($form['action']['create'])) { /* Show the "create group" view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminCreateGroup'); } else if (isset($form['action']['editFromList'])) { if (empty($form['list']['groupId'])) { GalleryUtilities::putRequestVariable('form.error.list.noGroupSelected', 1); } else { /* Show the "edit group" view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminEditGroup'); GalleryUtilities::putRequestVariable('groupId', $form['list']['groupId']); } } else if (isset($form['action']['addRemoveUsersFromList'])) { if (empty($form['list']['groupId'])) { GalleryUtilities::putRequestVariable('form.error.list.noGroupSelected', 1); } else { /* Show the "edit group" view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminEditGroupUsers'); GalleryUtilities::putRequestVariable('groupId', $form['list']['groupId']); } } else if (isset($form['action']['deleteFromList'])) { if (empty($form['list']['groupId'])) { GalleryUtilities::putRequestVariable('form.error.list.noGroupSelected', 1); } else { /* Show the "delete group" view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('groupId', $form['list']['groupId']); GalleryUtilities::putRequestVariable('subView', 'core:AdminDeleteGroup'); } } else if (isset($form['action']['editFromText'])) { if (empty($form['text']['groupName'])) { GalleryUtilities::putRequestVariable('form.error.text.noGroupSpecified', 1); } else if ($group == null) { GalleryUtilities::putRequestVariable('form.error.text.noSuchGroup', 1); } else { /* Show the "delete group" view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('groupId', $group->getId()); GalleryUtilities::putRequestVariable('subView', 'core:AdminEditGroup'); } } else if (isset($form['action']['deleteFromText'])) { if (empty($form['text']['groupName'])) { GalleryUtilities::putRequestVariable('form.error.text.noGroupSpecified', 1); } else if ($group == null) { GalleryUtilities::putRequestVariable('form.error.text.noSuchGroup', 1); } else { /* Show the "delete group" view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminDeleteGroup'); GalleryUtilities::putRequestVariable('groupId', $group->getId()); } } else if (isset($form['action']['addRemoveUsersFromText'])) { if (empty($form['text']['groupName'])) { GalleryUtilities::putRequestVariable('form.error.text.noGroupSpecified', 1); } else if ($group == null) { GalleryUtilities::putRequestVariable('form.error.text.noSuchGroup', 1); } else { /* Show the "edit group's users" view */ $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminEditGroupUsers'); GalleryUtilities::putRequestVariable('groupId', $group->getId()); } } if (empty($results['view'])) { /* * We're staying on the same page, so pass on our navigation * parameters. */ GalleryUtilities::putRequestVariable('form.list.page', $form['list']['page']); $results['view'] = 'core:SiteAdmin'; GalleryUtilities::putRequestVariable('subView', 'core:AdminGroups'); } return array(GalleryStatus::success(), $results); } } class AdminGroupsView extends GalleryView { /** * @see GalleryView::renderBody */ function renderBody() { global $gallery; $ret = $this->_assertSiteAdministrator(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Specify our translation module */ $ret = $this->_setTranslationModule('core'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Load some standard form parameters */ $form = GalleryUtilities::getFormVariables('form.'); /* Set some defaults, if necessary */ if (!isset($form['list']['filter'])) { $form['list']['filter'] = ''; } if (empty($form['list']['page'])) { $form['list']['page'] = 1; } if (empty($form['text']['groupName'])) { $form['text']['groupName'] = ''; } list ($ret, $totalGroupCount) = GalleryGroupHelper::fetchGroupCount(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $form['list']['count'] = $totalGroupCount; $form['list']['pageSize'] = 15; /* If we have a filter, find out how many groups match it */ if (!empty($form['list']['filter'])) { list ($ret, $form['list']['count']) = GalleryGroupHelper::fetchGroupCount($form['list']['filter']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } } /* Figure out our max pages, make sure our current page fits in it */ $form['list']['maxPages'] = ceil($form['list']['count'] / $form['list']['pageSize']); if ($form['list']['page'] > $form['list']['maxPages']) { $form['list']['page'] = $form['list']['maxPages']; } list ($ret, $form['list']['groupNames']) = GalleryGroupHelper::fetchGroupNames($form['list']['pageSize'], (($form['list']['page'] - 1) * $form['list']['pageSize']), $form['list']['filter']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } /* Render the HTML body */ list ($ret, $smarty) = $gallery->getSmarty(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $smarty->assign('form', $form); $smarty->assign('totalGroupCount', $totalGroupCount); $smarty->assign('controller', 'core:AdminGroups'); $smarty->template_dir = dirname(__FILE__) . '/templates'; $html = $smarty->fetch('AdminGroups.tpl'); return array(GalleryStatus::success(), $html); } } ?> Index: AdminCreateUser.inc =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/AdminCreateUser.inc,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AdminCreateUser.inc 13 Oct 2002 06:33:27 -0000 1.3 +++ AdminCreateUser.inc 16 Oct 2002 06:27:40 -0000 1.4 @@ -33,8 +33,8 @@ $results = array(); $redirectParams = array(); - $form = GalleryUtilities::getFormVariables('form'); - + $form = GalleryUtilities::getFormVariables('form.'); + if (isset($form['action']['cancel'])) { /* Go back to the AdminUsers view */ @@ -118,25 +118,12 @@ return array($ret->wrap(__FILE__, __LINE__), null); } - $form = GalleryUtilities::getFormVariables('form'); + $formName = GalleryUtilities::getRequestVariables('formName'); + $form = GalleryUtilities::getFormVariables('form.'); - if (empty($form['username']) && - empty($form['fullname']) && - empty($form['email']) && - empty($form['language']) && - empty($form['password1']) && - empty($form['password2'])) { - + if ($formName == 'AdminCreateUser') { /* - * Nothing posted -- set our defaults here. - */ - $form['username'] = ''; - $form['email'] = ''; - $form['fullname'] = ''; - $form['language'] = ''; - } else { - /* - * The form was posted unsuccessfully, so audit the inputs here + * Our form was posted. Audit the inputs. */ $errors = array(); foreach (array('username', 'email', 'password1', 'password2') as $key) { @@ -164,6 +151,12 @@ $form['error']['password2']['mismatch'] = 1; } } + } else { + /* First time around, set our defaults here. */ + $form['username'] = ''; + $form['email'] = ''; + $form['fullname'] = ''; + $form['language'] = ''; } /* Set up our language selection list */ Index: AdminDeleteUser.inc =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/AdminDeleteUser.inc,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AdminDeleteUser.inc 13 Oct 2002 07:46:05 -0000 1.2 +++ AdminDeleteUser.inc 16 Oct 2002 06:27:41 -0000 1.3 @@ -33,8 +33,8 @@ $results = array(); $redirectParams = array(); - $username = GalleryUtilities::getRequestVariables('username'); - $form = GalleryUtilities::getFormVariables('form'); + $userid = GalleryUtilities::getRequestVariables('userid'); + $form = GalleryUtilities::getFormVariables('form.'); if (isset($form['action']['cancel'])) { @@ -48,7 +48,7 @@ * Check to see if we're trying to delete the anonymous user, or * ourself (can't do either of those). */ - list ($ret, $user) = GalleryUserHelper::fetchUserByUsername($username); + list ($ret, $user) = $gallery->loadEntitiesById($userid); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } @@ -58,12 +58,12 @@ if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } - $isAnonymous = ($user->getId() == $anonymousUserId); - $isSelf = ($user->getId() == $gallery->getActiveUserId()); + $isAnonymous = ($userid == $anonymousUserId); + $isSelf = ($userid == $gallery->getActiveUserId()); if (!$isAnonymous && !$isSelf) { /* Delete the user */ - list ($ret, $lockId) = $gallery->acquireWriteLock($user->getId()); + list ($ret, $lockId) = $gallery->acquireWriteLock($userid); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } @@ -81,7 +81,7 @@ /* Request a redirect to the confirmation screen */ $redirectParams['view'] = 'core:SiteAdmin'; $redirectParams['subView'] = 'core:AdminDeleteUserConfirmation'; - $redirectParams['username'] = $username; + $redirectParams['username'] = $user->getUsername(); } } @@ -143,6 +143,7 @@ if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } + $smarty->assign('userid', $userid); $smarty->assign('username', $user->getUserName()); $smarty->assign('isSelf', $isSelf); $smarty->assign('isAnonymous', $isAnonymous); Index: AdminEditUser.inc =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/AdminEditUser.inc,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AdminEditUser.inc 13 Oct 2002 07:46:05 -0000 1.3 +++ AdminEditUser.inc 16 Oct 2002 06:27:41 -0000 1.4 @@ -33,9 +33,9 @@ $results = array(); $redirectParams = array(); - $form = GalleryUtilities::getFormVariables('form'); + $form = GalleryUtilities::getFormVariables('form.'); - list ($ret, $user) = GalleryUserHelper::fetchUserByUsername($form['username']); + list ($ret, $user) = $gallery->loadEntitiesById($form['userid']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } @@ -49,12 +49,7 @@ if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } - - if ($user->getId() == $anonymousUserId) { - $isAnonymous = true; - } else { - $isAnonymous = false; - } + $isAnonymous = ($form['userid'] == $anonymousUserId); if (isset($form['action']['cancel'])) { @@ -145,83 +140,74 @@ return array($ret->wrap(__FILE__, __LINE__), null); } - $userid = GalleryUtilities::getRequestVariables('userid'); - $form = GalleryUtilities::getFormVariables('form'); + list ($userid, $formName) = + GalleryUtilities::getRequestVariables('userid', 'formName'); + $form = GalleryUtilities::getFormVariables('form.'); /* The 'userid' variable is set the first time we come to this page */ - $firstTime = false; if (!empty($userid)) { $form['userid'] = $userid; - $firstTime = true; } - /* Get our smarty instance */ - list ($ret, $smarty) = $gallery->getSmarty(); + list ($ret, $user) = $gallery->loadEntitiesById($form['userid']); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } - $smarty->template_dir = dirname(__FILE__) . '/templates'; - - list ($ret, $user) = $gallery->loadEntitiesById($form['userid']); + + /* Email is not required for the anonymous user */ + list ($ret, $anonymousUserId) = + $gallery->getModuleParameter('core', 'id.anonymousUser'); if ($ret->isError()) { - if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { - $html = $smarty->fetch('AdminEditUserMissing.tpl'); - } else { - return array($ret->wrap(__FILE__, __LINE__), null); - } - } else { - /* Email is not required for the anonymous user */ - list ($ret, $anonymousUserId) = - $gallery->getModuleParameter('core', 'id.anonymousUser'); - if ($ret->isError()) { - return array($ret->wrap(__FILE__, __LINE__), null); - } - - $isAnonymous = ($form['userid'] == $anonymousUserId); - - if ($firstTime) { - /* First time around, load the form with user data */ - $form['username'] = $user->getUserName(); - $form['fullname'] = $user->getFullName(); - $form['email'] = $user->getEmail(); - $form['language'] = $user->getLanguage(); - } else { - /* After that, complain if any required fields are missing */ - - if (empty($form['email'])) { - if (!$isAnonymous) { - $form['error']['email']['missing'] = 1; - } - } + return array($ret->wrap(__FILE__, __LINE__), null); + } + $isAnonymous = ($form['userid'] == $anonymousUserId); - if ((isset($form['password1']) && !isset($form['password2'])) || - (isset($form['password2']) && !isset($form['password1']))) { - $form['error']['password2']['mismatch'] = 1; + if ($formName == 'AdminEditUser') { + /* Complain if any required fields are missing */ + if (empty($form['email'])) { + if (!$isAnonymous) { + $form['error']['email']['missing'] = 1; } } - - /* Set up our language selection list */ - list ($ret, $translator) = $gallery->getTranslator(); - if ($ret->isError()) { - return array($ret->wrap(__FILE__, __LINE__), null); + + if ((isset($form['password1']) && !isset($form['password2'])) || + (isset($form['password2']) && !isset($form['password1']))) { + $form['error']['password2']['mismatch'] = 1; } - $languageList = array(); - $languageList[''] = '<none>'; - $supportedLanguages = $translator->getSupportedLanguages(); - foreach ($supportedLanguages as $language => $countryList) { - foreach ($countryList as $country => $languageData) { - $languageList[$language . '_' . $country] = - $languageData['description']; - } + } else { + /* First time around, load the form with user data */ + $form['username'] = $user->getUserName(); + $form['fullname'] = $user->getFullName(); + $form['email'] = $user->getEmail(); + $form['language'] = $user->getLanguage(); + } + + /* Set up our language selection list */ + list ($ret, $translator) = $gallery->getTranslator(); + if ($ret->isError()) { + return array($ret->wrap(__FILE__, __LINE__), null); + } + $languageList = array(); + $languageList[''] = '<none>'; + $supportedLanguages = $translator->getSupportedLanguages(); + foreach ($supportedLanguages as $language => $countryList) { + foreach ($countryList as $country => $languageData) { + $languageList[$language . '_' . $country] = + $languageData['description']; } + } - /* Render the HTML body */ - $smarty->assign('form', $form); - $smarty->assign('isAnonymous', $isAnonymous); - $smarty->assign('languageList', $languageList); - $smarty->assign('controller', 'core:AdminEditUser'); - $html = $smarty->fetch('AdminEditUser.tpl'); + /* Render the HTML body */ + list ($ret, $smarty) = $gallery->getSmarty(); + if ($ret->isError()) { + return array($ret->wrap(__FILE__, __LINE__), null); } + $smarty->assign('form', $form); + $smarty->assign('isAnonymous', $isAnonymous); + $smarty->assign('languageList', $languageList); + $smarty->assign('controller', 'core:AdminEditUser'); + $smarty->template_dir = dirname(__FILE__) . '/templates'; + $html = $smarty->fetch('AdminEditUser.tpl'); return array(GalleryStatus::success(), $html); } Index: AdminModules.inc =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/AdminModules.inc,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- AdminModules.inc 7 Oct 2002 21:41:24 -0000 1.6 +++ AdminModules.inc 16 Oct 2002 06:27:41 -0000 1.7 @@ -186,7 +186,6 @@ if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } - $smarty->assign('modules', $modules); $smarty->assign('controller', 'core:AdminModules'); $smarty->template_dir = dirname(__FILE__) . '/templates'; Index: AdminUsers.inc =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/AdminUsers.inc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- AdminUsers.inc 13 Oct 2002 07:46:05 -0000 1.5 +++ AdminUsers.inc 16 Oct 2002 06:27:41 -0000 1.6 @@ -32,7 +32,20 @@ } $results = array(); - $form = GalleryUtilities::getFormVariables('form'); + $form = GalleryUtilities::getFormVariables('form.'); + + if (!empty($form['text']['username'])) { + list ($ret, $user) = + GalleryUserHelper::fetchUserByUsername($form['text']['username']); + if ($ret->isError()) { + if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { + $user = null; + } else { + return array($ret->wrap(__FILE__, __LINE__), null); + } + } + } + if (isset($form['action']['firstPage'])) { /* Go to the first page */ @@ -57,7 +70,7 @@ } else if (isset($form['action']['filterClear'])) { /* Clear the filter */ - $form['list']['filter'] = null; + GalleryUtilities::putRequestVariable('form.list.filter', null); } else if (isset($form['action']['create'])) { @@ -67,21 +80,13 @@ } else if (isset($form['action']['editFromText'])) { - if (!empty($form['text']['username'])) { - list ($ret, $user) = - GalleryUserHelper::fetchUserByUsername($form['text']['username']); - if ($ret->isError()) { - if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { - GalleryUtilities::putRequestVariable('form.error.text.noSuchUser', 1); - } else { - return array($ret->wrap(__FILE__, __LINE__), null); - } - } else { - /* Show the "delete user" view */ - $results['view'] = 'core:SiteAdmin'; - GalleryUtilities::putRequestVariable('userid', $user->getId()); - GalleryUtilities::putRequestVariable('subView', 'core:AdminEditUser'); - } + if ($user == null) { + GalleryUtilities::putRequestVariable('form.error.text.noSuchUser', 1); + } else { + /* Show the "delete user" view */ + $results['view'] = 'core:SiteAdmin'; + GalleryUtilities::putRequestVariable('userid', $user->getId()); + GalleryUtilities::putRequestVariable('subView', 'core:AdminEditUser'); } } else if (isset($form['action']['editFromList'])) { @@ -93,21 +98,13 @@ } else if (isset($form['action']['deleteFromText'])) { - if (!empty($form['text']['username'])) { - list ($ret, $user) = - GalleryUserHelper::fetchUserByUsername($form['text']['username']); - if ($ret->isError()) { - if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { - GalleryUtilities::putRequestVariable('form.error.text.noSuchUser', 1); - } else { - return array($ret->wrap(__FILE__, __LINE__), null); - } - } else { - /* Show the "delete user" view */ - $results['view'] = 'core:SiteAdmin'; - GalleryUtilities::putRequestVariable('subView', 'core:AdminDeleteUser'); - GalleryUtilities::putRequestVariable('userid', $user->getId()); - } + if ($user == null) { + GalleryUtilities::putRequestVariable('form.error.text.noSuchUser', 1); + } else { + /* Show the "delete user" view */ + $results['view'] = 'core:SiteAdmin'; + GalleryUtilities::putRequestVariable('subView', 'core:AdminDeleteUser'); + GalleryUtilities::putRequestVariable('userid', $user->getId()); } } else if (isset($form['action']['deleteFromList'])) { @@ -156,7 +153,7 @@ } /* Load some standard form parameters */ - $form = GalleryUtilities::getFormVariables('form'); + $form = GalleryUtilities::getFormVariables('form.'); /* Set some defaults, if necessary */ if (!isset($form['list']['filter'])) { |