<?php
session_start();
include_once 'src/combox.php';
include_once 'src/clicktoconnect.php';
include_once 'config.php';
$url='connexion.php';
if(!isset($_SESSION['connected'])){
echo '<script type="text/javascript">window.location="'.$url.'";</script>';
header('location: connexion.php');
}
$action=(isset($_GET["action"]))?$_GET["action"]:false;
switch($action){
case "upload":
//case upload...
$image = new Upload(
array(
'file' => 'image',
'upload_path' => ctc_pict_path.'/'
)
);
$imgex = explode('.', $_FILES['image']['name']);
$imgex = end($imgex);
$name=$_SESSION['pseudo'].date('ymdHis',time()).'.'.$imgex;
$new= new clicktoconnect($bdd,$_SESSION['user_id'],ctc_pict_path.'/'.$name ,sha1('ctc1_1 1_1 1_1 1_1default'),0);
// var_dump($new);
if($image->process($name)){
if($new->addpicture(true)){
echo "<p><a href=".$_SERVER['PHP_SELF']."?ui=crop&&name=".ctc_pict_path."/".$name.">Crop and add your password now</a></p>";
}
}
BREAK;
case "crop":
// case crop
$image_src = $_POST["image"];
$new_image_src = ctc_pict_path.'/'.basename($image_src);
$width = intval($_POST["width"]);
$height = intval($_POST["height"]);
$x = intval($_POST["x"]);
$y = intval($_POST["y"]);
/* Set options */
$options = array(
'image_src' => $image_src,
'new_image_src' => $new_image_src,
'width' => $width,
'height' => $height,
'x' => $x,
'y' => $y,
);
$cropImage = new cropImage($options);
$img = new image_sizer();
$img->setImage($new_image_src);
$img->setSize(400, 400);
if($img->saveTo($new_image_src, 100)){
echo 'success';
}else{
echo 'failed';
}
BREAK;
default:
$interface=(isset($_GET["ui"]))?$_GET["ui"]:false;
switch ($interface){
case 'upload':
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ajax Upload</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div id="content">
<p><hr/>| Welcome <span id="pseudo"><?php echo strtoupper($_SESSION["pseudo"]);?></span> | <a href="dologout.php" class="none">Log out</a> | <a href="preferences.php" class="none">Preferences</a> |<hr/></p>
<h1> Change Your preferences</h1>
<div class="grid"><h2>Add a new click to connect picture</h2>
<form action="<?php echo $_SERVER['PHP_SELF'].'?action=upload' ?>" method="post" enctype="multipart/form-data" class="uploadForm">
<input type="file" name="image" class="image">
</form>
<div id="preview"></div>
<!--<script src="./jquery-ui-1.12.1/external/jquery/jquery.js"></script>-->
<script src='http://code.jquery.com/jquery.js'></script>
<script src="./assets/js/jquery.form.js"></script>
<script>
jQuery(document).ready(function($){
$('.image').on('change', function(){
$('#preview').html('<img src="assets/img/loader.gif" alt="Uploading...." class="little"/>');
$('.uploadForm').ajaxForm({ target: '#preview' }).submit();
});
});
</script> </div></div>
</body>
</html><?php
break;
case 'crop':?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
<script src='http://code.jquery.com/jquery.js'></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="assets/css/style.css">
<!--<link rel="stylesheet" href="./jquery-ui-1.12.1/jquery-ui.css" />
<script src='./jquery-ui-1.12.1/external/jquery/jquery.js'></script>
<script src="./jquery-ui-1.12.1/jquery-ui.js"></script>-->
<?php
$image = $_GET['name'];;
list($width, $height) = getimagesize($image);
$max_width = $width;
// $min_width = $width / 2;
$min_width =150;
$max_height = $height;
// $min_height = $height / 2;
$min_height = 150;
?>
<script>
$(function(){
var _width;
var _height;
var _x;
var _y;
$( "#resize" ).resizable({
maxWidth: <?php echo $max_width ?>,
maxHeight: <?php echo $max_height ?>,
minWidth: <?php echo $min_width ?>,
minHeight: <?php echo $min_height ?>,
containment: "parent",
create: function(event, ui){
_width = $(this).width();
_height = $(this).height();
console.log("width: " + _width);
console.log("height: " + _height);
$("#preview").css({width: _width+"px", height: _height+"px"});
},
resize: function(event, ui){
_width = ui.size.width;
_height = ui.size.height;
console.log("width: " + _width);
console.log("height: " + _height);
$("#preview").css({width: _width+"px", height: _height+"px"});
},
});
$( "#resize" ).draggable({
containment: "parent",
create: function(event, ui){
_x = $(this).offset().left - $("#box").offset().left;
_y = $(this).offset().top - $("#box").offset().top;
console.log("x: " + _x);
console.log("y: " + _y);
$("#preview").css({backgroundImage: "url(<?php echo $image ?>)", backgroundPosition: -_x + "px " + -_y + "px"});
},
drag: function(event, ui){
_x = ui.offset.left - $("#box").offset().left;
_y = ui.offset.top - $("#box").offset().top;
console.log("x = " + _x);
console.log("y = " + _y);
$("#preview").css({backgroundImage: "url(<?php echo $image ?>)", backgroundPosition: -_x + "px " + -_y + "px"});
},
});
$("#btn").on("click", function(){
$('#preview').html('<img src="assets/img/loader.gif" alt="Uploading.... " class="little"/>');
$.post("<?php echo $_SERVER['PHP_SELF'].'?action=crop' ?>", {image: "<?php echo $image ?>", width: _width, height: _height, x: _x, y: _y}, function(data){
if(data.trim() == 'success'){
setInterval(window.location="addyourpassnow.php?name=<?php echo $image ?>",30000);
} else{
$("#request").html("<p id='resultat'>An error occured while trying to save Your ctc picture!Wait while refreshing...</p>");
setInterval(window.location="<?php echo $_SERVER['PHP_SELF'].'?ui=crop&&name='.$image;?>",30000);
}
}, 'text' );
});
});
</script>
<style>
#box{
background-image: url("<?php echo $image ?>");
background-repeat: no-repeat;
width: <?php echo $width ?>px;
height: <?php echo $height ?>px;
border: 1px solid #7E9EC7;
}
#resize{
width: <?php echo $width ?>px;
height: <?php echo $height ?>px;
border: 1px dashed #EE4040;
}
#preview{
background-repeat: no-repeat;
border: 1px solid #7E9EC7;
}
</style>
</head>
<body>
<div class="container">
<p><hr/>| Welcome <span id="pseudo"><?php echo strtoupper($_SESSION["pseudo"]);?></span> | <a href="dologout.php" class="none">Log out</a> |<a href="preferences.php" class="none">Preferences</a> |<hr/></p>
<h1> Change Your preferences</h1>
<div class="row">
<h3>Crop your new click to connect Image</h3>
<div id="request">
<div class="row">
<div >
<div id="box"><div id="resize"></div></div>
</div>
<div >
<h3>Preview</h3>
<div id="preview"></div>
<br/>
<button type="button" id="btn"><span>SAVE</span></button>
</div>
</div>
</div>
<br/>
<br/>
</div>
</body>
</html><?php
break;
default:
?><!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Upload a new CTC picture</title>
<link rel="stylesheet" href="./assets/css/style.css">
</head>
<body>
<div id="content">
<p><hr/>| Welcome <span id="pseudo"><?php echo strtoupper($_SESSION["pseudo"]);?></span> | <a href="dologout.php" class="none">Log out</a> | <a href="preferences.php" class="none">Preferences</a> |<hr/></p>
<h1> Change Your preferences</h1>
<div class="grid"><h2>Add a new click to connect picture</h2>
<form action="<?php echo $_SERVER['PHP_SELF'].'?action=upload' ?>" method="post" enctype="multipart/form-data" class="uploadForm">
<input type="file" name="image" class="image">
</form>
<div id="preview"></div>
<!--<script src="./jquery-ui-1.12.1/external/jquery/jquery.js"></script>-->
<script src='http://code.jquery.com/jquery.js'></script>
<script src="./assets/js/jquery.form.js"></script>
<script>
jQuery(document).ready(function($){
$('.image').on('change', function(){
$('#preview').html('<img src="assets/img/loader.gif" alt="Uploading.... " class="little"/>');
$('.uploadForm').ajaxForm({ target: '#preview' }).submit();
});
});
</script> </div></div>
</body>
</html><?php
break;
}
BREAK;
}
|