Beispiel #1
0
/**
 * Added in 2.1.0, this creates an Internal form with a handful of custom settings.
 *
 * @param $info the POST request containing the form name, number of fields and access type.
 */
function ft_create_internal_form($request)
{
    global $LANG, $g_table_prefix;
    $rules = array();
    $rules[] = "required,form_name,{$LANG["validation_no_form_name"]}";
    $rules[] = "required,num_fields,{$LANG["validation_no_num_form_fields"]}";
    $rules[] = "digits_only,num_fields,{$LANG["validation_invalid_num_form_fields"]}";
    $rules[] = "required,access_type,{$LANG["validation_no_access_type"]}";
    $errors = validate_fields($request, $rules);
    if (!empty($errors)) {
        array_walk($errors, create_function('&$el', '$el = "•  " . $el;'));
        $message = join("<br />", $errors);
        return array(false, $message);
    }
    $info = ft_sanitize($request);
    $config = array("form_type" => "internal", "form_name" => $info["form_name"], "access_type" => $info["access_type"]);
    // set up the entry for the form
    list($success, $message, $new_form_id) = ft_setup_form($config);
    $form_data = array("form_tools_form_id" => $new_form_id, "form_tools_display_notification_page" => false);
    for ($i = 1; $i <= $info["num_fields"]; $i++) {
        $form_data["field{$i}"] = $i;
    }
    ft_initialize_form($form_data);
    $infohash = array();
    $form_fields = ft_get_form_fields($new_form_id);
    $order = 1;
    // if the user just added a form with a lot of fields (over 50), the database row size will be too
    // great. Varchar fields (which with utf-8 equates to 1220 bytes) in a table can have a combined row
    // size of 65,535 bytes, so 53 is the max. The client-side validation limits the number of fields to
    // 1000. Any more will throw an error.
    $field_size_clause = $info["num_fields"] > 50 ? ", field_size = 'small'" : "";
    $field_name_prefix = ft_sanitize($LANG["word_field"]);
    foreach ($form_fields as $field_info) {
        if (preg_match("/field(\\d+)/", $field_info["field_name"], $matches)) {
            $field_id = $field_info["field_id"];
            mysql_query("\n        UPDATE {$g_table_prefix}form_fields\n        SET    field_title = '{$field_name_prefix} {$order}',\n              col_name = 'col_{$order}'\n              {$field_size_clause}\n        WHERE  field_id = {$field_id}\n      ");
            $order++;
        }
    }
    ft_finalize_form($new_form_id);
    // if the form has an access type of "private" add whatever client accounts the user selected
    if ($info["access_type"] == "private") {
        $selected_client_ids = $info["selected_client_ids"];
        $queries = array();
        foreach ($selected_client_ids as $client_id) {
            $queries[] = "({$client_id}, {$new_form_id})";
        }
        if (!empty($queries)) {
            $insert_values = implode(",", $queries);
            mysql_query("\n        INSERT INTO {$g_table_prefix}client_forms (account_id, form_id)\n        VALUES {$insert_values}\n          ");
        }
    }
    return array(true, $LANG["notify_internal_form_created"], $new_form_id);
}
Beispiel #2
0
$sortable_id = "multi_page_form_list";
$form_id = ft_load_field("form_id", "add_form_form_id", "");
$request = array_merge($_POST, $_GET);
$submission_type = ft_load_field("submission_type", "submission_type");
// bit weird, but if a user's coming back to this page to complete setting up their form, update
// the submission_type
if (!empty($form_id) && !empty($submission_type)) {
    mysql_query("UPDATE {$g_table_prefix}forms SET submission_type = '{$submission_type}' WHERE form_id = {$form_id}");
}
// a hash of form values
$page_values = array();
// start setting up the form
if (isset($request["add_form"])) {
    $request["form_type"] = "external";
    $request["submission_type"] = $submission_type;
    list($g_success, $g_message, $form_id) = ft_setup_form($request);
    // store the uploading_files value for the duration of this session
    $_SESSION["ft"]["uploading_files"] = isset($request['uploading_files']) ? $request['uploading_files'] : "no";
    // form successfully added. Continue to step 2.
    if ($g_success) {
        session_write_close();
        header("location: step3.php?form_id={$form_id}");
        exit;
    } else {
        $page_values = ft_preload_values("post");
    }
} else {
    if (isset($request['update_form'])) {
        // store the uploading_files value for the duration of this session
        $_SESSION["ft"]["uploading_files"] = isset($request["uploading_files"]) ? $request["uploading_files"] : "no";
        $request["submission_type"] = $submission_type;