[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/modules/history/ -> index.php (source)

   1  <?php /* $Id: index.php 194 2008-07-28 18:34:25Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/history/index.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  
   6  ##
   7  ## History module
   8  ## (c) Copyright
   9  ## J. Christopher Pereira (kripper@imatronix.cl)
  10  ## IMATRONIX
  11  ##
  12  
  13  $AppUI->savePlace();
  14  $titleBlock = new CTitleBlock('History', 'stock_book_blue_48.png', 'history', 'history.' . $a);
  15  $titleBlock->show();
  16  
  17  function show_history($history) {
  18      //        return $history;
  19      global $AppUI;
  20      $id = $history['history_item'];
  21      $module = $history['history_table'];
  22      if ($module == 'companies') {
  23          $table_id = 'company_id';
  24      } elseif ($module == 'modules') {
  25          $table_id = 'mod_id';
  26      } else {
  27          $table_id = (substr($module, -1) == 's' ? substr($module, 0, -1) : $module) . '_id';
  28      }
  29  
  30      if ($module == 'login') {
  31          return $AppUI->_('User') . ' "' . $history['history_description'] . '" ' . $AppUI->_($history['history_action']);
  32      }
  33  
  34      if ($history['history_action'] == 'add') {
  35          $msg = $AppUI->_('Added new') . ' ';
  36      } elseif ($history['history_action'] == 'update') {
  37          $msg = $AppUI->_('Modified') . ' ';
  38      } elseif ($history['history_action'] == 'delete') {
  39          return $AppUI->_('Deleted') . ' "' . $history['history_description'] . '" ' . $AppUI->_('from') . ' ' . $AppUI->_($module) . ' ' . $AppUI->_('module');
  40      }
  41  
  42      $q = new DBQuery;
  43      $q->addTable($module);
  44      $q->addQuery($table_id);
  45      $q->addWhere($table_id . ' =' . $id);
  46      if ($q->loadResult()) {
  47          switch ($module) {
  48              case 'history':
  49                  $link = '&a=addedit&history_id=';
  50                  break;
  51              case 'files':
  52                  $link = '&a=addedit&file_id=';
  53                  break;
  54              case 'tasks':
  55                  $link = '&a=view&task_id=';
  56                  break;
  57              case 'forums':
  58                  $link = '&a=viewer&forum_id=';
  59                  break;
  60              case 'projects':
  61                  $link = '&a=view&project_id=';
  62                  break;
  63              case 'companies':
  64                  $link = '&a=view&company_id=';
  65                  break;
  66              case 'contacts':
  67                  $link = '&a=view&contact_id=';
  68                  break;
  69              case 'task_log':
  70                  $module = 'Tasks';
  71                  $link = '&a=view&task_id=170&tab=1&task_log_id=';
  72                  break;
  73          }
  74      }
  75      $q->clear();
  76  
  77      if (!empty($link)) {
  78          $link = '<a href="?m=' . $module . $link . $id . '">' . $history['history_description'] . '</a>';
  79      } else {
  80          $link = $history['history_description'];
  81      }
  82      $msg .= $AppUI->_('item') . " '$link' " . $AppUI->_('in') . ' ' . $AppUI->_(ucfirst($module)) . ' ' . $AppUI->_('module'); // . $history;
  83  
  84      return $msg;
  85  }
  86  
  87  $filter_param = w2PgetParam($_REQUEST, 'filter', ''); 
  88  $filter = array();
  89  if ($filter_param) {
  90      $in_filter = $_REQUEST['filter'];
  91      $filter[] = 'history_table = \'' . $_REQUEST['filter'] . '\' ';
  92  } else {
  93      $in_filter = '';
  94  }
  95  
  96  if (!empty($_REQUEST['project_id'])) {
  97      $project_id = w2PgetParam($_REQUEST, 'project_id', 0);
  98  
  99      $q = new DBQuery;
 100      $q->addTable('tasks');
 101      $q->addQuery('task_id');
 102      $q->addWhere('task_project = ' . (int)$project_id);
 103      $project_tasks = implode(',', $q->loadColumn());
 104      if (!empty($project_tasks)) {
 105          $project_tasks = 'OR (history_table = \'tasks\' AND history_item IN (' . $project_tasks . '))';
 106      }
 107  
 108      $q->addTable('files');
 109      $q->addQuery('file_id');
 110      $q->addWhere('file_project = ' . (int)$project_id);
 111      $project_files = implode(',', $q->loadColumn());
 112      if (!empty($project_files)) {
 113          $project_files = 'OR (history_table = \'files\' AND history_item IN (' . $project_files . '))';
 114      }
 115  
 116      $filter[] = '((history_table = \'projects\' AND history_item = \'' . (int)$project_id .'\') ' . $project_tasks . ' ' . $project_files . ')';
 117  }
 118  
 119  $page = isset($_REQUEST['pg']) ? (int)$_REQUEST['pg'] : 1;
 120  $limit = isset($_REQUEST['limit']) ? (int)$_REQUEST['limit'] : 100;
 121  $offset = ($page - 1) * $limit;
 122  if ($filter_param != '' || $page) {
 123      $q = new DBQuery;
 124      $q->addQuery('COUNT(history_id) AS hits');
 125      $q->addTable('history', 'h');
 126      $q->addTable('users');
 127      $q->addWhere('history_user = user_id');
 128      $q->addTable('contacts');
 129      $q->addWhere('contact_id = user_contact');
 130      $q->addWhere($filter);
 131      $count = intval($q->loadResult());
 132  
 133      $q = new DBQuery;
 134      $q->addQuery('history_date, history_id, history_item, history_table, history_description, history_action');
 135      $q->addQuery('CONCAT(contact_first_name, \' \', contact_last_name) AS history_user_name');
 136      $q->addTable('history', 'h');
 137      $q->addTable('users');
 138      $q->addWhere('history_user = user_id');
 139      $q->addTable('contacts');
 140      $q->addWhere('contact_id = user_contact');
 141      $q->addWhere($filter);
 142      $q->addOrder('history_date DESC');
 143      $q->setLimit($limit, $offset);
 144      $history = $q->loadList();
 145  } else {
 146      $history = array();
 147  }
 148  
 149  $pages = (int)($count / $limit) + 1;
 150  $max_pages = 20;
 151  if ($pages > $max_pages) {
 152      $first_page = max($page - (int)($max_pages / 2), 1);
 153      $last_page = min($first_page + $max_pages - 1, $pages);
 154  } else {
 155      $first_page = 1;
 156      $last_page = $pages;
 157  }
 158  ?>
 159  
 160  <table width="100%" cellspacing="1" cellpadding="0" border="0">
 161  <tr>
 162      <td nowrap="nowrap" align="right">
 163  <form name="filter" action="?m=history" method="post" >
 164  <?php echo $AppUI->_('Changes to'); ?>:
 165          <select name="filter" class="text" onchange="document.filter.submit()">
 166                  <option value="">(<?php echo $AppUI->_('Select Filter'); ?>)</option>
 167                  <option value="0" <?php if ($in_filter == '0') echo 'selected="selected"'; ?>><?php echo $AppUI->_('Show all'); ?></option>
 168                  <option value="companies" <?php if ($in_filter == 'companies') echo 'selected="selected"'; ?>><?php echo $AppUI->_('Companies'); ?></option>
 169                  <option value="projects" <?php if ($in_filter == 'projects') echo 'selected="selected"'; ?>><?php echo $AppUI->_('Projects'); ?></option>
 170                  <option value="tasks" <?php if ($in_filter == 'tasks') echo 'selected="selected"'; ?>><?php echo $AppUI->_('Tasks'); ?></option>
 171                  <option value="files" <?php if ($in_filter == 'files') echo 'selected="selected"'; ?>><?php echo $AppUI->_('Files'); ?></option>
 172                  <option value="forums" <?php if ($in_filter == 'forums') echo 'selected="selected"'; ?>><?php echo $AppUI->_('Forums'); ?></option>
 173                  <option value="login" <?php if ($in_filter == 'login') echo 'selected="selected"'; ?>><?php echo $AppUI->_('Login/Logouts'); ?></option>
 174          </select>
 175      <?php
 176  if ($pages > 1) {
 177      for ($i = $first_page; $i <= $last_page; $i++) {
 178          echo '&nbsp;';
 179          if ($i == $page) {
 180              echo '<b>' . $i . '</b>';
 181          } else {
 182              echo '<a href="?m=history&filter=' . $in_filter . '&pg=' . $i . '">' . $i . '</a>';
 183          }
 184      }
 185  }
 186  ?>
 187  </form>
 188          </td>
 189      <td align="right"><input class="button" type="button" value="<?php echo $AppUI->_('Add history'); ?>" onclick="window.location='?m=history&a=addedit'"></td>
 190  </table>
 191  
 192  <table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
 193  <tr>
 194      <th width="10">&nbsp;</th>
 195      <th width="200"><?php echo $AppUI->_('Date'); ?></th>
 196      <th nowrap="nowrap"><?php echo $AppUI->_('Description'); ?></th>
 197      <th nowrap="nowrap"><?php echo $AppUI->_('User'); ?>&nbsp;&nbsp;</th>
 198  </tr>
 199  <?php
 200  foreach ($history as $row) {
 201      $module = $row['history_table'] == 'task_log' ? 'tasks' : $row['history_table'];
 202      // Checking permissions.
 203      // TODO: Enable the lines below to activate new permissions.
 204      $perms = &$AppUI->acl();
 205      //The next line makes no sense and takes loads of time
 206      //if ($module == 'login' || $perms->checkModuleItem($module, "access", $row['history_item']))  {
 207      $df = $AppUI->getPref('SHDATEFORMAT');
 208      $tf = $AppUI->getPref('TIMEFORMAT');
 209  
 210      $hd = new Date($row['history_date']);
 211  
 212  ?>
 213  <tr>    
 214      <td align="center"><a href='<?php echo '?m=history&a=addedit&history_id=' . $row['history_id'] ?>'><img src="<?php echo w2PfindImage('icons/pencil.gif'); ?>" alt="<?php echo $AppUI->_('Edit History') ?>" border="0" width="12" height="12" /></a></td>
 215      <td align="center"><?php echo $hd->format($df) . ' ' . $hd->format($tf); ?></td>
 216      <td><?php echo show_history($row) ?></td>    
 217      <td align="left"><?php echo $row['history_user_name'] ?></td>
 218  </tr>    
 219  <?php
 220  }
 221  ?>
 222  </table>


Generated: Fri Jan 9 03:00:02 2009 Cross-referenced by PHPXref 0.7