<?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['email'])) { $emailuserto=$_POST['email']; }

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='$emailuserto'");

$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, idcompany, langid) VALUES ('$emailuserto', '$first_name', '$last_name', '12345!AA', '2','Active','$datein','$datein','$datein','$idcompany','$langid')";



// 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($emailuserto);  // 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}";

}

        

        

        

  }}

  ?>



<?php

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

$newcolleaguelist->setQuery("SELECT * FROM auth_users WHERE auth_users.idcompany='$idcompany' ORDER BY auth_users.last_name");

$newcolleaguelist->execute();?>



<!DOCTYPE html>

<html lang="en">

	

<head>

        <meta charset="utf-8" />

        <title>TRF CIMAC </title>

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

        <meta content="CIMAC TRF Portal" name="description" />

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

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

        <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">

        <meta http-equiv="Pragma" content="no-cache">

        <meta http-equiv="Expires" content="0">

        <!-- App favicon -->

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

    

         <!-- DataTables -->

    

   <link rel="shortcut icon" type="image/png" href="/media/images/favicon.png">

	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://www.datatables.net/rss.xml">

	<link rel="stylesheet" type="text/css" href="/media/css/site-examples.css?_=8f7cff5ee7757412879aedf3efbfaee01">

	<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.min.css">

	<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/2.3.2/css/buttons.dataTables.min.css">

	<style type="text/css" class="init">

	

	</style>

	<script type="text/javascript" src="/media/js/site.js?_=1d5abd169416a09a2b389885211721dd" data-domain="datatables.net" data-api="https://plausible.sprymedia.co.uk/api/event"></script>

	<script src="https://media.ethicalads.io/media/client/ethicalads.min.js"></script>

	<script type="text/javascript" src="/media/js/dynamic.php?comments-page=extensions%2Fbuttons%2Fexamples%2Finitialisation%2Fexport.html" async></script>

	<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>

	<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"></script>

	<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/2.3.2/js/dataTables.buttons.min.js"></script>

	<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>

	<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>

	<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>

	<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/2.3.2/js/buttons.html5.min.js"></script>

	<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/2.3.2/js/buttons.print.min.js"></script>

	<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

	<!-- Font Awesome -->

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-RqEzHvnvS1k5K5wzgp5yoWY5U6TD5EoXyj9iikETmdcy1G6dbCVa+ZmzBm7VWzmj8Ov7VwtA9x9X7VWjG8SRFg==" crossorigin="anonymous" referrerpolicy="no-referrer" />

		<!--Form Wizard-->

        <link href="../plugins/jquery-steps/jquery.steps.css" rel="stylesheet" type="text/css">



        <!-- 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" />



    

	

	<!-- submit form with button -->

<script>

function formSubmit() {

    document.forms["myForm"].submit();

}

</script>

</script>

	<script type="text/javascript" class="init">

	





$(document).ready(function() {

	var table = $('#example').DataTable( {

        pageLength: 20,

        order: [[0, 'desc']],

        

		dom: 'Bfrtip',

		buttons: [

			'copy', 'csv', 'excel', 'pdf'

		]

        

        

	} );

    

$('a.toggle-vis').on('click', function (e) {

        e.preventDefault();

 

        // Get the column API object

        var column = table.column($(this).attr('data-column'));

 

        // Toggle the visibility

        column.visible(!column.visible());

    });

    

} );









	</script>



    <script type="text/javascript" class="init">

	





$(document).ready(function() {

	var table = $('#readytrf').DataTable( {

        pageLength: 20,

        order: [[0, 'desc']],

        

		dom: 'Bfrtip',

		buttons: [

			'copy', 'csv', 'excel', 'pdf'

		]

        

        

	} );

    

$('a.toggle-vis').on('click', function (e) {

        e.preventDefault();

 

        // Get the column API object

        var column = table.column($(this).attr('data-column'));

 

        // Toggle the visibility

        column.visible(!column.visible());

    });

    

} );









	</script>

    <script>

document.getElementById('clonetrfalert').addEventListener('click', function(e) {

    e.preventDefault();

    if (confirm("Sei sicuro di voler andare al link clonetrf.php?")) {

        window.location.href = e.target.parentNode.href;

    }

});

</script>



