Bonjour à tous, 

Je vous propose, en pièce jointe, le patch qui code les spécifications 
suivantes : 
https://forge.indepnet.net/projects/glpi/wiki/AutomaticTransferForComputer 


Il a été généré en diff de la version courante du trunk de glpi. 


En dehors de ce chantier, j'ai aussi codé l'ajout de l'entité courante de 
l'ordinateur (dans la table glpi_ocslinks) lorsqu'il est importé dans GLPI via 
le mode OCSNG. Ceci étant un manque dans le chantier OCSNGCleanLinks. 


Peut-on voir pour la validation de celles-ci et l'intégration du code qui va 
avec ? 


Bien cordialement, 
François 

-- 
François Legastelois (flegastel...@teclib.com) 
teclib' - Consultant Applications OpenSource - http://www.teclib.com 
tel : 06 84 59 42 62 / 01 79 97 02 78
diff -Naur --exclude='*.svn' --exclude=files --exclude=.DS_Store /Users/francoislegastelois/Sites/glpi_svn/ajax/computer.tabs.php /Users/francoislegastelois/Sites/glpi_proposal_patch/ajax/computer.tabs.php
--- /Users/francoislegastelois/Sites/glpi_svn/ajax/computer.tabs.php	2010-12-20 21:21:38.000000000 +0100
+++ /Users/francoislegastelois/Sites/glpi_proposal_patch/ajax/computer.tabs.php	2010-12-21 10:59:50.000000000 +0100
@@ -145,6 +145,7 @@
             break;
 
          case 13 :
+            OcsLink::showForItem($computer);
             OcsServer::editLock($_POST['target'], $_POST["id"]);
             break;

diff -Naur --exclude='*.svn' --exclude=files --exclude=.DS_Store /Users/francoislegastelois/Sites/glpi_svn/inc/computer.class.php /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/computer.class.php
--- /Users/francoislegastelois/Sites/glpi_svn/inc/computer.class.php	2010-12-21 10:55:38.000000000 +0100
+++ /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/computer.class.php	2010-12-21 11:42:04.000000000 +0100
@@ -1103,6 +1103,13 @@
       $tab[104]['massiveaction'] = false;
       $tab[104]['joinparams']    = array('jointype' => 'child');
 
+      $tab[105]['table']         = 'glpi_ocslinks';
+      $tab[105]['field']         = 'tag';
+      $tab[105]['name']          = $LANG['ocsconfig'][39];
+      $tab[105]['datatype']      = 'string';
+      $tab[105]['massiveaction'] = false;
+      $tab[105]['joinparams']    = array('jointype' => 'child');
+
       $tab['registry'] = $LANG['title'][43];
 
       $tab[110]['table']         = 'glpi_registrykeys';
diff -Naur --exclude='*.svn' --exclude=files --exclude=.DS_Store /Users/francoislegastelois/Sites/glpi_svn/inc/config.class.php /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/config.class.php
--- /Users/francoislegastelois/Sites/glpi_svn/inc/config.class.php	2010-12-21 10:55:38.000000000 +0100
+++ /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/config.class.php	2010-12-21 10:59:21.000000000 +0100
@@ -315,6 +315,19 @@
 
       echo "</table>";
 
+      if (haveRight("transfer","w") && isMultiEntitiesMode()) {
+         echo "<br><table class='tab_cadre_fixe'>";
+         echo "<tr><th colspan='2'>" . $LANG['setup'][290] . "</th></tr>";
+         echo "<tr class='tab_bg_2'>";
+         echo "<td>" . $LANG['setup'][291] . "&nbsp;:</td><td>";
+         Dropdown::show('Transfer',
+                           array('value' => $CFG_GLPI["transfers_id_auto"],
+                                 'name'  => "transfers_id_auto",
+                                 'emptylabel'=> $LANG['setup'][292]));
+         echo "</td></td></tr>";
+         echo "</table>";
+      }
+
       echo "<br><table class='tab_cadre_fixe'>";
       echo "<tr><th colspan='6'>".$LANG['setup'][280]." (".$LANG['peripherals'][32].")</th></tr>";
 
diff -Naur --exclude='*.svn' --exclude=files --exclude=.DS_Store /Users/francoislegastelois/Sites/glpi_svn/inc/ocslink.class.php /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/ocslink.class.php
--- /Users/francoislegastelois/Sites/glpi_svn/inc/ocslink.class.php	2010-12-20 21:22:11.000000000 +0100
+++ /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/ocslink.class.php	2010-12-21 10:57:31.000000000 +0100
@@ -56,6 +56,38 @@
       return haveRight('ocsng', 'r');
    }
 
