<?php
// $Id: link_manage.php,v 1.6 2005/10/28 11:56:02 ohwada Exp $

// 2005-10-20 K.OHWADA
// REQ 3110: Add in this category

// 2005-10-14 K.OHWADA
// BUG 3095: the number of links does not change, if delete link
// use del_link_vote_comm_catlink_by_lid($lid)

// 2005-09-27 K.OHWADA
// BUG 3031: timeout occurs if many waiting links

// 2005-08-09 K.OHWADA
// BUG 2828: submit form is not displayed correctly
// not use add_tray_xxx

// 2005-01-20 K.OHWADA
// bug fix: forget to delete catlink

// 2004-12-26 K.OHWADA
// add zip, state, city, addr2Afax

// 2004-12-14 K.OHWADA
// rename link.php -> link_manage.php
// use xoops_form_extend()

// 2004-11-20 K.OHWADA
// LinkForm() ModLinkForm()
//   input varibale

// 2004-10-24 K.OHWADA
// mutual site, recommend site 
// link broken check
// URL-less mode
// delete message of Notice Undefined index
// RSS url
// user comment

// 2004/08/10 K.OHWADA
// use class weblinksCatlink

// 2004/02/05 K.OHWADA
// not public mode of name & mail when edit

//=========================================================
// admin link manage
// divid this file from index.php
// 2004/01/14 K.OHWADA
//=========================================================

include 'admin_header.php';
include_once XOOPS_ROOT_PATH."/include/xoopscodes.php";
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
include_once $MODULE_ROOT."/class/xoops_form_extend.php";
include_once $MODULE_ROOT."/include/submit_form.php";
include_once $MODULE_ROOT."/admin/modify.php";
include_once $MODULE_ROOT."/admin/admin_functions.php";

// BUG 3031: timeout occurs if many waiting links
include_once $MODULE_ROOT."/class/pagenavi.php";

// constant
$WEBLINKS_MAX_LINK_IN_DETAIL =  5;
$WEBLINKS_MAX_LINK_IN_PAGE   = 10;

$op = 'main';
if     ( isset($_POST['delete_link']) )  $op = 'delete_link';
elseif ( isset($_POST['delete_new']) )   $op = 'delete_new';
elseif ( isset($_POST['ignore']) )       $op = 'ignore';
elseif ( isset($_POST['op']) )           $op = $_POST['op'];
elseif ( isset($_GET['op']) )            $op = $_GET['op'];

// start
$tbl_category->getAll();

switch ($op) 
{
case "addLinkS":
	addLinkS();
	break;

case "modLink":
	modLink();
	break;

case "modLinkS":
	modLinkS();
	break;

case 'delete_link';
case "delLink":
	delLink();
	break;

case "listNewLinks":
	listNewLinks();
	break;

case 'delete_new';
case "delNewLink":
	delNewLink();
	break;

case "approve":
	approve();
	break;

case "listModReq":
	listModReq();
	break;

case "approveModReq":
	approveModReq();
	break;

case "changeModReq":
	changeModReq();
	break;

case 'ignore';
case "ignoreModReq":
	ignoreModReq();
	break;

case 'main':
case "addLink":
default:
	addLink();
	break;

}

exit();
// --- end of main ---


//---------------------------------------------------------
// function
//---------------------------------------------------------
function addLink()
{
	global $xoops_user_uid, $xoops_user_uname, $xoops_user_email;
	global $myts;
	global $tbl_link;

// REQ 3110: Add in this category
	$cid_arr = array();
	if ( isset($_GET['cid']) )
	{
		$cid_arr = array($_GET['cid']);
	}

	$link = array(
// user	
		'nameflag'  => 0,
		'mailflag'  => 0,
		'uid'   => $xoops_user_uid,
		'name'  => $myts->makeTboxData4Edit( $xoops_user_uname ),
		'mail'  => $myts->makeTboxData4Edit( $xoops_user_email ),

// init
// REQ 3110: Add in this category
		'cid_arr'  => $cid_arr,

		'url'       => '',
		'banner'    => '',
		'rss_url'   => '',
		'rss_flag'  => 3,	// auto discovery

// table field
		'lid'          => '',
		'recommend'    => '',
		'mutual'       => '',
		'title'        => '',
		'zip'          => '',
		'state'        => '',
		'city'         => '',
		'addr'         => '',
		'addr2'        => '',
		'tel'          => '',
		'fax'          => '',
		'company'      => '',
		'description'  => '',
		'usercomment'  => '',
		'admincomment' => '',

// admin
		'mid'          => '',
		'broken'       => '',
		'time_create'  => '',
		'time_update'  => '',
		'link_uname'   => '',
		'link_email'   => '',
		'updateflag'   => 1,	// update

		);

	xoops_cp_header();
	echo "<h3>"._WLS_WEBLINKSCONF."</h3>\n";
	echo "<h4>"._WEBLINKS_ADMIN_ADD_LINK."</h4>\n";

	$total = $tbl_link->getNumAll();
	printf(_WLS_THEREARE, $total);
    echo "<br /><br />\n";
	print_link_index();

	LinkForm(0, $link);

	echo "<br />\n";
	xoops_cp_footer();
}

