public function get_menu_content() { global $LANG; $poll_config = PollConfig::load(); $config_cookie_name = $poll_config->get_cookie_name(); $polls = PollMiniMenuCache::load()->get_polls(); //Chargement de la langue du module. load_module_lang('poll'); $rand = array_rand($polls); $poll_mini = $polls[$rand]; //Sondage aléatoire. $tpl = new FileTemplate('poll/poll_mini.tpl'); #####################Résultats###################### //Si le cookie existe, on redirige vers les resulats, sinon on prend en compte le vote (vérification par ip plus tard). $array_cookie = array(); if (AppContext::get_request()->has_cookieparameter($config_cookie_name)) { $array_cookie = explode('/', AppContext::get_request()->get_cookie($config_cookie_name)); } if (in_array($poll_mini['id'], $array_cookie)) { $tpl->put_all(array('L_VOTE' => $poll_mini['total'] > 1 ? $LANG['poll_vote_s'] : $LANG['poll_vote'])); $tpl->assign_block_vars('result', array('QUESTION' => $poll_mini['question'], 'VOTES' => $poll_mini['total'])); foreach ($poll_mini['votes'] as $answer => $width) { $tpl->assign_block_vars('result.answers', array('ANSWERS' => $answer, 'WIDTH' => NumberHelper::round($width, 0), 'PERCENT' => $width)); } } else { #####################Questions###################### $tpl->put_all(array('L_MINI_POLL' => $LANG['mini_poll'], 'L_VOTE' => $LANG['poll_vote'], 'L_POLL_RESULT' => $LANG['poll_result'], 'U_POLL_RESULT' => url('.php?id=' . $poll_mini['id'] . '&r=1', '-' . $poll_mini['id'] . '-1.php'))); $tpl->assign_block_vars('question', array('ID' => url('.php?id=' . $poll_mini['id'], '-' . $poll_mini['id'] . '.php'), 'QUESTION' => $poll_mini['question'])); $z = 0; if ($poll_mini['type'] == '1') { if (is_array($poll_mini['votes'])) { // FIXME should always be an array, needs to patch cache generation foreach ($poll_mini['votes'] as $answer => $width) { $tpl->assign_block_vars('question.radio', array('NAME' => $z, 'ANSWERS' => $answer)); $z++; } } } elseif ($poll_mini['type'] == '0') { foreach ($poll_mini['votes'] as $answer => $width) { $tpl->assign_block_vars('question.checkbox', array('NAME' => $z, 'ANSWERS' => $answer)); $z++; } } } return $tpl->render(); }
$valid = $request->get_postvalue('valid', false); $poll_config = PollConfig::load(); //Liste des sondages affichés dans le mini module $config_displayed_in_mini_module_list = $poll_config->get_displayed_in_mini_module_list(); if ($del && !empty($id)) { AppContext::get_session()->csrf_get_protect(); //Protection csrf //On supprime des tables config et reponses des polls. PersistenceContext::get_querier()->delete(PREFIX . 'poll', 'WHERE id=:id', array('id' => $id)); ###### Régénération du cache si le sondage fait parti de la liste des sondages affichés dans le mini-module ####### if (in_array($id, $config_displayed_in_mini_module_list)) { $displayed_in_mini_module_list = $config_displayed_in_mini_module_list; unset($displayed_in_mini_module_list[array_search($id, $displayed_in_mini_module_list)]); $poll_config->set_displayed_in_mini_module_list($displayed_in_mini_module_list); PollConfig::save(); PollMiniMenuCache::invalidate(); } AppContext::get_response()->redirect('/poll/admin_poll.php'); } elseif ($valid && !empty($id_post)) { AppContext::get_session()->csrf_get_protect(); //Protection csrf $question = retrieve(POST, 'question', ''); $type = retrieve(POST, 'type', 0); $archive = retrieve(POST, 'archive', 0); $current_date = retrieve(POST, 'current_date', '', TSTRING_UNCHANGE); $start = retrieve(POST, 'start', '', TSTRING_UNCHANGE); $end = retrieve(POST, 'end', '', TSTRING_UNCHANGE); $hour = retrieve(POST, 'hour', '', TSTRING_UNCHANGE); $min = retrieve(POST, 'min', '', TSTRING_UNCHANGE); $get_visible = retrieve(POST, 'visible', 0); //On verifie les conditions!