diff --git a/chat.js b/chat.js new file mode 100644 index 0000000..9e1a9bc --- /dev/null +++ b/chat.js @@ -0,0 +1,62 @@ +const form = document.querySelector(".typing-area"), +incoming_id = form.querySelector(".incoming_id").value, +inputField = form.querySelector(".input-field"), +sendBtn = form.querySelector("button"), +chatBox = document.querySelector(".chat-box"); + +form.onsubmit = (e)=>{ + e.preventDefault(); +} + +inputField.focus(); +inputField.onkeyup = ()=>{ + if(inputField.value != ""){ + sendBtn.classList.add("active"); + }else{ + sendBtn.classList.remove("active"); + } +} + +sendBtn.onclick = ()=>{ + let xhr = new XMLHttpRequest(); + xhr.open("POST", "php/insert-chat.php", true); + xhr.onload = ()=>{ + if(xhr.readyState === XMLHttpRequest.DONE){ + if(xhr.status === 200){ + inputField.value = ""; + scrollToBottom(); + } + } + } + let formData = new FormData(form); + xhr.send(formData); +} +chatBox.onmouseenter = ()=>{ + chatBox.classList.add("active"); +} + +chatBox.onmouseleave = ()=>{ + chatBox.classList.remove("active"); +} + +setInterval(() =>{ + let xhr = new XMLHttpRequest(); + xhr.open("POST", "php/get-chat.php", true); + xhr.onload = ()=>{ + if(xhr.readyState === XMLHttpRequest.DONE){ + if(xhr.status === 200){ + let data = xhr.response; + chatBox.innerHTML = data; + if(!chatBox.classList.contains("active")){ + scrollToBottom(); + } + } + } + } + xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhr.send("incoming_id="+incoming_id); +}, 500); + +function scrollToBottom(){ + chatBox.scrollTop = chatBox.scrollHeight; +} diff --git a/chat.php b/chat.php new file mode 100644 index 0000000..1f58757 --- /dev/null +++ b/chat.php @@ -0,0 +1,49 @@ + + + + +
+
+
+ + 0){ + $row = mysqli_fetch_assoc($sql); + }else{ + header("location: users.php"); + } + ?> + + + Retour + + +
+ +

+
+ +
+
+ +
+
+ + + +
+
+
+ + + + + diff --git a/config.php b/config.php new file mode 100644 index 0000000..27aa1b3 --- /dev/null +++ b/config.php @@ -0,0 +1,11 @@ + diff --git a/data.php b/data.php new file mode 100644 index 0000000..5a82ee9 --- /dev/null +++ b/data.php @@ -0,0 +1,31 @@ + 0) ? $result = $row2['msg'] : $result = "Pas de message disponible"; + (strlen($result) > 28) ? $msg = substr($result, 0, 28) . '...' : $msg = $result; + + if (isset($row2['outgoing_msg_id'])) { + ($outgoing_id == $row2['outgoing_msg_id']) ? $you = "You: " : $you = ""; + } else { + $you = ""; + } + ($row['status'] == "Déconnecter") ? $offline = "line" : $offline = ""; + ($outgoing_id == $row['unique_id']) ? $hid_me = "hide" : $hid_me = ""; + + $output .= ' +
+ +
+ ' . $row['fname'] . " " . $row['lname'] . ' +

' . $you . $msg . '

+
+
+
+
'; +} diff --git a/get-chat.php b/get-chat.php new file mode 100644 index 0000000..e09e17b --- /dev/null +++ b/get-chat.php @@ -0,0 +1,37 @@ + 0){ + while($row = mysqli_fetch_assoc($query)){ + if($row['outgoing_msg_id'] === $outgoing_id){ + $output .= '
+
+

'. $row['msg'] .'

+
+
'; + }else{ + $output .= '
+ +
+

'. $row['msg'] .'

