<?php
session_start();
require_once('config.php');
if(isset($_SESSION['role'])&&$_SESSION['role']=="admin"){
?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MANAGE GROUP ACCESS TIME</title>
<style type="text/css">
#other {
font-family: verdana;
font-weight: bold;
font-size: 14px;
font-style:italic;
color: #FFFFFF;
background-color: grey;
width: auto;
margin-left: 15%;
margin-right: 15%;
padding:2%;
}
label
{
display: block ;
width: 150px;
float : left ;
}
</style>
</head>
<body>
<div id="other">
<?php
$_GET["action"]=(isset($_GET["action"]))?$_GET["action"]:false;
switch ($_GET["action"]){
case "add":
?>
<div>
<form id="groups" method="POST">
<fieldset><legend>Groups ADD</legend>
<label for="name">name</label><input name="name" type="text" id="name" /><br>
<label for="description">description</label><textarea name="description" ROWS="4" COLS="40" id="description" ></textarea><br>
<label for="startaccesstime">startaccesstime</label><input name="startaccesstime" type="text" id="startaccesstime" /><br>
<label for="endaccesstime">endaccesstime</label><input name="endaccesstime" type="text" id="endaccesstime" /><br>
<label for="datecreation">datecreation</label><input name="datecreation" type="text" id="datecreation" /><br>
<?php
$rang = array
('dayly','weekly','monthly','quartely','yearly','once','custom');
echo'<label for="recurrence">recurrence</label>';
echo'<select name="recurrence" id="recurrence">';
for($i=0;$i<7;$i++)
{
echo'<option value="'.$rang[$i].'">'.$rang[$i].'</option>';
}
echo'</select><br>';
?>
<label for="days">days</label><input name="days" type="text" id="days" /> <span style="font-size:12px;">use for custom recurrence only, example= friday,monday,saturday</span> <br >
</p>
</fieldset>
<p><input type="submit" value="Submit" /></p>
<div id="manage"></div></form></div>
<div><p>What do you want to do ?
<ul><li><a href="./managegroups.php?action=edit">Edit existing groups ?</a></li>
<li><a href="./managegroups.php?action=add">Add a new group ?</a></li>
<li><a href="./managegroups.php?action=delete">DELETE a group ?</a></li>
</ul>
</p></div>
<script language="JavaScript">
var manage=document.getElementById("manage");
var select=document.getElementById("select");
var groups=document.getElementById("groups");
var description=document.getElementById("description");
var startaccesstime=document.getElementById("startaccesstime");
var endaccesstime=document.getElementById("endaccesstime");
var datecreation=document.getElementById("datecreation");
var recurrence=document.getElementById("recurrence");
var days=document.getElementById("days");
function addEvent (element,event,func) {
if (element.attachEvent){
element.attachEvent ("on"+event,func) ;
}else{
element.addEventListener(event,func,true) ;
}
}
function group_create(){
var name=document.getElementById("name");
manage.innerHTML='<span style="color:blue;">submitting...Please wait...</span>';
var xhr=new XMLHttpRequest;
xhr.open("POST","./group_properties.php");
xhr .setRequestHeader ( "Content-Type" ,"application/x-www-form-urlencoded" );
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var resp=xhr.responseText;
manage.innerHTML=resp;
if(resp=="Group successfully added"){
manage.innerHTML +="<br> You will be redirected in 25 seconds";
setInterval(window.location="./managegroups.php?action=edit",25000);
}
}
}
xhr.send('add=true&name='+name.value+'&description='+description.value+'&recurrence='+recurrence.options[recurrence.selectedIndex ].innerHTML+'&datestart='+datecreation.value+'&startaccesstime='+startaccesstime.value+'&endaccesstime='+endaccesstime.value+'&days='+days.value);
}
addEvent(groups,"submit",function(e){
e = e || window.event ;
group_create();
e.returnValue= false;
if (e.preventDefault) {;
e.preventDefault();
}
}
);
</script>
<?php
break;
case "edit": ?>
<form id="groups" method="POST">
<fieldset><legend>Groups management</legend>
<p><select id="select">
<option value="none" >none</option>
<?php
$query=$bdd->query('SELECT name FROM groups');
// $query->bindValue(':pseudo',$_POST['pseudo'],PDO::PARAM_STR);
$query->execute();
while($data=$query->fetch()){
echo'<option value='.$data["name"].' id='.$data["name"].'>'.$data["name"].'</option>';
}
?></select></p><p>
<!--<input type="submit" value="modify" />-->
</p>
</fieldset><fieldset id="propert"></fieldset></form><div id="manage" ></div>
<div><p>What do you want to do ?
<ul><li><a href="./managegroups.php?action=edit">Edit existing groups ?</a></li>
<li><a href="./managegroups.php?action=add">Add a new group ?</a></li>
<li><a href="./managegroups.php?action=delete">DELETE a group ?</a></li>
</ul>
</p></div>
<script language="JavaScript">
var manage=document.getElementById("manage");
var select=document.getElementById("select");
var groups=document.getElementById("groups");
var propert=document.getElementById("propert");
function addEvent (element,event,func) {
if (element.attachEvent){
element.attachEvent ("on"+event,func) ;
}else{
element.addEventListener(event,func,true) ;
}
}
function gproperties(){
if(select.options[select.selectedIndex ].innerHTML!=="none"){
manage.innerHTML='<span style="color:blue;">Loading...Please wait...</span>';
var xhr=new XMLHttpRequest;
xhr.open("GET","./ajaxgroups.php?group="+select.options[select.selectedIndex ].innerHTML );
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
manage.innerHTML='';
var resp=xhr.responseText;
propert.innerHTML=resp;
}
}
xhr.send(null);
}else{
propert.innerHTML='This group doesn\'t exist so it doesn\'t have any properties';
manage.innerHTML='<span style="color:blue;">Choose another group to modify it</span>';
}
}
addEvent(select,"change",function(e){
e = e || window.event ;
gproperties();
e.returnValue= false;
if (e.preventDefault) {
e.preventDefault();
}
}
);
function properties_update(){
var name=document.getElementById("name");
var description=document.getElementById("description");
var startaccesstime=document.getElementById("startaccesstime");
var endaccesstime=document.getElementById("endaccesstime");
var datecreation=document.getElementById("datecreation");
var recurrence=document.getElementById("recurrence");
var days=document.getElementById("days");
var oldname=document.getElementById("oldname");
manage.innerHTML='<span style="color:blue;">Updating...Please wait...</span>';
var xhr=new XMLHttpRequest;
xhr.open("POST","./group_properties.php");
xhr .setRequestHeader ( "Content-Type" ,"application/x-www-form-urlencoded" );
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var resp=xhr.responseText;
manage.innerHTML=resp;
if(resp=="Group successfully updated"){
manage.innerHTML +="<br> You will be redirected in 25 seconds";
setInterval(window.location="./managegroups.php?action=edit",25000);
}
}
}
xhr.send('update=true&name='+name.value+'&description='+description.value+'&datestart='+datecreation.value+'&startaccesstime='+startaccesstime.value+'&endaccesstime='+endaccesstime.value+'&recurrence='+recurrence.options[recurrence.selectedIndex ].innerHTML+'&days='+days.value+'&oldname='+oldname.value);
}
addEvent(groups,"submit",function(e){
e = e || window.event ;
properties_update();
e.returnValue= false;
if (e.preventDefault) {
e.preventDefault();
}
}
);
</script>
<?php
break;
case "delete":
?>
Delete a group will be definitive, think about it...!
<form id="groups" method="POST">
<fieldset><legend>Groups management</legend>
<p><select id="select">
<option value="none" ></option>
<?php
$query=$bdd->query('SELECT name FROM groups');
// $query->bindValue(':pseudo',$_POST['pseudo'],PDO::PARAM_STR);
$query->execute();
while($data=$query->fetch()){
echo'<option value='.$data["name"].' id='.$data["name"].'>'.$data["name"].'</option>';
}
?></select></p><p>
<!--<input type="submit" value="modify" />-->
</p>
</fieldset><p id="propert"></p></form><div id="manage" ></div><div><p>What do you want to do ?
<ul><li><a href="./managegroups.php?action=edit">Edit existing groups ?</a></li>
<li><a href="./managegroups.php?action=add">Add a new group ?</a></li>
<li><a href="./managegroups.php?action=delete">DELETE a group ?</a></li>
</ul>
</p></div>
<script language="JavaScript">
var manage=document.getElementById("manage");
var select=document.getElementById("select");
var groups=document.getElementById("groups");
var propert=document.getElementById("propert");
function addEvent (element,event,func) {
if (element.attachEvent){
element.attachEvent ("on"+event,func) ;
}else{
element.addEventListener(event,func,true) ;
}
}
function gproperties(){
manage.innerHTML='<span style="color:blue;">Loading...Please wait...</span>';
var xhr=new XMLHttpRequest;
xhr.open("GET","./ajaxgroups.php?group="+select.options[select.selectedIndex ].innerHTML+"&delete=true"
);
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
manage.innerHTML='';
var resp=xhr.responseText;
propert.innerHTML=resp;
}
}
xhr.send(null);
}
addEvent(select,"change",function(e){
e = e || window.event ;
gproperties();
e.returnValue= false;
if (e.preventDefault) {
e.preventDefault();
}
}
);
function delete_group(){
manage.innerHTML='<span style="color:blue;">Updating...Please wait...</span>';
var xhr=new XMLHttpRequest;
xhr.open("POST","./group_properties.php");
xhr .setRequestHeader ( "Content-Type" ,"application/x-www-form-urlencoded" );
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var resp=xhr.responseText;
manage.innerHTML=resp;
if(resp=='Group deleted'){
manage.innerHTML +="<br> You will be redirected in 25 seconds";
setInterval(window.location="./managegroups.php?action=delete",25000);
}
}
}
xhr.send('group='+select.options[select.selectedIndex ].innerHTML);
}
addEvent(groups,"submit",function(e){
e = e || window.event ;
delete_group();
e.returnValue= false;
if (e.preventDefault) {
e.preventDefault();
}
}
);
</script>
<?php
break;
default:
echo'<div><p>What do you want to do ?
<ul><li><a href="./managegroups.php?action=edit">Edit existing groups ?</a></li>
<li><a href="./managegroups.php?action=add">Add a new group ?</a></li>
<li><a href="./managegroups.php?action=delete">DELETE a group ?</a></li>
</ul>
</p></div>';
break;
}
}else{
$url="./connexion.php";
echo '<script type="text/javascript">window.location="'.$url.'";</script>';
exit;
}
?>
</div>
</body>
</html>
|