Bonjour à tous,
Je vous propose, en pièce jointe, le patch qui code les spécifications suivantes : https://forge.indepnet.net/projects/glpi/wiki/OCSNGCleanLinks Il a été généré en diff de la version courante du trunk de glpi. 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/front/ocsng.clean.php /Users/francoislegastelois/Sites/glpi_proposal_patch/front/ocsng.clean.php --- /Users/francoislegastelois/Sites/glpi_svn/front/ocsng.clean.php 2010-12-08 18:11:51.000000000 +0100 +++ /Users/francoislegastelois/Sites/glpi_proposal_patch/front/ocsng.clean.php 2010-12-14 11:38:35.000000000 +0100 @@ -40,12 +40,25 @@ commonHeader($LANG['ocsng'][0],$_SERVER['PHP_SELF'],"utils","ocsng"); -OcsServer::cleanLinks($_SESSION["ocsservers_id"]); +if (!isset($_POST["clean_ok"])) { + if (!isset($_GET['check'])) { + $_GET['check'] = 'all'; + } + if (!isset($_GET['start'])) { + $_GET['start'] = 0; + } + OcsServer::manageDeleted($_SESSION["ocsservers_id"]); + OcsServer::showComputersToClean($_SESSION["ocsservers_id"],$_GET['check'],$_GET['start']); -echo "<div class='center b'>".$LANG['ocsng'][3]." - ".$LANG['log'][45]."<br>"; -displayBackLink(); -echo "</div>"; +} else { + if (count($_POST['toclean']) >0) { + OcsServer::cleanLinksFromList($_POST['toclean']); + echo "<div class='center b'>".$LANG['ocsng'][3]." - ".$LANG['log'][45]."<br>"; + displayBackLink(); + echo "</div>"; + } +} commonFooter(); -?> +?> \ No newline at end of file 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-08 18:12:04.000000000 +0100 +++ /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/computer.class.php 2010-12-14 10:36:21.000000000 +0100 @@ -44,7 +44,7 @@ // From CommonDBTM public $dohistory = true; - protected $forward_entity_to = array('Infocom', 'ComputerDisk', 'ReservationItem', 'NetworkPort'); + protected $forward_entity_to = array('Infocom', 'ComputerDisk', 'ReservationItem', 'NetworkPort','Ocslink'); // Specific ones ///Device container - format $device = array(ID,"device type","ID in device table","specificity value") var $devices = array(); 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-08 18:12:04.000000000 +0100 +++ /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/ocsserver.class.php 2010-12-14 11:39:32.000000000 +0100 @@ -1918,30 +1918,26 @@ } } - - static function cleanLinks($ocsservers_id) { - global $DB, $DBocs; + /** + * Displays a list of computers that can be cleaned. + * + *...@param $ocsservers_id int : id of ocs server in GLPI + *...@param $check string : parameter for HTML input checkbox + *...@param $start int : parameter for printPager method + * + *...@return nothing + */ + static function showComputersToClean($ocsservers_id, $check, $start) { + global $DB, $DBocs, $LANG, $CFG_GLPI; OcsServer::checkOCSconnection($ocsservers_id); - OcsServer::manageDeleted($ocsservers_id); - - // Delete unexisting GLPI computers - $query = "SELECT `glpi_ocslinks`.`id` - FROM `glpi_ocslinks` - LEFT JOIN `glpi_computers` ON `glpi_computers`.`id`=`glpi_ocslinks`.`computers_id` - WHERE `glpi_computers`.`id` IS NULL - AND `ocsservers_id` = '$ocsservers_id'"; - $result = $DB->query($query); - if ($DB->numrows($result) > 0) { - while ($data = $DB->fetch_array($result)) { - $query2 = "DELETE - FROM `glpi_ocslinks` - WHERE `id` = '" . $data['id'] . "'"; - $DB->query($query2); - } + if (!haveRight("clean_ocsng", "w") + AND !haveRight("clean_ocsng", "r")) { + return false; } - // Delete unexisting OCS hardware + + // Select unexisting OCS hardware $query_ocs = "SELECT * FROM `hardware`"; $result_ocs = $DBocs->query($query_ocs); @@ -1958,21 +1954,153 @@ WHERE `ocsservers_id` = '$ocsservers_id'"; $result = $DB->query($query); + $links_ocs_missing_str = ""; if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_array($result)) { $data = clean_cross_side_scripting_deep(addslashes_deep($data)); if (!isset ($hardware[$data["ocsid"]])) { - $query_del = "DELETE - FROM `glpi_ocslinks` - WHERE `id` = '" . $data["id"] . "'"; - $DB->query($query_del); - $comp = new Computer(); - $comp->delete( array("id" => $data["computers_id"]), 0); + $links_ocs_missing_str .= "'" . $data["ocsid"] . "', "; + } + } + } + + $sql_ocs_missing = ""; + if ($links_ocs_missing_str != null) { + $links_ocs_missing_str = substr($links_ocs_missing_str, 0, -2); + $sql_ocs_missing =" OR `ocsid` IN (". $links_ocs_missing_str .")"; + } + + //Select unexisting computers + $query_glpi = "SELECT `glpi_ocslinks`.`entities_id` AS entities_id, + `glpi_ocslinks`.`ocs_deviceid` AS ocs_deviceid, + `glpi_ocslinks`.`last_update` AS last_update, + `glpi_ocslinks`.`ocsid` AS ocsid, + `glpi_ocslinks`.`id`, + `glpi_computers`.`name` AS name + FROM `glpi_ocslinks` + LEFT JOIN `glpi_computers` ON `glpi_computers`.`id`=`glpi_ocslinks`.`computers_id` + WHERE (`glpi_computers`.`id` IS NULL AND `ocsservers_id`='$ocsservers_id')" + .$sql_ocs_missing + .getEntitiesRestrictRequest("AND","glpi_ocslinks"); + + $result_glpi = $DB->query($query_glpi); + + // fetch all links missing between glpi and OCS + $already_linked = array (); + if ($DB->numrows($result_glpi) > 0) { + while ($data = $DB->fetch_assoc($result_glpi)) { + + $data = clean_cross_side_scripting_deep(addslashes_deep($data)); + + $already_linked[$data["ocsid"]]["entities_id"] = $data["entities_id"]; + $already_linked[$data["ocsid"]]["ocs_deviceid"] = substr($data["ocs_deviceid"], 0, + strpos($data["ocs_deviceid"], + '-')); + $already_linked[$data["ocsid"]]["date"] = $data["last_update"]; + $already_linked[$data["ocsid"]]["id"] = $data["id"]; + if (trim($data["name"]) == null) { + $already_linked[$data["ocsid"]]["in_glpi"] = 0; + $already_linked[$data["ocsid"]]["in_ocs"] = 1; + } else { + $already_linked[$data["ocsid"]]["in_glpi"] = 1; + $already_linked[$data["ocsid"]]["in_ocs"] = 0; + } + } + } + + + echo "<div class='center'>"; + echo "<h2>" . $LANG['ocsng'][3] . "</h2>"; + + $target=$CFG_GLPI['root_doc'].'/front/ocsng.clean.php'; + if (($numrows = count($already_linked)) > 0) { + $parameters = "check=$check"; + printPager($start, $numrows, $target, $parameters); + + // delete end + array_splice($already_linked, $start + $_SESSION['glpilist_limit']); + // delete begin + if ($start > 0) { + array_splice($already_linked, 0, $start); + } + + echo "<form method='post' id='ocsng_form' name='ocsng_form' action='".$target."'>"; + + if (haveRight("clean_ocsng", "w")) { + echo "<a href='".$target."?check=all' ". + "onclick= \"if (markCheckboxes('ocsng_form')) return false;\">" . + $LANG['buttons'][18] . "</a> / \n"; + echo "<a href='".$target."?check=none' ". + "onclick= \"if ( unMarkCheckboxes('ocsng_form') ) return false;\">" . + $LANG['buttons'][19] . "</a>\n"; + } + echo "<table class='tab_cadre'>"; + echo "<tr><th>" . $LANG['common'][1] . "</th><th>" . $LANG['ocsng'][13] . "</th>"; + echo "<th>" . $LANG['ocsng'][59] . "</th><th>" . $LANG['ocsng'][60] . "</th>"; + if (isMultiEntitiesMode()) { + echo "<th>" . $LANG['entity'][0] . "</th>"; + } + if (haveRight("clean_ocsng", "w")) { + echo "<th> </th></tr>\n"; + } + + echo "<tr class='tab_bg_1'><td colspan='6' class='center'>"; + if (haveRight("clean_ocsng", "w")) { + echo "<input class='submit' type='submit' name='clean_ok' value='" .$LANG['buttons'][53]. "'>"; + } + echo "</td></tr>\n"; + + foreach ($already_linked as $ID => $tab) { + echo "<tr class='tab_bg_2 center'>"; + echo "<td>" . $tab["ocs_deviceid"] . "</td>\n"; + echo "<td>" . convDateTime($tab["date"]) . "</td>\n"; + echo "<td>" . $LANG['choice'][$tab["in_glpi"]] . "</td>\n"; + echo "<td>" . $LANG['choice'][$tab["in_ocs"]] . "</td>\n"; + if(isMultiEntitiesMode()) { + echo "<td>"; + echo Dropdown::getDropdownName('glpi_entities',$tab['entities_id']); + echo "</td>\n"; + } + if (haveRight("clean_ocsng", "w")) { + echo "<td><input type='checkbox' name='toclean[" . $tab["id"] . "]' " . + ($check == "all" ? "checked" : "") . "></td></tr>\n"; } } + echo "<tr class='tab_bg_1'><td colspan='6' class='center'>"; + if (haveRight("clean_ocsng", "w")) { + echo "<input class='submit' type='submit' name='clean_ok' value='".$LANG['buttons'][53]."'>"; + } + echo "</td></tr>"; + echo "</table></form>\n"; + printPager($start, $numrows, $target, $parameters); + } else { + echo "<div class='center'><strong>" . $LANG['ocsng'][61] . "</strong></div>"; + displayBackLink(); } + echo "</div>"; } + /** + * Clean links between GLPI and OCS from a list. + * + *...@param $computers_id array : ids of computers to be cleaned + * + *...@return nothing + */ + static function cleanLinksFromList($computers_id) { + global $DB; + + if (!haveRight("clean_ocsng", "w")) { + return false; + } + + foreach ($computers_id as $key => $val) { + $query = "DELETE + FROM `glpi_ocslinks` + WHERE `id` = '" . $key . "'"; + $DB->query($query); + } + } static function showComputersToUpdate($ocsservers_id, $check, $start) { global $DB, $DBocs, $LANG, $CFG_GLPI; diff -Naur --exclude='*.svn' --exclude=files --exclude=.DS_Store /Users/francoislegastelois/Sites/glpi_svn/inc/profile.class.php /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/profile.class.php --- /Users/francoislegastelois/Sites/glpi_svn/inc/profile.class.php 2010-12-14 10:31:51.000000000 +0100 +++ /Users/francoislegastelois/Sites/glpi_proposal_patch/inc/profile.class.php 2010-12-14 11:36:21.000000000 +0100 @@ -635,6 +635,12 @@ Profile::dropdownNoneReadWrite("view_ocsng", $this->fields["view_ocsng"], 1, 1, 0); echo "</td></tr>\n"; + echo "<tr class='tab_bg_2'>"; + echo "<td>".$LANG['ocsng'][3]." :</td><td>"; + Profile::dropdownNoneReadWrite("clean_ocsng", $this->fields["clean_ocsng"], 1, 1, 1); + echo "</td><td colspan='4' />"; + echo "</td></tr>\n"; + if ($canedit && $closeform) { echo "<tr class='tab_bg_1'>"; echo "<td colspan='6' class='center'>"; 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-08 18:11:53.000000000 +0100 +++ /Users/francoislegastelois/Sites/glpi_proposal_patch/install/mysql/glpi-0.80-empty.sql 2010-12-14 11:22:42.000000000 +0100 @@ -2711,6 +2711,7 @@ `ocsservers_id` int(11) NOT NULL DEFAULT '0', `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', PRIMARY KEY (`id`), UNIQUE KEY `unicity` (`ocsservers_id`,`ocsid`), KEY `last_update` (`last_update`), @@ -3168,16 +3169,17 @@ `calendar` char(1) COLLATE utf8_unicode_ci DEFAULT NULL, `sla` char(1) COLLATE utf8_unicode_ci DEFAULT NULL, `rule_dictionnary_printer` char(1) COLLATE utf8_unicode_ci DEFAULT NULL, + `clean_ocsng` char(1) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `interface` (`interface`), KEY `is_default` (`is_default`), 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,NULL,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); -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); -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); -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',NULL); +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,NULL,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); +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); +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'); +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',NULL,'w'); ### Dump table glpi_profiles_users 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-08 18:11:53.000000000 +0100 +++ /Users/francoislegastelois/Sites/glpi_proposal_patch/install/update_0781_080.php 2010-12-14 11:22:31.000000000 +0100 @@ -1117,6 +1117,27 @@ } } + /* OCS-NG new clean links features */ + if ($migration->addField('glpi_ocslinks', 'entities_id','int(11) NOT NULL DEFAULT \'0\'')) { + $migration->migrationOneTable("glpi_ocslinks"); + + $query = "UPDATE `glpi_ocslinks` + SET `entities_id` = '0'"; + + $DB->query($query) + or die("0.80 set entities_id to root entity in glpi_ocslinks " . $LANG['update'][90] . $DB->error()); + } + + if ($migration->addField('glpi_profiles', 'clean_ocsng','char(1) COLLATE utf8_unicode_ci DEFAULT NULL')) { + $migration->migrationOneTable("glpi_profiles"); + + $query = "UPDATE `glpi_profiles` + SET `clean_ocsng` = `sync_ocsng`"; + + $DB->query($query) + or die("0.80 copy sync_ocsng to clean_ocsng in glpi_ocslinks " . $LANG['update'][90] . $DB->error()); + } + /* END - OCS-NG new clean links features */ $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-14 10:31:50.000000000 +0100 +++ /Users/francoislegastelois/Sites/glpi_proposal_patch/locales/fr_FR.php 2010-12-14 10:34:54.000000000 +0100 @@ -1477,6 +1477,9 @@ $LANG['ocsng'][57] = "Interface OCSNG"; $LANG['ocsng'][58] = "Liaison OCSNG"; +$LANG['ocsng'][59] = "Présent dans GLPI"; +$LANG['ocsng'][60] = "Présent dans OCS"; +$LANG['ocsng'][61] = "Aucun objet à nettoyer."; $LANG['pager'][1] = "à "; $LANG['pager'][2] = "de";
_______________________________________________ Glpi-dev mailing list Glpi-dev@gna.org https://mail.gna.org/listinfo/glpi-dev