<?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");

ensure_defined_REQUEST('do');

$pref_file = FS_PATH.'/etc/inc-prefs.php';

if ($_REQUEST['do'] == 'save') {

  ensure_defined_REQUEST('enable_commField', 'f');
  ensure_defined_REQUEST('enable_dloadField', 'f');
  ensure_defined_REQUEST('protect_mediaField', 'f');
  ensure_defined_REQUEST('real_onlyField', 'f');
  ensure_defined_REQUEST('edit_mediaField', 'f');
  ensure_defined_REQUEST('batch_downloadField', 'f');
  ensure_defined_REQUEST('xmlField', 'f');

  $data = array(   'RES_PER_PAGE' => abs($_REQUEST['res_per_pageField'])
                 , 'ENABLE_COMMUNITY' => $_REQUEST['enable_commField']
                 , 'ENABLE_DOWNLOAD' => $_REQUEST['enable_dloadField']
                 , 'PROTECT_MEDIA' => $_REQUEST['protect_mediaField']
                 , 'REAL_ONLY' => $_REQUEST['real_onlyField']
                 , 'BATCH_DOWNLOAD' => $_REQUEST['batch_downloadField']
                 , 'BATCH_TIME_LIMIT' => $_REQUEST['batch_timeField']
                 , 'BATCH_SIZE_LIMIT' => $_REQUEST['batch_sizeField']
                 , 'EDIT_MEDIA' => $_REQUEST['edit_mediaField']
                 , 'ORGANIZE_FORMAT' => $_REQUEST['organize_formatField']
                 , 'ENABLE_XML' => $_REQUEST['xmlField'] );

  ensure_defined_REQUEST('edit_mediaField', 0);
  SavePrefFile($pref_file, $_REQUEST['save_to_fileField'], $data);

} else {

  $section = "sysadmin";
  include (INTERFACE_HEADER);

  PrefsTabs ('content');

  $enable_commChecked = '';
  $write_check = '';
  $enable_dloadChecked = '';
  $real_onlyChecked = '';
  $protect_mediaChecked = '';
  $enable_batchChecked = '';
  $edit_mediaChecked = '';
  $enable_xmlChecked = '';

  if (@is_writable($pref_file)) $write_check = 'checked';

  if (strtolower(substr(ENABLE_COMMUNITY,0,1)) == 't') $enable_commChecked = 'CHECKED';

  if (strtolower(substr(ENABLE_DOWNLOAD,0,1)) == 't') $enable_dloadChecked = 'CHECKED';

  if (strtolower(substr(REAL_ONLY,0,1)) == 't') $real_onlyChecked = 'CHECKED';

  if (strtolower(substr(PROTECT_MEDIA,0,1)) == 't') $protect_mediaChecked = 'CHECKED';

  if (strtolower(substr(BATCH_DOWNLOAD,0,1)) == 't') $enable_batchChecked = 'CHECKED';

  if (strtolower(substr(EDIT_MEDIA,0,1)) == 't') $edit_mediaChecked = 'CHECKED';

  if (strtolower(substr(ENABLE_XML,0,1)) == 't') $enable_xmlChecked = 'CHECKED';

?>

<script language='Javascript'>

  function security_note() {

     var myalert = "";

     myalert += "<?php echo  ADMPREF_FORMS_SAVETOFILE_HELP_1 ?>";

     alert(myalert);

  }

  function batch_download() {

     var myalert = "";

     myalert += "<?php echo  ADMPREF_FORMS_BATCH_HELP_1 ?>";

     alert(myalert);

  }


  function community_features() {

     var myalert = "";

     myalert += "<?php echo  ADMPREF_FORMS_ENABLECOMM_HELP_1 ?>";

     alert(myalert);

  }

  function download_features() {

     var myalert = "";

     myalert += "<?php echo  ADMPREF_FORMS_ENABLEDLOAD_HELP_1 ?>";

     alert(myalert);

  }

  function protect_media() {

     var myalert = "";

     myalert += "<?php echo  ADMPREF_FORMS_PROTECTMEDIA_HELP_1 ?>";

     alert(myalert);

  }

  function real_only() {

     var myalert = "";

     myalert += "<?php echo  ADMPREF_FORMS_REALONLY_HELP_1 ?>";

     alert(myalert);

  }

  function edit_media() {

     var myalert = "";

     myalert += "<?php echo  ADMPREF_FORMS_ENABLEEDIT_HELP_1 ?>";

     alert(myalert);

  }

  function format_help() {

     var myalert = "";

     myalert += "<?php echo  ADMPREF_FORMS_ORGANIZEFORMAT_HELP_3 ?>";

     alert(myalert);

  }

  function xml_help() {

     var myalert = "";

     myalert += "<?php echo  ADMPREF_FORMS_ENABLEXML_HELP_1 ?>";

     alert(myalert);

  }

  function checkForm () {

    var msg = '';

    //if (document.prefsForm.db_nameField.value.length == 0) {
    //  msg = msg + '- <?php echo  ADMPREF_CHECKFORM_DBNAME ?>.\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_2 ?></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_RESPERPAGE_1 ?></td>
      <td align=left nowrap><input type=text name='res_per_pageField' size='3' maxlength='3' value='<?php echo RES_PER_PAGE?>' class=input_content> <?php echo  ADMPREF_FORMS_RESPERPAGE_2 ?></td>
    </tr>
    <tr>
      <td align=left nowrap colspan=2>&nbsp;</td>
    </tr>
    <tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_ENABLECOMM ?></td>
      <td align=left nowrap>
        <input type=checkbox name='enable_commField' value='t' <?php echo $enable_commChecked?>> <?php echo  ADMPREF_FORMS_CAPT_ENABLED ?>
        &nbsp; (<a href="javascript:community_features();"><?php echo  ADMPREF_FORMS_ENABLECOMM_HELP_2 ?></a>)
      </td>
    </tr>
    <tr>
      <td align=left nowrap colspan=2>&nbsp;</td>
    </tr>
    <tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_ENABLEDLOAD ?></td>
      <td align=left nowrap>
        <input type=checkbox name='enable_dloadField' value='t' <?php echo $enable_dloadChecked?>> <?php echo  ADMPREF_FORMS_CAPT_ENABLED ?>
        &nbsp; (<a href="javascript:download_features();"><?php echo  ADMPREF_FORMS_ENABLEDLOAD_HELP_2 ?></a>)
      </td>
    </tr>
    <tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_PROTECTMEDIA ?></td>
      <td align=left nowrap>
        <input type=checkbox name='protect_mediaField' value='t' <?php echo $protect_mediaChecked?> onChange="if (document.prefsForm.real_onlyField.checked == true) document.prefsForm.protect_mediaField.checked = true;"> <?php echo  ADMPREF_FORMS_CAPT_ENABLED ?>
        &nbsp; (<a href="javascript:protect_media();"><?php echo  ADMPREF_FORMS_PROTECTMEDIA_HELP_2 ?></a>)
      </td>
    </tr>
    <tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_REALONLY ?></td>
      <td align=left nowrap>
        <input type=checkbox name='real_onlyField' value='t' <?php echo $real_onlyChecked?> onChange="if (document.prefsForm.real_onlyField.checked == true) document.prefsForm.protect_mediaField.checked = true;"> <?php echo  ADMPREF_FORMS_CAPT_ENABLED ?>
        &nbsp; (<a href="javascript:real_only();"><?php echo  ADMPREF_FORMS_REALONLY_HELP_2 ?></a>)
      </td>
    </tr>
    <tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_ENABLEEDIT ?></td>
      <td align=left nowrap>
        <input type=checkbox name='edit_mediaField' value='t' <?php echo $edit_mediaChecked?>> <?php echo  ADMPREF_FORMS_CAPT_ENABLED ?>
        &nbsp; (<a href="javascript:edit_media();"><?php echo  ADMPREF_FORMS_ENABLEEDIT_HELP_2 ?></a>)
      </td>
    </tr>
    <tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_ENABLEXML ?></td>
      <td align=left nowrap>
        <input type=checkbox name='xmlField' value='t' <?php echo $enable_xmlChecked?>> <?php echo  ADMPREF_FORMS_CAPT_ENABLED ?>
        &nbsp; (<a href="javascript:xml_help();"><?php echo  ADMPREF_FORMS_ENABLEXML_HELP_2 ?></a>)
      </td>
    </tr>
    <tr>
      <td align=left nowrap colspan=2>&nbsp;</td>
    </tr>
	<tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_ORGANIZEFORMAT_HELP_1 ?></td>
      <td align=left nowrap><input type=text name='organize_formatField' size='9' maxlength='25' value='<?php echo ORGANIZE_FORMAT ?>' class=input_content>
	    &nbsp;&nbsp;&nbsp;&nbsp;(<a href="javascript:format_help();"><?php echo  ADMPREF_FORMS_ORGANIZEFORMAT_HELP_2 ?></a>)
	  </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>
  </table>
  </tr>
</table>

  <br>

<table width='550' border=0 cellspacing=1 cellpadding=3 class='border'>
<tr>
  <td class='header' nowrap><B><?php echo  ADMPREF_HEADER_6 ?></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="35%" align=right nowrap><?php echo  ADMPREF_FORMS_ENABLEBATCH ?></td>
      	<td width="65%" align=left nowrap>
        <input type=checkbox name='batch_downloadField' value='t' <?php echo $enable_batchChecked?>> <?php echo  ADMPREF_FORMS_CAPT_ENABLED ?>
        	&nbsp; (<a href="javascript:batch_download();"><?php echo  ADMPREF_FORMS_BATCH_HELP_2 ?></a>)
      	</td>
    </tr>
	<tr>
      <td align=left nowrap colspan=2>&nbsp;</td>
    </tr>
	<tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_BATCHTIMELIMIT ?></td>
      <td align=left nowrap><input type=text name='batch_timeField' size='3' maxlength='3' value='<?php echo BATCH_TIME_LIMIT?>' class=input_content> <?php echo  ADMPREF_FORMS_BATCH_HELP_3 ?></td>
    </tr>
	<tr>
      <td align=right nowrap><?php echo  ADMPREF_FORMS_BATCHSIZELIMIT ?></td>
      <td align=left nowrap><input type=text name='batch_sizeField' size='3' maxlength='3' value='<?php echo BATCH_SIZE_LIMIT?>' class=input_content> <?php echo  ADMPREF_FORMS_BATCH_HELP_4 ?></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>
  </table>
 </form>

 </div>
</tr>
</table>

</form>

</div>

<?php

  include (INTERFACE_FOOTER);

}

exit;

?>
