function mf_theme_get_css_content($dbh, $theme_id)
{
    $css_content = "/** DO NOT MODIFY THIS FILE. All code here are generated by MachForm Theme Editor **/\n\n";
    $theme_properties = new stdClass();
    $mf_settings = mf_get_settings($dbh);
    $ssl_suffix = mf_get_ssl_suffix();
    if (!empty($ssl_suffix)) {
        $mf_settings['base_url'] = str_replace('http', 'https', $mf_settings['base_url']);
    }
    $query = "SELECT\r\n\t\t\t\t\t\ttheme_name,\r\n\t\t\t\t\t\tlogo_type,\r\n\t\t\t\t\t\tifnull(logo_custom_image,'') logo_custom_image,\r\n\t\t\t\t\t\tlogo_custom_height,\r\n\t\t\t\t\t\tlogo_default_image,\r\n\t\t\t\t\t\twallpaper_bg_type,\r\n\t\t\t\t\t\twallpaper_bg_color,\r\n\t\t\t\t\t\twallpaper_bg_pattern,\r\n\t\t\t\t\t\twallpaper_bg_custom,\r\n\t\t\t\t\t\theader_bg_type,\r\n\t\t\t\t\t\theader_bg_color,\r\n\t\t\t\t\t\theader_bg_pattern,\r\n\t\t\t\t\t\theader_bg_custom,\r\n\t\t\t\t\t\tform_bg_type,\r\n\t\t\t\t\t\tform_bg_color,\r\n\t\t\t\t\t\tform_bg_pattern,\r\n\t\t\t\t\t\tform_bg_custom,\r\n\t\t\t\t\t\thighlight_bg_type,\r\n\t\t\t\t\t\thighlight_bg_color,\r\n\t\t\t\t\t\thighlight_bg_pattern,\r\n\t\t\t\t\t\thighlight_bg_custom,\r\n\t\t\t\t\t\tguidelines_bg_type,\r\n\t\t\t\t\t\tguidelines_bg_color,\r\n\t\t\t\t\t\tguidelines_bg_pattern,\r\n\t\t\t\t\t\tguidelines_bg_custom,\r\n\t\t\t\t\t\tfield_bg_type,\r\n\t\t\t\t\t\tfield_bg_color,\r\n\t\t\t\t\t\tfield_bg_pattern,\r\n\t\t\t\t\t\tfield_bg_custom,\r\n\t\t\t\t\t\tform_title_font_type,\r\n\t\t\t\t\t\tform_title_font_weight,\r\n\t\t\t\t\t\tform_title_font_style,\r\n\t\t\t\t\t\tform_title_font_size,\r\n\t\t\t\t\t\tform_title_font_color,\r\n\t\t\t\t\t\tform_desc_font_type,\r\n\t\t\t\t\t\tform_desc_font_weight,\r\n\t\t\t\t\t\tform_desc_font_style,\r\n\t\t\t\t\t\tform_desc_font_size,\r\n\t\t\t\t\t\tform_desc_font_color,\r\n\t\t\t\t\t\tfield_title_font_type,\r\n\t\t\t\t\t\tfield_title_font_weight,\r\n\t\t\t\t\t\tfield_title_font_style,\r\n\t\t\t\t\t\tfield_title_font_size,\r\n\t\t\t\t\t\tfield_title_font_color,\r\n\t\t\t\t\t\tguidelines_font_type,\r\n\t\t\t\t\t\tguidelines_font_weight,\r\n\t\t\t\t\t\tguidelines_font_style,\r\n\t\t\t\t\t\tguidelines_font_size,\r\n\t\t\t\t\t\tguidelines_font_color,\r\n\t\t\t\t\t\tsection_title_font_type,\r\n\t\t\t\t\t\tsection_title_font_weight,\r\n\t\t\t\t\t\tsection_title_font_style,\r\n\t\t\t\t\t\tsection_title_font_size,\r\n\t\t\t\t\t\tsection_title_font_color,\r\n\t\t\t\t\t\tsection_desc_font_type,\r\n\t\t\t\t\t\tsection_desc_font_weight,\r\n\t\t\t\t\t\tsection_desc_font_style,\r\n\t\t\t\t\t\tsection_desc_font_size,\r\n\t\t\t\t\t\tsection_desc_font_color,\r\n\t\t\t\t\t\tfield_text_font_type,\r\n\t\t\t\t\t\tfield_text_font_weight,\r\n\t\t\t\t\t\tfield_text_font_style,\r\n\t\t\t\t\t\tfield_text_font_size,\r\n\t\t\t\t\t\tfield_text_font_color,\r\n\t\t\t\t\t\tborder_form_width,\r\n\t\t\t\t\t\tborder_form_style,\r\n\t\t\t\t\t\tborder_form_color,\r\n\t\t\t\t\t\tborder_guidelines_width,\r\n\t\t\t\t\t\tborder_guidelines_style,\r\n\t\t\t\t\t\tborder_guidelines_color,\r\n\t\t\t\t\t\tborder_section_width,\r\n\t\t\t\t\t\tborder_section_style,\r\n\t\t\t\t\t\tborder_section_color,\r\n\t\t\t\t\t\tform_shadow_style,\r\n\t\t\t\t\t\tform_shadow_size,\r\n\t\t\t\t\t\tform_shadow_brightness,\r\n\t\t\t\t\t\tform_button_type,\r\n\t\t\t\t\t\tform_button_text,\r\n\t\t\t\t\t\tform_button_image,\r\n\t\t\t\t\t\tadvanced_css\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\t`" . MF_TABLE_PREFIX . "form_themes`\r\n\t\t\t\t   WHERE\r\n\t\t\t\t   \t\ttheme_id=? and `status`=1";
    $params = array($theme_id);
    $sth = mf_do_query($query, $params, $dbh);
    $row = mf_do_fetch_result($sth);
    $theme_properties->theme_id = $theme_id;
    $theme_properties->theme_name = $row['theme_name'];
    $theme_properties->logo_type = $row['logo_type'];
    $theme_properties->logo_custom_image = $row['logo_custom_image'];
    $theme_properties->logo_custom_height = (int) $row['logo_custom_height'];
    $theme_properties->logo_default_image = $row['logo_default_image'];
    $theme_properties->wallpaper_bg_type = $row['wallpaper_bg_type'];
    $theme_properties->wallpaper_bg_color = $row['wallpaper_bg_color'];
    $theme_properties->wallpaper_bg_pattern = $row['wallpaper_bg_pattern'];
    $theme_properties->wallpaper_bg_custom = $row['wallpaper_bg_custom'];
    $theme_properties->header_bg_type = $row['header_bg_type'];
    $theme_properties->header_bg_color = $row['header_bg_color'];
    $theme_properties->header_bg_pattern = $row['header_bg_pattern'];
    $theme_properties->header_bg_custom = $row['header_bg_custom'];
    $theme_properties->form_bg_type = $row['form_bg_type'];
    $theme_properties->form_bg_color = $row['form_bg_color'];
    $theme_properties->form_bg_pattern = $row['form_bg_pattern'];
    $theme_properties->form_bg_custom = $row['form_bg_custom'];
    $theme_properties->highlight_bg_type = $row['highlight_bg_type'];
    $theme_properties->highlight_bg_color = $row['highlight_bg_color'];
    $theme_properties->highlight_bg_pattern = $row['highlight_bg_pattern'];
    $theme_properties->highlight_bg_custom = $row['highlight_bg_custom'];
    $theme_properties->guidelines_bg_type = $row['guidelines_bg_type'];
    $theme_properties->guidelines_bg_color = $row['guidelines_bg_color'];
    $theme_properties->guidelines_bg_pattern = $row['guidelines_bg_pattern'];
    $theme_properties->guidelines_bg_custom = $row['guidelines_bg_custom'];
    $theme_properties->field_bg_type = $row['field_bg_type'];
    $theme_properties->field_bg_color = $row['field_bg_color'];
    $theme_properties->field_bg_pattern = $row['field_bg_pattern'];
    $theme_properties->field_bg_custom = $row['field_bg_custom'];
    $theme_properties->form_title_font_type = $row['form_title_font_type'];
    $theme_properties->form_title_font_weight = (int) $row['form_title_font_weight'];
    $theme_properties->form_title_font_style = $row['form_title_font_style'];
    $theme_properties->form_title_font_size = $row['form_title_font_size'];
    $theme_properties->form_title_font_color = $row['form_title_font_color'];
    $theme_properties->form_desc_font_type = $row['form_desc_font_type'];
    $theme_properties->form_desc_font_weight = (int) $row['form_desc_font_weight'];
    $theme_properties->form_desc_font_style = $row['form_desc_font_style'];
    $theme_properties->form_desc_font_size = $row['form_desc_font_size'];
    $theme_properties->form_desc_font_color = $row['form_desc_font_color'];
    $theme_properties->field_title_font_type = $row['field_title_font_type'];
    $theme_properties->field_title_font_weight = (int) $row['field_title_font_weight'];
    $theme_properties->field_title_font_style = $row['field_title_font_style'];
    $theme_properties->field_title_font_size = $row['field_title_font_size'];
    $theme_properties->field_title_font_color = $row['field_title_font_color'];
    $theme_properties->guidelines_font_type = $row['guidelines_font_type'];
    $theme_properties->guidelines_font_weight = (int) $row['guidelines_font_weight'];
    $theme_properties->guidelines_font_style = $row['guidelines_font_style'];
    $theme_properties->guidelines_font_size = $row['guidelines_font_size'];
    $theme_properties->guidelines_font_color = $row['guidelines_font_color'];
    $theme_properties->section_title_font_type = $row['section_title_font_type'];
    $theme_properties->section_title_font_weight = (int) $row['section_title_font_weight'];
    $theme_properties->section_title_font_style = $row['section_title_font_style'];
    $theme_properties->section_title_font_size = $row['section_title_font_size'];
    $theme_properties->section_title_font_color = $row['section_title_font_color'];
    $theme_properties->section_desc_font_type = $row['section_desc_font_type'];
    $theme_properties->section_desc_font_weight = (int) $row['section_desc_font_weight'];
    $theme_properties->section_desc_font_style = $row['section_desc_font_style'];
    $theme_properties->section_desc_font_size = $row['section_desc_font_size'];
    $theme_properties->section_desc_font_color = $row['section_desc_font_color'];
    $theme_properties->field_text_font_type = $row['field_text_font_type'];
    $theme_properties->field_text_font_weight = (int) $row['field_text_font_weight'];
    $theme_properties->field_text_font_style = $row['field_text_font_style'];
    $theme_properties->field_text_font_size = $row['field_text_font_size'];
    $theme_properties->field_text_font_color = $row['field_text_font_color'];
    $theme_properties->border_form_width = (int) $row['border_form_width'];
    $theme_properties->border_form_style = $row['border_form_style'];
    $theme_properties->border_form_color = $row['border_form_color'];
    $theme_properties->border_guidelines_width = (int) $row['border_guidelines_width'];
    $theme_properties->border_guidelines_style = $row['border_guidelines_style'];
    $theme_properties->border_guidelines_color = $row['border_guidelines_color'];
    $theme_properties->border_section_width = (int) $row['border_section_width'];
    $theme_properties->border_section_style = $row['border_section_style'];
    $theme_properties->border_section_color = $row['border_section_color'];
    $theme_properties->form_shadow_style = $row['form_shadow_style'];
    $theme_properties->form_shadow_size = $row['form_shadow_size'];
    $theme_properties->form_shadow_brightness = $row['form_shadow_brightness'];
    $theme_properties->form_button_type = $row['form_button_type'];
    $theme_properties->form_button_text = $row['form_button_text'];
    $theme_properties->form_button_image = $row['form_button_image'];
    $theme_properties->advanced_css = $row['advanced_css'];
    /** Form Logo **/
    $form_logo_style = "#main_body h1 a";
    $form_logo_style .= "\n" . "{" . "\n";
    $form_logo_height = 40;
    if ($theme_properties->logo_type == 'disabled') {
        //logo disabled
        $form_logo_style .= "background-image: none;" . "\n";
    } else {
        if ($theme_properties->logo_type == 'default') {
            //default logo
            $form_logo_style .= "background-image: url('{$mf_settings['base_url']}images/form_resources/{$theme_properties->logo_default_image}');" . "\n";
            $form_logo_style .= "background-repeat: no-repeat;" . "\n";
        } else {
            if ($theme_properties->logo_type == 'custom') {
                //custom logo
                $form_logo_style .= "background-image: url('{$theme_properties->logo_custom_image}');" . "\n";
                $form_logo_height = $theme_properties->logo_custom_height;
            }
        }
    }
    $form_logo_style .= "height: {$form_logo_height}px;" . "\n";
    $form_logo_style .= "}" . "\n\n";
    $css_content .= $form_logo_style;
    /** Wallpaper **/
    $form_wallpaper_style = "html";
    $form_wallpaper_style .= "\n" . "{" . "\n";
    if ($theme_properties->wallpaper_bg_type == 'color') {
        $form_wallpaper_style .= "background-color: {$theme_properties->wallpaper_bg_color};" . "\n";
    } else {
        if ($theme_properties->wallpaper_bg_type == 'pattern') {
            $form_wallpaper_style .= "background-image: url('{$mf_settings['base_url']}images/form_resources/{$theme_properties->wallpaper_bg_pattern}');" . "\n";
            $form_wallpaper_style .= "background-repeat: repeat;" . "\n";
        } else {
            if ($theme_properties->wallpaper_bg_type == 'custom') {
                $form_wallpaper_style .= "background-image: url('{$theme_properties->wallpaper_bg_custom}');" . "\n";
                $form_wallpaper_style .= "background-repeat: repeat;" . "\n";
            }
        }
    }
    $form_wallpaper_style .= "}" . "\n\n";
    $css_content .= $form_wallpaper_style;
    /** Form Header **/
    $form_header_style = "#main_body h1";
    $form_header_style .= "\n" . "{" . "\n";
    if ($theme_properties->header_bg_type == 'color') {
        $form_header_style .= "background-color: {$theme_properties->header_bg_color};" . "\n";
    } else {
        if ($theme_properties->header_bg_type == 'pattern') {
            $form_header_style .= "background-image: url('{$mf_settings['base_url']}images/form_resources/{$theme_properties->header_bg_pattern}');" . "\n";
            $form_header_style .= "background-repeat: repeat;" . "\n";
        } else {
            if ($theme_properties->header_bg_type == 'custom') {
                $form_header_style .= "background-image: url('{$theme_properties->header_bg_custom}');" . "\n";
                $form_header_style .= "background-repeat: repeat;" . "\n";
            }
        }
    }
    $form_header_style .= "}" . "\n\n";
    $css_content .= $form_header_style;
    /** Form Background **/
    $form_container_style = "#form_container";
    $form_container_style .= "\n" . "{" . "\n";
    if ($theme_properties->form_bg_type == 'color') {
        $form_container_style .= "background-color: {$theme_properties->form_bg_color};" . "\n";
    } else {
        if ($theme_properties->form_bg_type == 'pattern') {
            $form_container_style .= "background-image: url('{$mf_settings['base_url']}images/form_resources/{$theme_properties->form_bg_pattern}');" . "\n";
            $form_container_style .= "background-repeat: repeat;" . "\n";
        } else {
            if ($theme_properties->form_bg_type == 'custom') {
                $form_container_style .= "background-image: url('{$theme_properties->form_bg_custom}');" . "\n";
                $form_container_style .= "background-repeat: repeat;" . "\n";
            }
        }
    }
    /** Form Border **/
    if (!empty($theme_properties->border_form_width)) {
        $form_container_style .= "border-width: {$theme_properties->border_form_width}px;" . "\n";
    } else {
        $form_container_style .= "border-width: 0px;" . "\n";
    }
    if (!empty($theme_properties->border_form_style)) {
        $form_container_style .= "border-style: {$theme_properties->border_form_style};" . "\n";
    }
    if (!empty($theme_properties->border_form_color)) {
        $form_container_style .= "border-color: {$theme_properties->border_form_color};" . "\n";
    }
    $form_container_style .= "}" . "\n\n";
    $css_content .= $form_container_style;
    /** Field Highlight **/
    $field_highlight_style = "#main_body form li.highlighted,#main_body .matrix tbody tr:hover td,#machform_review_table tr.alt";
    $field_highlight_style .= "\n" . "{" . "\n";
    if ($theme_properties->highlight_bg_type == 'color') {
        $field_highlight_style .= "background-color: {$theme_properties->highlight_bg_color};" . "\n";
    } else {
        if ($theme_properties->highlight_bg_type == 'pattern') {
            $field_highlight_style .= "background-image: url('{$mf_settings['base_url']}images/form_resources/{$theme_properties->highlight_bg_pattern}');" . "\n";
            $field_highlight_style .= "background-repeat: repeat;" . "\n";
        } else {
            if ($theme_properties->highlight_bg_type == 'custom') {
                $field_highlight_style .= "background-image: url('{$theme_properties->highlight_bg_custom}');" . "\n";
                $field_highlight_style .= "background-repeat: repeat;" . "\n";
            }
        }
    }
    $field_highlight_style .= "}" . "\n\n";
    $css_content .= $field_highlight_style;
    /** Field Guidelines **/
    $field_guidelines_style = "#main_body form .guidelines";
    $field_guidelines_style .= "\n" . "{" . "\n";
    if ($theme_properties->guidelines_bg_type == 'color') {
        $field_guidelines_style .= "background-color: {$theme_properties->guidelines_bg_color};" . "\n";
    } else {
        if ($theme_properties->guidelines_bg_type == 'pattern') {
            $field_guidelines_style .= "background-image: url('{$mf_settings['base_url']}images/form_resources/{$theme_properties->guidelines_bg_pattern}');" . "\n";
            $field_guidelines_style .= "background-repeat: repeat;" . "\n";
        } else {
            if ($theme_properties->guidelines_bg_type == 'custom') {
                $field_guidelines_style .= "background-image: url('{$theme_properties->guidelines_bg_custom}');" . "\n";
                $field_guidelines_style .= "background-repeat: repeat;" . "\n";
            }
        }
    }
    //guidelines border
    if (!empty($theme_properties->border_guidelines_width)) {
        $field_guidelines_style .= "border-width: {$theme_properties->border_guidelines_width}px;" . "\n";
    } else {
        $field_guidelines_style .= "border-width: 0px;" . "\n";
    }
    if (!empty($theme_properties->border_guidelines_style)) {
        $field_guidelines_style .= "border-style: {$theme_properties->border_guidelines_style};" . "\n";
    }
    if (!empty($theme_properties->border_guidelines_color)) {
        $field_guidelines_style .= "border-color: {$theme_properties->border_guidelines_color};" . "\n";
    }
    $field_guidelines_style .= "}" . "\n\n";
    $css_content .= $field_guidelines_style;
    //guidelines font
    $field_guidelines_text_style = "#main_body form .guidelines small";
    $field_guidelines_text_style .= "\n" . "{" . "\n";
    if (!empty($theme_properties->guidelines_font_type)) {
        $field_guidelines_text_style .= "font-family: '{$theme_properties->guidelines_font_type}','Lucida Grande',Tahoma,Arial,sans-serif;" . "\n";
    }
    if (!empty($theme_properties->guidelines_font_weight)) {
        $field_guidelines_text_style .= "font-weight: {$theme_properties->guidelines_font_weight};" . "\n";
    }
    if (!empty($theme_properties->guidelines_font_style)) {
        $field_guidelines_text_style .= "font-style: {$theme_properties->guidelines_font_style};" . "\n";
    }
    if (!empty($theme_properties->guidelines_font_size)) {
        $field_guidelines_text_style .= "font-size: {$theme_properties->guidelines_font_size};" . "\n";
    }
    if (!empty($theme_properties->guidelines_font_color)) {
        $field_guidelines_text_style .= "color: {$theme_properties->guidelines_font_color};" . "\n";
    }
    $field_guidelines_text_style .= "}" . "\n\n";
    $css_content .= $field_guidelines_text_style;
    /** Field Box **/
    $field_box_style = "#main_body input.text,#main_body input.file,#main_body textarea.textarea,#main_body select.select,#main_body input.checkbox,#main_body input.radio";
    $field_box_style .= "\n" . "{" . "\n";
    if ($theme_properties->field_bg_type == 'color') {
        $field_box_style .= "background-color: {$theme_properties->field_bg_color};" . "\n";
    } else {
        if ($theme_properties->field_bg_type == 'pattern') {
            $field_box_style .= "background-image: url('{$mf_settings['base_url']}images/form_resources/{$theme_properties->field_bg_pattern}');" . "\n";
            $field_box_style .= "background-repeat: repeat;";
        } else {
            if ($theme_properties->field_bg_type == 'custom') {
                $field_box_style .= "background-image: url('{$theme_properties->field_bg_custom}');" . "\n";
                $field_box_style .= "background-repeat: repeat;" . "\n";
            }
        }
    }
    //field text values
    if (!empty($theme_properties->field_text_font_type)) {
        $field_box_style .= "font-family: '{$theme_properties->field_text_font_type}','Lucida Grande',Tahoma,Arial,sans-serif;" . "\n";
        $font_family_array .= $theme_properties->field_text_font_type;
    }
    if (!empty($theme_properties->field_text_font_weight)) {
        $field_box_style .= "font-weight: {$theme_properties->field_text_font_weight};" . "\n";
    }
    if (!empty($theme_properties->field_text_font_style)) {
        $field_box_style .= "font-style: {$theme_properties->field_text_font_style};" . "\n";
    }
    if (!empty($theme_properties->field_text_font_size)) {
        $field_box_style .= "font-size: {$theme_properties->field_text_font_size};" . "\n";
    }
    if (!empty($theme_properties->field_text_font_color)) {
        $field_box_style .= "color: {$theme_properties->field_text_font_color};" . "\n";
    }
    $field_box_style .= "}" . "\n\n";
    $css_content .= $field_box_style;
    /** Review Table, value section (right column) **/
    //this is similar as field box above, except without background
    $review_table_value_style = "#machform_review_table td.mf_review_value";
    $review_table_value_style .= "\n" . "{" . "\n";
    if (!empty($theme_properties->field_text_font_type)) {
        $review_table_value_style .= "font-family: '{$theme_properties->field_text_font_type}','Lucida Grande',Tahoma,Arial,sans-serif;" . "\n";
    }
    if (!empty($theme_properties->field_text_font_weight)) {
        $review_table_value_style .= "font-weight: {$theme_properties->field_text_font_weight};" . "\n";
    }
    if (!empty($theme_properties->field_text_font_style)) {
        $review_table_value_style .= "font-style: {$theme_properties->field_text_font_style};" . "\n";
    }
    if (!empty($theme_properties->field_text_font_size)) {
        $review_table_value_style .= "font-size: {$theme_properties->field_text_font_size};" . "\n";
    }
    //on review page, special for the value color should be the same as label color
    if (!empty($theme_properties->field_title_font_color)) {
        $review_table_value_style .= "color: {$theme_properties->field_title_font_color};" . "\n";
    }
    $review_table_value_style .= "}" . "\n\n";
    $css_content .= $review_table_value_style;
    /** Form Title **/
    $form_title_style = "#main_body .form_description h2,#main_body .form_success h2";
    $form_title_style .= "\n" . "{" . "\n";
    if (!empty($theme_properties->form_title_font_type)) {
        $form_title_style .= "font-family: '{$theme_properties->form_title_font_type}','Lucida Grande',Tahoma,Arial,sans-serif;" . "\n";
    }
    if (!empty($theme_properties->form_title_font_weight)) {
        $form_title_style .= "font-weight: {$theme_properties->form_title_font_weight};" . "\n";
    }
    if (!empty($theme_properties->form_title_font_style)) {
        $form_title_style .= "font-style: {$theme_properties->form_title_font_style};" . "\n";
    }
    if (!empty($theme_properties->form_title_font_size)) {
        $form_title_style .= "font-size: {$theme_properties->form_title_font_size};" . "\n";
    }
    if (!empty($theme_properties->form_title_font_color)) {
        $form_title_style .= "color: {$theme_properties->form_title_font_color};" . "\n";
    }
    $form_title_style .= "}" . "\n\n";
    $css_content .= $form_title_style;
    /** Form Description **/
    $form_desc_style = "#main_body .form_description p,#main_body form ul.payment_list_items li";
    $form_desc_style .= "\n" . "{" . "\n";
    if (!empty($theme_properties->form_desc_font_type)) {
        $form_desc_style .= "font-family: '{$theme_properties->form_desc_font_type}','Lucida Grande',Tahoma,Arial,sans-serif;" . "\n";
    }
    if (!empty($theme_properties->form_desc_font_weight)) {
        $form_desc_style .= "font-weight: {$theme_properties->form_desc_font_weight};" . "\n";
    }
    if (!empty($theme_properties->form_desc_font_style)) {
        $form_desc_style .= "font-style: {$theme_properties->form_desc_font_style};" . "\n";
    }
    if (!empty($theme_properties->form_desc_font_size)) {
        $form_desc_style .= "font-size: {$theme_properties->form_desc_font_size};" . "\n";
    }
    if (!empty($theme_properties->form_desc_font_color)) {
        $form_desc_style .= "color: {$theme_properties->form_desc_font_color};" . "\n";
    }
    $form_desc_style .= "}" . "\n\n";
    $css_content .= $form_desc_style;
    /** Pagination Text **/
    $pagination_desc_style = "#main_body form li span.ap_tp_text";
    $pagination_desc_style .= "\n" . "{" . "\n";
    if (!empty($theme_properties->form_desc_font_color)) {
        $pagination_desc_style .= "color: {$theme_properties->form_desc_font_color};" . "\n";
    }
    $pagination_desc_style .= "}" . "\n\n";
    $css_content .= $pagination_desc_style;
    /** Field Title **/
    $field_title_style = "#main_body label.description,#main_body .matrix caption,#main_body .matrix td.first_col,#main_body form li.total_payment span,#machform_review_table td.mf_review_label";
    $field_sub_title_style = "#main_body form li span label,#main_body label.choice,#main_body .matrix th,#main_body form li span.symbol,.mf_sigpad_clear,#main_body form li div label";
    $field_title_style .= "\n" . "{" . "\n";
    $field_sub_title_style .= "\n" . "{" . "\n";
    if (!empty($theme_properties->field_title_font_type)) {
        $field_title_style .= "font-family: '{$theme_properties->field_title_font_type}','Lucida Grande',Tahoma,Arial,sans-serif;" . "\n";
        $field_sub_title_style .= "font-family: '{$theme_properties->field_title_font_type}','Lucida Grande',Tahoma,Arial,sans-serif;" . "\n";
    }
    if (!empty($theme_properties->field_title_font_weight)) {
        $field_title_style .= "font-weight: {$theme_properties->field_title_font_weight};" . "\n";
    }
    if (!empty($theme_properties->field_title_font_style)) {
        $field_title_style .= "font-style: {$theme_properties->field_title_font_style};" . "\n";
    }
    if (!empty($theme_properties->field_title_font_size)) {
        $field_title_style .= "font-size: {$theme_properties->field_title_font_size};" . "\n";
    }
    if (!empty($theme_properties->field_title_font_color)) {
        $field_title_style .= "color: {$theme_properties->field_title_font_color};" . "\n";
        $field_sub_title_style .= "color: {$theme_properties->field_title_font_color};" . "\n";
    }
    $field_title_style .= "}" . "\n\n";
    $css_content .= $field_title_style;
    $field_sub_title_style .= "}" . "\n\n";
    $css_content .= $field_sub_title_style;
    /** Section Title **/
    $section_title_style = "#main_body form .section_break h3,#machform_review_table td .mf_section_title";
    $section_title_style .= "\n" . "{" . "\n";
    if (!empty($theme_properties->section_title_font_type)) {
        $section_title_style .= "font-family: '{$theme_properties->section_title_font_type}','Lucida Grande',Tahoma,Arial,sans-serif;" . "\n";
    }
    if (!empty($theme_properties->section_title_font_weight)) {
        $section_title_style .= "font-weight: {$theme_properties->section_title_font_weight};" . "\n";
    }
    if (!empty($theme_properties->section_title_font_style)) {
        $section_title_style .= "font-style: {$theme_properties->section_title_font_style};" . "\n";
    }
    if (!empty($theme_properties->section_title_font_size)) {
        $section_title_style .= "font-size: {$theme_properties->section_title_font_size};" . "\n";
    }
    if (!empty($theme_properties->section_title_font_color)) {
        $section_title_style .= "color: {$theme_properties->section_title_font_color};" . "\n";
    }
    $section_title_style .= "}" . "\n\n";
    $css_content .= $section_title_style;
    /** Section Description **/
    $section_desc_style = "#main_body form .section_break p,#machform_review_table td .mf_section_content";
    $section_desc_style .= "\n" . "{" . "\n";
    if (!empty($theme_properties->section_desc_font_type)) {
        $section_desc_style .= "font-family: '{$theme_properties->section_desc_font_type}','Lucida Grande',Tahoma,Arial,sans-serif;" . "\n";
    }
    if (!empty($theme_properties->section_desc_font_weight)) {
        $section_desc_style .= "font-weight: {$theme_properties->section_desc_font_weight};" . "\n";
    }
    if (!empty($theme_properties->section_desc_font_style)) {
        $section_desc_style .= "font-style: {$theme_properties->section_desc_font_style};" . "\n";
    }
    if (!empty($theme_properties->section_desc_font_size)) {
        $section_desc_style .= "font-size: {$theme_properties->section_desc_font_size};" . "\n";
    }
    if (!empty($theme_properties->section_desc_font_color)) {
        $section_desc_style .= "color: {$theme_properties->section_desc_font_color};" . "\n";
    }
    $section_desc_style .= "}" . "\n\n";
    $css_content .= $section_desc_style;
    /** Section Block **/
    $section_block_style = "#main_body form li.section_break";
    $section_block_style .= "\n" . "{" . "\n";
    if (!empty($theme_properties->border_section_width)) {
        $section_block_style .= "border-top-width: {$theme_properties->border_section_width}px;" . "\n";
    } else {
        $section_block_style .= "border-top-width: 0px;" . "\n";
    }
    if (!empty($theme_properties->border_section_style)) {
        $section_block_style .= "border-top-style: {$theme_properties->border_section_style};" . "\n";
    }
    if (!empty($theme_properties->border_section_color)) {
        $section_block_style .= "border-top-color: {$theme_properties->border_section_color};" . "\n";
    }
    $section_block_style .= "}" . "\n\n";
    $css_content .= $section_block_style;
    /** Advanced CSS Code **/
    if (!empty($theme_properties->advanced_css)) {
        $css_content .= "\n\n" . '/** Advanced CSS **/' . "\n\n";
        $css_content .= $theme_properties->advanced_css;
    }
    return $css_content;
}
  
 Copyright 2007-2012 Appnitro Software. This code cannot be redistributed without
 permission from http://www.appnitro.com/
 
 More info at: http://www.appnitro.com/
 ********************************************************************************/
