<?php
include_once("../include/main.inc.php");
include_once("../ajax_functions.php");
check_session('MyCpanel','index.php');

################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start)==0 or $start=="")?$start=0:$start;
$pagesize = intval($pagesize)==0?$pagesize=10:$pagesize;

$heading="Companies URL List Creation";
$record_type="member";
$script_name="ap-company-url-list.php";
$table_name="company_url";

admin_header();
?>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
 <tr>
	<td align="left" width="50%" class="myTitle"><?=$heading;?></td>
	<td align="right">
	 <form name="pg_form" action="<?=$PHP_SELF?>" method="post" style="margin:0px;padding:0px;">
	 <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
	  <tr>
	   <td align="right">Companies URL List Creation: <br>
	   <?
	   
	   
	     
	$urlqry=mysql_query("select memberID,companyName from member_tbl where url_status='N' AND companyName!='' ORDER BY memberID ASC");
    while($urlres=mysql_fetch_array($urlqry)) {
	$companylist=strtolower(trim($urlres[companyName]));
	$memberID1=$urlres[memberID];
	//echo $memberID1;
	if ($companylist!= '') {
	$companypattern="[?()\/&#\,\;\.$]";
	$companylist=ereg_replace($companypattern,"",$companylist);	
	$companylist=str_replace("'","",$companylist);
	$companylist=str_replace("pvt","",$companylist);
	$companylist=str_replace("ltd","",$companylist);
	$companylist=str_replace("private","",$companylist);
	$companylist=str_replace("limted","",$companylist);
	$companylist=str_replace("corp","",$companylist);
	$companylist=str_replace("corporation","",$companylist);
	$companylist=str_replace("Pty","",$companylist);
	$companylist=str_replace("org","",$companylist);
	$companylist=str_replace("organisation","",$companylist);
	$companylist=str_replace("public","",$companylist);
	$companylist=str_replace("nig","",$companylist);
	$companylist=str_replace(".","",$companylist);
	$companylist=str_replace("_","",$companylist);
	$companylist=str_replace("-","",$companylist);

	$companylist = wordwrap($companylist, 60);
	$companylist=substr($companylist,0,60);
//echo $companylist;
	$companyurl=GetValidFileName(trim($companylist));
	$urlqry1=mysql_query("select member_url from company_url where member_url='$companyurl'"); 
	$urlres1=mysql_fetch_array($urlqry1);
	$url1=$urlres1[member_url];
	
	if($companyurl==$url1) {
	 $companyurl=str_replace("-","","$companyurl");
	$sql=db_query("insert into $table_name set memberID='$memberID1', member_url='$companyurl'");
	updateTable("member_tbl"," url_status='Y'  where memberID='$memberID1'"); 
	echo $companyurl."<br>";
	echo "Duplicate Success";

	}else {  
	$sql=db_query("insert into $table_name set memberID='$memberID1', member_url='$companyurl'");
	updateTable("member_tbl"," url_status='Y'  where memberID='$memberID1'");
	echo $companyurl."<br>";
	echo "Success";
		//header('Refresh: 0.1');      
	
	}
	}
	}
	//header('Refresh: 0.1');      
	exit;

     

?>
	   
		 </td>
		</tr>
	 </table>
	 </form>
	</td>
 </tr>
</table>


<?php
admin_footer();	
exit;
?>