<?php

if( ! defined( 'DATALIFEENGINE' ) ) {
	die( "Hacking attempt!" );
}


$skin_header = <<<HTML
<html dir=rtl>
<head>
<title>Datalife Engine Farsi - آپگرید به نسخه جدید</title>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<!-- calendar stylesheet -->
<link rel="stylesheet" type="text/css" media="all" href="{$theme}/skins/calendar-blue.css" title="win2k-cold-1" />
<link rel="stylesheet" type="text/css" media="all" href="{$theme}/skins/default.css" />

<!-- main calendar program -->
<script type="text/javascript" src="{$theme}/skins/calendar.js"></script>
<script type="text/javascript" src="{$theme}/skins/default.js"></script>

<!-- language for the calendar -->
<script type="text/javascript" src="{$theme}/skins/calendar-fa.js"></script>

<!-- the following script defines the Calendar.setup helper function, which makes
adding a calendar a matter of 1 or 2 lines of code. -->
<script type="text/javascript" src="{$theme}/skins/calendar-setup.js"></script>
<script type="text/javascript" src="{$theme}/skins/jalali.js"></script>

</head>
<body>
<table align="center" width="94%">
    <tr>
        <td width="4" height="16"><img src="{$theme}/skins/images/tb_left.gif" width="4" height="16" border="0" /></td>
		<td background="{$theme}/skins/images/tb_top.gif"><img src="{$theme}/skins/images/tb_top.gif" width="1" height="16" border="0" /></td>
		<td width="4"><img src="{$theme}/skins/images/tb_right.gif" width="3" height="16" border="0" /></td>
    </tr>
	<tr>
        <td width="4" background="{$theme}/skins/images/tb_lt.gif"><img src="{$theme}/skins/images/tb_lt.gif" width="4" height="1" border="0" /></td>
		<td valign="top" style="padding-top:12px; padding-left:13px; padding-right:13px;" bgcolor="#FAFAFA">
		
<table width="100%">
    <tr>
        <td bgcolor="#EFEFEF" height="29"><div class="navigation"> </td>
        <td bgcolor="#EFEFEF" height="29" align="right" style="padding-right:10px;"><div class="navigation">آپگرید دیتالایف انجین از نسخه قدیمی به نسخه جدید</td>
    </tr>
</table>

<div style="padding-top:5px;">
<table width="100%">
    <tr>
        <td width="4"><img src="{$theme}/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
        <td background="{$theme}/skins/images/tl_oo.gif"><img src="{$theme}/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
        <td width="6"><img src="{$theme}/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
    </tr>
    <tr>
        <td background="{$theme}/skins/images/tl_lb.gif"><img src="{$theme}/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
        <td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
    <tr>
        <td  width="267"><img src="{$theme}/skins/images/nav.jpg" width="311" height="99" border="0"></td>
        <td background="{$theme}/skins/images/logo_bg.gif">&nbsp;</td>
        <td width="301"><img src="{$theme}/skins/images/logos.jpg" height="99" border="0"></td>
    </tr>
</table>
</td>
        <td background="engine/skins/images/tl_rb.gif"><img src="{$theme}/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
    </tr>
    <tr>
        <td><img src="{$theme}/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
        <td background="{$theme}/skins/images/tl_ub.gif"><img src="{$theme}/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
        <td><img src="{$theme}/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
    </tr>
</table>
</div>
<!--MAIN area-->
HTML;

$skin_footer = <<<HTML
	 <!--MAIN area-->
<div style="padding-top:5px; padding-bottom:10px;">
<table width="100%">
    <tr>
        <td bgcolor="#EFEFEF" height="40" align="center" style="padding-right:10px;"><div class="navigation">System Powered By: <a href="http://datalifeengine.ir/" title="DataLife Engine" target="_blank"><B>Datalife Engine</b></a> v9.3<br />Copyright &copy; <B title="1385 - 1390">2006-2011</b> By <a href="http://datalifeengine.ir" title="سيستم مديريت محتواي فارسي ديتالايف انجين" target="_blank">Datalife Engine Farsi</a> , All rights reserved</div></td>
    </tr>
</table></div>		
		</td>
		<td width="4" background="{$theme}/skins/images/tb_rt.gif"><img src="{$theme}/skins/images/tb_rt.gif" width="4" height="1" border="0" /></td>
    </tr>
	<tr>
        <td height="16" background="{$theme}/skins/images/tb_lb.gif"></td>
		<td background="{$theme}/skins/images/tb_tb.gif"></td>
		<td background="{$theme}/skins/images/tb_rb.gif"></td>
    </tr>
</table>
</body>

</html>
HTML;

