Example #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());
     $admin = false;
     if (!class_exists('Permissions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php';
     }
     if (Permissions::getInstance()->check('admin', 'storeadmin')) {
         $admin = true;
     }
     // 		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 : @html_entity_decode($_userData[$_fld->name], ENT_COMPAT, 'UTF-8'), 'title' => JText::_($_fld->title), 'type' => $_fld->type, 'required' => $_fld->required, 'hidden' => false, 'formcode' => '', 'description' => JText::_($_fld->description));
             $readonly = '';
             if (!$admin) {
                 if ($_fld->readonly) {
                     $readonly = ' readonly="readonly" ';
                 }
             }
             // 				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':
                     //For nice lists in the FE
                     /*	$app = JFactory::getApplication();
                     			if($app->isSite()) {
                     				$attrib = array('class'=>'chzn-select');
                     			} else {
                     				$attrib = array();
                     			}*/
                     $attrib = array();
                     $_return['fields'][$_fld->name]['formcode'] = ShopFunctions::renderCountryList($_return['fields'][$_fld->name]['value'], false, $attrib, $_prefix, $_fld->required);
                     if (!empty($_return['fields'][$_fld->name]['value'])) {
                         // Translate the value from ID to name
                         $db = JFactory::getDBO();
                         $q = 'SELECT * FROM `#__virtuemart_countries` WHERE virtuemart_country_id = "' . (int) $_return['fields'][$_fld->name]['value'] . '"';
                         $db->setQuery($q);
                         $r = $db->loadAssoc();
                         if ($r) {
                             $_return['fields'][$_fld->name]['value'] = !empty($r['country_name']) ? $r['country_name'] : '';
                             $_return['fields'][$_fld->name]['country_2_code'] = !empty($r['country_2_code']) ? $r['country_2_code'] : '';
                             $_return['fields'][$_fld->name]['country_3_code'] = !empty($r['country_3_code']) ? $r['country_3_code'] : '';
                         } else {
                             vmError('Model Userfields, country with id ' . $_return['fields'][$_fld->name]['value'] . ' not found');
                         }
                     } else {
                         $_return['fields'][$_fld->name]['value'] = '';
                         $_return['fields'][$_fld->name]['country_2_code'] = '';
                         $_return['fields'][$_fld->name]['country_3_code'] = '';
                     }
                     //$_return['fields'][$_fld->name]['value'] = JText::_(shopFunctions::getCountryByID($_return['fields'][$_fld->name]['value']));
                     //$_return['fields'][$_fld->name]['state_2_code'] = JText::_(shopFunctions::getCountryByID($_return['fields'][$_fld->name]['value']));
                     break;
                 case 'virtuemart_state_id':
                     if (!class_exists('shopFunctionsF')) {
                         require JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php';
                     }
                     $_return['fields'][$_fld->name]['formcode'] = shopFunctions::renderStateList($_return['fields'][$_fld->name]['value'], $_prefix, false, $_fld->required);
                     if (!empty($_return['fields'][$_fld->name]['value'])) {
                         // Translate the value from ID to name
                         $db = JFactory::getDBO();
                         $q = 'SELECT * FROM `#__virtuemart_states` WHERE virtuemart_state_id = "' . (int) $_return['fields'][$_fld->name]['value'] . '"';
                         $db->setQuery($q);
                         $r = $db->loadAssoc();
                         if ($r) {
                             $_return['fields'][$_fld->name]['value'] = !empty($r['state_name']) ? $r['state_name'] : '';
                             $_return['fields'][$_fld->name]['state_2_code'] = !empty($r['state_2_code']) ? $r['state_2_code'] : '';
                             $_return['fields'][$_fld->name]['state_3_code'] = !empty($r['state_3_code']) ? $r['state_3_code'] : '';
                         } else {
                             vmError('Model Userfields, state with id ' . $_return['fields'][$_fld->name]['value'] . ' not found');
                         }
                     } else {
                         $_return['fields'][$_fld->name]['value'] = '';
                         $_return['fields'][$_fld->name]['state_2_code'] = '';
                         $_return['fields'][$_fld->name]['state_3_code'] = '';
                     }
                     //$_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, isset($_userData['virtuemart_user_id']) ? $_userData['virtuemart_user_id'] : 0, &$_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 . '"' : '') . $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 ;
                             //if(empty($_return['fields'][$_fld->name]['value'])){
                             //	$_return['fields'][$_fld->name]['value'] = "1912-01-01 00:00:00";
                             //}                                                     jDate($date='',$name="date",$id=null,$resetBt = true, $yearRange='') {
                             // Year range MUST start 100 years ago, for birthday
                             $_return['fields'][$_fld->name]['formcode'] = vmJsApi::jDate($_return['fields'][$_fld->name]['value'], $_prefix . $_fld->name, $_prefix . $_fld->name . '_field', false, $currentYear - 100 . ':' . $currentYear);
                             break;
                         case 'emailaddress':
                             if (JFactory::getApplication()->isSite()) {
                                 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 . '"' : '') . $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" ' . $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'], '150', '100', $_fld->cols, $_fld->rows, array('pagebreak', 'readmore'));
                             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"' : '') . '/>';
                             if ($_return['fields'][$_fld->name]['value']) {
                                 $_return['fields'][$_fld->name]['value'] = JText::_($_prefix . $_fld->title);
                             }
                             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 'multiselect':
                         case 'select':
                         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 and !$admin) {
                                 $_attribs['readonly'] = 'readonly';
                             }
                             if ($_fld->required) {
                                 $_attribs['class'] = 'required';
                             }
                             if ($_fld->type == 'radio' or $_fld->type == 'select') {
                                 $_selected = $_return['fields'][$_fld->name]['value'];
                             } else {
                                 $_attribs['size'] = $_fld->size;
                                 // Use for all but radioselects
                                 if (!is_array($_return['fields'][$_fld->name]['value'])) {
                                     $_selected = explode("|*|", $_return['fields'][$_fld->name]['value']);
                                 } else {
                                     $_selected = $_return['fields'][$_fld->name]['value'];
                                 }
                             }
                             // Nested switch...
                             switch ($_fld->type) {
                                 case 'multicheckbox':
                                     // todo: use those
                                     $_attribs['rows'] = $_fld->rows;
                                     $_attribs['cols'] = $_fld->cols;
                                     $formcode = '';
                                     $field_values = "";
                                     $_idx = 0;
                                     $separator_form = '<br />';
                                     $separator_title = ',';
                                     foreach ($_values as $_val) {
                                         if (in_array($_val->fieldvalue, $_selected)) {
                                             $is_selected = 'checked="checked"';
                                             $field_values .= JText::_($_val->fieldtitle) . $separator_title;
                                         } else {
                                             $is_selected = '';
                                         }
                                         $formcode .= '<input type="checkbox" name="' . $_prefix . $_fld->name . '[]" id="' . $_prefix . $_fld->name . '_field' . $_idx . '" value="' . $_val->fieldvalue . '" ' . $is_selected . '/> <label for="' . $_prefix . $_fld->name . '_field' . $_idx . '">' . JText::_($_val->fieldtitle) . '</label>' . $separator_form;
                                         $_idx++;
                                     }
                                     // remove last br
                                     $_return['fields'][$_fld->name]['formcode'] = substr($formcode, 0, -strlen($separator_form));
                                     $_return['fields'][$_fld->name]['value'] = substr($field_values, 0, -strlen($separator_title));
                                     break;
                                 case 'multiselect':
                                     $_attribs['multiple'] = 'multiple';
                                     $_attribs['class'] = 'vm-chzn-select';
                                     $field_values = "";
                                     $_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.genericlist', $_values, $_prefix . $_fld->name . '[]', $_attribs, 'fieldvalue', 'fieldtitle', $_selected);
                                     $separator_form = '<br />';
                                     $separator_title = ',';
                                     foreach ($_values as $_val) {
                                         if (in_array($_val->fieldvalue, $_selected)) {
                                             $field_values .= JText::_($_val->fieldtitle) . $separator_title;
                                         }
                                     }
                                     $_return['fields'][$_fld->name]['value'] = substr($field_values, 0, -strlen($separator_title));
                                     break;
                                 case 'select':
                                     $_attribs['class'] = 'vm-chzn-select';
                                     $_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.genericlist', $_values, $_prefix . $_fld->name, $_attribs, 'fieldvalue', 'fieldtitle', $_selected);
                                     foreach ($_values as $_val) {
                                         if ($_val->fieldvalue == $_selected) {
                                             $_return['fields'][$_fld->name]['value'] = JText::_($_val->fieldtitle);
                                         }
                                     }
                                     break;
                                 case 'radio':
                                     $_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.radiolist', $_values, $_prefix . $_fld->name, $_attribs, 'fieldvalue', 'fieldtitle', $_selected);
                                     foreach ($_values as $_val) {
                                         if ($_val->fieldvalue == $_selected) {
                                             $_return['fields'][$_fld->name]['value'] = JText::_($_val->fieldtitle);
                                         }
                                     }
                                     break;
                             }
                             break;
                     }
                     break;
             }
         }
     } else {
         vmdebug('getUserFieldsFilled $_selection is not an array ', $_selection);
         // 			$_return['fields'][$_fld->name]['formcode'] = '';
     }
     return $_return;
 }
