>
------------------------------------------------------------------------------
See main.inc.php for release information
MyPolls_PIP : classe to manage plugin public pages
--------------------------------------------------------------------------- */
include_once('mypolls_root.class.inc.php');
include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/public_integration.class.inc.php');
class MyPolls_PIP extends MyPolls_root
{
protected $section_page;
public function MyPolls_PIP($prefixeTable, $filelocation)
{
parent::__construct($prefixeTable, $filelocation);
$this->load_config();
// don't create this object inside root classe otherwise header is modified
// everywhere in admin pages
$this->ajax = new Ajax();
$this->section_page = new public_integration($this->section_name);
$this->init_events();
}
/*
load language file
*/
public function load_lang()
{
global $lang;
load_language('plugin.lang', MYPOLLS_PATH);
// ajax is managed here ; this permit to use user&language properties inside
// ajax content
$this->return_ajax_content();
}
/*
initialize events call for the plugin
*/
public function init_events()
{
parent::init_events();
$this->section_page->set_callback_page_function(array(&$this, 'manage_page'));
$this->section_page->init_events();
add_event_handler('blockmanager_apply', array(&$this, 'blockmanager_apply') );
add_event_handler('loading_lang', array(&$this, 'load_lang'));
add_event_handler('loc_end_page_header', array(&$this->css, 'apply_CSS'));
}
/* -------------------------------------------------------------------------
FUNCTIONS TO MANAGE POLL'S DISPLAY
------------------------------------------------------------------------- */
/*
display mypolls page ; no parameters, all is in $_REQUEST
this function is a called by a menubar's callback only when it is necessary
*/
protected function display_page($poll_id)
{
global $template, $user;
$poll_values=$this->get_poll_values($poll_id, $user['language']);
if(!$poll_values)
{
page_not_found('This page does not exist', 'index.php?');
return(false);
}
$users = new users($poll_values['allowed_users']);
$groups = new groups($poll_values['allowed_groups']);
$datas = array();
$user_groups=$this->get_user_groups($user['id']);
//looks if user/group is allowed to access page
if((!$users->is_allowed($user['status']) ||
(($poll_values['allowed_groups']!='') && !$groups->are_allowed($user_groups))) &&
!is_admin())
{
page_not_found('User not allowed', 'index.php?');
}
if($user['id']!=2)
{
$datas['GENERIC_TEXT']=$this->my_config['mypolls_generic_text_users'][$user['language']];
}
else
{
$datas['GENERIC_TEXT']=$this->my_config['mypolls_generic_text_guests'][$user['language']];
}
$datas['TITLE']=$poll_values['title'];
//displayed nfo even if results are not public
$datas['DESCRIPTION']=html_entity_decode($poll_values['description'], ENT_QUOTES);
if(!$this->get_user_already_vote($poll_id, $user['id'], $_SERVER['REMOTE_ADDR']))
{
// no vote for this poll by user, display poll in 'vote' mode
//count visit on page
$this->count_visit($poll_id, 'before');
$first_question=array('mono' => 0, 'multi' => 1);
$template_file=dirname($this->filelocation).'/templates/mypolls_public_question.tpl';
$datas['ATT_ID']=$poll_id;
$datas['AJAX_URL_POLL_DETAIL']='./index.php?/'.$this->section_name.'/'.$poll_id.'&ajaxfct=poll_question_blocks';
$datas['LANG']=$user['language'];
$datas['FIRST_QUESTION']=$first_question[$poll_values['display_type']];
$datas['NBQUESTIONS']=$poll_values['nb_questions'];
}
else
{
//user/ip have already voted
$template_file=dirname($this->filelocation).'/templates/mypolls_public_results.tpl';
$datas['AFTER_VOTE_TEXT']=html_entity_decode($poll_values['after_vote_text'], ENT_QUOTES);
if($poll_values['public_results']=='n')
{
$not_public_text=html_entity_decode($this->my_config['mypolls_not_public_results'][$user['language']]);
if($not_public_text=="")
{
$not_public_text=l10n('mypolls_not_public_results');
}
$datas['NOT_PUBLIC_RESULT_TEXT']=$not_public_text;
}
else
{
if($poll_values['show_comments']=='y')
{
$datas["AJAX_URL_POLL_COMMENT_LIST"]='./index.php?/'.$this->section_name.'/'.$poll_id.'&ajaxfct=poll_comment_list&vpage=';
}
$this->display_results_block($poll_id, $user['language'], $poll_values);
}
//count visit on page
$this->count_visit($poll_id, 'after');
}
$template->set_filename('body_page', $template_file);
$template->assign('TITLE', $datas['TITLE']);
$template->assign('datas', $datas);
// add icon in title bar
if (is_admin())
{
$this->make_icons(PHPWG_ROOT_PATH.$this->page_link."&f_tabsheet=polls&action=modify&fmypolls_att_id=".$poll_id, 'mypolls_msg_modify_poll','preferences.png', 'edit', 'icon_category_edit');
}
$this->make_icons(make_index_url(),'return to homepage', 'home.png', 'home', 'icon_home');
//remote icons from the title bar
unset($template->smarty->_tpl_vars["U_MODE_CREATED"]);
unset($template->smarty->_tpl_vars["U_MODE_POSTED"]);
$template->assign_var_from_handle('PLUGIN_INDEX_CONTENT_BEGIN', 'body_page');
}
protected function make_icons($url, $title, $icon, $alt, $id="")
{
global $template;
//method to make icon change with template
// assume yoga method by default
switch($template->smarty->_tpl_vars["themeconf"]['template'])
{
case 'gally':
$template->concat( 'PLUGIN_INDEX_ACTIONS',
'