<?php
require_once 'conf/link.php';

$nombrelista = $_POST['nombrelista'];
$videos_id = $_POST['listOfItems'];
$usuario = "admin";
$creacion = date("Y-m-d");

$playlist_id = explode('|', $videos_id);

foreach($playlist_id as $index=>$id)	{
	$sql = 'SELECT * FROM almacen WHERE id = "'.$id.'"';
	$result = mysqli_query($conexion, $sql);
	while($row = mysqli_fetch_assoc($result))	{	
		$media[] = array('id' => $row['id'], 'filename' => $row['filename'], 'thumbnail' => $row['thumbnail']);
	}
}
		
$media_json = json_encode($media);
		
$sql  = "INSERT INTO listas ( nombre_lista, videos_id, ultimo_usuario, creacion) ";
$sql .= "VALUES ('$nombrelista', '$media_json', '$usuario', '$creacion')";

$result = mysqli_query($conexion, $sql);
if ($result)	{
	echo "Exito";
}
else	{
	echo "Fallo";
	printf (mysqli_error($conexion));
}
?>
