Commit febd6409637c28f2dcc03f878d1ad2ce4b51a9d7
1 parent
a0daba42
News creation done
Showing
2 changed files
with
28 additions
and
0 deletions
Show diff stats
js/crep.js
... | ... | @@ -24,6 +24,16 @@ function deleteNewNews() |
24 | 24 | $("#newNews").remove(); |
25 | 25 | } |
26 | 26 | |
27 | +function validNewNews() | |
28 | +{ | |
29 | + var ret; | |
30 | + ret = $.post( "sendNews.php", {title: Base64.encode($("#newNews")[0].childNodes[0].childNodes[0].childNodes[0].value), content: Base64.encode($("#newNews")[0].childNodes[1].childNodes[0].value)}); | |
31 | + if(ret == true) | |
32 | + document.location.reload(); | |
33 | + else | |
34 | + alert("Erreur durant la transmission de la news"); | |
35 | +} | |
36 | + | |
27 | 37 | function addNews() |
28 | 38 | { |
29 | 39 | var elem = "<div id=\"newNews\" class=\"panel panel-default\"><div class=\"panel-heading\"><h3 class=\"panel-title\"><input type=text class=\"form-control\" placeholder=\"Nouvel article\"/></h3></div><div class=\"panel-body\"><textarea class=\"form-control\"></textarea></div><div class=\"panel-footer\"><p><button type=\"button\" onClick=\"validNewNews();\" class=\"btn btn-success\">Success</button> <button type=\"button\" onClick=\"deleteNewNews();\" class=\"btn btn-danger\">Annuler</button></p></div></div>"; | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<?php | |
2 | +require_once("creds.php"); | |
3 | + | |
4 | +if(isset($_SESSION["admin"])&&$_SESSION["admin"]) | |
5 | +{ | |
6 | + $link = mysql_connect(__MYSQL_HOSTNAME__, __MYSQL_USERNAME__, __MYSQL_PASSWORD__) | |
7 | + or die("Impossible de se connecter : " . mysql_error()); | |
8 | + if(!mysql_select_db('crep', $link)) | |
9 | + { | |
10 | + echo 'Selection de la base de donnees impossible'; | |
11 | + exit; | |
12 | + } | |
13 | + $requete = "INSERT INTO `crep`.`news` (`pk` ,`fk_author` ,`created` ,`title` ,`content`) VALUES (NULL , '2', CURDATE(), ".base64_decode($_POST["title"]).", ".base64_decode($_POST["content"]).")"; | |
14 | + $resultat = mysql_query($requete); | |
15 | +} | |
16 | +else | |
17 | + die("Nop, only admins here !"); | |
18 | + | ... | ... |