home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / calendar / links_tasks.php < prev    next >
Encoding:
PHP Script  |  2003-09-11  |  3.9 KB  |  111 lines

  1. <?php /* CALENDAR $Id: links_tasks.php,v 1.5 2003/09/11 02:04:02 gregorerhardt Exp $ */
  2.  
  3. /**
  4. * Sub-function to collect tasks within a period
  5. *
  6. * @param Date the starting date of the period
  7. * @param Date the ending date of the period
  8. * @param array by-ref an array of links to append new items to
  9. * @param int the length to truncate entries by
  10. * @param int the company id to filter by
  11. * @author Andrew Eddie <eddieajau@users.sourceforge.net>
  12. */
  13. function getTaskLinks( $startPeriod, $endPeriod, &$links, $strMaxLen, $company_id=0 ) {
  14.     GLOBAL $AppUI;
  15.     $tasks = CTask::getTasksForPeriod( $startPeriod, $endPeriod, $company_id );
  16.  
  17. //echo "<br>entering add tasks dt=".dPgetMicroDiff();
  18.     $durnTypes = dPgetSysVal( 'TaskDurationType' );
  19.  
  20.     $link = array();
  21.     $sid = 3600*24;
  22.     // assemble the links for the tasks
  23. //echo '<br><b>'.$startPeriod->format( FMT_TIMESTAMP );
  24. //echo ','.$endPeriod->format( FMT_TIMESTAMP ).'</b>';
  25.  
  26.     foreach ($tasks as $row) {
  27.     // the link
  28.         $link['href'] = "?m=tasks&a=view&task_id=".$row['task_id'];
  29.         $link['alt'] = $row['project_name'].":\n".$row['task_name'];
  30.  
  31.     // the link text
  32.         if (strlen( $row['task_name'] ) > $strMaxLen) {
  33.             $row['task_name'] = substr( $row['task_name'], 0, $strMaxLen ).'...';
  34.         }
  35.         $link['text'] = '<span style="color:'.bestColor($row['color']).';background-color:#'.$row['color'].'">'.$row['task_name'].'</span>';
  36.  
  37. //echo " [".dPgetMicroDiff()."]<sup>1</sup> ";
  38.     // determine which day(s) to display the task
  39.         $start = new CDate( $row['task_start_date'] );
  40.         $end = $row['task_end_date'] ? new CDate( $row['task_end_date'] ) : null;
  41.         $durn = $row['task_duration'];
  42.         $durnType = $row['task_duration_type'];
  43.  
  44. //echo '<br>'.$start->format( FMT_TIMESTAMP );
  45. //echo ','.$end->format( FMT_TIMESTAMP );
  46. //echo ",$durn,$durnType";
  47.  
  48. //echo "  ".intval($start->after( $startPeriod ) && $start->before( $endPeriod ));
  49. //echo intval($end && $end->after( $startPeriod ) && $end->before( $endPeriod )&& $start->before( $end ));
  50.         if (($start->after( $startPeriod ) || $start->equals($startPeriod) ) && ($start->before( $endPeriod ) || $start->equals($endPeriod) ) ) {
  51.             $temp = $link;
  52.             $temp['alt'] = "START [".$row['task_duration'].' '.$AppUI->_( $durnTypes[$row['task_duration_type']] )."]\n".$link['alt'];
  53.             $links[$start->format( FMT_TIMESTAMP_DATE )][] = $temp;
  54.         }
  55.         if ($end && $end->after( $startPeriod ) && $end->before( $endPeriod )
  56.                 && $start->before( $end )) {
  57.             $temp = $link;
  58.             $temp['alt'] = "FINISH\n".$link['alt'];
  59.             $links[$end->format( FMT_TIMESTAMP_DATE )][] = $temp;
  60.         }
  61.     // convert duration to days
  62.         if ($durnType < 24.0 ) {
  63.             if ($durn > $AppUI->cfg['daily_working_hours']) {
  64.                 $durn /= $AppUI->cfg['daily_working_hours'];
  65.             } else {
  66.                 $durn = 0.0;
  67.             }
  68.         } else {
  69.             $durn *= ($durnType / 24.0);
  70.         }
  71. //echo "   -- durn=$durn";
  72.     // fill in between start and finish based on duration
  73.         if ($durn > 1) {
  74.     // notes:
  75.         // start date is not in a future month, must be this or past month
  76.         // start date is counted as one days work
  77.         // business days are not taken into account
  78.             $target = $start;
  79.             $target->addSeconds( $durn*$sid );
  80.  
  81. //echo Date::compare( $target, $startPeriod ) < 0 ? '<font color=red>' : '<font color=green>';
  82. //echo ','.$target->format( FMT_TIMESTAMP_DATE ).'</font>';
  83. //echo "  ,".intval(Date::compare( $start, $startPeriod ));
  84.  
  85.             if (Date::compare( $target, $startPeriod ) < 0) {
  86.                 continue;
  87.             }
  88.             if (Date::compare( $start, $startPeriod ) > 0) {
  89.                 $temp = $start;
  90.                 $temp->addSeconds( $sid );
  91.             } else {
  92.                 $temp = $startPeriod;
  93.             }
  94. //echo ',temp='.$temp->format( FMT_TIMESTAMP_DATE );
  95. //echo "  ,".intval(Date::compare( $endPeriod, $temp ));
  96. //echo "  ,".intval(Date::compare( $target, $temp ));
  97. //continue;
  98.  
  99.             while (Date::compare( $endPeriod, $temp ) > 0) {
  100.                 if (Date::compare( $target, $temp ) > 0) {
  101.                     if ($end == null || $temp->before($end)) {
  102.                         $links[$temp->format( FMT_TIMESTAMP_DATE )][] = $link;
  103.                     }
  104.                 }
  105.                 $temp->addSeconds( $sid );
  106.             }
  107.         }
  108.     }
  109. }
  110. ?>
  111.