images.php 7.62 KB
Newer Older
1
<?php 
Reto Da Forno's avatar
Reto Da Forno committed
2
3
4
5
6
7
8
9
10
    /*
     * __author__      = "Christoph Walser <walser@tik.ee.ethz.ch>"
     * __copyright__   = "Copyright 2010, ETH Zurich, Switzerland, Christoph Walser"
     * __license__     = "GPL"
     * __version__     = "$Revision$"
     * __date__        = "$Date$"
     * __id__          = "$Id$"
     * __source__      = "$URL$" 
     */
11
12
13
14
?>
<?php require_once('include/layout.php');require_once('include/presets.php'); ?>
<script type="text/javascript" src="scripts/jquery.cookie.js"></script>
<script type="text/javascript">
Reto Da Forno's avatar
Reto Da Forno committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    $(document).ready(function() {
        var table_rows = Math.max(Math.floor(($(window).height() - 300) / 25),10);
        $("#pager_num_rows").attr('value', table_rows);
        $("#test_overview")
            .tablesorter({widgets: ['zebra']})
            .tablesorterPager({container: $("#pager"), positionFixed: false});
        $('.qtip_show').qtip( {
            content: {text: false},
            style  : 'flocklab',
        });
        $("#test_overview").show();
        $.cookie.json = true;
        var img_tbl_state;
        try { img_tbl_state = $.cookie('flocklab.imgsort'); }
         catch (err) {
            img_tbl_state = null;
        }
        if ( img_tbl_state == null) {
            img_tbl_state = {s: [[0,1]], p: 0};
        }
        $("#test_overview").data('tablesorter').page = img_tbl_state.p;
        $("#test_overview").trigger("sorton",[img_tbl_state.s]);
        $("#test_overview").bind("applyWidgets",function() { 
            $.cookie('flocklab.imgsort', {s:$("#test_overview").data('tablesorter').sortList, p:$("#test_overview").data('tablesorter').page});
        });
    });
41
</script>
Reto Da Forno's avatar
Reto Da Forno committed
42
43
44
45
46
47
48
49
50
51
52
<h1>Manage Images for <?php echo $_SESSION['firstname'] . " " . $_SESSION['lastname'];?></h1>
<?php 
    /* Platforms with more than one core. */
    $db = db_connect();
    $sql = "select count(core) as corenum, name from tbl_serv_architectures left join tbl_serv_platforms on serv_platforms_key = platforms_fk group by platforms_fk having corenum > 1";
    $rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test images from database because: ' . mysqli_error($db));
    $nrows = mysqli_num_rows($rs);
    $multicore = Array();
    while ($row = mysqli_fetch_assoc($rs))
        array_push($multicore, $row['name']);
    /* Get all test images of the current user from the database and display them in the table. */
53
    $sql =   "SELECT `serv_targetimages_key`, `tbl_serv_targetimages`.`name` as `name`, `tbl_serv_targetimages`.`description` as `description`, `tbl_serv_architectures`.`description` as `core_desc`, `tbl_serv_platforms`.`name` as `platform_name`, `tbl_serv_targetimages`.`last_changed`, `test_fk`, `tbl_serv_tests`.`test_status` 
Reto Da Forno's avatar
Reto Da Forno committed
54
              FROM `tbl_serv_targetimages`
55
              LEFT JOIN `tbl_serv_platforms` ON `platforms_fk` = `tbl_serv_platforms`.`serv_platforms_key`