+   /**
+   * Show OcsLink of an item
+   *
+   * @param $item CommonDBTM object
+   *
+   * @return nothing
+   **/
+   static function showForItem(CommonDBTM $item) {
+      global $DB,$LANG;
+
+      if (in_array($item->getType(),array('Computer'))) {
+         $items_id = $item->getField('id');
+
+         $query = "SELECT `glpi_ocslinks`.`tag` AS tag
+                     FROM `glpi_ocslinks`
+                     WHERE `glpi_ocslinks`.`computers_id` = '$items_id'"
+                     .getEntitiesRestrictRequest("AND","glpi_ocslinks");
+
+         $result = $DB->query($query);
+         if ($DB->numrows($result) > 0) {
+            $data = $DB->fetch_assoc($result);
+            $data = clean_cross_side_scripting_deep(addslashes_deep($data));
+
+            echo "<div class='center'>";
+            echo "<table class='tab_cadre_fixe'>";
+            echo "<tr><th>" . $LANG['ocsng'][0] . "</th>";
+            echo "<tr class='tab_bg_2'>";
+            echo "<td class='center'>" . $LANG['ocsconfig'][39] . "&nbsp;: " . $data['tag'] . "</td></tr>";
+         }
+      }
+
+   }
 
 }
 
diff -Naur --exclude='*.svn' --exclude=files --exclude=.DS_Store /Users/francoislegastelois/Sites/glpi_svn/inc/ocsserver.class.php /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/ocsserver.class.php
--- /Users/francoislegastelois/Sites/glpi_svn/inc/ocsserver.class.php	2010-12-21 10:55:38.000000000 +0100
+++ /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/ocsserver.class.php	2010-12-21 16:32:38.000000000 +0100
@@ -922,6 +922,10 @@
    static function ocsLink($ocsid, $ocsservers_id, $glpi_computers_id) {
       global $DB, $DBocs;
 
+      // Retrieve informations from computer
+      $comp = new Computer;
+      $comp->getFromDB($glpi_computers_id);
+
       OcsServer::checkOCSconnection($ocsservers_id);
 
       // Need to get device id due to ocs bug on duplicates
@@ -932,9 +936,11 @@
       $data = $DBocs->fetch_array($result_ocs);
 
       $query = "INSERT INTO `glpi_ocslinks`
-                       (`computers_id`, `ocsid`, `ocs_deviceid`, `last_update`, `ocsservers_id`)
+                       (`computers_id`, `ocsid`, `ocs_deviceid`, 
+                        `last_update`, `ocsservers_id`, `entities_id`)
                 VALUES ('$glpi_computers_id','$ocsid','" . $data["DEVICEID"] . "','" .
-                        $_SESSION["glpi_currenttime"] . "','$ocsservers_id')";
+                        $_SESSION["glpi_currenttime"] . "','$ocsservers_id','" . 
+                        $comp->fields['entities_id'] . "')";
       $result = $DB->query($query);
 
       if ($result) {
@@ -1563,6 +1569,12 @@
          }
          if ($DBocs->numrows($result_ocs) == 1) {
             $data_ocs = addslashes_deep($DBocs->fetch_array($result_ocs));
+
+            // automatic transfer computer 
+            if ($CFG_GLPI['transfers_id_auto']>0 AND isMultiEntitiesMode()) {
+               OcsServer::transferComputer($line,$data_ocs);
+            }
+
             // update last_update and and last_ocs_update
             $query = "UPDATE `glpi_ocslinks`
                       SET `last_update` = '" . $_SESSION["glpi_currenttime"] . "',
@@ -1884,6 +1896,172 @@
       }
    }
 
+   /**
+   * Do automatic transfer if option is enable
+   *...@param $line_links array : data from glpi_ocslinks table
+   *...@param $line_ocs array : data from ocs tables
+   *
+   *...@return nothing
+   */
+   static function transferComputer($line_links,$line_ocs) {
+      global $DB, $DBocs, $CFG_GLPI;
+
+      // Update TAG information in glpi_ocslinks
+      if (empty($line_links["tag"])) {
+         $line_links["tag"]=OcsServer::updateTag($line_links,$line_ocs);
+      }
+
+      // Get all rules for the current ocsservers_id
+      $rules = new RuleOcsCollection($line_links["ocsservers_id"]);
+      $rules->getCollectionDatas(1,1);
+
+      // Check actives critieria
+      $criteria_in_used = array();
+      foreach ($rules->RuleList->list as $rule) {
+         if ($rule->fields["is_active"]) {
+            foreach($rule->criterias as $criteria) {	
+               if(!in_array($criteria->fields["criteria"],$criteria_in_used)) {
+                  $criteria_in_used[$criteria->fields["criteria"]]=1;
+               }
+            }
+         }
+      }
+
+      // Retrieve OCS and GLPI datas
+      $ocsdatas = $rules->prepareInputDataForProcess('',$line_links['ocsid']);
+
+      $comp = new Computer;
+      $comp->getFromDB($line_links['computers_id']);
+
+      // Check if one criteria change
+      $criteria_is_updated = false;
+      foreach ($criteria_in_used as $criteria => $active) {
+	
+         // Retrieve current value for criteria
+         switch (utf8_strtoupper($criteria)) {
+            case 'TAG':
+               $current = $line_links["tag"];
+               break;
+            case 'DOMAIN':
+               $domains_id = $comp->fields["domains_id"];
+               $current = Dropdown::getDropdownName('glpi_domains',$domains_id);
+               break;
+            case 'OCS_SERVER':
+               $current = $line_links["ocsservers_id"];
+               break;
+            case 'IPSUBNET':
+               $query_IP = "SELECT GROUP_CONCAT(DISTINCT `glpi_networkports`.`subnet` 
+	                                 SEPARATOR '$$$$') as IPSUBNET
+                         FROM `glpi_networkports`
+                         WHERE `items_id` = '" . $comp->fields['id'] . "'
+                         AND `itemtype` = 'Computer'";
+               $result_IP = $DB->query($query_IP);
+               $data_IP = addslashes_deep($DBocs->fetch_array($result_IP));
+               $current = $data_IP["IPSUBNET"];
+               break;
+            case 'IPADDRESS':
+               $query_IP = "SELECT GROUP_CONCAT(DISTINCT `glpi_networkports`.`ip` 
+	                                 SEPARATOR '$$$$') as IPADDRESS
+                         FROM `glpi_networkports`
+                         WHERE `items_id` = '" . $comp->fields['id'] . "'
+                         AND `itemtype` = 'Computer'";
+               $result_IP = $DB->query($query_IP);
+               $data_IP = addslashes_deep($DBocs->fetch_array($result_IP));
+               $current = $data_IP["IPADDRESS"];
+               break;
+            case 'MACHINE_NAME':
+               $current = $comp->fields["name"];
+               break;
+            case 'DESCRIPTION':
+               $current = $comp->fields["comment"];
+               break;
+            case 'SSN':
+               $current = $comp->fields["serial"];
+               break;
+         }
+
+         // Retrieve new value for criteria
+         switch (utf8_strtoupper($criteria)) {
+            case 'OCS_SERVER':
+               $new = $ocsdatas[$criteria];
+               break;
+            case 'IPSUBNET':
+            case 'IPADDRESS':
+               $new = implode("$$$$",$ocsdatas[$criteria]);
+               break;
+            case 'DESCRIPTION':
+               $new = $ocsdatas[$criteria][0]."\r\n";
+               $new .= "Swap: " . $line_ocs["SWAP"];
+               break;
+            default:
+               $new = $ocsdatas[$criteria][0];
+         }
+
+         $current = stripslashes(trim($current));
+         $new = stripslashes(trim($new));
+
+         $current = utf8_strtolower($current);
+         $new = utf8_strtolower($new);
+
+         if($new != $current) {
+            $criteria_is_updated = true;
+         }
+      }
+
+      // If we have at least one criteria on update, we process allrules again
+      // And we move items (computer) to the new entities_id
+      if ($criteria_is_updated) {
+         $data = array();
+         $data = $rules->processAllRules(array(), array(), $line_links["ocsid"]);
+
+         if ($data['entities_id']!=$line_links['entities_id']) {
+            if (!haveAccessToEntity($data['entities_id'])) {
+               displayRightError();
+            }
+            $transfer = new Transfer;
+            $transfer->getFromDB($CFG_GLPI['transfers_id_auto']);
+
+            $item_to_transfer = array("Computer"=>
+                                       array($line_links['computers_id']=>$line_links['computers_id']));
+
+            $transfer->moveItems($item_to_transfer,$data['entities_id'],$transfer->fields);
+         }
+      }
+   }
+
+   /**
+   * Update TAG information in glpi_ocslinks table
+   *...@param $line_links array : data from glpi_ocslinks table
+   *...@param $line_ocs array : data from ocs tables
+   *
+   *...@return string : current tag of computer on update
+   */
+   static function updateTag($line_links,$line_ocs) {
+      global $DB, $DBocs;
+
+      $query_ocs = "SELECT `accountinfo`.`TAG` as TAG
+                        FROM `hardware`
+                        INNER JOIN `accountinfo` 
+                           ON (`hardware`.`ID` = `accountinfo`.`HARDWARE_ID`)
+                        WHERE `hardware`.`ID` = '" . $line_links["ocsid"] . "'";
+
+      $result_ocs = $DBocs->query($query_ocs);
+
+      if ($DBocs->numrows($result_ocs) == 1) {
+         $data_ocs = addslashes_deep($DBocs->fetch_array($result_ocs));
+
+         $query = "UPDATE `glpi_ocslinks`
+                   SET `tag` = '" . $data_ocs["TAG"] . "'
+                   WHERE `id` = '" . $line_links["id"] . "'";
+         if ($DB->query($query)) {
+            $changes[0] = '0';
+            $changes[1] = $line_links["tag"];
+            $changes[2] = $data_ocs["TAG"];
+            Log::history($line_links["id"], 'Ocslink', $changes, 0, HISTORY_OCS_LINK);
+            return $data_ocs["TAG"];
+         }
+      }
+   }
 
    /**
     * Import a group from OCS table.
@@ -2661,19 +2839,18 @@
       if ($DB->numrows($result) == 1) {
          $data = $DB->fetch_assoc($result);
          if (haveRight("sync_ocsng","w")) {
-            echo "\n<div class='center'>";
+            echo "<tr class='tab_bg_1'><td class='center'>";
             echo "<form method='post' action=\"$target\">";
             echo "<input type='hidden' name='id' value='$ID'>";
-            echo "<table class='tab_cadre_fixe'>";
-            echo "<tr><th>".$LANG['ocsng'][0]."</th></tr>";
-            echo "<tr class='tab_bg_1'><td class='center'>";
             echo "<input type='hidden' name='resynch_id' value='" . $data["id"] . "'>";
             echo "<input class=submit type='submit' name='force_ocs_resynch' value='" .
                    $LANG['ocsng'][24] . "'>";
-            echo "</td><tr></table>";
-            echo "</form></div>\n";
+            echo "</form>\n";
+            echo "</td><tr>";
          }
 
+         echo "</table></div>";
+
          $header = false;
          echo "<div width='50%'>";
          echo "<form method='post' action=\"$target\">";
diff -Naur --exclude='*.svn' --exclude=files --exclude=.DS_Store /Users/francoislegastelois/Sites/glpi_svn/install/mysql/glpi-0.80-empty.sql /Users/francoislegastelois/Sites/glpi_proposal_patch/install/mysql/glpi-0.80-empty.sql
--- /Users/francoislegastelois/Sites/glpi_svn/install/mysql/glpi-0.80-empty.sql	2010-12-21 10:55:37.000000000 +0100
+++ /Users/francoislegastelois/Sites/glpi_proposal_patch/install/mysql/glpi-0.80-empty.sql	2010-12-21 11:02:20.000000000 +0100
@@ -734,10 +734,11 @@
   `use_slave_for_search` tinyint(1) NOT NULL DEFAULT '0',
   `proxy_passwd` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
   `smtp_passwd` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  `transfers_id_auto` int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
-INSERT INTO `glpi_configs` VALUES(1, 0, 250, 15, 50, 30, ' 0.80', 5, 0, 'adm...@xxxxx.fr', NULL, NULL, NULL, 'SIGNATURE', 0, 'fr_FR', '#fff2f2', '#ffe0e0', '#ffcece', '#ffbfbf', '#ffadad', '#ff5555', '2005-12-31', 10, '', 443, '', NULL, 1, NULL, 0, '08:00:00', '20:00:00', 1, 0, 0, 'http://localhost/glpi/', 0, '', '', 100, '*', 0, 50, 1, 1, 0, 0, ';', 0, 50, 0, 0, NULL, 25, NULL, NULL, 8080, NULL, 1, 0, 0, 0, 0, 0, 0, 5, 2, NULL, NULL, 0, 2, 2, 2, 2, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, NULL, 0, 1, 0, 2097152, 0, 0, 1, 0, 'svg', 1, 1, 1, '{"1":{"1":1,"2":1,"3":2,"4":2,"5":2},"2":{"1":1,"2":2,"3":2,"4":3,"5":3},"3":{"1":2,"2":2,"3":3,"4":4,"5":4},"4":{"1":2,"2":3,"3":4,"4":4,"5":5},"5":{"1":2,"2":3,"3":4,"4":5,"5":5}}', 62, 62, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL);
+INSERT INTO `glpi_configs` VALUES(1, 0, 250, 15, 50, 30, ' 0.80', 5, 0, 'adm...@xxxxx.fr', NULL, NULL, NULL, 'SIGNATURE', 0, 'fr_FR', '#fff2f2', '#ffe0e0', '#ffcece', '#ffbfbf', '#ffadad', '#ff5555', '2005-12-31', 10, '', 443, '', NULL, 1, NULL, 0, '08:00:00', '20:00:00', 1, 0, 0, 'http://localhost/glpi/', 0, '', '', 100, '*', 0, 50, 1, 1, 0, 0, ';', 0, 50, 0, 0, NULL, 25, NULL, NULL, 8080, NULL, 1, 0, 0, 0, 0, 0, 0, 5, 2, NULL, NULL, 0, 2, 2, 2, 2, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, NULL, 0, 1, 0, 2097152, 0, 0, 1, 0, 'svg', 1, 1, 1, '{"1":{"1":1,"2":1,"3":2,"4":2,"5":2},"2":{"1":1,"2":2,"3":2,"4":3,"5":3},"3":{"1":2,"2":2,"3":3,"4":4,"5":4},"4":{"1":2,"2":3,"3":4,"4":4,"5":5},"5":{"1":2,"2":3,"3":4,"4":5,"5":5}}', 62, 62, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL,0);
 
 ### Dump table glpi_consumableitems

@@ -2730,6 +2731,7 @@
   `import_ip` longtext COLLATE utf8_unicode_ci,
   `ocs_agent_version` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
   `entities_id` int(11) NOT NULL DEFAULT '0',
+  `tag` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `unicity` (`ocsservers_id`,`ocsid`),
   KEY `last_update` (`last_update`),
diff -Naur --exclude='*.svn' --exclude=files --exclude=.DS_Store /Users/francoislegastelois/Sites/glpi_svn/install/update_0781_080.php /Users/francoislegastelois/Sites/glpi_proposal_patch/install/update_0781_080.php
--- /Users/francoislegastelois/Sites/glpi_svn/install/update_0781_080.php	2010-12-21 10:55:37.000000000 +0100
+++ /Users/francoislegastelois/Sites/glpi_proposal_patch/install/update_0781_080.php	2010-12-21 16:29:30.000000000 +0100
@@ -1310,6 +1310,13 @@
    }
    /* END - OCS-NG new clean links features */
 
