/**
 * validate Local Files
 */
function validateLocalFiles()
{
    sendLine('<h3>Validate Files</h3>');
    sendLine('<strong>Getting Checksum-list</strong>');
    // download list
    $checksumsString = "";
    @ini_set("allow_url_fopen", "1");
    @ini_set("user_agent", "torrentflux-b4rt/" . _VERSION);
    if ($urlHandle = @fopen(_SUPERADMIN_URLBASE . _FILE_CHECKSUMS_PRE . _VERSION . _FILE_CHECKSUMS_SUF, 'r')) {
        stream_set_timeout($urlHandle, 15);
        $info = stream_get_meta_data($urlHandle);
        while (!feof($urlHandle) && !$info['timed_out']) {
            $checksumsString .= @fgets($urlHandle, 8192);
            $info = stream_get_meta_data($urlHandle);
            sendLine('.');
        }
        @fclose($urlHandle);
    }
    if (empty($checksumsString)) {
        exit('error getting checksum-list from ' . _SUPERADMIN_URLBASE);
    }
    sendLine('<font color="green">done</font><br>');
    sendLine('<br><strong>Processing list</strong>');
    // remote Checksums
    $remoteChecksums = array();
    $remoteSums = explode("\n", $checksumsString);
    $remoteSums = array_map('trim', $remoteSums);
    foreach ($remoteSums as $remSum) {
        $tempAry = explode(";", $remSum);
        if (!empty($tempAry[0]) && !empty($tempAry[1])) {
            $remoteChecksums[$tempAry[0]] = $tempAry[1];
            sendLine('.');
        }
    }
    $remoteChecksumsCount = count($remoteChecksums);
    sendLine('<font color="green">done</font> (' . $remoteChecksumsCount . ')<br>');
    // local Checksums
    sendLine('<br><strong>Getting local checksums</strong>');
    $localChecksums = getFileChecksums(true);
    $localChecksumsCount = count($localChecksums);
    sendLine('<font color="green">done</font> (' . $localChecksumsCount . ')<br>');
    // init some arrays
    $filesMissing = array();
    $filesNew = array();
    $filesOk = array();
    $filesChanged = array();
    // validate
    sendLine('<br><strong>Validating...</strong><br>');
    // validate pass 1
    foreach ($remoteChecksums as $file => $md5) {
        $line = tfb_htmlencodekeepspaces($file);
        if (isset($localChecksums[$file])) {
            if ($md5 == $localChecksums[$file]) {
                array_push($filesOk, $file);
                $line .= ' <font color="green"> Ok</font>';
            } else {
                array_push($filesChanged, $file);
                $line .= ' <font color="red"> Changed</font>';
            }
        } else {
            array_push($filesMissing, $file);
            $line .= ' <font color="red"> Missing</font>';
        }
        sendLine($line . "<br>");
    }
    // validate pass 2
    foreach ($localChecksums as $file => $md5) {
        if (!isset($remoteChecksums[$file])) {
            array_push($filesNew, $file);
        }
    }
    // summary
    sendLine('<h3>Done.</h3>');
    // files Total
    sendLine('<strong>' . _VERSION . ': </strong>' . $remoteChecksumsCount . '<br>');
    sendLine('<strong>Local: </strong>' . $localChecksumsCount . '<br>');
    // files Ok
    sendLine('<strong>Unchanged: </strong>' . count($filesOk) . '<br>');
    // files Missing
    sendLine('<strong>Missing: </strong>' . count($filesMissing) . '<br>');
    // files Changed
    sendLine('<strong>Changed: </strong>' . count($filesChanged) . '<br>');
    // files New
    sendLine('<strong>New: </strong>' . count($filesNew) . '<br>');
    if (count($filesNew) > 0) {
        sendLine('<br><strong>New Files: </strong><br>');
        foreach ($filesNew as $newFile) {
            sendLine(tfb_htmlencodekeepspaces($newFile) . '<br>');
        }
    }
}
     $tmpl->setvar('new_msg', 1);
     $tmpl->setvar('message', "Error : No Filtername.");
 } else {
     if (FluxdRssad::filterIdCheck($filtername, false) === true) {
         // create the filter
         if (FluxdRssad::filterExists($filtername) === true) {
             $tmpl->setvar('filtername', $filtername);
             $content = trim(FluxdRssad::filterGetContent($filtername));
             $tmpl->setvar('rssad_filtercontent', tfb_htmlencode($content));
             $filterlines = explode("\n", $content);
             if (count($filterlines) > 0) {
                 $filterlist = array();
                 foreach ($filterlines as $filterline) {
                     $filt = trim($filterline);
                     if (strlen($filt) > 0) {
                         array_push($filterlist, array("filter" => tfb_htmlencodekeepspaces($filt)));
                     }
                 }
                 $tmpl->setloop('rssad_filter_list', $filterlist);
             }
         } else {
             $tmpl->setvar('new_msg', 1);
             $tmpl->setvar('message', "Error : Filter does not exist.");
         }
     } else {
         $tmpl->setvar('new_msg', 1);
         $tmpl->setvar('message', "Error : Invalid Filtername.");
     }
 }
 // title-bar
 tmplSetTitleBar("Administration - Fluxd Rssad - Edit Filter");