| [ 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_userfield.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 class vm_ps_userfield extends vmAbstractObject { 20 21 var $_key = 'fieldid'; 22 var $_table_name = '#__{vm}_userfield'; 23 24 function validateOnSave( &$d ) { 25 global $vmLogger, $VM_LANG; 26 /* 27 if( !$this->validate($d)) { 28 return false; 29 }*/ 30 switch($d['type']) { 31 case 'date': 32 $d['cType']='DATE'; 33 break; 34 case 'editorta': 35 case 'textarea': 36 case 'multiselect': 37 case 'multicheckbox': 38 $d['cType']='MEDIUMTEXT'; 39 break; 40 case 'letterman_subscription': 41 case 'yanc_subscription': 42 case 'anjel_subscription': 43 case 'ccnewsletter_subscription': 44 // Set params = 45 $d['params'] = 'newsletter='.substr($d['type'],0,strpos($d['type'], '_') )."\n"; 46 $d['type'] = 'checkbox'; 47 case 'checkbox': 48 $d['cType']='TINYINT'; 49 break; 50 case 'euvatid': 51 $d['params'] = 'shopper_group_id='.$d['shopper_group_id']."\n"; 52 $d['cType']='VARCHAR(255)'; 53 break; 54 case 'age_verification': 55 $d['params'] = 'minimum_age='.(int)$d['minimum_age']."\n"; 56 default: 57 $d['cType']='VARCHAR(255)'; 58 break; 59 } 60 $db = new ps_DB(); 61 62 $sql="SELECT COUNT(*) as num_rows FROM `#__{vm}_userfield` WHERE name='".$db->getEscaped($d['name'])."'"; 63 if( !empty($d['fieldid'])) { 64 $sql .= ' AND fieldid != '.intval($d['fieldid']); 65 } 66 $db->query($sql); $db->next_record(); 67 if($db->f('num_rows')) { 68 $vmLogger->err( sprintf($VM_LANG->_('VM_USERFIELD_ERR_ALREADY'),$d['name']) ); 69 return false; 70 } 71 72 return true; 73 } 74 75 function saveField( &$d ) { 76 global $my, $mosConfig_live_site, $VM_LANG; 77 78 $db = new ps_DB(); 79 80 if ($d['type'] == 'webaddress') { 81 $d['rows'] = $d['webaddresstypes']; 82 if ( !(($d['rows'] == 0) || ($d['rows'] == 2)) ) { 83 $d['rows'] = 0; 84 } 85 } 86 87 $d['name'] = str_replace(" ", "", strtolower($d['name'])); 88 89 if( !$this->validateOnSave($d)) { 90 return false; 91 } 92 // Prevent unpublishing and renaming of IMPORTANT Fields like "email", "username", "password",... 93 $fieldObj = $this->get( $d['fieldid'] ); 94 if( $fieldObj !== false ) { 95 if( in_array( $fieldObj->f('name'), $this->getSkipFields() )) { 96 $d['name'] = $fieldObj->f('name'); 97 $d['required'] = $fieldObj->f('required'); 98 $d['published'] = $fieldObj->f('published'); 99 } 100 } 101 $fields = array( 102 'name' => vmGet($d, 'name' ), 103 'title' => vmGet($d, 'title' ), 104 'description' => vmGet($d, 'description' ), 105 'type' => vmGet($d, 'type' ), 106 'maxlength' => vmGet($d, 'maxlength' ), 107 'size' => vmGet($d, 'size' ), 108 'required' => vmGet($d, 'required' ), 109 'ordering' => vmGet($d, 'ordering' ), 110 'cols' => vmGet($d, 'cols' ), 111 'rows' => vmGet($d, 'rows' ), 112 'value' => vmGet($d, 'value' ), 113 'default' => vmGet($d, 'default' ), 114 'published' => vmGet($d, 'published' ), 115 'registration' => vmGet($d, 'registration' ), 116 'shipping' => vmGet($d, 'shipping' ), 117 'account' => vmGet($d, 'account' ), 118 'readonly' => vmGet($d, 'readonly' ), 119 'calculated' => vmGet($d, 'calculated' ), 120 'params' => vmGet($d, 'params' ), 121 'vendor_id' => vmGet($_SESSION, 'ps_vendor_id', 1 ) 122 ); 123 if( !empty($d['fieldid']) ) { 124 // existing record 125 $db->buildQuery( 'UPDATE', '#__{vm}_userfield', $fields ,'WHERE `fieldid` ='. intval($d['fieldid'] ) ); 126 $db->query(); 127 128 if( $d['type'] != 'delimiter') { 129 $this->changeColumn( $d['name'], $d['cType'], 'update'); 130 } 131 132 } else { 133 // add a new record 134 $sql="SELECT MAX(ordering) as max FROM #__{vm}_userfield"; 135 $db->query($sql); $db->next_record(); 136 $d['ordering'] = $db->f('max')+1; 137 138 $db->buildQuery( 'INSERT', '#__{vm}_userfield', $fields ); 139 $db->query(); 140 141 $_REQUEST['fieldid'] = $db->last_insert_id(); 142 if( $d['type'] != 'delimiter') { 143 $this->changeColumn( $d['name'], $d['cType'], 'add'); 144 } 145 } 146 $fieldNames = vmGet( $d, 'vNames', array() ); 147 $fieldValues = vmGet( $d, 'vValues', array() ); 148 149 $j=1; 150 if( !empty( $d['fieldid'] )) { 151 $db->query( "DELETE FROM #__{vm}_userfield_values" 152 . " WHERE fieldid=".(int)$d['fieldid'] ); 153 } else { 154 $db->query( "SELECT MAX(fieldid) as max FROM `#__{vm}_userfield`" ); 155 $maxID=$db->loadResult(); 156 $d['fieldid']=$maxID; 157 } 158 $n=count( $fieldNames ); 159 for($i=0; $i <= $n; $i++) { 160 if(!empty($fieldNames[$i])) { 161 $fields = array('fieldid' => (int)$d['fieldid'], 162 'fieldtitle' => htmlspecialchars($fieldNames[$i]), 163 'fieldvalue' => htmlspecialchars($fieldValues[$i]), 164 'ordering' => $j ); 165 $db->buildQuery( 'INSERT', '#__{vm}_userfield_values', $fields ); 166 $db->query(); 167 $j++; 168 } 169 } 170 $GLOBALS['vmLogger']->info($VM_LANG->_('VM_USERFIELD_SAVED')); 171 return true; 172 } 173 /** 174 * Add, change or drop fields from the VirtueMart user tables 175 * Currently these are: #__{vm}_user_info, #__{vm}_order_user_info 176 * @param string $column 177 * @param string $type The column type is determined in the validateOnSave function 178 * @param string $action Can be: add, update or delete 179 */ 180 function changeColumn( $column, $type, $action) { 181 182 switch( $action ) { 183 case 'add': $action = 'ADD'; break; 184 case 'update': 185 case 'change': 186 $action = 'CHANGE'; break; 187 case 'delete': $action = 'DROP'; break; 188 default: $action = 'ADD'; break; 189 } 190 $db = new ps_DB(); 191 // The general shopper information table 192 $special = ''; 193 if( $action=='CHANGE') { 194 $special = "`$column`"; 195 } 196 $sql="ALTER TABLE `#__{vm}_user_info` $action `$column` $special $type"; 197 $db->query($sql); 198 // The table where the shopper information at the time of an order is stored 199 $sql="ALTER TABLE `#__{vm}_order_user_info` $action `$column` $special $type"; 200 $db->query($sql); 201 202 } 203 /** 204 * Remove a user field from the system 205 * 206 * @param int $cid 207 * @return boolean The result of the delete action 208 */ 209 function deleteField( &$d ) { 210 global $db, $vmLogger, $VM_LANG; 211 if( !is_array( @$d['fieldid'] )) { 212 $d['fieldid'] = array( $d['fieldid']); 213 } 214 if ( count( @$d['fieldid'] ) < 1) { 215 $vmLogger->err( $VM_LANG->_('VM_USERFIELD_DELETE_SELECT') ); 216 return false; 217 } 218 219 foreach ($d['fieldid'] as $id) { 220 $db->query('SELECT fieldid, name, title, ordering,sys FROM `#__{vm}_userfield` WHERE fieldid ='.intval($id)); 221 $db->next_record(); 222 223 if($db->f('sys')==1) { 224 $vmLogger->err(sprintf($VM_LANG->_('VM_USERFIELD_DELETE_ERR_SYSTEM'),$db->f('name'))); 225 continue; 226 } 227 else { 228 if( $db->f('type') != 'delimiter') { 229 $this->changeColumn( $db->f('name'), '', 'delete'); 230 } 231 232 $db->query('DELETE FROM `#__{vm}_userfield` WHERE fieldid='.(int)$id. ' LIMIT 1' ); 233 234 $db->query( 'UPDATE `#__{vm}_userfield` SET ordering = ordering-1 WHERE ordering > '.intval($db->f('ordering'))); 235 $vmLogger->info( sprintf($VM_LANG->_('VM_USERFIELD_DELETED'),$db->f('name')) ); 236 } 237 } 238 239 return true; 240 } 241 242 /** 243 * This allows us to print the user fields on 244 * the various sections of the shop 245 * 246 * @param array $rowFields An array returned from ps_database::loadObjectlist 247 * @param array $skipFields A one-dimensional array holding the names of fields that should NOT be displayed 248 * @param ps_DB $db A ps_DB object holding ovalues for the fields 249 * @param boolean $startform If true, print the starting <form...> tag 250 */ 251 function listUserFields( $rowFields, $skipFields=array(), $db = null, $startForm = true ) { 252 global $mm_action_url, $ps_html, $VM_LANG, $my, $default, $mainframe, $vm_mainframe, 253 $vendor_country_3_code, $mosConfig_live_site, $mosConfig_absolute_path, $page; 254 255 $dbf = new ps_DB(); 256 257 if( $db === null ) { 258 $db = new ps_DB(); 259 } 260 $default['country'] = $vendor_country_3_code; 261 262 $missing = vmGet( $_REQUEST, 'missing', '' ); 263 264 // collect all required fields 265 $required_fields = Array(); 266 foreach( $rowFields as $field ) { 267 if( $field->required == 1 ) { 268 $required_fields[$field->name] = $field->type; 269 } 270 $allfields[$field->name] = $field->name; 271 } 272 foreach( $skipFields as $skip ) { 273 unset($required_fields[$skip]); 274 } 275 276 // Form validation function 277 if( !vmIsAdminMode() ) { 278 ps_userfield::printJS_formvalidation( $required_fields, $rowFields ); 279 } else { 280 echo vmCommonHTML::scriptTag('', 'function submitregistration() { return true }'); 281 } 282 if( file_exists( $mosConfig_absolute_path .'/includes/js/mambojavascript.js') ) { 283 $vm_mainframe->addScript( 'includes/js/mambojavascript.js' ); 284 } 285 286 if( $startForm ) { 287 echo '<form action="'. $mm_action_url .basename($_SERVER['PHP_SELF']) .'" method="post" name="adminForm">'; 288 } 289 echo ' 290 <div style="width:90%;">'; 291 292 if( !empty( $required_fields )) { 293 echo '<div style="padding:5px;text-align:center;"><strong>(* = '.$VM_LANG->_('CMN_REQUIRED').')</strong></div>'; 294 295 } 296 $delimiter = 0; 297 298 foreach( $rowFields as $field) { 299 if( !isset( $default[$field->name] )) { 300 $default[$field->name] = $field->default; 301 } 302 $readonly = $field->readonly ? ' readonly="readonly"' : ''; 303 if( in_array( $field->name, $skipFields )) { 304 continue; 305 } 306 // Title handling. 307 $key = $field->title; 308 if( $key[0] == '_') { 309 $key = substr($key, 1, strlen($key)-1); 310 } 311 if( $VM_LANG->exists($key) ) { 312 $field->title = $VM_LANG->_($key); 313 } 314 if( $field->name == 'agreed') { 315 $field->title = '<script type="text/javascript">//<![CDATA[ 316 document.write(\'<label for="agreed_field">'. str_replace("'","\\'",$VM_LANG->_('PHPSHOP_I_AGREE_TO_TOS')) .'</label><a href="javascript:void window.open(\\\''. $mosConfig_live_site .'/index2.php?option=com_virtuemart&page=shop.tos&pop=1\\\', \\\'win2\\\', \\\'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no\\\');">\'); 317 document.write(\' ('.$VM_LANG->_('PHPSHOP_STORE_FORM_TOS') .')</a>\'); 318 //]]></script> 319 <noscript> 320 <label for="agreed_field">'. $VM_LANG->_('PHPSHOP_I_AGREE_TO_TOS') .'</label> 321 <a target="_blank" href="'. $mosConfig_live_site .'/index.php?option=com_virtuemart&page=shop.tos" title="'. $VM_LANG->_('PHPSHOP_I_AGREE_TO_TOS') .'"> 322 ('.$VM_LANG->_('PHPSHOP_STORE_FORM_TOS').') 323 </a></noscript>'; 324 } 325 if( $field->name == 'username' && VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION' ) { 326 echo '<div class="formLabel"> 327 <input type="checkbox" id="register_account" name="register_account" value="1" class="inputbox" onchange="showFields( this.checked, new Array(\'username\', \'password\', \'password2\') );if( this.checked ) { document.adminForm.remember.value=\'yes\'; } else { document.adminForm.remember.value=\'yes\'; }" checked="checked" /> 328 </div> 329 <div class="formField"> 330 <label for="register_account">'.$VM_LANG->_('VM_REGISTER_ACCOUNT').'</label> 331 </div> 332 '; 333 } elseif( $field->name == 'username' ) { 334 echo '<input type="hidden" id="register_account" name="register_account" value="1" />'; 335 } 336 // a delimiter marks the beginning of a new fieldset and 337 // the end of a previous fieldset 338 if( $field->type == 'delimiter') { 339 if( $delimiter > 0) { 340 echo "</fieldset>\n"; 341 } 342 if( VM_REGISTRATION_TYPE == 'SILENT_REGISTRATION' && $field->title == $VM_LANG->_('PHPSHOP_ORDER_PRINT_CUST_INFO_LBL') && $page == 'checkout.index' ) { 343 continue; 344 } 345 echo '<fieldset> 346 <legend class="sectiontableheader">'.$field->title.'</legend> 347 '; 348 $delimiter++; 349 continue; 350 } 351 352 echo '<div id="'.$field->name.'_div" class="formLabel '; 353 if (stristr($missing,$field->name)) { 354 echo 'missing'; 355 } 356 echo '">'; 357 echo '<label for="'.$field->name.'_field">'.$field->title.'</label>'; 358 if( isset( $required_fields[$field->name] )) { 359 echo '<strong>* </strong>'; 360 } 361 echo ' </div> 362 <div class="formField" id="'.$field->name.'_input">'."\n"; 363 364 /** 365 * This is the most important part of this file 366 * Here we print the field & its contents! 367 */ 368 369 switch( $field->name ) { 370 case 'title': 371 $ps_html->list_user_title($db->sf('title', true, false), "id=\"title_field\""); 372 break; 373 374 case 'country': 375 if( in_array('state', $allfields ) ) { 376 $onchange = "onchange=\"changeStateList();\""; 377 } 378 else { 379 $onchange = ""; 380 } 381 $ps_html->list_country("country", $db->sf('country', true, false), "id=\"country_field\" $onchange"); 382 break; 383 384 case 'state': 385 echo $ps_html->dynamic_state_lists( "country", "state", $db->sf('country', true, false), $db->sf('state', true, false) ); 386 echo "<noscript>\n"; 387 $ps_html->list_states("state", $db->sf('state', true, false), "", "id=\"state_field\""); 388 echo "</noscript>\n"; 389 break; 390 case 'agreed': 391 echo '<input type="checkbox" id="agreed_field" name="agreed" value="1" class="inputbox" />'; 392 break; 393 case 'password': 394 case 'password2': 395 echo '<input type="password" id="'.$field->name.'_field" name="'.$field->name.'" size="30" class="inputbox" />'."\n"; 396 break; 397 398 default: 399 400 switch( $field->type ) { 401 case 'date': 402 echo vmCommonHTML::scriptTag( $mosConfig_live_site .'/includes/js/calendar/calendar.js'); 403 if( vmIsJoomla( '1.5', '>=' ) ) { 404 // in Joomla 1.5, the name of calendar lang file is changed... 405 echo vmCommonHTML::scriptTag( $mosConfig_live_site .'/includes/js/calendar/lang/calendar-en-GB.js'); 406 } else { 407 echo vmCommonHTML::scriptTag( $mosConfig_live_site .'/includes/js/calendar/lang/calendar-en.js'); 408 } 409 echo vmCommonHTML::linkTag( $mosConfig_live_site .'/includes/js/calendar/calendar-mos.css'); 410 411 $maxlength = $field->maxlength ? 'maxlength="'.$field->maxlength.'"' : ''; 412 echo '<input type="text" id="'.$field->name.'_field" name="'.$field->name.'" size="'.$field->size.'" value="'. ($db->sf($field->name, true, false)?$db->sf($field->name, true, false):'') .'" class="inputbox" '.$maxlength . $readonly . ' />'."\n"; 413 echo '<input name="reset" type="reset" class="button" onclick="return showCalendar(\''.$field->name.'_field\', \'y-mm-dd\');" value="..." />'; 414 break; 415 case 'text': 416 case 'emailaddress': 417 case 'webaddress': 418 case 'euvatid': 419 $maxlength = $field->maxlength ? 'maxlength="'.$field->maxlength.'"' : ''; 420 echo '<input type="text" id="'.$field->name.'_field" name="'.$field->name.'" size="'.$field->size.'" value="'. ($db->sf($field->name, true, false)?$db->sf($field->name, true, false):'') .'" class="inputbox" '.$maxlength . $readonly . ' />'."\n"; 421 break; 422 423 case 'textarea': 424 echo '<textarea name="'.$field->name.'" id="'.$field->name.'_field" cols="'.$field->cols.'" rows="'.$field->rows.'" '.$readonly.'>'.$db->sf($field->name, true, false).'</textarea>'; 425 break; 426 427 case 'editorta': 428 editorArea( $field->name, $db->sf($field->name, true, false), $field->name, '300', '150', $field->cols, $field->rows ); 429 break; 430 431 case 'checkbox': 432 echo '<input type="checkbox" name="'.$field->name.'" id="'.$field->name.'_field" value="1" '. ($db->sf($field->name, true, false) ? 'checked="checked"' : '') . $readonly.'/>'; 433 break; 434 case 'age_verification': 435 $year = vmRequest::getInt('birthday_selector_year', date('Y')); 436 if( $db->f($field->name) ) { 437 $birthday = $db->f($field->name); 438 $date_array = explode('-', $birthday ); 439 $year = $date_array[0]; 440 $month = $date_array[1]; 441 $day = $date_array[2]; 442 } 443 ps_html::list_days('birthday_selector_day', vmRequest::getInt('birthday_selector_day', @$day)); 444 ps_html::list_month('birthday_selector_month', vmRequest::getInt('birthday_selector_month', @$month)); 445 ps_html::list_year('birthday_selector_year', $year, $year-100, $year); 446 break; 447 case 'captcha': 448 if (file_exists($mosConfig_absolute_path.'/administrator/components/com_securityimages/client.php')) { 449 include ($mosConfig_absolute_path.'/administrator/components/com_securityimages/client.php'); 450 // Note that this package name must be used on the validation side too! If both are not equal, validation will fail 451 $packageName = 'securityVMRegistrationCheck'; 452 echo insertSecurityImage($packageName); 453 echo getSecurityImageText($packageName); 454 } 455 else if (file_exists($mosConfig_absolute_path.'/plugins/system/securityimages.php')) { 456 echo "<script type=\"text/javascript\" src=\"".JURI :: root()."/components/com_securityimages/js/securityImages.js\"></script>"; 457 echo "<img id='captchaSecurityImages' name='captchaSecurityImages' src=\"".JURI :: root()."/index.php?option=com_securityimages&task=displayCaptcha\" />"; 458 echo "<a href=\"javascript:askNewSecurityImages('captchaSecurityImages');\">"; 459 echo "<img src=\"".JURI :: root()."/components/com_securityimages/buttons/reload.gif\" id=\"securityImagesContactCaptchaReload\" name=\"securityImagesContactCaptchaReload\" border=\"0\">"; 460 echo "</a>"; 461 echo "<input type=\"text\" name=\"securityVMRegistrationCheck_try\" />"; 462 } 463 464 break; 465 // Begin of a fallthrough 466 case 'multicheckbox': 467 case 'select': 468 case 'multiselect': 469 case 'radio': 470 $k = $db->f($field->name); 471 $dbf->setQuery( "SELECT fieldtitle,fieldvalue FROM #__{vm}_userfield_values" 472 . "\n WHERE fieldid = ".$field->fieldid 473 . "\n ORDER BY ordering" ); 474 $Values = $dbf->loadObjectList(); 475 $multi=""; 476 $rowFieldValues['lst_'.$field->name] = ''; 477 if($field->type=='multiselect') $multi="multiple='multiple'"; 478 if(count($Values) > 0) { 479 if($field->type=='radio') { 480 $rowFieldValues['lst_'.$field->name] = vmCommonHTML::radioListTable( $Values, $field->name, 481 'class="inputbox" size="1" ', 482 'fieldvalue', 'fieldtitle', $k, $field->cols, $field->rows, $field->size, $field->required); 483 } else { 484 $ks=explode("|*|",$k); 485 $k = array(); 486 foreach($ks as $kv) { 487 $k[]->fieldvalue=$kv; 488 } 489 if($field->type=='multicheckbox') { 490 $rowFieldValues['lst_'.$field->name] = vmCommonHTML::checkboxListTable( $Values, $field->name."[]", 491 'class="inputbox" size="'.$field->size.'" '.$multi . $readonly, 492 'fieldvalue', 'fieldtitle', $k, $field->cols, $field->rows, $field->size, $field->required); 493 } else { 494 $rowFieldValues['lst_'.$field->name] = vmCommonHTML::selectList( $Values, $field->name."[]", 495 'class="inputbox" size="'.$field->size.'" '.$multi, 496 'fieldvalue', 'fieldtitle', $k); 497 } 498 } 499 } 500 // no break! still a fallthrough 501 echo $rowFieldValues['lst_'.$field->name]; 502 break; 503 } 504 break; 505 } 506 if( $field->description != '') { 507 echo vmToolTip( $field->description ); 508 } 509 echo '<br /></div> 510 <br style="clear:both;" />'; 511 } 512 if( $delimiter > 0) { 513 echo "</fieldset>\n"; 514 } 515 echo '</div>'; 516 517 if( VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION') { 518 echo '<script type="text/javascript"> 519 //<![CDATA[ 520 function showFields( show, fields ) { 521 if( fields ) { 522 for (i=0; i<fields.length;i++) { 523 if( show ) { 524 document.getElementById( fields[i] + \'_div\' ).style.display = \'\'; 525 document.getElementById( fields[i] + \'_input\' ).style.display = \'\'; 526 } else { 527 document.getElementById( fields[i] + \'_div\' ).style.display = \'none\'; 528 document.getElementById( fields[i] + \'_input\' ).style.display = \'none\'; 529 } 530 } 531 } 532 } 533 try { 534 showFields( document.getElementById( \'register_account\').checked, new Array(\'username\', \'password\', \'password2\') ); 535 } catch(e){} 536 //]]> 537 </script>'; 538 } 539 } 540 541 function prepareFieldDataSave($fieldType,$fieldName,$value=null) { 542 global $_POST; 543 $sqlFormat = "Y-m-d"; 544 switch($fieldType) { 545 case 'date': 546 $value=vmGetUnEscaped($value); 547 break; 548 case 'webaddress': 549 if (isset($_POST[$fieldName."Text"]) && ($_POST[$fieldName."Text"])) { 550 $oValuesArr=array(); 551 $oValuesArr[0]=htmlspecialchars(str_replace(array('mailto:','http://','https://'),'', 552 vmGetUnEscaped($value))); 553 $oValuesArr[1]=htmlspecialchars(str_replace(array('mailto:','http://','https://'),'', 554 vmGetUnEscaped((isset($_POST[$fieldName."Text"]) ? $_POST[$fieldName."Text"] : "")))); 555 $value = implode("|*|",$oValuesArr); 556 } else { 557 $value= htmlspecialchars(str_replace(array('mailto:','http://','https://'),'',vmGetUnEscaped($value))); 558 } 559 break; 560 case 'emailaddress': 561 $value=htmlspecialchars(str_replace(array('mailto:','http://','https://'),'',vmGetUnEscaped($value))); 562 break; 563 case 'editorta': 564 $value=vmGetUnEscaped($value); 565 break; 566 case 'multiselect': 567 case 'multicheckbox': 568 case 'select': 569 if( is_array( $value )) { $value = implode("|*|",$value); } 570 $value = htmlspecialchars( vmGetUnEscaped( $value ) ); 571 break; 572 case 'delimiter': 573 break; 574 default: 575 $value=htmlspecialchars(vmGetUnEscaped($value)); 576 break; 577 } 578 return $value; 579 580 } 581 /** 582 * This function allows you to get an object list of user fields 583 * 584 * @param string $section The section the fields belong to (e.g. 'registration' or 'account') 585 * @param boolean $required_only 586 * @param mixed $sys When left empty, doesn't filter by sys 587 * @return array 588 */ 589 function getUserFields( $section = 'registration', $required_only=false, $sys = '', $exclude_delimiters=false, $exclude_skipfields=false ) { 590 $db = new ps_DB(); 591 592 $q = "SELECT f.* FROM `#__{vm}_userfield` f" 593 . "\n WHERE f.published=1"; 594 if( $section != 'bank' && $section != '') { 595 $q .= "\n AND f.`$section`=1"; 596 } 597 elseif( $section == 'bank' ) { 598 $q .= "\n AND f.name LIKE '%bank%'"; 599 } 600 if( $exclude_delimiters ) { 601 $q .= "\n AND f.type != 'delimiter' "; 602 } 603 if( $required_only ) { 604 $q .= "\n AND f.required=1"; 605 } 606 if( $sys !== '') { 607 if( $sys == '1') { $q .= "\n AND f.sys=1"; } 608 elseif( $sys == '0') { $q .= "\n AND f.sys=0"; } 609 } 610 if( $exclude_skipfields ) { 611 $q .= "\n AND FIND_IN_SET( f.name, '".implode(',', ps_userfield::getSkipFields())."') = 0 "; 612 } 613 $q .= "\n ORDER BY f.ordering"; 614 615 $db->setQuery( $q ); 616 $userFields = $db->loadObjectList(); 617 618 return $userFields; 619 } 620 /** 621 * Returns an array of fieldnames which are NOT used for VirtueMart tables 622 * 623 * @return array Field names which are to be skipped by VirtueMart db functions 624 */ 625 function getSkipFields() { 626 return array( 'username', 'password', 'password2', 'agreed' ); 627 } 628 /** 629 * Prints a JS function to validate all fields 630 * given in the array $required_fields 631 * Does only test if non-empty (or if no options are selected) 632 * Includes a check for a valid email-address 633 * 634 * @param array $required_fields The list of form elements that are to be validated 635 * @param string $formname The name for the form element 636 * @param string $div_id_postfix The ID postfix to identify the label for the field 637 */ 638 function printJS_formValidation( $required_fields, $allfields, $formname = 'adminForm', $functioname='submitregistration', $div_id_postfix = '_div' ) { 639 global $VM_LANG, $page, $mainframe, $vm_mainframe; 640 641 $field_list = implode( "','", array_keys( $required_fields ) ); 642 $field_list = str_replace( "'email',", '', $field_list ); 643 $field_list = str_replace( "'username',", '', $field_list ); 644 $field_list = str_replace( "'password',", '', $field_list ); 645 $field_list = str_replace( "'password2',", '', $field_list ); 646 647 echo ' 648 <script language="javascript" type="text/javascript">//<![CDATA[ 649 function '.$functioname.'() { 650 var form = document.'.$formname.'; 651 var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", "i"); 652 var isvalid = true; 653 var required_fields = new Array(\''. $field_list.'\'); 654 for (var i=0; i < required_fields.length; i++) { 655 formelement = eval( \'form.\' + required_fields[i] ); 656 '; 657 echo " 658 if( !formelement ) { 659 formelement = document.getElementById( required_fields[i]+'_field0' ); 660 var loopIds = true; 661 } 662 if( !formelement ) { continue; } 663 if (formelement.type == 'radio' || formelement.type == 'checkbox') { 664 if( loopIds ) { 665 var rOptions = new Array(); 666 for(var j=0; j<30; j++ ) { 667 rOptions[j] = document.getElementById( required_fields[i] + '_field' + j ); 668 if( !rOptions[j] ) { break; } 669 } 670 } else { 671 var rOptions = form[formelement.getAttribute('name')]; 672 } 673 var rChecked = 0; 674 if(rOptions.length > 1) { 675 for (var r=0; r < rOptions.length; r++) { 676 if( !rOptions[r] ) { continue; } 677 if (rOptions[r].checked) { rChecked=1; } 678 } 679 } else { 680 if (formelement.checked) { 681 rChecked=1; 682 } 683 } 684 if(rChecked==0) { 685 document.getElementById(required_fields[i]+'$div_id_postfix').className += ' missing'; 686 isvalid = false; 687 } 688 else if (document.getElementById(required_fields[i]+'$div_id_postfix').className == 'formLabel missing') { 689 document.getElementById(required_fields[i]+'$div_id_postfix').className = 'formLabel'; 690 } 691 } 692 else if( formelement.options ) { 693 if(formelement.selectedIndex.value == '') { 694 document.getElementById(required_fields[i]+'$div_id_postfix').className += ' missing'; 695 isvalid = false; 696 } 697 else if (document.getElementById(required_fields[i]+'$div_id_postfix').className == 'formLabel missing') { 698 document.getElementById(required_fields[i]+'$div_id_postfix').className = 'formLabel'; 699 } 700 } 701 else { 702 if (formelement.value == '') { 703 document.getElementById(required_fields[i]+'$div_id_postfix').className += ' missing'; 704 isvalid = false; 705 } 706 else if (document.getElementById(required_fields[i]+'$div_id_postfix').className == 'formLabel missing') { 707 document.getElementById(required_fields[i]+'$div_id_postfix').className = 'formLabel'; 708 } 709 } 710 } 711 "; 712 $optional_check = ''; 713 if( VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION') { 714 $optional_check = '&& form.register_account.checked'; 715 } 716 // We have skipped email in the first loop above! 717 // Now let's handle email address validation 718 if( isset( $required_fields['email'] )) { 719 720 echo ' 721 if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value))) { 722 alert( \''. str_replace("'","\\'",$VM_LANG->_('REGWARN_MAIL',false)) .'\'); 723 return false; 724 }'; 725 726 } 727 if( isset( $required_fields['username'] )) { 728 729 echo ' 730 if ((r.exec(form.username.value) || form.username.value.length < 3)'.$optional_check.') { 731 alert( "'. sprintf($VM_LANG->_('VALID_AZ09',false), $VM_LANG->_('USERNAME',false), 2) .'" ); 732 return false; 733 }'; 734 } 735 if( isset($required_fields['password']) ) { 736 if( $page == 'checkout.index' || $page == 'shop.registration') { 737 echo ' 738 passregex=/^\S[\S ]{2,98}\S$/; 739 if (form.password.value.length < 6 '.$optional_check.') { 740 alert( "'.$VM_LANG->_('REGWARN_PASS',false) .'" ); 741 return false; 742 } else if (form.password2.value == ""'.$optional_check.') { 743 alert( "'. $VM_LANG->_('REGWARN_VPASS1',false) .'" ); 744 return false; 745 } else if (!passregex.test(form.password.value)'.$optional_check.') { 746 alert( "'. sprintf( $VM_LANG->_('VALID_AZ09',false), $VM_LANG->_('PASSWORD',false), 6 ) .'" ); 747 return false; 748 }'; 749 } 750 echo ' 751 if ((form.password.value != "") && (form.password.value != form.password2.value)'.$optional_check.'){ 752 alert( "'. $VM_LANG->_('REGWARN_VPASS2',false) .'" ); 753 return false; 754 }'; 755 } 756 if( isset( $required_fields['agreed'] )) { 757 echo ' 758 if (!form.agreed.checked) { 759 alert( "'. $VM_LANG->_('PHPSHOP_AGREE_TO_TOS',false) .'" ); 760 return false; 761 }'; 762 } 763 foreach( $allfields as $field ) { 764 if( $field->type == 'euvatid' ) { 765 $euvatid = $field->name; 766 break; 767 } 768 } 769 if( !empty($euvatid) ) { 770 $vm_mainframe->addScript( 'components/'.VM_COMPONENT_NAME.'/js/euvat_check.js'); 771 echo ' 772 if( form.'.$euvatid.'.value != \'\' ) { 773 if( !isValidVATID( form.'.$euvatid.'.value )) { 774 alert( \''.addslashes($VM_LANG->_('VALID_EUVATID',false)).'\' ); 775 return false; 776 } 777 }'; 778 } 779 // Finish the validation function 780 echo ' 781 if( !isvalid) { 782 alert("'.addslashes( $VM_LANG->_('CONTACT_FORM_NC',false) ) .'" ); 783 } 784 return isvalid; 785 } 786 //]]> 787 </script>'; 788 } 789 } 790 791 792 // Check if there is an extended class in the Themes and if it is allowed to use them 793 // If the class is called outside Virtuemart, we have to make sure to load the settings 794 // Thomas Kahl - Feb. 2009 795 if (!defined('VM_ALLOW_EXTENDED_CLASSES') && file_exists(dirname(__FILE__).'/../virtuemart.cfg.php')) { 796 include_once(dirname(__FILE__).'/../virtuemart.cfg.php'); 797 } 798 // If settings are loaded, extended Classes are allowed and the class exisits... 799 if (defined('VM_ALLOW_EXTENDED_CLASSES') && defined('VM_THEMEPATH') && VM_ALLOW_EXTENDED_CLASSES && file_exists(VM_THEMEPATH.'user_class/'.basename(__FILE__))) { 800 // Load the theme-user_class as extended 801 include_once(VM_THEMEPATH.'user_class/'.basename(__FILE__)); 802 } else { 803 // Otherwise we have to use the original classname to extend the core-class 804 class ps_userfield extends vm_ps_userfield {} 805 } 806 ?>
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 |