external_module.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. ==============================================================================
  5. * This script is used for adding hyperlinks to a course homepage.
  6. * It used to be able to link html documents as well,
  7. * which it displayed in context, but that was abandoned
  8. * because of changes in documents tool:
  9. *
  10. * Html files are displayed by default with frames now in the documents tool
  11. * so the external module - html file include has to be refactored to
  12. * reuse documents tool code.
  13. *
  14. * @package chamilo.external_module
  15. * @todo this code is useless?
  16. ==============================================================================
  17. */
  18. // name of the language file that needs to be included
  19. $language_file='external_module';
  20. $iconForImportedTools='external.gif';
  21. $iconForInactiveImportedTools='external_inactive.gif';
  22. include('../inc/global.inc.php');
  23. $tbl_courseHome = Database::get_course_table(TABLE_TOOL_LIST);
  24. $toolid = $_GET['id']; // RH: all lines with $toolid added/changed by me
  25. if($toolid)
  26. {
  27. $nameTools = get_lang('EditLink');
  28. $noPHP_SELF = TRUE; // RH: no click to self on edit
  29. }
  30. else $nameTools = get_lang('AddLink');
  31. $is_allowedToEdit=$is_courseAdmin;
  32. $linkAdded=false;
  33. if($is_allowedToEdit && $_POST['formSent'] && $toolid) // RH: new section
  34. {
  35. $name_link=trim(stripslashes($_POST['name_link']));
  36. $link=trim(stripslashes($_POST['link']));
  37. $target=($_POST['target'] == '_blank')?'_blank':'_self';
  38. if(empty($name_link)) $msgErr=get_lang('NoLinkName');
  39. elseif(empty($link) || $link == 'http://') $msgErr=get_lang('NoLinkURL');
  40. else
  41. {
  42. $sql = "UPDATE $tbl_courseHome SET " .
  43. "name='" . Database::escape_string($name_link) .
  44. "', link='" . Database::escape_string($link) .
  45. "', target='" . Database::escape_string($target) .
  46. "' WHERE id='" . Database::escape_string($id) . "'";
  47. Database::query($sql);
  48. $linkAdded = TRUE;
  49. }
  50. }
  51. elseif($is_allowedToEdit && $_POST['formSent'])
  52. {
  53. $name_link=trim(stripslashes($_POST['name_link']));
  54. $link=trim(stripslashes($_POST['link']));
  55. $target=($_POST['target'] == '_blank')?'_blank':'_self';
  56. if(empty($name_link)) $msgErr=get_lang('NoLinkName');
  57. elseif(empty($link) || $link == 'http://') $msgErr=get_lang('NoLinkURL');
  58. else
  59. {
  60. if(!stristr($link,'http://'))
  61. {
  62. $link='http://'.$link;
  63. }
  64. Database::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')");
  65. $linkAdded=true;
  66. }
  67. }
  68. Display::display_header($nameTools,"External");
  69. ?>
  70. <h3><?php echo $toolid ? get_lang('EditLink') : $nameTools; ?></h3>
  71. <?php
  72. if(!$is_allowedToEdit)
  73. {
  74. api_not_allowed();
  75. }
  76. if($linkAdded)
  77. {
  78. echo $toolid ? get_lang('LinkChanged') :sprintf(get_lang('OkSentLink'),api_get_path(WEB_COURSE_PATH).$_course['path']);
  79. }
  80. else
  81. {
  82. if ($toolid) // RH: new section
  83. {
  84. $sql = "SELECT name,link,target FROM $tbl_courseHome" .
  85. " WHERE id='" . Database::escape_string($toolid) . "'";
  86. $result = Database::query($sql);
  87. (Database::num_rows($result) == 1 && ($row = Database::fetch_array($result)))
  88. or die('? Could not fetch data with ' . htmlspecialchars($sql));
  89. }
  90. ?>
  91. <p><?php echo $toolid ? get_lang('ChangePress') : get_lang('SubTitle'); ?></p>
  92. <table border="0">
  93. <form method="post" action="<?php echo $toolid ? api_get_self() . '?id=' . $id : api_get_self(); ?>">
  94. <input type="hidden" name="formSent" value="1">
  95. <?php
  96. if(!empty($msgErr))
  97. {
  98. ?>
  99. <tr>
  100. <td colspan="2">
  101. <?php
  102. Display::display_normal_message($msgErr); //main API
  103. ?>
  104. </td>
  105. </tr>
  106. <?php
  107. }
  108. ?>
  109. <tr>
  110. <td align="right"><?php echo get_lang('Link'); ?> :</td>
  111. <td><input type="text" name="link" size="50" value="<?php if($_POST['formSent']) echo htmlentities($link); else echo $toolid ? htmlspecialchars($row['link']) : 'http://'; ?>"></td>
  112. </tr>
  113. <tr>
  114. <td align="right"><?php echo get_lang('Name'); ?> :</td>
  115. <td><input type="text" name="name_link" size="50" value="<?php if($_POST['formSent']) echo api_htmlentities($name_link,ENT_QUOTES,$charset); else echo $toolid ? htmlspecialchars($row['name'],ENT_QUOTES,$charset) : ''; ?>"></td>
  116. </tr>
  117. <tr>
  118. <td align="right"><?php echo get_lang('LinkTarget'); ?> :</td>
  119. <td><select name="target">
  120. <option value="_self"><?php echo get_lang('SameWindow'); ?></option>
  121. <option value="_blank" <?php if(($_POST['formSent'] && $target == '_blank') || ($toolid && $row['target'] == '_blank')) echo 'selected="selected"'; ?>><?php echo get_lang('NewWindow'); ?></option>
  122. </select></td>
  123. </tr>
  124. <tr>
  125. <td>&nbsp;</td>
  126. <td><button type="submit" class="add" value="<?php echo get_lang('Ok'); ?>"><?php echo get_lang('AddLink'); ?></button></td>
  127. </tr>
  128. </table>
  129. <?php
  130. }
  131. Display::display_footer();
  132. ?>