/**
* 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 
}
    if ($tyyp['klass'] == 'rubriik' && $site->fdat['tab'] == 'object') {
        include_once "edit_rubriik.php";
        edit_objekt();
        ### load trigger
        if (function_exists('onAfterObjectLoad')) {
            $site->globals['onAfterObjectLoad'] = onAfterObjectLoad($objekt);
        }
        exit;
    }
    # / Section editor
    ##########################
    ###########################
    # Album editor
    if ($tyyp['klass'] == 'album' && $site->fdat['tab'] == 'object') {
        include_once "edit_album.php";
        edit_objekt();
        ### load trigger
        if (function_exists('onAfterObjectLoad')) {
            $site->globals['onAfterObjectLoad'] = onAfterObjectLoad($objekt);
        }
        exit;
    }
    # / Album editor
    ##########################
    ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?php 
    echo $site->title;
    ?>