コード例 #1
0
ファイル: poll.php プロジェクト: erico-deh/ocPortal
 function setUp()
 {
     parent::setUp();
     require_code('ocf_polls_action');
     require_code('ocf_polls_action2');
     require_code('ocf_topics_action');
     require_code('ocf_topics_action2');
     require_code('ocf_topics');
     require_code('ocf_forums');
     $this->establish_admin_session();
     $this->topic_id = ocf_make_topic(db_get_first_id(), 'Test');
     $this->poll_id = ocf_make_poll($this->topic_id, $question = 'Who are you ?', $is_private = 0, $is_open = 0, $minimum_selections = 2, $maximum_selections = 4, $requires_reply = 0, $answers = array('a', 'b', 'c'), $check_permissions = true);
     // Test the forum was actually created
     $this->assertTrue('Who are you ?' == $GLOBALS['FORUM_DB']->query_value('f_polls', 'po_question ', array('id' => $this->poll_id)));
 }
コード例 #2
0
ファイル: wowbb.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_polls_and_votes($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'poll_questions');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['poll_id']))) {
             continue;
         }
         $topic_id = import_id_remap_get('topic', strval($row['topic_id']), true);
         if (is_null($topic_id)) {
             import_id_remap_put('poll', strval($row['poll_id']), -1);
             continue;
         }
         $is_open = $row['poll_ends'] < time();
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'poll_options WHERE poll_id=' . strval((int) $row['poll_id']) . ' ORDER BY poll_option_id');
         $answers = array();
         $answer_map = array();
         foreach ($rows2 as $answer) {
             $answer_map[$answer['poll_option_id']] = count($answers);
             $answers[] = $answer['option_text'];
         }
         $maximum = $row['multiple_choice'] == 1 ? count($answers) : 1;
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'vote_votes WHERE poll_id=' . $row['poll_id']);
         foreach ($rows2 as $row2) {
             $row2['user_id'] = import_id_remap_get('member', strval($row2['user_id']), true);
         }
         $id_new = ocf_make_poll($topic_id, $row['question'], 0, $is_open ? 1 : 0, 1, $maximum, 0, $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         // Effectively, a remapping from IPB vote number to ocP vote number
         foreach ($rows2 as $row2) {
             $member_id = $row2['user_id'];
             if (!is_null($member_id) && $member_id != 0) {
                 if ($row2['poll_option_id'] == 0) {
                     $answer = -1;
                 } else {
                     $answer = $answers[$answer_map[$row2['poll_option_id']]];
                 }
                 $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $member_id, 'pv_answer_id' => $answer));
             }
         }
         import_id_remap_put('poll', strval($row['poll_id']), $id_new);
     }
 }
コード例 #3
0
ファイル: vb3.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_polls_and_votes($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT *,p.pollid AS pollid FROM ' . $table_prefix . 'poll p LEFT JOIN ' . $table_prefix . 'thread t ON p.pollid=t.pollid');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['pollid']))) {
             continue;
         }
         $topic_id = import_id_remap_get('topic', strval($row['threadid']), true);
         if (is_null($topic_id)) {
             continue;
         }
         $is_open = $row['active'];
         $answers = explode('|||', $row['options']);
         $maximum = $row['multiple'] == 1 ? count($answers) : 1;
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'pollvote WHERE pollid=' . $row['pollid']);
         foreach ($rows2 as $i => $row2) {
             $rows2[$i]['userid'] = import_id_remap_get('member', strval($row2['userid']), true);
         }
         $id_new = ocf_make_poll($topic_id, $row['question'], 0, $is_open, 1, $maximum, 0, $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         // Effectively, a remapping from VB vote number to ocP vote number
         foreach ($rows2 as $row2) {
             $member_id = $row2['userid'];
             if (!is_null($member_id) && $member_id != 0) {
                 $answer = array_key_exists($row2['voteoption'] - 1, $answers) ? $answers[$row2['voteoption'] - 1] : -1;
                 $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $member_id, 'pv_answer_id' => $answer));
             }
         }
         import_id_remap_put('poll', strval($row['pollid']), $id_new);
     }
 }
コード例 #4
0
ファイル: smf2.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_polls_and_votes($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'polls');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['id_poll']))) {
             continue;
         }
         $poll_topic_id = $db->query('SELECT id_topic FROM ' . $table_prefix . 'topics WHERE id_poll=' . strval($row['id_poll']));
         if (!isset($poll_topic_id[0]['id_topic'])) {
             continue;
         }
         $poll_topic_id = $poll_topic_id[0]['id_topic'];
         $topic_id = import_id_remap_get('topic', strval($poll_topic_id), true);
         if (is_null($topic_id)) {
             import_id_remap_put('poll', strval($row['id_poll']), -1);
             continue;
         }
         $is_open = $row['expire_time'] == 0 || $row['expire_time'] > time() ? 1 : 0;
         $answers = array();
         $poll_choices = $db->query('SELECT * FROM ' . $table_prefix . 'poll_choices WHERE id_poll=' . strval($row['id_poll']));
         $answers_array = array();
         foreach ($poll_choices as $key => $value) {
             $answers_array[] = $value['label'];
         }
         $answer_map = array();
         $maximum = 0;
         foreach ($answers_array as $key => $answer) {
             $answer_map[$key] = $poll_choices[$key]['votes'];
             $answers[$key] = $answer;
             $maximum += $poll_choices[$key]['votes'];
         }
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'log_polls WHERE id_poll=' . strval($row['id_poll']));
         foreach ($rows2 as $row2) {
             $row2['id_member'] = import_id_remap_get('member', strval($row2['id_member']), true);
         }
         $id_new = ocf_make_poll($topic_id, $row['question'], 0, $is_open, 1, $maximum, 0, $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         foreach ($rows2 as $row2) {
             $member_id = $row2['id_member'];
             if (!is_null($member_id) && $member_id != 0) {
                 if (!isset($answers[strval($row2['id_choice'])])) {
                     continue;
                 }
                 // Safety
                 $answer = $answers[strval($row2['id_choice'])];
                 $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $member_id, 'pv_answer_id' => $answer));
             }
         }
         import_id_remap_put('poll', strval($row['id_poll']), $id_new);
     }
 }
コード例 #5
0
ファイル: ocp_merge.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_polls_and_votes($db, $table_prefix, $file_base)
 {
     if ($this->on_same_msn($file_base)) {
         return;
     }
     $rows = $db->query('SELECT p.*,t.id AS tid FROM ' . $table_prefix . 'f_polls p LEFT JOIN ' . $table_prefix . 'f_topics t ON p.id=t.t_poll_id');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['id']))) {
             continue;
         }
         $topic_id = import_id_remap_get('topic', strval($row['tid']), true);
         if (is_null($topic_id)) {
             continue;
         }
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'f_poll_votes WHERE pv_poll_id=' . strval($row['id']));
         foreach ($rows2 as $i => $row2) {
             $rows2[$i]['pv_member_id'] = import_id_remap_get('member', strval($row2['pv_member_id']), true);
         }
         $rows3 = $db->query('SELECT * FROM ' . $table_prefix . 'f_poll_answers WHERE pa_poll_id=' . strval($row['id']) . ' ORDER BY id');
         $answers = array();
         $id_ordinal_map = array();
         foreach ($rows3 as $i => $row3) {
             $answers[] = array($row3['pa_answer'], 0);
             $id_ordinal_map[$row3['id']] = $i;
         }
         $id_new = ocf_make_poll($topic_id, $row['po_question'], $row['po_is_private'], $row['po_is_open'], $row['po_minimum_selections'], $row['po_maximum_selections'], $row['po_requires_reply'], $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         // Effectively, a remapping from vote number ordinal to new vote number
         foreach ($rows2 as $row2) {
             $vote = $row2['pv_answer_id'];
             if (!array_key_exists($vote, $id_ordinal_map)) {
                 continue;
             }
             if (!array_key_exists($id_ordinal_map[$vote], $answers)) {
                 continue;
             }
             $answer = $answers[$id_ordinal_map[$vote]];
             if (is_null($row2['pv_member_id'])) {
                 continue;
             }
             $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $row2['pv_member_id'], 'pv_answer_id' => $answer));
         }
         import_id_remap_put('f_poll', strval($row['id']), $id_new);
     }
 }
