1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| <?php
// fonction qui permet de faire un array avec les directions
function tabDirection()
{
$file = "fichiers_csv/employeakf.csv";
$taille = 1024;
$delimiteur = ";";
/* ouverture en lecture */
if($fp = fopen($file,"r")) {
/* extraction d'une ligne */
$dataDirection = array();
$comparaison = array();
$dataDirectionSansDoublons = array();
while ($ligne = fgetcsv($fp, $taille, $delimiteur))
{
if(!empty($ligne[9]) && !empty($ligne[10]))
{
$dataDirection[] = array($ligne[9],$ligne[10]);
$comparaison[] = $ligne[9].$ligne[10];
}
}
$comparaison = array_unique($comparaison);
foreach ($comparaison as $cleComparaison => $valComparaison)
{
$dataDirectionSansDoublons[] = $dataDirection[$cleComparaison];
}
return $dataDirectionSansDoublons;
fclose ($fp);
} else {
echo "Ouverture impossible.";
}
}
// fonction qui permet de faire un array avec les services
function tabService()
{
$file = "fichiers_csv/employeakf.csv";
$taille = 1024;
$delimiteur = ";";
/* ouverture en lecture */
if($fp = fopen($file,"r")) {
/* extraction d'une ligne */
$dataService = array();
$comparaison = array();
$dataServiceSansDoublons = array();
while ($ligne = fgetcsv($fp, $taille, $delimiteur))
{
if(!empty($ligne[7]) && !empty($ligne[8]) && !empty($ligne[9]))
{
$dataService[] = array($ligne[7],$ligne[8],$ligne[9]);
$comparaison[] = $ligne[7].$ligne[8].$ligne[9];
}
}
$comparaison = array_unique($comparaison);
foreach ($comparaison as $cleComparaison => $valComparaison)
{
$dataServiceSansDoublons[] = $dataService[$cleComparaison];
}
return $dataServiceSansDoublons;
fclose ($fp);
} else {
echo "Ouverture impossible.";
}
}
function tabGLPILocations()
{
$tabGLPILocations = array();
$tabGLPILocations[] = array('ID','FK_entities','name','parentID','completename','comments','level');
// Insertion des données sur les directions dans le tableau général
// Insertion des données sur les directions
$tabDirection = tabDirection(); // Array des nom de directions
$id = 0; // Déclaration de l'ID de l'Array général
for($i=0;$i<count($tabDirection);$i++)
{
$tabGLPILocations[] = array($id,
'0',
$tabDirection[$i][0] /* Ligne & colonne : CODE_DIRECTION > name & comptename */,
'0',
$tabDirection[$i][0] /* Ligne & colonne : CODE_DIRECTION > name & comptename */,
$tabDirection[$i][1] /* Ligne & colonne : DIRECTION > comments */,
'1'
);
$id++;
}
// Insertion des données sur les services
$tabService = tabService(); // Array des nom de Services
for($i=0;$i<count($tabService);$i++)
{
$tabGLPILocations[] = array($id,
'0',
$tabService[$i][0] /* Ligne & colonne : CODE_SERVICE > name & comptename */,
'0',
$tabService[$i][2].' > '.$tabService[$i][0] /* Ligne & colonne : CODE_SERVICE > name & comptename */,
$tabService[$i][1] /* Ligne & colonne : SERVICE > comments */,
'2'
);
$id++;
}
// Affichage de l'array général
for($i=0;$i<count($tabGLPILocations);$i++)
{
echo $tabGLPILocations[$i][0]; //Ligne & colonne
echo ';';
echo $tabGLPILocations[$i][1]; //Ligne & colonne
echo ';';
echo $tabGLPILocations[$i][2]; //Ligne & colonne
echo ';';
echo $tabGLPILocations[$i][3]; //Ligne & colonne
echo ';';
echo $tabGLPILocations[$i][4]; //Ligne & colonne
echo ';';
echo $tabGLPILocations[$i][5]; //Ligne & colonne
echo ';';
echo $tabGLPILocations[$i][6]; //Ligne & colonne
echo '<br>';
}
}
tabGLPILocations();
?> |