r2345 - don't allow editing/deleting stock records in dictionary editor
[racktables] / inc / interface.php
index 7c26a87..9973f71 100644 (file)
@@ -30,6 +30,7 @@ $aac2 = array
 (
        'regular' => '',
        'virtual' => '<strong>L:</strong>',
+       'shared' => '<strong>S:</strong>',
        'router' => '<strong>R:</strong>',
 );
 
@@ -71,6 +72,9 @@ $image['link']['height'] = 16;
 $image['add']['path'] = 'pix/tango-list-add.png';
 $image['add']['width'] = 16;
 $image['add']['height'] = 16;
+$image['ADD']['path'] = 'pix/tango-list-add-big.png';
+$image['ADD']['width'] = 32;
+$image['ADD']['height'] = 32;
 $image['delete']['path'] = 'pix/tango-list-remove.png';
 $image['delete']['width'] = 16;
 $image['delete']['height'] = 16;
@@ -142,6 +146,15 @@ $image['VS']['height'] = 62;
 $image['router']['path'] = 'pix/router.png';
 $image['router']['width'] = 32;
 $image['router']['height'] = 32;
+$image['LINK']['path'] = 'pix/tango-emblem-symbolic-link-big.png';
+$image['LINK']['width'] = 32;
+$image['LINK']['height'] = 32;
+$image['favorite']['path'] = 'pix/tango-emblem-favorite.png';
+$image['favorite']['width'] = 16;
+$image['favorite']['height'] = 16;
+$image['computer']['path'] = 'pix/tango-computer.png';
+$image['computer']['width'] = 16;
+$image['computer']['height'] = 16;
 
 // This may be populated later onsite, report rendering function will use it.
 // See the $systemreport for structure.
@@ -370,16 +383,12 @@ function renderRack ($rack_id = 0, $hl_obj_id = 0)
                echo "</a></td>";
        }
        echo "</h2></td></tr></table>\n";
-       if ($rackData['left_is_front'] == 'yes')
-               $markup = array ('left' => 'Front', 'right' => 'Back');
-       else
-               $markup = array ('left' => 'Back', 'right' => 'Front');
        echo "<table class=rack border=0 cellspacing=0 cellpadding=1>\n";
-       echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>${markup['left']}</th>";
-       echo "<th width='50%'>Interior</th><th width='20%'>${markup['right']}</th></tr>\n";
+       echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
+       echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
        for ($i = $rackData['height']; $i > 0; $i--)
        {
-               echo '<tr><th>' . ($rackData['bottom_is_unit1'] == 'yes' ? $i : $rackData['height'] - $i + 1) . '</th>';
+               echo "<tr><th>${i}</th>";
                for ($locidx = 0; $locidx < 3; $locidx++)
                {
                        if (isset ($rackData[$i][$locidx]['skipped']))
@@ -809,7 +818,7 @@ function renderRackObject ($object_id = 0)
                echo "<tr><td colspan=2 class=msg_error>Has problems</td></tr>\n";
        foreach (getAttrValues ($object_id, TRUE) as $record)
                if (!empty ($record['value']))
-                       echo "<tr><th width='50%' class=opt_attr_th>${record['name']}:</th><td class=tdleft>${record['a_value']}</td></tr>\n";
+                       echo "<tr><th width='50%' class=tdright><span class=sticker>${record['name']}</span>:</th><td class=tdleft>${record['a_value']}</td></tr>\n";
        printTagTRs ("${root}?page=objgroup&tab=default&group_id=${info['objtype_id']}&");
        echo "<tr><th width='50%' class=tdright>Actions:</th><td class=tdleft><a href='${root}process.php?op=deleteObject&page=objects&tab=default&object_id=${object_id}&name=${info['name']}' onclick=\"javascript:return confirm('Are you sure you want to delete the object?')\">Delete object</a></td></tr>\n";
        echo "</table><br>\n";
@@ -1459,6 +1468,7 @@ function printLog ($log)
                                175 => array ('code' => 'error', 'format' => 'Invalid netmask'),
                                176 => array ('code' => 'error', 'format' => 'This network already exists'),
                                177 => array ('code' => 'error', 'format' => 'commitUpdateRack() failed'),
+                               178 => array ('code' => 'error', 'format' => 'file not found'),
 
                                200 => array ('code' => 'warning', 'format' => 'generic warning: %s'),
                                201 => array ('code' => 'warning', 'format' => 'nothing happened...'),
@@ -3018,11 +3028,11 @@ function renderSearchResults ()
        // If we search for L2 address, we can either find one or find none.
        if
        (
-               preg_match ('/^[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?$/i', $terms) or
-               preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms) or
-               preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms) or
-               // STP bridge ID: bridge priotity + port MAC address. Cut off first 4 chars and look for MAC address.
-               preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms)
+               preg_match (RE_L2_IFCFG, $terms) or
+               preg_match (RE_L2_SOLID, $terms) or
+               preg_match (RE_L2_CISCO, $terms) or
+               // Foundry STP bridge ID: bridge priotity + port MAC address. Cut off first 4 chars and look for MAC address.
+               preg_match (RE_L2_FDRYSTP, $terms)
        )
        // Search for L2 address.
        {
@@ -3037,7 +3047,7 @@ function renderSearchResults ()
                        $summary['port'][] = $result;
                }
        }
