<?php require('config.php3'); require('SRC/macros.php3'); 
list ($home,$url,$users,$assign,$msg,$host,$sql,$MYCookie,$applet,$os)=courseAll();

$f1 = is_integer(strpos(getenv("REMOTE_HOST"),".kth."));
$f2 = is_integer(strpos(getenv("REMOTE_HOST"),".chalmers."));
$free=$f1||$f2;

if ($file=="Select your software") unset($file);
if ($stud_email=="Set permissions below") unset($stud_email);

# ----------------------------------------------------- List of products
function products($free){
  $item1=101; $price1="29.00"; $lbl1="spm";  $name1="PLA/SPM Single Particle Motion";
  $item2=102; $price2="29.00"; $lbl2="dsprl";$name2="PLA/DSPRL Dispersion relation"; 
  $item3=103; $price3="29.00"; $lbl3="pic";  $name3="PLA/PIC Particle in cell simulation";
  $total=3;
  if ($free) { $price1="0.00";  $price2="0.00";  $price3="0.00"; }
  $items =array($item1 ,$item2 ,$item3);
  $prices=array($price1,$price2,$price3);
  $names =array($name1 ,$name2 ,$name3);
  $lbls =array($lbl1 ,$lbl2 ,$lbl3);
  return array($total,$items,$prices,$names,$lbls);
} // products

# ----------------------------------------------------- Advetize products
function makeanoffer($db,$user_nbr,$url,$free){
  list ($total,$items,$prices,$names,$lbls)=products($free);
  $select="<form action=download.php3 method=post>\n &nbsp;".
          "<SELECT NAME=file>\n".
          " <OPTION SELECTED>Select your software\n";
  if ($user_nbr!=0) {                           # Free access for service>=2
    $cmd="SELECT admin_service FROM users WHERE user_nbr=".$user_nbr.";";
    $r=SQLquery($db,$cmd); $admin_service=SQLresult($r,0,'admin_service');
  } else {
    $admin_service=0;
  }
  echo "<p><center><table>\n";
  for ($i=0; $i<$total; $i++) {
   if ($user_nbr!=0) {                          # Create download selector
     $cmd="SELECT count FROM download ".
           "WHERE user_nbr=".$user_nbr." AND item=".$items[$i].";";
     $r=SQLquery($db,$cmd);
     if(SQLnumrows($r)!=0 || $admin_service>=2)
        $select=$select." <OPTION>$items[$i] $names[$i] (UNIX tar.gz)\n".
                        " <OPTION>$items[$i] $names[$i] (WIN zip)\n".
                        " <OPTION>$items[$i] $names[$i] (ASCII)\n";
    }
   echo "<tr>";                                 # List products and price
   if (!$free) echo "
     <form action=\"https://www.paypal.com/cgi-bin/webscr\" method=post>
      <input type=hidden name=cmd value=_xclick>
      <input type=hidden name=business      value=andre.jaun@google.com>
      <input type=hidden name=item_name     value=\"".$names[$i] ."\">
      <input type=hidden name=item_number   value=".  $items[$i] .">
      <input type=hidden name=amount        value=". $prices[$i].">
      <input type=hidden name=currency_code value=USD>
      <input type=hidden name=no_shipping   value=1>
      <input type=hidden name=rm            value=2>
      <input type=hidden name=image_url     
                         value=\"".$url."images/LogoLLLpaypal.png\">
      <input type=hidden name=return        
                         value=\"".$url."src/download.php3?register=t&paid=".
                                                    (140300*$prices[$i])."\">
      <input type=hidden name=cancel_return
                         value=\"".$url."src/download.php3\">";
   echo "
     <td><li><a href=\"../src/".$lbls[$i].".php3\">".$names[$i]."</a></td>";
   if (!$free) echo "
     <td>Price: &nbsp; USD ".$prices[$i]."</td>
     <td><input type=image border=0 name=submit alt=PayPal align=middle 
             src=\"../images/paypal.png\"></td>
    </form>\n";
   echo "</tr>\n";
  }
  if (!$free) echo "<tr>
   <form action=https://www.paypal.com/cgi-bin/webscr method=post>
    <td>Combination from above:</td>
    <td>Price:&nbsp;USD &nbsp; 
     <input type=text size=6 name=amount value=\"48.00\"></td>
     <input type=hidden name=cmd value=_xclick>
     <input type=hidden name=business      value=andre.jaun@google.com>
     <input type=hidden name=item_name     value=\"Open payment\">
     <input type=hidden name=item_number   value=0>
     <input type=hidden name=currency_code value=USD>
     <input type=hidden name=no_shipping   value=1>
     <input type=hidden name=rm            value=2>
     <input type=hidden name=image_url     
                        value=\"".$url."images/LogoLLLpaypal.png\">
     <input type=hidden name=return        
                        value=\"".$url."src/download.php3?u=$user_nbr\">
     <input type=hidden name=cancel_return 
                        value=\"".$url."src/download.php3\">
    <td><input type=image border=0 name=submit alt=PayPal align=middle 
           src=\"../images/paypal.png\"></td>
    </tr></form>\n";
  echo "</table></center><br clear=both><p>";
  $select=$select."</SELECT>\n &nbsp;&nbsp;".
    "<input type=submit value=download>\n"."</form>\n";
  return $select;
} //makeanoffer

