echo $site->CONF['wwwroot'] . $site->CONF[styles_path];
    ?>
/scms_general.css">
<SCRIPT LANGUAGE="JavaScript" SRC="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF[js_path];
    ?>
/yld.js"></SCRIPT>
</head>
<body class="popup_body" onLoad="this.focus();document.forms['vorm'].name.focus();">

<FORM action="<?php 
    echo $site->self;
    ?>
" method="post" name="vorm">
<?php 
    create_form_token('edit-forms');
    ?>
<table border="0" cellpadding="0" cellspacing="0" style="width:100%; height:100%">
<tr> 
    <td valign="top" width="100%" class="scms_dialog_area_top"  height="100%">
	  <table width="100%"   border="0" cellspacing="0" cellpadding="2">
	  <?php 
    ############ name #########
    if ($form_error['name']) {
        $name = $site->fdat['name'];
    } else {
        $name = $form_def['name'];
    }
    ?>
 
	  <tr> 
/**
 * edit_object_metadata.php
 * 
 * used by SEO Module to modify sections title, meta-description and meta-keywords
 * 
 */
function edit_objekt_metadata()
{
    global $site;
    $objekt = new Objekt(array('objekt_id' => $site->fdat['id'], 'no_cache' => '1'));
    ?>

<form name="frmEdit" action="<?php 
    echo $site->self;
    ?>
" method="POST">
<?php 
    create_form_token('edit-object-seo');
    ?>
<input type=hidden name=tab value="<?php 
    echo $site->fdat['tab'];
    ?>
">
<input type=hidden name=id value="<?php 
    echo $site->fdat['id'];
    ?>
">
<input type=hidden name=op value="<?php 
    echo $site->fdat['op'];
    ?>
">
<input type=hidden name=op2 value="">

<tr> 
	<td valign="top" width="100%" class="scms_dialog_area" height="100%"> 
		<div class="scms_scrolltable_border"> 
			<div style="width:100%;" class="scms_scrolltable_header">
				<table width="100%" cellpadding="0" cellspacing="0">
				</table>
			</div>
			<div id="scrolltableDiv" class="scms_scrolltable" style="height:290px"> 
				<table width="100%"  border="0" cellspacing="0" cellpadding="3">
<?php 
    //peaks siis otsima millisel esivanemal on SEO meta't
    function getSeoData($id, $clear = false)
    {
        static $seo_meta = array();
        $objekt = new Objekt(array('objekt_id' => $id));
        if ($clear) {
            $seo_meta = array();
        }
        if ($objekt->all['meta_title'] && empty($seo_meta['meta_title'])) {
            $seo_meta['meta_title'] = $objekt->all['meta_title'];
        }
        if ($objekt->all['meta_keywords'] && empty($seo_meta['meta_keywords'])) {
            $seo_meta['meta_keywords'] = $objekt->all['meta_keywords'];
        }
        if ($objekt->all['meta_description'] && empty($seo_meta['meta_description'])) {
            $seo_meta['meta_description'] = $objekt->all['meta_description'];
        }
        //if we have all seo data or the the tree trunk (id=0) then end else recurse
        if ($seo_meta['meta_title'] && $seo_meta['meta_keywords'] && $seo_meta['meta_description'] || $id == 0) {
            return $seo_meta;
        } else {
            return getSeoData($objekt->all['parent_id']);
        }
    }
    if ($objekt->all['objekt_id']) {
        $seo_meta = getSeoData($objekt->all['objekt_id']);
        $higher_seo_meta = getSeoData($objekt->all['parent_id'], true);
    } else {
        $seo_meta = getSeoData($site->fdat['parent_id']);
        $higher_seo_meta = $seo_meta;
    }
    ?>
		<script type="text/javascript">
			
			var metas = new Array();
			metas['meta_title'] = '<?php 
    echo str_replace(array("\r", "\n"), ' ', addslashes($higher_seo_meta['meta_title']));
    ?>
';
			metas['meta_keywords'] = '<?php 
    echo str_replace(array("\r", "\n"), ' ', addslashes($higher_seo_meta['meta_keywords']));
    ?>
';
			metas['meta_description'] = '<?php 
    echo str_replace(array("\r", "\n"), ' ', addslashes($higher_seo_meta['meta_description']));
    ?>
';

			function toggle(id)
			{
				var switcher=document.getElementById(id);
				if(switcher)
				{
					if(switcher.disabled) switcher.disabled=false;
					else 
					{
						switcher.disabled=true;
						switcher.value=metas[id];
					}
				}
			}
			
		</script>
		<tr> 
            <td class="txt" width="0" valign="top" align=right nowrap><label for="meta_title_toggler"><?php 
    echo $site->sys_sona(array(sona => "Saidi tiitel", tyyp => "editor"));
    ?>
</label> <input id="meta_title_toggler" onclick="toggle('meta_title');" type="checkbox"<?php 
    echo $objekt->all['meta_title'] ? ' checked="checked"' : ' ';
    ?>
/>:</td>
			<td class="txt" width="100%" nowrap valign="top">
				<input name="meta_title" id="meta_title" class="frm" style="width: 100%" value="<?php 
    echo htmlspecialchars($seo_meta['meta_title']);
    ?>
"<?php 
    echo empty($objekt->all['meta_title']) ? ' disabled="disabled"' : ' ';
    ?>
/> 
			</td>
		</tr>	
		<tr> 
            <td class="txt" width="0" valign="top"  align=right nowrap><label for="meta_desc_toggler">Meta-description</label> <input id="meta_desc_toggler" onclick="toggle('meta_description');" type="checkbox"<?php 
    echo $objekt->all['meta_description'] ? ' checked="checked"' : ' ';
    ?>
/>:</td>
			<td class="txt" width="100%" nowrap valign="top">
				<textarea name="meta_description" id="meta_description" rows="5" style="width: 100%; padding: 2px; font-family: Tahoma, Verdana; font-size: 11px; color: #000;" value="<?php 
    echo htmlspecialchars($seo_meta['meta_description']);
    ?>
"<?php 
    echo empty($objekt->all['meta_description']) ? ' disabled="disabled"' : ' ';
    ?>
><?php 
    echo htmlspecialchars($seo_meta['meta_description']);
    ?>
</textarea> 
			</td>
		</tr>	
		<tr> 
            <td class="txt" width="0" valign="top" align=right nowrap><label for="meta_keywords_toggler">Meta-keywords</label> <input id="meta_keywords_toggler" onclick="toggle('meta_keywords');" type="checkbox"<?php 
    echo $objekt->all['meta_keywords'] ? ' checked="checked"' : ' ';
    ?>
/>:</td>
			<td class="txt" width="100%" nowrap valign="top">
				<textarea name="meta_keywords" id="meta_keywords" rows="5" style="width: 100%; padding: 2px; font-family: Tahoma, Verdana; font-size: 11px; color: #000;" value="<?php 
    echo htmlspecialchars($seo_meta['meta_keywords']);
    ?>
"<?php 
    echo empty($objekt->all['meta_keywords']) ? ' disabled="disabled"' : ' ';
    ?>
><?php 
    echo htmlspecialchars($seo_meta['meta_keywords']);
    ?>
</textarea> 
			</td>
		</tr>	
		<?php 
    # SEO
    ####################################
    ?>
				</table>
			</div>
		</div>
	</td>
</tr>
<tr> 
	<td align="right" valign="top" class="scms_dialog_area_bottom"> 
		<input type="button" value="<?php 
    echo $site->sys_sona(array(sona => "apply", tyyp => "editor"));
    ?>
" onclick="javascript:frmEdit.op2.value='save';this.form.submit();">
		<input type="button" value="<?php 
    echo $site->sys_sona(array(sona => "Salvesta", tyyp => "editor"));
    ?>
" onclick="javascript:frmEdit.op2.value='saveclose';this.form.submit();">
		<input type="button" value="<?php 
    echo $site->sys_sona(array(sona => "close", tyyp => "editor"));
    ?>
" onclick="javascript:window.close();"> 
	</td>
</tr>

</form>

<?php 
}
        ?>

 <tr>
  <td width="100%" valign="top" class="scms_pane_area" height="100%">
	<?php 
        ################
        # DATA TABLE
        ?>
    <div id=listing class="scms_middle_div" style="min-height: 440px">
	<table width="100%" border="0" cellspacing="10" cellpadding="0" style="height:100%;">
	<form action="<?php 
        echo $site->self;
        ?>
" name="dataform" method=post>
	<?php 
        create_form_token('change-config');
        ?>
	<?php 
        #################
        # DATA ROWS
        ?>
		<tr>
			<td height="100%" valign="top">

			<table class="scms_table" width="100%"  border="0" cellspacing="0" cellpadding="4" id="contenttable">

				<?php 
        print_config_table();
        ?>

			<tr><td></td></tr>
        }
        ######################
        # UNSET parent group info for new group
        if ($site->fdat['op'] == 'new') {
            $group = '';
        }
        ?>
  <tr> 
    <td valign="top" width="100%" class="scms_dialog_area" height="100%"> 
      <table width="100%"  border="0" cellspacing="3" cellpadding="0" class="scms_borderbox">
	<form name="frmEdit" action="<?php 
        echo $site->self;
        ?>
" method="POST">
	<?php 
        create_form_token('edit-group');
        ?>
	<input type=hidden name=tab value="<?php 
        echo $site->fdat['tab'];
        ?>
">
	<input type=hidden name=group_id value="<?php 
        echo $site->fdat['group_id'];
        ?>
">
	<input type=hidden name=op value="<?php 
        echo $site->fdat['op'];
        ?>
">
	<input type=hidden name=op2 value="">
	<input type=hidden id=refresh name=refresh value="">
	</div><!-- / scms_header_bar -->
	<?php 
}
?>
	
	<div id="scms_content_body">
	
		<div id="edit_translastion_container">
		
			<form id="translations_form" action="<?php 
echo $_SERVER['PHP_SELF'];
?>
" method="POST">
			
				<?php 
create_form_token('edit-translations');
?>
				
				<input type="hidden" name="op" value="<?php 
echo $site->fdat['op'] == 'edit' ? 'edit' : 'new';
?>
" />
				<input type="hidden" name="action" value="save" />
				<input type="hidden" name="action" value="save" />
				<?php 
if ($site->fdat['type'] == 'popup') {
    ?>
<input type="hidden" name="type" value="popup" /><?php 
}
?>
				
			            			<li><a href="javascript:document.getElementById('configs_form').submit();" class="button_save"><?php 
echo $site->sys_sona(array('sona' => 'salvesta', 'tyyp' => 'Editor'));
?>
</a></li>
			            		</ul>
	    					</td>
	    				</tr>
	    			</table>
				</div><!-- / toolbarArea -->
				<div class="contentAreaContent withTitleAndToolBar">
					<form name="configs_form" id="configs_form" method="POST" action="<?php 
echo $_SERVER['PHP_SELF'];
?>
">
						<?php 
create_form_token('image-configs');
?>
						<input type="hidden" name="save_configs" value="1">
		    			<table cellpadding="0" cellspacing="0" class="data_table">
		    				<tr>
		    					<td><input type="text" name="image_width" class="text_config" value="<?php 
echo $configs['image_width']['sisu'];
?>
"></td>
		    					<td><?php 
echo $configs['image_width']['kirjeldus'];
?>
</td>
		    				</tr>
		    				<tr>
		    					<td><input type="text" name="thumb_width" class="text_config" value="<?php 
			<script type="text/javascript">
				window.opener.location=mylocation;
				window.close();
			</script>
