id = $form_id; $form->name = $row['form_name']; $form->description = $row['form_description']; $form->redirect = $row['form_redirect']; $form->success_message = $row['form_success_message']; $form->password = $row['form_password']; $form->frame_height = $row['form_frame_height']; $form->unique_ip = $row['form_unique_ip']; $form->has_css = $row['form_has_css']; $form->active = $row['form_active']; $form->captcha = $row['form_captcha']; $form->review = $row['form_review']; $async_sign = $row['async_sign']; $form_lang = $row["form_language"]; $async_sign = $row["async_sign"]; $code_snippet = $row["code_snippet"]; set_language(); if(empty($error_elements)){ $form->is_error = 0; }else{ $form->is_error = 1; } //if this form has review enabled and user are having $_SESSION['review_id'], then populate the form with that values if(!empty($form->review) && !empty($_SESSION['review_id']) && empty($populated_values)){ $populated_values = get_entry_values($form_id,$_SESSION['review_id'],true); } //get elements data //get element options first and store it into array $query = "select element_id, option_id, `position`, `option`, option_is_default from ap_element_options where form_id='$form_id' and live=1 order by element_id asc,`position` asc"; $result = do_query($query); while($row = do_fetch_result($result)){ $element_id = $row['element_id']; $option_id = $row['option_id']; $options_lookup[$element_id][$option_id]['position'] = $row['position']; $options_lookup[$element_id][$option_id]['option'] = $row['option']; $options_lookup[$element_id][$option_id]['option_is_default'] = $row['option_is_default']; } //get elements data $element = array(); $query = "select element_id, element_title, element_guidelines, element_size, element_is_required, element_is_unique, element_is_private, element_type, element_position, element_default_value, element_constraint from ap_form_elements where form_id='$form_id' order by element_position asc"; $result = do_query($query); $j=0; $has_calendar = false; //assume the form doesn't have calendar, so it won't load calendar.js while($row = do_fetch_result($result)){ $element_id = $row['element_id']; //lookup element options first if(!empty($options_lookup[$element_id])){ $element_options = array(); $i=0; foreach ($options_lookup[$element_id] as $option_id=>$data){ $element_options[$i] = new stdClass(); $element_options[$i]->id = $option_id; $element_options[$i]->option = $data['option']; $element_options[$i]->is_default = $data['option_is_default']; $element_options[$i]->is_db_live = 1; $i++; } } //populate elements $element[$j] = new stdClass(); $element[$j]->title = nl2br($row['element_title']); $element[$j]->guidelines = $row['element_guidelines']; $element[$j]->size = $row['element_size']; $element[$j]->is_required = $row['element_is_required']; $element[$j]->is_unique = $row['element_is_unique']; $element[$j]->is_private = $row['element_is_private']; $element[$j]->type = $row['element_type']; $element[$j]->position = $row['element_position']; $element[$j]->id = $row['element_id']; $element[$j]->is_db_live = 1; //this data came from db or form submit //being used to display edit form or redisplay form with errors and previous inputs //this should be optimized in the future, only pass necessary data, not the whole array $element[$j]->populated_value = $populated_values; //if there is file upload type, set form enctype to multipart if($row['element_type'] == 'file'){ $form_enc_type = 'enctype="multipart/form-data"'; } if(!empty($error_elements[$element[$j]->id])){ $element[$j]->is_error = 1; $element[$j]->error_message = $error_elements[$element[$j]->id]; } if($_REQUEST['type'] == "search"){ $element[$j]->default_value = ""; }else{ $element[$j]->default_value = htmlspecialchars($row['element_default_value']); } $element[$j]->constraint = $row['element_constraint']; if(!empty($element_options)){ $element[$j]->options = $element_options; }else{ $element[$j]->options = ''; } //check for calendar type if($row['element_type'] == 'date' || $row['element_type'] == 'europe_date'){ $has_calendar = true; } $j++; } //add captcha if enable if(!empty($form->captcha) && (empty($edit_id))){ $element[$j] = new stdClass(); $element[$j]->type = 'captcha'; $element[$j]->form_id = $form_id; $element[$j]->is_private = 0; if(!empty($error_elements['element_captcha'])){ $element[$j]->is_error = 1; $element[$j]->error_message = $error_elements['element_captcha']; } } //generate html markup for each element $all_element_markup = ''; foreach ($element as $element_data){ if($element_data->is_private && empty($_SESSION['logged_in'])){ //don't show private element continue; } if($element_data->type == "captcha"){ $captcha_markup_tmp = call_user_func('display_'.$element_data->type,$element_data); }else{ $all_element_markup .= call_user_func('display_'.$element_data->type,$element_data); } } if(!empty($custom_error)){ $form->error_message =<<

{$custom_error}

EOT; }elseif(!empty($error_elements)){ $form->error_message =<<

{$lang['error_title']}

{$lang['error_desc']}

EOT; } //display edit_id if there is any if(!empty($edit_id)){ $edit_markup = "\n"; }else{ $edit_markup = ''; } if(empty($form->review)){ $button_text = $lang['submit_button']; }else{ $button_text = $lang['continue_button']; } //markup for submit button if($search_mode){ $button_markup =<<
  • EOT; }else{ $button_markup =<< {$edit_markup} EOT; } //check for specific form css, if any, use it instead if($form->has_css){ $css_dir = DATA_DIR."/form_{$form_id}/css/"; } if(!empty($form->password) && empty($_SESSION['user_authenticated'])){ //if form require password and password hasn't set yet $show_password_form = true; }elseif (!empty($form->password) && !empty($_SESSION['user_authenticated']) && $_SESSION['user_authenticated'] != $form_id){ //if user authenticated but not for this form $show_password_form = true; }else{ //user authenticated for this form, or no password required $show_password_form = false; } if(empty($form->active)){ //if form is not active, don't show the fields $form_desc_div =''; $all_element_markup = ''; $button_markup = ''; $ul_class = 'class="password"'; $custom_element =<<

    {$lang['form_inactive']}

    EOT; }elseif($show_password_form){ //don't show form description if this page is password protected and user not authenticated $form_desc_div =''; $all_element_markup = ''; $custom_element =<<

    {$lang['form_pass_title']}

    EOT; $ul_class = 'class="password"'; }else{ if(!empty($form->name) || !empty($form->description)){ $form->description = nl2br($form->description); $form_desc_div =<<

    {$form->name}

    {$form->description}

    EOT; $query = "select form_name, form_description, header_text, footer_text, async_sign from ap_forms where form_id='$form_id'"; $result = do_query($query); $headers = do_fetch_result($result); $header_text = $headers['header_text']; $footer_text = $headers['footer_text']; $captcha_markup = $captcha_markup_tmp; if($search_mode){ $async_sign = ""; }else{ if($async_sign == 0){ $async_sign = ""; }else{ //$async_sign = ""; $async_sign = "
    id);\" value=\"".$lang['async_sign_notice']."\" />
    "; } } //$signature = '
  • '; } } if($embed){ $embed_class = 'class="embed"'; } if($has_calendar){ $calendar_js = ''; }else{ $calendar_js = ''; } if($search_mode){ $form_top_tag = '
    '; }else{ $form_top_tag = ''; } $form_markup = << {$form->name} {$calendar_js} {$code_snippet}

    {$form->name}

    {$form_top_tag} {$form_desc_div}
    • {$lang['asterisk_meaning']}
    • {$header_text}
    • {$form->error_message} {$all_element_markup}
    • {$footer_text}
    •  
    • {$custom_element} {$captcha_markup} {$button_markup} {$async_sign}
    EOT; return $form_markup; } ?>