source: temp/test-xoops.ec-cube.net/html/modules/xoopspoll/index.php @ 405

Revision 405, 7.0 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: index.php,v 1.3 2005/09/04 20:46:12 onokazu Exp $
3//  ------------------------------------------------------------------------ //
4//                XOOPS - PHP Content Management System                      //
5//                    Copyright (c) 2000 XOOPS.org                           //
6//                       <http://www.xoops.org/>                             //
7// ------------------------------------------------------------------------- //
8//  This program is free software; you can redistribute it and/or modify     //
9//  it under the terms of the GNU General Public License as published by     //
10//  the Free Software Foundation; either version 2 of the License, or        //
11//  (at your option) any later version.                                      //
12//                                                                           //
13//  You may not change or alter any portion of this comment or credits       //
14//  of supporting developers from this source code or any supporting         //
15//  source code which is considered copyrighted (c) material of the          //
16//  original comment or credit authors.                                      //
17//                                                                           //
18//  This program is distributed in the hope that it will be useful,          //
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21//  GNU General Public License for more details.                             //
22//                                                                           //
23//  You should have received a copy of the GNU General Public License        //
24//  along with this program; if not, write to the Free Software              //
25//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26//  ------------------------------------------------------------------------ //
27include "../../mainfile.php";
28include XOOPS_ROOT_PATH."/modules/xoopspoll/include/constants.php";
29include_once XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspoll.php";
30include_once XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspolloption.php";
31include_once XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspolllog.php";
32include_once XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspollrenderer.php";
33if ( !empty($_POST['poll_id']) ) {
34    $poll_id = intval($_POST['poll_id']);
35} elseif (!empty($_GET['poll_id'])) {
36    $poll_id = intval($_GET['poll_id']);
37}
38
39if ( empty($poll_id) ) {
40    $xoopsOption['template_main'] = 'xoopspoll_index.html';
41    include XOOPS_ROOT_PATH."/header.php";
42    $limit = (!empty($_GET['limit'])) ? intval($_GET['limit']) : 50;
43    $start = (!empty($_GET['start'])) ? intval($_GET['start']) : 0;
44    $xoopsTpl->assign('lang_pollslist', _PL_POLLSLIST);
45    $xoopsTpl->assign('lang_pollquestion' , _PL_POLLQUESTION);
46    $xoopsTpl->assign('lang_pollvoters', _PL_VOTERS);
47    $xoopsTpl->assign('lang_votes', _PL_VOTES);
48    $xoopsTpl->assign('lang_expiration', _PL_EXPIRATION);
49    $xoopsTpl->assign('lang_results', _PL_RESULTS);
50    // add 1 to $limit to know whether there are more polls
51    $polls_arr =& XoopsPoll::getAll(array(), true, "weight ASC, end_time DESC", $limit+1, $start);
52    $polls_count = count($polls_arr);
53    $max = ( $polls_count > $limit ) ? $limit : $polls_count;
54    for ( $i = 0; $i < $max; $i++ ) {
55    $polls = array();
56    $polls['pollId'] = $polls_arr[$i]->getVar("poll_id");
57        if ( $polls_arr[$i]->getVar("end_time") > time() ) {
58            $polls['pollEnd'] = formatTimestamp($polls_arr[$i]->getVar("end_time"),"m");
59            $polls['pollQuestion'] = "<a href='index.php?poll_id=".$polls_arr[$i]->getVar("poll_id")."'>".$polls_arr[$i]->getVar("question")."</a>";
60        } else {
61            $polls['pollEnd'] = "<span style='color:#ff0000;'>"._PL_EXPIRED."</span>";
62            $polls['pollQuestion'] = $polls_arr[$i]->getVar("question");
63        }
64    $polls['pollVoters'] = $polls_arr[$i]->getVar("voters");
65    $polls['pollVotes'] = $polls_arr[$i]->getVar("votes");
66    $xoopsTpl->append('polls', $polls);
67    unset($polls);
68    }
69    include XOOPS_ROOT_PATH."/footer.php";
70} elseif ( !empty($_POST['option_id']) ) {
71    $voted_polls = (!empty($_COOKIE['voted_polls'])) ? $_COOKIE['voted_polls'] : array();
72    $mail_author = false;
73    $poll = new XoopsPoll($poll_id);
74    if ( !$poll->hasExpired() ) {
75        if ( empty($voted_polls[$poll_id]) ) {
76            if ( $xoopsUser ) {
77                if ( XoopsPollLog::hasVoted($poll_id, xoops_getenv('REMOTE_ADDR'), $xoopsUser->getVar("uid")) ) {
78                    setcookie("voted_polls[$poll_id]", 1, 0);
79                    $msg = _PL_ALREADYVOTED;
80                } else {
81                    $poll->vote($_POST['option_id'], xoops_getenv('REMOTE_ADDR'), $xoopsUser->getVar("uid"));
82                    $poll->updateCount();
83                    setcookie("voted_polls[$poll_id]", 1, 0);
84                    $msg = _PL_THANKSFORVOTE;
85                }
86            } else {
87                if ( XoopsPollLog::hasVoted($poll_id, xoops_getenv('REMOTE_ADDR')) ) {
88                    setcookie("voted_polls[$poll_id]", 1, 0);
89                    $msg = _PL_ALREADYVOTED;
90                } else {
91                    $poll->vote($_POST['option_id'], xoops_getenv('REMOTE_ADDR'));
92                    $poll->updateCount();
93                    setcookie("voted_polls[$poll_id]", 1, 0);
94                    $msg = _PL_THANKSFORVOTE;
95                }
96            }
97        } else {
98            $msg = _PL_ALREADYVOTED;
99        }
100    } else {
101        $msg = _PL_SORRYEXPIRED;
102        if ( $poll->getVar("mail_status") != POLL_MAILED ) {
103            $xoopsMailer =& getMailer();
104            $xoopsMailer->useMail();
105            $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH."/modules/xoopspoll/language/".$xoopsConfig['language']."/mail_template/");
106            $xoopsMailer->setTemplate("mail_results.tpl");
107            $author = new XoopsUser($poll->getVar("user_id"));
108            $xoopsMailer->setToUsers($author);
109            $xoopsMailer->assign("POLL_QUESTION", $poll->getVar("question"));
110            $xoopsMailer->assign("POLL_START", formatTimestamp($poll->getVar("start_time"), "l", $author->timezone()));
111            $xoopsMailer->assign("POLL_END", formatTimestamp($poll->getVar("end_time"), "l", $author->timezone()));
112            $xoopsMailer->assign("POLL_VOTES", $poll->getVar("votes"));
113            $xoopsMailer->assign("POLL_VOTERS", $poll->getVar("voters"));
114            $xoopsMailer->assign("POLL_ID", $poll->getVar("poll_id"));
115            $xoopsMailer->assign("SITENAME", $xoopsConfig['sitename']);
116            $xoopsMailer->assign("ADMINMAIL", $xoopsConfig['adminmail']);
117            $xoopsMailer->assign("SITEURL", $xoopsConfig['xoops_url']."/");
118
119            $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
120            $xoopsMailer->setFromName($xoopsConfig['sitename']);
121            $xoopsMailer->setSubject(sprintf(_PL_YOURPOLLAT,$author->uname(),$xoopsConfig['sitename']));
122            if ( $xoopsMailer->send() != false ) {
123                $poll->setVar("mail_status", POLL_MAILED);
124                $poll->store();
125            }
126        }
127    }
128    redirect_header(XOOPS_URL."/modules/xoopspoll/pollresults.php?poll_id=$poll_id", 1, $msg);
129    exit();
130} elseif ( !empty($poll_id) ) {
131    $xoopsOption['template_main'] = 'xoopspoll_view.html';
132    include XOOPS_ROOT_PATH."/header.php";
133    $poll = new XoopsPoll($poll_id);
134    $renderer = new XoopsPollRenderer($poll);
135    $renderer->assignForm($xoopsTpl);
136    $xoopsTpl->assign('lang_vote' , _PL_VOTE);
137    $xoopsTpl->assign('lang_results' , _PL_RESULTS);
138    include XOOPS_ROOT_PATH."/footer.php";
139}
140?>
Note: See TracBrowser for help on using the repository browser.