Index: README.txt
===================================================================
RCS file: /cvs/drupal/contributions/modules/filestore2/README.txt,v
retrieving revision 1.2
diff -u -r1.2 README.txt
--- README.txt	16 Dec 2004 05:02:47 -0000	1.2
+++ README.txt	28 Jul 2006 09:04:05 -0000
@@ -1,4 +1,4 @@
-$Id: README.txt,v 1.2 2004/12/16 05:02:47 gordon Exp $
+$Id: README.txt,v 1.1 2006/05/26 15:17:52 sar Exp $
 
 Filestore2
 ----------
Index: filestore2.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/filestore2/filestore2.module,v
retrieving revision 1.32
diff -u -r1.32 filestore2.module
--- filestore2.module	18 Jan 2006 19:55:41 -0000	1.32
+++ filestore2.module	28 Jul 2006 09:04:05 -0000
@@ -1,10 +1,13 @@
 <?php
-// $Id: filestore2.module,v 1.32 2006/01/18 19:55:41 gordon Exp $
+// $Id: filestore2.module,v 1.2 2006/07/13 14:06:33 sar Exp $
 
 /*
  * Filestore2 drupal _hooks()
  */
 
+/**
+ * Implementation of hook_help().
+ */
 function filestore2_help($section) {
   
   switch($section) {
@@ -18,77 +21,17 @@
   }
 }
 
+/**
+ * Implementation of hook_perm().
+ */
 function filestore2_perm() {
   return array("upload files","access files");
 }
 
