Пример #1
0
 /**
  * Return an array with userFields in several formats.
  *
  * @access public
  * @param $_selection An array, as returned by getuserFields(), with fields that should be returned.
  * @param $_userData Array with userdata holding the values for the fields
  * @param $_prefix string Optional prefix for the formtag name attribute
  * @author Oscar van Eijk
  * @return array List with all userfield data in the format:
  * array(
  *    'fields' => array(   // All fields
  *                   <fieldname> => array(
  *                                     'name' =>       // Name of the field
  *                                     'value' =>      // Existing value for the current user, or the default
  *                                     'title' =>      // Title used for label and such
  *                                     'type' =>       // Field type as specified in the userfields table
  *                                     'hidden' =>     // True/False
  *                                     'required' =>   // True/False. If True, the formcode also has the class "required" for the Joomla formvalidator
  *                                     'formcode' =>   // Full HTML tag
  *                                  )
  *                   [...]
  *                )
  *    'functions' => array() // Optional javascript functions without <script> tags.
  *                           // Possible usage: if (count($ar('functions')>0) echo '<script ...>'.join("\n", $ar('functions')).'</script>;
  *    'scripts'   => array(  // Array with scriptsources for use with JHTML::script();
  *                      <name> => <path>
  *                      [...]
  *                   )
  *    'links'     => array(  // Array with stylesheets for use with JHTML::stylesheet();
  *                      <name> => <path>
  *                      [...]
  *                   )
  * )
  * @example This example illustrates the use of this function. For additional examples, see the Order view
  * and the User view in the administrator section.
  * <pre>
  *   // In the controller, make sure this model is loaded.
  *   // In view.html.php, make the following calls:
  *   $_usrDetails = getUserDetailsFromSomeModel(); // retrieve an user_info record, eg from the usermodel or ordermodel
  *   $_usrFieldList = $userFieldsModel->getUserFields(
  *                    'registration'
  *                  , array() // Default switches
  *                  , array('delimiter_userinfo', 'username', 'email', 'password', 'password2', 'agreed', 'address_type') // Skips
  *    );
  *   $usrFieldValues = $userFieldsModel->getUserFieldsFilled(
  *                      $_usrFieldList
  *                     ,$_usrDetails
  *   );
  *   $this->assignRef('userfields', $userfields);
  *   // In the template, use code below to display the data. For an extended example using
  *   // delimiters, JavaScripts and StyleSheets, see the edit_shopper.php in the user view
  *   <table class="admintable" width="100%">
  *     <thead>
  *       <tr>
  *         <td class="key" style="text-align: center;"  colspan="2">
  *            <?php echo JText::_('COM_VIRTUEMART_TABLE_HEADER') ?>
  *         </td>
  *       </tr>
  *     </thead>
  *      <?php
  *        foreach ($this->shipmentfields['fields'] as $_field ) {
  *          echo '  <tr>'."\n";
  *          echo '    <td class="key">'."\n";
  *          echo '      '.$_field['title']."\n";
  *          echo '    </td>'."\n";
  *          echo '    <td>'."\n";
  *
  *          echo '      '.$_field['value']."\n";    // Display only
  *       Or:
  *          echo '      '.$_field['formcode']."\n"; // Input form
  *
  *          echo '    </td>'."\n";
  *          echo '  </tr>'."\n";
  *        }
  *      ?>
  *    </table>
  * </pre>
  */
 public function getUserFieldsFilled($_selection, $_userData = null, $_prefix = '')
 {
     if (!class_exists('ShopFunctions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php';
     }
     $_return = array('fields' => array(), 'functions' => array(), 'scripts' => array(), 'links' => array());
     // 		vmdebug('my user data in getUserFieldsFilled',$_selection,$_userData);
     $_userData = (array) $_userData;
     if (is_array($_selection)) {
         foreach ($_selection as $_fld) {
             $_return['fields'][$_fld->name] = array('name' => $_prefix . $_fld->name, 'value' => $_userData == null || !array_key_exists($_fld->name, $_userData) ? $_fld->default : @$_userData[$_fld->name], 'title' => JText::_($_fld->title), 'type' => $_fld->type, 'required' => $_fld->required, 'hidden' => false, 'formcode' => '');
             // 				vmdebug ('getUserFieldsFilled',$_fld->name);
             // 			if($_fld->name==='email') vmdebug('user data email getuserfieldbyuser',$_userData);
             // First, see if there are predefined fields by checking the name
             switch ($_fld->name) {
                 // 				case 'email':
                 // 					$_return['fields'][$_fld->name]['formcode'] = $_userData->email;
                 // 					break;
                 case 'virtuemart_country_id':
                     $_return['fields'][$_fld->name]['formcode'] = ShopFunctions::renderCountryList($_return['fields'][$_fld->name]['value'], false, array(), $_prefix, $_fld->required);
                     // Translate the value from ID to name
                     $_return['fields'][$_fld->name]['value'] = shopFunctions::getCountryByID($_return['fields'][$_fld->name]['value']);
                     break;
                 case 'virtuemart_state_id':
                     $_return['fields'][$_fld->name]['formcode'] = shopFunctions::renderStateList($_return['fields'][$_fld->name]['value'], $_prefix, false, $_fld->required);
                     $_return['fields'][$_fld->name]['value'] = shopFunctions::getStateByID($_return['fields'][$_fld->name]['value']);
                     break;
                     //case 'agreed':
                     //	$_return['fields'][$_fld->name]['formcode'] = '<input type="checkbox" id="'.$_prefix.'agreed_field" name="'.$_prefix.'agreed" value="1" '
                     //		. ($_fld->required ? ' class="required"' : '') . ' />';
                     //	break;
                 //case 'agreed':
                 //	$_return['fields'][$_fld->name]['formcode'] = '<input type="checkbox" id="'.$_prefix.'agreed_field" name="'.$_prefix.'agreed" value="1" '
                 //		. ($_fld->required ? ' class="required"' : '') . ' />';
                 //	break;
                 case 'password':
                 case 'password2':
                     $_return['fields'][$_fld->name]['formcode'] = '<input type="password" id="' . $_prefix . $_fld->name . '_field" name="' . $_prefix . $_fld->name . '" size="30" class="inputbox" />' . "\n";
                     break;
                 case 'agreed':
                     $_return['fields'][$_fld->name]['formcode'] = '<input type="checkbox" name="' . $_prefix . $_fld->name . '" id="' . $_prefix . $_fld->name . '_field" value="1" ' . ($_return['fields'][$_fld->name]['value'] ? 'checked="checked"' : '') . '/>';
                     break;
                     // It's not a predefined field, so handle it by it's fieldtype
                 // It's not a predefined field, so handle it by it's fieldtype
                 default:
                     if (strpos($_fld->type, 'plugin') !== false) {
                         JPluginHelper::importPlugin('vmuserfield');
                         $dispatcher = JDispatcher::getInstance();
                         $dispatcher->trigger('plgVmOnUserfieldDisplay', array($_prefix, $_fld, &$_return));
                         break;
                     }
                     switch ($_fld->type) {
                         case 'hidden':
                             $_return['fields'][$_fld->name]['formcode'] = '<input type="hidden" id="' . $_prefix . $_fld->name . '_field" name="' . $_prefix . $_fld->name . '" size="' . $_fld->size . '" value="' . $_return['fields'][$_fld->name]['value'] . '" ' . ($_fld->required ? ' class="required"' : '') . ($_fld->maxlength ? ' maxlength="' . $_fld->maxlength . '"' : '') . ($_fld->readonly ? ' readonly="readonly"' : '') . ' /> ';
                             $_return['fields'][$_fld->name]['hidden'] = true;
                             break;
                         case 'date':
                         case 'age_verification':
                             //echo JHTML::_('behavior.calendar');
                             /*
                              * TODO We must add the joomla.javascript here that contains the calendar,
                              * since Joomla does not load it when there's no user logged in.
                              * Gotta find out why... some security issue or a bug???
                              * Note by Oscar
                              */
                             // if ($_userData === null) { // Not logged in
                             // $_doc = JFactory::getDocument();
                             // $_doc->addScript( JURI::root(true).'/includes/js/joomla.javascript.js');
                             // }
                             $currentYear = date('Y');
                             $calendar = vmJsApi::jDate($_return['fields'][$_fld->name]['value'], $_prefix . $_fld->name, $_prefix . $_fld->name . '_field', false, $currentYear - 100 . ':' . $currentYear);
                             $_return['fields'][$_fld->name]['formcode'] = $calendar;
                             break;
                         case 'emailaddress':
                             if (empty($_return['fields'][$_fld->name]['value'])) {
                                 $_return['fields'][$_fld->name]['value'] = JFactory::getUser()->email;
                             }
                             // 							vmdebug('emailaddress',$_fld);
                         // 							vmdebug('emailaddress',$_fld);
                         case 'text':
                         case 'webaddress':
                             $_return['fields'][$_fld->name]['formcode'] = '<input type="text" id="' . $_prefix . $_fld->name . '_field" name="' . $_prefix . $_fld->name . '" size="' . $_fld->size . '" value="' . $_return['fields'][$_fld->name]['value'] . '" ' . ($_fld->required ? ' class="required"' : '') . ($_fld->maxlength ? ' maxlength="' . $_fld->maxlength . '"' : '') . ($_fld->readonly ? ' readonly="readonly"' : '') . ' /> ';
                             break;
                         case 'textarea':
                             $_return['fields'][$_fld->name]['formcode'] = '<textarea id="' . $_prefix . $_fld->name . '_field" name="' . $_prefix . $_fld->name . '" cols="' . $_fld->cols . '" rows="' . $_fld->rows . '" class="inputbox" ' . ($_fld->readonly ? ' readonly="readonly"' : '') . '>' . $_return['fields'][$_fld->name]['value'] . '</textarea>';
                             break;
                         case 'editorta':
                             jimport('joomla.html.editor');
                             $editor = JFactory::getEditor();
                             $_return['fields'][$_fld->name]['formcode'] = $editor->display($_prefix . $_fld->name, $_return['fields'][$_fld->name]['value'], 300, 150, $_fld->cols, $_fld->rows);
                             break;
                         case 'checkbox':
                             $_return['fields'][$_fld->name]['formcode'] = '<input type="checkbox" name="' . $_prefix . $_fld->name . '" id="' . $_prefix . $_fld->name . '_field" value="1" ' . ($_return['fields'][$_fld->name]['value'] ? 'checked="checked"' : '') . '/>';
                             break;
                             // /*##mygruz20120223193710 { :*/
                             // case 'userfieldplugin': //why not just vmuserfieldsplugin ?
                             // JPluginHelper::importPlugin('vmuserfield');
                             // $dispatcher = JDispatcher::getInstance();
                             // //Todo to adjust to new pattern, using &
                             // $html = '' ;
                             // $dispatcher->trigger('plgVmOnUserFieldDisplay',array($_return['fields'][$_fld->name], &$html) );
                             // $_return['fields'][$_fld->name]['formcode'] = $html;
                             // break;
                             // /*##mygruz20120223193710 } */
                         // /*##mygruz20120223193710 { :*/
                         // case 'userfieldplugin': //why not just vmuserfieldsplugin ?
                         // JPluginHelper::importPlugin('vmuserfield');
                         // $dispatcher = JDispatcher::getInstance();
                         // //Todo to adjust to new pattern, using &
                         // $html = '' ;
                         // $dispatcher->trigger('plgVmOnUserFieldDisplay',array($_return['fields'][$_fld->name], &$html) );
                         // $_return['fields'][$_fld->name]['formcode'] = $html;
                         // break;
                         // /*##mygruz20120223193710 } */
                         case 'multicheckbox':
                         case 'select':
                         case 'multiselect':
                         case 'radio':
                             $_qry = 'SELECT fieldtitle, fieldvalue ' . 'FROM #__virtuemart_userfield_values ' . 'WHERE virtuemart_userfield_id = ' . $_fld->virtuemart_userfield_id . ' ORDER BY ordering ';
                             $_values = $this->_getList($_qry);
                             // We need an extra lok here, especially for the Bank info; the values
                             // must be translated.
                             // Don't check on the field name though, since others might be added in the future :-(
                             foreach ($_values as $_v) {
                                 $_v->fieldtitle = JText::_($_v->fieldtitle);
                             }
                             $_attribs = array();
                             if ($_fld->readonly) {
                                 $_attribs['readonly'] = 'readonly';
                             }
                             if ($_fld->required) {
                                 $_attribs['class'] = 'required';
                             }
                             if ($_fld->type == 'radio') {
                                 $_selected = $_return['fields'][$_fld->name]['value'];
                             } else {
                                 $_attribs['size'] = $_fld->size;
                                 // Use for all but radioselects
                                 $_selected = explode("|*|", $_return['fields'][$_fld->name]['value']);
                             }
                             // Nested switch...
                             switch ($_fld->type) {
                                 case 'multicheckbox':
                                     $_return['fields'][$_fld->name]['formcode'] = '';
                                     $_idx = 0;
                                     $rows = $_fld->rows;
                                     $row = 1;
                                     foreach ($_values as $_val) {
                                         if ($row > $rows) {
                                             $row = 1;
                                             $br = '<br />';
                                         } else {
                                             $row++;
                                             $br = '';
                                         }
                                         $_return['fields'][$_fld->name]['formcode'] .= '<input type="checkbox" name="' . $_prefix . $_fld->name . '[]" id="' . $_prefix . $_fld->name . '_field' . $_idx . '" value="' . $_val->fieldvalue . '" ' . (in_array($_val->fieldvalue, $_selected) ? 'checked="checked"' : '') . '/> ' . JText::_($_val->fieldtitle) . $br;
                                         $_idx++;
                                     }
                                     break;
                                 case 'select':
                                     $_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.genericlist', $_values, $_prefix . $_fld->name, $_attribs, 'fieldvalue', 'fieldtitle', $_selected[0]);
                                     break;
                                 case 'multiselect':
                                     $_attribs['multiple'] = 'multiple';
                                     $_attribs['rows'] = $_fld->rows;
                                     $_attribs['cols'] = $_fld->cols;
                                     $_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.genericlist', $_values, $_prefix . $_fld->name . '[]', $_attribs, 'fieldvalue', 'fieldtitle', $_selected);
                                     break;
                                 case 'radio':
                                     $_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.radiolist', $_values, $_prefix . $_fld->name, $_attribs, $_selected, 'fieldvalue', 'fieldtitle');
                                     break;
                             }
                             break;
                     }
                     break;
             }
         }
     } else {
         vmdebug('getUserFieldsFilled $_selection is not an array ', $_selection);
         // 			$_return['fields'][$_fld->name]['formcode'] = '';
     }
     return $_return;
 }
Пример #2
0
 function setCountryAndState($address)
 {
     // get rid of the references
     $address = $this->copyObj($address);
     if (!class_exists('ShopFunctions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php';
     }
     if (isset($address) && !is_object($address) || !is_object($address) && empty($address->virtuemart_country_id)) {
         if (!empty($address['virtuemart_country_id']) && !empty($address['virtuemart_country_id']['value']) && is_numeric($address['virtuemart_country_id']['value'])) {
             $address['virtuemart_country_id']['value_txt'] = shopFunctions::getCountryByID($address['virtuemart_country_id']['value']);
             //shopFunctions::getCountryByID($address['virtuemart_country_id']['value']);
         } else {
             $address['virtuemart_country_id']['value'] = '';
         }
         if (!empty($address['virtuemart_state_id']) && !empty($address['virtuemart_state_id']['value']) && is_numeric($address['virtuemart_state_id']['value'])) {
             $address['virtuemart_state_id']['value_txt'] = shopFunctions::getStateByID($address['virtuemart_state_id']['value']);
         } else {
             $address['virtuemart_state_id']['value'] = '';
         }
     } else {
         if (!empty($address->virtuemart_country_id) && is_numeric($address->virtuemart_country_id)) {
             $address->virtuemart_country_id = shopFunctions::getCountryByID($address->virtuemart_country_id);
         } else {
             $address->virtuemart_country_id = '';
         }
         if (!empty($address->virtuemart_state_id) && is_numeric($address->virtuemart_state_id)) {
             $address->virtuemart_state_id = shopFunctions::getStateByID($address->virtuemart_state_id);
         } else {
             $address->virtuemart_state_id = '';
         }
     }
     return $address;
 }