<?php

# $Id: method.install.php 1 2011-06-12 15:25:27Z arnoud $ 

#BEGIN_LICENSE
#-------------------------------------------------------------------------
# Module: UpCoupon (c) 2011 by Arnoud van Susteren (arnoud@upservice.nl)
#
# An addon module for CMS Made Simple to setup a Coupon Codes Lottery
# 
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2005 by Ted Kulp (wishy@cmsmadesimple.org)
# This project's 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(!is_object(cmsms())) exit;

###############################################################################
# tables
###############################################################################

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

// UPCOUPON_ACTION_TABLE

$flds = 'coupon_action_id I KEY AUTO,
        title C(100),
        alias C(45),
        description X,
        start_date '.CMS_ADODB_DT.',
        end_date '.CMS_ADODB_DT.', 
        status I1(1)';

$sqlarray = $dict->CreateTableSQL(UPCOUPON_ACTION_TABLE, $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);

// UPCOUPON_PERIOD_TABLE

$flds = 'coupon_period_id I KEY AUTO,
        coupon_action_id I(11),
        title C(100),
        start_date '.CMS_ADODB_DT.',
        end_date '.CMS_ADODB_DT.',
        is_final I1(1),      
        status I1(1)';

$sqlarray = $dict->CreateTableSQL(UPCOUPON_PERIOD_TABLE, $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);   

// UPCOUPON_PRIZE_TABLE

$flds = 'coupon_prize_id I KEY AUTO,
        coupon_period_id I(11),
        coupon_action_id I(11),        
        prize_code C(45),
        title C(100),
        description X,
        number I1(3),
        status I1(1)';

$sqlarray = $dict->CreateTableSQL(UPCOUPON_PRIZE_TABLE, $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);   

// UPCOUPON_CUSTOMER_TABLE

$flds = 'coupon_customer_id I KEY AUTO,
        first_name C(100),
        last_name C(100),
        email C(45),
        phone C(15),
        newsletter I1(1),
        ip C(15),
        status I1(1), 
        password C(8),
        salt C(8),
        checksum C(32),
        registration_date '.CMS_ADODB_DT.',
        timestamp I(11)';

$sqlarray = $dict->CreateTableSQL(UPCOUPON_CUSTOMER_TABLE, $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);

// UPCOUPON_CODE_TABLE

$flds = 'coupon_code_id I KEY AUTO,
        coupon_prize_id I,
        coupon_customer_id I,
        coupon_code C(16),
        timestamp I(11)';

$sqlarray = $dict->CreateTableSQL(UPCOUPON_CODE_TABLE, $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);

// indexes

$db_prefix = cms_db_prefix();

$sqlarray = $dict->CreateIndexSQL($db_prefix.'index_module_upcoupon_code_by_coupon_customer_id', UPCOUPON_CODE_TABLE, 'coupon_customer_id');
$dict->ExecuteSQLArray($sqlarray);

$sqlarray = $dict->CreateIndexSQL($db_prefix.'index_module_upcoupon_code_by_coupon_code', UPCOUPON_CODE_TABLE, 'coupon_code');
$dict->ExecuteSQLArray($sqlarray);

###############################################################################
# permissions
###############################################################################

$this->CreatePermission('Modify UpCoupon', 'Modify UpCoupon');	

###############################################################################
# events
###############################################################################

$this->CreateEvent('UpCouponActionAdded');
$this->CreateEvent('UpCouponActionEdited');
$this->CreateEvent('UpCouponActionDeleted');

$this->CreateEvent('UpCouponPeriodAdded');
$this->CreateEvent('UpCouponPeriodEdited');
$this->CreateEvent('UpCouponPeriodDeleted');

$this->CreateEvent('UpCouponPrizeAdded');
$this->CreateEvent('UpCouponPrizeEdited');
$this->CreateEvent('UpCouponPrizeDeleted');

$this->CreateEvent('UpCouponWinnerAdded');
$this->CreateEvent('UpCouponWinnerEdited');
$this->CreateEvent('UpCouponWinnerDeleted');

$this->CreateEvent('UpCouponTemplateAdded');
$this->CreateEvent('UpCouponTemplateEdited');
$this->CreateEvent('UpCouponTemplateDeleted');

$this->CreateEvent('UpCouponPreferenceAdded');
$this->CreateEvent('UpCouponPreferenceEdited');
$this->CreateEvent('UpCouponPreferenceDeleted');

###############################################################################
# preferences
###############################################################################

// $gCms->SetPreference('signup_email_subject', $gCms->lang('account details'));

$this->Audit( 0, $this->Lang('friendlyname'), $this->Lang('installed', $this->GetVersion()) );

#
# EOF
#
?>
