Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Continuous integration"

on:
push:
branches:
- "feature/**"
- "bugfix/**"
tags:
- "*"
workflow_dispatch:

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
generate-ci-matrix:
name: "Generate CI matrix"
runs-on: "ubuntu-latest"
outputs:
matrix: ${{ steps.generate-ci-matrix.outputs.matrix }}
steps:
- name: "Generate CI matrix"
id: "generate-ci-matrix"
run: |
MATRIX='
{
"include": [
{"glpi-version": "11.0.x", "php-version": "8.4", "db-image": "mariadb:11.4"}
]
}
'
echo "matrix=$(echo $MATRIX | jq -c .)" >> $GITHUB_OUTPUT
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
needs: "generate-ci-matrix"
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-ci-matrix.outputs.matrix) }}
uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1"
with:
plugin-key: "geolocation"
glpi-version: "${{ matrix.glpi-version }}"
php-version: "${{ matrix.php-version }}"
db-image: "${{ matrix.db-image }}"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/public/vendor
/vendor
composer.lock
21 changes: 21 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__)
->name('*.php')
->ignoreVCSIgnored(true);

$config = new Config();

$rules = [
'@PER-CS2.0' => true,
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']], // For PHP 7.4 compatibility
];

return $config
->setRules($rules)
->setFinder($finder)
->setUsingCache(false);
18 changes: 18 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<ruleset>
<file>.</file>
<exclude-pattern>/.git/</exclude-pattern>
<exclude-pattern type="relative">^node_modules/</exclude-pattern>
<exclude-pattern type="relative">^vendor/</exclude-pattern>

<arg name="colors" />
<arg name="extensions" value="php" />
<arg value="p" />
<arg name="warning-severity" value="0" />

<rule ref="PSR12">
<exclude name="Generic.Files.LineLength" />
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
</rule>
<rule ref="Generic.Arrays.ArrayIndent"></rule>
</ruleset>
15 changes: 15 additions & 0 deletions .twig_cs.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use FriendsOfTwig\Twigcs;

$finder = Twigcs\Finder\TemplateFinder::create()
->in(__DIR__ . '/templates/')
->name('*.html.twig')
->ignoreVCSIgnored(true);

return Twigcs\Config\Config::create()
->setFinder($finder)
->setRuleSet(\Glpi\Tools\GlpiTwigRuleset::class)
;
133 changes: 68 additions & 65 deletions ajax/map.php
Original file line number Diff line number Diff line change
@@ -1,81 +1,84 @@
<?php

/*
-------------------------------------------------------------------------
Geolocation plugin for GLPI
Copyright (C) 2022 by the TICgal Team.
https://www.tic.gal
-------------------------------------------------------------------------
LICENSE
This file is part of the Geolocation plugin.
Geolocation plugin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Geolocation plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Geolocation. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
@package Geolocation
@author the TICgal team
@copyright Copyright (c) 2022 TICgal team
@license AGPL License 3.0 or (at your option) any later version
http://www.gnu.org/licenses/agpl-3.0-standalone.html
@link https://www.tic.gal
@since 2022
----------------------------------------------------------------------
-------------------------------------------------------------------------
Geolocation plugin for GLPI
Copyright (C) 2022 by the TICgal Team.
https://www.tic.gal
-------------------------------------------------------------------------
LICENSE
This file is part of the Geolocation plugin.
Geolocation plugin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Geolocation plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Geolocation. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
@package Geolocation
@author the TICgal team
@copyright Copyright (c) 2022 TICgal team
@license AGPL License 3.0 or (at your option) any later version
http://www.gnu.org/licenses/agpl-3.0-standalone.html
@link https://www.tic.gal
@since 2022
----------------------------------------------------------------------
*/

include("../../../inc/includes.php");
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkLoginUser();

/** @var \DBmysql $DB */
global $DB;

