chat.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. $data = false;
  3. ini_set("display_errors", 1);
  4. ini_set("error_reporting", E_ALL | E_STRICT);
  5. require_once("user.php");
  6. require_once("functions.php");
  7. $USER = new User("registration_callback");
  8. $dbfile = DATABASE_LOCATION.'users.db';
  9. $file_db = new PDO("sqlite:" . $dbfile);
  10. $file_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11. $dbOptions = $file_db->query('SELECT name FROM sqlite_master WHERE type="table" AND name="options"');
  12. $hasOptions = "No";
  13. foreach($dbOptions as $row) :
  14. if (in_array("options", $row)) :
  15. $hasOptions = "Yes";
  16. endif;
  17. endforeach;
  18. if($hasOptions == "No") :
  19. $title = "Organizr";
  20. $topbar = "#333333";
  21. $topbartext = "#66D9EF";
  22. $bottombar = "#333333";
  23. $sidebar = "#393939";
  24. $hoverbg = "#AD80FD";
  25. $activetabBG = "#F92671";
  26. $activetabicon = "#FFFFFF";
  27. $activetabtext = "#FFFFFF";
  28. $inactiveicon = "#66D9EF";
  29. $inactivetext = "#66D9EF";
  30. $loading = "#66D9EF";
  31. $hovertext = "#000000";
  32. endif;
  33. if($hasOptions == "Yes") :
  34. $resulto = $file_db->query('SELECT * FROM options');
  35. foreach($resulto as $row) :
  36. $title = isset($row['title']) ? $row['title'] : "Organizr";
  37. $topbartext = isset($row['topbartext']) ? $row['topbartext'] : "#66D9EF";
  38. $topbar = isset($row['topbar']) ? $row['topbar'] : "#333333";
  39. $bottombar = isset($row['bottombar']) ? $row['bottombar'] : "#333333";
  40. $sidebar = isset($row['sidebar']) ? $row['sidebar'] : "#393939";
  41. $hoverbg = isset($row['hoverbg']) ? $row['hoverbg'] : "#AD80FD";
  42. $activetabBG = isset($row['activetabBG']) ? $row['activetabBG'] : "#F92671";
  43. $activetabicon = isset($row['activetabicon']) ? $row['activetabicon'] : "#FFFFFF";
  44. $activetabtext = isset($row['activetabtext']) ? $row['activetabtext'] : "#FFFFFF";
  45. $inactiveicon = isset($row['inactiveicon']) ? $row['inactiveicon'] : "#66D9EF";
  46. $inactivetext = isset($row['inactivetext']) ? $row['inactivetext'] : "#66D9EF";
  47. $loading = isset($row['loading']) ? $row['loading'] : "#66D9EF";
  48. $hovertext = isset($row['hovertext']) ? $row['hovertext'] : "#000000";
  49. endforeach;
  50. endif;
  51. ?>
  52. <!DOCTYPE html>
  53. <html lang="en" class="no-js">
  54. <head>
  55. <meta charset="UTF-8">
  56. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  57. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  58. <meta name="msapplication-tap-highlight" content="no" />
  59. <title><?=$title;?> Chat</title>
  60. <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  61. <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  62. <link rel="stylesheet" href="bower_components/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.css">
  63. <script src="js/menu/modernizr.custom.js"></script>
  64. <link rel="stylesheet" href="bower_components/animate.css/animate.min.css">
  65. <link rel="stylesheet" href="css/style.css?v=<?php echo INSTALLEDVERSION; ?>">
  66. <!--Scripts-->
  67. <script src="bower_components/jquery/dist/jquery.min.js"></script>
  68. <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
  69. <script src="bower_components/moment/min/moment.min.js"></script>
  70. <script src="bower_components/jquery.nicescroll/jquery.nicescroll.min.js"></script>
  71. <script src="bower_components/slimScroll/jquery.slimscroll.min.js"></script>
  72. <script src="bower_components/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.js"></script>
  73. <script src="bower_components/jquery.nicescroll/jquery.nicescroll.min.js"></script>
  74. <script src="bower_components/cta/dist/cta.min.js"></script>
  75. <script src="bower_components/fullcalendar/dist/fullcalendar.js"></script>
  76. <script src="js/jqueri_ui_custom/jquery-ui.min.js"></script>
  77. <script src="js/jquery.mousewheel.min.js" type="text/javascript"></script>
  78. <!--Other-->
  79. <script src="js/ajax.js?v=<?php echo INSTALLEDVERSION; ?>"></script>
  80. <script src="chatjs.php" defer="true"></script>
  81. <!--[if lt IE 9]>
  82. <script src="bower_components/html5shiv/dist/html5shiv.min.js"></script>
  83. <script src="bower_components/respondJs/dest/respond.min.js"></script>
  84. <![endif]-->
  85. <style>
  86. .offline{
  87. -webkit-filter: grayscale; /*sepia, hue-rotate, invert....*/
  88. -webkit-filter: brightness(25%);
  89. }
  90. <?php if(CUSTOMCSS == "true") :
  91. $template_file = "custom.css";
  92. $file_handle = fopen($template_file, "rb");
  93. echo fread($file_handle, filesize($template_file));
  94. fclose($file_handle);
  95. echo "\n";
  96. endif; ?>
  97. </style>
  98. </head>
  99. <body id="chat" class="scroller-body" style="padding: 0px;">
  100. <!-- D A T A B A S E -->
  101. <?php
  102. $dbcreated = false;
  103. if (!extension_loaded("SQLITE3")){
  104. echo '<div class="row" style="margin: 0"><div class="panel panel-danger" style="margin: 10px";>';
  105. echo '<div class="panel-heading">';
  106. echo '<h3 class="panel-title">SQLITE3</h3>';
  107. echo '</div>';
  108. echo '<div style="color: gray" class="panel-body">';
  109. echo 'SQLITE3 is NOT loaded! Please install it before proceeding';
  110. echo '</div></div></div>';
  111. die();
  112. }
  113. if( $db = new SQLite3("chatpack.db") )
  114. {
  115. if( $db->busyTimeout(5000) )
  116. {
  117. if( $db->exec("PRAGMA journal_mode = wal;") )
  118. {
  119. $logtable = "CREATE TABLE IF NOT EXISTS chatpack_log
  120. (id INTEGER PRIMARY KEY,
  121. timestamp INTEGER NOT NULL,
  122. user TEXT NOT NULL,
  123. avatar TEXT NOT NULL,
  124. message TEXT NOT NULL,
  125. liked INTEGER DEFAULT 0)";
  126. if( $db->exec($logtable) )
  127. {
  128. $usertable = "CREATE TABLE IF NOT EXISTS chatpack_typing
  129. (id INTEGER PRIMARY KEY,
  130. timestamp INTEGER NOT NULL,
  131. user TEXT NOT NULL)";
  132. $onlinetable = "CREATE TABLE IF NOT EXISTS chatpack_last_message
  133. (
  134. user TEXT PRIMARY KEY NOT NULL,
  135. timestamp INTEGER NOT NULL,
  136. avatar TEXT NOT NULL)";
  137. if( $db->exec($usertable) && $db->exec($onlinetable) )
  138. {
  139. $dbcreated = true;
  140. }
  141. else
  142. {
  143. errormessage("creating database table for typing");
  144. }
  145. }
  146. else
  147. {
  148. errormessage("creating database table for messages");
  149. }
  150. if( !$db->close() )
  151. {
  152. errormessage("closing database connection");
  153. }
  154. }
  155. else
  156. {
  157. errormessage("setting journal mode");
  158. }
  159. }
  160. else
  161. {
  162. errormessage("setting busy timeout");
  163. }
  164. }
  165. else
  166. {
  167. errormessage("using SQLite");
  168. }
  169. if( $dbcreated )
  170. {
  171. ?>
  172. <div class="main-wrapper" style="position: initial;">
  173. <div id="content" class="container-fluid">
  174. <br>
  175. <div class="row">
  176. <div class="col-lg-10">
  177. <div class="content-box big-box chat gray-bg">
  178. <div class="box" style="overflow: hidden; width: auto; height: 550px;">
  179. <div id="intro">
  180. <center><img class="logo" alt="logo" src="images/organizr-logo-h.png">
  181. <br><br>start chatting...</center>
  182. </div>
  183. <ul id="messages" class="chat-double chat-container"></ul>
  184. <ul class="chat-double chat-container" style="padding: 0px;"><li id="istyping"></li></ul>
  185. </div>
  186. <br/>
  187. <input id="message" autofocus type="text" class="form-control gray-bg" placeholder="Enter your text" autocomplete="off"/>
  188. <audio id="tabalert" preload="auto">
  189. <source src="chat/audio/newmessage.mp3" type="audio/mpeg">
  190. </audio>
  191. </div>
  192. </div>
  193. <div class="col-lg-2">
  194. <div class="content-box">
  195. <div class="content-title big-box i-block gray-bg">
  196. <h4 class="zero-m">Online</h4>
  197. </div>
  198. <div class="clearfix"></div>
  199. <div id="onlineusers" class="big-box"></div>
  200. </div>
  201. </div>
  202. </div>
  203. </div>
  204. </div>
  205. <?php
  206. }
  207. function errormessage($msg)
  208. {
  209. echo "<div style=\"margin-top: 50px;\">";
  210. echo "<span style=\"color:#d89334;\">error </span>";
  211. echo $msg;
  212. echo "</div>";
  213. }
  214. ?>
  215. </body>
  216. <script>
  217. $(".box").niceScroll({
  218. railpadding: {top:0,right:0,left:0,bottom:0},
  219. scrollspeed: 30,
  220. mousescrollstep: 60
  221. });
  222. $("#onlineusers").niceScroll({
  223. railpadding: {top:0,right:0,left:0,bottom:0},
  224. scrollspeed: 30,
  225. mousescrollstep: 60
  226. });
  227. </script>
  228. </html>