Esempio n. 1
0
	function display()
	{
		$app = JFactory::getApplication();
		$Itemid	= $app->getMenu('site')->getActive()->id;
		$config		= JFactory::getConfig();
		$user 		= JFactory::getUser();
		$model		=& $this->getModel();
		$model->_outPutFormat == 'feed';

		$document = JFactory::getDocument();
		$document->_itemTags = array();

		//Get the active menu item
		$usersConfig = JComponentHelper::getParams('com_fabrik');

		JRequest::setVar('incfilters', 0);
		$table = $model->getTable();
		$model->render();
		$params	=& $model->getParams();

		if ($params->get('rss') == '0') {
			return '';
		}

		$formModel = $model->getForm();
		$form = $formModel->getForm();

		$aJoinsToThisKey = $model->getJoinsToThisKey();
		/* get headings */
		$aTableHeadings = array();
		$groupModels = $formModel->getGroupsHiarachy();

		$titleEl = $params->get('feed_title');
		$dateEl = $params->get('feed_date');
		foreach ($groupModels as $groupModel) {
			$elementModels = $groupModel->getPublishedElements();
			foreach ($elementModels as $elementModel) {
				$element = $elementModel->getElement();
				if ($element->id == $titleEl) {
					$titleEl = $elementModel->getFullName(false, true, false);
				}
				if ($element->id == $dateEl) {
					$dateEl = $elementModel->getFullName(false, true, false);
				}
				$elParams = $elementModel->getParams();

				if ($elParams->get('show_in_rss_feed') == '1') {
					$heading = $element->label;
					if ($elParams->get('show_label_in_rss_feed') == '1') {
						$aTableHeadings[$heading]['label']	 = $heading;
					} else {
						$aTableHeadings[$heading]['label']	 = '';
					}
					$aTableHeadings[$heading]['colName'] = $elementModel->getFullName(false, true);
					$aTableHeadings[$heading]['dbField'] = $element->name;
					$aTableHeadings[$heading]['key'] = $elParams->get('use_as_fake_key');
					// $$$ hugh - adding enclosure stuff for podcasting
					if ($element->plugin == 'fabrikfileupload') {
						$aTableHeadings[$heading]['enclosure'] = true;
					}
					else {
						$aTableHeadings[$heading]['enclosure'] = false;
					}
				}
			}
		}

		foreach ($aJoinsToThisKey as $element) {
			$element = $elementModel->getElement();
			$elParams = new fabrikParams($element->attribs, JPATH_SITE . '/administrator/components/com_fabrik/xml/element.xml', 'component');
			if ($elParams->get('show_in_rss_feed') == '1') {
				$heading = $element->label;

				if ($elParams->get('show_label_in_rss_feed') == '1') {
					$aTableHeadings[$heading]['label']	 = $heading;
				} else {
					$aTableHeadings[$heading]['label']	 = '';
				}
				$aTableHeadings[$heading]['colName'] = $element->db_table_name . "___" . $element->name;
				$aTableHeadings[$heading]['dbField'] = $element->name;
				$aTableHeadings[$heading]['key'] = $elParams->get('use_as_fake_key');
				// $$$ hugh - adding enclosure stuff for podcasting
				if ($element->plugin == 'fabrikfileupload') {
					$aTableHeadings[$heading]['enclosure'] = true;
				}
				else {
					$aTableHeadings[$heading]['enclosure'] = false;
				}
			}
		}
		$w = new FabrikWorker();
		$rows = $model->getData();

		$document->title = $w->parseMessageForPlaceHolder($table->label, $_REQUEST);
		$document->description = $w->parseMessageForPlaceHolder($table->introduction);
		$document->link = JRoute::_('index.php?option=com_fabrik&view=list&listid='.$table->id.'&Itemid='.$Itemid);

		/* check for a custom css file and include it if it exists*/
		$tmpl = JRequest::getVar('layout', $table->template);
		$csspath = COM_FABRIK_FRONTEND.DS."views".DS."list".DS."tmpl".DS.$tmpl.DS.'feed.css';

		if (file_exists($csspath)) {
			$document->addStyleSheet(COM_FABRIK_LIVESITE."components/com_fabrik/views/table/tmpl/$tmpl/feed.css");
		}

		$view = $model->canEdit() ? 'form' : 'details';

		//list of tags to look for in the row data
		//- if they are there don't put them in the desc but put them in as a seperate item param
		$rsstags = array(
			'<georss:point>' => 'xmlns:georss="http://www.georss.org/georss"'
		);
		foreach ($rows as $group)
		{
			foreach ($group as $row)
			{
				// strip html from feed item title
				//$title = html_entity_decode($this->escape( $row->$titleEl));

				//get the content
				$str2 = '';
				$str = '<table style="margin-top:10px;padding-top:10px;">';
				//used for content not in dl
				//ok for feed gator you cant have the same item title so we'll take the first value from the table (asume its the pk and use that to append to the item title)'
				$title = '';
				$item = new JFabrikFeedItem();

				$enclosures = array();
				foreach ($aTableHeadings as $heading=>$dbcolname) {
					if ($dbcolname['enclosure']) {
						// $$$ hugh - diddling aorund trying to add enclosures
						$colName = $dbcolname['colName'] . '_raw';
						$enclosure_url = $row->$colName;
						if (!empty($enclosure_url)) {
							$enclosure_file = COM_FABRIK_BASE.$enclosure_url;
							$enclosure_url = COM_FABRIK_LIVESITE . str_replace('\\','/',$enclosure_url);
							if (file_exists($enclosure_file) and !is_dir($enclosure_file)) {
								$enclosure_type = '';
								if ($enclosure_type = FabrikWorker::getAudioMimeType($enclosure_file)) {
									$enclosure_size = filesize($enclosure_file);
									$enclosures[] = array(
										'url' => $enclosure_url,
										'length' => $enclosure_size,
										'type' => $enclosure_type
									);
									// no need to insert the URL in the description, as feed readers should
									// automagically show 'media' when they see an 'enclosure', so just move on ..
									continue;
								}
							}
						}
					}
					if ($title == '') {
						//set a default title
						$title = $row->$dbcolname['colName'];
					}
					$rsscontent = $row->$dbcolname['colName'];

					$found = false;
					foreach ($rsstags as $rsstag =>$namespace) {
						if (strstr($rsscontent, $rsstag)) {
							$found = true;
							$rsstag = substr($rsstag, 1, strlen($rsstag)-2);
							if (!strstr($document->_namespace, $namespace)) {
								$document->_itemTags[] = $rsstag;
								$document->_namespace .=  $namespace . " ";
							}
							break;
						}
					}

					if ($found) {
						$item->{$rsstag} = $rsscontent;
					} else {
						if ($dbcolname['label'] == '') {
							$str2 .= $rsscontent . "<br />\n";
						} else {
							$str .= "<tr><td>" . $dbcolname['label'] . ":</td><td>" . $rsscontent . "</td></tr>\n";
						}
					}
				}

				if (isset($row->$titleEl)) {
					$title = $row->$titleEl;
				}
				$str = $str2 . $str . "</table>";

				// url link to article
				$link = JRoute::_('index.php?option=com_fabrik&view='.$view.'&listid='.$table->id.'&formid='.$form->id.'&rowid='. $row->slug);
				$guid = COM_FABRIK_LIVESITE . 'index.php?option=com_fabrik&view='.$view.'&listid='.$table->id.'&formid='.$form->id.'&rowid='. $row->slug;

				// strip html from feed item description text
				$author			= @$row->created_by_alias ? @$row->created_by_alias : @$row->author;

				if ($dateEl != '') {
					$date = $row->$dateEl ? date('r', strtotime(@$row->$dateEl) ) : '';
				} else {
					$date = '';
				}
				// load individual item creator class

				$item->title 		= $title;
				$item->link 		= $link;
				$item->guid 		= $guid;
				$item->description 	= $str;
				$item->date			= $date;
				// $$$ hugh - not quite sure where we were expecting $row->category to come from.  Comment out for now.
				//$item->category   	= $row->category;

				foreach ($enclosures as $enclosure) {
					$item->setEnclosure($enclosure);
				}

				// loads item info into rss array
				$document->addItem( $item);
			}
		}
	}
