Location: PHPKode > scripts > MZSurvey > mzsurvey/mzsurvey.php
<?
  // MZSURVEY.PHP Version 0.1
  // Last modif date : 30.08.2004
  // hide@address.com

  // EDIT THIS LINE
  $SURVEY_PATH = "http://localhost/survey/";
  //


  function show_results($name){
           global $_POST, $_COOKIE, $SURVEY_PATH;

           $cfg = parse_ini_file($name.'.ini',true);

           echo "<table style='".$cfg['css']['table']."' width='".$cfg['main']['width']."' align='".$cfg['main']['align']."'>";

           echo "<tr><td align=center style='".$cfg['css']['title']."'>".$cfg['main']['title']."</td></tr>";

           $questions = $cfg['questions'];
           $answers = $cfg['answers'];

           $sum = array_sum($answers);

           for ($i=1;$i<=count($questions);$i++){
                echo "<tr><td style='".$cfg['css']['row']."' align=center>".round((($answers[$i]/$sum)*100),2)."%&nbsp; - ".$questions[$i]."</td></tr>";
           }

           if ($_COOKIE["mzpoolcook_$name"]!='yes') { echo "<tr><td style='".$cfg['css']['footer']."'><a href=#null onclick=self.close();>Close window</a></td></tr>"; }

           echo '</table>';
  }

  function write_vote($name){
           global $_POST, $_COOKIE, $SURVEY_PATH;


           if ($_COOKIE["mzpoolcook_$name"]!='yes') {

               setcookie("mzpoolcook_$name","yes",time()+36000);

               $cfg = parse_ini_file($name.'.ini',true);

               if ($_POST['survey_question']>0) $cfg['answers'][$_POST['survey_question']]++;

               write_ini_file($cfg, $name.'.ini', true);
           }

           header("Location:". $_SERVER['HTTP_REFERER']);
           exit;
  }

  function print_survey($name){
           global $SURVEY_PATH;

           $cfg = parse_ini_file($name.'.ini',true);

           $current_date = strtotime(date("m/d/Y"));
           $end_date = strtotime($cfg['main']['end_date']);

           if (($_COOKIE["mzpoolcook_$name"]=='yes')||($current_date>$end_date)) show_results($name); else {

           if (count($cfg['questions'])>0) {
                    echo "<script>;
                    function resultsWindow(url){
                    w=".($cfg['main']['width']+20).";
                    h=".($cfg['main']['height']+20).";
                    tb=0;
                    stb=0;
                    l=0;
                    mb=0;
                    sb=0;
                    rs=0;
                    x=screen.width/2 - w/2;
                    y=screen.height/2 - h/2;;
                    var t=(document.layers)? ',screenX='+x+',screenY='+y: ',left='+x+',top='+y; //A LITTLE CROSS-BROWSER CODE FOR WINDOW POSITIONING
                    tb=(tb)?'yes':'no'; stb=(stb)?'yes':'no'; l=(l)?'yes':'no'; mb=(mb)?'yes':'no'; sb=(sb)?'yes':'no'; rs=(rs)?'yes':'no';
                    var x=window.open(url, 'newWin'+new Date().getTime(), 'scrollbars='+sb+',width='+w+',height='+h+',toolbar='+tb+',status='+stb+',menubar='+mb+',links='+l+',resizable='+rs+t);
                    x.focus();
                    if(!x.opener) {x.opener = self}
                    }</script>";


                      echo "<table style='".$cfg['css']['table']."' width=".$cfg['main']['width']." align=".$cfg['main']['align'].">";

                      echo "<form name=survey_".$name." action='".$SURVEY_PATH."mzsurvey.php' method=post>";
                      echo "<input type=hidden name=survey_name value='".$name."'>";

                      echo "<tr><td align=center style='".$cfg['css']['title']."'>".$cfg['main']['title']."</td></tr>";

                      $questions = $cfg['questions'];

                      for ($i=1;$i<=count($questions);$i++){
                           echo "<tr><td style='".$cfg['css']['row']."'><input type=radio name=survey_question value=".$i.">&nbsp;".$questions[$i]."</td></tr>";
                      }

                      echo "<tr><td align=center><input style='".$cfg['css']['form']."' type=submit name=survey_submit value=Vote></td></tr>";

                      echo "<tr><td style='".$cfg['css']['footer']."'><a href=#null onclick=resultsWindow('".$SURVEY_PATH."mzsurvey.php?survey_results=1&survey_name=".$name."')>Show results</a></td></tr>";

                      echo '</table>';
                      echo '</form>';

           }
           }
  }

   if (!function_exists('write_ini_file')) {
   function write_ini_file($assoc_arr, $path, $has_sections=FALSE) {
       Global $SURVEY_PATH;
       $content = "";
       if ($has_sections) {
           foreach ($assoc_arr as $key=>$elem) {
               $content .= "[".$key."]\n";
               foreach ($elem as $key2=>$elem2) {
                   $content .= $key2." = \"".$elem2."\"\n";
               }
           }
       } else {
           foreach ($assoc_arr as $key=>$elem) {
               $content .= $key." = \"".$elem."\"\n";
           }
       }
       if (!$handle = fopen($path, 'w')) {
           return false;
       }
       if (!fwrite($handle, $content)) {
           return false;
       }
       fclose($handle);
       return true;
   }
   }

  if (isset($_POST['survey_submit'])) write_vote($_POST['survey_name']);
  if ($_GET['survey_results']==1) show_results($_GET['survey_name']);

?>
Return current item: MZSurvey