<?php
if (!isset($_SESSION)) {
session_start();//start session
}
$loginFormAction = $_SERVER['PHP_SELF'];//run this script after posting
if (isset($_GET['accesscheck']))
{
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['username']))//if there is a form value entered
{
$loginUsername=$_POST['username'];//assign variables
$MM_fldUserAuthorization = "LEVEL";
$MM_redirectLoginSuccess = "../crmcontacts/updatemycontact.php";//where to go if successful
$MM_redirectLoginFailed = "loginfail.php";//where to go on fail
$MM_redirecttoReferrer = false;
mysql_select_db($database_freecrm, $freecrm);//db connection
$LoginRS__query=sprintf("SELECT USERNAME, PASSWORD, LEVEL, GROUPCODE, USERTZ, USERTF FROM CONTACTS WHERE USERNAME=%s", GetSQLValueString($loginUsername, "text")); //get values from db where username is the post value
$LoginRS = mysql_query($LoginRS__query, $freecrm) or die(mysql_error());//return the query
$loginFoundUser = mysql_num_rows($LoginRS);//count rows
if ($loginFoundUser)//if theres a row
{
$salt = mysql_result($LoginRS,0,'PASSWORD');//gain salt from db
$password = crypt($_POST['password'],$salt);//encrypt posted password
if ($password == $salt)//if posted value equal to db entry
{
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = mysql_result($LoginRS,0,'LEVEL');
//groupcode declaration
$_SESSION['MM_GroupCode'] = mysql_result($LoginRS,0,'GROUPCODE');
//timezone/format preferences
$_SESSION['MM_UTZ'] = mysql_result($LoginRS,0,'USERTZ');
$_SESSION['MM_UTF'] = mysql_result($LoginRS,0,'USERTF');
header("Location: " . $MM_redirectLoginSuccess );//specify re-direct
}
else//if they don't match
{
header("Location: ". $MM_redirectLoginFailed );//specify re-direct
}
}
}
?>