$db = SQLconnect($host, $sql);

# ----------------------------------------------------- Access permit
if ($user_email != "" && $user_passwd != ""){
  $cmd = "SELECT user_nbr,admin_service FROM users WHERE ".
         "(user_email='" .filter_1quote($user_email)."' AND ".
         " user_passwd='".filter_1quote($user_passwd)."');";
  $r=SQLquery($db,$cmd); 
  if(SQLnumrows($r)==1){
    $user_nbr=SQLresult($r,0,'user_nbr');
    $admin_service=SQLresult($r,0,'admin_service');
    $CEMCookie = $user_nbr*1071911;
    setcookie("CEMCookie", $CEMCookie, time()+10*60);
    $cmd="SELECT tch_auth from teachers WHERE user_nbr='".$user_nbr."';";
    $r=SQLquery($db,$cmd);
    if(SQLnumrows($r)==1) {                     # administrator access
      $tch_auth=SQLresult($r,0,'tch_auth');
    } else {
      $tch_auth=0;
    }
  } else {
    myheader('Download: login failed','..',0);
    echo "Sorry, your e-mail / password pairs do not match those of any 
    registered user. Please try again.";
    $user_nbr=99; $admin_service=0; $tch_auth=0;
    thisFooter(); exit;
  }

} else if (isset($CEMCookie)) {
  $user_nbr = $CEMCookie / 1071911;
  $cmd="SELECT tch_auth from teachers WHERE user_nbr='".$user_nbr."';";
  $r=SQLquery($db,$cmd);
  if(SQLnumrows($r)==1) {                       # administrator access
    $tch_auth=SQLresult($r,0,'tch_auth');
  } else {
    $tch_auth=0;
  }
}

