<?php
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# 
#		Bookmark Widget
# 
# ***************************************

$id = parser($variables, 'linkid=');
$page = isset($_GET["linkpage".$id])  ?   ($_GET["linkpage".$id])   : 0;
$pageStart = $page*5;
$userId = isset($_SESSION["user_id"])   ?   $_SESSION["user_id"]    :   0;

if (isset($_GET["updated".$id])) {
	$updatedFav=$_GET["updated".$id];
	$DB->getResults($widFav_getFavorite,$DB->escape($updatedFav),$DB->escape($userId));
	$row = $DB->fetch(0);
	echo '<a name="favorites"></a>
		<div class="widget_options">
		<form method="post" action="../widgets/scr_widget_85.inc.php?act=upd&tab='.$selectedTab.'">
			<input type="hidden" name="link_id" value="'.$updatedFav.'"/>
			<input type="hidden" name="id" value="'.$id.'" />
			<input type="hidden" name="uniq" value="'.$uniq.'" />
			<input type="hidden" name="mod_id" value="'.$mod_id.'" />
			<table cellpadding="0">
				<tr>
				<td>'.lg('name').' </td>
				<td><input type="text" name="titre" value="'.$row['name'].'" /></td>
				</tr>
				<tr>
				<td>'.lg('url').' </td>
				<td><input type="text" name="url" value="'.$row['url'].'" /></td>
				</tr>
				<tr>
				<td>'.lg('tags').' </td>
				<td><input type="text" name="tag" value="'.$row['tags'].'"/></td>
				</tr>
				<tr>
				<td></td>
				<td><input type="submit" value="'.lg("modif").'"/> <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'#favorites">'.lg('cancel').'</a></td>
				</tr>
			</table>
		</form>
		</div>';

	$DB->freeResults();
}
else {
	$DB->getResults($widFav_getFavorites,$DB->escape($id),$DB->escape($userId),$DB->escape($pageStart));
	$nbFav=$DB->nbResults();
	$inc=0;
	echo '<a name="favorites"></a>
         <div class="widget">';
		
	while (($row = $DB->fetch(0)) && $inc<5) {
		$linkid=$row['link_id'];
		echo '	<a href="'.$row['url'].'">'.$row['name'].'</a>            
				<a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&updated'.$id.'='.$linkid.'#favorites"><img src="../../../../images/ico_edit.gif"></a>
				<a href="../widgets/del_widget_85.inc.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&act=del&id='.$linkid.'">
				<img src="../../../../images/ico_close.gif">
				</a>';
		$inc++;
	}
	echo '</div>';
		
	echo '
		<div class="widget_options">
		'.lg("add_favorit").' :<br><br>
		<form method="post" action="../widgets/scr_widget_85.inc.php?tab='.$selectedTab.'&act=add">
			<input type="hidden" name="id" value="'.$id.'">
			<input type="hidden" name="uniq" value="'.$uniq.'">
            <input type="hidden" name="mod_id" value="'.$mod_id.'" />
			<table cellpadding=0>
				<tr>
				<td>'.lg("title").' </td>
				<td><input type="text" name="titre" /></td>
				</tr>
				<tr>
				<td>'.lg('url').' </td>
				<td><input type="text" name="url" value="http://" /></td>
				</tr>
				<tr>
				<td>'.lg("tags").' </td>
				<td><input type="text" name="tag" /></td>
				</tr>
				<tr>
				<td></td>
				<td><input type="submit" value="'.lg("add").'" /></td>
				</tr>
			</table>
		</form>
		</div>';

	if ($page!=0) {
		echo ' <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&linkpage'.$id.'='.($page-1).'#favorites"><img src="../../../../images/ico_next2.gif" /> '.lg('previous').'</a>';
	}
	if($nbFav==6) {
		echo ' <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&linkpage'.$id.'='.($page+1).'#favorites">'.lg('next').' <img src="../../../../images/ico_next2.gif" /></a>';
	}
}

?>