function addLinkS()
{
	global $eh;
	global $tbl_link;

// check form
	if ( $tbl_link->checkFormAddLink( $_POST ) ) 
	{
		xoops_cp_header();
		echo "<h4>"._WEBLINKS_ADMIN_ADD_LINK."</h4>\n";
		echo "<hr>\n";
		echo $tbl_link->getErrorMsgAddLink();
		echo "<hr>\n";

		$tbl_link->clear_items(); 
		$tbl_link->set_items( $_POST );
		$tbl_link->make_name_mail_edit_for_owner();
		$link = $tbl_link->make_preview_in_form();

		LinkForm(0, $link);
		xoops_cp_footer();
		exit();
    }

// insert link
	$tbl_link->addLink($_POST) or $eh->show("0013");
	$newid = $tbl_link->getNewid();

// notification
	list($tags,$cid) = $tbl_link->makeTagsAddLink($newid);
	$notification_handler =& xoops_gethandler('notification');
	$notification_handler->triggerEvent('global', 0, 'new_link', $tags);
	$notification_handler->triggerEvent('category', $cid, 'new_link', $tags);

	redirect_header("link_list.php",1,_WLS_NEWLINKADDED);
}

function modLink()
{
	global $eh;
   	global $tbl_link, $tbl_broken, $tbl_votedata;

	$lid = 0;
	if ( isset($_GET['lid']) )  $lid = intval( $_GET['lid'] );

	$record = $tbl_link->getRowByLid($lid);
	$link   = $tbl_link->makeEditDisplayAdmin($record);

	xoops_cp_header();
	echo "<h4>"._WLS_WEBLINKSCONF."</h4>";
   	echo "<h4>"._WLS_MODLINK."</h4><br />";

	LinkForm(1,$link);
	echo "<hr>";

	$totalvotes = $tbl_votedata->getNumByLid($lid);

    echo "<table width=100%>\n";
    echo "<tr><td colspan=7><b>";
	printf(_WLS_TOTALVOTES,$totalvotes);
	echo "</b><br /><br /></td></tr>\n";

// Show Registered Users Votes
	$records5 = $tbl_votedata->getRowsByLidUser($lid);
	$votes = count($records5);

    echo "<tr><td colspan=7><br /><br /><b>";
	printf(_WLS_USERTOTALVOTES,$votes);
	echo "</b><br /><br /></td></tr>\n";
    echo "<tr><td><b>" ._WLS_USER."  </b></td><td><b>" ._WLS_IP."  </b></td><td><b>" ._WLS_RATING."  </b></td><td><b>" ._WLS_USERAVG."  </b></td><td><b>" ._WLS_TOTALRATE."  </b></td><td><b>" ._WLS_DATE."  </b></td><td align=\"center\"><b>" ._WLS_DELETE."</b></td></tr>\n";
    if ($votes == 0){
		echo "<tr><td align=\"center\" colspan=\"7\">" ._WLS_NOREGVOTES."<br /></td></tr>\n";
    }
    $x=0;
    $colorswitch="dddddd";

	foreach ($records5 as $record5)
	{
//Individual user information
		$ratingid        = $record5['ratingid'];
		$ratinguser      = $record5['ratinguser'];
		$rating          = $record5['rating'];
		$ratinghostname  = $record5['ratinghostname'];
		$ratingtimestamp = $record5['ratingtimestamp'];

		list($uservotes,$useravgrating) = $tbl_votedata->getRatingByRatinguser($ratinguser);

        $useravgrating = number_format($useravgrating, 1);
		$ratingusername = XoopsUser::getUnameFromId($ratinguser);
        echo "<tr><td bgcolor=\"".$colorswitch."\">".$ratingusername."</td><td bgcolor=\"$colorswitch\">".$ratinghostname."</td><td bgcolor=\"$colorswitch\">$rating</td><td bgcolor=\"$colorswitch\">".$useravgrating."</td><td bgcolor=\"$colorswitch\">".$uservotes."</td><td bgcolor=\"$colorswitch\">".$ratingtimestamp."</td><td bgcolor=\"$colorswitch\" align=\"center\"><b>".myTextForm("index.php?op=delVote&lid=$lid&rid=$ratingid", "X")."</b></td></tr>\n";
    	$x++;
    	if ( $colorswitch == "dddddd" ) {
			$colorswitch="ffffff";
    	} else {
			$colorswitch="dddddd";
		}
    }

// Show Unregistered Users Votes
	$records5 = $tbl_votedata->getRowsByLidRatinguser($lid,0);
	$votes = count($records5);

    echo "<tr><td colspan=7><b><br /><br />";
	printf(_WLS_ANONTOTALVOTES,$votes);
	echo "</b><br /><br /></td></tr>\n";
    echo "<tr><td colspan=2><b>" ._WLS_IP."  </b></td><td colspan=3><b>" ._WLS_RATING."  </b></td><td><b>" ._WLS_DATE."  </b></b></td><td align=\"center\"><b>" ._WLS_DELETE."</b></td><br /></tr>";
    if ( $votes == 0 ) {
		echo "<tr><td colspan=\"7\" align=\"center\">" ._WLS_NOUNREGVOTES."<br /></td></tr>";
    }
    $x=0;
    $colorswitch="dddddd";

	foreach ($records5 as $record5)
    {
		$ratingid        = $record5['ratingid'];
		$ratinguser      = $record5['ratinguser'];
		$rating          = $record5['rating'];
		$ratinghostname  = $record5['ratinghostname'];
		$ratingtimestamp = $record5['ratingtimestamp'];

		$formatted_date = formatTimestamp($ratingtimestamp);
        echo "<td colspan=\"2\" bgcolor=\"$colorswitch\">$ratinghostname</td><td colspan=\"3\" bgcolor=\"$colorswitch\">$rating</td><td bgcolor=\"$colorswitch\">$formatted_date</td><td bgcolor=\"$colorswitch\" aling=\"center\"><b>".myTextForm("index.php?op=delVote&lid=$lid&rid=$ratingid", "X")."</b></td></tr>";
    	$x++;
    	if ( $colorswitch == "dddddd" ) {
			$colorswitch="ffffff";
    	} else {
			$colorswitch="dddddd";
		}
	}
 	echo "<tr><td colspan=\"6\">&nbsp;<br /></td></tr>\n";
	echo "</table>\n";

	xoops_cp_footer();
}

