* Script for defining all functions used by DNA Module
* @author Gabriele Droege, DNA Bank Network
* @version 2.0
* @package Configuration
* @copyright Copyright © 2011 DNA Bank Network http://www.dnabank-network.org
The contents of this file are subject to the Mozilla Public License Version 1.1
* @filesource
* @license http://www.mozilla.org/MPL/ MPL
*/
header('Content-Type: text/html; charset=utf-8');
if(file_exists("config/loadsmtp.php"))
{
/**
* load defined SMTP path and port, include xml-parser (and xml file) from DNA_MODULE_PATH/config
*/
include("config/loadsmtp.php"); } else {
/**
* load alternative SMTP path and port
*/
include("../config/loadsmtp.php");}
ini_set("SMTP", $SMTP_Path);
ini_set("smtp_port", $SMTP_Port);
if(file_exists("config/loadgeneralsettings.php"))
{
/**
* load configurations for DNA Module, include xml-parser (and xml file) from DNA_MODULE_PATH/config
*/
include("config/loadgeneralsettings.php"); } else {
/**
* load alternative path for configurations
*/
include("../config/loadgeneralsettings.php");}
/**
* set global path for link to online handbook; every page links to the relevant handbook page
*/
$Path_Wiki = 'http://wiki.bgbm.org/dnabankwiki/index.php';
global $Path_Wiki;
/**
* set global debug level; default: $debug = '0'; usually an error message and email (to administrator) is triggered when a script error occurs; debug level = '1' will display the error at the frontend pages
*/
$debug = '1';
global $debug;
/**
* Connection to database
load parameters, include xml-parser (and xml file) from DNA_MODULE_PATH/config
if connection failed forwarding to createtables.php
* @param string $host DNA Database Host
* @param string $user DNA Database User
* @param string $passwd DNA Database Password
* @param string $dbname DNA Database Name
* @access public
* @return bool
* @see createtables.php
*/
function connect_to_dna() {
if(file_exists("config/loaddnaprovider.php"))
{include("config/loaddnaprovider.php"); }
else { include("../config/loaddnaprovider.php");}
if($DBMS == "mysql") {
$connID = @($GLOBALS["___mysqli_ston"] = mysqli_connect($host, $user, $passwd));
if(!$connID) { die('Connection failed: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
// header('Location: createtables.php');
}
if ($connID) {
$connection = ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE $dbname"));
return $connID;
if(!$connection){
die('Connection failed: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
// header('Location: createtables.php');
} }
}
}
/**
* Error handler, generates an email message with errormessage
* @param string $errno Error type
* @param string $errmsg Php/mysql error message
* @param string $filename Name of file caused error
* @param string $linenum Line in file caused error
* @access public
*/
function getErrorHandler($errno,$errmsg,$filename,$linenum) {
$msg = "Time: " .date("Y-m-d H:i:s"). "\n";
$msg .= "Error: " .$errmsg. "\n";
$msg .= "File: " .$filename. "\n";
$msg .= "Line: " .$linenum;
switch ($errno) {
case E_NOTICE: case E_USER_NOTICE:
return;
break;
case E_STRICT:
return;
break;
default:
if(empty($Email_Admin) or !isset($Email_Admin))
{$sendto = "g.droege@bgbm.org"; }
else { $sendto = $Email_Admin; }
$from = "From: contact@dnabank-network.org";
mail($sendto, $errmsg." ".$filename, $msg, $from);
if($debug = '1') echo $msg;
break; }
}
set_error_handler("getErrorHandler");
/**
* Check content of all fields
* @param integer $ar key
* @param string $key element
* @access public
* @return bool
*/
function array_item($ar, $key)
{
if(is_array($ar) && array_key_exists($key, $ar))
return $ar[$key];
else
return false;
}
/**
* Generate randomised password, 8 characters
* @access public
* @param string $randomPassword
* @return string
*/
function RandPass()
{
$randomPassword = "";
srand((double)microtime()*1000000);
for($i=0;$i<8;$i++)
{
$randnumber = rand(48,120);
while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
{
$randnumber = rand(48,120);
}
$randomPassword .= chr($randnumber);
}
return $randomPassword;
}
$randomstring = RandPass();
/**
* Build formatted hyperlink, with text-decoration and standard colours and special query parameters
* @param string $url domain and path
* @param string $query site and query parameters
* @param string $name hyperlink name
* @access public
* @return string
*/
function build_href($url, $query, $name)
{
if($query)
return "" . $name . "";
else
return "" . $name . "";
}
/**
* Build formatted hyperlink, with text-decoration and standard colours and special query parameters, but opens in new tab/window
* @param string $url domain and path
* @param string $query site and query parameters
* @param string $name hyperlink name
* @access public
* @return string
*/
function build_href_blank($url, $query, $name)
{
if($query)
return "" . $name . "";
else
return "" . $name . "";
}
/**
* Build formatted hyperlink, without text-decoration and without special query parameters
* @param string $url domain and path
* @param string $name hyperlink name
* @access public
* @return string
*/
function build_href1($url, $name)
{
return "" . $name . "";
}
/**
* Build formatted hyperlink, with text-decoration and standard colours, special query parameters and title description
* @param string $url domain and path
* @param string $query site and query parameters
* @param string $name hyperlink name
* @param string $title description
* @access public
* @return string
*/
function build_href2($url, $query, $name, $title)
{
if($query)
return "" . $name . "";
else
return "" . $name . "";
}
/**
* Build a field list (