cvs diff: Diffing .
Index: signup.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.module,v
retrieving revision 1.205.2.10
diff -u -p -r1.205.2.10 signup.module
--- signup.module	19 Jan 2009 16:45:24 -0000	1.205.2.10
+++ signup.module	21 Jan 2009 02:27:14 -0000
@@ -151,28 +151,6 @@ function signup_theme() {
         'node' => NULL,
       ),
     ),
-    'signup_current_signup' => array(
-      'file' => 'node.inc',
-      'path' => $path,
-      'arguments' => array(
-        'signup_data' => NULL,
-        'cancel_signup_form' => '',
-      ),
-    ),
-    'signup_custom_data_table' => array(
-      'file' => 'node.inc',
-      'path' => $path,
-      'arguments' => array(
-        'data' => NULL,
-      ),
-    ),
-    'signup_custom_data_rows' => array(
-      'file' => 'node.inc',
-      'path' => $path,
-      'arguments' => array(
-        'data' => NULL,
-      ),
-    ),
     'signup_user_form' => array(
       'file' => 'signup_form.inc',
       'path' => $path,
@@ -350,6 +328,16 @@ function signup_menu() {
     'file' => 'signup_cancel.inc',
     'file path' => $path,
   );
+  $items['signup/edit/%signup_menu'] = array(
+    'title' => 'Edit signup',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('signup_edit_form', 2),
+    'access callback' => '_signup_edit_menu_access',
+    'access arguments' => array(2),
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'signup_edit_form.inc',
+    'file path' => $path,
+  );
 
   $items['admin/content/signup'] = array(
     'description' => 'View all signup-enabled posts, and open or close signups on them.',
@@ -509,6 +497,33 @@ function _signup_user_menu_access($accou
 }
 
 /**
+ * Menu loader callback to load a project node.
+ */
+function signup_menu_load($sid) {
+  if (!is_numeric($sid)) {
+    return FALSE;
+  }
+  $signup = signup_load_signup($sid);
+  if (empty($signup)) {
+    return FALSE;
+  }
+  return $signup;
+}
+
+function _signup_edit_menu_access($signup) {
+  global $user;
+  if (user_access('edit own signups') && !empty($user->uid) && ($user->uid == $signup->uid)) {
+    return TRUE;
+  }
+  // Check admin powers for this signup.
+  $node = node_load($signup->nid);
+  if (_signup_menu_access($node, 'admin')) {
+    return TRUE;
+  }
+  return FALSE;
+}
+
+/**
  * Menu callback to handle the default tab at node/N/signups
  *
  * This tests the user's permission to see what tab they should really see.
@@ -567,6 +582,7 @@ function signup_perm() {
     'sign up for content',
     'cancel signups',
     'cancel own signups',
+    'edit own signups',
     'view all signups',
     'administer all signups',
     'administer signups for own content',
@@ -857,8 +873,10 @@ function signup_object_info() {
  */ 
 function signup_load_signup($sid) {
   $signup = db_fetch_object(db_query("SELECT sl.*, n.title, u.name FROM {signup_log} sl INNER JOIN {node} n ON sl.nid = n.nid INNER JOIN {users} u ON sl.uid = u.uid WHERE sl.sid = %d", $sid));
-  // This label is escaped by VBO, so it needs to be plain text, not HTML.
-  $signup->label = t("!user signup for '!title'", array('!user' => $signup->name, '!title' => $signup->title));
+  if (!empty($signup)) {
+    // This label is escaped by VBO, so it needs to be plain text, not HTML.
+    $signup->label = t("!user signup for '!title'", array('!user' => $signup->name, '!title' => $signup->title));
+  }
   return $signup;
 }
 
cvs diff: Diffing includes
Index: includes/node_output.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/includes/node_output.inc,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 node_output.inc
--- includes/node_output.inc	14 Jan 2009 18:11:21 -0000	1.1.2.4
+++ includes/node_output.inc	21 Jan 2009 02:27:14 -0000
@@ -40,6 +40,7 @@ function _signup_node_output($node, $typ
 function _signup_current_user_signup($node, $type = 'node') {
   global $user;
   $output = '';
+  $fieldset = $type == 'node' ? TRUE : FALSE;
   // The node has been closed for signups, and the user has
   // signup permissions.  Let them know it's closed.
   if (!$node->signup_status) {
@@ -48,17 +49,16 @@ function _signup_current_user_signup($no
       // If they're logged in and already signed up, show their current
       // signup info and give them the option to cancel.
       if ($user->uid) {
-        $result = db_query("SELECT * FROM {signup_log} WHERE uid = %d AND nid = %d", $user->uid, $node->nid);
-        $signup_info = db_fetch_object($result);
-        if (!empty($signup_info)) {
-          $current_signup = _signup_print_current_signup($node, $signup_info);
+        $signup = db_fetch_object(db_query("SELECT sl.*, n.title, u.name FROM {signup_log} sl INNER JOIN {node} n ON sl.nid = n.nid INNER JOIN {users} u ON sl.uid = u.uid WHERE sl.uid = %d AND sl.nid = %d", $user->uid, $node->nid));
+        if (!empty($signup)) {
+          module_load_include('inc', 'signup', 'includes/signup_edit_form');
+          $output .= drupal_get_form('signup_edit_form', $signup, $fieldset);
         }
       }
       $output .= theme('signup_signups_closed', $node, $current_signup);
     }
   }
   else {
-    $fieldset = $type == 'node' ? TRUE : FALSE;
     if ($user->uid == 0) {
       // This is an anonymous user.
       if (user_access('sign up for content')) {
@@ -91,9 +91,8 @@ function _signup_current_user_signup($no
       // An authenticated user.
 
       // See if the user is already signed up for this node.
-      $result = db_query("SELECT * FROM {signup_log} WHERE uid = %d AND nid = %d", $user->uid, $node->nid);
-      $signup_info = db_fetch_object($result);
-      if (empty($signup_info)) {
+      $signup = db_fetch_object(db_query("SELECT sl.*, n.title, u.name FROM {signup_log} sl INNER JOIN {node} n ON sl.nid = n.nid INNER JOIN {users} u ON sl.uid = u.uid WHERE sl.uid = %d AND sl.nid = %d", $user->uid, $node->nid));
+      if (empty($signup)) {
         // Not yet signed up
         if (user_access('sign up for content')) {
           // User has permission to do so, so give them the form.
@@ -103,7 +102,8 @@ function _signup_current_user_signup($no
       }
       else {
         // Already signed up, display their info.
-        $output .= _signup_print_current_signup($node, $signup_info);
+        module_load_include('inc', 'signup', 'includes/signup_edit_form');
+        $output .= drupal_get_form('signup_edit_form', $signup, $fieldset);
       }
     }
   }
@@ -171,38 +171,3 @@ function signup_node_tab($node) {
   drupal_set_title(check_plain($node->title));
   return _signup_node_output($node, 'tab');
 }
-
-/**
- * Helper function to display the current user's signup information.
- *
- * Contains the logic to determine what should be displayed, then invokes the
- * appropriate form builder and theme functions.
- *
- * @param $node
- *   The fully-loaded node object to display signup data about.
- * @param $signup_info
- *   Database object with information about the signup to display.
- *
- * @return
- *   Themed HTML to output for the given node and signup.
- *
- * @see theme_signup_current_signup()
- */
-function _signup_print_current_signup($node, $signup_info) {
-  // Generate an array of data about the current signup for the theme function.
-  $signup_data = array();
-  $signup_data['custom_data'] = unserialize($signup_info->form_data);
-  $signup_data['signup_timestamp'] = $signup_info->signup_time;
-
-  // See if the current user is allowed to cancel their signup, and if so,
-  // render the HTML for the cancel form (which is just a single button).
-  $cancel_signup_form = '';
-  if (user_access('cancel own signups')) {
-    module_load_include('inc', 'signup', 'includes/signup_cancel_form');
-    $cancel_signup_form = drupal_get_form('signup_cancel_form', $signup_info->sid);
-  }
-
-  // Hand off everything to the theme function for actual HTML generation.
-  return theme('signup_current_signup', $signup_data, $cancel_signup_form);
-}
-
Index: includes/signup_cancel_form.inc
===================================================================
RCS file: includes/signup_cancel_form.inc
diff -N includes/signup_cancel_form.inc
--- includes/signup_cancel_form.inc	19 Dec 2008 01:00:35 -0000	1.1.2.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,35 +0,0 @@
-<?php
-// $Id: signup_cancel_form.inc,v 1.1.2.1 2008/12/19 01:00:35 dww Exp $
-
-
-/**
- * @file
- * Code for the signup cancel form.
- */
-
-/**
- * Submit handler for the cancel signup form.
- *
- * @param $form
- *   The form being submitted.
- * @param $form_state
- *   The state of the submitted form, including the values.
- */
-function signup_cancel_form_submit($form, &$form_state) {
-  signup_cancel_signup($form_state['values']['sid']);
-}
-
-/**
- * Form builder for the cancel signup form.
- *
- * @param $form_state
- *   The form state from the FormAPI.
- * @param $sid
- *   The signup ID (sid) to cancel (primary key of the {signup_log} table).
- */
-function signup_cancel_form(&$form_state, $sid) {
-  $form['sid'] = array('#type' => 'value', '#value' => $sid);
-  $form['submit'] = array('#type' => 'submit', '#value' => t('Cancel signup'));
-  return $form;
-}
-
Index: includes/signup_edit_form.inc
===================================================================
RCS file: includes/signup_edit_form.inc
diff -N includes/signup_edit_form.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ includes/signup_edit_form.inc	21 Jan 2009 02:27:14 -0000
@@ -0,0 +1,119 @@
+<?php
+// $Id$
+
+
+/**
+ * @file
+ * Code for the form to edit existing signups.
+ */
+
+/**
+ * Build the form for editing existing signups.
+ *
+ * @param $form_state
+ *   The state of the form to build (not currently used).
+ * @param $signup
+ *   The fully-loaded signup object with data about the signup to edit.
+ * @param $fieldset
+ *   Optional boolean to indicate if the signup edit form should be enclosed
+ *   in a fieldset.
+ */
+function signup_edit_form($form_state, $signup, $fieldset = FALSE) {
+  global $user;
+  $form = array();
+
+  $form['#signup'] = $signup;
+  $node = node_load($signup->nid);
+
+  // Check permissions.
+  $admin = _signup_menu_access($node, 'admin');
+  $own = !empty($user->uid) && $user->uid == $signup->uid;
+  $can_cancel = $admin || (user_access('cancel own signups') && $own);
+  $can_edit = $admin || (user_access('edit own signups') && $own);
+
+  // TODO: This is not quite right if someone navigates to signup/edit/[sid]
+  // for one of their own signups.
+  $title = $own ? t('Your signup information') : t('Signup information for %user for %title', array('%user' => theme(''), '%title' => $node->title));
+
+  if ($fieldset) {
+    $form['fieldset'] = array(
+      '#type' => 'fieldset',
+      '#title' => $title,
+      '#collapsible' => TRUE,
+      '#collapsed' => variable_get('signup_fieldset_collapsed', 1),
+    );
+  }
+  else {
+    $form['fieldset'] = array();
+    $form['fieldset']['header'] = array(
+      '#type' => 'markup',
+      '#value' => $title,
+      '#prefix' => '<h4>',
+      '#suffix' => '</h4>',
+    );
+  }
+
+  // Build the themed signup form for this site and include that.
+  $site_form = theme('signup_user_form', $node);
+  $form_data = unserialize($signup->form_data);
+
+  // This is sort of a hack, but we don't support nested arrays for the custom
+  // signup form anyway, so it works for now.  Obviously all this will change
+  // with signup_fields and friends, but for now it works.
+  foreach ($form_data as $key => $value) {
+    if (!empty($site_form['signup_form_data'][$key])) {
+      $site_form['signup_form_data'][$key]['#default_value'] = $value;
+      if (!$can_edit) {
+        // If they can't edit, mark all the fields as disabled.
+        $site_form['signup_form_data'][$key]['#disabled'] = TRUE;
+        // Also, remove the required attribute from all fields (so that the
+        // cancel button, if it exists, will work).
+        $site_form['signup_form_data'][$key]['#required'] = FALSE;
+      }
+    }
+  }
+  $form['fieldset'] += $site_form;
+
+  if ($can_edit) {
+    $form['fieldset']['update'] = array(
+      '#type' => 'submit',
+      '#value' => t('Update'),
+      '#submit' => array('signup_edit_form_update_submit'),
+    );
+  }
+
+  if ($can_cancel) {
+    $form['fieldset']['cancel'] = array(
+      '#type' => 'submit',
+      '#value' => t('Cancel signup'),
+      '#submit' => array('signup_edit_form_cancel_submit'),
+    );
+  }
+  return $form;
+}
+
+/**
+ * Submit callback when updating an existing signup.
+ */
+function signup_edit_form_update_submit($form, $form_state) {
+  $signup_info = array();
+  if (!empty($form_state['values']['signup_form_data'])) {
+    $signup_info = $form_state['values']['signup_form_data'];
+  }
+  /// @TODO invoke a hook?
+  /// @TODO should we have a "signup_update_time" field and update that, too?
+  db_query("UPDATE {signup_log} SET form_data = '%s' WHERE sid = %d", serialize($signup_info), $form['#signup']->sid);
+  drupal_set_message(t('Updated signup information'));
+}
+
+/**
+ * Submit callback to cancel the signup when editing an existing signup.
+ */
+function signup_edit_form_cancel_submit($form, &$form_state) {
+  signup_cancel_signup($form['#signup']->sid);
+  if (empty($_REQUEST['destination'])) {
+    // If there's no destination already set, redirect to the node.
+    $form_state['redirect'] = 'node/'. $form['#signup']->nid;
+  }
+}
+
cvs diff: Diffing js
cvs diff: Diffing panels
cvs diff: Diffing panels/content_types
cvs diff: Diffing theme
Index: theme/node.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/theme/node.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 node.inc
--- theme/node.inc	7 Jan 2009 00:55:05 -0000	1.1.2.1
+++ theme/node.inc	21 Jan 2009 02:27:14 -0000
@@ -58,81 +58,3 @@ function theme_signup_anonymous_user_log
 function theme_signup_node_output_header($node) {
   return '<a name="signup"></a>';
 }
-
-/**
- * Controls the output of the users signup data and optional cancel button.
- *
- * @param $signup_data
- *   Array containing information about the user's signup.  Contains:
- *   'signup_timestamp' - Integer timestamp when the user signed up.
- *   'custom_data' - Array containing the user's custom signup data.
- * @param $cancel_signup_form
- *   Optional HTML for a "Cancel signup" button if the user is allowed.
- *
- * @return
- *   Themed output containing the user's current signup information.
- */
-function theme_signup_current_signup($signup_data, $cancel_signup_form = '') {
-  $output = theme('signup_custom_data_table', $signup_data['custom_data']);
-  $output .= $cancel_signup_form;
-  return $output;
-}
-
-/**
- * Renders custom signup user data into a table.
- *
- * @param $data
- *   Array of custom user signup data.
- *
- * @return
- *   The themed table with custom signup user data.
- *
- * @see theme_signup_user_form()
- */
-function theme_signup_custom_data_table($data) {
-  $output = '';
-  if (is_array($data)) {
-    $header = array(array('data' => t('Your signup information'), 'colspan' => 2));
-    $rows = theme('signup_custom_data_rows', $data);
-    $output .= theme('table', $header, $rows);
-  }
-  return $output;
-}
-
-/**
- * Renders custom signup user data into table rows.
- *
- * WARNING: This theme function is recursive (it calls itself for
- * nested data), so if you override it, be sure not to change the part
- * where it does "call_user_func(__FUNCTION__)".
- *
- * @param $data
- *   Array of custom user signup data.
- *
- * @return
- *   An array of table rows.
- *
- * @see theme_signup_user_form()
- */
-function theme_signup_custom_data_rows($data) {
-  $rows = array();
-  // All of the possible array key values should already be translated as
-  // string literals in theme_signup_user_form() via the #title attributes, so
-  // passing a variable to t() is actually safe here.  However, to avoid
-  // warnings when extracting strings, "hide" the call to t() by using a
-  // variable to hold the function name.
-  $tr = 't';
-  // Loop through each first level element.
-  foreach ($data as $key => $value) {
-    if (is_array($value)) {
-      // Element is nested, render it recursively.
-      // Instead of the overhead of theme(), just call ourself directly.
-      $rows += call_user_func(__FUNCTION__, $value);
-    }
-    else {
-      $rows[] = array($tr($key) .':', check_plain($value));
-    }
-  }
-  return $rows;
-}
-
cvs diff: Diffing translations
cvs diff: Diffing views
Index: views/signup.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/views/signup.views.inc,v
retrieving revision 1.4.2.5
diff -u -p -r1.4.2.5 signup.views.inc
--- views/signup.views.inc	14 Jan 2009 17:36:18 -0000	1.4.2.5
+++ views/signup.views.inc	21 Jan 2009 02:27:14 -0000
@@ -274,6 +274,14 @@ function signup_views_data() {
     ),
   );
 
+  $data['signup_log']['edit_link'] = array(
+    'title' => t('User: Edit signup link'),
+    'field' => array(
+      'handler' => 'signup_handler_field_signup_edit_link',
+      'help' => t('Link to edit this particular signup.'),
+    ),
+  );
+
   return $data;
 }
 
@@ -292,6 +300,9 @@ function signup_views_handlers() {
       'signup_handler_argument_signup_user_uid' => array(
         'parent' => 'views_handler_argument_numeric',
       ),
+      'signup_handler_field_signup_edit_link' => array(
+        'parent' => 'views_handler_field_node_link',
+      ),
       'signup_handler_field_signup_node_link' => array(
         'parent' => 'views_handler_field_node_link',
       ),
cvs diff: Diffing views/handlers
Index: views/handlers/signup_handler_field_signup_edit_link.inc
===================================================================
RCS file: views/handlers/signup_handler_field_signup_edit_link.inc
diff -N views/handlers/signup_handler_field_signup_edit_link.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ views/handlers/signup_handler_field_signup_edit_link.inc	21 Jan 2009 02:27:15 -0000
@@ -0,0 +1,33 @@
+<?php
+// $Id$
+
+/**
+ * Field handler to generate a link to edit a given signup.
+ */
+class signup_handler_field_signup_edit_link extends views_handler_field_node_link {
+  function construct() {
+    parent::construct();
+    $this->additional_fields['sid'] = array('table' => 'signup_log', 'field' => 'sid');
+    $this->additional_fields['uid'] = array('table' => 'signup_log', 'field' => 'uid');
+  }
+
+  function render($values) {
+    global $user;
+
+    // Check access to edit this signup.
+    $signup = new StdClass();
+    $signup->sid = $values->{$this->aliases['sid']};
+    $signup->nid = $values->{$this->aliases['nid']};
+    $signup->uid = $values->{$this->aliases['uid']};
+    if (!_signup_edit_menu_access($signup)) {
+      return;
+    }
+
+    // If we made it this far, generate the actual link.
+    $text = !empty($this->options['text']) ? $this->options['text'] : t('Edit signup');
+    $url = "signup/edit/$signup->sid";
+    $link_options['query'] = drupal_get_destination();
+    return l($text, $url, $link_options);
+  }
+}
+
cvs diff: Diffing views/plugins
