Source for file edit_connection.php

Documentation is available at edit_connection.php

  1. <?php  
  2. /**
  3. * Defining database connection
  4. *
  5. * Script is used for "First Steps" and package "Configuration"
  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.     /********************************************************************************************
  15.     * check, if user is logged in as administrator, if not permission denied                    *
  16.     *********************************************************************************************/
  17. if (!isset($_SESSION['admin']|| !$_SESSION['admin']{
  18.  
  19. $sql"SELECT ID_User FROM user";
  20. $result mysql_query($sql);
  21. if(mysql_num_rows($result0{                        
  22. $TestAdmin false;
  23. echo "<tr><td colspan='3'><span class='error'>Sorry, you don't have permission for editing connection parameters! Please login as administrator or contact an admin.</span></td></tr>"}
  24.  
  25. else
  26. $Test true}
  27. }
  28.  
  29. if($Test == "true" or (isset($_SESSION['admin']|| $_SESSION['admin'])) {
  30. ?>
  31.     <tr>
  32.         <td colspan="3" valign="top">
  33.         <table border="0 id="table2">
  34.     <?php
  35.     if($_POST['formSubmitSave']{
  36.     
  37. if($_POST['DBMS'== ""echo "<tr><td colspan='2'><span class='error'>Please select a DBMS!</span></td></tr>"
  38. $test true}
  39. if($_POST['host'== ""echo "<tr><td colspan='2'><span class='error'>Please enter the host of the database!</span></td></tr>";
  40. $test true}    
  41. if($_POST['database'== ""echo "<tr><td colspan='2'><span class='error'>Please select the database!</span></td></tr>"
  42. $test true}    
  43. if($_POST['user'== ""echo "<tr><td colspan='2'><span class='error'>Please enter the user!</span></td></tr>";
  44. $test true}    
  45.  
  46. if($test != true{
  47.  
  48.     /********************************************************************************************
  49.     * saving database connection parameters into an xml file (load/provider.xml)                *
  50.     * START                                                                                     *
  51.     *********************************************************************************************/
  52.     
  53. if(file_exists("load/provider.xml"))
  54. $file "load/provider.xml"else $file "../load/provider.xml"}
  55.  
  56. $newfile fopen($file,"w+");
  57.  
  58. rewind($newfile);
  59.  
  60.     $newxml '<?xml version="1.0" encoding="UTF-8"?>
  61.     <provider>
  62.     <dbms>'.$_REQUEST['DBMS'].'</dbms>
  63.     <host>'.$_REQUEST['host'].'</host>
  64.     <db>'.$_REQUEST['database'].'</db>
  65.     <user>'.$_REQUEST['user'].'</user>
  66.     <pw>'.$_REQUEST['password'].'</pw>
  67.     </provider>'
  68.  
  69. fwrite($newfile$newxml);
  70. fclose($newfile)}
  71.  
  72.  
  73.     }
  74.     /********************************************************************************************
  75.     * saving database connection parameters into an xml file (load/provider.xml)                *
  76.     * END                                                                                       *
  77.     *********************************************************************************************/
  78.     
  79.     if(file_exists("load/loaddnaprovider.php"))
  80.     
  81.     /**
  82.     * Start page, try to load exiting xml parser, just in case connection has been set up already, (load/loaddnaprovider.php -> load/provider.xml)
  83.     */
  84.     include ("load/loaddnaprovider.php")else 
  85.     /**
  86.     * Start page, alternative path for xml parser
  87.     */
  88.     include("../load/loaddnaprovider.php");
  89.     
  90.     echo "<tr><td id='DescriptionBlack'><b>Connection to database: </b></td><td>"
  91.     
  92.     if($DBMS == "mysql"{
  93.     $connID @mysql_connect($host$user$passwd);
  94.     if ($connID{    $connection mysql_select_db($dbname);  
  95.     if($connectionecho "<span class='fine'>OK</span>"}
  96.     if(!$connectionecho "<span class='error'>Not OK</span>"}}
  97.     
  98.     if(!$connIDecho "<span class='error'>Not OK</span>"} }
  99.     echo "</td></tr>";
  100.     ?>
  101.          <tr>
  102.                 <td id="DescriptionBlack">
  103.                 DBMS</td>
  104.                 <td>
  105.         <select name="DBMS" id="SelectLong">
  106.           <option selected value="mysql">mysql</option>
  107.         </select></td>
  108.         <td>Currently only MySQL can be used as database management system for DNA Module.</td>
  109.     </tr>
  110.     <tr>
  111.                 <td id="DescriptionBlack">
  112.                 Host</td>
  113.                 <td>
  114.         <input name="host" id="SelectLong" type="text" value="<?php echo $host?>"/></td>
  115.         <td>The host of the database.</td>
  116.     </tr>
  117.     <tr>
  118.                 <td id="DescriptionBlack">
  119.                 Database</td>
  120.                 <td>
  121.         <input name="database" id="SelectLong" type="text" value="<?php echo $dbname?>"/></td>
  122.         <td>The name of the database.</td>
  123.     </tr>
  124.     <tr>
  125.                 <td id="DescriptionBlack">
  126.                 User</td>
  127.                 <td>
  128.         <input name="user" id="SelectLong" type="text" value="<?php echo $user?>"/></td>
  129.         <td>User name.</td>
  130.     </tr>
  131.         <tr>
  132.                 <td id="DescriptionBlack">
  133.                 Password</td>
  134.                 <td>
  135.         <input name="password" id="SelectLong" type="password" value="<?php echo $passwd?>"/></td>
  136.         <td>Password, can be left empty if not assigned.</td>
  137.     </tr>
  138.       <tr>
  139.         <td id="DescriptionBlack"></td>
  140.         <td colspan="2">
  141.           <input type="submit" value="Save" name="formSubmitSave" id="SelectLong"></td>
  142.     </tr>
  143. </table></td></tr>
  144. <?php
  145.  // if($Test == "true" or (isset($_SESSION['admin']) || $_SESSION['admin']))
  146.  ?>

Documentation generated on Tue, 29 Nov 2011 10:44:50 +0100 by phpDocumentor 1.4.3