Session = $this->App->useSession(); $this->setId($this->App->getHTTPParameter('member_id', 'POST')); if($this->getIsAvalidMemberId()){ // IF the user is requesting a token, // we want to return right after switch($this->getState()){ case 'token-request': $this->_submitTokenRequest(); return FALSE; } $this->_setInitialFieldsAndLogos(); // Check what have changed switch($this->getState()){ case 'edit-info': $this->_editSelectedInformation(); break; case 'edit-logo': $this->_editSmallOrLargeLogo(); break; case 'edit-link': $this->_editMemberProduct(); break; case 'add-link': $this->_createMemberProduct(); break; case 'delete-link': $this->_deleteMemberProduct(); break; case 'add-contact': $this->_submitNewMaintainer(); break; } } } /** * Creating an Email in HTML format * */ public function createEmail($_to, $_subject, $_body){ if($this->App->is_staging()){ $_to = 'webdev@eclipse.org'; } $from = 'webmaster@eclipse.org'; $headers = "MIME-Version: 1.0" . PHP_EOL; $headers .= 'Content-Type: text/plain; charset=UTF-8' . PHP_EOL; $headers .= 'From: ' . $from . PHP_EOL . 'Reply-To: ' . $from . PHP_EOL; mail($_to, $_subject, $_body, $headers); } /** * GETTERS * */ /** * Getting the member's current short description * @param string * */ public function getMemberProduct(){ return $this->member_product; } /** * Getting the member's current short description * @param string * */ public function getMemberShortDescription(){ return stripslashes($this->member_short_description); } /** * Getting the member's current long description * @param string * */ public function getMemberLongDescription(){ return stripslashes($this->member_long_description); } /** * Getting the member's current url * @param string * */ public function getMemberUrl(){ return $this->member_url; } public function getMemberLogo($_size){ if($_size == 'small'){ return $this->member_small_logo; } if($_size == 'large'){ return $this->member_large_logo; } } /** * Get the Success or Error Mesage * @return string * */ public function getStatusMessage() { // Make sure we have a session session_start(); $html = ""; $messages = $_SESSION['eclipse']['status_message']; if(!empty($messages)){ foreach($messages as $type => $msgs) { foreach($msgs as $m) { $html .= '
';
$this->_setMemberLogo($new_image, $_param);
}
// SET MESSAGE
$this->setStatusMessage($message, $message_type);
$this->_redirectTo('#open_tab_edit-logos');
}
/**
* Validate that the token
* */
private function _fetchEmailBasedOnToken(){
$token = $this->App->returnQuotedString($this->App->sqlSanitize($this->getToken()));
$sql = 'SELECT *
FROM OrganizationTokens
WHERE Token = ' . $token;
$result = $this->App->eclipse_sql($sql);
// Put the results in an array
$email_array = array();
while ($row = mysql_fetch_assoc($result)) {
$email_array['EMail'] = $row['Email'];
}
$email = $this->App->returnQuotedString($this->App->sqlSanitize($email_array['EMail']));
$sql_people = 'SELECT EMail
FROM People
WHERE EMail = ' . $email;
$result_people = $this->App->foundation_sql($sql_people);
$uid_array = array();
while ($row = mysql_fetch_assoc($result_people)) {
$uid_array['EMail'] = $row['EMail'];
}
return $uid_array['EMail'];
}
/**
* Redirect the user to the same page after submit a form
* */
private function _redirectTo($_anchor){
header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . $_anchor, 302);
exit;
}
/**
* Resize an image/logo
* @param string
* */
private function _resize_image($_tmp_name,$_width,$_height,$_type,$_max){
$logo_resize = imagecreatetruecolor($_width, $_height);
$new_height = $_height;
$new_width = $_width;
if( $_width > $_max || $_height > $_max ) {
if( $_width < $_height ){
$new_height = $_max;
$aspect = $_width/$_height;
$new_width = $new_height * $aspect;
}else{
$new_width = $_max;
$aspect = $_height/$_width;
$new_height = $new_width * $aspect;
}
}
$logo_resize = imagecreatetruecolor($new_width, $new_height);
switch( $_type ) { //$_logo_info[2]
case IMAGETYPE_GIF: $image = imagecreatefromgif($_tmp_name); break;
case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($_tmp_name); break;
case IMAGETYPE_PNG:
imagealphablending($logo_resize, FALSE);
imagesavealpha($logo_resize, TRUE);
$image = imagecreatefrompng($_tmp_name);
$transparent = imagecolorallocatealpha($logo_resize, 255, 255, 255, 127);
imagefilledrectangle($logo_resize, 0, 0, $new_width, $new_height, $transparent);
break;
}
imagecopyresampled($logo_resize, $image, 0, 0, 0, 0, $new_width, $new_height, $_width, $_height);
return $logo_resize;
}
/**
* Set the initial values of text fields and logos
* on first page load
* @param string
* */
private function _setInitialFieldsAndLogos(){
// Fetch the member's information from database
$memberInfo = $this->fetchProfile();
// Set current information
$this->_setMemberTextFields($memberInfo['body'],$memberInfo['full_text'],$memberInfo['website']);
// Set the current small and large logo
$this->_setMemberLogo($memberInfo['small_logo_link'], 'small');
$this->_setMemberLogo($memberInfo['large_logo_link'], 'large');
// Set the current products
$this->_setMemberProduct($this->fetchMemberProducts());
}
/**
* SETTERS
* */
/**
* Setting all the current text fields
* @param string
* */
private function _setMemberTextFields($_short_desc, $_long_desc, $_url){
$this->_setMemberShortDescription($_short_desc);
$this->_setMemberLongDescription($_long_desc);
$this->_setMemberUrl($_url);
}
/**
* Setting all the current text fields
* @param string
* */
private function _setMemberProduct($_val){
$this->member_product = $_val;
}
/**
* Setting the member's current short description
* @param string
* */
private function _setMemberShortDescription($_val){
$this->member_short_description = $_val;
}
/**
* Setting the member's current long description
* @param string
* */
private function _setMemberLongDescription($_val){
$this->member_long_description = $_val;
}
/**
* Setting the member's current url
* @param string
* */
private function _setMemberUrl($_val){
$this->member_url = $_val;
}
/**
* Setting the current logo
* @param string
* */
private function _setMemberLogo($_val, $_size){
if($_size == 'small'){
$this->member_small_logo = $_val;
}
if($_size == 'large'){
$this->member_large_logo = $_val;
}
}
/**
* Set the token submitted by the user
* */
private function _setToken(){
$token = filter_var($this->App->getHTTPParameter('token', 'GET'), FILTER_SANITIZE_STRING);
if(!empty($token)){
$this->token = $token;
}
}
/**
* Submit a new maintainer for the specified member
* */
private function _submitNewMaintainer(){
$newMaintainerFields = array(
'first_name' => array('name' => 'first name', 'value' => filter_var($this->App->getHTTPParameter("new_maintainer_first_name", "POST"), FILTER_SANITIZE_STRING)),
'last_name' => array('name' => 'last name','value' => filter_var($this->App->getHTTPParameter("new_maintainer_last_name", "POST"), FILTER_SANITIZE_STRING)),
'email' => array('name' => 'email address','value' => filter_var($this->App->getHTTPParameter("new_maintainer_email", "POST"), FILTER_SANITIZE_EMAIL)),
'phone' => array('name' => 'phone number','value' => filter_var($this->App->getHTTPParameter("new_maintainer_phone", "POST"), FILTER_SANITIZE_STRING)),
'role' => array('name' => 'contact role','value' => filter_var_array($this->App->getHTTPParameter("new_maintainer_type", "POST"), FILTER_SANITIZE_STRING)),
);
// Fetch the current user's email and uid
$user = $this->fetchMemberMaintainers(EDITMEMBERSHIP_LOGGED_IN_USER);
foreach ($user as $u){
$currentUserFullName = $u['FName'] . " " . $u['LName'];
$currentUserEmail = $u['EMail'];
break;
}
$status_message = "";
$message_type = "danger";
$good_to_send = FALSE;
$is_company_rep = FALSE;
foreach($newMaintainerFields as $field) {
if($field['value'] == "") {
$status_message .= "Please enter a valid " . $field['name'] . ".
";
}
}
$maintainers = $this->fetchMemberMaintainers();
// Check if email is not empty
if ($newMaintainerFields['email']['value'] != "" && !empty($newMaintainerFields['role']['value'])) {
// Check if the email submitted matches with one already on record
// And already has the submitted role
foreach ($maintainers as $maintainer) {
if (($newMaintainerFields['email']['value'] == $maintainer['EMail'])) {
$roles = explode(",", $maintainer['Type']);
foreach ($newMaintainerFields['role']['value'] as $newRole) {
if (in_array($newRole, $roles)) {
$status_message .= $newMaintainerFields['email']['value'] . " is already a ". $newRole .".
";
}
}
break;
}
}
}
if($status_message == ""){
// All new maintainers are to be sent to Perri
$to = "membership-admin@eclipse.org";
$email_subject = "New Maintainer Request for " . $this->getMemberName(). "";
$email_body = $currentUserFullName . " has requested for a new maintainer to be added to " . $this->getMemberName() . '.';
$email_body .= PHP_EOL.PHP_EOL."Here are the information of the new maintainer:";
$email_body .= PHP_EOL."Member Name: " . $this->getMemberName();
$email_body .= PHP_EOL."First Name: " . $newMaintainerFields['first_name']['value'];
$email_body .= PHP_EOL."Last Name: " . $newMaintainerFields['last_name']['value'];
$email_body .= PHP_EOL."Email Address: " . $newMaintainerFields['email']['value'];
$email_body .= PHP_EOL."Phone Number: " . $newMaintainerFields['phone']['value'];
$email_body .= PHP_EOL."Contact Type: ";
foreach ($newMaintainerFields['role']['value'] as $role) {
if ($role == 'Company Representative (CR)') {
$is_company_rep = TRUE;
}
$email_body .= PHP_EOL . $role . ',';
}
$email_body .= PHP_EOL.PHP_EOL."Please verify this information and add the new maintainer if required.";
$email_body .= PHP_EOL.PHP_EOL."For more information about this request please contact:";
$email_body .= PHP_EOL."Name: " . $currentUserFullName;
$email_body .= PHP_EOL."Email: " . $currentUserEmail;
if ($is_company_rep === TRUE) {
$email_body .= PHP_EOL."NOTE: This person has been designated as a Company Representative.
PLEASE MAKE SURE THE COMPANY HAS ONLY 1 COMPANY REPRESENTATIVE.
THIS IS NOT AUTOMATED AND MUST BE VERIFIED WITH THE COMPANY AND
UPDATED MANUALLY IN BOTH THE DATABASE AND THE CRM.";
}
$this->createEmail($to, $email_subject, $email_body);
$status_message = "Thank you.
Your changes will be reviewed by the Eclipse Foundation's membership
management, and you may be contacted to provide further information.";
$message_type = "success";
}
$this->setStatusMessage($status_message, $message_type);
$this->_redirectTo('#open_tab_view-contacts');
}
/**
* Submit a token by email to the user
* The token will be valid for only 24 hours
* */
private function _submitTokenRequest(){
// Check if it's ok to send the token
// By verifying the email address submitted
$email_to = filter_var($this->App->getHTTPParameter("token_request_email", "POST"), FILTER_SANITIZE_EMAIL);
$emails = $this->fetchMemberMaintainers();
$good_to_send = FALSE;
foreach ($emails as $email){
if($email['EMail'] == $email_to){
$good_to_send = TRUE;
break;
}
}
// Default status message is the error message
$message = "The email address ". $email_to ." is not defined
as a maintainer for the member ". $this->getMemberName() .".
Please contact membership-admin@eclipse.org
if you think you should have access and be defined as a maintainer.";
$message_type = 'danger';
if($good_to_send){
//Generate the token
$token = $this->App->sqlSanitize(bin2hex(openssl_random_pseudo_bytes(32)));
$token_quoted = $this->App->returnQuotedString($token);
$token_is_valid_until = $this->App->returnQuotedString($this->App->sqlSanitize(date('Y-m-d H:i:s', strtotime('+1 day', time()))));
$subnet = $this->App->returnQuotedString($this->App->sqlSanitize($this->App->getSubnet()));
$memberId = $this->App->returnQuotedString($this->App->sqlSanitize($this->id));
$email_to = $this->App->returnQuotedString($email_to);
// Add a new entry in the OrganizationTokens table
$sql = 'INSERT INTO OrganizationTokens
(OrganizationID, Token, Email,
Subnet, ValidUntil)
values(' . $memberId . ', '. $token_quoted . ', ' . $email_to . ',
'. $subnet .', '. $token_is_valid_until .')';
$result = $this->App->eclipse_sql($sql);
// Send an email
$domain = $_SERVER['HTTP_HOST'];
$email_subject = 'Your token to modify the member page of ' . $this->getMemberName();
$email_body = 'You have been granted 24 hours to edit the '. $this->getMemberName() .' member page.'.
PHP_EOL. PHP_EOL .'Please use the following link to make the edits:'.
PHP_EOL.'https://'. $domain .'/membership/editMember.php?member_id='. $this->id .'&token='. $token .
PHP_EOL. PHP_EOL .'For more information, please contact membership-admin@eclipse.org.';
$this->createEmail($email_to, $email_subject, $email_body);
// Set the status message to success if the token has been sent
$message = 'An email has been sent
to ' . $email_to . '.
Please verify your inbox.';
$message_type = 'success';
}
$this->setStatusMessage($message, $message_type);
}
}