Esempio n. 1
0
 function checkFields($aData, $zData = false)
 {
     // Checks fields before submission of data.
     parent::checkFields($aData);
     // XSS attack prevention. Deny input of HTML.
     lovd_checkXSS();
 }
Esempio n. 2
0
 function checkFields($aData, $zData = false)
 {
     // Checks fields before submission of data.
     global $_DB;
     // Mandatory fields.
     $this->aCheckMandatory = array('type', 'announcement');
     parent::checkFields($aData);
     // NO XSS attack prevention, because the message might require HTML (links, markup etc).
     // lovd_checkXSS();
 }
Esempio n. 3
0
 function checkFields($aData, $zData = false)
 {
     // Checks fields before submission of data.
     global $_AUTH, $_DB;
     $bImport = lovd_getProjectFile() == '/import.php';
     $bCreate = ACTION && ACTION == 'create' || $bImport && !$zData;
     // Mandatory fields.
     $this->aCheckMandatory = array('symbol', 'name');
     $aData = parent::checkFields($aData);
     if (!empty($aData['id_omim']) && !preg_match('/^[1-9]\\d{5}$/', $aData['id_omim'])) {
         lovd_errorAdd('id_omim', 'The OMIM ID has to be six digits long and cannot start with a \'0\'.');
     }
     // Two diseases with the same OMIM ID are not allowed.
     if (!empty($aData['id_omim']) && ($bCreate || $aData['id_omim'] != $zData['id_omim'])) {
         $bExists = $_DB->query('SELECT id FROM ' . TABLE_DISEASES . ' WHERE id_omim = ?', array($aData['id_omim']))->fetchColumn();
         if ($bExists) {
             // IMPORTANT: when you change this message, also change the array_search argument in import.php in the Disease section.
             lovd_errorAdd('id_omim', 'Another disease already exists with this OMIM ID!');
         }
     }
     // We don't like two diseases with the exact same name, either.
     if (!empty($aData['name']) && ($bCreate || $aData['name'] != $zData['name'])) {
         $bExists = $_DB->query('SELECT id FROM ' . TABLE_DISEASES . ' WHERE name = ?', array($aData['name']))->fetchColumn();
         if ($bExists && ($bCreate || $zData['id'] != $bExists)) {
             // IMPORTANT: when you change this message, also change the array_search argument in import.php in the Disease section.
             lovd_errorAdd('name', 'Another disease already exists with the same name!');
         }
     }
     if (!$bImport && $_AUTH['level'] < LEVEL_MANAGER && empty($aData['genes'])) {
         lovd_errorAdd('genes', 'You should at least select one of the genes you are curator of.');
     }
     $_POST['genes'] = array();
     if (is_array($aData['genes'])) {
         foreach ($aData['genes'] as $sGene) {
             if (!lovd_isAuthorized('gene', $sGene, false) && $bCreate) {
                 lovd_errorAdd('genes', 'You are not authorized to add this disease to gene ' . htmlspecialchars($sGene) . '.');
             } else {
                 $_POST['genes'][] = $sGene;
             }
         }
     }
     if (!$bCreate) {
         if (is_array($aData['genes']) && isset($zData['genes']) && is_array($zData['genes'])) {
             foreach ($zData['genes'] as $sGene) {
                 if ($sGene && !in_array($sGene, $aData['genes']) && !lovd_isAuthorized('gene', $sGene, false)) {
                     lovd_errorAdd('genes', 'You are not authorized to remove this disease from gene ' . htmlspecialchars($sGene) . '.');
                     $_POST['genes'][] = $sGene;
                 }
             }
         }
     }
     // XSS attack prevention. Deny input of HTML.
     lovd_checkXSS();
 }
