<?php include "common/user_log.php"; ?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>NWP Engineering Department</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="dist/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="dist/css/ionicons.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="plugins/iCheck/all.css">
    <!-- Bootstrap Color Picker -->
    <link rel="stylesheet" href="plugins/colorpicker/bootstrap-colorpicker.min.css">
    <!-- Bootstrap time Picker -->
    <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="plugins/select2/select2.min.css">
	<!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="bootstrap-sweetalert/lib/sweet-alert.css" />
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">	
	
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">

      <header class="main-header">
        <!-- Logo -->
         <a href="home.php" class="logo">
          <!-- mini logo for sidebar mini 50x50 pixels -->
         <span class="logo-mini"><img src="img/logo.png" width="100"></span>
          <!-- logo for regular state and mobile devices -->
        <span class="logo-lg"><b><img src="img/logo.png" width="100"></b></span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" role="navigation">
          <!-- Sidebar toggle button-->
          <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
			 <span class="logo-lg">
             &nbsp;&nbsp;<font face="Lucida Sans Unicode, Lucida Grande, sans-serif">NWP Engineering Department</font></span>
          </a>
		
          <div class="navbar-custom-menu">
            <ul class="nav navbar-nav">

              <!-- User Account: style can be found in dropdown.less -->
              <li class="dropdown user user-menu">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                  <img src="dist/img/user2-160x160.png" class="user-image" alt="User Image">
                  <span class="hidden-xs"><?php echo $name; ?></span>
                </a>
                <ul class="dropdown-menu">
                  <!-- User image -->
                  <li class="user-header">
                    <img src="dist/img/user2-160x160.png" class="img-circle" alt="User Image">
                    <p>
             NWP Engineering Department
                    
                    </p>
                  </li>
                  <!-- Menu Body -->
                 
                  <!-- Menu Footer-->
                  <li class="user-footer">
                    <div class="pull-left">
                      
                    </div>
                    <div class="pull-right">
                      <a href="distroy.php" class="btn btn-default btn-flat">Sign out</a>
                    </div>
                  </li>
                </ul>
              </li>
              <!-- Control Sidebar Toggle Button -->
              <li>
                <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
              </li>
            </ul>
          </div>
        </nav>
      </header>
      <!-- Left side column. contains the logo and sidebar -->
      <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
          <!-- Sidebar user panel -->
    <?php include "common/sidebar.php"; ?>  
     
        </section>
        <!-- /.sidebar -->
      </aside>

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
          About Us
          </h1>
          
    <ol class="breadcrumb">
      <li><a href="home.php"><i class="fa fa-home"></i> Home</a></li>
    </ol>
        </section>

        <!-- Main content -->
        <section class="content">

<!-- ************************************************* -->
  <div class="box box-info only_eng"> 
    <div class="box-header with-border"> 
      <h3 class="box-title">About NWPED</h3>
    </div>

    <div class="box-body"> 
      <!-- text input -->
      <div class="form-group"> 
        <label>Description:<font color="#FF0000"><strong>*</strong></font></label>
        <textarea id="description" rows="10" cols="100">
        </textarea>
        <span id="des_val_msg" style="color: red; display: none">*Enter Description</span>
      </div>
	  
	  <div class="form-group"> 
        <label>Purpose And Objectives:<font color="#FF0000"><strong>*</strong></font></label>
        <textarea id="objectives" rows="10" cols="100">
        </textarea>
        <span id="obj_val_msg" style="color: red; display: none">*Enter Objectives</span>
      </div>

      <!-- /.box-body -->
      <div class="box-footer"> 
        <button  id="btn_submit" class="btn btn-primary">SUBMIT</button>
      </div>

    </div>
  </div>

 <!-- /.table -->
        
    <div class="box box-info"> 
      <div class="box-header"> 
        <h3 class="box-title">Details Edit / Remove</h3>
      </div>
      <!-- /.box-header -->
      <div class="box-body"> 
        <table id="example1" class="table table-bordered table-striped">
          <thead>
            <tr> 
              <th>ID</th>
              <th>Description</th>
              <th>Objectives</th>
              <th class="only_others">Add Details</th>
              <th>Edit</th>
            </tr>
          </thead>
          <tbody>
            <?php 
              $sql="SELECT * FROM about_us WHERE lang=1 AND del=0 ORDER BY id DESC";
              $result=mysqli_query($conn, $sql);

              $x = 0;
              while ($row = mysqli_fetch_array($result)){ $x++;
            ?>
            <tr> 
              <td><?php echo $x; ?>.</td>
              <td><?php echo $row['description']; ?></td>
              <td><?php echo $row['objectives']; ?></td>
              <td align="center" class="only_others">
			  <?php $sql_l = mysqli_query($conn, "SELECT * FROM about_us WHERE lang = '$log_lang' AND group_id=".$row['group_id']);
			  if(mysqli_num_rows($sql_l) == 0) { ?>
			  <button  class="btn btn-success btn-sm btn_select_lang" data-toggle="modal" data-target="#select_lng" value="<?php echo $row['group_id']; ?>"><span class="glyphicon glyphicon-plus"></span> &nbsp;ADD </button>
			  <?php } ?>
              </td>

              <td align="center">
			  <?php if(mysqli_num_rows($sql_l) == 1) { ?>
			  <button  class="btn btn-info btn-sm btn_up" data-toggle="modal" data-target="#edit_lng" value="<?php echo $row['group_id']; ?>"><span class="glyphicon glyphicon-pencil"></span> &nbsp;EDIT </button>
			  <?php } ?>
			  </td>
            </tr>
            <?php  } ?>
          </tbody>
        </table>
      </div>
      <!-- /.box-body -->
    </div>
    
  </section>
   
      </div>
	      <!-- /.End table -->
