芝麻web文件管理V1.00
编辑当前文件:/home/p/r/i/prismawe/clients/canaldegap.fr/modules/FormBuilder/classes/Form.class.php
More info at http://dev.cmsmadesimple.org/projects/formbuilder A Module for CMS Made Simple, Copyright (c) 2008 by Ted Kulp (wishy@cmsmadesimple.org) This project's homepage is: http://www.cmsmadesimple.org */ class fbForm { var $module_ptr = -1; var $Id = -1; var $Name = ''; var $Alias = ''; var $loaded = 'not'; var $formTotalPages = 0; var $Page; var $Attrs; var $Fields; var $formState; var $sampleTemplateCode; var $templateVariables; function fbForm(&$module_ptr, &$params, $loadDeep=false, $loadResp=false) { $this->module_ptr = $module_ptr; $this->Fields = array(); $this->Attrs = array(); $this->formState = 'new'; if (isset($params['form_id'])) { $this->Id = $params['form_id']; } if (isset($params['fbrp_form_alias'])) { $this->Alias = $params['fbrp_form_alias']; } if (isset($params['fbrp_form_name'])) { $this->Name = $params['fbrp_form_name']; } $fieldExpandOp = false; foreach($params as $pKey=>$pVal) { if (substr($pKey,0,9) == 'fbrp_FeX_' || substr($pKey,0,9) == 'fbrp_FeD_') { // expanding or shrinking a field $fieldExpandOp = true; } } if ($fieldExpandOp) { $params['fbrp_done'] = 0; if (isset($params['fbrp_continue'])) { $this->Page = $params['fbrp_continue'] - 1; } else { $this->Page = 1; } } else { if (isset($params['fbrp_continue'])) { $this->Page = $params['fbrp_continue']; } else { $this->Page = 1; } if (isset($params['fbrp_prev']) && isset($params['fbrp_previous'])) { $this->Page = $params['fbrp_previous']; $params['fbrp_done'] = 0; } } $this->formTotalPages = 1; if (isset($params['fbrp_done'])&& $params['fbrp_done']==1) { $this->formState = 'submit'; } if (isset($params['fbrp_user_form_validate']) && $params['fbrp_user_form_validate']==true) { $this->formState = 'confirm'; } if ($this->Id != -1) { if (isset($params['response_id']) && $this->formState == 'submit') { $this->formState = 'update'; } $this->Load($this->Id, $params, $loadDeep, $loadResp); } foreach ($params as $thisParamKey=>$thisParamVal) { if (substr($thisParamKey,0,11) == 'fbrp_forma_') { $thisParamKey = substr($thisParamKey,11); $this->Attrs[$thisParamKey] = $thisParamVal; } else if ($thisParamKey == 'fbrp_form_template' && $this->Id != -1) { $this->module_ptr->SetTemplate('fb_'.$this->Id,$thisParamVal); } } $this->templateVariables = Array( '{$sub_form_name}'=>$this->module_ptr->Lang('title_form_name'), '{$sub_date}'=>$this->module_ptr->Lang('help_submission_date'), '{$sub_host}'=>$this->module_ptr->Lang('help_server_name'), '{$sub_source_ip}'=>$this->module_ptr->Lang('help_sub_source_ip'), '{$sub_url}'=>$this->module_ptr->Lang('help_sub_url'), '{$fb_version}'=>$this->module_ptr->Lang('help_fb_version'), '{$TAB}'=>$this->module_ptr->Lang('help_tab'), ); } function SetAttributes($attrArray) { $this->Attrs = array_merge($this->Attrs,$attrArray); } function SetTemplate($template) { $this->Attrs['form_template'] = $template; $this->module_ptr->SetTemplate('fb_'.$this->Id,$template); } function GetId() { return $this->Id; } function SetId($id) { $this->Id = $id; } function GetName() { return $this->Name; } function GetFormState() { return $this->formState; } function GetPageCount() { return $this->formTotalPages; } function GetPageNumber() { return $this->Page; } function PageBack() { $this->Page--; } function SetName($name) { $this->Name = $name; } function GetAlias() { return $this->Alias; } function SetAlias($alias) { $this->Alias = $alias; } // dump params function DebugDisplay($params=array()) { $tmp = $this->module_ptr; $this->module_ptr = '[mdptr]'; if (isset($params['FORM'])) { $fpt = $params['FORM']; $params['FORM'] = '[form_pointer]'; } $template_tmp = $this->GetAttr('form_template',''); $this->SetAttr('form_template',strlen($template_tmp).' characters'); $field_tmp = $this->Fields; $this->Fields = 'Field Array: '.count($field_tmp); debug_display($this); $this->SetAttr('form_template',$template_tmp); $this->Fields = $field_tmp; foreach($this->Fields as $fld) { $fld->DebugDisplay(); } $this->module_ptr = $tmp; } function SetAttr($attrname, $val) { $this->Attrs[$attrname] = $val; } function GetAttr($attrname, $default="") { if (isset($this->Attrs[$attrname])) { return $this->Attrs[$attrname]; } else { return $default; } } function GetFieldCount() { return count($this->Fields); } function HasFieldNamed($name) { $ret = -1; foreach($this->Fields as $fld) { if ($fld->GetName() == $name) { $ret = $fld->GetId(); } } return $ret; } function AddTemplateVariable($name,$def) { $theKey = '{$'.$name.'}'; $this->templateVariables[$theKey] = $def; } function createSampleTemplateJavascript($fieldName='opt_email_template', $button_text='', $suffix='') { $fldAlias = preg_replace('/[^\w\d]/','_',$fieldName).$suffix; $jsCode = ""; $jsCode .= "
"; return $jsCode; } function createSampleTemplate($htmlish=false,$email=true, $oneline=false,$header=false) { $mod = $this->module_ptr; $ret = ""; if ($email) { if ($htmlish) { $ret .= "
".$mod->Lang('email_default_template')."
\n"; } else { $ret .= $mod->Lang('email_default_template')."\n"; } foreach($this->templateVariables as $thisKey=>$thisVal) { if ($htmlish) { $ret .= '
'.$thisVal.'
: '.$thisKey."
"; } else { $ret .= $thisVal.': '.$thisKey; } $ret .= "\n"; } if ($htmlish) { $ret .= "\n
\n"; } else { $ret .= "\n-------------------------------------------------\n"; } } elseif (! $oneline) { if ($htmlish) { $ret .= '
'; } $ret .= $mod->Lang('thanks'); if ($htmlish) { $ret .= '
'; } } $others = $this->GetFields(); for($i=0;$i
DisplayInSubmission()) { if ($others[$i]->GetAlias() != '') { $fldref = $others[$i]->GetAlias(); } else { $fldref = 'fld_'. $others[$i]->GetId(); } $ret .= '{if $'.$fldref.' != "" && $'.$fldref.' != "'.$this->GetAttr('unspecified',$mod->Lang('unspecified')).'" }'; $fldref = '{$'.$fldref.'}'; if ($htmlish) { $ret .= '
'.$others[$i]->GetName() . '
: ' . $fldref. "
"; } elseif ($oneline && !$header) { $ret .= $fldref. '{$TAB}'; } elseif ($oneline && $header) { $ret .= $others[$i]->GetName().'{$TAB}'; } else { $ret .= $others[$i]->GetName() . ': ' .$fldref; } $ret .= "{/if}\n"; } } if ($oneline) { $ret = substr($ret,0,strlen($ret) - 6). "\n"; } return $ret; } // function AdminTemplateHelp($formDescriptor,$fields='opt_email_template', // $includeHTML=true, $includeText=true, $oneline = false, $headerName='') function AdminTemplateHelp($formDescriptor,$fieldStruct) { $mod = $this->module_ptr; $ret = '
'.$mod->Lang('help_variables_for_template').'
'; $ret .= '
'.$mod->Lang('help_variable_name').'
'.$mod->Lang('help_form_field').'
'; $odd = false; foreach($this->templateVariables as $thisKey=>$thisVal) { $ret .= '
'.$thisKey.'
'.$thisVal.'
'; $odd = ! $odd; } $others = $this->GetFields(); for($i=0;$i
DisplayInSubmission()) { $ret .= '
{$'.$others[$i]->GetVariableName(). '} / {$fld_'. $others[$i]->GetId().'}'; if ($others[$i]->GetAlias() != '') { $ret .= ' / {$'.$others[$i]->GetAlias().'}'; } $ret .= '
' .$others[$i]->GetName() . '
'; $odd = ! $odd; } } $ret .= '
'.$mod->Lang('help_array_fields').'
'; $ret .= '
'.$mod->Lang('help_other_fields').'
'; $sampleTemplateCode = ''; foreach ($fieldStruct as $key=>$val) { $html_button = (isset($val['html_button']) && $val['html_button']); $text_button = (isset($val['text_button']) && $val['text_button']); $is_oneline = (isset($val['is_oneline']) && $val['is_oneline']); $is_email = (isset($val['is_email']) && $val['is_email']); $is_header = (isset($val['is_header']) && $val['is_header']); if ($html_button) { $button_text = $mod->Lang('title_create_sample_html_template'); } elseif ($is_header) { $button_text = $mod->Lang('title_create_sample_header_template'); } else { $button_text = $mod->Lang('title_create_sample_template'); } if ($html_button && $text_button) { $sample = $this->createSampleTemplate(false, $is_email, $is_oneline, $is_header); $sample = preg_replace('/\'/',"\\'",$sample); $sample = preg_replace('/\n/',"\\n'+\n'", $sample); $sampleTemplateCode .= preg_replace('/\|TEMPLATE\|/',"'".$sample."'", $this->createSampleTemplateJavascript($key, $mod->Lang('title_create_sample_template'),'text')); } $sample = $this->createSampleTemplate($html_button,$is_email, $is_oneline,$is_header); $sample = preg_replace('/\'/',"\\'",$sample); $sample = preg_replace('/\n/',"\\n'+\n'", $sample); $sampleTemplateCode .= preg_replace('/\|TEMPLATE\|/',"'".$sample."'", $this->createSampleTemplateJavascript($key, $button_text)); } /* $escapedSample = preg_replace('/\'/',"\\'",$this->createSampleTemplate(false,true,$oneline)); $escapedSampleHTML = preg_replace('/\'/',"\\'",$this->createSampleTemplate(true,true,$oneline)); $escapedSample = preg_replace('/\n/',"\\n'+\n'", $escapedSample); $escapedSampleHTML = preg_replace('/\n/',"\\n'+\n'", $escapedSampleHTML); $sampleTemplateCode = preg_replace('/\|TEMPLATE\|/',"'".$escapedSample."'", $this->createSampleTemplateJavascript($fieldName, $includeHTML, $includeText)); $sampleTemplateCode = preg_replace('/\|HTMLTEMPLATE\|/',"'".$escapedSampleHTML."'", $sampleTemplateCode); */ $sampleTemplateCode = preg_replace('/ID/',$formDescriptor, $sampleTemplateCode); $ret .= '
'.$sampleTemplateCode.'
'; $ret .= '
'; return $ret; } function Validate() { $validated = true; $message = array(); $formPageCount=1; $valPage = $this->Page - 1; for($i=0;$i
Fields);$i++) { if ($this->Fields[$i]->GetFieldType() == 'PageBreakField') { $formPageCount++; } if ($valPage != $formPageCount) { continue; } if (/*! $this->Fields[$i]->IsNonRequirableField() && */ $this->Fields[$i]->IsRequired() && $this->Fields[$i]->HasValue() == false) { array_push($message, $this->module_ptr->Lang('please_enter_a_value',$this->Fields[$i]->GetName())); $validated = false; $this->Fields[$i]->SetOption('is_valid',false); $this->Fields[$i]->validationErrorText = $this->module_ptr->Lang('please_enter_a_value',$this->Fields[$i]->GetName()); $this->Fields[$i]->validated = false; } else if ($this->Fields[$i]->GetValue() != $this->module_ptr->Lang('unspecified')) { $res = $this->Fields[$i]->Validate(); if ($res[0] != true) { array_push($message,$res[1]); $validated = false; $this->Fields[$i]->SetOption('is_valid',false); } else { $this->Fields[$i]->SetOption('is_valid',true); } } } return array($validated, $message); } function HasDisposition() { $hasDisp = false; for($i=0;$i
Fields);$i++) { if ($this->Fields[$i]->IsDisposition()) { $hasDisp = true; } } return $hasDisp; } // return an array: element 0 is true for success, false for failure // element 1 is an array of reasons, in the event of failure. function Dispose($returnid) { // first, we run all field methods that will modify other fields $computes = array(); for($i=0;$i
Fields);$i++) { if ($this->Fields[$i]->ModifiesOtherFields()) { $this->Fields[$i]->ModifyOtherFields(); } if ($this->Fields[$i]->ComputeOnSubmission()) { $computes[$i] = $this->Fields[$i]->ComputeOrder(); } } asort($computes); foreach($computes as $cKey=>$cVal) { $this->Fields[$cKey]->Compute(); } $resArray = array(); $retCode = true; // for each form disposition pseudo-field, dispose the form results for($i=0;$i
Fields);$i++) { if ($this->Fields[$i]->IsDisposition() && $this->Fields[$i]->DispositionIsPermitted()) { $res = $this->Fields[$i]->DisposeForm($returnid); if ($res[0] == false) { $retCode = false; array_push($resArray,$res[1]); } } } // handle any last cleanup functions for($i=0;$i
Fields);$i++) { $this->Fields[$i]->PostDispositionAction(); } return array($retCode,$resArray); } function RenderFormHeader() { if ($this->module_ptr->GetPreference('show_version',0) == 1) { return "\n\n"; } } function RenderFormFooter() { if ($this->module_ptr->GetPreference('show_version',0) == 1) { return "\n\n"; } } // returns a string. function RenderForm($id, &$params, $returnid) { $mod = $this->module_ptr; if ($this->Id == -1) { return "\n"; } if ($this->loaded != 'full') { $this->Load($this->Id,$params,true); } $reqSymbol = $this->GetAttr('required_field_symbol','*'); $mod->smarty->assign('title_page_x_of_y',$mod->Lang('title_page_x_of_y',array($this->Page,$this->formTotalPages))); $mod->smarty->assign('css_class',$this->GetAttr('css_class','')); $mod->smarty->assign('total_pages',$this->formTotalPages); $mod->smarty->assign('this_page',$this->Page); $mod->smarty->assign('form_name',$this->Name); $mod->smarty->assign('form_id',$this->Id); $hidden = $mod->CreateInputHidden($id, 'form_id', $this->Id); if (isset($params['lang'])) { $hidden .= $mod->CreateInputHidden($id, 'lang', $params['lang']); } $hidden .= $mod->CreateInputHidden($id, 'fbrp_continue', ($this->Page + 1)); if (isset($params['fbrp_browser_id'])) { $hidden .= $mod->CreateInputHidden($id,'fbrp_browser_id',$params['fbrp_browser_id']); } if (isset($params['response_id'])) { $hidden .= $mod->CreateInputHidden($id,'response_id',$params['response_id']); } if ($this->Page > 1) { $hidden .= $mod->CreateInputHidden($id, 'fbrp_previous', ($this->Page - 1)); } if ($this->Page == $this->formTotalPages) { $hidden .= $mod->CreateInputHidden($id, 'fbrp_done', 1); } $fields = array(); $prev = array(); $formPageCount = 1; for ($i=0; $i < count($this->Fields); $i++) { $thisField = &$this->Fields[$i]; if ($thisField->GetFieldType() == 'PageBreakField') { $formPageCount++; } if ($formPageCount != $this->Page) { $testIndex = 'fbrp__'.$this->Fields[$i]->GetId(); if (!isset($params[$testIndex])) { // do we need to write something? } elseif (is_array($params[$testIndex])) { foreach ($params[$testIndex] as $val) { $hidden .= $mod->CreateInputHidden($id, $testIndex.'[]', $this->unmy_htmlentities($val)); } } else { $hidden .= $mod->CreateInputHidden($id, $testIndex, $this->unmy_htmlentities($params[$testIndex])); } if ($formPageCount < $this->Page && $this->Fields[$i]->DisplayInSubmission()) { $oneset = new stdClass(); $oneset->value = $this->Fields[$i]->GetHumanReadableValue(); $mod->smarty->assign($this->Fields[$i]->GetName(),$oneset); if ($this->Fields[$i]->GetAlias() != '') { $mod->smarty->assign($this->Fields[$i]->GetAlias(),$oneset); } array_push($prev,$oneset); } continue; } $oneset = new stdClass(); $oneset->display = $thisField->DisplayInForm()?1:0; $oneset->required = $thisField->IsRequired()?1:0; $oneset->required_symbol = $thisField->IsRequired()?$reqSymbol:''; $oneset->css_class = $thisField->GetOption('css_class'); $oneset->helptext = $thisField->GetOption('helptext'); $oneset->field_helptext_id = 'fbrp_ht_'.$thisField->GetID(); // $oneset->valid = $thisField->GetOption('is_valid',true)?1:0; $oneset->valid = $thisField->validated?1:0; $oneset->error = $thisField->GetOption('is_valid',true)?'':$thisField->validationErrorText; $oneset->hide_name = 0; if( (!$thisField->HasLabel()) || $thisField->HideLabel() ) { $oneset->hide_name = 1; } $oneset->has_label = $thisField->HasLabel(); $oneset->needs_div = $thisField->NeedsDiv(); $oneset->name = $thisField->GetName(); $oneset->input = $thisField->GetFieldInput($id, $params, $returnid); $oneset->smarty_eval = $thisField->GetSmartyEval()?1:0; $oneset->multiple_parts = $thisField->HasMultipleFormComponents()?1:0; $oneset->label_parts = $thisField->LabelSubComponents()?1:0; $oneset->type = $thisField->GetDisplayType(); $oneset->input_id = $thisField->GetCSSId(); $mod->smarty->assign($thisField->GetName(),$oneset); if ($thisField->GetAlias() != '') { $mod->smarty->assign($thisField->GetAlias(),$oneset); } array_push($fields,$oneset); } $mod->smarty->assign_by_ref('fb_hidden',$hidden); $mod->smarty->assign_by_ref('fields',$fields); $mod->smarty->assign_by_ref('previous',$prev); $jsStr = ''; $jsTrigger = ''; if ($this->GetAttr('input_button_safety','0') == '1') { $jsStr = ''; $jsTrigger = " onclick='return LockButton()'"; } $js = $this->GetAttr('submit_javascript'); if ($this->Page > 1) { $mod->smarty->assign('prev',$mod->CreateInputSubmit($id, 'fbrp_prev', $this->GetAttr('prev_button_text'), 'class="fbsubmit_prev" '.$js)); } else { $mod->smarty->assign('prev',''); } if ($this->Page < $formPageCount) { $mod->smarty->assign('submit',$mod->CreateInputSubmit($id, 'fbrp_submit', $this->GetAttr('next_button_text'), 'class="fbsubmit_next" '.$js)); } else { $captcha = $mod->getModuleInstance('Captcha'); if ($this->GetAttr('use_captcha','0')== '1' && $captcha != null) { $mod->smarty->assign('graphic_captcha',$captcha->getCaptcha()); $mod->smarty->assign('title_captcha',$this->GetAttr('title_user_captcha',$mod->Lang('title_user_captcha'))); $mod->smarty->assign('input_captcha',$mod->CreateInputText($id, 'fbrp_captcha_phrase','')); $mod->smarty->assign('has_captcha','1'); } else { $mod->smarty->assign('has_captcha','0'); } $mod->smarty->assign('submit',$jsStr . $mod->CreateInputSubmit($id, 'fbrp_submit', $this->GetAttr('submit_button_text'), 'class="fbsubmit" '.$jsTrigger.' '.$js)); } return $mod->ProcessTemplateFromDatabase('fb_'.$this->Id); } function LoadForm($loadDeep=false) { return $this->Load($this->Id, array(), $loadDeep); } function unmy_htmlentities($val) { if ($val == "") { return ""; } $val = html_entity_decode($val); $val = str_replace("&","&",$val); $val = str_replace("<!--","",$val); $val = str_replace(">",">", $val); $val = str_replace("<","<",$val); $val = str_replace(""","\"",$val); $val = str_replace("$","\$",$val); $val = str_replace("!","!",$val); $val = str_replace("'","'",$val); // Uncomment if you need to convert unicode chars return $val; } function Load($formId, &$params, $loadDeep=false, $loadResp=false) { $mod = $this->module_ptr; //error_log("entering Form Load with usage ".memory_get_usage()); $sql = 'SELECT * FROM '.cms_db_prefix().'module_fb_form WHERE form_id=?'; $rs = $this->module_ptr->dbHandle->Execute($sql, array($formId)); if($rs && $rs->RecordCount() > 0) { $result = $rs->FetchRow(); $this->Id = $result['form_id']; if (!isset($params['fbrp_form_name']) || empty($params['fbrp_form_name'])) { $this->Name = $result['name']; } if (!isset($params['fbrp_form_alias']) || empty($params['fbrp_form_alias'])) { $this->Alias = $result['alias']; } } else { return false; } $sql = 'SELECT name,value FROM '.cms_db_prefix(). 'module_fb_form_attr WHERE form_id=?'; $rs = $this->module_ptr->dbHandle->Execute($sql, array($formId)); while ($rs && $result=$rs->FetchRow()) { $this->Attrs[$result['name']] = $result['value']; } $this->loaded = 'summary'; if (isset($params['response_id'])) { $loadDeep = true; $loadResp = true; } if ($loadDeep) { if ($loadResp) { // if it's a stored form, load the results -- but we need to manually merge them, // since $params[] should override the database value (say we're resubmitting a form) $fbf = $mod->GetFormBrowserField($formId); if ($fbf != false) { // if we're binding to FEU, get the FEU ID, see if there's a response for // that user. If so, load it. Otherwise, bring up an empty form. if ($fbf->GetOption('feu_bind','0')=='1') { $feu = $mod->GetModuleInstance('FrontEndUsers'); if ($feu == false) { debug_display("FAILED to instatiate FEU!"); return; } if (!isset($_COOKIE['cms_admin_user_id'])) { $response_id = $mod->GetResponseIDFromFEUID($feu->LoggedInId()); if ($response_id !== false) { $check = $this->module_ptr->dbHandle->GetOne('select count(*) from '.cms_db_prefix(). 'module_fb_formbrowser where fbr_id=?',array($response_id)); if ($check == 1) { $params['response_id'] = $response_id; } } } } } if (isset($params['response_id'])) { $loadParams = array('response_id'=>$params['response_id']); $this->LoadResponseValues($loadParams); foreach ($loadParams as $thisParamKey=>$thisParamValue) { if (! isset($params[$thisParamKey])) { $params[$thisParamKey] = $thisParamValue; } } } } $sql = 'SELECT * FROM ' . cms_db_prefix(). 'module_fb_field WHERE form_id=? ORDER BY order_by'; $rs = $this->module_ptr->dbHandle->Execute($sql, array($formId)); $result = array(); if ($rs && $rs->RecordCount() > 0) { $result = $rs->GetArray(); } $fieldCount = 0; if (count($result) > 0) { foreach($result as $thisRes) { //error_log("Instantiating Field. usage ".memory_get_usage()); $className = $this->MakeClassName($thisRes['type'], ''); // create the field object if ( ( isset($thisRes['field_id']) && ( isset($params['fbrp__'.$thisRes['field_id']]) || isset($params['fbrp___'.$thisRes['field_id']]) ) ) || (isset($thisRes['field_id']) && isset($params['value_'.$thisRes['name']])) || (isset($thisRes['field_id']) && isset($params['value_fld'.$thisRes['field_id']])) || ( isset($params['field_id']) && isset($thisRes['field_id']) && $params['field_id'] == $thisRes['field_id'] ) ) { $thisRes = array_merge($thisRes,$params); } $this->Fields[$fieldCount] = $this->NewField($thisRes); $fieldCount++; } } $this->loaded = 'full'; } for ($i=0; $i < count($this->Fields); $i++) { if ($this->Fields[$i]->Type == 'PageBreakField') { $this->formTotalPages++; } } return true; } /* notable params: fbrp_xml_file -- source file for the XML xml_string -- source string for the XML */ function ImportXML(&$params) { // xml_parser_create, xml_parse_into_struct $parser = xml_parser_create(''); xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 ); xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 0 ); // was 1 if (isset($params['fbrp_xml_file']) && ! empty($params['fbrp_xml_file'])) { xml_parse_into_struct($parser, file_get_contents($params['fbrp_xml_file']), $values); } elseif (isset($params['xml_string']) && ! empty($params['xml_string'])) { xml_parse_into_struct($parser, $params['xml_string'], $values); } else { return false; } xml_parser_free($parser); $elements = array(); $stack = array(); $fieldMap = array(); foreach ( $values as $tag ) { $index = count( $elements ); if ( $tag['type'] == "complete" || $tag['type'] == "open" ) { $elements[$index] = array(); $elements[$index]['name'] = $tag['tag']; $elements[$index]['attributes'] = empty($tag['attributes']) ? "" : $tag['attributes']; $elements[$index]['content'] = empty($tag['value']) ? "" : $tag['value']; if ( $tag['type'] == "open" ) { # push $elements[$index]['children'] = array(); $stack[count($stack)] = &$elements; $elements = &$elements[$index]['children']; } } if ( $tag['type'] == "close" ) { # pop $elements = &$stack[count($stack) - 1]; unset($stack[count($stack) - 1]); } } //debug_display($elements); if (!isset($elements[0]) || !isset($elements[0]) || !isset($elements[0]['attributes'])) { //parsing failed, or invalid file. return false; } $params['form_id'] = -1; // override any form_id values that may be around $formAttrs = &$elements[0]['attributes']; if (isset($params['fbrp_import_formalias']) && !empty($params['fbrp_import_formalias'])) { $this->SetAlias($params['fbrp_import_formalias']); } else if ($this->inXML($formAttrs['alias'])) { $this->SetAlias($formAttrs['alias']); } if (isset($params['fbrp_import_formname']) && !empty($params['fbrp_import_formname'])) { $this->SetName($params['fbrp_import_formname']); } $foundfields = false; // populate the attributes and field name first. When we see a field, we save the form and then start adding the fields to it. foreach ($elements[0]['children'] as $thisChild) { if ($thisChild['name'] == 'form_name') { $curname = $this->GetName(); if (empty($curname)) { $this->SetName($thisChild['content']); } } elseif ($thisChild['name'] == 'attribute') { $this->SetAttr($thisChild['attributes']['key'], $thisChild['content']); } else { // we got us a field if (! $foundfields) { // first field $foundfields = true; if( isset($params['fbrp_import_formname']) && trim($params['fbrp_import_formname']) != '') { $this->SetName(trim($params['fbrp_import_formname'])); } if( isset($params['fbrp_import_formalias']) && trim($params['fbrp_import_formname']) != '') { $this->SetAlias(trim($params['fbrp_import_formalias'])); } $this->Store(); $params['form_id'] = $this->GetId(); } //debug_display($thisChild); $fieldAttrs = &$thisChild['attributes']; $className = $this->MakeClassName($fieldAttrs['type'], ''); //debug_display($className); $newField = new $className($this, $params); $oldId = $fieldAttrs['id']; if ($this->inXML($fieldAttrs['alias'])) { $newField->SetAlias($fieldAttrs['alias']); } $newField->SetValidationType($fieldAttrs['validation_type']); if ($this->inXML($fieldAttrs['order_by'])) { $newField->SetOrder($fieldAttrs['order_by']); } if ($this->inXML($fieldAttrs['required'])) { $newField->SetRequired($fieldAttrs['required']); } if ($this->inXML($fieldAttrs['hide_label'])) { $newField->SetHideLabel($fieldAttrs['hide_label']); } foreach ($thisChild['children'] as $thisOpt) { if ($thisOpt['name'] == 'field_name') { $newField->SetName($thisOpt['content']); } if ($thisOpt['name'] == 'options') { foreach ($thisOpt['children'] as $thisOption) { $newField->OptionFromXML($thisOption); } } } $newField->Store(true); array_push($this->Fields,$newField); $fieldMap[$oldId] = $newField->GetId(); } } // clean up references if (isset($params['fbrp_xml_file']) && ! empty($params['fbrp_xml_file'])) { // need to update mappings in templates. $tmp = $this->updateRefs($this->GetAttr('form_template',''), $fieldMap); $this->SetAttr('form_template',$tmp); $tmp = $this->updateRefs($this->GetAttr('submit_response',''), $fieldMap); $this->SetAttr('submit_response',$tmp); // need to update mappings in field templates. $options = array('email_template','file_template'); foreach($this->Fields as $fid=>$thisField) { $changes = false; foreach ($options as $to) { $templ = $thisField->GetOption($to,''); if (!empty($templ)) { $tmp = $this->updateRefs($templ, $fieldMap); $thisField->SetOption($to,$tmp); $changes = true; } } // need to update mappings in FormBrowser sort fields if ($thisField->GetFieldType() == 'DispositionFormBrowser') { for ($i=1;$i<6;$i++) { $old = $thisField->GetOption('sortfield'.$i); if (isset($fieldMap[$old])) { $thisField->SetOption('sortfield'.$i,$fieldMap[$old]); $changes = true; } } } if ($changes) { $thisField->Store(true); } } $this->Store(); } return true; } function updateRefs($text, &$fieldMap) { foreach ($fieldMap as $k=>$v) { $text = preg_replace('/([\{\b\s])\$fld_'.$k.'([\}\b\s])/','$1\$fld_'.$v.'$2',$text); } return $text; } function inXML(&$var) { if (isset($var) && strlen($var) > 0) { return true; } else { return false; } } // storeDeep also stores all fields and options for a form function Store($storeDeep=false) { if ($this->Id == -1) { $this->Id = $this->module_ptr->dbHandle->GenID(cms_db_prefix(). 'module_fb_form_seq'); $sql = 'INSERT INTO ' . cms_db_prefix(). 'module_fb_form (form_id, name, alias) '. 'VALUES (?, ?, ?)'; $res = $this->module_ptr->dbHandle->Execute($sql, array($this->Id, $this->Name, $this->Alias)); } else { $sql = 'UPDATE ' . cms_db_prefix(). 'module_fb_form set name=?, alias=? where form_id=?'; $res = $this->module_ptr->dbHandle->Execute($sql, array($this->Name, $this->Alias, $this->Id)); } // save out the attrs $sql = 'DELETE FROM '.cms_db_prefix(). 'module_fb_form_attr WHERE form_id=?'; $res = $this->module_ptr->dbHandle->Execute($sql, array($this->Id)); foreach ($this->Attrs as $thisAttrKey=>$thisAttrValue) { $formAttrId = $this->module_ptr->dbHandle->GenID(cms_db_prefix(). 'module_fb_form_attr_seq'); $sql = 'INSERT INTO ' . cms_db_prefix(). 'module_fb_form_attr (form_attr_id, form_id, name, value) '. 'VALUES (?, ?, ?, ?)'; $res = $this->module_ptr->dbHandle->Execute($sql, array($formAttrId, $this->Id, $thisAttrKey, $thisAttrValue)); if ($thisAttrKey == 'form_template') { $this->module_ptr->SetTemplate('fb_'.$this->Id,$thisAttrValue); } } return $res; } function Delete() { if ($this->Id == -1) { return false; } if ($this->loaded != 'full') { $this->Load($this->Id,array(),true); } foreach ($this->Fields as $field) { $field->Delete(); } $this->module_ptr->DeleteTemplate('fb_'.$this->Id); $sql = 'DELETE FROM ' . cms_db_prefix() . 'module_fb_form where form_id=?'; $res = $this->module_ptr->dbHandle->Execute($sql, array($this->Id)); $sql = 'DELETE FROM ' . cms_db_prefix() . 'module_fb_form_attr where form_id=?'; $res = $this->module_ptr->dbHandle->Execute($sql, array($this->Id)); return true; } // returns a class name, and makes sure the file where the class is // defined has been loaded. function MakeClassName($type, $classDirPrefix) { // perform rudimentary security, since Type could come in from a form $type = preg_replace("/[\W]|\.\./", "_", $type); if ($type == '' || strlen($type) < 1) { $type = 'Field'; } $classFile=''; if (strlen($classDirPrefix) > 0) { $classFile = $classDirPrefix .'/'.$type.'.class.php'; } else { $classFile = $type.'.class.php'; } require_once cms_join_path(dirname(__FILE__), $classFile); // class names are prepended with "fb" to prevent namespace clash. return ( 'fb'.$type ); } function AddEditForm($id, $returnid, $message='') { global $gCms; $mod = $this->module_ptr; $mod->smarty->assign('message',$message); $mod->smarty->assign('formstart', $mod->CreateFormStart($id, 'admin_store_form', $returnid)); $mod->smarty->assign('formid', $mod->CreateInputHidden($id, 'form_id', $this->Id)); $mod->smarty->assign('tab_start',$mod->StartTabHeaders(). $mod->SetTabHeader('maintab',$mod->Lang('tab_main')). $mod->SetTabHeader('submittab',$mod->Lang('tab_submit')). $mod->SetTabHeader('symboltab',$mod->Lang('tab_symbol')). $mod->SetTabHeader('captchatab',$mod->Lang('tab_captcha')). $mod->SetTabHeader('templatelayout',$mod->Lang('tab_templatelayout')). $mod->SetTabHeader('submittemplate',$mod->Lang('tab_submissiontemplate')). $mod->EndTabHeaders() . $mod->StartTabContent()); $mod->smarty->assign('tabs_end',$mod->EndTabContent()); $mod->smarty->assign('maintab_start',$mod->StartTab("maintab")); $mod->smarty->assign('submittab_start',$mod->StartTab("submittab")); $mod->smarty->assign('symboltab_start',$mod->StartTab("symboltab")); $mod->smarty->assign('templatetab_start',$mod->StartTab("templatelayout")); $mod->smarty->assign('submittemplatetab_start',$mod->StartTab("submittemplate")); $mod->smarty->assign('captchatab_start',$mod->StartTab("captchatab")); $mod->smarty->assign('tab_end',$mod->EndTab()); $mod->smarty->assign('form_end',$mod->CreateFormEnd()); $mod->smarty->assign('title_form_name',$mod->Lang('title_form_name')); $mod->smarty->assign('input_form_name', $mod->CreateInputText($id, 'fbrp_form_name', $this->Name, 50)); $mod->smarty->assign('template_are_you_sure',$mod->Lang('template_are_you_sure')); $mod->smarty->assign('title_load_template',$mod->Lang('title_load_template')); $modLink = $mod->CreateLink($id, 'admin_get_template', $returnid, '', array(), '', true); list($mod_path, $mod_param) = explode('?',$modLink); $mod->smarty->assign('security_key',CMS_SECURE_PARAM_NAME.'='.$_SESSION[CMS_USER_KEY]); $mod->smarty->assign('mod_path',$mod_path); $mod->smarty->assign('mod_param',html_entity_decode($mod_param)); $templateList = array(''=>'',$mod->Lang('default_template')=>'RenderFormDefault.tpl', $mod->Lang('table_left_template')=>'RenderFormTableTitleLeft.tpl', $mod->Lang('table_top_template')=>'RenderFormTableTitleTop.tpl'); $allForms = $mod->GetForms(); foreach ($allForms as $thisForm) { if ($thisForm['form_id'] != $this->Id) { $templateList[$mod->Lang('form_template_name',$thisForm['name'])] = $thisForm['form_id']; } } $mod->smarty->assign('input_load_template',$mod->CreateInputDropdown($id, 'fbrp_fb_template_load', $templateList, -1, '', 'id="fb_template_load" onchange="getTemplate()"')); $mod->smarty->assign('help_template_variables',$mod->Lang('template_variable_help')); $mod->smarty->assign('title_form_unspecified',$mod->Lang('title_form_unspecified')); $mod->smarty->assign('input_form_unspecified', $mod->CreateInputText($id, 'fbrp_forma_unspecified', $this->GetAttr('unspecified',$mod->Lang('unspecified')), 50)); $mod->smarty->assign('title_form_status', $mod->Lang('title_form_status')); $mod->smarty->assign('text_ready', $mod->Lang('title_ready_for_deployment')); $mod->smarty->assign('title_form_alias',$mod->Lang('title_form_alias')); $mod->smarty->assign('input_form_alias', $mod->CreateInputText($id, 'fbrp_form_alias', $this->Alias, 50)); $mod->smarty->assign('title_form_css_class', $mod->Lang('title_form_css_class')); $mod->smarty->assign('input_form_css_class', $mod->CreateInputText($id, 'fbrp_forma_css_class', $this->GetAttr('css_class','formbuilderform'), 50,50)); $mod->smarty->assign('title_form_fields', $mod->Lang('title_form_fields')); $mod->smarty->assign('title_form_main', $mod->Lang('title_form_main')); if( $mod->GetPreference('show_fieldids',0) != 0 ) { $mod->smarty->assign('title_field_id', $mod->Lang('title_field_id')); } if( $mod->GetPreference('show_fieldaliases',1) != 0 ) { $mod->smarty->assign('title_field_alias', $mod->Lang('title_field_alias_short')); } $mod->smarty->assign('back', $mod->CreateLink($id, 'defaultadmin', '', $mod->Lang('back_top'), array())); $mod->smarty->assign('title_field_name', $mod->Lang('title_field_name')); $mod->smarty->assign('title_field_type', $mod->Lang('title_field_type')); $mod->smarty->assign('title_field_type', $mod->Lang('title_field_type')); $mod->smarty->assign('title_form_template', $mod->Lang('title_form_template')); $mod->smarty->assign('title_list_delimiter', $mod->Lang('title_list_delimiter')); $mod->smarty->assign('title_redirect_page', $mod->Lang('title_redirect_page')); $mod->smarty->assign('title_submit_action', $mod->Lang('title_submit_action')); $mod->smarty->assign('title_submit_response', $mod->Lang('title_submit_response')); $mod->smarty->assign('title_inline_form', $mod->Lang('title_inline_form')); $mod->smarty->assign('title_submit_actions', $mod->Lang('title_submit_actions')); $mod->smarty->assign('title_submit_labels', $mod->Lang('title_submit_labels')); $mod->smarty->assign('title_submit_javascript', $mod->Lang('title_submit_javascript')); $mod->smarty->assign('title_submit_help', $mod->cms->variables['admintheme']->DisplayImage('icons/system/info.gif','true','','','systemicon'). $mod->Lang('title_submit_help')); $mod->smarty->assign('title_submit_response_help', $mod->cms->variables['admintheme']->DisplayImage('icons/system/info.gif','true','','','systemicon'). $mod->Lang('title_submit_response_help')); $submitActions = array($mod->Lang('display_text')=>'text', $mod->Lang('redirect_to_page')=>'redir'); $mod->smarty->assign('input_submit_action', $mod->CreateInputRadioGroup($id, 'fbrp_forma_submit_action', $submitActions, $this->GetAttr('submit_action','text'))); $captcha = $mod->getModuleInstance('Captcha'); if ($captcha == null) { $mod->smarty->assign('title_install_captcha', $mod->Lang('title_captcha_not_installed')); $mod->smarty->assign('captcha_installed',0); } else { $mod->smarty->assign('title_use_captcha', $mod->Lang('title_use_captcha')); $mod->smarty->assign('captcha_installed',1); $mod->smarty->assign('input_use_captcha',$mod->CreateInputHidden($id,'fbrp_forma_use_captcha','0'). $mod->CreateInputCheckbox($id,'fbrp_forma_use_captcha','1',$this->GetAttr('use_captcha','0')). $mod->Lang('title_use_captcha_help')); } $mod->smarty->assign('title_information',$mod->Lang('information')); $mod->smarty->assign('title_order',$mod->Lang('order')); $mod->smarty->assign('title_field_required_abbrev',$mod->Lang('title_field_required_abbrev')); $mod->smarty->assign('hasdisposition',$this->HasDisposition()?1:0); $maxOrder = 1; if($this->Id > 0) { $mod->smarty->assign('submit_button', $mod->CreateInputSubmit($id, 'fbrp_submit', $mod->Lang('save_and_continue'))); $mod->smarty->assign('fb_hidden', $mod->CreateInputHidden($id, 'fbrp_form_op',$mod->Lang('updated'))); $mod->smarty->assign('adding',0); $mod->smarty->assign('save_button', $mod->CreateInputSubmit($id, 'fbrp_submit', $mod->Lang('save'))); $fieldList = array(); $currow = "row1"; $count = 1; $last = $this->GetFieldCount(); foreach ($this->Fields as $thisField) { $oneset = new stdClass(); $oneset->rowclass = $currow; $oneset->name = $mod->CreateLink($id, 'admin_add_edit_field', '', $thisField->GetName(), array('field_id'=>$thisField->GetId(),'form_id'=>$this->Id)); if( $mod->GetPreference('show_fieldids',0) != 0 ) { $oneset->id = $mod->CreateLink($id, 'admin_add_edit_field', '', $thisField->GetId(), array('field_id'=>$thisField->GetId(),'form_id'=>$this->Id)); } $oneset->type = $thisField->GetDisplayType(); $oneset->alias = $thisField->GetAlias(); if (/*$thisField->IsDisposition() ||*/ !$thisField->DisplayInForm() || $thisField->IsNonRequirableField()) { $oneset->disposition = '.'; } else if ($thisField->IsRequired()) { $oneset->disposition = $mod->CreateLink($id, 'admin_update_field_required', '', $mod->cms->variables['admintheme']->DisplayImage('icons/system/true.gif','true','','','systemicon'), array('form_id'=>$this->Id,'fbrp_active'=>'off','field_id'=>$thisField->GetId())); } else { $oneset->disposition = $mod->CreateLink($id, 'admin_update_field_required', '', $mod->cms->variables['admintheme']->DisplayImage('icons/system/false.gif','false','','','systemicon'), array('form_id'=>$this->Id,'fbrp_active'=>'on','field_id'=>$thisField->GetId())); } $oneset->field_status = $thisField->StatusInfo(); if ($count > 1) { $oneset->up = $mod->CreateLink($id, 'admin_update_field_order', '', $mod->cms->variables['admintheme']->DisplayImage('icons/system/arrow-u.gif','up','','','systemicon'), array('form_id'=>$this->Id,'fbrp_dir'=>'up','field_id'=>$thisField->GetId())); } else { $oneset->up = ' '; } if ($count < $last) { $oneset->down=$mod->CreateLink($id, 'admin_update_field_order', '', $mod->cms->variables['admintheme']->DisplayImage('icons/system/arrow-d.gif','down','','','systemicon'), array('form_id'=>$this->Id,'fbrp_dir'=>'down','field_id'=>$thisField->GetId())); } else { $oneset->down = ' '; } $oneset->editlink = $mod->CreateLink($id, 'admin_add_edit_field', '', $mod->cms->variables['admintheme']->DisplayImage('icons/system/edit.gif',$mod->Lang('edit'),'','','systemicon'), array('field_id'=>$thisField->GetId(),'form_id'=>$this->Id)); $oneset->deletelink = $mod->CreateLink($id, 'admin_delete_field', '', $mod->cms->variables['admintheme']->DisplayImage('icons/system/delete.gif',$mod->Lang('delete'),'','','systemicon'), array('field_id'=>$thisField->GetId(),'form_id'=>$this->Id),$mod->Lang('are_you_sure_delete_field',htmlspecialchars($thisField->GetName()))); ($currow == "row1"?$currow="row2":$currow="row1"); $count++; if ($thisField->GetOrder() >= $maxOrder) { $maxOrder = $thisField->GetOrder() + 1; } array_push($fieldList, $oneset); } $mod->smarty->assign('fields',$fieldList); $mod->smarty->assign('add_field_link', $mod->CreateLink($id, 'admin_add_edit_field', $returnid,$mod->cms->variables['admintheme']->DisplayImage('icons/system/newobject.gif',$mod->Lang('title_add_new_field'),'','','systemicon'),array('form_id'=>$this->Id, 'fbrp_order_by'=>$maxOrder), '', false) . $mod->CreateLink($id, 'admin_add_edit_field', $returnid,$mod->Lang('title_add_new_field'),array('form_id'=>$this->Id, 'fbrp_order_by'=>$maxOrder), '', false)); $mod->smarty->assign('order_field_link', $mod->CreateLink($id, 'admin_reorder_form', $returnid,$mod->cms->variables['admintheme']->DisplayImage('icons/system/reorder.gif',$mod->Lang('title_reorder_form'),'','','systemicon'),array('form_id'=>$this->Id), '', false) . $mod->CreateLink($id, 'admin_reorder_form', $returnid,$mod->Lang('title_reorder_form'),array('form_id'=>$this->Id), '', false)); if ($mod->GetPreference('enable_fastadd',1) == 1) { $mod->smarty->assign('fastadd',1); $mod->smarty->assign('title_fastadd',$mod->Lang('title_fastadd')); $typeInput = ""; $typeInput = str_replace('&','&',$typeInput); $mod->initialize(); if ($mod->GetPreference('show_field_level','basic') == 'basic') { $mod->smarty->assign('input_fastadd',$typeInput.$mod->CreateInputDropdown($id, 'fbrp_field_type',array_merge(array($mod->Lang('select_type')=>''),$mod->std_field_types), -1,'', 'onchange="fast_add(this)"'). $mod->Lang('title_switch_advanced'). $mod->CreateLink($id, 'admin_add_edit_form', $returnid,$mod->Lang('title_switch_advanced_link'),array('form_id'=>$this->Id, 'fbrp_set_field_level'=>'advanced'))); } else { $mod->smarty->assign('input_fastadd',$typeInput.$mod->CreateInputDropdown($id, 'fbrp_field_type',array_merge(array($mod->Lang('select_type')=>''),$mod->field_types), -1,'', 'onchange="fast_add(this)"'). $mod->Lang('title_switch_basic'). $mod->CreateLink($id, 'admin_add_edit_form', $returnid,$mod->Lang('title_switch_basic_link'),array('form_id'=>$this->Id, 'fbrp_set_field_level'=>'basic'))); } } } else { $mod->smarty->assign('save_button',''); $mod->smarty->assign('submit_button', $mod->CreateInputSubmit($id, 'fbrp_submit', $mod->Lang('add'))); $mod->smarty->assign('fb_hidden', $mod->CreateInputHidden($id, 'fbrp_form_op',$mod->Lang('added'))); $mod->smarty->assign('adding',1); } $mod->smarty->assign('link_notready',"
".$mod->Lang('title_not_ready1')."
".$mod->Lang('title_not_ready2')." ".$mod->CreateLink($id, 'admin_add_edit_field', $returnid,$mod->Lang('title_not_ready_link'),array('form_id'=>$this->Id, 'fbrp_order_by'=>$maxOrder,'fbrp_dispose_only'=>1), '', false, false,'class="module_fb_link"')." ".$mod->Lang('title_not_ready3') ); $mod->smarty->assign('input_inline_form',$mod->CreateInputHidden($id,'fbrp_forma_inline','0'). $mod->CreateInputCheckbox($id,'fbrp_forma_inline','1',$this->GetAttr('inline','0')). $mod->Lang('title_inline_form_help')); $mod->smarty->assign('title_form_submit_button', $mod->Lang('title_form_submit_button')); $mod->smarty->assign('input_form_submit_button', $mod->CreateInputText($id, 'fbrp_forma_submit_button_text', $this->GetAttr('submit_button_text',$mod->Lang('button_submit')), 35, 35)); $mod->smarty->assign('title_submit_button_safety', $mod->Lang('title_submit_button_safety_help')); $mod->smarty->assign('input_submit_button_safety',$mod->CreateInputHidden($id,'fbrp_forma_input_button_safety','0'). $mod->CreateInputCheckbox($id,'fbrp_forma_input_button_safety','1',$this->GetAttr('input_button_safety','0')). $mod->Lang('title_submit_button_safety')); $mod->smarty->assign('title_form_prev_button', $mod->Lang('title_form_prev_button')); $mod->smarty->assign('input_form_prev_button', $mod->CreateInputText($id, 'fbrp_forma_prev_button_text', $this->GetAttr('prev_button_text',$mod->Lang('button_previous')), 35, 35)); $mod->smarty->assign('input_title_user_captcha', $mod->CreateInputText($id, 'fbrp_forma_title_user_captcha', $this->GetAttr('title_user_captcha',$mod->Lang('title_user_captcha')),35,80)); $mod->smarty->assign('title_title_user_captcha',$mod->Lang('title_title_user_captcha')); $mod->smarty->assign('input_title_user_captcha_error', $mod->CreateInputText($id, 'fbrp_forma_captcha_wrong', $this->GetAttr('captcha_wrong',$mod->Lang('wrong_captcha')),35,80)); $mod->smarty->assign('title_user_captcha_error',$mod->Lang('title_user_captcha_error')); $mod->smarty->assign('title_form_next_button', $mod->Lang('title_form_next_button')); $mod->smarty->assign('input_form_next_button', $mod->CreateInputText($id, 'fbrp_forma_next_button_text', $this->GetAttr('next_button_text',$mod->Lang('button_continue')), 35, 35)); $mod->smarty->assign('title_form_predisplay_udt', $mod->Lang('title_form_predisplay_udt')); { $usertagops = $gCms->GetUserTagOperations(); $usertags = $usertagops->ListUserTags(); $usertaglist = array(); $usertaglist[$mod->lang('none')] = -1; foreach( $usertags as $key => $value ) { $usertaglist[$value] = $key; } $mod->smarty->assign('input_form_predisplay_udt', $mod->CreateInputDropdown($id,'fbrp_forma_predisplay_udt',$usertaglist,-1, $this->GetAttr('predisplay_udt',-1))); } $mod->smarty->assign('title_form_required_symbol', $mod->Lang('title_form_required_symbol')); $mod->smarty->assign('input_form_required_symbol', $mod->CreateInputText($id, 'fbrp_forma_required_field_symbol', $this->GetAttr('required_field_symbol','*'), 50)); $mod->smarty->assign('input_list_delimiter', $mod->CreateInputText($id, 'fbrp_forma_list_delimiter', $this->GetAttr('list_delimiter',','), 50)); $contentops = $gCms->GetContentOperations(); $mod->smarty->assign('input_redirect_page',$contentops->CreateHierarchyDropdown('',$this->GetAttr('redirect_page','0'), $id.'fbrp_forma_redirect_page')); $mod->smarty->assign('input_form_template', $mod->CreateTextArea(false, $id, $this->GetAttr('form_template',$this->DefaultTemplate()), 'fbrp_forma_form_template','','fb_form_template')); $mod->smarty->assign('input_submit_javascript', $mod->CreateTextArea(false, $id, $this->GetAttr('submit_javascript',''), 'fbrp_forma_submit_javascript','module_fb_area_short','fb_submit_javascript'). '
'.$mod->Lang('title_submit_javascript_long')); $mod->smarty->assign('input_submit_response', $mod->CreateTextArea(false, $id, $this->GetAttr('submit_response',''), 'fbrp_forma_submit_response','module_fb_area_wide')); $parms = array(); $parms['forma_submit_response']['html_button'] = true; $parms['forma_submit_response']['txt_button'] = false; $parms['forma_submit_response']['is_one_line'] = false; $parms['forma_submit_response']['is_email'] = false; $mod->smarty->assign('help_submit_response', $this->AdminTemplateHelp($id,$parms)); return $mod->ProcessTemplate('AddEditForm.tpl'); } function &NewField(&$params) { //$aefield = new fbFieldBase($this,$params); $aefield = false; if (isset($params['field_id']) && $params['field_id'] != -1 ) { // we're loading an extant field $sql = 'SELECT type FROM ' . cms_db_prefix() . 'module_fb_field WHERE field_id=?'; $rs = $this->module_ptr->dbHandle->Execute($sql, array( $params['field_id'])); if($rs && $result = $rs->FetchRow()) { if ($result['type'] != '') { $className = $this->MakeClassName($result['type'] , ''); $aefield = new $className($this, $params); $aefield->LoadField($params); } } } if ($aefield === false) { // new field if (! isset($params['fbrp_field_type'])) { // unknown field type $aefield = new fbFieldBase($this,$params); } else { // specified field type via params $className = $this->MakeClassName($params['fbrp_field_type'], ''); $aefield = new $className($this, $params); } } return $aefield; } function AddEditField($id, &$aefield, $dispose_only, $returnid, $message='') { $mod = $this->module_ptr; $mod->smarty->assign('message',$message); $mod->smarty->assign('backtoform_nav',$mod->CreateLink($id, 'admin_add_edit_form', $returnid, $mod->Lang('link_back_to_form'), array('form_id'=>$this->Id))); $mainList = array(); $advList = array(); $baseList = $aefield->PrePopulateBaseAdminForm($id, $dispose_only); if ($aefield->GetFieldType() == '') { // still need type $mod->smarty->assign('start_form',$mod->CreateFormStart($id, 'admin_add_edit_field', $returnid)); $fieldList = array('main'=>array(),'adv'=>array()); } else { // we have our type $mod->smarty->assign('start_form',$mod->CreateFormStart($id, 'admin_add_edit_field', $returnid)); $fieldList = $aefield->PrePopulateAdminForm($id); } $mod->smarty->assign('end_form', $mod->CreateFormEnd()); $mod->smarty->assign('tab_start',$mod->StartTabHeaders(). $mod->SetTabHeader('maintab',$mod->Lang('tab_main')). $mod->SetTabHeader('advancedtab',$mod->Lang('tab_advanced')). $mod->EndTabHeaders() . $mod->StartTabContent()); $mod->smarty->assign('tabs_end',$mod->EndTabContent()); $mod->smarty->assign('maintab_start',$mod->StartTab("maintab")); $mod->smarty->assign('advancedtab_start',$mod->StartTab("advancedtab")); $mod->smarty->assign('tab_end',$mod->EndTab()); $mod->smarty->assign('notice_select_type',$mod->Lang('notice_select_type')); if($aefield->GetId() != -1) { $mod->smarty->assign('op',$mod->CreateInputHidden($id, 'fbrp_op',$mod->Lang('updated'))); $mod->smarty->assign('submit',$mod->CreateInputSubmit($id, 'fbrp_aef_upd', $mod->Lang('update'))); } else { $mod->smarty->assign('op',$mod->CreateInputHidden($id, 'fbrp_op', $mod->Lang('added'))); $mod->smarty->assign('submit',$mod->CreateInputSubmit($id, 'fbrp_aef_add', $mod->Lang('add'))); } if ($aefield->HasAddOp()) { $mod->smarty->assign('add',$mod->CreateInputSubmit($id,'fbrp_aef_optadd',$aefield->GetOptionAddButton())); } else { $mod->smarty->assign('add',''); } if ($aefield->HasDeleteOp()) { $mod->smarty->assign('del',$mod->CreateInputSubmit($id,'fbrp_aef_optdel',$aefield->GetOptionDeleteButton())); } else { $mod->smarty->assign('del',''); } $mod->smarty->assign('fb_hidden', $mod->CreateInputHidden($id, 'form_id', $this->Id) . $mod->CreateInputHidden($id, 'field_id', $aefield->GetId()) . $mod->CreateInputHidden($id, 'fbrp_order_by', $aefield->GetOrder()). $mod->CreateInputHidden($id,'fbrp_set_from_form','1')); if (/*!$aefield->IsDisposition() && */ !$aefield->IsNonRequirableField()) { $mod->smarty->assign('requirable',1); } else { $mod->smarty->assign('requirable',0); } if (isset($baseList['main'])) { foreach ($baseList['main'] as $item) { $titleStr=$item[0]; $inputStr=$item[1]; $oneset = new stdClass(); $oneset->title = $titleStr; if (is_array($inputStr)) { $oneset->input = $inputStr[0]; $oneset->help = $inputStr[1]; } else { $oneset->input = $inputStr; $oneset->help=''; } array_push($mainList,$oneset); } } if (isset($baseList['adv'])) { foreach ($baseList['adv'] as $item) { $titleStr = $item[0]; $inputStr = $item[1]; $oneset = new stdClass(); $oneset->title = $titleStr; if (is_array($inputStr)) { $oneset->input = $inputStr[0]; $oneset->help = $inputStr[1]; } else { $oneset->input = $inputStr; $oneset->help=''; } array_push($advList,$oneset); } } if (isset($fieldList['main'])) { foreach ($fieldList['main'] as $item) { $titleStr=$item[0]; $inputStr=$item[1]; $oneset = new stdClass(); $oneset->title = $titleStr; if (is_array($inputStr)) { $oneset->input = $inputStr[0]; $oneset->help = $inputStr[1]; } else { $oneset->input = $inputStr; $oneset->help=''; } array_push($mainList,$oneset); } } if (isset($fieldList['adv'])) { foreach ($fieldList['adv'] as $item) { $titleStr=$item[0]; $inputStr=$item[1]; $oneset = new stdClass(); $oneset->title = $titleStr; if (is_array($inputStr)) { $oneset->input = $inputStr[0]; $oneset->help = $inputStr[1]; } else { $oneset->input = $inputStr; $oneset->help=''; } array_push($advList,$oneset); } } $aefield->PostPopulateAdminForm($mainList, $advList); $mod->smarty->assign('mainList',$mainList); $mod->smarty->assign('advList',$advList); return $mod->ProcessTemplate('AddEditField.tpl'); } function MakeAlias($string, $isForm=false) { $string = trim(htmlspecialchars($string)); if ($isForm) { return strtolower($string); } else { return 'fb'.strtolower($string); } } function SwapFieldsByIndex($src_field_index, $dest_field_index) { $srcField = $this->GetFieldByIndex($src_field_index); $destField = $this->GetFieldByIndex($dest_field_index); $tmpOrderBy = $destField->GetOrder(); $destField->SetOrder($srcField->GetOrder()); $srcField->SetOrder($tmpOrderBy); //it seems this makes php4 go crazy fixed by reloading form before showing it again # $this->Fields[$dest_field_index] = $srcField; # $this->Fields[$src_field_index] = $destField; $srcField->Store(); $destField->Store(); } function &GetFields() { return $this->Fields; } function &GetFieldById($field_id) { $index = -1; $ret = false; for ($i=0;$i
Fields);$i++) { if ($this->Fields[$i]->GetId() == $field_id) { $index = $i; } } if ($index != -1) { $ret = $this->Fields[$index]; } return $ret; } function &GetFieldByIndex($field_index) { return $this->Fields[$field_index]; } function GetFieldIndexFromId($field_id) { $index = -1; for ($i=0;$i
Fields);$i++) { if ($this->Fields[$i]->GetId() == $field_id) { $index = $i; } } return $index; } function DefaultTemplate() { return file_get_contents(dirname(__FILE__).'/../templates/RenderFormDefault.tpl'); } function DeleteField($field_id) { $index = $this->GetFieldIndexFromId($field_id); if ($index != -1) { $this->Fields[$index]->Delete(); array_splice($this->Fields,$index,1); } } function ResetFields() { for($i=0;$i
Fields);$i++) { $this->Fields[$i]->ResetValue(); } } function LoadResponse($response_id) { $mod = $this->module_ptr; $db = $this->module_ptr->dbHandle; $oneset = new StdClass(); $res = $db->GetOne('SELECT response, form_id FROM '.cms_db_prefix(). 'module_fb_formbrowser WHERE fbr_id=?', array($response_id)); if ($res && $row=$res->FetchRow()) { $oneset->xml = $row['response']; $oneset->form_id = $row['form_id']; } if ($oneset->form_id != $this->GetId()) { return false; } $fbField = $this->GetFormBrowserField(); if ($fbField == false) { // error handling goes here. echo($mod->Lang('error_has_no_fb_field')); } $mod->HandleResponseFromXML($fbField, $oneset); list($fnames, $aliases, $vals) = $mod->ParseResponseXML($oneset->xml, false); $this->ResetFields(); foreach ($vals as $id=>$val) { //error_log("setting value of field ".$id." to be ".$val); $index = $this->GetFieldIndexFromId($id); if($index != -1 && is_object($this->Fields[$index]) ) { $this->Fields[$index]->SetValue($val); } } return true; } function GetFormBrowserField() { $fields = $this->GetFields(); $fbField = false; foreach($fields as $thisField) { if ($thisField->GetFieldType() == 'DispositionFormBrowser') { $fbField = $thisField; } } if ($fbField == false) { // error handling goes here. return false; } return $fbField; } function LoadResponseValues(&$params) { $mod = $this->module_ptr; $db = $this->module_ptr->dbHandle; $oneset = new StdClass(); $form_id = -1; $res = $db->Execute('SELECT response, form_id FROM '.cms_db_prefix(). 'module_fb_formbrowser WHERE fbr_id=?', array($params['response_id'])); if ($res && $row=$res->FetchRow()) { $oneset->xml = $row['response']; $form_id = $row['form_id']; } // loaded a response -- at this point, we check that the response // is for the correct form_id! if ($form_id != $this->GetId()) { return false; } $fbField = $mod->GetFormBrowserField($form_id); if ($fbField == false) { // error handling goes here. echo($mod->Lang('error_has_no_fb_field')); } $mod->HandleResponseFromXML($fbField, $oneset); list($fnames, $aliases, $vals) = $mod->ParseResponseXML($oneset->xml, false); foreach ($vals as $id=>$val) { if (isset($params['fbrp__'.$id]) && ! is_array($params['fbrp__'.$id])) { $params['fbrp__'.$id] = array($params['fbrp__'.$id]); array_push($params['fbrp__'.$id], $val); } elseif (isset($params['fbrp__'.$id])) { array_push($params['fbrp__'.$id], $val); } else { $params['fbrp__'.$id] = $val; } } return true; } function LoadResponseValuesOld(&$params) { $db = $this->module_ptr->dbHandle; // loading a response -- at this point, we check that the response // is for the correct form_id! $sql = 'SELECT form_id FROM ' . cms_db_prefix(). 'module_fb_resp where resp_id=?'; if($result = $db->GetRow($sql, array($params['response_id']))) { if ($result['form_id'] != $this->GetId()) { return false; } $sql = 'SELECT * FROM '.cms_db_prefix(). 'module_fb_resp_val WHERE resp_id=? order by resp_val_id'; $dbresult = $db->Execute($sql, array($params['response_id'])); while ($dbresult && $row = $dbresult->FetchRow()) { // was '__' if (isset($params['fbrp__'.$row['field_id']]) && ! is_array($params['fbrp__'.$row['field_id']])) { $params['fbrp__'.$row['field_id']] = array($params['fbrp__'.$row['field_id']]); array_push($params['fbrp__'.$row['field_id']], $row['value']); } elseif (isset($params['fbrp__'.$row['field_id']])) { array_push($params['fbrp__'.$row['field_id']], $row['value']); } else { $params['fbrp__'.$row['field_id']] = $row['value']; } } } else { return false; } } function DeleteResponse($response_id) { $db = $this->module_ptr->dbHandle; $sql = 'DELETE FROM ' . cms_db_prefix(). 'module_fb_resp_val where resp_id=?'; $res = $db->Execute($sql, array($response_id)); $sql = 'DELETE FROM '.cms_db_prefix(). 'module_fb_resp where resp_id=?'; $res = $db->Execute($sql, array($response_id)); } function CheckResponse($form_id, $response_id, $code) { $db = $this->module_ptr->dbHandle; $sql = 'SELECT secret_code FROM ' . cms_db_prefix(). 'module_fb_formbrowser where form_id=? and resp_id=?'; if($result = $db->GetRow($sql, array($form_id,$response_id))) { if ($result['secret_code'] == $code) { return true; } } return false; } function StoreResponse($response_id=-1,$approver='',&$formBuilderDisposition) { $mod = $this->module_ptr; $db = $this->module_ptr->dbHandle; $fields = $this->GetFields(); $newrec = false; $crypt = false; $hash_fields = false; $sort_fields = array(); if (is_object($formBuilderDisposition) && ($formBuilderDisposition->GetFieldType()=='DispositionFormBrowser' || $formBuilderDisposition->GetFieldType()=='DispositionDatabase')) { $crypt = ($formBuilderDisposition->GetOption('crypt','0') == '1'); $hash_fields = ($formBuilderDisposition->GetOption('hash_sort','0') == '1'); for ($i=0;$i<5;$i++) { $sort_fields[$i] = $formBuilderDisposition->getSortFieldVal($i+1); } } if ($response_id == -1) { if ($formBuilderDisposition->GetOption('feu_bind','0') == '1') { $feu = $mod->GetModuleInstance('FrontEndUsers'); if ($feu == false) { debug_display("FAILED to instatiate FEU!"); return; } $feu_id = $feu->LoggedInId(); } else { $feu_id = -1; } $response_id = $db->GenID(cms_db_prefix(). 'module_fb_formbrowser_seq'); foreach ($fields as $thisField) { // set the response_id to be the attribute of the database disposition if (($thisField->GetFieldType() == 'DispositionDatabase')|| ($thisField->GetFieldType() == 'DispositionFormBrowser')) { $thisField->SetValue($response_id); } } $newrec = true; } else { $feu_id = $mod->getFEUIDFromResponseID($response_id); } $xml = $this->ResponseToXML(); if (! $crypt) { $this->StoreResponseXML( $response_id, $newrec, $approver, isset($sort_fields[0])?$sort_fields[0]:'', isset($sort_fields[1])?$sort_fields[1]:'', isset($sort_fields[2])?$sort_fields[2]:'', isset($sort_fields[3])?$sort_fields[3]:'', isset($sort_fields[4])?$sort_fields[4]:'', $feu_id, $xml); } elseif (! $hash_fields) { list($res, $xml) = $mod->crypt($xml,$formBuilderDisposition); if (! $res) { return array(false, $xml); } $this->StoreResponseXML( $response_id, $newrec, $approver, isset($sort_fields[0])?$sort_fields[0]:'', isset($sort_fields[1])?$sort_fields[1]:'', isset($sort_fields[2])?$sort_fields[2]:'', isset($sort_fields[3])?$sort_fields[3]:'', isset($sort_fields[4])?$sort_fields[4]:'', $feu_id, $xml); } else { list($res, $xml) = $mod->crypt($xml,$formBuilderDisposition); if (! $res) { return array(false, $xml); } $this->StoreResponseXML( $response_id, $newrec, $approver, isset($sort_fields[0])?$mod->getHashedSortFieldVal($sort_fields[0]):'', isset($sort_fields[1])?$mod->getHashedSortFieldVal($sort_fields[1]):'', isset($sort_fields[2])?$mod->getHashedSortFieldVal($sort_fields[2]):'', isset($sort_fields[3])?$mod->getHashedSortFieldVal($sort_fields[3]):'', isset($sort_fields[4])?$mod->getHashedSortFieldVal($sort_fields[4]):'', $feu_id, $xml); } return array(true,''); } function &ResponseToXML() { $xml = "\n"; $xml .= "
Id."\">\n"; foreach($this->Fields as $thisField) { $xml .= $thisField->ExportXML(true); } $xml .= "
\n"; return $xml; } function StoreResponseXML($response_id=-1,$newrec=false,$approver='',$sortfield1, $sortfield2,$sortfield3,$sortfield4,$sortfield5, $feu_id,$xml) { $db = $this->module_ptr->dbHandle; $secret_code = ''; if ($newrec) { // saving a new response $secret_code = substr(md5(session_id().'_'.time()),0,7); //$response_id = $db->GenID(cms_db_prefix(). 'module_fb_formbrowser_seq'); $sql = 'INSERT INTO ' . cms_db_prefix(). 'module_fb_formbrowser (fbr_id, form_id, submitted, secret_code, index_key_1, index_key_2, index_key_3, index_key_4, index_key_5, feuid, response) VALUES (?,?,?,?,?,?,?,?,?,?,?)'; $res = $db->Execute($sql, array($response_id, $this->GetId(), $this->clean_datetime($db->DBTimeStamp(time())), $secret_code, $sortfield1,$sortfield2,$sortfield3,$sortfield4,$sortfield5, $feu_id, $xml )); } else if ($approver != '') { $sql = 'UPDATE ' . cms_db_prefix(). 'module_fb_formbrowser set user_approved=? where fbr_id=?'; $res = $db->Execute($sql, array($this->clean_datetime($db->DBTimeStamp(time())),$response_id)); audit(-1, (isset($name)?$name:""), $this->module_ptr->Lang('user_approved_submission',array($response_id,$approver))); } if (! $newrec) { $sql = 'UPDATE ' . cms_db_prefix(). 'module_fb_formbrowser set index_key_1=?, index_key_2=?, index_key_3=?, index_key_4=?, index_key_5=?, response=? where fbr_id=?'; $res = $db->Execute($sql, array($sortfield1,$sortfield2,$sortfield3,$sortfield4,$sortfield5,$xml,$response_id)); } return array($response_id,$secret_code); } function clean_datetime($dt) { return substr($dt,1,strlen($dt)-2); } function ExportXML($exportValues = false) { $xmlstr = "\n"; $xmlstr .= "
Id."\"\n"; $xmlstr .= "\talias=\"".$this->Alias."\">\n"; $xmlstr .= "\t\t
Name."]]>
\n"; foreach ($this->Attrs as $thisAttrKey=>$thisAttrValue) { $xmlstr .= "\t\t
\n"; } foreach($this->Fields as $thisField) { $xmlstr .= $thisField->ExportXML($exportValues); } $xmlstr .= "
\n"; return $xmlstr; } function setFinishedFormSmarty($htmlemail=false) { $mod = $this->module_ptr; $theFields = $this->GetFields(); $unspec = $this->GetAttr('unspecified',$mod->Lang('unspecified')); $formInfo = array(); for($i=0;$i
DisplayInSubmission()) { $replVal = $theFields[$i]->GetHumanReadableValue(); if ($htmlemail) { // allow
as delimiter or in content $replVal = preg_replace('/
/i','|BR|',$replVal); $replVal = preg_replace('/[\n\r]+/','|BR|',$replVal); $replVal = htmlspecialchars($replVal); $replVal = preg_replace('/\|BR\|/','
',$replVal); } if ($replVal == '') { $replVal = $unspec; } } $mod->smarty->assign($theFields[$i]->GetVariableName(),$replVal); $mod->smarty->assign('fld_'.$theFields[$i]->GetId(),$replVal); $fldobj = $theFields[$i]->ExportObject(); $mod->smarty->assign($theFields[$i]->GetVariableName().'_obj',$fldobj); $mod->smarty->assign('fld_'.$theFields[$i]->GetId().'_obj',$fldobj); if ($theFields[$i]->GetAlias() != '') { $mod->smarty->assign($theFields[$i]->GetAlias(),$replVal); $mod->smarty->assign($theFields[$i]->GetAlias().'_obj',$fldobj); } } // general form details $mod->smarty->assign('sub_form_name',$this->GetName()); $mod->smarty->assign('sub_date',date('r')); $mod->smarty->assign('sub_host',$_SERVER['SERVER_NAME']); $mod->smarty->assign('sub_source_ip',$_SERVER['REMOTE_ADDR']); $mod->smarty->assign('sub_url',(empty($_SERVER['HTTP_REFERER'])?$mod->Lang('no_referrer_info'):$_SERVER['HTTP_REFERER'])); $mod->smarty->assign('fb_version',$mod->GetVersion()); $mod->smarty->assign('TAB',"\t"); } function manageFileUploads() { global $gCms; $theFields = $this->GetFields(); $mod = $this->module_ptr; for($i=0;$i
GetValue(); if( isset( $_FILES[$_id] ) && $_FILES[$_id]['size'] > 0 ) { $thisFile =& $_FILES[$_id]; if( $theFields[$i]->GetOption('sendto_uploads') ) { // we have a file we can send to the uploads $uploads = $mod->GetModuleInstance('Uploads'); if( !$uploads ) { // no uploads module audit(-1, $mod->GetName(), $mod->Lang('submit_error'),$mail->GetErrorInfo()); return array($res, $mod->Lang('nouploads_error')); } $parms = array(); $parms['input_author'] = $mod->Lang('anonymous'); $parms['input_summary'] = $mod->Lang('title_uploadmodule_summary'); $parms['category_id'] = $theFields[$i]->GetOption('uploads_category'); $parms['field_name'] = $_id; $res = $uploads->AttemptUpload(-1,$parms,-1); if( $res[0] == false ) { // failed upload kills the send. audit(-1, $mod->GetName(), $mod->Lang('submit_error',$res[1])); return array($res[0], $mod->Lang('uploads_error',$res[1])); } $uploads_destpage = $theFields[$i]->GetOption('uploads_destpage'); $url = $uploads->CreateLink (-1, 'getfile', $uploads_destpage, '', array ('upload_id' => $row['upload_id']), '', true); $theFields[$i]->ResetValue(); $theFields[$i]->SetValue($url); } else { // Handle the upload ourselves $src = $thisFile['tmp_name']; // this is safe[?] since we validated in FileUploadField's validate method. $dest = $gCms->config['uploads_path'].'/'.$thisFile['name']; if (! move_uploaded_file($src,$dest)) { audit(-1, $mod->GetName(), $mod->Lang('submit_error','')); return array(false, $mod->Lang('uploads_error','')); } else { $url = $gCms->config['uploads_url'].'/'.$thisFile['name']; $theFields[$i]->ResetValue(); $theFields[$i]->SetValue(array($dest,$url)); } } } } } return array(true,''); } } ?>