<?php require_once('Connections/islsigns_web.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.

if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
$msg = "";
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_GET['a']) && ($_GET['a'] == "failed")){
	$msg = "Login Failed. Incorrect username or password.";
	
	
}
if (isset($_POST['name'])) {
  if (preg_match('/^[A-Za-z0-9][A-Za-z0-9 ]+/', $_POST['name'])){
	  $loginUsername=$_POST['name'];
  }else{
	  $errorName = "Invalid Username";
  }
  if (preg_match('/^[A-Za-z0-9][A-Za-z0-9 ]+/', $_POST['pass'])){
	  $password=sha1($_POST['pass']);
  }else{
	  $errorPass = "Invalid Password";
  }
  $MM_fldUserAuthorization = "auth";
  $MM_redirectLoginSuccess = "isl_admin1/search1.php";
  $MM_redirectLoginFailed = "isl_login.php?a=failed";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_islsigns_web, $islsigns_web);
  	
  $LoginRS__query=sprintf("SELECT rep, name, auth, phone, cell FROM sr_isl WHERE name='$loginUsername' AND pass='$password' UNION SELECT rep, name, auth, phone, cell FROM sr_reps WHERE name='$loginUsername' AND pass='$password' UNION SELECT rep, name, auth, phone, cell FROM sr_salesReps WHERE name='$loginUsername' AND pass='$password'"); 
	   
   
  $LoginRS = mysql_query($LoginRS__query, $islsigns_web) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
	  
		$loginRepName = mysql_result($LoginRS,0,'rep');
		$loginStrGroup  = mysql_result($LoginRS,0,'auth');
		$loginRepPhone = mysql_result($LoginRS,0,'phone');
		$loginRepCell = mysql_result($LoginRS,0,'cell');
		 
		$_SESSION['rep'] = $loginRepName;
		$_SESSION['curRep'] = $loginRepName;
		$_SESSION['MM_Username'] = $loginUsername;
		$_SESSION['MM_UserGroup'] = $loginStrGroup;     
		$_SESSION['salesRepPhone'] = $loginRepPhone;
		$_SESSION['salesRepCell'] = $loginRepCell;
		
		if (isset($_SESSION['PrevUrl']) && false) {
		  $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
		}
		header("Location: " . $MM_redirectLoginSuccess );
	}else{
		header("Location: ". $MM_redirectLoginFailed );
	}
}
?>
<!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=iso-8859-1" />
<title>ISL Login</title>
<script language="JavaScript" type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// -->
</script>
<link href="css/isl_login.css" rel="stylesheet" type="text/css">
<link href="css/dropdown.css" media="screen" rel="stylesheet" type="text/css" />
<link href="css/default.advanced.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body onLoad="MM_preloadImages('isl_images/btn_home_o.jpg','isl_images/btn_sign_o.jpg','isl_images/btn_graphics_o.jpg','isl_images/btn_embroidery_o.jpg','isl_images/btn_printing_o.jpg','isl_images/btn_contact_o.jpg'); document.form1.name.focus()">
<div id="page">
	<div id="header">
		<div id="fss">FULL SERVICE SIGNS</div>
		<div id="header_bg1"><img src="isl_images/header_bg1.png" width="850" height="45"></div>
		<div id="phone"><img src="isl_images/877-597-4461.png" width="236" height="38"></div>
		<div id="navBar"><img src="isl_images/btn_bar.jpg" width="175" height="26"></div>
		<div id="logo"><img src="isl_images/logo_glow.png" width="250" height="202" alt="International Signs &amp; Lighting"></div>
		<div id="factory"><img src="isl_images/factorydirectDS.png" width="114" height="77" alt="Factory Direct"></div>
		<div id="ul"><img src="isl_images/ul_white.png" width="44" height="46"></div>
		<div id="homeLink"><a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('homeLink','isl_images/btn_home.jpg','isl_images/btn_home_o.jpg',1)"><img src="isl_images/btn_home.jpg" alt="Home" name="homeLink" width="88" height="26" border="0" id="homeLink2" /></a></div>
		<div id="signLink"><a href="signs.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('signLink','isl_images/btn_sign.jpg','isl_images/btn_sign_o.jpg',1)"><img src="isl_images/btn_sign.jpg" alt="Signs" name="signLink" width="91" height="26" border="0" id="signLink2" /></a></div>
		<div id="graphicsLink"><a href="graphics.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('graphicsLink','isl_images/btn_graphics.jpg','isl_images/btn_graphics_o.jpg',1)"><img src="isl_images/btn_graphics.jpg" alt="Graphics" name="graphicsLink" width="123" height="26" border="0" id="graphicsLink2" /></a></div>
		<div id="embroideryLink"><img src="isl_images//btn_printing.jpg" name="embroideryLink" width="143" height="26" border="0" id="embroideryLink2" /></div>
		<div id="screenLink"><img src="isl_images/btn_printing.jpg" alt="Screen Printing" name="screenLink" width="179" height="26" border="0" id="screenLink2" /></div>
		<div id="contactLink"><a href="contact.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contactLink','isl_images/btn_contact.jpg','isl_images/btn_contact_o.jpg',1)"><img src="isl_images/btn_contact.jpg" alt="Contact" name="contactLink" width="101" height="26" border="0" id="contactLink2" /></a></div>
		<div id="header_bg2"><img src="isl_images/header_bg2.png" width="10" height="45"></div>
	</div>
	<div id="pageBg">
		<div id="round_r"><img src="isl_images/cnr_r_7px.png" width="16" height="200"></div>
		<div id="round_br"><img src="isl_images/cnr_br_7px.png" width="16" height="20"></div>
		<div id="round_bl"><img src="isl_images/cnr_bl_7px.png" width="16" height="20"></div>
		<div id="round_tl"><img src="isl_images/cnr_tl_7px.png" width="16" height="8"></div>
		<div id="round_btm"><img src="isl_images/cnr_b_7px.png" width="500" height="20"></div>
    <div id="round_tr"><img src="isl_images/cnr_tr_7px.png" width="16" height="8"></div>
		<div id="round_l"><img src="isl_images/cnr_l_7px.png" width="16" height="200"></div>
	  <div id="pg_title">ISL Login</div>
		<div id="pg_txt">
			<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
               <table width="480" height="82" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td height="18" colspan="2" align="center"><?php if (strlen($msg) > 1){ echo '<span style="color:#F00">'.$msg.'</span>'; } ?></td>
                 </tr>
                <tr>
                    <td width="167" height="32" align="right"><span class="sm_bold">USERNAME :</span></td>
                    <td width="279">
                        <input name="name" type="text" id="name" size="20" maxlength="20" /><?php if (strlen($errorName) > 1){ echo '<span style="color:#F00">'.$errorName.'</span>'; } ?>
                    </td>
                    </tr>
                <tr>
                    <td height="32" align="right"><span class="sm_bold">PASSWORD
                    :</span></td>
                    <td>
                        <input name="pass" type="password" id="pass" size="20" maxlength="20" /><?php if (strlen($errorPass) > 1){ echo '<span style="color:#F00">'.$errorPass.'</span>'; } ?>
                    </td>
                    </tr>
                </table>
               <p class="sm_bold" align="center">
                    <input type="submit" name="submit" id="submit" value="Submit" />
              </p>
          </form>
		</div>
	</div>
<div id="footer_links">| <a href="index.html">Home</a> | <a href="signs.html">Signs</a> |<a href="graphics.html"> Graphics</a> | <a href="contact.html">Contact</a> |</div>
	<div id="cr">Copyright &copy; 2010 International Signs &amp; Lighting</div>
</div>
</body>
</html>
