2022-09-23 17:26:15 +00:00
< ? php
session_start ();
// Include server connection
include dirname ( __DIR__ ) . " /server/conn.php " ;
include dirname ( __DIR__ ) . " /app.php " ;
use App\Account ;
use App\Image ;
2022-09-24 17:07:22 +00:00
use App\Group ;
2022-09-23 17:26:15 +00:00
$user_info = new Account ();
$image_info = new Image ();
2022-09-24 17:07:22 +00:00
$group_info = new Group ();
2022-09-23 17:26:15 +00:00
$user_ip = $user_info -> get_ip ();
/*
|-------------------------------------------------------------
| Image Groups
|-------------------------------------------------------------
| The Long - awaited feature
|-------------------------------------------------------------
*/
if ( isset ( $_POST [ 'group_submit' ])) {
2022-09-24 17:07:22 +00:00
$query = $group_info -> get_group_info ( $conn , $_POST [ 'group_id' ]);
if ( $_SESSION [ 'id' ] == $query [ 'author' ] || $user_info -> is_admin ( $conn , $_SESSION [ 'id' ])) {
$sql = " UPDATE groups SET image_list = ? WHERE id = ? " ;
// Checking if databse is doing ok
if ( $stmt = mysqli_prepare ( $conn , $sql )) {
mysqli_stmt_bind_param ( $stmt , " si " , $param_images , $param_id );
// Setting parameters
$param_images = implode ( " " , $_POST [ 'group_images' ]);
$param_id = $_POST [ 'group_id' ];
// Attempt to execute the prepared statement
if ( mysqli_stmt_execute ( $stmt )) {
?>
< script >
2022-09-25 15:49:11 +00:00
window . location . href = " group.php?id=<?php echo $_POST['group_id'] ; ?> " ;
2022-09-24 17:07:22 +00:00
</ script >
< ? php
2022-09-25 15:49:11 +00:00
$_SESSION [ 'msg' ] = " Updated the image group! " ;
2022-09-24 17:07:22 +00:00
} else {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Oopsie....' , 'An error occured on the servers' , 'var(--warning)' , 'assets/icons/cross.svg' );
2022-09-24 17:07:22 +00:00
</ script >
< ? php
2022-09-23 17:26:15 +00:00
}
}
2022-09-24 17:07:22 +00:00
} else {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Gwa Gwa' , 'You\'re not privilaged enough to do thissss!' , 'var(--warning)' , 'assets/icons/cross.svg' );
2022-09-24 17:07:22 +00:00
</ script >
< ? php
2022-09-23 17:26:15 +00:00
}
}
2022-09-23 23:02:59 +00:00
/*
|-------------------------------------------------------------
2022-09-24 17:07:22 +00:00
| Edit title
2022-09-23 23:02:59 +00:00
|-------------------------------------------------------------
2022-09-24 17:07:22 +00:00
|
2022-09-23 23:02:59 +00:00
|-------------------------------------------------------------
*/
if ( isset ( $_POST [ 'title_submit' ])) {
2022-09-24 17:07:22 +00:00
$query = $group_info -> get_group_info ( $conn , $_POST [ 'group_id' ]);
if ( $_SESSION [ 'id' ] == $query [ 'author' ] || $user_info -> is_admin ( $conn , $_SESSION [ 'id' ])) {
// getting ready forSQL asky asky
$sql = " UPDATE groups SET group_name = ? WHERE id = ? " ;
// Checking if databse is doing ok
if ( $stmt = mysqli_prepare ( $conn , $sql )) {
mysqli_stmt_bind_param ( $stmt , " si " , $param_title , $param_id );
// Setting parameters
$param_title = $_POST [ 'group_title' ];
$param_id = $_POST [ 'group_id' ];
// Attempt to execute the prepared statement
if ( mysqli_stmt_execute ( $stmt )) {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Success!!!' , 'The title has been updated successfully! You may need to refresh the page to see the new information.' , 'var(--success)' , 'assets/icons/check.svg' );
2022-09-24 17:07:22 +00:00
flyoutClose ();
</ script >
< ? php
2022-09-23 23:02:59 +00:00
} else {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Error :c' , 'An error occured on the servers' , 'var(--warning)' , 'assets/icons/cross.svg' );
2022-09-23 23:02:59 +00:00
flyoutClose ();
</ script >
< ? php
}
} else {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Error :c' , 'An error occured on the servers' , 'var(--warning)' , 'assets/icons/cross.svg' );
2022-09-23 23:02:59 +00:00
flyoutClose ();
</ script >
< ? php
}
2022-09-24 17:07:22 +00:00
} else {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Denied' , 'It seems that you do not have the right permitions to edit this image.' , 'var(--warning)' , 'assets/icons/cross.svg' );
2022-09-24 17:07:22 +00:00
flyoutClose ();
</ script >
< ? php
2022-09-23 23:02:59 +00:00
}
}
2022-09-24 16:47:34 +00:00
2022-09-25 18:17:47 +00:00
/*
|-------------------------------------------------------------
| New Group
|-------------------------------------------------------------
|
|-------------------------------------------------------------
*/
2022-09-24 16:47:34 +00:00
if ( isset ( $_POST [ 'new_group_submit' ])) {
if ( $user_info -> is_loggedin ()) {
2022-09-27 14:10:08 +00:00
$group_name = " New Group " ;
2022-09-24 16:47:34 +00:00
$sql = " INSERT INTO groups (group_name, author, image_list) VALUES(' $group_name ', ' " . $_SESSION [ 'id' ] . " ', '') " ;
mysqli_query ( $conn , $sql );
$group_id = mysqli_insert_id ( $conn );
?>
< script >
window . location . href = " group.php?id=<?php echo $group_id ; ?> " ;
</ script >
< ? php
2022-09-25 15:49:11 +00:00
$_SESSION [ 'msg' ] = " New Group successfully made! " ;
2022-09-24 16:47:34 +00:00
} else {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Denied' , 'You must have an account to preform this action!' , 'var(--warning)' , 'assets/icons/cross.svg' );
2022-09-24 16:47:34 +00:00
</ script >
< ? php
}
}
2022-09-24 17:07:22 +00:00
2022-09-25 18:17:47 +00:00
/*
|-------------------------------------------------------------
| Delete Group
|-------------------------------------------------------------
|
|-------------------------------------------------------------
*/
2022-09-24 17:07:22 +00:00
if ( isset ( $_POST [ 'group_delete' ])) {
$query = $group_info -> get_group_info ( $conn , $_POST [ 'group_id' ]);
if ( $_SESSION [ 'id' ] == $query [ 'author' ] || $user_info -> is_admin ( $conn , $_SESSION [ 'id' ])) {
$sql = " DELETE FROM groups WHERE id = ? " ;
if ( $stmt = mysqli_prepare ( $conn , $sql )) {
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param ( $stmt , " i " , $_POST [ 'group_id' ]);
if ( $stmt -> execute ()) {
?>
< script >
flyoutClose ();
2022-09-25 18:17:47 +00:00
setTimeout ( function (){ window . location . href = " group.php " ;}, 500 );
2022-09-24 17:07:22 +00:00
</ script >
< ? php
2022-09-25 18:17:47 +00:00
$_SESSION [ 'msg' ] = " Group successfully yeeted out " ;
2022-09-24 17:07:22 +00:00
} else {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Ouchie' , 'Something went wrong while deleting the group' , 'var(--warning)' , 'assets/icons/cross.svg' );
2022-09-24 17:07:22 +00:00
flyoutClose ();
</ script >
< ? php
}
} else {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Ouchie' , 'Something went wrong while deleting the image group' , 'var(--warning)' , 'assets/icons/cross.svg' );
2022-09-24 17:07:22 +00:00
flyoutClose ();
</ script >
< ? php
}
} else {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Denied!!!' , 'You do not have the right permitions to delete this group' , 'var(--warning)' , 'assets/icons/cross.svg' );
2022-09-24 17:07:22 +00:00
flyoutClose ();
</ script >
< ? php
}
}