get("groupchatuser", ["id", "name", "usr_avatar"], ["id" => $_SESSION['gcuid']]); // Remove the user from the database $jakdb->delete("groupchatuser", ["id" => $row['id']]); // The left message $chatleave = sprintf($jkl['g16'], $_SESSION['gcname']); // The complete left final message $clmsg = jak_string_encrypt_decrypt(time().':#!#:0:#!#:'.$_SESSION['gcname'].':#!#:'.$row['usr_avatar'].':#!#:'.$chatleave.':#!#::#!#:'.false).':!n:'; // The chat file $groupchatfile = APP_PATH.JAK_CACHE_DIRECTORY.'/groupchat'.$_SESSION['groupchatid'].'.txt'; // Let's inform others that a new client has entered the chat file_put_contents($groupchatfile, $clmsg, FILE_APPEND); // OK, something is fishy, let's logout the client and redirect to the new chat with login unset($_SESSION['groupchatid']); unset($_SESSION['gcname']); unset($_SESSION['gcuid']); unset($_SESSION['gcavatar']); if (isset($_SESSION['gcopid']) && !empty($_SESSION['gcopid'])) { unset($_SESSION['gcopid']); jak_redirect(JAK_rewrite::jakParseurl(JAK_OPERATOR_LOC)); } else { // Set success message $_SESSION['hasloggedout'] = true; // Redirect back to the chat jak_redirect(JAK_rewrite::jakParseurl('groupchat', $page1, $page2)); } } // The chat file $groupchatfile = APP_PATH.JAK_CACHE_DIRECTORY.'/groupchat'.$page1.'.txt'; // Now check the button id if (!file_exists($cacheopid) || !is_numeric($page1)) { $gcoffline = true; } else { // Back to the chat $gochat = JAK_rewrite::jakParseurl('groupchat', $page1, $groupchat[$page1]['lang']); // Let's check if the operator has access if ($jakuserrow && is_numeric($jakuser->getVar("id")) && (isset($groupchat[$page1]['opids']) && ($groupchat[$page1]['opids'] == 0 || in_array($jakuser->getVar("id"), explode(",", $groupchat[$page1]['opids']))))) { $gcop = true; // Insert the user into the group chat database if (!isset($_SESSION['gcopid']) && empty($_SESSION['gcopid'])) { // Current time $ctime = time(); // Create the session if (!isset($_SESSION['gcuid'])) { $salt = rand(100, 99999); $gcid = $salt.$ctime; } $jakdb->insert("groupchatuser", [ "groupchatid" => $page1, "name" => $jakuser->getVar("name"), "usr_avatar" => $jakuser->getVar("picture"), "statusc" => $ctime, "ip" => $ipa, "isop" => 1, "session" => $gcid, "created" => $jakdb->raw("NOW()")]); $cid = $jakdb->id(); // The left message $chatopwelcome = sprintf($jkl['g76'], $jakuser->getVar("name")); // The welcome final message $clmsg = jak_string_encrypt_decrypt(time().':#!#:'.$cid.':#!#:'.$jakuser->getVar("name").':#!#:'.$jakuser->getVar("picture").':#!#:'.$chatopwelcome.':#!#::#!#:'.true).':!n:'; // Let's inform others that a new client has entered the chat file_put_contents($groupchatfile, $clmsg, FILE_APPEND); // Set the operator sessions for the public chat $_SESSION['groupchatid'] = $page1; $_SESSION['gcname'] = $jakuser->getVar("name"); $_SESSION['gcavatar'] = $jakuser->getVar("picture"); $_SESSION['gcuid'] = $cid; $_SESSION['gcopid'] = $jakuser->getVar("id"); } } // Ok user is not logged in, show the login form or the message that the chat is full if ($gcop || (isset($_SESSION['gcuid']) && !empty($_SESSION['gcuid']))) { $gclogout = false; // Logout feature if ($page2 == "logout") { // Get the user information $row = $jakdb->get("groupchatuser", ["id", "name", "usr_avatar"], ["id" => $_SESSION['gcuid']]); // Remove the user from the database $jakdb->delete("groupchatuser", ["id" => $row['id']]); // The left message $chatleave = sprintf($jkl['g16'], $_SESSION['gcname']); // The complete left final message $clmsg = jak_string_encrypt_decrypt(time().':#!#:0:#!#:'.$_SESSION['gcname'].':#!#:'.$row['usr_avatar'].':#!#:'.$chatleave.':#!#::#!#:'.false).':!n:'; // Let's inform others that a new client has entered the chat file_put_contents($groupchatfile, $clmsg, FILE_APPEND); // Unset the sessions $gclogout = true; } // Check if that customer still exists if (!$jakdb->has("groupchatuser", ["id" => $_SESSION['gcuid']]) || !(isset($_SESSION['gcuid']))) { // Unset the sessions $gclogout = true; } // Unset the sessions if ($gclogout) { unset($_SESSION['groupchatid']); unset($_SESSION['gcname']); unset($_SESSION['gcuid']); unset($_SESSION['gcavatar']); if (isset($_SESSION['gcopid']) && !empty($_SESSION['gcopid'])) { unset($_SESSION['gcopid']); jak_redirect(JAK_rewrite::jakParseurl(JAK_OPERATOR_LOC)); } else { // Set success message $_SESSION['hasloggedout'] = true; // Redirect back to the chat jak_redirect(JAK_rewrite::jakParseurl('groupchat', $page1, $groupchat[$page1]['lang'])); } } // All is normal just show the chat $gclogin = false; // Reset the last visit session unset($_SESSION["vislasttime"]); } else { // Count total user $gcuser = $jakdb->count("groupchatuser", ["groupchatid" => $page1]); // if we have reached the maximum clients or the ip is blocked abort if ($gcuser >= $groupchat[$page1]['maxclients'] || $USR_IP_BLOCKED) { $gcmax = true; } else { // Login form if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['groupchat'])) { // Shorter post var $jkp = $_POST; $dbSmall = ""; // Check Name at least 3 if (empty($jkp['name']) || strlen(trim($jkp['name'])) <= 2) { $errors['name'] = $jkl['e']; } // Check if it is valid if (!preg_match('/^([a-zA-Z0-9\-_ ])+$/', $jkp["name"])) { $errors['name'] = $jkl['e16']; } // We have a password check if it is correct. if (!empty($groupchat[$page1]['password']) && $groupchat[$page1]['password'] != $jkp["password"]) { $errors['password'] = $jkl['l']; } // We have a name, let's check if it exists already. if (count($errors) == 0) { if ($jakdb->has("groupchatuser", ["AND" => ["groupchatid" => $page1, "name" => $jkp['name']]])) { $errors['name'] = $jkl['e15']; } } // We have a custom avatar if (count($errors) == 0) { if (!empty($_FILES['customavatar']['name'])) { if ($_FILES['customavatar']['name'] != '') { $filename = $_FILES['customavatar']['name']; // original filename // Fix explode when upload in 1.2 $tmpf = explode(".", $filename); $jak_xtension = end($tmpf); if ($jak_xtension == "jpg" || $jak_xtension == "jpeg" || $jak_xtension == "png" || $jak_xtension == "gif") { // Get the maximum upload or set to 2 $postmax = (ini_get('post_max_size') ? filter_var(ini_get('post_max_size'), FILTER_SANITIZE_NUMBER_INT) : "2"); if ($_FILES['customavatar']['size'] <= ($postmax * 1000000)) { list($width, $height, $type, $attr) = getimagesize($_FILES['customavatar']['tmp_name']); $mime = image_type_to_mime_type($type); if (($mime == "image/jpeg") || ($mime == "image/pjpeg") || ($mime == "image/png") || ($mime == "image/gif")) { // first get the target path $targetPathd = APP_PATH.JAK_FILES_DIRECTORY.'/user/'; $targetPath = str_replace("//","/",$targetPathd); // Create the target path if (!is_dir($targetPath)) { mkdir($targetPath, 0755); copy(APP_PATH.JAK_FILES_DIRECTORY."/index.html", $targetPath . "/index.html"); } $tempFile = $_FILES['customavatar']['tmp_name']; $origName = substr($_FILES['customavatar']['name'], 0, -4); $name_space = strtolower($_FILES['customavatar']['name']); $middle_name = str_replace(" ", "_", $name_space); $middle_name = str_replace(".jpeg", ".jpg", $name_space); $glnrrand = rand(10, 99); $bigPhoto = str_replace(".", "_" . $glnrrand . ".", $middle_name); $smallPhoto = str_replace(".", "_t.", $bigPhoto); $targetFile = str_replace('//','/',$targetPath) . $bigPhoto; $origPath = '/user/'; $dbSmall = $origPath.$smallPhoto; require_once 'include/functions_thumb.php'; // Move file and create thumb move_uploaded_file($tempFile,$targetFile); create_thumbnail($targetPath, $targetFile, $smallPhoto, 250, 250, 80); // remove target file if (is_file($targetFile)) unlink($targetFile); } else { $errors['uploadavatar'] = $jkl['e9'].'
'; } } else { $errors['uploadavatar'] = $jkl['e9'].'
'; } } else { $errors['uploadavatar'] = $jkl['e9'].'
'; } } else { $errors['uploadavatar'] = $jkl['e9'].'
'; } } } // Ok name is not given or already taken if (count($errors) > 0) { $errors = $errors; // Proceed with the login } else { // Get the avatar $avatar = ""; if (isset($dbSmall) && !empty($dbSmall)) { $avatar = $dbSmall; } elseif (isset($jkp['avatar']) && $jkp['avatar']) { $avatar = $jkp['avatar']; } else { $avatar = "/standard.jpg"; } // Current time $ctime = time(); // Create the session if (!isset($_SESSION['gcuid'])) { $salt = rand(100, 99999); $gcid = $salt.$ctime; } // User is still banned after logout and login again $usrbanned = 0; if (isset($_SESSION["usrbanned"])) $usrbanned = 1; // Insert the user into the group chat database $jakdb->insert("groupchatuser", [ "groupchatid" => $page1, "name" => $jkp['name'], "usr_avatar" => $avatar, "statusc" => $ctime, "banned" => $usrbanned, "ip" => $ipa, "session" => $gcid, "created" => $jakdb->raw("NOW()")]); $cid = $jakdb->id(); // Set the user stuff into a session $_SESSION['gcname'] = $jkp["name"]; $_SESSION['gcavatar'] = $avatar; $_SESSION['gcuid'] = $cid; // The welcome message $chatenter = sprintf($jkl['g76'], $jkp["name"]); // The welcome final message $cwmsg = jak_string_encrypt_decrypt($ctime.':#!#:'.$cid.':#!#:'.$_SESSION['gcname'].':#!#:'.$avatar.':#!#:'.$chatenter.':#!#::#!#:'.false).':!n:'; // Let's inform others that a new client has entered the chat file_put_contents($groupchatfile, $cwmsg, FILE_APPEND); // No operator is online for this chat, send a push notification when available. if (!$jakdb->has("groupchatuser", ["groupchatid" => $page1])) { // Now send notifications if whish so $result = $jakdb->select("user", ["id", "username", "email", "alwaysnot", "emailnot", "hours_array", "pusho_tok", "pusho_key", "phonenumber", "push_notifications", "available"], ["AND" => ["OR" => ["id" => $groupchat[$page1]['opid'], "opid" => $groupchat[$page1]['opid']], "access" => 1]]); if (isset($result) && !empty($result)) { foreach ($result as $row) { if (((JAK_base::jakAvailableHours($row["hours_array"], date('Y-m-d H:i:s')) && $row["available"] == 0) || $row["alwaysnot"] == 1) && ($groupchat[$page1]['opids'] == 0 || in_array($row["id"], explode(",", $groupchat[$page1]['opids'])))) { jak_send_notifications($row["id"], $cid, JAK_TITLE, JAK_TW_MSG.' '.$groupchat[$page1]['title'], $gochat, $row["push_notifications"], $row["emailnot"], $row["email"], $row["pusho_tok"], $row["pusho_key"], $row["phonenumber"]); } } } } /* Go to the chat */ jak_redirect($gochat); } } } } } // Load messages for the group chat. if (empty($headermsg)) { if (!empty($LC_ANSWERS) && is_array($LC_ANSWERS)) foreach ($LC_ANSWERS as $v) { if ($v["msgtype"] == 11 && $v["lang"] == $page2) { $phold = array("%operator%","%client%","%email%"); $replace = array("", "", JAK_EMAIL); $welcomemsg = str_replace($phold, $replace, $v["message"]); } if ($v["msgtype"] == 12 && $v["lang"] == $page2) { $phold = array("%operator%","%client%","%email%"); $replace = array("", "", JAK_EMAIL); $offlinemsg = str_replace($phold, $replace, $v["message"]); } if ($v["msgtype"] == 13 && $v["lang"] == $page2) { $phold = array("%operator%","%client%","%email%"); $replace = array("", "", JAK_EMAIL); $fullmsg = str_replace($phold, $replace, $v["message"]); } } } ?> <?php echo $groupchat[$page1]['title'];?> - <?php echo JAK_TITLE;?>

">