<?php

// defines if this script requires to be logged in
define( "PRIVATE", true );

require_once('../lib/inc-admin.php');
require_once(FS_PATH."/etc/locale/".LANG_PACK."/inc-admin_prefs-edit.php");
  
$pref_file = FS_PATH.'/etc/inc-prefs.php';
  
if ($_REQUEST['do'] == 'save') {
  
  if ($_REQUEST['user_themesField'] == '') $_REQUEST['user_themesField'] = 'f';

  if ($_REQUEST['inv_icnField'] == '') $_REQUEST['inv_icnField'] = 'f';
  
  $data = array(   'LANG_PACK' => $_REQUEST['lang_packField']
                 , 'INTERFACE_HEADER' => FS_PATH."/lib/inc-header.php"
                 , 'INTERFACE_FOOTER' => FS_PATH."/lib/inc-footer.php"
                 , 'CUSTOM_HEADER' => separatorCleanup($_REQUEST['custom_headerField'])
                 , 'CUSTOM_FOOTER' => separatorCleanup($_REQUEST['custom_footerField'])
                 , 'USER_THEMES' => $_REQUEST['user_themesField']
                 , 'INV_ICN' => $_REQUEST['inv_icnField']
                 , 'DEFAULT_BGCOLOR' => $_REQUEST['bgcolorField']
                 , 'DEFAULT_TEXT' => $_REQUEST['textField']
                 , 'DEFAULT_LINK' => $_REQUEST['linkField']
                 , 'DEFAULT_ALINK' => $_REQUEST['alinkField']
                 , 'DEFAULT_VLINK' => $_REQUEST['vlinkField']
                 , 'DEFAULT_TD_BORDER' => $_REQUEST['td_borderField']
                 , 'DEFAULT_TD_HEADER' => $_REQUEST['td_headerField']
                 , 'DEFAULT_TD_HEADER_FC' => $_REQUEST['td_header_fcField']
                 , 'DEFAULT_TD_CONTENT' => $_REQUEST['td_contentField']
                 , 'DEFAULT_FONT_FACE' => $_REQUEST['font_faceField']
                 , 'DEFAULT_FONT_SIZE' => $_REQUEST['font_sizeField'] );
  
  SavePrefFile($pref_file, $_REQUEST['save_to_fileField'], $data);

} else {
 
  $section = "sysadmin";
  include (INTERFACE_HEADER);
  
  if (@is_writable($pref_file)) $write_check = 'checked';
  
  if (strtolower(substr(USER_THEMES,0,1)) == 't') $user_themesChecked = 'CHECKED';
  
  if (strtolower(substr(INV_ICN,0,1)) == 't') $inv_icnChecked = 'CHECKED';

?>

<script language='Javascript'>

  function security_note() {
  
     var myalert = "";
     
     myalert += "<?php echo  ADMPREF_FORMS_SAVETOFILE_HELP_1 ?>";
  
     alert(myalert);
  
  }

  function checkForm () {

    var msg = '';

    if (document.prefsForm.bgcolorField.value.length < 6) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_BGCOLOR ?>.\n';  
    }
    if (document.prefsForm.font_faceField.value.length == 0) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_FONTFACE ?>.\n';  
    }
    if (document.prefsForm.font_sizeField.value.length < 1) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_FONTSIZE ?>.\n';  
    }
    if (document.prefsForm.textField.value.length < 6) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_TEXT ?>.\n';  
    }
    if (document.prefsForm.linkField.value.length < 6) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_LINK ?>.\n';  
    }
    if (document.prefsForm.alinkField.value.length < 6) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_ALINK ?>.\n';  
    }
    if (document.prefsForm.vlinkField.value.length < 6) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_VLINK ?>.\n';  
    }
    if (document.prefsForm.td_borderField.value.length < 6) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_BORDER ?>.\n';  
    }
    if (document.prefsForm.td_headerField.value.length < 6) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_HEADER ?>.\n';  
    }
    if (document.prefsForm.td_header_fcField.value.length < 6) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_HEADERFC ?>.\n';  
    }
    if (document.prefsForm.td_contentField.value.length < 6) {
    msg = msg + '- <?php echo  ADMPREF_CHECKFORM_CONTENT ?>.\n';  
    }

    if (msg == '') {

      return (true);

    } else {

      alert(msg);

      return (false);

    }

  }
</script>
<div align=center>

<form action='<?php echo $_SERVER['PHP_SELF']?>' method=post name='prefsForm' target="_self" onSubmit='return checkForm ();'>
<input type=hidden name="do" value="save">

<table width='550' border=0 cellspacing=1 cellpadding=3 class='border'>
<tr>
  <td class='header' nowrap><B><?php echo  ADMPREF_HEADER_4 ?></B></td>
