home *** CD-ROM | disk | FTP | other *** search
- <?php
- /*
- Copyright Intermesh 2003
- Author: Merijn Schering <mschering@intermesh.nl>
- Version: 1.0 Release date: 08 July 2003
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 2 of the License, or (at your
- option) any later version.
- */
-
- require("../../Group-Office.php");
- require($GO_CONFIG->class_path.'cms.class.inc');
- $cms = new cms();
-
- //authenticate the user
- $GO_SECURITY->authenticate();
-
- //see if the user has access to this module
- //for this to work there must be a module named 'example'
- $GO_MODULES->authenticate('cms');
-
- //get the language file
- require($GO_LANGUAGE->get_language_file('cms'));
-
- //remember sorting in cookie
- if (isset($_REQUEST['newsort']))
- {
- SetCookie("cms_sort",$_REQUEST['newsort'],time()+3600*24*365,"/","",0);
- $_COOKIE['cms_sort'] = $_REQUEST['newsort'];
- }
- if (isset($_REQUEST['newdirection']))
- {
- SetCookie("cms_direction",$_REQUEST['newdirection'],time()+3600*24*365,"/","",0);
- $_COOKIE['cms_direction'] = $_REQUEST['newdirection'];
- }
-
- $site_id = isset($_REQUEST['site_id']) ? $_REQUEST['site_id'] : 0;
-
- if(!$site = $cms->get_site($site_id))
- {
- header('Location: index.php');
- }
-
- if (!$GO_SECURITY->has_permission($GO_SECURITY->user_id, $site['acl_write']))
- {
- require($GO_THEME->theme_path."header.inc");
- require($GO_CONFIG->root_path.'error_docs/403.inc');
- require($GO_THEME->theme_path."footer.inc");
- exit();
-
- }
-
- //set the folder id we are in
- $folder_id = isset($_REQUEST['folder_id']) ? $_REQUEST['folder_id'] : $site['root_folder_id'];
-
- $link_back = $GO_MODULES->url.'browse.php?site_id='.$site_id.'&folder_id='.$folder_id;
-
- //what to do before output
- $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
- switch ($task)
- {
- case 'upload':
- if ($_SERVER['REQUEST_METHOD'] == 'POST')
- {
- $task = 'list';
- if (isset($_FILES['file']))
- {
- require_once($GO_CONFIG->class_path.'filetypes.class.inc');
- $filetypes = new filetypes();
- for ($i=0;$i<count($_FILES['file']);$i++)
- {
- if (is_uploaded_file($_FILES['file']['tmp_name'][$i]))
- {
- $extension = get_extension($_FILES['file']['name'][$i]);
- if (!$filetypes->get_type($extension))
- {
- $filetypes->add_type($extension, $_FILES['file']['type'][$i]);
- }
-
- $name = $_FILES['file']['name'][$i];
- $x=0;
- while ($cms->file_exists($folder_id, $name))
- {
- $x++;
- $name = strip_extension($_FILES['file']['name'][$i]).' ('.$x.').'.get_extension($_FILES['file']['name'][$i]);
- }
-
- $fp = fopen($_FILES['file']['tmp_name'][$i], 'r');
- $content = addslashes(fread($fp, $_FILES['file']['size'][$i]));
- fclose($fp);
- if (eregi('htm', get_extension($name)))
- {
- $content = $cms->get_body($content);
- }
- $file_id = $cms->add_file($folder_id, $name, $content);
- unlink($_FILES['file']['tmp_name'][$i]);
- }
- }
- }
- }
- break;
-
- case 'add_folder':
- if($_SERVER['REQUEST_METHOD'] == 'POST')
- {
- $name = trim($_POST['name']);
- if ($name == '')
- {
- $feedback = '<p class="Error">'.$error_missing_field;
- }elseif($cms->folder_exists($folder_id, $name))
- {
- $feedback = '<p class="Error">Mapnaam bestaat al</p>';
- }elseif(!$cms->add_folder($folder_id, $name, $_POST['priority']))
- {
- $feedback = '<p class="Error">'.$strSaveError.'</p>';
- }else
- {
- $task = '';
- }
- }
- break;
-
- case 'delete':
- if (isset($_POST['files']))
- {
- for ($i=0;$i<count($_POST['files']);$i++)
- {
- $cms->delete_file($_POST['files'][$i]);
- }
- }
-
- if (isset($_POST['folders']))
- {
- for ($i=0;$i<count($_POST['folders']);$i++)
- {
- $cms->delete_folder($_POST['folders'][$i]);
- }
- }
- break;
-
- case 'cut':
- $_SESSION['cut_files'] = isset($_POST['files']) ? $_POST['files'] : array();
- $_SESSION['cut_folders'] = isset($_POST['folders']) ? $_POST['folders'] : array();
- $_SESSION['copy_folders'] = array();
- $_SESSION['copy_files'] = array();
- $task = '';
- break;
-
- case 'copy':
- $_SESSION['copy_files'] = isset($_POST['files']) ? $_POST['files'] : array();
- $_SESSION['copy_folders'] = isset($_POST['folders']) ? $_POST['folders'] : array();
- $_SESSION['cut_folders'] = array();
- $_SESSION['cut_files'] = array();
- $task = '';
- break;
-
- case 'paste':
- while ($file = smartstrip(array_shift($_SESSION['cut_files'] )))
- {
- $cms->move_file($file, $folder_id);
- }
- while ($file = smartstrip(array_shift($_SESSION['copy_files'])))
- {
- $cms->copy_file($file, $folder_id);
- }
- while ($folder = smartstrip(array_shift($_SESSION['cut_folders'])))
- {
- $cms->move_folder($folder, $folder_id);
- }
- while ($folder = smartstrip(array_shift($_SESSION['copy_folders'])))
- {
- $cms->copy_folder($folder, $folder_id);
- }
- break;
-
- case 'save_file_properties':
- $task = 'file_properties';
- $name = trim($_POST['name']);
- if ($name == '')
- {
- $feedback = '<p class="Error">'.$error_missing_field.'</p>';
- }else
- {
- if ($_POST['extension'] != '')
- {
- $name = $name.'.'.$_POST['extension'];
- }
- $existing_id = $cms->file_exists($folder_id, $name);
- if($existing_id && ($_POST['file_id'] != $existing_id))
- {
- $feedback = '<p class="Error">'.$fbNameExists.'</p>';
- }elseif(!$file=$cms->get_file($_POST['file_id']))
- {
- $feedback = '<p class="Error">'.$strSaveError.'</p>';
- }else
- {
- if (!$cms->update_file($_POST['file_id'], $name, addslashes($file['content']), $_POST['title'], $_POST['description'], $_POST['keywords'], $_POST['priority']))
- {
- $feedback = '<p class="Error">'.$strSaveError.'</p>';
- }else
- {
- if($_POST['close'] == 'true')
- {
- if($_POST['return'] == 'edit')
- {
- header('Location: edit.php?site_id='.$site_id.'&file_id='.$_POST['file_id'].'&folder_id='.$folder_id);
- exit();
- }else
- {
- $task = '';
- $folder_id = $_POST['return'];
- }
- }
- }
- }
- }
- break;
- }
-
- //set the page title for the header file
- $page_title = $lang_modules['cms'];
-
- //require the header file. This will draw the logo's and the menu
- require($GO_THEME->theme_path."header.inc");
- echo '<form name="cms" method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">';
- echo '<input type="hidden" name="site_id" value="'.$site_id.'" />';
- switch ($task)
- {
- case 'upload':
- require('upload.inc');
- break;
-
- case 'add_folder':
- require('add_folder.inc');
- break;
-
- default:
- require('files.inc');
- break;
- }
- echo '</form>';
-
- require($GO_THEME->theme_path."footer.inc");
- ?>
-