PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/modules/system/module.php

https://gitlab.com/mucill/majalengka
PHP | 232 lines | 142 code | 19 blank | 71 comment | 27 complexity | 0ff230d59f7b27ed23017721752e87dc MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * Copyright (C) 2007,2008 Arie Nugraha (dicarve@yahoo.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. /* Module Management section */
  22. // key to authenticate
  23. define('INDEX_AUTH', '1');
  24. // key to get full database access
  25. define('DB_ACCESS', 'fa');
  26. // main system configuration
  27. require '../../../sysconfig.inc.php';
  28. // IP based access limitation
  29. require LIB.'ip_based_access.inc.php';
  30. do_checkIP('smc');
  31. do_checkIP('smc-system');
  32. // start the session
  33. require SB.'admin/default/session.inc.php';
  34. require SB.'admin/default/session_check.inc.php';
  35. // only administrator have privileges to modify modules data
  36. if ($_SESSION['uid'] != 1) {
  37. die('<div class="errorBox">'.__('You don\'t have enough privileges to view this section').'</div>');
  38. }
  39. require SIMBIO.'simbio_GUI/form_maker/simbio_form_table_AJAX.inc.php';
  40. require SIMBIO.'simbio_GUI/table/simbio_table.inc.php';
  41. require SIMBIO.'simbio_GUI/paging/simbio_paging.inc.php';
  42. require SIMBIO.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
  43. require SIMBIO.'simbio_DB/simbio_dbop.inc.php';
  44. /* RECORD OPERATION */
  45. if (isset($_POST['saveData'])) {
  46. // check form validity
  47. $moduleName = trim(strip_tags($_POST['moduleName']));
  48. $modulePath = trim(strip_tags($_POST['modulePath']));
  49. if (empty($moduleName) OR empty($modulePath)) {
  50. utility::jsAlert(__('Module name and path can\'t be empty'));
  51. exit();
  52. } else {
  53. $data['module_path'] = $dbs->escape_string($modulePath);
  54. // check for module path existance
  55. if (!file_exists(MDLBS.$data['module_path'].DS)) {
  56. utility::jsAlert('Modules path doesn\'t exists! Please check again in module base directory');
  57. exit();
  58. }
  59. $data['module_name'] = $dbs->escape_string($moduleName);
  60. $data['module_desc'] = trim($dbs->escape_string(strip_tags($_POST['moduleDesc'])));
  61. // create sql op object
  62. $sql_op = new simbio_dbop($dbs);
  63. if (isset($_POST['updateRecordID'])) {
  64. /* UPDATE RECORD MODE */
  65. // filter update record ID
  66. $updateRecordID = (integer)$_POST['updateRecordID'];
  67. // update the data
  68. $update = $sql_op->update('mst_module', $data, 'module_id='.$updateRecordID);
  69. if ($update) {
  70. // write log
  71. utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'system', $_SESSION['realname'].' update module data ('.$moduleName.') with path ('.$modulePath.')');
  72. utility::jsAlert(__('Module Data Successfully Updated'));
  73. echo '<script type="text/javascript">parent.$(\'#mainContent\').simbioAJAX(parent.$.ajaxHistory[0].url);</script>';
  74. } else { utility::jsAlert(__('Module Data FAILED to Updated. Please Contact System Administrator')."\nDEBUG : ".$sql_op->error); }
  75. exit();
  76. } else {
  77. /* INSERT RECORD MODE */
  78. // insert the data
  79. if ($sql_op->insert('mst_module', $data)) {
  80. // insert module privileges for administrator
  81. $module_id = $sql_op->insert_id;
  82. $dbs->query('INSERT INTO group_access VALUES (1, '.$module_id.', 1, 1)');
  83. // write log
  84. utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'system', $_SESSION['realname'].' add new module ('.$moduleName.') with path ('.$modulePath.')');
  85. utility::jsAlert(__('New Module Data Successfully Saved'));
  86. echo '<script type="text/javascript">parent.$(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'\');</script>';
  87. } else { utility::jsAlert(__('Module Data FAILED to Save. Please Contact System Administrator')."\n".$sql_op->error); }
  88. exit();
  89. }
  90. }
  91. exit();
  92. } else if (isset($_POST['itemID']) AND !empty($_POST['itemID']) AND isset($_POST['itemAction'])) {
  93. /* DATA DELETION PROCESS */
  94. $sql_op = new simbio_dbop($dbs);
  95. $failed_array = array();
  96. $error_num = 0;
  97. if (!is_array($_POST['itemID'])) {
  98. // make an array
  99. $_POST['itemID'] = array((integer)$_POST['itemID']);
  100. }
  101. // loop array
  102. foreach ($_POST['itemID'] as $itemID) {
  103. $itemID = (integer)$itemID;
  104. // get module data
  105. $module_q = $dbs->query('SELECT module_name, module_path FROM mst_module WHERE module_id='.$itemID);
  106. $module_d = $module_q->fetch_row();
  107. if (!$sql_op->delete('mst_module', "module_id=$itemID")) {
  108. $error_num++;
  109. } else {
  110. // also delete all records related to this data
  111. // delete group privileges
  112. $dbs->query('DELETE FROM group_access WHERE module_id='.$itemID);
  113. // write log
  114. utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'system', $_SESSION['realname'].' DELETE module ('.$module_d[0].') with path ('.$module_d[1].')');
  115. }
  116. }
  117. // error alerting
  118. if ($error_num == 0) {
  119. utility::jsAlert(__('All Data Successfully Deleted'));
  120. echo '<script type="text/javascript">parent.$(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  121. } else {
  122. utility::jsAlert(__('Some or All Data NOT deleted successfully!\nPlease contact system administrator'));
  123. echo '<script type="text/javascript">parent.$(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  124. }
  125. exit();
  126. }
  127. /* RECORD OPERATION */
  128. /* search form */
  129. ?>
  130. <fieldset class="menuBox">
  131. <div class="menuBoxInner moduleIcon">
  132. <div class="per_title">
  133. <h2><?php echo __('Modules'); ?></h2>
  134. </div>
  135. <div class="sub_section">
  136. <div class="btn-group">
  137. <a href="<?php echo MWB; ?>system/module.php" class="btn btn-default"><i class="glyphicon glyphicon-list-alt"></i>&nbsp;<?php echo __('Modules List'); ?></a>
  138. <a href="<?php echo MWB; ?>system/module.php?action=detail" class="btn btn-default"><i class="glyphicon glyphicon-plus"></i>&nbsp;<?php echo __('Add New Modules'); ?></a>
  139. </div>
  140. <form name="search" action="<?php echo MWB; ?>system/module.php" id="search" method="get" style="display: inline;"><?php echo __('Search'); ?> :
  141. <input type="text" name="keywords" size="30" />
  142. <input type="submit" id="doSearch" value="<?php echo __('Search'); ?>" class="btn btn-default" />
  143. </form>
  144. </div>
  145. </div>
  146. </fieldset>
  147. <?php
  148. /* search form end */
  149. /* main content */
  150. if (isset($_POST['detail']) OR (isset($_GET['action']) AND $_GET['action'] == 'detail')) {
  151. /* RECORD FORM */
  152. $itemID = (integer)isset($_POST['itemID'])?$_POST['itemID']:0;
  153. $rec_q = $dbs->query('SELECT * FROM mst_module WHERE module_id='.$itemID);
  154. $rec_d = $rec_q->fetch_assoc();
  155. // create new instance
  156. $form = new simbio_form_table_AJAX('mainForm', $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], 'post');
  157. $form->submit_button_attr = 'name="saveData" value="'.__('Save').'" class="btn btn-default"';
  158. // form table attributes
  159. $form->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  160. $form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
  161. $form->table_content_attr = 'class="alterCell2"';
  162. // edit mode flag set
  163. if ($rec_q->num_rows > 0) {
  164. $form->edit_mode = true;
  165. // record ID for delete process
  166. $form->record_id = $itemID;
  167. // form record title
  168. $form->record_title = $rec_d['module_name'];
  169. // submit button attribute
  170. $form->submit_button_attr = 'name="saveData" value="'.__('Update').'" class="btn btn-default"';
  171. }
  172. /* Form Element(s) */
  173. // module
  174. $form->addTextField('text', 'moduleName', __('Module Name').'*', $rec_d['module_name'], 'style="width: 50%;"');
  175. // module path
  176. $form->addTextField('text', 'modulePath', __('Module Path').'*', $rec_d['module_path'], 'style="width: 100%;"');
  177. // module desc
  178. $form->addTextField('text', 'moduleDesc', __('Module Description'), $rec_d['module_desc'], 'style="width: 100%;"');
  179. // edit mode messagge
  180. if ($form->edit_mode) {
  181. echo '<div class="infoBox">'.__('You are going to edit data').' : <b>'.$rec_d['module_name'].'</b></div>'; //mfc
  182. }
  183. // print out the form object
  184. echo $form->printOut();
  185. } else {
  186. /* MODULE LIST */
  187. // table spec
  188. $table_spec = 'mst_module AS mdl';
  189. // create datagrid
  190. $datagrid = new simbio_datagrid();
  191. $datagrid->setSQLColumn('mdl.module_id',
  192. 'mdl.module_name AS \''.__('Module Name').'\'',
  193. 'mdl.module_desc AS \''.__('Module Description').'\'');
  194. $datagrid->setSQLorder('module_name ASC');
  195. // is there any search
  196. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  197. $keywords = $dbs->escape_string($_GET['keywords']);
  198. $datagrid->setSQLCriteria("mdl.module_name LIKE '%$keywords%'");
  199. }
  200. // set table and table header attributes
  201. $datagrid->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  202. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  203. // set delete proccess URL
  204. $datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
  205. // put the result into variables
  206. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, true);
  207. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  208. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords')); //mfc
  209. echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"</div>';
  210. }
  211. echo $datagrid_result;
  212. }
  213. /* main content end */