if (cu3er__url_exists($settings['cu3er_location'])) {
                            unset($xml['Settings']['cu3er_location']);
                        }
                    }
                    if ($settings['js_location'] != '') {
                        if (cu3er__url_exists($settings['js_location'])) {
                            unset($xml['Settings']['js_location']);
                        }
                    }
                    if ($settings['js_player_location'] != '') {
                        if (cu3er__url_exists($settings['js_player_location'])) {
                            unset($xml['Settings']['js_player_location']);
                        }
                    }
                    if ($settings['licence'] != '') {
                        unset($xml['Settings']['licence']);
                    }
                    if ($settings['id'] == 1) {
                        $xml['Settings']['id'] = 1;
                    }
                    cu3er__sql_magic($wpdb->prefix . 'cu3er__settings', $xml['Settings']);
                    @touch($uplDir . '/CU3ER.txt');
                    cu3er__writeToFile($id);
                    echo 'Project successfully imported!';
                } else {
                    echo mysql_error();
                }
            }
        }
    }
}
function cu3er__admin_setup()
{
    global $wpdb;
    global $cu3er_messages;
    $uploadsDir = wp_upload_dir();
    $writable = true;
    if (is_writable($uploadsDir['basedir'] . '/wpcu3er')) {
        touch($uploadsDir['basedir'] . '/wpcu3er/temp.txt');
        if (!is_writable($uploadsDir['basedir'] . '/wpcu3er/temp.txt')) {
            $writable = false;
        }
    } else {
        $writable = false;
    }
    $basedir = $writable === true ? $uploadsDir['basedir'] . '/wpcu3er' : $uploadsDir['path'];
    $baseurl = $writable === true ? $uploadsDir['baseurl'] . '/wpcu3er' : $uploadsDir['url'];
    $uplDir = $baseurl . '/';
    $save_path = $basedir . '/';
    $message .= cu3er__admin_checkCu3er();
    if ($_POST['Submit'] == 'Save Changes' || $_POST['Submit'] == 'Save Licence') {
        $upload_name = array(0 => "cu3er_location", 1 => "js_location", 2 => "js_player_location");
        $uploadErrors = array(0 => "There is no error, the file uploaded with success", 1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini", 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3 => "The uploaded file was only partially uploaded", 4 => "No file was uploaded", 6 => "Missing a temporary folder");
        $_POST['settings']['licence'] = $_POST['settings']['licence'] != '' ? urlencode(stripslashes($_POST['settings']['licence'])) : ' ';
        $_POST['settings']['licence1'] = $_POST['settings']['licence1'] != '' ? urlencode(stripslashes($_POST['settings']['licence1'])) : ' ';
        $_POST['settings']['licence2'] = $_POST['settings']['licence2'] != '' ? urlencode(stripslashes($_POST['settings']['licence2'])) : ' ';
        $_POST['settings']['licence3'] = $_POST['settings']['licence3'] != '' ? urlencode(stripslashes($_POST['settings']['licence3'])) : ' ';
        $_POST['settings']['licence4'] = $_POST['settings']['licence4'] != '' ? urlencode(stripslashes($_POST['settings']['licence4'])) : ' ';
        foreach ($upload_name as $key => $name) {
            if ($_FILES[$name]["tmp_name"] != '') {
                $file_name = preg_replace('/[^.A-Z0-9_ !@#$%^&()+={}\\[\\]\',~`-]|\\.+$/i', "", basename($_FILES[$name]['name']));
                @unlink($save_path . $file_name);
                if (!move_uploaded_file($_FILES[$name]["tmp_name"], $save_path . $file_name)) {
                    echo "File could not be saved. " . $uploadErrors[$_FILES[$name]['error']];
                    exit(0);
                } else {
                    $_POST['settings'][$name] = $uplDir . $file_name;
                }
            }
        }
        $_POST['settings']['branding'] = isset($_POST['settings']['branding']) ? 'yes' : 'no';
        cu3er__sql_magic($wpdb->prefix . "cu3er__settings", $_POST['settings']) or die(mysql_error());
        /* empty all CU3ER.txt files */
        global $wpdb;
        $uploadsDir = wp_upload_dir();
        // embeded code for showing cu3er //
        $rows = $wpdb->get_results("SELECT `xml_location`,`project_location` FROM `" . $wpdb->prefix . "cu3er__slideshows`", ARRAY_A) or die(mysql_error());
        foreach ($rows as $row) {
            foreach ($row as $key => $value) {
                $row[$key] = stripslashes($value);
            }
            $slideshowS = str_replace("'", "\\'", $row);
            if ($slideshowS['project_location'] != '') {
                $oldDir = $slideshowS['project_location'];
            } else {
                $pth = explode("/", $slideshowS['xml_location']);
                $delFlag = true;
                $size = sizeof($pth);
                $wpContentDirArray = explode('/', WP_CONTENT_DIR);
                $wpContentDir = $wpContentDirArray[sizeof($wpContentDirArray) - 1];
                for ($i = 0; $i < $size; $i++) {
                    if ($pth[$i] == $wpContentDir) {
                        unset($pth[$i], $pth[$i + 1]);
                        $delFlag = false;
                    }
                    if ($delFlag == true) {
                        unset($pth[$i]);
                    }
                }
                $pthOld = $pth;
                unset($pthOld[9], $pthOld[10], $pthOld[11], $pthOld[12]);
                $oldDir = $uploadsDir['basedir'] . '/' . implode("/", $pthOld);
            }
            if (file_exists($oldDir . '/CU3ER.txt') || file_get_contents($oldDir . '/CU3ER.txt') != '') {
                @chmod($oldDir . '/CU3ER.txt', 0777);
                $handle = fopen($oldDir . '/CU3ER.txt', 'w+');
                fclose($handle);
                @chmod($oldDir . '/CU3ER.txt', 0755);
            }
        }
        $message .= $cu3er_messages['setupSuccess'];
    }
    $row = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "cu3er__settings` WHERE `id`=1", ARRAY_A);
    foreach ($row as $key => $value) {
        $row[$key] = stripslashes($value);
    }
    $settings = $row;
    include_once 'tpl/setup.php';
}