+
+
'; + } + } + }else{ + $output .= '
Aucun message disponible. Si vous envoyer un message il apparaitra ici.
'; + } + echo $output; + }else{ + header("location: ../login.php"); + } + +?> \ No newline at end of file diff --git a/header.php b/header.php new file mode 100644 index 0000000..d5e0c49 --- /dev/null +++ b/header.php @@ -0,0 +1,10 @@ + + + + + + + Solola + + + \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..756685e --- /dev/null +++ b/index.php @@ -0,0 +1,64 @@ + + + + + + + +
+
+
Solola
+ +
+
+
+
+ + +
+ +
+ + +
+
+ +
+ + +
+ +
+ + + +
+ +
+ + +
+ +
+ +
+
+ + +
+
+ + + + + + diff --git a/insert-chat.php b/insert-chat.php new file mode 100644 index 0000000..d7128de --- /dev/null +++ b/insert-chat.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/login.js b/login.js new file mode 100644 index 0000000..81cf410 --- /dev/null +++ b/login.js @@ -0,0 +1,27 @@ +const form = document.querySelector(".login form"), +continueBtn = form.querySelector(".button input"), +errorText = form.querySelector(".error-text"); + +form.onsubmit = (e)=>{ + e.preventDefault(); +} + +continueBtn.onclick = ()=>{ + let xhr = new XMLHttpRequest(); + xhr.open("POST", "php/login.php", true); + xhr.onload = ()=>{ + if(xhr.readyState === XMLHttpRequest.DONE){ + if(xhr.status === 200){ + let data = xhr.response; + if(data === "success"){ + location.href = "users.php"; + }else{ + errorText.style.display = "block"; + errorText.textContent = data; + } + } + } + } + let formData = new FormData(form); + xhr.send(formData); +} \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..dc8fdbd --- /dev/null +++ b/login.php @@ -0,0 +1,34 @@ + 0){ + + $row = mysqli_fetch_assoc($sql); + $user_pass = md5($password); + $enc_pass = $row['password']; + + if($user_pass === $enc_pass){ + $status = "En ligne"; + $sql2 = mysqli_query($conn, "UPDATE users SET status = '{$status}' WHERE unique_id = {$row['unique_id']}"); + if($sql2){ + $_SESSION['unique_id'] = $row['unique_id']; + echo "success"; + }else{ + echo "Quelques chose ce mal passer. Essayer plutard!"; + } + }else{ + echo "Email ou mot de passe est Incorrect!"; + } + }else{ + echo "$email - Cet email n'existe pas!"; + } + }else{ + echo "Tout le champ son requis !"; + } +?> \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..0070563 --- /dev/null +++ b/logout.php @@ -0,0 +1,24 @@ + \ No newline at end of file diff --git a/pass-show-hide.js b/pass-show-hide.js new file mode 100644 index 0000000..d54fbc5 --- /dev/null +++ b/pass-show-hide.js @@ -0,0 +1,12 @@ +const pswrdField = document.querySelector(".form input[type='password']"), +toggleIcon = document.querySelector(".form .field i"); + +toggleIcon.onclick = () =>{ + if(pswrdField.type === "password"){ + pswrdField.type = "text"; + toggleIcon.classList.add("active"); + }else{ + pswrdField.type = "password"; + toggleIcon.classList.remove("active"); + } +} diff --git a/search.php b/search.php new file mode 100644 index 0000000..23b14e0 --- /dev/null +++ b/search.php @@ -0,0 +1,18 @@ + 0){ + include_once "data.php"; + }else{ + $output .= 'Aucune personne en ce nom! Veuillez refoumuler autrement'; + } + echo $output; +?> \ No newline at end of file diff --git a/signup.js b/signup.js new file mode 100644 index 0000000..6ff09f4 --- /dev/null +++ b/signup.js @@ -0,0 +1,27 @@ +const form = document.querySelector(".signup form"), +continueBtn = form.querySelector(".button input"), +errorText = form.querySelector(".error-text"); + +form.onsubmit = (e)=>{ + e.preventDefault(); +} + +continueBtn.onclick = ()=>{ + let xhr = new XMLHttpRequest(); + xhr.open("POST", "php/signup.php", true); + xhr.onload = ()=>{ + if(xhr.readyState === XMLHttpRequest.DONE){ + if(xhr.status === 200){ + let data = xhr.response; + if(data === "success"){ + location.href="users.php"; + }else{ + errorText.style.display = "block"; + errorText.textContent = data; + } + } + } + } + let formData = new FormData(form); + xhr.send(formData); +} \ No newline at end of file diff --git a/signup.php b/signup.php new file mode 100644 index 0000000..07fd4eb --- /dev/null +++ b/signup.php @@ -0,0 +1,69 @@ + 0){ + echo "$email - Cet email existe"; + }else{ + if(isset($_FILES['image'])){ + $img_name = $_FILES['image']['name']; + $img_type = $_FILES['image']['type']; + $tmp_name = $_FILES['image']['tmp_name']; + + $img_explode = explode('.',$img_name); + $img_ext = end($img_explode); + + $extensions = ["jpeg", "png", "jpg"]; + + if(in_array($img_ext, $extensions) === true){ + $types = ["image/jpeg", "image/jpg", "image/png"]; + + if(in_array($img_type, $types) === true){ + $time = time(); + $new_img_name = $time.$img_name; + + if(move_uploaded_file($tmp_name,"images/".$new_img_name)){ + + $ran_id = rand(time(), 100000000); + $status = "En ligne"; + $encrypt_pass = md5($password); + $insert_query = mysqli_query($conn, "INSERT INTO users (unique_id, fname, lname, email, password, img, status) + + VALUES ({$ran_id}, '{$fname}','{$lname}', '{$email}', '{$encrypt_pass}', '{$new_img_name}', '{$status}')"); + if($insert_query){ + + $select_sql2 = mysqli_query($conn, "SELECT * FROM users WHERE email = '{$email}'"); + if(mysqli_num_rows($select_sql2) > 0){ + $result = mysqli_fetch_assoc($select_sql2); + $_SESSION['unique_id'] = $result['unique_id']; + + echo "success"; + }else{ + echo "Cet Email n'existe pas"; + } + }else{ + echo "Quelques chose ne fonctionner pas. Essayer plutard!"; + } + } + }else{ + echo "Veuillez choisir un fichier - jpeg, png, jpg"; + } + }else{ + echo "Veuillez choisir un fichier - jpeg, png, jpg"; + } + } + } + }else{ + echo "$email ne pas un email valide"; + } + }else{ + echo "Tout le champ sont requis"; + } +?> \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..5e51bf2 --- /dev/null +++ b/style.css @@ -0,0 +1,412 @@ +@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap'); +*{ + margin: 0; + padding: 0; + box-sizing: border-box; + text-decoration: none; + font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; +} +body{ + display: flex; + align-items: center; + justify-content: center; + min-height: 100vh; + background: #f7f7f7; + padding: 0 10px; +} +.wrapper{ + background: #fff; + max-width: 520px; + width: 100%; + border-radius: 20px; + box-shadow: 0 0 128px 0 rgba(0,0,0,0.1), + 0 32px 64px -48px rgba(0,0,0,0.5); +} + +/* Login & Signup Form CSS Start */ +.form{ + padding: 25px 30px; +} +.form header{ + font-size: 25px; + font-weight: 600; + padding-bottom: 10px; + border-bottom: 1px solid #e6e6e6; +} +.form form{ + margin: 20px 0; +} +.form form .error-text{ + color: #721c24; + padding: 8px 10px; + text-align: center; + border-radius: 5px; + background: #f8d7da; + border: 1px solid #f5c6cb; + margin-bottom: 10px; + display: none; +} +.form form .name-details{ + display: flex; +} +.form .name-details .field:first-child{ + margin-right: 10px; +} +.form .name-details .field:last-child{ + margin-left: 10px; +} +.form form .field{ + display: flex; + margin-bottom: 10px; + flex-direction: column; + position: relative; +} +.form form .field label{ + margin-bottom: 2px; +} +.form form .input input{ + height: 40px; + width: 100%; + font-size: 16px; + padding: 0 10px; + border-radius: 5px; + border: 1px solid #ccc; +} +.form form .field input{ + outline: none; +} +.form form .image input{ + font-size: 17px; +} +.form form .button input{ + height: 45px; + border: none; + color: #fff; + font-size: 17px; + background: #333; + border-radius: 5px; + cursor: pointer; + margin-top: 13px; +} +.form form .field i{ + position: absolute; + right: 15px; + top: 70%; + color: #ccc; + cursor: pointer; + transform: translateY(-50%); +} +.form form .field i.active::before{ + color: #333; + content: "\f070"; +} +.form .link{ + text-align: center; + margin: 10px 0; + font-size: 17px; +} +.form .link a{ + color: #333; +} +.form .link a:hover{ + text-decoration: underline; +} + + +/* Users List CSS Start */ +.users{ + padding: 25px 30px; +} +.users header, +.users-list a{ + display: flex; + align-items: center; + padding-bottom: 20px; + border-bottom: 1px solid #e6e6e6; + justify-content: space-between; +} +.wrapper img{ + object-fit: cover; + border-radius: 50%; +} +.users header img{ + height: 50px; + width: 50px; +} +:is(.users, .users-list) .content{ + display: flex; + align-items: center; +} +:is(.users, .users-list) .content .details{ + color: #000; + margin-left: 20px; +} +:is(.users, .users-list) .details span{ + font-size: 18px; + font-weight: 500; +} +.users header .logout{ + display: block; + background: #333; + color: #fff; + outline: none; + border: none; + padding: 7px 15px; + text-decoration: none; + border-radius: 5px; + font-size: 17px; +} +.users .search{ + margin: 20px 0; + display: flex; + position: relative; + align-items: center; + justify-content: space-between; +} +.users .search .text{ + font-size: 18px; +} +.users .search input{ + position: absolute; + height: 42px; + width: calc(100% - 50px); + font-size: 16px; + padding: 0 13px; + border: 1px solid #e6e6e6; + outline: none; + border-radius: 5px 0 0 5px; + opacity: 0; + pointer-events: none; + transition: all 0.2s ease; +} +.users .search input.show{ + opacity: 1; + pointer-events: auto; +} +.users .search button{ + position: relative; + z-index: 1; + width: 47px; + height: 42px; + font-size: 17px; + cursor: pointer; + border: none; + background: #fff; + color: #333; + outline: none; + border-radius: 0 5px 5px 0; + transition: all 0.2s ease; +} +.users .search button.active{ + background: #333; + color: #fff; +} +.search button.active i::before{ + content: '\f00d'; +} +.users-list{ + max-height: 350px; + overflow-y: auto; +} +:is(.users-list, .chat-box)::-webkit-scrollbar{ + width: 0px; +} +.users-list a{ + padding-bottom: 10px; + margin-bottom: 15px; + padding-right: 15px; + border-bottom-color: #f1f1f1; +} +.users-list a:last-child{ + margin-bottom: 0px; + border-bottom: none; +} +.users-list a img{ + height: 40px; + width: 40px; +} +.users-list a .details p{ + color: #67676a; +} +.users-list a .status-dot{ + font-size: 12px; + color: #468669; + padding-left: 10px; +} +.users-list a .status-dot.offline{ + color: #ccc; +} + +/* Chat Area CSS Start */ +.chat-area header{ + display: flex; + align-items: center; + padding: 18px 30px; +} +.chat-area header .back-icon{ + color: #333; + font-size: 18px; +} +.chat-area header img{ + height: 45px; + width: 45px; + margin: 0 15px; +} +.chat-area header .details span{ + font-size: 17px; + font-weight: 500; +} +.chat-box{ + position: relative; + min-height: 500px; + max-height: 500px; + overflow-y: auto; + padding: 10px 30px 20px 30px; + background: #ccc; + box-shadow: inset 0 32px 32px -32px rgb(0 0 0 / 5%), + inset 0 -32px 32px -32px rgb(0 0 0 / 5%); +} +.chat-box .text{ + position: absolute; + top: 45%; + left: 50%; + width: calc(100% - 50px); + text-align: center; + transform: translate(-50%, -50%); +} +.chat-box .chat{ + margin: 15px 0; +} +.chat-box .chat p{ + word-wrap: break-word; + padding: 8px 16px; + box-shadow: 0 0 32px rgb(0 0 0 / 8%), + 0rem 16px 16px -16px rgb(0 0 0 / 10%); +} +.chat-box .outgoing{ + display: flex; +} +.chat-box .outgoing .details{ + margin-left: auto; + max-width: calc(100% - 130px); +} +.outgoing .details p{ + background: #333; + color: #fff; + border-radius: 18px 18px 0 18px; +} +.chat-box .incoming{ + display: flex; + align-items: flex-end; +} +.chat-box .incoming img{ + height: 35px; + width: 35px; +} +.chat-box .incoming .details{ + margin-right: auto; + margin-left: 10px; + max-width: calc(100% - 130px); +} +.incoming .details p{ + background: #fff; + color: #333; + border-radius: 18px 18px 18px 0; +} +.typing-area{ + padding: 18px 30px; + display: flex; + justify-content: space-between; +} +.typing-area input{ + height: 45px; + width: calc(100% - 58px); + font-size: 16px; + padding: 0 13px; + border: 1px solid #e6e6e6; + outline: none; + border-radius: 5px 0 0 5px; +} +.typing-area button{ + color: #fff; + width: 55px; + border: none; + outline: none; + background: #333; + font-size: 19px; + cursor: pointer; + opacity: 0.7; + pointer-events: none; + border-radius: 0 5px 5px 0; + transition: all 0.3s ease; +} +.typing-area button.active{ + opacity: 1; + pointer-events: auto; +} + +/* Responive media query */ +@media screen and (max-width: 450px) { + .form, .users{ + padding: 20px; + } + .form header{ + text-align: center; + } + .form form .name-details{ + flex-direction: column; + } + .form .name-details .field:first-child{ + margin-right: 0px; + } + .form .name-details .field:last-child{ + margin-left: 0px; + } + + .users header img{ + height: 45px; + width: 45px; + } + .users header .logout{ + padding: 6px 10px; + font-size: 16px; + } + :is(.users, .users-list) .content .details{ + margin-left: 15px; + } + + .users-list a{ + padding-right: 10px; + } + + .chat-area header{ + padding: 15px 20px; + } + .chat-box{ + min-height: 400px; + padding: 10px 15px 15px 20px; + } + .chat-box .chat p{ + font-size: 15px; + } + .chat-box .outogoing .details{ + max-width: 230px; + } + .chat-box .incoming .details{ + max-width: 265px; + } + .incoming .details img{ + height: 30px; + width: 30px; + } + .chat-area form{ + padding: 20px; + } + .chat-area form input{ + height: 40px; + width: calc(100% - 48px); + } + .chat-area form button{ + width: 45px; + } +} diff --git a/unzipper.php b/unzipper.php new file mode 100644 index 0000000..8f30550 --- /dev/null +++ b/unzipper.php @@ -0,0 +1,422 @@ +prepareExtraction($archive, $destination); +} + +if (isset($_POST['dozip'])) { + $zippath = !empty($_POST['zippath']) ? strip_tags($_POST['zippath']) : '.'; + // Resulting zipfile e.g. zipper--2016-07-23--11-55.zip. + $zipfile = 'zipper-' . date("Y-m-d--H-i") . '.zip'; + Zipper::zipDir($zippath, $zipfile); +} + +$timeend = microtime(TRUE); +$time = round($timeend - $timestart, 4); + +/** + * Class Unzipper + */ +class Unzipper { + public $localdir = '.'; + public $zipfiles = array(); + + public function __construct() { + // Read directory and pick .zip, .rar and .gz files. + if ($dh = opendir($this->localdir)) { + while (($file = readdir($dh)) !== FALSE) { + if (pathinfo($file, PATHINFO_EXTENSION) === 'zip' + || pathinfo($file, PATHINFO_EXTENSION) === 'gz' + || pathinfo($file, PATHINFO_EXTENSION) === 'rar' + ) { + $this->zipfiles[] = $file; + } + } + closedir($dh); + + if (!empty($this->zipfiles)) { + $GLOBALS['status'] = array('info' => '.zip or .gz or .rar files found, ready for extraction'); + } + else { + $GLOBALS['status'] = array('info' => 'No .zip or .gz or rar files found. So only zipping functionality available.'); + } + } + } + + /** + * Prepare and check zipfile for extraction. + * + * @param string $archive + * The archive name including file extension. E.g. my_archive.zip. + * @param string $destination + * The relative destination path where to extract files. + */ + public function prepareExtraction($archive, $destination = '') { + // Determine paths. + if (empty($destination)) { + $extpath = $this->localdir; + } + else { + $extpath = $this->localdir . '/' . $destination; + // Todo: move this to extraction function. + if (!is_dir($extpath)) { + mkdir($extpath); + } + } + // Only local existing archives are allowed to be extracted. + if (in_array($archive, $this->zipfiles)) { + self::extract($archive, $extpath); + } + } + + /** + * Checks file extension and calls suitable extractor functions. + * + * @param string $archive + * The archive name including file extension. E.g. my_archive.zip. + * @param string $destination + * The relative destination path where to extract files. + */ + public static function extract($archive, $destination) { + $ext = pathinfo($archive, PATHINFO_EXTENSION); + switch ($ext) { + case 'zip': + self::extractZipArchive($archive, $destination); + break; + case 'gz': + self::extractGzipFile($archive, $destination); + break; + case 'rar': + self::extractRarArchive($archive, $destination); + break; + } + + } + + /** + * Decompress/extract a zip archive using ZipArchive. + * + * @param $archive + * @param $destination + */ + public static function extractZipArchive($archive, $destination) { + // Check if webserver supports unzipping. + if (!class_exists('ZipArchive')) { + $GLOBALS['status'] = array('error' => 'Error: Your PHP version does not support unzip functionality.'); + return; + } + + $zip = new ZipArchive; + + // Check if archive is readable. + if ($zip->open($archive) === TRUE) { + // Check if destination is writable + if (is_writeable($destination . '/')) { + $zip->extractTo($destination); + $zip->close(); + $GLOBALS['status'] = array('success' => 'Files unzipped successfully'); + } + else { + $GLOBALS['status'] = array('error' => 'Error: Directory not writeable by webserver.'); + } + } + else { + $GLOBALS['status'] = array('error' => 'Error: Cannot read .zip archive.'); + } + } + + /** + * Decompress a .gz File. + * + * @param string $archive + * The archive name including file extension. E.g. my_archive.zip. + * @param string $destination + * The relative destination path where to extract files. + */ + public static function extractGzipFile($archive, $destination) { + // Check if zlib is enabled + if (!function_exists('gzopen')) { + $GLOBALS['status'] = array('error' => 'Error: Your PHP has no zlib support enabled.'); + return; + } + + $filename = pathinfo($archive, PATHINFO_FILENAME); + $gzipped = gzopen($archive, "rb"); + $file = fopen($destination . '/' . $filename, "w"); + + while ($string = gzread($gzipped, 4096)) { + fwrite($file, $string, strlen($string)); + } + gzclose($gzipped); + fclose($file); + + // Check if file was extracted. + if (file_exists($destination . '/' . $filename)) { + $GLOBALS['status'] = array('success' => 'File unzipped successfully.'); + + // If we had a tar.gz file, let's extract that tar file. + if (pathinfo($destination . '/' . $filename, PATHINFO_EXTENSION) == 'tar') { + $phar = new PharData($destination . '/' . $filename); + if ($phar->extractTo($destination)) { + $GLOBALS['status'] = array('success' => 'Extracted tar.gz archive successfully.'); + // Delete .tar. + unlink($destination . '/' . $filename); + } + } + } + else { + $GLOBALS['status'] = array('error' => 'Error unzipping file.'); + } + + } + + /** + * Decompress/extract a Rar archive using RarArchive. + * + * @param string $archive + * The archive name including file extension. E.g. my_archive.zip. + * @param string $destination + * The relative destination path where to extract files. + */ + public static function extractRarArchive($archive, $destination) { + // Check if webserver supports unzipping. + if (!class_exists('RarArchive')) { + $GLOBALS['status'] = array('error' => 'Error: Your PHP version does not support .rar archive functionality. How to install RarArchive'); + return; + } + // Check if archive is readable. + if ($rar = RarArchive::open($archive)) { + // Check if destination is writable + if (is_writeable($destination . '/')) { + $entries = $rar->getEntries(); + foreach ($entries as $entry) { + $entry->extract($destination); + } + $rar->close(); + $GLOBALS['status'] = array('success' => 'Files extracted successfully.'); + } + else { + $GLOBALS['status'] = array('error' => 'Error: Directory not writeable by webserver.'); + } + } + else { + $GLOBALS['status'] = array('error' => 'Error: Cannot read .rar archive.'); + } + } + +} + +/** + * Class Zipper + * + * Copied and slightly modified from http://at2.php.net/manual/en/class.ziparchive.php#110719 + * @author umbalaconmeogia + */ +class Zipper { + /** + * Add files and sub-directories in a folder to zip file. + * + * @param string $folder + * Path to folder that should be zipped. + * + * @param ZipArchive $zipFile + * Zipfile where files end up. + * + * @param int $exclusiveLength + * Number of text to be exclusived from the file path. + */ + private static function folderToZip($folder, &$zipFile, $exclusiveLength) { + $handle = opendir($folder); + + while (FALSE !== $f = readdir($handle)) { + // Check for local/parent path or zipping file itself and skip. + if ($f != '.' && $f != '..' && $f != basename(__FILE__)) { + $filePath = "$folder/$f"; + // Remove prefix from file path before add to zip. + $localPath = substr($filePath, $exclusiveLength); + + if (is_file($filePath)) { + $zipFile->addFile($filePath, $localPath); + } + elseif (is_dir($filePath)) { + // Add sub-directory. + $zipFile->addEmptyDir($localPath); + self::folderToZip($filePath, $zipFile, $exclusiveLength); + } + } + } + closedir($handle); + } + + /** + * Zip a folder (including itself). + * + * Usage: + * Zipper::zipDir('path/to/sourceDir', 'path/to/out.zip'); + * + * @param string $sourcePath + * Relative path of directory to be zipped. + * + * @param string $outZipPath + * Relative path of the resulting output zip file. + */ + public static function zipDir($sourcePath, $outZipPath) { + $pathInfo = pathinfo($sourcePath); + $parentPath = $pathInfo['dirname']; + $dirName = $pathInfo['basename']; + + $z = new ZipArchive(); + $z->open($outZipPath, ZipArchive::CREATE); + $z->addEmptyDir($dirName); + if ($sourcePath == $dirName) { + self::folderToZip($sourcePath, $z, 0); + } + else { + self::folderToZip($sourcePath, $z, strlen("$parentPath/")); + } + $z->close(); + + $GLOBALS['status'] = array('success' => 'Successfully created archive ' . $outZipPath); + } +} +?> + + + + + File Unzipper + Zipper + + + + +

+ Status:
+ Processing Time: seconds +

+
+
+

Archive Unzipper

+ + + + +

Enter extraction path without leading or trailing slashes (e.g. "mypath"). If left empty current directory will be used.

+ +
+ +
+

Archive Zipper

+ + +

Enter path to be zipped without leading or trailing slashes (e.g. "zippath"). If left empty current directory will be used.

+ +
+
+

Unzipper version:

+ + diff --git a/users.js b/users.js new file mode 100644 index 0000000..9bdd3e8 --- /dev/null +++ b/users.js @@ -0,0 +1,51 @@ +const searchBar = document.querySelector(".search input"), +searchIcon = document.querySelector(".search button"), +usersList = document.querySelector(".users-list"); + +searchIcon.onclick = ()=>{ + searchBar.classList.toggle("show"); + searchIcon.classList.toggle("active"); + searchBar.focus(); + if(searchBar.classList.contains("active")){ + searchBar.value = ""; + searchBar.classList.remove("active"); + } +} + +searchBar.onkeyup = ()=>{ + let searchTerm = searchBar.value; + if(searchTerm != ""){ + searchBar.classList.add("active"); + }else{ + searchBar.classList.remove("active"); + } + let xhr = new XMLHttpRequest(); + xhr.open("POST", "php/search.php", true); + xhr.onload = ()=>{ + if(xhr.readyState === XMLHttpRequest.DONE){ + if(xhr.status === 200){ + let data = xhr.response; + usersList.innerHTML = data; + } + } + } + xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhr.send("searchTerm=" + searchTerm); +} + +setInterval(() =>{ + let xhr = new XMLHttpRequest(); + xhr.open("GET", "php/users.php", true); + xhr.onload = ()=>{ + if(xhr.readyState === XMLHttpRequest.DONE){ + if(xhr.status === 200){ + let data = xhr.response; + if(!searchBar.classList.contains("active")){ + usersList.innerHTML = data; + } + } + } + } + xhr.send(); +}, 500); + diff --git a/users.php b/users.php new file mode 100644 index 0000000..ef6d61f --- /dev/null +++ b/users.php @@ -0,0 +1,18 @@ + 0){ + include_once "data.php"; + } + echo $output; +?> \ No newline at end of file