[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/modules/notebook/ -> index_table.php (source)

   1  <?php /* $Id: index_table.php 156 2008-04-11 15:47:40Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/links/index_table.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  global $AppUI, $deny1, $canRead, $canEdit;
   6  
   7  // modified later by Pablo Roca (proca) in 18 August 2003 - added page support
   8  // Files modules: index page re-usable sub-table
   9  $m = 'notebook';
  10  
  11  // ****************************************************************************
  12  // Page numbering variables
  13  // Pablo Roca (pabloroca@Xmvps.org) (Remove the X)
  14  // 19 August 2003
  15  //
  16  // $tab             - file category
  17  // $page            - actual page to show
  18  // $xpg_pagesize    - max rows per page
  19  // $xpg_min         - initial record in the SELECT LIMIT
  20  // $xpg_totalrecs   - total rows selected
  21  // $xpg_sqlrecs     - total rows from SELECT LIMIT
  22  // $xpg_total_pages - total pages
  23  // $xpg_next_page   - next pagenumber
  24  // $xpg_prev_page   - previous pagenumber
  25  // $xpg_break       - stop showing page numbered list?
  26  // $xpg_sqlcount    - SELECT for the COUNT total
  27  // $xpg_sqlquery    - SELECT for the SELECT LIMIT
  28  // $xpg_result      - pointer to results from SELECT LIMIT
  29  function shownavbar_notes($xpg_totalrecs, $xpg_pagesize, $xpg_total_pages, $page) {
  30  
  31      global $AppUI, $m;
  32      $xpg_break = false;
  33      $xpg_prev_page = $xpg_next_page = 0;
  34  
  35      $s = '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr>';
  36  
  37      if ($xpg_totalrecs > $xpg_pagesize) {
  38          $xpg_prev_page = $page - 1;
  39          $xpg_next_page = $page + 1;
  40          // left buttoms
  41          if ($xpg_prev_page > 0) {
  42              $s .= '<td align="left" width="15%"><a href="./index.php?m=' . $m . 'notebook&amp;page=1"><img src="' . w2PfindImage('navfirst.gif') . '" border="0" Alt="First Page"></a>&nbsp;&nbsp;';
  43              $s .= '<a href="./index.php?m=' . $m . '&amp;page=' . $xpg_prev_page . '"><img src="' . w2PfindImage('navleft.gif') . '" border="0" Alt="Previous page (' . $xpg_prev_page . ')"></a></td>';
  44          } else {
  45              $s .= '<td width="15%">&nbsp;</td>';
  46          }
  47  
  48          // central text (files, total pages, ...)
  49          $s .= '<td align="center" width="70%">' . $xpg_totalrecs . ' ' . $AppUI->_('Note(s)') . ' (' . $xpg_total_pages . ' ' . $AppUI->_('Page(s)') . ')</td>';
  50  
  51          // right buttoms
  52          if ($xpg_next_page <= $xpg_total_pages) {
  53              $s .= '<td align="right" width="15%"><a href="./index.php?m=' . $m . '&amp;page=' . $xpg_next_page . '"><img src="' . w2PfindImage('navright.gif') . '" border="0" Alt="Next Page (' . $xpg_next_page . ')"></a>&nbsp;&nbsp;';
  54              $s .= '<a href="./index.php?m=' . $m . '&amp;page=' . $xpg_total_pages . '"><img src="' . w2PfindImage('navlast.gif') . '" border="0" Alt="Last Page"></a></td>';
  55          } else {
  56              $s .= '<td width="15%">&nbsp;</td></tr>';
  57          }
  58          // Page numbered list, up to 30 pages
  59          $s .= '<tr><td colspan="3" align="center"> [ ';
  60  
  61          for ($n = $page > 16 ? $page - 16 : 1; $n <= $xpg_total_pages; $n++) {
  62              if ($n == $page) {
  63                  $s .= '<b>' . $n . '</b></a>';
  64              } else {
  65                  $s .= '<a href="./index.php?m=' . $m . '&amp;page=' . $n . '">' . $n . '</a>';
  66              }
  67              if ($n >= 30 + $page - 15) {
  68                  $xpg_break = true;
  69                  break;
  70              } elseif ($n < $xpg_total_pages) {
  71                  $s .= ' | ';
  72              }
  73          }
  74  
  75          if (!isset($xpg_break)) { // are we supposed to break ?
  76              if ($n == $page) {
  77                  $s .= '<' . $n . '</a>';
  78              } else {
  79                  $s .= '<a href="./index.php?m=' . $m . '&amp;page=' . $xpg_total_pages . '">';
  80                  $s .= $n . '</a>';
  81              }
  82          }
  83          $s .= ' ] </td></tr>';
  84      } else { // or we dont have any files..
  85          $s .= '<td align="center">';
  86          if ($xpg_next_page > $xpg_total_pages) {
  87              $s .= $xpg_sqlrecs . ' ' . $m . ' ';
  88          }
  89          $s .= '</td></tr>';
  90      }
  91      $s .= '</table>';
  92      echo $s;
  93  }
  94  
  95  $tab = $AppUI->getState('NoteIdxTab') !== null ? $AppUI->getState('NoteIdxTab') : 0;
  96  $page = w2PgetParam($_GET, 'page', 1);
  97  $search = w2PgetParam($_REQUEST, 'search', '');
  98  
  99  global $company_id, $project_id, $task_id, $user_id, $note_status, $showCompany;
 100  if (!isset($project_id)) {
 101      $project_id = w2PgetParam($_REQUEST, 'project_id', 0);
 102  }
 103  if (!isset($showCompany)) {
 104      $showCompany = true;
 105  }
 106  
 107  $xpg_pagesize = 30;
 108  $xpg_min = $xpg_pagesize * ($page - 1); // This is where we start our record set from
 109  
 110  // load the following classes to retrieved denied records
 111  include_once ($AppUI->getModuleClass('companies'));
 112  include_once ($AppUI->getModuleClass('projects'));
 113  include_once ($AppUI->getModuleClass('tasks'));
 114  
 115  $project = new CProject();
 116  $task = new CTask();
 117  
 118  $df = $AppUI->getPref('SHDATEFORMAT');
 119  $tf = $AppUI->getPref('TIMEFORMAT');
 120  
 121  $note_types = w2PgetSysVal('NoteCategory');
 122  $note_statuses = w2PgetSysVal('NoteStatus');
 123  if ($tab <= 0) {
 124      $catsql = '';
 125  } else {
 126      $catsql = 'note_category = ' . --$tab;
 127  }
 128  
 129  // SETUP FOR NOTE LIST
 130  $q = new DBQuery();
 131  $q->addQuery('notes.*');
 132  $q->addQuery('contact_first_name, contact_last_name');
 133  $q->addQuery('project_name, pr.project_id, project_color_identifier, project_status');
 134  $q->addQuery('task_name, task_id');
 135  $q->addQuery('con.company_name, con.company_id');
 136  
 137  $q->addTable('notes');
 138  
 139  $q->leftJoin('companies', 'con', 'con.company_id = note_company');
 140  
 141  $q->leftJoin('users', 'u', 'user_id = note_creator');
 142  $q->leftJoin('contacts', 'c', 'user_contact = contact_id');
 143  
 144  if (!empty($search)) {
 145      $q->addWhere('(note_title LIKE \'%' . $search . '%\' OR note_body LIKE \'%' . $search . '%\')');
 146  }
 147  if ($company_id) { // Company
 148      $q->addWhere('note_company = ' . (int)$company_id . ' OR note_company = 0');
 149  }
 150  if ($project_id) { // Project
 151      $q->addWhere('note_project = ' . (int)$project_id . ' OR note_project = 0');
 152  }
 153  if ($task_id) { // Task
 154      $q->addWhere('note_task = ' . (int)$task_id);
 155  }
 156  if ($user_id) { // User
 157      $q->addWhere('note_creator = ' . (int)$user_id);
 158  }
 159  if (isset($note_status) && $note_status >= 0) { // Task
 160      $q->addWhere('note_status = ' . (int)$note_status);
 161  }
 162  
 163  $q->addWhere('(note_private = 0 OR note_creator = ' . (int)$AppUI->user_id . ')');
 164  
 165  if ($catsql) { // Category
 166      $q->addWhere($catsql);
 167  }
 168  // Permissions
 169  $project->setAllowedSQL($AppUI->user_id, $q, 'note_project');
 170  $task->setAllowedSQL($AppUI->user_id, $q, 'note_task and task_project = note_project');
 171  $q->addOrder('company_name, note_title');
 172  
 173  //LIMIT ' . $xpg_min . ', ' . $xpg_pagesize ;
 174  if ($canRead) {
 175      $notes = $q->loadList();
 176  } else {
 177      $AppUI->redirect('m=public&a=access_denied');
 178  }
 179  // counts total recs from selection
 180  $xpg_totalrecs = count($notes);
 181  
 182  // How many pages are we dealing with here ??
 183  $xpg_total_pages = ($xpg_totalrecs > $xpg_pagesize) ? ceil($xpg_totalrecs / $xpg_pagesize) : 0;
 184  
 185  shownavbar_notes($xpg_totalrecs, $xpg_pagesize, $xpg_total_pages, $page);
 186  
 187  ?>
 188  <table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
 189  <tr>
 190      <th nowrap="nowrap">&nbsp;</th>
 191      <th nowrap="nowrap"><?php echo $AppUI->_('Note Title'); ?></th>
 192      <th nowrap="nowrap"><?php echo $AppUI->_('Category'); ?></th>
 193      <th nowrap="nowrap"><?php echo $AppUI->_('Status'); ?></th>
 194      <th nowrap="nowrap"><?php echo $AppUI->_('Project'); ?></th>
 195      <th nowrap="nowrap"><?php echo $AppUI->_('Task'); ?></th>
 196      <th nowrap="nowrap"><?php echo $AppUI->_('Creator'); ?></th>
 197      <th nowrap="nowrap"><?php echo $AppUI->_('Date'); ?></th>
 198  </tr>
 199  <?php
 200  $fp = -1;
 201  
 202  $id = 0;
 203  for ($i = ($page - 1) * $xpg_pagesize; $i < $page * $xpg_pagesize && $i < $xpg_totalrecs; $i++) {
 204      $row = $notes[$i];
 205      $note_created = new CDate($row['note_created']);
 206  
 207      if ($fp != $row['note_company']) {
 208          if (!$row['company_name']) {
 209              $row['company_name'] = $AppUI->_('All Companies');
 210          }
 211          if ($showCompany) {
 212              $s = '<tr>';
 213              $s .= '<td colspan="10" style="border: outset 2px #eeeeee">';
 214              if ($row['company_id'] > 0) {
 215                  $s .= '<a href="?m=companies&a=view&company_id=' . $row['company_id'] . '">' . $row['company_name'] . '</a>';
 216              } else {
 217                  $s .= $row['company_name'];
 218              }
 219              $s .= '</td></tr>';
 220              echo $s;
 221          }
 222      }
 223      $fp = $row['note_company'];
 224  ?>
 225  <tr>
 226      <td nowrap="nowrap" align="center" width="20">
 227      <?php if ($canEdit) {
 228          echo '<a href="./index.php?m=' . $m . '&a=addedit&note_id=' . $row['note_id'] . '">' . w2PshowImage('icons/stock_edit-16.png', '16', '16') . '</a>';
 229      }
 230  ?>
 231      </td>
 232      <td nowrap="8%">
 233          <?php 
 234              echo '<a href="./index.php?m=' . $m . '&a=view&note_id=' . $row['note_id'] . '">' . $row['note_title'] . '</a>';
 235              if (trim($row['note_doc_url'])) {
 236                  echo '<a href="' . $row['note_doc_url'] . '" target="_blank">' . w2PshowImage('clip.png', '16', '16') . '</a>';
 237              } 
 238          ?>
 239      </td>
 240      <td width="10%" nowrap="nowrap"><?php echo $note_types[$row['note_category']]; ?></td> 
 241      <td width="10%" nowrap="nowrap"><?php echo $note_statuses[$row['note_status']]; ?></td> 
 242      <td width="10%" align="left"><a href="./index.php?m=projects&a=view&project_id=<?php echo $row['project_id']; ?>"><?php echo $row['project_name']; ?></a></td>
 243      <td width="10%" align="left"><a href="./index.php?m=tasks&a=view&task_id=<?php echo $row['task_id']; ?>"><?php echo $row['task_name']; ?></a></td>
 244      <td width="15%" nowrap="nowrap"><?php echo $row['contact_first_name'] . ' ' . $row['contact_last_name']; ?></td>
 245      <td width="15%" nowrap="nowrap" align="center"><?php echo $note_created->format($df . ' ' . $tf); ?></td>
 246  </tr>
 247  <?php } ?>
 248  </table>
 249  <?php
 250  shownavbar_notes($xpg_totalrecs, $xpg_pagesize, $xpg_total_pages, $page);
 251  ?>


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