PageRenderTime 32ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/modules/stock_take/index.php

https://github.com/tonebix/s3st15_matoa
PHP | 153 lines | 105 code | 11 blank | 37 comment | 16 complexity | c15579e99faa1c57274049b5462a2a83 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (C) 2007,2008 Arie Nugraha (dicarve@yahoo.com)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. */
  20. /* Stock Take */
  21. // key to authenticate
  22. define('INDEX_AUTH', '1');
  23. if (!defined('SENAYAN_BASE_DIR')) {
  24. // main system configuration
  25. require '../../../sysconfig.inc.php';
  26. // start the session
  27. require SENAYAN_BASE_DIR.'admin/default/session.inc.php';
  28. }
  29. require SENAYAN_BASE_DIR.'admin/default/session_check.inc.php';
  30. require SIMBIO_BASE_DIR.'simbio_GUI/table/simbio_table.inc.php';
  31. require SIMBIO_BASE_DIR.'simbio_GUI/form_maker/simbio_form_table_AJAX.inc.php';
  32. require SIMBIO_BASE_DIR.'simbio_GUI/paging/simbio_paging.inc.php';
  33. require SIMBIO_BASE_DIR.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
  34. require SIMBIO_BASE_DIR.'simbio_DB/simbio_dbop.inc.php';
  35. // privileges checking
  36. $can_read = utility::havePrivilege('stock_take', 'r');
  37. $can_write = utility::havePrivilege('stock_take', 'w');
  38. if (!$can_read) {
  39. die('<div class="errorBox">'.__('You don\'t have enough privileges to access this area!').'</div>');
  40. }
  41. ?>
  42. <fieldset class="menuBox">
  43. <div class="menuBoxInner stockTakeIcon">
  44. <?php echo strtoupper(__('Stock Take')); ?>
  45. <hr />
  46. <form name="search" action="<?php echo MODULES_WEB_ROOT_DIR; ?>stock_take/index.php" id="search" method="get" style="display: inline;"><?php echo __('Search'); ?> :
  47. <input type="text" name="keywords" size="30" />
  48. <input type="submit" value="<?php echo __('Search'); ?>" class="button" />
  49. </form>
  50. </div>
  51. </fieldset>
  52. <?php
  53. if (isset($_POST['itemID']) AND !empty($_POST['itemID'])) {
  54. $itemID = (integer)$_POST['itemID'];
  55. $rec_q = $dbs->query("SELECT
  56. stock_take_name AS '".__('Stock Take Name')."',
  57. start_date AS '".__('Start Date')."',
  58. end_date AS '".__('End Date')."',
  59. init_user AS '".__('Initializer')."',
  60. total_item_stock_taked AS '".__('Total Item Stock Taked')."',
  61. total_item_lost AS '".__('Total Item Lost')."',
  62. total_item_exists AS '".__('Total Item Exists')."',
  63. total_item_loan AS '".__('Total Item On Loan')."',
  64. stock_take_users AS '".__('Stock Take Participants')."',
  65. is_active AS '".__('Status')."',
  66. report_file AS '".__('Report')."'
  67. FROM stock_take WHERE stock_take_id=".$itemID);
  68. $rec_d = $rec_q->fetch_assoc();
  69. // create table object
  70. $table = new simbio_table();
  71. $table->table_attr = 'align="center" class="border" cellpadding="5" cellspacing="0"';
  72. // table header
  73. $table->setHeader(array($rec_d[__('Stock Take Name')]));
  74. $table->table_header_attr = 'class="dataListHeader" colspan="3"';
  75. // initial row count
  76. $row = 1;
  77. foreach ($rec_d as $headings => $stk_data) {
  78. if ($headings == 'stock_take_id') {
  79. continue;
  80. } else if ($headings == __('Status')) {
  81. if ($stk_data == '1') {
  82. $stk_data = '<b style="color: #f00;">'.__('Currently Active').'</b>';
  83. } else {
  84. $stk_data = 'Finished';
  85. }
  86. }
  87. $table->appendTableRow(array($headings, ':', $stk_data));
  88. // set cell attribute
  89. $table->setCellAttr($row, 0, 'class="alterCell" valign="top" style="width: 170px;"');
  90. $table->setCellAttr($row, 1, 'class="alterCell" valign="top" style="width: 1%;"');
  91. $table->setCellAttr($row, 2, 'class="alterCell2" valign="top" style="width: auto;"');
  92. // add row count
  93. $row++;
  94. }
  95. // print out table
  96. echo $table->printTable();
  97. } else {
  98. /* STOCK TAKE HISTORY LIST */
  99. // table spec
  100. $table_spec = 'stock_take AS st';
  101. // create datagrid
  102. $datagrid = new simbio_datagrid();
  103. $datagrid->setSQLColumn('st.stock_take_id',
  104. 'st.stock_take_name AS \''.__('Stock Take Name').'\'',
  105. 'st.start_date AS \''.__('Start Date').'\'',
  106. 'st.end_date AS \''.__('End Date').'\'',
  107. 'CONCAT(\'<a class="notAJAX" href="'.SENAYAN_WEB_ROOT_DIR.FILES_DIR.'/'.REPORT_DIR.'/\', st.report_file, \'" target="_blank">\', st.report_file, \'</a>\') AS \''.__('Report').'\'');
  108. $datagrid->setSQLorder('st.start_date DESC');
  109. $datagrid->disableSort('Report');
  110. // is there any search
  111. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  112. $keyword = $dbs->escape_string(trim($_GET['keywords']));
  113. $words = explode(' ', $keyword);
  114. if (count($words) > 1) {
  115. $concat_sql = ' (';
  116. foreach ($words as $word) {
  117. $concat_sql .= " (stock_take_name LIKE '%$word%' OR init_user LIKE '%$word%') AND";
  118. }
  119. // remove the last AND
  120. $concat_sql = substr_replace($concat_sql, '', -3);
  121. $concat_sql .= ') ';
  122. $datagrid->setSQLCriteria($concat_sql);
  123. } else {
  124. $datagrid->setSQLCriteria("stock_take_name LIKE '%$keyword%' OR init_user LIKE '%$keyword%'");
  125. }
  126. }
  127. // set table and table header attributes
  128. $datagrid->icon_edit = $sysconf['admin_template']['dir'].'/'.$sysconf['admin_template']['theme'].'/edit.gif';
  129. $datagrid->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  130. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  131. $datagrid->chbox_property = false;
  132. // set delete proccess URL
  133. $datagrid->delete_URL = $_SERVER['PHP_SELF'];
  134. // put the result into variables
  135. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, true);
  136. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  137. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords')); //mfc
  138. echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"</div>';
  139. }
  140. echo $datagrid_result;
  141. }
  142. ?>