Esempio n. 2
0
 function display()
 {
     global $Itemid;
     $app =& JFactory::getApplication();
     $config =& JFactory::getConfig();
     $user =& JFactory::getUser();
     $model =& $this->getModel();
     $model->_outPutFormat == 'feed';
     $document =& JFactory::getDocument();
     $document->_itemTags = array();
     //Get the active menu item
     $usersConfig =& JComponentHelper::getParams('com_fabrik');
     if (!isset($this->_id)) {
         if ($app->isAdmin()) {
             $tpl = "admin";
         } else {
             $model->setId(array('id' => JRequest::getVar('tableid', $usersConfig->get('tableid')), 'package_id' => JRequest::getInt('package_id')));
         }
     } else {
         //when in a package the id is set from the package view
         $model->setId($this->_id);
     }
     $table =& $model->getTable();
     $model->render();
     $params =& $model->getParams();
     if ($params->get('rss') == '0') {
         return '';
     }
     $formModel =& $model->getForm();
     $form =& $formModel->getForm();
     $aJoinsToThisKey = $model->getJoinsToThisKey();
     /* get headings */
     $aTableHeadings = array();
     $groupModels =& $formModel->getGroupsHiarachy();
     foreach ($groupModels as $groupModel) {
         $elementModels =& $groupModel->getPublishedElements();
         foreach ($elementModels as $elementModel) {
             $element = $elementModel->getElement();
             $elParams =& $elementModel->getParams();
             //$elParams =& new fabrikParams($oElement->attribs, $mosConfig_absolute_path . '/administrator/components/com_fabrik/xml/element.xml', 'component');
             if ($elParams->get('show_in_rss_feed') == '1') {
                 $heading = $element->label;
                 if ($elParams->get('show_label_in_rss_feed') == '1') {
                     $aTableHeadings[$heading]['label'] = $heading;
                 } else {
                     $aTableHeadings[$heading]['label'] = '';
                 }
                 $aTableHeadings[$heading]['colName'] = $elementModel->getFullName(false, true);
                 $aTableHeadings[$heading]['dbField'] = $element->name;
                 $aTableHeadings[$heading]['key'] = $elParams->get('use_as_fake_key');
             }
         }
     }
     foreach ($aJoinsToThisKey as $element) {
         $element = $elementModel->getElement();
         $elParams = new fabrikParams($element->attribs, JPATH_SITE . '/administrator/components/com_fabrik/xml/element.xml', 'component');
         if ($elParams->get('show_in_rss_feed') == '1') {
             $heading = $element->label;
             if ($elParams->get('show_label_in_rss_feed') == '1') {
                 $aTableHeadings[$heading]['label'] = $heading;
             } else {
                 $aTableHeadings[$heading]['label'] = '';
             }
             $aTableHeadings[$heading]['colName'] = $element->db_table_name . "___" . $element->name;
             $aTableHeadings[$heading]['dbField'] = $element->name;
             $aTableHeadings[$heading]['key'] = $elParams->get('use_as_fake_key');
         }
     }
     $dateCol = $params->get('feed_date', '');
     $w = new FabrikWorker();
     $rows =& $model->getData();
     $document->title = $w->parseMessageForPlaceHolder($table->label, $_REQUEST);
     $document->description = $w->parseMessageForPlaceHolder($table->introduction);
     $document->link = JRoute::_('index.php?option=com_fabrik&view=table&tableid=' . $table->id . '&Itemid=' . $Itemid);
     /* check for a custom css file and include it if it exists*/
     $tmpl = JRequest::getVar('layout', $table->template);
     $csspath = COM_FABRIK_FRONTEND . DS . "views" . DS . "table" . DS . "tmpl" . DS . $tmpl . DS . 'feed.css';
     if (file_exists($csspath)) {
         $document->addstylesheet(COM_FABRIK_LIVESITE . "components/com_fabrik/views/table/tmpl/{$tmpl}/feed.css");
     }
     $titleEl = $params->get('feed_title');
     $dateEl = $params->get('feed_date');
     $dateEl = $params->get('feed_date');
     $view = $model->canEdit() ? 'form' : 'details';
     //list of tags to look for in the row data
     //- if they are there don't put them in the desc but put them in as a seperate item param
     $rsstags = array('<georss:point>' => 'xmlns:georss="http://www.georss.org/georss"');
     foreach ($rows as $group) {
         foreach ($group as $row) {
             // strip html from feed item title
             //$title = html_entity_decode($this->escape( $row->$titleEl));
             //get the content
             $str2 = '';
             $str = '<table style="margin-top:10px;padding-top:10px;">';
             //used for content not in dl
             //ok for feed gator you cant have the same item title so we'll take the first value from the table (asume its the pk and use that to append to the item title)'
             $title = '';
             $item =& new JFeedItem();
             foreach ($aTableHeadings as $heading => $dbcolname) {
                 if ($title == '') {
                     //set a default title
                     $title = $row->{$dbcolname}['colName'];
                 }
                 $rsscontent = $row->{$dbcolname}['colName'];
                 $found = false;
                 foreach ($rsstags as $rsstag => $namespace) {
                     if (strstr($rsscontent, $rsstag)) {
                         $found = true;
                         if (!strstr($document->_namespace, $namespace)) {
                             $rsstag = substr($rsstag, 1, strlen($rsstag) - 2);
                             $document->_itemTags[] = $rsstag;
                             $document->_namespace .= $namespace . "\n";
                         }
                         break;
                     }
                 }
                 if ($found) {
                     $item->{$rsstag} = $rsscontent;
                 } else {
                     if ($dbcolname['label'] == '') {
                         $str2 .= $rsscontent . "<br />\n";
                     } else {
                         $str .= "<tr><td>" . $dbcolname['label'] . ":</td><td>" . $rsscontent . "</td></tr>\n";
                     }
                 }
             }
             if (isset($row->{$titleEl})) {
                 $title = $row->{$titleEl};
             }
             $str = $str2 . $str . "</table>";
             // url link to article
             $link = JRoute::_('index.php?option=com_fabrik&view=' . $view . '&tableid=' . $table->id . '&fabrik=' . $form->id . '&rowid=' . $row->__pk_val);
             // strip html from feed item description text
             $author = @$row->created_by_alias ? @$row->created_by_alias : @$row->author;
             if ($dateEl != '') {
                 $date = $row->{$dateEl} ? date('r', strtotime(@$row->{$dateEl})) : '';
             } else {
                 $data = '';
             }
             // load individual item creator class
             $item->title = $title;
             $item->link = $link;
             $item->guid = $link;
             $item->description = $str;
             $item->date = $date;
             $item->category = $row->category;
             // loads item info into rss array
             $document->addItem($item);
         }
     }
 }