function modLinkS()
{
	global $tbl_link;

	$lid = 0;
	if ( isset($_POST['lid']) )  $lid = intval( $_POST['lid'] );

// check form
	if ( $tbl_link->checkFormModLinkAdmin( $_POST ) ) 
	{
		xoops_cp_header();
		echo "<h4>"._WLS_MODLINK."</h4><br />";
		echo "<hr>\n";
		echo $tbl_link->getErrorMsgModLink();
		echo "<hr>\n";

		$tbl_link->clear_items(); 
		$tbl_link->getRowByLid($lid);
		$tbl_link->set_items( $_POST );

		$arr_1 = $tbl_link->make_preview_in_form();
		$arr_2 = $tbl_link->make_data_4_edit_admin();
		$link  = array_merge($arr_1, $arr_2);

		LinkForm(1, $link);
		xoops_cp_footer();
		exit();
    }

// update link
	$tbl_link->modLinkAdmin( $_POST ) or $eh->show("0013");

	redirect_header("link_list.php",1,_WLS_DBUPDATED);
	exit();
}

function delLink()
{
	global $eh, $xoopsModule;
	global $tbl_link, $tbl_votedata, $tbl_catlink;
	global $xoops_module_mid;

	$lid = 0;
	if     ( isset($_POST['lid']) )  $lid = intval( $_POST['lid'] );
	elseif ( isset($_GET['lid']) )   $lid = intval( $_GET['lid'] );

// BUG 3095: the number of links does not change, if delete link
//	$tbl_link->delete($lid)          or  $eh->show("0013");
//	$tbl_votedata->deleteByLid($lid) or  $eh->show("0013");
//	$tbl_catlink->deleteByLid($lid)  or  $eh->show("0013");
//	xoops_comment_delete( $xoops_module_mid, $lid);
//	xoops_notification_deletebyitem ( $xoops_module_mid, 'link', $lid);

	del_link_vote_comm_catlink_by_lid($lid);

    redirect_header("link_list.php",1,_WLS_LINKDELETED);
	exit();
}

function LinkForm($flag=0, $link='')
{
	global $xoopsUser;
	global $weblinksConfig;
	global $MODULE_ROOT, $MODULE_URL;

// input varibale
	$SIZE_TEXT =  50;
	$MAX_TEXT  = 100;
	$SIZE_URL  =  70;
	$MAX_URL   = 250;

	global $tbl_category;
	$selbox = $tbl_category->makeEditSelboxMulti( $link['cid_arr'] );

	switch ($flag) 
	{
		case 1:
			$form_title = _WLS_MODLINK;
			$op         = 'modLinkS';
			$button_val = _WLS_MODIFY;
			$button_del_name = 'delete_link';
			$button_del_val  = _DELETE;
			break;

		case 2:
			$form_title = _WLS_MODLINK;
			$op         = 'approve';
			$button_val = _WLS_APPROVE;
			$button_del_name = 'delete_new';
			$button_del_val  = _WLS_IGNORE;
			break;

		case 0:
		default:
			$form_title = _WLS_ADDNEWLINK;
			$op         = 'addLinkS';
			$button_val = _WLS_ADD;
			$button_del_name = '';
			$button_del_val  = '';
			break;
	}

	echo "<br />\n";

// --- form start ---
	$builder = new xoops_form_extend();
	$builder->set_param_text(     $SIZE_TEXT, $MAX_TEXT );
	$builder->set_param_text_url( $SIZE_URL,  $MAX_URL  );

	$builder->start_theme_form( $form_title, 'link_edit' );

	$builder->add_hidden( 'op',  $op );
	$builder->add_hidden( 'mid', $link['mid']);
	$builder->add_hidden( 'lid', $link['lid']);
	$builder->add_hidden( 'time_update', $link['time_update']);
	$builder->add_hidden( 'time_create', $link['time_create']);

	if ($flag == 2)
	{
		$builder->add_label( _WEBLINKS_MID, "<b>".$link['mid']."</b>");
	}

	if (($flag == 1) || ($flag == 2))
	{
		$builder->add_label( _WLS_LINKID, "<b>".$link['lid']."</b>");
		$builder->add_text( _WEBLINKS_USERID, 'uid', $link['uid']);

		$val_uid = $link['link_uname']."&nbsp;&nbsp;".$link['link_email'];
		$builder->add_label( _WLS_OWNER, $val_uid);

		$builder->add_label( _WEBLINKS_CREATE,     '<b>'.$link['created'].'</b>');
		$builder->add_label_radio( _WLS_LASTUPDATE, '<b>'.$link['updated'].'</b>', 'updateflag', $link['updateflag'], get_opt_time() );
	}

	$builder->add_checkbox_multi( _WLS_MARK, make_value_mark( $link['recommend'], $link['mutual'] ) );

	$builder->add_text( "* "._WLS_SITETITLE." *", 'title', $link['title'] );
	$builder->add_text_url_visit( "* "._WLS_SITEURL." *", 'url', $link['url'], get_visit_mark() );

	if ($flag == 1)
	{
		$val_broken  = highlight_number( $link['broken'] );
		$builder->add_label( _WLS_BROKEN_COUNTER, $val_broken);
		$builder->add_text( '', 'broken', 0 );
	}

	$builder->add_text_url_image( _WLS_BANNERURL, 'banner',  $link['banner'] );

	$builder->add_element( make_tray_rss_url( _WLS_RSS_URL, $link['rss_url'], $link['rss_flag'], $SIZE_URL, $MAX_URL) );

	$builder->add_text_radio(_WLS_NAME,  'name', $link['name'], 'nameflag', $link['nameflag'], get_opt_name_mail_flag() );
	$builder->add_text_radio(_WLS_EMAIL, 'mail', $link['mail'], 'mailflag', $link['mailflag'], get_opt_name_mail_flag() );

	$builder->add_text(_WLS_COMPANY,  'company', $link['company']);
	$builder->add_text(_WLS_ZIP,      'zip',     $link['zip']);
	$builder->add_text(_WLS_STATE,    'state',   $link['state']);
	$builder->add_text(_WLS_CITY,     'city',    $link['city']);
	$builder->add_text(_WLS_ADDR,     'addr',    $link['addr']);
	$builder->add_text(_WLS_ADDR2,    'addr2',   $link['addr2']);
	$builder->add_text(_WLS_TEL,      'tel',     $link['tel']);
	$builder->add_text(_WLS_FAX,      'fax',     $link['fax']);

	$builder->add_label("* "._WLS_CATEGORY." *", make_category($selbox) );

	$field_desc = new XoopsFormDhtmlTextArea("* "._WLS_DESCRIPTION." *", 'description', $link['description'], 15, 60);
	$builder->sform->addElement( $field_desc );

	$builder->add_textarea( _WLS_USER_COMMENT, 'usercomment',  $link['usercomment']);
	$builder->add_textarea( _WLS_ADMINCOMMENT, 'admincomment', $link['admincomment']);

	$builder->add_submit_button( '', 'post', $button_val );

	if (($flag == 1) || ($flag == 2))
	{
		$builder->add_submit_cancel_button('', $button_del_name, $button_del_val, 'cancel', _CANCEL);
	}

	$builder->display();
// --- form end ---

}


