You are not logged in.
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
No one knows?
Offline
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
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;'> </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:
Where Cat1 - is root category and Cat2 subcategory.
Offline
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
It work on glpi GLPI 0.84.2
Offline
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
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
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
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