XoopsModules25x /
xhelp
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | //$Id: file.php,v 1.10 2005/11/29 17:48:12 ackbarr Exp $ |
||
| 3 | include('../../../include/cp_header.php'); |
||
| 4 | include_once('admin_header.php'); |
||
| 5 | include_once(XOOPS_ROOT_PATH . '/class/pagenav.php'); |
||
| 6 | |||
| 7 | global $xoopsModule; |
||
| 8 | $module_id = $xoopsModule->getVar('mid'); |
||
| 9 | |||
| 10 | $start = $limit = 0; |
||
| 11 | if (isset($_REQUEST['limit'])) { |
||
| 12 | $limit = intval($_REQUEST['limit']); |
||
| 13 | } |
||
| 14 | if (isset($_REQUEST['start'])) { |
||
| 15 | $start = intval($_REQUEST['start']); |
||
| 16 | } |
||
| 17 | if (!$limit) { |
||
| 18 | $limit = 15; |
||
| 19 | } |
||
| 20 | if(isset($_REQUEST['order'])){ |
||
| 21 | $order = $_REQUEST['order']; |
||
| 22 | } else { |
||
| 23 | $order = "ASC"; |
||
| 24 | } |
||
| 25 | if(isset($_REQUEST['sort'])) { |
||
| 26 | $sort = $_REQUEST['sort']; |
||
| 27 | } else { |
||
| 28 | $sort = "id"; |
||
| 29 | } |
||
| 30 | |||
| 31 | $aSortBy = array('id' => _AM_XHELP_TEXT_ID, 'ticketid' => _AM_XHELP_TEXT_TICKETID, 'filename' => _AM_XHELP_TEXT_FILENAME, |
||
| 32 | 'mimetype' => _AM_XHELP_TEXT_MIMETYPE); |
||
| 33 | $aOrderBy = array('ASC' => _AM_XHELP_TEXT_ASCENDING, 'DESC' => _AM_XHELP_TEXT_DESCENDING); |
||
| 34 | $aLimitBy = array('10' => 10, '15' => 15, '20' => 20, '25' => 25, '50' => 50, '100' => 100); |
||
| 35 | |||
| 36 | $op = 'default'; |
||
| 37 | |||
| 38 | if ( isset( $_REQUEST['op'] ) ) |
||
| 39 | { |
||
| 40 | $op = $_REQUEST['op']; |
||
| 41 | } |
||
| 42 | |||
| 43 | switch ( $op ) |
||
| 44 | { |
||
| 45 | case "deleteFile": |
||
| 46 | deleteFile(); |
||
| 47 | break; |
||
| 48 | |||
| 49 | case "deleteResolved": |
||
| 50 | deleteResolved(); |
||
| 51 | break; |
||
| 52 | |||
| 53 | case "manageFiles": |
||
| 54 | manageFiles(); |
||
| 55 | break; |
||
| 56 | |||
| 57 | default: |
||
| 58 | header("Location: ".XHELP_ADMIN_URL."/index.php"); |
||
| 59 | break; |
||
| 60 | } |
||
| 61 | |||
| 62 | function deleteFile() |
||
| 63 | { |
||
| 64 | $hFile =& xhelpGetHandler('file'); |
||
| 65 | |||
| 66 | if(!isset($_GET['fileid'])){ |
||
| 67 | redirect_header(XHELP_ADMIN_URL."/file.php?op=manageFiles", 3, _XHELP_MESSAGE_DELETE_FILE_ERR); |
||
| 68 | } |
||
| 69 | $fileid = intval($_GET['fileid']); |
||
| 70 | if(!isset($_POST['ok'])){ |
||
| 71 | xoops_cp_header(); |
||
| 72 | xoops_confirm(array('op' => 'deleteFile', 'ok' => 1), XHELP_ADMIN_URL.'/file.php?fileid='. $fileid, _AM_XHELP_MSG_DELETE_FILE); |
||
| 73 | xoops_cp_footer(); |
||
| 74 | } else { |
||
| 75 | |||
| 76 | $file =& $hFile->get($fileid); |
||
| 77 | if($hFile->delete($file, true)){ |
||
| 78 | header("Location: ".XHELP_ADMIN_URL."/file.php?op=manageFiles"); |
||
| 79 | } |
||
| 80 | redirect_header(XHELP_ADMIN_URL."/file.php?op=manageFiles", 3, _XHELP_MESSAGE_DELETE_FILE_ERR); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | function deleteResolved() |
||
| 85 | { |
||
| 86 | |||
| 87 | if(!isset($_POST['ok'])){ |
||
| 88 | xoops_cp_header(); |
||
| 89 | //echo $oAdminButton->renderButtons('manFiles'); |
||
| 90 | $indexAdmin = new ModuleAdmin(); |
||
| 91 | echo $indexAdmin->addNavigation('file.php'); |
||
| 92 | |||
| 93 | xoops_confirm(array('op' => 'deleteResolved', 'ok' => 1), XHELP_BASE_URL .'/admin/file.php', _AM_XHELP_MSG_DELETE_RESOLVED); |
||
| 94 | xoops_cp_footer(); |
||
| 95 | } else { |
||
| 96 | $hTicket =& xhelpGetHandler('ticket'); |
||
| 97 | $hFile =& xhelpGetHandler('file'); |
||
| 98 | |||
| 99 | $tickets =& $hTicket->getObjectsByState(1); // Memory saver - unresolved should be less tickets |
||
| 100 | |||
| 101 | $aTickets = array(); |
||
| 102 | foreach($tickets as $ticket){ |
||
| 103 | $aTickets[$ticket->getVar('id')] = $ticket->getVar('id'); |
||
| 104 | } |
||
| 105 | |||
| 106 | // Retrieve all unresolved ticket attachments |
||
| 107 | $crit = new CriteriaCompo(); |
||
| 108 | foreach($aTickets as $ticket){ |
||
| 109 | $crit->add(new Criteria('ticketid', $ticket, "!=")); |
||
| 110 | } |
||
| 111 | View Code Duplication | if($hFile->deleteAll($crit)){ |
|
| 112 | header("Location: ".XHELP_ADMIN_URL."/file.php?op=manageFiles"); |
||
| 113 | } else { |
||
| 114 | redirect_header(XHELP_ADMIN_URL."/file.php?op=manageFiles", 3, _XHELP_MESSAGE_DELETE_FILE_ERR); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | function manageFiles() |
||
| 120 | { |
||
| 121 | global $aSortBy, $aOrderBy, $aLimitBy, $order, $limit, $start, $sort; |
||
| 122 | $xhelpUploadDir = XHELP_UPLOAD_PATH; |
||
| 123 | $dir_status =& xhelp_admin_getPathStatus($xhelpUploadDir, true); |
||
| 124 | |||
| 125 | if($dir_status == -1){ |
||
| 126 | $can_upload = xhelp_admin_mkdir($xhelpUploadDir); |
||
| 127 | } |
||
| 128 | |||
| 129 | $hFile =& xhelpGetHandler('file'); |
||
| 130 | |||
| 131 | if(isset($_POST['deleteFiles'])){ // Delete all selected files |
||
| 132 | $aFiles = $_POST['files']; |
||
| 133 | $crit = new Criteria('id', "(". implode($aFiles, ',') .")", "IN"); |
||
| 134 | |||
| 135 | if($hFile->deleteAll($crit)){ |
||
| 136 | header("Location: ".XHELP_ADMIN_URL."/file.php?op=manageFiles"); |
||
| 137 | } |
||
| 138 | redirect_header(XHELP_ADMIN_URL."/file.php?op=manageFiles", 3, _XHELP_MESSAGE_DELETE_FILE_ERR); |
||
| 139 | } |
||
| 140 | xoops_cp_header(); |
||
| 141 | //echo $oAdminButton->renderButtons('manFiles'); |
||
| 142 | $indexAdmin = new ModuleAdmin(); |
||
| 143 | echo $indexAdmin->addNavigation('file.php?op=manageFiles'); |
||
| 144 | |||
| 145 | echo '<script type="text/javascript" src="'.XOOPS_URL.'/modules/xhelp/include/functions.js"></script>'; |
||
| 146 | echo "<form method='post' action='".XHELP_ADMIN_URL."/file.php?op=manageFiles'>"; |
||
| 147 | |||
| 148 | echo "<table width='100%' cellspacing='1' class='outer'> |
||
| 149 | <tr><th colspan='2'><label>"._AM_XHELP_TEXT_TOTAL_USED_SPACE."</label></th></tr>"; |
||
| 150 | |||
| 151 | echo "<tr><td class='head' width='20%'>"._AM_XHELP_TEXT_ALL_ATTACH."</td> |
||
| 152 | <td class='even'>".xhelpDirsize($xhelpUploadDir)." |
||
| 153 | </td> |
||
| 154 | </tr>"; |
||
| 155 | |||
| 156 | $resolvedSize = xhelpDirsize($xhelpUploadDir, true); |
||
| 157 | echo "<tr><td class='head'>"._AM_XHELP_TEXT_RESOLVED_ATTACH."</td> |
||
| 158 | <td class='even'>"; |
||
| 159 | if($resolvedSize > 0){ |
||
| 160 | echo $resolvedSize." <b>("._AM_XHELP_TEXT_DELETE_RESOLVED." |
||
| 161 | <a href='".XHELP_ADMIN_URL."/file.php?op=deleteResolved'><img src='".XHELP_IMAGE_URL."/button_delete.png' title='"._AM_XHELP_TEXT_DELETE."' name='deleteFile' /></a>)</b>"; |
||
| 162 | } else { |
||
| 163 | echo $resolvedSize; |
||
| 164 | } |
||
| 165 | echo "</td> |
||
| 166 | </tr>"; |
||
| 167 | echo "</table></form>"; |
||
| 168 | |||
| 169 | $crit = new Criteria('', ''); |
||
| 170 | $crit->setOrder($order); |
||
| 171 | $crit->setSort($sort); |
||
| 172 | $crit->setLimit($limit); |
||
| 173 | $crit->setStart($start); |
||
| 174 | $files =& $hFile->getObjects($crit); |
||
| 175 | $total = $hFile->getCount($crit); |
||
| 176 | |||
| 177 | $nav = new XoopsPageNav($total, $limit, $start, 'start', "op=manageFiles&limit=$limit"); |
||
| 178 | |||
| 179 | echo "<form action='". XHELP_ADMIN_URL."/file.php?op=manageFiles' style='margin:0; padding:0;' method='post'>"; |
||
| 180 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 181 | echo "<tr><td align='right'>"._AM_XHELP_TEXT_SORT_BY." |
||
| 182 | <select name='sort'>"; |
||
| 183 | View Code Duplication | foreach($aSortBy as $value=>$text){ |
|
| 184 | ($sort == $value) ? $selected = "selected='selected'" : $selected = ''; |
||
| 185 | echo "<option value='$value' $selected>$text</option>"; |
||
| 186 | } |
||
| 187 | echo "</select> |
||
| 188 | |
||
| 189 | "._AM_XHELP_TEXT_ORDER_BY." |
||
| 190 | <select name='order'>"; |
||
| 191 | View Code Duplication | foreach($aOrderBy as $value=>$text){ |
|
| 192 | ($order == $value) ? $selected = "selected='selected'" : $selected = ''; |
||
| 193 | echo "<option value='$value' $selected>$text</option>"; |
||
| 194 | } |
||
| 195 | echo "</select> |
||
| 196 | |
||
| 197 | "._AM_XHELP_TEXT_NUMBER_PER_PAGE." |
||
| 198 | <select name='limit'>"; |
||
| 199 | View Code Duplication | foreach($aLimitBy as $value=>$text){ |
|
| 200 | ($limit == $value) ? $selected = "selected='selected'" : $selected = ''; |
||
| 201 | echo "<option value='$value' $selected>$text</option>"; |
||
| 202 | } |
||
| 203 | echo "</select> |
||
| 204 | <input type='submit' name='file_sort' id='file_sort' value='"._AM_XHELP_BUTTON_SUBMIT."' /> |
||
| 205 | </td> |
||
| 206 | </tr>"; |
||
| 207 | echo "</table></form>"; |
||
| 208 | |||
| 209 | echo "<form method='post' action='".XHELP_ADMIN_URL."/file.php?op=manageFiles'>"; |
||
| 210 | echo "<table width='100%' cellspacing='1' class='outer'> |
||
| 211 | <tr><th colspan='6'><label>"._AM_XHELP_TEXT_MANAGE_FILES."</label></th></tr>"; |
||
| 212 | if($total != 0){ |
||
| 213 | echo "<tr class='head'> |
||
| 214 | <td>"._AM_XHELP_TEXT_ID."</td> |
||
| 215 | <td>"._AM_XHELP_TEXT_TICKETID."</td> |
||
| 216 | <td>"._AM_XHELP_TEXT_FILENAME."</td> |
||
| 217 | <td>"._AM_XHELP_TEXT_SIZE."</td> |
||
| 218 | <td>"._AM_XHELP_TEXT_MIMETYPE."</td> |
||
| 219 | <td>"._AM_XHELP_TEXT_ACTIONS."</td> |
||
| 220 | </tr>"; |
||
| 221 | |||
| 222 | foreach($files as $file){ |
||
| 223 | $filepath = XHELP_BASE_URL.'/viewFile.php?id='. $file->getVar('id'); |
||
| 224 | $ticketpath = XHELP_BASE_URL.'/ticket.php?id='.$file->getVar('ticketid'); |
||
| 225 | $filesize = filesize($xhelpUploadDir.'/'.$file->getVar('filename')); |
||
| 226 | |||
| 227 | echo "<tr class='even'> |
||
| 228 | <td><input type='checkbox' name='files[]' value='".$file->getVar('id')."' /> ".$file->getVar('id')."</td> |
||
| 229 | <td><a href='".$ticketpath."' target='_BLANK'>".$file->getVar('ticketid')."</a></td> |
||
| 230 | <td><a href='".$filepath."'>".$file->getVar('filename')."</a></td> |
||
| 231 | <td>".xhelpPrettyBytes($filesize)."</td> |
||
| 232 | <td>".$file->getVar('mimetype')."</td> |
||
| 233 | <td> |
||
| 234 | <a href='".XHELP_ADMIN_URL."/file.php?op=deleteFile&fileid=".$file->getVar('id')."'><img src='".XOOPS_URL."/modules/xhelp/images/button_delete.png' title='"._AM_XHELP_TEXT_DELETE."' name='deleteFile' /></a> |
||
| 235 | </td> |
||
| 236 | </tr>"; |
||
| 237 | } |
||
| 238 | echo "<tr class='foot'><td colspan='6'> |
||
| 239 | <input type='checkbox' name='checkAllFiles' value='0' onclick='selectAll(this.form,\"files[]\",this.checked);' /> |
||
| 240 | <input type='submit' name='deleteFiles' id='deleteFiles' value='"._AM_XHELP_BUTTON_DELETE."' /></td></tr>"; |
||
| 241 | echo "</table></form>"; |
||
| 242 | echo "<div id='status_nav'>".$nav->renderNav()."</div>"; |
||
| 243 | } else { |
||
| 244 | echo "<tr class='even'<td colspan='6'>"._AM_XHELP_TEXT_NO_FILES."</td></tr>"; |
||
| 245 | echo "</table></form>"; |
||
| 246 | } |
||
| 247 | |||
| 248 | include_once "admin_footer.php"; |
||
| 249 | |||
| 250 | } |
||
| 251 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.