Commit 78a8676c authored by nyloth's avatar nyloth

[ENH] surveys:

  * new question type 'Multiple choices of thumbnails from a file gallery' ('g') to be able to make a multiple choice question using thumbnails from a file gallery (e.g. for voting the best 3 images of a gallery, ...),
  * new checkbox to specify if a question is mandatory,
  * new params to specify, for multiple choices questions, the minimum and maximum number of required answers (+ error message when needed),
  * fix bad vote check and reset votes values after question edit for options of type 'text',
  * deploy auto_query_args + smarty self_link / button / icon,
  * remove useless comments in some places,
  * remove some redondancy in some templates titles/subtitles,
  * avoid useless tests on $questions[ix].type value in 'tiki-take_survey.tpl',
  * new 'Create New Survey' button in 'tiki-list_surveys.tpl' navbar,
  * use famfamfam icons instead of old ones in 'tiki-list_surveys.tpl',
  * translate of 'Vote' string in 'tiki-survey_stats_survey.tpl'
parent 09efd465
......@@ -1230,6 +1230,7 @@ installer/schema/20081022_application_menu_tiki.sql -text
installer/schema/20081024_fulltext_file_tiki.sql -text
installer/schema/20081027_calendar_tiki.sql -text
installer/schema/20081027_file_galleries_tiki.sql -text
installer/schema/20081027_surveys_tiki.sql -text
installer/schema/20081027_trackers_tiki.sql -text
installer/schema/20081027_wysiwyg_history_tiki.sql -text
installer/shell.php -text
......
......@@ -2191,6 +2191,9 @@ CREATE TABLE tiki_survey_question_options (
questionId int(12) NOT NULL default '0',
qoption text,
votes int(10) default NULL,
mandatory char(1) NOT NULL default 'n',
max_answers int(5) NOT NULL default 0,
min_answers int(5) NOT NULL default 0,
PRIMARY KEY (optionId)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
......
ALTER TABLE `tiki_survey_questions` ADD COLUMN `mandatory` char(1) NOT NULL default 'n';
ALTER TABLE `tiki_survey_questions` ADD COLUMN `max_answers` int(5) NOT NULL default 0;
ALTER TABLE `tiki_survey_questions` ADD COLUMN `min_answers` int(5) NOT NULL default 0;
......@@ -22,13 +22,14 @@ class SurveyLib extends TikiLib
}
function register_survey_text_option_vote($questionId, $value) {
$cant = $this->getOne("select count(*) from `tiki_survey_question_options` where `qoption`=?",array($value));
$bindvars = array((int)$questionId, $value);
$cant = $this->getOne("select count(*) from `tiki_survey_question_options` where `questionId`=? and `qoption`=?", $bindvars);
if ($cant) {
$query = "update `tiki_survey_question_options` set `votes`=`votes`+1 where `questionId`=? and `qoption`=?";
} else {
$query = "insert into `tiki_survey_question_options`(`questionId`,`qoption`,`votes`) values(?,?,1)";
}
$result = $this->query($query, array((int)$questionId,$value));
$result = $this->query($query, $bindvars);
}
function register_survey_rate_vote($questionId, $rate) {
......@@ -40,7 +41,7 @@ class SurveyLib extends TikiLib
function register_survey_option_vote($questionId, $optionId) {
$query = "update `tiki_survey_question_options` set `votes`=`votes`+1 where `questionId`=? and `optionId`=?";
$result = $this->query($query, array((int)$questionId,(int)$optionId));
$result = $this->query($query, array((int)$questionId, (int)$optionId));
}
function clear_survey_stats($surveyId) {
......@@ -77,22 +78,24 @@ class SurveyLib extends TikiLib
return $surveyId;
}
function replace_survey_question($questionId, $question, $type, $surveyId, $position, $options) {
//$question = addslashes($question);
//$options = addslashes($options);
function replace_survey_question($questionId, $question, $type, $surveyId, $position, $options, $mandatory = 'n', $min_answers = 0, $max_answers = 0) {
if ( $mandatory != 'y' ) $mandatory = 'n';
$min_answers = (int)$min_answers;
$max_answers = (int)$max_answers;
if ($questionId) {
$query = "update `tiki_survey_questions` set `type`=?, `position`=?, `question`=?, `options`=? where `questionId`=? and `surveyId`=?";
$result = $this->query($query, array($type,(int) $position,$question,$options,(int)$questionId,(int)$surveyId));
$query = "update `tiki_survey_questions` set `type`=?, `position`=?, `question`=?, `options`=?, `mandatory`=?, `min_answers`=?, `max_answers`=? where `questionId`=? and `surveyId`=?";
$result = $this->query($query, array($type, (int)$position, $question, $options, $mandatory, (int)$min_answers, (int)$max_answers, (int)$questionId, (int)$surveyId));
} else {
$query = "insert into `tiki_survey_questions`(`question`,`type`,`surveyId`,`position`,`votes`,`value`,`options`) values(?,?,?,?,0,0,?)";
$result = $this->query($query,array($question,$type,(int)$surveyId,(int) $position,$options));
$query = "insert into `tiki_survey_questions` (`question`,`type`,`surveyId`,`position`,`votes`,`value`,`options`,`mandatory`,`min_answers`,`max_answers`) values(?,?,?,?,0,0,?,?,?,?)";
$result = $this->query($query, array($question, $type, (int)$surveyId, (int)$position, $options, $mandatory, (int)$min_answers, (int)$max_answers));
$queryid = "select max(`questionId`) from `tiki_survey_questions` where `question`=? and `type`=?";
$questionId = $this->getOne($queryid,array($question,$type));
}
if (!empty($options)) {
......@@ -105,27 +108,30 @@ class SurveyLib extends TikiLib
$result = $this->query($query,array((int)$questionId));
$ret = array();
while ($res = $result->fetchRow()) {
if (!in_array($res["qoption"], $options)) {
$query2 = "delete from `tiki_survey_question_options` where `questionId`=? and `optionId`=?";
$result2 = $this->query($query2, array((int)$questionId,(int)$res["optionId"]));
} else {
$idx = array_search($res["qoption"], $options);
unset ($options[$idx]);
// Reset question options only if not a 'text' or 'filegal choice', because their options are dynamically generated
if ( ! in_array($type, array('t','g')) ) {
while ( $res = $result->fetchRow() ) {
if ( ! in_array($res["qoption"], $options) ) {
$query2 = "delete from `tiki_survey_question_options` where `questionId`=? and `optionId`=?";
$result2 = $this->query($query2, array((int)$questionId,(int)$res["optionId"]));
} else {
$idx = array_search($res["qoption"], $options);
unset ($options[$idx]);
}
}
foreach ( $options as $option ) {
$query = "insert into `tiki_survey_question_options` (`questionId`,`qoption`,`votes`) values(?,?,0)";
$result = $this->query($query, array((int)$questionId, $option));
}
}
foreach ($options as $option) {
$query = "insert into `tiki_survey_question_options` (`questionId`,`qoption`,`votes`) values(?,?,0)";
$result = $this->query($query,array((int)$questionId,$option));
}
return $questionId;
}
function get_survey($surveyId) {
$query = "select * from `tiki_surveys` where `surveyId`=?";
$result = $this->query($query,array((int)$surveyId));
if (!$result->numRows()) return false;
$result = $this->query($query, array((int)$surveyId));
if ( ! $result->numRows() ) return false;
$res = $result->fetchRow();
return $res;
}
......@@ -169,15 +175,22 @@ class SurveyLib extends TikiLib
$ret = array();
while ($res = $result->fetchRow()) {
$questionId = $res["questionId"];
if (!empty($res['options']) && ($res["type"] == 'r' || $res["type"] == 's') )
$res['explode'] = array_fill(1,$res['options'], " ");
// save user options
$options = explode( ",", $res["options"] );
$questionId = $res["questionId"];
if ( ! empty($res['options']) ) {
if ( $res['type'] == 'g' ) {
$res['explode'] = $options;
} elseif ( in_array($res['type'], array('r','s')) ) {
$res['explode'] = array_fill(1, $res['options'], ' ');
}
}
$res["options"] = $this->getOne("select count(*) from `tiki_survey_question_options` where `questionId`=?",array((int)$res["questionId"]));
$query2 = "select * from `tiki_survey_question_options` where `questionId`=? order by `optionId`";
$query2 = "select * from `tiki_survey_question_options` where `questionId`=? order by "
. ( $res['type'] == 'g' ? '`votes` desc' : '`optionId`' );
if ($res["type"] == 'r') {
$maxwidth = 5;
......@@ -188,7 +201,7 @@ class SurveyLib extends TikiLib
$result2 = $this->query($query2,array((int)$questionId));
$ret2 = array();
$votes = 0;
$total_votes = $this->getOne("select sum(`votes`) from `tiki_survey_question_options` where `questionId`=?",array((int)$questionId));
$total_votes = $this->getOne("select sum(`votes`) as sum from `tiki_survey_question_options` where `questionId`=?",array((int)$questionId));
// store user defined options indices
$opts = array();
......@@ -196,7 +209,10 @@ class SurveyLib extends TikiLib
$opts[$options[$cpt]] = $cpt;
}
$ids = array();
while ($res2 = $result2->fetchRow()) {
///FIXME if ( $res['type'] == 'g' ) unset($files['data']
if ($total_votes) {
$average = ($res2["votes"] / $total_votes)*100;
} else {
......@@ -206,17 +222,35 @@ class SurveyLib extends TikiLib
$votes += $res2["votes"];
$res2["average"] = $average;
$res2["width"] = $average * 2;
if ($res['type'] == 'x')
if ($res['type'] == 'x') {
$res2['qoption'] = $tikilib->parse_data($res2['qoption']);
}
// when question with multiple options
// we MUST respect the user defined order
if( in_array($res['type'], array('m', 'c')) ) {
if ( in_array($res['type'], array('m', 'c')) ) {
$ret2[$opts[$res2['qoption']]] = $res2;
}
else {
} else {
$ret2[] = $res2;
}
$ids[$res2['qoption']]++;
}
// For a multiple choice from a file gallery, show all files in the stats results, even if there was no vote for those files
if ( $res['type'] == 'g' && $res['options'] > 0 ) {
$files = $this->get_files(0, -1, '', '', $options[0], false, false, false, true, false, false, false, false, '', false, false);
foreach ( $files['data'] as $f ) {
if ( ! isset($ids[$f['id']]) ) {
$ret2[] = array(
'qoption' => $f['id'],
'votes' => 0,
'average' => 0,
'width' => 0
);
}
}
unset($files);
}
$res["qoptions"] = $ret2;
......
{title url="tiki-admin_survey_questions.php?surveyId=$surveyId"}{tr}Edit survey questions:{/tr} {$survey_info.name}{/title}
<span class="button2"><a href="tiki-list_surveys.php">{tr}List surveys{/tr}</a></span>
<span class="button2"><a href="tiki-survey_stats.php">{tr}Survey Stats{/tr}</a></span>
<span class="button2"><a href="tiki-survey_stats_survey.php?surveyId={$surveyId}">{tr}this survey stats{/tr}</a></span>
<span class="button2"><a href="tiki-admin_surveys.php?surveyId={$surveyId}">{tr}Edit this Survey{/tr}</a></span>
<span class="button2"><a href="tiki-admin_surveys.php">{tr}Admin Surveys{/tr}</a></span>
<br />
<div class="navbar">
{button href="tiki-admin_survey_questions.php?surveyId=$surveyId" _text="{tr}Add a New Question{/tr}"}
{button href="tiki-list_surveys.php" _text="{tr}List surveys{/tr}"}
{button href="tiki-survey_stats.php" _text="{tr}Survey Stats{/tr}"}
{button href="tiki-survey_stats_survey.php?surveyId=$surveyId" _text="{tr}this survey stats{/tr}"}
{button href="tiki-admin_surveys.php?surveyId=$surveyId" _text="{tr}Edit this Survey{/tr}"}
{button href="tiki-admin_surveys.php" _text="{tr}Admin Surveys{/tr}"}
</div>
<br />
<h2>{tr}Create/edit questions for survey{/tr}: <a href="tiki-admin_surveys.php?surveyId={$survey_info.surveyId}">{$survey_info.name}</a></h2>
<h2>
{if $questionId gt 0}{tr}Edit Survey Question{/tr}{else}{tr}Add a New Question to this survey{/tr}{/if}
</h2>
<form action="tiki-admin_survey_questions.php" method="post">
<input type="hidden" name="surveyId" value="{$surveyId|escape}" />
<input type="hidden" name="questionId" value="{$questionId|escape}" />
......@@ -18,14 +22,24 @@
<select name="type">
<option value='c' {if $info.type eq 'c'}selected=selected{/if}>{tr}One choice{/tr}</option>
<option value='m' {if $info.type eq 'm'}selected=selected{/if}>{tr}Multiple choices{/tr}</option>
<option value='g' {if $info.type eq 'g'}selected=selected{/if}>{tr}Multiple choices of thumbnails from a file gallery{/tr}</option>
<option value='t' {if $info.type eq 't'}selected=selected{/if}>{tr}Short text{/tr}</option>
<option value='x' {if $info.type eq 'x'}selected=selected{/if}>{tr}Wiki textaera{/tr}</option>
<option value='x' {if $info.type eq 'x'}selected=selected{/if}>{tr}Wiki textarea{/tr}</option>
<option value='r' {if $info.type eq 'r'}selected=selected{/if}>{tr}Rate (1..5){/tr}</option>
<option value='s' {if $info.type eq 's'}selected=selected{/if}>{tr}Rate (1..10){/tr}</option>
<option value='r' {if $info.type eq 'r'}selected=selected{/if}>{tr}Rate{/tr}</option>
</select></td></tr>
<tr><td class="formcolor">{tr}Answer is mandatory:{/tr}</td><td class="formcolor"><input type="checkbox" name="mandatory" {if $info.mandatory eq 'y'}checked="checked"{/if}/></td></tr>
<tr><td class="formcolor">{tr}Number of required answers (for multiple choices):{/tr}</td><td class="formcolor">
{tr}Min:{/tr}<input type="text" name="min_answers" size="4" value="{$info.min_answers}" />
{tr}Max:{/tr}<input type="text" name="max_answers" size="4" value="{$info.max_answers}" />
</td></tr>
<tr><td class="formcolor">&nbsp;</td><td class="formcolor">
{remarksbox type="tip" title="{tr}Tip{/tr}"}{tr}For a multiple answer question put the answers into the following field, separated by a comma. Example: one,two,many,lots{/tr}.<br />{tr}For a rate, you can give the maximum value.{/tr}{/remarksbox}
{remarksbox type="tip" title="{tr}Tip{/tr}"}
{tr}For a multiple answer question put the answers into the following field, separated by a comma. Example: one,two,many,lots{/tr}.
<br />{tr}For a rate, you can give the maximum value.{/tr}
<br />{tr}For the 'multiple choices of thumbnail from a file gallery' type, options are: Gallery ID. Example: 4{/tr}
{/remarksbox}
</td></tr>
<tr><td class="formcolor">{tr}Options (if apply){/tr}:</td><td class="formcolor"><input type="text" name="options" value="{$info.options|escape}" size="80" /></td></tr>
<tr><td class="formcolor">&nbsp;</td><td class="formcolor"><input type="submit" name="save" value="{tr}Save{/tr}" /></td></tr>
......@@ -62,9 +76,9 @@
<td class="{cycle advance=false}">{$channels[user].question}</td>
<td class="{cycle advance=false}">{$channels[user].type}</td>
<td class="{cycle advance=false}">{$channels[user].options}</td>
<td class="odd">
<a class="link" href="tiki-admin_survey_questions.php?surveyId={$surveyId}&amp;offset={$offset}&amp;sort_mode={$sort_mode}&amp;remove={$channels[user].questionId}">{tr}Delete{/tr}</a>
<a class="link" href="tiki-admin_survey_questions.php?surveyId={$surveyId}&amp;offset={$offset}&amp;sort_mode={$sort_mode}&amp;questionId={$channels[user].questionId}">{tr}Edit{/tr}</a>
<td class="{cycle advance=false}">
{self_link _icon='page_edit' questionId=$channels[user].questionId}{tr}Edit{/tr}{/self_link}
{self_link _icon='cross' remove=$channels[user].questionId}{tr}Delete{/tr}{/self_link}
</td>
</tr>
{/section}
......@@ -87,4 +101,3 @@
{/if}
</div>
</div>
......@@ -3,8 +3,8 @@
{title help="Surveys"}{tr}Admin surveys{/tr}{/title}
<div class="navbar">
<span class="button2"><a href="tiki-list_surveys.php">{tr}List Surveys{/tr}</a></span>
<span class="button2"><a href="tiki-survey_stats.php">{tr}Survey Stats{/tr}</a></span>
{button href="tiki-list_surveys.php" _text="{tr}List Surveys{/tr}"}
{button href="tiki-survey_stats.php" _text="{tr}Survey Stats{/tr}"}
</div>
{if $info.surveyId > 0}
......@@ -19,27 +19,21 @@
<input type="hidden" name="surveyId" value="{$info.surveyId|escape}" />
<table class="normal">
<tr class="formcolor">
<!-- the tiny field for giving it a name-->
<td>{tr}Name{/tr}:</td>
<td>
<!-- % works here -->
<input type="text" name="name" size="80" value="{$info.name|escape}" /></td>
</tr>
<tr class="formcolor">
<td>{tr}Description{/tr}:</td>
<td>
<!-- % !work here hence the wonkiness in formatting... ugly as dirt -->
<textarea name="description" rows="4" cols="80">{$info.description|escape}</textarea></td></tr>
{include file=categorize.tpl}
<tr class="formcolor">
<td>{tr}Status{/tr}</td>
<td>
<select name="status">
<!-- the survey has an on and off button... could be applied to quizzes -->
<option value="o" {if $info.status eq 'o'}selected='selected'{/if}>{tr}Open{/tr}</option>
<option value="c" {if $info.status eq 'c'}selected='selected'{/if}>{tr}closed{/tr}</option>
</select>
......@@ -47,29 +41,19 @@
<tr class="formcolor"><td>&nbsp;</td><td><input type="submit" name="save" value="{tr}Save{/tr}" /></td></tr>
</table>
</form>
<!-- find in existing surveys -->
<br />
<h2>{tr}Surveys{/tr}</h2>
{if $channels or ($find ne '')}
{include file='find.tpl' _sort_mode='y'}
{/if}
<!-- existing surveys -->
<table class="normal">
<tr>
<th>
<!-- table: sort by ID -->
<a href="tiki-admin_surveys.php?offset={$offset}&amp;sort_mode={if $sort_mode eq 'surveyId_desc'}surveyId_asc{else}surveyId_desc{/if}">{tr}ID{/tr}</a></th>
<!-- table: sort by name -->
<th><a href="tiki-admin_surveys.php?offset={$offset}&amp;sort_mode={if $sort_mode eq 'name_desc'}name_asc{else}name_desc{/if}">{tr}Name{/tr}</a></th>
<!-- table: sort by description-->
<th><a href="tiki-admin_surveys.php?offset={$offset}&amp;sort_mode={if $sort_mode eq 'description_desc'}description_asc{else}description_desc{/if}">{tr}Description{/tr}</a></th>
<!-- table: sort by stat: which appears rediculous becuase there is nothing to sort-->
<th><a href="tiki-admin_surveys.php?offset={$offset}&amp;sort_mode={if $sort_mode eq 'status_desc'}status_asc{else}status_desc{/if}">{tr}Status{/tr}</a></th>
<!-- table: sort by question but it doesn't work and I don't know why-->
{*
<th><a href="tiki-admin_surveys.php?offset={$offset}&amp;sort_mode={if $sort_mode eq 'question_desc'}question_asc{else}question_desc{/if}">{tr}Questions{/tr}</th>
*}
<th>{tr}Questions{/tr}</th>
<th>{tr}Action{/tr}</th>
......@@ -103,7 +87,6 @@
<tr><td class="odd" colspan="6">{tr}No records found.{/tr}</td></tr>
{/section}
</table>
<!-- the little page adjust... need to find the $prefs.maxRecords value so that we can set that to a user controlled value-->
<div class="mini">
{if $prev_offset >= 0}
......@@ -122,5 +105,3 @@
{/section}
{/if}
</div>
<!--end tiki-admin_surveys.tpl... last edited by dgd-->
{* $Id$ *}
{title help="Surveys"}{tr}Surveys{/tr}{/title}
<div class="navbar">
{if $tiki_p_view_survey_stats eq 'y'}
<div class="navbar">
<span class="button2"><a href="tiki-survey_stats.php">{tr}Survey stats{/tr}</a></span>
</div>
{button href="tiki-survey_stats.php" _text="{tr}Survey stats{/tr}"}
{/if}
{if $tiki_p_admin_surveys eq 'y'}
{button href="tiki-admin_surveys.php" _text="{tr}Create New Survey{/tr}"}
{/if}
</div>
<table class="normal">
<tr>
......@@ -32,17 +35,16 @@
<td style="text-align:right;" class="{cycle}">
{if ($tiki_p_admin_surveys eq 'y') or ($channels[user].status eq 'o' and $channels[user].taken_survey eq 'n')}
<a href="tiki-take_survey.php?surveyId={$channels[user].surveyId}">
<img border='0' title='{tr}Take Survey{/tr}' alt='{tr}Take Survey{/tr}' width="16" height="16" hspace="6" vspace="0" src='img/icons/toright.gif' /></a>
<a href="tiki-take_survey.php?surveyId={$channels[user].surveyId}">{icon _id='control_play' alt='{tr}Take Survey{/tr}}</a>
{/if}
{if ($tiki_p_admin eq 'y') or ($channels[user].individual eq 'n' and $tiki_p_view_survey_stats eq 'y') or ($channels[user].individual_tiki_p_view_survey_stats eq 'y')}
<a href="tiki-survey_stats_survey.php?surveyId={$channels[user].surveyId}">
<img border='0' title='{tr}Stats{/tr}' alt='{tr}Stats{/tr}' width="16" height="16" hspace="3" vspace="0" src='img/icons/zoom.gif' /></a>{/if}
<a href="tiki-survey_stats_survey.php?surveyId={$channels[user].surveyId}">{icon _id='chart_curve' alt='{tr}Stats{/tr}'}</a>
{/if}
{if ($tiki_p_admin eq 'y') or ($channels[user].individual eq 'n' and $tiki_p_admin_surveys eq 'y') or ($channels[user].individual_tiki_p_admin_surveys eq 'y')}
<a href="tiki-admin_surveys.php?surveyId={$channels[user].surveyId}">
<img border='0' title='{tr}Admin{/tr}' alt='{tr}Admin{/tr}' width="16" height="16" hspace="3" vspace="0" src='img/icons/config.gif' /></a>{/if}
<a href="tiki-admin_surveys.php?surveyId={$channels[user].surveyId}">{icon _id='page_edit' alt='{tr}Edit this Survey{/tr}'}</a>
{/if}
</td>
</tr>
{/if}
......
......@@ -3,14 +3,13 @@
{title}{tr}Stats for surveys{/tr}{/title}
<div class="navbar">
<span class="button2"><a href="tiki-list_surveys.php">{tr}List Surveys{/tr}</a></span>
<span class="button2"><a href="tiki-survey_stats.php">{tr}Survey Stats{/tr}</a></span>
{if $tiki_p_admin_surveys eq 'y'}
<span class="button2"><a href="tiki-admin_surveys.php">{tr}Admin Surveys{/tr}</a></span>
{/if}
{button href="tiki-list_surveys.php" _text="{tr}List Surveys{/tr}"}
{button href="tiki-survey_stats.php" _text="{tr}Survey Stats{/tr}"}
{if $tiki_p_admin_surveys eq 'y'}
{button href="tiki-admin_surveys.php" _text="{tr}Admin Surveys{/tr}"}
{/if}
</div>
<h2>{tr}Surveys{/tr}</h2>
<div align="center">
<table class="findtable">
<tr><td class="findtable">{tr}Find{/tr}</td>
......
{title}{tr}Stats for survey:{/tr}{$survey_info.name}{/title}
<span class="button2"><a href="tiki-list_surveys.php">{tr}List Surveys{/tr}</a></span>
<span class="button2"><a href="tiki-survey_stats.php">{tr}Survey Stats{/tr}</a></span>
{if $tiki_p_admin_surveys eq 'y'}
<span class="button2"><a href="tiki-admin_surveys.php?surveyId={$surveyId}">{tr}Edit this Survey{/tr}</a></span>
<span class="button2"><a href="tiki-survey_stats_survey.php?surveyId={$surveyId}&amp;clear={$surveyId}">{tr}Clear Stats{/tr}</a></span>
<span class="button2"><a href="tiki-admin_surveys.php">{tr}Admin Surveys{/tr}</a></span>
{/if}
<br /><br />
<div class="navbar">
{button href="tiki-list_surveys.php" _text="{tr}List Surveys{/tr}"}
{button href="tiki-survey_stats.php" _text="{tr}Survey Stats{/tr}"}
{if $tiki_p_admin_surveys eq 'y'}
{button href="tiki-admin_surveys.php?surveyId=`$surveyId`" _text="{tr}Edit this Survey{/tr}"}
{button href="tiki-survey_stats_survey.php?surveyId=`$surveyId`&amp;clear=`$surveyId`" _text="{tr}Clear Stats{/tr}"}
{button href="tiki-admin_surveys.php" _text="{tr}Admin Surveys{/tr}"}
{/if}
</div>
<br />
<h2>{tr}Stats for this survey Questions {/tr}</h2>
{section name=ix loop=$channels}
<table class="normal">
<tr>
......@@ -17,29 +18,41 @@
</tr>
{if $channels[ix].type eq 'r'}
<tr>
<td class="odd">Votes:</td>
<td class="odd">{$channels[ix].votes}</td>
<td class="odd">{tr}Votes:{/tr}</td>
<td class="odd">{$channels[ix].votes}</td>
</tr>
<tr>
<td class="odd">{tr}Average{/tr}:</td>
<td class="odd">{tr}Average:{/tr}</td>
<td class="odd">{$channels[ix].average|string_format:"%.2f"}</td>
</tr>
{elseif $channels[ix].type eq 's'}
<tr>
<td class="odd">Votes:</td>
<td class="odd">{$channels[ix].votes}</td>
<td class="odd">{tr}Votes:{/tr}</td>
<td class="odd">{$channels[ix].votes}</td>
</tr>
<tr>
<td class="odd">{tr}Average{/tr}:</td>
<td class="odd">{tr}Average:{/tr}</td>
<td class="odd">{$channels[ix].average|string_format:"%.2f"}/10</td>
</tr>
{else}
{section name=jx loop=$channels[ix].qoptions}
<tr>
<td class="odd">{$channels[ix].qoptions[jx].qoption}</td>
<td class="odd">{$channels[ix].qoptions[jx].votes}</td>
<td class="odd">{$channels[ix].qoptions[jx].average|string_format:"%.2f"}%</td>
<td class="odd"><img src="img/leftbar.gif" alt="&lt;" /><img alt="-" src="img/mainbar.gif" height="14" width="{$channels[ix].qoptions[jx].width}" /><img src="img/rightbar.gif" alt="&gt;" /></td>
<td class="odd">
{if $channels[ix].type eq 'g'}
<div style="float:left">
{thumb _id=$channels[ix].qoptions[jx].qoption _max=40 name='thumb' style='margin:3px;'}
</div>
<div>
{fileinfo _id=$channels[ix].qoptions[jx].qoption _field='name' _link='thumb'}
<br />{fileinfo _id=$channels[ix].qoptions[jx].qoption _field='description'}
</div>
{else}
{$channels[ix].qoptions[jx].qoption}
{/if}
</td>
<td class="odd">{$channels[ix].qoptions[jx].votes}</td>
<td class="odd">{$channels[ix].qoptions[jx].average|string_format:"%.2f"}%</td>
<td class="odd"><img src="img/leftbar.gif" alt="&lt;" /><img alt="-" src="img/mainbar.gif" height="14" width="{$channels[ix].qoptions[jx].width}" /><img src="img/rightbar.gif" alt="&gt;" /></td>
</tr>
{/section}
{/if}
......
{if $error_msg neq ''}
{remarksbox type="warning" title="{tr}Warning{/tr}"}{$error_msg}{/remarksbox}
<br />
{/if}
<form name="aform" formId='editpageform' action="tiki-take_survey.php" method="post">
<input type="hidden" name="surveyId" value="{$surveyId|escape}" />
<input type="hidden" name="vote" value="yes" />
......@@ -12,16 +16,12 @@
<input type="radio" value="{$questions[ix].qoptions[jx].optionId|escape}" name="question_{$questions[ix].questionId}" />{$questions[ix].qoptions[jx].qoption}<br />
{/section}
</div>
{/if}
{if $questions[ix].type eq 't'}
{elseif $questions[ix].type eq 't'}
<div class="quizoptions">
<input type="text" name="question_{$questions[ix].questionId}" />
</div>
{/if}
{if $questions[ix].type eq 'x'}
{assign var='area' value=$questions[ix].questionId}
{elseif $questions[ix].type eq 'x'}
{assign var='area' value=$questions[ix].questionId}
<div class="quizoptions">
<table class="normal">
......@@ -42,17 +42,13 @@
</tr>
</table>
</div>
{/if}
{if $questions[ix].type eq 'm'}
{elseif $questions[ix].type eq 'm'}
<div class="quizoptions">
{section name=jx loop=$questions[ix].qoptions}
<input type="checkbox" value="{$questions[ix].qoptions[jx].optionId|escape}" name="question_{$questions[ix].questionId}[{$questions[ix].qoptions[jx].optionId}]" />{$questions[ix].qoptions[jx].qoption}<br />
{/section}
</div>
{/if}
{if $questions[ix].type eq 'r' or $questions[ix].type eq 's'}
{elseif $questions[ix].type eq 'r' or $questions[ix].type eq 's'}
<div class="quizoptions">
{if $questions[ix].options}
{foreach from=$questions[ix].explode key=k item=j}
......@@ -77,6 +73,8 @@
<input type="radio" value="10" name="question_{$questions[ix].questionId}" />10
{/if}
</div>
{elseif $questions[ix].type eq 'g'}
{fgal_browse _id=$questions[ix].explode.0 show_selectall='n' show_infos='n' checkbox_label="{tr}Choose{/tr}" file_checkbox_name="question_`$questions[ix].questionId`"}
{/if}
</div>
{/section}
......
......@@ -8,25 +8,23 @@
// Initialization
require_once ('tiki-setup.php');
include_once ('lib/surveys/surveylib.php');
$auto_query_args = array('surveyId','questionId','offset','find','sort_mode','maxRecords');
if ($prefs['feature_surveys'] != 'y') {
$smarty->assign('msg', tra("This feature is disabled").": feature_surveys");
$smarty->display("error.tpl");
die;
}
if (!isset($_REQUEST["surveyId"])) {
$smarty->assign('msg', tra("No survey indicated"));
$smarty->display("error.tpl");
die;
}
$smarty->assign('surveyId', $_REQUEST["surveyId"]);
$smarty->assign('individual', 'n');
if ($userlib->object_has_one_permission($_REQUEST["surveyId"], 'survey')) {
......@@ -77,6 +75,9 @@ if ($_REQUEST["questionId"]) {
$info["type"] = '';
$info["position"] = '';
$info["options"] = '';
$info["mandatory"] = '';
$info["min_answers"] = '';
$info["max_answers"] = '';
}
$smarty->assign_by_ref('info', $info);
......@@ -93,13 +94,25 @@ if (isset($_REQUEST["remove"])) {
if (isset($_REQUEST["save"])) {
check_ticket('admin-survey-questions');
$srvlib->replace_survey_question($_REQUEST["questionId"], $_REQUEST["question"], $_REQUEST["type"], $_REQUEST["surveyId"],
$_REQUEST["position"], $_REQUEST["options"]);
$srvlib->replace_survey_question(
$_REQUEST["questionId"],
$_REQUEST["question"],
$_REQUEST["type"],
$_REQUEST["surveyId"],
$_REQUEST["position"],
$_REQUEST["options"],
isset($_REQUEST["mandatory"]) ? 'y' : 'n',
$_REQUEST["min_answers"],
$_REQUEST["max_answers"]
);
$info["question"] = '';
$info["type"] = '';
$info["position"] = '';
$info["options"] = '';
$info["mandatory"] = '';
$info["min_answers"] = '';
$info["max_answers"] = '';
$smarty->assign('questionId', 0);
$smarty->assign('info', $info);
}
......
......@@ -6,10 +6,9 @@
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// Initialization
// Initialization:
$section = 'surveys';
require_once ('tiki-setup.php');
include_once ('lib/surveys/surveylib.php');
if ($prefs['feature_categories'] == 'y') {
......@@ -21,14 +20,12 @@ if ($prefs['feature_categories'] == 'y') {
if ($prefs['feature_surveys'] != 'y') {
$smarty->assign('msg', tra("This feature is disabled").": feature_surveys");
$smarty->display("error.tpl");
die;
}
if (!isset($_REQUEST["surveyId"])) {
$smarty->assign('msg', tra("No survey indicated"));
$smarty->display("error.tpl");
die;
}
......@@ -75,10 +72,10 @@ if ($userlib->object_has_one_permission($_REQUEST["surveyId"], 'survey')) {
$smarty->assign('surveyId', $_REQUEST["surveyId"]);
$survey_info = $srvlib->get_survey($_REQUEST["surveyId"]);
$smarty->assign('survey_info', $survey_info);
if ($tiki_p_take_survey != 'y') {
$smarty->assign('msg', tra("You don't have permission to use this feature"));
$smarty->display("error.tpl");
die;
}
......@@ -87,7 +84,6 @@ if ($tiki_p_take_survey != 'y') {
if ($tiki_p_admin != 'y') {
if ($tikilib->user_has_voted($user, 'survey' . $_REQUEST["surveyId"])) {
$smarty->assign('msg', tra("You cannot take this survey twice"));
$smarty->display("error.tpl");
die;
}
......@@ -96,52 +92,88 @@ if ($tiki_p_admin != 'y') {
if ($_REQUEST["vote"])
$srvlib->add_survey_hit($_REQUEST["surveyId"]);
$smarty->assign('survey_info', $survey_info);
$questions = $srvlib->list_survey_questions($_REQUEST["surveyId"], 0, -1, 'position_asc', '');
$smarty->assign_by_ref('questions', $questions["data"]);
if (isset($_REQUEST["ans"])) {
check_ticket('take-survey');
foreach ($questions[