$survey = Survey::retrieveSurvey($id); // retrieves the survey object structure
if ($survey == null || !$survey->isValid()) {
return $this->show_error($page, "Sondage ".$id." introuvable.", 'survey');
- } elseif (!$survey->isEnded()) {
+ } elseif (!$survey->isEnded() && !$survey->canSeeEarlyResults(S::user())) {
return $this->show_error($page, "Le sondage ".$survey->getTitle()." n'est pas encore terminé.", 'survey');
}
if (!$this->check_surveyPerms($page, $survey)) {
private $promos;
private $valid;
private $questions;
+ private $creator;
public function __construct($args, $id = -1, $valid = false, $questions = null)
{
$this->title = $args['title'];
$this->description = $args['description'];
$this->end = $args['end'];
- $this->mode = (isset($args['mode']))? $args['mode'] : self::MODE_ALL;
+ $this->mode = (isset($args['mode']))? $args['mode'] : self::MODE_ALL;
+ $this->creator = $args['uid'];
if ($this->mode == self::MODE_ALL) {
$args['promos'] = '';
}
$args['promos'] = str_replace(' ', '', $args['promos']);
$this->promos = ($args['promos'] == '' || preg_match('#^(\d{4}-?|(\d{4})?-\d{4})(,(\d{4}-?|(\d{4})?-\d{4}))*$#', $args['promos']))? $args['promos'] : '#';
}
+
+ public function canSeeEarlyResults(User $user)
+ {
+ return $user->id() == $this->creator || $user->checkPerms('admin');
+ }
// }}}
// {{{ functions to access general information
// {{{ static function retrieveSurvey() : gets a survey in database (and unserialize the survey object structure)
public static function retrieveSurvey($sid)
{
- $sql = 'SELECT questions, title, description, end, mode, promos
+ $sql = 'SELECT questions, title, description, end, mode, promos, uid
FROM surveys
WHERE id={?}';
$res = XDB::query($sql, $sid);
{* Survey::MODE_ALL equals 0. *}
{assign var=SurveyMODE_ALL value=0}
+{if $survey_current->total() > 0 || $smarty.session.auth}
<table class="bicol">
<tr>
- <th>
+ <th colspan="3">
Sondages en cours
</th>
</tr>
{iterate item=s from=$survey_current}
{if $smarty.session.auth || $s.mode == $SurveyMODE_ALL}
<tr class="{cycle name=cs_cycle values="impair,pair"}">
- <td class="half">
- •
- <a href="survey/vote/{$s.id}">
- {$s.title} [{$s.end|date_format:"%x"} - {$survey_modes[$s.mode]}]
- </a>
+ <td class="half" style="clear: both">
+ <a href="survey/vote/{$s.id}">{$s.title}</a>
+ {if $s.uid eq $smarty.session.user->id() || hasPerm('admin')}
+ (<a href="survey/result/{$s.id}">résultats partiels</a>)
+ {/if}
+ </td>
+ <td>
+ {$s.end|date_format:"%x"}
+ </td>
+ <td>
+ {$survey_modes[$s.mode]}
</td>
</tr>
{assign var="has_cs" value="true"}
{/if}
{/iterate}
<tr class="impair">
- <td class="half">
- {if !$has_cs}Aucun sondage en cours{/if}
- {if $smarty.session.auth}<a style="display: block; float: right;" href="survey/edit/new">{icon name=page_edit} Proposer un sondage</a>{/if}
+ <td colspan="3" style="text-align: right">
+ {if $smarty.session.auth}<a href="survey/edit/new">{icon name=page_edit} Proposer un sondage</a>{/if}
</td>
</tr>
</table>
+{/if}
<br />
<table class="bicol">
<tr>
- <th>
+ <th colspan="3">
Anciens sondages
</th>
</tr>
{iterate item=s from=$survey_old}
{if $smarty.session.auth || $s.mode == $SurveyMODE_ALL}
<tr class="{cycle name=os_cycle values="impair,pair"}">
- <td class="half">
- •
+ <td>
<a href="survey/result/{$s.id}">
- {$s.title} [{$s.end|date_format:"%x"} - {$survey_modes[$s.mode]}]
+ {$s.title}
</a>
</td>
+ <td>
+ {$s.end|date_format:"%x"}
+ </td>
+ <td>
+ {$survey_modes[$s.mode]}
+ </td>
</tr>
{assign var="has_os" value="true"}
{/if}