<?php $config[‘db_poll_lite_questions’] = $config[‘dir_db’].LANGUAGE.’_poll_lite_questions.php’; $config[‘db_poll_lite_answers’] = $config[‘dir_db’].LANGUAGE.’_poll_lite_answers.php’; $config[‘db_poll_lite_votes’] = $config[‘dir_db’].LANGUAGE.’_poll_lite_votes.php’; $config[‘max_answers’] = 5; define( ‘DB_POLL_LITE_QUESTIONS’, $config[‘db_poll_lite_questions’] ); define( ‘DB_POLL_LITE_ANSWERS’, $config[‘db_poll_lite_answers’] ); define( ‘DB_POLL_LITE_VOTES’, $config[‘db_poll_lite_votes’] ); define( ‘MAX_ANSWERS’, $config[‘max_answers’] ); define( ‘POLL_LITE_COOKIE_NAME’, ‘iPollLiteAnswer’ ); /* $lang[‘PollLiteVote’] = ‘Głosuj’; $lang[‘poll’] = ‘sonda’; $lang[‘Poll’] = ‘Sonda’; $lang[‘Question’] = ‘Pytanie’; $lang[‘Answer’] = ‘Odpowiedź’; $lang[‘PollQuestionSelected’] = ‘Wybrano’; $lang[‘PollQuestionTimes’] = ‘razy’; $lang[‘Reset_answers_selected’] = ‘Zeruj wyniki’; $lang[‘Are_you_sure’] = ‘Jesteś pewny?’; */ /** * Return list of questions for poll * @return string * @param string $sFile * @param int $iPoll * @param bool $bResult * @param string $sOption */ function throwPollAnswers( $sFile, $iPoll, $bResult = null, $sOption = null ){ global $tpl, $aList; $aData = dbThrowPollAnswers( $iPoll ); $aVotes = dbThrowPollVotes( ); if( isset( $bResult ) ) $sBlock = ‘ANSWERS_RESULT_’; else $sBlock = ‘ANSWERS_FORM_’; $iCount = count( $aData ); if( isset( $bResult ) ){ $iSummary = 0; for( $i = 0; $i < $iCount; $i++ ){ list( $aList[‘iAnswer’], $aList[‘iPoll’], $aList[‘sAnswer’] ) = $aData[$i]; if( isset( $aVotes[$aList[‘iAnswer’]] ) && is_numeric( $aVotes[$aList[‘iAnswer’]] ) ) $iSummary += $aVotes[$aList[‘iAnswer’]]; } // end for } $content = null; $iLast = 0; for( $i = 0; $i < $iCount; $i++ ){ list( $aList[‘iAnswer’], $aList[‘iPoll’], $aList[‘sAnswer’] ) = $aData[$i]; if( isset( $aVotes[$aList[‘iAnswer’]] ) && is_numeric( $aVotes[$aList[‘iAnswer’]] ) ) $aList[‘iCountAnswers’] = $aVotes[$aList[‘iAnswer’]]; else $aList[‘iCountAnswers’] = 0; if( isset( $bResult ) ){ if( $aList[‘iCountAnswers’] > 0 && $iSummary > 0 ) $aList[‘iPercentage’] = round( $aList[‘iCountAnswers’] / $iSummary * 100 ); else $aList[‘iPercentage’] = 0; } $content .= $tpl->tbHtml( $sFile, $sBlock.‘LIST’ ); $iLast = $i+1; } // end for if( $sOption == ‘admin’ && $iLast < MAX_ANSWERS ){ for( $i = $iLast; $i < MAX_ANSWERS; $i++ ){ $content .= $tpl->tbHtml( $sFile, $sBlock.‘NEW’ ); } // end for } if( isset( $content ) ) $content = $tpl->tbHtml( $sFile, $sBlock.‘HEAD’ ).$content.$tpl->tbHtml( $sFile, $sBlock.‘FOOT’ ); return $content; } // end function throwPollAnswers /** * Return list of votes for poll questions * @return array */ function dbThrowPollVotes( ){ return $GLOBALS[‘oFF’]->throwFileArraySmall( DB_POLL_LITE_VOTES, null, 0, 1 ); } // end function dbThrowPollVotes /** * Return list of questions for poll * @return array * @param int $iPoll */ function dbThrowPollAnswers( $iPoll ){ return $GLOBALS[‘oFF’]->throwFileArrayClause( DB_POLL_LITE_ANSWERS, null, 1, $iPoll ); } // end function dbThrowPollAnswers /** * Return list of questions for poll * @return array * @param int $iPoll */ function dbThrowPollAnswersId( $iPoll ){ $aData = dbThrowPollAnswers( $iPoll ); $iCount = count( $aData ); $aReturn = Array( ); for( $i = 0; $i < $iCount; $i++ ){ list( $aList[‘iAnswer’], $aList[‘iPoll’], $aList[‘sAnswer’] ) = $aData[$i]; $aReturn[$aList[‘iAnswer’]] = true; } // end for return $aReturn; } // end function dbThrowPollAnswersId /** * Returns selected answer data * @return array * @param int $iPoll */ function dbThrowPollAnswerVotes( $iAnswer ){ return $GLOBALS[‘oFF’]->throwData( DB_POLL_LITE_VOTES, $iAnswer ); } // end function dbThrowPollAnswerVotese /** * Return list of questions for poll * @return string * @param string $sFile */ function throwPollQuestions( $iPoll = null ){ $aData = dbThrowPollQuestions( $iPoll ); if( isset( $aData ) && is_array( $aData ) ) return Array( ‘iPoll’ => $aData[0], ‘sQuestions’ => $aData[1], ‘sCookieName’ => $aData[2], ‘iStatus’ => $aData[3] ); else return Array( null, null ); } // end function throwPollQuestions /** * Returns list of questions for poll * @return array * @param int $iPoll */ function dbThrowPollQuestions( $iPoll = null ){ if( !isset( $iPoll ) ) $iPoll = $GLOBALS[‘oFF’]->throwLastId( DB_POLL_LITE_QUESTIONS, 0 ); return $GLOBALS[‘oFF’]->throwData( DB_POLL_LITE_QUESTIONS, $iPoll ); } // end function dbThrowPollQuestions /** * Returns poll content * @return string * @param string $sFile * @param int $iPoll * @param string $sOption */ function throwPoll( $sFile, $iPoll = null, $sOption = null ){ global $tpl, $aData; $aData = throwPollQuestions( $iPoll ); if( $sOption == ‘admin’ ) $aData[‘sStatusSelect’] = throwYesNoSelect( $aData[‘iStatus’] ); if( is_numeric( $aData[‘iPoll’] ) && !empty( $aData[‘sQuestions’] ) && ( ( isset( $aData[‘iStatus’] ) && $aData[‘iStatus’] == 1 ) || $sOption == ‘admin’ ) ){ if( isset( $_COOKIE[LANGUAGE.’_’.POLL_LITE_COOKIE_NAME.$aData[‘sCookieName’]] ) && $sOption != ‘admin’ ) $bResult = true; else $bResult = null; $aData[‘sAnswers’] = throwPollAnswers( $sFile, $aData[‘iPoll’], $bResult, $sOption ); return $tpl->tbHtml( $sFile, ‘POLL_LITE’ ); } else return $tpl->tbHtml( $sFile, ‘NOT_EXIST’ ); } // end function throwPoll /** * Saves user selected answer * @param int $iAnswer */ function dbSavePollAnswer( $iAnswer ){ global $oFF; list( $iAnswer, $iCountAnswers ) = dbThrowPollAnswerVotes( $iAnswer ); $sPollLiteCookieName = throwPollLiteCookieName( 1 ); $oFF->setRow( Array( $iAnswer, $iCountAnswers+1 ) ); $oFF->changeInFile( DB_POLL_LITE_VOTES, $iAnswer, 0 ); $_COOKIE[LANGUAGE.’_’.POLL_LITE_COOKIE_NAME.$sPollLiteCookieName] = $iAnswer; setCookie( LANGUAGE.’_’.POLL_LITE_COOKIE_NAME.$sPollLiteCookieName, $iAnswer, time( ) + 2592000 ); } // end function dbSavePollAnswer /** * Return answers count * @return array */ function dbThrowPollAnswersCount( ){ return $GLOBALS[‘oFF’]->throwFileArraySmall( DB_POLL_LITE_VOTES, null, 0, 1 ); } // end function dbThrowPollAnswersCount /** * Saves poll data * @param array $aForm */ function savePollLite( $aForm ){ global $oFF; extract( $aForm ); $sPollLiteCookieName = throwPollLiteCookieName( $iPoll ); $oFF->setRow( Array( $iPoll, $sQuestions, $sPollLiteCookieName, $iStatus ) ); $oFF->changeInFile( DB_POLL_LITE_QUESTIONS, $iPoll, 0 ); $aAnswersOld = dbThrowPollAnswersCount( ); $iCount = count( $aAnswers ); for( $i = 0; $i < $iCount; $i++ ){ if( isset( $aAnswers[$i] ) && !empty( $aAnswers[$i] ) ){ if( isset( $aAnswersId[$i] ) && is_numeric( $aAnswersId[$i] ) ){ $oFF->setRow( Array( $aAnswersId[$i], $iPoll, $aAnswers[$i] ) ); $oFF->changeInFile( DB_POLL_LITE_ANSWERS, $aAnswersId[$i] ); $oFF->setRow( Array( $aAnswersId[$i], $aAnswersOld[$aAnswersId[$i]] ) ); $oFF->changeInFile( DB_POLL_LITE_VOTES, $aAnswersId[$i] ); } else{ $aAnswersId[$i] = $oFF->throwLastId( DB_POLL_LITE_ANSWERS, 0 ) + 1; $oFF->setRow( Array( $aAnswersId[$i], $iPoll, $aAnswers[$i] ) ); $oFF->addToFile( DB_POLL_LITE_ANSWERS ); $oFF->setRow( Array( $aAnswersId[$i], 0 ) ); $oFF->addToFile( DB_POLL_LITE_VOTES ); } } elseif( isset( $aAnswersId[$i] ) && is_numeric( $aAnswersId[$i] ) ){ $oFF->deleteInFile( DB_POLL_LITE_ANSWERS, $aAnswersId[$i] ); $oFF->deleteInFile( DB_POLL_LITE_VOTES, $aAnswersId[$i] ); } } // end for } // end function savePollLite /** * Resets poll answers * @param int $iPoll */ function resetPollAnswers( $iPoll ){ dbResetPollAnswers( $iPoll ); } // end function resetPollAnswers /** * Resets poll answers * @param int $iPoll */ function dbResetPollAnswers( $iPoll ){ $aAnswers = dbThrowPollAnswersId( $iPoll ); $sFile = DB_POLL_LITE_VOTES; $aFile = file( $sFile ); $rFile = fopen( $sFile, ‘w’ ); $iCount = count( $aFile ); for( $i = 0; $i < $iCount; $i++ ){ if( $i > 0 ){ $aFile[$i] = trim( $aFile[$i] ); $aExp = explode( ‘$’, $aFile[$i] ); if( isset( $aAnswers[$aExp[0]] ) ){ $aExp[1] = 0; $aFile[$i] = implode( ‘$’, $aExp ); } $aFile[$i] .= “\n”; } fwrite( $rFile, $aFile[$i] ); } // end for fclose( $rFile ); changePollLiteCookieName( $iPoll ); } // end function dbResetPollAnswers /** * Throws poll cookie name * @param int $iPoll */ function throwPollLiteCookieName( $iPoll ){ $aData = throwPollQuestions( $iPoll ); if( isset( $aData[‘sCookieName’] ) && !empty( $aData[‘sCookieName’] ) ) return $aData[‘sCookieName’]; else return null; } // end function throwPollLiteCookieName /** * Change poll cookie name * @param int $iPoll */ function changePollLiteCookieName( $iPoll ){ global $oFF; $aData = throwPollQuestions( $iPoll ); if( isset( $aData ) ){ $aData[‘sCookieName’] = rand( 1, 99 ); $oFF->setRow( Array( $aData[‘iPoll’], $aData[‘sQuestions’], $aData[‘sCookieName’], $aData[‘iStatus’] ) ); $oFF->changeInFile( DB_POLL_LITE_QUESTIONS, $iPoll, 0 ); } } // end function changePollLiteCookieName ?>