but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.

 To read the license please visit http://www.gnu.org/copyleft/gpl.html

*******************************************************************************/
// prevent direct invocation
if (!isset($cfg['user']) || isset($_REQUEST['cfg'])) {
    @ob_end_clean();
    @header("location: ../../index.php");
    exit;
}
/******************************************************************************/
// common functions
require_once 'inc/functions/functions.common.php';
// transfer functions
require_once 'inc/functions/functions.transfer.php';
// init template-instance
tmplInitializeInstance($cfg["theme"], "page.transferLog.tmpl");
// init transfer
transfer_init();
// log-content
$tmpl->setvar('transferLog', getTransferLog($transfer));
// title + foot
tmplSetFoot(false);
tmplSetTitleBar($transferLabel . " - Log", false);
// iid
tmplSetIidVars();
// parse template
$tmpl->pparse();
/**
 * log
 *
 * @param $action
 */
function sa_log($action = "")
{
    global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
    if ($action == "") {
        return;
    }
    buildPage("l");
    switch ($action) {
        case "0":
            // log-main
            $htmlTitle = "Log Viewer";
            $htmlMain .= '<br>Select the type of log you want to view below:<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?l=1"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="fluxd" border="0"> fluxd</a> - STDOUT logfiles for the torrentflux-b4rt fluxd daemon';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?l=2"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="fluxd-error" border="0"> fluxd-error</a> - STDERR logfiles for the torrentflux-b4rt fluxd daemon';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?l=3"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="fluazu" border="0"> fluazu</a> - logfiles for the fluazu interface to Azureus';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?l=5"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="mainline" border="0"> BitTorrent Mainline</a> - centralised logfile for the BitTorrent Mainline client';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?l=8"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="transfers" border="0"> Transfers</a> - logfiles for transfers in the current transfer list';
            $htmlMain .= '<br><br>';
            break;
        case "1":
            // fluxd-log
            $htmlTitle = "log - fluxd";
            $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"] . '.fluxd/fluxd.log'));
            $htmlMain .= '</pre>';
            $htmlMain .= '</div>';
            break;
        case "2":
            // fluxd-error-log
            $htmlTitle = "log - fluxd - error-log";
            $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"] . '.fluxd/fluxd-error.log'));
            $htmlMain .= '</pre>';
            $htmlMain .= '</div>';
            break;
        case "3":
            // fluazu-log
            $htmlTitle = "log - fluazu";
            $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"] . '.fluazu/fluazu.log'));
            $htmlMain .= '</pre>';
            $htmlMain .= '</div>';
            break;
        case "5":
            // mainline-log
            $htmlTitle = "log - mainline";
            $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
            $htmlMain .= '<pre>';
            $mainlineLog = $cfg["path"] . '.bittorrent/tfmainline.log';
            if (is_file($mainlineLog)) {
                $htmlMain .= tfb_htmlencode(@file_get_contents($mainlineLog));
            } else {
                $htmlMain .= "mainline-log not found.";
            }
            $htmlMain .= '</pre>';
            $htmlMain .= '</div>';
            break;
        case "8":
            // transfers
            $htmlTitle = "log - transfers";
            $htmlMain .= "<br>Select the transfer you wish to view the logfile for from below:<br>";
            $logList = getTransferArray('na');
            if (isset($logList) && is_array($logList)) {
                $htmlMain .= '<ul>';
                foreach ($logList as $logFile) {
                    if (isset($logFile) && $logFile != "") {
                        $htmlMain .= '<li>';
                        $htmlMain .= '<a href="' . _FILE_THIS . '?l=9&transfer=' . urlencode($logFile) . '">';
                        $htmlMain .= tfb_htmlencode($logFile);
                        $htmlMain .= '</a>';
                        $htmlMain .= '</li>';
                    }
                }
                $htmlMain .= '</ul>';
            }
            break;
        case "9":
            // transfer-log
            if (isset($_REQUEST["transfer"])) {
                $transfer = trim(tfb_getRequestVarRaw('transfer'));
                // shorten name if too long
                if (strlen($transfer) >= 70) {
                    $htmlTitle = "log - transfer-log - " . tfb_htmlencodekeepspaces(substr($transfer, 0, 67)) . "...";
                } else {
                    $htmlTitle = "log - transfer-log - " . tfb_htmlencodekeepspaces($transfer);
                }
                $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
                $htmlMain .= '<pre>';
                $htmlMain .= tfb_htmlencode(getTransferLog($transfer));
                $htmlMain .= '</pre>';
                $htmlMain .= '</div>';
            } else {
                $htmlTitle = "log - transfer-log";
                $htmlMain .= '<font color="red">Error. missing params</font>';
            }
            break;
    }
    printPage();
    exit;
}