/** * 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)); }
/** * 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('&', '&', $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; } }
/** * 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); }
/** * 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'); } }
/** * 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__); }
/** * 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__); }