Index: epublish.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/epublish/epublish.install,v
retrieving revision 1.5
diff -u -p -r1.5 epublish.install
--- epublish.install	30 Dec 2009 03:35:52 -0000	1.5
+++ epublish.install	15 Mar 2010 09:16:08 -0000
@@ -129,3 +129,12 @@ function epublish_schema() {
 function epublish_update_1() {
   return _system_update_utf8(array('epublish_abstract', 'epublish_edition', 'epublish_edition_node', 'epublish_publication', 'epublish_section', 'epublish_topic', 'epublish_volume'));
 }
+
+function epublish_update_6002() {
+	$ret = array();
+	
+	db_add_field($ret, 'epublish_edition', 'cover', array ('type' => 'varchar','length' => 255,'not null' => TRUE,'default' => '','description' => "Path to the cover image."));
+	
+	return $ret;
+}
+
Index: epublish.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/epublish/epublish.module,v
retrieving revision 1.19
diff -u -p -r1.19 epublish.module
--- epublish.module	26 Feb 2010 02:02:22 -0000	1.19
+++ epublish.module	15 Mar 2010 09:16:11 -0000
@@ -77,6 +77,9 @@ function epublish_theme() {
     'epublish_navigation' => array(
       'arguments' => array('node' => NULL, 'eid' => NULL),
     ),
+    'epublish_cover_image' => array(
+      'arguments' => array('edition' => NULL),
+    ),
   );
   return (array_merge($static_arr, $dyn_arr));
 }
@@ -996,6 +999,20 @@ function theme_epublish_format_pub() {
   return "<div class=\"epublish\">$output</div>";
 }
 
+
+function theme_epublish_cover_image($edition) {
+
+	$output = '';
+	
+  if (isset($edition->cover)) {
+    $alt = t("@edition cover image", array('@edition' => $edition->dateline));
+    $output .= theme('image', $edition->cover, $alt, $alt, '', FALSE);
+  }
+	
+	return "<div class=\"picture\">$output</div>";
+}
+
+
 /*******************************************
  *	 SELECTORS
  ******************************************/
@@ -2186,6 +2203,51 @@ function epublish_form_edition($form_sta
     '#cols' => 70,
     '#rows' => 8,
     );
+    
+    
+   
+  
+  
+  
+  
+  
+  
+  
+  // based on user.module picture support. user_edit_form
+  $form['epublish_cover'] = array(
+  	'#type' => 'fieldset', 
+  	'#title' => t('Cover Image'), 
+  );
+  
+	$cover_image = theme('epublish_cover_image', (object)$edit);
+	
+  if ($edit->cover) {
+    $form['epublish_cover']['current_picture'] = array('#value' => $cover_image);
+    $form['epublish_cover']['cover_delete'] = array(
+    	'#type' => 'checkbox', 
+    	'#title' => t('Delete cover'), 
+    	'#description' => t('Check this box to delete the current cover.')
+    );
+    $form['epublish_cover']['cover_current'] = array('#type' => 'hidden', '#value' => $edit->cover);
+  }
+  else {
+    $form['epublish_cover']['cover_delete'] = array('#type' => 'hidden');
+  }
+  
+  $form['epublish_cover']['cover_upload'] = array(
+  	'#type' => 'file', 
+  	'#title' => t('Upload Cover image'), 
+  	'#size' => 48, 
+  	'#description' => t('The edition cover image.')
+  );
+  	
+  $form['#validate'][] = 'epublish_validate_cover_image';
+  $form['#attributes']['enctype'] = 'multipart/form-data';
+
+  
+  
+  
+    
   
   if (module_exists('path')) {
     $path = $form['#node']->path;
@@ -2391,6 +2453,40 @@ function epublish_edition() {
   return $output;
 }
 
+
+function epublish_validate_cover_image(&$form, &$form_state) {
+  $validators = array(
+    'file_validate_is_image' => array(),
+  );
+  
+  // delete the existing cover image first?
+  if ($form_state['values']['cover_delete']) {
+  	//print_r($form);
+    // Remove the old cover.
+    if (isset($form_state['values']['cover_current']) && file_exists($form_state['values']['cover_current'])) {
+      file_delete($form_state['values']['cover_current']);
+    }
+  }
+  
+  $cover_path = variable_get('file_directory_path', 'sites/default/files') .'/'. variable_get('epublish_cover_path', 'epublish') . '/';
+  file_check_directory(file_create_path($cover_path), FILE_CREATE_DIRECTORY);
+  $dest = file_create_path($cover_path);
+  
+  if ($file = file_save_upload('cover_upload', $validators)) {
+    $info = image_get_info($file->filepath);
+    
+    if (file_copy($file, $dest, FILE_EXISTS_REPLACE)) {
+      $form_state['values']['cover'] = $file->filepath;
+    }
+    else {
+  		form_set_error('cover_upload', t("Failed to upload the cover image; the %directory directory doesn't exist or is not writable.", array('%directory' => $cover_path)));
+  	}
+  }
+
+}
+
+
+
 function theme_epublish_form_edition($form) {
   // create the headlines table
   if (isset($form['title']) && is_array($form['title'])) {
@@ -2455,7 +2551,7 @@ function epublish_form_edition_submit($f
       }
     }
 
-    db_query("UPDATE {epublish_edition} SET pid='%d', dateline='%s', description='%s', volume='%d', number='%d', pubdate='%d', layout_list='%s', layout_page='%s', sid='%d', published='%d' WHERE eid = '%d'", $edit['pid'], $edit['dateline'], $edit['description'], $edit['volume'], $edit['number'], $edit['year'] . $edit['month'] . $edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published'], $edit['eid']);
+    db_query("UPDATE {epublish_edition} SET pid='%d', dateline='%s', description='%s', volume='%d', number='%d', pubdate='%d', layout_list='%s', layout_page='%s', sid='%d', published='%d', cover='%s' WHERE eid = '%d'", $edit['pid'], $edit['dateline'], $edit['description'], $edit['volume'], $edit['number'], $edit['year'] . $edit['month'] . $edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published'], $edit['cover'], $edit['eid']);
     // Handle operations:
     if (isset($edit['operation']) && isset($edit['nodes'])) {
       foreach ($edit['nodes'] as $nid => $value) {
@@ -2475,7 +2571,7 @@ function epublish_form_edition_submit($f
   }
   else {
     $edit['eid'] = db_last_insert_id('epublish_edition', 'eid');
-    db_query("INSERT INTO {epublish_edition} (eid, pid, dateline, description, volume, number, pubdate, layout_list, layout_page, sid, published) VALUES ('%d', '%d', '%s', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%d')", $edit['eid'], $edit['pid'], $edit['dateline'], $edit['description'], $edit['volume'], $edit['number'], $edit['year'] . $edit['month'] . $edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published']);
+    db_query("INSERT INTO {epublish_edition} (eid, pid, dateline, description, volume, number, pubdate, layout_list, layout_page, sid, published, cover) VALUES ('%d', '%d', '%s', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%d', '%s')", $edit['eid'], $edit['pid'], $edit['dateline'], $edit['description'], $edit['volume'], $edit['number'], $edit['year'] . $edit['month'] . $edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published'], $edit['cover']);
     drupal_set_message(t('The "%title" edition has been added.', array('%title' => $edit['dateline'])));
   }
   if ($edit['make_current']) {
