From: Matthew G. <gr...@mu...> - 2005-02-02 16:18:45
|
At first glance it looks pretty good. It'll need to be reworked to be against 1.7 and include DB changes for Postgres and sqlite. On Wed, 2005-02-02 at 17:09 +0100, Jochen Staerk wrote: > Hi, > I am sorry that the attached patch is against version 1.6.1. but that's > intention. > > It adds a check box "Show results after participation" to the > general-tab of a survey. If this is checked, a survey will show it's > preliminary results on the "thank you" page. On the finish-tab there now > is a snippet how to integrate survey results into one's homepage. If the > user has a custom thank-you url (and show results checked), he/she will > be warned to manually integrate this into the custom thank-you page. > > Please mail me what you think. > > plain text document attachment (results.diff) > Index: scripts/db/mysql_populate.sql > =================================================================== > --- scripts/db/mysql_populate.sql (revision 1) > +++ scripts/db/mysql_populate.sql (working copy) > @@ -94,6 +94,7 @@ > thanks_page CHAR(255), > thank_head CHAR(255), > thank_body TEXT, > + show_results ENUM('Y','N') NOT NULL DEFAULT 'N', > changed TIMESTAMP(14) NOT NULL DEFAULT '', > PRIMARY KEY (id), > UNIQUE(name) > Index: admin/include/function/survey_update.inc > =================================================================== > --- admin/include/function/survey_update.inc (revision 1) > +++ admin/include/function/survey_update.inc (working copy) > @@ -37,11 +37,13 @@ > } > > // create a new survey in the database > - $fields = array('name','realm','title','subtitle','email','theme','thanks_page','thank_head','thank_body','info'); > + $fields = array('name','realm','title','subtitle','email','theme','thanks_page','thank_head','thank_body', 'show_results', 'info'); > foreach($fields as $f) { > if(isset($HTTP_POST_VARS[$f])) { > array_push($f_arr,$f); > - array_push($v_arr,"'"._addslashes($HTTP_POST_VARS[$f])."'"); > + $value=$HTTP_POST_VARS[$f]; > + if (is_array($value)) $value=implode(',',$value); // if value is e.g. a radio button, handle the array > + array_push($v_arr,"'"._addslashes($value)."'"); > } > } > array_push($f_arr,'owner'); > @@ -79,7 +81,7 @@ > return(0); > } > > - $fields = array('name','realm','title','subtitle','email','theme','thanks_page','thank_head','thank_body','info'); > + $fields = array('name','realm','title','subtitle','email','theme','thanks_page','thank_head','thank_body','show_results','info'); > $sql = "SELECT name FROM survey WHERE id='${survey_id}'"; > $result = mysql_query($sql); > $name = mysql_result($result,0,0); > @@ -100,7 +102,9 @@ > > // UPDATE the row in the DB with current values > foreach($fields as $f) { > - array_push($f_arr,$f ."='" . _addslashes($HTTP_POST_VARS[$f]) . "'"); > + $value=$HTTP_POST_VARS[$f]; > + if (is_array($value)) $value=implode(',',$value); // if value is e.g. a radio button, handle the array > + array_push($f_arr,$f ."='" . _addslashes($value) . "'"); > } > $sql = "UPDATE survey SET " . join(', ',$f_arr) . " WHERE id='${survey_id}'"; > $result = mysql_query($sql); > Index: admin/include/tab/general.inc > =================================================================== > --- admin/include/tab/general.inc (revision 1) > +++ admin/include/tab/general.inc (working copy) > @@ -15,9 +15,10 @@ > $sql = "SELECT * FROM survey WHERE id='${sid}'"; > $result = mysql_query($sql); > $survey = mysql_fetch_array($result,MYSQL_ASSOC); > + $survey['show_results']=array($survey['show_results']); // this is a check box and thus an array is required > mysql_free_result($result); > } else { > - $fields = array('name','realm','title','subtitle','email','theme','thanks_page','thank_head','thank_body','info','public'); > + $fields = array('name','realm','title','subtitle','email','theme','thanks_page','thank_head','thank_body','show_results','info','public'); > foreach ($fields as $f) { > if(!empty($HTTP_POST_VARS[$f])) > $survey[$f] = _stripslashes($HTTP_POST_VARS[$f]); > @@ -110,6 +111,16 @@ > </tr> > <tr><td colspan="2"><hr width="90%" size="0" color="#FFFFFF"></td></tr> > <tr valign="top"> > + <td><b><?php echo(_('Results')); ?></b></td> > + <td> > + <?php > + echo mkcheckbox('show_results', 'Y', $survey); > + echo " "._('Show results after participation'); > + ?><br> > + </td> > + </tr> > + <tr><td colspan="2"><hr width="90%" size="0" color="#FFFFFF"></td></tr> > + <tr valign="top"> > <td><b><?php echo(_('Email')); ?></b></td> > <td> > <?php echo mktext('email', 30, 0, $survey); ?><br> > Index: admin/include/tab/finish.inc > =================================================================== > --- admin/include/tab/finish.inc (revision 1) > +++ admin/include/tab/finish.inc (working copy) > @@ -29,6 +29,32 @@ > include("<?php echo($ESPCONFIG['handler']); ?>");?> > </tt></blockquote> > > + > + <p><?php echo(_('To insert the results of this survey into your web page, copy the text > +below, and paste it into the HTML of your page.')); ?></p> > + > +<blockquote><tt> > + <?php $sid=<?php echo($HTTP_SESSION_VARS['survey_id']); ?>; > + $precision=1; > + $totals=1; > + $qid=''; > + $cid=''; > + > + include("<?php echo($ESPCONFIG['handler']); ?>");?> > +</tt></blockquote> > + > + <p> > + <?php > + $sql = "SELECT thanks_page,show_results FROM survey WHERE id='".$HTTP_SESSION_VARS['survey_id']."'"; > + $result = mysql_query($sql); > + list($thank_url,$show_results) = mysql_fetch_row($result); > + mysql_free_result($result); > + if (($show_results=='Y')&&(!empty($thank_url))) { > + echo("<b>"._('You are required to do this manually in the confirmation page').", $thank_url.</b>"); > + } > + ?></p> > + > + > <p><?php echo(_('Once activated you can also access the survey directly > from the following URL.')); ?></p> > <blockquote><tt> > Index: admin/include/funcs.inc > =================================================================== > --- admin/include/funcs.inc (revision 1) > +++ admin/include/funcs.inc (working copy) > @@ -78,9 +78,9 @@ > // redirect to thank you page for survey ID 'sid' > // exits PHP! > function goto_thankyou($sid,$referer) { > - $sql = "SELECT thanks_page,thank_head,thank_body FROM survey WHERE id='${sid}'"; > + $sql = "SELECT thanks_page,thank_head,thank_body,show_results FROM survey WHERE id='${sid}'"; > $result = mysql_query($sql); > - list($thank_url,$thank_head,$thank_body) = mysql_fetch_row($result); > + list($thank_url,$thank_head,$thank_body,$show_results) = mysql_fetch_row($result); > mysql_free_result($result); > if(!empty($thank_url)) { > if(!headers_sent()) { > @@ -110,7 +110,8 @@ > ?> > <h2 class="thankhead"><?php echo($thank_head); ?></h2> > <blockquote class="thankbody"><?php echo($thank_body); ?></blockquote> > -<a class="returnlink" href="<?php echo($referer); ?>">Return</a> > +<? if ($show_results=="Y") survey_results($sid); ?> > +<a class="returnlink" href="<?php echo($referer); ?>"><?=_('return to the survey')?></a> > <?php > return; > } > Index: public/handler.php > =================================================================== -- mcg ------------------------------------- The IT Lab (http://www.itlab.musc.edu) |