<?php
/*******************************************************************************
 *
 * LEIDEN OPEN VARIATION DATABASE (LOVD)
 *
 * Created     : 2006-10-19
 * Modified    : 2008-03-04
 * For LOVD    : 2.0-05
 *
 * Access      : Public
 * Purpose     : Show custom link details, referenced to from the variant and
 *               patient forms.
 *
 * Copyright   : 2004-2008 Leiden University Medical Center; http://www.LUMC.nl/
 * Programmer  : Ing. Ivo F.A.C. Fokkema <I.F.A.C.Fokkema@LUMC.nl>
 * Last edited : Ing. Ivo F.A.C. Fokkema <I.F.A.C.Fokkema@LUMC.nl>
 *
 *
 * This file is part of LOVD.
 *
 * LOVD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * LOVD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LOVD; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *************/

define('ROOT_PATH', './');
require ROOT_PATH . 'inc-init.php';
require ROOT_PATH . 'inc-top-clean.php';





// Request information on link.
print('
      <SCRIPT type="text/javascript">
        <!--
        self.focus();

        function lovd_addPattern (varCol, varPattern) {
          if (opener.document.forms[0][varCol].value == \'\') {
            opener.document.forms[0][varCol].value = varPattern;
          } else {
            opener.document.forms[0][varCol].value = opener.document.forms[0][varCol].value + \' \' + varPattern;
          }
        }
        // -->
      </SCRIPT>' . "\n\n");

print ('      <TABLE border="0" cellpadding="5" cellspacing="0" width="100%" class="S11" style="border : 1px solid #c0c0c0;">' . "\n" .
       '        <TR>' . "\n" .
       '          <TD>' . "\n");

$zData = @mysql_fetch_assoc(mysql_query('SELECT * FROM ' . TABLE_LINKS . ' WHERE linkid = "' . $_GET['view'] . '" AND active = 1'));
if (!$zData) {
    print('            Incorrect link' . "\n");

} else {
    // We need to print the columns this link is active for.
    $aCols = array();

    // I certainly don't feel like parsing out the c.form_type, I'm taking the head_column!
    $qCols = mysql_query('SELECT c2l.colid, c.head_column FROM ' . TABLE_COLS2LINKS . ' AS c2l LEFT OUTER JOIN ' . TABLE_COLS . ' AS c USING (colid) WHERE c2l.linkid = "' . $_GET['view'] . '" ORDER BY c.head_column');
    while ($r = mysql_fetch_row($qCols)) {
        $aCols[$r[0]] = $r[1];
    }
    // 2008-03-04; 2.0-05; What was I thinking? Needs this check of course. Otherwise, all links seem to be active for this column.
    if (array_key_exists('Gene/Reference', $aCols)) {
        $aCols['Gene/Reference'] = 'Gene Reference';
    }

    print('            <TABLE border="0" cellpadding="0" cellspacing="0" class="S11" width="100%">' . "\n" .
          '              <TR valign="top">' . "\n" .
          '                <TD><B>Link</B></TD>' . "\n" .
          '                <TD>&nbsp;:&nbsp;</TD>' . "\n" .
          '                <TD>' . $zData['linkname'] . '</TD></TR>' . "\n" .
          '              <TR valign="top">' . "\n" .
          '                <TD><B>Pattern</B></TD>' . "\n" .
          '                <TD>&nbsp;:&nbsp;</TD>' . "\n" .
          '                <TD>' . $zData['pattern_text'] . '</TD></TR>' . "\n" .
          '              <TR valign="top">' . "\n" .
          '                <TD><B>Replaced&nbsp;with</B></TD>' . "\n" .
          '                <TD>&nbsp;:&nbsp;</TD>' . "\n" .
          '                <TD>' . htmlspecialchars($zData['replace_text']) . '</TD></TR>' . "\n" .
          '              <TR valign="top">' . "\n" .
          '                <TD><B>Description</B></TD>' . "\n" .
          '                <TD>&nbsp;:&nbsp;</TD>' . "\n" .
          '                <TD>' . str_replace(array("\r\n", "\r", "\n"), '<BR>', trim($zData['link_description'])) . '</TD></TR>' . "\n" .
          '              <TR valign="top">' . "\n" .
          '                <TD><B>Active&nbsp;for&nbsp;column' . (count($aCols) == 1? '' : 's') . '</B></TD>' . "\n" .
          '                <TD>&nbsp;:&nbsp;</TD>' . "\n" .
          '                <TD>' . implode(', ', $aCols) . '</TD></TR></TABLE>' . "\n" .
          '            <A href="#" onclick="javascript:lovd_addPattern(\'' . $_GET['col'] . '\', \'' . $zData['pattern_text'] . '\'); self.close(); return false;"><B>Insert into ' . $aCols[$_GET['col']] . " field</B></A><BR>\n");
}

print('          </TD>' . "\n" .
      '        </TR>' . "\n" .
      '      </TABLE>' . "\n\n");

require ROOT_PATH . 'inc-bot-clean.php';
?>