Ejemplo n.º 1
0
/**
 * This function "finalizes" the form, i.e. marks it as completed and ready to go.
 *
 * This is where the excitement happens. This function is called when the user has completed step
 * 4 of the Add Form process, after the user is satisfied that the data that is stored is correct.
 * This function does the following:
 * <ul>
 * <li>Adds a new record to the <b>form_admin_fields</b> table listing which of the database fields are
 * to be visible in the admin interface panel for this form.</li>
 * <li>Creates a new form table with the column information specified in infohash.</li>
 * </ul>
 *
 * @param array $infohash This parameter should be a hash (e.g. $_POST or $_GET) containing the
 *             various fields from the Step 4 Add Form page.
 */
function ft_finalize_form($form_id)
{
    global $g_table_prefix, $g_field_sizes, $g_db_table_charset, $LANG;
    $form_fields = ft_get_form_fields($form_id);
    $query = "\n    CREATE TABLE {$g_table_prefix}form_{$form_id} (\n      submission_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,\n      PRIMARY KEY(submission_id),\n";
    foreach ($form_fields as $field) {
        // don't add system fields (submission ID, Date, Last Modified & IP address)
        if ($field["is_system_field"] == "yes") {
            continue;
        }
        $sql_size = $g_field_sizes[$field["field_size"]]["sql"];
        $query .= "{$field['col_name']} {$sql_size},\n";
    }
    $query .= "submission_date DATETIME NOT NULL,\n            last_modified_date DATETIME NOT NULL,\n            ip_address VARCHAR(15),\n            is_finalized ENUM('yes','no') default 'yes')\n            DEFAULT CHARSET={$g_db_table_charset}";
    $result = mysql_query($query);
    if (!$result) {
        return array("success" => "0", "message" => $LANG["notify_create_form_failure"], "sql_error" => mysql_error());
    }
    $now = ft_get_current_datetime();
    // now the form is complete. Update it as is_complete and enabled
    $query = "\n      UPDATE {$g_table_prefix}forms\n      SET    is_initialized = 'yes',\n             is_complete = 'yes',\n             is_active = 'yes',\n             date_created = '{$now}'\n      WHERE  form_id = {$form_id}\n          ";
    $result = mysql_query($query);
    if (!$result) {
        return array("success" => "0", "sql_error" => mysql_error());
    }
    // finally, add the default View
    ft_add_default_view($form_id);
    extract(ft_process_hook_calls("end", compact("form_id"), array()), EXTR_OVERWRITE);
    return array("success" => 1, "message" => "");
}
Ejemplo n.º 2
0
<?php

$sortable_id = "view_list";
$form_info = ft_get_form($form_id);
// this is called when the user clicks Update OR deletes a group. The delete group first updates the
// view order to ensure that whatever group is being deleted actually has the View that the user expects
if (isset($request["update_views"]) || isset($request["{$sortable_id}_sortable__delete_group"])) {
    $request["sortable_id"] = $sortable_id;
    list($g_success, $g_message) = ft_update_views($form_id, $request);
    if (isset($request["{$sortable_id}_sortable__delete_group"])) {
        list($g_success, $g_message) = ft_delete_view_group($request["{$sortable_id}_sortable__delete_group"]);
    }
}
// if the user deleted all their Views & View Groups, a special "add default view" option appears
if (isset($request["recreate_initial_view"])) {
    list($g_success, $g_message) = ft_add_default_view($form_id);
}
$grouped_views = ft_get_grouped_views($form_id, array("omit_empty_groups" => false, "include_clients" => true));
// figure out how many Views we're dealing with
$num_views = 0;
foreach ($grouped_views as $curr_group) {
    $num_views += count($curr_group["views"]);
}
// ------------------------------------------------------------------------------------------------
// compile the template information
$page_vars["page"] = "views";
$page_vars["page_url"] = ft_get_page_url("edit_form_views", array("form_id" => $form_id));
$page_vars["grouped_views"] = $grouped_views;
$page_vars["head_title"] = "{$LANG["phrase_edit_form"]} - {$LANG["word_views"]}";
$page_vars["form_info"] = $form_info;
$page_vars["sortable_id"] = $sortable_id;