Index: task/hosting_task.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/task/hosting_task.module,v
retrieving revision 1.40
diff -u -r1.40 hosting_task.module
--- task/hosting_task.module	6 Nov 2008 00:51:00 -0000	1.40
+++ task/hosting_task.module	27 Nov 2008 20:57:04 -0000
@@ -129,11 +129,61 @@
  * Implementation of hook_form().
  */
 function hosting_task_confirm_form(&$node, $task) {
+  hosting_site_check_incoming($node);
   $tasks = hosting_available_tasks($node);
   $form['help'] = array('#value' => $tasks[$task]['description']); 
   $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
   $form['task'] = array('#type' => 'value', '#value' => $task); 
   $form['parameters'] = array('#tree' => TRUE);
+
+  if ($task == 'restore') {
+    $form['parameters'] = array('#tree' => TRUE);
+    $form['#attributes'] = array('enctype' => 'multipart/form-data');
+    $form['#validate'] = array(
+        'hosting_task_restore_form_validate' => array(),
+    );
+    $form['#submit'] = array(
+        'hosting_task_restore_form_submit' => array(),
+    );
+
+    $form['import'] =  array(
+        '#type' => 'fieldset',
+        '#title' => t('Import your backup.'),
+	'#weight' => -1, 
+     );
+    $form['import']['file_upload'] = array (
+        '#type' => 'file',
+        '#title' => t('Attach backup file'),
+        '#size' => 40,
+    );
+    $form['import']['submit'] = array (
+        '#type' => 'submit',
+	'#value' => t('Restore')
+    );
+    $list = hosting_site_backup_list($node->nid);
+    if (sizeof($list)) {
+      $form['bid'] = array(
+        '#type' => 'radios',
+        '#title' => t('Backups'),
+        '#options' => $list,
+      );
+      $form['submit'] = array (
+        '#type' => 'submit',
+	'#value' => t('Restore')
+      );
+    }
+    else {
+      $form['no_backups'] = array(
+        '#type' => 'item',
+        '#title' => t('Backups'),
+        '#value' => t('There are no valid backups available.')
+      );
+    }
+
+    return $form;
+    
+  }
+
   $func = 'hosting_task_' . $task . '_form';
   if (function_exists($func)) {
     $form['parameters'] += $func($node);
@@ -142,24 +192,32 @@
   return confirm_form($form, $question, 'node/' . $node->nid, '', $tasks[$task]['title']);
 }
 
-function hosting_task_restore_form($node) {
-  $list = hosting_site_backup_list($node->nid);
-  if (sizeof($list)) {
-    $form['bid'] = array(
-      '#type' => 'radios',
-      '#title' => t('Backups'),
-      '#options' => $list,
-      '#required' => TRUE
-    );
+function hosting_task_restore_form_validate($form_id, $values) {
+  $file = file_check_upload('file_upload');
+  if ((empty($file) and empty($values['bid'])) or (!empty($file) and !empty($values['bid']))){
+    form_set_error('restore_form', t('you must select a backup to restore or upload a backup to restore.'));
+  }
+  if ($file){
+    if (!preg_match("/.*\.tar\.gz/", $file->filename)) {
+      form_set_error('restore_form', t('Only tar.gz can be upload with this form.'));
+    }
   }
-  else {
-    $form['no_backups'] = array(
-      '#type' => 'item', 
-      '#title' => t('Backups'), 
-      '#value' => t('There are no valid backups available.')
-    );
+}
+
+function hosting_task_restore_form_submit($form_id, $values){
+  if (!empty($values['bid'])){
+    $values['parameters']['bid'] += $values['bid'];
+    hosting_add_task($values['nid'], $values['task'], $values['parameters']);
+    drupal_set_message(t('You have successfully choose a backup to restore. A new task was created to process it.'));
+  }
+  if ($file = file_check_upload('file_upload')){
+    if (copy($file->filepath, PROVISION_INCOMING_PATH ."/". $file->filename)) {
+      drupal_set_message(t('You have successfully uploaded your backup.'));
+      unlink($file->filepath);
+    }else{
+      form_set_error('file_upload', t('Error during the move of the uploaded file.'));
+    }
   }
-  return $form;
 }
 
 function hosting_task_confirm_form_submit($form_id, $values) {
@@ -628,3 +686,16 @@
    return $output;
   }
 }
+
+function hosting_site_check_incoming($node) {
+   $tasks = hosting_task_outstanding($node->nid,'incoming');
+   if(!empty($tasks)){
+     return;
+   }
+   $new_files = file_scan_directory(PROVISION_INCOMING_PATH, $node->title.'.*\.tar\.gz$');
+
+   if (sizeof($new_files) >= 1 ) {
+     drupal_set_message("New backup file will be available in one minute or less.");
+     hosting_add_task($node->nid, 'incoming');
+   }
+}
