<?php
/* 
	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 
*/ 
  ?>
<script>
 function do_pwd_check(obj)
 { 
  <?php 
  //if(MODULE_CUSTOMERS_PASSWORD_STRENGTH==4){
  
  ?>	
 	pwd=obj.value;
	if(pwd.length==0)
	  document.all.pwd_str.innerHTML='';
	else if(pwd.length<"5")
		document.all.pwd_str.innerHTML='<font color="red">Password strength is poor</font>';
	else if(!check_password_strength(pwd))
		document.all.pwd_str.innerHTML='<font color="red">Password strength is poor</font>';
	else
		document.all.pwd_str.innerHTML='';
  <?php //} ?>
 }
 
 function check_password_strength(pwd)
	{ 
		var r_sym = new RegExp("[~`!@#$%^&*_=|\/><,?;:+-]","i");
		var r_caps =/^[A-Z]+$/; //new RegExp("[A-Z]","i");
		var r_small =/^[a-z]+$/; // new RegExp("[a-z]","i");
            tot_average        = 0.0; 
            pwdav_len            = 0.0;                 
            pwdav_caps        = 0.0;                 
            pwdav_nums        = 0.0;                                         
            pwdav_small        = 0.0; 
            pwdav_puncts        = 0.0;                 
            total_char_used = 0; 
            if (pwd.length>0) 
            { 
                p_limit = 5; 
                pwd_len = pwd.length; 
                nums_cnt = 0; 
                for(i=0;i<pwd_len;i++) 
                { 
					val=pwd.substr(i,1);
                    if (!isNaN(val)) 
                        nums_cnt++; 
                } 
                if (nums_cnt>0) 
                    total_char_used += 10; 
					
                small_cnt = 0; 
                for(i=0;i<pwd_len;i++) 
                { 
					val=pwd.substr(i,1);
					res = r_small.test(val);
                    if (res==true)
                        small_cnt++; 
                } 
                if (small_cnt>0) 
                    total_char_used += 26; 

                caps_cnt = 0; 
                for(i=0;i<pwd_len;i++) 
                { 
					val=pwd.substr(i,1);
					res = r_caps.test(val);
                    if (res==true) 
                        caps_cnt++; 
                } 
                if (caps_cnt>0) 
                    total_char_used += 26; 

                puncts_cnt = 0; 
                for(i=0;i<pwd_len;i++) 
                { 
					val=pwd.substr(i,1);
					res=val.match(r_sym);
                    if (res!=null) 
                        puncts_cnt++; 
                } 
                if (puncts_cnt>0) 
                    total_char_used += 31; 

                // calculation   
				len_min="5";
				len_max=16;                                      
                if ((pwd_len>len_min) && (pwd_len<len_max)) 
                    pwdav_len += (100 / p_limit); 
                // caps 
                tot_average += pwdav_len; 
                if (20 <= ((caps_cnt * 100) / pwd_len)) 
                    pwdav_caps += (100 / p_limit); 
                else 
                    pwdav_caps += (caps_cnt > 0) ? ((100 / p_limit) - 10) :  0; 
                tot_average += pwdav_caps; 
                // numbers 
                if (20 <= ((nums_cnt * 100) / pwd_len)) 
                    pwdav_nums += (100 / p_limit); 
                else 
                    pwdav_nums += (nums_cnt > 0) ? ((100 / p_limit) - 10) :  0; 
                tot_average += pwdav_nums; 
                // small 
                if (30 <= ((small_cnt * 100) / pwd_len)) 
                    pwdav_small += (100 / p_limit); 
                else 
                    pwdav_small += (small_cnt > 0) ? ((100 / p_limit) - 10) :  0; 
                tot_average += pwdav_small; 
				
                // symbols 
                if (10 <= ((puncts_cnt * 100) / pwd_len)) 
                    pwdav_puncts += (100 / p_limit); 
                else 
                    pwdav_puncts += (puncts_cnt > 0) ? ((100 / p_limit) - 10) :  0; 
                 
                tot_average += pwdav_puncts;             
                charSet = total_char_used; 
            } 
			if(tot_average<=40)
				return false;
			else
				return true;
	}
	