Esempio n. 4
0
 function checkFields($aData, $zData = false)
 {
     // Checks fields before submission of data.
     global $_DB;
     // No mandatory fields, since all the gene data is in $_SESSION.
     if (isset($aData['workID'])) {
         unset($aData['workID']);
     }
     parent::checkFields($aData);
     if (ACTION == 'create') {
         if ($_DB->query('SELECT COUNT(*) FROM ' . TABLE_GENES . ' WHERE id = ?', array($zData['id']))->fetchColumn()) {
             lovd_errorAdd('', 'Unable to add gene. This gene symbol already exists in the database!');
         } elseif ($_DB->query('SELECT COUNT(*) FROM ' . TABLE_GENES . ' WHERE id_hgnc = ?', array($zData['id_hgnc']))->fetchColumn()) {
             lovd_errorAdd('', 'Unable to add gene. A gene with this HGNC ID already exists in the database!');
         }
     }
     if (lovd_getProjectFile() != '/import.php' && !in_array($aData['refseq_genomic'], $zData['genomic_references'])) {
         lovd_errorAdd('refseq_genomic', 'Please select a proper NG, NC, or LRG accession number in the \'NCBI accession number for the genomic reference sequence\' selection box.');
     }
     if (!empty($aData['refseq']) && empty($aData['refseq_url'])) {
         lovd_errorAdd('refseq', 'You have selected that there is a human-readable reference sequence. Please fill in the "Human-readable reference sequence location" field. Otherwise, select \'No\' for the "This gene has a human-readable reference sequence" field.');
     }
     if ($aData['disclaimer'] == 2 && empty($aData['disclaimer_text'])) {
         lovd_errorAdd('disclaimer_text', 'If you wish to use an own disclaimer, please fill in the "Text for own disclaimer" field. Otherwise, select \'No\' for the "Include disclaimer" field.');
     }
     // Numeric values
     $aCheck = array('header_align' => 'Header aligned to', 'footer_align' => 'Footer aligned to');
     foreach ($aCheck as $key => $val) {
         if ($aData[$key] && !is_numeric($aData[$key])) {
             lovd_errorAdd($key, 'The \'' . $val . '\' field has to contain a numeric value.');
         }
     }
     // URL values
     if ($aData['url_homepage'] && !lovd_matchURL($aData['url_homepage'])) {
         lovd_errorAdd('url_homepage', 'The \'Homepage URL\' field does not seem to contain a correct URL.');
     }
     if ($aData['refseq_url'] && !lovd_matchURL($aData['refseq_url'], true)) {
         lovd_errorAdd('refseq_url', 'The \'Human-readable reference sequence location\' field does not seem to contain a correct URL.');
     }
     // List of external links.
     if ($aData['url_external']) {
         $aExternalLinks = explode("\r\n", $aData['url_external']);
         foreach ($aExternalLinks as $n => $sLink) {
             if (!lovd_matchURL($sLink) && (!preg_match('/^[^<>]+ <([^< >]+)>$/', $sLink, $aRegs) || !lovd_matchURL($aRegs[1]))) {
                 lovd_errorAdd('url_external', 'External link #' . ($n + 1) . ' (' . htmlspecialchars($sLink) . ') not understood.');
             }
         }
     }
     // XSS attack prevention. Deny input of HTML.
     // Ignore the 'External links' field.
     unset($aData['url_external'], $aData['disclaimer_text'], $aData['header'], $aData['footer'], $aData['note_index'], $aData['note_listing']);
     lovd_checkXSS($aData);
 }
