$fieldName = $name == 'ungrouped' ? '' : $name;
        ?>

		<legend class="joms-form__legend"><?php 
        echo JText::_($fieldName);
        ?>
</legend>


<?php 
        foreach ($fieldGroup as $field) {
            $field = JArrayHelper::toObject($field);
            if (!$required && $field->required == 1) {
                $required = true;
            }
            $html = CProfileLibrary::getFieldHTML($field);
            ?>
            <div class="joms-form__group" >
                <span id="lblfield<?php 
            echo $field->id;
            ?>
" for="field<?php 
            echo $field->id;
            ?>
"   ><?php 
            echo JText::_($field->name);
            ?>
                <?php 
            if ($field->required == 1) {
                echo '<span class="joms-required">*</span>';
            }
Exemple #2
0
        ?>
</dt>
		    	<dd>
		    		<?php 
        if (!empty($item['searchLink'])) {
            ?>
						<a href="<?php 
            echo $item['searchLink'];
            ?>
"> 
					<?php 
        }
        ?>
					
					<?php 
        echo CProfileLibrary::getFieldData($item['type'], $item['value']);
        ?>
					
					<?php 
        if (!empty($item['searchLink'])) {
            ?>
						</a> 
					<?php 
        }
        ?>
				</dd>
		    <?php 
    }
    ?>
		</dl>
	</div>
Exemple #3
0
					<tr>
	 					<td class="key"><label id="lblfield<?php 
        echo $f->id;
        ?>
" for="field<?php 
        echo $f->id;
        ?>
" class="label"><?php 
        if ($f->required == 1) {
            echo '*';
        }
        echo JText::_($f->name);
        ?>
</label></td>	 					
	 					<td class="value"><?php 
        echo CProfileLibrary::getFieldHTML($f, '');
        ?>
</td>
	 					<td class="privacy">
	 						<?php 
        echo CPrivacy::getHTML('privacy' . $f->id, $f->access);
        ?>
	 					</td>
	 				</tr>
	 		<?php 
    }
    ?>
		</tbody>
		</table>
<?php 
}
Exemple #4
0
 /**
  * Step 4
  * Update the users profile.
  */
 public function registerUpdateProfile()
 {
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $model = $this->getModel('register');
     // Check for request forgeries
     $mySess = JFactory::getSession();
     $ipAddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
     $token = $mySess->get('JS_REG_TOKEN', '');
     $formToken = $jinput->request->get('authkey', '', 'STRING');
     //JRequest::getVar( 'authkey', '', 'REQUEST');
     //$authKey   = $model->getAssignedAuthKey($token, $ipAddress);
     if (!$token) {
         //(empty($formToken) || empty($authKey) || ($formToken != $authKey))
         echo '<div class="error-box">' . JText::_('COM_COMMUNITY_INVALID_SESSION') . '</div>';
         return;
     }
     //intercept validation process in custom profile
     $post = JRequest::get('post');
     /*
      * Rules:
      * First we let 3rd party plugin to intercept the validation.
      * if there is not error return, we then proceed with our validation.
      */
     $errMsg = array();
     $errTrigger = null;
     $appsLib = CAppPlugins::getInstance();
     $appsLib->loadApplications();
     $params = array();
     $params[] = $post;
     $errTrigger = $appsLib->triggerEvent('onRegisterProfileValidate', $params);
     if (!is_null($errTrigger)) {
         if (!empty($errTrigger[0]) && count($errTrigger[0]) > 0) {
             //error found.
             foreach ($errTrigger[0] as $err) {
                 $mainframe->enqueueMessage($err, 'error');
             }
             $this->registerProfile();
             return;
         }
     }
     // get required obj for registration
     $pModel = $this->getModel('profile');
     $values = array();
     $filter = array('published' => '1', 'registration' => '1');
     $profileType = JRequest::getInt('profileType', 0, 'POST');
     $profiles = $pModel->getAllFields($filter, $profileType);
     foreach ($profiles as $key => $groups) {
         foreach ($groups->fields as $data) {
             $fieldValue = new stdClass();
             // Get value from posted data and map it to the field.
             // Here we need to prepend the 'field' before the id because in the form, the 'field' is prepended to the id.
             $postData = $jinput->post->get('field' . $data->id, '', 'NONE');
             //JRequest::getVar('field'.$data->id, '', 'POST');
             // Retrieve the privacy data for this particular field.
             $fieldValue->access = JRequest::getInt('privacy' . $data->id, 0, 'POST');
             $fieldValue->value = CProfileLibrary::formatData($data->type, $postData);
             if (get_magic_quotes_gpc()) {
                 $fieldValue->value = stripslashes($fieldValue->value);
             }
             $values[$data->id] = $fieldValue;
             // @rule: Validate custom profile if necessary
             if (!CProfileLibrary::validateField($data->id, $data->type, $values[$data->id]->value, $data->required)) {
                 // If there are errors on the form, display to the user.
                 $message = JText::sprintf('COM_COMMUNITY_FIELD_CONTAIN_IMPROPER_VALUES', $data->name);
                 $mainframe->enqueueMessage($message, 'error');
                 $this->registerProfile();
                 return;
             }
         }
     }
     $profileType = $jinput->post->get('profileType', 0, 'NONE');
     //JRequest::getVar('profileType', 0, 'POST');
     $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
     $multiprofile->load($profileType);
     $tmpUser = $model->getTempUser($token);
     $user = $this->_createUser($tmpUser, $multiprofile->approvals, $multiprofile->id);
     //update the first/last name if it exist in the profile configuration
     $this->_updateFirstLastName($user);
     $pModel->saveProfile($user->id, $values);
     // Update user location data
     $pModel->updateLocationData($user->id);
     $this->sendEmail('registration_complete', $user, null, $multiprofile->approvals);
     // now we need to set it for later avatar upload page
     // do the clear up job for tmp user.
     $mySess->set('tmpUser', $user);
     $model->removeTempUser($token);
     $model->removeAuthKey($token);
     //redirect to avatar upload page.
     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=register&task=registerAvatar&profileType=' . $profileType, false));
 }
