📄 webform.module
字号:
}/** Filters all special chars **/function _webform_filtervalues($string) { global $user; $find = array('%username', '%useremail', '%site', '%date'); $replace = array($user->name, $user->mail, variable_get('site_name', 'drupal'), format_date(time(), 'large')); if (module_exist('profile') ) { foreach($user as $k => $v) { $find[] = "%profile[$k]"; $replace[] = $v; } } foreach($_SERVER as $k => $v) { $find[] = "%server[$k]"; $replace[] = $v; } foreach($_GET as $k => $v) { $find[] = "%get[$k]"; $replace[] = $v; } foreach($_POST as $k => $v) { $find[] = "%post[$k]"; $replace[] = $v; } $string = str_replace( $find, $replace, $string); if (module_exist('profile')) { // Clean up any unused %profile stuff $string = preg_replace('/\%profile\[\w+\]/', '', $string); } // Clean up any unused %post and %get stuff $string = preg_replace('/\%get\[\w+\]/', '', $string); $string = preg_replace('/\%post\[\w+\]/', '', $string); // Clean up any unused %system stuff $string = preg_replace('/\%server\[\w+\]/', '', $string); return $string;}function _webform_create_mailmessage($reply) { global $user; $message .= t('Submitted on').' '.format_date(time(), 'small')."\r\n"; $ip_address = $_SERVER['REMOTE_ADDR']; if($user->uid) { $message .= t('Submitted by user').": $user->name [$ip_address] \n"; } else { $message .= t('Submitted by anonymous user').": [$ip_address] \n"; } $message .= t('Submitted values are:')."\n"; foreach($reply as $key => $value) { if (is_array($value)) { $message .= "$key :"; foreach($value as $k => $v) { $message .= "\n\t\t"."$k = $v"; } $message .= "\n"; } else { $message .= "$key : $value"."\n"; } } if (variable_get('webform_debug', 0) == 2) { $message .= "\r\n"; $message .= "DEBUG INFO\r\n"; $message .= "==========\r\n"; $message .= "\$_SERVER is\r\n"; $message .= print_r($_SERVER, true); $message .= "\r\n"; $message .= "\$_POST is\r\n"; $message .= print_r($_POST, true); } return $message;}function _webform_save_submission($node, $reply) { global $user; $reply['__userid'] = $user->uid; $reply['__timestamp'] = time(); $reply['__remotehost'] = $_SERVER['REMOTE_ADDR']; $reply['__useragent'] = $_SERVER['HTTP_USER_AGENT']; $sid = db_next_id('{webform_submissions}_id'); foreach($reply as $key => $value) { // TODO: Save array i a better way. if (is_array($value)) { $value = serialize($value); } $sqlstring[] = " (%d, %d, '%s', '%s') "; $values[] = $node->nid; $values[] = $sid; $values[] = $key; $values[] = $value; } db_query("INSERT INTO {webform_submitted_data} (nid, sid, name, data) ". "VALUES ".implode(', ', $sqlstring), $values);}function _webform_role_node_delete($nid) { db_query("DELETE FROM {webform_role_node} WHERE nid = %d",$nid);}function webform_page() { include_once('webform.inc'); _webform_page();}/** * function webform_results() is an allocator function that builds the page under the 'results' sub menu * The function uses the URL tail to nominate internal content. */function webform_results() { include_once('webform.inc'); $nid = arg(1); $node = node_load(array('nid' => $nid)); $title = $node->title; if( arg(2) == 'results') { switch ( arg(3) ) { case 'analysis': $content = _webform_results_analysis($nid); break; case 'clear': $content = _webform_results_clear($nid); break; case 'delete': $sid = arg(4); $content = _webform_submission_delete($nid, $sid); break; case 'table': $content = _webform_results_table($nid); break; case 'download': $content = _webform_results_download($nid); break; case 'submissions': default: $content = _webform_results_submissions($nid); break;} drupal_set_title($title); print theme('page', $content); }}/** * Returns the version of this release of the webform module. * * @return array An array with keys 'text' and 'build' containing the * text version and build ID of this release, respectively. */function _webform_version() { /* Why text and an ID? Well, the text is easier for the user to * read and understand while the build ID, being a number (a date * with a serial, specifically), is easier for the developer to use * to determine newer/older versions for upgrade and installation * purposes. */ return array("text" => "4.6.2", "build" => 462);} // function _webform_version/** * _webform_database_lazy_update - Lazy field adder for extra email fields * The lazy update function adds any columns in the database that are not * listed in its internal magic array. * It was purpose constructed to add fields 'email_from' and 'email_subject' as part of the * enhanced email patch. * The function does not add or delete any data and the upgraded database is backwardly * compatible with previous versions of webform.module */function _webform_database_lazy_update() { $lazy_update_output = ''; $field_list = ''; $table_altered = false; // {webform} $required_fields = array('nid' => false,'confirmation' => false,'email' => false,'email_from' => false,'email_subject' => false); $result = db_query("SHOW FIELDS FROM {webform}"); // Mark fields that exist in table as true while ($record = db_fetch_object($result)){ $required_fields[$record->Field] = true; } foreach($required_fields as $field_name => $required_field){ if(!$required_field){ // Field does not exist so we need to create it. switch($field_name){ case 'email_subject': // Contains the component name of the source field for the email subject case 'email_from': // Contains the component name of the source field for the email from address. db_query("ALTER TABLE {webform} ADD COLUMN %s varchar(255)",$field_name); $table_altered = true; $field_list .= " $field_name "; break; default: } } } if($table_altered){ $lazy_update_output = 'Database {webform} updated. Fields added: ' . $field_list; watchdog('webform',$lazy_update_output, WATCHDOG_NOTICE); } return $lazy_update_output;}/** * Makes updates to the database structure. **/function _webform_update() { $installed_version = variable_get('webform_version', array('text'=> 'Unknown', 'build' => 1)); $current_version = _webform_version(); if ( $installed_version['build'] < $current_version['build']) { include_once('database/updates.inc'); include_once('includes/bootstrap.inc'); include_once('includes/common.inc'); // Check to see if we should do a update. print "<strong>Upgrading webform from ".$installed_version['build'] . " to ". $current_version['build']."</strong><br />\n"; // Upgrading from original version if ( $installed_version['build'] <= 1 ) { $ret[] = array(1 => "<strong>Build 1</strong><br />\n", 2 => ""); // Add the table webform_submitted_data $ret[] = update_sql("CREATE TABLE {webform_submited_data} ". "( nid int(10) unsigned not null, ". "sid int(10) unsigned not null, ". "name varchar(255) not null, ". "data blob, ". "PRIMARY KEY(nid, sid, name))"); // Converting data from old submission table. $ret[] = _webform_convert_old_submissions(); } if ( $installed_version['build'] <= 1 ) { $ret[] = array(1 => "<strong>Build 4.5.0</strong><br />\n", 2 => ""); // Change webform_component.extra from varchar(128) -> text $ret[] = update_sql("ALTER TABLE {webform_component} MODIFY extra TEXT"); // Change webform_submited_data.data blob -> longtext $ret[] = update_sql("ALTER TABLE {webform_submited_data} MODIFY data LONGTEXT"); } if ( $installed_version['build'] < 460 ) { $ret[] = array(1 => "<strong>Build 4.6.0</strong><br />\n", 2 => ""); // Update webform_submited_data to webform_submitted_data $ret[] = update_sql("ALTER TABLE {webform_submited_data} RENAME TO {webform_submitted_data}"); } if ( $installed_version['build'] < 461 ) { // Update webform.email varchar(50) -> varchar(255) $ret[] = update_sql(" ALTER TABLE {webform} MODIFY email varchar(255)"); // Update from lable to label in webform_component $ret[] = update_sql(" UPDATE {webform_component} SET type = 'label' WHERE type = 'lable'"); } if ( $installed_version['build'] < 462 ) { // Update webform.confirm varchar(255) -> text and change name to "confirmation" $ret[] = update_sql(" ALTER TABLE {webform} CHANGE confirm confirmation text"); } // Set the $current_version variable_set("webform_version", $current_version); print "<pre>\n"; foreach ( $ret as $return ) { print $return[1]; print $return[2]; } print "</pre>\n"; print "<strong>Done!</strong><br/>\n"; print l(t('Go back'), 'admin/settings/webform')."<br/>\n"; } // end if ( $installed_version['build'] < $current_version['build'])} // end function _webform_update /** * Function to convert the old XML formated submissions into the newer format. **/function _webform_convert_old_submissions() { // Select all from webform_submissions. /* $result = db_query("SELECT nid, sid, uid, UNIX_TIMESTAMP(created) as created, data ". "FROM {webform_submissions}"); while ($row = db_fetch_object($result) ) { // TODO: Parse each XML string ... // ... and insert the data into the new table. } */ return array('1', "Converting old submissions", "<div style=\"color: red;\">Not implemented!</div>\n");} // end function _webform_convert_old_submissions?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -