<?php 
include_once 'CheckLogOut.php';
require_once 'Connection.php';
require_once 'ContactPhone.php';
// para atualizar a lista
require_once 'User.php';
require_once 'CacheArquivo.php';
////////////////////////////
require_once 'Log.php';
$con = new Connection();
$c = new ContactPhone();
$c->ContactId($_GET['contactId']);
$c->Sequential($_GET['sequential']);
$c->DeleteContactPhone();
// para atualizar a lista
$u = new User();
$cacheArquivo = new CacheArquivo();
$cacheArquivo->set_valor($UsId);
$Contacts = $u->GetAllContacts($USERID);
$valor = json_encode($Contacts);
$cacheArquivo->set_valor($USERID, $valor);
////////////////////////////
$Log = new Log(3);
// log de deleção, conforme a tabela Actions
$Log->UserId($USERID);
//
$Log->InsertLog();
echo '<html>';
echo '<script language="JavaScript">';
echo 'window.location="Main.php"';
echo '</script>';
$contact->UpdateContact();
$contactPhoneMessage = "";
$contactAdressMessage = "";
echo $USERID;
$Log = new Log(2);
// log de update, conforme a tabela Actions
$Log->UserId($USERID);
//
$Log->InsertLog();
// Telefone
if (isset($_GET['phoneNumber']) && $_GET['phoneNumber'] != '') {
    if (isset($_GET['cpSeq']) && $_GET['cpSeq'] != '') {
        // update phone
        $contactPhone = new ContactPhone($_GET['phoneType'], $_GET['countryId'], $_GET['ddd'], $_GET['phoneNumber']);
        $contactPhone->ContactId($_GET['contactId']);
        $contactPhone->Sequential($_GET['cpSeq']);
        $contactPhone->UpdateContactPhone();
        $contactPhoneMessage = "Telefone " . $_GET['phoneNumber'] . " editado!";
        $Log2 = new Log(2);
        // log de update, conforme a tabela Actions
        $Log2->UserId($USERID);
        //
        $Log2->InsertLog();
    } else {
        // insert phone
        $contactPhone = new ContactPhone($_GET['phoneType'], $_GET['countryId'], $_GET['ddd'], $_GET['phoneNumber']);
        $contactPhone->ContactId($_GET['contactId']);
        $contactPhone->InsertContactPhone();
        $contactPhoneMessage = "Telefone " . $_GET['phoneNumber'] . " inserido!";
        $Log2 = new Log(1);
        // log de inserção, conforme a tabela Actions