Exemple #5
0
        } else {
            ?>
				    	<dd>
				    		<?php 
            if (!empty($item['searchLink'])) {
                ?>
								<a href="<?php 
                echo $item['searchLink'];
                ?>
"> 
							<?php 
            }
            ?>
							
							<?php 
            echo CProfileLibrary::getFieldData($item);
            ?>
							
							<?php 
            if (!empty($item['searchLink'])) {
                ?>
								</a> 
							<?php 
            }
            ?>
						</dd>
					<?php 
        }
        ?>
				
				
</h4></li>
                <?php 
    }
    ?>

                <?php 
    foreach ($items as $item) {
        ?>
                    <?php 
        if (CPrivacy::isAccessAllowed($my->id, $profile['id'], 'custom', $item['access'])) {
            // There is some displayable data here
            $hasData = $hasData || CProfileLibrary::getFieldData($item) != '';
            ?>

                        <?php 
            $fieldData = CProfileLibrary::getFieldData($item);
            // Escape unless it is URL type, since URL type is in HTML format
            if ($item['type'] != 'url' && $item['type'] != 'email' && $item['type'] != 'list' && $item['type'] != 'checkbox') {
                $fieldData = $this->escape($fieldData);
            }
            // If textarea, we need to support multiline entry
            if ($item['type'] == 'textarea') {
                $fieldData = nl2br($fieldData);
            }
            if (!empty($fieldData)) {
                ?>
                            <li>
                                <h5 class="joms-text--light"><?php 
                echo JText::_($item['name']);
                ?>
</h5>
Exemple #7
0
 /**
  * Saves a user's profile
  *
  * @access	private
  * @param	none
  */
 private function _saveProfile()
 {
     $model = $this->getModel('profile');
     $usermodel = $this->getModel('user');
     $document = JFactory::getDocument();
     $my = CFactory::getUser();
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $input = CFactory::getInput();
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     $appsLib = CAppPlugins::getInstance();
     $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-profile-edit'));
     if (empty($saveSuccess) || !in_array(false, $saveSuccess)) {
         $values = array();
         $profiles = $model->getEditableProfile($my->id, $my->getProfileType());
         foreach ($profiles['fields'] as $group => $fields) {
             foreach ($fields as $data) {
                 $fieldValue = new stdClass();
                 // Get value from posted data and map it to the field.
                 // Here we need to prepend the 'field' before the id because in the form, the 'field' is prepended to the id.
                 // Grab raw, unfiltered data
                 $postData = $input->post->get('field' . $data['id'], '', 'RAW');
                 //
                 // Retrieve the privacy data for this particular field.
                 $fieldValue->access = JRequest::getInt('privacy' . $data['id'], 0, 'POST');
                 $fieldValue->value = CProfileLibrary::formatData($data['type'], $postData);
                 if (get_magic_quotes_gpc()) {
                     $fieldValue->value = stripslashes($fieldValue->value);
                 }
                 $values[$data['id']] = $fieldValue;
                 // @rule: Validate custom profile if necessary
                 if (!CProfileLibrary::validateField($data['id'], $data['type'], $values[$data['id']]->value, $data['required'], $data['visible'])) {
                     // If there are errors on the form, display to the user.
                     // If it is a drop down selection, use a different message
                     $message = '';
                     switch ($data['type']) {
                         case 'select':
                             $message = JText::sprintf('COM_COMMUNITY_FIELD_SELECT_EMPTY', $data['name']);
                             break;
                         case 'url':
                             $message = JText::sprintf('COM_COMMUNITY_FIELD_INVALID_URL', $data['name']);
                             break;
                         default:
                             $data['value'] = $values[$data['id']]->value;
                             $message = CProfileLibrary::getErrorMessage($data);
                     }
                     $mainframe->enqueueMessage(CTemplate::quote($message), 'error');
                     return false;
                 }
             }
         }
         // Rebuild new $values with field code
         $valuesCode = array();
         foreach ($values as $key => $val) {
             $fieldCode = $model->getFieldCode($key);
             if ($fieldCode) {
                 // For backward compatibility, we can't pass in an object. We need it to behave
                 // like 1.8.x where we only pass values.
                 $valuesCode[$fieldCode] = $val->value;
             }
         }
         $saveSuccess = false;
         $appsLib = CAppPlugins::getInstance();
         $appsLib->loadApplications();
         // Trigger before onBeforeUserProfileUpdate
         $args = array();
         $args[] = $my->id;
         $args[] = $valuesCode;
         $result = $appsLib->triggerEvent('onBeforeProfileUpdate', $args);
         $optionList = $model->getAllList();
         foreach ($optionList as $list) {
             // $optionList return all the list, even if the field is disabled
             // So, need to check if we're using it or not first
             if (isset($values[$list['id']]) && is_array($list['options'])) {
                 $option = $values[$list['id']]->value;
                 $option = str_replace('&amp;', '&', $option);
                 if (JString::strlen(JString::trim($option)) != 0 && !in_array($option, $list['options'])) {
                     if (!in_array($option, CProfile::getCountryList())) {
                         $result[] = false;
                     }
                 }
             }
         }
         // make sure none of the $result is false
         if (!$result || !in_array(false, $result)) {
             $saveSuccess = true;
             $model->saveProfile($my->id, $values);
         }
     }
     // Trigger before onAfterUserProfileUpdate
     $args = array();
     $args[] = $my->id;
     $args[] = $saveSuccess;
     $result = $appsLib->triggerEvent('onAfterProfileUpdate', $args);
     if ($saveSuccess) {
         CUserPoints::assignPoint('profile.save');
         return true;
     } else {
         $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_PROFILE_NOT_SAVED'), 'error');
         return false;
     }
 }
Exemple #8
0
        echo $field->id;
        ?>
"><span class="js-tooltip" title="<?php 
        echo $field->tips;
        ?>
"><?php 
        echo JText::_($field->name);
        ?>
</span><?php 
        if ($field->required == 1) {
            echo '<span class="required-sign"> *</span>';
        }
        ?>
</td>
			<td><?php 
        echo CProfileLibrary::getFieldHTML($field, '&nbsp; *', false);
        ?>
</td>
		</tr>
	<?php 
    }
    ?>
</table>

<?php 
}
echo JHtml::_('tabs.panel', JText::_('Setting'), 'setting-page');
?>
<div class="row-fluid">
	<div class='span12'>
		<table width='100%'>
Exemple #9
0
 /**
  * Save controller that receives arguments via HTTP POST.
  **/
 public function save()
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $lang =& JFactory::getLanguage();
     $lang->load('com_users');
     $userId = JRequest::getVar('userid', '', 'POST');
     $mainframe =& JFactory::getApplication();
     $message = '';
     $url = JRoute::_('index.php?option=com_community&view=users', false);
     $my =& JFactory::getUser();
     $acl =& JFactory::getACL();
     $cacl =& CACL::getInstance();
     $mailFrom = $mainframe->getCfg('mailfrom');
     $fromName = $mainframe->getCfg('fromname');
     $siteName = $mainframe->getCfg('sitename');
     if (empty($userId)) {
         $message = JText::_('COM_COMMUNITY_USERS_EMPTY_USER_ID');
         $mainframe->redirect($url, $message);
     }
     // Create a new JUser object
     $user = new JUser($userId);
     $original_gid = $user->get('gid');
     $post = JRequest::get('post');
     $post['username'] = JRequest::getVar('username', '', 'post', 'username');
     $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $notifyEmailSystem = JRequest::getVar('sendEmail', '', 'post', 'sendEmail');
     if (!$user->bind($post)) {
         $message = JText::_('COM_COMMUNITY_USERS_SAVE_USER_INFORMATION_ERROR') . ' : ' . $user->getError();
         $url = JRoute::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId, false);
         $mainframe->redirect($url, $message);
         exit;
     }
     //$objectID 	= $acl->get_object_id( 'users', $user->get('id'), 'ARO' );
     //$groups 	= $acl->get_object_groups( $objectID, 'ARO' );
     //$this_group = JString::strtolower( $acl->get_group_name( $groups[0], 'ARO' ) );
     $this_group = $cacl->getGroupsByUserId($user->get('id'));
     if ($user->get('id') == $my->get('id') && $user->get('block') == 1) {
         $message = JText::_('COM_COMMUNITY_USERS_BLOCK_YOURSELF');
         $url = JRoute::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId, false);
         $mainframe->redirect($url, $message);
         exit;
     }
     if ($this_group == 'super administrator' && $user->get('block') == 1) {
         $message = JText::_('COM_COMMUNITY_USERS_BLOCK_SUPER_ADMINISTRATOR');
         $url = JRoute::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId, false);
         $mainframe->redirect($url, $message);
         exit;
     }
     if ($this_group == 'administrator' && $my->get('gid') == 24 && $user->get('block') == 1) {
         $message = JText::_('COM_COMMUNITY_USERS_WARNBLOCK');
         $url = JRoute::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId, false);
         $mainframe->redirect($url, $message);
         exit;
     }
     if ($this_group == 'super administrator' && $my->get('gid') != 25) {
         $message = JText::_('COM_COMMUNITY_USERS_SUPER_ADMINISTRATOR_EDIT');
         $url = JRoute::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId, false);
         $mainframe->redirect($url, $message);
         exit;
     }
     $isNew = $user->get('id') == 0;
     if (!$isNew) {
         if ($user->get('gid') != $original_gid && $original_gid == 25) {
             $query = 'SELECT COUNT( ' . $db->nameQuote('id') . ' )' . ' FROM ' . $db->nameQuote('#__users') . ' WHERE ' . $db->nameQuote('gid') . ' = ' . $db->Quote(25) . ' AND ' . $db->nameQuote('block') . ' = ' . $db->Quote(0);
             $db->setQuery($query);
             $count = $db->loadResult();
             if ($count <= 1) {
                 $message = JText::_('COM_COMMUNITY_USERS_WARN_ONLY_SUPER');
                 $url = JRoute::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId, false);
                 $mainframe->redirect($url, $message);
                 exit;
             }
         }
     }
     //Joomla 1.6 patch to keep the group ID of user intact when saving
     if (property_exists($user, 'groups')) {
         foreach ($user->groups as $groupid => $groupname) {
             $user->groups[$groupid] = $groupid;
         }
     }
     if (!$user->save()) {
         $message = JText::_('COM_COMMUNITY_USERS_SAVE_USER_INFORMATION_ERROR') . ' : ' . $user->getError();
         $mainframe->redirect($url, $message);
         exit;
     }
     $appsLib =& CAppPlugins::getInstance();
     $appsLib->loadApplications();
     $userRow = array();
     $userRow[] = $user;
     $appsLib->triggerEvent('onUserDetailsUpdate', $userRow);
     // @rule: Send out email if it is a new user.
     if ($isNew) {
         $adminEmail = $my->get('email');
         $adminName = $my->get('name');
         $subject = JText::_('COM_COMMUNITY_USERS_NEW_USER_MESSAGE_SUBJECT');
         $message = sprintf(JText::_('COM_COMMUNITY_USERS_NEW_USER_MESSAGE'), $user->get('name'), $siteName, JURI::root(), $user->get('username'), $user->password_clear);
         if (!empty($mailfrom) && !empty($fromName)) {
             $adminName = $fromName;
             $adminEmail = $mailFrom;
         }
         JUtility::sendMail($adminEmail, $adminName, $user->get('email'), $subject, $message);
     }
     // If updating self, load the new user object into the session
     if ($user->get('id') == $my->get('id')) {
         jimport('joomla.version');
         $version = new JVersion();
         $joomla_ver = $version->getHelpVersion();
         // Get the user group from the ACL
         if ($joomla_ver <= '0.15') {
             $grp = $acl->getAroGroup($user->get('id'));
             // Mark the user as logged in
             $user->set('guest', 0);
             $user->set('aid', 1);
             // Fudge Authors, Editors, Publishers and Super Administrators into the special access group
             if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) {
                 $user->set('aid', 2);
             }
             // Set the usertype based on the ACL group name
             $user->set('usertype', $grp->name);
         } elseif ($joomla_ver >= '0.16') {
             $grp_name = $cacl->getGroupUser($user->get('id'));
             // Mark the user as logged in
             $user->set('guest', 0);
             $user->set('aid', 1);
             // Fudge Authors, Editors, Publishers and Super Administrators into the special access group
             if ($cacl->is_group_child_of($grp_name, 'Registered') || $cacl->is_group_child_of($grp_name, 'Public Backend')) {
                 $user->set('aid', 2);
             }
             // Set the usertype based on the ACL group name
             $user->set('usertype', $grp_name);
         }
         $session =& JFactory::getSession();
         $session->set('user', $user);
     }
     // Process and save custom fields
     $user = CFactory::getUser($userId);
     $model =& $this->getModel('users');
     $userModel = CFactory::getModel('profile');
     $values = array();
     $profile = $userModel->getEditableProfile($userId, $user->getProfileType());
     CFactory::load('libraries', 'profile');
     foreach ($profile['fields'] as $group => $fields) {
         foreach ($fields as $data) {
             // Get value from posted data and map it to the field.
             // Here we need to prepend the 'field' before the id because in the form, the 'field' is prepended to the id.
             $postData = JRequest::getVar('field' . $data['id'], '', 'POST');
             $values[$data['id']] = CProfileLibrary::formatData($data['type'], $postData);
             // @rule: Validate custom profile if necessary
             if (!CProfileLibrary::validateField($data['id'], $data['type'], $values[$data['id']], $data['required'])) {
                 // If there are errors on the form, display to the user.
                 $message = JText::sprintf('The field "%1$s" contain improper values', $data['name']);
                 $mainframe->redirect('index.php?option=com_community&view=users&layout=edit&id=' . $user->id, $message, 'error');
                 return;
             }
         }
     }
     // Update user's parameter DST
     $params =& $user->getParams();
     $offset = $post['daylightsavingoffset'];
     $params->set('daylightsavingoffset', $offset);
     $params->set('notifyEmailSystem', $notifyEmailSystem);
     // Update user's point
     $points = JRequest::getVar('userpoint', '', 'REQUEST');
     if (!empty($points)) {
         $user->_points = $points;
         $user->save();
     }
     // Update user's status
     if ($user->getStatus() != $post['status']) {
         $user->setStatus($post['status']);
     }
     $user->save('params');
     $valuesCode = array();
     foreach ($values as $key => &$val) {
         $fieldCode = $userModel->getFieldCode($key);
         if ($fieldCode) {
             $valuesCode[$fieldCode] =& $val;
         }
     }
     // Trigger before onBeforeUserProfileUpdate
     $args = array();
     $args[] = $userId;
     $args[] = $valuesCode;
     $saveSuccess = false;
     $result = $appsLib->triggerEvent('onBeforeProfileUpdate', $args);
     if (!$result || !in_array(false, $result)) {
         $saveSuccess = true;
         $userModel->saveProfile($userId, $values);
     }
     // Trigger before onAfterUserProfileUpdate
     $args = array();
     $args[] = $userId;
     $args[] = $saveSuccess;
     $result = $appsLib->triggerEvent('onAfterProfileUpdate', $args);
     if (!$saveSuccess) {
         $message = JText::_('COM_COMMUNITY_USERS_PROFILE_NOT_UPDATED');
         $mainframe->redirect($url, $message, 'error');
     }
     $message = JText::_('COM_COMMUNITY_USERS_UPDATED_SUCCESSFULLY');
     $mainframe->redirect($url, $message);
 }
