Example #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);
			}
		}
	}
Example #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);
         }
     }
 }
Example #3
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);
 }
Example #4
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;
 }
Example #5
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;
 }