function mf_validate_unique($value) { global $mf_lang; $input_value = $value[0]; $exploded = explode('#', $value[1]); $form_id = $exploded[0]; $element_name = $exploded[1]; $dbh = $value[2]['dbh']; if (!empty($_SESSION['edit_entry']) && $_SESSION['edit_entry']['form_id'] == $form_id) { //if admin is editing through edit_entry.php, bypass the unique checking if the new entry is the same as previous $query = "select count({$element_name}) total from " . MF_TABLE_PREFIX . "form_{$form_id} where {$element_name}=? and `id` != ? and {$element_name} is not null and {$element_name} <> ''"; $params = array($input_value, $_SESSION['edit_entry']['entry_id']); $sth = mf_do_query($query, $params, $dbh); $row = mf_do_fetch_result($sth); } else { $query = "select count({$element_name}) total from " . MF_TABLE_PREFIX . "form_{$form_id} where {$element_name}=? and resume_key is null"; $params = array($input_value); $sth = mf_do_query($query, $params, $dbh); $row = mf_do_fetch_result($sth); } if (!empty($row['total'])) { return $mf_lang['val_unique']; } else { return true; } }
function mf_theme_get_fonts_link($dbh, $theme_id) { $font_family_array = array(); $query = "SELECT\r\n\t\t\t\t\t\tform_title_font_type,\r\n\t\t\t\t\t\tform_desc_font_type,\r\n\t\t\t\t\t\tfield_title_font_type,\r\n\t\t\t\t\t\tguidelines_font_type,\r\n\t\t\t\t\t\tsection_title_font_type,\r\n\t\t\t\t\t\tsection_desc_font_type,\r\n\t\t\t\t\t\tfield_text_font_type\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); $font_family_array[] = $row['form_title_font_type']; $font_family_array[] = $row['form_desc_font_type']; $font_family_array[] = $row['field_title_font_type']; $font_family_array[] = $row['guidelines_font_type']; $font_family_array[] = $row['section_title_font_type']; $font_family_array[] = $row['section_desc_font_type']; $font_family_array[] = $row['field_text_font_type']; /** Build the font CSS tag **/ if (!empty($font_family_array)) { $font_family_joined = implode("','", $font_family_array); $query = "SELECT font_family,font_variants FROM " . MF_TABLE_PREFIX . "fonts WHERE font_family IN('{$font_family_joined}')"; $params = array(); $sth = mf_do_query($query, $params, $dbh); $font_css_array = array(); while ($row = mf_do_fetch_result($sth)) { $font_css_array[] = urlencode($row['font_family']) . ":" . $row['font_variants']; } $ssl_suffix = mf_get_ssl_suffix(); $font_css_markup = implode('|', $font_css_array); if (!empty($font_css_array)) { $font_css_markup = "<link href='http{$ssl_suffix}://fonts.googleapis.com/css?family={$font_css_markup}' rel='stylesheet' type='text/css'>\n"; } else { $font_css_markup = ''; } } return $font_css_markup; }
break; } $font_variants_pair[$font_variant_raw] = $primary_style . $secondary_style; } $font_family_slug = strtolower(str_replace(' ', '', $row['font_family'])); $font_data[$font_family_slug] = $font_variants_pair; //build the css markup for each font $font_css_array[] = urlencode($row['font_family']) . ":" . $row['font_variants']; } $font_css_markup = implode('|', $font_css_array); $font_css_markup = "<link href='http://fonts.googleapis.com/css?family={$font_css_markup}' rel='stylesheet' type='text/css'>\n"; //determine if the font list is reaching the end or not $query = "select max(font_id) max_font_id from " . MF_TABLE_PREFIX . "fonts"; $params = array(); $sth = mf_do_query($query, $params, $dbh); $row = mf_do_fetch_result($sth); if ($end_font_id > $row['max_font_id']) { $list_end = true; } else { $list_end = false; } //send the final markup and data $response_data = new stdClass(); $response_data->status = "ok"; $response_data->markup = $font_list_markup; $response_data->last_font_id = $end_font_id - 1; $response_data->list_end = $list_end; $response_data->font_styles = $font_data; $response_data->font_css_markup = $font_css_markup; $response_json = json_encode($response_data); echo $response_json;
function mf_get_required_elements_status($dbh, $form_id, $page_number, $user_input) { //get all fields within current page which has "required" property and has conditions $query = "SELECT \r\n\t\t\t\t\t\tA.element_id \r\n\t\t\t\t\tFROM \r\n\t\t\t\t\t\t" . MF_TABLE_PREFIX . "form_elements A LEFT JOIN " . MF_TABLE_PREFIX . "field_logic_elements B \r\n\t\t\t\t\t ON \r\n\t\t\t\t\t \tA.form_id=B.form_id and A.element_id=B.element_id\r\n\t\t\t\t WHERE \r\n\t\t\t\t \t\tA.form_id = ? and \r\n\t\t\t\t \t\tA.element_status = 1 and \r\n\t\t\t\t \t\tA.element_page_number = ? and \r\n\t\t\t\t \t\tA.element_is_required = 1 and \r\n\t\t\t\t \t\tB.element_id is not null\r\n\t\t\t\tORDER BY \r\n\t\t\t\t\t\tA.element_position asc"; $params = array($form_id, $page_number); $sth = mf_do_query($query, $params, $dbh); $required_fields_array = array(); while ($row = mf_do_fetch_result($sth)) { $required_fields_array[] = $row['element_id']; } $required_elements_status = array(); //loop through each field and check for the conditions if (!empty($required_fields_array)) { foreach ($required_fields_array as $element_id) { $current_element_conditions_status = array(); $query = "select rule_show_hide,rule_all_any from " . MF_TABLE_PREFIX . "field_logic_elements where form_id = ? and element_id = ?"; $params = array($form_id, $element_id); $sth = mf_do_query($query, $params, $dbh); $row = mf_do_fetch_result($sth); $rule_show_hide = $row['rule_show_hide']; $rule_all_any = $row['rule_all_any']; //get all conditions for current field $query = "SELECT \r\n\t\t\t\t\t\tA.target_element_id,\r\n\t\t\t\t\t\tA.element_name,\r\n\t\t\t\t\t\tA.rule_condition,\r\n\t\t\t\t\t\tA.rule_keyword,\r\n\t\t\t\t\t\ttrim(leading 'element_' from substring_index(A.element_name,'_',2)) as condition_element_id,\r\n\t\t\t\t\t\t(select \r\n\t\t\t\t\t\t\t B.element_page_number \r\n\t\t\t\t\t\t from \r\n\t\t\t\t\t\t \t " . MF_TABLE_PREFIX . "form_elements B \r\n\t\t\t\t\t\t where \r\n\t\t\t\t\t\t \t\tform_id=A.form_id and \r\n\t\t\t\t\t\t \t\telement_id=condition_element_id\r\n\t\t\t\t\t\t) condition_element_page_number,\r\n\t\t\t\t\t\t(select \r\n\t\t\t\t\t\t\t C.element_type \r\n\t\t\t\t\t\t from \r\n\t\t\t\t\t\t \t " . MF_TABLE_PREFIX . "form_elements C \r\n\t\t\t\t\t\t where \r\n\t\t\t\t\t\t \t\tform_id=A.form_id and \r\n\t\t\t\t\t\t \t\telement_id=condition_element_id\r\n\t\t\t\t\t\t) condition_element_type\r\n\t\t\t\t\tFROM \r\n\t\t\t\t\t\t" . MF_TABLE_PREFIX . "field_logic_conditions A \r\n\t\t\t\t WHERE\r\n\t\t\t\t\t\tA.form_id = ? and A.target_element_id = ?"; $params = array($form_id, $element_id); $sth = mf_do_query($query, $params, $dbh); $i = 0; $logic_conditions_array = array(); while ($row = mf_do_fetch_result($sth)) { $logic_conditions_array[$i]['element_name'] = $row['element_name']; $logic_conditions_array[$i]['element_type'] = $row['condition_element_type']; $logic_conditions_array[$i]['rule_condition'] = $row['rule_condition']; $logic_conditions_array[$i]['rule_keyword'] = $row['rule_keyword']; $logic_conditions_array[$i]['element_page_number'] = (int) $row['condition_element_page_number']; $i++; } //loop through each condition which is not coming from the current page foreach ($logic_conditions_array as $value) { if ($value['element_page_number'] == $page_number) { continue; } $condition_params = array(); $condition_params['form_id'] = $form_id; $condition_params['element_name'] = $value['element_name']; $condition_params['rule_condition'] = $value['rule_condition']; $condition_params['rule_keyword'] = $value['rule_keyword']; $current_element_conditions_status[] = mf_get_condition_status_from_table($dbh, $condition_params); } //loop through each condition which is coming from the current page foreach ($logic_conditions_array as $value) { if ($value['element_page_number'] != $page_number) { continue; } $condition_params = array(); $condition_params['form_id'] = $form_id; $condition_params['element_name'] = $value['element_name']; $condition_params['rule_condition'] = $value['rule_condition']; $condition_params['rule_keyword'] = $value['rule_keyword']; $current_element_conditions_status[] = mf_get_condition_status_from_input($dbh, $condition_params, $user_input); } //decide the status of the current element_id based on all conditions //required field should only being applied to an element which is being shown into the form //any field which is hidden due to conditions, shouldn't have any required attribute if ($rule_all_any == 'all') { if (in_array(false, $current_element_conditions_status)) { $all_conditions_status = false; } else { $all_conditions_status = true; } } else { if ($rule_all_any == 'any') { if (in_array(true, $current_element_conditions_status)) { $all_conditions_status = true; } else { $all_conditions_status = false; } } } if ($rule_show_hide == 'show') { if ($all_conditions_status === true) { $element_status = true; } else { $element_status = false; } } else { if ($rule_show_hide == 'hide') { if ($all_conditions_status === true) { $element_status = false; } else { $element_status = true; } } } if ($element_status === true) { $required_elements_status[$element_id] = 1; } else { $required_elements_status[$element_id] = 0; } } //end foreach required fields } return $required_elements_status; }
sort($all_tagnames); $jquery_data_code .= "\$('#dialog-enter-tagname-input').data('available_tags'," . json_encode($all_tagnames) . ");\n"; //get the available custom themes $query = "SELECT theme_id,theme_name FROM " . MF_TABLE_PREFIX . "form_themes WHERE theme_built_in=0 and status=1 ORDER BY theme_name ASC"; $params = array(); $sth = mf_do_query($query, $params, $dbh); $theme_list_array = array(); while ($row = mf_do_fetch_result($sth)) { $theme_list_array[$row['theme_id']] = htmlspecialchars($row['theme_name']); } //get built-in themes $query = "SELECT theme_id,theme_name FROM " . MF_TABLE_PREFIX . "form_themes WHERE theme_built_in=1 and status=1 ORDER BY theme_name ASC"; $params = array(); $sth = mf_do_query($query, $params, $dbh); $theme_builtin_list_array = array(); while ($row = mf_do_fetch_result($sth)) { $theme_builtin_list_array[$row['theme_id']] = htmlspecialchars($row['theme_name']); } $header_data = <<<EOT <link type="text/css" href="js/jquery-ui/themes/base/jquery.ui.all.css" rel="stylesheet" /> <link type="text/css" href="css/pagination_classic.css" rel="stylesheet" /> <link type="text/css" href="css/dropui.css" rel="stylesheet" /> EOT; $current_nav_tab = 'manage_forms'; ?> <br /> <div id="content" class="full"> <div class="post manage_forms"> <?php
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'] = ' '; $data['value'] = ' '; $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">></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">></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 = '$'; switch ($payment_currency) { case 'USD': $currency_symbol = '$'; break; case 'EUR': $currency_symbol = '€'; break; case 'GBP': $currency_symbol = '£'; break; case 'AUD': $currency_symbol = 'A$'; break; case 'CAD': $currency_symbol = 'C$'; break; case 'JPY': $currency_symbol = '¥'; break; case 'THB': $currency_symbol = '฿'; break; case 'HUF': $currency_symbol = 'Ft'; break; case 'CHF': $currency_symbol = 'CHF'; break; case 'CZK': $currency_symbol = 'Kč'; break; case 'SEK': $currency_symbol = 'kr'; break; case 'DKK': $currency_symbol = 'kr'; break; case 'PHP': $currency_symbol = '$'; break; case 'MYR': $currency_symbol = 'RM'; break; case 'PLN': $currency_symbol = 'zł'; break; case 'BRL': $currency_symbol = 'R$'; break; case 'HKD': $currency_symbol = 'HK$'; break; case 'MXN': $currency_symbol = 'Mex$'; break; case 'TWD': $currency_symbol = 'NT$'; 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_mysql_column_exist($table_name, $column_name, $dbh) { $query = "SHOW COLUMNS FROM {$table_name} LIKE '{$column_name}'"; $sth = mf_do_query($query, array(), $dbh); $row = mf_do_fetch_result($sth); if (!empty($row)) { return true; } else { return false; } }
function mf_get_user_permissions_all($dbh, $user_id) { $query = "SELECT \r\n\t\t\t\t\t\t`edit_form`,`edit_entries`,`view_entries`,`form_id` \r\n\t\t\t\t\tFROM \r\n\t\t\t\t\t\t`" . MF_TABLE_PREFIX . "permissions`\r\n\t\t\t\t WHERE\r\n\t\t\t\t \t\t`user_id` = ?"; $params = array($user_id); $sth = mf_do_query($query, $params, $dbh); while ($row = mf_do_fetch_result($sth)) { $form_id = $row['form_id']; $edit_form = false; $edit_entries = false; $view_entries = false; if (!empty($row['edit_form'])) { $edit_form = true; } if (!empty($row['edit_entries'])) { $edit_entries = true; } if (!empty($row['view_entries'])) { $view_entries = true; } $perms[$form_id]['edit_form'] = $edit_form; $perms[$form_id]['edit_entries'] = $edit_entries; $perms[$form_id]['view_entries'] = $view_entries; } return $perms; }
function mf_get_settings($dbh) { $query = "SELECT * FROM " . MF_TABLE_PREFIX . "settings"; $sth = mf_do_query($query, array(), $dbh); $row = mf_do_fetch_result($sth); return $row; }
function mf_get_filtered_entries_ids($dbh, $form_id) { //get filter keywords from ap_form_filters table $query = "select\r\n\t\t\t\t\t\telement_name,\r\n\t\t\t\t\t\tfilter_condition,\r\n\t\t\t\t\t\tfilter_keyword\r\n\t\t\t\t\tfrom \r\n\t\t\t\t\t\t" . MF_TABLE_PREFIX . "form_filters\r\n\t\t\t\t where\r\n\t\t\t\t \t\tform_id = ?\r\n\t\t\t\torder by \r\n\t\t\t\t \t\taff_id asc"; $params = array($form_id); $sth = mf_do_query($query, $params, $dbh); $i = 0; while ($row = mf_do_fetch_result($sth)) { $filter_data[$i]['element_name'] = $row['element_name']; $filter_data[$i]['filter_condition'] = $row['filter_condition']; $filter_data[$i]['filter_keyword'] = $row['filter_keyword']; $i++; } $query = "select \r\n\t\t\t\t\t\t entries_filter_type,\r\n\t\t\t\t\t\t entries_sort_by\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); if (!empty($row)) { $filter_type = $row['entries_filter_type']; $sort_by = $row['entries_sort_by']; $exploded = explode('-', $sort_by); $sort_element = $exploded[0]; //the element name, e.g. element_2 $sort_order = $exploded[1]; //asc or desc } /******************************************************************************************/ //prepare column header names lookup //get form element options first (checkboxes, choices, dropdown) $query = "select \r\n\t\t\t\t\t\telement_id,\r\n\t\t\t\t\t\toption_id,\r\n\t\t\t\t\t\t`option`\r\n\t\t\t\t\tfrom \r\n\t\t\t\t\t\t" . MF_TABLE_PREFIX . "element_options \r\n\t\t\t\t where \r\n\t\t\t\t \t\tform_id=? and live=1 \r\n\t\t\t\torder by \r\n\t\t\t\t\t\telement_id,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']; $element_option_lookup[$element_id][$option_id] = htmlspecialchars($row['option'], ENT_QUOTES); } //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); } //get 'multiselect' status of matrix fields $query = "select \r\n\t\t\t\t\t\t A.element_id,\r\n\t\t\t\t\t\t A.element_matrix_parent_id,\r\n\t\t\t\t\t\t A.element_matrix_allow_multiselect,\r\n\t\t\t\t\t\t (select if(A.element_matrix_parent_id=0,A.element_matrix_allow_multiselect,\r\n\t\t\t\t\t\t \t\t\t (select B.element_matrix_allow_multiselect from " . MF_TABLE_PREFIX . "form_elements B where B.form_id=A.form_id and B.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 ) 'multiselect' \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\t where \r\n\t\t\t\t\t \t A.form_id=? and A.element_status=1 and A.element_type='matrix'"; $params = array($form_id); $sth = mf_do_query($query, $params, $dbh); while ($row = mf_do_fetch_result($sth)) { $matrix_multiselect_status[$row['element_id']] = $row['multiselect']; } /******************************************************************************************/ //set column properties for basic fields $column_name_lookup['date_created'] = 'Date Created'; $column_name_lookup['date_updated'] = 'Date Updated'; $column_name_lookup['ip_address'] = 'IP Address'; $column_type_lookup['id'] = 'number'; $column_type_lookup['row_num'] = 'number'; $column_type_lookup['date_created'] = 'date'; $column_type_lookup['date_updated'] = 'date'; $column_type_lookup['ip_address'] = 'text'; //get column properties for other fields $query = "select \r\n\t\t\t\t\t\t element_id,\r\n\t\t\t\t\t\t element_title,\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_choice_has_other,\r\n\t\t\t\t\t\t element_choice_other_label,\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 element_matrix_allow_multiselect \r\n\t\t\t\t from \r\n\t\t\t\t `" . MF_TABLE_PREFIX . "form_elements` \r\n\t\t\t\t where \r\n\t\t\t\t \t form_id=? and element_status=1 and element_type not in('section','page_break')\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); $element_radio_has_other = array(); while ($row = mf_do_fetch_result($sth)) { $element_type = $row['element_type']; $element_constraint = $row['element_constraint']; //get 'other' field label for checkboxes and radio button if ($element_type == 'checkbox' || $element_type == 'radio') { if (!empty($row['element_choice_has_other'])) { $element_option_lookup[$row['element_id']]['other'] = htmlspecialchars($row['element_choice_other_label'], ENT_QUOTES); if ($element_type == 'radio') { $element_radio_has_other['element_' . $row['element_id']] = true; } } } $row['element_title'] = htmlspecialchars($row['element_title'], ENT_QUOTES); if ('address' == $element_type) { //address has 6 fields $column_name_lookup['element_' . $row['element_id'] . '_1'] = $row['element_title'] . ' - Street Address'; $column_name_lookup['element_' . $row['element_id'] . '_2'] = 'Address Line 2'; $column_name_lookup['element_' . $row['element_id'] . '_3'] = 'City'; $column_name_lookup['element_' . $row['element_id'] . '_4'] = 'State/Province/Region'; $column_name_lookup['element_' . $row['element_id'] . '_5'] = 'Zip/Postal Code'; $column_name_lookup['element_' . $row['element_id'] . '_6'] = 'Country'; $column_type_lookup['element_' . $row['element_id'] . '_1'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_2'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_3'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_4'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_5'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_6'] = $row['element_type']; } elseif ('simple_name' == $element_type) { //simple name has 2 fields $column_name_lookup['element_' . $row['element_id'] . '_1'] = $row['element_title'] . ' - First'; $column_name_lookup['element_' . $row['element_id'] . '_2'] = $row['element_title'] . ' - Last'; $column_type_lookup['element_' . $row['element_id'] . '_1'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_2'] = $row['element_type']; } elseif ('simple_name_wmiddle' == $element_type) { //simple name with middle has 3 fields $column_name_lookup['element_' . $row['element_id'] . '_1'] = $row['element_title'] . ' - First'; $column_name_lookup['element_' . $row['element_id'] . '_2'] = $row['element_title'] . ' - Middle'; $column_name_lookup['element_' . $row['element_id'] . '_3'] = $row['element_title'] . ' - Last'; $column_type_lookup['element_' . $row['element_id'] . '_1'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_2'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_3'] = $row['element_type']; } elseif ('name' == $element_type) { //name has 4 fields $column_name_lookup['element_' . $row['element_id'] . '_1'] = $row['element_title'] . ' - Title'; $column_name_lookup['element_' . $row['element_id'] . '_2'] = $row['element_title'] . ' - First'; $column_name_lookup['element_' . $row['element_id'] . '_3'] = $row['element_title'] . ' - Last'; $column_name_lookup['element_' . $row['element_id'] . '_4'] = $row['element_title'] . ' - Suffix'; $column_type_lookup['element_' . $row['element_id'] . '_1'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_2'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_3'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_4'] = $row['element_type']; } elseif ('name_wmiddle' == $element_type) { //name with middle has 5 fields $column_name_lookup['element_' . $row['element_id'] . '_1'] = $row['element_title'] . ' - Title'; $column_name_lookup['element_' . $row['element_id'] . '_2'] = $row['element_title'] . ' - First'; $column_name_lookup['element_' . $row['element_id'] . '_3'] = $row['element_title'] . ' - Middle'; $column_name_lookup['element_' . $row['element_id'] . '_4'] = $row['element_title'] . ' - Last'; $column_name_lookup['element_' . $row['element_id'] . '_5'] = $row['element_title'] . ' - Suffix'; $column_type_lookup['element_' . $row['element_id'] . '_1'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_2'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_3'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_4'] = $row['element_type']; $column_type_lookup['element_' . $row['element_id'] . '_5'] = $row['element_type']; } elseif ('money' == $element_type) { //money format $column_name_lookup['element_' . $row['element_id']] = $row['element_title']; if (!empty($element_constraint)) { $column_type_lookup['element_' . $row['element_id']] = 'money_' . $element_constraint; //euro, pound, yen,etc } else { $column_type_lookup['element_' . $row['element_id']] = 'money_dollar'; //default is dollar } } elseif ('checkbox' == $element_type) { //checkboxes, get childs elements $this_checkbox_options = $element_option_lookup[$row['element_id']]; foreach ($this_checkbox_options as $option_id => $option) { $column_name_lookup['element_' . $row['element_id'] . '_' . $option_id] = htmlspecialchars($option, ENT_QUOTES); $column_type_lookup['element_' . $row['element_id'] . '_' . $option_id] = $row['element_type']; } } elseif ('time' == $element_type) { if (!empty($row['element_time_showsecond']) && !empty($row['element_time_24hour'])) { $column_type_lookup['element_' . $row['element_id']] = 'time_24hour'; } else { if (!empty($row['element_time_showsecond'])) { $column_type_lookup['element_' . $row['element_id']] = 'time'; } else { if (!empty($row['element_time_24hour'])) { $column_type_lookup['element_' . $row['element_id']] = 'time_24hour_noseconds'; } else { $column_type_lookup['element_' . $row['element_id']] = 'time_noseconds'; } } } $column_name_lookup['element_' . $row['element_id']] = $row['element_title']; } else { if ('matrix' == $element_type) { if (empty($matrix_multiselect_status[$row['element_id']])) { $column_name_lookup['element_' . $row['element_id']] = $row['element_title']; $column_type_lookup['element_' . $row['element_id']] = 'matrix_radio'; } else { $this_checkbox_options = $matrix_element_option_lookup[$row['element_id']]; foreach ($this_checkbox_options as $option_id => $option) { $option = $option . ' - ' . $row['element_title']; $column_name_lookup['element_' . $row['element_id'] . '_' . $option_id] = htmlspecialchars($option, ENT_QUOTES); $column_type_lookup['element_' . $row['element_id'] . '_' . $option_id] = 'matrix_checkbox'; } } } else { //for other elements with only 1 field $column_name_lookup['element_' . $row['element_id']] = $row['element_title']; $column_type_lookup['element_' . $row['element_id']] = $row['element_type']; } } } /******************************************************************************************/ //get column preferences and store it into array $query = "select element_name from " . MF_TABLE_PREFIX . "column_preferences where form_id=? order by position asc"; $params = array($form_id); $sth = mf_do_query($query, $params, $dbh); while ($row = mf_do_fetch_result($sth)) { $column_prefs[] = $row['element_name']; } //if there is no column preferences, display the first 6 fields if (empty($column_prefs)) { $temp_slice = array_slice($column_name_lookup, 0, 8); unset($temp_slice['date_updated']); unset($temp_slice['ip_address']); $column_prefs = array_keys($temp_slice); } //get the entries from ap_form_x table and store it into array $column_prefs_joined = '`' . implode("`,`", $column_prefs) . '`'; //if there is any radio fields which has 'other', we need to query that field as well if (!empty($element_radio_has_other)) { $radio_has_other_array = array(); foreach ($element_radio_has_other as $element_name => $value) { $radio_has_other_array[] = $element_name . '_other'; } $radio_has_other_joined = '`' . implode("`,`", $radio_has_other_array) . '`'; $column_prefs_joined = $column_prefs_joined . ',' . $radio_has_other_joined; } //check for filter data and build the filter query if (!empty($filter_data)) { if ($filter_type == 'all') { $condition_type = ' AND '; } else { $condition_type = ' OR '; } $where_clause_array = array(); foreach ($filter_data as $value) { $element_name = $value['element_name']; $filter_condition = $value['filter_condition']; $filter_keyword = $value['filter_keyword']; $filter_element_type = $column_type_lookup[$element_name]; $temp = explode('_', $element_name); $element_id = $temp[1]; if (in_array($filter_element_type, array('radio', 'select', 'matrix_radio'))) { //these types need special steps to filter //we need to look into the ap_element_options first and do the filter there if ($filter_condition == 'is') { $where_operand = '='; $where_keyword = "'{$filter_keyword}'"; } else { if ($filter_condition == 'is_not') { $where_operand = '<>'; $where_keyword = "'{$filter_keyword}'"; } else { if ($filter_condition == 'begins_with') { $where_operand = 'LIKE'; $where_keyword = "'{$filter_keyword}%'"; } else { if ($filter_condition == 'ends_with') { $where_operand = 'LIKE'; $where_keyword = "'%{$filter_keyword}'"; } else { if ($filter_condition == 'contains') { $where_operand = 'LIKE'; $where_keyword = "'%{$filter_keyword}%'"; } else { if ($filter_condition == 'not_contain') { $where_operand = 'NOT LIKE'; $where_keyword = "'%{$filter_keyword}%'"; } } } } } } //do a query to ap_element_options table $query = "select \r\n\t\t\t\t\t\t\t\t\toption_id \r\n\t\t\t\t\t\t\t\tfrom \r\n\t\t\t\t\t\t\t\t\t" . MF_TABLE_PREFIX . "element_options \r\n\t\t\t\t\t\t\t where \r\n\t\t\t\t\t\t\t \t\tform_id=? and \r\n\t\t\t\t\t\t\t\t\telement_id=? and\r\n\t\t\t\t\t\t\t \t\tlive=1 and \r\n\t\t\t\t\t\t\t \t\t`option` {$where_operand} {$where_keyword}"; $params = array($form_id, $element_id); $filtered_option_id_array = array(); $sth = mf_do_query($query, $params, $dbh); while ($row = mf_do_fetch_result($sth)) { $filtered_option_id_array[] = $row['option_id']; } $filtered_option_id = implode("','", $filtered_option_id_array); if ($filter_element_type == 'radio' && !empty($radio_has_other_array)) { if (in_array($element_name . '_other', $radio_has_other_array)) { $filter_radio_has_other = true; } else { $filter_radio_has_other = false; } } if ($filter_radio_has_other) { //if the filter is radio button field with 'other' if (!empty($filtered_option_id_array)) { $where_clause_array[] = "({$element_name} IN('{$filtered_option_id}') OR {$element_name}_other {$where_operand} {$where_keyword})"; } else { $where_clause_array[] = "{$element_name}_other {$where_operand} {$where_keyword}"; } } else { //otherwise, for the rest of the field types if (!empty($filtered_option_id_array)) { $where_clause_array[] = "{$element_name} IN('{$filtered_option_id}')"; } } } else { if (in_array($filter_element_type, array('date', 'europe_date'))) { $date_exploded = array(); $date_exploded = explode('/', $filter_keyword); //the filter_keyword has format mm/dd/yyyy $filter_keyword = $date_exploded[2] . '-' . $date_exploded[0] . '-' . $date_exploded[1]; if ($filter_condition == 'is') { $where_operand = '='; $where_keyword = "'{$filter_keyword}'"; } else { if ($filter_condition == 'is_before') { $where_operand = '<'; $where_keyword = "'{$filter_keyword}'"; } else { if ($filter_condition == 'is_after') { $where_operand = '>'; $where_keyword = "'{$filter_keyword}'"; } } } $where_clause_array[] = "date({$element_name}) {$where_operand} {$where_keyword}"; } else { if ($filter_condition == 'is') { $where_operand = '='; $where_keyword = "'{$filter_keyword}'"; } else { if ($filter_condition == 'is_not') { $where_operand = '<>'; $where_keyword = "'{$filter_keyword}'"; } else { if ($filter_condition == 'begins_with') { $where_operand = 'LIKE'; $where_keyword = "'{$filter_keyword}%'"; } else { if ($filter_condition == 'ends_with') { $where_operand = 'LIKE'; $where_keyword = "'%{$filter_keyword}'"; } else { if ($filter_condition == 'contains') { $where_operand = 'LIKE'; $where_keyword = "'%{$filter_keyword}%'"; } else { if ($filter_condition == 'not_contain') { $where_operand = 'NOT LIKE'; $where_keyword = "'%{$filter_keyword}%'"; } else { if ($filter_condition == 'less_than' || $filter_condition == 'is_before') { $where_operand = '<'; $where_keyword = "'{$filter_keyword}'"; } else { if ($filter_condition == 'greater_than' || $filter_condition == 'is_after') { $where_operand = '>'; $where_keyword = "'{$filter_keyword}'"; } else { if ($filter_condition == 'is_one') { $where_operand = '='; $where_keyword = "'1'"; } else { if ($filter_condition == 'is_zero') { $where_operand = '='; $where_keyword = "'0'"; } } } } } } } } } } $where_clause_array[] = "{$element_name} {$where_operand} {$where_keyword}"; } } } $where_clause = implode($condition_type, $where_clause_array); if (empty($where_clause)) { $where_clause = "WHERE `status`=1"; } else { $where_clause = "WHERE ({$where_clause}) AND `status`=1"; } } else { $where_clause = "WHERE `status`=1"; } //check the sorting element //if the element type is radio, select or matrix_radio, we need to add a sub query to the main query //so that the fields can be sorted properly (the sub query need to get values from ap_element_options table) $sort_element_type = $column_type_lookup[$sort_element]; if (in_array($sort_element_type, array('radio', 'select', 'matrix_radio'))) { if ($sort_element_type == 'radio' && !empty($radio_has_other_array)) { if (in_array($sort_element . '_other', $radio_has_other_array)) { $sort_radio_has_other = true; } } $temp = explode('_', $sort_element); $sort_element_id = $temp[1]; if ($sort_radio_has_other) { //if this is radio button field with 'other' enabled $sorting_query = ",(\t\r\n\t\t\t\t\t\t\t\t\t\tselect if(A.{$sort_element}=0,A.{$sort_element}_other,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t(select \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`option` \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfrom " . MF_TABLE_PREFIX . "element_options \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t where \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t \t\tform_id='{$form_id}' and \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t \t\telement_id='{$sort_element_id}' and \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t \t\toption_id=A.{$sort_element} and \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t \t\tlive=1)\r\n\t\t\t\t\t\t\t\t\t \t)\r\n\t\t\t\t\t\t\t\t ) {$sort_element}_key"; } else { $sorting_query = ",(\r\n\t\t\t\t\t\t\t\t\tselect \r\n\t\t\t\t\t\t\t\t\t\t\t`option` \r\n\t\t\t\t\t\t\t\t\t\tfrom " . MF_TABLE_PREFIX . "element_options \r\n\t\t\t\t\t\t\t\t\t where \r\n\t\t\t\t\t\t\t\t\t \t\tform_id='{$form_id}' and \r\n\t\t\t\t\t\t\t\t\t \t\telement_id='{$sort_element_id}' and \r\n\t\t\t\t\t\t\t\t\t \t\toption_id=A.{$sort_element} and \r\n\t\t\t\t\t\t\t\t\t \t\tlive=1\r\n\t\t\t\t\t\t\t\t ) {$sort_element}_key"; } //override the $sort_element $sort_element .= '_key'; } $query = "select \r\n\t\t\t\t\t\t`id`,\r\n\t\t\t\t\t\t`id` as `row_num`,\r\n\t\t\t\t\t\t{$column_prefs_joined}\r\n\t\t\t\t\t\t{$sorting_query}\r\n\t\t\t\t from \r\n\t\t\t\t \t" . MF_TABLE_PREFIX . "form_{$form_id} A \r\n\t\t\t\t \t{$where_clause}\r\n\t\t\t\torder by \r\n\t\t\t\t\t\t{$sort_element} {$sort_order}"; $params = array(); $sth = mf_do_query($query, $params, $dbh); $filtered_entry_id_array = array(); while ($row = mf_do_fetch_result($sth)) { $filtered_entry_id_array[] = $row['id']; } return $filtered_entry_id_array; }
function mf_get_payment_total($dbh, $form_id, $session_id, $exclude_page_number) { $total_payment_amount = 0; //get price fields information from ap_element_prices table $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\tA.price,\r\n\t\t\t\t\t\tB.element_title,\r\n\t\t\t\t\t\tB.element_type,\r\n\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\tfrom\r\n\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 where\r\n\t\t\t\t\t\tA.form_id = ? and B.element_page_number <> ?\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, $exclude_page_number); $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 (empty($price_field_columns)) { return 0; } $price_field_columns_joined = implode(',', $price_field_columns); //check the value of the price fields from the ap_form_x_review table $query = "select {$price_field_columns_joined} from " . MF_TABLE_PREFIX . "form_{$form_id}_review where `session_id`=?"; $params = array($session_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; } } return $total_payment_amount; }
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 = '$'; 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">></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">></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">></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_get_form_properties($dbh, $form_id, $columns = array()) { if (!empty($columns)) { $columns_joined = implode("`,`", $columns); } else { //if no columns array specified, get all columns of ap_forms table $query = "show columns from " . MF_TABLE_PREFIX . "forms"; $params = array(); $sth = mf_do_query($query, $params, $dbh); while ($row = mf_do_fetch_result($sth)) { if ($row['Field'] == 'form_id' || $row['Field'] == 'form_name') { continue; //MySQL 4.1 doesn't support WHERE on show columns, hence we need this } $columns[] = $row['Field']; } $columns_joined = implode("`,`", $columns); } $query = "select `{$columns_joined}` from " . MF_TABLE_PREFIX . "forms where form_id = ?"; $params = array($form_id); $sth = mf_do_query($query, $params, $dbh); $row = mf_do_fetch_result($sth); $form_properties = array(); foreach ($columns as $column_name) { $form_properties[$column_name] = $row[$column_name]; } return $form_properties; }
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; }