Deletion of support_groups is possible, on delete cascade is pretty cool :D

This commit is contained in:
Quitta 2013-07-16 17:43:55 +02:00
parent 5b7f0fe95e
commit 8353b2a99a
7 changed files with 37 additions and 8 deletions

View file

@ -105,7 +105,20 @@ class Support_Group{
return $result;
}
//wrapper for adding user to a support group
public static function deleteSupportGroup($group_id) {
//check if group id exists
if (self::supportGroup_Exists($group_id)){
$sGroup = new self();
$sGroup->setSGroupId($group_id);
$sGroup->delete();
}else{
//return that group doesn't exist
return "GROUP_NOT_EXISTING";
}
}
//wrapper for adding user to a support group
public static function deleteUserOfSupportGroup( $user_id, $group_id) {
@ -184,7 +197,7 @@ class Support_Group{
//Load with sGroupId
public function load_With_SGroupId( $id) {
$dbl = new DBLayer("lib");
$statement = $dbl->execute("SELECT * FROM ticket_log WHERE TLogId=:id", array('id' => $id));
$statement = $dbl->execute("SELECT * FROM `support_group` WHERE `SGroupId` = :id", array('id' => $id));
$row = $statement->fetch();
$this->set($row);
}
@ -193,11 +206,19 @@ class Support_Group{
//update private data to DB.
public function update(){
$dbl = new DBLayer("lib");
$query = "UPDATE ticket_log SET Timestamp = :timestamp, Query = :query, Author = :author, Ticket = :ticket WHERE TLogId=:id";
$values = Array('id' => $this->getTLogId(), 'timestamp' => $this->getTimestamp(), 'query' => $this->getQuery(), 'author' => $this->getAuthor(), 'ticket' => $this->getTicket() );
$query = "UPDATE `support_group` SET `Name` = :name, `Tag` = :tag WHERE `SGroupId` = :id";
$values = Array('id' => $this->getSGroupId(), 'name' => $this->getName(), 'tag' => $this->getTag() );
$statement = $dbl->execute($query, $values);
}
//delete entry
public function delete(){
$dbl = new DBLayer("lib");
$query = "DELETE FROM `support_group` WHERE `SGroupId` = :id";
$values = Array('id' => $this->getSGroupId());
$statement = $dbl->execute($query, $values);
}
////////////////////////////////////////////Getters////////////////////////////////////////////////////
public function getSGroupId(){

View file

@ -4,6 +4,13 @@ function sgroup_list(){
//if logged in
if(WebUsers::isLoggedIn()){
if( WebUsers::isAdmin()){
if(isset($_GET['delete'])){
$delete_id = filter_var($_GET['delete'], FILTER_SANITIZE_NUMBER_INT);
$result['delete'] = Support_Group::deleteSupportGroup( $delete_id);
header("Location: index.php?page=sgroup_list");
exit;
}
$result['grouplist'] = Gui_Elements::make_table(Support_Group::getGroups(), Array("getSGroupId","getName","getTag"), Array("sGroupId","name","tag"));
return $result;
}else{

View file

@ -6,12 +6,13 @@ function show_sgroup(){
if( WebUsers::isAdmin()){
if( isset($_GET['id'])){
//['target_id'] holds the id of the group!
$result['target_id'] = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
if(isset($_GET['delete'])){
$delete_id = filter_var($_GET['delete'], FILTER_SANITIZE_NUMBER_INT);
$result['delete'] = Support_Group::deleteUserOfSupportGroup( $delete_id, $result['target_id'] );
header("Location: index.php?page=show_sgroup&id=1");
header("Location: index.php?page=show_sgroup&id=" . $result['target_id']);
exit;
}

View file

@ -307,7 +307,7 @@
CONSTRAINT `fk_in_support_group_support_group1`
FOREIGN KEY (`Group` )
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`support_group` (`SGroupId` )
ON DELETE NO ACTION
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;

View file

@ -264,7 +264,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`in_support_group` (
CONSTRAINT `fk_in_support_group_support_group1`
FOREIGN KEY (`Group` )
REFERENCES `mydb`.`support_group` (`SGroupId` )
ON DELETE NO ACTION
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;

View file

@ -28,7 +28,7 @@
<td>{$group.sGroupId}</td>
<td><a href ="index.php?page=show_sgroup&id={$group.sGroupId}">{$group.name}</a></td>
<td class="center"><span class="label label-important" >{$group.tag}</span></td>
<td class="center"><a class="btn btn-danger" href="#"><i class="icon-trash icon-white"></i> Delete</a></td>
<td class="center"><a class="btn btn-danger" href="index.php?page=sgroup_list&delete={$group.sGroupId}"><i class="icon-trash icon-white"></i> Delete</a></td>
</tr>
{/foreach}