<$mt:setvar name="page_title" value="<__trans phrase="Confirm Publishing Configuration">"$>
<$mt:setvar name="screen_type" value="restore-confirm-publishing-config"$>
<mt:setvarblock name="html_head" append="1">
<script type="text/javascript">
/* <![CDATA[ */
var websites_path = Array();
var websites_url  = Array();
<mt:loop name="all_websites">
websites_path['site_path_<mt:var name="website_id">'] = '<mt:var name="website_site_path"escape="js">';
websites_url['site_url_<mt:var name="website_id">'] = '<mt:var name="website_site_url" escape="js">';
</mt:loop>

function changeParent (ws) {

    var rex = RegExp("parent_id_([0-9]+)");
    if (ws.name.match(rex)) {
        blog_id = RegExp.$1;
    }

    var selected = ws.options[ws.selectedIndex].value;
    var new_path = '';
    var new_url = '';

    if (selected != 0) {
        new_path = websites_path['site_path_'+selected] + "<mt:var name="path_separator" escape="js">";
        new_url = websites_url['site_url_'+selected];
    }

    jQuery('.parent_site_path_'+blog_id).text(new_path);
    var matches = new_url.match(/(https?):\/\/(.+\/)$/);
    if ( matches && matches.length ) {
        jQuery('.parent_site_url_scheme_'+blog_id).text(matches[1] + '://');
        jQuery('.parent_site_url_domain_'+blog_id).text(matches[2]);
        jQuery('#site_url'+blog_id+'-field').removeClass('hidden');
        jQuery('#site_path'+blog_id+'-field').removeClass('hidden');
        jQuery('#archive_url'+blog_id+'-field').removeClass('hidden');
        jQuery('#archive_path'+blog_id+'-field').removeClass('hidden');
    }
}

function toggleWebsite() {
    if (jQuery('#adjust_sitepath').valid()) {
        jQuery('.for-website').hide();
        jQuery('.for-blog').show();
    }
}

function toggleBlog() {
    jQuery('.for-website').show();
    jQuery('.for-blog').hide();
}

function init() {
    jQuery('.parent_website').each( function () {
        this.onchange(this);
    });
}

/* ]]> */
</script>
</mt:setvarblock>
<mt:include name="dialog/header.tmpl">
<form name="adjust_sitepath" id="adjust_sitepath" method="post" action="<mt:var name="script_url">">
    <input type="hidden" name="__mode" value="adjust_sitepath" />
    <input type="hidden" name="magic_token" value="<mt:var name="magic_token">" />
    <input type="hidden" name="tmp_dir" value="<mt:var name="tmp_dir" escape="html">" />
    <input type="hidden" name="restore_upload" value="<mt:var name="restore_upload" escape="html">" />
    <input type="hidden" name="error" value="<mt:var name="error" escape="html">" />
    <input type="hidden" name="asset_ids" value="<mt:var name="asset_ids" escape="html">" />
    <input type="hidden" name="files" value="<mt:var name="files" escape="html">" />
    <input type="hidden" name="assets" value="<mt:var name="assets" escape="html">" />
    <input type="hidden" name="current_file" value="<mt:var name="name" escape="html">" />
    <input type="hidden" name="last" value="<mt:var name="last" escape="html">" />
    <input type="hidden" name="redirect" value="<mt:var name="redirect" escape="html">" />
    <input type="hidden" name="is_dirty" value="<mt:var name="is_dirty" escape="html">" />
    <input type="hidden" name="is_asset" value="<mt:var name="is_asset" escape="html">" />
    <input type="hidden" name="objects_json" value="<mt:var name="objects_json" escape="html">" />
    <input type="hidden" name="deferred_json" value="<mt:var name="deferred_json" escape="html">" />
    <input type="hidden" name="blogs_meta" value="<mt:var name="blogs_meta" escape="html">" />

    <div class="restore-publishing-paths">
        <div id="website-paths" class="for-website">
