| [ Indice ] |
Riferimento incrociato di Joomla! 1.5.14 - VM 1.1.4Servizio fornito da VMItalia |
[Vedi sommario] [Stampa] [Vedi testo]
1 <?php 2 if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); 3 /** 4 * 5 * @version $Id: ps_creditcard.php 1872 2009-08-24 14:59:44Z soeren_nb $ 6 * @package VirtueMart 7 * @subpackage classes 8 * @copyright Copyright (C) 2004-2009 soeren - All rights reserved. 9 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php 10 * VirtueMart is free software. This version may have been modified pursuant 11 * to the GNU General Public License, and as distributed it includes or 12 * is derivative of works licensed under the GNU General Public License or 13 * other free or open source software licenses. 14 * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. 15 * 16 * http://virtuemart.net 17 */ 18 19 /** 20 * The class is is used to manage the CreditCards in your store. 21 * 22 */ 23 class vm_ps_creditcard { 24 25 /** 26 * Validates the input parameters onBeforeCreditCardAdd 27 * 28 * @param array $d 29 * @return boolean 30 */ 31 function validate_add($d) { 32 global $vmLogger, $VM_LANG; 33 $db = new ps_DB; 34 35 if (!$d["creditcard_name"]) { 36 $vmLogger->err( $VM_LANG->_('VM_CREDITCARD_ERR_NAME') ); 37 return False; 38 } 39 if (!$d["creditcard_code"]) { 40 $vmLogger->err( $VM_LANG->_('VM_CREDITCARD_ERR_CODE') ); 41 return False; 42 } 43 44 $q = "SELECT count(*) as rowcnt FROM `#__{vm}_creditcard` WHERE"; 45 $q .= " creditcard_name='" . $db->getEscaped($d["creditcard_name"]) . "' OR "; 46 $q .= " creditcard_code='" . $db->getEscaped( $d["creditcard_code"]) . "'"; 47 $db->query( $q ); 48 $db->next_record(); 49 if ($db->f("rowcnt") > 0) { 50 $vmLogger->err( $VM_LANG->_('VM_CREDITCARD_EXISTS') ); 51 return False; 52 } 53 return True; 54 } 55 56 57 /** 58 * Validates the input parameters onBeforeCreditCardUpdate 59 * 60 * @param array $d 61 * @return boolean 62 */ 63 function validate_update($d) { 64 global $VM_LANG; 65 66 if (!$d["creditcard_name"]) { 67 $GLOBALS['vmLogger']->err( $VM_LANG->_('VM_CREDITCARD_ERR_NAME') ); 68 return False; 69 } 70 if (!$d["creditcard_code"]) { 71 $GLOBALS['vmLogger']->err( $VM_LANG->_('VM_CREDITCARD_ERR_CODE') ); 72 return False; 73 } 74 75 return true; 76 } 77 78 /** 79 * Validates the input parameters onBeforeCreditCardDelete 80 * 81 * @param array $d 82 * @return boolean 83 */ 84 function validate_delete($d) { 85 global $VM_LANG; 86 if (!$d["creditcard_id"]) { 87 $GLOBALS['vmLogger']->err( $VM_LANG->_('VM_CREDITCARD_ERR_DELETE_SELECT') ); 88 return False; 89 } 90 else { 91 return True; 92 } 93 } 94 95 /** 96 * creates a new Credit Card Entry 97 * 98 * @param array $d 99 * @return boolean 100 */ 101 function add(&$d) { 102 global $VM_LANG; 103 104 $hash_secret="VMisCool"; 105 $db = new ps_DB; 106 $timestamp = time(); 107 108 if (!$this->validate_add($d)) { 109 return False; 110 } 111 $fields = array( 'vendor_id' => $_SESSION["ps_vendor_id"], 112 'creditcard_name' => vmGet($d,'creditcard_name'), 113 'creditcard_code' => vmGet($d,'creditcard_code'), 114 ); 115 $db->buildQuery('INSERT', '#__{vm}_creditcard', $fields ); 116 if( $db->query() ) { 117 $GLOBALS['vmLogger']->info( $VM_LANG->_('VM_CREDITCARD_ADDED') ); 118 $_REQUEST['creditcard_id'] = $db->last_insert_id(); 119 return true; 120 } 121 return false; 122 } 123 124 /** 125 * Updates a given Credit Card Record 126 * 127 * @param array $d 128 * @return boolean 129 */ 130 function update(&$d) { 131 global $VM_LANG; 132 133 $db = new ps_DB; 134 $timestamp = time(); 135 136 if (!$this->validate_update($d)) { 137 $d["error"] = $this->error; 138 return False; 139 } 140 $fields = array( 'vendor_id' => $_SESSION["ps_vendor_id"], 141 'creditcard_name' => vmGet($d,'creditcard_name'), 142 'creditcard_code' => vmGet($d,'creditcard_code'), 143 ); 144 $db->buildQuery('UPDATE', '#__{vm}_creditcard', $fields, 'WHERE creditcard_id='.(int)$d["creditcard_id"]); 145 if( $db->query() ) { 146 $GLOBALS['vmLogger']->info( $VM_LANG->_('VM_CREDITCARD_UPDATED') ); 147 $_REQUEST['creditcard_id'] = $db->last_insert_id(); 148 return true; 149 } 150 return false; 151 } 152 153 /** 154 * Controller for Deleting Credit Card Records. 155 */ 156 function delete(&$d) { 157 158 $creditcard_id = $d["creditcard_id"]; 159 160 if( is_array( $creditcard_id)) { 161 foreach( $creditcard_id as $creditcard) { 162 if( !$this->delete_creditcard( $creditcard, $d )) 163 return false; 164 } 165 return true; 166 } 167 else { 168 return $this->delete_creditcard( $creditcard_id, $d ); 169 } 170 } 171 /** 172 * Deletes a Credit Card Record. 173 */ 174 function delete_creditcard( $creditcard_id, &$d ) { 175 global $db; 176 177 if (!$this->validate_delete($d)) { 178 $d["error"]=$this->error; 179 return False; 180 } 181 $q = "DELETE FROM #__{vm}_creditcard WHERE creditcard_id=" . (int)$creditcard_id; 182 $db->query($q); 183 return True; 184 } 185 186 /** 187 * Creates a Checkbox-List with all Credit Card Names 188 * 189 * @param string $selected: a comma-delimited list of creditcard_IDs, assigned to this payment method 190 */ 191 function creditcard_checkboxes( $selected ) { 192 193 if (!empty( $selected )) 194 $selected_arr = explode( ",", $selected); 195 else 196 $selected_arr = Array(); 197 $db = new ps_DB; 198 $q = "SELECT creditcard_name, creditcard_id FROM #__{vm}_creditcard WHERE vendor_id='".$_SESSION['ps_vendor_id']."'"; 199 $db->query( $q ); 200 $html = ""; 201 $i = 0; 202 while( $db->next_record() ) { 203 $html .= "<input type=\"checkbox\" name=\"creditcard[]\" id=\"creditcard$i\" value=\"".$db->f("creditcard_id")."\" class=\"inputbox\" "; 204 if (in_array($db->f("creditcard_id"), $selected_arr)) { 205 $html .= "checked=\"checked\""; 206 } 207 $html .= "/>"; 208 $html .= "<label for=\"creditcard$i\">".$db->f("creditcard_name")."</label><br/>"; 209 $i++; 210 } 211 212 echo $html; 213 } 214 215 /** 216 * Creates a Drop Down - List of Credit Card Records 217 * 218 * @param int $payment_method_id 219 */ 220 function creditcard_selector( $payment_method_id="" ) { 221 222 $db = new ps_DB; 223 224 /*** Select all credit card records ***/ 225 if(empty($payment_method_id)) { 226 $q = "SELECT creditcard_name, creditcard_id,creditcard_code FROM #__{vm}_creditcard WHERE vendor_id='".$_SESSION['ps_vendor_id']."'"; 227 } 228 /*** Get only accepted credit cards records ***/ 229 else { 230 $q = 'SELECT accepted_creditcards FROM #__{vm}_payment_method WHERE payment_method_id='.(int)$payment_method_id; 231 $db->query( $q ); 232 $db->next_record(); 233 $cc_array = explode( ",", $db->f("accepted_creditcards")); 234 $q = "SELECT creditcard_name,creditcard_id,creditcard_code FROM #__{vm}_creditcard WHERE vendor_id='".$_SESSION['ps_vendor_id']."' AND ("; 235 foreach ( $cc_array as $idx => $creditcard_id ) { 236 $q .= "creditcard_id='$creditcard_id' "; 237 if( $idx+1 < sizeof( $cc_array )) $q.= "OR "; 238 else $q .= ")"; 239 } 240 } 241 $db->query( $q ); 242 243 while( $db->next_record() ) { 244 $array[$db->f("creditcard_code")] = $db->f("creditcard_name"); 245 } 246 echo ps_html::selectList('creditcard_code', '', $array ); 247 } 248 249 /** 250 * Build a Credit Card list for each CreditCard Payment Method 251 * Uses JavsScript from mambojavascript: changeDynaList() 252 * 253 * @param ps_DB $db_cc 254 * @return string 255 */ 256 function creditcard_lists( &$db_cc ) { 257 global $mainframe; 258 if( vmIsJoomla('1.5') ) { 259 $document = JFactory::getDocument(); 260 $document->addScript('includes/js/joomla.javascript.js'); 261 } 262 $db = new ps_DB; 263 264 $db_cc->next_record(); 265 // Build the Credit Card lists for each CreditCard Payment Method 266 $script = "<script language=\"javascript\" type=\"text/javascript\">\n"; 267 $script .= "<!--\n"; 268 $script .= "var originalOrder = '1';\n"; 269 $script .= "var originalPos = '".$db_cc->f("payment_method_name")."';\n"; 270 $script .= "var orders = new Array(); // array in the format [key,value,text]\n"; 271 $i = 0; 272 $db_cc->reset(); 273 274 while( $db_cc->next_record() ) { 275 $accepted_creditcards = explode( ",", $db_cc->f("accepted_creditcards") ); 276 $cards = Array(); 277 foreach( $accepted_creditcards as $value ) { 278 if( !empty( $value)) { 279 $q = 'SELECT creditcard_code,creditcard_name FROM #__{vm}_creditcard WHERE creditcard_id='.(int)$value; 280 $db->query( $q ); 281 $db->next_record(); 282 283 $cards[$db->f('creditcard_code')] = shopMakeHtmlSafe( $db->f('creditcard_name') ); 284 } 285 } 286 foreach( $cards as $code => $name ) { 287 $script .= "orders[".$i++."] = new Array( '".addslashes($db_cc->f("payment_method_name"))."','$code','$name' );\n"; 288 } 289 290 } 291 $script .= "function changeCreditCardList() { \n"; 292 $script .= "var selected_payment = null; 293 for (var i=0; i<document.adminForm.payment_method_id.length; i++) 294 if (document.adminForm.payment_method_id[i].checked) 295 selected_payment = document.adminForm.payment_method_id[i].id;\n"; 296 $script .="changeDynaList('creditcard_code',orders,selected_payment, originalPos, originalOrder);\n"; 297 $script .="}\n"; 298 $script .="//-->\n"; 299 $script .="</script>\n"; 300 $script .= '<noscript>'.ps_html::selectList('creditcard_code', key($cards), $cards ).'</noscript>'; 301 return $script; 302 } 303 } 304 305 // Check if there is an extended class in the Themes and if it is allowed to use them 306 // If the class is called outside Virtuemart, we have to make sure to load the settings 307 // Thomas Kahl - Feb. 2009 308 if (!defined('VM_ALLOW_EXTENDED_CLASSES') && file_exists(dirname(__FILE__).'/../virtuemart.cfg.php')) { 309 include_once(dirname(__FILE__).'/../virtuemart.cfg.php'); 310 } 311 // If settings are loaded, extended Classes are allowed and the class exisits... 312 if (defined('VM_ALLOW_EXTENDED_CLASSES') && defined('VM_THEMEPATH') && VM_ALLOW_EXTENDED_CLASSES && file_exists(VM_THEMEPATH.'user_class/'.basename(__FILE__))) { 313 // Load the theme-user_class as extended 314 include_once(VM_THEMEPATH.'user_class/'.basename(__FILE__)); 315 } else { 316 // Otherwise we have to use the original classname to extend the core-class 317 class ps_creditcard extends vm_ps_creditcard {} 318 } 319 ?>
titolo
Descrizione
Corpo
titolo
Descrizione
Corpo
titolo
Descrizione
Corpo
titolo
Corpo
| Generato il: Mon Oct 19 20:29:27 2009 | Generato con PHPXref 0.7 |