PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/modules/master_file/publisher.php

https://github.com/awriel/s3st15_matoa
PHP | 222 lines | 140 code | 20 blank | 62 comment | 28 complexity | f2e987a442cc49964a2565194b47b684 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. /* Publisher 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 access this area!').'</div>');
  44. }
  45. /* RECORD OPERATION */
  46. if (isset($_POST['saveData']) AND $can_read AND $can_write) {
  47. $publisherName = trim(strip_tags($_POST['publisherName']));
  48. // check form validity
  49. if (empty($publisherName)) {
  50. utility::jsAlert(__('Publisher Name can\'t be empty')); //mfc
  51. exit();
  52. } else {
  53. $data['publisher_name'] = $dbs->escape_string($publisherName);
  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_publisher', $data, 'publisher_id='.$updateRecordID);
  66. if ($update) {
  67. utility::jsAlert(__('Publisher Data Successfully Updated'));
  68. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(parent.jQuery.ajaxHistory[0].url);</script>';
  69. } else { utility::jsAlert(__('PUBLISHER 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_publisher', $data);
  75. if ($insert) {
  76. utility::jsAlert(__('New Publisher Data Successfully Saved'));
  77. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'\');</script>';
  78. } else { utility::jsAlert(__('Publisher 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. if (!$sql_op->delete('mst_publisher', 'publisher_id='.$itemID)) {
  99. $error_num++;
  100. }
  101. }
  102. // error alerting
  103. if ($error_num == 0) {
  104. utility::jsAlert(__('All Data Successfully Deleted'));
  105. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  106. } else {
  107. utility::jsAlert(__('Some or All Data NOT deleted successfully!\nPlease contact system administrator'));
  108. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  109. }
  110. exit();
  111. }
  112. /* RECORD OPERATION */
  113. /* search form */
  114. ?>
  115. <fieldset class="menuBox">
  116. <div class="menuBoxInner masterFileIcon">
  117. <?php echo strtoupper(__('Publisher')); ?> - <a href="<?php echo MODULES_WEB_ROOT_DIR; ?>master_file/publisher.php?action=detail" class="headerText2"><?php echo __('Add New Publisher'); ?></a>
  118. &nbsp; <a href="<?php echo MODULES_WEB_ROOT_DIR; ?>master_file/publisher.php" class="headerText2"><?php echo __('Publisher List'); ?></a>
  119. <hr />
  120. <form name="search" action="<?php echo MODULES_WEB_ROOT_DIR; ?>master_file/publisher.php" id="search" method="get" style="display: inline;"><?php echo __('Search'); ?> :
  121. <input type="text" name="keywords" size="30" />
  122. <input type="submit" id="doSearch" value="<?php echo __('Search'); ?>" class="button" />
  123. </form>
  124. </div>
  125. </fieldset>
  126. <?php
  127. /* search form end */
  128. /* main content */
  129. if (isset($_POST['detail']) OR (isset($_GET['action']) AND $_GET['action'] == 'detail')) {
  130. if (!($can_read AND $can_write)) {
  131. die('<div class="errorBox">'.__('You don\'t have enough privileges to access this area!').'</div>');
  132. }
  133. /* RECORD FORM */
  134. $itemID = (integer)isset($_POST['itemID'])?$_POST['itemID']:0;
  135. $rec_q = $dbs->query('SELECT * FROM mst_publisher WHERE publisher_id='.$itemID);
  136. $rec_d = $rec_q->fetch_assoc();
  137. // create new instance
  138. $form = new simbio_form_table_AJAX('mainForm', $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], 'post');
  139. $form->submit_button_attr = 'name="saveData" value="'.__('Save').'" class="button"';
  140. // form table attributes
  141. $form->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  142. $form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
  143. $form->table_content_attr = 'class="alterCell2"';
  144. // edit mode flag set
  145. if ($rec_q->num_rows > 0) {
  146. $form->edit_mode = true;
  147. // record ID for delete process
  148. $form->record_id = $itemID;
  149. // form record title
  150. $form->record_title = $rec_d['publisher_name'];
  151. // submit button attribute
  152. $form->submit_button_attr = 'name="saveData" value="'.__('Update').'" class="button"';
  153. }
  154. /* Form Element(s) */
  155. // publisher name
  156. $form->addTextField('text', 'publisherName', __('Publisher Name').'*', $rec_d['publisher_name'], 'style="width: 60%;"');
  157. // edit mode messagge
  158. if ($form->edit_mode) {
  159. echo '<div class="infoBox">'.__('You are going to edit publisher data').' : <b>'.$rec_d['publisher_name'].'</b> <br />'.__('Last Update').$rec_d['last_update'] //mfc
  160. .'</div>'."\n";
  161. }
  162. // print out the form object
  163. echo $form->printOut();
  164. } else {
  165. /* PUBLISHER LIST */
  166. // table spec
  167. $table_spec = 'mst_publisher AS p';
  168. // create datagrid
  169. $datagrid = new simbio_datagrid();
  170. if ($can_read AND $can_write) {
  171. $datagrid->setSQLColumn('p.publisher_id',
  172. 'p.publisher_name AS \''.__('Publisher Name').'\'',
  173. 'p.last_update AS \''.__('Last Update').'\'');
  174. } else {
  175. // TODO: publisher_place was dropped in stable7...?
  176. $datagrid->setSQLColumn('p.publisher_name AS \''.__('Publisher Name').'\'',
  177. 'p.publisher_place AS \''.lang_mod_masterfile_publisher_form_field_place.'\'',
  178. 'p.last_update AS \''.__('Last Update').'\'');
  179. }
  180. $datagrid->setSQLorder('publisher_name ASC');
  181. // is there any search
  182. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  183. $keywords = $dbs->escape_string($_GET['keywords']);
  184. $datagrid->setSQLCriteria("p.publisher_name LIKE '%$keywords%'");
  185. }
  186. // set table and table header attributes
  187. $datagrid->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  188. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  189. // set delete proccess URL
  190. $datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
  191. // put the result into variable
  192. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, ($can_read AND $can_write));
  193. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  194. echo '<table cellpadding="3" cellspacing="0" class="infoBox">';
  195. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords')); //mfc
  196. echo '<tr><th>'.$msg.' : "'.$_GET['keywords'].'"</th></tr>';
  197. echo '</table>';
  198. }
  199. echo $datagrid_result;
  200. }
  201. /* main content end */
  202. ?>