Hi,
While I'm preparing the evolution on the network port, I saw few things
that I suggest. You will find the patches as attachment.
* add.internet.module.patch : I suggest to dissociate the "networking"
module and the "internet" one. Thus, "networking" will concern the
internal of the computer (ie : NIC, hostnames, ...) whereas "internet"
will concern the external of the computer, but inside the network (ie :
IPs, DNS names, ...) ;
* add.possibility.to.set.specific.onChange.patch : it would be fancy to
be able to set anything else than "submit()" inside the "onchange" field
of dropdowns. For instance, when inside a tab, I need to update the tab
itself, but not the whole page, I use this parameter to set
"reloadTab(...)" on change of the dropdown. Moreover, I correct a few
missing of passing displaywith to the ajax/dropdownValue.php ;
* add.tag.to.vlan.patch : many vlans relies on IEEE 802.1Q. This norm
define the TAG field. I suggest to add it.
* enhance.commonTreeDropDown.for.father.migration.patch : I don't know
if it is a misunderstanding of mine, but it seems that when a node of a
CommonTreeDropDown is moved inside the tree, all its children are not
updated correctly. Among others, their completename fields are not
updated. Their sons_cache are cleared wherever this part of the tree has
not been updated. Actually, the previous version clean cache fields of
all nodes, that is not optimale, I think. This overzealousness induce
parents to clean sons_cache, but also ancestors_cache.
So, I redefine the post_updateitem to update correctly the sons and the
parents (parents before the update and after the update). Moreover, this
part of the CommonTreeDropdown becomas standalone (no need to call
external "out of class" function "regenerateTreeCompleteNameUnderID").
Regards
Damien Touraine
--
--------------------------------------------------------------------
Damien TOURAINE - Ingénieur de Recherche CNRS, LIMSI-CNRS
Groupe de RV&A "VENISE", (http://www.limsi.fr/venise/)
Bat. 508, Universite Paris-Sud 91403 Orsay cedex - +33 1 69 85 81 64
--------------------------------------------------------------------
Index: install/mysql/glpi-0.83-empty.sql
===================================================================
--- install/mysql/glpi-0.83-empty.sql (revision 15226)
+++ install/mysql/glpi-0.83-empty.sql (working copy)
@@ -3679,6 +3808,7 @@
`monitor` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`software` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`networking` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `internet` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`printer` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`peripheral` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`cartridge` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
@@ -3780,10 +3910,10 @@
KEY `date_mod` (`date_mod`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-INSERT INTO `glpi_profiles` VALUES
('1','post-only','helpdesk','1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'r','1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'r',NULL,NULL,'1',NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,'1','1','[\"Computer\",\"Software\",\"Phone\"]',NULL,'0','0',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'0');
-INSERT INTO `glpi_profiles` VALUES
('2','normal','central','0','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','1','r','r',NULL,'r',NULL,NULL,NULL,NULL,'r','r',NULL,NULL,NULL,NULL,NULL,NULL,'w',NULL,'r',NULL,'r','r','r',NULL,NULL,NULL,NULL,NULL,NULL,'1','1','1','0','0','0','0','0','1','0','0','1','1','0','1','0','0','1','0','0','1','1','1','[\"Computer\",\"Software\",\"Phone\"]',NULL,'0','0',NULL,NULL,'r',NULL,NULL,NULL,NULL,NULL,'1','1',NULL,NULL,NULL,NULL,NULL,'0',NULL,'1','1',NULL,NULL,'1','1',NULL,NULL,'0');
-INSERT INTO `glpi_profiles` VALUES
('3','admin','central','0','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','1','w','r','w','r','w','w','w','w','w','w',NULL,NULL,NULL,NULL,NULL,NULL,'w','w','r','r','w','w','w',NULL,NULL,NULL,NULL,NULL,NULL,'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','3','[\"Computer\",\"Software\",\"Phone\"]',NULL,'0','0',NULL,NULL,'w','w',NULL,NULL,NULL,NULL,'1','1','w',NULL,NULL,'w','1','1',NULL,'1','1','1',NULL,'1','1','1',NULL,'0');
-INSERT INTO `glpi_profiles` VALUES
('4','super-admin','central','0','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','1','w','r','w','r','w','w','w','w','w','w','w','r','w','w','w','w','w','w','r','w','w','w','w','w','w','r','w','w','w','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','3','[\"Computer\",\"Software\",\"Phone\"]',NULL,'0','0','w','w','w','w','w','w',NULL,NULL,'1','1','w','w','w','w','1','1','w','1','1','1',NULL,'1','1','1',NULL,'0');
+INSERT INTO `glpi_profiles` VALUES
('1','post-only','helpdesk','1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'r','1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'r',NULL,NULL,'1',NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,'1','1','[\"Computer\",\"Software\",\"Phone\"]',NULL,'0','0',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'0');
+INSERT INTO `glpi_profiles` VALUES
('2','normal','central','0','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','1','r','r',NULL,'r',NULL,NULL,NULL,NULL,'r','r',NULL,NULL,NULL,NULL,NULL,NULL,'w',NULL,'r',NULL,'r','r','r',NULL,NULL,NULL,NULL,NULL,NULL,'1','1','1','0','0','0','0','0','1','0','0','1','1','0','1','0','0','1','0','0','1','1','1','[\"Computer\",\"Software\",\"Phone\"]',NULL,'0','0',NULL,NULL,'r',NULL,NULL,NULL,NULL,NULL,'1','1',NULL,NULL,NULL,NULL,NULL,'0',NULL,'1','1',NULL,NULL,'1','1',NULL,NULL,'0');
+INSERT INTO `glpi_profiles` VALUES
('3','admin','central','0','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','1','w','r','w','r','w','w','w','w','w','w',NULL,NULL,NULL,NULL,NULL,NULL,'w','w','r','r','w','w','w',NULL,NULL,NULL,NULL,NULL,NULL,'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','3','[\"Computer\",\"Software\",\"Phone\"]',NULL,'0','0',NULL,NULL,'w','w',NULL,NULL,NULL,NULL,'1','1','w',NULL,NULL,'w','1','1',NULL,'1','1','1',NULL,'1','1','1',NULL,'0');
+INSERT INTO `glpi_profiles` VALUES
('4','super-admin','central','0','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','1','w','r','w','r','w','w','w','w','w','w','w','r','w','w','w','w','w','w','r','w','w','w','w','w','w','r','w','w','w','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','3','[\"Computer\",\"Software\",\"Phone\"]',NULL,'0','0','w','w','w','w','w','w',NULL,NULL,'1','1','w','w','w','w','1','1','w','1','1','1',NULL,'1','1','1',NULL,'0');
### Dump table glpi_profiles_users
Index: inc/profile.class.php
===================================================================
--- inc/profile.class.php (revision 15226)
+++ inc/profile.class.php (working copy)
@@ -633,6 +633,11 @@
self::dropdownNoneReadWrite("peripheral", $this->fields["peripheral"],
1, 1, 1);
echo "</td></tr>\n";
+ echo "<tr class='tab_bg_2'>";
+ echo "<td>".$LANG['Menu'][44]." :</td><td>";
+ self::dropdownNoneReadWrite("internet", $this->fields["internet"], 1, 1,
1);
+ echo "</td></tr>\n";
+
// Gestion / Management
echo "<tr class='tab_bg_1'><th
colspan='6'>".$LANG['Menu'][26]."</th></tr>";
Index: ajax/dropdownValue.php
===================================================================
--- ajax/dropdownValue.php (revision 15226)
+++ ajax/dropdownValue.php (working copy)
@@ -206,6 +206,8 @@
if (isset($_POST["auto_submit"]) && $_POST["auto_submit"]==1) {
echo " onChange='submit()'";
+ } else if (isset($_POST["on_change"]) && !empty($_POST["on_change"])) {
+ echo " onChange='".$_POST["on_change"]."'";
}
echo ">";
@@ -465,6 +467,8 @@
if (isset($_POST["auto_submit"]) && $_POST["auto_submit"]==1) {
echo " onChange='submit()'";
+ } else if (isset($_POST["on_change"]) && !empty($_POST["on_change"])) {
+ echo " onChange='".$_POST["on_change"]."'";
}
echo ">";
Index: inc/dropdown.class.php
===================================================================
--- inc/dropdown.class.php (revision 15226)
+++ inc/dropdown.class.php (working copy)
@@ -52,6 +52,7 @@
* and may have moreparams)
* - used : array / Already used items ID: not to display in dropdown
(default empty)
* - auto_submit : boolean / autosubmit on change (default false)
+ * - on_change : string / value to transmit to "onChange"
* - rand : integer / already computed rand value
* - condition : string / aditional SQL condition to limit display
* - displaywith : array / array of field to display with request
@@ -80,6 +81,7 @@
$params['used'] = array();
$params['toadd'] = array();
$params['auto_submit'] = 0;
+ $params['on_change'] = '';
$params['condition'] = '';
$params['rand'] = mt_rand();
$params['displaywith'] = array();
@@ -177,10 +179,12 @@
'update_item' => $params['toupdate'],
'used' => $params['used'],
'auto_submit' => $params['auto_submit'],
+ 'on_change' => $params['on_change'],
'condition' => $params['condition'],
'emptylabel' => $params['emptylabel'],
'display_emptychoice' => $params['display_emptychoice'],
- 'display_rootentity' => $params['display_rootentity']);
+ 'display_rootentity' => $params['display_rootentity'],
+ 'displaywith' => $params['displaywith']);
$default = "<select name='".$params['name']."'
id='dropdown_".$params['name'].
$params['rand']."'>";
Index: inc/vlan.class.php
===================================================================
--- inc/vlan.class.php (revision 15226)
+++ inc/vlan.class.php (working copy)
@@ -46,6 +46,16 @@
return $LANG['setup'][90];
}
+ function getAdditionalFields() {
+ global $LANG;
+
+ return array(array('name' => 'tag',
+ 'label' => "TAG",
+ 'type' => 'text',
+ 'list' => true));
+ }
+
+
function cleanDBonPurge() {
global $DB;
Index: install/mysql/glpi-0.83-empty.sql
===================================================================
--- install/mysql/glpi-0.83-empty.sql (revision 15226)
+++ install/mysql/glpi-0.83-empty.sql (working copy)
@@ -4962,6 +5092,7 @@
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`comment` text COLLATE utf8_unicode_ci,
+ `tag` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Index: inc/commontreedropdown.class.php
===================================================================
--- inc/commontreedropdown.class.php (revision 15226)
+++ inc/commontreedropdown.class.php (working copy)
@@ -97,13 +97,11 @@
}
- function getCompleteNameFromParents($parentCompleteName, $thisName) {
- return addslashes($parentCompleteName) . " > " . $thisName;
+ static function getCompleteNameFromParents($parentCompleteName, $thisName) {
+ return addslashes($parentCompleteName) . " > " . addslashes($thisName);
}
-
- function prepareInputForAdd($input) {
-
+ function adaptTreeFieldsFromUpdateOrAdd($input) {
$parent = clone $this;
if (isset($input[$this->getForeignKeyField()])
@@ -113,7 +111,7 @@
$input['level'] = $parent->fields['level']+1;
// Sometimes (internet address), the complete name may be different
...
$input['completename'] =
$this->getCompleteNameFromParents($parent->fields['completename'],
-
$input['name']);
+
$input['name']);
} else {
$input[$this->getForeignKeyField()] = 0;
$input['level'] = 1;
@@ -123,7 +121,11 @@
return $input;
}
+ function prepareInputForAdd($input) {
+ return $this->adaptTreeFieldsFromUpdateOrAdd($input);
+ }
+
function pre_deleteItem() {
global $DB;
@@ -147,35 +149,62 @@
return true;
}
-
function prepareInputForUpdate($input) {
-
// Can't move a parent under a child
if (isset($input[$this->getForeignKeyField()])
&& in_array($input[$this->getForeignKeyField()],
getSonsOf($this->getTable(), $input['id']))) {
return false;
}
+ if ($input[$this->getForeignKeyField()] !=
$this->fields[$this->getForeignKeyField()]) {
+ // Only the parents changes, so we must update theses, but not the sons
!
+ $input["ancestors_cache"] = 'NULL';
+ return $this->adaptTreeFieldsFromUpdateOrAdd($input);
+ }
return $input;
}
+ function regenerateTreeUnderID($ID, $updateName, $changeParent) {
+ global $DB;
+ if (($updateName) || ($changeParent)) {
+ $currentNode = clone $this;
+ $currentNode->getFromDB($ID);
+ $query = "SELECT `id`, `name`
+ FROM `".$this->getTable()."`
+ WHERE `".$this->getForeignKeyField()."` = $ID";
+ foreach ($DB->request($query) as $data) {
+ $query = "UPDATE `".$this->getTable()."` SET ";
+ $fieldsToUpdate = array();
+ if ($updateName || $changeParent)
+ $fieldsToUpdate[] =
"`completename`='".$this->getCompleteNameFromParents($currentNode->getField("completename"),
$data["name"])."'";
+ if ($changeParent) {
+ // We have to reset the ancestors as only these changes (ie : not
the children).
+ $fieldsToUpdate[] = "`ancestors_cache`='NULL'";
+ }
+ $query .= implode(', ',$fieldsToUpdate)." WHERE
`id`='".$data["id"]."'";
+ $DB->query($query);
+ $this->regenerateTreeUnderID($data["id"], $updateName, $changeParent);
+ }
+ }
+ }
- function post_updateItem($history=1) {
+ function recursiveCleanSonsAboveID($ID) {
+ global $DB;
+ if ($ID > 0) {
+ $query = "UPDATE `".$this->getTable()."` SET `sons_cache`='NULL' where
`id`='$ID'";
+ $DB->query($query);
- if (in_array('name', $this->updates)
- || in_array($this->getForeignKeyField(), $this->updates)) {
-
- if (in_array($this->getForeignKeyField(), $this->updates)) {
- CleanFields($this->getTable(), array('ancestors_cache',
'sons_cache'));
- }
-
- regenerateTreeCompleteNameUnderID($this->getTable(),
$this->input['id']);
- }
+ $currentNode = clone $this;
+ if ($currentNode->getFromDB($ID)) {
+ $parentID = $currentNode->getField($this->getForeignKeyField());
+ if ($ID != $parentID) {
+ $this->recursiveCleanSonsAboveID($parentID);
+ }
+ }
+ }
}
-
function post_addItem() {
-
CleanFields($this->getTable(), 'sons_cache');
$parent = $this->fields[$this->getForeignKeyField()];
@@ -188,6 +217,54 @@
}
+ function post_updateItem($history=1) {
+ $ID = $this->getID();
+ $changeParent = in_array($this->getForeignKeyField(), $this->updates);
+ $this->regenerateTreeUnderID($ID, in_array('name', $this->updates),
$changeParent);
+ $this->recursiveCleanSonsAboveID($ID);
+
+ if ($changeParent) {
+ $oldParentID = $this->oldvalues[$this->getForeignKeyField()];
+ $newParentID = $this->fields[$this->getForeignKeyField()];
+ $oldParentNameID = '';
+ $newParentNameID = '';
+
+ $parent = clone $this;
+ if ($oldParentID > 0) {
+ $this->recursiveCleanSonsAboveID($oldParentID);
+ if ($history) {
+ if ($parent->getFromDB($oldParentID)) {
+ $oldParentNameID = $parent->getNameID();
+ }
+ $changes[0] = '0';
+ $changes[1] = addslashes($this->getNameID());
+ $changes[2] = '';
+ Log::history($oldParentID, $this->getType(), $changes,
$this->getType(), HISTORY_DELETE_SUBITEM);
+ }
+ }
+
+ if ($newParentID > 0) {
+ if ($history) {
+ if ($parent->getFromDB($newParentID)) {
+ $newParentNameID = $parent->getNameID();
+ }
+ $changes[0] = '0';
+ $changes[1] = '';
+ $changes[2] = addslashes($this->getNameID());
+ Log::history($newParentID, $this->getType(), $changes,
$this->getType(), HISTORY_ADD_SUBITEM);
+ }
+ }
+
+ if ($history) {
+ $changes[0] = '0';
+ $changes[1] = $oldParentNameID;
+ $changes[2] = $newParentNameID;
+ Log::history($ID, $this->getType(), $changes, $this->getType(),
HISTORY_UPDATE_SUBITEM);
+ }
+
+ }
+ }
+
function post_deleteFromDB() {
$parent = $this->fields[$this->getForeignKeyField()];
_______________________________________________
Glpi-dev mailing list
Glpi-dev@gna.org
https://mail.gna.org/listinfo/glpi-dev