Esempio n. 5
0
 function checkFields($aData, $zData = false)
 {
     // Checks fields before submission of data.
     global $_DB;
     // Mandatory fields.
     $this->aCheckMandatory = array('category', 'colid', 'head_column', 'description_legend_short', 'description_legend_full', 'mysql_type', 'form_type', 'width');
     if (ACTION == 'edit') {
         unset($this->aCheckMandatory['colid']);
     } elseif (!empty($aData['active_links']) && !preg_match('/^TEXT|VARCHAR/', $aData['mysql_type'])) {
         lovd_errorAdd('active_links', 'Only VARCHAR or TEXT columns can have custom links activated for it!');
     }
     parent::checkFields($aData);
     // Category; not chosen on this form, but we want to make sure it's correct anyways.
     if (!empty($aData['category']) && !in_array($aData['category'], array('Individual', 'Phenotype', 'Screening', 'VariantOnGenome', 'VariantOnTranscript'))) {
         lovd_errorAdd('category', 'The category is not correct. Please choose one of the following: Individual, Phenotype, Screening, VariantOnGenome or VariantOnTranscript.');
     }
     // ColID format.
     if (!empty($aData['colid']) && !preg_match('/^[A-Za-z0-9_]+(\\/[A-Za-z0-9_]+)*$/', $aData['colid'])) {
         lovd_errorAdd('colid', 'The column ID is not of the correct format. It can contain only letters, numbers and underscores. Subcategories must be divided by a slash (/).');
     }
     // During an import ColID that exist in the database do not give a hard error. Error is handled in import.php
     if (lovd_getProjectFile() != '/import.php') {
         // ColID must not exist in the database.
         if (!empty($aData['category']) && !empty($aData['colid'])) {
             if ($_DB->query('SELECT COUNT(*) FROM ' . TABLE_COLS . ' WHERE id = ?', array($aData['category'] . '/' . $aData['colid']))->fetchColumn()) {
                 lovd_errorAdd('colid', 'There is already a ' . $aData['category'] . ' column with this column ID. Please verify that you\'re not trying to create a column that already exists!');
             }
         }
     }
     // Width can not be less than 20 or more than 500.
     // These numbers are also defined in object_shared_columns.php and inc-js-columns.php.
     if (isset($aData['width']) && strlen($aData['width']) > 0) {
         if ($aData['width'] > 500) {
             lovd_errorAdd('width', 'The width can not be more than 500 pixels!');
         } elseif ($aData['width'] < 20) {
             lovd_errorAdd('width', 'The width can not be less than 20 pixels!');
         }
     }
     // MySQL type format.
     if ($aData['mysql_type'] && !preg_match('/^(TEXT|VARCHAR\\([0-9]{1,3}\\)|DATE(TIME)?|((TINY|SMALL|MEDIUM|BIG)?INT\\([0-9]{1,2}\\)|DECIMAL\\([0-9]{1,2}\\,[0-9]{1,2}\\)|FLOAT)( UNSIGNED)?)( DEFAULT ([0-9]+|"[^"]+"))?$/i', $aData['mysql_type'])) {
         lovd_errorAdd('mysql_type', 'The MySQL data type is not recognized. Please use the data type wizard to generate a proper MySQL data type.');
     }
     // Form type.
     if ($aData['form_type'] && !preg_match('/^[^|]+\\|[^|]*\\|(checkbox|text\\|[0-9]+|textarea\\|[0-9]+\\|[0-9]+|select\\|[0-9]+\\|[^|]*\\|(false|true)\\|(false|true))$/i', $aData['form_type'])) {
         lovd_errorAdd('form_type', 'The form type is not recognized. Please use the data type wizard to generate a proper form type.');
     }
     // XSS attack prevention. Deny input of HTML.
     // Ignore some fields that are allowed to contain HTML, or that might cause false positives.
     unset($aData['description_form'], $aData['preg_pattern'], $aData['description_legend_short'], $aData['description_legend_full']);
     lovd_checkXSS($aData);
 }
