Browse Source

ajout xml + identifiant

Idleman 7 years ago
parent
commit
aabfee656a
8 changed files with 199 additions and 16 deletions
  1. 2 0
      account.php
  2. 27 12
      action.php
  3. 25 0
      class/Type.class.php
  4. 1 1
      component.php
  5. 1 1
      constant.php
  6. 24 0
      function.php
  7. 15 2
      js/main.js
  8. 104 0
      js/plugins.js

+ 2 - 0
account.php

@@ -6,6 +6,8 @@
 			<div class="jumbotron-contents">
 				<form method="POST" action="action.php?action=save_user&amp;id=<?php echo $myUser->id;?>">
 					<h2>Mon profil</h2>
+					<label for="login">Identifiant</label>
+	      			<input type="text" id="login" name="login" value="<?php echo $myUser->login; ?>" class="form-control"/>
 					<label for="password">Nouveau mot de passe</label>
 	      			<input type="password" id="password" name="password" class="form-control"/>
 	      			<label for="confirmPassword">Nouveau mot de passe (Confirmation)</label>

+ 27 - 12
action.php

@@ -31,13 +31,17 @@ switch ($_['action']){
 
 	case 'save_user':
 		try{
-		global $myUser;
-		if(!$myUser->connected()) throw new Exception("Permission refusée, seul un connecté peux faire ça");
-		if($myUser->id!=$_['id']) throw new Exception("Permission refusée, seul le propriétaire du compte peux faire ça");
-		if($_['password']!=$_['confirmPassword']) throw new Exception("Les deux mot de passe ne correspondent pas");
-			$myUser->password = User::password_encrypt($_['password']);
+			global $myUser;
+			if(!$myUser->connected()) throw new Exception("Permission refusée, seul un connecté peux faire ça");
+			if($myUser->id!=$_['id']) throw new Exception("Permission refusée, seul le propriétaire du compte peux faire ça");
+
+			if(!empty($_['password']) && $_['password']!=$_['confirmPassword']) throw new Exception("Les deux mot de passe ne correspondent pas");
+			if(!empty($_['password'])) $myUser->password = User::password_encrypt($_['password']);
+			$myUser->login = $_['login']; 
+
 			$myUser->save();
-			$_SESSION['success'] = "Mot de passe modifié avec succès";
+			$_SESSION['currentUser'] = serialize($myUser);
+			$_SESSION['success'] = "Compte modifié avec succès";
 		}catch(Exception $e){
 			$_SESSION['error'] = $e->getMessage();
 		}
@@ -299,11 +303,22 @@ switch ($_['action']){
 
 	case 'upload_component_image':
 		global $myUser;
-		$ext = explode('.',$_FILES['file']['name']);
-		$ext = strtolower(array_pop($ext));
-		if(!in_array($ext,explode(',',ALLOWED_RESOURCE_IMAGE))) exit();
-		imageResize($_FILES['file']['tmp_name'],100,100);
-		echo 'data:image/png;base64,'.base64_encode(file_get_contents($_FILES['file']['tmp_name']));
+		$response = array();
+		try{
+			if(!isset($_FILES['file'])) throw new Exception("Le fichier est trop gros pour votre configuration php (php.ini), taille max :".max_upload_size(array(ALLOWED_RESOURCE_SIZE)));
+			$ext = explode('.',$_FILES['file']['name']);
+			$ext = strtolower(array_pop($ext));
+			if(!in_array($ext,explode(',',ALLOWED_RESOURCE_IMAGE))) throw new Exception("Format d'image interdit, autorisé : ".ALLOWED_RESOURCE_IMAGE);
+			if($_FILES['file']['size']>ALLOWED_RESOURCE_SIZE) throw new Exception("Le fichier est trop gros pour votre configuration programme, taille max: ".max_upload_size(array(ALLOWED_RESOURCE_SIZE)));
+		
+
+			imageResize($_FILES['file']['tmp_name'],100,100);
+			$response['thumb']  = 'data:image/png;base64,'.base64_encode(file_get_contents($_FILES['file']['tmp_name']));
+		}catch(Exception $e){
+			$response['error'] = $e->getMessage();
+		}
+		header('Content-Type:application/json');
+		echo json_encode($response);
 	break;
 	
 	
@@ -318,7 +333,7 @@ switch ($_['action']){
 				if($part->image==''){
 					$part->image = 'img/default_image.png';
 				}else{
-					$part->image = PART_PATH.html_entity_decode($part->image);
+					$part->image = PART_PATH.html_entity_decode($part->image).'?t='.time();
 				}
 				$response['rows'][] = $part->toArray();
 			}

+ 25 - 0
class/Type.class.php

@@ -38,6 +38,7 @@ class Type{
 				'readOnly' =>  false
 			)
 		);
+
 		$types['clike'] = array(
 			'label' => 'Source C++/C',
 			'extension' => 'cpp',
@@ -48,6 +49,7 @@ class Type{
 				'readOnly' =>  false
 			)
 		);
+
 		$types['shell'] = array(
 			'label' => 'Shell',
 			'extension' => 'sh',
@@ -70,6 +72,18 @@ class Type{
 			)
 		);
 
+		$types['xml'] = array(
+			'label' => 'Source XML',
+			'extension' => 'xml',
+			'codemirror' => array(
+				'mode'=>'htmlmixed',
+				'theme'=>'monokai',
+				'lineNumbers' => true,
+				'readOnly' =>  false
+			)
+		);
+
+
 		$types['python'] = array(
 			'label' => 'Source Python',
 			'extension' => 'py',
@@ -124,6 +138,17 @@ class Type{
 			)
 		);
 
+		$types['json'] = array(
+			'label' => 'Source JSON',
+			'extension' => 'json',
+			'codemirror' => array(
+				'mode'=>'javascript',
+				'theme'=>'monokai',
+				'lineNumbers' => true,
+				'readOnly' =>  false
+			)
+		);
+
 		$types['image'] = array(
 			'label' => 'Image',
 			'upload' => array(

+ 1 - 1
component.php

@@ -51,7 +51,7 @@
 	        <input class="form-control" type="text" id="brand"/>
 	        <label for="label">Prix</label>
 	        <input class="form-control" type="text" id="price"/>
-			<label for="imageUpload">Image (fichier)</label><br/>
+			<label for="imageUpload">Image (fichier) (taille max : <?php echo max_upload_size(array(ALLOWED_RESOURCE_SIZE)); ?> )</label><br/>
 			<img src="img/default_image.png" style="width:100px;height:100px;" id="imageUpload"/>
 			
 	      </div>

+ 1 - 1
constant.php

@@ -14,7 +14,7 @@ define('ALLOWED_RESOURCE_IMAGE','jpg,png,jpeg,gif,bmp');
 //Laisser vide si pas de vérification sur les resources de fichiers, sinon placez les extension
 //autorisées sous la forme : jpg,png,jpeg,gif,bmp,txt,doc,docx,cmd,bat,exe,cpp,c,h,hpp,ino,php,js,css,ttf,woff,svg,pdf,xls,xlsx,sql,ico,doc,docx
 define('ALLOWED_RESOURCE_FILE','');
-define('ALLOWED_RESOURCE_SIZE',1000000);
+define('ALLOWED_RESOURCE_SIZE',6000000);
 
 define('PROGRAM_NAME','Hackpoint');
 define('SOURCE_VERSION','1.0');

+ 24 - 0
function.php

@@ -150,6 +150,26 @@ function getExtIcon($ext){
 	return $icon;
 };
 
+function max_upload_size($limits = array()){
+	$limits[]= str_replace('M','',ini_get('post_max_size')) *1048576;
+	$limits[]= str_replace('M','',ini_get('upload_max_filesize')) *1048576;
+	return readable_size(min($limits));
+}
+
+function readable_size($bytes)
+{
+		 if($bytes<1024){
+		 	return round(($bytes / 1024), 2).' o';
+		 }elseif(1024<$bytes && $bytes<1048576){
+		 	return round(($bytes / 1024), 2).' ko';
+		 }elseif(1048576<$bytes && $bytes<1073741824){
+		 	return round(($bytes / 1024)/1024, 2).' Mo';
+		 }elseif(1073741824<$bytes){
+		 	return round(($bytes / 1024)/1024/1024, 2).' Go';
+		 }
+}
+
+
 function imageResize($image,$w,$h){
 	$resource = imagecreatefromstring(file_get_contents($image));
 	$size = getimagesize($image);
@@ -160,4 +180,8 @@ function imageResize($image,$w,$h){
 	imagejpeg($thumbnail , $image, 100);
 }
 
+
+
+
+
 ?>

+ 15 - 2
js/main.js

@@ -57,15 +57,28 @@ function init_component(){
 
 	search_component();
 
+/*
+	$('#imageUpload').upzone({
+		url : 'action.php?action=upload_component_image',
+		id  : $('#sketch').attr('data-id'),
+		success : function(server){
+			$('#imageUpload').attr('src',server);
+		}
+	});
+*/
+
 	$('#imageUpload').dropzone({
+
 			url : 'action.php?action=upload_component_image',
 			success : function(useless,server){
+					if(server.error != null)
+						return alert(server.error);
 					
-        			$('#imageUpload').attr('src',server);
+        			$('#imageUpload').attr('src',server.thumb);
       			
 			},
 			sending : function(file, xhr, formData){
-				//formData.append('id', $('#sketch').attr('data-id'));
+				formData.append('id', $('#sketch').attr('data-id'));
 			}
 	});
 

+ 104 - 0
js/plugins.js

@@ -140,10 +140,114 @@
 				return results[1] || 0;
 			}
 	}
+
+
+	$.upzoneTransfert = function(e,o){
+		var list = [];
+		if(e.dataTransfer) {
+			filelist = e.dataTransfer.files;
+		} else if(e.target) {
+			filelist = e.target.files;
+		}
+
+		if (!filelist || !filelist.length ) return;
+
+		        totalSize = 0;
+		        totalProgress = 0;
+		
+
+		        for (var i = 0; i < filelist.length && i < 5; i++) {
+		            list.push(filelist[i]);
+		            totalSize += filelist[i].size;
+		        }
+
+		        if (list.length) {
+		           
+
+		            var nextFile = list.shift();
+		            //if (nextFile.size >= 262144) { // 256 kb
+		         
+				        var xhr = new XMLHttpRequest();
+				        xhr.open('POST', o.url);
+				        xhr.onload = function() {
+				           // result.innerHTML += this.responseText;
+				           // handleComplete(file.size);
+				           if(o.success!=null)o.success(this.responseText);
+				        };
+				        xhr.onerror = function() {
+				           // result.textContent = this.responseText;
+				          //  handleComplete(file.size);
+				          console.log(this.responseText,'error');
+				          if(o.error!=null)o.error(this.responseText);
+				        };
+				        xhr.upload.onprogress = function(event) {
+				           // handleProgress(event);
+				           //console.log(event);
+				        }
+				        xhr.upload.onloadstart = function(event) {
+				        }
+
+				        // création de l'objet FormData
+				        var formData = new FormData();
+				        for(var k in o)
+				        	formData.append(k, o[k]);
+				        
+				      
+				        formData.append('file', nextFile);
+				        xhr.send(formData);
+		           
+		 }
+
+	}
+
 	
 $.fn.extend({
 	
+	upzone : function (option){
+		var defaults = {
+			url : '',
+			success : function(){},
+			error : function(){}
+		}
+		
+		var o = $.extend(defaults,option);
+		return this.each(function() {
+			var obj = $(this);
 
+			obj.before('<input type="file" id="test" style="display:none">');
+			
+			$('#test').change(function(e) {
+				
+				$.upzoneTransfert(e,o);
+
+     	 	});
+			obj.click(function(){
+				$('#test').trigger('click');
+			});
+
+			obj.get(0).addEventListener('drop', function(event) {
+		        event.stopPropagation();
+		        event.preventDefault();
+
+		        $.upzoneTransfert(event,o);
+
+		      	//var filelist = event.dataTransfer.files;
+		  
+		        
+
+
+
+    		}, false);
+
+        	obj.get(0).addEventListener('dragover', function handleDragOver(event) {
+		        event.stopPropagation();
+		        event.preventDefault();
+
+		      
+		    }, false);
+
+		});
+	},
 	
 	fill: function (option,callback){