PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/modules/master_file/supplier.php

https://gitlab.com/mucill/majalengka
PHP | 247 lines | 161 code | 20 blank | 66 comment | 28 complexity | 7b56cd97fb3cf4108f7547bf83cfe3e0 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 3 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. /* Supplier Management section */
  21. // key to authenticate
  22. define('INDEX_AUTH', '1');
  23. // key to get full database access
  24. define('DB_ACCESS', 'fa');
  25. // main system configuration
  26. require '../../../sysconfig.inc.php';
  27. // IP based access limitation
  28. require LIB.'ip_based_access.inc.php';
  29. do_checkIP('smc');
  30. do_checkIP('smc-masterfile');
  31. // start the session
  32. require SB.'admin/default/session.inc.php';
  33. require SB.'admin/default/session_check.inc.php';
  34. require SIMBIO.'simbio_GUI/table/simbio_table.inc.php';
  35. require SIMBIO.'simbio_GUI/form_maker/simbio_form_table_AJAX.inc.php';
  36. require SIMBIO.'simbio_GUI/paging/simbio_paging.inc.php';
  37. require SIMBIO.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
  38. require SIMBIO.'simbio_DB/simbio_dbop.inc.php';
  39. // privileges checking
  40. $can_read = utility::havePrivilege('master_file', 'r');
  41. $can_write = utility::havePrivilege('master_file', 'w');
  42. if (!$can_read) {
  43. die('<div class="errorBox">'.__('You don\'t have enough privileges to access this area!').'</div>');
  44. }
  45. /* RECORD OPERATION */
  46. if (isset($_POST['saveData']) AND $can_read AND $can_write) {
  47. $supplierName = trim(strip_tags($_POST['supplierName']));
  48. // check form validity
  49. if (empty($supplierName)) {
  50. utility::jsAlert(__('Supplier Name can\'t be empty'));
  51. exit();
  52. } else {
  53. $data['supplier_name'] = $dbs->escape_string($supplierName);
  54. $data['address'] = trim($dbs->escape_string(strip_tags($_POST['supplierPlace'])));
  55. $data['contact'] = trim($dbs->escape_string(strip_tags($_POST['supplierContact'])));
  56. $data['phone'] = trim($dbs->escape_string(strip_tags($_POST['supplierPhone'])));
  57. $data['fax'] = trim($dbs->escape_string(strip_tags($_POST['supplierFax'])));
  58. $data['e_mail'] = trim($dbs->escape_string(strip_tags($_POST['supplierEmail'])));
  59. $data['account'] = trim($dbs->escape_string(strip_tags($_POST['supplierAccount'])));
  60. $data['input_date'] = date('Y-m-d');
  61. $data['last_update'] = date('Y-m-d');
  62. // create sql op object
  63. $sql_op = new simbio_dbop($dbs);
  64. if (isset($_POST['updateRecordID'])) {
  65. /* UPDATE RECORD MODE */
  66. // remove input date
  67. unset($data['input_date']);
  68. // filter update record ID
  69. $updateRecordID = (integer)$_POST['updateRecordID'];
  70. // update the data
  71. $update = $sql_op->update('mst_supplier', $data, 'supplier_id='.$updateRecordID);
  72. if ($update) {
  73. utility::jsAlert(__('Supplier Data Successfully Updated'));
  74. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(parent.jQuery.ajaxHistory[0].url);</script>';
  75. } else { utility::jsAlert(__('Supplier Data FAILED to Updated. Please Contact System Administrator')."\nDEBUG : ".$error); }
  76. exit();
  77. } else {
  78. /* INSERT RECORD MODE */
  79. // insert the data
  80. $insert = $sql_op->insert('mst_supplier', $data);
  81. if ($insert) {
  82. utility::jsAlert(__('New Supplier Data Successfully Saved'));
  83. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'\');</script>';
  84. } else {
  85. utility::jsAlert(__('Supplier Data FAILED to Save. Please Contact System Administrator')."\nDEBUG : ".$sql_op->error);
  86. }
  87. exit();
  88. }
  89. }
  90. exit();
  91. } else if (isset($_POST['itemID']) AND !empty($_POST['itemID']) AND isset($_POST['itemAction'])) {
  92. if (!($can_read AND $can_write)) {
  93. die();
  94. }
  95. /* DATA DELETION PROCESS */
  96. $sql_op = new simbio_dbop($dbs);
  97. $failed_array = array();
  98. $error_num = 0;
  99. if (!is_array($_POST['itemID'])) {
  100. // make an array
  101. $_POST['itemID'] = array((integer)$_POST['itemID']);
  102. }
  103. // loop array
  104. foreach ($_POST['itemID'] as $itemID) {
  105. $itemID = (integer)$itemID;
  106. if (!$sql_op->delete('mst_supplier', 'supplier_id='.$itemID)) {
  107. $error_num++;
  108. }
  109. }
  110. // error alerting
  111. if ($error_num == 0) {
  112. utility::jsAlert(__('All Data Successfully Deleted'));
  113. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  114. } else {
  115. utility::jsAlert(__('Some or All Data NOT deleted successfully!\nPlease contact system administrator'));
  116. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  117. }
  118. exit();
  119. }
  120. /* RECORD OPERATION END */
  121. /* search form */
  122. ?>
  123. <fieldset class="menuBox">
  124. <div class="menuBoxInner masterFileIcon">
  125. <div class="per_title">
  126. <h2><?php echo __('Supplier'); ?></h2>
  127. </div>
  128. <div class="sub_section">
  129. <div class="btn-group">
  130. <a href="<?php echo MWB; ?>master_file/supplier.php" class="btn btn-default"><i class="glyphicon glyphicon-list-alt"></i>&nbsp;<?php echo __('Supplier List'); ?></a>
  131. <a href="<?php echo MWB; ?>master_file/supplier.php?action=detail" class="btn btn-default"><i class="glyphicon glyphicon-plus"></i>&nbsp;<?php echo __('Add New Supplier'); ?></a>
  132. </div>
  133. <form name="search" action="<?php echo MWB; ?>master_file/supplier.php" id="search" method="get" style="display: inline;"><?php echo __('Search'); ?> :
  134. <input type="text" name="keywords" size="30" />
  135. <input type="submit" id="doSearch" value="<?php echo __('Search'); ?>" class="button" />
  136. </form>
  137. </div>
  138. </div>
  139. </fieldset>
  140. <?php
  141. /* search form end */
  142. /* main content */
  143. if (isset($_POST['detail']) OR (isset($_GET['action']) AND $_GET['action'] == 'detail')) {
  144. if (!($can_read AND $can_write)) {
  145. die('<div class="errorBox">'.__('You don\'t have enough privileges to access this area!').'</div>');
  146. }
  147. /* RECORD FORM */
  148. $itemID = (integer)isset($_POST['itemID'])?$_POST['itemID']:0;
  149. $rec_q = $dbs->query('SELECT * FROM mst_supplier WHERE supplier_id='.$itemID);
  150. $rec_d = $rec_q->fetch_assoc();
  151. // create new instance
  152. $form = new simbio_form_table_AJAX('mainForm', $_SERVER['PHP_SELF'].'?itemID='.$itemID, 'post');
  153. $form->submit_button_attr = 'name="saveData" value="'.__('Save').'" class="button"';
  154. // form table attributes
  155. $form->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  156. $form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
  157. $form->table_content_attr = 'class="alterCell2"';
  158. // edit mode flag set
  159. if ($rec_q->num_rows > 0) {
  160. $form->edit_mode = true;
  161. // record ID for delete process
  162. $form->record_id = $itemID;
  163. // form record title
  164. $form->record_title = $rec_d['supplier_name'];
  165. // submit button attribute
  166. $form->submit_button_attr = 'name="saveData" value="'.__('Update').'" class="button"';
  167. }
  168. /* Form Element(s) */
  169. // supplier name
  170. $form->addTextField('text', 'supplierName', __('Supplier Name').'*', $rec_d['supplier_name'], 'style="width: 60%;"');
  171. // supplier address
  172. $form->addTextField('textarea', 'supplierPlace', __('Address'), $rec_d['address'], 'style="width: 100%;" rows="2"');
  173. // supplier contact
  174. $form->addTextField('text', 'supplierContact', __('Contact'), $rec_d['contact'], 'style="width: 60%;"');
  175. // supplier phone
  176. $form->addTextField('text', 'supplierPhone', __('Phone Number'), $rec_d['phone'], 'style="width: 60%;"');
  177. // supplier fax
  178. $form->addTextField('text', 'supplierFax', __('Fax Number'), $rec_d['fax'], 'style="width: 60%;"');
  179. // supplier account number
  180. $form->addTextField('text', 'supplierAccount', __('Account Number'), $rec_d['account'], 'style="width: 60%;"');
  181. // edit mode messagge
  182. if ($form->edit_mode) {
  183. echo '<div class="infoBox">'.__('You are going to edit Supplier data').' : <b>'.$rec_d['supplier_name'].'</b> <br />'.__('Last Update').$rec_d['last_update'].'</div>'; //mfc
  184. }
  185. // print out the form object
  186. echo $form->printOut();
  187. } else {
  188. /* SUPPLIER LIST */
  189. // table spec
  190. $table_spec = 'mst_supplier AS sp';
  191. // create datagrid
  192. $datagrid = new simbio_datagrid();
  193. if ($can_read AND $can_write) {
  194. $datagrid->setSQLColumn('sp.supplier_id',
  195. 'sp.supplier_name AS \''.__('Supplier Name').'\'',
  196. 'sp.contact AS \''.__('Contact').'\'',
  197. 'sp.phone AS \''.__('Phone Number').'\'',
  198. 'sp.fax AS \''.__('Fax Number').'\'',
  199. 'sp.last_update AS \''.__('Last Update').'\'');
  200. } else {
  201. $datagrid->setSQLColumn('sp.supplier_name AS \''.__('Supplier Name').'\'',
  202. 'sp.contact AS \''.__('Contact').'\'',
  203. 'sp.phone AS \''.__('Phone Number').'\'',
  204. 'sp.fax AS \''.__('Fax Number').'\'',
  205. 'sp.last_update AS \''.__('Last Update').'\'');
  206. }
  207. $datagrid->setSQLorder('supplier_name ASC');
  208. // is there any search
  209. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  210. $keywords = $dbs->escape_string($_GET['keywords']);
  211. $datagrid->setSQLCriteria("sp.supplier_name LIKE '%$keywords%' OR sp.supplier_id LIKE '%$keywords%'
  212. OR sp.contact LIKE '%$keywords%' OR sp.address LIKE '%$keywords%'");
  213. }
  214. // set table and table header attributes
  215. $datagrid->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  216. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  217. // set delete proccess URL
  218. $datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
  219. // put the result into variables
  220. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, ($can_read AND $can_write));
  221. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  222. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords')); //mfc
  223. echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"</div>';
  224. }
  225. echo $datagrid_result;
  226. }
  227. /* main content end */