<!-- ************************************************* -->
      
           <!-- /.col -->
              </div><!-- /.row -->
            </div><!-- /.box-body -->
            
          

          <div class="row">
            
    
    
      </div>
      <!-- /.col (right) -->
         

      </div>
<footer class="main-footer"> 
<div class="pull-right hidden-xs">
          
        </div>  <strong>Copyright &copy; NWP Engineering Department</strong> All rights reserved.
      </footer>

      <!-- Control Sidebar -->
      <aside class="control-sidebar control-sidebar-dark">
        <!-- Create the tabs -->
        <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
          <li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
          <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
        </ul>
        <!-- Tab panes -->
        <div class="tab-content">
          <!-- Home tab content -->
          <div class="tab-pane" id="control-sidebar-home-tab">
            

            
             

          </div><!-- /.tab-pane -->
         

          </div><!-- /.tab-pane -->
        </div>
      </aside><!-- /.control-sidebar -->
      <!-- Add the sidebar's background. This div must be placed
           immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div><!-- ./wrapper -->


    <!-- Modal -->
  <div class="modal fade" id="select_lng" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal2">&times;</button>
          <h4 class="modal-title" id="test_id">Add About NWPED</h4>
        </div>
        <div class="modal-body">			
			<div class="form-group">
			  <label>Select Language:<font color="#FF0000"><strong>*</strong></font></label>&nbsp;&nbsp;&nbsp;&nbsp;
			  <input name="lang" type="radio" id="sinhala" class="minimal" value="2" <?php if($log_lang == 2) { echo 'checked'; } else { echo 'disabled'; } ?>>
			  <label>&nbsp;&nbsp;සිංහල</label>&nbsp;&nbsp;&nbsp;&nbsp;
			  <input name="lang" type="radio" id="tamil" class="minimal" value="3" <?php if($log_lang == 3) { echo 'checked'; } else { echo 'disabled'; } ?>>
			  <label class="m-l-20"> &nbsp;&nbsp;தமிழ்</label>
			</div>			
			
			  <div class="form-group"> 
				<label>Description:<font color="#FF0000"><strong>*</strong></font></label>
				<textarea id="des_lang" rows="10" cols="100">
				</textarea>
			  </div>
			  
			  <div class="form-group"> 
				<label>Purpose And Objectives:<font color="#FF0000"><strong>*</strong></font></label>
				<textarea id="obj_lang" rows="10" cols="100">
				</textarea>
			  </div>			
			
			<input type="hidden" class="form-control" id="group_id" readonly>
            <span style="color: red;" class="pull-right">* Required Fields</span>
			
			<div class="form-group">
              <button id="submit_lng" class="btn btn-primary">SUBMIT</button>
            </div>
			
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
  </div>

