Source for file start.inc.php

Documentation is available at start.inc.php

  1. <?php
  2. /**
  3. * Main functions
  4. * <br/><br/>
  5. * Script for defining all functions used by DNA Module
  6. * @author Gabriele Droege, DNA Bank Network <contact@dnabank-network.org>
  7. * @version 2.0
  8. * @package Configuration
  9. * @copyright Copyright © 2011 DNA Bank Network http://www.dnabank-network.org<br>The contents of this file are subject to the Mozilla Public License Version 1.1
  10. * @filesource
  11. * @license http://www.mozilla.org/MPL/ MPL
  12. */
  13.  
  14. header('Content-Type: text/html; charset=utf-8');
  15.  
  16.  
  17.  
  18. if(file_exists("load/loadsmtp.php"))
  19. { 
  20. /**
  21. * load defined SMTP path and port, include xml-parser (and xml file) from DNA_MODULE_PATH/load/
  22. */
  23.  
  24. include("load/loadsmtp.php"); } else { 
  25. /**
  26. * load alternative SMTP path and port
  27. */
  28. include("../load/loadsmtp.php");}
  29. ini_set("SMTP", $SMTP_Path);
  30. ini_set("smtp_port", $SMTP_Port);
  31.  
  32.  
  33. if(file_exists("load/loadconfig.php"))
  34. { 
  35. /**
  36. * load configurations for DNA Module, include xml-parser (and xml file) from DNA_MODULE_PATH/load/
  37. */
  38.  
  39. include("load/loadconfig.php"); } else { 
  40. /**
  41. * load alternative path for configurations
  42. */
  43. include("../load/loadconfig.php");} 
  44.  
  45. $Path_Wiki = 'http://wiki.bgbm.org/dnabankwiki/index.php';
  46. global $Path_Wiki;
  47.  
  48.  
  49. /**
  50. * Connection to database<br>load parameters, include xml-parser (and xml file) from DNA_MODULE_PATH/load/<br>if connection failed forwarding to createtables.php
  51. * @param string $host DNA Database Host
  52. * @param string $user DNA Database User
  53. * @param string $passwd DNA Database Password
  54. * @param string $dbname DNA Database Name
  55. * @access public
  56. * @return bool 
  57. * @see createtables.php
  58. */ 
  59.   function connect_to_dna() {
  60.   if(file_exists("load/loaddnaprovider.php"))
  61.   {include("load/loaddnaprovider.php"); }
  62.  
  63.   else { include("../load/loaddnaprovider.php");}
  64.   if($DBMS == "mysql") {
  65.  
  66.   $connID = @mysql_connect($host, $user, $passwd);
  67.   
  68.   if(!$connID) {  header('Location: createtables.php');}
  69.   
  70.     if ($connID) {
  71.     $connection = mysql_select_db($dbname);
  72.     return $connID; 
  73.     if(!$connection){  header('Location: createtables.php');} }
  74.     
  75.   }
  76.   
  77. }
  78. /**
  79. * Error handler, generates an email message with errormessage
  80. * @param string $errno Error type
  81. * @param string $errmsg Php/mysql error message
  82. * @param string $filename Name of file caused error
  83. * @param string $linenum Line in file caused error
  84. * @access public
  85. */ 
  86.  
  87. function getErrorHandler($errno,$errmsg,$filename,$linenum) {
  88.     $msg = "Time: " .date("Y-m-d H:i:s"). "\n";
  89.     $msg .= "Error: " .$errmsg. "\n";
  90.     $msg .= "File: " .$filename. "\n";
  91.     $msg .= "Line: " .$linenum;
  92.     switch ($errno) {
  93.     case E_NOTICE: case E_USER_NOTICE:
  94.     return;
  95.     break;
  96.     case E_STRICT:
  97.     return;
  98.     break;
  99.     default:
  100.     if(empty($Email_Admin) or !isset($Email_Admin))
  101.     {$sendto = "g.droege@bgbm.org"; }
  102.     else { $sendto = $Email_Admin; }
  103.     
  104.     $from = "From: dnamodule@dnabank-network.org";
  105.     mail($sendto, $errmsg." ".$filename, $msg, $from); 
  106.     break; }
  107.  
  108.     } 
  109.     set_error_handler("getErrorHandler");
  110.  
  111.  
  112.  
  113. /**
  114. * Check content of all fields
  115. * @param integer $ar key
  116. * @param string $key element
  117. * @access public
  118. * @return bool 
  119. */
  120.  
  121. function array_item($ar, $key) 
  122.    {
  123.   if(is_array($ar) && array_key_exists($key, $ar))
  124.     return $ar[$key];
  125.   else
  126.     return false; 
  127.    }
  128.  
  129.    
  130. /**
  131. * Generate randomised password, 8 characters
  132. * @access public
  133. * @param string $randomPassword 
  134. * @return string 
  135. */
  136. function RandPass()
  137.           {
  138.            $randomPassword = "";
  139.            srand((double)microtime()*1000000);
  140.            for($i=0;$i<8;$i++)
  141.              {
  142.                 $randnumber = rand(48,120);
  143.                 while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
  144.                 {
  145.                   $randnumber = rand(48,120);
  146.                 }
  147.                 $randomPassword .= chr($randnumber);
  148.              }
  149.           return $randomPassword;
  150.         }
  151.  
  152.        $randomstring = RandPass();
  153.    
  154. /**
  155. * Build formatted hyperlink, with text-decoration and standard colours
  156. * @param string $url domain and path
  157. * @param string $query site and query parameters
  158. * @param string $name hyperlink name
  159. * @access public
  160. * @return string 
  161. */
  162.     
  163. function build_href($url, $query, $name) 
  164. {
  165.  if($query)
  166.  return "<a class='black' href=\"$url?" . $query . "\">" . $name . "</a>";
  167.  else
  168.  return "<a class='black' href=\"$url\">" . $name . "</a>";
  169. }
  170.  
  171. /**
  172. * Build formatted hyperlink, without text-decoration and without special query parameters
  173. * @param string $url domain and path
  174. * @param string $name hyperlink name
  175. * @access public
  176. * @return string 
  177. */
  178. function build_href1($url, $name) 
  179. {
  180.  return "<a class='ohne' style='text-decoration:none' target='_blank' href=\"$url\">" . htmlentities($name) . "</a>";
  181. }
  182. /**
  183. * Build a field list (<select>) from database, starting with an empty value
  184. * @param string $formname name of element
  185. * @param string $sql SQL query from database
  186. * @param string $defaultitem Default item to be selected
  187. * @access public
  188. */
  189.  
  190. function build_select_list($formname, $sql, $defaultitem) 
  191. {
  192.   $result = mysql_query($sql);
  193.   echo '<select name="', $formname, '" id="SelectLong">';
  194.   echo '<option value="">--------';
  195.   while($row=mysql_fetch_row($result)) 
  196.   {
  197.     echo "<option ";
  198.     if($defaultitem==$row[0]) echo "selected ";
  199.     echo "value=\"$row[0]\"> ", $row[1], "\n";
  200.   }
  201.   echo "</select>\n";
  202.   mysql_free_result($result);
  203. }
  204.  
  205. /**
  206. * Build a field list (<select>) from database, starting with an empty value, with large entry field
  207. * @param string $formname name of element
  208. * @param string $sql SQL query from database
  209. * @param string $defaultitem Default item to be selected
  210. * @access public
  211. */
  212.  
  213. function build_select_listlarge($formname, $sql, $defaultitem) 
  214. {
  215.   $result = mysql_query($sql);
  216.   echo '<select name="', $formname, '" id="InputVeryLong2">';
  217.   echo '<option value="">--------';
  218.   while($row=mysql_fetch_row($result)) 
  219.   {
  220.     echo "<option ";
  221.     if($defaultitem==$row[0]) echo "selected ";
  222.     echo "value=\"$row[0]\"> ", $row[1], "\n";
  223.   }
  224.   echo "</select>\n";
  225.   mysql_free_result($result);
  226. }
  227.  
  228. /**
  229. * Build a field list (<select>) from database with counted records, starting with an empty value
  230. * @param string $formname name of element
  231. * @param string $sql SQL query from database
  232. * @param string $defaultitem Default item to be selected
  233. * @access public
  234. */
  235. function build_select_listcount($formname, $sql, $defaultitem) 
  236. {
  237.   $result = mysql_query($sql);
  238.   echo '<select name="', $formname, '" id="SelectLong">';
  239.   echo '<option value="">--------</option>';
  240.   while($row=mysql_fetch_row($result)) 
  241.   {
  242.     echo "<option ";
  243.     if($defaultitem==$row[0]) echo "selected ";
  244.     echo "value=\"$row[0]\"> ", $row[1]." (".$row[2].")", "\n</option>";
  245.   }
  246.   echo "</select>\n";
  247.   mysql_free_result($result);
  248. }
  249. /**
  250. * Build a field list (<select>) from database, starting with an empty value, short element (width)
  251. * @param string $formname name of element
  252. * @param string $sql SQL query from database
  253. * @param string $defaultitem Default item to be selected
  254. * @access public
  255. */
  256.  
  257. function build_select_listShort($formname, $sql, $defaultitem) 
  258. {
  259.   $result = mysql_query($sql);
  260.   echo '<select name="', $formname, '" id="SelectShortOne">';
  261.   echo '<option value="">--------</option>';
  262.   while($row=mysql_fetch_row($result)) 
  263.   {
  264.     echo "<option ";
  265.     if($defaultitem==$row[0]) echo "selected ";
  266.     echo "value=\"$row[0]\"> ", $row[1], "\n</option>";
  267.   }
  268.   echo "</select>\n";
  269.   mysql_free_result($result);
  270. }
  271.  
  272. /**
  273. * Build a field list (<select>) from database, starting with value=rack, short element (width)
  274. * @param string $formname name of element
  275. * @param string $sql SQL query from database
  276. * @param string $defaultitem Default item to be selected
  277. * @access public
  278. */
  279. function build_select_listShortTwo($formname, $sql, $defaultitem) 
  280. {
  281.   $result = mysql_query($sql);
  282.   echo '<select name="', $formname, '" id="SelectShortTwo">';
  283.   echo '<option value="">--------</option>';
  284.   while($row=mysql_fetch_row($result)) 
  285.   {
  286.     echo "<option ";
  287.     if($defaultitem==$row[0]) echo "selected ";
  288.     echo "value=\"$row[0]\"> ", $row[1], "\n</option>";
  289.   }
  290.   echo "</select>\n";
  291.   mysql_free_result($result);
  292. }
  293. /**
  294. * Build a field list (<select>) from database, starting with value=Internal (list of specimen databases)
  295. * @param string $formname name of element
  296. * @param string $sql SQL query from database
  297. * @param string $defaultitem Default item to be selected
  298. * @access public
  299. */
  300. function build_select_listProviderIntern($formname, $sql, $defaultitem) 
  301. {
  302.   $result = mysql_query($sql);
  303.   echo '<select name="', $formname, '" id="SelectLong">';
  304.   echo '<option value="">Internal</option>';
  305.   while($row=mysql_fetch_row($result)) 
  306.   {
  307.     $Provider_ID_Provider = $row[0];
  308.     $Provider_View_Test = $row[1];
  309.     echo "<option value=\"$Provider_ID_Provider\"";
  310.     if (isset($_REQUEST['formSubmitClear'])) {
  311.         unset($_REQUEST['formProviderIntern']); }
  312.     if (isset($_REQUEST['formSubmitSave'])) {
  313.         unset($_REQUEST['formProviderIntern']); }
  314.     else {
  315.     if ($_POST["formProviderIntern"] == $Provider_ID_Provider) { echo " selected"; } }
  316.  
  317.     echo "> $Provider_View_Test <br>\n</option>";
  318.             }
  319.     echo '</select>';
  320.   mysql_free_result($result);
  321. }
  322. /**
  323. * Build a field list (<select>) from database, starting with value=External (list of specimen databases)
  324. * @param string $formname name of element
  325. * @param string $sql SQL query from database
  326. * @param string $defaultitem Default item to be selected
  327. * @access public
  328. */
  329. function build_select_listProviderExtern($formname, $sql, $defaultitem) 
  330. {
  331.   $result = mysql_query($sql);
  332.   echo '<select name="', $formname, '" id="SelectLong">';
  333.   echo '<option value="">External</option>';
  334.   while($row=mysql_fetch_row($result)) 
  335.   {
  336.     $Provider_ID_Provider = $row[0];
  337.     $Provider_View_Test = $row[1];
  338.     echo "<option value=\"$Provider_ID_Provider\"";
  339.     if (isset($_REQUEST['formSubmitClear'])) {
  340.         unset($_REQUEST['formProviderExtern']); }
  341.     if (isset($_REQUEST['formSubmitSave'])) {
  342.         unset($_REQUEST['formProviderExtern']); }        
  343.     else {
  344.     if ($_POST["formProviderExtern"] == $Provider_ID_Provider) { echo " selected"; } }
  345.     echo "> $Provider_View_Test <br>\n</option>";
  346.             }
  347.     echo '</select>';
  348.   mysql_free_result($result);
  349. }
  350. /**
  351. * Check format of a date
  352. * @param string $date format YYYY-MM-DD required
  353. * @access public
  354. */
  355. function valiDate($date)
  356. {
  357.     if (!preg_match('/^(\d{4})\-(\d{2})\-(\d{2})$/', trim($date), $matches)) {
  358.         return false;
  359.     }
  360.     return checkdate($matches[2], $matches[3], $matches[1]);
  361. }
  362.  
  363. /**
  364. * Create GUID
  365. * @access public
  366. * @return string 
  367. */
  368.  
  369. function GUID() {
  370.   return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  371.     mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  372.     mt_rand(0, 0x0fff) | 0x4000,
  373.     mt_rand(0, 0x3fff) | 0x8000,
  374.     mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
  375. }
  376.  
  377. ?>

Documentation generated on Tue, 29 Nov 2011 10:45:18 +0100 by phpDocumentor 1.4.3