<?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');
  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_LOGIN);
  
  if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'process')) {
    $email_address = tep_db_prepare_input($HTTP_POST_VARS['email_address']);
    $firstname = tep_db_prepare_input($HTTP_POST_VARS['firstname']);
    $log_times = $HTTP_POST_VARS['log_times']+1;
    if ($log_times >= 4) {
      tep_session_register('password_forgotten');
    }
      
// Check if email exists
    $check_admin_query = tep_db_query("select admin_id as check_id, admin_firstname as check_firstname, admin_lastname as check_lastname, admin_email_address as check_email_address 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);
      if ($check_admin['check_firstname'] != $firstname) {
        $HTTP_GET_VARS['login'] = 'fail';
      } else {
        $HTTP_GET_VARS['login'] = 'success';
        
        function randomize() {
          $salt = "ABCDEFGHIJKLMNOPQRSTUVWXWZabchefghjkmnpqrstuvwxyz0123456789";
          srand((double)microtime()*1000000); 
          $i = 0;
    
          while ($i <= 7) {
            $num = rand() % 33;
    	    $tmp = substr($salt, $num, 1);
    	    $pass = $pass . $tmp;
    	    $i++;
  	  }
  	  return $pass;
        }
        $makePassword = randomize();
        tep_db_query("update " . TABLE_ADMIN . " set admin_password = '" . tep_encrypt_password($makePassword) . "', encryption_style='" . ENCRYPTION_STYLE . "' where admin_id = '" . (int)$check_admin['check_id'] . "'");

		//send mails about  password forgot
		$merge_details=array(TEXT_FN=>$check_admin['check_firstname'] ,
                                            TEXT_LN=>$check_admin['check_lastname'] ,
		                                    TEXT_LE=>$check_admin['check_email_address'],
											TEXT_LP=>$makePassword,
											TEXT_SM=>STORE_NAME,
											TEXT_SN=>STORE_OWNER,
											TEXT_SE=>STORE_OWNER_EMAIL_ADDRESS,
											TEXT_AL=>HTTP_SERVER . DIR_WS_ADMIN);
       $send_details=array(array('to_name'=>$check_admin['check_firstname'] . ' ' . $check_admin['admin_lastname'],
	                                     'to_email'=>$check_admin['check_email_address'] ,
										 'from_name'=>STORE_OWNER,
										 'from_email'=>STORE_OWNER_EMAIL_ADDRESS));
	  
	  tep_send_default_email('AUR',$merge_details,$send_details);
      }
    }
  }

