Index: modules/upload.module =================================================================== RCS file: /cvs/drupal/drupal/modules/upload.module,v retrieving revision 1.31.2.5 diff -u -r1.31.2.5 upload.module --- modules/upload.module 25 May 2005 04:28:59 -0000 1.31.2.5 +++ modules/upload.module 25 Jun 2005 22:42:23 -0000 @@ -15,6 +15,8 @@ return t('Allows users to upload and attach files to content.'); case 'admin/settings/upload': return t('

Users with the upload files permission can upload attachments. You can choose which post types can take attachments on the content types settings page.

', array('%permissions' => url('admin/access'), '%types' => url('admin/node/configure/types'))); + case 'admin/uploads': + return t('

Users with the administer uploaded files permission can administer uploaded files.

', array('%permissions' => url('admin/access'))); } } @@ -22,7 +24,7 @@ * Implementation of hook_perm(). */ function upload_perm() { - return array('upload files', 'view uploaded files'); + return array('upload files', 'view uploaded files', 'administer uploaded files'); } /** @@ -57,9 +59,17 @@ $items[] = array( 'path' => 'admin/settings/upload', 'title' => t('uploads'), 'callback' => 'upload_admin', - 'access' => user_access('administer site configuration'), - 'type' => MENU_NORMAL_ITEM - ); + 'access' => user_access('administer uploaded files')); + $items[] = array( + 'path' => 'upload', 'title' => t('my uploads'), + 'callback' => 'upload_page', + 'callback arguments' => array('user'), + 'access' => user_access('upload files')); + $items[] = array( + 'path' => 'admin/upload', 'title' => t('uploads'), + 'callback' => 'upload_page', + 'callback arguments' => array('admin'), + 'access' => user_access('administer uploaded files')); } else { // Add handlers for previewing new uploads. @@ -80,6 +90,78 @@ return $items; } +/* + * Menu callback: + * Pages where users add and delete their subscriptions to nodes + */ +function upload_page($op) { + global $user; + + switch($op) { + case 'admin': + $header = array( + array('data' => t('Filename'), 'field' => 'filename'), + array('data' => t('Location'), 'field' => 'title'), + array('data' => t('Author'), 'field' => 'name'), + array('data' => t('Size'), 'field' => 'filesize') + ); + + $sql = "SELECT f.fid, n.nid, n.title, f.filename, f.filepath, f.filesize, n.uid, u.name FROM {files} f INNER JOIN {node} n INNER JOIN {users} u ON f.nid = n.nid AND n.uid = u.uid"; + $sql .= tablesort_sql($header); + $result = pager_query($sql, 50); + + while ($file = db_fetch_object($result)) { + $rows[] = array( + l($file->filename, file_create_url(($file->fid ? $file->filepath : file_create_filename($file->filename, file_create_path())))), + l($file->title, "node/$file->nid"), + l($file->name, "user/$file->uid"), + format_size($file->filesize) + ); + } + + if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) { + $rows[] = array(array('data' => $pager, 'colspan' => '4')); + } + + if (!$rows) { + $rows[] = array(array('data' => t('No uploaded files available.'), 'colspan' => '4')); + } + + print theme('page', theme('table', $header, $rows)); + break; + + case 'user': + $header = array( + array('data' => t('Filename'), 'field' => 'filename'), + array('data' => t('Location'), 'field' => 'title'), + array('data' => t('Size'), 'field' => 'filesize') + ); + + $sql = "SELECT f.fid, n.nid, n.title, f.filename, f.filepath, f.filesize, n.uid, u.name FROM {files} f INNER JOIN {node} n INNER JOIN {users} u ON f.nid = n.nid AND n.uid = u.uid WHERE n.uid = $user->uid"; + $sql .= tablesort_sql($header); + $result = pager_query($sql, 50); + + while ($file = db_fetch_object($result)) { + $rows[] = array( + l($file->filename, file_create_url(($file->fid ? $file->filepath : file_create_filename($file->filename, file_create_path())))), + l($file->title, "node/$file->nid"), + format_size($file->filesize) + ); + } + + if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) { + $rows[] = array(array('data' => $pager, 'colspan' => '3')); + } + + if (!$rows) { + $rows[] = array(array('data' => t('No uploaded files available.'), 'colspan' => '3')); + } + + print theme('page', theme('table', $header, $rows)); + break; + } +} + function upload_admin() { system_settings_save();