home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / projects / reports / userperformance.php < prev   
Encoding:
PHP Script  |  2003-12-18  |  6.5 KB  |  193 lines

  1. <?php
  2. $do_report             = dPgetParam( $_POST, "do_report", 0 );
  3. $log_start_date     = dPgetParam( $_POST, "log_start_date", 0 );
  4. $log_end_date         = dPgetParam( $_POST, "log_end_date", 0 );
  5. $log_all_projects     = dPgetParam($_POST["log_all_projects"], 0);
  6. $log_all            = dPgetParam($_POST["log_all"], 0);
  7. $group_by_unit      = dPgetParam($_POST["group_by_unit"],"day");
  8.  
  9. // create Date objects from the datetime fields
  10. $start_date = intval( $log_start_date ) ? new CDate( $log_start_date ) : new CDate();
  11. $end_date = intval( $log_end_date ) ? new CDate( $log_end_date ) : new CDate();
  12.  
  13. if (!$log_start_date) {
  14.     $start_date->subtractSpan( new Date_Span( "14,0,0,0" ) );
  15. }
  16. $end_date->setTime( 23, 59, 59 );
  17. ?>
  18.  
  19. <script language="javascript">
  20. var calendarField = '';
  21.  
  22. function popCalendar( field ){
  23.     calendarField = field;
  24.     idate = eval( 'document.editFrm.log_' + field + '.value' );
  25.     window.open( 'index.php?m=public&a=calendar&dialog=1&callback=setCalendar&date=' + idate, 'calwin', 'top=250,left=250,width=250, height=220, scollbars=false' );
  26. }
  27.  
  28. /**
  29.  *    @param string Input date in the format YYYYMMDD
  30.  *    @param string Formatted date
  31.  */
  32. function setCalendar( idate, fdate ) {
  33.     fld_date = eval( 'document.editFrm.log_' + calendarField );
  34.     fld_fdate = eval( 'document.editFrm.' + calendarField );
  35.     fld_date.value = idate;
  36.     fld_fdate.value = fdate;
  37. }
  38. </script>
  39.  
  40. <form name="editFrm" action="index.php?m=projects&a=reports" method="post">
  41. <input type="hidden" name="project_id" value="<?php echo $project_id;?>" />
  42. <input type="hidden" name="report_type" value="<?php echo $report_type;?>" />
  43.  
  44. <table cellspacing="0" cellpadding="4" border="0" width="100%" class="std">
  45.  
  46.  
  47. <tr>
  48.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_('For period');?>:</td>
  49.     <td nowrap="nowrap">
  50.         <input type="hidden" name="log_start_date" value="<?php echo $start_date->format( FMT_TIMESTAMP_DATE );?>" />
  51.         <input type="text" name="start_date" value="<?php echo $start_date->format( $df );?>" class="text" disabled="disabled" />
  52.         <a href="#" onClick="popCalendar('start_date')">
  53.             <img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0" />
  54.         </a>
  55.     </td>
  56.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_('to');?></td>
  57.     <td nowrap="nowrap">
  58.         <input type="hidden" name="log_end_date" value="<?php echo $end_date ? $end_date->format( FMT_TIMESTAMP_DATE ) : '';?>" />
  59.         <input type="text" name="end_date" value="<?php echo $end_date ? $end_date->format( $df ) : '';?>" class="text" disabled="disabled" />
  60.         <a href="#" onClick="popCalendar('end_date')">
  61.             <img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0" />
  62.         </a>
  63.     </td>
  64.  
  65.     <td nowrap="nowrap">
  66.         <input type="checkbox" name="log_all_projects" <?php if ($log_all_projects) echo "checked" ?> />
  67.         <?php echo $AppUI->_( 'Log All Projects' );?>
  68.     </td>
  69.     
  70.     <td nowrap='nowrap'>
  71.         <input type="checkbox" name="log_all" <?php if ($log_all) echo "checked" ?> />
  72.         <?php echo $AppUI->_( 'Log All' );?>
  73.     </td>
  74.  
  75.     <td align="right" width="50%" nowrap="nowrap">
  76.         <input class="button" type="submit" name="do_report" value="<?php echo $AppUI->_('submit');?>" />
  77.     </td>
  78. </tr>
  79.  
  80. </table>
  81. </form>
  82.  
  83. <?php
  84. if($do_report){
  85.     
  86.     // Let's figure out which users we have
  87.     $sql = "SELECT  u.user_id,
  88.                      u.user_username, 
  89.                     u.user_first_name, 
  90.                     u.user_last_name
  91.             FROM users AS u";
  92.     
  93.     $user_list = db_loadHashList($sql, "user_id");
  94.     
  95.     // Now which tasks will we need and the real allocated hours (estimated time / number of users)
  96.     // Also we will use tasks with duration_type = 1 (hours) and those that are not marked
  97.     // as milstones
  98.     $sql = "SELECT t.task_id, round(t.task_duration * t.task_duration_type/count(ut.task_id),2) as hours_allocated
  99.             FROM tasks as t, user_tasks as ut
  100.             WHERE t.task_id = ut.task_id
  101.                   AND t.task_milestone    ='0'";
  102.     
  103.     if(!$log_all_projects){
  104.         $sql .= " AND t.task_project='$project_id'\n";
  105.     }
  106.     
  107.     if(!$log_all){
  108.         $sql .= " AND t.task_start_date >= \"".$start_date->format( FMT_DATETIME_MYSQL )."\"
  109.                   AND t.task_start_date <= \"".$end_date->format( FMT_DATETIME_MYSQL )."\"";
  110.     }
  111.     
  112.     $sql .= "GROUP BY t.task_id";
  113.     
  114.     $task_list = db_loadHashList($sql, "task_id");
  115.     //echo $sql;
  116. ?>
  117.  
  118. <table cellspacing="1" cellpadding="4" border="0" class="tbl">
  119.     <tr>
  120.         <th colspan='2'><?php echo $AppUI->_('User');?></th>
  121.         <th><?php echo $AppUI->_('Hours allocated'); ?></th>
  122.         <th><?php echo $AppUI->_('Hours worked'); ?></th>
  123.         <th>%</th>
  124.     </tr>
  125.  
  126. <?php
  127.     if(count($user_list)){
  128.         $percentage_sum = $hours_allocated_sum = $hours_worked_sum = 0;
  129.         $sum_total_hours_allocated = $sum_total_hours_worked = 0;
  130.         
  131.         foreach($user_list as $user_id => $user){
  132.             $sql = "SELECT task_id
  133.                     FROM user_tasks
  134.                     where user_id = $user_id";
  135.             $tasks_id = db_loadColumn($sql);
  136.  
  137.             $total_hours_allocated = $total_hours_worked = 0;
  138.             
  139.             foreach($tasks_id as $task_id){
  140.                 if(isset($task_list[$task_id])){
  141.                     // Now let's figure out how many time did the user spent in this task
  142.                     $sql = "SELECT sum(task_log_hours)
  143.                             FROM task_log
  144.                             WHERE task_log_task        = $task_id
  145.                                   AND task_log_creator = $user_id";
  146.                     $hours_worked = round(db_loadResult($sql),2);
  147.                     
  148.                     $total_hours_allocated += $task_list[$task_id]["hours_allocated"];
  149.                     $total_hours_worked    += $hours_worked;
  150.                 }
  151.             }
  152.             
  153.             $sum_total_hours_allocated += $total_hours_allocated;
  154.             $sum_total_hours_worked    += $total_hours_worked;
  155.             
  156.             if($total_hours_allocated > 0 || $total_hours_worked > 0){
  157.                 $percentage = 0;
  158.                 if($total_hours_worked>0){
  159.                     $percentage = ($total_hours_allocated/$total_hours_worked)*100;
  160.                 }
  161.                 ?>
  162.                 <tr>
  163.                     <td><?php echo "(".$user["user_username"].") </td><td> ".$user["user_first_name"]." ".$user["user_last_name"]; ?></td>
  164.                     <td align='right'><?php echo $total_hours_allocated; ?> </td>
  165.                     <td align='right'><?php echo $total_hours_worked; ?> </td>
  166.                     <td align='right'> <?php echo number_format($percentage,0); ?>% </td>
  167.                 </tr>
  168.                 <?php
  169.             }
  170.         }
  171.         $sum_percentage = 0;
  172.         if($sum_total_hours_worked > 0){
  173.             $sum_percentage = ($sum_total_hours_allocated/$sum_total_hours_worked)*100;
  174.         }
  175.         ?>
  176.             <tr>
  177.                 <td colspan='2'><?php echo $AppUI->_('Total'); ?></td>
  178.                 <td align='right'><?php echo $sum_total_hours_allocated; ?></td>
  179.                 <td align='right'><?php echo $sum_total_hours_worked; ?></td>
  180.                 <td align='right'><?php echo number_format($sum_percentage,0); ?>%</td>
  181.             </tr>
  182.         <?php
  183.     } else {
  184.         ?>
  185.         <tr>
  186.             <td><p><?php echo $AppUI->_('There are no tasks that fulfill selected filters');?></p></td>
  187.         </tr>
  188.         <?php
  189.     }
  190. }
  191. ?>
  192. </table>
  193.