<?php

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

$adminAct = $_REQUEST['adminAct']; 

$variables = getVariables('loginfo',$page);

$admin = 'loginfo'; 

$FROM = $_SERVER['HTTP_REFERER']; 
if (strpos($FROM,'admin/client.php')) {
	$query = 'SELECT infoID FROM loginfo WHERE clientID='. $_REQUEST['cID'];
	$result = $con->query($query);
	$editID = $row['infoID'];
	if (empty($editID)) 
		$adminAct = 'new';
	else 
		$adminAct = 'edit';
}
	
if ($adminAct == 'new') {
	$op = 'add';
	$editInpID = '<input type="hidden" name="op" value="'. $op .'" />'; 
	foreach($variables['fieldArray'] as $value) { 
		if ($value == 'display')
			$$value = 1;
		elseif ($value == 'compID')
			$client = '';
		elseif ($value == 'projectID')
			$project = ''; 
		else 	
			$$value = '';
	}
	$subBtn = 'Add Loginfo'; 
	$modalTitle = 'Create New Loginfo';
} else {
	$op = '';
	if (empty($editID))
		$editID = $_REQUEST['editID']; 
	$editInpID = '<input type="hidden" name="infoID" value="'. $editID .'" />';
	
	$query = 'SELECT * FROM loginfo WHERE infoID=' . $editID; 
	$result = $con->query($query);
	
	while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
		$client = $row['clientID'];
		$project = $row['projectID'];
		foreach($variables['fieldArray'] as $value) 
			$$value =  $row[''. $value .''];
	}
	
	if ($adminAct == 'react') {
		$op = 'react';
		$delConfirm = ""; 
		$subBtn = 'Reactivate Info';
		$modalTitle = 'Reactivate Login Info: '. $projectName;
	} elseif ($adminAct == 'edit') {
		$op = 'edit';
		$delConfirm = ""; 
		$subBtn = 'Save Changes';
		$modalTitle = 'Edit Login Info: '. $projectName;
	} elseif ($adminAct == 'delete') {
		$op = 'delete';
		$display = 0;
		$delConfirm = ' onSubmit="return sure()"';
		$subBtn = 'Delete Info';
		$modalTitle = 'Delete Login Info: '. $projectName . '?';
	}
}
$LoginfoClient = getCompany($client,$con);

$projFilter = (($op=='add') ? '1,4' : ''); 	
$LoginfoProject = getProjectLists($project,$projFilter,$con);
	
include('form/loginfo.php');

?>