* * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. */ if (!defined(CONGREGATION_BASE)) { define(CONGREGATION_BASE, dirname(__FILE__)); } require_once CONGREGATION_BASE . '/lib/base.php'; require_once CONGREGATION_BASE . '/lib/Congregation.php'; switch(Util::getFormData('action')) { case 'modify': modifyUser(); break; case 'edit': // this is the default, I just specify a case to keep things readable default: break; } /* Always throw up the edit dialogue after doing everything else. */ // XXX FIXME using xmlhttp() in edituser.inc will make this unnecessary // editUser(); function modifyUser() { /* Prep some variables we will need to compile the list of changes from. */ // XXX FIXME isn't there any way to do this using Util instead of $_POST or $_QUERY? It // looks bad to use one in one place, and the other right below it. $arguments = $_POST; $userName = Util::getFormData('user'); $userAccount = Util::getFormData('accountId'); $moduleName = Util::getFormData('module'); global $congregation; $userAttributes = $congregation->getUserDetails($userName, $userAccount); unset($arguments['user']); // Empty $_POST of anything but actual inputted values. unset($arguments['accountId']); unset($arguments['module']); unset($arguments['action']); $changedValues = array(); /* Compile a list of changes in an array formatted as (attributeName => (values)), referring if necessary to the original values to determine what has changed. */ // XXX this might be do-able without pulling up the old values if the form just submitted everything, not JUST changes // I'm not sure which I prefer, but this seems to work so I'll leave it for now. foreach($arguments as $formVarName => $value) { /* Check if it's a member of an array of values; if so, we need to pass the entire original array, with modifications. */ if(preg_match('/[a-zA-Z]*?\d+/', $formVarName)) { $attName = preg_replace('/([a-zA-Z]*?)\d+/', '$1', $formVarName); $attIndex = preg_replace('/[a-zA-Z]*?(\d+)/', '$1', $formVarName); if(!isset($changedValues[$attName])) $changedValues[$attName] = $userAttributes[$attName]; /* Test if the field has been set to empty; if so, we remove the value altogether. */ if($value === '') unset($changedValues[$attName][$attIndex]); /* Otherwise, set it to the new value. */ else $changedValues[$attName][$attIndex] = $value; } /* Otherwise we only pass this one value. */ else $changedValues[$formVarName] = $value; } /* if(!$congregation->modifyUser($userAccount, $userName, $changedValues)) { ; } */ echo 'WOOT! Ok, dumping $arguments and $changedValues:
'; print_r($arguments); print_r($changedValues); echo ''; return; } function editUser() { global $registry; global $congregation; $userName = Util::getFormData('user'); $userAccount = Util::getFormData('accountId'); $userAttributes = $congregation->getUserDetails($userName, $userAccount); $installedApps = $registry->listApps(); /* The next two lines just make sure that Congregation's attributes show up at the top of the list */ unset($installedApps[array_search('congregation', $installedApps)]); array_unshift($installedApps, 'congregation'); $modules = array(); foreach($installedApps as $moduleName) { /* If the file, directory, or variable do not exist we will silently not list the attributes for that module. */ @include(HORDE_BASE.'/'.$moduleName.'/lib/'.$moduleName.'Atts.php'); if(isset(${$moduleName . 'Attributes'})) { $modules[$moduleName] = ${$moduleName . 'Attributes'}; /* XXX insert code here to determine permissions for this module */ } } require $registry->get('templates', 'horde') . '/common-header.inc'; require CONGREGATION_TEMPLATES . '/common-header.inc'; require CONGREGATION_TEMPLATES . '/menu.inc'; require CONGREGATION_TEMPLATES . "/edituser.inc"; // this is where the action happens require $registry->get('templates', 'horde') . '/common-footer.inc'; } ?>