<?php
#BEGIN_LICENSE
#-------------------------------------------------------------------------
# Module: HitCounter (c) 2009 by Robert Campbell
#         (calguy1000@cmsmadesimple.org)
#  An addon module for CMS Made Simple to allow management of frontend
#  users, and their login process within a CMS Made Simple powered
#  website.
#
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2009 by Ted Kulp (wishy@cmsmadesimple.org)
# This projects homepage is: http://www.cmsmadesimple.org
#
#-------------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# However, as a special exception to the GPL, this software is distributed
# as an addon module to CMS Made Simple.  You may not use this software
# in any Non GPL version of CMS Made simple, or in any version of CMS
# Made simple that does not indicate clearly and obviously in its admin
# section that the site was built with CMS Made simple.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
#
#-------------------------------------------------------------------------
#END_LICENSE
if( !isset($gCms) ) exit;

$taboptarray = array('mysql' => 'TYPE=MyISAM');
$dict = NewDataDictionary($db);

$flds = "id I KEY AUTO,
         key1 C(255),
         key2 C(255),
         key3 C(255),
         returnid I,
         ip_address C(255),
         date DT,
         agent C(255)
         ";
// create it. This should do error checking, but I'm a lazy sod.
$sqlarray = $dict->CreateTableSQL(cms_db_prefix()."module_hitcounter", $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);

// create a permission
$this->CreatePermission('Manage HitCounter', 'Manage HitCounter');

// create a preference or two
$this->SetPreference("subnet_exclusions", "192.168.0.0/16,10.0.0.0/8,127.0.0.1/32");
$this->SetPreference("agent_exclusions", "Wget\/");
$this->SetPreference("visit_timeout","30");
$this->SetPreference("agent_exclusions", "");
$this->SetPreference('excluded_bots',1);

$this->RegisterModulePlugin(TRUE);

// template stuff
try {
    $popular_template_type = new CmsLayoutTemplateType();
    $popular_template_type->set_originator($this->GetName());
    $popular_template_type->set_name('popular');
    $popular_template_type->set_dflt_flag(TRUE);
    $popular_template_type->set_lang_callback('HitCounter::page_type_lang_callback');
    $popular_template_type->set_content_callback('HitCounter::reset_page_type_defaults');
    //$popular_template_type->set_help_callback('HitCounter::template_help_callback');
    $popular_template_type->reset_content_to_factory();
    $popular_template_type->save();

    $ob = new CmsLayoutTemplate();
    $ob->set_type( $popular_template_type );
    $ob->set_content( $popular_template_type->get_dflt_contents() );
    $ob->set_owner($uid);
    $ob->set_type_dflt(TRUE);
    $ob->set_name('HitCounter Popular Sample');
    $ob->save();
}
catch( CmsException $e ) {
    // log it
    debug_to_log(__FILE__.':'.__LINE__.' '.$e->GetMessage());
    audit('',$this->GetName(),'Installation Error: '.$e->GetMessage());
}

/*
$tpl = file_get_contents(__DIR__.'/templates/orig_popular.tpl');
$this->SetTemplate('sysdflt_popular_template',$tpl);
$this->SetTemplate('popularSample',$tpl);
$this->SetPreference('current_popular_template','Sample');
*/

#
# EOF
#
?>