<?php
session_start();
include_once 'config.php';
include_once 'src/clicktoconnect.php';
if(isset($_GET["name"])&&isset($_GET["deletethis"])){
$x=new usepictures($bdd,$_SESSION["user_id"]);
$x=$x->getapass($_GET["name"]);
$x=new clicktoconnect($bdd,$_SESSION['user_id'],$_GET['name'],$x,0);
if($x->deletepicture()){
unlink($_GET["name"]);
echo'success';
}else{
echo 'failed';
}
}
elseif(isset($_GET["name"])){
$x=new usepictures($bdd,$_SESSION["user_id"]);
$x=$x->getapass($_GET["name"]);
if($x!=sha1('ctc1_1 1_1 1_1 1_1default')){
$req=$bdd->prepare('
UPDATE users SET
default_ctcpic=:default_ctcpic
WHERE user_id=:user_id'
);
$req->bindValue(':user_id',$_SESSION["user_id"],PDO::PARAM_INT);
$req->bindValue(':default_ctcpic',$_GET["name"],PDO::PARAM_STR);
$req->execute();
$req->CloseCursor();
echo'success';
}else{
echo 'You can\'t select this picture as default connexion picture.Please change this picture\'s password first and try again.';
}
}elseif(isset($_POST['type'])){
// $_POST['type']=(int)$_POST['type'];
$_POST['type']=($_POST['type']!=0&&$_POST['type']!=1&&$_POST['type']!=2&&$_POST['type']!=3&&$_POST['type']!=4)?'2':$_POST['type'];
if($_POST['type']==3||$_POST['type']==4){
$x=new usepictures($bdd,$_SESSION["user_id"]);
$x=$x->getallpass();
if(!in_array(sha1('ctc1_1 1_1 1_1 1_1default'),$x)){
// var_dump($_POST['type']);
$req=$bdd->prepare('
UPDATE users SET
user_preference=:user_preference
WHERE user_id=:user_id');
$req->bindValue(':user_id',$_SESSION["user_id"],PDO::PARAM_INT);
$req->bindValue(':user_preference',$_POST['type'],PDO::PARAM_STR);
$req->execute();
$req->CloseCursor();
echo'success';
}else{
echo 'You can\'t select this option as default connexion option.Please choose a personal password for each picture first and try again.';
}
}else{
// var_dump($_POST['type']);
$req=$bdd->prepare('
UPDATE users SET
user_preference=:user_preference
WHERE user_id=:user_id');
$req->bindValue(':user_id',$_SESSION["user_id"],PDO::PARAM_INT);
$req->bindValue(':user_preference',$_POST['type'],PDO::PARAM_STR);
$req->execute();
$req->CloseCursor();
echo'success';
}
}
else{
echo "Failed";
}
?>
|