コード例 #6
0
ファイル: topics.php プロジェクト: erico-deh/ocPortal
 /**
  * The actualiser to add a poll.
  *
  * @return tempcode		The UI
  */
 function _add_poll()
 {
     $topic_id = get_param_integer('id');
     require_code('ocf_polls_action');
     require_code('ocf_polls_action2');
     $_existing = post_param('existing', '');
     if ($_existing != '') {
         $existing = intval($_existing);
         $_poll_row = $GLOBALS['FORUM_DB']->query_select('f_topics t LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_polls p ON t.t_poll_id=p.id', array('t_forum_id', 'p.*'), array('p.id' => $existing), '', 1);
         if (!array_key_exists(0, $_poll_row)) {
             warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
         }
         $row = $_poll_row[0];
         $existing_forum_id = $row['t_forum_id'];
         if (!has_category_access(get_member(), 'forums', strval($existing_forum_id))) {
             access_denied('CATEGORY_ACCESS_LEVEL');
         }
         $answer_rows = $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('pa_answer'), array('pa_poll_id' => $existing), 'ORDER BY id');
         $answers = array();
         foreach ($answer_rows as $trow) {
             $answers[] = $trow['pa_answer'];
         }
         ocf_make_poll($topic_id, $row['po_question'], $row['po_is_private'], $row['po_is_open'], $row['po_minimum_selections'], $row['po_maximum_selections'], $row['po_requires_reply'], $answers);
         return $this->redirect_to('ADD_TOPIC_POLL', $topic_id);
     }
     $question = post_param('question');
     $is_private = post_param_integer('is_private', 0);
     $is_open = post_param_integer('is_open', 0);
     $minimum_selections = post_param_integer('minimum_selections', 0);
     $maximum_selections = post_param_integer('maximum_selections', 0);
     $requires_reply = post_param_integer('requires_reply', 0);
     $answers = array();
     foreach ($_POST as $key => $val) {
         if (!is_string($val)) {
             continue;
         }
         if (substr($key, 0, 7) == 'answer_') {
             if (get_magic_quotes_gpc()) {
                 $val = stripslashes($val);
             }
             if ($val != '') {
                 $answers[] = array($val, 0);
             }
         }
     }
     ocf_make_poll($topic_id, $question, $is_private, $is_open, $minimum_selections, $maximum_selections, $requires_reply, $answers);
     if (get_param_integer('try_validate', 0) == 1) {
         $forum_id = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_forum_id', array('id' => $topic_id));
         if (!is_null($forum_id) && !has_specific_permission(get_member(), 'bypass_validation_midrange_content', 'topics', array('forums', $forum_id))) {
             $validated = 0;
         } else {
             $validated = 1;
         }
         if ($validated == 1) {
             $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_validated' => 1), array('id' => $topic_id), '', 1);
         }
     }
     return $this->redirect_to('ADD_TOPIC_POLL', $topic_id);
 }
コード例 #7
0
ファイル: phpbb2.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_polls_and_votes($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'vote_desc');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['vote_id']))) {
             continue;
         }
         $topic_id = import_id_remap_get('topic', strval($row['topic_id']), true);
         if (is_null($topic_id)) {
             import_id_remap_put('poll', strval($row['vote_id']), -1);
             continue;
         }
         $is_open = $row['vote_start'] > time() && ($row['vote_length'] == 0 || $row['vote_start'] + $row['vote_length'] < time());
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'vote_results WHERE vote_id=' . strval($row['vote_id'] . ' ORDER BY vote_option_id'));
         $answers = array();
         foreach ($rows2 as $answer) {
             $answers[] = $answer['vote_option_text'];
         }
         $maximum = 1;
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'vote_voters WHERE vote_id=' . $row['vote_id']);
         foreach ($rows2 as $row2) {
             $row2['vote_user_id'] = import_id_remap_get('member', strval($row2['vote_user_id']), true);
         }
         $id_new = ocf_make_poll($topic_id, $row['vote_text'], 0, $is_open ? 1 : 0, 1, $maximum, 0, $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         // Effectively, a remapping from IPB vote number to ocP vote number
         foreach ($rows2 as $row2) {
             $member_id = $row2['vote_user_id'];
             if (!is_null($member_id) && $member_id != 0) {
                 if ($row2['vote_cast'] == 0 || !array_key_exists($row2['vote_cast'] - 1, $answers)) {
                     $answer = -1;
                 } else {
                     $answer = $answers[$row2['vote_cast'] - 1];
                 }
                 $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $member_id, 'pv_answer_id' => $answer));
             }
         }
         import_id_remap_put('poll', strval($row['vote_id']), $id_new);
     }
 }
