edit.php 8.67 KB
Newer Older
majidbeigi's avatar
majidbeigi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
<?php

	include_once('../../library/config.php');

    $logadmin = new ADMIN();

    if(!$logadmin->logincheck()){

        header('location:../../adminn/login/');

    }

    $id = $_GET['id'];
    $err = null;

    $db = new DB();
    $db->connect();


    if(isset($_POST['edit']))

    {
        $namef = $_POST['namef'];
        $namee = $_POST['namee'];
        $code = $_POST['code'];
        $price = $_POST['price'];
        $description = $_POST['description'];
        
        $tmp = new PRODUCT();
        if($tmp->updatebrand($id,$namef,$namee,$code,$price,$description))
        {
            $err=true;
        }
    }




    if(isset($_POST['delete']))
    {
         $image = $_POST['image'];
         if(file_exists("../../images/products/brand/".$image))
         {
            unlink("../../images/products/brand/".$image);
         }
         if(file_exists("../../images/products/brand/th/th".$image))
         {
            unlink("../../images/products/brand/th/th".$image);
         }
         $data=array("image"=>"''");
         $where="id_brand=$id";
         $db->update("brand",$data,$where);
    }
    
    define ("MAX_SIZE","4000");
    if(isset($_POST['upload']))
    {
        $image =$_FILES['image']['name'];
        if($image){
            $uploadedfile = $_FILES['image']['tmp_name'];
            $size = $_FILES['image']['size'];
            if($size > MAX_SIZE * 1004)
        {
            echo "You have exceeded the size limit";
        }
        else
        {
            if( ($_FILES['image']['type']== "image/jpeg") || ($_FILES['image']['type']== "image/pjpeg") )
            {
                $src = imagecreatefromjpeg($uploadedfile);
            }
            elseif($_FILES['image']['type']== "image/png")
            {
                $src = imagecreatefrompng($uploadedfile);
            }
            else
            {
                echo "فایل نامعتبر";
            }
            
            if($src)
            {

                list($width, $height) = getimagesize($uploadedfile);

                // image                
                $newwidth = 600;
                $newheight= ($height / $width) * $newwidth;
                
                
                
                
                $tmp = imagecreatetruecolor($newwidth, $newheight);
               
                imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
                $imagename = mt_rand(1000,9999). $image;
                $filename = "../../images/products/brand/".$imagename;
                imagejpeg($tmp, $filename, 100);
                
                //th_image
                $newwidth_th = 120;
                $newheight_th= 80;
                 
                $tmp_th = imagecreatetruecolor($newwidth_th, $newheight_th);
                 
                imagecopyresampled($tmp_th, $src, 0, 0, 0, 0, $newwidth_th, $newheight_th, $width, $height);
                $imagename_th ="th".$imagename;
                $filename_th = "../../images/products/brand/th/".$imagename_th;
                imagejpeg($tmp_th, $filename_th, 100);
                
                imagedestroy($tmp_th);
                imagedestroy($src);
                imagedestroy($tmp);
                 
                 $data=array("image"=>"'$imagename'");
                 $where="id_brand=$id";
                 $db->update("brand",$data,$where);
                
            }
        }
        }
    }




    $brand = new PRODUCT();
    $brands = $brand->loadbrand($id);
?>

<!DOCTYPE html>

<html>

<head>
        <?php
            include_once($_SERVER['DOCUMENT_ROOT'].SITE.'/library/head.php');               
        ?>
        <script type="text/javascript" src="js/jscripts/tiny_mce/tiny_mce.js"></script>

        <script>

        tinyMCE.init({
		// General options
                        language: 'fa',
                		mode : "exact",
                        elements : "description" ,
                		theme : "advanced",
                        forced_root_block : false,
                        directionality : "rtl",
                        height : 220,
    		plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,visualblocks",

    		// Theme options
    		theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect,|,tablecontrols",
    		theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,code,|,preview,|,forecolor,backcolor,hr,|,sub,sup,|,charmap,emotions,|,ltr,rtl",
	        theme_advanced_resizing : false,
            theme_advanced_font_sizes: "10px,12px,13px,14px,16px,18px,20px",
            font_size_style_values: "12px,13px,14px,16px,18px,20px",
       });
        </script>
</head>

<body>

<!-- Base Table -->

<table class="body" cellspacing="0" cellpadding="0" align="center">

    <!-- Head -->

    <?php

        include($_SERVER['DOCUMENT_ROOT'].SITE.'/library/header.php');

    ?>

<tr>

    <!-- Main -->

    <td align="center" >

    <div dir="rtl" id="main" align="center" class="ui-corner-all , ui-widget-content">

        <div align="left" style="padding: 5px;"> <a href="login/logout.php"> LOGOUT </a> </div>

        <?php

            echo $_SESSION['admin_name'];

        ?>

        پنل مدیریت آپشن استاندارد

        <hr />

    <!-- Top Menu -->

    <?php

        include($_SERVER['DOCUMENT_ROOT'].SITE.'/adminn/library/topmenu.php');

    ?>

    <div align="right">
    <form method="post" action="">
    <h2 style="font-weight: normal;margin-left: 20px;font-size: 17px;">
    فرم ایجاد آپشن استاندارد
    </h2>
    <table>
        <tr>
            <td style="width: 100px;">نام فارسی : </td><td><input type="text" name="namef"  value='<?php echo $brands[0]['namef']; ?>' style="width: 300px;" />  </td>
        </tr>
        <tr>
            <td>نام انگلیسی : </td><td><input type="text" name="namee"  value='<?php echo $brands[0]['namee']; ?>' style="width: 300px;" />  </td>
        </tr>
        <tr>
            <td>کد : </td><td><input type="text" name="code"  value='<?php echo $brands[0]['code']; ?>' style="width: 170px;" /></td>
        </tr>
        <tr>
            <td>قیمت : </td><td><input type="text" name="price"  value='<?php echo $brands[0]['price']; ?>' style="width: 170px;" /></td>
        </tr>
        <tr> 
            <td colspan="2">توضیحات :<br /><textarea name="description"><?php echo $brands[0]['description']; ?></textarea></td>
        </tr>
        
        <tr>
            <td colspan="2"><input type="submit" value="ثبت" name="edit" />
            <?php
                if($err)
                print"ویرایش با موفقیت انجام شد";
            ?>
            </td></td>
        </tr>
        </form>
        <tr>
            <td>تصویر</td>
            <td>
                    <?php
                        if($brands[0]['image'])
                        {
                            print"<img src='images/products/brand/th/th".$brands[0]['image']."' style='padding:1px;border:1px solid #C0C0C0;float:right;margin-left:10px;' />";
                            print'<form method="post" action="">';
                            print'<input type="hidden" name="image" value="'.$brands[0]['image'].'" />
                            <input type="submit" name="delete" value="حذف" onclick="return confirm(\'حذف شود؟\');" />';
                            print'</form>';
                            
                        }
                        else
                        {
                            print'<form method="post" action=""  enctype="multipart/form-data">';
                            print '<input type="file" name="image" /><input type="submit" name="upload" value="آپلود" />'; 
                            print'</form>';                       
                        }
                        
                    ?>
            </td>
        </tr>
    </table>
    </div>

    <div dir="ltr" class="holder"></div>

    </div>

    </td>

</tr>

<!-- Footer -->

        <?php

            include($_SERVER['DOCUMENT_ROOT'].SITE.'/library/footer.php');

        ?>

</table>

</body>

</html>