<mt:loop name="website_loop">
    <mt:if name="__first__"><h2><__trans phrase="Websites"></h2></mt:if>
        <fieldset>
            <h3><$mt:var name="name" escape="html"$> (<$mt:var name="id" escape="html"$>)</h3>
            <mtapp:setting
                id="site_url"
                label="<__trans phrase="Site URL">">
                <mt:if name="old_site_url">
                <input type="hidden" name="old_site_url_<mt:var name="id" escape="html">" id="old_site_url_<mt:var name="id" escape="html">" value="<mt:var name="old_site_url" escape="html">" />
                </mt:if>
                <input type="text" name="site_url_<mt:var name="id" escape="html">" id="site_url_<mt:var name="id" escape="html">" class="website-url-text site_url" value="<mt:var name="old_site_url" escape="html">" />
            </mtapp:setting>
            <mtapp:setting
                id="site_path"
                label="<__trans phrase="Site Path">">
                <mt:if name="old_site_path">
                <input type="hidden" name="old_site_path_<mt:var name="id" escape="html">" id="old_site_path_<mt:var name="id" escape="html">" value="<mt:var name="old_site_path" escape="html">" />
                </mt:if>
                <input type="text" name="site_path_<mt:var name="id" escape="html">" id="site_path_<mt:var name="id" escape="html">" class="website-path-text" value="<$mt:var name="old_site_path" escape="html"$>" />
            </mtapp:setting>
        </fieldset>
</mt:loop>
        </div>

        <div id="blog-paths" class="for-blog"<mt:if name="website_loop"> style="display: none"</mt:if>>
