Skip to content

Instantly share code, notes, and snippets.

@guilhem
Created July 26, 2011 13:59
Show Gist options
  • Save guilhem/1106825 to your computer and use it in GitHub Desktop.
Save guilhem/1106825 to your computer and use it in GitHub Desktop.
Big patch to plugin imp
diff -urB -x .svn branches/forge/trunk//hook.php trunk//hook.php
--- branches/forge/trunk//hook.php 2011-07-07 10:41:20.765282080 +0200
+++ trunk//hook.php 2011-07-07 10:41:20.755282080 +0200
@@ -58,7 +58,10 @@
"`update_computer_type` bool NOT NULL DEFAULT 1, ".
"`update_software_name` bool NOT NULL DEFAULT 1, ".
"`update_software_category` bool NOT NULL DEFAULT 1, ".
- " PRIMARY KEY (`ID`)) ENGINE=MyISAM DEFAULT CHARSET=utf8";
+ "`flat_entities` bool NOT NULL DEFAULT 0, ".
+ "`recursive` bool NOT NULL DEFAULT 1, ".
+ " PRIMARY KEY (`ID`)
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8";
$DB->query($Sql) or die($DB->error());
diff -urB -x .svn branches/forge/trunk//inc/plugin_imp_config.class.php trunk//inc/plugin_imp_config.class.php
--- branches/forge/trunk//inc/plugin_imp_config.class.php 2011-07-07 10:41:20.765282080 +0200
+++ trunk//inc/plugin_imp_config.class.php 2011-07-07 10:41:20.755282080 +0200
@@ -1,36 +1,36 @@
<?php
/*
- ----------------------------------------------------------------------
- GLPI - Gestionnaire Libre de Parc Informatique
- Copyright (C) 2003-2009 by the INDEPNET Development Team.
-
- http://indepnet.net/ http://glpi-project.org/
- ----------------------------------------------------------------------
-
- LICENSE
-
- This file is part of GLPI.
-
- GLPI is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- GLPI is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GLPI; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- ------------------------------------------------------------------------
- */
+ ----------------------------------------------------------------------
+GLPI - Gestionnaire Libre de Parc Informatique
+Copyright (C) 2003-2009 by the INDEPNET Development Team.
+
+http://indepnet.net/ http://glpi-project.org/
+----------------------------------------------------------------------
+
+LICENSE
+
+This file is part of GLPI.
+
+GLPI is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GLPI is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GLPI; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+------------------------------------------------------------------------
+*/
// ----------------------------------------------------------------------
// Sponsor: Carrefour
// Original Author: Yanick Durant
-// Contact:
+// Contact:
// Project Website: http://yanick.info
// Purpose of file:
// ----------------------------------------------------------------------
@@ -38,305 +38,313 @@
if (!defined('GLPI_ROOT')){
die("Sorry. You can't access directly to this file");
- }
+}
include (GLPI_ROOT . "/plugins/imp/inc/plugin_imp.run.php");
class ImpConfig extends CommonDBTM{
- var $baseurl;
+ var $baseurl;
+
+ function __construct() {
- function __construct() {
+ $this->table="glpi_plugin_imp_config";
+ $this->type=-1;
+ $this->baseurl="plugins/dumpentity/front";
+ }
- $this->table="glpi_plugin_imp_config";
- $this->type=-1;
- $this->baseurl="plugins/dumpentity/front";
- }
-
- function showStatus($ID) {
- global $LANG,$DB;
-
- if ($this->getFromDB($ID)) {
- echo "<table class='tab_cadre' cellpadding='5'>";
-
- echo "<tr><th colspan='3' align='center'>".$LANG['plugin_imp']['setup'][6]."</th></tr>";
-
- $response = ImpPreliminaryNegociation($this);
-
- if (!$response) {
- echo "<tr class='tab_bg_1'><td align='center' colspan='3'><strong>" .$LANG['plugin_imp']['setup'][11]."</strong></td></tr>";
- echo "</table>";
- return false;
- }
- else {
- echo "<td colspan='3' align='center' class='tab_bg_4'>" .$LANG['plugin_imp']['setup'][9]. "&nbsp;:&nbsp;";
- if (empty($this->fields["user"]))
- echo $LANG['plugin_imp']['setup'][10]. "</td>";
- else
- echo convDateTime($this->fields["date_sync"])." (".$this->fields["user"]. ")</td>";
-
- $tables=ImpGetTables($this);
- if (count($tables)) {
- echo "<tr class='tab_bg_5'><td align='center' colspan='3'>" .$LANG['plugin_imp']['setup'][8]."</td></tr>";
- $i=0;
- foreach ($tables as $nom => $desc) {
- if ($i%3==0) echo "<tr class='tab_bg_1'>";
-
- echo "<td>". $desc . "</td>";
-
- if ($i%3==2) echo "</tr>\n";
- $i++;
- }
- if ($i%3==1) echo "<td>&nbsp;</td><td>&nbsp;</td></tr>\n";
- if ($i%3==2) echo "<td>&nbsp;</td></tr>\n";
- } else {
- echo "<tr class='tab_bg_4'><td align='center' colspan='3'><strong>" .$LANG['plugin_imp']['setup'][7]."</strong></td></tr>";
- }
- echo "</table>";
- return true;
- }
- }
- else return false;
- }
- function showFormEdit(){
- global $LANG,$DB;
-
- if (!haveRight("config","r")) {
- return false;
- }
- $canedit=haveRight("config","w");
-
-// if ($this->getFromDB(1)) {
-// $ID=$this->fields["ID"];
-// }
-// else {
-// $ID=0;
-// }
+ function showStatus($ID) {
+ global $LANG,$DB;
- $data = $this->find();
+ if ($this->getFromDB($ID)) {
+ echo "<table class='tab_cadre' cellpadding='5'>";
- echo "<div align='center'>";
+ echo "<tr><th colspan='3' align='center'>".$LANG['plugin_imp']['setup'][6]."</th></tr>";
- echo "<table class='tab_cadre' cellpadding='5'>";
- echo "<tr><th colspan='2' align='center'>".$LANG['plugin_imp']['setup'][2]."</th></tr>";
+ $response = ImpPreliminaryNegociation($this);
- foreach ($data as $ID => $value)
- {
- echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
- echo "<tr class='tab_bg_1'>";
- echo "<td>" .$LANG['plugin_imp']['setup'][5]. "&nbsp;:&nbsp;</td>";
- echo "<td><input name='url' size='40' value='". $value["url"]."'/></td>";
- echo "<td>" .$LANG['plugin_imp']['setup'][12]. "&nbsp;:&nbsp;</td>";
- echo "<td><input name='srcentity' size='20' value='". $value["srcentity"]."'/></td>";
- echo "<td>" .$LANG['plugin_imp']['setup'][13]. "&nbsp;:&nbsp;</td>";
- echo "<td>"; dropdownValue("glpi_entities", "dstentity", $value["dstentity"], 0); echo "</td>";
- echo "<td>" .$LANG['plugin_imp']['setup'][14]. "&nbsp;:&nbsp;</td>";
- echo "<td>"; dropdownYesNo("active", $value["active"]); echo "</td>";
- if ($canedit) {
- echo "<input type='hidden' name='ID' value=$ID>";
- echo "<td><input type='submit' name='test' value=\"".$LANG["buttons"][50]."\" class='submit'></td>";
- echo "<td><input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'></td>";
- echo "<td><input type='submit' name='edit' value=\"".$LANG["buttons"][35]."\" class='submit'></td>";
- echo "<td><input type='submit' name='del' onclick=\"return confirm('".$LANG['common'][50]."')\" value=\"".$LANG["buttons"][6]."\" class='submit'></td>";
+ if (!$response) {
+ echo "<tr class='tab_bg_1'><td align='center' colspan='3'><strong>" .$LANG['plugin_imp']['setup'][11]."</strong></td></tr>";
+ echo "</table>";
+ return false;
+ }
+ else {
+ echo "<td colspan='3' align='center' class='tab_bg_4'>" .$LANG['plugin_imp']['setup'][9]. "&nbsp;:&nbsp;";
+ if (empty($this->fields["user"]))
+ echo $LANG['plugin_imp']['setup'][10]. "</td>";
+ else
+ echo convDateTime($this->fields["date_sync"])." (".$this->fields["user"]. ")</td>";
+
+ $tables=ImpGetTables($this);
+ if (count($tables)) {
+ echo "<tr class='tab_bg_5'><td align='center' colspan='3'>" .$LANG['plugin_imp']['setup'][8]."</td></tr>";
+ $i=0;
+ foreach ($tables as $nom => $desc) {
+ if ($i%3==0) echo "<tr class='tab_bg_1'>";
+
+ echo "<td>". $desc . "</td>";
+
+ if ($i%3==2) echo "</tr>\n";
+ $i++;
+ }
+ if ($i%3==1) echo "<td>&nbsp;</td><td>&nbsp;</td></tr>\n";
+ if ($i%3==2) echo "<td>&nbsp;</td></tr>\n";
+ } else {
+ echo "<tr class='tab_bg_4'><td align='center' colspan='3'><strong>" .$LANG['plugin_imp']['setup'][7]."</strong></td></tr>";
+ }
+ echo "</table>";
+ return true;
+ }
}
- echo "</tr></form>\n";
+ else return false;
}
- if ($canedit) {
- echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
- echo "<tr class='tab_bg_1'>";
- echo "<td>" .$LANG['plugin_imp']['setup'][5]. "&nbsp;:&nbsp;</td>";
- echo "<td><input name='url' size='40' value='". "http://"."'/></td>";
- echo "<td>" .$LANG['plugin_imp']['setup'][12]. "&nbsp;:&nbsp;</td>";
- echo "<td><input name='srcentity' size='20' value='". "0"."'/></td>";
- echo "<td>" .$LANG['plugin_imp']['setup'][13]. "&nbsp;:&nbsp;</td>";
- echo "<td>"; dropdownValue("glpi_entities", "dstentity", $value["dstentity"], 0); echo "</td>";
- echo "<td>" .$LANG['plugin_imp']['setup'][14]. "&nbsp;:&nbsp;</td>";
- echo "<td>"; dropdownYesNo("active", $value["active"]); echo "</td>";
- if ($canedit) {
- echo "<td></td>";
- echo "<td><input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'></td>";
+ function showFormEdit(){
+ global $LANG,$DB;
+
+ if (!haveRight("config","r")) {
+ return false;
}
- echo "</tr></form>\n";
- echo "\n</table>";
- }
- else {
- echo "</table>";
- }
-
- // if ($ID>0) {
- // $this->showStatus();
- // }
-
- echo "</div>";
- }
-
- function getDumpURL()
- {
- return $this->baseurl.'/plugin_dumpentity.getcsv.php';
- }
-
- function getChecksURL()
- {
- return $this->baseurl.'/plugin_dumpentity.checks.php';
- }
-
- function updateTranslateEntity($impid,$srcentity,$dstentity)
- {
- global $DB;
- $DB->query("UPDATE glpi_plugin_imp_translate SET dstID=$dstentity WHERE impID=$impid and type=".ENTITY_TYPE." and srcID=$srcentity");
- }
-
- function showTranslateEntityEdit($impid,$url){
- global $LANG,$DB;
-
- if (!haveRight("config","r")) {
- return false;
- }
- $canedit=haveRight("config","w");
-
- echo "<div align='center'>";
-
- if ($result = $DB->query("SELECT * FROM glpi_plugin_imp_translate WHERE impID=$impid and type=".ENTITY_TYPE)) {
- if ($DB->numrows($result)>0) {
- echo "<table class='tab_cadre' cellpadding='5'>";
- echo "<tr><th colspan='2' align='center'>".$LANG['plugin_imp']['setup'][15]." ".$url."</th></tr>";
- $i = 0;
- if ($canedit) echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
- while($data = $DB->fetch_array($result)) {
-
- echo "<tr class='tab_bg_1'>";
- echo "<td>" .$LANG['plugin_imp']['setup'][12]. "&nbsp;:&nbsp;</td>";
- echo "<td>" . $data["name"] . "</td>";
- echo "<td>" .$LANG['plugin_imp']['setup'][13]. "&nbsp;:&nbsp;</td>";
- if ($canedit) {
- echo "<td>"; dropdownValue("glpi_entities", "dstentity".$i, $data["dstID"], 0); echo "</td>";
- echo "<input type='hidden' name='srcentity".$i."' value=".$data["srcID"].">";
+ $canedit=haveRight("config","w");
+
+ // if ($this->getFromDB(1)) {
+ // $ID=$this->fields["ID"];
+ // }
+ // else {
+ // $ID=0;
+ // }
+
+ $data = $this->find();
+
+ echo "<div align='center'>";
+
+ echo "<table class='tab_cadre' cellpadding='5'>";
+ echo "<tr><th colspan='2' align='center'>".$LANG['plugin_imp']['setup'][2]."</th></tr>";
+
+ foreach ($data as $ID => $value)
+ {
+ echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][5]. "&nbsp;:&nbsp;</td>";
+ echo "<td><input name='url' size='40' value='". $value["url"]."'/></td>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][12]. "&nbsp;:&nbsp;</td>";
+ echo "<td><input name='srcentity' size='20' value='". $value["srcentity"]."'/></td>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][13]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownValue("glpi_entities", "dstentity", $value["dstentity"], 0); echo "</td>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][14]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownYesNo("active", $value["active"]); echo "</td>";
+ if ($canedit) {
+ echo "<input type='hidden' name='ID' value=$ID>";
+ echo "<td><input type='submit' name='test' value=\"".$LANG["buttons"][50]."\" class='submit'></td>";
+ echo "<td><input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'></td>";
+ echo "<td><input type='submit' name='edit' value=\"".$LANG["buttons"][35]."\" class='submit'></td>";
+ echo "<td><input type='submit' name='del' onclick=\"return confirm('".$LANG['common'][50]."')\" value=\"".$LANG["buttons"][6]."\" class='submit'></td>";
}
- else echo "<td>".$data["dstID"]."</td>";
- echo "</tr>\n";
- $i++;
+ echo "</tr></form>\n";
}
- if ($canedit) {
- echo "<tr><td colspan=4></td>";
- echo "<input type='hidden' name='ID' value=$impid>";
- echo "<input type='hidden' name='nbID' value=$i>";
- echo "<input type='hidden' name='url' value='$url'>";
- echo "<td><input type='submit' name='updatetrans' value=\"".$LANG["buttons"][7]."\" class='submit'></td>";
- echo "</tr>";
+ if ($canedit) {
+ echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][5]. "&nbsp;:&nbsp;</td>";
+ echo "<td><input name='url' size='40' value='". "http://"."'/></td>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][12]. "&nbsp;:&nbsp;</td>";
+ echo "<td><input name='srcentity' size='20' value='". "0"."'/></td>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][13]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownValue("glpi_entities", "dstentity", $value["dstentity"], 0); echo "</td>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][14]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownYesNo("active", $value["active"]); echo "</td>";
+ if ($canedit) {
+ echo "<td></td>";
+ echo "<td><input type='submit' name='add' value=\"".$LANG["buttons"][8]."\" class='submit'></td>";
+ }
+ echo "</tr></form>\n";
+ echo "\n</table>";
}
- if ($canedit) echo "</form>\n";
-
- echo "\n</table>";
- }
- } else echo "Oups error";
-
- echo "</div>";
- }
-
- function showConfigEntityEdit($impid,$url){
- global $LANG,$DB;
-
- if (!haveRight("config","r")) {
- return false;
- }
- $canedit=haveRight("config","w");
-
- echo "<div align='center'>";
-
- if ($this->getFromDB($impid)) {
- echo "<table class='tab_cadre' cellpadding='5'>";
- echo "<tr><th colspan='2' align='center'>".$LANG['plugin_imp']['setup'][21]." ".$url."</th></tr>";
- echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
- echo "<tr class='tab_bg_1'>";
- echo "<td>" .$LANG['plugin_imp']['setup'][16]. "&nbsp;:&nbsp;</td>";
- echo "<td>"; dropdownYesNo("update_computer_model",$this->fields["update_computer_model"]); echo "</td>";
- echo "</tr>";
- echo "<tr class='tab_bg_1'>";
- echo "<td>" .$LANG['plugin_imp']['setup'][17]. "&nbsp;:&nbsp;</td>";
- echo "<td>"; dropdownYesNo("update_computer_vendor",$this->fields["update_computer_vendor"]); echo "</td>";
- echo "</tr>";
- echo "<tr class='tab_bg_1'>";
- echo "<td>" .$LANG['plugin_imp']['setup'][18]. "&nbsp;:&nbsp;</td>";
- echo "<td>"; dropdownYesNo("update_computer_type",$this->fields["update_computer_type"]); echo "</td>";
- echo "</tr>";
- echo "<tr class='tab_bg_1'>";
- echo "<td>" .$LANG['plugin_imp']['setup'][19]. "&nbsp;:&nbsp;</td>";
- echo "<td>"; dropdownYesNo("update_software_name",$this->fields["update_software_name"]); echo "</td>";
- echo "</tr>";
- echo "<tr class='tab_bg_1'>";
- echo "<td>" .$LANG['plugin_imp']['setup'][20]. "&nbsp;:&nbsp;</td>";
- echo "<td>"; dropdownYesNo("update_software_category",$this->fields["update_software_category"]); echo "</td>";
- echo "</tr>";
- echo "<tr class='tab_bg_1'>";
- if ($canedit) {
- echo "<input type='hidden' name='ID' value=$impid>";
- echo "<input type='hidden' name='url' value='$url'>";
- echo "<td><input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'></td>";
+ else {
+ echo "</table>";
}
- echo "</tr></form>\n";
- echo "\n</table>";
- } else echo "Oups error";
+ // if ($ID>0) {
+ // $this->showStatus();
+ // }
- echo "</div>";
- }
+ echo "</div>";
+ }
-function importEntity ($id) {
- if (! $this->getFromDB($id)) return;
- ImpImportEntity($this,$id);
-}
+ function getDumpURL()
+ {
+ return $this->baseurl.'/plugin_dumpentity.getcsv.php';
+ }
-function listResult () {
- global $LANG,$DB;
+ function getChecksURL()
+ {
+ return $this->baseurl.'/plugin_dumpentity.checks.php';
+ }
- if (!haveRight("config","r")) {
- return false;
- }
- $canedit=haveRight("config","w");
-
-// if ($this->getFromDB(1)) {
-// $ID=$this->fields["ID"];
-// }
-// else {
-// $ID=0;
-// }
-
- $data = $this->find();
-
- echo "<div align='center'>";
-
- echo "<table class='tab_cadre' cellpadding='5'>";
- echo "<tr><th colspan='4' align='center'>".$LANG['plugin_imp']['status'][1]."</th></tr>";
-
- echo "<tr class='tab_bg_1'>";
- echo "<td>" .$LANG['plugin_imp']['setup'][5]. "&nbsp;&nbsp;</td>";
- echo "<td>" .$LANG['plugin_imp']['setup'][12]. "&nbsp;&nbsp;</td>";
- echo "<td>" .$LANG['plugin_imp']['setup'][13]. "&nbsp;&nbsp;</td>";
- echo "<td>" .$LANG['plugin_imp']['status'][2]. "&nbsp;&nbsp;</td>";
- echo "</tr>\n";
- foreach ($data as $ID => $value)
+ function updateTranslateEntity($impid,$srcentity,$dstentity)
{
- echo "<tr class='tab_bg_1'>";
- #echo "<td>" .$LANG['plugin_imp']['setup'][5]. "&nbsp;:&nbsp;</td>";
- echo "<td>". $value["url"]."</td>";
- #echo "<td>" .$LANG['plugin_imp']['setup'][12]. "&nbsp;:&nbsp;</td>";
- echo "<td>". $value["srcentity"]."</td>";
- #echo "<td>" .$LANG['plugin_imp']['setup'][13]. "&nbsp;:&nbsp;</td>";
- #echo "<td>"; getDropdownnameopdownValue("glpi_entities", "dstentity", $value["dstentity"], 0); echo "</td>";
- echo "<td>"; $v = getDropdownName("glpi_entities", $value["dstentity"], 1); echo $v["name"]; echo "</td>";
- #echo "<td>" .$LANG['plugin_imp']['status'][2]. "&nbsp;:&nbsp;</td>";
- echo "<td>" . $value["date_sync"]."</td>";
- echo "</tr>\n";
+ global $DB;
+ $DB->query("UPDATE glpi_plugin_imp_translate SET dstID=$dstentity WHERE impID=$impid and type=".ENTITY_TYPE." and srcID=$srcentity");
}
- echo "</table>";
- // if ($ID>0) {
- // $this->showStatus();
- // }
+ function showTranslateEntityEdit($impid,$url){
+ global $LANG,$DB;
- echo "</div>";
-}
+ if (!haveRight("config","r")) {
+ return false;
+ }
+ $canedit=haveRight("config","w");
+
+ echo "<div align='center'>";
+
+ if ($result = $DB->query("SELECT * FROM glpi_plugin_imp_translate WHERE impID=$impid and type=".ENTITY_TYPE)) {
+ if ($DB->numrows($result)>0) {
+ echo "<table class='tab_cadre' cellpadding='5'>";
+ echo "<tr><th colspan='2' align='center'>".$LANG['plugin_imp']['setup'][15]." ".$url."</th></tr>";
+ $i = 0;
+ if ($canedit) echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
+ while($data = $DB->fetch_array($result)) {
+
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][12]. "&nbsp;:&nbsp;</td>";
+ echo "<td>" . $data["name"] . "</td>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][13]. "&nbsp;:&nbsp;</td>";
+ if ($canedit) {
+ echo "<td>"; dropdownValue("glpi_entities", "dstentity".$i, $data["dstID"], 0); echo "</td>";
+ echo "<input type='hidden' name='srcentity".$i."' value=".$data["srcID"].">";
+ }
+ else echo "<td>".$data["dstID"]."</td>";
+ echo "</tr>\n";
+ $i++;
+ }
+ if ($canedit) {
+ echo "<tr><td colspan=4></td>";
+ echo "<input type='hidden' name='ID' value=$impid>";
+ echo "<input type='hidden' name='nbID' value=$i>";
+ echo "<input type='hidden' name='url' value='$url'>";
+ echo "<td><input type='submit' name='updatetrans' value=\"".$LANG["buttons"][7]."\" class='submit'></td>";
+ echo "</tr>";
+ }
+ if ($canedit) echo "</form>\n";
+
+ echo "\n</table>";
+ }
+ } else echo "Oups error";
+
+ echo "</div>";
+ }
+
+ function showConfigEntityEdit($impid,$url){
+ global $LANG,$DB;
+
+ if (!haveRight("config","r")) {
+ return false;
+ }
+ $canedit=haveRight("config","w");
+
+ echo "<div align='center'>";
+
+ if ($this->getFromDB($impid)) {
+ echo "<table class='tab_cadre' cellpadding='5'>";
+ echo "<tr><th colspan='2' align='center'>".$LANG['plugin_imp']['setup'][21]." ".$url."</th></tr>";
+ echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][16]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownYesNo("update_computer_model",$this->fields["update_computer_model"]); echo "</td>";
+ echo "</tr>";
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][17]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownYesNo("update_computer_vendor",$this->fields["update_computer_vendor"]); echo "</td>";
+ echo "</tr>";
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][18]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownYesNo("update_computer_type",$this->fields["update_computer_type"]); echo "</td>";
+ echo "</tr>";
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][19]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownYesNo("update_software_name",$this->fields["update_software_name"]); echo "</td>";
+ echo "</tr>";
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][20]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownYesNo("update_software_category",$this->fields["update_software_category"]); echo "</td>";
+ echo "</tr>";
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][22]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownYesNo("flat_entities",$this->fields["flat_entities"]); echo "</td>";
+ echo "</tr>";
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][23]. "&nbsp;:&nbsp;</td>";
+ echo "<td>"; dropdownYesNo("recursive",$this->fields["recursive"]); echo "</td>";
+ echo "</tr>";
+ echo "<tr class='tab_bg_1'>";
+ if ($canedit) {
+ echo "<input type='hidden' name='ID' value=$impid>";
+ echo "<input type='hidden' name='url' value='$url'>";
+ echo "<td><input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'></td>";
+ }
+ echo "</tr></form>\n";
+
+ echo "\n</table>";
+ } else echo "Oups error";
+
+ echo "</div>";
+ }
+
+ function importEntity ($id) {
+ if (! $this->getFromDB($id)) return;
+ ImpImportEntity($this,$id);
+ }
+
+ function listResult () {
+ global $LANG,$DB;
+
+ if (!haveRight("config","r")) {
+ return false;
+ }
+ $canedit=haveRight("config","w");
+
+ // if ($this->getFromDB(1)) {
+ // $ID=$this->fields["ID"];
+ // }
+ // else {
+ // $ID=0;
+ // }
+
+ $data = $this->find();
+
+ echo "<div align='center'>";
+
+ echo "<table class='tab_cadre' cellpadding='5'>";
+ echo "<tr><th colspan='4' align='center'>".$LANG['plugin_imp']['status'][1]."</th></tr>";
+
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][5]. "&nbsp;&nbsp;</td>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][12]. "&nbsp;&nbsp;</td>";
+ echo "<td>" .$LANG['plugin_imp']['setup'][13]. "&nbsp;&nbsp;</td>";
+ echo "<td>" .$LANG['plugin_imp']['status'][2]. "&nbsp;&nbsp;</td>";
+ echo "</tr>\n";
+ foreach ($data as $ID => $value)
+ {
+ echo "<tr class='tab_bg_1'>";
+ #echo "<td>" .$LANG['plugin_imp']['setup'][5]. "&nbsp;:&nbsp;</td>";
+ echo "<td>". $value["url"]."</td>";
+ #echo "<td>" .$LANG['plugin_imp']['setup'][12]. "&nbsp;:&nbsp;</td>";
+ echo "<td>". $value["srcentity"]."</td>";
+ #echo "<td>" .$LANG['plugin_imp']['setup'][13]. "&nbsp;:&nbsp;</td>";
+ #echo "<td>"; getDropdownnameopdownValue("glpi_entities", "dstentity", $value["dstentity"], 0); echo "</td>";
+ echo "<td>"; $v = getDropdownName("glpi_entities", $value["dstentity"], 1); echo $v["name"]; echo "</td>";
+ #echo "<td>" .$LANG['plugin_imp']['status'][2]. "&nbsp;:&nbsp;</td>";
+ echo "<td>" . $value["date_sync"]."</td>";
+ echo "</tr>\n";
+ }
+ echo "</table>";
+
+ // if ($ID>0) {
+ // $this->showStatus();
+ // }
+
+ echo "</div>";
+ }
}
diff -urB -x .svn branches/forge/trunk//inc/plugin_imp.function.php trunk//inc/plugin_imp.function.php
--- branches/forge/trunk//inc/plugin_imp.function.php 2011-07-07 10:41:20.765282080 +0200
+++ trunk//inc/plugin_imp.function.php 2011-07-21 14:20:45.695771314 +0200
@@ -144,14 +144,16 @@
}
function ImpLoadFile (&$config, $table) {
- $dst=@fopen(PLUGIN_IMP_UPLOAD_DIR.$table.".csv", "wb");
- if ($dst===false) return -1;
-print $config->fields["url"];
+ $dst=@fopen(PLUGIN_IMP_UPLOAD_DIR.$table.".csv", "wb");
+ $entity = $config->fields["srcentity"];
+ if ($dst===false)
+ return -1;
+ print $config->fields["url"]."\n";
$rd=0;
$wr=0;
$old = ini_set('default_socket_timeout', 180);
if (function_exists("gzopen") and substr($config->fields["url"], 0, 5) != 'proxy') {
- $fic=gzopen($config->fields["url"].$config->getDumpURL()."?table=$table&gzip=1","rb");
+ $fic=gzopen($config->fields["url"].$config->getDumpURL()."?table=$table&gzip=1&entity=$entity","rb");
if ($fic) {
while ($buf=gzread($fic,4096)) {
$rd += strlen($buf);
@@ -159,13 +161,13 @@
}
gzclose($fic);
} else {
-print "err on gzopen";
+print "err on gzopen\n" ; //print $config->fields["url"].$config->getDumpURL()."?table=$table&gzip=1"." "; print_r(error_get_last());
fclose($dst);
return -1;
}
}
else {
- $fic=fopen($config->fields["url"].$config->getDumpURL()."?table=$table","rb");
+ $fic=fopen($config->fields["url"].$config->getDumpURL()."?table=$table&entity=$entity","rb");
if ($fic) {
while ($buf=fread($fic,4096)) {
$rd += strlen($buf);
@@ -174,7 +176,7 @@
fclose ($fic);
} else {
fclose($dst);
-print "err on fopen";
+print "err on fopen\n";
return -1;
}
}
@@ -346,4 +348,109 @@
}
}
- ?>
+ /**
+ * Delete all components in an entity and its sub-entities.
+ * For the moment, entity isn't remove at the end (but sub-entities yes).
+ * @param int $entity entity ID
+ */
+ function DeleteEntity($entity) {
+ global $DB;
+ print ("Delete entity $entity\n");
+ // treat the sub-entities and associated computers ...
+ if ($result = $DB->query("Select * from glpi_entities where parentID=$entity"))
+ {
+ if ($DB->numrows($result)>0)
+ {
+ while ($data = $DB->fetch_array($result)) {
+ if (DeleteEntity($data["ID"])==-1) loganddie ("Delete entity ".$data["ID"]);
+ $DB->query("delete from glpi_entities where ID=".$data["ID"]);
+ }
+ }
+ }
+
+ // TODO suppress InfoCom
+ // delete computers
+
+ print "Delete glpi_inst_software from entity $entity\n";
+ if (! $DB->query("delete ".
+ "from glpi_inst_software ".
+ "where EXISTS ( ".
+ "select * from glpi_computers c ".
+ "where c.ID = glpi_inst_software.cID AND c.FK_entities = $entity )")) return -1;
+
+ print "Delete glpi_networking_ports from entity $entity\n";
+ if (! $DB->query("delete ".
+ "from glpi_networking_ports ".
+ "where device_type = 1 and EXISTS ( ".
+ "select * from glpi_computers c ".
+ "where c.ID = glpi_networking_ports.on_device AND c.FK_entities = $entity )")) return -1;
+
+ print "Delete glpi_computer_device from entity $entity\n";
+ if (! $DB->query("delete ".
+ "FROM glpi_computer_device ".
+ "WHERE EXISTS ( ".
+ "SELECT * FROM glpi_computers c ".
+ "WHERE c.ID = glpi_computer_device.FK_computers and c.FK_entities = $entity )")) return -1;
+
+ print "Delete glpi_computerdisks from entity $entity\n";
+ if (! $DB->query("delete ".
+ "FROM glpi_computerdisks ".
+ "WHERE EXISTS ( ".
+ "SELECT * FROM glpi_computers c ".
+ "WHERE c.ID = glpi_computerdisks.FK_computers and c.FK_entities = $entity )")) return -1;
+
+ print "Delete glpi_computers from entity $entity\n";
+ if (! $DB->query("delete ".
+ "from glpi_computers ".
+ "where FK_entities = $entity")) return -1;
+
+ // delete software
+
+
+ //TODO Infocom ...
+ print "Delete glpi_softwarelicenses from entity $entity\n";
+ if (! $DB->query("delete ".
+ "from glpi_softwarelicenses ".
+ "where FK_entities = $entity")) return -1;
+
+ //old query
+ //TODO : remove if useless
+ /* delete
+ from glpi_softwarelicenses l
+ where EXISTS (
+ select * from glpi_softwareversions v WHERE v.ID = l.use_version AND EXISTS (
+ select * from glpi_software s where s.ID = v.sID AND FK_entities = $entity )) */
+
+ // Must be useless... but we are never too prudent
+ print "Delete glpi_inst_software from entity $entity\n";
+ if (! $DB->query("delete ".
+ "from glpi_inst_software ".
+ "where EXISTS ( ".
+ "select * from glpi_softwareversions v ".
+ "where glpi_inst_software.vID = v.ID AND EXISTS ( ".
+ "select * from glpi_software s where s.ID = v.sID AND s.FK_entities = $entity))")) return -1;
+
+ print "Delete glpi_softwareversions from entity $entity\n";
+ if (! $DB->query("delete ".
+ "from glpi_softwareversions ".
+ "where EXISTS ( ".
+ "select * from glpi_software s ".
+ "where s.ID = glpi_softwareversions.sID AND s.FK_entities = $entity)")) return -1;
+
+ print "Delete glpi_software from entity $entity\n";
+ if (! $DB->query("delete ".
+ "from glpi_software ".
+ "where FK_entities = $entity")) return -1;
+
+ //KB Items
+ print "Delete glpi_kbitems from entity $entity\n";
+ if (! $DB->query("delete ".
+ "from glpi_kbitems ".
+ "where FK_entities = $entity")) return -1;
+ //Printers
+ //TODO
+
+ print "\n";
+ return 0;
+ }
+?>
Seulement dans trunk//inc: plugin_imp.function.php.old
diff -urB -x .svn branches/forge/trunk//inc/plugin_imp.run.php trunk//inc/plugin_imp.run.php
--- branches/forge/trunk//inc/plugin_imp.run.php 2011-07-07 10:41:20.765282080 +0200
+++ trunk//inc/plugin_imp.run.php 2011-07-26 10:19:38.032913730 +0200
@@ -1,30 +1,30 @@
<?php
/*
----------------------------------------------------------------------
- GLPI - Gestionnaire Libre de Parc Informatique
- Copyright (C) 2003-2008 by the INDEPNET Development Team.
+GLPI - Gestionnaire Libre de Parc Informatique
+Copyright (C) 2003-2008 by the INDEPNET Development Team.
- http://indepnet.net/ http://glpi-project.org/
- ----------------------------------------------------------------------
-
- LICENSE
+http://indepnet.net/ http://glpi-project.org/
+----------------------------------------------------------------------
- This file is part of GLPI.
+LICENSE
- GLPI is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- GLPI is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GLPI; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- ------------------------------------------------------------------------
+This file is part of GLPI.
+
+GLPI is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GLPI is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GLPI; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+------------------------------------------------------------------------
*/
// Original Author of file: Yanick Durant
@@ -75,370 +75,425 @@
$tableliste = array (
- ENTITY_TYPE => "glpi_entities",
- COMPUTER_TYPE => "glpi_computers",
- SOFTWARE_TYPE => "glpi_software",
- DROPDOWN_DOMAIN_TYPE => "glpi_dropdown_domain",
- DROPDOWN_NETWORK_TYPE => "glpi_dropdown_network",
- DROPDOWN_AUTO_UPDATE_TYPE => "glpi_dropdown_auto_update",
- DROPDOWN_MODEL_TYPE => "glpi_dropdown_model",
- DROPDOWN_OS_TYPE => "glpi_dropdown_os",
- DROPDOWN_OS_SP_TYPE => "glpi_dropdown_os_sp",
- DROPDOWN_OS_VERSION_TYPE => "glpi_dropdown_os_version",
- DROPDOWN_STATE_TYPE => "glpi_dropdown_state",
- DROPDOWN_MANUFACTURER_TYPE => "glpi_dropdown_manufacturer",
- TYPE_COMPUTERS_TYPE => "glpi_type_computers",
- DROPDOWN_LOCATIONS_TYPE => "glpi_dropdown_locations",
- DROPDOWN_SOFTWARE_CATEGORY_TYPE => "glpi_dropdown_software_category",
- DROPDOWN_LICENSETYPES_TYPE => "glpi_dropdown_licensetypes",
- SOFTWAREVERSION_TYPE => "glpi_softwareversions",
- INST_SOFTWARE_TYPE => "glpi_inst_software",
- SOFTWARELICENSE_TYPE => "glpi_softwarelicenses",
-
- COMPUTER_DEVICE_TYPE => "glpi_computer_device",
- COMPUTERDISK_TYPE => "glpi_computerdisks",
- DEVICE_CASE_TYPE => "glpi_device_case",
- DEVICE_CONTROL_TYPE => "glpi_device_control",
- DEVICE_DRIVE_TYPE => "glpi_device_drive",
- DEVICE_GFXCARD_TYPE => "glpi_device_gfxcard",
- DEVICE_HDD_TYPE => "glpi_device_hdd",
- DEVICE_IFACE_TYPE => "glpi_device_iface",
- DEVICE_MOBOARD_TYPE => "glpi_device_moboard",
- DEVICE_PCI_TYPE => "glpi_device_pci",
- DEVICE_POWER_TYPE => "glpi_device_power",
- DEVICE_PROCESSOR_TYPE => "glpi_device_processor",
- DEVICE_RAM_TYPE => "glpi_device_ram",
- DEVICE_SNDCARD_TYPE => "glpi_device_sndcard",
- DROPDOWN_CASE_TYPE_TYPE => "glpi_dropdown_case_type",
- DROPDOWN_FILESYSTEMS_TYPE => "glpi_dropdown_filesystems",
- DROPDOWN_FIRMWARE_TYPE => "glpi_dropdown_firmware",
- DROPDOWN_IFACE_TYPE => "glpi_dropdown_iface",
- DROPDOWN_INTERFACE_TYPE => "glpi_dropdown_interface",
- DROPDOWN_MODEL_PERIPHERALS_TYPE => "glpi_dropdown_model_peripherals",
- DROPDOWN_RAM_TYPE_TYPE => "glpi_dropdown_ram_type",
- NETWORKING_PORT_TYPE => "glpi_networking_ports",
+ENTITY_TYPE => "glpi_entities",
+COMPUTER_TYPE => "glpi_computers",
+SOFTWARE_TYPE => "glpi_software",
+DROPDOWN_DOMAIN_TYPE => "glpi_dropdown_domain",
+DROPDOWN_NETWORK_TYPE => "glpi_dropdown_network",
+DROPDOWN_AUTO_UPDATE_TYPE => "glpi_dropdown_auto_update",
+DROPDOWN_MODEL_TYPE => "glpi_dropdown_model",
+DROPDOWN_OS_TYPE => "glpi_dropdown_os",
+DROPDOWN_OS_SP_TYPE => "glpi_dropdown_os_sp",
+DROPDOWN_OS_VERSION_TYPE => "glpi_dropdown_os_version",
+DROPDOWN_STATE_TYPE => "glpi_dropdown_state",
+DROPDOWN_MANUFACTURER_TYPE => "glpi_dropdown_manufacturer",
+TYPE_COMPUTERS_TYPE => "glpi_type_computers",
+DROPDOWN_LOCATIONS_TYPE => "glpi_dropdown_locations",
+DROPDOWN_SOFTWARE_CATEGORY_TYPE => "glpi_dropdown_software_category",
+DROPDOWN_LICENSETYPES_TYPE => "glpi_dropdown_licensetypes",
+SOFTWAREVERSION_TYPE => "glpi_softwareversions",
+INST_SOFTWARE_TYPE => "glpi_inst_software",
+SOFTWARELICENSE_TYPE => "glpi_softwarelicenses",
+
+COMPUTER_DEVICE_TYPE => "glpi_computer_device",
+COMPUTERDISK_TYPE => "glpi_computerdisks",
+DEVICE_CASE_TYPE => "glpi_device_case",
+DEVICE_CONTROL_TYPE => "glpi_device_control",
+DEVICE_DRIVE_TYPE => "glpi_device_drive",
+DEVICE_GFXCARD_TYPE => "glpi_device_gfxcard",
+DEVICE_HDD_TYPE => "glpi_device_hdd",
+DEVICE_IFACE_TYPE => "glpi_device_iface",
+DEVICE_MOBOARD_TYPE => "glpi_device_moboard",
+DEVICE_PCI_TYPE => "glpi_device_pci",
+DEVICE_POWER_TYPE => "glpi_device_power",
+DEVICE_PROCESSOR_TYPE => "glpi_device_processor",
+DEVICE_RAM_TYPE => "glpi_device_ram",
+DEVICE_SNDCARD_TYPE => "glpi_device_sndcard",
+DROPDOWN_CASE_TYPE_TYPE => "glpi_dropdown_case_type",
+DROPDOWN_FILESYSTEMS_TYPE => "glpi_dropdown_filesystems",
+DROPDOWN_FIRMWARE_TYPE => "glpi_dropdown_firmware",
+DROPDOWN_IFACE_TYPE => "glpi_dropdown_iface",
+DROPDOWN_INTERFACE_TYPE => "glpi_dropdown_interface",
+DROPDOWN_MODEL_PERIPHERALS_TYPE => "glpi_dropdown_model_peripherals",
+DROPDOWN_RAM_TYPE_TYPE => "glpi_dropdown_ram_type",
+NETWORKING_PORT_TYPE => "glpi_networking_ports",
- DROPDOWN_BUDGET_TYPE => "glpi_dropdown_budget",
- FINANCIAL_INFORMATION_TYPE => "glpi_infocoms",
+DROPDOWN_BUDGET_TYPE => "glpi_dropdown_budget",
+FINANCIAL_INFORMATION_TYPE => "glpi_infocoms",
);
$ImpSoftAsRootEntity = 0;
-$imp_flag_update_computer_vendor = true;
-$imp_flag_update_computer_model = true;
-$imp_flag_update_computer_type = true;
-$imp_flag_update_software_name = true;
-$imp_flag_update_software_category = true;
-
+$imp_flag_update_computer_vendor = true;
+$imp_flag_update_computer_model = true;
+$imp_flag_update_computer_type = true;
+$imp_flag_update_software_name = true;
+$imp_flag_update_software_category = true;
+$imp_flag_flat_entities = false;
+
+/**
+ * Clean translate table of old imput
+ */
function ImpCleanTranslate () {
-global $DB;
-global $tableliste;
-
+ global $DB;
+ global $tableliste;
+
reset($tableliste);
for ($i = 0; $i < count($tableliste); $i++)
{
- $index = key($tableliste);
-// print $tableliste[$index];
+ $index = key($tableliste);
+ // print $tableliste[$index];
- $query = "DELETE FROM glpi_plugin_imp_translate WHERE type = $index AND dstID not in (SELECT ID FROM ".$tableliste[$index].")" ;
+ $query = "DELETE FROM glpi_plugin_imp_translate WHERE type = $index AND
+ dstID not in (SELECT ID FROM ".$tableliste[$index].")" ;
-// print $query."\n";
- if (! $DB->query($query)) print "Err clean ".$tableliste[$index]."\n";
+ // print $query."\n";
+ if (! $DB->query($query)) print "Err clean ".$tableliste[$index]."\n";
next($tableliste);
}
}
function ImpCleanImportTable () {
-global $DB;
-global $tableliste;
+ global $DB;
+ global $tableliste;
+
-
reset($tableliste);
foreach ($tableliste as $table)
{
- $table = str_replace ("glpi_","glpi_plugin_imp_",$table);
-// print $tableliste[$index];
+ $table = str_replace ("glpi_","glpi_plugin_imp_",$table);
+ // print $tableliste[$index];
- $query = "TRUNCATE TABLE $table ";
+ $query = "TRUNCATE TABLE $table ";
-// print $query."\n";
- if (! $DB->query($query)) print "Err truncate ".$table."\n";
+ // print $query."\n";
+ if (! $DB->query($query)) print "Err truncate ".$table."\n";
}
}
-function ImpAddTranslate ($srcID,$dstID,$impid,$type,$name='') {
-global $DB;
- $query = "INSERT INTO glpi_plugin_imp_translate (srcID,dstID,impID,type,name) VALUES ($srcID,$dstID,$impid,$type,'$name')";
-// print $query."\n";
- if (! $DB->query($query)) {
-//die ("");
- return false;
+function ImpAddTranslate ($srcID,$dstID,$impid,$type) {
+ global $DB;
+ $query = "INSERT INTO glpi_plugin_imp_translate (srcID,dstID,impID,type) VALUES ($srcID,$dstID,$impid,$type)";
+ // print $query."\n";
+ if (! $DB->query($query)) {
+ //die ("");
+ return false;
}
- return true;
+ return true;
}
+/**
+ * Get ID from translation table
+ * @param unknown_type $srcID
+ * @param unknown_type $impid
+ * @param unknown_type $type
+ * @return Ambiguous|number
+ */
function ImpGetdstID ($srcID,$impid,$type) {
-// return translated value, could be -1 if not set in the dest. GLPI
-// return -2 if it doesn't exist in the translate table
-// return -3 if error
-global $DB;
+ // return translated value, could be -1 if not set in the dest. GLPI
+ // return -2 if it doesn't exist in the translate table
+ // return -3 if error
+ global $DB;
+ global $imp_flag_flat_entities;
- $query = "SELECT dstID FROM glpi_plugin_imp_translate WHERE srcID=$srcID and impID=$impid and type =$type";
-// print $query."\n";
- if ($result3 = $DB->query($query)) {
- if ($DB->numrows($result3) == 1) {
- $data3 = $DB->fetch_array($result3);
- return $data3["dstID"];
+ // flat entities by return parent entity on call with "imp_flag_flat_entities"
+ if ($type == ENTITY_TYPE and $imp_flag_flat_entities) //return only configure destination
+ {
+ print "Flat Entity $srcID \n";
+ $query = "SELECT dstentity AS dstID FROM glpi_plugin_imp_config WHERE ID=$impid";
+ }
+ else //return destination ID from translation table
+ $query = "SELECT dstID AS dstID FROM glpi_plugin_imp_translate WHERE srcID=$srcID and impID=$impid and type =$type";
+
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result) == 1) {
+ $data = $DB->fetch_array($result);
+ return $data["dstID"];
}
else
{
-// print "Diff d'un retour ".$DB->numrows($result3);
+ // print "Diff d'un retour ".$DB->numrows($result3);
return -2;
}
}
return -3;
}
-function ImpGetdstID2 ($srcID,$impid,$type)
-{
+//TODO : Completly remove this legacy function if no error found
+
+/* function ImpGetdstID2 ($srcID,$impid,$type)
+ {
global $DB;
- $query = "SELECT dstID FROM glpi_plugin_imp_translate WHERE srcID=$srcID and impID=$impid and type =$type";
+$query = "SELECT dstID FROM glpi_plugin_imp_translate WHERE srcID=$srcID and impID=$impid and type =$type";
// print $query."\n";
- if ($result3 = $DB->query($query)) {
- if ($DB->numrows($result3) == 1) {
- $data3 = $DB->fetch_array($result3);
- print $data3["dstID"]."\n";
- return $data3["dstID"];
- }
- else
- {
- print "Diff d'un retour ".$DB->numrows($result3);
- return -1;
- }
- }
- return -1;
+if ($result3 = $DB->query($query)) {
+if ($DB->numrows($result3) == 1) {
+$data3 = $DB->fetch_array($result3);
+print $data3["dstID"]."\n";
+return $data3["dstID"];
}
+else
+{
+print "Diff d'un retour ".$DB->numrows($result3);
+return -1;
+}
+}
+return -1;
+} */
+/**
+ * Initialisation of translation table :
+ * Check if in translation
+ * If not, check if exist in $table_out (by name)
+ * If not, insert a entry in $table_out
+ * @param unknown_type $table_in
+ * @param unknown_type $table_out
+ * @param unknown_type $type
+ * @param unknown_type $impid
+ */
function ImpDropdown ($table_in,$table_out,$type,$impid)
{
-global $DB;
-print "Import dropdown $table_out\n";
- $query = "SELECT * FROM $table_in WHERE 1 ";
-// print $query."\n";
- if ($result = $DB->query($query)) {
- if ($DB->numrows($result)>0) {
- while($data = $DB->fetch_array($result)) {
+ global $DB;
+ print "Import dropdown $table_out \n";
+ $query = "SELECT ID AS ID, name AS name, comment AS comment FROM $table_in t";
+ // print $query."\n";
+ if ($result_in = $DB->query($query)) {
+ if ($DB->numrows($result_in)>0) {
+ while($data_in = $DB->fetch_array($result_in)) {
// print $data["ID"].$data["name"].$data["comments"]."\n";
- // allready exist in translation table ? (we could use a configuration flag to force the update here)
+ // allready exist in translation table ? (we could use a configuration flag to force the update here)
- $srcID = $data["ID"];
- if (ImpGetdstID ($srcID,$impid,$type) >= 0) continue; // allready exist in translate
- // allready exist in destination table ?
-
- $query = "SELECT ID FROM $table_out WHERE name = '".$data["name"]."' LIMIT 1";
-// print $query."\n";
- $dstID = 0 ;
- if ($result2 = $DB->query($query)) {
- if ($DB->numrows($result2)>0) {
- $data2 = $DB->fetch_array($result2);
- $dstID = $data2["ID"];
- }
- }
- if ($dstID == 0) {
- $query = "INSERT INTO $table_out (name,comments) VALUES ('".addslashes($data["name"])."','".addslashes($data["comments"])."')";
-// print $query."\n";
- if ($result2 = $DB->query($query)) {
- $dstID = $DB-> insert_id();
- }
- }
- // update translation table
- if ($dstID != 0) {
- if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) print "Err db translate $srcID-$dstID\n";
- }
-//
- } // while
- } // if
- else
- print "Nb Result ? :".$DB->numrows($result)."\n";
- } // if
- else
- print "Result ? :".$result."\n";
+ $srcID = $data_in["ID"];
+ if (ImpGetdstID ($srcID,$impid,$type) >= 0)
+ continue; // already exist in translate table
+
+ $dstID = 0;
+
+ // already exist in destination table ?
+ $query = "SELECT ID FROM $table_out WHERE name = '".$data_in["name"]."' LIMIT 1";
+ if ($result2 = $DB->query($query)) {
+ if ($DB->numrows($result2)>0) {
+ $data_out = $DB->fetch_array($result2);
+ $dstID = $data_out["ID"];
+ }
+ }
+
+ // Not in translate, not in table -> Insert element into the table
+ if ($dstID == 0) {
+ $query = "INSERT INTO $table_out (name,comments) VALUES ('".addslashes($data_in["name"])."','".addslashes($data_in["comments"])."')";
+ // print $query."\n";
+ if ($result2 = $DB->query($query)) {
+ $dstID = $DB-> insert_id();
+ }
+ }
+
+ // update translation table with existing entry or new one
+ if ($dstID != 0) {
+ if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) print "Err db translate $srcID-$dstID\n";
+ }
+
+ }
+ }
+ else
+ print "Nb Result ? :".$DB->numrows($result_in)."\n";
+ }
+ else
+ print "Result ? :".$result_in."\n";
}
function ImpLocation ($impid,$dstentity)
{
-// We will need to update the entity value of the table after the import ...
+ // We will need to update the entity value of the table after the import ...
-global $DB;
+ global $DB;
-$table_in = 'glpi_plugin_imp_dropdown_locations';
-$table_out = 'glpi_dropdown_locations';
-$type = DROPDOWN_LOCATIONS_TYPE;
-//$entity = 2;
-print "Import dropdown $table_out\n";
-
- $query = "SELECT * FROM $table_in WHERE 1";
-// print $query."\n";
- if ($result = $DB->query($query)) {
- if ($DB->numrows($result)>0) {
- $i = 0;
- while($data = $DB->fetch_array($result)) {
-// print $data["ID"].$data["name"].$data["comments"]."\n";
-
- // allready exist in translation table ? (we could use a configuration flag to force the update here)
-
- $srcID = $data["ID"];
- if (ImpGetdstID ($srcID,$impid,$type) >= 0) continue; // allready exist in translate
-
- // allready exist in destination table ?
-
- $query = "SELECT ID FROM $table_out WHERE name = '".$data["name"]."' LIMIT 1";
-// print $query."\n";
- $dstID = 0 ;
- if ($result2 = $DB->query($query)) {
- if ($DB->numrows($result2)>0) {
- $data2 = $DB->fetch_array($result2);
- $dstID = $data2["ID"];
- }
- }
- if ($dstID == 0) {
- $query = "INSERT INTO $table_out (name,comments,completename,level,FK_entities) VALUES ('".
- addslashes($data["name"])."','".addslashes($data["comments"])."','".addslashes($data["completename"])."','".$data["level"]."',".$dstentity.")";
-// print $query."\n";
- if ($result2 = $DB->query($query)) {
- $dstID = $DB-> insert_id();
- }
- }
- // update translation table
- if ($dstID != 0) {
- if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) print "Err db";
- }
-//
- $i++;
- }
-
- }
- else
- print "Nb Result ? :".$DB->numrows($result)."\n";
+ $table_in = 'glpi_plugin_imp_dropdown_locations';
+ $table_out = 'glpi_dropdown_locations';
+ $type = DROPDOWN_LOCATIONS_TYPE;
+ //$entity = 2;
+ print "Import dropdown $table_out\n";
+
+ $query = "SELECT * FROM $table_in WHERE 1";
+ // print $query."\n";
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ $i = 0;
+ while($data = $DB->fetch_array($result)) {
+ // print $data["ID"].$data["name"].$data["comments"]."\n";
+
+ // allready exist in translation table ? (we could use a configuration flag to force the update here)
+
+ $srcID = $data["ID"];
+ if (ImpGetdstID ($srcID,$impid,$type) >= 0) continue; // allready exist in translate
+
+ // allready exist in destination table ?
+
+ $query = "SELECT ID FROM $table_out WHERE name = '".$data["name"]."' LIMIT 1";
+ // print $query."\n";
+ $dstID = 0 ;
+ if ($result2 = $DB->query($query)) {
+ if ($DB->numrows($result2)>0) {
+ $data2 = $DB->fetch_array($result2);
+ $dstID = $data2["ID"];
+ }
+ }
+ if ($dstID == 0) {
+ $query = "INSERT INTO $table_out (name,comments,completename,level,FK_entities) VALUES ('".
+ addslashes($data["name"])."','".addslashes($data["comments"])."','".addslashes($data["completename"])."','".$data["level"]."',".$dstentity.")";
+ // print $query."\n";
+ if ($result2 = $DB->query($query)) {
+ $dstID = $DB-> insert_id();
+ }
+ }
+ // update translation table
+ if ($dstID != 0) {
+ if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) print "Err db\n";
+ }
+ //
+ $i++;
}
- else
- print "Result ? :".$result."\n";
-//$query = "ALTER TABLE glpi_plugin_imp_dropdown_locations DROP INDEX name";
-//if (! $DB->query($query)) { print "Err update location\n$query\n"; return; }
+ }
+ else
+ print "Nb Result ? :".$DB->numrows($result)."\n";
+ }
+ else
+ print "Result ? :".$result."\n";
+
+ //$query = "ALTER TABLE glpi_plugin_imp_dropdown_locations DROP INDEX name";
+ //if (! $DB->query($query)) { print "Err update location\n$query\n"; return; }
-// Update parent ID in plugin_imp_dropdown_locations
+ // Update parent ID in plugin_imp_dropdown_locations
-$query = "UPDATE glpi_plugin_imp_dropdown_locations SET parentid = ( SELECT dstID FROM glpi_plugin_imp_translate WHERE impID=$impid AND type=$type AND glpi_plugin_imp_dropdown_locations.parentid=srcID)";
-// print $query."\n";
-if ($result = $DB->query($query))
-{
- $query = " SELECT dstID,srcID FROM glpi_plugin_imp_translate WHERE impID=$impid AND type=$type "; // We browse all the location table
- if ($result = $DB->query($query)) {
- if ($DB->numrows($result)>0) {
- while($data = $DB->fetch_array($result)) {
+ $query = "UPDATE glpi_plugin_imp_dropdown_locations SET parentid = ( SELECT dstID FROM glpi_plugin_imp_translate WHERE impID=$impid AND type=$type AND glpi_plugin_imp_dropdown_locations.parentid=srcID)";
+ // print $query."\n";
+ if ($result = $DB->query($query))
+ {
+ $query = " SELECT dstID,srcID FROM glpi_plugin_imp_translate WHERE impID=$impid AND type=$type "; // We browse all the location table
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
$query = "UPDATE glpi_dropdown_locations SET parentid = ( SELECT parentid FROM glpi_plugin_imp_dropdown_locations ".
"WHERE glpi_plugin_imp_dropdown_locations.ID = ".$data["srcID"]." ) " .
"WHERE ID = ".$data["dstID"];
- if (!$DB->query($query)) print "Err update location $query";
- }
+ if (!$DB->query($query)) print "Err update location $query\n";
+ }
+ }
}
- }
-} else print "Err 2 update location $query";
+ }
+ else
+ print "Err 2 update location $query \n";
-// Done before fill of table
-// $query = "ALTER TABLE glpi_plugin_imp_dropdown_locations ADD UNIQUE INDEX name (`name`,`parentID`,`FK_entities`)";
-// if (! $DB->query($query)) { print "Err update location\n$query\n"; return; }
+ // Done before fill of table
+ // $query = "ALTER TABLE glpi_plugin_imp_dropdown_locations ADD UNIQUE INDEX name (`name`,`parentID`,`FK_entities`)";
+ // if (! $DB->query($query)) { print "Err update location\n$query\n"; return; }
}
function ImpUpdateLocationEntities($impid)
{
-Global $DB;
-//$table_in = 'glpi_plugin_imp_dropdown_locations';
-//$table_out = 'glpi_dropdown_locations';
-//$type = DROPDOWN_LOCATIONS_TYPE;
-
-$query = "ALTER TABLE glpi_plugin_imp_dropdown_locations DROP INDEX name";
-if (! $DB->query($query)) { print "Warning update location\n$query\n"; }
-
- $query = "SELECT * FROM glpi_plugin_imp_dropdown_locations WHERE 1";
-// print $query."\n";
- if ($result = $DB->query($query)) {
- if ($DB->numrows($result)>0) {
- while($data = $DB->fetch_array($result)) {
- print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
-
- // allready exist in translation table ?
-
- if (($dstID = ImpGetdstID ($data["ID"],$impid,DROPDOWN_LOCATIONS_TYPE)) < 0) {
- print "Err update location not in translate ";
- print $data["ID"]."\n";
- return;
- }
- if (($dstENT= ImpGetdstID ($data["FK_entities"],$impid,ENTITY_TYPE)) < 0) $dstENT = 0; // default is root entity
-
- $query = "UPDATE glpi_dropdown_locations SET FK_entities = $dstENT WHERE ID=$dstID";
- if (! $DB->query($query)) { print "\n".$query."\n"; print $data["ID"]." Err update location ent $dstENT -$dstID-\n"; return; }
- }
- }
- else
- print "ImpUpdateLocationEntities Nb Result ? :".$DB->numrows($result)."\n";
+ Global $DB;
+ //$table_in = 'glpi_plugin_imp_dropdown_locations';
+ //$table_out = 'glpi_dropdown_locations';
+ //$type = DROPDOWN_LOCATIONS_TYPE;
+
+ $query = "ALTER TABLE glpi_plugin_imp_dropdown_locations DROP INDEX name";
+ if (! $DB->query($query)) {
+ print "Warning update location\n$query\n";
+ }
+
+ $query = "SELECT * FROM glpi_plugin_imp_dropdown_locations WHERE 1";
+ // print $query."\n";
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
+
+ // allready exist in translation table ?
+
+ if (($dstID = ImpGetdstID ($data["ID"],$impid,DROPDOWN_LOCATIONS_TYPE)) < 0) {
+ print "Err update location not in translate ";
+ print $data["ID"]."\n";
+ return;
+ }
+ if (($dstENT= ImpGetdstID ($data["FK_entities"],$impid,ENTITY_TYPE)) < 0) $dstENT = 0; // default is root entity
+
+ $query = "UPDATE glpi_dropdown_locations SET FK_entities = $dstENT WHERE ID=$dstID";
+ if (! $DB->query($query)) {
+ print "\n".$query."\n"; print $data["ID"]." Err update location ent $dstENT -$dstID-\n"; return;
+ }
}
- else
- print "ImpUpdateLocationEntities Result empty ? \n";
+ }
+ else
+ print "ImpUpdateLocationEntities Nb Result ? :".$DB->numrows($result)."\n";
+ }
+ else
+ print "ImpUpdateLocationEntities Result empty ? \n";
}
-function ImpUpdateField($table,$field, $type,$impid,$entity)
+/**
+ * Update field in temporary tables to match with futur one.
+ * @param string $table
+ * @param string $field
+ * @param string $type
+ * @param int $impid synchronisation number
+ * @param string $entity pretty useless param before use for flat_entities
+ */
+function ImpUpdateField($table,$field, $type,$impid,$entity)
{
-Global $DB;
+ Global $DB;
+ Global $imp_flag_flat_entities;
-//$query = "update glpi_plugin_imp_computers SET $field = (SELECT dstID FROM glpi_plugin_imp_translate WHERE impID=$impid AND type=$type AND srcID = glpi_plugin_imp_computers.$field)";
-$query = "update $table SET $field = (SELECT dstID FROM glpi_plugin_imp_translate WHERE impID=$impid AND type=$type AND srcID = $table.$field)";
-// print $query."\n";
+ // HACK : if we update an entity, we set with $entity who come from ImpGetdstID (we hope)
+ // TODO : To Clean with better mechanism
+ if ($type == ENTITY_TYPE and $imp_flag_flat_entities)
+ $query = "update $table SET $field = $entity";
+ else
+ $query = "update $table t SET $field = (SELECT dstID FROM glpi_plugin_imp_translate WHERE impID=$impid AND type=$type AND srcID = t.$field)";
+ // print $query."\n";
-//if ($result = $DB->query($query)) print "Ok - $field mapping\n";
-if (!$result = $DB->query($query)) print "Err - $field mapping\n$query\n".mysql_error();
+ //if ($result = $DB->query($query)) print "Ok - $field mapping\n";
+ if (!$result = $DB->query($query)) print "Err - $field mapping\n$query\n".mysql_error();
}
-function ImpUpdateLocationTable($field, $type,$impid,$entity)
+function ImpUpdateLocationTable($field, $type,$impid,$entity)
{
- ImpUpdateField ("glpi_plugin_imp_dropdown_locations",$field, $type,$impid,$entity);
+ ImpUpdateField ("glpi_plugin_imp_dropdown_locations",$field, $type,$impid,$entity);
}
-function ImpUpdateComputerTable($field, $type,$impid,$entity)
+function ImpUpdateComputerTable($field, $type,$impid,$entity)
{
- ImpUpdateField ("glpi_plugin_imp_computers",$field, $type,$impid,$entity);
+ ImpUpdateField ("glpi_plugin_imp_computers",$field, $type,$impid,$entity);
}
-function ImpUpdateSoftwareTable($field, $type,$impid,$entity)
+function ImpUpdateSoftwareTable($field, $type,$impid,$entity)
{
- ImpUpdateField ("glpi_plugin_imp_software",$field, $type,$impid,$entity);
+ ImpUpdateField ("glpi_plugin_imp_software",$field, $type,$impid,$entity);
}
-function ImpUpdateSoftwareVersionTable($field, $type,$impid,$entity)
+function ImpUpdateSoftwareVersionTable($field, $type,$impid,$entity)
{
- ImpUpdateField ("glpi_plugin_imp_softwareversions",$field, $type,$impid,$entity);
+ ImpUpdateField ("glpi_plugin_imp_softwareversions",$field, $type,$impid,$entity);
}
-function ImpUpdateSoftwareInstTable($field, $type,$impid,$entity)
+function ImpUpdateSoftwareInstTable($field, $type,$impid,$entity)
{
- ImpUpdateField ("glpi_plugin_imp_inst_software",$field, $type,$impid,$entity);
+ ImpUpdateField ("glpi_plugin_imp_inst_software",$field, $type,$impid,$entity);
}
-function ImpUpdateSoftwareLicensesTable($field, $type,$impid,$entity)
+function ImpUpdateSoftwareLicensesTable($field, $type,$impid,$entity)
{
- ImpUpdateField ("glpi_plugin_imp_softwarelicenses",$field, $type,$impid,$entity);
+ ImpUpdateField ("glpi_plugin_imp_softwarelicenses",$field, $type,$impid,$entity);
}
-function ImpUpdateDeviceTable($field, $type,$impid,$entity)
+function ImpUpdateDeviceTable($field, $type,$impid,$entity)
{
- ImpUpdateField ("glpi_plugin_imp_computer_device",$field, $type,$impid,$entity);
+ ImpUpdateField ("glpi_plugin_imp_computer_device",$field, $type,$impid,$entity);
}
-function ImpImportEntity(&$config) {
- ImpLoadFile (&$config, "glpi_entities");
- ImpLoadTable (&$config, "glpi_entities",false);
+function ImpImportEntity($config) {
+ ImpLoadFile ($config, "glpi_entities");
+ ImpLoadTable ($config, "glpi_entities",false);
$impid = $config->fields["ID"];
$dstentity = $config->fields["dstentity"];
@@ -449,13 +504,14 @@
function ImpInitTranslateEntity ($impid, $srcentity,$dstentity,$sub=0) {
-global $DB;
+ global $DB;
-// Recursive treatment
+ // Recursive treatment
- if ($sub == 0) { // root entity must be in translate table
+ if ($sub == 0) {
+ // root entity must be in translate table
if ($srcentity > 0) {
- $query = "SELECT * FROM glpi_plugin_imp_entities WHERE ID = $srcentity" ; //
+ $query = "SELECT * FROM glpi_plugin_imp_entities WHERE ID = $srcentity" ; //
if ($result = $DB->query($query)) {
if ($DB->numrows($result)>0) {
$data = $DB->fetch_array($result);
@@ -464,8 +520,11 @@
}
else $data["completename"]="Root entity";
- if (($ret=ImpGetdstID($srcentity,$impid,ENTITY_TYPE))<-1) { // If not exist in translate table add it
- if (!ImpAddTranslate ($srcentity,$dstentity,$impid,ENTITY_TYPE,$data["completename"])) { print "Err db add translate"; return; }
+ if (($ret=ImpGetdstID($srcentity,$impid,ENTITY_TYPE))<-1) {
+ // If not exist in translate table add it
+ if (!ImpAddTranslate ($srcentity,$dstentity,$impid,ENTITY_TYPE)) {
+ print "Err db add translate\n"; return;
+ }
}
}
@@ -473,82 +532,152 @@
if ($result = $DB->query($query)) {
if ($DB->numrows($result)>0) {
while($data = $DB->fetch_array($result)) {
-// print $data["ID"]." ".$data["name"]." ".$data["completename"]." ".$data["parentID"]." ".$data["level"]."\n";
+ // print $data["ID"]." ".$data["name"]." ".$data["completename"]." ".$data["parentID"]." ".$data["level"]."\n";
- // Exist ? if not we create
+ // Exist ? if not we create
$dstID = ImpGetdstID ( $data["ID"],$impid,ENTITY_TYPE);
if ($dstID==-2 ) {
- if (!ImpAddTranslate ($data["ID"],-1,$impid,ENTITY_TYPE,$data["completename"])) { print "Err db"; return; }
+ if (!ImpAddTranslate ($data["ID"],-1,$impid,ENTITY_TYPE)) {
+ print "Err db\n"; return;
+ }
}
ImpInitTranslateEntity ($impid,$data["ID"],-1,1); // Recurse
}
- }
- } else { print "Err not exported 1"; return; }
+ }
+ } else { print "Err not exported 1\n"; return;
+ }
} // ImpInitTranslateEntity
-function ImpResetTranslate ($impID)
+
+/**
+ * Clean translate table of suppressed data inside local database
+ * @param unknown_type $impID
+ */
+function ImpRefreshTranslate ($impID)
{
-global $DB;
-global $tableliste;
+ global $DB;
+ global $tableliste;
reset($tableliste);
for ($i = 0; $i < count($tableliste); $i++)
{
- $index = key($tableliste);
- print "Clean for : ".$tableliste[$index]." ";
+ $index = key($tableliste);
+ print "Clean for : ".$tableliste[$index]." ";
- $dsttable = $tableliste[$index];
- $intable = str_replace ("glpi_","glpi_plugin_imp_",$dsttable);
+ $dsttable = $tableliste[$index];
+ $intable = str_replace ("glpi_","glpi_plugin_imp_",$dsttable);
- $query = "DELETE FROM glpi_plugin_imp_translate WHERE impID = $impID and type = $index and ".
- " not exists (select * from $intable WHERE ID=srcID ) ";
- if (!$DB->query($query)) print "Err ImpResetTranslate - $query\n";
+ $query = "DELETE FROM glpi_plugin_imp_translate WHERE impID = $impID and type = $index and ".
+ " not exists (SELECT * from $intable WHERE ID=srcID ) ";
+ if (!$DB->query($query))
+ print "Err ImpRefreshTranslate - $query\n";
- $query = "DELETE FROM glpi_plugin_imp_translate WHERE impID = $impID and type = $index and ".
- " not exists (select * from $dsttable WHERE ID=dstID ) ";
+ $query = "DELETE FROM glpi_plugin_imp_translate WHERE impID = $impID and type = $index and ".
+ " not exists (SELECT * FROM $dsttable WHERE ID=dstID ) ";
-print "\n";
- next($tableliste);
+ if (!$DB->query($query))
+ print "Err ImpRefreshTranslate - $query\n";
+
+ print "\n";
+ next($tableliste);
}
-//exit (0); // Temporary hack
+ //exit (0); // Temporary hack
}
+/**
+ * Reset Translation Table
+ * @param int $impID ID of import
+ */
+function ImpResetTranslate($impID="")
+{
+ global $DB;
+ if ($impID == "")
+ $query = "TRUNCATE glpi_plugin_imp_translate";
+ else
+ $query = "DELETE FROM glpi_plugin_imp_translate WHERE impID = $impID";
+ if (!$DB->query($query))
+ print "Err ImpResetTranslate - $query\n";
+}
+/**
+ * Reset Tables Computer, ...
+ * @param int $impID ID of import
+ */
+function ImpResetTables($impID)
+{
+ global $DB;
+
+ $query = "SELECT dstentity AS dstentity FROM glpi_plugin_imp_config WHERE ID=$impID";
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ $data = $DB->fetch_array($result);
+ $dstentity = $data["dstentity"];
+ }
+ }
+
+ DeleteEntity($dstentity);
+}
-
-function ImpRun (&$config,$log=false) {
-global $DB;
-global $tableliste;
-global $imp_flag_update_computer_vendor ;
-global $imp_flag_update_computer_model ;
-global $imp_flag_update_computer_type ;
-global $imp_flag_update_software_name ;
-global $imp_flag_update_software_category ;
-global $ImpLocalFile;
-global $ImpResetTranslate;
-
-// Imports data inside temporary tables
-
-// we recreate index droped normally by ImpLocation
-$query = "ALTER TABLE glpi_plugin_imp_dropdown_locations ADD UNIQUE INDEX name (`name`,`parentID`,`FK_entities`)";
-if (! $DB->query($query)) { print "Update location : index allready present (normal)\n$query\n"; } // We could got an error at first run
+/**
+ * Function on start ...
+ * @param config $config
+ * @param boolean $log
+ */
+function ImpRun ($config,$log=false) {
+ global $DB;
+ global $tableliste;
+ global $imp_flag_update_computer_vendor ;
+ global $imp_flag_update_computer_model ;
+ global $imp_flag_update_computer_type ;
+ global $imp_flag_update_software_name ;
+ global $imp_flag_update_software_category ;
+ global $imp_flag_flat_entities ;
+ global $ImpLocalFile;
+ global $ImpRefreshTranslate;
+ global $ImpReset;
+
+ // Imports data inside temporary tables
+
+ // we recreate index droped normally by ImpLocation
+ $query = "ALTER TABLE glpi_plugin_imp_dropdown_locations ADD UNIQUE INDEX name (`name`,`parentID`,`FK_entities`)";
+ if (! $DB->query($query)) {
+ print "Update location : index allready present (normal)\n$query\n";
+ } // We could got an error at first run
reset($tableliste);
for ($i = 0; $i < count($tableliste); $i++)
{
- $index = key($tableliste);
- print $tableliste[$index]." ";
- if ($ImpLocalFile == false ) print $err = ImpLoadFile (&$config, $tableliste[$index]); else $err =0;
- if ($err == -1 ) { fwrite ($log, "Error loading table ". $tableliste[$index]); return; }
- ImpLoadTable (&$config, $tableliste[$index],$recursive=false);
-print "\n";
- next($tableliste);
+ $index = key($tableliste);
+ print $tableliste[$index]." \n";
+
+ //Get information from other GLPI instance
+ if ($ImpLocalFile == false )
+ {
+ print "Get File from dumpentity\n";
+ $err = ImpLoadFile ($config, $tableliste[$index]);
+ }
+ else
+ {
+ print "Get file from Local\n";
+ $err =0;
+ }
+
+ if ($err == -1 )
+ {
+ fwrite ($log, "Error loading table ". $tableliste[$index]);
+ return;
+ }
+
+ print "Import files in temporary tables\n";
+ ImpLoadTable ($config, $tableliste[$index],$recursive=false);
+ print "\n";
+ next($tableliste);
}
-// get information from plugin table, and run recursively
+ // get information from plugin table, and run recursively
$impid = $config->fields["ID"];
$dstentity = $config->fields["dstentity"];
@@ -558,22 +687,33 @@
$imp_flag_update_computer_type = $config->fields["update_computer_type"];
$imp_flag_update_software_name = $config->fields["update_software_name"];
$imp_flag_update_software_category = $config->fields["update_software_category"];
+ $imp_flag_flat_entities = $config->fields["flat_entities"];
+
+ // ImpEntity ($impid,$srcentity,$dstentity);
+ // ImpSoftwareEntity ($impid,$srcentity,$dstentity);
+ // 0)
-// ImpEntity ($impid,$srcentity,$dstentity);
-// ImpSoftwareEntity ($impid,$srcentity,$dstentity);
-// 0) clean translate table of suppressed data inside local database
+ if ($ImpReset)
+ {
+ print "Reset translate\n";
+ ImpResetTranslate(); // remove in Translate table
+ print "Reset Tables (delete entity)\n";
+ ImpResetTables($impid); //remove computers and softwares
+ }
- if ($ImpResetTranslate == true) ImpResetTranslate($impid);
+ //Clean translate table of suppressed data inside local database
+ if ($ImpRefreshTranslate == true)
+ ImpRefreshTranslate($impid);
-// 1) create entities
+ // 1) create entities
ImpCreateEntity ($impid,$srcentity,$dstentity);
-// 2) import dropdown (and create them if needed )
+ // 2) import dropdown (and create them if needed )
// For computer
-
+ /* */
ImpDropdown ('glpi_plugin_imp_dropdown_domain','glpi_dropdown_domain',DROPDOWN_DOMAIN_TYPE,$impid);
ImpDropdown ('glpi_plugin_imp_dropdown_network','glpi_network',DROPDOWN_NETWORK_TYPE,$impid);
ImpDropdown ('glpi_plugin_imp_dropdown_auto_update','glpi_auto_update',DROPDOWN_AUTO_UPDATE_TYPE,$impid);
@@ -593,12 +733,14 @@
ImpDropDown ('glpi_plugin_imp_dropdown_budget','glpi_dropdown_budget',DROPDOWN_BUDGET_TYPE,$impid);
// Location
- $query = "ALTER TABLE glpi_plugin_imp_dropdown_locations DROP INDEX name"; // drop unicity index in conflict
- if (! $DB->query($query)) { print "Warning update location\n$query\n"; }
+ $query = "ALTER TABLE glpi_plugin_imp_dropdown_locations DROP INDEX name"; // drop unicity index in conflict
+ if (! $DB->query($query)) {
+ print "Warning update location\n$query\n";
+ }
ImpUpdateLocationTable('FK_entities', ENTITY_TYPE,$impid,$dstentity);
ImpLocation ($impid,$dstentity);
-// ImpUpdateLocationEntities($impid);
+ // ImpUpdateLocationEntities($impid);
// For devices
@@ -611,11 +753,12 @@
ImpDropdown ('glpi_plugin_imp_dropdown_ram_type','glpi_dropdown_ram_type',DROPDOWN_RAM_TYPE_TYPE,$impid);
-// 3) treat each table to import
+ // 3) treat each table to import
+ print "Destination entity : $dstentity\n";
ImpCreateComputer ($impid,$srcentity,$dstentity);
ImpCreateDevice ($impid,$srcentity,$dstentity);
-// Add create ... network_port
+ // Add create ... network_port
ImpCreateSoftware ($impid,$srcentity,$dstentity);
ImpCreateSoftwareVersion($impid,$srcentity,$dstentity);
ImpCreateSoftwareInst ($impid,$srcentity,$dstentity);
@@ -623,18 +766,28 @@
ImpCreateFinancialInformation ($impid,$srcentity,$dstentity);
}
+/**
+ * Create an Entity
+ * @param unknown_type $impid
+ * @param unknown_type $srcentity
+ * @param unknown_type $dstentity
+ * @param bool $sub
+ */
function ImpCreateEntity ($impid, $srcentity,$dstentity,$sub=0) {
-// prerequisite : dstentity allready exist in destination database (table glpi_entities)
-global $DB;
+ // prerequisite : dstentity allready exist in destination database (table glpi_entities)
+ global $DB;
+ global $imp_flag_flat_entities ;
-// Recursive treatment
-print "**** Create entity\n";
+ // Recursive treatment
+ print "**** Create entity\n";
- if ($sub == 0) { // dst root entity of import must be in translate table, we add it
+ if ($sub == 0) {
+ // dst root entity of import must be in translate table, we add it
if ($srcentity > 0) {
- $query = "SELECT * FROM glpi_plugin_imp_entities WHERE ID = $srcentity" ; //
- if ($result = $DB->query($query)) { // usefull for getting the completename
+ $query = "SELECT * FROM glpi_plugin_imp_entities WHERE ID = $srcentity" ; //
+ if ($result = $DB->query($query)) {
+ // usefull for getting the completename
if ($DB->numrows($result)>0) {
$data = $DB->fetch_array($result);
} else return; // error
@@ -644,14 +797,20 @@
if (($ret=ImpGetdstID($srcentity,$impid,ENTITY_TYPE))==-2) // Doesn't exist in translation table
{
- if (!ImpAddTranslate ($srcentity,$dstentity,$impid,ENTITY_TYPE,$data["completename"])) { print "Err db add translate"; return; }
+ if (!ImpAddTranslate ($srcentity,$dstentity,$impid,ENTITY_TYPE)) {
+ print "Err db add translate\n"; return;
+ }
}
else
- if ($ret==-1) // line allready exist and need to be updated
- {
- if (!ImpUpdateTranslate ($srcentity,$dstentity,$impid,ENTITY_TYPE,$data["completename"])) { print "Err db update translate"; return; }
+ if ($ret==-1) // line allready exist and need to be updated
+ {
+ if (!ImpUpdateTranslate ($srcentity,$dstentity,$impid,ENTITY_TYPE,$data["completename"])) {
+ print "Err db update translate\n"; return;
}
- else if ($ret == -3) { print "Err db "; return; }
+ }
+ else if ($ret == -3) {
+ print "Err db \n"; return;
+ }
}
$query = "SELECT * FROM glpi_entities WHERE id = $dstentity" ; // fetch entity to use for computing complete name and other information
@@ -660,25 +819,40 @@
$data = $DB->fetch_array($result);
$completename = $data["completename"];
$level = $data["level"];
- }
- else { print "Err entity does not exist id $dstentity"; return; }
+ }
+ else { print "Err entity does not exist id $dstentity\n"; return;
+ }
}
- else { print "Err entity does not exist id $dstentity"; return; } // must exist else it's an error
+ else { print "Err entity does not exist id $dstentity\n"; return;
+ } // must exist else it's an error
- // Treat son of entity
+ // if (! $imp_flag_flat_entities)
+ // {
+
+ // Treat son of entity
$query = "SELECT * FROM glpi_plugin_imp_entities WHERE parentid = $srcentity" ; // fetch childs
-// print $query."\n";
+ // print $query."\n";
if ($result = $DB->query($query)) {
if ($DB->numrows($result)>0) {
while($data = $DB->fetch_array($result)) {
print $data["ID"]." ".$data["name"]." ".$data["completename"]." ".$data["parentID"]." ".$data["level"]."\n";
- // Exist ? if not create
+ //Get dstID in translate table if not flat
+ //Else, get root ID.
$dstID = ImpGetdstID ( $data["ID"],$impid,ENTITY_TYPE);
- if ($dstID==-2 or $dstID==-1) { // Don't exist in translate
+
+ if ($imp_flag_flat_entities)
+ {
+ if (!ImpAddTranslate ($data["ID"],$dstID,$impid,ENTITY_TYPE)) {
+ print "Err db\n"; return;
+ }
+ }
+
+ if ($dstID==-2 or $dstID==-1) {
+ // Don't exist in translate
$ret = $dstID; $dstID = -1;
- $query = "SELECT ID FROM glpi_entities WHERE parentID = $dstentity AND name='".$data["name"]."'" ; // Allready exist in table?
+ $query = "SELECT ID FROM glpi_entities WHERE parentID = $dstentity AND name='".$data["name"]."'" ; // Allready exist in table?
// print $query."\n";
if ($result2 = $DB->query($query)) {
if ($DB->numrows($result2)>0) {
@@ -686,510 +860,689 @@
$dstID = $data2["ID"];
}
}
- if ($dstID == -1) { // Not found in glpi_entities
+ if ($dstID == -1) {
+ // Not found in glpi_entities
$query = "INSERT INTO glpi_entities (name,completename,parentID,level,comments) VALUES ('".
- $data["name"]."','".$completename." > ".$data["name"]."',".$dstentity.",".($level+1).",'')";
+ $data["name"]."','".$completename." > ".$data["name"]."',".$dstentity.",".($level+1).",'')";
if ($DB->query($query)) {
$dstID = $DB->insert_id();
- } else { print "Err Db"; return; }
+ } else { print "Err Db\n"; return;
+ }
}
- if ($ret==-2) { // don't exist in translate table
- if (!ImpAddTranslate ($data["ID"],$dstID,$impid,ENTITY_TYPE,$data["completename"])) { print "Err db"; return; }
+ if ($ret==-2) {
+ // don't exist in translate table
+ if (!ImpAddTranslate ($data["ID"],$dstID,$impid,ENTITY_TYPE)) {
+ print "Err db"; return;
+ }
}
- else { // exist, but partially initialized
- if (!ImpUpdateTranslate ($data["ID"],$dstID,$impid,ENTITY_TYPE,$data["completename"])) { print "Err db"; return; }
+ else { // exist, but partially initialized
+ if (!ImpUpdateTranslate ($data["ID"],$dstID,$impid,ENTITY_TYPE,$data["completename"])) {
+ print "Err db"; return;
+ }
}
}
- if ($dstID==-3) { print "err db"; return; }
+ if ($dstID==-3) {
+ print "err db\n"; return;
+ }
ImpCreateEntity ($impid,$data["ID"],$dstID,1); // recursivly treat son of this entity
}
- }
- } else { print "Err not exported 1"; return; }
-
+ }
+ }
+ else
+ {
+ print "Err not exported 1\n";
+ return;
+ }
+ // }
} // ImpCreateEntity
+/**
+ * Create a computer in database
+ * @param unknown_type $impid
+ * @param unknown_type $srcentity
+ * @param unknown_type $dstentity
+ */
function ImpCreateComputer ($impid, $srcentity,$dstentity)
{
-global $DB;
-global $imp_flag_update_computer_model;
-global $imp_flag_update_computer_type;
-global $imp_flag_update_computer_vendor;
-
-print "**** Create computer\n";
-$nb_item = 0;
-// Update computer table with good field
-
- ImpUpdateComputerTable('FK_entities', ENTITY_TYPE,$impid,$dstentity);
- ImpUpdateComputerTable('domain', DROPDOWN_DOMAIN_TYPE,$impid,$dstentity);
- ImpUpdateComputerTable('network', DROPDOWN_NETWORK_TYPE,$impid,$dstentity);
- ImpUpdateComputerTable('auto_update', DROPDOWN_AUTO_UPDATE_TYPE,$impid,$dstentity);
- ImpUpdateComputerTable('model', DROPDOWN_MODEL_TYPE,$impid,$dstentity);
- ImpUpdateComputerTable('os', DROPDOWN_OS_TYPE,$impid,$dstentity);
- ImpUpdateComputerTable('os_sp', DROPDOWN_OS_SP_TYPE,$impid,$dstentity);
- ImpUpdateComputerTable('os_version', DROPDOWN_OS_VERSION_TYPE,$impid,$dstentity);
- ImpUpdateComputerTable('state', DROPDOWN_STATE_TYPE,$impid,$dstentity);
+ global $DB;
+ global $imp_flag_update_computer_model;
+ global $imp_flag_update_computer_type;
+ global $imp_flag_update_computer_vendor;
+ global $ImpReset;
+
+ print "**** Create computer\n";
+ $nb_item = 0;
+ // Update computer table with good field
+
+ ImpUpdateComputerTable('FK_entities', ENTITY_TYPE,$impid,$dstentity);
+ ImpUpdateComputerTable('domain', DROPDOWN_DOMAIN_TYPE,$impid,$dstentity);
+ ImpUpdateComputerTable('network', DROPDOWN_NETWORK_TYPE,$impid,$dstentity);
+ ImpUpdateComputerTable('auto_update', DROPDOWN_AUTO_UPDATE_TYPE,$impid,$dstentity);
+ ImpUpdateComputerTable('model', DROPDOWN_MODEL_TYPE,$impid,$dstentity);
+ ImpUpdateComputerTable('os', DROPDOWN_OS_TYPE,$impid,$dstentity);
+ ImpUpdateComputerTable('os_sp', DROPDOWN_OS_SP_TYPE,$impid,$dstentity);
+ ImpUpdateComputerTable('os_version', DROPDOWN_OS_VERSION_TYPE,$impid,$dstentity);
+ ImpUpdateComputerTable('state', DROPDOWN_STATE_TYPE,$impid,$dstentity);
ImpUpdateComputerTable('FK_glpi_enterprise', DROPDOWN_MANUFACTURER_TYPE,$impid,$dstentity); // manufacturer = glpi data schema missmatch
- ImpUpdateComputerTable('type', TYPE_COMPUTERS_TYPE,$impid,$dstentity);
- ImpUpdateComputerTable('location', DROPDOWN_LOCATIONS_TYPE,$impid,$dstentity);
+ ImpUpdateComputerTable('type', TYPE_COMPUTERS_TYPE,$impid,$dstentity);
+ ImpUpdateComputerTable('location', DROPDOWN_LOCATIONS_TYPE,$impid,$dstentity);
-// update of changed computers
-
- $query = "SELECT * FROM glpi_plugin_imp_computers WHERE 1" ;
+ // update of changed computers
$type = COMPUTER_TYPE;
- if ($result = $DB->query($query)) {
- if ($DB->numrows($result)>0) {
- while($data = $DB->fetch_array($result)) {
- $nb_item ++;
- //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
- // allready exist in translation table ? (we could use a configuration flag to force the update here)
-
- $srcID = $data["ID"];
-
- $dstID = ImpGetdstID ( $srcID,$impid,$type);
- // create entry
- if ($dstID < 0) {
- $query = "INSERT INTO glpi_computers (name,comments) VALUES ('','')";
-// print $query."\n";
- if ($result2 = $DB->query($query)) {
+
+ if ($ImpReset)
+ {
+ $query = "SELECT ID FROM glpi_plugin_imp_computers" ;
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ $nb_item ++;
+ $query_insert = "INSERT INTO glpi_computers (FK_entities, name, serial, otherserial, contact, contact_num, tech_num, comments, date_mod, os, os_version, os_sp, os_license_number, os_license_id, auto_update, location, domain, network, model, type, is_template, tplname, FK_glpi_enterprise, deleted, notes, ocs_import, FK_users, FK_groups, state, ticket_tco) ".
+ "SELECT FK_entities, name, serial, otherserial, contact, contact_num, tech_num, comments, date_mod, os, os_version, os_sp, os_license_number, os_license_id, auto_update, location, domain, network, model, type, is_template, tplname, FK_glpi_enterprise, deleted, notes, ocs_import, FK_users, FK_groups, state, ticket_tco ".
+ "FROM glpi_plugin_imp_computers p ".
+ "WHERE p.ID = ".$data["ID"];
+ if ($DB->query($query_insert)) {
$dstID = $DB-> insert_id();
- if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) { print "Err db"; $dstID=-1; }
- else $new = true;
+ if (!ImpAddTranslate ($data["ID"],$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
}
- } else $new = false;
-
- if ($dstID >= 0) {
- // Update record
-
- $query = "UPDATE glpi_computers SET".
- " FK_entities = ".$data["FK_entities"].','.
- " FK_users = 0, FK_groups = 0, ".
- " name = '".addslashes($data["name"])."',".
- " serial = '". addslashes($data["serial"])."',".
- " otherserial = '". addslashes($data["otherserial"])."',".
- " contact = '".addslashes($data["contact"])."',".
- " contact_num = '".addslashes($data["contact_num"])."',".
- " tech_num = ".$data["tech_num"].",".
- " comments = '".addslashes($data["comments"])."',".
- " date_mod = '".addslashes($data["date_mod"])."',".
- " os = '".addslashes($data["os"])."',".
- " os_version = '".addslashes($data["os_version"])."',".
- " os_sp = '".addslashes($data["os_sp"])."',".
- " os_license_number = '".addslashes($data["os_license_number"])."',".
- " os_license_id = '".addslashes($data["os_license_id"])."',".
- " auto_update = ".$data["auto_update"].",".
- " location = ".$data["location"].",".
- " domain = ".$data["domain" ].",".
- " network = ".$data["network" ].",";
- if ($imp_flag_update_computer_model == true or $new == true)
- {
+ }
+ }
+ }
+ }
+ else
+ {
+ $query = "SELECT * FROM glpi_plugin_imp_computers" ;
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ $nb_item ++;
+ //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
+ // allready exist in translation table ? (we could use a configuration flag to force the update here)
+
+ $srcID = $data["ID"];
+ $dstID = ImpGetdstID ( $srcID,$impid,$type);
+ // create entry
+ if ($dstID < 0) {
+ $query = "INSERT INTO glpi_computers (name) VALUES ('')";
+ // print $query."\n";
+ if ($result2 = $DB->query($query)) {
+ $dstID = $DB-> insert_id();
+ if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
+ else $new = true;
+ }
+ } else $new = false;
+
+ if ($dstID >= 0) {
+ // Update record
+
+ $query = "UPDATE glpi_computers SET".
+ " FK_entities = ".$data["FK_entities"].','.
+ " FK_users = 0, FK_groups = 0, ".
+ " name = '".addslashes($data["name"])."',".
+ " serial = '". addslashes($data["serial"])."',".
+ " otherserial = '". addslashes($data["otherserial"])."',".
+ " contact = '".addslashes($data["contact"])."',".
+ " contact_num = '".addslashes($data["contact_num"])."',".
+ " tech_num = ".$data["tech_num"].",".
+ " comments = '".addslashes($data["comments"])."',".
+ " date_mod = '".addslashes($data["date_mod"])."',".
+ " os = '".addslashes($data["os"])."',".
+ " os_version = '".addslashes($data["os_version"])."',".
+ " os_sp = '".addslashes($data["os_sp"])."',".
+ " os_license_number = '".addslashes($data["os_license_number"])."',".
+ " os_license_id = '".addslashes($data["os_license_id"])."',".
+ " auto_update = ".$data["auto_update"].",".
+ " location = ".$data["location"].",".
+ " domain = ".$data["domain" ].",".
+ " network = ".$data["network" ].",";
+ if ($imp_flag_update_computer_model == true or $new == true)
+ {
$query .= " model = ".$data["model"].",";
}
- if ($imp_flag_update_computer_type == true or $new == true)
- {
+ if ($imp_flag_update_computer_type == true or $new == true)
+ {
$query .= " type = ".$data["type" ].",";
}
- if ($imp_flag_update_computer_vendor == true or $new == true)
- {
+ if ($imp_flag_update_computer_vendor == true or $new == true)
+ {
$query .= " FK_glpi_enterprise = ".$data["FK_glpi_enterprise"].",";
}
- $query.=" is_template = ".$data["is_template" ].",".
- " tplname = '".addslashes($data["tplname" ])."',".
- " deleted = ".$data["deleted" ].",".
- " notes = '".addslashes($data["notes" ])."',".
- " ocs_import = ".$data["ocs_import" ].",".
+ $query.=" is_template = ".$data["is_template" ].",".
+ " tplname = '".addslashes($data["tplname" ])."',".
+ " deleted = ".$data["deleted" ].",".
+ " notes = '".addslashes($data["notes" ])."',".
+ " ocs_import = ".$data["ocs_import" ].",".
// $data["FK_users" ],".
// $data["FK_groups" ],".
- " state = ".$data["state" ].",".
- " ticket_tco = ".$data["ticket_tco" ]." ".
- " WHERE ID=$dstID";
-// print $query."\n";
- if (! $DB->query($query)) print "Err db update computer $dstID\n";
- $query = "DELETE FROM glpi_inst_software WHERE cID = $dstID"; // Suppress installed software on computer
- if (! $DB->query($query)) print "Err db update computer $dstID\n";
+ " state = ".$data["state" ].",".
+ " ticket_tco = ".$data["ticket_tco" ]." ".
+ " WHERE ID=$dstID";
+ // print $query."\n";
+ if (! $DB->query($query)) print "Err db update computer $dstID\n";
+
+
+ $query = "DELETE FROM glpi_inst_software WHERE cID = $dstID"; // Suppress installed software on computer
+ if (! $DB->query($query)) print "Err db update computer $dstID\n";
+
+ }
}
+
}
-
+ else
+ print "Nb Result ? :".$DB->numrows($result)."\n";
}
else
- print "Nb Result ? :".$DB->numrows($result)."\n";
+ print "Result ? :".$result."\n";
+
+ // mark as deleted all computer absent from the import
+
+ $query = "update glpi_computers c set deleted = 1 where not exists (SELECT * FROM glpi_plugin_imp_translate t WHERE t.impID=$impid and t.type =$type AND t.dstID=c.ID) and FK_entities = $dstentity";
+ // print $query."\n";
+ if (!$result = $DB->query($query)) print "Err - update deleted\n";
}
- else
- print "Result ? :".$result."\n";
-
-// mark as deleted all computer absent from the import
-
- $query = "update glpi_computers set deleted = 1 where not exists (SELECT dstID FROM glpi_plugin_imp_translate WHERE impID=$impid and type =$type AND dstID=ID) and FK_entities = $dstentity";
-// print $query."\n";
- if (!$result = $DB->query($query)) print "Err - update deleted\n";
-print " Imported $nb_item\n";
+
+ print " Imported $nb_item\n";
}
+
function ImpCreateSoftware ($impid, $srcentity,$dstentity)
{
-// prerquisite : entity allready exist in destination database (table glpi_entities)
+ // prerquisite : entity allready exist in destination database (table glpi_entities)
-global $DB;
-global $ImpSoftAsRootEntity ;
-global $imp_flag_update_software_name;
-global $imp_flag_update_software_category;
+ global $DB;
+ global $ImpSoftAsRootEntity ;
+ global $imp_flag_update_software_name;
+ global $imp_flag_update_software_category;
+ global $ImpReset;
-print "**** Create software\n";
-$nb_item = 0;
+ print "**** Create software\n";
+ $nb_item = 0;
-// Update software table with good fields
+ // Update software table with good fields
- ImpUpdateSoftwareTable('FK_entities', ENTITY_TYPE,$impid,$dstentity);
+ ImpUpdateSoftwareTable('FK_entities', ENTITY_TYPE,$impid,$dstentity);
ImpUpdateSoftwareTable('location', DROPDOWN_LOCATIONS_TYPE,$impid,$dstentity);
ImpUpdateSoftwareTable('platform',DROPDOWN_OS_TYPE,$impid,$dstentity);
- ImpUpdateSoftwareTable('FK_glpi_enterprise', DROPDOWN_MANUFACTURER_TYPE,$impid,$dstentity);
+ ImpUpdateSoftwareTable('FK_glpi_enterprise', DROPDOWN_MANUFACTURER_TYPE,$impid,$dstentity);
ImpUpdateSoftwareTable('oldstate', DROPDOWN_STATE_TYPE,$impid,$dstentity);
ImpUpdateSoftwareTable('category', DROPDOWN_SOFTWARE_CATEGORY_TYPE,$impid,$dstentity);
-// update of changed software
+ // update of changed software
-// $query = "SELECT * FROM glpi_plugin_imp_software WHERE 1" ;
-// $type = SOFTWARE_TYPE;
-// if ($result = $DB->query($query)) {
-// if ($DB->numrows($result)>0) {
-// while($data = $DB->fetch_array($result)) {
-// //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
-// // allready exist in translation table ? (we could use a configuration flag to force the update here)
-//
-// $srcID = $data["ID"];
-//
-// $dstID = ImpGetdstID ( $srcID,$impid,$type);
-// // if ImpSoftAsRootEntity look if present in the root entity
-// if ($ImpSoftAsRootEntity == 1)
-// {
-// }
-//
-// // create entry
-// if ($dstID < 0) {
-// $query = "INSERT INTO glpi_software (name,comments) VALUES ('','')";
-// print $query."\n";
-// if ($result2 = $DB->query($query)) {
-// $dstID = $DB-> insert_id();
-// if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) { print "Err db"; $dstID=-1; }
-// else $new = true;
-// }
-// } else $new = false;
-// }
-// }
-// else
-// print "No Result ? :".$DB->numrows($result)."\n";
-// }
-// else
-// print "DB access Result ? :".$result."\n";
+ // $query = "SELECT * FROM glpi_plugin_imp_software WHERE 1" ;
+ // $type = SOFTWARE_TYPE;
+ // if ($result = $DB->query($query)) {
+ // if ($DB->numrows($result)>0) {
+ // while($data = $DB->fetch_array($result)) {
+ // //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
+ // // allready exist in translation table ? (we could use a configuration flag to force the update here)
+ //
+ // $srcID = $data["ID"];
+ //
+ // $dstID = ImpGetdstID ( $srcID,$impid,$type);
+ // // if ImpSoftAsRootEntity look if present in the root entity
+ // if ($ImpSoftAsRootEntity == 1)
+ // {
+ // }
+ //
+ // // create entry
+ // if ($dstID < 0) {
+ // $query = "INSERT INTO glpi_software (name,comments) VALUES ('','')";
+ // print $query."\n";
+ // if ($result2 = $DB->query($query)) {
+ // $dstID = $DB-> insert_id();
+ // if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) { print "Err db"; $dstID=-1; }
+ // else $new = true;
+ // }
+ // } else $new = false;
+ // }
+ // }
+ // else
+ // print "No Result ? :".$DB->numrows($result)."\n";
+ // }
+ // else
+ // print "DB access Result ? :".$result."\n";
ImpUpdateSoftwareTable('update_software',SOFTWARE_TYPE,$impid,$dstentity); // Hum ... la poule et l'oeuf ... a faire à la fin
- $query = "SELECT * FROM glpi_plugin_imp_software WHERE 1" ;
$type = SOFTWARE_TYPE;
- if ($result = $DB->query($query)) {
- if ($DB->numrows($result)>0) {
- while($data = $DB->fetch_array($result)) {
- $nb_item ++;
- //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
- // allready exist in translation table ? (we could use a configuration flag to force the update here)
-
- $srcID = $data["ID"];
-
- $dstID = ImpGetdstID ( $srcID,$impid,$type);
-
- // create entry
- // if ($dstID == -1) {
- if ($dstID < 0) {
-// test of root presence of software must be here
- $query = "INSERT INTO glpi_software (name,comments) VALUES ('','')";
-// print $query."\n";
- if ($result2 = $DB->query($query)) {
+
+ if ($ImpReset)
+ {
+ $query = "SELECT ID FROM glpi_plugin_imp_software" ;
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ $nb_item ++;
+ $query_insert ="INSERT INTO glpi_software (FK_entities, recursive, name, comments, location, tech_num, platform, is_update, update_software, FK_glpi_enterprise, deleted, is_template, tplname, date_mod, notes, FK_users, FK_groups, oldstate, ticket_tco, helpdesk_visible, category) ".
+ "SELECT FK_entities, recursive, name, comments, location, tech_num, platform, is_update, update_software, FK_glpi_enterprise, deleted, is_template, tplname, date_mod, notes, FK_users, FK_groups, oldstate, ticket_tco, helpdesk_visible, category ".
+ "FROM glpi_plugin_imp_software s ".
+ "WHERE s.ID = ".$data["ID"];
+
+ if ($DB->query($query_insert)) {
$dstID = $DB-> insert_id();
- if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) { print "Err db"; $dstID=-1; }
- else $new = true;
+ if (!ImpAddTranslate ($data["ID"],$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
}
- } else $new = false;
- // print "Err db $srcID\n";
- // }
- if ($dstID >= 0) {
- // Update record
-
- $query = "UPDATE glpi_software SET".
- " FK_entities = ".$data["FK_entities"].','.
- " recursive = ".$data["recursive"].",";
- if ($imp_flag_update_software_name == true or $new == true)
- {
+ }
+ }
+ }
+ }
+ else
+ {
+ $query = "SELECT * FROM glpi_plugin_imp_software WHERE 1" ;
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ $nb_item ++;
+ //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
+ // allready exist in translation table ? (we could use a configuration flag to force the update here)
+ $srcID = $data["ID"];
+ $dstID = ImpGetdstID ( $srcID,$impid,$type);
+
+ // create entry
+ // if ($dstID == -1) {
+ if ($dstID < 0) {
+ // test of root presence of software must be here
+ $query = "INSERT INTO glpi_software (name) VALUES ('')";
+ // print $query."\n";
+ if ($result2 = $DB->query($query)) {
+ $dstID = $DB-> insert_id();
+ if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
+ else $new = true;
+ }
+ } else $new = false;
+
+ if ($dstID >= 0) {
+ // Update record
+
+ $query = "UPDATE glpi_software SET".
+ " FK_entities = ".$data["FK_entities"].','.
+ " recursive = ".$data["recursive"].",";
+ if ($imp_flag_update_software_name == true or $new == true)
+ {
$query .= " name = '".addslashes($data["name"])."',";
}
- if ($imp_flag_update_software_category == true or $new == true)
- {
+ if ($imp_flag_update_software_category == true or $new == true)
+ {
$query .= " category = ".$data["category"].",";
}
- $query.=" comments = '".addslashes($data["comments"])."',".
- " location = ".$data["location"].",".
- " tech_num = ".$data["tech_num"].",".
- " platform = ".$data["platform"].",".
- " is_update = ".$data["is_update"].",".
- " update_software = ".$data["update_software"].",".
- " FK_glpi_enterprise = ".$data["FK_glpi_enterprise"].",".
- " deleted = ".$data["deleted" ].",".
- " is_template = ".$data["is_template" ].",".
- " tplname = '".addslashes($data["tplname" ])."',".
- " date_mod = '".addslashes($data["date_mod"])."',".
- " notes = '".addslashes($data["notes" ])."',".
- " FK_users = 0, FK_groups = 0, ".
- " oldstate = ".$data["oldstate" ].",".
- " ticket_tco = ".$data["ticket_tco" ].",".
- " helpdesk_visible = ".$data["helpdesk_visible"]." ".
- " WHERE ID=$dstID";
-// print $query."\n";
- if (! $DB->query($query)) print "Err db update softare $dstID\n";
- $query = "DELETE FROM glpi_softwareversions WHERE sID = $dstID"; // clean version table
- if (! $DB->query($query)) print "Err db update softare clean version table $dstID\n";
+ $query.=" comments = '".addslashes($data["comments"])."',".
+ " location = ".$data["location"].",".
+ " tech_num = ".$data["tech_num"].",".
+ " platform = ".$data["platform"].",".
+ " is_update = ".$data["is_update"].",".
+ " update_software = ".$data["update_software"].",".
+ " FK_glpi_enterprise = ".$data["FK_glpi_enterprise"].",".
+ " deleted = ".$data["deleted" ].",".
+ " is_template = ".$data["is_template" ].",".
+ " tplname = '".addslashes($data["tplname" ])."',".
+ " date_mod = '".addslashes($data["date_mod"])."',".
+ " notes = '".addslashes($data["notes" ])."',".
+ " FK_users = 0, FK_groups = 0, ".
+ " oldstate = ".$data["oldstate" ].",".
+ " ticket_tco = ".$data["ticket_tco" ].",".
+ " helpdesk_visible = ".$data["helpdesk_visible"]." ".
+ " WHERE ID=$dstID";
+ // print $query."\n";
+ if (! $DB->query($query)) print "Err db update softare $dstID\n";
+ $query = "DELETE FROM glpi_softwareversions WHERE sID = $dstID"; // clean version table
+ if (! $DB->query($query)) print "Err db update softare clean version table $dstID\n";
+ }
}
}
-
+ else
+ print "Nb Result ? :".$DB->numrows($result)."\n";
}
else
- print "Nb Result ? :".$DB->numrows($result)."\n";
- }
- else
print "Result ? :".$result."\n";
-
-// mark as deleted all software absent from the import
-
- $query = "update glpi_software set deleted = 1 where not exists (SELECT dstID FROM glpi_plugin_imp_translate WHERE impID=$impid and type =$type AND dstID=ID) and FK_entities = $dstentity";
-// print $query."\n";
- if (!$result = $DB->query($query)) print "Err - update deleted\n";
- $query = "DELETE FROM glpi_plugin_imp_translate WHERE impID=$impid and type = ". SOFTWAREVERSION_TYPE .
- " and not exists (select * from glpi_softwareversions where ID=dstID)";
- if (! $DB->query($query)) print "Err db update softare clean translate table $query\n";
-
+
+ // mark as deleted all software absent from the import
+ $query = "update glpi_software set deleted = 1 where not exists (SELECT dstID FROM glpi_plugin_imp_translate WHERE impID=$impid and type =$type AND dstID=ID) and FK_entities = $dstentity";
+ // print $query."\n";
+ if (!$result = $DB->query($query)) print "Err - update deleted\n";
+ $query = "DELETE FROM glpi_plugin_imp_translate WHERE impID=$impid and type = ". SOFTWAREVERSION_TYPE .
+ " and not exists (select * from glpi_softwareversions where ID=dstID)";
+ if (! $DB->query($query)) print "Err db update softare clean translate table $query\n";
+ }
// ImpUpdateSoftwareTable('update_software',SOFTWARE_TYPE,$impid,$dstentity); // Hum ... la poule et l'oeuf ... a faire à la fin ???
-// Post Treatement of software ....
-// update update_software field
-// $query = "update glpi_software set update_software = (select dstID from glpi_plugin_imp_translate WHERE impID=$impid and type =$type AND srcID=update_software)";
-// $query .= " WHERE ID IN (select dstID from glpi_plugin_imp_translate where srcID in (select ID from glpi_plugin_imp_software))";
-//print $query."\n";
-// if (!$result = $DB->query($query)) print "Err - update_software\n";
-print " Imported $nb_item\n";
+ // Post Treatement of software ....
+ // update update_software field
+ // $query = "update glpi_software set update_software = (select dstID from glpi_plugin_imp_translate WHERE impID=$impid and type =$type AND srcID=update_software)";
+ // $query .= " WHERE ID IN (select dstID from glpi_plugin_imp_translate where srcID in (select ID from glpi_plugin_imp_software))";
+ //print $query."\n";
+ // if (!$result = $DB->query($query)) print "Err - update_software\n";
+ print "Imported $nb_item\n";
} // ImpCreateSoftware
function ImpCreateSoftwareVersion ($impid, $srcentity,$dstentity) {
-global $DB;
-global $ImpSoftAsRootEntity ;
+ global $DB;
+ global $ImpSoftAsRootEntity ;
+ global $ImpReset;
+
+ print "**** Create Software version\n";
+ // Update software versions
+ ImpUpdateSoftwareVersionTable('sID',SOFTWARE_TYPE,$impid,$dstentity);
+ ImpUpdateSoftwareVersionTable('state', DROPDOWN_STATE_TYPE,$impid,$dstentity);
-print "**** Create Software version\n";
- // Update software versions
- ImpUpdateSoftwareVersionTable('sID',SOFTWARE_TYPE,$impid,$dstentity);
- ImpUpdateSoftwareVersionTable('state', DROPDOWN_STATE_TYPE,$impid,$dstentity);
-
- $query = "SELECT * FROM glpi_plugin_imp_softwareversions WHERE 1" ;
- $type = SOFTWAREVERSION_TYPE;
+ $type = SOFTWAREVERSION_TYPE;
+
+ $nb_item = 0;
+
+
+ if ($ImpReset)
+ {
+ $query = "SELECT ID FROM glpi_plugin_imp_softwareversions" ;
if ($result = $DB->query($query)) {
if ($DB->numrows($result)>0) {
while($data = $DB->fetch_array($result)) {
- //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
- // allready exist in translation table ? (we could use a configuration flag to force the update here)
+ $nb_item ++;
+ $query_insert = "INSERT INTO glpi_softwareversions (sID, state, name, comments) ".
+ "SELECT sID, state, name, comments ".
+ "FROM glpi_plugin_imp_softwareversions v ".
+ "WHERE v.ID = ".$data["ID"];
+ if ($DB->query($query_insert)) {
+ $dstID = $DB-> insert_id();
+ if (!ImpAddTranslate ($data["ID"],$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ $query = "SELECT * FROM glpi_plugin_imp_softwareversions WHERE 1" ;
+
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ $nb_item ++;
+ //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
+ // allready exist in translation table ? (we could use a configuration flag to force the update here)
+
$srcID = $data["ID"];
-
$dstID = ImpGetdstID ( $srcID,$impid,$type);
-
- // create entry
+
+ // create entry
if ($dstID < 0) {
$query = "INSERT INTO glpi_softwareversions (sID,state,name,comments) VALUES (".
- " ".$data["sID"].",".
- " ".$data["state" ].",".
- " '".addslashes($data["name"])."',".
- " '".addslashes($data["comments"])."')";
-// Debug //
-// print $query;
-// Debug //
-
-// print $query."\n";
+ " ".$data["sID"].",".
+ " ".$data["state" ].",".
+ " '".addslashes($data["name"])."',".
+ " '".addslashes($data["comments"])."')";
+ // Debug //
+ // print $query;
+ // Debug //
+
+ // print $query."\n";
if ($result2 = $DB->query($query)) {
$dstID = $DB-> insert_id();
- if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) { print "Err db"; $dstID=-1; }
-// Debug //
-// print " $srcID to $dstID\n";
-// Debug //
+ if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
+ // Debug //
+ // print " $srcID to $dstID\n";
+ // Debug //
+ }
+ else { print "Err create software version ".mysql_error()."\n$query\n";
}
- else { print "Err create software version ".mysql_error()."\n$query\n"; }
}
else {
- // Update record
+ // Update record
$query = "UPDATE glpi_softwareversions SET ".
- "sID = ". $data["sID"].",".
- "state = ".$data["state" ].",".
- "name = '".addslashes($data["name"])."',".
- "comments = '".addslashes($data["comments"])."' ".
- " where ID= $dstID";
- // print $query."\n";
- if (! $DB->query($query)) print "Err db update softareversion $dstID\n$query\ny";
+ "sID = ". $data["sID"].",".
+ "state = ".$data["state" ].",".
+ "name = '".addslashes($data["name"])."',".
+ "comments = '".addslashes($data["comments"])."' ".
+ " where ID= $dstID";
+ // print $query."\n";
+ if (! $DB->query($query)) print "Err db update softareversion $dstID\n$query\ny\n";
}
}
-
+
}
else
- print "Softwareversions Nb Result ? :".$DB->numrows($result)."\n";
+ print "Softwareversions Nb Result ? :".$DB->numrows($result)."\n";
}
else
- print "Softwareversions Result ? \n";
+ print "Softwareversions Result ? \n";
+ }
+ print "Imported $nb_item\n";
+
} // ImpCreateSoftwareVersion
-
function ImpCreateSoftwareInst ($impid, $srcentity,$dstentity) {
-global $DB;
+ global $DB;
+ global $ImpReset;
-print "**** Create Software Instalation\n";
- // Update software install
- ImpUpdateSoftwareInstTable('vID',SOFTWAREVERSION_TYPE,$impid,$dstentity);
- ImpUpdateSoftwareInstTable('cID', COMPUTER_TYPE,$impid,$dstentity);
+ print "**** Create Software Instalation\n";
+ // Update software install
+ ImpUpdateSoftwareInstTable('vID',SOFTWAREVERSION_TYPE,$impid,$dstentity);
+ ImpUpdateSoftwareInstTable('cID', COMPUTER_TYPE,$impid,$dstentity);
- // Erase software installation for computer in the translate table (we only manage those)
+ // Erase software installation for computer in the translate table (we only manage those)
- $query = "DELETE FROM glpi_inst_software WHERE cID IN (SELECT dstID FROM glpi_plugin_imp_translate WHERE impID=$impid and type = ".COMPUTER_TYPE.")";
- if (! $DB->query($query)) { print "CreateSoftareInst - err delete\n$query\n"; return; }
-
-
- $query = "SELECT * FROM glpi_plugin_imp_inst_software WHERE 1" ;
- $type = INST_SOFTWARE_TYPE;
+ $type = INST_SOFTWARE_TYPE;
+ $nb_item = 0;
+
+ if ($ImpReset)
+ {
+ $query = "SELECT ID FROM glpi_plugin_imp_inst_software" ;
if ($result = $DB->query($query)) {
if ($DB->numrows($result)>0) {
while($data = $DB->fetch_array($result)) {
- //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
- // allready exist in translation table ? (we could use a configuration flag to force the update here)
+ $nb_item ++;
+ $query_insert = "INSERT INTO glpi_inst_software (cID, vID) ".
+ "SELECT cID, vID ".
+ "FROM glpi_plugin_imp_inst_software i ".
+ "WHERE i.ID = ".$data["ID"];
+
+ if ($DB->query($query_insert)) {
+ $dstID = $DB-> insert_id();
+ if (!ImpAddTranslate ($data["ID"],$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ $query = "DELETE ".
+ "FROM glpi_inst_software ".
+ "WHERE EXISTS ".
+ "(SELECT * FROM glpi_plugin_imp_translate t WHERE glpi_inst_software.cID = t.dstID AND t.impID=$impid and t.type = ".COMPUTER_TYPE.")";
+ if (! $DB->query($query)) {
+ print "CreateSoftareInst - err delete\n$query\n"; return;
+ }
+
+
+
+ $query = "SELECT * FROM glpi_plugin_imp_inst_software WHERE 1" ;
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
+ // allready exist in translation table ? (we could use a configuration flag to force the update here)
+
+ $nb_item ++;
+
$srcID = $data["ID"];
-
$dstID = ImpGetdstID ( $srcID,$impid,$type);
-
- // create entry
-
+
+ // create entry
+
if ($dstID < 0) {
$query = "INSERT INTO glpi_inst_software (vID,cID) VALUES (".
- " ".$data["vID"].",".
- " ".$data["cID"].")";
-// print $query."\n";
+ " ".$data["vID"].",".
+ " ".$data["cID"].")";
+ // print $query."\n";
if ($result2 = $DB->query($query)) {
$dstID = $DB-> insert_id();
- if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) { print "Err db"; $dstID=-1; }
+ if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
}
}
else {
$query = "INSERT INTO glpi_inst_software (ID,vID,cID) VALUES (".
- " ".$dstID."," .
- " ".$data["vID"].",".
- " ".$data["cID"].")";
- // print $query."\n";
+ " ".$dstID."," .
+ " ".$data["vID"].",".
+ " ".$data["cID"].")";
+ // print $query."\n";
if (! $DB->query($query)) print "Err db update inst_softare $dstID\n$query\n";
-
+
}
}
-
+
}
else
- print "Inst Softwareversions No Result ? :".$DB->numrows($result)."\n";
+ print "Inst Softwareversions No Result ? :".$DB->numrows($result)."\n";
}
else
- print "Inst Softwareversions Result ? ".mysql_error()."\n";
-
+ print "Inst Softwareversions Result ? ".mysql_error()."\n";
+ }
+ print "Imported $nb_item\n";
}
-function ImpCreateSoftwareLicenses ($impid, $srcentity,$dstentity) {
-global $DB;
-
-print "**** Create Software Licenses\n";
- // Update software licenses
- ImpUpdateSoftwareLicensesTable('FK_entities', ENTITY_TYPE,$impid,$dstentity);
- ImpUpdateSoftwareLicensesTable('sID',SOFTWARE_TYPE,$impid,$dstentity);
- ImpUpdateSoftwareLicensesTable('type', DROPDOWN_LICENSETYPES_TYPE,$impid,$dstentity);
- ImpUpdateSoftwareLicensesTable('buy_version',SOFTWAREVERSION_TYPE,$impid,$dstentity);
- ImpUpdateSoftwareLicensesTable('use_version',SOFTWAREVERSION_TYPE,$impid,$dstentity);
- ImpUpdateSoftwareLicensesTable('FK_computers', COMPUTER_TYPE,$impid,$dstentity);
-// update of changed software
+function ImpCreateSoftwareLicenses ($impid, $srcentity,$dstentity) {
+ global $DB;
+ global $ImpReset;
+ print "**** Create Software Licenses\n";
+ // Update software licenses
+ ImpUpdateSoftwareLicensesTable('FK_entities', ENTITY_TYPE,$impid,$dstentity);
+ ImpUpdateSoftwareLicensesTable('sID',SOFTWARE_TYPE,$impid,$dstentity);
+ ImpUpdateSoftwareLicensesTable('type', DROPDOWN_LICENSETYPES_TYPE,$impid,$dstentity);
+ ImpUpdateSoftwareLicensesTable('buy_version',SOFTWAREVERSION_TYPE,$impid,$dstentity);
+ ImpUpdateSoftwareLicensesTable('use_version',SOFTWAREVERSION_TYPE,$impid,$dstentity);
+ ImpUpdateSoftwareLicensesTable('FK_computers', COMPUTER_TYPE,$impid,$dstentity);
- $query = "SELECT * FROM glpi_plugin_imp_softwarelicenses WHERE 1" ;
- $type = SOFTWARELICENSE_TYPE;
+ $nb_item = 0;
+ // update of changed software
+
+ if ($ImpReset)
+ {
+ $query = "SELECT ID FROM glpi_plugin_imp_softwarelicenses" ;
if ($result = $DB->query($query)) {
- if ($DB->numrows($result)>0) {
- while($data = $DB->fetch_array($result)) {
- //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
- // allready exist in translation table ? (we could use a configuration flag to force the update here)
-
- $srcID = $data["ID"];
-
- $dstID = ImpGetdstID ( $srcID,$impid,$type);
-
- // create entry
- if ($dstID < 0) {
- $query = "INSERT INTO glpi_softwarelicenses (name,comments) VALUES ('','')";
-// print $query."\n";
- if ($result2 = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ $nb_item ++;
+ $query_insert = "INSERT INTO glpi_softwarelicenses (sID, FK_entities, recursive, number, type, name, serial, otherserial, buy_version, use_version, expire, FK_computers, comments) ".
+ "SELECT sID, FK_entities, recursive, number, type, name, serial, otherserial, buy_version, use_version, expire, FK_computers, comments ".
+ "FROM glpi_plugin_imp_softwarelicenses i ".
+ "WHERE i.ID = ".$data["ID"];
+
+ if ($DB->query($query_insert)) {
$dstID = $DB-> insert_id();
- if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) { print "Err db"; $dstID=-1; }
+ if (!ImpAddTranslate ($data["ID"],$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
}
}
- if ($dstID >= 0) {
- // Update record
-
- if ($data["expire"] == '') $expire = "NULL"; else $expire = $data["expire"];
-
- $query = "UPDATE glpi_softwarelicenses SET".
- " sID = ".$data["sID"].",".
- " FK_entities = ".$data["FK_entities"].','.
- " recursive = ".$data["recursive" ].",".
- " number = ".$data["number" ].",".
- " type = ".$data["type" ].",".
- " name = '".addslashes($data["name"])."',".
- " serial = '".addslashes($data["serial"])."',".
- " otherserial = '".addslashes($data["otherserial"])."',".
- " buy_version = ".$data["buy_version"].",".
- " use_version = ".$data["use_version"].",".
- " expire = ".$expire.",".
- " FK_computers = ".$data["FK_computers"].",".
- " comments = '".addslashes($data["comments"])."' ".
- " WHERE ID=$dstID";
-// print $query."\n";
- if (! $DB->query($query)) print "Err db update license : $dstID - $query - ".mysql_error()."\n";
- }
}
-
}
- else
- print "ImpSoftwareLicenses Nb Result ? :".$DB->numrows($result)."\n";
}
else
+ {
+
+ $query = "SELECT * FROM glpi_plugin_imp_softwarelicenses WHERE 1" ;
+ $type = SOFTWARELICENSE_TYPE;
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
+ // allready exist in translation table ? (we could use a configuration flag to force the update here)
+
+ $nb_item++;
+
+ $srcID = $data["ID"];
+ $dstID = ImpGetdstID ( $srcID,$impid,$type);
+
+ // create entry
+ if ($dstID < 0) {
+ $query = "INSERT INTO glpi_softwarelicenses (name,comments) VALUES ('','')";
+ // print $query."\n";
+ if ($result2 = $DB->query($query)) {
+ $dstID = $DB-> insert_id();
+ if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
+ }
+ }
+ if ($dstID >= 0) {
+ // Update record
+
+ if ($data["expire"] == '') $expire = "NULL"; else $expire = $data["expire"];
+
+ $query = "UPDATE glpi_softwarelicenses SET".
+ " sID = ".$data["sID"].",".
+ " FK_entities = ".$data["FK_entities"].','.
+ " recursive = ".$data["recursive" ].",".
+ " number = ".$data["number" ].",".
+ " type = ".$data["type" ].",".
+ " name = '".addslashes($data["name"])."',".
+ " serial = '".addslashes($data["serial"])."',".
+ " otherserial = '".addslashes($data["otherserial"])."',".
+ " buy_version = ".$data["buy_version"].",".
+ " use_version = ".$data["use_version"].",".
+ " expire = ".$expire.",".
+ " FK_computers = ".$data["FK_computers"].",".
+ " comments = '".addslashes($data["comments"])."' ".
+ " WHERE ID=$dstID";
+ // print $query."\n";
+ if (! $DB->query($query)) print "Err db update license : $dstID - $query - ".mysql_error()."\n";
+ }
+ }
+
+ }
+ else
+ print "ImpSoftwareLicenses Nb Result ? :".$DB->numrows($result)."\n";
+ }
+ else
print "ImpSoftwareLicenses Result ? \n";
-
+ }
+ print "Imported $nb_item\n";
}
function ImpCreateDevice ($impid, $srcentity,$dstentity) {
-global $DB;
-/*
- define("MOBOARD_DEVICE",1);
- define("PROCESSOR_DEVICE",2);
- define("RAM_DEVICE",3);
- define("HDD_DEVICE",4);
- define("NETWORK_DEVICE",5);
- define("DRIVE_DEVICE",6);
- define("CONTROL_DEVICE",7);
- define("GFX_DEVICE",8);
- define("SND_DEVICE",9);
- define("PCI_DEVICE",10);
- define("CASE_DEVICE",11);
- define("POWER_DEVICE",12);
-*/
+ global $DB;
+ global $ImpReset;
+ /*
+ define("MOBOARD_DEVICE",1);
+ define("PROCESSOR_DEVICE",2);
+ define("RAM_DEVICE",3);
+ define("HDD_DEVICE",4);
+ define("NETWORK_DEVICE",5);
+ define("DRIVE_DEVICE",6);
+ define("CONTROL_DEVICE",7);
+ define("GFX_DEVICE",8);
+ define("SND_DEVICE",9);
+ define("PCI_DEVICE",10);
+ define("CASE_DEVICE",11);
+ define("POWER_DEVICE",12);
+ */
-print "**** Create computer Device\n";
+ print "**** Create computer Device\n";
ImpCreateDeviceItem( MOBOARD_DEVICE ,$impid,$srcentity, $dstentity);
ImpCreateDeviceItem( PROCESSOR_DEVICE ,$impid,$srcentity, $dstentity);
@@ -1204,106 +1557,142 @@
ImpCreateDeviceItem( CASE_DEVICE ,$impid,$srcentity, $dstentity);
ImpCreateDeviceItem( POWER_DEVICE ,$impid,$srcentity, $dstentity);
-// Update device table with good field
-
- ImpUpdateDeviceTable('FK_computers', COMPUTER_TYPE,$impid,$dstentity);
-
-// update of changed computers
-
- $query = "SELECT * FROM glpi_plugin_imp_computer_device WHERE 1" ;
- $type = COMPUTER_DEVICE_TYPE;
- if ($result = $DB->query($query)) {
- if ($DB->numrows($result)>0) {
- while($data = $DB->fetch_array($result)) {
- //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
- // allready exist in translation table ? (we could use a configuration flag to force the update here)
+ // Update device table with good field
- $srcID = $data["ID"];
+ ImpUpdateDeviceTable('FK_computers', COMPUTER_TYPE,$impid,$dstentity);
- $dstID = ImpGetdstID ( $srcID,$impid,$type);
+ // update of changed computers
+
+ $nb_item = 0;
- // create entry
- if ($dstID < 0) {
- $query = "INSERT INTO glpi_computer_device (specificity) VALUES ('')";
-// print $query."\n";
- if ($result2 = $DB->query($query)) {
+/* if ($ImpReset)
+ {
+ $query = "SELECT ID FROM glpi_plugin_imp_computer_device" ;
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ $nb_item ++;
+ $query_insert = "INSERT INTO glpi_computer_device (specificity, device_type, FK_device, FK_computers) ".
+ "SELECT specificity, device_type, FK_device, FK_computers ".
+ "FROM glpi_plugin_imp_computer_device i ".
+ "WHERE i.ID = ".$data["ID"];
+
+ if ($DB->query($query_insert)) {
$dstID = $DB-> insert_id();
- if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) { print "Err db"; $dstID=-1; }
+ if (!ImpAddTranslate ($data["ID"],$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
}
}
- if ($dstID >= 0) {
- // Update record
-
- switch ($data["device_type"])
- {
- case MOBOARD_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_MOBOARD_TYPE); break;
- case PROCESSOR_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_PROCESSOR_TYPE); break;
- case RAM_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_RAM_TYPE); break;
- case HDD_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_HDD_TYPE); break;
- case NETWORK_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_IFACE_TYPE); break;
- case DRIVE_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_DRIVE_TYPE); break;
- case CONTROL_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_CONTROL_TYPE); break;
- case GFX_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_GFXCARD_TYPE); break;
- case SND_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_SNDCARD_TYPE); break;
- case PCI_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_PCI_TYPE); break;
- case CASE_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_CASE_TYPE); break;
- case POWER_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_POWER_TYPE); break;
- default : $queryId = "0";
- }
- $query = "UPDATE glpi_computer_device SET".
- " FK_computers = ".$data["FK_computers"].','.
- " specificity = '".addslashes($data["specificity"])."',".
- " device_type = ".$data["device_type"].",".
- " FK_device = $queryId".
- " WHERE ID=$dstID";
-
- if ($queryId < 0)
- {
- print $data["device_type"]." ".$data["FK_device"]."\n";
- print $query."\n";
- }
-
- if (! $DB->query($query)) print "Err db update device $dstID\n";
- }
}
-
}
- else
- print "No Result ? :".$DB->numrows($result)."\n";
}
else
+ { */
+ $query = "SELECT * FROM glpi_plugin_imp_computer_device WHERE 1" ;
+ $type = COMPUTER_DEVICE_TYPE;
+ if ($result = $DB->query($query)) {
+ if ($DB->numrows($result)>0) {
+ while($data = $DB->fetch_array($result)) {
+ //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
+ // allready exist in translation table ? (we could use a configuration flag to force the update here)
+
+ $nb_item++;
+
+ $srcID = $data["ID"];
+ if (! $ImpReset)
+ $dstID = ImpGetdstID ( $srcID,$impid,$type);
+
+ // create entry
+ if ($ImpReset or $dstID < 0) {
+ $query = "INSERT INTO glpi_computer_device (specificity) VALUES ('')";
+ // print $query."\n";
+ if ($result2 = $DB->query($query)) {
+ $dstID = $DB-> insert_id();
+ if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
+ }
+ }
+ if ($dstID >= 0) {
+ // Update record
+
+ switch ($data["device_type"])
+ {
+ case MOBOARD_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_MOBOARD_TYPE); break;
+ case PROCESSOR_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_PROCESSOR_TYPE); break;
+ case RAM_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_RAM_TYPE); break;
+ case HDD_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_HDD_TYPE); break;
+ case NETWORK_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_IFACE_TYPE); break;
+ case DRIVE_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_DRIVE_TYPE); break;
+ case CONTROL_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_CONTROL_TYPE); break;
+ case GFX_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_GFXCARD_TYPE); break;
+ case SND_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_SNDCARD_TYPE); break;
+ case PCI_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_PCI_TYPE); break;
+ case CASE_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_CASE_TYPE); break;
+ case POWER_DEVICE : $queryId = ImpGetdstID ($data["FK_device"],$impid,DEVICE_POWER_TYPE); break;
+ default : $queryId = "0";
+ }
+ $query = "UPDATE glpi_computer_device SET".
+ " FK_computers = ".$data["FK_computers"].','.
+ " specificity = '".addslashes($data["specificity"])."',".
+ " device_type = ".$data["device_type"].",".
+ " FK_device = $queryId".
+ " WHERE ID=$dstID";
+
+ if ($queryId < 0)
+ {
+ print $data["device_type"]." ".$data["FK_device"]."\n";
+ print $query."\n";
+ }
+
+ if (! $DB->query($query)) print "Err db update device $dstID\n";
+ }
+ }
+
+ }
+ else
+ print "No Result ? :".$DB->numrows($result)."\n";
+ }
+ else
print "Result ? :".$result."\n";
+
+ //}
+
+ print "Imported $nb_item\n";
}
+
function ImpCreateDeviceItem ($device_type,$impid,$srcentity, $dstentity) {
-global $DB;
+ global $DB;
+ global $ImpReset;
switch ($device_type)
{
- case MOBOARD_DEVICE : $type = DEVICE_MOBOARD_TYPE; $table ="moboard"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- break;
+ case MOBOARD_DEVICE : $type = DEVICE_MOBOARD_TYPE; $table ="moboard"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
+ break;
case PROCESSOR_DEVICE : $type = DEVICE_PROCESSOR_TYPE; $table ="processor"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- break;
- case RAM_DEVICE : $type = DEVICE_RAM_TYPE; $table ="ram"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- ImpUpdateField ($table_in,'type', DROPDOWN_RAM_TYPE_TYPE,$impid,$dstentity); break;
+ break;
+ case RAM_DEVICE : $type = DEVICE_RAM_TYPE; $table ="ram"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
+ ImpUpdateField ($table_in,'type', DROPDOWN_RAM_TYPE_TYPE,$impid,$dstentity); break;
case HDD_DEVICE : $type = DEVICE_HDD_TYPE; $table ="hdd"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- ImpUpdateField ($table_in,'interface', DROPDOWN_INTERFACE_TYPE,$impid,$dstentity); break;
- case NETWORK_DEVICE : $type = DEVICE_IFACE_TYPE; $table ="iface"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- break;
- case DRIVE_DEVICE : $type = DEVICE_DRIVE_TYPE; $table ="drive"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- ImpUpdateField ($table_in,'interface', DROPDOWN_INTERFACE_TYPE,$impid,$dstentity); break;
- case CONTROL_DEVICE : $type = DEVICE_CONTROL_TYPE; $table ="control"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- ImpUpdateField ($table_in,'interface', DROPDOWN_INTERFACE_TYPE,$impid,$dstentity); break;
- case GFX_DEVICE : $type = DEVICE_GFXCARD_TYPE; $table ="gfxcard"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- ImpUpdateField ($table_in,'FK_interface', DROPDOWN_INTERFACE_TYPE,$impid,$dstentity); break;
- case SND_DEVICE : $type = DEVICE_SNDCARD_TYPE; $table ="sndcard"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- break;
- case PCI_DEVICE : $type = DEVICE_PCI_TYPE; $table ="pci"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- break;
+ ImpUpdateField ($table_in,'interface', DROPDOWN_INTERFACE_TYPE,$impid,$dstentity); break;
+ case NETWORK_DEVICE : $type = DEVICE_IFACE_TYPE; $table ="iface"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
+ break;
+ case DRIVE_DEVICE : $type = DEVICE_DRIVE_TYPE; $table ="drive"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
+ ImpUpdateField ($table_in,'interface', DROPDOWN_INTERFACE_TYPE,$impid,$dstentity); break;
+ case CONTROL_DEVICE : $type = DEVICE_CONTROL_TYPE; $table ="control"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
+ ImpUpdateField ($table_in,'interface', DROPDOWN_INTERFACE_TYPE,$impid,$dstentity); break;
+ case GFX_DEVICE : $type = DEVICE_GFXCARD_TYPE; $table ="gfxcard"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
+ ImpUpdateField ($table_in,'FK_interface', DROPDOWN_INTERFACE_TYPE,$impid,$dstentity); break;
+ case SND_DEVICE : $type = DEVICE_SNDCARD_TYPE; $table ="sndcard"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
+ break;
+ case PCI_DEVICE : $type = DEVICE_PCI_TYPE; $table ="pci"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
+ break;
case CASE_DEVICE : $type = DEVICE_CASE_TYPE; $table ="case"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- ImpUpdateField ($table_in,'type', DROPDOWN_CASE_TYPE_TYPE,$impid,$dstentity); break;
- case POWER_DEVICE : $type = DEVICE_POWER_TYPE; $table ="power"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
- break;
+ ImpUpdateField ($table_in,'type', DROPDOWN_CASE_TYPE_TYPE,$impid,$dstentity); break;
+ case POWER_DEVICE : $type = DEVICE_POWER_TYPE; $table ="power"; $table_in = "glpi_plugin_imp_device_".$table; $table_out = "glpi_device_".$table;
+ break;
default : $type .= "0"; print "$device_type unknown\n"; return; // error case
}
@@ -1311,131 +1700,141 @@
ImpUpdateField ($table_in,'FK_glpi_enterprise', DROPDOWN_MANUFACTURER_TYPE,$impid,$dstentity);
-print "***** Create device $table\n";
+ print "***** Create device $table\n";
- $query = "SELECT * FROM $table_in WHERE 1" ;
- if ($result = $DB->query($query)) {
+ $query = "SELECT * FROM $table_in WHERE 1" ;
+ if ($result = $DB->query($query)) {
if ($DB->numrows($result)>0) {
while($data = $DB->fetch_array($result)) {
$srcID = $data["ID"];
- $dstID = ImpGetdstID ( $srcID,$impid,$type);
+ if (! $ImpReset)
+ $dstID = ImpGetdstID ( $srcID,$impid,$type);
// create entry
- if ($dstID < 0) {
+ if ($ImpReset or $dstID < 0) {
$query = "INSERT INTO $table_out (comment) VALUES ('')";
-// print $query."\n";
+ // print $query."\n";
if ($result2 = $DB->query($query)) {
$dstID = $DB-> insert_id();
- if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) { print "Err db translate"; $dstID=-1; }
+ if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) {
+ print "Err db translate\n"; $dstID=-1;
+ }
}
}
- if ($dstID >= 0) {
- // Update record
+ if ($dstID >= 0) {
+ // Update record
$query = "UPDATE $table_out SET".
" FK_glpi_enterprise = ".$data["FK_glpi_enterprise"].','.
" designation = '".addslashes($data["designation"])."',".
" specif_default = '".addslashes($data["specif_default"])."',";
-
- switch ($device_type)
- {
- case MOBOARD_DEVICE : $query .=
+
+ switch ($device_type)
+ {
+ case MOBOARD_DEVICE : $query .=
" chipset = '".addslashes($data["chipset"])."',";
- break;
- case PROCESSOR_DEVICE : $query .=
+ break;
+ case PROCESSOR_DEVICE : $query .=
" frequence = ".$data["frequence"].',';
- break;
- case RAM_DEVICE : $query .=
+ break;
+ case RAM_DEVICE : $query .=
" frequence = '".addslashes($data["frequence"])."',".
" type = ".$data["type"].',';
- break;
- case HDD_DEVICE : $query .=
+ break;
+ case HDD_DEVICE : $query .=
" interface = ".$data["interface"].','.
" rpm = '".addslashes($data["rpm"])."',".
" cache = '".addslashes($data["cache"])."',";
- break;
- case NETWORK_DEVICE : $query .=
+ break;
+ case NETWORK_DEVICE : $query .=
" bandwidth = '".addslashes($data["bandwidth"])."',";
- break;
- case DRIVE_DEVICE : $query .= " interface = ".$data["interface"].','.
+ break;
+ case DRIVE_DEVICE : $query .= " interface = ".$data["interface"].','.
" speed = '".addslashes($data["speed"])."',".
" is_writer = ".$data["is_writer"].',';
- break;
- case CONTROL_DEVICE : $query .=
+ break;
+ case CONTROL_DEVICE : $query .=
" interface = ".$data["interface"].','.
" raid = ".$data["raid"].',';
- break;
- case GFX_DEVICE : $query .=
+ break;
+ case GFX_DEVICE : $query .=
" FK_interface = ".$data["FK_interface"].',';
- break;
- case SND_DEVICE : $query .=
+ break;
+ case SND_DEVICE : $query .=
" type = '".addslashes($data["type"])."',";
- break;
- case PCI_DEVICE : break;
- case CASE_DEVICE : $query .= " type = ".$data["type"].',';
- break;
- case POWER_DEVICE : $query .=
+ break;
+ case PCI_DEVICE : break;
+ case CASE_DEVICE : $query .= " type = ".$data["type"].',';
+ break;
+ case POWER_DEVICE : $query .=
" power = '".addslashes($data["power"])."',".
" atx = ".$data["atx"].',';
- break;
- default : $query .= ""; print "Err $device_type\n"; return;
- }
+ break;
+ default : $query .= ""; print "Err $device_type\n"; return;
+ }
$query .=" comment = '".addslashes($data["comment"])."' ".
" WHERE ID=$dstID";
- // print $query."\n";
+ // print $query."\n";
if (! $DB->query($query)) print "Err db update control $dstID\n";
}
}
}
else
- print "Device No Result ? :".$DB->numrows($result)."\n";
+ print "Device No Result ? :".$DB->numrows($result)."\n";
}
else
- print "Device DB Result ? \n";
+ print "Device DB Result ? \n";
}
+
function ImpCreateFinancialInformation ($impid,$srcentity,$dstentity)
{
-global $DB;
+ global $DB;
+ global $ImpReset;
-print "**** Create financial informations\n";
-// We take in account only financial informations for SOFTWARE
+ print "**** Create financial informations\n";
+ // We take in account only financial informations for SOFTWARE
- $query = "DELETE FROM glpi_plugin_imp_infocoms WHERE device_type !=". SOFTWARE_TYPE ;
- if ( ! $result = $DB->query($query)) { print "Err Delete glpi_plugin_imp_infocom, $query\n";return; }
+ $query = "DELETE FROM glpi_plugin_imp_infocoms WHERE device_type !=". SOFTWARE_TYPE ;
+ if ( ! $result = $DB->query($query)) {
+ print "Err Delete glpi_plugin_imp_infocom, $query\n";return;
+ }
-// Update foreign keys
+ // Update foreign keys
ImpUpdateField ('glpi_plugin_imp_infocoms','FK_enterprise', DROPDOWN_MANUFACTURER_TYPE,$impid,$dstentity);
ImpUpdateField ('glpi_plugin_imp_infocoms','FK_device', SOFTWARE_TYPE,$impid,$dstentity);
ImpUpdateField ('glpi_plugin_imp_infocoms','budget', DROPDOWN_BUDGET_TYPE,$impid,$dstentity);
-// Update the table
+ // Update the table
- $query = "SELECT * FROM glpi_plugin_imp_infocoms WHERE 1" ;
- $type = FINANCIAL_INFORMATION_TYPE;
- if ($result = $DB->query($query)) {
+ $query = "SELECT * FROM glpi_plugin_imp_infocoms WHERE 1" ;
+ $type = FINANCIAL_INFORMATION_TYPE;
+ if ($result = $DB->query($query)) {
if ($DB->numrows($result)>0) {
while($data = $DB->fetch_array($result)) {
- //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
- // allready exist in translation table ? (we could use a configuration flag to force the update here)
+ //print $data["ID"]." ".$data["name"]." ".$data["comments"]."\n";
+ // allready exist in translation table ? (we could use a configuration flag to force the update here)
$srcID = $data["ID"];
-
- $dstID = ImpGetdstID ( $srcID,$impid,$type);
+
+ if (! $ImpReset)
+ $dstID = ImpGetdstID ( $srcID,$impid,$type);
// create entry
- if ($dstID < 0) {
- $query = "INSERT INTO glpi_infocoms (name,comments) VALUES ('','')";
-// print $query."\n";
+ if ($ImpReset or $dstID < 0) {
+ $query = "INSERT INTO glpi_infocoms (name) VALUES ('')";
+ // print $query."\n";
if ($result2 = $DB->query($query)) {
$dstID = $DB-> insert_id();
- if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) { print "Err db"; $dstID=-1; }
+ if (!ImpAddTranslate ($srcID,$dstID,$impid,$type)) {
+ print "Err db\n"; $dstID=-1;
+ }
}
}
- if ($dstID >= 0) {
- // Update record
+ if ($dstID >= 0) {
+ // Update record
$query = "UPDATE glpi_infocoms SET".
" FK_device = ".$data["FK_device"].','.
@@ -1458,17 +1857,17 @@
" alert = ".$data["alert"].",".
" comments = '".addslashes($data["comments"])."' ".
" WHERE ID=$dstID";
-// print $query."\n";
+ // print $query."\n";
if (! $DB->query($query)) print "Err db update infocoms : $dstID\n";
}
}
}
else
- print "ImpCreateFinancialInformation Nb Result ? :".$DB->numrows($result)."\n";
+ print "ImpCreateFinancialInformation Nb Result ? :".$DB->numrows($result)."\n";
}
else
- print "ImpcwCreateFinancialInformation Result ? \n";
+ print "ImpcwCreateFinancialInformation Result ? \n";
}
?>
diff -urB -x .svn branches/forge/trunk//inc/setup.sql trunk//inc/setup.sql
--- branches/forge/trunk//inc/setup.sql 2011-07-07 10:41:20.765282080 +0200
+++ trunk//inc/setup.sql 2011-07-19 10:44:57.403689225 +0200
@@ -4,12 +4,13 @@
`type` int(11) NOT NULL default 0,
`srcID` int(11) NOT NULL,
`dstID` int(11) NOT NULL,
- `name` varchar(255) NOT NULL default '',
PRIMARY KEY (`impID`,`type`,`srcID`),
KEY (`impID`,`type`,`dstID`),
KEY (`type`,`dstID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
+# useless. remove to have a fixed table `name` varchar(255) NOT NULL default '',
+
DROP TABLE IF EXISTS `glpi_plugin_imp_computers`;
CREATE TABLE `glpi_plugin_imp_computers` (
`ID` int(11) NOT NULL ,
diff -urB -x .svn branches/forge/trunk//locales/en_GB.php trunk//locales/en_GB.php
--- branches/forge/trunk//locales/en_GB.php 2011-07-07 10:41:20.765282080 +0200
+++ trunk//locales/en_GB.php 2011-07-07 10:41:20.755282080 +0200
@@ -31,7 +31,7 @@
// Purpose of file:
// ----------------------------
-$LANG['plugin_imp']['setup'][1] = "Synchronize with Entity";
+$LANG['plugin_imp']['setup'][1] = "Import Entity";
$LANG['plugin_imp']['setup'][2] = $LANG['plugin_imp']['setup'][1] . "plugin configuration";
$LANG['plugin_imp']['setup'][3] = "Install plugin";
$LANG['plugin_imp']['setup'][4] = "Uninstall plugin";
@@ -53,6 +53,8 @@
$LANG['plugin_imp']['setup'][19] = "Update Software Name Field";
$LANG['plugin_imp']['setup'][20] = "Update Software Category Field";
$LANG['plugin_imp']['setup'][21] = "Optionnal fields to update on import for :";
+$LANG['plugin_imp']['setup'][22] = "Flatten entity after import ? (cancel any parm below)";
+$LANG['plugin_imp']['setup'][23] = "Take source tree";
$LANG['plugin_imp']['status'][1] = "Import status";
diff -urB -x .svn branches/forge/trunk//locales/fr_FR.php trunk//locales/fr_FR.php
--- branches/forge/trunk//locales/fr_FR.php 2011-07-07 10:41:20.765282080 +0200
+++ trunk//locales/fr_FR.php 2011-07-07 10:41:20.755282080 +0200
@@ -31,7 +31,7 @@
// Purpose of file:
// ----------------------------
-$LANG['plugin_imp']['setup'][1] = "Synchronisation avec entité";
+$LANG['plugin_imp']['setup'][1] = "Import d'entité";
$LANG['plugin_imp']['setup'][2] = "Configuration de l'extension " . $LANG['plugin_imp']['setup'][1];
$LANG['plugin_imp']['setup'][3] = "Installation";
$LANG['plugin_imp']['setup'][4] = "Désinstallation";
@@ -53,6 +53,9 @@
$LANG['plugin_imp']['setup'][19] = "Met à jour le champ Software Nom";
$LANG['plugin_imp']['setup'][20] = "Met à jour le champ Software Categorie";
$LANG['plugin_imp']['setup'][21] = "Champs mis à jour optionnellement lors de l'import pour :";
+$LANG['plugin_imp']['setup'][22] = "Applatir l'entité une fois importée ? (les paramètres en dessous seront annulés)";
+$LANG['plugin_imp']['setup'][23] = "Remonter toute l'arborescence source";
+
$LANG['plugin_imp']['status'][1] = "Status de l'import";
$LANG['plugin_imp']['status'][2] = "Date";
diff -urB -x .svn branches/forge/trunk//scripts/run.php trunk//scripts/run.php
--- branches/forge/trunk//scripts/run.php 2011-07-07 10:41:20.765282080 +0200
+++ trunk//scripts/run.php 2011-07-21 15:50:09.245772495 +0200
@@ -1,32 +1,32 @@
<?php
/*
* @version $Id: ocsng_fullsync.php 4980 2008-05-15 13:32:29Z walid $
- -------------------------------------------------------------------------
- GLPI - Gestionnaire Libre de Parc Informatique
- Copyright (C) 2003-2008 by the INDEPNET Development Team.
-
- http://indepnet.net/ http://glpi-project.org
- -------------------------------------------------------------------------
-
- LICENSE
-
- This file is part of GLPI.
-
- GLPI is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- GLPI is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GLPI; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- --------------------------------------------------------------------------
- */
+-------------------------------------------------------------------------
+GLPI - Gestionnaire Libre de Parc Informatique
+Copyright (C) 2003-2008 by the INDEPNET Development Team.
+
+http://indepnet.net/ http://glpi-project.org
+-------------------------------------------------------------------------
+
+LICENSE
+
+This file is part of GLPI.
+
+GLPI is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GLPI is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GLPI; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+--------------------------------------------------------------------------
+*/
// ----------------------------------------------------------------------
// Original Author of file: Yanick Durant
@@ -34,8 +34,8 @@
// ----------------------------------------------------------------------
if (!isset($_SERVER["argv"][0])) {
- header("HTTP/1.0 403 Forbidden");
- die("403 Forbidden");
+ header("HTTP/1.0 403 Forbidden");
+ die("403 Forbidden");
}
@@ -52,29 +52,30 @@
include (GLPI_ROOT . "/config/based_config.php");
include (GLPI_ROOT . "/inc/includes.php");
+print "including files\n";
-global $ImpSoftAsRootEntity ; // Consolidate all software as root entity
+global $ImpSoftAsRootEntity ; // Consolidate all software as root entity
+global $ImpReset;
if (!defined("PLUGIN_IMP_UPLOAD_DIR")){
- define ("PLUGIN_IMP_UPLOAD_DIR", GLPI_PLUGIN_DOC_DIR."/imp/");
+ define ("PLUGIN_IMP_UPLOAD_DIR", GLPI_PLUGIN_DOC_DIR."/imp/");
}
error_reporting(E_ALL);
- // To use a proxy use proxy:// instead of http:// for the url
- // LOAD LIB
+// To use a proxy use proxy:// instead of http:// for the url
+// LOAD LIB
- require_once(GLPI_ROOT.'/plugins/imp/inc/proxy.class.php');
+require_once(GLPI_ROOT.'/plugins/imp/inc/proxy.class.php');
- // CONFIGURE proxy
-
- HttpProxyStream::$proxy_host = '127.0.0.1'; // set IP address of proxy
- HttpProxyStream::$proxy_port = 8080;
- HttpProxyStream::$proxy_user = '';
- HttpProxyStream::$proxy_pass = '';
+// CONFIGURE proxy
+HttpProxyStream::$proxy_host = '127.0.0.1'; // set IP address of proxy
+HttpProxyStream::$proxy_port = 8080;
+HttpProxyStream::$proxy_user = '';
+HttpProxyStream::$proxy_pass = '';
include (GLPI_ROOT . "/plugins/imp/inc/plugin_imp_config.class.php");
include (GLPI_ROOT . "/plugins/imp/inc/plugin_imp.function.php");
@@ -86,28 +87,30 @@
$ImpSoftAsRootEntity = 0;
$ImpDebug = false;
$ImpLocalFile = false; // dont get file from internet (used for debug)
-$ImpResetTranslate = false;
+$ImpReset = false;
+$ImpRefreshTranslate = false;
$ImpManual = 0;
// print $_SERVER["argc"]."\n";
if ($_SERVER["argc"] >= 2 )
-for ($i=1;$i < $_SERVER["argc"];$i++ )
+for ($i=1;$i < $_SERVER["argc"];$i++ )
{
-// print $_SERVER["argv"][$i]."\n";
- switch (strtolower($_SERVER["argv"][$i]))
- {
- case "--consolidatesoftware" : $ImpSoftAsRootEntity = 1; break; // attach software to root entity
- case "--nolog" : $log = STDOUT; break; // display err to stdout
- case "--debug" : $ImpDebug = true; break; // mode debug don't erase files
- case "--localfile" : $ImpLocalFile = true; $ImpDebug = true; break; // use CSV files allready imported
- case "--reset_translate" : $ImpResetTranslate = true; break; // recalculate translation table use with care
- case "--manual" : $i++;
- if ($i < $_SERVER["argc"])
- $ImpManual = $_SERVER["argv"][$i];
- else die ("--manual need numerical arg");
- break; // run for only one line
- case "--list" :
+ // print $_SERVER["argv"][$i]."\n";
+ switch (strtolower($_SERVER["argv"][$i]))
+ {
+ case "--consolidatesoftware" : $ImpSoftAsRootEntity = 1; break; // attach software to root entity
+ case "--nolog" : $log = STDOUT; break; // display err to stdout
+ case "--debug" : $ImpDebug = true; break; // mode debug don't erase files
+ case "--localfile" : $ImpLocalFile = true; $ImpDebug = true; break; // use CSV files allready imported
+ case "--refresh_translate" : $ImpRefreshTranslate = true; break;
+ case "--reset" : $ImpReset = true; break; // recalculate translation table use with care
+ case "--manual" : $i++;
+ if ($i < $_SERVER["argc"])
+ $ImpManual = $_SERVER["argv"][$i];
+ else die ("--manual need numerical arg");
+ break; // run for only one line
+ case "--list" :
print "*** Import list ***\n";
$config = new ImpConfig();
$data = $config->find();
@@ -123,45 +126,57 @@
exit (0);
break;
- die ("Unknown arg\n");
- }
+ die ("Unknown arg\n");
+ }
}
-if ($log == 0)
+if ($log == 0)
{
- $logfilename = GLPI_LOG_DIR."/imp.log";
- $log=fopen($logfilename, "wt");
+ $logfilename = GLPI_LOG_DIR."/imp.log";
+ $log=fopen($logfilename, "wt");
}
//Check if plugin is installed, ie if tables are present
if (!TableExists("glpi_plugin_imp_config")) {
- fwrite ($log, $LANG['plugin_imp']['cron'][1] . "\n");
- fclose($log);
- exit(1);
+ fwrite ($log, $LANG['plugin_imp']['cron'][1] . "\n");
+ fclose($log);
+ exit(1);
}
$config = new ImpConfig();
-ImpCleanTranslate (); // Clean translate table of old imput
+if (! $ImpReset)
+{
+ print "Cleaning translate table\n";
+ ImpCleanTranslate (); // Clean translate table of old imput
+}
+else
+ print "mode Reset\n";
+
+
$data = $config->find();
foreach ($data as $k => $v) {
-print "\nImport number $k \n";
+ print "\nImport number $k \n";
-if (($ImpManual != 0) and ($ImpManual != $k)) { print "manual mode : import skipped\n"; continue; }
+ if (($ImpManual != 0) and ($ImpManual != $k)) {
+ print "manual mode : import skipped\n"; continue;
+ }
ImpCleanImportTable (); // Remove data from Import tables
+
if ($ImpLocalFile == false)
- foreach (glob (PLUGIN_IMP_UPLOAD_DIR."*csv") as $filename) { // CLean uploaded file
+ foreach (glob (PLUGIN_IMP_UPLOAD_DIR."*csv") as $filename) {
+ // CLean uploaded file
unlink ($filename);
print ("Remove ".$filename ."\n");
}
$loaded = $config->getFromDB($k);
if (!$loaded) {
- fwrite ($log, $LANG['plugin_imp']['cron'][2] . "\n");
- fclose($log);
+ fwrite ($log, $LANG['plugin_imp']['cron'][2] . "\n");
+ fclose($log);
}
else
if (($config->fields["active"]==1) or ($ImpManual !=0)) {
@@ -170,15 +185,17 @@
//
if (!ImpIsTimeToDump ($config)) {
- fwrite ($log, $LANG['plugin_imp']['cron'][3]);
+ fwrite ($log, $LANG['plugin_imp']['cron'][3]);
}
else {
- fwrite ($log, "Start on " . date("r") . "\n");
- ImpRun($config, $log);
- $config->fields["date_sync"]=date( 'Y-m-d H:i:s' );
- $config->updateInDB(array("date_sync"));
- fwrite ($log, "Ended on " . date("r") . "\n\n");
- if ($ImpDebug) { print "Debug end\n"; fclose ($log); exit(0); }
+ fwrite ($log, "Start on " . date("r") . "\n");
+ ImpRun($config, $log);
+ $config->fields["date_sync"]=date( 'Y-m-d H:i:s' );
+ $config->updateInDB(array("date_sync"));
+ fwrite ($log, "Ended on " . date("r") . "\n\n");
+ if ($ImpDebug) {
+ print "Debug end\n"; fclose ($log); exit(0);
+ }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment