/** * Outputs a pair of linked selects, for picking a prebuilt form from the library. The first select is for picking a form * category and the second select is populated by AJAX for picking the actual form. * @param array $options Options array with the following possibilities:<ul> * <li><b>form</b><br/> * Optional. The name of the form to select as a default value.</li> * <li><b>includeOutputDiv</b><br/> * Set to true to generate a div after the controls which will receive the form parameter * controls when a form is selected.</li> * <li><b>needWebsiteInputs</b><br/> * Defaults to false. In this state, the website ID and password controls are not displayed * when both the values are already specified, though hidden inputs are put into the form. * When set to true, the website ID and password input controls are always included in the form output. * </li> * </ul> */ public static function prebuilt_form_picker($options) { require_once 'data_entry_helper.php'; form_helper::add_resource('jquery_ui'); $path = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . self::relative_client_helper_path(); $r = ''; if (!($dir = opendir($path . 'prebuilt_forms/'))) { throw new Exception('Cannot open path to prebuilt form library.'); } while (false !== ($file = readdir($dir))) { $parts = explode('.', $file); if ($file != "." && $file != ".." && strtolower($parts[count($parts) - 1]) == 'php') { require_once $path . 'prebuilt_forms/' . $file; $file_tokens = explode('.', $file); ob_start(); if (is_callable(array('iform_' . $file_tokens[0], 'get_' . $file_tokens[0] . '_definition'))) { $definition = call_user_func(array('iform_' . $file_tokens[0], 'get_' . $file_tokens[0] . '_definition')); $definition['title'] = lang::get($definition['title']); $forms[$definition['category']][$file_tokens[0]] = $definition; if (isset($options['form']) && $file_tokens[0] == $options['form']) { $defaultCategory = $definition['category']; } } elseif (is_callable(array('iform_' . $file_tokens[0], 'get_title'))) { $title = call_user_func(array('iform_' . $file_tokens[0], 'get_title')); $forms['Miscellaneous'][$file_tokens[0]] = array('title' => $title); if (isset($options['form']) && $file_tokens[0] == $options['form']) { $defaultCategory = 'Miscellaneous'; } } ob_end_clean(); } } if (isset($defaultCategory)) { $availableForms = array(); foreach ($forms[$defaultCategory] as $form => $def) { $availableForms[$form] = $def['title']; } } else { $defaultCategory = ''; $availableForms = array('' => '<Please select a category first>'); } closedir($dir); // makes an assoc array from the categories. $categories = array_merge(array('' => '<Please select>'), array_combine(array_keys($forms), array_keys($forms))); // translate categories foreach ($categories as $key => &$value) { $value = lang::get($value); } asort($categories); if (isset($options['needWebsiteInputs']) && !$options['needWebsiteInputs'] && !empty($options['website_id']) && !empty($options['password'])) { $r .= '<input type="hidden" id="website_id" name="website_id" value="' . $options['website_id'] . '">'; $r .= '<input type="hidden" id="password" name="password" value="' . $options['password'] . '">'; } else { $r .= data_entry_helper::text_input(array('label' => lang::get('Website ID'), 'fieldname' => 'website_id', 'helpText' => lang::get('Enter the ID of the website record on the Warehouse you are using.'), 'default' => isset($options['website_id']) ? $options['website_id'] : '')); $r .= data_entry_helper::text_input(array('label' => lang::get('Password'), 'fieldname' => 'password', 'helpText' => lang::get('Enter the password for the website record on the Warehouse you are using.'), 'default' => isset($options['password']) ? $options['password'] : '')); } $r .= data_entry_helper::select(array('id' => 'form-category-picker', 'label' => lang::get('Select Form Category'), 'helpText' => lang::get('Select the form category pick a form from.'), 'lookupValues' => $categories, 'default' => $defaultCategory)); $r .= data_entry_helper::select(array('id' => 'form-picker', 'fieldname' => 'iform', 'label' => lang::get('Select Form'), 'helpText' => lang::get('Select the Indicia form you want to use.'), 'lookupValues' => $availableForms, 'default' => isset($options['form']) ? $options['form'] : '')); // div for the form instructions $details = ''; if (isset($options['form'])) { if (isset($forms[$defaultCategory][$options['form']]['description'])) { $details .= '<p>' . $forms[$defaultCategory][$options['form']]['description'] . '</p>'; } if (isset($forms[$defaultCategory][$options['form']]['helpLink'])) { $details .= '<p><a href="' . $forms[$defaultCategory][$options['form']]['helpLink'] . '">Find out more...</a></p>'; } if ($details !== '') { $details = "<div class=\"ui-state-highlight ui-corner-all page-notice\">{$details}</div>"; } } $r .= "<div id=\"form-def\">{$details}</div>\n"; $r .= '<input type="button" value="' . lang::get('Load Settings Form') . '" id="load-params" disabled="disabled" />'; if (isset($options['includeOutputDivs']) && $options['includeOutputDivs']) { $r .= '<div id="form-params"></div>'; } self::add_form_picker_js($forms); return $r; }