# ----------------------------------------------------- Download
if (isset($CEMCookie) && isset($file)) {
 $item=substr($file,0,3);
 $file=substr($file,4,strlen($file)-3);
 $cmd="SELECT count FROM download WHERE user_nbr=$user_nbr AND item=$item;";
 $r=SQLquery($db,$cmd);
 if(SQLnumrows($r) != 0){
   $count=SQLresult($r,0,'count');
   $cmd="UPDATE download SET count='".($count+1)."', last='today', ".
        "type='$file' WHERE user_nbr=$user_nbr AND item=$item;";
 } else {                                         # Assume that permission ok
   $cmd="INSERT INTO download (user_nbr,item,type,last) ".
               "VALUES ($user_nbr,$item,'".$file."','now');";
 }
 SQLquery($db,$cmd);

 if ($file=='PLA/SPM Single Particle Motion (UNIX tar.gz)') {
  header("Content-type: application/x-gzip");
  header("Content-Disposition: attachment; filename=spm.tar.gz");
  header("Content-Description: Matlab source code (UNIX tar.gz)");
  $cmd="cat ../downld/spm.tar.gz";
  passthru($cmd);
 } else if ($file=='PLA/SPM Single Particle Motion (WIN zip)') {
  header("Content-type: application/zip");
  header("Content-Disposition: attachment; filename=spm.zip");
  header("Content-Description: Matlab source code (WIN zip)");
  $cmd="cat ../downld/spm.zip";
  passthru($cmd);
 } else if ($file=='PLA/SPM Single Particle Motion (ASCII)') {
  header("Content-type: text/plain");
  header("Content-Disposition: attachment; filename=spm.m");
  header("Content-Description: Matlab source code (ASCII)");
  $cmd="cat ../downld/spm/spm.m ../downld/spm/eqMotion.m ../downld/spm/data.m";
  passthru($cmd);
 } else if ($file=='PLA/DSPRL Dispersion relation (UNIX tar.gz)') {
  header("Content-type: application/x-gzip");
  header("Content-Disposition: attachment; filename=dsprl.tar.gz");
  header("Content-Description: Matlab source code (UNIX tar.gz)");
  $cmd="cat ../downld/dsprl.tar.gz";
  passthru($cmd);
 } else if ($file=='PLA/DSPRL Dispersion relation (WIN zip)') {
  header("Content-type: application/zip");
  header("Content-Disposition: attachment; filename=dsprl.zip");
  header("Content-Description: Matlab source code (WIN zip)");
  $cmd="cat ../downld/dsprl.zip";
  passthru($cmd);
 } else if ($file=='PLA/DSPRL Dispersion relation (ASCII)') {
  header("Content-type: text/plain");
  header("Content-Disposition: attachment; filename=dsprl.m");
  header("Content-Description: Matlab source code (ASCII)");
  $cmd="cat ../downld/dsprl/dsprl.m";
  passthru($cmd);
 } else if ($file=='PLA/PIC Particle in cell simulation (UNIX tar.gz)') {
  header("Content-type: application/x-gzip");
  header("Content-Disposition: attachment; filename=pic.tar.gz");
  header("Content-Description: Matlab source code (UNIX tar.gz)");
  $cmd="cat ../downld/pic.tar.gz";
  passthru($cmd);
 } else if ($file=='PLA/PIC Particle in cell simulation (WIN zip)') {
  header("Content-type: application/zip");
  header("Content-Disposition: attachment; filename=pic.zip");
  header("Content-Description: Matlab source code (WIN zip)");
  $cmd="cat ../downld/pic.zip";
  passthru($cmd);
 } else if ($file=='PLA/PIC Particle in cell simulation (ASCII)') {
  header("Content-type: text/plain");
  header("Content-Disposition: attachment; filename=pic.m");
  header("Content-Description: Matlab source code (ASCII)");
  $cmd="cat ../downld/pic/pic.m";
  passthru($cmd);
 }
 exit();
}

# ----------------------------------------------------- Select software
if (!isset($register) && !isset($login)) {
  myheader('Download: select','..',0);
  echo "Here is the list of software ready for download.";
  if (!$free && $user_nbr<100) {
    echo " To proceed, you need to accept the general <a href=\"license.php3\">
      conditions</a> that govern the usage of this educational website.
      You may then proceed with your credit-card payment using the secured
      <a href=\"http://www.paypal.com\">PayPal</a> method simply by pressing
      one of the buttons below. A password will be sent to you by e-mail after
      registration to complete the download. ";
  }
  if (!$free && $admin_service>=2) {
    echo " To avoid any delay, the selector automatically gives you access 
      to the entire library. In return, we hope that you will spontaneously 
      pay any additional software you choose to download without obliging 
      us to send you an invoice manually.";
  }
  echo " Students from the Royal Institute of Technology and Chalmers can 
    download the software free of charge after registration provided that 
    their computer is located within the school intranet.";
  $selectSoftware=makeanoffer($db,$user_nbr,$url,$free);
  if ($user_nbr>99) echo $selectSoftware;
  if (!$free) {
    echo "
      Please contact <a href=\"mailto:jaun@kth.se.remove-this-field\">
      Andr&eacute; Jaun</a> if you experience any difficulty.";
  } else {
    $register=f;
  }
}

# ----------------------------------------------------- Admin
if ($tch_auth>=4) {
  list ($total,$items,$prices,$names,$lbls)=products(0);
  $auth="<p><hr><h2>Administrator: edit permissions</h2>".
        "By default, Paypal users get access to the entire catalogue: this ".
        "right is destroyed as soon as you submit the permissions below.".
        "<form action=download.php3 method=post>\n".
        "<SELECT NAME=stud_email>\n";
  if (isset($stud_email)){                      # Update permissions
    $cmd="SELECT user_nbr from users WHERE user_email='".$stud_email."';";
    $r=SQLquery($db,$cmd); $stud_nbr=SQLresult($r,0,'user_nbr');
    if (isset($stud_store) && !strstr($stud_email,'permission')) {
      for ($i=0;$i<$total;$i++){
        $cmd="SELECT count FROM download ".
             "WHERE user_nbr=".$stud_nbr." AND item=".$items[$i].";";
        $r=SQLquery($db,$cmd);
        if (isset($$lbls[$i]) && SQLnumrows($r)==0) {
          $cmd="INSERT INTO download (user_nbr,item,type,last,count) ".
               "VALUES ($stud_nbr,$items[$i],'".$names[$i]."','now',0);";
          $r=SQLquery($db,$cmd);
        } else if (!isset($$lbls[$i]) && SQLnumrows($r)>0) {
          $cmd="DELETE FROM download ".
               "WHERE user_nbr=".$stud_nbr." AND item=".$items[$i].";";
          $r=SQLquery($db,$cmd);
        } 
      }
                                                # Remove automatic priviledge
      $cmd="UPDATE users SET admin_service=1 WHERE user_nbr=$stud_nbr;";
      $r=SQLquery($db,$cmd);
    } // Update permissions
    $auth=$auth." <OPTION SELECTED>".$stud_email."\n";
  } else {
    $stud_nbr=0;
    $auth=$auth." <OPTION SELECTED>Set permissions below\n";
  }
						# Student selector
  $cmd="SELECT user_email,user_passwd FROM users ORDER BY admin_lastlog DESC LIMIT 30;";
  $r=SQLquery($db,$cmd);
  for ($row=0; $row < SQLnumrows($r); $row++) {
    $thisUser = SQLobject($r, $row);
    $auth=$auth."<OPTION value=\"$thisUser->user_email\">$thisUser->user_email &nbsp; $thisUser->user_passwd\n";
  }
  $auth=$auth."</SELECT>\n".
     "<input type=submit value=update>\n".
     "<input type=checkbox name=stud_store value=yes> store<br>";
  for ($i=0; $i<$total; $i++) {			# Show/edit permissions
    $auth=$auth."<input type=checkbox name=".$lbls[$i];
    $cmd="SELECT count,last FROM download ".
         "WHERE user_nbr=".$stud_nbr." AND item=".$items[$i].";";
    $r=SQLquery($db,$cmd);
    if(SQLnumrows($r)==1) { 
      $thisDwnld=SQLobject($r,0);
      $auth=$auth." checked ";
      $count = "$thisDwnld->count / $thisDwnld->last";
    } else {
      $count=0;
    }
    $auth=$auth." value=yes>&nbsp;".$names[$i]." ($count)<br>\n";
  }
  $auth=$auth."</form>\n";
  SQLclose($db);
  echo $auth;
  thisFooter(); exit;
} // Admin

# ----------------------------------------------------- Login form
if (isset($login)) { 
 myheader('Download: login','..',0);  ?>
 <form action="download.php3" method=post>
  <table>
   <tr><td>User ID <br>(email):</td>
       <td><input type=text size=60 name=user_email value="<?php echo $user_email;?>"></td></tr>
   <tr><td>Password:</td>
       <td><input type=password size=60 name=user_passwd></td></tr>
   <tr><td>&nbsp;</td>
       <td><a href="download.php3?register=t">Register</a> as a new downloader, 
           or ask for an e-mail <a href=remind.php3>reminder</a>.</td></tr>
  </table>
  <p><input type="submit" value="Enter">
 </form>
  <br><b>Note:</b>An encrypted <i>cookie</i> will be submitted to your browser.
 <?php
} // login