</tr>
<tr>
  <td class='content' nowrap align=center>
    <table border=0 cellspacing=0 cellpadding=2>
    <tr>
      <td align=left nowrap colspan=2>&nbsp;</td>
    </tr>
    <tr>
      <td width="30%" align=right nowrap><?php echo  ADMPREF_FORMS_SAVETOFILE ?></td>
      <td width="70%" align=left nowrap>
        <input type="checkbox" name="save_to_fileField" value="1" <?php echo $write_check?>> <?php echo  ADMPREF_FORMS_CAPT_ENABLED ?>
        &nbsp; (<a href="javascript:security_note();"><?php echo  ADMPREF_FORMS_SAVETOFILE_HELP_2 ?></a>)
      </td>
    </tr>
    <tr>
      <td align=left nowrap colspan=2>&nbsp;</td>
    </tr>
    <tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_LANGPACK ?></td>
      <td align=left nowrap><?php echo  lang_pack_menu("lang_packField", LANG_PACK) ?></td>
    </tr>
    <tr>
      <td align=left nowrap colspan=2>&nbsp;</td>
    </tr>
    <tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_HTMLHEAD ?></td>
      <td align=left nowrap><input type=text name='custom_headerField' size='50' maxlength='256' value='<?php echo CUSTOM_HEADER?>' class=input_content title="/path/file.html  -or-  http://your.host.dom/path/file.html"></td>
    </tr>
    <tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_HTMLFOOT ?></td>
      <td align=left nowrap><input type=text name='custom_footerField' size='50' maxlength='256' value='<?php echo CUSTOM_FOOTER?>' class=input_content title="/path/file.html  -or-  http://your.host.dom/path/file.html"></td>
    </tr>
    <tr>
      <td align=left nowrap colspan=2>&nbsp;</td>
    </tr>
    <tr>
      <td align=center nowrap colspan=2>

        <table width='400' border=0 cellspacing=1 cellpadding=3>
        <tr>
          <td align=left wrap="virtual" colspan=3>
            <?php echo  ADMPREF_CAPTION ?>
            <BR>
            <BR>
            <div align=center><A HREF="<?php echo  WEB_PATH ?>/palette.php" target="NetJukePalette" onClick="window.open('','NetJukePalette','width=640,height=575,top=0,left=0,menubar=no,scrollbars=yes,resizable=yes');"><B><?php echo  ADMPREF_PALETTE ?></B></A></div>
            <BR>
          </td>
        </tr>
        <tr>
          <td width="40%" align=right valign=top nowrap><?php echo  ADMPREF_FORMS_THEMES ?></td>
          <td width="60%" align=left valign=top colspan=2>
          	<input type=checkbox name='user_themesField' value='t' <?php echo $user_themesChecked?> title="<?php echo  ADMPREF_FORMS_THEMES_HELP ?>"> <?php echo  ADMPREF_FORMS_CAPT_ENABLED ?>
          </td>
        </tr>
        <tr>
          <td width="40%" align=right valign=top nowrap><?php echo  ADMPREF_FORMS_INVICN ?></td>
          <td width="60%" align=left valign=top colspan=2>
          	<input type=checkbox name='inv_icnField' value='t' <?php echo $inv_icnChecked?> title="<?php echo  ADMPREF_FORMS_INVICN_HELP ?>"> <?php echo  ADMPREF_FORMS_CAPT_ENABLED ?>
          </td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_FONTFACE ?></td>
          <td align=left nowrap colspan=2><input type=text name='font_faceField' size='25' maxlength='80' value='<?php echo DEFAULT_FONT_FACE?>' class=input_content></td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_FONTSIZE ?></td>
          <td align=left nowrap colspan=2><input type=text name='font_sizeField' size='2' maxlength='2' value='<?php echo DEFAULT_FONT_SIZE?>' class=input_content></td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_BGCOLOR ?></td>
          <td align=left nowrap><input type=text name='bgcolorField' size='6' maxlength='6' value='<?php echo DEFAULT_BGCOLOR?>' class=input_content></td>
          <td><TABLE BORDER="1" WIDTH="20" CELLSPACING="0" CELLPADDING="0"><TR><TD BGCOLOR='#<?php echo DEFAULT_BGCOLOR?>'>&nbsp;</TD></TR></TABLE></td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_TEXT ?></td>
          <td align=left nowrap><input type=text name='textField' size='6' maxlength='6' value='<?php echo DEFAULT_TEXT?>' class=input_content></td>
          <td><TABLE BORDER="1" WIDTH="20" CELLSPACING="0" CELLPADDING="0"><TR><TD BGCOLOR='#<?php echo DEFAULT_TEXT?>'>&nbsp;</TD></TR></TABLE></td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_LINK ?></td>
          <td align=left nowrap><input type=text name='linkField' size='6' maxlength='6' value='<?php echo DEFAULT_LINK?>' class=input_content></td>
          <td><TABLE BORDER="1" WIDTH="20" CELLSPACING="0" CELLPADDING="0"><TR><TD BGCOLOR='#<?php echo DEFAULT_LINK?>'>&nbsp;</TD></TR></TABLE></td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_ALINK ?></td>
          <td align=left nowrap><input type=text name='alinkField' size='6' maxlength='6' value='<?php echo DEFAULT_ALINK?>' class=input_content></td>
          <td><TABLE BORDER="1" WIDTH="20" CELLSPACING="0" CELLPADDING="0"><TR><TD BGCOLOR='#<?php echo DEFAULT_ALINK?>'>&nbsp;</TD></TR></TABLE></td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_VLINK ?></td>
          <td align=left nowrap><input type=text name='vlinkField' size='6' maxlength='6' value='<?php echo DEFAULT_VLINK?>' class=input_content></td>
          <td><TABLE BORDER="1" WIDTH="20" CELLSPACING="0" CELLPADDING="0"><TR><TD BGCOLOR='#<?php echo DEFAULT_VLINK?>'>&nbsp;</TD></TR></TABLE></td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_BORDER ?></td>
          <td align=left nowrap><input type=text name='td_borderField' size='6' maxlength='6' value='<?php echo DEFAULT_TD_BORDER?>' class=input_content></td>
          <td><TABLE BORDER="1" WIDTH="20" CELLSPACING="0" CELLPADDING="0"><TR><TD BGCOLOR='#<?php echo DEFAULT_TD_BORDER?>'>&nbsp;</TD></TR></TABLE></td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_HEADER ?></td>
          <td align=left nowrap><input type=text name='td_headerField' size='6' maxlength='6' value='<?php echo DEFAULT_TD_HEADER?>' class=input_content></td>
          <td><TABLE BORDER="1" WIDTH="20" CELLSPACING="0" CELLPADDING="0"><TR><TD BGCOLOR='#<?php echo DEFAULT_TD_HEADER?>'>&nbsp;</TD></TR></TABLE></td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_HEADERFC ?></td>
          <td align=left nowrap><input type=text name='td_header_fcField' size='6' maxlength='6' value='<?php echo DEFAULT_TD_HEADER_FC?>' class=input_content></td>
          <td><TABLE BORDER="1" WIDTH="20" CELLSPACING="0" CELLPADDING="0"><TR><TD BGCOLOR='#<?php echo DEFAULT_TD_HEADER_FC?>'>&nbsp;</TD></TR></TABLE></td>
        </tr>
        <tr>
          <td align=right nowrap><?php echo  ADMPREF_FORMS_CONTENT ?></td>
          <td align=left nowrap><input type=text name='td_contentField' size='6' maxlength='6' value='<?php echo DEFAULT_TD_CONTENT?>' class=input_content></td>
          <td><TABLE BORDER="1" WIDTH="20" CELLSPACING="0" CELLPADDING="0"><TR><TD BGCOLOR='#<?php echo DEFAULT_TD_CONTENT?>'>&nbsp;</TD></TR></TABLE></td>
        </tr>
        </table>

      </td>
    </tr>
    <tr>
      <td align=left nowrap colspan=2>&nbsp;</td>
    </tr>
    <tr>
      <td align=center nowrap colspan=2>
        <input type=submit value='<?php echo  ADMPREF_FORMS_BTN_SAVE ?>' class='btn_content'>
        <input type=reset value='<?php echo  ADMPREF_FORMS_BTN_RESET ?>' class='btn_content'>
      </td>
    </tr>
    <tr>
      <td align=left nowrap colspan=2>&nbsp;</td>
    </tr>
    </table>
  </td>
</tr>
</table>

</form>

</div>

<?php

  include (INTERFACE_FOOTER);

}

exit;


function lang_pack_menu($name, $selected_val="", $onchange="") {

  $html = "<select name=\"$name\" onchange=\"$onchange\" class=input_content>";
  
  $values = array( "en"=>ADMPREF_FORMS_LANGPACK_CAPTION_1
                 , "fr"=>ADMPREF_FORMS_LANGPACK_CAPTION_2
                 , "de"=>ADMPREF_FORMS_LANGPACK_CAPTION_3
                 , "ca"=>ADMPREF_FORMS_LANGPACK_CAPTION_4
                 , "es"=>ADMPREF_FORMS_LANGPACK_CAPTION_5
								 , "ru"=>ADMPREF_FORMS_LANGPACK_CAPTION_6);
  
  asort($values);
  
  foreach ($values as $key => $value) {
  
    if ($key == $selected_val) {
      $selected = "selected";
    } else {
      $selected = "";
    }
    
    $html .= "<option value=\"$key\" $selected>$value </option>";
  
  }

  $html .= "</select>";
  
  return $html;

}

?>
