<commit_before><?php

/* 
 *  delete a post
 */



session_start();

if( !( isset( $_SESSION['Username'] ) && isset($_SESSION['Name']) && $_SESSION['Username'] === 'admin' ) )
{
	echo "To access this page you need to login as Admin. Please log in first.";
	die();
}


$html = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/favicon.png" type="image/png">
<link rel="shortcut icon" type="image/png" href="../../image/gogreen.jpg" />
<style>
a:link    {color:red;  text-decoration:none}/*link color when not visited anytime*/
a:visited {color:red;  text-decoration:none}/*link coloe after visiting*/
a:hover   {color:white;  text-decoration:none}/*link color when try to click the link*/
a:active  {color:red; background-color:transparent; text-decoration:none}/*link color juat after clicking if active*/

body {
    
    background-image: url("../../image/image4.jpg");
     min-height: 500px;
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}
button
{
	cursor: pointer; font-size : 25px; height:auto; width:auto ;background-color:transparent;color:white ;
	border: 0.25px solid white;
}
</style>
</head>

<body>
<br><br>
<button onclick="document.location.href='../../'"> BACK </button>
<center>
<br><br><br><br><br><br><br>
<form action = "DeletePost.php" method = "post">
<var style ="color:white"><b><i>Type the name of POST::</i></b></var>
<input type = "text" name = "delete" pattern='[A-Za-z0-9. ]{1,}'  title='only alphabets, numbers and spaces and dot are allowed' required autofocus>
<br><br>
<button type = "submit"  >DELETE</button>
</form>

HTML;
echo $html;

if ( isset($_POST['delete']))

	DeletePost ( $_POST['delete'] );

function DeletePost ( $DeleteThisPost)
{
	require '../Globals.php';
	require '../../LocalSettings.php';

	$userN = $DeleteThisPost;
	$sqlConn = new mysqli( $eorgDBserver , $eorgDBuser , $eorgDBpasswd , $eorgDBname );

	if( $sqlConn->connect_errno ) 
	{
		echo "Server error.";
		die();
	}

	$qry = "DELETE FROM $PostTable WHERE  $NameOfThePost = ?" ;
	$stmt = $sqlConn->prepare ( $qry );
	$stmt->bind_param ( 's', $DeleteThisPost );


	if (  $stmt->execute() )
	{
		$DeleteThisPost = str_replace('.','$', $DeleteThisPost);
		$DeleteThisPost = preg_replace('/\s+/', '_', $DeleteThisPost);
		$stmt = $sqlConn->prepare ( "DROP TABLE $DeleteThisPost");

		$stmt->execute();
		
		$stmt = $sqlConn->prepare ("DELETE FROM $assignPostTable WHERE $postTitle REGEXP \"^$userN\"");<commit_msg>minor bug fix<commit_after><?php

/* 
 *  delete a post
 */



session_start();

if( !( isset( $_SESSION['Username'] ) && isset($_SESSION['Name']) && $_SESSION['Username'] === 'admin' ) )
{
	echo "To access this page you need to login as Admin. Please log in first.";
	die();
}


$html = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/favicon.png" type="image/png">
<link rel="shortcut icon" type="image/png" href="../../image/gogreen.jpg" />
<style>
a:link    {color:red;  text-decoration:none}/*link color when not visited anytime*/
a:visited {color:red;  text-decoration:none}/*link coloe after visiting*/
a:hover   {color:white;  text-decoration:none}/*link color when try to click the link*/
a:active  {color:red; background-color:transparent; text-decoration:none}/*link color juat after clicking if active*/

body {
    
    background-image: url("../../image/image4.jpg");
     min-height: 500px;
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}
button
{
	cursor: pointer; font-size : 25px; height:auto; width:auto ;background-color:transparent;color:white ;
	border: 0.25px solid white;
}
</style>
</head>

<body>
<br><br>
<button onclick="document.location.href='../../'"> BACK </button>
<center>
<br><br><br><br><br><br><br>
<form action = "DeletePost.php" method = "post">
<var style ="color:white"><b><i>Type the name of POST::</i></b></var>
<input type = "text" name = "delete" pattern='[A-Za-z0-9. ]{1,}'  title='only alphabets, numbers and spaces and dot are allowed' required autofocus>
<br><br>
<button type = "submit"  >DELETE</button>
</form>

HTML;
echo $html;

if ( isset($_POST['delete']))

	DeletePost ( $_POST['delete'] );

function DeletePost ( $DeleteThisPost)
{
	require '../Globals.php';
	require '../../LocalSettings.php';

	$userN = $DeleteThisPost;
	$sqlConn = new mysqli( $eorgDBserver , $eorgDBuser , $eorgDBpasswd , $eorgDBname );

	if( $sqlConn->connect_errno ) 
	{
		echo "Server error.";
		die();
	}

	$qry = "DELETE FROM $PostTable WHERE  $NameOfThePost = ?" ;
	$stmt = $sqlConn->prepare ( $qry );
	$stmt->bind_param ( 's', $DeleteThisPost );


	if (  $stmt->execute() )
	{
		$DeleteThisPost = str_replace('.','$', $DeleteThisPost);
		$DeleteThisPost = preg_replace('/\s+/', '_', $DeleteThisPost);
		$stmt = $sqlConn->prepare ( "DROP TABLE $DeleteThisPost");

		$stmt->execute();
		
		$stmt = $sqlConn->prepare ("DELETE FROM $assignPostTable WHERE $postTitle REGEXP \"^$userN$\"");
{'fraction_non_alphanumeric': 0.19547285632073663, 'fraction_numerical': 0.005371187416075196, 'mean_word_length': 4.505807814149947, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3838931', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1791, 'n_words': 437}