external_module.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * This script is used for adding hyperlinks to a course homepage.
  22. * It used to be able to link html documents as well,
  23. * which it displayed in context, but that was abandoned
  24. * because of changes in documents tool:
  25. *
  26. * Html files are displayed by default with frames now in the documents tool
  27. * so the external module - html file include has to be refactored to
  28. * reuse documents tool code.
  29. *
  30. * @package dokeos.external_module
  31. ==============================================================================
  32. */
  33. $langFile='external_module';
  34. $iconForImportedTools='external.gif';
  35. $iconForInactiveImportedTools='external_inactive.gif';
  36. include('../inc/global.inc.php');
  37. $tbl_courseHome = Database::get_course_table(TOOL_LIST_TABLE);
  38. $toolid = $_GET['id']; // RH: all lines with $toolid added/changed by me
  39. if($toolid)
  40. {
  41. $nameTools = get_lang('EditLink');
  42. $noPHP_SELF = TRUE; // RH: no click to self on edit
  43. }
  44. else $nameTools = get_lang('AddLink');
  45. $is_allowedToEdit=$is_courseAdmin;
  46. $linkAdded=false;
  47. if($is_allowedToEdit && $_POST['formSent'] && $toolid) // RH: new section
  48. {
  49. $name_link=trim(stripslashes($_POST['name_link']));
  50. $link=trim(stripslashes($_POST['link']));
  51. $target=($_POST['target'] == '_blank')?'_blank':'_self';
  52. if(empty($name_link)) $msgErr=get_lang('NoLinkName');
  53. elseif(empty($link) || $link == 'http://') $msgErr=get_lang('NoLinkURL');
  54. else
  55. {
  56. $sql = "UPDATE $tbl_courseHome SET " .
  57. "name='" . addslashes($name_link) .
  58. "', link='" . addslashes($link) .
  59. "', target='" . addslashes($target) .
  60. "' WHERE id='" . addslashes($id) . "'";
  61. api_sql_query($sql, __FILE__, __LINE__);
  62. $linkAdded = TRUE;
  63. }
  64. }
  65. elseif($is_allowedToEdit && $_POST['formSent'])
  66. {
  67. $name_link=trim(stripslashes($_POST['name_link']));
  68. $link=trim(stripslashes($_POST['link']));
  69. $target=($_POST['target'] == '_blank')?'_blank':'_self';
  70. if(empty($name_link)) $msgErr=get_lang('NoLinkName');
  71. elseif(empty($link) || $link == 'http://') $msgErr=get_lang('NoLinkURL');
  72. else
  73. {
  74. if(!stristr($link,'http://'))
  75. {
  76. $link='http://'.$link;
  77. }
  78. api_sql_query("INSERT INTO $tbl_courseHome(name,link,image,visibility,admin,address,target) VALUES('".addslashes($name_link)."','".addslashes($link)."','$iconForImportedTools','1','0','$iconForInactiveImportedTools','$target')",__FILE__,__LINE__);
  79. $linkAdded=true;
  80. }
  81. }
  82. Display::display_header($nameTools,"External");
  83. ?>
  84. <h3><?php echo $toolid ? get_lang('EditLink') : $nameTools; ?></h3>
  85. <?php
  86. if(!$is_allowedToEdit)
  87. {
  88. api_not_allowed();
  89. }
  90. if($linkAdded)
  91. {
  92. echo $toolid ? get_lang('LinkChanged') :get_lang('OkSentLink');
  93. }
  94. else
  95. {
  96. if ($toolid) // RH: new section
  97. {
  98. $sql = "SELECT name,link,target FROM $tbl_courseHome" .
  99. " WHERE id='" . addslashes($id) . "'";
  100. $result = api_sql_query($sql, __FILE__, __LINE__);
  101. (mysql_num_rows($result) == 1 && ($row = mysql_fetch_array($result)))
  102. or die('? Could not fetch data with ' . htmlspecialchars($sql));
  103. }
  104. ?>
  105. <p><?php echo $toolid ? get_lang('ChangePress') : get_lang('SubTitle'); ?></p>
  106. <table border="0">
  107. <form method="post" action="<?php echo $toolid ? $_SERVER['PHP_SELF'] . '?id=' . $id : $_SERVER['PHP_SELF']; ?>">
  108. <input type="hidden" name="formSent" value="1">
  109. <?php
  110. if(!empty($msgErr))
  111. {
  112. ?>
  113. <tr>
  114. <td colspan="2">
  115. <?php
  116. Display::display_normal_message($msgErr); //main API
  117. ?>
  118. </td>
  119. </tr>
  120. <?php
  121. }
  122. ?>
  123. <tr>
  124. <td align="right"><?php echo get_lang('Link'); ?> :</td>
  125. <td><input type="text" name="link" size="50" value="<?php if($_POST['formSent']) echo htmlentities($link); else echo $toolid ? htmlspecialchars($row['link']) : 'http://'; ?>"></td>
  126. </tr>
  127. <tr>
  128. <td align="right"><?php echo get_lang('Name'); ?> :</td>
  129. <td><input type="text" name="name_link" size="50" value="<?php if($_POST['formSent']) echo htmlentities($name_link); else echo $toolid ? htmlspecialchars($row['name']) : ''; ?>"></td>
  130. </tr>
  131. <tr>
  132. <td align="right"><?php echo get_lang('LinkTarget'); ?> :</td>
  133. <td><select name="target">
  134. <option value="_self"><?php echo get_lang('SameWindow'); ?></option>
  135. <option value="_blank" <?php if(($_POST['formSent'] && $target == '_blank') || ($toolid && $row['target'] == '_blank')) echo 'selected="selected"'; ?>><?php echo get_lang('NewWindow'); ?></option>
  136. </select></td>
  137. </tr>
  138. <tr>
  139. <td>&nbsp;</td>
  140. <td><input type="submit" value="<?php echo get_lang('Ok'); ?>"></td>
  141. </tr>
  142. </table>
  143. <?php
  144. }
  145. Display::display_footer();
  146. ?>