From da908c23115915f34890e19cb4f3f2fb3b170892 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 3 Jan 2008 13:28:15 +0000 Subject: [PATCH] added pspadmin --- psp_admin/README | 1 + psp_admin/inc/class.bo_pspadmin.inc.php | 105 ++ psp_admin/inc/class.so_oscadminapi.inc.php | 60 + psp_admin/inc/class.so_pspadmin.inc.php | 312 ++++ psp_admin/inc/class.ui_pspadmin.inc.php | 251 ++++ psp_admin/inc/functions.inc.php | 14 + psp_admin/inc/header.inc.php | 14 + psp_admin/inc/hook_admin.inc.php | 23 + psp_admin/inc/hook_manual.inc.php | 19 + psp_admin/inc/hook_preferences.inc.php | 22 + .../inc/payment_modules/cc_validation.php | 85 ++ .../inc/payment_modules/checkout_shipping.php | 452 ++++++ .../checkout_shipping_address.php | 516 +++++++ psp_admin/inc/payment_modules/currencies.php | 71 + psp_admin/inc/payment_modules/database.php | 152 ++ psp_admin/inc/payment_modules/general.php | 1253 +++++++++++++++++ psp_admin/inc/payment_modules/html_output.php | 298 ++++ psp_admin/inc/payment_modules/order.php | 170 +++ psp_admin/inc/payment_modules/payment.php | 237 ++++ psp_admin/inc/payment_modules/payment/cc.php | 220 +++ psp_admin/inc/payment_modules/payment/cod.php | 119 ++ .../inc/payment_modules/payment/ogone.php | 148 ++ .../inc/payment_modules/payment/paypal.php | 141 ++ psp_admin/inc/payment_modules/shipping.php | 93 ++ psp_admin/inc/payment_modules/validations.php | 122 ++ psp_admin/inc/wrap_osc_payment.php | 130 ++ psp_admin/inc/wrap_osc_plugin.php | 49 + psp_admin/index.php | 27 + 28 files changed, 5104 insertions(+) create mode 100644 psp_admin/README create mode 100644 psp_admin/inc/class.bo_pspadmin.inc.php create mode 100644 psp_admin/inc/class.so_oscadminapi.inc.php create mode 100644 psp_admin/inc/class.so_pspadmin.inc.php create mode 100644 psp_admin/inc/class.ui_pspadmin.inc.php create mode 100755 psp_admin/inc/functions.inc.php create mode 100755 psp_admin/inc/header.inc.php create mode 100755 psp_admin/inc/hook_admin.inc.php create mode 100644 psp_admin/inc/hook_manual.inc.php create mode 100755 psp_admin/inc/hook_preferences.inc.php create mode 100644 psp_admin/inc/payment_modules/cc_validation.php create mode 100644 psp_admin/inc/payment_modules/checkout_shipping.php create mode 100644 psp_admin/inc/payment_modules/checkout_shipping_address.php create mode 100644 psp_admin/inc/payment_modules/currencies.php create mode 100644 psp_admin/inc/payment_modules/database.php create mode 100644 psp_admin/inc/payment_modules/general.php create mode 100644 psp_admin/inc/payment_modules/html_output.php create mode 100644 psp_admin/inc/payment_modules/order.php create mode 100644 psp_admin/inc/payment_modules/payment.php create mode 100644 psp_admin/inc/payment_modules/payment/cc.php create mode 100644 psp_admin/inc/payment_modules/payment/cod.php create mode 100644 psp_admin/inc/payment_modules/payment/ogone.php create mode 100644 psp_admin/inc/payment_modules/payment/paypal.php create mode 100644 psp_admin/inc/payment_modules/shipping.php create mode 100755 psp_admin/inc/payment_modules/validations.php create mode 100644 psp_admin/inc/wrap_osc_payment.php create mode 100644 psp_admin/inc/wrap_osc_plugin.php create mode 100644 psp_admin/index.php diff --git a/psp_admin/README b/psp_admin/README new file mode 100644 index 0000000000..6648e20476 --- /dev/null +++ b/psp_admin/README @@ -0,0 +1 @@ +See /doc for all information about this app. diff --git a/psp_admin/inc/class.bo_pspadmin.inc.php b/psp_admin/inc/class.bo_pspadmin.inc.php new file mode 100644 index 0000000000..940ceb3dd6 --- /dev/null +++ b/psp_admin/inc/class.bo_pspadmin.inc.php @@ -0,0 +1,105 @@ +so = CreateObject('psp_admin.so_pspadmin'); + } + + function get_installed_modules($wrapper) + { + switch($wrapper) + { + case 'oscommerce': + $fsplugins = $this->so->oscom_fsmodules(); + $dbplugins = $this->so->oscom_dbmodules(); + + foreach($dbplugins as $key=>$plugin) + { + $dbplugins[$key] = substr("$plugin",0,strpos($plugin,".php")); + } + + if ($dbplugins=='') $dbplugins = array(); + if ($fsplugins=='') $fsplugins = array(); + foreach($fsplugins as $record) + { + if(in_array($record, $dbplugins)) + { + $_ret[] = array($record,'installed'); + } else $_ret[] = array($record, 'not_yet'); + } + + foreach($dbplugins as $record) + { + if(!in_array($record, $fsplugins)) + { + if($record != '') $_ret[] = array($record, 'broken'); + } + } + break; + default: + $_ret = 'not yet.'; + break; + } + return $_ret; + } + + function oscom_install($module) + { + require_once(EGW_INCLUDE_ROOT."/psp_admin/inc/wrap_osc_plugin.php"); + $osc_wrap = new wrap_osc_plugin($module); + $debugmess = $osc_wrap->install(); + // todo: if and only if it really happened + // insert it into the PAYMODINSTALLED list + $this->so->oscom_installmod($module); + return $module.' module installed.'; + } + + function oscom_remove($module) + { + require_once(EGW_INCLUDE_ROOT."/psp_admin/inc/wrap_osc_plugin.php"); + $osc_wrap = new wrap_osc_plugin($module); + $debugmess = $osc_wrap->remove(); + // todo: if and only if it really happened + // remove it from the PAYMODINSTALLED list + $this->so->oscom_removemod($module); + return $module.' module removed.'; + } + + function oscom_broken($module) + { + return 'error.'; + } + + function config_module($module) + { + // form based on keys, values and types of plugin + // + require_once(EGW_INCLUDE_ROOT."/psp_admin/inc/wrap_osc_plugin.php"); + $osc_wrap = new wrap_osc_plugin($module); + // get the keys and their values + $plugin_keys = $osc_wrap->keys(); + + foreach($plugin_keys as $record) + { + $plugin_values[] = $this->so->oscmod_values($record); + + $plugin_functions[$record] = $this->so->oscmod_functions($record); + } + // create displaybox 2d-array pluginkey[title, value, description] + foreach($plugin_keys as $key=>$record) + { + //$display[$record] = array_values($plugin_values[$key]); + $display[$record] = $plugin_values[$key]; + } + return array($display, $plugin_functions); + } + +} diff --git a/psp_admin/inc/class.so_oscadminapi.inc.php b/psp_admin/inc/class.so_oscadminapi.inc.php new file mode 100644 index 0000000000..dab77dce62 --- /dev/null +++ b/psp_admin/inc/class.so_oscadminapi.inc.php @@ -0,0 +1,60 @@ +load(); + $this->user_id = $GLOBALS['egw_info']['user']['account_id']; + + } + + + function load() + { + $this->sessiondata = $GLOBALS['phpgw']->session->appsession('session_data','oscadminapi'); + } + + function save_session() + { + if(count($this->sessiondata) > 0) //this catches the bug in the phpgwapi crypto class.. + { + $GLOBALS['phpgw']->session->appsession('session_data','oscadminapi',$this->sessiondata); + } + } + + function save_token($token) + { + $GLOBALS['phpgw']->session->appsession('sestoken','oscadminapi',$token); + } + + function load_token() + { + return $GLOBALS['phpgw']->session->appsession('sestoken','oscadminapi'); + } + + function getPersonalData($id) + { + $account =& CreateObject('phpgwapi.accounts',(int)$id,'u'); + $contact = $GLOBALS['egw']->contacts =& CreateObject('phpgwapi.contacts'); + $userData = $account->read_repository(); + $c_arr = $contact->read($userData['person_id']); + #_Debug_array($userData); + #_Debug_array($c_arr); + + return array_merge($userData,$c_arr); + } + + } +?> diff --git a/psp_admin/inc/class.so_pspadmin.inc.php b/psp_admin/inc/class.so_pspadmin.inc.php new file mode 100644 index 0000000000..040ae25cb3 --- /dev/null +++ b/psp_admin/inc/class.so_pspadmin.inc.php @@ -0,0 +1,312 @@ +db = $GLOBALS['egw']->db; + } + + function default_settings() + { + // this needs to be cleaned/stripped whatever + // make the modules work without these settings + return array( + 'FILENAME_CHECKOUT_PROCESS' => array( + 'configuration_title' => 'FILENAME_CHECKOUT_PROCESS', + 'configuration_value' => 'index.php?menuaction=confirmcheckoutfunction', + 'configuration_description' => 'checkout process', + 'use_function' => 'NULL', + 'set_function' => 'NULL' + ), + 'STORE_NAME' => array( + 'configuration_title' => 'Store Name', + 'configuration_value'=>'INSTALL', + 'configuration_description'=>'The name of your store', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'STORE_OWNER' => array( + 'configuration_title'=>'Store Owner', + 'configuration_value'=>'Fill in', + 'configuration_description'=>'The name of my store owner', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'EMAIL_FROM' => array( + 'configuration_title'=>'E-Mail From', + 'configuration_value'=>'jataggo hosting ', + 'configuration_description'=>'The e-mail address used in (sent) e-mails', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'STORE_COUNTRY' => array( + 'configuration_title'=>'Country', + 'configuration_value'=>'223', + 'configuration_description'=>'The country my store is located in
Note: Please remember to update the store zone.', + 'use_function'=>'tep_get_country_name', + 'set_function'=>'tep_cfg_pull_down_country_list(' + ), + 'STORE_ZONE' => array( + 'configuration_title'=>'Zone', + 'configuration_value'=>'18', + 'configuration_description'=>'The zone my store is located in', + 'use_function'=>'tep_cfg_get_zone_name', + 'set_function'=>'tep_cfg_pull_down_zone_list(' + ), + 'STORE_NAME_ADDRESS' => array( + 'configuration_title'=>'Store Address and Phone', + 'configuration_value'=>'Jataggo.com', + 'configuration_description'=>'This is the Store Name, Address and Phone used on printable documents and displayed online', + 'use_function'=>'NULL', + 'set_function'=>'tep_cfg_textarea(' + ), + 'DEFAULT_CURRENCY' => array( + 'configuration_title'=>'Default Currency', + 'configuration_value'=>'EUR', + 'configuration_description'=>'Default Currency', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'DEFAULT_LANGUAGE' => array( + 'configuration_title'=>'Default Language', + 'configuration_value'=>'NL', + 'configuration_description'=>'Default Language', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'DEFAULT_ORDERS_STATUS_ID' => array( + 'configuration_title'=>'Default Order Status For New Orders', + 'configuration_value'=>'1', + 'configuration_description'=>'When a new order is created, this order status will be assigned to it.', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'DIR_WS_LANGUAGES' => array( + 'configuration_title'=>'DIR_WS_LANGUAGES', + 'configuration_value'=>'inc/languages/', + 'configuration_description'=>'', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'DIR_WS_MODULES' => array( + 'configuration_title'=>'DIR_WS_MODULES', + 'configuration_value'=>'inc/payment_modules/', + 'configuration_description'=>'', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'JS_ERROR' => array( + 'configuration_title'=>'JS_ERROR', + 'configuration_value'=>'there was a javasript error', + 'configuration_description'=>'', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'JS_ERROR_NO_PAYMENT_MODULE_SELECTED' => array( + 'configuration_title'=>'JS_ERROR_NO_PAYMENT_MODULE_SELECTED', + 'configuration_value'=>'No payment module selected', + 'configuration_description'=>'', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'HTTPS_SERVER' => array( + 'configuration_title'=>'HTTPS_SERVER', + 'configuration_value'=>'http://xoo.cybro.info/web_ries/egroupware/', + 'configuration_description'=>'', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'DIR_WS_HTTPS_CATALOG' => array( + 'configuration_title'=>'', + 'configuration_value'=>'', + 'configuration_description'=>'', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'FILENAME_CHECKOUT_PAYMENT' => array( + 'configuration_title'=>'', + 'configuration_value'=>'?menuaction=paymentError', + 'configuration_description'=>'', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ), + 'DIR_WS_CLASSES' => array( + 'configuration_title'=>'', + 'configuration_value'=>'inc/payment_modules/', + 'configuration_description'=>'', + 'use_function'=>'NULL', + 'set_function'=>'NULL' + ) + ); + } + + function get_settings() + { + $keys = array_keys($this->default_settings()); + $keysstr = implode('","',$keys); + $query = 'SELECT configuration_value FROM '.CONF_TABLE.' WHERE configuration_key IN ("'.$keysstr.'");'; + $erres = $this->db->query($query); + while ($this->db->next_record()) + { + $_res[] = $this->db->row(); + } + foreach($_res as $key=>$record) + { + $_vals[$keys[$key]] = $_res[$key]['configuration_value']; + } + return $_vals; + } + + function check_tables() + { + // 1. everything OK + // 2. first entry in db is not MODULE_PAYMENT_INSTALLED: error + // 3. rows are missing: settings not ok. + + $query="SELECT configuration_key FROM ".CONF_TABLE." WHERE configuration_id = '1';"; + $this->db->query($query); + while ($this->db->next_record()) + { + $_result = $this->db->row(); + } + if( $_result['configuration_key'] != 'MODULE_PAYMENT_INSTALLED' ) + { + return 'check_tables failed: MODPAYINSTALLED'; + } + $mand_keys = implode('","',array_keys($this->default_settings())); + $query = 'SELECT configuration_key FROM '.CONF_TABLE.' WHERE configuration_key IN ("'.$mand_keys.'");'; + $erres = $this->db->query($query); + while ($this->db->next_record()) + { + $_res[] = $this->db->row(); + } + if ($_res = '' || count(array_keys($this->default_settings())) != count(array_keys($_res))) + { + return 'check_tables failed: empty rows'; + } + return True; + } + + function oscom_fsmodules($dir=PAYMOD_DIR) + { + // loops through the given directory for possible plugins + $_list = scandir($dir); + if( ($_list == FALSE) || ($_list == '') ) { + $list[0] = 'empty or error while processing scandir'; + return $list; + } + // return only the .php entries (without .php) + foreach($_list as $record) + { + if(strpos($record,'.php')) { + $list[] = substr($record, 0, -4); + } + } + return $list; + } + + + function oscom_dbmodules() + { + $query = "SELECT configuration_value FROM ".CONF_TABLE." WHERE configuration_key = 'MODULE_PAYMENT_INSTALLED'; "; + $geti = $this->db->query($query); + while ($this->db->next_record()) + { + $row = $this->db->row(); + if ($row['configuration_value'] != '') + { + return explode(';',$row['configuration_value']); + //return explode(';',str_replace('.php','',$row['configuration_value'])); + } else return array(); + } + + } + + function oscom_installmod($module) + { + $module .= '.php'; + $_list= $this->oscom_dbmodules(); + if($_list == '') $_list = array($module); // nothing installed yet + else + { + // no duplicates + if(!array_search($module, $_list)) $_list[] = $module; + } + $this->update_oscommod($_list); + } + + function oscom_removemod($module) + { + $module .= '.php'; + $_list= $this->oscom_dbmodules(); + if(array_search($module, $_list) || $_list[0] = $module) + { + unset($_list[array_search($module, $_list)]); // remove + } + $this->update_oscommod($_list); + } + + function update_oscommod($arr) + { + if(count($arr) > 1) + { + $new = implode($arr, ';'); + } else $new = $arr[0]; + $query = "UPDATE egw_oscadmin_osc_conf SET configuration_value = '$new' WHERE configuration_key = 'MODULE_PAYMENT_INSTALLED';"; + $this->db->query($query); + } + + function oscmod_values($config_key) + { + // + $_columns = 'configuration_title, configuration_value, configuration_description'; + $query = 'SELECT ' .$_columns. ' FROM ' .CONF_TABLE. ' WHERE configuration_key = "' .$config_key. '";'; + + $this->db->query($query); + while ($this->db->next_record()) + { + $values_arr = $this->db->row(); + } + return $values_arr; + } + + /** + * get_plugin_functions + **/ + function oscmod_functions($_key) + { + + $query = 'SELECT use_function, set_function FROM ' .CONF_TABLE. ' WHERE configuration_key = "' .$_key. '";'; + $erres = $this->db->query($query); + while ($this->db->next_record()) + { + $values_arr = $this->db->row(); + if($values_arr['use_function'] == "") $values_arr['use_function'] = "NO_FUNC"; + if($values_arr['set_function'] == "") $values_arr['set_function'] = "NO_FUNC"; + } + return $values_arr; + } + + function confedit($key, $newvalue) + { + // + $query = "UPDATE ".CONF_TABLE." SET configuration_value = '$newvalue' WHERE configuration_key = '$key';"; + $this->db->query($query); + } +} + + + + diff --git a/psp_admin/inc/class.ui_pspadmin.inc.php b/psp_admin/inc/class.ui_pspadmin.inc.php new file mode 100644 index 0000000000..00981fc64e --- /dev/null +++ b/psp_admin/inc/class.ui_pspadmin.inc.php @@ -0,0 +1,251 @@ + True, + 'settings' => True, + 'apitesting' => True, + 'sidebox_menu' => True + ); + + function ui_pspadmin() + { + $this->sav2 = CreateObject('phpgwapi.tplsavant2'); + $this->bo = CreateObject('psp_admin.bo_pspadmin'); + + // nec. + if(!$this->checks()) + { + die('UI:: checks failed.'); + } + if(isset($_POST['wrapper'])) + { + $this->wrapper = $_POST['wrapper']; + } else // this is for now... but should be handled by POST + { + $this->wrapper = 'oscommerce'; + } + $this->module = $_GET['plug']; + } + + function sidebox_menu() + { + $appname = 'psp_admin'; + $content = Array( + '0' => array( + 'link'=>$GLOBALS['phpgw']->link('/index.php','menuaction=psp_admin.ui_pspadmin.modules'), + 'icon'=>( ($_GET['menuaction']=='psp_admin.ui_pspadmin.modules'||!$_GET['menuaction']) ?'c_plan_a':'c_plan'), + 'text'=>'Modules' + ), + '1' => array( + 'link'=>$GLOBALS['phpgw']->link('/index.php','menuaction=psp_admin.ui_pspadmin.settings'), + 'icon'=>( ($_GET['menuaction']=='psp_admin.ui_pspadmin.settings'||!$_GET['menuaction']) ?'settings':'settings'), + 'text'=>'Settings' + ) + ); + $menu_title = lang('PSP Admin'); + display_sidebox($appname,$menu_title,$content); + } + + function showMe($template) + { + $this->sav2->baselink = $GLOBALS['phpgw']->link('/index.php','menuaction=psp_admin.ui_pspadmin.').$template; + $GLOBALS['egw']->common->phpgw_header(); + echo parse_navbar(); + $this->sav2->display($template.'.tpl.php'); + $GLOBALS['egw']->common->phpgw_footer(); + } + + function modules() + { + switch($_POST['submitted']) + { + case false: + break; + case 'update': + $this->process_post( 'modules' , $_POST); + case 'cancel': + $this->sav2->module = $this->module = $_POST['payplug']; + $_res = $this->bo->config_module($this->module); + $this->sav2->selection = $_res[0]; + $this->sav2->modinfo = $this->sav2->fetch('confmod.tpl.php'); + break; + default: + die('no strange posting here.'); + } + + $this->sav2->wrapper = $this->wrapper; + + if(isset($_GET['act']) && isset($_GET['plug']) && True) // todo: True replaced by sec.expression + { + if($this->wrapper == 'oscommerce') + { + $this->sav2->module = $_GET['plug']; + switch($_GET['act']) + { + case 'editmod': // when we actually want to change something + $selection = $this->bo->config_module($this->module); + $this->sav2->editline = 'no'; + $this->sav2->dim2array = $this->gen_form('modules',$selection[0],'text', '10','255',$this->module); + $result = $this->sav2->fetch('generic_form.tpl.php'); + break; + case 'install': + $result = $this->bo->oscom_install($_GET['plug']); + break; + case 'remove': + $result = $this->bo->oscom_remove($_GET['plug']); + break; + case 'broken': + $result = $this->bo->oscom_broken($_GET['plug']); + break; + case 'conf': + $_res = $this->bo->config_module($this->module); //$_GET['plug']); hm.., redundancy + $this->sav2->selection = $_res[0]; + $result = $this->sav2->fetch('confmod.tpl.php'); + break; + default: + die('illegal call to function.'); + } + $this->sav2->modinfo = $result; + } + else $this->sav2->infomsg = 'oh? another wrapper?'; + } + $mod_overview = $this->bo->get_installed_modules($this->wrapper); + if(!is_array($mod_overview)) $this->sav2->infomsg = $mod_overview; // on error: display it + else $this->sav2->list = $mod_overview; + + + $this->showMe('modules'); + } + + function process_post( $from ,$arr) + { + switch($from) + { + case 'modules': + $this->module = $arr['payplug']; + unset($arr['payplug']); unset($arr['submitted']); + break; + case 'settings': + unset($arr['submitted']); + break; + default: + die('nope.'); + } + foreach( $arr as $key=>$value ) + { + $this->bo->so->confedit($key, $value); + } + } + + function settings() + { + switch($_POST['submitted']) + { + case false: + break; + case 'update': + $this->process_post( 'settings' , $_POST); + break; + case 'cancel': + break; + default: + die('no strange posting here.'); + break; + } + + + $this->sav2->settings = $this->bo->so->get_settings(); + $this->sav2->wrapper = $this->wrapper; + $this->showMe('settings'); + } + + function checks() + { + // check if this page is reached in a proper way + + // check if the necessary tables exist and are sane + $_ret = $this->bo->so->check_tables(); + if(!$_ret) $this->sav2->infomsg = $_ret; + else return True; + } + + function gen_form($link2func, $update, $type, $size, $maxl, $payplug) + { + $this->sav2->form['baselink'] = $GLOBALS['phpgw']->link('/index.php','menuaction=psp_admin.ui_pspadmin.'.$link2func); + $this->sav2->form['update'] = $update; + $this->sav2->form['type'] = $type; + $this->sav2->form['size'] = $size; + $this->sav2->form['max'] = $maxl; + $this->sav2->form['payplug'] = $payplug; + $this->sav2->genset_form = $this->sav2->fetch('generic_form.tpl.php'); + } + + + // ================================================== + // begin skeleton : api access +/* + function apitesting() + { + // + $fail_url = 'psp_admin.ui_pspadmin.apifail'; + $success_url = 'psp_admin.ui_pspadmin.apisuccess'; + $base_url = 'psp_admin.ui_pspadmin.apitesting' ; // app.class.function + + $stoken = md5(uniqid(rand(), true)); + + if($_POST[submitted] != True) + { + $this->sav2->assign('step',1); + $this->sav2->assign('title',"1"); + $content = $this->sav2->fetch("stepbefore.tpl.php"); + } + else + { + require_once(EGW_SERVER_ROOT.'/psp_admin/inc/class.oscadminapi.inc.php'); + $oscapi = new oscadminapi(); + $content = $oscapi->purchase($stoken, $amount, $fail_url, $success_url, $base_url, $_POST); + } + + + $this->sav2->assign('content',$content); + $this->showMe('apitest'); + + } + + function apifail() + { + die('something went wrong. please try again.'); + } + + function apisuccess() + { + die('Thank You.'); + } + */ + + // end testing of oscadminapi + // ================================================== + + +} + +?> + diff --git a/psp_admin/inc/functions.inc.php b/psp_admin/inc/functions.inc.php new file mode 100755 index 0000000000..c4dc87079a --- /dev/null +++ b/psp_admin/inc/functions.inc.php @@ -0,0 +1,14 @@ + diff --git a/psp_admin/inc/header.inc.php b/psp_admin/inc/header.inc.php new file mode 100755 index 0000000000..aac8c4b56e --- /dev/null +++ b/psp_admin/inc/header.inc.php @@ -0,0 +1,14 @@ + diff --git a/psp_admin/inc/hook_admin.inc.php b/psp_admin/inc/hook_admin.inc.php new file mode 100755 index 0000000000..9da0624e90 --- /dev/null +++ b/psp_admin/inc/hook_admin.inc.php @@ -0,0 +1,23 @@ + diff --git a/psp_admin/inc/hook_manual.inc.php b/psp_admin/inc/hook_manual.inc.php new file mode 100644 index 0000000000..9dac2cecf1 --- /dev/null +++ b/psp_admin/inc/hook_manual.inc.php @@ -0,0 +1,19 @@ + diff --git a/psp_admin/inc/hook_preferences.inc.php b/psp_admin/inc/hook_preferences.inc.php new file mode 100755 index 0000000000..6c7470439f --- /dev/null +++ b/psp_admin/inc/hook_preferences.inc.php @@ -0,0 +1,22 @@ + * + * -------------------------------------------- * + * 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. * + \**************************************************************************/ + + /* $Id: hook_preferences.inc.php,v 1.14 2005/07/23 15:52:48 ralfbecker Exp $ */ + { + $title = $appname; + $file = Array( + 'Preferences' => $GLOBALS['phpgw']->link('/preferences/preferences.php','appname='.$appname) + ); + display_section($appname,$title,$file); + } + +?> diff --git a/psp_admin/inc/payment_modules/cc_validation.php b/psp_admin/inc/payment_modules/cc_validation.php new file mode 100644 index 0000000000..bd81c1dd57 --- /dev/null +++ b/psp_admin/inc/payment_modules/cc_validation.php @@ -0,0 +1,85 @@ +cc_number = ereg_replace('[^0-9]', '', $number); + + if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) { + $this->cc_type = 'Visa'; + } elseif (ereg('^5[1-5][0-9]{14}$', $this->cc_number)) { + $this->cc_type = 'Master Card'; + } elseif (ereg('^3[47][0-9]{13}$', $this->cc_number)) { + $this->cc_type = 'American Express'; + } elseif (ereg('^3(0[0-5]|[68][0-9])[0-9]{11}$', $this->cc_number)) { + $this->cc_type = 'Diners Club'; + } elseif (ereg('^6011[0-9]{12}$', $this->cc_number)) { + $this->cc_type = 'Discover'; + } elseif (ereg('^(3[0-9]{4}|2131|1800)[0-9]{11}$', $this->cc_number)) { + $this->cc_type = 'JCB'; + } elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) { + $this->cc_type = 'Australian BankCard'; + } else { + return -1; + } + if (is_numeric($expiry_m) && ($expiry_m > 0) && ($expiry_m < 13)) { + $this->cc_expiry_month = $expiry_m; + } else { + return -2; + } + + $current_year = date('Y'); + $expiry_y = substr($current_year, 0, 2) . $expiry_y; + if (is_numeric($expiry_y) && ($expiry_y >= $current_year) && ($expiry_y <= ($current_year + 10))) { + $this->cc_expiry_year = $expiry_y; + } else { + return -3; + } + + if ($expiry_y == $current_year) { + if ($expiry_m < date('n')) { + return -4; + } + } + + return $this->is_valid(); + } + + function is_valid() { + $cardNumber = strrev($this->cc_number); + $numSum = 0; + + for ($i=0; $i 9) { + $firstNum = $currentNum % 10; + $secondNum = ($currentNum - $firstNum) / 10; + $currentNum = $firstNum + $secondNum; + } + + $numSum += $currentNum; + } + +// If the total has no remainder it's OK + return ($numSum % 10 == 0); + } + } +?> diff --git a/psp_admin/inc/payment_modules/checkout_shipping.php b/psp_admin/inc/payment_modules/checkout_shipping.php new file mode 100644 index 0000000000..900a6bedcf --- /dev/null +++ b/psp_admin/inc/payment_modules/checkout_shipping.php @@ -0,0 +1,452 @@ +set_snapshot(); + tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); + } + +// if there is nothing in the customers cart, redirect them to the shopping cart page + if ($cart->count_contents() < 1) { + tep_redirect(tep_href_link(FILENAME_SHOPPING_CART)); + } + +// if no shipping destination address was selected, use the customers own address as default + if (!tep_session_is_registered('sendto')) { + tep_session_register('sendto'); + $sendto = $customer_default_address_id; + } else { +// verify the selected shipping address + $check_address_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$sendto . "'"); + $check_address = tep_db_fetch_array($check_address_query); + + if ($check_address['total'] != '1') { + $sendto = $customer_default_address_id; + if (tep_session_is_registered('shipping')) tep_session_unregister('shipping'); + } + } + + require(DIR_WS_CLASSES . 'order.php'); + $order = new order; + +// register a random ID in the session to check throughout the checkout procedure +// against alterations in the shopping cart contents + if (!tep_session_is_registered('cartID')) tep_session_register('cartID'); + $cartID = $cart->cartID; + +// if the order contains only virtual products, forward the customer to the billing page as +// a shipping address is not needed + if ($order->content_type == 'virtual') { + if (!tep_session_is_registered('shipping')) tep_session_register('shipping'); + $shipping = false; + $sendto = false; + tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); + } + + $total_weight = $cart->show_weight(); + $total_count = $cart->count_contents(); + +// load all enabled shipping modules + require(DIR_WS_CLASSES . 'shipping.php'); + $shipping_modules = new shipping; + + if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') ) { + $pass = false; + + switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) { + case 'national': + if ($order->delivery['country_id'] == STORE_COUNTRY) { + $pass = true; + } + break; + case 'international': + if ($order->delivery['country_id'] != STORE_COUNTRY) { + $pass = true; + } + break; + case 'both': + $pass = true; + break; + } + + $free_shipping = false; + if ( ($pass == true) && ($order->info['total'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) { + $free_shipping = true; + + include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php'); + } + } else { + $free_shipping = false; + } + +// process the selected shipping method + if ( isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process') ) { + if (!tep_session_is_registered('comments')) tep_session_register('comments'); + if (tep_not_null($HTTP_POST_VARS['comments'])) { + $comments = tep_db_prepare_input($HTTP_POST_VARS['comments']); + } + + if (!tep_session_is_registered('shipping')) tep_session_register('shipping'); + + if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) { + if ( (isset($HTTP_POST_VARS['shipping'])) && (strpos($HTTP_POST_VARS['shipping'], '_')) ) { + $shipping = $HTTP_POST_VARS['shipping']; + + list($module, $method) = explode('_', $shipping); + if ( is_object($$module) || ($shipping == 'free_free') ) { + if ($shipping == 'free_free') { + $quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE; + $quote[0]['methods'][0]['cost'] = '0'; + } else { + $quote = $shipping_modules->quote($method, $module); + } + if (isset($quote['error'])) { + tep_session_unregister('shipping'); + } else { + if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) { + $shipping = array('id' => $shipping, + 'title' => (($free_shipping == true) ? $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'), + 'cost' => $quote[0]['methods'][0]['cost']); + + tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); + } + } + } else { + tep_session_unregister('shipping'); + } + } + } else { + $shipping = false; + + tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); + } + } + +// get all available shipping quotes + $quotes = $shipping_modules->quote(); + +// if no shipping method has been selected, automatically select the cheapest method. +// if the modules status was changed when none were available, to save on implementing +// a javascript force-selection method, also automatically select the cheapest shipping +// method if more than one module is now enabled + if ( !tep_session_is_registered('shipping') || ( tep_session_is_registered('shipping') && ($shipping == false) && (tep_count_shipping_modules() > 1) ) ) $shipping = $shipping_modules->cheapest(); + + require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_SHIPPING); + + $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')); + $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')); +?> + +> + + +<?php echo TITLE; ?> + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + 0) { +?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + +
+ + + +
+ + + + + +

' . tep_image_button('button_change_address.gif', IMAGE_BUTTON_CHANGE_ADDRESS) . ''; ?>
+ + + + + + +
' . TITLE_SHIPPING_ADDRESS . '
' . tep_image(DIR_WS_IMAGES . 'arrow_south_east.gif'); ?>
'); ?>
+ + + +
+ + + +
+ 1 && sizeof($quotes[0]) > 1) { +?> + + + + + + + + + + + + + + + + + + + + + + + + + +
' . TITLE_PLEASE_SELECT . '
' . tep_image(DIR_WS_IMAGES . 'arrow_east_south.gif'); ?>
+ + + + + + + + + + +
 
format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)) . tep_draw_hidden_field('shipping', 'free_free'); ?>
+ + + + + + + + + + + +' . "\n"; + } else { + echo ' ' . "\n"; + } +?> + + + 1) || ($n2 > 1) ) { +?> + + + + + + + + +
 
format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))); ?>format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax'])) . tep_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']); ?>
+ + + +
+ + + +
+ + + +
+ + + +
+ + + + + + +
' . TITLE_CONTINUE_CHECKOUT_PROCEDURE . '
' . TEXT_CONTINUE_CHECKOUT_PROCEDURE; ?>
+ + + + + + + + + + + + +
+ + + + +
+ + + + +
+ + + +
+ + + + + +
+ + + diff --git a/psp_admin/inc/payment_modules/checkout_shipping_address.php b/psp_admin/inc/payment_modules/checkout_shipping_address.php new file mode 100644 index 0000000000..70210c5be3 --- /dev/null +++ b/psp_admin/inc/payment_modules/checkout_shipping_address.php @@ -0,0 +1,516 @@ +set_snapshot(); + tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); + } + +// if there is nothing in the customers cart, redirect them to the shopping cart page + if ($cart->count_contents() < 1) { + tep_redirect(tep_href_link(FILENAME_SHOPPING_CART)); + } + + // needs to be included earlier to set the success message in the messageStack + require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_SHIPPING_ADDRESS); + + require(DIR_WS_CLASSES . 'order.php'); + $order = new order; + +// if the order contains only virtual products, forward the customer to the billing page as +// a shipping address is not needed + if ($order->content_type == 'virtual') { + if (!tep_session_is_registered('shipping')) tep_session_register('shipping'); + $shipping = false; + if (!tep_session_is_registered('sendto')) tep_session_register('sendto'); + $sendto = false; + tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); + } + + $error = false; + $process = false; + if (isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'submit')) { +// process a new shipping address + if (tep_not_null($HTTP_POST_VARS['firstname']) && tep_not_null($HTTP_POST_VARS['lastname']) && tep_not_null($HTTP_POST_VARS['street_address'])) { + $process = true; + + if (ACCOUNT_GENDER == 'true') $gender = tep_db_prepare_input($HTTP_POST_VARS['gender']); + if (ACCOUNT_COMPANY == 'true') $company = tep_db_prepare_input($HTTP_POST_VARS['company']); + $firstname = tep_db_prepare_input($HTTP_POST_VARS['firstname']); + $lastname = tep_db_prepare_input($HTTP_POST_VARS['lastname']); + $street_address = tep_db_prepare_input($HTTP_POST_VARS['street_address']); + if (ACCOUNT_SUBURB == 'true') $suburb = tep_db_prepare_input($HTTP_POST_VARS['suburb']); + $postcode = tep_db_prepare_input($HTTP_POST_VARS['postcode']); + $city = tep_db_prepare_input($HTTP_POST_VARS['city']); + $country = tep_db_prepare_input($HTTP_POST_VARS['country']); + if (ACCOUNT_STATE == 'true') { + if (isset($HTTP_POST_VARS['zone_id'])) { + $zone_id = tep_db_prepare_input($HTTP_POST_VARS['zone_id']); + } else { + $zone_id = false; + } + $state = tep_db_prepare_input($HTTP_POST_VARS['state']); + } + + if (ACCOUNT_GENDER == 'true') { + if ( ($gender != 'm') && ($gender != 'f') ) { + $error = true; + + $messageStack->add('checkout_address', ENTRY_GENDER_ERROR); + } + } + + if (strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) { + $error = true; + + $messageStack->add('checkout_address', ENTRY_FIRST_NAME_ERROR); + } + + if (strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) { + $error = true; + + $messageStack->add('checkout_address', ENTRY_LAST_NAME_ERROR); + } + + if (strlen($street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) { + $error = true; + + $messageStack->add('checkout_address', ENTRY_STREET_ADDRESS_ERROR); + } + + if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) { + $error = true; + + $messageStack->add('checkout_address', ENTRY_POST_CODE_ERROR); + } + + if (strlen($city) < ENTRY_CITY_MIN_LENGTH) { + $error = true; + + $messageStack->add('checkout_address', ENTRY_CITY_ERROR); + } + + if (ACCOUNT_STATE == 'true') { + $zone_id = 0; + $check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "'"); + $check = tep_db_fetch_array($check_query); + $entry_state_has_zones = ($check['total'] > 0); + if ($entry_state_has_zones == true) { + $zone_query = tep_db_query("select distinct zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' and (zone_name like '" . tep_db_input($state) . "%' or zone_code like '%" . tep_db_input($state) . "%')"); + if (tep_db_num_rows($zone_query) == 1) { + $zone = tep_db_fetch_array($zone_query); + $zone_id = $zone['zone_id']; + } else { + $error = true; + + $messageStack->add('checkout_address', ENTRY_STATE_ERROR_SELECT); + } + } else { + if (strlen($state) < ENTRY_STATE_MIN_LENGTH) { + $error = true; + + $messageStack->add('checkout_address', ENTRY_STATE_ERROR); + } + } + } + + if ( (is_numeric($country) == false) || ($country < 1) ) { + $error = true; + + $messageStack->add('checkout_address', ENTRY_COUNTRY_ERROR); + } + + if ($error == false) { + $sql_data_array = array('customers_id' => $customer_id, + 'entry_firstname' => $firstname, + 'entry_lastname' => $lastname, + 'entry_street_address' => $street_address, + 'entry_postcode' => $postcode, + 'entry_city' => $city, + 'entry_country_id' => $country); + + if (ACCOUNT_GENDER == 'true') $sql_data_array['entry_gender'] = $gender; + if (ACCOUNT_COMPANY == 'true') $sql_data_array['entry_company'] = $company; + if (ACCOUNT_SUBURB == 'true') $sql_data_array['entry_suburb'] = $suburb; + if (ACCOUNT_STATE == 'true') { + if ($zone_id > 0) { + $sql_data_array['entry_zone_id'] = $zone_id; + $sql_data_array['entry_state'] = ''; + } else { + $sql_data_array['entry_zone_id'] = '0'; + $sql_data_array['entry_state'] = $state; + } + } + + if (!tep_session_is_registered('sendto')) tep_session_register('sendto'); + + tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array); + + $sendto = tep_db_insert_id(); + + if (tep_session_is_registered('shipping')) tep_session_unregister('shipping'); + + tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')); + } +// process the selected shipping destination + } elseif (isset($HTTP_POST_VARS['address'])) { + $reset_shipping = false; + if (tep_session_is_registered('sendto')) { + if ($sendto != $HTTP_POST_VARS['address']) { + if (tep_session_is_registered('shipping')) { + $reset_shipping = true; + } + } + } else { + tep_session_register('sendto'); + } + + $sendto = $HTTP_POST_VARS['address']; + + $check_address_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$sendto . "'"); + $check_address = tep_db_fetch_array($check_address_query); + + if ($check_address['total'] == '1') { + if ($reset_shipping == true) tep_session_unregister('shipping'); + tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')); + } else { + tep_session_unregister('sendto'); + } + } else { + if (!tep_session_is_registered('sendto')) tep_session_register('sendto'); + $sendto = $customer_default_address_id; + + tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')); + } + } + +// if no shipping destination address was selected, use their own address as default + if (!tep_session_is_registered('sendto')) { + $sendto = $customer_default_address_id; + } + + $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')); + $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL')); + + $addresses_count = tep_count_customer_address_book_entries(); +?> + +> + + +<?php echo TITLE; ?> + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + +size('checkout_address') > 0) { +?> + + + + + + + + + + + + + + + + + 1) { +?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
output('checkout_address'); ?>
+ + + +
+ + + +
+ + + + + +
+ + + + + + +
' . TITLE_SHIPPING_ADDRESS . '
' . tep_image(DIR_WS_IMAGES . 'arrow_south_east.gif'); ?>
'); ?>
+ + + +
+ + + +
+ + + + + + + + + + + + + +
' . TITLE_PLEASE_SELECT . '
' . tep_image(DIR_WS_IMAGES . 'arrow_east_south.gif'); ?>
+' . "\n"; + } else { + echo ' ' . "\n"; + } +?> + + + + + + + + + + +
+ + + + + +
+ + + +
+ + + +
+ + + + + + + + + + +
+ + + + + +
+ + + +
+ + + + + + +
' . TITLE_CONTINUE_CHECKOUT_PROCEDURE . '
' . TEXT_CONTINUE_CHECKOUT_PROCEDURE; ?>
' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . ''; ?>
+ + + + + + + + + + + + +
+ + + + +
+ + + + +
+ + + +
+ + + + + +
+ + + diff --git a/psp_admin/inc/payment_modules/currencies.php b/psp_admin/inc/payment_modules/currencies.php new file mode 100644 index 0000000000..a0d7d8edc5 --- /dev/null +++ b/psp_admin/inc/payment_modules/currencies.php @@ -0,0 +1,71 @@ +currencies = array(); + $this->currencies['EUR'] = array('title' => 'EURO', + 'symbol_left' => '€', + 'symbol_right' => 'EURO', + 'decimal_point' => ',', + 'thousands_point' => '.', + 'decimal_places' => 2, + 'value' => 1); + } + +// class methods + function format($number, $calculate_currency_value = false, $currency_type = DEFAULT_CURRENCY, $currency_value = '') { + if ($calculate_currency_value) { + $rate = ($currency_value) ? $currency_value : $this->currencies[$currency_type]['value']; + $format_string = $this->currencies[$currency_type]['symbol_left'] . number_format($number * $rate, $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right']; +// if the selected currency is in the european euro-conversion and the default currency is euro, +// the currency will displayed in the national currency and euro currency + if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) { + $format_string .= ' [' . $this->format($number, true, 'EUR') . ']'; + } + } else { + $format_string = $this->currencies[$currency_type]['symbol_left'] . number_format($number, $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right']; + } + + return $format_string; + } + function is_set($code) { + if (isset($this->currencies[$code]) && tep_not_null($this->currencies[$code])) { + return true; + } else { + return false; + } + } + + function get_value($code) { + return $this->currencies[$code]['value']; + } + function get_title($code) + { + return $this->currencies[$code]['title']; + } + + function get_decimal_places($code) { + return $this->currencies[$code]['decimal_places']; + } + + function display_price($products_price, $products_tax, $quantity = 1) { + return $this->format(tep_add_tax($products_price, $products_tax) * $quantity); + } + } +?> diff --git a/psp_admin/inc/payment_modules/database.php b/psp_admin/inc/payment_modules/database.php new file mode 100644 index 0000000000..dba8300d09 --- /dev/null +++ b/psp_admin/inc/payment_modules/database.php @@ -0,0 +1,152 @@ +' . $errno . ' - ' . $error . '

