-
Notifications
You must be signed in to change notification settings - Fork 16
/
ocf_polls_action.php
executable file
·80 lines (64 loc) · 2.61 KB
/
ocf_polls_action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php /*
ocPortal
Copyright (c) ocProducts, 2004-2013
See text/EN/licence.txt for full licencing information.
NOTE TO PROGRAMMERS:
Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
**** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****
*/
/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright ocProducts Ltd
* @package core_ocf
*/
/**
* Add a forum poll.
*
* @param AUTO_LINK The ID of the topic to add the poll to.
* @param SHORT_TEXT The question.
* @param BINARY Whether the result tallies are kept private until the poll is made non-private.
* @param BINARY Whether the poll is open for voting.
* @param integer The minimum number of selections that may be made.
* @param integer The maximum number of selections that may be made.
* @param BINARY Whether members must have a post in the topic before they made vote.
* @param array A list of pairs of the potential voteable answers and the number of votes.
* @param boolean Whether to check there are permissions to make the poll.
* @return AUTO_LINK The ID of the newly created forum poll.
*/
function ocf_make_poll($topic_id,$question,$is_private,$is_open,$minimum_selections,$maximum_selections,$requires_reply,$answers,$check_permissions=true)
{
require_code('ocf_polls');
if (($check_permissions) && (!ocf_may_attach_poll($topic_id)))
access_denied('I_ERROR');
$poll_id=$GLOBALS['FORUM_DB']->query_insert('f_polls',array(
'po_question'=>$question,
'po_cache_total_votes'=>0,
'po_is_private'=>$is_private,
'po_is_open'=>$is_open,
'po_minimum_selections'=>$minimum_selections,
'po_maximum_selections'=>$maximum_selections,
'po_requires_reply'=>$requires_reply
),true);
foreach ($answers as $answer)
{
if (is_array($answer))
{
list($answer,$num_votes)=$answer;
} else $num_votes=0;
$GLOBALS['FORUM_DB']->query_insert('f_poll_answers',array(
'pa_poll_id'=>$poll_id,
'pa_answer'=>$answer,
'pa_cache_num_votes'=>$num_votes
));
}
$map=array('t_poll_id'=>$poll_id);
// Now make the topic validated if this is attaching immediately
if (get_param_integer('re_validate',0)==1)
{
$forum_id=$GLOBALS['FORUM_DB']->query_select_value('f_topics','t_forum_id',array('id'=>$topic_id));
if ((is_null($forum_id)) || (has_privilege(get_member(),'bypass_validation_midrange_content','topics',array('forums',$forum_id))))
$map['t_validated']=1;
}
$GLOBALS['FORUM_DB']->query_update('f_topics',$map,array('id'=>$topic_id),'',1);
return $poll_id;
}