-function filestore2_access($op, $node) {
-  if (user_access("access content")) {
-    switch($op) {
-      case "view":
-        return $node->status;
-      case "create":
-        return user_access("upload files");
-      default:
-        return 0;
-    }
-  }
-  else {
-    return 0;
-  }
-}
-
-function filestore2_link($type, $node = 0) {
-
-  $links = array();
-  
-  if ($type == "page" && user_access("access content")) {
-    $links[] = l(t("files"), "filestore2", array("title" => t("Browse files to download")));
-  }
-  
-  if (user_access('access files') && $node->fsid) {
-    $links[] = l(t('download'), "filestore2/download/$node->nid/$node->filename", array("title" => t('download %filename', array('%filename' => $node->filename))));
-    $links[] = format_size($node->size);
-  }
-  if ($type == "node" && user_access("access content") && isset($node->fsid)) {
-    if (module_exist("statistics") && user_access("access statistics") && variable_get("statistics_display_counter", 0)) {
-      $links[] = format_plural(($node->downloads ? $node->downloads : 0), "1 download", "%count downloads");
-    }
-  }
-
-  return $links ? $links :  array();
-}
-
-function filestore2_menu($may_cache) {
-  $items = array();
-
-  if ($may_cache) {
-    $items[] = array('path' => 'node/add/filestore2', 
-      'title' => t('upload file'), 
-      'access' => user_access('upload files'), 
-      'type' => MENU_NORMAL_ITEM);
-    $items[] = array('path' => 'filestore2', 
-      'title' => t('Browse files to download'), 
-      'callback' => 'filestore2_page', 
-      'access' => user_access("access files"), 
-      'type' => MENU_CALLBACK);
-    $items[] = array('path' => 'filestore2/download', 
-      'title' => t('Browse files to download'), 
-      'callback' => 'filestore2_page', 
-      'access' => user_access("access content"), 
-      'type' => MENU_CALLBACK);
-    $items[] = array('path' => 'admin/settings/filestore/convert', 
-      'title' => t('convert'), 
-      'callback' => 'filestore2_convert', 
-      'access' => module_exist("filestore") && user_access("access administration pages"), 
-      'type' => MENU_LOCAL_TASK);
-  }
-  return $items;
-}
-  
+/**
+ * Implementation of hook_settings().
+ */
 function filestore2_settings() {
-
-  //$output .= form_textfield(t("Max Upload Size"), "filestore2_max_upload", _filestore2_display_size(variable_get("filestore2_max_upload", _filestore2_getmaxsize_actual())), 15, 15, t("The maximum size of a file that can be uploaded. System maximum upload size is "). _filestore2_display_size(_filestore2_getmaxsize_actual()));
   $form["filestore2_max_upload"] = array(
     '#type' => 'textfield',
     '#title' => t("Max Upload Size"),
@@ -130,16 +73,96 @@
   return $form;
 }
 
+/**
+ * Implementation of hook_menu().
+ */
+function filestore2_menu($may_cache) {
+  $items = array();
+
+  if ($may_cache) {
+    $items[] = array('path' => 'node/add/filestore2', 
+      'title' => t('upload file'), 
+      'access' => user_access('upload files'), 
+      'type' => MENU_NORMAL_ITEM);
+    $items[] = array('path' => 'filestore2', 
+      'title' => t('Browse files to download'), 
+      'callback' => 'filestore2_page', 
+      'access' => user_access("access files"), 
+      'type' => MENU_CALLBACK);
+    $items[] = array('path' => 'filestore2/download', 
+      'title' => t('Browse files to download'), 
+      'callback' => 'filestore2_page', 
+      'access' => user_access("access content"), 
+      'type' => MENU_CALLBACK);
+    $items[] = array('path' => 'admin/settings/filestore/convert', 
+      'title' => t('convert'), 
+      'callback' => 'filestore2_convert', 
+      'access' => module_exist("filestore") && user_access("access administration pages"), 
+      'type' => MENU_LOCAL_TASK);
+  }
+  return $items;
+}
+
+/**
+ * Implementation of hook_access().
+ */
+function filestore2_access($op, $node) {
+  if (user_access("access content")) {
+    switch($op) {
+      case "view":
+        return $node->status;
+      case "create":
+        return user_access("upload files");
+      default:
+        return 0;
+    }
+  }
+  else {
+    return 0;
+  }
+}
+
+/**
+ * Implementation of hook_link().
+ */
+function filestore2_link($type, $node = 0) {
+
+  $links = array();
+  
+  if ($type == "page" && user_access("access content")) {
+    $links[] = l(t("files"), "filestore2", array("title" => t("Browse files to download")));
+  }
+  
+  if (user_access('access files') && $node->fsid) {
+    $links[] = l(t('download'), "filestore2/download/$node->nid/$node->filename", array("title" => t('download %filename', array('%filename' => $node->filename))));
+    $links[] = format_size($node->size);
+  }
+  if ($type == "node" && user_access("access content") && isset($node->fsid)) {
+    if (module_exist("statistics") && user_access("access statistics") && variable_get("statistics_display_counter", 0)) {
+      $links[] = format_plural(($node->downloads ? $node->downloads : 0), "1 download", "%count downloads");
+    }
+  }
+
+  return $links ? $links :  array();
+}
+
+/**
+ * Implementation of hook_node_info().
+ */
 function filestore2_node_info() {
-  return array('filestore2' => array('name' => t("file upload"), 'base' => 'filestore2'));
+  return array('filestore2' => array('name' => t('file upload'), 'base' => 'filestore2'));
 }
 
+
+/**
+ * Menu callback.
+ */
 function filestore2_page() {
 
   switch (arg(1)) {
     case "download":
       if (user_access("access files")) {
-        $node = node_load(array("nid" => arg(2)));
+        $node = node_load(arg(2));
         if (fscache_download(array("fsid" => $node->fsid), TRUE)) {
           db_query("UPDATE {filestore2} SET downloads = downloads + 1 WHERE nid = $node->nid");
           watchdog("user", t("file %filename downloaded.", array("%filename" => $node->filename)));
@@ -150,7 +173,7 @@
       }
       break;
 	case 'browse':
-          print theme("page",_filestore2_browse(arg(2)));
+    return _filestore2_browse(arg(2));
 	  break;
     default:
       if (variable_get("filestore2_alpha", 1) == 1) {
@@ -163,21 +186,32 @@
         $output .= node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1);
       }
       $output .= theme("pager",NULL, variable_get("default_nodes_main", 10));
-      print theme("page", $output);
+      return $output;
   }
 }
 
+/**
+ * Implementation of hook_view().
+ */
 function filestore2_view(&$node, $main = 0, $page = 0) {
   $node->title = _filestore2_change_title($node);
   $node = node_prepare($node, $main);
 }
 
+/**
+ * Implementation of hook_insert().
+ */
 function filestore2_insert($node) {
-
   $fields = array("fid", "nid", "fsid", "version", "author", "url");
 
   $node->fid = db_next_id("{filestore2}_fid");
-  
+
+  // revalidate and save upload
+  filestore2_upload_validate($node, TRUE, TRUE);
+
+  //require_once('html.inc');
+  //_dump($node, 'filestore2_insert');
+
   foreach ($node as $k => $v) {
     if (in_array($k, $fields)) {
       $keys[] = db_escape_string($k);
@@ -189,7 +223,12 @@
   fscache_update_status(array("fsid" => $node->fsid));
 }
 
+/**
+ * Implementation of hook_update().
+ */
 function filestore2_update($node) {
+  // revalidate and save upload
+  filestore2_upload_validate($node, TRUE, TRUE);
 
   $fields = array("fid", "nid", "fsid", "version", "author", "url");
   foreach ($node as $k => $v) {
@@ -198,12 +237,14 @@
     }
   }
 
-  db_query("UPDATE {filestore2} SET " .implode(", ", $q) ." WHERE fid = '$node->fid'");
+  db_query("UPDATE {filestore2} SET " .implode(", ", $q) ." WHERE fid = %d", $node->fid);
   fscache_update_status(array("fsid" => $node->fsid));
 }
 
+/**
+ * Implementation of hook_load().
+ */
 function filestore2_load($node) {
-  
   $fs = db_fetch_object(db_query("SELECT * FROM {filestore2} WHERE nid = %d", $node->nid));
 
   fscache_add_cache_info($fs, $fs->fsid);
@@ -211,114 +252,149 @@
   return $fs;
 }
 
+/**
+ * Implementation of hook_delete().
+ */
 function filestore2_delete($node) {
-
 // first we need to delete all the fscache files
-  $result = db_query("SELECT fsid FROM {filestore2} WHERE nid = '$node->nid'");
+  $result = db_query("SELECT fsid FROM {filestore2} WHERE nid = %d", $node->nid);
 
   while ($fitem = db_fetch_object($result)) {
     fscache_delete(array("fsid" => $fitem->fsid));
   }
  
 // now I can delete the filestore2 rows.
-  db_query("DELETE FROM {filestore2} WHERE nid = '$node->nid'");
+  db_query("DELETE FROM {filestore2} WHERE nid = %d", $node->nid);
 }
 
 function filestore2_form(&$node, &$param) {
-  $form["title"] = array(
+  $form['title'] = array(
     '#type' => 'textfield',
-    '#title' => t("Title"),
+    '#title' => t('Title'),
     '#default_value' => $node->title,
     '#size' => 60,
     '#maxlength' => 65
   );
-  $form["file_author"] = array(
+  $form['file_author'] = array(
     '#type' => 'textfield',
-    '#title' => t("File Author"),
+    '#title' => t('File Author'),
     '#default_value' => $node->author,
     '#size' => 60,
     '#maxlength' => 65,
-    '#description' => t("Name of the Individual or Company who created this file")
+    '#description' => t('Name of the Individual or Company who created this file')
   );
-  if (variable_get("filestore2_version_enter",0) != 2 || $node->version) {
-    $form["version"] = array(
+  if (variable_get('filestore2_version_enter',0) != 2 || $node->version) {
+    $form['version'] = array(
       '#type' => 'textfield',
-      '#title' => t("File Version"),
+      '#title' => t('File Version'),
       '#default_value' => $node->version,
       '#size' => 60,
       '#maxlength' => 65,
-      '#description' => t("The version of the file uploaded"),
+      '#description' => t('The version of the file uploaded'),
       '#attributes' => NULL,
       '#required' => variable_get('filestore2_version_enter', 0) == 0 ? true : false,
     );
   }
-  $form["body"] = array(
+  $form['body'] = array(
     '#type' => 'textarea',
-    '#title' => t("Body"),
+    '#title' => t('Body'),
     '#default_value' => $node->body,
     '#cols' => 60,
     '#rows' => 15,
   );
-  $form["url"] = array(
+  $form['url'] = array(
     '#type' => 'textfield',
-    '#title' => t("Web Page"),
+    '#title' => t('Web Page'),
     '#default_value' => $node->url,
     '#size' => 60,
     '#maxlength' => 65,
-    '#description' => t("Link to uploads home page"),
+    '#description' => t('Link to uploads home page'),
   );
-  $form["fid"] = array(
+  $form['fid'] = array(
     '#type' => 'hidden',
     '#value' => $node->fid,
-    );
-  $form["fsid"] = array(
+  );
+  $form['fsid'] = array(
     '#type' => 'hidden',
     '#value' => $node->fsid,
-    );
+  );
   filestore2_form_init($form);
-  $form["upload_file"] = array(
+  if ($node->filename) {
+    $form['upload_file_current'] = array(
+      '#type' => 'markup',
+      '#prefix' => '<div>',
+      '#suffix' => '</div>',
+      '#value' => check_markup(t('Current file') .': '. $node->filename. " ($node->size)"),
+    );
+  }
+
+  $form['upload_file'] = array(
     '#type' => 'file',
-    '#title' => t("File to Upload"),
+    '#title' => t('File to Upload'),
     '#size' => 60,
-    '#description' => t("Enter the name of the file to upload."),
+    '#description' => t('Enter the name of the file to upload.'),
   );
+  $form['#attributes']['enctype'] = 'multipart/form-data';
   return $form;
 }
 
 function filestore2_validate(&$node) {
-
   if (isset($node->version) && !$node->version && variable_get("filestore2_version_enter", 0) == 0) {
     form_set_error("version", t("You did not supply a version number."));
   }
-  filestore2_upload_validate($node);
+  // filestore2_upload_validate(&$node, $required = TRUE, $store = TRUE, $field = "upload_file")
+  filestore2_upload_validate($node, TRUE, FALSE);
   return;
 }
 
+
+function filestore2_form_alter($form_id, &$form) {
+  if (isset($form['type']) && $form['type']['#value'] != 'filestore2') {
+    if ($form['type']['#value'] .'_node_settings' == $form_id) {
+      $form['filestore2']['filestore2_attach_'. $form['type']['#value']] = array(
+        '#type' => 'checkboxes', 
+        '#title' => t('Default options'), 
+        '#default_value' => variable_get('filestore2_attach_'. $form['type']['#value'], 0),
+        '#options' => array('0'  => t('disabled'), '2' => t('optional'), '1' => t('required')),
+        '#description' => '',
+      );
+    }
+    else if ($form['type']['#value'] .'_node_form' == $form_id) {
+      // "form post"
+      filestore2_form_init($form);
+      $node = $form['#node'];
+      $form['fid'] = array(
+        '#type' => 'hidden',
+        '#value' => $node->fid,
+      );
+      $form['fsid'] = array(
+        '#type' => 'hidden',
+        '#value' => $node->fsid,
+      );
+      if ($node->filename) {
+        $form['nodeapi_upload_file_current'] = array(
+          '#type' => 'item',
+          '#title' => "",
+          '#default_value' => check_markup($node->filename). " ($node->size)",
+        );
+      }
+      $form['nodeapi_upload_file'] = array(
+        '#type' => 'file',
+        '#title' => t('File to Upload'),
+        '#size' => 60,
+        '#description' => t('Enter the name of the file to upload.'),
+      );
+      $form['#attributes']['enctype'] = 'multipart/form-data';
+    }
+  }
+}
+
+
+
+
 function filestore2_nodeapi(&$node, $op, $arg = 0) {
-  if (variable_get("filestore2_attach_$node->type", 0) || $op == "settings") {
+  if (variable_get("filestore2_attach_$node->type", 0)) {
     switch ($op) {
-      case "settings":
-        if ($node->type != "filestore2") {
-          $output[t("attach file")] = form_select('', "filestore2_attach_$node->type", variable_get("filestore2_attach_$node->type", 0), array("0"  => t("disabled"), "2" => t("optional"), "1" => t("required")));
-        }
-        else {
-          $output[t("attach file")] = "&nbsp;";
-        }
-        return $output;
-        break;
-      case "form post":
-        $output .= filestore2_form_init($param);
-        $output .= form_hidden("fid", $node->fid);
-        $output .= form_hidden("fsid", $node->fsid);
-        $output .= ($node->filename ? form_item("", check_output($node->filename). " ($node->size)") : ""); 
-        $output .= filestore2_form_file(t("File to Upload"), "nodeapi_upload_file", 0, ($arg["nodeapi_upload_file"] ? $arg["nodeapi_upload_file"] : t("Enter the name of the file to upload.")), $param);
-        return $output;
-        break;
-      case "form param":
-        $param["method"] = "post";
-        $param["options"]["enctype"] = "multipart/form-data";
-        return $param;
-        break;
       case "validate":
         return filestore2_upload_validate($node, variable_get("filestore2_attach_$node->type", 0) == 1 ? TRUE : FALSE, TRUE, "nodeapi_upload_file");
         break;
@@ -465,18 +541,39 @@
       $count = 0;
       $result = db_query("SELECT n.nid FROM {node} n LEFT JOIN {filestore2} fs2 ON n.nid = fs2.nid WHERE fs2.nid IS NOT NULL AND n.type = 'filestore'");
       while($nid = db_fetch_object($result)) {
-        $node = node_load(array("nid" => $nid->nid));
+        $node = node_load($nid->nid);
         filestore2_delete($node);
         $count++;
       }
       drupal_set_message(t("%count files deleted", array("%count" => $count)));
       break;
   }
-  $output .= form_item(t("Transfer files"),l(t("transfer"), "admin/system/modules/filestore2/convert", array(), "op=transfer"), t("transfer any files from filestore to filestore2 that do not already exist in filestore2 database"));
-  $output .= form_item(t("change nodes"),l(t("change to filestore2"), "admin/system/modules/filestore2/convert", array(), "op=chgfs2"), t("change any filestore nodes to filestore2 that have been transferred to filestore2"));
-  $output .= form_item(t("back out conversion"),l(t("change to filestore"), "admin/system/modules/filestore2/convert", array(), "op=backout"), t("change any filestore2 nodes back to filestore that where moved."));
-  $output .= form_item(t("Remove files from filestore2"),l(t("delete transferred files"), "admin/system/modules/filestore2/convert", array(), "op=remove"), t("This process will delete any files that have been transferred to filestore2 from filestore."));
-  print theme("page", $output);
+  $form['transfer_files'] = array(
+    '#type' => 'item',
+    '#title' => t("Transfer files"),
+    '#default_value' => l(t("transfer"), "admin/system/modules/filestore2/convert", array(), "op=transfer"),
+    '#description' => t("transfer any files from filestore to filestore2 that do not already exist in filestore2 database"),
+  );
+  $form['change_nodes'] = array(
+    '#type' => 'item',
+    '#title' => t("change nodes"),
+    '#default_value' => l(t("change to filestore2"), "admin/system/modules/filestore2/convert", array(), "op=chgfs2"),
+    '#description' => t("change any filestore nodes to filestore2 that have been transferred to filestore2"),
+  );
+  $form['back_out_conversion'] = array(
+    '#type' => 'item',
+    '#title' => t("back out conversion"),
+    '#default_value' => l(t("change to filestore"), "admin/system/modules/filestore2/convert", array(), "op=backout"),
+    '#description' => t("change any filestore2 nodes back to filestore that where moved."),
+  );
+  $form['remove_files'] = array(
+    '#type' => 'item',
+    '#title' => t("Remove files from filestore2"),
+    '#default_value' => l(t("delete transferred files"), "admin/system/modules/filestore2/convert", array(), "op=remove"),
+    '#description' => t("This process will delete any files that have been transferred to filestore2 from filestore."),
+  );
+  $output = drupal_get_form('filestore2_convert', $form);
+  return $output;
 }
 
 /*
@@ -484,7 +581,6 @@
  */
 
 function filestore2_upload_validate(&$node, $required = TRUE, $store = TRUE, $field = "upload_file") {
-
   if (!$node->fsid || $node->fsid && $_FILES && ($_FILES["edit"]["error"][$field] != 4 || $_FILES["edit"]["error"][$field] == 4 && ($required && !$node->fsid))) {
     if ($_FILES["edit"]["error"][$field] == 0 && $_FILES["edit"]["size"][$field] > _filestore2_getmaxsize()) {
       $_FILES["edit"]["error"][$field] = 1;
@@ -517,7 +613,6 @@
   if ($store) {
     fscache_add_cache_info($node, $node->fsid);
   }
-  return;
 }
 
 function filestore2_form_init(&$form, $maxfilesize = 0) {
@@ -557,6 +652,7 @@
 
   $header = array("", array("data" => t("file"), "align" => "left"), array("data" => t("ver"), "align" => "left"), array("data" => t("dls"), "align" => "left"));
   $i=0;
+  $rows = array();
   while($fitem = db_fetch_object($result)) {
     $i++;
     $rows[] = array($i .".", l((strlen($fitem->filename) > 15 ? substr($fitem->filename, 0, 12) ."..." : $fitem->filename), "filestore2/download/$fitem->nid/$fitem->filename", array("title" => t('download %filename', array('%filename' => $fitem->filename)))), $fitem->version, $fitem->downloads);
@@ -631,4 +727,4 @@
     }
   }
 }
-?>
+?>
\ No newline at end of file
Index: TODO
===================================================================
RCS file: /cvs/drupal/contributions/modules/filestore2/TODO,v
retrieving revision 1.1
diff -u -r1.1 TODO
--- TODO	27 Jan 2004 21:22:29 -0000	1.1
+++ TODO	28 Jul 2006 09:04:05 -0000
@@ -1,4 +1,4 @@
-$Id: TODO,v 1.1 2004/01/27 21:22:29 gordon Exp $
+$Id: TODO,v 1.1 2006/05/26 15:17:52 sar Exp $
 
 Critical
 --------
Index: modules/filestore2/filestore2.install
===================================================================
RCS file: modules/filestore2/filestore2.install
diff -N modules/filestore2/filestore2.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/filestore2/filestore2.install	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * @file
+ * Update file for the filestore2 module.
+ */
+
+/**
+ * Implementation of hook_install().
+ */
+
+function filestore2_install() {
+  drupal_set_message('Installing filestore2');
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      db_query("CREATE TABLE `filestore2` (
+      `fid` int(11) unsigned NOT NULL default '0',
+      `nid` int(11) NOT NULL default '0',
+      `fsid` int(11) NOT NULL default '0',
+      `author` text NOT NULL,
+      `version` text NOT NULL,
+      `url` text NOT NULL,
+      `downloads` int(11) NOT NULL default '0',
+      PRIMARY KEY  (`fid`),
+      KEY `nid` (`nid`)
+    ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;
+      ");
+      $success = true;
+      break;
+
+    case 'pgsql':
+      break;
+  }
+  if ($success) {
+    drupal_set_message(t('filestore2 module installed tables successfully.'));
+  }
+  else {
+    drupal_set_message(t('The installation of the filestore2 module failed.'), 'error');
+  }
+}
+
+/*
+ * update module tables to UTF.
+ */
+function filestore2_update_1() {
+  return _system_update_utf8(array('filestore2'));
+}
+
+
+?>
