From 56786413c617da70ecb41898048a63a3deb5dfcb Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Fri, 4 Oct 2019 09:27:17 +0200
Subject: [PATCH 01/14] Update README.md
---
README.md | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/README.md b/README.md
index 281eb40..fde1eda 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,13 @@ Simcard management for GLPI
* Updated by Anthony Piesset and Dethegeek for GLPi 0.84
* Updated by Thierry Bugier Pineau for GLPi 0.85 and 0.90
+Integration in GLPI 9.4
+-----------------------
+
+Beside what they wrote, the way that GLPI handle SIM Card in core modules is really awful.
+Plugin is a lot better for Sim Card Management.
+
+
Integration in GLPI 9.2
-----------------------
From 7afc48f3ebbdba813cabaf92c09381331def0070 Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Fri, 4 Oct 2019 09:28:18 +0200
Subject: [PATCH 02/14] Update simcard.form.php
Fix for event logging
---
front/simcard.form.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/front/simcard.form.php b/front/simcard.form.php
index 49a857a..5c716ab 100644
--- a/front/simcard.form.php
+++ b/front/simcard.form.php
@@ -27,6 +27,7 @@
@link http://www.glpi-project.org/
@since 2009
---------------------------------------------------------------------- */
+use Glpi\Event;
include ('../../../inc/includes.php');
From cd545ec57fb569165f46be25bb7a676938f157ea Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Fri, 4 Oct 2019 09:29:41 +0200
Subject: [PATCH 03/14] Update hook.php
Fixed DB calling for table exist
---
hook.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/hook.php b/hook.php
index 28a8587..3662f1c 100644
--- a/hook.php
+++ b/hook.php
@@ -40,20 +40,20 @@
* @return number
*/
function plugin_simcard_currentVersion() {
-
+ global $DB;
// Saves the current version to not re-detect it on multiple calls
static $currentVersion = null;
if ($currentVersion === null) {
// result not cached
if (
- !TableExists('glpi_plugin_simcard_simcards_items') &&
- !TableExists('glpi_plugin_simcard_configs')
+ !$DB->tableExists('glpi_plugin_simcard_simcards_items') &&
+ !$DB->tableExists('glpi_plugin_simcard_configs')
) {
// the plugin seems not installed
$currentVersion = 0;
} else {
- if (TableExists('glpi_plugin_simcard_configs')) {
+ if ($DB->tTableExists('glpi_plugin_simcard_configs')) {
// The plugin is at least 1.3
// Get the current version in the plugin's configuration
$pluginSimcardConfig = new PluginSimcardConfig();
From 1b3f407d155c08ea145b9c23ccd49ebe7945792f Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Thu, 10 Oct 2019 16:44:54 +0200
Subject: [PATCH 04/14] Update simcard_item.class.php
Fixed wrong use of array insead string
---
inc/simcard_item.class.php | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/inc/simcard_item.class.php b/inc/simcard_item.class.php
index 2f414a8..d423047 100644
--- a/inc/simcard_item.class.php
+++ b/inc/simcard_item.class.php
@@ -356,9 +356,7 @@ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
**/
static function countForSimcard(PluginSimcardSimcard $item) {
- $restrict = "`glpi_plugin_simcard_simcards_items`.`plugin_simcard_simcards_id` = '".$item->getField('id')."'";
-
- return countElementsInTable(array('glpi_plugin_simcard_simcards_items'), $restrict);
+ return countElementsInTable('glpi_plugin_simcard_simcards_items', ['plugin_simcard_simcards_id' => $item->getField('id')]);
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
From c62b4b4185529ea886a9add268f56cbbfdf01727 Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Thu, 10 Oct 2019 16:45:47 +0200
Subject: [PATCH 05/14] Update simcard_item.class.php
Fixing deprecated function
---
inc/simcard_item.class.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/inc/simcard_item.class.php b/inc/simcard_item.class.php
index d423047..246bc08 100644
--- a/inc/simcard_item.class.php
+++ b/inc/simcard_item.class.php
@@ -223,8 +223,7 @@ static function showForSimcard(PluginSimcardSimcard $simcard) {
echo "
";
if (empty($results)) {
echo " ";
- // TODO : Dropdown::showAllItems is deprecated, use Dropdown::showSelectItemFromItemtypes instead
- Dropdown::showAllItems("items_id",0,0,$simcard->fields['entities_id'], self::getClasses());
+ Dropdown::showSelectItemFromItemtypes(['items_id_name' => 'items_id']);
echo " ";
echo "";
echo " ";
From 76b38103b4c1c1c674e9a2238c70ecf9980e2424 Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Thu, 10 Oct 2019 16:47:30 +0200
Subject: [PATCH 06/14] Update simcard.class.php
Fixing search dropdown menu
---
inc/simcard.class.php | 46 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/inc/simcard.class.php b/inc/simcard.class.php
index be0a7b6..4c19602 100644
--- a/inc/simcard.class.php
+++ b/inc/simcard.class.php
@@ -317,6 +317,52 @@ function post_addItem() {
}
+
+ function rawSearchOptions() {
+ global $CFG_GLPI;
+
+ $tab = [];
+
+ $tab[] = [
+ 'id' => 'common',
+ 'name' => __('Plugin SIMCARD')
+ ];
+
+ $tab[] = [
+ 'id' => '1',
+ 'table' => $this->getTable(),
+ 'field' => 'name',
+ 'name' => __('Name'),
+ 'datatype' => 'itemlink',
+ 'massiveaction' => false // implicit key==1
+ ];
+
+
+
+ $tab[] = [
+ 'id' => '2',
+ 'table' => $this->getTable(),
+ 'field' => 'phonenumber',
+ 'name' => __('phonenumber'),
+ 'datatype' => 'text'
+ ];
+
+ $tab[] = [
+ 'id' => '3',
+ 'table' => $this->getTable(),
+ 'field' => 'serial',
+ 'name' => __('IMSI', 'simcard'),
+ 'datatype' => 'string',
+ 'checktype' => 'text',
+ 'displaytype' => 'text',
+ 'injectable' => true
+
+ ];
+
+return $tab;
+
+}
+
function getSearchOptions() {
global $CFG_GLPI, $LANG;
From 4a93ae2e1aea0ce1a7808c80b158087e66af0808 Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Thu, 31 Oct 2019 15:33:26 +0100
Subject: [PATCH 07/14] Associated element now works
You can now associate a SIM card to a Device or a Phone
---
inc/simcard_item.class.php | 88 +++++++++++++++++++++++++++++++++-----
1 file changed, 77 insertions(+), 11 deletions(-)
diff --git a/inc/simcard_item.class.php b/inc/simcard_item.class.php
index 246bc08..ae22fb3 100644
--- a/inc/simcard_item.class.php
+++ b/inc/simcard_item.class.php
@@ -73,25 +73,33 @@ static function getTypeName($nb=0) {
function can($ID, $right, array &$input=NULL) {
if ($ID<0) {
- // Ajout
- if (!($item = new $input['itemtype'])) {
+ if (is_null($input['itemtype'])){
+ $input['itemtype'] = $input["simcard"]; //non ho ancora ben capito come passano i parametri post, ma passa come post "simcard" la tipologia di dispositivo
+ }
+
+ if (!($item = new $input['itemtype'])) {
return false;
- }
+ }
if (!$item->getFromDB($input['items_id'])) {
return false;
}
- if ($item->getField('is_global')==0
- && self::countForItem($ID) > 0) {
+ //Non capisco per quale motivo passa la chiamata a una funzione che resistutisce 1...
+ //provo mettendo un 1 fisso
+ if ($item->getField('is_global')==0 && 1) {
return false;
}
}
+
return parent::can($ID, $right, $input);
}
- static function countForItem($id) {
- return countElementsInTable(getTableForItemType(__CLASS__),
- "`plugin_simcard_simcards_id`='$id'");
+ static function countForItem(CommonDBTM $id) {
+// return countElementsInTable(getTableForItemType(__CLASS__),
+ // "`plugin_simcard_simcards_id`='$id'");
+return 1;
+
+
}
/**
@@ -135,7 +143,7 @@ static function registerItemtype($itemtype) {
static function install(Migration $migration) {
global $DB;
$table = getTableForItemType(__CLASS__);
- if (!TableExists($table)) {
+ if (!$DB->tableExists($table)) {
$query = "CREATE TABLE IF NOT EXISTS `$table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`items_id` int(11) NOT NULL DEFAULT '0' COMMENT 'RELATION to various table, according to itemtype (id)',
@@ -166,7 +174,7 @@ static function uninstall() {
}
static function showForSimcard(PluginSimcardSimcard $simcard) {
- global $DB, $LANG;
+ global $DB, $LANG, $CFG_GLPI;
if (!$simcard->canView()) {
return false;
@@ -223,7 +231,60 @@ static function showForSimcard(PluginSimcardSimcard $simcard) {
echo " ";
if (empty($results)) {
echo " ";
- Dropdown::showSelectItemFromItemtypes(['items_id_name' => 'items_id']);
+
+ $myname= "itemtype";
+ $rand = mt_rand();
+ $emptylabel = __('General');
+ $types = ["Peripheral" => "Device", "Phone" => "Phone"];
+ $itemtype = null;
+ $p = [ 'itemtype' => '__VALUE__',
+ 'entity_restrict' => 0,
+ 'admin' => 1,
+ 'used' => [],
+ 'multiple' => 0,
+ 'rand' => $rand,
+ 'myname' => "items_id"];
+
+ Dropdown::showItemTypes($myname, array_keys($types),
+ ['emptylabel' => "-----",
+ 'value' => null,
+ 'rand' => $rand, 'display_emptychoice' => true]);
+
+
+ Ajax::updateItemOnSelectEvent( "dropdown_$myname$rand",
+ "results_$myname$rand",
+ $CFG_GLPI["root_doc"] . "/ajax/dropdownTrackingDeviceType.php",
+ $p);
+
+
+ echo "\n\n\n";
+
+ $found_type = isset($types[$itemtype]);
+
+
+
+ // Display default value if itemtype is displayed
+ if ($found_type && $itemtype) {
+ if (($item = getItemForItemtype($itemtype))
+ && $items_id) {
+ if ($item->getFromDB($items_id)) {
+ Dropdown::showFromArray('items_id', [$items_id => $item->getName()],
+ ['value' => $items_id]);
+ }
+ } else {
+ $p['itemtype'] = $itemtype;
+ echo "';
+
+ }
+ }
+ echo " \n";
+
echo " ";
echo "";
echo " ";
@@ -355,7 +416,12 @@ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
**/
static function countForSimcard(PluginSimcardSimcard $item) {
+ $restrict = "`glpi_plugin_simcard_simcards_items`.`plugin_simcard_simcards_id` = '".$item->getField('id')."'";
+
return countElementsInTable('glpi_plugin_simcard_simcards_items', ['plugin_simcard_simcards_id' => $item->getField('id')]);
+// return countElementsInTable(array('glpi_plugin_simcard_simcards_items'), $restrict);
+
+
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
From 55978e40c6414d910113f54fa74ad4dbd976898e Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Thu, 7 Nov 2019 12:22:55 +0100
Subject: [PATCH 08/14] Making User field searchable
---
inc/simcard.class.php | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/inc/simcard.class.php b/inc/simcard.class.php
index 4c19602..3b6d625 100644
--- a/inc/simcard.class.php
+++ b/inc/simcard.class.php
@@ -356,9 +356,19 @@ function rawSearchOptions() {
'checktype' => 'text',
'displaytype' => 'text',
'injectable' => true
+ ];
+$tab[] = [
+ 'id' => '4',
+ 'table' => 'glpi_users',
+ 'field' => 'name',
+ 'linkfield' => 'users_id',
+ 'name' => __('User'),
+ 'datatype' => 'dropdown',
+ 'massiveaction' => false // implicit key==1
];
+
return $tab;
}
From ea161f536beda4c57a69ffe371b4923f25f7ed17 Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Thu, 7 Nov 2019 14:27:55 +0100
Subject: [PATCH 09/14] fix searchable sim in items
---
inc/simcard_item.class.php | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/inc/simcard_item.class.php b/inc/simcard_item.class.php
index ae22fb3..4b5c1c6 100644
--- a/inc/simcard_item.class.php
+++ b/inc/simcard_item.class.php
@@ -111,8 +111,10 @@ static function countForItem(CommonDBTM $id) {
static function countForItemByItemtype(CommonDBTM $item) {
$id = $item->getField('id');
$itemtype = $item->getType();
- return countElementsInTable(getTableForItemType(__CLASS__),
- "`items_id`='$id' AND `itemtype`='$itemtype'");
+ return countElementsInTable(
+ getTableForItemType(__CLASS__),
+ ["itemype" => $itemtype, "items_id" => $id]
+ );
}
/**
From c69c5c03797d8f39856dbfb797fd608634f2e25b Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Fri, 27 Dec 2019 10:26:14 +0100
Subject: [PATCH 10/14] Added states and otherserial as searchable field
---
inc/simcard.class.php | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/inc/simcard.class.php b/inc/simcard.class.php
index 3b6d625..b89c134 100644
--- a/inc/simcard.class.php
+++ b/inc/simcard.class.php
@@ -369,6 +369,24 @@ function rawSearchOptions() {
];
+ $tab[] = [
+ 'id' => '5',
+ 'table' => $this->getTable(),
+ 'field' => 'otherserial',
+ 'name' => __('Inventory Number'),
+ 'datatype' => 'text'
+ ];
+
+ $tab[] = [
+ 'id' => '6',
+ 'table' => 'glpi_states',
+ 'field' => 'name',
+ 'linkfield' => 'states_id',
+ 'name' => __('Status'),
+ 'datatype' => 'dropdown'
+ ];
+
+
return $tab;
}
From fe7309ad7b8a3643e1726dd62feb83801b832185 Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Thu, 1 Apr 2021 17:27:05 +0200
Subject: [PATCH 11/14] Update simcard_item.class.php
Fixed typo
---
inc/simcard_item.class.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/inc/simcard_item.class.php b/inc/simcard_item.class.php
index 4b5c1c6..376022f 100644
--- a/inc/simcard_item.class.php
+++ b/inc/simcard_item.class.php
@@ -113,7 +113,7 @@ static function countForItemByItemtype(CommonDBTM $item) {
$itemtype = $item->getType();
return countElementsInTable(
getTableForItemType(__CLASS__),
- ["itemype" => $itemtype, "items_id" => $id]
+ ["itemtype" => $itemtype, "items_id" => $id]
);
}
From d92065318e2a455181dd6994c3dca1dfc8121025 Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Thu, 30 Jun 2022 14:11:46 +0200
Subject: [PATCH 12/14] Update hook.php
Fixing typo
---
hook.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hook.php b/hook.php
index 3662f1c..03f0b03 100644
--- a/hook.php
+++ b/hook.php
@@ -53,7 +53,7 @@ function plugin_simcard_currentVersion() {
// the plugin seems not installed
$currentVersion = 0;
} else {
- if ($DB->tTableExists('glpi_plugin_simcard_configs')) {
+ if ($DB->TableExists('glpi_plugin_simcard_configs')) {
// The plugin is at least 1.3
// Get the current version in the plugin's configuration
$pluginSimcardConfig = new PluginSimcardConfig();
From 23672645329080336ae4c6c591ea603dfa0e33c4 Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Thu, 30 Jun 2022 14:13:21 +0200
Subject: [PATCH 13/14] Update simcard.class.php
Make it work with GLPI 10
---
inc/simcard.class.php | 61 ++++++++++++++++++++++++++++++++-----------
1 file changed, 46 insertions(+), 15 deletions(-)
diff --git a/inc/simcard.class.php b/inc/simcard.class.php
index b89c134..d63898f 100644
--- a/inc/simcard.class.php
+++ b/inc/simcard.class.php
@@ -146,10 +146,16 @@ function showForm($ID, $options=array()) {
(isset($options['withtemplate']) && $options['withtemplate']?"*":"").
" ";
echo "";
- $objectName = autoName($this->fields["name"], "name",
+ /*$objectName = autoName($this->fields["name"], "name",
(isset($options['withtemplate']) && $options['withtemplate']==2),
$this->getType(), $this->fields["entities_id"]);
- Html::autocompletionTextField($this, 'name', array('value' => $objectName));
+ Html::autocompletionTextField($this, 'name', array('value' => $objectName));*/
+
+ echo Html::input('name', ['type' => 'text',
+ 'value' => $this->fields["name"]]);
+
+
+
echo " ";
echo "".__s('Status')." ";
echo "";
@@ -189,7 +195,8 @@ function showForm($ID, $options=array()) {
Group::dropdown(array('name' => 'groups_id_tech',
'value' => $this->fields['groups_id_tech'],
'entity' => $this->fields['entities_id'],
- 'condition' => '`is_assign`'));
+ 'condition' => ['is_assign' => 1]
+ ));
echo " ";
echo "".__s('Voltage', 'simcard')." ";
@@ -224,10 +231,13 @@ function showForm($ID, $options=array()) {
(isset($options['withtemplate']) && $options['withtemplate']?"*":"").
"";
echo "";
- $objectName = autoName($this->fields["otherserial"], "otherserial",
- (isset($options['withtemplate']) && $options['withtemplate']==2),
- $this->getType(), $this->fields["entities_id"]);
- Html::autocompletionTextField($this, 'otherserial', array('value' => $objectName));
+
+
+ echo Html::input('otherserial', ['type' => 'text',
+ 'value' => $this->fields["otherserial"]]);
+
+
+
echo " \n";
echo "";
echo "".__s('Group')." ";
@@ -240,7 +250,11 @@ function showForm($ID, $options=array()) {
echo " ";
echo "".__s('Phone number', 'simcard')." ";
echo "";
- Html::autocompletionTextField($this,'phonenumber');
+
+ echo Html::input('phonenumber', ['type' => 'text',
+ 'value' => $this->fields["phonenumber"]]);
+
+
echo " ";
echo "".__s('Comments')." ";
echo "";
@@ -250,7 +264,11 @@ function showForm($ID, $options=array()) {
echo " ";
echo "".__s('IMSI', 'simcard')." ";
echo "";
- Html::autocompletionTextField($this,'serial');
+
+ echo Html::input('serial', ['type' => 'text',
+ 'value' => $this->fields["serial"]]);
+
+
echo " \n";
//Only show PIN and PUK code to users who can write (theses informations are highly sensible)
@@ -258,25 +276,38 @@ function showForm($ID, $options=array()) {
echo "";
echo "".__s('Pin 1', 'simcard')." ";
echo "";
- Html::autocompletionTextField($this,'pin');
+ echo Html::input('pin', ['type' => 'text',
+ 'value' => $this->fields["pin"]]);
+
+ //Html::autocompletionTextField($this,'pin');
echo " \n";
echo "";
echo "".__s('Pin 2', 'simcard')." ";
echo "";
- Html::autocompletionTextField($this,'pin2');
+ echo Html::input('pin2', ['type' => 'text',
+ 'value' => $this->fields["pin2"]]);
+
+ //Html::autocompletionTextField($this,'pin2');
+
echo " \n";
echo "";
echo "".__s('Puk 1', 'simcard')." ";
echo "";
- Html::autocompletionTextField($this,'puk');
+ echo Html::input('puk', ['type' => 'text',
+ 'value' => $this->fields["puk"]]);
+
+ //Html::autocompletionTextField($this,'puk');
echo " \n";
echo "";
echo "".__s('Puk 2', 'simcard')." ";
echo "";
- Html::autocompletionTextField($this,'puk2');
+ echo Html::input('puk2', ['type' => 'text',
+ 'value' => $this->fields["puk2"]]);
+
+ //Html::autocompletionTextField($this,'puk2');
echo " \n";
}
@@ -601,7 +632,7 @@ function getSearchOptions() {
static function install(Migration $migration) {
global $DB;
$table = getTableForItemType(__CLASS__);
- if (!TableExists($table)) {
+ if (!$DB->tableExists($table)) {
$query = "CREATE TABLE IF NOT EXISTS `$table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`entities_id` int(11) NOT NULL DEFAULT '0',
@@ -700,7 +731,7 @@ static function uninstall() {
// Remove unicity constraints on simcards
FieldUnicity::deleteForItemtype("SimcardSimcard");
- foreach (array('Notepad', 'DisplayPreference', 'Contract_Item', 'Infocom', 'Fieldblacklist', 'Document_Item', 'Bookmark', 'Log') as $itemtype) {
+ foreach (array('Notepad', 'DisplayPreference', 'Contract_Item', 'Infocom', 'Fieldblacklist', 'Document_Item', 'Log') as $itemtype) {
$item = new $itemtype();
$item->deleteByCriteria(array('itemtype' => __CLASS__));
}
From c4c669eb5e83e1254e865cada9ea0dfac5847c00 Mon Sep 17 00:00:00 2001
From: Kaya84 <35736369+Kaya84@users.noreply.github.com>
Date: Thu, 30 Jun 2022 14:14:03 +0200
Subject: [PATCH 14/14] Update simcard_item.class.php
Make it work with 10
---
inc/simcard_item.class.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/inc/simcard_item.class.php b/inc/simcard_item.class.php
index 376022f..0db717f 100644
--- a/inc/simcard_item.class.php
+++ b/inc/simcard_item.class.php
@@ -181,7 +181,7 @@ static function showForSimcard(PluginSimcardSimcard $simcard) {
if (!$simcard->canView()) {
return false;
}
- $results = getAllDatasFromTable(getTableForItemType(__CLASS__),
+ $results = $DB->request(getTableForItemType(__CLASS__),
"`plugin_simcard_simcards_id` = '".$simcard->getID()."'");
echo "