<?php
/* This file is part of Madcollector.
* Madcollector created by Thomas Andrieu,
* Developped by Mickael Jardet and Thomas Andrieu.
* Madcollector is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* Madcollector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
require_once LIBS.('classes/user.class.php');
if(($_SESSION['id_user'] == "")||(!isset($_SESSION['id_user'])))
header("Location:index.php");
$idUser = $_SESSION['id_user'];
$header_title = "Your account";
require_once DATA.('header.inc.php');
echo "<div id=\"account_user\"><h1>".$lc_Welcome.", ".$_SESSION['RegUser']."</h1></div>\n";
//Links
echo "<div id=\"user_collection\"><h2><a href=\"index.php?rub=mycollection\">".$lc_Collection."</a> <a href=\"index.php?rub=mycollecpdf\"><img src=\"images/pdf.gif\" alt=\"PDF\"/></a></h2></div>\n";
echo "<div id=\"user_searchlist\"><h2><a href=\"index.php?rub=mysearchlist\">".$lc_Searchlist."</a> <a href=\"index.php?rub=mysearchpdf\"><img src=\"images/pdf.gif\" alt=\"PDF\"/></a></h2></div>\n";
echo "<div id=\"user_selllist\"><h2><a href=\"index.php?rub=myselllist\">".$lc_Selllist."</a> <a href=\"index.php?rub=mysellpdf\"><img src=\"images/pdf.gif\" alt=\"PDF\"/></a></h2></div>\n";
//Form processing
$is_changepass = $_POST['changepass'];
$oldpasswd = $_POST['oldpassword'];
$passwd = $_POST['newpassword'];
$passwordconfirm = $_POST['passwordconfirm'];
if($is_changepass!="")
{
$isOk = true;
if(($oldpasswd=="")||(!isset($oldpasswd)))
{echo "<div id=\"errorpass1\">Please confirm old password.</div>";$isOk=false;}
if(($passwd=="")||($passwd==null))
{echo "<div id=\"errorpass2\">Please enter a new password.</div>";$isOk=false;}
if(($passwordconfirm=="")||(!isset($passwordconfirm)))
{echo "<div id=\"errorpass3\">Please confirm password.</div>";$isOk=false;}
if($passwordconfirm != $passwd)
{echo "<div class=\"errorpass4\">".$lc_ErrMsg_PwDiff.".</div>";$isOk=false;}
if($isOk)
{
$verif= "SELECT * FROM mc_users WHERE id_user='".$_SESSION['id_user']."' and password='".addslashes($oldpasswd)."'" ;
$resultat= $myDB->send_query($verify);
if(!$objLigne=$myDB->get_object($resultat))
echo "<div id=\errorpass5\">".$lc_ErrMsg_PwBad."</div>";
else
{
$update_pass = "UPDATE mc_users SET password='".addslashes($passwd)."' WHERE id_user='".$_SESSION['id_user']."'";
$resultat= $myDB->send_query($update_pass);
$nb_occur = $myDB->num_rows();
if(($nb_occur == -1)||($nb_occur == ""))
{
echo "<div class=\"message\">Error ".$myDB->return_error()." while updating password</div>";
}
else echo "<div class=\"message\">Password successfully updated</div>";
}
}
}
$is_changeaddress = $_POST['changeaddress'];
$newmail = $_POST['email'];
if($is_changeaddress!="")
{
$isOk = true;
if(($newmail=="")||(!isset($newmail)))
{echo "<div class=\"error5\">".$lc_ErrMsg_EmailNull.".</div>";$isOk=false;}
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
if (!eregi($regexp, $newmail))
{echo "<div class=\"error6\">".$lc_ErrMsg_EmailBad.".</div>";$isOk=false;}
if($isOk)
{
$update_email = "UPDATE mc_users SET email='".$newmail."' WHERE id_user='".$_SESSION['id_user']."'";
$resultat= $myDB->send_query($update_email);
$nb_occur = $myDB->num_rows();
if(($nb_occur == -1)||($nb_occur == ""))
echo "<div class=\"message\">Error ".$myDB->return_error()." while updating email</div>";
else echo "<div class=\"message\">Email successfully updated</div>";
}
}
$is_changeallow = $_POST['changeallow'];
$newallow = $_POST['allow'];
if($is_changeallow!="")
{
$update_allow = "UPDATE mc_users SET allow='".$newallow."' WHERE id_user='".$_SESSION['id_user']."'";
$resultat= $myDB->send_query($update_allow);
$nb_occur = $myDB->num_rows();
if(($nb_occur == -1)||($nb_occur == ""))
echo "<div class=\"message\">Error ".$myDB->return_error()." while updating</div>";
else echo "<div class=\"message\">Successfully updated</div>";
}
//------------- User data -------------
$requete_user = 'SELECT id_user,login,email,level,allow FROM mc_users WHERE id_user="'.$_SESSION['id_user'].'" ;';
$envoi_requete_user = $myDB->send_query($requete_user);
$nb_occur = $myDB->num_rows();
if(($nb_occur == 0)||($nb_occur == ""))
{
echo "<div id=\"error7\">ERREUR GRAVE : USER NON TROUVE</div>\n ";
}
$table_user = $myDB->get_array($envoi_requete_user,'NUMERIC');
$myUser = new User($table_user);
echo "<hr/>\n";
echo "<form method=\"POST\">\n";
echo "<h2>Change your password</h2>\n";
echo "<table><tr><td>Old password</td><td><input type=\"password\" name=\"oldpassword\"/></td></tr>\n";
echo " <tr><td>New password</td><td><input type=\"password\" name=\"newpassword\"/></td></tr>\n";
echo " <tr><td>Repeat password</td><td><input type=\"password\" name=\"passwordconfirm\"/></td></tr>\n";
echo " <tr><td></td><td><input type=\"submit\" name=\"changepass\" value=\"change\" class=\"submit\"/></td></tr>\n";
echo "</table></form>\n";
echo "<hr/>\n";
echo "<form method=\"POST\">\n";
echo "<h2>Change your address</h2>\n";
echo "<table> <tr><td>New address </td>\n";
echo " <td><input type=\"text\" name=\"email\" value=\"";
echo $myUser->email;
echo "\"/></td></td><td>$error[3]</td></tr>\n";
echo " <tr><td></td><td><input type=\"submit\" name=\"changeaddress\" value=\"change\" class=\"submit\"/></td></td><td></td></tr>\n";
echo "</table></form>\n";
echo "<hr/>\n";
echo "<form method=\"POST\">\n";
echo "<h2>Public profile</h2>\n";
$is_allowed = $myUser->allow;
echo "<table> <tr><td>Public profile *</td>\n";
echo " <td><input type=\"radio\" name=\"allow\" value=\"yes\"";
if($is_allowed=="yes") echo " checked=\"checked\"";
echo "/>yes <input type=\"radio\" name=\"allow\" value=\"no\"";
if($is_allowed=="no") echo " checked=\"checked\"";
echo "/>no </td></tr>\n";
echo " <tr><td></td><td><input type=\"submit\" name=\"changeallow\" value=\"change\" class=\"submit\"/></td></tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "* Allows people to see your collection, and allows members to contact you for information about issues.";
?>