コード例 #8
0
ファイル: ipb.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_polls_and_votes($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'polls');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['pid']))) {
             continue;
         }
         $topic_id = import_id_remap_get('topic', strval($row['tid']), true);
         if (is_null($topic_id)) {
             continue;
         }
         $topic = $db->query('SELECT * FROM ' . $table_prefix . 'topics WHERE tid=' . strval($row['tid']));
         $is_open = $topic[0]['poll_state'] == 'open' ? 1 : 0;
         $_answers = unserialize($row['choices']);
         $answers = array();
         // An array of answers
         foreach ($_answers as $answer) {
             $answers[] = array(@html_entity_decode($answer[1], ENT_QUOTES, get_charset()), $answer[2]);
         }
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'voters WHERE tid=' . strval($row['tid']));
         $id_new = ocf_make_poll($topic_id, @html_entity_decode($row['poll_question'], ENT_QUOTES, get_charset()), 0, $is_open, 1, 1, 0, $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         // Effectively, a remapping from IPB vote number to ocP vote number
         $vote_list = array();
         $j = 0;
         foreach ($_answers as $answer) {
             for ($i = 0; $i < intval($answer[2]); $i++) {
                 array_push($vote_list, $answers[$j]);
                 // Push the mapped ocPortal vote id onto the list of votes
             }
             $j++;
         }
         foreach ($rows2 as $row2) {
             $member_id = import_id_remap_get('member', $row2['member_id'], true);
             if (is_null($member_id)) {
                 $member_id = db_get_first_id();
             }
             if ($member_id != $GLOBALS['OCF_DRIVER']->get_guest_id()) {
                 $answer = array_pop($vote_list);
                 if (is_null($answer)) {
                     $answer = -1;
                 }
                 $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $member_id, 'pv_answer_id' => $answer));
             }
         }
         import_id_remap_put('poll', strval($row['pid']), $id_new);
     }
 }
コード例 #9
0
ファイル: mybb.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_polls_and_votes($db, $table_prefix, $file_base)
 {
     $rows = $db->query_select('polls');
     foreach ($rows as $row) {
         if (import_check_if_imported('poll', strval($row['pid']))) {
             continue;
         }
         $topic_id = import_id_remap_get('topic', strval($row['tid']), true);
         if (is_null($topic_id)) {
             import_id_remap_put('poll', strval($row['pid']), -1);
             continue;
         }
         $is_open = 1 - $row['closed'];
         $answers = array();
         $answers_array = explode('||~|~||', $row['options']);
         $answer_map = array();
         foreach ($answers_array as $key => $answer) {
             $answer_map[$key + 1] = count($answers);
             $answers[] = $answer;
         }
         $maximum = count($answers);
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'pollvotes WHERE pid=' . strval($row['pid']));
         foreach ($rows2 as $row2) {
             $row2['uid'] = import_id_remap_get('member', strval($row2['uid']), true);
         }
         $id_new = ocf_make_poll($topic_id, $row['question'], 0, $is_open, 1, $maximum, 0, $answers, false);
         $answers = collapse_1d_complexity('id', $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $id_new)));
         foreach ($rows2 as $row2) {
             $member_id = $row2['uid'];
             if (!is_null($member_id) && $member_id != 0) {
                 if ($row2['voteoption'] == 0) {
                     $answer = -1;
                 } else {
                     $answer = $answers[$answer_map[$row2['voteoption']]];
                 }
                 $GLOBALS['FORUM_DB']->query_insert('f_poll_votes', array('pv_poll_id' => $id_new, 'pv_member_id' => $member_id, 'pv_answer_id' => $answer));
             }
         }
         import_id_remap_put('poll', strval($row['pid']), $id_new);
     }
 }