Exemple #1
0
// Something to save (edit or add)
// -------------------------------
if (!empty($_POST['save'])) {
    // Save edition of an old vote
    $name = $inputService->filterName($_POST['name']);
    $editedVote = filter_input(INPUT_POST, 'save', FILTER_VALIDATE_INT);
    $choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]);
    if (empty($editedVote)) {
        $message = new Message('danger', __('Error', 'Something is going wrong...'));
    }
    if (count($choices) != count($_POST['choices'])) {
        $message = new Message('danger', __('Error', 'There is a problem with your choices'));
    }
    if ($message == null) {
        // Update vote
        $result = $pollService->updateVote($poll_id, $editedVote, $name, $choices);
        if ($result) {
            $message = new Message('success', __('adminstuds', 'Vote updated'));
        } else {
            $message = new Message('danger', __('Error', 'Update vote failed'));
        }
    }
} elseif (isset($_POST['save'])) {
    // Add a new vote
    $name = $inputService->filterName($_POST['name']);
    $choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]);
    if ($name == null) {
        $message = new Message('danger', __('Error', 'The name is invalid.'));
    }
    if (count($choices) != count($_POST['choices'])) {
        $message = new Message('danger', __('Error', 'There is a problem with your choices'));
Exemple #2
0
if (!empty($_POST['save'])) {
    // Save edition of an old vote
    $name = $inputService->filterName($_POST['name']);
    $editedVote = filter_input(INPUT_POST, 'save', FILTER_VALIDATE_INT);
    $choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]);
    $slots_hash = $inputService->filterMD5($_POST['control']);
    if (empty($editedVote)) {
        $message = new Message('danger', __('Error', 'Something is going wrong...'));
    }
    if (count($choices) != count($_POST['choices'])) {
        $message = new Message('danger', __('Error', 'There is a problem with your choices'));
    }
    if ($message == null) {
        // Update vote
        try {
            $result = $pollService->updateVote($poll_id, $editedVote, $name, $choices, $slots_hash);
            if ($result) {
                if ($poll->editable == Editable::EDITABLE_BY_OWN) {
                    $editedVoteUniqueId = filter_input(INPUT_POST, 'edited_vote', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
                    $urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId);
                    $message = new Message('success', __('studs', 'Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:'), $urlEditVote);
                } else {
                    $message = new Message('success', __('studs', 'Update vote succeeded'));
                }
                sendUpdateNotification($poll, $mailService, $name, UPDATE_VOTE);
            } else {
                $message = new Message('danger', __('Error', 'Update vote failed'));
            }
        } catch (ConcurrentEditionException $cee) {
            $message = new Message('danger', __('Error', 'Poll has been updated before you vote'));
        }