home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / cms / browse.php < prev    next >
Encoding:
PHP Script  |  2004-03-08  |  6.6 KB  |  247 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. require("../../Group-Office.php");
  14. require($GO_CONFIG->class_path.'cms.class.inc');
  15. $cms = new cms();
  16.  
  17. //authenticate the user
  18. $GO_SECURITY->authenticate();
  19.  
  20. //see if the user has access to this module
  21. //for this to work there must be a module named 'example'
  22. $GO_MODULES->authenticate('cms');
  23.  
  24. //get the language file
  25. require($GO_LANGUAGE->get_language_file('cms'));
  26.  
  27. //remember sorting in cookie
  28. if (isset($_REQUEST['newsort']))
  29. {
  30.     SetCookie("cms_sort",$_REQUEST['newsort'],time()+3600*24*365,"/","",0);
  31.     $_COOKIE['cms_sort'] = $_REQUEST['newsort'];
  32. }
  33. if (isset($_REQUEST['newdirection']))
  34. {
  35.     SetCookie("cms_direction",$_REQUEST['newdirection'],time()+3600*24*365,"/","",0);
  36.     $_COOKIE['cms_direction'] = $_REQUEST['newdirection'];
  37. }
  38.  
  39. $site_id = isset($_REQUEST['site_id']) ? $_REQUEST['site_id'] : 0;
  40.  
  41. if(!$site = $cms->get_site($site_id))
  42. {
  43.     header('Location: index.php');
  44. }
  45.  
  46. if (!$GO_SECURITY->has_permission($GO_SECURITY->user_id, $site['acl_write']))
  47. {
  48.     require($GO_THEME->theme_path."header.inc");
  49.     require($GO_CONFIG->root_path.'error_docs/403.inc');
  50.     require($GO_THEME->theme_path."footer.inc");
  51.     exit();
  52.  
  53. }
  54.  
  55. //set the folder id we are in
  56. $folder_id = isset($_REQUEST['folder_id']) ? $_REQUEST['folder_id'] : $site['root_folder_id'];
  57.  
  58. $link_back = $GO_MODULES->url.'browse.php?site_id='.$site_id.'&folder_id='.$folder_id;
  59.  
  60. //what to do before output
  61. $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
  62. switch ($task)
  63. {
  64.     case 'upload':
  65.         if ($_SERVER['REQUEST_METHOD'] == 'POST')
  66.         {
  67.             $task = 'list';
  68.             if (isset($_FILES['file']))
  69.             {
  70.                 require_once($GO_CONFIG->class_path.'filetypes.class.inc');
  71.                 $filetypes = new filetypes();
  72.                 for ($i=0;$i<count($_FILES['file']);$i++)
  73.                 {
  74.                     if (is_uploaded_file($_FILES['file']['tmp_name'][$i]))
  75.                     {
  76.                         $extension = get_extension($_FILES['file']['name'][$i]);
  77.                         if (!$filetypes->get_type($extension))
  78.                         {
  79.                             $filetypes->add_type($extension, $_FILES['file']['type'][$i]);
  80.                         }
  81.  
  82.                         $name = $_FILES['file']['name'][$i];
  83.                         $x=0;
  84.                         while ($cms->file_exists($folder_id, $name))
  85.                         {
  86.                             $x++;
  87.                             $name = strip_extension($_FILES['file']['name'][$i]).' ('.$x.').'.get_extension($_FILES['file']['name'][$i]);
  88.                         }
  89.  
  90.                         $fp = fopen($_FILES['file']['tmp_name'][$i], 'r');
  91.                         $content = addslashes(fread($fp, $_FILES['file']['size'][$i]));
  92.                         fclose($fp);
  93.                         if (eregi('htm', get_extension($name)))
  94.                         {
  95.                             $content = $cms->get_body($content);
  96.                         }
  97.                         $file_id = $cms->add_file($folder_id, $name, $content);
  98.                         unlink($_FILES['file']['tmp_name'][$i]);
  99.                     }
  100.                 }
  101.             }
  102.         }
  103.     break;
  104.  
  105.     case 'add_folder':
  106.         if($_SERVER['REQUEST_METHOD'] == 'POST')
  107.         {
  108.             $name = trim($_POST['name']);
  109.             if ($name == '')
  110.             {
  111.                 $feedback = '<p class="Error">'.$error_missing_field;
  112.             }elseif($cms->folder_exists($folder_id, $name))
  113.             {
  114.                 $feedback = '<p class="Error">Mapnaam bestaat al</p>';
  115.             }elseif(!$cms->add_folder($folder_id, $name, $_POST['priority']))
  116.             {
  117.                 $feedback = '<p class="Error">'.$strSaveError.'</p>';
  118.             }else
  119.             {
  120.                 $task = '';
  121.             }
  122.         }
  123.     break;
  124.  
  125.     case 'delete':
  126.         if (isset($_POST['files']))
  127.         {
  128.             for ($i=0;$i<count($_POST['files']);$i++)
  129.             {
  130.                 $cms->delete_file($_POST['files'][$i]);
  131.             }
  132.         }
  133.  
  134.         if (isset($_POST['folders']))
  135.         {
  136.             for ($i=0;$i<count($_POST['folders']);$i++)
  137.             {
  138.                 $cms->delete_folder($_POST['folders'][$i]);
  139.             }
  140.         }
  141.     break;
  142.  
  143.     case  'cut':
  144.         $_SESSION['cut_files'] = isset($_POST['files']) ? $_POST['files'] : array();
  145.         $_SESSION['cut_folders'] = isset($_POST['folders']) ? $_POST['folders'] : array();
  146.         $_SESSION['copy_folders'] = array();
  147.         $_SESSION['copy_files'] = array();
  148.         $task = '';
  149.     break;
  150.  
  151.     case 'copy':
  152.         $_SESSION['copy_files'] = isset($_POST['files']) ? $_POST['files'] : array();
  153.         $_SESSION['copy_folders'] = isset($_POST['folders']) ? $_POST['folders'] : array();
  154.         $_SESSION['cut_folders'] = array();
  155.         $_SESSION['cut_files'] = array();
  156.         $task = '';
  157.     break;
  158.  
  159.     case 'paste':
  160.         while ($file = smartstrip(array_shift($_SESSION['cut_files'] )))
  161.         {
  162.             $cms->move_file($file, $folder_id);
  163.         }
  164.         while ($file = smartstrip(array_shift($_SESSION['copy_files'])))
  165.         {
  166.             $cms->copy_file($file, $folder_id);
  167.         }
  168.         while ($folder = smartstrip(array_shift($_SESSION['cut_folders'])))
  169.         {
  170.             $cms->move_folder($folder, $folder_id);
  171.         }
  172.         while ($folder = smartstrip(array_shift($_SESSION['copy_folders'])))
  173.         {
  174.             $cms->copy_folder($folder, $folder_id);
  175.         }
  176.     break;
  177.  
  178.     case 'save_file_properties':
  179.         $task = 'file_properties';
  180.         $name = trim($_POST['name']);
  181.         if ($name == '')
  182.         {
  183.             $feedback = '<p class="Error">'.$error_missing_field.'</p>';
  184.         }else
  185.         {
  186.             if ($_POST['extension'] != '')
  187.             {
  188.                 $name = $name.'.'.$_POST['extension'];
  189.             }
  190.             $existing_id = $cms->file_exists($folder_id, $name);
  191.             if($existing_id && ($_POST['file_id'] != $existing_id))
  192.             {
  193.                 $feedback = '<p class="Error">'.$fbNameExists.'</p>';
  194.             }elseif(!$file=$cms->get_file($_POST['file_id']))
  195.             {
  196.                 $feedback = '<p class="Error">'.$strSaveError.'</p>';
  197.             }else
  198.             {
  199.                 if (!$cms->update_file($_POST['file_id'], $name, addslashes($file['content']), $_POST['title'], $_POST['description'], $_POST['keywords'], $_POST['priority']))
  200.                 {
  201.                     $feedback = '<p class="Error">'.$strSaveError.'</p>';
  202.                 }else
  203.                 {
  204.                     if($_POST['close'] == 'true')
  205.                     {
  206.                         if($_POST['return'] == 'edit')
  207.                         {
  208.                             header('Location: edit.php?site_id='.$site_id.'&file_id='.$_POST['file_id'].'&folder_id='.$folder_id);
  209.                             exit();
  210.                         }else
  211.                         {
  212.                             $task = '';
  213.                             $folder_id = $_POST['return'];
  214.                         }
  215.                     }
  216.                 }
  217.             }
  218.         }
  219.     break;
  220. }
  221.  
  222. //set the page title for the header file
  223. $page_title = $lang_modules['cms'];
  224.  
  225. //require the header file. This will draw the logo's and the menu
  226. require($GO_THEME->theme_path."header.inc");
  227. echo '<form name="cms" method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">';
  228. echo '<input type="hidden" name="site_id" value="'.$site_id.'" />';
  229. switch ($task)
  230. {
  231.     case 'upload':
  232.         require('upload.inc');
  233.     break;
  234.  
  235.     case 'add_folder':
  236.         require('add_folder.inc');
  237.     break;
  238.  
  239.     default:
  240.         require('files.inc');
  241.     break;
  242. }
  243. echo '</form>';
  244.  
  245. require($GO_THEME->theme_path."footer.inc");
  246. ?>
  247.