r2412 Row can now be deleted if it has no racks
authorDenis Yeldandi <dyeldandi@gmail.com>
Sun, 8 Feb 2009 04:46:27 +0000 (04:46 +0000)
committerDenis Yeldandi <dyeldandi@gmail.com>
Sun, 8 Feb 2009 04:46:27 +0000 (04:46 +0000)
inc/database.php
inc/interface.php

index c4962e24d982d85f2442ddeb8f27a756f2a730c6..3df91eb1201d6a10eddbc408d4303595c4ffbddc 100644 (file)
@@ -37,15 +37,15 @@ function getRackspace ($tagfilter = array(), $tfmode = 'any')
 {
        $whereclause = getWhereClause ($tagfilter);
        $query =
-               "select RackRow.id as row_id, RackRow.name as row_name " .
+               "select RackRow.id as row_id, RackRow.name as row_name, count(Rack.id) as count " .
                "from RackRow left join Rack on Rack.row_id = RackRow.id " .
                "left join TagStorage on Rack.id = TagStorage.entity_id and entity_realm = 'rack' " .
                "where 1=1 " .
                $whereclause .
-               " order by RackRow.name";
+               " group by RackRow.id order by RackRow.name";
        $result = useSelectBlade ($query, __FUNCTION__);
        $ret = array();
-       $clist = array ('row_id', 'row_name');
+       $clist = array ('row_id', 'row_name', 'count');
        while ($row = $result->fetch (PDO::FETCH_ASSOC))
                foreach ($clist as $cname)
                        $ret[$row['row_id']][$cname] = $row[$cname];
@@ -92,9 +92,22 @@ function commitUpdateRow($rackrow_id, $rackrow_name)
 function commitDeleteRow($rackrow_id)
 {
        global $dbxlink;
-       $query = "delete from RackRow where id=${rackrow_id}";
+       $query = "select count(*) from Rack where row_id=${rackrow_id}";
        $result = $dbxlink->query ($query);
-       if ($result == NULL)
+       if (($result!=NULL) && ($row = $result->fetch(PDO::FETCH_NUM)) )
+       {
+               if ($row[0] == 0)
+               {
+                       $query = "delete from RackRow where id=${rackrow_id}";
+                       $result = $dbxlink->query ($query);
+                       if ($result == NULL)
+                       {
+                               showError ("SQL query '${query}' failed", __FUNCTION__);
+                               return FALSE;
+                       }
+               }
+       }
+       else
        {
                showError ("SQL query '${query}' failed", __FUNCTION__);
                return FALSE;
index 0c027cfbe3e5e09773e891472e4476d793e3009d..d0fb5d0a714807671466c89f61297c804a990819 100644 (file)
@@ -279,9 +279,14 @@ function renderRackspaceRowEditor ()
                printOpFormIntro ('updateRow', array ('row_id' => $rackrow['row_id']));
                echo "<tr><td><input type=text name=name value='${rackrow['row_name']}'></td><td>";
                printImageHREF ('save', 'Save changes', TRUE);
-               echo "</td></form><td><a href=\"".makeHrefProcess(array('op'=>'delete', 'row_id'=>$rackrow['row_id'], 'name'=>$rackrow['row_name']))."\">";
-               printImageHREF ('delete', 'Delete row');
-               echo "</a></td></tr>\n";
+               echo "</td></form><td>";
+               if ($rackrow['count'] == 0)
+               {
+                       echo "<a href=\"".makeHrefProcess(array('op'=>'delete', 'row_id'=>$rackrow['row_id'], 'name'=>$rackrow['row_name']))."\">";
+                       printImageHREF ('delete', 'Delete row');
+                       echo "</a>";
+               }
+               echo "</td></tr>\n";
        }
        if (getConfigVar ('ADDNEW_AT_TOP') != 'yes')
                printNewItemTR();
@@ -310,8 +315,8 @@ function renderRow ($row_id = 0)
        echo "<tr><td class=pcleft>";
        startPortlet ($rowInfo['name']);
        echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
-       echo "<tr><th width='50%' class=tdright>Racks:</th><td class=tdleft>${rowInfo['rackCount']}</td></tr>\n";
-       echo "<tr><th width='50%' class=tdright>Units:</th><td class=tdleft>${rowInfo['sumHeight']}</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Racks:</th><td class=tdleft>${rowInfo['count']}</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Units:</th><td class=tdleft>${rowInfo['sum']}</td></tr>\n";
        echo "<tr><th width='50%' class=tdright>%% used:</th><td class=tdleft>";
        renderProgressBar (getRSUforRackRow ($rackList));
        echo "</td></tr>\n";