home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / cms / edit.php < prev    next >
PHP Script  |  2004-03-08  |  7KB  |  194 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. require_once($GO_CONFIG->class_path.'filetypes.class.inc');
  16.  
  17. $filetypes = new filetypes();
  18. $cms = new cms();
  19.  
  20. //authenticate the user
  21. $GO_SECURITY->authenticate();
  22.  
  23. //see if the user has access to this module
  24. //for this to work there must be a module named 'example'
  25. $GO_MODULES->authenticate('cms');
  26.  
  27. //get the language file
  28. require($GO_LANGUAGE->get_language_file('cms'));
  29.  
  30. $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
  31. $file_id = isset($_REQUEST['file_id']) ? $_REQUEST['file_id'] : 0;
  32. $folder_id = isset($_REQUEST['folder_id']) ? $_REQUEST['folder_id'] : 0;
  33. $site_id = isset($_REQUEST['site_id']) ? $_REQUEST['site_id'] : 0;
  34.  
  35. if ($folder_id == 0 || $site_id == 0)
  36. {
  37.     //no folder or site given so back off cowardly
  38.     header('Location: index.php');
  39.     exit();
  40. }
  41.  
  42.  
  43.  
  44. if($task=='save')
  45. {
  46.     if ($file_id > 0)
  47.     {
  48.         $cms->update_file($file_id, $_POST['name'], smart_addslashes($_POST['content']), $_POST['title'], $_POST['description'], $_POST['keywords'], $_POST['priority']);
  49.     }else
  50.     {
  51.         $name = trim($_POST['name']);
  52.         if ($name == '')
  53.         {
  54.             $feedback = '<p class="Error">'.$error_missing_field.'</p>';
  55.         }else
  56.         {
  57.             $filename = $name.'.html';
  58.  
  59.             if($cms->file_exists($folder_id, $filename))
  60.             {
  61.                 $feedback = '<p class="Error">'.$fbNameExists.'</p>';
  62.             }elseif(!$file_id = $cms->add_file($folder_id, $filename, $_POST['content'], '', '', '', $_POST['priority']))
  63.             {
  64.                 $feedback = '<p class="Error">'.$strSaveError.'</p>';
  65.             }
  66.         }
  67.     }
  68. }
  69.  
  70. if ($file_id > 0)
  71. {
  72.     $file = $cms->get_file($file_id);
  73.     $content = $file['content'];
  74.     $name= $file['name'];
  75.     $title = $file['title'];
  76.     $description = $file['description'];
  77.     $keywords = $file['keywords'];
  78.     $priority = $file['priority'];
  79. }else
  80. {
  81.     require($GO_THEME->theme_path."header.inc");
  82.     require("add_file.inc");
  83.     require($GO_THEME->theme_path."footer.inc");
  84.     exit();
  85. }
  86.  
  87. $link_back = 'edit.php?site_id='.$site_id.'&file_id='.$file_id.'&folder_id='.$folder_id;
  88.  
  89. if ($task == 'clean_formatting')
  90. {
  91.     $content = $cms->clean_up_html($content);
  92. }
  93.  
  94. //set the page title for the header file
  95. $page_title = $lang_modules['cms'];
  96.  
  97. //get the site template
  98. if($site = $cms->get_site($site_id))
  99. {
  100.     $template = $cms->get_template($site['template_id']);
  101. }
  102.  
  103. $pagestyle = (isset($template)) ? $template['style'] : '';
  104. $pagestyle = str_replace("\r", '', $pagestyle);
  105. $pagestyle = str_replace("\n", '', $pagestyle);
  106. $pagestyle = str_replace("\t", '', $pagestyle);
  107. $pagestyle = str_replace("'", '"', $pagestyle);
  108. $pagestyle = str_replace(' ', '', $pagestyle);
  109.  
  110. //create htmlarea
  111. $htmlarea = new htmlarea();
  112. if ($fs_module = $GO_MODULES->get_module('filesystem'))
  113. {
  114.     if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $fs_module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $fs_module['acl_write']))
  115.     {
  116.         $htmlarea->add_button('insert', $cms_insert_file, $GO_CONFIG->control_url.'htmlarea/images/binary.png', 'false', "function insertObject()
  117.         {
  118.             popup('select.php?site_id=".$site_id."', '600', '400');
  119.         }");
  120.  
  121.     }
  122. }
  123. $GO_HEADER['head'] = $htmlarea->get_header('content', -70, -125, 25, $pagestyle, 'config.baseURL="";');
  124. $GO_HEADER['body_arguments'] = 'onload="initEditor()"';
  125.  
  126. //require the header file. This will draw the logo's and the menu
  127. require($GO_THEME->theme_path."header.inc");
  128.  
  129. //echo '<table border="0" cellpadding="10" cellspacing="0"><tr><td>';
  130. if (isset($feedback)) echo $feedback;
  131. echo '<form method="post" name="editor" action="'.$_SERVER['PHP_SELF'].'">';
  132. echo '<input type="hidden" name="site_id" value="'.$site_id.'" />';
  133. echo '<input type="hidden" name="file_id" value="'.$file_id.'" />';
  134. echo '<input type="hidden" name="folder_id" value="'.$folder_id.'" />';
  135. echo '<input type="hidden" name="old_name" value="'.$name.'" />';
  136. echo '<input type="hidden" name="title" value="'.$title.'" />';
  137. echo '<input type="hidden" name="description" value="'.$description.'" />';
  138. echo '<input type="hidden" name="keywords" value="'.$keywords.'" />';
  139. echo '<input type="hidden" name="priority" value="'.$priority.'" />';
  140. echo '<input type="hidden" name="unedited" value = "" />';
  141. echo '<input type="hidden" name="task" value="save" />';
  142. echo '<input type="hidden" name="name" value="'.$name.'" />';
  143.  
  144. echo '<table border="0">';
  145. echo '<td class="ModuleIcons" nowrap>';
  146. echo '<a href="javascript:document.editor.onsubmit();document.editor.submit();"><img src="'.$GO_THEME->images['save_big'].'" border="0" height="32" width="32" /><br />'.$cmdSave.'</a></td>';
  147. if ($file_id >0)
  148. {
  149.     echo '<td class="ModuleIcons"  nowrap>';
  150.     echo '<a class="small" href="properties.php?site_id='.$site_id.'&task=file_properties&file_id='.$file_id.'&return_to='.urlencode($link_back).'&folder_id='.$folder_id.'"><img src="'.$GO_THEME->images['properties'].'" border="0" height="32" width="32" /><br />'.$fbProperties.'</a></td>';
  151.  
  152.     echo '<td class="ModuleIcons" nowrap>';
  153.     echo '<a class="small" target="_blank" href="view.php?site_id='.$site_id.'&folder_id='.$folder_id.'&file_id='.$file_id.'" title="'.$cms_preview.' \''.$name.'\'"><img src="'.$GO_THEME->images['magnifier_big'].'" border="0" /><br />'.$cms_preview.'</a></td>';
  154. }
  155. echo '<td class="ModuleIcons"  nowrap>';
  156. echo '<a class="small" href="javascript:confirm_close(\''.$GO_CONFIG->host.$GO_MODULES->path.'browse.php?site_id='.$site_id.'&folder_id='.$folder_id.'\')"><img src="'.$GO_THEME->images['close'].'" border="0" height="32" width="32" /><br />'.$cmdClose.'</a></td>';
  157.  
  158.  
  159. echo '<td class="ModuleIcons" nowrap>';
  160. echo '<a class="small" href=\'javascript:clean_formatting()\'><img src="'.$GO_THEME->images['filters'].'" border="0" height="32" width="32" /><br />Cleanup</a></td>';
  161. echo '</table>';
  162.  
  163. $tabtable = new tabtable('cms_edit', $name);
  164. $tabtable->print_head();
  165. $htmlarea->print_htmlarea($content);
  166. $tabtable->print_foot();
  167.  
  168. echo '</form>';
  169. ?>
  170. <script type="text/javascript">
  171. function clean_formatting()
  172. {
  173.     document.forms[0].task.value='clean_formatting';
  174.     document.forms[0].onsubmit();
  175.     document.forms[0].submit();
  176. }
  177.  
  178. function confirm_close(URL)
  179. {
  180.     //TODO: detect if content has been changed
  181.     //if (confirm('<?php echo $cms_confirm_close; ?>'))
  182.     //{
  183.         document.location=URL;
  184.     //}
  185. }
  186.  
  187. </script>
  188.  
  189. <?php
  190. require($GO_THEME->theme_path."footer.inc");
  191. ?>
  192.  
  193.  
  194.