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

/admin/modules/bibliography/pop_topic.php

https://gitlab.com/mucill/majalengka
PHP | 193 lines | 133 code | 16 blank | 44 comment | 19 complexity | f4f8d62df521dd43b92efdc0baa94145 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. /* Biblio Topic Adding Pop Windows */
  21. // key to authenticate
  22. define('INDEX_AUTH', '1');
  23. // main system configuration
  24. require '../../../sysconfig.inc.php';
  25. // IP based access limitation
  26. require LIB.'ip_based_access.inc.php';
  27. do_checkIP('smc');
  28. do_checkIP('smc-bibliography');
  29. // start the session
  30. require SB.'admin/default/session.inc.php';
  31. require SB.'admin/default/session_check.inc.php';
  32. require SIMBIO.'simbio_GUI/table/simbio_table.inc.php';
  33. require SIMBIO.'simbio_GUI/form_maker/simbio_form_table.inc.php';
  34. require SIMBIO.'simbio_DB/simbio_dbop.inc.php';
  35. // privileges checking
  36. $can_write = utility::havePrivilege('bibliography', 'w');
  37. if (!$can_write) {
  38. die('<div class="errorBox">'.__('You are not authorized to view this section').'</div>');
  39. }
  40. // page title
  41. $page_title = 'Subject List';
  42. // check for biblioID in url
  43. $biblioID = 0;
  44. if (isset($_GET['biblioID']) AND $_GET['biblioID']) {
  45. $biblioID = (integer)$_GET['biblioID'];
  46. }
  47. // utility function to check subject/topic
  48. function checkSubject($str_subject, $str_subject_type = 't')
  49. {
  50. global $dbs;
  51. $_q = $dbs->query('SELECT topic_id FROM mst_topic WHERE topic=\''.$str_subject.'\' AND topic_type=\''.$str_subject_type.'\'');
  52. if ($_q->num_rows > 0) {
  53. $_d = $_q->fetch_row();
  54. // return the subject/topic ID
  55. return $_d[0];
  56. }
  57. return false;
  58. }
  59. // start the output buffer
  60. ob_start();
  61. /* main content */
  62. // biblio topic save proccess
  63. if (isset($_POST['save']) AND (isset($_POST['topicID']) OR trim($_POST['search_str']))) {
  64. $subject = trim($dbs->escape_string(strip_tags($_POST['search_str'])));
  65. // create new sql op object
  66. $sql_op = new simbio_dbop($dbs);
  67. // check if biblioID POST var exists
  68. if (isset($_POST['biblioID']) AND !empty($_POST['biblioID'])) {
  69. $data['biblio_id'] = (integer)$_POST['biblioID'];
  70. // check if the topic select list is empty or not
  71. if (!empty($_POST['topicID'])) {
  72. $data['topic_id'] = $_POST['topicID'];
  73. } else if ($subject AND empty($_POST['topicID'])) {
  74. // check subject
  75. $subject_id = checkSubject($subject, $_POST['type']);
  76. if ($subject_id !== false) {
  77. $data['topic_id'] = $subject_id;
  78. } else {
  79. // adding new topic
  80. $topic_data['topic'] = $subject;
  81. $topic_data['topic_type'] = $_POST['type'];
  82. $topic_data['input_date'] = date('Y-m-d');
  83. $topic_data['last_update'] = date('Y-m-d');
  84. // insert new topic to topic master table
  85. $sql_op->insert('mst_topic', $topic_data);
  86. // put last inserted ID
  87. $data['topic_id'] = $sql_op->insert_id;
  88. }
  89. }
  90. $data['level'] = intval($_POST['level']);
  91. if ($sql_op->insert('biblio_topic', $data)) {
  92. echo '<script type="text/javascript">';
  93. echo 'alert(\'' . addslashes(__('Topic succesfully updated!')) . '\');';
  94. echo 'parent.setIframeContent(\'topicIframe\', \''.MWB.'bibliography/iframe_topic.php?biblioID='.$data['biblio_id'].'\');';
  95. echo '</script>';
  96. } else {
  97. utility::jsAlert(__('Subject FAILED to Add. Please Contact System Administrator')."\n".$sql_op->error);
  98. }
  99. } else {
  100. if (!empty($_POST['topicID'])) {
  101. // add to current session
  102. $_SESSION['biblioTopic'][$_POST['topicID']] = array($_POST['topicID'], intval($_POST['level']));
  103. } else if ($subject AND empty($_POST['topicID'])) {
  104. // check subject
  105. $subject_id = checkSubject($subject);
  106. if ($subject_id !== false) {
  107. $last_id = $subject_id;
  108. } else {
  109. // adding new topic
  110. $topic_data['topic'] = $subject;
  111. $topic_data['topic_type'] = $_POST['type'];
  112. $topic_data['input_date'] = date('Y-m-d');
  113. $topic_data['last_update'] = date('Y-m-d');
  114. // insert new topic to topic master table
  115. $sql_op->insert('mst_topic', $topic_data);
  116. $last_id = $sql_op->insert_id;
  117. }
  118. $_SESSION['biblioTopic'][$last_id] = array($last_id, intval($_POST['level']));
  119. }
  120. echo '<script type="text/javascript">';
  121. echo 'alert(\''.__('Subject added!').'\');';
  122. echo 'parent.setIframeContent(\'topicIframe\', \''.MWB.'bibliography/iframe_topic.php\');';
  123. echo '</script>';
  124. }
  125. }
  126. ?>
  127. <div class="popUpForm">
  128. <form name="mainForm" action="pop_topic.php?biblioID=<?php echo $biblioID; ?>" method="post">
  129. <div>
  130. <strong><?php echo __('Add Subject'); ?></strong>
  131. <hr />
  132. <form name="searchTopic" method="post" style="display: inline;">
  133. <?php
  134. $ajax_exp = "ajaxFillSelect('../../AJAX_vocabolary_control.php', 'mst_topic', 'topic_id:topic:topic_type', 'topicID', $('#search_str').val())";
  135. ?>
  136. <?php echo __('Keyword'); ?> : <input type="text" name="search_str" id="search_str" style="width: 30%;" onkeyup="<?php echo $ajax_exp; ?>" />
  137. <select name="type" style="width: 20%;"><?php
  138. foreach ($sysconf['subject_type'] as $type_id => $type) {
  139. echo '<option value="'.$type_id.'">'.$type.'</option>';
  140. }
  141. ?></select>
  142. <select name="level" style="width: 20%;">
  143. <?php
  144. echo '<option value="1">' . __('Primary') . '</option>';
  145. echo '<option value="2">' . __('Additional') . '</option>';
  146. ?>
  147. </select>
  148. </div>
  149. <div class="popUpSubForm">
  150. <ul id="topicID">
  151. <li><?php echo __('Type to search for existing topics or to add a new one'); ?></li>
  152. </ul>
  153. <?php if ($biblioID) { echo '<input type="hidden" name="biblioID" value="'.$biblioID.'" />'; } ?>
  154. <input type="submit" name="save" value="<?php echo __('Insert To Bibliography'); ?>" class="popUpSubmit btn btn-primary" />
  155. </div>
  156. </form>
  157. <script type="text/javascript">
  158. $('#topicID').mouseover(function() {
  159. $('.voc').mouseover(function() {
  160. $(this).css({'cursor': 'pointer', 'background': '#b3e5fc'});
  161. })
  162. .mouseleave(function() {
  163. $(this).css('background', 'none');
  164. })
  165. .click(function() {
  166. var vocVal = $(this).text();
  167. $('#search_str').val(vocVal);
  168. ajaxFillSelect('../../AJAX_vocabolary_control.php', 'mst_topic', 'topic_id:topic:topic_type', 'topicID', vocVal);
  169. });
  170. });
  171. </script>
  172. </div>
  173. <?php
  174. /* main content end */
  175. $content = ob_get_clean();
  176. // include the page template
  177. require SB.'/admin/'.$sysconf['admin_template']['dir'].'/notemplate_page_tpl.php';