myprofiles.php 6.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<?php
#
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
# 
# {{{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/>.
# 
# }}}
#
chdir("..");
include("defs.php3");
chdir("apt");
include("quickvm_sup.php");
$page_title = "My Profiles";

#
# Verify page arguments.
#
$optargs = OptionalPageArguments("target_user",   PAGEARG_USER,
34
				 "all",           PAGEARG_BOOLEAN);
35 36 37 38 39

#
# Get current user.
#
RedirectSecure();
40 41
$this_user = CheckLoginOrRedirect();

42 43 44 45 46
if (!isset($target_user)) {
    $target_user = $this_user;
}
if (!$this_user->SameUser($target_user)) {
    if (!ISADMIN()) {
47 48
	SPITUSERERROR("You do not have permission to view ".
		      "target user's profiles");
49 50 51 52 53
	exit();
    }
}
$target_idx = $target_user->uid_idx();

54 55
SPITHEADER(1);

56
echo "<link rel='stylesheet'
57
            href='css/tablesorter.css'>\n";
58

Leigh B Stoller's avatar
Leigh B Stoller committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
$whereclause = "where v.creator_idx='$target_idx'";
$joinclause  = "";
$orderclause = "";

if (isset($all)) {
    if (ISADMIN()) {
	$whereclause = "";
    }
    else {
	$joinclause =
	    "left join group_membership as g on ".
	    "     g.uid_idx='$target_idx' and ".
	    "     g.pid_idx=v.pid_idx and g.pid_idx=g.gid_idx";
	$whereclause =
	    "where p.public=1 or p.shared=1 or v.creator_idx='$target_idx' or ".
	    "      g.uid_idx is not null ";
    }
}

78
$query_result =
Leigh B Stoller's avatar
Leigh B Stoller committed
79 80
    DBQueryFatal("select p.*,v.*,DATE(v.created) as created ".
		 "   from apt_profiles as p ".
81
		 "left join apt_profile_versions as v on ".
Leigh B Stoller's avatar
Leigh B Stoller committed
82 83 84 85
		 "     v.profileid=p.profileid and ".
		 "     v.version=p.version ".
		 "$joinclause ".
		 "$whereclause order by v.creator");
86 87

if (mysql_num_rows($query_result) == 0) {
88 89 90 91
    $message = "<b>No profiles to show you. Maybe you want to ".
	"<a href='manage_profile.php'>create one?</a></b><br><br>";

    if (ISADMIN()) {
92
	$message .= "<img src='images/redball.gif'>".
93 94 95
	    "<a href='myprofiles.php?all=1'>Show all user Profile</a>";
    }
    SPITUSERERROR($message);
96 97
    exit();
}
98 99 100 101 102 103 104 105 106 107 108 109
echo "<div class='row'>
       <div class='col-lg-12 col-lg-offset-0
                   col-md-12 col-md-offset-0
                   col-sm-12 col-sm-offset-0
                   col-xs-12 col-xs-offset-0'>\n";

echo "<input class='form-control search' type='search'
             id='profile_search' placeholder='Search'>\n";

echo "  <table class='tablesorter'>
         <thead>
          <tr>
Leigh B Stoller's avatar
Leigh B Stoller committed
110 111 112
           <th>Name</th>
           <th>&nbsp</th>
           <th>&nbsp</th>\n";
113 114 115 116
if (isset($all) && ISADMIN()) {
    echo " <th>Creator</th>";
}
echo "     <th>Project</th>
117 118
           <th>Description</th>
           <th>Created</th>
119 120
           <th>Listed</th>
           <th>Privacy</th>
121 122 123
          </tr>
         </thead>
         <tbody>\n";
124 125

while ($row = mysql_fetch_array($query_result)) {
126 127 128
    $idx     = $row["profileid"];
    $uuid    = $row["uuid"];
    $version = $row["version"];
129 130 131
    $name    = $row["name"];
    $pid     = $row["pid"];
    $desc    = $row["description"];
132
    $created = DateStringGMT($row["created"]);
133
    $public  = $row["public"];
134 135
    $listed  = ($row["listed"] ? "Yes" : "No");
    $shared  = $row["shared"];
136
    $creator = $row["creator"];
137 138 139 140 141 142 143 144
    $rspec   = $row["rspec"];

    if ($public)
	$privacy = "Public";
    elseif ($shared)
	$privacy = "Shared";
    else
	$privacy = "Private";
145 146 147 148 149 150

    $parsed_xml = simplexml_load_string($rspec);
    if ($parsed_xml &&
	$parsed_xml->rspec_tour && $parsed_xml->rspec_tour->description) {
	$desc = $parsed_xml->rspec_tour->description;
    }
151 152
    
    echo " <tr>
Leigh B Stoller's avatar
Leigh B Stoller committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
            <td>$name</td>\n";

    if ($creator == $this_user->uid() || ISADMIN()) {
	echo " <td style='text-align:center'>
             <a class='btn btn-primary btn-xs' type='button'
                href='manage_profile.php?action=edit&uuid=$uuid'>Edit</a>
            </td>\n";
    }
    else {
	echo " <td style='text-align:center'>
             <a class='btn btn-primary btn-xs' type='button'
                href='manage_profile.php?action=copy&uuid=$uuid'>Copy</a>
            </td>\n";
    }
    echo "<td style='text-align:center'>
             <button class='btn btn-primary btn-xs showtopo_modal_button'
                     data-profile=$uuid>Topo</button>
            </td>\n";
    
172 173 174 175
    if (isset($all) && ISADMIN()) {
	echo "<td>$creator</td>";
    }
    echo "  <td style='white-space:nowrap'>$pid</td>
176
            <td>$desc</td>
177
            <td class='format-date'>$created</td>
178 179
            <td>$listed</td>
            <td>$privacy</td>
180
           </tr>\n";
181
}
182
echo "   </tbody>
183 184
        </table>\n";

Leigh B Stoller's avatar
Leigh B Stoller committed
185 186 187 188 189 190 191 192 193
if (!isset($all)) {
    if (ISADMIN()) {
	echo "<img src='images/redball.gif'>
          <a href='myprofiles.php?all=1'>Show all user profiles</a>\n";
    }
    else {
	echo "<img src='images/blueball.gif'>
          <a href='myprofiles.php?all=1'>Show all profiles you can instantiate</a>\n";
    }
194 195
}
echo"   </div>
196
      </div>\n";
197

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
echo "<!-- This is the topology view modal -->
      <div id='quickvm_topomodal' class='modal fade'>
        <div class='modal-dialog' id='showtopo_dialog'>
          <div class='modal-content'>
            <div class='modal-header'>
              <button type='button' class='close' data-dismiss='modal'
                      aria-hidden='true'>
                      &times;</button>
                <h3>Topology Viewer</h3>
            </div>
            <div class='modal-body'>
              <!-- This topo diagram goes inside this div -->
              <div class='panel panel-default'
                         id='showtopo_container'>
                <div class='panel-body'>
213
                  <div id='showtopo_nopicker' class='jacks'></div>
214 215
                </div>
              </div>
216 217 218
            </div>
          </div>
        </div>
219
      </div>\n";
220

221 222 223 224

echo "<script type='text/javascript'>\n";
echo "    window.AJAXURL  = 'server-ajax.php';\n";
echo "</script>\n";
225
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
226
echo "<script src='js/lib/bootstrap.js'></script>\n";
227 228 229 230
echo "<script src='js/lib/require.js' data-main='js/myprofiles'></script>\n";

SPITFOOTER();
?>