<!-- Modal -->
  <div class="modal fade" id="edit_lng" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title" id="test_id">Edit About Us</h4>
        </div>
        <div class="modal-body">
		  
			  <div class="form-group"> 
				<label>Description:<font color="#FF0000"><strong>*</strong></font></label>
				<textarea id="des_update" rows="10" cols="100">
				</textarea>
			  </div>
			  
			  <div class="form-group"> 
				<label>Purpose And Objectives:<font color="#FF0000"><strong>*</strong></font></label>
				<textarea id="obj_update" rows="10" cols="100">
				</textarea>
			  </div>		  
			  
			<input type="hidden" id="group_id_up" readonly>
			<input type="hidden" id="log_lang" readonly value="<?php echo $log_lang; ?>">

			<span style="color: red;" class="pull-right">* Required Fields</span>
			<div class="form-group">
			  <button class="btn btn-danger" id="update_btn">UPDATE</button>
			</div>

        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
  </div>


    <!-- jQuery 2.1.4 -->
    <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <!-- Select2 -->
    <script src="plugins/select2/select2.full.min.js"></script>
	<!-- DataTables -->
    <script src="plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- InputMask -->
    <script src="plugins/input-mask/jquery.inputmask.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>
    <!-- date-range-picker -->
    <script src="plugins/daterangepicker/moment.min.js"></script>
    <script src="plugins/daterangepicker/daterangepicker.js"></script>
    <!-- bootstrap color picker -->
    <script src="plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <!-- bootstrap time picker -->
    <script src="plugins/timepicker/bootstrap-timepicker.min.js"></script>
    <!-- SlimScroll 1.3.0 -->
    <script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- iCheck 1.0.1 -->
    <script src="plugins/iCheck/icheck.min.js"></script>
    <!-- FastClick -->
    <script src="plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="dist/js/demo.js"></script>
    <script src="bootstrap-sweetalert/lib/sweet-alert.min.js"></script>
    <!-- CK Editor -->
    <script src="https://cdn.ckeditor.com/4.4.3/standard/ckeditor.js"></script>    
	<!-- Bootstrap WYSIHTML5 -->
    <script src="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>   

   <!-- Page script -->
    <script>
      $(function () {
        //Initialize Select2 Elements
        $(".select2").select2();

        //Datemask dd/mm/yyyy
        $("#datemask").inputmask("dd/mm/yyyy", {"placeholder": "yyyy-mm-dd"});
        //Datemask2 mm/dd/yyyy
        $("#datemask2").inputmask("mm/dd/yyyy", {"placeholder": "yyyy-mm-dd"});
        //Money Euro
        $("[data-mask]").inputmask();

        //Date range picker
        $('#reservation').daterangepicker();
        //Date range picker with time picker
		   $('#date').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});
		   $('#edt_date').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});
        //Date range as a button
        $('#daterange-btn').daterangepicker(
            {
              ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month')]
              },
              startDate: moment().subtract(29, 'days'),
           
            },
        function (start) {
          $('#reportrange span').html(start.format('MMMM D, YYYY'));
        }
        );

        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
          checkboxClass: 'icheckbox_minimal-blue',
          radioClass: 'iradio_minimal-blue'
        });
        //Red color scheme for iCheck
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
          checkboxClass: 'icheckbox_minimal-red',
          radioClass: 'iradio_minimal-red'
        });
        //Flat red color scheme for iCheck
        $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
          checkboxClass: 'icheckbox_flat-green',
          radioClass: 'iradio_flat-green'
        });

        
      });
	  
      $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": true,
          "info": true,
          "autoWidth": false
        });
      });	  
	  
      $(function () {
        // Replace the <textarea id="editor1"> with a CKEditor
        // instance, using default configuration.
        CKEDITOR.replace('description');
        CKEDITOR.replace('objectives');
        CKEDITOR.replace('des_lang');
        CKEDITOR.replace('obj_lang');
        
		CKEDITOR.replace('des_update');
		CKEDITOR.replace('obj_update');

        //bootstrap WYSIHTML5 - text editor
        $(".textarea").wysihtml5();
      });
	  
    </script>

<script>
/***************************************  Form Validation**********************************/

var des_val = true;
function des_validate() {
	if (CKEDITOR.instances['description'].getData() === '') {
		des_val = false;
		$('#des_val_msg').fadeIn();
		display_error_msg();
	} else {
		des_val = true;
		clear_validation();
	}
}

var obj_val = true;
function obj_validate() {
	if (CKEDITOR.instances['objectives'].getData() === '') {
		obj_val = false;
		$('#obj_val_msg').fadeIn();
		display_error_msg();
	} else {
		obj_val = true;
		clear_validation();
	}
}

function display_error_msg() {
	if (CKEDITOR.instances['description'].getData() === '') {
		$('#des_val_msg').fadeIn();
	}
	
	if (CKEDITOR.instances['objectives'].getData() === '') {
		$('#obj_val_msg').fadeIn();
	}
}