Esempio n. 6
0
 function checkFields($aData, $zData = false)
 {
     // Checks fields before submission of data.
     global $_SETT;
     $this->aCheckMandatory = array('system_title', 'email_address', 'refseq_build');
     parent::checkFields($aData);
     // Database URL is mandatory, if the option "Include in the global LOVD listing" is selected.
     if (!empty($aData['include_in_listing']) && empty($aData['location_url'])) {
         lovd_errorAdd('location_url', 'Please fill in an URL in the \'Database URL\' field, if you want this LOVD installation to be included in the global LOVD listing; otherwise disable the \'Include in the global LOVD listing\' setting below.');
     }
     // Database URL should be an URL.
     if (!empty($aData['location_url']) && !lovd_matchURL($aData['location_url'])) {
         lovd_errorAdd('location_url', 'Please fill in a correct URL in the \'Database URL\' field.');
     }
     // Email address.
     if (!empty($aData['email_address']) && !lovd_matchEmail($aData['email_address'])) {
         lovd_errorAdd('email_address', 'Please fill in a correct email address.');
     }
     // Refseq build should match the available builds.
     if (!empty($aData['refseq_build']) && !array_key_exists($aData['refseq_build'], $_SETT['human_builds'])) {
         lovd_errorAdd('refseq_build', 'Please select one of the available Human Builds.');
     }
     // Proxy server checks (valid hostname, valid port number, try connecting.
     if (!empty($aData['proxy_host'])) {
         // Pattern taken from lovd_matchURL().
         if (!preg_match('/^([0-9]{1,3}(\\.[0-9]{1,3}){3}|(([0-9a-z][-0-9a-z]*[0-9a-z]|[0-9a-z])\\.?)+[a-z]{2,6})$/i', $aData['proxy_host'])) {
             lovd_errorAdd('proxy_host', 'Please fill in a correct host name of the proxy server, if you wish to use one.');
         } elseif (empty($aData['proxy_port'])) {
             lovd_errorAdd('proxy_port', 'Please fill in a correct, numeric, port number of the proxy server, if you wish to use a proxy server.');
         } else {
             // Alright, let's try and connect.
             // First: normal connect, direct, no outside connection requested.
             $f = @fsockopen($aData['proxy_host'], $aData['proxy_port'], $nError, $sError, 5);
             if ($f === false) {
                 lovd_errorAdd('proxy_host', 'Could not connect to given proxy server. Please check if the fields are correctly filled in.');
                 lovd_errorAdd('proxy_port', '');
             } else {
                 $sRequest = 'GET ' . $_SETT['check_location_URL'] . ' HTTP/1.0' . "\r\n" . 'User-Agent: LOVDv.' . $_SETT['system']['version'] . " Proxy Check\r\n" . (empty($_POST['proxy_username']) || empty($_POST['proxy_password']) ? '' : 'Proxy-Authorization: Basic ' . base64_encode($_POST['proxy_username'] . ':' . $_POST['proxy_password']) . "\r\n") . 'Connection: Close' . "\r\n\r\n";
                 fputs($f, $sRequest);
                 $s = rtrim(fgets($f));
                 if (!preg_match('/^HTTP\\/1\\.. [23]/', $s, $aRegs)) {
                     // Allowing HTTP 2XX and 3XX.
                     if (preg_match('/^HTTP\\/1\\.. 407/', $s, $aRegs)) {
                         // Proxy needs username and password.
                         if (!empty($_POST['proxy_username']) && !empty($_POST['proxy_password'])) {
                             lovd_errorAdd('proxy_username', 'Invalid username/password combination for this proxy server. Please try again.');
                             lovd_errorAdd('proxy_password', '');
                         } else {
                             lovd_errorAdd('proxy_username', 'This proxy server requires a valid username and password. Please make sure you provide them both.');
                             lovd_errorAdd('proxy_password', '');
                         }
                     } else {
                         lovd_errorAdd('proxy_host', 'Unexpected answer from proxy when trying to connect upstream: ' . $s);
                     }
                 }
             }
         }
     } elseif (!empty($aData['proxy_port'])) {
         // We have a port number, but no host name.
         lovd_errorAdd('proxy_host', 'Please also fill in a correct host name of the proxy server, if you wish to use one.');
     }
     // Custom logo must exist.
     if (!empty($aData['logo_uri'])) {
         // Determine if file can be read and is an image or not.
         if (!is_readable(ROOT_PATH . $aData['logo_uri'])) {
             lovd_errorAdd('logo_uri', 'Cannot read the custom logo file. Please make sure the path is correct and that the file can be read.');
         } else {
             $a = @getimagesize(ROOT_PATH . $aData['logo_uri']);
             if (!is_array($a)) {
                 lovd_errorAdd('logo_uri', 'The custom logo file that you selected does not seem to be a picture.');
             }
         }
     } else {
         // FIXME; this is probably not the best way of doing this...
         $_POST['logo_uri'] = 'gfx/LOVD3_logo145x50.jpg';
     }
     // FIXME; Like above, not the best solution, but gets the job done for now.
     if (empty($aData['mutalyzer_soap_url'])) {
         $_POST['mutalyzer_soap_url'] = 'https://mutalyzer.nl/services';
     }
     // SSL check.
     if (!empty($aData['use_ssl']) && !SSL) {
         lovd_errorAdd('use_ssl', 'You\'ve selected to force the use of SSL, but SSL is not currently activated for this session. To force SSL, I must be sure it\'s possible to approach LOVD through an SSL connection (use <A href="https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . ($_SERVER['QUERY_STRING'] ? '?' . str_replace('&sent=true', '', $_SERVER['QUERY_STRING']) : '') . '" target="_blank">https://</A> instead of http://).');
     }
     $_POST['api_feed_history'] = 0;
     $_POST['allow_count_hidden_entries'] = 0;
     $_POST['use_versioning'] = 0;
     // XSS attack prevention. Deny input of HTML.
     lovd_checkXSS();
 }
Esempio n. 7
0
 function checkFields($aData, $zData = false)
 {
     // Checks fields before submission of data.
     // Mandatory fields.
     $this->aCheckMandatory = array('description_legend_short', 'description_legend_full', 'width');
     parent::checkFields($aData);
     // Width can not be less than 20 or more than 500.
     // These numbers are also defined in object_columns.php and inc-js-columns.php.
     if (isset($aData['width']) && strlen($aData['width']) > 0) {
         if ($aData['width'] > 500) {
             lovd_errorAdd('width', 'The width can not be more than 500 pixels!');
         } elseif ($aData['width'] < 20) {
             lovd_errorAdd('width', 'The width can not be less than 20 pixels!');
         }
     }
     // XSS attack prevention. Deny input of HTML.
     // Ignore some fields that are allowed to contain HTML, or that might cause false positives.
     unset($aData['description_form'], $aData['description_legend_short'], $aData['description_legend_full']);
     lovd_checkXSS($aData);
 }
Esempio n. 8
0
 function checkFields($aData, $zData = false)
 {
     // Checks fields before submission of data.
     global $_AUTH, $_DB, $_PE, $_SETT;
     // Mandatory fields.
     $this->aCheckMandatory = array('name', 'institute', 'address', 'city', 'countryid', 'email', 'username');
     // These password fields are only not mandatory when we're editing.
     if (ACTION != 'edit') {
         $this->aCheckMandatory[] = 'password_1';
         $this->aCheckMandatory[] = 'password_2';
     }
     parent::checkFields($aData);
     // Email address.
     if (!empty($aData['email'])) {
         $aEmail = explode("\r\n", $aData['email']);
         foreach ($aEmail as $sEmail) {
             if (!lovd_matchEmail($sEmail)) {
                 lovd_errorAdd('email', 'Email "' . htmlspecialchars($sEmail) . '" is not a correct email address' . ($sEmail && $sEmail == trim($sEmail) ? '' : '. Make sure there are no spaces or empty lines left in the email field') . '.');
             }
         }
     }
     if (lovd_getProjectFile() == '/install/index.php' || ACTION == 'create') {
         // Check username format.
         if ($aData['username'] && !lovd_matchUsername($aData['username'])) {
             lovd_errorAdd('username', 'Please fill in a correct username; 4 to 20 characters and starting with a letter followed by letters, numbers, dots, underscores and dashes only.');
         }
     }
     if (in_array(ACTION, array('create', 'register'))) {
         // Does the username exist already?
         if ($aData['username']) {
             if ($_DB->query('SELECT COUNT(*) FROM ' . TABLE_USERS . ' WHERE username = ?', array($aData['username']))->fetchColumn()) {
                 lovd_errorAdd('username', 'There is already a user with this username. Please choose another one.');
             }
         }
     }
     // One of two password fields entered... check 'em.
     if ($aData['password_1'] || $aData['password_2']) {
         if ($aData['password_1'] && $aData['password_2']) {
             // Both entered.
             if ($aData['password_1'] != $aData['password_2']) {
                 lovd_errorAdd('password_2', 'The \'' . (in_array(ACTION, array('edit', 'change_password')) ? 'New p' : 'P') . 'assword\' fields are not equal. Please try again.');
             } else {
                 // Password quality.
                 if (!lovd_matchPassword($aData['password_1'])) {
                     lovd_errorAdd('password_1', 'Your password is found too weak. Please fill in a proper password; at least 4 characters long and containing at least one number or special character.');
                 }
             }
         } else {
             if (in_array(ACTION, array('edit', 'change_password'))) {
                 lovd_errorAdd('password_2', 'If you want to change the current password, please fill in both \'New password\' fields.');
             } else {
                 lovd_errorAdd('password_2', 'Please fill in both \'Password\' fields.');
             }
         }
     }
     // Check given security IP range.
     if (!empty($aData['allowed_ip'])) {
         // This function will throw an error itself (second argument).
         $bIP = lovd_matchIPRange($aData['allowed_ip'], 'allowed_ip');
         if (lovd_getProjectFile() == '/install/index.php' || ACTION == 'edit' && $_PE[1] == $_AUTH['id']) {
             // Check given security IP range.
             if ($bIP && !lovd_validateIP($aData['allowed_ip'], $_SERVER['REMOTE_ADDR'])) {
                 // This IP range is not allowing the current IP to connect. This ain't right.
                 // If IP address is actually IPv6, then complain that we can't restrict at all.
                 // Otherwise, be clear the current setting just doesn't match.
                 if (strpos($_SERVER['REMOTE_ADDR'], ':') !== false) {
                     // IPv6...
                     lovd_errorAdd('allowed_ip', 'Your current IP address is IPv6 (' . $_SERVER['REMOTE_ADDR'] . '), which is not supported by LOVD to restrict access to your account.');
                 } else {
                     lovd_errorAdd('allowed_ip', 'Your current IP address is not matched by the given IP range. This would mean you would not be able to get access to LOVD with this IP range.');
                 }
             }
         }
     } else {
         // We're not sure if $aData == $_POST. But we'll just do this. It can't harm I guess.
         $_POST['allowed_ip'] = '*';
     }
     // Level can't be higher or equal than the current user.
     if (!empty($aData['level']) && $aData['level'] >= $_AUTH['level']) {
         lovd_writeLog('Error', 'HackAttempt', 'Tried to upgrade user ID ' . $_PE[1] . ' to level ' . $_SETT['user_levels'][$aData['level']] . ')');
         lovd_errorAdd('level', 'User level is not permitted. Hack attempt.');
     }
     // XSS attack prevention. Deny input of HTML.
     lovd_checkXSS();
 }
 function checkFields($aData, $zData = false)
 {
     // Checks fields before submission of data.
     // Loop through all transcripts to have each transcript's set of columns checked.
     global $_AUTH;
     // Reset mandatory fields, because import.php calls checkFields() multiple times
     // and we don't want this list to grow forever.
     $this->aCheckMandatory = array();
     foreach (array_keys($this->aTranscripts) as $nTranscriptID) {
         if (!empty($aData['ignore_' . $nTranscriptID])) {
             continue;
         }
         $sPrefix = lovd_getProjectFile() == '/import.php' ? '' : $nTranscriptID . '_';
         foreach ($this->aColumns as $sCol => $aCol) {
             if (!$aCol['public_add'] && $_AUTH['level'] < LEVEL_CURATOR) {
                 continue;
             }
             $sCol = $sPrefix . $sCol;
             if ($aCol['mandatory']) {
                 $this->aCheckMandatory[] = $sCol;
             }
             if (isset($aData[$sCol])) {
                 $this->checkInputRegExp($sCol, $aData[$sCol]);
                 $this->checkSelectedInput($sCol, $aData[$sCol]);
             }
         }
         $this->aCheckMandatory[] = $sPrefix . 'effect_reported';
         if ($_AUTH['level'] >= LEVEL_CURATOR) {
             $this->aCheckMandatory[] = $sPrefix . 'effect_concluded';
         } elseif (isset($aData[$sPrefix . 'effect_reported']) && $aData[$sPrefix . 'effect_reported'] === '0') {
             // Submitters must fill in the variant effect field; '0' is not allowed for them.
             unset($aData[$sPrefix . 'effect_reported']);
         }
     }
     // Bypass LOVD_Custom::checkFields(), since it's functionality has been copied above.
     LOVD_Object::checkFields($aData);
     lovd_checkXSS();
 }
Esempio n. 10
0
 function checkFields($aData, $zData = false)
 {
     // Checks fields before submission of data.
     global $_DB;
     // Mandatory fields.
     $this->aCheckMandatory = array('name', 'pattern_text', 'replace_text', 'description');
     parent::checkFields($aData);
     // Link name must be unique.
     if (!empty($aData['name'])) {
         // Enforced in the table, but we want to handle this gracefully.
         $sSQL = 'SELECT COUNT(*) FROM ' . TABLE_LINKS . ' WHERE name = ?';
         $aSQL = array($aData['name']);
         if (ACTION == 'edit') {
             $sSQL .= ' AND id != ?';
             $aSQL[] = $zData['id'];
         }
         if ($_DB->query($sSQL, $aSQL)->fetchColumn()) {
             lovd_errorAdd('name', 'There is already a custom link with this link name. Please choose another one.');
         }
     }
     if (!isset($aData['active_columns'])) {
         $_POST['active_columns'] = array();
     } elseif (!empty($aData['active_columns'])) {
         // Check if columns are text columns, since others cannot even hold the custom link's pattern text.
         $aColumns = $_DB->query('SELECT id FROM ' . TABLE_COLS . ' WHERE mysql_type LIKE \'VARCHAR%\' OR mysql_type LIKE \'TEXT%\'')->fetchAllColumn();
         foreach ($aData['active_columns'] as $sCol) {
             if (substr_count($sCol, '/') && !in_array($sCol, $aColumns)) {
                 // Columns without slashes are the category headers, that could be selected.
                 lovd_errorAdd('active_columns', 'Please select a valid custom column from the \'Active for columns\' selection box.');
             }
         }
     }
     // On the pattern text.
     if (!empty($aData['pattern_text'])) {
         // Pattern text must be unique.
         // Enforced in the table, but we want to handle this gracefully.
         $sSQL = 'SELECT COUNT(*) FROM ' . TABLE_LINKS . ' WHERE pattern_text = ?';
         $aSQL = array($aData['pattern_text']);
         if (ACTION == 'edit') {
             $sSQL .= ' AND id != ?';
             $aSQL[] = $zData['id'];
         }
         if ($_DB->query($sSQL, $aSQL)->fetchColumn()) {
             lovd_errorAdd('pattern_text', 'There is already a custom link with this pattern. Please choose another one.');
         } else {
             // Check the pattern of the pattern text.
             if (!preg_match('/^\\{([A-Z0-9 :;,_-]|\\[[0-9]\\])+\\}$/i', $aData['pattern_text'])) {
                 lovd_errorAdd('pattern_text', 'The link pattern is found to be incorrect. It must start with \'{\', end with \'}\' and can contain letters, numbers, spaces, some special characters (:;,_-) and references ([1] to [9]) and must be 3-25 characters long.');
             }
             // References shouldn't follow each other directly, because LOVD wouldn't know the separation character.
             if (preg_match('/(\\[[0-9]\\]){2,}/', $aData['pattern_text'])) {
                 lovd_errorAdd('pattern_text', 'The link pattern is found to be incorrect. Two or more references directly after each other must be separated by at least one character to keep the two apart.');
             }
         }
         // Check references in the pattern and replacement texts.
         if (!empty($aData['replace_text'])) {
             // Isolate reference numbers.
             $aPattern = explode(']', $aData['pattern_text']);
             $aPatternRefs = array();
             foreach ($aPattern as $val) {
                 if (substr_count($val, '[')) {
                     $aPatternRefs[] = substr(strrchr($val, '['), 1);
                 }
             }
             // Isolate reference numbers.
             $aReplace = explode(']', $aData['replace_text']);
             $aReplaceRefs = array();
             foreach ($aReplace as $val) {
                 if (substr_count($val, '[')) {
                     $aReplaceRefs[] = substr(strrchr($val, '['), 1);
                 }
             }
             // Check for reference order and/or references missing from the replacement text.
             reset($aPatternRefs);
             for ($i = 1; list(, $nRef) = each($aPatternRefs); $i++) {
                 if ($nRef != $i) {
                     lovd_errorAdd('pattern_text', 'The link pattern is found to be incorrect. Expected reference [' . $i . '] ' . ($i == 1 ? 'first' : 'after [' . ($i - 1) . ']') . ', got [' . $nRef . '].');
                 }
             }
             foreach ($aReplaceRefs as $nRef) {
                 if (!in_array($nRef, $aPatternRefs)) {
                     lovd_errorAdd('replace_text', 'The link replacement text is found to be incorrect. Could not find used reference [' . $nRef . '] in link pattern.');
                 }
             }
             foreach ($aPatternRefs as $nPatternRef) {
                 if (!in_array($nPatternRef, $aReplaceRefs)) {
                     lovd_errorAdd('replace_text', 'The link replacement text is found to be incorrect. Expected reference [' . $nPatternRef . '] not found in replacement text.');
                 }
             }
         }
     }
     // NO XSS attack prevention, because the replacement NEEDS HTML.
     // lovd_checkXSS();
 }
Esempio n. 11
0
 function checkFields($aData, $zData = false)
 {
     global $_AUTH;
     // Checks fields before submission of data.
     foreach ($this->aColumns as $sCol => $aCol) {
         if ($aCol['mandatory']) {
             $this->aCheckMandatory[] = $sCol;
         }
         // Make it easier for users to fill in the age fields. Change 5d into 00y00m05d, for instance.
         if (preg_match('/\\/Age(\\/.+|_.+)?$/', $sCol) && $aData[$sCol] && preg_match('/^([<>])?(\\d{1,2}y)?(\\d{1,2}m)?(\\d{1,2}d)?(\\?)?$/', $aData[$sCol], $aRegs)) {
             $aRegs = array_pad($aRegs, 6, '');
             if ($aRegs[2] || $aRegs[3] || $aRegs[4]) {
                 // At least some data needs to be filled in!
                 // First, pad the numbers.
                 foreach ($aRegs as $key => $val) {
                     if (preg_match('/^\\d{1}[ymd]$/', $val)) {
                         $aRegs[$key] = '0' . $val;
                     }
                 }
                 // Then, glue everything together.
                 $aData[$sCol] = $_POST[$sCol] = $aRegs[1] . (!$aRegs[2] ? '00y' : $aRegs[2]) . (!$aRegs[3] && $aRegs[4] ? '00m' : $aRegs[3]) . (!$aRegs[4] ? '' : $aRegs[4]) . (!$aRegs[5] ? '' : $aRegs[5]);
             }
         }
         if (!empty($aData[$sCol])) {
             $this->checkInputRegExp($sCol, $aData[$sCol]);
             $this->checkSelectedInput($sCol, $aData[$sCol]);
         }
     }
     if ($_AUTH['level'] < LEVEL_CURATOR) {
         if (!empty($aData['owned_by'])) {
             // FIXME; this is a hack attempt. We should consider logging this. Or just plainly ignore the value.
             lovd_errorAdd('owned_by', 'Not allowed to change \'Owner of this data\'.');
         }
         if (!empty($aData['statusid'])) {
             lovd_errorAdd('statusid', 'Not allowed to set \'Status of this data\'.');
         }
     }
     if (lovd_getProjectFile() == '/import.php' && $this->sObject == 'Genome_Variant' && ($nIndex = array_search('VariantOnGenome/DBID', $this->aCheckMandatory)) !== false) {
         // Importing, and in VOG. Make the DBID non-mandatory, because it will be predicted by the import script when it's empty.
         unset($this->aCheckMandatory[$nIndex]);
     }
     parent::checkFields($aData);
 }