![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: index_table.php 115 2008-03-21 17:20:33Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/files/index_table.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 /* FILES $Id: index_table.php 115 2008-03-21 17:20:33Z pedroix $ */ 7 // modified later by Pablo Roca (proca) in 18 August 2003 - added page support 8 // Files modules: index page re-usable sub-table 9 global $AppUI, $deny1, $canRead, $canEdit, $canAdmin; 10 global $company_id, $project_id, $task_id; 11 12 global $currentTabId; 13 global $currentTabName; 14 global $tabbed, $m; 15 16 $tab = ((!$company_id && !$project_id && !$task_id) || $m == 'files') ? $currentTabId : 0; 17 $page = w2PgetParam($_GET, 'page', 1); 18 if (!isset($project_id)) { 19 $project_id = w2PgetParam($_REQUEST, 'project_id', 0); 20 } 21 if (!isset($showProject)) { 22 $showProject = true; 23 } 24 $xpg_pagesize = 30; 25 $xpg_min = $xpg_pagesize * ($page - 1); // This is where we start our record set from 26 27 // load the following classes to retrieved denied records 28 include_once $AppUI->getModuleClass('projects'); 29 include_once $AppUI->getModuleClass('tasks'); 30 require_once $AppUI->getSystemClass('query'); 31 require_once $AppUI->getModuleClass('files'); 32 33 $project = new CProject(); 34 $task = new CTask(); 35 36 $df = $AppUI->getPref('SHDATEFORMAT'); 37 $tf = $AppUI->getPref('TIMEFORMAT'); 38 39 $file_types = w2PgetSysVal('FileType'); 40 if (($company_id || $project_id || $task_id) && !($m == 'files')) { 41 $catsql = false; 42 } elseif ($tabbed) { 43 if ($tab <= 0) { 44 $catsql = false; 45 } else { 46 $catsql = 'file_category = ' . --$tab; 47 } 48 } else { 49 if ($tab < 0) { 50 $catsql = false; 51 } else { 52 $catsql = 'file_category = ' . $tab; 53 } 54 } 55 56 // Fetch permissions once for all queries 57 $allowedProjects = $project->getAllowedSQL($AppUI->user_id, 'file_project'); 58 $allowedTasks = $task->getAllowedSQL($AppUI->user_id, 'file_task'); 59 60 // SQL text for count the total recs from the selected option 61 $q = new DBQuery; 62 $q->addQuery('count(file_id)'); 63 $q->addTable('files', 'f'); 64 $q->addJoin('projects', 'p', 'p.project_id = file_project'); 65 $q->addJoin('tasks', 't', 't.task_id = file_task'); 66 $q->leftJoin('project_departments', 'project_departments', 'p.project_id = project_departments.project_id OR project_departments.project_id IS NULL'); 67 $q->leftJoin('departments', 'departments', 'departments.dept_id = project_departments.department_id OR dept_id IS NULL'); 68 if (count($allowedProjects)) { 69 $q->addWhere('( ( ' . implode(' AND ', $allowedProjects) . ') OR file_project = 0 )'); 70 } 71 if (count($allowedTasks)) { 72 $q->addWhere('( ( ' . implode(' AND ', $allowedTasks) . ') OR file_task = 0 )'); 73 } 74 if ($catsql) { 75 $q->addWhere($catsql); 76 } 77 if ($company_id) { 78 $q->addWhere('project_company = ' . (int)$company_id); 79 } 80 if ($project_id) { 81 $q->addWhere('file_project = ' . (int)$project_id); 82 } 83 if ($task_id) { 84 $q->addWhere('file_task = ' . (int)$task_id); 85 } 86 $q->addGroup('file_version_id'); 87 88 // SETUP FOR FILE LIST 89 $q2 = new DBQuery; 90 $q2->addQuery('f.*' . ', max(f.file_id) as latest_id' . ', count(f.file_version) as file_versions, round(max(f.file_version),2) as file_lastversion'); 91 $q2->addQuery('ff.*'); 92 $q2->addTable('files', 'f'); 93 $q2->addJoin('file_folders', 'ff', 'ff.file_folder_id = file_folder'); 94 $q2->addJoin('projects', 'p', 'p.project_id = file_project'); 95 $q2->addJoin('tasks', 't', 't.task_id = file_task'); 96 $q2->leftJoin('project_departments', 'project_departments', 'p.project_id = project_departments.project_id OR project_departments.project_id IS NULL'); 97 $q2->leftJoin('departments', 'departments', 'departments.dept_id = project_departments.department_id OR dept_id IS NULL'); 98 if (count($allowedProjects)) { 99 $q2->addWhere('( ( ' . implode(' AND ', $allowedProjects) . ') OR file_project = 0 )'); 100 } 101 if (count($allowedTasks)) { 102 $q2->addWhere('( ( ' . implode(' AND ', $allowedTasks) . ') OR file_task = 0 )'); 103 } 104 if ($catsql) { 105 $q2->addWhere($catsql); 106 } 107 if ($company_id) { 108 $q2->addWhere('project_company = ' . (int)$company_id); 109 } 110 if ($project_id) { 111 $q2->addWhere('file_project = ' . (int)$project_id); 112 } 113 if ($task_id) { 114 $q2->addWhere('file_task = ' . (int)$task_id); 115 } 116 $q2->setLimit($xpg_pagesize, $xpg_min); 117 // Adding an Order by that is different to a group by can cause 118 // performance issues. It is far better to rearrange the group 119 // by to get the correct ordering. 120 $q2->addGroup('p.project_id'); 121 $q2->addGroup('file_version_id DESC'); 122 123 $q3 = new DBQuery; 124 $q3->addQuery('file_id, file_version, file_version_id, file_project, file_name, file_task, task_name, file_description, file_checkout, file_co_reason, u.user_username as file_owner, file_size, file_category, file_type, file_date, cu.user_username as co_user, project_name, project_color_identifier, project_owner, con.contact_first_name, con.contact_last_name, co.contact_first_name as co_contact_first_name, co.contact_last_name as co_contact_last_name '); 125 $q3->addQuery('ff.*'); 126 $q3->addTable('files'); 127 $q3->addJoin('users', 'u', 'u.user_id = file_owner'); 128 $q3->addJoin('contacts', 'con', 'con.contact_id = u.user_contact'); 129 $q3->addJoin('file_folders', 'ff', 'ff.file_folder_id = file_folder'); 130 $q3->addJoin('projects', 'p', 'p.project_id = file_project'); 131 $q3->addJoin('tasks', 't', 't.task_id = file_task'); 132 $q3->leftJoin('users', 'cu', 'cu.user_id = file_checkout'); 133 $q3->leftJoin('contacts', 'co', 'co.contact_id = cu.user_contact'); 134 $q3->leftJoin('project_departments', 'project_departments', 'p.project_id = project_departments.project_id OR project_departments.project_id IS NULL'); 135 $q3->leftJoin('departments', 'departments', 'departments.dept_id = project_departments.department_id OR dept_id IS NULL'); 136 if (count($allowedProjects)) { 137 $q3->addWhere('( ( ' . implode(' AND ', $allowedProjects) . ') OR file_project = 0 )'); 138 } 139 if (count($allowedTasks)) { 140 $q3->addWhere('( ( ' . implode(' AND ', $allowedTasks) . ') OR file_task = 0 )'); 141 } 142 if ($catsql) { 143 $q3->addWhere($catsql); 144 } 145 if ($company_id) { 146 $q3->addWhere('project_company = ' . (int)$company_id); 147 } 148 if ($project_id) { 149 $q3->addWhere('file_project = ' . (int)$project_id); 150 } 151 if ($task_id) { 152 $q3->addWhere('file_task = ' . (int)$task_id); 153 } 154 155 $files = array(); 156 $file_versions = array(); 157 if ($canRead) { 158 159 $files = $q2->loadList(); 160 $file_versions = $q3->loadHashList('file_id'); 161 } 162 // counts total recs from selection 163 $xpg_totalrecs = count($q->loadList()); 164 165 // How many pages are we dealing with here ?? 166 $xpg_total_pages = ($xpg_totalrecs > $xpg_pagesize) ? ceil($xpg_totalrecs / $xpg_pagesize) : 1; 167 168 shownavbar($xpg_totalrecs, $xpg_pagesize, $xpg_total_pages, $page); 169 170 ?> 171 <script type="text/JavaScript"> 172 function expand(id){ 173 var element = document.getElementById(id); 174 element.style.display = (element.style.display == '' || element.style.display == 'none') ? 'block' : 'none'; 175 } 176 </script> 177 178 <table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl"> 179 <tr> 180 <th nowrap="nowrap"><?php echo $AppUI->_('File Name'); ?></th> 181 <th nowrap="nowrap"><?php echo $AppUI->_('Description'); ?></th> 182 <th nowrap="nowrap"><?php echo $AppUI->_('Versions'); ?></th> 183 <th nowrap="nowrap"><?php echo $AppUI->_('Category'); ?></th> 184 <th nowrap="nowrap"><?php echo $AppUI->_('Folder'); ?></th> 185 <th nowrap="nowrap"><?php echo $AppUI->_('Task Name'); ?></th> 186 <th nowrap="nowrap"><?php echo $AppUI->_('Owner'); ?></th> 187 <th nowrap="nowrap"><?php echo $AppUI->_('Size'); ?></th> 188 <th nowrap="nowrap"><?php echo $AppUI->_('Type'); ?></a></th> 189 <th nowrap="nowrap"><?php echo $AppUI->_('Date'); ?></th> 190 <th nowrap="nowrap"><?php echo $AppUI->_('Checkout Reason') ?></th> 191 <th nowrap="nowrap"><?php echo $AppUI->_('co') ?></th> 192 <th nowrap="nowrap"> </th> 193 </tr> 194 <?php 195 $fp = -1; 196 $file_date = new CDate(); 197 198 $id = 0; 199 foreach ($files as $file_row) { 200 $latest_file = $file_versions[$file_row['latest_id']]; 201 $file_date = new CDate($latest_file['file_date']); 202 203 if ($fp != $latest_file['file_project']) { 204 if (!$latest_file['file_project']) { 205 $latest_file['project_name'] = $AppUI->_('Not associated to projects'); 206 $latest_file['project_color_identifier'] = 'f4efe3'; 207 } 208 if ($showProject) { 209 $style = 'background-color:#' . $latest_file[project_color_identifier] . ';color:' . bestColor($latest_file['project_color_identifier']); 210 $s = '<tr>'; 211 $s .= '<td colspan="20" style="border: outset 2px #eeeeee;' . $style . '">'; 212 $s .= '<a href="?m=projects&a=view&project_id=' . $latest_file['file_project'] . '">'; 213 $s .= '<span style="' . $style . '">' . $latest_file['project_name'] . '</span></a>'; 214 $s .= '</td></tr>'; 215 echo $s; 216 } 217 } 218 $fp = $latest_file['file_project']; 219 ?> 220 <tr> 221 <td nowrap="8%"> 222 <?php 223 $fnamelen = 32; 224 $filename = $latest_file['file_name']; 225 if (strlen($latest_file['file_name']) > $fnamelen + 9) { 226 $ext = substr($filename, strrpos($filename, '.') + 1); 227 $filename = substr($filename, 0, $fnamelen); 228 $filename .= '[...].' . $ext; 229 } 230 $file_icon = getIcon($file_row['file_type']); 231 echo '<a href="./fileviewer.php?file_id=' . $latest_file['file_id'] . '" title="' . $latest_file['file_description'] . '"><img border="0" width="16" heigth="16" src="' . w2PfindImage($file_icon, 'files') . '" /> ' . $filename . '</a>'; 232 // {$latest_file['file_name']} 233 234 ?> 235 </td> 236 <td width="20%"><?php echo $latest_file['file_description']; ?></td> 237 <td width="5%" nowrap="nowrap" align="right"> 238 <?php 239 $hidden_table = ''; 240 echo $file_row['file_lastversion']; 241 if ($file_row['file_versions'] > 1) { 242 echo ' <a href="javascript: void(0);" onclick="expand(\'versions_' . $latest_file['file_id'] . '\'); ">(' . $file_row['file_versions'] . ')</a>'; 243 $hidden_table = '<tr><td colspan="20"> 244 <table style="display: none" id="versions_' . $latest_file['file_id'] . '" width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl"> 245 <tr> 246 <th nowrap="nowrap">' . $AppUI->_('File Name') . '</th> 247 <th nowrap="nowrap">' . $AppUI->_('Description') . '</th> 248 <th nowrap="nowrap">' . $AppUI->_('Versions') . '</th> 249 <th nowrap="nowrap">' . $AppUI->_('Category') . '</th> 250 <th nowrap="nowrap">' . $AppUI->_('Folder') . '</th> 251 <th nowrap="nowrap">' . $AppUI->_('Task Name') . '</th> 252 <th nowrap="nowrap">' . $AppUI->_('Owner') . '</th> 253 <th nowrap="nowrap">' . $AppUI->_('Size') . '</th> 254 <th nowrap="nowrap">' . $AppUI->_('Type') . '</a></th> 255 <th nowrap="nowrap">' . $AppUI->_('Date') . '</th> 256 <th nowrap="nowrap"> </th> 257 </tr> 258 '; 259 foreach ($file_versions as $file) { 260 if ($file['file_version_id'] == $latest_file['file_version_id']) { 261 $file_icon = getIcon($file['file_type']); 262 $hdate = new Date($file['file_date']); 263 $hidden_table .= '<tr><td nowrap="8%"><a href="./fileviewer.php?file_id=' . $file['file_id'] . '" title="' . $file['file_description'] . '">' . '<img border="0" width="16" heigth="16" src="' . w2PfindImage($file_icon, 'files') . '" /> ' . $file['file_name'] . ' 264 </a></td> 265 <td width="20%">' . $file['file_description'] . '</td> 266 <td width="5%" nowrap="nowrap" align="right">' . $file['file_version'] . '</td> 267 <td width="10%" nowrap="nowrap" align="left">' . $file_types[$file['file_category']] . '</td> 268 <td width="10%" nowrap="nowrap" align="left">' . (($file['file_folder_name'] != '') ? '<a href="' . W2P_BASE_URL . '/index.php?m=files&tab=' . (count($file_types) + 1) . '&folder=' . $file['file_folder_id'] . '">' . w2PshowImage('folder5_small.png', '16', '16', 'folder icon', 'show only this folder', 'files') . $file['file_folder_name'] . '</a>' : 'Root') . '</td> 269 <td width="5%" align="center"><a href="./index.php?m=tasks&a=view&task_id=' . $file['file_task'] . '">' . $file['task_name'] . '</a></td> 270 <td width="15%" nowrap="nowrap">' . $file['contact_first_name'] . ' ' . $file['contact_last_name'] . '</td> 271 <td width="5%" nowrap="nowrap" align="right">' . file_size(intval($file['file_size'])) . '</td> 272 <td nowrap="nowrap">' . substr($file['file_type'], strpos($file['file_type'], '/') + 1) . '</td> 273 <td width="15%" nowrap="nowrap" align="center">' . $hdate->format($df . ' ' . $tf) . '</td> 274 <td nowrap="nowrap" width="20">'; 275 if ($canEdit && $w2Pconfig['files_show_versions_edit']) { 276 $hidden_table .= '<a href="./index.php?m=files&a=addedit&file_id=' . $file['file_id'] . '">' . w2PshowImage('kedit.png', '16', '16', 'edit file', 'edit file', 'files') . "</a>"; 277 } 278 $hidden_table .= '</td><tr>'; 279 } 280 } 281 $hidden_table .= '</table>'; 282 } 283 ?> 284 </td> 285 <td width="10%" nowrap="nowrap" align="left"><?php echo $file_types[$latest_file['file_category']]; ?></td> 286 <td width="10%" nowrap="nowrap" align="left"><?php 287 echo ($latest_file['file_folder_name'] != '') ? '<a href="' . W2P_BASE_URL . '/index.php?m=files&tab=' . (count($file_types) + 1) . '&folder=' . $latest_file['file_folder_id'] . '">' . w2PshowImage('folder5_small.png', '16', '16', 'folder icon', 'show only this folder', 'files') . $latest_file['file_folder_name'] . '</a>' : 'Root';?> 288 </td> 289 <td width="5%" align="left"><a href="./index.php?m=tasks&a=view&task_id=<?php echo $latest_file['file_task']; ?>"><?php echo $latest_file["task_name"]; ?></a></td> 290 <td width="15%" nowrap="nowrap"><?php echo $latest_file['contact_first_name'] . ' ' . $latest_file['contact_last_name']; ?></td> 291 <td width="5%" nowrap="nowrap" align="right"><?php echo file_size(intval($latest_file["file_size"])); ?></td> 292 <td nowrap="nowrap"><?php echo $AppUI->_(substr($latest_file['file_type'], strpos($latest_file['file_type'], '/') + 1)); ?></td> 293 <td width="15%" nowrap="nowrap" align="center"><?php echo $file_date->format($df . ' ' . $tf); ?></td> 294 <td width="10%"><?php echo $latest_file['file_co_reason']; ?></td> 295 <td nowrap="nowrap"> 296 <?php if ($canEdit && empty($latest_file['file_checkout'])) { 297 ?> 298 <a href="?m=files&a=co&file_id=<?php echo $latest_file['file_id']; ?>"><?php echo w2PshowImage('up.png', '16', '16', 'checkout', 'checkout file', 'files'); ?></a> 299 <?php } else 300 if ($latest_file['file_checkout'] == $AppUI->user_id) { ?> 301 <a href="?m=files&a=addedit&ci=1&file_id=<?php echo $latest_file['file_id']; ?>"><?php echo w2PshowImage('down.png', '16', '16', 'checkin', 'checkin file', 'files'); ?></a> 302 <?php } else { 303 if ($latest_file['file_checkout'] == 'final') { 304 echo 'final'; 305 } else { 306 echo $latest_file['co_contact_first_name'] . ' ' . $latest_file['co_contact_last_name'] . '<br>(' . $latest_file['co_user'] . ')'; 307 } 308 } 309 ?> 310 311 </td> 312 <td nowrap="nowrap" width="20"> 313 <?php if ($canEdit && (empty($latest_file['file_checkout']) || ($latest_file['file_checkout'] == 'final' && ($canEdit || $latest_file['project_owner'] == $AppUI->user_id)))) { 314 echo '<a href="./index.php?m=files&a=addedit&file_id=' . $latest_file['file_id'] . '">' . w2PshowImage('kedit.png', '16', '16', 'edit file', 'edit file', 'files') . '</a>'; 315 } 316 ?> 317 </td> 318 </tr> 319 <?php 320 echo $hidden_table; 321 $hidden_table = ''; 322 } ?> 323 </table> 324 <?php 325 shownavbar($xpg_totalrecs, $xpg_pagesize, $xpg_total_pages, $page); 326 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Jan 9 03:00:02 2009 | Cross-referenced by PHPXref 0.7 |