PageRenderTime 23ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/modules/master_file/label.php

https://gitlab.com/mucill/majalengka
PHP | 260 lines | 173 code | 19 blank | 68 comment | 34 complexity | 8dd5e1ab3b96b0a5b4abfaed81bd77f8 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. /* Document Label 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. require SIMBIO.'simbio_FILE/simbio_file_upload.inc.php';
  40. // privileges checking
  41. $can_read = utility::havePrivilege('master_file', 'r');
  42. $can_write = utility::havePrivilege('master_file', 'w');
  43. if (!$can_read) {
  44. die('<div class="errorBox">'.__('You don\'t have enough privileges to view this section').'</div>');
  45. }
  46. /* RECORD OPERATION */
  47. if (isset($_POST['saveData']) AND $can_read AND $can_write) {
  48. $labelName = trim(strip_tags($_POST['labelName']));
  49. $labelDesc = trim(strip_tags($_POST['labelDesc']));
  50. // check form validity
  51. if (empty($labelDesc) OR empty($labelName)) {
  52. utility::jsAlert('Label Name OR Label Description must be filled!');
  53. exit();
  54. } else {
  55. $data['label_desc'] = $dbs->escape_string($labelDesc);
  56. $data['label_name'] = 'label-'.strtolower(str_ireplace(array(' ', 'label-', '_'), array('-', '', '-'), $dbs->escape_string($labelName)));
  57. // image uploading
  58. if (!empty($_FILES['labelImage']) AND $_FILES['labelImage']['size']) {
  59. // create upload object
  60. $image_upload = new simbio_file_upload();
  61. $image_upload->setAllowableFormat($sysconf['allowed_images']);
  62. $image_upload->setMaxSize($sysconf['max_image_upload']*1024);
  63. $image_upload->setUploadDir(IMGBS.'labels');
  64. // upload
  65. $img_upload_status = $image_upload->doUpload('labelImage', $data['label_name']);
  66. if ($img_upload_status == UPLOAD_SUCCESS) {
  67. $data['label_image'] = $dbs->escape_string($image_upload->new_filename);
  68. // write log
  69. utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', $_SESSION['realname'].' upload label image file '.$image_upload->new_filename);
  70. utility::jsAlert('Label image file successfully uploaded');
  71. } else {
  72. // write log
  73. utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', 'ERROR : '.$_SESSION['realname'].' FAILED TO upload label image file '.$image_upload->new_filename.', with error ('.$image_upload->error.')');
  74. utility::jsAlert('FAILED to upload label image! Please see System Log for more detailed information');
  75. }
  76. }
  77. $data['input_date'] = date('Y-m-d');
  78. $data['last_update'] = date('Y-m-d');
  79. // create sql op object
  80. $sql_op = new simbio_dbop($dbs);
  81. if (isset($_POST['updateRecordID'])) {
  82. /* UPDATE RECORD MODE */
  83. // remove input date
  84. unset($data['input_date']);
  85. // filter update record ID
  86. $updateRecordID = $dbs->escape_string(trim($_POST['updateRecordID']));
  87. // update the data
  88. $update = $sql_op->update('mst_label', $data, 'label_id='.$updateRecordID);
  89. if ($update) {
  90. utility::jsAlert(__('Label Data Successfully Updated'));
  91. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(parent.jQuery.ajaxHistory[0].url);</script>';
  92. } else { utility::jsAlert(__('Label Data FAILED to Updated. Please Contact System Administrator')."\nDEBUG : ".$sql_op->error); }
  93. exit();
  94. } else {
  95. /* INSERT RECORD MODE */
  96. // insert the data
  97. if ($sql_op->insert('mst_label', $data)) {
  98. utility::jsAlert(__('New Label Data Successfully Saved'));
  99. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'\');</script>';
  100. } else { utility::jsAlert(__('Label Data FAILED to Save. Please Contact System Administrator')."\nDEBUG : ".$sql_op->error); }
  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. // loop array
  118. foreach ($_POST['itemID'] as $itemID) {
  119. $itemID = (integer)$itemID;
  120. if (!$sql_op->delete('mst_label', 'label_id='.$itemID)) {
  121. $error_num++;
  122. }
  123. }
  124. // error alerting
  125. if ($error_num == 0) {
  126. utility::jsAlert(__('All Data Successfully Deleted'));
  127. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  128. } else {
  129. utility::jsAlert(__('Some or All Data NOT deleted successfully!\nPlease contact system administrator'));
  130. echo '<script type="text/javascript">parent.jQuery(\'#mainContent\').simbioAJAX(\''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\');</script>';
  131. }
  132. exit();
  133. }
  134. /* RECORD OPERATION END */
  135. /* search form */
  136. ?>
  137. <fieldset class="menuBox">
  138. <div class="menuBoxInner masterFileIcon">
  139. <div class="per_title">
  140. <h2><?php echo __('Label'); ?></h2>
  141. </div>
  142. <div class="sub_section">
  143. <div class="btn-group">
  144. <a href="<?php echo MWB; ?>master_file/label.php" class="btn btn-default"><i class="glyphicon glyphicon-list-alt"></i>&nbsp;<?php echo __('Label List'); ?></a>
  145. <a href="<?php echo MWB; ?>master_file/label.php?action=detail" class="btn btn-default"><i class="glyphicon glyphicon-plus"></i>&nbsp;<?php echo __('Add New Label'); ?></a>
  146. </div>
  147. <form name="search" action="<?php echo MWB; ?>master_file/label.php" id="search" method="get" style="display: inline;"><?php echo __('Search'); ?> :
  148. <input type="text" name="keywords" size="30" />
  149. <input type="submit" id="doSearch" value="<?php echo __('Search'); ?>" class="button" />
  150. </form>
  151. </div>
  152. </div>
  153. </fieldset>
  154. <?php
  155. /* search form end */
  156. /* main content */
  157. if (isset($_POST['detail']) OR (isset($_GET['action']) AND $_GET['action'] == 'detail')) {
  158. if (!($can_read AND $can_write)) {
  159. die('<div class="errorBox">'.__('You don\'t have enough privileges to view this section').'</div>');
  160. }
  161. /* RECORD FORM */
  162. $itemID = (integer)isset($_POST['itemID'])?$_POST['itemID']:0;
  163. $rec_q = $dbs->query('SELECT * FROM mst_label WHERE label_id='.$itemID);
  164. $rec_d = $rec_q->fetch_assoc();
  165. // create new instance
  166. $form = new simbio_form_table_AJAX('mainForm', $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], 'post');
  167. $form->submit_button_attr = 'name="saveData" value="'.__('Save').'" class="button"';
  168. // form table attributes
  169. $form->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  170. $form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
  171. $form->table_content_attr = 'class="alterCell2"';
  172. // edit mode flag set
  173. if ($rec_q->num_rows > 0) {
  174. $form->edit_mode = true;
  175. // record ID for delete process
  176. $form->record_id = $itemID;
  177. // form record title
  178. $form->record_title = str_ireplace('label-', '', $rec_d['label_name']);
  179. // submit button attribute
  180. $form->submit_button_attr = 'name="saveData" value="'.__('Update').'" class="button"';
  181. }
  182. /* Form Element(s) */
  183. // label name
  184. $form->addTextField('text', 'labelName', __('Label Name').'*', $rec_d['label_name'], 'style="width: 60%;" maxlength="20"');
  185. // label image
  186. if (empty($rec_d['label_image'])) {
  187. $str_input = simbio_form_element::textField('file', 'labelImage');
  188. $str_input .= ' Maximum '.$sysconf['max_image_upload'].' KB. All image will be automatically resized.';
  189. $form->addAnything(__('File Attachment'), $str_input);
  190. } else {
  191. $str_input = '<div><img src="'.SWB.'lib/minigalnano/createthumb.php?filename=../../'.IMG.'/labels/'.urlencode($rec_d['label_image']).'&amp;width=24&amp;height=24" align="middle" /> <strong>'.$rec_d['label_image'].'</strong></div>';
  192. $str_input .= simbio_form_element::textField('file', 'labelImage');
  193. $str_input .= ' Maximum '.$sysconf['max_image_upload'].' KB. All image will be automatically resized.';
  194. $form->addAnything(__('File Attachment'), $str_input);
  195. }
  196. // label desc
  197. $form->addTextField('text', 'labelDesc', __('Label Description'), $rec_d['label_desc'], 'style="width: 100%;" maxlength="50"');
  198. // edit mode messagge
  199. if ($form->edit_mode) {
  200. echo '<div class="infoBox">'.__('You are going to edit Label data').' : <b>'.$rec_d['label_name'].' - '.$rec_d['label_desc'].'</b> <br />'.__('Last Update').$rec_d['last_update'].'</div>'; //mfc
  201. }
  202. // print out the form object
  203. echo $form->printOut();
  204. } else {
  205. /* GMD LIST */
  206. // table spec
  207. $table_spec = 'mst_label AS lb';
  208. // create datagrid
  209. $datagrid = new simbio_datagrid();
  210. if ($can_read AND $can_write) {
  211. $datagrid->setSQLColumn('lb.label_id',
  212. 'lb.label_desc AS \''.__('Label Description').'\'',
  213. 'lb.label_name AS \''.__('Label Name').'\'',
  214. 'lb.last_update AS \''.__('Last Update').'\'');
  215. } else {
  216. $datagrid->setSQLColumn('lb.label_desc AS \''.__('Label Description').'\'',
  217. 'lb.label_name AS \''.__('Label Name').'\'',
  218. 'lb.last_update AS \''.__('Last Update').'\'');
  219. }
  220. $datagrid->setSQLorder('label_name ASC');
  221. // is there any search
  222. $criteria = 'lb.label_id IS NOT NULL';
  223. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  224. $keywords = $dbs->escape_string($_GET['keywords']);
  225. $criteria = " AND (lb.label_name LIKE '%$keywords%' OR lb.label_desc LIKE '%$keywords%')";
  226. }
  227. $datagrid->setSQLCriteria($criteria);
  228. // set table and table header attributes
  229. $datagrid->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  230. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  231. // set delete proccess URL
  232. $datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
  233. // put the result into variables
  234. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, ($can_read AND $can_write));
  235. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  236. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords')); //mfc
  237. echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"</div>';
  238. }
  239. echo $datagrid_result;
  240. }
  241. /* main content end */