require $GO_MODULES->class_path . 'cms.class.inc';
$cms = new cms();
//get the language file
require $GO_LANGUAGE->get_language_file('cms');
require $GO_THEME->theme_path . 'header.inc';
echo '<input type="hidden" name="template_file_id" />';
echo '<input type="hidden" name="task" />';
echo '<table border="0" cellpadding="3" cellspacing="0"><tr>';
echo '<td width="16">&nbsp;</td>';
echo '<td width="100" nowrap><h3>' . $strName . '</h3></td>';
echo '<td width="100" nowrap><h3>' . $strType . '</h3></td></tr>';
//list the files
$total_size = 0;
$count_files = $cms->get_template_files($_REQUEST['template_id']);
while ($cms->next_record()) {
    $total_size += $cms->f('size');
    $short_name = cut_string($cms->f('name'), 30);
    echo '<tr class="Table1">';
    echo '<td><img width="16" height="16" border="0" src="' . get_filetype_image($cms->f('extension')) . '" /></td>';
    echo '<td nowrap>&nbsp;<a href="javascript:paste_url(\'' . $GO_MODULES->url . 'template_file.php?template_file_id=' . $cms->f('id') . '\')" title="' . $cms->f('name') . '">' . $short_name . '</a>&nbsp;&nbsp;</td>';
    echo '<td nowrap>' . $cms->f('content_type_friendly') . '&nbsp;&nbsp;</td></tr>';
}
echo '<tr><td colspan="99" height="18">&nbsp;' . $count_files . ' ' . $cms_items . '</td></tr>';
echo '</table>
<script type="text/javascript">

function paste_url(url)
{
  var textarea = opener.document.forms[0].' . $_REQUEST['SET_FIELD'] . ';

  if (document.all)
            ?>
</textarea>
	</td>
	</tr>
	<tr>
	<td>
	<?php 
            echo $cms_theme;
            ?>
:
	</td>
	<td>
	<?php 
            $dropbox = new dropbox();
            while ($cms->next_record()) {
                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'))) {
                    $dropbox->add_value($cms->f('id'), $cms->f('name'));
                }
            }
            $dropbox->print_dropbox('template_id', $template_id);
            ?>
	</td>
	</tr>
	<tr>
	<td colspan="2">
	<?php 
            $checkbox = new checkbox('secure', 'true', $cms_use_go_auth, $secure_check);
            ?>
	</td>
	</tr>
	
//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');
//load the CMS module class library
require $GO_MODULES->class_path . 'cms.class.inc';
$cms = new cms();
/*
MS: If a standard user has only one site redirect him there directly.
*/
if (!$GO_MODULES->write_permissions) {
    if ($count = $cms->get_authorized_sites($GO_SECURITY->user_id)) {
        if ($count == 1) {
            $cms->next_record();
            header('Location: browse.php?site_id=' . $cms->f('id'));
            exit;
        }
    }
}
//get the language file
require $GO_LANGUAGE->get_language_file('cms');
//create a tab window
$tabtable = new tabtable('sites', $lang_modules['cms'], '100%', '400');
//$tabtable->add_tab('subscribed.inc', $cms_your_sites);
$tabtable->add_tab('sites.inc', $cms_all_sites);
if ($GO_MODULES->write_permissions) {
    $tabtable->add_tab('templates.inc', $cms_themes_menu);
    $tabtable->add_tab('configuration.inc', $menu_configuration);
}
//perform tasks before output to client
  echo '</a></td>';

  echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="'.$_SERVER['PHP_SELF'].'?site_id='.$site_id.'&new_sort_field=cms_files.mtime&new_sort_order='.$new_sort_order.'">'.$strModified;
  if ($cms_settings['sort_field'] == "cms_files.mtime")
  echo $image_string;
*/
echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="' . $_SERVER['PHP_SELF'] . '?site_id=' . $site_id . '&new_sort_field=cms_files.priority&new_sort_order=' . $new_sort_order . '&folder_id=' . $folder_id . '">' . $cms_priority;
if ($cms_settings['sort_field'] == "cms_files.priority") {
    echo $image_string;
}
echo '</a></td></tr>';
//list the folders first
$total_size = 0;
$count_folders = $cms->get_folders($folder_id, $folders_sort, $cms_settings['sort_order']);
while ($cms->next_record()) {
    $short_name = cut_string($cms->f('name'), 30);
    echo '<tr id="folder_' . $cms->f('id') . '" class="Table1">';
    echo '<td><input onclick="javascript:folder_click(this)" type="checkbox" name="folders[]" value="' . $cms->f('id') . '" id="' . $cms->f('name') . '" /></td>' . '<td nowrap><a href="' . $_SERVER['PHP_SELF'] . '?site_id=' . $site_id . '&folder_id=' . $cms->f('id') . '" title="' . $cms->f('name') . '">';
    if ($cms->f('disabled') == '1') {
        echo '<img width="16" height="16" border="0" src="' . $GO_THEME->images['invisible_folder'] . '" align="absmiddle" />';
    } else {
        echo '<img width="16" height="16" border="0" src="' . $GO_THEME->images['folder'] . '" align="absmiddle" />';
    }
    echo '&nbsp;&nbsp;' . $short_name . '</a>';
    echo '<td nowrap>' . $fbFolder . '&nbsp;&nbsp;</td>';
    /*
      echo '<td align="right">-&nbsp;&nbsp;</td>';
      echo '<td nowrap>'.date($_SESSION['GO_SESSION']['date_format'], $cms->f('mtime')).'&nbsp;&nbsp;</td>';
    */
    echo '<td nowrap align="center">' . $cms->f('priority') . '</td>';
    echo '</tr>';
         if (!$cms->update_folder($folder_id, $name, $disabled, $_POST['priority'], $disable_multipage)) {
             $feedback = '<p class="Error">' . $strSaveError . '</p>';
         } else {
             if ($_POST['close'] == 'true') {
                 header('Location: ' . $return_to);
                 exit;
             }
         }
     }
     break;
 case 'save_search_words':
     $cms2 = new cms();
     $selected_search_words = isset($_POST['selected_search_words']) ? $_POST['selected_search_words'] : array();
     $cms->get_search_words($site_id);
     while ($cms->next_record()) {
         $attached = $cms2->file_is_attached($_POST['file_id'], $cms->f('id'));
         $selected = in_array($cms->f('id'), $selected_search_words);
         if ($selected && !$attached) {
             $cms2->attach_file($_POST['file_id'], $cms->f('id'));
         }
         if ($attached && !$selected) {
             $cms2->detach_file($_POST['file_id'], $cms->f('id'));
         }
     }
     $task = 'file_properties';
     if ($_POST['close'] == 'true') {
         header('Location: ' . $return_to);
         exit;
     }
     break;
 case 'search_file':