-       elseif (preg_match ('/^[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$/i', $terms))
+       elseif (preg_match (RE_IP4_ADDR, $terms))
        // Search for IPv4 address.
        {
                if (NULL !== getIPv4AddressNetworkId ($terms))
@@ -3047,7 +3057,7 @@ function renderSearchResults ()
                        $summary['ipv4addressbydq'][] = $terms;
                }
        }
-       elseif (preg_match ('/^[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\/[0-9][0-9]?$/i', $terms))
+       elseif (preg_match (RE_IP4_NET, $terms))
        // Search for IPv4 network
        {
                list ($base, $len) = explode ('/', $terms);
@@ -3486,7 +3496,7 @@ function renderDictionary ()
        foreach ($dict as $chapter_no => $chapter)
        {
                $order = 'odd';
-               echo "<tr><th>Chapter</th><th>refs</th><th>Word</th></tr>\n";
+               echo "<tr><th>Chapter</th><th>status</th><th>Word</th></tr>\n";
                $wc = count ($chapter['word']);
                echo "<tr class=row_${order}><td class=tdleft" . ($wc ? " rowspan = ${wc}" : '');
                echo "><div title='number=${chapter_no}'>${chapter['name']} (${wc} records)</div></td>";
@@ -3501,8 +3511,12 @@ function renderDictionary ()
                                        echo "<tr class=row_${order}>";
                                else
                                        $chap_start = FALSE;
-                               echo '<td>' . ($chapter['refcnt'][$key] ? $chapter['refcnt'][$key] : '&nbsp;') . '</td>';
-                               echo "<td><div title='key=${key}'>${value}</div></td></tr>\n";
+                               echo '<td>';
+                               printImageHREF (($key <= MAX_DICT_KEY) ? 'computer' : 'favorite');
+                               echo '&nbsp;';
+                               if ($chapter['refcnt'][$key])
+                                       echo $chapter['refcnt'][$key];
+                               echo "</td><td><div title='key=${key}'>${value}</div></td></tr>\n";
                                $order = $nextorder[$order];
                        }
                }
