<?php include 'header.php'; ?>

<?php include 'sidebar.php'; ?>

<div id="page-wrapper">

    <div class="container-fluid">

		<br/>

         <div class="row">

             <div class="col-lg-12">
				<div class="panel panel-default dash">
					<div class="panel panel-primary">
						<div class="panel-heading">
							<h2 class="sub-header">
								<i class="fa fa-info-circle" aria-hidden="true"></i> Experts
							</h2>
						</div>
						<!-- /.panel-heading -->
						<div class="panel-body">
							<div class="table-responsive">
							
								<div class="col-md-12">

									<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" class="form-horizontal" name="newExpert">
										<fieldset>
											<?php $csrf->echoInputField(); ?>

											
											<!-- Expert Title input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name">Expert Title</label>
												<div class="col-md-6">
													<input id="title" name="title" type="text" class="form-control input-md" required>
												</div>
											</div>
											<!-- Image title input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name">Expert Image Title 1</label>
												<div class="col-md-6">
													<input id="title" name="title1" type="text" class="form-control input-md" required>
												</div>
											</div>

											<!-- Image input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="url"><?php echo lang('UPLOAD_IMAGE');?> 1</label>
												<div class="col-md-6">
													<input type="file" name="image1" id="image">
												</div>
											</div>

											<!-- Image Name input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Name </label>
												<div class="col-md-6">
													<input id="name" name="name1" type="text" class="form-control input-md" required>
												</div>
											</div>

											<!-- Image designation input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Designation </label>
												<div class="col-md-6">
													<input id="name" name="desig1" type="text" class="form-control input-md" required>
												</div>
											</div>

											<!-- Image 1st end -->

											<!-- Image title input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name">Expert Image Title 2</label>
												<div class="col-md-6">
													<input id="title" name="title2" type="text" class="form-control input-md" required>
												</div>
											</div>

											<!-- Image input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="url"><?php echo lang('UPLOAD_IMAGE');?> 2</label>
												<div class="col-md-6">
													<input type="file" name="image2" id="image">
												</div>
											</div>

											<!-- Image Name input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Name </label>
												<div class="col-md-6">
													<input id="name" name="name2" type="text" class="form-control input-md" required>
												</div>
											</div>

											<!-- Image designation input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Designation </label>
												<div class="col-md-6">
													<input id="name" name="desig2" type="text" class="form-control input-md" required>
												</div>
											</div>
											
											<!-- Image 2 end -->

											<!-- Image title input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name">Expert Image Title 3</label>
												<div class="col-md-6">
													<input id="title" name="title3" type="text" class="form-control input-md" required>
												</div>
											</div>

											<!-- Image input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="url"><?php echo lang('UPLOAD_IMAGE');?> 3</label>
												<div class="col-md-6">
													<input type="file" name="image3" id="image">
												</div>
											</div>

											<!-- Image Name input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Name </label>
												<div class="col-md-6">
													<input id="name" name="name3" type="text" class="form-control input-md" required>
												</div>
											</div>

											<!-- Image designation input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Designation </label>
												<div class="col-md-6">
													<input id="name" name="desig3" type="text" class="form-control input-md" required>
												</div>
											</div>

										<!-- Image designation input-->

																					<!-- Image title input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name">Expert Image Title 4</label>
												<div class="col-md-6">
													<input id="title" name="title4" type="text" class="form-control input-md" required>
												</div>
											</div>

											<!-- Image input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="url"><?php echo lang('UPLOAD_IMAGE');?> 4</label>
												<div class="col-md-6">
													<input type="file" name="image4" id="image">
												</div>
											</div>

											<!-- Image Name input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Name </label>
												<div class="col-md-6">
													<input id="name" name="name4" type="text" class="form-control input-md" required>
												</div>
											</div>

											<!-- Image designation input-->
											<div class="form-group">
												<label class="col-md-2 control-label" for="name"> Designation </label>
												<div class="col-md-6">
													<input id="name" name="desig4" type="text" class="form-control input-md" required>
												</div>
											</div>

 
											<!-- Button -->
											<div class="form-group">
												<label class="col-md-10 control-label" for="singlebutton"></label>
												<div class="col-md-2">
													<input type="submit" name="newexpert" class="btn btn-primary" value="<?php echo lang('SAVE');?>" />
												</div>
											</div>

										</fieldset>
									</form>
									<?php		

										if (!empty($_POST['newexpert']))
										 {
											global $conection;

											$title = $_POST['title']; 
											$title1 = $_POST['title1']; 
											$image1 = $_FILES['image1'];
											$name1 = $_POST['name1'];
											$desig1 = $_POST['desig1'];

											$title2 = $_POST['title2']; 
											$image2 = $_FILES['image2'];
											$name2 = $_POST['name2'];
											$desig2 = $_POST['desig2'];
 

											$title3 = $_POST['title3']; 
											$image3 = $_FILES['image3'];
											$name3 = $_POST['name3'];
											$desig3 = $_POST['desig3'];
 
											$title4 = $_POST['title4']; 
											$image4 = $_FILES['image4'];
											$name4 = $_POST['name4'];
											$desig4 = $_POST['desig4'];
 
 


											if (!empty($image1["name"]) || ($image2["name"]) || ($image3["name"]) || ($image4["name"])) {
										 
												$largura = 1000000;
												$altura = 1000000;
												$tamanho = 500000000000;
										 
												if(!preg_match("/image\/(pjpeg|jpeg|png|gif|bmp)/", $image1["type"])){
												   $error[1] = "Isso não é uma imagem.";
												} 
										 
												$dimensoes = getimagesize($image1["tmp_name"]);
												$dimensoes1 = getimagesize($image2["tmp_name"]);
												$dimensoes2 = getimagesize($image3["tmp_name"]);
												$dimensoes3 = getimagesize($image4["tmp_name"]);

										 
												if(($dimensoes[0] > $largura) || ($dimensoes1[0] > $largura) || ($dimensoes2[0] > $largura) || ($dimensoes3[0] > $largura)) {
													$error[2] = "A largura da imagem não deve ultrapassar ".$largura." pixels";
												}
										 
												if($dimensoes[1] > $altura) {
													$error[3] = "Altura da imagem não deve ultrapassar ".$altura." pixels";
												}
										 
												if($image1["size"] > $tamanho) {
													$error[4] = "A imagem deve ter no máximo ".$tamanho." bytes";
												}

												if($image2["size"] > $tamanho) {
													$error[4] = "A imagem deve ter no máximo ".$tamanho." bytes";
												}
												if($image3["size"] > $tamanho) {
													$error[4] = "A imagem deve ter no máximo ".$tamanho." bytes";
												}
												if($image4["size"] > $tamanho) {
													$error[4] = "A imagem deve ter no máximo ".$tamanho." bytes";
												}
													preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $image1["name"], $ext);
													preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $image2["name"], $ext);
													preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $image3["name"], $ext);
													preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $image4["name"], $ext);

													$nome_imagem = $image1["name"];
													$nome_imagem1 = $image2["name"];
													$nome_imagem2 = $image3["name"];
													$nome_imagem3 = $image4["name"];
										 
													$caminho_imagem = "assets/img/uploads/experts/" . $nome_imagem;
													$caminho_imagem1 = "assets/img/uploads/experts/" . $nome_imagem1;
													$caminho_imagem2 = "assets/img/uploads/experts/" . $nome_imagem2;
													$caminho_imagem3 = "assets/img/uploads/experts/" . $nome_imagem3;
										 
													move_uploaded_file($image1["tmp_name"], $caminho_imagem);
													move_uploaded_file($image2["tmp_name"], $caminho_imagem1);
													move_uploaded_file($image3["tmp_name"], $caminho_imagem2);
													move_uploaded_file($image4["tmp_name"], $caminho_imagem3);
										  
													 $sql = mysqli_query($conection,"INSERT INTO experts VALUES ('', '".$title."', '".$title1."', '".$nome_imagem."', '".$name1."', '".$desig1."', '".$title2."', '".$nome_imagem1."', '".$name2."', '".$desig2."', '".$title3."', '".$nome_imagem2."', '".$name3."', '".$desig3."', '".$title4."', '".$nome_imagem3."', '".$name4."', '".$desig4."')");

													// Se os dados forem inseridos com sucesso			
													if (!$sql) {
													echo ("Can't insert into database: " . mysqli_error());
													return false;
													} else {
													echo "<script type='text/javascript'>swal('".lang('NICE')."', '".lang('ADDED')."', 'success');</script>";
													echo '<meta http-equiv="refresh" content="1; experts.php">'; 
													die();
													}		
													return true;

												// Se houver mensagens de erro, exibe-as
												if (count($error) != 0) {
													foreach ($error as $erro) {
														echo $erro . "<br />";
													}
												}
											}
										}
											
										?>

								</div>    
							</div>
						</div>
					</div>
				</div>
			</div>
        </div>
        <!-- /.row -->

    <?php include 'copyright.php'; ?>
    
    </div>
    <!-- /.container-fluid -->

</div>
<!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->

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