Esempio n. 3
0
 /**
  * Edit an element
  */
 function edit()
 {
     global $_PROFILER;
     JDEBUG ? $_PROFILER->mark('edit: start') : null;
     $app =& JFactory::getApplication();
     $user =& JFactory::getUser();
     $db =& JFactory::getDBO();
     $acl =& JFactory::getACL();
     $model =& JModel::getInstance('element', 'FabrikModel');
     if ($this->_task == 'edit') {
         $cid = JRequest::getVar('cid', array(0), 'method', 'array');
         $cid = array((int) $cid[0]);
     } else {
         $cid = array(0);
     }
     $model->setId($cid[0]);
     $row =& $model->getElement();
     if ($cid) {
         $row->checkout($user->get('id'));
     }
     // get params definitions
     $params =& $model->getParams();
     require_once JPATH_COMPONENT . DS . 'views' . DS . 'element.php';
     $pluginManager =& JModel::getInstance('Pluginmanager', 'FabrikModel');
     $db->setQuery("SELECT COUNT(*) FROM #__fabrik_groups");
     $total = $db->loadResult();
     if ($total == 0) {
         $app->redirect("index.php?option=com_fabrik&c=group&task=new", JText::_('PLEASE CREATE A GROUP BEFORE CREATING AN ELEMENT'));
         return;
     }
     $lists = array();
     if ($cid[0] != '0') {
         $aEls = array();
         $aGroups = array();
         $db->setQuery("SELECT form_id FROM #__fabrik_formgroup AS fg\n" . "WHERE fg.group_id = {$row->group_id}");
         $formrow = $db->loadObject();
         if (is_null($formrow)) {
             $aEls[] = $aGroups[] = JText::_('GROUP MUST BE IN A FORM');
         } else {
             $formModel = JModel::getInstance('form', 'FabrikModel');
             $formModel->setId($formrow->form_id);
             //get available element types
             $groups =& $formModel->getGroupsHiarachy();
             foreach ($groups as $groupModel) {
                 $group =& $groupModel->getGroup();
                 $o = new stdClass();
                 $o->label = $group->name;
                 $o->value = "fabrik_trigger_group_group" . $group->id;
                 $aGroups[] = $o;
                 $elementModels =& $groupModel->getMyElements();
                 foreach ($elementModels as $elementModel) {
                     $o = new stdClass();
                     $element =& $elementModel->getElement();
                     $o->label = FabrikString::getShortDdLabel($element->label);
                     $o->value = "fabrik_trigger_element_" . $elementModel->getFullName(false, true, false);
                     $aEls[] = $o;
                 }
             }
         }
         asort($aEls);
         $o = new StdClass();
         $o->groups = $aGroups;
         $o->elements = array_values($aEls);
         $lists['elements'] = $o;
     } else {
         // set the publish default to 1
         $row->state = '1';
         $lists['elements'] = array(JText::_('AVAILABLE ONCE SAVED'));
     }
     JDEBUG ? $_PROFILER->mark('edit: after element types') : null;
     $pluginManager->getPlugInGroup('validationrule');
     $pluginManager->loadPlugInGroup('element');
     $j = new JRegistry();
     $lists['jsActions'] = $model->getJSActions();
     //merge the js attribs back into the array
     foreach ($lists['jsActions'] as $js) {
         $j->loadINI($js->attribs);
         $a = $j->toArray();
         foreach ($a as $k => $v) {
             $js->{$k} = $v;
         }
         unset($js->attribs);
     }
     $no_html = JRequest::getBool('no_html', 0);
     // Create the form
     $form = new fabrikParams('', JPATH_COMPONENT . DS . 'models' . DS . 'element.xml');
     $form->bind($row);
     $form->loadINI($row->attribs);
     $row->parent_id = (int) $row->parent_id;
     if ($row->parent_id === 0) {
         $lists['parent'] = 0;
     } else {
         $sql = "SELECT * FROM #__fabrik_elements WHERE id = " . (int) $row->parent_id;
         $db->setQuery($sql);
         $parent = $db->loadObject();
         if (is_null($parent)) {
             //perhaps the parent element was deleted?
             $lists['parent'] = 0;
             $row->parent_id = 0;
         } else {
             $lists['parent'] = $parent;
         }
     }
     JDEBUG ? $_PROFILER->mark('view edit: start') : null;
     if ($no_html != 1) {
         FabrikViewElement::edit($row, $pluginManager, $lists, $params, $form);
     }
 }
