camp_html_display_error(getGS('You do not have the right to manage polls.')); exit; } $f_poll_nr = Input::Get('f_poll_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); $f_title = Input::Get('f_title', 'string'); $f_question = Input::Get('f_question', 'string'); $f_date_begin = Input::Get('f_date_begin', 'string'); $f_date_end = Input::Get('f_date_end', 'string'); $f_votes_per_user = Input::Get('f_votes_per_user', 'int'); $f_is_extended = Input::Get('f_is_extended', 'boolean'); $f_nr_of_answers = Input::Get('f_nr_of_answers', 'int'); $f_answers = Input::Get('f_answer', 'array'); $f_onhitlist = Input::Get('f_onhitlist', 'array'); $poll = new Poll($f_fk_language_id, $f_poll_nr); if ($poll->exists()) { // update existing poll $poll = new Poll($f_fk_language_id, $f_poll_nr); $poll->setProperty('title', $f_title); $poll->setProperty('question', $f_question); $poll->setProperty('date_begin', $f_date_begin); $poll->setProperty('date_end', $f_date_end); $poll->setProperty('votes_per_user', $f_votes_per_user); $poll->setProperty('nr_of_answers', $f_nr_of_answers); $poll->setProperty('is_extended', $f_is_extended); foreach ($f_answers as $nr_answer => $text) { if ($text !== '__undefined__') { $answer = new PollAnswer($f_fk_language_id, $f_poll_nr, $nr_answer); if ($answer->exists()) { $answer->setProperty('answer', $text); } else {
// Check permissions if (!$g_user->hasPermission('plugin_poll')) { camp_html_display_error(getGS('You do not have the right to manage polls.')); exit; } $allLanguages = Language::GetLanguages(); $f_poll_nr = Input::Get('f_poll_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); $f_from = Input::Get('f_from', 'string', false); $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');
/** * Gets an issue list based on the given parameters. * * @param array $p_parameters * An array of ComparisonOperation objects * @param string item * An indentifier which assignment should be used (publication/issue/section/article) * @param string $p_order * An array of columns and directions to order by * @param integer $p_start * The record number to start the list * @param integer $p_limit * The offset. How many records from $p_start will be retrieved. * * @return array $issuesList * An array of Issue objects */ public static function GetList(array $p_parameters, $p_item = null, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count) { global $g_ado_db; if (!is_array($p_parameters)) { return null; } // adodb::selectLimit() interpretes -1 as unlimited if ($p_limit == 0) { $p_limit = -1; } $selectClauseObj = new SQLSelectClause(); // sets the where conditions foreach ($p_parameters as $param) { $comparisonOperation = self::ProcessListParameters($param); if (empty($comparisonOperation)) { continue; } if (strpos($comparisonOperation['left'], '_assign_publication_id') !== false) { $assign_publication_id = $comparisonOperation['right']; } elseif (strpos($comparisonOperation['left'], '_assign_issue_nr') !== false) { $assign_issue_nr = $comparisonOperation['right']; } elseif (strpos($comparisonOperation['left'], '_assign_section_nr') !== false) { $assign_section_nr = $comparisonOperation['right']; } elseif (strpos($comparisonOperation['left'], '_assign_article_nr') !== false) { $assign_article_nr = $comparisonOperation['right']; } elseif (strpos($comparisonOperation['left'], '_current') !== false) { $whereCondition = "date_begin <= NOW()"; $selectClauseObj->addWhere($whereCondition); $whereCondition = "date_end >= NOW()"; $selectClauseObj->addWhere($whereCondition); } elseif (strpos($comparisonOperation['left'], 'language_id') !== false) { $language_id = $comparisonOperation['right']; $whereCondition = $g_ado_db->escapeOperation($comparisonOperation); $selectClauseObj->addWhere($whereCondition); } else { $whereCondition = $g_ado_db->escapeOperation($comparisonOperation); $selectClauseObj->addWhere($whereCondition); } } // sets the columns to be fetched $tmpPoll = new Poll(); $columnNames = $tmpPoll->getColumnNames(true); foreach ($columnNames as $columnName) { $selectClauseObj->addColumn($columnName); } // sets the main table for the query $mainTblName = $tmpPoll->getDbTableName(); $selectClauseObj->setTable($mainTblName); unset($tmpPoll); switch ($p_item) { case 'publication': if (empty($assign_publication_id)) { return; } $tmpAssignObj = new PollPublication(); $assignTblName = $tmpAssignObj->getDbTableName(); $join = "LEFT JOIN `{$assignTblName}` AS j\n ON\n j.fk_poll_nr = `{$mainTblName}`.poll_nr\n AND j.fk_publication_id = '{$assign_publication_id}'"; $selectClauseObj->addJoin($join); $selectClauseObj->addWhere('j.fk_poll_nr IS NOT NULL'); $selectClauseObj->setDistinct('plugin_poll.poll_nr'); break; case 'issue': if (empty($assign_publication_id) || empty($assign_issue_nr)) { return; } $tmpAssignObj = new PollIssue(); $assignTblName = $tmpAssignObj->getDbTableName(); $join = "LEFT JOIN {$assignTblName} AS j\n ON\n j.fk_poll_nr = `{$mainTblName}`.poll_nr\n AND j.fk_issue_nr = '{$assign_issue_nr}'\n AND j.fk_publication_id = '{$assign_publication_id}'"; if (isset($language_id)) { $join .= " AND j.fk_issue_language_id = '{$language_id}'"; } $selectClauseObj->addJoin($join); $selectClauseObj->addWhere('j.fk_poll_nr IS NOT NULL'); $selectClauseObj->setDistinct('plugin_poll.poll_nr'); break; case 'section': if (empty($assign_publication_id) || empty($assign_issue_nr) || empty($assign_section_nr)) { return; } $tmpAssignObj = new PollSection(); $assignTblName = $tmpAssignObj->getDbTableName(); $join = "LEFT JOIN `{$assignTblName}` AS j\n ON\n j.fk_poll_nr = `{$mainTblName}`.poll_nr\n AND j.fk_section_nr = '{$assign_section_nr}'\n AND j.fk_issue_nr = '{$assign_issue_nr}'\n AND j.fk_publication_id = '{$assign_publication_id}'"; if (isset($language_id)) { $join .= " AND j.fk_section_language_id = '{$language_id}'"; } $selectClauseObj->addJoin($join); $selectClauseObj->addWhere('j.fk_poll_nr IS NOT NULL'); $selectClauseObj->setDistinct('plugin_poll.poll_nr'); break; case 'article': if (empty($assign_article_nr)) { return; } $tmpAssignObj = new PollArticle(); $assignTblName = $tmpAssignObj->getDbTableName(); $join = "LEFT JOIN `{$assignTblName}` AS j\n ON\n j.fk_poll_nr = `{$mainTblName}`.poll_nr\n AND j.fk_article_nr = '{$assign_article_nr}'"; if (isset($language_id)) { $join .= " AND j.fk_article_language_id = '{$language_id}'"; } $selectClauseObj->addJoin($join); $selectClauseObj->addWhere('j.fk_poll_nr IS NOT NULL'); $selectClauseObj->setDistinct('plugin_poll.poll_nr'); break; } if (is_array($p_order)) { $order = Poll::ProcessListOrder($p_order); // sets the order condition if any foreach ($order as $orderField => $orderDirection) { $selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection); } } $sqlQuery = $selectClauseObj->buildQuery(); // count all available results $countRes = $g_ado_db->Execute($sqlQuery); $p_count = $countRes->recordCount(); //get the wanted rows $pollRes = $g_ado_db->SelectLimit($sqlQuery, $p_limit, $p_start); // builds the array of poll objects $pollsList = array(); while ($poll = $pollRes->FetchRow()) { $pollObj = new Poll($poll['fk_language_id'], $poll['poll_nr']); if ($pollObj->exists()) { $pollsList[] = $pollObj; } } return $pollsList; }
/** * 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; }
camp_load_translation_strings("plugin_poll"); // Check permissions if (!$g_user->hasPermission('plugin_poll')) { camp_html_display_error(getGS('You do not have the right to manage polls.')); exit; } $allLanguages = Language::GetLanguages(); $f_poll_nr = Input::Get('f_poll_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); $f_from = Input::Get('f_from', 'string', false); if (empty($f_from)) { $f_from = $Campsite['WEBSITE_URL'] . '/admin/poll/index.php'; } $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 {
camp_load_translation_strings("plugin_poll"); // Check permissions if (!$g_user->hasPermission('plugin_poll')) { camp_html_display_error(getGS('You do not have the right to manage polls.')); exit; } $allLanguages = Language::GetLanguages(); $f_poll_nr = Input::Get('f_poll_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); $poll = new Poll($f_fk_language_id, $f_poll_nr); if (!$poll->exists()) { camp_html_display_error(getGS('Poll does not exists.')); exit; } $title = $poll->getProperty('title'); $question = $poll->getProperty('question'); $date_begin = $poll->getProperty('date_begin'); $date_end = $poll->getProperty('date_end'); $fk_language_id = $poll->getProperty('fk_language_id'); $votes_per_user = $poll->getProperty('votes_per_user'); /* $topArray = array('Pub' => $publicationObj, 'Issue' => $issueObj, 'Section' => $sectionObj); camp_html_content_top(getGS('Add new article'), $topArray, true, false, array(getGS("Articles") => "/$ADMIN/articles/?f_publication_id=$f_publication_id&f_issue_number=$f_issue_number&f_section_number=$f_section_number&f_language_id=$f_language_id"));