![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: gantt2.php 56 2008-02-19 18:39:18Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/projects/gantt2.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 include ($AppUI->getLibraryClass('jpgraph/src/jpgraph')); 7 include ($AppUI->getLibraryClass('jpgraph/src/jpgraph_gantt')); 8 9 global $company_id, $dept_ids, $department, $locale_char_set, $proFilter, $projectStatus, $showInactive, $showLabels, $showAllGantt; // $showAllGantt == Gantt with tasks and users 10 11 // get the prefered date format 12 $df = $AppUI->getPref('SHDATEFORMAT'); 13 14 $filter1 = array(); 15 $projectStatus = w2PgetSysVal('ProjectStatus'); 16 $projectStatus = arrayMerge(array('-2' => $AppUI->_('All w/o in progress')), $projectStatus); 17 $proFilter = w2PgetParam($_REQUEST, 'proFilter', '-1'); 18 19 if ($proFilter == '-2') { 20 $filter1[] = 'project_status != 3 '; 21 } elseif ($proFilter != '-1') { 22 $filter1[] = 'project_status = ' . (int)$proFilter; 23 } 24 if ($company_id != 0) { 25 $filter1[] = 'project_company = ' . (int)$company_id; 26 } 27 //$filter1 = ($proFilter == '-1') ? '' : " AND project_status = $proFilter "; 28 if ($showInactive != '1') { 29 $filter1[] = 'project_active > 0 '; 30 } 31 $pjobj = &new CProject; 32 $allowed_projects = $pjobj->getAllowedSQL($AppUI->user_id); 33 $where = array_merge($filter1, $allowed_projects); 34 35 // pull valid projects and their percent complete information 36 // changed "ti.task_end_date AS project_actual_end_date" to "max(t1.task_end_date) AS project_actual_end_date" -- max() 37 $sql = ' 38 SELECT u.user_username user_name, t.task_name task_name, t.task_start_date task_start_date, t.task_milestone task_milestone, ut.perc_assignment perc_assignment, 39 t.task_end_date task_end_date, p.project_color_identifier project_color_identifier, p.project_name project_name 40 FROM tasks t 41 LEFT JOIN user_tasks ut ON t.task_id = ut.task_id 42 LEFT JOIN users u ON u.user_id = ut.user_id 43 LEFT JOIN projects p ON p.project_id = t.task_project 44 LEFT JOIN companies c ON p.project_company = c.company_id 45 ORDER BY 1, 2, 5, 4 46 '; 47 $q = new DBQuery; 48 $q->addTable('tasks', 't'); 49 $q->addQuery('u.user_username user_name'); 50 $q->addQuery('t.task_name task_name, t.task_start_date task_start_date, t.task_milestone 51 task_milestone, ut.perc_assignment perc_assignment, t.task_end_date task_end_date, t.task_dynamic'); 52 $q->addQuery('p.project_color_identifier project_color_identifier, p.project_name project_name'); 53 $q->addJoin('user_tasks', 'ut', 't.task_id = ut.task_id'); 54 $q->addJoin('users', 'u', 'u.user_id = ut.user_id'); 55 $q->addJoin('projects', 'p', 'p.project_id = t.task_project'); 56 $q->addJoin('companies', 'c', 'p.project_company = c.company_id'); 57 $q->addOrder('1, 2, 5, 4'); 58 $tasks = $q->loadList(); 59 60 $sqlMinMax = ' 61 SELECT min(t.task_start_date) task_min_date, max(t.task_end_date) task_max_date 62 FROM users u, tasks t, user_tasks ut 63 WHERE u.user_id = ut.user_id AND ut.task_id = t.task_id 64 '; 65 $q = new DBQuery; 66 $q->addTable('users', 'u'); 67 $q->addTable('tasks', 't'); 68 $q->addTable('user_tasks', 'ut'); 69 $q->addQuery('min(t.task_start_date) task_min_date, max(t.task_end_date) task_max_date'); 70 $q->addWhere('u.user_id = ut.user_id AND ut.task_id = t.task_id'); 71 $taskMinMax = $q->loadList(); 72 73 $width = w2PgetParam($_GET, 'width', 600); 74 $start_date = w2PgetParam($_GET, 'start_date', 0); 75 $end_date = w2PgetParam($_GET, 'end_date', 0); 76 $showTaskGantt = w2PgetParam($_GET, 'showTaskGantt', 0); 77 78 $graph2 = new GanttGraph($width); 79 $graph2->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY | GANTT_HWEEK); 80 81 $graph2->SetFrame(false); 82 $graph2->SetBox(true, array(0, 0, 0), 2); 83 $graph2->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY); 84 85 $pLocale = setlocale(LC_TIME, 0); // get current locale for LC_TIME 86 $res = setlocale(LC_TIME, $AppUI->user_lang[2]); 87 if ($res) { // Setting locale doesn't fail 88 $graph->scale->SetDateLocale($AppUI->user_lang[2]); 89 } 90 setlocale(LC_TIME, $pLocale); 91 92 if ($start_date && $end_date) { 93 $graph2->SetDateRange($start_date, $end_date); 94 } 95 96 //$graph2->scale->actinfo->SetFont(FF_CUSTOM); 97 $graph2->scale->actinfo->vgrid->SetColor('gray'); 98 $graph2->scale->actinfo->SetColor('darkgray'); 99 $graph2->scale->actinfo->SetColTitles(array($AppUI->_('User Name', UI_OUTPUT_RAW), $AppUI->_('Start Date', UI_OUTPUT_RAW), $AppUI->_('Finish', UI_OUTPUT_RAW), $AppUI->_(' ')), array(160, 10, 70, 70)); 100 101 $tableTitle = ($proFilter == '-1') ? $AppUI->_('All Tasks By Users') : $projectStatus[$proFilter]; 102 $graph2->scale->tableTitle->Set($tableTitle); 103 104 // Use TTF font if it exists 105 // try commenting out the following two lines if gantt charts do not display 106 if (is_file(TTF_DIR . 'FreeSansBold.ttf')) { 107 $graph2->scale->tableTitle->SetFont(FF_CUSTOM, FS_BOLD, 12); 108 } 109 $graph2->scale->SetTableTitleBackground('#eeeeee'); 110 $graph2->scale->tableTitle->Show(true); 111 112 //----------------------------------------- 113 // nice Gantt image 114 // if diff(end_date,start_date) > 90 days it shows only 115 //week number 116 // if diff(end_date,start_date) > 240 days it shows only 117 //month number 118 //----------------------------------------- 119 if ($start_date && $end_date) { 120 $min_d_start = new CDate($start_date); 121 $max_d_end = new CDate($end_date); 122 $graph2->SetDateRange($start_date, $end_date); 123 } else { 124 // find out DateRange from gant_arr 125 $d_start = new CDate(); 126 $d_end = new CDate(); 127 for ($i = 0, $i_cmp = count($taskMinMax); $i < $i_cmp; $i++) { 128 $start = substr($taskMinMax['task_min_date'], 0, 10); 129 $end = substr($taskMinMax['task_max_date'], 0, 10); 130 131 $d_start->Date($start); 132 $d_end->Date($end); 133 134 if ($i == 0) { 135 $min_d_start = $d_start; 136 $max_d_end = $d_end; 137 } else { 138 if (Date::compare($min_d_start, $d_start) > 0) { 139 $min_d_start = $d_start; 140 } 141 if (Date::compare($max_d_end, $d_end) < 0) { 142 $max_d_end = $d_end; 143 } 144 } 145 } 146 } 147 148 // check day_diff and modify Headers 149 $day_diff = $min_d_start->dateDiff($max_d_end); 150 151 if ($day_diff > 240) { 152 //more than 240 days 153 $graph2->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH); 154 } else 155 if ($day_diff > 90) { 156 //more than 90 days and less of 241 157 $graph2->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HWEEK); 158 $graph2->scale->week->SetStyle(WEEKSTYLE_WNBR); 159 } 160 161 $row = 0; 162 163 if (!is_array($tasks) || sizeof($tasks) == 0) { 164 $d = new CDate(); 165 $bar = new GanttBar($row++, array(' ' . $AppUI->_('No tasks found'), ' ', ' ', ' '), $d->getDate(), $d->getDate(), ' ', 0.6); 166 $bar->title->SetCOlor('red'); 167 $graph2->Add($bar); 168 } 169 170 if (is_array($tasks)) { 171 $nameUser = ''; 172 foreach ($tasks as $t) { 173 174 if ($nameUser != $t['user_name']) { 175 $row++; 176 $barTmp = new GanttBar($row++, array($t['user_name'], '', '', ' '), '0', '0;', 0.6); 177 $barTmp->title->SetColor('#' . $t['project_color_identifier']); 178 $barTmp->SetFillColor('#' . $t['project_color_identifier']); 179 if (is_file(TTF_DIR . 'FreeSansBold.ttf')) { 180 $barTmp->title->SetFont(FF_CUSTOM, FF_BOLD); 181 } 182 $graph2->Add($barTmp); 183 } 184 185 if ($locale_char_set == 'utf-8' && function_exists('utf_decode')) { 186 $name = strlen(utf8_decode($t['task_name'])) > 25 ? substr(utf8_decode($t['task_name']), 0, 22) . '...' : utf8_decode($t['task_name']); 187 $nameUser = $t['user_name']; 188 } else { 189 //while using charset different than UTF-8 we need not to use utf8_deocde 190 $name = strlen($t['task_name']) > 25 ? substr($t['task_name'], 0, 22) . '...' : $t['task_name']; 191 $nameUser = $t['user_name']; 192 } 193 194 //using new jpGraph determines using Date object instead of string 195 $start = ($t['task_start_date'] > '0000-00-00 00:00:00') ? $t['task_start_date'] : date('Y-m-d H:i:s'); 196 $end_date = $t['task_end_date']; 197 $actual_end = $t['task_end_date'] ? $t['task_end_date'] : ' '; 198 199 $end_date = new CDate($end_date); 200 // $end->addDays(0); 201 $end = $end_date->getDate(); 202 203 $start = new CDate($start); 204 // $start->addDays(0); 205 $start = $start->getDate(); 206 207 //$progress = $p['project_percent_complete']; 208 209 $caption = ''; 210 if (!$start || $start == '0000-00-00') { 211 $start = !$end ? date('Y-m-d') : $end; 212 $caption .= '(no start date)'; 213 } 214 215 if (!$end) { 216 $end = $start; 217 $caption .= ' (no end date)'; 218 } else { 219 $cap = ''; 220 } 221 222 if ($showLabels) { 223 $caption .= $t['project_name'] . ' (' . $t['perc_assignment'] . '%)'; 224 // $caption .= $p['project_active'] != 0 ? $AppUI->_('active') : $AppUI->_('inactive'); 225 } 226 227 if ($t['task_milestone'] != 1) { 228 $enddate = new CDate($end); 229 $startdate = new CDate($start); 230 $bar = new GanttBar($row++, array($name, $startdate->format($df), $enddate->format($df), /*substr($actual_end, 0, 10))*/ ' '), $start, $actual_end, $cap, $t['task_dynamic'] == 1 ? 0.1 : 0.6); 231 if (is_file(TTF_DIR . 'FreeSans.ttf')) { 232 $bar->title->SetFont(FF_CUSTOM, FS_NORMAL, 10); 233 } 234 $bar->SetFillColor('#' . $t['project_color_identifier']); 235 $bar->SetPattern(BAND_SOLID, '#' . $t['project_color_identifier']); 236 237 //adding captions 238 $bar->caption = new TextProperty($caption); 239 $bar->caption->Align('left', 'center'); 240 241 } else { 242 $bar = new MileStone($row++, $name, $start, (substr($start, 0, 10))); 243 $bar->title->SetColor('#CC0000'); 244 245 } 246 247 $graph2->Add($bar); 248 249 // If showAllGant checkbox is checked 250 } 251 } // End of check for valid projects array. 252 253 $today = date('y-m-d'); 254 $vline = new GanttVLine($today, $AppUI->_('Today', UI_OUTPUT_RAW)); 255 $graph->Add($vline); 256 $graph2->Stroke(); 257 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Jan 9 03:00:02 2009 | Cross-referenced by PHPXref 0.7 |