mardi 20 décembre 2022

Combining foreach and while in PHP

I need help, my code below does not show me all the rows that come from the database. I have 8 rows but they show me only 6 rows. if I try to change the break to put it a little lower, it displays all the rows except that it repeats the same file in the checkbox.

<?php
ob_start();
include('_TEMPLATE_/header.inc.php');
?>
<?php  

    if(isset($_POST['download'])){
        $file_to_remove = glob("downloads/*.zip");
        foreach ($file_to_remove as $file) {
            unlink($file);
        }

        if(!isset($_POST['theme-files'])){
            $error = "<div class='alert alert-danger' role='alert'>Attention, Vous devez au moins selectionner un fichier pour télécharger !!!</div>";
        }else{
            $themes = $_POST['theme-files'];

            $characters = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz";
            $string_length = 4;

            $random_characters = substr(str_shuffle($characters), 0, $string_length);
            $zip_name = "Cvs_{$random_characters}.zip";

            $zip_name = "Cvs.zip";
        
            $zip = new ZipArchive();
            $zip->open("downloads/{$zip_name}", ZipArchive::CREATE);
            foreach ($themes as $file) {
                $zip->addFile($file, basename($file));
            }
            $zip->close();
            if(! headers_sent()){
                header("location: downloads/$zip_name");
                ob_end_flush();
            }else{
                echo'<script type="text/javascript">window.location.href="downloads/'.$zip_name.'"</script>';
            }
            

            //echo'<script> location.replace("downloads/'.$zip_name.'"); </script>';
            echo'<script type="text/javascript">window.location.href="viviers"</script>';
        }
    }
?>
<!-- Loader -->
<div id="preloader">
    <div id="status">
        <div class="spinner">
            <i class="ri-loader-line spin-icon"></i>
        </div>
    </div>
