| [ PHPXref.com ] | [ Generated: Sun Jul 20 19:53:39 2008 ] | [ PHProjekt 5.0.1 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 3 // projects_gantt.php - PHProjekt Version 5.0 4 // copyright © 2000-2005 Albrecht Guenther ag@phprojekt.com 5 // www.phprojekt.com 6 // Author: Albrecht Guenther, $Author: paolo $ 7 // $Id: projects_gantt.php,v 1.25 2005/06/20 14:52:51 paolo Exp $ 8 9 // assign colours to categories 10 $colours = array( "#000000", "#00ff00", "#0000ff", "#ffff00", "#ff00ff", "#00ffff", 11 "#800080", "#c0c0c0", "#008000", "#000080", "#808000", "#ff0000" ); 12 13 $path_pre = '../'; 14 include_once ('../lib/lib.inc.php'); 15 ini_set(max_execution_time, 200); 16 17 // include librry to sort the projects 18 include_once "./projects_sort.php"; 19 //categories: 1=offered, 2=ordered, 3=at work, 4=ended, 5=stopped, 6=reopened 7 = waiting, 10=container, 11=ext. project 20 $categories = array( "1" => __('offered'), "2" => __('ordered'), "3" => __('Working'), "4" => __('ended'), 21 "5" => __('stopped'), "6" => __('Re-Opened'), "7" => __('waiting') ); 22 $values = 12; 23 $pixel = 780; 24 $width_proj_names = 220; 25 if (empty($scaling)) $scaling = "auto"; 26 27 // clear projectlist 28 $projectlist = array(); 29 30 // define start and end time 31 define_timeframe(); 32 33 // fetch list of projects 34 fetch_projects(); 35 36 // ************** 37 // business chart 38 // ************** 39 if ($chart) { 40 unset($GLOBALS['php_errormsg']); 41 if (!is_file("$lib_path/chart/src/jpgraph.php")) die("Panic - cannot include plot library!"); 42 43 include_once("$lib_path/chart/src/jpgraph.php"); 44 include_once("$lib_path/chart/src/jpgraph_gantt.php"); 45 46 $graph = new GanttGraph(0, 0, "auto"); 47 $graph->SetBox(); 48 $graph->SetShadow(); 49 $graph->ShowHeaders(GANTT_HMONTH); 50 $graph->scale->tableTitle->SetFont(FF_FONT1,FS_BOLD); 51 $graph->scale->SetTableTitleBackground("silver"); 52 $inarray[] = __('Project Name'); 53 if ($chefl) $inarray[] = __('Leader'); 54 if ($person) $inarray[] = __('Person'); 55 if ($categorie) $inarray[] = __('Category'); 56 //$inarray[] = array(100); 57 $graph->scale->actinfo->SetColTitles( $inarray,array(100)); 58 // Show day, week and month scale 59 if(empty($scaling2))$scaling2="week"; 60 if($scaling2=='auto'){ 61 $nrofdays = round((strtotime($ende)-strtotime($anfang))/(3600*24)); 62 //echo $nrofdays; 63 if($nrofdays<=200)$scaling2="week"; 64 elseif($nrofdays<=400)$scaling2="month"; 65 else $scaling2="year"; 66 } 67 // Show day, week and month scale 68 if($scaling2=="week"){ 69 $graph->ShowHeaders(GANTT_HWEEK | GANTT_HMONTH); 70 // Instead of week number show the date for the first day in the week 71 // on the week scale 72 $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY); 73 // Make the week scale font smaller than the default 74 $graph->scale->week->SetFont(FF_FONT0); 75 // make the month names longer 76 $graph->scale->month->SetStyle(MONTHSTYLE_SHORTNAMEYEAR4); 77 $graph->scale->month->SetFont(FF_FONT1,FS_BOLD); 78 $graph->scale->month->SetFontColor("white"); 79 $graph->scale->month->SetBackgroundColor("blue"); 80 } 81 if($scaling2=="month"){ 82 $graph->ShowHeaders(GANTT_HMONTH | GANTT_HYEAR); 83 // Use the short name of the together with a 2 digit year 84 // on the month scale 85 $graph->scale->month->SetStyle(MONTHSTYLE_SHORTNAME); 86 $graph->scale->month->SetFont(FF_FONT1,FS_BOLD); 87 $graph->scale->month->SetFontColor("white"); 88 $graph->scale->month->SetBackgroundColor("blue"); 89 //$graph->scale->year->SetFontColor("white"); 90 //$graph->scale->year->SetBackgroundColor("blue"); 91 92 } 93 94 if($scaling2=="year"){ 95 $graph->ShowHeaders(GANTT_HYEAR); 96 //$graph->scale->year->SetStyle(); 97 $graph->scale->year->SetFontColor("white"); 98 $graph->scale->year->SetBackgroundColor("blue"); 99 } 100 // 0 % vertical label margin 101 $graph->SetLabelVMarginFactor(1); 102 // Only show part of the Gantt 103 if ($scaling == 'manual') { 104 $graph->SetDateRange($start_year.'-'.$start_month.'-01',$end_year.'-'.$end_month.'-30'); 105 } 106 $graph->SetDateRange($start_year.'-'.$start_month.'-01',$end_year.'-'.$end_month.'-30'); 107 // create bars 108 foreach ($projectlist as $project) { 109 add_chart($project); 110 } 111 112 // add constraints 113 $dep1 = array( '4' => 'STARTEND', '3' => 'STARTSTART', '2' => 'ENDSTART', '5' => 'ENDEND'); 114 foreach ($projectlist as $project) { 115 if ($project[4] > 0 && $activity_list[$project[4]]>0) { 116 // since the current project only listens to another project, 117 // we have to start the contraint at the target project and end at the current project 118 $activity_list[$project[4]]->SetConstrain($projects_ref[$project[0]], 'CONSTRAIN_'.$dep1[$project[10]]); 119 } 120 } 121 if (sizeof($activity_list)>0) { 122 // Finally add the bar to the graph 123 foreach ($activity_list as $activity) { 124 $graph->Add($activity); 125 } 126 } 127 $graph->Stroke(); 128 } 129 else { 130 echo " 131 <script type='text/javascript'> 132 <!-- 133 function formSubmit2(theForm) { 134 theForm.target = '_self'; 135 theForm.action = 'projects.php?mode=gantt'; 136 } 137 function formSubmit1(theForm) { 138 theForm.target = '_blank'; 139 theForm.action = 'projects_gantt.php'; 140 } 141 //--> 142 </script> 143 "; 144 145 // tabs 146 $tabs = array(); 147 $output .= get_tabs_area($tabs); 148 // button bar 149 $buttons = array(); 150 $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=forms&action=new'.$sid, 'text' => __('New'), 'active' => false); 151 $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=options'.$sid, 'text' => __('Options'), 'active' => false); 152 $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=stat'.$sid, 'text' => __('Statistics'), 'active' => false); 153 $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=stat&mode2=mystat'.$sid, 'text' => __('My Statistic'), 'active' => false); 154 $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=gantt'.$sid, 'text' => __('Gantt'), 'active' => true); 155 $buttons[] = array('type' => 'link', 'href' => 'projects.php?type='.$type.'&sort='.$sort.'&mode=view&up='.$up.'&filter='.$filter.'&keyword='.$keyword.'&perpage='.$perpage.'&page='.$page, 'text' => __('back'), 'active' => false); 156 $output .= get_buttons_area($buttons); 157 158 $output .= '<div class="hline"></div><a name="content"></a>'; 159 $output .= "<form style='display:inline;' action='projects_gantt.php?' method='get' name='theForm' target='_blank'>"; 160 $output .= '<div class="div2">'; 161 162 // ************** 163 // navigation bar 164 // ************* 165 166 if (SID) $output.= "<input type='hidden' name='".session_name()."' value='".session_id()."' />\n"; 167 $output.= "<input type='hidden' name='mode' value='gantt' />\n"; 168 $output.= "<div class='gantt'>".__('timescale').":</div> 169 <input type='radio' name='scaling' value='auto'"; 170 if ($scaling=="auto" or !$scaling) $output.= ' checked="checked"'; 171 $output.= " />".__('Automatic scaling'); 172 173 $output.= " <input type='radio' name='scaling' value='manual'"; 174 if ($scaling == "manual") $output.= ' checked="checked"'; 175 $output.= " />".__('Manual Scaling').": \n"; 176 // box for start year 177 $output.= __('Begin:')." <select name='start_year'>\n"; 178 179 for ($i=2000; $i <= 2005; $i++) { 180 $output.= "<option value='$i'"; 181 if ($i == $start_year) $output.= ' selected="selected"'; 182 $output.= ">$i</option>\n"; 183 } 184 $output.= "</select>\n"; 185 // box for start month 186 $output.= "<select name='start_month'>\n"; 187 for ($i=1; $i <= 12; $i++) { 188 if ($i < 10) { $j = "0".$i; } 189 else { $j = $i; } 190 $output.= "<option value='$j'"; 191 if ($i == $start_month) $output.= ' selected="selected"'; 192 $output.=">$j</option>\n"; 193 } 194 $output.="</select> \n"; 195 // end year 196 $output.= __('End:')." <select name='end_year'>\n"; 197 for ($i=2000; $i <= 2010; $i++) { 198 $output.= "<option value='$i'"; 199 if ($i == $end_year) $output.= ' selected="selected"'; 200 $output.= ">$i</option>\n"; 201 } 202 $output.= "</select>\n"; 203 // end month 204 $output.="<select name='end_month'>\n"; 205 for ($i=1; $i <= 12; $i++) { 206 if ($i < 10) { $j = "0".$i; } 207 else { $j = $i; } 208 $output.="<option value='$j'"; 209 if ($i == $end_month) $output.= ' selected="selected"'; 210 $output.= ">$j</option>\n"; 211 } 212 $output.="</select> \n"; 213 // automatic scaling 214 215 $output.= "</div>\n"; 216 $output.='<div class="div2">'; 217 218 // second row of navigation table 219 // check whether the user just wants to have one major project 220 $output.= "<div class='gantt'>".__('project choice').":</div> <label for='single_project'>".__('Only this project').":</label> 221 <select name='single_project' id='single_project'><option value='0'></option>\n"; 222 // call function to show all required elements in a tree structure in the select box 223 $output.= show_elements_of_tree('projekte', 224 'name', 225 "WHERE (acc LIKE 'system' OR ((von = ".$user_ID." OR acc LIKE 'group' OR acc LIKE '%\"$user_kurz\"%') AND $sql_user_group))", 226 'acc'," ORDER BY name",$single_project,'parent',0); 227 228 $output.= "</select> | \n"; 229 230 // checkbox for option 'only display main projects 231 $output.="<input type='checkbox' name='only_main' value='1'"; 232 if ($only_main) $output.= ' checked="checked"'; 233 $output.= " />".__('Only main projects')." "; 234 235 // show chart 236 if (PHPR_SUPPORT_CHART) { 237 if (!$scaling2) $scaling2 = 'week'; 238 $output.="</div><div class='div2'><div class='gantt'>".__('display format').":</div><input type='radio' name='chart' onchange='formSubmit2(this.form);' value='' />html <input type='radio' name='chart' value='chart' checked='checked' onchange='formSubmit1(this.form);' /> chart</div>\n"; 239 $output.="<div class='div2'><div class='gantt' style='width:300px;'>".__('for chart only')."</div></div>"; 240 $output.="<div class='div2'><div class='gantt'>".__('column view').":</div><input type='checkbox' name='chefl' id='chef1' /><label for='chef1'>".__('Leader')."</label> <input type='checkbox' name='person'id='person' /><label for='person'>".__('Person')."</label> 241 <input type='checkbox' name='categorie' id='categorie' /><label for='categorie'>".__('Category')."</label></div>"; 242 $output.="<div class='div2'><div class='gantt'>".__('colours:')."</div> 243 <input type='checkbox' name='colour' id='colour' /> <label for='colour'>".__('display project colours').":</label></div>"; 244 $output.="<div class='div2'><div class='gantt'>".__('scaling:')."</div>\n"; 245 $output.="<input type='radio' name='scaling2' id='auto' value='auto'"; 246 if ($scaling2 == "auto") $output.= " checked='checked'"; 247 $output.= " /><label for='auto'>".__('automatic')."</label>\n "; 248 $output.="<input type='radio' name='scaling2' id='week' value='week'"; 249 if ($scaling2 == "week") $output.= " checked='checked'"; 250 $output.= " /><label for='week'>".__('weekly')."</label>\n "; 251 $output.="<input type='radio' id='month' name='scaling2' value='month'"; 252 if ($scaling2 == "month") $output.= " checked='checked'"; 253 $output.= " /><label for='month'>".__('monthly')."</label>\n "; 254 $output.="<input type='radio' id='year' name='scaling2' value='year'"; 255 if ($scaling2 == "year") $output.= " checked='checked'"; 256 $output.= " /><label for='year'>".__('annually')."</label>\n "; 257 258 } 259 260 $output.= " <input type='submit' class='buttonklein' value='GO' /></div>\n"; 261 $output.= "</form>\n"; 262 263 // end navigation bar 264 // ***************** 265 266 echo $output; 267 268 // ********* 269 //calc chart 270 // ********* 271 272 //************** 273 // display range 274 275 echo "<br /><br /><br />\n<table border='1' cellspacing='0' cellpadding='0'>\n<tr>\n"; 276 echo "<td> </td>\n"; 277 // write values 278 $months = round((mktime(0,0,0,$end_month,1,$end_year)-mktime(0,0,0,$start_month,1,$start_year))/(86400*30))+1; 279 280 // short range? -> print each month 281 if ($months <= $values) { 282 $width = $pixel/$values; 283 for ($i = 0; $i < $months; $i++) { 284 $a = date("Y-m", mktime(0,0,0,($start_month+$i),1,$start_year)); 285 echo "<td width='$width'>$a</td>\n"; 286 } 287 echo "</tr>\n"; 288 } 289 // higher range: -> just x values 290 else { 291 // try to find within reasonable frame whether more values would fit it 292 if ($months <= 24) $values = $months; 293 // number of months which will fall additionally into the last table cell 294 $last_part = (($months/$values)-(floor($months/$values)))*$values; 295 for ($i = 0; $i < $values; $i++) { 296 if ($i < ($values-1)) { 297 if ($last_part > 0) { 298 // calculate the width for all cells except the last one 299 $total_width = $pixel - floor($pixel*($last_part/$months)); 300 $width = floor($total_width/$values); 301 } 302 else { 303 $width = floor($pixel/$values); 304 } 305 $sumwidth = $sumwidth + $width; 306 } 307 else { 308 $width = $pixel - $sumwidth; 309 } 310 $j = $i*floor($months/$values); 311 $a = date("Y-m", mktime(0,0,0,($start_month+$j),1,$start_year)); 312 echo "<td width='$width'>$a</td>\n"; 313 } 314 echo "</tr>\n"; 315 } 316 // end display range 317 // ***************** 318 319 320 // ****************** 321 // print the projects 322 foreach ($projectlist as $project) { 323 324 // check whether this project is within the timeframe 325 if ( $project[3] < $anfang or $project[2] > $ende) {} 326 else { 327 328 // define left edge of block 329 if ($project[2] <= $anfang) { 330 $edgeleft = 0; 331 $t1 = 0; 332 } 333 else { 334 $st = explode("-", $project[2]); 335 $edgeleft = floor((mktime(0,0,0,$st[1],$st[2],$st[0]) - mktime(0,0,0,$start_month,$start_day,$start_year))/86400*$pixel/$range); 336 $t1 = $edgeleft; 337 } 338 // define right edge of block 339 if ($project[3] >= $ende) $edgeright = $pixel; 340 else { 341 $st = explode("-", $project[3]); 342 $edgeright = $pixel - floor((mktime(0,0,0,$end_month,$end_day,$end_year) - mktime(0,0,0,$st[1],$st[2],$st[0]))/86400*$pixel/$range); 343 } 344 345 // indent as transparent img on the left side 346 if ($edgeright < $pixel) { 347 $t2 = $pixel - $edgeright; 348 } 349 else { 350 $t2 = 0; 351 } 352 $w1 = $edgeright - $edgeleft; 353 echo "<tr><td class='align-left' width='$width_proj_names'> ".indent_name($project[1],$project[11],' ')." </td>\n"; 354 355 // define bar - special workaround for NN4 356 if (eregi("4.7|4.6|4.5", $HTTP_USER_AGENT)) { 357 echo "<td colspan='$values' bgcolor='#eeeeee'><table cellspacing='0' cellpadding='0'><tr valign='bottom'> 358 <td valign='bottom'><img src='$img_path/t.gif' width='$t1' height='5' border='0' vspace='5' alt='' /></td> 359 <td valign='bottom'><img src='$img_path/s.gif' width='$w1' height='5' border='0' vspace='5' alt='$project[2] - $project[3]' title='$project[2] - $project[3]' /></td> 360 <td valign='bottom'><img src='$img_path/t.gif' width='$t2' height='5' border='0' vspace='5' alt='' /></td> 361 </tr></table></td></tr>\n"; 362 } 363 else { 364 echo "<td colspan='$values' bgcolor='#eeeeee'><table cellspacing='0' cellpadding='0'><tr valign='bottom'> 365 <td valign='bottom'><img src='$img_path/t.gif' width='$t1' height='5' border='0' vspace='5' alt='' style='background-color:transparent;' /></td> 366 <td valign='bottom'><img src='$img_path/t.gif' width='$w1' height='5' border='0' vspace='5' style='background-color:".$colours[$project[6]].";' alt='$project[2] - $project[3]' title='$project[2] - $project[3]' /></td> 367 <td valign='bottom'><img src='$img_path/t.gif' width='$t2' height='5' border='0' vspace='5' alt='' style='background-color:transparent;' /></td> 368 </tr></table></td></tr>\n"; 369 } 370 } 371 } 372 echo "</table><br />\n"; 373 374 // add legend 375 if (!$add_legend and !eregi("4.7|4.6|4.5", $HTTP_USER_AGENT)) { 376 echo " <b>".__('Legend')."</b><table cellpadding='3' cellspacing='0' border='1'>\n<tr>"; 377 // no value 378 echo "<td><img src='$img_path/t.gif' style='background-color:black;' width='7' alt='black' /> ".__('No value')."</td>\n"; 379 foreach ($categories as $cat_ID => $cat_name) { 380 echo "<td><img src='$img_path/t.gif' style='background-color:".$colours[$cat_ID].";' width='7' alt='$colours[$cat_ID]' /> ".$cat_name."</td>\n"; 381 } 382 echo "</tr></table>\n"; 383 } 384 } 385 386 387 // end print projects 388 // ************************ 389 390 function define_timeframe() { 391 global $anfang, $ende, $sql_user_group, $start_month, $start_day, $start_year; 392 global $end_day, $end_month, $end_year, $single_project, $scaling; 393 394 // set lowest stat month and year 395 if ($scaling == "auto") { 396 if ($single_project) { 397 $result = db_query("SELECT ID, name, anfang, ende, depend_proj 398 FROM ".DB_PREFIX."projekte 399 WHERE ID = '$single_project'") or db_die(); 400 } 401 else { 402 $result = db_query("SELECT ID, name, anfang, ende, depend_proj 403 FROM ".DB_PREFIX."projekte 404 WHERE parent = 0 405 AND $sql_user_group") or db_die(); 406 } 407 while ($row = db_fetch_row($result)) { 408 $projectlist[] = $row; 409 } 410 411 foreach ($projectlist as $project) { 412 // lowest 413 if (!$lowest) $lowest = $project[2]; 414 elseif ($project[2] < $lowest) $lowest = $project[2]; 415 // highest 416 if (!$highest) $highest = $project[3]; 417 elseif ($project[3] > $highest) $highest = $project[3]; 418 } 419 $start_month = substr($lowest,5,2); 420 $start_year = substr($lowest,0,4); 421 422 $end_month = substr($highest,5,2); 423 $end_year = substr($highest,0,4); 424 } 425 $start_day = "01"; 426 $end_day = date("t", mktime(0,0,0,$end_month+1,0,$end_year)); 427 $anfang = $start_year."-".$start_month."-".$start_day; 428 $ende = $end_year."-".$end_month."-".$end_day; 429 if ($ende <= $anfang) { 430 $end_year = $start_year; 431 $end_month = $start_month+1; 432 $ende = $end_year."-".$end_month."-".$end_day; 433 } 434 } 435 436 function fetch_projects() { 437 global $start_day, $start_month, $start_year, $end_day, $end_month, $end_year, $single_project; 438 global $sql_user_group, $ende, $anfang, $only_main, $range, $projectlist, $level, $user_ID, $user_kurz; 439 440 // fetch projects 441 $range = floor((