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

$addid = parser($variables, 'addid=');
$page = isset($_GET["addrpage".$addid])     ?     ($_GET["addrpage".$addid])      :        0;
$pageStart = $page*5;

if(isset($_GET['addid'])) {
	$addid = $_GET['addid'];
}
if (isset($_GET["taskact".$addid])) {
	switch($_GET["taskact".$addid]) {
		case 'upd':
			$DB->getResults($widAddress_getContact, $DB->escape($_GET["mid"]),$DB->escape($_SESSION["user_id"]));
			$row = $DB->fetch(0);

			echo'<a name="contact"></a>
				<div class="widget_options">
				<form method="post" action="../widgets/scr_widget_401.inc.php?act=upd&tab='.$selectedTab.'&addid='.$addid.'">
					<input type="hidden" name="id" value="'.$_GET["mid"].'">
					<input type="hidden" name="uniq" value="'.$uniq.'">
                    <input type="hidden" name="mod_id" value="'.$mod_id.'" />
					<table cellpadding="0">
						<tr>
						<td>'.lg("lastname").' </td>
						<td><input type="text" name="lastname" value="'.$row['lastname'].'"/></td>
						</tr>
						<tr>
						<td>'.lg("firstname").' </td>
						<td><input type="text" name="firstname" value="'.$row['firstname'].'"/></td>
						</tr>
						<tr>
						<td>'.lg("email").' </td>
						<td><input type="text" name="email" value="'.$row['email'].'"/></td>
						</tr>
						<tr>
						<td>'.lg("enterprise").' </td>
						<td><input type="text" name="company" value="'.$row['company'].'"/></td>
						</tr>
						<tr>
						<td>'.lg("function").' </td>
						<td><input type="text" name="function" value="'.$row['func'].'"/></td>
						</tr>
						<tr>
						<td>'.lg('phone').'1 </td>
						<td><input type="text" name="tel1" value="'.$row['phone1'].'"/></td>
						</tr>
						<tr>
						<td>'.lg('phone').'2 </td>
						<td><input type="text" name="tel2" value="'.$row['phone2'].'"/></td>
						</tr>
						<tr>
						<td>'.lg("other").' </td>
						<td><input type="text" name="other" value="'.$row['other'].'"/></td>
						</tr>
						<tr>
						<td>'.lg('tags').' </td>
						<td><input type="text" name="tags" value="'.$row['tags'].'"/></td>
						</tr>
						<tr>
						<td></td>
						<td><input type="submit" value="'.lg('ok').'"> <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'#contact">'.lg('cancel').'</a></td>
						</tr>
					</table>
				</form>
				</div>';
			$DB->freeResults();
			break;
		case 'add':
			echo'<a name="contact"></a>
				<div class="widget_options">
				'.lg("add_con").' :
				<form method="post" action="../widgets/scr_widget_401.inc.php?act=add&tab='.$selectedTab.'">
					<input type="hidden" name="id" value="'.$addid.'">
					<input type="hidden" name="uniq" value="'.$uniq.'">
                    <input type="hidden" name="mod_id" value="'.$mod_id.'" />
					<table cellpadding="0">
						<tr>
						<td>'.lg("lastname").' </td>
						<td><input type="text" name="lastname" /></td>
						</tr>
						<tr>
						<td>'.lg("firstname").' </td>
						<td><input type="text" name="firstname" /></td>
						</tr>
						<tr>
						<td>'.lg("email").' </td>
						<td><input type="text" name="email"/></td>
						</tr>
						<tr>
						<td>'.lg("enterprise").' </td>
						<td><input type="text" name="company" /></td>
						</tr>
						<tr>
						<td>'.lg("function").' </td>
						<td><input type="text" name="function" /></td>
						</tr>
						<tr>
						<td>'.lg('phone').'1 </td>
						<td><input type="text" name="tel1" /></td>
						</tr>
						<tr>
						<td>'.lg('phone').'2 </td>
						<td><input type="text" name="tel2"/></td>
						</tr>
						<tr>
						<td>'.lg("other").' </td>
						<td><input type="text" name="other"/></td>
						</tr>
						<tr>
						<td>'.lg('tags').' </td>
						<td><input type="text" name="tags" /></td>
						</tr>
						<tr>
						<td></td>
						<td><input type="submit" value="'.lg("add").'"> <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'#contact">'.lg('cancel').'</a></td>
						</tr>
					</table>
				</form>
				</div>';
			break;
		case 'detail':
				$DB->getResults($widAddress_getContact2, $DB->escape($addid),$DB->escape($_SESSION['user_id']));
				$row = $DB->fetch(0);
				echo'<a name="contact"></a>
					<div class="widget">
					'.lg("lastname").' : '.$row['lastname'].'<br>
					'.lg("firstname").' : '.$row['firstname'].'<br>
					mail : '.$row['email'].'<br>
					'.lg("enterprise").' : '.$row['company'].'<br>
					'.lg("function").' :  '.$row['func'].'<br>
					'.lg('phone').'1 : '.$row['phone1'].'<br>
					'.lg('phone').'2 : '.$row['phone2'].'<br>
					'.lg("other").' : '.$row['other'].'<br>
					'.lg('tags').' :'.$row['tags'].'<br>
					<a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'#contact">OK</a>
					<a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&addid='.$addid.'&mid='.$row['add_id'].'&taskact'.$addid.'=upd#contact">'.lg("modif").'</a>
					</div>';
			break;
	}
}
else {
	$DB->getResults($widAddress_getContacts, $DB->escape($addid),$DB->escape($_SESSION['user_id']),$DB->escape($pageStart));
	$nbAddr = $DB->nbResults();
	$inc=0;
	echo '<a name="contact"></a>
		<div class="widget">';
	while (($row = $DB->fetch(0)) && $inc<5) {
		$id=$row['add_id'];
		echo '<a name="contact"></a>
			<div class="widget">
			<a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&addid='.$id.'&taskact'.$id.'=detail">'.$row['lastname'].', '.$row['firstname'].'</a>
			<a href="../widgets/del_widget_401.inc.php?mod_id='.$mod_id.'&tab='.$selectedTab.'act=del&id='.$id.'"><img src="../../../../images/ico_suppress.gif"></a>
			</div>';
		$inc++;
	}
	echo '</div>';

	echo'
		<div class="widget_options">
			<a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&taskact'.$addid.'=add#contact">+ '.lg("add_con").'</a>
		</div>';
	
	if ($page!=0) {
		echo ' <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&addrpage'.$addid.'='.($page-1).'#contact"><img src="../../../../images/ico_next2.gif" /> '.lg('previous').'</a>';
	}
	if($nbAddr==6) {
		echo ' <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&addrpage'.$addid.'='.($page+1).'#contact">'.lg('next').' <img src="../../../../images/ico_next2.gif" /></a>';
	}
}

?>