<?php 
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# 
#		Add a Contact in adressbook
# 
# ***************************************

$not_access=1;
$granted="I";

require_once('../scripts/includes_mobile.php');
 
$id = isset($_POST['id'])?$_POST['id']:0;
$nom = isset($_POST['lastname'])?$_POST['lastname']:"";
$prenom = isset($_POST['firstname'])?$_POST['firstname']:"";
$mail = isset($_POST['email'])?$_POST['email']:"";
$entreprise = isset($_POST['company'])?$_POST['company']:"";
$fonction = isset($_POST['function'])?$_POST['function']:"";
$tel1 = isset($_POST['tel1'])?$_POST['tel1']:0;
$tel2 = isset($_POST['tel2'])?$_POST['tel2']:0;
$autre = isset($_POST['other'])?$_POST['other']:"";
$tag = isset($_POST['tags'])?$_POST['tags']:"";
$mod_id = $_POST['mod_id'];
$tab = $_REQUEST['tab'];
$uniq = $_POST['uniq'];
$act=$_REQUEST['act'];

if (empty($nom) or empty($prenom)) {
    header("location:../scripts/display_widget.php?mod_id=".$mod_id."&tab=".$tab);
    exit();
}

if($act=="add") {
	if(empty($id)) {
		$sharedMD5 = md5(uniqid(rand(), true));
		$DB->execute($widAddr_createNewId, $DB->escape($_SESSION['user_id']), $DB->quote($sharedMD5));
		$id = $DB->getId();
		$DB->execute($updModule,$DB->quote("addid=".$id),$DB->escape($_SESSION['user_id']), $DB->escape($uniq));
	}
	$DB->execute($widAddr_addNewContact, $DB->escape($id), $DB->quote($prenom), $DB->quote($nom), $DB->quote($mail), $DB->quote($entreprise), $DB->quote($fonction), $DB->noHTML($tel1), $DB->noHTML($tel2), $DB->quote($autre), $DB->quote($tag));
}
else {
	$DB->execute($widAddr_updateContact, $DB->quote($prenom), $DB->quote($nom), $DB->quote($mail), $DB->quote($entreprise), $DB->quote($fonction), $DB->noHTML($tel1), $DB->noHTML($tel2), $DB->quote($autre), $DB->quote($tag),$DB->escape($id),$DB->escape($_SESSION["user_id"]));
}

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