<mt:loop name="blogs_loop">
    <mt:if name="__first__"><h2><__trans phrase="Blogs"></h2></mt:if>
        <fieldset>
            <h3><$mt:var name="name" escape="html"$> (<$mt:var name="id" escape="html"$>)</h3>
            <mtapp:setting
                id="parent_id"
                label="<__trans phrase="Parent Website">">
                <select id="parent_id_<mt:var name="id">" name="parent_id_<mt:var name="id">" class="parent_website" onchange="changeParent(this)">
                    <option value="0"><__trans phrase="Please choose parent website."></option>
                    <mt:loop name="all_websites">
                        <option value="<mt:var name="website_id">"<mt:if name="parent_id" eq="$website_id"> selected</mt:if>> <mt:var name="website_name" escape="html"></option>
                    </mt:loop>
                </select>
            </mtapp:setting>

            <mt:setvarblock name="site_url_id">site_url<mt:var name="id"></mt:setvarblock>
            <mtapp:setting
                id="$site_url_id"
                class="url-field hidden"
                label="<__trans phrase="Site URL">">
            <mt:if name="old_site_url_subdomain">
                <div class="site-url">
                    <span class="parent_site_url_scheme_<mt:var name="id">">&nbsp;</span><span class="subdomain"><input type="text" name="site_url_subdomain_<mt:var name="id" escape="html">" id="site_url_subdomain_<mt:var name="id" escape="html">" class="blog-subdomain-text extra-path" value="<mt:var name="old_site_url_subdomain" escape="html">" />.</span><span class="website-url"><span class="parent_site_url_domain_<mt:var name="id">">&nbsp;</span></span><span class="extra-path"><input type="text" name="site_url_path_<mt:var name="id" escape="html">" id="site_url_path_<mt:var name="id" escape="html">" class="blog-url-text extra-path" value="<mt:var name="old_site_url_path" escape="html">" /></span>
                </div>
                <div class="use_subdomain">
                    <input type="checkbox" name="use_subdomain_<mt:var name="id">" id="use_subdomain_<mt:var name="id">" value="1" checked="checked" class="cb" /> <label for="use_subdomain_<mt:var name="id">"><__trans phrase="Use subdomain"></label>
                </div>
            <mt:elseif name="old_site_url_path">
                <div class="site-url">
                    <span class="parent_site_url_scheme_<mt:var name="id">">&nbsp;</span><span class="subdomain"><input type="text" name="site_url_subdomain_<mt:var name="id" escape="html">" id="site_url_subdomain_<mt:var name="id" escape="html">" class="blog-subdomain-text extra-path" value="<mt:var name="old_site_url_subdomain" escape="html">" />.</span><span class="website-url"><span class="parent_site_url_domain_<mt:var name="id">">&nbsp;</span></span><span class="extra-path"><input type="text" name="site_url_path_<mt:var name="id" escape="html">" id="site_url_path_<mt:var name="id" escape="html">" class="blog-url-text extra-path" value="<mt:var name="old_site_url_path" escape="html">" /></span>
                </div>
                <div class="use_subdomain">
                    <input type="checkbox" name="use_subdomain_<mt:var name="id">" id="use_subdomain_<mt:var name="id">" value="1" class="cb" /> <label for="use_subdomain_<mt:var name="id">"><__trans phrase="Use subdomain"></label>
                </div>
            <mt:else>
                <div class="site-url">
                    <span class="parent_site_url_scheme_<mt:var name="id">">&nbsp;</span><span class="subdomain"><input type="text" name="site_url_subdomain_<mt:var name="id" escape="html">" id="site_url_subdomain_<mt:var name="id" escape="html">" class="blog-subdomain-text extra-path" value="<mt:var name="old_site_url_subdomain" escape="html">" />.</span><span class="website-url"><span class="parent_site_url_domain_<mt:var name="id">">&nbsp;</span></span><span class="extra-path"><input type="text" name="site_url_path_<mt:var name="id" escape="html">" id="site_url_path_<mt:var name="id" escape="html">" class="blog-url-text extra-path" value="<mt:var name="old_site_url_path" escape="html">" /></span>
                </div>
                <div class="use_subdomain">
                    <input type="checkbox" name="use_subdomain_<mt:var name="id">" id="use_subdomain_<mt:var name="id">" value="1" class="cb" /> <label for="use_subdomain_<mt:var name="id">"><__trans phrase="Use subdomain"></label>
                </div>
            </mt:if>
            </mtapp:setting>

            <mt:setvarblock name="site_path_id">site_path<mt:var name="id"></mt:setvarblock>
            <mtapp:setting
                id="$site_path_id"
                class="site-path-field hidden"
                label="<__trans phrase="Site Path">">
            <mt:if name="old_site_path">
                <input type="hidden" name="old_site_path_<mt:var name="id" escape="html">" id="old_site_path_<mt:var name="id" escape="html">" value="<mt:var name="old_site_path" escape="html">" />
            </mt:if>
                <span class="website-path"><span class="parent_site_path_<mt:var name="id"><mt:if name="site_path_absolute"> hidden</mt:if>">&nbsp;</span></span><input type="text" name="site_path_<mt:var name="id" escape="html">" id="site_path_<mt:var name="id" escape="html">" class="blog-path-text extra-path" value="<$mt:var name="old_site_path" escape="html"$>" />
            </mtapp:setting>

            <mt:if name="old_archive_url">
            <mt:setvarblock name="archive_url_id">archive_url<mt:var name="id"></mt:setvarblock>
            <mtapp:setting
                id="$archive_url_id"
                class="url-field hidden"
                label="<__trans phrase="Archive URL">">
                <input type="hidden" name="old_archive_url_<mt:var name="id" escape="html">" id="old_archive_url_<mt:var name="id" escape="html">" value="<mt:var name="old_archive_url" escape="html">" />
            <mt:if name="old_archive_url_subdomain">
                <div class="archive-url">
                    <span class="parent_site_url_scheme_<mt:var name="id">">&nbsp;</span><span class="subdomain"><input type="text" name="archive_url_subdomain_<mt:var name="id" escape="html">" id="archive_url_subdomain_<mt:var name="id" escape="html">" class="blog-subdomain-text extra-path" value="<mt:var name="old_archive_url_subdomain" escape="html">" />.</span><span class="website-url"><span class="parent_site_url_domain_<mt:var name="id">">&nbsp;</span></span><span class="extra-path"><input type="text" name="archive_url_path_<mt:var name="id" escape="html">" id="archive_url_<mt:var name="id" escape="html">" class="blog-url-text extra-path" value="<mt:var name="old_archive_url_path" escape="html">" /></span>
                </div>
                <div class="use-subdomain">
                    <input type="checkbox" name="use_archive_subdomain_<mt:var name="id">" id="use_archive_subdomain_<mt:var name="id">" value="1" checked="checked" class="cb" /> <label for="use_archive_subdomain_<mt:var name="id">"><__trans phrase="Use subdomain"></label>
                </div>
            <mt:elseif name="old_archive_url_path">
                <div class="archive-url">
                    <span class="parent_site_url_scheme_<mt:var name="id">">&nbsp;</span><span class="subdomain"><input type="text" name="archive_url_subdomain_<mt:var name="id" escape="html">" id="archive_url_subdomain_<mt:var name="id" escape="html">" class="blog-subdomain-text extra-path" value="<mt:var name="old_archive_url_subdomain" escape="html">" />.</span><span class="webarchive-url"><span class="parent_site_url_domain_<mt:var name="id">">&nbsp;</span></span><span class="extra-path"><input type="text" name="archive_url_path_<mt:var name="id" escape="html">" id="archive_url_path_<mt:var name="id" escape="html">" class="blog-url-text extra-path" value="<mt:var name="old_archive_url_path" escape="html">" /></span>
                </div>
                <div class="use_subdomain">
                    <input type="checkbox" name="use_subdomain_<mt:var name="id">" id="use_subdomain_<mt:var name="id">" value="1" class="cb" /> <label for="use_subdomain_<mt:var name="id">"><__trans phrase="Use subdomain"></label>
                </div>
            <mt:elseif name="old_archive_url">
                <div class="archive-url">
                    <span class="parent_site_url_scheme_<mt:var name="id">">&nbsp;</span><span class="subdomain"><input type="text" name="archive_url_subdomain_<mt:var name="id" escape="html">" id="archive_url_subdomain_<mt:var name="id" escape="html">" class="blog-subdomain-text extra-path" value="<mt:var name="old_archive_url_subdomain" escape="html">" />.</span><span class="website-url"><span class="parent_site_url_domain_<mt:var name="id">">&nbsp;</span></span><span class="extra-path"><input type="text" name="archive_url_<mt:var name="id" escape="html">" id="archive_url_<mt:var name="id" escape="html">" class="blog-url-text extra-path" value="<mt:var name="old_archive_url" escape="html">" /></span>
                </div>
                <div class="use-subdomain">
                    <input type="checkbox" name="use_archive_subdomain_<mt:var name="id">" id="use_archive_subdomain_<mt:var name="id">" value="1" class="cb" /> <label for="use_archive_subdomain_<mt:var name="id">"><__trans phrase="Use subdomain"></label>
                </div>
            </mt:if>
            </mtapp:setting>
            </mt:if>

            <mt:if name="old_archive_path">
            <mt:setvarblock name="archive_path_id">archive_path<mt:var name="id"></mt:setvarblock>
            <mtapp:setting
                id="$archive_path_id"
                class="site-path-field hidden"
                label="<__trans phrase="Archive Path">">
                <input type="hidden" name="old_archive_path_<mt:var name="id" escape="html">" id="old_archive_path_<mt:var name="id" escape="html">" value="<mt:var name="old_archive_path" escape="html">" />
                <span class="website-path"><span class="parent_site_path_<mt:var name="id"><mt:if name="site_path_absolute"> hidden</mt:if>">&nbsp;</span></span><input type="text" name="archive_path_<mt:var name="id" escape="html">" id="archive_path_<mt:var name="id" escape="html">" class="blog-path-text extra-path" value="<mt:var name="old_archive_path" escape="html">" />
            </mtapp:setting>
            </mt:if>

        </fieldset>