Esempio n. 4
0
 /**
  * Save group
  */
 function save()
 {
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     $db =& JFactory::getDBO();
     $row =& JTable::getInstance('Group', 'FabrikTable');
     $post = JRequest::get('post');
     if (!$row->bind($post)) {
         return JError::raiseWarning(500, $row->getError());
     }
     // 	save params
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'xml' . DS . 'group.xml');
     $row->attribs = $params->updateAttribsFromParams(JRequest::getVar('params', array(), 'post', 'array'));
     if (!$row->store()) {
         return JError::raiseWarning(500, $row->getError());
     }
     $row->checkin();
     $task = JRequest::getCmd('task');
     //update the group's element table definitons, currently used for database join element
     //which if part of a repeat group should revert to varchar(255) regardless of what table
     //field it joins to
     $groupModel =& JModel::getInstance('Group', 'FabrikModel');
     $groupModel->setId($row->id);
     $elements =& $groupModel->getMyElements();
     $c = 0;
     foreach ($elements as $element) {
         if ($c === 0) {
             $tableModel =& $element->getTableModel();
             // $$$ hugh - this was screwing up if it's a joined group, tried to modify
             // columns on main form's table instead of joined table!
             // So if it's a joined group, need to get table name from join model
             if ($groupModel->isJoin()) {
                 $joinModel =& $groupModel->getJoinModel();
                 $joinTable =& $joinModel->getJoin();
                 $tableName = $joinTable->table_join;
             } else {
                 $table =& $tableModel->getTable();
                 $tableName = $table->db_table_name;
             }
             // $$$ hugh - at the moment, connection details will be same even it's a join, as
             // we don't do cross database joins.  But at some point may need to modify this
             // this bit as well to get connection from join.
             $fabrikDb =& $tableModel->getDb();
         }
         $elementName = $element->getElement()->name;
         $objtype = $element->getFieldDescription();
         // $$$ hugh - changed this to use $tableName derived above instead of $table->db_table_name
         $query = "ALTER TABLE " . FabrikString::safeColName($tableName) . " CHANGE " . $fabrikDb->nameQuote($elementName) . " " . $fabrikDb->nameQuote($elementName) . " {$objtype}";
         $fabrikDb->setQuery($query);
         $fabrikDb->query();
         $c++;
     }
     switch ($task) {
         case 'apply':
             $link = 'index.php?option=com_fabrik&c=group&task=edit&cid[]=' . $row->id;
             break;
         case 'save':
         default:
             $link = 'index.php?option=com_fabrik&c=group';
             break;
     }
     $cache =& JFactory::getCache('com_fabrik');
     $cache->clean();
     $this->setRedirect($link, JText::_('GROUP SAVED'));
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
 /**
  * Save package
  */
 function save()
 {
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     jimport('joomla.utilities.date');
     $now = new JDate();
     $now = $now->toUnix();
     $db =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $row =& JTable::getInstance('package', 'Table');
     $post = JRequest::get('post');
     if (!$row->bind($post)) {
         return JError::raiseWarning(500, $row->getError());
     }
     // save params
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'xml' . DS . 'package.xml');
     $row->attribs = $params->updateAttribsFromParams(JRequest::getVar('params', array(), 'post', 'array'));
     $row->tables = implode(",", JRequest::getVar('tables', array(), 'post'));
     if ($row->id == 0) {
         $row->created = $now;
     } else {
         $row->modified = $now;
         $row->modified_by = $user->get('id');
     }
     if (!$row->store()) {
         return JError::raiseWarning(500, $row->getError());
     }
     $row->checkin();
     $task = JRequest::getCmd('task');
     $msg = JText::_('PACKAGE SAVED');
     switch ($task) {
         case 'apply':
             $link = 'index.php?option=com_fabrik&c=package&task=edit&cid[]=' . $row->id;
             break;
         case 'save':
         default:
             $link = 'index.php?option=com_fabrik&c=package';
             break;
     }
     $this->setRedirect($link, $msg);
 }
Esempio n. 7
0
 function _loadPluginParams()
 {
     if (isset($this->_xmlPath)) {
         $element = $this->getElement();
         $pluginParams = new fabrikParams($element->params, $this->_xmlPath, 'fabrikplugin');
         $pluginParams->bind($element);
         return $pluginParams;
     }
     return false;
 }
Esempio n. 8
0
 protected function updateMetaSettings($model, $tmpldata = array())
 {
     $db =& JFactory::getDBO();
     if ($model === false) {
         $db->setQuery("select id from #__fabrik_tables where db_table_name = " . $db->Quote($this->tbl));
         $tid = $db->loadResult();
         $model = JModel::getInstance('table', 'FabrikModel');
         $model->setId($tid);
     }
     $elements = $model->getForm()->getFormGroups();
     foreach ($tmpldata as $fullElName => $data) {
         $shortName = array_pop(explode("___", $fullElName));
         $filterType = JArrayHelper::getValue($data, 'filter_type');
         foreach ($elements as $el) {
             if ($el->name == $shortName) {
                 $db->setQuery("update #__elements set filter_type = " . $db->Quote($filterType) . " where id = " . (int) $el->id);
                 $db->Query();
             }
         }
     }
     //set the search type
     $table = $model->getTable();
     $attribs = $table->attribs;
     $params = new fabrikParams($attribs, JPATH_COMPONENT . DS . 'xml' . DS . 'table.xml');
     $aparams = $params->toArray();
     $aparams['search-mode'] = $this->searchMode ? 'OR' : 'AND';
     $params->empty_data_msg = 'No records found';
     $table->attribs = $params->updateAttribsFromParams($aparams);
     $table->store();
 }
Esempio n. 9
0
 function _loadPluginParams()
 {
     if (isset($this->_xmlPath)) {
         $rule =& $this->getValidationRule();
         $pluginParams = new fabrikParams($rule->attribs, $this->_xmlPath, 'fabrikplugin');
         $pluginParams->bind($rule);
         return $pluginParams;
     }
     return false;
 }
