<?php



$auditcontactcheck = new WA_MySQLi_RS("auditcontactcheck",$cmctrfdb,1);

$auditcontactcheck->setQuery("SELECT contacts.idcontacts, contacts.kindofcontacts, contacts.idtrf FROM contacts WHERE contacts.idtrf='$idtrf' and contacts.kindofcontacts='$kindcont'");

$auditcontactcheck->execute();





if (empty($auditcontactcheck->getColumnVal("idcontacts"))) {

	

if(!empty($companyData["idcompany"])) { $companyid=$companyData["idcompany"]; } else { $companyid=""; }

if(!empty($companyData["companyname_company"])) { $companyname=$companyData["companyname_company"]; } else { $companyname=""; }

if(!empty($companyData["piva_company"])) { $companypiva=$companyData["piva_company"]; } else { $companypiva=""; }

if(!empty($companyData["address_company"])) { $companyaddress=$companyData["address_company"]; } else { $companyaddress=""; }

if(!empty($companyData["city_company"])) { $companycity=$companyData["city_company"]; } else { $companycity=""; }

if(!empty($companyData["zip_company"])) { $companycap=$companyData["zip_company"]; } else { $companycap=""; }

if(!empty($companyData["country_company"])) { $companycountry=$companyData["country_company"]; } else { $companycountry=""; }

if(!empty($companyData["telephone_company"])) { $companytelephone=$companyData["telephone_company"]; } else { $companytelephone=""; }

if(!empty($companyData["email_company"])) { $companyemail=$companyData["email_company"]; } else { $companyemail=""; }

if(!empty($companyData["maincontactname_company"])) { $companycontactname=$companyData["maincontactname_company"]; } else { $companycontactname=""; }

if(!empty($companyData["maincontactsurname_company"])) { $companycontactsurname=$companyData["maincontactsurname_company"]; } else { $companycontactsurname=""; }





	

	

  $InsertQuery = new WA_MySQLi_Query($cmctrfdb);

  $InsertQuery->Action = "insert";

  $InsertQuery->Table = "contacts";

  $InsertQuery->bindColumn("kindofcontacts", "s", "$kindcont", "WA_DEFAULT");

  $InsertQuery->bindColumn("companyname", "s", "$companyname", "WA_DEFAULT");

  $InsertQuery->bindColumn("piva", "s", "$companypiva", "WA_DEFAULT");

  $InsertQuery->bindColumn("address", "s", "$companyaddress", "WA_DEFAULT");

  $InsertQuery->bindColumn("city", "s", "$companycity", "WA_DEFAULT");

  $InsertQuery->bindColumn("cap", "s", "$companycap", "WA_DEFAULT");

  $InsertQuery->bindColumn("country", "s", "$companycountry", "WA_DEFAULT");

  $InsertQuery->bindColumn("telephone", "s", "$companytelephone", "WA_DEFAULT");

  $InsertQuery->bindColumn("email", "s", "$companyemail", "WA_DEFAULT");

  $InsertQuery->bindColumn("contactname", "s", "$companycontactname", "WA_DEFAULT");

  $InsertQuery->bindColumn("contactsurname", "s", "$companycontactsurname", "WA_DEFAULT");

  $InsertQuery->bindColumn("idtrf", "i", "$idtrf", "WA_DEFAULT");

	$InsertQuery->bindColumn("companyid", "i", "$companyid", "WA_DEFAULT");

  $InsertQuery->saveInSession("");

  $InsertQuery->execute();

  $InsertGoTo = "";

  if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";

  $InsertQuery->redirect($InsertGoTo);

}



if ($kindcont=="certificatetotest") {

    

      $UpdateQuery = new WA_MySQLi_Query($cmctrfdb);

  $UpdateQuery->Action = "update";

  $UpdateQuery->Table = "`trf-details`";

  $UpdateQuery->bindColumn("certotherclient", "s", "Y", "WA_DEFAULT");

  $UpdateQuery->addFilter("idtrfdetails", "=", "i", "".($idtrf)  ."");

  $UpdateQuery->execute();

  $UpdateGoTo = "";

  if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo?rel2abs($UpdateGoTo,dirname(__FILE__)):"";

  $UpdateQuery->redirect($UpdateGoTo);

    unset($_SESSION['certotherclientsession']);

}

?>	