<?php
global $emailtmp;
include("config.php");

$lib=stripslashes(@$_GET['lib']);

foreach($importerinfo as $name=>$path)
{
	if($lib==$path)
	{
		if(file_exists($lib)===true)
		{
			$defaultimporterlib=$lib;
		}
		else
		{
			echo "<pre>Cannot find <b>".htmlspecialchars($lib,ENT_QUOTES)."</b>. Please make sure it is uploaded to the same directory!</pre>"; exit;
		}
		break;
	}
}

include($defaultimporterlib);

if(intval(@$_POST['update'])==1)
{
	$email=stripslashes(@$_POST['EmailAddress']);
	$password=stripslashes(@$_POST['Passwd']);
	$output=null;

	if(@$imode==0)
	{
		$contactemails=import_contacts($email,$password);
		if(!is_array($contactemails))
		{
			$output="<span class=\"sbox\"><img align=\"absmiddle\" src=\"error.gif\"> Failed to import contacts. Please check your username &amp; password!</span>";
		}
	}
	elseif(@$imode==1)
	{
		$contactemails=import_contacts($_FILES['fupload']);
		if(!is_array($contactemails)){
			$output="<span class=\"sbox\"><img align=\"absmiddle\" src=\"error.gif\"> Failed to import contacts from CSV file. Please check if the file selected is valid.</span>";
		}
	}

	$i=0;
	if(is_array($contactemails))
	{
		foreach($contactemails as $contact)
		{
				$output.="<tr><td style=\"padding:6px;\"><input type=\"hidden\" name=\"name[]\" value=\"".htmlspecialchars(@$contact[0],ENT_QUOTES)."\"><input type=\"hidden\" id=\"email[]\" name=\"email[]\" value=\"".htmlspecialchars(@$contact[1],ENT_QUOTES)."\"><input type=\"checkbox\" id=\"selcontacts[]\" name=\"selcontacts[]\" value=\"".htmlspecialchars($i,ENT_QUOTES)."\" checked></td>
				<td style=\"padding:6px;\" width=\"200\">".htmlspecialchars(@$contact[0],ENT_QUOTES)."</td><td style=\"padding:6px;\" width=\"200\" bgcolor=\"#eeeeee\">".htmlspecialchars(@$contact[1],ENT_QUOTES)."</td></tr>";
				$i++;
		}

		$checkrow="<tr><td style=\"padding:6px;\" colspan=\"3\" bgcolor=\"#cccccc\"><a onclick=\"select_all(1);\" href=\"javascript: void(0);\"><font color=\"#666666\"><b>Select All</b></font></a> | <a onclick=\"select_all(0);\" href=\"javascript: void(0);\"><font color=\"#666666\"><b>Unselect All</b></font></a></td></tr>";

		$output="
		<form name=\"formlist\" method=\"POST\" action=\"".$postpath."\">
		<table border=\"1\" bordercolor=\"#cccccc\" class=\"stxtb\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" style=\"border-collapse:collapse;\" width=\"450\">".$checkrow.$output.$checkrow."</table>
		<br/><span class=\"stxt\">There are a total of <b>".count($contactemails)."</b> emails being imported.</span><br/><br/><input type=\"button\" class=\"smtb\" onclick=\"this.value='Please wait...'; this.disabled=true; this.form.submit();\" value=\"Send Invitation\"><input type=\"hidden\" name=\"fromemail\" value=\"".htmlspecialchars($emailtmp,ENT_QUOTES)."\"></form>
		";

	}
}

?><html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>XgContacts Importer v2.2</title>
<style><!--
body{margin-top:26px; margin-bottom:20px; background-image:url(bg.jpg); background-repeat:repeat-x;}

form{margin:10px 0px;}

img{border:0px solid;}