Esempio n. 10
0
 function getAdminSelectedPluginJS($group, $row, $lists, $params)
 {
     $c = 0;
     $usedPlugins = $params->get('plugin', '', '_default', 'array');
     $usedLocations = $params->get('plugin_locations', '', '_default', 'array');
     $usedEvents = $params->get('plugin_events', '', '_default', 'array');
     $js = '';
     //go through all of this form's ACTIVE plugins
     foreach ($usedPlugins as $usedPlugin) {
         if (trim($usedPlugin) == '') {
             continue;
         }
         $plugin = $this->_plugIns[$group][$usedPlugin];
         $pluginParams = new fabrikParams($row->attribs, $plugin->_xmlPath, 'fabrikplugin');
         $names = $pluginParams->_getParamNames();
         $tmpAttribs = '';
         foreach ($names as $name) {
             $pluginElOpts = $params->get($name, '', '_default', 'array');
             $val = JArrayHelper::getValue($pluginElOpts, $c, '');
             //backslash any "|"'s in the data (otherwise the ini.php format thinks you are storing an array
             $val = preg_replace('#(?<!\\\\)\\|#', '\\|', $val);
             $tmpAttribs .= $name . "=" . $val . "\n";
         }
         //redo the parmas with the exploded data
         $pluginParams = new fabrikParams($tmpAttribs, $plugin->_xmlPath, 'fabrikplugin');
         $pluginParams->_duplicate = true;
         $plugin->_adminVisible = true;
         $plugin->_counter = $c;
         $data = $plugin->renderAdminSettings($usedPlugin, $row, $pluginParams, $lists, $c);
         //sanitize data as its no longer sanitized in renderAdminSettings
         $data = addslashes(str_replace("\n", "", $data));
         $js .= "controller.addAction('" . $data . "', '" . $usedPlugins[$c] . "', '" . @$usedLocations[$c] . "', '" . @$usedEvents[$c] . "', false);\n";
         $c++;
     }
     return $js;
 }