require 'includes/init.php';
require 'config.php';
require 'includes/db-core.php';
require 'includes/helper-functions.php';
require 'includes/check-session.php';
require 'includes/filter-functions.php';
require 'includes/theme-functions.php';
require 'includes/users-functions.php';
$dbh = mf_connect_db();
$mf_settings = mf_get_settings($dbh);
if (empty($_POST['form_id'])) {
    die("Error! You can't open this file directly");
}
$form_id = (int) $_POST['form_id'];
$theme_id = (int) $_POST['theme_id'];
//check permission, is the user allowed to access this page?
if (empty($_SESSION['mf_user_privileges']['priv_administer'])) {
    $user_perms = mf_get_user_permissions($dbh, $form_id, $_SESSION['mf_user_id']);
    //this page need edit_form permission
    if (empty($user_perms['edit_form'])) {
        die("Access Denied. You don't have permission to edit this form.");
    }
}
$query = "update " . MF_TABLE_PREFIX . "forms set form_theme_id=? where form_id=?";
$params = array($theme_id, $form_id);
Example #3
0
function mf_display_form_review($dbh, $form_id, $record_id, $from_page_num, $form_params = array())
{
    global $mf_lang;
    if (!empty($form_params['integration_method'])) {
        $integration_method = $form_params['integration_method'];
    } else {
        $integration_method = '';
    }
    if (!empty($form_params['machform_path'])) {
        $machform_path = $form_params['machform_path'];
    } else {
        $machform_path = '';
    }
    if (!empty($form_params['machform_data_path'])) {
        $machform_data_path = $form_params['machform_data_path'];
    } else {
        $machform_data_path = '';
    }
    $mf_settings = mf_get_settings($dbh);
    //get form properties data
    $query = "select \r\n\t\t\t\t\t\t  form_name,\r\n\t\t\t\t\t\t  form_has_css,\r\n\t\t\t\t\t\t  form_redirect,\r\n\t\t\t\t\t\t  form_review_primary_text,\r\n\t\t\t\t\t\t  form_review_secondary_text,\r\n\t\t\t\t\t\t  form_review_primary_img,\r\n\t\t\t\t\t\t  form_review_secondary_img,\r\n\t\t\t\t\t\t  form_review_use_image,\r\n\t\t\t\t\t\t  form_review_title,\r\n\t\t\t\t\t\t  form_review_description,\r\n\t\t\t\t\t\t  form_page_total,\r\n\t\t\t\t\t\t  form_lastpage_title,\r\n\t\t\t\t\t\t  form_pagination_type,\r\n\t\t\t\t\t\t  form_theme_id,\r\n\t\t\t\t\t\t  payment_show_total,\r\n\t\t\t\t\t\t  payment_total_location,\r\n\t\t\t\t\t\t  payment_enable_merchant,\r\n\t\t\t\t\t\t  payment_currency,\r\n\t\t\t\t\t\t  payment_price_type,\r\n\t\t\t\t\t\t  payment_price_amount\r\n\t\t\t\t     from \r\n\t\t\t\t     \t " . MF_TABLE_PREFIX . "forms \r\n\t\t\t\t    where \r\n\t\t\t\t    \t form_id=?";
    $params = array($form_id);
    $sth = mf_do_query($query, $params, $dbh);
    $row = mf_do_fetch_result($sth);
    $form_has_css = $row['form_has_css'];
    $form_redirect = $row['form_redirect'];
    $form_review_primary_text = $row['form_review_primary_text'];
    $form_review_secondary_text = $row['form_review_secondary_text'];
    $form_review_primary_img = $row['form_review_primary_img'];
    $form_review_secondary_img = $row['form_review_secondary_img'];
    $form_review_use_image = (int) $row['form_review_use_image'];
    $form_review_title = $row['form_review_title'];
    $form_review_description = $row['form_review_description'];
    $form_page_total = $row['form_page_total'];
    $form_lastpage_title = $row['form_lastpage_title'];
    $form_pagination_type = $row['form_pagination_type'];
    $form_name = htmlspecialchars($row['form_name'], ENT_QUOTES);
    $form_theme_id = $row['form_theme_id'];
    $payment_show_total = (int) $row['payment_show_total'];
    $payment_total_location = $row['payment_total_location'];
    $payment_enable_merchant = (int) $row['payment_enable_merchant'];
    if ($payment_enable_merchant < 1) {
        $payment_enable_merchant = 0;
    }
    $payment_currency = $row['payment_currency'];
    $payment_price_type = $row['payment_price_type'];
    $payment_price_amount = $row['payment_price_amount'];
    //prepare entry data for previewing
    $param['strip_download_link'] = true;
    $param['review_mode'] = true;
    $param['show_attach_image'] = true;
    $param['machform_data_path'] = $machform_data_path;
    $entry_details = mf_get_entry_details($dbh, $form_id, $record_id, $param);
    $entry_data = '<table id="machform_review_table" width="100%" border="0" cellspacing="0" cellpadding="0"><tbody>' . "\n";
    $toggle = false;
    foreach ($entry_details as $data) {
        if ($toggle) {
            $toggle = false;
            $row_style = 'class="alt"';
        } else {
            $toggle = true;
            $row_style = '';
        }
        if ($data['label'] == 'mf_page_break' && $data['value'] == 'mf_page_break') {
            $data['label'] = '&nbsp;';
            $data['value'] = '&nbsp;';
            $row_style = '';
        }
        $entry_data .= "<tr {$row_style}>\n";
        $entry_data .= "<td class=\"mf_review_label\" width=\"40%\">{$data['label']}</td>\n";
        $entry_data .= "<td class=\"mf_review_value\" width=\"60%\">" . nl2br($data['value']) . "</td>\n";
        $entry_data .= "</tr>\n";
    }
    $entry_data .= '</tbody></table>';
    //check for specific form css, if any, use it instead
    if ($form_has_css) {
        $css_dir = $mf_settings['data_dir'] . "/form_{$form_id}/css/";
    }
    if ($integration_method == 'iframe') {
        $embed_class = 'class="embed"';
    }
    //if the form has multiple pages
    //display the pagination header
    if ($form_page_total > 1) {
        //build pagination header based on the selected type. possible values:
        //steps - display multi steps progress
        //percentage - display progress bar with percentage
        //disabled - disabled
        $page_breaks_data = array();
        $page_title_array = array();
        //get page titles
        $query = "SELECT \r\n\t\t\t\t\t\t\telement_page_title\r\n\t\t\t\t\t\tFROM \r\n\t\t\t\t\t\t\t" . MF_TABLE_PREFIX . "form_elements\r\n\t\t\t\t\t   WHERE\r\n\t\t\t\t\t\t\tform_id = ? and element_status = 1 and element_type = 'page_break'\r\n\t\t\t\t\tORDER BY \r\n\t\t\t\t\t   \t\telement_page_number asc";
        $params = array($form_id);
        $sth = mf_do_query($query, $params, $dbh);
        while ($row = mf_do_fetch_result($sth)) {
            $page_title_array[] = $row['element_page_title'];
        }
        if ($form_pagination_type == 'steps') {
            $page_titles_markup = '';
            $i = 1;
            foreach ($page_title_array as $page_title) {
                $page_titles_markup .= '<td align="center"><span id="page_num_' . $i . '" class="ap_tp_num">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text">' . $page_title . '</span></td><td align="center" class="ap_tp_arrow">&gt;</td>' . "\n";
                $i++;
            }
            //add the last page title into the pagination header markup
            $page_titles_markup .= '<td align="center"><span id="page_num_' . $i . '" class="ap_tp_num">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text">' . $form_lastpage_title . '</span></td>';
            $i++;
            $page_titles_markup .= '<td align="center" class="ap_tp_arrow">&gt;</td><td align="center"><span id="page_num_' . $i . '" class="ap_tp_num ap_tp_num_active">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text ap_tp_text_active">' . $form_review_title . '</span></td>';
            $pagination_header = <<<EOT
\t\t\t<ul>
\t\t\t<li id="pagination_header" class="li_pagination">
\t\t\t <table class="ap_table_pagination" width="100%" border="0" cellspacing="0" cellpadding="0">
\t\t\t  <tr> 
\t\t\t  \t{$page_titles_markup}
\t\t\t  </tr>
\t\t\t</table>
\t\t\t</li>
\t\t\t</ul>
EOT;
        } else {
            if ($form_pagination_type == 'percentage') {
                $page_total = count($page_title_array) + 2;
                $percent_value = 99;
                $page_number_title = sprintf($mf_lang['page_title'], $page_total, $page_total);
                $pagination_header = <<<EOT
\t\t\t<ul>
\t\t\t\t<li id="pagination_header" class="li_pagination" title="Click to edit">
\t\t\t    <h3 id="page_title_{$page_total}">{$page_number_title}</h3>
\t\t\t\t<div class="mf_progress_container">          
\t\t\t    \t<div id="mf_progress_percentage" class="mf_progress_value" style="width: {$percent_value}%"><span>{$percent_value}%</span></div>
\t\t\t\t</div>
\t\t\t\t</li>
\t\t\t</ul>
EOT;
            } else {
                $pagination_header = '';
            }
        }
    }
    //build the button markup (image or text)
    if (!empty($form_review_use_image)) {
        $button_markup = <<<EOT
<input id="review_submit" class="submit_img_primary" type="image" name="review_submit" alt="{$form_review_primary_text}" src="{$form_review_primary_img}" />
<input id="review_back" class="submit_img_secondary" type="image" name="review_back" alt="{$form_review_secondary_text}" src="{$form_review_secondary_img}" />
EOT;
    } else {
        $button_markup = <<<EOT
<input id="review_submit" class="button_text btn_primary" type="submit" name="review_submit" value="{$form_review_primary_text}" />
<input id="review_back" class="button_text btn_secondary" type="submit" name="review_back" value="{$form_review_secondary_text}" />
EOT;
    }
    //if this form is using custom theme
    if (!empty($form_theme_id)) {
        //get the field highlight color for the particular theme
        $query = "SELECT \r\n\t\t\t\t\t\t\thighlight_bg_type,\r\n\t\t\t\t\t\t\thighlight_bg_color,\r\n\t\t\t\t\t\t\tform_shadow_style,\r\n\t\t\t\t\t\t\tform_shadow_size,\r\n\t\t\t\t\t\t\tform_shadow_brightness,\r\n\t\t\t\t\t\t\tform_button_type,\r\n\t\t\t\t\t\t\tform_button_text,\r\n\t\t\t\t\t\t\tform_button_image,\r\n\t\t\t\t\t\t\ttheme_has_css  \r\n\t\t\t\t\t\tFROM \r\n\t\t\t\t\t\t\t" . MF_TABLE_PREFIX . "form_themes \r\n\t\t\t\t\t   WHERE \r\n\t\t\t\t\t   \t\ttheme_id = ?";
        $params = array($form_theme_id);
        $sth = mf_do_query($query, $params, $dbh);
        $row = mf_do_fetch_result($sth);
        $form_shadow_style = $row['form_shadow_style'];
        $form_shadow_size = $row['form_shadow_size'];
        $form_shadow_brightness = $row['form_shadow_brightness'];
        $theme_has_css = (int) $row['theme_has_css'];
        //if the theme has css file, make sure to refer to that file
        //otherwise, generate the css dynamically
        if (!empty($theme_has_css)) {
            $theme_css_link = '<link rel="stylesheet" type="text/css" href="' . $machform_path . $mf_settings['data_dir'] . '/themes/theme_' . $form_theme_id . '.css" media="all" />';
        } else {
            $theme_css_link = '<link rel="stylesheet" type="text/css" href="' . $machform_path . 'css_theme.php?theme_id=' . $form_theme_id . '" media="all" />';
        }
        if ($row['highlight_bg_type'] == 'color') {
            $field_highlight_color = $row['highlight_bg_color'];
        } else {
            //if the field highlight is using pattern instead of color, set the color to empty string
            $field_highlight_color = '';
        }
        //get the css link for the fonts
        $font_css_markup = mf_theme_get_fonts_link($dbh, $form_theme_id);
        //get the form shadow classes
        if (!empty($form_shadow_style) && $form_shadow_style != 'disabled') {
            preg_match_all("/[A-Z]/", $form_shadow_style, $prefix_matches);
            //this regex simply get the capital characters of the shadow style name
            //example: RightPerspectiveShadow result to RPS and then being sliced to RP
            $form_shadow_prefix_code = substr(implode("", $prefix_matches[0]), 0, -1);
            $form_shadow_size_class = $form_shadow_prefix_code . ucfirst($form_shadow_size);
            $form_shadow_brightness_class = $form_shadow_prefix_code . ucfirst($form_shadow_brightness);
            if (empty($integration_method)) {
                //only display shadow if the form is not being embedded using any method
                $form_container_class = $form_shadow_style . ' ' . $form_shadow_size_class . ' ' . $form_shadow_brightness_class;
            }
        }
    } else {
        //if the form doesn't have any theme being applied
        $field_highlight_color = '#FFF7C0';
        if (empty($integration_method)) {
            $form_container_class = 'WarpShadow WLarge WNormal';
            //default shadow
        } else {
            $form_container_class = '';
            //dont show any shadow when the form being embedded
        }
    }
    //if the form has enabled merchant support and set the total payment to be displayed
    if (!empty($payment_enable_merchant) && !empty($payment_show_total)) {
        $currency_symbol = '&#36;';
        switch ($payment_currency) {
            case 'USD':
                $currency_symbol = '&#36;';
                break;
            case 'EUR':
                $currency_symbol = '&#8364;';
                break;
            case 'GBP':
                $currency_symbol = '&#163;';
                break;
            case 'AUD':
                $currency_symbol = 'A&#36;';
                break;
            case 'CAD':
                $currency_symbol = 'C&#36;';
                break;
            case 'JPY':
                $currency_symbol = '&#165;';
                break;
            case 'THB':
                $currency_symbol = '&#3647;';
                break;
            case 'HUF':
                $currency_symbol = '&#70;&#116;';
                break;
            case 'CHF':
                $currency_symbol = 'CHF';
                break;
            case 'CZK':
                $currency_symbol = '&#75;&#269;';
                break;
            case 'SEK':
                $currency_symbol = 'kr';
                break;
            case 'DKK':
                $currency_symbol = 'kr';
                break;
            case 'PHP':
                $currency_symbol = '&#36;';
                break;
            case 'MYR':
                $currency_symbol = 'RM';
                break;
            case 'PLN':
                $currency_symbol = '&#122;&#322;';
                break;
            case 'BRL':
                $currency_symbol = 'R&#36;';
                break;
            case 'HKD':
                $currency_symbol = 'HK&#36;';
                break;
            case 'MXN':
                $currency_symbol = 'Mex&#36;';
                break;
            case 'TWD':
                $currency_symbol = 'NT&#36;';
                break;
            case 'TRY':
                $currency_symbol = 'TL';
                break;
        }
        if ($payment_total_location == 'review' || $payment_total_location == 'all') {
            $session_id = session_id();
            if ($payment_price_type == 'variable') {
                $total_payment = (double) mf_get_payment_total($dbh, $form_id, $session_id, 0);
            } elseif ($payment_price_type == 'fixed') {
                $total_payment = $payment_price_amount;
            }
            $payment_total_markup = <<<EOT
\t\t\t\t<li class="total_payment mf_review">
\t\t\t\t\t<span>
\t\t\t\t\t\t<h3>{$currency_symbol}<var>{$total_payment}</var></h3>
\t\t\t\t\t\t<h5>{$mf_lang['payment_total']}</h5>
\t\t\t\t\t</span>
\t\t\t\t</li>
EOT;
        }
    }
    if (empty($mf_settings['disable_machform_link'])) {
        $powered_by_markup = 'Powered by MachForm';
    } else {
        $powered_by_markup = '';
    }
    $self_address = htmlentities($_SERVER['PHP_SELF']);
    //prevent XSS
    if ($integration_method == 'php') {
        $form_markup = <<<EOT
<link rel="stylesheet" type="text/css" href="data/form_default/css/view.css" media="all" />
{$theme_css_link}
{$font_css_markup}
<style>
html{
\tbackground: none repeat scroll 0 0 transparent;
}
</style>

<div id="main_body" class="integrated">
\t<div id="form_container">
\t\t<form id="form_{$form->id}" class="appnitro" method="post" action="{$self_address}">
\t\t    <div class="form_description">
\t\t\t\t<h2>{$form_review_title}</h2>
\t\t\t\t<p>{$form_review_description}</p>
\t\t\t</div>
\t\t\t{$pagination_header}
\t\t\t{$entry_data}
\t\t\t<ul>
\t\t\t{$payment_total_markup}
\t\t\t<li id="li_buttons" class="buttons">
\t\t\t    <input type="hidden" name="id" value="{$form_id}" />
\t\t\t    <input type="hidden" name="mf_page_from" value="{$from_page_num}" />
\t\t\t    {$button_markup}
\t\t\t</li>
\t\t\t</ul>
\t\t</form>\t\t
\t</div>
</div>
EOT;
    } else {
        if ($integration_method == 'iframe') {
            $auto_height_js = <<<EOT
<script type="text/javascript" src="{$machform_path}js/jquery.min.js"></script>
<script type="text/javascript" src="{$machform_path}js/jquery.ba-postmessage.min.js"></script>
<script type="text/javascript">
    \$(function(){
    \t\$.postMessage({mf_iframe_height: \$('body').outerHeight(true)}, '*', parent );
    });
</script>
EOT;
        }
        $form_markup = <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html {$embed_class} xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{$form_name}</title>
<link rel="stylesheet" type="text/css" href="data/form_default/css/view.css" media="all" />
{$theme_css_link}
{$font_css_markup}
{$auto_height_js}
</head>
<body id="main_body">
\t
\t<img id="top" src="{$machform_path}images/top.png" alt="" />
\t<div id="form_container" class="{$form_container_class}">
\t
\t\t<h1><a>MachForm</a></h1>
\t\t<form id="form_{$form_id}" class="appnitro" method="post" action="{$self_address}">
\t\t    <div class="form_description">
\t\t\t\t<h2>{$form_review_title}</h2>
\t\t\t\t<p>{$form_review_description}</p>
\t\t\t</div>
\t\t\t{$pagination_header}
\t\t\t{$entry_data}
\t\t\t<ul>
\t\t\t{$payment_total_markup}
\t\t\t<li id="li_buttons" class="buttons">
\t\t\t    <input type="hidden" name="id" value="{$form_id}" />
\t\t\t    <input type="hidden" name="mf_page_from" value="{$from_page_num}" />
\t\t\t    {$button_markup}
\t\t\t</li>
\t\t\t</ul>
\t\t</form>\t\t
\t\t\t
\t</div>
\t<img id="bottom" src="{$machform_path}images/bottom.png" alt="" />
\t</body>
</html>
EOT;
    }
    return $form_markup;
}
function mf_get_merchant_redirect_url($dbh, $form_id, $entry_id)
{
    $mf_settings = mf_get_settings($dbh);
    $merchant_redirect_url = '';
    $payment_has_value = false;
    $query = "select \r\n\t\t\t\t\t\t payment_enable_merchant,\r\n\t\t\t\t\t\t payment_merchant_type,\r\n\t\t\t\t\t\t ifnull(payment_paypal_email,'') payment_paypal_email,\r\n\t\t\t\t\t\t payment_paypal_language,\r\n\t\t\t\t\t\t payment_currency,\r\n\t\t\t\t\t\t payment_show_total,\r\n\t\t\t\t\t\t payment_total_location,\r\n\t\t\t\t\t\t payment_enable_recurring,\r\n\t\t\t\t\t\t payment_recurring_cycle,\r\n\t\t\t\t\t\t payment_recurring_unit,\r\n\t\t\t\t\t\t payment_enable_trial,\r\n\t\t\t\t\t\t payment_trial_period,\r\n\t\t\t\t\t\t payment_trial_unit,\r\n\t\t\t\t\t\t payment_trial_amount,\r\n\t\t\t\t\t\t payment_price_type,\r\n\t\t\t\t\t\t payment_price_amount,\r\n\t\t\t\t\t\t payment_price_name,\r\n\t\t\t\t\t\t payment_paypal_enable_test_mode,\r\n\t\t\t\t\t\t form_redirect,\r\n\t\t\t\t\t\t form_redirect_enable\r\n\t\t\t\t     from \r\n\t\t\t\t     \t `" . MF_TABLE_PREFIX . "forms` \r\n\t\t\t\t    where \r\n\t\t\t\t    \t form_id=?";
    $params = array($form_id);
    $sth = mf_do_query($query, $params, $dbh);
    $row = mf_do_fetch_result($sth);
    $payment_enable_merchant = (int) $row['payment_enable_merchant'];
    if ($payment_enable_merchant < 1) {
        $payment_enable_merchant = 0;
    }
    $payment_merchant_type = $row['payment_merchant_type'];
    $payment_paypal_email = $row['payment_paypal_email'];
    $payment_paypal_language = $row['payment_paypal_language'];
    $payment_currency = $row['payment_currency'];
    $payment_show_total = (int) $row['payment_show_total'];
    $payment_total_location = $row['payment_total_location'];
    $payment_enable_recurring = (int) $row['payment_enable_recurring'];
    $payment_recurring_cycle = (int) $row['payment_recurring_cycle'];
    $payment_recurring_unit = $row['payment_recurring_unit'];
    $payment_paypal_enable_test_mode = (int) $row['payment_paypal_enable_test_mode'];
    if (!empty($payment_paypal_enable_test_mode)) {
        $paypal_url = "www.sandbox.paypal.com";
    } else {
        $paypal_url = "www.paypal.com";
    }
    $payment_enable_trial = (int) $row['payment_enable_trial'];
    $payment_trial_period = (int) $row['payment_trial_period'];
    $payment_trial_unit = $row['payment_trial_unit'];
    $payment_trial_amount = $row['payment_trial_amount'];
    $payment_price_type = $row['payment_price_type'];
    $payment_price_amount = (double) $row['payment_price_amount'];
    $payment_price_name = $row['payment_price_name'];
    if (!empty($row['form_redirect_enable'])) {
        $form_redirect = $row['form_redirect'];
    }
    if (!empty($payment_enable_merchant)) {
        //if merchant is enabled
        //paypal website payment standard
        if ($payment_merchant_type == 'paypal_standard') {
            //get current entry timestamp
            $query = "select unix_timestamp(date_created) entry_timestamp from " . MF_TABLE_PREFIX . "form_{$form_id} where `id` = ? and `status` = 1";
            $params = array($entry_id);
            $sth = mf_do_query($query, $params, $dbh);
            $row = mf_do_fetch_result($sth);
            $entry_timestamp = $row['entry_timestamp'];
            $paypal_params = array();
            $paypal_params['charset'] = 'UTF-8';
            $paypal_params['upload'] = 1;
            $paypal_params['business'] = $payment_paypal_email;
            $paypal_params['currency_code'] = $payment_currency;
            $paypal_params['custom'] = $form_id . '_' . $entry_id . '_' . $entry_timestamp;
            $paypal_params['rm'] = 2;
            //the buyer’s browser is redirected to the return URL by using the POST method, and all payment variables are included
            $paypal_params['lc'] = $payment_paypal_language;
            if (!empty($form_redirect)) {
                $paypal_params['return'] = $form_redirect;
            } else {
                $paypal_params['return'] = $mf_settings['base_url'] . 'view.php?id=' . $form_id . '&done=1';
            }
            $paypal_params['notify_url'] = $mf_settings['base_url'] . 'paypal_ipn.php';
            $paypal_params['no_shipping'] = 1;
            if (!empty($payment_enable_recurring)) {
                //this is recurring payment
                $paypal_params['cmd'] = '_xclick-subscriptions';
                $paypal_params['src'] = 1;
                //subscription payments recur, until user cancel it
                $paypal_params['sra'] = 1;
                //reattempt failed recurring payments before canceling
                $paypal_params['item_name'] = $payment_price_name;
                $paypal_params['p3'] = $payment_recurring_cycle;
                $paypal_params['t3'] = strtoupper($payment_recurring_unit[0]);
                if ($paypal_params['t3'] == 'Y' && $payment_recurring_cycle > 5) {
                    $paypal_params['p3'] = 5;
                    //paypal can only handle 5-year-period recurring payments, maximum
                }
                if ($payment_price_type == 'fixed') {
                    //this is fixed amount payment
                    $paypal_params['a3'] = $payment_price_amount;
                    if (!empty($payment_price_amount) && $payment_price_amount !== '0.00') {
                        $payment_has_value = true;
                    }
                } else {
                    if ($payment_price_type == 'variable') {
                        $total_payment_amount = 0;
                        //get price fields information from ap_element_prices table
                        $query = "select \r\n\t\t\t\t\t\t\t\t\t\t\tA.element_id,\r\n\t\t\t\t\t\t\t\t\t\t\tA.option_id,\r\n\t\t\t\t\t\t\t\t\t\t\tA.price,\r\n\t\t\t\t\t\t\t\t\t\t\tB.element_title,\r\n\t\t\t\t\t\t\t\t\t\t\tB.element_type,\r\n\t\t\t\t\t\t\t\t\t\t\t(select `option` from " . MF_TABLE_PREFIX . "element_options where form_id=A.form_id and element_id=A.element_id and option_id=A.option_id and live=1 limit 1) option_title\r\n\t\t\t\t\t\t\t\t\t\tfrom\r\n\t\t\t\t\t\t\t\t\t\t\t" . MF_TABLE_PREFIX . "element_prices A left join " . MF_TABLE_PREFIX . "form_elements B on (A.form_id=B.form_id and A.element_id=B.element_id)\r\n\t\t\t\t\t\t\t\t\t\twhere\r\n\t\t\t\t\t\t\t\t\t\t\tA.form_id = ?\r\n\t\t\t\t\t\t\t\t\t\torder by \r\n\t\t\t\t\t\t\t\t\t\t\tA.element_id,A.option_id asc";
                        $params = array($form_id);
                        $sth = mf_do_query($query, $params, $dbh);
                        $price_field_columns = array();
                        while ($row = mf_do_fetch_result($sth)) {
                            $element_id = (int) $row['element_id'];
                            $option_id = (int) $row['option_id'];
                            $element_type = $row['element_type'];
                            if ($element_type == 'checkbox') {
                                $column_name = 'element_' . $element_id . '_' . $option_id;
                            } else {
                                $column_name = 'element_' . $element_id;
                            }
                            if (!in_array($column_name, $price_field_columns)) {
                                $price_field_columns[] = $column_name;
                                $price_field_types[$column_name] = $row['element_type'];
                            }
                            $price_values[$element_id][$option_id] = $row['price'];
                        }
                        $price_field_columns_joined = implode(',', $price_field_columns);
                        //check the value of the price fields from the ap_form_x table
                        $query = "select {$price_field_columns_joined} from " . MF_TABLE_PREFIX . "form_{$form_id} where `id`=?";
                        $params = array($entry_id);
                        $sth = mf_do_query($query, $params, $dbh);
                        $row = mf_do_fetch_result($sth);
                        $processed_column_name = array();
                        foreach ($price_field_columns as $column_name) {
                            if (!empty($row[$column_name]) && !in_array($column_name, $processed_column_name)) {
                                $temp = explode('_', $column_name);
                                $element_id = (int) $temp[1];
                                $option_id = (int) $temp[2];
                                if ($price_field_types[$column_name] == 'money') {
                                    $total_payment_amount += $row[$column_name];
                                } else {
                                    if ($price_field_types[$column_name] == 'checkbox') {
                                        $total_payment_amount += $price_values[$element_id][$option_id];
                                    } else {
                                        $option_id = $row[$column_name];
                                        $total_payment_amount += $price_values[$element_id][$option_id];
                                    }
                                }
                                $processed_column_name[] = $column_name;
                            }
                        }
                        $paypal_params['a3'] = $total_payment_amount;
                        if (!empty($total_payment_amount) && $total_payment_amount !== '0.00') {
                            $payment_has_value = true;
                        }
                    }
                }
                //end of variable-recurring payment
                //trial periods
                if (!empty($payment_enable_trial)) {
                    //set trial price
                    if ($payment_trial_amount === '0.00') {
                        $payment_trial_amount = 0;
                    }
                    $paypal_params['a1'] = $payment_trial_amount;
                    //set trial period
                    $paypal_params['p1'] = $payment_trial_period;
                    $paypal_params['t1'] = strtoupper($payment_trial_unit[0]);
                    //check for limits being set by PayPal
                    if ($paypal_params['t1'] == 'Y' && $payment_trial_period > 5) {
                        $paypal_params['p1'] = 5;
                        //max 5 years recurring
                    }
                }
            } else {
                //non recurring payment
                $paypal_params['cmd'] = '_cart';
                if ($payment_price_type == 'fixed') {
                    //this is fixed amount payment
                    $paypal_params['item_name_1'] = $payment_price_name;
                    $paypal_params['amount_1'] = $payment_price_amount;
                    if (!empty($payment_price_amount) && $payment_price_amount !== '0.00') {
                        $payment_has_value = true;
                    }
                } else {
                    if ($payment_price_type == 'variable') {
                        //this is variable amount payment
                        //get price fields information from ap_element_prices table
                        $query = "select \r\n\t\t\t\t\t\t\t\t\t\t\tA.element_id,\r\n\t\t\t\t\t\t\t\t\t\t\tA.option_id,\r\n\t\t\t\t\t\t\t\t\t\t\tA.price,\r\n\t\t\t\t\t\t\t\t\t\t\tB.element_title,\r\n\t\t\t\t\t\t\t\t\t\t\tB.element_type,\r\n\t\t\t\t\t\t\t\t\t\t\t(select `option` from " . MF_TABLE_PREFIX . "element_options where form_id=A.form_id and element_id=A.element_id and option_id=A.option_id and live=1 limit 1) option_title\r\n\t\t\t\t\t\t\t\t\t\tfrom\r\n\t\t\t\t\t\t\t\t\t\t\t" . MF_TABLE_PREFIX . "element_prices A left join " . MF_TABLE_PREFIX . "form_elements B on (A.form_id=B.form_id and A.element_id=B.element_id)\r\n\t\t\t\t\t\t\t\t\t\twhere\r\n\t\t\t\t\t\t\t\t\t\t\tA.form_id = ?\r\n\t\t\t\t\t\t\t\t\t\torder by \r\n\t\t\t\t\t\t\t\t\t\t\tA.element_id,A.option_id asc";
                        $params = array($form_id);
                        $sth = mf_do_query($query, $params, $dbh);
                        $price_field_columns = array();
                        while ($row = mf_do_fetch_result($sth)) {
                            $element_id = (int) $row['element_id'];
                            $option_id = (int) $row['option_id'];
                            $element_type = $row['element_type'];
                            if ($element_type == 'checkbox') {
                                $column_name = 'element_' . $element_id . '_' . $option_id;
                            } else {
                                $column_name = 'element_' . $element_id;
                            }
                            if (!in_array($column_name, $price_field_columns)) {
                                $price_field_columns[] = $column_name;
                                $price_field_types[$column_name] = $row['element_type'];
                            }
                            $price_values[$element_id][$option_id] = $row['price'];
                            if ($element_type == 'money') {
                                $price_titles[$element_id][$option_id] = $row['element_title'];
                            } else {
                                $price_titles[$element_id][$option_id] = $row['option_title'];
                            }
                        }
                        $price_field_columns_joined = implode(',', $price_field_columns);
                        //check the value of the price fields from the ap_form_x table
                        $query = "select {$price_field_columns_joined} from " . MF_TABLE_PREFIX . "form_{$form_id} where `id`=?";
                        $params = array($entry_id);
                        $sth = mf_do_query($query, $params, $dbh);
                        $row = mf_do_fetch_result($sth);
                        $i = 1;
                        $processed_column_name = array();
                        foreach ($price_field_columns as $column_name) {
                            if (!empty($row[$column_name]) && !in_array($column_name, $processed_column_name)) {
                                $temp = explode('_', $column_name);
                                $element_id = (int) $temp[1];
                                $option_id = (int) $temp[2];
                                $item_name = '';
                                $amount = '';
                                if ($price_field_types[$column_name] == 'money') {
                                    $item_name = $price_titles[$element_id][0];
                                    $amount = $row[$column_name];
                                } else {
                                    if ($price_field_types[$column_name] == 'checkbox') {
                                        $item_name = $price_titles[$element_id][$option_id];
                                        $amount = $price_values[$element_id][$option_id];
                                    } else {
                                        $option_id = $row[$column_name];
                                        $item_name = $price_titles[$element_id][$option_id];
                                        $amount = $price_values[$element_id][$option_id];
                                    }
                                }
                                $processed_column_name[] = $column_name;
                                if (!empty($amount) && $amount !== '0.00') {
                                    $payment_has_value = true;
                                    $paypal_params['item_name_' . $i] = $item_name;
                                    $paypal_params['amount_' . $i] = $amount;
                                    $i++;
                                }
                            }
                        }
                    }
                }
                //end of non-recurring variable payment
            }
            //end of non-recurring payment
            $merchant_redirect_url = 'https://' . $paypal_url . '/cgi-bin/webscr?' . http_build_query($paypal_params, '', '&');
        }
        //end paypal standard
    }
    if ($payment_has_value) {
        return $merchant_redirect_url;
    } else {
        return '';
        //if total amount is zero, don't redirect to PayPal
    }
}
Example #5
0
function mf_send_resume_link($dbh, $form_name, $form_resume_url, $resume_email)
{
    global $mf_lang;
    //get settings first
    $mf_settings = mf_get_settings($dbh);
    $subject = sprintf($mf_lang['resume_email_subject'], $form_name);
    $email_content = sprintf($mf_lang['resume_email_content'], $form_name, $form_resume_url, $form_resume_url);
    $subject = utf8_encode($subject);
    //create the mail transport
    if (!empty($mf_settings['smtp_enable'])) {
        $s_transport = Swift_SmtpTransport::newInstance($mf_settings['smtp_host'], $mf_settings['smtp_port']);
        if (!empty($mf_settings['smtp_secure'])) {
            $s_transport->setEncryption('tls');
        }
        if (!empty($mf_settings['smtp_auth'])) {
            $s_transport->setUsername($mf_settings['smtp_username']);
            $s_transport->setPassword($mf_settings['smtp_password']);
        }
    } else {
        $s_transport = Swift_MailTransport::newInstance();
        //use PHP mail() transport
    }
    //create mailer instance
    $s_mailer = Swift_Mailer::newInstance($s_transport);
    if (file_exists($mf_settings['upload_dir'] . "/form_{$form_id}/files")) {
        Swift_Preferences::getInstance()->setCacheType('disk')->setTempDir($mf_settings['upload_dir'] . "/form_{$form_id}/files");
    }
    $from_name = html_entity_decode($mf_settings['default_from_name'], ENT_QUOTES);
    $from_email = $mf_settings['default_from_email'];
    if (!empty($resume_email) && !empty($form_resume_url)) {
        $s_message = Swift_Message::newInstance()->setCharset('utf-8')->setMaxLineLength(1000)->setSubject($subject)->setFrom(array($from_email => $from_name))->setSender($from_email)->setReturnPath($from_email)->setTo($resume_email)->setBody($email_content, 'text/html');
        //send the message
        $send_result = $s_mailer->send($s_message);
        if (empty($send_result)) {
            echo "Error sending email!";
        }
    }
}
Example #6
0
function mf_get_entry_details($dbh, $form_id, $entry_id, $options = array())
{
    $mf_settings = mf_get_settings($dbh);
    $admin_clause = '';
    if (!empty($options['review_mode'])) {
        //hide admin fields in review page
        $admin_clause = ' and element_is_private=0 ';
    }
    if (!empty($options['checkbox_image'])) {
        $checkbox_image = $options['checkbox_image'];
    } else {
        $checkbox_image = $options['machform_path'] . 'images/icons/checkbox_16.gif';
    }
    //get form elements
    $query = "select \r\n\t\t\t\t\t\t element_id,\r\n\t\t\t\t\t\t element_type,\r\n\t\t\t\t\t\t element_constraint,\r\n\t\t\t\t\t\t element_title,\r\n\t\t\t\t\t\t element_file_as_attachment,\r\n\t\t\t\t\t\t element_time_showsecond,\r\n\t\t\t\t\t\t element_time_24hour,\r\n\t\t\t\t\t\t (select if(element_matrix_parent_id=0,\r\n\t\t\t\t\t\t\t \t\telement_matrix_allow_multiselect,\r\n\t\t\t\t\t\t\t\t\t(select \r\n\t\t\t\t\t\t\t\t\t\t\tB.element_matrix_allow_multiselect \r\n\t\t\t\t\t\t\t\t\t   from \r\n\t\t\t\t\t\t\t\t\t   \t\t" . MF_TABLE_PREFIX . "form_elements B \r\n\t\t\t\t\t\t\t\t\t  where \r\n\t\t\t\t\t\t\t\t\t  \t\tB.form_id=A.form_id and \r\n\t\t\t\t\t\t\t\t\t  \t\tB.element_id=A.element_matrix_parent_id\r\n\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t )\r\n\t\t\t\t\t\t ) matrix_multiselect_status  \r\n\t\t\t\t\t from \r\n\t\t\t\t\t \t `" . MF_TABLE_PREFIX . "form_elements` A\r\n\t\t\t\t\twhere \r\n\t\t\t\t\t\t form_id=? and \r\n\t\t\t\t\t\t element_status = 1 and\r\n\t\t\t\t\t\t element_type <> 'section'\r\n\t\t\t\t\t\t {$admin_clause} \r\n\t\t\t\t order by \r\n\t\t\t\t \t\t element_position asc";
    $params = array($form_id);
    $sth = mf_do_query($query, $params, $dbh);
    $i = 0;
    while ($row = mf_do_fetch_result($sth)) {
        $form_elements[$i]['element_id'] = $row['element_id'];
        $form_elements[$i]['element_type'] = $row['element_type'];
        $form_elements[$i]['element_constraint'] = $row['element_constraint'];
        $form_elements[$i]['element_file_as_attachment'] = $row['element_file_as_attachment'];
        $form_elements[$i]['element_time_showsecond'] = $row['element_time_showsecond'];
        $form_elements[$i]['element_time_24hour'] = $row['element_time_24hour'];
        $form_elements[$i]['element_matrix_allow_multiselect'] = $row['matrix_multiselect_status'];
        //store element title into array for reference later
        $element_title_lookup[$row['element_id']] = $row['element_title'];
        $i++;
    }
    if (!empty($options['review_mode'])) {
        $table_suffix = '_review';
    } else {
        $table_suffix = '';
    }
    //get whole entry for current id
    $query = "select * from `" . MF_TABLE_PREFIX . "form_{$form_id}{$table_suffix}` where id=? limit 1";
    $params = array($entry_id);
    $sth = mf_do_query($query, $params, $dbh);
    $row = mf_do_fetch_result($sth);
    foreach ($row as $column_name => $column_data) {
        $entry_data[$column_name] = htmlspecialchars($column_data, ENT_QUOTES);
    }
    //get form element options
    $query = "select element_id,option_id,`option` from " . MF_TABLE_PREFIX . "element_options where form_id=? and live=1 order by position asc";
    $params = array($form_id);
    $sth = mf_do_query($query, $params, $dbh);
    while ($row = mf_do_fetch_result($sth)) {
        $element_id = $row['element_id'];
        $option_id = $row['option_id'];
        $element_option_lookup[$element_id][$option_id] = $row['option'];
        //array index will hold option_id
    }
    //get element options for matrix fields
    $query = "select \r\n\t\t\t\t\t\tA.element_id,\r\n\t\t\t\t\t\tA.option_id,\r\n\t\t\t\t\t\t(select if(B.element_matrix_parent_id=0,A.option,\r\n\t\t\t\t\t\t\t(select \r\n\t\t\t\t\t\t\t\t\tC.`option` \r\n\t\t\t\t\t\t\t   from \r\n\t\t\t\t\t\t\t   \t\t" . MF_TABLE_PREFIX . "element_options C \r\n\t\t\t\t\t\t\t  where \r\n\t\t\t\t\t\t\t  \t\tC.element_id=B.element_matrix_parent_id and \r\n\t\t\t\t\t\t\t  \t\tC.form_id=A.form_id and \r\n\t\t\t\t\t\t\t  \t\tC.live=1 and \r\n\t\t\t\t\t\t\t  \t\tC.option_id=A.option_id))\r\n\t\t\t\t\t\t) 'option_label'\r\n\t\t\t\t\tfrom \r\n\t\t\t\t\t\t" . MF_TABLE_PREFIX . "element_options A left join " . MF_TABLE_PREFIX . "form_elements B on (A.element_id=B.element_id and A.form_id=B.form_id)\r\n\t\t\t\t   where \r\n\t\t\t\t   \t\tA.form_id=? and A.live=1 and B.element_type='matrix' and B.element_status=1\r\n\t\t\t\torder by \r\n\t\t\t\t\t\tA.element_id,A.option_id asc";
    $params = array($form_id);
    $sth = mf_do_query($query, $params, $dbh);
    while ($row = mf_do_fetch_result($sth)) {
        $element_id = $row['element_id'];
        $option_id = $row['option_id'];
        $matrix_element_option_lookup[$element_id][$option_id] = htmlspecialchars($row['option_label'], ENT_QUOTES);
    }
    //loop through each element to get the values
    $i = 0;
    foreach ($form_elements as $element) {
        $element_type = $element['element_type'];
        $element_id = $element['element_id'];
        $element_constraint = $element['element_constraint'];
        $element_file_as_attachment = $element['element_file_as_attachment'];
        $element_time_24hour = $element['element_time_24hour'];
        $element_time_showsecond = $element['element_time_showsecond'];
        $element_matrix_allow_multiselect = $element['element_matrix_allow_multiselect'];
        $entry_details[$i]['label'] = $element_title_lookup[$element_id];
        $entry_details[$i]['value'] = '&nbsp;';
        //default value
        $entry_details[$i]['element_id'] = $element_id;
        $entry_details[$i]['element_type'] = $element_type;
        if ('simple_name' == $element_type) {
            //Simple Name - 2 elements
            $simple_name_value = trim($entry_data['element_' . $element_id . '_1'] . ' ' . $entry_data['element_' . $element_id . '_2']);
            if (!empty($simple_name_value)) {
                $entry_details[$i]['value'] = $simple_name_value;
            }
        } elseif ('simple_name_wmiddle' == $element_type) {
            //Simple Name with Middle - 3 elements
            $simple_name_wmiddle_value = trim($entry_data['element_' . $element_id . '_1'] . ' ' . $entry_data['element_' . $element_id . '_2'] . ' ' . $entry_data['element_' . $element_id . '_3']);
            if (!empty($simple_name_wmiddle_value)) {
                $entry_details[$i]['value'] = $simple_name_wmiddle_value;
            }
        } elseif ('name' == $element_type) {
            //Extended Name - 4 elements
            $name_value = trim($entry_data['element_' . $element_id . '_1'] . ' ' . $entry_data['element_' . $element_id . '_2'] . ' ' . $entry_data['element_' . $element_id . '_3'] . ' ' . $entry_data['element_' . $element_id . '_4']);
            if (!empty($name_value)) {
                $entry_details[$i]['value'] = $name_value;
            }
        } elseif ('name_wmiddle' == $element_type) {
            //Extended Name  with Middle- 5 elements
            $name_wmiddle_value = trim($entry_data['element_' . $element_id . '_1'] . ' ' . $entry_data['element_' . $element_id . '_2'] . ' ' . $entry_data['element_' . $element_id . '_3'] . ' ' . $entry_data['element_' . $element_id . '_4'] . ' ' . $entry_data['element_' . $element_id . '_5']);
            if (!empty($name_wmiddle_value)) {
                $entry_details[$i]['value'] = $name_wmiddle_value;
            }
        } elseif ('time' == $element_type) {
            //Time - 4 elements
            //convert into time and split into 4 elements
            if (!empty($entry_data['element_' . $element_id]) && $entry_data['element_' . $element_id] != '00:00:00') {
                $time_value = $entry_data['element_' . $element_id];
                if (!empty($element_time_24hour)) {
                    if (!empty($element_time_showsecond)) {
                        $time_value = date("H:i:s", strtotime($time_value));
                    } else {
                        $time_value = date("H:i", strtotime($time_value));
                    }
                } else {
                    if (!empty($element_time_showsecond)) {
                        $time_value = date("h:i:s A", strtotime($time_value));
                    } else {
                        $time_value = date("h:i A", strtotime($time_value));
                    }
                }
                $entry_details[$i]['value'] = $time_value;
            }
        } elseif ('address' == $element_type) {
            //Address - 6	 elements
            if (!empty($entry_data['element_' . $element_id . '_3'])) {
                $entry_data['element_' . $element_id . '_3'] = $entry_data['element_' . $element_id . '_3'] . ',';
            }
            $entry_details[$i]['value'] = $entry_data['element_' . $element_id . '_1'] . ' ' . $entry_data['element_' . $element_id . '_2'] . '<br />' . $entry_data['element_' . $element_id . '_3'] . ' ' . $entry_data['element_' . $element_id . '_4'] . ' ' . $entry_data['element_' . $element_id . '_5'] . '<br />' . $entry_data['element_' . $element_id . '_6'];
            //if empty, shows blank instead of breaks
            if (trim(str_replace("<br />", "", $entry_details[$i]['value'])) == "") {
                $entry_details[$i]['value'] = '&nbsp;';
            }
        } elseif ('money' == $element_type) {
            //Price
            switch ($element_constraint) {
                case 'pound':
                    $currency = '&#163;';
                    break;
                case 'euro':
                    $currency = '&#8364;';
                    break;
                case 'yen':
                    $currency = '&#165;';
                    break;
                case 'baht':
                    $currency = '&#3647;';
                    break;
                case 'rupees':
                    $currency = 'Rs';
                    break;
                case 'rand':
                    $currency = 'R';
                    break;
                case 'forint':
                    $currency = '&#70;&#116;';
                    break;
                case 'franc':
                    $currency = 'CHF';
                    break;
                case 'koruna':
                    $currency = '&#75;&#269;';
                    break;
                case 'krona':
                    $currency = 'kr';
                    break;
                case 'pesos':
                    $currency = '&#36;';
                    break;
                case 'ringgit':
                    $currency = 'RM';
                    break;
                case 'zloty':
                    $currency = '&#122;&#322;';
                    break;
                case 'riyals':
                    $currency = '&#65020;';
                    break;
                default:
                    $currency = '$';
                    break;
            }
            if (!empty($entry_data['element_' . $element_id]) || $entry_data['element_' . $element_id] === 0 || $entry_data['element_' . $element_id] === '0') {
                $entry_details[$i]['value'] = $currency . $entry_data['element_' . $element_id];
            }
        } elseif ('date' == $element_type) {
            //date with format MM/DD/YYYY
            if (!empty($entry_data['element_' . $element_id]) && $entry_data['element_' . $element_id] != '0000-00-00') {
                $date_value = $entry_data['element_' . $element_id];
                $date_value = date("M d, Y", strtotime($date_value));
                $entry_details[$i]['value'] = $date_value;
            }
        } elseif ('europe_date' == $element_type) {
            //date with format DD/MM/YYYY
            if (!empty($entry_data['element_' . $element_id]) && $entry_data['element_' . $element_id] != '0000-00-00') {
                $date_value = $entry_data['element_' . $element_id];
                $date_value = date("d M Y", strtotime($date_value));
                $entry_details[$i]['value'] = $date_value;
            }
        } elseif ('phone' == $element_type) {
            //Phone - 3 elements
            $phone_value = $entry_data['element_' . $element_id];
            $phone_1 = substr($phone_value, 0, 3);
            $phone_2 = substr($phone_value, 3, 3);
            $phone_3 = substr($phone_value, -4);
            if (!empty($phone_value)) {
                $entry_details[$i]['value'] = "({$phone_1}) {$phone_2}-{$phone_3}";
            }
        } elseif ('checkbox' == $element_type) {
            //Checkbox - multiple elements
            $checkbox_childs = $element_option_lookup[$element_id];
            $checkbox_content = '';
            if ($checkbox_childs) {
                foreach ($checkbox_childs as $option_id => $option_label) {
                    if (!empty($entry_data['element_' . $element_id . '_' . $option_id])) {
                        if (empty($options['strip_checkbox_image'])) {
                            $checkbox_content .= '<img src="' . $checkbox_image . '" align="absmiddle" /> ' . $option_label . '<br />';
                        } else {
                            $checkbox_content .= '- ' . $option_label . '<br />';
                        }
                    }
                }
            }
            if (!empty($entry_data['element_' . $element_id . '_other'])) {
                if (empty($options['strip_checkbox_image'])) {
                    $checkbox_content .= '<img src="' . $checkbox_image . '" align="absmiddle" /> ' . $entry_data['element_' . $element_id . '_other'];
                } else {
                    $checkbox_content .= '- ' . $entry_data['element_' . $element_id . '_other'];
                }
            }
            if (!empty($checkbox_content)) {
                $entry_details[$i]['value'] = $checkbox_content;
            }
        } elseif ('file' == $element_type) {
            //File
            $filename_record = $entry_data['element_' . $element_id];
            $filename_array = array();
            if (!empty($filename_record)) {
                $filename_array = explode('|', $filename_record);
            }
            if (!empty($filename_array)) {
                $entry_details[$i]['value'] = '';
                $j = 0;
                foreach ($filename_array as $filename_value) {
                    $filename_md5 = md5($filename_value);
                    $filename_path = $options['machform_data_path'] . $mf_settings['upload_dir'] . "/form_{$form_id}/files/{$filename_value}.tmp";
                    if (!file_exists($filename_path)) {
                        $filename_path = $options['machform_data_path'] . $mf_settings['upload_dir'] . "/form_{$form_id}/files/{$filename_value}";
                    }
                    $file_size = @mf_format_bytes(filesize($filename_path));
                    $file_1 = substr($filename_value, strpos($filename_value, '-') + 1);
                    $filename_value = substr($file_1, strpos($file_1, '-') + 1);
                    //encode the long query string for more readibility
                    $q_string = base64_encode("form_id={$form_id}&id={$entry_id}&el=element_{$element_id}&hash={$filename_md5}");
                    if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
                        $ssl_suffix = 's';
                    } else {
                        $ssl_suffix = '';
                    }
                    //'show_attach_image' is being called on review page
                    if (!empty($options['show_attach_image'])) {
                        //trim filename if more than 30 characters
                        if (strlen($filename_value) > 30) {
                            $filename_value = substr($filename_value, 0, 30) . "...";
                        }
                        $entry_details[$i]['value'] .= '<img src="' . $options['machform_path'] . 'images/icons/185.png" align="absmiddle" style="vertical-align: middle" />&nbsp;' . "{$filename_value} ({$file_size})<br/>";
                    } else {
                        //provide a markup to download the file
                        if (!empty($options['machform_base_path'])) {
                            //if the form is called from advanced form code
                            $entry_details[$i]['value'] .= '<img src="' . $options['machform_path'] . 'images/icons/185.png" align="absmiddle" style="vertical-align: middle" />&nbsp;<a class="entry_link" href="' . $options['machform_base_path'] . 'download.php?q=' . $q_string . '">' . $filename_value . '</a><br/>';
                        } else {
                            $entry_details[$i]['value'] .= '<img src="' . $options['machform_path'] . 'images/icons/185.png" align="absmiddle" style="vertical-align: middle" />&nbsp;<a class="entry_link" href="http' . $ssl_suffix . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/download.php?q=' . $q_string . '">' . $filename_value . '</a><br/>';
                        }
                        if (!empty($options['strip_download_link'])) {
                            $entry_details[$i]['value'] .= $filename_value . '<br/>';
                        }
                        if (!empty($element_file_as_attachment)) {
                            $entry_details[$i]['filedata'][$j]['filename_path'] = $filename_path;
                            $entry_details[$i]['filedata'][$j]['filename_value'] = $filename_value;
                        }
                    }
                    $j++;
                }
                $entry_details[$i]['value'] = rtrim($entry_details[$i]['value'], '<br/>');
            }
        } elseif ('select' == $element_type) {
            if (!empty($entry_data['element_' . $element_id])) {
                $entry_details[$i]['value'] = $element_option_lookup[$element_id][$entry_data['element_' . $element_id]];
            }
        } elseif ('radio' == $element_type) {
            if (!empty($entry_data['element_' . $element_id])) {
                $entry_details[$i]['value'] = $element_option_lookup[$element_id][$entry_data['element_' . $element_id]];
            } else {
                if (!empty($entry_data['element_' . $element_id . '_other'])) {
                    $entry_details[$i]['value'] = $entry_data['element_' . $element_id . '_other'];
                } else {
                    $entry_details[$i]['value'] = '&nbsp;';
                }
            }
        } elseif ('matrix' == $element_type) {
            if (!empty($element_matrix_allow_multiselect)) {
                //this is checkbox matrix
                $checkbox_childs = $element_option_lookup[$element_id];
                $checkbox_content = '';
                foreach ($checkbox_childs as $option_id => $option_label) {
                    if (!empty($entry_data['element_' . $element_id . '_' . $option_id])) {
                        if (empty($options['strip_checkbox_image'])) {
                            $checkbox_content .= '<img src="' . $checkbox_image . '" align="absmiddle" /> ' . $option_label . '<br />';
                        } else {
                            $checkbox_content .= '- ' . $option_label . '<br />';
                        }
                    }
                }
                if (!empty($entry_data['element_' . $element_id . '_other'])) {
                    $checkbox_content .= '<img src="' . $checkbox_image . '" align="absmiddle" /> ' . $entry_data['element_' . $element_id . '_other'];
                }
                if (!empty($checkbox_content)) {
                    $entry_details[$i]['value'] = $checkbox_content;
                }
            } else {
                //this is radio matrix
                if (!empty($entry_data['element_' . $element_id])) {
                    $entry_details[$i]['value'] = $matrix_element_option_lookup[$element_id][$entry_data['element_' . $element_id]];
                } else {
                    $entry_details[$i]['value'] = '&nbsp;';
                }
            }
        } elseif ('url' == $element_type) {
            if (!empty($entry_data['element_' . $element_id])) {
                $entry_details[$i]['value'] = "<a class=\"entry_link\" href=\"{$entry_data['element_' . $element_id]}\">{$entry_data['element_' . $element_id]}</a>";
            }
        } elseif ('page_break' == $element_type) {
            $entry_details[$i]['value'] = 'mf_page_break';
            $entry_details[$i]['label'] = 'mf_page_break';
        } else {
            //element with only 1 input
            if (isset($entry_data['element_' . $element_id])) {
                $entry_details[$i]['value'] = $entry_data['element_' . $element_id];
            }
        }
        $i++;
    }
    return $entry_details;
}
function mf_display_form_payment($dbh, $form_id, $record_id, $form_params = array())
{
    global $mf_lang;
    if (!empty($form_params['integration_method'])) {
        $integration_method = $form_params['integration_method'];
    } else {
        $integration_method = '';
    }
    if (!empty($form_params['machform_path'])) {
        $machform_path = $form_params['machform_path'];
    } else {
        $machform_path = '';
    }
    if (!empty($form_params['machform_data_path'])) {
        $machform_data_path = $form_params['machform_data_path'];
    } else {
        $machform_data_path = '';
    }
    //check permission to access this page
    if ($_SESSION['mf_form_payment_access'][$form_id] !== true) {
        return "Your session has been expired. Please <a href='view.php?id={$form_id}'>click here</a> to start again.";
    }
    $mf_settings = mf_get_settings($dbh);
    //get form properties data
    $query = "select \r\n\t\t\t\t\t\t  form_name,\r\n\t\t\t\t\t\t  form_has_css,\r\n\t\t\t\t\t\t  form_redirect,\r\n\t\t\t\t\t\t  form_language,\r\n\t\t\t\t\t\t  form_review,\r\n\t\t\t\t\t\t  form_review_primary_text,\r\n\t\t\t\t\t\t  form_review_secondary_text,\r\n\t\t\t\t\t\t  form_review_primary_img,\r\n\t\t\t\t\t\t  form_review_secondary_img,\r\n\t\t\t\t\t\t  form_review_use_image,\r\n\t\t\t\t\t\t  form_review_title,\r\n\t\t\t\t\t\t  form_review_description,\r\n\t\t\t\t\t\t  form_resume_enable,\r\n\t\t\t\t\t\t  form_page_total,\r\n\t\t\t\t\t\t  form_lastpage_title,\r\n\t\t\t\t\t\t  form_pagination_type,\r\n\t\t\t\t\t\t  form_theme_id,\r\n\t\t\t\t\t\t  payment_show_total,\r\n\t\t\t\t\t\t  payment_total_location,\r\n\t\t\t\t\t\t  payment_enable_merchant,\r\n\t\t\t\t\t\t  payment_merchant_type,\r\n\t\t\t\t\t\t  payment_currency,\r\n\t\t\t\t\t\t  payment_price_type,\r\n\t\t\t\t\t\t  payment_price_name,\r\n\t\t\t\t\t\t  payment_price_amount,\r\n\t\t\t\t\t\t  payment_ask_billing,\r\n\t\t\t\t\t\t  payment_ask_shipping,\r\n\t\t\t\t\t\t  payment_stripe_live_public_key,\r\n\t\t\t\t\t\t  payment_stripe_test_public_key,\r\n\t\t\t\t\t\t  payment_stripe_enable_test_mode,\r\n\t\t\t\t\t\t  payment_enable_recurring,\r\n\t\t\t\t\t\t  payment_recurring_cycle,\r\n\t\t\t\t\t\t  payment_recurring_unit,\r\n\t\t\t\t\t\t  payment_enable_trial,\r\n\t\t\t\t\t\t  payment_trial_period,\r\n\t\t\t\t\t\t  payment_trial_unit,\r\n\t\t\t\t\t\t  payment_trial_amount,\r\n\t\t\t\t\t\t  payment_delay_notifications\r\n\t\t\t\t     from \r\n\t\t\t\t     \t " . MF_TABLE_PREFIX . "forms \r\n\t\t\t\t    where \r\n\t\t\t\t    \t form_id=?";
    $params = array($form_id);
    $sth = mf_do_query($query, $params, $dbh);
    $row = mf_do_fetch_result($sth);
    $form_language = $row['form_language'];
    if (!empty($form_language)) {
        mf_set_language($form_language);
    }
    $form_payment_title = $mf_lang['form_payment_title'];
    $form_payment_description = $mf_lang['form_payment_description'];
    $form_has_css = $row['form_has_css'];
    $form_redirect = $row['form_redirect'];
    $form_review = (int) $row['form_review'];
    $form_review_primary_text = $row['form_review_primary_text'];
    $form_review_secondary_text = $row['form_review_secondary_text'];
    $form_review_primary_img = $row['form_review_primary_img'];
    $form_review_secondary_img = $row['form_review_secondary_img'];
    $form_review_use_image = (int) $row['form_review_use_image'];
    $form_review_title = $row['form_review_title'];
    $form_review_description = $row['form_review_description'];
    $form_page_total = (int) $row['form_page_total'];
    $form_lastpage_title = $row['form_lastpage_title'];
    $form_pagination_type = $row['form_pagination_type'];
    $form_name = htmlspecialchars($row['form_name'], ENT_QUOTES);
    $form_theme_id = $row['form_theme_id'];
    $form_resume_enable = (int) $row['form_resume_enable'];
    $payment_show_total = (int) $row['payment_show_total'];
    $payment_total_location = $row['payment_total_location'];
    $payment_enable_merchant = (int) $row['payment_enable_merchant'];
    if ($payment_enable_merchant < 1) {
        $payment_enable_merchant = 0;
    }
    $payment_currency = $row['payment_currency'];
    $payment_price_type = $row['payment_price_type'];
    $payment_price_amount = $row['payment_price_amount'];
    $payment_price_name = htmlspecialchars($row['payment_price_name'], ENT_QUOTES);
    $payment_ask_billing = (int) $row['payment_ask_billing'];
    $payment_ask_shipping = (int) $row['payment_ask_shipping'];
    $payment_merchant_type = $row['payment_merchant_type'];
    $payment_stripe_enable_test_mode = (int) $row['payment_stripe_enable_test_mode'];
    $payment_stripe_live_public_key = trim($row['payment_stripe_live_public_key']);
    $payment_stripe_test_public_key = trim($row['payment_stripe_test_public_key']);
    $payment_enable_recurring = (int) $row['payment_enable_recurring'];
    $payment_recurring_cycle = (int) $row['payment_recurring_cycle'];
    $payment_recurring_unit = $row['payment_recurring_unit'];
    $payment_enable_trial = (int) $row['payment_enable_trial'];
    $payment_trial_period = (int) $row['payment_trial_period'];
    $payment_trial_unit = $row['payment_trial_unit'];
    $payment_trial_amount = (double) $row['payment_trial_amount'];
    $payment_delay_notifications = (int) $row['payment_delay_notifications'];
    //check for specific form css, if any, use it instead
    if ($form_has_css) {
        $css_dir = $mf_settings['data_dir'] . "/form_{$form_id}/css/";
    }
    if ($integration_method == 'iframe') {
        $embed_class = 'class="embed"';
    }
    //get total payment
    $currency_symbol = '&#36;';
    if ($payment_price_type == 'variable') {
        $total_payment_amount = (double) mf_get_payment_total($dbh, $form_id, $record_id, 0, 'live');
        $payment_items = mf_get_payment_items($dbh, $form_id, $record_id, 'live');
        //build the payment list markup
        $payment_list_items_markup = '';
        if (!empty($payment_items)) {
            foreach ($payment_items as $item) {
                if ($item['type'] == 'money') {
                    $payment_list_items_markup .= "<li>{$item['title']} <span>{$currency_symbol}{$item['amount']}</span></li>" . "\n";
                } else {
                    if ($item['type'] == 'checkbox') {
                        $payment_list_items_markup .= "<li>{$item['sub_title']} <span>{$currency_symbol}{$item['amount']}</span></li>" . "\n";
                    } else {
                        if ($item['type'] == 'select' || $item['type'] == 'radio') {
                            $payment_list_items_markup .= "<li>{$item['title']} <em>({$item['sub_title']})</em> <span>{$currency_symbol}{$item['amount']}</span></li>" . "\n";
                        }
                    }
                }
            }
        }
    } else {
        if ($payment_price_type == 'fixed') {
            $total_payment_amount = $payment_price_amount;
            $payment_list_items_markup = "<li>{$payment_price_name}</li>";
        }
    }
    //construct payment terms
    if (!empty($payment_enable_recurring)) {
        $payment_plurals = '';
        if ($payment_recurring_cycle > 1) {
            $payment_plurals = 's';
            $payment_recurring_cycle_markup = $payment_recurring_cycle . ' ';
        }
        if (!empty($payment_enable_trial)) {
            //recurring with trial period
            $payment_trial_price = $currency_symbol . $payment_trial_amount;
            if (empty($payment_trial_amount)) {
                $payment_trial_price = 'free';
            }
            $payment_trial_plurals = '';
            if ($payment_trial_period > 1) {
                $payment_trial_plurals = 's';
            }
            $payment_term_markup = <<<EOT
\t\t\t\t\t<li class="payment_summary_term">
\t\t\t\t\t\t<em>Trial period: {$payment_trial_period} {$payment_trial_unit}{$payment_trial_plurals} ({$payment_trial_price})</em><br>
\t\t\t\t\t\t<em>Then you will be charged {$currency_symbol}{$total_payment_amount} every {$payment_recurring_cycle_markup}{$payment_recurring_unit}{$payment_plurals}</em>
\t\t\t\t\t</li>
EOT;
        } else {
            $payment_term_markup = "<li class=\"payment_summary_term\"><em>You will be charged {$currency_symbol}{$total_payment_amount} every {$payment_recurring_cycle_markup}{$payment_recurring_unit}{$payment_plurals}</em></li>";
        }
    }
    //if the form has multiple pages
    //display the pagination header
    if ($form_page_total > 1) {
        //build pagination header based on the selected type. possible values:
        //steps - display multi steps progress
        //percentage - display progress bar with percentage
        //disabled - disabled
        $page_breaks_data = array();
        $page_title_array = array();
        //get page titles
        $query = "SELECT \r\n\t\t\t\t\t\t\telement_page_title\r\n\t\t\t\t\t\tFROM \r\n\t\t\t\t\t\t\t" . MF_TABLE_PREFIX . "form_elements\r\n\t\t\t\t\t   WHERE\r\n\t\t\t\t\t\t\tform_id = ? and element_status = 1 and element_type = 'page_break'\r\n\t\t\t\t\tORDER BY \r\n\t\t\t\t\t   \t\telement_page_number asc";
        $params = array($form_id);
        $sth = mf_do_query($query, $params, $dbh);
        while ($row = mf_do_fetch_result($sth)) {
            $page_title_array[] = $row['element_page_title'];
        }
        if ($form_pagination_type == 'steps') {
            $page_titles_markup = '';
            $i = 1;
            foreach ($page_title_array as $page_title) {
                $page_titles_markup .= '<td align="center"><span id="page_num_' . $i . '" class="ap_tp_num">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text">' . $page_title . '</span></td><td align="center" class="ap_tp_arrow">&gt;</td>' . "\n";
                $i++;
            }
            //add the last page title into the pagination header markup
            $page_titles_markup .= '<td align="center"><span id="page_num_' . $i . '" class="ap_tp_num">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text">' . $form_lastpage_title . '</span></td>';
            if (!empty($form_review)) {
                $i++;
                $page_titles_markup .= '<td align="center" class="ap_tp_arrow">&gt;</td><td align="center"><span id="page_num_' . $i . '" class="ap_tp_num">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text">' . $form_review_title . '</span></td>';
            }
            $i++;
            $page_titles_markup .= '<td align="center" class="ap_tp_arrow">&gt;</td><td align="center"><span id="page_num_' . $i . '" class="ap_tp_num ap_tp_num_active">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text ap_tp_text_active">' . $mf_lang['form_payment_header_title'] . '</span></td>';
            $pagination_header = <<<EOT
\t\t\t<ul>
\t\t\t<li id="pagination_header" class="li_pagination">
\t\t\t <table class="ap_table_pagination" width="100%" border="0" cellspacing="0" cellpadding="0">
\t\t\t  <tr> 
\t\t\t  \t{$page_titles_markup}
\t\t\t  </tr>
\t\t\t</table>
\t\t\t</li>
\t\t\t</ul>
EOT;
        } else {
            if ($form_pagination_type == 'percentage') {
                $page_total = count($page_title_array) + 2;
                if (!empty($form_review)) {
                    $page_total++;
                }
                $percent_value = 99;
                $page_number_title = sprintf($mf_lang['page_title'], $page_total, $page_total);
                $pagination_header = <<<EOT
\t\t\t<ul>
\t\t\t\t<li id="pagination_header" class="li_pagination" title="Click to edit">
\t\t\t    <h3 id="page_title_{$page_total}">{$page_number_title}</h3>
\t\t\t\t<div class="mf_progress_container">          
\t\t\t    \t<div id="mf_progress_percentage" class="mf_progress_value" style="width: {$percent_value}%"><span>{$percent_value}%</span></div>
\t\t\t\t</div>
\t\t\t\t</li>
\t\t\t</ul>
EOT;
            } else {
                $pagination_header = '';
            }
        }
    }
    //build the button markup
    $button_markup = <<<EOT
<input id="btn_submit_payment" class="button_text btn_primary" type="submit" data-originallabel="{$mf_lang['payment_submit_button']}" value="{$mf_lang['payment_submit_button']}" />
EOT;
    //if this form is using custom theme
    if (!empty($form_theme_id)) {
        //get the field highlight color for the particular theme
        $query = "SELECT \r\n\t\t\t\t\t\t\thighlight_bg_type,\r\n\t\t\t\t\t\t\thighlight_bg_color,\r\n\t\t\t\t\t\t\tform_shadow_style,\r\n\t\t\t\t\t\t\tform_shadow_size,\r\n\t\t\t\t\t\t\tform_shadow_brightness,\r\n\t\t\t\t\t\t\tform_button_type,\r\n\t\t\t\t\t\t\tform_button_text,\r\n\t\t\t\t\t\t\tform_button_image,\r\n\t\t\t\t\t\t\ttheme_has_css  \r\n\t\t\t\t\t\tFROM \r\n\t\t\t\t\t\t\t" . MF_TABLE_PREFIX . "form_themes \r\n\t\t\t\t\t   WHERE \r\n\t\t\t\t\t   \t\ttheme_id = ?";
        $params = array($form_theme_id);
        $sth = mf_do_query($query, $params, $dbh);
        $row = mf_do_fetch_result($sth);
        $form_shadow_style = $row['form_shadow_style'];
        $form_shadow_size = $row['form_shadow_size'];
        $form_shadow_brightness = $row['form_shadow_brightness'];
        $theme_has_css = (int) $row['theme_has_css'];
        //if the theme has css file, make sure to refer to that file
        //otherwise, generate the css dynamically
        if (!empty($theme_has_css)) {
            $theme_css_link = '<link rel="stylesheet" type="text/css" href="' . $machform_path . $mf_settings['data_dir'] . '/themes/theme_' . $form_theme_id . '.css" media="all" />';
        } else {
            $theme_css_link = '<link rel="stylesheet" type="text/css" href="' . $machform_path . 'css_theme.php?theme_id=' . $form_theme_id . '" media="all" />';
        }
        if ($row['highlight_bg_type'] == 'color') {
            $field_highlight_color = $row['highlight_bg_color'];
        } else {
            //if the field highlight is using pattern instead of color, set the color to empty string
            $field_highlight_color = '';
        }
        //get the css link for the fonts
        $font_css_markup = mf_theme_get_fonts_link($dbh, $form_theme_id);
        //get the form shadow classes
        if (!empty($form_shadow_style) && $form_shadow_style != 'disabled') {
            preg_match_all("/[A-Z]/", $form_shadow_style, $prefix_matches);
            //this regex simply get the capital characters of the shadow style name
            //example: RightPerspectiveShadow result to RPS and then being sliced to RP
            $form_shadow_prefix_code = substr(implode("", $prefix_matches[0]), 0, -1);
            $form_shadow_size_class = $form_shadow_prefix_code . ucfirst($form_shadow_size);
            $form_shadow_brightness_class = $form_shadow_prefix_code . ucfirst($form_shadow_brightness);
            if (empty($integration_method)) {
                //only display shadow if the form is not being embedded using any method
                $form_container_class = $form_shadow_style . ' ' . $form_shadow_size_class . ' ' . $form_shadow_brightness_class;
            }
        }
    } else {
        //if the form doesn't have any theme being applied
        $field_highlight_color = '#FFF7C0';
        if (empty($integration_method)) {
            $form_container_class = 'WarpShadow WLarge WNormal';
            //default shadow
        } else {
            $form_container_class = '';
            //dont show any shadow when the form being embedded
        }
    }
    if (empty($mf_settings['disable_machform_link'])) {
        $powered_by_markup = 'Powered by <a href="http://www.appnitro.com" target="_blank">MachForm</a>';
    } else {
        $powered_by_markup = '';
    }
    $self_address = htmlentities($_SERVER['PHP_SELF']);
    //prevent XSS
    $country = mf_get_country_list();
    $country_markup = '<option value="" selected="selected"></option>' . "\n";
    foreach ($country as $data) {
        $country_markup .= "<option value=\"{$data['value']}\">{$data['label']}</option>\n";
    }
    $billing_address_markup = '';
    if (!empty($payment_ask_billing)) {
        $billing_address_markup = <<<EOT
\t\t\t\t<li id="li_billing_address" class="address">
\t\t\t\t\t<label class="description">Billing Address <span class="required">*</span></label>
\t\t\t\t\t<div>
\t\t\t\t\t\t<span id="li_billing_span_1">
\t\t\t\t\t\t\t<input id="billing_street" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="billing_street">{$mf_lang['address_street']}</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t
\t\t\t\t\t\t<span id="li_billing_span_2" class="left state_list">
\t\t\t\t\t\t\t<input id="billing_city" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="billing_city">{$mf_lang['address_city']}</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t
\t\t\t\t\t\t<span id="li_billing_span_3" class="right state_list">
\t\t\t\t\t\t\t<input id="billing_state" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="billing_state">{$mf_lang['address_state']}</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t
\t\t\t\t\t\t<span id="li_billing_span_4" class="left">
\t\t\t\t\t\t\t<input id="billing_zipcode" class="element text large" maxlength="15" value="{$default_value_5}" type="text" />
\t\t\t\t\t\t\t<label for="billing_zipcode">{$mf_lang['address_zip']}</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t\t
\t\t\t\t\t\t<span id="li_billing_span_5" class="right">
\t\t\t\t\t\t\t<select class="element select large" id="billing_country"> 
\t\t\t\t\t\t\t\t{$country_markup}\t
\t\t\t\t\t\t\t</select>
\t\t\t\t\t\t<label for="billing_country">{$mf_lang['address_country']}</label>
\t\t\t\t\t    </span>
\t\t\t\t    </div><p id="billing_error_message" class="error" style="display: none"></p>
\t\t\t\t</li>
EOT;
    }
    $shipping_address_markup = '';
    if (!empty($payment_ask_shipping)) {
        $shipping_address_markup = <<<EOT
\t\t\t\t<li id="li_shipping_address" class="address">
\t\t\t\t\t<label class="description shipping_address_detail" style="display: none">Shipping Address <span class="required">*</span></label>
\t\t\t\t\t<div class="shipping_address_detail" style="display: none">
\t\t\t\t\t\t<span id="li_shipping_span_1">
\t\t\t\t\t\t\t<input id="shipping_street" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="shipping_street">{$mf_lang['address_street']}</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t
\t\t\t\t\t\t<span id="li_shipping_span_2" class="left state_list">
\t\t\t\t\t\t\t<input id="shipping_city" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="shipping_city">{$mf_lang['address_city']}</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t
\t\t\t\t\t\t<span id="li_shipping_span_3" class="right state_list">
\t\t\t\t\t\t\t<input id="shipping_state" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="shipping_state">{$mf_lang['address_state']}</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t
\t\t\t\t\t\t<span id="li_shipping_span_4" class="left">
\t\t\t\t\t\t\t<input id="shipping_zipcode" class="element text large" maxlength="15" value="{$default_value_5}" type="text" />
\t\t\t\t\t\t\t<label for="shipping_zipcode">{$mf_lang['address_zip']}</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t\t
\t\t\t\t\t\t<span id="li_shipping_span_5" class="right">
\t\t\t\t\t\t\t<select class="element select large" id="shipping_country"> 
\t\t\t\t\t\t\t\t{$country_markup}\t
\t\t\t\t\t\t\t</select>
\t\t\t\t\t\t<label for="shipping_country">{$mf_lang['address_country']}</label>
\t\t\t\t\t    </span>
\t\t\t\t\t    <p id="shipping_error_message" class="error" style="display: none"></p>
\t\t\t\t    </div>
\t\t\t\t    <div>
\t\t\t\t\t    <input type="checkbox" value="1" checked="checked" class="checkbox" id="mf_same_shipping_address">
\t\t\t\t\t\t<label for="mf_same_shipping_address" class="choice">My shipping address is the same as my billing address</label>
\t\t\t\t\t</div>
\t\t\t\t</li>
EOT;
    }
    if ($payment_merchant_type == 'stripe') {
        if (!empty($payment_stripe_enable_test_mode)) {
            $stripe_public_key = $payment_stripe_test_public_key;
        } else {
            $stripe_public_key = $payment_stripe_live_public_key;
        }
        $stripe_js = <<<EOT
<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
<script type="text/javascript">
\tStripe.setPublishableKey('{$stripe_public_key}');
</script>
<script type="text/javascript" src="{$machform_path}js/payment_stripe.js"></script>
EOT;
    }
    $ssl_suffix = mf_get_ssl_suffix();
    $jquery_url = 'http' . $ssl_suffix . '://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js';
    $current_year = date("Y");
    $year_dropdown_markup = '';
    foreach (range($current_year, $current_year + 15) as $year) {
        $year_dropdown_markup .= "<option value=\"{$year}\">{$year}</option>" . "\n";
    }
    if ($integration_method == 'php') {
        $form_markup = <<<EOT
<link rel="stylesheet" type="text/css" href="{$machform_path}{$css_dir}view.css" media="all" />
<link rel="stylesheet" type="text/css" href="{$machform_path}view.mobile.css" media="all" />
{$theme_css_link}
{$font_css_markup}
<script type="text/javascript" src="{$jquery_url}"></script>
<script type="text/javascript" src="{$machform_path}js/jquery-ui/ui/jquery.effects.core.js"></script>
<script type="text/javascript" src="{$machform_path}view.js"></script>
{$stripe_js}
<style>
html{
\tbackground: none repeat scroll 0 0 transparent;
}
</style>

<div id="main_body" class="integrated no_guidelines" data-machformpath="{$machform_path}">
\t<div id="form_container">
\t\t<form id="form_{$form_id}" class="appnitro" method="post" action="javascript:" data-highlightcolor="{$field_highlight_color}">
\t\t    <div class="form_description">
\t\t\t\t<h2>{$form_payment_title}</h2>
\t\t\t\t<p>{$form_payment_description}</p>
\t\t\t</div>
\t\t\t{$pagination_header}
\t\t\t
\t\t\t<ul class="payment_summary">
\t\t\t\t<li class="payment_summary_amount total_payment" data-basetotal="{$total_payment_amount}">
\t\t\t\t\t<span>
\t\t\t\t\t\t<h3>{$currency_symbol}<var>0</var></h3>
\t\t\t\t\t\t<h5>{$mf_lang['payment_total']}</h5>
\t\t\t\t\t</span>
\t\t\t\t</li>
\t\t\t\t<li class="payment_summary_list">
\t\t\t\t\t<ul class="payment_list_items">
\t\t\t\t\t\t{$payment_list_items_markup}
\t\t\t\t\t</ul>
\t\t\t\t</li>
\t\t\t\t{$payment_term_markup}
\t\t\t</ul>
\t\t\t<ul class="payment_detail_form">
\t\t\t\t<li id="error_message" style="display: none">
\t\t\t\t\t\t<h3 id="error_message_title">{$mf_lang['error_title']}</h3>
\t\t\t\t\t\t<p id="error_message_desc">{$mf_lang['error_desc']}</p>
\t\t\t\t</li>\t
\t\t\t\t<li id="li_accepted_cards">
\t\t\t\t\t<img src="{$machform_path}images/cards/visa.png" alt="Visa" title="Visa" />
\t\t\t\t\t<img src="{$machform_path}images/cards/mastercard.png" alt="MasterCard" title="MasterCard" />
\t\t\t\t\t<img src="{$machform_path}images/cards/amex.png" alt="American Express" title="American Express" />
\t\t\t\t\t<img src="{$machform_path}images/cards/jcb.png" alt="JCB" title="JCB" />
\t\t\t\t\t<img src="{$machform_path}images/cards/discover.png" alt="Discover" title="Discover" />
\t\t\t\t\t<img src="{$machform_path}images/cards/diners.png" alt="Diners Club" title="Diners Club" />
\t\t\t\t</li>
\t\t\t\t<li id="li_credit_card" class="credit_card">
\t\t\t\t\t<label class="description">Credit Card <span class="required">*</span></label>
\t\t\t\t\t<div>
\t\t\t\t\t\t<span id="li_cc_span_1" class="left">
\t\t\t\t\t\t\t<input id="cc_first_name" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="cc_first_name">First Name</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t
\t\t\t\t\t\t<span id="li_cc_span_2" class="right">
\t\t\t\t\t\t\t<input id="cc_last_name" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="cc_last_name">Last Name</label>
\t\t\t\t\t\t</span>

\t\t\t\t\t\t<span id="li_cc_span_3" class="left">
\t\t\t\t\t\t\t<input id="cc_number" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="cc_number">Credit Card Number</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t
\t\t\t\t\t\t<span id="li_cc_span_4" class="right">
\t\t\t\t\t\t\t<input id="cc_cvv" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="cc_cvv">CVV</label>
\t\t\t\t\t\t</span>

\t\t\t\t\t\t<span id="li_cc_span_5" style="text-align: right">
\t\t\t\t\t\t\t<img id="cc_secure_icon" src="{$machform_path}images/icons/lock.png" alt="Secure" title="Secure" /> 
\t\t\t\t\t\t\t<label for="cc_expiry_month" style="display: inline">Expiration: </label>
\t\t\t\t\t\t\t<select class="element select" id="cc_expiry_month">
\t\t\t\t\t\t\t\t<option value="01">01 - January</option>
\t\t\t\t\t\t\t\t<option value="02">02 - February</option>
\t\t\t\t\t\t\t\t<option value="03">03 - March</option>
\t\t\t\t\t\t\t\t<option value="04">04 - April</option>
\t\t\t\t\t\t\t\t<option value="05">05 - May</option>
\t\t\t\t\t\t\t\t<option value="06">06 - June</option>
\t\t\t\t\t\t\t\t<option value="07">07 - July</option>
\t\t\t\t\t\t\t\t<option value="08">08 - August</option>
\t\t\t\t\t\t\t\t<option value="09">09 - September</option>
\t\t\t\t\t\t\t\t<option value="10">10 - October</option>
\t\t\t\t\t\t\t\t<option value="11">11 - November</option>
\t\t\t\t\t\t\t\t<option value="12">12 - December</option>
\t\t\t\t\t\t\t</select>
\t\t\t\t\t\t\t<select class="element select" id="cc_expiry_year">
\t\t\t\t\t\t\t\t{$year_dropdown_markup}
\t\t\t\t\t\t\t</select>
\t\t\t\t\t\t</span>
\t\t\t\t\t</div><p id="credit_card_error_message" class="error" style="display: none"></p>
\t\t\t\t</li>
\t\t\t\t<li id="li_2" class="section_break">
\t\t\t\t</li>
\t\t\t\t{$billing_address_markup}
\t\t\t\t{$shipping_address_markup}
\t\t\t\t<li id="li_buttons" class="buttons">
\t\t\t\t\t<input type="hidden" id="form_id" value="{$form_id}" />
\t\t\t\t    {$button_markup}
\t\t\t\t    <img id="mf_payment_loader_img" style="display: none" src="{$machform_path}images/loader_small_grey.gif" />
\t\t\t\t</li>
\t\t\t</ul>
\t\t</form>\t\t
\t\t<form id="form_payment_redirect" method="post" action="{$self_address}">
\t\t\t<input type="hidden" id="form_id_redirect" name="form_id_redirect" value="{$form_id}" />
\t\t</form>\t\t
\t</div>
</div>
EOT;
    } else {
        if ($integration_method == 'iframe') {
            $auto_height_js = <<<EOT
<script type="text/javascript" src="{$machform_path}js/jquery.ba-postmessage.min.js"></script>
<script type="text/javascript">
    \$(function(){
    \t\$.postMessage({mf_iframe_height: \$('body').outerHeight(true)}, '*', parent );
    });
</script>
EOT;
        }
        $form_markup = <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html {$embed_class} xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>{$form_name}</title>
<link rel="stylesheet" type="text/css" href="{$machform_path}{$css_dir}view.css" media="all" />
<link rel="stylesheet" type="text/css" href="{$machform_path}view.mobile.css" media="all" />
{$theme_css_link}
{$font_css_markup}
<script type="text/javascript" src="{$jquery_url}"></script>
<script type="text/javascript" src="{$machform_path}js/jquery-ui/ui/jquery.effects.core.js"></script>
<script type="text/javascript" src="{$machform_path}view.js"></script>
{$stripe_js}
{$auto_height_js}
</head>
<body id="main_body" class="no_guidelines" data-machformpath="{$machform_path}">
\t
\t<img id="top" src="{$machform_path}images/top.png" alt="" />
\t<div id="form_container" class="{$form_container_class}">
\t
\t\t<h1><a>MachForm</a></h1>
\t\t<form id="form_{$form_id}" class="appnitro" method="post" action="javascript:" data-highlightcolor="{$field_highlight_color}">
\t\t    <div class="form_description">
\t\t\t\t<h2>{$form_payment_title}</h2>
\t\t\t\t<p>{$form_payment_description}</p>
\t\t\t</div>
\t\t\t{$pagination_header}
\t\t\t
\t\t\t<ul class="payment_summary">
\t\t\t\t<li class="payment_summary_amount total_payment" data-basetotal="{$total_payment_amount}">
\t\t\t\t\t<span>
\t\t\t\t\t\t<h3>{$currency_symbol}<var>0</var></h3>
\t\t\t\t\t\t<h5>{$mf_lang['payment_total']}</h5>
\t\t\t\t\t</span>
\t\t\t\t</li>
\t\t\t\t<li class="payment_summary_list">
\t\t\t\t\t<ul class="payment_list_items">
\t\t\t\t\t\t{$payment_list_items_markup}
\t\t\t\t\t</ul>
\t\t\t\t</li>
\t\t\t\t{$payment_term_markup}
\t\t\t</ul>
\t\t\t<ul class="payment_detail_form">
\t\t\t\t<li id="error_message" style="display: none">
\t\t\t\t\t\t<h3 id="error_message_title">{$mf_lang['error_title']}</h3>
\t\t\t\t\t\t<p id="error_message_desc">{$mf_lang['error_desc']}</p>
\t\t\t\t</li>\t
\t\t\t\t<li id="li_accepted_cards">
\t\t\t\t\t<img src="{$machform_path}images/cards/visa.png" alt="Visa" title="Visa" />
\t\t\t\t\t<img src="{$machform_path}images/cards/mastercard.png" alt="MasterCard" title="MasterCard" />
\t\t\t\t\t<img src="{$machform_path}images/cards/amex.png" alt="American Express" title="American Express" />
\t\t\t\t\t<img src="{$machform_path}images/cards/jcb.png" alt="JCB" title="JCB" />
\t\t\t\t\t<img src="{$machform_path}images/cards/discover.png" alt="Discover" title="Discover" />
\t\t\t\t\t<img src="{$machform_path}images/cards/diners.png" alt="Diners Club" title="Diners Club" />
\t\t\t\t</li>
\t\t\t\t<li id="li_credit_card" class="credit_card">
\t\t\t\t\t<label class="description">Credit Card <span class="required">*</span></label>
\t\t\t\t\t<div>
\t\t\t\t\t\t<span id="li_cc_span_1" class="left">
\t\t\t\t\t\t\t<input id="cc_first_name" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="cc_first_name">First Name</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t
\t\t\t\t\t\t<span id="li_cc_span_2" class="right">
\t\t\t\t\t\t\t<input id="cc_last_name" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="cc_last_name">Last Name</label>
\t\t\t\t\t\t</span>

\t\t\t\t\t\t<span id="li_cc_span_3" class="left">
\t\t\t\t\t\t\t<input id="cc_number" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="cc_number">Credit Card Number</label>
\t\t\t\t\t\t</span>
\t\t\t\t\t
\t\t\t\t\t\t<span id="li_cc_span_4" class="right">
\t\t\t\t\t\t\t<input id="cc_cvv" class="element text large" value="" type="text" />
\t\t\t\t\t\t\t<label for="cc_cvv">CVV</label>
\t\t\t\t\t\t</span>

\t\t\t\t\t\t<span id="li_cc_span_5" style="text-align: right">
\t\t\t\t\t\t\t<img id="cc_secure_icon" src="{$machform_path}images/icons/lock.png" alt="Secure" title="Secure" /> 
\t\t\t\t\t\t\t<label for="cc_expiry_month" style="display: inline">Expiration: </label>
\t\t\t\t\t\t\t<select class="element select" id="cc_expiry_month">
\t\t\t\t\t\t\t\t<option value="01">01 - January</option>
\t\t\t\t\t\t\t\t<option value="02">02 - February</option>
\t\t\t\t\t\t\t\t<option value="03">03 - March</option>
\t\t\t\t\t\t\t\t<option value="04">04 - April</option>
\t\t\t\t\t\t\t\t<option value="05">05 - May</option>
\t\t\t\t\t\t\t\t<option value="06">06 - June</option>
\t\t\t\t\t\t\t\t<option value="07">07 - July</option>
\t\t\t\t\t\t\t\t<option value="08">08 - August</option>
\t\t\t\t\t\t\t\t<option value="09">09 - September</option>
\t\t\t\t\t\t\t\t<option value="10">10 - October</option>
\t\t\t\t\t\t\t\t<option value="11">11 - November</option>
\t\t\t\t\t\t\t\t<option value="12">12 - December</option>
\t\t\t\t\t\t\t</select>
\t\t\t\t\t\t\t<select class="element select" id="cc_expiry_year">
\t\t\t\t\t\t\t\t{$year_dropdown_markup}
\t\t\t\t\t\t\t</select>
\t\t\t\t\t\t</span>
\t\t\t\t\t</div><p id="credit_card_error_message" class="error" style="display: none"></p>
\t\t\t\t</li>
\t\t\t\t<li id="li_2" class="section_break">
\t\t\t\t</li>
\t\t\t\t{$billing_address_markup}
\t\t\t\t{$shipping_address_markup}
\t\t\t\t<li id="li_buttons" class="buttons">
\t\t\t\t\t<input type="hidden" id="form_id" value="{$form_id}" />
\t\t\t\t    {$button_markup}
\t\t\t\t    <img id="mf_payment_loader_img" style="display: none" src="{$machform_path}images/loader_small_grey.gif" />
\t\t\t\t</li>
\t\t\t</ul>
\t\t</form>\t\t
\t\t<form id="form_payment_redirect" method="post" action="{$self_address}">
\t\t\t<input type="hidden" id="form_id_redirect" name="form_id_redirect" value="{$form_id}" />
\t\t</form>\t
\t</div>
\t<img id="bottom" src="{$machform_path}images/bottom.png" alt="" />
\t</body>
</html>
EOT;
    }
    return $form_markup;
}
function mf_send_login_info($dbh, $user_id, $password)
{
    global $mf_lang;
    //get settings first
    $mf_settings = mf_get_settings($dbh);
    //get user information
    $query = "select user_fullname,user_email from " . MF_TABLE_PREFIX . "users where user_id=? and `status`=1";
    $params = array($user_id);
    $sth = mf_do_query($query, $params, $dbh);
    $row = mf_do_fetch_result($sth);
    $user_fullname = $row['user_fullname'];
    $user_email = $row['user_email'];
    $subject = 'Your MachForm login information';
    $email_template = <<<EOT
Hello %s,

You can login to MachForm panel using the following information:

<b>URL:</b> %s

<b>Email:</b> %s
<b>Password:</b> %s

Thank you.
EOT;
    $email_template = nl2br($email_template);
    $email_content = sprintf($email_template, $user_fullname, $mf_settings['base_url'], $user_email, $password);
    $subject = utf8_encode($subject);
    //create the mail transport
    if (!empty($mf_settings['smtp_enable'])) {
        $s_transport = Swift_SmtpTransport::newInstance($mf_settings['smtp_host'], $mf_settings['smtp_port']);
        if (!empty($mf_settings['smtp_secure'])) {
            $s_transport->setEncryption('tls');
        }
        if (!empty($mf_settings['smtp_auth'])) {
            $s_transport->setUsername($mf_settings['smtp_username']);
            $s_transport->setPassword($mf_settings['smtp_password']);
        }
    } else {
        $s_transport = Swift_MailTransport::newInstance();
        //use PHP mail() transport
    }
    //create mailer instance
    $s_mailer = Swift_Mailer::newInstance($s_transport);
    if (file_exists($mf_settings['upload_dir'] . "/form_{$form_id}/files") && is_writable($mf_settings['upload_dir'] . "/form_{$form_id}/files")) {
        Swift_Preferences::getInstance()->setCacheType('disk')->setTempDir($mf_settings['upload_dir'] . "/form_{$form_id}/files");
    } else {
        Swift_Preferences::getInstance()->setCacheType('array');
    }
    $from_name = html_entity_decode($mf_settings['default_from_name'], ENT_QUOTES);
    $from_email = $mf_settings['default_from_email'];
    if (!empty($user_email)) {
        $s_message = Swift_Message::newInstance()->setCharset('utf-8')->setMaxLineLength(1000)->setSubject($subject)->setFrom(array($from_email => $from_name))->setSender($from_email)->setReturnPath($from_email)->setTo($user_email)->setBody($email_content, 'text/html');
        //send the message
        $send_result = $s_mailer->send($s_message);
        if (empty($send_result)) {
            echo "Error sending email!";
        }
    }
}
function do_delta_update_3_3_to_3_4($dbh, $options = array())
{
    $post_install_error = '';
    $mf_settings = mf_get_settings($dbh);
    //1. Create table ap_field_logic_elements
    $query = "CREATE TABLE `" . MF_TABLE_PREFIX . "field_logic_elements` (\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `form_id` int(11) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `element_id` int(11) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `rule_show_hide` varchar(4) NOT NULL DEFAULT 'show',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `rule_all_any` varchar(3) NOT NULL DEFAULT 'all',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  PRIMARY KEY (`form_id`,`element_id`)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t) DEFAULT CHARACTER SET utf8;";
    $params = array();
    $sth = $dbh->prepare($query);
    try {
        $sth->execute($params);
    } catch (PDOException $e) {
        $post_install_error .= $e->getMessage() . '<br/><br/>';
    }
    //2. Create table ap_field_logic_conditions
    $query = "CREATE TABLE `" . MF_TABLE_PREFIX . "field_logic_conditions` (\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `alc_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `form_id` int(11) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `target_element_id` int(11) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `element_name` varchar(50) NOT NULL DEFAULT '',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `rule_condition` varchar(15) NOT NULL DEFAULT 'is',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `rule_keyword` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  PRIMARY KEY (`alc_id`)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t) DEFAULT CHARACTER SET utf8;";
    $params = array();
    $sth = $dbh->prepare($query);
    try {
        $sth->execute($params);
    } catch (PDOException $e) {
        $post_install_error .= $e->getMessage() . '<br/><br/>';
    }
    //3. Create table ap_form_payments
    $query = "CREATE TABLE `" . MF_TABLE_PREFIX . "form_payments` (\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `afp_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `form_id` int(11) unsigned NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `record_id` int(11) unsigned NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `payment_id` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `date_created` datetime DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `payment_date` datetime DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `payment_status` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `payment_fullname` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `payment_amount` decimal(62,2) NOT NULL DEFAULT '0.00',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `payment_currency` varchar(3) NOT NULL DEFAULT 'usd',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `payment_test_mode` int(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `payment_merchant_type` varchar(25) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `status` int(1) NOT NULL DEFAULT '1',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `billing_street` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `billing_city` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `billing_state` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `billing_zipcode` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `billing_country` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `same_shipping_address` int(1) NOT NULL DEFAULT '1',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `shipping_street` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `shipping_city` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `shipping_state` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `shipping_zipcode` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  `shipping_country` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   PRIMARY KEY (`afp_id`)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ) DEFAULT CHARACTER SET utf8;";
    $params = array();
    $sth = $dbh->prepare($query);
    try {
        $sth->execute($params);
    } catch (PDOException $e) {
        $post_install_error .= $e->getMessage() . '<br/><br/>';
    }
    //4. Create table ap_page_logic
    $query = "CREATE TABLE `" . MF_TABLE_PREFIX . "page_logic` (\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`form_id` int(11) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  \t`page_id` varchar(15) NOT NULL DEFAULT '',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  \t`rule_all_any` varchar(3) NOT NULL DEFAULT 'all',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  \t PRIMARY KEY (`form_id`,`page_id`)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   ) DEFAULT CHARACTER SET utf8;";
    $params = array();
    $sth = $dbh->prepare($query);
    try {
        $sth->execute($params);
    } catch (PDOException $e) {
        $post_install_error .= $e->getMessage() . '<br/><br/>';
    }
    //5. Create table ap_page_logic_conditions
    $query = "CREATE TABLE `" . MF_TABLE_PREFIX . "page_logic_conditions` (\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   `apc_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   `form_id` int(11) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   `target_page_id` varchar(15) NOT NULL DEFAULT '',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   `element_name` varchar(50) NOT NULL DEFAULT '',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   `rule_condition` varchar(15) NOT NULL DEFAULT 'is',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   `rule_keyword` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t    PRIMARY KEY (`apc_id`)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   \t\t\t  ) DEFAULT CHARACTER SET utf8;";
    $params = array();
    $sth = $dbh->prepare($query);
    try {
        $sth->execute($params);
    } catch (PDOException $e) {
        $post_install_error .= $e->getMessage() . '<br/><br/>';
    }
    //6. Alter ap_forms table. Add new columns
    $query = "ALTER TABLE `" . MF_TABLE_PREFIX . "forms` \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `logic_field_enable` tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `logic_page_enable` tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `payment_enable_trial` int(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `payment_trial_period` int(11) NOT NULL DEFAULT '1',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `payment_trial_unit` varchar(5) NOT NULL DEFAULT 'month',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `payment_trial_amount` decimal(62,2) NOT NULL DEFAULT '0.00',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `payment_stripe_live_secret_key` varchar(50) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t  \t\t\t  ADD COLUMN `payment_stripe_live_public_key` varchar(50) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t  \t\t\t  ADD COLUMN `payment_stripe_test_secret_key` varchar(50) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t  \t\t\t  ADD COLUMN `payment_stripe_test_public_key` varchar(50) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t  \t\t\t  ADD COLUMN `payment_stripe_enable_test_mode` int(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t\t\t\t\t\t\t  \t\t\t  ADD COLUMN `payment_paypal_enable_test_mode` int(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `payment_enable_invoice` int(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `payment_invoice_email` varchar(255) DEFAULT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `payment_delay_notifications` int(1) NOT NULL DEFAULT '1',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `payment_ask_billing` int(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  ADD COLUMN `payment_ask_shipping` int(1) NOT NULL DEFAULT '0';";
    $params = array();
    $sth = $dbh->prepare($query);
    try {
        $sth->execute($params);
    } catch (PDOException $e) {
        $post_install_error .= $e->getMessage() . '<br/><br/>';
    }
    //7. Update ap_forms records, set the value of 'payment_delay_notifications' to 0 for all records.
    //so that all existing paypal payments will still working as it is now.
    $query = "UPDATE `" . MF_TABLE_PREFIX . "forms` SET `payment_delay_notifications`=0";
    $params = array();
    $sth = $dbh->prepare($query);
    try {
        $sth->execute($params);
    } catch (PDOException $e) {
        $post_install_error .= $e->getMessage() . '<br/><br/>';
    }
    //8. Loop through each form CSS file and add new CSS code
    $query = "select `form_id` from " . MF_TABLE_PREFIX . "forms";
    $params = array();
    $sth = mf_do_query($query, $params, $dbh);
    while ($row = mf_do_fetch_result($sth)) {
        $form_id = $row['form_id'];
        $form_id_array[] = $form_id;
    }
    $new_css_code = <<<EOT

#main_body select.select { background-image: none; }
#main_body form li.guidelines_bottom .guidelines { clear: both; }
#main_body ul.payment_summary{
\toverflow: hidden;
}
#main_body form li.payment_summary_list{
\tborder-right: 1px dashed #ccc;
\tpadding-right: 10px;
\twidth: 70%;
\tfloat: right;
\tclear: none;
\ttext-align: right;
}
#main_body form li.payment_summary_amount{
\twidth: auto;
\tfloat: right;
\tclear: none;
}
#main_body form ul.payment_list_items li{
\twidth: 98%;
\tfont-size: 95%;
\tpadding-top: 0px;
\tpadding-bottom: 5px;
}
#main_body form ul.payment_list_items li span{
\tmargin: 0px;
\tfloat: right;
\tdisplay: block;
\tfont-weight: bold;
\tpadding: 0px;
\tpadding-left: 10px;
\tcolor: inherit;
}
#main_body form li.payment_summary_term{
\ttext-align: right;
\tfont-size: 90%;
\tpadding: 15px 0;
}
#main_body form li#li_accepted_cards{
\tmargin-bottom: 10px;
}
#li_accepted_cards img{
\theight: 27px;
}
#main_body form ul.payment_detail_form{
\tmargin-top: 20px
}
#main_body form li.credit_card div span{
\tpadding-bottom: 8px;
}
#main_body form li.credit_card div span#li_cc_span_3{
\twidth: 75%;
}
#main_body form li.credit_card div span#li_cc_span_4{
\twidth: 21%;
}
#cc_secure_icon{
\tfloat: left;
\tmargin-top:5px;
}
#cc_expiry_month{
\twidth: 23%;
}
#cc_expiry_year{
\twidth: 11%;
}
#li_billing_address span.state_list,
#li_shipping_address span.state_list{
\tpadding-bottom: 12px !important;
}
#li_shipping_address div.shipping_address_detail{
\tcontent: "";
    display: table;
  \tclear: both;
}
#li_credit_card{
\tpadding-bottom: 5px !important;
\tmargin-bottom: 20px !important;
}
EOT;
    foreach ($form_id_array as $form_id) {
        $target_css_file = $mf_settings['data_dir'] . "/form_{$form_id}/css/view.css";
        if (file_exists($target_css_file) && is_writable($target_css_file)) {
            file_put_contents($target_css_file, $new_css_code, FILE_APPEND);
        }
    }
    return $post_install_error;
}