pub_defs.php 4.29 KB
Newer Older
1
<?php
Mike Hibler's avatar
Mike Hibler committed
2 3
#
# Copyright (c) 2008 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Mike Hibler's avatar
Mike Hibler committed
23
#
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

include_once("defs.php3");

function MayEditPub($user, $isadmin, $row) {
    global $TBDB_TRUST_LOCALROOT;
    if ($isadmin) 
        return true;
    if (!$user)
	return false;
    $uid_idx = $user->uid_idx();
    if ($uid_idx == $row['owner'] && $row['editable_owner'])
        return true;
    $pid = $row['project'];
    if ($pid == '') 
        return false;
    $proj = Project::LookupByPid($pid);
40 41
    if (!$proj)
	return false;
42 43 44
    return TBMinTrust($proj->UserTrust($user), $TBDB_TRUST_LOCALROOT);
}

45 46 47 48 49 50
$thesis_map = array(
	'thesis' => 'Thesis',
	'phd thesis' => 'PhD Thesis',
	'masters thesis' => "Master's Thesis",
	'bachelors thesis' => "Bachelor's Thesis");

51
function MakeBib($user, $isadmin, $r) {
52
    global $thesis_map;
53 54 55 56 57 58 59 60 61 62 63 64
    $res = '';
    if ($r['url'] != '')
        $res .= "<a href=\"" . $r['url'] . "\">";
    $res .= $r['title'];
    #if row[3][-1] != '.' and row[3][-1] != '?' and row[3][-1] != '!':
    $res .= ".";
    if ($r['url'] != '')
        $res .= "</a>";
    $res .= "\n";
    $res .= ' ' . $r['authors'];
    $res .= '.';
    $type = $r['type'];
Kevin Atkinson's avatar
Kevin Atkinson committed
65 66 67 68
    if ($type == "talk") {
	$res .= "Talk. ";
    }
    if ($type == "article" || $type == "talk") {
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
        $res .= ' <em>' . $r['conf'] . '</em>';
        if ($r['volume'] != '')
            $res .= ', Vol. ' . $r['volume'];
        if ($r['number'] != '') {
            if ($r['volume'] != '')
                $res .= ' No.';
            $res .= ' ' . $r['number'];
        }
        if ($r['pages'] != '')
            $res .= ', pages ' . $r['pages'];
        if ($r['where'] != '')
            $res .= ', ' . $r['where'];
    # if Tech report
    } else if ($type == 'techreport') {
        $res .= ' Technical Report '.  $r['number'];
        # Affiliation here, but can't for techreports because of our data
85 86
        if (!preg_match('/,/', $r['affil']))
            $res .= ', ' . $r['affil'];
87
    # if Thesis
88 89 90 91
    } else if (preg_match('/^([a-z]+ |)thesis$/', $type)) {
        $res .= ' '. $thesis_map[$type];
        if ($r['affil'] != '')
            $res .= ', ' . $r['affil'];
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
    }
    # Not an Article/Tech report/Thesis? Add nothing special (for now)

    if ($r['month_name'] != '' || $r['year'] != '')
        $res .= ', ';
    if ($r['month_name'] != '')
        $res .= $r['month_name'] . ' ';
    $res .= $r['year'];
    if (MayEditPub($user, $isadmin, $r)) {
#      $res .= " <a href=\"submitpub.php?idx=". $r['idx'] . "\" style=\"background:#ffffaa \">Edit</a>";
       $res .= " <a href=\"submitpub.php?idx=". $r['idx'] . "\" style=\"background:yellow\">Edit</a>";
    }
    return $res;
}

function MakeBibList($user, $isadmin, $query_result) {
    $res = '';
    $number = 1;
    $category = "\n\t xyz";
    while ($r = mysql_fetch_array($query_result)) {
	if ($category != $r['category']) {
	    if ($category != "\n\t xyz") {
		$res .= "</ol>\n";
	    }
	    $category = $r['category'];
	    if ($category == '')
                $category = 'Uncategorized';
	    $res .= "<h2>" . $category . "</h2>\n";
	    $res .= "<ol>\n";
	    $category = $r['category'];
	}
	$res .= "<li style=\"margin-bottom: 10pt\" value=$number>";
	$res .= MakeBib($user, $isadmin, $r);
	$res .= "</li>\n";
	$number++;
    }
    $res .= "</ol>\n";
    return $res;
}

function GetPubs($where_clause, $deleted_clause = '!`deleted`') {
    return DBQueryFatal("select p.*,m.month_name,if(category = '',1,0) as category_sort  from emulab_pubs as p natural join emulab_pubs_month_map as m where $where_clause and $deleted_clause order by category_sort,category,year desc,month desc,title");
}

?>