external_module.php 4.7 KB

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