function wb_handle_upload()
{
    global $DR_TEXT, $TEXT, $database, $admin;
    if (isset($_POST['cancel'])) {
        return;
    }
    if (!isset($_FILES['userfile']) && !isset($_FILES['userfile']['name'])) {
        ?>
    <form method="post" action="<?php 
        echo ADMIN_URL;
        ?>
/admintools/tool.php?tool=droplets&amp;upload=1" enctype="multipart/form-data" name="upload">
<?php 
        if (method_exists($admin, 'getFTAN')) {
            echo $admin->getFTAN();
        }
        ?>
      <fieldset class="fieldset">
        <legend><?php 
        echo $DR_TEXT['UPLOAD'];
        ?>
</legend>
        <table>
          <tbody>
            <tr>
              <td>
                <input type="file" name="userfile" size="50" />
                <script type="text/javascript">document.upload.userfile.focus();</script>
              </td>
            </tr>
            <tr>
              <td>
                <input type="submit" class="button" value="<?php 
        echo $DR_TEXT['UPLOAD'];
        ?>
" name="submit" />
                <input type="submit" class="button" value="<?php 
        echo $TEXT['CANCEL'];
        ?>
" name="cancel" />
              </td>
            </tr>
          </tbody>
        </table>
      </fieldset>
    </form>
<?php 
    } else {
        // Set temp vars
        $temp_dir = WB_PATH . '/temp/';
        $temp_file = $temp_dir . $_FILES['userfile']['name'];
        $temp_unzip = WB_PATH . '/temp/unzip/';
        $errors = array();
        // Try to upload the file to the temp dir
        if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
            echo $DR_TEXT['Upload failed'];
            return;
        }
        $result = wb_unpack_and_import($temp_file, $temp_unzip);
        // Delete the temp zip file
        if (file_exists($temp_file)) {
            unlink($temp_file);
        }
        rm_full_dir($temp_unzip);
        // show errors
        if (isset($result['errors']) && is_array($result['errors']) && count($result['errors']) > 0) {
            echo '<div style="border: 1px solid #f00; padding: 5px; color: #f00; font-weight: bold;">', $DR_TEXT['IMPORT_ERRORS'], "<br />\n";
            foreach ($result['errors'] as $droplet => $error) {
                echo 'Droplet: ', $droplet, '<br />', '<span style="padding-left: 15px">', $error, '</span>';
            }
            echo "</div>\n";
        }
        echo '<div class="drok">', $result['count'], " ", $DR_TEXT['IMPORTED'], '</div>';
        return $result['imported'];
    }
}
                        // Already in the DB?
                        $stmt = 'INSERT';
                        $id = NULL;
                        $found = $database->get_one("SELECT * FROM " . TABLE_PREFIX . "mod_droplets WHERE name='{$name}'");
                        if ($found && $found > 0) {
                            $stmt = 'REPLACE';
                            $id = $found;
                        }
                        // execute
                        $result = $database->query("{$stmt} INTO " . TABLE_PREFIX . "mod_droplets VALUES('{$id}','{$name}','{$code}','{$description}','" . time() . "','" . $admin->get_user_id() . "',1,0,0,0,'{$usage}')");
                        if (!$database->is_error()) {
                            $count++;
                            $imports[$name] = 1;
                        } else {
                            $errors[$name] = $database->get_error();
                        }
                    }
                }
            }
            closedir($dh);
        }
        if (!isset($imports)) {
            $imports = array();
        }
        return array('count' => $count, 'errors' => $errors, 'imported' => $imports);
    }
    // function wb_unpack_and_import()
}
// install the droplet(s)
wb_unpack_and_import(WB_PATH . '/modules/topics/droplets/droplet_topics_rss_statistic.zip', WB_PATH . '/temp/unzip/');
// ----- added by WebBird, 2010-11-16 -----
if (isset($_GET['copy'])) {
    $id = $_GET['copy'];
    if (version_compare(WB_VERSION, '2.8.2', '>=') && WB_VERSION != "2.8.x") {
        $id = $admin->checkIDKEY('copy', NULL, 'GET');
    }
    if (is_numeric($id)) {
        wb_handle_copy($id);
    }
}
// ----- added by WebBird, 2010-11-02 -----
if (isset($_GET['upload']) && $_GET['upload']) {
    $new = wb_handle_upload();
}
if (isset($_GET['recover']) && file_exists(WB_PATH . '/modules/droplets/export/' . $_GET['recover'])) {
    $result = wb_unpack_and_import(WB_PATH . '/modules/droplets/export/' . $_GET['recover'], WB_PATH . '/temp/unzip/');
    // show errors
    if (isset($result['errors']) && is_array($result['errors']) && count($result['errors']) > 0) {
        echo '<div style="border: 1px solid #f00; padding: 5px; color: #f00; font-weight: bold;">', $DR_TEXT['IMPORT_ERRORS'], "<br />\n";
        foreach ($result['errors'] as $droplet => $error) {
            echo 'Droplet: ', $droplet, '<br />', '<span style="padding-left: 15px">', $error, '</span>';
        }
        echo "</div>\n";
    } else {
        $new = isset($result['imported']) ? $result['imported'] : array();
        echo '<div class="drok">', $result['count'], " ", $DR_TEXT['IMPORTED'], '</div>';
    }
}
if (isset($_REQUEST['export']) && $_REQUEST['export']) {
    wb_handle_export();
}
                        $id = NULL;
                        $found = $database->get_one("SELECT * FROM " . TABLE_PREFIX . "mod_droplets WHERE name='{$name}'");
                        if ($found && $found > 0) {
                            $stmt = 'REPLACE';
                            $id = $found;
                        }
                        // execute
                        $result = $database->query("{$stmt} INTO " . TABLE_PREFIX . "mod_droplets VALUES('{$id}','{$name}','{$code}','{$description}','" . time() . "','" . $admin->get_user_id() . "',1,0,0,0,'{$usage}')");
                        if (!$database->is_error()) {
                            $count++;
                            $imports[$name] = 1;
                        } else {
                            $errors[$name] = $database->get_error();
                        }
                    }
                }
            }
            closedir($dh);
        }
        return array('count' => $count, 'errors' => $errors, 'imported' => $imports);
    }
    // function wb_unpack_and_import()
}
// install the droplet(s)
wb_unpack_and_import(WB_PATH . '/modules/wysiwyg/droplets/droplet_wysiwyg_teaser.zip', WB_PATH . '/temp/unzip/');
require_once LEPTON_PATH . '/modules/manufaktur_config/library.php';
// initialize the configuration
$config = new manufakturConfig();
if (!$config->readXMLfile(LEPTON_PATH . '/modules/wysiwyg/config/extendedWYSIWYG.xml', 'wysiwyg', true)) {
    $admin->print_error($config->getError());
}