function publicOutreach($form, &$form_state) { global $user; $UID = $user->uid; $TID = getCurrentTeam()['TID']; $outreaches = dbGetLockedOutreachForTeam($TID); // checking to make sure user has permission to change team outreach settings if (!hasPermissionForTeam('editAnyOutreach', $TID)) { drupal_set_message("You don't have permission to change outreach settings for this team.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } // checking to see if the user has a team assigned if (dbGetTeamsForUser($user->uid) == false) { drupal_set_message("You don't have a team assigned.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } // checking to see if the user is approved for the team if (!dbIsUserApprovedForTeam($UID, $TID)) { drupal_set_message("You aren't approved for this team.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } // checking to see if the team is active if (dbGetStatusForTeam($TID) == "0" || dbGetStatusForTeam($TID) == false) { drupal_set_message("This team isn't active/approved.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } $names = array(); $data = array(); // if team has locked outreaches if (!empty($outreaches)) { foreach ($outreaches as $outreach) { $names[$outreach['OID']] = $outreach['name']; if ($outreach['isPublic']) { $data[] = $outreach['OID']; } } } // begin form $form = array(); $form['fields'] = array('#type' => 'fieldset', '#title' => t('Changing Visibilities For ' . dbGetTeamNumber($TID))); $new = false; // cancel changes button doesn't save anything and goes back to team outreach settings if (!$new) { $form['fields']['back'] = array('#prefix' => '<left>', '#limit_validation_errors' => array(), '#submit' => array('backToSettings'), '#type' => 'submit', '#value' => '⇦ Cancel Changes', '#attributes' => array('OnSubmit' => 'if(!confirm("Back?")){return false;}'), '#suffix' => '</left>'); } // if the team has locked outreaches if (!empty($outreaches)) { $form['fields']['outreaches'] = array('#prefix' => '<table><tr><td>', '#type' => 'checkboxes', '#title' => t('<h5>Which outreaches would you like to make public?</h5>'), '#options' => $names, '#default_value' => $data, '#suffix' => '</td></tr><tr><td><br>Only showing outreaches which are "locked".</td></tr>', '#checkall' => true); $form['fields']['footer'] = array('#markup' => '</table>'); $form['fields']['submit'] = array('#prefix' => '<table><tr><td colspan="3" style="text-align:right">', '#type' => 'submit', '#value' => t('Save'), '#suffix' => '</td></tr></table>'); } else { // if the team does not have any locked outreaches $form['fields']['outreaches'] = array('#prefix' => '<table><tr><td colspan="3" style="text-align:left">', '#markup' => "Your team doesn't have any locked outreaches. All locked outreaches are displayed on this page. If you make a locked outreach public, it becomes visible on the outreach directory widget.<br>", '#suffix' => '</td></tr></table>'); } return $form; }
function outreachForm($form, &$form_state) { global $user; $UID = $user->uid; $params = drupal_get_query_parameters(); $currentTeam = getCurrentTeam(); $TID = $currentTeam['TID']; $form_state['TID'] = $TID; $new = $form_state['new'] = true; if (teamIsIneligible($TID)) { drupal_set_message('Your team does not have permission to access this page.', 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } if (isset($params["OID"])) { $form_state['OID'] = $params['OID']; $new = $form_state['new'] = false; $outreach = dbGetOutreach($params["OID"]); $times = dbGetTimesForOutreach($params["OID"]); // set to display all times $form_state['numRows'] = count($times); // record how many were there before (in case user deletes one) $form_state['initialNumTimes'] = count($times); $TID = $outreach['TID']; $form_state['TID'] = $TID; } $form = array(); // if the user is editing an old outreach if (!$new) { // menu hook to duplicate outreach $confirmBoxJS = "if(!confirm('Are you sure you want to duplicate this outreach? Any changes you made just now will NOT be saved.')){return false;}"; $form['duplicate'] = array('#prefix' => "<div style=\"text-align:right\"><a href=\"?q=duplicateOutreach/{$form_state['OID']}/{$TID}\">", '#markup' => "<button onclick=\"{$confirmBoxJS}\" type=\"button\">Duplicate</button>", '#suffix' => '</a>'); } if (!$new) { // menu hook to cancel the outreach if ($outreach["cancelled"]) { $confirmBoxJS = "if(!confirm('Are you sure you want to uncancel this outreach for the team?')){return false;}"; $form['cancel'] = array('#prefix' => "<a href=\"?q=cancelOutreach/{$form_state['OID']}/{$TID}\">", '#markup' => "<button onclick=\"{$confirmBoxJS}\" type=\"button\">Uncancel Outreach</button>", '#suffix' => '</a></div>'); } else { $confirmBoxJS = "if(!confirm('Are you sure you want to cancel this outreach for the team? This will remove the outreach from current team use.')){return false;}"; $form['cancel'] = array('#prefix' => "<a href=\"?q=cancelOutreach/{$form_state['OID']}/{$TID}\">", '#markup' => "<button onclick=\"{$confirmBoxJS}\" type=\"button\">Cancel From Team Use</button>", '#suffix' => '</a></div>'); } } $teamNumb = dbGetTeamNumber($TID); // form title $form['fields'] = array('#type' => 'fieldset', '#title' => t('Add Outreach: Team ' . '<b>' . $teamNumb . '</b>')); // if editing an outreach, then allow a user to cancel changes if (!$new) { $form['fields']['back'] = array('#prefix' => '<left>', '#limit_validation_errors' => array(), '#submit' => array('backToEvent'), '#type' => 'submit', '#value' => '⇦ Cancel Changes', '#attributes' => array('OnSubmit' => 'if(!confirm("Back?")){return false;}'), '#suffix' => '</left>'); } $form['fields']['markupOne'] = array('#markup' => '<table>'); // displays the name of the outreach editing $form['fields']['name'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('Outreach Name:'), '#default_value' => $new ? '' : $outreach['name'], '#placeholder' => 'Name of the event', '#attributes' => array('onsubmit' => 'return false'), '#suffix' => '</td>'); $tags = dbGetOutreachTagsForTeam($TID); // notifies a user to create outreach tags if the team doesn't have any if (empty($tags)) { if (hasPermissionForTeam('manageOutreachTags', $TID)) { $msg = 'Click <a href="?q=teamOutreachSettings"><b>here</b></a> to change your settings.'; } else { $msg = 'Please have a team admin or owner set up tags for your team.'; } drupal_set_message('To give the outreach a tag, you need to set up the tag options for your team! ' . $msg, 'error'); $form['fields']['tags'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#markup' => 'Tags:<br><em>You have no available tags.</em>', '#suffix' => '</td></tr>'); } else { // allows a user to add tags to the outreach if (!$new) { // get only OTID's to satisfy select field $oldTags = dbGetTagsForOutreach($form_state['OID'], true); } $form['fields']['tags'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#type' => 'select', '#id' => 'tags_field', '#title' => t('Tags:'), '#options' => $tags, '#default_value' => $new ? '' : $oldTags, '#chosen' => true, '#multiple' => true, '#suffix' => '</td></tr>'); } // allows a user to change the status of the outreach if they have permission if (hasPermissionForTeam('manageOutreachTags', $TID)) { $form['fields']['status'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'select', '#default_value' => $new ? 'Select' : $outreach['status'], '#options' => array('isIdea' => 'Idea', 'isOutreach' => 'Outreach', 'doingWriteUp' => 'Write-Up', 'locked' => 'Locked'), '#title' => t('Status:'), '#chosen' => true, '#suffix' => '</td>'); // if the user doesn't have permission, then the status of isIdea displays idea } else { if (!$new && $outreach['status'] == 'isIdea') { $form['fields']['status'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'select', '#title' => t('Status:'), '#options' => array('isIdea' => 'Idea'), '#default_value' => 'isIdea', '#disabled' => true, '#suffix' => '</td>'); // if the user doesn't have permission, then the status of isOutreach displays outreach } else { if (!$new && $outreach['status'] == 'isOutreach') { $form['fields']['status'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'select', '#title' => t('Status:'), '#options' => array('isOutreach' => 'Outreach'), '#default_value' => 'isOutreach', '#disabled' => true, '#suffix' => '</td>'); // if the user doesn't have permission, then the status of doingWriteUp displays write-up } else { if (!$new && $outreach['status'] == 'doingWriteUp') { $form['fields']['status'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'select', '#title' => t('Status:'), '#options' => array('doingWriteUp' => 'Write-Up'), '#default_value' => 'doingWriteUp', '#disabled' => true, '#suffix' => '</td>'); // if the user doesn't have permission, then the status of locked displays locked } else { if (!$new && $outreach['status'] == 'locked') { $form['fields']['status'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'select', '#title' => t('Status:'), '#options' => array('locked' => 'Locked'), '#default_value' => 'locked', '#disabled' => true, '#suffix' => '</td>'); // if the user doesn't have permission, then the events created can only have a status of idea } else { $form['fields']['status'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'select', '#default_value' => $new ? 'Select' : $outreach['status'], '#options' => array('isIdea' => 'Idea'), '#title' => t('Status:'), '#chosen' => true, '#suffix' => '</td>'); } } } } } // allows a user to go to team outreach settings $form['fields']['manageTagsBttn'] = array('#prefix' => '<td colspan ="3" style="text-align:center">', '#markup' => '<a href="?q=teamOutreachSettings" target="_blank"><button type="button">Manage Tags</button></a>', '#suffix' => '</td></tr>'); $form['fields']['description'] = array('#prefix' => '<tr><td colspan="6" style="text-align:center">', '#type' => 'textarea', '#title' => t('Description:'), '#default_value' => $new ? '' : $outreach['description'], '#placeholder' => 'Maximum of 500 characters', '#suffix' => '</td></tr>', '#maxlength_js' => 'TRUE', '#maxlength' => '500'); $form['fields']['address'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t('Address:'), '#default_value' => $new ? '' : $outreach['address'], '#suffix' => '</td>'); $team = dbGetTeam($TID); // default value from the team form $form['fields']['city'] = array('#prefix' => '<td colspan="1" style="text-align:center">', '#type' => 'textfield', '#title' => t('City:'), '#default_value' => $new ? $team['city'] : $outreach['city'], '#suffix' => '</td></tr>'); $form['fields']['state'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'select', '#title' => t('State:'), '#options' => states_list(), '#default_value' => $new ? $team['state'] : $outreach['state'], '#chosen' => true, '#suffix' => '</td>'); $form['fields']['country'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#type' => 'select', '#title' => t('Country:'), '#options' => countries_list(), '#default_value' => $new ? $team['country'] : $outreach['country'], '#chosen' => true, '#suffix' => '</td></tr>'); $form['fields']['co_firstName'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t("Host Contact's First Name:"), '#default_value' => $new ? '' : $outreach['co_firstName'], '#placeholder' => 'Contact for this outreach', '#suffix' => '</td>'); $form['fields']['co_lastName'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t("Host Contact's Last Name:"), '#default_value' => $new ? '' : $outreach['co_lastName'], '#suffix' => '</tr>'); $form['fields']['co_phoneNumber'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t("Host Contact's Phone Number:"), '#default_value' => $new ? '' : $outreach['co_phoneNumber'], '#placeholder' => 'Format: XXXXXXXXXX', '#suffix' => '</td>'); $form['fields']['co_email'] = array('#prefix' => '<td colspan="3" style="text-align:center">', '#type' => 'textfield', '#title' => t("Host Contact's Email:"), '#default_value' => $new ? '' : $outreach['co_email'], '#placeholder' => 'Email of outreach contact', '#suffix' => '</td></tr>'); $form['fields']['co_organization'] = array('#prefix' => '<tr><td colspan="6" style="text-align:center">', '#type' => 'textfield', '#title' => t("Host Organization:"), '#default_value' => $new ? '' : $outreach['co_organization'], '#placeholder' => 'Group participating with for this outreach', '#suffix' => '</td></tr>'); // allows a user to add dates to an outreach if (empty($form_state['numRows'])) { $form_state['numRows'] = 1; } $form['fields']['datesHeader'] = array('#markup' => '<tr><td colspan="6">'); $form['fields']['dates']['header'] = array('#markup' => '<div id="dates-div"><table>'); $date = date(DEFAULT_TIME_FORMAT, strtotime('today noon')); for ($i = 0; $i < $form_state['numRows']; $i++) { $form['fields']['dates']["openFieldOfStart-{$i}"] = array('#markup' => '<tr><td colspan="2" align="left" style="text-align:left">'); if (!empty($times)) { $startTime = date(DEFAULT_TIME_FORMAT, dbDateSQL2PHP($times[$i]['startTime'])); } $form['fields']['dates']["startTime-{$i}"] = array('#type' => 'date_popup', '#title' => t('Start Date:'), '#default_value' => !isset($startTime) ? $date : $startTime, '#date_format' => TIME_FORMAT, '#date_label_position' => 'within', '#date_increment' => 1, '#date_year_range' => '-20:+20', '#datepicker_options' => array(), '#states' => array('invisible' => array(':input[name="status"]' => array('value' => 'isIdea')))); if (!$new) { $form_state['fields']['dates']["TOID-{$i}"] = $times[$i]['TOID']; } $form['fields']['dates']["closeFieldOfStart-{$i}"] = array('#markup' => '</td>'); $form['fields']['dates']["openFieldOfEnd-{$i}"] = array('#markup' => '<td colspan="2" align="right" style="text-align:left">'); if (!empty($times)) { $endTime = date(DEFAULT_TIME_FORMAT, dbDateSQL2PHP($times[$i]['endTime'])); } $form['fields']['dates']["endTime-{$i}"] = array('#type' => 'date_popup', '#title' => t('End Date:'), '#default_value' => !isset($endTime) ? $date : $endTime, '#date_format' => TIME_FORMAT, '#date_label_position' => 'within', '#date_increment' => 1, '#date_year_range' => '-20:+20', '#datepicker_options' => array(), '#states' => array('invisible' => array(':input[name="status"]' => array('value' => 'isIdea')))); $form['fields']['dates']["closeFieldOfEnd-{$i}"] = array('#markup' => '</td>'); if ($i == $form_state['numRows'] - 1) { $form['fields']['dates']["addRowButton-{$i}"] = array('#prefix' => '<td colspan="1" style="text-align:center">', '#type' => 'submit', '#submit' => array('addDateRow'), '#value' => '+', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'modifyDateRows_callback', 'wrapper' => 'dates-div'), '#states' => array('invisible' => array(':input[name="status"]' => array('value' => 'isIdea'))), '#suffix' => '</td>'); } if ($i == $form_state['numRows'] - 1) { $form['fields']['dates']["removeRowButton-{$i}"] = array('#prefix' => '<td colspan="1" style="text-align:center">', '#type' => 'submit', '#submit' => array('removeDateRow'), '#value' => '-', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'modifyDateRows_callback', 'wrapper' => 'dates-div'), '#states' => array('invisible' => array(':input[name="status"]' => array('value' => 'isIdea'))), '#suffix' => '</td>'); } $form['fields']['dates']["rowFooter-{$i}"] = array('#markup' => '</tr>'); } // end of for loop $form['fields']['dates']["divFooter-{$i}"] = array('#markup' => '</table></div></td>'); // allows the user to change the outreach visibility if the status is locked if (!$new && $outreach["status"] == "locked") { $isPublicOptions = array(0 => t('Private'), 1 => t('Public')); $form['fields']['isPublic'] = array('#prefix' => '<tr><td colspan="3" style="text-align:center">', '#type' => 'radios', '#title' => t('Set Event Visibility'), '#options' => $isPublicOptions, '#default_value' => $new ? '1' : $outreach['isPublic'], '#suffix' => '</td></tr>'); } $form['fields']['submit'] = array('#prefix' => '<tr><td colspan="6" style="text-align:right">', '#type' => 'submit', '#value' => t('Save'), '#sorted' => false, '#suffix' => '</td></tr>'); $form['fields']['finalFooter'] = array('#markup' => '</table>'); if (!$new && !(hasPermissionForTeam('editAnyOutreach', $TID) || isMyOutreach($params['OID']))) { drupal_set_message("You don't have permission to edit this outreach.", 'error'); drupal_goto('viewOutreach', array('query' => array('OID' => $params['OID']))); } if (dbGetTeamsForUser($user->uid) == NULL) { drupal_set_message("You don't have a team assigned.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } if (!dbIsUserApprovedForTeam($UID, $TID)) { drupal_set_message("You aren't approved for this team.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } if (dbGetStatusForTeam($TID) == "0" || dbGetStatusForTeam($TID) == FALSE) { drupal_set_message("This team isn't active/approved.", 'error'); drupal_goto($_SERVER['HTTP_REFERER']); } return $form; }