ocPortal Developer's Guide: Polls
» Return to Contents
sources/polls.php
Global_functions_polls.php
Function summary
|
?object
|
poll_script (boolean ret, ?AUTO_LINK param)
|
|
boolean
|
may_vote_in_poll (array myrow)
|
|
tempcode
|
show_poll (boolean results, array myrow, ID_TEXT zone)
|
|
AUTO_LINK
|
add_poll (SHORT_TEXT question, SHORT_TEXT a1, SHORT_TEXT a2, SHORT_TEXT a3, SHORT_TEXT a4, SHORT_TEXT a5, SHORT_TEXT a6, SHORT_TEXT a7, SHORT_TEXT a8, SHORT_TEXT a9, SHORT_TEXT a10, integer num_options, BINARY current, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, ?TIME time, ?MEMBER submitter, ?TIME use_time, integer v1, integer v2, integer v3, integer v4, integer v5, integer v6, integer v7, integer v8, integer v9, integer v10, integer views, ?TIME edit_date)
|
|
void
|
edit_poll (AUTO_LINK id, SHORT_TEXT question, SHORT_TEXT a1, SHORT_TEXT a2, SHORT_TEXT a3, SHORT_TEXT a4, SHORT_TEXT a5, SHORT_TEXT a6, SHORT_TEXT a7, SHORT_TEXT a8, SHORT_TEXT a9, SHORT_TEXT a10, integer num_options, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes)
|
|
void
|
delete_poll (AUTO_LINK id)
|
|
void
|
set_poll (AUTO_LINK id)
|
|
tempcode
|
nice_get_polls (?AUTO_LINK it, ?MEMBER only_owned)
|
?object poll_script(boolean ret, ?AUTO_LINK param)
Show poll block.
Parameters…
| Name |
ret |
| Description |
Whether to get the output instead of outputting it directly |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
param |
| Description |
Poll ID (NULL: read from environment) |
| Default value |
|
| Type |
?AUTO_LINK |
Returns…
| Description |
Output (NULL: outputted it already) |
| Type |
?object |
function poll_script($ret=false,$param=NULL)
{
require_lang('polls');
require_css('polls');
if (is_null($param)) $param=get_param_integer('param');
$zone=get_param('zone',get_module_zone('polls'));
if ($param==-1)
{
$rows=persistant_cache_get('POLL');
if (is_null($rows))
{
$rows=$GLOBALS['SITE_DB']->query_select('poll',array('*'),array('is_current'=>1),'ORDER BY id DESC',1);
persistant_cache_set('POLL',$rows);
}
} else
{
$rows=$GLOBALS['SITE_DB']->query_select('poll',array('*'),array('id'=>$param),'',1);
}
if ((has_actual_page_access(NULL,'cms_polls',NULL,NULL)) && (has_submit_permission('mid',get_member(),get_ip_address(),'cms_polls')))
{
$submit_url=build_url(array('page'=>'cms_polls','type'=>'ad','redirect'=>get_self_url(true,false)),get_module_zone('cms_polls'));
} else $submit_url=new ocp_tempcode();
if (!array_key_exists(0,$rows))
{
$content=do_template('BLOCK_NO_ENTRIES',array('_GUID'=>'fdc85bb2e14bdf00830347e52f25cdac','HIGH'=>true,'TITLE'=>do_lang_tempcode('POLL'),'MESSAGE'=>do_lang_tempcode('NO_ENTRIES'),'ADD_NAME'=>do_lang_tempcode('ADD_POLL'),'SUBMIT_URL'=>$submit_url));
} else
{
$myrow=$rows[0];
$ip=get_ip_address();
// Show the poll normally
$show_poll_results=get_param_integer('show_poll_results_'.strval($myrow['id']),0);
if ($show_poll_results==0)
{
$content=show_poll(false,$myrow,$zone);
} else
{
// Voting
$cast=post_param_integer('cast_'.strval($myrow['id']),-1);
if ($cast!=-1)
{
if (may_vote_in_poll($myrow))
{
if (addon_installed('points'))
{
require_code('points');
$_before=point_info(get_member());
$before=array_key_exists('points_gained_voting',$_before)?$_before['points_gained_voting']:0;
$GLOBALS['FORUM_DRIVER']->set_custom_field(get_member(),'points_gained_voting',$before+1);
}
$GLOBALS['SITE_DB']->query_update('poll',array(('votes'.strval($cast))=>($myrow['votes'.strval($cast)]+1)),array('id'=>$myrow['id']),'',1);
$GLOBALS['SITE_DB']->query_insert('poll_votes',array(
'v_poll_id'=>$myrow['id'],
'v_voter_id'=>get_member(),
'v_voter_ip'=>$ip,
'v_vote_for'=>$cast,
));
$myrow['votes'.strval($cast)]++;
}
} else
{
// Viewing the results
if (may_vote_in_poll($myrow)) // If they do this, they nullify their vote
{
$GLOBALS['SITE_DB']->query_insert('poll_votes',array(
'v_poll_id'=>$myrow['id'],
'v_voter_id'=>is_guest()?NULL:get_member(),
'v_voter_ip'=>$ip,
'v_vote_for'=>NULL,
));
}
}
// Show poll, with results
$content=show_poll(true,$myrow,$zone);
}
}
if ($ret) return $content;
// Display
$echo=do_template('STYLED_HTML_WRAP',array('TITLE'=>do_lang_tempcode('POLL'),'FRAME'=>true,'CONTENT'=>$content));
$echo->handle_symbol_preprocessing();
$echo->evaluate_echo();
return NULL;
}
boolean may_vote_in_poll(array myrow)
Find whether the current member may vote.
Parameters…
| Name |
myrow |
| Description |
The poll row |
| Type |
array |
Returns…
| Description |
Whether the current member may vote |
| Type |
boolean |
function may_vote_in_poll($myrow)
{
if (!has_specific_permission(get_member(),'vote_in_polls','cms_polls')) return false;
if (get_value('poll_no_member_ip_restrict')==='1')
{
if (is_guest())
{
return is_null($GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT id FROM '.get_table_prefix().'poll_votes WHERE v_poll_id='.strval($myrow['id']).' AND '.db_string_equal_to('v_voter_ip',get_ip_address())));
} else
{
return is_null($GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT id FROM '.get_table_prefix().'poll_votes WHERE v_poll_id='.strval($myrow['id']).' AND v_voter_id='.strval(get_member())));
}
}
return is_null($GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT id FROM '.get_table_prefix().'poll_votes WHERE v_poll_id='.strval($myrow['id']).' AND (v_voter_id='.strval(get_member()).' OR '.db_string_equal_to('v_voter_ip',get_ip_address()).')'));
}
tempcode show_poll(boolean results, array myrow, ID_TEXT zone)
Show an actual poll block.
Parameters…
| Name |
results |
| Description |
Whether to show results (if we've already voted, this'll be overrided) |
| Type |
boolean |
| Name |
myrow |
| Description |
The poll row |
| Type |
array |
| Name |
zone |
| Description |
The zone our poll module is in |
| Type |
ID_TEXT |
Returns…
| Description |
The block |
| Type |
tempcode |
function show_poll($results,$myrow,$zone)
{
$ip=get_ip_address();
if (!may_vote_in_poll($myrow)) $results=true;
// Count our total votes
$num_options=$myrow['num_options'];
$totalvotes=0;
for ($i=1;$i<=$num_options;$i++)
{
if (!array_key_exists('votes'.strval($i),$myrow)) $myrow['votes'.strval($i)]=0;
$totalvotes+=$myrow['votes'.strval($i)];
}
// Sort by results
$orderings=array();
for ($i=1;$i<=$num_options;$i++)
{
$orderings[$i]=$myrow['votes'.strval($i)];
}
if ($results) asort($orderings);
if (running_script('poll'))
{
$keep=symbol_tempcode('KEEP');
$vote_url=find_script('poll').'?poll_id='.strval($myrow['id']).'&show_poll_results_'.strval($myrow['id']).'=1¶m='.urlencode(strval($myrow['id'])).'&zone='.urlencode(get_param('zone',get_module_zone('polls'))).$keep->evaluate();
if (get_param_integer('in_panel',0)==1) $vote_url.='&in_panel=1';
if (get_param_integer('interlock',0)==1) $vote_url.='&interlock=1';
$result_url=$results?'':$vote_url;
} else
{
$poll_results='show_poll_results_'.strval($myrow['id']);
$vote_url=get_self_url(false,true,array('poll_id'=>$myrow['id'],$poll_results=>1,'utheme'=>NULL));
$result_url=$results?'':get_self_url(false,true,array($poll_results=>1,'utheme'=>NULL));
}
if (get_param('utheme','')!='')
{
if (is_object($result_url))
{
if (!$result_url->is_empty()) $result_url->attach('&utheme='.get_param('utheme'));
} else
{
if ($result_url!='') $result_url.='&utheme='.get_param('utheme');
}
if (is_object($vote_url))
{
if (!$vote_url->is_empty()) $vote_url->attach('&utheme='.get_param('utheme'));
} else
{
if ($vote_url!='') $vote_url.='&utheme='.get_param('utheme');
}
}
// Our questions templated
$tpl=new ocp_tempcode();
for ($i=1;$i<=$num_options;$i++)
{
$answer=get_translated_tempcode($myrow['option'.strval($i)]);
$answer_plain=get_translated_text($myrow['option'.strval($i)]);
if (!$results)
{
$tpl->attach(do_template('POLL_ANSWER',array('_GUID'=>'bc9c2e818f2e7031075d8d7b01d79cd5','PID'=>strval($myrow['id']),'I'=>strval($i),'CAST'=>strval($i),'VOTE_URL'=>$vote_url,'ANSWER'=>$answer,'ANSWER_PLAIN'=>$answer_plain)));
} else
{
$votes=$myrow['votes'.strval($i)];
if (!is_numeric($votes)) $votes=0;
if ($totalvotes!=0) $width=intval(round(70.0*floatval($votes)/floatval($totalvotes))); else $width=0;
$tpl->attach(do_template('POLL_ANSWER_RESULT',array('_GUID'=>'887ea0ed090c48305eb84500865e5178','PID'=>strval($myrow['id']),'I'=>strval($i),'VOTE_URL'=>$vote_url,'ANSWER'=>$answer,'ANSWER_PLAIN'=>$answer_plain,'WIDTH'=>strval($width),'VOTES'=>integer_format($votes))));
}
}
if ((has_actual_page_access(NULL,'cms_polls',NULL,NULL)) && (has_submit_permission('mid',get_member(),get_ip_address(),'cms_polls')))
{
$submit_url=build_url(array('page'=>'cms_polls','type'=>'ad','redirect'=>running_script('index')?get_self_url(true,true,array()):NULL),get_module_zone('cms_polls'));
} else $submit_url=new ocp_tempcode();
// Do our final template
$question=get_translated_tempcode($myrow['question']);
$question_plain=get_translated_text($myrow['question']);
$archive_url=build_url(array('page'=>'polls','type'=>'misc'),$zone);
$full_url=new ocp_tempcode();
if ((get_page_name()!='polls') || (get_param('type','')!='view'))
$full_url=build_url(array('page'=>'polls','type'=>'view','id'=>$myrow['id']),$zone);
$map2=array('_GUID'=>'4c6b026f7ed96f0b5b8408eb5e5affb5','VOTE_URL'=>$vote_url,'SUBMITTER'=>strval($myrow['submitter']),'PID'=>strval($myrow['id']),'FULL_URL'=>$full_url,'CONTENT'=>$tpl,'QUESTION'=>$question,'QUESTION_PLAIN'=>$question_plain,'SUBMIT_URL'=>$submit_url,'ARCHIVE_URL'=>$archive_url,'RESULT_URL'=>$result_url,'ZONE'=>$zone);
if ((get_option('is_on_comments')=='1') && (!has_no_forum()) && ($myrow['allow_comments']>=1)) $map2['COMMENT_COUNT']='1';
return do_template('POLL',$map2);
}
AUTO_LINK add_poll(SHORT_TEXT question, SHORT_TEXT a1, SHORT_TEXT a2, SHORT_TEXT a3, SHORT_TEXT a4, SHORT_TEXT a5, SHORT_TEXT a6, SHORT_TEXT a7, SHORT_TEXT a8, SHORT_TEXT a9, SHORT_TEXT a10, integer num_options, BINARY current, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, ?TIME time, ?MEMBER submitter, ?TIME use_time, integer v1, integer v2, integer v3, integer v4, integer v5, integer v6, integer v7, integer v8, integer v9, integer v10, integer views, ?TIME edit_date)
Add a new poll to the database, then return the ID of the new entry.
Parameters…
| Name |
question |
| Description |
The question |
| Type |
SHORT_TEXT |
| Name |
a1 |
| Description |
The first choice |
| Type |
SHORT_TEXT |
| Value range |
1 max |
| Name |
a2 |
| Description |
The second choice |
| Type |
SHORT_TEXT |
| Value range |
1 max |
| Name |
a3 |
| Description |
The third choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a4 |
| Description |
The fourth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a5 |
| Description |
The fifth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a6 |
| Description |
The sixth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a7 |
| Description |
The seventh choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a8 |
| Description |
The eighth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a9 |
| Description |
The ninth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a10 |
| Description |
The tenth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
num_options |
| Description |
The number of choices |
| Type |
integer |
| Value range |
2 5 |
| Name |
current |
| Description |
Whether the poll is the current poll |
| Type |
BINARY |
| Name |
allow_rating |
| Description |
Whether to allow rating of this poll |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether comments are allowed (0=no, 1=yes, 2=review style) |
| Type |
SHORT_INTEGER |
| Name |
allow_trackbacks |
| Description |
Whether to allow trackbacking on this poll |
| Type |
BINARY |
| Name |
notes |
| Description |
Notes about this poll |
| Type |
LONG_TEXT |
| Name |
time |
| Description |
The time the poll was submitted (NULL: now) |
| Default value |
|
| Type |
?TIME |
| Name |
submitter |
| Description |
The member who submitted (NULL: the current member) |
| Default value |
|
| Type |
?MEMBER |
| Name |
use_time |
| Description |
The time the poll was put to use (NULL: not put to use yet) |
| Default value |
|
| Type |
?TIME |
| Name |
v1 |
| Description |
How many have voted for option 1 |
| Default value |
0 |
| Type |
integer |
| Value range |
0 max |
| Name |
v2 |
| Description |
How many have voted for option 2 |
| Default value |
0 |
| Type |
integer |
| Value range |
0 max |
| Name |
v3 |
| Description |
How many have voted for option 3 |
| Default value |
0 |
| Type |
integer |
| Value range |
0 max |
| Name |
v4 |
| Description |
How many have voted for option 4 |
| Default value |
0 |
| Type |
integer |
| Value range |
0 max |
| Name |
v5 |
| Description |
How many have voted for option 5 |
| Default value |
0 |
| Type |
integer |
| Value range |
0 max |
| Name |
v6 |
| Description |
How many have voted for option 6 |
| Default value |
0 |
| Type |
integer |
| Value range |
0 max |
| Name |
v7 |
| Description |
How many have voted for option 7 |
| Default value |
0 |
| Type |
integer |
| Value range |
0 max |
| Name |
v8 |
| Description |
How many have voted for option 8 |
| Default value |
0 |
| Type |
integer |
| Value range |
0 max |
| Name |
v9 |
| Description |
How many have voted for option 9 |
| Default value |
0 |
| Type |
integer |
| Value range |
0 max |
| Name |
v10 |
| Description |
How many have voted for option 10 |
| Default value |
0 |
| Type |
integer |
| Value range |
0 max |
| Name |
views |
| Description |
The number of views had |
| Default value |
0 |
| Type |
integer |
| Name |
edit_date |
| Description |
The edit date (NULL: never) |
| Default value |
|
| Type |
?TIME |
Returns…
| Description |
The poll ID of our new poll |
| Type |
AUTO_LINK |
function add_poll($question,$a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,$a10,$num_options,$current,$allow_rating,$allow_comments,$allow_trackbacks,$notes,$time=NULL,$submitter=NULL,$use_time=NULL,$v1=0,$v2=0,$v3=0,$v4=0,$v5=0,$v6=0,$v7=0,$v8=0,$v9=0,$v10=0,$views=0,$edit_date=NULL)
{
if ($current==1)
{
persistant_cache_delete('POLL');
$GLOBALS['SITE_DB']->query_update('poll',array('is_current'=>0),array('is_current'=>1),'',1);
}
if (is_null($time)) $time=time();
if (is_null($submitter)) $submitter=get_member();
$id=$GLOBALS['SITE_DB']->query_insert('poll',array('edit_date'=>$edit_date,'poll_views'=>$views,'add_time'=>$time,'allow_trackbacks'=>$allow_trackbacks,'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'notes'=>$notes,'submitter'=>$submitter,'date_and_time'=>$use_time,'votes1'=>$v1,'votes2'=>$v2,'votes3'=>$v3,'votes4'=>$v4,'votes5'=>$v5,'votes6'=>$v6,'votes7'=>$v7,'votes8'=>$v8,'votes9'=>$v9,'votes10'=>$v10,'question'=>insert_lang_comcode($question,1),'option1'=>insert_lang_comcode($a1,1),'option2'=>insert_lang_comcode($a2,1),'option3'=>insert_lang_comcode($a3,1),'option4'=>insert_lang_comcode($a4,1),'option5'=>insert_lang_comcode($a5,1),'option6'=>insert_lang_comcode($a6,1),'option7'=>insert_lang_comcode($a7,1),'option8'=>insert_lang_comcode($a8,1),'option9'=>insert_lang_comcode($a9,1),'option10'=>insert_lang_comcode($a10,1),'num_options'=>$num_options,'is_current'=>$current),true);
log_it('ADD_POLL',strval($id),$question);
return $id;
}
void edit_poll(AUTO_LINK id, SHORT_TEXT question, SHORT_TEXT a1, SHORT_TEXT a2, SHORT_TEXT a3, SHORT_TEXT a4, SHORT_TEXT a5, SHORT_TEXT a6, SHORT_TEXT a7, SHORT_TEXT a8, SHORT_TEXT a9, SHORT_TEXT a10, integer num_options, BINARY allow_rating, SHORT_INTEGER allow_comments, BINARY allow_trackbacks, LONG_TEXT notes)
Edit a poll.
Parameters…
| Name |
id |
| Description |
The ID of the poll to edit |
| Type |
AUTO_LINK |
| Name |
question |
| Description |
The question |
| Type |
SHORT_TEXT |
| Name |
a1 |
| Description |
The first choice |
| Type |
SHORT_TEXT |
| Value range |
1 max |
| Name |
a2 |
| Description |
The second choice |
| Type |
SHORT_TEXT |
| Value range |
1 max |
| Name |
a3 |
| Description |
The third choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a4 |
| Description |
The fourth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a5 |
| Description |
The fifth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a6 |
| Description |
The sixth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a7 |
| Description |
The seventh choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a8 |
| Description |
The eighth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a9 |
| Description |
The ninth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
a10 |
| Description |
The tenth choice (blank means not a choice) |
| Type |
SHORT_TEXT |
| Name |
num_options |
| Description |
The number of choices |
| Type |
integer |
| Name |
allow_rating |
| Description |
Whether to allow rating of this poll |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether comments are allowed (0=no, 1=yes, 2=review style) |
| Type |
SHORT_INTEGER |
| Name |
allow_trackbacks |
| Description |
Whether to allow trackbacking on this poll |
| Type |
BINARY |
| Name |
notes |
| Description |
Notes about this poll |
| Type |
LONG_TEXT |
(No return value)
function edit_poll($id,$question,$a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,$a10,$num_options,$allow_rating,$allow_comments,$allow_trackbacks,$notes)
{
log_it('EDIT_POLL',strval($id),$question);
persistant_cache_delete('POLL');
$rows=$GLOBALS['SITE_DB']->query_select('poll',array('*'),array('id'=>$id),'',1);
$_question=$rows[0]['question'];
$_a1=$rows[0]['option1'];
$_a2=$rows[0]['option2'];
$_a3=$rows[0]['option3'];
$_a4=$rows[0]['option4'];
$_a5=$rows[0]['option5'];
$_a6=$rows[0]['option6'];
$_a7=$rows[0]['option7'];
$_a8=$rows[0]['option8'];
$_a9=$rows[0]['option9'];
$_a10=$rows[0]['option10'];
$GLOBALS['SITE_DB']->query_update('poll',array('edit_date'=>time(),'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks,'notes'=>$notes,'num_options'=>$num_options,'question'=>lang_remap_comcode($_question,$question),'option1'=>lang_remap_comcode($_a1,$a1),'option2'=>lang_remap_comcode($_a2,$a2),'option3'=>lang_remap_comcode($_a3,$a3),'option4'=>lang_remap_comcode($_a4,$a4),'option5'=>lang_remap_comcode($_a5,$a5),'option6'=>lang_remap_comcode($_a6,$a6),'option7'=>lang_remap_comcode($_a7,$a7),'option8'=>lang_remap_comcode($_a8,$a8),'option9'=>lang_remap_comcode($_a9,$a9),'option10'=>lang_remap_comcode($_a10,$a10)),array('id'=>$id),'',1);
decache('main_poll');
require_code('urls2');
suggest_new_idmoniker_for('polls','view',strval($id),$question);
require_code('feedback');
update_spacer_post($allow_comments!=0,'polls',strval($id),build_url(array('page'=>'polls','type'=>'view','id'=>$id),get_module_zone('polls'),NULL,false,false,true),$question,get_value('comment_forum__polls'));
}
void delete_poll(AUTO_LINK id)
Delete a poll.
Parameters…
| Name |
id |
| Description |
The ID of the poll to delete |
| Type |
AUTO_LINK |
(No return value)
function delete_poll($id)
{
$rows=$GLOBALS['SITE_DB']->query_select('poll',array('*'),array('id'=>$id),'',1);
persistant_cache_delete('POLL');
$question=get_translated_text($rows[0]['question']);
log_it('DELETE_POLL',strval($id),$question);
delete_lang($rows[0]['question']);
for ($i=1;$i<=10;$i++)
{
delete_lang($rows[0]['option'.strval($i)]);
}
$GLOBALS['SITE_DB']->query_delete('rating',array('rating_for_type'=>'polls','rating_for_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('trackbacks',array('trackback_for_type'=>'polls','trackback_for_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('poll',array('id'=>$id),'',1);
}
void set_poll(AUTO_LINK id)
Set the poll.
Parameters…
| Name |
id |
| Description |
The poll ID to set |
| Type |
AUTO_LINK |
(No return value)
function set_poll($id)
{
persistant_cache_delete('POLL');
$rows=$GLOBALS['SITE_DB']->query_select('poll',array('question','submitter'),array('id'=>$id));
$question=$rows[0]['question'];
$submitter=$rows[0]['submitter'];
log_it('CHOOSE_POLL',strval($id),get_translated_text($question));
if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(),'polls'))
syndicate_described_activity('polls:ACTIVITY_CHOOSE_POLL',get_translated_text($question),'','','_SEARCH:polls:view:'.strval($id),'','','polls');
if ((!is_guest($submitter)) && (addon_installed('points')))
{
require_code('points2');
$_points_chosen=get_option('points_CHOOSE_POLL');
if (is_null($_points_chosen)) $points_chosen=35; else $points_chosen=intval($_points_chosen);
if ($points_chosen!=0)
system_gift_transfer(do_lang('POLL'),$points_chosen,$submitter);
}
$GLOBALS['SITE_DB']->query_update('poll',array('is_current'=>0),array('is_current'=>1));
$GLOBALS['SITE_DB']->query_update('poll',array('is_current'=>1,'date_and_time'=>time()),array('id'=>$id),'',1);
decache('main_poll');
require_lang('polls');
require_code('notifications');
$subject=do_lang('POLL_CHOSEN_NOTIFICATION_MAIL_SUBJECT',get_site_name(),$question);
$poll_url=build_url(array('page'=>'polls','type'=>'view','id'=>$id),get_module_zone('polls'),NULL,false,false,true);
$mail=do_lang('POLL_CHOSEN_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape($question),$poll_url->evaluate());
dispatch_notification('poll_chosen',NULL,$subject,$mail);
}
tempcode nice_get_polls(?AUTO_LINK it, ?MEMBER only_owned)
Get a list of polls.
Parameters…
| Name |
it |
| Description |
The ID of the poll to select by default (NULL: first) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
only_owned |
| Description |
Only show polls owned by this member (NULL: no such restriction) |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The list |
| Type |
tempcode |
function nice_get_polls($it=NULL,$only_owned=NULL)
{
$where=is_null($only_owned)?NULL:array('submitter'=>$only_owned);
$rows=$GLOBALS['SITE_DB']->query_select('poll',array('question','is_current','votes1','votes2','votes3','votes4','votes5','votes6','votes7','votes8','votes9','votes10','id'),$where,'ORDER BY is_current DESC,date_and_time,question',400);
if (count($rows)==400) // Ok, just new ones
{
if (is_null($where)) $where=array();
$rows=$GLOBALS['SITE_DB']->query_select('poll',array('question','is_current','votes1','votes2','votes3','votes4','votes5','votes6','votes7','votes8','votes9','votes10','id'),$where+array('date_and_time'=>NULL),'ORDER BY add_time DESC',400);
}
$out=new ocp_tempcode();
foreach ($rows as $myrow)
{
$selected=!is_null($it);
if ($myrow['is_current']==1)
{
$status=do_lang_tempcode('CURRENT');
if (is_null($it)) $selected=true;
}
else
{
// If people have voted the IP field will have something in it. So we can tell if its new or not from this
if ($myrow['votes1']+$myrow['votes2']+$myrow['votes3']+$myrow['votes4']+$myrow['votes5']+$myrow['votes6']+$myrow['votes7']+$myrow['votes8']+$myrow['votes9']+$myrow['votes10']!=0)
$status=do_lang_tempcode('USED_PREVIOUSLY');
else $status=do_lang_tempcode('NOT_USED_PREVIOUSLY');
}
$text=do_template('POLL_LIST_ENTRY',array('_GUID'=>'dadf669bca2add9b79329b21e45d1010','QUESTION'=>get_translated_text($myrow['question']),'STATUS'=>$status));
$out->attach(form_input_list_entry(strval($myrow['id']),$selected,$text));
}
return $out;
}
0 reviews: Unrated (average)
There have been no comments yet