function cacheXTPL($file, $cache_file, $preview_file = false) { global $beanList; //now if we have a backup_file lets use that instead of the original if ($preview_file) { $file = $preview_file; } if (!isset($the_module)) { $the_module = $_SESSION['studio']['module']; } $files = StudioParser::getFiles($the_module); $xtpl = $files[$_SESSION['studio']['selectedFileId']]['php_file']; $originalFile = $files[$_SESSION['studio']['selectedFileId']]['template_file']; $type = StudioParser::getFileType($files[$_SESSION['studio']['selectedFileId']]['type']); $buffer = sugar_file_get_contents($xtpl); $cache_file = create_cache_directory('studio/' . $file); $xtpl_cache = create_cache_directory('studio/' . $xtpl); $module = $this->workingModule; $form_string = "require_once('modules/" . $module . "/Forms.php');"; if ($type == 'edit' || $type == 'detail') { if (empty($_REQUEST['record'])) { $buffer = preg_replace('(\\$xtpl[\\ ]*=)', "\$focus->assign_display_fields('{$module}'); \$0", $buffer); } else { $buffer = preg_replace('(\\$xtpl[\\ ]*=)', "\$focus->retrieve('" . $_REQUEST['record'] . "');\n\$focus->assign_display_fields('{$module}');\n \$0", $buffer); } } $_REQUEST['query'] = true; if (substr_count($file, 'SearchForm') > 0) { $temp_xtpl = new XTemplate($file); if ($temp_xtpl->exists('advanced')) { global $current_language; $mods = return_module_language($current_language, 'DynamicLayout'); $mod = BeanFactory::getBean($module); $this->populateRequestFromBuffer($file); $mod->assign_display_fields($module); $buffer = str_replace(array('echo $lv->display();', '$search_form->parse("advanced");', '$search_form->out("advanced");', '$search_form->parse("main");', '$search_form->out("main");'), '', $buffer); $buffer = str_replace('echo get_form_footer();', '$search_form->parse("main");' . "\n" . '$search_form->out("main");' . "\necho '<br><b>" . translate('LBL_ADVANCED', 'DynamicLayout') . "</b><br>';" . '$search_form->parse("advanced");' . "\n" . '$search_form->out("advanced");' . "\n \$sugar_config['list_max_entries_per_page'] = 1;", $buffer); } } else { if ($type == 'detail') { $buffer = str_replace('header(', 'if(false) header(', $buffer); } } $buffer = str_replace($originalFile, $cache_file, $buffer); $buffer = "<?php\n\$sugar_config['list_max_entries_per_page'] = 1;\n ?>" . $buffer; $buffer = str_replace($form_string, '', $buffer); $buffer = $this->disableInputs($buffer); $xtpl_fp_cache = sugar_fopen($xtpl_cache, 'w'); fwrite($xtpl_fp_cache, $buffer); fclose($xtpl_fp_cache); return $xtpl_cache; }
$required_opt = !empty($_REQUEST['required_option']) ? 'required' : 'optional'; $id = !empty($_REQUEST['id']) ? $_REQUEST['id'] : ''; if (empty($id)) { $custom_fields->addField($_REQUEST['name'], $label, $_REQUEST['data_type'], $max_size, $required_opt, $default_value, $ext1, $ext2, $ext3, $audit_value, $mass_update, $ext4, $help, $_REQUEST['duplicate_merge']); } else { $values = array('max_size' => $max_size, 'required_option' => $required_opt, 'default_value' => $default_value, 'audited' => $audit_value, 'mass_update' => $mass_update, 'ext4' => $ext4, 'help' => $help, 'duplicate_merge' => $_REQUEST['duplicate_merge']); if (!empty($ext1)) { $values['ext1'] = $ext1; } $custom_fields->updateField($id, $values); } if (!empty($_REQUEST['popup'])) { ob_clean(); $name = $custom_fields->getDBName($_REQUEST['name']); $files = StudioParser::getFiles($module); $view = StudioParser::getFileType($files[$_SESSION['studio']['selectedFileId']]['type']); $custom_fields->avail_fields = array(); $custom_fields->getAvailableFields(true); $field = $custom_fields->getField($name); $custom_fields->bean->field_defs[$name] = $field->get_field_def(); $custom_fields->bean->field_defs[$name]['type'] = $custom_fields->bean->field_defs[$name]['custom_type']; $html = $custom_fields->getAllBeanFieldsView($view, 'html'); $html = $html[$name]; $string = '[NAME]' . $name . '[TYPE]' . $html['fieldType'] . '[LABEL]' . translate(str_replace(array('{', '}', 'MOD.', 'mod.', 'APP.', 'app.'), '', $html['label']), $module); $string .= '[DATA]' . $html['html']; echo str_replace(array('{', '}', 'MOD.', 'mod.', 'APP.', 'app.'), '', $string); sugar_cleanup(true); } else { header("Location: index.php?module=Studio&action=wizard&wizard=EditCustomFieldsWizard&option=ViewCustomFields"); sugar_cleanup(true); }