function pwdValidation(type,strng){
	switch (type){
			case '1':
				if(str_trim(strng)=='')
					return false;
				break;
			case '2':
				 var alphanum = /^[a-zA-Z0-9_]+$/;
				 return alphanum.test(strng);
				 break;
			case '3':
				//var symbol = /^([a-zA-Z0-9_\.\+\-\*\/])+$/;
				var symbol = /^([0-9a-zA-Z_\.\+\-\=\*\/\@\#\$\!\`\~\%\^\&\*\(\)\_\|\>\<\,\?\:\;\"\'\{\[\}\]\\])+$/;
                var ans = symbol.test(strng);
				if (ans == true) return true;
				else return false;
				// return symbol.test(strng);	
				 break;
		/*	case '4':
				//var symbol = /^([0-9a-zA-Z]\*\+\-\*)*?/g;
					var symbol = /^([0-9a-zA-Z_\.\+\-\*\/])+$/;
					//alert(symbol.test(strng));
					var ans = symbol.test(strng);
					if (ans == true){
					return true;
					}
					else 
					return false;
					// return symbol.test(strng);	
				 break;*/
	}			
	return true;
}


</script>

<?php	
  $action=(isset($HTTP_GET_VARS["action"])?$HTTP_GET_VARS["action"]:'');

  if ($action=='email_update'){
    $db['DB_SERVER'] = trim(stripslashes($HTTP_POST_VARS['DB_SERVER']));
    $db['DB_SERVER_USERNAME'] = trim(stripslashes($HTTP_POST_VARS['DB_SERVER_USERNAME']));
    $db['DB_SERVER_PASSWORD'] = trim(stripslashes($HTTP_POST_VARS['DB_SERVER_PASSWORD']));
    $db['DB_DATABASE'] = trim(stripslashes($HTTP_POST_VARS['DB_DATABASE']));
    $db_error = false;    
	osc_db_connect($db['DB_SERVER'], $db['DB_SERVER_USERNAME'], $db['DB_SERVER_PASSWORD']);

	if (!osc_db_select_db($db['DB_DATABASE'])){
		$db_error=mysql_error();
	}
	if (!$db_error){
		$email_address=isset($HTTP_POST_VARS["txtEmail"])?$HTTP_POST_VARS["txtEmail"]:'';
		$password=isset($HTTP_POST_VARS["txtPass"])?$HTTP_POST_VARS["txtPass"]:'';
		if ($email_address!='' && $password!=''){
			$password=osc_encrypt_password($password);
			osc_db_query("UPDATE admin set admin_email_address='" . $email_address . "',admin_password='" . $password . "' where admin_id=1");
		}
	}
	$action="complete";
  }
  $www_location=isset($HTTP_POST_VARS['HTTP_WWW_ADDRESS'])?$HTTP_POST_VARS['HTTP_WWW_ADDRESS']:'';
  $web_service=isset($HTTP_POST_VARS['webservice'])?$HTTP_POST_VARS['webservice']:'0';
  if ($www_location==""){
	  $www_location = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER["SCRIPT_NAME"];
	  $www_location = substr($www_location, 0, strpos($www_location, 'install'));
  }
  
  $script_filename = getenv('PATH_TRANSLATED');
  if (empty($script_filename)) {
    $script_filename = getenv('SCRIPT_FILENAME');
  }


  if (empty($script_filename)) {
	$script_filename = $_SERVER["SCRIPT_FILENAME"];
  }
  $script_filename = str_replace('\\', '/', $script_filename);
  $script_filename = str_replace('//', '/', $script_filename);

  $dir_fs_www_root_array = explode('/', dirname($script_filename));
  $dir_fs_www_root = array();
  for ($i=0, $n=sizeof($dir_fs_www_root_array)-1; $i<$n; $i++) {
    $dir_fs_www_root[] = $dir_fs_www_root_array[$i];
  }
  $dir_fs_www_root = implode('/', $dir_fs_www_root) . '/';
  
  	$last_test="";
  $compat_link="install.php?mode=compat_test&action=testemail";
  $show_continue=true;
  $require_load=true;
  $display_mode="dir";
  if ($action=="email"){
  	if (!isset($HTTP_POST_VARS["first_install"]) || $HTTP_POST_VARS["first_install"]!='1'){
		$action="complete_no_config";
	}
  } 
  if ($action=="email") {
	  $current_step="complete";
?>
<script language="javascript">

	function validateForm(){
		frm=document.frmSetting;
		error="";
			
		if (trim(frm.txtEmail.value)==""){
			error+="* Email Address cannot be empty.\n";
		} else if (!checkEmail(frm.txtEmail.value)){
			error+="* Email Address not valid.\n";
		}
		if (trim(frm.txtPass.value)==""){
			error+="* Password cannot be empty.\n";
		} else if (frm.txtPass.value.length<5 || !check_password_strength(frm.txtPass.value) || !pwdValidation('3',frm.txtPass.value)){
			error+="* Password must be strong.\n";
		}
		if (trim(frm.txtConfirmPass.value)==""){
			error+="* Confirm Password cannot be empty.\n";
		}
		if (error=="" && (frm.txtPass.value!=frm.txtConfirmPass.value)){
			error+="* Password and Confirm Password are not matching\n";
		}
		
		if(error!=''){
			alert(error);
			return false;
		}
		return true;
	}
	function checkEmail(email) {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
			return (true)
		}
		return false;
	}
	function trim(str){
		if(!str || typeof str != 'string')
			return '';
	
		return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
	}
</script>
 <table width="100%" cellpadding="0" border="0" cellspacing="0">
 <form action="install.php?step=9&action=email_update" onSubmit="javascript:return validateForm();" name="frmSetting" method="post">
	<tr>
		<td>
		<?php echo osc_draw_box_start(480);?>
		<table width="100%" border="0" cellpadding="2" class="formPage">
		  <tr>
			<td>
			  <p><b>Installation was <font color="#3F7B86">successful</font></b> <img src="images/setting_right.gif" align="absmiddle"/></p>
			  <p> Please change the Login Settings for Administration tool.<br />
			</td>
		  </tr>
		  <tr>
		  	<td>
			<table border="0" cellpadding="2" class="formPage" width="100%">
				  <tr>
					<td width="130"><b>Email Address:</b></td><td><input type="text" name="txtEmail" value="freeway@zac-ware.com"/></td>
				  </tr>
				  <tr>
					<td><b>Password:</b> </td><td><input name="txtPass" type="password" onkeyup="javascript:do_pwd_check(this);"/></td>
					<td id='pwd_str' class="inputRequirement" style="font-color:red;font-size:11"></td>
				</tr>
				<tr>
					<td><b>Confirm Password:</b> </td><td><input name="txtConfirmPass" type="password"/></td>

				</tr>
			</table>
			</td>
		</tr>
			<?php
				  reset($HTTP_POST_VARS);
				  while (list($key, $value) = each($HTTP_POST_VARS)) {
					if (($key != 'x') && ($key != 'y') && ($key != 'DB_TEST_CONNECTION')) {
					  if (is_array($value)) {
						for ($i=0; $i<sizeof($value); $i++) {
						  echo osc_draw_hidden_field($key . '[]', $value[$i]);
						}
					  } else {
						echo osc_draw_hidden_field($key, $value);
					  }
					}
				  }
			?>
		</table>
		<?php echo osc_draw_box_end();?>
		</td>
	</tr>
	<tr>
		<td>
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr>
			<td><a href="index.php"><img src="images/button_cancel.gif" border="0" alt="Cancel"></a></td>
			<td align="right"><input type="image" src="images/button_continue.gif" border="0" alt="Continue" class="imageButton"></td>
		  </tr>
		</table>
		</td>
	</tr>
</form>
</table>
<?php
  } else if ($action=="complete" || $action=="complete_no_config") {
  $current_step="complete";
?>
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td>
		<?php echo osc_draw_box_start(480);?>
		<table width="100%" border="0" cellpadding="2" class="formPage">
		  <tr>
			<td>
			<?php if ($action=="complete_no_config") { ?>
			  <p><b>Installation was <font color="#3F7B86">successful</font></b> <img src="images/setting_right.gif" align="absmiddle"/></p>
			<?php } else { ?>
			  <p>The Login Settings for Administration tool are changed <font color="#AB212E">successfully</font> <img src="images/setting_right.gif" align="absmiddle"/>
			 <?php } ?>
			</td>
		  </tr>
		</table>
		<?php echo osc_draw_box_end();?>
		</td>
	</tr>
	<tr>
		<td>
		<table border="0" cellspacing="5" cellpadding="0" width="100%">
		  <tr>
			<td><a href="<?php echo $www_location . 'index.php'; ?>" target="_blank"><img src="images/button_catalog.gif" border="0" alt="Catalog"></a></td>
			<td align="right"><a href="<?php echo $www_location . 'admin/index.php'; ?>" target="_blank"><img src="images/button_administration_tool.gif" border="0" alt="Administration Tool"></a></td>
		  </tr>
		</table>
		</td>
	</tr>
</table>
<?php
	} else {
	  	$current_step="config";
	  require("compat_test_info.php");
	}
?>