function ModLinkForm($old,$new)
{
	$SIZE_TEXT =  50;
	$MAX_TEXT  = 100;
	$SIZE_URL  =  70;
	$MAX_URL   = 250;

	global $tbl_category;
	$selbox_new = $tbl_category->makeEditSelboxMulti( $new['cid_arr'] );
	$selbox_old = $tbl_category->showSelboxMulti( $old['cid_arr'] );

	global $tbl_link;
	list($link_uname, $link_email) = $tbl_link->make_xoops_guest_link( $new['muid'] );

	global $MODULE_URL;
	global $link_image_checked, $link_image_nochecked;
	$image_checked   = $MODULE_URL.'/images/checked.gif';
	$image_nochecked = $MODULE_URL.'/images/nochecked.gif';
	$link_image_checked    = "<img src='$image_checked'   border='0' alt='checked' />";
	$link_image_nochecked  = "<img src='$image_nochecked' border='0' alt='nochecked' />";

	echo "<br />\n";

// --- form start ---
	$builder = new xoops_form_extend();
	$builder->set_param_text(     $SIZE_TEXT, $MAX_TEXT );
	$builder->set_param_text_url( $SIZE_URL,  $MAX_URL  );

	$builder->start_theme_form( _WLS_MODREQUESTS, 'link_append' );

	$builder->add_hidden( 'op', 'approveModReq' );
	$builder->add_hidden( 'mid', $new['mid']);
	$builder->add_hidden( 'lid', $old['lid']);
	$builder->add_hidden( 'time_create', $old['time_create']);
	$builder->add_hidden( 'time_update', $old['time_update']);

	$builder->add_label( _WEBLINKS_MID, "<b>".$new['mid']."</b>");
	$builder->add_label( _WLS_LINKID, "<b>".$old['lid']."</b>");

	$val_uid_new = $new['muid'].'&nbsp;&nbsp;'.$link_uname."&nbsp;&nbsp;".$link_email;
	$val_uid_old = $old['link_uname']."&nbsp;&nbsp;".$old['link_email'];
	$builder->add_text( _WEBLINKS_USERID, 'uid', $old['uid']);
	$builder->add_label( _WLS_OWNER,     $val_uid_old );
	$builder->add_label( _WLS_SUBMITTER, $val_uid_new );

	$builder->add_label( _WEBLINKS_CREATE,     $old['created'] );
	$builder->add_label_radio( _WLS_LASTUPDATE, $old['updated'], 'updateflag', 0, get_opt_time() );

// mark
	$opt_recommend = array(
		1 => _WLS_SITE_RECOMMEND
		);

	$opt_mutual = array(
		1 => _WLS_SITE_MUTUAL
		);

	$val_recommend = make_value_checked( $old['recommend'], $opt_recommend );
	$val_mutual    = make_value_checked( $old['mutual'],    $opt_mutual );
	$val_mark_old = $val_recommend." ".$val_mutual;

	$builder->add_label( _WLS_MARK, $val_mark_old );
	$builder->add_checkbox_multi( '', make_value_mark( $new['recommend'], $new['mutual'] ) );

// title
	$builder->add_label( "* "._WLS_SITETITLE." *", $old['title']);
	$builder->add_text( '', 'title', $new['title'] );

	$builder->add_label( "* "._WLS_SITEURL." *", make_value_url_old( $old['url'] ) );
	$builder->add_text_url_visit( '', 'url', $new['url'], get_visit_mark() );

// banner
	if ( $old['banner'] )
	{
		$banner_old  = make_value_url_old( $old['banner'] );
		$banner_old .= "<br /><br />\n";
		$banner_old .= $builder->make_image_link( $old['banner'] );
	}
	else
	{
		$banner_old = get_null_bar();
	}

	$builder->add_label( _WLS_BANNERURL, $banner_old );
	$builder->add_text_url_image( '', 'banner', $new['banner'] );

// rss
	$val_rss_old  = make_value_url_old( $old['rss_url']) ."<br />\n";
	$val_rss_old .= make_value_checked( $old['rss_flag'], get_opt_rss_flag() );
	$builder->add_label( _WLS_RSS_URL, $val_rss_old );
	$builder->add_element( make_tray_rss_url( '', $new['rss_url'], $new['rss_flag'], $SIZE_URL, $MAX_URL) );

	$val_name_old = make_value_name_mail_old($old['name'], $old['nameflag'] );
	$builder->add_label( _WLS_NAME,  $val_name_old );
	$builder->add_text_radio( '', 'name', $new['name'], 'nameflag', $new['nameflag'], get_opt_name_mail_flag() );

	$val_mail_old = make_value_name_mail_old($old['mail'], $old['mailflag'] );
	$builder->add_label( _WLS_EMAIL, $val_mail_old );
	$builder->add_text_radio( '', 'mail', $new['mail'], 'mailflag', $new['mailflag'], get_opt_name_mail_flag() );

	$builder->add_label(_WLS_COMPANY, make_value_show( $old['company'] ) );
	$builder->add_text( '', 'company', $new['company']);

	$builder->add_label(_WLS_ZIP, make_value_show( $old['zip'] ) );
	$builder->add_text( '', 'zip', $new['zip']);

	$builder->add_label(_WLS_STATE, make_value_show( $old['state'] ) );
	$builder->add_text( '', 'state', $new['state']);

	$builder->add_label(_WLS_CITY, make_value_show( $old['city'] ) );
	$builder->add_text( '', 'city', $new['city']);

	$builder->add_label(_WLS_ADDR, make_value_show( $old['addr'] ) );
	$builder->add_text( '', 'addr', $new['addr']);

	$builder->add_label(_WLS_ADDR2, make_value_show( $old['addr2'] ) );
	$builder->add_text( '', 'addr2', $new['addr2']);

	$builder->add_label(_WLS_TEL,  make_value_show( $old['tel'] ));
	$builder->add_text( '', 'tel',  $new['tel']);

	$builder->add_label(_WLS_FAX,  make_value_show( $old['fax'] ));
	$builder->add_text( '', 'fax',  $new['fax']);

	$builder->add_label("* "._WLS_CATEGORY." *", $selbox_old);
	$builder->add_label( '', make_category($selbox_new) );

	$val_desc_old     = make_value_desc_old( $old['description'] );
	$builder->add_label("* "._WLS_DESCRIPTION." *", $val_desc_old );
	$field_desc = new XoopsFormDhtmlTextArea( '', 'description', $new['description'], 15, 60);
	$builder->add_element( $field_desc );

	$val_usercomm_old = make_value_desc_old( $old['usercomment'] );
	$builder->add_label( _WLS_USER_COMMENT, $val_usercomm_old );
	$builder->add_textarea( '', 'usercomment',  $new['usercomment']);

	$builder->add_label( _WLS_ADMINCOMMENT, _WEBLINKS_ADMIN_PRESENT_SAVE );
	$builder->add_textarea( '', 'admincomment', $old['admincomment']);

// button
	$builder->add_submit_button( '', 'post', _WLS_APPROVE );
	$builder->add_submit_cancel_button('', 'ignore', _WLS_IGNORE, 'cancel', _CANCEL);

	$builder->display();
// --- form end ---

}


function get_opt_time()
{
	$opt = array(
		0 => _WLS_NOTTIMEUPDATE,
		1 => _WLS_TIMEUPDATE
		);
	return $opt;
}

function get_visit_mark()
{
	$mark = " ["._WLS_VISIT."] ";
	return $mark;
}

function get_null_bar()
{
	return "-----";
}

function make_value_mark( $recommend, $mutual )
{
	$arr_rerecommend = array('recommend', $recommend, 1, _WLS_SITE_RECOMMEND );
	$arr_mutual      = array('mutual',    $mutual,    1, _WLS_SITE_MUTUAL );
	$val_mark        = array($arr_rerecommend, $arr_mutual );
	return $val_mark;
}

function make_tray_rss_url($caption, $rss_url, $rss_flag, $size, $max )
{
// BUG 2828: submit form is not displayed correctly
// not use add_tray_xxx
//	$maker = new xoops_form_extend();
//	$maker->start_tray( $caption, " ");
//	$maker->add_tray_text_url( '', 'rss_url', $rss_url, $size, $max );
//	if ($rss_url)
//	{
//		$link = $maker->make_url_link( $rss_url, get_visit_mark(), '_blank' );
//		$maker->add_tray_label( '', $link );
//	}
//	$maker->add_tray_label( '', "<br />\n");
//	$maker->add_tray_radio_array('', 'rss_flag', $rss_flag, get_opt_rss_flag() );
//	return $maker->tray;

	$maker = new xoops_form_extend();
	$tray  = new XoopsFormElementTray( $caption, '' );
	$tray->addElement( $maker->make_text_url('',  'rss_url', $rss_url, $size, $max) );

	if ($rss_url)
	{
		$link = $maker->make_url_link( $rss_url, get_visit_mark(), '_blank' );
		$tray->addElement( new XoopsFormLabel('', $link) );
	}

	$tray->addElement( new XoopsFormLabel('', "<br />\n") );
	$tray->addElement( $maker->make_radio_array('', 'rss_flag', $rss_flag, get_opt_rss_flag() ) );

	return $tray;
}

