external_module.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. // name of the language file that needs to be included
  34. $language_file='external_module';
  35. $iconForImportedTools='external.gif';
  36. $iconForInactiveImportedTools='external_inactive.gif';
  37. include('../inc/global.inc.php');
  38. $tbl_courseHome = Database::get_course_table(TABLE_TOOL_LIST);
  39. $toolid = $_GET['id']; // RH: all lines with $toolid added/changed by me
  40. if($toolid)
  41. {
  42. $nameTools = get_lang('EditLink');
  43. $noPHP_SELF = TRUE; // RH: no click to self on edit
  44. }
  45. else $nameTools = get_lang('AddLink');
  46. $is_allowedToEdit=$is_courseAdmin;
  47. $linkAdded=false;
  48. if($is_allowedToEdit && $_POST['formSent'] && $toolid) // RH: new section
  49. {
  50. $name_link=trim(stripslashes($_POST['name_link']));
  51. $link=trim(stripslashes($_POST['link']));
  52. $target=($_POST['target'] == '_blank')?'_blank':'_self';
  53. if(empty($name_link)) $msgErr=get_lang('NoLinkName');
  54. elseif(empty($link) || $link == 'http://') $msgErr=get_lang('NoLinkURL');
  55. else
  56. {
  57. $sql = "UPDATE $tbl_courseHome SET " .
  58. "name='" . Database::escape_string($name_link) .
  59. "', link='" . Database::escape_string($link) .
  60. "', target='" . Database::escape_string($target) .
  61. "' WHERE id='" . Database::escape_string($id) . "'";
  62. api_sql_query($sql, __FILE__, __LINE__);
  63. $linkAdded = TRUE;
  64. }
  65. }
  66. elseif($is_allowedToEdit && $_POST['formSent'])
  67. {
  68. $name_link=trim(stripslashes($_POST['name_link']));
  69. $link=trim(stripslashes($_POST['link']));
  70. $target=($_POST['target'] == '_blank')?'_blank':'_self';
  71. if(empty($name_link)) $msgErr=get_lang('NoLinkName');
  72. elseif(empty($link) || $link == 'http://') $msgErr=get_lang('NoLinkURL');
  73. else
  74. {
  75. if(!stristr($link,'http://'))
  76. {
  77. $link='http://'.$link;
  78. }
  79. api_sql_query("INSERT INTO $tbl_courseHome(name,link,image,visibility,admin,address,target) VALUES('".Database::escape_string($name_link)."','".Database::escape_string($link)."','$iconForImportedTools','1','0','$iconForInactiveImportedTools','$target')",__FILE__,__LINE__);
  80. $linkAdded=true;
  81. }
  82. }
  83. Display::display_header($nameTools,"External");
  84. ?>
  85. <h3><?php echo $toolid ? get_lang('EditLink') : $nameTools; ?></h3>
  86. <?php
  87. if(!$is_allowedToEdit)
  88. {
  89. api_not_allowed();
  90. }
  91. if($linkAdded)
  92. {
  93. echo $toolid ? get_lang('LinkChanged') :get_lang('OkSentLink');
  94. }
  95. else
  96. {
  97. if ($toolid) // RH: new section
  98. {
  99. $sql = "SELECT name,link,target FROM $tbl_courseHome" .
  100. " WHERE id='" . Database::escape_string($id) . "'";
  101. $result = api_sql_query($sql, __FILE__, __LINE__);
  102. (Database::num_rows($result) == 1 && ($row = Database::fetch_array($result)))
  103. or die('? Could not fetch data with ' . htmlspecialchars($sql));
  104. }
  105. ?>
  106. <p><?php echo $toolid ? get_lang('ChangePress') : get_lang('SubTitle'); ?></p>
  107. <table border="0">
  108. <form method="post" action="<?php echo $toolid ? api_get_self() . '?id=' . $id : api_get_self(); ?>">
  109. <input type="hidden" name="formSent" value="1">
  110. <?php
  111. if(!empty($msgErr))
  112. {
  113. ?>
  114. <tr>
  115. <td colspan="2">
  116. <?php
  117. Display::display_normal_message($msgErr); //main API
  118. ?>
  119. </td>
  120. </tr>
  121. <?php
  122. }
  123. ?>
  124. <tr>
  125. <td align="right"><?php echo get_lang('Link'); ?> :</td>
  126. <td><input type="text" name="link" size="50" value="<?php if($_POST['formSent']) echo htmlentities($link); else echo $toolid ? htmlspecialchars($row['link']) : 'http://'; ?>"></td>
  127. </tr>
  128. <tr>
  129. <td align="right"><?php echo get_lang('Name'); ?> :</td>
  130. <td><input type="text" name="name_link" size="50" value="<?php if($_POST['formSent']) echo htmlentities($name_link,ENT_QUOTES,$charset); else echo $toolid ? htmlspecialchars($row['name'],ENT_QUOTES,$charset) : ''; ?>"></td>
  131. </tr>
  132. <tr>
  133. <td align="right"><?php echo get_lang('LinkTarget'); ?> :</td>
  134. <td><select name="target">
  135. <option value="_self"><?php echo get_lang('SameWindow'); ?></option>
  136. <option value="_blank" <?php if(($_POST['formSent'] && $target == '_blank') || ($toolid && $row['target'] == '_blank')) echo 'selected="selected"'; ?>><?php echo get_lang('NewWindow'); ?></option>
  137. </select></td>
  138. </tr>
  139. <tr>
  140. <td>&nbsp;</td>
  141. <td><input type="submit" value="<?php echo get_lang('Ok'); ?>"></td>
  142. </tr>
  143. </table>
  144. <?php
  145. }
  146. Display::display_footer();
  147. ?>