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

/admin/modules/master_file/coll_type.php

https://github.com/awriel/s3st15_matoa
PHP | 237 lines | 155 code | 20 blank | 62 comment | 32 complexity | 7f613ccace9e2b2540a7ce449a77e764 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. /* Collection Type 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_DIR.'ip_based_access.inc.php';
  29. do_checkIP('smc');
  30. do_checkIP('smc-masterfile');
  31. // start the session
  32. require SENAYAN_BASE_DIR.'admin/default/session.inc.php';
  33. require SENAYAN_BASE_DIR.'admin/default/session_check.inc.php';
  34. require SIMBIO_BASE_DIR.'simbio_GUI/table/simbio_table.inc.php';
  35. require SIMBIO_BASE_DIR.'simbio_GUI/form_maker/simbio_form_table_AJAX.inc.php';
  36. require SIMBIO_BASE_DIR.'simbio_GUI/paging/simbio_paging.inc.php';
  37. require SIMBIO_BASE_DIR.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
  38. require SIMBIO_BASE_DIR.'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 view this section').'</div>');
  44. }
  45. /* RECORD OPERATION */
  46. if (isset($_POST['saveData'])) {
  47. $collTypeName = trim(strip_tags($_POST['collTypeName']));
  48. // check form validity
  49. if (empty($collTypeName)) {
  50. utility::jsAlert(__('Collection type name can\'t be empty'));
  51. exit();
  52. } else {
  53. $data['coll_type_name'] = $dbs->escape_string($collTypeName);
  54. $data['input_date'] = date('Y-m-d');
  55. $data['last_update'] = date('Y-m-d');
  56. // create sql op object
  57. $sql_op = new simbio_dbop($dbs);
  58. if (isset($_POST['updateRecordID'])) {
  59. /* UPDATE RECORD MODE */
  60. // remove input date
  61. unset($data['input_date']);
  62. // filter update record ID
  63. $updateRecordID = (integer)$_POST['updateRecordID'];
  64. // update the data
  65. $update = $sql_op->update('mst_coll_type', $data, 'coll_type_id='.$updateRecordID);
  66. if ($update) {
  67. utility::jsAlert(__('Colllection Type Data Successfully Updated'));
  68. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(parent.jQuery.ajaxHistory[0].url);</script>';
  69. } else { utility::jsAlert(__('Colllection Type Data FAILED to Updated. Please Contact System Administrator')."\nDEBUG : ".$sql_op->error); }
  70. exit();
  71. } else {
  72. /* INSERT RECORD MODE */
  73. // insert the data
  74. $insert = $sql_op->insert('mst_coll_type', $data);
  75. if ($insert) {
  76. utility::jsAlert(__('New Colllection Type Data Successfully Saved'));
  77. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'\');</script>';
  78. } else { utility::jsAlert(__('Author Data FAILED to Save. Please Contact System Administrator')."\nDEBUG : ".$sql_op->error); }
  79. exit();
  80. }
  81. }
  82. exit();
  83. } else if (isset($_POST['itemID']) AND !empty($_POST['itemID']) AND isset($_POST['itemAction'])) {
  84. if (!($can_read AND $can_write)) {
  85. die();
  86. }
  87. /* DATA DELETION PROCESS */
  88. $sql_op = new simbio_dbop($dbs);
  89. $failed_array = array();
  90. $error_num = 0;
  91. if (!is_array($_POST['itemID'])) {
  92. // make an array
  93. $_POST['itemID'] = array((integer)$_POST['itemID']);
  94. }
  95. // loop array
  96. foreach ($_POST['itemID'] as $itemID) {
  97. $itemID = (integer)$itemID;
  98. // check if this item data still have an item
  99. $item_q = $dbs->query('SELECT ct.coll_type_name, COUNT(item_id) FROM item AS i
  100. LEFT JOIN mst_coll_type AS ct ON i.coll_type_id=ct.coll_type_id
  101. WHERE i.coll_type_id='.$itemID.' GROUP BY i.coll_type_id');
  102. $item_d = $item_q->fetch_row();
  103. if ($item_d[1] < 1) {
  104. if (!$sql_op->delete('mst_coll_type', "coll_type_id=$itemID")) {
  105. $error_num++;
  106. }
  107. } else {
  108. $msg = str_replace('{item_name}', $item_d[0], __('Location ({item_name}) still used by {number_items} item(s)')); //mfc
  109. $msg = str_replace('{number_items}', $item_d[1], $msg);
  110. $still_have_item[] = $msg;
  111. $error_num++;
  112. }
  113. }
  114. if ($still_have_item) {
  115. $undeleted_coll_types = '';
  116. foreach ($still_have_item as $coll_type) {
  117. $undeleted_coll_types .= $coll_type."\n";
  118. }
  119. utility::jsAlert(__('Below data can not be deleted:').$undeleted_coll_types);
  120. exit();
  121. }
  122. // error alerting
  123. if ($error_num == 0) {
  124. utility::jsAlert(__('All Data Successfully Deleted'));
  125. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  126. } else {
  127. utility::jsAlert(__('Some or All Data NOT deleted successfully!\nPlease contact system administrator'));
  128. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  129. }
  130. exit();
  131. }
  132. /* RECORD OPERATION END */
  133. /* search form */
  134. ?>
  135. <fieldset class="menuBox">
  136. <div class="menuBoxInner masterFileIcon">
  137. <?php echo strtoupper(__('Collection Type')); ?> - <a href="<?php echo MODULES_WEB_ROOT_DIR; ?>master_file/coll_type.php?action=detail" class="headerText2"><?php echo __('Add New Collection Type'); ?></a>
  138. &nbsp; <a href="<?php echo MODULES_WEB_ROOT_DIR; ?>master_file/coll_type.php" class="headerText2"><?php echo __('Collection Type List'); ?></a>
  139. <hr />
  140. <form name="search" action="<?php echo MODULES_WEB_ROOT_DIR; ?>master_file/coll_type.php" id="search" method="get" style="display: inline;"><?php echo __('Search'); ?> :
  141. <input type="text" name="keywords" size="30" />
  142. <input type="submit" id="doSearch" value="<?php echo __('Search'); ?>" class="button" />
  143. </form>
  144. </div>
  145. </fieldset>
  146. <?php
  147. /* search form end */
  148. /* main content */
  149. if (isset($_POST['detail']) OR (isset($_GET['action']) AND $_GET['action'] == 'detail')) {
  150. if (!($can_read AND $can_write)) {
  151. die('<div class="errorBox">'.__('You don\'t have enough privileges to view this section').'</div>');
  152. }
  153. $itemID = (integer)isset($_POST['itemID'])?$_POST['itemID']:0;
  154. $rec_q = $dbs->query("SELECT * FROM mst_coll_type WHERE coll_type_id=$itemID");
  155. $rec_d = $rec_q->fetch_assoc();
  156. // create new instance
  157. $form = new simbio_form_table_AJAX('mainForm', $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], 'post');
  158. $form->submit_button_attr = 'name="saveData" value="'.__('Save').'" class="button"';
  159. // form table attributes
  160. $form->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  161. $form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
  162. $form->table_content_attr = 'class="alterCell2"';
  163. // edit mode flag set
  164. if ($rec_q->num_rows > 0) {
  165. $form->edit_mode = true;
  166. // record ID for delete process
  167. $form->record_id = $itemID;
  168. // form record title
  169. $form->record_title = $rec_d['coll_type_name'];
  170. // submit button attribute
  171. $form->submit_button_attr = 'name="saveData" value="'.__('Update').'" class="button"';
  172. }
  173. /* Form Element(s) */
  174. // coll_type_name
  175. $form->addTextField('text', 'collTypeName', __('Collection Type').'*', $rec_d['coll_type_name'], 'style="width: 60%;"');
  176. // edit mode messagge
  177. if ($form->edit_mode) {
  178. echo '<div class="infoBox">'.__('You are going to edit collection type data').' : <b>'.$rec_d['coll_type_name'].'</b> <br />'.__('Last Update').$rec_d['last_update'].'</div>'; //mfc
  179. }
  180. // print out the form object
  181. echo $form->printOut();
  182. } else {
  183. /* COLLECTION TYPE LIST */
  184. // table spec
  185. $table_spec = 'mst_coll_type AS ct';
  186. // create datagrid
  187. $datagrid = new simbio_datagrid();
  188. if ($can_read AND $can_write) {
  189. $datagrid->setSQLColumn('ct.coll_type_id', 'ct.coll_type_name AS \''.__('Collection Type').'\'', 'ct.last_update AS \''.__('Last Update').'\'');
  190. } else {
  191. $datagrid->setSQLColumn('ct.coll_type_name AS \''.__('Collection Type').'\'', 'ct.last_update AS \''.__('Last Update').'\'');
  192. }
  193. $datagrid->setSQLorder('coll_type_name ASC');
  194. // change the record order
  195. if (isset($_GET['fld']) AND isset($_GET['dir'])) {
  196. $datagrid->setSQLorder("'".urldecode($_GET['fld'])."' ".$dbs->escape_string($_GET['dir']));
  197. }
  198. // is there any search
  199. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  200. $keywords = $dbs->escape_string($_GET['keywords']);
  201. $datagrid->setSQLCriteria("ct.coll_type_name LIKE '%$keywords%'");
  202. }
  203. // set table and table header attributes
  204. $datagrid->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  205. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  206. // set delete proccess URL
  207. $datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
  208. // put the result into variables
  209. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, ($can_read AND $can_write));
  210. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  211. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords')); //mfc
  212. echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"</div>';
  213. }
  214. echo $datagrid_result;
  215. }
  216. /* main content end */
  217. ?>