Esempio n. 1
0
 function getForm()
 {
     // Build the form.
     // If we've built the form before, simply return it. Especially imports will repeatedly call checkFields(), which calls getForm().
     if (!empty($this->aFormData)) {
         return parent::getForm();
     }
     global $_SETT;
     $aHumanBuilds = array();
     foreach ($_SETT['human_builds'] as $sCode => $aBuild) {
         $aHumanBuilds[$sCode] = $sCode . ' / ' . $aBuild['ncbi_name'];
     }
     // No more hg18! We'll support LOVDs having this setting, but we won't allow new installations to pick this setting.
     unset($aHumanBuilds['hg18']);
     $aFeedHistory = array('Not available');
     for ($i = 1; $i <= 12; $i++) {
         $aFeedHistory[$i] = $i . ' month' . ($i == 1 ? '' : 's');
     }
     $this->aFormData = array(array('POST', '', '', '', '335', '14', ''), array('', '', 'print', '<B>General system settings</B>'), 'hr', array('Title of this LOVD installation', 'This will be shown on the top of every page.', 'text', 'system_title', 45), array('Institute (optional)', 'The institute which runs this database is displayed in the public area and in emails sent by LOVD. It\'s commonly set to a laboratory name or a website name.', 'text', 'institute', 45), array('Database URL (optional)', 'This is the URL with which the database can be accessed by the outside world, including "http://" or "https://". It will also be used in emails sent by LOVD. This field is mandatory if you select the "Include in the global LOVD listing" option.<BR>If you click the "check" link, LOVD will verify or try to predict the value.', 'print', '<INPUT type="text" name="location_url" size="40" id="location_url" value="' . (empty($_POST['location_url']) ? '' : htmlspecialchars($_POST['location_url'])) . '"' . (!lovd_errorFindField('location_url') ? '' : ' class="err"') . '>&nbsp;<SPAN id="location_url_check">(<A href="#" onclick="javascript:lovd_checkURL(); return false;">check</A>)</SPAN>'), array('LOVD email address', 'This email address will be used to send emails from LOVD to users. We need this address to make sure that emails from LOVD arrive. Please note that although strictly speaking this email address does not need to exist, we recommend that you use a valid address.', 'text', 'email_address', 40), array('Forward messages to database admin?', 'This will forward messages to the database administrator about submitter registrations and submissions.', 'checkbox', 'send_admin_submissions'), 'refseq_build' => array('Human Build to map to (UCSC/NCBI)', 'We need to know which version of the Human Build we need to map the variants in this LOVD to.', 'select', 'refseq_build', 1, $aHumanBuilds, false, false, false), array('List database changes in feed for how long?', 'LOVD includes a "newsfeed" that allows users to get a list of changes recently made in the database. Select here how many months back you want changes to appear on this list. Set to "Not available" to disable the newsfeed.', 'print', '&nbsp;<I style="color : #666666;">Not yet implemented</I>'), 'hr', 'skip', 'skip', array('', '', 'print', '<B>Connection settings (optional)</B>'), array('', '', 'note', 'The following settings apply to how LOVD connects to other resources.<BR>Some networks have no access to the outside world except through a proxy. If this applies to the network this server is installed on, please fill in the proxy server information here.'), 'hr', array('Proxy server host name', 'The host name of the proxy server, such as www-cache.institution.edu.', 'text', 'proxy_host', 20), array('Proxy server port number', 'The port number of the proxy server, such as 3128.', 'text', 'proxy_port', 4), 'skip', array('', '', 'note', 'The following two fields only apply if the proxy server requires authentication.'), array('Proxy server username', 'In case the proxy server requires authentication, please enter the required username here.', 'text', 'proxy_username', 20), array('Proxy server password', 'In case the proxy server requires authentication, please enter the required password here.', 'password', 'proxy_password', 20, true), 'hr', 'skip', 'skip', array('', '', 'print', '<B>Customize LOVD</B>'), array('', '', 'note', 'Here you can customize the way LOVD looks. We will add more options here later.'), 'hr', array('System logo', 'If you wish to have your custom logo on the top left of every page instead of the default LOVD logo, enter the path to the image here, relative to the LOVD installation path.', 'text', 'logo_uri', 40), array('', '', 'note', 'Currently, only images already uploaded to the LOVD server are allowed here.'), 'hr', 'skip', 'skip', array('', '', 'print', '<B>Global LOVD statistics</B>'), array('', '', 'note', 'The following settings apply to the kind of information your LOVD install sends to the development team to gather statistics about global LOVD usage.'), 'hr', array('Send statistics?', 'This sends <I>anonymous</I> statistics about the number of submitters, genes, individuals and variants in your installation of LOVD.', 'checkbox', 'send_stats'), array('Include in the global LOVD listing?', 'We keep a public listing of LOVD installations, their genes and their URLs. Deselect this checkbox if you do not want to be included in this public listing.', 'checkbox', 'include_in_listing'), 'hr', 'skip', 'skip', array('', '', 'print', '<B>Security settings</B>'), array('', '', 'note', 'Using the following settings you can control some security settings of LOVD.'), 'hr', array('Allow submitter registration?', 'Enabling this setting allows submitters to create their own accounts in your LOVD installation. Having it enabled is the default setting, and this could not be disabled prior to LOVD 3.0-17.<BR>Note, that submitters can never register when your LOVD installation is set to read-only because of an active announcement with the read-only setting enabled. See the Announcements section in the Setup area for more information.', 'checkbox', 'allow_submitter_registration'), array('Lock users after 3rd failed login?', 'Do you want to lock users (submitters, curators and managers) after three failed attempts to log in using their username?<BR>(This does <I>not</I> affect the database administrator account)', 'checkbox', 'lock_users'), array('Allow (locked) users to retrieve a new password?', 'Do you want to enable an "I forgot my password" option that allows users who forgot their password to retrieve a new one?', 'checkbox', 'allow_unlock_accounts'), array('Enable submitters to change data?', 'Enabling this setting allows submitters to make changes to data previously submitted by them or assigned to them.', 'checkbox', 'allow_submitter_mods'), array('Enable getting counts of hidden entries?', 'Enabling this feature allows the public to find the number of entries in the database (including hidden entries) matching one or more search terms on a specified set of columns. This feature will only mention the number of variant entries matched, without showing them.', 'print', '&nbsp;<I style="color : #666666;">Not yet implemented</I>'), array('Force SSL-only access to LOVD?', 'SSL is a secure protocol allowing for encryption of data sent between you and LOVD. When you will record sensitive individual information in LOVD, you <B>should</B> enable this setting, as the individual information can otherwise be \'sniffed\' off the network. If you do not record sensitive information, enabling SSL is <I>recommended</I>.', 'checkbox', 'use_ssl'), array('Use data versioning of biological data?', 'Versioning allows you to see all previous versions of a certain data entry (individuals, variants, phenotype information, etc) and allows you to return the entry to a previous state. Please note that this feature requires quite a lot of space in the database. Disabling this feature later will not free any space, just prevent more space from being used.', 'print', '&nbsp;<I style="color : #666666;">Not yet implemented</I>'), 'uninstall' => array('Disable LOVD uninstall?', 'Select this to disable the "Uninstall LOVD" option in the Setup area. Please note that this uninstall lock can only be removed by directly accessing the MySQL database.', 'checkbox', 'lock_uninstall'), 'uninstall_hr' => 'hr');
     if (lovd_getProjectFile() != '/install/index.php') {
         unset($this->aFormData['uninstall'], $this->aFormData['uninstall_hr']);
         global $_CONF;
         $this->aFormData['refseq_build'] = array('Human Build to map to (UCSC/NCBI)', '', 'print', '&nbsp;' . $_CONF['refseq_build']);
     }
     return parent::getForm();
 }
