<?php 

use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;

require_once('../Connections/cmctrfdb.php'); ?>

<?php require_once('../webassist/mysqli/rsobj.php'); ?>

<?php require_once('../webassist/mysqli/queryobj.php'); ?>

<?php



// include('include/headscript.php'); ?>





<?php  //insert query

if (isset($_POST['adduser'])) {   

if (isset($_POST['first_name'])) { $first_name=$_POST['first_name']; }

if (isset($_POST['last_name'])) { $last_name=$_POST['last_name']; }

if (isset($_POST['emailuser'])) { $emailuser=$_POST['emailuser']; }

if (isset($_POST['datein'])) { $datein=$_POST['datein']; }

if (isset($_POST['language'])) { $langid=$_POST['language']; }

	?>

<?php //insert query

    

    $checkmail = new WA_MySQLi_RS("checkmail",$cmctrfdb,0);

$checkmail->setQuery("SELECT * FROM auth_users WHERE auth_users.email='$emailuser'");

$checkmail->execute();

    if(!empty($checkmail->getColumnVal("id"))) { $varmailrepeat='Y'; ?>

        

        <?php

    } else {

    

    

	$mysqli = new mysqli($hostname_cmctrfdb, $username_cmctrfdb, $password_cmctrfdb, $database_cmctrfdb);



    

    $query = "INSERT INTO auth_users (email, first_name, last_name, password,  role_id, status, email_verified_at, created_at, updated_at, langid, termuseaccepted) VALUES ('$emailuser', '$first_name', '$last_name', '12345!AA', '2','Active','$datein','$datein','$datein','$langid', '$datein')";



// Esegui la query

$mysqli->query($query);

$inserttrue='Y';

// Chiudi la connessione al database

$mysqli->close();



    





//Now include the following following files based 

//on the correct file path. Third file is required only if you want to enable SMTP.



require 'phpmailer/src/Exception.php';

require 'phpmailer/src/PHPMailer.php';

require 'phpmailer/src/SMTP.php';



    //mail to client



$mail = new PHPMailer(true);

try {

$mail->isSMTP();                                      // Set mailer to use SMTP

$mail->Host = $mailhost;  // Specify main and backup server

$mail->SMTPAuth = true;                               // Enable SMTP authentication

$mail->Username = $mailusername;                            // SMTP username

$mail->Password = $mailpassword;                           // SMTP password

$mail->SMTPSecure = $mailmethod;                            // Enable encryption, 'ssl' also accepted

$mail->Port       = $mailport; 

    

$mmessage="mailnewuser";

include('include/mailnewuser.php');

// Email body content 





$htmlContent = $mailmessage1; 

    

    

$mail->From = $fromaddresssmail;

$mail->FromName = 'CIMAC Application Form System';

$mail->addAddress($emailuser);  // Add a recipient

    

                      



$mail->Subject = "Creazione Nuovo Utente";

$mail->Body    = $htmlContent;

$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';





    $mail->send();

   // echo 'Message has been sent';

} catch (Exception $e) {

    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";

}

        

        

        

  }}

  ?>

  <!DOCTYPE html>

