Exemplo n.º 1
0
 /**
  * save the form
  * @param array $data (the jform part of the request data)
  */
 function save($data)
 {
     $this->populateState();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $config = JFactory::getConfig();
     $date = JFactory::getDate();
     $row = $this->getTable();
     $id = $data['id'];
     $row->load($id);
     $this->setState('list.id', $id);
     $this->setState('list.form_id', $row->form_id);
     $feModel = $this->getFEModel();
     $formModel = $this->getFormModel();
     if (!$row->bind($data)) {
         $this->setError($row->getError());
         return false;
     }
     $filter = new JFilterInput(null, null, 1, 1);
     $introduction = JRequest::getVar('introduction', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $row->introduction = $filter->clean($introduction);
     $row->order_by = json_encode(JRequest::getVar('order_by', array(), 'post', 'array'));
     $row->order_dir = json_encode(JRequest::getVar('order_dir', array(), 'post', 'array'));
     if (!$row->check()) {
         $this->setError($row->getError());
         return false;
     }
     $isNew = true;
     if ($id == 0) {
         if ($row->created == '') {
             $row->created = $date->toMySQL();
         }
         //save the row now
         $row->store();
         $isNew = false;
         $newtable = trim(JArrayHelper::getValue($data, '_database_name'));
         // $$$ hugh - added some more sanity checking on table name, get rid of non-alphanumeric and _
         // @TODO - should prolly use a helper for this, like FabrikString::clean()
         // but need to think about case issues first
         $newtable = preg_replace('#[^0-9a-zA-Z_]#', '_', $newtable);
         //check the entered database table doesnt already exist
         if ($newtable != '' && $this->getFEModel()->databaseTableExists($newtable)) {
             $this->setError(JText::_('COM_FABRIK_DATABASE_TABLE_ALREADY_EXISTS'));
             return false;
         }
         if (!$this->canCreateDbTable()) {
             $this->setError(Jtext::_('COM_FABRIK_INSUFFICIENT_RIGHTS_TO_CREATE_TABLE'));
             return false;
         }
         //create fabrik form
         $formModel =& $this->createLinkedForm();
         $row->form_id = $this->getState('list.form_id');
         //create fabrik group
         $groupData = array("name" => $row->label, "label" => $row->label);
         JRequest::setVar('_createGroup', 1, 'post');
         $groupId = $this->createLinkedGroup($groupData, false);
         if ($newtable == '') {
             //new fabrik table but existing db table
             $this->createLinkedElements($groupId);
         } else {
             $row->db_table_name = $newtable;
             $row->db_primary_key = $newtable . '.id';
             $row->auto_inc = 1;
             $res = $feModel->createDBTable($formModel, $newtable);
         }
     }
     // 	save params - this file no longer exists? do we use models/table.xml instead??
     $params = new fabrikParams($row->params, JPATH_COMPONENT . DS . 'xml' . DS . 'table.xml');
     if ($row->id != 0) {
         $datenow = JFactory::getDate();
         $row->modified = $datenow->toMySQL();
         $row->modified_by = $user->get('id');
     }
     FabrikHelper::prepareSaveDate($row->publish_down);
     FabrikHelper::prepareSaveDate($row->created);
     FabrikHelper::prepareSaveDate($row->publish_up);
     $pk = JArrayHelper::getValue($data, 'db_primary_key');
     if ($pk == '') {
         $fields = $row->getFields();
         $key = $row->getKeyName();
         //store without namequotes as thats db specific
         $row->db_primary_key = $row->db_table_name . "." . $key;
         $row->auto_inc = stristr($fields[$key]->Extra, 'auto_increment') ? true : false;
     }
     if (!$row->store()) {
         $this->setError($row->getError());
         return false;
     }
     $pk = $row->db_primary_key;
     $this->updateJoins($data);
     $feModel->setTable($row);
     //needed to ensure pk field is not quoted
     if (!$feModel->isView()) {
         // this was only run on a new table - but I've put it here so that if you upload a new table you can ensure that its columns are fixed
         //$this->makeSafeTableColumns();
         $this->updatePrimaryKey($row->db_primary_key, $row->auto_inc);
     }
     //make an array of elments and a presumed index size
     //map is then used in creating indexes
     $map = array();
     $groups =& $this->getFormModel()->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $elementModels =& $groupModel->getMyElements();
         foreach ($elementModels as $element) {
             //int elements cant have a index size attrib
             // $$$ hugh neither can DATETIME
             $coltype = $element->getFieldDescription();
             if (JString::stristr($coltype, 'int')) {
                 $size = '';
             } else {
                 if (JString::stristr($coltype, 'datetime')) {
                     $size = '';
                 } else {
                     $size = '10';
                 }
             }
             $map[$element->getFullName(false, false, false)] = $size;
             $map[$element->getElement()->id] = $size;
         }
     }
     //update indexes (added array_key_exists check as these may be during after CSV import)
     if (!empty($aOrderBy) && array_key_exists($row->order_by, $map)) {
         foreach ($aOrderBy as $orderBy) {
             if (array_key_exists($orderBy, $map)) {
                 $feModel->addIndex($orderBy, 'tableorder', 'INDEX', $map[$orderBy]);
             }
         }
     }
     if ($row->group_by !== '' && array_key_exists($row->group_by, $map)) {
         $feModel->addIndex($row->group_by, 'groupby', 'INDEX', $map["{$row->group_by}"]);
     }
     if ($params->get('group_by_order') !== '') {
         $feModel->addIndex($params->get('group_by_order'), 'groupbyorder', 'INDEX', $map[$params->get('group_by_order')]);
     }
     $afilterFields = $params->get('filter-fields', '', '_default', 'array');
     foreach ($afilterFields as $field) {
         if (array_key_exists($field, $map)) {
             $feModel->addIndex($field, 'prefilter', 'INDEX', $map[$field]);
         }
     }
     if (JFolder::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'contentelements')) {
         if ($params->get('allow-data-translation')) {
             if (!$this->makeJoomfishXML()) {
                 $this->setError(JTEXT::_("Unable to make Joomfish XML file"));
                 return false;
             }
         } else {
             $this->removeJoomfishXML();
         }
     }
     $pkName = $row->getKeyName();
     if (isset($row->{$pkName})) {
         $this->setState($this->getName() . '.id', $row->{$pkName});
     }
     $this->setState($this->getName() . '.new', $isNew);
     return true;
 }