</div>
<div class="main-content">
    <div class="page-content">
        <div class="container-fluid">
            <!-- start page title -->
            <div class="row">
                <div class="col-12">
                    <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                        <h4 class="mb-sm-0"></h4>
                            <div class="page-title-right">
                            <ol class="breadcrumb m-0">
                                <li class="breadcrumb-item"><a href="javascript: void(0);">Nazox</a></li>
                                <li class="breadcrumb-item active">Viviers
                                </li>
                            </ol>
                        </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- end page title -->
            <!-- start page title -->
            <div class="row">
                <div class="col-lg-12">
                <div class="line__separator"></div>
                    <div class="card">
                    <h6 class="card-header"><?php echo $title; ?> | Viviers</h6>
                        <div class="card-body">
                            <div class="data__separator"></div>
                            <div class="dataTables_wrapper dt-bootstrap4 no-footer">
                            <form action="" method="post" enctype="multipart/form-data">
                                <table id="scroll-vertical-datatable" class="table dt-responsive nowrap w-100">
                                    <thead class="thead-light">
                                    <div>
                                    <button type="submit" class="btn btn-success" id="submit_prog" name="download"><i class="ri-download-fill mb-2"></i> Télécharger le CV</button>
                                    </div>
                                    <p class="error"></p>
                                        <?php echo @$error; ?>
                                        <tr>
                                            <th>
                                                Selectionner
                                            </th>
                                            <th>ID</th>
                                            <th>Date vivier</th>
                                            <th>Expérience</th>
                                            <th>Diplôme</th>
                                            <th>Prénom</th>
                                            <th>Nom</th>
                                            <th>Postnom</th>
                                            <th>Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $query = "SELECT `apply`.`id`, `apply`.`sexe`, `apply`.`prenom`, `apply`.`nom`, `apply`.`postnom`, `apply`.`tel`, `apply`.`email`, `apply`.`datetime`, `apply`.`cv`, `apply`.`lettre`, `apply`.`id_offre`, `apply`.`status`, `apply`.`years`, `apply`.`diplome`, `postes`.`title` FROM `apply` JOIN `postes` ON `apply`.`id_offre` = `postes`.`id` ORDER BY `apply`.`id` DESC";
                                        //$query = "SELECT * FROM `apply`";
                                        $run_query = mysqli_query($conn, $query);
                                        $count = mysqli_num_rows($run_query);
                                        if($count < 1){
                                            echo '<tr>';
                                            echo '<td></td>';
                                            echo '<td></td>';
                                            echo '<td></td>';
                                            echo '<td></td>';
                                            echo '<td>
                                            <div class="nothing">
                                            <div class="alert alert-danger" role="alert">
                                            <i class="mdi mdi-alert-outline me-2"></i> Votre vivier est encore vide, revenez plus tard !!!
                                            </div></div></td>
                                            ';
                                            echo '<td></td>';
                                            echo '<td></td>';
                                            echo '<td></td>';
                                            echo '</tr>'; 
                                        }else{
                                        $i = 1;                                       
                                        while ($row = mysqli_fetch_assoc($run_query)) {
                                            $files = glob("uploads/cvs/*");
                                            foreach ($files as $theme_file){
                                                $id = $row['id'];
                                                //$user_id = $row['id'];
                                                $sexe = ucfirst($row['sexe']);
                                                $datetime = $row['datetime'];
                                                $date = date("d/m/Y", strtotime($datetime));
                                                $prenom = ucfirst($row['prenom']);
                                                $nom = ucfirst($row['nom']);
                                                $postnom = ucfirst($row['postnom']);
                                                $cv = $row['cv'];
                                                $lettre = $row['lettre'];
                                                $poste = ucfirst($row['title']);
                                                $status = $row['status'];
                                                $years = $row['years'];
                                                $diplome = ucfirst($row['diplome']);
                                                
                                        ?>
                                            <tr>                                               
                                                <td>
                                                <input type="checkbox" name="theme-files[]" value="<?php echo $theme_file; ?>">                                          
                                                </td>                                 
                                                <td><?php echo $i; ?></td>
                                                <td><?php echo $date; ?></td>
                                                <td><?php echo $years; ?> an(s)</td>
                                                <td>
                                                <span class="badge bg-info">
                                                    <?php echo $diplome; ?>
                                                </span>
                                                </td>
                                                <td>
                                                    <?php
                                                    if ($status == '1') {

                                                        echo '<span class="badge bg-info float-end mt-1"><i class="ri-lock-2-line"></i></span>';
                                                    }
                                                    ?>
                                                    <?php echo $prenom; ?>
                                                </td>
                                                <td><?php echo $nom; ?></td>
                                                <td><?php echo $postnom; ?></td>
                                                <td>
                                                <a onclick="cvIinfo(<?php echo $id; ?>)" id="<?php echo $id; ?>" class="userinfo view_cv" href="javascript:void(0)"><i class="mdi mdi-magnify-scan font-size-18"></i></a>
                                                
                                                <?php
                                                if(!empty($lettre)){
                                                    echo '
                                                    <a href="uploads/lettres/'.$lettre.'" class="me-3 text-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="Lettre de motivation">
                                                    <i class="mdi mdi-paperclip font-size-18"></i></a></td>';
                                                } ?>
                                                
                                                </td>
                                            </tr>
                                        </div> 
                                        <?php $i++; ?>
                                        <?php } ?>

                                        <?php } ?>   
                                        <?php break;?>                                  
                                        <?php } ?>                                       
                                    </tbody>
                                </table>
                            </form>
                            </div>
                        </div>
                    </div>
                </div> <!-- end col -->
            </div> <!-- end row -->
            <!-- end row -->
        </div>
    </div>
    <!-- End Page-content -->
    <footer class="footer">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-6">
                    <script>
                        document.write(new Date().getFullYear())
                    </script> © <?php echo $copyright; ?>.
                </div>
                <div class="col-sm-6">
                    <div class="text-sm-end d-none d-sm-block">
                    Crafted with <i class="mdi mdi-heart text-danger"></i> | Version <?php echo $version; ?>
                    </div>
                </div>
            </div>
        </div>
    </footer>

</div>
<!-- end main content-->

</div>
<!-- END layout-wrapper -->

