group can be set when adding/editing user

This commit is contained in:
Uwe Steinmann 2013-04-17 12:02:22 +02:00
parent aecd7a9083
commit 59ed4ff9cc
2 changed files with 60 additions and 14 deletions

View File

@ -63,22 +63,28 @@ if ($action == "adduser") {
$newUser = $dms->addUser($login, md5($pwd), $name, $email, $settings->_language, $settings->_theme, $comment, $role, $isHidden, $isDisabled, $pwdexpiration); $newUser = $dms->addUser($login, md5($pwd), $name, $email, $settings->_language, $settings->_theme, $comment, $role, $isHidden, $isDisabled, $pwdexpiration);
if ($newUser) { if ($newUser) {
/* Set user image if uploaded */
if (isset($_FILES["userfile"]) && is_uploaded_file($_FILES["userfile"]["tmp_name"]) && $_FILES["userfile"]["size"] > 0 && $_FILES['userfile']['error']==0) if (isset($_FILES["userfile"]) && is_uploaded_file($_FILES["userfile"]["tmp_name"]) && $_FILES["userfile"]["size"] > 0 && $_FILES['userfile']['error']==0)
{ {
$userfiletype = $_FILES["userfile"]["type"]; $userfiletype = $_FILES["userfile"]["type"];
$userfilename = $_FILES["userfile"]["name"]; $userfilename = $_FILES["userfile"]["name"];
$lastDotIndex = strrpos(basename($userfilename), "."); $lastDotIndex = strrpos(basename($userfilename), ".");
$fileType = substr($userfilename, $lastDotIndex); $fileType = substr($userfilename, $lastDotIndex);
if ($fileType != ".jpg" && $filetype != ".jpeg") if ($fileType != ".jpg" && $filetype != ".jpeg") {
{
UI::exitError(getMLText("admin_tools"),getMLText("only_jpg_user_images")); UI::exitError(getMLText("admin_tools"),getMLText("only_jpg_user_images"));
} } else {
else
{
resizeImage($_FILES["userfile"]["tmp_name"]); resizeImage($_FILES["userfile"]["tmp_name"]);
$newUser->setImage($_FILES["userfile"]["tmp_name"], $userfiletype); $newUser->setImage($_FILES["userfile"]["tmp_name"], $userfiletype);
} }
} }
/* Set groups if set */
if(isset($_POST["groups"]) && $_POST["groups"]) {
foreach($_POST["groups"] as $groupid) {
$group = $dms->getGroup($groupid);
$group->addUser($newUser);
}
}
} }
else UI::exitError(getMLText("admin_tools"),getMLText("access_denied")); else UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
@ -259,6 +265,26 @@ else if ($action == "edituser") {
if (isset($_POST["grpApprovers"])) foreach ($_POST["grpApprovers"] as $appID) if (isset($_POST["grpApprovers"])) foreach ($_POST["grpApprovers"] as $appID)
$editedUser->setMandatoryApprover($appID,true); $editedUser->setMandatoryApprover($appID,true);
/* Updates groups */
if(isset($_POST["groups"]))
$newgroups = $_POST["groups"];
else
$newgroups = array();
$oldgroups = array();
foreach($editedUser->getGroups() as $k)
$oldgroups[] = $k->getID();
$addgroups = array_diff($newgroups, $oldgroups);
foreach($addgroups as $groupid) {
$group = $dms->getGroup($groupid);
$group->addUser($editedUser);
}
$delgroups = array_diff($oldgroups, $newgroups);
foreach($delgroups as $groupid) {
$group = $dms->getGroup($groupid);
$group->removeUser($editedUser);
}
add_log_line(".php&action=edituser&userid=".$userid); add_log_line(".php&action=edituser&userid=".$userid);
} }
@ -271,19 +297,19 @@ function resizeImage($imageFile) {
// and the output quality is low. Now uses the function imagecreatetruecolor(), // and the output quality is low. Now uses the function imagecreatetruecolor(),
// though, so at least the pictures are in colour. // though, so at least the pictures are in colour.
// Originalbild einlesen // read original image
$origImg = imagecreatefromjpeg($imageFile); $origImg = imagecreatefromjpeg($imageFile);
$width = imagesx($origImg); $width = imagesx($origImg);
$height = imagesy($origImg); $height = imagesy($origImg);
// Thumbnail im Speicher erzeugen // Create thumbnail in memory
$newHeight = 150; $newHeight = 150;
$newWidth = ($width/$height) * $newHeight; $newWidth = ($width/$height) * $newHeight;
$newImg = imagecreatetruecolor($newWidth, $newHeight); $newImg = imagecreatetruecolor($newWidth, $newHeight);
// Verkleinern // resize
imagecopyresized($newImg, $origImg, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); imagecopyresized($newImg, $origImg, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
// In File speichern // save to file
imagejpeg($newImg, $imageFile); imagejpeg($newImg, $imageFile);
// Aufräumen // Clean up
imagedestroy($origImg); imagedestroy($origImg);
imagedestroy($newImg); imagedestroy($newImg);

View File

@ -169,6 +169,16 @@ function showUser(selectObj) {
<td><?php printMLText("role");?>:</td> <td><?php printMLText("role");?>:</td>
<td><select name="role"><option value="<?php echo SeedDMS_Core_User::role_user ?>"><?php printMLText("role_user"); ?></option><option value="<?php echo SeedDMS_Core_User::role_admin ?>"><?php printMLText("role_admin"); ?></option><option value="<?php echo SeedDMS_Core_User::role_guest ?>"><?php printMLText("role_guest"); ?></option></select></td> <td><select name="role"><option value="<?php echo SeedDMS_Core_User::role_user ?>"><?php printMLText("role_user"); ?></option><option value="<?php echo SeedDMS_Core_User::role_admin ?>"><?php printMLText("role_admin"); ?></option><option value="<?php echo SeedDMS_Core_User::role_guest ?>"><?php printMLText("role_guest"); ?></option></select></td>
</tr> </tr>
<tr>
<td><?php printMLText("groups");?>:</td>
<td><select class="chzn-select" multiple="multiple" name="groups[]" data-placeholder="<?php printMLText('select_groups'); ?>">
<?php
foreach($groups as $group) {
echo '<option value="'.$group->getID().'">'.$group->getName().'</option>';
}
?>
</select></td>
</tr>
<tr> <tr>
<td><?php printMLText("is_hidden");?>:</td> <td><?php printMLText("is_hidden");?>:</td>
<td><input type="checkbox" name="ishidden" value="1"></td> <td><input type="checkbox" name="ishidden" value="1"></td>
@ -198,7 +208,7 @@ function showUser(selectObj) {
<div class="cbSelectTitle"><?php printMLText("individuals");?>:</div> <div class="cbSelectTitle"><?php printMLText("individuals");?>:</div>
</td> </td>
<td> <td>
<select class="chzn-select" name="usrReviewers[]" multiple="multiple"> <select class="chzn-select" name="usrReviewers[]" multiple="multiple" data-placeholder="<?php printMLText('select_users'); ?>">
<?php <?php
foreach ($users as $usr) { foreach ($users as $usr) {
@ -359,6 +369,16 @@ function showUser(selectObj) {
<td><?php printMLText("role");?>:</td> <td><?php printMLText("role");?>:</td>
<td><select name="role"><option value="<?php echo SeedDMS_Core_User::role_user ?>"><?php printMLText("role_user"); ?></option><option value="<?php echo SeedDMS_Core_User::role_admin ?>" <?php if($currUser->getRole() == SeedDMS_Core_User::role_admin) echo "selected"; ?>><?php printMLText("role_admin"); ?></option><option value="<?php echo SeedDMS_Core_User::role_guest ?>" <?php if($currUser->getRole() == SeedDMS_Core_User::role_guest) echo "selected"; ?>><?php printMLText("role_guest"); ?></option></select></td> <td><select name="role"><option value="<?php echo SeedDMS_Core_User::role_user ?>"><?php printMLText("role_user"); ?></option><option value="<?php echo SeedDMS_Core_User::role_admin ?>" <?php if($currUser->getRole() == SeedDMS_Core_User::role_admin) echo "selected"; ?>><?php printMLText("role_admin"); ?></option><option value="<?php echo SeedDMS_Core_User::role_guest ?>" <?php if($currUser->getRole() == SeedDMS_Core_User::role_guest) echo "selected"; ?>><?php printMLText("role_guest"); ?></option></select></td>
</tr> </tr>
<tr>
<td><?php printMLText("groups");?>:</td>
<td><select class="chzn-select" multiple="multiple" name="groups[]" data-placeholder="<?php printMLText('select_groups'); ?>">
<?php
foreach($groups as $group) {
echo '<option value="'.$group->getID().'"'.($group->isMember($currUser) ? ' selected' : '').'>'.$group->getName().'</option>';
}
?>
</select></td>
</tr>
<tr> <tr>
<td><?php printMLText("is_hidden");?>:</td> <td><?php printMLText("is_hidden");?>:</td>
<td><input type="checkbox" name="ishidden" value="1"<?php print ($currUser->isHidden() ? " checked='checked'" : "");?>></td> <td><input type="checkbox" name="ishidden" value="1"<?php print ($currUser->isHidden() ? " checked='checked'" : "");?>></td>
@ -423,7 +443,7 @@ function showUser(selectObj) {
<div class="cbSelectTitle"><?php printMLText("groups");?>:</div> <div class="cbSelectTitle"><?php printMLText("groups");?>:</div>
</td> </td>
<td> <td>
<select class="chzn-select" name="grpReviewers[]" multiple="multiple"> <select class="chzn-select" name="grpReviewers[]" multiple="multiple" data-placeholder="<?php printMLText('select_groups'); ?>">
<?php <?php
foreach ($groups as $grp) { foreach ($groups as $grp) {
@ -445,7 +465,7 @@ function showUser(selectObj) {
<div class="cbSelectTitle"><?php printMLText("individuals");?>:</div> <div class="cbSelectTitle"><?php printMLText("individuals");?>:</div>
</td> </td>
<td> <td>
<select class="chzn-select" name="usrApprovers[]" multiple="multiple"> <select class="chzn-select" name="usrApprovers[]" multiple="multiple" data-placeholder="<?php printMLText('select_users'); ?>">
<?php <?php
$res=$currUser->getMandatoryApprovers(); $res=$currUser->getMandatoryApprovers();
foreach ($users as $usr) { foreach ($users as $usr) {
@ -466,7 +486,7 @@ function showUser(selectObj) {
<div class="cbSelectTitle"><?php printMLText("groups");?>:</div> <div class="cbSelectTitle"><?php printMLText("groups");?>:</div>
</td> </td>
<td> <td>
<select class="chzn-select" name="grpApprovers[]" multiple="multiple"> <select class="chzn-select" name="grpApprovers[]" multiple="multiple" data-placeholder="<?php printMLText('select_groups'); ?>">
<?php <?php
foreach ($groups as $grp) { foreach ($groups as $grp) {