function clear_validation() {
	if (CKEDITOR.instances['description'].getData() != '') {
		$('#des_val_msg').fadeOut();
	}
	
	if (CKEDITOR.instances['objectives'].getData() != '') {
		$('#obj_val_msg').fadeOut();
	}
}

$('.form-control').focusin(function () {
	$('.formError').fadeOut();
});

/****************************** Insert Eng Language  *********************************************************/

$("#btn_submit").click(function () {
	des_validate();
	obj_validate();
	
	if (des_val && obj_val) {
		var des = CKEDITOR.instances['description'].getData();
		var obj = CKEDITOR.instances['objectives'].getData();
		
		$.post('function/about_us_conn.php', {add_des_eng: 'data', des: des, obj: obj},
		function (data) {
		if (data.msgType === 1) {
			setTimeout(function () {
				swal({
				title: "",
				text: "Successfully Updated!",
				type: "success",
				confirmButtonText: "OK"
				},
				function (isConfirm) {
					if (isConfirm) {
						window.location.href = "add_about_us.php";
					}
				});
			}, 100);
		
		} else if (data.msgType === 2){
			swal("MYSQL Error!", "Please Try Again!", "warning");
		
		} else if (data.msgType === 3){
			swal("", "Data Already Exist!", "warning");
		}
		
		}, "json");	
		
	}
});

/***************************************  Insert Sinhala/Tamil Language **********************************/

$(".btn_select_lang").click(function(){
  $("#group_id").val($(this).val());
});

$("#submit_lng").click(function () {
	var des = CKEDITOR.instances['des_lang'].getData();
	var obj = CKEDITOR.instances['obj_lang'].getData();
	
	var group_id = $('#group_id').val();
	
	var lang = "";
	if ($("#sinhala:checked").val() === "2") {
		lang = "2";
	
	} else if ($("#tamil:checked").val() === "3") {
	   lang = "3";
	}
	
	if (des === '' || obj === '' || group_id === '' || lang === '') {
		swal("Warning!", "Please Enter Required Fields!", "warning");
	
	} else {

		$.post('function/about_us_conn.php', {add_des_lang: 'data', des: des, obj: obj, group_id: group_id, lang:lang},
		function (data) {
		if (data.msgType === 1) {
			setTimeout(function () {
				swal({
				title: "",
				text: "Successfully Updated!",
				type: "success",
				confirmButtonText: "OK"
				},
				function (isConfirm) {
					if (isConfirm) {
						window.location.href = "add_about_us.php";
					}
				});
			}, 100);
		
		} else if (data.msgType === 2){
			swal("MYSQL Error!", "Please Try Again!", "warning");
		
		} else if (data.msgType === 3){
			swal("", "Data Already Exist", "warning");
		
		}		

		}, "json");	
		
	}
});

/******************************************* Load Form Data **************************************/

$(".btn_up").click(function(){
	var lang = $("#log_lang").val();
	
	load_form_data($(this).val(), lang);
	$("#group_id_up").val($(this).val());
});

function load_form_data(gid, lang){
	$.post( "function/about_us_conn.php", { get_dataset: "data", gid : gid, lang: lang}, function( data ) {
		$.each(data, function (index, data) {
			CKEDITOR.instances['obj_update'].setData(data.objectives);			
			CKEDITOR.instances['des_update'].setData(data.description);
		});

	}, "json");
}

/******************************************* Edit **************************************/

$("#update_btn").click(function () {
	var des = CKEDITOR.instances['des_update'].getData();
	var obj = CKEDITOR.instances['obj_update'].getData();
	
	var lang = $('#log_lang').val();
	var group_id = $('#group_id_up').val();
	
	if (des === '' || obj === '') {
		swal("Warning!", "Please Enter Required Fields!", "warning");
	
	} else if(group_id === '' ||  lang === '') {
		swal("Warning!", "Please Enter Required Fields!", "warning");
	
	} else {
		$.post('function/about_us_conn.php', {update_des:'data', group_id: group_id, lang: lang, des: des, obj: obj},
		function (data) {
			if (data.msgType === 1) {
				setTimeout(function () {
					swal({
					title: "",
					text: "Successfully Updated!",
					type: "success",
					confirmButtonText: "OK"
					},
					function (isConfirm) {
						if (isConfirm) {
							window.location.href = "add_about_us.php";
						}
					});
				}, 100);
			
			} else if (data.msgType === 2){
				swal("MYSQL Error!", "Please Try Again!", "warning");
			}

		}, "json");	
		
	}
});



</script>	
		
</body>
</html>