Exemplo n.º 2
0
 /**
  * Save a connection
  */
 function save()
 {
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     // clear form from session
     $session =& JFactory::getSession();
     $session->clear('com_fabrik.admin.form.edit.model');
     jimport('joomla.utilities.date');
     $db =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $formModel =& JModel::getInstance('Form', 'FabrikModel');
     $formModel->setId(JRequest::getInt('id'));
     $formModel->getForm();
     $row =& JTable::getInstance('form', 'Table');
     $post = JRequest::get('post');
     if (!$row->bind($post)) {
         return JError::raiseWarning(500, $row->getError());
     }
     list($dofilter, $filter) = FabrikWorker::getContentFilter();
     //$filter	= new JFilterInput(null, null, 1, 1);
     $intro = JRequest::getVar('intro', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $row->intro = $dofilter ? $filter->clean($intro) : $intro;
     $details = JRequest::getVar('details', array(), 'post', 'array');
     $row->bind($details);
     FabrikHelper::prepareSaveDate($row->publish_down);
     FabrikHelper::prepareSaveDate($row->created);
     FabrikHelper::prepareSaveDate($row->publish_up);
     // save params
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'model' . DS . 'form.xml');
     $row->attribs = $params->updateAttribsFromParams(JRequest::getVar('params', array(), 'post', 'array'));
     if ($row->id != 0) {
         $datenow =& JFactory::getDate();
         $row->modified = $datenow->toMySQL();
         $row->modified_by = $user->get('id');
     }
     if (!$row->store()) {
         return JError::raiseWarning(500, $row->getError());
     }
     $row->checkin();
     $formModel->_id = $row->id;
     $formModel->_form =& $row;
     $formModel->saveFormGroups();
     $task = JRequest::getCmd('task');
     switch ($task) {
         case 'apply':
             $link = 'index.php?option=com_fabrik&c=form&task=edit&cid[]=' . $row->id;
             break;
         case 'save':
         default:
             $link = 'index.php?option=com_fabrik&c=form';
             break;
     }
     $cache =& JFactory::getCache('com_fabrik');
     $cache->clean();
     $this->setRedirect($link, JText::_('FORM SAVED'));
     //for prefab
     return $formModel;
 }