.tab{border:2px solid #fff; font:bold 12px arial, tahoma, verdana; color:#000; text-decoration:none; padding:4px;}

.tabhover{border:2px solid #ddd; font:bold 12px arial, tahoma, verdana; color:#eee; text-decoration:none; padding:4px; background-color:#000; background-image:url(bx.jpg); background-repeat:repeat-x;}

h1{font:bold 11pt arial, tahoma, verdana; color:#000; margin:0px; padding:0px; color:#666;}

.skn{border:2px solid #ddd; background-color:#eee; padding:24px 4px;}

.stxt{font:normal 12px arial, tahoma, verdana; color:#000;}

.stxt A{text-decoration:none; color:#666;}

.stxt A:hover{text-decoration:underline; color:#000;}

.stxtb{font:normal 8pt tahoma, verdana, arial; color:#000;}

.sbox{border:1px solid #ddd; background-color:#eee; padding:8px 10px; font:bold 8pt arial, tahoma, verdana; color:#666; width:auto;}

.smt{font: bold 9pt arial, verdana, helvetica, sans-serif;}

.st{font: normal 8pt arial, verdana, helvetica, sans-serif; color: #000;}

.smtb{
    background-color: #CC3333;
    font: bold 9pt arial,verdana, helvetica, sans-serif;
    color: #fff; cursor: pointer; border-width: 1px 1px 1px 1px; border-style: solid; border-color: #F66 #900 #900 #F66; padding: 2px;
}
--></style>

<script language="Javascript"><!--
/*
Copyright reserved (c) 2006-2007 Xceog.Net.
Distribution of these codes without written permission from Xceog is prohibited.
*/
var stat=0;

function changestat(object,stat,obj){
if(stat==0){
obj.innerHTML='<div class="skn"><h1>+ Manual Invite</h1><form method="POST" action="<?php echo $postpath;?>"><table border="0" cellpadding="2" align=\"center\" style=\"border-collapse:collapse;\" width="250" class="stxt" cellspacing="2"><tr><td align="middle"><input type="text" name="email[]" style="width:120px;" class="stxt"></td><td align="middle"><input type="text" name="email[]" style="width:120px;" class="stxt"></td></tr><tr><td align="middle"><input type="text" name="email[]" style="width:120px;" class="stxt"></td><td align="middle"><input type="text" name="email[]" style="width:120px;" class="stxt"></td></tr><tr><td align="middle"><input type="text" name="email[]" style="width:120px;" class="stxt"></td><td align="middle"><input type="text" name="email[]" style="width:120px;" class="stxt"></td></tr><tr><td align="middle"><input type="text" name="email[]" style="width:120px;" class="stxt"></td><td align="middle"><input type="text" name="email[]" style="width:120px;" class="stxt"></td></tr><tr><td colspan="2" align="middle"><input type="image" src="invite.jpg"></td></tr></table><input type="hidden" name="manualinvite" value="1"></form></div>';
object.src='close.jpg';
var stat=1;
}else{obj.innerHTML=''; object.src='mi.jpg'; var stat=0;}
return stat;
}

function select_all(CheckValue){
	var objCheckBoxes = document.forms['formlist'].elements['selcontacts[]'];
	if(!objCheckBoxes)
	return;

	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

--></script>
</head>

<body>
<div style="text-align:center;">
<img border="0" src="<?php echo @$setpicture;?>" width="132" height="58"></div>
<br/>
<div style="text-align:center; margin:0px auto;">
<?php
/*Auto Detect Script Available*/
$prt=null;
foreach($importerinfo as $name=>$path){
if(file_exists($path)){
	if($prt==null){$prt.="| <a onmouseover=\"this.className='tabhover';\" onmouseout=\"this.className='tab';\" class=\"tab\" href=\"index.php?lib=".urlencode($path)."\">".htmlspecialchars($name,ENT_QUOTES)."</a> |";}else{$prt.=" <a onmouseover=\"this.className='tabhover';\" onmouseout=\"this.className='tab';\" class=\"tab\" href=\"index.php?lib=".urlencode($path)."\">".htmlspecialchars($name,ENT_QUOTES)."</a> |";}
	}
}
echo "<div style=\"margin-bottom:8px;\">".$prt."</div>";
?>
	<div style="text-align:left; width:350px; margin:0px auto; padding:8px; border-top:1px solid #ddd; border-left:1px solid #ddd; border-right:1px solid #ccc; border-bottom:1px solid #ccc; background-image:url(bg.jpg); background-repeat:repeat-x;" class="stxt">
		<div><div style="float:left;">
		<?php 
		if(@$imode==0)
		{ 
		?>
			<img src="enter.gif">
		<?php 
		} 
		elseif(@$imode==1)
		{ 
		?>
			<img src="selectfile.gif">
		<?php 
		} 
		?>
		</div>
		<div style="float:right;"><a onclick="javascript:history.back();" href="javascript:void(0);"><img title="Go Back" alt="Go Back" src="back.gif"></a></div><br clear="both"/></div>
		<form method="POST" action="index.php?lib=<?php echo urlencode($defaultimporterlib);?>" enctype="multipart/form-data">
<?php 
if(@$imode==0)
{ 
?>
				<table border="0" cellpadding="2" width="100%" class="stxt" cellspacing="2">
					<tr>
						<td width="100"><label for="email">E-mail Address:</label></td>
						<td>
						<input type="text" id="email" name="EmailAddress" style="width:120px;" class="stxt" value="<?php echo htmlspecialchars(stripslashes(@$_POST['EmailAddress']),ENT_QUOTES);?>"><?php if(@$showemailtxt){ ?> @<?php echo htmlspecialchars(@$emaildomain,ENT_QUOTES);?><?php }?></td>
					</tr>
					<tr>
						<td width="100"><label for="password">Password:</label></td>
						<td><input type="password" id="password" name="Passwd" style="width:100px;" class="stxt"></td>
					</tr>
					<tr>
						<td width="100"></td>
						<td><input type="button" class="smt" onclick="this.value='Please wait. Importing...'; this.disabled=true; this.form.submit();" value="Import Now"></td>
					</tr>
				</table>
<?php 
}
elseif(@$imode==1)
{ 
?>
				<table border="0" cellpadding="2" width="100%" class="stxt" cellspacing="2">
					<tr>
						<td width="100"><label for="fileupload">Select CSV File:</label></td>
						<td>
						<input type="file" id="fileupload" name="fupload" style="width:120px;" class="stxt" value="<?php echo htmlspecialchars(stripslashes(@$_POST['fupload']),ENT_QUOTES);?>"></td>
					</tr>
					<tr>
						<td width="100"></td>
						<td><input type="button" class="smt" onclick="this.value='Please wait. Importing...'; this.disabled=true; this.form.submit();" value="Import Now"></td>
					</tr>
				</table>
<?php 
}
?>
				<input type="hidden" name="update" value="1">
		</form>
	</div>
<br/><br/>
<div class="stxt"><?php echo @$output;?></div>

<!--Remove Powered By Tag / Manual Invite System. You may remove the line below-->
<br/><br/>
<div id="manual" class="stxt"></div>
<div class="stxt" style="background-image: url(ln.jpg); background-repeat: repeat-x; border-top:1px solid #eee; border-bottom:1px solid #eee; background-color:#f7f7f7; padding:6px;">
<img align="absmiddle" src="power.gif"> Powered by <a target="_blank" href="http://www.xceog.net/?i">XgContacts Importer v<?php echo htmlspecialchars($scriptversion,ENT_QUOTES);?></a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript: void(0);"><img id="mi" name="mi" onclick="javascript:stat=changestat(this,stat,document.getElementById('manual'));" align="absmiddle" src="mi.jpg"></a> <a href="mailto:suggestion@xceog.net"><img align="absmiddle" src="suggestions.jpg"></a>
<br/><br/>
<span class="st"><b>Warning:</b> All trademarks belong to their respective owners.</span>
</div>
<!--Do not remove the line below-->

</div>
</body>

</html>