</mt:loop>
        </div>
    </div>
    <div class="actions-bar">
        <button
            value="<__trans phrase="Continue">"
            type="submit"
            accesskey="s"
            title="<__trans phrase="Continue (s)">"
            class="continue action primary-button for-blog"<mt:if name="website_loop">
            style="display: none"</mt:if>
            ><__trans phrase="Continue"></button>
<mt:if name="website_loop">
        <button
            value="<__trans phrase="Back">"
            type="button"
            accesskey="b"
            title="<__trans phrase="Back (b)">"
            class="back action for-blog"
            onclick="toggleBlog();"
            style="display: none"
            ><__trans phrase="Back"></button>
        <button
            value="<__trans phrase="Continue">"
            type="button"
            accesskey="s"
            title="<__trans phrase="Continue (s)">"
            class="continue action primary-button for-website"
            onclick="toggleWebsite();"
            ><__trans phrase="Continue"></button>
</mt:if>
    </div>
</form>

<script type="text/javascript">
/* <![CDATA[ */
    function is_valid_url(url_){
        return url_.match( /^https?:\/\/[A-Za-z0-9!$%()=_.:,;@~-]+/ );
    }
    function is_valid_path(path_){
        var str = path_.replace(/[ "%<>\[\\\]\^`{\|}~]/g, "");
        str = encodeURI(str);
        if (str.indexOf('%') != -1) {
            return false;
        }
        if (str.match(/\.\./)) {
            return false;
        }
        return true;
    }
/* ]]> */
</script>
<mt:setvarblock name="jq_js_include" append="1">
    init();

    jQuery.validator.addMethod('url', function(value, element) {
        rex = RegExp("site_url_([0-9]+)");
        parent_url = '';
        if (element.name.match(rex)) {
            b_id = RegExp.$1;
            parent_url = jQuery('.parent_site_url_'+b_id).text();
        }
        if (parent_url == '' && value == '')
            return false;

        return is_valid_url(parent_url + value);
    });

    jQuery.validator.addMethod('path', function(value, element) {
        rex = RegExp("site_path_([0-9]+)");
        parent_path = '';
        if (element.name.match(rex)) {
            b_id = RegExp.$1;
            parent_path = jQuery('.parent_site_path_'+b_id).text();
        }
        if (parent_path == '' && value == '')
            return false;

        return is_valid_path(parent_path + value);
    });

    jQuery('#adjust_sitepath').validate({
        rules: {
<mt:loop name="website_loop">
            site_url_<mt:var name="id" escape="html">: {
                required: true,
                url: true
            },
            site_path_<mt:var name="id" escape="html">: {
                required: true,
                path: true
            }<mt:unless name="__last__">,<mt:else><mt:if name="blogs_loop">,</mt:if></mt:unless>
</mt:loop>
<mt:loop name="blogs_loop">
            site_url_<mt:var name="id" escape="html">: 'url',
            site_path_<mt:var name="id" escape="html">: 'path',
            parent_id_<mt:var name="id">: {
                min: 1
            }<mt:unless name="__last__">,</mt:unless>
</mt:loop>
        },
        messages: {
<mt:loop name="website_loop">
            site_url_<mt:var name="id" escape="html">: {
                required: '<__trans phrase="You must set a valid Site URL." escape="singlequotes">',
                url: '<__trans phrase="You must set a valid Site URL." escape="singlequotes">'
            },
            site_path_<mt:var name="id" escape="html">: {
                required: '<__trans phrase="You must set your Local Site Path." escape="singlequotes">',
                path: '<__trans phrase="You must set a valid Local Site Path." escape="singlequotes">'
            }<mt:unless name="__last__">,<mt:else><mt:if name="blogs_loop">,</mt:if></mt:unless>
</mt:loop>
<mt:loop name="blogs_loop">
            site_url_<mt:var name="id" escape="html">: {
                url: '<__trans phrase="You must set a valid Site URL." escape="singlequotes">'
            },
            site_path_<mt:var name="id" escape="html">: {
                path: '<__trans phrase="You must set a valid Local Site Path." escape="singlequotes">'
            },
            parent_id_<mt:var name="id">: {
                min: '<__trans phrase="You must select a parent website." escape="singlequotes">'
            }<mt:unless name="__last__">,</mt:unless>
</mt:loop>
        },
        errorClass: "msg-error",
        errorPlacement: function(error, element) {
            element.parents('div.field').addClass('error-field');
            error.removeAttr('generated').insertAfter(element);
        }
    });

    jQuery('.website-path-text').change( function () {
        websites_path[this.name] = this.value;

        var rex = RegExp("site_path_([0-9]+)");
        if (this.name.match(rex)) {
            var id = RegExp.$1;
            jQuery('.parent_website').each( function () {
                if (this.value == id) {
                    this.onchange(this);
                    return;
                }
            });
        }
    });

    jQuery('.website-url-text').change( function () {
        websites_url[this.name] = this.value;
        var rex = RegExp("site_url_([0-9]+)");
        if (this.name.match(rex)) {
            var id = RegExp.$1;
            jQuery('.parent_website').each( function () {
                if (this.value == id) {
                    this.onchange(this);
                    return;
                }
            });
        }
    });

    jQuery.mtUseSubdomain();
    jQuery.mtEditSitePath();
</mt:setvarblock>
<mt:include name="dialog/footer.tmpl">
