<?php

/*
osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );

  require('includes/application_top.php');
  if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'process')) {
    $email_address = tep_db_prepare_input($HTTP_POST_VARS['email_address']);
    $password = tep_db_prepare_input($HTTP_POST_VARS['password']);

// Check if email exists
    $check_admin_query = tep_db_query("select admin_id as login_id, admin_groups_id as login_groups_id, admin_firstname as login_firstname, admin_email_address as login_email_address, admin_password as login_password, admin_modified as login_modified, admin_logdate as login_logdate, admin_lognum as login_lognum,encryption_style from " . TABLE_ADMIN . " where admin_email_address = '" . tep_db_input($email_address) . "'");
    if (!tep_db_num_rows($check_admin_query)) { 
      $HTTP_GET_VARS['login'] = 'fail';
    } else {
      $check_admin = tep_db_fetch_array($check_admin_query);
      // Check that password is good
	  
      if (!tep_validate_password($password, $check_admin['login_password'],$check_admin['encryption_style'])) { 
        $HTTP_GET_VARS['login'] = 'fail';
      } else {
        if (tep_session_is_registered('password_forgotten')) {
          tep_session_unregister('password_forgotten');
        }//echo "UPDATE " . TABLE_ADMIN . " set admin_password='" . $new_password . "', encryption_style='" . ENCRYPTION_STYLE . "' where admin_id=" . (int)$check_admin['login_id'];
		if (!($check_admin['encryption_style']=="" && ENCRYPTION_STYLE=="O") && $check_admin['encryption_style']!=ENCRYPTION_STYLE){
			$new_password=tep_encrypt_password($password);
		
			tep_db_query("UPDATE " . TABLE_ADMIN . " set admin_password='" . $new_password . "', encryption_style='" . ENCRYPTION_STYLE . "' where admin_id=" . (int)$check_admin['login_id']);
		}
        $login_id = $check_admin['login_id'];
        $login_groups_id = $check_admin['login_groups_id'];
        $login_first_name = $check_admin['login_firstname'];
        $login_email_address = $check_admin['login_email_address'];
        $login_logdate = $check_admin['login_logdate'];
        $login_lognum = $check_admin['login_lognum'];
        $login_modified = $check_admin['login_modified'];

        tep_session_register('login_id');
        tep_session_register('login_groups_id');
        tep_session_register('login_first_name');

    	// error count
    	    tep_set_session_value('error_count',0);
		//error count 
		// find the admin groups name
		$group_query=tep_db_query("SELECT admin_groups_name from ". TABLE_ADMIN_GROUPS . " where admin_groups_id='". $login_groups_id . "'");
		$group_result=tep_db_fetch_array($group_query);
		$login_groups_name=$group_result['admin_groups_name'];
		$login_groups_type=$login_groups_name;
		tep_session_register('login_groups_type');
		tep_session_register("login_email");
		tep_session_register("top_admin_email");
		
	    tep_set_session_value('login_email',$login_email_address); 
		// error count
    	    tep_set_session_value('error_count',0);
		//error count
		// set top administrator email		
		$admin_query=tep_db_query("SELECT admin_email_address from " . TABLE_ADMIN . " a, " . TABLE_ADMIN_GROUPS . " ag where ag.admin_groups_name='" . TEXT_ADMINISTRATOR_ENTRY . "' and a.admin_groups_id=ag.admin_groups_id");
		$admin_result=tep_db_fetch_array($admin_query);
		tep_set_session_value('top_admin_email',$admin_result["admin_email_address"]);

		$select_box="";
        tep_db_query("update " . TABLE_ADMIN . " set admin_logdate ='" . getServerDate(true) . "', admin_lognum = admin_lognum+1 where admin_id = '" . $login_id . "'");

        /*if (($login_lognum == 0) || !($login_logdate) || ($login_email_address == 'admin@localhost') || ($login_modified == '0000-00-00 00:00:00')) {
          if ($login_groups_name==TEXT_CALLSTAFF_ENTRY) $select_box="selected_box=customers";
		  if ($login_groups_name==TEXT_INSTRUCTOR_ENTRY) $select_box="selected_box=event";
          tep_redirect(tep_href_link(FILENAME_ADMIN_ACCOUNT,$select_box));
        } else {*/
		  // find the login user group if callstaff or instructor redirect to appropriate pages
		/*  if ($login_groups_name==TEXT_CALLSTAFF_ENTRY){
		    tep_redirect(tep_href_link(FILENAME_CUSTOMERS,'selected_box=customers'));
		  } else if ($login_groups_name==TEXT_INSTRUCTOR_ENTRY || $login_groups_name==TEXT_RESERVATIONMANAGER_ENTRY){
		     tep_redirect(tep_href_link(FILENAME_EVENTS_ADMIN_MESSAGES,'selected_box=instructor'));
		  } 
           tep_redirect(tep_href_link('configuration.php?selected_box=configuration&gID=1'));*/
		   
		   // find the login user group and redirecting to appropriate pages		  
		  $file_name = (isset($HTTP_COOKIE_VARS["store_file_name_" . $login_groups_id]) ? $HTTP_COOKIE_VARS["store_file_name_" . $login_groups_id] : 'configuration.php?selected_box=configuration&gID=1');
		   if ($login_groups_name==TEXT_ADMINISTRATOR_ENTRY){
		   	tep_redirect(tep_href_link($file_name));
			//tep_redirect(tep_href_link(FILENAME_CONFIGURATION,'selected_box=configuration'));
			} else if ($login_groups_name==TEXT_INSTRUCTOR_ENTRY){
			tep_redirect(tep_href_link(FILENAME_EVENTS_ADMIN_MESSAGES,''));
			 }
			 else if ($login_groups_name==TEXT_CALLMANAGER_ENTRY){ 
			tep_redirect(tep_href_link(FILENAME_CALL_CENTRE_ORDERS,''));
			  } 
			   else if ($login_groups_name==TEXT_CALLSTAFF_ENTRY){
			tep_redirect(tep_href_link(FILENAME_EVENTS_BROWSE,''));
			  } 
			   else if ($login_groups_name==TEXT_PRODUCTMANAGER_ENTRY){
			tep_redirect(tep_href_link(FILENAME_PRODUCTS_SALES,''));
			  } 
			   else if ($login_groups_name==TEXT_RESERVATIONMANAGER_ENTRY){
			tep_redirect(tep_href_link(FILENAME_EVENTS_SALES,''));
			  } else if ($login_groups_name==TEXT_FULFILLER_ENTRY){
			  tep_redirect(tep_href_link(FILENAME_REPORTS_FULFILLER,''));
			  }
			tep_redirect(tep_href_link('myaccount_update_account.php?mPath=12'));
			
        //}

      }
    }
  }
  
  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_LOGIN);
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<style type="text/css"><!--
a { color:#08a1ee; text-decoration:none; }
a:hover { color:#aabbdd; text-decoration:underline; }
a.text:link, a.text:visited { color: #ffffff; text-decoration: none; }
a:text:hover { color: #ffffff; text-decoration: none; }
a.sub:link, a.sub:visited { color: #6176C9; text-decoration: none; }
A.sub:hover { color: #6176C9; text-decoration: underline; }
.sub { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; line-height: 1.5; color: #000000; }
.text { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #000000; }
.smallText { font-family: Verdana, Arial, sans-serif; font-size: 10px; color:#FFFFFF }
.login_heading { font-family: Verdana, Arial, sans-serif; font-size: 12px; color: #ffffff; background-color:#8EA6EF}
.login { font-family: Verdana, Arial, sans-serif; font-size: 11px; color: #000000;}
.loginleft{
background:#8EA6EF url(images/template/cell_bg_strip1.gif) no-repeat top left ;
}
.smallText a {font-family: Verdana, Arial, sans-serif; font-size: 10px; color:#FFFFFF; }
.error { font-family: Verdana, Arial, sans-serif; font-size: 10px; color:#000000 }
.shadow {
background:#F0F0FF url(images/template/cell_bg_shadow.gif) no-repeat bottom  ;
}
.loginright{
	background:#8EA6EF url(images/template/cell_bg_strip2.gif) no-repeat top right ;
}

//--></style>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#647DCD">

<table border="0" width="100%"   cellspacing="0" cellpadding="0" align="center" valign="middle" bgcolor="#647DCD" >

  <tr  height="500">
    <td>
		  <table border="0" width="100%" cellspacing="0" cellpadding="0" >
		   <!-- freeway Image -->
            <tr> <td colspan="2" valign="top" >
               <table border="0"  cellspacing="0" cellpadding="0" bgcolor="#647DCD" bordercolor="#8EA6EF" width=100%>
                  <tr><td colspan="3"> 
				     <table  border="0" cellpadding="0" cellspacing=0  width=100% >
                        <tr bgcolor="#ffffff" height="250"> 
                    <!--   <td width="30%" align=center valign="bottom"> <?php //echo '<a href="http://www.zac-ware.com">' . tep_image(DIR_WS_IMAGES . COMPANY_LOGO,'') . '</a>'; ?></td> !-->
                           <td align="center" valign="bottom"><a href="http://www.zac-ware.com"><?php echo tep_image(DIR_WS_IMAGES . 'admin_logo.png', STORE_NAME,'','','align=absmiddle'); ?></a>
						   <?php 
								//$url='<a href="http://www.zac-ware.com">' . tep_image(DIR_WS_TEMPLATES.DEFAULT_TEMPLATE.'/'.DIR_WS_IMAGES . COMPANY_LOGO,  STORE_NAME,'','') . '</a>';
								//echo $url;
							    //echo tep_image(DIR_WS_IMAGES . 'admin_logo.png', STORE_NAME,'','','align=absmiddle');?>
							</td>
						<!-- <td width="30%" align=center valign="bottom"> <?php //echo '<a href="http://www.zac-ware.com">' . tep_image(DIR_WS_TEMPLATES.DEFAULT_TEMPLATE.'/'.DIR_WS_IMAGES . COMPANY_LOGO,'') . '</a>'; ?></td> !-->
						 </tr>
						   <tr><td >
						   <table border="0" width="100%" cellpadding="0" cellspacing="0" >
                    		<tr><td class="loginleft"  width="256" height="31"></td> 
							<td align="center" class="login_heading" nowrap="nowrap"><b>FREEWAY Administration Interface&nbsp;</b></td>
							<td class="loginright" width="256" height="31"></td>
							</tr>
							</table>
							</td></tr>
							
							<tr> 
                         	 <td height="100%" valign="top" align="center" >
						    <?php echo tep_draw_form('login', FILENAME_LOGIN, 'action=process'); ?> 
								<table border="0" width="468" height="200" cellspacing="3" cellpadding="2"  class="shadow"  bgcolor="#F0F0FF">
                                    <?php
									  if ($HTTP_GET_VARS['login'] == 'fail') {
										$info_message = TEXT_LOGIN_ERROR;
									  }

									  if (isset($info_message)) {
									?>
                                    <tr> 
                                      <td colspan="3" class="error" align="center"><?php echo $info_message; ?></td>
                                    </tr>
                                    <?php
									} else {
									?>
                                    <tr> 
                                      <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
                                    </tr>
                                    <?php
										  }
										?>
                                    <tr> 
									  <td></td>
                                      <td class="login" align="right"><b><?php echo ENTRY_EMAIL_ADDRESS; ?></b></td>
                                      <td class="login"><?php echo tep_draw_separator('pixel_trans.gif', '10', '10'); ?><?php echo tep_draw_input_field('email_address'); ?></td>
                                    </tr>
                                    <tr> 
									  <td></td>
                                      <td class="login" align="right"><?php echo tep_draw_separator('pixel_trans.gif', '33', '10'); ?><b><?php echo ENTRY_PASSWORD; ?></b></td>
                                      <td class="login"><?php echo tep_draw_separator('pixel_trans.gif', '10', '10'); ?><?php echo tep_draw_password_field('password'); ?></td>
                                    </tr>
									
									<tr> 
                                      <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
                                    </tr>
                                    <tr> 
                                      <td colspan="3" align="center" valign="top"><?php echo tep_image_submit('button_login.gif', IMAGE_BUTTON_LOGIN); ?></td>
                                    </tr>
									
									 <tr> 
                         			 <td colspan="3" align="center"  valign="bottom"><?php echo '<a class="sub" href="' . tep_href_link(FILENAME_PASSWORD_FORGOTTEN, '', 'SSL') . '">' . TEXT_PASSWORD_FORGOTTEN . '</a><span class="sub">&nbsp;</span>'; ?></td>
                      				 </tr>
									 <tr><td colspan="3" height="5"></td></tr>
                            </table>
							</form>
							</td>
                      	  </tr>
							<tr>
             				 <td  id="desc" valign="top"> 
              			  <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
              			</td>
     					</tr>
                      </table>
				  </td></tr>
          		<!-- //freeway Image -->	
    </table></td>
  </tr>
</table>

</td>

</tr>
 <tr bgcolor="#647DCD"> 
  <td align=center> <?php //echo '<a href="http://www.zac-ware.com">' . tep_image(DIR_WS_IMAGES . 'logo_size2.gif','') . '</a>'; ?></td>
 </tr>

</table>

</body>
<script language="javascript">
	function toggle_panel(title,funname){
		var img=document.getElementById("img_"+title);
		var panel=document.getElementById("panel_"+title);
		if (panel.style.display=="none"){
			img.src="images/template/panel_up.gif";
			panel.style.display="";
		} else {
			panel.style.display="none";
			img.src="images/template/panel_down.gif";
		}
		if(funname=='true'){
			doaction();
		}	
	}
	function toggle_focus(element,mode){
		if (mode==2){
			element.className="inputSelect";
		} else {
			element.className="inputNormal";
		}
	}
</script>
<style>
.inputNormal{
	font-family: Verdana, Arial, sans-serif; font-size: 11px;
	font-weight:normal;
	background:#F8F8F8 url(../images/template/cell_bg_input.gif) repeat-x top left;
	border:solid 1px #B4B3B3;
}
.inputSelect{
	font-family: Verdana, Arial, sans-serif; font-size: 11px;
	font-weight:normal;
	background:#F3F6FF url(../images/template/cell_bg_input_select.gif) repeat-x top left;
	border:solid 1px #B4B3B3;
}
</style>
</html>
<!--session expired-->