| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* @file webform_paths.module
|
| 4 |
* Allows assigning multiple paths and destinations to a single webform.
|
| 5 |
*
|
| 6 |
* @author Omar Abdel-Wahab <owahab@owhab.com>
|
| 7 |
* @copyright: KnowledgeTree Inc
|
| 8 |
* @license: GPL 2 or any later version.
|
| 9 |
* @date 2009-01-01
|
| 10 |
*/
|
| 11 |
|
| 12 |
|
| 13 |
/**
|
| 14 |
* Implementation of hook_menu().
|
| 15 |
*/
|
| 16 |
function webform_paths_menu() {
|
| 17 |
$items = array();
|
| 18 |
|
| 19 |
$items['node/%webform_menu/path/%webform_paths'] = array(
|
| 20 |
'title' => 'Paths',
|
| 21 |
'page callback' => 'webform_paths_view_webform',
|
| 22 |
'page arguments' => array(1, 3),
|
| 23 |
'access callback' => 'node_access',
|
| 24 |
'access arguments' => array('view', 1),
|
| 25 |
'type' => MENU_CALLBACK,
|
| 26 |
);
|
| 27 |
$items['node/%webform_menu/edit/webform_paths'] = array(
|
| 28 |
'title' => 'Paths',
|
| 29 |
'page callback' => 'webform_paths_edit_node_settings',
|
| 30 |
'page arguments' => array(1, 4),
|
| 31 |
'access callback' => 'node_access',
|
| 32 |
'access arguments' => array('update', 1),
|
| 33 |
'weight' => 9,
|
| 34 |
'type' => MENU_LOCAL_TASK,
|
| 35 |
'file' => 'webform_paths.admin.inc',
|
| 36 |
);
|
| 37 |
$items['webform_paths/delete'] = array(
|
| 38 |
'title' => 'Delete path',
|
| 39 |
'page callback' => 'drupal_get_form',
|
| 40 |
'page arguments' => array('webform_paths_delete_path_confirm'),
|
| 41 |
'access arguments' => array('administer webform paths'),
|
| 42 |
'type' => MENU_CALLBACK,
|
| 43 |
'file' => 'webform_paths.admin.inc',
|
| 44 |
);
|
| 45 |
|
| 46 |
return $items;
|
| 47 |
}
|
| 48 |
|
| 49 |
/**
|
| 50 |
* Implementation of hook_load().
|
| 51 |
*/
|
| 52 |
function webform_paths_load($pathid) {
|
| 53 |
return db_fetch_object(db_query('SELECT * FROM {webform_paths} WHERE pathid = %d', $pathid));
|
| 54 |
}
|
| 55 |
|
| 56 |
/**
|
| 57 |
* Implementation of hook_perm().
|
| 58 |
*/
|
| 59 |
function webform_paths_perm() {
|
| 60 |
return array('administer webform paths');
|
| 61 |
}
|
| 62 |
|
| 63 |
/**
|
| 64 |
* Returns a node view page for a given webform path.
|
| 65 |
*/
|
| 66 |
function webform_paths_view_webform($node, $path) {
|
| 67 |
if (!empty($path->title)) {
|
| 68 |
drupal_set_title($path->title);
|
| 69 |
drupal_set_message($path->message);
|
| 70 |
}
|
| 71 |
return node_view($node, FALSE, TRUE);
|
| 72 |
}
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Retrieves a list of paths created for a given webform node.
|
| 76 |
*/
|
| 77 |
function webform_paths_get_node_paths($node) {
|
| 78 |
$paths = array();
|
| 79 |
$query = db_query('SELECT * FROM {webform_paths} WHERE nid = %d', $node->nid);
|
| 80 |
while ($rs = db_fetch_array($query)) {
|
| 81 |
$pathid = $rs['pathid'];
|
| 82 |
$paths[$pathid] = $rs;
|
| 83 |
}
|
| 84 |
return $paths;
|
| 85 |
}
|
| 86 |
|
| 87 |
/**
|
| 88 |
* Creates or updates a webform path.
|
| 89 |
*/
|
| 90 |
function webform_paths_path_save($path) {
|
| 91 |
// In case of updating
|
| 92 |
if ($path['pathid'] > 0) {
|
| 93 |
// Specify the schema key
|
| 94 |
$key = array('pathid');
|
| 95 |
// Load the old path
|
| 96 |
$old_path = webform_paths_load($path['pathid']);
|
| 97 |
path_set_alias(NULL, $old_path->path);
|
| 98 |
}
|
| 99 |
|
| 100 |
// Save the path to our table:
|
| 101 |
drupal_write_record('webform_paths', $path, $key);
|
| 102 |
|
| 103 |
// Update necessary aliases
|
| 104 |
$real_path = 'node/' . $path['nid'] . '/path/' . $path['pathid'];
|
| 105 |
path_set_alias($real_path, $path['path']);
|
| 106 |
return $path;
|
| 107 |
}
|