<?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 = $lc_Menu_Account;
require_once DATA.('header.inc.php');
$error_messages = array();
//-------------------------------------
// PROCESS
//-------------------------------------
if(($_SESSION['id_user']!="")&&($_POST['account_submit']!=""))
{
$isOk = true;
$isPassUpdate = false;
if($_POST['newpassword']!="")
{
$isPassUpdate = true;
if(($_POST['oldpassword']=="")||(!isset($_POST['oldpassword'])))
{
array_push($error_messages,$lc_ErrMsg_Confirm_Old);
$isOk=false;
}
if(($_POST['passwordconfirm']=="")||(!isset($_POST['passwordconfirm'])))
{
array_push($error_messages,$lc_ErrMsg_Confirm_New);
$isOk=false;
}
if($_POST['passwordconfirm'] != $_POST['newpassword'])
{
array_push($error_messages,$lc_ErrMsg_PwDiff);
$isOk=false;
}
if($isOk)
{
$verify= "SELECT * FROM mc_users WHERE id_user='".$_SESSION['id_user']."' and password=MD5('".$_POST['oldpassword']."')" ;
$resultat= $myDB->send_query($verify);
if(!$objLigne=$myDB->get_object($resultat))
{
array_push($error_messages,$lc_ErrMsg_PwBad);
$isOk=false;
}
}
}
if(($_POST['email']=="")||(!isset($_POST['email'])))
{
array_push($error_messages,$lc_ErrMsg_EmailNull);
$isOk=false;
}
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
if (!eregi($regexp, $_POST['email']))
{
array_push($error_messages,$lc_ErrMsg_EmailBad);
$isOk=false;
}
if($isOk)
{
$update_user = "UPDATE mc_users SET email='".$_POST['email']."', allow='".$_POST['allow']."',public_mail='".$_POST['public_mail']."',signature='".$_POST['signature']."',language='".$_POST['language']."'";
if($isPassUpdate)
$update_user .= ",password=MD5('".addslashes($_POST['newpassword'])."')";
$update_user .= " WHERE id_user='".$_SESSION['id_user']."'";
$resultat= $myDB->send_query($update_user);
$nb_occur = $myDB->num_rows();
if(($nb_occur == -1)||($nb_occur == ""))
array_push($error_messages,$lc_ErrMsg_SQL_Update_User." : ".$myDB->return_error());
}
}
//------------- User data -------------
$requete_user = 'SELECT id_user,login,email,level,allow,language,public_mail,signature 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 == ""))
{
array_push($error_messages,$lc_ErrMsg_SQL_User_Not_Found);
}
$table_user = $myDB->get_array($envoi_requete_user,'NUMERIC');
$myUser = new User($table_user);
//-------------------------------------
// DISPLAY
//-------------------------------------
for($i=0;$i<sizeOf($error_messages);$i++)
{
echo "<div class=\"error\">".$error_messages[$i]."</div>";
}
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";
echo "<hr/>\n";
echo "<form method=\"POST\">\n";
echo "<h2>".$lc_UserPassWord."</h2>\n";
echo "<p>".$lc_UserOldPassWord." : <input type=\"password\" name=\"oldpassword\"/></p>\n";
echo "<p>".$lc_UserNewPassWord." : <input type=\"password\" name=\"newpassword\"/></p>\n";
echo "<p>".$lc_UserConfirmPassword." : <input type=\"password\" name=\"passwordconfirm\"/></p>\n";
echo "<br/>\n";
echo "<h2>".$lc_UserEmail."</h2>\n";
echo "<p>".$lc_UserEmail." : <input type=\"text\" name=\"email\" value=\"";
echo $myUser->email;
echo "\"/></p>\n";
echo "<br/>\n";
echo "<h2>".$lc_UserPublicProfile."</h2>\n";
$is_allowed = $myUser->allow;
echo "<p>".$lc_UserPublicProfile."* : <input type=\"radio\" name=\"allow\" value=\"yes\"";
if($is_allowed=="yes") echo " checked=\"checked\"";
echo "/>".$lc_Yes." <input type=\"radio\" name=\"allow\" value=\"no\"";
if($is_allowed=="no") echo " checked=\"checked\"";
echo "/>".$lc_No." </p>\n";
echo "<p>* ".$lc_Explain_Allow."</p>";
echo "<br/>\n";
echo "<h2>".$lc_UserEmailVisble."</h2>\n";
echo "<p>".$lc_UserEmailVisble." : <input type=\"radio\" name=\"public_mail\" value=\"1\"";
if($myUser->public_mail==1) echo " checked=\"checked\"";
echo "/>".$lc_Yes." <input type=\"radio\" name=\"public_mail\" value=\"0\"";
if($myUser->public_mail==0) echo " checked=\"checked\"";
echo "/>".$lc_No." </p>\n";
echo "<br/>\n";
echo "<h2>".$lc_Language."</h2>\n";
echo '<p><select name="language">';
if($fp = fopen("locales/lc.locales","r"))
{
while (!feof($fp))
{
$ligne = fgets($fp, 4096);
if (ereg ("^(.+):(.+)$", $ligne, $regs)) {
echo "<option value=\"".$regs[1]."\"";
if($regs[1]==$myUser->language) echo " selected=\"selected\"";
echo ">".$regs[2]."</option>";
}
}
fclose($fp);
}
echo '</select></p>';
echo "<br/>\n";
echo "<h2>".$lc_UserSignature."</h2>\n";
echo "<p><textarea name=\"signature\">".$myUser->signature."</textarea></p>\n";
echo "<p><input type=\"submit\" name=\"account_submit\" value=\"".$lc_Update."\" class=\"submit\"/></p>\n";
echo "</form>\n";
?>