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
-----------------------
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');
diff --git a/hook.php b/hook.php
index 28a8587..03f0b03 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->TableExists('glpi_plugin_simcard_configs')) {
// The plugin is at least 1.3
// Get the current version in the plugin's configuration
$pluginSimcardConfig = new PluginSimcardConfig();
diff --git a/inc/simcard.class.php b/inc/simcard.class.php
index be0a7b6..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";
}
@@ -317,6 +348,80 @@ 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
+ ];
+
+$tab[] = [
+ 'id' => '4',
+ 'table' => 'glpi_users',
+ 'field' => 'name',
+ 'linkfield' => 'users_id',
+ 'name' => __('User'),
+ 'datatype' => 'dropdown',
+ 'massiveaction' => false // implicit key==1
+ ];
+
+
+ $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;
+
+}
+
function getSearchOptions() {
global $CFG_GLPI, $LANG;
@@ -527,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',
@@ -626,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__));
}
diff --git a/inc/simcard_item.class.php b/inc/simcard_item.class.php
index 2f414a8..0db717f 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;
+
+
}
/**
@@ -103,8 +111,10 @@ static function countForItem($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__),
+ ["itemtype" => $itemtype, "items_id" => $id]
+ );
}
/**
@@ -135,7 +145,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,12 +176,12 @@ static function uninstall() {
}
static function showForSimcard(PluginSimcardSimcard $simcard) {
- global $DB, $LANG;
+ global $DB, $LANG, $CFG_GLPI;
if (!$simcard->canView()) {
return false;
}
- $results = getAllDatasFromTable(getTableForItemType(__CLASS__),
+ $results = $DB->request(getTableForItemType(__CLASS__),
"`plugin_simcard_simcards_id` = '".$simcard->getID()."'");
echo "