コード例 #1
0
ファイル: ticket.php プロジェクト: 8dx/bugspray
                $error = true;
                $errors[] = 'Your comment could not be inserted. There may be a server error.';
            }
            // and our work here is done!
            if ($error) {
                output_errors($errors);
            } else {
                header("Location: {$_SERVER['REQUEST_URI']}");
                exit;
            }
        }
        // add to views
        db_query("UPDATE issues SET num_views = num_views + 1 WHERE id = '{$id}'");
        // who is the issue assigned to?
        if ($issue['assign'] > 0) {
            $issue['assignedto'] = getuinfo($issue['assign']);
        } else {
            $issue['assignedto'] = 'nobody';
        }
        // Get assignable users (for now, just admins)
        $assignsarr = array(array(0, 'nobody'), array(0, '----------------------'));
        foreach ($users->from_admins() as $uid) {
            $assignsarr[] = array($uid, getunm($uid), $uid == $issue['assign'] ? true : false);
        }
        $issue['assigns'] = $assignsarr;
        // get the comments
        $result_comments = db_query_toarray("SELECT * FROM comments WHERE issue = {$id} ORDER BY when_posted ASC", "Retrieving comments for issue {$id} from database");
        // output the page
        $page->include_template('ticket', array('issue' => $issue, 'comments' => $result_comments));
    }
}
コード例 #2
0
ファイル: users.php プロジェクト: 8dx/bugspray
 public function from_group()
 {
     $ret = array();
     $num = func_num_args();
     // Did we get nothing?
     if ($num < 1) {
         return $ret;
     } elseif ($num == 1) {
         $id = func_get_arg(0);
         if (is_numeric($id)) {
             $users = db_query_toarray("SELECT id FROM users WHERE `group` = {$id}", "Retrieving users from group {$id}");
             foreach ($users as $user) {
                 $ret[] = $user['id'];
             }
         } else {
             // todo: log an error
         }
     } else {
         foreach (func_get_args() as $id) {
             $ret = array_merge($ret, $this->from_group($id));
         }
     }
     return $ret;
 }
コード例 #3
0
ファイル: functions.php プロジェクト: 8dx/bugspray
/**
 * @version 0.4
 * @since 0.2
 */
