# création automatique en ligne de commande
# du fichier pdf de la liste des stages pour une
# catégorie passée en paramètre :
###################################################################################
function rappelSyntaxe() {
print "\n la syntaxe de la commande est :\n" ;
print "\n php categstagesautom.php CATGEGORIE";
print "\n où CATEGORIE est l'un des mots";
print "\n info stat gp mkg rh ";
print "\n" ;
print "\n exemple d'utilisation :";
print "\n php categstagesautom.php info\n";
print "\n" ;
} ; # fin de fonction rappelSyntaxe
###################################################################################
# début du programme principal : on teste s'il y a un paramètre
###################################################################################
if ($argc==1) {
print "\n" ;
print "Vous n'avez fourni aucun paramètre, je ne peux pas continuer.\n\n" ;
rappelSyntaxe() ;
exit(-1) ;
} ; # fin de si aucun paramètre
###################################################################################
# si on arrive ici c'est qu'il y a un paramètre
$categ = $argv[1] ;
# si la catégorie n'est pas un des mots réservés,
# on le dit et on quitte le programme
$lstcateg = " info stat gp mkg rh " ;
if (strpos($lstcateg,$categ)===false) {
print "\n" ;
print " Vous avez demandé la catégorie '".$categ."' que je ne connais pas. Je ne peux pas continuer.\n\n" ;
rappelSyntaxe() ;
exit(-2) ;
} ; # fin de si
###################################################################################
# si on arrive ici c'est que le paramètre était correct
# chargement de la classe ezpdf
include 'class.ezpdf.php';
# création de l'objet
$fichierPDF =& new Cezpdf() ;
# page 1 : c'est une page de titre
// do some funky stuff in the background, in a nice light blue, which is
// bound to clash with something and some red for the hell of it
$x=578;
$r1=25;
for ($xw=40;$xw>0;$xw-=3){
$tone=1.0-$xw/40*0.2;
$fichierPDF->setLineStyle($xw);
$fichierPDF->setStrokeColor($tone,1,$tone);
$fichierPDF->ellipse(50,750,$r1);
$r1=$r1+$xw;
} ;
for ($xw=40;$xw>0;$xw-=3){
$tone=1.0-$xw/40*0.2;
$fichierPDF->setStrokeColor($tone,$tone,1);
$fichierPDF->setLineStyle($xw);
$fichierPDF->line($x,0,$x,842);
$x=$x-$xw-2;
} ;
$fichierPDF->setStrokeColor(0,0,0);
$fichierPDF->setLineStyle(1);
$fichierPDF->rectangle(20,20,558,802);
$y=800;
for ($size=50;$size>5;$size=$size-5){
$height = $fichierPDF->getFontHeight($size);
$y=$y-$height;
$fichierPDF->addText(30,$y,$size,$demotext);
} ;
for ($angle=0;$angle<360;$angle=$angle+20){
$r=rand(0,100)/100;
$g=rand(0,100)/100;
$b=rand(0,100)/100;
$fichierPDF->setColor($r,$g,$b);
$fichierPDF->addText(300+cos(deg2rad($angle))*40,300-
sin(deg2rad($angle))*40,20,$demotext,$angle);
} ;
$fichierPDF->setColor(0,0,0);
$fichierPDF->selectFont('./fonts/Helvetica');
$fichierPDF->addText(120,550,50,"Liste des stages") ;
$fichierPDF->addText(180,480,50,"\"MASS\"") ;
$fichierPDF->addText(200,120,20,"Université d'Angers") ;
$ligne = "préparation du document réalisée le ".date("d / m / Y")." vers ". date("H")." h ".date("i") ;
$fichierPDF->addText(150,80,12,$ligne) ;
# après la page de titre, les stages
$fichierPDF->ezNewpage() ;
$fichierPDF->selectFont('./fonts/Helvetica');
# ouverture de la base de données
mysql_connect("sirius","anonymous","anonymous") ;
mysql_select_db("webmass") ;
# comptage du nombre de stages en tout
$res = mysql_query("select count(nom) from stagesMaitrise ") ;
$ligr = mysql_fetch_array($res) ;
$nbst = $ligr["count(nom)"] ;
# et du nombre d'années
$res = mysql_query("select distinct an from stagesMaitrise order by an desc") ;
$nbans = 0 ;
while ($ligr=mysql_fetch_array($res)) {
$nbans++ ;
} ; # fin de tant que
# on en déduit la moyenne par an (mpa)
$mpa = sprintf("%3.1f",$nbst/$nbans) ;
$fichierPDF->addText(30,800,16,"Il y a $nbst stages répartis en tout sur $nbans années soit approximativement $mpa ") ;
$fichierPDF->addText(30,780,16,"stages par an, toutes catégories confondues.") ;
$fichierPDF->setLineStyle(2) ;
$fichierPDF->line(200,750,550,750) ;
# nombre de stages pour la catégorie choisie
$res = mysql_query("select count(nom) from stagesMaitrise where categorie = \"$categ\" ") ;
$ligr = mysql_fetch_array($res) ;
$nbs = $ligr["count(nom)"] ;
$fichierPDF->addText(30,700,16,"Voici la liste des $nbs stages pour la catégorie $categ.\n\n") ;
# création du tableau
$tabStages = array() ;
$qry = "select entreprise from stagesMaitrise where categorie = \"$categ\" " ;
$res = mysql_query($qry) ;
$nbent = 0 ;
while ($ligr=mysql_fetch_array($res)) {
$nbent++ ;
$num = $nbent."." ;
$ent = trim($ligr["entreprise"]) ;
array_push($tabStages, array("num"=>$num,"ent"=>$ent) ) ;
} ; # fin de tant que
# et affichage du tableau
$fichierPDF->ezSetY(680) ;
$fichierPDF->ezTable($tabStages,'','',
array('showHeadings'=>0,'width'=>330,
'cols'=>array( 'num'=>array('justification'=>'right','width'=>30),
'ent'=>array('width'=>300))
)
) ; # fin de ezTable
$pdfCode = $fichierPDF->output();
$nomfic = "stagesautom.pdf" ;
$fh = fopen($nomfic,"wb") ;
fwrite($fh,$pdfCode) ;
fclose($fh) ;
print "\n le fichier $nomfic est prêt...\n\n" ;
?>