$Date: 2006-10-11 13:01:38 -0500 (Wed, 11 Oct 2006) $
| > $Revision: 628 $
| > $Author: bfarber $
+---------------------------------------------------------------------------
|
| > Pay Subscriptions Manager
| > Module written by Matt Mecham
| > Date started: Friday 1st April 2005 (14:05)
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_ACP' ) )
{
print "
Incorrect access
You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
exit();
}
//---------------------------------------
// Carry on!
//---------------------------------------
class ad_paysubscriptions
{
# Global
var $ipsclass;
var $html;
var $gateway;
var $email;
/**
* Section title name
*
* @var string
*/
var $perm_main = "content";
/**
* Section title name
*
* @var string
*/
var $perm_child = "msubs";
/*-------------------------------------------------------------------------*/
// IPB auto_run
/*-------------------------------------------------------------------------*/
function auto_run()
{
//-----------------------------------------
// Load skin
//-----------------------------------------
$this->html = $this->ipsclass->acp_load_template('cp_skin_paysubs');
//--------------------------------------------
// Get the sync module
//--------------------------------------------
if ( USE_MODULES == 1 )
{
require ROOT_PATH."modules/ipb_member_sync.php";
$this->modules = new ipb_member_sync();
}
//-----------------------------------------
// GET EMAIL CLASS
//-----------------------------------------
require_once( ROOT_PATH."sources/classes/class_email.php" );
$this->email = new emailer( ROOT_PATH );
$this->email->ipsclass =& $this->ipsclass;
$this->email->email_init();
define( 'GW_CORE_INIT', TRUE );
//--------------------------------------------
// Load extra db cache file
//--------------------------------------------
$this->ipsclass->DB->load_cache_file( ROOT_PATH.'sources/sql/'.SQL_DRIVER.'_subsm_queries.php', 'sql_subsm_queries' );
$this->ipsclass->admin->page_title = "IPB Subscriptions Manager";
$this->ipsclass->admin->page_detail = "You can set up and manage your member's paid subscriptions in this section.";
$this->ipsclass->admin->nav[] = array( $this->ipsclass->form_code, 'IPB Subscription Manager Home' );
//-----------------------------------------
// Do what?
//-----------------------------------------
switch($this->ipsclass->input['code'])
{
//-----------------------------------------
case 'install-index':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':install' );
$this->install_index();
break;
case 'install-gateway':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':install' );
$this->install_gateway();
break;
case 'edit_package_gateway_info':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->edit_package_gateway_info();
break;
case 'edit_package_complete':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->edit_package_complete();
break;
//-----------------------------------------
case 'removepackage':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->remove_package();
break;
case 'remove_package_complete':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->remove_package_complete();
break;
//-----------------------------------------
case 'removemembers':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->remove_members();
break;
case 'remove_members_complete':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->remove_members_complete();
break;
//-----------------------------------------
case 'addpackage':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->alter_package_form('add');
break;
case 'doaddpackage':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->do_add_package();
break;
//-----------------------------------------
case 'editpackage':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->alter_package_form('edit');
break;
case 'doeditpackage':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->do_edit_package();
break;
//-----------------------------------------
case 'editmethod':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->edit_method();
break;
case 'edit_method_complete':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->edit_method_complete();
break;
//-----------------------------------------
case 'find_transactions':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':search' );
$this->find_transactions();
break;
case 'find_logs':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':search' );
$this->find_logs();
break;
case 'find_logs_view_entry':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':search' );
$this->find_logs_view_entry();
break;
//-----------------------------------------
case 'domodifytrans':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->do_modify_trans();
break;
case 'dotransdelete':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->do_delete_trans();
break;
//-----------------------------------------
case 'edittransaction':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->edit_transaction('edit');
break;
case 'addtransaction':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->edit_transaction('add');
break;
case 'doedittransaction':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->save_transaction('edit');
break;
case 'doaddtransaction':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->save_transaction('add');
break;
//-----------------------------------------
case 'currency':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->currency_index();
break;
case 'editcurrency':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->currency_edit();
break;
case 'deletecurrency':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->currency_delete();
break;
//-----------------------------------------
// View...
//-----------------------------------------
case 'index-gateways':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->paysubs_index_gateways();
break;
case 'index-packages':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->paysubs_index_packages();
break;
case 'index-tools':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->paysubs_index_tools();
break;
default:
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->paysubs_index_gateways();
break;
}
}
/*-------------------------------------------------------------------------*/
// Install INDEX
/*-------------------------------------------------------------------------*/
function install_gateway()
{
//-------------------------------------------
// INIT
//-------------------------------------------
$gateway = trim( $this->ipsclass->input['name'] );
$gateway = preg_replace( '#\.{1,}#s', '.', $gateway );
//-------------------------------------------
// Check...
//-------------------------------------------
if ( ! $gateway )
{
$this->ipsclass->main_msg = "No gateway specified";
$this->install_index();
}
$test = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'submethod_name', 'from' => 'subscription_methods', 'where' => "submethod_name='{$gateway}'" ) );
if ( $test['submethod_name'] )
{
$this->ipsclass->main_msg = "Gateway already installed";
$this->install_index();
}
//-------------------------------------------
// Load it
//-------------------------------------------
require_once( ROOT_PATH . 'sources/classes/paymentgateways/class_gw_core.php' );
require_once( ROOT_PATH . 'sources/classes/paymentgateways/class_gw_'.$gateway.'.php' );
$this->gateway = new class_gw_module();
$this->gateway->ipsclass =& $this->ipsclass;
//-------------------------------------------
// Get info...
//-------------------------------------------
$this->gateway->install_gateway();
//-------------------------------------------
// Install language
//-------------------------------------------
if ( is_array( $this->gateway->install_lang ) and count ( $this->gateway->install_lang ) )
{
require( ROOT_PATH.'sources/api/api_language.php' );
$api = new api_language();
$api->ipsclass =& $this->ipsclass;
$api->api_init();
$api->lang_add_strings( $this->gateway->install_lang, 'lang_subscriptions' );
}
//-------------------------------------------
// Install DB
//-------------------------------------------
if ( is_array( $this->gateway->db_info ) )
{
$this->ipsclass->DB->do_insert( 'subscription_methods', array( 'submethod_title' => $this->gateway->db_info['human_title'],
'submethod_desc' => $this->gateway->db_info['human_desc'],
'submethod_name' => $this->gateway->db_info['module_name'],
'submethod_is_cc' => $this->gateway->db_info['allow_creditcards'],
'submethod_is_auto' => $this->gateway->db_info['allow_auto_validate'],
'submethod_use_currency' => $this->gateway->db_info['default_currency'] ) );
}
//-------------------------------------------
// Done...
//-------------------------------------------
$this->ipsclass->main_msg = "Gateway installed";
$this->install_index();
}
/*-------------------------------------------------------------------------*/
// Install INDEX
/*-------------------------------------------------------------------------*/
function install_index()
{
//-------------------------------------------
// INIT
//-------------------------------------------
$methods = array();
$dir_contents = array();
$dir_path = ROOT_PATH.'sources/classes/paymentgateways';
$content = "";
//-------------------------------------------
// Get all current methods
//-------------------------------------------
$this->ipsclass->DB->build_query( array( 'select' => 'submethod_name', 'from' => 'subscription_methods' ) );
$this->ipsclass->DB->exec_query();
while( $r = $this->ipsclass->DB->fetch_row() )
{
$methods[ strtolower($r['submethod_name']) ] = 1;
}
//-------------------------------------------
// Get contents of dir
//-------------------------------------------
$handle = opendir( $dir_path );
while ( ( $file = readdir($handle) ) !== FALSE )
{
if ( ($file != ".") && ($file != "..") )
{
if ( preg_match( "#class_gw_(.+?)\.php$#", $file, $match ) )
{
if ( $match[1] == 'core' )
{
continue;
}
$dir_contents[ strtolower($match[1]) ] = $file;
}
}
}
closedir($handle);
//-------------------------------------------
// Loop and list
//-------------------------------------------
foreach( $dir_contents as $gateway => $filename )
{
//-------------------------------------------
// Already installed?
//-------------------------------------------
if ( $methods[ $gateway ] )
{
$installed = 1;
}
else
{
$installed = 0;
}
$content .= $this->html->gateway_install_row( $gateway, $installed );
}
$this->ipsclass->html .= $this->html->gateway_install_wrapper( $content );
$this->ipsclass->admin->output();
}
/*-------------------------------------------------------------------------*/
// Currency Overview - Yeah
/*-------------------------------------------------------------------------*/
function currency_index($message="")
{
$default = $this->ipsclass->DB->build_and_exec_query( array( 'select' => '*', 'from' => 'subscription_currency', 'where' => 'subcurrency_default=1' ) );
$this->ipsclass->DB->fetch_row();
//-------------------------------------------
// Message in a bottle?
//-------------------------------------------
if ( $message != "" )
{
$this->ipsclass->adskin->td_header[] = array( " " , "100%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Message" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( $message ) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
}
$this->ipsclass->admin->page_detail .= "
Currency Information The currency you set as default becomes the currency the subscriptions are based in. For example, if you chose USD as default, entering a value of 1.00 for a subscription package means that the subscription
package costs 1.00 USD. If you choose another default you may want to edit all the subscription values as they will become incorrect. If you choose another default, you will also want to edit the exchange values.
Editing Gateway '{$this_mtd['submethod_title']}' specific information for package '{$this_pkg['sub_title']}'.";
$this->ipsclass->admin->nav[] = array( '', 'Editing Gateway '.$this_mtd['submethod_title'].' Info for Package '.$this_pkg['sub_title'] );
//-------------------------------------------
// Quick Jump Table
//-------------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , 'edit_package_gateway_info'),
2 => array( 'act' , 'msubs' ),
4 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( " " , "40%" );
$this->ipsclass->adskin->td_header[] = array( " " , "60%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Quick Jump");
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Payment Gateway" ,
$this->ipsclass->adskin->form_dropdown( 'method', $methods, $this_mtd['submethod_id'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Subscription Package" ,
$this->ipsclass->adskin->form_dropdown( 'sub', $packages, $this_pkg['sub_id'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form( "Go!" );
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
//-------------------------------------------
// Carry on!
//-------------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , 'edit_package_complete'),
2 => array( 'act' , 'msubs' ),
3 => array( 'method' , $method_id ),
4 => array( 'sub' , $subpkg_id ),
5 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( " " , "40%" );
$this->ipsclass->adskin->td_header[] = array( " " , "60%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "{$this_mtd['submethod_title']} -> {$this_pkg['sub_title']}");
//---------------------------------
// Load the API...
//---------------------------------
$custom = array();
if ( @file_exists( ROOT_PATH . 'sources/classes/paymentgateways/class_gw_'.$this_mtd['submethod_name'].'.php' ) )
{
require_once( ROOT_PATH . 'sources/classes/paymentgateways/class_gw_core.php' );
require_once( ROOT_PATH . 'sources/classes/paymentgateways/class_gw_'.$this_mtd['submethod_name'].'.php' );
$this->gateway = new class_gw_module();
//----------------------------------
// Sort out the custom method fields
//----------------------------------
$form = $this->gateway->acp_return_package_variables();
foreach( $form as $name => $data )
{
if ( $data['used'] != 0 )
{
$custom[] = $this->ipsclass->adskin->add_td_row( array( "{$data['formname']} {$data['formextra']}" ,
$this->ipsclass->adskin->form_input( $name, $row[ $name ] )
) );
}
}
}
else
{
$this->ipsclass->admin->error("Could not locate the API in: ".ROOT_PATH . 'modules/subsmanager/api_'.$row['submethod_name'].'.php');
}
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Subscription / Gateway Combo: Product ID This is not required by all combinations" ,
$this->ipsclass->adskin->form_input("subextra_product_id", $row['subextra_product_id'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Can be recurringly billed for this package using this gateway? This is not required by all combinations and will not count if the package never expires" ,
$this->gateway->can_do_recurring_billing == 0 ? "This gateway does not support recurring billing" : $this->ipsclass->adskin->form_yes_no("subextra_recurring", $row['subextra_recurring'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Can upgrade from this package using this gateway? This is not required by all combinations" ,
$this->gateway->can_do_upgrades == 0 ? "This gateway does not support upgrading packages" : $this->ipsclass->adskin->form_yes_no("subextra_can_upgrade", $row['subextra_can_upgrade'] )
) );
if ( count( $custom ) > 0 )
{
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic( 'Gateway Specific Settings', 'left', 'catrow2' );
$this->ipsclass->html .= implode( "\n", $custom );
}
$this->ipsclass->html .= $this->ipsclass->adskin->end_form( "Save Settings" );
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->output();
}
/*-------------------------------------------------------------------------*/
// Remove Package: You can do iiiiit! I know.
/*-------------------------------------------------------------------------*/
function remove_package_complete()
{
$this->ipsclass->input['id'] = isset($this->ipsclass->input['id']) ? intval($this->ipsclass->input['id']) : 0;
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->admin->error("Could locate a subscription package with the id of {$this->ipsclass->input['id']}");
}
$this->ipsclass->DB->build_query( array( 'select' => '*', 'from' => 'subscriptions', 'where' => "sub_id={$this->ipsclass->input['id']}" ) );
$this->ipsclass->DB->exec_query();
if ( ! $row = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->admin->error("Could locate a subscription package with the id of {$this->ipsclass->input['id']}");
}
$this->_unsub_members($this->ipsclass->input['id'], 'all', 'dead');
$this->ipsclass->DB->do_delete( 'subscriptions', "sub_id={$this->ipsclass->input['id']}" );
$this->ipsclass->admin->save_log("Subscription Package {$row['sub_title']} removed");
$this->ipsclass->boink_it( $this->ipsclass->base_url."&{$this->ipsclass->form_code}" );
}
/*-------------------------------------------------------------------------*/
// Remove Package: Step One
/*-------------------------------------------------------------------------*/
function remove_package()
{
$time = time();
$this->ipsclass->input['id'] = isset($this->ipsclass->input['id']) ? intval($this->ipsclass->input['id']) : 0;
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->admin->error("Could locate a subscription package with the id of {$this->ipsclass->input['id']}");
}
$row = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'COUNT(*) as total', 'from' => 'subscription_trans', 'where' => "subtrans_sub_id={$this->ipsclass->input['id']}" ) );
$total = intval( $row['total'] );
$sub = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'sub_title', 'from' => 'subscriptions', 'where' => "sub_id={$this->ipsclass->input['id']}" ) );
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , 'remove_package_complete' ),
2 => array( 'act' , 'msubs' ),
3 => array( 'id' , $this->ipsclass->input['id'] ),
4 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( " " , "100%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Remove Package '{$sub['sub_title']}' Confirmation" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Members subscribed to {$sub['sub_title']}: $total
Deleting this package will remove all subscribed members and return them back to their previous group. It will also mark all transactions currently subscribed to this package as 'dead'
Please note that if the group that they were in no longer exists, they will be moved into the default member group."
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form("Remove Package");
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->output();
}
/*-------------------------------------------------------------------------*/
// Remove Members: You can do iiiiit!
/*-------------------------------------------------------------------------*/
function remove_members_complete()
{
//-------------------------------------------
// INIT
//-------------------------------------------
$this->ipsclass->input['id'] = isset($this->ipsclass->input['id']) ? intval($this->ipsclass->input['id']) : 0;
//-------------------------------------------
// Check
//-------------------------------------------
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->admin->error("Could locate a subscription package with the id of {$this->ipsclass->input['id']}");
}
$this->ipsclass->DB->build_query( array( 'select' => '*', 'from' => 'subscriptions', 'where' => "sub_id={$this->ipsclass->input['id']}" ) );
$this->ipsclass->DB->exec_query();
if ( ! $row = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->admin->error("Could locate a subscription package with the id of {$this->ipsclass->input['id']}");
}
$this->_unsub_members($this->ipsclass->input['id'], $this->ipsclass->input['type']);
$this->ipsclass->admin->save_log("Members unsubscribed from package {$row['sub_title']} using type {$this->ipsclass->input['type']}");
$this->ipsclass->main_msg = "Members unsubscribed from package {$row['sub_title']} using type {$this->ipsclass->input['type']}";
$this->paysubs_index_packages();
}
/*-------------------------------------------------------------------------*/
// Remove Members: Step One
/*-------------------------------------------------------------------------*/
function remove_members()
{
//-------------------------------------------
// INIT
//-------------------------------------------
$time = time();
$this->ipsclass->input['id'] = isset($this->ipsclass->input['id']) ? intval($this->ipsclass->input['id']) : 0;
//-------------------------------------------
// Check
//-------------------------------------------
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->admin->error("Could locate a subscription package with the id of {$this->ipsclass->input['id']}");
}
if ( $this->ipsclass->input['type'] != 'all' )
{
$query = "subtrans_end_date < $time AND subtrans_sub_id={$this->ipsclass->input['id']}";
}
else
{
$query = "subtrans_sub_id={$this->ipsclass->input['id']}";
}
$row = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'count(*) as total', 'from' => 'subscription_trans', 'where' => $query ) );
$total = intval( $row['total'] );
if ( $total < 1 )
{
$this->ipsclass->admin->error("There are no members to remove.");
}
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , 'remove_members_complete' ),
2 => array( 'act' , 'msubs' ),
3 => array( 'type' , $this->ipsclass->input['type'] ),
4 => array( 'id' , $this->ipsclass->input['id'] ),
5 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( " " , "100%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Unsubscription Confirmation" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Members to unsubscribe: $total
Unsubscribing members will mark their transaction as 'expired' and return them to the group they were in before they subscribed.
Please note that if the group that they were in no longer exists, they will be moved into the default member group."
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form("Unsubscribe");
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->output();
}
/*-------------------------------------------------------------------------*/
// Subscription Package: Add Package
/*-------------------------------------------------------------------------*/
function do_add_package()
{
$this->ipsclass->input['sub_run_module'] = preg_replace( '#\.{1,}#s', '.', $this->ipsclass->input['sub_run_module'] );
if ( $this->ipsclass->input['sub_title'] == "" )
{
$this->ipsclass->admin->error("You must enter a valid title for this subscription package");
}
if ( $this->ipsclass->input['sub_cost'] == "" )
{
$this->ipsclass->admin->error("You must enter a valid cost for this subscription package");
}
if ( $this->ipsclass->input['sub_noexpire'] )
{
$this->ipsclass->input['sub_unit'] = 'x';
$this->ipsclass->input['sub_length'] = 0;
}
if ( $this->ipsclass->vars['admin_group'] == $this->ipsclass->input['sub_new_group'] )
{
if ( $this->ipsclass->member['mgroup'] != $this->ipsclass->vars['admin_group'] )
{
$this->ipsclass->input['sub_new_group'] = 0;
}
}
$this->ipsclass->DB->do_insert( "subscriptions", array (
'sub_title' => str_replace( "'", "", str_replace( "'", "'", $this->ipsclass->input['sub_title'])),
'sub_desc' => $this->ipsclass->txt_safeslashes(trim($_POST['sub_desc'])),
'sub_new_group' => intval($this->ipsclass->input['sub_new_group']),
'sub_length' => $this->ipsclass->input['sub_length'],
'sub_unit' => $this->ipsclass->input['sub_unit'],
'sub_cost' => $this->ipsclass->input['sub_cost'],
'sub_run_module' => $this->ipsclass->input['sub_run_module'],
) );
$this->ipsclass->admin->save_log("Subscription Package '{$this->ipsclass->input['sub_title']}' created");
$this->ipsclass->main_msg = 'Subscription Package Added';
$this->paysubs_index_packages();
}
/*-------------------------------------------------------------------------*/
// Subscription Package: Complete Edit
/*-------------------------------------------------------------------------*/
function do_edit_package()
{
//-------------------------------------------
// INIT
//-------------------------------------------
$this->ipsclass->input['id'] = isset($this->ipsclass->input['id']) ? intval($this->ipsclass->input['id']) : 0;
$this->ipsclass->input['sub_run_module'] = preg_replace( '#\.{1,}#s', '.', $this->ipsclass->input['sub_run_module'] );
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->admin->error("Could locate a payment gateway with the id of {$this->ipsclass->input['id']}");
}
$this->ipsclass->DB->build_query( array( 'select' => '*', 'from' => 'subscriptions', 'where' => "sub_id={$this->ipsclass->input['id']}" ) );
$this->ipsclass->DB->exec_query();
if ( ! $row = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->admin->error("Could locate a payment gateway with the id of {$this->ipsclass->input['id']}");
}
if ( $this->ipsclass->input['sub_title'] == "" )
{
$this->ipsclass->admin->error("You must enter a valid title for this subscription package");
}
if ( $this->ipsclass->input['sub_cost'] == "" )
{
$this->ipsclass->admin->error("You must enter a valid cost for this subscription package");
}
if ( $this->ipsclass->input['sub_noexpire'] )
{
$this->ipsclass->input['sub_unit'] = 'x';
$this->ipsclass->input['sub_length'] = 0;
}
if ( $this->ipsclass->vars['admin_group'] == $this->ipsclass->input['sub_new_group'] )
{
if ( $this->ipsclass->member['mgroup'] != $this->ipsclass->vars['admin_group'] )
{
$this->ipsclass->input['sub_new_group'] = 0;
}
}
$this->ipsclass->DB->do_update( 'subscriptions', array (
'sub_title' => str_replace( "'", "", str_replace( "'", "'", $this->ipsclass->input['sub_title'])),
'sub_desc' => $this->ipsclass->txt_safeslashes(trim($_POST['sub_desc'])),
'sub_new_group' => intval($this->ipsclass->input['sub_new_group']),
'sub_length' => $this->ipsclass->input['sub_length'],
'sub_unit' => $this->ipsclass->input['sub_unit'],
'sub_cost' => $this->ipsclass->input['sub_cost'],
'sub_run_module' => $this->ipsclass->input['sub_run_module'],
), "sub_id={$row['sub_id']}" );
$this->ipsclass->admin->save_log("Subscription Package '{$row['sub_title']}' edited");
$this->ipsclass->main_msg = 'Subscription Package edited';
$this->paysubs_index_packages();
}
/*-------------------------------------------------------------------------*/
// Subscription Package: Alter Form (edit/new)
/*-------------------------------------------------------------------------*/
function alter_package_form($type='edit')
{
$this->ipsclass->input['id'] = isset($this->ipsclass->input['id']) ? intval($this->ipsclass->input['id']) : 0;
//-------------------------------------------
// Get packages and get methods
//-------------------------------------------
$this->ipsclass->DB->build_query( array( 'select' => 'sub_id, sub_title, sub_cost', 'from' => 'subscriptions', 'order' => 'sub_cost' ) );
$this->ipsclass->DB->exec_query();
$packages = array();
while ( $p = $this->ipsclass->DB->fetch_row() )
{
$packages[] = array( $p['sub_id'], $p['sub_title'] );
if ( $p['sub_id'] == $subpkg_id )
{
$this_pkg = $p;
}
}
$methods = array();
$this->ipsclass->DB->build_query( array( 'select' => '*', 'from' => 'subscription_methods', 'order' => 'submethod_title' ) );
$this->ipsclass->DB->exec_query();
while ( $m = $this->ipsclass->DB->fetch_row() )
{
$methods[] = array( $m['submethod_id'], $m['submethod_title'] );
if ( $m['submethod_id'] == $method_id )
{
$this_mtd = $m;
}
}
if ( $type == 'edit' )
{
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->admin->error("Could not locate a payment gateway with the id of {$this->ipsclass->input['id']}");
}
$this->ipsclass->DB->build_query( array( 'select' => '*', 'from' => 'subscriptions', 'where' => "sub_id={$this->ipsclass->input['id']}" ) );
$this->ipsclass->DB->exec_query();
if ( ! $row = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->admin->error("Could not locate a payment gateway with the id of {$this->ipsclass->input['id']}");
}
$submit = 'Edit Package';
$code = 'doeditpackage';
$table = "Edit Package '{$row['sub_title']}'";
}
else
{
$row = array();
$submit = "Add Package";
$code = "doaddpackage";
$table = "Add new subscription package";
}
foreach( explode( ",", $row['sub_payment_allow'] ) as $p )
{
$allow_payment[$p] = 1;
}
//-------------------------------------------
// Grab member groups
//-------------------------------------------
$groups = array( 0 => array( 0, "--Don't Change Group--" ) );
$this->ipsclass->DB->build_query( array( 'select' => 'g_id,g_title', 'from' => 'groups', 'order' => 'g_title' ) );
$this->ipsclass->DB->exec_query();
while ( $r = $this->ipsclass->DB->fetch_row() )
{
// Don't allow non-roots to create packages that they can purchase to upgrade to root
if ( $this->ipsclass->vars['admin_group'] == $r['g_id'] )
{
if ( $this->ipsclass->member['mgroup'] != $this->ipsclass->vars['admin_group'] )
{
continue;
}
}
$groups[] = array( $r['g_id'], $r['g_title'] );
}
//-------------------------------------------
// Show form
//-------------------------------------------
$subchecked = $row['sub_unit'] == 'x' ? "checked='checked'" : '';
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , $code ),
2 => array( 'act' , 'msubs' ),
3 => array( 'id' , $this->ipsclass->input['id']),
4 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( " " , "40%" );
$this->ipsclass->adskin->td_header[] = array( " " , "60%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( $table );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Package Name" ,
$this->ipsclass->adskin->form_input("sub_title", $row['sub_title'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Package Description HTML is allowed" ,
$this->ipsclass->adskin->form_textarea("sub_desc", $row['sub_desc'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Subscription Duration" ,
$this->ipsclass->adskin->form_simple_input("sub_length", $row['sub_length'] ) .
" ". $this->ipsclass->adskin->form_dropdown( 'sub_unit',
array( 0 => array( 'w', 'Weeks' ), 1 => array( 'm', 'Months' ), 2 => array( 'y', 'Years' ) ),
$row['sub_unit'] )
." ",
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Subscription Costs Numerics and decimal points only please. Prices in your chosen default currency" ,
$this->ipsclass->adskin->form_simple_input("sub_cost", $row['sub_cost'] , 7)
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "New Member Group Select the member group that the member will be moved into when payment has been cleared." ,
$this->ipsclass->adskin->form_dropdown( 'sub_new_group' , $groups , $row['sub_new_group'] ),
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Run custom module on subscription start/end? Optional - Advanced users only" ,
"./sources/classes/paymentgateways/custom/cus_".$this->ipsclass->adskin->form_simple_input("sub_run_module", $row['sub_run_module'] , 7) .".php (File must be in this format and location)"
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form($submit);
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
//-------------------------------------------
// Quick Jump Table
//-------------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , 'editpkginfo'),
2 => array( 'act' , 'msubs' ),
4 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( " " , "40%" );
$this->ipsclass->adskin->td_header[] = array( " " , "60%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Edit Subscription / Gateway Specific Information");
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Payment Gateway" ,
$this->ipsclass->adskin->form_dropdown( 'method', $methods, $row['submethod_id'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Subscription Package" ,
$this->ipsclass->adskin->form_dropdown( 'sub', $packages, $row['sub_id'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form( "Go!" );
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->nav[] = array( $this->ipsclass->form_code.'&code=index-packages', 'Manage Packages' );
$this->ipsclass->admin->nav[] = array( '', 'Add/Edit Packages' );
$this->ipsclass->admin->output();
}
/*-------------------------------------------------------------------------*/
// Payment gateway: Complete Edit
/*-------------------------------------------------------------------------*/
function edit_method_complete()
{
$this->ipsclass->admin->page_detail .= " Please make sure that you have correctly set up any third party payment gateway before allowing them here in IPB";
$this->ipsclass->input['id'] = isset($this->ipsclass->input['id']) ? intval($this->ipsclass->input['id']) : 0;
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->admin->error("The chickens have escaped, there's feathers everywhere!");
}
$this->ipsclass->DB->build_query( array( 'select' => '*', 'from' => 'subscription_methods', 'where' => "submethod_id={$this->ipsclass->input['id']}" ) );
$this->ipsclass->DB->exec_query();
if ( ! $row = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->admin->error("Could locate a payment gateway with the id of {$this->ipsclass->input['id']}");
}
if ( $this->ipsclass->input['submethod_title'] == "" )
{
$this->ipsclass->admin->error("You must enter a valid title for this payment gateway");
}
$newbie = array (
'submethod_title' => $this->ipsclass->input['submethod_title'],
'submethod_desc' => $this->ipsclass->txt_safeslashes( $_POST['submethod_desc'] ),
'submethod_email' => $this->ipsclass->input['submethod_email'],
'submethod_active' => $this->ipsclass->input['submethod_active'],
'submethod_sid' => $this->ipsclass->input['submethod_sid'],
'submethod_is_cc' => $this->ipsclass->input['submethod_is_css'],
'submethod_is_auto' => $this->ipsclass->input['submethod_is_auto'],
'submethod_use_currency' => $this->ipsclass->input['submethod_use_currency'],
);
foreach( array( 1,2,3,4,5 ) as $id )
{
if ( isset($_POST['submethod_custom_'.$id]) )
{
$newbie[ 'submethod_custom_'.$id ] = $this->ipsclass->txt_safeslashes( $_POST['submethod_custom_'.$id] );
}
}
$this->ipsclass->DB->do_update( 'subscription_methods', $newbie, "submethod_id={$row['submethod_id']}" );
$this->ipsclass->admin->save_log("Payment gateway '{$row['submethod_title']}' edited");
$this->ipsclass->main_msg = "Payment gateway '{$row['submethod_title']}' edited";
$this->paysubs_index_gateways();
}
/*-------------------------------------------------------------------------*/
// Payment gateway: Edit Form
/*-------------------------------------------------------------------------*/
function edit_method()
{
$this->ipsclass->admin->page_detail .= " Please make sure that you have correctly set up any third party payment gateway before allowing them here in IPB";
$this->ipsclass->input['id'] = isset($this->ipsclass->input['id']) ? intval($this->ipsclass->input['id']) : 0;
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->admin->error("The chickens have escaped, there's feathers everywhere!");
}
$this->ipsclass->DB->build_query( array( 'select' => '*', 'from' => 'subscription_methods', 'where' => "submethod_id={$this->ipsclass->input['id']}" ) );
$this->ipsclass->DB->exec_query();
if ( ! $row = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->admin->error("Could locate a payment gateway with the id of {$this->ipsclass->input['id']}");
}
$currency = array();
$this_cur = "";
$this->ipsclass->DB->build_query( array( 'select' => '*', 'from' => 'subscription_currency' ) );
$this->ipsclass->DB->exec_query();
while ( $c = $this->ipsclass->DB->fetch_row() )
{
$currency[] = array( $c['subcurrency_code'], $c['subcurrency_desc'] );
if ( $c['subcurrency_default'] )
{
$this_cur = $c['subcurrency_code'];
}
}
//---------------------------------
// Forms like to mess up with entities
//---------------------------------
foreach( $row as $k => $v )
{
$row[$k] = $this->ipsclass->parse_clean_value( $v );
}
//---------------------------------
// Load the API...
//---------------------------------
$custom = array();
if ( @file_exists( ROOT_PATH . 'sources/classes/paymentgateways/class_gw_'.$row['submethod_name'].'.php' ) )
{
require_once( ROOT_PATH . 'sources/classes/paymentgateways/class_gw_core.php' );
require_once( ROOT_PATH . 'sources/classes/paymentgateways/class_gw_'.$row['submethod_name'].'.php' );
$this->gateway = new class_gw_module();
//----------------------------------
// Sort out the custom method fields
//----------------------------------
$form = $this->gateway->acp_return_method_variables();
foreach( $form as $name => $data )
{
if ( $data['used'] != 0 )
{
$custom[] = $this->ipsclass->adskin->add_td_row( array( "{$data['formname']} {$data['formextra']}" ,
$this->ipsclass->adskin->form_input( $name, $row[ $name ] )
) );
}
}
}
else
{
$this->ipsclass->admin->error("Could not locate the API in: ".ROOT_PATH . 'sources/classes/paymentgateways/class_gw_'.$row['submethod_name'].'.php');
}
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , 'edit_method_complete' ),
2 => array( 'act' , 'msubs' ),
3 => array( 'id' , $this->ipsclass->input['id'] ),
4 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( " " , "40%" );
$this->ipsclass->adskin->td_header[] = array( " " , "60%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "{$row['submethod_title']}'s Gateway Settings" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Gateway Public Name" ,
$this->ipsclass->adskin->form_input("submethod_title", $row['submethod_title'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Gateway Public Description" ,
$this->ipsclass->adskin->form_textarea("submethod_desc", $row['submethod_desc'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Gateway Associated Email Address OR associated transaction key This is not needed for all gateways." ,
$this->ipsclass->adskin->form_input("submethod_email", $row['submethod_email'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Gateway Store / Seller ID This is not needed for all gateways." ,
$this->ipsclass->adskin->form_input("submethod_sid", $row['submethod_sid'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Gateway auto-completes order via return validation? If the gateway does not support a return validation method, then make sure this is off." ,
$this->ipsclass->adskin->form_yes_no("submethod_is_auto", $row['submethod_is_auto'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Gateway default currency? Select the currency this gateway uses." ,
$this->ipsclass->adskin->form_dropdown("submethod_use_currency", $currency, $row['submethod_use_currency'] )
) );
if ( count( $custom ) > 0 )
{
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic( 'Gateway Specific Settings', 'left', 'catrow2' );
$this->ipsclass->html .= implode( "\n", $custom );
}
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Activate this Gateway? This will allow your members to use this option." ,
$this->ipsclass->adskin->form_yes_no("submethod_active", $row['submethod_active'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form("Edit Settings");
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->nav[] = array( '', 'Editing '.$row['submethod_title'].' Gateway' );
$this->ipsclass->admin->output();
}
/*-------------------------------------------------------------------------*/
// Show index screen
/*-------------------------------------------------------------------------*/
function paysubs_index_gateways()
{
//---------------------------------------
// INIT
//---------------------------------------
$packages_cache = array();
$pack_dropdown = "";
$trans = array();
$dead = array();
$pending = array();
$totals = array();
//---------------------------------------
// Title
//---------------------------------------
$this->ipsclass->admin->page_detail .= "