risvhal

MIROSTATOR/application/models/voucher_model.php

Dec 31st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. if (!defined('BASEPATH'))
  3. exit('No direct script access allowed');
  4.  
  5. class Voucher_model extends CI_Model {
  6.  
  7. function __construct() {
  8. parent::__construct();
  9. $this->load->model('stator');
  10. $this->load->model('log');
  11. }
  12.  
  13. //***MODEL VOUCHER.start
  14. function prosesGenerateVoucher($data = array()) {
  15. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { //.cek paka proxy atau tidak?
  16. $iptujuan = $_SERVER['HTTP_X_FORWARDED_FOR']; //pakai proxy
  17. } else {
  18. $iptujuan = $_SERVER['REMOTE_ADDR']; //tanpa proxy
  19. }
  20.  
  21. $namavoucher = $data['namavoucher'];
  22. $qty = $data['qty'];
  23. $userprofile = $data['userprofile'];
  24. $limituptime = $data['limituptime'];
  25. $tipepassword = $data['tipepassword'];
  26. $password = $data['password'];
  27. //$chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  28. $chars = "0123456789abcdefghijklmnopqrstuvwxyz";
  29. ?>
  30. <style>
  31. table td, table th{font-size:11px;}
  32. .nowrap {white-space:nowrap;}
  33. </style>
  34. <div class="table-responsive">
  35. <h3 style="color:#008899;">Voucher <span style="color:#ff7777"><?php echo $namavoucher; ?></span></h3>
  36. <table class="table table-hover table-striped table-condensed table-bordered" id="table_generate_voucher" data-order='[[ 0, "asc" ]]'>
  37. <thead>
  38. <tr>
  39. <th class="text-nowrap" title="menu order">NO</th>
  40. <th class="text-nowrap" title="menu name">USERNAME</th>
  41. <th class="text-nowrap" title="menu link">PASSWORD</th>
  42. <th class="text-nowrap" title="menu link">USER PROFILE</th>
  43. <th class="text-nowrap" title="menu link">LIMIT UPTIME</th>
  44. </tr>
  45. </thead>
  46. <tbody>
  47. <?php
  48. date_default_timezone_set('Asia/Jakarta');
  49. for ($n = 1; $n <= $qty; $n++) {
  50. $res1 = '';
  51. $res2 = '';
  52. for ($i = 0; $i < 6; $i++) {
  53. $res1 .= $chars[mt_rand(0, strlen($chars) - 1)];
  54. }
  55. if ($tipepassword == 'at') {
  56. for ($i = 0; $i < 6; $i++) {
  57. $res2 .= $chars[mt_rand(0, strlen($chars) - 1)];
  58. }
  59. }
  60. if ($tipepassword == 'sm') {
  61. $res2 = $res1;
  62. }
  63. if ($tipepassword == 'mt') {
  64. $res2 = $password;
  65. }
  66. // } else {
  67. // $res2 = $password;
  68. // }
  69.  
  70.  
  71. $user = $res1;
  72. $password = $res2;
  73. $userprofile = $userprofile;
  74. $limit_uptime = $limituptime;
  75. $server = 'all';
  76.  
  77. $data = array(
  78. 'user' => $user,
  79. 'password' => $password,
  80. 'userprofile' => $userprofile,
  81. 'limit_uptime' => $limit_uptime,
  82. 'server' => $server,
  83. 'comment' => $namavoucher,
  84. );
  85.  
  86. $ARRAY = $this->mikrostator->addHotspotUserVoucher($data);
  87. if ($ARRAY[0] == "!done") { //.0 berarti tidak ada pesan tambahan/sukses
  88. $msg = "sukses";
  89. } else {
  90. $msg = "gagal";
  91. }
  92.  
  93. //.insert to db.begin
  94. $datax = array(
  95. 'voucher_name' => $namavoucher,
  96. 'voucher_username' => $res1,
  97. 'voucher_password_type' => $tipepassword,
  98. 'voucher_password' => $res2,
  99. 'voucher_qty' => $qty,
  100. 'voucher_user_profile' => $userprofile,
  101. 'voucher_limit_uptime' => $limituptime,
  102. 'voucher_status' => $msg,
  103. );
  104. $this->db->insert('wk_voucher', $datax);
  105. //.insert to db.end
  106. ?>
  107. <tr>
  108. <td class="text-nowrap"><?php echo $n; ?></td>
  109. <td class="text-nowrap"><?php echo $res1; ?></td>
  110. <td class="text-nowrap"><?php echo $res2; ?></td>
  111. <td class="text-nowrap"><?php echo $userprofile; ?></td>
  112. <td class="text-nowrap"><?php echo $limituptime; ?></td>
  113. </tr>
  114. <?php
  115. }
  116. ?>
  117. </tbody>
  118. </table>
  119. </div>
  120. <script>
  121. $(document).ready(function() {
  122. $('#table_generate_voucher').DataTable({
  123. });
  124. });
  125. </script>
  126. <?php
  127. }
  128.  
  129. function getVoucherList($data = array()) {
  130. $namavoucher = $data['namavoucher'];
  131. ?>
  132. <style>
  133. table td, table th{font-size:11px;}
  134. .nowrap {white-space:nowrap;}
  135. </style>
  136. <div class="table-responsive">
  137. <h3 style="color:#008899;">Voucher <span style="color:#ff7777"><?php echo $namavoucher; ?></span></h3>
  138. <table class="table table-hover table-striped table-condensed table-bordered" id="table_generate_voucher" data-order='[[ 0, "asc" ]]'>
  139. <thead>
  140. <tr>
  141. <th class="text-nowrap">NO</th>
  142. <th class="text-nowrap">USERNAME</th>
  143. <th class="text-nowrap">PASSWORD</th>
  144. <th class="text-nowrap">USER PROFILE</th>
  145. <th class="text-nowrap">LIMIT UPTIME</th>
  146. <th class="text-nowrap">STATUS</th>
  147. </tr>
  148. </thead>
  149. <tbody>
  150. <?php
  151. date_default_timezone_set('Asia/Jakarta');
  152. $this->db->select('*');
  153. $this->db->from('wk_voucher');
  154. $this->db->where('voucher_name', $namavoucher);
  155. $query = $this->db->get();
  156. $n = 0;
  157. foreach ($query->result() as $row) {
  158. $n++;
  159. $res1 = $row->voucher_username;
  160. $res2 = $row->voucher_password;
  161. $userprofile = $row->voucher_user_profile;
  162. $limituptime = $row->voucher_limit_uptime;
  163. $status = $row->voucher_status;
  164. ?>
  165. <tr>
  166. <td class="text-nowrap"><?php echo $n; ?></td>
  167. <td class="text-nowrap"><?php echo $res1; ?></td>
  168. <td class="text-nowrap"><?php echo $res2; ?></td>
  169. <td class="text-nowrap"><?php echo $userprofile; ?></td>
  170. <td class="text-nowrap"><?php echo $limituptime; ?></td>
  171. <td class="text-nowrap"><?php echo $status; ?></td>
  172. </tr>
  173. <?php
  174. }
  175. ?>
  176. </tbody>
  177. </table>
  178. </div>
  179. <script>
  180. $(document).ready(function() {
  181. $('#table_generate_voucher').DataTable({
  182. });
  183. });
  184. </script>
  185. <?php
  186. }
  187.  
  188. function getVoucherUsed($data = array()) {
  189. $namavoucher = $data['namavoucher'];
  190. ?>
  191. <style>
  192. table td, table th{font-size:11px;}
  193. .nowrap {white-space:nowrap;}
  194. </style>
  195. <div class="table-responsive">
  196. <h3 style="color:#008899;">Voucher <span style="color:#ff7777"><?php echo $namavoucher; ?></span></h3>
  197. <table class="table table-hover table-striped table-condensed table-bordered" id="table_voucher_used" data-order='[[ 0, "asc" ]]'>
  198. <thead>
  199. <tr>
  200. <th class="text-nowrap" title="name">NAMA</th>
  201. <th class="text-nowrap" title="password">SANDI</th>
  202. <th class="text-nowrap" title="profile">PROFIL</th>
  203. <th class="text-nowrap" title="sisa" style="background:#ffcc99;">SISA</th>
  204. <th class="text-nowrap" title="limit-uptime">BATAS</th>
  205. <th class="text-nowrap" title="uptime">DIPAKAI</th>
  206. <th class="text-nowrap" title="bytes-in">UP (MB)</th>
  207. <th class="text-nowrap" title="bytes-out">DOWN (MB)</th>
  208. <th class="text-nowrap" title="comment">KOMENTAR</th>
  209. <th class="text-nowrap" title="sisa menit">SM</th>
  210. <th class="text-nowrap" title="nyawa"><center><span class="glyphicon glyphicon-time" aria-hidden="true"></span></center></th>
  211. <th class="text-nowrap" title="status">STATUS</th>
  212. </tr>
  213. </thead>
  214. <tbody>
  215. <?php
  216. date_default_timezone_set('Asia/Jakarta');
  217. $query = $this->mikrostator->baca("/ip/hotspot/user/print", array(
  218. "?comment" => $namavoucher,
  219. ));
  220. foreach ($query as $row):
  221. $uid = $row['.id'];
  222. $name = $row['name'];
  223. $password = $row['password'];
  224. $profile = $row['profile'];
  225. $limit_uptime = "";
  226. if (isset($row['limit-uptime'])) {
  227. $limit_uptime = $row['limit-uptime'];
  228. }
  229. $uptime = $row['uptime'];
  230. $bytes_in = $row['bytes-in'];
  231. $bytes_out = $row['bytes-out'];
  232. $comment = isset($row['comment'])?$row['comment']:'';
  233. $disabled = $row['disabled'];
  234. $sisa_time = $this->stator->time_elapsed_A($this->stator->get_menit($limit_uptime, 's') - $this->stator->get_menit($uptime, 's'));
  235. $status = 'hidup';
  236. $status_msg = '';
  237. $hidup_mati = 'hidup';
  238. if ($disabled == 'true') {
  239. $status = 'mati';
  240. $status_msg = "style='background-color:#ffaaaa;color:#aaa;' title='tidak aktif (mati)'";
  241. $hidup_mati = 'mati';
  242. }
  243. //.list hotspot user.end
  244. ?>
  245. <tr <?php echo $status_msg; ?>>
  246. <td class="text-nowrap"><?php echo $name; ?></td>
  247. <td class="text-nowrap" title="<?php echo $password; ?>">***</td>
  248. <td class="text-nowrap"><?php echo $profile; ?></td>
  249. <td class="text-nowrap" style="background:#ffdfbf;" title="<?php echo "PC:Rp." . floor(($this->stator->get_menit($sisa_time, 's') / 3600) * 2500) . "|" . "HP:Rp." . floor(($this->stator->get_menit($sisa_time, 's') / 3600) * 2000); ?>"><?php echo $sisa_time; ?></td>
  250. <td class="text-nowrap"><?php echo $limit_uptime; ?></td>
  251. <td class="text-nowrap"><?php echo $uptime; ?></td>
  252. <td class="text-nowrap" title="<?php echo $bytes_in; ?>"><?php echo number_format($bytes_in / 1024 / 1024, 2); ?></td>
  253. <td class="text-nowrap" title="<?php echo $bytes_out; ?>"><?php echo number_format($bytes_out / 1024 / 1024, 2); ?></td>
  254. <td class="text-nowrap"><?php echo $comment; ?></td>
  255. <td class="text-nowrap"><?php echo $this->stator->get_menit($sisa_time, 'm'); ?></td>
  256. <td class="text-nowrap"><?php echo $this->stator->get_menit($sisa_time, 's'); ?></td>
  257. <td class="text-nowrap" title="<?php echo $status; ?>"><?php echo $hidup_mati; ?></td>
  258. </tr>
  259. <?php
  260. endforeach;
  261. ?>
  262. </tbody>
  263. </table>
  264. </div>
  265. <script>
  266. $(document).ready(function() {
  267. $('#table_voucher_used').DataTable({
  268. });
  269. });
  270. </script>
  271. <?php
  272. }
  273.  
  274. function getVoucherName() {
  275. $this->db->select('voucher_name');
  276. $this->db->from('wk_voucher');
  277. $this->db->distinct();
  278. $query = $this->db->get();
  279. return $query->result();
  280. }
  281.  
  282. function getVoucherByName($nama) {
  283. $this->db->select('voucher_name');
  284. $this->db->from('wk_voucher');
  285. $this->db->where('voucher_name', $nama);
  286. return $this->db->count_all_results();
  287. }
  288.  
  289. function prosesHapusVoucherList($data = array()) {
  290.  
  291. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { //.cek paka proxy atau tidak?
  292. $iptujuan = $_SERVER['HTTP_X_FORWARDED_FOR']; //pakai proxy
  293. } else {
  294. $iptujuan = $_SERVER['REMOTE_ADDR']; //tanpa proxy
  295. }
  296.  
  297. $namavoucher = $data['namavoucher'];
  298.  
  299. $this->db->select('*');
  300. $this->db->from('wk_voucher');
  301. $this->db->where('voucher_name', $namavoucher);
  302. $query = $this->db->get();
  303. foreach ($query->result() as $row) {
  304. $nama = $row->voucher_username;
  305. $ARRAY = $this->mikrostator->delHotspotUserByName($nama);
  306. /*
  307. return count($ARRAY);
  308. if (count($ARRAY) == 0) { //.0 berarti tidak ada pesan tambahan/sukses
  309. $msg = "dihapus";
  310. //.update to db.begin
  311. $datax = array(
  312. 'voucher_status' => $msg,
  313. );
  314. $this->db->where('voucher_username', $user);
  315. $this->db->update('wk_voucher', $data);
  316. //.update to db.end
  317. } else {
  318. $msg = "gagal dihapus";
  319. //.update to db.begin
  320. $datax = array(
  321. 'voucher_status' => $msg,
  322. );
  323. $this->db->where('voucher_username', $user);
  324. $this->db->update('wk_voucher', $data);
  325. //.update to db.end
  326. }
  327. *
  328. */
  329. $this->db->where('voucher_username', $row->voucher_username);
  330. $this->db->delete('wk_voucher');
  331. }
  332.  
  333. if ($this->getVoucherByName($nama) == 0) {
  334. $msg = "VOUCHER $nama BERHASIL DIHAPUS via $iptujuan";
  335. $this->log->writeLog($msg);
  336. return $msg;
  337. } else {
  338. $msg = "GAGAL MENGHAPUS VOUCHER $nama, SILAHKAN COBA LAGI!. msg: " . $this->db->_error_message();
  339. $this->log->writeLog($msg);
  340. return $msg;
  341. }
  342. }
  343.  
  344. function prosesCetakVoucherList($data = array()) {
  345. $namavoucher = $data['namavoucher'];
  346. ?>
  347. <style>
  348. table td, table th{font-size:11px;}
  349. .nowrap {white-space:nowrap;}
  350. </style>
  351. <div class="table-responsive">
  352. <h3 style="color:#008899;">Voucher <span style="color:#ff7777"><?php echo $namavoucher; ?></span></h3>
  353. <?php
  354. date_default_timezone_set('Asia/Jakarta');
  355. $this->db->select('*');
  356. $this->db->from('wk_voucher');
  357. $this->db->where('voucher_name', $namavoucher);
  358. $query = $this->db->get();
  359. $n = 0;
  360. foreach ($query->result() as $row) {
  361. $n++;
  362. $res1 = $row->voucher_username;
  363. $res2 = $row->voucher_password;
  364. $userprofile = $row->voucher_user_profile;
  365. $limituptime = $row->voucher_limit_uptime;
  366. ?>
  367.  
  368. <table style="display: inline-block; border: 1px solid #ccc; font-family: arial; font-size: 12px; margin: 1px;">
  369. <tr style="border-bottom:1px solid #ccc;background:#ddd;">
  370. <th style="text-align: center" colspan="2"><span style="padding:10px;font-size:15px;">*MUARA CYBER*</span></th>
  371. </tr>
  372. <tr>
  373. <td><span style="padding:5px;">USERNAME</span></td><td><span style="padding:5px;"><b><?php echo $res1; ?></b></span></td>
  374. </tr>
  375. <tr>
  376. <td><span style="padding:5px;">PASSWORD</span></td><td><span style="padding:5px;"><b><?php echo $res2; ?></b></span></td>
  377. </tr>
  378. <tr style="border-bottom:1px solid #ccc;">
  379. <td style="text-align: center" colspan="2"><span style="padding:50px;">Voucher : <?php echo $namavoucher; ?></span></td>
  380. </tr>
  381. </table>
  382. <?php
  383. }
  384. ?>
  385. <?php
  386. }
  387.  
  388. function prosesCetakVoucherList2($namavoucher) {
  389. $namavoucher = rawurldecode($namavoucher);
  390. ?>
  391. <script>
  392. window.onload = function() {
  393. window.print();
  394. }
  395. </script>
  396. <style>
  397. table td, table th{font-size:11px;}
  398. .nowrap {white-space:nowrap;}
  399. </style>
  400. <div class="table-responsive">
  401. <?php
  402. date_default_timezone_set('Asia/Jakarta');
  403. $this->db->select('*');
  404. $this->db->from('wk_voucher');
  405. $this->db->where('voucher_name', $namavoucher);
  406. $this->db->where('voucher_status', 'sukses');
  407. $query = $this->db->get();
  408. $n = 0;
  409. foreach ($query->result() as $row) {
  410. $n++;
  411. $res1 = $row->voucher_username;
  412. $res2 = $row->voucher_password;
  413. $userprofile = $row->voucher_user_profile;
  414. $limituptime = $row->voucher_limit_uptime;
  415. $victim = array("w", "d", "h", "m", "s");
  416. $replacement1 = array("*w*", "*d*", "*h*", "*m*", "*s*");
  417. $replacement2 = array("minggu ", "hari ", "jam ", "menit ", "detik ");
  418. $limituptime = str_replace($victim, $replacement1, $limituptime);
  419. $limituptime = str_replace($replacement1, $replacement2, $limituptime);
  420. ?>
  421. <table style="display: inline-block; border: 1px solid #2B78C5; font-family: arial; font-size: 12px; margin: 2px;">
  422. <tr style="border-bottom:1px solid #2B78C5;background:#2B78C5;">
  423. <th style="text-align: center" colspan="2"><span style="padding:25px;font-size:15px;">&#9734;&#9734;&#9734; MUARA CYBER &#9734;&#9734;&#9734;</span></th>
  424. </tr>
  425. <tr>
  426. <td style="width: 50%; text-align: center;"><span style="padding:25px;font-style: italic;text-decoration: underline;">UserName</span></td><td style="width: 50%; text-align: center;"><span style="padding:25px;font-style: italic;text-decoration: underline;">PassWord</span></td>
  427. </tr>
  428. <tr>
  429. <td style="width: 50%; text-align: center;"><span style="padding:25px;font-weight: bold;font-size:17px;"><?php echo $res1; ?></span></td><td style="width: 50%; text-align: center;"><span style="padding:25px;font-weight: bold;font-size:17px;"><?php echo $res2; ?></span></td>
  430. </tr>
  431. <tr>
  432. <td style="text-align: center" colspan="2"><span style="padding:25px;font-style: italic;text-decoration: underline;">Limit Waktu</span></td>
  433. </tr>
  434. <tr>
  435. <td style="text-align: center" colspan="2"><span style="padding:25px;"><b><?php echo $limituptime; ?></b></span></td>
  436. </tr>
  437. <tr style="border-bottom:1px solid #ccc;background:#eee;">
  438. <td style="text-align: center" colspan="2"><span style="color:#008899;">Voucher <span style="color:#ff7777"><?php echo $namavoucher; ?></span></span></td>
  439. </tr>
  440. </table>
  441. <?php
  442. }
  443. ?>
  444. <?php
  445. }
  446.  
  447. //***MODEL VOUCHER.end
  448. }
  449.  
  450. /* End of file voucher_model.php */
  451. /* Location: ./application/models/voucher_model.php */
Add Comment
Please, Sign In to add comment