<?php
include("include/config.php");
include("include/protect.class.php");
include("include/functions.php");
include("include/jdf.php");
$prot = new protect();
if ($prot->showPage) {
$db = new DB($globalConfig['dbase'], $globalConfig['dbhost'], $globalConfig['dbuser'],$globalConfig['dbpass']);
if (isset($_GET['do'])) {
        $action = $_GET['do'];
}
switch($action){
//-------------------------------------------------------------------------------------
        	case 'pdelete':
            if (isset($_GET['confirm'])) {
                $db->execute("delete from chitaportal where portalID = '" . (int)$_GET['id'] . "'");
            }
            header("location: chitaPortal.php");
            break;
//-------------------------------------------------------------------------------
        	case 'pinsert':
            if (isset($_POST['Insert'])) {
                $res = $db->execute("insert into chitaportal set 
													title ='" . $db->safe_string($_POST['title']) . "',
													titleen ='" . $db->safe_string($_POST['titleen']) . "',
													soudPortal ='" . $db->safe_string($_POST['soudPortal']) . "',
													maliyat ='" . $db->safe_string($_POST['maliyat']) . "',
													linkPortal ='" . $db->safe_string($_POST['linkPortal']) . "',
													keywords ='" . addslashes($_POST['keywords']) . "',
													keywordsen ='" . addslashes($_POST['keywordsen']) . "',
													description ='" . addslashes($_POST['description']) . "',
													descriptionen ='" . addslashes($_POST['descriptionen']) . "',
													googleverification ='".addslashes($_POST['google-site-verification'])."',
													otherMeta ='" .addslashes($_POST['otherMeta']). "',
													status ='" . $db->safe_string($_POST['status']) . "',
													factorName ='" . $db->safe_string($_POST['factorName']) . "',
													factorCompany ='" . $db->safe_string($_POST['factorCompany']) . "',
													factorAddress ='" . $db->safe_string($_POST['factorAddress']) . "',
													factorHesab ='" . $db->safe_string($_POST['factorHesab']) . "',
													factorTell ='" . $db->safe_string($_POST['factorTell']) . "',
													factorShenaseSabt ='" . $db->safe_string($_POST['factorShenaseSabt']) . "',
													factorShenaseMeli ='" . $db->safe_string($_POST['factorShenaseMeli']) . "',
													factorCodeEghtesadi ='" . $db->safe_string($_POST['factorCodeEghtesadi']) . "' ");
            }
			 break;
        	case 'update':
            if (isset($_POST['Insert'])) {
                $res = $db->execute("update  chitaportal set 
													title ='" . $db->safe_string($_POST['title']) . "',
													titleen ='" . $db->safe_string($_POST['titleen']) . "',
													soudPortal ='" . $db->safe_string($_POST['soudPortal']) . "',
													maliyat ='" . $db->safe_string($_POST['maliyat']) . "',
													linkPortal ='" . $db->safe_string($_POST['linkPortal']) . "',
													keywords ='" . addslashes($_POST['keywords']) . "',
													keywordsen ='" . addslashes($_POST['keywordsen']) . "',
													description ='" . addslashes($_POST['description']) . "',
													descriptionen ='" . addslashes($_POST['descriptionen']) . "',
													googleverification ='".addslashes($_POST['google-site-verification'])."',
													otherMeta ='" .addslashes($_POST['otherMeta']). "',
													status ='" . $db->safe_string($_POST['status']) . "',
													factorName ='" . $db->safe_string($_POST['factorName']) . "',
													factorCompany ='" . $db->safe_string($_POST['factorCompany']) . "',
													factorAddress ='" . $db->safe_string($_POST['factorAddress']) . "',
													factorHesab ='" . $db->safe_string($_POST['factorHesab']) . "',
													factorTell ='" . $db->safe_string($_POST['factorTell']) . "',
													factorShenaseSabt ='" . $db->safe_string($_POST['factorShenaseSabt']) . "',
													factorShenaseMeli ='" . $db->safe_string($_POST['factorShenaseMeli']) . "',
													factorCodeEghtesadi ='" . $db->safe_string($_POST['factorCodeEghtesadi']) . "'
													where portalID='".$_POST['portalID']."' ");
            }			
            header("location: chitaPortal.php");
            break;
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>مدیریت پرتال </title>
<?php include("maintemplate/mainheader.php");?>
</head>
<body>
<div id="wpwrap">
<div id="wpcontent">
	<?php include("include/menutop.php");?> 
<div id="wpbody">
	<?php include("include/header.php");?>
    <div style="overflow:hidden;" id="wpbody-content">
        <div id="screen-meta">
            <div class="wrap">
                <div id="icon-index" class="icon32"><br></div>
                <h2>مدیریت پرتال</h2>
                <div id="dashboard-widgets-wrap">
                    <div id="dashboard-widgets" class="metabox-holder">
                        <div class="postbox-container" style="width:100%;">
                            <div id="normal-sortables" class="meta-box-sortables ui-sortable"><div id="dashboard_recent_comments" class="postbox ">  
                    <div class="handlediv" title="برای جانشینی کلیک کنید"><br></div><h3 class="hndle"><span>مدیریت پرتال  </span></h3>
<?php
    if ($_GET['act'] == 'delete') {
        if (!isset($_GET['confirm'])) {
            echo 'آيا شما مطمئنيد؟ <br /> <a href="chitaPortal.php?do=pdelete&id=' . (int)$_GET['pID'] .
                '&confirm"> بلــــه </a> | <a href="chitaPortal.php"> خيـــــر </a> ';
        }
    }

switch ($action) {
//-------------------------------------------------------------------------------------
default:
            $sql2 = $db->query("select * from chitaportal where portalID='" . $_GET['id'] . "'");
            $res2 = $db->fetchNextArray($sql2);
            $num = $db->numRows($sql2);
                if($_GET['act']=='edite'){
                	$act = 'do=update';
				}else{
					$act = 'do=pinsert';
				}
?>
             <form action="chitaPortal.php?<?= $act ?>" method="post">
  	               <table  class="table_insert" cellpadding="3" cellspacing="3" width="90%" align="center" >
                      <tr>
                         <td class="td_d">سود کلی سایت  :</td>
                         <td class="td_d"><input type="text" name="soudPortal" value="<?=$res2['soudPortal']?>"/> % </td>            
                       </tr>                   
                                      
                      <tr>
                         <td class="td_d">مالیات بر ارزش افزوده  :</td>
                         <td class="td_d"><input type="text" name="maliyat" value="<?=$res2['maliyat']?>"/> % </td>            
                      </tr>                     
                      <tr>
                         <td class="td_d">آدرس پرتال :</td>
                         <td class="td_d"><input type="text" name="linkPortal" value="<?=$res2['linkPortal']?>"/></td>            
                       </tr>
                       
                       <tr>
                          <td class="td_d">title :</td>
                          <td class="td_d"><input type="text" name="title" value="<?=$res2['title']?>"/></td> 
                       </tr>
                       <tr>
                          <td class="td_d">title en :</td>
                          <td class="td_d"><input type="text" name="titleen" value="<?=$res2['titleen']?>"/></td> 
                       </tr>
                              
						<tr>
                         	<td class="td_d">keywords :</td>
                            <td class="td_d"><textarea  name="keywords" ><?=$res2['keywords']?></textarea></td>	
						</tr>
                        <tr>
                         	<td class="td_d">keywords en :</td>
                            <td class="td_d"><textarea  name="keywordsen" ><?=$res2['keywordsen']?></textarea></td>	
						</tr>  
                              
						<tr>
                         	<td class="td_d">description :</td>
                            <td class="td_d"><textarea  name="description" ><?=$res2['description']?></textarea></td>	
						</tr>
                        
                        <tr>
                         	<td class="td_d">description en:</td>
                            <td class="td_d"><textarea  name="descriptionen" ><?=$res2['descriptionen']?></textarea></td>	
						</tr>
                        
						<tr>
                         	<td class="td_d">google-site-verification :</td>
                            <td class="td_d"><textarea  name="google-site-verification" ><?=$res2['googleverification']?></textarea></td>	
						</tr>                           
                        
						<tr>
                         	<td class="td_d">other Meta :</td><td class="td_d"><textarea  name="otherMeta" ><?=$res2['otherMeta']?></textarea></td>	
						</tr>                         

                         
						<tr>
                         	<td class="td_d" colspan="2"><hr /><b>اطلاعات فاکتور </b><br /><hr /></td>	
						</tr>                          
                          
						<tr>
                         	<td class="td_d">نام فاکتور :</td><td class="td_d"><textarea  name="factorName" ><?=$res2['factorName']?></textarea></td>	
						</tr> 
                        
						<tr>
                         	<td class="td_d">نام شرکت :</td><td class="td_d"><textarea  name="factorCompany" ><?=$res2['factorCompany']?></textarea></td>	
						</tr> 
                        
						<tr>
                         	<td class="td_d">آدرس فاکتور :</td><td class="td_d"><textarea  name="factorAddress" ><?=$res2['factorAddress']?></textarea></td>	
						</tr> 
                        
						<tr>
                         	<td class="td_d">شماره حساب:</td><td class="td_d"><textarea  name="factorHesab" ><?=$res2['factorHesab']?></textarea></td>	
						</tr> 
                        
						<tr>
                         	<td class="td_d">اطلاعات تماس :</td><td class="td_d"><textarea  name="factorTell" ><?=$res2['factorTell']?></textarea></td>	
						</tr>                                                                                                 
                     
						<tr>
                         	<td class="td_d">شماره ثبت :</td><td class="td_d"><input  name="factorShenaseSabt"  value="<?=$res2['factorShenaseSabt']?>"/></td>	
						</tr>                                                                                                 
                        
						<tr>
                         	<td class="td_d">شناسه ملی :</td><td class="td_d"><input  name="factorShenaseMeli" value="<?=$res2['factorShenaseMeli']?>" ></td>	
						</tr>                                                                                                 
                                                                                   
						<tr>
                         	<td class="td_d">کد اقتصادی :</td><td class="td_d"><input  name="factorCodeEghtesadi" value="<?=$res2['factorCodeEghtesadi']?>" ></td>	
						</tr>                             
                                                  
                              
                     <tr>
                        <td colspan="2" align="center">
                        <?php
							echo '<input type="hidden" value="'.$res2['portalID'].'" name="portalID">';
                            echo '<input type="submit" name="Insert" value="ذخیره" />';                
            			?>
                          </td>
                    </tr>
        </table>        
        </form>	
            <?php
            $sql = $db->query("select * from chitaportal  ORDER BY portalID  ");
            echo '<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0"  class="table1" >';
            echo '<tr>
					  <th class="td_header">title</th>
					  <th class="td_header">سود </th>
					  <th class="td_header">مالیات </th>
					  <th class="td_header">address</th>
					  <th class="td_header">counter all</th>
					  <th class="td_header">counter now</th>
					  <th class="td_header">counter yesterday</th>
                  	  <th class="td_header" align="center" width="80px"> امکانات </th>
                  </tr>';
            while ($res = $db->fetchNextArray($sql)) {
                echo '<tr>
				<td  align=center class="tablebattom1">'.$res['title'].'</td>
				<td  align=center class="tablebattom1">'.$res['soudPortal'].' %</td>
				<td  align=center class="tablebattom1">'.$res['maliyat'].' %</td>
                <td  align=center class="tablebattom1">
							<a target="_blank" href="http://www.'.$res['linkPortal'].'">'.$res['linkPortal'].'</a></td>
				<td  align=center class="tablebattom1">'.$res['counter_all'].'</td>
				<td  align=center class="tablebattom1">'.$res['counter_now'].'</td>
				<td  align=center class="tablebattom1">'.$res['counter_yesterday'].'</td>
			 	<td  align=center class="tablebattom1">
                     <a href="chitaPortal.php?act=delete&pID='.$res['portalID'].'"><img border="0" src="images/dp.png"></a>
					 <a href="chitaPortal.php?act=edite&id='.$res['portalID'].'"><img border="0" src="images/ep.png"></a>
					 </td></tr>';
            }
            echo '</table>';
            break;
//-------------------------------------------------------------------------------------
}
?>
                           </div>
                          </div>
                        </div>                        
                    </div>
                    <div class="clear"></div>
                </div><!-- dashboard-widgets-wrap -->
            </div><!-- wrap -->
			<div class="clear"></div></div><!-- wpbody-content -->
			<div class="clear"></div></div><!-- wpbody -->
			<div class="clear"></div></div><!-- wpcontent -->
        </div>
    </div><!-- wpcontent -->
</div><!-- wpwrap -->
<?php include("include/footer.php");?>
</div>
</div>
</body>
</html><?php } ?>