Reto Da Forno's avatar
Reto Da Forno committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
              LEFT JOIN `tbl_serv_architectures` 
                  ON (`tbl_serv_architectures`.`platforms_fk` = `tbl_serv_platforms`.`serv_platforms_key` AND `tbl_serv_architectures`.`core` = `tbl_serv_targetimages`.`core`)
              LEFT JOIN `tbl_serv_map_test_observer_targetimages` 
                  ON (`serv_targetimages_key` = `tbl_serv_map_test_observer_targetimages`.`targetimage_fk`)
              LEFT JOIN `tbl_serv_tests` 
                  ON (`test_fk` = `tbl_serv_tests`.`serv_tests_key`)
              WHERE (`tbl_serv_targetimages`.`owner_fk` = " . $_SESSION['serv_users_key'] . ") 
                  AND (`tbl_serv_targetimages`.`binary_hash_sha1` is not NULL)
              GROUP BY `serv_targetimages_key`
              ORDER BY `serv_targetimages_key` DESC";
    $rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test images from database because: ' . mysqli_error($db));
    $nrows = mysqli_num_rows($rs);
    mysqli_close($db);
    
    // If there are no tests for this user, display a message instead of the table:
    if ($nrows == 0) {
        echo "<p class='warning'><img alt='' src='pics/icons/att.png'>No images uploaded yet</p>";
    }
    // If there are tests for this user, display them (with alternating row coloring):
    else {
?>
<table id="test_overview" class="tablesorter" style="display:none">
    <thead>
        <tr>
            <th width="50px">ID</th>
            <th>Name</th>
            <th>Description</th>
Reto Da Forno's avatar
Reto Da Forno committed
83
84
85
            <th>Platform</th>
            <th>Date</th>
            <th width="60px" class='qtip_show' title='Actions'>Actions</th>
Reto Da Forno's avatar
Reto Da Forno committed
86
87
88
89
90
91
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
137
138
139
140
141
142
143
144
        </tr>
    </thead>
    <tbody>
<?php 
    $i = 0;
    $max_len = 16; // maximum length of text before beeing cut
    while ($row = mysqli_fetch_assoc($rs)) {
        $i++;
        if ($i%2 == 1) {
            echo "<tr class='even'>";
        } else {
            echo "<tr class='odd'>";
        }
        echo "<td>" . $row['serv_targetimages_key'] . "</td>";
        // Name. If longer than $max_len characters, display as tooltip:
        echo "<td class='qtip_show' title='" . $row['name'] . "'>" . $row['name'] . "</td>";
        // Description. If longer than $max_len characters, display as tooltip:
        if (strlen($row['description']) <= $max_len) 
            echo "<td>" . $row['description'] . "</td>";
        else
            echo "<td class='qtip_show' title='" . $row['description'] . "'>" . substr($row['description'],0,$max_len) . "...</td>";
        // Platform. If longer than $max_len characters, display as tooltip:
        $corenum = in_array($row['platform_name'], $multicore)?': '.$row['core_desc']:'';
        echo "<td class='qtip_show' title='" . $row['platform_name'] .$corenum. "'>" . $row['platform_name'] .$corenum. "</td>";
        // Date
        echo "<td title='Date' class='qtip_show'>".date_to_tzdate($row['last_changed'])."</td>";
        // Actions
        echo "<td>";
        if (is_null($row['test_fk']) || ($row['test_status'] == "deleted")) {
          echo "<span style='display:none'>delete</span>"; // needed to make cell sortable by JQuery
          echo "<img src='pics/icons/trash.png' height='16px' alt='Delete' title='Delete test image' class='qtip_show link' onClick='document.tstimgdel.imageid.value = " . $row['serv_targetimages_key'] . ";document.tstimgdel.submit();'> ";
        }
        else {
          echo "<span style='display:none'>delete not possible</span>"; // needed to make cell sortable by JQuery
          echo "<img src='pics/icons/cancel.png' height='16px' alt='Not Delete' title='This image is used in a test' class='qtip_show link'> ";
        }
        echo "<img src='pics/icons/download.png' height='16px' alt='Download' title='Download test image' class='qtip_show link' onClick='document.tstimgdownload.imageid.value = " . $row['serv_targetimages_key'] . ";document.tstimgdownload.submit();'> ";
        echo "</td>";
        echo "</tr>";
    }
?>
    </tbody>
</table>
<br />
<span id="pager" class="pager">
    <span class="texticonsm first link" alt="first" title="first"><<</span>
    <span class="texticonsm prev link" alt="prev" title="prev"><</span>
    <span class="pagedisplay"></span>
    <span class="texticonsm next link" alt="next" title="next">></span>
    <span class="texticonsm last link" alt="last" title="last">>></span>
    <input class="pagesize" style="visibility: hidden;" id="pager_num_rows" value="15">
</span> <br>
<?php
  }
?>
<!-- Forms for processing actions -->
<form name="tstimgdel" method="post" action="image_delete.php"><input type="hidden" name="imageid" value=""></form>
<form name="tstimgdownload" method="post" action="image_download.php"><input type="hidden" name="imageid" value=""></form>
<p><a style="color:#666666;text-decoration:none;" href="newimage.php"><span class="texticon">+</span> add new test image</a></p>
145
146
<!-- END content -->
<?php
Reto Da Forno's avatar
Reto Da Forno committed
147
  do_layout('Manage Images','Manage Images');
148
?>