[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/modules/reports/reports/ -> tasklist.php (source)

   1  <?php /* $Id: tasklist.php 135 2008-04-04 13:49:13Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/reports/reports/tasklist.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  global $AppUI, $cal_sdf;
   6  $AppUI->loadCalendarJS();
   7  
   8  /**

   9   * Generates a report of the task logs for given dates

  10   */
  11  //error_reporting( E_ALL );

  12  $do_report = w2PgetParam($_POST, 'do_report', 0);
  13  $log_all = w2PgetParam($_POST, 'log_all', 0);
  14  $log_pdf = w2PgetParam($_POST, 'log_pdf', 0);
  15  $log_ignore = w2PgetParam($_POST, 'log_ignore', 0);
  16  $days = w2PgetParam($_POST, 'days', 30);
  17  
  18  $list_start_date = w2PgetParam($_POST, 'list_start_date', 0);
  19  $list_end_date = w2PgetParam($_POST, 'list_end_date', 0);
  20  
  21  $period = w2PgetParam($_POST, 'period', 0);
  22  $period_value = w2PgetParam($_POST, 'pvalue', 1);
  23  if ($period) {
  24      $today = new CDate();
  25      $ts = $today->format(FMT_TIMESTAMP_DATE);
  26      if (strtok($period, ' ') == $AppUI->_('Next')) {
  27          $sign = + 1;
  28      } else { //if(...)
  29          $sign = -1;
  30      }
  31  
  32      $day_word = strtok(' ');
  33      if ($day_word == $AppUI->_('Day')) {
  34          $days = $period_value;
  35      } elseif ($day_word == $AppUI->_('Week')) {
  36          $days = 7 * $period_value;
  37      } elseif ($day_word == $AppUI->_('Month')) {
  38          $days = 30 * $period_value;
  39      }
  40  
  41      $start_date = new CDate($ts);
  42      $end_date = new CDate($ts);
  43  
  44      if ($sign > 0) {
  45          $end_date->addSpan(new Date_Span("$days,0,0,0"));
  46      } else {
  47          $start_date->subtractSpan(new Date_Span("$days,0,0,0"));
  48      }
  49  
  50      $do_report = 1;
  51  
  52  } else {
  53      // create Date objects from the datetime fields

  54      $start_date = intval($list_start_date) ? new CDate($list_start_date) : new CDate();
  55      $end_date = intval($list_end_date) ? new CDate($list_end_date) : new CDate();
  56  }
  57  
  58  if (!$list_start_date) {
  59      $start_date->subtractSpan(new Date_Span('14,0,0,0'));
  60  }
  61  $end_date->setTime(23, 59, 59);
  62  
  63  ?>
  64  <script language="javascript">
  65  function setDate( frm_name, f_date ) {
  66      fld_date = eval( 'document.' + frm_name + '.' + f_date );
  67      fld_real_date = eval( 'document.' + frm_name + '.' + 'list_' + f_date );
  68      if (fld_date.value.length>0) {
  69        if ((parseDate(fld_date.value))==null) {
  70              alert('The Date/Time you typed does not match your prefered format, please retype.');
  71              fld_real_date.value = '';
  72              fld_date.style.backgroundColor = 'red';
  73          } else {
  74              fld_real_date.value = formatDate(parseDate(fld_date.value), 'yyyyMMdd');
  75              fld_date.value = formatDate(parseDate(fld_date.value), '<?php echo $cal_sdf ?>');
  76              fld_date.style.backgroundColor = '';
  77            }
  78      } else {
  79            fld_real_date.value = '';
  80      }
  81  }
  82  </script>
  83  
  84  <form name="editFrm" action="index.php?m=reports" method="post">
  85      <input type="hidden" name="project_id" value="<?php echo $project_id; ?>" />
  86      <input type="hidden" name="report_type" value="<?php echo $report_type; ?>" />
  87  
  88  <?php
  89  if (function_exists('styleRenderBoxTop')) {
  90      echo styleRenderBoxTop();
  91  }
  92  ?>
  93  <table cellspacing="0" cellpadding="4" border="0" width="100%" class="std">
  94  <tr>
  95          <td align="right"><?php echo $AppUI->_('Default Actions'); ?>:</td>
  96          <td nowrap="nowrap" colspan="2">
  97            <input class="button" type="submit" name="period" value="<?php echo $AppUI->_('Previous Month'); ?>" />
  98            <input class="button" type="submit" name="period" value="<?php echo $AppUI->_('Previous Week'); ?>" />
  99            <input class="button" type="submit" name="period" value="<?php echo $AppUI->_('Previous Day'); ?>" />
 100          </td>
 101          <td nowrap="nowrap">
 102            <input class="button" type="submit" name="period" value="<?php echo $AppUI->_('Next Day'); ?>" />
 103            <input class="button" type="submit" name="period" value="<?php echo $AppUI->_('Next Week'); ?>" />
 104            <input class="button" type="submit" name="period" value="<?php echo $AppUI->_('Next Month'); ?>" />
 105            </td>
 106          <td colspan="3"><input class="text" type="field" size="2" name="pvalue" value="1" /> - value for the previous buttons</td>
 107  <!--
 108          <td><input class="button" type="submit" name="do_report" value="<?php echo $AppUI->_('Previous Month'); ?>" onClick="set(-30)" /></td>
 109          <td><input class="button" type="submit" name="do_report" value="<?php echo $AppUI->_('Previous Week'); ?>" onClick="set(-7)" /></td>
 110          <td><input class="button" type="submit" name="do_report" value="<?php echo $AppUI->_('Next Week'); ?>" onClick="set(7)" /></td>
 111          <td><input class="button" type="submit" name="do_report" value="<?php echo $AppUI->_('Next Month'); ?>" onClick="set(30)" /></td>
 112  -->
 113  </tr>
 114  <tr>
 115  
 116      <td align="right" nowrap="nowrap"><?php echo $AppUI->_('For period'); ?>:</td>
 117      <td nowrap="nowrap">
 118          <input type="hidden" name="list_start_date" id="list_start_date" value="<?php echo $start_date ? $start_date->format(FMT_TIMESTAMP_DATE) : ''; ?>" />
 119          <input type="text" name="start_date" id="start_date" onchange="setDate('editFrm', 'start_date');" value="<?php echo $start_date ? $start_date->format($df) : ''; ?>" class="text" />
 120          <a href="javascript: void(0);" onclick="return showCalendar('start_date', '<?php echo $df ?>', 'editFrm', null, true)">
 121              <img src="<?php echo w2PfindImage('calendar.gif'); ?>" width="24" height="12" alt="<?php echo $AppUI->_('Calendar'); ?>" border="0" />
 122          </a>
 123      </td>
 124      <td align="right" nowrap="nowrap"><?php echo $AppUI->_('to'); ?></td>
 125      <td nowrap="nowrap">
 126          <input type="hidden" name="list_end_date" id="list_end_date" value="<?php echo $end_date ? $end_date->format(FMT_TIMESTAMP_DATE) : ''; ?>" />
 127          <input type="text" name="end_date" id="end_date" onchange="setDate('editFrm', 'end_date');" value="<?php echo $end_date ? $end_date->format($df) : ''; ?>" class="text" />
 128          <a href="javascript: void(0);" onclick="return showCalendar('end_date', '<?php echo $df ?>', 'editFrm', null, true)">
 129              <img src="<?php echo w2PfindImage('calendar.gif'); ?>" width="24" height="12" alt="<?php echo $AppUI->_('Calendar'); ?>" border="0" />
 130          </a>
 131      </td>
 132  
 133      <td nowrap="nowrap">
 134          <input type="checkbox" name="log_all" id="log_all" <?php if ($log_all)
 135      echo 'checked="checked"' ?> />
 136          <label for="log_all"><?php echo $AppUI->_('Log All'); ?></label>
 137      </td>
 138      <td nowrap="nowrap">
 139          <input type="checkbox" name="log_pdf" id="log_pdf" <?php if ($log_pdf)
 140      echo 'checked="checked"' ?> />
 141          <label for="log_pdf"><?php echo $AppUI->_('Make PDF'); ?></label>
 142      </td>
 143  
 144      <td align="right" width="50%" nowrap="nowrap">
 145          <input class="button" type="submit" name="do_report" value="<?php echo $AppUI->_('submit'); ?>" />
 146      </td>
 147  </tr>
 148  </table>
 149  </form>
 150  <?php
 151  if ($do_report) {
 152  
 153      if ($project_id == 0) {
 154          $q = new DBQuery;
 155          $q->addTable('tasks', 'a');
 156          $q->addTable('projects', 'b');
 157          $q->addQuery('a.*, b.project_name');
 158          $q->addWhere('a.task_project = b.project_id');
 159          $q->addWhere('b.project_active = 1');
 160          if (($template_status = w2PgetConfig('template_projects_status_id')) != '') {
 161              $q->addWhere('b.project_status <> ' . (int)$template_status);
 162          }
 163      } else {
 164          $q = new DBQuery;
 165          $q->addTable('tasks', 'a');
 166          $q->addWhere('task_project =' . $project_id);
 167      }
 168      if (!$log_all) {
 169          $q->addWhere('task_start_date >= \'' . $start_date->format(FMT_DATETIME_MYSQL) . '\'');
 170          $q->addWhere('task_start_date <= \'' . $end_date->format(FMT_DATETIME_MYSQL) . '\'');
 171      }
 172  
 173      $obj = &new CTask;
 174      $allowedTasks = $obj->getAllowedSQL($AppUI->user_id);
 175      if (count($allowedTasks)) {
 176          $obj->getAllowedSQL($AppUI->user_id, $q);
 177      }
 178      $q->addOrder('task_start_date');
 179      $Task_List = $q->exec();
 180  
 181      if (function_exists('styleRenderBoxBottom')) {
 182          echo styleRenderBoxBottom();
 183      }
 184      echo '<br />';
 185      if (function_exists('styleRenderBoxTop')) {
 186          echo styleRenderBoxTop();
 187      }
 188      echo '<table cellspacing="0" cellpadding="4" border="0" width="100%" class="std">
 189  <tr>
 190      <td>';
 191  
 192      echo '<table cellspacing="1" cellpadding="4" border="0" class="tbl">';
 193      if ($project_id == 0) {
 194          echo '<tr><th>Project Name</th><th>Task Name</th>';
 195      } else {
 196          echo '<tr><th>Task Name</th>';
 197      }
 198      echo '<th width=400>Task Description</th>';
 199      echo '<th>Assigned To</th>';
 200      echo '<th>Task Start Date</th>';
 201      echo '<th>Task End Date</th>';
 202      echo '<th>Completion</th></tr>';
 203  
 204      $pdfdata = array();
 205      $columns = array('<b>' . $AppUI->_('Task Name') . '</b>', '<b>' . $AppUI->_('Task Description') . '</b>', '<b>' . $AppUI->_('Assigned To') . '</b>', '<b>' . $AppUI->_('Task Start Date') . '</b>', '<b>' . $AppUI->_('Task End Date') . '</b>', '<b>' . $AppUI->_('Completion') . '</b>');
 206      if ($project_id == 0) {
 207          array_unshift($columns, '<b>' . $AppUI->_('Project Name') . '</b>');
 208      }
 209      while ($Tasks = db_fetch_assoc($Task_List)) {
 210          $start_date = intval($Tasks['task_start_date']) ? new CDate($Tasks['task_start_date']) : ' ';
 211          $end_date = intval($Tasks['task_end_date']) ? new CDate($Tasks['task_end_date']) : ' ';
 212          $task_id = $Tasks['task_id'];
 213  
 214          $q = new DBQuery;
 215          $q->addTable('user_tasks');
 216          $q->addWhere('task_id = ' . (int)$task_id);
 217          $sql_user = $q->exec();
 218  
 219          $users = null;
 220          while ($Task_User = db_fetch_assoc($sql_user)) {
 221              //$current_user = $Task_User['user_id'];

 222              if ($users != null) {
 223                  $users .= ', ';
 224              }
 225  
 226              $q->clear();
 227              $q = new DBQuery;
 228              $q->addTable('users', 'u');
 229              $q->addTable('contacts', 'c');
 230              $q->addQuery('contact_first_name, contact_last_name');
 231              $q->addWhere('u.user_contact = c.contact_id');
 232              $q->addWhere('user_id = ' . (int)$Task_User['user_id']);
 233  
 234              $sql_user_array = $q->exec();
 235              $q->clear();
 236              $user_list = db_fetch_assoc($sql_user_array);
 237              $users .= $user_list['contact_first_name'] . ' ' . $user_list['contact_last_name'];
 238          }
 239          $str = '<tr>';
 240          if ($project_id == 0) {
 241              $str .= '<td>' . $Tasks['project_name'] . '</td>';
 242          }
 243          $str .= '<td><a href="?m=tasks&a=view&task_id=' . $Tasks['task_id'] . '">' . $Tasks['task_name'] . '</a></td>';
 244          $str .= '<td>' . nl2br($Tasks['task_description']) . '</td>';
 245          $str .= '<td>' . $users . '</td>';
 246          $str .= '<td align="center">';
 247          ($start_date != ' ') ? $str .= $start_date->format($df) . '</td>' : $str .= ' </td>';
 248          $str .= '<td align="center">';
 249          ($end_date != ' ') ? $str .= $end_date->format($df) . '</td>' : $str .= ' ' . '</td>';
 250          $str .= '<td align="right">' . $Tasks['task_percent_complete'] . '%</td>';
 251          $str .= '</tr>';
 252          echo $str;
 253          if ($project_id == 0) {
 254              $pdfdata[] = array($Tasks['project_name'], $Tasks['task_name'], $Tasks['task_description'], $users, (($start_date != ' ') ? $start_date->format($df) : ' '), (($end_date != ' ') ? $end_date->format($df) : ' '), $Tasks['task_percent_complete'] . '%', );
 255          } else {
 256              $pdfdata[] = array($Tasks['task_name'], $Tasks['task_description'], $users, (($start_date != ' ') ? $start_date->format($df) : ' '), (($end_date != ' ') ? $end_date->format($df) : ' '), $Tasks['task_percent_complete'] . '%', );
 257          }
 258      }
 259      echo '</table>';
 260      if ($log_pdf) {
 261          // make the PDF file

 262          $q = new DBQuery;
 263          $q->addTable('projects');
 264          $q->addQuery('project_name');
 265          $q->addWhere('project_id=' . (int)$project_id);
 266          $pname = $q->loadResult();
 267  
 268          $font_dir = W2P_BASE_DIR . '/lib/ezpdf/fonts';
 269          $temp_dir = W2P_BASE_DIR . '/files/temp';
 270  
 271          require ($AppUI->getLibraryClass('ezpdf/class.ezpdf'));
 272  
 273          $pdf = &new Cezpdf($paper = 'A4', $orientation = 'landscape');
 274          $pdf->ezSetCmMargins(1, 2, 1.5, 1.5);
 275          $pdf->selectFont($font_dir . '/Helvetica.afm');
 276  
 277          $pdf->ezText(w2PgetConfig('company_name'), 12);
 278          // $pdf->ezText( w2PgetConfig( 'company_name' ).' :: '.w2PgetConfig( 'page_title' ), 12 );

 279  
 280          $date = new CDate();
 281          $pdf->ezText("\n" . $date->format($df), 8);
 282  
 283          $pdf->selectFont($font_dir . '/Helvetica-Bold.afm');
 284          $pdf->ezText("\n" . $AppUI->_('Project Task Report'), 12);
 285          if ($project_id != 0) {
 286              $pdf->ezText($pname, 15);
 287          }
 288          if ($log_all) {
 289              $pdf->ezText('All task entries', 9);
 290          } else {
 291              if ($end_date != ' ') {
 292                  $pdf->ezText('Task entries from ' . $start_date->format($df) . ' to ' . $end_date->format($df), 9);
 293              } else {
 294                  $pdf->ezText('Task entries from ' . $start_date->format($df), 9);
 295              }
 296          }
 297          $pdf->ezText("\n");
 298          $pdf->selectFont($font_dir . '/Helvetica.afm');
 299          //$columns = null; This is already defined above... :)

 300          $title = null;
 301          $options = array('showLines' => 2, 'showHeadings' => 1, 'fontSize' => 9, 'rowGap' => 4, 'colGap' => 5, 'xPos' => 50, 'xOrientation' => 'right', 'width' => '750', 'shaded' => 0, 'cols' => array(0 => array('justification' => 'left', 'width' => 100), 1 => array('justification' => 'left', 'width' => 100), 2 => array('justification' => 'left', 'width' => 260), 3 => array('justification' => 'left', 'width' => 80), 4 => array('justification' => 'center', 'width' => 80), 5 => array('justification' => 'center', 'width' => 80), 6 => array('justification' => 'right', 'width' => 60)));
 302  
 303          $pdf->ezTable($pdfdata, $columns, $title, $options);
 304  
 305          if ($fp = fopen($temp_dir . '/temp' . $AppUI->user_id . '.pdf', 'wb')) {
 306              fwrite($fp, $pdf->ezOutput());
 307              fclose($fp);
 308              echo '<a href="' . W2P_BASE_URL . '/files/temp/temp' . $AppUI->user_id . '.pdf" target="pdf">';
 309              echo $AppUI->_('View PDF File');
 310              echo '</a>';
 311          } else {
 312              echo 'Could not open file to save PDF.  ';
 313              if (!is_writable($temp_dir)) {
 314                  'The files/temp directory is not writable.  Check your file system permissions.';
 315              }
 316          }
 317      }
 318      echo '</td>
 319  </tr>
 320  </table>';
 321  }
 322  ?>        


Generated: Thu Jan 8 03:00:03 2009 Cross-referenced by PHPXref 0.7