/**
 * Updates the LANG.js file if necessary, with the strings from LANG.php.
 * Returns false on failure.
 *
 * @return bool
 *
 * @global array  The paths of system files and folders.
 * @global string The current language.
 * @global array  The localization of the plugins.
 */
function Advancedform_updateLangJs()
{
    global $pth, $sl, $plugin_tx;
    $ptx = $plugin_tx['advancedform'];
    $fn = $pth['folder']['plugins'] . 'advancedform/languages/' . $sl;
    if (!file_exists($fn . '.php')) {
        e('missing', 'language', $fn . '.php');
        return false;
    }
    if (!file_exists($fn . '.js') || filemtime($fn . '.js') < filemtime($fn . '.php')) {
        $js = '// auto-generated by Advancedform_XH -- do not modify!' . PHP_EOL . '// any modifications should be made in ' . $sl . '.php' . PHP_EOL . PHP_EOL . 'ADVFRM_TX = {' . PHP_EOL;
        $first = true;
        foreach ($ptx as $key => $msg) {
            $parts = explode('_', $key);
            if ($parts[0] != 'cf') {
                if ($first) {
                    $first = false;
                } else {
                    $js .= ',' . PHP_EOL;
                }
                $js .= '    \'' . $key . '\': \'' . Advancedform_escapeJsString($msg) . '\'';
            }
        }
        $js .= PHP_EOL . '};' . PHP_EOL;
        if (!($fh = fopen($fn . '.js', 'w')) || ($res = fwrite($fh, $js)) === false) {
            e('cntwriteto', 'file', $fn . '.js');
        }
        if ($fh) {
            fclose($fh);
        }
        return $fh && $res;
    }
    return true;
}
/**
 * Returns the mail forms administration.
 *
 * @return string (X)HTML.
 *
 * @global string The script name.
 * @global array  The localization of the core.
 * @global array  The localization of the plugins.
 */
function Advancedform_formsAdministration()
{
    global $sn, $tx, $plugin_tx;
    $ptx = $plugin_tx['advancedform'];
    $forms = Advancedform_db();
    $o = '<div id="advfrm-form-list">' . PHP_EOL . '<h1>' . $ptx['menu_main'] . '</h1>' . PHP_EOL;
    $href = $sn . '?advancedform&amp;admin=plugin_main&amp;action=new';
    $o .= Advancedform_toolForm('add', $href);
    $href = $sn . '?advancedform&amp;admin=plugin_main&amp;action=import&amp;form=';
    $o .= Advancedform_toolForm('import', $href, 'return advfrm_import(this)');
    $o .= '<table>' . PHP_EOL;
    foreach ($forms as $id => $form) {
        if ($id != '%VERSION%') {
            $href = $sn . '?advancedform&amp;admin=plugin_main&amp;action=%s' . '&amp;form=' . $id;
            $o .= '<tr>' . '<td class="tool">' . Advancedform_toolForm('delete', sprintf($href, 'delete'), 'return confirm(\'' . Advancedform_escapeJsString($ptx['message_confirm_delete']) . '\')') . '</td>' . '<td class="tool">' . Advancedform_toolForm('template', sprintf($href, 'template'), 'return confirm(\'' . Advancedform_escapeJsString(sprintf($ptx['message_confirm_template'], $form['name'])) . '\')') . '</td>' . '<td class="tool">' . Advancedform_toolForm('copy', sprintf($href, 'copy')) . '</td>' . '<td class="tool">' . Advancedform_toolForm('export', sprintf($href, 'export'), 'return confirm(\'' . Advancedform_escapeJsString(sprintf($ptx['message_confirm_export'], $form['name'])) . '\')') . '</td>' . '<td class="name"><a href="' . sprintf($href, 'edit') . '" title="' . ucfirst($tx['action']['edit']) . '">' . $id . '</a></td>' . '<td class="script" title="' . $ptx['message_script_code'] . '">' . '{{{PLUGIN:advancedform(\'' . $id . '\');}}}</td>' . '</tr>' . PHP_EOL;
        }
    }
    $o .= '</table>' . PHP_EOL;
    $o .= '</div>' . PHP_EOL;
    return $o;
}