Exemple #1
0
    $last_name = $view_clients[$i]["last_name"];
    $selected_users_str .= "<option value=\"{$client_id}\">{$first_name} {$last_name}</option>\n";
    $selected_user_ids[] = $client_id;
}
// build the available users <options>. This is used to populate the Available Clients section
// of Private accessed forms
$available_users_str = "";
foreach ($form_info["client_info"] as $client) {
    if (in_array($client["account_id"], $selected_user_ids)) {
        continue;
    }
    $available_users_str .= "<option value=\"{$client['account_id']}\">{$client['first_name']} {$client['last_name']}</option>\n";
}
// get the ID of the previous and next field options. We should probably cache this, but until I'm sure
// it's slowing things down, we'll keep it simple
$ordered_view_ids = ft_get_view_ids($form_id, true);
$previous_view_link = "<span class=\"light_grey\">{$LANG["phrase_previous_view"]}</span>";
$next_view_link = "<span class=\"light_grey\">{$LANG["phrase_next_view"]}</span>";
$num_views = count($ordered_view_ids);
$same_page = ft_get_clean_php_self();
for ($i = 0; $i < $num_views; $i++) {
    $curr_view_id = $ordered_view_ids[$i];
    if ($curr_view_id == $view_id) {
        if ($i != 0) {
            $previous_view_id = $ordered_view_ids[$i - 1];
            $previous_view_link = "<a href=\"{$same_page}?page=edit_view&form_id={$form_id}&view_id={$previous_view_id}\">{$LANG["phrase_previous_view"]}</a>";
        }
        if ($i != $num_views - 1) {
            $next_view_id = $ordered_view_ids[$i + 1];
            $next_view_link = "<a href=\"{$same_page}?page=edit_view&form_id={$form_id}&view_id={$next_view_id}\">{$LANG["phrase_next_view"]}</a>";
        }
Exemple #2
0
/**
 * Called by administrators; updates the content stored on the "Main" tab in the Edit Form pages.
 *
 * @param integer $infohash a hash containing the contents of the Edit Form Main tab.
 * @return array returns array with indexes:<br/>
 *               [0]: true/false (success / failure)<br/>
 *               [1]: message string<br/>
 */
function ft_update_form_main_tab($infohash, $form_id)
{
    global $g_table_prefix, $LANG;
    $infohash = ft_sanitize($infohash);
    extract(ft_process_hook_calls("start", compact("infohash", "form_id"), array("infohash")), EXTR_OVERWRITE);
    $success = true;
    $message = $LANG["notify_form_updated"];
    // check required POST fields
    $rules = array();
    $rules[] = "required,form_name,{$LANG["validation_no_form_name"]}";
    $rules[] = "required,edit_submission_page_label,{$LANG["validation_no_edit_submission_page_label"]}";
    $errors = validate_fields($infohash, $rules);
    if (!empty($errors)) {
        $success = false;
        array_walk($errors, create_function('&$el', '$el = "&bull;&nbsp; " . $el;'));
        $message = join("<br />", $errors);
        return array($success, $message, "");
    }
    $is_active = "";
    if (!empty($infohash["active"])) {
        $is_active = "is_active = '{$infohash['active']}',";
    }
    $form_name = $infohash["form_name"];
    $form_type = $infohash["form_type"];
    $submission_type = $infohash["submission_type"];
    $client_ids = isset($infohash["selected_client_ids"]) ? $infohash["selected_client_ids"] : array();
    $is_multi_page_form = isset($infohash["is_multi_page_form"]) ? $infohash["is_multi_page_form"] : "no";
    $access_type = $infohash["access_type"];
    if ($submission_type == "direct") {
        $is_multi_page_form = "no";
    }
    if ($is_multi_page_form == "yes") {
        $form_url = $infohash["multi_page_urls"][0];
    } else {
        $form_url = $infohash["form_url"];
    }
    $redirect_url = isset($infohash["redirect_url"]) ? $infohash["redirect_url"] : "";
    $auto_delete_submission_files = $infohash["auto_delete_submission_files"];
    $submission_strip_tags = $infohash["submission_strip_tags"];
    $edit_submission_page_label = $infohash["edit_submission_page_label"];
    $add_submission_button_label = $infohash["add_submission_button_label"];
    $query = "\n    UPDATE {$g_table_prefix}forms\n    SET    {$is_active}\n          form_type = '{$form_type}',\n          submission_type = '{$submission_type}',\n          is_multi_page_form = '{$is_multi_page_form}',\n          form_url = '{$form_url}',\n          form_name = '{$form_name}',\n          redirect_url = '{$redirect_url}',\n          access_type = '{$access_type}',\n          auto_delete_submission_files ='{$auto_delete_submission_files}',\n          submission_strip_tags = '{$submission_strip_tags}',\n          edit_submission_page_label = '{$edit_submission_page_label}',\n          add_submission_button_label = '{$add_submission_button_label}'\n    WHERE  form_id = {$form_id}\n          ";
    $result = mysql_query($query) or ft_handle_error("Failed query in <b>" . __FUNCTION__ . "</b>, line " . __LINE__ . ": <i>{$query}</i>", mysql_error());
    // finally, update the list of clients associated with this form
    mysql_query("DELETE FROM {$g_table_prefix}client_forms WHERE form_id = {$form_id}");
    foreach ($client_ids as $client_id) {
        $query = mysql_query("\n      INSERT INTO {$g_table_prefix}client_forms (account_id, form_id)\n      VALUES  ({$client_id}, {$form_id})\n        ");
    }
    // since the client list may have just changed, do a little cleanup on the database data
    switch ($access_type) {
        // no changes needed!
        case "public":
            break;
            // delete all client_view, client_form, public_form_omit_list, and public_view_omit_list entries concerning this form &
            // it's Views. Since only the administrator can see the form, no client can see any of it's sub-parts
        // delete all client_view, client_form, public_form_omit_list, and public_view_omit_list entries concerning this form &
        // it's Views. Since only the administrator can see the form, no client can see any of it's sub-parts
        case "admin":
            mysql_query("DELETE FROM {$g_table_prefix}client_forms WHERE form_id = {$form_id}");
            mysql_query("DELETE FROM {$g_table_prefix}public_form_omit_list WHERE form_id = {$form_id}");
            $view_ids = ft_get_view_ids($form_id);
            foreach ($view_ids as $view_id) {
                mysql_query("DELETE FROM {$g_table_prefix}client_views WHERE view_id = {$view_id}");
                mysql_query("DELETE FROM {$g_table_prefix}public_view_omit_list WHERE view_id = {$view_id}");
            }
            break;
            // remove any records from the client_view and public_view_omit_list tables concerned clients NOT associated
            // with this form.
        // remove any records from the client_view and public_view_omit_list tables concerned clients NOT associated
        // with this form.
        case "private":
            mysql_query("DELETE FROM {$g_table_prefix}public_form_omit_list WHERE form_id = {$form_id}");
            $client_clauses = array();
            foreach ($client_ids as $client_id) {
                $client_clauses[] = "account_id != {$client_id}";
            }
            // there WERE clients associated with this form. Delete the ones that AREN'T associated
            if (!empty($client_clauses)) {
                $client_id_clause = implode(" AND ", $client_clauses);
                mysql_query("DELETE FROM {$g_table_prefix}client_views WHERE form_id = {$form_id} AND {$client_id_clause}");
                // also delete any orphaned records in the View omit list
                $view_ids = ft_get_view_ids($form_id);
                foreach ($view_ids as $view_id) {
                    mysql_query("DELETE FROM {$g_table_prefix}public_view_omit_list WHERE view_id = {$view_id} AND {$client_id_clause}");
                }
            } else {
                $view_ids = ft_get_view_ids($form_id);
                foreach ($view_ids as $view_id) {
                    mysql_query("DELETE FROM {$g_table_prefix}client_views WHERE view_id = {$view_id}");
                    mysql_query("DELETE FROM {$g_table_prefix}public_view_omit_list WHERE view_id = {$view_id}");
                }
            }
            break;
    }
    // update the multi-page form URLs
    mysql_query("DELETE FROM {$g_table_prefix}multi_page_form_urls WHERE form_id = {$form_id}");
    // if this is a multi-page form, add the list of pages in the form. One minor thing to note: the first page in the form
    // is actually stored in two locations: one in the main "form_url" value in the form, and two, here in the multi_page_form_urls
    // table. It's not necessary, of course, but it makes the code a little simpler
    if ($is_multi_page_form == "yes") {
        $page_num = 1;
        foreach ($infohash["multi_page_urls"] as $url) {
            if (empty($url)) {
                continue;
            }
            mysql_query("INSERT INTO {$g_table_prefix}multi_page_form_urls (form_id, form_url, page_num) VALUES ({$form_id}, '{$url}', {$page_num})");
            $page_num++;
        }
    }
    extract(ft_process_hook_calls("end", compact("infohash", "form_id", "success", "message"), array("success", "message")), EXTR_OVERWRITE);
    return array($success, $message);
}
Exemple #3
0
/**
 * Caches the total number of (finalized) submissions in a particular form - or all forms -
 * in the $_SESSION["ft"]["form_{$form_id}_num_submissions"] key. That value is used on the administrators
 * main Forms page to list the form submission count.
 *
 * @param integer $form_id
 */
function _ft_cache_view_stats($form_id, $view_id = "")
{
    global $g_table_prefix;
    $view_ids = array();
    if (empty($view_id)) {
        $view_ids = ft_get_view_ids($form_id);
    } else {
        $view_ids[] = $view_id;
    }
    foreach ($view_ids as $view_id) {
        $filters = ft_get_view_filter_sql($view_id);
        // if there aren't any filters, just set the submission count & first submission date to the same
        // as the parent form
        if (empty($filters)) {
            $_SESSION["ft"]["view_{$view_id}_num_submissions"] = $_SESSION["ft"]["form_{$form_id}_num_submissions"];
        } else {
            $filter_clause = join(" AND ", $filters);
            $count_query = mysql_query("\r\n        SELECT count(*) as c\r\n        FROM   {$g_table_prefix}form_{$form_id}\r\n        WHERE  is_finalized = 'yes' AND\r\n        {$filter_clause}\r\n          ") or ft_handle_error("Failed query in <b>" . __FUNCTION__ . "</b>, line " . __LINE__, mysql_error());
            $info = mysql_fetch_assoc($count_query);
            $_SESSION["ft"]["view_{$view_id}_num_submissions"] = $info["c"];
        }
    }
}