home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / projects / reports / tasklogs.php < prev    next >
Encoding:
PHP Script  |  2004-01-14  |  9.3 KB  |  292 lines

  1. <?php /* PROJECTS $Id: tasklogs.php,v 1.4 2004/01/14 03:11:59 dylan_cuthbert Exp $ */
  2. /**
  3. * Generates a report of the task logs for given dates
  4. */
  5. error_reporting( E_ALL );
  6. $do_report = dPgetParam( $_POST, "do_report", 0 );
  7. $log_all = dPgetParam( $_POST, 'log_all', 0 );
  8. $log_pdf = dPgetParam( $_POST, 'log_pdf', 0 );
  9. $log_ignore = dPgetParam( $_POST, 'log_ignore', 0 );
  10. $log_userfilter = dPgetParam( $_POST, 'log_userfilter', '0' );
  11. $log_allprojects = dPgetParam( $_POST, 'log_allprojects', '0' );
  12.  
  13. $log_start_date = dPgetParam( $_POST, "log_start_date", 0 );
  14. $log_end_date = dPgetParam( $_POST, "log_end_date", 0 );
  15.  
  16. // create Date objects from the datetime fields
  17. $start_date = intval( $log_start_date ) ? new CDate( $log_start_date ) : new CDate();
  18. $end_date = intval( $log_end_date ) ? new CDate( $log_end_date ) : new CDate();
  19.  
  20. if (!$log_start_date) {
  21.     $start_date->subtractSpan( new Date_Span( "14,0,0,0" ) );
  22. }
  23. $end_date->setTime( 23, 59, 59 );
  24.  
  25. ?>
  26. <script language="javascript">
  27. var calendarField = '';
  28.  
  29. function popCalendar( field ){
  30.     calendarField = field;
  31.     idate = eval( 'document.editFrm.log_' + field + '.value' );
  32.     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' );
  33. }
  34.  
  35. /**
  36.  *    @param string Input date in the format YYYYMMDD
  37.  *    @param string Formatted date
  38.  */
  39. function setCalendar( idate, fdate ) {
  40.     fld_date = eval( 'document.editFrm.log_' + calendarField );
  41.     fld_fdate = eval( 'document.editFrm.' + calendarField );
  42.     fld_date.value = idate;
  43.     fld_fdate.value = fdate;
  44. }
  45. </script>
  46.  
  47. <table cellspacing="0" cellpadding="4" border="0" width="100%" class="std">
  48.  
  49. <form name="editFrm" action="index.php?m=projects&a=reports" method="post">
  50. <input type="hidden" name="project_id" value="<?php echo $project_id;?>" />
  51. <input type="hidden" name="report_type" value="<?php echo $report_type;?>" />
  52.  
  53. <tr>
  54.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_('For period');?>:</td>
  55.     <td nowrap="nowrap">
  56.         <input type="hidden" name="log_start_date" value="<?php echo $start_date->format( FMT_TIMESTAMP_DATE );?>" />
  57.         <input type="text" name="start_date" value="<?php echo $start_date->format( $df );?>" class="text" disabled="disabled" style="width: 80px" />
  58.         <a href="#" onClick="popCalendar('start_date')">
  59.             <img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0" />
  60.         </a>
  61.     </td>
  62.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_('to');?></td>
  63.     <td nowrap="nowrap">
  64.         <input type="hidden" name="log_end_date" value="<?php echo $end_date ? $end_date->format( FMT_TIMESTAMP_DATE ) : '';?>" />
  65.         <input type="text" name="end_date" value="<?php echo $end_date ? $end_date->format( $df ) : '';?>" class="text" disabled="disabled" style="width: 80px"/>
  66.         <a href="#" onClick="popCalendar('end_date')">
  67.             <img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0" />
  68.         </a>
  69.     </td>
  70.     
  71.     <TD NOWRAP>
  72.         <?php echo $AppUI->_('User');?>: 
  73.         <SELECT NAME="log_userfilter" CLASS="text" STYLE="width: 80px">
  74.         
  75.     <?php
  76.         $usersql = "
  77.         SELECT user_id, user_username, user_first_name, user_last_name
  78.         FROM users
  79.         ";
  80.         
  81.         if ( $log_userfilter == 0 ) echo '<OPTION VALUE="0" SELECTED>'.$AppUI->_('All users' );
  82.         else echo '<OPTION VALUE="0">All users';
  83.         
  84.         if (($rows = db_loadList( $usersql, NULL )))
  85.         {
  86.             foreach ($rows as $row)
  87.             {
  88.                 if ( $log_userfilter == $row["user_id"])
  89.                     echo "<OPTION VALUE='".$row["user_id"]."' SELECTED>".$row["user_username"];
  90.                 else
  91.                     echo "<OPTION VALUE='".$row["user_id"]."'>".$row["user_username"];
  92.             }
  93.         }
  94.  
  95.     ?>
  96.             
  97.         </SELECT>
  98.     </TD>
  99.  
  100.     <td nowrap="nowrap">
  101.         <input type="checkbox" name="log_allprojects" <?php if ($log_allprojects) echo "checked" ?> />
  102.         <?php echo $AppUI->_( 'All Projects' );?>
  103.     </td>
  104.  
  105.     <td nowrap="nowrap">
  106.         <input type="checkbox" name="log_all" <?php if ($log_all) echo "checked" ?> />
  107.         <?php echo $AppUI->_( 'Log All' );?>
  108.     </td>
  109.  
  110.     <td nowrap="nowrap">
  111.         <input type="checkbox" name="log_pdf" <?php if ($log_pdf) echo "checked" ?> />
  112.         <?php echo $AppUI->_( 'Make PDF' );?>
  113.     </td>
  114.  
  115.     <td nowrap="nowrap">
  116.         <input type="checkbox" name="log_ignore" />
  117.         <?php echo $AppUI->_( 'Ignore 0 hours' );?>
  118.     </td>
  119.  
  120.     <td align="right" width="50%" nowrap="nowrap">
  121.         <input class="button" type="submit" name="do_report" value="<?php echo $AppUI->_('submit');?>" />
  122.     </td>
  123. </tr>
  124. </form>
  125. </table>
  126.  
  127. <?php
  128. if ($do_report) {
  129.  
  130.     $sql = "SELECT t.*, CONCAT_WS(' ',u.user_first_name,u.user_last_name) AS creator"
  131.         ."\nFROM task_log AS t, tasks"
  132.         ."\nLEFT JOIN users AS u ON user_id = task_log_creator"
  133.         ."\nWHERE task_log_task = task_id";
  134.     if (!$log_allprojects)
  135.     {
  136.          $sql .= "\nAND task_project = $project_id";
  137.     }
  138.     if (!$log_all) {
  139.         $sql .= "\n    AND task_log_date >= '".$start_date->format( FMT_DATETIME_MYSQL )."'"
  140.         ."\n    AND task_log_date <= '".$end_date->format( FMT_DATETIME_MYSQL )."'";
  141.     }
  142.     if ($log_ignore) {
  143.         $sql .= "\n    AND task_log_hours > 0";
  144.     }
  145.     if ($log_userfilter) {
  146.         $sql .= "\n    AND task_log_creator = $log_userfilter";
  147.     }
  148.     $sql .= " ORDER BY task_log_date";
  149.  
  150.     //echo "<pre>$sql</pre>";
  151.  
  152.     $logs = db_loadList( $sql );
  153.     echo db_error();
  154. ?>
  155.     <table cellspacing="1" cellpadding="4" border="0" class="tbl">
  156.     <tr>
  157.         <th nowrap="nowrap"><?php echo $AppUI->_('Created by');?></th>
  158.         <th><?php echo $AppUI->_('Summary');?></th>
  159.         <th><?php echo $AppUI->_('Description');?></th>
  160.         <th><?php echo $AppUI->_('Date');?></th>
  161.         <th><?php echo $AppUI->_('Hours');?></th>
  162.         <th><?php echo $AppUI->_('Cost Code');?></th>
  163.     </tr>
  164. <?php
  165.     $hours = 0.0;
  166.     $pdfdata = array();
  167.     $pdfdata[] = array(
  168.         $AppUI->_('Created by'),
  169.         $AppUI->_('Summary'),
  170.         $AppUI->_('Description'),
  171.         $AppUI->_('Date'),
  172.         $AppUI->_('Hours'),
  173.         $AppUI->_('Cost Code')
  174.     );
  175.  
  176.     foreach ($logs as $log) {
  177.         $date = new CDate( $log['task_log_date'] );
  178.         $hours += $log['task_log_hours'];
  179.  
  180.         $pdfdata[] = array(
  181.             $log['creator'],
  182.             $log['task_log_name'],
  183.             $log['task_log_description'],
  184.             $date->format( $df ),
  185.             sprintf( "%.2f", $log['task_log_hours'] ),
  186.             $log['task_log_costcode'],
  187.         );
  188. ?>
  189.     <tr>
  190.         <td><?php echo $log['creator'];?></td>
  191.         <td>
  192.             <a href="index.php?m=tasks&a=view&tab=1&task_id=<?php echo $log['task_log_task'];?>&task_log_id=<?php echo $log['task_log_id'];?>"><?php echo $log['task_log_name'];?></a>
  193.         </td>
  194.         <td><?php
  195. // dylan_cuthbert: auto-transation system in-progress, leave these lines for time-being
  196.             $transbrk = "\n[translation]\n";
  197.             $descrip = str_replace( "\n", "<br />", $log['task_log_description'] );
  198.             $tranpos = strpos( $descrip, str_replace( "\n", "<br />", $transbrk ) );
  199.             if ( $tranpos === false) echo $descrip;
  200.             else
  201.             {
  202.                 $descrip = substr( $descrip, 0, $tranpos );
  203.                 $tranpos = strpos( $log['task_log_description'], $transbrk );
  204.                 $transla = substr( $log['task_log_description'], $tranpos + strlen( $transbrk ) );
  205.                 $transla = trim( str_replace( "'", '"', $transla ) );
  206.                 echo $descrip."<div style='font-weight: bold; text-align: right'><a title='$transla' class='hilite'>[".$AppUI->_("translation")."]</a></div>";
  207.             }
  208. // dylan_cuthbert; auto-translation end
  209.             ?></td>
  210.         <td><?php echo $date->format( $df );?></td>
  211.         <td align="right"><?php printf( "%.2f", $log['task_log_hours'] );?></td>
  212.         <td><?php echo $log['task_log_costcode'];?></td>
  213.     </tr>
  214. <?php
  215.     }
  216.     $pdfdata[] = array(
  217.         '',
  218.         '',
  219.         '',
  220.         $AppUI->_('Total Hours').':',
  221.         sprintf( "%.2f", $hours ),
  222.         '',
  223.     );
  224. ?>
  225.     <tr>
  226.         <td align="right" colspan="4"><?php echo $AppUI->_('Total Hours');?>:</td>
  227.         <td align="right"><?php printf( "%.2f", $hours );?></td>
  228.     </tr>
  229.     </table>
  230. <?php
  231.     if ($log_pdf) {
  232.     // make the PDF file
  233.         $sql = "SELECT project_name FROM projects WHERE project_id=$project_id";
  234.         $pname = db_loadResult( $sql );
  235.         echo db_error();
  236.  
  237.         $font_dir = $AppUI->getConfig( 'root_dir' )."/lib/ezpdf/fonts";
  238.         $temp_dir = $AppUI->getConfig( 'root_dir' )."/files/temp";
  239.         $base_url  = $AppUI->getConfig( 'base_url' );
  240.         require( $AppUI->getLibraryClass( 'ezpdf/class.ezpdf' ) );
  241.  
  242.         $pdf =& new Cezpdf();
  243.         $pdf->ezSetCmMargins( 1, 2, 1.5, 1.5 );
  244.         $pdf->selectFont( "$font_dir/Helvetica.afm" );
  245.  
  246.         $pdf->ezText( $AppUI->getConfig( 'company_name' ), 12 );
  247.         // $pdf->ezText( $AppUI->getConfig( 'company_name' ).' :: '.$AppUI->getConfig( 'page_title' ), 12 );        
  248.  
  249.         $date = new CDate();
  250.         $pdf->ezText( "\n" . $date->format( $df ) , 8 );
  251.  
  252.         $pdf->selectFont( "$font_dir/Helvetica-Bold.afm" );
  253.         $pdf->ezText( "\n" . $AppUI->_('Task Log Report'), 12 );
  254.         $pdf->ezText( "$pname", 15 );
  255.         if ($log_all) {
  256.             $pdf->ezText( "All task log entries", 9 );
  257.         } else {
  258.             $pdf->ezText( "Task log entries from ".$start_date->format( $df ).' to '.$end_date->format( $df ), 9 );
  259.         }
  260.         $pdf->ezText( "\n\n" );
  261.  
  262.         $columns = null;
  263.         $title = null;
  264.         $options = array(
  265.             'showLines' => 1,
  266.             'showHeadings' => 0,
  267.             'fontSize' => 8,
  268.             'rowGap' => 2,
  269.             'colGap' => 5,
  270.             'xPos' => 50,
  271.             'xOrientation' => 'right',
  272.             'width'=>'500'
  273.         );
  274.  
  275.         $pdf->ezTable( $pdfdata, $columns, $title, $options );
  276.  
  277.         if ($fp = fopen( "$temp_dir/temp$AppUI->user_id.pdf", 'wb' )) {
  278.             fwrite( $fp, $pdf->ezOutput() );
  279.             fclose( $fp );
  280.             echo "<a href=\"$base_url/files/temp/temp$AppUI->user_id.pdf\" target=\"pdf\">";
  281.             echo $AppUI->_( "View PDF File" );
  282.             echo "</a>";
  283.         } else {
  284.             echo "Could not open file to save PDF.  ";
  285.             if (!is_writable( $temp_dir )) {
  286.                 "The files/temp directory is not writable.  Check your file system permissions.";
  287.             }
  288.         }
  289.     }
  290. }
  291. ?>
  292.