PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/modules/master_file/frequency.php

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