@@ -3519,36 +3533,47 @@ function renderDictionaryEditor ()
        foreach ($dict as $chapter_no => $chapter)
        {
                $order = 'odd';
-               echo "<tr><th>Chapter</th><th>&nbsp;</th><th>Word</th><th>&nbsp;</th></tr>\n";
+               echo "<tr><th>Chapter</th><th>&nbsp;</th><th>&nbsp;</th><th>Word</th><th>&nbsp;</th></tr>\n";
                $wc = count ($chapter['word']);
                // One extra span for the new record per each chapter block.
                echo "<tr class=row_${order}><td class=tdleft" . ($wc ? ' rowspan = ' . ($wc + 1) : '');
                echo "><div title='number=${chapter_no}'>${chapter['name']} (${wc} records)</div></td>";
                printOpFormIntro ('add', array ('chapter_no' => $chapter['no']));
-               echo "<td>";
+               echo "<td>&nbsp;</td><td>";
                printImageHREF ('add', 'Add new', TRUE);
                echo "</td>";
-               echo "<td class=tdright><input type=text name=dict_value size=32></td>";
+               echo "<td class=tdleft><input type=text name=dict_value size=32></td>";
                echo "<td>&nbsp;</td>";
                echo '</tr></form>';
                $order = $nextorder[$order];
                foreach ($chapter['word'] as $key => $value)
                {
-                       printOpFormIntro ('upd', array ('chapter_no' => $chapter['no'], 'dict_key' => $key));
                        echo "<tr class=row_${order}><td>";
-                       // Prevent deleting words currently used somewhere.
-                       if ($chapter['refcnt'][$key])
-                               printImageHREF ('nodelete', 'referenced ' . $chapter['refcnt'][$key] . ' time(s)');
+                       // Show plain row for stock records, render a form for user's ones.
+                       if ($key <= MAX_DICT_KEY)
+                       {
+                               printImageHREF ('computer');
+                               echo "</td><td>&nbsp;</td><td>${value}</td><td>&nbsp;</td></tr>";
+                       }
                        else
                        {
-                               echo "<a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&chapter_no=${chapter['no']}&dict_key=${key}'>";
-                               printImageHREF ('delete', 'Delete word');
-                               echo "</a>";
+                               printOpFormIntro ('upd', array ('chapter_no' => $chapter['no'], 'dict_key' => $key));
+                               printImageHREF ('favorite');
+                               echo "<td>";
+                               // Prevent deleting words currently used somewhere.
+                               if ($chapter['refcnt'][$key])
+                                       printImageHREF ('nodelete', 'referenced ' . $chapter['refcnt'][$key] . ' time(s)');
+                               else
+                               {
+                                       echo "<a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&chapter_no=${chapter['no']}&dict_key=${key}'>";
+                                       printImageHREF ('delete', 'Delete word');
+                                       echo "</a>";
+                               }
+                               echo '</td>';
+                               echo "<td class=tdright><input type=text name=dict_value size=64 value='${value}'></td><td>";
+                               printImageHREF ('save', 'Save changes', TRUE);
+                               echo "</td></tr></form>\n";
                        }
-                       echo '</td>';
-                       echo "<td class=tdright><input type=text name=dict_value size=32 value='${value}'></td><td>";
-                       printImageHREF ('save', 'Save changes', TRUE);
-                       echo "</td></tr></form>\n";
                        $order = $nextorder[$order];
                } // foreach ($chapter['word']
        } // foreach ($dict
@@ -5137,17 +5162,17 @@ function printTagTRs ($baseurl = '')
        global $expl_tags, $impl_tags, $auto_tags;
        if (getConfigVar ('SHOW_EXPLICIT_TAGS') == 'yes' and count ($expl_tags))
        {
-               echo "<tr><th width='50%' class=tag_list_th>Explicit tags:</th><td class=tdleft>";
+               echo "<tr><th width='50%' class=tdright><span class=tagheader>Explicit tags</span>:</th><td class=tdleft>";
                echo serializeTags ($expl_tags, $baseurl) . "</td></tr>\n";
        }
        if (getConfigVar ('SHOW_IMPLICIT_TAGS') == 'yes' and count ($impl_tags))
        {
-               echo "<tr><th width='50%' class=tag_list_th>Implicit tags:</th><td class=tdleft>";
+               echo "<tr><th width='50%' class=tdright>Implicit tags:</th><td class=tdleft>";
                echo serializeTags ($impl_tags, $baseurl) . "</td></tr>\n";
        }
        if (getConfigVar ('SHOW_AUTOMATIC_TAGS') == 'yes' and count ($auto_tags))
        {
-               echo "<tr><th width='50%' class=tag_list_th>Automatic tags:</th><td class=tdleft>";
+               echo "<tr><th width='50%' class=tdright>Automatic tags:</th><td class=tdleft>";
                echo serializeTags ($auto_tags) . "</td></tr>\n";
        }
 }
@@ -5366,9 +5391,9 @@ function renderUser ($user_id)
 
        startPortlet ('summary');
        echo '<table border=0 align=center>';
