PageRenderTime 57ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/modules/system/module.php

https://github.com/awriel/s3st15_matoa
PHP | 230 lines | 140 code | 19 blank | 71 comment | 28 complexity | 00f102aa02d906f5f5d5e333945fe324 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 2 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_DIR.'ip_based_access.inc.php';
  30. do_checkIP('smc');
  31. do_checkIP('smc-system');
  32. // start the session
  33. require SENAYAN_BASE_DIR.'admin/default/session.inc.php';
  34. require SENAYAN_BASE_DIR.'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_BASE_DIR.'simbio_GUI/form_maker/simbio_form_table_AJAX.inc.php';
  40. require SIMBIO_BASE_DIR.'simbio_GUI/table/simbio_table.inc.php';
  41. require SIMBIO_BASE_DIR.'simbio_GUI/paging/simbio_paging.inc.php';
  42. require SIMBIO_BASE_DIR.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
  43. require SIMBIO_BASE_DIR.'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(MODULES_BASE_DIR.$data['module_path'].DIRECTORY_SEPARATOR)) {
  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. if (!($can_read AND $can_write)) {
  94. die();
  95. }
  96. /* DATA DELETION PROCESS */
  97. $sql_op = new simbio_dbop($dbs);
  98. $failed_array = array();
  99. $error_num = 0;
  100. if (!is_array($_POST['itemID'])) {
  101. // make an array
  102. $_POST['itemID'] = array((integer)$_POST['itemID']);
  103. }
  104. // loop array
  105. foreach ($_POST['itemID'] as $itemID) {
  106. $itemID = (integer)$itemID;
  107. // get module data
  108. $module_q = $dbs->query('SELECT module_name, module_path FROM mst_module WHERE module_id='.$itemID);
  109. $module_d = $module_q->fetch_row();
  110. if (!$sql_op->delete('mst_module', "module_id=$itemID")) {
  111. $error_num++;
  112. } else {
  113. // also delete all records related to this data
  114. // delete group privileges
  115. $dbs->query('DELETE FROM group_access WHERE module_id='.$itemID);
  116. // write log
  117. utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'system', $_SESSION['realname'].' DELETE module ('.$module_d[0].') with path ('.$module_d[1].')');
  118. }
  119. }
  120. // error alerting
  121. if ($error_num == 0) {
  122. utility::jsAlert(__('All Data Successfully Deleted'));
  123. echo '<script type="text/javascript">parent.$(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  124. } else {
  125. utility::jsAlert(__('Some or All Data NOT deleted successfully!\nPlease contact system administrator'));
  126. echo '<script type="text/javascript">parent.$(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  127. }
  128. exit();
  129. }
  130. /* RECORD OPERATION */
  131. /* search form */
  132. ?>
  133. <fieldset class="menuBox">
  134. <div class="menuBoxInner moduleIcon">
  135. <?php echo strtoupper(__('Modules')); ?> - <a href="<?php echo MODULES_WEB_ROOT_DIR; ?>system/module.php?action=detail" class="headerText2"><?php echo __('Add New Modules'); ?></a>
  136. &nbsp; <a href="<?php echo MODULES_WEB_ROOT_DIR; ?>system/module.php" class="headerText2"><?php echo __('Modules List'); ?></a>
  137. <hr />
  138. <form name="search" action="<?php echo MODULES_WEB_ROOT_DIR; ?>system/module.php" id="search" method="get" style="display: inline;"><?php echo __('Search'); ?> :
  139. <input type="text" name="keywords" size="30" />
  140. <input type="submit" id="doSearch" value="<?php echo __('Search'); ?>" class="button" />
  141. </form>
  142. </div>
  143. </fieldset>
  144. <?php
  145. /* search form end */
  146. /* main content */
  147. if (isset($_POST['detail']) OR (isset($_GET['action']) AND $_GET['action'] == 'detail')) {
  148. /* RECORD FORM */
  149. $itemID = (integer)isset($_POST['itemID'])?$_POST['itemID']:0;
  150. $rec_q = $dbs->query('SELECT * FROM mst_module WHERE module_id='.$itemID);
  151. $rec_d = $rec_q->fetch_assoc();
  152. // create new instance
  153. $form = new simbio_form_table_AJAX('mainForm', $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], 'post');
  154. $form->submit_button_attr = 'name="saveData" value="'.__('Save').'" class="button"';
  155. // form table attributes
  156. $form->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  157. $form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
  158. $form->table_content_attr = 'class="alterCell2"';
  159. // edit mode flag set
  160. if ($rec_q->num_rows > 0) {
  161. $form->edit_mode = true;
  162. // record ID for delete process
  163. $form->record_id = $itemID;
  164. // form record title
  165. $form->record_title = $rec_d['module_name'];
  166. // submit button attribute
  167. $form->submit_button_attr = 'name="saveData" value="'.__('Update').'" class="button"';
  168. }
  169. /* Form Element(s) */
  170. // module
  171. $form->addTextField('text', 'moduleName', __('Module Name').'*', $rec_d['module_name'], 'style="width: 50%;"');
  172. // module path
  173. $form->addTextField('text', 'modulePath', __('Module Path').'*', $rec_d['module_path'], 'style="width: 100%;"');
  174. // module desc
  175. $form->addTextField('text', 'moduleDesc', __('Module Description'), $rec_d['module_desc'], 'style="width: 100%;"');
  176. // edit mode messagge
  177. if ($form->edit_mode) {
  178. echo '<div class="infoBox">'.__('You are going to edit data').' : <b>'.$rec_d['module_name'].'</b></div>'; //mfc
  179. }
  180. // print out the form object
  181. echo $form->printOut();
  182. } else {
  183. /* MODULE LIST */
  184. // table spec
  185. $table_spec = 'mst_module AS mdl';
  186. // create datagrid
  187. $datagrid = new simbio_datagrid();
  188. $datagrid->setSQLColumn('mdl.module_id',
  189. 'mdl.module_name AS \''.__('Module Name').'\'',
  190. 'mdl.module_desc AS \''.__('Module Description').'\'');
  191. $datagrid->setSQLorder('module_name ASC');
  192. // is there any search
  193. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  194. $keywords = $dbs->escape_string($_GET['keywords']);
  195. $datagrid->setSQLCriteria("mdl.module_name LIKE '%$keywords%'");
  196. }
  197. // set table and table header attributes
  198. $datagrid->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  199. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  200. // set delete proccess URL
  201. $datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
  202. // put the result into variables
  203. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, true);
  204. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  205. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords')); //mfc
  206. echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"</div>';
  207. }
  208. echo $datagrid_result;
  209. }
  210. /* main content end */
  211. ?>