├── pics
└── vip.png
├── locales
├── en_GB.mo
├── fr_FR.mo
├── en_GB.po
├── glpi.pot
└── fr_FR.po
├── README.md
├── install
├── sql
│ ├── update-1.7.3.sql
│ ├── update-1.8.0.sql
│ ├── empty-1.1.2.sql
│ ├── empty-1.5.0.sql
│ ├── empty-1.7.3.sql
│ ├── empty-1.8.0.sql
│ └── empty-1.0.0.sql
└── index.php
├── tools
├── extract_template.sh
├── update_mo.pl
└── update_po.pl
├── .github
└── workflows
│ ├── updatepot.yml
│ ├── generatemo.yml
│ └── release.yml
├── vip_load_scripts.js.php
├── index.php
├── ajax
├── index.php
├── loadscripts.php
├── ticket.php
└── getDropdownUsers.php
├── front
├── index.php
├── rulevip.php
├── rulevip.form.php
├── group.form.php
├── rulesengine.test.php
└── rule.test.php
├── inc
├── index.php
├── rulevipcollection.class.php
├── rulevip.class.php
├── vip.class.php
├── ticket.class.php
├── dashboard.class.php
├── profile.class.php
└── group.class.php
├── setup.php
├── vip.xml
├── vip.js.php
├── hook.php
└── LICENSE
/pics/vip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfotelGLPI/vip/master/pics/vip.png
--------------------------------------------------------------------------------
/locales/en_GB.mo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfotelGLPI/vip/master/locales/en_GB.mo
--------------------------------------------------------------------------------
/locales/fr_FR.mo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfotelGLPI/vip/master/locales/fr_FR.mo
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vip
2 | VIP Plugin for GLPI
3 |
4 | Plugin migrated to https://github.com/pluginsGLPI/vip
5 |
--------------------------------------------------------------------------------
/install/sql/update-1.7.3.sql:
--------------------------------------------------------------------------------
1 | ALTER TABLE `glpi_plugin_vip_groups` ADD
2 | `vip_color` varchar(10) DEFAULT '#ff0000' NOT NULL;
--------------------------------------------------------------------------------
/install/sql/update-1.8.0.sql:
--------------------------------------------------------------------------------
1 | ALTER TABLE `glpi_plugin_vip_groups` ADD `vip_icon` varchar(100) DEFAULT 'fa-exclamation-triangle';
2 | ALTER TABLE `glpi_plugin_vip_groups` ADD `name` varchar(100) DEFAULT 'VIP';
3 |
--------------------------------------------------------------------------------
/tools/extract_template.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Only strings with domain specified are extracted (use Xt args of keyword param to set number of args needed)
4 |
5 | xgettext *.php */*.php --copyright-holder='VIP Development Team' --package-name='GLPI - VIP plugin' -o locales/glpi.pot -L PHP --add-comments=TRANS --from-code=UTF-8 --force-po \
6 | --keyword=_n:1,2,4t --keyword=__s:1,2t --keyword=__:1,2t --keyword=_e:1,2t --keyword=_x:1c,2,3t \
7 | --keyword=_ex:1c,2,3t --keyword=_nx:1c,2,3,5t --keyword=_sx:1c,2,3t
--------------------------------------------------------------------------------
/install/sql/empty-1.1.2.sql:
--------------------------------------------------------------------------------
1 | -- --------------------------------------------------------
2 | -- Structure de la table 'glpi_plugin_vip_groups'
3 | -- --------------------------------------------------------
4 | CREATE TABLE `glpi_plugin_vip_groups` (
5 | `id` int(11) NOT NULL default 0 COMMENT 'RELATION to glpi_groups(id)',
6 | `isvip` tinyint(1) default '0',
7 | PRIMARY KEY (`id`)
8 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
9 |
10 | INSERT INTO `glpi_plugin_vip_groups` (`id`, `isvip`) VALUES ('0', '0');
11 |
--------------------------------------------------------------------------------
/install/sql/empty-1.5.0.sql:
--------------------------------------------------------------------------------
1 | -- --------------------------------------------------------
2 | -- Structure de la table 'glpi_plugin_vip_groups'
3 | -- --------------------------------------------------------
4 | CREATE TABLE `glpi_plugin_vip_groups` (
5 | `id` int(11) NOT NULL default 0 COMMENT 'RELATION to glpi_groups(id)',
6 | `isvip` tinyint(1) default '0',
7 | PRIMARY KEY (`id`)
8 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
9 |
10 | INSERT INTO `glpi_plugin_vip_groups` (`id`, `isvip`) VALUES ('0', '0');
11 |
--------------------------------------------------------------------------------
/install/sql/empty-1.7.3.sql:
--------------------------------------------------------------------------------
1 | -- --------------------------------------------------------
2 | -- Structure de la table 'glpi_plugin_vip_groups'
3 | -- --------------------------------------------------------
4 | CREATE TABLE `glpi_plugin_vip_groups` (
5 | `id` int(11) NOT NULL default 0 COMMENT 'RELATION to glpi_groups(id)',
6 | `isvip` tinyint(1) default '0',
7 | `vip_color` varchar(10) DEFAULT '#ff0000' NOT NULL,
8 | PRIMARY KEY (`id`)
9 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
10 |
11 | INSERT INTO `glpi_plugin_vip_groups` (`id`, `isvip`) VALUES ('0', '0');
12 |
--------------------------------------------------------------------------------
/tools/update_mo.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | #!/usr/bin/perl -w
3 |
4 | if (@ARGV!=0){
5 | print "USAGE update_mo.pl\n\n";
6 |
7 | exit();
8 | }
9 |
10 |
11 | opendir(DIRHANDLE,'locales')||die "ERROR: can not read current directory\n";
12 | foreach (readdir(DIRHANDLE)){
13 | if ($_ ne '..' && $_ ne '.'){
14 |
15 | if(!(-l "$dir/$_")){
16 | if (index($_,".po",0)==length($_)-3) {
17 | $lang=$_;
18 | $lang=~s/\.po//;
19 |
20 | `msgfmt locales/$_ -o locales/$lang.mo`;
21 | }
22 | }
23 |
24 | }
25 | }
26 | closedir DIRHANDLE;
27 |
28 | #
29 | #
30 |
--------------------------------------------------------------------------------
/install/sql/empty-1.8.0.sql:
--------------------------------------------------------------------------------
1 | -- --------------------------------------------------------
2 | -- Structure de la table 'glpi_plugin_vip_groups'
3 | -- --------------------------------------------------------
4 | CREATE TABLE `glpi_plugin_vip_groups` (
5 | `id` int unsigned NOT NULL default 0 COMMENT 'RELATION to glpi_groups(id)',
6 | `name` varchar(100) DEFAULT 'VIP',
7 | `isvip` tinyint default '0',
8 | `vip_color` varchar(10) DEFAULT '#ff0000' NOT NULL,
9 | `vip_icon` varchar(100) DEFAULT 'fa-exclamation-triangle',
10 | PRIMARY KEY (`id`)
11 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
12 |
13 | INSERT INTO `glpi_plugin_vip_groups` (`id`, `isvip`) VALUES ('0', '0');
14 |
--------------------------------------------------------------------------------
/.github/workflows/updatepot.yml:
--------------------------------------------------------------------------------
1 | name: Update POT
2 | on:
3 | push:
4 | branches: [ master ]
5 | paths-ignore:
6 | - 'locales/**'
7 |
8 | env:
9 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 | jobs:
11 | run:
12 |
13 | name: Update POT
14 |
15 | runs-on: ubuntu-latest
16 | steps:
17 | - name: Checkout repo
18 | uses: actions/checkout@v2
19 |
20 | - name: install xgettext
21 |
22 | run: sudo apt-get install gettext;
23 | - name: Update POT
24 | run: sh tools/extract_template.sh;
25 |
26 |
27 | - name: Commit changes
28 | uses: EndBug/add-and-commit@v5.1.0
29 | with:
30 | message: "Update POT"
31 | - name: Push changes
32 |
33 | uses: actions-go/push@v1
34 |
35 |
--------------------------------------------------------------------------------
/tools/update_po.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | #!/usr/bin/perl -w
3 |
4 | if (@ARGV!=2){
5 | print "USAGE update_po.pl transifex_login transifex_password\n\n";
6 |
7 | exit();
8 | }
9 | $user = $ARGV[0];
10 | $password = $ARGV[1];
11 |
12 | opendir(DIRHANDLE,'locales')||die "ERROR: can not read current directory\n";
13 | foreach (readdir(DIRHANDLE)){
14 | if ($_ ne '..' && $_ ne '.'){
15 |
16 | if(!(-l "$dir/$_")){
17 | if (index($_,".po",0)==length($_)-3) {
18 | $lang=$_;
19 | $lang=~s/\.po//;
20 |
21 | `wget --user=$user --password=$password --output-document=locales/$_ http://www.transifex.com/api/2/project/GLPI_vip/resource/glpipot/translation/$lang/?file=$_`;
22 | }
23 | }
24 |
25 | }
26 | }
27 | closedir DIRHANDLE;
28 |
29 | #
30 | #
31 |
--------------------------------------------------------------------------------
/vip_load_scripts.js.php:
--------------------------------------------------------------------------------
1 |
7 |
8 | var root_vip_doc = "";
9 | (function ($) {
10 |
11 | $.fn.vip_load_scripts = function () {
12 |
13 | init();
14 | // Start the plugin
15 | function init() {
16 | // Send data
17 | $.ajax({
18 | url: root_vip_doc +'/ajax/loadscripts.php',
19 | type: "POST",
20 | dataType: "html",
21 | data: 'action=load',
22 | success: function (response, opts) {
23 | var scripts, scriptsFinder = /";
51 | break;
52 | }
53 |
--------------------------------------------------------------------------------
/front/rulesengine.test.php:
--------------------------------------------------------------------------------
1 | .
27 | --------------------------------------------------------------------------
28 | */
29 |
30 | if (!defined('GLPI_ROOT')) {
31 | include('../../../inc/includes.php');
32 | }
33 |
34 | Session::checkCentralAccess();
35 |
36 | if (isset($_POST["sub_type"])) {
37 | $sub_type = $_POST["sub_type"];
38 | } else if (isset($_GET["sub_type"])) {
39 | $sub_type = $_GET["sub_type"];
40 | } else {
41 | $sub_type = 0;
42 | }
43 |
44 | if (isset($_POST["condition"])) {
45 | $condition = $_POST["condition"];
46 | } else if (isset($_GET["condition"])) {
47 | $condition = $_GET["condition"];
48 | } else {
49 | $condition = 0;
50 | }
51 |
52 | $rulecollection = RuleCollection::getClassByType($sub_type);
53 | if ($rulecollection->isRuleRecursive()) {
54 | $rulecollection->setEntity($_SESSION['glpiactive_entity']);
55 | }
56 | $rulecollection->checkGlobal(READ);
57 |
58 | Html::popHeader(__('Setup'), $_SERVER['PHP_SELF']);
59 |
60 | // Need for RuleEngines
61 | foreach ($_POST as $key => $val) {
62 | $_POST[$key] = stripslashes($_POST[$key]);
63 | }
64 | $input = $rulecollection->showRulesEnginePreviewCriteriasForm($_SERVER['PHP_SELF'], $_POST, $condition);
65 |
66 | if (isset($_POST["test_all_rules"])) {
67 | //Unset values that must not be processed by the rule
68 | unset($_POST["sub_type"]);
69 | unset($_POST["test_all_rules"]);
70 |
71 | echo "
";
72 | $rulecollection->showRulesEnginePreviewResultsForm($_SERVER['PHP_SELF'], $_POST, $condition);
73 | }
74 |
75 | Html::popFooter();
76 |
--------------------------------------------------------------------------------
/front/rule.test.php:
--------------------------------------------------------------------------------
1 | .
27 | --------------------------------------------------------------------------
28 | */
29 |
30 | if (!defined('GLPI_ROOT')) {
31 | include('../../../inc/includes.php');
32 | }
33 |
34 | Session::checkCentralAccess();
35 |
36 | if (isset($_POST["sub_type"])) {
37 | $sub_type = $_POST["sub_type"];
38 | } else if (isset($_GET["sub_type"])) {
39 | $sub_type = $_GET["sub_type"];
40 | } else {
41 | $sub_type = 0;
42 | }
43 |
44 | if (isset($_POST["rules_id"])) {
45 | $rules_id = $_POST["rules_id"];
46 | } else if (isset($_GET["rules_id"])) {
47 | $rules_id = $_GET["rules_id"];
48 | } else {
49 | $rules_id = 0;
50 | }
51 |
52 | $dbu = new DbUtils();
53 |
54 | if (!$rule = $dbu->getItemForItemtype($sub_type)) {
55 | exit;
56 | }
57 | $rule->checkGlobal(READ);
58 |
59 | $test_rule_output = null;
60 |
61 | Html::popHeader(__('Setup'), $_SERVER['PHP_SELF']);
62 |
63 | $rule->showRulePreviewCriteriasForm($_SERVER['PHP_SELF'], $rules_id);
64 |
65 | if (isset($_POST["test_rule"])) {
66 | $params = [];
67 | //Unset values that must not be processed by the rule
68 | unset($_POST["test_rule"]);
69 | unset($_POST["rules_id"]);
70 | unset($_POST["sub_type"]);
71 | $rule->getRuleWithCriteriasAndActions($rules_id, 1, 1);
72 |
73 | // Need for RuleEngines
74 | foreach ($_POST as $key => $val) {
75 | $_POST[$key] = stripslashes($_POST[$key]);
76 | }
77 | //Add rules specific POST fields to the param array
78 | $params = $rule->addSpecificParamsForPreview($params);
79 |
80 | $input = $rule->prepareAllInputDataForProcess($_POST, $params);
81 | //$rule->regex_results = [];
82 | echo "
";
83 | $rule->showRulePreviewResultsForm($_SERVER['PHP_SELF'], $input, $params);
84 | }
85 |
86 | Html::popFooter();
87 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 |
2 | on:
3 | push:
4 | # Sequence of patterns matched against refs/tags
5 | tags:
6 | - '*.*.*' # Push events to matching ex:20.15.10
7 |
8 | name: Create release with tag
9 | env:
10 | TAG_VALUE: ${GITHUB_REF/refs\/tags\//}
11 | jobs:
12 | build:
13 | name: Upload Release Asset
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout code
17 | uses: actions/checkout@v2
18 | - name: Build project # This would actually build your project, using zip for an example artifact
19 | id: build_
20 | env:
21 | GITHUB_NAME: ${{ github.event.repository.name }}
22 |
23 |
24 | run: sudo apt-get install libxml-xpath-perl;echo $(xpath -e '/root/versions/version[num="'${GITHUB_REF/refs\/tags\//}'"]/compatibility/text()' $GITHUB_NAME.xml);echo ::set-output name=version_glpi::$(xpath -e '/root/versions/version[num="'${GITHUB_REF/refs\/tags\//}'"]/compatibility/text()' $GITHUB_NAME.xml); rm -rf $GITHUB_NAME.xml tools wiki screenshots test .git .github ISSUE_TEMPLATE.md TODO.txt $GITHUB_NAME.png;cd ..; tar jcvf glpi-$GITHUB_NAME-${GITHUB_REF/refs\/tags\//}.tar.bz2 $GITHUB_NAME;ls -al;echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//};echo ${{ steps.getxml.outputs.info }};
25 | # run: rm -rf $GITHUB_NAME.xml tools wiki screenshots test ISSUE_TEMPLATE.md TODO.txt $GITHUB_NAME.png; tar -zcvf glpi-$GITHUB_NAME-$GITHUB_TAG.tar.gz $GITHUB_NAME
26 | - name: Create Release
27 | id: create_release
28 | uses: actions/create-release@v1
29 | env:
30 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 | with:
32 | tag_name: ${{ github.ref }}
33 | release_name: |
34 | GLPI ${{ steps.build_.outputs.version_glpi }} : Version ${{ github.ref }} disponible / available
35 | body : Version ${{ steps.build_.outputs.tag }} released for GLPI ${{ steps.build_.outputs.version_glpi }}
36 | draft: false
37 | prerelease: true
38 | - name: Upload Release Asset
39 | id: upload-release-asset
40 | uses: actions/upload-release-asset@v1
41 | env:
42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43 | GITHUB_NAME: ${{ github.event.repository.name }}
44 | with:
45 | upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
46 | asset_path: /home/runner/work/${{ github.event.repository.name }}/glpi-${{ github.event.repository.name }}-${{ steps.build_.outputs.tag }}.tar.bz2
47 | asset_name: glpi-${{ github.event.repository.name }}-${{ steps.build_.outputs.tag }}.tar.bz2
48 | asset_content_type: application/zip
49 |
50 |
--------------------------------------------------------------------------------
/setup.php:
--------------------------------------------------------------------------------
1 | .
27 | --------------------------------------------------------------------------
28 | */
29 |
30 | define('PLUGIN_VIP_VERSION', '1.8.1');
31 |
32 | if (!defined("PLUGIN_VIP_DIR")) {
33 | define("PLUGIN_VIP_DIR", Plugin::getPhpDir("vip"));
34 | define("PLUGIN_VIP_NOTFULL_DIR", Plugin::getPhpDir("vip",false));
35 | define("PLUGIN_VIP_WEBDIR", Plugin::getWebDir("vip"));
36 | }
37 |
38 | // Init the hooks of the plugins -Needed
39 | function plugin_init_vip() {
40 |
41 | global $PLUGIN_HOOKS;
42 |
43 | $PLUGIN_HOOKS['csrf_compliant']['vip'] = true;
44 |
45 | Plugin::registerClass('PluginVipProfile', ['addtabon' => ['Profile']]);
46 | $PLUGIN_HOOKS['change_profile']['vip'] = ['PluginVipProfile', 'changeProfile'];
47 |
48 | if (Session::haveRight('plugin_vip', UPDATE)) {
49 | Plugin::registerClass('PluginVipGroup', ['addtabon' => ['Group']]);
50 | $PLUGIN_HOOKS['use_massive_action']['vip'] = 1;
51 | Plugin::registerClass('PluginVipTicket');
52 | }
53 |
54 | if (class_exists('PluginMydashboardMenu')) {
55 | $PLUGIN_HOOKS['mydashboard']['vip'] = ["PluginVipDashboard"];
56 | }
57 |
58 | if (Session::haveRight('plugin_vip', READ)
59 | && isset($_SESSION["glpiactiveprofile"]["interface"])
60 | && $_SESSION["glpiactiveprofile"]["interface"] != "helpdesk") {
61 |
62 | $PLUGIN_HOOKS['add_javascript']['vip'][] = 'vip.js.php';
63 | $PLUGIN_HOOKS["javascript"]['vip'] = [PLUGIN_VIP_NOTFULL_DIR."/vip.js.php"];
64 |
65 | if (class_exists('PluginVipTicket')) {
66 | foreach (PluginVipTicket::$types as $item) {
67 | if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], strtolower($item) . ".form.php") !== false) {
68 | $PLUGIN_HOOKS['add_javascript']['vip'][] = 'vip_load_scripts.js.php';
69 | $PLUGIN_HOOKS['javascript']['vip'] = [
70 | PLUGIN_VIP_NOTFULL_DIR. "/vip_load_scripts.js.php",
71 | ];
72 | }
73 | }
74 | }
75 | }
76 | if (isset($_SESSION["glpiactiveprofile"]["interface"])
77 | && $_SESSION["glpiactiveprofile"]["interface"] != "helpdesk") {
78 | $PLUGIN_HOOKS['pre_show_item']['vip'] = ['PluginVipTicket', 'showVIPInfos'];
79 | }
80 | $PLUGIN_HOOKS['item_add']['vip'] = ['User' => ['PluginVipVip', 'afterAdd']];
81 | $PLUGIN_HOOKS['item_update']['vip'] = ['User' => ['PluginVipVip', 'afterUpdate']];
82 |
83 | Plugin::registerClass('PluginVipRuleVipCollection', [
84 | 'rulecollections_types' => true
85 | ]);
86 | }
87 |
88 | function plugin_version_vip() {
89 |
90 | return ['name' => "VIP",
91 | 'version' => PLUGIN_VIP_VERSION,
92 | 'author' => 'Probesys & Infotel',
93 | 'license' => 'GPLv2+',
94 | 'homepage' => 'https://github.com/InfotelGLPI/vip',
95 | 'requirements' => [
96 | 'glpi' => [
97 | 'min' => '10.0',
98 | 'max' => '11.0',
99 | 'dev' => false
100 | ]
101 | ]
102 | ];
103 | }
104 |
--------------------------------------------------------------------------------
/ajax/ticket.php:
--------------------------------------------------------------------------------
1 | .
27 | --------------------------------------------------------------------------
28 | */
29 |
30 | define('GLPI_ROOT', '../../..');
31 |
32 | include(GLPI_ROOT . "/inc/includes.php");
33 |
34 | Session::checkLoginUser();
35 | //Html::header_nocache();
36 |
37 | switch ($_POST['action']) {
38 | case 'getTicket':
39 | header('Content-Type: application/json; charset=UTF-8"');
40 |
41 | $params = ['entities_id' => (is_array($_SESSION['glpiactiveentities']) ? json_encode(array_values($_SESSION['glpiactiveentities'])) : $_SESSION['glpiactiveentities']),
42 | 'used' => []];
43 |
44 | if (isset($_POST['items_id'])) {
45 | $ticket = new Ticket();
46 | $actor = new Ticket_User();
47 | if($ticket->getFromDB($_POST['items_id'])) {
48 | $actors = $actor->getActors($_POST['items_id']);
49 |
50 | $used = [];
51 | if (isset($actors[CommonITILActor::REQUESTER])) {
52 | foreach ($actors[CommonITILActor::REQUESTER] as $requesters) {
53 | $used[] = $requesters['users_id'];
54 | }
55 | }
56 |
57 | $params = ['used' => $used,
58 | 'entities_id' => $ticket->fields['entities_id']];
59 | }
60 | }
61 |
62 | echo json_encode($params);
63 | break;
64 | case 'getVIP':
65 | header('Content-Type: application/json; charset=UTF-8"');
66 |
67 | $params = ['entities_id' => (is_array($_SESSION['glpiactiveentities']) ? json_encode(array_values($_SESSION['glpiactiveentities'])) : $_SESSION['glpiactiveentities']),
68 | 'used' => []];
69 |
70 | $used = PluginVipTicket::getUserVipList($params['entities_id']);
71 |
72 | if (count($used) > 0) {
73 | $params = ['used' => $used];
74 | }
75 |
76 | echo json_encode($params);
77 | break;
78 | case 'getPrinter':
79 | header('Content-Type: application/json; charset=UTF-8"');
80 |
81 | $params = ['entities_id' => (is_array($_SESSION['glpiactiveentities']) ? json_encode(array_values($_SESSION['glpiactiveentities'])) : $_SESSION['glpiactiveentities']),
82 | 'used' => []];
83 |
84 | if (isset($_POST['items_id'])) {
85 | $printer = new Printer();
86 | $printer->getFromDB($_POST['items_id']);
87 |
88 | $used = [];
89 | $used[] = $printer->fields['users_id'];
90 |
91 |
92 | $params = ['used' => $used,
93 | 'entities_id' => $printer->fields['entities_id']];
94 | }
95 |
96 | echo json_encode($params);
97 | break;
98 | case 'getComputer':
99 | header('Content-Type: application/json; charset=UTF-8"');
100 |
101 | $params = ['entities_id' => (is_array($_SESSION['glpiactiveentities']) ? json_encode(array_values($_SESSION['glpiactiveentities'])) : $_SESSION['glpiactiveentities']),
102 | 'used' => []];
103 |
104 | if (isset($_POST['items_id'])) {
105 | $computer = new Computer();
106 | $computer->getFromDB($_POST['items_id']);
107 |
108 | $used = [];
109 | $used[] = $computer->fields['users_id'];
110 |
111 |
112 | $params = ['used' => $used,
113 | 'entities_id' => $computer->fields['entities_id']];
114 | }
115 | echo json_encode($params);
116 | break;
117 | }
118 |
--------------------------------------------------------------------------------
/vip.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | VIP Infotel
4 | vip
5 | stable
6 | https://raw.githubusercontent.com/InfotelGLPI/vip/master/pics/vip.png
7 |
8 |
9 |
10 |
11 |
12 |
13 | * Paramétrage dans l'interface du groupe :
- Création d'un groupe, indication dans l'onget "VIP" du paramètre si oui ou non "Groupe VIP"
* Indication dans l'interface du ticket par un logo "VIP" et colorisation du nom de l'utilisateur en rouge si le demandeur du ticket fait partie d'un groupe VIP]]>
14 | * Parameter setting in the group interface:
- Creation of a group, indication in the "VIP" window of the parameter if yes or no "VIP Group".
* Indication in the ticket interface by a "VIP" logo and colouring of the user's name in red if the ticket requester belongs to a VIP group]]>
15 |
16 |
17 | https://github.com/InfotelGLPI/vip
18 | https://github.com/InfotelGLPI/vip/releases
19 | https://github.com/InfotelGLPI/vip/issues
20 | https://raw.githubusercontent.com/InfotelGLPI/vip/master/README.md
21 |
22 | Infotel
23 |
24 |
25 |
26 | 1.8.1
27 | ~10.0
28 | https://github.com/InfotelGLPI/vip/releases/download/1.8.1/glpi-vip-1.8.1.tar.bz2
29 |
30 |
31 | 1.8.0
32 | ~10.0
33 | https://github.com/InfotelGLPI/vip/releases/download/1.8.0/glpi-vip-1.8.0.tar.bz2
34 |
35 |
36 | 1.8.0-rc2
37 | ~10.0
38 | https://github.com/InfotelGLPI/vip/releases/download/1.8.0-rc2/glpi-vip-1.8.0-rc2.tar.bz2
39 |
40 |
41 | 1.8.0-rc1
42 | ~10.0
43 | https://github.com/InfotelGLPI/vip/releases/download/1.8.0-rc1/glpi-vip-1.8.0-rc1.tar.bz2
44 |
45 |
46 | 1.7.2
47 | ~9.5.0
48 | https://github.com/InfotelGLPI/vip/releases/download/1.7.2/glpi-vip-1.7.2.tar.gz
49 |
50 |
51 | 1.7.1
52 | ~9.5.0
53 |
54 |
55 | 1.7.0
56 | ~9.5.0
57 |
58 |
59 | 1.6.0
60 | 9.4
61 |
62 |
63 | 1.5.2
64 | 9.3
65 |
66 |
67 | 1.5.1
68 | 9.3
69 |
70 |
71 | 1.5.0
72 | 9.3
73 |
74 |
75 | 1.4.0
76 | 9.2
77 |
78 |
79 |
80 | en_GB
81 | fr_FR
82 |
83 |
84 |
85 |
86 | Groupes
87 | Ticket
88 | Helpdesk
89 |
90 |
91 | Groups
92 | Ticket
93 | Assistance
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/inc/rulevip.class.php:
--------------------------------------------------------------------------------
1 | .
27 | --------------------------------------------------------------------------
28 | */
29 |
30 | if (!defined('GLPI_ROOT')) {
31 | die("Sorry. You can't access directly to this file");
32 | }
33 |
34 | /**
35 | * Rule class store all informations about a GLPI rule :
36 | * - description
37 | * - criterias
38 | * - actions
39 | *
40 | * */
41 | class PluginVipRuleVip extends Rule {
42 |
43 | // From Rule
44 | public static $rightname = 'plugin_vip';
45 | public $can_sort = true;
46 |
47 | /**
48 | * @return translated
49 | */
50 | function getTitle() {
51 |
52 | return PluginVipVip::getTypeName(1);
53 | }
54 |
55 | /**
56 | * @return int
57 | */
58 | function maxActionsCount() {
59 | return count($this->getActions());
60 | }
61 |
62 | /**
63 | * @param parameters $params
64 | *
65 | * @return parameters
66 | */
67 | function addSpecificParamsForPreview($params) {
68 |
69 | if (!isset($params["entities_id"])) {
70 | $params["entities_id"] = $_SESSION["glpiactive_entity"];
71 | }
72 | return $params;
73 | }
74 |
75 | /**
76 | * Function used to display type specific criterias during rule's preview
77 | *
78 | * @param $fields fields values
79 | * */
80 | function showSpecificCriteriasForPreview($fields) {
81 |
82 | $entity_as_criteria = false;
83 | foreach ($this->criterias as $criteria) {
84 | if ($criteria->fields['criteria'] == 'entities_id') {
85 | $entity_as_criteria = true;
86 | break;
87 | }
88 | }
89 | if (!$entity_as_criteria) {
90 | echo Html::hidden('entities_id', ['value' => $_SESSION["glpiactive_entity"]]);
91 | }
92 | }
93 |
94 | /**
95 | * @return array
96 | */
97 | function getCriterias() {
98 |
99 | $dbu = new DbUtils();
100 | $criterias = [];
101 | $criterias['ldap'] = __('LDAP criteria');
102 | foreach ($dbu->getAllDataFromTable('glpi_rulerightparameters', [], true) as $datas) {
103 | $criterias[$datas["value"]]['name'] = $datas["name"];
104 | $criterias[$datas["value"]]['field'] = $datas["value"];
105 | $criterias[$datas["value"]]['linkfield'] = '';
106 | $criterias[$datas["value"]]['table'] = '';
107 | }
108 |
109 | return $criterias;
110 | }
111 |
112 |
113 | /**
114 | * @return array
115 | */
116 | function getActions() {
117 | $actions = [];
118 |
119 | $actions['groups_id']['name'] = __('Group');
120 | $actions['groups_id']['type'] = 'dropdown';
121 | $actions['groups_id']['table'] = 'glpi_groups';
122 |
123 | return $actions;
124 | }
125 |
126 | /**
127 | * @see Rule::executeActions()
128 | *
129 | * @param the $output
130 | * @param parameters $params
131 | *
132 | * @return the
133 | */
134 | function executeActions($output, $params, array $input = []) {
135 | if (count($this->actions)) {
136 | foreach ($this->actions as $action) {
137 | switch ($action->fields["action_type"]) {
138 | default :
139 | $output[$action->fields["field"]] = $action->fields["value"];
140 | break;
141 | case "assign" :
142 | switch ($action->fields["field"]) {
143 | case "groups_id" :
144 | $output["groups_id"] = $action->fields["value"];
145 | break;
146 | }
147 | }// end switch (field)
148 | }
149 | }
150 | return $output;
151 | }
152 |
153 | }
154 |
--------------------------------------------------------------------------------
/ajax/getDropdownUsers.php:
--------------------------------------------------------------------------------
1 | .
30 | * ---------------------------------------------------------------------
31 | */
32 |
33 | /** @file
34 | * @brief
35 | * @since version 0.85
36 | */
37 |
38 | // Direct access to file
39 | if (strpos($_SERVER['PHP_SELF'], "getDropdownUsers.php")) {
40 | $AJAX_INCLUDE = 1;
41 | include ('../../../inc/includes.php');
42 | header("Content-Type: text/html; charset=UTF-8");
43 | Html::header_nocache();
44 | } else if (!defined('GLPI_ROOT')) {
45 | die("Sorry. You can't access this file directly");
46 | }
47 | Session::checkLoginUser();
48 |
49 | if (!isset($_POST['right'])) {
50 | $_POST['right'] = "all";
51 | }
52 |
53 | // Default view : Nobody
54 | if (!isset($_POST['all'])) {
55 | $_POST['all'] = 0;
56 | }
57 |
58 | $used = [];
59 |
60 | if (isset($_POST['used'])) {
61 | $used = $_POST['used'];
62 | }
63 |
64 | if (!isset($_POST['value'])) {
65 | $_POST['value'] = 0;
66 | }
67 |
68 | $one_item = -1;
69 | if (isset($_POST['_one_id'])) {
70 | $one_item = $_POST['_one_id'];
71 | }
72 |
73 | if (!isset($_POST['page'])) {
74 | $_POST['page'] = 1;
75 | $_POST['page_limit'] = $CFG_GLPI['dropdown_max'];
76 | }
77 |
78 | $entity_restrict = -1;
79 | if (isset($_POST['entity_restrict'])) {
80 | $entity_restrict = Toolbox::jsonDecode($_POST['entity_restrict']);
81 | }
82 |
83 | $iterator = [];
84 | if ($one_item < 0) {
85 | $start = intval(($_POST['page']-1)*$_POST['page_limit']);
86 | $searchText = (isset($_POST['searchText']) ? $_POST['searchText'] : null);
87 | $iterator = User::getSqlSearchResult(false, $_POST['right'], $entity_restrict,
88 | $_POST['value'], $used, $searchText, $start,
89 | intval($_POST['page_limit']));
90 | } else {
91 | $iterator = $DB->request([
92 | 'FROM' => 'glpi_users',
93 | 'WHERE' => [
94 | 'id' => $one_item,
95 | ],
96 | ]);
97 | //$query = "SELECT DISTINCT `glpi_users`.*
98 | // FROM `glpi_users`
99 | // WHERE `glpi_users`.`id` = '$one_item';";
100 | //$result = $DB->query($query);
101 | }
102 | $users = [];
103 |
104 | // Count real items returned
105 | $count = 0;
106 | if (count($iterator)) {
107 | foreach ($iterator as $data) {
108 | $users[$data["id"]] = formatUserName($data["id"], $data["name"], $data["realname"],
109 | $data["firstname"]);
110 | $logins[$data["id"]] = $data["name"];
111 | }
112 | }
113 |
114 | /*
115 | if (!function_exists('dpuser_cmp')) {
116 | function dpuser_cmp($a, $b) {
117 | return strcasecmp($a, $b);
118 | }
119 | }
120 |
121 | // Sort non case sensitive
122 | uasort($users, 'dpuser_cmp');
123 | */
124 |
125 | $datas = [];
126 |
127 | // Display first if empty search
128 | if ($_POST['page'] == 1 && empty($_POST['searchText'])) {
129 | if (($one_item < 0) || ($one_item == 0)) {
130 | if ($_POST['all'] == 0) {
131 | array_push($datas, ['id' => 0,
132 | 'text' => Dropdown::EMPTY_VALUE]);
133 | } else if ($_POST['all'] == 1) {
134 | array_push($datas, ['id' => 0,
135 | 'text' => __('All')]);
136 | }
137 | }
138 | }
139 |
140 | if (count($users)) {
141 | foreach ($users as $ID => $output) {
142 | $title = sprintf(__('%1$s - %2$s'), $output, $logins[$ID]);
143 |
144 | array_push($datas, ['id' => $ID,
145 | 'text' => $output,
146 | 'title' => $title]);
147 | $count++;
148 | }
149 | }
150 |
151 | if (($one_item >= 0)
152 | && isset($datas[0])) {
153 | echo json_encode($datas[0]);
154 | } else {
155 | $ret['results'] = $datas;
156 | $ret['count'] = $count;
157 | echo json_encode($ret);
158 | }
159 |
--------------------------------------------------------------------------------
/inc/vip.class.php:
--------------------------------------------------------------------------------
1 | .
27 | --------------------------------------------------------------------------
28 | */
29 |
30 | if (!defined('GLPI_ROOT')) {
31 | die("Sorry. You can't access directly to this file");
32 | }
33 |
34 | /**
35 | * Class PluginVipVip
36 | */
37 | class PluginVipVip extends CommonDBTM {
38 | public static $rightname = 'plugin_vip';
39 |
40 | /**
41 | * @param int $nb
42 | *
43 | * @return translated
44 | */
45 | static function getTypeName($nb = 0) {
46 | return __('VIP', 'vip');
47 |
48 | }
49 |
50 | static function afterAdd(User $user) {
51 | $rulevip = new PluginVipRuleVip();
52 | $criterias = $rulevip->getCriterias();
53 |
54 | if (isset($user->fields["authtype"])
55 | && (($user->fields["authtype"] == Auth::LDAP)
56 | || Auth::isAlternateAuth($user->fields['authtype']))) {
57 |
58 | $config_ldap = new AuthLDAP();
59 | $ds = false;
60 |
61 | if ($config_ldap->getFromDB($user->fields['auths_id'])) {
62 | $ds = $config_ldap->connect();
63 | }
64 |
65 | if ($ds) {
66 | $info = AuthLdap::getUserByDn($ds, $user->fields['user_dn'], []);
67 |
68 | }
69 |
70 | $input = [];
71 | foreach ($criterias as $criteria) {
72 | if (isset($criteria['field']) && isset($info[$criteria['field']]) && isset($info[$criteria['field']][0])) {
73 | $input[$criteria['field']] = $info[$criteria['field']][0];
74 | }
75 | if (isset($info["dn"])) {
76 | $input["dn"] = $info["dn"];
77 | }
78 | }
79 |
80 | $ruleCollection = new PluginVipRuleVipCollection($user->fields['entities_id']);
81 | $fields = [];
82 |
83 | $fields = $ruleCollection->processAllRules($input, $fields, []);
84 |
85 | //Store rule that matched
86 | if (isset($fields['groups_id'])) {
87 | $groupuser = new Group_User();
88 |
89 | if (!$groupuser->find(["`users_id` = " . $user->getID() . " AND `groups_id` =" . $fields['groups_id']])) {
90 | $groupuser->add(['users_id' => $user->getID(),
91 | 'groups_id' => $fields['groups_id']]);
92 | }
93 | }
94 | }
95 | }
96 |
97 | static function afterUpdate(User $user) {
98 | $rulevip = new PluginVipRuleVip();
99 | $criterias = $rulevip->getCriterias();
100 |
101 | if (isset($user->fields["authtype"])
102 | && (($user->fields["authtype"] == Auth::LDAP)
103 | || Auth::isAlternateAuth($user->fields['authtype']))) {
104 |
105 | $config_ldap = new AuthLDAP();
106 | $ds = false;
107 |
108 | if ($config_ldap->getFromDB($user->fields['auths_id'])) {
109 | $ds = $config_ldap->connect();
110 | }
111 |
112 | if ($ds) {
113 | $info = AuthLdap::getUserByDn($ds, $user->fields['user_dn'], []);
114 |
115 | }
116 |
117 | $input = [];
118 | foreach ($criterias as $criteria) {
119 | if (isset($criteria['field']) && isset($info[$criteria['field']]) && isset($info[$criteria['field']][0])) {
120 | $input[$criteria['field']] = $info[$criteria['field']][0];
121 | }
122 | if (isset($info["dn"])) {
123 | $input["dn"] = $info["dn"];
124 | }
125 | }
126 |
127 | $ruleCollection = new PluginVipRuleVipCollection($user->fields['entities_id']);
128 | $fields = [];
129 |
130 | $fields = $ruleCollection->processAllRules($input, $fields, []);
131 |
132 | //Store rule that matched
133 | if (isset($fields['groups_id'])) {
134 | $groupuser = new Group_User();
135 |
136 | if (!$groupuser->find(["`users_id` = " . $user->getID() . " AND `groups_id` =" . $fields['groups_id']])) {
137 | $groupuser->add(['users_id' => $user->getID(),
138 | 'groups_id' => $fields['groups_id']]);
139 | }
140 | }
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/inc/ticket.class.php:
--------------------------------------------------------------------------------
1 | .
27 | --------------------------------------------------------------------------
28 | */
29 |
30 | if (!defined('GLPI_ROOT')) {
31 | die("Sorry. You can't access directly to this file");
32 | }
33 |
34 | class PluginVipTicket extends CommonDBTM {
35 |
36 | static $types = ['Ticket', 'Printer', 'Computer'];
37 |
38 | /**
39 | * @param $uid
40 | *
41 | * @return bool
42 | */
43 | static function isUserVip($uid) {
44 | global $DB;
45 |
46 | if ($uid) {
47 | $vipquery = "SELECT `glpi_plugin_vip_groups`.`id`
48 | FROM `glpi_groups_users`
49 | LEFT JOIN `glpi_plugin_vip_groups`
50 | ON `glpi_plugin_vip_groups`.`id` = `glpi_groups_users`.`groups_id`
51 | WHERE `glpi_plugin_vip_groups`.`isvip` = 1
52 | AND `glpi_groups_users`.`users_id` = " . $uid;
53 |
54 | $result = $DB->query($vipquery);
55 | $nb = $DB->numrows($result);
56 | if ($nb > 0) {
57 | while ($uids = $DB->fetchArray($result)) {
58 | return $uids['id'];
59 | }
60 | }
61 | }
62 |
63 | return false;
64 | }
65 |
66 | /**
67 | * @param $entities
68 | *
69 | * @return array
70 | */
71 | static function getUserVipList($entities) {
72 | global $DB;
73 |
74 | $vip = [];
75 | $vipquery = "SELECT `glpi_groups_users`.`users_id`
76 | FROM `glpi_groups_users`
77 | LEFT JOIN `glpi_plugin_vip_groups`
78 | ON `glpi_plugin_vip_groups`.`id` = `glpi_groups_users`.`groups_id`
79 | WHERE `glpi_plugin_vip_groups`.`isvip` = 1";
80 |
81 | $result = $DB->query($vipquery);
82 | $nb = $DB->numrows($result);
83 | if ($nb > 0) {
84 | while ($uids = $DB->fetchArray($result)) {
85 | $vip[] = $uids['users_id'];
86 | }
87 | }
88 | return $vip;
89 | }
90 |
91 | /**
92 | * @param $ticketid
93 | *
94 | * @return bool
95 | */
96 | static function isTicketVip($ticketid) {
97 | global $DB;
98 |
99 | if ($ticketid > 0) {
100 | $userquery = "SELECT `users_id`
101 | FROM `glpi_tickets_users`
102 | WHERE `type` = " . CommonITILActor::REQUESTER . "
103 | AND `tickets_id` = " . $ticketid;
104 | $userresult = $DB->query($userquery);
105 | $nb = $DB->numrows($userresult);
106 | if ($nb > 0) {
107 | while ($uids = $DB->fetchArray($userresult)) {
108 | $isuservip = self::isUserVip($uids['users_id']);
109 | if ($isuservip > 0) {
110 | return $isuservip;
111 | }
112 |
113 | }
114 | }
115 | }
116 | return false;
117 | }
118 |
119 | /**
120 | * @param $printers_id
121 | *
122 | * @return bool
123 | */
124 | static function isPrinterVip($printers_id) {
125 |
126 | $printer = new Printer();
127 | $printer->getFromDB($printers_id);
128 | return self::isUserVip($printer->getField('users_id'));
129 | }
130 |
131 | /**
132 | * @param $computers_id
133 | *
134 | * @return bool
135 | */
136 | static function isComputerVip($computers_id) {
137 |
138 | $computer = new Computer();
139 | $computer->getFromDB($computers_id);
140 | return self::isUserVip($computer->getField('users_id'));
141 | }
142 |
143 | /**
144 | * @param $params
145 | *
146 | * @return void
147 | */
148 | public static function showVIPInfos($params) {
149 | $item = $params['item'];
150 |
151 | if (in_array($item->getType(), self::$types)) {
152 | if ($item->getType() == 'Ticket') {
153 | if ($id = self::isTicketVip($item->getID())) {
154 | $name = PluginVipGroup::getVipName($id);
155 | $icon = PluginVipGroup::getVipIcon($id);
156 | echo "
";
157 | echo " ";
158 | echo sprintf(__('%1$s %2$s'), __('This ticket concerns at least one', 'vip'), $name);
159 | echo "
";
160 | }
161 | } else {
162 | if ($id = self::isUserVip($item->getField('users_id'))) {
163 | echo "";
164 | if ($item->getType() == 'Computer') {
165 | $name = PluginVipGroup::getVipName($id);
166 | $icon = PluginVipGroup::getVipIcon($id);
167 | echo " ";
168 | echo sprintf(__('%1$s %2$s'), __('This computer is used by a', 'vip'), $name);
169 | } else if ($item->getType() == 'Printer') {
170 | $name = PluginVipGroup::getVipName($id);
171 | $icon = PluginVipGroup::getVipIcon($id);
172 | echo " ";
173 | echo sprintf(__('%1$s %2$s'), __('This printer is used by a', 'vip'), $name);
174 | }
175 | echo "
";
176 | }
177 | }
178 | }
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/inc/dashboard.class.php:
--------------------------------------------------------------------------------
1 | .
27 | --------------------------------------------------------------------------
28 | */
29 |
30 | class PluginVipDashboard extends CommonGLPI {
31 |
32 | public $widgets = [];
33 | private $options;
34 | private $datas, $form;
35 |
36 | public function __construct($_options = []) {
37 | $this->options = $_options;
38 | }
39 |
40 | function getWidgetsForItem() {
41 |
42 | $widgets = [
43 | __('Tables', "mydashboard") => [
44 | $this->getType() . "1" => ["title" => __("Tickets VIP", "mydashboard"),
45 | "icon" => "ti ti-table",
46 | "comment" => ""],
47 | ],
48 | ];
49 | return $widgets;
50 |
51 | }
52 |
53 | public function getWidgetContentForItem($widgetId) {
54 | global $DB;
55 |
56 | $dbu = new DbUtils();
57 | switch ($widgetId) {
58 |
59 | case $this->getType() . "1":
60 |
61 | $widget = new PluginMydashboardHtml();
62 |
63 | $link_ticket = Toolbox::getItemTypeFormURL("Ticket");
64 |
65 | $mygroups = Group_User::getUserGroups(Session::getLoginUserID(), ["is_assign" => 1]);
66 | $groups = [];
67 | foreach ($mygroups as $mygroup) {
68 | $groups[] = $mygroup["id"];
69 | }
70 |
71 | $query = "SELECT `glpi_tickets`.`id` AS tickets_id,
72 | `glpi_tickets`.`status` AS status,
73 | `glpi_tickets`.`time_to_resolve` AS time_to_resolve
74 | FROM `glpi_tickets`
75 | LEFT JOIN `glpi_entities` ON (`glpi_tickets`.`entities_id` = `glpi_entities`.`id`)
76 | LEFT JOIN `glpi_groups_tickets` ON (`glpi_tickets`.`id` = `glpi_groups_tickets`.`tickets_id`
77 | AND `glpi_groups_tickets`.`type` = " . CommonITILActor::ASSIGN . ")
78 | WHERE `glpi_tickets`.`is_deleted` = '0'
79 | AND `glpi_tickets`.`status` NOT IN (" . CommonITILObject::INCOMING . "," . CommonITILObject::SOLVED . "," . CommonITILObject::CLOSED . ") ";
80 | if (count($groups) > 0) {
81 | $query .= "AND `glpi_groups_tickets`.`groups_id` IN (" . implode(",", $groups) . ")";
82 | }
83 | $query .= "ORDER BY `glpi_tickets`.`time_to_resolve` DESC";//
84 |
85 | $widget = PluginMydashboardHelper::getWidgetsFromDBQuery('table', $query);
86 | $headers = [__('ID'),
87 | _n('Requester', 'Requesters', 2),
88 | __('Status'),
89 | __('Time to resolve'),
90 | __('Assigned to technicians')];
91 | $widget->setTabNames($headers);
92 |
93 | $result = $DB->query($query);
94 | $nb = $DB->numrows($result);
95 |
96 | $datas = [];
97 | $tickets = [];
98 |
99 | if ($nb) {
100 | while ($data = $DB->fetchAssoc($result)) {
101 |
102 | $ticket = new Ticket();
103 | $ticket->getFromDB($data['tickets_id']);
104 | if ($ticket->countUsers(CommonITILActor::REQUESTER)) {
105 | $users = [];
106 | foreach ($ticket->getUsers(CommonITILActor::REQUESTER) as $u) {
107 | $users[] = $u['users_id'];
108 | }
109 | foreach ($users as $key => $val) {
110 | if (PluginVipTicket::isUserVip($val) !== false) {
111 | $tickets[] = $data;
112 | }
113 | }
114 | }
115 | }
116 | $i = 0;
117 |
118 | foreach ($tickets as $key => $val) {
119 |
120 | $ticket = new Ticket();
121 | $ticket->getFromDB($val['tickets_id']);
122 |
123 | $bgcolor = $_SESSION["glpipriority_" . $ticket->fields["priority"]];
124 |
125 | $name_ticket = "";
130 |
131 |
132 | $datas[$i]["tickets_id"] = $name_ticket;
133 |
134 |
135 | $userdata = '';
136 | if ($ticket->countUsers(CommonITILActor::REQUESTER)) {
137 |
138 | foreach ($ticket->getUsers(CommonITILActor::REQUESTER) as $u) {
139 | $k = $u['users_id'];
140 | if ($k) {
141 | $userdata .= $dbu->getUserName($k);
142 | }
143 |
144 |
145 | if ($ticket->countUsers(CommonITILActor::REQUESTER) > 1) {
146 | $userdata .= "
";
147 | }
148 | }
149 | }
150 | $datas[$i]["users_id"] = $userdata;
151 |
152 | $datas[$i]["status"] = Ticket::getStatus($val['status']);
153 |
154 | $time_to_resolve = '';
155 | $due = strtotime(date('Y-m-d H:i:s')) - strtotime($val['time_to_resolve']);
156 | if ($due > 0) {
157 | $time_to_resolve .= "";
158 | }
159 | $time_to_resolve .= Html::convDateTime($val['time_to_resolve']);
160 | if ($due > 0) {
161 | $time_to_resolve .= "
";
162 | }
163 | $datas[$i]["time_to_resolve"] = $time_to_resolve;
164 |
165 | $techdata = '';
166 | if ($ticket->countUsers(CommonITILActor::ASSIGN)) {
167 |
168 | foreach ($ticket->getUsers(CommonITILActor::ASSIGN) as $u) {
169 | $k = $u['users_id'];
170 | if ($k) {
171 | $techdata .= $dbu->getUserName($k);
172 | }
173 |
174 |
175 | if ($ticket->countUsers(CommonITILActor::ASSIGN) > 1) {
176 | $techdata .= "
";
177 | }
178 | }
179 | }
180 | $datas[$i]["techs_id"] = $techdata;
181 | $i++;
182 | }
183 | }
184 |
185 | $widget->setTabDatas($datas);
186 | // $widget->setOption("bSort", false);
187 | $widget->toggleWidgetRefresh();
188 |
189 | $widget->setWidgetTitle(__("Tickets VIP", "mydashboard"));
190 |
191 | return $widget;
192 | break;
193 | }
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/inc/profile.class.php:
--------------------------------------------------------------------------------
1 | .
27 | --------------------------------------------------------------------------
28 | */
29 |
30 | if (!defined('GLPI_ROOT')) {
31 | die("Sorry. You can't access directly to this file");
32 | }
33 |
34 | /**
35 | * Class PluginVipProfile
36 | *
37 | * This class manages the profile rights of the plugin
38 | */
39 | class PluginVipProfile extends Profile {
40 |
41 | /**
42 | * Get tab name for item
43 | *
44 | * @param CommonGLPI $item
45 | * @param type $withtemplate
46 | *
47 | * @return string
48 | */
49 | function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
50 |
51 | if ($item->getType() == 'Profile'
52 | && $item->getField('interface') != 'helpdesk') {
53 | return __('VIP', 'vip');
54 | }
55 | return '';
56 | }
57 |
58 | /**
59 | * display tab content for item
60 | *
61 | * @global type $CFG_GLPI
62 | *
63 | * @param CommonGLPI $item
64 | * @param type $tabnum
65 | * @param type $withtemplate
66 | *
67 | * @return boolean
68 | */
69 | static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
70 | global $CFG_GLPI;
71 |
72 | if ($item->getType() == 'Profile') {
73 | $ID = $item->getID();
74 | $prof = new self();
75 |
76 | self::addDefaultProfileInfos($ID,
77 | ['plugin_vip' => 0]);
78 | $prof->showForm($ID);
79 | }
80 |
81 | return true;
82 | }
83 |
84 | /**
85 | * show profile form
86 | *
87 | * @param type $ID
88 | * @param type $options
89 | *
90 | * @return boolean
91 | */
92 | function showForm($profiles_id = 0, $openform = TRUE, $closeform = TRUE) {
93 |
94 | echo "";
95 | if (($canedit = Session::haveRightsOr(self::$rightname, [CREATE, UPDATE, PURGE]))
96 | && $openform) {
97 | $profile = new Profile();
98 | echo "
";
117 |
118 | $this->showLegend();
119 | }
120 |
121 | /**
122 | * Get all rights
123 | *
124 | * @param type $all
125 | *
126 | * @return array
127 | */
128 | static function getAllRights($all = false) {
129 |
130 | $rights = [
131 | ['itemtype' => 'PluginVipGroup',
132 | 'label' => __('VIP', 'vip'),
133 | 'field' => 'plugin_vip'
134 | ]
135 | ];
136 |
137 | return $rights;
138 | }
139 |
140 | /**
141 | * Init profiles
142 | *
143 | **/
144 |
145 | static function translateARight($old_right) {
146 | switch ($old_right) {
147 | case '':
148 | return 0;
149 | case 'r' :
150 | return READ;
151 | case 'w':
152 | return ALLSTANDARDRIGHT;
153 | case '0':
154 | case '1':
155 | return $old_right;
156 |
157 | default :
158 | return 0;
159 | }
160 | }
161 |
162 |
163 | /**
164 | * @since 0.85
165 | * Migration rights from old system to the new one for one profile
166 | *
167 | * @param $profiles_id the profile ID
168 | */
169 | static function migrateOneProfile($profiles_id) {
170 | global $DB;
171 | //Cannot launch migration if there's nothing to migrate...
172 | if (!$DB->tableExists('glpi_plugin_vip_profiles')) {
173 | return true;
174 | }
175 |
176 | foreach ($DB->request('glpi_plugin_vip_profiles',
177 | "`profiles_id`='$profiles_id'") as $profile_data) {
178 |
179 | $matching = ['show_vip_tab' => 'plugin_vip'];
180 | $current_rights = ProfileRight::getProfileRights($profiles_id, array_values($matching));
181 | foreach ($matching as $old => $new) {
182 | if (!isset($current_rights[$old])) {
183 | $right = self::translateARight($profile_data[$old]);
184 | switch ($new) {
185 | case 'plugin_vip' :
186 | $right = 0;
187 | if ($profile_data[$old] == '1') {
188 | $right = ALLSTANDARDRIGHT;
189 | }
190 | break;
191 | }
192 |
193 | $query = "UPDATE `glpi_profilerights`
194 | SET `rights`='" . $right . "'
195 | WHERE `name`='$new' AND `profiles_id`='$profiles_id'";
196 | $DB->query($query);
197 | }
198 | }
199 | }
200 | }
201 |
202 | /**
203 | * Initialize profiles, and migrate it necessary
204 | */
205 | static function initProfile() {
206 | global $DB;
207 | $profile = new self();
208 | $dbu = new DbUtils();
209 | //Add new rights in glpi_profilerights table
210 | foreach ($profile->getAllRights(true) as $data) {
211 | if ($dbu->countElementsInTable("glpi_profilerights",
212 | ["name" => $data['field']]) == 0) {
213 | ProfileRight::addProfileRights([$data['field']]);
214 | }
215 | }
216 |
217 | //Migration old rights in new ones
218 | foreach ($DB->request("SELECT `id` FROM `glpi_profiles`") as $prof) {
219 | self::migrateOneProfile($prof['id']);
220 | }
221 | foreach ($DB->request("SELECT *
222 | FROM `glpi_profilerights`
223 | WHERE `profiles_id`='" . $_SESSION['glpiactiveprofile']['id'] . "'
224 | AND `name` LIKE '%plugin_vip%'") as $prof) {
225 | $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights'];
226 | }
227 | }
228 |
229 | /**
230 | * Initialize profiles, and migrate it necessary
231 | */
232 | static function changeProfile() {
233 | global $DB;
234 |
235 | foreach ($DB->request("SELECT *
236 | FROM `glpi_profilerights`
237 | WHERE `profiles_id`='" . $_SESSION['glpiactiveprofile']['id'] . "'
238 | AND `name` LIKE '%plugin_vip%'") as $prof) {
239 | $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights'];
240 | }
241 |
242 | }
243 |
244 | static function createFirstAccess($profiles_id) {
245 |
246 | $rights = ['plugin_vip' => ALLSTANDARDRIGHT];
247 |
248 | self::addDefaultProfileInfos($profiles_id,
249 | $rights, true);
250 |
251 | }
252 |
253 | /**
254 | * @param $profile
255 | **/
256 | static function addDefaultProfileInfos($profiles_id, $rights, $drop_existing = false) {
257 |
258 | $profileRight = new ProfileRight();
259 | $dbu = new DbUtils();
260 | foreach ($rights as $right => $value) {
261 | if ($dbu->countElementsInTable('glpi_profilerights',
262 | ["profiles_id" => $profiles_id,
263 | "name" => $right]) && $drop_existing) {
264 | $profileRight->deleteByCriteria(['profiles_id' => $profiles_id, 'name' => $right]);
265 | }
266 | if (!$dbu->countElementsInTable('glpi_profilerights',
267 | ["profiles_id" => $profiles_id,
268 | "name" => $right])) {
269 | $myright['profiles_id'] = $profiles_id;
270 | $myright['name'] = $right;
271 | $myright['rights'] = $value;
272 | $profileRight->add($myright);
273 |
274 | //Add right to the current session
275 | $_SESSION['glpiactiveprofile'][$right] = $value;
276 | }
277 | }
278 | }
279 |
280 | static function removeRightsFromSession() {
281 | foreach (self::getAllRights(true) as $right) {
282 | if (isset($_SESSION['glpiactiveprofile'][$right['field']])) {
283 | unset($_SESSION['glpiactiveprofile'][$right['field']]);
284 | }
285 | }
286 | }
287 |
288 | }
289 |
--------------------------------------------------------------------------------
/vip.js.php:
--------------------------------------------------------------------------------
1 |
7 |
8 | var root_vip_doc = "";
9 |
10 | (function ($) {
11 | $.fn.initVipPlugin = function (options) {
12 |
13 | var object = this;
14 | init();
15 |
16 | // Start the plugin
17 | function init() {
18 | object.params = new Array();
19 | object.params['entities_id'] = 0;
20 | object.params['page_limit'] = 0;
21 | object.params['minimumResultsForSearch'] = 0;
22 | object.params['root_doc'] = null;
23 | object.params['emptyValue'] = null;
24 |
25 | if (options != undefined) {
26 | $.each(options, function (index, val) {
27 | if (val != undefined && val != null) {
28 | object.params[index] = val;
29 | }
30 | });
31 | }
32 | }
33 |
34 | this.changeRequesterColor = function (vip) {
35 | $(document).ready(function () {
36 |
37 | // only in ticket form
38 | if (location.pathname.indexOf('ticket.form.php') > 0) {
39 | $.urlParam = function (url, name) {
40 | var results = new RegExp('[\?&]' + name + '=([^]*)').exec(url);
41 | if (results != null) {
42 | return results[1] || 0;
43 | }
44 | };
45 |
46 | // get item id
47 | var items_id = $.urlParam(window.location.href, 'id');
48 |
49 | // Launched on each complete Ajax load
50 | $(document).ajaxComplete(function (event, xhr, option) {
51 |
52 | if (option.url !== undefined
53 | && (option.url.indexOf('vip/ajax/loadscripts.php') > 0 || option.url.indexOf('common.tabs.php') > 0)) {
54 |
55 | setTimeout(function () {
56 |
57 | if (items_id > 0) {
58 | $.ajax({
59 | url: root_vip_doc + '/ajax/ticket.php',
60 | type: "POST",
61 | dataType: "json",
62 | data: {
63 | 'items_id': items_id,
64 | 'action': 'getTicket'
65 | },
66 | success: function (response, opts) {
67 | var ticketVip = false;
68 | $.each(vip, function (index, val) {
69 | $.each(response.used, function (index2, val2) {
70 | var userid = val.id;
71 |
72 | if (val.id == val2
73 | ) {
74 | var userid = val.id;
75 | $("span[data-items-id='" + userid + "']").css("color", val.color);
76 | $("span[data-items-id='" + userid + "']").after(" ");
77 | }
78 | });
79 | });
80 | },
81 | });
82 | } else {
83 | $.ajax({
84 | url: root_vip_doc + '/ajax/ticket.php',
85 | type: "POST",
86 | dataType: "json",
87 | data: {
88 | 'action': 'getVIP'
89 | },
90 | success: function (response, opts) {
91 | var ticketVip = false;
92 | $.each(vip, function (index, val) {
93 | $.each(response.used, function (index2, val2) {
94 | var userid = val.id;
95 |
96 | if (val.id == val2
97 | ) {
98 | var userid = val.id;
99 | $("span[data-items-id='" + userid + "']").css("color", val.color);
100 | $("span[data-items-id='" + userid + "']").after(" ");
101 | }
102 | });
103 | });
104 | },
105 | });
106 | }
107 | }, 500);
108 | }
109 | // }, 500);
110 | }, this);
111 | }
112 | inputName = 'users_id';
113 | if (location.pathname.indexOf('printer.form.php') > 0) {
114 | $.urlParam = function (url, name) {
115 | var results = new RegExp('[\?&]' + name + '=([^]*)').exec(url);
116 | if (results != null) {
117 | return results[1] || 0;
118 | }
119 | };
120 | // get item id
121 | var items_id = $.urlParam(window.location.href, 'id');
122 |
123 | setTimeout(function () {
124 | $.ajax({
125 | url: root_vip_doc + '/ajax/ticket.php',
126 | type: "POST",
127 | dataType: "json",
128 | data: {
129 | 'items_id': items_id,
130 | 'action': 'getPrinter'
131 | },
132 | success: function (response, opts) {
133 | $.each(vip, function (index, val) {
134 | $.each(response.used, function (index2, val2) {
135 | var userid = val.id;
136 |
137 | if (val.id == val2
138 | ) {
139 | var userid = val.id;
140 | $("span[id^='select2-dropdown_users_id']").each(function () {
141 | //not select2-dropdown_users_id_tech
142 | selectname = $(this).attr('id');
143 | if (selectname.indexOf('select2-dropdown_users_id_tech') == -1) {
144 | $(this).css("color", val.color);
145 | }
146 |
147 | });
148 | // $("span[id^='select2-dropdown_users_id']").css("color", val.color);
149 | $("select[name='" + inputName + "']").before(" ");
150 | }
151 | });
152 | });
153 | }
154 | });
155 | }, 500);
156 | }
157 | inputName = 'users_id';
158 | if (location.pathname.indexOf('computer.form.php') > 0) {
159 | $.urlParam = function (url, name) {
160 | var results = new RegExp('[\?&]' + name + '=([^]*)').exec(url);
161 | if (results != null) {
162 | return results[1] || 0;
163 | }
164 | };
165 | // get item id
166 | var items_id = $.urlParam(window.location.href, 'id');
167 |
168 | setTimeout(function () {
169 | $.ajax({
170 | url: root_vip_doc + '/ajax/ticket.php',
171 | type: "POST",
172 | dataType: "json",
173 | data: {
174 | 'items_id': items_id,
175 | 'action': 'getComputer'
176 | },
177 | success: function (response, opts) {
178 | $.each(vip, function (index, val) {
179 | $.each(response.used, function (index2, val2) {
180 | var userid = val.id;
181 |
182 | if (val.id == val2
183 | ) {
184 | var userid = val.id;
185 | $("span[id^='select2-dropdown_users_id']").each(function () {
186 | //not select2-dropdown_users_id_tech
187 | selectname = $(this).attr('id');
188 | if (selectname.indexOf('select2-dropdown_users_id_tech') == -1) {
189 | $(this).css("color", val.color);
190 | }
191 |
192 | });
193 | // $("span[id^='select2-dropdown_users_id']").css("color", val.color);
194 | $("select[name='" + inputName + "']").before(" ");
195 | }
196 | });
197 | });
198 | }
199 | });
200 | }, 500);
201 | }
202 | });
203 | };
204 |
205 | return this;
206 | };
207 | }(jQuery));
208 |
--------------------------------------------------------------------------------
/inc/group.class.php:
--------------------------------------------------------------------------------
1 | .
27 | --------------------------------------------------------------------------
28 | */
29 |
30 | if (!defined('GLPI_ROOT')) {
31 | die("Sorry. You can't access directly to this file");
32 | }
33 |
34 | class PluginVipGroup extends CommonDBTM {
35 |
36 | static $rightname = "plugin_vip";
37 |
38 | /**
39 | * Configuration form
40 | * */
41 | function showForm($id, $options = []) {
42 |
43 | $target = $this->getFormURL();
44 | if (isset($options['target'])) {
45 | $target = $options['target'];
46 | }
47 |
48 | if (!Session::haveRight("plugin_vip", READ)) {
49 | return false;
50 | }
51 |
52 | $canedit = Session::haveRight("plugin_vip", UPDATE);
53 | $prof = new Profile();
54 |
55 | if ($id) {
56 | $this->getFromDB($id);
57 | $prof->getFromDB($id);
58 | }
59 |
60 | echo "