Esempio n. 11
0
 /**
  * Edit a table
  */
 function edit()
 {
     $app =& JFactory::getApplication();
     $session =& JFactory::getSession();
     $session->clear('com_fabrik.admin.table.edit.model');
     require_once JPATH_COMPONENT . DS . 'views' . DS . 'table.php';
     $user =& JFactory::getUser();
     $db =& JFactory::getDBO();
     $row =& JTable::getInstance('table', 'Table');
     $acl =& JFactory::getACL();
     $config =& JFactory::getConfig();
     if ($this->_task == 'edit') {
         $cid = JRequest::getVar('cid', array(0), 'method', 'array');
         $cid = array((int) $cid[0]);
     } else {
         $cid = array(0);
     }
     $connectionTables = array();
     //  this only appears if you are automatically creating the table from an existing form - which has no table associated with it
     $fabrikid = JRequest::getVar('fabrikid', '', 'get');
     $row->load($cid[0]);
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'model' . DS . 'table.xml');
     $lists['tablejoin'] = "";
     //$lists['defaultJoinTables'] = '[]';
     $lists['defaultJoinTables'] = array();
     $lists['linkedtables'] = array();
     $connModel =& JModel::getInstance('Connection', 'FabrikModel');
     $model =& JModel::getInstance('Table', 'FabrikModel');
     $model->setId($cid[0]);
     $model->_table =& $row;
     $formModel =& $model->getForm();
     $aJoinObjs = array();
     if ($this->_task != 'edit') {
         $row->template = 'default';
         $realCnns = $connModel->getConnections();
         $defaultCid = '';
         foreach ($realCnns as $realCnn) {
             if ($realCnn->default == 1) {
                 $defaultCid = $realCnn->id;
             }
         }
         $javascript = "onchange=\"changeDynaList('db_table_name', connectiontables, document.adminForm.connection_id.options[document.adminForm.connection_id.selectedIndex].value, 0, 0);\"";
         $lists['connections'] = $connModel->getConnectionsDd($realCnns, $javascript, 'connection_id', $defaultCid);
         $connectionTables = $connModel->getConnectionTables($realCnns);
         $javascript = '';
         $lists['tablename'] = '<select name="db_table_name" id="tablename" class="inputbox" size="1" >';
         if ($defaultCid == '') {
             $lists['tablename'] .= '<option value="" selected="selected">' . JText::_('CHOOSE A CONNECTION FIRST') . '</option>';
         } else {
             foreach ($connectionTables[$defaultCid] as $t) {
                 $lists['tablename'] .= '<option value="' . $t->value . '">' . $t->text . '</option>';
             }
         }
         $lists['tablename'] .= '</select>';
         $lists['order_by'][] = JText::_('AVAILABLE AFTER TABLE SAVED');
         $lists['group_by'] = JText::_('AVAILABLE AFTER TABLE SAVED');
         $lists['filter-fields'] = JText::_('AVAILABLE AFTER TABLE SAVED');
         $lists['db_primary_key'] = JText::_('AVAILABLE AFTER TABLE SAVED');
     } else {
         //if record already exists then you can't change the form or table it points to
         // fail if checked out not by 'me'
         if ($row->checked_out && $row->checked_out != $user->get('id')) {
             $app->redirect('index.php?option=com_fabrik', 'The connection ' . $row->description . ' is currently being edited by another administrator');
         }
         $row->checkout($user->get('id'));
         if ($row->connection_id != "-1") {
             $sql = "SELECT description FROM #__fabrik_connections WHERE id = " . (int) $row->connection_id;
             $db->setQuery($sql);
             $lists['connections'] = $db->loadResult();
             $lists['tablename'] = "<input type='hidden' name='db_table_name' value='{$row->db_table_name}' />{$row->db_table_name}";
         } else {
             $lists['connections'] = "no database";
             $lists['tablename'] = "no table";
         }
         $lists['connections'] .= "<input type=\"hidden\" value=\"{$row->connection_id}\" id=\"connection_id\" name=\"connection_id\" />";
         $formModel->setId($row->form_id);
         $formTable =& $formModel->getForm();
         $formModel->getGroupsHiarachy();
         //table join info
         $sql = "SELECT * FROM #__fabrik_joins WHERE table_id = " . (int) $row->id . " AND element_id = 0";
         $db->setQuery($sql);
         $aJoinObjs = $db->loadObjectList();
         $lists['joins'] =& $aJoinObjs;
         $lists['order_by'] = array();
         $orderbys = explode(GROUPSPLITTER2, $row->order_by);
         foreach ($orderbys as $orderby) {
             $lists['order_by'][] = $formModel->getElementList('order_by[]', $orderby, true, false, true);
         }
         $lists['group_by'] = $formModel->getElementList('group_by', $row->group_by, true, false, true);
         //needs to be table.element format for where statement to work
         $formModel->_addDbQuote = true;
         $lists['filter-fields'] = $formModel->getElementList('params[filter-fields][]', '', false, false, true);
         $lists['db_primary_key'] = $formModel->getElementList('db_primary_key', $row->db_primary_key);
         $formModel->_addDbQuote = false;
         //but you can now add table joins
         $connModel->setId($row->connection_id);
         $connModel->getConnection($row->connection_id);
         ///load in current connection
         $joinFromTables[] = JHTML::_('select.option', '', '-');
         $joinFromTables[] = JHTML::_('select.option', $row->db_table_name, $row->db_table_name);
         $lists['defaultjoin'] = $connModel->getTableDdForThisConnection('', 'table_join[]', '', 'inputbox table_key');
         $lists['tablejoin'] = $connModel->getTableDdForThisConnection('', 'table_join[]', '', 'inputbox table_join_key');
         //make a drop down validation type for each validation
         $aActiveJoinTypes = array();
         if (is_array($aJoinObjs)) {
             for ($ff = 0; $ff < count($aJoinObjs); $ff++) {
                 $oJoin = $aJoinObjs[$ff];
                 $fields = array();
                 $aFields = $model->getDBFields($oJoin->join_from_table);
                 foreach ($aFields as $o) {
                     if (is_array($o)) {
                         foreach ($o as $f) {
                             $fields[] = $f->Field;
                         }
                     } else {
                         $fields[] = $o->Field;
                     }
                 }
                 $aJoinObjs[$ff]->joinFormFields = $fields;
                 $aFields = $model->getDBFields($oJoin->table_join);
                 $fields = array();
                 foreach ($aFields as $o) {
                     if (is_array($o)) {
                         foreach ($o as $f) {
                             $fields[] = $f->Field;
                         }
                     } else {
                         $fields[] = $o->Field;
                     }
                 }
                 $aJoinObjs[$ff]->joinToFields = $fields;
             }
             $lists['defaultJoinTables'] = $connModel->getThisTables(true);
         }
     }
     if ($row->id != '') {
         //only existing tables can have a menu linked to them
         $and = "\n AND link LIKE '%index.php?option=com_fabrik%' AND link LIKE '%view=table%'";
         $and .= " AND params LIKE '%tableid=" . $row->id . "'";
         $menus = FabrikHelperMenu::Links2Menu('component', $and);
     } else {
         $menus = null;
     }
     $lists['filter-access'] = $this->getFilterACLList($row);
     $lists['menuselect'] = FabrikHelperMenu::MenuSelect();
     $lists['tableTemplates'] = FabrikHelperAdminHTML::templateList('table', 'template', $row->template);
     // make the filter action drop down
     $filterActions[] = JHTML::_('select.option', 'onchange', JText::_('ON CHANGE'));
     $filterActions[] = JHTML::_('select.option', 'submitform', JText::_('SUBMIT FORM'));
     $lists['filter_action'] = JHTML::_('select.genericlist', $filterActions, 'filter_action', 'class="inputbox" size="1" ', 'value', 'text', $row->filter_action);
     //make the order direction drop down
     $orderDir[] = JHTML::_('select.option', 'ASC', JText::_('ASCENDING'));
     $orderDir[] = JHTML::_('select.option', 'DESC', JText::_('DESCENDING'));
     $orderdirs = explode(GROUPSPLITTER2, $row->order_dir);
     $lists['order_dir'] = array();
     foreach ($orderdirs as $orderdir) {
         $lists['order_dir'][] = JHTML::_('select.genericlist', $orderDir, 'order_dir[]', 'class="inputbox" size="1" ', 'value', 'text', $orderdir);
     }
     $linkedTables = $model->getJoinsToThisKey();
     $aExisitngLinkedTables = $params->get('linkedtable', '', '_default', 'array');
     $aExisitngLinkedForms = $params->get('linkedform', '', '_default', 'array');
     $aExistingTableHeaders = $params->get('linkedtableheader', '', '_default', 'array');
     $aExistingFormHeaders = $params->get('linkedformheader', '', '_default', 'array');
     $linkedform_linktype = $params->get('linkedform_linktype', '', '_default', 'array');
     $linkedtable_linktype = $params->get('linkedtable_linktype', '', '_default', 'array');
     $tableLinkTexts = $params->get('linkedtabletext', '', '_default', 'array');
     $formLinkTexts = $params->get('linkedformtext', '', '_default', 'array');
     $lists['linkedtables'] = array();
     $f = 0;
     $used = array();
     foreach ($linkedTables as $linkedTable) {
         $key = $linkedTable->table_id . '-' . $linkedTable->form_id . '-' . $linkedTable->element_id;
         if (!array_key_exists($f, $aExisitngLinkedTables)) {
             $aExisitngLinkedTables[$f] = '0';
         }
         if (!array_key_exists($f, $linkedtable_linktype)) {
             $linkedtable_linktype[$f] = '0';
         }
         //fiddle ordering
         $index = array_search($key, $aExisitngLinkedTables);
         $index = $index === false ? $f : $index;
         if (!array_search($key, $aExisitngLinkedTables)) {
             for ($fcounter = 0; $fcounter <= count($linkedTables); $fcounter++) {
                 if (!in_array($fcounter, $used)) {
                     $index = $fcounter;
                     break;
                 }
             }
         }
         $used[] = $index;
         $yeschecked = in_array($linkedTable->db_table_name, $aExisitngLinkedTables) || JArrayHelper::getValue($aExisitngLinkedTables, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $el = '<label><input name="params[linkedtable][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $el .= '<label><input name="params[linkedtable][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $yeschecked = in_array($linkedTable->db_table_name, $linkedtable_linktype) || JArrayHelper::getValue($linkedtable_linktype, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $linkType1 = '<label><input name="params[linkedtable_linktype][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $linkType1 .= '<label><input name="params[linkedtable_linktype][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $tableHeader = '<input name="params[linkedtableheader][' . $key . ']" value="' . @$aExistingTableHeaders[$index] . '" size="16" >';
         $label = str_replace(array("\n", "\r", "<br>", "</br>"), '', $linkedTable->tablelabel);
         $hover = JText::_('ELEMENT') . ': ' . $linkedTable->element_label . " [{$linkedTable->plugin}]. {tmpl key =" . $linkedTable->element_id . "_table_heading}";
         $tableLinkText = '<input name="params[linkedtabletext][' . $key . ']" value="' . @$tableLinkTexts[$index] . '" size="16" >';
         $linkedArray = array($label, $hover, $el, $tableHeader, $linkType1, $tableLinkText);
         $lists['linkedtables'][$index] = $linkedArray;
     }
     ksort($lists['linkedtables']);
     $lists['linkedforms'] = array();
     $f = 0;
     $used = array();
     /***/
     foreach ($linkedTables as $linkedTable) {
         $key = $linkedTable->table_id . '-' . $linkedTable->form_id . '-' . $linkedTable->element_id;
         if (!array_key_exists($f, $aExisitngLinkedForms)) {
             $aExisitngLinkedForms[$f] = '0';
         }
         if (!array_key_exists($f, $linkedform_linktype)) {
             $linkedform_linktype[$f] = '0';
         }
         //fiddle ordering
         $index = array_search($key, $aExisitngLinkedForms);
         $index = $index === false ? $f : $index;
         if (!array_search($key, $aExisitngLinkedForms)) {
             for ($fcounter = 0; $fcounter <= count($linkedTables); $fcounter++) {
                 if (!in_array($fcounter, $used)) {
                     $index = $fcounter;
                     break;
                 }
             }
         }
         $used[] = $index;
         $yeschecked = in_array($linkedTable->db_table_name, $aExisitngLinkedForms) || JArrayHelper::getValue($aExisitngLinkedForms, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $el2 = '<label><input name="params[linkedform][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $el2 .= '<label><input name="params[linkedform][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $yeschecked = in_array($linkedTable->db_table_name, $linkedform_linktype) || JArrayHelper::getValue($linkedform_linktype, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $linkType2 = '<label><input name="params[linkedform_linktype][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $linkType2 .= '<label><input name="params[linkedform_linktype][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $formHeader = '<input name="params[linkedformheader][' . $key . ']" value="' . @$aExistingFormHeaders[$index] . '" size="16" >';
         $label = str_replace(array("\n", "\r", "<br>", "</br>"), '', $linkedTable->tablelabel);
         $formLinkText = '<input name="params[linkedformtext][' . $key . ']" value="' . @$formLinkTexts[$index] . '" size="16" >';
         $linkedArray = array($label, $el2, $formHeader, $linkType2, $formLinkText);
         $linkedArray['formhover'] = JText::_('ELEMENT') . ': ' . $linkedTable->element_label . " [{$linkedTable->plugin}]. {tmpl key =" . $linkedTable->element_id . "_form_heading}";
         $lists['linkedforms'][$index] = $linkedArray;
     }
     ksort($lists['linkedforms']);
     /*****/
     $pluginManager = JModel::getInstance('Pluginmanager', 'FabrikModel');
     $pluginManager->getPlugInGroup('table');
     // Create the form (publish dates should be stored as UTC)
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'table.xml');
     $form->bind($row);
     $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S'));
     $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
     if ($cid[0] == 0 || $form->get('publish_down') == '' || $form->get('publish_down') == $db->getNullDate()) {
         $form->set('publish_down', JText::_('NEVER'));
     } else {
         $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
     }
     $form->loadINI($row->attribs);
     $session->set('com_fabrik.admin.table.edit.model', $model);
     FabrikViewTable::edit($row, $lists, $connectionTables, $menus, $fabrikid, $params, $pluginManager, $model, $form);
 }
Esempio n. 12
0
 /**
  * Save cron
  */
 function save()
 {
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     jimport('joomla.utilities.date');
     $user =& JFactory::getUser();
     $db =& JFactory::getDBO();
     $row =& JTable::getInstance('cron', 'Table');
     $post = JRequest::get('post');
     // $$$ hugh - published state is checkbox, so doesn't seem to be in post array if not selected
     if (!isset($post['state'])) {
         $post['state'] = '0';
     }
     if (!$row->bind($post)) {
         return JError::raiseWarning(500, $row->getError());
     }
     $now = new JDate();
     if ($row->id == 0) {
         $row->created = $now->toMySQL();
         $row->created_by = $user->get('id');
         $row->created_by_alias = $user->get('username');
     } else {
         $row->modified = $now->toMySQL();
         $row->modified_by = $user->get('id');
     }
     //set the lastrun date to be that shown in the date selections
     echo JRequest::getVar('lastrun');
     // 	save params
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'xml' . DS . 'cron.xml');
     $row->attribs = $params->updateAttribsFromParams(JRequest::getVar('params', array(), 'post', 'array'));
     $this->crontab_set($row->frequency, $row->unit);
     if (!$row->store()) {
         return JError::raiseWarning(500, $row->getError());
     }
     $row->checkin();
     $task = JRequest::getCmd('task');
     switch ($task) {
         case 'apply':
             $link = 'index.php?option=com_fabrik&c=cron&task=edit&cid[]=' . $row->id;
             break;
         case 'save':
         default:
             $link = 'index.php?option=com_fabrik&c=cron';
             break;
     }
     $this->setRedirect($link, JText::_('CRON SAVED'));
 }
Esempio n. 13
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;
 }
Esempio n. 14
0
 /**
  * when saving a table that links to a database for the first time we
  * need to create all the elements based on the database table fields and their
  * column type
  *
  * @access private
  * @param int group id
  * @param array newly created table data
  * @param array of element objects - if this is not empty then we've come from the csv import and the elements
  * have already been defined, use this instead of the field analysis to create correctly typed elements
  */
 function _createLinkedElements($groupId, $aTableData, $aSpecificElements = array())
 {
     $db =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $session =& JFactory::getSession();
     $config =& JFactory::getConfig();
     $createdate = JFactory::getDate();
     $createdate = $createdate->toMySQL();
     $tableName = JRequest::getVar('db_table_name');
     $pluginManager =& $this->getPluginManager();
     $ordering = 0;
     $fabrikDb =& $this->getDb();
     if (!empty($aSpecificElements)) {
         //we're asking the method to create predefined elements - e.g. when installing sample data.
         foreach ($aSpecificElements as $elementModel) {
             $element =& $elementModel->getElement();
             if ($element->label == 'id') {
                 $element->hidden = 1;
                 $element->primary_key = 1;
                 $element->auto_increment = 1;
             } else {
                 $element->hidden = 0;
             }
             $element->name = strtolower(str_replace(' ', '', $element->name));
             $element->group_id = $groupId;
             $element->created = $createdate;
             $element->created_by = $user->get('id');
             $element->created_by_alias = $user->get('username');
             $element->state = 1;
             $element->show_in_table_summary = 1;
             $element->width = 30;
             $element->height = 6;
             $element->ordering = 99999;
             $element->attribs = $elementModel->getDefaultAttribs();
             $element->store();
             $where = " group_id = " . (int) $element->group_id;
             $element->reorder($where);
         }
     } else {
         //here we're importing directly from the database schema
         $db->setQuery("SELECT id FROM #__fabrik_tables WHERE " . $db->nameQuote('db_table_name') . " = " . $db->Quote($tableName));
         $id = $db->loadResult();
         $elementModel =& JModel::getInstance('Element', 'FabrikModel');
         if ($id) {
             //a fabrik table already exists - so we can copy the formatting of its elements
             $groupTableModel = JModel::getInstance('table', 'FabrikModel');
             $groupTableModel->setId($id);
             $table = $groupTableModel->getTable();
             //$this->_oForm = null; //reset form so that it loads new table form
             $groups = $groupTableModel->getFormGroupElementData();
             $newElements = array();
             foreach ($groups as $groupModel) {
                 // if we are saving a new table and the previously found tables group is a join
                 // then don't add its elements to the table as they don't exist in the database table
                 // we are linking to
                 // $$$ hugh - removed id == 0 test, as this gets called from _makeNewJoin as well, see #608
                 //if ($groupModel->isJoin() && JRequest::getCmd('task') == 'save' && JRequest::getInt('id') == 0) {
                 if ($groupModel->isJoin() && JRequest::getCmd('task') == 'save') {
                     continue;
                 }
                 $elementModels =& $groupModel->getMyElements();
                 foreach ($elementModels as $elementModel) {
                     $element =& $elementModel->getElement();
                     $copy = $elementModel->copyRow($element->id, '', $groupId);
                     $newElements[$element->id] = $copy->id;
                 }
             }
             $elementModel =& JModel::getInstance('Element', 'FabrikModel');
             foreach ($newElements as $origId => $newId) {
                 $plugin = $pluginManager->getElementPlugin($newId);
                 $plugin->finalCopyCheck($newElements);
             }
         } else {
             //$$$ rob since 2.0.4 - lets see if theres a session element / plugin map set up (used in balsamiq to fabrik component)
             $map = (array) $session->get('com_fabrik.list.create.elementmap');
             $elementTypes = JRequest::getVar('elementtype', array(), 'default', 'array');
             $fields = $fabrikDb->getTableFields(array("`{$tableName}`"));
             $fields = $fields["`{$tableName}`"];
             $key = $this->getPrimaryKeyAndExtra($tableName);
             // no existing fabrik table so we take a guess at the most
             //relavent element types to  create
             $elementLabels = JRequest::getVar('elementlabels', array(), 'default', 'array');
             foreach ($fields as $label => $type) {
                 $element =& JTable::getInstance('Element', 'Table');
                 $info = array();
                 $element->sub_values = '';
                 $element->sub_labels = '';
                 //$element->label = str_replace("_", " ", $label);
                 if (array_key_exists($ordering, $elementTypes)) {
                     //if importing from a CSV file then we have userselect field definitions
                     $plugin = $elementTypes[$ordering];
                 } else {
                     //$$$ rob since 2.0.4 - lets see if theres a session element / plugin map set up (used in balsamiq to fabrik component)
                     if (array_key_exists($tableName . '___' . $label, $map)) {
                         $info = $map[$tableName . '___' . $label];
                         //check its in the right group (or not assinged if from tbl)
                         if (!is_null($info['groupid']) && $info['groupid'] == $groupId) {
                             $plugin = $info['plugin'];
                             $element->bind($info);
                         } else {
                             continue;
                         }
                     } else {
                         //if the field is the primary key and it's an INT type set the plugin to be the fabrik internal id
                         if ($key[0]['colname'] == $label && strtolower(substr($key[0]['type'], 0, 3)) === 'int') {
                             $plugin = 'fabrikinternalid';
                         } else {
                             //otherwise guestimate!
                             switch ($type) {
                                 case "int":
                                 case "tinyint":
                                 case "varchar":
                                     $plugin = 'fabrikfield';
                                     break;
                                 case "text":
                                 case "tinytext":
                                 case "mediumtext":
                                 case "longtext":
                                     $plugin = 'fabriktextarea';
                                     break;
                                 case "datetime":
                                 case "date":
                                 case "time":
                                 case "timestamp":
                                     $plugin = 'fabrikdate';
                                     break;
                                 default:
                                     $plugin = 'fabrikfield';
                                     break;
                             }
                         }
                     }
                 }
                 if ($plugin == '') {
                     continue;
                 }
                 $element->plugin = $plugin;
                 $element->hidden = $element->label == 'id' ? '1' : '0';
                 $element->group_id = $groupId;
                 $element->name = $label;
                 $element->created = $createdate;
                 $element->created_by = $user->get('id');
                 $element->created_by_alias = $user->get('username');
                 $element->state = '1';
                 $element->show_in_table_summary = '1';
                 switch ($plugin) {
                     case 'fabriktextarea':
                         $element->width = '40';
                         break;
                     case 'fabrikdate':
                         $element->width = '10';
                         break;
                     default:
                         $element->width = '30';
                         break;
                 }
                 $a = new fabrikParams($elementModel->getDefaultAttribs(), JPATH_SITE . '/administrator/components/com_fabrik/models/element.xml');
                 $aparams = JArrayHelper::getValue($info, 'params', array());
                 $a->bind($aparams);
                 $element->height = '6';
                 $element->ordering = $ordering;
                 $element->attribs = $a->toString();
                 if ($element->label == '') {
                     $element->label = JArrayHelper::getValue($elementLabels, $ordering, str_replace("_", " ", $label));
                 }
                 if (!$element->store()) {
                     return JError::raiseError(500, $element->getError());
                 }
                 $elementModel =& $pluginManager->getPlugIn($element->plugin, 'element');
                 $elementModel->setId($element->id);
                 $elementModel->_element = $element;
                 // hack for user element
                 $details = array('group_id' => $element->group_id);
                 JRequest::setVar('details', $details);
                 $elementModel->onSave();
                 $ordering++;
             }
         }
     }
 }