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

                
                            //to upload name file to db
                            $sdiv=$_POST['sdiv'];
                            $name_product = $_POST['name_product'];
							$intro_product = $_POST['intro_product'];
							
                            $date_time_f=date("Y-m-d h:i:s");
                            $date_f=date("Y-m-d");
                            $time_f=date("h:i:s");
                            $active=$_POST['active'];
                            $submit = $_POST['submit'];
                            if($submit){
                                //to upload name file to db
                                if($_FILES['filedata']['tmp_name'] && $name_product && $intro_product != ""){
                                	$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);
                                    $result = @mysql_query("INSERT INTO `product` VALUES ('', '$name_product', '$intro_product', '$sdiv', '$_POST[desc]', '$fileName', '$fileSize', '$fileType', '$data', '$date_time_f', '$date_f', '$time_f', '$active', 'en')");
                                    
                                    
                                    //to upload pic any folder
                                    $path = "../upload/product_en/";
                                    $path = $path . basename($fileName); 
                                    if(move_uploaded_file($tmpName, $path)) {
                                        echo "تم إضافة منتج بنجاح";
                                    } else{echo "<font color='red'>خطأ في رفع الصورة من فضلك حاول مرة أخرى</font>";}
                                    
                                }else{echo "<font color='red'>من فضلك ادخل البيانات كاملة - ملحوظة: تعني * مطلوب</font>";}
                            }
            
                        ?>
                    </span>
                </div>
                <form method="post" action="<?= $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
                <div class="editor">
                    <table class="table_color">
                        <tr>
                            <td class="ti_ro">القسم</td>
                            <td class="comast">:</td>
                            <td><select name="sdiv"><?sel_father();?></select></td>
                        </tr>
                        <tr>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                        </tr>
                        <tr>
                            <td class="ti_ro">الاسم *</td>
                            <td class="comast">:</td>
                            <td><input class="typ_ro" type="text" name="name_product" /></td>
                        </tr>
                        <tr>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                        </tr>
                        <tr>
                            <td class="ti_ro">المقدمة</td>
                            <td class="comast">:</td>
                            <td><textarea class="desmsgt" dir="rtl" cols="65" rows="2" name="intro_product"></textarea></td>
                        </tr>
                        <tr>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                        </tr>
                        <tr>
                            <td class="ti_ro">الصورة *</td>
                            <td class="comast">:</td>
                            <td><input class="typ_ro" type="file" name="filedata" /></td>
                        </tr>
                        <tr>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                        </tr>
                        <tr>
                            <td class="ti_ro">وصف الصورة *</td>
                            <td class="comast">:</td>
                            <td><input type="text" name="filename" /></td>
                        </tr>
                        <tr>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                        </tr>
                        <tr>
                            <td class="ti_ro">التفعيل</td>
                            <td class="comast">:</td>
                            <td><select name="active"><?active();?></select></td>
                        </tr>
                        <tr>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                            <td class="hr_table"></td>
                        </tr>
                        <tr>
                            <td class="ti_ro">التفاصيل</td>
                            <td class="comast">:</td>
                            <td>
                                    <?
                                        //make fckeditor
                                        include_once ('fckeditor/fckeditor.php');
                                        $oFCKeditor = new FCKeditor ( 'desc' );
                                        $oFCKeditor->BasePath = 'fckeditor/';
                                        $oFCKeditor->Width =550;
                                        $oFCKeditor->Height =400;
                                        $oFCKeditor->Value =$desc;
                                        $oFCKeditor->Create ();
                                    ?>
                            </td>
                        </tr>
                    </table>

                </div>
                <div class="submit"><input type="submit" name="submit" value="إضافة" /></div>
                </form>
            </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();?>