Exemple #10
0
 /**
  * Saves a user's profile	
  * 	 	
  * @access	private
  * @param	none 
  */
 private function _saveProfile()
 {
     $model =& $this->getModel('profile');
     $usermodel =& $this->getModel('user');
     $document =& JFactory::getDocument();
     $my = CFactory::getUser();
     $mainframe =& JFactory::getApplication();
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     CFactory::load('libraries', 'apps');
     $appsLib =& CAppPlugins::getInstance();
     $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-profile-edit'));
     if (empty($saveSuccess) || !in_array(false, $saveSuccess)) {
         $values = array();
         $profiles = $model->getEditableProfile($my->id, $my->getProfileType());
         CFactory::load('libraries', 'profile');
         foreach ($profiles['fields'] as $group => $fields) {
             foreach ($fields as $data) {
                 // Get value from posted data and map it to the field.
                 // Here we need to prepend the 'field' before the id because in the form, the 'field' is prepended to the id.
                 $postData = JRequest::getVar('field' . $data['id'], '', 'POST');
                 $values[$data['id']] = CProfileLibrary::formatData($data['type'], $postData);
                 // @rule: Validate custom profile if necessary
                 if (!CProfileLibrary::validateField($data['type'], $values[$data['id']], $data['required'])) {
                     // If there are errors on the form, display to the user.
                     $message = JText::sprintf('CC FIELD CONTAIN IMPROPER VALUES', $data['name']);
                     $mainframe->enqueueMessage($message, 'error');
                     return;
                 }
             }
         }
         // Rebuild new $values with field code
         $valuesCode = array();
         foreach ($values as $key => &$val) {
             $fieldCode = $model->getFieldCode($key);
             if ($fieldCode) {
                 $valuesCode[$fieldCode] =& $val;
             }
         }
         $saveSuccess = true;
         $appsLib =& CAppPlugins::getInstance();
         $appsLib->loadApplications();
         // Trigger before onBeforeUserProfileUpdate
         $args = array();
         $args[] = $my->id;
         $args[] = $valuesCode;
         $result = $appsLib->triggerEvent('onBeforeProfileUpdate', $args);
         // make sure none of the $result is false
         if (!$result || !in_array(false, $result)) {
             $model->saveProfile($my->id, $values);
         } else {
             $saveSuccess = false;
         }
     }
     // Trigger before onAfterUserProfileUpdate
     $args = array();
     $args[] = $my->id;
     $args[] = $saveSuccess;
     $result = $appsLib->triggerEvent('onAfterProfileUpdate', $args);
     if ($saveSuccess) {
         CFactory::load('libraries', 'userpoints');
         CUserPoints::assignPoint('profile.save');
         $mainframe->enqueueMessage(JText::_('CC PROFILE SAVED'));
     } else {
         $mainframe->enqueueMessage(JText::_('CC PROFILE NOT SAVED'), 'error');
     }
 }
