Codice PHP:
{
printMessage('Unable To Send E-Mail',
"We're sorry but we were unable to send your e-mail. " .
'If you are sure that you entered all your email ' .
'addresses properly, you should contact your server ' .
'administrator.');
}
}
/**
* Parses owner-defined email message
*
* Loops through posted form values and replaces all form
* elements in the $message with their corresponding values.
*
* @param string $message an owner-defined email message
* @param array $preferences the CoffeeCup Flash Form Builder Preferences.
*/
function parseMessage($message, $preferences)
{
foreach($preferences['form_fields'] as $key => $value)
{
$message = str_replace('[' . $key . ']', $_POST[$key], $message);
}
return $message;
}
/**
* Gets the real name of the file that was uploaded.
*
* Since the file upload occurs in a different request,
* this method helps us resolve what the name of the
* uploaded file was in case it was renamed.
*/
function fixUploadedFileName()
{
if($_POST['Uploaded_File'] != '')
{
$extension = substr($_POST['Uploaded_File'],
strrpos($_POST['Uploaded_File'], '.'));
$basename = basename($_POST['Uploaded_File'], $extension);
while(file_exists(CC_FB_UPLOADS_DIRECTORY . "/$basename".
CC_FB_UPLOADS_EXTENSION . "$i$extension"))
{
$new_upload_name = "$basename". CC_FB_UPLOADS_EXTENSION .
"$i$extension";
$i++;
}
}
$_POST['Uploaded_File'] = $new_upload_name;
}
/**
* Write form response to a database.
*
* Writes the form response to the database specified at 'CC_FB_DB_ADDRESS'
* if appropriate. If the database doesn't it exist, the CC_FB_DB_TABLE
* table doesn't exist or if the CC_FB_DB_TABLE table doesn't comply with
* the structure of the current form then the database will be restructured
* accordingly.
*
* @param array $preferences the CoffeeCup Flash Form Builder Preferences.
*/
function writeResponseToDatabase($preferences)
{
// If the CC_FB_DB_ADDRESS constant has been populated, then
// the user wants to write their data to a database.
if(CC_FB_DB_ADDRESS != '[ADDRESS]')
{
// First and foremost, lets make sure they have the mysql extension
// loaded.
if(!extension_loaded('mysql'))
{
printMessage('Unable to use MySQL',
"We're sorry but you must have the MySQL extensions loaded " .
'in your PHP configuration in order to save your form '.
'results to a MySQL database. Please contact your ' .
'server administrator.');
}
// Secondly, lets make sure we can connect to their database.
elseif(!($link =
mysql_connect(CC_FB_DB_ADDRESS . ':' . CC_FB_DB_PORT,
CC_FB_DB_USERNAME, CC_FB_DB_PASSWORD)))
{
printMessage('Unable to Connect to Database Server.',
"We're sorry but we were unable to connect to your database " .
'server. Please be sure you have entered your database ' .
'settings correctly.');
}
// If we can't select their DB, lets try to create our own.
elseif(!mysql_select_db(CC_FB_DB_NAME, $link))
{
if(!mysql_query('CREATE DATABASE ' . CC_FB_DB_NAME, $link))
{
printMessage('Unable to Create Database.',
"We're sorry but we were unable to create your database. " .
'If you believe the database already exists, please ' .
'be sure that you have the proper permissions to ' .
'select it. Otherwise, please be sure that you ' .
'have permissions to create databases. If you ' .
'are still experiencing troubles, please contact ' .
'your server administrator.');
}
elseif(!mysql_select_db(CC_FB_DB_NAME, $link))
{
printMessage('Unable to select Database.',
"We're sorry but we were unable to select your database. " .
'Please be sure that you have the proper permissions to ' .
'select it. If you are still experiencing trouble, ' .
'please contact your server administrator.');
}
}
// If a form_results table exists, make sure it is in the
// proper format.
if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '" . CC_FB_DB_TABLE .
"'", $link)) != 0)
{
if(!($results = mysql_query('SHOW COLUMNS FROM `' . CC_FB_DB_TABLE .
'`', $link)))
{
printMessage('Unable to Query Database.',
"We're sorry but we were unable to query your database " .
'table. Please be sure that you have the proper ' .
'permissions to select from the ' . CC_FB_DB_TABLE .
' table. If you are still experiencing trouble, ' .
'please contact your server administrator.');
}
while($row = mysql_fetch_assoc($results))
{
if($row['Field'] != 'id' && $row['Field'] != 'created_at')
{
$columns[$row['Field']] = $row;
}
}
if(!formFieldsEqualsTableFields($preferences['form_fields'],
$columns))
{
archiveOldTable($link);
createTableFromFormFields($preferences['form_fields'], $link);
}
}
// Otherwise create the CC_FB_DB_TABLE table in the proper format.
else
{
createTableFromFormFields($preferences['form_fields'], $link);
}
// If all went well, lets attempt to write the form results to
// the database.
foreach($preferences['form_fields'] as $field_name => $field)
{
$query .= "`$field_name` = " .
mysqlEscape($_POST[$field_name], $link) . ',';
}
// Add the uploaded file to the query if necessary
if(CC_FB_ATTACHMENT_SAVETODB)
{
if($_POST['Uploaded_File'] != '')
{
if(!($contents =
file_get_contents(CC_FB_UPLOADS_DIRECTORY .
"/{$_POST['Uploaded_File']}")))
{
printMessage('Unable To Open Attachment File',"We're sorry " .
'but we were unable to open your uploaded file to ' .
'attach it for email. Please be sure that you have the ' .
'proper permissions.');
}
$query .= '`uploaded_file_name` = ' .
mysqlEscape($_POST['Uploaded_File'], $link) . ',' .
'`uploaded_file` = ' . mysqlEscape($contents, $link) .
',';
}
else
{
$query .= "`uploaded_file_name` = '',`uploaded_file` = '',";
}
}
if(!mysql_query('INSERT INTO `' . CC_FB_DB_TABLE . '` SET ' .
$query . "`created_at` = NOW()", $link))
{
printMessage('Unable to Insert Into Database Table.',
"We're sorry but we were unable to insert the form results " .
'into your database table. Please be sure that you have ' .
'the proper permissions to insert data into the ' .
CC_FB_DB_TABLE . ' table. If you are still experiencing ' .
'trouble, please contact your server administrator.');
}
}
}