<?php 
                exit;
                ################################
                # Ask confirmation
            } else {
                ?>
	<form action="<?php 
                echo $site->self;
                ?>
" method=get>
	<?php 
                create_form_token('delete-object');
                ?>
<table border="0" cellpadding="0" cellspacing="0" style="width:100%; height:100px">
  <tr> 
    <td valign="top" width="100%" class="scms_confirm_delete_cell" height="100%">
<?php 
                ######## 1. ask confirmation:  "Do you want to delete this and that?"
                $kinnitus = $site->sys_sona(array(sona => "tyyp_" . $tyyp['nimi'], tyyp => "System")) . ' "<b>' . $objekt->pealkiri . '</b>": ' . $site->sys_sona(array(sona => "Kas tahate kustutada", tyyp => "editor"));
                echo $kinnitus;
                ######## 2. for section only, show alert:  "NB! This section includes objects which are published also in other sections. These objects are deleted only from this section."
                # If we have tyyp=rubriik, check for objects, that are under some other rubrics too
                if ($objekt->all['klass'] == "rubriik") {
                    $sql = $site->db->prepare("SELECT DISTINCT objekt.objekt_id, objekt.pealkiri FROM objekt \r\n\t\t\tLEFT JOIN objekt_objekt AS parents_objekt ON parents_objekt.parent_id = ? \r\n\t\t\tLEFT JOIN objekt_objekt AS alam_objekt ON alam_objekt.objekt_id=parents_objekt.objekt_id \r\n\t\t\tWHERE objekt.tyyp_id = 2 AND objekt.objekt_id = alam_objekt.objekt_id AND alam_objekt.parent_id != ?", $objekt->objekt_id, $objekt->objekt_id);
                    $sth = new SQL($sql);
                    $site->debug->msg($sth->debug->get_msgs());
                    if ($sth->rows) {
/**
 * show object permission rows
 *
 * Shows all objected permissions: user/group name + CRUPD matrix + subtree checkbox
 * Allows to add new user/group as new permission row and delete rows
 * NB! Used some global variables (doesn't have to be this way later... only for development convienence now)
 * 
 * @param string type - permission type (OBJ/ADMIN/ACL/..)
 *
 * Call:
 *		edit_permissions(array(
 *			"type" => 'OBJ'	
 *		));
 */
function edit_permissions($args)
{
    global $site;
    global $objekt;
    global $class_path;
    global $keel;
    $db_permissions = array();
    $existing_users = array();
    $existing_groups = array();
    $selected_users = array();
    $selected_groups = array();
    $crud = array();
    # if objekt is not created (probably error situation), try to create it again
    if (!$objekt->objekt_id) {
        $objekt = new Objekt(array(objekt_id => $site->fdat['id']));
    }
    $everybody_group_id = get_topparent_group(array("site" => $site));
    # default permission set
    if ($args['permissions']) {
        $crud = split(",", $args['permissions']);
    } else {
        $crud = split(",", "C,R,U,P,D,S");
    }
    $crudnames = array("C" => "Create", "R" => "Read", "U" => "Update", "P" => "Publish", "D" => "Delete", "S" => "");
    if ($args['type']) {
        ##################
        # HTML
        ?>
<SCRIPT LANGUAGE="JavaScript"><!--

function sanity_check(obj,acl,type,id){
//	alert(obj.checked+type+id);
	// rule 1: !R => !C & !U & !P & !D
	if(type=='R' && !obj.checked) {
		if(document.getElementById(acl+"_C_"+id)) { document.getElementById(acl+"_C_"+id).checked=false; }
		if(document.getElementById(acl+"_U_"+id)) { document.getElementById(acl+"_U_"+id).checked=false; }
		if(document.getElementById(acl+"_P_"+id)){ document.getElementById(acl+"_P_"+id).checked=false; }
		if(document.getElementById(acl+"_D_"+id)) { document.getElementById(acl+"_D_"+id).checked=false; }
	}
	// rule 2: C || U || P || D => R
	if(type=='C' && obj.checked || 
		type=='U' && obj.checked || 
		type=='P' && obj.checked || 
		type=='D' && obj.checked) {
		document.getElementById(acl+"_R_"+id).checked=true;
	}
}
function get_copypermissions_url(acl,id){
	var crud = '';
	if(document.getElementById(acl+"_C_"+id)) { 
		if(document.getElementById(acl+"_C_"+id).checked) { crud = crud + '1'; } else { crud = crud + '0'; }
	}
	if(document.getElementById(acl+"_R_"+id) || $("input[name="+acl+"_R_"+id+"]").length > 0) { 
		if($("input[name="+acl+"_R_"+id+"]").val() == '1' || document.getElementById(acl+"_R_"+id).checked) { crud = crud + '1'; } else { crud = crud + '0'; }
	}
	if(document.getElementById(acl+"_U_"+id)) { 
		if(document.getElementById(acl+"_U_"+id).checked) { crud = crud + '1'; } else { crud = crud + '0'; }
	}
	if(document.getElementById(acl+"_P_"+id)) { 
		if(document.getElementById(acl+"_P_"+id).checked) { crud = crud + '1'; } else { crud = crud + '0'; }
	}
	if(document.getElementById(acl+"_D_"+id)) { 
		if(document.getElementById(acl+"_D_"+id).checked) { crud = crud + '1'; } else { crud = crud + '0'; }
	}
	return crud;
}
-->
</script>
<?php 
        ######## gather all fdat values into url string
        foreach ($site->fdat as $fdat_field => $fdat_value) {
            if ($fdat_field != 'id') {
                $url_parameters .= '&' . $fdat_field . "=" . $fdat_value;
                #not used?			$hidden_parameters .= '<input type=hidden name="'.$fdat_field.'" value="'.$fdat_value.'">';
            }
        }
        ######################
        # OBJECT PERMISSIONS
        $sql = $site->db->prepare("SELECT permissions.*, roles.name AS role_name, groups.name AS group_name, CONCAT(users.firstname,' ',users.lastname) AS user_name, groups.is_predefined AS predefined_group \r\n\tFROM permissions \r\n\t\tLEFT JOIN roles ON permissions.role_id=roles.role_id \r\n\t\tLEFT JOIN groups ON permissions.group_id=groups.group_id\r\n\t\tLEFT JOIN users ON permissions.user_id=users.user_id \r\n\tWHERE permissions.type=? AND permissions.source_id=?\r\n\tORDER BY permissions.group_id DESC, permissions.user_id DESC, groups.name, users.firstname,users.lastname\r\n\t\t", $args['type'], $site->fdat['id']);
        $sth = new SQL($sql);
        $saved_permissions_found = $sth->rows ? true : false;
        $site->debug->msg($sth->debug->get_msgs());
        #print $sql;
        while ($permtmp = $sth->fetch()) {
            $permtmp['is_role'] = $permtmp['role_id'] ? 1 : 0;
            $permtmp['is_group'] = $permtmp['group_id'] ? 1 : 0;
            $permtmp['name'] = $permtmp['role_id'] ? $permtmp['role_name'] : ($permtmp['group_id'] ? $permtmp['group_name'] : $permtmp['user_name']);
            $db_permissions[] = $permtmp;
            if ($permtmp['user_id']) {
                $existing_users[] = $permtmp['user_id'];
            }
            if ($permtmp['group_id']) {
                $existing_groups[] = $permtmp['group_id'];
            }
        }
        ######################
        ######################
        # HOME section permissions (sys_alias=home) will be default permissions through all website
        # get site permissions for everybody:
        $sql = $site->db->prepare("SELECT permissions.*, groups.name\r\n\tFROM permissions \r\n\t\tLEFT JOIN groups ON permissions.group_id=groups.group_id\r\n\tWHERE permissions.type=? AND permissions.source_id=?\r\n\t\t", 'OBJ', $site->alias("rub_home_id"));
        $sth = new SQL($sql);
        $home_permissions_found = $sth->rows ? true : false;
        $site->debug->msg($sth->debug->get_msgs());
        #print $sql;
        while ($permtmp = $sth->fetch()) {
            $permtmp['is_group'] = $permtmp['group_id'] ? 1 : 0;
            $home_permissions[] = $permtmp;
            if ($permtmp['group_id']) {
                $home_existing_groups[] = $permtmp['group_id'];
            }
        }
        # if for some reason home section doesn't have permissions
        # then use default mask: only Read permission (CRUPD=01000)
        if (!is_array($home_permissions)) {
            $home_permissions[] = array(id => '', type => 'OBJ', source_id => $site->alias("rub_home_id"), group_id => 1, user_id => '', C => 0, R => 1, U => 0, P => 0, D => 0, is_role => 0, is_group => 1, name => 'Everybody');
        }
        #printr($home_permissions);
        ######################
        # TEMPORALLY SELECTED USERS & GROUPS PERMISSIONS
        # they are in the list but not in database yet
        #echo printr($site->fdat['selected_groups']);
        if (trim($site->fdat['selected_users'])) {
            $selected_users = split(",", trim($site->fdat['selected_users']));
            $selected_users = array_unique($selected_users);
            ### remove user from array if asked in url
            if ($site->fdat['remove_user_id']) {
                $key = array_search($site->fdat['remove_user_id'], $selected_users);
                unset($selected_users[$key]);
            }
        }
        if (trim($site->fdat['selected_groups'])) {
            $selected_groups = split(",", trim($site->fdat['selected_groups']));
            $selected_groups = array_unique($selected_groups);
            ### remove group from array if asked in url
            if ($site->fdat['remove_group_id']) {
                $key = array_search($site->fdat['remove_group_id'], $selected_groups);
                unset($selected_groups[$key]);
            }
        }
        #printr($selected_groups);
        #printr($existing_groups);
        # add selected groups to permission list
        if (sizeof($selected_groups) > 0) {
            foreach ($selected_groups as $group_id) {
                # if group not found in existing groups (in database) then add it
                if (!in_array($group_id, $existing_groups)) {
                    # get group info: to get group name
                    $group = new Group(array(group_id => $group_id));
                    $permtmp = array();
                    $permtmp['type'] = $args['type'];
                    $permtmp['source_id'] = $site->fdat['id'];
                    $permtmp['group_id'] = $group_id;
                    $permtmp['is_group'] = 1;
                    $permtmp['name'] = $group->name;
                    # insert permission to the permissions array:
                    $db_permissions[] = $permtmp;
                }
                # if group not found in existing groups
            }
            # foreach group id
        }
        # if selected_groups
        if (sizeof($selected_users) > 0) {
            foreach ($selected_users as $user_id) {
                # if user not found in existing users (in database) then add it
                if (!in_array($user_id, $existing_users)) {
                    # get user info: to get user full name
                    $user = new User(array(user_id => $user_id));
                    $permtmp = array();
                    $permtmp['type'] = $args['type'];
                    $permtmp['source_id'] = $site->fdat['id'];
                    $permtmp['user_id'] = $user_id;
                    $permtmp['is_group'] = 0;
                    $permtmp['name'] = $user->all['firstname'] . ' ' . $user->all['lastname'];
                    # insert permission to the permissions array:
                    $db_permissions[] = $permtmp;
                }
                # if user not found in existing users
            }
            # foreach user id
        }
        # if selected_users
        # / TEMPORALLY SELECTED USERS & GROUPS PERMISSIONS
        ######################
        #printr($db_permissions);
        ?>
  <tr> 
    <td valign="top" width="100%" class="scms_dialog_area" height="100%"> 
      <div class="scms_scrolltable_border"> 
        <div style="width:100%;" class="scms_scrolltable_header">
		   <table width="100%" cellpadding="0" cellspacing="0">
	<form name="frmEdit" action="<?php 
        echo $site->self;
        ?>
" method="POST">
	<?php 
        create_form_token('edit-permissions');
        ?>
	<input type=hidden name=tab value="<?php 
        echo $site->fdat['tab'];
        ?>
">
	<input type=hidden name=id value="<?php 
        echo $site->fdat['id'];
        ?>
">
	<input type=hidden name=keel value="<?php 
        echo $site->fdat['keel'];
        ?>
">
	<input type=hidden name=op value="<?php 
        echo $site->fdat['op'];
        ?>
">
	<input type=hidden name="callback" value="<?php 
        echo $site->fdat['callback'];
        ?>
">
	<input type=hidden name=op2 value="">
	<input type=hidden name=selected_users value="<?php 
        echo join(',', $selected_users);
        ?>
">
	<input type=hidden name=selected_groups value="<?php 
        echo join(',', $selected_groups);
        ?>
">
	
	<tr> 
              <td><?php 
        echo $site->sys_sona(array(sona => "role", tyyp => "kasutaja"));
        ?>
 / <?php 
        echo $site->sys_sona(array(sona => "group", tyyp => "kasutaja"));
        ?>
 / <?php 
        echo $site->sys_sona(array(sona => "user", tyyp => "kasutaja"));
        ?>
</td>
			  <td align="right"><a href="javascript:void(openpopup('select_group.php','selectgroup','980','600'))"><?php 
        echo $site->sys_sona(array(sona => "lisa", tyyp => "editor"));
        ?>
</a></td>
            </tr>
            <tr> 
              <td colspan="2" align="right" class="scms_scrolltable_header2" style="padding-right:30px"> 
                <table  border="0" cellspacing="0" cellpadding="3" class="scms_scrolltable_header2" >
				<?php 
        ############## C R U P D S ###########
        ?>
                  <tr> 
				  <?php 
        foreach ($crud as $char) {
            ?>
                    <td width="24" align="center"><?php 
            if ($char != 'S') {
                ?>
<a href="#" title="<?php 
                echo $crudnames[$char];
                ?>
"><?php 
                echo $char;
                ?>
</a><?php 
            }
            ?>
</td>
				  <?php 
        }
        ?>
                  </tr>
                </table>
              </td>
            </tr>
          </table>
        </div>
        <div id="scrolltableDiv" class="scms_scrolltable" style="height:290px"> 
          <table width="100%"  border="0" cellspacing="0" cellpadding="3">
<?php 
        ####################
        # 1. OBJECT PERMISSIONS saved into database (if found any)
        #printr($db_permissions);
        if (sizeof($db_permissions) > 0) {
            foreach ($db_permissions as $key => $perm) {
                ######### create remove link
                $remove_href = $site->self . "?tab=" . $site->fdat['tab'] . "&id=" . $site->fdat['id'] . $url_parameters;
                $remove_href .= sizeof($selected_users) > 0 ? "&selected_users=" . join(',', $selected_users) : '';
                $remove_href .= sizeof($selected_groups) > 0 ? "&selected_groups=" . join(',', $selected_groups) : '';
                $remove_href .= "&remove_" . ($perm['is_group'] ? 'group_id=' . $perm['group_id'] : 'user_id=' . $perm['user_id']);
                ######### create copy link (permission data will be added later)
                $copy_href = $site->self . "?tab=" . $site->fdat['tab'] . "&id=" . $site->fdat['id'] . $url_parameters;
                ######### dont print permission row if it's the removed
                if ($perm['is_group'] && $perm['group_id'] == $site->fdat['remove_group_id'] || !$perm['is_group'] && $perm['user_id'] == $site->fdat['remove_user_id']) {
                    # goto next row
                    continue;
                } else {
                    print_permission_row(array("perm" => $perm, "remove_href" => $remove_href, "copy_href" => $copy_href, "crud" => $crud));
                }
                # if not in remove list => print permission row
            }
            # foreach
        }
        # if object permissions found
        # / 1. OBJECT PERMISSIONS saved into database (if found any)
        ####################
        ####################
        # 2. HOME permissions row: when NO SAVED PERMISSIONS found in database
        # - get permission values from default site values
        # - dont allow to delete everybody row
        #sizeof($db_permissions)==0
        if (!$saved_permissions_found && ($args['type'] == 'OBJ' || $args['type'] == 'ACL')) {
            foreach ($home_permissions as $key => $perm) {
                ######### create copy link (permission data will be added later)
                $copy_href = $site->self . "?tab=" . $site->fdat['tab'] . "&id=" . $site->fdat['id'] . $url_parameters;
                ########### print permission row
                print_permission_row(array("perm" => $perm, "remove_href" => $remove_href, "copy_href" => $copy_href, "crud" => $crud));
            }
        }
        # / 2. HOME permissions
        ####################
        ?>
			</table>
        </div></div>
    </td>
  </tr>
  <tr> 
    <td align="right" valign="top" class="scms_dialog_area_bottom"> 
     <input type="button" value="<?php 
        echo $site->sys_sona(array(sona => "apply", tyyp => "editor"));
        ?>
" onclick="javascript:frmEdit.op2.value='save';this.form.submit();">
    <input type="button" value="<?php 
        echo $site->sys_sona(array(sona => "Salvesta", tyyp => "editor"));
        ?>
" onclick="javascript:frmEdit.op2.value='saveclose';this.form.submit();">
	<input type="button" value="<?php 
        echo $site->sys_sona(array(sona => "close", tyyp => "editor"));
        ?>
" onclick="javascript:window.close();"> 
    </td>
  </tr>

</form>
<?php 
    }
    # if permission type provided
}




  <tr> 
    <td valign="top" width="100%" class="scms_dialog_area" height="100%"> 


		<table width="100%" height=100% border="0" cellspacing="3" cellpadding="0" class="scms_borderbox">
	<form name="frmEdit" action="<?php 
        echo $site->self;
        ?>
" method="POST">
	<?php 
        create_form_token('edit-user-mailinglist');
        ?>
	<input type=hidden name=tab value="<?php 
        echo $site->fdat['tab'];
        ?>
">
	<input type=hidden name=user_id value="<?php 
        echo $site->fdat['user_id'];
        ?>
">
	<input type=hidden name=group_id value="<?php 
        echo $site->fdat['group_id'];
        ?>
">
	<input type=hidden name=op value="<?php 
        echo $site->fdat['op'];
    if ($profile_def['source_table'] == 'obj_asset') {
        ?>
change_profile_map_value1(document.forms['vorm'].profile_type.options[document.forms['vorm'].profile_type.options.selectedIndex].value);<?php 
    } else {
        ?>
change_profile_map_value2(document.forms['vorm'].definition_name.value);<?php 
    }
    ?>
">

<FORM action="<?php 
    echo $site->self;
    ?>
" method="post" name="vorm">
	<?php 
    create_form_token('edit-profile-field');
    ###################
    # luba profiili MUUTA ja nime muuta ainult siis kui andmeid SELLE KONKREETSE V�LJA KOHTA pole veel sisestatud:
    # otsi, kas leidub selle profiiliga andmeid kus antud v�li ei ole t�hi (aga ignoreeri default pealkirja v�lja, sest see asub objekt tabelis Bug #2818)
    $locked = 0;
    if ($site->fdat['op'] == "edit" && $site->fdat['did'] && !$profile_info["is_general"] && $site->fdat['did'] != 'pealkiri') {
        $sql2 = "SELECT COUNT(*) FROM " . $profile_def['source_table'] . " WHERE profile_id = ? AND ";
        $sql2 .= " " . $site->fdat['did'] . " <>''";
        #print $sql2;
        $sql2 = $site->db->prepare($sql2, $site->fdat['pid']);
        $sth2 = new SQL($sql2);
        $site->debug->msg($sth2->debug->get_msgs());
        $found_data = $sth2->fetchsingle();
        $locked = $found_data ? 1 : 0;
    }
    # testimiseks: $locked = 0;
## LOAD DATA
$sql = "SELECT * FROM css";
$sth = new SQL($sql);
while ($tmp = $sth->fetch()) {
    $css[$tmp['name']] = $tmp;
}
?>


<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
	<form action="<?php 
echo $site->self;
?>
" name="dataform" method="POST">
	<?php 
create_form_token('edit-styles');
?>
	<input type="hidden" name="save" value="1">

 <?php 
##############
# FUNCTION BAR
?>
  <!-- Toolbar -->
  <tr>
	<td class="scms_toolbar">
		<TABLE cellpadding=0 cellspacing=0 border=0>
			<TR>	
				<?php 
############ save button ###########
?>
<link rel="stylesheet" href="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/scms_general.css">
<SCRIPT LANGUAGE="JavaScript" SRC="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/yld.js"></SCRIPT>
</head>
<body  class="popup_body">
	<form name="frmEdit" action	="<?php 
    echo $site->self;
    ?>
" method="POST">
	<?php 
    create_form_token('delete-data');
    ?>
	<input type=hidden name=table_name value="<?php 
    echo $site->fdat['table_name'];
    ?>
">
	<input type=hidden name=field_name value="<?php 
    echo $site->fdat['field_name'];
    ?>
">
	<input type=hidden name=op value="<?php 
    echo $site->fdat['op'];
    ?>
">
	<input type=hidden name=op2 value="">
<table border="0" cellpadding="0" cellspacing="0" style="width:100%; height:100%">
/**
 * edit_artikkel.php
 *
 */
function edit_objekt()
{
    function print_profiles()
    {
        global $site, $objekt, $parent;
        $sql = $site->db->prepare("SELECT profile_id AS id, source_table AS parent, name FROM object_profiles WHERE source_table=? ORDER BY name", 'obj_artikkel');
        $sth = new SQL($sql);
        # get object profile
        if ($objekt->all['profile_id']) {
            $profile_def = $site->get_profile(array("id" => $objekt->all['profile_id']));
            $site->fdat['profile_id'] = $profile_def['profile_id'];
        }
        # if still not found then use default profile for this class
        if (!$profile_def['profile_id'] && !$site->fdat['profile_id']) {
            $site->fdat['profile_id'] = $site->get_default_profile_id(array("source_table" => 'obj_artikkel'));
            $profile_def = $site->get_profile(array("id" => $site->fdat['profile_id']));
        }
        ?>

<fieldset>
	<legend>
		<select onchange="changeProfile(this)" name="profile_id">
		<?php 
        $all_profiles_hash = array();
        while ($profile_data = $sth->fetch()) {
            $all_profiles_hash[] = $profile_data['id'];
            print "<option value='" . $profile_data['id'] . "' " . ($profile_data['id'] == $site->fdat['profile_id'] ? '  selected' : '') . ">" . $site->sys_sona(array(sona => $profile_data['name'], tyyp => "custom")) . "</option>";
        }
        ?>
		</select>
	</legend>

	<?php 
        foreach ($all_profiles_hash as $profile_id) {
            ?>

	<div id="profile_<?php 
            echo $profile_id;
            ?>
" style="display: <?php 
            echo $site->fdat['profile_id'] == $profile_id ? 'block' : 'none';
            ?>
;">
		<table cellpadding="0" cellspacing="0">
	<?php 
            $profile_def = $site->get_profile(array("id" => $profile_id));
            $profile_fields = unserialize($profile_def['data']);
            # if profile fields exist
            if (is_array($profile_fields) && sizeof($profile_fields) > 0) {
                ## add suffix for each field, to get unique id-s
                foreach ($profile_fields as $key => $tmp_prof) {
                    $profile_fields[$key]['html_fieldname'] = $profile_fields[$key]['name'] . "_" . $profile_id;
                    # field can be INPUT or READ-ONLY value - this info may be passed from triggers file "actions.inc.php", using "$site->fdat" array
                    $profile_fields[$key]['is_readonly'] = $site->fdat['is_readonly_' . $key];
                }
                #printr($profile_fields);
                ###################
                # print profile fields rows
                print_profile_fields(array('profile_fields' => $profile_fields, 'field_values' => $objekt->all));
            }
            # if profile fields exist
            ?>
		</table>
	</div>

	<?php 
        }
        //foreach
        ?>

</fieldset>

<fieldset>
	<legend><?php 
        echo $site->sys_sona(array('sona' => 'visible_to_visitors', 'tyyp' => 'editor'));
        ?>
</legend>
	<input type="radio" name="publish" id="object_published" value="1"<?php 
        echo $site->fdat['publish'] || $objekt->all['on_avaldatud'] ? ' checked' : '';
        echo $objekt->permission && !$objekt->permission['P'] || !$objekt->permission && !$parent->permission['P'] ? ' disabled="disabled"' : NULL;
        ?>
> <label for="object_published"><?php 
        echo $site->sys_sona(array('sona' => 'published', 'tyyp' => 'editor'));
        ?>
</label><br>
	<input type="radio" name="publish" id="object_unpublished" value="0"<?php 
        echo $site->fdat['publish'] == 0 && $objekt->all['on_avaldatud'] == 0 ? ' checked' : '';
        echo $objekt->permission && !$objekt->permission['P'] || !$objekt->permission && !$parent->permission['P'] ? ' disabled="disabled"' : NULL;
        ?>
> <label for="object_unpublished"><?php 
        echo $site->sys_sona(array('sona' => 'unpublished', 'tyyp' => 'editor'));
        ?>
</label><br>
</fieldset>

<fieldset>
	<?php 
        ####### dont show checkbox "Headline is visible" if config variable "killheadlineisvisible" is true in file config.php
        if ($site->CONF['killheadlineisvisible']) {
            ?>

	<input type="hidden" id="on_pealkiri" name="on_pealkiri" value="<?php 
            echo $site->fdat['op'] == 'new' ? 1 : $objekt->all['on_pealkiri'];
            ?>
">

	<?php 
        } else {
            # by default: show it
            ?>
	<div>
		<input type="checkbox" id="on_pealkiri" name="on_pealkiri" value="1" <?php 
            echo $site->fdat['op'] == 'new' ? 'checked' : ($objekt->all['on_pealkiri'] ? 'checked' : null);
            ?>
>
		<label for="on_pealkiri"><?php 
            echo $site->sys_sona(array(sona => 'Pealkiri on nahtav', tyyp => 'editor'));
            ?>
</label>
	</div>
	<?php 
        }
        ?>
	<div>
		<input type="checkbox" name="on_foorum" id="on_foorum" value="1" <?php 
        echo $objekt->all['on_foorum'] || $site->fdat['op'] == 'new' && ($site->CONF['default_comments'] || $site->fdat['allow_comments']) ? 'checked' : null;
        ?>
>
		<label for="on_foorum"><?php 
        echo $site->sys_sona(array(sona => "Foorum lubatud", tyyp => "editor"));
        ?>
</label>
	</div>

	<?php 
        if ($site->CONF['enable_mailing_list']) {
            ## Bug #2590
            ## fuzzy logic: if editor checks here checkbox "is mailinglist",
            # then field "on_saadetud" is set to "0" and that means article is included in next mailinglist routine.
            ?>
	<div>
		  <input type="checkbox" name="on_saadetud" id="on_saadetud" value="1" <?php 
            echo $objekt->all['on_saadetud'] ? null : "checked";
            ?>
>
		  <label for="on_saadetud"><?php 
            echo $site->sys_sona(array(sona => 'On meilinglist', tyyp => 'editor'));
            ?>
</label>
	</div>
	<?php 
        }
        ?>

</fieldset>

<fieldset>
	<table cellpadding="1" cellspacing="1" border="0"  style="color: #999;">
		<?php 
        if ($objekt->all['created_user_name']) {
            ?>
		<?php 
            if ($site->CONF['allow_change_position']) {
                ?>
		<tr>
			<td><?php 
                echo $site->sys_sona(array('sona' => 'position', 'tyyp' => 'Editor'));
                ?>
:</td>
			<td>
				<input type="text" name="kesk" value="<?php 
                echo $objekt->all['kesk'];
                ?>
" style="width: 40px; text-align: right;">
			</td>
		</tr>
		<?php 
            }
            ?>
		<tr>
			<td><?php 
            echo $site->sys_sona(array('sona' => 'object_created', 'tyyp' => 'Editor'));
            ?>
:</td>
			<td><?php 
            echo date('d.m.Y H:i', strtotime($objekt->all['created_time']));
            ?>
</td>
		</tr>
		<tr>
			<td></td>
			<td><?php 
            echo $objekt->all['created_user_name'];
            ?>
</td>
		</tr>
		<?php 
        }
        ?>
		<?php 
        if ($objekt->all['changed_user_name']) {
            ?>
		<tr>
			<td><?php 
            echo $site->sys_sona(array('sona' => 'object_changed', 'tyyp' => 'Editor'));
            ?>
:</td>
			<td><?php 
            echo date('d.m.Y H:i', strtotime($objekt->all['changed_time']));
            ?>
</td>
		</tr>
		<tr>
			<td></td>
			<td><?php 
            echo $objekt->all['changed_user_name'];
            ?>
</td>
		</tr>
		<?php 
        }
        ?>
	</table>
</fieldset>




	<?php 
    }
    // end function print_profile()
    function print_sections()
    {
        global $site, $objekt, $class_path, $keel;
        $tmpkeel = $keel;
        if (!is_numeric($tmpkeel)) {
            $sql = $site->db->prepare("SELECT keel FROM objekt WHERE objekt_id=?", $site->fdat['parent_id']);
            $sth = new SQL($sql);
            $site->debug->msg($sth->debug->get_msgs());
            $tmpkeel = $sth->fetchsingle();
        }
        $sections = array($site->fdat['parent_id']);
        if ($objekt->objekt_id) {
            $sql = $site->db->prepare("SELECT parent_id FROM objekt_objekt WHERE objekt_id=?", $objekt->objekt_id);
            $result = new SQL($sql);
            while ($data = $result->fetch('ASSOC')) {
                $sections[] = $data['parent_id'];
            }
        }
        if ($site->fdat['permanent_parent_id'] == '') {
            include_once $class_path . 'rubloetelu.class.php';
            $all_sections = new RubLoetelu(array('keel' => $keel));
            $all_sections = $all_sections->get_loetelu();
            asort($all_sections);
        }
        ?>
<script type="text/javascript">
// the sections list
var all_sections = Array();

// for Mozilla the section list doesn't stretch dynamically so add this increment value to the containing elements height
var heightIncrement = 10;

function createSectionNodeSet(sectionNode, section_id, section_name)
{
	var input = document.createElement('input');
	input.type = 'hidden';
	input.name = 'rubriik[]';
	input.value = section_id;

	sectionNode.appendChild(input);

	var buttons = document.createElement('div');
	buttons.id='button_' + section_id;

	if(sectionNode.parentNode)
	{
		for(var i = 0; i < sectionNode.parentNode.childNodes.length; i++) if(sectionNode.parentNode.childNodes[i].tagName == 'LI') break;

		if(sectionNode.id != sectionNode.parentNode.childNodes[i].id)
		{
			var del_button = document.createElement('a');
			del_button.href = "javascript:deleteSection('" + section_id +"');";
			del_button.innerHTML = '<img src="<?php 
        echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
        ?>
/gfx/editor/delete.gif">';
			buttons.appendChild(del_button);
		}
	}

	sectionNode.appendChild(buttons);

	var link = document.createElement('a');
	link.href = "javascript:opopup('"+ section_id +"');";
	link.innerHTML = section_name;

	sectionNode.appendChild(link);

	return sectionNode;
}
// add a new item to the section list

function opopup(section_id){
var pre_selected='';

if(section_id !=''){
	pre_selected = '&pre_selected=' + section_id;
	explorer_window = openpopup('explorer.php?objekt_id=home&editor=1&swk_setup=current_article_parent_selection' + pre_selected, 'cms_explorer', '800','600', 'auto');
}else{
	explorer_window = openpopup('explorer.php?objekt_id=home&editor=1&swk_setup=article_parent_selection', 'cms_explorer', '800','600', 'auto');
}


}


function addNewSection(node)
{

	explorer_window.close();
		for(var j = 0; j < node.length; j++){

			var error = false;
			for(var i = 0; i < all_sections.length; i++){
			/* no duplicates */
				if (all_sections[i] == node[j].objekt_id){
					//return;
					error = true;
				}else{

				}
			}
			if(!error){

				var trail_path= new Array();

					for(var z = 0; z < node[j].trail.length; z++){
						trail_path[z] = node[j].trail[z].pealkiri;
					}

				var sections = document.getElementById('sections');

				var item = document.createElement('li');
				item.id = 'section_' + node[j].objekt_id;
				sections.appendChild(item);
				item = createSectionNodeSet(item, node[j].objekt_id, trail_path.join("->"));
				var container = document.getElementById('sections_container');
				container.height = Number(container.height) + heightIncrement;

				all_sections[all_sections.length] = node[j].objekt_id;
				}




				for(var b = 0; b < all_sections.length; b++){
					var c = all_sections[b];
					var x = document.getElementById("button_" + c);

					x.style.visibility = "visible";

				}


		}


	return;

}
// /function addNewSection

function deleteSection(section_id)
{
	var section = document.getElementById('section_' + section_id);

	section.parentNode.removeChild(section);

	var container = document.getElementById('sections_container');
	//container.height = Number(container.height) - heightIncrement;

	// delete from duplicate checklist
	var new_all_sections =new Array();

	for(var i = 0; i < all_sections.length; i++){
		if (all_sections[i] == section_id){
			all_sections[i] = null;
		}else{

			new_all_sections.push(all_sections[i]);
		}
	}
all_sections=new_all_sections;

	var c = 0;
	var d = '';

	for(var b = 0; b < all_sections.length; b++){
		if (all_sections[b] != null){
			c++;
			d=all_sections[b];
		}
	}

	if(c == 1){
		document.getElementById('button_' + d).style.visibility = 'hidden';
	}

	return;
}
// /function deleteSection

function modifySection(node,section_id)
{

	explorer_window.close();
		for(var j = 0; j < node.length; j++){

			var error = false;
			for(var i = 0; i < all_sections.length; i++){
			/* no duplicates */
				if (all_sections[i] == node[j].objekt_id){
					//return;
					error = true;
				}else{

				}
			}
			if(!error){

				var trail_path= new Array();

					for(var z = 0; z < node[j].trail.length; z++){
						trail_path[z] = node[j].trail[z].pealkiri;
					}

				var section = document.getElementById('section_' + section_id);
				section.innerHTML = '';

				section = createSectionNodeSet(section, node[j].objekt_id, trail_path.join("->"));
				section.id = 'section_' + node[j].objekt_id;

					/* delete from duplicate checklist */
						for(var i = 0; i < all_sections.length; i++) if (all_sections[i] == section_id) all_sections[i] = null;
						all_sections[all_sections.length] = node[j].objekt_id;


				}




		}


	return;
}

// /function modifySection
</script>
<?php 
        // setup for new section selection
        $_SESSION['article_parent_selection']['callback'] = 'window.opener.addNewSection';
        $_SESSION['article_parent_selection']['selectable'] = 2;
        $_SESSION['article_parent_selection']['hide_language_selection'] = '1';
        $_SESSION['article_parent_selection']['mem_classes'] = array('rubriik');
        //this sucks, really
        $_SESSION['article_parent_selection']['db_fields'] = array('select_checkbox', 'objekt_id', 'pealkiri');
        $_SESSION['article_parent_selection']['display_fields'] = array('select_checkbox', 'pealkiri');
        // setup for current section change
        $_SESSION['current_article_parent_selection']['callback'] = 'window.opener.modifySection';
        $_SESSION['current_article_parent_selection']['selectable'] = 1;
        $_SESSION['current_article_parent_selection']['hide_language_selection'] = '1';
        $_SESSION['current_article_parent_selection']['mem_classes'] = array('rubriik');
        //this sucks, really
        $_SESSION['current_article_parent_selection']['db_fields'] = array('select_checkbox', 'objekt_id', 'pealkiri');
        $_SESSION['current_article_parent_selection']['display_fields'] = array('select_checkbox', 'pealkiri');
        ?>
		<div class="sections_header">
			<div>
				<a href="#" id="new_section" onClick="opopup(''); return false;"><?php 
        echo $site->sys_sona(array(sona => "New", tyyp => "editor"));
        ?>
</a>
			</div>
			<?php 
        echo $site->sys_sona(array(sona => "Rubriigid", tyyp => "editor"));
        ?>
		</div>
		<ul id="sections" class="sections">
		<?php 
        $home_section = $site->alias(array('key' => 'rub_home_id', 'keel' => $tmpkeel));
        $i = 0;
        foreach ($all_sections as $section_id => $section_name) {
            # Bug #2264: Uuele artiklile KAKS v�i rohkem eeldefineeritud parentit (triggers)
            if ($section_id != $home_section && (in_array($section_id, $sections) || is_array($site->fdat['parents_arr']) && in_array($section_id, $site->fdat['parents_arr']))) {
                ?>
			<script type="text/javascript">
				all_sections[all_sections.length] = <?php 
                echo $section_id;
                ?>
;
			</script>
<?php 
                if ($i == 0) {
                    $first_section = $section_id;
                }
                ?>
			<li id="section_<?php 
                echo $section_id;
                ?>
">
				<input type="hidden" name="rubriik[]" value="<?php 
                echo $section_id;
                ?>
">
				<div id="button_<?php 
                echo $section_id;
                ?>
"><a href="javascript:deleteSection('<?php 
                echo $section_id;
                ?>
');"><img src="<?php 
                echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
                ?>
/gfx/editor/delete.gif"></a></div>
				<a href="javascript:opopup('<?php 
                echo $section_id;
                ?>
');"><?php 
                echo $section_name;
                ?>
</a>
			</li>
			<?php 
                $i++;
            }
        }
        ?>
		</ul>
		<?php 
        if ($i == 1) {
            ?>

			<script type="text/javascript">
					document.getElementById('button_<?php 
            echo $first_section;
            ?>
').style.visibility = 'hidden';
			</script>
		<?php 
        }
        ?>

	  <!-- /rubriigid -->
	  <?php 
    }
    /* end function print_sections2() */
    global $site, $class_path, $objekt, $tyyp, $keel;
    include_once $class_path . 'adminpage.inc.php';
    include_once $class_path . 'SCMSEditor.php';
    include_once $class_path . 'extension.class.php';
    $editor = new SCMSEditor('scms_article_editor');
    if ($site->fdat['op'] == 'new') {
        $editor->Value = '';
    } else {
        $editor->Value = ($objekt->lyhi->get_text() ? $objekt->lyhi->get_text() . '<hr class="scms_lead_body_separator" />' : '') . ($objekt->sisu->get_text() ? $objekt->sisu->get_text() : '');
        // bug #2388  Tagaside vormist eemaldada e-maili aadress, tagasiasendus
        if (preg_match_all('/<input(.*?)>/', $editor->Value, $matches)) {
            $systemfields = array();
            foreach ($matches[0] as $match) {
                if (strpos($match, 'type="hidden"') && strpos($match, 'name="systemfield"')) {
                    $systemfields[] = $match;
                }
            }
            foreach ($systemfields as $systemfield) {
                if (preg_match('/value="(.*?)\\|\\|\\|(.*?)\\|\\|\\|(.*?)\\|\\|\\|/', $systemfield, $matches)) {
                    $sql = $site->db->prepare('select mail from allowed_mails where id = ?;', $matches[1]);
                    $result = new SQL($sql);
                    $mail = $result->fetchsingle();
                    $editor->Value = str_replace('value="' . $matches[1] . '|||', 'value="' . $mail . '|||', $editor->Value);
                }
            }
        }
        // /form allowed mails check/insert
    }
    $editor->Height = '100%';
    $editor->Width = '100%';
    $editor->ToolbarSet = '';
    $editor->BasePath = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $site->CONF['hostname'] . $site->CONF['wwwroot'] . $site->CONF['js_path'] . '/fckeditor/';
    // create config array
    $Config['CustomConfigurationsPath'] = $editor->BasePath . 'scms_config.js';
    $Config['SkinPath'] = $editor->BasePath . 'editor/skins/scms/';
    $Config['ToolbarCanCollapse'] = false;
    $Config['SCMSFormName'] = $site->CONF['feedbackform_form_name'];
    $Config['SCMSFormAction'] = $site->CONF['feedbackform_action'];
    $Config['SCMSFormMethod'] = $site->CONF['feedbackform_method'];
    $Config['SCMSFormHiddenName'] = 'systemfield';
    $Config['SCMSFormHiddenString'] = $site->CONF["default_mail"] . '|||index.php?id=' . $site->alias(array('key' => "error_page", 'keel' => $keel)) . '|||index.php?id=' . $site->alias(array('key' => "ok_page", 'keel' => $keel)) . '|||' . $site->CONF["subject"];
    $default_toolbar = 'SCMS_simple';
    if ($_COOKIE['scms_toolbar']) {
        $default_toolbar = $_COOKIE['scms_toolbar'];
    }
    // load custom values for FCKeditor config
    foreach (get_extensions('DB', true) as $act_ext) {
        if (file_exists($act_ext['fullpath'] . '/extension.config.php')) {
            $EXTENSION =& load_extension_config($act_ext);
            // set the toolbar, later TODO user based toolbars
            if ($site->user->is_superuser) {
                if ($EXTENSION['wysiwyg_config']['SuperUserToolbarSet']) {
                    $editor->ToolbarSet = $EXTENSION['wysiwyg_config']['SuperUserToolbarSet'];
                } elseif ($EXTENSION['wysiwyg_config']['DefaultToolbarSet']) {
                    $editor->ToolbarSet = $EXTENSION['wysiwyg_config']['DefaultToolbarSet'];
                } else {
                    $editor->ToolbarSet = $default_toolbar;
                }
            } else {
                $roles = array();
                $sql = 'select role_id, name from roles;';
                $result = new SQL($sql);
                while ($row = $result->fetch('ASSOC')) {
                    $roles[$row[role_id]] = $row['name'];
                }
                foreach ((array) $EXTENSION['wysiwyg_config']['ToolbarSets'] as $role => $set) {
                    if ($role) {
                        $key = array_search($role, $roles);
                        if ($key !== null && in_array($key, $site->user->roles)) {
                            $editor->ToolbarSet = $set;
                            break;
                        }
                    }
                }
                if (!$editor->ToolbarSet) {
                    $EXTENSION['wysiwyg_config']['DefaultToolbarSet'] ? $editor->ToolbarSet = $EXTENSION['wysiwyg_config']['DefaultToolbarSet'] : ($editor->ToolbarSet = $default_toolbar);
                }
            }
            // set the config
            if (is_array($EXTENSION['wysiwyg_config']['Config'])) {
                $Config = array_merge($Config, $EXTENSION['wysiwyg_config']['Config']);
            }
            break;
            // get only the first
        }
    }
    if (!$editor->ToolbarSet) {
        $editor->ToolbarSet = $default_toolbar;
    }
    $editor->Config = $Config;
    // somethings are not allowed to be overwritten
    $editor->Config['PluginsPath'] = $editor->BasePath . 'editor/plugins/';
    $editor->Config['EditorAreaCSS'] = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $site->CONF['hostname'] . $site->CONF['wwwroot'] . '/styles.php?with_wysiwyg=1';
    $editor->Config['CustomStyles'] = '';
    $editor->Config['StylesXmlPath'] = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $site->CONF['hostname'] . $site->CONF['wwwroot'] . '/admin/fckstyles.php';
    $editor->Config['FormatOutput'] = false;
    $editor->Config['AutoDetectLanguage'] = false;
    $editor->Config['DefaultLanguage'] = substr($_SESSION['keel_admin']['locale'], 0, 2);
    $editor->Config['ProcessHTMLEntities'] = false;
    $editor->Config['Debug'] = false;
    //$editor->Config['FitWindow_autoFitToResize'] = true;
    $editor->Config['CurrentToolbar'] = $editor->ToolbarSet;
    //printr($editor->Config);
    //printr($editor->ToolbarSet);
    // setup for site linking
    $_SESSION['site_linking']['callback'] = 'window.opener.frames[0].site_linking';
    $_SESSION['site_linking']['selectable'] = 1;
    $_SESSION['site_linking']['mem_classes'] = array('rubriik', 'artikkel');
    //this sucks, really
    $_SESSION['site_linking']['db_fields'] = array('select_checkbox', 'objekt_id', 'pealkiri', 'klass');
    $_SESSION['site_linking']['display_fields'] = array('select_checkbox', 'pealkiri', 'klass');
    // /setup for site linking
    global $parent;
    $parent = new Objekt(array('objekt_id' => $site->fdat['parent_id']));
    // to get the correct path to parent objects set use_alises on
    $site->CONF['use_aliases'] = 1;
    $parent_href = $parent->get_object_href();
    if ($site->CONF['alias_trail_format'] == 0 || $parent->all['sys_alias'] == 'home' || $parent->all['sys_alias'] == 'trash' || $parent->all['sys_alias'] == 'system' || $parent->all['sys_alias'] == 'gallup_arhiiv') {
        $parent_href = preg_replace('#' . preg_quote('/' . ($parent->all['friendly_url'] ? $parent->all['friendly_url'] : $parent->objekt_id), '#') . '/$#', '/', $parent_href);
    }
    $parent_href = $site->CONF['hostname'] . $parent_href;
    // setup file insert
    $_SESSION['scms_filemanager_settings']['scms_wysiwyg_insert_file'] = array('select_mode' => 1, 'action_text' => $site->sys_sona(array('sona' => 'fm_choose_file_into_article', 'tyyp' => 'editor')), 'action_trigger' => $site->sys_sona(array('sona' => 'fm_insert_file_into_article', 'tyyp' => 'editor')), 'callback' => 'window.opener.frames[0].SCMSImageFileInsert');
    ?>
<html>

<head>

	<title><?php 
    echo $site->title;
    ?>
 <?php 
    echo $site->cms_version;
    ?>
</title>

	<meta http-equiv="Content-Type" content="text/html; charset=<?php 
    echo $encoding ? $encoding : $site->encoding;
    ?>
">
	<meta http-equiv="Cache-Control" content="no-cache">
	<link rel="stylesheet" href="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'] . '/article_editor.css';
    ?>
" media="screen">

	<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/yld.js"></script>
	<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/edit_popup.js"></script>
	<link rel="stylesheet" href="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/datepicker.css">
	<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/jquery.js"></script>
	<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/datepicker.js"></script>
	<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'];
    ?>
/common.js.php"></script>

	<script type="text/javascript">
	function FCKeditor_OnComplete( editorInstance )
	{
		<?php 
    if ($objekt->objekt_id) {
        ?>
		var oSCMSEditor = FCKeditorAPI.GetInstance('scms_article_editor') ;
		oSCMSEditor.Focus();
		<?php 
    } else {
        ?>
		document.frmEdit.pealkiri.focus();
		<?php 
    }
    ?>
		window.moveTo((screen.width - 880) / 2, (screen.height - 660) / 2);
		window.resizeTo(880, 660);
	}

	function editAlias()
	{
		var alias_placeholder = document.getElementById('alias_placeholder');
		var alias_value = document.getElementById('alias_value');

		alias_placeholder.innerHTML = '<input type="text" id="alias" value="' + alias_value.value + '" onblur="saveAlias();">';

		var alias = document.getElementById('alias');
		alias.focus();
	}

	function saveAlias()
	{
		var alias_placeholder = document.getElementById('alias_placeholder');
		var alias_value = document.getElementById('alias_value');
		var alias = document.getElementById('alias');

		if(alias_value.value != alias.value)
		{
			$.ajax({
			    url: 'ajax_response.php?rand=' + Math.random(9999),
			    data: {op: 'generate_alias', string: alias.value, language_id: '<?php 
    echo $keel;
    ?>
'},
			    type: 'POST',
			    dataType: 'json',
			    timeout: 1000,
			    error: function()
			    {
					alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (alias_value.value.length > 30 ? alias_value.value.substring(0, 30) + '...' : alias_value.value) + '</a>';
			    },
			    success: function(response)
			    {
			    	if(response.alias)
			    	{
						alias_value.value = response.alias;
						alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (alias_value.value.length > 30 ? alias_value.value.substring(0, 30) + '...' : alias_value.value) + '</a>';
			    	}
			    	else
			    	{
						alias_value.value = '';
						<?php 
    if ($objekt->objekt_id) {
        ?>
						alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + '<?php 
        echo $objekt->objekt_id;
        ?>
' + '</a>';
						<?php 
    } else {
        ?>
				    	alias_placeholder.innerHTML = '<input type="text" id="alias" value="" onblur="saveAlias();">';
						<?php 
    }
    ?>
			    	}
			    }
			});
		}
		else
		{
			if(!alias.value)
			{
				alias_value.value = '';
				<?php 
    if ($objekt->objekt_id) {
        ?>
				alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + '<?php 
        echo $objekt->objekt_id;
        ?>
' + '</a>';
				<?php 
    } else {
        ?>
		    	alias_placeholder.innerHTML = '<input type="text" id="alias" value="" onblur="saveAlias();">';
				<?php 
    }
    ?>
			}
			else
			{
				alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (alias_value.value.length > 30 ? alias_value.value.substring(0, 30) + '...' : alias_value.value) + '</a>';
			}
		}

	}

	function createAlias()
	{
		var alias_value = document.getElementById('alias_value');
		var title = document.getElementById('pealkiri')

		if(0 || (!alias_value && title.value))
		{
			$.ajax({
			    url: 'ajax_response.php?rand=' + Math.random(9999),
			    data: {op: 'generate_alias', string: title.value, language_id: '<?php 
    echo $keel;
    ?>
'},
			    type: 'POST',
			    dataType: 'json',
			    timeout: 1000,
			    error: function()
			    {
			    },
			    success: function(response)
			    {

			    	var alias_cell = document.getElementById('alias_cell');
			    	alias_cell.className = 'alias';
			    	if(response.alias)
			    	{
				    	alias_cell.innerHTML = '<input type="hidden" name="friendly_url" id="alias_value" value="' + response.alias + '"><?php 
    echo $parent_href;
    ?>
<span id="alias_placeholder"><a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (response.alias.length > 30 ? response.alias.substring(0, 30) + '...' : response.alias) + '</a></span>';
			    	}
			    	else
			    	{
				    	alias_cell.innerHTML = '<input type="hidden" name="friendly_url" id="alias_value" value=""><?php 
    echo $parent_href;
    ?>
<span id="alias_placeholder"><input type="text" id="alias" value="" onblur="saveAlias();"></span>';
			    	}
			    }
			});
		}
	}

	function saveForm(op2)
	{
		var form = document.getElementById('frmEdit');

		var title = document.getElementById('pealkiri')
		var alias_value = document.getElementById('alias_value');
		var alias = document.getElementById('alias');

		if((title.value && !alias_value) || (alias && alias_value && alias.value != alias_value.value))
		{
			$.ajax({
			    url: 'ajax_response.php?rand=' + Math.random(9999),
			    data: {op: 'generate_alias', string: title.value, language_id: '<?php 
    echo $keel;
    ?>
'},
			    type: 'POST',
			    dataType: 'json',
			    timeout: 1000,
			    error: function()
			    {
			    	var form = document.getElementById('frmEdit');

			    	form.op2.value = op2;
	 				form.submit();
			    },
			    success: function(response)
			    {
			    	var alias_value = document.getElementById('alias_value');

			    	if(!alias_value && response.alias)
			    	{
				    	var alias_cell = document.getElementById('alias_cell');
				    	alias_cell.className = 'alias';
				    	alias_cell.innerHTML = '<input type="hidden" name="friendly_url" id="alias_value" value="' + response.alias + '"><?php 
    echo $parent_href;
    ?>
<span id="alias_placeholder"><a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (response.alias.length > 30 ? response.alias.substring(0, 30) + '...' : response.alias) + '</a></span>';
			    	}

			    	var form = document.getElementById('frmEdit');

			    	form.op2.value = op2;
	 				form.submit();
			    }
			});
		}
		else
		{
				form.op2.value = op2;
				form.submit();
		}
	}
	</script>

	<?php 
    if ($editor->browser() == 'Gecko') {
        ?>
	<style type="text/css">
		table.layout td.editor div {
			height: 100%;
		}
	</style>
	<?php 
    }
    ?>

</head>

<body id="scms_editor_popup">

	<form action="edit.php" method="POST" name="frmEdit" id="frmEdit" class="article_submit_form">
		
		<?php 
    create_form_token('edit-article');
    ?>
		
		<input type=hidden name="op" value="<?php 
    echo $site->fdat['op'];
    ?>
">
		<input type=hidden name="op2" id="op2" value="saveclose">
		<input type=hidden name="refresh" value="0">

		<input type="hidden" name="tyyp_id" value="<?php 
    echo $tyyp['tyyp_id'];
    ?>
">
		<input type="hidden" name="tyyp" value="<?php 
    echo $tyyp['klass'];
    ?>
">
		<input type="hidden" name="sys_alias" value="<?php 
    echo $site->fdat['sys_alias'];
    ?>
">

		<input type="hidden" name="id" value="<?php 
    echo $site->fdat['id'];
    ?>
">
		<input type="hidden" name="kesk" value="<?php 
    echo $site->fdat['kesk'];
    ?>
">
		<input type="hidden" name="parent_id" value="<?php 
    echo $site->fdat['parent_id'];
    ?>
">
		<input type="hidden" name="previous_id" value="<?php 
    echo $site->fdat['previous_id'];
    ?>
">
		<input type="hidden" name="keel" value="<?php 
    echo $keel;
    ?>
">
		<input type="hidden" name="baseurl" value="<?php 
    echo (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $site->CONF['hostname'] . $site->CONF['wwwroot'];
    ?>
/">
		<input type="hidden" name="wwwroot" value="<?php 
    echo $site->CONF['wwwroot'];
    ?>
/">

        <input type="hidden" name="sorting" value="<?php 
    echo $site->fdat['sorting'];
    ?>
">

		<input type="hidden" name="extension_path" value="<?php 
    echo $site->fdat['extension_path'];
    ?>
">
		
		<input type="hidden" name="publish" value="<?php 
    echo $site->fdat['publish'] || $objekt->all['on_avaldatud'] ? 1 : 0;
    ?>
">

	<table cellpadding="0" cellspacing="0" class="layout" border="0">
		<tr>
			<td>
				<table cellpadding="0" cellspacing="0" class="layout" border="0">
					<tr>
						<td class="header">
							<table cellpadding="0" cellspacing="0" border="0">
								<tr>
									<td style="	font-size: 12px;font-weight: bold;"><label for="pealkiri"><?php 
    echo $site->sys_sona(array('sona' => 'Pealkiri', 'tyyp' => 'editor'));
    ?>
:&nbsp;</label></td>
									<td width="100%"><input type="text" tabindex="1" id="pealkiri" name="pealkiri" value="<?php 
    echo htmlspecialchars($objekt->pealkiri);
    ?>
" onblur="createAlias();"></td>
								</tr>
							</table>
						</td>
					</tr>
					<?php 
    if ($objekt->objekt_id) {
        ?>
					<tr>
						<td class="alias"><input type="hidden" name="friendly_url" id="alias_value" value="<?php 
        echo htmlspecialchars($objekt->all['friendly_url']);
        ?>
"><?php 
        echo $parent_href;
        ?>
<span id="alias_placeholder"><a href="javascript:void(0);" onclick="editAlias();" id="alias_link"><?php 
        echo $objekt->all['friendly_url'] ? strlen(htmlspecialchars($objekt->all['friendly_url'])) > 30 ? substr(htmlspecialchars($objekt->all['friendly_url']), 0, 30) . '...' : htmlspecialchars($objekt->all['friendly_url']) : $objekt->objekt_id;
        ?>
</a></span></td>
					</tr>
					<?php 
    } else {
        ?>
					<tr>
						<td id="alias_cell" class="alias">&nbsp;</td>
					</tr>
					<?php 
    }
    ?>
					<tr>
						<td class="editor">
							<?php 
    echo $editor->Create();
    ?>
						</td>
					</tr>
					<tr>
						<td id="sections_container" class="sections">
							<?php 
    echo print_sections();
    ?>
						</td>
					</tr>
				</table>
			</td>
			<td class="profiles">
				<?php 
    echo print_profiles();
    ?>
			</td>
		</tr>
	</table>


	</form>
	<?php 
    if ($site->fdat['op'] == 'edit') {
        ?>
		<iframe src="checkin.php?objekt_id=<?php 
        echo $objekt->objekt_id;
        ?>
" style="width: 0; height: 0; display: none; visibility: hidden;"></iframe>
	<?php 
    }
    ?>

</body>

</html>

<?php 
}
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/scms_general.css">
<SCRIPT LANGUAGE="JavaScript" SRC="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/yld.js"></SCRIPT>
</head>
	<body class="popup_body" onLoad="this.focus()">

	<form name="editform" action="<?php 
    echo $site->self;
    ?>
" method=get>
		<?php 
    create_form_token('delete-comments');
    ?>
<table border="0" cellpadding="0" cellspacing="0" style="width:100%; height:100%">
  <tr> 
	<td valign="top" width="100%" class="scms_confirm_delete_cell" height="100%">
<?php 
    $objekt->load_sisu();
    echo $site->sys_sona(array(sona => "kustuta", tyyp => "editor")) . " \"<b>" . substr($objekt->all['text'], 0, 20) . (strlen($objekt->all['text']) > 20 ? '...' : '') . "</b>\"? ";
    echo $site->sys_sona(array(sona => "are you sure?", tyyp => "admin"));
    ?>
	</td>
  </tr>
  <tr align="right"> 
    <td valign="top" colspan=2 > 
            <input type="button" value="<?php 
    echo $site->sys_sona(array(sona => "kustuta", tyyp => "editor"));
/**
 * This source file is is part of Saurus CMS content management software.
 * It is licensed under MPL 1.1 (http://www.opensource.org/licenses/mozilla1.1.php).
 * Copyright (C) 2000-2010 Saurused Ltd (http://www.saurus.info/).
 * Redistribution of this file must retain the above copyright notice.
 * 
 * Please note that the original authors never thought this would turn out
 * such a great piece of software when the work started using Perl in year 2000.
 * Due to organic growth, you may find parts of the software being
 * a bit (well maybe more than a bit) old fashioned and here's where you can help.
 * Good luck and keep your open source minds open!
 * 
 * @package		SaurusCMS
 * @copyright	2000-2010 Saurused Ltd (http://www.saurus.info/)
 * @license		Mozilla Public License 1.1 (http://www.opensource.org/licenses/mozilla1.1.php)
 * 
 */
function edit_objekt()
{
    global $site;
    global $objekt;
    global $keel;
    global $class_path;
    global $tyyp;
    // refreshing (fdat['refresh'] = 1) looses object data, I don't know why and because it's done in edit_object.php, I'm not going to fix it, lord knows what it'll screw up
    if ($site->fdat['refresh'] && $site->fdat['id']) {
        $obj = new Objekt(array('objekt_id' => $site->fdat['id']));
        $objekt->objekt_id = $obj->objekt_id;
        $objekt->parent_id = $obj->parent_id;
    }
    $parent = new Objekt(array('objekt_id' => $objekt->objekt_id ? $objekt->parent_id : $site->fdat['parent_id']));
    $pearubriik = $parent->all['sys_alias'] == 'home' ? 1 : 0;
    // parent path
    if ($objekt->all['sys_alias'] == '' && $site->fdat['sys_alias'] == '') {
        // this needs serious rethink and optmisation: there's no need to get the entire tree, parent object's path to top is only needed
        include_once $class_path . 'rubloetelu.class.php';
        $rubs = new RubLoetelu(array('keel' => $keel, 'required_perm' => 'C', 'ignore_perm_for_obj' => $parent->objekt_id));
        #$rubs->debug->print_msg();
        $topparents = $rubs->get_loetelu();
        if (is_array($topparents)) {
            asort($topparents);
        }
        foreach ($topparents as $k => $v) {
            if ($parent->objekt_id == $k) {
                $section_name = $v;
                break;
            }
        }
    }
    // publishing
    $publish_start = $objekt->all['avaldamisaeg_algus'] > 0 ? $site->db->MySQL_ee_long($objekt->all['avaldamisaeg_algus']) : '';
    /* Don't print out time which is 00:00:00 */
    if (preg_match("/(\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d?\\d\\d)\\s(\\d?\\d)[\\:\\\\.\\/\\-](\\d?\\d)/", $publish_start, $aa_reg)) {
        $publish_start = $aa_reg[2] == "00" && $aa_reg[3] == "00" ? $aa_reg[1] : $publish_start;
    }
    $publish_end = $objekt->all['avaldamisaeg_lopp'] > 0 ? $site->db->MySQL_ee_long($objekt->all['avaldamisaeg_lopp']) : '';
    /* Don't print out time which is 23:59 */
    if (preg_match("/(\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d?\\d\\d)\\s(\\d?\\d)[\\:\\\\.\\/\\-](\\d?\\d)/", $publish_end, $la_reg)) {
        $publish_end = $la_reg[2] == "23" && $la_reg[3] == "59" ? $la_reg[1] : $publish_end;
    }
    // to get the correct path to parent objects set use_alises on
    $site->CONF['use_aliases'] = 1;
    $parent_href = $parent->get_object_href();
    if ($site->CONF['alias_trail_format'] == 0 || $parent->all['sys_alias'] == 'home' || $parent->all['sys_alias'] == 'trash' || $parent->all['sys_alias'] == 'system' || $parent->all['sys_alias'] == 'gallup_arhiiv') {
        $parent_href = preg_replace('#' . preg_quote('/' . ($parent->all['friendly_url'] ? $parent->all['friendly_url'] : $parent->objekt_id), '#') . '/$#', '/', $parent_href);
    }
    $parent_href = $site->CONF['hostname'] . $parent_href;
    // setup for section selection
    $_SESSION['parent_selection']['callback'] = 'window.opener.updateSection';
    $_SESSION['parent_selection']['selectable'] = 1;
    $_SESSION['parent_selection']['hide_language_selection'] = '1';
    $_SESSION['parent_selection']['mem_classes'] = array('rubriik');
    //this sucks, really
    $_SESSION['parent_selection']['db_fields'] = array('select_checkbox', 'objekt_id', 'pealkiri');
    $_SESSION['parent_selection']['display_fields'] = array('select_checkbox', 'pealkiri');
    // setup folder select
    $_SESSION['scms_filemanager_settings']['scms_select_album_folder'] = array('select_mode' => 2, 'action_text' => $site->sys_sona(array('sona' => 'use_this_folder_for_album', 'tyyp' => 'editor')), 'action_trigger' => $site->sys_sona(array('sona' => 'use_this_folder_for_album', 'tyyp' => 'editor')), 'callback' => 'window.opener.setFolder');
    $conf = new CONFIG($objekt->all['ttyyp_params']);
    $args['cols'] = $conf->get('cols');
    $args['rows'] = $conf->get('rows');
    $args['path'] = $conf->get('path');
    //$args['path'] = 1;
    $args['tn_size'] = $conf->get('tn_size');
    $args['desc'] = $conf->get('desc');
    $args['pic_size'] = $conf->get('pic_size');
    $args['folder_id'] = $conf->get('folder_id');
    if (!$args['path']) {
        if ($objekt->all['pealkiri']) {
            $album_folder_path = $clean_path = create_alias_from_string($objekt->all['pealkiri']);
        } else {
            $result = new SQL('select max(objekt_id) + 1 from objekt');
            $album_folder_path = $clean_path = $result->fetchsingle();
        }
        $supplement = 2;
        // unlikely to happen
        if ($album_folder_path === '') {
            $album_folder_path = $clean_path = rand(10000, 20000);
        }
        while (file_exists($site->absolute_path . '/public/galleries/' . $album_folder_path)) {
            $album_folder_path = create_alias_from_string($clean_path . '-' . $supplement);
            $supplement++;
            // guard, also unlikely
            if ($supplement > 1000) {
                exit;
            }
        }
        $album_folder_path = 'public/galleries/' . $album_folder_path;
    }
    //printr($album_folder_path);
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
	<head> 	
		<title><?php 
    echo $site->title;
    ?>
 <?php 
    echo $site->cms_version;
    ?>
</title>
		
		<meta http-equiv="Content-Type" content="text/html; charset=<?php 
    echo $encoding ? $encoding : $site->encoding;
    ?>
" />
		<meta http-equiv="Cache-Control" content="no-cache" />
		
		<link rel="stylesheet" href="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/datepicker.css" />
		<link rel="stylesheet" href="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/album_editor.css" />
		<!--[if IE 6]>
			<style type="text/css">
				input.inline_button {
					padding: 0px 0px 0px 0px;
					height: 21px;
				}
			</style>
		<![endif]-->
		<!--[if IE 7]>
			<style type="text/css">
				input.inline_button {
					padding: 0px 0px 0px 0px;
					height: 21px;
				}
			</style>
		<![endif]-->
		
		<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/yld.js"></script>
		<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/edit_popup.js"></script>
		<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/jquery.js"></script>
		<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/datepicker.js"></script>
		<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'];
    ?>
/common.js.php"></script>
		<?php 
    if ($site->CONF['fm_allow_multiple_upload'] && $parent->all['ttyyp_id'] != 39) {
        ?>
		<script type="text/javascript" src="<?php 
        echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
        ?>
/swfupload/swfupload.js"></script>
		<script type="text/javascript" src="<?php 
        echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
        ?>
/swfupload/swfupload.queue.js"></script>
		<?php 
    }
    ?>
		
		<script type="text/javascript">
			var isIE = navigator.appVersion.match(/MSIE/); // assume gecko on false
			
			var folder_path = '<?php 
    echo $album_folder_path;
    ?>
';
			
			var ajax_token = <?php 
    echo create_form_token_json('edit-album-ajax');
    ?>
;
			
			var swfu;
			
			window.onload = function ()
			{
				var title = document.getElementById('pealkiri');
				
				var advanced_panel_state = document.getElementById('advanced_panel_state');
				if(advanced_panel_state.value == 1)
				{
					togglePanel('advanced');
				}
				
				this.focus();
				title.focus();
				
				resizeWindow();
				
				<?php 
    if ($site->CONF['fm_allow_multiple_upload'] && $parent->all['ttyyp_id'] != 39) {
        ?>
				
				var post_params = {'<?php 
        echo session_name();
        ?>
' : '<?php 
        echo session_id();
        ?>
', 'op': 'add_image_to_album'};
				$.extend(post_params, ajax_token);
				
				swfu = new SWFUpload({
					flash_url : '<?php 
        echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
        ?>
/swfupload/swfupload.swf',
					upload_url: '<?php 
        echo $site->CONF['wwwroot'];
        ?>
/admin/ajax_response.php',
					post_params: post_params,
					file_size_limit : '<?php 
        echo is_int(ini_get('upload_max_filesize')) ? round(ini_get('upload_max_filesize') / 1024) : ini_get('upload_max_filesize') . 'B';
        ?>
',
					file_types : '*.gif;*.png;*.jpeg;*.jpg',
					file_types_description : 'Images',
					file_upload_limit : 0,
					file_queue_limit : 100,
					custom_settings : {
						cancelButtonId : 'cancel_file_upload_button'
					},
					debug: false,
			
					// Button settings
					button_image_url: '<?php 
        echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
        ?>
/gfx/general/album_upload_button_bg.gif',	// Relative to the Flash file
					button_width: '95',
					button_height: '21',
					button_placeholder_id: 'span_upload_button_place_holder',
					button_text: '<?php 
        echo $site->sys_sona(array('sona' => 'add_images', 'tyyp' => 'editor'));
        ?>
',
					button_text_left_padding: 8,
					button_text_top_padding: 1,
					button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,
					
					// The event handler functions
					swfupload_loaded_handler: swfuLoaded,
					file_queued_handler : fileQueued,
					file_queue_error_handler : fileQueueError,
					file_dialog_complete_handler : fileDialogComplete,
					upload_start_handler : uploadStart,
					upload_progress_handler : uploadProgress,
					upload_error_handler : uploadError,
					upload_success_handler : uploadSuccess,
					upload_complete_handler : uploadComplete
					//queue_complete_handler : queueComplete	// Queue plugin event
				});
				<?php 
    }
    ?>
				}
			
			function resizeWindow()
			{
        if(jQuery.browser.webkit)
        {
          window.resizeTo(580, 380);
        }
        else
        {
          resizeWindowTo($('#size_wrapper').width(), $('#size_wrapper').height());
        }
			}
			
			var filemanager_window;
			var uploadFolderPathSet = false;

			function chooseFolder()
			{
				filemanager_window = openpopup('filemanager.php?setup=scms_select_album_folder', 'filemanager', 980, 600);
			}
			
			function setFolder(data)
			{
				filemanager_window.close();
				uploadFolderPathSet = true;
				
				$('input#path').attr('value', data.folders[0].relative_path.replace(/^\//, ''));
				$('a#images_folder_path_link').text(data.folders[0].relative_path.replace(/^\//, ''));
				
				$('td#images_folder_cf_container_cell').removeClass('hidden');
				$('td#images_choose_folder_button_cell').addClass('hidden');
			}
			
			
			function clearFolder()
			{
				$('input#path').attr('value', '');
				
				$('td#images_folder_cf_container_cell').addClass('hidden');
				$('td#images_choose_folder_button_cell').removeClass('hidden');
				
				resizeWindow();
			}
			
			function chooseSection()
			{
				explorer_window = openpopup('explorer.php?objekt_id=home&editor=1&swk_setup=parent_selection&remove_objects=<?php 
    echo $site->fdat['id'];
    ?>
&pre_selected=' + document.getElementById('rubriik').value, 'cms_explorer', '800','600');
			}
			
			function updateSection(sections)
			{
				explorer_window.close();
				var section_name = document.getElementById('section_name');
				var section_id = document.getElementById('rubriik');
				var trail_path= new Array();

					for(var j = 0; j < sections[0].trail.length; j++){
						trail_path[j] = sections[0].trail[j].pealkiri;
					}

				section_name.innerHTML = '<a href="javascript:chooseSection();">' + trail_path.join("->") + '</a>';
				section_id.value = sections[0].objekt_id;
			}

			function editAlias()
			{
				var alias_placeholder = document.getElementById('alias_placeholder');
				var alias_value = document.getElementById('alias_value');
				
				alias_placeholder.innerHTML = '<input type="text" id="alias" value="' + alias_value.value + '" onblur="saveAlias();">';
				
		    	resizeWindow();
		    	
				var alias = document.getElementById('alias');
				alias.focus();
			}
			
			function saveAlias()
			{
				var alias_placeholder = document.getElementById('alias_placeholder');
				var alias_value = document.getElementById('alias_value');
				var alias = document.getElementById('alias');
				
				if(alias_value.value != alias.value)
				{
					$.ajax({
					    url: 'ajax_response.php?rand=' + Math.random(9999),
					    data: {op: 'generate_alias', string: alias.value, language_id: '<?php 
    echo $keel;
    ?>
'},
					    type: 'POST',
					    dataType: 'json',
					    timeout: 1000,
					    error: function()
					    {
							alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (alias_value.value.length > 30 ? alias_value.value.substring(0, 30) + '...' : alias_value.value) + '</a>';
					    },
					    success: function(response)
					    {
					    	if(response.alias)
					    	{
								alias_value.value = response.alias;
								alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (alias_value.value.length > 30 ? alias_value.value.substring(0, 30) + '...' : alias_value.value) + '</a>';
					    	}
					    	else
					    	{
								alias_value.value = '';
								<?php 
    if ($objekt->objekt_id) {
        ?>
								alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + '<?php 
        echo $objekt->objekt_id;
        ?>
' + '</a>';
								<?php 
    } else {
        ?>
						    	alias_placeholder.innerHTML = '<input type="text" id="alias" value="" onblur="saveAlias();">';
								<?php 
    }
    ?>
					    	}
							
					    	resizeWindow();
					    }
					});
				}
				else
				{
					if(!alias.value)
					{
						alias_value.value = '';
						<?php 
    if ($objekt->objekt_id) {
        ?>
						alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + '<?php 
        echo $objekt->objekt_id;
        ?>
' + '</a>';
						<?php 
    } else {
        ?>
				    	alias_placeholder.innerHTML = '<input type="text" id="alias" value="" onblur="saveAlias();">';
						<?php 
    }
    ?>
					}
					else
					{
						alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (alias_value.value.length > 30 ? alias_value.value.substring(0, 30) + '...' : alias_value.value) + '</a>';
					}
			    	
					resizeWindow();
				}
			}
			
			function createAlias()
			{
				var alias_value = document.getElementById('alias_value');
				var title = document.getElementById('pealkiri')
				
				if(0 || (!alias_value && title.value))
				{
					$.ajax({
					    url: 'ajax_response.php?rand=' + Math.random(9999),
					    data: {op: 'generate_alias', string: title.value, language_id: '<?php 
    echo $keel;
    ?>
'},
					    type: 'POST',
					    dataType: 'json',
					    timeout: 1000,
					    error: function()
					    {
					    },
					    success: function(response)
					    {
					    	var alias_cell = document.getElementById('alias_cell');
					    	alias_cell.className = 'alias';
					    	if(response.alias)
					    	{
						    	alias_cell.innerHTML = '<input type="hidden" name="friendly_url" id="alias_value" value="' + response.alias + '"><?php 
    echo $parent_href;
    ?>
<span id="alias_placeholder"><a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (response.alias.length > 30 ? response.alias.substring(0, 30) + '...' : response.alias) + '</a></span>';
						    	if(swfu && !swfu.uploadFolderPathSent && !uploadFolderPathSet) $('input#path').attr('value', 'public/galleries/' + response.alias);
					    	}
					    	else
					    	{
						    	alias_cell.innerHTML = '<input type="hidden" name="friendly_url" id="alias_value" value=""><?php 
    echo $parent_href;
    ?>
<span id="alias_placeholder"><input type="text" id="alias" value="" onblur="saveAlias();"></span>';
					    	}
					    	
					    	$('a#images_folder_path_link').text($('input#path').attr('value'));
					    	
					    	$('#alias_row').show();
					    	//var alias_row = document.getElementById('alias_row');
					    	//alias_row.style.display = (isIE ? 'block' : 'table-row');

	    					resizeWindow();
					    }
					});			
				}
			}
			
			function saveForm(op2)
			{
				var form = document.getElementById('editForm');
				
				var title = document.getElementById('pealkiri');
				
				if(title.value.length == 0)
				{
					alert('<?php 
    echo $site->sys_sona(array('sona' => 'please_fill_in_the_title!', 'tyyp' => 'admin'));
    ?>
');
					return;
				}
				
				var alias_value = document.getElementById('alias_value');
				var alias = document.getElementById('alias');
				
				if((title.value && !alias_value) || (alias && alias_value && alias.value != alias_value.value))
				{
					$.ajax({
					    url: 'ajax_response.php?rand=' + Math.random(9999),
					    data: {op: 'generate_alias', string: title.value, language_id: '<?php 
    echo $keel;
    ?>
'},
					    type: 'POST',
					    dataType: 'json',
					    timeout: 1000,
					    error: function()
					    {
					    	var form = document.getElementById('editForm');
			 				
					    	form.op2.value = op2;
			 				form.submit();
					    },
					    success: function(response)
					    {
					    	var alias_value = document.getElementById('alias_value');
					    	
					    	if(!alias_value && response.alias)
					    	{
						    	var alias_cell = document.getElementById('alias_cell');
						    	alias_cell.innerHTML = '<input type="hidden" name="friendly_url" id="alias_value" value="' + response.alias + '"><?php 
    echo $parent_href;
    ?>
<span id="alias_placeholder"><a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (response.alias.length > 30 ? response.alias.substring(0, 30) + '...' : response.alias) + '</a></span>';
					    	}
							
					    	var form = document.getElementById('editForm');
			 				
					    	form.op2.value = op2;
			 				form.submit();
					    }
					});
				}
				else
				{
	 				form.op2.value = op2;
	 				form.submit();
				}
			}
			
			<?php 
    if ($site->CONF['fm_allow_multiple_upload'] && $parent->all['ttyyp_id'] != 39) {
        ?>
			// SWFupload handler functions
			function fileQueued(file) {
				try {
				} catch (ex) {
					this.debug(ex);
				}
			}
			

			function fileQueueError(file, errorCode, message) {
				try {
					
					if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
						alert('<?php 
        echo $site->sys_sona(array('sona' => 'upload_queue_limit', 'tyyp' => 'Files'));
        ?>
' + ': ' + this.settings.file_queue_limit);
						return;
					}
				
					if (errorCode === SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT) {
						alert(file.name + ' ' + '<?php 
        echo $site->sys_sona(array('sona' => 'upload_limit_size', 'tyyp' => 'Files'));
        ?>
' + ' ' + this.settings.file_size_limit);
						return;
					}
			
					switch (errorCode) {
					default:
						if (file !== null) {
							alert("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
						}
						this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
						break;
					}
				} catch (ex) {
			        this.debug(ex);
			    }
			}
			
			function fileDialogComplete(numFilesSelected, numFilesQueued) {
				try {
					
					if(numFilesQueued > 0)
					{
						$('td#images_folder_cf_container_cell').addClass('hidden');
						$('td#images_choose_folder_button_cell').addClass('hidden');
						$('table#form_submit_buttons_table').addClass('hidden');
						
						this.setButtonDisabled(true);
						this.setButtonDimensions(1, 1);
						
						$('td#upload_progress_cell').removeClass('hidden');
						$('td#upload_progress_text_cell').removeClass('hidden');
						$('table#upload_cancel_table').removeClass('hidden');
						
						$('div#upload_progress_grow').width(0);
						
						this.numFilesQueued = numFilesQueued;
						
						if(!$('input#path').attr('value')) $('input#path').attr('value', folder_path);
						
						this.addPostParam('folder_path', $('input#path').attr('value'));
						this.uploadFolderPathSent = true;
						this.startUpload();
					}
				} catch (ex)  {
			        this.debug(ex);
				}
			}
			
			function uploadStart(file) {
				try {
					
					$('td#upload_progress_text_cell').html(file.name + ' <span id="percent_placeholder">0</span>%');
					this.progressBarWidth = $('div#upload_progress_grow').width();
					
				} catch (ex)  {
			        this.debug(ex);
				}
				
				return true;
			}
			
			function uploadProgress(file, bytesLoaded, bytesTotal) {
				try {
					var percent = Math.round((bytesLoaded / bytesTotal) * 100);
					
					$('div#upload_progress_grow').width(this.progressBarWidth + Math.round(($('div#upload_progress_bar').width() / this.numFilesQueued * percent) / 100));
					
					$('span#percent_placeholder').html(percent);
					
				} catch (ex) {
					this.debug(ex);
				}
			}
			
			function uploadSuccess(file, serverData) {
				try {
				} catch (ex) {
					this.debug(ex);
				}
			}
			
			function uploadError(file, errorCode, message) {
				try {
					
					switch (errorCode) {
						case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
						case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
							// upload canceled
						break;
						
						case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
							alert('Error occured while trying to connect.');
						break;
						
						default:
							alert("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
						break;
					}
				} catch (ex) {
			        this.debug(ex);
			    }
			}
			
			function uploadComplete(file) {
				
				$('td#upload_progress_text_cell').empty();
				
				if (this.getStats().files_queued === 0) {
					
					// all files are finished
					$('td#upload_progress_cell').addClass('hidden');
					$('td#upload_progress_text_cell').addClass('hidden');
					$('table#upload_cancel_table').addClass('hidden');
						
					this.setButtonDisabled(false);
					this.setButtonDimensions(95, 21);
					
					$('a#images_folder_path_link').text($('input#path').attr('value'));
					
					$('table#form_submit_buttons_table').removeClass('hidden');
					$('td#images_folder_cf_container_cell').removeClass('hidden');
				}
			}
			
			function swfuLoaded()
			{
				$('input#add_images_button').addClass('hidden');
			}
			<?php 
    }
    ?>
			
		</script>
	</head>
	
	<body>
		
		<?php 
    if ($site->fdat['op'] == 'edit') {
        ?>
			<iframe src="checkin.php?objekt_id=<?php 
        echo $objekt->objekt_id;
        ?>
" style="width: 0; height: 0; display: none; visibility: hidden;"></iframe>
		<?php 
    }
    ?>
		
		<form action="edit.php" name="editForm" id="editForm" method="POST"  enctype="multipart/form-data">
		
		<?php 
    create_form_token('edit-album');
    ?>
		
		<input type="hidden" name="tab" value="<?php 
    echo $site->fdat['tab'];
    ?>
" />
		<input type="hidden" id="op" name="op" value="<?php 
    echo htmlspecialchars($site->fdat['op']);
    ?>
" />
		<input type="hidden" id="op2" name="op2" value="" />
		<input type="hidden" id="refresh" name="refresh" value="0" />
		
		<input type="hidden" name="tyyp_id" value="<?php 
    echo $tyyp['tyyp_id'];
    ?>
" />
		<input type="hidden" name="tyyp" value="<?php 
    echo $tyyp['klass'];
    ?>
" />
		
		<input type="hidden" name="pearubriik" value="<?php 
    echo $pearubriik;
    ?>
" />
		<input type="hidden" name="id" value="<?php 
    echo $site->fdat['id'];
    ?>
" />
		<input type="hidden" name="parent_id" value="<?php 
    echo $site->fdat['parent_id'];
    ?>
" />
		<input type="hidden" name="previous_id" value="<?php 
    echo $site->fdat['previous_id'];
    ?>
" />
		<input type="hidden" name="keel" value="<?php 
    echo $keel;
    ?>
" />
		<input type="hidden" name="on_pealkiri" value="1" />
		
        <input type="hidden" name="sorting" value="<?php 
    echo $site->fdat['sorting'];
    ?>
">

		<input type="hidden" name="opener_location" value="" />
		<input type="hidden" name="publish" value="<?php 
    echo $site->fdat['publish'] || $objekt->all['on_avaldatud'] ? 1 : 0;
    ?>
">

		<input name="permanent_parent_id" type="hidden" value="<?php 
    echo $objekt->parent_id;
    ?>
" />
		<input name="sys_alias" type="hidden" value="<?php 
    echo $site->fdat['sys_alias'] ? $site->fdat['sys_alias'] : $objekt->all['sys_alias'];
    ?>
" />
		
		<input name="advanced_panel_state" id="advanced_panel_state" type="hidden" value="<?php 
    echo $site->fdat['advanced_panel_state'] ? htmlspecialchars($site->fdat['advanced_panel_state']) : 0;
    ?>
" />
		
		<div id="size_wrapper" class="section_editor">
		
		<div id="main_container">
			<?php 
    ########### Tabs  ########
    ?>
			<div id="tab_container">
				<a href="javascript:void(0);" class="selected"><?php 
    echo $site->sys_sona(array('sona' => 'tyyp_album', 'tyyp' => 'System'));
    ?>
</a>
			</div>
			
			<div id="content_container">
		
				<table cellpadding="0" cellspacing="0" class="form_row">
					<tr>
						<td class="label"><label><?php 
    echo $site->sys_sona(array('sona' => 'Pealkiri', 'tyyp' => 'editor'));
    ?>
:</label></td>
						<td class="input"><input type="text" class="text" name="pealkiri" id="pealkiri" value="<?php 
    echo htmlspecialchars($objekt->all['pealkiri']);
    ?>
" onblur="createAlias();" /></td>
					</tr>
					<?php 
    if (($objekt->objekt_id || isset($objekt->all['friendly_url'])) && !($objekt->all['sys_alias'] == 'home' || $objekt->all['sys_alias'] == 'trash' || $objekt->all['sys_alias'] == 'system' || $objekt->all['sys_alias'] == 'gallup_arhiiv')) {
        ?>
					<tr>
						<td class="label">&nbsp;</td>
						<td class="input"><input type="hidden" id="alias_value" name="friendly_url" name="friendly_url" value="<?php 
        echo htmlspecialchars($objekt->all['friendly_url']);
        ?>
" /><?php 
        echo $parent_href;
        ?>
<span id="alias_placeholder"><a href="javascript:void(0);" onclick="editAlias();" id="alias_link"><?php 
        echo $objekt->all['friendly_url'] ? strlen(htmlspecialchars($objekt->all['friendly_url'])) > 30 ? substr(htmlspecialchars($objekt->all['friendly_url']), 0, 30) . '...' : htmlspecialchars($objekt->all['friendly_url']) : $objekt->objekt_id;
        ?>
</a></span></td>
					</tr>
					<?php 
    } else {
        ?>
					<tr id="alias_row">
						<td class="label">&nbsp;</td>
						<td class="input" id="alias_cell"></td>
					</tr>
					<?php 
    }
    ?>
					
					<?php 
    ########### images folder  ########
    ?>
					<?php 
    if ($parent->all['ttyyp_id'] != 39) {
        ?>
					<tr id="images_folder">
						<td class="label"><?php 
        echo $site->sys_sona(array('sona' => 'Image files directory', 'tyyp' => 'editor'));
        ?>
:</td>
						<td class="input">
							<table cellpadding="0" cellspacing="0" class="container" id="images_folder_cf_container_table">
								<tr>
									<?php 
        ########### images folder  ########
        ?>
									<td id="images_folder_cf_container_cell"<?php 
        echo $args['path'] ? '' : ' class="hidden"';
        ?>
>
										<table cellpadding="0" cellspacing="0" class="cf_container">
											<tr>
												<th><input type="hidden" name="path" id="path" value="<?php 
        echo $args['path'] ? $args['path'] : '';
        ?>
"><span id="images_folder_path"><a href="javascript:chooseFolder();" id="images_folder_path_link" title="<?php 
        echo $site->sys_sona(array('sona' => 'choose_a_folder', 'tyyp' => 'editor'));
        ?>
"><?php 
        echo $args['path'];
        ?>
</a></span></th>
												<td><a href="javascript:chooseFolder();" title="<?php 
        echo $site->sys_sona(array('sona' => 'choose_a_folder', 'tyyp' => 'editor'));
        ?>
">..</a></td>
												<td><a href="javascript:clearFolder();">X</a></td>
											</tr>
										</table>
									</td>
									
									<?php 
        ########### add images  ########
        ?>
									<?php 
        if ($site->CONF['fm_allow_multiple_upload']) {
            ?>
									<td id="images_add_button_cell">
										<span id="span_upload_button_place_holder"></span>
									</td>
									
									<?php 
            ########### upload progress  ########
            ?>
									<td id="upload_progress_cell" class="hidden"><div id="upload_progress_bar"><div id="upload_progress_grow"></div></div></td><!-- / scms_upload_progress -->
									<td id="upload_progress_text_cell" class="hidden"></td><!-- / scms_upload_text -->
									<?php 
        }
        ?>
									
									<?php 
        ########### choose_a_folder  ########
        ?>
									<td id="images_choose_folder_button_cell"<?php 
        echo $args['path'] ? ' class="hidden"' : '';
        ?>
>
										<?php 
        if ($site->CONF['fm_allow_multiple_upload']) {
            ?>
&nbsp;<?php 
            echo $site->sys_sona(array('sona' => 'or', 'tyyp' => 'editor'));
        }
        ?>
										<input type="button" value="<?php 
        echo $site->sys_sona(array('sona' => 'choose_a_folder', 'tyyp' => 'editor'));
        ?>
" class="inline_button" onclick="chooseFolder();" />
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<?php 
    }
    ?>
					
					<?php 
    ########### description  ########
    ?>
					<tr>
						<td class="label"><?php 
    echo $site->sys_sona(array('sona' => 'Kirjeldus', 'tyyp' => 'editor'));
    ?>
:</td>
						<td class="input"><textarea name="desc"><?php 
    echo $args['desc'] ? $args['desc'] : "";
    ?>
</textarea></td>
					</tr>
					
					<?php 
    ########### publishing  ########
    ?>
					<tr>
						<td class="label"><?php 
    echo $site->sys_sona(array('sona' => 'visible_to_visitors', 'tyyp' => 'editor'));
    ?>
:</td>
						<td><input type="radio" name="publish" id="object_published" value="1"<?php 
    echo $site->fdat['publish'] || $objekt->all['on_avaldatud'] ? ' checked' : '';
    echo $objekt->permission && !$objekt->permission['P'] || !$objekt->permission && !$parent->permission['P'] ? ' disabled="disabled"' : NULL;
    ?>
> <label for="object_published"><?php 
    echo $site->sys_sona(array('sona' => 'published', 'tyyp' => 'editor'));
    ?>
</label>	<input type="radio" name="publish" id="object_unpublished" value="0"<?php 
    echo $site->fdat['publish'] == 0 && $objekt->all['on_avaldatud'] == 0 ? ' checked' : '';
    echo $objekt->permission && !$objekt->permission['P'] || !$objekt->permission && !$parent->permission['P'] ? ' disabled="disabled"' : NULL;
    ?>
> <label for="object_unpublished"><?php 
    echo $site->sys_sona(array('sona' => 'unpublished', 'tyyp' => 'editor'));
    ?>
</label></td>
					</tr>
				</table>
				
				<br />
				
				<?php 
    ########### advanced  ########
    ?>
				<div class="panel_toggler" onclick="togglePanel('advanced');">
					<a href="javascript:void(0);"><?php 
    echo $site->sys_sona(array('sona' => 'Advanced', 'tyyp' => 'editor'));
    ?>
 <span id="advanced_panel_link_state">&raquo;</span></a>
				</div>
				
				<div id="advanced_panel" class="panel">
					
					<?php 
    ########### image sizes  ########
    ?>
					<table cellpadding="0" cellspacing="0" class="form_row">
						<tr>
							<td class="label">Image sizes:</td>
							<td><?php 
    echo $site->sys_sona(array('sona' => 'Image size', 'tyyp' => 'editor'));
    ?>
:</td>
							<td>
								<input name="pic_size" class="text_number" value="<?php 
    echo $args['pic_size'] ? $args['pic_size'] : $site->CONF['image_width'];
    ?>
" />
								<input name="old_pic_size" type="hidden" value="<?php 
    echo $args['pic_size'] ? $args['pic_size'] : $site->CONF['image_width'];
    ?>
" />
							</td>
							<td>px&nbsp;</td>
							<td><?php 
    echo $site->sys_sona(array('sona' => 'Thumbnail size', 'tyyp' => 'editor'));
    ?>
:</td>
							<td>
								<input name="tn_size" class="text_number" value="<?php 
    echo $args['tn_size'] ? $args['tn_size'] : $site->CONF['thumb_width'];
    ?>
" />
								<input name="old_tn_size" type="hidden" value="<?php 
    echo $args['tn_size'] ? $args['tn_size'] : $site->CONF['thumb_width'];
    ?>
" />
							</td>
							<td>px</td>
						</tr>
					</table>
					
					<?php 
    ########### parent section  ########
    ?>
					<?php 
    if ($section_name) {
        ?>
					<table cellpadding="0" cellspacing="0" class="form_row">
						<tr>
							<td class="label"><label><?php 
        echo $site->sys_sona(array('sona' => 'Rubriigid', 'tyyp' => 'editor'));
        ?>
:</label></td>
							<td class="input">
								<table cellpadding="0" cellspacing="0" class="cf_container">
									<tr>
										<th><input type="hidden" name="rubriik[]" id="rubriik" value="<?php 
        echo $parent->objekt_id;
        ?>
"><span id="section_name"><a href="javascript:chooseSection();"><?php 
        echo $section_name;
        ?>
</a></span></th>
										<td><a href="javascript:chooseSection();">..</a></td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
					<?php 
    }
    ?>
					
					<table cellpadding="0" cellspacing="0" class="form_row">
						<tr>
							<td class="label">&nbsp;</td>
							<td><label><?php 
    echo $site->sys_sona(array('sona' => 'Avaldatud', 'tyyp' => 'editor'));
    ?>
:</label></td>
							<td><input type="text" id="publish_start" name="avaldamise_algus" maxlength="16" class="text_date" value="<?php 
    echo $publish_start;
    ?>
" /></td>
							<td><a href="javascript:init_datepicker('publish_start', 'publish_start', 'publish_end');"><img src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/gfx/calendar/cal.gif" width="16" height="15" title="Choose from calendar" alt="Choose from calendar" /></a></td>
							<td><label><?php 
    echo $site->sys_sona(array('sona' => 'Kuni', 'tyyp' => 'editor'));
    ?>
:</label></td>
							<td><input type="text" id="publish_end" name="avaldamise_lopp" maxlength="16" class="text_date" value="<?php 
    echo $publish_end;
    ?>
" /></td>
							<td><a href="javascript:init_datepicker('publish_end', 'publish_start', 'publish_end');"><img src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/gfx/calendar/cal.gif" width="16" height="15" title="Choose from calendar" alt="Choose from calendar" /></a></td>
						</tr>
					</table>
					
					<?php 
    ########### position  ########
    ?>
					<?php 
    if ($site->CONF['allow_change_position']) {
        ?>
					<table cellpadding="0" cellspacing="0" class="form_row">
						<tr>
							<td class="label"><label><?php 
        echo $site->sys_sona(array('sona' => 'Position', 'tyyp' => 'editor'));
        ?>
:</label></td>
							<td><input type="text" maxlength="5" class="text_position" name="kesk" value="<?php 
        echo $site->fdat['op'] == 'edit' ? $objekt->all['kesk'] : $site->fdat['kesk'];
        ?>
" /></td>
						</tr>
					</table>
					<?php 
    } else {
        ?>
						<input type="hidden" name="kesk" value="<?php 
        echo $site->fdat['op'] == 'edit' ? $objekt->all['kesk'] : $site->fdat['kesk'];
        ?>
" />
					<?php 
    }
    ?>
					
				</div>
			</div>
			
		</div>
		
		<div id="button_container">
			
			<table cellspacing="0" cellpadding="0" id="form_submit_buttons_table">
				<tr>
					<td id="apply_button_cell">
						<input type="button" class="button" value="<?php 
    echo $site->sys_sona(array('sona' => 'Apply', 'tyyp' => 'editor'));
    ?>
" onclick="saveForm('save');" />
					</td>
					<td id="save_close_button_cell">
						<input type="button" class="button" value="&nbsp;&nbsp;&nbsp;&nbsp;<?php 
    echo $site->sys_sona(array('sona' => 'save_and_close', 'tyyp' => 'editor'));
    ?>
&nbsp;&nbsp;&nbsp;&nbsp;" onclick="saveForm('saveclose');" />
						<input type="button" class="button" value="<?php 
    echo $site->sys_sona(array('sona' => 'Close', 'tyyp' => 'editor'));
    ?>
" onclick="window.close();" />		
					</td>
				</tr>
			</table>
			
			<table cellspacing="0" cellpadding="0" class="hidden" id="upload_cancel_table">
				<tr>
					<td id="cancel_button_cell">
						<input type="button" class="button" value="<?php 
    echo $site->sys_sona(array('sona' => 'katkesta', 'tyyp' => 'editor'));
    ?>
" onclick="swfu.cancelQueue();" />		
					</td>
				</tr>
			</table>
			
		</div> <!-- / button_container -->
		
		</div> <!-- / size_wrapper -->
		
		</form>
	</body>
</html>

<?php 
}
	//-->
	</script>

</head>

<body style="overflow-y: auto; overflow-x: auto;">

<?php 
############ FORM #########
?>
<form name="selectform" action="<?php 
echo $site->self;
?>
" method="POST">
<?php 
create_form_token('edit-permissions');
######## gather all fdat values into hidden fields
#foreach($site->fdat as $fdat_field=>$fdat_value) {
#	if($fdat_field != 'op' && substr($fdat_field,0,4) != 'tmp_'){
#		echo '<input type=hidden id="selectform_'.$fdat_field.'" name="'.$fdat_field.'" value="'.$fdat_value.'">';
#	}
#}
?>
<input type=hidden id="selectform_op" name="op" value="">
<input type=hidden id="selectform_selected_group" name="selected_group" value="<?php 
echo $site->fdat['selected_group'];
?>
">
<input type=hidden id="selectform_user_id" name="user_id" value="<?php 
echo $site->fdat['user_id'];
?>
?>

 <tr>
  <td width="100%" valign="top" height="100%"> 	
		<div id=listing class="scms_middle_div" style="min-height: 440px"> 
		<?php 
################
# DATA TABLE
?>

		<FORM action="<?php 
echo $site->self;
?>
" method="post" name="vorm">
		<?php 
create_form_token('edit-object-templates');
?>
		<input type=hidden name="save" id="save" value="1">

			  <table border="0" cellspacing="0" cellpadding="3" width="100%">
				<tr  class="scms_tableheader"> 
				  <td nowrap class="scms_tableheader"><?php 
echo $site->sys_sona(array(sona => "Type", tyyp => "admin"));
?>
</td>
				  <td nowrap>&nbsp;</td>
				  <td nowrap><?php 
echo $site->sys_sona(array(sona => "Content template", tyyp => "editor"));
?>
</td>
				</tr>
//		window.close();
	// -->
	</SCRIPT>
<?php 
    }
}
#############################
# FORM
#############################
?>
<form action="<?php 
$site->self;
?>
" method="post" name="vorm">
<?php 
create_form_token('');
###### 1. Master table
?>
<TABLE border="0" cellpadding="0" cellspacing="0" style="width:100%; height:100%">
<TR>
<TD valign="top" width="100%" class="scms_dialog_area"  height="100%">


	<?php 
###### 2. White dialog table
?>
	<table width="100%"  border="0" cellspacing="3" cellpadding="0" class="scms_borderbox">

	<tr valign=top> 
          <td colspan="2"> 
            <div style="position:relative"> 
<table border="0" cellpadding="0" cellspacing="0" style="width:100%; height:100%">
<?php 
    ########### tabs
    print_tabs();
    ?>
  <tr> 
    <td valign="top" width="100%" class="scms_dialog_area" height="100%"> 
<div id="scroll">
	<table width="100%"  border="0" cellspacing="0" cellpadding="3">
	
	<form name="frmEdit" action="<?php 
    echo $site->self;
    ?>
" method="POST">
	<?php 
    create_form_token('edit-table');
    ?>
	<input type=hidden id=tab name=tab value="<?php 
    echo $site->fdat['tab'];
    ?>
">
	<input type=hidden id=id name=id value="<?php 
    echo $site->fdat['id'];
    ?>
">
	<input type=hidden name=op value="<?php 
    echo $site->fdat['op'];
    ?>
">
	<input type=hidden name=op2 value="">
	<input type=hidden id=external_table name=external_table value="<?php 
/**
 * This source file is is part of Saurus CMS content management software.
 * It is licensed under MPL 1.1 (http://www.opensource.org/licenses/mozilla1.1.php).
 * Copyright (C) 2000-2010 Saurused Ltd (http://www.saurus.info/).
 * Redistribution of this file must retain the above copyright notice.
 * 
 * Please note that the original authors never thought this would turn out
 * such a great piece of software when the work started using Perl in year 2000.
 * Due to organic growth, you may find parts of the software being
 * a bit (well maybe more than a bit) old fashioned and here's where you can help.
 * Good luck and keep your open source minds open!
 * 
 * @package		SaurusCMS
 * @copyright	2000-2010 Saurused Ltd (http://www.saurus.info/)
 * @license		Mozilla Public License 1.1 (http://www.opensource.org/licenses/mozilla1.1.php)
 * 
 */
function edit_objekt()
{
    global $site;
    global $objekt;
    global $keel;
    global $class_path;
    global $tyyp;
    // refreshing (fdat['refresh'] = 1) looses object data, I don't know why and because it's done in edit_object.php, I'm not going to fix it, lord knows what it'll screw up
    if ($site->fdat['refresh'] && $site->fdat['id']) {
        $obj = new Objekt(array('objekt_id' => $site->fdat['id']));
        $objekt->objekt_id = $obj->objekt_id;
        $objekt->parent_id = $obj->parent_id;
    }
    if ($objekt->parent_id || $site->fdat['op'] == 'new') {
        $parent = new Objekt(array('objekt_id' => $objekt->objekt_id ? $objekt->parent_id : $site->fdat['parent_id']));
        $pearubriik = $parent->all['sys_alias'] == 'home' ? 1 : 0;
    } else {
        $pearubriik = 0;
    }
    $content_templates = get_templates('CONTENT', $objekt->all['ttyyp_id']);
    if ($content_templates['template_variable_html']) {
        $template_variable_html = $content_templates['template_variable_html'];
        unset($content_templates['template_variable_html']);
    }
    $page_templates = get_templates('PAGE', $objekt->all['page_ttyyp_id']);
    $sql = $site->db->prepare('select ttyyp_id, page_ttyyp_id from keel where keel_id = ' . $keel);
    $default_templates = new SQL($sql);
    $default_templates = $default_templates->fetch('ASSOC');
    foreach ($page_templates as $name => $group) {
        if ($group[$default_templates['page_ttyyp_id']]) {
            $default_page_template = array('id' => $default_templates['page_ttyyp_id'], 'group' => $name, 'name' => $group[$default_templates['page_ttyyp_id']]['nimi']);
        }
    }
    foreach ($content_templates as $name => $group) {
        if ($group[$default_templates['ttyyp_id']]) {
            $default_content_template = array('id' => $default_templates['ttyyp_id'], 'group' => $name, 'name' => $group[$default_templates['ttyyp_id']]['nimi']);
        }
    }
    // parent path
    if ($objekt->all['sys_alias'] == '' && $site->fdat['sys_alias'] == '') {
        // this needs serious rethink and optmisation: there's no need to get the entire tree, parent object's path to top is only needed
        include_once $class_path . 'rubloetelu.class.php';
        $rubs = new RubLoetelu(array('keel' => $keel, 'required_perm' => 'C', 'ignore_perm_for_obj' => $parent ? $parent->objekt_id : 0));
        #$rubs->debug->print_msg();
        $topparents = $rubs->get_loetelu();
        if (is_array($topparents)) {
            asort($topparents);
        }
        foreach ($topparents as $k => $v) {
            if ($parent->objekt_id == $k) {
                $section_name = $v;
                break;
            }
        }
    }
    // setup for section selection
    $_SESSION['parent_selection']['callback'] = 'window.opener.updateSection';
    $_SESSION['parent_selection']['selectable'] = 1;
    $_SESSION['parent_selection']['hide_language_selection'] = '1';
    $_SESSION['parent_selection']['mem_classes'] = array('rubriik');
    //this sucks, really
    $_SESSION['parent_selection']['db_fields'] = array('select_checkbox', 'objekt_id', 'pealkiri');
    $_SESSION['parent_selection']['display_fields'] = array('select_checkbox', 'pealkiri');
    $publish_start = $objekt->all['avaldamisaeg_algus'] > 0 ? $site->db->MySQL_ee_long($objekt->all['avaldamisaeg_algus']) : '';
    /* Don't print out time which is 00:00:00 */
    if (preg_match("/(\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d?\\d\\d)\\s(\\d?\\d)[\\:\\\\.\\/\\-](\\d?\\d)/", $publish_start, $aa_reg)) {
        $publish_start = $aa_reg[2] == "00" && $aa_reg[3] == "00" ? $aa_reg[1] : $publish_start;
    }
    $publish_end = $objekt->all['avaldamisaeg_lopp'] > 0 ? $site->db->MySQL_ee_long($objekt->all['avaldamisaeg_lopp']) : '';
    /* Don't print out time which is 23:59 */
    if (preg_match("/(\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d?\\d\\d)\\s(\\d?\\d)[\\:\\\\.\\/\\-](\\d?\\d)/", $publish_end, $la_reg)) {
        $publish_end = $la_reg[2] == "23" && $la_reg[3] == "59" ? $la_reg[1] : $publish_end;
    }
    // to get the correct path to parent objects set use_alises on
    $site->CONF['use_aliases'] = 1;
    if ($parent) {
        $parent_href = $parent->get_object_href();
    } else {
        $alias = '';
        if ($site->CONF['alias_language_format']) {
            $languages = $site->cash(array('klass' => 'GET_LANGUAGES', 'kood' => 'ALL_LANGUAGE_INFO'));
            if (empty($languages)) {
                $sql = "select keel_id, extension, on_default from keel where on_kasutusel = 1";
                $result = new SQL($sql);
                while ($row = $result->fetch('ASSOC')) {
                    $languages[$row['keel_id']] = $row;
                }
                $site->cash(array('klass' => 'GET_LANGUAGES', 'kood' => 'ALL_LANGUAGE_INFO', 'sisu' => $languages));
            }
        }
        // add languge alias - alias language format 0: none, 1: always, 2: for non-default lang objs
        if ($site->CONF['alias_language_format'] == 1) {
            $alias .= $languages[$objekt->all['keel']]['extension'] . '/';
        } elseif ($site->CONF['alias_language_format'] == 2) {
            if (!$languages[$objekt->all['keel']]['on_default']) {
                $alias .= $languages[$objekt->all['keel']]['extension'] . '/';
            }
        }
        $parent_href = '/' . $alias;
    }
    if ($parent_href && $parent_href != '/' && ($site->CONF['alias_trail_format'] == 0 || $parent->all['sys_alias'] == 'home' || $parent->all['sys_alias'] == 'trash' || $parent->all['sys_alias'] == 'system' || $parent->all['sys_alias'] == 'gallup_arhiiv')) {
        $parent_href = preg_replace('#' . preg_quote('/' . ($parent->all['friendly_url'] ? $parent->all['friendly_url'] : $parent->objekt_id), '#') . '/$#', '/', $parent_href);
    }
    $parent_href = $site->CONF['hostname'] . $parent_href;
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
	<head> 	
		<title><?php 
    echo $site->title;
    ?>
 <?php 
    echo $site->cms_version;
    ?>
</title>
		
		<meta http-equiv="Content-Type" content="text/html; charset=<?php 
    echo $encoding ? $encoding : $site->encoding;
    ?>
" />
		<meta http-equiv="Cache-Control" content="no-cache" />
		
		<link rel="stylesheet" href="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/datepicker.css" />
		<link rel="stylesheet" href="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/section_editor.css" />
		
		<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/yld.js"></script>
		<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/edit_popup.js"></script>
		<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/jquery.js"></script>
		<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/datepicker.js"></script>
		<script type="text/javascript" src="<?php 
    echo $site->CONF['wwwroot'];
    ?>
/common.js.php"></script>
		
		<script type="text/javascript">
			var isIE = navigator.appVersion.match(/MSIE/); // assume gecko on false
			
			window.onload = function ()
			{
				var title = document.getElementById('pealkiri');
				
				resizeWindow();
				
				var advanced_panel_state = document.getElementById('advanced_panel_state');
				if(advanced_panel_state.value == 1)
				{
					togglePanel('advanced');
				}
				
				this.focus();
				title.focus();
			}
			
			function resizeWindow()
			{
				if(jQuery.browser.webkit)
        {
          window.resizeTo(580, 310);
				}
				else
				{
          resizeWindowTo($('#size_wrapper').width(), $('#size_wrapper').height());
				}
			}
			
			
			function chooseSection()
			{
				explorer_window = openpopup('explorer.php?objekt_id=home&editor=1&swk_setup=parent_selection&remove_objects=<?php 
    echo $site->fdat['id'];
    ?>
&pre_selected=' + document.getElementById('rubriik').value, 'cms_explorer', '800','600');
			}
			
			function updateSection(sections)
			{
				explorer_window.close();
				var section_name = document.getElementById('section_name');
				var section_id = document.getElementById('rubriik');
				var trail_path= new Array();

					for(var j = 0; j < sections[0].trail.length; j++){
						trail_path[j] = sections[0].trail[j].pealkiri;
					}

				section_name.innerHTML = '<a href="javascript:chooseSection();">' + trail_path.join("->") + '</a>';
				section_id.value = sections[0].objekt_id;
			}

			function editAlias()
			{
				var alias_placeholder = document.getElementById('alias_placeholder');
				var alias_value = document.getElementById('alias_value');
				
				alias_placeholder.innerHTML = '<input type="text" id="alias" value="' + alias_value.value + '" onblur="saveAlias();">';
				
		    	resizeWindow();
		    	
				var alias = document.getElementById('alias');
				alias.focus();
			}
			
			function saveAlias()
			{
				var alias_placeholder = document.getElementById('alias_placeholder');
				var alias_value = document.getElementById('alias_value');
				var alias = document.getElementById('alias');
				
				if(alias_value.value != alias.value)
				{
					$.ajax({
					    url: 'ajax_response.php?rand=' + Math.random(9999),
					    data: {op: 'generate_alias', string: alias.value, language_id: '<?php 
    echo $keel;
    ?>
'},
					    type: 'POST',
					    dataType: 'json',
					    timeout: 1000,
					    error: function()
					    {
							alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (alias_value.value.length > 30 ? alias_value.value.substring(0, 30) + '...' : alias_value.value) + '</a>';
					    },
					    success: function(response)
					    {
					    	if(response.alias)
					    	{
								alias_value.value = response.alias;
								alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (alias_value.value.length > 30 ? alias_value.value.substring(0, 30) + '...' : alias_value.value) + '</a>';
					    	}
					    	else
					    	{
								alias_value.value = '';
								<?php 
    if ($objekt->objekt_id) {
        ?>
								alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + '<?php 
        echo $objekt->objekt_id;
        ?>
' + '</a>';
								<?php 
    } else {
        ?>
						    	alias_placeholder.innerHTML = '<input type="text" id="alias" value="" onblur="saveAlias();">';
								<?php 
    }
    ?>
					    	}
							
					    	resizeWindow();
					    }
					});
				}
				else
				{
					if(!alias.value)
					{
						alias_value.value = '';
						<?php 
    if ($objekt->objekt_id) {
        ?>
						alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + '<?php 
        echo $objekt->objekt_id;
        ?>
' + '</a>';
						<?php 
    } else {
        ?>
				    	alias_placeholder.innerHTML = '<input type="text" id="alias" value="" onblur="saveAlias();">';
						<?php 
    }
    ?>
					}
					else
					{
						alias_placeholder.innerHTML = '<a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (alias_value.value.length > 30 ? alias_value.value.substring(0, 30) + '...' : alias_value.value) + '</a>';
					}
			    	
					resizeWindow();
				}
			}
			
			function createAlias()
			{
				var alias_value = document.getElementById('alias_value');
				var title = document.getElementById('pealkiri')
				
				if(0 || (!alias_value && title.value))
				{
					$.ajax({
					    url: 'ajax_response.php?rand=' + Math.random(9999),
					    data: {op: 'generate_alias', string: title.value, language_id: '<?php 
    echo $keel;
    ?>
'},
					    type: 'POST',
					    dataType: 'json',
					    timeout: 1000,
					    error: function()
					    {
					    },
					    success: function(response)
					    {
					    	var alias_cell = document.getElementById('alias_cell');
					    	alias_cell.className = 'alias';
					    	if(response.alias)
					    	{
						    	alias_cell.innerHTML = '<input type="hidden" name="friendly_url" id="alias_value" value="' + response.alias + '"><?php 
    echo $parent_href;
    ?>
<span id="alias_placeholder"><a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (response.alias.length > 30 ? response.alias.substring(0, 30) + '...' : response.alias) + '</a></span>';
					    	}
					    	else
					    	{
						    	alias_cell.innerHTML = '<input type="hidden" name="friendly_url" id="alias_value" value=""><?php 
    echo $parent_href;
    ?>
<span id="alias_placeholder"><input type="text" id="alias" value="" onblur="saveAlias();"></span>';
					    	}
					    	
					    	var alias_row = document.getElementById('alias_row');
					    	alias_row.style.display = (isIE ? 'block' : 'table-row');

					    	resizeWindow();
					    }
					});			
				}
			}
			
			function saveForm(op2)
			{
				var form = document.getElementById('editForm');
				
				var title = document.getElementById('pealkiri');
				
				if(title.value.length == 0)
				{
					alert('<?php 
    echo $site->sys_sona(array('sona' => 'please_fill_in_the_title!', 'tyyp' => 'admin'));
    ?>
');
					return;
				}
				
				var alias_value = document.getElementById('alias_value');
				var alias = document.getElementById('alias');
				
				if((title.value && !alias_value) || (alias && alias_value && alias.value != alias_value.value))
				{
					$.ajax({
					    url: 'ajax_response.php?rand=' + Math.random(9999),
					    data: {op: 'generate_alias', string: title.value, language_id: '<?php 
    echo $keel;
    ?>
'},
					    type: 'POST',
					    dataType: 'json',
					    timeout: 1000,
					    error: function()
					    {
					    	var form = document.getElementById('editForm');
			 				
					    	form.op2.value = op2;
			 				form.submit();
					    },
					    success: function(response)
					    {
					    	var alias_value = document.getElementById('alias_value');
					    	
					    	if(!alias_value && response.alias)
					    	{
						    	var alias_cell = document.getElementById('alias_cell');
						    	alias_cell.innerHTML = '<input type="hidden" name="friendly_url" id="alias_value" value="' + response.alias + '"><?php 
    echo $parent_href;
    ?>
<span id="alias_placeholder"><a href="javascript:void(0);" onclick="editAlias();" id="alias_link">' + (response.alias.length > 30 ? response.alias.substring(0, 30) + '...' : response.alias) + '</a></span>';
					    	}
							
					    	var form = document.getElementById('editForm');
			 				
					    	form.op2.value = op2;
			 				form.submit();
					    }
					});
				}
				else
				{
	 				form.op2.value = op2;
	 				form.submit();
				}
			}
		</script>
	</head>
	
	<body>
		
		<?php 
    if ($site->fdat['op'] == 'edit') {
        ?>
			<iframe src="checkin.php?objekt_id=<?php 
        echo $objekt->objekt_id;
        ?>
" style="width: 0; height: 0; display: none; visibility: hidden;"></iframe>
		<?php 
    }
    ?>
		
		<form action="edit.php" name="editForm" id="editForm" method="POST"  enctype="multipart/form-data">
		
		<?php 
    create_form_token('edit-section');
    ?>
		
		<input type="hidden" name="tab" value="<?php 
    echo $site->fdat['tab'];
    ?>
" />
		<input type="hidden" id="op" name="op" value="<?php 
    echo htmlspecialchars($site->fdat['op']);
    ?>
" />
		<input type="hidden" id="op2" name="op2" value="" />
		<input type="hidden" id="refresh" name="refresh" value="0" />
		
		<input type="hidden" name="tyyp_id" value="<?php 
    echo $tyyp['tyyp_id'];
    ?>
" />
		<input type="hidden" name="tyyp" value="<?php 
    echo $tyyp['klass'];
    ?>
" />
		
		<input type="hidden" name="pearubriik" value="<?php 
    echo $pearubriik;
    ?>
" />
		<input type="hidden" name="id" value="<?php 
    echo $site->fdat['id'];
    ?>
" />
		<input type="hidden" name="parent_id" value="<?php 
    echo $site->fdat['parent_id'];
    ?>
" />
		<input type="hidden" name="previous_id" value="<?php 
    echo $site->fdat['previous_id'];
    ?>
" />
		<input type="hidden" name="keel" value="<?php 
    echo $keel;
    ?>
" />
		<input type="hidden" name="on_pealkiri" value="1" />
		
        <input type="hidden" name="sorting" value="<?php 
    echo $site->fdat['sorting'];
    ?>
">

		<input type="hidden" name="opener_location" value="" />
		<input type="hidden" name="publish" value="<?php 
    echo $site->fdat['publish'] || $objekt->all['on_avaldatud'] ? 1 : 0;
    ?>
">

		<input name="permanent_parent_id" type="hidden" value="<?php 
    echo $objekt->parent_id;
    ?>
" />
		<input name="sys_alias" type="hidden" value="<?php 
    echo $site->fdat['sys_alias'] ? $site->fdat['sys_alias'] : $objekt->all['sys_alias'];
    ?>
" />
		
		<input name="advanced_panel_state" id="advanced_panel_state" type="hidden" value="<?php 
    echo $site->fdat['advanced_panel_state'] ? htmlspecialchars($site->fdat['advanced_panel_state']) : 0;
    ?>
" />
		
		<div id="size_wrapper" class="section_editor">
		
		<div id="main_container">
			<?php 
    ########### Tabs  ########
    ?>
			<div id="tab_container">
				<a href="javascript:void(0);" class="selected"><?php 
    echo $site->sys_sona(array('sona' => 'tyyp_rubriik', 'tyyp' => 'System'));
    ?>
</a>
				<?php 
    if ($objekt->objekt_id) {
        ?>
					<a href="<?php 
        echo $site->self . '?tab=seo&id=' . $site->fdat['id'] . '&keel=' . $keel . '&op=' . $site->fdat['op'];
        ?>
" onclick="resizeDocumentHeightTo(430);"><?php 
        echo $site->sys_sona(array('sona' => 'meta-info', 'tyyp' => 'admin'));
        ?>
</a>
					<?php 
    } else {
        ?>
					<a href="javascript:void(0);"><?php 
        echo $site->sys_sona(array('sona' => 'meta-info', 'tyyp' => 'admin'));
        ?>
</a>
				<?php 
    }
    ?>
				<?php 
    if ($objekt->objekt_id) {
        ?>
					<a href="<?php 
        echo $site->self . '?tab=permissions&id=' . $site->fdat['id'] . '&keel=' . $keel . '&op=' . $site->fdat['op'];
        ?>
" onclick="resizeDocumentHeightTo(430);"><?php 
        echo $site->sys_sona(array('sona' => 'permissions', 'tyyp' => 'admin'));
        ?>
</a>
					<?php 
    } else {
        ?>
					<a href="javascript:void(0);"><?php 
        echo $site->sys_sona(array('sona' => 'permissions', 'tyyp' => 'admin'));
        ?>
</a>
				<?php 
    }
    ?>
			</div>
			
			<div id="content_container">
		
				<table cellpadding="0" cellspacing="0" class="form_row">
					<tr>
						<td class="label"><label><?php 
    echo $site->sys_sona(array('sona' => 'Pealkiri', 'tyyp' => 'editor'));
    ?>
:</label></td>
						<td class="input"><input type="text" class="text" name="pealkiri" id="pealkiri" value="<?php 
    echo htmlspecialchars($objekt->all['pealkiri']);
    ?>
" onblur="createAlias();" /></td>
					</tr>
					<?php 
    if (($objekt->objekt_id || isset($objekt->all['friendly_url'])) && !($objekt->all['sys_alias'] == 'trash' || $objekt->all['sys_alias'] == 'system' || $objekt->all['sys_alias'] == 'gallup_arhiiv')) {
        ?>
					<tr>
						<td class="label">&nbsp;</td>
						<td class="input"><input type="hidden" id="alias_value" name="friendly_url" name="friendly_url" value="<?php 
        echo htmlspecialchars($objekt->all['friendly_url']);
        ?>
" /><?php 
        echo $parent_href;
        ?>
<span id="alias_placeholder"><a href="javascript:void(0);" onclick="editAlias();" id="alias_link"><?php 
        echo $objekt->all['friendly_url'] ? strlen(htmlspecialchars($objekt->all['friendly_url'])) > 30 ? substr(htmlspecialchars($objekt->all['friendly_url']), 0, 30) . '...' : htmlspecialchars($objekt->all['friendly_url']) : $objekt->objekt_id;
        ?>
</a></span></td>
					</tr>
					<?php 
    } else {
        ?>
					<tr id="alias_row">
						<td class="label">&nbsp;</td>
						<td class="input" id="alias_cell"></td>
					</tr>
					<?php 
    }
    ?>
					<tr>
						<td class="label"><label><?php 
    echo $site->sys_sona(array('sona' => 'content template', 'tyyp' => 'editor'));
    ?>
:</label></td>
						<td class="input"><select class="select" id="template_select" name="ttyyp_id" onchange="refreshForm();"><option value="0"><?php 
    echo $site->sys_sona(array('sona' => 'default', 'tyyp' => 'admin'));
    ?>
 (<?php 
    echo $default_content_template['name'];
    ?>
)</option>
						<?php 
    foreach ($content_templates as $template_group_name => $templates_group) {
        ?>
							<optgroup label="<?php 
        echo $template_group_name;
        ?>
">
						<?php 
        foreach ($templates_group as $template_id => $template) {
            ?>
						<?php 
            if ($objekt->all['ttyyp_id'] == $template_id) {
                $ttyyp = $template;
            }
            ?>
								<option value="<?php 
            echo $template_id;
            ?>
"<?php 
            echo $objekt->all['ttyyp_id'] == $template_id ? ' selected="selected" style="color: #a7a6aa;"' : '';
            ?>
><?php 
            echo $template['nimi'];
            ?>
</option>
						<?php 
        }
        ?>
							</optgroup>
						<?php 
    }
    ?>
						</select></td>
					</tr>
					<?php 
    ########### publishing  ########
    ?>
					<tr>
						<td class="label"><?php 
    echo $site->sys_sona(array('sona' => 'visible_to_visitors', 'tyyp' => 'editor'));
    ?>
</td>
						<td><input type="radio" name="publish" id="object_published" value="1"<?php 
    echo $site->fdat['publish'] || $objekt->all['on_avaldatud'] ? ' checked' : '';
    echo $objekt->permission && !$objekt->permission['P'] || !$objekt->permission && !$parent->permission['P'] ? ' disabled="disabled"' : NULL;
    ?>
> <label for="object_published"><?php 
    echo $site->sys_sona(array('sona' => 'published', 'tyyp' => 'editor'));
    ?>
</label>	<input type="radio" name="publish" id="object_unpublished" value="0"<?php 
    echo $site->fdat['publish'] == 0 && $objekt->all['on_avaldatud'] == 0 ? ' checked' : '';
    echo $objekt->permission && !$objekt->permission['P'] || !$objekt->permission && !$parent->permission['P'] ? ' disabled="disabled"' : NULL;
    ?>
> <label for="object_unpublished"><?php 
    echo $site->sys_sona(array('sona' => 'unpublished', 'tyyp' => 'editor'));
    ?>
</label></td>
					</tr>
				</table>
				
				<br />
				
				<?php 
    ########### advanced  ########
    ?>
				<div class="panel_toggler" onclick="togglePanel('advanced');">
					<a href="javascript:void(0);"><?php 
    echo $site->sys_sona(array('sona' => 'Advanced', 'tyyp' => 'editor'));
    ?>
 <span id="advanced_panel_link_state">&raquo;</span></a>
				</div>
				
				<div id="advanced_panel" class="panel">
					
					<?php 
    ########### parent section  ########
    ?>
					<?php 
    if ($section_name) {
        ?>
					<table cellpadding="0" cellspacing="0" class="form_row">
						<tr>
							<td class="label"><label><?php 
        echo $site->sys_sona(array('sona' => 'Rubriigid', 'tyyp' => 'editor'));
        ?>
:</label></td>
							<td class="input">
								<table cellpadding="0" cellspacing="0" class="cf_container">
									<tr>
										<th><input type="hidden" name="rubriik[]" id="rubriik" value="<?php 
        echo $parent ? $parent->objekt_id : 0;
        ?>
"><span id="section_name"><a href="javascript:chooseSection();"><?php 
        echo $section_name;
        ?>
</a></span></th>
										<td><a href="javascript:chooseSection();">..</a></td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
					<?php 
    }
    ?>
					
					<?php 
    ########### page template  ########
    ?>
					<table cellpadding="0" cellspacing="0" class="form_row">
						<tr>
							<td class="label"><label><?php 
    echo $site->sys_sona(array('sona' => 'page template', 'tyyp' => 'editor'));
    ?>
:</label></td>
							<td class="input"><select class="select" name="page_ttyyp_id"><option value="0"><?php 
    echo $site->sys_sona(array('sona' => 'default', 'tyyp' => 'admin'));
    ?>
 (<?php 
    echo $default_page_template['name'];
    ?>
)</option>
							<?php 
    foreach ($page_templates as $template_group_name => $templates_group) {
        ?>
								<optgroup label="<?php 
        echo $template_group_name;
        ?>
">
							<?php 
        foreach ($templates_group as $template_id => $template) {
            ?>
									<option value="<?php 
            echo $template_id;
            ?>
"<?php 
            echo $objekt->all['page_ttyyp_id'] == $template_id ? ' selected="selected" style="color: #a7a6aa;"' : '';
            ?>
><?php 
            echo $template['nimi'];
            ?>
</option>
							<?php 
        }
        ?>
								</optgroup>
							<?php 
    }
    ?>
							</select></td>
						</tr>
					</table>
					
					<?php 
    ########### hiding in menu and mailinglist  ########
    ?>
					<table cellpadding="0" cellspacing="0" class="form_row">
						<tr>
							<td class="label">&nbsp;</td>
							<td><input type="checkbox" class="checkbox" id="hide_in" name="is_hided_in_menu" value="1"<?php 
    echo $objekt->all['is_hided_in_menu'] ? ' checked="checked"' : '';
    ?>
 /></td>
							<td width="145"><label for="hide_in"><?php 
    echo $site->sys_sona(array('sona' => 'Hide in menu', 'tyyp' => 'editor'));
    ?>
</label></td>
							<td><input type="checkbox" class="checkbox" id="add_mailinglist" name="on_meilinglist" value="1"<?php 
    echo $objekt->all['on_meilinglist'] ? ' checked="checked"' : '';
    ?>
 /></td>
							<td><label for="add_mailinglist"><?php 
    echo $site->sys_sona(array('sona' => 'On meilinglist', 'tyyp' => 'editor'));
    ?>
</label></td>
						</tr>
					</table>
					
					<table cellpadding="0" cellspacing="0" class="form_row">
						<tr>
							<td class="label">&nbsp;</td>
							<td><label><?php 
    echo $site->sys_sona(array('sona' => 'Avaldatud', 'tyyp' => 'editor'));
    ?>
:</label></td>
							<td><input type="text" id="publish_start" name="avaldamise_algus" maxlength="16" class="text_date" value="<?php 
    echo $publish_start;
    ?>
" /></td>
							<td><a href="javascript:init_datepicker('publish_start', 'publish_start', 'publish_end');"><img src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/gfx/calendar/cal.gif" width="16" height="15" title="Choose from calendar" alt="Choose from calendar" /></a></td>
							<td><label><?php 
    echo $site->sys_sona(array('sona' => 'Kuni', 'tyyp' => 'editor'));
    ?>
:</label></td>
							<td><input type="text" id="publish_end" name="avaldamise_lopp" maxlength="16" class="text_date" value="<?php 
    echo $publish_end;
    ?>
" /></td>
							<td><a href="javascript:init_datepicker('publish_end', 'publish_start', 'publish_end');"><img src="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/gfx/calendar/cal.gif" width="16" height="15" title="Choose from calendar" alt="Choose from calendar" /></a></td>
						</tr>
					</table>
					
					<?php 
    ########### ONLY FOR SAURUS 3 BUILT-IN TEMPLATES: subarticles +  Add print icon  ########
    ?>
					<?php 
    if (($objekt || $site->fdat['refresh']) && $ttyyp['ttyyp_id'] > 0 && $ttyyp['ttyyp_id'] < 1000) {
        # if ver3 content template
        ?>
					<table cellpadding="0" cellspacing="0" class="form_row">
			              <tr> 
							<td class="label">&nbsp;</td>
			
							<?php 
        ########### subarticles  ########
        ?>
			                <td><input type="checkbox" id="on_alamartiklid" name="on_alamartiklid"<?php 
        echo $objekt->all['on_alamartiklid'] ? ' checked="checked"' : '';
        ?>
 /></td>
			                <td width="145"><label for="on_alamartiklid"><?php 
        echo $site->sys_sona(array('sona' => 'Naita alamartiklid', 'tyyp' => 'editor'));
        ?>
</label></td>
			
							<?php 
        ########### Add print icon  ########
        ?>
			                <td><input type="checkbox" id="on_printlink" name="on_printlink"  value="1" <?php 
        echo $objekt->all['on_printlink'] ? ' checked="checked"' : '';
        ?>
 /></td>
			                <td><label for="on_printlink"><?php 
        echo $site->sys_sona(array('sona' => 'Naita prindi ikoon', 'tyyp' => 'editor'));
        ?>
</label></td>
			
						  </tr>
					</table>
					<?php 
    }
    # if ver3 content template
    ?>
					<?php 
    if ($template_variable_html) {
        ?>
					<table cellpadding="0" cellspacing="0" class="form_row">
						<?php 
        echo $template_variable_html;
        ?>
					</table>
					<?php 
    }
    ?>
					
					<?php 
    ########### position  ########
    ?>
					<?php 
    if ($site->CONF['allow_change_position']) {
        ?>
					<table cellpadding="0" cellspacing="0" class="form_row">
						<tr>
							<td class="label"><label><?php 
        echo $site->sys_sona(array('sona' => 'Position', 'tyyp' => 'editor'));
        ?>
:</label></td>
							<td><input type="text" maxlength="5" class="text_position" name="kesk" value="<?php 
        echo $site->fdat['op'] == 'edit' ? $objekt->all['kesk'] : $site->fdat['kesk'];
        ?>
" /></td>
						</tr>
					</table>
					<?php 
    } else {
        ?>
						<input type="hidden" name="kesk" value="<?php 
        echo $site->fdat['op'] == 'edit' ? $objekt->all['kesk'] : $site->fdat['kesk'];
        ?>
" />
					<?php 
    }
    ?>
					
				</div>
			</div>
			
		</div>
		
		<div id="button_container">
			
			<table width="100%" cellspacing="0" cellpadding="0">
				<tbody>
					<tr>
						<td align="left">
							<input type="button" class="button" value="<?php 
    echo $site->sys_sona(array('sona' => 'Apply', 'tyyp' => 'editor'));
    ?>
" onclick="saveForm('save');" />
						</td>
						<td align="right">
							<input type="button" class="button" value="&nbsp;&nbsp;&nbsp;&nbsp;<?php 
    echo $site->sys_sona(array('sona' => 'save_and_close', 'tyyp' => 'editor'));
    ?>
&nbsp;&nbsp;&nbsp;&nbsp;" onclick="saveForm('saveclose');" />
							<input type="button" class="button" value="<?php 
    echo $site->sys_sona(array('sona' => 'Close', 'tyyp' => 'editor'));
    ?>
" onclick="window.close();" />		
						</td>
					</tr>
				</tr>
				</tbody>
			</table>
			
			
			
			
		</div>
		
		</div> <!-- / size_wrapper -->
		
		</form>
	</body>
</html>

<?php 
}
/gfx/icons/16x16/actions/edittrash.png" width="16" height="16"></td>
									<td class="title"><?php 
echo $site->sys_sona(array('sona' => 'recycle bin', 'tyyp' => 'Admin'));
?>
</td>
								</tr>
							</table>
	            		</div><!-- s_Page_title_bar -->
	            </td>
	        </tr>
	        <tr>
	            <td class="s_Page_container">
	                <div id="s_Content_container">
					<form name="actionForm" id="actionForm" method="POST">
       				<?php 
create_form_token('trash-actions');
?>

					<input type="hidden" name="delete_all" value="0">

					<input type="hidden" name="language" value="<?php 
echo $language_id;
?>
">
					<input type="hidden" name="sort_by" value="<?php 
echo $sort_by;
?>
">
					<input type="hidden" name="sort_dir" value="<?php 
echo $sort_dir;
?>
	                	<div class="division_bar">
	                		<!--<table cellpadding="0" cellspacing="0">
	                			<tr>
	                				<td>Autori nimi</td>
	                				<td width="100%"><div></div></td>
	                			</tr>
	                		</table>-->
                		</div><!-- / division_bar -->
	                	<div class="extensions_list">
							
		                	<form id="installForm" action="<?php 
        echo $_SERVER['PHP_SELF'];
        ?>
" method="POST">
								<?php 
        create_form_token('install-extension');
        ?>
								<input type="hidden" name="activate" value="1">
								<input type="hidden" name="direct" value="1">
								<?php 
        if ($editor_mode) {
            ?>
								<input type="hidden" name="keepThis" value="true">
								<?php 
        }
        ?>
								<input type="hidden" name="extension">
							</form>
							
							<?php 
        foreach ($extensions as $extension) {
/**
 * This source file is is part of Saurus CMS content management software.
 * It is licensed under MPL 1.1 (http://www.opensource.org/licenses/mozilla1.1.php).
 * Copyright (C) 2000-2010 Saurused Ltd (http://www.saurus.info/).
 * Redistribution of this file must retain the above copyright notice.
 * 
 * Please note that the original authors never thought this would turn out
 * such a great piece of software when the work started using Perl in year 2000.
 * Due to organic growth, you may find parts of the software being
 * a bit (well maybe more than a bit) old fashioned and here's where you can help.
 * Good luck and keep your open source minds open!
 * 
 * @package		SaurusCMS
 * @copyright	2000-2010 Saurused Ltd (http://www.saurus.info/)
 * @license		Mozilla Public License 1.1 (http://www.opensource.org/licenses/mozilla1.1.php)
 * 
 */
function smarty_function_create_form_token($params, &$smarty)
{
    create_form_token($params['form_id']);
}
</SCRIPT>
</head>

<body>
<?php 
#################
# IMPORT FORM
if ($site->fdat['op'] == 'import' || $site->fdat['op'] == 'import_cvs') {
    ?>

<FORM method=post action="<?php 
    echo $site->self;
    ?>
" enctype="multipart/form-data">
<?php 
    create_form_token('import-glossary');
    ?>

<!-- Popup table -->
<table border="0" cellpadding="0" cellspacing="0" style="width:100%; height:100%">
<tr> 
	<TD valign="top" width="100%" class="scms_table" height="100%" style="background: #fff;">

	<!-- Scrollable area -->
	<div id=listing class="scms_middle_div">

	<!-- Adding-more-space table -->
	<table width="100%"  border="0" cellspacing="3" cellpadding="0" class="scms_table">
	<tr>
	<td>
	<br />
    echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
    ?>
/scms_general.css">
<SCRIPT LANGUAGE="JavaScript" SRC="<?php 
    echo $site->CONF['wwwroot'] . $site->CONF['js_path'];
    ?>
/yld.js"></SCRIPT>
</head>
<body class="popup_body" onLoad="this.focus();document.forms['vorm'].role_name.focus();">

<FORM action="<?php 
    echo $site->self;
    ?>
" method="post" name="vorm">
	<?php 
    create_form_token('edit-role');
    ?>
<table border="0" cellpadding="0" cellspacing="0" style="width:100%; height:100%">
<tr> 
    <td valign="top" width="100%" class="scms_dialog_area_top"  height="100%">
	  <table width="100%"   border="0" cellspacing="0" cellpadding="2">
	  <?php 
    ############ name #########
    ?>
 
	  <tr> 
		<td><?php 
    echo $site->sys_sona(array(sona => "nimi", tyyp => "editor"));
    ?>
: </td>
		<td width="100%"><input type=text name=role_name value="<?php 
/**
* show object info
*
* Shows general info from table "objekt" and customized info from table "obj_*".
* Uses sub-scripts to show different data for different object types.
* No parameters used, only globals, it is included file.
*
* @package CMS
*
* Call:
*		include_once("edit_object.php");
*		edit_object();
*/
function edit_general_object()
{
    global $site;
    global $objekt;
    global $par_obj;
    global $class_path;
    global $keel;
    global $tyyp;
    global $ttyyp;
    global $op;
    global $op2;
    ?>

	<!-- Scrollable area -->
	<div id=listing class="scms_middle_div">
<?php 
    #####################
    # pearubriigi leidmine
    $par_obj = new Objekt(array(objekt_id => $site->fdat['parent_id']));
    $pearubriik = $par_obj->all[sys_alias] == "home" ? 1 : 0;
    # ----------------------
    # Uue objekti vorm
    # ----------------------
    ?>
<table border="0" cellspacing="0" cellpadding="0">
<tr><form name=global>
	<td>
	<input type=hidden name="controll_form_was_opened" value="">
	<input type=hidden name="button_checkform_was_pressed" value="">

<?php 
    if ($op == 'edit') {
        ?>
	<iframe src="checkin.php?objekt_id=<?php 
        echo $objekt->objekt_id;
        ?>
" style="width:1;height:1;visibility:hidden;"></iframe>
<?php 
    }
    ?>

	</td>
</tr></form>

<?php 
    /* Paneme selle tag siia, et ei olnud liiga suur tyhi rida */
    ?>
<form action="edit.php" method=post name=frmEdit id=frmEdit  enctype="multipart/form-data">
</table>

<?php 
    create_form_token('edit-object');
    ?>
<input type=hidden name=tab value="<?php 
    echo $site->fdat['tab'];
    ?>
">
<input type=hidden id="op" name="op" value="<?php 
    echo $site->fdat['op'];
    ?>
">
<input type=hidden id="op2" name=op2 value="">
<input type=hidden id="refresh" name="refresh" value=0>


<input type="hidden" name="tyyp_id" value="<?php 
    echo $tyyp[tyyp_id];
    ?>
">
<input type="hidden" name="tyyp" value="<?php 
    echo $tyyp['klass'];
    ?>
">
<input type="hidden" name="sys_alias" value="<?php 
    echo $site->fdat[sys_alias];
    ?>
">

<input type="hidden" name="pearubriik" value="<?php 
    echo $pearubriik;
    ?>
">
<input type="hidden" name="id" value="<?php 
    echo $site->fdat['id'];
    ?>
">
<input type="hidden" name="parent_id" value="<?php 
    echo $site->fdat['parent_id'];
    ?>
">
<input type="hidden" name="previous_id" value="<?php 
    echo $site->fdat['previous_id'];
    ?>
">
<input type="hidden" name="keel" value="<?php 
    echo $keel;
    ?>
">

<input type="hidden" name="sorting" value="<?php 
    echo $site->fdat['sorting'];
    ?>
">

<input type="hidden" name="opener_location" value="">
<input type="hidden" name="publish" value="<?php 
    echo $site->fdat['publish'] || $objekt->all['on_avaldatud'] ? 1 : 0;
    ?>
">
	<script>
		document.frmEdit.opener_location.value = window.opener.location;
	</script>
<?php 
    ###################
    # special case: if object is  picture
    if ($tyyp['klass'] == "pilt" && !$objekt->objekt_id) {
        // if new pilt
        include_once "edit_" . $tyyp['klass'] . ".php";
        if (function_exists("new_objekt")) {
            new_objekt();
        }
    } else {
        ################# CONTENT - SURROUNDING SCROLL TABLE ################
        ?>

<table width="100%"  border="0" cellspacing="3" cellpadding="0" class="scms_table">
<tr>
<td>

<br>
<?php 
        ######################### MAIN TABLE ##########################
        ?>
<!--<fieldset class="scms_borderbox">
<legend><?php 
        echo $site->sys_sona(array(sona => "Main info", tyyp => "kasutaja"));
        ?>
</legend>
-->


	  <table width="100%"  border="0" cellspacing="3" cellpadding="0" class="scms_borderbox">
        <tr>
          <td colspan="2">
            <div style="position:relative">
              <div class="scms_borderbox_label"><?php 
        echo $site->sys_sona(array(sona => "Main info", tyyp => "kasutaja"));
        ?>
</div>
            </div>
          </td>
        </tr>
<?php 
        ###################
        # pealkiri
        $pealkiri = htmlspecialchars($objekt->all['pealkiri']);
        # if pealkiri is empty then fill with profile default value (Bug #2819)
        if ($pealkiri == '' && $site->fdat['profile_id']) {
            $profile_def = $site->get_profile(array(id => $site->fdat['profile_id']));
            $profile_fields = unserialize($profile_def['data']);
            # profile_fields is now array of ALL fields, indexes are fieldnames
            # if found profile default value
            if ($profile_fields['pealkiri']['default_value'] != '') {
                $pealkiri = $profile_fields['pealkiri']['default_value'];
            }
        }
        ?>
		<tr>
          <td nowrap><?php 
        echo $site->sys_sona(array(sona => "Pealkiri", tyyp => "editor"));
        ?>
:</td>
          <td width="100%">
            <input name="pealkiri" id="pealkiri" type="text" class="scms_flex_input" value="<?php 
        echo $pealkiri;
        ?>
" onkeyup="javascript: if(event.keyCode==13){document.getElementById('op2').value='saveclose'; frmEdit.submit();}">
			<textarea name="pastearea" rows="5" cols="30" style="width:1;height:1;visibility:hidden;"></textarea>
          </td>
        </tr>
<?php 
        # / pealkiri
        ###################
        ###################
        # ONLY image: checkbox "pealkiri on n�htav" + "foorum lubatud"
        if ($tyyp['klass'] == "pilt") {
            ?>
		<tr>
          <td nowrap><?php 
            echo $site->sys_sona(array(sona => "Pealkiri on nahtav", tyyp => "editor"));
            ?>
:</td>
          <td width="100%"><input type=checkbox name="on_pealkiri" value="1" <?php 
            echo $op == "new" ? "checked" : ($objekt->all[on_pealkiri] ? "checked" : "");
            ?>
>
	<?php 
            echo $site->sys_sona(array(sona => "Foorum lubatud", tyyp => "editor"));
            ?>
	<input type=checkbox name="on_foorum" value="1" <?php 
            echo $objekt->all[on_foorum] || $op == "new" && $site->CONF[default_comments] ? "checked" : "";
            ?>
>
            </td>
        </tr>
<?php 
        } else {
            ?>
		<input type="hidden" name="on_pealkiri" value=1>
<?php 
        }
        # / checkbox "pealkiri on n�htav" + "foorum lubatud"
        ###################
        ############################
        # template selectbox
        if ($tyyp[on_kujundusmall]) {
            # print selectboxes and get selected template array
            $ttyyp = print_template_selectboxes();
        }
        ?>
</table>
<!--</fieldset>-->

<?php 
        ######################### / MAIN TABLE ##########################
        ?>
<br><br>
<?php 
        ###################### ADVANCED TABLE #################
        ?>

	  <table width="100%"  border="0" cellspacing="3" cellpadding="0" class="scms_borderbox">
        <tr>
          <td colspan="2">
            <div style="position:relative">
              <div class="scms_borderbox_label"><?php 
        echo $site->sys_sona(array(sona => "Additional info", tyyp => "kasutaja"));
        ?>
</div>
            </div>
          </td>
        </tr>
<?php 
        if ($tyyp['klass'] == 'file') {
            print_parent_selectbox();
        }
        ###########################
        # OBJECT TYPE: include "edit_*.php"
        include_once "edit_" . $tyyp['klass'] . ".php";
        if (function_exists("edit_objekt")) {
            edit_objekt();
        }
        ###########################
        # type/class configuration
        if ($tyyp[on_konfigureeritav]) {
            if (function_exists("edit_tyyp_params")) {
                edit_tyyp_params(array(objekt => $objekt));
            }
        }
        # / type/class configuration
        ###########################
        ####################################
        # Kuulub rubriiki
        if ($tyyp['klass'] != 'file' && $tyyp['klass'] != 'folder') {
            print_parent_selectbox();
        }
        ?>

</table>
<?php 
        ###################### / ADVANCED TABLE #################
        if ($tyyp['klass'] != 'file' || $site->CONF['allow_change_position']) {
            # show advanced table
            ?>
<br>
<br>
     <table width="100%"  border="0" cellspacing="3" cellpadding="0" class="scms_borderbox">

<?php 
            ###################### PUBLISHING & LOCATION TABLE #################
            ### dont show publish information for files and folders
            if ($tyyp['klass'] != 'file' && $tyyp['klass'] != 'folder') {
                $avaldamise_algus = $objekt->all[avaldamisaeg_algus] > 0 ? $site->db->MySQL_ee_long($objekt->all[avaldamisaeg_algus]) : "";
                /* Don't print out time which is 00:00:00 */
                if (preg_match("/(\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d?\\d\\d)\\s(\\d?\\d)[\\:\\\\.\\/\\-](\\d?\\d)/", $avaldamise_algus, $aa_reg)) {
                    $avaldamise_algus = $aa_reg[2] == "00" && $aa_reg[3] == "00" ? $aa_reg[1] : $avaldamise_algus;
                }
                $avaldamise_lopp = $objekt->all[avaldamisaeg_lopp] > 0 ? $site->db->MySQL_ee_long($objekt->all[avaldamisaeg_lopp]) : "";
                /* Don't print out time which is 23:59 */
                if (preg_match("/(\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d[\\:\\\\.\\/\\-]\\d?\\d?\\d\\d)\\s(\\d?\\d)[\\:\\\\.\\/\\-](\\d?\\d)/", $avaldamise_lopp, $la_reg)) {
                    $avaldamise_lopp = $la_reg[2] == "23" && $la_reg[3] == "59" ? $la_reg[1] : $avaldamise_lopp;
                }
                ?>
        <tr>
          <td colspan="2">
            <div style="position:relative">
              <div class="scms_borderbox_label"><?php 
                echo $site->sys_sona(array(sona => "Publishing", tyyp => "editor"));
                ?>
</div>
            </div>
          </td>
        </tr>
        <tr>
          <td nowrap>
		  <?php 
                echo $site->sys_sona(array(sona => "Avaldatud", tyyp => "editor"));
                ?>
:</td>
          <td width="100%">
            <table border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td style="padding:0px">
                  <input name="avaldamise_algus" id="avaldamise_algus" type="text" class="scms_flex_input_date" style="width:80px" value="<?php 
                echo $avaldamise_algus;
                ?>
">
                </td>
                <td style="padding:0px"><a href="#" onclick="init_datepicker('avaldamise_algus','avaldamise_algus','avaldamise_lopp');"><img src="<?php 
                echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
                ?>
/gfx/calendar/cal.gif" width="16" height="15" title="Choose from calendar" alt="Choose from calendar" border="0"></a></td>
                <td style="padding:0px">&nbsp;&nbsp;<?php 
                echo $site->sys_sona(array(sona => "Kuni", tyyp => "editor"));
                ?>
:&nbsp; </td>
                <td style="padding:0px">
                  <input name="avaldamise_lopp" id="avaldamise_lopp" type="text" class="scms_flex_input_date" style="width:80px" value="<?php 
                echo $avaldamise_lopp;
                ?>
">
                </td>
                <td style="padding:0px"><a href="#" onclick="init_datepicker('avaldamise_lopp','avaldamise_algus','avaldamise_lopp');"><img src="<?php 
                echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
                ?>
/gfx/calendar/cal.gif" width="16" height="15" title="Choose from calendar" alt="Choose from calendar" border="0"></a></td>
              </tr>
            </table>
          </td>
        </tr>
<?php 
            }
            # not "file"
            ############################
            # position
            # n�idata kui configi v��rtus "" on sees JA kui on rubriik v�i artikkel
            $tmp_kesk = split(",", $site->fdat[kesk]);
            if (sizeof($tmp_kesk) > 0) {
                $site->fdat[kesk] = trim($tmp_kesk[0]);
            }
            if ($site->CONF['allow_change_position']) {
                ?>
	<tr>
		<td nowrap><?php 
                echo $site->sys_sona(array(sona => "Position", tyyp => "editor"));
                ?>
:</td>
        <td nowrap width="100%">
		<input name="kesk" size="2" class="scms_flex_input" style="width:40px" value="<?php 
                echo $op == 'edit' ? $objekt->all[kesk] : $site->fdat[kesk];
                ?>
">
		</td>
	</tr>
<?php 
            } else {
                ?>
		<input type="hidden" name="kesk" value="<?php 
                echo $op == 'edit' ? $objekt->all[kesk] : $site->fdat[kesk];
                ?>
">
<?php 
            }
            # / position
            ############################
            ?>
      </table>
<?php 
        }
        # show advanced table
        ###################### / PUBLISHING & LOCATION TABLE #################
        ?>
</td>
</tr>
</table>
<?php 
        ################# / CONTENT - SURROUNDING SCROLL TABLE ################
        ?>
	</div>
	<!-- //Scrollable area -->

    </td>
  </tr>
	<?php 
        #################### BUTTONS ###########
        ?>
	  <tr>
	  <td align="right" valign="top" class="scms_dialog_area_bottom">
	  <?php 
        if ($tyyp['klass'] == 'asset') {
            ?>
	  	<table cellpadding="0" cellspacing="0" width="100%">
	  		<tr>
				<td><input type="button" value="<?php 
            echo $site->sys_sona(array('sona' => 'New', 'tyyp' => 'editor'));
            ?>
" onclick="javascript:frmEdit.op.value='new'; frmEdit.id.value=0; frmEdit.submit();"></td>
	  			<td align="right">
	  <?php 
        }
        ?>

	<?php 
        # dont show "Apply" button for new file if opened from WYSIWYG editor
        ?>
	<?php 
        if (!($site->fdat['op'] == 'new' && $tyyp[klass] == 'file' && $site->fdat['in_wysiwyg'])) {
            ?>

		<input type="button" value="<?php 
            echo $site->sys_sona(array(sona => "Apply", tyyp => "editor"));
            ?>
" onclick="javascript:frmEdit.op2.value='save'; body.style.cursor = 'wait';if(typeof url_browse == 'object'){url_browse.removeNode()}; frmEdit.submit();">

	<?php 
        }
        ?>
	   <input type="button" value="<?php 
        echo $site->sys_sona(array(sona => "Salvesta", tyyp => "editor"));
        ?>
" onclick="javascript:frmEdit.op2.value='saveclose'; body.style.cursor = 'wait';if(typeof url_browse == 'object'){url_browse.removeNode()}; frmEdit.submit();">

	   <input type="button" value="<?php 
        echo $site->sys_sona(array(sona => "Close", tyyp => "editor"));
        ?>
" onclick="javascript:window.close();">
	  <?php 
        if ($tyyp['klass'] == 'asset') {
            ?>
	  			</td>
	  		</tr>
	  	</table>
	  <?php 
        }
        ?>
    </td>
  </tr>

</table>

<?php 
    }
    # / if object is not picture
    ###################
    ?>

</form>
<?php 
    $site->debug->msg("EDIT: Objekti loomine, vormi kuvamine");
    ?>

<?php 
}
			}
			
			var contentBox = function(id, top, right, bottom, left)
			{
				this.box = document.getElementById(id);
				this.box.style.top = top;
				this.box.style.right = right;
				this.box.style.bottom = bottom;
				this.box.style.left = left;
			}
		</script>
	</head>
	<body id="popup">
		<form name="upload_extension" method="POST" enctype="multipart/form-data">
		<?php 
    create_form_token('upload-extension');
    ?>
		<div id="mainContainer">
			<div class="titleArea">
				<?php 
    echo $site->sys_sona(array(sona => "extension_upload", tyyp => "admin"));
    ?>
			</div><!-- / titleArea -->
			<div class="contentArea" id="content_box">
				<div class="contentAreaContent">

							<table cellspacing="0" cellpadding="10" width="100%">
								<tr>
									<td>
<?php 
    if ($ext->error()) {