/** * Display the form to add or edit a table * @param object table * @param array the drop down lists used on the form * @param array connection tables * @param object menus * @param string compoent action * @param int form id that the table links to? * @param object parameters * @param object plugin mangager * @param object table model */ function edit($row, $lists, $connectionTables, $menus, $fabrikid, $params, $pluginManager, $model, $form) { JHTML::stylesheet('fabrikadmin.css', 'administrator/components/com_fabrik/views/'); FabrikViewTable::setTableToolbar(); JRequest::setVar('hidemainmenu', 1); $document =& JFactory::getDocument(); FabrikHelperHTML::script('namespace.js', 'administrator/components/com_fabrik/views/', true); FabrikHelperHTML::script('pluginmanager.js', 'administrator/components/com_fabrik/views/', true); FabrikHelperHTML::script('admintable.js', 'administrator/components/com_fabrik/views/', true); JFilterOutput::objectHTMLSafe($row); jimport('joomla.html.editor'); //just until joomla uses mootools 1.2 FabrikHelperHTML::mootools(); require_once COM_FABRIK_FRONTEND . DS . 'helpers' . DS . 'editor.php'; jimport('joomla.html.pane'); FabrikHelperHTML::tips(); $editor =& FabrikHelperHTML::getEditor(); $pane =& JPane::getInstance(); $fbConfig =& JComponentHelper::getParams('com_fabrik'); $opts = new stdClass(); $opts->mooversion = FabrikWorker::getMooVersion() == 1 ? 1.2 : 1.1; $opts = FastJSON::encode($opts); $lang = new stdClass(); $lang->action = JText::_('ACTION'); $lang->do = JText::_('DO'); $lang->del = JText::_('DELETE'); $lang->in = JText::_('IN'); $lang->on = JText::_('ON'); $lang->options = JText::_('OPTIONS'); $lang->please_select = JText::_('COM_FABRIK_PLEASE_SELECT'); $lang = FastJSON::encode($lang); $js = "window.addEvent('domready', function() {\n \t\tvar aPlugins = [];\n"; $js .= $pluginManager->getAdminPluginJs('table', $row, $lists); $js .= "controller = new TablePluginManager(aPlugins, {$lang}, {$opts});\n"; $usedPlugins = $params->get('plugin', '', '_default', 'array'); $js .= $pluginManager->getAdminSelectedPluginJS('table', $row, $lists, $params); $js .= "});\n"; $js .= "var connectiontables = new Array;\n"; $i = 0; if (is_array($connectionTables)) { foreach ($connectionTables as $k => $items) { foreach ($items as $v) { $js .= "connectiontables[" . $i++ . "] = new Array('{$k}','" . addslashes($v->value) . "','" . addslashes($v->text) . "');\n\t\t"; } } } $js .= "\n\t\t\tfunction submitbutton(pressbutton) {\n\t\t\t\tif (pressbutton == 'cancel') {\n\t\t\t\t\tsubmitform( pressbutton);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tvar err = '';"; $js .= $editor->save('introduction'); $js .= "if(\$('label').value == '') {\n\t\t\t\t\terr = err +'" . JText::_('PLEASE ENTER A TABLE LABEL', true) . '\\n' . "';\n\t\t\t\t}\n\n\t\t\t\tif(\$('database_name')) {\n\t\t\t\t\tif(\$('database_name').value == '') {\n\t\t\t\t\t\tif(\$('connection_id')) {\n\t\t\t\t\t\t\tif(\$('connection_id').value == '-1') {\n\t\t\t\t\t\t\t\terr = err +'" . JText::_('PLEASE SELECT A CONNECTION', true) . '\\n' . "';\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif(\$('tablename')) {\n\t\t\t\t\t\t\tif(\$('tablename').value == '' || \$('tablename').value == '-1') {\n\t\t\t\t\t\t\t\terr = err + '" . JText::_('PLEASE SELECT A DATABASE TABLE', true) . '\\n' . "';\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (err == '') {\n\t\t\t\t\tsubmitform( pressbutton);\n\t\t\t\t}else{\n\t\t\t\t\talert (err);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tvar joinCounter = 0;"; $document->addScriptDeclaration($js); FabrikHelperHTML::cleanMootools(); ?> <form action="index.php" method="post" name="adminForm"> <table style="width: 100%"> <tr> <td style="width: 50%" valign="top"> <fieldset class="adminform"><legend><?php echo JText::_('DETAILS'); ?> </legend> <table class="admintable"> <tr> <td class="key"><label for="label"><?php echo JText::_('LABEL'); ?> </label></td> <td><input class="inputbox" type="text" id="label" name="label" size="50" value="<?php echo $row->label; ?> " /></td> </tr> <tr> <td class="key"><?php echo JText::_('INTRODUCTION'); ?> </td> <td><?php echo $editor->display('introduction', $row->introduction, '100%', '200', '45', '25', false); ?> </td> </tr> </table> </fieldset> <fieldset><legend><?php echo JText::_('FILTERS'); ?> </legend> <table class="admintable"> <tr> <td class="key"><?php echo JText::_('FILTER TRIGGER'); ?> </td> <td><?php echo $lists['filter_action']; ?> </td> </tr> </table> <?php echo $form->render('params', 'filters'); ?> </fieldset> <fieldset><legend><?php echo JText::_('NAVIGATION'); ?> </legend> <table class="admintable"> <tr> <td class="key"><label for="rows_per_page"><?php echo JText::_('ROWS PER PAGE'); ?> </label> </td> <td><input type="text" name="rows_per_page" id="rows_per_page" class="inputbox" value="<?php echo $row->rows_per_page != '' ? $row->rows_per_page : 10; ?> " size="3" /></td> </tr> </table> <?php echo $form->render('params', 'navigation'); ?> </fieldset> <fieldset><legend><?php echo JText::_('LAYOUT'); ?> </legend> <table class="admintable"> <tr> <td class="key"><?php echo JText::_('TEMPLATE'); ?> </td> <td><?php print_r($lists['tableTemplates']); ?> </td> </tr> </table> <?php echo $form->render('params', 'layout'); ?> </fieldset> <fieldset><legend><?php echo JText::_('COM_FABRIK_DETAIL_LINKS'); ?> </legend> <?php echo $form->render('params', 'detaillinks'); ?> </fieldset> <fieldset><legend><?php echo JText::_('COM_FABRIK_EDIT_LINKS'); ?> </legend> <?php echo $form->render('params', 'editlinks'); ?> </fieldset> <fieldset><legend><?php echo JText::_('COM_FABRIK_ADD_LINK'); ?> </legend> <?php echo $form->render('params', 'addlink'); ?> </fieldset> <fieldset><legend><?php echo JText::_('Notes'); ?> </legend> <?php echo $form->render('params', 'notes'); ?> </fieldset> <fieldset><legend><?php echo JText::_('Advanced'); ?> </legend> <?php echo $form->render('params', 'advanced'); ?> </fieldset> <?php if ($fbConfig->get('use_wip')) { ?> <fieldset><legend><?php echo JText::_('WORK IN PROGRESS'); ?> </legend> <?php echo $form->render('params', 'wip'); ?> <?php } ?> </td> <td valign="top"><?php echo $pane->startPane("content-pane"); echo $pane->startPanel(JText::_('PUBLISHING'), "publish-page"); echo $form->render('details'); ?> <fieldset><legend><?php echo JText::_('RSS OPTIONS'); ?> </legend> <?php echo $form->render('params', 'rss'); ?> </fieldset> <fieldset><legend><?php echo JText::_('CSV OPTIONS'); ?> </legend> <?php echo $form->render('params', 'csv'); ?> </fieldset> <fieldset><legend><?php echo JText::_('SEARCH'); ?> </legend> <?php echo $form->render('params', 'search'); ?> </fieldset> <?php echo $pane->endPanel(); echo $pane->startPanel(JText::_('ACCESS'), "access-page"); ?> <fieldset><legend><?php echo JText::_('ACCESS'); ?> </legend> <?php echo $form->render('params', 'access'); ?> </fieldset> <?php echo $pane->endPanel(); echo $pane->startPanel(JText::_('DATA'), "tabledata-page"); ?> <fieldset><legend><?php echo JText::_('DATA'); ?> </legend> <table class="admintable"> <tr> <td class="key"><?php echo JText::_('CONNECTION'); ?> </td> <td><?php echo $lists['connections']; ?> </td> </tr> <?php if ($row->id == 0) { ?> <tr> <td class="key"><?php echo JText::_('CREATE NEW TABLE'); ?> </td> <td><input id="database_name" name="_database_name" size="40" /></td> </tr> <tr> <td colspan="2"><?php echo JText::_('OR'); ?> </td> </tr> <?php } ?> <tr> <td class="key"><?php echo JText::_('LINK TO TABLE'); ?> </td> <td><?php echo $lists['tablename']; ?> </td> </tr> <?php if ($row->id != '') { ?> <tr> <td class="key"><label for="db_primary_key"> <?php echo JHTML::_('tooltip', JText::_("PRIMARY KEY DESC"), JText::_('PRIMARY KEY'), 'tooltip.png', JText::_('PRIMARY KEY')); ?> </label></td> <td><?php echo $lists['db_primary_key']; ?> </td> </tr> <tr> <td class="key"><?php echo JText::_('AUTO INCREMENT'); ?> </td> <td> <label> <input type="radio" name="auto_inc" value="0" <?php echo $row->auto_inc ? '' : 'checked="checked"'; ?> /> <?php echo JText::_('No'); ?> </label> <label> <input type="radio" name="auto_inc" value="1" <?php echo $row->auto_inc ? 'checked="checked"' : ''; ?> /> <?php echo JText::_('YES'); ?> </label> </td> </tr> <?php } ?> <tr> <td class="key"><label for="order_by"><?php echo JText::_('ORDER BY'); ?> </label></td> <td id="orderByTd"><?php for ($o = 0; $o < count($lists['order_by']); $o++) { ?> <div class="orderby_container" style="margin-bottom:3px"> <?php echo $lists['order_by'][$o]; ?> <?php if ($row->id !== 0) { echo JArrayHelper::getValue($lists['order_dir'], $o, $lists['order_dir'][0]); ?> <a class="addOrder" href="#"><img src="components/com_fabrik/images/add.png" label="<?php echo JText::_('ADD'); ?> " alt="<?php echo JText::_('ADD'); ?> " /></a> <a class="deleteOrder" href="#"><img src="components/com_fabrik/images/remove.png" label="<?php echo JText::_('REMOVE'); ?> " alt="<?php echo JText::_('REMOVE'); ?> " /></a> <?php } ?> </div> <?php } ?> </td> </tr> </table> </fieldset> <fieldset><legend><?php echo JText::_('GROUP BY'); ?> </legend> <table class="admintable"> <tr> <td class="key"><label for="group_by"><?php echo JText::_('GROUP BY'); ?> </label> </td> <td id="groupByTd"><?php echo $lists['group_by']; ?> </td> </tr> </table> <?php echo $form->render('params', 'grouping'); ?> </fieldset> <fieldset><legend><?php echo JHTML::_('tooltip', JText::_('PREFILTER DESC'), JText::_('PREFILTER'), 'tooltip.png', JText::_('PREFILTER')); ?> </legend> <a class="addButton" href="#" onclick="oAdminFilters.addFilterOption(); return false;"><?php echo JText::_('ADD'); ?> </a> <?php echo $form->render('params', 'prefilter'); ?> <table class="adminform" width="100%"> <tbody id="filterContainer"> </tbody> </table> </fieldset> <fieldset><legend> <?php echo JHTML::_('tooltip', JText::_('JOIN DESC'), JText::_('JOINS'), 'tooltip.png', JText::_('JOINS')); ?> </legend> <?php if ($row->id != 0) { ?> <a href="#" id="addAJoin" class="addButton"><?php echo JText::_('ADD'); ?> </a> <div id="joindtd"></div> <?php echo $form->render('params', 'joins'); ?> <?php } else { echo JText::_('Available once saved'); } ?> </fieldset> <fieldset><legend> <?php echo JHTML::_('tooltip', JText::_('RELATED DATA DESC'), JText::_('RELATED DATA'), 'tooltip.png', JText::_('RELATED DATA')); ?> </legend> <?php if (empty($lists['linkedtables'])) { echo "<i>" . JText::_('No other tables link here') . "</i>"; } else { ?> <table class="adminlist linkedTables"> <thead> <tr> <th></th> <th><?php echo JText::_('TABLE'); ?> </th> <th><?php echo JText::_('LINK TO TABLE'); ?> </th> <th><?php echo JText::_('HEADING'); ?> </th> <th><?php echo JText::_('BUTTON_TEXT'); ?> </th> <th><?php echo JText::_('POPUP'); ?> </th> </tr> </thead> <tbody> <?php $i = 0; foreach ($lists['linkedtables'] as $linkedTable) { ?> <tr class="row<?php echo $i % 2; ?> "> <td class="handle"></td> <td><?php echo JHTML::_('tooltip', $linkedTable[1], $linkedTable[0], 'tooltip.png', $linkedTable[0]); ?> <td><?php echo $linkedTable[2]; ?> </td> <td><?php echo $linkedTable[3]; ?> </td> <td><?php echo $linkedTable[5]; ?> </td> <td><?php echo $linkedTable[4]; ?> </td> </tr> <?php $i++; } ?> </tbody> </table> <table class="adminlist linkedForms" style="margin-toip:20px"> <thead> <tr> <th></th> <th><?php echo JText::_('TABLE'); ?> </th> <th><?php echo JText::_('LINK TO FORM'); ?> </th> <th><?php echo JText::_('HEADING'); ?> </th> <th><?php echo JText::_('BUTTON_TEXT'); ?> </th> <th><?php echo JText::_('POPUP'); ?> </th> </tr> </thead> <tbody> <?php $i = 0; foreach ($lists['linkedforms'] as $linkedForm) { ?> <tr class="row<?php echo $i % 2; ?> "> <td class="handle"></td> <td><?php echo JHTML::_('tooltip', $linkedForm['formhover'], $linkedForm[0], 'tooltip.png', $linkedForm[0]); ?> <td><?php echo $linkedForm[1]; ?> </td> <td><?php echo $linkedForm[2]; ?> </td> <td><?php echo $linkedForm[4]; ?> </td> <td><?php echo $linkedForm[3]; ?> </td> </tr> <?php $i++; } ?> </tbody> </table> <?php } ?> </fieldset> <?php echo $pane->startPanel(JText::_('PLUGINS'), "plugins-page"); ?> <div id="plugins"></div> <a href="#" id="addPlugin" class="addButton"><?php echo JText::_('ADD'); ?> </a> <?php echo $pane->endPanel(); echo $pane->endPane(); ?> </td> </tr> </table> <input type="hidden" name="params[isview]" value="<?php echo $params->get('isview', -1); ?> " /> <input type="hidden" name="option" value="com_fabrik" /> <input type="hidden" name="task" value="saveTable" /> <input type="hidden" name="c" value="table" /> <input type="hidden" name="id" value="<?php echo $row->id; ?> " /> <input type="hidden" name="fabrikid" value="<?php echo $fabrikid; ?> " /> <?php echo JHTML::_('form.token'); echo JHTML::_('behavior.keepalive'); ?> </form> <?php //$joinTypeOpts = "[['inner', '" . JText::_('INNER JOIN') ."'], ['left', '" . JText::_('LEFT JOIN') ."'], ['right', '" . JText::_('RIGHT JOIN') ."']]"; $joinTypeOpts = array(); $joinTypeOpts[] = array('inner', JText::_('INNER JOIN')); $joinTypeOpts[] = array('left', JText::_('LEFT JOIN')); $joinTypeOpts[] = array('right', JText::_('RIGHT JOIN')); $activetableOpts[] = ""; $activetableOpts[] = $row->db_table_name; if (array_key_exists('joins', $lists)) { for ($i = 0; $i < count($lists['joins']); $i++) { $j = $lists['joins'][$i]; $activetableOpts[] = $j->table_join; $activetableOpts[] = $j->join_from_table; } } $activetableOpts = array_unique($activetableOpts); $activetableOpts = array_values($activetableOpts); $joinLang = new stdClass(); $joinLang->joinType = JText::_('JOIN TYPE'); $joinLang->joinFromTable = JText::_('FROM'); $joinLang->joinToTable = JText::_('TO'); $joinLang->thisTablesIdCol = JText::_('FROM COLUMN'); $joinLang->joinTablesIdCol = JText::_('TO COLUMN'); $joinLang->del = JText::_('DELETE'); $joinLang = FastJSON::encode($joinLang); $opts = new stdClass(); $opts->joinOpts = $joinTypeOpts; $opts->tableOpts = $lists['defaultJoinTables']; $opts->activetableOpts = $activetableOpts; $opts = FastJSON::encode($opts); $filterOpts = new stdClass(); $filterOpts->filterJoinDd = $model->getFilterJoinDd(false, 'params[filter-join][]'); $filterOpts->filterCondDd = $model->getFilterConditionDd(false, 'params[filter-conditions][]', 2); //$filterOpts->filterAccess = addslashes(str_replace(array("\n", "\r"), '', $lists['filter-access'])); $filterOpts->filterAccess = str_replace(array("\n", "\r"), '', $lists['filter-access']); $filterOpts = FastJSON::encode($filterOpts); $applyFilterText = defined('_JACL') ? 'APPLY FILTER TO' : 'APPLY FILTER BENEATH'; $filterLang = new stdClass(); $filterLang->join = JText::_('JOIN'); $filterLang->field = JText::_('FIELD'); $filterLang->condition = JText::_('CONDITION'); $filterLang->value = JText::_('VALUE'); $filterLang->eval = JText::_('EVAL'); $filterLang->applyFilterTo = JText::_($applyFilterText); $filterLang->del = JText::_('DELETE'); $filterLang->yes = JText::_('YES'); $filterLang->no = JText::_('NO'); $filterLang->query = JText::_('QUERY'); $filterLang->noquotes = JTEXT::_('NOQUOTES'); $filterLang->text = JText::_('TEXT'); $filterLang->type = JText::_('TYPE'); $filterLang->please_select = JText::_('COM_FABRIK_PLEASE_SELECT'); $filterLang->grouped = JText::_('GROUPED'); $filterLang = FastJSON::encode($filterLang); $script = "window.addEvent('domready', function() {\n\toAdminTable = new tableForm({$opts}, {$joinLang});\n\toAdminTable.watchJoins();\n"; if (array_key_exists('joins', $lists)) { for ($i = 0; $i < count($lists['joins']); $i++) { $j = $lists['joins'][$i]; $joinFormFields = FastJSON::encode($j->joinFormFields); $joinToFields = FastJSON::encode($j->joinToFields); $script .= "\toAdminTable.addJoin('{$j->group_id}','{$j->id}','{$j->join_type}','{$j->table_join}',"; $script .= "'{$j->table_key}','{$j->table_join_key}','{$j->join_from_table}', {$joinFormFields}, {$joinToFields});\n"; } } $filterfields = addslashes(str_replace(array("\n", "\r"), '', $lists['filter-fields'])); $script .= "\toAdminFilters = new adminFilters('filterContainer', '{$filterfields}', {$filterOpts}, {$filterLang});\n"; $afilterJoins = $params->get('filter-join', '', '_default', 'array'); $afilterFields = $params->get('filter-fields', '', '_default', 'array'); $afilterConditions = $params->get('filter-conditions', '', '_default', 'array'); $afilterEval = $params->get('filter-eval', '', '_default', 'array'); $afilterValues = $params->get('filter-value', '', '_default', 'array'); $afilterAccess = $params->get('filter-access', '', '_default', 'array'); $aGrouped = $params->get('filter-grouped', '', '_default', 'array'); for ($i = 0; $i < count($afilterFields); $i++) { $selJoin = JArrayHelper::getValue($afilterJoins, $i, 'and'); $selFilter = $afilterFields[$i]; $grouped = $aGrouped[$i]; $selCondition = $afilterConditions[$i]; $filerEval = JArrayHelper::getValue($afilterEval, $i, '1'); if ($selCondition == '>') { $selCondition = '>'; } if ($selCondition == '<') { $selCondition = '<'; } $selValue = JArrayHelper::getValue($afilterValues, $i, ''); $selAccess = $afilterAccess[$i]; //alow for multiline js variables ? $selValue = htmlspecialchars_decode($selValue, ENT_QUOTES); $selValue = FastJSON::encode($selValue); if ($selFilter != '') { $script .= "\toAdminFilters.addFilterOption('{$selJoin}', '{$selFilter}', '{$selCondition}', {$selValue}, '{$selAccess}', '{$filerEval}', '{$grouped}');\n"; } } $script .= "\n});"; $document->addScriptDeclaration($script); $session =& JFactory::getSession(); $session->clear('com_fabrik.admin.table.edit.model'); }