home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / cms / site.php < prev    next >
PHP Script  |  2004-03-08  |  14KB  |  499 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.  
  14. //load Group-Office
  15. require("../../Group-Office.php");
  16.  
  17. //load the CMS module class library
  18. require($GO_CONFIG->class_path.'cms.class.inc');
  19. $cms = new cms();
  20.  
  21. //authenticate the user
  22. $GO_SECURITY->authenticate();
  23.  
  24. //see if the user has access to this module
  25. //for this to work there must be a module named 'example'
  26. $GO_MODULES->authenticate('cms');
  27.  
  28. //get the language file
  29. require($GO_LANGUAGE->get_language_file('cms'));
  30.  
  31. $site_id = isset($_REQUEST['site_id']) ? $_REQUEST['site_id'] : 0;
  32. $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
  33.  
  34. $return_to = isset($_REQUEST['return_to']) ? $_REQUEST['return_to'] : 'index.php';
  35.  
  36. $root_publish_path = $GO_CONFIG->get_setting('cms_publish_path');
  37.  
  38. if ($_SERVER['REQUEST_METHOD'] =='POST' && $task == 'save_site')
  39. {
  40.     $name = trim($_POST['name']);
  41.     if ($name == '')
  42.     {
  43.         $feedback= '<p class="Error">'.$error_missing_field.'</p>';
  44.  
  45.     }else
  46.     {
  47.         if ($_POST['site_id'] > 0)
  48.         {
  49.             if(!$site = $cms->get_site($_POST['site_id']))
  50.             {
  51.                 $feedback = '<p class="Error">'.$strSaveError.'</p>';
  52.             }else
  53.             {
  54.                 $existing_site = $cms->get_site_by_name($name);
  55.                 if ($existing_site && $existing_site['id'] != $_POST['site_id'])
  56.                 {
  57.                     $feedback = '<p class="Error">'.$cms_site_exists.'</p>';
  58.                 }else
  59.                 {
  60.                     if (isset($_POST['secure']))
  61.                     {
  62.                         if ($site['acl_read'] == 0)
  63.                         {
  64.                             if (!$acl_read = $GO_SECURITY->get_new_acl('cms read: '.$name))
  65.                             {
  66.                                 die($strAclError);
  67.                             }
  68.                         }else
  69.                         {
  70.                             $acl_read = $site['acl_read'];
  71.                         }
  72.                     }else
  73.                     {
  74.                         $acl_read = 0;
  75.                         if($site['acl_read'] > 0)
  76.                         {
  77.                             $GO_SECURITY->delete_acl($site['acl_read']);
  78.                         }
  79.                     }
  80.  
  81.                     if (!$cms->update_site($site_id, $name, $_POST['description'], $_POST['keywords'], $_POST['template_id'], $acl_read))
  82.                     {
  83.                         $feedback = '<p class="Error">'.$strSaveError.'</p>';
  84.                     }
  85.                 }
  86.             }
  87.         }else
  88.         {
  89.             if (!$cms->get_site_by_name($name))
  90.             {
  91.                 if (isset($_POST['secure']))
  92.                 {
  93.                     if (!$acl_read = $GO_SECURITY->get_new_acl('cms read: '.$name))
  94.                     {
  95.                         die($strAclError);
  96.                     }
  97.                 }else
  98.                 {
  99.                     $acl_read = 0;
  100.                 }
  101.  
  102.                 if (!$acl_write = $GO_SECURITY->get_new_acl('cms write: '.$name))
  103.                 {
  104.                     $GO_SECURITY->delete_acl($acl_read);
  105.                     die($strAclError);
  106.                 }
  107.  
  108.                 if (!$GO_SECURITY->add_user_to_acl($GO_SECURITY->user_id, $acl_write))
  109.                 {
  110.                     $GO_SECURITY->delete_acl($acl_read);
  111.                     $GO_SECURITY->delete_acl($acl_write);
  112.                     die($strAclError);
  113.                 }
  114.  
  115.                 if($site_id = $cms->add_site($GO_SECURITY->user_id, $name, $acl_read, $acl_write, $_POST['description'], $_POST['keywords'], $_POST['template_id']))
  116.                 {
  117.                     $cms->subscribe_site($GO_SECURITY->user_id, $site_id);
  118.  
  119.                 }else
  120.                 {
  121.                     $GO_SECURITY->delete_acl($acl_read);
  122.                     $GO_SECURITY->delete_acl($acl_write);
  123.                     $feedback = '<p class="Error">'.$strSaveError.'</p>';
  124.  
  125.                 }
  126.             }else
  127.             {
  128.                 $feedback = '<p class="Error">'.$cms_site_exists.'</p>';
  129.             }
  130.         }
  131.         if($_POST['close'] == 'true')
  132.         {
  133.             header('Location: '.$return_to);
  134.             exit();
  135.         }
  136.     }
  137. }elseif($_SERVER['REQUEST_METHOD'] == 'POST' && $task == 'save_publish')
  138. {
  139.     $publish_path = trim($_POST['publish_path']);
  140.     if ($publish_path == '')
  141.     {
  142.         $feedback = '<p class="Error">'.$error_missing_field.'</p>';
  143.     }else
  144.     {
  145.         if (substr($publish_path,0,1) == $GO_CONFIG->slash) $publish_path = substr($publish_path,1);
  146.         if (substr($publish_path, -1) != $GO_CONFIG->slash) $publish_path = $publish_path.$GO_CONFIG->slash;
  147.  
  148.         $existing_site = $cms->get_site_by_publish_path($publish_path);
  149.  
  150.         if ($existing_site && $existing_site['id'] != $site_id)
  151.         {
  152.             $feedback = '<p class="Error">'.$cms_path_already_used.'</p>';
  153.         }else
  154.         {
  155.             $full_publish_path = '';
  156.             $dirs = explode($GO_CONFIG->slash, $publish_path);
  157.             while($dir = array_shift($dirs))
  158.             {
  159.                 $full_publish_path = $full_publish_path.$dir.$GO_CONFIG->slash;
  160.                 $existing_site = $cms->get_site_by_publish_path($full_publish_path);
  161.                 if ($existing_site && $existing_site['id'] != $site_id)
  162.                 {
  163.                     $path_used = true;
  164.                     break;
  165.                 }
  166.             }
  167.  
  168.             if (isset($path_used))
  169.             {
  170.                 $feedback = '<p class="Error">'.$cms_path_already_used.'</p>';
  171.             }else
  172.             {
  173.                 require_once($GO_CONFIG->class_path.'filesystem.class.inc');
  174.                 $fs = new filesystem(true);
  175.  
  176.                 $site = $cms->get_site($site_id);
  177.  
  178.                 if ($site['publish_path'] != '' && file_exists($root_publish_path.$site['publish_path']) && $site['publish_path']  != $publish_path)
  179.                 {
  180.                     $publish_dir = $root_publish_path;
  181.                     $dirs = explode($GO_CONFIG->slash, $site['publish_path']);
  182.                     while($dir = array_shift($dirs))
  183.                     {
  184.                         $publish_dir = $publish_dir.$dir.$GO_CONFIG->slash;
  185.                         $fs->delete($publish_dir);
  186.                     }
  187.                 }
  188.  
  189.                 $full_publish_path = $root_publish_path;
  190.  
  191.                 $dirs = explode($GO_CONFIG->slash, $publish_path);
  192.                 while($dir = array_shift($dirs))
  193.                 {
  194.                     $full_publish_path = $full_publish_path.$dir.$GO_CONFIG->slash;
  195.                     if (!file_exists($full_publish_path))
  196.                     {
  197.                         @mkdir($full_publish_path);
  198.                     }
  199.                     if (!is_writable($full_publish_path))
  200.                     {
  201.                         $feedback = '<p class="Error">'.$cms_path_not_writable.': \''.$full_publish_path.'\'</p>';
  202.                         break;
  203.                     }
  204.                 }
  205.                 if ($full_publish_path == $root_publish_path.$publish_path)
  206.                 {
  207.                     $cms->set_publishing($site_id, $publish_style, $publish_path);
  208.                     require($GO_CONFIG->class_path.'cms_site.class.inc');
  209.                     $cms_site = new cms_site($site_id);
  210.                     $cms_site->publish();
  211.  
  212.                     if ($close == 'true')
  213.                     {
  214.                         header('Location: '.$return_to);
  215.                         exit();
  216.                     }
  217.                 }
  218.             }
  219.         }
  220.     }
  221. }
  222.  
  223. if ($site_id > 0)
  224. {
  225.     //create a tab window
  226.     $site = $cms->get_site($site_id);
  227.  
  228.     if (!$GO_SECURITY->has_permission($GO_SECURITY->user_id, $site['acl_write']))
  229.     {
  230.         header('Location: '.$GO_CONFIG->host.'error_docs/403.php');
  231.         exit();
  232.     }
  233.  
  234.     $tabtable = new tabtable('sites', $site['name'], '600', '400','100','',true);
  235.     $tabtable->add_tab('properties', $strProperties);
  236.     $tabtable->add_tab('search_words', $cms_search_words);
  237.  
  238.     if ($root_publish_path != '')
  239.     {
  240.         $tabtable->add_tab('publish', $cms_publish);
  241.     }
  242.  
  243.     $tabtable->add_tab('write_permissions', $strWriteRights);
  244.  
  245.     if ($site['acl_read'] > 0)
  246.     {
  247.         $tabtable->add_tab('read_permissions', $strReadRights);
  248.     }
  249.     if ($task == 'edit_search_words')
  250.     {
  251.         $tabtable->set_active_tab(1);
  252.     }
  253.  
  254.  
  255.  
  256. }else
  257. {
  258.     $tabtable = new tabtable('properties', $cms_new_site, '600', '400');
  259. }
  260.  
  261. switch($task)
  262. {
  263.     case 'save_search_word':
  264.         $search_word_name = trim($_POST['search_word_name']);
  265.         if ($search_word_name == '')
  266.         {
  267.             $feedback= '<p class="Error">'.$error_missing_field.'</p>';
  268.             $task = 'add_search_word';
  269.         }else
  270.         {
  271.             $search_word_id = isset($_POST['search_word_id']) ? $_POST['search_word_id'] : 0;
  272.             if($search_word_id > 0)
  273.             {
  274.                 $search_word = $cms->get_search_word_by_name($site_id, $search_word_name);
  275.                 if ($search_word && $search_word['id'] != $search_word_id)
  276.                 {
  277.                     $feedback= '<p class="Error">'.$fbNameExists.'</p>';
  278.                     $task = 'add_search_word';
  279.                 }else
  280.                 {
  281.                     $cms->update_search_word($search_word_id, $search_word_name);
  282.                 }
  283.             }else
  284.             {
  285.                 if ($cms->get_search_word_by_name($site_id, $search_word_name))
  286.                 {
  287.                     $feedback= '<p class="Error">'.$fbNameExists.'</p>';
  288.                     $task = 'add_search_word';
  289.                 }else
  290.                 {
  291.                     if (!$search_word_id = $cms->add_search_word($site_id, $search_word_name))
  292.                     {
  293.                         $feedback = '<p class="Error">'.$strSaveError.'</p>';
  294.                     }else
  295.                     {
  296.                         $cms->search_files($site['root_folder_id'], $search_word_id);
  297.                         $feedback = "<p>".$cms_search_files_prefix." '".$search_word_name."' ".$cms_search_files_suffix."</p>";
  298.                     }
  299.                 }
  300.             }
  301.  
  302.             if ($search_word_id > 0 && isset($_POST['files']))
  303.             {
  304.                 $selected_files = isset($_POST['selected_files']) ? $_POST['selected_files'] : array();
  305.                 while ($file_id = array_shift($_POST['files']))
  306.                 {
  307.                     $selected = in_array($file_id, $selected_files);
  308.                     $attached = $cms->file_is_attached($file_id, $search_word_id);
  309.                     if ($selected && !$attached)
  310.                     {
  311.                         $cms->attach_file($file_id, $search_word_id);
  312.                     }
  313.  
  314.                     if ($attached && !$selected)
  315.                     {
  316.                         $cms->detach_file($file_id, $search_word_id);
  317.                     }
  318.                 }
  319.             }
  320.         }
  321.     break;
  322.  
  323.     case 'delete_search_word':
  324.         $cms->delete_search_word($_REQUEST['search_word_id']);
  325.     break;
  326.  
  327.     case 'search_files':
  328.         $site = $cms->get_site($site_id);
  329.         $task = 'add_search_word';
  330.         $cms->search_files($site['root_folder_id'], $_POST['search_word_id']);
  331.         $feedback = "<p>".$cms_search_files_prefix." '".$_POST['search_word_name']."' ".$cms_search_files_suffix."</p>";
  332.     break;
  333. }
  334.  
  335. //set the page title for the header file
  336. $page_title = $lang_modules['cms'];
  337.  
  338. //require the header file. This will draw the logo's and the menu
  339. require($GO_THEME->theme_path."header.inc");
  340. echo '<form name="cms" method="post" action="'.$_SERVER['PHP_SELF'].'">';
  341. echo '<input type="hidden" name="site_id" value="'.$site_id.'" />';
  342. echo '<input type="hidden" name="close" value="false" />';
  343. echo '<input type="hidden" name="return_to" value="'.$return_to.'" />';
  344.  
  345. $tabtable->print_head();
  346.  
  347. switch($tabtable->get_active_tab_id())
  348. {
  349.     case 'search_words':
  350.         require('site_search_words.inc');
  351.     break;
  352.  
  353.     case 'publish':
  354.         require('publish.inc');
  355.     break;
  356.  
  357.     case 'write_permissions':
  358.         echo '<table border="0" cellpadding="10" cellspacing="0"><tr><td>';
  359.         $read_only = ($site['user_id'] == $GO_SECURITY->user_id) ? false : true;
  360.         print_acl($site["acl_write"], $read_only);
  361.         echo '</td></tr></table><br />';
  362.         $button = new button($cmdClose, "javascript:document.location='".$return_to."';");
  363.     break;
  364.  
  365.     case 'read_permissions':
  366.         echo '<table border="0" cellpadding="10" cellspacing="0"><tr><td>';
  367.         $read_only = ($site['user_id'] == $GO_SECURITY->user_id) ? false : true;
  368.         print_acl($site["acl_read"], $read_only);
  369.         echo '</td></tr></table><br />';
  370.         $button = new button($cmdClose, "javascript:document.location='".$return_to."';");
  371.     break;
  372.  
  373.     default:
  374.         if($site_id > 0)
  375.         {
  376.             $name = $site['name'];
  377.             $description = $site['description'];
  378.             $keywords = $site['keywords'];
  379.             $template_id = $site['template_id'];
  380.             $secure_check = ($site['acl_read'] > 0) ? true : false;
  381.         }else
  382.         {
  383.             $name = isset($_POST['name']) ? $_POST['name'] : '';
  384.             $description = isset($_POST['description']) ? $_POST['description'] : '';
  385.             $keywords = isset($_POST['keywords']) ? $_POST['keywords'] : '';
  386.             $secure_check = isset($_POST['secure']) ? true : false;
  387.             $template_id = isset($_POST['template_id']) ? $_POST['template_id'] : '';
  388.         }
  389.  
  390.         if ($cms->get_templates() == 0)
  391.         {
  392.             echo '<br />';
  393.             echo $cms_no_themes;
  394.             echo '<br /><br />';
  395.             $button = new button($cmdOk, "javascript:document.location='".$GO_MODULES->url."index.php?tabindex=2';");
  396.         }else
  397.         {
  398.         ?>
  399.             <input type="hidden" name="task" />
  400.             <br />
  401.             <table border="0" cellpadding="4" cellspacing="0">
  402.             <?php
  403.             if(isset($feedback)) echo '<tr><td colspan="2">'.$feedback.' </td></tr>';
  404.  
  405.             if ($site_id > 0)
  406.             {
  407.                 echo '<tr><td>'.$cms_id.':</td><td>'.$site_id.'</td></tr>';
  408.             }
  409.             ?>
  410.  
  411.             <tr>
  412.                 <td>
  413.                 <?php echo $strName; ?>:
  414.                 </td>
  415.                 <td>
  416.                 <input type="text" class="textbox" name="name" value="<?php echo $name; ?>" maxlength="100" style="width: 250" />
  417.                 </td>
  418.             </tr>
  419.             <tr>
  420.                 <td valign="top">
  421.                 <?php echo $strDescription; ?>:
  422.                 </td>
  423.                 <td>
  424.                 <textarea class="textbox" name="description" style="width: 250" rows="5"><?php echo $description; ?></textarea>
  425.                 </td>
  426.             </tr>
  427.             <tr>
  428.                 <td valign="top">
  429.                 <?php echo $cms_keywords; ?>:
  430.                 </td>
  431.                 <td>
  432.                 <textarea class="textbox" name="keywords" style="width: 250" rows="5"><?php echo $keywords; ?></textarea>
  433.                 </td>
  434.             </tr>
  435.             <tr>
  436.                 <td>
  437.                 <?php echo $cms_theme; ?>:
  438.                 </td>
  439.                 <td>
  440.                 <?php
  441.  
  442.                 $dropbox=new dropbox();
  443.  
  444.                 while ($cms->next_record())
  445.                 {
  446.                     if ((isset($site) && $cms->f('id') == $site['template_id']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $cms->f('acl_read')) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $cms->f('acl_write')))
  447.                     {
  448.                         $dropbox->add_value($cms->f('id'), $cms->f('name'));
  449.                     }
  450.                 }
  451.                 $dropbox->print_dropbox('template_id', $template_id);
  452.                 ?>
  453.                 </td>
  454.             </tr>
  455.             <tr>
  456.                 <td colspan="2">
  457.                 <?php
  458.                 $checkbox = new checkbox('secure', 'true', $cms_use_go_auth, $secure_check);
  459.                 ?>
  460.                 </td>
  461.             </tr>
  462.             <tr>
  463.                 <td colspan="2">
  464.                     <br />
  465.                     <?php
  466.                     $button = new button($cmdOk, "javascript:save_close_site()");
  467.                     echo '  ';
  468.                     $button = new button($cmdApply, "javascript:save_site()");
  469.                     echo '  ';
  470.                     $button = new button($cmdClose, "javascript:document.location='".$return_to."';");
  471.                     ?>
  472.                 </td>
  473.             </tr>
  474.             </table>
  475.             <script type="text/javascript">
  476.             function save_close_site()
  477.             {
  478.                 document.forms[0].close.value='true';
  479.                 document.forms[0].task.value='save_site';
  480.                 document.forms[0].submit();
  481.             }
  482.  
  483.             function save_site()
  484.             {
  485.                 document.forms[0].task.value='save_site';
  486.                 document.forms[0].submit();
  487.             }
  488.             document.forms[0].name.focus();
  489.             </script>
  490.             <?php
  491.  
  492.         }
  493.     break;
  494. }
  495.  
  496. $tabtable->print_foot();
  497. echo '</form>';
  498. require($GO_THEME->theme_path."footer.inc");
  499. ?>