PageRenderTime 29ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/test/cometchat/plugins/chathistory/index.php

https://github.com/chacha13/runningmate
PHP | 399 lines | 272 code | 72 blank | 55 comment | 16 complexity | b9efcc21e0270e8fd381f5063c70ecfa MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. CometChat
  4. Copyright (c) 2009 Inscripts
  5. CometChat ('the Software') is a copyrighted work of authorship. Inscripts
  6. retains ownership of the Software and any copies of it, regardless of the
  7. form in which the copies may exist. This license is not a sale of the
  8. original Software or any copies.
  9. By installing and using CometChat on your server, you agree to the following
  10. terms and conditions. Such agreement is either on your own behalf or on behalf
  11. of any corporate entity which employs you or which you represent
  12. ('Corporate Licensee'). In this Agreement, 'you' includes both the reader
  13. and any Corporate Licensee and 'Inscripts' means Inscripts (I) Private Limited:
  14. CometChat license grants you the right to run one instance (a single installation)
  15. of the Software on one web server and one web site for each license purchased.
  16. Each license may power one instance of the Software on one domain. For each
  17. installed instance of the Software, a separate license is required.
  18. The Software is licensed only to you. You may not rent, lease, sublicense, sell,
  19. assign, pledge, transfer or otherwise dispose of the Software in any form, on
  20. a temporary or permanent basis, without the prior written consent of Inscripts.
  21. The license is effective until terminated. You may terminate it
  22. at any time by uninstalling the Software and destroying any copies in any form.
  23. The Software source code may be altered (at your risk)
  24. All Software copyright notices within the scripts must remain unchanged (and visible).
  25. The Software may not be used for anything that would represent or is associated
  26. with an Intellectual Property violation, including, but not limited to,
  27. engaging in any activity that infringes or misappropriates the intellectual property
  28. rights of others, including copyrights, trademarks, service marks, trade secrets,
  29. software piracy, and patents held by individuals, corporations, or other entities.
  30. If any of the terms of this Agreement are violated, Inscripts reserves the right
  31. to revoke the Software license at any time.
  32. The above copyright notice and this permission notice shall be included in
  33. all copies or substantial portions of the Software.
  34. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  35. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  36. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  37. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  38. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  39. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  40. THE SOFTWARE.
  41. */
  42. include dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR."plugins.php";
  43. $body = '';
  44. logs();
  45. function logsview() {
  46. global $db;
  47. $usertable = DB_USERTABLE;
  48. $usertable_username = DB_USERTABLE_NAME;
  49. $usertable_userid = DB_USERTABLE_USERID;
  50. global $body;
  51. global $userid;
  52. $data = array();
  53. if (!empty($_GET['id'])) {
  54. $data = preg_split("/,/",base64_decode($_GET['id']));
  55. }
  56. $sql = ("select m1.*, f.$usertable_username fromu, t.$usertable_username tou from cometchat m1, ".TABLE_PREFIX."$usertable f, ".TABLE_PREFIX."$usertable t where f.$usertable_userid = m1.from and t.$usertable_userid = m1.to and ((m1.from = '".mysql_real_escape_string($userid)."') or (m1.to = '".mysql_real_escape_string($userid)."')) and m1.id >= $data[0] and m1.id < $data[1] order by id");
  57. if (!empty($_GET['history'])) {
  58. $history = $_GET['history'];
  59. $sql = ("select m1.*, f.$usertable_username fromu, t.$usertable_username tou from cometchat m1, ".TABLE_PREFIX."$usertable f, ".TABLE_PREFIX."$usertable t where f.$usertable_userid = m1.from and t.$usertable_userid = m1.to and ((m1.from = '".mysql_real_escape_string($userid)."' and m1.to = '".mysql_real_escape_string($history)."') or (m1.to = '".mysql_real_escape_string($userid)."' and m1.from = '".mysql_real_escape_string($history)."')) and m1.id >= $data[0] and m1.id < $data[1] order by id");
  60. }
  61. $query = mysql_query($sql);
  62. $chatdata = '';
  63. $previd = '';
  64. $lines = 0;
  65. $s = 0;
  66. while ($chat = mysql_fetch_array($query)) {
  67. if ($s == 0) { $s = $chat['sent']; }
  68. $requester = $chat['fromu'];
  69. if ($chat['from'] == '1') {
  70. $requester = $chat['tou'];
  71. $chat['fromu'] = 'Me';
  72. }
  73. $time = date('g:iA', $chat['sent']);
  74. $chat['message'] = strip_tags($chat['message']);
  75. $display = $chat['fromu'].':';
  76. $chatnoline = '';
  77. if ($previd == $chat['fromu']) {
  78. $display = '';
  79. $time = '';
  80. $chatnoline = '';
  81. }
  82. $lines++;
  83. $chatdata = <<<EOD
  84. $chatdata
  85. <div class="chat chatnoline">
  86. <div class="chatrequest" style="text-align:right;padding-right:5px;"><b>$display</b></div>
  87. <div class="chatmessage chatnowrap">{$chat['message']}</div>
  88. <div class="chattime">$time</div>
  89. <div style="clear:both"></div>
  90. </div>
  91. EOD;
  92. $previd = $chat['fromu'];
  93. }
  94. $time = date('M jS Y', $s);
  95. if (!empty($_GET['history'])) {
  96. $history = '?history='.$_GET['history'];
  97. }
  98. $body = <<<EOD
  99. <script>
  100. jQuery(document).ready(function () {
  101. });
  102. </script>
  103. <div class="chatbar"><div style="float:left">Chat Conversation with $requester ($lines lines)<br> on $time</div><div style="float:right;padding-right:7px;"><a href="index.php$history">Back</a></div><div style="clear:both"></div></div>
  104. $chatdata
  105. EOD;
  106. template();
  107. }
  108. function logs() {
  109. global $db;
  110. $usertable = DB_USERTABLE;
  111. $usertable_username = DB_USERTABLE_NAME;
  112. $usertable_userid = DB_USERTABLE_USERID;
  113. global $body;
  114. global $userid;
  115. if (!empty($_GET['id'])) { logsview(); }
  116. $sql = ("select m1.*, f.$usertable_username fromu, t.$usertable_username tou from cometchat m1, ".TABLE_PREFIX."$usertable f, ".TABLE_PREFIX."$usertable t
  117. where f.$usertable_userid = m1.from and t.$usertable_userid = m1.to and ((m1.from = '".mysql_real_escape_string($userid)."') or (m1.to = '".mysql_real_escape_string($userid)."')) and (m1.sent) > ALL
  118. (select (m2.sent)+1800 from cometchat m2
  119. where ((m2.to = m1.to and m2.from = m1.from) or (m2.to = m1.from and m2.from = m1.to))
  120. and m2.sent <= m1.sent and m2.id < m1.id) order by id desc");
  121. if (!empty($_GET['history'])) {
  122. $history = $_GET['history'];
  123. $sql = ("select m1.*, f.$usertable_username fromu, t.$usertable_username tou from cometchat m1, ".TABLE_PREFIX."$usertable f, ".TABLE_PREFIX."$usertable t
  124. where f.$usertable_userid = m1.from and t.$usertable_userid = m1.to and ((m1.from = '".mysql_real_escape_string($userid)."' and m1.to = '".mysql_real_escape_string($history)."') or (m1.to = '".mysql_real_escape_string($userid)."' and m1.from = '".mysql_real_escape_string($history)."')) and (m1.sent) > ALL
  125. (select (m2.sent)+1800 from cometchat m2
  126. where ((m2.to = m1.to and m2.from = m1.from) or (m2.to = m1.from and m2.from = m1.to))
  127. and m2.sent <= m1.sent and m2.id < m1.id) order by id desc");
  128. }
  129. $query = mysql_query($sql);
  130. $chatdata = '<table>';
  131. $previd = 1000000;
  132. while ($chat = mysql_fetch_array($query)) {
  133. $requester = $chat['fromu'];
  134. if ($chat['from'] == '1') {
  135. $requester = $chat['tou'];
  136. $chat['fromu'] = 'Me';
  137. }
  138. $time = date('g:iA M dS', $chat['sent']);
  139. $chat['message'] = strip_tags($chat['message']);
  140. $encode = base64_encode($chat['id'].",".$previd);
  141. $chatdata = <<<EOD
  142. $chatdata
  143. <div class="chat" id="{$encode}">
  144. <div class="chatmessage"><b>{$chat['fromu']}</b>: {$chat['message']}</div>
  145. <div class="chattime">$time</div>
  146. <div style="clear:both"></div>
  147. </div>
  148. EOD;
  149. $previd = $chat['id'];
  150. }
  151. $chatdata .= '</table>';
  152. $history = '';
  153. if (!empty($_GET['history'])) {
  154. $history = '+"&history='.$_GET['history'].'"';
  155. }
  156. $body = <<<EOD
  157. <script>
  158. jQuery(document).ready(function () {
  159. $('.chat').mouseover(function() {
  160. $(this).addClass('chatbg');
  161. });
  162. $('.chat').mouseout(function() {
  163. $(this).removeClass('chatbg');
  164. });
  165. $('.chat').click(function() {
  166. var id = $(this).attr('id');
  167. location.href = "?action=logs&id="+id$history;
  168. });
  169. });
  170. </script>
  171. $chatdata
  172. EOD;
  173. template();
  174. }
  175. function template() {
  176. global $body;
  177. echo <<<EOD
  178. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  179. <html>
  180. <head>
  181. <title>Chat History</title>
  182. <style>
  183. html, body, div, span, applet, object, iframe,
  184. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  185. a, abbr, acronym, address, big, cite, code,
  186. del, dfn, em, font, img, ins, kbd, q, s, samp,
  187. small, strike, strong, sub, sup, tt, var,
  188. dl, dt, dd, ol, ul, li,
  189. fieldset, form, label, legend,
  190. table, caption, tbody, tfoot, thead, tr, th, td {
  191. margin: 0;
  192. padding: 0;
  193. border: 0;
  194. outline: 0;
  195. font-weight: inherit;
  196. font-style: inherit;
  197. font-size: 100%;
  198. font-family: inherit;
  199. vertical-align: baseline;
  200. }
  201. #container {
  202. margin:0 auto;
  203. width: 400px;
  204. padding:20px;
  205. }
  206. #content {
  207. border-left: 1px solid #ccc;
  208. border-right: 1px solid #ccc;
  209. border-bottom: 1px solid #ccc;
  210. padding: 15px;
  211. }
  212. .message {
  213. padding: 0px;
  214. width: 200px;
  215. font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;
  216. font-size:11px;
  217. background-color: #eeeeee;
  218. border-bottom: 1px solid #ccc;
  219. margin-bottom: 5px;
  220. -moz-border-radius-topleft:7px;
  221. -moz-border-radius-topright:7px;
  222. }
  223. .messageright {
  224. float:left;
  225. padding-left: 10px;
  226. padding-right: 10px;
  227. padding-top: 10px;
  228. padding-bottom: 10px;
  229. width: 265px;
  230. /* border-left: 1px dotted #0f5d7e; */
  231. }
  232. .messagetime {
  233. font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;
  234. font-size:9px;
  235. font-weight: bold;
  236. color: #666666;
  237. }
  238. .chat {
  239. font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;
  240. font-size:11px;
  241. color: #666666;
  242. padding-top:7px;
  243. padding-bottom:7px;
  244. border-bottom:1px solid #ccc;
  245. display: block;
  246. width: 350px;
  247. }
  248. .chat a {
  249. text-decoration: none;
  250. color: black;
  251. }
  252. a {
  253. color: black;
  254. }
  255. .chatrequest {
  256. float:left;
  257. width:50px;
  258. padding-left: 5px;
  259. height: 12px;
  260. overflow: hidden;
  261. }
  262. .chatmessage {
  263. float:left;
  264. width: 220px;
  265. padding-left:5px;
  266. }
  267. .chattime {
  268. font-size: 10px;
  269. float:right;
  270. text-align: right;
  271. padding-right: 5px;
  272. }
  273. .chatbg {
  274. background-color: #efefef;
  275. }
  276. .chatnoline {
  277. border-bottom: 0px !important;
  278. }
  279. .chattopline {
  280. border-top:1px solid #ccc;
  281. }
  282. .chatnowrap {
  283. height: default;
  284. overflow: show;
  285. }
  286. .chatbar {
  287. font-weight: bold;
  288. background-color: #eeeeee;
  289. border-bottom:1px solid #ccc;
  290. font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;
  291. font-size:11px;
  292. color: #666666;
  293. padding-top:7px;
  294. padding-bottom:7px;
  295. padding-left: 7px;
  296. }
  297. body {
  298. overflow-y:scroll;
  299. }
  300. </style>
  301. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  302. </head>
  303. <body>
  304. <div style="width:98%;margin:0 auto;margin-top: 5px;">
  305. <div style="border-left: 1px solid #11648F;border-top: 1px solid #11648F;border-right: 1px solid #11648F;background-color:#3E92BD;color:#fff;padding:5px;font-weight:bold;font-family:'lucida grande',tahoma,verdana,arial,sans-serif;font-size: 14px;letter-spacing:0px;padding-left:10px;text-align:left;">Chat History</div>
  306. <div style="border-left: 1px solid #cccccc;border-bottom: 1px solid #cccccc;border-right: 1px solid #cccccc;background-color:#fffff;color:#333;padding:5px;font-weight:normal;font-family:'lucida grande',tahoma,verdana,arial,sans-serif;font-size:11px;padding:10px 10px;text-align:left;margin-bottom:10px;">
  307. $body
  308. </div>
  309. </div>
  310. </div>
  311. </body>
  312. </html>
  313. EOD;
  314. exit;
  315. }