<commit_before><?php

	/*
	Long term TODOs editing and viewing. Part of My Daily Todo -project.
	Copyright (C) 2009 <NAME> <<EMAIL>>
	 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
	*/	

	session_start();
	require 'general_functions.php';

	function delete_todo( $id )
	{
		$todo_file = 'users/' . $_SESSION['username'] 
			. '/future_todo.txt';

		// Make sure that todo file exists at all.
		if(! file_exists( $todo_file ) )
			return false;

		// Read old data from file
		$data = file( $todo_file, FILE_IGNORE_NEW_LINES );
		$i = 0;

		// We rewrite the whole file, so open it for writing.
		$fh = fopen( $todo_file, 'w' );

		if(! $fh )
		{
			echo 'Failed to open TODO file for writing.';
			return false;
		}

		foreach( $data as $line )
		{
			$i++;

			if( $i != $id )
				fwrite( $fh, $line . "\n" );
		}

		fclose( $fh );
		return true;
	}

	function check_post_values()
	{
		// Is there POST-data where are new TODO's?
		if( isset( $_POST['todo'] ) )
		{
			$todo_file = 'users/' . $_SESSION['username'] 
				. '/future_todo.txt';

			// Try to open todo-file for writing.
			$fh = fopen( $todo_file, 'w' );

			if(! $fh )
			{
				echo 'Error when writing file!';
				return;
			}

			// Write all non-empty lines to TODO-file.
			foreach( $_POST['todo'] as $item )
			{
				if( $item != '' )
					fwrite( $fh, $item . "\n" );
			}

			fclose( $fh );
		}
	}

	function show_future_todos()
	{
		$todo_file = 'users/' . $_SESSION['username'] <commit_msg>Check if user folder exists before add future todo.<commit_after><?php

	/*
	Long term TODOs editing and viewing. Part of My Daily Todo -project.
	Copyright (C) 2009 <NAME> <<EMAIL>>
	 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
	*/	

	session_start();
	require 'general_functions.php';

	function delete_todo( $id )
	{
		$todo_file = 'users/' . $_SESSION['username'] 
			. '/future_todo.txt';

		// Make sure that todo file exists at all.
		if(! file_exists( $todo_file ) )
			return false;

		// Read old data from file
		$data = file( $todo_file, FILE_IGNORE_NEW_LINES );
		$i = 0;

		// We rewrite the whole file, so open it for writing.
		$fh = fopen( $todo_file, 'w' );

		if(! $fh )
		{
			echo 'Failed to open TODO file for writing.';
			return false;
		}

		foreach( $data as $line )
		{
			$i++;

			if( $i != $id )
				fwrite( $fh, $line . "\n" );
		}

		fclose( $fh );
		return true;
	}

	function check_post_values()
	{
		// Is there POST-data where are new TODO's?
		if( isset( $_POST['todo'] ) )
		{
			$todo_file = 'users/' . $_SESSION['username'] 
				. '/future_todo.txt';

			if(! file_exists( 'users/' . $_SESSION['username'] ) )
			{
				if(! mkdir( 'users/' . $_SESSION['username'], 0755 ) )
					echo 'Failed to create new folder!';
			}

			// Try to open todo-file for writing.
			$fh = fopen( $todo_file, 'w' );

			if(! $fh )
			{
				echo 'Error when writing file!';
				return;
			}

			// Write all non-empty lines to TODO-file.
			foreach( $_POST['todo'] as $item )
			{
				if( $item != '' )
					fwrite( $fh, $item . "\n" );
			}

			fclose( $fh );
		}
	}

	function show_future_todos()
	{
		$todo_file = 'users/' . $_SESSION['username'] 
{'fraction_non_alphanumeric': 0.12653618570778333, 'fraction_numerical': 0.0036413290851160674, 'mean_word_length': 2.7119932432432434, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '2294317', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1447, 'n_words': 529}