public function __call($ps_function, $pa_args) { $ps_function = strtolower($ps_function); if (!($va_form_info = $this->_checkForm($ps_function))) { return; } $this->view->setVar('t_subject', $t_subject = $this->pt_subject); $va_tags = $this->view->getTagList($va_form_info['view']); foreach ($va_tags as $vs_tag) { if (in_array($vs_tag, array('form', '/form', 'submit', 'reset'))) { continue; } $va_parse = caParseTagOptions($vs_tag); $vs_tag_proc = $va_parse['tag']; $va_opts = $va_parse['options']; if (($vs_default_value = caGetOption('default', $va_opts, null)) || ($vs_default_value = caGetOption($vs_tag_proc, $va_default_form_values, null))) { $va_default_form_values[$vs_tag_proc] = $vs_default_value; unset($va_opts['default']); } $vs_tag_val = null; switch (strtolower($vs_tag_proc)) { case 'submit': $this->view->setVar($vs_tag, "<a href='#' class='caContributeFormSubmit'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Submit')) . "</a>"); break; case 'reset': $this->view->setVar($vs_tag, "<a href='#' class='caContributeFormReset'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Reset')) . "</a>"); $vs_script = "<script type='text/javascript'>\n\tjQuery('.caContributeFormSubmit').bind('click', function() {\n\t\tjQuery('#caContribute').submit();\n\t\treturn false;\n\t});\n\tjQuery('.caContributeFormReset').bind('click', function() {\n\t\tjQuery('#caContribute').find('input[type!=\"hidden\"],textarea').val('');\n\t\tjQuery('#caContribute').find('select.caContributeBoolean').val('AND');\n\t\tjQuery('#caContribute').find('select').prop('selectedIndex', 0);\n\t\treturn false;\n\t});\n\tjQuery(document).ready(function() {\n\t\tvar f, defaultValues = " . json_encode($va_default_form_values) . ", defaultBooleans = " . json_encode($va_default_form_booleans) . ";\n\t\tfor (f in defaultValues) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('input[name=\"' + f_proc+ '\"], textarea[name=\"' + f_proc+ '\"], select[name=\"' + f_proc+ '\"]').each(function(k, v) {\n\t\t\t\tif (defaultValues[f][k]) { jQuery(v).val(defaultValues[f][k]); } \n\t\t\t});\n\t\t}\n\t\tfor (f in defaultBooleans) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('select[name=\"' + f_proc+ '\"].caContributeBoolean').each(function(k, v) {\n\t\t\t\tif (defaultBooleans[f][k]) { jQuery(v).val(defaultBooleans[f][k]); }\n\t\t\t});\n\t\t}\n\t});\n</script>\n"; break; default: if (preg_match("!^(.*):label\$!", $vs_tag_proc, $va_matches)) { $this->view->setVar($vs_tag, $vs_tag_val = $t_subject->getDisplayLabel($va_matches[1])); } else { $va_opts['asArrayElement'] = true; if ($vs_tag_val = $t_subject->htmlFormElementForSimpleForm($this->request, $vs_tag_proc, $va_opts)) { $this->view->setVar($vs_tag, $vs_tag_val); } $va_tmp = explode('.', $vs_tag_proc); if (($t_element = ca_metadata_elements::getInstance($va_tmp[1])) && $t_element->get('datatype') == 0) { if (is_array($va_elements = $t_element->getElementsInSet())) { foreach ($va_elements as $va_element) { if ($va_element['datatype'] > 0) { $va_form_elements[] = $va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code']; } } } break; } } if ($vs_tag_val) { $va_form_elements[] = $vs_tag_proc; } break; } } $this->view->setVar("form", caFormTag($this->request, "Send", 'caContribute', null, 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true))); $this->view->setVar("/form", $vs_script . caHTMLHiddenInput("_contributeFormName", array("value" => $ps_function)) . caHTMLHiddenInput("_formElements", array("value" => join(';', $va_form_elements))) . caHTMLHiddenInput("_contribute", array("value" => 1)) . "</form>"); $this->render($va_form_info['view']); }
/** * */ public function advanced() { $o_config = caGetSearchConfig(); $ps_function = strtolower($this->request->getActionExtra()); if (!($va_search_info = caGetInfoForAdvancedSearchType($ps_function))) { // invalid advanced search type – throw error die("Invalid advanced search type"); } $vs_class = $va_search_info['table']; $va_types = caGetOption('restrictToTypes', $va_search_info, array(), array('castTo' => 'array')); $this->opo_result_context = new ResultContext($this->request, $va_search_info['table'], $this->ops_find_type . '_advanced'); $this->opo_result_context->setAsLastFind(); MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . _t("Search %1", $va_search_info["displayName"])); $this->view->setVar('searchInfo', $va_search_info); $this->view->setVar('options', caGetOption('options', $va_search_info, array(), array('castTo' => 'array'))); $va_default_form_values = $this->opo_result_context->getParameter("pawtucketAdvancedSearchFormContent_{$ps_function}"); $va_default_form_booleans = $this->opo_result_context->getParameter("pawtucketAdvancedSearchFormBooleans_{$ps_function}"); $va_tags = $this->view->getTagList($va_search_info['view']); $t_subject = $this->request->datamodel->getInstanceByTableName($va_search_info['table'], true); $va_form_elements = array(); $vs_script = null; foreach ($va_tags as $vs_tag) { $va_parse = caParseTagOptions($vs_tag); $vs_tag_proc = $va_parse['tag']; $va_opts = $va_parse['options']; if (($vs_default_value = caGetOption('default', $va_opts, null)) || ($vs_default_value = caGetOption($vs_tag_proc, $va_default_form_values, null))) { $va_default_form_values[$vs_tag_proc] = $vs_default_value; unset($va_opts['default']); } $vs_tag_val = null; switch (strtolower($vs_tag_proc)) { case 'submit': $this->view->setVar($vs_tag, "<a href='#' class='caAdvancedSearchFormSubmit'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Submit')) . "</a>"); break; case 'reset': $this->view->setVar($vs_tag, "<a href='#' class='caAdvancedSearchFormReset'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Reset')) . "</a>"); $vs_script = "<script type='text/javascript'>\n\tjQuery('.caAdvancedSearchFormSubmit').bind('click', function() {\n\t\tjQuery('#caAdvancedSearch').submit();\n\t\treturn false;\n\t});\n\tjQuery('.caAdvancedSearchFormReset').bind('click', function() {\n\t\tjQuery('#caAdvancedSearch').find('input[type!=\"hidden\"],textarea').val('');\n\t\tjQuery('#caAdvancedSearch').find('select.caAdvancedSearchBoolean').val('AND');\n\t\tjQuery('#caAdvancedSearch').find('select').prop('selectedIndex', 0);\n\t\treturn false;\n\t});\n\tjQuery(document).ready(function() {\n\t\tvar f, defaultValues = " . json_encode($va_default_form_values) . ", defaultBooleans = " . json_encode($va_default_form_booleans) . ";\n\t\tfor (f in defaultValues) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('input[name=\"' + f_proc+ '\"], textarea[name=\"' + f_proc+ '\"], select[name=\"' + f_proc+ '\"]').each(function(k, v) {\n\t\t\t\tif (defaultValues[f][k]) { jQuery(v).val(defaultValues[f][k]); } \n\t\t\t});\n\t\t}\n\t\tfor (f in defaultBooleans) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('select[name=\"' + f_proc+ '\"].caAdvancedSearchBoolean').each(function(k, v) {\n\t\t\t\tif (defaultBooleans[f][k]) { jQuery(v).val(defaultBooleans[f][k]); }\n\t\t\t});\n\t\t}\n\t});\n</script>\n"; break; default: if (preg_match("!^(.*):label\$!", $vs_tag_proc, $va_matches)) { $this->view->setVar($vs_tag, $vs_tag_val = $t_subject->getDisplayLabel($va_matches[1])); } elseif (preg_match("!^(.*):boolean\$!", $vs_tag_proc, $va_matches)) { $this->view->setVar($vs_tag, caHTMLSelect($vs_tag_proc . '[]', array(_t('AND') => 'AND', _t('OR') => 'OR', 'AND NOT' => 'AND NOT'), array('class' => 'caAdvancedSearchBoolean'))); } else { $va_opts['asArrayElement'] = true; if (isset($va_opts['restrictToTypes']) && $va_opts['restrictToTypes'] && !is_array($va_opts['restrictToTypes'])) { $va_opts['restrictToTypes'] = explode(";", $va_opts['restrictToTypes']); } if ($vs_tag_val = $t_subject->htmlFormElementForSearch($this->request, $vs_tag_proc, $va_opts)) { $this->view->setVar($vs_tag, $vs_tag_val); } $va_tmp = explode('.', $vs_tag_proc); if (($t_element = ca_metadata_elements::getInstance($va_tmp[1])) && $t_element->get('datatype') == 0) { if (is_array($va_elements = $t_element->getElementsInSet())) { foreach ($va_elements as $va_element) { if ($va_element['datatype'] > 0) { $va_form_elements[] = $va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code']; } } } break; } } if ($vs_tag_val) { $va_form_elements[] = $vs_tag_proc; } break; } } $this->view->setVar("form", caFormTag($this->request, "{$ps_function}", 'caAdvancedSearch', null, 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true, 'submitOnReturn' => true))); $this->view->setVar("/form", $vs_script . caHTMLHiddenInput("_advancedFormName", array("value" => $ps_function)) . caHTMLHiddenInput("_formElements", array("value" => join(';', $va_form_elements))) . caHTMLHiddenInput("_advanced", array("value" => 1)) . "</form>"); $this->render($va_search_info['view']); }
/** * Generate form */ public function __call($ps_function, $pa_args) { $ps_function = strtolower($ps_function); if (!($va_form_info = $this->_checkForm($ps_function))) { return; } MetaTagManager::setWindowTitle(caGetOption('formTitle', $va_form_info, $this->request->config->get("app_display_name") . ": " . _t("Contribute"))); $this->view->setVar('t_subject', $t_subject = $this->pt_subject); $t_subject->set('type_id', $va_form_info['type']); $va_response_data = $this->view->getVar('response'); $va_form_data = caGetOption('formData', $va_response_data, null); $va_tags = $this->view->getTagList($va_form_info['form_view']); // Format to wrap field-level error messages in $vs_error_format = caGetOption('errorFormat', $va_form_info, '<div class="error">^ERRORS</div>'); $this->view->setVar('errors', is_array($va_response_data['errors']['_general_']) ? join("; ", $va_response_data['errors']['_general_']) : ""); foreach ($va_tags as $vs_tag) { if (in_array($vs_tag, array('form', '/form', 'submit', 'reset'))) { continue; } $va_parse = caParseTagOptions($vs_tag); $vs_tag_proc = $va_parse['tag']; $va_opts = $va_parse['options']; if (($vs_default_value = caGetOption('default', $va_opts, null)) || ($vs_default_value = caGetOption($vs_tag_proc, $va_default_form_values, null))) { $va_default_form_values[$vs_tag_proc] = $vs_default_value; unset($va_opts['default']); } $vs_tag_val = null; switch (strtolower($vs_tag_proc)) { case 'submit': $this->view->setVar($vs_tag, "<a href='#' class='caContributeFormSubmit'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Submit')) . "</a>"); break; case 'reset': $this->view->setVar($vs_tag, "<a href='#' class='caContributeFormReset'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Reset')) . "</a>"); $vs_script = "<script type='text/javascript'>\n\tjQuery(document).ready(function() {\n\t\tvar f, defaultValues = " . json_encode($va_default_form_values) . ", defaultBooleans = " . json_encode($va_default_form_booleans) . ";\n\t\tfor (f in defaultValues) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('input[name=\"' + f_proc+ '\"], textarea[name=\"' + f_proc+ '\"], select[name=\"' + f_proc+ '\"]').each(function(k, v) {\n\t\t\t\tif (defaultValues[f][k]) { jQuery(v).val(defaultValues[f][k]); } \n\t\t\t});\n\t\t}\n\t\tfor (f in defaultBooleans) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('select[name=\"' + f_proc+ '\"].caContributeBoolean').each(function(k, v) {\n\t\t\t\tif (defaultBooleans[f][k]) { jQuery(v).val(defaultBooleans[f][k]); }\n\t\t\t});\n\t\t}\n\t\t\n\t\tjQuery('.caContributeFormSubmit').bind('click', function(e) {\n\t\t\tjQuery('#ContributeForm').submit();\n\t\t\treturn false;\n\t\t});\n\t\tjQuery('.caContributeFormReset').bind('click', function(e) {\n\t\t\tjQuery('#ContributeForm').find('input[type!=\"hidden\"],textarea').val('');\n\t\t\tjQuery('#ContributeForm').find('select.caContributeBoolean').val('AND');\n\t\t\tjQuery('#ContributeForm').find('select').prop('selectedIndex', 0);\n\t\t\te.preventDefault();\n\t\t\treturn false;\n\t\t});\n\t});\n</script>\n"; break; default: if (preg_match("!^(.*):label\$!", $vs_tag_proc, $va_matches)) { $this->view->setVar($vs_tag, $vs_tag_val = $t_subject->getDisplayLabel($va_matches[1])); } elseif (preg_match("!^(.*):error\$!", $vs_tag_proc, $va_matches)) { if (is_array($va_response_data['errors'][$va_matches[1]]) && sizeof($va_response_data['errors'][$va_matches[1]])) { $vs_error_message = join("; ", $va_response_data['errors'][$va_matches[1]]); if ($vs_error_format) { $vs_error_message = str_replace("^ERRORS", $vs_error_message, $vs_error_format); } $this->view->setVar($vs_tag, $vs_error_message); } } else { if ($vs_tag_proc == 'errors') { break; } // skip general errors tag $va_opts['asArrayElement'] = true; $va_opts['IDNumberingConfig'] = $this->config; $va_vals = array(); $va_tmp = explode('.', $vs_tag_proc); if (($t_element = ca_metadata_elements::getInstance($va_tmp[1])) && $t_element->get('datatype') == 0) { if (is_array($va_elements = $t_element->getElementsInSet())) { foreach ($va_elements as $va_element) { if ($va_element['datatype'] > 0) { $va_form_elements[] = $vs_subfld = $va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code']; if (is_array($va_form_data[$va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code']])) { $va_vals[$va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code']] = array_shift($va_form_data[$va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code']]); } } } } } else { if (is_array($va_form_data[$vs_tag_proc])) { $va_vals[$vs_tag_proc] = array_shift($va_form_data[$vs_tag_proc]); } } $va_opts['values'] = $va_vals; if ($vs_tag_val = $t_subject->htmlFormElementForSimpleForm($this->request, $vs_tag_proc, $va_opts)) { $this->view->setVar($vs_tag, $vs_tag_val); } } if ($vs_tag_val) { $va_form_elements[] = $vs_tag_proc; } break; } } $this->view->setVar("form", caFormTag($this->request, "Send", 'ContributeForm', null, 'post', 'multipart/form-data', '_top', array('noTimestamp' => true, 'submitOnReturn' => true, 'disableUnsavedChangesWarning' => true))); $this->view->setVar("/form", $vs_script . caHTMLHiddenInput("_contributeFormName", array("value" => $ps_function)) . caHTMLHiddenInput("_formElements", array("value" => join(';', $va_form_elements))) . caHTMLHiddenInput("_contribute", array("value" => 1)) . "</form>"); $this->view->setVar('spam_protection', caGetOption('spam_protection', $va_form_info, false) ? 1 : 0); $this->view->setVar('terms_and_conditions', caGetOption('terms_and_conditions', $va_form_info, false)); $this->render($va_form_info['form_view']); }