-       echo "<tr><th class=tdright>Account name:</th><td>${username}</td></tr>";
-       echo '<tr><th class=tdright>Real name:</th><td>' . $accounts[$username]['user_realname'] . '</td></tr>';
-       echo '<tr><th class=tdright>Enabled:</th><td>';
+       echo "<tr><th class=tdright>Account name:</th><td class=tdleft>${username}</td></tr>";
+       echo '<tr><th class=tdright>Real name:</th><td class=tdleft>' . $accounts[$username]['user_realname'] . '</td></tr>';
+       echo '<tr><th class=tdright>Enabled:</th><td class=tdleft>';
        // This is weird, some other image titles have to be used.
        if ($accounts[$username]['user_enabled'] == 'yes')
                printImageHREF ('blockuser', 'enabled');
@@ -5381,18 +5406,18 @@ function renderUser ($user_id)
        $baseurl = "${root}?page=userlist&tab=default&";
        if (getConfigVar ('SHOW_EXPLICIT_TAGS') == 'yes' and count ($expl_tags))
        {
-               echo "<tr><th width='50%' class=tag_list_th>Explicit tags:</th><td class=tdleft>";
+               echo "<tr><th width='50%' class=tdright><span class=tagheader>Explicit tags</span>:</th><td class=tdleft>";
                echo serializeTags ($expl_tags, $baseurl) . "</td></tr>\n";
        }
        if (getConfigVar ('SHOW_IMPLICIT_TAGS') == 'yes' and count ($impl_tags))
        {
-               echo "<tr><th width='50%' class=tag_list_th>Implicit tags:</th><td class=tdleft>";
+               echo "<tr><th width='50%' class=tdright><span class=tagheader>Implicit tags</span>:</th><td class=tdleft>";
                echo serializeTags ($impl_tags, $baseurl) . "</td></tr>\n";
        }
        $target_auto_tags = getUserAutoTags ($username);
        if (getConfigVar ('SHOW_AUTOMATIC_TAGS') == 'yes' and count ($target_auto_tags))
        {
-               echo "<tr><th width='50%' class=tag_list_th>Automatic tags:</th><td class=tdleft>";
+               echo "<tr><th width='50%' class=tdright><span class=tagheader>Automatic tags</span>:</th><td class=tdleft>";
                echo serializeTags ($target_auto_tags) . "</td></tr>\n";
        }
        echo '</table>';
@@ -5430,16 +5455,16 @@ function renderAccessDenied ()
        echo ' access denied ';
        printImageHREF ('DENIED');
        echo '</h3></th></tr>';
-       echo "<tr><th width='50%' class=tag_list_th>Explicit tags:</th><td class=tdleft>";
+       echo "<tr><th width='50%' class=tdright><span class=tagheader>Explicit tags</span>:</th><td class=tdleft>";
        echo serializeTags ($expl_tags) . "&nbsp;</td></tr>\n";
-       echo "<tr><th width='50%' class=tag_list_th>Implicit tags:</th><td class=tdleft>";
+       echo "<tr><th width='50%' class=tdright><span class=tagheader>Implicit tags</span>:</th><td class=tdleft>";
        echo serializeTags ($impl_tags) . "&nbsp;</td></tr>\n";
-       echo "<tr><th width='50%' class=tag_list_th>Automatic tags:</th><td class=tdleft>";
+       echo "<tr><th width='50%' class=tdright><span class=tagheader>Automatic tags</span>:</th><td class=tdleft>";
        echo serializeTags ($auto_tags) . "&nbsp;</td></tr>\n";
-       echo "<tr><th width='50%' class=tag_list_th>This user tags:</th><td class=tdleft>";
+       echo "<tr><th width='50%' class=tdright><span class=tagheader>This user tags</span>:</th><td class=tdleft>";
        echo serializeTags ($user_tags) . "&nbsp;</td></tr>\n";
-       echo "<tr><th width='50%' class=tag_list_th>Requested page:</th><td class=tdleft>${pageno}</td></tr>\n";
-       echo "<tr><th width='50%' class=tag_list_th>Requested tab:</th><td class=tdleft>${tabno}</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Requested page:</th><td class=tdleft>${pageno}</td></tr>\n";
+       echo "<tr><th width='50%' class=tdright>Requested tab:</th><td class=tdleft>${tabno}</td></tr>\n";
        echo "</table>\n";
        echo "</body></html>";
 }
