<?php
include("include/config.php");
include("include/protect.class.php");
include("include/jdf.php");
include('include/functions.php');
include("include/thumbnail_create.php");
$prot=new protect();
if ($prot->showPage) {
$db=new DB($globalConfig['dbase'], $globalConfig['dbhost'],$globalConfig['dbuser'], $globalConfig['dbpass']);
$error=0;

?>
<!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>
<link href="css/dropdown/dropdown.vertical.rtl.css" media="all" rel="stylesheet" type="text/css" />
<?php include("maintemplate/mainheader.php");?>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="js/js_body.js"></script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox-1.3.1.css" media="screen" />
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="fancybox/jquery.fancybox-1.3.1.js"></script>
<script type="text/javascript">   
	function creationPage(p_id){
		$(document).ready(function() {
				$.fancybox.showActivity();
				$.ajax({
					type		: "POST",
					cache	: false,
					url		: "send_ajax_chitasoft.php?act=creationPage",
					data		: {'p_id':p_id},
					success: function(data) {
						$.fancybox(data);
					}
				});
				return false;		
		});
	}
	function insertPage(p_id){
		$(document).ready(function() {
				var title = $("#title").val();
				$.fancybox.showActivity();
				$.ajax({
					type		: "POST",
					cache	: false,
					url		: "send_ajax_chitasoft.php?act=insertPage",
					data: "p_id="+p_id+"&title="+title,
					success: function(data) {
						$.fancybox(data);
					}
				});
				return false;		
		});
	}

	function ListPage(p_id){
		$(document).ready(function() {
				var title = $("#title").val();
				$.fancybox.showActivity();
				$.ajax({
					type		: "POST",
					cache	: false,
					url		: "send_ajax_chitasoft.php?act=ListPage",
					data: "p_id="+p_id,
					success: function(data) {
						$.fancybox(data);
					}
				});
				return false;		
		});
	}

	function dellPage(p_id){
		$(document).ready(function() {
				var pattern = $("#pattern").val();
				$.fancybox.showActivity();
				$.ajax({
					type		: "POST",
					cache	: false,
					url		: "send_ajax_chitasoft.php?act=ListPage",
					data: "p_id="+p_id+"&dell=1",
					success: function(data) {
						$.fancybox(data);
					}
				});
				return false;		
		});
	}
    </script>
</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['dell']){
			
			 //select first
			 $e_product = $db->query("select * from page_index where cid='".$_GET['dell']."'");
			 $product= $db->fetchNextArray($e_product); 
			 //languages input
			$path2 = "../".$product['file'];
							
		$db->query("delete from page_index where cid='".$_GET['dell']."'");
		unlink("$path2") or die ('اپراتور قابل حذف نیست');
		header("location: admin_page_index.php");
	
}

if ($_POST["edit"]){
			 /////////////////////
			 //select first
			 $e_product = $db->query("select * from page_index where cid='".$_POST['cid']."'");
			 $product= $db->fetchNextArray($e_product); 
			 //languages input
			
			
			//check for the new pic. is not set any new pic
			$isFile = is_uploaded_file($_FILES['myfile']['tmp_name']);
			if (!$isFile){
					$path = $product['file'];
					}else {
						//unlink first
					
							$path2 = "../".$product['file'];
						unlink("$path2") or die ('اپراتور قابل حذف نیست');
								//  5MB maximum file size
$MAXIMUM_FILESIZE = 1 * 1024 * 1024;
//  Valid file extensions (images, word, excel, powerpoint)
$rEFileTypes =
  "/^\.(jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx|
        ppt|pptx){1}$/i";
$dir_base = "../upload/pages/";

$isFile = is_uploaded_file($_FILES['myfile']['tmp_name']);
if ($isFile)    //  do we have a file?
   {//  sanatize file name
    //     - remove extra spaces/convert to _,
    //     - remove non 0-9a-Z._- characters,
    //     - remove leading/trailing spaces
    //  check if under 5MB,
    //  check file extension for legal file types
    $safe_filename1 = preg_replace(
                     array("/\s+/", "/[^-\.\w]+/"),
                     array("_", ""),
                     trim($_FILES['myfile']['name']));
	$safe_filename = time().'-'.$safe_filename1;
    if ($_FILES['myfile']['size'] <= $MAXIMUM_FILESIZE &&
        preg_match($rEFileTypes, strrchr($safe_filename, '.')))
      {$isMove = move_uploaded_file (
                 $_FILES['myfile']['tmp_name'],
                 $dir_base.$safe_filename);}
      } else{//$cc=1;
	  }
// now time
			$path='upload/pages/'.$safe_filename.'';
					}	
	
	$sql="update page_index set type='".$_POST['type']."',
			type='".$_POST['type']."',
			title='".$db->safe_string($_POST['title'])."',
			keywords='".$db->safe_string($_POST['keywords'])."',
			descriptionHead='".$db->safe_string($_POST['descriptionHead'])."',
			userGroup='".get_user_group2()."',
			file='".$path."',
	 		description='".addslashes($_POST['description'])."' where cid='".$_POST['cid']."' ";
    $query= $db->query($sql);
        echo debug_message('صفحه با موفقیت ویرایش شد ...','2','');
		echo '<form action="admin_page_index.php" method="POST">
				<p align="center"><input type="submit" id="button" value="OK"></p>
		      </form>';	
			   
}elseif($_POST["Send"]){
											//  5MB maximum file size
$MAXIMUM_FILESIZE = 1 * 1024 * 1024;
//  Valid file extensions (images, word, excel, powerpoint)
$rEFileTypes =
  "/^\.(jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx|
        ppt|pptx){1}$/i";
$dir_base = "../upload/pages/";

$isFile = is_uploaded_file($_FILES['myfile']['tmp_name']);
if ($isFile)    //  do we have a file?
   {//  sanatize file name
    //     - remove extra spaces/convert to _,
    //     - remove non 0-9a-Z._- characters,
    //     - remove leading/trailing spaces
    //  check if under 5MB,
    //  check file extension for legal file types
    $safe_filename1 = preg_replace(
                     array("/\s+/", "/[^-\.\w]+/"),
                     array("_", ""),
                     trim($_FILES['myfile']['name']));
	$safe_filename = time().'-'.$safe_filename1;
    if ($_FILES['myfile']['size'] <= $MAXIMUM_FILESIZE &&
        preg_match($rEFileTypes, strrchr($safe_filename, '.')))
      {$isMove = move_uploaded_file (
                 $_FILES['myfile']['tmp_name'],
                 $dir_base.$safe_filename);}
      } else{$nn=1;}
	  
	  if($nn == 1){$path=0;}else{
		$path='upload/pages/'.$safe_filename.'';}
	
	
	$query=$db->query("insert into page_index set
		type='".$_POST['type']."',
		title='".$db->safe_string($_POST['title'])."',
		keywords='".$db->safe_string($_POST['keywords'])."',
		descriptionHead='".$db->safe_string($_POST['descriptionHead'])."',
		userGroup='".get_user_group2()."',
		file='".$path."',
		description='".addslashes($_POST['description'])."'");

        echo debug_message('صفحه با موفقیت ذخیره شد ...','2','');
		echo '<form action="admin_page_index.php" method="POST">
				<p align="center"><input type="submit" id="button" value="OK"></p>
		      </form>';	
}
$query_s=$db->query("select * from page_index  where cid='".$_GET['cid']."'");
$num_s=$db->numRows($query_s);
$row_s=$db->fetchNextArray($query_s);
?>
<form  action="admin_page_index.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table width="100%" border="0" align="center" cellpadding="3" cellspacing="3"  class="table_insert"  dir="ltr" >
	<tr>
    <td align="right"  dir="rtl" style="padding-right:20px" height="40px">
    <?php
		printCombobox('type', 'type', 'page_index_group', 'p_id', 'title',$row_s['type'], ' where groupID='.get_user_group2().'');
	?>
      </td>
    <td align="right" >گروه صفحه</td>
  </tr>    
    
	<tr>
    <td align="right"  dir="rtl" style="padding-right:20px" height="40px">
    <textarea name="title"><?=$row_s['title']?></textarea>
      </td>
    <td align="right" >title 	 </td>
  </tr>     
	<tr>
    <td align="right"  dir="rtl" style="padding-right:20px" height="40px">
    <textarea name="keywords"><?=$row_s['keywords']?></textarea>
      </td>
    <td align="right" >keywords </td>
  </tr>     
    
	<tr>
    <td align="right"  dir="rtl" style="padding-right:20px" height="40px">
    <textarea name="descriptionHead"><?=$row_s['descriptionHead']?></textarea>
      </td>
    <td align="right" >descriptionHead </td>
  </tr>     
    
    <tr>
      <td align="right">
			<textarea cols="80" id="description" name="description" rows="10"><?=$row_s['description']?></textarea>
			<script type="text/javascript">
			//<![CDATA[

				CKEDITOR.replace( 'description',
					{
						fullPage : true,
						extraPlugins : 'docprops'
					});

			//]]>
			</script>                   
                
      </td>
      <td align="right">محتوا </td>
    </tr>
    
    <tr>
      <td align="right">
			<?php if($_GET['cid']){ ?>
<div class="error_strings" style="padding:4px;">در صورتیکه قصد تغییر تصویر را ندارید این بخش را به همین صورت رها کنید</div>
<?php } ?>
<input name="myfile" id="myfile"  type="file" size="31" class="regular-text"  dir="rtl" accept="image/gif, image/jpeg"  />                  
                
      </td>
      <td align="right">تصویر</td>
    </tr>
    
	
     

  <tr><td> 
       <?php
	   if($num_s){
			  echo '<input type="hidden" value="'.$_GET['cid'].'"  name="cid" />
      		   		<input type="submit" id="button"  value="ویرایش"  name="edit" />';
	   	}else {  
      		  echo' <input type="submit" id="button"  value="ذخیره" name="Send" />';}
		?>
        </td><td></td></tr>
        
        
  </table>
</form>
<?php	
echo '
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" class="table1" dir=rtl>
<tr>
	<th class="td_header">لینک</th>
	<th class="td_header">نوع کادر</th>
	<th class="td_header">title</th>
	<th class="td_header">ویرایش </th>
</tr>';


$query="select * from page_index where userGroup = '".get_user_group2()."' order by cid";
$result=$db->query($query);
while($res=$db->fetchNextArray($result)){
echo '
<tr align="center" dir="rtl" class="product_out2" onmouseover="this.className=\'product_over2\'" onmouseout="this.className=\'product_out2\'">
	<td class="tablebattom1"><a href="'.seourl('pages',0,$res['cid']).'">آدرس</a></td>
	<td class="tablebattom1">'.get_title_pageIndex($res['type']).'</td>
	<td class="tablebattom1">'.$res['title'].'</td>
	<td class="tablebattom1">
		<a href=admin_page_index.php?cid='.$res['cid'].'><img src="images/edit.gif" border ="0"/></a>
		<a href=admin_page_index.php?dell='.$res['cid'].'><img src="images/dell.gif" border ="0"/></a>
	</td>
</tr>';
}
echo '</table>';
?>

                            </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 } ?>