18 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
19 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
20 require_once SQ_FUDGE_PATH.
'/general/text.inc';
21 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
48 $this->_ser_attrs = TRUE;
49 parent::__construct($assetid);
66 if (!parent::_createAdditional($link))
return FALSE;
69 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
70 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'folder');
72 $folders = Array(
'vote_formats',
'results_formats',
'past_questions_formats');
76 foreach ($folders as $name) {
78 $copy_link = Array(
'asset' => &$this,
'value' => $name ,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
80 $asset->setAttrValue(
'name', ucwords(str_replace(
'_',
' ', $name)));
81 if (!$asset->create($copy_link))
return FALSE;
83 $formats[$name] = $asset;
85 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
90 $bodycopies = Array();
91 $bodycopies[
'question_format'] =
'vote_formats';
92 $bodycopies[
'option_list_format'] =
'vote_formats';
93 $bodycopies[
'results_format'] =
'results_formats';
94 $bodycopies[
'results_list_format'] =
'results_formats';
95 $bodycopies[
'past_questions_format'] =
'past_questions_formats';
96 $bodycopies[
'past_questions_list_format'] =
'past_questions_formats';
98 foreach ($bodycopies as $value => $folder_asset) {
100 $copy_link = Array(
'asset' => &$formats[$folder_asset],
'value' => $value ,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
101 $asset->setAttrValue(
'name', ucwords(str_replace(
'_',
' ',$value)));
102 if (!$asset->create($copy_link))
return FALSE;
130 function prepareLink(&$asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
132 $return_value = FALSE;
135 if ($side_of_link ==
'major' &&( $asset instanceof poll_question)) {
136 if ($link_type != SQ_LINK_TYPE_2) {
137 $link_type = SQ_LINK_TYPE_2;
138 $return_value = TRUE;
142 return $return_value;
156 $page_links = parent::_getAllowedLinks();
157 $page_links[SQ_LINK_TYPE_2][
'folder'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
158 $page_links[SQ_LINK_TYPE_2][
'poll_question'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
160 $page_links[SQ_LINK_NOTICE][
'asset'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
161 $page_links[SQ_LINK_TYPE_2][
'bodycopy'] = Array(
'card' => 3,
'exclusive' => FALSE);
179 $active_question_id = $this->
attr(
'active_question');
180 $format_type =
'question_format';
183 $am = $GLOBALS[
'SQ_SYSTEM']->am;
187 if ($active_question_id) {
188 $active_question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($active_question_id,
'', TRUE);
191 $question =& $active_question;
192 if (is_null($question)) $valid = FALSE;
205 if (array_get_index($_GET,
'SQ_POLL_ID') && array_get_index($_GET,
'SQ_ACTION')) {
206 $SQ_POLL_ID = (int) $_GET[
'SQ_POLL_ID'];
207 $SQ_ACTION = $_GET[
'SQ_ACTION'];
210 if (is_integer($SQ_POLL_ID) && $SQ_POLL_ID > 0 && $SQ_ACTION == $prefix.
'_results') {
213 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($SQ_POLL_ID,
'', TRUE);
216 if (!$question->id || !$am->getAssetTypeInfo(Array($question->id), Array(
'poll_question'), TRUE) || $question->status < SQ_STATUS_LIVE || !$am->getLinkByAsset($this->
id, $question->id, SQ_LINK_TYPE_2)) {
218 $question = $active_question;
226 $format_type =
'results_format';
227 $keyword_reps = Array();
230 if (!$this->
attr(
'allow_multiple_votes')) {
232 if ((!is_null($GLOBALS[
'SQ_SYSTEM']->user->name)) && (!$GLOBALS[
'SQ_SYSTEM']->userPublic())) {
234 if (!$GLOBALS[
'SQ_SYSTEM']->am->getShadowLinkByAsset($question->id, $GLOBALS[
'SQ_SYSTEM']->user->id, SQ_LINK_NOTICE)) {
236 if (isset($_POST[
'option_id'])) {
237 $GLOBALS[
'SQ_SYSTEM']->am->createShadowAssetLink($question, $GLOBALS[
'SQ_SYSTEM']->user, SQ_LINK_NOTICE);
242 if (array_get_index($_SESSION, $prefix.
'_VOTED') == FALSE) {
251 if (isset($_POST[
'option_id'])) {
256 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
259 $format_type =
'results_format';
264 if (array_get_index($_GET,
'SQ_ACTION') == $prefix.
'_past_polls') {
265 $format_type =
'past_questions_format';
269 if ($can_vote && array_get_index($_GET,
'SQ_ACTION') != $prefix.
'_results') {
271 $question = $active_question;
272 $format_type =
'question_format';
276 $format_type =
'results_format';
284 if (!is_null($format_bodycopy)) {
285 $keywords = $format_bodycopy->getKeywords();
286 foreach ($keywords as $keyword) {
287 if (!isset($keyword_reps[$keyword])) {
292 $format_bodycopy->setKeywordReplacements($keyword_reps);
296 if (isset($_POST[
'option_id']) && $can_vote) {
298 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
316 if ($format_type ==
'question_format') {
317 echo
'<form id="'.$this->getPrefix().
'_poll" action="'.$this->
getURL().
'" method="post">';
318 $format_bodycopy->printBody();
321 $format_bodycopy->printBody();
338 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE, $type);
340 if (empty($link))
return $null;
342 $folder = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
343 if (is_null($folder))
return $null;
361 $parent_folders = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id,
'folder', TRUE);
362 $parent_bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id,
'bodycopy', TRUE);
364 $vote_formats = $this->
getFolder(
'vote_formats');
365 $result_formats = $this->
getFolder(
'results_formats');
366 $past_questions_formats = $this->
getFolder(
'past_questions_formats');
369 if (in_array($vote_formats->id, array_keys($parent_folders))) {
371 $option_list_format = $this->
getFormatAsset(
'option_list_format');
372 if (in_array($quetion_format->id, array_keys($parent_bodycopy))) {
374 }
else if (in_array($option_list_format->id, array_keys($parent_bodycopy))) {
377 }
else if (in_array($result_formats->id, array_keys($parent_folders))) {
379 $results_list_format = $this->
getFormatAsset(
'results_list_format');
380 if (in_array($results_format->id, array_keys($parent_bodycopy))) {
382 }
else if (in_array($results_list_format->id, array_keys($parent_bodycopy))) {
385 }
else if (in_array($past_questions_formats->id, array_keys($parent_folders))) {
386 $past_questions_format = $this->
getFormatAsset(
'past_questions_format');
387 $past_questions_list_format = $this->
getFormatAsset(
'past_questions_list_format');
388 if (in_array($past_questions_format->id, array_keys($parent_bodycopy))) {
390 }
else if (in_array($past_questions_list_format->id, array_keys($parent_bodycopy))) {
395 $vars[
'keywords'] = array_merge($vars[
'keywords'], $keywords);
424 'poll_active_question' => $this->_componentActiveQuestion($question, FALSE),
425 'poll_active_question_results' => $this->_componentActiveQuestion($question, FALSE, TRUE),
426 'poll_active_question_date' => $this->_componentActiveQuestion($question, TRUE),
427 'poll_active_question_date_results' => $this->_componentActiveQuestion($question, TRUE, TRUE),
444 $keywords[
'poll_question'] = translate(
'cms_poll_question');
445 $keywords[
'poll_date'] = translate(
'cms_poll_date');
446 $keywords[
'poll_option_list'] = translate(
'cms_poll_option_list');
447 $keywords[
'poll_vote_button'] = translate(
'cms_poll_vote_button');
448 $keywords[
'poll_vote_button_new_window'] = translate(
'cms_poll_vote_button_new_window');
449 $keywords[
'poll_vote_button_js'] = translate(
'cms_poll_vote_button_js');
450 $keywords[
'poll_vote_button_js_new_window'] = translate(
'cms_poll_vote_button_js_new_window');
451 $keywords[
'poll_view_results'] = translate(
'cms_poll_view_results');
452 $keywords[
'poll_view_results_url'] = translate(
'cms_poll_view_results_url');
453 $keywords[
'poll_view_past_questions'] = translate(
'cms_poll_view_past_questions');
454 $keywords[
'poll_view_past_questions_url'] = translate(
'cms_poll_view_past_questions_url');
455 $keywords[
'poll_active_question'] = translate(
'cms_poll_active_question');
456 $keywords[
'poll_active_question_results'] = translate(
'cms_poll_active_question_results');
457 $keywords[
'poll_active_question_date'] = translate(
'cms_poll_active_question_date');
458 $keywords[
'poll_active_question_date_results'] = translate(
'cms_poll_active_question_date_results');
474 $keywords[
'poll_option_label'] = translate(
'cms_poll_option_label');
475 $keywords[
'poll_option_number'] = translate(
'cms_poll_option_number');
476 $keywords[
'poll_option_id'] = translate(
'cms_poll_option_id');
477 $keywords[
'poll_option_vote_selection_button'] = translate(
'cms_poll_option_vote_selection_button');
494 $keywords[
'poll_results_list'] = translate(
'cms_poll_results_list');
495 if (isset($keywords[
'poll_option_list'])) {
496 unset($keywords[
'poll_option_list']);
528 $keywords[
'poll_option_number'] = translate(
'cms_poll_option_number');
529 $keywords[
'poll_option_id'] = translate(
'cms_poll_option_id');
530 $keywords[
'poll_option_label'] = translate(
'cms_poll_option_label');
531 $keywords[
'poll_option_bar'] = translate(
'cms_poll_option_bar');
532 $keywords[
'poll_option_votes_number'] = translate(
'cms_poll_option_votes_number');
533 $keywords[
'poll_option_votes_percent'] = translate(
'cms_poll_option_votes_percent');
549 $keywords[
'poll_question_list'] = translate(
'cms_poll_question_list');
550 $keywords[
'poll_question_list_date'] = translate(
'cms_poll_question_list_date');
551 $keywords[
'poll_question_list_no_active'] = translate(
'cms_poll_question_list_no_active');
552 $keywords[
'poll_question_list_date_no_active'] = translate(
'cms_poll_question_list_date_no_active');
553 $keywords[
'poll_active_question'] = translate(
'cms_poll_active_question');
554 $keywords[
'poll_date'] = translate(
'cms_poll_date');
576 'poll_question_list' => $this->_componentQuestionList($active_question_id, FALSE, FALSE),
577 'poll_question_list_date' => $this->_componentQuestionList($active_question_id, TRUE, FALSE),
578 'poll_question_list_no_active' => $this->_componentQuestionList($active_question_id, FALSE, TRUE),
579 'poll_question_list_date_no_active' => $this->_componentQuestionList($active_question_id, TRUE, TRUE),
580 'poll_active_question' => $this->_componentActiveQuestion($question, FALSE),
597 $keywords[
'poll_question'] = translate(
'cms_poll_question');
616 $folders = $this->
attr(
'format_bodycopies');
618 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE, $folders[$format]);
619 if (empty($link))
return $null;
621 $folder = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
622 if (is_null($folder))
return $null;
624 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2,
'bodycopy', TRUE, $format);
625 if (empty($bodycopy_link))
return $null;
627 $format_bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bodycopy_link[
'minorid'], $bodycopy_link[
'minor_type_code']);
629 return $format_bodycopy;
647 if (!is_array($option_ids)) {
648 $option_ids = Array($option_ids);
651 $options = $question->attr(
'options');
653 foreach ($option_ids as $option_id) {
655 if (isset($options[$option_id])) {
658 $options[$option_id][
'votes']++;
659 $question->setAttrValue(
'options', $options);
666 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
667 $question->saveAttributes();
668 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
670 $_SESSION[$this->
getPrefix().
'_VOTED'] = TRUE;
691 return $question->attr(
'name');
706 return easy_datetime($question->created);
722 if (is_null($format_bodycopy))
return FALSE;
726 $options = $question->attr(
'options');
730 foreach ($options as $option_id => $option_values ) {
731 $keywords[
'poll_option_label'] = $option_values[
'option_text'];
732 $keywords[
'poll_option_number'] = $option_id + 1;
733 $keywords[
'poll_option_id'] = $option_id;
735 if ($question->attr(
'allow_multiple')) {
736 check_box(
'option_id[]',$option_id);
738 radio_button(
'option_id',$option_id);
740 $selection_button = ob_get_clean();
741 $keywords[
'poll_option_vote_selection_button'] = $selection_button;
744 $format_bodycopy->setKeywordReplacements($keywords);
745 $format_bodycopy->printBody();
746 $output .= ob_get_clean();
768 submit_button($this->
getPrefix().
'_poll_vote', $this->
attr(
'vote_button_text'), $xtras);
770 return ob_get_clean();
790 return $xtras.
' document.getElementById(\''.$this->
getPrefix().
'_poll\').submit();';
803 $width = $this->
attr(
'new_window_width');
804 $height = $this->
attr(
'new_window_height');
805 $options = $this->
attr(
'new_window_options');
807 $params =
'location='.((strpos($options,
'hide_location' ) !== FALSE) ?
'0' :
'1').
','
808 .
'menubar='.((strpos($options,
'hide_menubar' ) !== FALSE) ?
'0' :
'1').
','
809 .
'scrollbars='.((strpos($options,
'hide_scrollbars') !== FALSE) ?
'0' :
'1').
','
810 .
'statusbar='.((strpos($options,
'hide_status' ) !== FALSE) ?
'0' :
'1').
','
811 .
'toolbar='.((strpos($options,
'hide_toolbar' ) !== FALSE) ?
'0' :
'1').
','
812 .
'resizable='.((strpos($options,
'not_resizable' ) !== FALSE) ?
'0' :
'1');
814 $xtras =
' window.open(\'\', \'results\', \'width='.$width.
',height='.$height.
','.$params.
'\'); document.getElementById(
"'.$this->getPrefix().'_poll").target=\
'results\';';
830 <a href=
"<?php echo $this->getURL(); ?>?SQ_ACTION=<?php echo $this->getPrefix(); ?>_results"><?php echo $this->
attr(
'view_results_text'); ?></a>
833 return ob_get_clean();
862 <a href=
"<?php echo $this->getURL(); ?>?SQ_ACTION=<?php echo $this->getPrefix(); ?>_past_polls"><?php echo $this->
attr(
'previous_questions_text'); ?></a>
865 return ob_get_clean();
915 $question_width = $this->
attr(
'graph_box_width');
916 $question_height = $this->
attr(
'graph_box_height');
917 $question_colour_bar = $this->
attr(
'graph_box_colour_bar');
921 $options = $question->attr(
'options');
925 <style
type=
"text/css">
926 #sq-page-poll-graph {
928 width: <?php echo $question_width; ?>px;
931 #sq-page-poll-graph-bar {
932 background: <?php echo $question_colour_bar; ?>;
936 #sq-page-poll-result {
947 <div
id=
"sq-page-poll-graph">
951 foreach ($options as $option_values) {
952 $poll_total += $option_values[
'votes'];
956 if ($poll_total == 0) $poll_total++;
958 $format_bodycopy = $this->getFormatAsset(
'results_list_format');
959 if (is_null($format_bodycopy))
return FALSE;
962 $output .= ob_get_clean();
965 foreach ($options as $option_id => $option_values) {
967 $width = $option_values[
'votes'] / $poll_total;
969 $keywords[
'poll_option_label'] = $option_values[
'option_text'];
970 $keywords[
'poll_option_number'] = $option_id + 1;
971 $keywords[
'poll_option_id'] = $option_id;
975 <div
id=
"sq-page-poll-graph-bar" style=
"width: <?php echo round($width * $question_width / 2); ?>px"> </div>
977 $bar_output = ob_get_clean();
978 $keywords[
'poll_option_bar'] = $bar_output;
979 $keywords[
'poll_option_votes_number'] = $option_values[
'votes'];
980 $keywords[
'poll_option_votes_percent'] = number_format(($width*100),0,
'.',
' ').
'%';
982 $format_bodycopy->setKeywordReplacements($keywords);
983 $format_bodycopy->printBody();
984 $output .= ob_get_clean();
992 $output .= ob_get_clean();
1008 function _componentQuestionList($active_question_id, $date=FALSE, $no_active=FALSE)
1012 $format_bodycopy = $this->getFormatAsset(
'past_questions_list_format');
1013 if (is_null($format_bodycopy))
return FALSE;
1014 $keywords = Array();
1019 $poll_children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks( $this->
id, SQ_LINK_TYPE_2,
1031 $asset_id_list = Array();
1032 foreach ($poll_children as $child_id => $child_data) {
1033 array_push($asset_id_list, $child_data[
'minorid']);
1037 $info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($asset_id_list,
'poll_question');
1041 array_reverse($info);
1042 $output = ob_get_clean();
1044 foreach ($info as $info_index => $info_data) {
1047 if ($info_data[
'status'] < SQ_STATUS_LIVE)
continue;
1051 if ($info_index == $active_question_id && $no_active) {
1058 <a href=
"<?php echo $this->getURL().'?SQ_ACTION='.$this->getPrefix().'_results&SQ_POLL_ID='.$info_index; ?>">
1061 echo $info_data[
'name'];
1063 echo
' ('.easy_datetime(strtotime($info_data[
'created'])).
')';
1065 if ($info_index == $active_question_id) {
1066 echo
' (<strong>Active</strong>)';
1072 $link .= ob_get_clean();
1073 $keywords[
'poll_question'] = $link;
1074 $poll_question_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($info_index);
1075 foreach ($format_bodycopy->getKeywords() as $keyword) {
1076 if (empty($keywords[$keyword])) {
1077 $keywords[$keyword] = $poll_question_asset->getKeywordReplacement($keyword);
1081 $format_bodycopy->setKeywordReplacements($keywords);
1082 $format_bodycopy->printBody();
1083 $output .= ob_get_clean();
1088 $output .= ob_get_clean();
1104 function _componentActiveQuestion(&$active_question, $date, $results=FALSE)
1109 <a href=
"<?php echo $this->getURL(); ?>?SQ_ACTION=<?php echo $this->getPrefix(); ?><?php echo ($results ? '_results' : ''); ?>">
1112 echo $active_question->attr(
'name');
1114 echo
' ('.easy_datetime($active_question->created).
')';
1121 return ob_get_clean();