/** * Save the pacakge * * @param array $data jform data * * @return bool */ public function save($data) { $canvas = $data['params']['canvas']; $canvas = json_decode($canvas); $o = new stdClass(); if (is_null($canvas)) { JError::raiseError(E_ERROR, 'malformed json package object'); } $o->canvas = $canvas; $data['params'] = json_encode($o); $return = parent::save($data); $data['id'] = $this->getState($this->getName() . '.id'); $packageId = $this->getState($this->getName() . '.id'); $blocks = is_object($o->canvas) ? $o->canvas->blocks : array(); foreach ($blocks as $fullkey => $ids) { $key = FabrikString::rtrimword($fullkey, 's'); $tbl = JString::ucfirst($key); foreach ($ids as $id) { $item = $this->getTable($tbl); $item->load($id); if ($key == 'list') { // Also assign the form to the package $form = $this->getTable('Form'); $form->load($item->form_id); if (!in_array($form->id, $blocks->form)) { $o->canvas->blocks->form[] = $item->id; } } } } // Resave the data to update blocks $data['params'] = json_encode($o); $return = parent::save($data); return $return; }
/** * Save the package * * @param array $data jform data * * @return bool */ public function save($data) { $canvas = $data['params']['canvas']; $o = new stdClass(); $o->blocks = new stdClass(); $o->blocks->list = array(); $o->blocks->form = array(); $app = JFactory::getApplication(); $input = $app->input; $blocks = $input->get('blocks', array(), 'array'); foreach ($blocks as $type => $values) { $o->blocks->{$type} = $values; } foreach ($blocks as $type => $values) { $tbl = JString::ucfirst($type); foreach ($values as $id) { $item = $this->getTable($tbl); $item->load($id); if ($type == 'list') { // Also assign the form to the package $form = $this->getTable('Form'); $form->load($item->form_id); if (!in_array($form->id, $o->blocks->form)) { $o->blocks->form[] = $form->id; } } } } // Resave the data to update blocks $data['params']['canvas'] = $o; $data['params'] = json_encode($data['params']); $return = parent::save($data); return $return; }
/** * Save the form * * @param array $data posted jForm data * * @return bool */ public function save($data) { $input = $this->app->input; $jForm = $input->get('jform', array(), 'array'); $data['params']['plugins'] = (array) FArrayHelper::getValue($jForm, 'plugin'); $data['params']['plugin_locations'] = (array) FArrayHelper::getValue($jForm, 'plugin_locations'); $data['params']['plugin_events'] = (array) FArrayHelper::getValue($jForm, 'plugin_events'); $data['params']['plugin_description'] = (array) FArrayHelper::getValue($jForm, 'plugin_description'); /** * Move back into the main data array some values we are rendering as * params (did that for ease of rendering admin output) */ $opts = array('reset_button_label', 'submit_button_label'); foreach ($opts as $opt) { $data[$opt] = $data['params'][$opt]; } $tmpName = FArrayHelper::getValue($data, 'db_table_name'); unset($data['db_table_name']); $return = parent::save($data); if ($return) { $data['db_table_name'] = $tmpName; $this->saveFormGroups($data); } parent::cleanCache('com_fabrik'); return $return; }
/** * save the form * @param array $data */ function save($data) { $post = JRequest::get('post'); $data['params']['plugins'] = (array)JArrayHelper::getValue($post['jform'], 'plugin'); $data['params']['plugin_locations'] = (array)JArrayHelper::getValue($post['jform'], 'plugin_locations'); $data['params']['plugin_events'] = (array)JArrayHelper::getValue($post['jform'], 'plugin_events'); // move back into the main data array some values we are rendering as // params (did that for ease of rendering admin output) $opts = array('reset_button_label', 'submit_button_label'); foreach ($opts as $opt) { $data[$opt] = $data['params'][$opt]; } $tmpName = JArrayHelper::getValue($data, 'db_table_name'); unset($data['db_table_name']); $return = parent::save($data); if ($return) { $data['db_table_name'] = $tmpName; $this->saveFormGroups($data); } return $return; }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success, False on error. */ public function save($data) { $config = JComponentHelper::getParams('com_fabrik'); if ($config->get('fbConf_wysiwyg_label', 0) == 0) { // Ensure the data is in the same format as when saved by the wysiwyg element e.g. < becomes < $data['label'] = htmlspecialchars($data['label']); } jimport('joomla.utilities.date'); $input = $this->app->input; $new = $data['id'] == 0 ? true : false; $params = $data['params']; $data['name'] = FabrikString::iclean($data['name']); $name = $data['name']; $params['validations'] = FArrayHelper::getValue($data, 'validationrule', array()); $elementModel = $this->getElementPluginModel($data); $elementModel->getElement()->bind($data); $origId = $input->getInt('id'); $row = $elementModel->getElement(); if ($new) { // Have to forcefully set group id otherwise listmodel id is blank $elementModel->getElement()->group_id = $data['group_id']; } $listModel = $elementModel->getListModel(); $item = $listModel->getTable(); // Are we updating the name of the primary key element? if ($row->name === FabrikString::shortColName($item->db_primary_key)) { if ($name !== $row->name) { // Yes we are so update the table $item->db_primary_key = str_replace($row->name, $name, $item->db_primary_key); $item->store(); } } $jsons = array('sub_values', 'sub_labels', 'sub_initial_selection'); foreach ($jsons as $json) { if (array_key_exists($json, $data)) { $data[$json] = json_encode($data[$json]); } } // Only update the element name if we can alter existing columns, otherwise the name and field name become out of sync $data['name'] = $listModel->canAlterFields() || $new || $listModel->noTable() ? $name : $input->get('name_orig', ''); $ar = array('published', 'use_in_page_title', 'show_in_list_summary', 'link_to_detail', 'can_order', 'filter_exact_match'); foreach ($ar as $a) { if (!array_key_exists($a, $data)) { $data[$a] = 0; } } /** * $$$ rob - test for change in element type * (eg if changing from db join to field we need to remove the join * entry from the #__{package}_joins table */ $elementModel->beforeSave($row); // Unlink linked elements if ($input->get('unlink') == 'on') { $data['parent_id'] = 0; } $dateNow = new JDate(); if ($row->id != 0) { $data['modified'] = $dateNow->toSql(); $data['modified_by'] = $this->user->get('id'); } else { $data['created'] = $dateNow->toSql(); $data['created_by'] = $this->user->get('id'); $data['created_by_alias'] = $this->user->get('username'); } /** * $$$ hugh * This insane chunk of code is needed because the validation rule params are not in sequential, * completely indexed arrays. What we have is single item arrays, with specific numeric * keys, like foo-something[0], bar-otherthing[2], etc. And if you json_encode an array with incomplete * or out of sequence numeric indexes, it encodes it as an object instead of an array. Which means the first * validation plugin will encode as an array, as it's params are single [0] index, and the rest as objects. * This foobars things, as we then don't know if validation params are arrays or objects! * * One option would be to modify every validation, and test every param we use, and if necessary convert it, * but that would be a major pain in the ass. * * So ... we need to fill in the blanks in the arrays, and ksort them. But, we need to know the param names * for each validation. But as they are just stuck in with the rest of the element params, there is no easy * way of knowing which are validation params and which are element params. * * So ... we need to load the validation objects, then load the XML file for each one, and iterate through * the fieldsets! Well, that's the only way I could come up with doing it. Hopefully Rob can come up with * a quicker and simpler way of doing this! */ $validations = FArrayHelper::getValue($params['validations'], 'plugin', array()); $num_validations = count($validations); $validation_plugins = $this->getValidations($elementModel, $validations); foreach ($validation_plugins as $plugin) { $plugin_form = $plugin->getJForm(); JForm::addFormPath(JPATH_SITE . '/plugins/fabrik_validationrule/' . $plugin->get('pluginName')); $xmlFile = JPATH_SITE . '/plugins/fabrik_validationrule/' . $plugin->get('pluginName') . '/forms/fields.xml'; $xml = $plugin->jform->loadFile($xmlFile, false); foreach ($plugin_form->getFieldsets() as $fieldset) { foreach ($plugin_form->getFieldset($fieldset->name) as $field) { if (isset($params[$field->fieldname])) { if (is_array($params[$field->fieldname])) { for ($x = 0; $x < $num_validations; $x++) { if (!array_key_exists($x, $params[$field->fieldname])) { $params[$field->fieldname][$x] = ''; } } ksort($params[$field->fieldname]); } } } } } $data['params'] = json_encode($params); $row->params = $data['params']; $cond = 'group_id = ' . (int) $row->group_id; if ($new) { $data['ordering'] = $row->getNextOrder($cond); } $row->reorder($cond); /** * $$$ hugh - shouldn't updateChildIds() happen AFTER we save the main row? * Same place we do updateJavascript()? */ $this->updateChildIds($row); $elementModel->getElement()->bind($data); $origName = $input->get('name_orig', ''); list($update, $q, $oldName, $newdesc, $origDesc) = $listModel->shouldUpdateElement($elementModel, $origName); if ($update && $input->get('task') !== 'save2copy') { $origPlugin = $input->get('plugin_orig'); $prefix = $this->config->get('dbprefix'); $tableName = $listModel->getTable()->db_table_name; $hasPrefix = strstr($tableName, $prefix) === false ? false : true; $tableName = str_replace($prefix, '#__', $tableName); if (in_array($tableName, $this->core)) { $this->app->enqueueMessage(FText::_('COM_FABRIK_WARNING_UPDATE_CORE_TABLE'), 'notice'); } else { if ($hasPrefix) { $this->app->enqueueMessage(FText::_('COM_FABRIK_WARNING_UPDATE_TABLE_WITH_PREFIX'), 'notice'); } } $this->app->setUserState('com_fabrik.confirmUpdate', 1); $this->app->setUserState('com_fabrik.plugin_orig', $origPlugin); $this->app->setUserState('com_fabrik.q', $q); $this->app->setUserState('com_fabrik.newdesc', $newdesc); $this->app->setUserState('com_fabrik.origDesc', $origDesc); $this->app->setUserState('com_fabrik.origplugin', $origPlugin); $this->app->setUserState('com_fabrik.oldname', $oldName); $this->app->setUserState('com_fabrik.newname', $data['name']); $this->app->setUserState('com_fabrik.origtask', $input->get('task')); $this->app->setUserState('com_fabrik.plugin', $data['plugin']); $task = $input->get('task'); $url = 'index.php?option=com_fabrik&view=element&layout=confirmupdate&id=' . (int) $origId . '&origplugin=' . $origPlugin . '&origtask=' . $task . '&plugin=' . $row->plugin; $this->app->setUserState('com_fabrik.redirect', $url); } else { $this->app->setUserState('com_fabrik.confirmUpdate', 0); } if ((int) $listModel->getTable()->id !== 0) { $this->updateIndexes($elementModel, $listModel, $row); } $return = parent::save($data); if ($return) { $this->updateJavascript($data); $elementModel->setId($this->getState($this->getName() . '.id')); $row->id = $elementModel->getId(); $data['id'] = $row->id; $this->createRepeatElement($elementModel, $row); // If new, check if the element's db table is used by other tables and if so add the element to each of those tables' groups if ($new) { $this->addElementToOtherDbTables($elementModel, $row); } if (!$elementModel->onSave($data)) { $this->setError(FText::_('COM_FABRIK_ERROR_SAVING_ELEMENT_PLUGIN_OPTIONS')); return false; } } parent::cleanCache('com_fabrik'); return $return; /** * used for prefab * return $elementModel; */ }
/** * Save the cron job - merging plugin parameters * * @param array $data The form data. * * @return boolean True on success, False on error. */ public function save($data) { if (FArrayHelper::getValue($data, 'lastrun') == '') { $date = JFactory::getDate(); $data['lastrun'] = $date->toSql(); } $data['params'] = json_encode($data['params']); return parent::save($data); }
/** * Save the connection- test first if its valid * if it is remove the session instance of the connection then call parent save * * @param array $data connection data * * @return boolean True on success, False on error. */ public function save($data) { $model = JModelLegacy::getInstance('Connection', 'FabrikFEModel'); $model->setId($data['id']); $crypt = FabrikWorker::getCrypt(); $params = new stdClass(); $params->encryptedPw = true; $data['params'] = json_encode($params); $data['password'] = $crypt->encrypt($data['password']); // $$$ hugh TESTING REMOVE!!!! // $$$ Felikat - Not sure what you were testing but it broke stuff! // unset($data['password']); $options = $model->getConnectionOptions(JArrayHelper::toObject($data)); $db = $model->getDriverInstance($options); $key = 'fabrik.connection.' . $data['id']; /** * erm yeah will remove the session connection for the admin user, but not any other user whose already using the site * would need to clear out the session table i think - but that would then log out all users. */ $this->session->clear($key); return parent::save($data); }
/** * (non-PHPdoc) * @see JModelAdmin::save() */ public function save($data) { if ($data['id'] == 0) { $user = JFactory::getUser(); $data['created_by'] = $user->get('id'); $data['created_by_alias'] = $user->get('username'); $data['created'] = JFactory::getDate()->toMySQL(); } $makeJoin = ($data['params']['repeat_group_button'] == 1); if ($makeJoin) { $data['is_join'] = 1; } $data['params'] = json_encode($data['params']); $return = parent::save($data); $data['id'] = $this->getState($this->getName().'.id'); if ($return) { $this->makeFormGroup($data); if ($makeJoin) { $return = $this->makeJoinedGroup($data); //update for the is_join change if ($return) { $return = parent::save($data); } } } return $return; }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success, False on error. */ public function save($data) { if ($data['id'] == 0) { $user = JFactory::getUser(); $data['created_by'] = $user->get('id'); $data['created_by_alias'] = $user->get('username'); $data['created'] = JFactory::getDate()->toSql(); } $makeJoin = false; $unMakeJoin = false; if ($this->checkRepeatAndPK($data)) { $makeJoin = $data['params']['repeat_group_button'] == 1; if ($makeJoin) { $data['is_join'] = 1; } else { if ($data['is_join'] == 1) { $unMakeJoin = true; $data['is_join'] = 0; } } } else { if ($data['params']['repeat_group_button'] == 1) { $data['params']['repeat_group_button'] = 0; JError::raiseNotice(500, 'You can not set the group containing the list primary key to be repeatable'); } } $data['params'] = json_encode($data['params']); $return = parent::save($data); $data['id'] = $this->getState($this->getName() . '.id'); if ($return) { $this->makeFormGroup($data); if ($makeJoin) { /** * $$$ rob added this check as otherwise toggling group from repeat * to norepeat back to repeat incorrectly created a 2nd join */ if (!$this->joinedGroupExists($data['id'])) { $return = $this->makeJoinedGroup($data); } // Update for the is_join change if ($return) { $return = parent::save($data); } } else { // $data['is_join'] = 0; // NO! none repeat joined groups were getting unset here - not right! if ($unMakeJoin) { $this->unMakeJoinedGroup($data); } $return = parent::save($data); } } parent::cleanCache('com_fabrik'); return $return; }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success, False on error. */ public function save($data) { if ($data['id'] == 0) { $data['created_by'] = $this->user->get('id'); $data['created_by_alias'] = $this->user->get('username'); $data['created'] = JFactory::getDate()->toSql(); } $makeJoin = false; $unMakeJoin = false; if ($this->checkRepeatAndPK($data)) { $makeJoin = $data['params']['repeat_group_button'] == 1; if ($makeJoin) { $data['is_join'] = 1; } elseif ($data['is_join'] == 1) { /* * $$$ rob - this was destroying legitimate joins on saving the group * see http://fabrikar.com/forums/showthread.php?t=29385 * commenting out for now until Hugh can take another look at what ever he was trying to solve * in commit #ee697dd * $unMakeJoin = true; $data['is_join'] = 0; */ } } else { if ($data['params']['repeat_group_button'] == 1) { $data['params']['repeat_group_button'] = 0; $this->app->enqueueMessage('You can not set the group containing the list primary key to be repeatable', 'notice'); } } $data['params'] = json_encode($data['params']); $return = parent::save($data); $data['id'] = $this->getState($this->getName() . '.id'); if ($return) { $this->makeFormGroup($data); if ($makeJoin) { /** * $$$ rob added this check as otherwise toggling group from repeat * to norepeat back to repeat incorrectly created a 2nd join */ if (!$this->joinedGroupExists($data['id'])) { $return = $this->makeJoinedGroup($data); } else { $this->checkFKIndex($data); } // Update for the is_join change if ($return) { $return = parent::save($data); } } else { // $data['is_join'] = 0; // NO! none repeat joined groups were getting unset here - not right! if ($unMakeJoin) { $this->unMakeJoinedGroup($data); } $return = parent::save($data); } } parent::cleanCache('com_fabrik'); return $return; }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success, False on error. */ public function save($data) { parent::cleanCache('com_fabrik'); return parent::save($data); }