return ($long)? self::$longModes : self::$shortModes;
}
- private static $types = array('text' => 'texte court',
- 'textarea' => 'texte long',
- 'num' => 'numérique',
- 'radio' => 'radio',
- 'checkbox' => 'checkbox');
+ private static $types = array('text' => 'Texte court',
+ 'textarea' => 'Texte long',
+ 'num' => 'Numérique',
+ 'radio' => 'Choix multiples (une réponse)',
+ 'checkbox' => 'Choix multiples (plusieurs réponses)');
public static function getTypes()
{
{
$this->title = $args['title'];
$this->description = $args['description'];
- if (preg_match('#^\d{2}/\d{2}/\d{4}$#', $args['end'])) {
- $this->end = preg_replace('#^(\d{2})/(\d{2})/(\d{4})$#', '\3-\2-\1', $args['end']);
- } else {
- $this->end = (preg_match('#^\d{4}-\d{2}-\d{2}$#', $args['end']))? $args['end'] : '#';
- }
+ $this->end = $args['end'];
$this->mode = (isset($args['mode']))? $args['mode'] : self::MODE_ALL;
if ($this->mode == self::MODE_ALL) {
$args['promos'] = '';
// {{{ function checkSyntax() : checks syntax of the questions (currently the root only) before storing the survey in database
private static $errorMessages = array(
- "dateformat" => "la date de fin de sondage est mal formattée : elle doit respecter la syntaxe dd/mm/aaaa",
"datepassed" => "la date de fin de sondage est déjà dépassée : vous devez préciser une date future",
"promoformat" => "les restrictions à certaines promotions sont mal formattées"
);
public function checkSyntax()
{
$rArr = array();
- if (!preg_match('#^\d{4}-\d{2}-\d{2}$#', $this->end)) {
- $rArr[] = array('question' => 'root', 'error' => self::$errorMessages["dateformat"]);
- } else {
- // checks that the end date given is not already passed
- // (unless the survey has already been validated : an admin can have a validated survey expired)
- if (!$this->valid && $this->isEnded()) {
- $rArr[] = array('question' => 'root', 'error' => self::$errorMessages["datepassed"]);
- }
+ // checks that the end date given is not already passed
+ // (unless the survey has already been validated : an admin can have a validated survey expired)
+ if (!$this->valid && $this->isEnded()) {
+ $rArr[] = array('question' => 'root', 'error' => self::$errorMessages["datepassed"]);
}
if ($this->promos != '' && !preg_match('#^(\d{4}-?|(\d{4})?-\d{4})(,(\d{4}-?|(\d{4})?-\d{4}))*$#', $this->promos)) {
$rArr[] = array('question' => 'root', 'error' => self::$errorMessages["promoformat"]);
public function update($args)
{
parent::update($args);
- $this->choices = explode('|', $args['options']);
+ $this->choices = array();
+ foreach ($args['options'] as $val) {
+ if (trim($val)) {
+ $this->choices[] = $val;
+ }
+ }
}
public function toArray()
{
$rArr = parent::toArray();
$rArr['choices'] = $this->choices;
- $rArr['options'] = implode('|', $this->choices);
return $rArr;
}
<td class="titre">Commentaire</td>
<td><textarea name="survey_question[comment]" rows="5" cols="60">{$survey_current.comment}</textarea></td>
</tr>
+ {javascript name=jquery}
+ <script type="text/javascript">//<![CDATA[
+ var id = {$survey_current.choices|@count};
+ {literal}
+ function newChoice(tid)
+ {
+ fid = "t" + id;
+ $("#choice_" + tid).before('<div id="choice_' + fid + '">'
+ + '<input type="text" name="survey_question[options][' + fid + ']" size="50" maxlength="200" value="" /> '
+ + '<a href="javascript:removeChoice("' + fid + '")"><img src="images/icons/delete.gif" alt="" title="Supprimer" /></a>'
+ + '</div>');
+ id++;
+ }
+ function removeChoice(tid)
+ {
+ $("#choice_" + tid).remove();
+ }
+ {/literal}
+ //]]></script>
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
{include file='survey/edit_question.tpl'}
<tr>
<td class="titre">Choix</td>
- <td><input type="text" name="survey_question[options]" size="50" maxlength="200" value="{$survey_current.options}"/></td>
+ <td>
+ {foreach from=$survey_current.choices key=value item=choice}
+ <div id="choice_t{$value}">
+ <input type="text" name="survey_question[options][t{$value}]" size="50" maxlength="200" value="{$choice}" />
+ <a href="javascript:removeChoice('t{$value}')">{icon name=delete title="Supprimer"}</a>
+ </div>
+ {/foreach}
+ <div id="choice_last">
+ <a href="javascript:newChoice('last')">{icon name=add}</a>
+ </div>
+ </td>
</tr>
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
</tr>
<tr>
<td class="titre">Date de fin</td>
- <td><input type="text" name="survey_question[end]" size="50" maxlength="200" value="{if $survey_current.end eq '#'}#{else}{$survey_current.end|date_format:"%d/%m/%Y"}{/if}"/></td>
+ <td>
+ {valid_date name="survey_question[end]" value=$survey_current.end to=90}
+ </td>
</tr>
+ {javascript name=jquery}
+ <script type="text/javascript">//<![CDATA[
+ {literal}
+ $(document).ready(function() {
+ function hidePromo(value) {
+ if (value == "0" || value == "") {
+ $("#ln_promo").hide();
+ } else {
+ $("#ln_promo").show();
+ }
+ }
+ $("[@name='survey_question[mode]']").change(function() { hidePromo(this.value); });
+ hidePromo({/literal}"{$survey_current.mode}"{literal});
+ });
+ {/literal}
+ //]]></script>
<tr>
<td class="titre">Type de sondage</td>
<td>
- {html_radios name="survey_question[mode]" options=$survey_modes selected=$survey_current.mode separator='<br/>'}
+ <select name="survey_question[mode]">
+ {foreach from=$survey_modes item=text key=name}
+ <option value="{$name}" {if $name eq $survey_current.mode}selected="selected"{/if}>{$text}</option>
+ {/foreach}
+ </select>
</td>
- <tr>
- <td class="titre">Promotions (si restreint aux polytechniciens)</td>
+ <tr id="ln_promo">
+ <td class="titre">Promotions</td>
<td><input type="text" name="survey_question[promos]" size="50" maxlength="200" value="{$survey_current.promos}"/></td>
</tr>
<table class="bicol" id="survey_form">
{include file="survey/edit_$survey_type.tpl"}
</table>
- <input type="submit" name="survey_submit" value="Valider"/>
- <input type="reset" name="survey_reset" value="Réinitialiser"/>
- <input type="submit" name="survey_cancel" value="Annuler"/>
+ <div class="center">
+ <input type="submit" name="survey_submit" value="Valider"/>
+ <input type="reset" name="survey_reset" value="Réinitialiser"/>
+ <input type="submit" name="survey_cancel" value="Annuler"/>
+ </div>
</form>
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
Sondages en cours
</th>
</tr>
+ <tr>
+ <td>
+ {if $survey_current->total() eq 0}
+ Aucun sondage en cours
+ {/if}
+ <a style="display: block; float: right;" href="survey/edit/new">{icon name=page_edit} Proposer un sondage</a></td>
+ </tr>
{iterate item=s from=$survey_current}
- {if $smarty.session.auth || $s.mode == Survey::MODE_ALL}
+ {if $smarty.session.auth || $s.mode == Survey::MODE_ALL}
<tr class="{cycle values="impair,pair"}">
<td class="half">
•
</a>
</td>
</tr>
- {assign var="has_cs" value="true"}
- {/if}
- {/iterate}
- {if !$has_cs}
- <tr>
- <td class="half">Aucun sondage en cours</td>
- </tr>
{/if}
+ {/iterate}
</table>
<br />
{/if}
</table>
-<a href="./survey/edit/new">Proposer un sondage</a>
-
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
{**************************************************************************}
<h1>Sondage : {$survey.title}</h1>
-<form action="./survey/vote{if $survey_votemode}/{$survey.id}{/if}" method='post'>
-{if $survey.description != ''}
- {$survey.description}
-{/if}
-<br/>Fin du sondage :
-{if $survey.end eq "#"}
- erreur
-{else}
- {$survey.end|date_format:"%x"}
-{/if}
-<br/>Type de sondage :
-{$survey_modes[$survey.mode]}
-{if $survey.mode != Survey::MODE_ALL}
- <br/>Réservé aux promotions :
- {if $survey.promos eq "#"}
- erreur
- {elseif $survey.promos eq ""}
- aucune restriction
- {else}
- {$survey.promos}
- {/if}
-{/if}
-{if $survey_warning neq ''}
- <br/>{$survey_warning}
-{/if}
-{if $survey_resultmode}
- <br/>{$survey.votes} personnes ont répondu à ce sondage.
- <br/>Récupérer <a href="./survey/result/{$survey.id}/csv">l'ensemble des résultats</a> au format csv
-{/if}
-<br/>
-{if $survey_editmode}
- {assign var="survey_rooteditmode" value=true}
- {if $survey.valid}
- {assign var="survey_editmode" value=false}
- {/if}
-{/if}
-{if $survey_rooteditmode}<a href='./survey/edit/question/root'>Modifier la racine</a>{/if}
-{if $survey_editmode} | <a href='./survey/edit/add/0'>Ajouter une question au début</a>{/if}
-{if is_array($survey.questions)}
+<form action="survey/vote{if $survey_votemode}/{$survey.id}{/if}" method='post'>
+<table style="width: 100%">
+ <tr>
+ <td>
+ <table class="bicol">
+ <tr class="pair">
+ <td colspan="2">{$survey.description}</td>
+ </tr>
+ <tr>
+ <td class="titre">Fin du sondage :</td>
+ <td>{$survey.end|date_format:"%x"}</td>
+ </tr>
+ <tr>
+ <td class="titre">Type de sondage :</td>
+ <td>{$survey_modes[$survey.mode]}</td>
+ </tr>
+ {if $survey.mode != Survey::MODE_ALL}
+ <tr>
+ <td class="titre">Promotions :</td>
+ <td>
+ {if $survey.promos eq "#"}
+ erreur
+ {elseif $survey.promos eq ""}
+ aucune restriction
+ {else}
+ {$survey.promos}
+ {/if}
+ </td>
+ </tr>
+ {/if}
+ {if $survey_warning}
+ <tr class="pair">
+ <td colspan="2">{$survey_warning}</td>
+ </tr>
+ {/if}
+ </table>
+ {if $survey_resultmode}
+ <p class="smaller">{$survey.votes} personnes ont répondu à ce sondage.<br />
+ Récupérer <a href="survey/result/{$survey.id}/csv">l'ensemble des résultats</a> au format csv
+ </p>
+ {/if}
+ </td>
+ {if $survey_editmode}
+ {assign var="survey_rooteditmode" value=true}
+ {if $survey.valid}
+ {assign var="survey_editmode" value=false}
+ {/if}
+ {/if}
+ {if $survey_editmode}
+ <td>
+ {if $survey_rooteditmode}<a href='survey/edit/question/root'>{icon name=page_edit} Modifier la description</a><br />{/if}
+ <a href='survey/edit/add/0'>{icon name=add} Ajouter une question au début</a>
+ </td>
+ {/if}
+ </tr>
+ {if is_array($survey.questions)}
{foreach from=$survey.questions item=squestion}
- {include file='survey/show_question.tpl' squestion=$squestion}
+ <tr>
+ <td>
+ {include file='survey/show_question.tpl' squestion=$squestion}
+ </td>
{if $survey_editmode}
- <br/>
- <a href='./survey/edit/question/{$squestion.id}'>Modifier cette question</a> |
- <a href='./survey/edit/del/{$squestion.id}'>Supprimer cette question</a> |
- <a href='./survey/edit/add/{$squestion.id+1}'>Ajouter une question après</a>
+ <td>
+ <a href='survey/edit/question/{$squestion.id}'>{icon name=page_edit} Modifier cette question</a><br />
+ <a href='survey/edit/del/{$squestion.id}'>{icon name=delete} Supprimer cette question</a><br />
+ <a href='survey/edit/add/{$squestion.id+1}'>{icon name=add} Ajouter une question après</a>
+ </td>
{/if}
- <br/>
+ </tr>
{/foreach}
-{/if}
-{if $survey_rooteditmode}
-<br/>
-<a href='./survey/edit/valid'>{if $survey_updatemode}Enregistrer les modifications{else}Proposer ce sondage{/if}</a> |
-<a href='./survey/edit/cancel'>Annuler {if $survey_updatemode}les modifications{else}totalement la création de ce sondage{/if}</a>
-{elseif $survey_adminmode}
-<br/>
-{if !$survey.valid}<a href="./survey/admin/valid/{$survey.id}">Valider ce sondage</a> | {/if}
-<a href="./survey/admin/edit/{$survey.id}">Modifier ce sondage</a> |
-<a href="./survey/admin/del/{$survey.id}">Supprimer ce sondage</a> |
-<a href="./survey/admin">Retour</a>
-{elseif $survey_votemode}
-<input type='submit' name='survey_submit' value='Voter'/>
-<input type='submit' name='survey_cancel' value='Annuler'/>
-{else}
-<a href="./survey">Retour</a>
-{/if}
+ {/if}
+</table>
+<p class="center">
+ {if $survey_rooteditmode}
+ <a href='survey/edit/valid'>
+ {icon name=tick}
+ {if $survey_updatemode}Enregistrer les modifications{else}Proposer ce sondage{/if}
+ </a> |
+ <a href='survey/edit/cancel'>
+ {icon name=cross} Annuler
+ {if $survey_updatemode}les modifications{else}totalement la création de ce sondage{/if}
+ </a>
+ {elseif $survey_adminmode}
+ {if !$survey.valid}<a href="survey/admin/valid/{$survey.id}">Valider ce sondage</a> | {/if}
+ <a href="survey/admin/edit/{$survey.id}">{icon name=tick} Modifier ce sondage</a> |
+ <a href="survey/admin/del/{$survey.id}">{icon name=cross} Supprimer ce sondage</a> |
+ <a href="survey/admin">Retour</a>
+ {elseif $survey_votemode}
+ <input type='submit' name='survey_submit' value='Voter'/>
+ <input type='submit' name='survey_cancel' value='Annuler'/>
+ {else}
+ <a href="survey">Retour</a>
+ {/if}
+</p>
</form>
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}