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 .= ''; } } unset($_SESSION['eclipse']['status_message']); session_destroy(); return $html; } } public function getState() { if (is_null($this->state)) { $this->state = $this->App->getHTTPParameter('state', 'GET'); } return $this->state; } /** * Get the token submitted by the user * @parem string * */ public function getToken(){ if (!$this->token) { $this->_setToken(); } return $this->token; } /** * Fetch the user ID using the Friend's class * @param string * */ public function fetchUserEmail(){ if ($this->getToken() != "") { $mail = $this->_fetchEmailBasedOnToken(); } if(empty($mail) && $this->Session->isLoggedIn()){ $Friend = $this->Session->getFriend(); $mail = $Friend->getEmail(); } return !empty($mail) ? $mail : ""; } /** * Query to fetch the Member's maintainers * @param array * */ public function fetchMemberMaintainers($_users = ""){ $_email = $this->App->returnQuotedString($this->App->sqlSanitize($this->fetchUserEmail())); $_member_id = $this->App->returnQuotedString($this->App->sqlSanitize($this->id)); if (!empty($_member_id)) { $sql = 'SELECT p.PersonID, p.FName, p.LName, p.EMail, p.Phone, group_concat("", CASE oc.Relation WHEN "MPE" THEN "Membership Page Editor" WHEN "DE" THEN "Delegate" WHEN "MA" THEN "Marketing" WHEN "CR" THEN "Company Representative" END) as Type FROM People as p LEFT JOIN OrganizationContacts as oc ON p.PersonID = oc.PersonID '; if ($_users == EDITMEMBERSHIP_LOGGED_IN_USER) { $sql .= 'WHERE p.EMail = '. $_email; } else { $sql .= 'WHERE p.EMail IN (SELECT p.Email FROM OrganizationContacts as oc LEFT JOIN People as p ON oc.PersonID = p.PersonID WHERE OrganizationID = ' . $_member_id . ' )'; } $sql .= 'AND (oc.Relation = "CR" OR oc.Relation = "MA" OR oc.Relation = "DE" OR oc.Relation = "MPE") AND OrganizationID = ' . $_member_id . ' GROUP BY p.PersonID'; $result = $this->App->foundation_sql($sql); // Build the array containing the Employees of this Member $_contacts = array(); while ($row = mysql_fetch_assoc($result)) { $_contacts[$row['PersonID']]['PersonID'] = $row['PersonID']; $_contacts[$row['PersonID']]['FName'] = $row['FName']; $_contacts[$row['PersonID']]['LName'] = $row['LName']; $_contacts[$row['PersonID']]['EMail'] = $row['EMail']; $_contacts[$row['PersonID']]['Phone'] = ($row['Phone'] != NULL ? $row['Phone'] : 'N/A'); $_contacts[$row['PersonID']]['Type'] = ($row['Type'] != NULL ? $row['Type'] : 'N/A'); } } return !empty($_contacts) ? $_contacts : array(); } /** * Content of the page on first load * Depending on if the user has the rights * to edit the page or not * @return string */ public function outputPage() { $html = ""; ob_start(); if ($this->getIsAvalidMemberId() === FALSE) { $this->setMemberName("Invalid Member ID"); include($_SERVER['DOCUMENT_ROOT'] . '/membership/content/en_showMemberInvalid.php'); return ob_get_clean(); exit; } switch($this->validateUser()) { case TRUE: $this->_editPage(); break; case FALSE: print '

Request access to edit the '. $this->getMemberName() .' Membership Page

'; print $this->getStatusMessage(); include($_SERVER['DOCUMENT_ROOT'] . '/membership/content/en_token_request.php'); break; } return ob_get_clean(); } /** * Set the success or error message * @param string * */ public function setStatusMessage($_message = '', $_type = 'success') { // Make sure we have a session session_start(); $alert_type = array('success', 'warning', 'danger', 'info'); if(!in_array($_type, $alert_type)) { $_type = 'warning'; } $_SESSION['eclipse']['status_message'][$_type][] = $_message; } /** * Is the user a valid maintainer for org? * * @return boolean */ public function isMaintainer() { $member_id = $this->id; $email = $this->fetchUserEmail(); if (!empty($email) && !empty($member_id)) { $member_id = $this->App->returnQuotedString($this->App->sqlSanitize($member_id)); $email = $this->App->returnQuotedString($this->App->sqlSanitize($email)); $sql = 'SELECT p.EMail FROM OrganizationContacts as oc LEFT JOIN People as p ON oc.PersonID = p.PersonID WHERE oc.OrganizationID = ' . $member_id . ' AND p.EMail = ' . $email . ' AND (oc.Relation = "CR" OR oc.Relation = "MA" OR oc.Relation = "DE" OR oc.Relation = "MPE")'; $result = $this->App->foundation_sql($sql); while ($row = mysql_fetch_assoc($result)) { $return = TRUE; break; } } return !empty($return) ? TRUE : FALSE; } /** * Validate token * * @return boolean */ public function validateToken() { $member_id = $this->id; $token = $this->getToken(); $email = $this->fetchUserEmail(); if (!empty($email) && !empty($member_id) && !empty($token)) { $token = $this->App->returnQuotedString($this->App->sqlSanitize($token)); $member_id = $this->App->returnQuotedString($this->App->sqlSanitize($member_id)); $email = $this->App->returnQuotedString($this->App->sqlSanitize($email)); $subnet = $this->App->returnQuotedString($this->App->sqlSanitize($this->App->getSubnet())); // Check to see if the token is there and valid $sql = 'SELECT ValidUntil FROM OrganizationTokens WHERE Token = ' . $token . ' and OrganizationID = ' . $member_id . ' and Email = ' . $email . ' and Subnet = ' . $subnet; $result = $this->App->eclipse_sql($sql); while ($row = mysql_fetch_assoc($result)) { // Check to see if the token has expired $current_time = date('Y-m-d H:i:s'); if ($row['ValidUntil'] > $current_time) { $return = TRUE; break; } } } return !empty($return) ? TRUE : FALSE; } /** * Is logged-in user an admin? * * @return boolean */ public function isAdmin(){ $admins = array( 'pmisingnameu8g' => 'perri.lavergne@eclipse-foundation.org', 'zfazli' => 'zahra.fazli@eclipse-foundation.org', 'webdev' => 'webdev@eclipse.org', 'cwitt' => 'christie.witt@eclipse-foundation.org' ); $Friend = $this->Session->getFriend(); $friend_uid = strtolower($Friend->getUID()); $friend_email = strtolower($Friend->getEmail()); $valid = FALSE; // Is the user an admin? foreach ($admins as $username => $email) { if ($friend_uid === $username && $friend_email === $email) { $valid = TRUE; break; } } return !empty($valid) ? TRUE : FALSE; } /** * Validate the user * - Check if the logged in user is a maintainer of the selected Member * - Check if the token submitted is valid * - Returns the state of the user ($user_state) * @param string * */ public function validateUser(){ $valid = FALSE; // Is the logged in user an admin? if ($this->isAdmin()) { $valid = TRUE; } // Is the user a maintainer? if (!$valid && $this->isMaintainer()) { $valid = TRUE; } // Is this a valid token for the user? if (!$valid && $this->validateToken()) { $valid = TRUE; } return !empty($valid) ? TRUE : FALSE; } /** * This function insert a new product in the OrganizationProducts table * */ private function _createMemberProduct(){ $productFields = array( 'org_id' => filter_var($this->App->getHTTPParameter("new_member_product_organization_id", "POST"), FILTER_SANITIZE_NUMBER_INT), 'name' => filter_var($this->App->getHTTPParameter("new_member_product_name", "POST"), FILTER_SANITIZE_STRING), 'description' => filter_var($this->App->getHTTPParameter("new_member_product_description", "POST"), FILTER_SANITIZE_STRING), 'url' => filter_var($this->App->getHTTPParameter("new_member_product_url", "POST"), FILTER_SANITIZE_URL) ); // Define default error message $message = ''; $message_type = 'danger'; // Check if id and url is not empty // Description can be empty if(empty($productFields['name'])){ $message .= 'ERROR, The Name field is empty.
'; } if(empty($productFields['url'])){ $message .= 'ERROR, The URL field is empty.
'; } if (!empty($productFields['url']) && !empty($productFields['name']) && !empty($productFields['org_id'])) { $sql = 'INSERT INTO OrganizationProducts (OrganizationID,name,description,product_url) VALUES ('. $this->App->returnQuotedString($this->App->sqlSanitize($productFields['org_id'])).','. $this->App->returnQuotedString($this->App->sqlSanitize($productFields['name'])).','. $this->App->returnQuotedString($this->App->sqlSanitize($productFields['description'])).','. $this->App->returnQuotedString($this->App->sqlSanitize($productFields['url'])). ')'; $result = $this->App->eclipse_sql($sql); $message = 'SUCCESS, a new link has been created.'; $message_type = 'success'; } // SET MESSAGE $this->setStatusMessage($message, $message_type); // Get the most up to date product data $this->_setMemberProduct($this->fetchMemberProducts()); $this->_redirectTo('#open_tab_edit-links'); } /** * Edit the Member products (links) * */ private function _editMemberProduct(){ $product = array( 'id' => filter_var($this->App->getHTTPParameter("member_product_id", "POST"), FILTER_SANITIZE_NUMBER_INT), 'name' => filter_var($this->App->getHTTPParameter("member_product_name", "POST"), FILTER_SANITIZE_STRING), 'description' => filter_var($this->App->getHTTPParameter("member_product_description", "POST"), FILTER_SANITIZE_STRING), 'url' => filter_var($this->App->getHTTPParameter("member_product_url", "POST"), FILTER_SANITIZE_URL) ); // Define default error message $message = 'ERROR, one of your fields is empty.'; $message_type = 'danger'; // Check if id and url is not empty // Description can be empty if(empty($product['name'])){ $message .= 'ERROR, The Name field is empty.
'; } if(empty($product['url'])){ $message .= 'ERROR, The URL field is empty.
'; } if (!empty($product['id']) && !empty($product['url']) && !empty($product['name'])) { $sql = 'UPDATE OrganizationProducts SET name = ' . $this->App->returnQuotedString($this->App->sqlSanitize($product['name'])) . ', description = ' . $this->App->returnQuotedString($this->App->sqlSanitize($product['description'])) . ', product_url = ' . $this->App->returnQuotedString($this->App->sqlSanitize($product['url'])) . ' WHERE ProductID = ' . $this->App->returnQuotedString($this->App->sqlSanitize($product['id'])); $result = $this->App->eclipse_sql($sql); $message = 'SUCCESS, your product has been changed.'; $message_type = 'success'; } // SET MESSAGE $this->setStatusMessage($message, $message_type); // Get the most up to date product data $this->_setMemberProduct($this->fetchMemberProducts()); $this->_redirectTo('#open_tab_edit-links'); } /** * Content of the Edit Page * @return string * */ private function _editPage(){ $token = $this->getToken(); if(!empty($token)) { $this->token_url = '&token=' . $token; } print '

Edit '. $this->getMemberName() .' Membership Page

'; print $this->getStatusMessage(); include($_SERVER['DOCUMENT_ROOT'] . '/membership/content/en_editMember.php'); } /** * This function deletes member products * */ private function _deleteMemberProduct(){ $product_id = filter_var($this->App->getHTTPParameter("member_product_id", "POST"), FILTER_SANITIZE_STRING); // Define default error message $message = 'ERROR, your link has not been deleted.'; $message_type = 'danger'; $is_part_of_product_list = FALSE; $products = $this->fetchMemberProducts(); foreach($products as $product){ if($product_id == $product['id']){ $is_part_of_product_list = TRUE; break; } } if($is_part_of_product_list && !empty($product_id)) { $sql = 'DELETE FROM OrganizationProducts WHERE ProductID = ' . $product_id; $result = $this->App->eclipse_sql($sql); $message = 'SUCCESS, your link has been deleted.'; $message_type = 'success'; } // SET MESSAGE $this->setStatusMessage($message, $message_type); // Get the most up to date product data $this->_setMemberProduct($this->fetchMemberProducts()); $this->_redirectTo('#open_tab_edit-links'); } /** * Update/Edit the Member's information * */ private function _editSelectedInformation(){ // Set the member's information $short_desc = filter_var($this->App->getHTTPParameter("member_short_description", "POST"), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); $long_desc = filter_var(strip_tags($this->App->getHTTPParameter("member_long_description", "POST"), '