chat.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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( $db = new SQLite3("chatpack.db") )
  104. {
  105. if( $db->busyTimeout(5000) )
  106. {
  107. if( $db->exec("PRAGMA journal_mode = wal;") )
  108. {
  109. $logtable = "CREATE TABLE IF NOT EXISTS chatpack_log
  110. (id INTEGER PRIMARY KEY,
  111. timestamp INTEGER NOT NULL,
  112. user TEXT NOT NULL,
  113. avatar TEXT NOT NULL,
  114. message TEXT NOT NULL,
  115. liked INTEGER DEFAULT 0)";
  116. if( $db->exec($logtable) )
  117. {
  118. $usertable = "CREATE TABLE IF NOT EXISTS chatpack_typing
  119. (id INTEGER PRIMARY KEY,
  120. timestamp INTEGER NOT NULL,
  121. user TEXT NOT NULL)";
  122. if( $db->exec($usertable) )
  123. {
  124. $dbcreated = true;
  125. }
  126. else
  127. {
  128. errormessage("creating database table for typing");
  129. }
  130. }
  131. else
  132. {
  133. errormessage("creating database table for messages");
  134. }
  135. if( !$db->close() )
  136. {
  137. errormessage("closing database connection");
  138. }
  139. }
  140. else
  141. {
  142. errormessage("setting journal mode");
  143. }
  144. }
  145. else
  146. {
  147. errormessage("setting busy timeout");
  148. }
  149. }
  150. else
  151. {
  152. errormessage("using SQLite");
  153. }
  154. if( $dbcreated )
  155. {
  156. ?>
  157. <div class="main-wrapper" style="position: initial;">
  158. <div id="content" class="container-fluid">
  159. <br>
  160. <div class="row">
  161. <div class="col-lg-12">
  162. <div class="content-box big-box chat">
  163. <div class="content-title i-block">
  164. <h4 class="zero-m">Welcome To The Chat <?php echo $USER->username;?></h4>
  165. </div>
  166. <div class="box" style="overflow: hidden; width: auto; height: calc(100vh - 130px);">
  167. <div id="intro">
  168. <center><img class="logo" alt="logo" src="images/organizr-logo-h-d.png">
  169. <br><br>start chatting...</center>
  170. </div>
  171. <ul id="messages" class="chat-double chat-container"></ul>
  172. <ul class="chat-double chat-container" style="padding: 0px;"><li id="istyping"></li></ul>
  173. </div>
  174. <input id="message" autofocus type="text" class="form-control" placeholder="Enter your text" autocomplete="off"/>
  175. <audio id="tabalert" preload="auto">
  176. <source src="chat/audio/newmessage.mp3" type="audio/mpeg">
  177. </audio>
  178. </div>
  179. </div>
  180. </div>
  181. </div>
  182. </div>
  183. <?php
  184. }
  185. function errormessage($msg)
  186. {
  187. echo "<div style=\"margin-top: 50px;\">";
  188. echo "<span style=\"color:#d89334;\">error </span>";
  189. echo $msg;
  190. echo "</div>";
  191. }
  192. ?>
  193. </body>
  194. <script>
  195. $(".box").niceScroll({
  196. railpadding: {top:0,right:0,left:0,bottom:0},
  197. scrollspeed: 30,
  198. mousescrollstep: 60
  199. });
  200. </script>
  201. </html>