}
     if (count($return)) {
         $top_message = array('type' => 'E', 'content' => cw_get_langvar_by_name('lbl_mdm_error_copy_skin', array('log' => implode('<br/>', $return)), false, true));
     }
     cw_header_location("index.php?target={$target}");
 } elseif ($action == 'copy_basic') {
     $smarty->assign('main', 'copy');
     $data = cw_func_call('cw_md_domain_get', array('domain_id' => $domain_id));
     $smarty->assign('altskin', $data['skin']);
     $smarty->assign('domain_id', $domain_id);
 }
 if ($action == 'cleanup') {
     $data = cw_func_call('cw_md_domain_get', array('domain_id' => $domain_id));
     $return = false;
     if ($data['skin'] && $data['skin'] != $app_config_file['web']['skin']) {
         $return = cw_md_cleanup_skin($app_dir . $app_config_file['web']['skin'], $app_dir . $data['skin'], '/');
     }
     $smarty->assign('result', $return);
     $smarty->assign('altskin', $data['skin']);
     $smarty->assign('main', 'cleanup');
 }
 if (empty($action)) {
     $smarty->assign('main', 'domains');
     $domains = cw_md_get_domains();
     if (is_array($domains)) {
         foreach ($domains as $key => $domain) {
             $domains[$key]['attributes'] = cw_func_call('cw_attributes_get', array('item_id' => $domain['domain_id'], 'item_type' => 'DM', 'language' => $edited_language));
             if (is_array($domains[$key]['attributes'])) {
                 foreach ($domains[$key]['attributes'] as $akey => $attr) {
                     $domains[$key]['attributes'][$akey]['fieldname'] = "posted_data[" . $domain['domain_id'] . "][attribute]";
                 }
function cw_md_cleanup_skin($dir, $dir_, $int = '')
{
    global $app_dir;
    $int = with_leading_slash($int);
    if (!cw_allowed_path($app_dir, $dir . $int)) {
        return false;
    }
    if (!cw_allowed_path($app_dir, $dir_ . $int)) {
        return false;
    }
    $status = array();
    if (is_dir($dir . $int)) {
        if ($handle = opendir($dir . $int)) {
            while ($file = readdir($handle)) {
                if ($file == "." || $file == "..") {
                    continue;
                }
                $full = $int . $file;
                $is_dir = is_dir($dir . $full);
                if ($is_dir) {
                    $status = array_merge($status, cw_md_cleanup_skin($dir, $dir_, with_slash($full)));
                    if (cw_is_empty_dir($dir_ . $full)) {
                        cw_rm_dir($dir_ . $full);
                        $status[] = '[ ] Dir ' . $dir_ . $full . ' removed';
                    }
                } elseif (in_array(pathinfo($full, PATHINFO_EXTENSION), array('tpl', 'css', 'js', 'gif', 'png', 'jpg', 'jpeg', 'bmp'), true)) {
                    if (file_exists($dir_ . $full)) {
                        $md5 = md5_file($dir . $full);
                        $md5_ = md5_file($dir_ . $full);
                        $same = $md5 == $md5_;
                        if ($same) {
                            if (!unlink($dir_ . $full)) {
                                $status[] = '[!] Can\'t remove file: ' . $dir_ . $full;
                            } else {
                                $status[] = '[ ] File ' . $dir_ . $full . ' removed';
                            }
                        } else {
                            $status[] = '[*] File ' . $dir_ . $full . ' differs';
                        }
                    }
                }
            }
            closedir($handle);
        } else {
            $status[] = '[!] Can\'t open ' . $dir . $int . " directory  (need to check permissions)";
        }
    }
    return $status;
}