コード例 #1
0
ファイル: viewOutreach.php プロジェクト: ChapResearch/CROMA
function viewOutreach()
{
    global $user;
    $UID = $user->uid;
    $params = drupal_get_query_parameters();
    $markup = "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.js\"></script>";
    $markup .= '<script src="numberCounting.js"></script>';
    $markup .= '<h1>Outreach</h1><br>';
    // if doing a custom search
    if (isset($params['query']) && $params['query'] == 'search') {
        $sql = generateSearchSQL($_SESSION['searchParams'], $_SESSION['proxyFields']);
        $outreaches = dbSearchOutreach($sql, $_SESSION['proxyFields']);
        $header = '<h2>Custom Search Results (';
        $header .= empty($outreaches) ? '0' : count($outreaches);
        $header .= ' matches)</h2>';
    } else {
        if (isset($params['tag'])) {
            $_SESSION['searchParams'] = array('tags' => array($params['tag']));
            $_SESSION['proxyFields'] = array();
            $sql = generateSearchSQL($_SESSION['searchParams'], $_SESSION['proxyFields']);
            $outreaches = dbSearchOutreach($sql, $_SESSION['proxyFields']);
            $header = '<h2>Outreaches Tagged "' . dbGetTagName($params['tag']) . '"</h2>';
        } else {
            if (isset($params['owned'])) {
                $outreaches = dbGetOwnedOutreachForUser($UID);
                $header = '<h2>Outreaches I Own</h2>';
            } else {
                if (isset($params['signedUp'])) {
                    $outreaches = dbGetOutreachForUser($UID);
                    $header = '<h2>Outreaches I Am Signed Up For</h2>';
                } else {
                    if (isset($params['allTeamOutreach'])) {
                        $TID = getCurrentTeam()['TID'];
                        $_SESSION['searchParams'] = array('TID' => array('value' => $TID, 'matchType' => 'exact'));
                        $_SESSION['proxyFields'] = array(':TID' => $TID);
                        $sql = generateSearchSQL($_SESSION['searchParams'], $_SESSION['proxyFields']);
                        $outreaches = dbSearchOutreach($sql, $_SESSION['proxyFields']);
                        $teamName = dbGetTeamName($TID);
                        $header = "<h2>All Outreach for {$teamName}</h2>";
                    } else {
                        $_SESSION['searchParams'] = array();
                        $_SESSION['proxyFields'] = array();
                        $header = "<h2>No Search Selected</h2>";
                    }
                }
            }
        }
    }
    if (isset($_SESSION['searchParams']['teams']) && count($_SESSION['searchParams']['teams']) > 1) {
        $multipleTeamsInResult = true;
    } else {
        $multipleTeamsInResult = false;
    }
    $markup .= $header;
    // set $outreaches to an array rather than false (so that later functions don't have errors)
    if (empty($outreaches)) {
        $outreaches = array();
    }
    $totalFilterOutreaches = count($outreaches);
    $totalFilterHours = 0;
    foreach ($outreaches as &$outreach) {
        $outreach['hours'] = dbGetHoursForOutreach($outreach['OID']);
        $totalFilterHours += $outreach['hours'];
    }
    unset($outreach);
    $sortParam = isset($params["sort"]) ? $params['sort'] : 'name';
    $isAscending = isset($params['isAscending']) ? true : false;
    orderByValue($outreaches, $sortParam, $isAscending);
    // custom function (see helperFunctions.inc)
    $markup .= '<table style="margin:0px">';
    $markup .= '<tr><td style="padding:0px; text-align:left"><b>Outreaches with Current Filters: </b><span class="countUp">' . $totalFilterOutreaches . '</span></td>';
    $markup .= '<td style="padding:0px; text-align:right" align="right"><b>Hours with Current Filters: </b><span class="countUp">' . $totalFilterHours . '</span></td></tr>';
    $markup .= '<tr><td style="padding:0px" align="left">Sort By: ';
    // remove special params (since they should not be added every time)
    unset($params['isAscending']);
    unset($params['sort']);
    $markup .= sortHeader($sortParam, $params, $isAscending, 'Name', 'name', 'outreach') . ' | ';
    $markup .= sortHeader($sortParam, $params, $isAscending, 'Status', 'status', 'outreach') . ' | ';
    $markup .= sortHeader($sortParam, $params, $isAscending, 'Hours', 'hours', 'outreach') . ' | ';
    $markup .= sortHeader($sortParam, $params, $isAscending, 'Event Date', 'eventDate', 'outreach');
    $markup .= '</td><td style="padding:0px; text-align:right">';
    if (!isset($params['owned'])) {
        $markup .= '<a href="?q=outreach&owned"><div class="help tooltip4"><button>Owned</button><span id="helptext"; class="helptext tooltiptext4">Click here to sort by outreach you own.</span></div></a>';
    } else {
        $markup .= '<a href="?q=outreach&allTeamOutreach"><button>All Team Outreach</button></a>';
    }
    if (!isset($params['signedUp'])) {
        $markup .= '<a href="?q=outreach&signedUp"><div class="help tooltip3"><button>Signed Up</button><span id="helptext"; class="helptext tooltiptext3">Click here to sort by outreach you are signed up for.</span></div></a>';
    } else {
        $markup .= '<a href="?q=outreach&allTeamOutreach"><button>All Team Outreach</button></a>';
    }
    $markup .= '</td></tr></table>';
    $markup .= '<table class="infoTable" style="margin:0px"><tr><th colspan="2">Status</th>';
    if ($multipleTeamsInResult) {
        $markup .= '<th colspan="2">Team</th>';
    }
    $markup .= '<th colspan="4">Name</th>';
    $markup .= '<th colspan="2">Hours</th>';
    $markup .= '<th colspan="2">Event Date</th>';
    if (empty($outreaches)) {
        $markup .= '<tr><td colspan="11">No outreach found! Click <a href="?q=outreachForm">here</a> to create new outreach!</td></tr></table>';
        return array('#markup' => $markup);
    }
    foreach ($outreaches as $outreach) {
        $OID = $outreach['OID'];
        $hours = dbGetHoursForOutreach($OID);
        $status;
        switch ($outreach['status']) {
            case 'isOutreach':
                $status = '<span title="Outreach Event"><img class="eventIndicatorIcon" src="/images/icons/outreachBlue.png"></span>';
                break;
            case 'isIdea':
                $status = '<span title="Idea"><img class="eventIndicatorIcon" src="/images/icons/ideaBlue.png"></span>';
                break;
            case 'doingWriteUp':
                $status = '<span title="Write Up"><img class="eventIndicatorIcon" src="/images/icons/writeUpBlue.png"></span>
';
                break;
            case 'locked':
                $status = '<span title="Locked Event"><img class="eventIndicatorIcon" src="/images/icons/lockedBlue.png"></span>';
                break;
            default:
                drupal_set_message('Invalid outreach data.');
                break;
        }
        $markup .= '<tr><td colspan="2" style="padding: 0px 0px 0px 14px;">';
        $markup .= showOutreachStatusIcon($outreach['status']) . '</td>';
        if ($multipleTeamsInResult) {
            $markup .= '<td colspan="2"><a href="?q=viewTeam&TID=' . $outreach['TID'] . '">' . dbGetTeamNumber($outreach['TID']) . '</a></td>';
        }
        $markup .= '<td colspan="4"><a href="?q=viewOutreach&OID=' . $OID . '">' . chopString($outreach['name'], 15) . '</a></td>';
        $markup .= '<td colspan="2">' . $hours . '</td>';
        if (dbGetEarliestTimeForOutreach($OID) != false) {
            $markup .= '<td colspan="2">' . date(TIME_FORMAT, dbDateSQL2PHP(dbGetEarliestTimeForOutreach($OID))) . '</td>';
        } else {
            $markup .= '<td colspan="2">[none]</td>';
        }
    }
    $markup .= '</table>';
    return array('#markup' => $markup);
}
コード例 #2
0
ファイル: manageTags.php プロジェクト: ChapResearch/CROMA
function tagManager($form, &$form_state)
{
    $team = getCurrentTeam();
    $form_state['TID'] = $TID = $team['TID'];
    if (teamIsIneligible($TID)) {
        drupal_set_message('Your team does not have permission to access this page.', 'error');
        drupal_goto($_SERVER['HTTP_REFERER']);
    }
    $currentURL = getCurrentURL();
    // if browser didn't end up here by coming from the current page
    if ($currentURL != getAjaxURL() && (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $currentURL)) {
        switchTagEditMode(false);
        // be sure to start with just viewing the tags
        if (!empty(drupal_get_query_parameters())) {
            // clear any other drupal_query_parameters
            drupal_goto(parseURLAlias($_SERVER['QUERY_STRING']));
        }
    }
    $markup = "<h1>Team {$team['number']} Outreach Settings</h1>";
    $editMode = checkTagEditMode();
    // create the wrapper-div used by AJAX
    $form['tags'] = array('#prefix' => '<div id="tags-div">', '#suffix' => '</div>');
    $tableHeader = '<table><tr><td><div class="help tooltip2"><h2>Outreach Tags</h2><span id="helptext"; class="helptext tooltiptext2">Outreach Tags are used to tag similar outreaches.</span></div></td><td><div align="right">';
    $form['tags']['tableHeader'] = array('#markup' => $tableHeader);
    // only show edit button if in "view mode" and the user has proper permissions
    if (!$editMode && hasPermissionForTeam('manageOutreachTags', $TID)) {
        $form['tags']['buttons'] = array('#type' => 'image_button', '#src' => '/images/icons/editWhite.png', '#attributes' => array('class' => array('editIcon')), '#limit_validation_errors' => array(), '#submit' => array('switchTagEditMode'));
    }
    // finish off the title and buttons table, then start the table for the tags themselves
    $tableHeader2 = '</div></td></tr></table>';
    $tableHeader2 .= '<table class="infoTable"><tr><th>Tag Name</th>';
    if (!$editMode) {
        $tableHeader2 .= '<th style="text-align:center">Matched Outreaches</th>';
    } else {
        $tableHeader2 .= '<th></th><th></th>';
    }
    $form['tags']['tableHeader2'] = array('#markup' => $tableHeader2);
    $tags = dbGetOutreachTagsForTeam($TID);
    if (!$editMode) {
        // if in "view" mode (aka not acting as a form)
        $tableContents = '';
        $tableContents .= '</tr>';
        if (!empty($tags)) {
            foreach ($tags as $OTID => $tagName) {
                // display the name
                $tableContents .= '<tr><td>' . $tagName . '</td>';
                // show the number of matching outreaches (which can be clicked on to search the outreach form by tags)
                $numMatched = dbGetOutreachMatchingTags(array($tagName), $TID, true);
                // "true" indicates only a count is returned
                $tableContents .= "<td style=\"text-align:center\"><a href=\"?q=outreach&tag={$OTID}\">{$numMatched}</a></td></tr>";
            }
        } else {
            $tableContents = '<tr><td colspan="2" style="text-align:center"><em>[None]</em></td></tr>';
        }
        $form['tags']['tableContents'] = array('#markup' => $tableContents);
    } else {
        // -------------------------------- in "edit" mode
        $i = 0;
        if (!empty($tags)) {
            foreach ($tags as $OTID => $tagName) {
                $i++;
                $form['tags']["tagName-{$i}"] = array('#prefix' => '<tr><td colspan="2">', '#type' => 'textfield', '#maxlength' => 50, '#default_value' => $tagName, '#suffix' => '</td>');
                $numMatching = dbGetOutreachMatchingTags(array(dbGetTagName($OTID)), $TID, true);
                $confirmBoxJS = '';
                if ($numMatching > 0) {
                    $confirmBoxJS = "if(!confirm('This tag matches {$numMatching} outreach(es). Are you sure you want to delete it?')){return false;}";
                }
                $form['tags']["deleteBttn-{$i}"] = array('#prefix' => "<td><a href=\"?q=deleteTag/{$OTID}/{$TID}\">", '#markup' => "<button onclick=\"{$confirmBoxJS}\" type=\"button\"><img src=\"/images/icons/trashWhite.png\" class=\"trashIcon\"></button>", '#suffix' => '</a></td></tr>');
                $form_state["OTID-{$i}"] = $OTID;
            }
            // end of foreach
        }
        // end of if
        $form_state['numTags'] = $i;
        // initialize the 'numNewRows' variable
        if (empty($form_state['numNewRows'])) {
            $form_state['numNewRows'] = 1;
        }
        $x;
        // PHP is weird and makes you declare a variable before the loop
        // create the empty row for creating new tags
        for ($x = 1; $x <= $form_state['numNewRows']; $x++) {
            // have to be sure to not overwrite anything
            // create row to allow entry of a new tag
            $form['tags']["newTagName-{$x}"] = array('#prefix' => '<tr><td>', '#type' => 'textfield', '#maxlength' => 50, '#suffix' => '</td>');
            // if this is the last row (and not the only row), add a "-" button
            if ($form_state['numNewRows'] > 1 && $x == $form_state['numNewRows']) {
                $form['tags']["newRemoveBttn-{$x}"] = array('#prefix' => '<td>', '#type' => 'submit', '#submit' => array('removeTagRow'), '#value' => '-', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'modifyTagRows_callback', 'wrapper' => 'tags-div'), '#suffix' => '</td>');
            } else {
                // add a placeholder instead of the "-" button
                $form['tags']["removeBttnPlaceHolder-{$x}"] = array('#markup' => '<td></td>');
            }
            // if this is the last row, add a "+" button
            if ($x == $form_state['numNewRows']) {
                $form['tags']["newAddBttn-{$x}"] = array('#prefix' => '<td>', '#type' => 'submit', '#submit' => array('addTagRow'), '#value' => '+', '#limit_validation_errors' => array(), '#ajax' => array('callback' => 'modifyTagRows_callback', 'wrapper' => 'tags-div'), '#suffix' => '</td>');
            } else {
                // add a placeholder instead of the "+" button
                $form['tags']["addBttnPlaceHolder-{$x}"] = array('#markup' => '<td></td>');
            }
            $for['tags']["rowFooter-{$x}"] = array('#markup' => '</tr>');
        }
        // end of for loop
    }
    // end of else (aka edit mode code)
    $form['tags']['tableFooter'] = array('#markup' => '</table>');
    // allow the user to cancel and return to the previous page
    // (note that the URL for cancel has a random extra parameter to ensure the mode is changed to view)
    if ($editMode) {
        $form['cancel'] = array('#prefix' => '<table><tr><td style="text-align:left">', '#markup' => '<a href="?q=teamOutreachSettings&notEdit"><button type="button">Cancel</button></a>', '#suffix' => '</td>');
        $form['submit'] = array('#prefix' => '<td style="text-align:right">', '#type' => 'submit', '#value' => 'Confirm', '#suffix' => '</td></tr></table>');
    }
    return $form;
}