Example #2
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;
 }
Example #3
0
 function display($tpl = null)
 {
     if (!class_exists('VmHTML')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'html.php';
     }
     $model = VmModel::getModel('calc');
     if (!class_exists('Permissions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php';
     }
     $perms = Permissions::getInstance();
     $this->assignRef('perms', $perms);
     //@todo should be depended by loggedVendor
     $vendorId = 1;
     $this->assignRef('vendorId', $vendorId);
     $db = JFactory::getDBO();
     $this->SetViewTitle();
     $layoutName = JRequest::getWord('layout', 'default');
     if ($layoutName == 'edit') {
         $calc = $model->getCalc();
         $this->assignRef('calc', $calc);
         $isNew = $calc->virtuemart_calc_id < 1;
         if ($isNew) {
             $db = JFactory::getDBO();
             //get default currency of the vendor, if not set get default of the shop
             $q = 'SELECT `vendor_currency` FROM `#__virtuemart_vendors` WHERE `virtuemart_vendor_id` = "' . $vendorId . '"';
             $db->setQuery($q);
             $currency = $db->loadResult();
             if (empty($currency)) {
                 $q = 'SELECT `vendor_currency` FROM `#__virtuemart_vendors` WHERE `virtuemart_vendor_id` = "1" ';
                 $db->setQuery($q);
                 $currency = $db->loadResult();
                 $calc->calc_currency = $currency;
             } else {
                 $calc->calc_currency = $currency;
             }
         }
         $entryPointsList = self::renderEntryPointsList($calc->calc_kind);
         $this->assignRef('entryPointsList', $entryPointsList);
         $mathOpList = self::renderMathOpList($calc->calc_value_mathop);
         $this->assignRef('mathOpList', $mathOpList);
         /* Get the category tree */
         $categoryTree = null;
         if (isset($calc->calc_categories)) {
             $calc_categories = $calc->calc_categories;
             $categoryTree = ShopFunctions::categoryListTree($calc_categories);
         } else {
             $categoryTree = ShopFunctions::categoryListTree();
         }
         $this->assignRef('categoryTree', $categoryTree);
         $currencyModel = VmModel::getModel('currency');
         $_currencies = $currencyModel->getCurrencies();
         $this->assignRef('currencies', $_currencies);
         /* Get the shoppergroup tree */
         $shopperGroupList = ShopFunctions::renderShopperGroupList($calc->virtuemart_shoppergroup_ids, True);
         $this->assignRef('shopperGroupList', $shopperGroupList);
         $countriesList = ShopFunctions::renderCountryList($calc->calc_countries, True);
         $this->assignRef('countriesList', $countriesList);
         $statesList = ShopFunctions::renderStateList($calc->virtuemart_state_ids, '', True);
         $this->assignRef('statesList', $statesList);
         $manufacturerList = ShopFunctions::renderManufacturerList($calc->virtuemart_manufacturers, true);
         $this->assignRef('manufacturerList', $manufacturerList);
         if (Vmconfig::get('multix', 'none') !== 'none') {
             $vendorList = ShopFunctions::renderVendorList($calc->virtuemart_vendor_id, false);
             $this->assignRef('vendorList', $vendorList);
         }
         $this->addStandardEditViewCommands();
     } else {
         JToolBarHelper::custom('toggle.calc_shopper_published.0', 'unpublish', 'no', JText::_('COM_VIRTUEMART_CALC_SHOPPER_PUBLISH_TOGGLE_OFF'), true);
         JToolBarHelper::custom('toggle.calc_shopper_published.1', 'publish', 'yes', JText::_('COM_VIRTUEMART_CALC_SHOPPER_PUBLISH_TOGGLE_ON'), true);
         JToolBarHelper::custom('toggle.calc_vendor_published.0', 'unpublish', 'no', JText::_('COM_VIRTUEMART_CALC_VENDOR_PUBLISH_TOGGLE_OFF'), true);
         JToolBarHelper::custom('toggle.calc_vendor_published.1', 'publish', 'yes', JText::_('COM_VIRTUEMART_CALC_VENDOR_PUBLISH_TOGGLE_ON'), true);
         $this->addStandardDefaultViewCommands();
         $this->addStandardDefaultViewLists($model);
         $search = JRequest::getWord('search', false);
         $calcs = $model->getCalcs(false, false, $search);
         $this->assignRef('calcs', $calcs);
         $pagination = $model->getPagination();
         $this->assignRef('pagination', $pagination);
     }
     parent::display($tpl);
 }