<html lang="en">



    <head>

        <meta charset="utf-8" />

        <title>CIMAC Application Form</title>

        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <meta content="Premium Multipurpose Admin & Dashboard Template" name="description" />

        <meta content="" name="author" />

        <meta http-equiv="X-UA-Compatible" content="IE=edge" />



        <!-- App favicon -->

        <link rel="shortcut icon" href="../assets/images/favicon.ico">



        <!-- App css -->

        <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

        <link href="assets/css/jquery-ui.min.css" rel="stylesheet">

        <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />

        <link href="assets/css/metisMenu.min.css" rel="stylesheet" type="text/css" />

        <link href="assets/css/app.min.css" rel="stylesheet" type="text/css" />



    </head>



    <body class="account-body accountbg">



        <!-- Log In page -->

        <div class="container">

            <div class="row vh-100 ">

                <div class="col-12 align-self-center">

                    <div class="auth-page">

                        <div class="card auth-card shadow-lg">

                        

                            <div class="card-body">

                                <div class="px-3">

                                    <div>

                                        <a href="https://www.cimac.it/modulo_certificazione/public/login" class="logo logo-admin"><img src="assets/img/cimac-logo.png" height="55" alt="logo" class="auth-logo"></a>

                                    </div><!--end auth-logo-box-->

                                    

                                    <div class="text-center auth-logo-text">

                                        <h4 class="mt-0 mb-3 mt-5">Registrazione CIMAC Application Form</h4>

                                        

                                    </div> <!--end auth-logo-text-->  

    

                                     <?php if (isset($varmailrepeat)) { ?>

							<div class="alert icon-custom-alert alert-outline-pink b-round fade show" role="alert">                                            

                                        <i class="mdi mdi-alert-outline alert-icon"></i>

                                        <div class="alert-text">

                                            <strong>Email già presente nel database.

                                        </div>

                                        

                                        <div class="alert-close">

                                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">

                                                <span aria-hidden="true"><i class="mdi mdi-close text-danger"></i></span>

                                            </button>

                                        </div>

                                    </div><?php } ?>

                                

                                 <?php if (isset($inserttrue)) { ?>

							<div class="alert icon-custom-alert alert-outline-success alert-success-shadow" role="alert">

                                        <i class="mdi mdi-check-all alert-icon"></i>

                                        <div class="alert-text">

                                            <strong>Ben fatto!</strong> Utente creato con successo.

                                        </div>                                            

                                    </div>

                                    <?php } ?>

                                    <form class="form-horizontal auth-form my-4" action="auth-register.php" method="post" name="usernew">

            <?php $nowtime=date("Y-m-d G:i:s"); ?>

                                         <div class="form-group">

                                            <label for="useremail">Nome/Name</label>

                                            <div class="input-group mb-3">

                                                <span class="auth-form-icon">

                                                    <i class="dripicons-user"></i> 

                                                </span>                                                                                                              

                                                <input type="text" class="form-control" id="first_name" name="first_name" placeholder="Nome/Name">

                                            </div>                                    

                                        </div><!--end form-group-->

                                        

                                         <div class="form-group">

                                            <label for="useremail">Cognome / Surname</label>

                                            <div class="input-group mb-3">

                                                <span class="auth-form-icon">

                                                    <i class="dripicons-user"></i> 

                                                </span>                                                                                                              

                                                <input type="text" class="form-control" id="last_name" name="last_name" placeholder="Cognome / Surname">

                                            </div>                                    

                                        </div><!--end form-group-->

    

                                        <div class="form-group">

                                            <label for="useremail">Email</label>

                                            <div class="input-group mb-3">

                                                <span class="auth-form-icon">

                                                    <i class="dripicons-mail"></i> 

                                                </span>                                                                                                              

                                                <input type="email" class="form-control" id="emailuser" name="emailuser" placeholder="Email">

                                            </div>                                    

                                        </div><!--end form-group-->

            

                                       

    

                                      <div class="form-row">

                                      

                                              <div  class="col-md-8 mb-8">

                                            <label for="exampleFormControlSelect1">Lingua / Language</label>

                                            <select class="form-control" id="language"  name="language">

                                                    <option value="1">Italiano</option>

                                                    <option value="2">English</option>

                                            </select>

											</div>

                                            

                                            <input type="hidden" id="status" name="status" value="Active">

                                            <input type="hidden" id="role_id" name="role_id" value="2">

											<input type="hidden" id="adduser" name="adduser" value="Y">

											<input type="hidden" id="datein" name="datein" value="<?php echo $nowtime; ?>">

                                        </div>

            

                                        <div class="form-group row mt-4">

                                            <div class="col-sm-12">

                                                <div class="custom-control custom-switch switch-success">

                                                    <input type="checkbox" class="custom-control-input" id="customSwitchSuccess">

                                                    <label class="custom-control-label text-muted" for="customSwitchSuccess">Registrandoti accetti le condizioni d'uso di seguito riportate / By registering you agree to the following  <a href="#" class="text-primary">Terms of Use</a></label>

                                                </div>

                                            </div><!--end col-->                                             

                                        </div><!--end form-group--> 

            

                                        <div class="form-group mb-0 row">

                                            <div class="col-12 mt-2">

                                                <button class="btn btn-gradient-primary btn-round btn-block waves-effect waves-light" type="submit">Registrati /Register <i class="fas fa-sign-in-alt ml-1"></i></button>

                                            </div><!--end col--> 

                                        </div> <!--end form-group-->                           

                                    </form><!--end form-->

                                </div><!--end /div-->

                                

                                <div class="m-3 text-center text-muted">

                                    <p class="">Hai già un account? / Already have an account ? <a href="../login" class="text-primary ml-2">Log in</a></p>

                                </div>

                            </div><!--end card-body-->

                        </div><!--end card-->

                    </div><!--end auth-card-->

                </div><!--end col-->           

            </div><!--end row-->

        </div><!--end container-->

        <!-- End Log In page -->



        





        <!-- jQuery  -->

        <script src="assets/js/jquery.min.js"></script>

        <script src="assets/js/jquery-ui.min.js"></script>

        <script src="assets/js/bootstrap.bundle.min.js"></script>

        <script src="assets/js/metismenu.min.js"></script>

        <script src="assets/js/waves.js"></script>

        <script src="assets/js/feather.min.js"></script>

        <script src="assets/js/jquery.slimscroll.min.js"></script>        



        <!-- App js -->

        <script src="../assets/js/app.js"></script>

        

    </body>



</html>