You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2013-11-18 11:17:47

mercury131
Member
Registered: 2013-10-15
Posts: 50

Changes to the form of selection of categories ticket

Hello everyone! I have a question about GLPI categories. How I can change  the form of selection of categories ticket?
I will explain, I want select the main category ticket, and then select subcategory. How on  this screenshot  http://gyazo.com/b74ae6f1352afa9873958cb11caf1424.png
Can I do it via default GLPI functional?

Offline

#2 2015-01-28 16:19:28

thiagomrvieira
Member
Registered: 2014-10-02
Posts: 9

Re: Changes to the form of selection of categories ticket

No one knows?

Offline

#3 2015-01-28 16:49:48

mercury131
Member
Registered: 2013-10-15
Posts: 50

Re: Changes to the form of selection of categories ticket

Hello!
I add it functional on glpi084 via custom php code.
It works in my production. But it's experemental code.
I add it in specialist ticket form.
If you want I can add instruction how to add it in glpi 0.84

Offline

#4 2015-01-29 12:09:14

mercury131
Member
Registered: 2013-10-15
Posts: 50

Re: Changes to the form of selection of categories ticket

Tutorial

Warning It's not my own code, and I take no responsibility for the performance of the this code

Open glpi root folder. Then open folder ajax.

Then create new file with name _category.php

Add this code in file _category.php

Code:

<?php
include ('../inc/includes.php');
global $DB;
$query = "SELECT * FROM glpi_itilcategories where itilcategories_id=".$_POST['id'];
$result = $DB->query($query);
echo '<option value="0" >---</option>';
if ($DB->numrows($result)) 
{
 while ($data=$DB->fetch_assoc($result))
 {
  if($current==$data['id'])
  {
   echo '<option value="'.$data['id'].'" selected>'.$data["name"].'</option>';
  }else{
   echo '<option value="'.$data['id'].'">'.$data["name"].'</option>';
  }
 }   
}
?>

Then open file /front/ticket.form.php

Find string

$_SESSION['gopro'] = 1; 

and add the this code exactly underneath

