<?php

/*
 * info.php
 *
 * - without arguments: displays the change personal info form
 *
 * - with the "pb" argument set
 *
 *    - if it has the value of a field name, displays the registration form
 *       and ask the user for correction.
 *
 *    - if it has the value "duplication", explain the problem(ids of people
 *       already registred should be found in $ids).
 *
 *    - if it has the value "error", displays the $errorno and $errormsg and
 *       ask for registrating again.
 *
 *
 *
 *
 */

//add by Isa on 08.09.2009: keep login info
if (isset($_COOKIE['login'])) { $login = strip_tags($_COOKIE['login']); } else { $login = ""; }
if (isset($_COOKIE['password'])) { $password = strip_tags($_COOKIE['password']); } else { $password = ""; }

//add by Isa on 10.09.2009: get parameter of php script
if (isset($_GET['pb'])) {  $pb = strip_tags($_GET['pb']); } else { $pb = ""; }
if (isset($_GET['errorno'])) {  $errorno = strip_tags($_GET['errorno']); } else { $errorno = ""; }
if (isset($_GET['errormsg'])) {  $errormsg = strip_tags($_GET['errormsg']); } else { $errormsg = ""; }
if (isset($_GET['ids'])) {  $ids = strip_tags($_GET['ids']); } else { $ids = ""; }

require_once("../databases.php");
include("../sequencer.php");
require("../opendb.php");

require("checkpass.php");



if ("$pb" == "")
{
  $request_info = "SELECT first_name, last_name, affiliation, phone, fax, email
                   FROM people
	           WHERE id_people='$myid';";

  $result_info = mysql_query ($request_info, $db)
  or
  mysql_die("Query SELECT failed.");

  $first_name = mysql_result($result_info, 0, "first_name");
  $last_name = mysql_result($result_info, 0, "last_name");
  $affiliation = mysql_result($result_info, 0, "affiliation");
  $phone = mysql_result($result_info, 0, "phone");
  $fax = mysql_result($result_info, 0, "fax");
  $email = mysql_result($result_info, 0, "email");

  mysql_free_result($result_info);
}



//echo "pb='$pb'; empty='$empty'; first_name='$first_name'; last_name='$last_name'";

function printhappy()
{
 echo '<IMG SRC="../images/smiley1.gif" BORDER=0 ALT="happy smiley">';
}

function printsad()
{
 echo '<IMG SRC="../images/smiley2.gif" BORDER=0 ALT="sad smiley">';
}

function printquestion()
{
 echo '<IMG SRC="../images/smiley5.gif" BORDER=0 ALT="question smiley">';
}

// This function displays the status of the field given as $1
// If there is not problem (indicated by $pb), do nothing
// Otherwise, if the problem is the $field, displays ":-("

function displaystatus($field)
{
 global $pb, $pbdisplayed, $empty;

// echo "$field='${$field}'; pb='$pb'";

 if("$pb" != "")
 {
  echo "<TD ALIGN=CENTER>";

  if("$pb" == "$field")
  {
   $pbdisplayed = TRUE;
   printsad();
  }
  else
  {
   if ($pbdisplayed == FALSE)
    printhappy();
   else
    printquestion();
  }


  echo "</TD>";
 }
}


// This function displays a field
// $mandatory: [M|O]
// $pass: [Y|N]  $value is not used
// $option: option field (S: select), $values: the values
//

function displayfield($field, $legend, $value, $maxlength, $example, $mandatory,
                      $pass, $option, $values)
{
 global $pb, $pbdisplayed, $empty;

 echo "<TR>";

 echo "<TD>";

 if("$pb" == "$field")
  echo "<SPAN CLASS=RED><B>";
 elseif("$mandatory" == "M")
  echo "<SPAN CLASS=CUTEBLUE><B>";

 echo "$legend:";


 if("$pb" == "$field")
  echo "</B></SPAN>";
 elseif("$mandatory" == "M")
  echo "</B></SPAN>";

 echo "</TD>";

 echo "<TD>";

 if("$pass" == "Y")
  echo "<INPUT TYPE=PASSWORD SIZE=30 MAXLENGTH=$maxlength NAME=$field VALUE=\"\"></TD>";
 elseif("$option" == "S")
  echo "$values</TD>";
 else
  echo "<INPUT TYPE=TEXT SIZE=30 MAXLENGTH=$maxlength NAME=$field VALUE=\"$value\"></TD>";

 echo "<TD>&nbsp;&nbsp;<I>$example</I></TD>";

 displaystatus("$field");

 echo "</TR>\n";
}


// displays a field, but with hidden attribute

function displayhiddenfield($field, $value)
{
 echo "<INPUT TYPE=HIDDEN VALUE=\"$value\" NAME=\"$field\">";
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<LINK rel="stylesheet" type="text/css" href="../sequencerstyle.css">
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="Author" lang="fr" content="Pierre Berthier">
<META name="keywords" lang="en"    content="">
<META name="keywords" lang="fr"    content="">
<META http-equiv="Pragma" content="no-cache">
<META http-equiv="Cache-Control" content="no-cache">
<META http-equiv="Cache-Control" content="must-revalidate">
<META http-equiv="Content-Script-Type" content="text/javascript">

<TITLE>CMPG sequencer - Edit personal information for <?php echo "$login"; ?></TITLE>
</HEAD>

<BODY><A NAME="TOP"></A>

<TABLE BORDER=0 WIDTH="100%">
<TR>
<TD ALIGN=LEFT VALIGN=BOTTOM>
<A HREF="http://www.unibe.ch" TARGET=BLANK><IMG SRC="../images/unibern_logo.gif" BORDER=0></A>&nbsp;
<A HREF="http://cmpg.unibe.ch" TARGET=BLANK><IMG SRC="../images/new_banner_CMPG_Panorama_s3.jpg" BORDER=0></A>
</TD>
<TD ALIGN=RIGHT VALIGN=BOTTOM>
<H1 ALIGN=RIGHT CLASS=RED><A HREF="http://cmpg.unibe.ch/sequencer/">ABI 3100</A></H1>
</TD>
</TR>
</TABLE>



<HR NOSHADE SIZE=3>



<TABLE BORDER=0><TR><TD>





<H2>Edit personal information for <?php echo "$login"; ?></H2>


<?php
echo "<A HREF=\"$home\">Home</A> | <A HREF=\"login.php\">user page</A><P>" ;
?>

<TABLE WIDTH="50%" CELLSPACING=0 CELLPADDING=0 BORDER=0><TR><TD><HR SIZE=3 NOSHADE></TD></TR></TABLE>


<?php

if ("$pb" != "") { $pbdisplayed = FALSE; ?>

<H3>There was a problem in your submission (your changes have NOT been submitted)</H3>

<?php if ("$pb"=="duplication") { ?>

<B>The problem was that at least one person already registred using your Name and Affiliation.</B>

<P>Users that are already registred under <I><?php echo "$last_name, $first_name, $affiliation"; ?></I> are found under the ids #<?php echo "$ids"; ?>.

<P>I think it is quite unlikely that two persons of the same Name stay in the same Affiliation, and consequently that's not allowed in the database to avoid you to register many times just by error.

<P>Now you have several choices:

<DL>
<DT>1) You are actually submitting your registration a second time by error...

<DD>Stop your registration now and return to the <A HREF=<?php echo "\"$home\""; ?> >Home Page</A>.

<P>
<DT>2) You made an error in typing your informations and want to correct them...

<DD>Please review your submission in the form below and click on the &#8220;<B>Submit</B>&#8221; button.

<P>
<DT>3)There is really two different persons and you want to confirm your registration...

<DD>Well... please send an email here: <A HREF="<?php echo $webmaster; ?>"><?php echo $webmaster; ?></A>.

</DL>



<?php

} // end pb dupli

elseif ("$pb" == "error")
{
 echo "<P>The last operation has failed due to a database error: error #$errorno, <I>$errormsg</I>. Please retry.";
}
else { // other pb

echo "Please review your submission below and correct the field in <SPAN CLASS=RED><B>red</B></SPAN> (&#8220;<I>" . "$columns[$pb]" . "</I>&#8221;).";

if ("$empty" == "1")
echo "<BLOCKQUOTE><I>Note: the field was empty whereas it is <SPAN CLASS=CUTEBLUE><B>mandatory</B></SPAN> to fill it.</I></BLOCKQUOTE>";

else

echo "<BLOCKQUOTE><I>Note: the password is not the same between the two password fields. Please retry.</I></BLOCKQUOTE>";


} // end other pb

} // end pb

else {  // no problemo

?>





Please make your changes in the following form. <SPAN CLASS=CUTEBLUE><B>Mandatory fields</B></SPAN> are hereafter indicated in <SPAN CLASS=CUTEBLUE><B>blue</B></SPAN>. Other fields are optional, but could be useful to contact you in the future.

<P>
When done, submit your changes by clicking on the &#8220;<B>Submit</B>&#8221; button at the bottom of the form.

<P>Alternatively, click on the &#8220;<B>Reset</B>&#8221; button below the form to erase all the fields content.



<?php } // end no problemo
?>





<P>
<HR NOSHADE SIZE=3>




<FORM ACTION="<?php echo "changeinfo.php"; ?>" METHOD=POST>

<TABLE BGCOLOR=BLACK BORDER=0 CELLPADDING=2>

<TR><TD><TABLE BORDER=0 BGCOLOR=WHITE CELLPADDING=5 CELLSPACING=0>

<?php if("$pb" != "") { ?>
<TR><TD COLSPAN=4>
<B>Legend:</B><BR>
<?php printhappy() ?> the field value is valid<BR>
<?php printsad() ?> the field value is <SPAN CLASS=RED><B>invalid</B></SPAN><BR>
<?php printquestion() ?> I did not review the field value yet<BR>
</TD></TR>
<TR><TD COLSPAN=4>&nbsp;</TD></TR>
<?php } ?>


<TR>
<TH>Field</TH>
<TH>Value</TH>
<TH ALIGN=LEFT>Example</TH>
<?php if("$pb" != "") echo "<TH>Status</TH>";?>
</TR>

<?php

displayfield("first_name", "First Name", "$first_name", 80, "", "M", "N", "N", "");
displayfield("last_name",  "Last Name",  "$last_name",  80, "", "M", "N", "N", "");
displayfield("phone",  "Phone",  "$phone",  80, "", "O", "N", "N", "");
displayfield("fax",  "Fax",  "$fax",  80, "", "O", "N", "N", "");
displayfield("email",  "Email",  "$email",  80, "", "M", "N", "N", "");

?>
<TR><TD COLSPAN=<?php if("$pb"=="") echo 3; else echo 4; ?> ><I>You current password is not displayed for security reasons.<BR>Leave the fields below empty if you don't want to change your password.</I></TD></TR>

<?php
displayfield("new_password",  "Password",  "",  80, "", "M", "Y", "N", "");
displayfield("new_password2",  "Password (verify)",  "",  80, "", "M", "Y", "N", "");

?>

<TR><TD COLSPAN=<?php if("$pb"=="") echo 3; else echo 4; ?> >&nbsp;</TD></TR>

<TR><TD COLSPAN=<?php if("$pb"=="") echo 3; else echo 4; ?> >
<INPUT TYPE=SUBMIT VALUE="Submit">&nbsp;
<INPUT TYPE=RESET>
</TD></TR>

<?php if("$pb" != "") { ?>
<TR><TD COLSPAN=4>
<B>Legend:</B><BR>
<?php printhappy() ?> the field value is valid<BR>
<?php printsad() ?> the field value is <SPAN CLASS=RED><B>invalid</B></SPAN><BR>
<?php printquestion() ?> I did not review the field value yet<BR>
</TD></TR>
<?php } ?>

</TABLE>
</TD></TR></TABLE>
</FORM>



<P><I>Any problem?</I> Please contact the <A HREF="mailto:isabelle.duperret@iee.unibe.ch">Webmaster</A>.

<P><A HREF="#TOP"><img SRC="../images/up.gif" BORDER=0 height=11 width=14 ALT="Top of the page">Top of the page</A>

</TD></TR></TABLE>



<HR NOSHADE SIZE=3>

<TABLE WIDTH="100%">
<TR>
<TD WIDTH="50%" VALIGN=MIDDLE><A HREF="mailto:isabelle.duperret@iee.unibe.ch"><IMG SRC="../images/mail.gif" BORDER=0 WIDTH=30 ALIGN=TOP HSPACE=2 ALT="[Webmaster: isabelle.duperret@iee.unibe.ch]">Webmaster</A><BR><A HREF="../version.html">Version</A>: 2.0, 07.09.2009
</TD>
</TR>
</TABLE>

</BODY>
</HTML>


<?php mysql_close($db); ?>