function make_value_url_old($url)
{
	$maker = new xoops_form_extend();

	if ( empty($url) )
	{
		return get_null_bar();
	}

	$link = $maker->make_url_link( $url, get_visit_mark(), '_blank' );
	$link = $url." ".$link;

	return $link;
}

function make_value_name_mail_old($name, $nameflag )
{
	$value  = make_value_show($name)."<br />";
	$value .= make_value_checked($nameflag, get_opt_name_mail_flag(), 0 );
	return $value;
}

function make_value_desc_old($desc)
{
	$text  = "<table border='1' bordercolor='black' cellpadding='0' cellspacing='0' width='100%'>";
	$text .= "<tr><td><pre>";
	$text .= $desc;
	$text .= "</pre></td></tr></table>";

	return $text;
}


function make_value_show($item)
{
	$show = $item;

	if (empty($item))
	{
		$show = get_null_bar();
	}

	return $show;
}

function make_value_checked($value, $opt_arr, $highlight='' )
{
	global $link_image_checked, $link_image_nochecked;

	$text = '';

	foreach ( $opt_arr as $opt_key => $opt_value )
	{
		if ( $value == $opt_key)
		{
			if ($highlight === $value)
			{
				$text .= $link_image_checked;
				$text .= " <span style='color: #ff0000; font-weight: bold'>$opt_value</span>";
			}
			else
			{
				$text .= $link_image_checked." ".$opt_value;
			}
		}
		else
		{
			$text .= $link_image_nochecked." <s>".$opt_value."</s>";
		}

		$text .= " ";
	}

	return $text;
}

?>
