online_links.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php // $Id: online_links.php 20467 2009-05-11 08:38:29Z ivantcholakov $
  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) Olivier Brouckaert
  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. * Management of links. When we click on a link, it opens in the right frame
  22. *
  23. * @author Olivier Brouckaert
  24. * @package dokeos.online
  25. ==============================================================================
  26. */
  27. define('FRAME','links');
  28. // name of the language file that needs to be included
  29. $language_file='chat';
  30. include('../inc/global.inc.php');
  31. $this_section=SECTION_COURSES;
  32. include_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  33. $action=$_GET['action'];
  34. $link=intval($_GET['link']);
  35. $tbl_user=Database::get_main_table(TABLE_MAIN_USER);
  36. $tbl_online_link=Database::get_course_table(TABLE_ONLINE_LINK);
  37. $query="SELECT username FROM $tbl_user WHERE user_id='".$_user['user_id']."'";
  38. $result=Database::query($query,__FILE__,__LINE__);
  39. list($pseudoUser)=Database::fetch_row($result);
  40. $isAllowed=(empty($pseudoUser) || !$_cid)?false:true;
  41. $isMaster=$is_courseAdmin?true:false;
  42. if(!$isAllowed || !$isMaster)
  43. {
  44. exit();
  45. }
  46. $doc_path=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  47. if($_POST['sent'])
  48. {
  49. $sent=1;
  50. $link_name=trim(stripslashes($_POST['link_name']));
  51. $link_url=trim(stripslashes($_POST['link_url']));
  52. $link_file=$_FILES['link_file'];
  53. if($link_file['size'])
  54. {
  55. if(empty($link_name))
  56. {
  57. $link_name=$link_file['name'];
  58. }
  59. $link_file['name']=php2phps(replace_dangerous_char($link_file['name'],'strict'));
  60. $extension=explode('.',$link_file['name']);
  61. $extension=$extension[sizeof($extension)-1];
  62. $suffix='';
  63. $i=0;
  64. do
  65. {
  66. if(file_exists($doc_path.str_replace('.'.$extension,$suffix.'.'.$extension,$link_file['name'])))
  67. {
  68. $suffix='_'.(++$i);
  69. }
  70. else
  71. {
  72. break;
  73. }
  74. }
  75. while(1);
  76. $link_file['name']=str_replace('.'.$extension,$suffix.'.'.$extension,$link_file['name']);
  77. move_uploaded_file($link_file['tmp_name'],$doc_path.$link_file['name']);
  78. $link_url=str_replace($_configuration['root_sys'],$_configuration['root_web'],$doc_path).$link_file['name'];
  79. }
  80. if(!empty($link_name) && !empty($link_url))
  81. {
  82. if(!strstr($link_url,'://'))
  83. {
  84. $link_url='http://'.$link_url;
  85. }
  86. if($action == 'edit')
  87. {
  88. $query="UPDATE $tbl_online_link
  89. SET name='".addslashes($link_name)."',
  90. url='".addslashes($link_url)."'
  91. WHERE id='$link'";
  92. Database::query($query,__FILE__,__LINE__);
  93. }
  94. else
  95. {
  96. $query="INSERT INTO $tbl_online_link (name,url) VALUES('".addslashes($link_name)."','".addslashes($link_url)."')";
  97. Database::query($query,__FILE__,__LINE__);
  98. }
  99. }
  100. mysql_close();
  101. header('Location: '.api_get_self());
  102. exit();
  103. }
  104. if($action == 'delete')
  105. {
  106. $link=intval($_GET['link']);
  107. $query="DELETE FROM $tbl_online_link WHERE id='$link'";
  108. Database::query($query,__FILE__,__LINE__);
  109. mysql_close();
  110. header('Location: '.api_get_self());
  111. exit();
  112. }
  113. $query="SELECT id,name,url FROM $tbl_online_link ORDER BY name";
  114. $result=Database::query($query,__FILE__,__LINE__);
  115. $Links=array();
  116. while($row=Database::fetch_array($result))
  117. {
  118. $Links[]=$row;
  119. if($action == 'edit' && $link == $row['id'])
  120. {
  121. $link_name=$row['name'];
  122. $link_url=$row['url'];
  123. }
  124. }
  125. if($action == 'edit' && empty($link_name))
  126. {
  127. $action='';
  128. $link=0;
  129. }
  130. include('header_frame.inc.php');
  131. ?>
  132. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  133. <tr>
  134. <td width="1%" valign="middle"><a href="online_master.php"><img src="../img/home.gif" border="0" alt="" title="<?php echo api_htmlentities(get_lang('Back'),ENT_QUOTES,$charset); ?>"></a></td>
  135. <td width="99%" align="left">&nbsp;<a href="online_master.php"><?php echo get_lang('Back'); ?></a></td>
  136. </tr>
  137. </table>
  138. <br>
  139. <form method="post" action="<?php echo api_get_self(); ?>?action=<?php echo $action; ?>&link=<?php echo $link; ?>" enctype="multipart/form-data">
  140. <input type="hidden" name="sent" value="1">
  141. <table border="0" cellpadding="3" cellspacing="0">
  142. <tr>
  143. <td width="45%"><?php echo get_lang('LinkName'); ?> :</td>
  144. <td width="55%"><input type="text" name="link_name" size="10" maxlength="50" value="<?php if($action == 'edit') echo api_htmlentities($link_name,ENT_QUOTES,$charset); ?>" style="width: 95px;"></td>
  145. </tr>
  146. <tr>
  147. <td width="45%"><?php echo get_lang('LinkURL'); ?> :</td>
  148. <td width="55%"><input type="text" name="link_url" size="10" maxlength="100" value="<?php if($action == 'edit') echo htmlentities($link_url); else echo 'http://'; ?>" style="width: 95px;"></td>
  149. </tr>
  150. <tr>
  151. <td width="45%"><?php echo get_lang('OrFile'); ?> :</td>
  152. <td width="55%"><input type="file" name="link_file" size="1" value="" style="width: 95px;"></td>
  153. </tr>
  154. <tr>
  155. <td colspan="2" align="center">
  156. <input type="submit" value="<?php echo api_htmlentities(' '.get_lang('Ok').' ',ENT_QUOTES,$charset); ?>">
  157. </td>
  158. </tr>
  159. </table>
  160. </form>
  161. <br>
  162. <?php
  163. if(!sizeof($Links))
  164. {
  165. echo get_lang('NoLinkAvailable');
  166. }
  167. else
  168. {
  169. ?>
  170. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  171. <?php
  172. foreach($Links as $enreg)
  173. {
  174. ?>
  175. <tr>
  176. <td width="98%"><a href="online_goto.php?url=<?php echo urlencode($enreg['url']); ?>" target="online_working_area"><?php echo $enreg['name']; ?></a></td>
  177. <td width="1%" valign="middle"><a href="<?php echo api_get_self(); ?>?action=edit&link=<?php echo $enreg['id']; ?>"><img src="../img/edit.gif" border="0" alt="" title="<?php echo api_htmlentities(get_lang('Modify'),ENT_QUOTES,$charset); ?>"></a></td>
  178. <td width="1%" valign="middle"><a href="<?php echo api_get_self(); ?>?action=delete&link=<?php echo $enreg['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)); ?>')) return false;"><img src="../img/delete.gif" border="0" alt="" title="<?php echo api_htmlentities(get_lang('Delete'),ENT_QUOTES,$charset); ?>"></a></td>
  179. </tr>
  180. <?php
  181. }
  182. unset($Links);
  183. ?>
  184. </table>
  185. <?php
  186. }
  187. include('footer_frame.inc.php');
  188. ?>