?? webform.module
字號:
<?php// $Id: webform.module,v 1.48.2.5 2005/06/18 08:18:19 ullgren Exp $ /** This module provides a simple way to create forms and questionnaires * for your website. * The development of this module was sponsered by ÅF Industri AB, * Open Source City and Karlstad University Library. * * @author Pontus Ullgren <ullgren@user.sourceforge.net> * @package module_webform * @copyright Pontus Ullgren 2003 * **//** Hook Help - displayes help and general infomation about the module * @param section specifies the section to display help for. * @return a formated string containing the help output. **/function webform_help($section = "admin/help#webform") { $output = ""; switch ($section) { case 'admin/settings/webform': $output = t("Webforms are forms and questionnaires. To add one select <strong>create content -> webform</strong>. Below you can set different security and debug options."); break; case 'admin/help#webform': $output = t("<p>This module lets you create forms or questionnaires and define there content. Submissions from these forms are stored in the database and optionaly also send by e-mail to a predefined address.</p><p>Here is how to create one:<ul> <li>Go to Create Content and add a webform</li> <li>Add a description that is displayed as a teaser and above the actual form.</li> <li>Add a confirmation message or redirect node that is to be displayed after a successful submission.</li> <li>Select which roles who should have submission access to this form (roles that have the "use all webforms" permision can allways use a webform).</li> <li>Add one or more components to your form.</li> <li>Optionaly add a email address to which submissions will be send. If no email address is specified no email will be send when submissions are made through the form.</li> <li>Optionally select an email component that will be used to populate the return email address on any sent email.</ul> <li>Optionally select a textfield component that will be used to populate the subject email field on any sent email.</ul></ul>Help on adding and how to configure the components will be shown after adding your first component.</p><p>On user submissions the form content is stored in the database table <i>webform_submitted_data</i> as key-value pairs. Apart from the form fields the following "special" fields are added:<ul> <li> __userid : UID of the submiting user.</li> <li> __timestamp : UNIX timestamp for when the submission occured.</li> <li> __remotehost : IP or name of the remote host from which the submission came.</li> <li> __useragent : What user agent (browser) the user used upon submitting the data.</li></ul>"); break; case 'admin/modules#description': $output = t("Enables the creation of forms and questionnaires."); break; case 'node/add#webform': $output = t("A webform can be a questionnaires, contact or request forms. It can be used to let visitors make contact, register for a event or to enable a complex survey."); break; case 'webform/helptext#variables': $output = t('Available variables are: %username, %useremail, %site, %date.'); $output .= ' '.t('You can also use %server[key] to add any of the special PHP <a href="http://www.php.net/reserved.variables#reserved.variables.server">$_SERVER</a> variables and %get[key] to create prefilled forms from from the <a href="http://www.php.net/reserved.variables#reserved.variables.get">URL</a>.'); if ( module_exist('profile') ) { $output .= t('If you are using the profiles module, you can also access all profile data using the syntax %profile[form_name]. If you for example have a profile value named profile_city, add the varible %profile[profile_city].'); } break; } return $output;}function webform_perm() { return array("maintain webforms", "create webforms", "use all webforms");}/** * Define the human-readable name of a node type. */function webform_node_name($node) { return t('webform');}function webform_access($op, $node) { global $user; if ($op == "view") { if ( user_access("use all webforms") ) { return $node->status; } else if ( is_array($node->roles) ) { foreach ($node->roles as $rid) { if( isset($user->roles[$rid]) ) { return $node->status; } } } return false; } if ($op == "create") { return user_access("create webforms"); } if ($op == "update") { return user_access("maintain webforms"); } if ($op == "delete") { return user_access("maintain webforms"); } return false;}function webform_insert($node) { global $user; // insert _webform_database_lazy_update(); // Lazy Initializer db_query("INSERT INTO {webform} (nid, confirmation, email, email_from, email_subject) VALUES (%d, '%s', '%s', '%s', '%s')", $node->nid, $node->confirmation, $node->email, $node->email_from, $node->email_subject); if( is_array($node->webformcomponents_name) && !empty($node->webformcomponents_name)) { foreach($node->webformcomponents_name as $key => $name) { db_query("INSERT INTO {webform_component} (nid, cid, name, type, value, extra, mandatory, weight) ". " VALUES (%d, %d, '%s', '%s', '%s', '%s', %d, %d)", $node->nid, $key, $name, $node->webformcomponents_type[$key], $node->webformcomponents_value[$key], $node->webformcomponents_extra[$key], ($node->webformcomponents_mandatory[$key]?1:0), $node->webformcomponents_weight[$key]); } } _webform_role_node_delete($node->nid); if (is_array($node->roles)) { // Filter all empty roles foreach ($node->roles as $rid) { if($rid != 0) $roles[] = $rid; } // Add the users group if it isn't allready checked. if(!is_array($roles) || !in_array($user->rid, $roles)) { $roles[] = $user->rid; } if (!empty($roles)) { foreach ($roles as $rid) { db_query("INSERT INTO {webform_role_node} (nid, rid) VALUES (%d, %d)", $node->nid, $rid); } } }}function webform_update($node) { // Update // Lazy Initializer _webform_database_lazy_update(); db_query("UPDATE {webform} SET confirmation = '%s', email = '%s', email_from = '%s', email_subject = '%s' ". "WHERE nid = %d", $node->confirmation, $node->email, trim($node->email_from), trim($node->email_subject), $node->nid); db_query("DELETE FROM {webform_component} WHERE nid = %d", $node->nid); if( is_array($node->webformcomponents_name) && !empty($node->webformcomponents_name)) { foreach($node->webformcomponents_name as $key => $name) { db_query("INSERT INTO {webform_component} (nid, cid, name, type, value, extra, mandatory, weight) ". " VALUES (%d, %d, '%s', '%s', '%s', '%s', %d, %d)", $node->nid, $key, $name, $node->webformcomponents_type[$key], $node->webformcomponents_value[$key], $node->webformcomponents_extra[$key], ($node->webformcomponents_mandatory[$key]?1:0), $node->webformcomponents_weight[$key]); } } _webform_role_node_delete($node->nid); if ($node->roles) { foreach ($node->roles as $rid) { if($rid != 0) db_query("INSERT INTO {webform_role_node} (nid, rid) VALUES (%d, %d)", $node->nid, $rid); } } }function webform_delete(&$node) { // delete db_query("DELETE FROM {webform} WHERE nid = %d", $node->nid); db_query("DELETE FROM {webform_component} WHERE nid = %d", $node->nid); _webform_role_node_delete($node->nid); watchdog('webform','webform "' . $node->title . '" deleted', WATCHDOG_NOTICE);}function webform_load($node) { // load // Lazy initializer _webform_database_lazy_update(); $page = db_fetch_object(db_query("SELECT confirmation, email, email_from, email_subject FROM {webform} WHERE nid = %d", $node->nid)); $result = db_query('SELECT cid, name, type, value, extra, mandatory, weight '. ' FROM {webform_component} '. ' WHERE nid = %d '. ' ORDER BY weight, name', $node->nid); while($c = db_fetch_array($result)) { $page->webformcomponents_name[$c['cid']] = $c['name']; $page->webformcomponents_type[$c['cid']] = $c['type']; $page->webformcomponents_value[$c['cid']] = $c['value']; $page->webformcomponents_extra[$c['cid']] = $c['extra']; $page->webformcomponents_mandatory[$c['cid']] = $c['mandatory']; $page->webformcomponents_weight[$c['cid']] = $c['weight']; } $result = db_query("SELECT rid FROM {webform_role_node} WHERE nid = %d", $node->nid); while($rid = db_fetch_array($result)) { $page->roles[]=$rid['rid']; } return $page;}function webform_settings(){ $installed_version = variable_get('webform_version', array('text'=> 'Unknown', 'build' => 1)); $current_version = _webform_version(); if ( $installed_version['build'] < $current_version['build'] ) { $output .= '<div>'.l(t('Update from version %a to version %b', array( '%a' => $installed_version['text'], '%b' => $current_version['text']) ), 'webform/upgrade').'</div>'; } $output .= form_select(t("Allow cross site posting"), "webform_allow_cross_site_posting", variable_get("webform_allow_cross_site_posting", 0), array(0 => t('Yes'), 1 => t('No')), t("Allow postings to your webforms that do not originate from your site's domain.")); $output .= form_select(t("Webforms Debug"), "webform_debug", variable_get("webform_debug", 0), array(0 => "OFF", 1 => "Log submissions", 2 => "Full debug"), '<br />'.t("DEBUG for the webform module") . '<br />' . t('Set this option to "Log submissions" to log all submissions in the watchdog. Set it to "Full debug" to print debug info on submission. You probably want to leave this option on "OFF".')); $output .= form_checkbox(t("Show main webform menu"), "webform_show_main_menu",1, variable_get("webform_show_main_menu", true), t('Select the visibility of the main webform item on the main menu')); return $output;} // end function webform_settingsfunction webform_validate(&$node) { if( isset($_POST['edit_component']) ) { // If we are adding a new componenet or removing a old one // 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']); } _webform_editfield(); exit(0); } if( isset($_POST['webform_edit_done']) ) { $old_edit = unserialize($_POST['old_edit']); $new_edit = $_POST['edit']; if ( !is_array($new_edit) ) $new_edit =array(); if ( !is_array($old_edit) ) $old_edit =array(); $edit = array_merge($new_edit, $old_edit); // If we are adding a new componenet or removing a old one // we have to do what the framework would do for us so we don't loose // information. $node = array2object($edit); // We have just edited component add it to the node $node->webformcomponents_name[$node->webform_edited_key] = $node->webform_edited_name; $node->webformcomponents_type[$node->webform_edited_key] = $node->webform_edited_type; $node->webformcomponents_value[$node->webform_edited_key] = $node->webform_edited_default; $node->webformcomponents_extra[$node->webform_edited_key] = serialize($node->webform_edited_extra); drupal_set_message(t('The form component has been changed. Remember to press Submit on the bottom of this form to save your changes.')); } if(isset($_POST['delete_component']) && isset($_POST['edit']['webform_checked_component']) ) { unset($node->webformcomponents_name[$_POST['edit']['webform_checked_component']]); drupal_set_message(t('The form component has been deleted. Remember to press Submit on the bottom of this form to save your changes.')); } // Validate the body field. if (isset($node->body)) { if (!$node->body) { form_set_error('body', t('You have to specify a form description.')); return false; } } // Validate confirm field if (isset($node->confirmation)) { if (!$node->confirmation) { form_set_error('confirmation', t('You have to specify a confirmation message.')); return $false; } } // TODO: Put email validates here return true;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -