<?php
/* This file is part of Madcollector.
* Madcollector created by Thomas Andrieu,
* Developped by 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
* 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 = $locales["Menu_Account"];
if(($_GET['format']=="")||(!isset($_GET['format'])))
require_once THEME.('header.inc.php');
if($_GET['format']=="xml")
{
header("Content-Type: application/xml");
echo '<?xml version="1.0" ?><usersettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="'.LIBS.'schema/usersettings.xsd">';
}
//-------------------------------------
// PROCESS
//-------------------------------------
if((isset($_SESSION['id_user']))&&(isset($_POST['account_submit'])))
{
$isOk = true;
$isPassUpdate = false;
if($_POST['newpassword']!="")
{
$isPassUpdate = true;
if(($_POST['oldpassword']=="")||(!isset($_POST['oldpassword'])))
{
array_push($error_messages,$locales["ErrMsg_Confirm_Old"]);
$isOk=false;
}
if(($_POST['passwordconfirm']=="")||(!isset($_POST['passwordconfirm'])))
{
array_push($error_messages,$locales["ErrMsg_Confirm_New"]);
$isOk=false;
}
if($_POST['passwordconfirm'] != $_POST['newpassword'])
{
array_push($error_messages,$locales["ErrMsg_PwDiff"]);
$isOk=false;
}
if($isOk)
{
$verify_old_pwd= "SELECT * FROM ".$cfg_table_prefix."users WHERE id_user='".$_SESSION['id_user']."' and password=MD5('".$_POST['oldpassword']."')" ;
$result_verify_old_pwd= mysql_query($verify_old_pwd,$DB_connexion);
if(!$objLigne=mysql_fetch_object($result_verify_old_pwd))
{
array_push($error_messages,$locales["ErrMsg_PwBad"]);
$isOk=false;
}
mysql_free_result($result_verify_old_pwd);
}
}
if(($_POST['email']=="")||(!isset($_POST['email'])))
{
array_push($error_messages,$locales["ErrMsg_EmailNull"]);
$isOk=false;
}
$regexp = "/^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/";
if (!preg_match($regexp, $_POST['email']))
{
array_push($error_messages,$locales["ErrMsg_EmailBad"]);
$isOk=false;
}
if($isOk)
{
$posted_accountsettings_names_array = $_POST["posted_accountsettings_names"];
for($i=0;$i<sizeOf($posted_accountsettings_names_array);$i++)
{
if($i>0) $update_user .= ", ";
else $update_user = "UPDATE ".$cfg_table_prefix."users SET ";
$update_user .= $posted_accountsettings_names_array[$i]."='".$_POST[$posted_accountsettings_names_array[$i]]."'";
}
if($isPassUpdate)
$update_user .= ",password=MD5('".addslashes($_POST['newpassword'])."')";
$update_user .= " WHERE id_user='".$_SESSION['id_user']."'";
$resultat_update_user= mysql_query($update_user,$DB_connexion);
if(!$resultat_update_user)
array_push($error_messages,$locales["ErrMsg_SQL_Update_User"]." : ".mysql_error($DB_connexion));
}
}
//------------- User data -------------
$requete_user = 'SELECT * FROM '.$cfg_table_prefix.'users WHERE id_user="'.$_SESSION['id_user'].'" ;';
$envoi_requete_user = mysql_query($requete_user,$DB_connexion);
if(!$envoi_requete_user)
{
array_push($error_messages,$locales["ErrMsg_SQL_User_Not_Found"]);
}
$table_user = mysql_fetch_array($envoi_requete_user, MYSQL_BOTH);
$myUser = new User($table_user);
mysql_free_result($envoi_requete_user);
//-------------------------------------
// DISPLAY
//-------------------------------------
for($i=0;$i<sizeOf($error_messages);$i++)
{
echo "<div class=\"error\">".$error_messages[$i]."</div>\n";
}
if(($_GET['format']=="")||(!isset($_GET['format']))) {
echo "<div class=\"ul-navig\"><ul>\n";
echo "<li class=\"selected\">".$locales["Menu_Account"]."</li>";
//Links
echo "<li><a href=\"index.php?rub=mycollection&action=collected\">".$locales["Collection"]."</a></li>";
echo "<li><a href=\"index.php?rub=mycollection&action=searched\">".$locales["Searchlist"]."</a></li>";
echo "<li><a href=\"index.php?rub=mycollection&action=forsale\">".$locales["Selllist"]."</a></li>";
echo "<li><a href=\"index.php?rub=profile&id_user=".$_SESSION['id_user']."\">".$locales["Profile"]."</a></li>";
echo "</ul></div>\n";
echo "<br/>\n\n";
echo "<form method=\"post\">\n";
echo "<h2>".$locales["UserPassWord"]."</h2>\n";
echo '<p id="old_password">'.$locales["UserOldPassWord"]." : <input type=\"password\" name=\"oldpassword\"/></p>\n";
echo '<p id="new_password">'.$locales["UserNewPassWord"]." : <input type=\"password\" name=\"newpassword\"/></p>\n";
echo '<p id="confirm_new_password">'.$locales["UserConfirmPassword"]." : <input type=\"password\" name=\"passwordconfirm\"/></p>\n";
echo "<br/>\n\n";
}
if(($_GET['format']=="")||(!isset($_GET['format']))) {
echo "<h2>".$locales["UserEmail"]."</h2>\n";
echo '<p id="user_mail">'.$locales["UserEmail"]." : <input type=\"text\" name=\"email\" value=\"";
echo $myUser->email;
echo '"/><input type="hidden" name="posted_accountsettings_names[]" value="email"/></p>'."\n" ;
echo "<br/>\n\n";
}
if($_GET['format']=="xml"){
echo "<email>".$myUser->email."</email>";
}
if(($_GET['format']=="")||(!isset($_GET['format']))) {
echo "<h2>".$locales["UserPublicProfile"]."</h2>\n";
echo '<p id="user_public_profile">'.$locales["UserPublicProfile"]."* : <input type=\"radio\" name=\"public_profile\" value=\"Y\"";
if($myUser->public_profile=="Y") echo " checked=\"checked\"";
echo "/>".$locales["Yes"]." <input type=\"radio\" name=\"public_profile\" value=\"N\"";
if($myUser->public_profile=="N") echo " checked=\"checked\"";
echo "/>".$locales["No"].' </p><input type="hidden" name="posted_accountsettings_names[]" value="public_profile"/>';
echo "<p>* ".$locales["Explain_Public_Profile"]."</p>";
echo "<br/>\n";
}
if($_GET['format']=="xml"){
echo '<public_profile value="'.$myUser->public_profile.'"/>';
}
if(($_GET['format']=="")||(!isset($_GET['format']))) {
echo "<h2>".$locales["Allow_PM"]."</h2>\n";
echo '<p id="user_allow_PM">'.$locales["Allow_PM"]." : <input type=\"radio\" name=\"allow_PM\" value=\"Y\"";
if($myUser->allow_PM=="Y") echo " checked=\"checked\"";
echo "/>".$locales["Yes"]." <input type=\"radio\" name=\"allow_PM\" value=\"N\"";
if($myUser->allow_PM=="N") echo " checked=\"checked\"";
echo "/>".$locales["No"].' </p><input type="hidden" name="posted_accountsettings_names[]" value="allow_PM"/>';
echo "<br/>\n\n";
}
if($_GET['format']=="xml"){
echo '<allow_PM value="'.$myUser->allow_PM.'"/>';
}
if(($_GET['format']=="")||(!isset($_GET['format']))) {
echo "<h2>".$locales["Allow_ML"]."</h2>\n";
echo '<p id="user_allow_ML">'.$locales["Allow_ML"]." : <input type=\"radio\" name=\"allow_ML\" value=\"Y\"";
if($myUser->allow_ML=="Y") echo " checked=\"checked\"";
echo "/>".$locales["Yes"]." <input type=\"radio\" name=\"allow_ML\" value=\"N\"";
if($myUser->allow_ML=="N") echo " checked=\"checked\"";
echo "/>".$locales["No"].' </p><input type="hidden" name="posted_accountsettings_names[]" value="allow_ML"/>';
echo "<br/>\n\n";
}
if($_GET['format']=="xml"){
echo '<allow_ML value="'.$myUser->allow_ML.'"/>';
}
if(($_GET['format']=="")||(!isset($_GET['format']))) {
echo "<h2>".$locales["Language"]."</h2>\n";
echo '<p id="user_language"><select name="language">';
if($fp = fopen("locales/lc.locales","r"))
{
while (!feof($fp))
{
$ligne = fgets($fp, 4096);
if (preg_match("/^(.+):(.+)$/", $ligne, $regs)) {
echo "<option value=\"".$regs[1]."\"";
if($regs[1]==$myUser->language) echo " selected=\"selected\"";
echo ">".$regs[2]."</option>";
}
}
fclose($fp);
}
echo '</select><input type="hidden" name="posted_accountsettings_names[]" value="language"/></p>';
echo "<br/>\n\n";
}
if($_GET['format']=="xml"){
echo '<language value="'.$myUser->language.'"/>';
}
if(($_GET['format']=="")||(!isset($_GET['format']))) {
echo "<h2>".$locales["UserSignature"]."</h2>\n";
echo '<p id="user_signature"><textarea name="signature">'.preg_replace('/<br \/>/', "", $myUser->signature).'</textarea><input type="hidden" name="posted_accountsettings_names[]" value="signature"/></p>'."\n";
echo "<p><input type=\"submit\" name=\"account_submit\" value=\"".$locales["Update"]."\" class=\"submit\"/></p>\n";
echo "</form>\n\n";
}
if($_GET['format']=="xml"){
echo '<signature>'.htmlspecialchars($myUser->signature).'</signature>';
}
if(($_GET['format']=="")||(!isset($_GET['format'])))
require_once THEME.('footer.inc.php');
if($_GET['format']=="xml")
echo '</usersettings>';
?>