/** * Gallery content modification form */ function gallery_form() { global $ssc_database, $ssc_site_url; if (isset($_GET['param'][0])) { $galID = (int) array_shift($_GET['param']); } if (!empty($_POST['form-id']) && $_POST['form-id'] == 'gallery_form') { $data = new stdClass(); $data->name = empty($_POST['name']) ? '' : $_POST['name']; $data->descr = empty($_POST['desc']) ? '' : $_POST['desc']; $data->visible = empty($_POST['vis']) ? 0 : (int) $_POST['vis']; $data->path = empty($_POST['url']) ? '' : $_POST['url']; } elseif ($galID > 0) { $result = $ssc_database->query("SELECT path, title name, description descr, visible FROM #__gallery g \n\t\t\tLEFT JOIN #__handler h ON h.id = g.id WHERE h.id = %d LIMIT 1", $galID); if (!$result || !($data = $ssc_database->fetch_object($result))) { // Something borked $data = new stdClass(); $data->name = ''; $data->descr = ''; $data->visible = 1; $data->path = ''; } } else { // New $data = new stdClass(); $data->name = ''; $data->descr = ''; $data->visible = 1; $data->path = ''; $galID = 0; } $form = array('#action' => '', '#method' => 'post', '#attributes' => array('enctype' => 'multipart/form-data')); $fieldset =& $form['details']; $fieldset = array('#type' => 'fieldset', '#title' => t('Gallery details'), '#parent' => true); $fieldset['name'] = array('#title' => t('Gallery name'), '#description' => t('Name to display at top of the page'), '#type' => 'text', '#required' => true, '#value' => $data->name); $fieldset['url'] = array('#type' => 'text', '#value' => $data->path, '#title' => t('Path to gallery'), '#required' => true, '#description' => t('Path that should be used to access the gallery. Should exclude \'!site\'', array('!site' => $ssc_site_url . '/'))); $fieldset['desc'] = array('#type' => 'textarea', '#title' => t('Gallery description'), '#description' => t('Short optional description relating to the gallery. Plain-text only!'), '#value' => $data->descr); $fieldset['vis'] = array('#type' => 'checkbox', '#title' => t('Enabled'), '#description' => t('If checked, the gallery will be enabled for viewing'), '#value' => 1, '#checked' => $data->visible); $fieldset['gid'] = array('#type' => 'hidden', '#value' => $galID); $fieldset['sub'] = array('#type' => 'submit', '#value' => t('Save changes')); $fieldset['rev'] = array('#type' => 'reset', '#value' => t('Revert changes')); // Return only first half for new gallery if ($galID == 0) { return $form; } $fieldset =& $form['upload']; $fieldset = array('#type' => 'fieldset', '#title' => t('Upload photos'), '#parent' => true); $fieldset['single'] = array('#type' => 'file', '#title' => t('Upload single image'), '#description' => t('Add a single image to the gallery. Image will be automatically resized as needed.')); $fieldset['sub'] = array('#type' => 'submit', '#value' => t('Save and upload')); $result = $ssc_database->query("SELECT id, caption, mid FROM #__gallery_content WHERE gallery_id = %d", $galID); if (!$result) { return $form; } $fieldset =& $form['content']; $fieldset = array('#type' => 'fieldset', '#title' => t('Gallery content'), '#parent' => true); // Generate caption listing $input = array('#type' => 'text', '#maxlength' => 150); $input_border = array('#title' => t('Caption'), '#description' => t('Short caption for the image')); while ($data = $ssc_database->fetch_object($result)) { $input['#name'] = "item[{$data->id}][cap]"; $input['#value'] = $data->caption; $input_border['#value'] = theme_render_input($input); $out = "<div class=\"form-img\"><img src=\"{$ssc_site_url}/images/gallery/{$galID}/{$data->id}_t\" alt=\"\" />"; $out .= theme_render_form_element($input_border); $out .= '</div>'; $fieldset["item{$data->id}"] = array('#type' => '', '#value' => $out); } return $form; }
/** * Render the dropdown box for a form * @param array $structure Element structure * @return string Markup representing the select box */ function theme_render_select($structure) { $out = '<select name="' . $structure['#name'] . '"' . (isset($structure['#id']) ? ' id="' . $structure['#id'] . '"' : '') . '>'; // Get values $sel = empty($structure['#selected']) ? null : $structure['#selected']; foreach ($structure['#value'] as $val => $name) { $out .= "\n<option value=\"{$val}\"" . ($sel == $val ? ' selected="selected" ' : '') . ">{$name}</option>"; } $out .= '</select>'; if (!empty($structure['#elementonly'])) { return $out; } $structure['#value'] = $out; $out = theme_render_form_element($structure); return $out; }
/** * Form processing * @param string $form_name Name of the form in the form of 'module_formname' representing the * function to call to generate said form * function ssc_form_handler($form_name){ //return ssc_generate_html($form_name()); } /** * Display a structured array of html elements * @param array $structure Array of html elements and element properties */ function ssc_generate_html(&$structure) { $out = ''; // Get keys $keys = array_keys($structure); rsort($keys); if (isset($structure['#parent'])) { // Generate the field content foreach ($structure as $tag => $value) { if ($tag[0] == '#') { continue; } $value['#name'] = $tag; if (empty($value['#id'])) { $value['#id'] = $structure['#formname'] . "-{$tag}"; } $value['#formname'] = $structure['#formname']; $out .= ssc_generate_html($value); unset($structure[$tag]); } $structure['#value'] = $out; $out = ''; } $hook = 'theme_render_' . $structure['#type']; if (function_exists($hook)) { $out = $hook($structure); } else { switch ($structure['#type']) { case 'text': case 'password': case 'file': $structure['#value'] = theme_render_input($structure); $out = theme_render_form_element($structure); break; case 'hidden': case 'submit': case 'reset': $out = theme_render_input($structure); break; default: $out = $structure['#value']; } } return $out; }