<?php
session_start();
include("connect.php");
include("includes/func_links.php");
$folder=$folderlinks;
$action = $_GET['action'];
if(!isset($action)) $action = "home";

IF ($action=="home"){
$m1=$d4;
$m2=$k4;
tpl_header($LANGAUGE[54]);
bar($namelinks1,$LANGAUGE[54],"","");
if ($htmlorphp=="1"){
$prl = "addsite.html";
}else{
$prl = "links.php?action=addsite";
}
table($LANGAUGE[54],'<h2 style="text-align:center; padding:5px 0 5px 0;"><a href="'.$prl.'">'.$LANGAUGE[294].'</a></h2>'.aldleel_cats(),1);

tpl_footer();

}ELSEIF ($action=="islam_dlil"){
$id = intval($_GET["id"]);

$sql = @mysql_query("select * from dlil_cat where id='$id' AND active='1'");
$Row = @mysql_fetch_array($sql);
if (!$Row)
{
error();
exit;
}
$names_cats = text(3,$Row['name_cat']);
$id_cats    = $Row['id'];

tpl_header($names_cats);
bar($namelinks1,$namelinks5,$names_cats,"");

table($names_cats,aldleel_sites(),1);

tpl_footer();

}ELSEIF ($action=="islam_dlil_go"){
$id = intval($_GET["id"]);

$sql = @mysql_query("select * from islam_dlil where id='$id' AND active='1'");
$Row = @mysql_fetch_array($sql);
if (!$Row)
{
error();
exit;
}
$Row['url_site'] = text(3,$Row['url_site']);

$sql2 = @mysql_query("update islam_dlil set vis=vis+1 where id='$id'")  or die ("Query failed");
echo "<meta http-equiv='Refresh' content='1;URL=".$Row['url_site']."' />";

}ELSEIF ($action=="addsite"){
$text1 = rand(0,9);
$text2 = rand(0,9);
$text3 = "<label for='xzx5'>".$LANGAUGE[176]." ".$text1." + ".$text2."</label>";
$text4 = $text1 + $text2;
$_SESSION["captchacode"] = $text4;

tpl_header($LANGAUGE[294]);
bar($namelinks1,$namelinks5,$LANGAUGE[294],"");

if ($htmlorphp=="1"){
$li = "insertsite.html";
}else{
$li = "links.php?action=insertsite";
}

$dd = "<form name='vbform' method='post' action='$li'>

<label for='xd1'>".$LANGAUGE[233]."</label><br />
<input id='xd1' size='60' name='name_site' /><br /><br />

<label for='xd2'>".$LANGAUGE[234]."</label><br />
<input id='xd2' size='60' name='text_site' /><br /><br />

<label for='xd2x'>".$LANGAUGE[240]."</label><br />
<input id='xd2x' size='60' name='keywords' /><br /><br />

<label for='xd3'>".$LANGAUGE[235]."</label><br />
<input id='xd3' size='60' name='url_site' /><br /><br />

<label for='xd4'>".$LANGAUGE[236]."</label><br />
<select id='xd4' size='1' name='lang'>
<option value='0' selected='selected'>".$LANGAUGE[237]."</option>
<option value='1'>".$LANGAUGE[238]."</option>
</select><br /><br />

<label for='xd5'>".$LANGAUGE[239]."</label><br />
<select id='xd5' size='1' name='cat'>";
$sql = mysql_query ("SELECT * FROM dlil_cat where active='1' order by id asc,sub desc");
while($cat=mysql_fetch_array($sql))
{
$cat['name_cat'] = text(3,$cat['name_cat']);
if($cat['sub']==0){
$sss = "&nbsp;";
}else{
$sss = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
$dd .= "<option value='".$cat['id']."'>".$sss."".$cat['name_cat']."</option>";
}
$dd .= "</select><br /><br />

".$text3." <input id='xzx5' name='code' size='10' /><br /><br />

<input type='submit' value=' ".$LANGAUGE[241]." ' name='cmdAdd' />

</form>";

table($LANGAUGE[294],$dd,1);

tpl_footer();

}ELSEIF ($action=="insertsite"){
if($_POST['code'] != $_SESSION['captchacode'] OR $_SESSION["captchacode"]=='')
{
tpl_header($LANGAUGE[126]);
table($LANGAUGE[126],$LANGAUGE[178],1);
tpl_footer();
exit;
}
$d = time();
$name_site = text(1,$_POST['name_site']);
$url_site  = text(1,$_POST['url_site']);
$text_site = text(1,$_POST['text_site']);
$keywords = text(1,$_POST['keywords']);
$lang = text(1,$_POST['lang']);
$cat = $_POST['cat'];

if($text_site==""){
$xm1 = $name_site;
}else{
$xm1 = $text_site;
}

if($keywords==""){
$m2x = str_replace(" ",",",$name_site);
$xm2 = $m2x;
}else{
$xm2 = $keywords;
}

if ($htmlorphp=="1"){
$li = "index.html";
}else{
$li = "index.php";
}
$eee = "";

if (empty($name_site)){
$eee .= $LANGAUGE[133];
$chch = "no";
}

if (empty($url_site)){
$eee .= $LANGAUGE[134];
$chch = "no";
}

if (empty($text_site)){
$eee .= $LANGAUGE[135];
$chch = "no";
}

$queryx = mysql_query("SELECT * FROM islam_dlil where url_site='$url_site'");
$xx = mysql_num_rows($queryx);
if($xx != 0){
$eee .= $LANGAUGE[136];
$chch = "no";
}

if($chch != "no"){
$query = mysql_query ("INSERT INTO islam_dlil (name_site,url_site,cat,text_site,lang,active,date,keywords) VALUES ('$name_site','$url_site','$cat','$xm1','$lang','0','$d','$xm2')");
$eeex = $LANGAUGE[137];
$eeex .= "<META HTTP-EQUIV='refresh' CONTENT='3; URL=$li' />";
}else{
$eeex = $eee.$LANGAUGE[131];
}
tpl_header($LANGAUGE[54]);
bar($namelinks1,$LANGAUGE[126],"","");

table($LANGAUGE[126],$eeex,1);

tpl_footer();

}ELSEIF ($action=="show"){
$id = intval($_GET["id"]);

$sql = @mysql_query("select * from islam_dlil where id='$id' AND active='1'");
$Row = @mysql_fetch_array($sql);
if (!$Row)
{
error();
exit;
}
$Row['name_site'] = text(3,$Row['name_site']);
$Row['url_site'] = text(3,$Row['url_site']);
$Row['text_site'] = text(3,$Row['text_site']);

$m1 = text(3,$Row['text_site']);
$m2 = text(3,$Row['keywords']);

$img = "<a href='".$Row['url_site']."' title='".$Row['url_site']."'><img src='http://images.websnapr.com/?url=".$Row['url_site']."' border='0' /></a>";
$google = "<a target='_blank' href='http://www.google.com/search?q=site:".$Row['url_site']."'>".$LANGAUGE[291]."</a> - <a target='_blank' href='http://www.google.com/search?q=link:".$Row['url_site']."'>".$LANGAUGE[292]."</a> - <a target='_blank' href='http://www.google.com/search?q=cache:".$Row['url_site']."'>".$LANGAUGE[293]."</a>";
$alexa = "<script type='text/javascript' language='JavaScript' src='http://xslt.alexa.com/site_stats/js/t/a?url=".$Row['url_site']."'></script>";
/*
//start
function findit($mytext,$starttag,$endtag) {
        $posLeft  = stripos($mytext,$starttag)+strlen($starttag);
        $posRight = stripos($mytext,$endtag,$posLeft+1);
        return  substr($mytext,$posLeft,$posRight-$posLeft);
}
$url = 'http://www.alexa.com/siteinfo/'.$Row['url_site'].'';
$page = file_get_contents($url);
$result = findit($page,'<div class="data up">','</div>');
$text = str_replace('<img src="/images/icons/globe-sm.jpg" alt="Global" style="margin-bottom:-2px;"/>','',$result);
$text = str_replace('</a>','',$text);
//end
*/

if($m1==""){
$des = $Row['name_site'];
}else{
$des = $m1;
}

if($m2==""){
$des0 = str_replace(" ",",",$Row['name_site']);
}else{
$des0 = $m2;
}

if ($htmlorphp=="1"){
$pr = "<a target='_blank' href='aldlel_gosite-$Row[id].html'>".cuttext(120, $Row['url_site'], "")."</a>";
}else{
$pr = "<a target='_blank' href='links.php?action=islam_dlil_go&id=$Row[id]'>".cuttext(120, $Row['url_site'], "")."</a>";
}

$sql2 = @mysql_query("SELECT * FROM dlil_cat where id='".$Row['cat']."'") or die ("Query failed3");
$cats = @mysql_fetch_array($sql2);
$catnamef = text(3,$cats['name_cat']);

if ($htmlorphp=="1"){
$printcats = "<a href='aldlel_cat-".$cats['id'].".html'>".$catnamef."</a>";
}else{
$printcats = "<a href='links.php?action=islam_dlil&id=".$cats['id']."'>".$catnamef."</a>";
}

$dd = "<table class='xtable' width='100%' id='AutoNumbler15'>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE[233]."</td>
<td width='70%' class='xtd'>".$Row['name_site']."</td>
</tr>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE[235]."</td>
<td width='70%' class='xtd'>".$pr."</td>
</tr>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE[242]."</td>
<td width='70%' class='xtd'>".$Row['vis']."</td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE[234]."</td>
<td width='70%' class='xtd'>".$des."</td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE[240]."</td>
<td width='70%' class='xtd'>".$m2."</td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE[243]."</td>
<td width='70%' class='xtd'>".$google."</td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE[239]."</td>
<td width='70%' class='xtd'>".$printcats."</td>
</tr>


<tr>
<td width='30%' class='xtr'>".$LANGAUGE[244]."</td>
<td width='70%' class='xtd'>".$alexa."</td>
</tr>

</table>";

tpl_header($Row['name_site']);
bar($namelinks1,$namelinks5,$printcats,$Row['name_site']);
table($Row['name_site'],$dd,1);
tpl_footer();
}
?>