/** * Update Member's Profile * * @param unknown_type $vars * @return unknown */ public function updateProfile(&$vars) { $IdMember = (int) $vars['memberid']; $words = new MOD_words(); $rights = new MOD_right(); $m = $vars['member']; // fantastic ... love the implementation. Fake $CanTranslate = false; // $CanTranslate = CanTranslate($vars["memberid"], $_SESSION['IdMember']); $ReadCrypted = "MemberReadCrypted"; // This might be changed in the future if ($rights->hasRight('Admin') || $rights->hasRight('SafetyTeam')) { // admin or CanTranslate can alter other profiles $ReadCrypted = "AdminReadCrypted"; // In this case the AdminReadCrypted will be used } $m->removeLanguages(); foreach ($vars['languages_selected'] as $lang) { if ($language = $this->createEntity('Language')->findById($lang->IdLanguage)) { $ml = $this->createEntity('MemberLanguage'); $ml->setSpokenLanguage($m, $language, $lang->Level); } } // Set the language that ReplaceinMTrad uses for writing $words->setlangWrite($vars['profile_language']); // refactoring to use member entity // $m->LastLogin = '******' ? 'Never' : $layoutbits->ago(strtotime($TM->LastLogin)); // Members lastlogin is no to be updated here if (isset($vars['Status']) && !empty($vars['Status'])) { // this can only happen when an admin or the safety team edits a profile $m->Status = $vars['Status']; } $m->Gender = $vars['gender']; $m->HideGender = $vars['HideGender']; $m->BirthDate = $vars['BirthYear'] . '-' . $vars['BirthMonth'] . '-' . $vars['BirthDay']; $m->bday = $vars['BirthDay']; $m->bmonth = $vars['BirthMonth']; $m->byear = $vars['BirthYear']; $m->HideBirthDate = $vars['HideBirthDate']; $m->HideGender = $vars['HideGender']; $m->ProfileSummary = $words->ReplaceInMTrad($vars['ProfileSummary'], "members.ProfileSummary", $IdMember, $m->ProfileSummary, $IdMember); $m->WebSite = strip_tags($vars['WebSite']); $m->Accomodation = $vars['Accomodation']; $m->Organizations = $words->ReplaceInMTrad($vars['Organizations'], "members.Organizations", $IdMember, $m->Organizations, $IdMember); $m->Occupation = $words->ReplaceInMTrad(strip_tags($vars['Occupation']), "members.Occupation", $IdMember, $m->Occupation, $IdMember); $m->ILiveWith = $words->ReplaceInMTrad($vars['ILiveWith'], "members.ILiveWith", $IdMember, $m->ILiveWith, $IdMember); $m->MaxGuest = strip_tags($vars['MaxGuest']); $m->MaxLenghtOfStay = $words->ReplaceInMTrad($vars['MaxLenghtOfStay'], "members.MaxLenghtOfStay", $IdMember, $m->MaxLenghtOfStay, $IdMember); $m->AdditionalAccomodationInfo = $words->ReplaceInMTrad($vars['AdditionalAccomodationInfo'], "members.AdditionalAccomodationInfo", $IdMember, $m->AdditionalAccomodationInfo, $IdMember); $m->TypicOffer = strip_tags($vars['TypicOffer']); $m->Restrictions = strip_tags($vars['Restrictions']); $m->OtherRestrictions = $words->ReplaceInMTrad($vars['OtherRestrictions'], "members.OtherRestrictions", $IdMember, $m->OtherRestrictions, $IdMember); $m->Hobbies = $words->ReplaceInMTrad($vars['Hobbies'], "members.Hobbies", $IdMember, $m->Hobbies, $IdMember); $m->Books = $words->ReplaceInMTrad($vars['Books'], "members.Books", $IdMember, $m->Books, $IdMember); $m->Music = $words->ReplaceInMTrad($vars['Music'], "members.Music", $IdMember, $m->Music, $IdMember); $m->Movies = $words->ReplaceInMTrad($vars['Movies'], "members.Movies", $IdMember, $m->Movies, $IdMember); $m->PastTrips = $words->ReplaceInMTrad($vars['PastTrips'], "members.PastTrips", $IdMember, $m->PastTrips, $IdMember); $m->PlannedTrips = $words->ReplaceInMTrad($vars['PlannedTrips'], "members.PlannedTrips", $IdMember, $m->PlannedTrips, $IdMember); $m->PleaseBring = $words->ReplaceInMTrad($vars['PleaseBring'], "members.PleaseBring", $IdMember, $m->PleaseBring, $IdMember); $m->OfferGuests = $words->ReplaceInMTrad($vars['OfferGuests'], "members.OfferGuests", $IdMember, $m->OfferGuests, $IdMember); $m->OfferHosts = $words->ReplaceInMTrad($vars['OfferHosts'], "members.OfferHosts", $IdMember, $m->OfferHosts, $IdMember); $m->PublicTransport = $words->ReplaceInMTrad($vars['PublicTransport'], "members.PublicTransport", $IdMember, $m->PublicTransport, $IdMember); // as $CanTranslate is set explicitly above, this is disabled // if (!$CanTranslate) { // a volunteer translator will not be allowed to update crypted data if ($vars["HouseNumber"] != $m->get_housenumber()) { $this->logWrite("Housenumber updated", "Address Update"); } if ($vars["Street"] != $m->get_street()) { $this->logWrite("Street updated", "Address Update"); } if ($vars["Zip"] != $m->get_zip()) { $this->logWrite("Zip updated", "Address Update"); } if ($vars["Email"] == "cryptedhidden") { $this->logWrite("members.model updateprofile email keeps previous value (cryptedhidden detected)", "Debug"); } else { if ($vars["Email"] != $m->email) { $this->logWrite("Email updated (previous was " . $m->email . ")", "Email Update"); // Sticking to old BW, the previous email is stored in logs, // this might be discussed, but if the member fills a bad email, // there is no more way to retrieve him // Todo : get rid with this, but implement a confimmation mail $m->Email = MOD_crypt::NewReplaceInCrypted(strip_tags($vars['Email']), "members.Email", $IdMember, $m->Email, $IdMember, $this->ShallICrypt($vars, "Email")); } } if ($vars["HomePhoneNumber"] != "cryptedhidden") { $m->HomePhoneNumber = MOD_crypt::NewReplaceInCrypted(addslashes(strip_tags($vars['HomePhoneNumber'])), "members.HomePhoneNumber", $IdMember, $m->HomePhoneNumber, $IdMember, $this->ShallICrypt($vars, "HomePhoneNumber")); } if ($vars["CellPhoneNumber"] != "cryptedhidden") { $m->CellPhoneNumber = MOD_crypt::NewReplaceInCrypted(addslashes(strip_tags($vars['CellPhoneNumber'])), "members.CellPhoneNumber", $IdMember, $m->CellPhoneNumber, $IdMember, $this->ShallICrypt($vars, "CellPhoneNumber")); } if ($vars["WorkPhoneNumber"] != "cryptedhidden") { $m->WorkPhoneNumber = MOD_crypt::NewReplaceInCrypted(addslashes(strip_tags($vars['WorkPhoneNumber'])), "members.WorkPhoneNumber", $IdMember, $m->WorkPhoneNumber, $IdMember, $this->ShallICrypt($vars, "WorkPhoneNumber")); } if ($vars["chat_SKYPE"] != "cryptedhidden") { $m->chat_SKYPE = MOD_crypt::NewReplaceInCrypted(addslashes(strip_tags($vars['chat_SKYPE'])), "members.chat_SKYPE", $IdMember, $m->chat_SKYPE, $IdMember, $this->ShallICrypt($vars, "chat_SKYPE")); } if ($vars["chat_AOL"] != "cryptedhidden") { $m->chat_AOL = MOD_crypt::NewReplaceInCrypted(addslashes(strip_tags($vars['chat_AOL'])), "members.chat_AOL", $IdMember, $m->chat_AOL, $IdMember, $this->ShallICrypt($vars, "chat_AOL")); } if ($vars["chat_YAHOO"] != "cryptedhidden") { $m->chat_YAHOO = MOD_crypt::NewReplaceInCrypted(addslashes(strip_tags($vars['chat_YAHOO'])), "members.chat_YAHOO", $IdMember, $m->chat_YAHOO, $IdMember, $this->ShallICrypt($vars, "chat_YAHOO")); } if ($vars["chat_ICQ"] != "cryptedhidden") { $m->chat_ICQ = MOD_crypt::NewReplaceInCrypted(addslashes(strip_tags($vars['chat_ICQ'])), "members.chat_ICQ", $IdMember, $m->chat_ICQ, $IdMember, $this->ShallICrypt($vars, "chat_ICQ")); } if ($vars["chat_Others"] != "cryptedhidden") { $m->chat_Others = MOD_crypt::NewReplaceInCrypted(addslashes(strip_tags($vars['chat_Others'])), "members.chat_Others", $IdMember, $m->chat_Others, $IdMember, $this->ShallICrypt($vars, "chat_Others")); } if ($vars["chat_GOOGLE"] != "cryptedhidden") { $m->chat_GOOGLE = MOD_crypt::NewReplaceInCrypted(addslashes(strip_tags($vars['chat_GOOGLE'])), "members.chat_GOOGLE", $IdMember, $m->chat_GOOGLE, $IdMember, $this->ShallICrypt($vars, "chat_GOOGLE")); } $firstname = MOD_crypt::AdminReadCrypted($m->FirstName); $secondname = MOD_crypt::AdminReadCrypted($m->SecondName); $lastname = MOD_crypt::AdminReadCrypted($m->LastName); if ($firstname != strip_tags($vars['FirstName']) || $secondname != strip_tags($vars['SecondName']) || $lastname != strip_tags($vars['LastName'])) { $this->logWrite("{$m->Username} changed name. Firstname: {$firstname} -> " . strip_tags($vars['FirstName']) . ", second name: {$secondname} -> " . strip_tags($vars['SecondName']) . ", second name: {$lastname} -> " . strip_tags($vars['LastName']), 'Profile update'); } if ($vars["FirstName"] != "cryptedhidden") { MOD_crypt::NewReplaceInCrypted($this->dao->escape(strip_tags($vars['FirstName'])), "members.FirstName", $IdMember, $m->FirstName, $IdMember, $this->ShallICrypt($vars, "FirstName")); } if ($vars["SecondName"] != "cryptedhidden") { $cryptId = MOD_crypt::NewReplaceInCrypted($this->dao->escape(strip_tags($vars['SecondName'])), "members.SecondName", $IdMember, $m->SecondName, $IdMember, $this->ShallICrypt($vars, "SecondName")); // Update member if a new crypted SecondName value was added if ($cryptId != $m->SecondName) { $m->SecondName = $cryptId; } } if ($vars["LastName"] != "cryptedhidden") { MOD_crypt::NewReplaceInCrypted($this->dao->escape(strip_tags($vars['LastName'])), "members.LastName", $IdMember, $m->LastName, $IdMember, $this->ShallICrypt($vars, "LastName")); } if ($vars["Zip"] != "cryptedhidden") { $this->logWrite("in members.model updateprofile() Before Zip update addresss.Zip=" . $m->address->Zip, "Debug"); $cryptId = MOD_crypt::NewReplaceInCrypted($this->dao->escape(strip_tags($vars['Zip'])), "addresses.Zip", $m->IdAddress, $m->address->Zip, $IdMember, $this->ShallICrypt($vars, "Zip")); // Update addresses table if a new crypted zip value was added if ($cryptId != $m->address->Zip) { $m->setCryptedZip($cryptId); } $this->logWrite("in members.model updateprofile() After Zip update addresss.Zip=" . $m->address->Zip . " \$cryptId=" . $cryptId, "Debug"); } if ($vars["HouseNumber"] != "cryptedhidden") { $cryptId = MOD_crypt::NewReplaceInCrypted($this->dao->escape(strip_tags($vars['HouseNumber'])), "addresses.HouseNumber", $m->IdAddress, $m->address->HouseNumber, $IdMember, $this->ShallICrypt($vars, "Address")); // Update addresses table if a new crypted HouseNumber value was added if ($cryptId != $m->address->HouseNumber) { $m->setCryptedHouseNumber($cryptId); } } if ($vars["Street"] != "cryptedhidden") { $cryptId = MOD_crypt::NewReplaceInCrypted($this->dao->escape(strip_tags($vars['Street'])), "addresses.StreetName", $m->IdAddress, $m->address->StreetName, $IdMember, $this->ShallICrypt($vars, "Address")); // Update addresses table if a new crypted StreetName value was added if ($cryptId != $m->address->StreetName) { $m->setCryptedStreetName($cryptId); } } // Check relations, and update them if they have changed $Relations = $m->get_all_relations(); foreach ($Relations as $Relation) { if ($words->mInTrad($Relation->Comment, $vars['profile_language']) != $vars["RelationComment_" . $Relation->id] and !empty($vars["RelationComment_" . $Relation->id])) { // echo "Relation #".$Relation->id,"<br />", $words->mInTrad($Relation->Comment,$vars['profile_language']),"<br />",$vars['RelationComment_'.$Relation->id],"<br />" ; $IdTrad = $words->ReplaceInMTrad(strip_tags($vars["RelationComment_" . $Relation->id]), "specialrelations.Comment", $Relation->id, $Relation->Comment, $IdMember); // Empty comments have trad id 0. Causing ReplaceInMTrad to create // a new trad id and returning the new number. if ($IdTrad != $Relation->id) { $m->update_relation($Relation->id, $IdTrad); } $this->logWrite("updating relation #" . $Relation->id . " Relation Confirmed=" . $Relation->Confirmed, "Profile update"); } } // Check groups membership description, and update them if they have changed // Tod od with Peter: check if there is other feature to update a group membership (a groupmembership model for example, or entity) /* group membership should not be present here, disabled for now $Groups=$m->getGroups() ; for ($i = 0; $i < count($Groups) ; $i++) { $group=$Groups[$i] ; $group_id = $group->getPKValue() ; $group_name_translated = $words->get("Group_".$group->Name); $group_comment_translated = htmlspecialchars($words->mInTrad($m->getGroupMembership($group)->Comment,$vars['profile_language']), ENT_QUOTES); $IdMemberShip=$m->getGroupMembership($group)->id ; if (($words->mInTrad($m->getGroupMembership($group)->Comment,$vars['profile_language'])!=$vars["GroupMembership_".$IdMemberShip]) and (!empty($vars["GroupMembership_".$IdMemberShip]))) { echo "Group #".$group_id,"<br />",$words->mInTrad($m->getGroupMembership($group)->Comment,$vars['profile_language']),"<br />",$vars["GroupMembership_".$IdMemberShip],"<br />" ; $words->ReplaceInMTrad(strip_tags($vars["GroupMembership_".$IdMemberShip]),"membersgroups.Comment", $IdMemberShip, $m->getGroupMembership($group)->Comment, $IdMember); $this->logWrite("updating membership description in group #".$group_id." Group name=".$group->name, "Profil update"); } } */ // if a member with status NeedMore updates her/his profile, moving them back to pending if ($m->Status == 'NeedMore') { $m->Status = 'Pending'; } $status = $m->update(); if (!empty($_FILES['profile_picture']) && !empty($_FILES['profile_picture']['tmp_name'])) { if (isset($_FILES['profile_picture']) && $_FILES['profile_picture']['error'] == 0) { $this->avatarMake($vars['memberid'], $_FILES['profile_picture']['tmp_name']); } } if ($IdMember == $_SESSION['IdMember']) { $this->logWrite("Profile update by member himself [Status={$m->Status}]", "Profile update"); } else { $this->logWrite("update of another profile <b>" . $m->Username . "</b>", "Profile update"); // It can be an admin update or a delegated translation update } return $status; }
function NewReplaceInMTrad($ss, $TableColumn, $IdRecord, $IdTrad = 0, $IdOwner = 0) { $words_for_BW = new MOD_words(); return $words_for_BW->ReplaceInMTrad($ss, $TableColumn, $IdRecord, $IdTrad, $IdOwner); }