2017-11-11 17:00:08 +01:00
|
|
|
<?php
|
|
|
|
ini_set('display_errors', '1');
|
|
|
|
date_default_timezone_set('Europe/Oslo');
|
2018-02-10 18:08:53 +01:00
|
|
|
setlocale(LC_ALL, 'nb_NO');
|
2017-11-11 17:00:08 +01:00
|
|
|
error_reporting(E_ALL);
|
|
|
|
require __DIR__ . '/../../../src/_autoload.php';
|
2024-02-15 22:57:03 +01:00
|
|
|
require __DIR__ . '/../../../config.php';
|
2024-03-12 19:33:09 +01:00
|
|
|
$pdo = new \PDO($DB_DSN, $DB_USER, $DB_PASS);
|
2017-11-11 17:00:08 +01:00
|
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
$userManager = new \pvv\admin\UserManager($pdo);
|
|
|
|
|
|
|
|
require_once(__DIR__ . '/../../../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php');
|
|
|
|
$as = new SimpleSAML_Auth_Simple('default-sp');
|
|
|
|
$as->requireAuth();
|
|
|
|
$attrs = $as->getAttributes();
|
|
|
|
$uname = $attrs['uid'][0];
|
|
|
|
|
|
|
|
if(!$userManager->isAdmin($uname)){
|
2017-11-11 20:37:04 +01:00
|
|
|
echo 'Her har du ikke lov\'t\'å\'værra!!!';
|
2017-11-11 17:00:08 +01:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2017-11-11 19:13:59 +01:00
|
|
|
$newUser;
|
|
|
|
if(isset($_POST['newuser'])){
|
2017-11-11 20:37:04 +01:00
|
|
|
$newUser = $_POST['newuser'];
|
|
|
|
unset($_POST['newuser']);
|
2017-11-11 19:13:59 +01:00
|
|
|
}
|
|
|
|
|
2018-08-06 23:30:27 +02:00
|
|
|
//$updatingUsers = explode('_', $_POST['users']);
|
|
|
|
$updatingUsers = array();
|
|
|
|
foreach ($_POST as $key => $value) { if ($key === "user_to_update") {
|
|
|
|
array_push($updatingUsers, $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($_POST['user_to_update']);
|
2017-11-11 20:37:04 +01:00
|
|
|
|
2017-11-11 17:00:08 +01:00
|
|
|
// 2d array of usernames and their corresponding group flags
|
|
|
|
$userFlags = [];
|
2017-11-11 20:37:04 +01:00
|
|
|
if($newUser){
|
|
|
|
$userFlags[$newUser] = 0;
|
|
|
|
}
|
2017-11-11 19:13:59 +01:00
|
|
|
|
2017-11-11 20:37:04 +01:00
|
|
|
foreach($_POST as $namegroup => $info){
|
2017-11-11 17:00:08 +01:00
|
|
|
$data = explode('_', $namegroup);
|
2018-08-06 23:30:27 +02:00
|
|
|
$group = array_pop($data);
|
|
|
|
$uname = implode("_", $data);
|
|
|
|
if($uname == 'newuser'){
|
2017-11-11 19:13:59 +01:00
|
|
|
if(!$newUser){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-08-06 23:30:27 +02:00
|
|
|
$uname = $newUser;
|
2017-11-11 19:13:59 +01:00
|
|
|
}
|
|
|
|
|
2018-08-06 23:30:27 +02:00
|
|
|
if(!isset($userFlags[$uname])){
|
|
|
|
$userFlags[$uname] = 0;
|
2017-11-11 17:00:08 +01:00
|
|
|
}
|
|
|
|
|
2018-08-06 23:30:27 +02:00
|
|
|
$userFlags[$uname] = ($userFlags[$uname] | $userManager->usergroups[$group]);
|
2017-11-11 17:00:08 +01:00
|
|
|
}
|
|
|
|
|
2018-08-06 23:30:27 +02:00
|
|
|
foreach($updatingUsers as $uname) {
|
2017-11-11 20:37:04 +01:00
|
|
|
if(!array_key_exists($uname, $userFlags)){
|
|
|
|
$userFlags[$uname] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 17:00:08 +01:00
|
|
|
foreach($userFlags as $uname => $flag){
|
|
|
|
$userManager->setGroups($uname, $flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
header('Location: .');
|
|
|
|
?>
|
|
|
|
|
2018-08-06 23:30:27 +02:00
|
|
|
<a href=".">Om du ikke ble automatisk omdirigert tilbake klikk her</a>
|