Exemple #11
0
 /**
  * Updates user profile
  **/
 public function updateProfile()
 {
     $document = JFactory::getDocument();
     $viewType = $document->getType();
     $viewName = JRequest::getCmd('view', $this->getName());
     $view = $this->getView($viewName, '', $viewType);
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     if (!$this->_isEnabled()) {
         echo JText::_('COM_COMMUNITY_MULTIPROFILE_IS_CURRENTLY_DISABLED');
         return;
     }
     $appsLib = CAppPlugins::getInstance();
     $appsLib->loadApplications();
     $mainframe = JFactory::getApplication();
     $profileType = JRequest::getInt('profileType', 0);
     $model = $this->getModel('Profile');
     $my = CFactory::getUser();
     $data = $model->getEditableProfile($my->id, $profileType);
     $oldProfileType = $my->getProfileType();
     // If there is nothing to edit, we should just redirect
     if (empty($data['fields'])) {
         $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
         $multiprofile->load($profileType);
         $my->_profile_id = $multiprofile->id;
         // Trigger before onProfileTypeUpdate
         $args = array();
         $args[] = $my->id;
         $args[] = $oldProfileType;
         $args[] = $multiprofile->id;
         $result = $appsLib->triggerEvent('onProfileTypeUpdate', $args);
         //CFactory::load( 'helpers' , 'owner' );
         // @rule: If profile requires approval, logout user and update block status. This is not
         // applicable to site administrators.
         if ($multiprofile->approvals && !COwnerHelper::isCommunityAdmin($my->id)) {
             $my->set('block', 1);
             //CFactory::load( 'helpers' , 'owner' );
             $subject = JText::sprintf('COM_COMMUNITY_USER_NEEDS_APPROVAL_SUBJECT', $my->name);
             $message = JText::sprintf('COM_COMMUNITY_USER_PROFILE_CHANGED_NEEDS_APPROVAL', $my->name, $my->email, $my->username, $multiprofile->name, CRoute::getExternalURL('index.php?option=com_community&view=profile&userid=' . $my->id));
             COwnerHelper::emailCommunityAdmins($subject, $message);
             // @rule: Logout user.
             $mainframe->logout();
         }
         $my->save();
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=multiprofile&task=profileupdated&profileType=' . $multiprofile->id, false));
     }
     if ($jinput->getMethod() == 'POST') {
         $model = $this->getModel('Profile');
         $values = array();
         $profileType = JRequest::getInt('profileType', 0, 'POST');
         //CFactory::load( 'libraries' , 'profile' );
         $profiles = $model->getAllFields(array('published' => '1'), $profileType);
         $errors = array();
         // Delete all user's existing profile values and re-add the new ones
         // @rule: Bind the user data
         foreach ($profiles as $key => $groups) {
             foreach ($groups->fields as $data) {
                 // Get value from posted data and map it to the field.
                 // Here we need to prepend the 'field' before the id because in the form, the 'field' is prepended to the id.
                 $postData = JRequest::getVar('field' . $data->id, '', 'POST');
                 $values[$data->id] = CProfileLibrary::formatData($data->type, $postData);
                 if (get_magic_quotes_gpc()) {
                     $values[$data->id] = stripslashes($values[$data->id]);
                 }
                 // @rule: Validate custom profile if necessary
                 if (!CProfileLibrary::validateField($data->id, $data->type, $values[$data->id], $data->required)) {
                     // If there are errors on the form, display to the user.
                     $message = JText::sprintf('COM_COMMUNITY_FIELD_CONTAIN_IMPROPER_VALUES', $data->name);
                     $mainframe->enqueueMessage($message, 'error');
                     $errors[] = true;
                 }
             }
         }
         // Rebuild new $values with field code
         $valuesCode = array();
         foreach ($values as $key => $val) {
             $fieldCode = $model->getFieldCode($key);
             if ($fieldCode) {
                 // For backward compatibility, we can't pass in an object. We need it to behave
                 // like 1.8.x where we only pass values.
                 $valuesCode[$fieldCode] = $val;
             }
         }
         $args = array();
         $args[] = $my->id;
         $args[] = $valuesCode;
         $saveSuccess = false;
         $result = $appsLib->triggerEvent('onBeforeProfileUpdate', $args);
         // make sure none of the $result is false
         if (!$result || !in_array(false, $result)) {
             $saveSuccess = true;
             $model->saveProfile($my->id, $values);
         }
         $mainframe = JFactory::getApplication();
         if (!$saveSuccess) {
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=multiprofile&task=updateProfile&profileType=' . $profileType, false), JText::_('COM_COMMUNITY_PROFILE_NOT_SAVED'), 'error');
         }
         // Trigger before onAfterUserProfileUpdate
         $args = array();
         $args[] = $my->id;
         $args[] = $saveSuccess;
         $result = $appsLib->triggerEvent('onAfterProfileUpdate', $args);
         $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
         $multiprofile->load($profileType);
         $my->_profile_id = $multiprofile->id;
         //CFactory::load( 'helpers' , 'owner' );
         // @rule: If profile requires approval, logout user and update block status. This is not
         // applicable to site administrators.
         if ($multiprofile->approvals && !COwnerHelper::isCommunityAdmin($my->id)) {
             $my->set('block', 1);
             //CFactory::load( 'helpers' , 'owner' );
             $subject = JText::sprintf('COM_COMMUNITY_USER_NEEDS_APPROVAL_SUBJECT', $my->name);
             $message = JText::sprintf('COM_COMMUNITY_USER_PROFILE_CHANGED_NEEDS_APPROVAL', $my->name, $my->email, $my->username, $multiprofile->name, CRoute::getExternalURL('index.php?option=com_community&view=profile&userid=' . $my->id));
             COwnerHelper::emailCommunityAdmins($subject, $message);
             // @rule: Logout user.
             $mainframe->logout();
         }
         $my->save();
         // Trigger before onProfileTypeUpdate
         $args = array();
         $args[] = $my->id;
         $args[] = $oldProfileType;
         $args[] = $multiprofile->id;
         $result = $appsLib->triggerEvent('onProfileTypeUpdate', $args);
         if (!in_array(true, $errors)) {
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=multiprofile&task=profileupdated&profileType=' . $multiprofile->id, false));
         }
     }
     echo $view->get(__FUNCTION__);
 }
