<?php

$admin = 'contact'; 
include ($PATH . 'globals/globals.php');
$adminAct = $_REQUEST['adminAct']; 

$fieldArray = array('contactID','lastname','firstname','company','title','email','phone_office','phone_mobile','fax','website','address1','address2','PObox','city','state','zip','contact_source','last_contact','last_contact_campaign','notes','isClient','date_added','date_updated','display');
$excludeArray = array('last_contact','date_added','date_updated');

if ($adminAct == 'new') {
		
	$op = 'add';
	$editInpID = '<input type="hidden" name="op" value="'. $op .'" />'; 
	foreach($fieldArray as $value) { 
		if ($value == 'display')
			$$value = 1;
		elseif (($value == 'date_added')||($value == 'date_updated'))
			$$value = $today;
		else 	
			$$value = '';
	}
	$marketing_contactsubCompany = getCompany($subClient,$con);
	$subBtn = 'Add Contact'; 
	$modalTitle = 'Create New Contact';
} else {
	$op = '';
	$editID = $_REQUEST['editID']; 
	$editInpID = '<input type="hidden" name="contactID" value="'. $editID .'" />';
		
	$query = 'SELECT * FROM marketing_contacts WHERE contactID=' . $editID; 
	$result = $con->query($query);
		
	while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
		foreach($fieldArray as $value) { 
			if ($value == 'date_updated')
				$$value = $today;
			else
				$$value = $row[''. $value .''];
		}
		if ($adminAct == 'react') {
			$op = 'react';
			$delConfirm = "";
			$subBtn = 'Reactivate Contact';
			$modalTitle = 'Reactivate Contact: '. $clientName;
		} elseif ($adminAct == 'edit') {
			$op = 'edit';
			$delConfirm = ""; 
			$subBtn = 'Save Changes';
			$modalTitle = 'Edit Contact: '. $clientName;
		} elseif ($adminAct == 'delete') {
			$op = 'delete';
			$delConfirm = ' onSubmit="return sure()"';
			$subBtn = 'Deactivate Contact';
			$modalTitle = 'Delete Contact: '. $clientName . '?';
		}
	}
}
$sources = get_sources($contact_source,$con);
$campaigns = get_campaigns($last_contact_campaign,$con);
	
include('form/contact.php');

?>