if (isset($register)) {
 if ($register=='t')
   myheader('Download: registration','..',0);
# ----------------------------------------------------- Registration fill-in
 if (!isset($process) || $user_name=="" || 
     $user_email=="" || $agree=="") {
  ?>
  To download the software, you need first to register and accept the general
  <a href="license.php3">conditions</a> that governs usage of the educational
  website. A password will immediately be sent to you by e-mail, allowing you 
  to identify yourself and complete the download.
  <form action="download.php3" method=post>
   <input type=hidden name=register value=yes>
   <input type=hidden name=process value=1>
   <?php if (isset($paid)) echo "<input type=hidden name=paid value=$paid>"; ?>
   <table>
     <?php if(count($process)==1 && $user_name == "")
            echo "<tr><td></td><td><blink>You must supply your full name!</blink></td></tr>\n"; ?>
   <tr><td>Your (title and) full name<sup>1</sup>:</td>
       <td><input type=text size=60 name=user_name value="<?php echo $user_name;?>"></td></tr>
    <?php if(count($process) == 1 && $user_email == "")
            echo "<tr><td></td><td><blink>You must supply your email!</blink></td></tr>\n"; ?>
   <tr><td>Your email<sup>1</sup>:</td>
       <td><input type=text size=60 name=user_email value="<?php echo $user_email;?>"></td></tr>
   <tr><td>Your ID / passport number<sup>2</sup>:</td>
       <td><input type=text size=60 name=user_pers_nbr value="<?php echo $user_pers_nbr;?>"></td></tr>
   <tr><td>Your URL:</td>
       <td><input type=text size=60 name=user_url value="<?php echo $user_url;?>"></td></tr>
   <tr><td>Your company/school<sup>2</sup>:</td>
       <td><input type=text size=60 name=user_school value="<?php echo $user_school;?>"></td></tr>
   <tr><td>Your dept./section<sup>2</sup>:</td>
       <td><input type=text size=60 name=user_dept value="<?php echo $user_dept;?>"></td></tr>
   <tr><td>Supervisor title + full name<sup>2</sup>:</td>
       <td><input type=text size=60 name=super_name value="<?php echo $super_name;?>"></td></tr>
   <tr><td>Supervisor email<sup>2</sup>:</td>
       <td><input type=text size=60 name=super_email value="<?php echo $super_email;?>"></td></tr>
   <tr><td>How did you spot this material?</td>
       <td><input type=text size=60 name=course_find value="<?php echo $course_find;?>"></td></tr>
   <tr><td>Comments:</td>
       <td><textarea rows=3 cols=60 wrap=hard name=course_expect><?php echo $course_expect; ?></textarea>
   <tr><td>Invoice / payment details:</td>
       <td><textarea rows=3 cols=60 wrap=hard name=admin_invoice><?php echo $admin_invoice; ?></textarea>
     <?php if(count($process) == 1 && $agree == "")
             echo "<tr><td></td><td><blink>You must agree with the conditions!</blink></td></tr>\n"; ?>
   <tr><td>I agree with the <a href="license.php3">conditions</a><sup>1</sup></td>
       <td><input type=checkbox name=agree <?php if($agree=="yes") echo "checked"; ?> value=yes></td></tr>
   <tr><td>Do you want us to inform your<br>supervisor about your registration<sup>2</sup>?</td>
       <td><input type=checkbox name=super_inform <?php if($super_inform=="t") echo "checked"; ?> value=t></td></tr>
   <tr><td>We may publish your registration as<br>
           a <a href=users.php3>downloader of this material</a><br> 
           (your email will not be exposed)</td>
       <td><input type=checkbox name=user_publish <?php if($user_publish=="t") echo "checked"; ?> value=t></td></tr>
   </table>
   <p><input type="submit" value="Register">
  </form>
  <p><sup>1</sup>are required fields<br>
     <sup>2</sup>are optional
  <?php 
	
# ----------------------------------------------------- Registration new user
 } else {
  if ($free) {
    $admin_service=2; $admin_payed='free';      # Free for KTH/CTH
    $admin_price='free for KTH/CTH';
  } else if (isset($paid)) {
    $admin_service=2; $admin_payed=$paid/140300;# Paying users
    $admin_price='PayPal';
  } else {
    $admin_service=1; $admin_payed='no';        # Paying users
    $admin_price='PayPal';
  }
  $user_class=0;                                # No classroom
  if($super_inform=="")  $super_inform="f";
  if($user_publish =="") $user_publish="f";
  if($user_announce=="") $user_announce="f";
						# Verify if already exists
  $cmd = "SELECT user_email FROM users ".
         "WHERE user_email='".filter_1quote($user_email)."';";
  $r=SQLquery($db,$cmd);
  if(SQLnumrows($r)!=0){
    echo "Sorry, the account ".$user_email." has already been registred!
      If you don't remember your password, follow <a href=remind.php3>
      this link</a> to obtain a copy by email within a minute. ";
      thisFooter(); SQLclose($db); exit;
  } else {
    srand((double)microtime()*1000000);		# Generate a new $passwd
    $randval=rand(); $user_passwd="";
    for($i = 0; $i<5; $i++)
      $user_passwd = $user_passwd . chr(rand(97,122));

    $user_grp="www".date("y")."-";		# User directory + web
    if(substr($user_url,0,7) != "http://" && $user_url != "")
      $user_url = "http://".str_replace("'", " ", $user_url);

						# Generate new db entry
    $cmd = "INSERT INTO users (" .
      " user_class" .       ",user_grp" .        ",user_require" .
      ",user_name" .        ",user_passwd" .     ",user_pers_nbr" .
      ",user_email" .       ",user_url" .        ",user_school" .
      ",user_dept" .        ",user_publish" .    ",user_announce" .
      ",super_name" .       ",super_email" .     ",super_inform" .
      ",course_find" .      ",course_expect" .   ",admin_invoice" .
      ",admin_price" .      ",admin_payed" .     ",admin_service" .
      ",admin_created" .
      ") values (" .
      " '".$user_class."'" .
      ",'".$user_grp."'" .
      ",'170'" .
      ",'".filter_1quote($user_name)."'".
      ",'".filter_1quote($user_passwd)."'".
      ",'".filter_1quote($user_pers_nbr)."'".
      ",'".filter_1quote($user_email)."'".
      ",'".filter_1quote($user_url)."'".
      ",'".filter_1quote($user_school)."'".
      ",'".filter_1quote($user_dept)."'".
      ",'".$user_publish."'" .
      ",'".filter_1quote($user_announce)."'".
      ",'".filter_1quote($super_name)."'".
      ",'".filter_1quote($super_email)."'".
      ",'".filter_1quote($super_inform)."'".
      ",'".filter_1quote($course_find)."'".
      ",'".filter_1quote($course_expect)."'".
      ",'".filter_1quote($admin_invoice)."' ".
      ",'".$admin_price."'".
      ",'".$admin_payed."'".
      ",'".$admin_service."'".
      ",'today'".
      ");";
    $r=SQLquery($db,$cmd);

					# Mail the new password
    $mail = "Dear ".$user_name.",\n".
      "Thank you for registering as a downloader of course material\n".
      "    Introduction to Plasma Physics with Applications\n".
      "    http://www.lifelong-learners.com/pla\n".
      "which you should bookmark in your browser. You may now login\n".
      "using your email and the password ".$user_passwd."\n".
      "which cannot be modified and should remain secret.\n".
      "Your Webmaster";
    mail($user_email, "Password", $mail,
      "From: webmaster@$SERVER_NAME\n" .
      "Reply-To: jaun@kth.se\n" . 
      "X-Mailer: PHP/" . phpversion());

    if($super_inform=="t") {
      $mail = "Dear ".$super_name."\n".
      "I have the pleasure to inform you that ".$user_name."\n".
      "has registered as a downloader of course material under\n".
      "    Introduction to Plasma Physics with Applications\n".
      "    http://www.lifelong-learners.com/pla\n".
      "The educational material consist of a number of Matlab scripts\n".
      "that illustrate a number of phenomena using numerical simulations.\n".
      "Please don't hesitate to contact me if you have any question.\n".
      "Thanking you very much for your time, I look forward to following\n".
      $user_name."'s rapid progress!\n\n".
      "Sincerely yours,\n".
      "Andre Jaun\n".
      "Associate Professor at the Royal Institute of Technology in Stockholm";
      mail($super_email, $user_name."'s registration", $mail,
       "From: webmaster@$SERVER_NAME\n" .
       "Reply-To: jaun@kth.se\n" . 
       "X-Mailer: PHP/" . phpversion());
     mail("jaun@kth.se", "PLA new downloader", $cmd,
      "From: webmaster@$SERVER_NAME\n" .
      "Reply-To: jaun@kth.se\n" .
      "X-Mailer: PHP/" . phpversion());
    }
    echo "
      Thank you for registering on this Website; a password has been sent to 
      you by electronic mail. Using your e-mail/password pair, you may now 
      login and download the requested software.";
     if (!$free && !isset($paid)) echo "
      Please allow for a couple of days to process your order and
      contact <a href=mailto:jaun@kth.se>jaun@kth.se</a> if you 
      encounter any difficulty.";
    }
 } // register new user
}// registration

SQLclose($db);
thisFooter();
?>
