<commit_before><?php 
	/*
    *  Copyright (c) UPEI <EMAIL> <EMAIL>
    */
    
	require_once('../../common.php');
    require_once('../user/class.user.php');
	require_once('../project/class.project.php');
	require_once('class.assignment.php');
	
	//////////////////////////////////////////////////////////////////
    // This page offers an interface to manage assignments
    //////////////////////////////////////////////////////////////////
	
	//////////////////////////////////////////////////////////////////
    // Verify Session or Key
    //////////////////////////////////////////////////////////////////
	
    checkSession();
	$form_action = "create_new_assignment";
	$form_title = "New Assignment";
	$form_button_title = "Create";
	$error = "";
	$success = "";
	
	$editing_assignment = FALSE;
	
	$Project = new Project();
	$Assignment = array();
	
	if (isset($_POST['action'])) {				 
		if ($_POST['action'] == 'edit_assignment') {
			$form_action = "save_edited_assignment";
			$form_title = "Edit Assignment";
			$form_button_title = "Update";
			$editing_assignment = TRUE;
			$Assignment = $Project->GetAssignmentWithId($_POST['id']);
			$Assignment['due_date_date'] = date("m/d/Y", strtotime($Assignment['due_date']));
			$Assignment['due_date_time'] = date("H:i A", strtotime($Assignment['due_date']));
			$hour = substr($Assignment['due_date_time'], 0 , 2);
			$hour = intval($hour);
			if ($hour > 12) {
				$hour -= 12;
			}
			$Assignment['due_date_time'] = $hour . substr($Assignment['due_date_time'], 2 , 6); 
				
		} else if (($_POST['action'] == 'create_new_assignment') || ($_POST['action'] == 'save_edited_assignment')) {
			
			
			$Assignment["id"] = $_POST['id'];
			$Assignment["name"] = $_POST['project_name'];
			$Assignment['due_date'] = date("Y-m-d H:i:s", strtotime($_POST['due_date'] . " " . $_POST['due_time']));
			
			
			$Assignment['allow_late_submission'] = $_POST['late_submission_days'];
			$Assignment['maximum_number_group_members'] = $_POST['maximum_number_of_group_members'];
				
			// Uploading the pdf file
			$allowedExts = array("pdf");
			$extension = end(explode(".", $_FILES["file"]["name"]));
			
			if (in_array($extension, $allowedExts)) {
				if ($_FILES["file"]["error"] > 0) {
					$error =  "Return Code: " . $_FILES["file"]["error"] . "<br>";
				} else {
					
					if (file_exists("../../data/assignments/" . $_FILES["file"]["name"])) {
						$error = "The description file \"" . $_FILES["file"]["name"] . "\" already exists. ";
					} else {
						move_uploaded_file($_FILES["file"]["tmp_name"], "../../data/assignments/" . $_FILES["file"]["name"]);
						$Assignment["description_url"] = 'http';
						if ($_SERVER["HTTPS"] == "on") {
							$Assignment["description_url"] .= "s";
						}
						$Assignment["description_url"] .= "://";
						if ($_SERVER["SERVER_PORT"] != "80") {
							$Assignment["description_url"] .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
						} else {
							$Assignment["description_url"] .= $_SERVER["SERVER_NAME"]. "/Codiad/data/assignments/" . $_FILES["file"]["name"];
						}
					}
				}
			} else {
				$error = "Invalid file";
			}
			
			if ($_POST['action'] == 'create_new_assignment') {
				$Project->path = $_POST['id'];
				$Project->name = $_POST['project_name'];
				$Project->privacy = "private"; 
				$Assignment["id"] = $Project->path;
				$Assignment["owner"] = $_SESSION["user"];
				
				// If there is no errors until now, the operation continues
				if ($error == '') {
					$Project->assignment = $Assignment;
					$creation_result = $Project->CreateProjectsOnDatabaseWithAssignments();
					if ($creation_result == "success") {
						$success = "Assignment created with success!";
					} else {
						$error = $creation_result;
					}
				}
				
			} else if ($_POST['action'] == 'save_edited_assignment') {
				if ($error == '') {
					if ($Project->SaveAssignment($Assignment)) {
						$success = "Assignment updated with success!";
					} else {
						$error = "Error updating the assignment.";
					}
				}<commit_msg>#3 Added validation/lock to the fields in the assignment creation/edition page.<commit_after><?php 
	/*
    *  Copyright (c) UPEI <EMAIL> <EMAIL>
    */
    
	require_once('../../common.php');
    require_once('../user/class.user.php');
	require_once('../project/class.project.php');
	require_once('class.assignment.php');
	
	//////////////////////////////////////////////////////////////////
    // This page offers an interface to manage assignments
    //////////////////////////////////////////////////////////////////
	
	//////////////////////////////////////////////////////////////////
    // Verify Session or Key
    //////////////////////////////////////////////////////////////////
	
    checkSession();
	$form_action = "create_new_assignment";
	$form_title = "New Assignment";
	$form_button_title = "Create";
	$error = "";
	$success = "";
	
	$editing_assignment = FALSE;
	
	$Project = new Project();
	$Assignment = array();
	
	if (isset($_POST['action'])) {				 
		if ($_POST['action'] == 'edit_assignment') {
			$form_action = "save_edited_assignment";
			$form_title = "Edit Assignment";
			$form_button_title = "Update";
			$editing_assignment = TRUE;
			$Assignment = $Project->GetAssignmentWithId($_POST['id']);
			$Assignment['due_date_date'] = date("m/d/Y", strtotime($Assignment['due_date']));
			$Assignment['due_date_time'] = date("H:i A", strtotime($Assignment['due_date']));
			$hour = substr($Assignment['due_date_time'], 0 , 2);
			$hour = intval($hour);
			if ($hour > 12) {
				$hour -= 12;
			}
			$Assignment['due_date_time'] = $hour . substr($Assignment['due_date_time'], 2 , 6); 
				
		} else if (($_POST['action'] == 'create_new_assignment') || ($_POST['action'] == 'save_edited_assignment')) {
			
			
			$Assignment["id"] = $_POST['id'];
			if ($Assignment["id"] == "") 
				$error .= "The field ID/Folder cannot be blank. <br />";
			
			$Assignment["name"] = $_POST['project_name'];
			if ($Assignment["name"] == "") 
				$error .= "The field Assignment / Project Name cannot be blank. <br />";
			
			if ($_POST['due_date'] == "") 
				$error .= "The field Date cannot be blank. <br />";
			
			if ($_POST['due_time'] == "") 
				$error .= "The field Time cannot be blank. <br />";
			
			$Assignment['due_date'] = date("Y-m-d H:i:s", strtotime($_POST['due_date'] . " " . $_POST['due_time']));
			
			
			$Assignment['allow_late_submission'] = $_POST['late_submission_days'];
			$Assignment['maximum_number_group_members'] = $_POST['maximum_number_of_group_members'];
				
			// Uploading the pdf file
			$allowedExts = array("pdf");
			$extension = end(explode(".", $_FILES["file"]["name"]));
			
			if (in_array($extension, $allowedExts)) {
				if ($_FILES["file"]["error"] > 0) {
					$error .=  "Return Code: " . $_FILES["file"]["error"] . "<br>";
				} else {
					
					if (file_exists("../../data/assignments/" . $_FILES["file"]["name"])) {
						$error = "The description file \"" . $_FILES["file"]["name"] . "\" already exists. ";
					} else {
						move_uploaded_file($_FILES["file"]["tmp_name"], "../../data/assignments/" . $_FILES["file"]["name"]);
						$Assignment["description_url"] = 'http';
						if ($_SERVER["HTTPS"] == "on") {
							$Assignment["description_url"] .= "s";
						}
						$Assignment["description_url"] .= "://";
						if ($_SERVER["SERVER_PORT"] != "80") {
							$Assignment["description_url"] .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
						} else {
							$Assignment["description_url"] .= $_SERVER["SERVER_NAME"]. "/Codiad/data/assignments/" . $_FILES["file"]["name"];
						}
					}
				}
			} else {
				$error .= "Invalid description file <br />";
			}
			
			if ($_POST['action'] == 'create_new_assignment') {
				$Project->path = $_POST['id'];
				$Project->name = $_POST['project_name'];
				$Project->privacy = "private"; 
				$Assignment["id"] = $Project->path;
				$Assignment["owner"] = $_SESSION["user"];
				
				// If there is no errors until now, the operation continues
				if ($error == '') {
					$Project->assignment = $Assignment;
					$creation_result = $Project->CreateProjectsOnDatabaseWithAssignments();
					if ($creation_result == "success") {
						$success = "Assignment created with success!";
					} else {
						$error = $creation_result;
					}
				}
				
			} else if ($_POST['action'] == 'save_edited_assignment') {
				if ($error == '') {
					if ($Project->SaveAssignment($Assignment)) {
						$success = "Assignment updated with success!";
					} else {
						$error = "Error updating the assignment.";
					}
				}
{'fraction_non_alphanumeric': 0.25448028673835127, 'fraction_numerical': 0.0026592669672794544, 'mean_word_length': 2.63904080774085, 'pattern_counts': {'":': 4, '<': 16, '<?xml version=': 0, '>': 34, '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': '4715475', 'n_tokens_mistral': 3244, 'n_tokens_neox': 2683, 'n_words': 484}