?? webform.module
字號:
/** * Implementation of hook_menu(). */function webform_menu() { global $user; $items = array(); $items[] = array('path' => 'node/add/webform', 'title' => t('webform'), 'access' => user_access('create webforms')); $items[] = array('path' => 'webform/done', 'title' => t('webform'), 'callback' => '_webform_thanks', 'type' => MENU_CALLBACK, 'access' => true); // Upgrade page for the webform $items[] = array('path' => 'webform/upgrade', 'title' => t('Webform upgrade page'), 'callback' => '_webform_update', 'type' => MENU_CALLBACK, 'access' => ($user->uid == 1)); // Access only for the "admin" user. // Submission listning if(variable_get("webform_show_main_menu",true)) { $items[] = array('path' => 'webform', 'title' => t('webform'), 'callback' => 'webform_page', 'type' => MENU_NORMAL_ITEM, 'access' => user_access('maintain webforms')); } if (arg(0) == 'node' && is_numeric(arg(1))) { $node = node_load(array('nid' => arg(1))); if ($node->nid && $node->type == 'webform') { $items[] = array('path' => 'node/' . $node->nid . '/results', 'title' => t('results'), 'callback' => 'webform_results', 'access' => user_access('maintain webforms'), 'type' => MENU_LOCAL_TASK, 'weight' => 3); $items[] = array('path' => 'node/' . $node->nid . '/results/clear', 'title' => t('clear'), 'callback' => 'webform_results', 'type' => MENU_CALLBACK, 'access' => ($user->uid == 1)); // Access only for the "admin" user. $items[] = array('path' => 'node/'.$node->nid.'/results/submissions', 'title' => t('submissions'), 'callback' => 'webform_results', 'access' => user_access('maintain webforms'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => 4); $items[] = array('path' => 'node/'.$node->nid.'/results/analysis', 'title' => t('analysis'), 'callback' => 'webform_results', 'access' => user_access('maintain webforms'), 'type' => MENU_LOCAL_TASK, 'weight' => 5); $items[] = array('path' => 'node/'.$node->nid.'/results/table', 'title' => t('table'), 'callback' => 'webform_results', 'access' => user_access('maintain webforms'), 'type' => MENU_LOCAL_TASK, 'weight' => 6); $items[] = array('path' => 'node/'.$node->nid.'/results/download', 'title' => t('download'), 'callback' => 'webform_results', 'access' => user_access('maintain webforms'), 'type' => MENU_LOCAL_TASK, 'weight' => 7); } } return $items;}/** * Implementation of hook_link(). * Always add a "view form" link **/function webform_link($type, $node = 0, $main = 0) { if ( $node->type == 'webform' ) { if ( $main == 1) { $links[] = l(t('go to form'), "node/$node->nid", array('title' => t('View this form.'), 'class' => 'read-more')); } if ( $main != 1 && arg(0) == 'webform' && arg(1) == 'done') { $links[] = l(t('Go back to the form'), 'node/'.$node->nid); } } return $links;}function webform_form(&$node, &$error) { $output .= _webform_database_lazy_update(); $component_types = array('textfield' => t('textfield'), 'textarea' => t('textarea'), 'select' => t('select'), 'label' => t('label'), 'hidden' => t('hidden'), 'email' => t('e-mail address')); //'explanation' => t('explanation')); // User access stuff $roles = user_roles(0); // Get all roles including anonymous users $checkboxes = ''; foreach ($roles as $rid => $role) { // Uggly way to create a array $checkboxes .= form_checkbox($role, "roles][", $rid, (is_array($node->roles) && in_array($rid, $node->roles)?1:0)); } if(!empty($checkboxes)) $output .= form_item(t('Use access'),$checkboxes, t('Roles that should be able to submit data using this form.')); if (function_exists("taxonomy_node_form")) { $output .= implode("", taxonomy_node_form("webform", $node)); } $output .= form_textarea(t("Description"), "body", $node->body, 20, 10, $error["body"]. " ". t('Text to be shown as teaser and before the form.'), NULL, TRUE); $output .= filter_form('format', $node->format); $output .= form_textarea(t("Confirmation message or redirect URL"), "confirmation", $node->confirmation, 20, 10, $error["confirmation"]." ". t("Message to be shown upon successful submission or an absolute path to a redirect page (must start with http://)"), NULL, TRUE); // List all form components. if( is_array($node->webformcomponents_name) && !empty($node->webformcomponents_name)) { $nocomponents = count($node->webformcomponents_name); foreach($node->webformcomponents_name as $key => $name) { $other = form_hidden("webformcomponents_type][".$key.']', $node->webformcomponents_type[$key]). form_hidden("webformcomponents_extra][".$key, $node->webformcomponents_extra[$key]); $rows[] = array( form_radio('', 'webform_checked_component', $key), form_textfield('', "webformcomponents_name][".$key, $name, 20, 127), $node->webformcomponents_type[$key], form_textfield('', "webformcomponents_value][".$key, $node->webformcomponents_value[$key], 20, 255), form_checkbox('', "webformcomponents_mandatory][".$key, '1', ($node->webformcomponents_mandatory[$key]?1:0)), form_weight('', "webformcomponents_weight][".$key, ($node->webformcomponents_weight[$key]?$node->webformcomponents_weight[$key]:0), (($nocomponents>10)?$nocomponents:10)). $other); } $help_text = theme_item_list(array( t('To edit a component, check its "selected" box and press "Edit selected".'), t('To delete a component, check its "selected" box and press "Delete selected".'), t('Use "value" to enter a default value.'), t('Check "mandatory" box if the field should be mandatory.'), t('Remember to set weight on the components or they will be added to the form in a random order.'), t('The components are sorted first by weight and then by name.') ) ); $output .= form_item(t('Form components'), $help_text); $headers = array( '<span> '.t('Select').'</span>', '<span>'.t('Name').'</span>', t('Type'), '<span>'.t('Value').'</span>', '<span>'.t('Mandatory').'</span>', '<span>'.t('Weight').'</span>' ); $output .= theme('table', $headers, $rows); $output .= form_button(t('Edit selected'), 'edit_component'); $output .= form_button(t('Delete selected'), 'delete_component'); } // Mini-form to add a new component. $output .= form_select(t('Add a new component'), 'webform_newfield_type', $node->webform_newfield_type, $component_types, t('Select a component type to add.')); $output .= form_button(t('Add'), 'edit_component'); $output .= form_textfield(t("E-mail to address"), "email", $node->email, 60, 250, t('Form submissions will be e-mailed to this address. Leave blank for none.').($error["email"] ? $error["email"] : '')); // Build arrays of possible return email addresses and email subject lines from elements on the form $possible_email_from = array('Automatic' => 'Automatic'); $possible_email_subject = array('Automatic' => 'Automatic'); if( is_array($node->webformcomponents_name) && !empty($node->webformcomponents_name)) { foreach($node->webformcomponents_name as $key => $name) { $type = $node->webformcomponents_type[$key]; if( $type == 'email' || $type == 'hidden' ){ $possible_email_from[$name] = $name; } if( $type == 'textfield' || $type == 'hidden' ){ $possible_email_subject[$name] = $name; } } } $output .= form_select(t('E-mail from address'), 'email_from', $node->email_from, $possible_email_from, t('Form e-mails will have this return address. Choose Automatic for the default')); $output .= form_select(t('E-mail subject'), 'email_subject', $node->email_subject, $possible_email_subject, t('Form e-mails will have this subject line. Choose Automatic for the default')); return $output;}function webform_view(&$node, $teaser = 0, $page = 0) { global $user; $doSubmit = true; if (module_exist('profile') ) { profile_load_profile($user); } $node->body = check_output($node->body, $node->format); $submitted = $_POST['edit']['submitted']; $sid_to_display = $_GET['sid']; // Will be NULL if no sid if($sid_to_display){ if(user_access('maintain webforms')){ $output .= '<H2 class="warning">Submission #' . $sid_to_display . '</H2><br>'; // TODO: Expand the information block //$submitting_user = user_load(array('uid' => 2)); //$output .= 'User: ' . $submitting_user->name . ' from IP' . $_GET['ipaddr'] . '<br>'; //$output .= 'Date: ' . $_GET['dated'] . '<br>'; //$output .= 'Read Only<br>'; }else { $sid_to_display = 0; // This user is not allowed to access a submitted node. Deny the attempt without alert. watchdog('webform', t('Unauthorized webform access attempt', array('%name' => "<em>$user->name</em>")), WATCHDOG_WARNING); // and log the attempt } } if( is_array($node->webformcomponents_name) && !empty($node->webformcomponents_name)) { foreach($node->webformcomponents_name as $key => $name) { $extra = unserialize ($node->webformcomponents_extra[$key]); if ( $_POST['webform_send'] ) { $error = _webform_submission_ok($name, $node->webformcomponents_type[$key], $submitted[$name], $node->webformcomponents_mandatory[$key]); if ( $error !== 0 ) { $doSubmit = false; } } if($sid_to_display){ // It is view only so we append the tag HTML attributes to disable the input $extra['attributes'] = array('disabled' => 'disabled'); // Rather ugly string required to workaround a bug in common.inc }else { $extra['attributes'] = array(); } $output .= _webform_create_widget( $name, $node->webformcomponents_type[$key], $node->webformcomponents_mandatory[$key], (isset($submitted[$name])? $submitted[$name]: _webform_filtervalues($node->webformcomponents_value[$key])), $extra, $error, $node->nid, $sid_to_display); } if ( (!isset($_POST['op']) || ($_POST['op'] != t('Preview'))) ) { if(!$sid_to_display){ // Do not show the submit button if we are viewing a previously submitted form $output .= form_button(t('Submit'), 'webform_send', 'submit'); } } $output = form($output); } if ( $doSubmit && $_POST['webform_send']) { if(_webform_process_submit($node, $errors)) { // Check confirmation field to see if redirect should be to another node or a message if(valid_url(trim($node->confirmation),true)) { header("Location: " . trim($node->confirmation)); } else { // Submission was successfully redirected to webform/done/<nid> drupal_goto('webform/done/'.$node->nid); } return; } } $node->body .= $output;}function _webform_editfield() { // we have to do what the framework would do for us so we don't lose // information. if( isset($_POST['edit']) ) { $node = array2object($_POST['edit']); } else { // We are calling this page in the wrong way ... // Do some clean up ?? print theme('page', theme('error', t('Page called out of order'))); return; } // This is the information about the current field. $currfield = array(); if ( $_POST['edit_component'] != t('Add') ) { // We are editing a existing field. // Fetch all filed data into the $currfield object. $currfield['key'] = $node->webform_checked_component; $currfield['type'] = $node->webformcomponents_type[$currfield['key']]; $currfield['name'] = $node->webformcomponents_name[$currfield['key']]; $currfield['default'] = $node->webformcomponents_value[$currfield['key']]; $currfield['extra'] = unserialize($node->webformcomponents_extra[$currfield['key']]); } else { // We are editing a new node $currfield['key'] = time(); $currfield['type'] = $node->webform_newfield_type; $currfield['name'] = $node->webform_newfield_type . $currfield['key'];
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -