ok

Mini Shell

Direktori : /proc/thread-self/root/home2/selectio/www/saew.in/admin/
Upload File :
Current File : //proc/thread-self/root/home2/selectio/www/saew.in/admin/news-add.php

<?php  include "header.php";
$date = date('Y-m-d'); 
if(isset($_POST['add_news'])){
        try{
            $date = date('Y-m-d h:i:s', time());
            
             if(isset($_FILES['photo']) && $_FILES["photo"]["name"]!=""){
                        $extension = end(explode(".", $_FILES["photo"]["name"]));
                        $image = rand(10,1000000000)."-image." . $extension;
                        $upload = move_uploaded_file($_FILES['photo']['tmp_name'], '../upload/' . $image);
                        $upload_image = '../upload/' . $image;   
                }
                else{
                    $upload_image='';
                }
            
         $statement = $pdo->prepare("INSERT INTO `news`(`category`, `title`,`type`,`file`, `status`, `department_id`, `date`, `news_type`) VALUES (?,?,?,?,?,?,?,?)");
            $result=$statement->execute(array($_POST['category_id'],$_POST['title'],$_POST['type_id'],$upload_image,$_POST['status'],$_POST['department_id'],$_POST['news_date'],$_POST['news_type']));
                 error_log($result);   
                    if($result){
                        $message = 'News added successfully!';
                        unset($_POST);  
                        
                    }else{
                        $warning="Something went wrong try again...";
                    }  
                }catch(Exception $e){
                    $error=$e;
                }   
    }
    
?>



?>
<div class="content-wrapper" style="background:white;">
        <div class="col-lg-12 alerts">
            <div id="custom-alerts" style="display:none;">
                <div class="alert alert-dismissable">
                    <div class="custom-msg"></div>
                </div>
            </div>
            <?php if ($error)  { ?>
            <div class="alert alert-danger alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-ban"></i> Error</h4>
                <?= $error; ?>
            </div>
            <?php $error=0;} if ($warning) { ?>
            <div class="alert alert-warning alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-warning"></i> warning</h4>
                <?= $warning; ?>
            </div>
            <?php  $warning=0;} if ($message) { ?>
            <div class="alert alert-success alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4>    <i class="icon fa fa-check"></i> Success</h4>
                <?= $message; ?>
            </div>
            <?php $message=0; } ?>
        </div>
        <div class="clearfix"></div>







<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div>
                <div class="box-header">
                    <h3 class="box-title"><b>Create Newses : </b></h3>
                </div>
                <div class="box-body">
                    <div class="col-lg-12">

                        <form action="" class="validation" enctype="multipart/form-data" method="post" accept-charset="utf-8">
                                                                 
                        <div class="row">
                            <div class="col-sm-4">
                                    <div class="form-group">
                                        <label class="control-label" for="departement_id">Select Category</label>
                                             <select name="category_id" class="form-control select2" style="width:100%" id="category_id">
                                                <option value="0">All Category List</option>
                                                <option value="1">Lastest News</option>
                                                <option value="2">Circular/Safety</option>
                                                <option value="3">Announcement</option>
                                             </select>
                                    </div>
                           </div>
                           
                           
                           <div class="col-sm-4">
                                    <div class="form-group">
                                        <label class="control-label" for="departement_id">Department</label>
                                             <select name="department_id" class="form-control select2" style="width:100%" id="department_id">
                                              <?php if($_SESSION['hrm']['id']==1){ ?> <option value="">Selcet Department Name</option> <?php } ?>
                                          <?php 
                                          $conds='';
                                            if($_SESSION['hrm']['id']!=1){ $conds=' and id in ('.$_SESSION['department_ids'].')';}
                                          
                                          
                                            $statement = $pdo->prepare("SELECT * FROM `tbl_departement` where status=1 $conds");
                                            $statement->execute();
                                            $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                            foreach ($location_result as $result) {
                                                echo "<option value=".$result['id'].">".$result['departement']."</option>";
                                            }?>
                                             </select>
                                    </div>
                           </div>
                           
                           
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="required" for="desgination">Title</label>                                    
                                    <input type="text" name="title" value="" placeholder="Enter The Title" class="form-control tip" id="title"  required="required" />
                                </div>
                            </div>
                            
                            <div class="col-sm-4">
                                <div class="form-group">
                                    <label class="control-label" for="departement_id">Select News Type</label>
                                        <select name="news_type" class="form-control select2" style="width:100%" id="news_type">
                                            <option value="1">Public</option>
                                            <option value="2">Private</option>
                                        </select>
                                </div>
                            </div>
                            
                            
                            <div class="col-sm-4" id="type">
                                <div class="form-group">
                                    <label class="control-label" for="departement_id">Select Type</label>
                                        <select name="type_id" class="form-control select2" style="width:100%" id="type_id">
                                            <option value="0">All Type List</option>
                                            <option value="1">PDF</option>
                                            <option value="2">Normal</option>
                                        </select>
                                </div>
                            </div>
                            
                            <div class="col-md-4" id="upload">
                                <div class="form-group">
                                    <label for="file">Upload PDF File</label>                                    
                                    <input type="file" name="photo" value="" placeholder="Upload File" class="form-control tip" />
                                
                                </div>
                            </div>
                                           
                                            <div class="col-md-4">
                                                <div class="form-group">
                                                    <label class="required" for="status">Status</label> 
                                                     <!--<input type="text" name="role1"  placeholder="Enter Your Role" class="form-control tip" id="role1"  required="required" />-->
                                                    <select name="status" class="form-control tip select2">
                                                        <option value="1">Active</option>
                                                        <option value="0">De-Active</option>
                                                       
                                                    </select>
                                                </div>
                                            </div>
                                            
                                             <div class="col-md-4">
                                                <div class="form-group">
                                                    <label class="required" for="file">News Add Date</label>                                    
                                                    <input type="date" name="news_date" value="<?=$date?>" placeholder="Enter The News Add Date" class="form-control tip" id="news_date" required="required" />
                                                
                                                </div>
                                            </div>
     
                            
                        </div>
                        

                        <div class="form-group" style="text-align:center;">
                            <input type="submit" name="add_news" value="Add News"  class="btn btn-success" />
                        </form>
                        </div>

                    </div>
                        <div class="form-group" style="text-align:center;">
                            <a href="news-add.php"><button class="btn btn-primary" ><i class="fa fa-refresh"></i> Reset Form</button></a>
                            <a href="news.php"><button class="btn btn-warning" ><i class="fa fa-chevron-left"></i> Back to List</button></a>
                         </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
</section>
<script>
        window.onload = function() {
            $("#upload").hide();
        };
    $(function () {
          $("#type_id").change(function() {
            var val = $(this).val();
            
            //console.log('If Before llog :'+val);
            if(val==0) {
                $("#upload").hide();
                //console.log('If indside llog :'+1);
            }else if(val==1){
                $("#upload").show();
            }else{
                $("#upload").hide();
            }
          });
        });
        
</script>


<?php include "footer.php";?>

Zerion Mini Shell 1.0