8 require_once(CH_DIRECTORY_PATH_CLASSES .
'ChWsbModule.php');
9 require_once(CH_DIRECTORY_PATH_CLASSES .
'ChWsbAlerts.php');
10 require_once(CH_DIRECTORY_PATH_CLASSES .
'ChWsbCategories.php');
12 require_once(
'ChPollCalendar.php');
13 require_once(
'ChPollPrivacy.php');
14 require_once(
'ChPollSearch.php');
16 define(
'CH_POLL_VOTE_UNIQ', 60*60*24*30);
17 define(
'CH_POLL_ANS_DIVIDER',
'<delim>');
18 define(
'CH_POLL_RES_DIVIDER',
';');
20 define(
'POLL_ERROR_OCCURED',
_t(
'_Error occured') );
21 define(
'POLL_EMPTY_FIELDS',
_t(
'_please_fill_next_fields_first') );
22 define(
'POLL_CREATED',
_t(
'_ch_poll_created') );
23 define(
'POLL_EDITED',
_t(
'_ch_poll_was_edited') );
24 define(
'POLL_MAX_REACHED',
_t(
'_ch_poll_max_reached') );
25 define(
'POLL_NOT_ALLOW',
_t(
'_ch_poll_not_available') );
31 if (count($aItems) < 2) {
35 return parent::checkLength ($aItems, $iLenMin, $iLenMax);
41 foreach ($a
as $k => $v)
43 return is_array($a) ? implode(
',', $a) : $a;
171 $this -> sHomeUrl = $this ->_oConfig -> _sHomeUrl;
175 $this -> aPollSettings[
'question_min_length'] = 10;
176 $this -> aPollSettings[
'question_max_length'] = 300;
178 $this -> aPollSettings[
'answer_min_length'] = 1;
179 $this -> aPollSettings[
'answer_max_length'] = 300;
182 if( !$this -> aPollSettings[
'per_page'] )
183 $this -> aPollSettings[
'per_page'] = 10;
185 if ( $this -> aPollSettings[
'per_page'] > 100 )
186 $this -> aPollSettings[
'per_page'] = 100;
188 if( $this -> aPollSettings[
'page'] < 1 )
189 $this -> aPollSettings[
'page'] = 1;
192 $this -> aUsedTemplates = array
194 'poll_init' =>
'poll_init.html',
195 'poll_block' =>
'poll_block.html',
196 'poll_view_block' =>
'poll_view_block.html',
197 'poll_block_ajax' =>
'poll_block_ajax.html',
198 'poll_questions_list' =>
'poll_questions_list.xml',
199 'poll_results_list' =>
'poll_results_list.xml',
200 'server_answer' =>
'server_answer.xml',
201 'poll_creation_form' =>
'poll_creation_form.html',
202 'poll_edit_form' =>
'poll_edit_form.html',
203 'poll_actions' =>
'poll_actions.html',
204 'poll_premoderation' =>
'poll_premoderation.html',
205 'poll_owner' =>
'entry_view_block_info.html',
211 $this -> sPathToModule = CH_WSB_URL_ROOT . $this -> _oConfig -> getBaseUri();
212 if ($this -> aPollSettings[
'action']) {
213 $this -> sPathToModule .=
'&action=' . rawurlencode($this -> aPollSettings[
'action']);
227 return CH_WSB_URL_ROOT . $this -> _oConfig -> getBaseUri();
242 $aTemplateKeys = array(
243 'author_unit' => $sThumbImg,
253 $sOutpuCode = $this -> _oTemplate -> parseHtmlByName($this -> aUsedTemplates[
'poll_owner'], $aTemplateKeys);
255 return array($sOutpuCode);
267 switch($this -> aPollSettings[
'mode']) {
290 $sPageCaption =
_t($this->aPollSettings[
'mode'] ==
'manage' ?
'_ch_poll_manage_poll' :
'_ch_poll_pending_poll');
294 if(!
empty($_POST[
'poll_id']) && is_array($_POST[
'poll_id']))
295 foreach($_POST[
'poll_id']
as $iKey)
300 $sOutputCode .= $this ->
getManagePollsPage($this -> aPollSettings[
'mode'] ==
'manage');
305 $sOutputCode =
'<center class="ch-def-font-large">' .
_t(
'_ch_poll_have_not_approval',
306 '<b>' . $this -> _oDb -> getUnApprovedPolls($this -> aPollSettings[
'member_id']) .
'</b>') .
'</center>';
308 $aTemplateKeys = array(
309 'content' => $sOutputCode,
312 $sOutputCode =
$GLOBALS[
'oSysTemplate'] -> parseHtmlByName(
'default_padding.html', $aTemplateKeys);
321 $aToggleItems = array (
322 'main' =>
_t(
'_ch_poll_main'),
323 'add' =>
_t(
'_ch_poll_add'),
324 'manage' =>
_t(
'_ch_poll_manage'),
325 'pending' =>
_t(
'_ch_poll_pending'),
329 if(!$this->aPollSettings[
'mode'])
330 $this->aPollSettings[
'mode'] =
'main';
333 if($this->aPollSettings[
'mode'] ==
'edit_poll')
334 $aToggleItems[
'edit_poll'] =
_t(
'_ch_poll_edit');
337 foreach($aToggleItems
as $sKey => $sValue)
338 $aItems[$sValue] = array(
'href' => $this->sPathToModule .
'&mode=' . $sKey,
'active' => $this->aPollSettings[
'mode'] == $sKey ? 1 : 0);
354 $this -> oSearch -> aCurrent[
'restriction'][
'my'][
'value'] = $this -> aPollSettings[
'member_id'];
355 $this -> oSearch -> aCurrent[
'restriction'][
'activeStatus'][
'value'] =
'';
356 $sExtraParam =
'&mode=manage';
357 $sOutputCode = $this ->
showSearchResult(
null, $sExtraParam, 0,
true, 0,
false);
360 $this -> oSearch -> aCurrent[
'restriction'][
'my'][
'value'] = $this -> aPollSettings[
'member_id'];
361 $this -> oSearch -> aCurrent[
'restriction'][
'approvalStatus'][
'operator'] =
'!=';
362 $sExtraParam =
'&mode=pending';
363 $sOutputCode = $this ->
showSearchResult(
null, $sExtraParam, 0,
true, 0,
false);
371 <div id="pol_container">
372 <form id="manage_form" method="post">
373 ' . $sOutputCode . $aAdminSection .
'
381 function showAdminActionsPanel($sWrapperId, $aButtons, $sCheckboxName =
'entry', $bSelectAll =
true, $bSelectAllChecked =
false)
383 $aUnit = $aBtns = array();
384 if(is_array($aButtons) && !
empty($aButtons))
385 foreach ($aButtons
as $k => $v) {
393 'value' => (
'_' == $v[0] ?
_t($v) : $v),
397 $aUnit[
'ch_if:actionButtons'] = array(
398 'condition' => !
empty($aBtns),
400 'ch_repeat:buttons' => $aBtns
403 $aUnit[
'ch_if:selectAll'] = array(
404 'condition' => $bSelectAll,
406 'wrapperId' => $sWrapperId,
407 'checkboxName' => $sCheckboxName,
408 'checked' => ($bSelectAll && $bSelectAllChecked ?
'checked="checked"' :
'')
411 $aUnit[
'ch_if:customHTML'] = array(
412 'condition' =>
false,
413 'content' => array(),
416 return $GLOBALS[
'oSysTemplate']->parseHtmlByName(
'adminActionsPanel.html',
$aUnit, array(
'{',
'}'));
431 $aTemplateKeys = array ();
432 return $this -> _oTemplate -> parseHtmlByName(
'poll_private_block.html', $aTemplateKeys);
445 function getPollBlock(&$aPollInfo, $bAjaxQuery =
false, $bViewMode =
false, $bAdminMode =
false)
447 if(!$this -> oPrivacy -> check(
'view', $aPollInfo[
'id_poll'], $this -> aPollSettings[
'member_id']))
451 $sPollActions =
null;
455 $aLanguageKeys = array (
456 'results' =>
_t(
'_ch_poll_result'),
457 'delete' =>
_t(
'_ch_poll_delete'),
458 'edit' =>
_t(
'_ch_poll_edit'),
459 'active' =>
_t(
'_ch_poll_active'),
460 'sure' =>
_t(
'_Are_you_sure'),
461 'by' =>
_t(
'_ch_poll_by' ),
462 'poll' =>
_t(
'_ch_poll'),
464 'featured' =>
_t(
'_ch_poll_featured'),
465 'unfeatured' =>
_t(
'_ch_poll_unfeatured'),
466 'poll_approved' =>
_t(
'_ch_poll_approved'),
467 'poll_unapproved' =>
_t(
'_ch_poll_unapproved'),
474 $aTemplateKeys = array (
475 'ch_if:start_tag' => array (
476 'condition' => !$bAjaxQuery,
477 'content' => array(
'uid' => $aPollInfo[
'id_poll']),
480 'ch_if:manage_page' => array (
481 'condition' => $bAdminMode || (in_array($this->aPollSettings[
'mode'], array(
'manage',
'pending')) && $this->aPollSettings[
'member_id'] && $this->aPollSettings[
'member_id'] == $aPollInfo[
'id_profile']),
486 'ch_if:end_tag' => array (
487 'condition' => !$bAjaxQuery,
488 'content' => array(),
491 'uid' => $aPollInfo[
'id_poll'],
492 'poll_url' => CH_WSB_URL_ROOT . $this -> _oConfig -> getBaseUri() .
'&action=show_poll_info&id=' . $aPollInfo[
'id_poll'],
493 'ch_if:show_link' => array(
494 'condition' => $aPollInfo[
'id_profile'],
500 'ch_if:show_text' => array(
501 'condition' => !$aPollInfo[
'id_profile'],
503 'content' =>
_t(
'_Admin' )
506 'date_add' => $sDateAdd ,
507 'result' => $aLanguageKeys[
'results'],
508 'actions' => $sPollActions,
509 'by' => $aLanguageKeys[
'by'],
511 'ch_if:show_status' => array(
512 'condition' => $bAdminMode,
514 'status' => $aPollInfo[
'poll_approval'] ? $aLanguageKeys[
'poll_approved'] : $aLanguageKeys[
'poll_unapproved'],
515 'featured' => $aPollInfo[
'poll_featured'] ? $aLanguageKeys[
'featured'] : $aLanguageKeys[
'unfeatured'],
519 'ch_if:show_actions' => array(
520 'condition' => $bAdminMode,
522 'url_edit' => $this -> sPathToModule .
'&action=my&mode=edit_poll&edit_poll_id=' . $aPollInfo[
'id_poll'],
527 'pool_down_src' => $this -> _oTemplate -> getIconUrl (
'poll_down.png' ),
528 'pool_up_src' => $this -> _oTemplate -> getIconUrl (
'poll_up.png' ),
530 'spacer' => $this -> _oTemplate -> getIconUrl (
'spacer.gif' ),
532 'back' => $aLanguageKeys[
'poll'],
535 $sTemplateName = !$bViewMode ? $this->aUsedTemplates[
'poll_block'] : $this->aUsedTemplates[
'poll_view_block'];
536 return $this->_oTemplate->parseHtmlByName($sTemplateName, $aTemplateKeys);
551 $this -> _oTemplate -> addJs(
'profile_poll.js');
553 $sJS = $this -> _oTemplate -> addJs(
'profile_poll.js',
true);
557 $aLanguageKeys = array
559 'delete' =>
_t(
'_ch_poll_delete'),
560 'loading' =>
_t(
'_ch_poll_loading') .
'...',
561 'poll_deleted' =>
_t(
'_ch_poll_was_deleted'),
562 'make_it' =>
_t(
'_ch_poll_make_it'),
563 'you_should' =>
_t(
'_ch_poll_specify_least'),
566 $aTemplateKeys = array
569 'delete' => $aLanguageKeys[
'delete'],
570 'loading' => $aLanguageKeys[
'loading'],
571 'poll_deleted' => $aLanguageKeys[
'poll_deleted'],
572 'make_it' => $aLanguageKeys[
'make_it'],
573 'you_should' => $aLanguageKeys[
'you_should'],
574 'path_to_script' => $this -> sHomeUrl,
575 'module_name' => $this -> aModuleInfo[
'uri'],
576 'site' =>
$site[
'url'],
580 $sInitPart = $this -> _oTemplate -> parseHtmlByName( $this -> aUsedTemplates[
'poll_init'], $aTemplateKeys );
582 return $sJS . $sInitPart;
591 $sPollResults =
null;
593 if (isset($_POST[
'question'])
594 and ( $this -> aPollSettings[
'member_id']
or $this -> aPollSettings[
'admin_mode'] ) ) {
597 $sPollQuestion = strip_tags( trim($_POST[
'question']) );
599 if( $_POST[
'answers']
and is_array($_POST[
'answers']) ) {
601 foreach( $_POST[
'answers']
as $iKey => $sValue ) {
603 $sValue = strip_tags( trim($sValue) );
606 $sPollResults .=
'0;';
611 foreach($_POST
as $sKey => $sValue) {
612 if( strstr($sKey,
'answers_') ) {
620 if( isset($_POST[
'tags']) ) {
621 $sTags = strip_tags( trim($_POST[
'tags']) );
625 if( isset($_POST[
'Categories']) && is_array($_POST[
'Categories']) ) {
626 foreach($_POST[
'Categories']
as $iKey => $sValue) {
634 $iCommentGroupValue = ( isset($_POST[
'allow_comment_to']) )
635 ? (
int) $_POST[
'allow_comment_to']
638 $iVoteGroupValue = ( isset($_POST[
'allow_vote_to']) )
639 ? (
int) $_POST[
'allow_vote_to']
642 $iViewGroupValue = ( isset($_POST[
'allow_view_to']) )
643 ? (
int) $_POST[
'allow_view_to']
646 if (
$_GET[
'mode'] ==
'add' && $sPollAnsers) {
659 }
else if (
$_GET[
'mode'] ==
'edit_poll' && $sPollAnsers) {
661 $bActive = ( isset($_POST[
'active']) ) ?
true :
false ;
662 $bApprove = ( isset($_POST[
'approve']) &&
isAdmin() ) ?
true :
false ;
666 $this -> aPollSettings[
'edit_poll_id'],
690 return MsgBox(
_t(
'_ch_poll_access_denied') );
693 $iDefaultAnswerCount = 2;
695 $aLanguageKeys = array
697 'create' =>
_t(
'_ch_poll_create'),
698 'tags' =>
_t(
'_ch_poll_tags'),
699 'tags_sep' =>
_t(
'_sys_tags_note'),
700 'generate' =>
_t(
'_ch_poll_generate'),
701 'question' =>
_t(
'_ch_poll_question'),
702 'answer' =>
_t(
'_ch_poll_answer'),
703 'add_answer' =>
_t(
'_ch_poll_add'),
704 'max_pool' =>
_t(
'_ch_poll_max_reached'),
706 'question_length_req' =>
_t(
'_ch_poll_question_length_required',
707 $this -> aPollSettings[
'question_min_length'], $this -> aPollSettings[
'question_max_length']),
709 'answer_length_req' =>
_t(
'_ch_poll_answer_length_required',
710 $this -> aPollSettings[
'answer_min_length'], $this -> aPollSettings[
'answer_max_length']),
715 'form_attrs' => array (
716 'action' => $this -> sPathToModule .
'&mode=' . $this -> aPollSettings[
'mode'],
718 'name' =>
'poll_creation_form'
722 'checker_helper' =>
'ChCheckerPoll',
724 'submit_name' =>
'do_submit',
729 'question' => array (
731 'name' =>
'question',
732 'caption' => $aLanguageKeys[
'question'],
738 'params' => array($this -> aPollSettings[
'question_min_length'], $this -> aPollSettings[
'question_max_length']),
739 'error' => $aLanguageKeys[
'question_length_req'],
745 'name' =>
'answers[]',
746 'caption' => $aLanguageKeys[
'answer'],
748 'value' => array (
'',
''),
751 'multiplyable' =>
'true',
757 'params' => array($this -> aPollSettings[
'answer_min_length'], $this -> aPollSettings[
'answer_max_length']),
758 'error' => $aLanguageKeys[
'answer_length_req'],
766 'category' => array(),
771 'caption' => $aLanguageKeys[
'tags'],
773 'info' => $aLanguageKeys[
'tags_sep'],
776 'allow_view_to' => $this -> oPrivacy -> getGroupChooser($this -> aPollSettings[
'member_id']
777 , $this -> aModuleInfo[
'uri'],
'view', array(),
_t(
'_ch_poll_allow_view') ),
779 'allow_comments_to' => $this -> oPrivacy -> getGroupChooser($this -> aPollSettings[
'member_id']
780 , $this -> aModuleInfo[
'uri'],
'comment', array(),
_t(
'_ch_poll_allow_comment') ),
782 'allow_vote_to' => $this -> oPrivacy -> getGroupChooser($this -> aPollSettings[
'member_id']
783 , $this -> aModuleInfo[
'uri'],
'vote', array(),
_t(
'_ch_poll_allow_vote') ),
789 $oCategories -> getTagObjectConfig();
790 $aForm[
'inputs'][
'category'] = $oCategories -> getGroupChooser (
'ch_poll', $this -> aPollSettings[
'member_id'],
true);
793 $aForm[
'inputs'][] = array (
795 'name' =>
'do_submit',
796 'value' => $aLanguageKeys[
'generate'],
803 if (
$oForm -> isSubmittedAndValid() ) {
805 $sOutputCode .= $this -> sActionAnswer;
807 $sOutputCode .=
$oForm -> getCode();
810 return $this->_oTemplate->parseHtmlByName(
'default_margin.html', array(
'content' => $sOutputCode));
822 $aOpt = array(
'only_menu' => 1,
'BaseUri' => $this -> _oConfig -> getBaseUri());
823 $GLOBALS[
'oTopMenu'] -> setCustomSubActions($aOpt,
'ch_poll_title');
834 if($this -> aPollSettings[
'edit_poll_id']) {
835 $aPollInfo = $this -> _oDb -> getPollInfo($this -> aPollSettings[
'edit_poll_id']);
836 $aPollInfo = array_shift($aPollInfo);
839 if ($this -> aPollSettings[
'admin_mode']
840 || $aPollInfo[
'id_profile'] == $this -> aPollSettings[
'member_id'] ) {
842 $aLanguageKeys = array
844 'question' =>
_t(
'_ch_poll_question'),
845 'answer' =>
_t(
'_ch_poll_answer'),
846 'save' =>
_t(
'_ch_poll_save'),
847 'close' =>
_t(
'_ch_poll_close'),
848 'active' =>
_t(
'_ch_poll_active'),
849 'approve' =>
_t(
'_ch_poll_approve'),
850 'tags' =>
_t(
'_ch_poll_tags'),
851 'tags_sep' =>
_t(
'_ch_poll_tags_separeted'),
853 'question_length_req' =>
_t(
'_ch_poll_question_length_required',
854 $this -> aPollSettings[
'question_min_length'], $this -> aPollSettings[
'question_max_length']),
856 'answer_length_req' =>
_t(
'_ch_poll_answer_length_required',
857 $this -> aPollSettings[
'answer_min_length'], $this -> aPollSettings[
'answer_max_length']),
862 'form_attrs' => array (
863 'action' => $this -> sPathToModule .
'&mode=' . $this -> aPollSettings[
'mode'] .
'&edit_poll_id=' . $this -> aPollSettings[
'edit_poll_id'],
865 'name' =>
'poll_edit_form'
869 'checker_helper' =>
'ChCheckerPoll',
871 'submit_name' =>
'do_submit',
876 'question' => array (
878 'name' =>
'question',
879 'caption' => $aLanguageKeys[
'question'],
881 'value' => $aPollInfo[
'poll_question'],
886 'params' => array($this -> aPollSettings[
'question_min_length'], $this -> aPollSettings[
'question_max_length']),
887 'error' => $aLanguageKeys[
'question_length_req'],
897 foreach($aAnswers
as $iKey => $sValue) {
901 $aForm[
'inputs'][] = array(
903 'name' =>
'answers_' .
$iIndex,
904 'caption' => $aLanguageKeys[
'answer'] .
' ' .
$iIndex,
911 'params' => array($this -> aPollSettings[
'answer_min_length'], $this -> aPollSettings[
'answer_max_length']),
912 'error' => $aLanguageKeys[
'answer_length_req'],
920 $oCategories -> getTagObjectConfig();
923 $aForm[
'inputs'][
'category'] = $oCategories -> getGroupChooser (
'ch_poll', $this -> aPollSettings[
'member_id'],
true, $aPollInfo[
'poll_categories']);
924 $aForm[
'inputs'][
'category'][
'value'] = $aCurrentCategories;
927 $aForm[
'inputs'][] = array (
930 'caption' => $aLanguageKeys[
'tags'],
932 'info' => $aLanguageKeys[
'tags_sep'],
933 'value' => $aPollInfo[
'poll_tags'],
937 'allow_view_to' => $this -> oPrivacy -> getGroupChooser($this -> aPollSettings[
'member_id'], $this -> aModuleInfo[
'uri'],
'view', array(),
_t(
'_ch_poll_allow_view') ),
938 'allow_comments_to' => $this -> oPrivacy -> getGroupChooser($this -> aPollSettings[
'member_id'], $this -> aModuleInfo[
'uri'],
'comment', array(),
_t(
'_ch_poll_allow_comment') ),
939 'allow_vote_to' => $this -> oPrivacy -> getGroupChooser($this -> aPollSettings[
'member_id'], $this -> aModuleInfo[
'uri'],
'vote', array(),
_t(
'_ch_poll_allow_vote') ),
943 $aForm[
'inputs'][] = array (
944 'type' =>
'checkbox',
946 'caption' => $aLanguageKeys[
'active'],
949 'checked' => ($aPollInfo[
'poll_status']) ?
'checked' :
null,
955 $aForm[
'inputs'][] = array (
956 'type' =>
'checkbox',
958 'caption' => $aLanguageKeys[
'approve'],
961 'checked' => ($aPollInfo[
'poll_approval']) ?
'checked' :
null,
966 $aForm[
'inputs'][] = array (
968 'name' =>
'do_submit',
969 'value' => $aLanguageKeys[
'save'],
972 $aForm[
'inputs'][
'allow_view_to'][
'value'] = (string) $aPollInfo[
'allow_view_to'];
973 $aForm[
'inputs'][
'allow_comments_to'][
'value'] = (string) $aPollInfo[
'allow_comment_to'];
974 $aForm[
'inputs'][
'allow_vote_to'][
'value'] = (string) $aPollInfo[
'allow_vote_to'];
980 if (
$oForm -> isSubmittedAndValid() ) {
982 $sOutputCode =
MsgBox(
_t(
'_ch_poll_was_edited') );
984 $sOutputCode =
$oForm -> getCode();
989 return $this->_oTemplate->parseHtmlByName(
'default_margin.html', array(
'content' => $sOutputCode));
1006 $aPoll = $this -> _oDb -> getPollInfo( (
int) $iPollID );
1010 $iTotalVotes = $aPoll[0][
'poll_total_votes'];
1012 foreach ($aAnswersResult
as $value) {
1016 'point' => round( (0 != $iTotalVotes ? (( $value / $iTotalVotes ) * 100) : 0), 1),
1017 'number' => htmlspecialchars ( $value ),
1019 }
else if ( $value !=
'' ) {
1028 foreach ($aAnswersNames
as $value) {
1032 'name' => htmlspecialchars ( $value ),
1038 header(
'Content-Type: application/xml');
1040 $aTemplateKeys = array
1042 'ch_repeat:points' => $aPoints,
1043 'ch_repeat:names' => $aNames,
1046 $this -> _oTemplate -> _bCacheEnable =
false;
1047 echo $this -> _oTemplate -> parseHtmlByName( $this -> aUsedTemplates[
'poll_results_list'], $aTemplateKeys );
1061 $aQuestionsList = array();
1064 $aPoll = $this -> _oDb -> getPollInfo( (
int) $iPollID );
1069 foreach ($aQuestions
as $sValue) {
1071 $aQuestionsList[] = array
1073 'answer' => htmlspecialchars($sValue),
1078 $aQuestionsList[] = array
1080 'answer' =>
_t(
'_Empty' ),
1085 $aTemplateKeys = array
1087 'question' => ( isset($aPoll[0][
'poll_question']) )
1088 ? htmlspecialchars( $aPoll[0][
'poll_question'] )
1091 'ch_repeat:answer_list' => $aQuestionsList,
1094 header(
'Content-Type: application/xml; charset=utf-8');
1095 $this -> _oTemplate -> _bCacheEnable =
false;
1096 echo $this -> _oTemplate -> parseHtmlByName( $this -> aUsedTemplates[
'poll_questions_list'], $aTemplateKeys );
1107 if ( (
int) $iVoteNumber >= 0 ) {
1109 $aPoll = $this -> _oDb -> getPollInfo( (
int) $iPollID );
1113 $aVotes[$iVoteNumber]++;
1115 $iPoll_total_votes = array_sum($aVotes);
1116 $sVotes = implode(
';', $aVotes);
1118 if ( !isset($_COOKIE[
'profile_polls_question_' . $iPollID]) ) {
1119 if ( $this -> _oDb -> setVotes( (
int) $iPollID, $sVotes, $iPoll_total_votes) ) {
1121 $aUrl = parse_url(
$GLOBALS[
'site'][
'url']);
1122 $sPath = isset($aUrl[
'path']) && !
empty($aUrl[
'path']) ? $aUrl[
'path'] :
'/';
1126 $oZ =
new ChWsbAlerts(
'ch_poll',
'answered', $aPoll[0][
'id_profile'], $this -> aPollSettings[
'member_id'], array(
'poll_id' => $iPollID,
'vote' => $iVoteNumber));
1133 header(
'Content-Type: application/xml; charset=utf-8');
1145 $iEntryId = (int)$iEntryId;
1146 if ( !($aDataEntry = $this -> _oDb -> getPollInfo($iEntryId)) ) {
1151 $aDataEntry = array_shift($aDataEntry);
1152 require_once (CH_DIRECTORY_PATH_INC .
"shared_sites.inc.php");
1154 $sEntryUrl = CH_WSB_URL_ROOT . $this -> _oConfig -> getBaseUri()
1155 .
'&action=show_poll_info&id=' . $aDataEntry[
'id_poll'];
1159 $sIconsUrl = str_replace(
'digg.png',
'', $sIconsUrl);
1161 foreach ($aSitesPrepare
as $k => $r) {
1163 'icon' => $sIconsUrl . $r[
'icon'],
1169 $aVarsContent = array (
1170 'ch_repeat:sites' => $aSites,
1172 $aVarsPopup = array (
1173 'title' =>
_t(
'_Share'),
1174 'content' => $this->_oTemplate->parseHtmlByName(
'popup_share.html', $aVarsContent),
1177 header(
'Content-Type: text/html; charset=utf-8');
1178 echo
$GLOBALS[
'oFunctions']->transBox($this->_oTemplate->parseHtmlByName(
'popup.html', $aVarsPopup),
true);
1192 $aTemplateKeys = array(
1193 'answer' =>
$bResult ?
'ok' :
_t(
'_Error Occured'),
1196 header(
'Content-Type: application/xml');
1197 $this -> _oTemplate -> _bCacheEnable =
false;
1198 echo $this -> _oTemplate -> parseHtmlByName( $this -> aUsedTemplates[
'server_answer'], $aTemplateKeys );
1210 $aPollInfo = $this -> _oDb -> getPollInfo( (
int)
$iPollId );
1211 $aPoll = array_shift($aPollInfo);
1213 header(
'Content-Type: application/xml; charset=utf-8');
1230 $_page[
'css_name'] =
'main.css';
1250 $oCalendar =
new ChPollCalendar($iYear, $iMonth, $this->_oDb, $this->_oTemplate, $this->_oConfig);
1251 $sCode = $oCalendar->display();
1252 $this->_oTemplate->pageCode($this->aPageTmpl, array(
'page_main_code' =>
$sCode));
1264 $oCateg =
new ChTemplCategoriesModule($aParam,
'', CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() .
'categories');
1265 $sCode = $oCateg->getCode();
1266 $this -> _oTemplate -> defaultPage(
_t(
'_ch_poll_categories'),
$sCode);
1278 $sExtraParam =
'tag/' . urlencode($sTag);
1280 $this -> _oTemplate -> addCss(
'main.css');
1281 echo $this -> _oTemplate -> defaultPage(
_t(
'_ch_poll_view_tag')
1282 , $this ->
searchTags($sProccessed, $sExtraParam ) );
1296 'type' =>
'ch_poll',
1297 'pagination' => ( isset(
$_GET[
'per_page']) )
1298 ? (
int)
$_GET[
'per_page']
1302 $oTags =
new ChTemplTagsModule($aParam,
'', CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() .
'tags');
1303 $sCode = $oTags->getCode();
1304 $this -> _oTemplate -> defaultPage(
_t(
'_ch_poll_tags'),
$sCode);
1314 $aPollsList = array();
1317 ? (
int)
$_GET[
'page']
1321 ? (
int)
$_GET[
'per_page']
1337 if ( isset($_POST[
'poll_id'])
and is_array($_POST[
'poll_id']) ) {
1338 foreach($_POST[
'poll_id']
as $iKey => $iValue ) {
1339 $iValue = (int) $iValue;
1342 if (isset($_POST[
'approve']) || isset($_POST[
'disapprove']))
1344 $this -> _oDb -> setOption($iValue);
1345 }
else if( isset($_POST[
'delete']))
1348 }
else if(isset($_POST[
'featured']) || isset($_POST[
'unfeatured']))
1349 $this -> _oDb -> setOption($iValue,
'featured');
1355 $oCateg->reparseObjTags(
'ch_poll', $iValue);
1359 $aLanguageKeys = array
1361 'premoderation' =>
_t(
'_ch_poll_moderation'),
1362 'select_all' =>
_t(
'_ch_poll_select_all'),
1363 'approve' =>
_t(
'_ch_poll_approve'),
1364 'disapprove' =>
_t(
'_ch_poll_disapprove'),
1366 'delete' =>
_t(
'_ch_poll_delete'),
1367 'sure' =>
_t(
'_Are_you_sure'),
1368 'featured' =>
_t(
'_ch_poll_featured'),
1369 'unfeatured' =>
_t(
'_ch_poll_unfeatured'),
1373 $iTotalNum = $this -> _oDb -> getPollsCount(0,
true);
1379 $sqlLimit =
"LIMIT {$sLimitFrom}, {$iPerPage}";
1381 $aPolls = $this->_oDb -> getAllPolls($sqlLimit, 0,
true);
1382 foreach($aPolls
as $iKey => $aItems)
1383 $aPollsList[] = array (
1384 'poll' => $this->
getPollBlock($aItems,
false,
false,
true),
1391 $sRequest = $this -> sPathToModule .
'administration&page={page}&per_page={per_page}';
1396 'page_url' => $sRequest,
1404 $sPagination = $oPaginate -> getPaginate();
1408 'approve' => $aLanguageKeys[
'approve'],
1409 'disapprove' => $aLanguageKeys[
'disapprove'],
1410 'featured' => $aLanguageKeys[
'featured'],
1411 'unfeatured' => $aLanguageKeys[
'unfeatured'],
1416 'value' => $aLanguageKeys[
'delete'],
1417 'onclick' =>
'onclick="return confirm(\'' . $aLanguageKeys[
'sure'] .
'\')
"',
1421 $sButtons = $oNewSearchresult -> showAdminActionsPanel('poll_form', $aButtons, 'poll_id');
1423 if (isset($GLOBALS['oAdmTemplate'])) {
1424 $GLOBALS['oAdmTemplate']->addDynamicLocation($this->_oConfig->getHomePath(), $this->_oConfig->getHomeUrl());
1425 $GLOBALS['oAdmTemplate'] -> addCss('main.css');
1428 // generate template ;
1429 $aTemplateKeys = array (
1430 'action' => $this -> sPathToModule . 'administration&page=' . $iPage . '&per_page=' . $iPerPage,
1432 'init_js' => $sInitPart,
1433 'js_file' => $this -> _oTemplate -> addJs( 'profile_poll.js', true ),
1435 'ch_repeat:polls' => $aPollsList,
1436 'pagination' => $sPagination,
1437 'admin_panel' => $sButtons,
1440 $sOutputHtml .= $this -> _oTemplate -> parseHtmlByName( $this -> aUsedTemplates['poll_premoderation'], $aTemplateKeys );
1442 $sOutputHtml = '<div id="pol_container
">' . $sOutputHtml . '</div>';
1443 return $sOutputHtml;
1451 function actionAdministration()
1453 $GLOBALS['iAdminPage'] = 1;
1456 header('location: ' . CH_WSB_URL_ROOT);
1459 $aLanguageKeys = array(
1460 'premoderation' => _t('_ch_poll_tags_premoderation'),
1464 'ch_poll_main' => array('title' => _t('_ch_poll_main'), 'href' => $this -> sPathToModule . 'administration&action=main'),
1465 'ch_poll_settings' => array('title' => _t('_ch_poll_settings'), 'href' => $this -> sPathToModule . 'administration&action=settings'),
1468 $sAction = ( isset($_GET['action']) ) ? $_GET['action'] : null;
1472 $aMenu['ch_poll_main']['active'] = 1;
1473 $sContent = $this -> getAdminForm();
1476 $aMenu['ch_poll_settings']['active'] = 1;
1477 $sContent = $this -> getSettingsForm();
1480 $aMenu['ch_poll_main']['active'] = 1;
1481 $sContent = $this -> getAdminForm();
1484 $this -> _oTemplate-> pageCodeAdminStart();
1485 echo $this -> _oTemplate -> adminBlock ($sContent, $aLanguageKeys['premoderation'], $aMenu);
1486 $this -> _oTemplate->pageCodeAdmin( _t('_ch_poll_module') );
1494 function actionSetOption($iPollId, $sAction = 'approval')
1496 $iPollId = (int)$iPollId;
1499 $iActionerId = getLoggedId();
1500 $sJQueryJS = genAjaxyPopupJS($iPollId);
1501 if (isAdmin($iActionerId) || isModerator($iActionerId))
1503 if (!$this->_oDb ->setOption($iPollId, $sAction))
1509 $sMsg = '_Access denied';
1510 header('Content-Type: text/html; charset=UTF-8');
1511 echo MsgBox(_t($sMsg)) . $sJQueryJS;
1520 function getSettingsForm()
1522 $iId = $this-> _oDb -> getSettingsCategory('enable_poll');
1524 return MsgBox( _t('_Empty') );
1527 ch_import('ChWsbAdminSettings');
1530 if(isset($_POST['save']) && isset($_POST['cat'])) {
1531 $oSettings = new ChWsbAdminSettings($iId);
1532 $mixedResult = $oSettings -> saveChanges($_POST);
1535 $oSettings = new ChWsbAdminSettings($iId);
1536 $sResult = $oSettings->getForm();
1538 if($mixedResult !== true && !empty($mixedResult))
1539 $sResult = $mixedResult . $sResult;
1541 return $GLOBALS['oAdmTemplate']
1542 -> parseHtmlByName( 'design_box_content.html', array('content' => $sResult) );
1553 function searchTags($sTag, $sExtraParam = '', $bUseInitPart = true)
1559 $sOutputCode = $this -> getInitPollPage();
1562 $this -> oSearch -> aCurrent['restriction']['tag']['value'] = $sTag;
1564 !$sExtraParam ? $sExtraParam = '&tag=' . urlencode( title2uri($sTag) ) : '';
1565 $sOutputCode .= $this
1566 -> showSearchResult( _t('_ch_poll_browse_tag') . ': ' . htmlspecialchars_adv($sTag), $sExtraParam );
1568 return $sOutputCode;
1579 function searchCategories($sCategory, $sExtraParam = null, $bUseInitPart = true)
1581 $sOutputCode = null;
1585 $sOutputCode = $this -> getInitPollPage();
1588 $this -> oSearch -> aCurrent['restriction']['category']['value'] = $sCategory;
1589 $sExtraParam .= '&category=' . urlencode( title2uri($sCategory) );
1590 $sOutputCode .= $this -> showSearchResult( _t('_ch_poll_browse_category')
1591 . ': ' . htmlspecialchars_adv($sCategory), $sExtraParam );
1593 return $sOutputCode;
1602 function searchFeatured($bUseInitPart = true, $iLimit = 0)
1604 $sOutputCode = null;
1608 $sOutputCode = $this -> getInitPollPage();
1611 $this -> oSearch -> aCurrent['restriction']['featured']['value'] = '1';
1612 $sOutputCode .= $this -> showSearchResult( _t('_ch_poll_featured') );
1614 return $sOutputCode;
1623 function searchFeaturedHome($bUseInitPart = true)
1625 $sOutputCode = null;
1629 $sOutputCode = $this -> getInitPollPage();
1632 $this -> oSearch -> aCurrent['restriction']['featured']['value'] = '1';
1633 $this -> oSearch -> aCurrent['paginate']['perPage'] = 1;
1635 $sOutputCode .= $this -> showSearchResult( _t('_ch_poll_featured'), null, 0, false, 1);
1637 return $sOutputCode;
1646 function searchPopular($bUseInitPart = true)
1648 $sOutputCode = null;
1652 $sOutputCode = $this -> getInitPollPage();
1655 $this -> oSearch -> aCurrent['sorting'] = 'popular';
1656 $sOutputCode .= $this -> showSearchResult( _t('_ch_poll_popular') );
1658 return $sOutputCode;
1667 function searchMy($bUseInitPart = true)
1669 $sOutputCode = null;
1670 $sMemberPanel = $this -> genMemberAdministration();
1674 $sOutputCode = $this -> getInitPollPage();
1677 $this -> oSearch -> aCurrent['restriction']['my']['value'] = $this -> aPollSettings['member_id'];
1678 $this -> oSearch -> aCurrent['restriction']['activeStatus']['value'] = '';
1680 if($this->aPollSettings['mode'] != 'manage' && $this->aPollSettings['mode'] != 'pending')
1681 $sOutputCode .= $this -> showSearchResult( _t('_ch_poll_my') );
1683 return $sMemberPanel . $sOutputCode;
1694 function searchAll($iLimit = 0, $iPerLine = 0, $bUseInitPart = true, $sCaption = null, $bShowEmptyMsg = true)
1696 $sOutputCode = null;
1698 $this -> oSearch -> aCurrent['restriction']['unfeatured']['value'] = 0;
1702 $sOutputCode = $this -> getInitPollPage();
1705 $sPageCaption = $sCaption ? _t($sCaption) : _t('_ch_poll_latest');
1707 $sOutputCode .= $this -> showSearchResult( $sPageCaption
1708 , null, ($iLimit) ? $iLimit : 0, ($iLimit) ? false : true, $iPerLine, true, $bShowEmptyMsg);
1710 return $sOutputCode;
1720 function searchProfilePolls($iProfileId, $iLimit = 6, $bUseInitPart = true, $bShowEmptyMsg = true)
1722 $sOutputCode = null;
1726 $sOutputCode = $this -> getInitPollPage();
1728 $this -> oSearch -> aCurrent['restriction']['my']['value'] = $iProfileId;
1729 $sOutputCode .= $this -> showSearchResult( _t('_ch_polls_profile'), null, $iLimit, false, 1, true, $bShowEmptyMsg );
1731 return $sOutputCode;
1743 function searchAllProfilePolls($iProfileId, $iLimit = 0, $iPerLine = 0, $bUseInitPart = true)
1745 $sOutputCode = null;
1747 $this -> oSearch -> aCurrent['restriction']['my']['value'] = $iProfileId;
1751 $sOutputCode = $this -> getInitPollPage();
1754 $sNickName = isset($_GET['nickname']) ? $_GET['nickname'] : null;
1755 $sExtraParam = '&nickname=' . $sNickName;
1757 $this -> oSearch -> aCurrent['sorting'] = 'popular';
1758 $sOutputCode .= $this -> showSearchResult( _t('_ch_poll_popular'), $sExtraParam );
1760 return $sOutputCode;
1773 function searchByDate($sCaption, $iYear, $iMonth, $iDay, $bUseInitPart = true)
1775 $sOutputCode = null;
1779 $sOutputCode = $this -> getInitPollPage();
1782 $oCalendar = new ChPollCalendar($iYear, $iMonth, $this->_oDb, $this->_oTemplate, $this->_oConfig);
1784 $iYear = (int) $iYear;
1785 $iMonth = (int) $iMonth;
1786 $iDay = (int) $iDay;
1787 $iNextDay = $iDay + 1;
1789 $this -> oSearch -> aCurrent['restriction']['calendar-min']['value'] = "UNIX_TIMESTAMP(
'{$iYear}-{$iMonth}-{$iDay}')
";
1790 $this -> oSearch -> aCurrent['restriction']['calendar-max']['value'] = "UNIX_TIMESTAMP(
'{$iYear}-{$iMonth}-{$iNextDay}')-1
";
1792 $sExtraParam = $oCalendar -> sActionViewResult . "{$iYear}/{$iMonth}/{$iDay}
";
1793 $sOutputCode .= $this -> showSearchResult( $sCaption, $sExtraParam );
1795 return $sOutputCode;
1808 function showSearchResult($sBlockCaption, $sExtraParam = null, $iPerPage = 5, $bShowPagination = true, $iPerLine = 0, $bUseDesignBox = true, $bShowEmptyMsg = true)
1810 $sOutputCode = $sPaginate = '';
1812 $this -> oSearch -> aCurrent['paginate']['perPage'] = $iPerPage ? $iPerPage : 5;
1813 if(!$bShowPagination)
1814 $this -> oSearch -> aCurrent['paginate']['page'] = 1;
1816 $aPolls = $this -> oSearch -> getSearchData();
1818 //process recived data;
1819 if( $aPolls && is_array($aPolls) ) {
1820 $sOutputCode = $this -> genPollsList($aPolls);
1822 if(!empty($sOutputCode))
1823 $sOutputCode = $this->_oTemplate->parseHtmlByName('default_margin.html', array(
1824 'content' => $sOutputCode
1827 if($bShowPagination)
1828 $sPaginate = $this -> oSearch -> showPagination(array('module_path' => $this -> sPathToModule . $sExtraParam));
1830 $sOutputCode = $bShowEmptyMsg ? MsgBox( _t('_Empty') ) : '';
1832 return ($bUseDesignBox && $sOutputCode) ? DesignBoxContent($sBlockCaption, $sOutputCode, 1, '', $sPaginate) : $sOutputCode . $sPaginate;
1847 function createPoll($sPollQuestion, $sPollAnswers, $sPollResults, $sTags, $iCommentGroupValue, $iVoteGroupValue, $sCategory, $iViewGroupValue)
1849 // check membership;
1850 if(!$this -> isPollCreateAlowed($this -> aPollSettings['member_id'], true) ) {
1854 // ** init some needed variables ;
1855 $aPoolInfo = array();
1857 if ( !$sPollQuestion or !$sPollAnswers ) {
1858 $this -> sActionAnswer = MsgBox(POLL_EMPTY_FIELDS);
1862 'owner_id' => $this -> aPollSettings['member_id'],
1863 'question' => $sPollQuestion,
1864 'answers' => $sPollAnswers,
1865 'results' => $sPollResults,
1867 'allow_comment' => $iCommentGroupValue,
1868 'allow_vote' => $iVoteGroupValue,
1869 'category' => $sCategory,
1870 'allow_view' => $iViewGroupValue
1873 $iResponse = $this -> _oDb -> createPoll($aPoolInfo, $this -> aPollSettings['admin_mode']);
1874 $iLastPoll = $this -> _oDb -> lastId();
1876 // define the action number ;
1877 switch($iResponse) {
1879 $this -> sActionAnswer = MsgBox(POLL_NOT_ALLOW);
1883 $this -> sActionAnswer = MsgBox(POLL_CREATED);
1884 // create system event
1885 $oZ = new ChWsbAlerts('ch_poll', 'add', $iLastPoll);
1888 $oTag = new ChWsbTags();
1889 $oTag -> reparseObjTags('ch_poll', $iLastPoll);
1891 $oCateg = new ChWsbCategories();
1892 $oCateg->reparseObjTags('ch_poll', $iLastPoll);
1896 $this -> sActionAnswer = MsgBox(POLL_MAX_REACHED);
1912 function editPoll($iPollId, $sPollQuestion, $sPollAnswers, $sCategory, $bActive = true, $bApprove = false, $sTags = null, $iCommentGroupValue = 3, $iVoteGroupValue = 3, $iViewGroupValue = 3)
1914 if ( !$sPollQuestion or !$sPollAnswers ) {
1915 $this -> sActionAnswer = MsgBox(POLL_EMPTY_FIELDS);
1917 // check poll's owner Id;
1918 $aPoolInfo = $this -> _oDb -> getPollInfo( $iPollId );
1920 if ( $this -> aPollSettings['admin_mode']
1921 or ( $this -> aPollSettings['member_id']
1922 and $aPoolInfo[0]['id_profile'] == $this -> aPollSettings['member_id']) ) {
1926 'question' => $sPollQuestion,
1927 'answers' => $sPollAnswers,
1928 'status' => ( $bActive ) ? 'active' : null,
1931 'allow_comment' => $iCommentGroupValue,
1932 'allow_vote' => $iVoteGroupValue,
1933 'category' => $sCategory,
1934 'allow_view' => $iViewGroupValue,
1937 if ( $this -> aPollSettings['admin_mode'] ) {
1938 $aPoolInfo['approve'] = ( $bApprove ) ? true : false;
1941 $this -> _oDb -> editPoll($aPoolInfo);
1942 $this -> sActionAnswer = MsgBox(POLL_EDITED);
1944 // create system event
1945 $oZ = new ChWsbAlerts('ch_poll', 'edit', $iPollId);
1948 // reparse poll's tags;
1949 $oTag = new ChWsbTags();
1950 $oTag -> reparseObjTags('ch_poll', $iPollId);
1952 $oCateg = new ChWsbCategories();
1953 $oCateg->reparseObjTags('ch_poll', $iPollId);
1955 $this -> sActionAnswer = MsgBox(POLL_NOT_ALLOW);
1960 function deletePoll($iId)
1962 $aPoll = $this->_oDb->getPollInfo($iId);
1963 if(empty($aPoll) || !is_array($aPoll))
1966 $aPoll = array_shift($aPoll);
1967 if(!isLogged() || (!isAdmin() && $aPoll['id_profile'] != getLoggedId()))
1970 $this->_oDb->deletePoll($iId);
1972 $oTag = new ChWsbTags();
1973 $oTag -> reparseObjTags('ch_poll', $iId);
1975 $oCateg = new ChWsbCategories();
1976 $oCateg->reparseObjTags('ch_poll', $iId);
1978 //delete all subscriptions
1979 $oSubscription = ChWsbSubscription::getInstance();
1980 $oSubscription->unsubscribe(array('type' => 'object_id', 'unit' => 'ch_poll', 'object_id' => $iId));
1982 // create system event
1983 $oZ = new ChWsbAlerts('ch_poll', 'delete_poll', $iId);
1996 function serviceGetPolls($sAction, $iProfileId = 0)
1999 $this -> _oTemplate -> addCss('main.css');
2003 // for profile's page;
2004 case 'get_profile_polls' :
2006 $iRowsLimit = $this -> _oConfig -> iProfilePagePollsCount;
2007 $sOutputCode = $this -> searchProfilePolls($iProfileId, $iRowsLimit, true, false);
2013 $aVis = array(CH_WSB_PG_ALL);
2014 if ($this->getUserId())
2015 $aVis[] = CH_WSB_PG_MEMBERS;
2016 $this -> oSearch -> aCurrent['restriction']['allow_view']['value'] = $aVis;
2017 $iRowsLimit = $this ->_oConfig -> iIndexPagePollsCount;
2018 $sOutputCode = $this -> searchAll($iRowsLimit, 1, true, '_ch_polls_public', false);
2025 function serviceGetMemberMenuLink($iMemberId = false)
2027 if (false === $iMemberId)
2028 $iMemberId = getLoggedId();
2030 $oMemberMenu = ch_instance('ChWsbMemberMenu');
2033 'item_img_src' => 'tasks',
2034 'item_img_alt' => _t( '_ch_polls' ),
2035 'item_link' => $this -> sPathToModule . '&action=my',
2036 'item_title' => _t( '_ch_polls' ),
2037 'extra_info' => count($this -> _oDb -> getAllPolls(null, $iMemberId)), // number of member's polls
2040 return $oMemberMenu -> getGetExtraMenuLink($aLinkInfo);
2043 function serviceGetMemberMenuLinkAddContent($iMemberId = false)
2045 if (false === $iMemberId)
2046 $iMemberId = getLoggedId();
2048 if (!$this -> isPollCreateAlowed($iMemberId))
2051 $oMemberMenu = ch_instance('ChWsbMemberMenu');
2054 'item_img_src' => 'tasks',
2055 'item_img_alt' => _t( '_ch_poll' ),
2056 'item_link' => $this -> sPathToModule . '&action=my&mode=add',
2057 'item_title' => _t( '_ch_poll' ),
2060 return $oMemberMenu -> getGetExtraMenuLink($aLinkInfo);
2066 function serviceEditActionButton($iMemberId, $iPollId)
2070 $aPollInfo = $this -> _oDb -> getPollInfo( (int) $iPollId);
2071 $aPollInfo = array_shift($aPollInfo);
2073 if($aPollInfo['id_profile'] == $iMemberId || isAdmin() ){
2074 $sEditLink = $this -> sPathToModule . '&action=my&mode=edit_poll&edit_poll_id=' . $iPollId;
2083 function serviceDeleteActionButton($iMemberId, $iPollId)
2085 $sDeleteLink = null;
2087 $aPollInfo = $this -> _oDb -> getPollInfo( (int) $iPollId);
2088 $aPollInfo = array_shift($aPollInfo);
2090 if($aPollInfo['id_profile'] == $iMemberId || isAdmin() ){
2091 $sDeleteLink = $this -> sPathToModule . '&action=delete_poll&id=' . $iPollId;
2094 return $sDeleteLink;
2097 function serviceGetSubscriptionParams ($sAction, $iEntryId)
2099 $aDataEntry = $this->_oDb->getPollInfo($iEntryId);
2100 $aDataEntry = array_shift($aDataEntry);
2101 if(empty($aDataEntry) || (int)$aDataEntry['poll_approval'] == 0) {
2102 return array('skip' => true);
2105 $aActionList = array(
2106 'commentPost' => '_ch_poll_sbs_comment'
2109 $sActionName = isset($aActionList[$sAction]) ? ' (' . _t($aActionList[$sAction]) . ')' : '';
2112 'template' => array (
2113 'Subscription' => $aDataEntry['poll_question'] . $sActionName,
2114 'ViewLink' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . '&action=show_poll_info&id=' . $aDataEntry['id_poll'],
2119 function serviceGetWallPost($aEvent)
2121 $aItem = $this->_oDb->getPollInfo((int)$aEvent['object_id']);
2123 return array('perform_delete' => true);
2125 $aItem = array_shift($aItem);
2128 if(!empty($aEvent['owner_id']))
2129 $iOwner = (int)$aEvent['owner_id'];
2132 if(!empty($aEvent['date']))
2133 $iDate = (int)$aEvent['date'];
2135 $bItem = !empty($aItem) && is_array($aItem);
2136 if($iOwner == 0 && $bItem && !empty($aItem['id_profile']))
2137 $iOwner = (int)$aItem['id_profile'];
2139 if($iDate == 0 && $bItem && !empty($aItem['poll_date']))
2140 $iDate = (int)$aItem['poll_date'];
2142 if($iOwner == 0 || !$bItem)
2145 $aProfile = getProfileInfo($iOwner);
2146 if(empty($aProfile) || (int)$aItem['poll_approval'] != 1 || !$this->oPrivacy->check('view', (int)$aEvent['object_id'], getLoggedId()))
2149 $sJs = $sCss = $sInit = '';
2150 $sBaseUrl = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/';
2151 if($aEvent['js_mode']) {
2152 $sJs = $this->_oTemplate->addJs(array('profile_poll.js'), true);
2153 $sCss = $this->_oTemplate->addCss(array('main.css', 'wall_post.css'), true);
2155 $this->_oTemplate->addJs(array('profile_poll.js'));
2156 $this->_oTemplate->addCss(array('main.css', 'wall_post.css'));
2159 $sInit = $this->getInitPollPage();
2160 $sOwner = getNickName($iOwner);
2162 //--- Single public event
2163 $aItem['url'] = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . '&action=show_poll_info&id=' . $aItem['id_poll'];
2165 $sTextWallObject = _t('_ch_poll_wall_object');
2167 'owner_id' => $iOwner,
2168 'title' => _t('_ch_poll_wall_added_new_title', $sOwner, $sTextWallObject),
2169 'description' => $aItem['poll_question'],
2170 'content' => $sJs . $sCss . $sInit . $this->_oTemplate->parseHtmlByName('wall_post.html', array(
2171 'cpt_user_name' => $sOwner,
2172 'cpt_added_new' => _t('_ch_poll_wall_added_new'),
2173 'cpt_object' => $sTextWallObject,
2174 'cpt_item_url' => $aItem['url'],
2175 'cnt_item_page' => $aItem['url'],
2176 'cnt_item_title' => $aItem['poll_question'],
2177 'cnt_item_id' => $aItem['id_poll'],
2178 'post_id' => $aEvent['id'],
2184 function serviceGetWallPostOutline($aEvent)
2186 $aItem = $this->_oDb->getPollInfo((int)$aEvent['object_id']);
2188 return array('perform_delete' => true);
2190 $aItem = array_shift($aItem);
2191 $aProfile = getProfileInfo((int)$aEvent['owner_id']);
2192 if(empty($aProfile) || (int)$aItem['poll_approval'] != 1 || !$this->oPrivacy->check('view', (int)$aEvent['object_id'], getLoggedId()))
2196 $sPrefix = 'ch_' . $this->_oConfig->getUri();
2197 if($aEvent['js_mode'])
2198 $sCss = $this->_oTemplate->addCss('wall_outline.css', true);
2200 $this->_oTemplate->addCss('wall_outline.css');
2202 $iOwner = (int)$aEvent['owner_id'];
2203 $sOwner = getNickName($iOwner);
2204 $sOwnerLink = getProfileLink($iOwner);
2206 //--- Single public event
2207 $aItem['poll_url'] = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . '&action=show_poll_info&id=' . $aItem['id_poll'];
2210 'content' => $sCss . $this->_oTemplate->parseHtmlByName('modules/cheetah/wall/|outline_item_text.html', array(
2211 'mod_prefix' => $sPrefix,
2212 'mod_icon' => 'tasks',
2213 'user_name' => $sOwner,
2214 'user_link' => $sOwnerLink,
2215 'item_page' => $aItem['poll_url'],
2216 'item_title' => $aItem['poll_question'],
2217 'item_description' => $this->_getWallContent($aItem),
2218 'item_comments' => (int)$aItem['poll_comments_count'] > 0 ? _t('_wall_n_comments', $aItem['poll_comments_count']) : _t('_wall_no_comments'),
2219 'item_comments_link' => $aItem['poll_url'] . '#cmta-' . $sPrefix . '-' . $aItem['id'],
2220 'post_id' => $aEvent['id'],
2221 'post_ago' => $aEvent['ago']
2226 function serviceGetWallAddComment($aEvent)
2228 $iId = (int)$aEvent['object_id'];
2229 $iOwner = (int)$aEvent['owner_id'];
2230 $sOwner = $iOwner != 0 ? getNickName($iOwner) : _t('_Anonymous');
2232 $aContent = unserialize($aEvent['content']);
2233 if(empty($aContent) || empty($aContent['object_id']))
2236 $iItem = (int)$aContent['object_id'];
2237 $aItem = $this->_oDb->getPollInfo($iItem);
2238 if(empty($aItem) || !is_array($aItem))
2239 return array('perform_delete' => true);
2241 if(!$this->oPrivacy->check('view', $iItem, getLoggedId()))
2244 ch_import('ChTemplCmtsView');
2245 $oCmts = new ChTemplCmtsView('ch_poll', $iItem);
2246 if(!$oCmts->isEnabled())
2249 $aComment = $oCmts->getCommentRow($iId);
2250 if(empty($aComment) || !is_array($aComment))
2251 return array('perform_delete' => true);
2254 if($aEvent['js_mode'])
2255 $sCss = $this->_oTemplate->addCss('wall_post.css', true);
2257 $this->_oTemplate->addCss('wall_post.css');
2259 $aItem = array_shift($aItem);
2260 $aItem['url'] = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . '&action=show_poll_info&id=' . $aItem['id_poll'];
2262 $sTextWallObject = _t('_ch_poll_wall_object');
2264 'title' => _t('_ch_poll_wall_added_new_title_comment', $sOwner, $sTextWallObject),
2265 'description' => $aComment['cmt_text'],
2266 'content' => $sCss . $this->_oTemplate->parseHtmlByName('wall_post_comment.html', array(
2267 'cpt_user_name' => $sOwner,
2268 'cpt_added_new' => _t('_ch_poll_wall_added_new_comment'),
2269 'cpt_object' => $sTextWallObject,
2270 'cpt_item_url' => $aItem['url'],
2271 'cnt_comment_text' => $aComment['cmt_text'],
2272 'cnt_item_page' => $aItem['url'],
2273 'cnt_item_title' => $aItem['poll_question'],
2274 'cnt_item_description' => $this->_getWallContent($aItem),
2275 'post_id' => $aEvent['id'],
2283 function serviceGetWallPostComment($aEvent)
2285 $iId = (int)$aEvent['object_id'];
2286 $iOwner = (int)$aEvent['owner_id'];
2287 $sOwner = getNickName($iOwner);
2289 $aItem = $this->_oDb->getPollInfo($iId);
2291 return array('perform_delete' => true);
2293 if(!$this->oPrivacy->check('view', $iId, getLoggedId()))
2296 $aContent = unserialize($aEvent['content']);
2297 if(empty($aContent) || !isset($aContent['comment_id']))
2300 ch_import('ChTemplCmtsView');
2301 $oCmts = new ChTemplCmtsView('ch_poll', $iId);
2302 if(!$oCmts->isEnabled())
2305 $aItem = array_shift($aItem);
2306 $aItem['url'] = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . '&action=show_poll_info&id=' . $aItem['id_poll'];
2307 $aComment = $oCmts->getCommentRow((int)$aContent['comment_id']);
2308 if(empty($aComment) || !is_array($aComment))
2309 return array('perform_delete' => true);
2312 if($aEvent['js_mode'])
2313 $sCss = $this->_oTemplate->addCss('wall_post.css', true);
2315 $this->_oTemplate->addCss('wall_post.css');
2317 $sTextWallObject = _t('_ch_poll_wall_object');
2319 'title' => _t('_ch_poll_wall_added_new_title_comment', $sOwner, $sTextWallObject),
2320 'description' => $aComment['cmt_text'],
2321 'content' => $sCss . $this->_oTemplate->parseHtmlByName('wall_post_comment.html', array(
2322 'cpt_user_name' => $sOwner,
2323 'cpt_added_new' => _t('_ch_poll_wall_added_new_comment'),
2324 'cpt_object' => $sTextWallObject,
2325 'cpt_item_url' => $aItem['url'],
2326 'cnt_comment_text' => $aComment['cmt_text'],
2327 'cnt_item_page' => $aItem['url'],
2328 'cnt_item_title' => $aItem['poll_question'],
2329 'cnt_item_description' => $this->_getWallContent($aItem),
2330 'post_id' => $aEvent['id'],
2335 function serviceGetWallData ()
2337 $sUri = $this->_oConfig->getUri();
2338 $aName = 'ch_' . $sUri;
2341 'handlers' => array(
2342 array('alert_unit' => $aName, 'alert_action' => 'add', 'module_uri' => $sUri, 'module_class' => 'Module', 'module_method' => 'get_wall_post', 'groupable' => 0, 'group_by' => '', 'timeline' => 1, 'outline' => 1),
2343 array('alert_unit' => $aName, 'alert_action' => 'comment_add', 'module_uri' => $sUri, 'module_class' => 'Module', 'module_method' => 'get_wall_add_comment', 'groupable' => 0, 'group_by' => '', 'timeline' => 1, 'outline' => 0),
2345 //DEPRICATED, saved for backward compatibility
2346 array('alert_unit' => $aName, 'alert_action' => 'commentPost', 'module_uri' => $sUri, 'module_class' => 'Module', 'module_method' => 'get_wall_post_comment', 'groupable' => 0, 'group_by' => '', 'timeline' => 1, 'outline' => 0)
2349 array('unit' => $aName, 'action' => 'add')
2354 function _getWallContent($aItem, $bAsArray = false)
2356 $aItemAns = explode(CH_POLL_ANS_DIVIDER, trim($aItem['poll_answers'], CH_POLL_ANS_DIVIDER));
2357 $iItemAns = count($aItemAns);
2358 $aItemRes = explode(CH_POLL_RES_DIVIDER, trim($aItem['poll_results'], CH_POLL_RES_DIVIDER));
2359 $iItemTotal = (int)$aItem['poll_total_votes'];
2362 for($i = 0; $i < $iItemAns; $i++)
2363 if(!empty($aItemAns[$i]))
2365 'answer' => $aItemAns[$i],
2366 'result' => round(($iItemTotal != 0 ? 100 * ($aItemRes[$i] / $iItemTotal) : 0), 1)
2369 return $bAsArray ? $aResult : $this->_oTemplate->parseHtmlByName('poll_answers.html', array('ch_repeat:items' => $aResult));
2372 function serviceGetSpyData ()
2375 'handlers' => array(
2376 array('alert_unit' => 'ch_poll', 'alert_action' => 'add', 'module_uri' => 'poll', 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
2377 array('alert_unit' => 'ch_poll', 'alert_action' => 'answered', 'module_uri' => 'poll', 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
2378 array('alert_unit' => 'ch_poll', 'alert_action' => 'rate', 'module_uri' => 'poll', 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
2379 array('alert_unit' => 'ch_poll', 'alert_action' => 'commentPost', 'module_uri' => 'poll', 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
2382 array('unit' => 'ch_poll', 'action' => 'add'),
2383 array('unit' => 'ch_poll', 'action' => 'answered'),
2384 array('unit' => 'ch_poll', 'action' => 'rate'),
2385 array('unit' => 'ch_poll', 'action' => 'delete_poll'),
2386 array('unit' => 'ch_poll', 'action' => 'commentPost'),
2387 array('unit' => 'ch_poll', 'action' => 'commentRemoved')
2397 function serviceGetSpyPost($sAction, $iObjectId = 0, $iSenderId = 0, $aExtraParams = array())
2403 // define some poll's data for rendering;
2404 $sNickName = getNickName($iSenderId);
2405 $sProfileLink = getProfileLink($iSenderId);
2407 $aPollInfo = $this -> _oDb -> getPollInfo($iObjectId);
2408 $sPollCaption = $aPollInfo[0]['poll_question'];
2409 $sPollLink = $this -> sPathToModule . '&action=show_poll_info&id=' . $iObjectId;
2412 'lang_key' => '_ch_poll_added',
2414 'profile_link' => $sProfileLink,
2415 'profile_nick' => $sNickName,
2416 'poll_url' => $sPollLink,
2417 'poll_caption' => $sPollCaption,
2419 'recipient_id' => 0,
2424 $aRet = $this -> _getSpyArray($aExtraParams['poll_id'], $iSenderId, '_ch_poll_answered', 'content_activity', $iObjectId);
2428 $aRet = $this -> _getSpyArray($iObjectId, $iSenderId, '_ch_poll_rated');
2431 case 'commentPost' :
2432 $aRet = $this -> _getSpyArray($iObjectId, $iSenderId, '_ch_poll_commented');
2447 function _getSpyArray($iObjectId, $iSenderId, $sLangKey, $sActivityType = 'content_activity', $iRecipientId = 0)
2451 // try define the poll's owner;
2452 $aPollInfo = array_shift( $this -> _oDb -> getPollInfo($iObjectId) );
2453 if( isset($aPollInfo['id_profile']) ) {
2454 $sRecipientNickName = getNickName($aPollInfo['id_profile']);
2455 $sRecipientProfileLink = getProfileLink($aPollInfo['id_profile']);
2456 $sSenderNickName = $iSenderId ? getNickName($iSenderId) : _t('_Guest');
2457 $sSenderProfileLink = $iSenderId ? getProfileLink($iSenderId) : 'javascript:void(0)';
2458 $sPollLink = $this -> sPathToModule . '&action=show_poll_info&id=' . $aPollInfo['id_poll'];
2461 'lang_key' => $sLangKey,
2463 'recipient_p_link' => $sRecipientProfileLink,
2464 'recipient_p_nick' => $sRecipientNickName,
2465 'profile_nick' => $sSenderNickName,
2466 'profile_link' => $sSenderProfileLink,
2467 'poll_link' => $sPollLink,
2469 'recipient_id' => ($iRecipientId) ? $iRecipientId : $aPollInfo['id_profile'],
2470 'spy_type' => $sActivityType,
2484 function genPollsList(&$aActivePolls)
2489 foreach($aActivePolls as $iKey => $aItems) {
2490 $aItems['poll_ago'] = $iNow - (int)$aItems['poll_date'];
2491 $sOutputCode .= $this->getPollBlock($aItems);
2494 return '<div id="pol_container
">' . $sOutputCode . '</div>';
2503 function isPollCreateAlowed($iMemberId = false, $isPerformAction = false)
2505 if (false === $iMemberId)
2506 $iMemberId = getLoggedId();
2507 $this -> _defineActions();
2508 $aCheck = checkAction($iMemberId, CH_CREATE_POLLS, $isPerformAction);
2509 return $aCheck[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
2512 function isAllowedShare(&$aDataEntry)
2514 if($aDataEntry['allow_view_to'] != CH_WSB_PG_ALL)
2520 function _defineActions()
2522 defineMembershipActions( array('create polls') );