sondage.php 3.1 KB
Newer Older
Ayolo's avatar
Ayolo committed
1 2 3
<?php

/* Copyright 2006
4
 * - Julien Etelain <julien CHEZ pmad POINT net>
5
 *
Ayolo's avatar
Ayolo committed
6 7 8 9
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
Ayolo's avatar
Ayolo committed
10
 * modify it under the terms of the GNU General Public License a
Ayolo's avatar
Ayolo committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

$topdir = "./";

require_once($topdir. "include/site.inc.php");
require_once($topdir. "include/cts/newsflow.inc.php");
require_once($topdir. "include/cts/sqltable.inc.php");
require_once($topdir."include/cts/react.inc.php");

$site = new site ();

34
$site->allow_only_logged_users("accueil");
Ayolo's avatar
indent  
Ayolo committed
35 36 37



Ayolo's avatar
Ayolo committed
38 39 40 41 42
$sdn = new sondage($site->db,$site->dbrw);

if (  isset($_REQUEST["answord"]) )
{

Ayolo's avatar
indent  
Ayolo committed
43 44 45
  $sdn->load_lastest();
  if ( $sdn->id > 0 && $_REQUEST["id_sondage"] == $sdn->id )
    $sdn->repondre($site->user->id,$_REQUEST["numrep"]);
Ayolo's avatar
Ayolo committed
46

Ayolo's avatar
indent  
Ayolo committed
47
  $res = new contents("Merci","Votre réponse a été enregistrée.");
48
}
Ayolo's avatar
Ayolo committed
49
else if ( isset($_REQUEST["id_sondage"]) )
Ayolo's avatar
indent  
Ayolo committed
50
  $sdn->load_by_id($_REQUEST["id_sondage"]);
Ayolo's avatar
Ayolo committed
51

52
if ( $sdn->is_valid() )
Ayolo's avatar
Ayolo committed
53 54
{

55 56
  $site->start_page("accueil","Sondage");

Ayolo's avatar
indent  
Ayolo committed
57
  $cts = new contents("Sondage");
58

Ayolo's avatar
indent  
Ayolo committed
59 60
  if ( $res )
    $cts->add($res);
61

Ayolo's avatar
indent  
Ayolo committed
62 63

  $cts->add_title(2,"Resultats");
64

Ayolo's avatar
indent  
Ayolo committed
65
  $cts->add_paragraph($sdn->question);
66

Ayolo's avatar
indent  
Ayolo committed
67 68 69
  $cts->puts("<p>");

  $res = $sdn->get_results();
70

Ayolo's avatar
indent  
Ayolo committed
71 72 73 74
  foreach ( $res as $re )
  {
    $cumul+=$re[1];
    $pc = $re[1]*100/$sdn->total;
75

Ayolo's avatar
indent  
Ayolo committed
76
    $cts->puts($re[0]."<br/>");
77

Ayolo's avatar
indent  
Ayolo committed
78 79 80 81 82
    $wpx = floor($pc);
    if ( $wpx != 0 )
      $cts->puts("<div class=\"activebar\" style=\"width: ".$wpx."px\"></div>");
    if ( $wpx != 100 )
      $cts->puts("<div class=\"inactivebar\" style=\"width: ".(100-$wpx)."px\"></div>");
83

Ayolo's avatar
indent  
Ayolo committed
84 85
    $cts->puts("<div class=\"percentbar\">".round($pc,1)."%</div>");
    $cts->puts("<div class=\"clearboth\"></div>\n");
86

Ayolo's avatar
indent  
Ayolo committed
87
  }
88

Ayolo's avatar
indent  
Ayolo committed
89 90 91 92 93
  if ( $cumul < $sdn->total )
  {
    $pc = ( $sdn->total-$cumul)*100/$sdn->total;
    $cts->puts("<br/>Blanc ou nul : ".round($pc,1)."%");
  }
94

Ayolo's avatar
indent  
Ayolo committed
95 96 97 98
  $cts->puts("</p>");

  $cts->add_title(2,"Voir aussi");
  $cts->add_paragraph("<a href=\"sondage.php\">Archives</a>");
99

Ayolo's avatar
Ayolo committed
100 101
  $cts->add(new reactonforum ( $site->db, $site->user, $sdn->question, array("id_sondage"=>$sdn->id), null, true ));

Ayolo's avatar
indent  
Ayolo committed
102
  $site->add_contents($cts);
103

Ayolo's avatar
indent  
Ayolo committed
104 105
  $site->end_page();
  exit();
Ayolo's avatar
Ayolo committed
106 107 108 109 110
}

$site->start_page("accueil","Sondage");


111
$req = new requete($site->db, "SELECT * FROM `sdn_sondage` ORDER BY date_sondage");
Ayolo's avatar
Ayolo committed
112 113

$site->add_contents(new sqltable(
114 115 116
  "listsondages",
  "Archives", $req, "../sondage.php",
  "id_sondage",
Ayolo's avatar
indent  
Ayolo committed
117 118 119 120
  array(
    "question"=>"Question",
    "date_sondage"=>"Du",
    "date_fin"=>"Au"
121 122
    ),
  array(),
Ayolo's avatar
indent  
Ayolo committed
123 124 125
  array(),
  array( )
  ));
Ayolo's avatar
Ayolo committed
126 127 128 129

$site->end_page();

?>