<commit_before><?php 
session_start(); 
include('lib/config.php');
include('lib/db.class.php');
include('include_classes.php');
include('functions.php');

ini_set('display_errors', 0);
error_reporting(E_ALL);

$db = new Db($dbConfig);
$error = new error();

c_cookie::enforce_log();
?>

<?php 
$user_id = $_SESSION['user_id']; 
$admin_p = $_SESSION['admin'];
$teacher_p = $_SESSION['teacher'];
$club_p = $_SESSION['club'];
$sports_p = $_SESSION['sports'];
$staff_p = $_SESSION['staff'];
?>

<?php
	//Inserting stuff.
	if(!empty($_REQUEST)) {
		//$anno_id = 17;
		$anno_id = $_REQUEST['anno_id']; //*Get the announcment id from the address
		
		//*This is for updating the announcements
		$subtype_ids = $_REQUEST['check']; //check is the name of the checkbox array. Subtype_ids contains all the subtypes that the announcement is associated with.
		if(!empty($subtype_ids)) {
			//*Insert the actual announcement into the announcement table
			$title = mysql_real_escape_string($_REQUEST['title']);
			$description = mysql_real_escape_string( $_REQUEST['description'] );
			$start_date = mysql_real_escape_string($_REQUEST['start_date']);
			$end_date = mysql_real_escape_string($_REQUEST['end_date']);
			$date = mysql_real_escape_string($_REQUEST['date']);
			$location = mysql_real_escape_string($_REQUEST['location']);
			$time = mysql_real_escape_string($_REQUEST['time']);
			
			$query = "UPDATE announcements SET title='$title', description='$description', start_date='$start_date', end_date='$end_date', date='$date', location='$location', time='$time' WHERE id='$anno_id';";
			mysql_query($query);

			//*Insert the anno_subtype relationship into its table
			//*First delete all the existing ones
			$query = "DELETE FROM anno_subtype WHERE anno_id='$anno_id'";
			mysql_query($query);
			
			//*Then, insert the new ones.
			foreach($subtype_ids as $subtype_id) {
				$query = "INSERT INTO anno_subtype(anno_id, subtype_id) VALUES('$anno_id', '$subtype_id');";
				mysql_query($query);
			}
			header("Location: main.php?current=1");
		} else {
			//$message = "You must check a category.";
			//$error->set_message($message);
			//?This doesn't work right now because it when you go to the page, there isn't anything for check. Address this issue when you finally decide to merge create and edit into one function.
		}
		
		$query = "SELECT * FROM announcements WHERE id='$anno_id'"; //*Get the announcement
		$anno_info = $db->runQuery($query); //*Put the anno info into this array
		foreach ($anno_info as $info) {
			/*echo "<pre>";
			print_r($info);
			echo "</pre>";*/
			$title = $info['title'];
			$description = $info['description'];
			$start_date = $info['start_date'];
			$end_date = $info['end_date'];
			$date = $info['date'];
			$location = $info['location'];
			$time = $info['time'];
		} 
		
		//*Also gonna need the anno_subtype relationships so you know what to check.
		$query = "SELECT * FROM anno_subtype WHERE anno_id='$anno_id'";
		$anno_cb = $db->runQuery($query); //*This is where the the checkbox info is
		//redirect here maybe?
		
	}
	

?>
<!DOCTYPE HTML>

<!--
Okay, this is gonna be more work. The focus of this page is to update the announcements. It's going to be few a variable from the
main page like ?id=# and this is going to have to grab that variable and use the id to fill up the slots. Then it'll fill up the
inputs based on that and ONLY UPDATE the announcement when submitted.

To do:
DONE-Grab the subtypes from db so you can check them. Remember checked="checked"
-Make it update.
-->

<html>

