// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // | GNU General Public License for more details. | // | | // | You should have received a copy of the GNU General Public License | // | along with this program; if not, write to the Free Software Foundation, | // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | // | | // +---------------------------------------------------------------------------+ // require_once "../lib-common.php"; // Path to your lib-common.php $id = COM_applyFilter($_GET['id'], true); // Form ID of current displayed form $rid = COM_applyFilter($_GET['rid'], true); // Row ID in Dynamic Field - user can have multiple $form = COM_applyFilter($_GET['form']); // New form definition to add $instance = $rid + 1; if ($CONF_FE['debug']) { COM_errorLog("ajaxAddForm: id:{$id},rid:{$rid},form:{$form}"); COM_errorLog("instance = {$instance}"); } $content = htmlentities(nexform_dynamicFormHTML($form, $id, $form, 'edit', true, $instance)); header("Cache-Control: no-store, no-cache, must-revalidate"); header("content-type: text/xml"); $XML = "<result>"; $XML .= "<id>{$id}</id>"; $XML .= "<rid>{$rid}</rid>"; $XML .= "<html>{$content}</html>"; $XML .= "</result>"; print $XML;
/** * nexform_showFormFields: Main function that generates the HTML for the fields * Called from function nexform_showform() * * @param string $formid Required: form id to generate html for * @param object $template Required: Passed by reference the template object being used * @parm string $resultid Optional: Result Record ID if we need to show the posted results * @param string $mode Optional: Valid values are 'view,edit','print' * @param string $linked_formnum Optional: Used when multiple forms are linked * Example: form 1 of 3, this function will be called 3 times, this parm will be 1 . 2 and then 3 * Used to not show multiple submit buttons but allow a subform to be called on it's own if need. * $param boolean $dynamic Optional: Set to integer value to indicate dynamic form instance. * @return mixed returns formatted HTML for all fields * **/ function nexform_showFormFields($formid, $form_action, &$template, $resultid = 0, $mode = 'view', $linked_formnum = 1, $dynamic = '') { global $_CONF, $_TABLES, $_STATES, $CONF_FE, $LANG_FEMSG; $lines = 5; $i = 1; // Used to count the number of fields $fields = 'id,formid,tfid,field_name,type,fieldorder,label,style,col_width,col_padding,label_padding,'; $fields .= 'is_vertical,is_newline,is_mandatory,is_searchfield,is_resultsfield,is_reverseorder,field_help,'; $fields .= 'field_attributes,field_values,value_by_function,validation,javascript,is_internaluse,hidelabel'; $fieldquery = DB_query("SELECT {$fields} FROM {$_TABLES['nxform_fields']} WHERE formid='{$formid}' ORDER BY fieldorder"); $prevnewline = false; $is_lastfield = false; $is_firstfield = true; $cssid = 1; $groupEditAccess = DB_getItem($_TABLES['nxform_definitions'], 'perms_edit', "id='{$formid}'"); if ($mode != 'print' and DB_getItem($_TABLES['nxform_definitions'], 'show_mandatory_note', "id='{$formid}'") == 1) { $show_mandatory = true; } else { $show_mandatory = false; } /* Un-encode the fieldset definitions and display them as records if any exist */ $ofieldset = DB_getItem($_TABLES['nxform_definitions'], 'fieldsets', "id='{$formid}'"); if (trim($ofieldset != '')) { $afieldsets = unserialize($ofieldset); // Array of fieldset definitions } $fieldset_mode = false; while (list($fieldID, $formID, $tfid, $field_name, $type, $fieldorder, $label, $style, $col_width, $col_padding, $label_padding, $is_vertical, $newline, $mandatory, $searchfield, $reportfield, $is_reverseorder, $field_help, $field_attributes, $field_value, $use_function, $validation, $javascript, $is_internaluse, $hidelabel) = DB_fetchArray($fieldquery)) { if ($is_internaluse == 0 or $is_internaluse == 1 and SEC_inGroup($groupEditAccess)) { $javascript = nexform_replaceFieldTags($formid, $dynamic, $javascript); $label = stripslashes($label); $field_attributes = stripslashes($field_attributes); $nextfieldquery = DB_query("SELECT is_newline,type FROM {$_TABLES['nxform_fields']} WHERE formid='{$formid}' AND fieldorder > {$fieldorder} AND type NOT IN ('cancel','submit','hidden') ORDER BY fieldorder LIMIT 1"); if (DB_numRows($nextfieldquery) == 0) { $is_lastfield = true; } list($nextfield_linetype, $nextfield_type) = DB_fetchArray($nextfieldquery); //echo "<br>Field: $label, Order:$fieldorder => Current linetype:$newline and Next linetype:$nextfield_linetype"; //echo "<br>Fieldvalue: $field_value, ResultID:$resultid"; if ($newline and $nextfield_linetype or $parsedLastRecordline and $is_lastfield) { $recStyle = 'recstyle1'; } else { $recStyle = 'recstyle2'; } $template->set_var("cssid", $cssid); if ($is_firstfield) { $parsedLastRecordline = true; } if (is_numeric($col_width)) { $template->set_var('field_width', "width:{$col_width}%;"); } elseif (isset($CONF_FE['field_defaultspacing']) and $CONF_FE['fiel1_defaultspacing'] > 0) { $template->set_var('field_width', "width:{{$CONF_FE['field_defaultspacing']}}%;"); } elseif ($type == 'textarea2') { $template->set_var('field_width', 'width:99%;'); } else { $template->set_var('field_width', ''); } if (is_numeric($col_padding)) { $template->set_var('cell_padding', $col_padding); } else { $template->set_var('cell_padding', $CONF_FE['field_defaultrightpadding']); } if (is_numeric($label_padding)) { $template->set_var('label_padding', $label_padding); } else { $template->set_var('label_padding', $CONF_FE['field_defaultlabelpadding']); } if (trim($field_help) != '') { $template->set_var('help_message', $field_help); $template->parse('field_help', 'fieldhelp'); } else { $template->set_var('field_help', ''); } if ($is_lastfield or $is_firstfield and $nextfield_linetype) { $parseRecord = 1; $cssid = $cssid == 2 ? 1 : 2; } elseif (!$newline and !$nextfield_linetype or $newline and !$nextfield_linetype) { $parseRecord = 0; } else { $parseRecord = 1; $cssid = $cssid == 2 ? 1 : 2; } // Check if this field is not part of a fieldset definition if (!$fieldset_mode) { //echo "<br>Field $tfid. Set fset template vars to blanks"; $template->set_var('fset_begin', ''); $template->set_var('fset_end', ''); } if (is_array($afieldsets)) { $lines += 1; foreach ($afieldsets as $fset_id => $fieldset) { $fset = explode('::', $afieldsets[$i]); if ($mode != 'print') { if ($tfid == $fieldset['begin']) { $template->set_var('fset_label', $fieldset['label']); $template->parse('fset_begin', 'fieldsetbegin'); $fieldset_mode = true; } if ($tfid == $fieldset['end']) { $template->parse('fset_end', 'fieldsetend'); } } else { if ($tfid == $fieldset['begin']) { $template->set_var('fset_label', $fieldset['label']); $template->parse('fset_begin', 'printfieldsetbegin'); $fieldset_mode = true; } if ($tfid == $fieldset['end']) { $template->parse('fset_end', 'printfieldsetend'); } } } } if ($is_vertical == 1) { if ($recStyle == 'recstyle1') { if ($is_reverseorder) { $fieldStyle = 'fieldstyle2R'; } else { $fieldStyle = 'fieldstyle2'; } } else { if ($is_reverseorder) { $fieldStyle = 'fieldstyle3R'; } else { $fieldStyle = 'fieldstyle3'; } } } else { if ($is_reverseorder) { $fieldStyle = 'fieldstyle1R'; } else { $fieldStyle = 'fieldstyle1'; } } if ($type == 'mfile') { //$fieldStyle = 'fieldstyle4'; if ($resultid == 0 or $mode == 'edit') { $template->set_var('showfilectl', ''); } else { $template->set_var('showfilectl', 'none'); } } elseif ($type == 'mtxt') { if ($is_vertical == 1) { $fieldStyle = 'fieldstyle5R'; } else { $fieldStyle = 'fieldstyle5'; } if ($resultid == 0 or $mode == 'edit') { $template->set_var('showfieldctl', ''); } else { $template->set_var('showfieldctl', 'none'); } } //echo "<br>FormID: $formid, Field: $fieldID, Name:$field_name, Label: $label, Type:$type"; //echo "<br>value:$field_value, Next Fieldtype:$nextfield_type, parseRecord is: $parseRecord"; //echo "<br> Template ID:$tfid, Type:$type, fieldStyle:$fieldStyle, recStyle:$recStyle, "; //echo " parseRecord is: $parseRecord, parsedLastRecord:$parsedLastRecordline, ReverseLabel:$is_reverseorder "; //echo "<br> FieldID:$fieldID, FieldAttributes: $field_attributes,fieldset_mode:$fieldset_mode"; //echo "Labelclass:" . $CONF_FE['fieldstyles'][$style][1]; if ($type != 'hidden' and $type != 'heading') { $template->set_var('hidelabel', ''); if ($mandatory) { if (!$hidelabel) { if ($show_mandatory) { $template->set_var('label', "{$label}<span style=\"color:red;padding-left:5px;\">*</span>"); } else { $template->set_var('label', "{$label}"); } } else { $template->set_var("label", ''); $template->set_var('hidelabel', 'none'); } if ($type == 'radio' or $type == 'checkbox' or $type == 'multicheck') { $validatetag = "required=\"1\" Realname=\"{$label}\""; } elseif ($type == 'select') { $validatetag = "required=\"1\" exclude=\"-1\" {$validation} minlength=\"1\" Realname=\"{$label}\""; } elseif ($type == 'mfile') { $validatetag = "required=\"1\" callback=\"validate_mfile_field\""; } else { $validatetag = "required=\"1\" {$validation} minlength=\"1\" Realname=\"{$label}\""; } } else { $validatetag = ''; if (!$hidelabel) { $template->set_var('label', "{$label}"); } else { $template->set_var("label", ''); $template->set_var('hidelabel', 'none'); } } $fieldLableStyle = $CONF_FE['fieldstyles'][$style]; next($fieldLableStyle); $template->set_var('labelclass', key($fieldLableStyle)); $field_attributes = str_replace(',', ' ', $field_attributes); } else { $template->set_var('labelclass', ''); $template->set_var('label', ''); } if ($mode == 'print' and $CONF_FE['fieldstyles'][$style][1] == 'frm_label1') { $template->set_var('cell_padding', '20'); } if (DB_getItem($_TABLES['nxform_definitions'], 'post_method', "id='{$formid}'") == 'posturl') { $customfieldmode = true; } else { $customfieldmode = false; } $field_html = ''; if ($type != 'hidden' and $resultid > 0) { // Viewing detail of a previous posted form data - retrieve the field value switch ($type) { case 'textarea1': case 'textarea2': $field_value = DB_getItem($_TABLES['nxform_restext'], 'field_data', "result_id='{$resultid}' AND field_id='{$fieldID}'"); $field_value = stripslashes($field_value); break; case 'file': // generate link to uploaded file $field_value = DB_getItem($_TABLES['nxform_resdata'], 'field_data', "result_id='{$resultid}' AND field_id='{$fieldID}'"); $filename = explode(':', $field_value); //echo "<br>fieldid:$fieldID, result id:$resultid, field_value:$field_value"; if (!empty($field_value)) { $field_html = "<a href=\"{$CONF_FE['public_url']}/download.php?id={$fieldID}&rid={$resultid}\" target=\"_new\">{$filename[1]}</a>"; } else { $field_html = 'N/A'; } break; case 'mfile': // generate link to uploaded file $mquery = DB_query("SELECT id,field_data FROM {$_TABLES['nxform_resdata']} WHERE result_id='{$resultid}' AND field_id='{$fieldID}'"); if ($CONF_FE['debug']) { COM_errorLOG("Displaying form result:{$resultid} - field:{$fieldID}"); } $usetable = false; if (DB_numRows($mquery) > 0) { if ($CONF_FE['debug']) { COM_errorLog("Displaying form result:{$resultid} - found files"); } $field_html = '<table border="0"><tr style="vertical-align:top;">'; $usetable = true; $i = 0; } if (is_array($dynamic)) { $inputfilename = "mfile_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $inputfilename = "{$field_name}"; } else { $inputfilename = "mfile_frm{$formID}_{$fieldID}"; } while (list($rec, $field_value) = DB_fetchArray($mquery)) { $field_html .= '<td align="left">'; $filename = explode(':', $field_value); if (!empty($field_value)) { $field_html .= '<table border="0"><tr><td align="left"> '; $field_html .= "<a href=\"{$CONF_FE['public_url']}/download.php?id={$rec}\" target=\"_new\">"; $field_html .= "<img src=\"{$CONF_FE['image_url']}/document_sm.gif\" border=\"0\">{$filename[1]}</a> "; if ($mode == 'edit') { $field_html .= "<a href=\"#\" onClick='ajaxDeleteFile({$fieldID},{$rec},\"{$inputfilename}\"); return false;'>"; $field_html .= "<img src=\"{$CONF_FE['image_url']}/delete.gif\" border=\"0\"></a> "; } $field_html .= "</td></tr></table>"; } else { $field_html = 'N/A '; } $field_html .= '</td>'; $i++; $field_html .= '</tr><tr style="vertical-align:top;">'; } $mfile_count = $i; if ($usetable) { $field_html .= '</tr></table>'; } break; case 'submit': case 'cancel': break; default: // Check if custom field - if so then data is in text field table if (array_key_exists($type, $CONF_FE['customfieldmap'])) { $field_value = DB_getItem($_TABLES['nxform_restext'], 'field_data', "result_id='{$resultid}' AND field_id='{$fieldID}'"); } else { $field_value = DB_getItem($_TABLES['nxform_resdata'], 'field_data', "result_id='{$resultid}' AND field_id='{$fieldID}'"); } break; } // switch } /* Code to handle assigning a value to field by Function */ $function_datavalues = ''; $setresult = false; if ($use_function) { if ($resultid > 0) { $fvalue = DB_getItem($_TABLES['nxform_fields'], "field_values", "id='{$fieldID}'"); // Check if autotag is being used for value if (strpos($fvalue, '[' === FALSE)) { $function = explode(':', $fvalue); if (function_exists($function[0])) { $function_datavalues = $function[0]($function[1], $fieldID); } } else { // - Assume autotag is being used = if [ is in value like the autotag format $function_datavalues = nexform_getAutotagValues($fvalue, $type, $field_value, $fieldID); } } else { // Check if autotag is being used for value - assume so if [ is in value like the autotag format if (strpos($field_value, '[') === FALSE) { /* Not an autotag so assume a function has been defined with parms in () * Example: userprofile(name) // Show the user's name * userprofile(location) // Show the user's location * capitalreq(deptcodes) // Show a list of department billing codes * Any number of parms can be in the definition - up to your function to sort out */ $function = explode('(', $field_value); $function[1] = str_replace(')', '', $function[1]); // Strip out trailing ) in the parms value if (function_exists($function[0])) { $function_datavalues = $function[0]($function[1], $fieldID); } } else { // - Assume autotag is being used = if [ is in value like the autotag format $function_datavalues = nexform_getAutotagValues($field_value, $type, '', $fieldID); } } if (!is_array($function_datavalues)) { $function_datavalues = stripslashes($function_datavalues); } } $is_firstfield = false; if ($mode == 'print') { if (!is_array($dynamic)) { $resultid = COM_applyFilter($_GET['result'], true); } //if not saved in database yet - show current values if ($resultid == 0) { switch ($type) { case 'date1': if ($_POST[$field_name] == '') { $field_name = str_replace('da1_ftm', 'da1_frm', $field_name); } $field_value = $_POST[$field_name]; break; case 'mtxt': $field_value = implode('|', $_POST[$field_name]); break; case 'multicheck': if (get_magic_quotes_gpc()) { if (is_array($_POST[$field_name])) { foreach ($_POST[$field_name] as $key => $value) { $_POST[$field_name][$key] = stripslashes($_POST[$field_name][$key]); } } } break; case 'file': case 'mfile': $tmpid = COM_applyFilter($_GET['rid'], true); $resultid = $tmpid != 0 ? $tmpid : $resultid; break; default: if (strpos($field_name, 'cust') !== false) { foreach ($_POST as $var => $value) { $parts = explode('_', $var); $fieldtype = $parts[0]; $field_id = (int) $parts[2]; if (is_array($value) and $fieldtype == 'cust') { $subfield = $parts[3]; foreach ($value as $subfield_value) { $subfield_value = stripslashes($subfield_value); $custom_fields[$field_id][$subfield][] = $subfield_value; } } } if (count($custom_fields) > 0) { foreach ($custom_fields as $field_id => $value) { $_POST[$field_name] = serialize($value); } } } else { $field_value = $_POST[$field_name]; } break; } $field_value = stripslashes($field_value); } } switch ($type) { case 'hidden': if (is_array($dynamic)) { $fieldname = "hid_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "hid_frm{$formID}_{$fieldID}"; } $field_html = "<input type=\"hidden\" id=\"{$fieldname}\" name=\"{$fieldname}\" value=\"{$field_value}\" >"; $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'date1': if ($mode != 'print') { if (is_array($dynamic)) { $fieldname = "da1_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "da1_frm{$formID}_{$fieldID}"; } $field_html = "<input type=\"text\" id=\"{$fieldname}\" name=\"{$fieldname}\" "; if ($resultid == 0 and $function_datavalues != '') { $field_html .= "value=\"{$function_datavalues}\" "; } else { $field_html .= "value=\"{$field_value}\" "; } if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['date1'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['date1'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' READONLY'; } $field_html .= '>'; } else { $field_html .= $field_value; } $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'date2': // Date Field with Popup DHTML Calendar if ($mode != 'print') { if (is_array($dynamic)) { $fieldname = "da2_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "da2_frm{$formID}_{$fieldID}"; } $field_html = "<input type=\"text\" id=\"{$fieldname}\" name=\"{$fieldname}\" "; if ($resultid == 0 and $function_datavalues != '') { $field_html .= "value=\"{$function_datavalues}\" "; } else { $field_html .= "value=\"{$field_value}\" "; } if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['date2'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['date2'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' READONLY'; $field_html .= '>'; } else { $field_html .= "onMouseOver=\"setupCalendar('{$fieldname}', '%m/%d/%Y', false);\" >"; } } else { $field_html .= $field_value; } $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'datetime': // Date Field with Popup DHTML Calendar if ($mode != 'print') { if (is_array($dynamic)) { $fieldname = "time_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "time_frm{$formID}_{$fieldID}"; } $field_html = "<input type=\"text\" id=\"{$fieldname}\" name=\"{$fieldname}\" "; if ($resultid == 0 and $function_datavalues != '') { $field_html .= "value=\"{$function_datavalues}\" "; } else { $field_html .= "value=\"{$field_value}\" "; } if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['datetime'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['datetime'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' READONLY'; $field_html .= '>'; } else { $field_html .= "onMouseOver=\"setupCalendar('{$fieldname}', '%m/%d/%Y %H:%M', true);\" >"; } } else { $field_html .= $field_value; } $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'text': if ($mode != 'print') { if (is_array($dynamic)) { $fieldname = "txt_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "txt_frm{$formID}_{$fieldID}"; } $field_html = "<input type=\"text\" id=\"{$fieldname}\" name=\"{$fieldname}\" "; if ($function_datavalues != '') { $function_datavalues = trim($function_datavalues); $field_html .= "value=\"{$function_datavalues}\" "; } else { $field_html .= "value=\"{$field_value}\" "; } if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['text'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['text'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' READONLY'; } $field_html .= '>'; } else { if ($function_datavalues != '' and $mode != 'print' and $resultid != 0) { $field_value = $function_datavalues; } $field_html = $field_value; } $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'mtxt': $template->set_var('field_id', $fieldID); // Extra variables for mtext field template $template->set_var('sform_id', $formID); $template->set_var('sfield_id', '0'); if (is_array($dynamic)) { $fieldname = "mtxt_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}[]"; $mtxt_id = "mtxt_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; $template->set_var('field_id', $fieldID); // Extra variables for mtext field template $template->set_var('sform_id', $dynamic[0]); $template->set_var('sfield_id', $dynamic[1]); $template->set_var('mtxt_instance', $dynamic[2]); } elseif ($customfieldmode and $field_name != '') { $fieldname = "{$field_name}[]"; $mtxt_id = "{$field_name}"; } else { $fieldname = "mtxt_frm{$formID}_{$fieldID}[]"; $mtxt_id = "mtxt_frm{$formID}_{$fieldID}"; } // Need to create as many text fields as there are data elements in the varible text field value $mtxt_values = explode('|', $field_value); $field_html = ''; $i = 0; $closetable = false; foreach ($mtxt_values as $val) { if ($i > 0) { $field_html .= '<td width="120">'; } $field_html .= "<input type=\"text\" id=\"{$mtxt_id}_{$i}\" name=\"{$fieldname}\" size=\"20\" "; $field_html .= "value=\"{$val}\" "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['mtxt'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['mtxt'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' READONLY'; } $field_html .= '>'; if ($i > 0) { $field_html .= '</td>'; } if ($i % 4 == 3) { $field_html .= '</tr><tr>'; $closetable = true; } $i++; } if ($closetable) { $field_html .= '</tr>'; } $template->set_var('mtxt_fieldname', $mtxt_id); $template->set_var('mtxt_counter', $i); $template->set_var('mtxt_counter_id', str_replace('_', '-', $mtxt_id)); $template->set_var('field_id', $fieldID); // Extra variables for mtext field template $template->set_var('form_id', $formID); $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'select': if ($mode != 'print') { if (is_array($dynamic)) { $fieldname = "sel_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "sel_frm{$formID}_{$fieldID}"; } $field_html = "<select id=\"{$fieldname}\" name=\"{$fieldname}\" "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['select'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['select'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' DISABLED'; } $field_html .= '>'; $field_html .= '<option value="-1">' . $LANG_FEMSG[1] . '</option>'; // Check if this field is using a function to generate the select options // It could be a simple list or an array of options example [alist:xx] if ($function_datavalues != '' and is_array($function_datavalues)) { // Check and see if passed in array contains a key to indicate the selected item if (array_key_exists('selected', $function_datavalues)) { $field_value = $function_datavalues['selected']; // Now remove this item from the array of results to use an select options unset($function_datavalues['selected']); $setresult = true; } else { $setresult = false; } // Jan 9/2006 (BL) Updated to now add the class=xxx for the dynamic select feature $dynamicSelect = false; // Cycle thru the array of values to set the dropdown options foreach ($function_datavalues as $optval => $optitem) { $optitem = explode(',', $optitem); $field_html .= '<option value="' . $optval . '"'; if (isset($optitem[1])) { $field_html .= ' ' . $optitem[1]; $dynamicSelect = true; } if (($resultid > 0 or $setresult) and $field_value == $optval) { $field_html .= ' SELECTED '; } $field_html .= '>' . $optitem[0] . '</option>'; } if ($dynamicSelect) { $CONF_FE['dynamicSelect'] = true; $template->parse('dynamic_select_function_calls', 'dselect_field', true); } } else { // List of options separated by commas if ($function_datavalues != '') { $options = explode(',', $function_datavalues); } else { $default_value = DB_getItem($_TABLES['nxform_fields'], 'field_values', "id='{$fieldID}'"); $options = explode(',', $default_value); } foreach ($options as $option) { if ($resultid > 0 and $field_value == $option) { $field_html .= '<option value="' . $option . '" SELECTED>' . $option . '</option>'; } else { $field_html .= '<option value="' . $option . '">' . $option . '</option>'; } } } $field_html .= '</select>'; } elseif (trim($field_value) != '') { if ($function_datavalues != '' and is_array($function_datavalues)) { // Filter out class attribute in value if this is a dynamic select field if (strpos($function_datavalues[$field_value], 'class=') > 0) { $fieldDisplayValue = explode(',', $function_datavalues[$field_value]); $field_html .= $fieldDisplayValue[0]; } else { $field_html .= $function_datavalues[$field_value]; } } else { $field_html .= $field_value; } } $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'passwd': if (is_array($dynamic)) { $fieldname = "pwd_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "pwd_frm{$formID}_{$fieldID}"; } $field_html = "<input type=\"password\" id=\"{$fieldname}\" name=\"{$fieldname}\" value=\"{$field_value}\" "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['passwd'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['passwd'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' READONLY'; } $field_html .= '>'; $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'file': if ($resultid == 0) { // Don't show hidden fields when viewing results if (is_array($dynamic)) { $fieldname = "file_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "file_frm{$formID}_{$fieldID}"; } $field_html = "<input type=\"file\" id=\"{$fieldname}\" name=\"{$fieldname}\" value=\"{$field_value}\" "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['file'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['file'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript) . '>'; } $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'mfile': if (is_array($dynamic)) { $fieldname = "mfile_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}[]"; $file_id = "mfile_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = "{$field_name}[]"; $file_id = "{$field_name}"; } else { $fieldname = "mfile_frm{$formID}_{$fieldID}[]"; $file_id = "mfile_frm{$formID}_{$fieldID}"; } if ($resultid == 0) { if ($function_datavalues != '') { $field_html = $function_datavalues; } } $file_input1 = "<input type=\"file\" name=\""; $file_input2 = $fieldname; $file_input3 = "\" id=\"{$file_id}\" value=\"{$field_value}\" "; if (!empty($field_attributes)) { $file_input3 .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['mfile'])) { $file_input3 .= html_entity_decode(key($CONF_FE['defaultattributes']['mfile'])); } $file_input3 .= " {$validatetag} "; $file_input3 .= html_entity_decode($javascript) . '>'; $mfile_count = $mfile_count == '' ? 0 : $mfile_count; $template->set_var('upload_field_name', str_replace('[]', '', $fieldname)); $template->set_var('file_input1', $file_input1); $template->set_var('file_input2', $file_input2); $template->set_var('file_input3', $file_input3); $template->set_var('field_id', $fieldID); $template->set_var('mfile_count', $mfile_count); $template->set_var('mfile_count_name', str_replace('_', '-', $file_id)); $template->set_var('form_id', $formID); $template->set_var('mfield_html', "{$field_html}"); if ($mode == 'print' or $mode == 'review') { $template->set_var('show_addremove', 'none'); } else { $template->set_var('show_addremove', ''); } $template->parse('field', 'mfile_field'); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'checkbox': if (is_array($dynamic)) { $fieldname = "chk_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "chk_frm{$formID}_{$fieldID}"; } //support pullform values if ($function_datavalues != '') { $field_value = $function_datavalues; } $default_value = DB_getItem($_TABLES['nxform_fields'], 'field_values', "id='{$fieldID}'"); if ($default_value == '') { $default_value = 1; } $field_html = "<input type=\"checkbox\" id=\"{$fieldname}\" name=\"{$fieldname}\" value=\"1\""; if ($field_value == '1' or $field_value == 'yes') { $field_html .= ' CHECKED=CHECKED '; } $field_html .= " {$validatetag} "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['checkbox'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['checkbox'])); } $field_html .= ' ' . html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' DISABLED'; } $field_html .= '>'; $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'multicheck': if (is_array($dynamic)) { $fieldname = "mchk_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}[]"; $mcheck_id = "mchk_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}_%s"; } elseif ($customfieldmode and $field_name != '') { if (strpos('[]', $field_name) == 0) { $fieldname = "{$field_name}[]"; $mcheck_id = "{$field_name}_%s"; } else { $fieldname = $field_name; $tmp_fieldname = str_replace('[]', '', $field_name); $mcheck_id = "{$tmp_fieldname}_%s"; } } else { $fieldname = "mchk_frm{$formID}_{$fieldID}[]"; $mcheck_id = "mchk_frm{$formID}_{$fieldID}_%s"; } $setresult = false; if ($function_datavalues != '') { if (is_array($function_datavalues)) { // Tested with AIM [pullform] autotag functions // Array of Options and selected Checkboxes $setresult = true; } else { $default_values = explode(',', $function_datavalues); } } else { $default_values = explode(',', DB_getItem($_TABLES['nxform_fields'], 'field_values', "id='{$fieldID}'")); } if ($resultid > 0) { $result_values = explode(',', $field_value); } $field_html = ''; if ($setresult) { $i = 0; foreach ($function_datavalues as $chkoption => $seloption) { $tmp_fieldname = sprintf($mcheck_id, $i); $field_html .= "{$chkoption} <input type=\"checkbox\" id=\"{$tmp_fieldname}\" name=\"{$fieldname}\" value=\"{$chkoption}\" "; if ($seloption == 1 or is_array($result_values) and in_array($chkoption, $result_values)) { $field_html .= 'CHECKED=CHECKED '; } $field_html .= " {$validatetag} "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['multicheck'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['multicheck'])); } $field_html .= ' ' . html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' DISABLED'; } $field_html .= '> '; $i++; } } else { for ($a = 0; $a < count($default_values); $a++) { $tmp_fieldname = sprintf($mcheck_id, $a); $field_html .= "{$default_values[$a]} <input type=\"checkbox\" id=\"{$tmp_fieldname}\" name=\"{$fieldname}\" value=\"{$default_values[$a]}\" "; if ($mode == 'print' and $resultid == 0) { if ($seloption == 1 or is_array($_POST[$field_name]) and in_array($default_values[$a], $_POST[$field_name])) { $field_html .= 'CHECKED=CHECKED '; } } else { if ($resultid > 0 and in_array($default_values[$a], $result_values)) { $field_html .= 'CHECKED=CHECKED '; } } $field_html .= " {$validatetag} "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['multicheck'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['multicheck'])); } $field_html .= ' ' . html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' DISABLED'; } $field_html .= '> '; } } $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'radio': if (is_array($dynamic)) { $fieldname = "rad_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "rad_frm{$formID}_{$fieldID}"; } if ($function_datavalues != '') { if (is_array($function_datavalues)) { // Tested with AIM [pullform] autotag functions // Array of Options and selected Checkboxes $setresult = true; } else { $default_values = explode(',', $function_datavalues); } } else { $default_values = explode(',', DB_getItem($_TABLES['nxform_fields'], 'field_values', "id='{$fieldID}'")); } $field_html = ''; if ($setresult) { $i = 0; foreach ($function_datavalues as $chkoption => $seloption) { $field_html .= "{$chkoption} <input type=\"radio\" id=\"{$fieldname}_{$i}\" name=\"{$fieldname}\" value=\"{$chkoption}\" "; if ($seloption == 1 or is_array($result_values) and in_array($chkoption, $result_values)) { $field_html .= 'CHECKED=CHECKED '; } $field_html .= " {$validatetag} "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['radio'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['radio'])); } $field_html .= ' ' . html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' DISABLED'; } $field_html .= '> '; $i++; } } else { for ($a = 0; $a < count($default_values); $a++) { $dynValue = trim($default_values[$a]); $dynValue = str_replace(array('<br>', ' '), array('', ''), $dynValue); $field_html .= "<input type=\"radio\" id=\"{$fieldname}_{$a}\" name=\"{$fieldname}\" value=\"{$dynValue}\" "; if ($resultid > 0 and $dynValue == trim($field_value)) { $field_html .= ' CHECKED=CHECKED '; } $field_html .= " {$validatetag} "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['radio'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['radio'])); } $field_html .= ' ' . html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' DISABLED'; } $field_html .= '> '; $field_html .= $default_values[$a]; } } $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'textarea1': if ($mode != 'print') { if (is_array($dynamic)) { $fieldname = "ta1_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "ta1_frm{$formID}_{$fieldID}"; } $field_html = "<textarea id=\"{$fieldname}\" name=\"{$fieldname}\" "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['textarea1'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['textarea1'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript); if ($mode == 'review') { $field_html .= ' READONLY'; } $field_html .= '>'; if ($function_datavalues != '') { $field_html .= $function_datavalues . '</textarea>'; } else { $field_html .= $field_value . '</textarea>'; } } else { $field_html = '<table style="border: solid #A5ACB2 1px;" bgcolor="#FFFFFF"><tr><td bgcolor="#FFFFFF" width=600 height=60 valign="top">'; $field_html .= $field_value; $field_html .= '</td></tr></table>'; } $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'textarea2': if ($mode != 'print' and $mode != 'review') { if (is_array($dynamic)) { $fieldname = "ta2_frm{$dynamic['0']}_{$dynamic['1']}_{$fieldID}_{$dynamic['2']}"; } elseif ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "ta2_frm{$formID}_{$fieldID}"; } $field_html = "<textarea id=\"{$fieldname}\" name=\"{$fieldname}\" "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['textarea2'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['textarea2'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript) . '>'; if ($function_datavalues != '') { $field_html .= $function_datavalues . '</textarea>'; } else { $field_html .= $field_value . '</textarea>'; } } elseif (trim($field_value) != '') { $field_html = '<table style="border: solid #A5ACB2 1px;" bgcolor="#FFFFFF"><tr><td bgcolor="#FFFFFF" width=600 valign="top">'; $field_html .= $field_value; $field_html .= '</td></tr></table>'; } $template->set_var('field', "{$field_html}"); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'captcha': if ($resultid == 0 and DB_getItem($_TABLES['plugins'], 'pi_enabled', "pi_name='captcha'") == 1) { // Don't show field when viewing results $fieldname = "captcha"; // Assume only 1 CAPTCHA Field per form $field_html = "<input type=\"text\" name=\"{$fieldname}\" "; if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } else { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['captcha'])); } $field_html .= " {$validatetag} "; $field_html .= html_entity_decode($javascript) . '>'; global $_CP_CONF; $sessid = CAPTCHA_sid(); $time = time(); DB_save($_TABLES['cp_sessions'], "session_id,cptime,validation,counter", "'{$sessid}','{$time}','','0'"); $field_html .= '<input type="hidden" name="csid" value="' . $sessid . '">'; $captchaImage = '<img src="' . $_CONF['site_url'] . '/captcha/captcha.php?csid=' . $sessid . '&.' . $_CP_CONF['gfxFormat'] . '">'; $template->set_var('captcha_image', $captchaImage); $template->set_var('verification_field', $field_html); $template->parse('field', 'captchafield'); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } } break; case 'submit': if ($mode != 'review' and $mode != 'print' and $linked_formnum == 1) { if ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "sub_frm{$formID}_{$fieldID}"; } $field_html = "<input type=\"submit\" id=\"{$fieldname}\" name=\"{$fieldname}\" "; // Disable the enterkey $field_html .= "onFocus=\"this.form.action=document.getElementById('submit_url').value; this.form.target='';\""; if (empty($field_value) and !empty($label)) { $field_html .= " value=\"{$label}\" "; } else { $field_html .= " value=\"{$field_value}\" "; } if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['submit'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['submit'])); } $field_html .= ' ' . html_entity_decode($javascript) . '>'; $template->set_var('submit_btn', "{$field_html}"); $template->parse('submit', 'submit_button', true); } break; case 'cancel': if ($mode != 'review' and $mode != 'print') { if ($customfieldmode and $field_name != '') { $fieldname = $field_name; } else { $fieldname = "btn_frm{$formID}_{$fieldID}"; } if ($javascript == '') { $javascript = 'onclick=\'javascript:history.go(-1)\''; } $field_html = "<input type=\"button\" id=\"{$fieldname}\" name=\"{$fieldname}\" "; if (empty($field_value) and !empty($label)) { $field_html .= " value=\"{$label}\" "; } else { $field_html .= " value=\"{$field_value}\" "; } if (!empty($field_attributes)) { $field_html .= html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['cancel'])) { $field_html .= html_entity_decode(key($CONF_FE['defaultattributes']['cancel'])); } $field_html .= html_entity_decode($javascript) . '>'; $template->set_var('cancel', $field_html); } break; case 'heading': $heading = "<div"; if ($style > 0) { $heading .= ' class="' . $CONF_FE['fieldstyles'][$style][1] . '"'; } if (!empty($field_attributes)) { $heading .= " " . html_entity_decode($field_attributes); } elseif (!empty($CONF_FE['defaultattributes']['heading'])) { $heading .= " " . html_entity_decode(key($CONF_FE['defaultattributes']['heading'])); } $heading .= ">"; $heading_label = ''; $heading_label .= $field_value != '' ? $field_value : $label; if ($heading_label == '') { $heading_label = $function_datavalues; } $heading .= $heading_label; $heading .= "</div>"; $template->set_var('label', "{$heading}"); $template->set_var('field', " "); if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; case 'dynamic': if ($resultid == 0) { $dynamicFormID = $field_value; $template->set_var('field', nexform_dynamicFormHTML($formID, $fieldID, $dynamicFormID, $mode)); $instance = 1; } else { $dynamicFormResults = explode('|', $field_value); // Determine which form is to be used - in form definition $dynamicFormID = DB_getItem($_TABLES['nxform_fields'], 'field_values', "id='{$fieldID}'"); $instance = 0; $resultCount = count($dynamicFormResults) - 1; // Want to show the [add/remove] field after the last form instance foreach ($dynamicFormResults as $dynamicResult) { if ($instance == 0) { $template->set_var('field', nexform_dynamicFormHTML($formID, $fieldID, $dynamicFormID, $mode, false, $instance, $dynamicResult)); } else { $template->set_var('field', nexform_dynamicFormHTML($formID, $fieldID, $dynamicFormID, $mode, true, $instance, $dynamicResult), true); } $instance++; } } $values = DB_getItem($_TABLES['nxform_fields'], 'field_values', "id={$fieldID}"); $v_arr = explode(',', $values); $v2 = $v_arr[1]; if (($mode == 'edit' || $mode == 'view') && $v2 != 1) { $tmp_template = new Template($_CONF['path_layout'] . 'nexform'); $tmp_template->set_file('dynamicform_end', 'dynamicform_end.thtml'); $tmp_template->set_var('form_id', $formID); $tmp_template->set_var('dynamic_field_id', $fieldID); $tmp_template->set_var('dynamicform_id', $dynamicFormID); $tmp_template->set_var('last_id', $instance - 1); $tmp_template->set_var('cell_padding', $template->get_var('cell_padding')); $tmp_template->parse('output', 'dynamicform_end'); $dynamicform_end = $tmp_template->finish($tmp_template->get_var('output')); $template->set_var('field', $dynamicform_end, true); } if (!$hidelabel) { $template->set_var('label', "{$label}"); } if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } break; default: // Check for any custom field definition types using custom templates if (array_key_exists($type, $CONF_FE['customfieldmap'])) { $template->set_file('custom_field', 'custom/' . $CONF_FE['customfieldmap'][$type]['form']); if ($mode == 'print') { $printTemplateFiles = explode(',', $CONF_FE['customfieldmap'][$type]['print']); if (count($printTemplateFiles) > 1) { $template->set_file('custom_field', 'custom/' . $printTemplateFiles[0]); $template->set_file('custom_field_rec', 'custom/' . $printTemplateFiles[1]); } else { $template->set_file('custom_field_rec', 'custom/' . $printTemplateFiles[0]); } } else { $template->set_file('custom_field_rec', 'custom/' . $CONF_FE['customfieldmap'][$type]['record']); } $template->set_var('field_id', $fieldID); $template->set_var('form_id', $formID); if ($resultid > 0 or $mode == 'print') { if ($mode == 'print' and $resultid == 0) { $field_value = $_POST[$field_name]; } $field_value = unserialize($field_value); if ($mode == 'edit') { $template->set_file('custom_js', 'custom/' . $CONF_FE['customfieldmap'][$type]['javascript']); $template->parse('javascript_functions', 'custom_js'); } else { $template->set_var('showcustomfieldctl', 'none'); } $i = 0; do { $k = 1; $template->set_var('row', $i); if (is_array($field_value)) { $printCustomRec = false; foreach ($field_value as $custom_value) { if ($mode == 'print') { $custom_value[$i] = nl2br($custom_value[$i]); } $template->set_var("cust_value{$k}", $custom_value[$i]); $k++; } } if ($printCustomRec and $i == 0) { $template->parse('custom_record', 'custom_field_rec'); } elseif ($printCustomRec) { $template->parse('custom_record', 'custom_field_rec', true); } $i++; } while (isset($custom_value[$i])); } elseif ($function_datavalues != '') { /* Form wants to use a function to format this field */ $template->set_file('custom_js', 'custom/' . $CONF_FE['customfieldmap'][$type]['javascript']); $template->parse('javascript_functions', 'custom_js'); $template->set_var('custom_record', $function_datavalues); } else { $template->set_file("custom_field{$fieldID}", 'custom/' . $CONF_FE['customfieldmap'][$type]['form']); $template->set_file("custom_field_rec{$fieldID}", 'custom/' . $CONF_FE['customfieldmap'][$type]['record']); $template->set_file("custom_js{$fieldID}", 'custom/' . $CONF_FE['customfieldmap'][$type]['javascript']); $template->parse('javascript_functions', "custom_js{$fieldID}", true); $template->parse('custom_record', "custom_field_rec{$fieldID}"); } $template->parse('field', "custom_field{$fieldID}"); if (!$hidelabel) { $template->set_var('label', "{$label}"); } if ($parsedLastRecordline) { $template->parse('fields', $fieldStyle); } else { $template->parse('fields', $fieldStyle, true); } if ($parseRecord) { $template->parse('form_records', $recStyle, true); $parsedLastRecordline = true; } else { $parsedLastRecordline = false; } } break; } // switch $template->set_var('validatetag', $validatetag); $i++; if ($parsedLastRecordline) { $fieldset_mode = false; } } // Check for internal_use fields } // while // Flush the last field form records if the template has not been parsed if (!$parsedLastRecordline) { $template->parse('form_records', $recStyle, true); } }