PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/modules/serial_control/subscription.php

https://gitlab.com/mucill/majalengka
PHP | 269 lines | 169 code | 24 blank | 76 comment | 32 complexity | e691c756148e642699f676e9f9e15904 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. /* serial 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-serialcontrol');
  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/form_maker/simbio_form_table.inc.php';
  35. require SIMBIO.'simbio_GUI/table/simbio_table.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. require MDLBS.'serial_control/serial_base_lib.inc.php';
  40. // privileges checking
  41. $can_read = utility::havePrivilege('serial_control', 'r');
  42. $can_write = utility::havePrivilege('serial_control', 'w');
  43. if (!$can_read) {
  44. die('<div class="errorBox">'.__('You are not authorized to view this section').'</div>');
  45. }
  46. // page title
  47. $page_title = 'Subscription List';
  48. $biblioID = 0;
  49. if (isset($_GET['biblioID'])) {
  50. $biblioID = (integer)$_GET['biblioID'];
  51. }
  52. if (isset($_POST['biblioID'])) {
  53. $biblioID = (integer)$_POST['biblioID'];
  54. }
  55. /* RECORD OPERATION */
  56. if (isset($_POST['saveData'])) {
  57. $dateStart = trim($dbs->escape_string(strip_tags($_POST['dateStart'])));
  58. // $dateEnd = trim($dbs->escape_string(strip_tags($_POST['dateEnd'])));
  59. $period = trim($dbs->escape_string(strip_tags($_POST['period'])));
  60. // check form validity
  61. if (!$period OR !$dateStart) {
  62. utility::jsAlert(__('Error inserting subscription data, Subscription Date must be filled!'));
  63. } else {
  64. $data['biblio_id'] = $biblioID;
  65. $data['date_start'] = $dateStart;
  66. // $data['date_end'] = $dateEnd;
  67. $data['period'] = $period;
  68. $data['notes'] = trim($_POST['notes'])==''?'literal{NULL}':trim($dbs->escape_string(strip_tags($_POST['notes'])));
  69. $data['input_date'] = date('Y-m-d');
  70. $data['last_update'] = date('Y-m-d');
  71. $sql_op = new simbio_dbop($dbs);
  72. if (isset($_POST['updateRecordID'])) {
  73. /* UPDATE RECORD MODE */
  74. // remove input date
  75. unset($data['input_date']);
  76. // filter update record ID
  77. $updateRecordID = (integer)$_POST['updateRecordID'];
  78. // update the data
  79. $update = $sql_op->update('serial', $data, 'serial_id='.$updateRecordID);
  80. if ($update) {
  81. utility::jsAlert(__('Subscription Data Successfully Updated'));
  82. utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'serial_control', $_SESSION['realname'].' update subcription('.$updateRecordID.') '.$period);
  83. } else { utility::jsAlert(__('Subscription Data FAILED to Updated. Please Contact System Administrator')."\nDEBUG : ".$sql_op->error); }
  84. echo '<script type="text/javascript">self.location.href = \''.MWB.'serial_control/subscription.php?biblioID='.$biblioID.'\';</script>';
  85. exit();
  86. } else {
  87. /* INSERT RECORD MODE */
  88. // insert the data
  89. $insert = $sql_op->insert('serial', $data);
  90. $serial_id = $sql_op->insert_id;
  91. if ($insert) {
  92. $exemplar = (integer)$_POST['exemplar'];
  93. // generate kardex entry
  94. $serial = new serial($dbs, $serial_id);
  95. $serial->generateKardexes($exemplar, true);
  96. // alert
  97. utility::jsAlert(__('New Subscription Data Successfully Saved'));
  98. utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'serial_control', $_SESSION['realname'].' add new subcription('.$sql_op->insert_id.') '.$period);
  99. } else { utility::jsAlert(__('Subscription Data FAILED to Save. Please Contact System Administrator')."\n".$sql_op->error); }
  100. echo '<script type="text/javascript">self.location.href = \''.MWB.'serial_control/subscription.php?biblioID='.$biblioID.'\';</script>';
  101. exit();
  102. }
  103. }
  104. exit();
  105. } else if (isset($_POST['itemID']) AND !empty($_POST['itemID']) AND isset($_POST['itemAction'])) {
  106. if (!($can_read AND $can_write)) {
  107. die();
  108. }
  109. /* DATA DELETION PROCESS */
  110. $sql_op = new simbio_dbop($dbs);
  111. $failed_array = array();
  112. $error_num = 0;
  113. if (!is_array($_POST['itemID'])) {
  114. // make an array
  115. $_POST['itemID'] = array((integer)$_POST['itemID']);
  116. }
  117. // get biblio ID for this subcription
  118. $biblio_q = $dbs->query('SELECT biblio_id FROM serial WHERE serial_id='.( isset($_POST['itemID'][0])?$_POST['itemID'][0]:'0' ).' LIMIT 1');
  119. $biblio_d = $biblio_q->fetch_row();
  120. $biblioID = $biblio_d[0];
  121. // loop array
  122. foreach ($_POST['itemID'] as $itemID) {
  123. $itemID = (integer)$itemID;
  124. if (!$sql_op->delete('serial', 'serial_id='.$itemID)) {
  125. $error_num++;
  126. } else {
  127. // also delete kardex data
  128. $sql_op->delete('kardex', 'serial_id='.$itemID);
  129. }
  130. }
  131. // error alerting
  132. if ($error_num == 0) {
  133. utility::jsAlert(__('Subscription data successfully deleted'));
  134. } else {
  135. utility::jsAlert(__('Subscription data FAILED to deleted!'));
  136. }
  137. }
  138. /* RECORD OPERATION END */
  139. // start the output buffering
  140. ob_start();
  141. /* main content */
  142. if ($can_write AND ( isset($_POST['detail']) OR (isset($_GET['detail']) AND $_GET['detail'] == 'true') )) {
  143. /* RECORD FORM */
  144. $biblioID = (integer)isset($_GET['biblioID'])?$_GET['biblioID']:0;
  145. $itemID = (integer)isset($_GET['itemID'])?$_GET['itemID']:0;
  146. $rec_q = $dbs->query('SELECT * FROM serial WHERE biblio_id='.$biblioID.' AND serial_id='.$itemID);
  147. $rec_d = $rec_q->fetch_assoc();
  148. // create new instance
  149. $form = new simbio_form_table('mainForm', $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], 'post');
  150. $form->submit_button_attr = 'name="saveData" value="'.__('Save').'" class="button"';
  151. // form table attributes
  152. $form->table_attr = 'align="center" id="dataList" style="width: 100%;" cellpadding="5" cellspacing="0"';
  153. $form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
  154. $form->table_content_attr = 'class="alterCell2"';
  155. // edit mode flag set
  156. if ($rec_q->num_rows > 0) {
  157. $form->edit_mode = true;
  158. // record ID for delete process
  159. $form->record_id = $itemID;
  160. // form record title
  161. $form->record_title = $rec_d['period'];
  162. // submit button attribute
  163. $form->submit_button_attr = 'name="saveData" value="'.__('Update').'" class="button"';
  164. }
  165. /* Form Element(s) */
  166. // serial date start
  167. $form->addDateField('dateStart', __('Subscription Start').'*', $rec_d['date_start']);
  168. if (!$form->edit_mode) {
  169. // serial exemplar
  170. $form->addTextField('text', 'exemplar', __('Total Exemplar Expected').'*', '1');
  171. }
  172. // serial periode name
  173. $form->addTextField('text', 'period', __('Period Name').'*', $rec_d['period'], 'style="width: 100%;"');
  174. // serial notes
  175. $form->addTextField('textarea', 'notes', __('Subscription Notes'), $rec_d['notes'], 'style="width: 100%;" rows="3"');
  176. // serial gmd
  177. // get gmd data related to this record from database
  178. $gmd_q = $dbs->query('SELECT gmd_id, gmd_name FROM mst_gmd');
  179. $gmd_options = array();
  180. while ($gmd_d = $gmd_q->fetch_row()) {
  181. $gmd_options[] = array($gmd_d[0], $gmd_d[1]);
  182. }
  183. $form->addSelectList('gmdID', __('GMD'), $gmd_options, $rec_d['gmd_id']);
  184. // serial biblio ID
  185. $form->addHidden('biblioID', $biblioID);
  186. // edit mode messagge
  187. if ($form->edit_mode) {
  188. echo '<div class="infoBox">'.__('You are going to edit Subscription data').' : <b>'.$rec_d['period'].'</b><div><i>'.$rec_d['notes'].'</i></div></div>'; //mfc
  189. }
  190. // print out the form object
  191. echo $form->printOut();
  192. } else {
  193. /* SUBSCRIPTION LIST */
  194. function serialTitle($obj_db, $array_data)
  195. {
  196. $_output = '';
  197. $_output .= '<div style="font-weight: bold; font-size: 110%;">'.$array_data[1].'</div>';
  198. $_output .= '<div style="font-weight: bold; font-size: 90%;"><a href="'.MWB.'serial_control/kardex.php?serialID='.$array_data[0].'" title="'.__('View/Edit Kardex Detail').'">'.__('View/Edit Kardex Detail').'</a></div>';
  199. return $_output;
  200. }
  201. // table spec
  202. $table_spec = 'serial AS s';
  203. // create datagrid
  204. $datagrid = new simbio_datagrid();
  205. $datagrid->setSQLColumn('s.serial_id',
  206. 's.period AS \''.__('Period Name').'\'',
  207. 's.date_start AS \''.__('Subscription Start').'\'',
  208. 's.notes AS \''.__('Subscription Notes').'\'');
  209. if ($can_read AND $can_write) {
  210. $datagrid->modifyColumnContent(1, 'callback{serialTitle}');
  211. } else {
  212. $datagrid->invisible_fields = array(0);
  213. $datagrid->modifyColumnContent(1, 'callback{serialTitle}');
  214. }
  215. $datagrid->setSQLorder('s.date_start DESC');
  216. $criteria = 's.biblio_id='.$biblioID;
  217. // is there any search
  218. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  219. $keyword = $dbs->escape_string($_GET['keywords']);
  220. $criteria .= " AND (s.period LIKE '%$keyword%' OR s.notes LIKE '%$keyword%')";
  221. }
  222. $datagrid->setSQLCriteria($criteria);
  223. // set table and table header attributes
  224. $datagrid->table_attr = 'align="center" id="dataList" style="width: 100%;" cellpadding="5" cellspacing="0"';
  225. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  226. $datagrid->using_AJAX = false;
  227. // set delete proccess URL
  228. $datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
  229. // special properties
  230. $datagrid->column_width = array(0 => '45%');
  231. // put the result into variables
  232. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, ($can_read AND $can_write));
  233. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  234. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords')); //mfc
  235. echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"</div>';
  236. }
  237. echo $datagrid_result;
  238. }
  239. /* main content end */
  240. // get the buffered content
  241. $content = ob_get_clean();
  242. // js include
  243. $js = '<script type="text/javascript" src="'.JWB.'calendar.js"></script>';
  244. // include the page template
  245. require SB.'/admin/'.$sysconf['admin_template']['dir'].'/notemplate_page_tpl.php';