<?
require_once("include/includes.php");
if (($HttpVars->TraerSession('adminValido') != "si")){
header("Location: index.php");
}
$idUsuarioName = $_SESSION['idUsuarioAdminSUser'];
$imagespath = "imagenes/";
$agregada = 0;
$existe = 0;
if ($HttpVars->TraerPost('envio') != '') {
$pathabs1 = "";
$pathabs2 = "";
$nombre = $HttpVars->TraerPost('nombre');
$sql="SELECT nombre from tbl_productos where nombre = '" . $nombre . "'";
$result = mysqli_query( $conexion, $sql );
if($result->num_rows > 0) {
$existe = 1;
}else{
$archivo1=$_FILES['imgch']['tmp_name'];
$nomarchivo1=$_FILES['imgch']['name'];
if (is_dir( PATHIMAGEN ) == false) {
mkdir( PATHIMAGEN );
}
$directorio = PATHIMAGEN ;
$archfinal1 = $directorio . $nomarchivo1 ;
if (file_exists ($archivo1)){
$pathabs1 = "" ;
move_uploaded_file ($archivo1, $archfinal1 );
if (file_exists ($directorio . $nomarchivo1))
{
$patharch1 = $directorio . $nomarchivo1 ;
$pathabs1=str_replace("\\","\\\\",$patharch1);
}
}
//adjunto1
$allowed = array('gif','png' ,'jpg', 'jpeg', 'pdf','docx','doc');
$adj1=$_FILES['adj1']['tmp_name'];
$nomadj1=$_FILES['adj1']['name'];
$ext = pathinfo($nomadj1, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) ) {
$msjextension = '<div class="alert alert-danger" role="alert">Los archivos deben ser GIF, PNG, JPG, PDF o DOC</div>';
} else {
if (is_dir( PATHIMAGEN ) == false) {
mkdir( PATHIMAGEN );
}
$directorio = PATHIMAGEN ;
$adj1final1 = $directorio . $nomadj1 ;
if (file_exists ($adj1)){
$pathadj1 = "" ;
move_uploaded_file ($adj1, $adj1final1 );
if (file_exists ($directorio . $nomadj1))
{
$pathadj1 = $directorio . $nomadj1 ;
$pathadj1=str_replace("\\","\\\\",$pathadj1);
}
}
//adjunto2
$adj2=$_FILES['adj2']['tmp_name'];
$nomadj2=$_FILES['adj2']['name'];
if (is_dir( PATHIMAGEN ) == false) {
mkdir( PATHIMAGEN );
}
$directorio = PATHIMAGEN ;
$adj2final2 = $directorio . $nomadj2 ;
if (file_exists ($adj2)){
$pathadj2 = "" ;
move_uploaded_file ($adj2, $adj2final2 );
if (file_exists ($directorio . $nomadj2))
{
$pathadj2 = $directorio . $nomadj2 ;
$pathadj2=str_replace("\\","\\\\",$pathadj2);
}
}
//adjunto3
$adj3=$_FILES['adj3']['tmp_name'];
$nomadj3=$_FILES['adj3']['name'];
if (is_dir( PATHIMAGEN ) == false) {
mkdir( PATHIMAGEN );
}
$directorio = PATHIMAGEN ;
$adj3final3 = $directorio . $nomadj3 ;
if (file_exists ($adj3)){
$pathadj3 = "" ;
move_uploaded_file ($adj3, $adj3final3 );
if (file_exists ($directorio . $nomadj3))
{
$pathadj3 = $directorio . $nomadj3 ;
$pathadj3=str_replace("\\","\\\\",$pathadj3);
}
}
//adjunto4
$adj4=$_FILES['adj4']['tmp_name'];
$nomadj4=$_FILES['adj4']['name'];
if (is_dir( PATHIMAGEN ) == false) {
mkdir( PATHIMAGEN );
}
$directorio = PATHIMAGEN ;
$adj4final4 = $directorio . $nomadj4 ;
if (file_exists ($adj4)){
$pathadj4 = "" ;
move_uploaded_file ($adj4, $adj4final4 );
if (file_exists ($directorio . $nomadj4))
{
$pathadj4 = $directorio . $nomadj4 ;
$pathadj4=str_replace("\\","\\\\",$pathadj4);
}
}
$nombre = $HttpVars->TraerPost('nombre') ;
$keywords = $HttpVars->TraerPost('keywords') ;
$chkpubli = $HttpVars->TraerPost('chkpubli') ;
$destacado = $HttpVars->TraerPost('chkdestacado') ;
$oferta = $HttpVars->TraerPost('chkoferta') ;
if ($chkpubli == "") $chkpubli = 0;
if ($destacado == "") $destacado = 0;
if ($oferta == "") $oferta = 0;
$dcorta = $HttpVars->TraerPost('dcorta') ;
$dlarga = $HttpVars->TraerPost('dlarga') ;
$tips = $HttpVars->TraerPost('tips') ;
$dosis = $HttpVars->TraerPost('dosis') ;
$label1 = $HttpVars->TraerPost('label1') ;
$label2 = $HttpVars->TraerPost('label2') ;
$label3 = $HttpVars->TraerPost('label3') ;
$label4 = $HttpVars->TraerPost('label4') ;
$codigo = $HttpVars->TraerPost('codigo') ;
$precio = $HttpVars->TraerPost('precio') ;
$id_cate = $HttpVars->TraerPost('cmbcategoria') ;
$id_plaga = $HttpVars->TraerPost('cmbplaga') ;
$id_subcate = $HttpVars->TraerPost('cmbsubcate') ;
$sql="INSERT into tbl_productos( nombre, keywords, codigo, precio, dcorta, dlarga, tips, dosis, pathch, filech, adjunto1, adjunto2, adjunto3, adjunto4, label1, label2, label3, label4, destacado, oferta, publicado) VALUES " .
"('".$nombre."','".$keywords."','".$codigo."',".$precio.",'".$dcorta."','".$dlarga."','".$tips."','".$dosis."','".$pathabs1."','".$nomarchivo1."','".$pathadj1."','".$pathadj2."','".$pathadj3."','".$pathadj4."','".$label1."','".$label2."','".$label3."','".$label4."',".$destacado.",".$oferta.",".$chkpubli.")";
$result = mysqli_query( $conexion, $sql );
$agregada = 1;
//grabo las categorias en la tabla relcateprod
$sql = "SELECT MAX(id_prod) as id_prod FROM tbl_productos";
$result = mysqli_query( $conexion, $sql );
$myrow = mysqli_fetch_assoc( $result );
$id_prod = $myrow["id_prod"];
$idcate=$HttpVars->TraerPost('id_cate');
while (list ($key,$val) = @each ($idcate)) {
$sql = "INSERT INTO tbl_relcateprod(id_prod, id_cate) VALUES (".$id_prod.",".intval($val).")";
$result = mysqli_query( $conexion, $sql );
}
$idplaga=$HttpVars->TraerPost('id_plaga');
while (list ($key,$val) = @each ($idplaga)) {
$sql = "INSERT INTO tbl_relplagaprod(id_prod, id_plaga) VALUES (".$id_prod.",".intval($val).")";
$result = mysqli_query( $conexion, $sql );
}
}
}
$nombre = $HttpVars->TraerPost('nombre') ;
$keywords = $HttpVars->TraerPost('keywords') ;
$chkpubli = $HttpVars->TraerPost('chkpubli') ;
$destacado = $HttpVars->TraerPost('chkdestacado') ;
$oferta = $HttpVars->TraerPost('chkoferta') ;
if ($chkpubli == "") $chkpubli = 0;
if ($destacado == "") $destacado = 0;
if ($oferta == "") $oferta = 0;
$dcorta = $HttpVars->TraerPost('dcorta') ;
$dlarga = $HttpVars->TraerPost('dlarga') ;
$tips = $HttpVars->TraerPost('tips') ;
$dosis = $HttpVars->TraerPost('dosis') ;
$label1 = $HttpVars->TraerPost('label1') ;
$label2 = $HttpVars->TraerPost('label2') ;
$label3 = $HttpVars->TraerPost('label3') ;
$label4 = $HttpVars->TraerPost('label4') ;
$codigo = $HttpVars->TraerPost('codigo') ;
$precio = $HttpVars->TraerPost('precio') ;
$id_cate = $HttpVars->TraerPost('cmbcategoria') ;
$id_plaga = $HttpVars->TraerPost('cmbplaga') ;
$id_subcate = $HttpVars->TraerPost('cmbsubcate') ;}
?>