Exemplo n.º 3
0
 /**
  * Save a visualization
  */
 function save()
 {
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     $task = JRequest::getCmd('task');
     $pluginManager =& JModel::getInstance('Pluginmanager', 'FabrikModel');
     $className = JRequest::getVar('plugin', 'calendar', 'post');
     $pluginModel =& $pluginManager->getPlugIn($className, 'visualization');
     $id = JRequest::getInt('id', 0, 'post');
     $pluginModel->setId($id);
     $row =& JTable::getInstance('visualization', 'Table');
     $post = JRequest::get('post');
     if (!$row->bind($post)) {
         return JError::raiseWarning(500, $row->getError());
     }
     //$filter	= new JFilterInput(null, null, 1, 1);
     list($dofilter, $filter) = FabrikWorker::getContentFilter();
     $intro_text = JRequest::getVar('intro_text', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $row->intro_text = $dofilter ? $filter->clean($intro_text) : $intro_text;
     $details = JRequest::getVar('details', array(), 'post', 'array');
     $row->bind($details);
     // 	save params
     $pluginModel->attribs =& $row->attribs;
     $params = $pluginModel->getParams();
     $row->attribs = $params->updateAttribsFromParams(JRequest::getVar('params', array(), 'post', 'array'));
     FabrikHelper::prepareSaveDate($row->publish_down);
     FabrikHelper::prepareSaveDate($row->created);
     FabrikHelper::prepareSaveDate($row->publish_up);
     $user =& JFactory::getUser();
     if ($row->id != 0) {
         $datenow =& JFactory::getDate();
         $row->modified = $datenow->toMySQL();
         $row->modified_by = $user->get('id');
     }
     if (!$row->store()) {
         return JError::raiseWarning(500, $row->getError());
     }
     $row->checkin();
     switch ($task) {
         case 'apply':
             $link = 'index.php?option=com_fabrik&c=visualization&task=edit&cid[]=' . $row->id;
             $msg = JText::_('VISUALIZATION SAVED');
             break;
         case 'save':
         default:
             $link = 'index.php?option=com_fabrik&c=visualization';
             $msg = JText::_('VISUALIZATION SAVED');
             break;
     }
     $this->setRedirect($link, $msg);
 }
Exemplo n.º 4
0
 /**
  * save the table from admin
  *
  * @return Jerror if not saved true if saved ok
  */
 function save()
 {
     $session =& JFactory::getSession();
     $app =& JFactory::getApplication();
     $db =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $config =& JFactory::getConfig();
     $id = JRequest::getInt('id', 0, 'post');
     $this->setId($id);
     $row =& $this->getTable(false, false);
     $formModel =& JModel::getInstance('Form', 'FabrikModel');
     $post = JRequest::get('post');
     if (!$row->bind($post)) {
         return JError::raiseWarning(500, $row->getError());
     }
     list($dofilter, $filter) = FabrikWorker::getContentFilter();
     $introduction = JRequest::getVar('introduction', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $row->introduction = $dofilter ? $filter->clean($introduction) : $introduction;
     $details = JRequest::getVar('details', array(), 'post', 'array');
     $row->bind($details);
     $aOrderBy = JRequest::getVar('order_by', array(), 'post', 'array');
     $row->order_by = implode(GROUPSPLITTER2, $aOrderBy);
     $aOrderDir = JRequest::getVar('order_dir', array(), 'post', 'array');
     $row->order_dir = implode(GROUPSPLITTER2, $aOrderDir);
     if (!$row->check()) {
         $app->setError($row->getError());
         return JError::raiseWarning(500, $row->getError());
     }
     if ($id == 0) {
         $newtable = trim(JRequest::getVar('_database_name', '', 'post'));
         // $$$ hugh - added some more sanity checking on table name, get rid of non-alphanumeric and _
         // @TODO - should prolly use a helper for this, like FabrikString::clean()
         // but need to think about case issues first
         $newtable = preg_replace('#[^0-9a-zA-Z_]#', '_', $newtable);
         //check the entered database table doesnt already exist
         if ($newtable != '' && $this->databaseTableExists($newtable)) {
             return JError::raiseWarning(500, JText::_('DATABASE TABLE ALREADY EXISTS'));
         }
         if (!$this->canCreateDbTable()) {
             return JError::raiseWarning(500, Jtext::_('YOUR_DB_USER_HAS_INSUFFICIENT_RIGHTS_TO_CREATE_TABLE'));
         }
         //create fabrik form
         $formModel =& $this->_createLinkedForm();
         //create fabrik group
         $groupData = array("name" => $row->label, "label" => $row->label);
         JRequest::setVar('_createGroup', 1, 'post');
         if ($newtable != '') {
             $groupId = $this->_createLinkedGroup($groupData, false);
             $row->db_table_name = $newtable;
             $row->db_primary_key = "`" . $newtable . '`.`id`';
             $row->auto_inc = 1;
             $res = $this->createDBTable($formModel, $newtable);
         } else {
             // 2.0.5 balsamiq to fabrik tmpl generator sets up group properties in session, if we find those lets make
             // n groups each with their own groupid
             $groupDatas = array($groupData);
             if ($session->has('com_fabrik.list.create.groupmap')) {
                 $groupDatas =& $session->get('com_fabrik.list.create.groupmap');
             }
             $groupMap = array();
             foreach ($groupDatas as $x => $groupData) {
                 $groupId = $this->_createLinkedGroup($groupData, false);
                 $groupMap[$x] = $groupId;
             }
             //set element group ids
             if ($session->has('com_fabrik.list.create.elementmap')) {
                 $map = (array) $session->get('com_fabrik.list.create.elementmap');
                 foreach ($map as &$m) {
                     $groupMapId = array_key_exists('groupid', $m) ? $m['groupid'] : 0;
                     $m['groupid'] = $groupMap[$groupMapId];
                 }
                 $session->set('com_fabrik.list.create.elementmap', $map);
             }
             // save elements in group
             foreach ($groupMap as $groupId) {
                 $this->_createLinkedElements($groupId, $post);
             }
         }
         //	set the tables form id
         $this->_updateFormId($formModel->_form->id);
     }
     // 	save params - this file no longer exists? do we use models/table.xml instead??
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'xml' . DS . 'table.xml');
     $row->attribs = $params->updateAttribsFromParams(JRequest::getVar('params', array(), 'post', 'array'));
     $row->rows_per_page = JRequest::getInt('rows_per_page', 10, 'post');
     if ($row->id != 0) {
         $datenow =& JFactory::getDate();
         $row->modified = $datenow->toMySQL();
         $row->modified_by = $user->get('id');
     }
     FabrikHelper::prepareSaveDate($row->publish_down);
     FabrikHelper::prepareSaveDate($row->created);
     FabrikHelper::prepareSaveDate($row->publish_up);
     $pk = JRequest::getVar('db_primary_key');
     if ($pk == '') {
         $aKey = $this->getPrimaryKeyAndExtra();
         $aKey = $aKey[0];
         $row->db_primary_key = "`" . $row->db_table_name . "`.`" . $aKey['colname'] . "`";
         $row->auto_inc = stristr($aKey['extra'], 'auto_increment') ? true : false;
     }
     if (!$row->store()) {
         return JError::raiseWarning(500, $row->getError());
     }
     // load in all the tables data - even if it wasnt in the post data
     $table =& $this->getTable();
     //needed if saving a table for first time (otherwise id = 0)
     $this->setId($table->id);
     $this->updateJoins();
     if (!$this->isView()) {
         // this was only run on a new table - but I've put it here so that if you upload a new table you can ensure that its columns are fixed
         $this->makeSafeTableColumns();
         $this->updatePrimaryKey($row->db_primary_key, $row->auto_inc);
     }
     $row->checkin();
     //make an array of elments and a presumed index size
     //map is then used in creating indexes
     $map = array();
     $groups =& $this->getForm()->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $elementModels =& $groupModel->getMyElements();
         foreach ($elementModels as $element) {
             //int elements cant have a index size attrib
             // $$$ hugh neither can DATETIME
             $coltype = $element->getFieldDescription();
             if (JString::stristr($coltype, 'int')) {
                 $size = '';
             } else {
                 if (JString::stristr($coltype, 'datetime')) {
                     $size = '';
                 } else {
                     $size = 10;
                     // $$$ hugh - adding index will barf if key size > varchar size.
                     $matches = array();
                     if (preg_match('/varchar\\((\\d+)\\)/i', $coltype, $matches)) {
                         $varchar_size = (int) $matches[1];
                         if ($varchar_size < 10) {
                             $size = $varchar_size;
                         }
                     }
                 }
             }
             $map[$element->getFullName(false, false, false)] = $size;
             $map[$element->getElement()->id] = $size;
         }
     }
     //update indexes (added array_key_exists check as these may be during after CSV import)
     if (!empty($aOrderBy) && array_key_exists($row->order_by, $map)) {
         foreach ($aOrderBy as $orderBy) {
             if (array_key_exists($orderBy, $map)) {
                 $this->addIndex($orderBy, 'tableorder', 'INDEX', $map[$orderBy]);
             }
         }
     }
     if ($row->group_by !== '' && array_key_exists($row->group_by, $map)) {
         $this->addIndex($row->group_by, 'groupby', 'INDEX', $map["{$row->group_by}"]);
     }
     if ($params->get('group_by_order') !== '') {
         $this->addIndex($params->get('group_by_order'), 'groupbyorder', 'INDEX', $map[$params->get('group_by_order')]);
     }
     $afilterFields = $params->get('filter-fields', '', '_default', 'array');
     foreach ($afilterFields as $field) {
         $field = str_replace('`', '', $field);
         $this->addIndex($field, 'prefilter', 'INDEX', $map[$field]);
     }
     if (JFolder::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'contentelements')) {
         if ($params->get('allow-data-translation')) {
             if (!$this->makeJoomfishXML()) {
                 JError::raiseNotice('E_ERROR', JTEXT::_("Unable to make Joomfish XML file"));
             }
         } else {
             $this->removeJoomfishXML();
         }
     }
     return true;
 }