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 >
Encoding:
PHP Script  |  2004-03-08  |  6.6 KB  |  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.  
  45. if($task=='save')
  46. {
  47.     if ($file_id > 0)
  48.     {
  49.         $cms->update_file($file_id, $_POST['name'], smart_addslashes($_POST['content']), $_POST['title'], $_POST['description'], $_POST['keywords'], $_POST['priority']);
  50.     }else
  51.     {
  52.         $name = trim($_POST['name']);
  53.         if ($name == '')
  54.         {
  55.             $feedback = '<p class="Error">'.$error_missing_field.'</p>';
  56.         }else
  57.         {
  58.             $filename = $name.'.html';
  59.  
  60.             if($cms->file_exists($folder_id, $filename))
  61.             {
  62.                 $feedback = '<p class="Error">'.$fbNameExists.'</p>';
  63.             }elseif(!$file_id = $cms->add_file($folder_id, $filename, $_POST['content'], '', '', '', $_POST['priority']))
  64.             {
  65.                 $feedback = '<p class="Error">'.$strSaveError.'</p>';
  66.             }
  67.         }
  68.     }
  69. }
  70.  
  71. if ($file_id > 0)
  72. {
  73.     $file = $cms->get_file($file_id);
  74.     $content = $file['content'];
  75.     $name= $file['name'];
  76.     $title = $file['title'];
  77.     $description = $file['description'];
  78.     $keywords = $file['keywords'];
  79.     $priority = $file['priority'];
  80. }else
  81. {
  82.     require($GO_THEME->theme_path."header.inc");
  83.     require("add_file.inc");
  84.     require($GO_THEME->theme_path."footer.inc");
  85.     exit();
  86. }
  87.  
  88. $link_back = 'edit.php?site_id='.$site_id.'&file_id='.$file_id.'&folder_id='.$folder_id;
  89.  
  90. if ($task == 'clean_formatting')
  91. {
  92.     $content = $cms->clean_up_html($content);
  93. }
  94.  
  95. //set the page title for the header file
  96. $page_title = $lang_modules['cms'];
  97.  
  98. //get the site template
  99. if($site = $cms->get_site($site_id))
  100. {
  101.     $template = $cms->get_template($site['template_id']);
  102. }
  103.  
  104. $pagestyle = (isset($template)) ? $template['style'] : '';
  105. $pagestyle = str_replace("\r", '', $pagestyle);
  106. $pagestyle = str_replace("\n", '', $pagestyle);
  107. $pagestyle = str_replace("\t", '', $pagestyle);
  108. $pagestyle = str_replace("'", '"', $pagestyle);
  109. $pagestyle = str_replace(' ', '', $pagestyle);
  110.  
  111. //create htmlarea
  112. $htmlarea = new htmlarea();
  113. if ($fs_module = $GO_MODULES->get_module('filesystem'))
  114. {
  115.     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']))
  116.     {
  117.         $htmlarea->add_button('insert', $cms_insert_file, $GO_CONFIG->control_url.'htmlarea/images/binary.png', 'false', "function insertObject()
  118.         {
  119.             popup('select.php?site_id=".$site_id."', '600', '400');
  120.         }");
  121.  
  122.     }
  123. }
  124. $GO_HEADER['head'] = $htmlarea->get_header('content', -70, -125, 25, $pagestyle, 'config.baseURL="";');
  125. $GO_HEADER['body_arguments'] = 'onload="initEditor()"';
  126.  
  127. //require the header file. This will draw the logo's and the menu
  128. require($GO_THEME->theme_path."header.inc");
  129.  
  130. //echo '<table border="0" cellpadding="10" cellspacing="0"><tr><td>';
  131. if (isset($feedback)) echo $feedback;
  132. echo '<form method="post" name="editor" action="'.$_SERVER['PHP_SELF'].'">';
  133. echo '<input type="hidden" name="site_id" value="'.$site_id.'" />';
  134. echo '<input type="hidden" name="file_id" value="'.$file_id.'" />';
  135. echo '<input type="hidden" name="folder_id" value="'.$folder_id.'" />';
  136. echo '<input type="hidden" name="old_name" value="'.$name.'" />';
  137. echo '<input type="hidden" name="title" value="'.$title.'" />';
  138. echo '<input type="hidden" name="description" value="'.$description.'" />';
  139. echo '<input type="hidden" name="keywords" value="'.$keywords.'" />';
  140. echo '<input type="hidden" name="priority" value="'.$priority.'" />';
  141. echo '<input type="hidden" name="unedited" value = "" />';
  142. echo '<input type="hidden" name="task" value="save" />';
  143. echo '<input type="hidden" name="name" value="'.$name.'" />';
  144.  
  145. echo '<table border="0">';
  146. echo '<td class="ModuleIcons" nowrap>';
  147. 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>';
  148. if ($file_id >0)
  149. {
  150.     echo '<td class="ModuleIcons"  nowrap>';
  151.     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>';
  152.  
  153.     echo '<td class="ModuleIcons" nowrap>';
  154.     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>';
  155. }
  156. echo '<td class="ModuleIcons"  nowrap>';
  157. 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>';
  158.  
  159.  
  160. echo '<td class="ModuleIcons" nowrap>';
  161. echo '<a class="small" href=\'javascript:clean_formatting()\'><img src="'.$GO_THEME->images['filters'].'" border="0" height="32" width="32" /><br />Cleanup</a></td>';
  162. echo '</table>';
  163.  
  164. $tabtable = new tabtable('cms_edit', $name);
  165. $tabtable->print_head();
  166. $htmlarea->print_htmlarea($content);
  167. $tabtable->print_foot();
  168.  
  169. echo '</form>';
  170. ?>
  171. <script type="text/javascript">
  172. function clean_formatting()
  173. {
  174.     document.forms[0].task.value='clean_formatting';
  175.     document.forms[0].onsubmit();
  176.     document.forms[0].submit();
  177. }
  178.  
  179. function confirm_close(URL)
  180. {
  181.     //TODO: detect if content has been changed
  182.     //if (confirm('<?php echo $cms_confirm_close; ?>'))
  183.     //{
  184.         document.location=URL;
  185.     //}
  186. }
  187.  
  188. </script>
  189.  
  190. <?php
  191. require($GO_THEME->theme_path."footer.inc");
  192. ?>
  193.  
  194.  
  195.