<?php
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# 
#			Add a Bookmark
# 
# ***************************************
 
$not_access=1;
$granted="I";

require_once('../scripts/includes_mobile.php');
 
$id_user = $_SESSION['user_id']; 
$title = $_POST['titre'];
$url = $_POST['url'];
$tag = $_POST['tag'];
$id = isset($_POST['id'])?$_POST['id']:0;
$act = $_GET["act"];
$link_id = isset($_POST["link_id"])?$_POST["link_id"]:0;
$tab = $_GET['tab'];
$uniq = $_POST['uniq'];
$mod_id = $_POST['mod_id'];

//do not add in database if empty url or title
if (empty($url) or empty($title)) {
	header("location:../scripts/display_widget.php?mod_id=".$mod_id."&tab=".$tab);
	exit();
}

//Add a bookmark in database
if($act=="upd") {
	$DB->execute($widFav_updateFavorite,$DB->quote($title),$DB->quote($url),$DB->quote($tag),$DB->escape($link_id),$DB->escape($_SESSION["user_id"]));
} else {
	$sharedMD5 = md5(uniqid(rand(), true));
	if(empty($id)) {
		$DB->execute($widlink_addNewLinkId, $DB->escape($_SESSION['user_id']), $DB->quote($sharedMD5));
		$id = $DB->getId();
		$DB->execute($updModule,$DB->quote("linkid=".$id),$DB->escape($_SESSION['user_id']), $DB->escape($uniq));
	}
	$DB->getResults($widlink_getIdLink,$DB->escape($id), $DB->escape($_SESSION['user_id']));
	$DB->execute($widlink_addNewLink, $DB->escape($id), $DB->quote($title), $DB->quote($url), $DB->quote($tag));
	$DB->freeResults();
}

header("location:../scripts/display_widget.php?mod_id=".$mod_id."&tab=".$tab);
?>