Jump to content

got myself in a muddle, with too many if-then-else's


dmccabe

Recommended Posts

I have bee writing a script for staff to request new users on our system.

 

However i have done something wrong with the if-then-else's and now I can work out what.

 

Sorry about this being so long, but I really would appreciate it if someone can help me get the logic worked out:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>11.0.1 - New IT user request</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>

</head>
<body id="main_body" >

<div id="main">
<?php 
$ldap_host = "XYZ.com";
$base_dn = "OU=XPZusers, DC=XYZ, DC=com";
$ldapname = $_POST['ldapname']."@XYZ.com";
$ldappass = $_POST['ldappass'];

if (!isset($ldappass)) { ?>
	You must login below with your Windows(Citrix) username and password:
	<form method="POST" action="<?php echo $PHP_SELF; ?>" name="login">
		<table align="center">	
			<tr>
				<td>Username:</td>
				<td><input type="text" name="ldapname"></td>
				<td><a href=".." title="Click for help on this item"><strong>?</strong></td>
			</tr>
			<tr>
				<td>Password:</td>
				<td><input type="password" name="ldappass"></td>
				<td><a href=".." title="Click for help on this item"><strong>?</strong></td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" value="Login" name="submit"></td>
			</tr>
		</table>
	</form>
<?php
} else {

	$connect = ldap_connect( $ldap_host, $ldap_port)
			or exit(">>Could not connect to LDAP server<<");

	//for win2003
	ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);

	//for win2003
	ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);

	$bind = ldap_bind($connect, $ldapname, $ldappass);

	if (!$bind || !$ldappass) {
		echo "Invalid username/password.... try again <br /><FORM><INPUT TYPE='button' VALUE='Go Back' onClick='history.go(-1);return true;'> </FORM>";
		unset($ldappass);
	} else {
		include($rootdir.'XPZconnect.php');
		if (isset($_POST['company'])) {

			$request_by = mysql_real_escape_string($_SESSION['ldapname']);
			$company = mysql_real_escape_string($_POST['company']);
			$first_name = mysql_real_escape_string($_POST['first_name']);
			$initial = mysql_real_escape_string($_POST['initial']);
			$surname = mysql_real_escape_string($_POST['surname']);
			$location = mysql_real_escape_string($_POST['location']);
			$job_title = mysql_real_escape_string($_POST['job_title']);
			$start_date = mysql_real_escape_string($_POST['start_date']);
			$email = mysql_real_escape_string($_POST['email']);
			$prohire = mysql_real_escape_string($_POST['prohire']);
			$prolease = mysql_real_escape_string($_POST['prolease']);
			$proclaim = mysql_real_escape_string($_POST['proclaim']);
			$sage = mysql_real_escape_string($_POST['sage']);
			$internet = mysql_real_escape_string($_POST['internet']);
			$other = mysql_real_escape_string($_POST['other']);
			$other_software = mysql_real_escape_string($_POST['other_software']);
			$internet_reason = mysql_real_escape_string($_POST['internet_reason']);
			$mailing_lists = mysql_real_escape_string($_POST['mailing_lists']);
			$other_reqs = mysql_real_escape_string($_POST['other_reqs']);
			$requested_date = date("d/m/y");  
			if (($internet == full && !$internet_reason) || ($other && !$other_software) || !$first_name || !$surname || !$location || !$mailing_lists) {
				echo "You have made an error!<br />
					Please click back and check the following:<br />
					<ul>
						<li>First name must be completed</li>
						<li>Surname must be completed</li>
						<li>Location/Department must be completed</li>
						<li>Mailing lists must be completed</li>
						<li>If you selected Full Internet Access, then you must give a reason for the request</li>
						<li>If you selected Other Software, then you must specify the software required</li>
					</ul><br />
						<FORM><INPUT TYPE='button' VALUE='Go Back' onClick='history.go(-1);return true;'> </FORM>";
			} else { 
					$insert = "INSERT INTO `tbl_newsusers` (`nuid`,`first_name`,`initial`,`surname`,`company`,`location`,`job_title`,
							`start_date`,`prohire`,`prolease`,`proclaim`,`sage`,`email`,`other`,`other_software`,`internet`,
							`internet_reason`,`mailing_lists`,`other_reqs`,`requested_by`,`requested_date`)
							VALUES (NULL,'$first_name','$initial','$surname','$company','$location','$job_title',
							'$start_date','$prohire','$prolease','$proclaim','$sage','$email','$other','$other_software','$internet',
							'$internet_reason','$mailing_lists','$other_reqs','$requested_by','$requested_date')";
					if (!mysql_query($insert)) {
						die('Error: ' . mysql_error());
					} else {
						$email = "[email protected]";
						$message = "Username: $fist_name \n Surname: $surname";
						mail("[email protected]","New User Request: $first_name $surname", $message, "From: $email");
						echo "Your new user has been requested.  You will receive an e-mail shortly confirming this request<br />
							Once your user is set up then you will receive a further e-mail with the users login details.<br />
							Thank you! - XPZ IT Team - 0113 387 5518 / <a href='mailto:[email protected]'>[email protected]</a>";
					}
				} 
		} else { ?>


			<img id="top" src="top.png" alt="">
			<div id="form_container">

			<h1><a>Untitled Form</a></h1>
			<form id="new_user" class="appnitro"  method="post" action="<?php echo $PHP_SELF; ?>">
				<div class="form_description">
					<h2>11.0.1 - New IT user request</h2>
					<p>Please use this form to request a new user be created on the network.</p>
				</div>						
				<ul >
					<li id="li_1" >
						<label class="description" for="element_1">First Name </label>
						<div>
							<input id="element_1" name="first_name" class="element text medium" type="text" maxlength="255" value=""/> 
						</div>
						<p class="guidelines" id="guide_1"><small>Enter the users first name</small></p> 
					</li>

					<li id="li_2" >
						<label class="description" for="element_2">Initial </label>
						<div>
							<input id="element_2" name="initial" class="element text small" type="text" maxlength="255" value=""/> 
						</div>
						<p class="guidelines" id="guide_2"><small>Enter the users middle initial(s)</small></p> 
					</li>

					<li id="li_3" >
						<label class="description" for="element_3">Surname </label>
						<div>
							<input id="element_3" name="surname" class="element text medium" type="text" maxlength="255" value=""/> 
						</div>
						<p class="guidelines" id="guide_3"><small>Enter the users surname.</small></p> 
					</li>

					<li id="li_10" >
						<label class="description" for="element_10">Which company will the user be working for? </label>
						<span>
							<input id="element_10_1" name="company" class="element radio" type="radio" value="XPZ" />
							<label class="choice" for="element_10_1">XPZ</label>
							<input id="element_10_2" name="company" class="element radio" type="radio" value="XPZ_contracts" />
							<label class="choice" for="element_10_2">XPZ Contracts</label>
							<input id="element_10_3" name="company" class="element radio" type="radio" value="XYZ_acc_man" />
							<label class="choice" for="element_10_3">XYZ Accident Management</label>
						</span> 
					</li>

					<li id="li_4" >
						<label class="description" for="element_4">Which department/location will the user work in? </label>
						<div>
							<input id="element_4" name="location" class="element text medium" type="text" maxlength="255" value=""/> 	
						</div>
						<p class="guidelines" id="guide_4"><small>Specify the department or branch the user will be working for.  Eg: Birmingham branch / Credit Control Dept</small></p> 
					</li>

					<li id="li_9" >
						<label class="description" for="element_9">Job Title </label>
						<div>
							<input id="element_9" name="job_title" class="element text medium" type="text" maxlength="255" value=""/> 
						</div>
						<p class="guidelines" id="guide_9"><small>Enter the users job title. e.g. Rental Agent</small></p> 
					</li>

					<li id="li_13" >
						<label class="description" for="element_13">Start Date</label>
						<div>
							<input id="element_13" name="start_date" class="element text medium" type="text" maxlength="255" value=""/> 
						</div>
						<p class="guidelines" id="guide_13"><small>Enter the users start date in dd/mm/yy format. eg: 01/02/08</small></p> 
					</li>

					<li id="li_11" >
						<label class="description" for="element_11">What software will the user need access to? </label>
						<span>
							<input id="element_11_1" name="prohire" class="element checkbox" type="checkbox" value="1" />
							<label class="choice" for="element_11_1">Prohire</label>
							<input id="element_11_2" name="prolease" class="element checkbox" type="checkbox" value="1" />
							<label class="choice" for="element_11_2">ProLease</label>
							<input id="element_11_3" name="proclaim" class="element checkbox" type="checkbox" value="1" />
							<label class="choice" for="element_11_3">ProClaim</label>
							<input id="element_11_4" name="sage" class="element checkbox" type="checkbox" value="1" />
							<label class="choice" for="element_11_4">Sage</label>
							<input id="element_11_5" name="email" class="element checkbox" type="checkbox" value="1" />
							<label class="choice" for="element_11_5">Email</label>
							<input id="element_11_6" name="other" class="element checkbox" type="checkbox" value="1" />
							<label class="choice" for="element_11_6">Other (please specify below)</label>
						</span>
						<p class="guidelines" id="guide_11"><small>Pick one or more of the software items that the user will need access to.</small></p> 
					</li>

					<li id="li_5" >
						<label class="description" for="element_5">Other Software </label>
						<div>
							<textarea id="element_5" name="other_software" class="element textarea medium"></textarea> 
						</div> 
					</li>

					<li id="li_12" >
						<label class="description" for="element_12">What lever of internet access does the user need? </label>
						<span>
							<input id="element_12_1" name="internet" class="element radio" type="radio" value="whitelist" />
							<label class="choice" for="element_12_1">White List Only</label>
							<input id="element_12_2" name="internet" class="element radio" type="radio" value="full" />
							<label class="choice" for="element_12_2">Full (Please give reason below)</label>
						</span>
						<p class="guidelines" id="guide_12"><small>Whitelisted means access only to sites specified on the companies "allowed" list.
																	Full is access to everything. Please note full access is still monitored and logged.</small></p> 
					</li>

					<li id="li_6" >
						<label class="description" for="element_6">Full Internet Reason </label>
						<div>
							<textarea id="element_6" name="internet_reason" class="element textarea medium"></textarea> 
						</div> 
					</li>

					<li id="li_7" >
						<label class="description" for="element_7">Specify which mailing lists the user needs to be included on. </label>
						<div>
							<textarea id="element_7" name="mailing_lists" class="element textarea medium"></textarea> 
						</div>
						<p class="guidelines" id="guide_7"><small>e.g. [email protected]</small></p> 
					</li>

					<li id="li_8" >
						<label class="description" for="element_8">Other requirements </label>
						<div>
							<textarea id="element_8" name="other_reqs" class="element textarea medium"></textarea> 
						</div>
						<p class="guidelines" id="guide_8"><small>Use this field to specify anything that isnt covered in this form.</small></p> 
					</li>

					<li class="buttons">
						<input type="hidden" name="form_id" value="58659" />
					    
						<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
					</li>
				</ul>
			</form>	
		</div>
			<img id="bottom" src="bottom.png" alt="">

	<?php 
			}
		} 
}	?>
	</body>
</html>

 

This is what should happen

 

1 - user authenticates against our LDAP server (WORKS)

2a - if authentication is successful, then they are shown the form

2b - if not successful they are asked to login again

3 - User fills in form

4a - if all is well, then they are given a message and the system sends an email to our helpdesk

4b - if not successful then they are told what fields to check and click back to try again.

 

All is working until step 4a/4b, instead of the email being sent or them getting the error message, instead they are sent back to the login screen again.

 

Very confused... please help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.