$poll = new Poll($f_fk_language_id, $f_poll_nr); if ($poll->exists()) { // edit existing poll $parent_poll_nr = $poll->getProperty('parent_poll_nr'); $is_extended = $poll->isExtended(); $title = $poll->getProperty('title'); $question = $poll->getProperty('question'); $date_begin = $poll->getProperty('date_begin'); $date_end = $poll->getProperty('date_end'); $nr_of_answers = $poll->getProperty('nr_of_answers'); $fk_language_id = $poll->getProperty('fk_language_id'); $votes_per_user = $poll->getProperty('votes_per_user'); $poll_answers = $poll->getAnswers(); foreach ($poll_answers as $poll_answer) { $answers[$poll_answer->getProperty('nr_answer')] = $poll_answer->getProperty('answer'); } } else { // language_id may preset from from assign_popup.php $fk_language_id = Input::Get('f_language_id', 'int'); } if (empty($GLOBALS['_popup'])) { $title = $poll->exists() ? getGS('Edit Poll') : getGS('Add new Poll'); echo camp_html_breadcrumbs(array( array(getGS('Plugins'), $Campsite['WEBSITE_URL'] . '/admin/plugins/manage.php'), array(getGS('Polls'), $Campsite['WEBSITE_URL'] . '/admin/poll/index.php'),
/** * Reads the input parameters and vote the poll * * @param array $p_input */ public function __construct(array $p_input) { $this->m_defined = true; $this->m_name = 'poll'; if (!isset($p_input['f_poll_nr']) || empty($p_input['f_poll_nr'])) { $this->m_error = new PEAR_Error('The poll number is missing.', ACTION_POLL_ERR_NO_POLL_NUMBER); return false; } $this->m_properties['poll_nr'] = $p_input['f_poll_nr']; if (!isset($p_input['f_poll_language_id']) || empty($p_input['f_poll_language_id'])) { $this->m_error = new PEAR_Error('The poll language is missing.', ACTION_POLL_ERR_NO_LANGUAGE_ID); return false; } $this->m_properties['poll_language_id'] = $p_input['f_poll_language_id']; if ($p_input['f_poll_mode'] !== 'standard' && $p_input['f_poll_mode'] !== 'ajax') { $this->m_error = new PEAR_Error('The poll mode parameter is invalid.', ACTION_POLL_ERR_INVLID_MODE); return false; } $this->m_properties['poll_mode'] = $p_input['f_poll_mode']; $Poll = new Poll($this->m_properties['poll_language_id'], $this->m_properties['poll_nr']); if (!$Poll->exists()) { $this->m_error = new PEAR_Error('Poll does not exists.', ACTION_POLL_ERR_NOT_EXISTS); return false; } if (!$Poll->isVotable()) { $this->m_error = new PEAR_Error('Poll is not votable.', ACTION_POLL_ERR_NOT_VOTABLE); return false; } else { switch($p_input['f_poll_mode']) { case 'ajax': $allowed_values = $_SESSION['camp_poll_maxvote'][$this->m_properties['poll_nr']][$this->m_properties['poll_language_id']]; if (!is_array($allowed_values)) { $this->m_error = new PEAR_Error('Invalid poll voting value.', ACTION_POLL_ERR_INVALID_VALUE); return false; } foreach ($Poll->getAnswers() as $PollAnswer) { $nr = $PollAnswer->getNumber(); if (isset($p_input['f_pollanswer_'.$nr]) && !empty($p_input['f_pollanswer_'.$nr])) { // check if value is valid if (!array_key_exists($p_input['f_pollanswer_'.$nr], $allowed_values[$nr])) { $this->m_error = new PEAR_Error('Invalid poll voting value.', ACTION_POLL_ERR_INVALID_VALUE); return false; } $this->m_properties['pollanswer_nr'] = $nr; $this->m_properties['value'] = $p_input['f_pollanswer_'.$nr]; break; } } if (!$this->m_properties['value']) { $this->m_error = new PEAR_Error('No answer value was given.', ACTION_POLL_ERR_NOANSWER_VALUE); return false; } break; case 'standard': if (!isset($p_input['f_pollanswer_nr']) || empty($p_input['f_pollanswer_nr'])) { $this->m_error = new PEAR_Error('Invalid poll voting value.', ACTION_POLL_ERR_INVALID_VALUE); return false; } $this->m_properties['pollanswer_nr'] = $p_input['f_pollanswer_nr']; $this->m_properties['value'] = 1; break; } } $this->m_poll = $Poll; }
/** * Create a copy of an answer set. * * @param int $p_fk_poll_nr * @param int $p_parent_nr * @param array $p_answers * @return Article */ function CreateCopySet($p_poll_nr, $p_language_id, $p_parent_nr) { $ParentPoll = new Poll($p_language_id, $p_parent_nr); $parentAnswers = $ParentPoll->getAnswers(); foreach ($parentAnswers as $ParentPollAnswer) { $TargetPollAnswer = new PollAnswer($p_language_id, $p_poll_nr, $ParentPollAnswer->getNumber()); if ($TargetPollAnswer->exists()) { $parentPollAnswerAttachments = $ParentPollAnswer->getPollAnswerAttachments(); foreach ($parentPollAnswerAttachments as $ParentPollAnswerAttachment) { $TargetPollAnswerAttachment = new PollAnswerAttachment($p_poll_nr, $ParentPollAnswerAttachment->getProperty('fk_pollanswer_nr'), $ParentPollAnswerAttachment->getProperty('fk_attachment_id')); $TargetPollAnswerAttachment->create(); } } } }
</TD> </TR> <tr> <TD ALIGN="RIGHT" ><?php putGS("Title"); ?>:</TD> <TD> <INPUT TYPE="TEXT" NAME="f_title" SIZE="40" MAXLENGTH="255" class="input_text" alt="blank" emsg="<?php putGS('You must fill in the $1 field.', getGS('Title')); ?>" value="<?php echo htmlspecialchars($title); ?>"> </TD> </TR> <tr> <TD ALIGN="RIGHT" ><?php putGS("Question"); ?>:</TD> <TD> <TEXTAREA NAME="f_question" class="input_textarea" cols="28" alt="blank" emsg="<?php putGS('You must fill in the $1 field.', getGS('Question')); ?>"><?php echo htmlspecialchars($question); ?></TEXTAREA> </TD> </TR> <?php foreach ($poll->getAnswers() as $answer) { ?> <tr> <TD ALIGN="RIGHT" ><?php putGS("Answer $1", $answer->getNumber()); ?>:</TD> <TD> <INPUT TYPE="TEXT" NAME="f_answer[<?php p($answer->getNumber()); ?>]" SIZE="40" MAXLENGTH="255" class="input_text" alt="blank" emsg="<?php putGS('You must fill in the $1 field.', getGS('Answer $1', $answer->getNumber())); ?>" value="<?php p(htmlspecialchars($answer->getProperty('answer'))); ?>"> </TD> </TR> <?php } ?> </table> </td> </tr> <TR> <TD COLSPAN="2" align="center">