prefs.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <?php
  2. set_include_path(get_include_path() . PATH_SEPARATOR .
  3. dirname(__FILE__) ."/include");
  4. require_once "functions.php";
  5. function css_editor() {
  6. $user_css = get_pref("USER_STYLESHEET");
  7. ?>
  8. <div class="modal-header">
  9. <button type="button" onclick="close_infobox()" class="close">&times;</button>
  10. <h4 class="modal-title"><?php echo __("Customize Theme") ?></h4>
  11. </div>
  12. <div class="modal-body">
  13. <div class="alert alert-info" id="mini-notice" style='display : none'>&nbsp;</div>
  14. <form class="form" id="prefs_css_form" onsubmit="return false;">
  15. <input type="hidden" name="op" value="prefs-save-css"/>
  16. <div class="alert alert-info"><?php echo T_sprintf("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here.") ?></div>
  17. <textarea name="user_css" rows="10" class="form-control"><?php echo $user_css ?></textarea>
  18. </form>
  19. </div>
  20. <div class="modal-footer">
  21. <button class="btn btn-primary" type="submit" onclick="save_css()"><?php echo __('Save & Reload') ?></button>
  22. <button class="btn btn-default" type="submit" onclick="show_prefs()"><?php echo __('Go back') ?></button></div>
  23. </div>
  24. </div>
  25. <?php
  26. }
  27. function print_servers($id) {
  28. $dbh = DB::get();
  29. $sth = $dbh->prepare("SELECT ttirc_servers.*,
  30. status,active_server
  31. FROM ttirc_servers,ttirc_connections
  32. WHERE connection_id = ? AND
  33. connection_id = ttirc_connections.id AND
  34. owner_uid = ?");
  35. $sth->execute([$id, $_SESSION['uid']]);
  36. while ($line = $sth->fetch()) {
  37. $id = $line['id'];
  38. if ($line['status'] != CS_DISCONNECTED &&
  39. $line['server'] . ':' . $line['port'] == $line['active_server']) {
  40. $connected = __("(connected)");
  41. } else {
  42. $connected = '';
  43. }
  44. print "<li class='row' id='S-$id' server_id='$id'>";
  45. print "<div class='checkbox'><label>";
  46. print "<input type='checkbox' onchange='select_row(this)'
  47. row_id='S-$id'>";
  48. print $line['server'] . ":" . $line['port'] . " $connected";
  49. print "</label></div>";
  50. print "</li>";
  51. }
  52. }
  53. function notification_editor() {
  54. $notify_on = json_decode(get_pref("NOTIFY_ON"));
  55. if (!is_array($notify_on)) $notify_on = array();
  56. $nev_checked = array();
  57. foreach ($notify_on as $no) {
  58. $nev_checked[$no] = "checked";
  59. }
  60. ?>
  61. <div class="modal-header">
  62. <button type="button" onclick="close_infobox()" class="close">&times;</button>
  63. <h4 class="modal-title"><?php echo __("Notifications") ?></h4>
  64. </div>
  65. <div class="modal-body">
  66. <div id="mini-notice" class="alert alert-info" style='display : none'>&nbsp;</div>
  67. <div class="alert alert-info"><?php echo T_sprintf("Desktop notifications are only shown for events happening in background channels or when your Tiny Tiny IRC window is unfocused.") ?></div>
  68. <form class="form" id="prefs_notify_form" onsubmit="return false;">
  69. <input type="hidden" name="op" value="prefs-save-notify"/>
  70. <h5><?php echo __('Notify events') ?></h5>
  71. <div class="form-group">
  72. <div class="col-sm-6">
  73. <div class="checkbox"><label for="n_highlight">
  74. <input name="notify_event[]" <?php echo $nev_checked[1] ?>
  75. id="n_highlight" type="checkbox" value="1">
  76. <?php echo __('Channel highlight') ?>
  77. </label></div>
  78. <div class="checkbox"><label for="n_privmsg">
  79. <input name="notify_event[]" <?php echo $nev_checked[2] ?>
  80. id="n_privmsg" type="checkbox" value="2">
  81. <?php echo __('Private message') ?>
  82. </label></div>
  83. <div class="checkbox"><label for="n_connstat">
  84. <input name="notify_event[]" <?php echo $nev_checked[3] ?>
  85. id="n_connstat" type="checkbox" value="3">
  86. <?php echo __('Connection status change') ?>
  87. </label></div>
  88. <div class="checkbox"><label for="n_chanmsg">
  89. <input name="notify_event[]" <?php echo $nev_checked[4] ?>
  90. id="n_chanmsg" type="checkbox" value="4">
  91. <?php echo __('Channel message') ?>
  92. </label></div>
  93. </div>
  94. </div>
  95. </form>
  96. </div>
  97. <div class="modal-footer">
  98. <div style='float : left'>
  99. <button class="btn btn-default" type="submit" onclick="notify_enable()"><?php echo __('Enable notifications') ?></button></div>
  100. <button class="btn btn-primary" type="submit" onclick="save_notifications()"><?php echo __('Save') ?></button>
  101. <button class="btn btn-default" type="submit" onclick="show_prefs()"><?php echo __('Go back') ?></button></div>
  102. </div>
  103. </div>
  104. <?php
  105. }
  106. function connection_editor($id) {
  107. $dbh = DB::get();
  108. $sth = $dbh->prepare("SELECT * FROM ttirc_connections
  109. WHERE id = ? AND owner_uid = ?");
  110. $sth->execute([$id, $_SESSION['uid']]);
  111. $line = $sth->fetch();
  112. $auto_connect_checked = $line['auto_connect'] ? 'checked' : '';
  113. $visible_checked = $line['visible'] ? 'checked' : '';
  114. $permanent_checked = $line['permanent'] ? 'checked' : '';
  115. $use_ssl_checked = $line['use_ssl'] ? 'checked' : '';
  116. ?>
  117. <div class="modal-header">
  118. <button type="button" onclick="close_infobox()" class="close">&times;</button>
  119. <h4 class="modal-title"><?php echo __("Edit Connection") ?></h4>
  120. </div>
  121. <div class="modal-body">
  122. <div class="alert alert-info" id="mini-notice" style='display : none'>&nbsp;</div>
  123. <form class="form form-horizontal" id="prefs_conn_form" onsubmit="return false;">
  124. <input type="hidden" name="connection_id" value="<?php echo $id ?>"/>
  125. <input type="hidden" name="op" value="prefs-conn-save"/>
  126. <div class="form-group">
  127. <label class='col-sm-4 control-label'><?php echo __('Title:') ?></label>
  128. <div class="col-sm-6">
  129. <input type="text" class="form-control" name="title" required="1" size="30" value="<?php echo $line['title'] ?>">
  130. </div>
  131. </div>
  132. <div class="form-group">
  133. <label class='col-sm-4 control-label'><?php echo __('Server password:') ?></label>
  134. <div class="col-sm-6">
  135. <input class="form-control" name="server_password" size="30" type="password"
  136. value="<?php echo $line['server_password'] ?>">
  137. </div>
  138. </div>
  139. <div class="form-group">
  140. <label class="col-sm-4 control-label"><?php echo __('Nickname:') ?></label>
  141. <div class="col-sm-6">
  142. <input type="text" class="form-control" name="nick" size="30" value="<?php echo $line['nick'] ?>">
  143. </div>
  144. </div>
  145. <div class="form-group">
  146. <label class='col-sm-4 control-label'><?php echo __('Favorite channels:') ?></label>
  147. <div class="col-sm-6">
  148. <input type="text" class="form-control" name="autojoin" size="30" value="<?php echo $line['autojoin'] ?>">
  149. </div>
  150. </div>
  151. <div class="form-group">
  152. <label class='col-sm-4 control-label'><?php echo __('Connect command:') ?></label>
  153. <div class="col-sm-6">
  154. <input type="text" class="form-control" name="connect_cmd" size="30" value="<?php echo $line['connect_cmd'] ?>">
  155. </div>
  156. </div>
  157. <div class="form-group">
  158. <label class='col-sm-4 control-label'><?php echo __('Character set:') ?></label>
  159. <div class="col-sm-6">
  160. <?php print_select('encoding', $line['encoding'], get_iconv_encodings()) ?>
  161. </div>
  162. </div>
  163. <div class="form-group">
  164. <div class="col-sm-4"></div>
  165. <div class="col-sm-6">
  166. <div class="checkbox"><label for="pr_visible">
  167. <input name="visible" <?php echo $visible_checked ?>
  168. id="pr_visible" type="checkbox" value="1">
  169. <?php echo __('Enable connection') ?>
  170. </label></div>
  171. <div class="checkbox"><label for="pr_auto_connect">
  172. <input name="auto_connect" <?php echo $auto_connect_checked ?>
  173. id="pr_auto_connect" type="checkbox" value="1">
  174. <?php echo __('Automatically connect') ?>
  175. </label></div>
  176. <div class="checkbox"><label for="pr_permanent">
  177. <input name="permanent" <?php echo $permanent_checked ?>
  178. id="pr_permanent" type="checkbox" value="1">
  179. <?php echo __('Stay connected permanently') ?>
  180. </label></div>
  181. <div class="checkbox"><label for="pr_use_ssl">
  182. <input name="use_ssl" <?php echo $use_ssl_checked ?>
  183. id="pr_use_ssl" type="checkbox" value="1">
  184. <?php echo __('Connect using SSL') ?>
  185. </label></div>
  186. </div>
  187. </div>
  188. <button type="submit" style="display : none" onclick="save_conn()"></button>
  189. <h5><?php echo __('Servers') ?></h5>
  190. <ul id="servers-list" class="list-unstyled scrollable panel panel-default">
  191. <?php print_servers($id); ?>
  192. </ul>
  193. </form>
  194. </div>
  195. <div class="modal-footer">
  196. <div style='float : left'>
  197. <button class="btn btn-default" onclick="create_server()"><?php echo __('Add server') ?></button>
  198. <button class="btn btn-danger" onclick="delete_server()"><?php echo __('Delete') ?></button>
  199. </div>
  200. <button class="btn btn-primary" type="submit" onclick="save_conn()"><?php echo __('Save') ?></button>
  201. <button class="btn btn-default" type="submit" onclick="show_prefs()"><?php echo __('Go back') ?></button></div>
  202. </div>
  203. </div>
  204. <?php
  205. }
  206. function print_connections() {
  207. $dbh = DB::get();
  208. $sth = $dbh->prepare("SELECT * FROM ttirc_connections
  209. WHERE title != '_ttirc_instance' AND owner_uid = ?");
  210. $sth->execute([$_SESSION['uid']]);
  211. while ($line = $sth->fetch()) {
  212. $id = $line['id'];
  213. if ($line["status"] != "0") {
  214. $connected = __("(active)");
  215. } else {
  216. $connected = "";
  217. }
  218. print "<li class='row' id='C-$id' connection_id='$id'>";
  219. print "<div class='checkbox'><label>";
  220. print "<input type='checkbox' onchange='select_row(this)'
  221. row_id='C-$id'>";
  222. print "<a href=\"#\" title=\"".__('Click to edit connection')."\"
  223. onclick=\"edit_connection($id)\">".
  224. $line['title']." $connected</a>";
  225. print "</label></div>";
  226. print "</li>";
  227. }
  228. }
  229. function main_prefs() {
  230. $_SESSION["prefs_cache"] = false;
  231. $dbh = DB::get();
  232. $sth = $dbh->prepare("SELECT * FROM ttirc_users WHERE id = ?");
  233. $sth->execute([$_SESSION['uid']]);
  234. $row = $sth->fetch();
  235. $realname = $row["realname"];
  236. $nick = $row["nick"];
  237. $email = $row["email"];
  238. $quit_message = $row["quit_message"];
  239. $hide_join_part_checked = $row['hide_join_part'] ? 'checked' : '';
  240. $highlight_on = get_pref("HIGHLIGHT_ON");
  241. $disable_image_preview_checked = get_pref("DISABLE_IMAGE_PREVIEW") ? "checked" : "";
  242. ?>
  243. <div class="modal-header">
  244. <button type="button" onclick="close_infobox()" class="close">&times;</button>
  245. <h4 class="modal-title"><?php echo __("Preferences") ?></h4 class="modal-title"></div>
  246. <div class="modal-body">
  247. <form class="form-horizontal" id="prefs_form" onsubmit="return false;">
  248. <div id="mini-notice" class="alert alert-info" style='display : none'>&nbsp;</div>
  249. <input type="hidden" name="op" value="prefs-save"/>
  250. <div class="form-group">
  251. <label class="col-sm-4 control-label"><?php echo __('Real name:') ?></label>
  252. <div class="col-sm-6">
  253. <input class="form-control" type="text" name="realname" required="1" size="30" value="<?php echo $realname ?>">
  254. </div>
  255. </div>
  256. <div class="form-group">
  257. <label class="col-sm-4 control-label"><?php echo __('Nickname:') ?></label>
  258. <div class="col-sm-6">
  259. <input type="text" class="form-control" name="nick" required="1" size="30" value="<?php echo $nick ?>">
  260. </div>
  261. </div>
  262. <div class="form-group">
  263. <label class="col-sm-4 control-label"><?php echo __('E-mail:') ?></label>
  264. <div class="col-sm-6">
  265. <input type="text" class="form-control" name="email" required="1" size="30" value="<?php echo $email ?>">
  266. </div>
  267. </div>
  268. <div class="form-group">
  269. <label class="col-sm-4 control-label"><?php echo __('Quit message:') ?></label>
  270. <div class="col-sm-6">
  271. <input type="text" class="form-control" name="quit_message" size="30" value="<?php echo $quit_message ?>">
  272. </div>
  273. </div>
  274. <div class="form-group">
  275. <label class="col-sm-4 control-label"><?php echo __('Highlight on:') ?></label>
  276. <div class="col-sm-6">
  277. <input type="text" class="form-control" name="highlight_on" size="30" value="<?php echo $highlight_on ?>">
  278. </div>
  279. </div>
  280. <div class="form-group">
  281. <label class="col-sm-4 control-label"><?php echo __('Theme:') ?></label>
  282. <div class="col-sm-6">
  283. <div class="input-group">
  284. <?php print_theme_select(); ?>
  285. <a class="input-group-addon btn btn-default" href="#" onclick="customize_css()">
  286. <?php echo __("Customize") ?></a>
  287. </div>
  288. </div>
  289. </div>
  290. <div class="form-group">
  291. <div class="col-sm-4"></div>
  292. <div class="col-sm-6">
  293. <a class="btn btn-default" href="#" onclick="configure_notifications()"><?php echo __('Configure desktop notifications') ?></a>
  294. </div>
  295. </div>
  296. <div class="form-group">
  297. <div class="col-sm-4"></div>
  298. <div class="col-sm-6">
  299. <div class="checkbox">
  300. <label><input name="hide_join_part" <?php echo $hide_join_part_checked ?>
  301. id="pr_hide_join_part" type="checkbox" value="1">
  302. <?php echo __('Do not highlight tabs on auxiliary messages') ?></label></div>
  303. <div class="checkbox">
  304. <label><input name="disable_image_preview" <?php echo $disable_image_preview_checked ?>
  305. id="pr_disable_image_preview" type="checkbox" value="1">
  306. <?php echo __('Disable popup image viewer') ?></label></div>
  307. </div>
  308. </div>
  309. <div class="form-group">
  310. <label class="col-sm-4 control-label"><?php echo __('Change password:') ?></label>
  311. <div class="col-sm-6">
  312. <input placeholder="<?php echo __("New password") ?>" autocomplete="off" type="password" class="form-control" name="new_password" type="password" size="30" value="">
  313. </div>
  314. </div>
  315. <div class="form-group">
  316. <label class="col-sm-4"> </label>
  317. <div class="col-sm-6">
  318. <input placeholder="<?php echo __("Confirm password") ?>" autocomplete="off" type="password" class="form-control" name="confirm_password" type="password" size="30" value="">
  319. </div>
  320. </div>
  321. <h5><?php echo __('Connections') ?></h5>
  322. <ul class="scrollable panel panel-default list-unstyled" id="connections-list"><?php print_connections() ?></ul>
  323. </form>
  324. </div>
  325. <div class="modal-footer">
  326. <div style='float : left'>
  327. <button class="btn btn-default" onclick="create_connection()">
  328. <?php echo __('Create connection') ?></button class="btn">
  329. <button class="btn btn-danger" onclick="delete_connection()">
  330. <?php echo __('Delete') ?></button class="btn">
  331. </div>
  332. <button class="btn btn-primary" type="submit" onclick="save_prefs()">
  333. <?php echo __('Save') ?></button class="btn">
  334. <button class="btn btn-default" onclick="close_infobox()"><?php echo __('Close') ?></button>
  335. </div>
  336. <?php } ?>