Skip to content

Instantly share code, notes, and snippets.

@renatoschroepfer
Last active November 16, 2017 19:11
Show Gist options
  • Save renatoschroepfer/87c36f1195e24d50df20a71a670fb488 to your computer and use it in GitHub Desktop.
Save renatoschroepfer/87c36f1195e24d50df20a71a670fb488 to your computer and use it in GitHub Desktop.
<?php
$query = "SELECT id, name FROM `glpi_entities`.`name";
echo "<script>";
echo "function change(select) {";
echo " window.open('helpdesk.public.php?create_ticket=1&active_entity=' + select.value,'_self'); ";
echo "}";
echo "</script>";
echo '<td>Deseja abrir chamado para qual setor</td>';
echo '<td>';
echo '<select onchange="change(this)">';
echo '<option value="0">Selecione o setor</option>';
echo '<option value="2" selected="selected"> Tecnologia da Informação</option>';
echo '<option value="3"selected="selected">Comunicação</option>';
echo '</select>';
echo '</td>';
echo '</tr>';
@renatoschroepfer
Copy link
Author

renatoschroepfer commented Nov 16, 2017

/Conexão local para confirmar se o problema é a conexão com o banco que está impedindo o retorno dos dados/

//Connect database
$db = mysqli_connect('localhost','root','password','db')
or die('Error connecting to MySQL.');

  //Select database
  $query = "SELECT `id`, `name` FROM `glpi_entities`";
  mysqli_query($db, $query) or die('Error querying database.');
  $result = mysqli_query($db, $query);
  $row = mysqli_fetch_array($result);
  echo "<script>";
  echo "function change(select) {";
  echo " window.open('helpdesk.public.php?create_ticket=1&active_entity=' + select.value,'_self'); ";
  echo "}";
  echo "</script>"; 
  echo '<td>Deseja abrir chamado para qual setor</td>';
  echo '<td>';
  echo '<select onchange="change(this)">';
  echo '<option value="">Selecione o setor</option>';
  while ($row = mysqli_fetch_array($result)) {
      echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';  
  }
  echo '</select>';
  echo '</td>';
  echo '</tr>';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment