(file) Return to TemplateDisplay.class.php CVS log (file) (dir) Up to [Development] / old-advokit-installer

File: [Development] / old-advokit-installer / TemplateDisplay.class.php (download) / (as text)
Revision: 1.1.1.1 (vendor branch), Sat Jun 5 04:22:18 2004 UTC (6 years, 3 months ago) by travislow
Branch: advokit-installer, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
Initial import of AdvoKit into voter2voter cvs ... I hope you committed your changes. :-) 

<?
#======================================================================
# TemplateDisplay - class to render template-based displays
#
# (c) 2003, Dawnstar - http://dawnstar.com - info@dawnstar.com
#======================================================================
class TemplateDisplay extends BaseDisplay
{
    var $template;

    #.................................................. initialize
    #
    # Set any template values that need setting.  Override
    # this for custom subclasses.
    #
    function initialize()
    {
        
    }

    #.................................................. setTemplate
    #
    # Set the name of the template to be rendered.
    #
    function setTemplate( $template )
    {
        $this->template = $template;
    }

    #.................................................. doRender
    #
    # Render the display.
    # 
    # Anything common to all screens should be in the 
    # template from here.
    #
    function doRender()
    {
        $user =& $this->context->user;
        $this->context->te->set( "requested_display", $this->context->request->get( "display" ) );
        $this->context->te->set( "dataset", $this->context->request->get( "dataset" ) );
        $this->context->te->set( "terms", stripslashes( $this->context->request->get( "terms" ) ) );
        $this->context->te->set( "current_display", $this->getName() );
        $this->context->te->set( "username", $user->getUsername() );
        $this->context->te->set( "userdept", $user->get( "department_id" ) );
        $this->context->te->set( "lastresult", $this->getMessage() );
        $this->context->te->set( "isLoggedIn", $user->isLoggedIn() );
        $this->context->te->set( "isAdmin", $user->isAdmin() );
        $this->context->te->set( "isTech", $user->isTech() );
        $this->context->te->set( "userid", $user->getId() );
        $this->context->te->set( "browser", $this->getBrowser() );
        $this->context->te->set( "tweaks", $this->getBrowserTweaks() );
        $this->context->te->set( "taskfiltering", $this->context->ustate->getValue( $user->getId(), 0, '', '', 'taskfilter' ) );
        $this->context->te->set( "faqfiltering", $this->context->ustate->getValue( $user->getId(), 0, '', '', 'faqfilter' ) );
        $this->context->te->set( "convert_newlines", $this->context->config->get( "convert_newlines" ) );
        $ver = $this->context->db->select_one( "select * from ".W_TBL."ver where patch=0 order by ts desc" );
        $this->context->te->set( "ver", $ver );

        # Stuff for logged in users.  Should be separated out.
        if( $user->isLoggedIn() )
        {
            $homepagealert = $this->context->db->select_one( "select * from ".W_TBL."settings s where s.name='homepagealert'" );
            $this->context->te->set( "homepagealert", $homepagealert );
            $admincontact = $this->context->db->select_one( "select p.email from ".W_TBL."settings s left join ".W_TBL."person p on (p.id = s.intvalue) where s.name='admincontact'" );
            $this->context->te->set( "admincontact", $admincontact );
            $this->context->te->set( "login_timeout", $this->context->config->get( "login_timeout" ) );
            $this->context->te->set( "logout_warning_interval", $this->context->config->get( "logout_warning_interval" ) );
            $this->context->te->set( "show_sql", $this->context->config->get( "show_sql" ) );

            # Get campaigns
            # TODO: Need to restrict this by user somehow.
            $campaigns = $this->context->db->select_all( "select * from ".W_TBL."campaign c left join ".W_TBL."node n on (n.id = c.id) order by n.name" );
            $this->context->te->set( "campaigns", $campaigns );

            # Get current campaign, operation, and node
            # TODO: Need to restrict this by user somehow.
            $current_campaign_id = $this->context->ustate->getValue( $user->getId(), 0, '', '', 'current_campaign_id' );
            $this->context->te->set( "current_campaign_id", $current_campaign_id );
            $current_operation_id = $this->context->ustate->getValue( $user->getId(), 0, '', '', 'current_operation_id' );
            $this->context->te->set( "current_operation_id", $current_operation_id );
            $current_node_id = $this->context->ustate->getValue( $user->getId(), 0, '', '', 'current_node_id' );
            $this->context->te->set( "current_node_id", $current_node_id );
            # Make breadcrumbs
            # TODO: Need to restrict this by user somehow.
            $breadcrumbs = array();
            if( $current_node_id && $current_node_id != $current_campaign_id )
            {
                $current_node = $this->context->db->select_one( "select n.* from ".W_TBL."node n where id=$current_node_id" );
                while( $current_node )
                {
                    array_unshift( $breadcrumbs, $current_node );
                    if( $current_node["parent_id"] )
                    {
                        $current_node = $this->context->db->select_one( "select n.* from ".W_TBL."node n where id=".$current_node["parent_id"] );
                    }
                    else
                    {
                        $current_node = NULL;
                    }
                }
                $this->context->te->set( "breadcrumbs", $breadcrumbs );
            }
            
        }
        # Now render the display.
        $this->context->te->render( $this->displaytype.$this->context->config->get( "te_header_suffix" ) );
        $this->initialize();
        $this->renderBody();
        $this->context->te->render( $this->displaytype.$this->context->config->get( "te_footer_suffix" ) );

    }
    #.................................................. renderBody
    #
    # Render the meat of the display.  You may wish
    # to override this in a subclass.
    #
    function renderBody()
    {
        if( $this->template && file_exists( $this->context->config->get( "te_root" ).DIRSEP.$this->context->config->get( "te_tpls_raw" ).DIRSEP.$this->template ) )
        {
            $this->context->te->render( $this->template );
        }
    }
}
?>

cvsadmin@voter2voter.org
CVS Snapshots (updated daily)