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
|
<?php
function shortcode_biblio($atts){
//début de code pour gérer l'emplacement du code
ob_start();
// do some stuff
//extraction de l'attribut collaborateur
extract(shortcode_atts(array ('collaborateur'=>'',) ,$atts));
//connexion au serveur
$serveur = "localhost";
$login = "root";
$pass = "";
try{
$connexion = new PDO("mysql:host=$serveur;dbname=archeodunum_local;charset=UTF8",$login,$pass);
$connexion->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
echo 'Echec : ' .$e->getMessage();
}
//requête SQL et mise en forme en tableau
$sql="SELECT * from BIBLIOGRAPHIE WHERE Auteur='$collaborateur' ORDER BY Annee DESC ";
if(!$connexion->query($sql)) {echo "Pb d'accès au CARNET";}
else if (empty($collaborateur)) {
$sql2="SELECT * from BIBLIOGRAPHIE ORDER BY Annee DESC ";
?>
<table>
<tr> <th width=10%> Auteur </th><th width=10%> Année </th> <th width= 60%> Références bibliographiques </th><th width=10%> Type </th><th width= 15%> </th></tr>
<?php
foreach ($connexion->query($sql2) as $row)
echo "<tr><td>".$row['Auteur']."</td><td>".$row['Annee']."</td><td><div class=cesure>".$row['Reference']."</div></td><td>".$row['Type']."</td><td><a href='modifier_biblio?id=".$row['ID']."&o=u'>Modifier</a><br><a href='supprimer_biblio?id=".$row['ID']."&o=d'>Supprimer</a></td></tr>\n";
?>
</table>
<?php
}
else{
?>
<table>
<tr> <th width=10%> Année </th> <th width= 90%> Références bibliographiques </th></tr>
<?php
foreach ($connexion->query($sql) as $row)
echo "<tr><td>".$row['Annee']."</td><td><div class=cesure>".$row['Reference']."</div></td></tr>\n";
?>
</table>
<?php
}
?>
<?php
//fin de code pour gérer l'emplacement
$code_output = ob_get_contents();
ob_end_clean();
return $code_output;
//fin de code de fonction
}
add_shortcode('Bibliographie', 'shortcode_biblio');
?> |
Partager