SpaceHam
Messages postés
78
Date d'inscription
lundi 27 mars 2006
Statut
Membre
Dernière intervention
22 octobre 2015
21 juin 2011 à 14:56
Je vais déposer mes 2 fichiers principaux pour le cas. Ma Vue pour afficher ma table d'ordinateur et ma persistance (seulement les function que j'utilise ou vais utiliser)
Comme j'ai dit plus haut mon problème est que lorsque je demande d'afficher les champs demandé il n'y a rien. Mais le Array qui en sort (voir dans la méthode getAllComputer() eh bien il sors à la fois une position et le nom du champ qui détienne les réponses.
-----------------VUE- VComputer_List.php-------------------------------------------
<?php
session_start();
echo '<html>
<title>Inventaire 1.0 - Liste des ordinateurs</title>
Réservé aux membres IT
';
if(isset($_SESSION['username']))
{
$access = $_SESSION['access'];
if($access 'ADM' || $access 'UIT')
{
include_once('class/PInventaire.class.php');
$pi =new PInventaire;
if(isset($_POST['delpc']))
$pi->deleteComputer($_POST['delpc']);
echo 'Bienvenue ' . $_SESSION['fname'] . ' ' . $_SESSION['lname'] . '
[PrincipalView.php Page principal]
[VComputer_List.php Rafraîchir cette page]
<form method="post" action="VAdd_Computer.php">
<tr><td colspan="2" align="center"></td></tr>
</form>
<center>
SN,
Nom,
Manufacture,
Modèle,
Projet,
Système d´exploitation,
';
include_once('class/Computer.class.php');
$all_pc = $pi->getAllComputer();
foreach($all_pc as $pc)
{
echo ' ----
' . $pc->getSerialNumber() . '
' . $pc->getSerialNumber() . ',
' . $pc->getName() . ',
' . $pc->getManufacturer() . ',
' . $pc->getModel() . ',
' . $pc->getProject() . ',
' . $pc->getOSName() . ',
<form method="post" action="VModif_Computer.php">
getSerialNumber() . '">,
,
</form>
<form method="post" action="VComputer_List.php">
getSerialNumber() . '">,
,
</form>
';
}
echo '
</center>';
}
else
{
echo 'Vous n´êtes pas autorisé!
';
echo '
[PrincipalView.php Page principal]';
}
}
else
{
echo 'Vous n´êtes pas autorisé!
';
echo '[login.php Page de connexion]';
}
echo '
</html>';
?>
----------------------------------------------------------------
P.S.: les ..... c'est juste parce qu'il y a d'autres code qui ont rapport à l'usager donc pas important à savoir LOL. C'est juste à titre informatif.
------------- Persistance - PInventaire.class.php -----------------------
<?php
//EDITED BY : SpaceHamAgent
//YEAR : 2011
class PInventaire
{
private $conn;
private $db_host = 'localhost';
private $db_username = 'root';
private $db_password = 'p4ssw0rd';
private $db_database = 'inventory';
....
public function getComputer($serial)
{
include_once('Computer.class.php');
$pc = new Computer;
$req = "SELECT * FROM inv_computer WHERE
sn = '" . $serial . "'";
$this->connect();
$res = mysqli_query($this->conn, $req);
if($row = mysqli_fetch_array($res))
{
//CODE pour afficher le array au complet de la ligne.
//echo '***';
//print_r($row);
//var_dump($row);
//echo '
***';
$pc->setSerialNumber($row['sn']);
$pc->setName($row['name']);
$pc->setNameAddress($row['nameaddress']);
$pc->setManufacturer($row['manufacturer']);
$pc->setModel($row['model']);
$pc->setProject($row['project']);
$pc->setDomain($row['domain']);
$pc->setWorkgroup($row['workgroup']);
$pc->setOSName($row['osname']);
$pc->setOSKey($row['oskey']);
$pc->setServer($row['server']);
$pc->setWorkable($row['workable']);
$pc->setInventory($row['inventory']);
$pc->setProduction($row['production']);
$pc->setFormation($row['formation']);
return $pc;
}
else
return NIL;
}
public function getAllComputer()
{
include_once('Computer.class.php');
$all_pc = new ArrayObject;
$req = "SELECT * FROM inv_computer";
$this->connect();
$res = mysqli_query($this->conn, $req);
while($row = mysqli_fetch_array($res))
{
//CODE pour afficher le array au complet de la ligne.
echo '***';
print_r($row);
var_dump($row);
echo '
***';
$pc = new Computer;
$pc->setSerialNumber($row['sn']);
$pc->setName($row['name']);
$pc->setNameAddress($row['nameaddress']);
$pc->setManufacturer($row['manufacturer']);
$pc->setModel($row['model']);
$pc->setProject($row['project']);
$pc->setDomain($row['domain']);
$pc->setWorkgroup($row['workgroup']);
$pc->setOSName($row['osname']);
$pc->setOSKey($row['oskey']);
$pc->setServer($row['server']);
$pc->setWorkable($row['workable']);
$pc->setInventory($row['inventory']);
$pc->setProduction($row['production']);
$pc->setFormation($row['formation']);
$all_pc->append($pc);
}
$this->disconnect();
return $all_pc;
}
..........
public function saveNewComputer($pc)
{
include_once('Computer.class.php');
$req = "INSERT INTO inv_computer VALUES ('" . $pc->getSerialNumber() . "', '" . $pc->getName() . "', '" . $pc->getNameAddress() .
"', '" . $pc->getManufacturer() . "', '" . $pc->getModel() . "', '" . $pc->getProject() . "', '" . $pc->getDomain() .
"', '" . $pc->getWorkgroup() . "', '" . $pc->getOSName() . "', '" . $pc->getOSKey() . "', " . $pc->getServer() .
", " . $pc->getWorkable() . ", " . $pc->getInventory() . ", " . $pc->getProduction() . ", " . $pc->getFormation() . ")";
$this->connect();
mysqli_query($this->conn, $req);
$this->disconnect();
}
............
public function saveModifComputer($pc)
{
include_once('Computer.class.php');
echo 'saveModifComputer is [' . $pc->getSerialNumber() . ']';
$req "UPDATE inv_computer SET name '" . $pc->getName() . "', nameaddress = '" . $pc->getNameAddress() .
"', manufacturer '" . $pc->getManufacturer() . "', model '" . $pc->getModel() . "', project = '" . $pc->getProject() .
"', domain '" . $pc->getDomain() . "', workgroup '" . $pc->getWorkgroup() . "', osname = '". $pc->getOSName() .
"', oskey '" . $pc->getOSKey() . "' server " . $pc->getServer() . ", workable = " . $pc->getWorkable() .
", inventory " . $pc->getInventory() . ", production " . $pc->getProduction() . ", formation = " . $pc->getFormation() .
" WHERE sn = '" . $pc->getSerialNumber() . "'";
echo $req;
$this->connect();
mysqli_query($this->conn, $req);
$this->disconnect();
}
..............
public function deleteComputer($sn)
{
$req "DELETE FROM inv_computer WHERE sn '" . $sn . "'";
$this->connect();
$res = mysqli_query($this->conn, $req);
$this->disconnect();
}
...........
private function connect()
{
$this->conn = new mysqli($this->db_host, $this->db_username, $this->db_password);
if(!$this->conn)
{
echo "Impossible de se connecter à la base.";
exit;
}
$base = mysqli_select_db($this->conn, $this->db_database);
if(!$base)
{
echo "Impossible de trouver la base de donnée.";
exit;
}
}
private function disconnect()
{
mysqli_close($this->conn);
}
}
?>
-------------------------------------------------------------------------
SpaceHamAgent