function closed_panel($idx)
{
    //calculate the panel name
    $pvar = 's_' . strtolower($GLOBALS['s_page']) . '_panels';
    $GLOBALS[$pvar][$idx][2] = 'close';
    $icon = get_icon_path(DATAPATH, ICON_SIZE) . 'open.png';
    $html = get_closed_panel($GLOBALS[$pvar][$idx][1], $idx, $icon);
    set_customize_cookie($GLOBALS['s_cust']);
    header('Content-Type: text/html;charset=' . $GLOBALS['charset']);
    echo $html;
}
function get_opened_trigger($name, $trigger, $url)
{
    global $dbhandle, $acc_strings, $ptitle_strings;
    $type_str = implode('<br>', $trigger['type']);
    $red_triangle = get_icon_path(DATAPATH, ICON_SIZE) . 'red_triangle.png';
    $html = <<<EOT
        <nobr>
          <a href="{$url}" class="dtitle"><img src="{$red_triangle}" alt="{$ptitle_strings['Close']}" title="{$ptitle_strings['Close']}" border="0" hspace="7"><b>{$name}</b></a>
        </nobr>
        <nobr>
        <table>
          <tr>
            <td width="26">
            </td>
            <td>
              <table class="table table-bordered">
                <tr>
                  <th>{$acc_strings['Table']}</th>
                  <th>{$acc_strings['Phase']}</th>
                  <th>{$acc_strings['Type']}</th>
                  <th>{$acc_strings['Pos']}</th>
                  <th>{$acc_strings['Status']}</th>
                  <th>{$acc_strings['Source']}</th>
                </tr>
                <tr>
\t          <td valign="top">{$trigger['table']}</td>
\t          <td valign="top">{$trigger['phase']}</td>
\t          <td valign="top">{$type_str}</td>
\t          <td valign="top">{$trigger['pos']}</td>
\t          <td valign="top">{$trigger['status']}</td>
\t          <td valign="top"><pre>{$trigger['source']}</pre></td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </nobr>

EOT;
    return $html;
}
function get_open_panel_start($title, $nr)
{
    global $ptitle_strings;
    $fold_url = sprintf("javascript:requestClosedPanel('%d')", $nr);
    $close_icon = get_icon_path(DATAPATH, ICON_SIZE) . 'close.png';
    return '<table width="100%" class="area">' . "\n" . "  <tr class=\"panel\">\n" . '    <td rowspan="2" width="25" align="center" valign="top">' . "\n" . '      ' . sprintf('<a href="%1$s"><img src="%2$s" alt="%3$s" title="%3$s" border="0"></a>' . "\n", $fold_url, $close_icon, $ptitle_strings['Close']) . "\n" . "    </td>\n" . '    <td width="100%"><a class="ptitle" href="' . $fold_url . '">' . $title . "</a></td>\n" . "    <td>\n" . "    </td>\n" . "  </tr>\n" . "  <tr>\n" . "    <td colspan=\"2\">\n";
}
function get_opened_procedure($name, $procedure, $url)
{
    global $dbhandle, $tb_strings, $acc_strings, $ptitle_strings;
    $in = $out = '';
    $in_start = $out_start = $src_start = '';
    $rowspan = 1;
    if (count($procedure['in']) > 0) {
        $in = procedure_parameters($procedure['in']);
        $out_start = $src_start = "<tr>\n";
        $rowspan++;
    }
    if (count($procedure['out']) > 0) {
        $out = procedure_parameters($procedure['out']);
        $src_start = "<tr>\n";
        $rowspan++;
    }
    $red_triangle = get_icon_path(DATAPATH, ICON_SIZE) . 'red_triangle.png';
    $html = <<<EOT
        <nobr>
          <a href="{$url}" class="dtitle"><img src="{$red_triangle}" alt="{$ptitle_strings['Close']}" title="{$ptitle_strings['Close']}" border="0" hspace="7">{$name}</a>
        </nobr>
        <table>
          <tr>
            <td width="26" rowspan="{$rowspan}">
            </td>

EOT;
    if (!empty($in)) {
        $html .= <<<EOT
          <td>
            <table class="table table-bordered">
              <tr>
                <th align="left">{$acc_strings['Param']}</th>
              </tr>
              <tr>
\t        <td valign="top">{$in}</td>
              </tr>
            </table>
          </td>
       </tr>

EOT;
    }
    if (!empty($out)) {
        $html .= <<<EOT
        {$out_start}
          <td>
            <table class="table table-bordered">
              <tr>
                <th align="left">{$acc_strings['Return']}</th>
              </tr>
              <tr>
\t        <td valign="top">{$out}</td>
              </tr>
            </table>
          </td>
        </tr>

EOT;
    }
    $html .= <<<EOT
        {$src_start}
          <td>
            <table>
              <tr>
                <th align="left">{$acc_strings['Source']}</th>
              </tr>
              <tr>
\t        <td valign="top"><pre>{$procedure['source']}</pre></td>
              </tr>
            </table>
          </td>
        </tr>
        </table>

EOT;
    return $html;
}
function get_opened_view($name, $title, $url)
{
    global $dbhandle, $s_fields, $tb_strings, $acc_strings, $ptitle_strings;
    $source = get_view_source($name);
    $red_triangle = get_icon_path(DATAPATH, ICON_SIZE) . 'red_triangle.png';
    $html = <<<EOT
        <nobr>
          <a href="{$url}" class="dtitle"><img src="{$red_triangle}" alt="{$ptitle_strings['Close']}" title="{$ptitle_strings['Close']}" border="0" hspace="7">{$title}</a>
        </nobr>
        <nobr>
        <table class="table table-hover">
          <tr>
            <td width="26">
            </td>
            <td valign="top">
              <table class="table table-bordered">
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[$name] as $field) {
        $size_str = $field['type'] == 'VARCHAR' || $field['type'] == 'CHARACTER' ? $field['size'] : '&nbsp;';
        $prec_str = isset($field['prec']) ? $field['prec'] : '&nbsp;';
        $scale_str = isset($field['scale']) ? $field['scale'] : '&nbsp;';
        $char_str = isset($field['charset']) ? $field['charset'] : '&nbsp;';
        $coll_str = isset($field['collate']) ? $field['collate'] : '&nbsp;';
        $html .= "              <tr>\n                <td class=\"detail\">{$field['name']}</td>\n\t        <td class=\"detail\">{$field['type']}</td>\n\t        <td align=\"right\" class=\"detail\">{$size_str}</td>\n\t        <td align=\"right\" class=\"detail\">{$prec_str}</td>\n\t        <td align=\"right\" class=\"detail\">{$scale_str}</td>\n    \t        <td class=\"detail\">{$char_str}</td>\n                <td class=\"detail\">{$coll_str}</td>\n              </tr>\n";
    }
    $html .= "            </table>\n          </td>\n";
    $html .= "         <td>&nbsp;</td>\n" . "          <td valign=\"top\">\n" . "            <table border=\"1\" 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;
}
        // there may be different instances of the data edit/delete panel,
        // which carrying the instance nr in the panel name
        if (preg_match('/dt_(edit|delete)([0-9]+)/', $panel[0], $matches)) {
            $instance = $matches[2];
            if ($matches[1] == 'edit') {
                include './panels/dt_edit.php';
            } else {
                $subject = 'row';
                include './panels/confirm.php';
            }
        } else {
            include './panels/' . $panel[0] . '.php';
        }
        echo get_open_panel_end();
    } else {
        $open_icon = get_icon_path(DATAPATH, ICON_SIZE) . 'open.png';
        echo get_closed_panel($panel[1], $nr, $open_icon);
    }
    echo "</div>\n";
}
// close the db connection
if (isset($dbhandle) && is_resource($dbhandle)) {
    // fbird_close() chrashes the apache-process,
    // this was a bug in some revisions of the ibase-module
    //    fbird_close($dbhandle);
}
if (DEBUG === TRUE) {
    echo "<div align=\"left\">\n";
    show_time_consumption($start_time, microtime());
    //     echo 'cookie size: '.strlen($_COOKIE[get_customize_cookie_name()])."<br>\n";
    //     debug_var($_COOKIE[get_customize_cookie_name()]);