Location: PHPKode > projects > Work project > workproject/add_taskuser.php
<?
include ("include_config.inc");
include ("include_profile_name.inc");
include ("include_project_name.inc");
include ("include_log_file.inc");
include ("include_delete_task.inc");
include ("include_delete_project.inc");
include ("include_delete_profile.inc");
include ("include_update_user.inc"); 
include ("include_delete_user.inc");
include ("include_list_user.inc");
include ("include_state_name.inc");
include ("include_user_name.inc");
include ("include_workload_project.inc");
include ("include_dates_project.inc");
include ("include_display_comment.inc");
include ("include_button.inc");

if ( isset( $HTTP_COOKIE_VARS[$g_string_cookie] ) ) {
	$g_string_cookie_val         = $HTTP_COOKIE_VARS[$g_string_cookie];
	write_log_user ($filename_log, "Cookie created 1.1: ".$g_string_cookie." -- ".$g_string_cookie_val);
}
if ( isset( $HTTP_COOKIE_VARS[$g_project_cookie] ) ) {
	$g_project_cookie_val        = $HTTP_COOKIE_VARS[$g_project_cookie];
	write_log_user ($filename_log, "Cookie created 2.1: ".$g_project_cookie." -- ".$g_project_cookie_val);
}

/* check the login for user */
login_cookie_check();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Your tasks - Add task to a selected user</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<? include ("include_css.inc"); ?>
<script src="main.js" type="text/javascript"></script>
<script src="tasks.js" type="text/javascript"></script>
<script src="nav.js" type="text/javascript"></script>

</head>
<BODY onload="init()">

<?
include ("include_mail.inc");
include ("include_main.inc");
?>

<?php

/* connection to the database */
$link= mysql_connect($g_hostname, $g_db_username, $g_db_password) or die("could not connect");
$result = mysql_select_db($g_database_name);

write_log_user ($filename_log, "Add or update task for the selected user.");

/* read of the user connected */
$connected_user = user_connected();
$profile_connected_user = user_profile($connected_user);
$name_connected_user = user_name($connected_user,$g_database_name);
$name_profile_connected_user = profile_name($profile_connected_user);
display_connected_user($name_connected_user,$name_profile_connected_user);

/* delete created or selected task */
if ($delete == "1" AND $select_task !="") {
	/* delete of the task */
	write_log_user($filename_log, "Delete of the task: ".$select_task." ");

	$result_delete = delete_task($select_task);
	if (!$result_delete) {
		write_log_user($filename_log, "delete result for the selected task: ".$result_delete." ");
		$is_comment=$is_comment."<br> delete result for the selected task: ".$result_delete." ";
		display_comment($is_comment);
	} else {
		$result_delete = 'OK';
	}
	$delete = 0;
	mysql_query("COMMIT");

	$is_comment=$is_comment."<br> Delete task done: ".$result_delete;
	display_comment($is_comment);

	$TASK_NAME ="";
	$select_task= "";
}