Exemple #12
0
 /**
  * Updates user profile
  **/
 public function updateProfile()
 {
     $document =& JFactory::getDocument();
     $viewType = $document->getType();
     $viewName = JRequest::getCmd('view', $this->getName());
     $view =& $this->getView($viewName, '', $viewType);
     if (!$this->_isEnabled()) {
         echo JText::_('CC MULTIPROFILE IS CURRENTLY DISABLED');
         return;
     }
     $mainframe =& JFactory::getApplication();
     $profileType = JRequest::getInt('profileType', 0);
     $model = $this->getModel('Profile');
     $my = CFactory::getUser();
     $data = $model->getEditableProfile($my->id, $profileType);
     // If there is nothing to edit, we should just redirect
     if (empty($data['fields'])) {
         $multiprofile =& JTable::getInstance('MultiProfile', 'CTable');
         $multiprofile->load($profileType);
         $my->_profile_id = $multiprofile->id;
         CFactory::load('helpers', 'owner');
         // @rule: If profile requires approval, logout user and update block status. This is not
         // applicable to site administrators.
         if ($multiprofile->approvals && !COwnerHelper::isCommunityAdmin($my->id)) {
             $my->set('block', 1);
             CFactory::load('helpers', 'owner');
             $subject = JText::sprintf('CC USER NEEDS APPROVAL SUBJECT', $my->name);
             $message = JText::sprintf('CC USER PROFILE CHANGED NEEDS APPROVAL', $my->name, $my->email, $my->username, $multiprofile->name, CRoute::getExternalURL('index.php?option=com_community&view=profile&userid=' . $my->id));
             COwnerHelper::emailCommunityAdmins($subject, $message);
             // @rule: Logout user.
             $mainframe->logout();
         }
         $my->save();
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=multiprofile&task=profileupdated&profileType=' . $multiprofile->id, false));
     }
     if (JRequest::getMethod() == 'POST') {
         $model = $this->getModel('Profile');
         $values = array();
         $profileType = JRequest::getInt('profileType', 0, 'POST');
         CFactory::load('libraries', 'profile');
         $profiles = $model->getAllFields(array('published' => '1', 'registration' => '1'), $profileType);
         $errors = array();
         $my = CFactory::getUser();
         // Delete all user's existing profile values and re-add the new ones
         // @rule: Bind the user data
         foreach ($profiles as $key => $groups) {
             foreach ($groups->fields as $data) {
                 // Get value from posted data and map it to the field.
                 // Here we need to prepend the 'field' before the id because in the form, the 'field' is prepended to the id.
                 $postData = JRequest::getVar('field' . $data->id, '', 'POST');
                 $values[$data->id] = CProfileLibrary::formatData($data->type, $postData);
                 // @rule: Validate custom profile if necessary
                 if (!CProfileLibrary::validateField($data->type, $values[$data->id], $data->required)) {
                     // If there are errors on the form, display to the user.
                     $message = JText::sprintf('CC FIELD CONTAIN IMPROPER VALUES', $data->name);
                     $mainframe->enqueueMessage($message, 'error');
                     $errors[] = true;
                 }
             }
         }
         $model->saveProfile($my->id, $values);
         $multiprofile =& JTable::getInstance('MultiProfile', 'CTable');
         $multiprofile->load($profileType);
         $my->_profile_id = $multiprofile->id;
         $mainframe =& JFactory::getApplication();
         CFactory::load('helpers', 'owner');
         // @rule: If profile requires approval, logout user and update block status. This is not
         // applicable to site administrators.
         if ($multiprofile->approvals && !COwnerHelper::isCommunityAdmin($my->id)) {
             $my->set('block', 1);
             CFactory::load('helpers', 'owner');
             $subject = JText::sprintf('CC USER NEEDS APPROVAL SUBJECT', $my->name);
             $message = JText::sprintf('CC USER PROFILE CHANGED NEEDS APPROVAL', $my->name, $my->email, $my->username, $multiprofile->name, CRoute::getExternalURL('index.php?option=com_community&view=profile&userid=' . $my->id));
             COwnerHelper::emailCommunityAdmins($subject, $message);
             // @rule: Logout user.
             $mainframe->logout();
         }
         $my->save();
         if (!in_array(true, $errors)) {
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=multiprofile&task=profileupdated&profileType=' . $multiprofile->id, false));
         }
     }
     echo $view->get(__FUNCTION__);
 }