function profileForm($form, &$form_state) { global $user; $params = drupal_get_query_parameters(); $new = true; if (isset($params["UID"])) { // editing a user other than the current one $UID = $params['UID']; } else { // user is editing him/her own profile $UID = $user->uid; } $data = dbGetUserProfile($UID); if (empty($data)) { // if the UID passed did not have any user data associated with it } else { $new = false; // editing a user which already exists } // beginning the form $form = array(); $form['fields'] = array('#type' => 'fieldset', '#title' => t('Edit: User Info')); $form['fields']['tableHeader'] = array('#markup' => '<table>'); // checking permissions $canEdit = false; $sharedTeams = getSharedTeams($UID); if (!empty($sharedTeams)) { foreach ($sharedTeams as $TID) { if (hasPermissionForTeam('manageTeamMembers', $TID)) { $canEdit = true; break; } } } // if the user is viewing his/her own profile, he/she should be able to edit it if ($user->uid == $UID) { $canEdit = true; } if (!$canEdit) { drupal_set_message("You don't have permission to edit this user.", 'error'); return; } if (!$new) { // if the profile is not new $form['fields']['back'] = array('#prefix' => '<left>', '#limit_validation_errors' => array(), '#submit' => array('backToProfile'), '#type' => 'submit', '#value' => '⇦ Cancel Changes', '#attributes' => array('OnSubmit' => 'if(!confirm("Back?")){return false;}'), '#suffix' => '</left>'); } $form['fields']['firstName'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('First Name'), '#default_value' => $new ? '' : $data['firstName'], '#suffix' => '</td>'); $form['fields']['lastName'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('Last Name'), '#default_value' => $new ? '' : $data['lastName'], '#suffix' => '</td></tr>'); $form['fields']['primaryEmail'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#markup' => "Primary Email <br>" . $user->mail, '#suffix' => '</td>'); if (!$new) { $secondaryEmail = dbGetSecondaryEmailForUser($UID); } $form['fields']['secondaryEmail'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('Secondary Email'), '#default_value' => $new ? '' : $secondaryEmail, '#suffix' => '</td></tr>'); $form['fields']['gender'] = array('#prefix' => '<tr><td colspan="2" style="text-align:center">', '#type' => 'radios', '#options' => array('Male' => 'Male', 'Female' => 'Female', 'Other' => 'Other'), '#title' => t('Gender'), '#default_value' => $new ? '' : $data['gender'], '#suffix' => '</td>'); $form['fields']['type'] = array('#prefix' => '<td colspan="2" style="text-align:center">', '#type' => 'radios', '#options' => array('student' => 'Student', 'mentor' => 'Mentor', 'alumni' => 'Alumni'), '#title' => t('Type'), '#default_value' => $new ? '' : $data['type'], '#suffix' => '</td>'); $form['fields']['grade'] = array('#prefix' => '<td colspan="2" style="text-align:center">', '#type' => 'select', '#options' => array('1' => '1st', '2' => '2nd', '3' => '3rd', '4' => '4th', '5' => '5th', '6' => '6th', '7' => '7th', '8' => '8th', '9' => '9th', '10' => '10th', '11' => '11th', '12' => '12th', '0' => 'N/A'), '#title' => t('Grade'), '#default_value' => $new ? '' : $data['grade'], '#chosen' => true, '#suffix' => '</td></tr>'); $form['fields']['phone'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('Phone Number'), '#default_value' => $new ? '' : $data['phone'], '#placeholder' => 'Format: XXXXXXXXXX', '#suffix' => '</td>'); $form['fields']['position'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('Team Position'), '#default_value' => $new ? '' : $data['position'], '#placeholder' => "i.e. Chairman's Presenter", '#suffix' => '</td></tr>'); $form['fields']['bio'] = array('#prefix' => '<tr><td colspan="6">', '#type' => 'textarea', '#title' => t('Short Bio'), '#default_value' => $new ? '' : $data['bio'], '#suffix' => '</td></tr>'); // end of inputting info into the form $form['fields']['tabling'] = array('#markup' => '</td></tr><tr>'); $form['fields']['tabling2'] = array('#markup' => '<td colspan="3"></td>'); $form['fields']['submit'] = array('#prefix' => '<td colspan="3" style="text-align:right">', '#type' => 'submit', '#value' => t('Save'), '#suffix' => '</td>'); $form['footer'] = array('#markup' => '</tr></table>'); return $form; }
function viewUser() { global $user; $currentUID = $user->uid; $params = drupal_get_query_parameters(); // checks that there is a user if (isset($params["UID"])) { $UID = $params["UID"]; } else { drupal_set_message('No user specified.', 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } // checks that the user being viewed shares a team with the user currently viewing if (!($UID == $currentUID || isOnMyTeam($UID))) { drupal_set_message("You can't view this profile.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } $profile = dbGetUserProfile($UID); $canEdit = false; $sharedTeams = getSharedTeams($UID); if (!empty($sharedTeams)) { foreach ($sharedTeams as $TID) { if (hasPermissionForTeam('manageTeamMembers', $TID)) { $canEdit = true; break; } } } if ($user->uid == $UID) { $canEdit = true; } $markup = ''; // create name header and table $markup .= '<div style="float:left; width:28%">'; $markup .= '<table style="margin:0px 0px 10px 0px;"><tr>'; $markup .= '<td style="padding:0px 14px 10px 14px;"><div align="left"><h2 style="margin:0px 0px 7px 0px;"><b>'; $markup .= $profile['firstName'] . ' ' . $profile['lastName']; $markup .= '</b></h2></div></td></tr></table>'; $markup .= '<table id="photoAndEdit"><tr><td style="padding:0px;">'; // if the profile belongs to the currently logged in user, the picture should be editable if ($canEdit) { $markup .= '<div align="right">'; $markup .= '<a href= "?q=editThumbnail'; $markup .= '&UID=' . $UID . '&FID=' . $profile['FID'] . '">'; $markup .= '<span title="Edit Photo"><button type="button"><img class="editIcon" src="/images/icons/editThumbnailWhite.png"></button></a></span>'; $markup .= '</div>'; } $markup .= '</td></tr><tr><td style="padding:0px;">'; // if user has picture, display picture if (!empty($profile['FID'])) { $url = generateURL($profile['FID']); $markup .= '<div align="center"><img src="' . $url . '" style="max-width:150px; width:auto; height:auto; padding: 5px 0px 5px 0px">'; // default picture if user does not have a picture } else { $markup .= '<div align="center"><img src="/images/defaultPics/user.png" style="max-width:200px; width:auto; height:auto; padding: 15px 0px 15px 0px">'; } $markup .= '</div></td></tr></table></div>'; $markup .= '<div align="right">'; // if user has permissions or owns the profile, edit info if ($canEdit) { $markup .= '<a href= "?q=profileForm'; $markup .= '&UID=' . $UID . '">'; $markup .= '<span title="Edit Profile"><button type="button"><img class="editIcon" src="/images/icons/editWhite.png"></button></a></span>'; } // if the user wants to change their own password - no one else can access this feature on someone's profile if ($UID == $currentUID) { $markup .= '<a href="?q=user/' . $UID . '/edit"'; $markup .= '<span title="Change Password"><button type="button"><img class="keyIcon" src="/images/icons/keyWhite.png"></button></a></span>'; } // users are only allowed to delete their own profiles if ($UID == $currentUID) { $markup .= '<span title="Delete User"><a href="?q=deleteUser&UID=' . $UID . '"><button type="button"><img class="trashIcon" src="/images/icons/trashWhite.png"></button></a></span>'; } $markup .= '</div>'; // begin displaying info portion $markup .= '<div style="width:70%; float:right; padding-left:10px">'; $markup .= '<table id="miniViewTeam" style="margin:16px 0px 0px 0px"><tr><td><b>Role: </b>' . ucfirst($profile['type']) . '</td>'; $markup .= '<td><b>Position: </b> ' . strip_tags($profile['position']) . '</td>'; if ($profile['grade'] == '0') { $markup .= '<tr><td><b>Grade: </b> N/A</td>'; } else { $markup .= '<tr><td><b>Grade: </b> ' . $profile['grade'] . '</td>'; } $markup .= '<td><b>Gender: </b> ' . $profile['gender'] . '</td></tr>'; $email = dbGetUserPrimaryEmail($UID); $markup .= '<tr><td><b>Email: </b> <a href="mailto:' . $email . '" target="_blank">'; $markup .= $email . '</a>'; $secondaryEmail = dbGetSecondaryEmailForUser($UID); if ($secondaryEmail) { $markup .= "<br>(" . '<a href="mailto:' . $secondaryEmail . '" target="_blank">' . $secondaryEmail . '</a>' . ')'; } $phoneNumber = dbFormatPhoneNumber($profile['phone']); $markup .= '</td><td><b>Phone: </b> ' . $phoneNumber . '</td></tr>'; // displays teams the user is on $teamNumbers = ''; $first = true; // used to put commas in the right places $teams = dbGetTeamsForUser($UID); foreach ($teams as $team) { if ($first) { $teamNumbers = '<a href="?q=viewTeam&TID=' . $team['TID'] . '">' . $team['number'] . '</a>'; $first = false; } else { $teamNumbers = $teamNumbers . ', <a href="?q=viewTeam&TID=' . $team['TID'] . '">' . $team['number'] . '</a>'; } } if (count($teams) > 1) { $teamLabel = 'Teams'; } else { $teamLabel = 'Team'; } if ($UID == $currentUID) { $markup .= '<tr><td><a href="?q=manageUserTeams"><b>' . $teamLabel . ':</b></a> ' . $teamNumbers . '</td>'; } else { $markup .= '<tr><td><b>' . $teamLabel . ':</b> ' . $teamNumbers . '</td>'; } // displays user hours $numberOfHours = dbGetUserHours($UID); if ($numberOfHours != 0) { $markup .= "<td><a href=\"?q=viewHours&UID={$UID}\"><b>Number of Hours:</b></a> {$numberOfHours}</td>"; } else { $markup .= "<td><b>Number of Hours:</b> No Hours!</td>"; } // displays user bio $markup .= '</table><table id="miniViewTeam" style="margin:16px 0px 0px 0px"><tr><td><b>Bio: </b>'; $markup .= wordwrap($profile['bio'], 92, "<br />\n") . '</td></tr>'; $markup .= '</table></div>'; return array("#markup" => $markup); }