Esempio n. 2
0
function lovd_viewForm($a, $sHeaderPrefix = "\n          <TR valign=\"top\">\n            <TD class=\"{{ CLASS }}\">", $sHeaderSuffix = '</TD>', $sHelpPrefix = "\n            <TD class=\"{{ CLASS }}\">", $sHelpSuffix = '</TD>', $sDataPrefix = "\n            <TD class=\"{{ CLASS }}\">", $sDataSuffix = '</TD></TR>', $sNewLine = '              ')
{
    // Based on a function provided by Ileos.nl.
    /***************************************************************************
     * Display HTML form according to input array containing settings and field
     * descriptions.
     *
     * Sytax for values of input array :
     *
     * array('GET|POST', 'header_class_name', 'help_class_name', 'data_class_name', 'header_width', 'help_width', 'data_width'),
     * 'skip',
     * 'hr',
     * array('print', '<text>'),
     * array('fieldset', '<id>', '<text>', '<open>:[true]|false'),
     * 'end_fieldset',
     * array('<header>', '<help_text>', 'print', '<text>'),
     * array('<header>', '<help_text>', 'note', '<text>'),
     * array('<header>', '<help_text>', 'text|password|file', '<field_name>', <field_size>),
     * array('<header>', '<help_text>', 'textarea', '<field_name>', <field_cols>, <field_rows>),
     * array('<header>', '<help_text>', 'select', '<field_name>', <field_size>, <data> (array, key => val|query, [0] => [1]), <select>:true|false|select_text, <multiple>:true|false, <select_all_link>:true|false|link_text),
     * array('<header>', '<help_text>', 'checkbox', '<field_name>'),
     * array('<header>', '<help_text>', 'submit', '<button_value>', '<field_name>'),
     *
     **********/
    // Options.
    list($sMethod, $sHeaderClass, $sHelpClass, $sDataClass, $sHeaderWidth, $sHelpWidth, $sDataWidth) = $a[0];
    // Method.
    if (!in_array($sMethod, array('GET', 'POST'))) {
        $sMethod = 'POST';
    }
    // Class names, widths are taken care of in the COLGROUP element (that doesn't support class name).
    $aCats = array('Header', 'Help', 'Data');
    foreach ($aCats as $sCat) {
        $sClass = 's' . $sCat . 'Class';
        $sPrefix = 's' . $sCat . 'Prefix';
        if (${$sClass}) {
            ${$sPrefix} = str_replace('{{ CLASS }}', ${$sClass}, ${$sPrefix});
        } else {
            ${$sPrefix} = str_replace(' class="{{ CLASS }}"', '', ${$sPrefix});
        }
    }
    // Table structure, use COLGROUP for the width to ensure table-layout:fixed gets the width correctly.
    $nFormWidth = 760;
    $sTable = '        <TABLE border="0" cellpadding="0" cellspacing="1" width="' . $nFormWidth . '" class="dataform">
          <COLGROUP>
            <COL width="' . $sHeaderWidth . '"></COL>
            <COL width="' . $sHelpWidth . '"></COL>
            <COL width="' . $sDataWidth . '"></COL>
          </COLGROUP>';
    // First: print the table.
    $bInFieldset = false;
    if (!(!empty($a[1][0]) && $a[1][0] == 'fieldset')) {
        // Table should only be printed when the first field is not a fieldset definition, that definition will close and open a new table.
        print $sTable;
    }
    // Now loop the array with fields, to print them on the screen.
    foreach ($a as $nKey => $aField) {
        if (!$nKey) {
            // Options, already read out.
            continue;
        } elseif (!is_array($aField)) {
            // Commands like "skip" and "hr" (horizontal rule).
            if ($aField == 'skip') {
                // Skip line.
                echo $sHeaderPrefix . '&nbsp;' . $sHeaderSuffix . $sHelpPrefix . '&nbsp;' . $sHelpSuffix . $sDataPrefix . '&nbsp;' . $sDataSuffix;
                continue;
            } elseif ($aField == 'hr') {
                // Horizontal line (ruler).
                // This construction may not entirely be correct when this function is called with different prefixes & suffixes than the default ones.
                echo str_replace('<TD', '<TD colspan="3"', $sHeaderPrefix) . '<IMG src="gfx/trans.png" alt="" width="100%" height="1" class="form_hr">' . $sDataSuffix;
                continue;
            } elseif ($aField == 'end_fieldset' && $bInFieldset) {
                // End of fieldset. Only given when fieldset is open and no new fieldset should be opened.
                print '</TABLE>' . "\n" . '        </FIELDSET>' . "\n" . $sTable;
                $bInFieldset = false;
                continue;
            }
        } else {
            // Build some form content.
            if ($aField[0] == 'print') {
                // Print text.
                echo $aField[1] . "\n";
                continue;
            } elseif ($aField[0] == 'fieldset') {
                $bShow = !(isset($aField[3]) && $aField[3] === false);
                print '</TABLE>' . "\n";
                if ($bInFieldset && $nKey > 1) {
                    // $nKey needs to be > 1 because if fieldset is the first thing the form does, there is no opening table yet.
                    print '        </FIELDSET>' . "\n";
                }
                print '        <FIELDSET style="width : ' . ($nFormWidth + 4) . 'px;"><LEGEND style="margin-left : ' . $sHeaderWidth . ';"><B>' . $aField[2] . '</B> <SPAN class="S11">[<A href="#" id="' . $aField[1] . '_link" onClick="lovd_toggleVisibility(\'' . $aField[1] . '\'); return false;">' . ($bShow ? 'Hide' : 'Show') . '</A>]</SPAN></LEGEND>' . "\n" . preg_replace('/>/', ' id="' . $aField[1] . '"' . ($bShow ? '' : ' style="display : none"') . '>', $sTable, 1);
                $bInFieldset = true;
                continue;
            }
            // Print the HTML parts and add the help button.
            print $sHeaderPrefix . $aField[0] . $sHeaderSuffix . $sHelpPrefix;
            if ($aField[2] == 'select' && $aField[7]) {
                $aField[1] .= ($aField[1] ? '<BR><BR>' : '') . 'You can select a range of items by clicking the first item, holding "Shift" and clicking the last item in the range. Selecting/deselecting individual items can be done by holding "Ctrl" on a PC or "Command" on a Mac and clicking on the items.';
            }
            if (!empty($aField[1])) {
                // Somehow, we need the str_replace() because the htmlspecialchars() with ENT_QUOTES does not prevent JS errors due to single quotes.
                print '<IMG src="gfx/lovd_form_question.png" alt="" onmouseover="lovd_showToolTip(\'' . htmlspecialchars(str_replace("'", "\\'", $aField[1])) . '\');" onmouseout="lovd_hideToolTip();" class="help" width="14" height="14">';
            } else {
                print '&nbsp;';
            }
            print $sHelpSuffix . $sDataPrefix;
            if (in_array($aField[2], array('print', 'note'))) {
                // Print text separated in header and field values.
                list($sHeader, $sHelp, $sType, $sPrint) = $aField;
                print ($sType == 'note' ? '<SPAN class="form_note">' . $sPrint . '</SPAN>' : $sPrint) . $sDataSuffix;
                continue;
            } elseif (in_array($aField[2], array('text', 'file'))) {
                list($sHeader, $sHelp, $sType, $sName, $nSize) = $aField;
                if (!isset($GLOBALS['_' . $sMethod][$sName])) {
                    $GLOBALS['_' . $sMethod][$sName] = '';
                }
                print '<INPUT type="' . $sType . '" name="' . $sName . '" size="' . $nSize . '" value="' . htmlspecialchars($GLOBALS['_' . $sMethod][$sName]) . '"' . (!lovd_errorFindField($sName) ? '' : ' class="err"') . '>' . $sDataSuffix;
                continue;
            } elseif ($aField[2] == 'password') {
                // Add default values to any missing entries at the end of the field array.
                $aFieldComplete = array_pad($aField, 6, false);
                list(, , $sType, $sName, $nSize, $bBlockAutofillPass) = $aFieldComplete;
                if (!isset($GLOBALS['_' . $sMethod][$sName])) {
                    $GLOBALS['_' . $sMethod][$sName] = '';
                }
                // Setup password field attributes.
                $sFieldAtts = ' type="' . $sType . '" name="' . $sName . '" size="' . $nSize . '"';
                if ($bBlockAutofillPass) {
                    // Block editing of the actual password field until JS onFocus event.
                    $sFieldAtts .= ' readonly onfocus="this.removeAttribute(\'readonly\');"';
                }
                // Output a hidden text field before password field, to catch a possible
                // mistaken automatic fill of a username.
                print '<INPUT type="text" style="display:none" />' . PHP_EOL;
                // Print indentation for new line.
                print $sNewLine;
                print '<INPUT' . $sFieldAtts . ' value="' . htmlspecialchars($GLOBALS['_' . $sMethod][$sName]) . '"' . (!lovd_errorFindField($sName) ? '' : ' class="err"') . '>' . $sDataSuffix;
                continue;
            } elseif ($aField[2] == 'textarea') {
                list($sHeader, $sHelp, $sType, $sName, $nCols, $nRows) = $aField;
                if (!isset($GLOBALS['_' . $sMethod][$sName])) {
                    $GLOBALS['_' . $sMethod][$sName] = '';
                }
                print '<TEXTAREA name="' . $sName . '" cols="' . $nCols . '" rows="' . $nRows . '"' . (!lovd_errorFindField($sName) ? '' : ' class="err"') . '>' . htmlspecialchars($GLOBALS['_' . $sMethod][$sName]) . '</TEXTAREA>' . $sDataSuffix;
                continue;
            } elseif ($aField[2] == 'select') {
                list($sHeader, $sHelp, $sType, $sName, $nSize, $oData, $sSelect, $bMultiple, $bSelectAll) = $aField;
                if (!isset($GLOBALS['_' . $sMethod][$sName])) {
                    $GLOBALS['_' . $sMethod][$sName] = '';
                }
                print '<SELECT name="' . $sName . ($bMultiple ? '[]' : '') . '"' . ($bMultiple == true || $nSize != 1 ? ' size="' . $nSize . '"' : '') . ($bMultiple ? ' multiple' : '') . '' . (!lovd_errorFindField($sName) ? '' : ' class="err"') . '>';
                if ($sSelect) {
                    // Print the first 'select' element, by default valued '-- select --'.
                    $bSelected = !$bMultiple && !$GLOBALS['_' . $sMethod][$sName] || $bMultiple && is_array($GLOBALS['_' . $sMethod][$sName]) && !count($GLOBALS['_' . $sMethod][$sName]);
                    print "\n" . $sNewLine . '  <OPTION value=""' . ($bSelected ? ' selected' : '') . '>' . ($sSelect === "true" || $sSelect === true ? '-- select --' : $sSelect) . '</OPTION>';
                }
                if (is_array($oData)) {
                    // Array input.
                    $bInOptGroup = false;
                    // Used to determine if we are in an option group.
                    foreach ($oData as $key => $val) {
                        // Create option groups for select boxes.
                        if (substr($key, 0, 8) == 'optgroup') {
                            // This handles the creation of option groups.
                            // To add option groups include array values above each group as follows array('optgroup1' => 'Group 1 Name').
                            // If we are in an option group then we need to close it before we start a new option group.
                            print ($bInOptGroup ? '' : "\n" . $sNewLine . '</OPTGROUP>') . "\n" . $sNewLine . '  <OPTGROUP label="' . htmlspecialchars($val) . '">';
                            $bInOptGroup = true;
                        } else {
                            // We have to cast the $key to string because PHP made integers of them, if they were integer strings.
                            $bSelected = !$bMultiple && (string) $GLOBALS['_' . $sMethod][$sName] === (string) $key || $bMultiple && is_array($GLOBALS['_' . $sMethod][$sName]) && in_array((string) $key, $GLOBALS['_' . $sMethod][$sName], true);
                            print "\n" . $sNewLine . '  <OPTION value="' . htmlspecialchars($key) . '"' . ($bSelected ? ' selected' : '') . '>' . htmlspecialchars($val) . '</OPTION>';
                        }
                    }
                    // If we are still in an option group then lets close it.
                    print $bInOptGroup ? '' : "\n" . $sNewLine . '</OPTGROUP>';
                }
                print '</SELECT>';
                // Select all link.
                if ($bMultiple && $bSelectAll) {
                    print '&nbsp;<A href="#" onclick="$(this.previousSibling.previousSibling).children().each(function(){$(this).attr(\'selected\', true);}); $(this.previousSibling.previousSibling).change(); return false">Select&nbsp;all</A>';
                }
                print $sDataSuffix;
                continue;
            } elseif ($aField[2] == 'checkbox') {
                list($sHeader, $sHelp, $sType, $sName) = $aField;
                if (!isset($GLOBALS['_' . $sMethod][$sName])) {
                    $GLOBALS['_' . $sMethod][$sName] = '';
                }
                print '<INPUT type="checkbox" name="' . $sName . '" value="1"' . ($GLOBALS['_' . $sMethod][$sName] ? ' checked' : '') . ' style="margin-top : 4px; border : 0px;"' . (!lovd_errorFindField($sName) ? '' : ' class="err"') . '>' . $sDataSuffix;
                continue;
            } elseif ($aField[2] == 'submit') {
                print '<INPUT type="submit"' . (isset($aField[4]) ? ' name="' . $aField[4] . '"' : '') . ' value="' . $aField[3] . '">' . $sDataSuffix;
                continue;
            }
        }
    }
    print '</TABLE>';
    if ($bInFieldset) {
        print '</FIELDSET>';
    }
}