+   /* New automatic transfert feature */
+   $migration->addField('glpi_configs', 'transfers_id_auto',
+                        'int(11) NOT NULL DEFAULT \'0\'');
+
+   $migration->addField('glpi_ocslinks','tag',
+                        'varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL');
+   /* END - New automatic transfert feature */
 
    $migration->displayMessage($LANG['update'][142] . ' - glpi_displaypreferences');
 
diff -Naur --exclude='*.svn' --exclude=files --exclude=.DS_Store /Users/francoislegastelois/Sites/glpi_svn/locales/fr_FR.php /Users/francoislegastelois/Sites/glpi_proposal_patch/locales/fr_FR.php
--- /Users/francoislegastelois/Sites/glpi_svn/locales/fr_FR.php	2010-12-21 10:55:37.000000000 +0100
+++ /Users/francoislegastelois/Sites/glpi_proposal_patch/locales/fr_FR.php	2010-12-21 11:00:48.000000000 +0100
@@ -2103,6 +2103,10 @@
 $LANG['setup'][285] = "Ne pas copier";
 $LANG['setup'][286] = "Ne pas effacer";
 
+$LANG['setup'][290] = "Transfert automatique d'ordinateur";
+$LANG['setup'][291] = "Modèle pour le transfert automatique d'ordinateur dans une autre entité";
+$LANG['setup'][292] = "Pas de transfert automatique";
+
 $LANG['setup'][300] = "Vérifier si une nouvelle version est disponible";
 $LANG['setup'][301] = "Une nouvelle version est disponible :";
 $LANG['setup'][302] = "Vous la trouverez sur le site GLPI-PROJECT.org";
_______________________________________________
Glpi-dev mailing list
Glpi-dev@gna.org
https://mail.gna.org/listinfo/glpi-dev

Reply via email to