<!-- JAVASCRIPT -->
<script src="assets/libs/jquery/jquery.min.js"></script>
<script src="assets/js/timeout.js"></script>
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/libs/metismenu/metisMenu.min.js"></script>
<script src="assets/libs/simplebar/simplebar.min.js"></script>
<script src="assets/libs/node-waves/waves.min.js"></script>

<!-- Required datatable js -->
<script src="assets/libs/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="assets/libs/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>
<!-- Buttons examples -->
<script src="assets/libs/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
<script src="assets/libs/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js"></script>
<script src="assets/libs/jszip/jszip.min.js"></script>
<script src="assets/libs/pdfmake/build/pdfmake.min.js"></script>
<script src="assets/libs/pdfmake/build/vfs_fonts.js"></script>
<script src="assets/libs/datatables.net-buttons/js/buttons.html5.min.js"></script>
<script src="assets/libs/datatables.net-buttons/js/buttons.print.min.js"></script>
<script src="assets/libs/datatables.net-buttons/js/buttons.colVis.min.js"></script>

<script src="assets/libs/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
<script src="assets/libs/datatables.net-select/js/dataTables.select.min.js"></script>

<!-- Responsive examples -->
<script src="assets/libs/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
<script src="assets/libs/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js"></script>

<!-- Datatable init js -->
<script src="assets/js/pages/datatables.init.js"></script>

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


<script src="https://unpkg.com/pdfobject@2.2.8/pdfobject.min.js"></script>
</body>

</html>

<script>
    function cvIinfo(id){
        $.ajax({
            url: 'backend/view_modal.php',
            type: 'post',
            data: {userid: id},
            success: function(response){ 
                $('#show__modal').html(response); 
                $('#empModal').modal('show'); 
            }
        });
    }

    function save_note(id){
     
     var get_note = $('#get_note').val();
     $.ajax({
        url:'backend/update_note.php',
        type:'post',
        data:{get_note: get_note, id:id},
        success: function(response){
            if(response == 'success'){
                $('#result_note').css("color", "green").html('Mise à jour réussie...');
                return true;
            }else{
                $('#result_note').css("color", "red").html(response);
                return false;
            }
        }
     })
    }
    
</script>

<script>
$(document).ready(function() {

var $submit = $("#submit_prog").hide(),
    $cbs = $('input[name="theme-files[]"]').click(function() {
        $submit.toggle( $cbs.is(":checked") );
    });

});
</script>

<div id="show__modal"></div>

I would like each checbox to have its own file and on the other side to show me all the rows




lundi 19 décembre 2022

Is there a way to get a checkbox component out of a checkboxgroup component in Vaadin 23.3.0?

I need a single checkbox component to add a tool-tip on it. However, the component is of a CheckboxGroup type. Is there a way to get a Checkbox component out of a CheckboxGroup component?

I have tried to look up different type of methods on the CheckbocGroup class but I can get the Items back which are a Enum type. I need a class that is a child class of the Vaadin Component class. I was expecting something like:

CheckboxGroup<Enum> checkboxGroup = new CheckboxGroup();
checkboxGroup.setItems(Enum.values())

Checkbox checkbox = checkboxGroup.getCheckboxOfType(Enum.Type);
checkbox.setTooltipText("TEST");



Vue3: Controlling checkbox checked state by a component prop

This is the setup:

Parent component: Has a reactive Todo object with a checked state {checked: true and passes it to a Todo component.

Todo component: Accepts the Todo as a prop and binds the checked value to a checkbox. Upon toggling the checkbox, it emits an event to the parent, which then asynchronously updates the checked state of the Todo.

Parent:

<template>
  <Todo @update="handleUpdate" :todo="todo" />
</template>

<script setup>
import { reactive } from "vue";
import Todo from "./components/Todo.vue";

let todo = reactive({ checked: true });

let handleUpdate = (e) => {
  setTimeout(() => {
    // Always sets it to false for test purposes
    todo.checked = false;
  }, 1000);
};
</script>

Child:

<template>
  <input type="checkbox" v-model="checkboxProxy" />
</template>

<script setup>
const { computed, defineProps, defineEmits } = require("vue");

let props = defineProps(["todo"]);
let emit = defineEmits(["update"]);

let checkboxProxy = computed({
  get() {
    return props.todo.checked;
  },
  set(val) {
    emit("update", val);
  },
});
</script>

Question: I would expect the checkbox to get unchecked a second after it has been checked. But that doesn't happen. Why?

Codesandbox: https://codesandbox.io/s/crazy-snow-kdse27

I also tried this setup:

<input type="checkbox" :checked="todo.checked" @change="emit('update)" />

But it still not reflecting the todo state. I'm testing in Brave it that matters.




dimanche 18 décembre 2022

Oracle APEX looping through CheckBox Group elements

I need to make the function of inserting data into several tables at once in the ORACLE APEX App Builder. Interactive report displays information from the View collected from the tables "Book", "Autors_list", "Autor", where "Autors_list" is needed to reveal the many-to-many relationship between the author and the book.

So, on an automatically created form, when I click on the CREATE button, using a dynamic event, I try to add data to the "Book" and "Autors_list" tables.

The data I'm trying to add:

P15_ID_BOOK - book id - add to "Book" and to "Autors_list"

P15_BOOK_NAME - book name - add to "Book"

P15_AUTORS - authors - are represented using the Checkbox Group - I need to go through each of its elements and for each element add an entry to the "Autors_list" in the form (P15_BOOK_NAME, author id from P15_AUTORS)

P15_PUBLICATION_DATE - publication date - add to "Book"

P15_PRICE - book's price - add to "Book"

The CheckBox Group is set using the following List of Values

`

select "id_autor", (CONCAT(CONCAT(autor."Name", ' '),autor."Surname")) as "Autors" from "Autor" autor;

`

I wrote the following PL/SQL code to add the above values to the tables:

begin
insert into "Book"
("Name", "Publication_date", "Price")
values
(:P15_BOOK_NAME, :P15_PUBLICATION_DATE, :P15_PRICE);

FOR i IN (select * from table(apex_string.split(:P15_AUTORS, ',')))
LOOP
 insert into "Autors_list"
 values (:P15_ID_BOOK, i);
END LOOP;
end ;

However, it gives me an error

ORA-01008: not all variables bound

Please tell me how to cycle through the elements of the Checkbox Group correctly and get the values from there




samedi 17 décembre 2022

CheckboxGroupInput with Conditional panel for choices

I am trying to get an app in which user will choose from "Variables set no 1" and conditionally another set of variables will show up (e.g. if A and B chosen in set 1 then A1 in second set will show up) and if box ticked the input variables will show up. I have done it with checkboxGroupInput and then set of checkboxInput but would like to have the latter turn into another checkboxGroupInput for filtering. To do so the conditional panel (of if - else, although I tried it and its not working) needs to be allowed to create dynamically list of choices. Rudimentary version of the code is below.

library(shiny)

ui <- fluidPage(

  fluidRow(column(4, 
             checkboxGroupInput("variables", 
                                "Variables set 1",
                                choices  = c("A", "B", "C", "D"),
                                selected = NULL)), 

##########################################################
# How to change this section into checkboxGroupInput?????? 
##########################################################
           column(8,
             conditionalPanel(
               condition='input.variables.indexOf("A") > -1 &
                          input.variables.indexOf("B") > -1',
               checkboxInput(inputId = "a1", label = "A1", value = FALSE)),
             
             conditionalPanel(
               condition='input.variables.indexOf("B") > -1 &
                          input.variables.indexOf("D") > -1',
               checkboxInput(inputId = "a2", label = "A2", value = FALSE)),
             
             conditionalPanel(
               condition='input.variables.indexOf("B") > -1 &
                          input.variables.indexOf("C") > -1 &
                          input.variables.indexOf("D") > -1',
               checkboxInput(inputId = "a3", label = "A3", value = FALSE)))), 
########################################################## 


  fluidRow(column(6, 
      conditionalPanel(
        condition = "input.a1 == 1 || input.a2 == 1",
            radioButtons(inputId = "A11", 
                         label = "A blah",
                         choices = list("Bla" = 2, "Ble" = 3),
                         selected = 2)),

      conditionalPanel(
        condition = "input.a3 == 1",
            sliderInput(inputId = "B11", 
                        label = "B blah",
                        min = 1, max = 10, value = 5, step = 1)),
      conditionalPanel(
        condition = "input.a1 == 1 || input.a2 == 1 || input.a3 == 1",
            sliderInput(inputId = "C11", 
                        label = "C blah",
                        min = 1, max = 10, value = 5, step = 1))))
  
)

server <- function(input, output, session) {}

shinyApp(ui = ui, server = server)

Thank you in advance!




vendredi 16 décembre 2022

Check only a range of checkboxes

I have this code with works brilliantly for me. I just need a small alteration to be able to select a range of cells as well, meaning:

Either H15-H17 or H22 or H26 in the attached image.enter image description here

the code I have is the following:

var CHECKBOX_CELLS = ["H15", "H22", "H26"];

function onEdit(e) {
  var range = e.range;

  var checkboxIndex = CHECKBOX_CELLS.indexOf(range.getA1Notation());

  if (checkboxIndex > -1 && range.getValue() == true) {
    var sheet = range.getSheet();

    for (var i=0; i<CHECKBOX_CELLS.length; i++) {
      if (i==checkboxIndex) continue;

      sheet.getRange(CHECKBOX_CELLS[i]).setValue(false);
    }
  }
}




jeudi 15 décembre 2022

How can I filter and show an array with React?

I'm trying to filter some companies array -that is being shown in a table- using multiple checkboxes. These checkboxes returns an array of strings with some status. For example: ['accepted', 'pending', 'declined'];. The problem is that while the checkboxes returns the status OK, I cannot manage to filter the companies array with the checkboxes data.

Here is my main code:

function App() {

  const [filters, setFilters] = useState([]);
  const [companies, setCompanies] = useState([
    { id: 1, status: "accepted", name: "001", date: "01/01/2022" },
    { id: 2, status: "accepted", name: "001", date: "01/01/2022" },
    { id: 8, status: "accepted", name: "001", date: "10/04/2022" },
  ]);

  //HERE I TRY TO FILTER MY COMPANIES ARRAY WITH THE SELECTED CHECKBOXES
  const showFilteredCompanies = (filters) => {
    return [...companies].filter((company) => {
      return filters.includes(company.status);
    });
  }


  //Inside data I have my array of selected status like this: ['accepted', 'pending', 'declined']

  const handleFilters = (data) => {
    
    let newFilters = {...filters};
    newFilters = data;
    setFilters(newFilters);

    // THIS CONSOLE.LOG SHOWS THE FILTERED ARRAY OF COMPANIES JUST FINE
    console.log(showFilteredCompanies(newFilters));

    const filtered = showFilteredCompanies(newFilters);

    //BUT WHEN I TRY TO SAVE MY COMPANIES FILTERED ARRAY IN MY STATE THE FILTERING DOESN'T WORK AS IT SHOULD
    console.log(filtered);
    setCompanies(filtered);
  }

  return (
    <div className="App">

      <Checkbox 
        handleFilters={data => handleFilters(data)}
      />

      {/* companies list */}
      <div>
        {companies.length ? 
          (
            <table>
              <thead>
                <tr>
                  <th>ID</th>
                  <th>Estado</th>
                  <th>nombre</th>
                  <th>Fecha</th>
                </tr>
              </thead>
              <tbody>
                {companies.map((company, i) => (
                    <tr key={i}>
                      <td>{company.id}</td>
                      <td>{company.status}</td>
                      <td>{company.name}</td>
                      <td>{company.date}</td>
                    </tr>
                  )
                )}
              </tbody>
            </table>   
          ) : (
            <h2>No hay compañías para mostrar</h2>
          )
        }
      </div>

      {/* list length */}
      <div>
          <h3>Cantidad de compañías: {companies.length}</h3>
      </div>
    </div>
  );
}

export default App;

I was expecting to filter my companies array with all the strings of my checkboxes data array to show only the companies.status that matches the selected status of the checkboxes