+ $this->clear_session();
+ $this->show_form($page, $action, 'root', 'newsurvey');
+ } // }}}
+ } elseif ($action == 'add') { // {{{ adds a new question
+ if (Post::has('survey_submit')) { // if the form has been submitted, adds the question
+ $survey = unserialize(S::v('survey'));
+ if (!$survey->addQuestion($qid, $survey->factory(Post::v('survey_type'), Post::v('survey_question')))) {
+ return $this->show_error($page, '', 'survey/edit');
+ }
+ $this->show_survey($page, $survey);
+ $this->store_session($survey);
+ } else {
+ $this->show_form($page, $action, $qid);
+ } // }}}
+ } elseif ($action == 'del') { // {{{ deletes a question
+ if (Post::has('survey_submit')) { // if a confirmation has been sent, deletes the question
+ $survey = unserialize(S::v('survey'));
+ if (!$survey->delQuestion(Post::v('survey_qid'))) { // deletes the node in the survey object structure
+ return $this->show_error($page, '', 'survey/edit');
+ }
+ $this->show_survey($page, $survey);
+ $this->store_session($survey);
+ } else { // if user has not confirmed, shows a confirmation form
+ $survey = unserialize(S::v('survey'));
+ $current = $survey->toArray($qid); // needed to get the title of the question to delete (more user-friendly than an id)
+ if ($current == null) {
+ return $this->show_error($page, '', 'survey/edit');
+ }
+ $this->show_confirm($page, 'Êtes-vous certain de vouloir supprimer la question intitulé "'.$current['question'].'" ? '
+ .'Attention, cela supprimera en même temps toutes les questions qui dépendent de celle-ci.',
+ 'edit', array('action' => 'del', 'qid' => $qid));
+ } // }}}
+ } elseif ($action == 'show') { // {{{ simply shows the survey in its current state
+ $this->show_survey($page, unserialize(S::v('survey'))); // }}}
+ } elseif ($action == 'valid') { // {{{ validates the proposition, i.e stores the proposition in the database
+ // but an admin will still need to validate the survey before it is activated
+ if (Post::has('survey_submit')) { // needs a confirmation before storing the proposition
+ $survey = unserialize(S::v('survey'));
+ if (S::has('survey_id')) { // if 'survey_id' is in session, we are modifying an existing survey (in admin mode) instead of proposing a new one
+ $link = (S::has('survey_validate'))? 'admin/validate' : 'survey/admin';
+ if ($survey->updateSurvey()) { // updates the database according the new survey object structure
+ $this->show_success($page, "Les modifications sur le sondage ont bien été enregistrées.", $link);
+ } else {
+ $this->show_error($page, '', $link);
+ }
+ } else { // if no 'survey_id' is in session, we are indeed proposing a new survey
+ if ($survey->proposeSurvey()) { // stores the survey object structure in database
+ $this->show_success($page, "Votre proposition de sondage a bien été enregistrée,
+ elle est en attente de validation par un administrateur du site.", 'survey');
+ } else {
+ $this->show_error($page, '', 'survey');
+ }
+ }
+ $this->clear_session();
+ } else { // asks for a confirmation if it has not been sent
+ $survey = unserialize(S::v('survey'));
+ $errors = $survey->checkSyntax();
+ if (!is_null($errors)) {
+ $this->show_error($page, "", 'survey/edit', $errors);
+ } else {
+ if (S::has('survey_id')) {
+ $this->show_confirm($page, "Veuillez confirmer l'enregistrement des modifications apportées à ce sondage.", 'edit', array('action' => 'valid'));
+ } else {
+ $this->show_confirm($page, "Veuillez confirmer l'envoi de cette proposition de sondage.", 'edit', array('action' => 'valid'));
+ }
+ }
+ } // }}}
+ } elseif ($action == 'cancel') { // {{{ cancels the creation/modification of a survey
+ if (Post::has('survey_submit')) { // needs a confirmation
+ if (S::has('survey_id')) { // only possible when modifying a survey in admin mode
+ if (S::has('survey_validate')) { // if a link has been supplied, uses it
+ $this->clear_session();
+ return $this->show_success($page, "Les modifications effectuées ont été annulées", 'admin/validate');
+ } else { // else shows the admin index
+ $this->clear_session();
+ return $this->handler_admin($page);
+ }
+ } else {
+ $this->clear_session();
+ return $this->handler_index($page); // else shows the 'normal' index
+ }
+ } else { // asks for a confirmation if it has not been sent
+ $this->show_confirm($page, "Êtes-vous certain de vouloir annuler totalement l'édition de ce sondage ? Attention, "
+ ."toutes les données éditées jusque là seront définitivement perdues.",
+ 'edit', array('action' => $action));