dokeos-online
[ class tree: dokeos-online ] [ index: dokeos-online ] [ all elements ]

Source for file online_links.php

Documentation is available at online_links.php

  1. <?php // $Id: online_links.php 13296 2007-09-27 02:19:40Z yannoo $
  2. /*
  3. ==============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2004 Dokeos S.A.
  7.     Copyright (c) 2003 Ghent University (UGent)
  8.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9.     Copyright (c) Olivier Brouckaert
  10.  
  11.     For a full list of contributors, see "credits.txt".
  12.     The full license can be read in "license.txt".
  13.  
  14.     This program is free software; you can redistribute it and/or
  15.     modify it under the terms of the GNU General Public License
  16.     as published by the Free Software Foundation; either version 2
  17.     of the License, or (at your option) any later version.
  18.  
  19.     See the GNU General Public License for more details.
  20.  
  21.     Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  22. ==============================================================================
  23. */
  24. /**
  25. ==============================================================================
  26. *    Management of links. When we click on a link, it opens in the right frame
  27. *
  28. *    @author Olivier Brouckaert
  29. *    @package dokeos.online
  30. ==============================================================================
  31. */
  32.  
  33. define('FRAME','links');
  34.  
  35. // name of the language file that needs to be included 
  36. $language_file='chat';
  37.  
  38. include('../inc/global.inc.php');
  39. $this_section=SECTION_COURSES;
  40.  
  41. include_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  42.  
  43. $action=$_GET['action'];
  44. $link=intval($_GET['link']);
  45.  
  46.  
  47. $query="SELECT username FROM $tbl_user WHERE user_id='".$_user['user_id']."'";
  48. $result=api_sql_query($query,__FILE__,__LINE__);
  49.  
  50. list($pseudoUser)=mysql_fetch_row($result);
  51.  
  52. $isAllowed=(empty($pseudoUser|| !$_cid)?false:true;
  53. $isMaster=$is_courseAdmin?true:false;
  54.  
  55. if(!$isAllowed || !$isMaster)
  56. {
  57.     exit();
  58. }
  59.  
  60. $doc_path=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  61.  
  62. if($_POST['sent'])
  63. {
  64.     $sent=1;
  65.  
  66.     $link_name=trim(stripslashes($_POST['link_name']));
  67.     $link_url=trim(stripslashes($_POST['link_url']));
  68.     $link_file=$_FILES['link_file'];
  69.  
  70.     if($link_file['size'])
  71.     {
  72.         if(empty($link_name))
  73.         {
  74.             $link_name=$link_file['name'];
  75.         }
  76.  
  77.         $link_file['name']=php2phps(replace_dangerous_char($link_file['name'],'strict'));
  78.  
  79.         $extension=explode('.',$link_file['name']);
  80.  
  81.         $extension=$extension[sizeof($extension)-1];
  82.  
  83.         $suffix='';
  84.         $i=0;
  85.  
  86.         do
  87.         {
  88.             if(file_exists($doc_path.str_replace('.'.$extension,$suffix.'.'.$extension,$link_file['name'])))
  89.             {
  90.                 $suffix='_'.(++$i);
  91.             }
  92.             else
  93.             {
  94.                 break;
  95.             }
  96.         }
  97.         while(1);
  98.  
  99.         $link_file['name']=str_replace('.'.$extension,$suffix.'.'.$extension,$link_file['name']);
  100.  
  101.         move_uploaded_file($link_file['tmp_name'],$doc_path.$link_file['name']);
  102.  
  103.         $link_url=str_replace($_configuration['root_sys'],$_configuration['root_web'],$doc_path).$link_file['name'];
  104.     }
  105.  
  106.     if(!empty($link_name&& !empty($link_url))
  107.     {
  108.         if(!strstr($link_url,'://'))
  109.         {
  110.             $link_url='http://'.$link_url;
  111.         }
  112.  
  113.         if($action == 'edit')
  114.         {
  115.             $query="UPDATE $tbl_online_link
  116.                     SET name='".addslashes($link_name)."',
  117.                         url='".addslashes($link_url)."'
  118.                     WHERE id='$link'";
  119.             api_sql_query($query,__FILE__,__LINE__);
  120.         }
  121.         else
  122.         {
  123.             $query="INSERT INTO $tbl_online_link (name,url) VALUES('".addslashes($link_name)."','".addslashes($link_url)."')";
  124.             api_sql_query($query,__FILE__,__LINE__);
  125.         }
  126.     }
  127.  
  128.     mysql_close();
  129.     header('Location: '.api_get_self());
  130.     exit();
  131. }
  132.  
  133. if($action == 'delete')
  134. {
  135.     $link=intval($_GET['link']);
  136.  
  137.     $query="DELETE FROM $tbl_online_link WHERE id='$link'";
  138.     api_sql_query($query,__FILE__,__LINE__);
  139.  
  140.     mysql_close();
  141.     header('Location: '.api_get_self());
  142.     exit();
  143. }
  144.  
  145. $query="SELECT id,name,url FROM $tbl_online_link ORDER BY name";
  146. $result=api_sql_query($query,__FILE__,__LINE__);
  147.  
  148. $Links=array();
  149.  
  150. while($row=mysql_fetch_array($result))
  151. {
  152.     $Links[]=$row;
  153.  
  154.     if($action == 'edit' && $link == $row['id'])
  155.     {
  156.         $link_name=$row['name'];
  157.         $link_url=$row['url'];
  158.     }
  159. }
  160.  
  161. if($action == 'edit' && empty($link_name))
  162. {
  163.     $action='';
  164.     $link=0;
  165. }
  166.  
  167. include('header_frame.inc.php');
  168. ?>
  169.  
  170. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  171. <tr>
  172.   <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'),ENT_QUOTES,$charset)?>"></a></td>
  173.   <td width="99%" align="left">&nbsp;<a href="online_master.php"><?php echo get_lang('Back')?></a></td>
  174. </tr>
  175. </table>
  176.  
  177. <br>
  178.  
  179. <form method="post" action="<?php echo api_get_self()?>?action=<?php echo $action?>&link=<?php echo $link?>" enctype="multipart/form-data">
  180. <input type="hidden" name="sent" value="1">
  181. <table border="0" cellpadding="3" cellspacing="0">
  182. <tr>
  183.   <td width="45%"><?php echo get_lang('LinkName')?> :</td>
  184.   <td width="55%"><input type="text" name="link_name" size="10" maxlength="50" value="<?php if($action == 'edit'echo htmlentities($link_name,ENT_QUOTES,$charset)?>" style="width: 95px;"></td>
  185. </tr>
  186. <tr>
  187.   <td width="45%"><?php echo get_lang('LinkURL')?> :</td>
  188.   <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>
  189. </tr>
  190. <tr>
  191.   <td width="45%"><?php echo get_lang('OrFile')?> :</td>
  192.   <td width="55%"><input type="file" name="link_file" size="1" value="" style="width: 95px;"></td>
  193. </tr>
  194. <tr>
  195.   <td colspan="2" align="center">
  196.     <input type="submit" value="<?php echo htmlentities(get_lang('Ok'),ENT_QUOTES,$charset)?>">
  197.   </td>
  198. </tr>
  199. </table>
  200. </form>
  201.  
  202. <br>
  203.  
  204. <?php
  205. if(!sizeof($Links))
  206. {
  207.     echo get_lang('NoLinkAvailable');
  208. }
  209. else
  210. {
  211. ?>
  212.  
  213. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  214.  
  215. <?php
  216.     foreach($Links as $enreg)
  217.     {
  218. ?>
  219.  
  220. <tr>
  221.   <td width="98%"><a href="online_goto.php?url=<?php echo urlencode($enreg['url'])?>" target="online_working_area"><?php echo $enreg['name']?></a></td>
  222.   <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 htmlentities(get_lang('Modify'),ENT_QUOTES,$charset)?>"></a></td>
  223.   <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(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset))?>')) return false;"><img src="../img/delete.gif" border="0" alt="" title="<?php echo htmlentities(get_lang('Delete'),ENT_QUOTES,$charset)?>"></a></td>
  224. </tr>
  225.  
  226. <?php
  227.     }
  228.  
  229.     unset($Links);
  230. ?>
  231.  
  232. </table>
  233.  
  234. <?php
  235. }
  236.  
  237. include('footer_frame.inc.php');
  238. ?>

Documentation generated on Thu, 12 Jun 2008 14:08:29 -0500 by phpDocumentor 1.4.1