<commit_before><?php	

require_once 'note-base.php';

class NoteEdit extends Note {

	function __construct() {
		parent::__construct();
	}

	function addNote($id, $text, $tags, $title) {
		$tags = serialize($tags);

		$stmt = $this->db->prepare('INSERT INTO note(NoteTitle, NoteText, NoteTags, UserId) VALUES (:title, :text, :tags, :userId)');
		$stmt->execute(array(':title' => $title, ':text' => $text, ':tags' => $tags, ':userId' => $id));
		
		echo $this->db->lastInsertId();
	}

	function deleteNote($noteId) {
		$stmt = $this->db->prepare('DELETE FROM note WHERE NoteId = :noteId');
		$stmt->execute(array(':noteId' => $noteId));
		echo 'Complete';
	}

	function editNote($id, $text, $title, $tags) {
		
		$tags = serialize($tags);
		$stmt = $this->db->prepare('UPDATE note SET NoteText = :text, NoteTitle = :title, NoteTags = :tags WHERE NoteId = :id ');
		$stmt->execute(array(':text' => $text, ':title' => $title, ':tags' => $tags, ':id' => $id));
		
		echo $id . ' has been updated.';
	}
}

if($_SERVER['REQUEST_METHOD'] == 'POST' && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
	
	$action = $_POST['action'];
	$note = new NoteEdit();

	if(isset($_POST['noteText']) && ($action === 'addnote')) {
		$tags = isset($_POST['noteTags']) ? $_POST['noteTags'] : '';
		$note->addNote($_POST['userId'], $_POST['noteText'], $tags, $_POST['noteTitle']);
	} else if(isset($_POST['deleteNote']) && ($action === 'deletenote')) {
		$note->deleteNote($_POST['deleteNote']);
	} else if(($action === 'editnote') && isset($_POST['noteText']) && isset($_POST['noteId'])) {
		$tags = isset($_POST['noteTags']) ? $_POST['noteTags'] : '';
		$note->editNote($_POST['noteId'], $_POST['noteText'], $_POST['noteTitle'], $tags);
	}

	$note = null;

} else {
	die('No direct access!');
}

?><commit_msg>Change to the base note file<commit_after><?php

class Note {
	public $db = null;
	public $email = '';
	public $password = '';
	public $id = 0;

	function __construct() {
		require_once 'db-connect.inc.php';
		$this->db = Database::ConnectDb();
	}
}

?>
{'fraction_non_alphanumeric': 0.23816495851634945, 'fraction_numerical': 0.0004880429477794046, 'mean_word_length': 5.119402985074627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '1308119', 'n_tokens_mistral': 756, 'n_tokens_neox': 716, 'n_words': 151}