if(isset($_POST['itilsubcategories_id'])&&$_POST['itilsubcategories_id']>0)
 {
  $_POST['itilcategories_id']= $_POST['itilsubcategories_id'];
 }

 
 Your code is supposed to be so
 
 $_SESSION['gopro'] = 1;
 if(isset($_POST['itilsubcategories_id'])&&$_POST['itilsubcategories_id']>0)
 {
  $_POST['itilcategories_id']= $_POST['itilsubcategories_id'];
 }
   if (isset($_POST["_my_items"]) && !empty($_POST["_my_items"])) {
      $splitter = explode("_",$_POST["_my_items"]);
      if (count($splitter) == 2) {
         $_POST["itemtype"] = $splitter[0];
         $_POST["items_id"] = $splitter[1];
      }
      

     
Then find strings :

$_POST['view']=0;
 $_SESSION['gopro'] = 1;

and add this code exactly underneath

if(isset($_POST['itilsubcategories_id'])&&$_POST['itilsubcategories_id']>0)
 {
  $_POST['itilcategories_id']= $_POST['itilsubcategories_id'];
 }

Your code is supposed to be so

$_POST['view']=0;
 $_SESSION['gopro'] = 1;
 if(isset($_POST['itilsubcategories_id'])&&$_POST['itilsubcategories_id']>0)
 {
  $_POST['itilcategories_id']= $_POST['itilsubcategories_id'];
 }
   if (isset($_POST["_my_items"]) && !empty($_POST["_my_items"])) {
      $splitter = explode("_",$_POST["_my_items"]);
      if (count($splitter) == 2) {
         $_POST["itemtype"] = $splitter[0];
         $_POST["items_id"] = $splitter[1];
      }
   }

   
   
Then open file inc/ticket.class.php

Find string

echo "<span id='show_category_by_type'>";

And then replace the code:

global $DB;
         echo "<span id='show_category_by_type'>";
ITILCategory::dropdown($opt);
 echo "</span>"; 

to the new code:

global $DB;
         echo "<span id='show_category_by_type'>";
   $current = $this->fields["itilcategories_id"];
   $query = "SELECT * FROM glpi_itilcategories where id=".$this->fields["itilcategories_id"];
         $result = $DB->query($query);
   if ($DB->numrows($result)) 
         {
          while ($data=$DB->fetch_assoc($result))
   {
    if($data['itilcategories_id']!=0)
    {
     $current = $data['itilcategories_id'];
    }
    
   }
   }
    
  echo "<select  size='1' name='itilcategories_id' onchange='change_category(this)'>";
     $query = "SELECT *
                      FROM glpi_itilcategories where itilcategories_id=0";
           $result = $DB->query($query);
     if ($DB->numrows($result)) 
            {
              while ($data=$DB->fetch_assoc($result))
     {
      if($current==$data['id'])
     {
      echo '<option value="'.$data['id'].'" selected>'.$data["name"].'</option>';
     }else{
      echo '<option value="'.$data['id'].'">'.$data["name"].'</option>';
     }
     if($current==0)
     {
      $current=$data['id'];
     }
 
     }   
   }
   echo '</select>';
   
   echo "<p style='font-size:2px;'>&nbsp;</p>";
   echo "<select  size='1' name='itilsubcategories_id' id='sub'>";
   echo '<option value="0" >---</option>';
      $query = "SELECT * FROM glpi_itilcategories where itilcategories_id=".$current;
            $result = $DB->query($query);
      if ($DB->numrows($result)) 
            {
             while ($data=$DB->fetch_assoc($result))
    {
     if($this->fields["itilcategories_id"]==$data['id'])
     {
      echo '<option value="'.$data['id'].'" selected>'.$data["name"].'</option>';
     }else{
      echo '<option value="'.$data['id'].'">'.$data["name"].'</option>';
     }
     }   
   }
   echo "</select>
   <script>
   function change_category(element)
   {
    //alert(element.value);
    //if(element.value>0)
    //{
    // document.getElementById(sub).attributes.removeNamedItem(disabled);
    //}else{
    // document.getElementById(sub).attributes.addNamedItem(disabled);
    //}
    Ext.Ajax.request({
       url: '/ajax/_category.php',
       success: function(response, opts){ document.getElementById('sub').innerHTML = response.responseText;}, 
       headers: {
          // 'my-header': 'foo'
       },
       params: { id: element.value }
    });
    //alert($(element).val());
    
   }
   </script>
   ";
   //echo $this->fields["itilcategories_id"];//Dropdown::getDropdownName("glpi_itilcategories", $this->fields["itilcategories_id"]);
         // ITILCategory::dropdown($opt);
         
    // ITILCategory::dropdown($opt);
         echo "</span>";

   
Result will be like this:

214324242314214.png

Where Cat1 - is root category and Cat2 subcategory.

Offline

#5 2015-01-30 14:32:52

thiagomrvieira
Member
Registered: 2014-10-02
Posts: 9

Re: Changes to the form of selection of categories ticket

Thanks Mercury, but it doesn't work here.
My GLPI version is 0.84.8 i'm not sure if was for this or other problem.

I don't found these strings "$_POST['view']=0;" and "$_SESSION['gopro'] = 1;" but i inserted the code above this code:

" if (isset($_POST["_my_items"]) && !empty($_POST["_my_items"])) {
      $splitter = explode("_",$_POST["_my_items"]);
      if (count($splitter) == 2) {
         $_POST["itemtype"] = $splitter[0];
         $_POST["items_id"] = $splitter[1];
      }"





Thiago Maciel
thiagomrvieira@gmail.com

Offline

#6 2015-01-30 15:15:46

mercury131
Member
Registered: 2013-10-15
Posts: 50

Re: Changes to the form of selection of categories ticket

It work on glpi GLPI 0.84.2

Offline

#7 2022-03-04 06:55:56

giang
Member
Registered: 2022-02-11
Posts: 50

Re: Changes to the form of selection of categories ticket

mercury131 wrote:

It work on glpi GLPI 0.84.2

@All,

Thanks, mercury131 pointed how to do. It sounds like good solution atthough involve many codes in hand

So, let me know if it work with 9.5.5 ?

Thanks,
Giang.

Offline

#8 2022-03-05 19:18:53

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: Changes to the form of selection of categories ticket

There is a plugin for this if you have a GLPI-Network subscription.
https://plugins.glpi-project.org/#/plugin/splitcat


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#9 2023-07-03 17:15:34

horus95
Member
Registered: 2023-07-03
Posts: 2

Re: Changes to the form of selection of categories ticket

I'm using GLPI 10 and just now I discovered that this is a paid functionally. Frankly I'm kinda baffled, this is so basic that I assumed it was included in the open source version.
If you have many categories, without that GLPI is basically unusable.

I will try to see if I can come up with something, and if so I will post here.

Last edited by horus95 (2023-07-03 17:17:39)

Offline

#10 2024-09-19 08:33:58

helsing
Member
Registered: 2024-09-19
Posts: 2

Re: Changes to the form of selection of categories ticket

horus95 wrote:

I'm using GLPI 10 and just now I discovered that this is a paid functionally. Frankly I'm kinda baffled, this is so basic that I assumed it was included in the open source version.
If you have many categories, without that GLPI is basically unusable.

I will try to see if I can come up with something, and if so I will post here.

Did you find a solution?

Offline

Board footer

Powered by FluxBB