<?php
/* $Id: tableview.php 1 2006-06-07 08:07:41Z hodaka $
 *  ------------------------------------------------------------------------ *
 *                XOOPS - PHP Content Management System                      *
 *                    Copyright (c) 2000 XOOPS.org                           *
 *                       <http://www.xoops.org/>                             *
 *  ------------------------------------------------------------------------ *
 *                     MyAddress - XOOPS addressbook                         *
 *                        <http://www.kuri3.net/>                            *
 *             Copyright (c) 2004 by hodaka <hodaka@kuri3.net>               *
 * ------------------------------------------------------------------------- *
 * 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.                                       *
 *                                                                           *
 * You may not change or alter any portion of this comment or credits        *
 * of supporting developers from this source code or any supporting          *
 * source code which is considered copyrighted (c) material of the           *
 * original comment or credit authors.                                       *
 *                                                                           *
 * This program is distributed in the hope that it will be useful,           *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
 * GNU General Public License for more details.                              *
 *                                                                           *
 * You should have received a copy of the GNU General Public License         *
 * along with this program; if not, write to the Free Software               *
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *
 */

include("admin_header.php");
include_once( XOOPS_ROOT_PATH."/class/xoopstree.php" ) ;
include_once( XOOPS_ROOT_PATH."/class/xoopscomments.php" ) ;
include_once( XOOPS_ROOT_PATH."/class/xoopslists.php" ) ;
include_once( "../../../class/xoopsformloader.php" ) ;

$myts =& MyTextSanitizer::getInstance();
$cattree = new XoopsTree($table_cat,"cid","pid");

$op = isset( $_GET['op'] ) ? $_GET['op'] : '' ;
if( $op == '' && isset( $_POST['op'] ) ) $op = $_POST['op'] ;
switch( $op ) {
	case "Change":
		ChangeView();
		break;
	default :
	case "main" :
		mainView();
		break;
}

function mainView()
{
	global $xoopsModule, $xoopsDB, $xoopsConfig, $myts, $cattree;
	global $table_view ;

	// set table title
	include_once('../include/viewitems_sqlfield.php');
	
	xoops_cp_header();
	include('./mymenu.php'); // GIJOE
	// Select myaddress view (change terms,yesno,order)
	echo "<form method='POST' action='tableview.php'>\n";
	echo "<h3>"._AM_MYADDRESS_TABLEVIEW . "</h3>\n";
	OpenTable();
	echo "<table border=0>\n<tr><th>"._AM_MYADDRESS_VIEWTERM."</th><th>"._AM_MYADDRESS_VIEWYESNO."</th><th>"._AM_MYADDRESS_VIEWORDER."</th></tr>\n";
	$tableview_result = $xoopsDB->query( "SELECT * FROM $table_view order by title_sequence" ) ;
	$n=0;

	while($term = $xoopsDB->fetchArray( $tableview_result )){
		$n++;
		$yes_check = "";
		$no_check = "";
		echo "<tr><td>".$myaddress_viewtitle[$term['table_title']]['viewterm']."<input type=\"hidden\" name=\"table_title[$n]\" value=\"{$term['table_title']}\"></td>";
		if($term['title_indication'] != "0"){ $yes_check = "checked=\"checked\""; }else{ $no_check = "checked=\"checked\""; }
		echo "<td><input type=\"radio\" name=\"title_indication[$n]\" value=\"1\" {$yes_check}>"._MD_MYADDRESS_YES."&nbsp;&nbsp;";
		echo "<input type=\"radio\" name=\"title_indication[$n]\" value=\"0\" {$no_check}>". _MD_MYADDRESS_NO . "</td>";
		echo "<td><input type=\"text\" name=\"title_sequence[$n]\" size=\"2\" value=\"{$term['title_sequence']}\"></td></tr>\n";
	}
	echo "<input type=\"hidden\" name=\"op\" value=\"Change\">\n";
	echo "</table>\n<input type=\"submit\" name=\"submitbutton\" value=\"" ._AM_MYADDRESS_SEND. "\">\n</form>\n";
	CloseTable();
	echo "<br />\n";
	xoops_cp_footer();

}

function ChangeView()
{
	global $xoopsDB , $myts ;
	global $table_view ;

	foreach($_POST['table_title'] as $key => $table_title){
		$table_title = $myts->makeTboxData4Save(strval($_POST['table_title'][$key]));
		$title_indication = $myts->makeTboxData4Save(intval($_POST['title_indication'][$key]));
		$title_sequence = $myts->makeTboxData4Save(intval($_POST['title_sequence'][$key]));
		$query = "UPDATE $table_view set title_indication='$title_indication',title_sequence='$title_sequence' where table_title='$table_title'";
		$xoopsDB->query($query) or die( "DB error: cannot UPDATE viewtable" ) ;
	}

	redirect_header("tableview.php",1,_AM_MYADDRESS_CHANGEVIEW);
}


?>