PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/modules/master_file/frequency.php

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