<?php

    lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
    lt_include( PLOG_CLASS_PATH."class/template/menu/menu.class.php" );
    
    /**
     * CrystalPoll class
     */
    class PluginCrystalPoll extends PluginBase
    {
        var $pluginEnabled;
        
        function PluginCrystalPoll( $source = "" )
        {
            $this->PluginBase();
            $this->id = "crystalpoll";
            $this->desc = "This plugin offers you to create your own poll in your blog";
            $this->author = "Ahmad Fathi Saleh (Al Bawaba Team)";
            $this->locale = "locale_en_UK, locale_ar_SA";
            $this->version = "20080419";
            if( "admin" == $source ) {
                $this->adminInit();
            } elseif( "index" == $source ) {
                $this->blogInit();
            }
        }
        
        /**
         * init admin actions
         */
        function adminInit()
        {
            
            $this->registerAdminAction( "addPoll", "AdminAddPollAction" );
            $this->registerAdminAction( "updatePoll", "AdminUpdatePollAction" );
            $this->registerAdminAction( "deletePolls", "AdminDeletePollsAction" );
            $this->registerAdminAction( "newPoll", "AdminNewPollAction" );
            $this->registerAdminAction( "editPolls", "AdminEditPollsAction" );
            $this->registerAdminAction( "editPoll", "AdminEditPollAction" );
            $this->registerAdminAction( "pollSettings", "AdminPollSettingsAction" );
            $this->registerAdminAction( "updatePollSettings", "AdminUpdatePollSettingsAction" );

            $menu =& Menu::getMenu();
            if( !$menu->entryExists( "/menu/Manage/crystalPoll" ) ) {
                $this->addMenuEntry( "/menu/Manage", "crystalPoll", "", null, true, false );
                $this->addMenuEntry( "/menu/Manage/crystalPoll", "newPoll", "admin.php?op=newPoll", null, true, false );
                $this->addMenuEntry( "/menu/Manage/crystalPoll", "editPolls", "admin.php?op=editPolls", null, true, false );
                $this->addMenuEntry( "/menu/Manage/crystalPoll", "pollSettings", "admin.php?op=pollSettings", null, true, false);
            }
        }

        
        /**
         * init blog actions
         */
        function blogInit()
        {
            $this->registerBlogAction('addVote','AddVoteAction');
            $this->registerBlogAction('readPoll','ReadPollAction');
        }
        

        function install()
        {
            lt_include(PLOG_CLASS_PATH.'plugins/crystalpoll/class/dao/polls.class.php');
            $polls = new Polls();
            if( !$polls->tablesExists() ) {
                if( !$polls->createTables() ){
                    die( 'cannot create plugin tables' );
                }
            }
        }
		
    }
?>
