function dashboard_rss_edit($dashletid)
{
    global $CONFIG, $sit;
    $action = $_REQUEST['editaction'];
    switch ($action) {
        case 'add':
            echo "<h2>" . icon('feed-icon', 32) . " {$GLOBALS['strAddRSSAtomFeed']}</h2>";
            echo "<form id='dashrssaddform' action='{$_SERVER['PHP_SELF']}?action=do_add' method='post'>";
            echo "<table class='vertical'>";
            echo "<tr><td><label>" . icon('feed-icon', 12, $GLOBALS['strFeedIcon']) . " ";
            echo "{$GLOBALS['strRSSAtomURL']}: <input type='text' name='url' size='45' /></label></td></tr>\n";
            echo "<tr><td><label>{$GLOBALS['strDisplay']}: <input type='text' name='items' size='3' value='0' /></label> ({$GLOBALS['str0MeansUnlimited']})</td></tr>";
            echo "</table>";
            // <input name='submit' type='submit' value='{$GLOBALS['strAdd']}' />
            echo "<p align='center'>" . dashlet_link('rss', $dashletid, $GLOBALS['strAdd'], 'save', array('editaction' => 'do_add'), false, 'dashrssaddform') . "</p>";
            echo "</form>";
            break;
        case 'do_add':
            $url = cleanvar($_REQUEST['url']);
            $enable = cleanvar($_REQUEST['enable']);
            $items = cleanvar($_REQUEST['items']);
            $sql = "INSERT INTO `{$CONFIG['db_tableprefix']}dashboard_rss` (owner, url, items, enabled) VALUES ({$sit[2]},'{$url}','{$items}','true')";
            //SET enabled = '{$enable}' WHERE url = '{$url}' AND owner = {$sit[2]}";
            $result = mysql_query($sql);
            if (mysql_error()) {
                trigger_error(mysql_error(), E_USER_WARNING);
            }
            if (!$result) {
                html_redirect("edit_rss_feeds.php", FALSE);
            } else {
                html_redirect("edit_rss_feeds.php");
            }
            break;
        case 'edit':
            $url = cleanvar(urldecode($_REQUEST['url']));
            $sql = "SELECT * FROM `{$CONFIG['db_tableprefix']}dashboard_rss` WHERE owner = {$sit[2]} AND url = '{$url}' LIMIT 1 ";
            if ($CONFIG['debug']) {
                $dbg .= print_r($sql, true);
            }
            $result = mysql_query($sql);
            if (mysql_error()) {
                trigger_error(mysql_error(), E_USER_WARNING);
            }
            if (mysql_num_rows($result) > 0) {
                $feed = mysql_fetch_object($result);
                if ($feed->items == '') {
                    $feed->items = 0;
                }
                echo "<h2>" . icon('feed-icon', 32) . " {$GLOBALS['strEditRSSAtomFeed']}</h2>";
                echo "<form id='dashrsseditform' action='{$_SERVER['PHP_SELF']}?action=do_edit' method='post'>";
                echo "<table class='vertical'>";
                echo "<tr><td><label><img src='{$CONFIG['application_webpath']}images/icons/{$iconset}/12x12/feed-icon.png' alt='Feed Icon' /> ";
                echo "{$GLOBALS['strRSSAtomURL']}: <input type='text' name='url' size='45' value='{$feed->url}' /></label></td></tr>\n";
                echo "<tr><td><label>{$GLOBALS['strDisplay']}: <input type='text' name='items' size='3' value='{$feed->items}' /></label> ({$GLOBALS['str0MeansUnlimited']})</td></tr>";
                echo "</table>";
                echo "<input type='hidden' name='oldurl' size='45' value='{$feed->url}' />";
                echo "<p align='center'>" . dashlet_link('rss', $dashletid, $GLOBALS['strSave'], 'save', array('editaction' => 'do_edit'), false, 'dashrsseditform') . "</p>";
                echo "</form>";
            } else {
                echo "<p class='error'>{$GLOBALS['strNoRecords']}</p>";
            }
            break;
        case 'do_edit':
            $url = cleanvar($_REQUEST['url']);
            $oldurl = cleanvar($_REQUEST['oldurl']);
            $items = cleanvar($_REQUEST['items']);
            $sql = "UPDATE `{$CONFIG['db_tableprefix']}dashboard_rss` SET url = '{$url}', items = '{$items}' WHERE url = '{$oldurl}' AND owner = {$sit[2]}";
            $result = mysql_query($sql);
            if (mysql_error()) {
                trigger_error(mysql_error(), E_USER_ERROR);
            }
            if (!$result) {
                html_redirect("edit_rss_feeds.php", FALSE);
            } else {
                html_redirect("edit_rss_feeds.php");
            }
            break;
        case 'enable':
            $url = urldecode(cleanvar($_REQUEST['url']));
            $enable = cleanvar($_REQUEST['enable']);
            $sql = "UPDATE `{$CONFIG['db_tableprefix']}dashboard_rss` SET `enabled` = '{$enable}' WHERE `url` = '{$url}' AND `owner` = {$sit[2]}";
            mysql_query($sql);
            if (mysql_error()) {
                trigger_error(mysql_error(), E_USER_ERROR);
            }
            if (mysql_affected_rows() < 1) {
                html_redirect("edit_rss_feeds.php", FALSE, "Changed enabled state failed");
            }
            if (mysql_affected_rows() < 1) {
                html_redirect("edit_rss_feeds.php", FALSE, "Changed enabled state failed");
            } else {
                html_redirect("edit_rss_feeds.php");
            }
            break;
        case 'delete':
            $url = $_REQUEST['url'];
            $enable = $_REQUEST['enable'];
            $sql = "DELETE FROM `{$CONFIG['db_tableprefix']}dashboard_rss` WHERE url = '{$url}' AND owner = {$sit[2]}";
            $result = mysql_query($sql);
            if (mysql_error()) {
                trigger_error(mysql_error(), E_USER_ERROR);
            }
            if (!$result) {
                html_redirect("edit_rss_feeds.php", FALSE);
            } else {
                html_redirect("edit_rss_feeds.php");
            }
            break;
        default:
            echo "<h2>" . icon('feed-icon', 32) . " {$GLOBALS['strEditRSSAtomFeed']}</h2>";
            $sql = "SELECT * FROM `{$CONFIG['db_tableprefix']}dashboard_rss` WHERE owner = {$sit[2]}";
            $result = mysql_query($sql);
            if (mysql_error()) {
                trigger_error(mysql_error(), E_USER_WARNING);
            }
            if (mysql_num_rows($result) > 0) {
                echo "<table align='center'>\n";
                echo "<tr><th>URL</th><th>{$GLOBALS['strDisplay']}</th><th>{$GLOBALS['strEnabled']}</th><th>{$GLOBALS['strOperation']}</th></tr>\n";
                $shade = 'shade1';
                while ($obj = mysql_fetch_object($result)) {
                    if ($obj->enabled == "true") {
                        $opposite = "false";
                    } else {
                        $opposite = "true";
                    }
                    $urlparts = parse_url($obj->url);
                    if ($obj->enabled == 'false') {
                        $shade = 'expired';
                    }
                    echo "<tr class='{$shade}'><td align='left'><a href=\"" . htmlentities($obj->url, ENT_NOQUOTES, $GLOBALS['i18ncharset']) . "\">";
                    echo icon('feed-icon', 12, $strFeedIcon);
                    echo "</a> <a href=\"{$obj->url}\">{$urlparts['host']}</a></td>";
                    echo "<td>";
                    if ($obj->items >= 1) {
                        echo "{$obj->items}";
                    } else {
                        echo $GLOBALS['strUnlimited'];
                    }
                    echo "</td>";
                    echo "<td>" . dashlet_link('rss', $dashletid, $obj->enabled, 'edit', array('editaction' => 'enable', 'enable' => $opposite, 'url' => urlencode($obj->url))) . "</td>";
                    echo "<td>" . dashlet_link('rss', $dashletid, $GLOBALS['strEdit'], 'edit', array('editaction' => 'edit', 'url' => urlencode($obj->url)));
                    echo " | " . dashlet_link('rss', $dashletid, $GLOBALS['strRemove'], 'edit', array('editaction' => 'delete', 'url' => urlencode($obj->url)));
                    echo "</td></tr>\n";
                    if ($shade == 'shade1') {
                        $shade = 'shade2';
                    } else {
                        $shade = 'shade1';
                    }
                }
                echo "</table>\n";
            } else {
                echo "<p align='center'>{$GLOBALS['strNoFeedsCurrentlyPresent']}</p>";
            }
            echo "<p align='center'>" . dashlet_link('rss', $dashletid, $GLOBALS['strAdd'], 'edit', array('editaction' => 'add')) . "</p>";
            break;
    }
}
function dashboard_watch_incidents_edit($dashletid)
{
    global $CONFIG, $sit;
    $editaction = $_REQUEST['editaction'];
    switch ($editaction) {
        case 'add':
            $type = $_REQUEST['type'];
            echo "<h2>{$GLOBALS['strWatchAddSet']}</h2>";
            echo "<form id='dwiaddform' action='{$_SERVER['PHP_SELF']}?action=do_add&type={$type}' method='post' onsubmit='return false'>";
            echo "<table class='vertical'>";
            echo "<tr><td>";
            switch ($type) {
                case '0':
                    //site
                    echo "{$GLOBALS['strSite']}: ";
                    echo site_drop_down('id', '');
                    break;
                case '1':
                    //contact
                    echo "{$GLOBALS['strContact']}: ";
                    echo contact_drop_down('id', '');
                    break;
                case '2':
                    //engineer
                    echo "{$GLOBALS['strEngineer']}: ";
                    echo user_drop_down('id', '', FALSE);
                    break;
                case '3':
                    //Incident
                    echo "{$GLOBALS['strIncident']}:";
                    echo "<input class='textbox' name='id' size='30' />";
                    break;
            }
            echo "</td><tr>";
            echo "</table>";
            echo "<p align='center'>";
            echo dashlet_link('watch_incidents', $dashletid, $GLOBALS['strAdd'], 'save', array('editaction' => 'do_add', 'type' => $type), false, 'dwiaddform');
            echo "</p>";
            break;
        case 'do_add':
            $id = $_REQUEST['id'];
            $type = $_REQUEST['type'];
            $sql = "INSERT INTO `{$CONFIG['db_tableprefix']}dashboard_watch_incidents` VALUES ({$sit[2]},'{$type}','{$id}')";
            $result = mysql_query($sql);
            if (mysql_error()) {
                trigger_error(mysql_error(), E_USER_ERROR);
            }
            if (!$result) {
                echo "<p class='error'>{$GLOBALS['strWatchAddFailed']}</p>";
            } else {
                echo "<p>{$GLOBALS['strAddedSuccessfully']}</p>";
                echo dashlet_link('watch_incidents', $dashletid, $GLOBALS['strBackToList'], '', '', TRUE);
            }
            break;
        case 'delete':
            $id = $_REQUEST['id'];
            $type = $_REQUEST['type'];
            $sql = "DELETE FROM `{$CONFIG['db_tableprefix']}dashboard_watch_incidents` WHERE id = '{$id}' AND userid = {$sit[2]} AND type = '{$type}'";
            $result = mysql_query($sql);
            if (mysql_error()) {
                trigger_error(mysql_error(), E_USER_ERROR);
            }
            if (!$result) {
                echo "<p class='error'>{$GLOBALS['strWatchDeleteFailed']}</p>";
            } else {
                echo "<p>{$GLOBALS['strSuccess']}</p>";
                echo dashlet_link('watch_incidents', $dashletid, $GLOBALS['strBackToList'], '', '', TRUE);
            }
            break;
        default:
            echo "<h3>{$GLOBALS['strEditWatchedIncidents']}</h3>";
            echo "<table align='center'>";
            for ($i = 0; $i < 4; $i++) {
                $sql = "SELECT * FROM `{$CONFIG['db_tableprefix']}dashboard_watch_incidents` WHERE userid = {$sit[2]} AND type = {$i}";
                $result = mysql_query($sql);
                if (mysql_error()) {
                    trigger_error(mysql_error(), E_USER_WARNING);
                }
                echo "<tr><td align='left'><strong>";
                switch ($i) {
                    case 0:
                        echo $GLOBALS['strSites'];
                        break;
                    case 1:
                        echo $GLOBALS['strContacts'];
                        break;
                    case 2:
                        echo $GLOBALS['strEngineers'];
                        break;
                    case 3:
                        echo $GLOBALS['strIncidents'];
                        break;
                }
                echo "</strong></td><td align='right'>";
                switch ($i) {
                    case 0:
                        $linktext = $GLOBALS['strAddSite'];
                        break;
                    case 1:
                        $linktext = $GLOBALS['strAddContact'];
                        break;
                    case 2:
                        $linktext = $GLOBALS['strAddUser'];
                        break;
                    case 3:
                        $linktext = $GLOBALS['strAddIncident'];
                        break;
                }
                echo dashlet_link('watch_incidents', $dashletid, $linktext, 'edit', array('editaction' => 'add', 'type' => $i));
                echo "</td></tr>";
                if (mysql_num_rows($result) > 0) {
                    $shade = 'shade1';
                    while ($obj = mysql_fetch_object($result)) {
                        $name = '';
                        switch ($obj->type) {
                            case 0:
                                //site
                                $sql = "SELECT name FROM `{$GLOBALS['dbSites']}` WHERE id = {$obj->id}";
                                $iresult = mysql_query($sql);
                                if (mysql_error()) {
                                    trigger_error(mysql_error(), E_USER_WARNING);
                                }
                                $iobj = mysql_fetch_object($iresult);
                                $name = $iobj->name;
                                break;
                            case 1:
                                //contact
                                $sql = "SELECT forenames, surname FROM `{$GLOBALS['dbContacts']}` WHERE id = {$obj->id}";
                                $iresult = mysql_query($sql);
                                if (mysql_error()) {
                                    trigger_error(mysql_error(), E_USER_WARNING);
                                }
                                $iobj = mysql_fetch_object($iresult);
                                $name = $iobj->forenames . ' ' . $iobj->surname;
                                break;
                            case 2:
                                //Engineer
                                $sql = "SELECT realname FROM `{$GLOBALS['dbUsers']}` WHERE id = {$obj->id}";
                                $iresult = mysql_query($sql);
                                if (mysql_error()) {
                                    trigger_error(mysql_error(), E_USER_WARNING);
                                }
                                $iobj = mysql_fetch_object($iresult);
                                $name = $iobj->realname;
                                break;
                            case 3:
                                //Incident
                                $sql = "SELECT title FROM `{$GLOBALS['dbIncidents']}` WHERE id = {$obj->id}";
                                $iresult = mysql_query($sql);
                                if (mysql_error()) {
                                    trigger_error(mysql_error(), E_USER_WARNING);
                                }
                                $iobj = mysql_fetch_object($iresult);
                                $name = "<a href=\"javascript:incident_details_window('{$obj->id}','incident{$obj->id}')\" class='info'>[{$obj->id}] {$iobj->title}</a>";
                                break;
                        }
                        echo "<tr class='{$shade}'><td>{$name}</td><td>";
                        echo dashlet_link('watch_incidents', $dashletid, $GLOBALS['strRemove'], 'edit', array('editaction' => 'delete', 'id' => $obj->id, 'type' => $i));
                        if ($shade == 'shade1') {
                            $shade = 'shade2';
                        } else {
                            $shade = 'shade1';
                        }
                    }
                } else {
                    echo "<tr><td colspan='2'>{$GLOBALS['strNoIncidentsBeingWatchOfType']}</td></tr>";
                }
            }
            echo "</table>";
            break;
    }
    return $html;
}