online_links.php 6.4 KB

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