' . $query . '

[TEP STOP]

'); + } + + function tep_db_query($query, $link = 'db_link') { + global $$link; + + if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) { + error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); + } + + $result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error()); + + if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) { + $result_error = mysql_error(); + error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); + } + + return $result; + } + + function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') { + reset($data); + if ($action == 'insert') { + $query = 'insert into ' . $table . ' ('; + while (list($columns, ) = each($data)) { + $query .= $columns . ', '; + } + $query = substr($query, 0, -2) . ') values ('; + reset($data); + while (list(, $value) = each($data)) { + switch ((string)$value) { + case 'now()': + $query .= 'now(), '; + break; + case 'null': + $query .= 'null, '; + break; + default: + $query .= '\'' . tep_db_input($value) . '\', '; + break; + } + } + $query = substr($query, 0, -2) . ')'; + } elseif ($action == 'update') { + $query = 'update ' . $table . ' set '; + while (list($columns, $value) = each($data)) { + switch ((string)$value) { + case 'now()': + $query .= $columns . ' = now(), '; + break; + case 'null': + $query .= $columns .= ' = null, '; + break; + default: + $query .= $columns . ' = \'' . tep_db_input($value) . '\', '; + break; + } + } + $query = substr($query, 0, -2) . ' where ' . $parameters; + } + + return tep_db_query($query, $link); + } + + function tep_db_fetch_array($db_query) { + return mysql_fetch_array($db_query, MYSQL_ASSOC); + } + + function tep_db_num_rows($db_query) { + return mysql_num_rows($db_query); + } + + function tep_db_data_seek($db_query, $row_number) { + return mysql_data_seek($db_query, $row_number); + } + + function tep_db_insert_id() { + return mysql_insert_id(); + } + + function tep_db_free_result($db_query) { + return mysql_free_result($db_query); + } + + function tep_db_fetch_fields($db_query) { + return mysql_fetch_field($db_query); + } + + function tep_db_output($string) { + return htmlspecialchars($string); + } + + function tep_db_input($string) { + return addslashes($string); + } + + function tep_db_prepare_input($string) { + if (is_string($string)) { + return trim(tep_sanitize_string(stripslashes($string))); + } elseif (is_array($string)) { + reset($string); + while (list($key, $value) = each($string)) { + $string[$key] = tep_db_prepare_input($value); + } + return $string; + } else { + return $string; + } + } +?> diff --git a/psp_admin/inc/payment_modules/general.php b/psp_admin/inc/payment_modules/general.php new file mode 100644 index 0000000000..fcb5215f72 --- /dev/null +++ b/psp_admin/inc/payment_modules/general.php @@ -0,0 +1,1253 @@ + '"')); + } else { + return tep_parse_input_field_data($string, $translate); + } + } + } + + function tep_output_string_protected($string) { + return tep_output_string($string, false, true); + } + + function tep_sanitize_string($string) { + $string = ereg_replace(' +', ' ', trim($string)); + + return preg_replace("/[<>]/", '_', $string); + } + +//// +// Return a random row from a database query + function tep_random_select($query) { + $random_product = ''; + $random_query = tep_db_query($query); + $num_rows = tep_db_num_rows($random_query); + if ($num_rows > 0) { + $random_row = tep_rand(0, ($num_rows - 1)); + tep_db_data_seek($random_query, $random_row); + $random_product = tep_db_fetch_array($random_query); + } + + return $random_product; + } + +//// +// Return a product's name +// TABLES: products + function tep_get_products_name($product_id, $language = '') { + global $languages_id; + + if (empty($language)) $language = $languages_id; + + $product_query = tep_db_query("select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language . "'"); + $product = tep_db_fetch_array($product_query); + + return $product['products_name']; + } + +//// +// Return a product's special price (returns nothing if there is no offer) +// TABLES: products + function tep_get_products_special_price($product_id) { + $product_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status"); + $product = tep_db_fetch_array($product_query); + + return $product['specials_new_products_price']; + } + +//// +// Return a product's stock +// TABLES: products + function tep_get_products_stock($products_id) { + $products_id = tep_get_prid($products_id); + $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); + $stock_values = tep_db_fetch_array($stock_query); + + return $stock_values['products_quantity']; + } + +//// +// Check if the required stock is available +// If insufficent stock is available return an out of stock message + function tep_check_stock($products_id, $products_quantity) { + $stock_left = tep_get_products_stock($products_id) - $products_quantity; + $out_of_stock = ''; + + if ($stock_left < 0) { + $out_of_stock = '' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . ''; + } + + return $out_of_stock; + } + +//// +// Break a word in a string if it is longer than a specified length ($len) + function tep_break_string($string, $len, $break_char = '-') { + $l = 0; + $output = ''; + for ($i=0, $n=strlen($string); $i<$n; $i++) { + $char = substr($string, $i, 1); + if ($char != ' ') { + $l++; + } else { + $l = 0; + } + if ($l > $len) { + $l = 1; + $output .= $break_char; + } + $output .= $char; + } + + return $output; + } + +//// +// Return all HTTP GET variables, except those passed as a parameter + function tep_get_all_get_params($exclude_array = '') { + global $HTTP_GET_VARS; + + if (!is_array($exclude_array)) $exclude_array = array(); + + $get_url = ''; + if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) { + reset($HTTP_GET_VARS); + while (list($key, $value) = each($HTTP_GET_VARS)) { + if ( (strlen($value) > 0) && ($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) { + $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&'; + } + } + } + + return $get_url; + } + +//// +// Returns an array with countries +// TABLES: countries + function tep_get_countries($countries_id = '', $with_iso_codes = false) { + $countries_array = array(); + if (tep_not_null($countries_id)) { + if ($with_iso_codes == true) { + $countries = tep_db_query("select countries_name, countries_iso_code_2, countries_iso_code_3 from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "' order by countries_name"); + $countries_values = tep_db_fetch_array($countries); + $countries_array = array('countries_name' => $countries_values['countries_name'], + 'countries_iso_code_2' => $countries_values['countries_iso_code_2'], + 'countries_iso_code_3' => $countries_values['countries_iso_code_3']); + } else { + $countries = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "'"); + $countries_values = tep_db_fetch_array($countries); + $countries_array = array('countries_name' => $countries_values['countries_name']); + } + } else { + $countries = tep_db_query("select countries_id, countries_name from " . TABLE_COUNTRIES . " order by countries_name"); + while ($countries_values = tep_db_fetch_array($countries)) { + $countries_array[] = array('countries_id' => $countries_values['countries_id'], + 'countries_name' => $countries_values['countries_name']); + } + } + + return $countries_array; + } + +//// +// Alias function to tep_get_countries, which also returns the countries iso codes + function tep_get_countries_with_iso_codes($countries_id) { + return tep_get_countries($countries_id, true); + } + +//// +// Generate a path to categories + function tep_get_path($current_category_id = '') { + global $cPath_array; + + if (tep_not_null($current_category_id)) { + $cp_size = sizeof($cPath_array); + if ($cp_size == 0) { + $cPath_new = $current_category_id; + } else { + $cPath_new = ''; + $last_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$cPath_array[($cp_size-1)] . "'"); + $last_category = tep_db_fetch_array($last_category_query); + + $current_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'"); + $current_category = tep_db_fetch_array($current_category_query); + + if ($last_category['parent_id'] == $current_category['parent_id']) { + for ($i=0; $i<($cp_size-1); $i++) { + $cPath_new .= '_' . $cPath_array[$i]; + } + } else { + for ($i=0; $i<$cp_size; $i++) { + $cPath_new .= '_' . $cPath_array[$i]; + } + } + $cPath_new .= '_' . $current_category_id; + + if (substr($cPath_new, 0, 1) == '_') { + $cPath_new = substr($cPath_new, 1); + } + } + } else { + $cPath_new = implode('_', $cPath_array); + } + + return 'cPath=' . $cPath_new; + } + +//// +// Returns the clients browser + function tep_browser_detect($component) { + global $HTTP_USER_AGENT; + + return stristr($HTTP_USER_AGENT, $component); + } + +//// +// Alias function to tep_get_countries() + function tep_get_country_name($country_id) { + $country_array = tep_get_countries($country_id); + + return $country_array['countries_name']; + } + +//// +// Returns the zone (State/Province) name +// TABLES: zones + function tep_get_zone_name($country_id, $zone_id, $default_zone) { + $zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'"); + if (tep_db_num_rows($zone_query)) { + $zone = tep_db_fetch_array($zone_query); + return $zone['zone_name']; + } else { + return $default_zone; + } + } + +//// +// Returns the zone (State/Province) code +// TABLES: zones + function tep_get_zone_code($country_id, $zone_id, $default_zone) { + $zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'"); + if (tep_db_num_rows($zone_query)) { + $zone = tep_db_fetch_array($zone_query); + return $zone['zone_code']; + } else { + return $default_zone; + } + } + +//// +// Wrapper function for round() + function tep_round($number, $precision) { + if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.')+1)) > $precision)) { + $number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1); + + if (substr($number, -1) >= 5) { + if ($precision > 1) { + $number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision-1) . '1'); + } elseif ($precision == 1) { + $number = substr($number, 0, -1) + 0.1; + } else { + $number = substr($number, 0, -1) + 1; + } + } else { + $number = substr($number, 0, -1); + } + } + + return $number; + } + +//// +// Returns the tax rate for a zone / class +// TABLES: tax_rates, zones_to_geo_zones + function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) { + global $customer_zone_id, $customer_country_id; + + if ( ($country_id == -1) && ($zone_id == -1) ) { + if (!tep_session_is_registered('customer_id')) { + $country_id = STORE_COUNTRY; + $zone_id = STORE_ZONE; + } else { + $country_id = $customer_country_id; + $zone_id = $customer_zone_id; + } + } + + $tax_query = tep_db_query("select sum(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . (int)$country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . (int)$zone_id . "') and tr.tax_class_id = '" . (int)$class_id . "' group by tr.tax_priority"); + if (tep_db_num_rows($tax_query)) { + $tax_multiplier = 1.0; + while ($tax = tep_db_fetch_array($tax_query)) { + $tax_multiplier *= 1.0 + ($tax['tax_rate'] / 100); + } + return ($tax_multiplier - 1.0) * 100; + } else { + return 0; + } + } + +//// +// Return the tax description for a zone / class +// TABLES: tax_rates; + function tep_get_tax_description($class_id, $country_id, $zone_id) { + $tax_query = tep_db_query("select tax_description from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . (int)$country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . (int)$zone_id . "') and tr.tax_class_id = '" . (int)$class_id . "' order by tr.tax_priority"); + if (tep_db_num_rows($tax_query)) { + $tax_description = ''; + while ($tax = tep_db_fetch_array($tax_query)) { + $tax_description .= $tax['tax_description'] . ' + '; + } + $tax_description = substr($tax_description, 0, -3); + + return $tax_description; + } else { + return TEXT_UNKNOWN_TAX_RATE; + } + } + +//// +// Add tax to a products price + function tep_add_tax($price, $tax) { + global $currencies; + + if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) { + return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + tep_calculate_tax($price, $tax); + } else { + return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']); + } + } + +// Calculates Tax rounding the result + function tep_calculate_tax($price, $tax) { + global $currencies; + + return tep_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']); + } + +//// +// Return the number of products in a category +// TABLES: products, products_to_categories, categories + function tep_count_products_in_category($category_id, $include_inactive = false) { + $products_count = 0; + if ($include_inactive == true) { + $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category_id . "'"); + } else { + $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$category_id . "'"); + } + $products = tep_db_fetch_array($products_query); + $products_count += $products['total']; + + $child_categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'"); + if (tep_db_num_rows($child_categories_query)) { + while ($child_categories = tep_db_fetch_array($child_categories_query)) { + $products_count += tep_count_products_in_category($child_categories['categories_id'], $include_inactive); + } + } + + return $products_count; + } + +//// +// Return true if the category has subcategories +// TABLES: categories + function tep_has_category_subcategories($category_id) { + $child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'"); + $child_category = tep_db_fetch_array($child_category_query); + + if ($child_category['count'] > 0) { + return true; + } else { + return false; + } + } + +//// +// Returns the address_format_id for the given country +// TABLES: countries; + function tep_get_address_format_id($country_id) { + $address_format_query = tep_db_query("select address_format_id as format_id from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$country_id . "'"); + if (tep_db_num_rows($address_format_query)) { + $address_format = tep_db_fetch_array($address_format_query); + return $address_format['format_id']; + } else { + return '1'; + } + } + +//// +// Return a formatted address +// TABLES: address_format + function tep_address_format($address_format_id, $address, $html, $boln, $eoln) { + $address_format_query = tep_db_query("select address_format as format from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . (int)$address_format_id . "'"); + $address_format = tep_db_fetch_array($address_format_query); + + $company = tep_output_string_protected($address['company']); + if (isset($address['firstname']) && tep_not_null($address['firstname'])) { + $firstname = tep_output_string_protected($address['firstname']); + $lastname = tep_output_string_protected($address['lastname']); + } elseif (isset($address['name']) && tep_not_null($address['name'])) { + $firstname = tep_output_string_protected($address['name']); + $lastname = ''; + } else { + $firstname = ''; + $lastname = ''; + } + $street = tep_output_string_protected($address['street_address']); + $suburb = tep_output_string_protected($address['suburb']); + $city = tep_output_string_protected($address['city']); + $state = tep_output_string_protected($address['state']); + if (isset($address['country_id']) && tep_not_null($address['country_id'])) { + $country = tep_get_country_name($address['country_id']); + + if (isset($address['zone_id']) && tep_not_null($address['zone_id'])) { + $state = tep_get_zone_code($address['country_id'], $address['zone_id'], $state); + } + } elseif (isset($address['country']) && tep_not_null($address['country'])) { + $country = tep_output_string_protected($address['country']); + } else { + $country = ''; + } + $postcode = tep_output_string_protected($address['postcode']); + $zip = $postcode; + + if ($html) { +// HTML Mode + $HR = '
'; + $hr = '
'; + if ( ($boln == '') && ($eoln == "\n") ) { // Values not specified, use rational defaults + $CR = '
'; + $cr = '
'; + $eoln = $cr; + } else { // Use values supplied + $CR = $eoln . $boln; + $cr = $CR; + } + } else { +// Text Mode + $CR = $eoln; + $cr = $CR; + $HR = '----------------------------------------'; + $hr = '----------------------------------------'; + } + + $statecomma = ''; + $streets = $street; + if ($suburb != '') $streets = $street . $cr . $suburb; + if ($country == '') $country = tep_output_string_protected($address['country']); + if ($state != '') $statecomma = $state . ', '; + + $fmt = $address_format['format']; + eval("\$address = \"$fmt\";"); + + if ( (ACCOUNT_COMPANY == 'true') && (tep_not_null($company)) ) { + $address = $company . $cr . $address; + } + + return $address; + } + +//// +// Return a formatted address +// TABLES: customers, address_book + function tep_address_label($customers_id, $address_id = 1, $html = false, $boln = '', $eoln = "\n") { + $address_query = tep_db_query("select entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customers_id . "' and address_book_id = '" . (int)$address_id . "'"); + $address = tep_db_fetch_array($address_query); + + $format_id = tep_get_address_format_id($address['country_id']); + + return tep_address_format($format_id, $address, $html, $boln, $eoln); + } + + function tep_row_number_format($number) { + if ( ($number < 10) && (substr($number, 0, 1) != '0') ) $number = '0' . $number; + + return $number; + } + + function tep_get_categories($categories_array = '', $parent_id = '0', $indent = '') { + global $languages_id; + + if (!is_array($categories_array)) $categories_array = array(); + + $categories_query = tep_db_query("select c.categories_id, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where parent_id = '" . (int)$parent_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name"); + while ($categories = tep_db_fetch_array($categories_query)) { + $categories_array[] = array('id' => $categories['categories_id'], + 'text' => $indent . $categories['categories_name']); + + if ($categories['categories_id'] != $parent_id) { + $categories_array = tep_get_categories($categories_array, $categories['categories_id'], $indent . '  '); + } + } + + return $categories_array; + } + + function tep_get_manufacturers($manufacturers_array = '') { + if (!is_array($manufacturers_array)) $manufacturers_array = array(); + + $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name"); + while ($manufacturers = tep_db_fetch_array($manufacturers_query)) { + $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'], 'text' => $manufacturers['manufacturers_name']); + } + + return $manufacturers_array; + } + +//// +// Return all subcategory IDs +// TABLES: categories + function tep_get_subcategories(&$subcategories_array, $parent_id = 0) { + $subcategories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$parent_id . "'"); + while ($subcategories = tep_db_fetch_array($subcategories_query)) { + $subcategories_array[sizeof($subcategories_array)] = $subcategories['categories_id']; + if ($subcategories['categories_id'] != $parent_id) { + tep_get_subcategories($subcategories_array, $subcategories['categories_id']); + } + } + } + +// Output a raw date string in the selected locale date format +// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS + function tep_date_long($raw_date) { + if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false; + + $year = (int)substr($raw_date, 0, 4); + $month = (int)substr($raw_date, 5, 2); + $day = (int)substr($raw_date, 8, 2); + $hour = (int)substr($raw_date, 11, 2); + $minute = (int)substr($raw_date, 14, 2); + $second = (int)substr($raw_date, 17, 2); + + return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year)); + } + +//// +// Output a raw date string in the selected locale date format +// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS +// NOTE: Includes a workaround for dates before 01/01/1970 that fail on windows servers + function tep_date_short($raw_date) { + if ( ($raw_date == '0000-00-00 00:00:00') || empty($raw_date) ) return false; + + $year = substr($raw_date, 0, 4); + $month = (int)substr($raw_date, 5, 2); + $day = (int)substr($raw_date, 8, 2); + $hour = (int)substr($raw_date, 11, 2); + $minute = (int)substr($raw_date, 14, 2); + $second = (int)substr($raw_date, 17, 2); + + if (@date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) { + return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year)); + } else { + return ereg_replace('2037' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037))); + } + } + +//// +// Parse search string into indivual objects + function tep_parse_search_string($search_str = '', &$objects) { + $search_str = trim(strtolower($search_str)); + +// Break up $search_str on whitespace; quoted string will be reconstructed later + $pieces = split('[[:space:]]+', $search_str); + $objects = array(); + $tmpstring = ''; + $flag = ''; + + for ($k=0; $k 1) { + $pieces[$k] = substr($pieces[$k], 1); + } else { + $pieces[$k] = ''; + } + } + + $post_objects = array(); + + while (substr($pieces[$k], -1) == ')') { + $post_objects[] = ')'; + if (strlen($pieces[$k]) > 1) { + $pieces[$k] = substr($pieces[$k], 0, -1); + } else { + $pieces[$k] = ''; + } + } + +// Check individual words + + if ( (substr($pieces[$k], -1) != '"') && (substr($pieces[$k], 0, 1) != '"') ) { + $objects[] = trim($pieces[$k]); + + for ($j=0; $j 1) { + $pieces[$k] = substr($pieces[$k], 0, -1); + } else { + $pieces[$k] = ''; + } + } + +// If the word doesn't end in double quotes, append it to the $tmpstring. + if (substr($pieces[$k], -1) != '"') { +// Tack this word onto the current string entity + $tmpstring .= ' ' . $pieces[$k]; + +// Move on to the next word + $k++; + continue; + } else { +/* If the $piece ends in double quotes, strip the double quotes, tack the + $piece onto the tail of the string, push the $tmpstring onto the $haves, + kill the $tmpstring, turn the $flag "off", and return. +*/ + $tmpstring .= ' ' . trim(ereg_replace('"', ' ', $pieces[$k])); + +// Push the $tmpstring onto the array of stuff to search for + $objects[] = trim($tmpstring); + + for ($j=0; $j 12 || $month < 1) { + return false; + } + + if ($day < 1) { + return false; + } + + if (tep_is_leap_year($year)) { + $no_of_days[1] = 29; + } + + if ($day > $no_of_days[$month - 1]) { + return false; + } + + $date_array = array($year, $month, $day); + + return true; + } + +//// +// Check if year is a leap year + function tep_is_leap_year($year) { + if ($year % 100 == 0) { + if ($year % 400 == 0) return true; + } else { + if (($year % 4) == 0) return true; + } + + return false; + } + +//// +// Return table heading with sorting capabilities + function tep_create_sort_heading($sortby, $colnum, $heading) { + global $PHP_SELF; + + $sort_prefix = ''; + $sort_suffix = ''; + + if ($sortby) { + $sort_prefix = '' ; + $sort_suffix = (substr($sortby, 0, 1) == $colnum ? (substr($sortby, 1, 1) == 'a' ? '+' : '-') : '') . ''; + } + + return $sort_prefix . $heading . $sort_suffix; + } + +//// +// Recursively go through the categories and retreive all parent categories IDs +// TABLES: categories + function tep_get_parent_categories(&$categories, $categories_id) { + $parent_categories_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$categories_id . "'"); + while ($parent_categories = tep_db_fetch_array($parent_categories_query)) { + if ($parent_categories['parent_id'] == 0) return true; + $categories[sizeof($categories)] = $parent_categories['parent_id']; + if ($parent_categories['parent_id'] != $categories_id) { + tep_get_parent_categories($categories, $parent_categories['parent_id']); + } + } + } + +//// +// Construct a category path to the product +// TABLES: products_to_categories + function tep_get_product_path($products_id) { + $cPath = ''; + + $category_query = tep_db_query("select p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = '" . (int)$products_id . "' and p.products_status = '1' and p.products_id = p2c.products_id limit 1"); + if (tep_db_num_rows($category_query)) { + $category = tep_db_fetch_array($category_query); + + $categories = array(); + tep_get_parent_categories($categories, $category['categories_id']); + + $categories = array_reverse($categories); + + $cPath = implode('_', $categories); + + if (tep_not_null($cPath)) $cPath .= '_'; + $cPath .= $category['categories_id']; + } + + return $cPath; + } + +//// +// Return a product ID with attributes + function tep_get_uprid($prid, $params) { + $uprid = $prid; + if ( (is_array($params)) && (!strstr($prid, '{')) ) { + while (list($option, $value) = each($params)) { + $uprid = $uprid . '{' . $option . '}' . $value; + } + } + + return $uprid; + } + +//// +// Return a product ID from a product ID with attributes + function tep_get_prid($uprid) { + $pieces = explode('{', $uprid); + + return $pieces[0]; + } + +//// +// Return a customer greeting + function tep_customer_greeting() { + global $customer_id, $customer_first_name; + + if (tep_session_is_registered('customer_first_name') && tep_session_is_registered('customer_id')) { + $greeting_string = sprintf(TEXT_GREETING_PERSONAL, tep_output_string_protected($customer_first_name), tep_href_link(FILENAME_PRODUCTS_NEW)); + } else { + $greeting_string = sprintf(TEXT_GREETING_GUEST, tep_href_link(FILENAME_LOGIN, '', 'SSL'), tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL')); + } + + return $greeting_string; + } + +//// +//! Send email (text/html) using MIME +// This is the central mail function. The SMTP Server should be configured +// correct in php.ini +// Parameters: +// $to_name The name of the recipient, e.g. "Jan Wildeboer" +// $to_email_address The eMail address of the recipient, +// e.g. jan.wildeboer@gmx.de +// $email_subject The subject of the eMail +// $email_text The text of the eMail, may contain HTML entities +// $from_email_name The name of the sender, e.g. Shop Administration +// $from_email_adress The eMail address of the sender, +// e.g. info@mytepshop.com + + function tep_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) { + if (SEND_EMAILS != 'true') return false; + + // Instantiate a new mail object + $message = new email(array('X-Mailer: osCommerce Mailer')); + + // Build the text version + $text = strip_tags($email_text); + if (EMAIL_USE_HTML == 'true') { + $message->add_html($email_text, $text); + } else { + $message->add_text($text); + } + + // Send message + $message->build_message(); + $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject); + } + +//// +// Check if product has attributes + function tep_has_product_attributes($products_id) { + $attributes_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "'"); + $attributes = tep_db_fetch_array($attributes_query); + + if ($attributes['count'] > 0) { + return true; + } else { + return false; + } + } + +//// +// Get the number of times a word/character is present in a string + function tep_word_count($string, $needle) { + $temp_array = split($needle, $string); + + return sizeof($temp_array); + } + + function tep_count_modules($modules = '') { + $count = 0; + + if (empty($modules)) return $count; + + $modules_array = split(';', $modules); + + for ($i=0, $n=sizeof($modules_array); $i<$n; $i++) { + $class = substr($modules_array[$i], 0, strrpos($modules_array[$i], '.')); + + if (is_object($GLOBALS[$class])) { + if ($GLOBALS[$class]->enabled) { + $count++; + } + } + } + + return $count; + } + + function tep_count_payment_modules() { + return tep_count_modules(MODULE_PAYMENT_INSTALLED); + } + + function tep_count_shipping_modules() { + return tep_count_modules(MODULE_SHIPPING_INSTALLED); + } + + function tep_create_random_value($length, $type = 'mixed') { + if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) return false; + + $rand_value = ''; + while (strlen($rand_value) < $length) { + if ($type == 'digits') { + $char = tep_rand(0,9); + } else { + $char = chr(tep_rand(0,255)); + } + if ($type == 'mixed') { + if (eregi('^[a-z0-9]$', $char)) $rand_value .= $char; + } elseif ($type == 'chars') { + if (eregi('^[a-z]$', $char)) $rand_value .= $char; + } elseif ($type == 'digits') { + if (ereg('^[0-9]$', $char)) $rand_value .= $char; + } + } + + return $rand_value; + } + + function tep_array_to_string($array, $exclude = '', $equals = '=', $separator = '&') { + if (!is_array($exclude)) $exclude = array(); + + $get_string = ''; + if (sizeof($array) > 0) { + while (list($key, $value) = each($array)) { + if ( (!in_array($key, $exclude)) && ($key != 'x') && ($key != 'y') ) { + $get_string .= $key . $equals . $value . $separator; + } + } + $remove_chars = strlen($separator); + $get_string = substr($get_string, 0, -$remove_chars); + } + + return $get_string; + } + + function tep_not_null($value) { + if (is_array($value)) { + if (sizeof($value) > 0) { + return true; + } else { + return false; + } + } else { + if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) { + return true; + } else { + return false; + } + } + } + +//// +// Output the tax percentage with optional padded decimals + function tep_display_tax_value($value, $padding = TAX_DECIMAL_PLACES) { + if (strpos($value, '.')) { + $loop = true; + while ($loop) { + if (substr($value, -1) == '0') { + $value = substr($value, 0, -1); + } else { + $loop = false; + if (substr($value, -1) == '.') { + $value = substr($value, 0, -1); + } + } + } + } + + if ($padding > 0) { + if ($decimal_pos = strpos($value, '.')) { + $decimals = strlen(substr($value, ($decimal_pos+1))); + for ($i=$decimals; $i<$padding; $i++) { + $value .= '0'; + } + } else { + $value .= '.'; + for ($i=0; $i<$padding; $i++) { + $value .= '0'; + } + } + } + + return $value; + } + +//// +// Checks to see if the currency code exists as a currency +// TABLES: currencies + function tep_currency_exists($code) { + $code = tep_db_prepare_input($code); + + $currency_code = tep_db_query("select currencies_id from " . TABLE_CURRENCIES . " where code = '" . tep_db_input($code) . "'"); + if (tep_db_num_rows($currency_code)) { + return $code; + } else { + return false; + } + } + + function tep_string_to_int($string) { + return (int)$string; + } + +//// +// Parse and secure the cPath parameter values + function tep_parse_category_path($cPath) { +// make sure the category IDs are integers + $cPath_array = array_map('tep_string_to_int', explode('_', $cPath)); + +// make sure no duplicate category IDs exist which could lock the server in a loop + $tmp_array = array(); + $n = sizeof($cPath_array); + for ($i=0; $i<$n; $i++) { + if (!in_array($cPath_array[$i], $tmp_array)) { + $tmp_array[] = $cPath_array[$i]; + } + } + + return $tmp_array; + } + +//// +// Return a random value + function tep_rand($min = null, $max = null) { + static $seeded; + + if (!isset($seeded)) { + mt_srand((double)microtime()*1000000); + $seeded = true; + } + + if (isset($min) && isset($max)) { + if ($min >= $max) { + return $min; + } else { + return mt_rand($min, $max); + } + } else { + return mt_rand(); + } + } + + function tep_setcookie($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = 0) { + setcookie($name, $value, $expire, $path, (tep_not_null($domain) ? $domain : ''), $secure); + } + + function tep_get_ip_address() { + if (isset($_SERVER)) { + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { + $ip = $_SERVER['HTTP_CLIENT_IP']; + } else { + $ip = $_SERVER['REMOTE_ADDR']; + } + } else { + if (getenv('HTTP_X_FORWARDED_FOR')) { + $ip = getenv('HTTP_X_FORWARDED_FOR'); + } elseif (getenv('HTTP_CLIENT_IP')) { + $ip = getenv('HTTP_CLIENT_IP'); + } else { + $ip = getenv('REMOTE_ADDR'); + } + } + + return $ip; + } + + function tep_count_customer_orders($id = '', $check_session = true) { + global $customer_id; + + if (is_numeric($id) == false) { + if (tep_session_is_registered('customer_id')) { + $id = $customer_id; + } else { + return 0; + } + } + + if ($check_session == true) { + if ( (tep_session_is_registered('customer_id') == false) || ($id != $customer_id) ) { + return 0; + } + } + + $orders_check_query = tep_db_query("select count(*) as total from " . TABLE_ORDERS . " where customers_id = '" . (int)$id . "'"); + $orders_check = tep_db_fetch_array($orders_check_query); + + return $orders_check['total']; + } + + function tep_count_customer_address_book_entries($id = '', $check_session = true) { + global $customer_id; + + if (is_numeric($id) == false) { + if (tep_session_is_registered('customer_id')) { + $id = $customer_id; + } else { + return 0; + } + } + + if ($check_session == true) { + if ( (tep_session_is_registered('customer_id') == false) || ($id != $customer_id) ) { + return 0; + } + } + + $addresses_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$id . "'"); + $addresses = tep_db_fetch_array($addresses_query); + + return $addresses['total']; + } + +// nl2br() prior PHP 4.2.0 did not convert linefeeds on all OSs (it only converted \n) + function tep_convert_linefeeds($from, $to, $string) { + if ((PHP_VERSION < "4.0.5") && is_array($from)) { + return ereg_replace('(' . implode('|', $from) . ')', $to, $string); + } else { + return str_replace($from, $to, $string); + } + } +?> diff --git a/psp_admin/inc/payment_modules/html_output.php b/psp_admin/inc/payment_modules/html_output.php new file mode 100644 index 0000000000..44ad0a3eb9 --- /dev/null +++ b/psp_admin/inc/payment_modules/html_output.php @@ -0,0 +1,298 @@ +

