Documentation TYPO3 par Ameos

poll_submit.inc

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2001-2004 René Fritz (r.fritz@colorcube.de)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the Typo3 project. The Typo3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00036 if (is_object($this))   {
00037 
00038         if (is_array($this->newData["tt_poll"]))        {
00039 
00040 
00041                 list($uid,)=each($this->newData["tt_poll"]);
00042 
00043                 $cookieName = "t3_tt_poll_voted_".$uid;
00044 
00045                         // poll is allowed if cookie not set or the user is logged in the backend
00046                 if (((!isset($GLOBALS["HTTP_COOKIE_VARS"][$cookieName])) OR ($GLOBALS["TSFE"]->beUserLogin)) && ($this->newData["tt_poll"][$uid]["vote"])) {
00047 
00048                                 // we need the old data to calc the new one
00049                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_poll', 'uid='.intval($uid));
00050                         $actPoll = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00051 
00052                                 // we got the data so let's start
00053                         if (is_array ($actPoll)) {
00054 
00055                                         // calc the new data
00056                                 if ($submittedVote = $this->newData["tt_poll"][$uid]["vote"]) {
00057                                         $answers = explode("\n",$actPoll["answers"]);
00058                                         $newAnswers = array();
00059                                         $votesTotal = 0;
00060                                         reset($answers);
00061                                         while(list(,$value)=each($answers))     {
00062                                                 list($votes,$answer) = explode("|",$value);
00063                                                 $answer=trim($answer);
00064                                                 $votes=intval($votes);
00065                                                 if (md5($answer) == $submittedVote) {
00066                                                         $votes++;
00067                                                 }
00068                                                 $newAnswers[] = $votes."|".$answer;
00069                                                 $votesTotal += $votes;
00070                                         }
00071 
00072                                         $this->newData["tt_poll"][$uid]["votes"] = $votesTotal;
00073                                         $this->newData["tt_poll"][$uid]["answers"] = implode("\n",$newAnswers);
00074 
00075                                                 // prepare for database update
00076                                         $updateFields = array();
00077                                         unset($this->newData["tt_poll"][$uid]["uid"]);
00078                                         unset($this->newData["tt_poll"][$uid]["pid"]);
00079                                         $this->newData["tt_poll"][$uid]["tstamp"] = time();
00080 
00081                                         while(list($f,$v)=each($this->newData["tt_poll"][$uid]))        {
00082                                                 if (t3lib_div::inList("tstamp",$f) || isset($GLOBALS["TCA"]["tt_poll"]["columns"][$f])) {
00083                                                         $updateFields[$f] = $v;
00084                                                 }
00085                                         }
00086                                                 // write to database
00087                                         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_poll', 'uid='.intval($uid), $updateFields);
00088 
00089                                                 // set a cookie for preventing double polls
00090                                         setcookie($cookieName,$submittedVote,time()+(3600*24*10)); // delete cookie after 10 days
00091 
00092                                                 // clear the page cache
00093                                         if ($id = t3lib_div::_GP("clearCachePid"))      {
00094                                                 $this->clear_cacheCmd(intval($id));
00095                                         }
00096                                         if ($id = t3lib_div::_GP("clearCacheTargetPid"))        {
00097                                                 $this->clear_cacheCmd(intval($id));
00098                                         }
00099                                 }
00100                         }
00101                 } else {
00102                         // user voted already - what to do?
00103                 }
00104         }
00105 }
00106 
00107 
00108 
00109 
00110 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6