Index: captcha.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/Attic/captcha.module,v
retrieving revision 1.42.2.43
diff -u -u -p -r1.42.2.43 captcha.module
--- captcha.module	7 Jan 2008 12:56:26 -0000	1.42.2.43
+++ captcha.module	3 Feb 2008 16:07:42 -0000
@@ -82,6 +82,13 @@ function captcha_menu($may_cache) {
       'type' => MENU_LOCAL_TASK,
       'weight' => 5,
     );
+    $items[] = array(
+      'path' => 'admin/user/captcha/add',
+      'title' => t('Add a CAPTCHA point'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('captcha_captcha_point_settings_form'),
+      'type' => MENU_CALLBACK,
+    );
   }
   return $items;
 }
@@ -177,8 +184,6 @@ function captcha_admin($form_id='', $op=
         drupal_goto('admin/user/captcha');
         break;
       case 'enable':
-        db_query("DELETE FROM {captcha_points} WHERE form_id = '%s'", $form_id);
-        db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, NULL)", $form_id);
         // No drupal_goto() call because we have to go to the CAPTCHA administration
         // form and not a different destination if that would be present in the
         // URI. So we call this form explicitly. The destination will be preserved
@@ -208,7 +213,9 @@ function captcha_admin_settings() {
   $form['captcha_types'] = array(
     '#type' => 'fieldset',
     '#title' => t('Challenge type per form'),
-    '#description' => t('Select the challenge type you want for each of the listed forms (identified by their so called <em>form_id</em>\'s). You can easily add arbitrary forms with the help of the \'%CAPTCHA_admin_links\' option.', array('%CAPTCHA_admin_links'=>t('Add CAPTCHA administration links to forms'))),
+    '#description' => t('Select the challenge type you want for each of the listed forms (identified by their so called <em>form_id</em>\'s). You can easily add arbitrary forms with the help of the \'%CAPTCHA_admin_links\' option or the <a href="!add_captcha_point">add CAPTCHA point form</a>.',
+      array('%CAPTCHA_admin_links' => t('Add CAPTCHA administration links to forms'),
+        '!add_captcha_point' => url('admin/user/captcha/add'))),
     '#tree' => TRUE,
     '#collapsible' => TRUE,
     '#collapsed' => FALSE,
@@ -337,39 +344,60 @@ function captcha_admin_settings_submit($
 /**
  * form generating function for CAPTCHA point settings
  */
-function captcha_captcha_point_settings_form($form_id) {
-  $result = db_query("SELECT * FROM {captcha_points} WHERE form_id = '%s'", $form_id);
-  $captcha_point = db_fetch_object($result);
-  if ($captcha_point) {
-    $form = array();
+function captcha_captcha_point_settings_form($form_id=NULL) {
+  $form = array();
+  if (isset($form_id)) {
     $form['captcha_point_form_id'] = array(
-      '#type' => 'hidden',
-      '#value' => $captcha_point->form_id,
-    );
-    // select widget for CAPTCHA type
-    $form['captcha_type'] = array(
-      '#type' => 'select',
-      '#title' => t('Select the challenge for @form_id', array('@form_id' => $form_id)),
-      '#default_value' => "{$captcha_point->module}/{$captcha_point->type}",
-      '#options' => _captcha_available_challenge_types(),
-    );
-    // submit button
-    $form['submit'] = array(
-      '#type' => 'submit',
-      '#value' => t('Submit'),
-    );
-    // cancel button
-    $form['cancel'] = array(
-      '#type' => 'submit',
-      '#value' => t('Cancel'),
+      '#type' => 'textfield',
+      '#title' => t('Form ID'),
+      '#description' => t('The Drupal form_id of the form to add the CAPTCHA to.'),
+      '#value' => check_plain($form_id),
+      '#disabled' => TRUE,
     );
-    return $form;
+    $result = db_query("SELECT * FROM {captcha_points} WHERE form_id = '%s'", $form_id);
+    $captcha_point = db_fetch_object($result);
+    if ($captcha_point) {
+      $default_value = "{$captcha_point->module}/{$captcha_point->type}";
+    }
+    else {
+      $default_value = '<'. t('none') .'>';
+    }
   }
   else {
-    // illegal form_id
-    drupal_set_message(t('Unavailable form_id %form_id ', array('%form_id' => $form_id)), 'error');
-    // goto the CAPTCHA administration or alternative destination if present in URI
-    drupal_goto('admin/user/captcha');
+    $form['captcha_point_form_id'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Form ID'),
+      '#description' => t('The Drupal form_id of the form to add the CAPTCHA to.'),
+    );
+  }
+  // select widget for CAPTCHA type
+  $form['captcha_type'] = array(
+    '#type' => 'select',
+    '#title' => t('Challenge type'),
+    '#description' => t('The CAPTCHA type to use for this form'),
+    '#default_value' => $default_value,
+    '#options' => _captcha_available_challenge_types(),
+  );
+  $form['#redirect'] = 'admin/user/captcha';
+  // submit button
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Submit'),
+  );
+  // cancel button
+  $form['cancel'] = array(
+    '#type' => 'submit',
+    '#value' => t('Cancel'),
+  );
+  return $form;
+}
+
+/**
+ * validation function for captcha_captcha_point_settings_form
+ */
+function captcha_captcha_point_settings_form_validate($form_id, $form_values) {
+  if (!preg_match('/^[a-z_]+$/', $form_values['captcha_point_form_id'])) {
+    form_set_error('captcha_point_form_id', t('Illegal form_id'));
   }
 }
 
@@ -380,12 +408,13 @@ function captcha_captcha_point_settings_
   if ($form_id == 'captcha_captcha_point_settings_form' && $form_values['op'] == t('Submit')) {
     $captcha_point_form_id = $form_values['captcha_point_form_id'];
     $captcha_type = $form_values['captcha_type'];
+    db_query("DELETE FROM {captcha_points} WHERE form_id = '%s'", $captcha_point_form_id);
     if ($captcha_type == 'none') {
-      db_query("UPDATE {captcha_points} SET module = NULL, type = NULL WHERE form_id = '%s'", $captcha_point_form_id);
+      db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, NULL)", $captcha_point_form_id);
     }
     else {
       list($module, $type) = explode('/', $captcha_type);
-      db_query("UPDATE {captcha_points} SET module = '%s', type = '%s' WHERE form_id = '%s'", $module, $type, $captcha_point_form_id);
+      db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', '%s', '%s')", $captcha_point_form_id, $module, $type);
     }
     drupal_set_message(t('Saved CAPTCHA settings.'), 'status');
   }