<head>
	<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
	<title>Update Announcement</title>
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
	<!--Credit: http://jqueryvalidation.org/-->
	<script type="text/javascript" src="js/jquery.validate.min.js"></script>
	<!--Credit: http://api.jqueryui.com/-->
	<script type="text/javascript" src="js/jquery-ui-1.10.3.custom.min.js"></script>
	<!--Credit: http://www.tinymce.com/index.php-->
	<script type="text/javascript" src="js/tinymce/tinymce.min.js"></script>
	<script type="text/javascript" src="js/scripts.js"></script>
	<script type="text/javascript">
	$(document).ready(
		function(){	
			jQuery.validator.addMethod("notEqual", function(value, element, param) {return this.optional(element) || value != param;}, "Please specify a different (non-default) value");
			$("form").validate({
				ignore: "",
				rules: {
					title: {
						required: true,
					},
					description: {
						required: true,
					},
					start_date: {
						required: true,
					},
					end_date: {
						required: true,
					}
				}
			});
			
			$("#start_date").datepicker({ dateFormat: "yy-mm-dd" });
			$("#end_date").datepicker({ dateFormat: "yy-mm-dd" });
			$("#date").datepicker({ dateFormat: "yy-mm-dd" });<commit_msg>Datepicker changes<commit_after><?php 
session_start(); 
include('lib/config.php');
include('lib/db.class.php');
include('include_classes.php');
include('functions.php');

ini_set('display_errors', 0);
error_reporting(E_ALL);

$db = new Db($dbConfig);
$error = new error();

c_cookie::enforce_log();
?>

<?php 
$user_id = $_SESSION['user_id']; 
$admin_p = $_SESSION['admin'];
$teacher_p = $_SESSION['teacher'];
$club_p = $_SESSION['club'];
$sports_p = $_SESSION['sports'];
$staff_p = $_SESSION['staff'];
?>

<?php
	//Inserting stuff.
	if(!empty($_REQUEST)) {
		//$anno_id = 17;
		$anno_id = $_REQUEST['anno_id']; //*Get the announcment id from the address
		
		//*This is for updating the announcements
		$subtype_ids = $_REQUEST['check']; //check is the name of the checkbox array. Subtype_ids contains all the subtypes that the announcement is associated with.
		if(!empty($subtype_ids)) {
			//*Insert the actual announcement into the announcement table
			$title = mysql_real_escape_string($_REQUEST['title']);
			$description = mysql_real_escape_string( $_REQUEST['description'] );
			$start_date = mysql_real_escape_string($_REQUEST['start_date']);
			$end_date = mysql_real_escape_string($_REQUEST['end_date']);
			$date = mysql_real_escape_string($_REQUEST['date']);
			$location = mysql_real_escape_string($_REQUEST['location']);
			$time = mysql_real_escape_string($_REQUEST['time']);
			
			$query = "UPDATE announcements SET title='$title', description='$description', start_date='$start_date', end_date='$end_date', date='$date', location='$location', time='$time' WHERE id='$anno_id';";
			mysql_query($query);

			//*Insert the anno_subtype relationship into its table
			//*First delete all the existing ones
			$query = "DELETE FROM anno_subtype WHERE anno_id='$anno_id'";
			mysql_query($query);
			
			//*Then, insert the new ones.
			foreach($subtype_ids as $subtype_id) {
				$query = "INSERT INTO anno_subtype(anno_id, subtype_id) VALUES('$anno_id', '$subtype_id');";
				mysql_query($query);
			}
			header("Location: main.php?current=1");
		} else {
			//$message = "You must check a category.";
			//$error->set_message($message);
			//?This doesn't work right now because it when you go to the page, there isn't anything for check. Address this issue when you finally decide to merge create and edit into one function.
		}
		
		$query = "SELECT * FROM announcements WHERE id='$anno_id'"; //*Get the announcement
		$anno_info = $db->runQuery($query); //*Put the anno info into this array
		foreach ($anno_info as $info) {
			/*echo "<pre>";
			print_r($info);
			echo "</pre>";*/
			$title = $info['title'];
			$description = $info['description'];
			$start_date = $info['start_date'];
			$end_date = $info['end_date'];
			$date = $info['date'];
			$location = $info['location'];
			$time = $info['time'];
		} 
		
		//*Also gonna need the anno_subtype relationships so you know what to check.
		$query = "SELECT * FROM anno_subtype WHERE anno_id='$anno_id'";
		$anno_cb = $db->runQuery($query); //*This is where the the checkbox info is
		//redirect here maybe?
		
	}
	

?>
<!DOCTYPE HTML>

<!--
Okay, this is gonna be more work. The focus of this page is to update the announcements. It's going to be few a variable from the
main page like ?id=# and this is going to have to grab that variable and use the id to fill up the slots. Then it'll fill up the
inputs based on that and ONLY UPDATE the announcement when submitted.

To do:
DONE-Grab the subtypes from db so you can check them. Remember checked="checked"
-Make it update.
-->

<html>

<head>
	<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
	<title>Update Announcement</title>
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
	<!--Credit: http://jqueryvalidation.org/-->
	<script type="text/javascript" src="js/jquery.validate.min.js"></script>
	<!--Credit: http://api.jqueryui.com/-->
	<script type="text/javascript" src="js/jquery-ui-1.10.3.custom.min.js"></script>
	<!--Credit: http://www.tinymce.com/index.php-->
	<script type="text/javascript" src="js/tinymce/tinymce.min.js"></script>
	<script type="text/javascript" src="js/scripts.js"></script>
	<script type="text/javascript">
	$(document).ready(
		function(){	
			jQuery.validator.addMethod("notEqual", function(value, element, param) {return this.optional(element) || value != param;}, "Please specify a different (non-default) value");
			$("form").validate({
				ignore: "",
				rules: {
					title: {
						required: true,
					},
					description: {
						required: true,
					},
					start_date: {
						required: true,
					},
					end_date: {
						required: true,
					}
				}
			});
			
			$("#anno_text_start_date").datepicker({ dateFormat: "yy-mm-dd" });
			$("#anno_text_end_date").datepicker({ dateFormat: "yy-mm-dd" });
			$("#anno_text_date").datepicker({ dateFormat: "yy-mm-dd" });
{'fraction_non_alphanumeric': 0.1693208671529847, 'fraction_numerical': 0.0024658378711599712, 'mean_word_length': 4.301742919389978, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7597630', 'n_tokens_mistral': 3529, 'n_tokens_neox': 3100, 'n_words': 833}