<?php
//editare carte
require_once ('smarty/Smarty.class.php');
require_once ('include/functions.php');
require_once ('conf/dbconnect.php');
require_once "conf/config.php";
if(isset($_POST['json']) && $_POST['json'] == 1){ // o facem asincron
if(isset($_POST['action']) && $_POST['action'] == "delete"){
$id = $_POST['id_carte_delete'];
$ok = sterge_carte($id);
if($ok[0])
echo '{"response":1}';
else{
echo '{"response":0,"reason":"'.$ok[1].'"}';
}
}else{
$date_carte = array(
"cod"=>$_POST['clasificare'],
"titlu"=>$_POST['titlu'],
"nume_autor"=>$_POST['nume_autor'],
"prenume_autor"=>$_POST['prenume_autor'],
"editura"=>$_POST['editura'],
"adresa"=>$_POST['adresa'],
"nr_inventar"=>$_POST['nr_inventar']
);
$executa = modifica_carte($_POST['id_carte'], $date_carte);
if(!$executa){
echo '{"response":1}';
}else{
echo '{"response":0}';
}
}
}else{
if(!isset($smarty)){
$smarty = new Smarty;
$print = 1;
}else{
$print = 0;
}
$smarty->assign('server', $_SERVER['REQUEST_URI']);
if(isset($_GET['id'])){
$sql = "SELECT * FROM ".$table_prefix."carti WHERE id_carte='".$_GET['id']."'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$smarty->assign('titlu', $row['titlu']);
$smarty->assign('nume_autor', $row['nume_autor']);
$smarty->assign('prenume_autor', $row['prenume_autor']);
$smarty->assign('editura', $row['editura']);
$smarty->assign('adresa', $row['adresa']);
$smarty->assign('nr_inventar', $row['nr_inventar']);
$smarty->assign('cod', $row['cod']);
if(isset($_POST['submit'])){
$date_carte = array(
"cod"=>$_POST['cod'],
"titlu"=>$_POST['titlu'],
"nume_autor"=>$_POST['nume_autor'],
"prenume_autor"=>$_POST['prenume_autor'],
"editura"=>$_POST['editura'],
"adresa"=>$_POST['nr_inventar']
);
$executa = modifica_carte($_GET['id'], $date_carte);
if(!$executa){
$smarty->assign('message', 'Modificare cu succes!<script type="text/javascript">window.setTimeout("history.back()", 5000);</script>');
}else{
$smarty->assign('message', 'Modificare esuata!<script type="text/javascript">window.setTimeout("history.back()", 5000);</script>');
}
$smarty->assign("action", "1");
}else
$smarty->assign("action", "0");
$smarty->assign('error', 'error ba fraiere!');
}
if($print)
$smarty->display('mod_carte.tpl.php');
else
$smarty->assign("template", "mod_carte.tpl.php");
}
?>