<?php 
/**
 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 * @desc This allows students to create documents in the student publication tool. 
*/
		if ($_GET['action']=='create_document' and !$_POST['SubmitCreateDocument'])
		{
			echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."?action=create_document\">";
			echo '<table>';
			echo '<tr>';
			echo '<td align="right"><strong>'.get_lang('Title').'</strong></td>';
			echo '<td><input name="title" value="" size="30" type="text"></td>';
			echo '</tr>';
			echo '<tr>';
			echo '<td align="right" valign="top"><strong>'.get_lang('Authors').'</strong>&nbsp;&nbsp;</td>';
			echo '<td><input name="authors" value="'.$_user['firstName'].' '.$_user['lastName'].'" size="30" type="text">';
			echo '</td>';
			echo '</tr>';
			echo '<tr>';
			echo '<td align="right" valign="top"><strong>'.get_lang('Description').'</strong></td>';
			echo '<td><textarea name="description" cols="30" rows="3"></textarea></td>';
			echo '</tr>';
			echo '</table>';
			
			api_disp_html_area('create_studentpublication',$content,'300px');
			echo '<input type="submit" name="SubmitCreateDocument" value="Submit">';
			echo "</form>";
		}
		if ($_POST['SubmitCreateDocument'])
		{
			$work_dir = $currentCourseRepositorySys.'work/';
			$filename = time().'.html';
			$fp=@fopen($work_dir.$filename,'w');
			fputs($fp,$_POST['create_studentpublication']);
			fclose($fp);
			
			$title=strip_tags($_POST['title']); 
			if ($title=='')
			{
				$title=$filename;
			}
			
			$sql_add_publication = "INSERT INTO ".$work_table."
		               SET url         = 'work/".$filename."',
					       title       = '".$title."',
		                   description = '".strip_tags($_POST['description'])."',
		                   author      = '".strip_tags($_POST['authors'])."',
						   active		= '".$active."',
						   accepted		= '".(!$uploadvisibledisabled)."',
						   sent_date			= NOW()";
			api_sql_query($sql_add_publication);
			
		}		
?>