@@ -5665,9 +5690,9 @@ function renderFilesPortlet ($entity_type = NULL, $entity_id = 0)
                echo "<tr><th>Name</th><th>Size</th><th>Comment</th><th>Actions</th></tr>\n";
                foreach ($files as $file_id => $file)
                {
-                       printf("<td><a href='%/?page=file&file_id=%s'><strong>%s</strong></a></td>", $root, $file_id, $file['name']);
-                       printf("<td>%s</td>", formatFileSize($file['size']));
-                       echo "<td>${file['comment']}</td>";
+                       printf("<td class=tdleft><a href='%/?page=file&file_id=%s'><strong>%s</strong></a></td>", $root, $file_id, $file['name']);
+                       printf("<td class=tdleft>%s</td>", formatFileSize($file['size']));
+                       echo "<td class=tdleft>${file['comment']}</td>";
                        echo "<td><a href='${root}download.php?file_id=${file_id}'>";
                        printImageHREF ('download', 'Download file');
                        echo '</a></td></tr>';
@@ -5686,56 +5711,60 @@ function renderFilesForEntity ($entity_type = NULL, $id_name = NULL, $entity_id
                return;
        }
 
-       function printNewItemTR ($entity_type, $entity_id)
+       showMessageOrError();
+       startPortlet ('Upload new');
+       echo "<table border=0 cellspacing=0 cellpadding='5' align='center'>\n";
+       printOpFormIntro ('addFile', array ('entity_type' => $entity_type, 'entity_id' => $entity_id, 'MAX_FILE_SIZE' => convertToBytes(get_cfg_var('upload_max_filesize'))), TRUE);
+       echo "<tr>";
+       echo "<td class=tdleft><input type='file' size='10' name='file' tabindex=100></td>\n";
+       echo "<td class=tdleft><input type='text' size='15' name='comment' tabindex=101></td><td>\n";
+       printImageHREF ('CREATE', 'Upload file', TRUE, 102);
+       echo "</td></tr></form>";
+       echo "</table><br>\n";
+       finishPortlet();
+
+       $files = getAllUnlinkedFiles ($entity_type, $entity_id);
+       if (count ($files))
        {
-               global $root;
-               printOpFormIntro ('addFile', array ('entity_type' => $entity_type, 'entity_id' => $entity_id, 'MAX_FILE_SIZE' => convertToBytes(get_cfg_var('upload_max_filesize'))), TRUE);
-               echo "<tr><td>";
-               printImageHREF ('add', 'Upload file', TRUE, 99);
-               echo "</td>";
-               echo "<td class=tdleft><input type='file' size='10' name='file' tabindex=100></td>\n";
-               echo "<td class=tdleft><input type='text' size='15' name='comment' tabindex=101></td>\n";
-               echo "<td></td>\n";
-               echo "<td><a href='javascript:;' onclick='window.open(\"${root}file_link_helper.php?entity_type=$entity_type&entity_id=$entity_id";
-               echo "\",\"findlink\",\"height=700, width=400, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, titlebar=no, toolbar=no\");'>";
-               printImageHREF ('link', 'Link an existing file');
-               echo "</a> &nbsp;&nbsp;";
-               printImageHREF ('add', 'Upload file', TRUE, 99);
-               echo "</td></tr></form>";
+               startPortlet ('Use existing');
+               printOpFormIntro ('linkFile');
+       echo "<table border=0 cellspacing=0 cellpadding='5' align='center'>\n";
+               echo '<tr><td class=tdleft>';
+               printSelect ($files, 'file_id');
+               echo '</td><td class=tdleft>';
+               printImageHREF ('LINK', 'Link file', TRUE);
+               echo '</td></tr></table>';
+               echo "</form>\n";
+               finishPortlet();
        }
 
-       showMessageOrError();
-       startPortlet ('Files');
        $filelist = getFilesOfEntity ($entity_type, $entity_id);
-       echo "<table border=0 cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
-       echo "<tr><th>&nbsp;</th><th>Name</th><th>Comment</th><th>Size</th><th>Actions</th></tr>\n";
-
-       if (getConfigVar ('ADDNEW_AT_TOP') == 'yes')
-               printNewItemTR($entity_type, $entity_id);
-       foreach ($filelist as $file_id => $file)
+       if (count ($filelist))
        {
-               printOpFormIntro ('updateFile', array ('file_id' => $file_id, 'link_id' => $file['link_id'], 'name' => $file['name']));
-               echo "<tr valign=top><td><a href='${root}process.php?op=deleteFile&page=${pageno}&tab=${tabno}&file_id=${file_id}&${id_name}=${entity_id}&name=${file['name']}'>";
-               printImageHREF ('delete', 'Unlink and delete file');
-               echo '</a></td>';
-               printf("<td class='tdleft'><a href='%/?page=file&file_id=%s'><strong>%s</strong></a>", $root, $file_id, $file['name']);
-               echo "<td class=tdleft><input type='text' name='comment' value='${file['comment']}' size=15></td>";
-               printf("<td class=tdleft>%s</td>", formatFileSize($file['size']));
-               echo "<td><a href='${root}download.php?file_id=${file_id}'>";
-               printImageHREF ('download', 'Download file');
-               echo '</a> ';
-               echo "<a href='${root}process.php?op=unlinkFile&page=${pageno}&tab=${tabno}&link_id=${file['link_id']}&${id_name}=${entity_id}&name=${file['name']}'>";
-               printImageHREF ('clear', 'Unlink file');
-               echo '</a> ';
-               printImageHREF ('save', 'Save changes', TRUE);
-               echo "</td></form></tr>\n";
+               startPortlet ('Manage linked');
+               echo "<table border=0 cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
+               echo "<tr><th>&nbsp;</th><th>Name</th><th>Comment</th><th>Size</th><th>Actions</th></tr>\n";
+               foreach ($filelist as $file_id => $file)
+               {
+                       printOpFormIntro ('updateFile', array ('file_id' => $file_id, 'link_id' => $file['link_id'], 'name' => $file['name']));
+                       echo "<tr valign=top><td><a href='${root}process.php?op=deleteFile&page=${pageno}&tab=${tabno}&file_id=${file_id}&${id_name}=${entity_id}&name=${file['name']}'>";
+                       printImageHREF ('delete', 'Unlink and delete file');
+                       echo '</a></td>';
+                       printf("<td class='tdleft'><a href='%/?page=file&file_id=%s'><strong>%s</strong></a>", $root, $file_id, $file['name']);
+                       echo "<td class=tdleft><input type='text' name='comment' value='${file['comment']}' size=15></td>";
+                       printf("<td class=tdleft>%s</td>", formatFileSize($file['size']));
+                       echo "<td><a href='${root}download.php?file_id=${file_id}'>";
+                       printImageHREF ('download', 'Download file');
+                       echo '</a> ';
+                       echo "<a href='${root}process.php?op=unlinkFile&page=${pageno}&tab=${tabno}&link_id=${file['link_id']}&${id_name}=${entity_id}&name=${file['name']}'>";
+                       printImageHREF ('clear', 'Unlink file');
+                       echo '</a> ';
+                       printImageHREF ('save', 'Save changes', TRUE);
+                       echo "</td></form></tr>\n";
+               }
+               echo "</table><br>\n";
+               finishPortlet();
        }
-       if (getConfigVar ('ADDNEW_AT_TOP') != 'yes')
-               printNewItemTR($entity_type, $entity_id);
-
-       echo "</table><br>\n";
-       finishPortlet();
-
 }
 
 // Set of wrapper functions to reduce duplicate code
@@ -5781,7 +5810,7 @@ function printOpFormIntro ($opname, $extra = array(), $upload = FALSE)
                echo "<input type=hidden name=${inputname} value=${inputvalue}>\n";
 }
 
-// This is a two-way formating function:
+// This is a dual-purpose formating function:
 // 1. Replace empty strings with nbsp.
 // 2. Cut strings, which are too long, append "cut here" indicator and provide a mouse hint.
 function niftyString ($string, $maxlen = 30)