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

/admin/modules/master_file/author.php

https://gitlab.com/mucill/majalengka
PHP | 264 lines | 174 code | 22 blank | 68 comment | 34 complexity | c7b208f29591611e3a68fd9aa0f4551d 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. /* Author 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. $authorName = trim(strip_tags($_POST['authorName']));
  48. // check form validity
  49. if (empty($authorName)) {
  50. utility::jsAlert(__('Author name can\'t be empty'));
  51. exit();
  52. } else {
  53. $data['author_name'] = $dbs->escape_string($authorName);
  54. $author_year = $dbs->escape_string(trim($_POST['authorYear']));
  55. if ($author_year) { $data['author_year'] = $author_year; }
  56. $data['authority_type'] = trim($dbs->escape_string(strip_tags($_POST['authorityType'])));
  57. $data['auth_list'] = trim($dbs->escape_string(strip_tags($_POST['authList'])));
  58. $data['input_date'] = date('Y-m-d');
  59. $data['last_update'] = date('Y-m-d');
  60. // create sql op object
  61. $sql_op = new simbio_dbop($dbs);
  62. if (isset($_POST['updateRecordID'])) {
  63. /* UPDATE RECORD MODE */
  64. // remove input date
  65. unset($data['input_date']);
  66. // filter update record ID
  67. $updateRecordID = (integer)$_POST['updateRecordID'];
  68. // update the data
  69. $update = $sql_op->update('mst_author', $data, 'author_id='.$updateRecordID);
  70. if ($update) {
  71. utility::jsAlert(__('Author Data Successfully Updated'));
  72. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(parent.jQuery.ajaxHistory[0].url);</script>';
  73. } else { utility::jsAlert(__('Author Data FAILED to Updated. Please Contact System Administrator')."\nDEBUG : ".$sql_op->error); }
  74. exit();
  75. } else {
  76. /* INSERT RECORD MODE */
  77. // insert the data
  78. $insert = $sql_op->insert('mst_author', $data);
  79. if ($insert) {
  80. utility::jsAlert(__('New Author Data Successfully Saved'));
  81. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'\');</script>';
  82. } else { utility::jsAlert(__('Author Data FAILED to Save. Please Contact System Administrator')."\nDEBUG : ".$sql_op->error); }
  83. exit();
  84. }
  85. }
  86. exit();
  87. } else if (isset($_POST['itemID']) AND !empty($_POST['itemID']) AND isset($_POST['itemAction'])) {
  88. if (!($can_read AND $can_write)) {
  89. die();
  90. }
  91. /* DATA DELETION PROCESS */
  92. $sql_op = new simbio_dbop($dbs);
  93. $failed_array = array();
  94. $error_num = 0;
  95. if (!is_array($_POST['itemID'])) {
  96. // make an array
  97. $_POST['itemID'] = array((integer)$_POST['itemID']);
  98. }
  99. // loop array
  100. foreach ($_POST['itemID'] as $itemID) {
  101. $itemID = (integer)$itemID;
  102. if (!$sql_op->delete('mst_author', 'author_id='.$itemID)) {
  103. $error_num++;
  104. }
  105. }
  106. // error alerting
  107. if ($error_num == 0) {
  108. utility::jsAlert(__('All Data Successfully Deleted'));
  109. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  110. } else {
  111. utility::jsAlert(__('Some or All Data NOT deleted successfully!\nPlease contact system administrator'));
  112. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  113. }
  114. exit();
  115. }
  116. /* RECORD OPERATION END */
  117. /* search form */
  118. ?>
  119. <fieldset class="menuBox">
  120. <div class="menuBoxInner masterFileIcon">
  121. <div class="per_title">
  122. <h2><?php echo __('Author'); ?></h2>
  123. </div>
  124. <div class="sub_section">
  125. <div class="btn-group">
  126. <a href="<?php echo MWB; ?>master_file/author.php" class="btn btn-default"><i class="glyphicon glyphicon-list-alt"></i>&nbsp;<?php echo __('Author List'); ?></a>
  127. <a href="<?php echo MWB; ?>master_file/author.php?action=detail" class="btn btn-default"><i class="glyphicon glyphicon-plus"></i>&nbsp;<?php echo __('Add New Author'); ?></a>
  128. </div>
  129. <form name="search" action="<?php echo MWB; ?>master_file/author.php" id="search" method="get" style="display: inline;"><?php echo __('Search'); ?> :
  130. <input type="text" name="keywords" size="30" />
  131. <input type="submit" id="doSearch" value="<?php echo __('Search'); ?>" class="button" />
  132. </form>
  133. </div>
  134. </div>
  135. </fieldset>
  136. <?php
  137. /* search form end */
  138. /* main content */
  139. if (isset($_POST['detail']) OR (isset($_GET['action']) AND $_GET['action'] == 'detail')) {
  140. if (!($can_read AND $can_write)) {
  141. die('<div class="errorBox">'.__('You don\'t have enough privileges to access this area!').'</div>');
  142. }
  143. /* RECORD FORM */
  144. $itemID = (integer)isset($_POST['itemID'])?$_POST['itemID']:0;
  145. $rec_q = $dbs->query('SELECT * FROM mst_author WHERE author_id='.$itemID);
  146. $rec_d = $rec_q->fetch_assoc();
  147. // create new instance
  148. $form = new simbio_form_table_AJAX('mainForm', $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], 'post');
  149. $form->submit_button_attr = 'name="saveData" value="'.__('Save').'" class="button"';
  150. // form table attributes
  151. $form->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  152. $form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
  153. $form->table_content_attr = 'class="alterCell2"';
  154. // edit mode flag set
  155. if ($rec_q->num_rows > 0) {
  156. $form->edit_mode = true;
  157. // record ID for delete process
  158. $form->record_id = $itemID;
  159. // form record title
  160. $form->record_title = $rec_d['author_name'];
  161. // submit button attribute
  162. $form->submit_button_attr = 'name="saveData" value="'.__('Update').'" class="button"';
  163. }
  164. /* Form Element(s) */
  165. // author name
  166. $form->addTextField('text', 'authorName', __('Author Name').'*', $rec_d['author_name'], 'style="width: 60%;"');
  167. // author year
  168. $form->addTextField('text', 'authorYear', __('Author Birth Year'), $rec_d['author_year'], 'style="width: 60%;"');
  169. // authority type
  170. foreach ($sysconf['authority_type'] as $auth_type_id => $auth_type) {
  171. $auth_type_options[] = array($auth_type_id, $auth_type);
  172. }
  173. $form->addSelectList('authorityType', __('Authority Type'), $auth_type_options, $rec_d['authority_type']);
  174. // authority list
  175. $form->addTextField('text', 'authList', __('Authority Files'), $rec_d['auth_list'], 'style="width: 30%;"');
  176. // edit mode messagge
  177. if ($form->edit_mode) {
  178. echo '<div class="infoBox">'.__('You are going to edit author data').' : <b>'.$rec_d['author_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. /* AUTHOR LIST */
  184. // table spec
  185. $sql_criteria = 'a.author_id > 1';
  186. if (isset($_GET['type']) && $_GET['type'] == 'orphaned') {
  187. $table_spec = 'mst_author AS a LEFT JOIN biblio_author AS ba ON a.author_id=ba.author_id';
  188. $sql_criteria = 'ba.biblio_id IS NULL OR ba.author_id IS NULL';
  189. } else {
  190. $table_spec = 'mst_author AS a';
  191. }
  192. // authority field num
  193. $auth_type_fld = 2;
  194. // create datagrid
  195. $datagrid = new simbio_datagrid();
  196. if ($can_read AND $can_write) {
  197. $auth_type_fld = 3;
  198. $datagrid->setSQLColumn('a.author_id', 'a.author_name AS \''.__('Author Name').'\'',
  199. 'a.author_year AS \''.__('Author Year').'\'',
  200. 'a.authority_type AS \''.__('Authority Type').'\'',
  201. 'a.auth_list AS \''.__('Authority Files').'\'',
  202. 'a.last_update AS \''.__('Last Update').'\'');
  203. } else {
  204. $datagrid->setSQLColumn('a.author_name AS \''.__('Author Name').'\'',
  205. 'a.author_year AS \''.__('Author Year').'\'',
  206. 'a.authority_type AS \''.__('Authority Type').'\'',
  207. 'a.auth_list AS \''.__('Authority Files').'\'',
  208. 'a.last_update AS \''.__('Last Update').'\'');
  209. }
  210. $datagrid->setSQLorder('author_name ASC');
  211. // change the record order
  212. if (isset($_GET['fld']) AND isset($_GET['dir'])) {
  213. $datagrid->setSQLorder("'".urldecode($_GET['fld'])."' ".$dbs->escape_string($_GET['dir']));
  214. }
  215. // is there any search
  216. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  217. $keywords = $dbs->escape_string($_GET['keywords']);
  218. $sql_criteria .= " AND a.author_name LIKE '%$keywords%'";
  219. }
  220. $datagrid->setSQLCriteria($sql_criteria);
  221. // set table and table header attributes
  222. $datagrid->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  223. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  224. // set delete proccess URL
  225. $datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
  226. // callback function to change value of authority type
  227. function callbackAuthorType($obj_db, $rec_d)
  228. {
  229. global $sysconf, $auth_type_fld;
  230. return $sysconf['authority_type'][$rec_d[$auth_type_fld]];
  231. }
  232. // modify column content
  233. $datagrid->modifyColumnContent($auth_type_fld, 'callback{callbackAuthorType}');
  234. // put the result into variable
  235. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, ($can_read AND $can_write));
  236. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  237. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords')); //mfc
  238. echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"</div>';
  239. }
  240. echo $datagrid_result;
  241. }
  242. /* main content end */