Location: PHPKode > projects > Work project > workproject/drawing.php
<?

	include ("include_config.inc");
	include ("include_log_file.inc");
	include ("include_project_name.inc");
	include ("include_translate.inc");
	include ("include_row_table.inc");
	include ("../phplot-4.4.6/phplot.php");

	$link= mysql_connect($g_hostname, $g_db_username, $g_db_password) or die("could not connect");
	$result_link = mysql_select_db($g_database_name);

	write_log_user ($filename_log, "Draw the statistics, filter_date: ".$filter_date." - project: ".$each_project);
	#creation of date filter
	$week_before  = date("Y-m-d", mktime(0,0,0,date("m")  ,date("d") -7,date("Y")    ) );
  	$month_before = date("Y-m-d", mktime(0,0,0,date("m")-1,date("d")    ,date("Y")    ) );
  	$year_before  = date("Y-m-d", mktime(0,0,0,date("m"),  date("d")    ,date("Y") -1) );
	#write_log_user ($filename_log, "Draw the statistics, week_before: ".$week_before );
	#write_log_user ($filename_log, "Draw the statistics, month_before: ".$month_before );
	#write_log_user ($filename_log, "Draw the statistics, year_before: ".$year_before );
	if ( $filter_date == 1 ) { #all values
		$select_date_form = "";
		$translated_filter = translation('L_FILTER_STATS_ALL',$g_language);
	}
	if ( $filter_date == 2 ) { #before 1 year
		$select_date_form = "and b.DATE >= '$year_before' "; 
		$translated_filter = translation('L_FILTER_STATS_LAST_YEAR',$g_language);
	}
	if ( $filter_date == 3 ) { #before 1 month
		$select_date_form = "and b.DATE >= '$month_before' ";
		$translated_filter = translation('L_FILTER_STATS_LAST_MONTH',$g_language); 
	}
	if ( $filter_date == 4 ) { #before 1 wwek
		$select_date_form = "and b.DATE >= '$week_before' ";
		$translated_filter = translation('L_FILTER_STATS_LAST_WEEK',$g_language);
	}

	if ( $type_data	== "ALL" or $type_data == "EACH" ){
		if ( $type_data == "ALL" ) {
			$select_form = "where x.PROJECT_CODE<>'' and x.PROJECT_ADMIN=$type_project and b.DATE <>'' $select_date_form ";
		}
		if ( $type_data == "EACH" ) {
			$select_form = "where b.DATE <>'' and x.PROJECT_ADMIN=$type_project and x.PROJECT_CODE = '$each_project'  $select_date_form ";
		}
		$query_project = "SELECT DISTINCT x.PROJECT_CODE 
		from TASK a, COMMENT_TASK b, PROJECT x
		$select_form 
		and a.PROJECT_CODE=x.PROJECT_CODE and b.TASK_CODE=a.TASK_CODE
		and a.TASK_CODE<>''
		and x.PROJECT_ADMIN=$type_project and x.STATE=2
		order by b.DATE asc, x.PROJECT_CODE asc";
		#write_log_user ($filename_log, "Draw the statistics, query_project: ".$query_project);
		$result = mysql_query($query_project) or $error_project = mysql_error();
		$example_title = array();
		if ( !$error_project) {
			$nb_project = mysql_numrows($result);	
			$counter = 0;
			$project_list = array();
			while ( $counter < $nb_project) {
				$project_list[] = mysql_result($result,$counter,PROJECT_CODE);
				$counter = $counter +1;
			}	
		} else {
			display_comment(translation('L_STATISTICS_NO_URL',$g_language));
		}		
		#write_log_user ($filename_log, "Draw the statistics, nb_projects: ". $nb_project);
		
		$query_date = "SELECT DISTINCT UNIX_TIMESTAMP(b.DATE) as DATE
		from TASK a, COMMENT_TASK b, PROJECT x
		$select_form 
		and a.PROJECT_CODE=x.PROJECT_CODE and b.TASK_CODE=a.TASK_CODE
		and a.TASK_CODE<>''
		and x.PROJECT_ADMIN=$type_project and x.STATE=2
		order by b.DATE asc, x.PROJECT_CODE asc";
		$result = mysql_query($query_date) or $error_project = mysql_error();
		if ( !$error_project) {
			$nb_date = mysql_numrows($result);	
		} else {
			display_comment(translation('L_STATISTICS_NO_DATE',$g_language));
		}
		#write_log_user ($filename_log, "Draw the statistics, nb_date: ". $nb_date);
		
		$query_select = "SELECT DISTINCT x.PROJECT_NAME, a.WORKLOAD, a.WORKLOAD_FINAL, a.WORKLOAD_TODO, 
		a.TASK_NAME, b.COMMENT_CODE,
		UNIX_TIMESTAMP(b.DATE) as DATE, b.C_WORKLOAD_DONE, b.C_WORKLOAD_TODO
		from TASK a, COMMENT_TASK b, PROJECT x
		$select_form 
		and a.PROJECT_CODE=x.PROJECT_CODE and b.TASK_CODE=a.TASK_CODE
		and a.TASK_CODE<>''
		and x.PROJECT_ADMIN=$type_project and x.STATE=2
		order by b.DATE asc, x.PROJECT_CODE asc";
		#write_log_user ($filename_log,$query_select);
		
		$result = mysql_query($query_select) or $error_select = mysql_error();
		if ( !$error_select) {
			$total_rows = mysql_numrows($result);
			if ( $total_rows != 0 ) {
				$counter = 0;
				$example_data = array();
				$tabnew = array();
				$flag = 0;
				$workload_end = 0;
				$workload_start = 0;
				
				$date_old = 0; 
				$project_old = ''; 
				$ind_x= -1;
				while ( $counter < $total_rows) {
					$project = mysql_result($result,$counter,PROJECT_NAME);
					$workload = mysql_result($result,$counter,WORKLOAD);
					if ( $workload == '' ) $workload = 0;
					$workload_done =  mysql_result($result,$counter,C_WORKLOAD_DONE);
					if ( $workload_done == '' ) $workload_done = 0;
					$workload_todo =  mysql_result($result,$counter,C_WORKLOAD_TODO);
					if ( $workload_todo == '' ) $workload_todo = 0;
					$date = mysql_result($result,$counter,DATE);
					$task_name = mysql_result($result,$counter,TASK_NAME);
					$comment_code = mysql_result($result,$counter,COMMENT_CODE);
					#write_log_user ($filename_log, "--------------------------------------");
					#write_log_user ($filename_log, "Draw the statistics, Project name : ". $project);
					#write_log_user ($filename_log, "Draw the statistics, workload     : ". $workload);
					#write_log_user ($filename_log, "Draw the statistics, date         : ". strftime($g_date_format, $date ));
					#write_log_user ($filename_log, "Draw the statistics, task name    : ". $task_name);
					#write_log_user ($filename_log, "Draw the statistics, comment code : ". $comment_code);
					#write_log_user ($filename_log, "Draw the statistics, workload done: ". $workload_done);
					#write_log_user ($filename_log, "Draw the statistics, workload todo: ". $workload_todo);
					if ( $flag == 0 ) {
						$date_start = $date;
						$flag = 1;
					}
					if ( $workload >= $workload_end) 		$workload_end = $workload;
					if ( $workload <= $workload_start) 		$workload_start = $workload;
					if ( $workload_done >= $workload_end) 	$workload_end = $workload_done;
					if ( $workload_done <= $workload_start) $workload_start = $workload_done;	
					if ( $workload_todo >= $workload_end) 	$workload_end = $workload_todo;
					if ( $workload_todo <= $workload_start) $workload_start = $workload_todo;								
					
					if ( $type_data == "EACH" ){
						if ( $date != $date_old and $project != $project_old) {
							#write_log_user ($filename_log, "Draw the statistics,1: ".$project. " - ".$date);
							$tabnew = array();
							$tabnew[0]=strftime($g_date_format, $date );
							$tabnew[1]=$date;
							$tabnew[2]=$workload;
							$tabnew[3]=$workload_todo;
							$tabnew[4]=$workload_done;
							for ($j=5;$j<sizeof($project_list)+2;$j++){
								$tabnew[$j]= 0;
							}
							$ind_x = $ind_x +1;
						}
						elseif ( $date != $date_old and $project == $project_old){
							#write_log_user ($filename_log, "Draw the statistics,2: ".$project. " - ".$date);
							$tabnew = array();
							$tabnew[0]=strftime($g_date_format, $date );
							$tabnew[1]=$date;
							$tabnew[2]=$workload;
							$tabnew[3]=$workload_todo;
							$tabnew[4]=$workload_done;
							for ($j=5;$j<sizeof($project_list)+2;$j++){
								$tabnew[$j]= 0;
							}
							$ind_x = $ind_x +1;
						}
						elseif ( $date == $date_old and $project == $project_old){
							#write_log_user ($filename_log, "Draw the statistics, 3: ".$project. " : ".strftime($g_date_format, $date ));
							#ind_x = idem and tabnew = idem						
							$tabnew[3]=$tabnew[3]+$workload_todo;
							$tabnew[4]=$tabnew[4]+$workload_done;
							for ($j=5;$j<sizeof($project_list)+2;$j++){
								$tabnew[$j]= 0;
							}
						}
						elseif ( $date == $date_old and $project != $project_old){
							#write_log_user ($filename_log, "Draw the statistics,4: ".$project. " - ".$date);
							#ind_x = idem and tabnew = idem
							$row_new_project = row_table($project,$project_list);
							$tabnew[$row_new_project+2]=$workload;
							$tabnew[$row_new_project+3]=$workload_todo;
							$tabnew[$row_new_project+4]=$workload_done;
						}
					} else {
						#ALL
						if ( $date != $date_old ) {
							write_log_user ($filename_log, "Draw the statistics,1: ".$project. " - ".strftime($g_date_format, $date ));
							$tabnew = array();
							$tabnew[0]=strftime($g_date_format, $date );
							$tabnew[1]=$date;
							$tabnew[2]=$workload;
							$tabnew[3]=$workload_todo;
							$tabnew[4]=$workload_done;
							for ($j=5;$j<sizeof($project_list)+2;$j++){
								$tabnew[$j]= 0;
							}
							$ind_x = $ind_x +1;
						}	
						if ( $date == $date_old ){
							write_log_user ($filename_log, "Draw the statistics, 3: ".$project. " : ".strftime($g_date_format, $date ));
							#ind_x = idem and tabnew = idem		
							$tabnew[2]=$tabnew[2]+$workload;				
							$tabnew[3]=$tabnew[3]+$workload_todo;
							$tabnew[4]=$tabnew[4]+$workload_done;
							for ($j=5;$j<sizeof($project_list)+2;$j++){
								$tabnew[$j]= 0;
							}
							#for ($j=0;$j<sizeof($project_list)+2;$j++){
							#	write_log_user ($filename_log, "Draw the statistics,3: ".$tabnew[$j]); 
							#}
						}
					}
					$counter = $counter +1 ;
					if ($counter < $total_rows) {
						$date_old = $date;
						$project_old = $project;
					}
					$example_data[$ind_x] = $tabnew; 
				}
				$date_end = $date;
			} else {
				display_comment(translation('L_STATISTICS_NO_DATA',$g_language));
			}
		} else {
			display_comment(translation('L_STATISTICS_ERROR',$g_language)." : ".$error_select);
		}
		
		/*
		write_log_user ($filename_log, " wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww ");
		for ($j=0;$j<sizeof($example_data);$j++){
			for ($k=0;$k<sizeof($example_data[$j]);$k++){
				write_log_user ($filename_log, "Draw the statistics,5: ".$example_data[$j][$k]);
			}
		}
		write_log_user ($filename_log, " wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww ");
		*/
			
		#draw					
		$graph = new PHPlot;
		$graph->SetDataType("data-data");  //Must be called before SetDataValues
	
		$graph->SetImageArea(600,600);
		$graph->SetPrecisionY(0);
		$graph->SetPrecisionX(0);
		$graph->SetXLabel("");
		$translation_title_y = translation('L_WORKLOAD',$g_language);
		$graph->SetYLabel($translation_title_y);

		$inc_y = ($workload_end - $workload_start);
		if ( $inc_y <= 10 ) { $inc_y = ($workload_end - $workload_start); $inc_y = intval($inc_y); }
		if ( $inc_y > 10 and $inc_y <= 100 ) { $inc_y = ($workload_end - $workload_start)/10; $inc_y = intval($inc_y); }
		if ( $inc_y > 100 and $inc_y <= 1000 ) { $inc_y = ($workload_end - $workload_start)/100;$inc_y = intval($inc_y)*10;}
		if (  $inc_y > 1000 and $inc_y <= 10000 ) { $inc_y = ($workload_end - $workload_start)/1000;$inc_y = intval($inc_y)*100;}
		if ( $inc_y > 10000 ) { $inc_y = ($workload_end - $workload_start)/10000;$inc_y = intval($inc_y)*10000;}
		$graph->SetVertTickIncrement($inc_y);
		$graph->SetXAxisPosition(0);
		//$graph->SetSkipBottomTick(1);
	
		//Set Unixtime Increment and X Axis Settings
		$div = $nb_date +1;
		if ( $nb_date < 3) $div = $nb_date;
		$inc_x =intval(($date_end -$date_start)/$div);
		write_log_user ($filename_log, "Draw the statistics, inc_x: ".$inc_x);
		if ( $inc_x == 0 ) { 
			$inc_x = 172800/2; 
			$date_end = $date_start + 172800/2;
			$date_start = $date_start - 172800/2;
		}
		$graph->SetHorizTickIncrement(intval($inc_x));
		$graph->SetXGridLabelType("time");
		$graph->SetXTimeFormat($g_date_format_image);
		$graph->SetXDataLabelAngle(90);
		$graph->SetDataColors(
			array("blue","green","yellow","red","black","cyan","brown","pink","grey","violet","orange"),  //Data Colors
			array("black")							//Border Colors
		);
		$graph->SetDataValues($example_data);
		
		if ( $type_project == 2 ) $translation_title_general = translation('L_STATS_PROJECTS',$g_language);
		if ( $type_project == 1 ) $translation_title_general = translation('L_STATS__STAFF_PROJECTS',$g_language);
		for ( $k=0;$k<sizeof($project_list);$k++){
			$project_list[$k] = project_name($project_list[$k]);
			$translation_title_general = $translation_title_general." : ".$project_list[$k];
		}
		$graph->SetTitle($translation_title_general);		
		
		//Since X axis is in Unixtime format we set the limits accordingly
		$graph->SetPlotAreaWorld($date_start,$workload_start,$date_end,$workload_end+10);
								
		#$graph->SetDrawXDataLabels(0); //We already got them in the first graph
		#$graph->SetLegend($project_list); //Lets add a legend
		#$graph->DrawLegend(55,55,'');		
		
		$label_workload = array();
		$label_workload[0]= translation('L_WORKLOAD_PLANNED',$g_language);
		$label_workload[1]= translation('L_WORKLOAD_TODO',$g_language);
		$label_workload[2]= translation('L_WORKLOAD_DONE',$g_language);		
		$graph->SetLegend($label_workload);
		$graph->DrawLegend(55,30,'');
	
		$graph->DrawGraph();
	}

?>
Return current item: Work project