<?
ob_start();
require_once("functions.php");
    if(!isset($_COOKIE[$admin])){
        header('Location: index.php');
    }
?>
<!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" />

<link href="css/style.css" rel="stylesheet" type="text/css" />

</head>

<body onload="clickMenu('menu')">
<!-- outer -->
<div id="outer">
	<!-- header ----------------------------------------------------->
	<div id="header"> <? include("header.php")?> </div>
	<!-- header -->
    
    <!-- content ---------------------------------------------------->
	<div id="content">
        <!-- con_right --------------------------------------->
	   <div id="con_right">
            <div class="title_page">المكتبة الزراعية</div>
            <!--<a href="add_father.php"><div class="add_father"><img src="images/add_48.png" /> Ø¥Ø¶Ø§ÙØ© Ù‚Ø³Ù…</div></a>-->
           
            <div class="path_page">
                تعديل مقال
                <img src="images/001_27.gif" width="10" height="10" />
                <a href="info.php">الرئيسية</a>
                
                
            </div>
            <div class="conteaner">
                <div class="details_page">
                   
                    <br /><br /><hr /><br />
                </div>
                <div class="title_editor">
                    <span class="title">
                        <?php
							$iddd=$_GET['id'];
							$id_cat44=$_GET['id_cat22'];
                            $submit = $_POST['submit'];
                            $name_product = $_POST['name_product'];
							$intro_product = $_POST['intro_product'];
                            
                            $active=$_POST['active'];
                            
                            $sdiv=$_POST['sdiv'];
                            $date_time_f=date("Y-m-d h:i:s");
                            $date_f=date("Y-m-d");
                            $time_f=date("h:i:s");
                            
                            if($submit){
                                
                                if($_FILES['filedata']['tmp_name'] != ""){
                                    //to upload name pic to db
                                    $fileName = $_FILES['filedata']['name'];
                                	$tmpName  = $_FILES['filedata']['tmp_name'];
                                	$fileSize = $_FILES['filedata']['size'];
                                	$fileType = $_FILES['filedata']['type'];
                                	$fo = @fopen($tmpName, "r");
                                	$data = @fread($fo, filesize($tmpName));
                                	$data = addslashes($data);
                                }else{
                                    $fileName = $_POST['filedata'];
                                }
                                
                                if($name_product && $intro_product != ""){
                                	                     
                                    
                                    //to send data from editor to db
                                    $result = "update product_maktaba set name='$name_product', intro='$intro_product', id_cat='$sdiv', content='$_POST[desc]', picname='$fileName',
                                     picsize='$fileSize', pictype='$fileType', date_time='$date_time_f', date='$date_f', time='$time_f', active='$active', langu='en' where id='$iddd'";
                                    //dataproducts='$desc',, 
                                    $query = mysql_query($result);
                                    echo "من فضلك انتظر حتى يتم التعديل <img src='images/loading11.gif' />".
                                                "<meta http-equiv='refresh' content='1'>";
												header('Location: edit_son_maktaba.php');
                                    
                                    //to upload pic any folder
                                    $path = "../upload/product_maktaba_en/";
                                    $path = $path . basename($fileName); 
                                    if(move_uploaded_file($tmpName, $path)) {
                                        echo "file ".  basename($fileName)."uploaded";
                                    }
                                    
                                }else{echo "<font color='red'>sory!! من فضلك قم باستكمال بيانات الحقول</font>";}
                            }
                        ?>
                    </span>
                </div>
                
                <div class="editor">
                    <?
                        //to send data to db with get id
                        $iddd=$_GET['id'];
                        //form send data
                        echo "<form method='post' action='edit_son_in_maktaba.php?id=$iddd' enctype='multipart/form-data'>";
                            
                            echo "<table class='table_color'>";
                                
								echo "<tr>";
                                    echo "<td class='ti_ro'>الاسم: *</td>";
                                                   //fetch data from db
                                                   
                                                   $seldb = "select * from product_maktaba where id = $iddd";
                                                   $querydb = mysql_query($seldb);
                                                   while($resultdb = mysql_fetch_array($querydb)){
                                                         if($resultdb){
                                                             extract($resultdb);
                                                             
                                                          }
                                                   }
                                    echo "<td><input class='typ_ro type='text' name='name_product' value='$name' /></td>";
                                echo "</tr>";
								
                               echo "<tr>";
                                    echo "<td class='ti_ro'>القسم:</td>";
                                                   
                                     echo "<td>";
										echo"<select name='sdiv'>";
											$sel = "select * from cat_maktaba where langu='en' and id=$id_cat44";
                                                    $query = mysql_query($sel);
                                                    while($result = mysql_fetch_array($query)){
                                                        extract($result);
                                                        echo "
                                                            <option value='$id' selected='selected'>$name</option>
                                                        ";
                                                    }
                                                    $sel = "select * from cat_maktaba where langu='en'";
													$query = mysql_query($sel);
													while($result = mysql_fetch_array($query)){
														extract($result);
														echo "
															<option value='$id'>$name</option>
														";
													}
										echo"</select>";
									//sel_father(); 
									 echo "</td>";
                                echo "</tr>";
								
								
								
								/*
								 echo "<td>";
										echo"<select name='sdiv'>";
											$sel = "select * from cat where id=$id_cat";
                                                    $query = mysql_query($sel);
                                                    while($result = mysql_fetch_array($query)){
                                                        extract($result);
                                                        echo "
                                                            <option value='$id' selected='selected'>$name</option>
                                                        ";
                                                    }
                                                     sel_father();
										echo"</select>";
									//sel_father(); 
									 echo "</td>";
								*/
							    
								
                                echo "<tr>";
                                    echo "<td class='ti_ro'>المقدمة: *</td>";
                                                   //fetch data from db
                                                   
                                                   $seldb = "select * from product_maktaba where id = $iddd";
                                                   $querydb = mysql_query($seldb);
                                                   while($resultdb = mysql_fetch_array($querydb)){
                                                         if($resultdb){
                                                             extract($resultdb);
                                                             $intro_product = $intro;
                                                          }
                                                   }
                                    echo "<td><textarea class='desmsgt' dir='rtl' cols='65' rows='2' name='intro_product'>$intro_product</textarea></td>";
                                echo "</tr>";
                                
                                
                                echo "<tr>";
                                    echo "<td class='ti_ro'>الوصف: *</td>";
                                    echo "<td>";
                                                
                                              
                                                   //fetch data from db to fckeditor
                                                   
                                                   $seldb = "select * from product_maktaba where id = $iddd";
                                                   $querydb = mysql_query($seldb);
                                                   while($resultdb = mysql_fetch_array($querydb)){
                                                         if($resultdb){
                                                             extract($resultdb);
                                                             $dataproducts = $content;
                                                          }
                                                   }
                                                   
                                                   //make fckeditor
                                                   include_once ('fckeditor/fckeditor.php');
                                                   $oFCKeditor = new FCKeditor ( 'desc' );
                                                   $oFCKeditor->BasePath = 'fckeditor/';
                                                   $oFCKeditor->Width =550;
                                                   $oFCKeditor->Height =400;
                                                   $oFCKeditor->Value =$dataproducts;
                                                   $oFCKeditor->Create ();
                                
                                                
                                                
                                    echo "</td>";
                                echo "</tr>";
                                
                                
                                
                                echo "<tr>";
                                    
                                    echo "<td class='ti_ro'>load pic: <br />الصورة: ";
                                        
                                                   //fetch data from db
                                                   
                                                   $seldb = "select * from product_maktaba where id = $iddd";
                                                   $querydb = mysql_query($seldb);
                                                   while($resultdb = mysql_fetch_array($querydb)){
                                                         if($resultdb){
                                                             extract($resultdb);
                                                             $path = "../upload/product_maktaba_en";
                                                             echo "<img src='$path/$picname' width=75 height=75 />";
                                                          }
                                                   }
                                        
                                    echo "</td>";
                                                   
                                    echo "<td>
                                            <input type='file' name='filedata' />
                                            <input type='hidden' name='filedata' value='$picname' />
                                        </td>";
                                echo "</tr>";
                                echo "<tr>";
                                    echo "<td class='ti_ro'>التفعيل :</td>";
                                    echo "<td><select name='active'>"; active(); echo "</select></td>";
                                echo "</tr>";
                                echo "<tr>";
                                    echo "<td></td>";
                                    echo "<td class='submit'><input type='submit' name='submit' value='تعديل' /></td>";
                                echo "</tr>";
                            echo "</table>";
                         echo "</form>";
                    
                    ?>
					
					
                </div>
                
            </div>
       </div>
	   <!-- /con_right -->
       
       <!-- con_left ---------------------------------------->
	   <div id="con_left">
            <!-- menu ---------------------------------->
            <div id="menuall"> <? include("menu.php")?> </div>
            <!-- /menu -->
            
            <!-- calender ------------------------------>
            <div id="calender"><embed src="images/Calender.swf" width="235" height="320" /></embed></div>
            <!-- /calender -->
       </div>
	   <!-- /con_left ---------------------------------------->
    </div>
	<!-- /content -->
    
    <!-- footer ----------------------------------------------------->
	<div id="footer"> <? include("footer.php")?> </div>
	<!-- /footer -->
</div>
<!-- /outer -->
</body>
</html>
<?ob_flush();?>