Index: modules/project_issue/pi_contact.info =================================================================== RCS file: modules/project_issue/pi_contact.info diff -N modules/project_issue/pi_contact.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/project_issue/pi_contact.info 24 Jan 2007 07:30:17 -0000 @@ -0,0 +1,6 @@ +; $Id$ +name = Project issue contact integration +description = Allows the site-wide contact tab to optionally generate project issues instead of emails. +dependencies = contact project project_issue +package = Project +version = "$Name$" Index: modules/project_issue/pi_contact.install =================================================================== RCS file: modules/project_issue/pi_contact.install diff -N modules/project_issue/pi_contact.install --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/project_issue/pi_contact.install 24 Jan 2007 07:30:17 -0000 @@ -0,0 +1,35 @@ + 'fieldset', + '#title' => t('Issue queue integration'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + if (arg(3) == "edit" && ($cid = arg(4)) && $cid > 0) { + $defaults = db_fetch_array(db_query("SELECT * FROM {pi_contact} WHERE cid = %d", $cid)); + $default_state = variable_get('project_issue_default_state', 1); + $uris = NULL; + $projects = array(t('')) + project_projects_select_options($uris); + if (isset($defaults['pid'])) { + $project = node_load(array('nid' => $defaults['pid'], 'type' => 'project_project')); + } + $components = array(); + if (!empty($project->components)) { + $components = array(t('')); + foreach ($project->components as $component) { + $component = check_plain($component); + $components[$component] = $component; + } + } + if (module_exists('project_release') && isset($project) && + $releases = project_release_get_releases($project, 0)) { + $releases = array(t('')) + $releases; + } + $categories = array_merge(array(t('')), project_issue_category(0, 0)); + $priorities = project_issue_priority(); + $states = project_issue_state(); + + // Add the appropriate description to the fieldset. Since we're + // editing an existing contact category, the issue settings are valid. + $form['issues']['#description'] = t('Optionally define an issue queue where issues should be created whenever a user submits a contact form for this category. If the %project setting is set to %none, no issue will be generated and the other settings are ignored. However, if you select a %project, the other settings determine the values to use the corresponding fields in the issue creation form when users use this contact category.', array('%project' => t('Project'), '%none' => t(''))); + + $form['issues']['pid'] = array( + '#type' => 'select', + '#title' => t('Project'), + '#default_value' => isset($defaults['pid']) ? $defaults['pid'] : 0, + '#options' => $projects, + ); + if (!empty($components)) { + $form['issues']['component'] = array( + '#type' => 'select', + '#title' => t('Component'), + '#default_value' => isset($defaults['component']) ? $defaults['component'] : 0, + '#options' => $components, + ); + } + if (!empty($releases)) { + $form['issues']['rid'] = array( + '#type' => 'select', + '#title' => t('Version'), + '#default_value' => isset($defaults['rid']) ? $defaults['rid'] : 0, + '#options' => $releases, + ); + } + $form['issues']['issue_category'] = array( + '#type' => 'select', + '#title' => t('Issue category'), + '#default_value' => isset($defaults['category']) ? $defaults['category'] : 'support', + '#options' => $categories, + ); + $form['issues']['priority'] = array( + '#type' => 'select', + '#title' => t('Priority'), + '#default_value' => isset($defaults['priority']) ? $defaults['priority'] : 2, + '#options' => $priorities, + ); + if (count($states) > 1) { + $form['issues']['sid'] = array( + '#type' => 'select', + '#title' => t('Status'), + '#default_value' => isset($defaults['sid']) ? $defaults['sid'] : $default_state, + '#options' => $states, + ); + } + else { + $form['issues']['sid'] = array( + '#type' => 'hidden', + '#value' => $default_state, + ); + $form['issues']['status'] = array( + '#type' => 'item', + '#title' => t('Status'), + '#value' => project_issue_state($default_state), + ); + } + $form['#validate']['pi_contact_admin_edit_validate'] = array(); + $form['#submit']['pi_contact_admin_edit_submit'] = array(); + } + else { + // Add the appropriate description to the fieldset. Since we're + // not going to know the cid until the category is added, we + // currently don't present any of the settings on the add form. + /// @todo This is lame! + $form['issues']['#description'] = t('You can only configure issue queue integration once you have created the contact tab initially. After submitting this form, you can click on the %edit link and new settings will be present here.', array('%edit' => t('edit'))); + } + $form['submit']['#weight'] = 10; +} + +/** + * Validation handler for contact admin form. + * + * @todo !!! + * + */ +function pi_contact_admin_edit_validate($form_id, $form_values) { +} + +/** + * Submit handler for contact admin form. Deletes, updates, or inserts + * records into the {pi_contact} table as approriate. + */ +function pi_contact_admin_edit_submit($form_id, $form_values) { + if ($form_values['pid'] == 0) { + db_query("DELETE FROM {pi_contact} WHERE cid = %d", $form_values['cid']); + } + else if (arg(3) != 'add' && db_num_rows(db_query("SELECT * from {pi_contact} WHERE cid = %d", $form_values['cid']))) { + db_query("UPDATE {pi_contact} SET pid = %d, rid = %d, category = '%s', component = '%s', priority = %d, sid = %d WHERE cid = %d", $form_values['pid'], $form_values['rid'], $form_values['issue_category'], $form_values['component'], $form_values['priority'], $form_values['sid'], $form_values['cid']); + drupal_set_message(t('Category %category issue queue settings modified.', array('%category' => $form_values['category']))); + } + else if (!empty($form_values['cid'])) { + db_query("INSERT INTO {pi_contact} (cid, pid, rid, category, component, priority, sid) VALUES (%d, %d, %d, '%s', '%s', %d, %d)", $form_values['cid'], $form_values['pid'], $form_values['rid'], $form_values['issue_category'], $form_values['component'], $form_values['priority'], $form_values['sid']); + drupal_set_message(t('Category %category configured to create issues when users fill out the contact form.', array('%category' => $form_values['category']))); + } +} + + +/** + * Alters the confirmation form for deleting a contact tab to add + * another submit handler. + */ +function pi_contact_alter_delete_form($form_id, &$form) { + $form['#submit']['pi_contact_delete_submit'] = array(); +} + +/** + * Submit handler for contact tab delete form that cleans out the + * appropriate record from the {pi_contact} table. + */ +function pi_contact_delete_submit($form_id, $form_values) { + db_query("DELETE FROM {pi_contact} WHERE cid = %d", arg(4)); +} + +function pi_contact_alter_mail_page_form($form_id, &$form) { + // for debugging only + unset($form['#submit']); + $form['#submit']['pi_contact_mail_page_form_submit'] = array(); +} + +function pi_contact_mail_page_form_submit($form_id, $form_values) { + $pi_contact_values = db_fetch_array(db_query("SELECT * FROM {pi_contact} WHERE cid = %d", $form_values['cid'])); + global $user; + + $node->type = 'project_issue'; + $node->uid = $user->uid; + $node->title = $form_values['subject']; + $node->body = $form_values['message']; + $node->teaser = node_teaser($node->body); + $node->filter = variable_get('filter_default_format', 1); + $node->status = 1; + + foreach (array('pid', 'rid', 'category', 'component', 'priority', 'sid') as $field) { + $node->$field = $pi_contact_values[$field]; + } + + /// @todo : store name/email somewhere reasonable for anon contacts? + + node_save($node); + if (node_access('view', $node)) { + drupal_set_message(t('Your message has been recorded into !issue_link', array('!issue_link' => l('this issue', 'node/' . $node->nid)))); + } + else { + drupal_set_message(t('Your message has been recorded on the site')); + } +} + +/* +// TODO: maybe we need this (or something like it) if we want to support +// adding issue queue stuff when we first add contact tab categories. :( +function pi_contact_get_last_cid() { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + return mysql_insert_id(); + case 'pgsql: + return db_result(db_query("SELECT currval {contact}_cid_seq")); + } + return 0; +} +*/ +