</head>



    <body>

        

         <!-- Top Bar Start -->

                   

		

           

        <!-- Top Bar Start -->

         <?php include('include/topbar.php'); ?>

        <!-- Top Bar End -->



        

        <!-- Left Sidenav -->

        <?php include('include/leftsidenav.php'); ?>

    <!-- end left-sidenav-->



        <div class="page-wrapper">

            <!-- Page Content-->

            <div class="page-content">



                <div class="container-fluid">

                    <!-- Page-Title -->

                    <div class="row">

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

                            <div class="page-title-box">

                                <div class="float-right">

                                    <ol class="breadcrumb">

                                        <li class="breadcrumb-item"><a href="javascript:void(0);">TRF</a></li>

                                        <li class="breadcrumb-item active">Starter</li>

                                    </ol>

                                </div>

                                <h4 class="page-title"><?php echo $titlewb; ?></h4>

                            </div><!--end page-title-box-->

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

                    </div>

					<div class="row">

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

							

							

							

							<!-- DRAFT TRF -->

							

   

							

							<!-- COMPLETE TRF -->

                            <?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 } ?>

														<div class="card">

<div class="card-body">

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

                                    <h4 class="mt-0 header-title">Aggiungi nuovo utente / Collega</h4>

                                    <p class="text-muted mb-3">L'utente riceverà una mail con le istruzione per la prima impsotazione/reset password.

                                    </p> 

                                    <form class="was-validated" action="newusercolleague2.php" method="post" name="usernew">

                                        <div class="form-row">

                                            <div class="col-md-4 mb-3">

                                                <label for="validationServer01">Nome</label>

                                                <input type="text" class="form-control is-invalid" id="validationServer01" name="first_name" placeholder="nome"  required="">

                                                

                                            </div>

                                            <div class="col-md-4 mb-3">

                                                <label for="validationServer02">Cognome</label>

                                                <input type="text" class="form-control is-valid" id="validationServer02"  name="last_name" placeholder="Cognome"  required="">

                                                

                                            </div>

                                            <div class="col-md-4 mb-3">

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

                                                <div class="input-group">

                                                    <div class="input-group-prepend">

                                                        <span class="input-group-text" id="inputGroupPrepend3">@</span>

                                                    </div>

                                                    <input type="text" class="form-control is-invalid" id="validationServerUsername" name="email" placeholder="Email" aria-describedby="inputGroupPrepend3" required="">

                                                    

                                                </div>

                                            </div>

                                        </div>

						

								



                                        <div class="form-row">

                                      

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

                                            <label for="exampleFormControlSelect1">Lingua</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="company"  name="company" value="<?php echo $idcompany; ?>">

                                            <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>

                                       

									   

                                        <button class="btn btn-gradient-primary" type="submit">Inserisci</button>

                                        

                                    </form>

                                

                                

                                 

 

<br>



								  

								  

								

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

							

							

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

                                

							

						  <!-- card for show requirements -->

							<div class="card">

                              <div class="card-body">



                                <h4 class="mt-0 header-title">Colleghi con accesso al portale</h4>

                                 

                             <table id="readytrf" class="display table table-striped table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">

                                        <thead>

                                        <tr>

                                            <th>Name</th>

											<th>Last Name</th>

                                            <th>Email</th>

                                            



                                        </tr>

                                        </thead>

    

    

                                        <tbody>

                                       <?php

$wa_startindex = 0;

while(!$newcolleaguelist->atEnd()) {

  $wa_startindex = $newcolleaguelist->Index;

?>

        <tr>

                <td><?php echo($newcolleaguelist->getColumnVal("first_name")); ?></td>

				<td><?php echo($newcolleaguelist->getColumnVal("last_name")); ?></td>

				<td><?php echo($newcolleaguelist->getColumnVal("email")); ?></td>



                

        </tr>

		

        <?php

  $newcolleaguelist->moveNext();

}

$newcolleaguelist->moveFirst(); //return RS to first record

unset($wa_startindex);

unset($wa_repeatcount);

?>

                                        </tbody>

                                    </table>

<br>



								  

								  

								

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

							

							

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

                       

							

							

                       

                  </div>

              </div>

                    <!-- end page title end breadcrumb -->

                    



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

<!-- footer start -->

              <?php include('include/footer.php'); ?>

                </footer><!--end footer-->

    </div>

            <!-- end page content -->

        </div>

        <!-- end page-wrapper -->



        



        <!-- jQuery  -->



        <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>

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

        





	

	        <script src="../plugins/jquery-steps/jquery.steps.min.js"></script>

        <script src="assets/pages/jquery.form-wizard.init.js"></script>



        <!-- App js -->

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



    </body>



</html>