Error!

Unable to determine the page link!

'); + } + + if ($connection == 'NONSSL') { + $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG; + } elseif ($connection == 'SSL') { + if (ENABLE_SSL == true) { + $link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG; + } else { + $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG; + } + } else { + die('

Error!

Unable to determine connection method on a link!

Known methods: NONSSL SSL


'); + } + + if (tep_not_null($parameters)) { + $link .= $page . '&' . tep_output_string($parameters); + $separator = '&'; + } else { + $link .= $page; + $separator = '?'; + } + + while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1); + +// Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined + if ( ($add_session_id == true) && ($session_started == true) && (SESSION_FORCE_COOKIE_USE == 'False') ) { + if (tep_not_null($SID)) { + $_sid = $SID; + } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == true) ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) { + if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) { + $_sid = tep_session_name() . '=' . tep_session_id(); + } + } + } + + if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) { + while (strstr($link, '&&')) $link = str_replace('&&', '&', $link); + + $link = str_replace('?', '/', $link); + $link = str_replace('&', '/', $link); + $link = str_replace('=', '/', $link); + + $separator = '?'; + } + + if (isset($_sid)) { + $link .= $separator . $_sid; + } + + return $link; + } + +//// +// The HTML image wrapper function + function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '') { + if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) { + return false; + } + +// alt is added to the img tag even if it is null to prevent browsers from outputting +// the image filename as default + $image = ' '"', '\'' => ''', '<' => '<', '>' => '>')) . ''; + } + $field .= ''; + + if ($required == true) $field .= TEXT_FIELD_REQUIRED; + + return $field; + } + +//// +// Creates a pull-down list of countries + function tep_get_country_list($name, $selected = '', $parameters = '') { + $countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT)); + $countries = tep_get_countries(); + + for ($i=0, $n=sizeof($countries); $i<$n; $i++) { + $countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']); + } + + return tep_draw_pull_down_menu($name, $countries_array, $selected, $parameters); + } +?> diff --git a/psp_admin/inc/payment_modules/order.php b/psp_admin/inc/payment_modules/order.php new file mode 100644 index 0000000000..1d2252c6c4 --- /dev/null +++ b/psp_admin/inc/payment_modules/order.php @@ -0,0 +1,170 @@ +info = array(); + $this->totals = array(); + $this->products = array(); + $this->customer = array(); + $this->delivery = array(); + + $this->insert_cybro_values(); + } + + function insert_cybro_values() + { + $bo = CreateObject('psp_admin.bo_oscadminapi'); + #_debug_array($bo->socreditspoint->sessiondata); + $ses = $bo->so_oscadminapi->sessiondata; + #_debug_array($bo->socreditspoint->config->config_data[cost_one_credit]); + #die(); + $this->customer = array + ( + 'name' => $ses[step2][n_givven].''.$ses[step2][n_middle].''.$ses[step2][n_family], + 'company' => '', + 'street_address' => $ses[step2][adr_one_street], + 'suburb' => '', + 'city' => $ses[step2][adr_one_locality], + 'postcode' => $ses[step2][adr_one_postalcode], + 'state' => '', + 'country' => array( + 'id'=>150 , + 'Name'=>'Netherlands', + 'countries_iso_code_2'=>'NL', + 'countries_iso_code_3'=>'NLD', + 'address_format_id'=>3 + ), + 'format_id' => '',//$order['customers_address_format_id'], + 'telephone' => $ses[step2][tel_work], + 'email_address' => $ses[step2][email], + 'zone_id'=>18 + + ); + + $this->delivery = $this->billing = $this->customer; + + $this->info = array + ( + 'order_status'=>1, + 'currency' => 'EURO',//$order['currency'], + 'currency_value' =>'1',// $order['currency_value'], + 'payment_method' => $ses[stap3]['payment'],//$order['payment_method'], + 'cc_type' => '',//$order['cc_type'], + 'cc_owner' => $ses[stap3][cc_owner],//$order['cc_owner'], + 'cc_number' => $ses[stap3][cc_number],//$order['cc_number'], + 'cc_expires' => $ses[stap3][cc_expires_month].'/'.$ses[stap3][cc_expires_year],//$order['cc_expires'], + 'date_purchased' => date('d-m-Y'),//$order['date_purchased'], + 'orders_status' => '1',//$order['orders_status'], + 'last_modified' => '',//$order['last_modified'], + 'tax'=> 0, + 'subtotal'=>(intval($ses[step2][amount])*floatval($bo->so_pspadmin->config->config_data[cost_one_credit])), + 'total'=>((intval($ses[step2][amount])*floatval($bo->so_pspadmin->config->config_data[cost_one_credit]))*1.19) + + ); + $index = 0; + $this->products[0] = array + ( + 'qty' => $ses[step2][amount], + 'name' => lang('Credits'), + 'model' => '', + 'tax' => '19', + 'price' => $bo->so_pspadmin->config->config_data[cost_one_credit], + 'final_price' => (intval($ses[step2][amount])*floatval($bo->so_pspadmin->config->config_data[cost_one_credit])) + ); + + } + function query($order_id) { + $order_query = tep_db_query("select customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value, date_purchased, orders_status, last_modified from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'"); + $order = tep_db_fetch_array($order_query); + + $totals_query = tep_db_query("select title, text from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' order by sort_order"); + while ($totals = tep_db_fetch_array($totals_query)) + { + $this->totals[] = array('title' => $totals['title'], + 'text' => $totals['text']); + } + + $this->info = array('currency' => $order['currency'], + 'currency_value' => $order['currency_value'], + 'payment_method' => $order['payment_method'], + 'cc_type' => $order['cc_type'], + 'cc_owner' => $order['cc_owner'], + 'cc_number' => $order['cc_number'], + 'cc_expires' => $order['cc_expires'], + 'date_purchased' => $order['date_purchased'], + 'orders_status' => $order['orders_status'], + 'last_modified' => $order['last_modified']); + + $this->customer = array('name' => $order['customers_name'], + 'company' => $order['customers_company'], + 'street_address' => $order['customers_street_address'], + 'suburb' => $order['customers_suburb'], + 'city' => $order['customers_city'], + 'postcode' => $order['customers_postcode'], + 'state' => $order['customers_state'], + 'country' => $order['customers_country'], + 'format_id' => $order['customers_address_format_id'], + 'telephone' => $order['customers_telephone'], + 'email_address' => $order['customers_email_address']); + + $this->delivery = array('name' => $order['delivery_name'], + 'company' => $order['delivery_company'], + 'street_address' => $order['delivery_street_address'], + 'suburb' => $order['delivery_suburb'], + 'city' => $order['delivery_city'], + 'postcode' => $order['delivery_postcode'], + 'state' => $order['delivery_state'], + 'country' => $order['delivery_country'], + 'format_id' => $order['delivery_address_format_id']); + + $this->billing = array('name' => $order['billing_name'], + 'company' => $order['billing_company'], + 'street_address' => $order['billing_street_address'], + 'suburb' => $order['billing_suburb'], + 'city' => $order['billing_city'], + 'postcode' => $order['billing_postcode'], + 'state' => $order['billing_state'], + 'country' => $order['billing_country'], + 'format_id' => $order['billing_address_format_id']); + + $index = 0; + $orders_products_query = tep_db_query("select orders_products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'"); + while ($orders_products = tep_db_fetch_array($orders_products_query)) { + $this->products[$index] = array( + 'qty' => $orders_products['products_quantity'], + 'name' => $orders_products['products_name'], + 'model' => $orders_products['products_model'], + 'tax' => $orders_products['products_tax'], + 'price' => $orders_products['products_price'], + 'final_price' => $orders_products['final_price']); + + $subindex = 0; + $attributes_query = tep_db_query("select products_options, products_options_values, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'"); + if (tep_db_num_rows($attributes_query)) { + while ($attributes = tep_db_fetch_array($attributes_query)) { + $this->products[$index]['attributes'][$subindex] = array( + 'option' => $attributes['products_options'], + 'value' => $attributes['products_options_values'], + 'prefix' => $attributes['price_prefix'], + 'price' => $attributes['options_values_price']); + + $subindex++; + } + } + $index++; + } + } + } + ?> diff --git a/psp_admin/inc/payment_modules/payment.php b/psp_admin/inc/payment_modules/payment.php new file mode 100644 index 0000000000..214212a99d --- /dev/null +++ b/psp_admin/inc/payment_modules/payment.php @@ -0,0 +1,237 @@ +modules = explode(';', MODULE_PAYMENT_INSTALLED); + $PHP_SELF = $_SERVER['PHP_SELF']; +// _debug_array($module); +// _debug_array($_SERVER['PHP_SELF']); +// _debug_array($module . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1))); +// _debug_array((in_array($module . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules))); +// die('test_init'); + $include_modules = array(); + if ( (tep_not_null($module)) && (in_array($module . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) + { + $this->selected_module = $module; + $include_modules[] = array('class' => $module, 'file' => $module . '.php'); + } + else + { + reset($this->modules); + while (list(, $value) = each($this->modules)) + { + $class = substr($value, 0, strrpos($value, '.')); // RVD replaced + $include_modules[] = array('class' => $class, 'file' => $value); // RVD added .php + } + } + + for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) { + include(DIR_WS_LANGUAGES . $language . '/modules/payment/' . $include_modules[$i]['file']); + include(DIR_WS_MODULES . 'payment/' . $include_modules[$i]['file']); + + $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class']; + } + +// if there is only one payment method, select it as default because in +// checkout_confirmation.php the $payment variable is being assigned the +// $HTTP_POST_VARS['payment'] value which will be empty (no radio button selection possible) + //_debug_array($payment); + //die(); + if ((tep_count_payment_modules() == 1) && (!isset($GLOBALS[$payment]) || (isset($GLOBALS[$payment]) && !is_object($GLOBALS[$payment]))) ) { + $payment = $include_modules[0]['class']; + } + //print_r($this->modules); + //print_r($module); + // if ( (tep_not_null($module)) && (in_array($module, $this->modules)) && (isset($GLOBALS[$module]->form_action_url)) ) { + // print_r($GLOBALS[$module]->form_action_url); + $this->form_action_url = $GLOBALS[$module]->form_action_url; + // } + } +} + +// class methods +/* The following method is needed in the checkout_confirmation.php page + due to a chicken and egg problem with the payment class and order class. + The payment modules needs the order destination data for the dynamic status + feature, and the order class needs the payment module title. + The following method is a work-around to implementing the method in all + payment modules available which would break the modules in the contributions + section. This should be looked into again post 2.2. +*/ + function update_status() { + if (is_array($this->modules)) { + if (is_object($GLOBALS[$this->selected_module])) { + if (function_exists('method_exists')) { + if (method_exists($GLOBALS[$this->selected_module], 'update_status')) { + $GLOBALS[$this->selected_module]->update_status(); + } + } else { // PHP3 compatibility + @call_user_method('update_status', $GLOBALS[$this->selected_module]); + } + } + } + } + + function javascript_validation() { + $js = ''; + if (is_array($this->modules)) { + $js = '' . "\n"; + } + + return $js; + } + + function selection() { + $selection_array = array(); + if (is_array($this->modules)) { + reset($this->modules); + while (list(, $value) = each($this->modules)) { + $class = substr($value, 0, strrpos($value, '.')); + if ($GLOBALS[$class]->enabled) { + $selection = $GLOBALS[$class]->selection(); + if (is_array($selection)) $selection_array[] = $selection; + } + } + } + return $selection_array; + } + + function pre_confirmation_check() { + // print_r($GLOBALS[$this->selected_module]); + if (is_array($this->modules)) { + if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { + $GLOBALS[$this->selected_module]->pre_confirmation_check(); + } + } + } + + function confirmation() { + if (is_array($this->modules)) { + if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { + return $GLOBALS[$this->selected_module]->confirmation(); + } + } + } + + function process_button() { + if (is_array($this->modules)) { + if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { + return $GLOBALS[$this->selected_module]->process_button(); + } + } + } + + function before_process() { + if (is_array($this->modules)) { + if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { + return $GLOBALS[$this->selected_module]->before_process(); + } + } + } + + function after_process() { + if (is_array($this->modules)) { + if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { + return $GLOBALS[$this->selected_module]->after_process(); + } + } + } + + function get_error() { + if (is_array($this->modules)) { + if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { + return $GLOBALS[$this->selected_module]->get_error(); + } + } + } + function after_submit_order() { + if (is_array($this->modules)) { + if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { + if(method_exists($GLOBALS[$this->selected_module],'after_submit_order')) + { + return $GLOBALS[$this->selected_module]->after_submit_order(); + } + } + } + } + function has_after_submit_order() { + if (is_array($this->modules)) { + if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { + return(is_callable(array($this->selected_module,'after_submit_order'))); + } + } + } + function call_aut_function($function,$param = "") + { + if (is_array($this->modules)) { + if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { + if(is_callable(array($this->selected_module,$function))) + { + if($param == "") + { + return call_user_func(array($GLOBALS[$this->selected_module],$function)); + } + else + { + return call_user_func(array($GLOBALS[$this->selected_module],$function),$param); + } + } + } + } + return false; + } +} +?> diff --git a/psp_admin/inc/payment_modules/payment/cc.php b/psp_admin/inc/payment_modules/payment/cc.php new file mode 100644 index 0000000000..fa9577b89d --- /dev/null +++ b/psp_admin/inc/payment_modules/payment/cc.php @@ -0,0 +1,220 @@ +code = 'cc'; + $this->title = MODULE_PAYMENT_CC_TEXT_TITLE; + $this->description = MODULE_PAYMENT_CC_TEXT_DESCRIPTION; + $this->sort_order = MODULE_PAYMENT_CC_SORT_ORDER; + $this->enabled = ((MODULE_PAYMENT_CC_STATUS == 'True') ? true : false); + + if ((int)MODULE_PAYMENT_CC_ORDER_STATUS_ID > 0) { + $this->order_status = MODULE_PAYMENT_CC_ORDER_STATUS_ID; + } + + if (is_object($order)) $this->update_status(); + } + +// class methods +function update_status() { +// global $order; + global $order, $HTTP_POST_VARS; +// print_r($HTTP_POST_VARS); + + if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_CC_ZONE > 0) ) { + $check_flag = false; + $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_CC_ZONE . "' and zone_country_id = '223' order by zone_id"); + // FIXME ORDER ARRAY + // $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_CC_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id"); + //print_r($check_query); + while ($check = tep_db_fetch_array($check_query)) { + //print_r($check); + //print_r($order->billing['zone_id']); + + if ($check['zone_id'] < 1) { + $check_flag = true; + //print_r('true'); + break; + } elseif ($check['zone_id'] == $order->billing['zone_id']) { + //print_r('true'); + + $check_flag = true; + break; + } + } + + if ($check_flag == false) { + $this->enabled = false; + } + } + } + + function javascript_validation() { + $js = ' if (payment_value == "' . $this->code . '") {' . "\n" . + ' var cc_owner = document.checkout_payment.cc_owner.value;' . "\n" . + ' var cc_number = document.checkout_payment.cc_number.value;' . "\n" . + ' if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" . + ' error_message = error_message + "' . MODULE_PAYMENT_CC_TEXT_JS_CC_OWNER . '";' . "\n" . + ' error = 1;' . "\n" . + ' }' . "\n" . + ' if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" . + ' error_message = error_message + "' . MODULE_PAYMENT_CC_TEXT_JS_CC_NUMBER . '";' . "\n" . + ' error = 1;' . "\n" . + ' }' . "\n" . + ' }' . "\n"; + + return $js; + } + + function selection() { + global $order; + + for ($i=1; $i<13; $i++) { + $expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000))); + } + + $today = getdate(); + for ($i=$today['year']; $i < $today['year']+10; $i++) { + $expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i))); + } + + $selection = array('id' => $this->code, + 'module' => $this->title, + 'fields' => array(array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_OWNER, + 'field' => tep_draw_input_field('cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'])), + array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_NUMBER, + 'field' => tep_draw_input_field('cc_number')), + array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_EXPIRES, + 'field' => tep_draw_pull_down_menu('cc_expires_month', $expires_month) . ' ' . tep_draw_pull_down_menu('cc_expires_year', $expires_year)))); + + return $selection; + } + + function pre_confirmation_check() { + global $HTTP_POST_VARS; + + include(DIR_WS_CLASSES . 'cc_validation.php'); + + $cc_validation = new cc_validation(); + $result = $cc_validation->validate($HTTP_POST_VARS['cc_number'], $HTTP_POST_VARS['cc_expires_month'], $HTTP_POST_VARS['cc_expires_year']); + + $error = ''; + switch ($result) { + case -1: + $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4)); + break; + case -2: + case -3: + case -4: + $error = TEXT_CCVAL_ERROR_INVALID_DATE; + break; + case false: + $error = TEXT_CCVAL_ERROR_INVALID_NUMBER; + break; + } + + if ( ($result == false) || ($result < 1) ) { + $payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&cc_owner=' . urlencode($HTTP_POST_VARS['cc_owner']) . '&cc_expires_month=' . $HTTP_POST_VARS['cc_expires_month'] . '&cc_expires_year=' . $HTTP_POST_VARS['cc_expires_year']; + + tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false)); + } + + $this->cc_card_type = $cc_validation->cc_type; + $this->cc_card_number = $cc_validation->cc_number; + } + + function confirmation() { + global $HTTP_POST_VARS; + + $confirmation = array('title' => $this->title . ': ' . $this->cc_card_type, + 'fields' => array(array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_OWNER, + 'field' => $HTTP_POST_VARS['cc_owner']), + array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_NUMBER, + 'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)), + array('title' => MODULE_PAYMENT_CC_TEXT_CREDIT_CARD_EXPIRES, + 'field' => strftime('%B, %Y', mktime(0,0,0,$HTTP_POST_VARS['cc_expires_month'], 1, '20' . $HTTP_POST_VARS['cc_expires_year']))))); + + return $confirmation; + } + + function process_button() { + global $HTTP_POST_VARS; + + $process_button_string = tep_draw_hidden_field('cc_owner', $HTTP_POST_VARS['cc_owner']) . + tep_draw_hidden_field('cc_expires', $HTTP_POST_VARS['cc_expires_month'] . $HTTP_POST_VARS['cc_expires_year']) . + tep_draw_hidden_field('cc_type', $this->cc_card_type) . + tep_draw_hidden_field('cc_number', $this->cc_card_number); + + return $process_button_string; + } + + function before_process() { + global $HTTP_POST_VARS, $order; + + if ( (defined('MODULE_PAYMENT_CC_EMAIL')) && (tep_validate_email(MODULE_PAYMENT_CC_EMAIL)) ) { + $len = strlen($HTTP_POST_VARS['cc_number']); + + $this->cc_middle = substr($HTTP_POST_VARS['cc_number'], 4, ($len-8)); + $order->info['cc_number'] = substr($HTTP_POST_VARS['cc_number'], 0, 4) . str_repeat('X', (strlen($HTTP_POST_VARS['cc_number']) - 8)) . substr($HTTP_POST_VARS['cc_number'], -4); + } + } + + function after_process() { + global $insert_id; + + if ( (defined('MODULE_PAYMENT_CC_EMAIL')) && (tep_validate_email(MODULE_PAYMENT_CC_EMAIL)) ) { + $message = 'Order #' . $insert_id . "\n\n" . 'Middle: ' . $this->cc_middle . "\n\n"; + + tep_mail('', MODULE_PAYMENT_CC_EMAIL, 'Extra Order Info: #' . $insert_id, $message, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS); + } + } + + function get_error() { + global $HTTP_GET_VARS; + + $error = array('title' => MODULE_PAYMENT_CC_TEXT_ERROR, + 'error' => stripslashes(urldecode($HTTP_GET_VARS['error']))); + + return $error; + } + + function check() { + if (!isset($this->_check)) { + $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_CC_STATUS'"); + $this->_check = tep_db_num_rows($check_query); + } + return $this->_check; + } + + function install() { + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Credit Card Module', 'MODULE_PAYMENT_CC_STATUS', 'True', 'Do you want to accept credit card payments?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Split Credit Card E-Mail Address', 'MODULE_PAYMENT_CC_EMAIL', '', 'If an e-mail address is entered, the middle digits of the credit card number will be sent to the e-mail address (the outside digits are stored in the database with the middle digits censored)', '6', '0', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_CC_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0' , now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_CC_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_CC_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())"); + } + + function remove() { + tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); + } + + function keys() { + return array('MODULE_PAYMENT_CC_STATUS', 'MODULE_PAYMENT_CC_EMAIL', 'MODULE_PAYMENT_CC_ZONE', 'MODULE_PAYMENT_CC_ORDER_STATUS_ID', 'MODULE_PAYMENT_CC_SORT_ORDER'); + } + } +?> diff --git a/psp_admin/inc/payment_modules/payment/cod.php b/psp_admin/inc/payment_modules/payment/cod.php new file mode 100644 index 0000000000..f22f373031 --- /dev/null +++ b/psp_admin/inc/payment_modules/payment/cod.php @@ -0,0 +1,119 @@ +code = 'cod'; + $this->title = MODULE_PAYMENT_COD_TEXT_TITLE; + $this->description = MODULE_PAYMENT_COD_TEXT_DESCRIPTION; + $this->sort_order = MODULE_PAYMENT_COD_SORT_ORDER; + $this->enabled = ((MODULE_PAYMENT_COD_STATUS == 'True') ? true : false); + + if ((int)MODULE_PAYMENT_COD_ORDER_STATUS_ID > 0) { + $this->order_status = MODULE_PAYMENT_COD_ORDER_STATUS_ID; + } + + if (is_object($order)) $this->update_status(); + } + +// class methods + function update_status() { + global $order; + + if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_COD_ZONE > 0) ) { + $check_flag = false; + $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_COD_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); + while ($check = tep_db_fetch_array($check_query)) { + if ($check['zone_id'] < 1) { + $check_flag = true; + break; + } elseif ($check['zone_id'] == $order->delivery['zone_id']) { + $check_flag = true; + break; + } + } + + if ($check_flag == false) { + $this->enabled = false; + } + } + +// disable the module if the order only contains virtual products + if ($this->enabled == true) { + if ($order->content_type == 'virtual') { + $this->enabled = false; + } + } + } + + function javascript_validation() { + return false; + } + + function selection() { + return array('id' => $this->code, + 'module' => $this->title); + } + + function pre_confirmation_check() { + return false; + } + + function confirmation() { + return false; + } + + function process_button() { + return false; + } + + function before_process() { + return false; + } + + function after_process() { + return false; + } + + function get_error() { + return false; + } + + function check() { + if (!isset($this->_check)) { + $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_COD_STATUS'"); + $this->_check = tep_db_num_rows($check_query); + } + return $this->_check; + } + + function install() { + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Cash On Delivery Module', 'MODULE_PAYMENT_COD_STATUS', 'True', 'Do you want to accept Cash On Delevery payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_COD_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_COD_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_COD_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())"); + } + + function remove() { + tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); + } + + function keys() { + return array('MODULE_PAYMENT_COD_STATUS', 'MODULE_PAYMENT_COD_ZONE', 'MODULE_PAYMENT_COD_ORDER_STATUS_ID', 'MODULE_PAYMENT_COD_SORT_ORDER'); + } + } +?> diff --git a/psp_admin/inc/payment_modules/payment/ogone.php b/psp_admin/inc/payment_modules/payment/ogone.php new file mode 100644 index 0000000000..72c3206604 --- /dev/null +++ b/psp_admin/inc/payment_modules/payment/ogone.php @@ -0,0 +1,148 @@ +code = 'ogone'; + $this->title = MODULE_PAYMENT_OGONE_TEXT_TITLE; + $this->description = MODULE_PAYMENT_OGONE_TEXT_DESCRIPTION; + $this->enabled = MODULE_PAYMENT_OGONE_STATUS; + $this->form_action_url = 'https://secure.ogone.com/ncol/' . MODULE_PAYMENT_OGONE_MODE . '/orderstandard.asp'; + } + + function javascript_validation() { + return true; + } + + function selection() { + return array('id' => $this->code, 'module' => $this->title); + } + + function pre_confirmation_check() { + return false; + } + + function confirmation() { + return false; + } + + /* For a detailled spec on these fields for ogone see https://secure.ogone.com/ncol/test/admin_ogone.asp */ + function process_button() { + global $customer_id, $order, $currencies; + + $ogone_orderID = $customer_id . date('YmdHis'); + $ogone_amount = number_format($order->info['total'] * 100 * $order->info['currency_value'], 0, '', ''); + + $process_button_string = "\n" . + tep_draw_hidden_field('orderID', $ogone_orderID) . "\n" . + tep_draw_hidden_field('pspid', MODULE_PAYMENT_OGONE_PSPID) . "\n" . + tep_draw_hidden_field('RL', 'ncol-2.0') . "\n" . + tep_draw_hidden_field('currency', $order->info['currency']) . "\n" . + tep_draw_hidden_field('language', MODULE_PAYMENT_OGONE_LANGUAGE) . "\n" . + tep_draw_hidden_field('amount', $ogone_amount) . "\n" . + tep_draw_hidden_field('TITLE', STORE_NAME . ': ' . MODULE_PAYMENT_OGONE_TITLE_OGONE) . "\n" . + tep_draw_hidden_field('accepturl', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL')) . "\n" . + tep_draw_hidden_field('declineurl', tep_href_link(FILENAME_SHOPPING_CART)) . "\n" . + tep_draw_hidden_field('exceptionurl', tep_href_link(FILENAME_SHOPPING_CART)) . "\n" . + tep_draw_hidden_field('cancelurl', tep_href_link(FILENAME_SHOPPING_CART)) . "\n" . + tep_draw_hidden_field('CN', $order->customer['firstname'] . ' ' . $order->customer['lastname']) . "\n" . + tep_draw_hidden_field('catalogurl', tep_href_link(FILENAME_DEFAULT)) . "\n" . + tep_draw_hidden_field('owneraddress', $order->delivery['street_address']) . "\n" . + tep_draw_hidden_field('ownerZIP', $order->delivery['postcode']) . "\n" . + tep_draw_hidden_field('COM', MODULE_PAYMENT_OGONE_TITLE_OGONE) . "\n" . + tep_draw_hidden_field('email', $order->customer['email_address']) . "\n"; + + $sign = $ogone_orderID . $ogone_amount . $order->info['currency'] . MODULE_PAYMENT_OGONE_PSPID . MODULE_PAYMENT_OGONE_SHA_STRING; + $process_button_string .= tep_draw_hidden_field('SHASign', sha1($sign)) . "\n"; + + if(MODULE_PAYMENT_OGONE_DYNAMIC_TEMPLATE == 'Yes') { + $process_button_string .= tep_draw_hidden_field('TP', MODULE_PAYMENT_OGONE_DYNAMIC_TEMPLATE_URL) . "\n"; + } + + return $process_button_string; + } + + function before_process() { + return false; + } + + function after_process() { + return false; + } + + function output_error() { + return false; + } + + function check() { + if (!isset($this->check)) { + $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_OGONE_STATUS'"); + $this->check = tep_db_num_rows($check_query); + } + return $this->check; + } + + function install() { + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Allow OGONE Payments', 'MODULE_PAYMENT_OGONE_STATUS', 'True', 'Do you want to accept OGONE payments?', '6', '20', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('OGONE Status Mode', 'MODULE_PAYMENT_OGONE_MODE', 'test', 'Status mode for OGONE payments?', '6', '21', 'tep_cfg_select_option(array(\'test\', \'prod\'), ', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('OGONE Merchant ID', 'MODULE_PAYMENT_OGONE_PSPID', 'TESTSTD', 'Merchant NCOL ID', '6', '22', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('OGONE Client Language', 'MODULE_PAYMENT_OGONE_LANGUAGE', 'en_US', 'Client language', '6', '23', 'tep_cfg_pull_down_ogone_language(', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('OGONE SHA String', 'MODULE_PAYMENT_OGONE_SHA_STRING', '', 'SHA string used for the signature (set at the merchant administration page)', '6', '24', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('OGONE Dynamic Template', 'MODULE_PAYMENT_OGONE_DYNAMIC_TEMPLATE', 'No', 'Use dynamic template for payment form?', '6', '25', 'tep_cfg_select_option(array(\'Yes\', \'No\'), ',now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('OGONE Dynamic Template URL', 'MODULE_PAYMENT_OGONE_DYNAMIC_TEMPLATE_URL', ' http://www.ogone.com/ncol/template_standard.htm', 'Change the appearance of the payment form', '6', '25', now())"); + } + + function remove() { + tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . join($this->keys(), "','") . "')"); + } + + function keys() { + return array( + 'MODULE_PAYMENT_OGONE_STATUS', + 'MODULE_PAYMENT_OGONE_MODE', + 'MODULE_PAYMENT_OGONE_PSPID', + 'MODULE_PAYMENT_OGONE_LANGUAGE', + 'MODULE_PAYMENT_OGONE_SHA_STRING', + 'MODULE_PAYMENT_OGONE_DYNAMIC_TEMPLATE', + 'MODULE_PAYMENT_OGONE_DYNAMIC_TEMPLATE_URL' + ); + } +} + +function tep_cfg_pull_down_ogone_language($language_id, $configuration_key = NULL) { + $name = isset($configuration_key) ? 'configuration[' . $configuration_key . ']' : 'configuration_value'; + + /* languages supported by Ogone */ + $languages = array( + 'en_US' => 'English', + 'fr_FR' => 'French', + 'nl_NL' => 'Dutch', + 'it_IT' => 'Italian', + 'de_DE' => 'German', + 'es_ES' => 'Spanish', + 'no_NO' => 'Norvegian' + ); + + $languages_array = array(); + + foreach($languages as $id => $text) { + $languages_array[] = array('id' => $id, 'text' => $text); + } + + return tep_draw_pull_down_menu($name, $languages_array, $language_id); +} + +?> diff --git a/psp_admin/inc/payment_modules/payment/paypal.php b/psp_admin/inc/payment_modules/payment/paypal.php new file mode 100644 index 0000000000..203c8296e4 --- /dev/null +++ b/psp_admin/inc/payment_modules/payment/paypal.php @@ -0,0 +1,141 @@ +code = 'paypal'; + $this->title = MODULE_PAYMENT_PAYPAL_TEXT_TITLE; + $this->description = MODULE_PAYMENT_PAYPAL_TEXT_DESCRIPTION; + $this->sort_order = MODULE_PAYMENT_PAYPAL_SORT_ORDER; + $this->enabled = ((MODULE_PAYMENT_PAYPAL_STATUS == 'True') ? true : false); + + if ((int)MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID > 0) { + $this->order_status = MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID; + } + + if (is_object($order)) $this->update_status(); + + $this->form_action_url = 'https://secure.paypal.com/cgi-bin/webscr'; + } + +// class methods + function update_status() { + global $order; + + if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PAYPAL_ZONE > 0) ) { + $check_flag = false; + $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PAYPAL_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id"); + while ($check = tep_db_fetch_array($check_query)) { + if ($check['zone_id'] < 1) { + $check_flag = true; + break; + } elseif ($check['zone_id'] == $order->billing['zone_id']) { + $check_flag = true; + break; + } + } + + if ($check_flag == false) { + $this->enabled = false; + } + } + } + + function javascript_validation() { + return false; + } + + function selection() { + return array('id' => $this->code, + 'module' => $this->title); + } + + function pre_confirmation_check() { + return false; + } + + function confirmation() { + return false; + } + + function process_button() { + global $order, $currencies, $currency; + + if (MODULE_PAYMENT_PAYPAL_CURRENCY == 'Selected Currency') + { + $my_currency = $currency; + } + else + { + $my_currency = substr(MODULE_PAYMENT_PAYPAL_CURRENCY, 5); + } + if (!in_array($my_currency, array('CAD', 'EUR', 'GBP', 'JPY', 'USD'))) + { + $my_currency = 'USD'; + } + $process_button_string = tep_draw_hidden_field('cmd', '_xclick') . + tep_draw_hidden_field('business', MODULE_PAYMENT_PAYPAL_ID) . + tep_draw_hidden_field('item_name', STORE_NAME) . + tep_draw_hidden_field('amount', number_format(($order->info['total'] - $order->info['shipping_cost']) * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency))) . + tep_draw_hidden_field('shipping', number_format($order->info['shipping_cost'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency))) . + tep_draw_hidden_field('currency_code', $my_currency) . + tep_draw_hidden_field('return', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL')) . + tep_draw_hidden_field('cancel_return', tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); + + //print_r($process_button_string); + return $process_button_string; + + } + + function before_process() { + return false; + } + + function after_process() { + return false; + } + + function output_error() { + return false; + } + + function check() { + if (!isset($this->_check)) { + $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_STATUS'"); + $this->_check = tep_db_num_rows($check_query); + } + return $this->_check; + } + + function install() { + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable PayPal Module', 'MODULE_PAYMENT_PAYPAL_STATUS', 'True', 'Do you want to accept PayPal payments?', '6', '3', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('E-Mail Address', 'MODULE_PAYMENT_PAYPAL_ID', 'you@yourbusiness.com', 'The e-mail address to use for the PayPal service', '6', '4', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Currency', 'MODULE_PAYMENT_PAYPAL_CURRENCY', 'Selected Currency', 'The currency to use for credit card transactions', '6', '6', 'tep_cfg_select_option(array(\'Selected Currency\',\'Only USD\',\'Only CAD\',\'Only EUR\',\'Only GBP\',\'Only JPY\'), ', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_PAYPAL_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_PAYPAL_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())"); + tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())"); + } + + function remove() { + tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); + } + + function keys() { + return array('MODULE_PAYMENT_PAYPAL_STATUS', 'MODULE_PAYMENT_PAYPAL_ID', 'MODULE_PAYMENT_PAYPAL_CURRENCY', 'MODULE_PAYMENT_PAYPAL_ZONE', 'MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID', 'MODULE_PAYMENT_PAYPAL_SORT_ORDER'); + } + } +?> diff --git a/psp_admin/inc/payment_modules/shipping.php b/psp_admin/inc/payment_modules/shipping.php new file mode 100644 index 0000000000..1a630452b3 --- /dev/null +++ b/psp_admin/inc/payment_modules/shipping.php @@ -0,0 +1,93 @@ +add(NAVBAR_TITLE, tep_href_link(FILENAME_SHIPPING)); +?> + +> + + +<?php echo TITLE; ?> + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + + + + +
+ + + + +
+ + + +
+ + + +
+ + + + + +
' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . ''; ?>
+ + + +
+ + + + + +
+ + + diff --git a/psp_admin/inc/payment_modules/validations.php b/psp_admin/inc/payment_modules/validations.php new file mode 100755 index 0000000000..766cbd5001 --- /dev/null +++ b/psp_admin/inc/payment_modules/validations.php @@ -0,0 +1,122 @@ +@,;:\.\\\"\[]"; + $atom = "$valid_chars+"; + $quoted_user='(\"[^\"]*\")'; + $word = "($atom|$quoted_user)"; + $user_pat = "^$word(\.$word)*$"; + $ip_domain_pat='^\[([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\]$'; + $domain_pat = "^$atom(\.$atom)*$"; + + if (eregi($mail_pat, $email, $components)) { + $user = $components[1]; + $domain = $components[2]; + // validate user + if (eregi($user_pat, $user)) { + // validate domain + if (eregi($ip_domain_pat, $domain, $ip_components)) { + // this is an IP address + for ($i=1;$i<=4;$i++) { + if ($ip_components[$i] > 255) { + $valid_address = false; + break; + } + } + } + else { + // Domain is a name, not an IP + if (eregi($domain_pat, $domain)) { + /* domain name seems valid, but now make sure that it ends in a valid TLD or ccTLD + and that there's a hostname preceding the domain or country. */ + $domain_components = explode(".", $domain); + // Make sure there's a host name preceding the domain. + if (sizeof($domain_components) < 2) { + $valid_address = false; + } else { + $top_level_domain = strtolower($domain_components[sizeof($domain_components)-1]); + // Allow all 2-letter TLDs (ccTLDs) + if (eregi('^[a-z][a-z]$', $top_level_domain) != 1) { + $tld_pattern = ''; + // Get authorized TLDs from text file + $tlds = file(DIR_WS_INCLUDES . 'tld.txt'); + while (list(,$line) = each($tlds)) { + // Get rid of comments + $words = explode('#', $line); + $tld = trim($words[0]); + // TLDs should be 3 letters or more + if (eregi('^[a-z]{3,}$', $tld) == 1) { + $tld_pattern .= '^' . $tld . '$|'; + } + } + // Remove last '|' + $tld_pattern = substr($tld_pattern, 0, -1); + if (eregi("$tld_pattern", $top_level_domain) == 0) { + $valid_address = false; + } + } + } + } + else { + $valid_address = false; + } + } + } + else { + $valid_address = false; + } + } + else { + $valid_address = false; + } + if ($valid_address && ENTRY_EMAIL_ADDRESS_CHECK == 'true') { + if (!checkdnsrr($domain, "MX") && !checkdnsrr($domain, "A")) { + $valid_address = false; + } + } + return $valid_address; + } +?> diff --git a/psp_admin/inc/wrap_osc_payment.php b/psp_admin/inc/wrap_osc_payment.php new file mode 100644 index 0000000000..e4e85f1859 --- /dev/null +++ b/psp_admin/inc/wrap_osc_payment.php @@ -0,0 +1,130 @@ +wrap = new $plug();"); + } +*/ + global $conn; + global $currencies; + global $currency; + global $order; + global $HTTP_POST_VARS; + global $sav2wrapper; + global $base_url; + global $trans; + $this->trans =& $trans; + $this->base_url = $base_url; + $this->conn = $conn; + tep_db_connect() or die("hmmm... tep_db_connect error in wrap_osc_payment"); + $this->read_settings(); + $currencies = new currencies(); + $currency = $currencies->get_title('EUR'); + if($plug !='' and $no_order==false) + { + $order = new order(1); + } + $this->sav2wrapper = & $sav2wrapper; + //$this->tplsav2 = & $sav2wrapper; + parent::payment($plug); + //$this->wrap = & $this->(); + } + + + function remove() + { + $this->wrap->remove(); + return "removed"; + } + + function install() + { + $this->wrap->install(); + return "installed"; + } + + function keys() + { + + $plugin_keys = $this->wrap->keys(); + return $plugin_keys; + } +/* + function selection() + { + $this->db = clone($GLOBALS['egw']->db); + $query = "SELECT configuration_value FROM egw_oscadmin_osc_conf WHERE configuration_key = 'MODULE_PAYMENT_INSTALLED'; "; + + $geti = $this->db->query($query); + while ($this->db->next_record()) + { + $row = $this->db->row(); + if ($row != "") + { + $modarray = explode(';',str_replace('.php','',$row['configuration_value'])); + foreach($modarray as $key=>$mod) + { + $_ret[$key]['module']= $mod; + $_ret[$key]['id'] = $mod; + } + return $_ret; + } else + return array(''); + + } + + } +*/ + function getName() + { + return $GLOBALS[$this->selected_module]->title; + } + + function read_settings() + { + // set the application parameters + $configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION); + while ($configuration = tep_db_fetch_array($configuration_query)) + { + define($configuration['cfgKey'], $configuration['cfgValue']); + } + } + + function convert_order_to_osc() + { + $GLOBALS['order'] = new order(1); + } + + function get_installedplugs() + { + die ('get_installedplugs in wrap_osc_payment'); + return $_result; + } + + } +?> diff --git a/psp_admin/inc/wrap_osc_plugin.php b/psp_admin/inc/wrap_osc_plugin.php new file mode 100644 index 0000000000..b0e79c9c33 --- /dev/null +++ b/psp_admin/inc/wrap_osc_plugin.php @@ -0,0 +1,49 @@ +wrap = new $plug();"); + } + tep_db_connect() or die("hmmm... tep_db_connect error in wrap_osc_plugin"); + } + + + function remove() + { + $this->wrap->remove(); + } + + function install() + { + $this->wrap->install(); + } + + function keys() + { + $plugin_keys = $this->wrap->keys(); + return $plugin_keys; + } + } diff --git a/psp_admin/index.php b/psp_admin/index.php new file mode 100644 index 0000000000..53339d6db9 --- /dev/null +++ b/psp_admin/index.php @@ -0,0 +1,27 @@ + 'psp_admin', + 'noheader' => True, + 'nonavbar' => True, + 'enable_nextmatchs_class' => True + ); + include('../header.inc.php'); + + ExecMethod('psp_admin.ui_pspadmin.settings'); + +?>