/** * load up the cck view * @return unknown_type */ protected function cck() { if (JRequest::getVar('task') === 'cck') { $model = $this->getModel(); $params = $model->getParams(); $row = $model->getForm(); JHTML::script('admincck.js', 'administrator/components/com_fabrik/views/', true); $document = JFactory::getDocument(); $opts = new stdClass(); $opts->livesite = JURI::base(); $opts->ename = JRequest::getVar('e_name'); $opts->catid = JRequest::getInt('catid'); $opts->section = JRequest::getInt('section'); $opts->formid = $row->id; $tmpl = $row->form_template == '' ? "default" : $row->form_template; $tmpl = JRequest::getVar('cck_layout', $tmpl); $opts->tmplList = FabrikHelperAdminHTML::templateList('form', 'fabrik_cck_template', $tmpl); $views = array(); $views[] = JHTML::_('select.option', 'form'); $views[] = JHTML::_('select.option', 'details'); $selView = JRequest::getVar('cck_view'); $opts->viewList = JHTML::_('select.radiolist', $views, 'fabrik_cck_view', 'class="inputbox"', 'value', 'text', $selView); $opts = json_encode($opts); $document->addScriptDeclaration("head.ready(function() {\r\n\t\tnew adminCCK({$opts});\r\n\t\t});"); } }
/** * 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); }
/** * Edit a connection */ function edit() { $user =& JFactory::getUser(); $db =& JFactory::getDBO(); $row =& JTable::getInstance('package', 'Table'); if ($this->_task == 'edit') { $cid = JRequest::getVar('cid', array(0), 'method', 'array'); $cid = array((int) $cid[0]); } else { $cid = array(0); } $row->load($cid[0]); if ($cid) { $row->checkout($user->get('id')); } $db->setQuery("SELECT id AS value, label AS text FROM #__fabrik_tables"); $tables = $db->loadObjectList(); $tables = array_merge(array(JHTML::_('select.option', '', '-')), $tables); $model = JModel::getInstance('Package', 'FabrikModel'); $model->setId($cid[0]); $model->getPackage(); $selectTables = $model->loadTables(); $aSelTables = array(); if (!empty($selectTables)) { foreach ($selectTables as $selTable) { $aSelTables[] = JHTML::_('select.genericlist', $tables, 'tables[]', 'class="inputbox"', 'value', 'text', $selTable->id, "table_" . $selTable->id); } } else { $aSelTables[] = JHTML::_('select.genericlist', $tables, 'tables[]', 'class="inputbox"', 'value', 'text', ''); } $lists['template'] = FabrikHelperAdminHTML::templateList('package', $row->template); require_once JPATH_COMPONENT . DS . 'views' . DS . 'package.php'; FabrikViewPackage::edit($row, $aSelTables, $lists); }
/** * Edit a form */ function edit() { $user =& JFactory::getUser(); $session =& JFactory::getSession(); $db =& JFactory::getDBO(); $lists = array(); $row =& JTable::getInstance('form', 'Table'); if ($this->_task == 'edit') { $cid = JRequest::getVar('cid', array(0), 'method', 'array'); $cid = array((int) $cid[0]); } else { $cid = array(0); } $row->load($cid[0]); if ($cid) { $row->checkout($user->get('id')); } $model = JModel::getInstance('Form', 'FabrikModel'); $model->setId($cid[0]); $model->getTable(); $groupModels =& $model->getGroupsHiarachy(); $possible_email_receipt_fields[] = JHTML::_('select.option', '', 'n/a'); foreach ($groupModels as $groupModel) { $groupModel->_form =& $model; $elementModels =& $groupModel->getMyElements(); foreach ($elementModels as $elementModel) { if ($elementModel->isReceiptElement()) { $element =& $elementModel->getElement(); $possible_email_receipt_fields[] = JHTML::_('select.option', $element->name, $element->label); } } } // get params definitions $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'xml' . DS . 'form.xml'); require_once JPATH_COMPONENT . DS . 'views' . DS . 'form.php'; // get a list of used groups $sql = "SELECT #__fabrik_formgroup.group_id AS value,\n\t\t\t#__fabrik_groups.name AS text\n\t\t\tFROM #__fabrik_formgroup\n\t\t\tLEFT JOIN #__fabrik_groups\n\t\t\tON #__fabrik_formgroup.group_id = #__fabrik_groups.id\n\t\t\tWHERE #__fabrik_formgroup.form_id = '" . $cid[0] . "'\n\t\t\tAND #__fabrik_groups.name <> ''\n\t\t\tORDER BY #__fabrik_formgroup.ordering"; $db->setQuery($sql); $current_groups = $db->loadObjectList(); $lists['current_groups'] = $current_groups; $lists['current_grouplist'] = JHTML::_('select.genericlist', $current_groups, 'current_groups', "class=\"inputbox\" style=\"width:100%;\" size=\"10\" ", 'value', 'text', '/'); // get a list of available groups - need to make the sql only return groups not already listed in mos_fabrik_fromgroup for $id //$$$ only unused groups can be assigned now - simplifies a load of stuff for us! $db->setQuery("SELECT DISTINCT(group_id) FROM #__fabrik_formgroup"); $usedgroups = $db->loadResultArray(); if (!empty($usedgroups)) { $db->setQuery("SELECT id AS value, name AS text FROM #__fabrik_groups WHERE id NOT IN(" . implode(",", $usedgroups) . ") ORDER BY `text`"); $groups = $db->loadObjectList(); } else { $groups = array(); } $lists['groups'] = $groups; $lists['grouplist'] = JHTML::_('select.genericlist', $groups, 'groups', "class=\"inputbox\" size=\"10\" style=\"width:100%;\" ", 'value', 'text', null); if ($cid[0] != 0) { $row->_database_name = $model->getTableName(); $row->_connection_id = $model->getListModel()->getTable()->connection_id; } else { //this is a new form so fill in some default values $row->error = JText::_('SOME OF THE FORM DATA IS MISSING'); $row->submit_button_label = JText::_('SUBMIT'); $row->_database_name = ''; $row->_connection_id = ''; $menus = array(); } //get the view only templates $viewTemplate = $row->view_only_template == '' ? "default" : $row->view_only_template; $lists['viewOnlyTemplates'] = FabrikHelperAdminHTML::templateList('form', 'view_only_template', $viewTemplate); //get the form templates $formTemplate = $row->form_template == '' ? "default" : $row->form_template; $lists['formTemplates'] = FabrikHelperAdminHTML::templateList('form', 'form_template', $formTemplate); $pluginManager = JModel::getInstance('Pluginmanager', 'FabrikModel'); $pluginManager->getPlugInGroup('form'); // Create the form $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'form.xml'); $form->bind($row); 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->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')); $form->loadINI($row->attribs); $session->set('com_fabrik.admin.form.edit.model', $model); FabrikViewForm::edit($row, $pluginManager, $lists, $params, $form); }