# ================================================================== # Plugins::GForum::Poll - Auto Generated Install Module # # Plugins::GForum::Poll # Author : Ivan Herger # Version : 1.0.9 # Updated : 25-Mar-2003 # # ================================================================== # package Plugins::GForum::Poll; # ================================================================== use strict; use vars qw/$VERSION $DEBUG $NAME $META/; use GT::Base; use GT::Plugins qw/STOP CONTINUE/; use GForum qw/$IN $DB $CFG/; $VERSION = '1.0.9'; $DEBUG = 0; $NAME = 'Poll'; # Inhert from base class for debug and error methods @Plugins::GForum::Poll::ISA = qw(GT::Base); $META = { 'prog_ver' => '1.1.4', 'url' => 'http://www.iyengar-yoga.com/', 'license' => 'Freeware', 'description' => 'This plugin allows you to hold polls in your forum.', 'author' => 'Ivan Herger', 'version' => '1.0.9' }; sub pre_install { # ------------------------------------------------------------------- # This function displays an HTML formatted message that will display # to the user any instructions/information before they install # the plugin. # my $inst_msg = qq~

The Poll plugin allows you to hold polls in your forum.

~; return $inst_msg; } sub pre_uninstall { # ------------------------------------------------------------------- # This function displays an HTML formatted message that will display # to the user any instructions/information before they remove the # plugin. # my $uninst_msg = qq~

The Poll plugin will be uninstalled. No Poll data will be deleted!

~; return $uninst_msg; } sub install { # ------------------------------------------------------------------- # This function does the actual installation. It's first argument is # a plugin manager which you can use to register hooks, install files, # add menu options, etc. The second argument is a GT::Tar object which # you can use to access any files in your plugin module. # # You should return an HTML formatted string that will be displayed # to the user. # # If there is an error, return undef, and set the error message in # $Plugins::GForum::Poll::error # my ($mgr, $tar) = @_; # Create the Poll table. my $p = $DB->creator ('Poll'); $p->cols([ poll_id => { type => 'INT', not_null => 1 }, post_id_fk => { type => 'INT', not_null => 1 }, forum_id_fk => { type => 'INT', not_null => 1 }, poll_question => { type => 'VARCHAR', size => '255', not_null => 1 }, poll_type => { type => 'TINYINT', default => '1', not_null => '1' }, poll_votes => { type => 'INT', not_null => 1 }, poll_enabled => { default => '1', type => 'TINYINT', not_null => 1 } ]); $p->pk('poll_id'); $p->ai('poll_id'); $p->fk({ Post => { post_id_fk => 'post_id' } }); $p->index({p_p => ['post_id_fk']}); if (!$p->create and $GT::SQL::errcode eq 'TBLEXISTS') { $p->set_defaults(); $p->save_schema(); } # Create the PollAnswer table my $a = $DB->creator ('PollAnswer'); $a->cols([ poll_answer_id => { type => 'INT', not_null => 1 }, poll_id_fk => { type => 'INT', not_null => 1 }, post_id_fk => { type => 'INT', not_null => 1 }, poll_answer_answer => { type => 'VARCHAR', size => '255', not_null => 1, default => 0 }, poll_answer_votes => { type => 'INT', not_null => 1, default => 0 } ]); $a->pk('poll_answer_id'); $a->ai('poll_answer_id'); $a->fk({ Poll => { poll_id_fk => 'poll_id' }, Post => { post_id_fk => 'post_id' } }); $a->index({ a_ps => ['post_id_fk'], a_pl => ['poll_id_fk'] } ); if (!$a->create and $GT::SQL::errcode eq 'TBLEXISTS') { $a->set_defaults(); $a->save_schema(); } # Create the PollVote table my $v = $DB->creator ('PollVote'); $v->cols([ poll_vote_id => { type => 'INT', not_null => 1 }, poll_id_fk => { type => 'INT', not_null => 1 }, post_id_fk => { type => 'INT', not_null => 1 }, user_id_fk => { type => 'INT', not_null => 0, }, poll_vote_ip => { type => 'VARCHAR', size => '15', not_null => 1, }, poll_vote_time => { type => 'INT', default => '0', not_null => '1' } ]); $v->pk('poll_vote_id'); $v->ai('poll_vote_id'); $v->fk ( { 'Poll' => { 'poll_id_fk' => 'poll_id' }, 'Post' => { 'post_id_fk' => 'post_id' }, 'User' => { 'user_id_fk' => 'user_id' } }); $v->index({ v_p => ['poll_id_fk'], user_poll => ['user_id_fk','poll_id_fk'], guest_poll => ['poll_vote_ip','poll_id_fk','user_id_fk'] }); if (!$v->create and $GT::SQL::errcode eq 'TBLEXISTS') { $v->set_defaults(); $v->save_schema(); } # Create the PollGroup table my $g = $DB->creator ('PollGroup'); $g->cols([ poll_group_id => { type => 'INT', not_null => 1 , form_display => 'PollGroup ID', form_size => '2', form_type => 'HIDDEN' }, forum_id_fk => { type => 'INT', not_null => 1, form_display => 'Forum ID', form_size => '2', form_type => 'INT' }, group_id_fk => { type => 'INT', not_null => 1, form_display => 'Group ID', form_size => '2', form_type => 'INT' }, poll_perms => { type => 'TINYINT', size => '3', not_null => 1, form_display => 'Poll Permissions', form_type => 'SELECT', form_values => ['None','Vote','Write','Edit'], form_names => ['0','1','2','3'] } ]); $g->pk('poll_group_id'); $g->ai('poll_group_id'); $g->fk ( { 'Forum' => { 'forum_id_fk' => 'forum_id' }, 'Grouping' => { 'group_id_fk' => 'group_id' } }); $g->index => { 'v_p' => ['poll_perms'] }; if (!$g->create and $GT::SQL::errcode eq 'TBLEXISTS') { $g->set_defaults(); $g->save_schema(); } # Add "post_is_poll" column to Post table my $editor = $DB->editor ('Post'); $editor->add_col ('post_is_poll', { form_display => 'Post contains a Poll', form_size => '2', form_type => 'INT', not_null => '1', default => '0', size => 3, type => 'TINYINT' }); # define new actions $CFG->{functions}->{poll_vote} = { action => 'function', customizable => { description => '1', page => '1', min_user_status => '1', user_groups => '1' }, description => 'Voting', function => 'Plugins::GForum::Poll::vote', hidden => '1', }; $CFG->{functions}->{poll_more_options} = { action => 'function', customizable => { description => '1', page => '1', min_user_status => '1', user_groups => '1' }, description => 'Display More Options for Polls', function => 'Plugins::GForum::Poll::more_options', hidden => '1', }; $CFG->{functions}->{poll_disable} = { action => 'function', customizable => { description => '1', page => '1', min_user_status => '1', user_groups => '1' }, description => 'Disabling Poll Voting', function => 'Plugins::GForum::Poll::disable', hidden => '1', page => { no_such_post => 'error.html', no_such_poll => 'error.html', poll_already_disabled => 'error.html', disabled => 'poll_disable.html' } }; $CFG->{functions}->{poll_enable} = { action => 'function', customizable => { description => '1', page => '1', min_user_status => '1', user_groups => '1' }, description => 'Enabling Poll Voting', function => 'Plugins::GForum::Poll::enable', hidden => '1', page => { no_such_post => 'error.html', no_such_poll => 'error.html', poll_already_enabled => 'error.html', enabled => 'poll_disable.html' } }; $CFG->{functions}->{poll_ssi} = { action => 'function', customizable => { description => '1', page => '1', min_user_status => '1', user_groups => '1' }, description => 'Voting', function => 'Plugins::GForum::Poll::poll_ssi', hidden => '1', page => { poll => 'poll_ssi.html' } }; $CFG->save(); # install language variable my $selected_dir = "$CFG->{admin_root_path}/templates/$CFG->{default_template_set}"; my $language = GT::Config->load("$selected_dir/language.txt", { create_ok => 0, inheritance => 1, local => 1, debug => $CFG->{debug_level}, header => <
{POLL_MAY_NOT_EDIT} = 'You may not edit the poll (you can still edit your post).'; $language->{POLL_VOTE_EMPTY} = 'Empty vote... why on earth did you do that?'; $language->{POLL_DOES_NOT_EXIST} = 'The poll you are looking for does not exist!'; $language->{POLL_DISABLED} = 'This poll is closed.'; $language->{POLL_ALREADY_DISABLED} = 'This poll is already disabled.'; $language->{POLL_ALREADY_ENABLED} = 'This poll is already enabled.'; $language->{POLL_ALREADY_VOTED} = 'You have already voted!'; $language->{POLL_THANK_YOU} = 'Thank you for voting'; $language->{POLL_NOT_ENOUGH_OPTIONS} = 'You can only post polls with two or more options.'; $language->save(); # Install Hooks $mgr->install_hooks ( 'Poll', [ ['do_post_write', 'POST', 'Plugins::GForum::Poll::post_write', 'FIRST'] ]); $mgr->install_hooks ( 'Poll', [ ['do_post_post', 'PRE', 'Plugins::GForum::Poll::post_post_pre', 'FIRST'] ]); $mgr->install_hooks ( 'Poll', [ ['do_post_post', 'POST', 'Plugins::GForum::Poll::post_post_post', 'FIRST'] ]); $mgr->install_hooks ( 'Poll', [ ['do_post_edit', 'POST', 'Plugins::GForum::Poll::post_edit', 'FIRST'] ]); $mgr->install_hooks ( 'Poll', [ ['do_post_edit_post', 'POST', 'Plugins::GForum::Poll::post_edit_post', 'FIRST'] ]); $mgr->install_hooks ( 'Poll', [ ['do_post_view_flat', 'POST', 'Plugins::GForum::Poll::post_view_flat', 'FIRST'] ]); $mgr->install_hooks ( 'Poll', [ ['do_post_view_threaded', 'POST', 'Plugins::GForum::Poll::post_view_threaded', 'FIRST'] ]); $mgr->install_hooks ( 'Poll', [ ['do_post_view_printable', 'POST', 'Plugins::GForum::Poll::post_view_printable', 'FIRST'] ]); $mgr->install_hooks ( 'Poll', [ ['do_forum_view_collapsed', 'POST', 'Plugins::GForum::Poll::forum_view', 'FIRST'] ]); $mgr->install_hooks ( 'Poll', [ ['do_forum_view_expandable', 'POST', 'Plugins::GForum::Poll::forum_view', 'FIRST'] ]); $mgr->install_hooks ( 'Poll', [ ['do_forum_view_expanded', 'POST', 'Plugins::GForum::Poll::forum_view', 'FIRST'] ]); # Install User Options $mgr->install_options('Poll', [['poll_vote_permission', '3', 'Permissions for voting in a poll (see "About" for details)']]); $mgr->install_options('Poll', [['poll_write_permission', '5', 'Permissions for writing a new poll (see "About" for details)']]); $mgr->install_options('Poll', [['poll_edit_permission', '6', 'Permissions for editing new poll (see "About" for details)']]); $mgr->install_options('Poll', [['track_user', '1', 'Track votes by username', 'SELECT', ['Yes','No'], ['1','0'], '']]); $mgr->install_options('Poll', [['track_ip', '1', 'Track votes by IP address', 'SELECT', ['Yes','No'], ['1','0'], '']]); $mgr->install_options('Poll', [['track_cookie', '0', 'Track votes by setting a cookie', 'SELECT', ['Yes','No'], ['1','0'], '']]); $mgr->install_options('Poll', [['track_cookie_hours', '24', 'Lifetime of cookie (in hours)']]); $mgr->install_options('Poll', [['percentage_pre', '0', 'Number of digits to use before point']]); $mgr->install_options('Poll', [['percentage_post', '0', 'Number of digits to use after decimal point']]); # Intall Menus $mgr->install_menu ( 'Poll', [ ['Add Poll Groups', 'db.cgi?db=PollGroup;do=add_form'] ] ); $mgr->install_menu ( 'Poll', [ ['Modify', 'db.cgi?db=PollGroup;do=modify_search_form'] ] ); $mgr->install_menu ( 'Poll', [ ['Delete', 'db.cgi?db=PollGroup;do=delete_search_form'] ] ); $mgr->install_menu ( 'Poll', [ ['Search', 'db.cgi?db=PollGroup;do=search_form'] ] ); $mgr->install_menu ( 'Poll', [ ['List', 'db.cgi?db=PollGroup;do=search_results;keyword=*'] ] ); $mgr->install_menu ( 'Poll', [ ['About', 'admin.cgi?do=plugin&plugin=Poll&func=about'] ] ); my $file; # Install template files my @files = ('include_poll_write.html', 'include_poll_view.html', 'include_poll_results.html', 'poll_disable.html', 'poll_ssi.html'); for my $html (@files) { $file = $tar->get_file ("templates/default/$html"); $file->name("$CFG->{admin_root_path}/templates/$CFG->{default_template_set}/$html"); unless ($file->write) { last; return Plugins::GForum::Poll->error("Unable to extract file: '$CFG->{admin_root_path}/templates/$CFG->{default_template_set}/$html' ($GT::Tar::error)", 'WARN'); } } # Install images my @images = ('leftbar.gif', 'mainbar.gif', 'rightbar.gif'); for my $html (@images) { $file = $tar->get_file ("images/$html"); $file->name("$CFG->{image_path}/$html"); unless ($file->write) { last; return Plugins::GForum::Poll->error("Unable to extract file: '$CFG->{image_path}/$html' ($GT::Tar::error)", 'WARN'); } } return "The plugin has been successfully installed!"; } sub uninstall { # ------------------------------------------------------------------- # This function removes the plugin. It's first argument is # also a plugin manager which you can use to register hooks, install files, # add menu options, etc. You should return an HTML formatted string # that will be displayed to the user. # # If there is an error, return undef, and set the error message in # $Plugins::GForum::Poll::error # my $mgr = shift; delete $CFG->{functions}->{poll_vote}; delete $CFG->{functions}->{poll_more_options}; delete $CFG->{functions}->{poll_enable}; delete $CFG->{functions}->{poll_disable}; delete $CFG->{functions}->{poll_ssi}; $CFG->save(); return "The plugin has been successfully removed!"; } 1;