/* create task */
if($TASK_NAME!="" AND $select_task == "") {

	/* seek for the highest task code */
	$result = mysql($g_database_name,"SELECT TASK_CODE FROM TASK order by TASK_CODE ASC");
	$total_rows = mysql_numrows($result);
	if ($total_rows == 0 ) {
		$taskcode = 1;		
	} else {
		$taskcode = mysql_result($result,$total_rows-1,TASK_CODE);
		write_log_user ($filename_log, "Add task Error: ". mysql_error() );
		$taskcode = $taskcode + 1;
	}
	mysql_free_result($result);

	/* add task to the selected user */
	if ($USER_CODE_VERIF == "") $USER_CODE_VERIF='NULL';
	if ($PROJECT_CODE == "") $PROJECT_CODE = 'NULL';
	$TASK_STATE=1; /* created */
	if ($USER_CODE_COPY == "") $USER_CODE_COPY='NULL';
	if ($USER_ASSIGN == "") $USER_ASSIGN=$userid;
	
	/* end date = start date if empty */
	$TASK_DATE_START_PLANNED = $task_year."-".$task_month."-".$task_day;
	if ($TASK_DATE_START_PLANNED == "--") $TASK_DATE_START_PLANNED = date('Y-m-d');
	$TASK_DATE_END_PLANNED = $task_year2."-".$task_month2."-".$task_day2;
	if ($TASK_DATE_END_PLANNED == "--") $TASK_DATE_END_PLANNED = $TASK_DATE_START_PLANNED;
	$TASK_DATE_START_DONE = $TASK_DATE_START_PLANNED;
	$TASK_DATE_END_DONE = $TASK_DATE_END_PLANNED;
	$date_creation = date('Y-m-d'); 	 /* by default, curent date */
	if ($WORKLOAD == "") $WORKLOAD = 'NULL';
	if ($WORKLOAD_TODO == "") $WORKLOAD_TODO = $WORKLOAD;
	if ($WORKLOAD_FINAL == "") $WORKLOAD_FINAL = 'NULL';
	if($TASK_COMMENT == "") $TASK_COMMENT='NULL';
	if($TASK_RESULT == "") $TASK_RESULT='NULL';
	if($TASK_FATHER_CODE == "") $TASK_FATHER_CODE='NULL';
	if($TASK_SON_CODE == "") $TASK_SON_CODE='NULL';

	write_log_user ($filename_log, "INSERT INTO TASK (TASK_CODE,TASK_NAME,USER_CODE_CREATOR,PROJECT_CODE,USER_CODE_ASSIGNED,TASK_STATE,USER_CODE_VERIF,USER_CODE_COPY,WORKLOAD,WORKLOAD_TODO,WORKLOAD_FINAL,CREATION_TASK_DATE,TASK_DATE_START_PLANNED,TASK_DATE_END_PLANNED) 
	VALUES ($taskcode,'$TASK_NAME',$userid,$PROJECT_CODE,$USER_ASSIGN,$TASK_STATE,$USER_CODE_VERIF,$USER_CODE_COPY,$WORKLOAD,$WORKLOAD_TODO,$WORKLOAD_FINAL,'$date_creation','$TASK_DATE_START_PLANNED','$TASK_DATE_END_PLANNED')" );

	/* prepare the comment */
	$m_comment	= string_prepare_textarea( $TASK_COMMENT );
	write_log_user ($filename_log, "add task m_comment: ".$m_comment );

	$query_add = "INSERT INTO TASK 
			(TASK_CODE,TASK_NAME,
			USER_CODE_CREATOR,PROJECT_CODE,
			USER_CODE_ASSIGNED,TASK_STATE,
			USER_CODE_VERIF,USER_CODE_COPY,
			WORKLOAD,WORKLOAD_TODO,WORKLOAD_FINAL,
			CREATION_TASK_DATE,
			TASK_DATE_START_PLANNED,
			TASK_DATE_END_PLANNED,
			TASK_DATE_START_DONE,
			TASK_DATE_END_DONE,
			TASK_RESULT,TASK_COMMENT,
			TASK_FATHER_CODE,TASK_SON_CODE) 
			VALUES ($taskcode,'$TASK_NAME',
				$connected_user,$PROJECT_CODE,
				$USER_ASSIGN,$TASK_STATE,
				$USER_CODE_VERIF,$USER_CODE_COPY,
				$WORKLOAD,$WORKLOAD_TODO,$WORKLOAD_FINAL,
				'$date_creation',
				'$TASK_DATE_START_PLANNED',
				'$TASK_DATE_END_PLANNED',
				'$TASK_DATE_START_DONE',
				'$TASK_DATE_END_DONE',
				'$TASK_RESULT','$m_comment',
				'$TASK_FATHER_CODE','$TASK_SON_CODE')";

	mysql_query($query_add) or $mysql_eval_error_add = mysql_error();
	if ($mysql_eval_error_add) {
		write_log_user ($filename_log, "Add task Error: ". mysql_error() );
		$is_comment=$is_comment."<br> task not added: ". mysql_error();
		display_comment($is_comment);
	} else {

		/* update the related tasks */
		if ( $TASK_FATHER_CODE != 'NULL') {
			$query_update_related = "UPDATE TASK SET TASK_SON_CODE='$taskcode' where TASK_CODE=$TASK_FATHER_CODE";
			mysql_query($query_update_related) or $error_update_related = mysql_error();
			write_log_user ($filename_log, "Update related task: ".$error_update_related  );
		}
		if ( $TASK_FATHER_CODE != 'NULL') {
			$query_update_related = "UPDATE TASK SET TASK_FATHER_CODE='$taskcode' where TASK_CODE=$TASK_SON_CODE";
			mysql_query($query_update_related) or $error_update_related = mysql_error();
			write_log_user ($filename_log, "Update related task: ".$error_update_related  );
		}
		
		if ( $PROJECT_CODE != 'NULL') {
			$query_insert_user ="INSERT INTO PROJECT_USER (PROJECT_CODE,USERID)
					VALUES ($PROJECT_CODE,$USER_ASSIGN)";
			mysql_query($query_insert_user) or $error_insert_user = mysql_error();
			write_log_user ($filename_log, "Insert user Project_user error: ".$error_insert_user );
		}
		
		/* display a warning on the screen */
		mysql_query("COMMIT");
		$is_comment=$is_comment."<br> Add task OK: ".$taskcode;
		display_comment($is_comment);

		/* send mail */
		task_send_mail($USER_ASSIGN,$taskcode,$TASK_NAME,$TASK_COMMENT,$PROJECT_CODE,
			$TASK_DATE_START_PLANNED,$TASK_DATE_END_PLANNED,$WORKLOAD,$TASK_STATE);
	}
	/* copy task for the selected copy user */
	if ($USER_CODE_COPY != 'NULL') {
		$taskcode = $taskcode + 1;
		if ($TASK_STATE_COPY == "") $TASK_STATE_COPY=2; /* distributed */

		$query_add = "INSERT INTO TASK (TASK_CODE,TASK_NAME,USER_CODE_CREATOR,PROJECT_CODE,USER_CODE_ASSIGNED,TASK_STATE,USER_CODE_VERIF,USER_CODE_COPY,WORKLOAD,WORKLOAD_FINAL,CREATION_TASK_DATE,TASK_DATE_START_PLANNED,TASK_DATE_END_PLANNED,TASK_DATE_START_DONE,TASK_DATE_END_DONE,TASK_RESULT,TASK_COMMENT,TASK_FATHER_CODE,TASK_SON_CODE) 
		VALUES ($taskcode,'$TASK_NAME',$connected_user,$PROJECT_CODE,$USER_CODE_COPY,$TASK_STATE_COPY,$USER_CODE_VERIF,$USER_CODE_COPY,$WORKLOAD,$WORKLOAD_FINAL,
'$date_creation','$TASK_DATE_START_PLANNED','$TASK_DATE_END_PLANNED','$TASK_DATE_START_DONE','$TASK_DATE_END_DONE','$TASK_RESULT','$TASK_COMMENT','$TASK_FATHER_CODE','$TASK_SON_CODE')" ;

		mysql_query($query_add) or $mysql_eval_error_add = mysql_error();
		if ($mysql_eval_error_add) {
			write_log_user ($filename_log, "Add task Error for copy user: ". mysql_error() );
			$is_comment=$is_comment."<br> Add task Error for copy user: ". mysql_error();
			display_comment($is_comment);
		} else {
			/* not related task for the the copied task */
			
			mysql_query("COMMIT");

			$is_comment=$is_comment."<br> Add task OK for copy: ".$taskcode ;
			display_comment($is_comment);

			/* send mail */
			task_send_mail($USER_CODE_COPY,$taskcode,$TASK_NAME,$TASK_COMMENT,$PROJECT_CODE,
				$TASK_DATE_START_PLANNED,$TASK_DATE_END_PLANNED,$WORKLOAD,$TASK_STATE_COPY);
		}
	}

}

/* update the created or selected task */
if($TASK_NAME!="" AND $select_task != "") {
	/* add task to the selected user */
	if ($USER_CODE_VERIF == "") $USER_CODE_VERIF='NULL';
	if ($PROJECT_CODE == "") $PROJECT_CODE = 'NULL';
	if ($TASK_STATE == "") $TASK_STATE=3; /* modified */
	if ($USER_CODE_COPY == "") $USER_CODE_COPY='NULL';
	if ($USER_ASSIGN == "") $USER_ASSIGN=$userid;
	
	/* end date = start date if empty */
	/* the planned dates are not updated, only the done dates */
	$TASK_DATE_START_DONE = $task_year."-".$task_month."-".$task_day;	
	if ($TASK_DATE_START_DONE == "--") $TASK_DATE_START_DONE = date('Y-m-d');
	$TASK_DATE_END_DONE = $task_year2."-".$task_month2."-".$task_day2;	
	if ($TASK_DATE_END_DONE == "--") $TASK_DATE_END_DONE = $TASK_DATE_START_DONE;
	$date_creation = date('Y-m-d'); 	 /* by default, curent date */
	if ($WORKLOAD == "") $WORKLOAD = 'NULL';
	#if ($WORKLOAD_TODO == "") $WORKLOAD_TODO = $WORKLOAD;
	#if ($WORKLOAD_FINAL == "") $WORKLOAD_FINAL = 'NULL';
	if($TASK_COMMENT == "") $TASK_COMMENT='NULL';
	if($TASK_RESULT == "") $TASK_RESULT='NULL';
	if($TASK_FATHER_CODE == "") $TASK_FATHER_CODE='NULL';
	if($TASK_SON_CODE == "") $TASK_SON_CODE='NULL';
	
	$m_comment	= string_prepare_textarea( $TASK_COMMENT );
	$m_result	= string_prepare_textarea( $TASK_RESULT );

	# WORKLOAD_TODO=$WORKLOAD_TODO,
	# WORKLOAD_FINAL=$WORKLOAD_FINAL,

	$query_update = "UPDATE TASK SET
			TASK_NAME='$TASK_NAME' ,
			USER_CODE_CREATOR=$connected_user,
			PROJECT_CODE=$PROJECT_CODE,
			USER_CODE_ASSIGNED=$USER_ASSIGN,
			TASK_STATE=$TASK_STATE,
			USER_CODE_VERIF=$USER_CODE_VERIF,
			USER_CODE_COPY=$USER_CODE_COPY,
			WORKLOAD=$WORKLOAD,
			CREATION_TASK_DATE='$date_creation',
			TASK_DATE_START_DONE='$TASK_DATE_START_DONE',
			TASK_DATE_END_DONE='$TASK_DATE_END_DONE',
			TASK_RESULT='$m_result',
			TASK_COMMENT='$m_comment',
			TASK_FATHER_CODE='$TASK_FATHER_CODE',
			TASK_SON_CODE='$TASK_SON_CODE'
			 where TASK_CODE=$select_task";
	write_log_user ($filename_log, "Query update: ".$query_update );
	mysql_query($query_update) or $mysql_eval_error_update = mysql_error();
	if ($mysql_eval_error_update) {
		write_log_user ($filename_log, "Update task Error: ". mysql_error() );
		$is_comment=$is_comment."<br> Task not updated: ". mysql_error();
		display_comment($is_comment);
	} else {

		/* update the related tasks */
		if ( $select_task_ex_previous != ""){
			$query_update_related = "UPDATE TASK SET TASK_SON_CODE='NULL' where TASK_CODE=$select_task_ex_previous";
			mysql_query($query_update_related) or $error_update_related = mysql_error();
			write_log_user ($filename_log, "Update related task ex previous:  ".$select_task_ex_previous." ".$error_update_related  );
		}
		if ( $select_task_ex_next != "") {
			$query_update_related = "UPDATE TASK SET TASK_SON_CODE='NULL' where TASK_CODE=$select_task_ex_next";
			mysql_query($query_update_related) or $error_update_related = mysql_error();
			write_log_user ($filename_log, "Update related task ex next: ".$select_task_ex_next." ".$error_update_related  );
		}
		if ( $TASK_FATHER_CODE != 'NULL') {
			$query_update_related = "UPDATE TASK SET TASK_SON_CODE='$select_task' where TASK_CODE=$TASK_FATHER_CODE";
			mysql_query($query_update_related) or $error_update_related = mysql_error();
			write_log_user ($filename_log, "Update related task: ".$error_update_related  );
		}
		if ( $TASK_FATHER_CODE != 'NULL') {
			$query_update_related = "UPDATE TASK SET TASK_FATHER_CODE='$select_task' where TASK_CODE=$TASK_SON_CODE";
			mysql_query($query_update_related) or $error_update_related = mysql_error();
			write_log_user ($filename_log, "Update related task: ".$error_update_related  );
		}	
	
		if ( $PROJECT_CODE != 'NULL') {
			$query_insert_user ="INSERT INTO PROJECT_USER (PROJECT_CODE,USERID)
					VALUES ($PROJECT_CODE,$USER_ASSIGN)";
			mysql_query($query_insert_user) or $error_insert_user = mysql_error();
			write_log_user ($filename_log, "Insert user Project_user error: ".$error_insert_user );
		}
		mysql_query("COMMIT") or $mysql_eval_error_commit = mysql_error();
		if ($mysql_eval_error_commit) write_log_user ($filename_log, "Commit error: ".mysql_error() );

		write_log_user ($filename_log, "Update task OK: ".$select_task );
		#show_comment_screen("task updated OK");
		$is_comment=$is_comment."<br> Update task OK: ".$select_task ;
		display_comment($is_comment);

		/* send mail */
		task_send_mail($USER_ASSIGN,$select_task,$TASK_NAME,$TASK_COMMENT,$PROJECT_CODE,
				$TASK_DATE_START_PLANNED,$TASK_DATE_END_PLANNED,$WORKLOAD,$TASK_STATE);
	}
	/* copy task for the selected copy user */
	if ($USER_CODE_COPY != 'NULL' AND $USER_CODE_COPY != $USER_CODE_COPY_read ) {

		/* seek for the highest task code */
		$result = mysql($g_database_name,"SELECT TASK_CODE FROM TASK order by TASK_CODE ASC");
		$total_rows = mysql_numrows($result);
		if ($total_rows == 0 ) {
			$taskcode = 1;		
		} else {
			$taskcode = mysql_result($result,$total_rows-1,TASK_CODE);
			write_log_user ($filename_log, "Add task Error: ". mysql_error() );
			$taskcode = $taskcode + 1;
		}
		mysql_free_result($result);

		$taskcode = $taskcode + 1;
		if ($TASK_STATE_COPY == "") $TASK_STATE_COPY=2; /* distributed */
		if ($WORKLOAD_TODO == "") $WORKLOAD_TODO = $WORKLOAD;
		if ($WORKLOAD_FINAL == "") $WORKLOAD_FINAL = 'NULL';
		$TASK_DATE_START_PLANNED =$TASK_DATE_START_DONE;
		$TASK_DATE_END_PLANNED =$TASK_DATE_END_DONE;

		write_log_user ($filename_log, "Add task for copy - INSERT code: 
			INSERT INTO TASK (TASK_CODE,
			TASK_NAME,
			USER_CODE_CREATOR,
			PROJECT_CODE,
			USER_CODE_ASSIGNED,
			TASK_STATE,
			USER_CODE_VERIF,
			USER_CODE_COPY,
			WORKLOAD,
			WORKLOAD_TODO,
			WORKLOAD_FINAL,
			CREATION_TASK_DATE,
			TASK_DATE_START_PLANNED,
			TASK_DATE_END_PLANNED,
			TASK_RESULT,
			TASK_COMMENT,
			TASK_FATHER_CODE,TASK_SON_CODE) 
			VALUES ($taskcode,
			'$TASK_NAME',
			$connected_user,
			$PROJECT_CODE,
			$USER_CODE_COPY,
			$TASK_STATE_COPY,
			$USER_CODE_VERIF,
			$USER_CODE_COPY,
			$WORKLOAD,
			$WORKLOAD_TODO,
			$WORKLOAD_FINAL,
			'$date_creation',
			'$TASK_DATE_START_PLANNED',
			'$TASK_DATE_END_PLANNED',
			'$TASK_RESULT',
			'$TASK_COMMENT',
			'$TASK_FATHER_CODE','$TASK_SON_CODE')");

		$query_add = "INSERT INTO TASK (TASK_CODE,TASK_NAME,USER_CODE_CREATOR,PROJECT_CODE,USER_CODE_ASSIGNED,TASK_STATE,USER_CODE_VERIF,USER_CODE_COPY,WORKLOAD,WORKLOAD_TODO,WORKLOAD_FINAL,CREATION_TASK_DATE,TASK_DATE_START_PLANNED,TASK_DATE_END_PLANNED,TASK_RESULT,TASK_COMMENT,TASK_FATHER_CODE,TASK_SON_CODE) 
		VALUES ($taskcode,'$TASK_NAME',$connected_user,$PROJECT_CODE,$USER_CODE_COPY,$TASK_STATE_COPY,$USER_CODE_VERIF,$USER_CODE_COPY,$WORKLOAD,$WORKLOAD_TODO,$WORKLOAD_FINAL,
'$date_creation','$TASK_DATE_START_PLANNED','$TASK_DATE_END_PLANNED','$TASK_RESULT','$TASK_COMMENT','$TASK_FATHER_CODE','$TASK_SON_CODE')" ;

		mysql_query($query_add) or $mysql_eval_error_add = mysql_error();
		if ($mysql_eval_error_add) {
			write_log_user ($filename_log, "Add task Error for copy user: ". mysql_error() );
			$is_comment=$is_comment."<br> task not added: ". mysql_error();
			display_comment($is_comment);
		} else {
			mysql_query("COMMIT");

			write_log_user ($filename_log, "Add task OK for copy: ".$taskcode );
			$is_comment=$is_comment."<br> Add task OK for copy: ".$taskcode;
			display_comment($is_comment);

			/* send mail */
			task_send_mail($USER_CODE_COPY,$taskcode,$TASK_NAME,$TASK_COMMENT,$PROJECT_CODE,
				$TASK_DATE_START_PLANNED,$TASK_DATE_END_PLANNED,$WORKLOAD,$TASK_STATE_COPY);
		}
	}
}


/* view user */
$result = mysql_query("SELECT USERID,NAME,SURNAME,PROJECT_CODE,PROFIL_CODE FROM USER WHERE USERID=$select_user");
$total_rows = mysql_numrows($result);
$USERID = mysql_result($result,$counter,USERID);
$NAME= mysql_result($result,$counter,NAME);
$SURNAME= mysql_result($result,$counter,SURNAME);
$PROJECT_CODE= mysql_result($result,$counter,PROJECT_CODE);
$PROFILE_CODE= mysql_result($result,$counter,PROFIL_CODE);
$PROJECT_NAME= project_name($PROJECT_CODE);
$PROFILE_NAME= profile_name($PROFILE_CODE);

/* read created or selected task */
if ($select_task != "") {
	/*if ($TASK_NAME != "") $select_task = $taskcode;*/
	$query_select = "SELECT TASK_CODE, TASK_NAME, USER_CODE_CREATOR, PROJECT_CODE, USER_CODE_ASSIGNED, TASK_STATE, USER_CODE_VERIF, USER_CODE_COPY, WORKLOAD, WORKLOAD_TODO, WORKLOAD_FINAL, CREATION_TASK_DATE, TASK_DATE_START_PLANNED, TASK_DATE_END_PLANNED, TASK_DATE_START_DONE, TASK_DATE_END_DONE, TASK_RESULT, TASK_COMMENT, TASK_FATHER_CODE, TASK_SON_CODE FROM TASK where TASK_CODE=$select_task";
	$result_select = mysql_query($query_select) or $mysql__eval_error_select = mysql_error();
	if ($mysql_eval_error_select) {
		write_log_user ($filename_log, "Selection task Error: ". mysql_error() );
		$is_comment=$is_comment."<br> task not selected: ". mysql_error();
		display_comment($is_comment);
	} 
	$counter=0;
	$TASK_CODE_read 			= mysql_result($result_select,$counter,TASK_CODE);
	$TASK_NAME_read 			= mysql_result($result_select,$counter,TASK_NAME);
	$USER_CODE_CREATOR_read 	= mysql_result($result_select,$counter,USER_CODE_CREATOR);
	$PROJECT_CODE_read 			= mysql_result($result_select,$counter,PROJECT_CODE);
	$USER_CODE_ASSIGNED_read 	= mysql_result($result_select,$counter,USER_CODE_ASSIGNED);
	$TASK_STATE_read 			= mysql_result($result_select,$counter,TASK_STATE);
	$USER_CODE_VERIF_read 		= mysql_result($result_select,$counter,USER_CODE_VERIF);
	$USER_CODE_COPY_read 		= mysql_result($result_select,$counter,USER_CODE_COPY);
	$WORKLOAD_read 				= mysql_result($result_select,$counter,WORKLOAD);
	$WORKLOAD_TODO_read 		= mysql_result($result_select,$counter,WORKLOAD_TODO);
	$WORKLOAD_FINAL_read 		= mysql_result($result_select,$counter,WORKLOAD_FINAL);
	$CREATION_TASK_DATE_read	= mysql_result($result_select,$counter,CREATION_TASK_DATE);
	$TASK_DATE_START_PLANNED_read = mysql_result($result_select,$counter,TASK_DATE_START_PLANNED);
	$TASK_DATE_END_PLANNED_read = mysql_result($result_select,$counter,TASK_DATE_END_PLANNED);
	$TASK_DATE_START_DONE_read 	= mysql_result($result_select,$counter,TASK_DATE_START_DONE);
	$TASK_DATE_END_DONE_read 	= mysql_result($result_select,$counter,TASK_DATE_END_DONE);
	$TASK_RESULT_read 			= mysql_result($result_select,$counter,TASK_RESULT);
	if ($TASK_RESULT_read == 'NULL') $TASK_RESULT_read ="";
	$TASK_COMMENT_read 			= mysql_result($result_select,$counter,TASK_COMMENT);
	if( $TASK_COMMENT_read == 'NULL') $TASK_COMMENT_read ="";
	$TASK_FATHER_CODE_read 		= mysql_result($result_select,$counter,TASK_FATHER_CODE);
	$TASK_SON_CODE_read 		= mysql_result($result_select,$counter,TASK_SON_CODE);
}
?>

<form name ="edit" method="post">
<input type="hidden" name="userid" value="<? echo $USERID; ?>">
<input type="hidden" name="filename_log" value="<? echo $filename_log; ?>">
<input type="hidden" name="select_user" value="<? echo $select_user; ?>">
<input type="hidden" name="select_task" value="<? echo $select_task; ?>">
<input type="hidden" name="select_task_ex_previous" value="<? echo $TASK_SON_CODE_read; ?>">
<input type="hidden" name="select_task_ex_next" value="<? echo $TASK_FATHER_CODE_read; ?>">

<table class="around" border=1 align="center" cellspacing="2" cellpadding="4">

<tr><td>
<table border=1 cellspacing="2" cellpadding="4">
<tr><td class="title" colspan="6">
<? if ($select_task == "") { ?>
Add task to the selected user
<? } else { ?>
Update the selected task for this user
<? } ?>
</td></tr>
<tr><td class="title2">Name</td>
<td class="title2">
<? $wiew_user_path= $g_path."view_user.php?select_user=$select_user&filename_log=$filename_log";
echo "<a href='$wiew_user_path'>$NAME<a>"; ?>
</td>
<td class="title2">Project Name</td>
<? if ( project_name($select_project) != "Not assigned project") { ?>
<td class="title2">
<a href="<? echo $g_path; ?>view_project.php?select_project=<? echo $select_project; ?>&filename_log=<?echo $filename_log;?>"><? echo project_name($select_project); ?></a>
<? } else {
echo "<td>";
echo project_name($select_project);
} ?>
</td>
<td class="title2">Profile</td>
<td><? echo $PROFILE_NAME; ?></td>
</tr>
</table>
</td></tr>

<tr><td>
<table cellspacing="2" cellpadding="4">
<tr>
<td class="input">Task code</td>
<td class="title2">
<?
$view_task_path = $g_path."view_task.php?select_task=".$TASK_CODE_read."&select_user=".$select_user." ";
echo "<a href='$view_task_path'>".$TASK_CODE_read."<a>";
?>
</td>
<td class="input">Task name</td>
<td><input type="text" name="TASK_NAME" value="<? echo $TASK_NAME_read;?>"></input></td>
</tr>

<?
/* limited display of the enabled tasks for the connected user */
$result_task = mysql($g_database_name,
"SELECT a.TASK_CODE,a.TASK_NAME,a.PROJECT_CODE 
FROM TASK a, PROJECT b, PROJECT_USER c, USER d 
		where ((a.PROJECT_CODE=b.PROJECT_CODE and
		b.PROJECT_CODE=c.PROJECT_CODE and c.USERID=$connected_user 
		and d.USERID=$connected_user and b.PROJECT_CODE=a.PROJECT_CODE) 
		or (a.PROJECT_CODE IS NULL and a.USER_CODE_ASSIGNED=$connected_user 
		and d.USERID=a.USER_CODE_ASSIGNED
		and c.USERID=$connected_user 
		and b.PROJECT_CODE=d.PROJECT_CODE and b.PROJECT_CODE=c.PROJECT_CODE)) 
		ORDER BY a.TASK_NAME,a.PROJECT_CODE");
$total_rows = mysql_numrows($result_task);
?>
<tr><td class="input">Previous task</td><td><select name="TASK_FATHER_CODE">
<option value=""></option>
<?
$counter = 0;
while($counter < $total_rows) {
	$task_code = mysql_result($result_task,$counter,TASK_CODE);
	$task_name = mysql_result($result_task,$counter,TASK_NAME);
	$project_code = mysql_result($result_task,$counter,PROJECT_CODE);
	$project_name = project_name($project_code);
	if ( $TASK_FATHER_CODE_read == $task_code ){
		echo "<option value=".$task_code." selected>".$task_name." - PRJ: ".$project_name."</option>";
	} else {
		echo "<option value=".$task_code.">".$task_name." - PRJ: ".$project_name."</option>";
	}
	$counter = $counter + 1;
}
?>
</select></td>

<td class="input">Next task</td><td><select name="TASK_SON_CODE">
<option value=""></option>
<?
$counter = 0;
while($counter < $total_rows) {
	$task_code = mysql_result($result_task,$counter,TASK_CODE);
	$task_name = mysql_result($result_task,$counter,TASK_NAME);
	$project_code = mysql_result($result_task,$counter,PROJECT_CODE);
	$project_name = project_name($project_code);
	if ( $TASK_SON_CODE_read == $task_code ){
		echo "<option value=".$task_code." selected>".$task_name." - PRJ: ".$project_name."</option>";
	} else {
		echo "<option value=".$task_code.">".$task_name." - PRJ: ".$project_name."</option>";
	}
	$counter = $counter + 1;
}
?>
</select></td></tr>

<? if ($select_task == "") { 
/* only the planned dates are set */
?>
<tr>
<td class="input">Planned start date</td>
<td>
<select name="task_day">
	<option value="" selected></option>
	<option value="01">1</option>
	<option value="02">2</option>
	<option value="03">3</option>
	<option value="04">4</option>
	<option value="05">5</option>
	<option value="06">6</option>
	<option value="07">7</option>
	<option value="08">8</option>
	<option value="09">9</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
	<option value="13">13</option>
	<option value="14">14</option>
	<option value="15">15</option>
	<option value="16">16</option>
	<option value="17">17</option>
	<option value="18">18</option>
	<option value="19">19</option>
	<option value="20">20</option>
	<option value="21">21</option>
	<option value="22">22</option>
	<option value="23">23</option>
	<option value="24">24</option>
	<option value="25">25</option>
	<option value="26">26</option>
	<option value="27">27</option>
	<option value="28">28</option>
	<option value="29">29</option>
	<option value="30">30</option>
	<option value="31">31</option>
</select>
<select name="task_month">
	<option value="" selected></option>
	<option value="01">1</option>
	<option value="02">2</option>
	<option value="03">3</option>
	<option value="04">4</option>
	<option value="05">5</option>
	<option value="06">6</option>
	<option value="07">7</option>
	<option value="08">8</option>
	<option value="09">9</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
</select>
<select name="task_year">
	<option value="" selected></option>
	<option value="2003">2003</option>
	<option value="2004">2004</option>
	<option value="2005">2005</option>
	<option value="2006">2006</option>
	<option value="2007">2007</option>
	<option value="2008">2008</option>
	<option value="2009">2009</option>
	<option value="2010">2010</option>
	<option value="2011">2011</option>
	<option value="2012">2012</option>
	<option value="2013">2013</option>
</select>
<img src="<? echo $g_path;?>images/calendar.gif" ALT="Calendar" onClick="showPicker('date','edit','');"></td>
<td class="input">Planned end date</td>
<td>
<select name="task_day2">
	<option value="" selected></option>
	<option value="01">1</option>
	<option value="02">2</option>
	<option value="03">3</option>
	<option value="04">4</option>
	<option value="05">5</option>
	<option value="06">6</option>
	<option value="07">7</option>
	<option value="08">8</option>
	<option value="09">9</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
	<option value="13">13</option>
	<option value="14">14</option>
	<option value="15">15</option>
	<option value="16">16</option>
	<option value="17">17</option>
	<option value="18">18</option>
	<option value="19">19</option>
	<option value="20">20</option>
	<option value="21">21</option>
	<option value="22">22</option>
	<option value="23">23</option>
	<option value="24">24</option>
	<option value="25">25</option>
	<option value="26">26</option>
	<option value="27">27</option>
	<option value="28">28</option>
	<option value="29">29</option>
	<option value="30">30</option>
	<option value="31">31</option>
</select>
<select name="task_month2">
	<option value="" selected></option>
	<option value="01">1</option>
	<option value="02">2</option>
	<option value="03">3</option>
	<option value="04">4</option>
	<option value="05">5</option>
	<option value="06">6</option>
	<option value="07">7</option>
	<option value="08">8</option>
	<option value="09">9</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
</select>
<select name="task_year2">
	<option value="" selected></option>
	<option value="2003">2003</option>
	<option value="2004">2004</option>
	<option value="2005">2005</option>
	<option value="2006">2006</option>
	<option value="2007">2007</option>
	<option value="2008">2008</option>
	<option value="2009">2009</option>
	<option value="2010">2010</option>
	<option value="2011">2011</option>
	<option value="2012">2012</option>
	<option value="2013">2013</option>
</select>
<img src="<? echo $g_path;?>images/calendar.gif" ALT="Calendar" onClick="showPicker('date','edit2','');"></td>
</tr>
<? } else { 
/* Update only the done dates */
?>
<tr>
<td class="input">Planned start date</td><td><? echo $TASK_DATE_START_PLANNED_read;?></td>
<td class="input">Planned end date</td><td><? echo $TASK_DATE_END_PLANNED_read;?></td>
</tr>
<tr>
<td class="input">Actual start date</td>
<td>
<select name="task_day">
	<option value="" selected></option>
	<option value="01">1</option>
	<option value="02">2</option>
	<option value="03">3</option>
	<option value="04">4</option>
	<option value="05">5</option>
	<option value="06">6</option>
	<option value="07">7</option>
	<option value="08">8</option>
	<option value="09">9</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
	<option value="13">13</option>
	<option value="14">14</option>
	<option value="15">15</option>
	<option value="16">16</option>
	<option value="17">17</option>
	<option value="18">18</option>
	<option value="19">19</option>
	<option value="20">20</option>
	<option value="21">21</option>
	<option value="22">22</option>
	<option value="23">23</option>
	<option value="24">24</option>
	<option value="25">25</option>
	<option value="26">26</option>
	<option value="27">27</option>
	<option value="28">28</option>
	<option value="29">29</option>
	<option value="30">30</option>
	<option value="31">31</option>
</select>
<select name="task_month">
	<option value="" selected></option>
	<option value="01">1</option>
	<option value="02">2</option>
	<option value="03">3</option>
	<option value="04">4</option>
	<option value="05">5</option>
	<option value="06">6</option>
	<option value="07">7</option>
	<option value="08">8</option>
	<option value="09">9</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
</select>
<select name="task_year">
	<option value="" selected></option>
	<option value="2003">2003</option>
	<option value="2004">2004</option>
	<option value="2005">2005</option>
	<option value="2006">2006</option>
	<option value="2007">2007</option>
	<option value="2008">2008</option>
	<option value="2009">2009</option>
	<option value="2010">2010</option>
	<option value="2011">2011</option>
	<option value="2012">2012</option>
	<option value="2013">2013</option>
</select>
<img src="<? echo $g_path;?>images/calendar.gif" ALT="Calendar" onClick="showPicker('date','edit','');"></td>
<td class="input">Actual end date</td>
<td>
<select name="task_day2">
	<option value="" selected></option>
	<option value="01">1</option>
	<option value="02">2</option>
	<option value="03">3</option>
	<option value="04">4</option>
	<option value="05">5</option>
	<option value="06">6</option>
	<option value="07">7</option>
	<option value="08">8</option>
	<option value="09">9</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
	<option value="13">13</option>
	<option value="14">14</option>
	<option value="15">15</option>
	<option value="16">16</option>
	<option value="17">17</option>
	<option value="18">18</option>
	<option value="19">19</option>
	<option value="20">20</option>
	<option value="21">21</option>
	<option value="22">22</option>
	<option value="23">23</option>
	<option value="24">24</option>
	<option value="25">25</option>
	<option value="26">26</option>
	<option value="27">27</option>
	<option value="28">28</option>
	<option value="29">29</option>
	<option value="30">30</option>
	<option value="31">31</option>
</select>
<select name="task_month2">
	<option value="" selected></option>
	<option value="01">1</option>
	<option value="02">2</option>
	<option value="03">3</option>
	<option value="04">4</option>
	<option value="05">5</option>
	<option value="06">6</option>
	<option value="07">7</option>
	<option value="08">8</option>
	<option value="09">9</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
</select>
<select name="task_year2">
	<option value="" selected></option>
	<option value="2003">2003</option>
	<option value="2004">2004</option>
	<option value="2005">2005</option>
	<option value="2006">2006</option>
	<option value="2007">2007</option>
	<option value="2008">2008</option>
	<option value="2009">2009</option>
	<option value="2010">2010</option>
	<option value="2011">2011</option>
	<option value="2012">2012</option>
	<option value="2013">2013</option>
</select>
<img src="<? echo $g_path;?>images/calendar.gif" ALT="Calendar" onClick="showPicker('date','edit2','');"></td>
</tr>
<? } ?>

<?
$result_user = mysql($g_database_name,
"SELECT a.USERID,a.NAME from USER a, PROJECT_USER b, PROJECT_USER c, PROJECT d
				where a.USERID=b.USERID and b.PROJECT_CODE=d.PROJECT_CODE
				and $connected_user=c.USERID and c.PROJECT_CODE=d.PROJECT_CODE 
				and a.PROJECT_CODE=c.PROJECT_CODE
				ORDER BY NAME");
$total_rows = mysql_numrows($result_user);
?>
<tr>
<td class="input">Assigned user</td>
<td>
<select name="USER_ASSIGN">
<option value=""></option>
<?
$counter = 0;
while($counter < $total_rows) {
	$useridassignuser = mysql_result($result_user,$counter,USERID);
	$nameassignuser = mysql_result($result_user,$counter,NAME);
	$display_user = $select_user;
	if ( $USER_ASSIGN != "") {
		$display_user = $USER_ASSIGN;
	} 
	if ($display_user == $useridassignuser) {
		echo "<option value=".$useridassignuser." selected>".$nameassignuser."</option>";
	} else {
		echo "<option value=".$useridassignuser.">".$nameassignuser."</option>";
	}
	$counter = $counter + 1;
}
?>
</select>
</td>


<td class="input">Copied user</td>
<td>
<select name="USER_CODE_COPY">
<option value=""></option>
<?
$counter = 0;
while($counter < $total_rows) {
	$useridcopyuser = mysql_result($result_user,$counter,USERID);
	$namecopyuser = mysql_result($result_user,$counter,NAME);
	if ($USER_CODE_COPY_read==$useridcopyuser) {
		echo "<option value=".$useridcopyuser." selected>".$namecopyuser."</option>";
	} else {
		echo "<option value=".$useridcopyuser.">".$namecopyuser."</option>";
	}
	$counter = $counter + 1;
}
?>
</select>
</td>
</tr>

<tr>
<td class="input">Project code</td>
<td><select name="PROJECT_CODE">
<option value=""></option>
<?
$result_projectcode = mysql($g_database_name,
"SELECT a.PROJECT_CODE,a.PROJECT_NAME FROM PROJECT a, PROJECT_USER b 
	where a.PROJECT_CODE=b.PROJECT_CODE and b.USERID=$connected_user  
	ORDER BY PROJECT_CODE");
$total_rows = mysql_numrows($result_projectcode);
$counter = 0;
while($counter < $total_rows) {
	$project_code = mysql_result($result_projectcode,$counter,PROJECT_CODE);
	$project_name = mysql_result($result_projectcode,$counter,PROJECT_NAME);
	$select_project_test = $select_project;
	if ( $PROJECT_CODE_read != "" ) $select_project_test = $PROJECT_CODE_read;
	if ( $select_project_test == $project_code) {
		echo "<option value=".$project_code." selected>".$project_name."</option>";
	} else {
		echo "<option value=".$project_code.">".$project_name."</option>";
	}
	$counter = $counter + 1;

}
?>
</select>
</td>
</tr>
<tr>
<td class="input">Comment</td>
<td><textarea cols="50" rows="5" name="TASK_COMMENT"><? echo $TASK_COMMENT_read;?></textarea></td>
</tr>
<? if ($select_task != "") { ?>
<tr> 
<td class="input">Result</td>
<td><textarea cols="50" rows="5" name="TASK_RESULT"><? echo $TASK_RESULT_read;?></textarea></td>
</tr> 
<? } ?>

<tr>
<td class="input">Controller</td>
<td><select name="USER_CODE_VERIF">
<option value=""></option>
<?
$counter = 0;
while($counter < $total_rows) {
	$useridcopyuser = mysql_result($result_user,$counter,USERID);
	$namecopyuser = mysql_result($result_user,$counter,NAME);
	if ($USER_CODE_VERIF_read == $useridcopyuser) {
		echo "<option value=".$useridcopyuser." selected>".$namecopyuser."</option>";
	} else {
		echo "<option value=".$useridcopyuser.">".$namecopyuser."</option>";
	}
	$counter = $counter + 1;
}
?>
</select></td>       

<td class="input">Creator</td><td><? echo  user_name($connected_user,$g_database_name); ?></td></tr>

<? if ($select_task == "") { 
/* the state is Created by default */
 } else { ?>
<tr><td class="input">State</td><td><select name="TASK_STATE">
<option value=""></option>
<?
$result_taskstate = mysql($g_database_name,"SELECT STATE_TASK_ID,STATE_TASK_DESC FROM STATE_TASK ORDER BY STATE_TASK_ID");
$total_rows = mysql_numrows($result_taskstate);
$counter = 0;
while($counter < $total_rows) {
	$state_id = mysql_result($result_taskstate,$counter,STATE_TASK_ID);
	$state_name = mysql_result($result_taskstate,$counter,STATE_TASK_DESC);
	if ($TASK_STATE_read == $state_id) {
		/* the state CREATED is not taken */
		if ($state_id != 1) echo "<option value=".$state_id." selected>".$state_name."</option>";
	} else {
		/* the state CREATED is not taken */
		if ($state_id != 1) echo "<option value=".$state_id.">".$state_name."</option>";
	}
	$counter = $counter + 1;
}
?>
</select></td></tr>
<? } ?>
</table>
</td></tr>

<tr><td>
<table cellspacing="2" cellpadding="4">
<tr>
<td class="input">Planned Workload: </td><td><input type="text" name="WORKLOAD" value="<? echo $WORKLOAD_read;?>"></input></td>
<? if ($select_task != "") { 
/* data only updated if the state is different of created */
?>
<td class="input">Workload to do: &nbsp;&nbsp;</td><td><!-- <input type="text" name="WORKLOAD_TODO" value=" --> <? echo $WORKLOAD_TODO_read;?> <!-- "></input> --></td>
<td class="input">Workload done: &nbsp;&nbsp;</td><td><!-- <input type="text" name="WORKLOAD_FINAL" value=" --> <? echo $WORKLOAD_FINAL_read;?> <!-- "></input> --></td>
<? } ?>
</tr>
</table>
</td></tr>
</table>
<br>

<table align="center" cellspacing="2" cellpadding="4">
<? if ($select_task == "") { 
	if ( right_user($connected_user,18) ){ ?>
	<tr><td colspan="2"><? button("Add task","Add a new task","submit();"); ?></td>
	<? }
  } else { 
	if ( right_user($connected_user,16) ){ ?>
	<tr><td colspan="2"><? button("Update task","Update the current task","submit();"); ?></td>
	<? }
}
if ( right_user($connected_user,17) and $select_task != ""){ ?>
<td><a href="<? echo $g_path;?>add_taskuser.php?select_user=<? echo $select_user; ?>&filename_log=<? echo $filename_log; ?>&delete=1&select_task=<? echo $select_task; ?>"><? button("Delete task"); ?></a></td>
<? }
if ( right_user($connected_user,7) ){ ?>
<td><a href="<? echo $g_path;?>view_user.php?select_user=<? echo $select_user; ?>&filename_log=<? echo $filename_log; ?>"><? button("View user"); ?></a></td>
<? } 
if ( right_user($connected_user,10) and $PROJECT_CODE_read != ""){ ?>
<td><a href="<? echo $g_path; ?>view_project.php?select_project=<? echo $PROJECT_CODE_read; ?>&filename_log=<?echo $filename_log;?>"><? button("View project"); ?></a></td>
<? }
if ( right_user($connected_user,13) ){ ?>
<td>
<a href=<? echo $g_file_log_directory; ?>  title="Log data" > <img src="<? echo $g_icon_path;?>see.gif" border="0"> </a>
</td>
<? } ?>
<td>
<img src="<? echo $g_icon_path;?>question.gif" ALT="Help" onClick="show_comment_screen('Help','Add a new task for selected user',47,'');">
</td>
</tr>
</table>

</form>

<?
include ("include_bottom.inc");
?>

</BODY>
</HTML>
Return current item: Work project