<?php

$admin = 'service'; 

include ($PATH . '/globals/globals.php');

$adminAct = $_REQUEST['adminAct']; 

$fieldArray = array('svcID','domainName','compID','svcType','svcProvider','svcBeginDate','svcExpDate','svcOwner','svcNotes','dateAdded','display');
$sanitizeExclude = array(); 
/*
if (!empty($_POST['op'])) {

	$op = $_POST['op'];
	$content = '<h2>Service Information has been Successfully';
	
	$fieldString = '';
	$valueString = '';
	
	if ($_POST['op'] == 'delete') {
		$fieldString .= 'svcID,display'; 
		$valueString .= $_POST['svcID'].',0';
	} 
	else {
		foreach($_POST as $key => $value) {
			if (in_array($key,$fieldArray)) {
				if ($key == 'compID')
					$key = 'clientID';
				elseif (($key == 'svcProvider') && ($value == "NEW")) {
					$newProdierName = '';
					if ((!empty($_POST['newProviderName'])) && ($_POST['newProviderName'] != 'Service Provider Name'))
						$newProdierName = $_POST['newProviderName'];
					$newProdierWebisite = '';
					if ((!empty($_POST['newProdierWebisite'])) && ($_POST['newProdierWebisite'] != 'Service Provider Website'))
						$newProdierWebisite = $_POST['newProdierWebisite'];
					$query = "INSERT INTO serviceProviders (spName,spWebsite,dateAdded,display) VALUES ('". $newProdierName ."','". $newProdierWebisite ."','". date("Y-m-d H:i:s") ."',1)";
					$result = mysql_query ($query) or die('Invalid New Provider query: ' . mysql_error());
					$value = mysql_insert_id();
				}
				$fieldString .= $key .',';
				$valueString .= '"'. nice_addslashes($value) .'",';
			}
		}
		// Remove Last comma from string to avoid mySQL errors
		$fieldString = substr($fieldString,0,strlen($fieldString)-1);
		$valueString = substr($valueString,0,strlen($valueString)-1);
	}
	$query = 'REPLACE INTO serviceInfo ('. $fieldString .') VALUES ('. $valueString .')';
	//echo $query;
	//exit;
	$result = mysql_query ($query) or die('Invalid Loginfo '. $op .' query: ' . mysql_error());
	
	if ($result) {
		echo '<script type="text/javascript">
				parent.location.reload();
				parent.Shadowbox.close();
			</script>';
	}
}
else {
*/	
if ($adminAct == 'new') {
	$op = 'add';
	$editInpID = '<input type="hidden" name="op" value="'. $op .'" />'; 
	foreach($fieldArray as $value) { 
		if ($value == 'display')
			$$value = 1;
		elseif ($value == 'compID')
			$client = '';
		else 	
			$$value = '';
	}
	$subBtn = 'Add Service Info'; 
	$modalTitle = 'Add New Service Info';
} else {
	$op = '';
	if (empty($editID))
		$editID = $_REQUEST['editID']; 
	$editInpID = '<input type="hidden" name="svcID" value="'. $editID .'" />';
		
	$query = 'SELECT * FROM serviceInfo WHERE svcID=' . $editID; 
	$result = $con->query($query);
		
	while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
		$client = $row['clientID'];
		$project = $row['projectID'];
		foreach($fieldArray as $value) 
			$$value =  $row[''. $value .''];
		if ($adminAct == 'react') {
			$op = 'react';
			$delConfirm = "";
			$subBtn = 'Reactivate Service';
			$modalTitle = 'Reactivate Service Information';
		} elseif ($adminAct == 'edit') {
			$op = 'edit';
			$delConfirm = ""; 
			$subBtn = 'Save Changes';
			$modalTitle = 'Edit Service Information';
		} elseif ($adminAct == 'delete') {
			$op = 'delete';
			$delConfirm = ' onSubmit="return sure()"';
			$subBtn = 'Deactivate Service';
			$modalTitle = 'Delete Service Information?';
			$display = '0'; 
		}
	}
}
$servideInfoClient = getCompany($client,$con);
$serviceTypes = '<option value="">&lt; select &gt;</option>' . getSvcType($svcType,$con);
$serviceProviders = '<option value="">&lt; select &gt;</option><option value="NEW">NEW Provider</option>' . getSvcProvide($svcProvider,$con);
$serviceOwners = getSvcOwner($svcOwner,$con);
	
if ($svcBeginDate == '0000-00-00')
	$svcBeginDate = '';
if ($svcExpDate == '0000-00-00')
	$svcExpDate = ''; 

include('form/service.php'); 

?>