$result = [];
if (!isset($_POST['itemtype']) || !isset($_POST['params'])) {
http_response_code(500);
$result = [
'success' => false,
'message' => __('Required argument missing!')
];
http_response_code(500);
$result = [
'success' => false,
'message' => __('Required argument missing!'),
];
} else {
$itemtype = $_POST['itemtype'];
$params = $_POST['params'];
$itemtype = $_POST['itemtype'];
$params = $_POST['params'];

$data = Search::prepareDatasForSearch($itemtype, $params);
Search::constructSQL($data);
Search::constructData($data);
$data = Search::prepareDatasForSearch($itemtype, $params);
Search::constructSQL($data);
Search::constructData($data);

$rows = $data['data']['rows'];
$items_id = [];
$titles = [];
foreach ($rows as $row) {
$items_id[] = $row['raw']['id'];
$titles[$row['raw']['id']] = $row['raw']["ITEM_".$itemtype."_1"];
}
$points = [];
if (count($items_id) > 0) {
$query = [
'FROM' => PluginGeolocationGeolocation::getTable(),
'WHERE' => [
'itemtype' => $itemtype,
'items_id' => $items_id
]
];
$iterator = $DB->request($query);
foreach ($iterator as $result) {
$points[$result['id']] = [
'lat' => $result['latitude'],
'lng' => $result['longitude'],
'title' => $titles[$result['items_id']],
'url' => $itemtype::getFormURLWithID($result['items_id']),
'count' => 1
];
}
}
$result['points'] = $points;
$rows = $data['data']['rows'];
$items_id = [];
$titles = [];
foreach ($rows as $row) {
$items_id[] = $row['raw']['id'];
$titles[$row['raw']['id']] = $row['raw']["ITEM_" . $itemtype . "_1"];
}
$points = [];
if (count($items_id) > 0) {
$query = [
'FROM' => PluginGeolocationGeolocation::getTable(),
'WHERE' => [
'itemtype' => $itemtype,
'items_id' => $items_id,
],
];
$iterator = $DB->request($query);
foreach ($iterator as $result) {
$points[$result['id']] = [
'lat' => $result['latitude'],
'lng' => $result['longitude'],
'title' => $titles[$result['items_id']],
'url' => $itemtype::getFormURLWithID($result['items_id']),
'count' => 1,
];
}
}
$result['points'] = $points;
}
echo json_encode($result);
35 changes: 35 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"require": {
"chillerlan/php-qrcode":"*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.75",
"friendsoftwig/twigcs": "^6.1",
"glpi-project/tools": "^0.7.5",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-deprecation-rules": "^2.0",
"squizlabs/php_codesniffer": "^3.7"
},
"config": {
"optimize-autoloader": true,
"platform": {
"php": "8.1.0"
},
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"autoload": {
"psr-4": {
"CustomPHPStanRules\\": "tools/phpstan/rules/"
}
},
"autoload-dev": {
"psr-4": {
"Glpi\\Tools\\": "../../tools/src/"
}
}
}
15 changes: 9 additions & 6 deletions front/config.form.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
-------------------------------------------------------------------------
Geolocation plugin for GLPI
Expand All @@ -22,23 +23,25 @@
@author the TICgal team
@copyright Copyright (c) 2022 TICgal team
@license AGPL License 3.0 or (at your option) any later version
http://www.gnu.org/licenses/agpl-3.0-standalone.html
http://www.gnu.org/licenses/agpl-3.0-standalone.html
@link https://www.tic.gal
@since 2022
----------------------------------------------------------------------
*/
include('../../../inc/includes.php');

$plugin = new Plugin();
if (!$plugin->isInstalled('geolocation') || !$plugin->isActivated('geolocation')) {
Html::displayNotFoundError();
throw new \Glpi\Exception\Http\NotFoundHttpException();
}

Session::checkRight('config', UPDATE);

global $CFG_GLPI;

$config = new PluginGeolocationConfig();
if (isset($_POST["update"])) {
$config->check($_POST['id'], UPDATE);
$config->update($_POST);
Html::back();
$config->check($_POST['id'], UPDATE);
$config->update($_POST);
Html::back();
}
Html::redirect($CFG_GLPI["root_doc"] . "/front/config.form.php?forcetab=" . urlencode('PluginGeolocationConfig$1'));
37 changes: 18 additions & 19 deletions front/geolocation.form.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
-------------------------------------------------------------------------
Geolocation plugin for GLPI
Expand All @@ -22,32 +23,30 @@
@author the TICgal team
@copyright Copyright (c) 2022 TICgal team
@license AGPL License 3.0 or (at your option) any later version
http://www.gnu.org/licenses/agpl-3.0-standalone.html
http://www.gnu.org/licenses/agpl-3.0-standalone.html
@link https://www.tic.gal
@since 2022
----------------------------------------------------------------------
*/

include('../../../inc/includes.php');

$geo = new PluginGeolocationGeolocation();
if (isset($_POST['add'])) {
$geo->check(-1, CREATE, $_POST);
$geo->check(-1, CREATE, $_POST);

$newID = $geo->add($_POST, false);
Html::back();
} else if (isset($_POST["purge"])) {
$geo->check($_POST["id"], PURGE);
$geo->delete($_POST, 1);
Html::back();
} else if (isset($_POST["update"])) {
$geo->check($_POST["id"], UPDATE);
if (empty($_POST['latitude']) && empty($_POST['longitude'])) {
$geo->check($_POST["id"], PURGE);
$geo->delete($_POST, 1);
} else {
$geo->update($_POST);
}
Html::back();
$newID = $geo->add($_POST, false);
Html::back();
} elseif (isset($_POST["purge"])) {
$geo->check($_POST["id"], PURGE);
$geo->delete($_POST, 1);
Html::back();
} elseif (isset($_POST["update"])) {
$geo->check($_POST["id"], UPDATE);
if (empty($_POST['latitude']) && empty($_POST['longitude'])) {
$geo->check($_POST["id"], PURGE);
$geo->delete($_POST, 1);
} else {
$geo->update($_POST);
}
Html::back();
}
Html::back();
Loading
Loading