<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2005 Coppermine Dev Team
  v1.1 originaly written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  ********************************************
  Coppermine version: 1.4.8
  $Source: /cvsroot/cpg-contrib/master_template/codebase.php,v $
  $Revision: 1.3 $
  $Author: donnoman $
  $Date: 2005/12/08 05:46:49 $
**********************************************/
/**********************************************
Modified By BMossavari 
- Add menu option to remove each part
- Add config page
**********************************************/

require('include/init.inc.php');
if (!GALLERY_ADMIN_MODE) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
if($lang_text_dir=='ltr') {
	$align="left";
	$direction="ltr";
}else {
	$align="right";
	$direction="rtl";
}

// Check for change status Final extract 2.2
if (isset($_POST['change_stat'])) {
	$sql="UPDATE `{$CONFIG['TABLE_FINAL_EXTRACT_CONFIG']}` SET value=0;";
	cpg_db_query($sql);
	$cnt=count($_POST)-1;
	if($cnt <=0) {
		pageheader($lang_plugin_final_extract['display_name']);
        msg_box($lang_plugin_final_extract['display_name'], $lang_plugin_final_extract_delete['nothing_changed'], $lang_continue, 'index.php?file=final_extract/plugin_config');
		pagefooter();
		exit;
	} else {
		unset($_POST['change_stat']);
		$sql="UPDATE `{$CONFIG['TABLE_FINAL_EXTRACT_CONFIG']}` SET value=1 WHERE";
		$i=0;
		foreach ($_POST as $key=>$value) {
			if($value=="1") {
				 $i+=1;
				 if($i==$cnt) { $sql=$sql." name='$key'";} 
				 else if ($i<$cnt){ $sql=$sql." name='$key' or ";}
			}
		}
		cpg_db_query($sql);
		pageheader($lang_plugin_final_extract['display_name']);
        msg_box($lang_plugin_final_extract['display_name'], $lang_plugin_final_extract_delete['success'], $lang_continue, 'index.php?file=final_extract/plugin_config');
		pagefooter();
		exit;
	}
}
pageheader($lang_plugin_final_extract['display_name']);
?>
<script language="javascript" type="text/javascript">
function change() {
   var Nodes = document.getElementsByTagName("table")
        var max = Nodes.length
        for(var i = 0;i < max;i++) {
                var nodeObj = Nodes.item(i)
                var str = nodeObj.id
                if (str.match("section")) {
                        nodeObj.style.display = 'none';
                }
        }
advkind=document.getElementById("plugin_status").value;
}
function change_conf() {
advkind=document.getElementById("plugin_status").value;
if(advkind==3) {
	document.getElementById("max_show").style.display='block';
	} else {
		document.getElementById("max_show").style.display='none';
	}
}
function check_all(formname) {
 i=0;
 while(document.getElementById(formname).elements[i]) {
	document.getElementById(formname).elements[i].checked="cheked";
	i+=1;
 }
}
onload = change;
</script>
<?php
starttable('100%', 'Final Extract - '.$lang_plugin_final_extract['version'].'<font size=1 color=red> By <a href=\"http://www.myprj.com\">BMossavari at gmail dot com</a></font>- <a href="pluginmgr.php" class="admin_menu">Plugin Manager</a>', 3);
echo <<<EOT
    <tr>
        <td class="tableh2" colspan="3">
            <a href="javascript:expand();" class="admin_menu">{$lang_plugin_final_extract_config['expand_all']}&nbsp;&nbsp;<img src="images/descending.gif" width="9" height="9" border="0" alt="" title="{$lang_plugin_final_extract_config['expand_all']}" /></a>
        </td>
    </tr>
EOT;

//Create a list of objects
$sql="SELECT name,value FROM `{$CONFIG['TABLE_FINAL_EXTRACT_CONFIG']}`";
$result=cpg_db_query($sql);
?>
<TR>
  <TD class=tableh2 onClick="show_section('section0')" colSpan=3><SPAN 
            style="CURSOR: pointer"><IMG title="click section name to expand" 
            height=9 alt="" 
            src="images/descending.gif" 
            width=9 border=0> <strong><?php echo $lang_plugin_final_extract_manage['list_block']; ?> </strong></SPAN></TD>
</TR>
<TR>
  <TD><TABLE class="maintable" id="section0" cellSpacing="1" cellPadding="0" width="100%" align="center" border="0">
      <form id="blocks" name="blocks" method="post" action="<?php echo $_SERVER['REQUEST_URI']?>">
        <TR>
        <TD><TABLE class=maintable cellSpacing=1 cellPadding=0 width="100%" align=center border=0>
            <TR>
              <TD width="70%" align="<?php echo $align ?>" dir="<?php echo $direction ?>" class=tableb><strong><?php echo $lang_plugin_final_extract_manage['list_name']; ?></strong></TD>
              <TD width="10%" align="center" vAlign=top class=tableb><strong><?php echo $lang_plugin_final_extract_manage['list_stat']; ?></strong></TD>
            </TR>
            
              <?php while($row=mysql_fetch_assoc($result)){?>
              <TR>
                <TD class=tableb align="<?php echo $align ?>" dir="<?php echo $direction ?>"><?php echo (stripslashes($row['name']));?></TD>
                <TD align="center" vAlign=top class=tableb><input name="<?php echo stripslashes($row['name']);?>" type="checkbox" id="<?php echo stripslashes($row['name']);?>" value="1" <?php if($row['value']==1) { echo 'checked="cheked"';} ?>/>                </TD>
              </TR>
              <?php } ?>
              <TR>
                <TD class=tableb align="<?php echo $align ?>" dir="<?php echo $direction ?>">&nbsp;</TD>
                <TD align="center" vAlign=top class=tableb>&nbsp;&nbsp;
                  <INPUT class="button" type="button" value="<?php echo $lang_plugin_final_extract_manage['list_chkall']; ?>" name="restore_config" onclick="return check_all('blocks');"></TD>
              </TR>
            
          </TABLE></TD>
      </TR>
      <TR>
        <TD align="center" class="tableb"><input class="button" type="submit" value="<?php echo $lang_plugin_final_extract_manage['list_chstat']; ?>" name="change_stat" />
        </TD>
      </TR></form>
  </TABLE></TD>
</TR>
<?php endtable();
pagefooter();
ob_end_flush();
mysql_free_result($result);
?>
