Dokeos PHP Cross Reference Learning Management Systems

Source: /main/online/online_links.php - 240 lines - 6817 bytes - Summary - Text - Print

Description: Management of links. When we click on a link, it opens in the right frame

   1  <?php // $Id: online_links.php 20467 2009-05-11 08:38:29Z ivantcholakov $
   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  $tbl_user=Database::get_main_table(TABLE_MAIN_USER);
  47  $tbl_online_link=Database::get_course_table(TABLE_ONLINE_LINK);
  48  
  49  $query="SELECT username FROM $tbl_user WHERE user_id='".$_user['user_id']."'";
  50  $result=Database::query($query,__FILE__,__LINE__);
  51  
  52  list($pseudoUser)=Database::fetch_row($result);
  53  
  54  $isAllowed=(empty($pseudoUser) || !$_cid)?false:true;
  55  $isMaster=$is_courseAdmin?true:false;
  56  
  57  if(!$isAllowed || !$isMaster)
  58  {
  59      exit();
  60  }
  61  
  62  $doc_path=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  63  
  64  if($_POST['sent'])
  65  {
  66      $sent=1;
  67  
  68      $link_name=trim(stripslashes($_POST['link_name']));
  69      $link_url=trim(stripslashes($_POST['link_url']));
  70      $link_file=$_FILES['link_file'];
  71  
  72      if($link_file['size'])
  73      {
  74          if(empty($link_name))
  75          {
  76              $link_name=$link_file['name'];
  77          }
  78  
  79          $link_file['name']=php2phps(replace_dangerous_char($link_file['name'],'strict'));
  80  
  81          $extension=explode('.',$link_file['name']);
  82  
  83          $extension=$extension[sizeof($extension)-1];
  84  
  85          $suffix='';
  86          $i=0;
  87  
  88          do
  89          {
  90              if(file_exists($doc_path.str_replace('.'.$extension,$suffix.'.'.$extension,$link_file['name'])))
  91              {
  92                  $suffix='_'.(++$i);
  93              }
  94              else
  95              {
  96                  break;
  97              }
  98          }
  99          while(1);
 100  
 101          $link_file['name']=str_replace('.'.$extension,$suffix.'.'.$extension,$link_file['name']);
 102  
 103          move_uploaded_file($link_file['tmp_name'],$doc_path.$link_file['name']);
 104  
 105          $link_url=str_replace($_configuration['root_sys'],$_configuration['root_web'],$doc_path).$link_file['name'];
 106      }
 107  
 108      if(!empty($link_name) && !empty($link_url))
 109      {
 110          if(!strstr($link_url,'://'))
 111          {
 112              $link_url='http://'.$link_url;
 113          }
 114  
 115          if($action == 'edit')
 116          {
 117              $query="UPDATE $tbl_online_link
 118                      SET name='".addslashes($link_name)."',
 119                          url='".addslashes($link_url)."'
 120                      WHERE id='$link'";
 121              Database::query($query,__FILE__,__LINE__);
 122          }
 123          else
 124          {
 125              $query="INSERT INTO $tbl_online_link (name,url) VALUES('".addslashes($link_name)."','".addslashes($link_url)."')";
 126              Database::query($query,__FILE__,__LINE__);
 127          }
 128      }
 129  
 130      mysql_close();
 131      header('Location: '.api_get_self());
 132      exit();
 133  }
 134  
 135  if($action == 'delete')
 136  {
 137      $link=intval($_GET['link']);
 138  
 139      $query="DELETE FROM $tbl_online_link WHERE id='$link'";
 140      Database::query($query,__FILE__,__LINE__);
 141  
 142      mysql_close();
 143      header('Location: '.api_get_self());
 144      exit();
 145  }
 146  
 147  $query="SELECT id,name,url FROM $tbl_online_link ORDER BY name";
 148  $result=Database::query($query,__FILE__,__LINE__);
 149  
 150  $Links=array();
 151  
 152  while($row=Database::fetch_array($result))
 153  {
 154      $Links[]=$row;
 155  
 156      if($action == 'edit' && $link == $row['id'])
 157      {
 158          $link_name=$row['name'];
 159          $link_url=$row['url'];
 160      }
 161  }
 162  
 163  if($action == 'edit' && empty($link_name))
 164  {
 165      $action='';
 166      $link=0;
 167  }
 168  
 169  include ('header_frame.inc.php');
 170  ?>
 171  
 172  <table border="0" cellpadding="0" cellspacing="0" width="100%">
 173  <tr>
 174    <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>
 175    <td width="99%" align="left">&nbsp;<a href="online_master.php"><?php echo get_lang('Back'); ?></a></td>
 176  </tr>
 177  </table>
 178  
 179  <br>
 180  
 181  <form method="post" action="<?php echo api_get_self(); ?>?action=<?php echo $action; ?>&link=<?php echo $link; ?>" enctype="multipart/form-data">
 182  <input type="hidden" name="sent" value="1">
 183  <table border="0" cellpadding="3" cellspacing="0">
 184  <tr>
 185    <td width="45%"><?php echo get_lang('LinkName'); ?> :</td>
 186    <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>
 187  </tr>
 188  <tr>
 189    <td width="45%"><?php echo get_lang('LinkURL'); ?> :</td>
 190    <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>
 191  </tr>
 192  <tr>
 193    <td width="45%"><?php echo get_lang('OrFile'); ?> :</td>
 194    <td width="55%"><input type="file" name="link_file" size="1" value="" style="width: 95px;"></td>
 195  </tr>
 196  <tr>
 197    <td colspan="2" align="center">
 198      <input type="submit" value="<?php echo api_htmlentities('  '.get_lang('Ok').'  ',ENT_QUOTES,$charset); ?>">
 199    </td>
 200  </tr>
 201  </table>
 202  </form>
 203  
 204  <br>
 205  
 206  <?php
 207  if(!sizeof($Links))
 208  {
 209      echo get_lang('NoLinkAvailable');
 210  }
 211  else
 212  {
 213  ?>
 214  
 215  <table border="0" cellpadding="0" cellspacing="0" width="100%">
 216  
 217  <?php
 218      foreach($Links as $enreg)
 219      {
 220  ?>
 221  
 222  <tr>
 223    <td width="98%"><a href="online_goto.php?url=<?php echo urlencode($enreg['url']); ?>" target="online_working_area"><?php echo $enreg['name']; ?></a></td>
 224    <td width="1%" valign="middle"><a href="<?php echo api_get_self(); ?>?action=edit&link=<?php echo $enreg['id']; ?>"><img src="../img/edit.png" border="0" alt="" title="<?php echo api_htmlentities(get_lang('Modify'),ENT_QUOTES,$charset); ?>"></a></td>
 225    <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.png" border="0" alt="" title="<?php echo api_htmlentities(get_lang('Delete'),ENT_QUOTES,$charset); ?>"></a></td>
 226  </tr>
 227  
 228  <?php
 229      }
 230  
 231      unset($Links);
 232  ?>
 233  
 234  </table>
 235  
 236  <?php
 237  }
 238  
 239  include ('footer_frame.inc.php');
 240  ?>

title

Description

title

Description

title

Description

title

title

Body