public function delete() { // Check for request forgeries JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); //GET CLIENT AND CLIENT TYPE $input = JFactory::getApplication()->input; $client = $input->get('client', '', 'STRING'); $client_form = explode('.', $client); $client_type = $client_form[1]; // Get items to remove from the request. $cid = JFactory::getApplication()->input->get('cid', array(), 'array'); if (!is_array($cid) || count($cid) < 1) { JLog::add(JText::_($this->text_prefix . '_NO_ITEM_SELECTED'), JLog::WARNING, 'jerror'); } else { // Get the model. $model = $this->getModel('fields'); // Make sure the item ids are integers jimport('joomla.utilities.arrayhelper'); JArrayHelper::toInteger($cid); // Remove the items. if ($model->deletefield($cid)) { $TjfieldsHelper = new TjfieldsHelper(); $data = array(); $data['client'] = $client; $data['client_type'] = $client_type; $TjfieldsHelper->generateXml($data); // $this->setMessage(JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid))); $ntext = $this->text_prefix . '_N_ITEMS_DELETED'; } else { $this->setMessage($model->getError()); } } $this->setMessage(JText::plural($ntext, count($cid))); $this->setRedirect('index.php?option=com_tjfields&view=fields&client=' . $client, false); }
public function save_option($post) { $table = $this->getTable(); $data = $post->get('jform', '', 'ARRAY'); //add clint type in data as it is not present in jform $data['client_type'] = $post->get('client_type', '', 'STRING'); $data['saveOption'] = 0; // use later to store later. //remove extra value which are not needed to save in the fields table $TjfieldsHelper = new TjfieldsHelper(); $data = $TjfieldsHelper->getFieldArrayFormatted($data); if ($table->save($data) === true) { $id = $table->id; } //check if name feild is unique $is_unique = $TjfieldsHelper->checkIfUniqueName($data['name']); //print_r($is_unique); die; if ($is_unique > 1) { //append id to the name $change_name_if_same = $TjfieldsHelper->changeNameIfNotUnique($data['name'], $id); } //save javascript functions. $js = $post->get('tjfieldsJs', '', 'ARRAY'); if (!empty($js)) { $jsfunctionSave = $this->jsfunctionSave($js, $id); } //end // if the field is inserted. if ($id) { //print_r($post); die('asd'); $options = $post->get('tjfields', '', 'ARRAY'); //print_r($options); die('asdasd11111'); if ($data['saveOption'] == 1) { //Firstly Delete Fields Options That are Removed $field_options = $TjfieldsHelper->getOptions($id); foreach ($field_options as $fokey => $fovalue) { if ($fovalue->id) { $fields_in_DB[] = $fovalue->id; } } foreach ($options as $key => $value) { if ($value['hiddenoptionid']) { $options_filled[] = $value['hiddenoptionid']; } } if ($fields_in_DB) { $diff_ids = array_diff($fields_in_DB, $options_filled); if (!empty($diff_ids)) { $this->delete_option($diff_ids); } } if (empty($options)) { $this->delete_option($fields_in_DB); } else { //save option fields. foreach ($options as $option) { if (!isset($option['hiddenoption'])) { $option['hiddenoption'] = 0; } $obj = new stdClass(); $obj->options = $option['optionname']; $obj->value = $option['optionvalue']; $obj->default_option = $option['hiddenoption']; $obj->field_id = $id; //if edit options if (isset($option['hiddenoptionid']) && !empty($option['hiddenoptionid'])) { if ($option['optionname'] != '' && $option['optionvalue'] != '') { $obj->id = $option['hiddenoptionid']; if (!$this->_db->updateObject('#__tjfields_options', $obj, 'id')) { echo $this->_db->stderr(); return false; } } } else { if ($option['optionname'] != '' && $option['optionvalue'] != '') { $obj->id = ''; if (!$this->_db->insertObject('#__tjfields_options', $obj, 'id')) { echo $this->_db->stderr(); return false; } } } } } //return true; } //create XML for the current client. $TjfieldsHelper->generateXml($data); return $id; } else { return false; } }