1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
<?php
// File views.inc.php / ibWebAdmin
// Purpose functions working with views, included from accessories.php
// Author Lutz Brueckner <irie@gmx.de>
// Copyright (c) 2000, 2001, 2002, 2003 by Lutz Brueckner,
// published under the terms of the GNU General Public Licence v.2,
// see file LICENCE for details
// Created <03/01/13 20:52:58 lb>
//
// $Id: views.inc.php,v 1.8 2003/11/06 22:13:15 lbrueckner Exp $
//
// create a view from the values in viewdefs array
//
function create_view($viewdefs) {
global $dbhandle;
global $ib_error, $lsql;
$lsql = $viewdefs['source'];
if ($viewdefs['check'] == 'yes') {
$lsql .= "\nWITH CHECK OPTION";
}
if (DEBUG) add_debug('lsql', __FILE__, __LINE__);
if (!@ibase_query($dbhandle, $lsql)) {
$ib_error = ibase_errmsg();
}
return (empty($ib_error)) ? get_viewname($viewdefs['source']) : FALSE;
}
//
// drop the view $name off the database
//
function drop_view($name) {
global $dbhandle, $s_tables;
global $ib_error, $lsql;
$lsql = 'DROP VIEW '.$name;
if (DEBUG) add_debug('lsql', __FILE__, __LINE__);
if (!@ibase_query($dbhandle, $lsql)) {
$ib_error = ibase_errmsg();
return FALSE;
}
else {
unset($s_tables[$name]);
return TRUE;
}
}
//
// return the html for the form elements to create or alter a view
//
function view_definition($title, $viewdefs) {
global $acc_strings, $s_cust;
$html = <<<EOT
<table border cellpadding="3" cellspacing="0">
<tr>
<th align="left">$title</th>
</tr>
<tr>
<td>
<b>${acc_strings['Source']}</b><br>
<textarea name="def_view_source" rows="%1\$d" cols="%2\$d" wrap="virtual">${viewdefs['source']}</textarea>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="def_view_check" value="yes"%3\$s>${acc_strings['CheckOpt']}
</td>
</tr>
</table>
EOT;
return sprintf($html,
$s_cust['textarea']['rows'],
$s_cust['textarea']['cols'],
($viewdefs['check'] == 'yes' ? ' checked' : '')
);
}
//
// find the name of a view in its source code
//
function get_viewname($viewsource) {
$chunks = preg_split("/[\s]+/", $viewsource, 4);
return $chunks[2];
}
//
// deliver the html for an opened view on the views panel
//
function &get_opened_view($name, $title, $url) {
global $dbhandle, $s_fields, $red_triangle_icon, $tb_strings, $acc_strings, $ptitle_strings;
$source = get_view_source($name);
$html = <<<EOT
<nobr>
<a href="$url"><img src="$red_triangle_icon" alt="${ptitle_strings['Close']}" title="${ptitle_strings['Close']}" border="0" hspace="7"></a><b>$title</b>
</nobr>
<nobr>
<table>
<tr>
<td width="26">
</td>
<td valign="top">
<table border cellpadding="0" cellspacing="0">
<tr>
EOT;
$cols = array('Name', 'Type', 'Length', 'Prec', 'Scale', 'Charset', 'Collate');
$html .= " <tr align=\"left\">\n";
foreach ($cols as $idx) {
$html .= ' <th class="detail"><nobr>'.$tb_strings[$idx]."</nobr></th>\n";
}
$html .= " </tr>\n";
foreach ($s_fields as $field) {
if ($field['table'] <> $name) {
continue;
}
$size_str = ($field['type'] == 'VARCHAR' || $field['type'] == 'CHARACTER') ? $field['size'] : ' ';
$prec_str = (isset($field['prec'])) ? $field['prec'] : ' ';
$scale_str= (isset($field['scale'])) ? $field['scale'] : ' ';
$char_str = (isset($field['charset'])) ? $field['charset'] : ' ';
$coll_str = (isset($field['collate'])) ? $field['collate'] : ' ';
$html .= " <tr>
<td class=\"detail\">${field['name']}</td>
<td class=\"detail\">${field['type']}</td>
<td align=\"right\" class=\"detail\">$size_str</td>
<td align=\"right\" class=\"detail\">$prec_str</td>
<td align=\"right\" class=\"detail\">$scale_str</td>
<td class=\"detail\">$char_str</td>
<td class=\"detail\">$coll_str</td>
</tr>\n";
}
$html .= " </table>\n </td>\n";
$html .= " <td> </td>\n"
." <td valign=\"top\">\n"
." <table border cellpadding=\"0\" cellspacing=\"0\">\n"
." <tr align=\"left\">\n"
.' <th class="detail">'.$acc_strings['Source']."</th>\n"
." </tr>\n"
." <tr>\n"
.' <td class="detail"><pre>'.$source."</pre></td>\n"
." </tr>\n"
." </table>\n"
." </tr>\n"
." </td>\n"
." </table>\n"
." </nobr>\n";
return $html;
}
//
// return the sourcecode of the definition for $view
//
function get_view_source($name) {
global $dbhandle;
$vsource = '';
$sql = 'SELECT R.RDB$VIEW_SOURCE VSOURCE'
.' FROM RDB$RELATIONS R'
." WHERE R.RDB\$RELATION_NAME='".$name."'";
$res = ibase_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
$obj = @ibase_fetch_object($res);
if (is_object($obj)) {
$bid = ibase_blob_open($obj->VSOURCE);
$arr = ibase_blob_info($obj->VSOURCE);
// $arr[0] holds the blob length
$vsource = trim(ibase_blob_get($bid, $arr[0]));
ibase_blob_close($bid);
}
ibase_free_result($res);
return $vsource;
}
//
// mark all views as opened or closed in $s_tables
//
function &toggle_all_views(&$tables, $status) {
foreach (array_keys($tables) as $name) {
if ($tables[$name]['is_view']) {
$tables[$name]['status'] = $status;
}
}
return $tables;
}
?>
|