Index: modules/attachment/attachment.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/attachment/attachment.module,v
retrieving revision 1.3.2.1
diff -u -r1.3.2.1 attachment.module
--- modules/attachment/attachment.module	3 Feb 2005 22:17:42 -0000	1.3.2.1
+++ modules/attachment/attachment.module	6 Feb 2005 23:24:53 -0000
@@ -41,13 +41,14 @@
       foreach ((array)$node->attachments as $attachment) {
         if (!$attachment['deleted']) {
           filemanager_promote_working($attachment['fid']);
+
           if ($attachment['aid']) {
-            db_query("UPDATE {attachment} SET size=%d, hidden='%s' WHERE aid=%d", $attachment['size'], $attachment['hidden'], $attachment['aid']);
+            db_query("UPDATE {attachment} SET title='%s', description = '%s', size=%d, hidden='%s' WHERE aid=%d", $attachment['title'], $attachment['description'], $attachment['size'], $attachment['hidden'], $attachment['aid']);
           }
           else {
-            $aid = db_next_id('attachment_aid');
-            db_query("INSERT INTO {attachment} (aid,nid,fid,filename,size,hidden) VALUES (%d,%d,%d,'%s',%d,'%s')",
-                     $aid, $node->nid, $attachment['fid'], $attachment['filename'], $attachment['size'], $attachment['hidden']);
+            $aid = db_next_id('{attachment}_aid');
+            db_query("INSERT INTO {attachment} (aid,title,description,nid,fid,filename,size,hidden) VALUES (%d,'%s','%s',%d,%d,'%s',%d,'%s')",
+                     $aid, $attachment['title'],$attachment['description'],$node->nid, $attachment['fid'], $attachment['filename'], $attachment['size'], $attachment['hidden']);
           }
         }
         else {
@@ -65,10 +66,12 @@
       return;
     case 'validate':
       switch ($_POST['fileop']) {
-        case t('Add attachment'):
+        case t('Add'):
           return attachment_add($node);
-        case t('Delete attachment'):
+        case t('Delete'):
           return attachment_delete($node);
+        case t('Change title/desc'):
+          return attachment_change($node);
       }
       return;
   }
@@ -85,7 +88,7 @@
  * Implementation of hook_file_areas()
  */
 function attachment_filemanager_areas() {
-  return array(array('area'=>'attachments','name'=>t('Attachments'),'description'=>t('Area were all node attachments are stored.')));
+  return array(array('area'=>'attachments','name'=>t('Attachments'),'description'=>t('Area where all node attachments are stored.')));
 }
 
 /**
@@ -140,10 +143,13 @@
   $header[2] = t('Hidden');
   $header[3] = t('Size');
 
+  $size = 0;
+  $files = 0;
+
   $attributes['class'] = 'attachment-list';
   foreach ((array)$node->attachments as $key=>$attachment) {
 
-    $fields = array('aid','fid','filename','size','working','deleted');
+    $fields = array('aid','fid','filename','size','working','deleted','title','description');
     foreach($fields as $field) {
       $output .= form_hidden("attachments][$key][$field", $attachment[$field]);
     }
@@ -161,17 +167,47 @@
       $row[3]['class'] = 'size';
       $rows[] = $row;
     }
+    $files ++;
+    $size += $attachment['size'];
   }
 
   $group = '<div class="attachment-group">';
   if (count($rows) > 0) {
+    $row[0] = '';
+    $row[1]['data'] = t('<strong>Totally %numfiles files</strong>', array('%numfiles' => $files));
+    $row[2] = '';
+    $row[3]['data'] = '<strong>' . format_size($size) . '</strong>';
+    $rows[] = $row;
     $group .= theme('table', $header, $rows, $attributes);
-    $group .= form_submit(t('Delete attachment'), 'fileop');
+    $group .= form_submit(t('Delete'), 'fileop');
+    $group .= form_submit(t('Change title/desc'), 'fileop');
+    $group .= '<br />';
   }
 
-  $group .= '<br />';
-  $group .= form_file(t('New attachment'), 'file', 20);
-  $group .= form_submit(t('Add attachment'), 'fileop');
+  // title
+  $group .= form_textfield(
+    t('Title'),               // title
+    'attachment_title',       // name
+    $node->attachment_title,  // value
+    10,   // size
+    50,   // maxlength
+    t('used as link-text'),
+    null, // attributes
+    false // required
+  );
+  // description
+  $group .= form_textfield(
+    t('Description'),               // title
+    'attachment_description',       // name
+    $node->attachment_description,  // value
+    10,   // size
+    50,   // maxlength
+    t('used as title-attribute in link'),
+    null, // attributes
+    false // required
+  );
+  $group .= form_file(t('File'), 'file', 20);
+  $group .= form_submit(t('Add'), 'fileop');
   $group .= '</div>';
   $output .= form_group(t('Attachments'),$group);
 
@@ -187,7 +223,7 @@
 
   $file = file_check_upload('file');
   if (!$file) {
-    form_set_error(t('Attachments'), t('No file selected.'));
+    form_set_error('file', t('No file selected.'));
     return $node;
   }
 
@@ -210,10 +246,14 @@
   // Move the upload file into working filestore
   $file = filemanager_add_upload('file', 'attachments', FALSE, $new_attachment["fid"]);
   if (!$file) {
-    form_set_error(t('Attachments'), t('Error saving upload to filestore.'));
+    form_set_error('file', t('Error saving upload to filestore.'));
     return $node;
   }
-  $new_attachment['fid'] = $file->fid;
+  $new_attachment['fid']         = $file->fid;
+  $new_attachment['title']       = $node->attachment_title;
+  $new_attachment['description'] = $node->attachment_description;
+  unset($node->attachment_title);
+  unset($node->attachment_description);
 
   $node->attachments[] = $new_attachment;
 }
@@ -222,7 +262,7 @@
  * Load the attachments for the given node
  */
 function attachment_load($node) {
-  $result = db_query("SELECT aid, fid, filename, size, hidden FROM {attachment} WHERE nid = %d", $node->nid);
+  $result = db_query("SELECT aid, title, description, fid, filename, size, hidden FROM {attachment} WHERE nid = %d", $node->nid);
   while ($attachment = db_fetch_array($result)) {
     $attachment['deleted'] = FALSE;
     $attachment['working'] = FALSE;
@@ -245,6 +285,19 @@
       $node->attachments[$attachindex]['deleted'] = TRUE;
     }
   }
+  unset($node->attachment_title);
+  unset($node->attachment_description);
+}
+
+function attachment_change(&$node) {
+  for ($attachindex = 0; $attachindex < count($node->attachments); $attachindex++) {
+    if ($node->attachments[$attachindex]['selected']) {
+      $node->attachments[$attachindex]['title'] = $node->attachment_title;
+      $node->attachments[$attachindex]['description'] = $node->attachment_description;
+    }
+  }
+  unset($node->attachment_title);
+  unset($node->attachment_description);
 }
 
 function attachment_filemanager_download($file) {
@@ -267,17 +320,28 @@
 
   $attributes['class'] = 'attachment-list';
 
-  $header[0]['data'] = t('Filename');
+  $header[0]['data'] = t('Title/Filename');
   $header[0]['class'] = 'filename';
   $header[1]['data'] = t('Size');
   $header[1]['class'] = 'size';
+  $header[2]['data'] = t('Type');
+  $header[2]['class'] = 'type';
 
   foreach ((array)$node->attachments as $attachment) {
     if (!$attachment['hidden'] && !$attachment['deleted']) {
-      $row[0]['data'] = '<a href="' . filemanager_url($attachment['fid']) . '">' . $attachment['filename'] . '</a>';
+      $matches = array();
+      $extension = '';
+      if (preg_match('/.+\.([^.]+)$/', $attachment['filename'],$matches)) {
+        $extension = $matches[1];
+      }
+      $text = empty($attachment['title']) ? $attachment['filename'] : $attachment['title'];
+      $attrib = empty($attachment['description']) ? array() : array('title' => $attachment['description']);
+      $row[0]['data'] = l($text, filemanager_url($attachment['fid']), $attrib);
       $row[0]['class'] = 'filename';
       $row[1]['data'] = format_size($attachment['size']);
       $row[1]['class'] = 'size';
+      $row[2]['data'] = $extension;
+      $row[2]['class'] = 'type';
       $rows[] = $row;
     }
   }
