PHP Classes

File: group_properties.php

Recommend this page to a friend!
  Classes of zinsou A.A.E.Moïse   tinyUGatMs   group_properties.php   Download  
File: group_properties.php
Role: Auxiliary script
Content type: text/plain
Description: php script for ajax group properties insertion
Class: tinyUGatMs
Manage users and groups of events in a database
Author: By
Last change:
Date: 6 years ago
Size: 2,396 bytes
 

Contents

Class file image Download
<?php
session_start
();
require_once(
'./config.php');
require_once(
'./groupmyusers.class.php');
// var_dump($_POST);
if(count($_POST)==1){
    if(
$_POST["group"]!="FIRST"){
       
$query=$bdd->prepare('SELECT idgroup FROM groups WHERE name=:name');//get the id
       
$query->bindValue(':name',$_POST["group"],PDO::PARAM_STR);
       
$query->execute();
       
$id=$query->fetch();
       
$query->CloseCursor();
       
$query=$bdd->prepare('UPDATE users SET groupid=1 WHERE groupid=:id');//save the users from being without group otherwise they can't connect
       
$query->bindValue(':id',(int)$id["idgroup"],PDO::PARAM_INT);
       
$query->execute();
       
$query->CloseCursor();
       
$query=$bdd->prepare('DELETE FROM groups WHERE name=:name');//now do what admin ask: delete the group
       
$query->execute(array('name'=>$_POST["group"]));
       
$query->CloseCursor();
    echo
'Group deleted';
    }else{
        echo
'You can\'t delete this group';//it is the default group
   
}
}elseif(isset(
$_POST['add'])){
   
$query=$bdd->prepare('SELECT idgroup FROM groups WHERE name=:name');//get the id
   
$query->bindValue(':name',$_POST["name"],PDO::PARAM_STR);
   
$query->execute();
   
$id=$query->fetch();
   
$query->CloseCursor();
    if(empty(
$id)){
       
$group=new groupmyusers($bdd,$_POST['name'],$_POST['description'],$_POST['datestart'],$_POST['startaccesstime'],
       
$_POST['endaccesstime'],$_POST['recurrence'],$_POST['days']);
       
$group->add();
    }else{
        echo
'A group with the same name already exists please change the name or use the edit option to edit the group with this name';
    }
}elseif(isset(
$_POST['update'])){
    if(
$_POST['oldname']!=$_POST['name']){
       
$query=$bdd->prepare('SELECT idgroup FROM groups WHERE name=:name');//get the id
       
$query->bindValue(':name',$_POST["name"],PDO::PARAM_STR);
       
$query->execute();
       
$id=$query->fetch();
       
$query->CloseCursor();
    }
    if(!isset(
$id)||empty($id)){
       
$group=new groupmyusers($bdd,$_POST['name'],$_POST['description'],$_POST['datestart'],$_POST['startaccesstime'],
       
$_POST['endaccesstime'],$_POST['recurrence'],$_POST['days']);
       
$group->update($_POST['oldname']);
    }else{
        echo
'A group with the same name already exists please change the name or use the edit option to edit the group with this name';
    }

}else{
    echo
"you have nothing to do here";
    echo
'<script type="text/javascript"> setInterval(window.location="./managegroups.php",25000);</script>';
}
?>