function msgbox($type, $title, $text, $back=FALSE){
global $lang, $theme;

  if($back){
        $back = "<br /><br/> <a class=main href=\"$back\">$lang[func_msg]</a>";
  }

  echoheader($type, $title);

echo <<<HTML
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%">
    <tr>
        <td width="4"><img src="{$theme}/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
        <td background="{$theme}/skins/images/tl_oo.gif"><img src="{$theme}/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
        <td width="6"><img src="{$theme}/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
    </tr>
    <tr>
        <td background="{$theme}/skins/images/tl_lb.gif"><img src="{$theme}/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
        <td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
    <tr>
        <td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$title}</div></td>
    </tr>
</table>
<div class="unterline"></div>
<table width="100%">
    <tr>
        <td height="100" align="center">{$text} {$back}</td>
    </tr>
</table>
</td>
        <td background="{$theme}/skins/images/tl_rb.gif"><img src="{$theme}/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
    </tr>
    <tr>
        <td><img src="{$theme}/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
        <td background="{$theme}/skins/images/tl_ub.gif"><img src="{$theme}/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
        <td><img src="{$theme}/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
    </tr>
</table>
</div>
HTML;
  echofooter();
exit();
}

$login_panel = <<<HTML
<form  name="login" action="{$PHP_SELF}" method="post"><input type="hidden" name="action" value="dologin">
<div style="padding-top:5px;">
<table width="100%">
    <tr>
        <td width="4"><img src="{$theme}/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
        <td background="{$theme}/skins/images/tl_oo.gif"><img src="{$theme}/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
        <td width="6"><img src="{$theme}/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
    </tr>
    <tr>
        <td background="{$theme}/skins/images/tl_lb.gif"><img src="{$theme}/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
        <td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
    <tr>
        <td bgcolor="#EFEFEF" height="29" style="padding-right:10px;"><div class="navigation">صفحه ورود مدیریت</div></td>
    </tr>
</table>
<div class="unterline"></div>
<table width="100%">
    <tr>
        <td width="55" style="padding:5px;" rowspan="2"><img src="{$theme}/skins/images/key.png" border="0"></td>
        <td width="70" style="padding:5px;">نام کاربری:</td>
        <td><input class="edit bk" type="text" name="username" value='' size="20">&nbsp;&nbsp;</td>
    </tr>
    <tr>
        <td style="padding:5px;">کلمه عبور:</td>
        <td><input class="edit bk" type="password" name="password" size="20">&nbsp;&nbsp;<input type="submit" class="edit" value="انجام"></td>
    </tr>
</table>
<div class="hr_line"></div>
<div class="navigation">برای آپگرید نسخه ی دیتالایف انجین به ورژن جدید، اطلاعات مدیریت رو وارد کنید.</div>
</td>
        <td background="{$theme}/skins/images/tl_rb.gif"><img src="{$theme}/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
    </tr>
    <tr>
        <td><img src="{$theme}/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
        <td background="{$theme}/skins/images/tl_ub.gif"><img src="{$theme}/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
        <td><img src="{$theme}/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
    </tr>
</table>
</div></form>
HTML;

$is_logged = false;

if ($_SESSION['member_name'] != "") {

$member_name = $db->safesql($_SESSION['member_name']);
$password = $db->safesql($_SESSION['member_password']);

if (version_compare($version_id, '4.2', ">")) $password = md5($_SESSION['member_password']);
if (!defined('USERPREFIX')) {
define('USERPREFIX', PREFIX);
}

$db->query("SELECT * FROM " . USERPREFIX . "_users where name='$member_name' and password='$password' and user_group = '1'");

if ($db->num_rows() > 0){
$member_id = $db->get_row();
$is_logged = TRUE;
}

$db->free();
}

if ($_POST['action'] == "dologin")
{

$login_name = $db->safesql($_POST['username']);

$login_password = md5($_POST['password']);

if (version_compare($version_id, '4.2', ">")) $pass = md5($login_password); else $pass = $login_password;
if (!defined('USERPREFIX')) {
define('USERPREFIX', PREFIX);
}

$db->query("SELECT * FROM " . USERPREFIX . "_users where name='$login_name' and password='$pass' and user_group = '1'");

if ($db->num_rows() > 0){

		$member_id = $db->get_row();

        $_SESSION['member_name']        = $member_id['name'];
        $_SESSION['member_password']    = $login_password;

        $is_logged = TRUE;
}

$db->free();
}

if(!is_writable(ENGINE_DIR.'/data/config.php')){
msgbox("info","خطا", "لطفاً سطح دسترسی فایل 'engine/data/config.php' را روی 666 قرار دهید.");
}
if(!is_writable(ENGINE_DIR.'/data/dbconfig.php')){
msgbox("info","خطا", "لطفاً سطح دسترسی فایل 'engine/data/dbconfig.php' را روی 666 قرار دهید.");
}

if (!$is_logged)
{
echoheader('', '');
echo $login_panel;
echofooter();
exit();
}

?>