<?php

# $Id: function.admin_tab_action.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;

###############################################################################
# program start 
###############################################################################

$actiondb = new coupon_actionDAO();

if (isset($params['submit_massdelete_action'])) {
    
    if( isset($params['pkeys']) && is_array($params['pkeys']) &&
    count($params['pkeys']) > 0 ) {
    
        foreach ($params['pkeys'] as $pkey) {
            $actiondb->delete($pkey);  
        }    
        
        $params = array('action_message'=> 's_deleted,action_s', 'active_tab' => 'action');
        $this->Redirect($id, 'defaultadmin', $returnid, $params);
    
    }
    
}

$action_data = $actiondb->fetch_all();

$entryarray = array();

foreach ($action_data as $key => $value) {

    $onerow = new stdClass();
    
    foreach ($value as $sub_key => $sub_value) {
        $onerow->$sub_key = $value[$sub_key];   
    }
        
    $onerow->editurl = $this->CreateLink($id, 'action_add_edit', $returnid, '', array('pkey'=>$value['coupon_action_id']), '', 'true');
    
    $onerow->edit_link = $this->CreateLink(
        $id, 
        'action_add_edit', 
        $returnid,
        $admintheme->DisplayImage('icons/system/edit.gif',
        $this->Lang('edit'),'','','systemicon'),
        array('pkey'=>$value['coupon_action_id'])
    );

    $onerow->delete_link = $this->CreateLink(
        $id, 
        'action_delete', 
        $returnid, 
        $admintheme->DisplayImage('icons/system/delete.gif',
        $this->Lang('delete'),'','','systemicon'),
        array('pkey'=>$value['coupon_action_id']), 
        $this->Lang('areyousure')
    );
    
    $onerow->select = $this->CreateInputCheckbox($id, 'pkeys[]', $value['coupon_action_id']);

    if ( $value['status'] == '1' ) {
        $onerow->approve_link = $this->CreateLink($id, 'action_change_status', $returnid, $admintheme->DisplayImage('icons/system/true.gif', $this->Lang('revert_status'), '', '', 'systemicon'), array('status' => 0, 'pkey' => $value['coupon_action_id']));
    } else {
        $onerow->approve_link = $this->CreateLink($id, 'action_change_status', $returnid, $admintheme->DisplayImage('icons/system/false.gif', $this->Lang('approve_status'), '', '', 'systemicon'), array('status' => 1, 'pkey' => $value['coupon_action_id']));    
    }

    $entryarray[] = $onerow;

}
		
$this->smarty->assign_by_ref('items', $entryarray);
$this->smarty->assign('itemcount', count($entryarray));

###############################################################################
# define text for labels
###############################################################################	
	
$smarty->assign('title_text', $this->Lang('title'));	
$smarty->assign('alias_text', $this->Lang('alias'));	
$smarty->assign('start_date_text', $this->Lang('start_date'));	
$smarty->assign('end_date_text', $this->Lang('end_date'));	
$smarty->assign('status_text', $this->Lang('status'));	
$smarty->assign('select_text', $this->Lang('select'));

###############################################################################
# setup buttons and links
###############################################################################

$form_params = array();
$form_params['active_tab'] = 'action';

if (isset($params['action_message'])) {
        $action_message = explode(",", $params['action_message']);
        $smarty->assign('action_message',$this->ShowMessage($this->Lang($action_message[0], array($this->Lang($action_message[1])))));
}

$smarty->assign('startform',$this->CreateFormStart($id, 'defaultadmin', $returnid, 'post', '', false, '', $form_params, ''));

$smarty->assign('endform',$this->CreateFormEnd());

$smarty->assign('submit_massdelete',
$this->CreateInputSubmit($id, 'submit_massdelete_action', $this->Lang('delete_selected_items'), '', '', $this->Lang('areyousure')));

$this->smarty->assign('add_link', $this->CreateLink(
    $id, 
    'action_add_edit', 
    $returnid, 
    $admintheme->DisplayImage('icons/system/newobject.gif', 
    $this->Lang('s_add', array($this->Lang('action_s'))),
    '',
    '',
    'systemicon'), 
    array(), 
    '', 
    false, 
    false, 
    '') .' '. $this->CreateLink(
        $id, 
        'action_add_edit', 
        $returnid,
        $this->Lang('s_add', array($this->Lang('action_s'))), 
        array(),
        '', 
        false, 
        false, 
        'class="pageoptions"')
    );

$this->smarty->assign('action', $this->Lang('action_s'));

###############################################################################
# ProcessTemplate
###############################################################################

echo $this->ProcessTemplate('action_list.tpl');
	
#
# EOF
#
?>