if (in_array($action, array('update', 'delete'))) {
     foreach ($posted_data as $k => $v) {
         if ($action == 'delete' && $v['del']) {
             cw_md_domain_delete($k);
         }
         if ($action == 'update' && $k) {
             cw_md_domain_update($k, $v);
         }
     }
     cw_header_location("index.php?target={$target}");
 }
 if ($action == 'copy_basic' && $confirmed == 'Y') {
     $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_copy_skin($app_dir . $app_config_file['web']['skin'], $app_dir . $data['skin'], '/');
     }
     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']) {
function cw_md_copy_skin($dir, $dir_, $int = '')
{
    $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) {
                    $full .= '/';
                }
                $file_info = pathinfo($full);
                if ($is_dir) {
                    if (!is_dir($dir_ . $full) && !@mkdir($dir_ . $full)) {
                        $status[] = 'Not possible to create directory: ' . dirname($dir_ . $full);
                    }
                    $status = array_merge($status, cw_md_copy_skin($dir, $dir_, $full));
                } elseif (in_array($file_info['extension'], array('js', 'css', 'tpl', 'gif', 'jpg', 'png', 'jpeg', 'bmp', 'htaccess'))) {
                    if (!file_exists($dir_ . $full)) {
                        if (is_dir(dirname($dir_ . $full))) {
                            if (!@copy($dir . $full, $dir_ . $full)) {
                                $status[] = 'Can\'t add file: ' . $dir_ . $full;
                            }
                        } else {
                            $status[] = 'No directory: ' . dirname($dir_ . $full);
                        }
                    }
                }
            }
            closedir($handle);
        } else {
            $status[] = 'Can\'t open ' . $dir . $int . " directory  (need to check permissions)";
        }
    }
    return $status;
}