?>
<!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:#080381; text-decoration:none; }
a:hover { color:#aabbdd; text-decoration:underline; }
a.text:link, a.text:visited { color: #ffffff; text-decoration: none; }
a.top { color: #647DCD; text-decoration:none; }
a.top:link { ccolor: #ffffff; text-decoration:underline; }
a.top:hover { ccolor: #ffffff; text-decoration:underline; }

a.text:link, a.text:visited { color: #ffffff; text-decoration: none; }
a:text:hover { color: #ffffff; text-decoration: underline; }
a.sub:link, a.sub:visited { color: #dddddd; text-decoration: none; }
A.sub:hover { color: #dddddd; text-decoration: underline; }
.sub { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; line-height: 1.5; color: #dddddd; }
.text { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #000000; }
.toptext { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #647DCD; }
.smallText { font-family: Verdana, Arial, sans-serif; font-size: 10px; color:#FFFFFF; }
.smallText a {font-family: Verdana, Arial, sans-serif; font-size: 10px; color:#FFFFFF; }
.menuBoxHeading { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; background-color: #49549E; border-color: #FFFFFF; border-style: solid; border-width: 0px; color:#FFFFFF;}
.login_heading { font-family: Verdana, Arial, sans-serif; font-size: 12px; color:#FFFFFF;}
.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 ;
}
.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"> 
                         <?php //tep_image(DIR_WS_IMAGES . 'freeway.png',''); ?>
                           <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" bgcolor="#8EA6EF"><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_PASSWORD_FORGOTTEN, 'action=process'); ?>
						<table border="0" width="468"   cellspacing="3" cellpadding="2"  class="shadow"  bgcolor="#F0F0FF">
							<tr>
								<td height="100%"  valign="top" align="center"  >
											<?php
											if ($HTTP_GET_VARS['login'] == 'success') {
											$success_message = TEXT_FORGOTTEN_SUCCESS;
											} elseif ($HTTP_GET_VARS['login'] == 'fail') {
											$info_message = TEXT_FORGOTTEN_ERROR1;
											}
											if (tep_session_is_registered('password_forgotten')) {
											?>
									<tr>
									<td class="smallText"><?php echo TEXT_FORGOTTEN_FAIL; ?></td>
									</tr>
									<tr>
									<td align="center" valign="top"><?php echo '<a href="' . tep_href_link(FILENAME_LOGIN, '' , 'SSL') . '">' . tep_image_button('button_login.gif', IMAGE_BACK) . '</a>'; ?></td>
									</tr>
									<?php
									} elseif (isset($success_message)) {
									?>
									<tr>
										<td style="color:#000000; font-size:10px; font-family:Verdana, Arial, sans-serif"><?php echo $success_message; ?></td>
									</tr>
									<tr>
										<td align="center" valign="middle"><?php echo '<a href="' . tep_href_link(FILENAME_LOGIN, '' , 'SSL') . '">' . tep_image_button('button_login.gif', IMAGE_BACK) . '</a>'; ?></td>
									</tr>
									<tr><td></td></tr>
									<?php
									} else {
										if (isset($info_message)) {
									?>
                                    <tr>
                                      <td colspan="2" class="error" align="center"><?php echo $info_message; ?><?php echo tep_draw_hidden_field('log_times', $log_times); ?></td>
                                    </tr>
										<?php
										} else {
										?>
									<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?><?php echo tep_draw_hidden_field('log_times', '0'); ?></td>
									</tr>
										<?php
											}
										?>   
                                  
									<tr> 
                                      <td class="login" colspan="2" valign="top" align="center"><b><?php echo 'Password forgotten?'; ?></b></td>
                                    </tr>
									
									<tr> 
                                      <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
                                    </tr>
									
									<tr> 
                                      <td class="login" align="center" nowrap="nowrap"><b><?php echo ENTRY_FIRSTNAME; ?></b></td>
                                      <td class="login"><?php echo tep_draw_separator('pixel_trans.gif', '10', '5'); ?><?php echo tep_draw_input_field('firstname'); ?></td>
                                    </tr>
									
									<tr> 
                                      <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
                                    </tr>
                                    <tr> 
                                      <td class="login" nowrap="nowrap" align="center"><?php echo tep_draw_separator('pixel_trans.gif', '33', '10'); ?><b><?php echo ENTRY_EMAIL_ADDRESS; ?></b></td>
                                      <td class="login"><?php echo tep_draw_separator('pixel_trans.gif', '10', '5'); ?><?php echo tep_draw_input_field('email_address'); ?></td>
                                    </tr>
									
									
									<tr> 
                                      <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
                                    </tr>
                                    <tr>
                                      <td colspan="2" align="center" valign="top"><?php echo '<a href="' . tep_href_link(FILENAME_LOGIN, '' , 'SSL') . '">' . tep_image_button('button_login.gif', IMAGE_BACK) . '</a> ' . tep_image_submit('button_send_password.gif', IMAGE_BUTTON_LOGIN); ?>&nbsp;</td>
                                    </tr>
									
									<tr> 
                                      <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
                                    </tr>
									
									<tr><td colspan="2" align="center" nowrap  class="toptext"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '" class="top">' . HEADER_TITLE_ADMINISTRATION . '</a>&nbsp;|&nbsp;<a href="' . tep_catalog_href_link() . '" class="top">' . HEADER_TITLE_ONLINE_CATALOG . '</a>&nbsp;|&nbsp;<a href="http://www.oscommres.com" target="_blank" class="top">' . HEADER_TITLE_SUPPORT_SITE . '</a>'; ?>&nbsp;&nbsp;</td> 
								</tr>
								
									<tr> 
                                      <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
                                    </tr>
									<?php
									}
									?>   
									
                                </td>
                              </tr>
                            </table>
                          </form>

            </td>
          </tr>
		  <tr>
             				 <td  id="desc" valign="top"> 
              			  <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
              			</td>
     					</tr>
        </table>
		</td>
      </tr>
  
    </table>
	</td>
  </tr>
</table>
</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>