/** * Method to get the field input markup. * * @return string The field input markup. * @since 1.6 */ protected function getInput() { // Initialize variables. $html = array(); $options = array(); $doc = JFactory::getDocument(); $currentId = 0; // When use this field in view/reservationasset/edit $selectedId = (int) $this->form->getValue('category_id'); // When use this field in view/category/edit if (empty($selectedId)) { $selectedId = (int) $this->form->getValue('parent_id'); } // Set the default view name and format from the Request. $vName = JRequest::getWord('view', 'category'); // if we are editing a category, hide it in the parent_id category select list if ($vName == 'category') { $currentId = (int) $this->form->getValue('id'); } $options = SolidresHelper::getCategoryOptions($currentId); $html[] = JHtml::_('select.genericlist', $options, $this->name, null, 'value', 'text', $selectedId); return implode($html); }
</div> </th> <th> <select name="filter_published" class="inputbox" onchange="this.form.submit()"> <option value=""></option> <?php echo JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.state'), true); ?> </select> </th> <!-- <th> <select name="filter_category_id" class="inputbox" onchange="this.form.submit()"> <option value=""></option> <?php echo JHtml::_('select.options', SolidresHelper::getCategoryOptions(), 'value', 'text', $this->state->get('filter.category_id')); ?> </select> </th> --> <th></th> <th> <select name="filter_country_id" class="inputbox" onchange="this.form.submit()"> <?php echo JHtml::_('select.options', SolidresHelper::getCountryOptions(), 'value', 'text', $this->state->get('filter.country_id')); ?> </select> </th> <th> <select name="filter_access" class="inputbox" onchange="this.form.submit()"> <option value=""></option>
/** * Method to save a record. * * @param string $key The name of the primary key of the URL variable. * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). * * @return boolean True if successful, false otherwise. * @since 11.1 */ public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken('GET') or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $lang = JFactory::getLanguage(); $model = $this->getModel(); $table = $model->getTable(); $data = JRequest::getVar('jform', array(), 'post', 'array'); $checkin = property_exists($table, 'checked_out'); $context = "{$this->option}.edit.{$this->context}"; $task = $this->getTask(); // Determine the name of the primary key for the data. if (empty($key)) { $key = $table->getKeyName(); } // To avoid data collisions the urlVar may be different from the primary key. if (empty($urlVar)) { $urlVar = $key; } $recordId = JRequest::getInt($urlVar); $session = JFactory::getSession(); $registry = $session->get('registry'); if (!$this->checkEditId($context, $recordId)) { // Somehow the person just went to the form and tried to save it. We don't allow that. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $recordId)); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $this->getRedirectToListAppend(), false)); return false; } // Populate the row id from the session. $data[$key] = $recordId; // Access check. if (!$this->allowSave($data, $key)) { $this->setError(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED')); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $this->getRedirectToListAppend(), false)); return false; } // Validate the posted data. // Sometimes the form needs some posted data, such as for plugins and modules. $form = $model->getForm($data, false); if (!$form) { $app->enqueueMessage($model->getError(), 'error'); return false; } // Test whether the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { // Get the validation messages. $errors = $model->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); } else { $app->enqueueMessage($errors[$i], 'warning'); } } // Save the data in the session. $app->setUserState($context . '.data', $data); // Redirect back to the edit screen. $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId, $key), false)); return false; } // Attempt to save the data. if (!$model->save($validData)) { // Save the data in the session. $app->setUserState($context . '.data', $validData); // Redirect back to the edit screen. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError())); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId, $key), false)); return false; } // Save succeeded, so check-in the record. if ($checkin && $model->checkin($validData[$key]) === false) { // Save the data in the session. $app->setUserState($context . '.data', $validData); // Check-in failed, so go back to the record and display a notice. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError())); $this->setMessage($this->getError(), 'error'); $this->setRedirect('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId, $key)); return false; } $this->setMessage(JText::_(($lang->hasKey($this->text_prefix . ($recordId == 0 && $app->isSite() ? '_SUBMIT' : '') . '_SAVE_SUCCESS') ? $this->text_prefix : 'JLIB_APPLICATION') . ($recordId == 0 && $app->isSite() ? '_SUBMIT' : '') . '_SAVE_SUCCESS')); // Load saved record $savedRecordId = $model->getState($model->getName() . '.id'); $table->load($savedRecordId); $options = SolidresHelper::getCategoryOptions(); echo json_encode(array('saved' => 'true', 'category_select_html' => JHtmlSelect::options($options, 'value', 'text', $savedRecordId))); die(1); }