function ticket_list($status, $order = 'desc', $pinfollowing = false)
{
    global $page, $users;
    if ($_COOKIE["current"] !== "") {
        $status = $_COOKIE["current"];
    }
    // Ah, the myriad of status filters
    switch ($status) {
        case 'unassigned':
            $whereclause = 'issues.status = 0';
            break;
        case 'assigned':
            $whereclause = 'issues.status = 2';
            break;
        case 'resolved':
            $whereclause = 'issues.status = 3';
            break;
        case 'postponed':
            $whereclause = 'issues.status = 4';
            break;
        case 'declined':
            $whereclause = 'issues.status = 5';
            break;
        case 'duplicate':
            $whereclause = 'issues.status = 6';
            break;
        case 'all':
            $whereclause = '1';
            break;
            // This seems to be okay, see http://stackoverflow.com/questions/1983655
        // This seems to be okay, see http://stackoverflow.com/questions/1983655
        case 'open':
        default:
            $status = 'open';
            $whereclause = '(issues.status = 0 OR issues.status = 1 OR issues.status = 2)';
            break;
    }
    // If we don't have a proper order defined, just make it descending
    $order = strtoupper($order);
    if ($order != 'ASC' || $order != 'DESC') {
        $order = 'DESC';
    }
    // Are we logged in?
    $l = $users->client->is_logged;
    // Alright, create our lovely little query [TODO(maybe): if possible, rewrite the subquery as a join]
    $query = '
		SELECT issues.*,
		       comments.author AS commentauthor,
			   ' . ($l ? 'favorites.userid AS favorited,' : '') . '
			   (SELECT COUNT(favoritescount.userid) FROM favorites AS favoritescount WHERE ticketid = issues.id) AS favoritecount
		FROM issues
		
		-- This join is used for getting the comment author
		LEFT JOIN comments
			ON comments.issue = issues.id AND comments.when_posted = issues.when_updated
		
		-- This one lets us find out whether the user has favourited the ticket or not
		' . ($l ? '
		LEFT JOIN favorites
			ON favorites.ticketid = issues.id AND favorites.userid = ' . $_SESSION['uid'] : '') . '
		
		WHERE ' . $whereclause . '
		
		ORDER BY issues.when_updated ' . $order;
    // And then run it!
    $result_tickets = db_query_toarray($query, false, 'Retrieving all tickets <code>WHERE ' . $whereclause . '</code>');
    // Do we want to pin tickets that the client has favourited or has assigned to them?
    if ($pinfollowing && $l) {
        // If so, we'll need another query to get those only
        $uid = $_SESSION['uid'];
        $query2 = str_replace('WHERE', 'WHERE ((favorites.ticketid = issues.id AND favorites.userid = ' . $uid . ') OR issues.assign = ' . $uid . ') AND ', $query);
        // And of course, run it
        $result_tickets2 = db_query_toarray($query2, false, 'Retrieving all tickets favourited or assigned to the client <code>WHERE ' . $whereclause . '</code>');
        // Have we got anything?
        $c2 = count($result_tickets2);
        if ($c2) {
            // We now have to take out all the non pinned tickets from the first query
            $result_tickets2_ids = array();
            for ($i = 0; $i < $c2; $i++) {
                // We get all the IDs for extraction
                $result_tickets2_ids[] = $result_tickets2[$i]['id'];
                // And for convenience, we'll also mark the ticket as pinned now
                $result_tickets2[$i]['pinned'] = true;
            }
            // Now for the actual removal
            $c = count($result_tickets);
            for ($i = 0; $i < $c; $i++) {
                // Do we have a matching ID?
                if (in_array($result_tickets[$i]['id'], $result_tickets2_ids)) {
                    unset($result_tickets[$i]);
                } else {
                    $result_tickets[$i]['pinned'] = false;
                }
            }
            // Since unset screws up indexes in arrays we'll need to fix them.
            $result_tickets = array_values($result_tickets);
            // We're done now, so we'll just join up the two arrays, et voila!
            $result_tickets = array_merge($result_tickets2, $result_tickets);
        }
    }
    // Look ma, extra variables
    $count = count($result_tickets);
    for ($i = 0; $i < $count; $i++) {
        // Is the issue favoUrited? (The database uses "favorite" because everyone favoUrs the americans)
        $result_tickets[$i]['favorite'] = $result_tickets[$i]['favorited'] ? true : false;
        // The classes of the ticket, of course, we just start off with "ticket"
        $classes = array('ticket');
        // The severity shall be addded something like .severity-0
        $classes[] = 'severity-' . $result_tickets[$i]['severity'];
        // Pinned ticket? Add the class!
        if ($result_tickets[$i]['pinned']) {
            $classes[] = 'pinned';
        }
        // Declined or resolved? Add the class!
        if (getstatustype($result_tickets[$i]['status']) == 'declined') {
            $classes[] = 'declined';
        } elseif (getstatustype($result_tickets[$i]['status']) == 'resolved') {
            $classes[] = 'resolved';
        }
        // And now we implode the classes into a nice string
        $result_tickets[$i]['classes'] = implode(' ', $classes);
    }
    // Status types
    $statuses = array(array('name' => 'Open', 'type' => 'open', 'sel' => $status == 'open' ? true : false), array('name' => 'Unassigned', 'type' => 'unassigned', 'sel' => $status == 'unassigned' ? true : false), array('name' => 'Assigned', 'type' => 'assigned', 'sel' => $status == 'assigned' ? true : false), array('name' => 'Resolved', 'type' => 'resolved', 'sel' => $status == 'resolved' ? true : false), array('name' => 'Postponed', 'type' => 'postponed', 'sel' => $status == 'postponed' ? true : false), array('name' => 'Declined', 'type' => 'declined', 'sel' => $status == 'declined' ? true : false), array('name' => 'All', 'type' => 'all', 'sel' => $status == 'all' ? true : false), array('name' => 'Duplicate', 'type' => 'duplicate', 'sel' => $status == 'duplicate' ? true : false));
    // And we're off!
    ob_start();
    $page->include_template('ticket_list', array('type' => $type, 'statuses' => $statuses, 'tickets' => $result_tickets));
    return ob_get_clean();
}