Index: modules/ecommerce/file/file.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/ecommerce/file/file.module,v
retrieving revision 1.37.2.7
diff -u -r1.37.2.7 file.module
--- modules/ecommerce/file/file.module	2 Oct 2006 00:33:20 -0000	1.37.2.7
+++ modules/ecommerce/file/file.module	20 Nov 2006 12:55:16 -0000
@@ -25,18 +25,24 @@
   $items  = array();
   $access = user_access('administer store');
 
+  // Get the User ID of the current logged-in user into uid
   global $user;
-
   $uid = $user->uid;
+  // Users with administer store access can override uid from the menu
+  // TODO: Check this. Menu items must always make this arg(2)
   if ($access) {
     if (arg(2) > 0) {
       $uid = arg(2);
     }
   }
+  // TODO: Check this. Currently ignores passed uid if non-admins specify another user
+  // Is this behaviour intended? Maybe should drupal_access_denied() instead?
 
   if ($may_cache) {
-
+    // Set cacheable menu items
     if ($user->uid) {
+      // Menu items only available if user is logged in
+      // TODO: Check this. Why isn't this also available to admins?
       $items[] = array('path' => 'ec_file/autocomplete', 'title' => t('file autocomplete'),
                        'callback' => 'ec_file_autocomplete', 'access' => $access, 'type' => MENU_CALLBACK);
 
@@ -49,10 +55,14 @@
                        'type' => MENU_CALLBACK);
     }
 
+    // Set menu item available to all users
     $items[] = array('path' => 'admin/store/products/files', 'title' => t('product file quicklist'),
         'callback' => 'file_quicklist', 'access' => $access, 'type' => MENU_CALLBACK);
   }
   else {
+    // Set uncacheable menu items
+    // Show my expired files
+    // (Presumably this is not cacheable since the file could expire at any time?)
     $items[] = array('path' => "store/myfiles/$uid/expired", 'title' => t('expired'),
                      'callback' => 'file_my_expired', 'access' => user_access('access content'),
                      'type' => MENU_LOCAL_TASK);
@@ -82,6 +92,7 @@
     return user_access('create file products');
   }
 
+  // Users with "edit own" permission can update or delete own products
   if ($op == 'update' || $op == 'delete') {
     if (user_access('edit own file products') && ($user->uid == $node->uid)) {
       return TRUE;
@@ -91,6 +102,46 @@
 
 /**
  * Implementation of the productapi_hook()
+ *
+ * @param &$node
+ *   The node object for the product.
+ * @param $op
+ *   What kind of action is being performed.  Implemented operations:
+ *   - "fields":
+ *       Return associative array of field => value pairs
+ *   - "validate":
+ *       Validate node as a submitted form.
+ *   - "wizard_select":
+ *       Return an associated array of product types as ptype => description provided by the module.
+ *   - "attributes":
+ *       Return possible attributes for the product (for files: "in_stock")
+ *   - "form":
+ *       Return a form structure (??to specify a product??)
+ *
+ *   - "cart add item":  called when trying to add a product to a shopping cart.  This
+ *     allows the product to limit the addition of items.  This is optional as a null
+ *     return will be treated as true and the item will be added.
+ *   - "adjust_price": called to provide a price adjustment to the product.  No changes
+ *      to node->price should be made.
+ *   -  "transaction": I can only guess.  the only place I see this is coupon.module
+ *   -  "on payment completion": called on payment completion
+ *   -  "subproduct_types": called by subproduct to get a list of supported subproducts
+ * @param $arg3
+ *   The "adjust_price" operation passes a current price here.
+ *   Possible values for attributes operation:
+ *   - "in_stock"
+ * @param $arg4
+ * @return
+ *   This value varies depending on the operation.
+ *   - The "wizard_select" operation should return an array of product types provided by
+ *     the module.  The key should uniquely identify the type and the value should be a
+  *     translated description.
+ *   - The "cart add item" operation should return a bool value.  True or NULL will add
+ *     to cart and false will redirect.  You must provide you own drupal_set_message
+ *     failure message.
+ *   - The "ajust_price" operation returns a new price.
+ *   - The 'insert'
+ *
  */
 function file_productapi(&$node, $op, $a3 = null, $a4 = null) {
 
@@ -149,12 +200,12 @@
         }
         else {
           $description = t('Enter the filesystem path to this file (not the URL). This path will be prefixed with <b>%file_path</b> Here is a <a href="%file_quicklist" onclick="window.open(this.href, \'%file_quicklist\', \'width=480,height=480,scrollbars=yes,status=yes\'); return false">list of files</a> in this directory. You may need to FTP your file to this directory before you can create the file product.', array('%file_quicklist' => url('admin/store/products/files'), '%file_path' => ec_file_create_path()));
-          $attribues = NULL;
+          $attributes = NULL;
         }
         $form['f_settings']['fpath'] = array(
           '#type' => 'textfield',
           '#title' => t('File path'),
-          '#default_value' => $node->fpath,
+          '#default_value' => isset($node->fpath) ? $node->fpath : NULL,
           '#size' => 50,
           '#maxlength' => 200,
           '#autocomplete_path' => 'ec_file/autocomplete',
@@ -342,6 +393,8 @@
   }
 
   // Check 2: Check for multi products that contain file downloads.
+ // Parcel module is optional: we shouldn't do this if it is not enabled
+ if (module_exist('parcel')) {
   $result = db_query('SELECT st.created, st.expires, stp.title, pp.mnid, p.nid FROM {ec_transaction} AS st, {users} AS u, {ec_product} AS p, {ec_product_parcel} AS pp, {ec_transaction_product} AS stp WHERE u.uid = st.uid AND st.uid = %d AND p.nid = stp.nid AND st.txnid = stp.txnid AND pp.nid = p.nid AND st.payment_status = 2'. tablesort_sql($header), $uid);
   while ($data = db_fetch_object($result)) {
     // Load each individual product and determine if it's a file download.
@@ -371,7 +424,10 @@
       }
     }
   }
-  $output .= ($rows) ? theme('table', $header, $rows) : t('You have no files to download.');
+ } // End [if parcel module enabled]
+
+  // Create a table of the rows, or a suitable message if none
+  $output .= !empty($rows) ? theme('table', $header, $rows) : t('You have no files to download.');
 
   return $output;
 }
@@ -435,7 +491,8 @@
     return $dest;
   }
   // check if the destination is instead inside the Drupal temporary files directory.
-  else if (file_check_location($dest, variable_get('file_directory_temp', FILE_DIRECTORY_TEMP))) {
+  // Following used to use FILE_DIRECTORY_TEMP, but that is not defined  (in Drupal 4.7, at least)
+  else if (file_check_location($dest, file_directory_temp())) {
     return $dest;
   }
   // Not found, try again with prefixed dirctory path.
