From fee6071d8519a1e9369440bec27ca83c6a399556 Mon Sep 17 00:00:00 2001 From: chriskl Date: Sun, 30 May 2004 04:22:51 +0000 Subject: [PATCH] lots of fixes for view wizard. it didn't work on a single table, layout is improved, field sizes are standardised --- views.php | 75 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/views.php b/views.php index 793a6736..260b1d34 100644 --- a/views.php +++ b/views.php @@ -3,7 +3,7 @@ /** * Manage views in a database * - * $Id: views.php,v 1.37 2004/05/26 14:03:17 chriskl Exp $ + * $Id: views.php,v 1.38 2004/05/30 04:22:51 chriskl Exp $ */ // Include application functions @@ -172,7 +172,7 @@ echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: {$lang['strcreateviewwiz']}

\n"; $misc->printMsg($msg); - $tblCount = count($_POST['formTables']); + $tblCount = sizeof($_POST['formTables']); // If we have a message that means an error occurred in doSaveCreate, which means POST['formTables'] has quotes // around the table names, but getTableAttributes doesn't accept quoted table names so we strip them here if (strlen($msg)) { @@ -183,7 +183,7 @@ $arrFields = array(); //array that will hold all our table/field names - //if we can get foreign key info then get our linking keys + // If we can get foreign key info then get our linking keys if ($data->hasForeignKeysInfo()) { $rsLinkKeys = $data->getLinkingKeys($_POST['formTables']); @@ -206,16 +206,19 @@ echo "{$lang['strviewname']}"; echo "\n\n"; // View name - echo "\n"; + echo "_maxNameLen}\" />\n"; echo "\n\n"; echo "{$lang['strcomment']}"; echo "\n\n"; // View comments echo "\n"; - echo "\n\n"; - echo "\n\n"; + echo "\n\n"; + echo "\n"; // Output selector for fields to be retrieved from view + echo "\n"; + echo ""; + echo "\n\n\n
{$lang['strfields']}
\n"; echo GUI::printCombo($arrFields, 'formFields[]', false, '', true); echo "
\n
\n"; @@ -383,9 +386,9 @@ $selFields = implode(', ', $_POST['formFields']); $linkFields = ''; - + + // If we have links, out put the JOIN ... ON statements if (is_array($_POST['formLink']) ) { - // Filter out invalid/blank entries for our links $arrLinks = array(); foreach ($_POST['formLink'] AS $curLink) { @@ -394,31 +397,42 @@ } } // We must perform some magic to make sure that we have a valid join order - $count = count($arrLinks); + $count = sizeof($arrLinks); $arrJoined = array(); $arrUsedTbls = array(); - - $j = 0; - while ($j < $count) { - foreach ($arrLinks AS $curLink) { - - $tbl1 = substr($curLink['leftlink'], 0, strpos($curLink['leftlink'], '.') ); - $tbl2 = substr($curLink['rightlink'], 0, strpos($curLink['rightlink'], '.') ); - - if ( (!in_array($curLink, $arrJoined) && in_array($tbl1, $arrUsedTbls)) || !count($arrJoined) ) { - - //make sure for multi-column foreign keys that we use a table alias tables joined to more than once - //this can (and should be) more optimized for multi-column foreign keys - $adj_tbl2 = in_array($tbl2, $arrUsedTbls) ? "$tbl2 AS alias_ppa_" . mktime() : $tbl2; + + // If we have at least one join condition, output it + if ($count > 0) { + $j = 0; + while ($j < $count) { + foreach ($arrLinks AS $curLink) { - $linkFields .= strlen($linkFields) ? "{$curLink['operator']} $adj_tbl2 ON ({$curLink['leftlink']} = {$curLink['rightlink']}) " : "$tbl1 {$curLink['operator']} $adj_tbl2 ON ({$curLink['leftlink']} = {$curLink['rightlink']}) "; - $arrJoined[] = $curLink; - if (!in_array($tbl1, $arrUsedTbls) ) $arrUsedTbls[] = $tbl1; - if (!in_array($tbl2, $arrUsedTbls) ) $arrUsedTbls[] = $tbl2; - } + $tbl1 = substr($curLink['leftlink'], 0, strpos($curLink['leftlink'], '.') ); + $tbl2 = substr($curLink['rightlink'], 0, strpos($curLink['rightlink'], '.') ); + + if ( (!in_array($curLink, $arrJoined) && in_array($tbl1, $arrUsedTbls)) || !count($arrJoined) ) { + + // Make sure for multi-column foreign keys that we use a table alias tables joined to more than once + // This can (and should be) more optimized for multi-column foreign keys + $adj_tbl2 = in_array($tbl2, $arrUsedTbls) ? "$tbl2 AS alias_ppa_" . mktime() : $tbl2; + + $linkFields .= strlen($linkFields) ? "{$curLink['operator']} $adj_tbl2 ON ({$curLink['leftlink']} = {$curLink['rightlink']}) " : "$tbl1 {$curLink['operator']} $adj_tbl2 ON ({$curLink['leftlink']} = {$curLink['rightlink']}) "; + $arrJoined[] = $curLink; + if (!in_array($tbl1, $arrUsedTbls) ) $arrUsedTbls[] = $tbl1; + if (!in_array($tbl2, $arrUsedTbls) ) $arrUsedTbls[] = $tbl2; + } + } + $j++; } - $j++; } + // Otherwise, just select from all seleted tables - a cartesian join + else { + $linkFields = implode(', ', $_POST['formTables']); + } + } + // Otherwise, just select from all seleted tables - a cartesian join + else { + $linkFields = implode(', ', $_POST['formTables']); } $addConditions = ''; @@ -436,9 +450,10 @@ if (strlen($addConditions) ) $viewQuery .= ' WHERE ' . $addConditions; $status = $data->createView($_POST['formView'], $viewQuery, false, $_POST['formComment']); - - if ($status == 0) + if ($status == 0) { + $_reload_browser = true; doDefault($lang['strviewcreated']); + } else doSetParamsCreate($lang['strviewcreatedbad']); } -- 2.39.5