<?php
/*
Plugin Name: Irontec - Tunnels
Plugin URI: http://www.irontec.com
Description: Creaci&oacute;n de t&uacute;neles de convicci&oacute;n utilizados durante el proceso de registro.
Version: 0.1
Author: Irontec
Author URI: http://www.irontec.com
License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
*/

// Define plugin version and plugin db version
define( 'IRON_TUNNELS_VERSION', '0.2' );
define( 'IRON_TUNNELS_DB_VERSION', '0.1' );
define( 'IRON_TUNNELS_URL', WP_PLUGIN_URL . '/irontec-tunnels' );

// Activation hook
register_activation_hook( __FILE__, 'iron_tunnels_activation' );
// Deactivation hook
register_deactivation_hook( __FILE__, 'iron_tunnels_deactivation' );
// Add the plugin Administration Menu
add_action('admin_menu', 'iron_tunnels_create_menu');

function iron_tunnels_display( $cat_id ) {
	global $wpdb;

	// Obtain the different item types
	$table_name = $wpdb->prefix . "iron_tunnels_entries";

	$results = $wpdb->get_results(
	"SELECT ".$table_name.".*, group_concat(rel.tag_id separator ',') as tagsId FROM ".$table_name."
	left join wp_iron_tunnels_relations rel on (rel.entry_id=".$table_name.".id)
	WHERE entry_category = ".$cat_id." group by ".$table_name.".id");
	
	echo mysql_error();

	echo '<ul class="iron-tunnel-main">';

	if (sizeof($results)>0) {
		foreach ($results as $entry) {
			$avatar=$entry->entry_avatar;
			if ($entry->entry_avatar=="") {
				$avatar=get_stylesheet_directory_uri().'/_inc/images/bp_default_avatar_mini.png';
			}

			$tagsClasses = "tg" . implode(" tg",explode(",",$entry->tagsId));
			
			if ($_COOKIE['LANG']=='eu')
			 $ent_content = $entry->entry_content_eu;
			elseif ($_COOKIE['LANG']=='en')
             $ent_content = $entry->entry_content_en;
            else
             $ent_content = $entry->entry_content;  

			echo '
			<li style="min-height: 32px;" class="'.$tagsClasses.'">
				<div class="tunnel-chat-avatar">
				<img style="width: 32px; height: 32px;" src="'.$avatar.'" />
				</div>
				<div class="tunnel-chat-content">
					<div class="tunnel-chat-name">'.$entry->entry_username.'</div>
					'.$ent_content.'
				</div>
			</li>
			';
		}
	}
	else
		echo '<li>'. __ ('No se han encontrado conversaciones en &eacute;sta categor&iacute;a, prueba otra.', 'buddypress') .'</li>';

	echo '</ul>';
}

function iron_tunnels_display_tagcloud ($cat_id) {
	global $wpdb;

	echo '<ul class="iron-tunnel-tags">';

	// Obtain the different tags
	$table_name = $wpdb->prefix . "iron_tunnels_tags";

	$sql = "SELECT ".$table_name.".* ,count(rel.entry_id) as total ";
	$sql .= " FROM ".$table_name. " left join wp_iron_tunnels_relations rel on (rel.tag_id=".$table_name.".id and rel.entry_id in (select id from wp_iron_tunnels_phrases where phrase_category='".$cat_id."'))";
	$sql .= " where rel.entry_id is not null group by ".$table_name.".id";


/*
	$sql = "SELECT ".$table_name.".* ,count(rel.id_rel) as total ";
        $sql .= " FROM ".$table_name. " left join wp_iron_tunnels_relations rel on (rel.tag_id=".$table_name.".id and rel.entry_id in (select id from wp_iron_tunnels_entries where entry_category='".$cat_id."'))";
        $sql .= " where rel.id_rel is not null group by ".$table_name.".id";
*/
	$results = $wpdb->get_results($sql);

	if (sizeof($results)>0) {
		$total = 0;
		$tags = array();
		foreach ($results as $entry) {
			$idx = $entry->total * 100;
			while (isset($tags[$idx])) $idx++;
			if ($_COOKIE['LANG']=='eu')
			 $tags[$idx] = array("name"=> $entry->tag_name_eu , "id"=>$entry->id,"total"=>$entry->total);
			elseif ($_COOKIE['LANG']=='en')
			 $tags[$idx] = array("name"=> $entry->tag_name_en , "id"=>$entry->id,"total"=>$entry->total);
			else
			 $tags[$idx] = array("name"=> $entry->tag_name , "id"=>$entry->id,"total"=>$entry->total); 
			$total += $entry->total;
		}


		ksort($tags);
		$tags = array_reverse($tags);

		$baseSize = "130";
		$prev = 0;
		foreach($tags as $idx => $aTag) {
				echo '<li class="tag" rel="tg'.$aTag['id'].'" style="font-size:'.$baseSize.'%;">'.$aTag['name'].'</li> ';

				if ($aTag['total'] < $prev) {
					$baseSize -= 15;
				}

				$prev = $aTag['total'];
		}


	}
	else
		echo '<li>'. __ ('No se han encontrado tags.', 'buddypress') .'</li>';

	echo '</ul>';
}

function iron_tunnels_get_category_data ( $cat_id ) {
	global $wpdb;

	// Obtain the category data
	$table_name = $wpdb->prefix . "iron_tunnels_categories";
	$results = $wpdb->get_results(
	"SELECT * FROM ".$table_name." WHERE category_id='".$cat_id."'");

	if (sizeof($results) == 1) {
		return $results[0];
	}
	return false;
}

function iron_tunnels_display_slogan () {
	if ($_COOKIE['LANG']=='eu')
		echo get_site_option('iron_tunnels_slogan_eu');
	elseif ($_COOKIE['LANG']=='en')
        echo get_site_option('iron_tunnels_slogan_en');	
	else
		echo get_site_option('iron_tunnels_slogan');
}

function iron_tunnels_display_top_slogan () {

    if ($_COOKIE['LANG']=='eu')
        echo get_site_option('iron_tunnels_top_slogan_eu');
    elseif ($_COOKIE['LANG']=='en')
        echo get_site_option('iron_tunnels_top_slogan_en'); 
    else
        echo get_site_option('iron_tunnels_top_slogan');
}

function iron_tunnels_display_maintext () {
	if ($_COOKIE['LANG']=='eu')
		echo get_site_option('iron_tunnels_maintext_eu');
	elseif ($_COOKIE['LANG']=='en')
        echo get_site_option('iron_tunnels_maintext_en');	
	else
		echo get_site_option('iron_tunnels_maintext');
}

function iron_tunnels_display_register_text () {
	if ($_COOKIE['LANG']=='eu')
		echo get_site_option('iron_tunnels_register_text_eu');
	elseif ($_COOKIE['LANG']=='en')
        echo get_site_option('iron_tunnels_register_text_en');	
	else
		echo get_site_option('iron_tunnels_register_text');
}

function iron_tunnels_display_register_addtext () {
	if ($_COOKIE['LANG']=='eu')
		echo get_site_option('iron_tunnels_register_addtext_eu');
	elseif ($_COOKIE['LANG']=='en')
        echo get_site_option('iron_tunnels_register_addtext_en');	
	else
		echo get_site_option('iron_tunnels_register_addtext');
}

function iron_tunnels_get_category_phrases ( $cat_id ) {
	global $wpdb;

	// Obtain the category data
	$table_name = $wpdb->prefix . "iron_tunnels_phrases";
	$results = $wpdb->get_results(
	"SELECT * FROM ".$table_name." where phrase_category='".$cat_id."'");

	$ret = array();

	if (sizeof($results)>0) {

		foreach ($results as $category) {
			if ($_COOKIE['LANG']=='eu')
				$ret[] = $category->phrase_content_eu;
			elseif ($_COOKIE['LANG']=='en')
                $ret[] = $category->phrase_content_en;	
			else
				$ret[] = $category->phrase_content;
		}
	}
	return $ret;
}

/*
Activation of the plugin.
*/
function iron_tunnels_activation() {
	// Check DB version first
	if ( get_site_option( 'iron_tunnels_db_version' ) < IRON_TUNNELS_DB_VERSION ) {
		iron_tunnels_install_db();
	}
}

/*
Deactivation of the plugin.
*/
function iron_tunnels_deactivation() {
	// Do NOT delete DB TABLE upon deactivation
	iron_tunnels_uninstall_db();
}

/*
Installation of the DB tables
*/
function iron_tunnels_install_db () {
	global $wpdb;

	$iron_tunnels_db_version = IRON_TUNNELS_DB_VERSION;
	$iron_tunnels_slogan = 'Elige tu experiencia y participa en la red';
	$iron_tunnels_slogan_eu = 'Elige tu experiencia y participa en la red';
	$iron_tunnels_maintext = '�Aun no conoces kronikoen-sarea? Esta es tu comunidad, con los contenidos que te interesan. La red construida por y para las personas que viven con una enfermedad cr�nica y las que las acompa�an y cuidan. Echa un vistazo, expr�sate, escucha, construye, crece y conoce a m�s personas en kronikoen-sarea.';
	$iron_tunnels_maintext_eu = '�Aun no conoces kronikoen-sarea? Esta es tu comunidad, con los contenidos que te interesan. La red construida por y para las personas que viven con una enfermedad cr�nica y las que las acompa�an y cuidan. Echa un vistazo, expr�sate, escucha, construye, crece y conoce a m�s personas en kronikoen-sarea.';
	$iron_tunnels_maintext_en = '�Aun no conoces kronikoen-sarea? Esta es tu comunidad, con los contenidos que te interesan. La red construida por y para las personas que viven con una enfermedad cr�nica y las que las acompa�an y cuidan. Echa un vistazo, expr�sate, escucha, construye, crece y conoce a m�s personas en kronikoen-sarea.';

	if ( !empty($wpdb->charset) )
		$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";

	// Create table categories
	$table_name = $wpdb->prefix . "iron_tunnels_categories";

	if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {

		$sql[] = "CREATE TABLE {$table_name} (
	  		id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
			category_id bigint(20) NOT NULL,
			category_order tinyint(1) NOT NULL,
			category_name_eu varchar(250) NOT NULL,
			category_name_en varchar(250) NOT NULL,
			category_phrase varchar(250) NOT NULL,
			category_phrase_eu varchar(250) NOT NULL,
			category_phrase_en varchar(250) NOT NULL,
			image1 varchar(200) NOT NULL,
			image2 varchar(200) NOT NULL,
			image3 varchar(200) NOT NULL,
			image4 varchar(200) NOT NULL,
			bg_att varchar(100) NOT NULL,
			KEY category_id (category_id)
	 	   ) {$charset_collate};";

		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
		dbDelta($sql);
	}

	// Create table tags
	$table_name = $wpdb->prefix . "iron_tunnels_tags";

	if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {

		$sql[] = "CREATE TABLE {$table_name} (
	  		id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
			tag_name varchar(100) NOT NULL,
			tag_description varchar(250),
			tag_name_eu varchar(100) NOT NULL,
			tag_description_eu varchar(250),
			tag_name_en varchar(100) NOT NULL,
            tag_description_en varchar(250)
	 	   ) {$charset_collate};";

		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
		dbDelta($sql);
	}

	// Create table entries
	$table_name = $wpdb->prefix . "iron_tunnels_entries";

	if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {

		$sql[] = "CREATE TABLE {$table_name} (
	  		id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
			entry_username varchar(100) NOT NULL,
			entry_avatar varchar(100) NOT NULL,
			entry_content varchar(250) NOT NULL,
			entry_content_eu varchar(250) NOT NULL,
			entry_content_en varchar(250) NOT NULL,
			entry_category int(11) NOT NULL DEFAULT '0'
	 	   ) {$charset_collate};";

		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
		dbDelta($sql);
	}

	// Create table phrases
	$table_name = $wpdb->prefix . "iron_tunnels_phrases";

	if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {

		$sql[] = "CREATE TABLE {$table_name} (
	  		id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
	  		phrase_category int(11) NOT NULL DEFAULT '0',
			phrase_content varchar(250) NOT NULL,
			phrase_content_eu varchar(250) NOT NULL,
			phrase_content_en varchar(250) NOT NULL
	 	   ) {$charset_collate};";

		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
		dbDelta($sql);
	}

	// Create table relations
	$table_name = $wpdb->prefix . "iron_tunnels_relations";

	if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {

		$sql[] = "CREATE TABLE {$table_name} (
	  		id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
			tag_id bigint(20) NOT NULL,
			entry_id bigint(20) NOT NULL,
			KEY tag_id (tag_id),
	 	    KEY entry_id (entry_id)
	 	   ) {$charset_collate};";

		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
		dbDelta($sql);
	}

	// Default options
	$iron_tunnels_maintext = "Escribe aqu&iacute; el Texto Principal.";
	$iron_tunnels_maintext_eu = "Escribe aqu&iacute; el Texto Principal.";
	$iron_tunnels_maintext_en = "Escribe aqu&iacute; el Texto Principal.";
	$iron_tunnels_top_slogan = "Escribe aqu&iacute; el Slogan Superior.";
    $iron_tunnels_top_slogan_eu = "Escribe aqu&iacute; el Slogan Superior.";
    $iron_tunnels_top_slogan_en = "Escribe aqu&iacute; el Slogan Superior.";
	$iron_tunnels_slogan = "Escribe aqu&iacute; el Slogan.";
	$iron_tunnels_slogan_eu = "Escribe aqu&iacute; el Slogan.";
	$iron_tunnels_slogan_en = "Escribe aqu&iacute; el Slogan.";
	$iron_tunnels_register_text = "Escribe aqu&iacute; tu texto de registro";
	$iron_tunnels_register_text_eu = "Escribe aqu&iacute; tu texto de registro";
	$iron_tunnels_register_text_en = "Escribe aqu&iacute; tu texto de registro";
	$iron_tunnels_register_addtext = "Escribe aqu&iacute; tu texto de registro adicional.";
	$iron_tunnels_register_addtext_eu = "Escribe aqu&iacute; tu texto de registro adicional.";
	$iron_tunnels_register_addtext_en = "Escribe aqu&iacute; tu texto de registro adicional.";

	// add default options to wp_options
	add_option("iron_tunnels_db_version", $iron_tunnels_db_version);
	add_option("iron_tunnels_top_slogan", $iron_tunnels_top_slogan);
	add_option("iron_tunnels_top_slogan_eu", $iron_tunnels_top_slogan_eu);
	add_option("iron_tunnels_top_slogan_en", $iron_tunnels_top_slogan_en);
	add_option("iron_tunnels_slogan", $iron_tunnels_slogan);
    add_option("iron_tunnels_slogan_eu", $iron_tunnels_slogan_eu);
    add_option("iron_tunnels_slogan_en", $iron_tunnels_slogan_en);
	add_option("iron_tunnels_maintext", $iron_tunnels_maintext);
	add_option("iron_tunnels_maintext_eu", $iron_tunnels_maintext_eu);
	add_option("iron_tunnels_maintext_en", $iron_tunnels_maintext_en);
	add_option("iron_tunnels_register_text", $iron_tunnels_register_text);
	add_option("iron_tunnels_register_text_eu", $iron_tunnels_register_text_eu);
	add_option("iron_tunnels_register_text_en", $iron_tunnels_register_text_en);
	add_option("iron_tunnels_register_addtext", $iron_tunnels_register_addtext);
	add_option("iron_tunnels_register_addtext_eu", $iron_tunnels_register_addtext_eu);
	add_option("iron_tunnels_register_addtext_en", $iron_tunnels_register_addtext_en);
}

/*
Uninstall of the DB tables
*/
function iron_tunnels_uninstall_db () {
	global $wpdb;

	// delete options from wp_options
	delete_option("iron_tunnels_db_version");
	delete_option("iron_tunnels_slogan");
	delete_option("iron_tunnels_slogan_eu");
	delete_option("iron_tunnels_slogan_en");
	delete_option("iron_tunnels_top_slogan");
    delete_option("iron_tunnels_top_slogan_eu");
    delete_option("iron_tunnels_top_slogan_en");
	delete_option("iron_tunnels_maintext");
	delete_option("iron_tunnels_maintext_eu");
	delete_option("iron_tunnels_maintext_en");
	delete_option("iron_tunnels_register_text");
	delete_option("iron_tunnels_register_text_eu");
	delete_option("iron_tunnels_register_text_en");
	delete_option("iron_tunnels_register_addtext");
	delete_option("iron_tunnels_register_addtext_eu");
	delete_option("iron_tunnels_register_addtext_en");
}

/*
Administration Menu
*/
function iron_tunnels_create_menu() {

	//create new top-level menu
	add_menu_page('Iron Tunnels', 'Iron Tunnels', 'manage_options', 'my-top-level-handle', 'iron_tunnels_front_page', plugins_url('images/irontec.gif', __FILE__));
	add_submenu_page( 'my-top-level-handle', 'Main Settings', 'Main Settings', 'manage_options', 'my-submenu-handle2', 'iron_tunnels_settings_page');

	//call register settings function
	add_action( 'admin_init', 'iron_tunnels_settings' );
}

/*
Administration Settings page options
*/
function iron_tunnels_settings() {
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_slogan' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_slogan_eu' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_slogan_en' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_top_slogan' );
    register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_top_slogan_eu' );
    register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_top_slogan_en' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_maintext' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_maintext_eu' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_maintext_en' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_register_text' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_register_text_eu' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_register_text_en' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_register_addtext' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_register_addtext_eu' );
	register_setting( 'iron-tunnels-settings-group', 'iron_tunnels_register_addtext_en' );
}

/*
Administration Settings page
*/
function iron_tunnels_settings_page() {
?>
<div class="admindiv wrap">
<img style="float: left; margin: 13px;" src="<?php echo IRON_TUNNELS_URL; ?>/images/logo_irontec_2.0.png" />
<h2>Iron Tunnels Settings Page</h2>

<div class="ironclear"></div>

<div id="iron-tunnels">
	<form method="post" action="options.php">
		<fieldset>
		<legend><b>&nbsp;Global Settings&nbsp;</b></legend>
		<?php settings_fields( 'iron-tunnels-settings-group' ); ?>
		<div class="ironclear"></div>

		<table class="form-table">
		    <tr valign="top">
                <td class="iron-td" style="width: 100px;"><b>Top Slogan</b></td>
                <td style="width: 140px;">
                <input type="text" name="iron_tunnels_top_slogan" value="<?php if (get_option('iron_tunnels_top_slogan')) echo get_option('iron_tunnels_top_slogan'); ?>" maxlength="200" style="width: 350px;">
                </td>
            </tr>
            <tr valign="top">
                <td class="iron-td" style="width: 100px;"><b>Top Slogan (EUS)</b></td>
                <td style="width: 140px;">
                <input type="text" name="iron_tunnels_top_slogan_eu" value="<?php if (get_option('iron_tunnels_top_slogan_eu')) echo get_option('iron_tunnels_top_slogan_eu'); ?>" maxlength="200" style="width: 350px;">
                </td>
            </tr>
            <tr valign="top">
                <td class="iron-td" style="width: 100px;"><b>Top Slogan (EN)</b></td>
                <td style="width: 140px;">
                <input type="text" name="iron_tunnels_top_slogan_en" value="<?php if (get_option('iron_tunnels_top_slogan_en')) echo get_option('iron_tunnels_top_slogan_en'); ?>" maxlength="200" style="width: 350px;">
                </td>
            </tr>
	        <tr valign="top">
		        <td class="iron-td" style="width: 100px;"><b>Slogan</b></td>
		        <td style="width: 140px;">
		        <input type="text" name="iron_tunnels_slogan" value="<?php if (get_option('iron_tunnels_slogan')) echo get_option('iron_tunnels_slogan'); ?>" maxlength="200" style="width: 350px;">
		        </td>
	        </tr>
	        <tr valign="top">
		        <td class="iron-td" style="width: 100px;"><b>Texto</b></td>
		        <td>
		        <textarea name="iron_tunnels_maintext" style="width: 400px; height: 60px;"><?php if (get_option('iron_tunnels_maintext')) echo get_option('iron_tunnels_maintext'); ?></textarea>
		        </td>
	        </tr>
	        <tr valign="top">
		        <td class="iron-td" style="width: 100px;"><b>Slogan (EUS)</b></td>
		        <td style="width: 140px;">
		        <input type="text" name=iron_tunnels_slogan_eu value="<?php if (get_option('iron_tunnels_slogan_eu')) echo get_option('iron_tunnels_slogan_eu'); ?>" maxlength="200" style="width: 350px;">
		        </td>
	        </tr>
	        <tr valign="top">
		        <td class="iron-td" style="width: 100px;"><b>Texto (EUS)</b></td>
		        <td>
		        <textarea name="iron_tunnels_maintext_eu" style="width: 400px; height: 60px;"><?php if (get_option('iron_tunnels_maintext_eu')) echo get_option('iron_tunnels_maintext_eu'); ?></textarea>
		        </td>
	        </tr>
	        <tr valign="top">
                <td class="iron-td" style="width: 100px;"><b>Texto (EN)</b></td>
                <td>
                <textarea name="iron_tunnels_maintext_en" style="width: 400px; height: 60px;"><?php if (get_option('iron_tunnels_maintext_en')) echo get_option('iron_tunnels_maintext_en'); ?></textarea>
                </td>
            </tr>
	        <tr valign="top">
		        <td class="iron-td" style="width: 100px;"><b>Texto Registro</b></td>
		        <td style="width: 140px;">
		        <textarea name="iron_tunnels_register_text" style="width: 400px; height: 60px;"><?php if (get_option('iron_tunnels_register_text')) echo get_option('iron_tunnels_register_text'); ?></textarea>
		        </td>
	        </tr>
	        <tr valign="top">
		        <td class="iron-td" style="width: 100px;"><b>Texto Registro (EUS)</b></td>
		        <td style="width: 140px;">
		        <textarea name="iron_tunnels_register_text_eu" style="width: 400px; height: 60px;"><?php if (get_option('iron_tunnels_register_text_eu')) echo get_option('iron_tunnels_register_text_eu'); ?></textarea>
		        </td>
	        </tr>
	        <tr valign="top">
                <td class="iron-td" style="width: 100px;"><b>Texto Registro (EN)</b></td>
                <td style="width: 140px;">
                <textarea name="iron_tunnels_register_text_en" style="width: 400px; height: 60px;"><?php if (get_option('iron_tunnels_register_text_en')) echo get_option('iron_tunnels_register_text_en'); ?></textarea>
                </td>
            </tr>
	        <tr valign="top">
		        <td class="iron-td" style="width: 100px;"><b>Texto Registro Add.</b></td>
		        <td style="width: 140px;">
		        <textarea name="iron_tunnels_register_addtext" style="width: 400px; height: 60px;"><?php if (get_option('iron_tunnels_register_addtext')) echo get_option('iron_tunnels_register_addtext'); ?></textarea>
		        </td>
	        </tr>
	        <tr valign="top">
		        <td class="iron-td" style="width: 100px;"><b>Texto Registro Add. (EUS)</b></td>
		        <td style="width: 140px;">
		        <textarea name="iron_tunnels_register_addtext_eu" style="width: 400px; height: 60px;"><?php if (get_option('iron_tunnels_register_addtext_eu')) echo get_option('iron_tunnels_register_addtext_eu'); ?></textarea>
		        </td>
	        </tr>
	        <tr valign="top">
                <td class="iron-td" style="width: 100px;"><b>Texto Registro Add. (EN)</b></td>
                <td style="width: 140px;">
                <textarea name="iron_tunnels_register_addtext_en" style="width: 400px; height: 60px;"><?php if (get_option('iron_tunnels_register_addtext_en')) echo get_option('iron_tunnels_register_addtext_en'); ?></textarea>
                </td>
            </tr>

		</table>

	    <p class="submit">
	    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
	    </p>

	    </fieldset>

	    <fieldset>
	    	<legend><b>&nbsp;Usage in your theme&nbsp;</b></legend>

	    	<div class="ironclear"></div>

			<ul>
				<li>
				&lt;?php iron_tunnels_display($cat_id); ?&gt;<br />
				&lt;?php $data=iron_tunnels_get_category_data($cat->term_id); ?&gt;<br />
				&lt;?php $data=iron_tunnels_get_category_phrases($cat->term_id); ?&gt;<br />
				&lt;?php iron_tunnels_display_tagcloud($cat_id); ?&gt;<br />
				&lt;?php iron_tunnels_display_top_slogan(); ?&gt;<br />
				&lt;?php iron_tunnels_display_slogan(); ?&gt;<br />
				&lt;?php iron_tunnels_display_maintext(); ?&gt;<br />
				&lt;?php iron_tunnels_display_register_text(); ?&gt;<br />
				&lt;?php iron_tunnels_display_register_addtext(); ?&gt;
				</li>
			</ul>

		</fieldset>
		<input type="hidden" name="page" value="my-submenu-handle2">
	</form>
</div>

</div>
<?php }

/*
Administration Front page
*/
function iron_tunnels_front_page() {
		
	wp_register_script('my-upload', IRON_TUNNELS_URL.'/tunnels.js', array('jquery','media-upload','thickbox'));
	wp_enqueue_script('my-upload');
	wp_print_scripts('my-upload');
	
	wp_enqueue_script('media-upload');
	wp_enqueue_script('thickbox');
	wp_enqueue_style('thickbox');
	wp_print_styles('thickbox');		
	
	// Styles
	wp_deregister_style('iron-tunnels-css');
	wp_enqueue_style('iron-tunnels-css', IRON_TUNNELS_URL.'/css/style.css');
	wp_print_styles('iron-tunnels-css');

	// TABBER
	wp_deregister_script( 'tabber' );
	wp_register_script( 'tabber', get_stylesheet_directory_uri() .'/_inc/tabber/tabber.js' );
	wp_print_scripts( 'tabber' );
	wp_deregister_style('tabber-css');
	wp_enqueue_style('tabber-css', get_stylesheet_directory_uri() . '/_inc/tabber/tabber.css');
	wp_print_styles('tabber-css');

	// Limpiamos variables
	$act=trim(substr(strip_tags($_GET['act']),0,10));
	$_GET['type']=trim(substr(strip_tags($_GET['type']),0,20));
	$_GET['id']=trim(substr(strip_tags($_GET['id']),0,5));
	$_POST['conf']=trim(substr(strip_tags($_POST['conf']),0,5));

	if ($_GET['type']=="entry") $cur_item="Entradas";
	elseif ($_GET['type']=="tag") $cur_item="Etiquetas";
	elseif ($_GET['type']=="cat") $cur_item="Categor&iacute;as";
	elseif ($_GET['type']=="phrase") $cur_item="Frases";
	$cur_menu="my-top-level-handle";
	?>
	<div class="ratingadmindiv wrap">
	<img style="float: left; margin: 13px;" src="<?php echo IRON_TUNNELS_URL; ?>/images/logo_irontec_2.0.png" />
	<h2>Iron Tunnels Front Page</h2>	

		<?php
		global $wpdb;

		// action delete
		if ($act=="delete" && $_GET['type'] && $_GET['id']) {

			if ($_GET['type']=="entry") $table_name = $wpdb->prefix . "iron_tunnels_entries";
			elseif ($_GET['type']=="cat") $table_name = $wpdb->prefix . "iron_tunnels_categories";
			elseif ($_GET['type']=="tag") $table_name = $wpdb->prefix . "iron_tunnels_tags";
			elseif ($_GET['type']=="phrase") $table_name = $wpdb->prefix . "iron_tunnels_phrases";
			$page=trim(substr(strip_tags($_GET['page']),0,100));
			$id=trim(substr(strip_tags($_GET['id']),0,3));

			$wpdb->query("DELETE FROM ".$table_name." WHERE id=".$id);
			echo 'Registro eliminado.';
		}
		// action edit
		elseif ($act=="edit") {

			// Insert
			if ($_POST['conf'] == "true") {

				// Entradas
				if ($_POST['type']=="entry") {
					// Limpieza de variables
					$UserName=trim(substr(strip_tags($_POST['UserName']),0,100));
					$EntryCategory=trim(substr(strip_tags($_POST['EntryCategory']),0,2));
					$EntryContent=trim(substr(strip_tags($_POST['EntryContent']),0,250));
					$EntryContentEu=trim(substr(strip_tags($_POST['EntryContentEu']),0,250));
					$EntryContentEn=trim(substr(strip_tags($_POST['EntryContentEn']),0,250));
					$UserAvatar=trim(substr(strip_tags($_POST['UserAvatar']),0,250));
					$Etiquetas=$_POST['Etiquetas'];

					// GUARDAMOS EN LA BBDD
					$table_name = $wpdb->prefix . "iron_tunnels_entries";
					$wpdb->query('UPDATE '.$table_name.' SET entry_username="'.$UserName.'", entry_avatar="'.$UserAvatar.'", entry_content="'.$EntryContent.'", entry_content_eu="'.$EntryContentEu.'", entry_content_en="'.$EntryContentEn.'", entry_category="'.$EntryCategory.'" WHERE id='.$_POST['id']);
					
					// BORRAMOS LAS RELACIONES tags/entries
					$table_name = $wpdb->prefix . "iron_tunnels_relations";
                    $wpdb->query('DELETE FROM '.$table_name.' WHERE entry_id='.$_POST['id']);
                    
                    // GUARDAMOS LAS RELACIONES tags/entries    
					foreach ($Etiquetas as $Eti) {                        
                        $wpdb->query('INSERT INTO '.$table_name.' (tag_id, entry_id) VALUES ('.$Eti.', '.$_POST['id'].')');
					}					

					echo "<script> alert (\"Entrada modificada.\"); </script>";

				}
				// Etiquetas
				if ($_GET['type']=="tag") {
					// Limpieza de variables
					$Nombre=trim(substr(strip_tags($_POST['Nombre']),0,100));
					$Descripcion=trim(substr(strip_tags($_POST['Descripcion']),0,250));
					$NombreEu=trim(substr(strip_tags($_POST['NombreEu']),0,100));
					$DescripcionEu=trim(substr(strip_tags($_POST['DescripcionEu']),0,250));
					$NombreEn=trim(substr(strip_tags($_POST['NombreEn']),0,100));
                    $DescripcionEn=trim(substr(strip_tags($_POST['DescripcionEn']),0,250));

					// GUARDAMOS EN LA BBDD					
					$table_name = $wpdb->prefix . "iron_tunnels_tags";					
					$wpdb->query('UPDATE '.$table_name.' SET tag_name="'.$Nombre.'", tag_description="'.$Descripcion.'", tag_name_eu="'.$NombreEu.'", tag_description_eu="'.$DescripcionEu.'", tag_name_en="'.$NombreEn.'", tag_description_en="'.$DescripcionEn.'" WHERE id='.$_POST['id']);

					echo "<script> alert (\"Etiqueta modificada.\"); </script>";
					
				}
				// Frases
				if ($_GET['type']=="phrase") {
					// Limpieza de variables
					$Frase = $_POST['Frase'];
					$FraseEu = $_POST['FraseEu'];
					$FraseEn = $_POST['FraseEn'];
					$EntryCategory=trim(substr(strip_tags($_POST['EntryCategory']),0,2));

					// GUARDAMOS EN LA BBDD
					// Check exists
					$table_name = $wpdb->prefix . "iron_tunnels_phrases";					
					$wpdb->query('UPDATE '.$table_name.' SET phrase_category="'.$EntryCategory.'", phrase_content="'.$Frase.'", phrase_content_eu="'.$FraseEu.'", phrase_content_en="'.$FraseEn.'" WHERE id='.$_POST['id']);

					echo "<script> alert (\"Frase modificada.\"); </script>";
					
				}
				// Categorias
				if ($_GET['type']=="cat") {
					// Limpieza de variables
					$Imagen1=trim(substr(strip_tags($_POST['Imagen1']),0,100));
					$Imagen2=trim(substr(strip_tags($_POST['Imagen2']),0,100));
					$Imagen3=trim(substr(strip_tags($_POST['Imagen3']),0,100));
					$Imagen4=trim(substr(strip_tags($_POST['Imagen4']),0,100));
					$Orden=trim(substr(strip_tags($_POST['Orden']),0,2));
					$EntryCategory=trim(substr(strip_tags($_POST['EntryCategory']),0,2));
					$BgAtt=trim(substr(strip_tags($_POST['BgAtt']),0,200));
					$CategoryPhrase=trim(substr(strip_tags($_POST['CategoryPhrase']),0,200));
					$CategoryPhraseEu=trim(substr(strip_tags($_POST['CategoryPhraseEu']),0,200));
					$CategoryPhraseEn=trim(substr(strip_tags($_POST['CategoryPhraseEn']),0,200));
					$CategoryNameEu=trim(substr(strip_tags($_POST['CategoryNameEu']),0,100));
					$CategoryNameEn=trim(substr(strip_tags($_POST['CategoryNameEn']),0,100));                    

					// GUARDAMOS EN LA BBDD
					$table_name = $wpdb->prefix . "iron_tunnels_categories";
					$wpdb->query('UPDATE '.$table_name.' SET category_id="'.$EntryCategory.'", 
					category_order="'.$Orden.'", category_phrase="'.$CategoryPhrase.'", 
					category_name_eu="'.$CategoryNameEu.'", category_name_en="'.$CategoryNameEn.'",
					category_phrase_eu="'.$CategoryPhraseEu.'", category_phrase_en="'.$CategoryPhraseEn.'", 
					image1="'.$Imagen1.'", image2="'.$Imagen2.'", image3="'.$Imagen3.'", image4="'.$Imagen4.'", 
					bg_att="'.$BgAtt.'" WHERE id='.$_POST['id']); 
											
					echo "<script> alert (\"Categoria modificada.\"); </script>";					
				}
			}
			?>

			<div id="iron-tunnels">
				<fieldset>
				<legend><b>&nbsp;<?php echo $cur_item; ?></b>&nbsp;<i>(Modificando)</i>&nbsp;&middot;&nbsp;<a href="?page=<?php echo $cur_menu; ?>&type=<?php echo $_GET['type']; ?>">Volver</a>&nbsp;</legend>				

				<form id="iron-tunnels-form" method="post" action="">

				<?php
				if ($_GET['type']=="entry") {
					$table_name = $wpdb->prefix . "iron_tunnels_entries";
					$row = $wpdb->get_results( "SELECT * FROM ".$table_name."
					WHERE id=".$_GET['id']);
					?>
				    <table class="form-table">
				    	</tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Categor&iacute;a</b></td>
				        <td colspan="5">
				        <select name="EntryCategory" style="width: 150px;">
				        	<?php
				        	$cats=get_categories(array('hide_empty' => 0, 'parent' => 1));
							foreach ($cats as $cat) {
								if ($cat->term_id == $row[0]->entry_category)
									echo '<option value="'.$cat->term_id.'" selected>'. $cat->name . '</option>';
								else
									echo '<option value="'.$cat->term_id.'">'. $cat->name . '</option>';	
							}
				        	?>
				        </select>
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Usuario</b></td>
				        <td style="width: 140px;">
				        <input type="text" name="UserName" value="<?php echo $row[0]->entry_username; ?>" maxlength="100" style="width: 150px;">				        
				        </td>
				        <td class="iron-td" style="width: 50px;"><b>Imagen</b></td>
				        <td>
				        <input id="upload_image_1" type="text" name="UserAvatar" maxlength="200" style="width: 250px; font-size: 9px;" value="<?php echo $row[0]->entry_avatar; ?>" />
						<input id="upload_image_button_1" type="button" value="Choose Image" />
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Contenido</b></td>
				        <td colspan="5">
				        <textarea name="EntryContent" style="width: 400px; height: 60px;"><?php echo $row[0]->entry_content; ?></textarea>
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Contenido (EUS)</b></td>
				        <td colspan="5">
				        <textarea name="EntryContentEu" style="width: 400px; height: 60px;"><?php echo $row[0]->entry_content_eu; ?></textarea>
				        </td>
				        </tr>
				        </tr>
                        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Contenido (EN)</b></td>
                        <td colspan="5">
                        <textarea name="EntryContentEn" style="width: 400px; height: 60px;"><?php echo $row[0]->entry_content_en; ?></textarea>
                        </td>
                        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Etiquetas</b></td>
				        <td>
				        
				        <select multiple name="Etiquetas[]" style="width: 200px; height: 80px;">
				        	<?php
				        	
				        	
				        	$table_name = $wpdb->prefix . "iron_tunnels_tags";
				        	$result_total[] = $wpdb->get_results(
							"SELECT DISTINCT id, tag_name FROM ".$table_name." ORDER BY tag_name");

							foreach ($result_total[0] as $item_tag) {                                
                                $table_name = $wpdb->prefix . "iron_tunnels_relations";
                                $tagsel = $wpdb->get_results(
                                "SELECT * FROM ".$table_name." WHERE tag_id=".$item_tag->id." AND entry_id=".$row[0]->id);                                                                
                                var_dump($tagsel);
                                if ($tagsel[0]->tag_id == $item_tag->id)
								    echo '<option selected value="'.$item_tag->id.'">'. $item_tag->tag_name . '</option>';
                                else
                                    echo '<option value="'.$item_tag->id.'">'. $item_tag->tag_name . '</option>';
							}
				        	?>
				        </select>
				        </td>
				        </tr>

					</table>
					<?php }
				elseif ($_GET['type']=="tag") {
					$table_name = $wpdb->prefix . "iron_tunnels_tags";
					$row = $wpdb->get_results( "SELECT * FROM ".$table_name."
					WHERE id=".$_GET['id']);
					?>
					<table class="form-table">
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Nombre</b></td>
				        <td style="width: 160px;">
				        <input type="text" name="Nombre" value="<?php echo $row[0]->tag_name; ?>" maxlength="100" style="width: 150px;">
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Descripci&oacute;n</b></td>
				        <td>
				        <textarea name="Descripcion" style="width: 400px; height: 60px;"><?php echo $row[0]->tag_description; ?></textarea>
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Nombre (EUS)</b></td>
				        <td style="width: 160px;">
				        <input type="text" name="NombreEu" value="<?php echo $row[0]->tag_name_eu; ?>" maxlength="100" style="width: 150px;">
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Descripci&oacute;n (EUS)</b></td>
				        <td>
				        <textarea name="DescripcionEu" style="width: 400px; height: 60px;"><?php echo $row[0]->tag_description_eu; ?></textarea>
				        </td>
				        </tr>
				        </tr>
                        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Nombre (EN)</b></td>
                        <td style="width: 160px;">
                        <input type="text" name="NombreEn" value="<?php echo $row[0]->tag_name_en; ?>" maxlength="100" style="width: 150px;">
                        </td>
                        </tr>
                        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Descripci&oacute;n (EN)</b></td>
                        <td>
                        <textarea name="DescripcionEn" style="width: 400px; height: 60px;"><?php echo $row[0]->tag_description_en; ?></textarea>
                        </td>
                        </tr>
					</table>
				<?php }
			elseif ($_GET['type']=="phrase") {
					$table_name = $wpdb->prefix . "iron_tunnels_phrases";
					$row = $wpdb->get_results( "SELECT * FROM ".$table_name."
					WHERE id=".$_GET['id']);
					?>
					<table class="form-table">
						<tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Categor&iacute;a</b></td>
				        <td>
				        <select name="EntryCategory" style="width: 150px;">
				        	<?php
				        	$cats=get_categories(array('hide_empty' => 0, 'parent' => 1));
							foreach ($cats as $cat) {
								if ($row[0]->phrase_category == $cat->term_id)
									echo '<option value="'.$cat->term_id.'" selected>'. $cat->name . '</option>';
								else
									echo '<option value="'.$cat->term_id.'">'. $cat->name . '</option>';	
							}
				        	?>
				        </select>
				        </td>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Frase</b></td>
				        <td>
				        <textarea name="Frase" style="width: 400px; height: 60px;"><?php echo $row[0]->phrase_content; ?></textarea>
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Frase (EUS)</b></td>
				        <td>
				        <textarea name="FraseEu" style="width: 400px; height: 60px;"><?php echo $row[0]->phrase_content_eu; ?></textarea>
				        </td>
				        </tr>
				        </tr>
                        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Frase (EN)</b></td>
                        <td>
                        <textarea name="FraseEn" style="width: 400px; height: 60px;"><?php echo $row[0]->phrase_content_en; ?></textarea>
                        </td>
                        </tr>
					</table>
				<?php }
			elseif ($_GET['type']=="cat") {
					$table_name = $wpdb->prefix . "iron_tunnels_categories";
					$row = $wpdb->get_results( "SELECT * FROM ".$table_name."
					WHERE id=".$_GET['id']);
					?>
					<table class="form-table">
					<tr valign="top">
						<td class="iron-td" style="width: 100px;"><b>Categor&iacute;a</b></td>
				        <td>
				        <select name="EntryCategory" style="width: 150px;">
				        	<?php
				        	$cats=get_categories(array('hide_empty' => 0, 'parent' => 1));
							foreach ($cats as $cat) {
								if ($row[0]->category_id == $cat->term_id)
									echo '<option value="'.$cat->term_id.'" selected>'. $cat->name . '</option>';
								else	
									echo '<option value="'.$cat->term_id.'">'. $cat->name . '</option>';
							}
				        	?>
				        </select>
				        </td>
						</tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Orden</b></td>
				        <td>
				        <input type="text" name="Orden" value="<?php echo $row[0]->category_order; ?>" maxlength="2" style="width: 40px;">
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Imagen 1</b></td>
				        <td>
				        <input id="upload_image_1" type="text" name="Imagen1" maxlength="200" style="width: 250px; font-size: 9px;" value="<?php echo $row[0]->image1; ?>" />
						<input id="upload_image_button_1" type="button" value="Choose Image" /><br />
						<img src="<?php echo $row[0]->image1; ?>" height="40" />
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Imagen 2</b></td>
				        <td>
				        <input id="upload_image_2" type="text" name="Imagen2" maxlength="200" style="width: 250px; font-size: 9px;" value="<?php echo $row[0]->image2; ?>" />
						<input id="upload_image_button_2" type="button" value="Choose Image" /><br />
						<img src="<?php echo $row[0]->image2; ?>" height="40" />
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Imagen 3</b></td>
				        <td>
				        <input id="upload_image_3" type="text" name="Imagen3" maxlength="200" style="width: 250px; font-size: 9px;" value="<?php echo $row[0]->image3; ?>" />
						<input id="upload_image_button_3" type="button" value="Choose Image" /><br />
						<img src="<?php echo $row[0]->image3; ?>" height="40" />
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Imagen 4</b></td>
				        <td>
				        <input id="upload_image_4" type="text" name="Imagen4" maxlength="200" style="width: 250px; font-size: 9px;" value="<?php echo $row[0]->image4; ?>" />
						<input id="upload_image_button_4" type="button" value="Choose Image" /><br />
						<img src="<?php echo $row[0]->image4; ?>" height="40" />
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>BG Att.</b></td>
				        <td>
				        <input type="text" name="BgAtt" value="<?php echo $row[0]->bg_att; ?>" maxlength="100" style="width: 200px;">
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Cat (EUS)</b></td>
				        <td>
				        <input type="text" name="CategoryNameEu" value="<?php echo $row[0]->category_name_eu; ?>" maxlength="100" style="width: 150px;">
				        </td>
				        </tr>
				        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Cat (EN)</b></td>
                        <td>
                        <input type="text" name="CategoryNameEn" value="<?php echo $row[0]->category_name_en; ?>" maxlength="100" style="width: 150px;">
                        </td>
                        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Frase</b></td>
				        <td>
				        <input type="text" name="CategoryPhrase" value="<?php echo $row[0]->category_phrase; ?>" maxlength="100" style="width: 150px;">
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Frase (EUS)</b></td>
				        <td>
				        <input type="text" name="CategoryPhraseEu" value="<?php echo $row[0]->category_phrase_eu; ?>" maxlength="100" style="width: 150px;">
				        </td>
				        </tr>
				        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Frase (EN)</b></td>
                        <td>
                        <input type="text" name="CategoryPhraseEn" value="<?php echo $row[0]->category_phrase_en; ?>" maxlength="100" style="width: 150px;">
                        </td>
                        </tr>
					</table>

				<?php }
				?>

				<p class="submit">
				<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
				<input type="hidden" name="act" value="edit">
				<input type="hidden" name="conf" value="true">
				<input type="hidden" name="type" value="<?php echo $_GET['type']; ?>">
				<input type="hidden" name="page" value="<?php echo $cur_menu; ?>">
    			<input type="submit" class="button-primary" value="<?php _e('Guardar') ?>" />
    			</p>

    			</form>

				</fieldset>
			</div>
		<?php }
		// action add
		elseif ($act=="add") {

			// Insert
			if ($_POST['conf'] == "true") {

				// Entradas
				if ($_GET['type']=="entry") {
					// Limpieza de variables
					$UserName=trim(substr(strip_tags($_POST['UserName']),0,100));
					$EntryCategory=trim(substr(strip_tags($_POST['EntryCategory']),0,2));
					$EntryContent=trim(substr(strip_tags($_POST['EntryContent']),0,250));
					$EntryContentEu=trim(substr(strip_tags($_POST['EntryContentEu']),0,250));
					$EntryContentEn=trim(substr(strip_tags($_POST['EntryContentEn']),0,250));
					$UserAvatar=trim(substr(strip_tags($_POST['UserAvatar']),0,250));

					// GUARDAMOS EN LA BBDD
					// Check exists
					$table_name = $wpdb->prefix . "iron_tunnels_entries";
					$exists = $wpdb->get_results( "SELECT (id) AS itemid FROM ".$table_name."
					WHERE entry_content LIKE '".$EntryContent."'");

					// Db Insert
					if ($exists[0]->itemid == 0) {
						$wpdb->query('INSERT INTO '.$table_name.' (entry_username, entry_avatar, entry_content, entry_content_eu, entry_content_en, entry_category ) VALUES ("'.$UserName.'", "'.$UserAvatar.'", "'.$EntryContent.'", "'.$EntryContentEu.'", "'.$EntryContentEn.'", "'.$EntryCategory.'")');

						$new_id=$wpdb->insert_id;
						$table_name = $wpdb->prefix . "iron_tunnels_relations";
						foreach ( $_POST['Etiquetas'] as $etiqueta) {
							$wpdb->query('INSERT INTO '.$table_name.' (tag_id, entry_id) VALUES ("'.$etiqueta.'", "'.$new_id.'")');
						}

						echo "<script> alert (\"Entrada insertada.\"); </script>";

					}
					else
						echo "<script> alert (\"Ya existe una entrada con ese nombre !.\"); </script>";
				}
				// Etiquetas
				if ($_GET['type']=="tag") {
					// Limpieza de variables
					$Nombre=trim(substr(strip_tags($_POST['Nombre']),0,100));
					$Descripcion=trim(substr(strip_tags($_POST['Descripcion']),0,250));
					$NombreEu=trim(substr(strip_tags($_POST['NombreEu']),0,100));
					$DescripcionEu=trim(substr(strip_tags($_POST['DescripcionEu']),0,250));
					$NombreEn=trim(substr(strip_tags($_POST['NombreEn']),0,100));
                    $DescripcionEn=trim(substr(strip_tags($_POST['DescripcionEn']),0,250));

					// GUARDAMOS EN LA BBDD
					// Check exists
					$table_name = $wpdb->prefix . "iron_tunnels_tags";
					$exists = $wpdb->get_results( "SELECT (id) AS itemid FROM ".$table_name."
					WHERE entry_name LIKE '".$Nombre."'");

					// Db Insert
					if ($exists[0]->itemid == 0) {
						$wpdb->query('INSERT INTO '.$table_name.' (tag_name, tag_description, tag_name_eu, tag_description_eu, tag_name_en, tag_description_en) VALUES ("'.$Nombre.'", "'.$Descripcion.'", "'.$NombreEu.'", "'.$DescripcionEu.'", "'.$NombreEn.'", "'.$DescripcionEn.'")');
						echo "<script> alert (\"Etiqueta insertada.\"); </script>";
					}
					else
						echo "<script> alert (\"Ya existe una etiqueta con ese nombre !.\"); </script>";
				}
				// Frases
				if ($_GET['type']=="phrase") {
					// Limpieza de variables
					$Frase = $_POST['Frase'];
					$FraseEu = $_POST['FraseEu'];
					$FraseEn = $_POST['FraseEn'];
					$EntryCategory=trim(substr(strip_tags($_POST['EntryCategory']),0,2));

					// GUARDAMOS EN LA BBDD
					// Check exists
					$table_name = $wpdb->prefix . "iron_tunnels_phrases";
					$exists = $wpdb->get_results( "SELECT (id) AS itemid FROM ".$table_name."
					WHERE phrase_content LIKE '".$Frase."'");

					// Db Insert
					if ($exists[0]->itemid == 0) {
						$wpdb->query('INSERT INTO '.$table_name.' (phrase_category, phrase_content, phrase_content_eu, phrase_content_en) VALUES
						("'.$EntryCategory.'", "'.$Frase.'", "'.$FraseEu.'", "'.$FraseEn.'")');
						echo "<script> alert (\"Frase insertada.\"); </script>";
					}
					else
						echo "<script> alert (\"Ya existe una frase con ese nombre !.\"); </script>";
				}
				// Categorias
				if ($_GET['type']=="cat") {
					// Limpieza de variables
					$Imagen1=trim(substr(strip_tags($_POST['Imagen1']),0,100));
					$Imagen2=trim(substr(strip_tags($_POST['Imagen2']),0,100));
					$Imagen3=trim(substr(strip_tags($_POST['Imagen3']),0,100));
					$Imagen4=trim(substr(strip_tags($_POST['Imagen4']),0,100));
					$Orden=trim(substr(strip_tags($_POST['Orden']),0,2));
					$EntryCategory=trim(substr(strip_tags($_POST['EntryCategory']),0,2));
					$BgAtt=trim(substr(strip_tags($_POST['BgAtt']),0,200));
					$CategoryPhrase=trim(substr(strip_tags($_POST['CategoryPhrase']),0,200));
					$CategoryPhraseEu=trim(substr(strip_tags($_POST['CategoryPhraseEu']),0,200));					
					$CategoryPhraseEn=trim(substr(strip_tags($_POST['CategoryPhraseEn']),0,200));
					$CategoryNameEu=trim(substr(strip_tags($_POST['CategoryNameEu']),0,200));
                    $CategoryNameEn=trim(substr(strip_tags($_POST['CategoryNameEn']),0,200));

					// GUARDAMOS EN LA BBDD
					// Check exists
					$table_name = $wpdb->prefix . "iron_tunnels_categories";
					$exists = $wpdb->get_results( "SELECT (id) AS itemid FROM ".$table_name."
					WHERE category_id LIKE '".$EntryCategory."'");

					// Db Insert
					if ($exists[0]->itemid == 0) {
						$wpdb->query('INSERT INTO '.$table_name.' (category_id, category_order, category_name_eu, category_name_en, category_phrase, category_phrase_eu, category_phrase_en, image1, image2, image3, image4, bg_att) VALUES ("'.$EntryCategory.'", "'.$Orden.'", "'.$CategoryNameEu.'", "'.$CategoryNameEn.'", "'.$CategoryPhrase.'", "'.$CategoryPhraseEu.'", "'.$CategoryPhraseEn.'", "'.$Imagen1.'", "'.$Imagen2.'", "'.$Imagen3.'", "'.$Imagen4.'", "'.$BgAtt.'")');						
						echo "<script> alert (\"Categor&iacute;a insertada.\"); </script>";
					}
					else
						echo "<script> alert (\"Ya existe una categor&iacute;a con ese nombre !.\"); </script>";
				}
			}
			?>

			<div id="iron-tunnels">
				<fieldset>
				<legend><b>&nbsp;<?php echo $cur_item; ?></b>&nbsp;<i>(Insertando)</i>&nbsp;&middot;&nbsp;<a href="?page=<?php echo $cur_menu; ?>&type=<?php echo $_GET['type']; ?>">Volver</a>&nbsp;</legend>				

				<form id="iron-tunnels-form" method="post" action="">

				<?php
				if ($_GET['type']=="entry") { ?>
				    <table class="form-table">
				    	</tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Categor&iacute;a</b></td>
				        <td colspan="5">
				        <select name="EntryCategory" style="width: 150px;">
				        	<?php
				        	$cats=get_categories(array('hide_empty' => 0, 'parent' => 1));
							foreach ($cats as $cat) {
								echo '<option value="'.$cat->term_id.'">'. $cat->name . '</option>';
							}
				        	?>
				        </select>
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Usuario</b></td>
				        <td style="width: 140px;">
				        <input type="text" name="UserName" value="" maxlength="100" style="width: 150px;">
				        </td>
				        <td class="iron-td" style="width: 50px;"><b>Imagen</b></td>
				        <td>
				        <input id="upload_image_1" type="text" name="UserAvatar" maxlength="200" style="width: 250px; font-size: 9px;" value="" />
						<input id="upload_image_button_1" type="button" value="Choose Image" />
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Contenido</b></td>
				        <td colspan="5">
				        <textarea name="EntryContent" style="width: 400px; height: 60px;"></textarea>
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Contenido (EUS)</b></td>
				        <td colspan="5">
				        <textarea name="EntryContentEu" style="width: 400px; height: 60px;"></textarea>
				        </td>
				        </tr>
				        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Contenido (EN)</b></td>
                        <td colspan="5">
                        <textarea name="EntryContentEn" style="width: 400px; height: 60px;"></textarea>
                        </td>
                        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Etiquetas</b></td>
				        <td>
				        <select multiple name="Etiquetas[]" style="width: 200px; height: 80px;">
				        	<?php
				        	$table_name = $wpdb->prefix . "iron_tunnels_tags";
				        	$result_total[] = $wpdb->get_results(
							"SELECT DISTINCT id, tag_name FROM ".$table_name." ORDER BY tag_name");

							foreach ($result_total[0] as $item_tag) {
								echo '<option value="'.$item_tag->id.'">'. $item_tag->tag_name . '</option>';
							}
				        	?>
				        </select>
				        </td>
				        </tr>

					</table>
					<?php }
				elseif ($_GET['type']=="tag") {
					?>
					<table class="form-table">
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Nombre</b></td>
				        <td style="width: 160px;">
				        <input type="text" name="Nombre" value="" maxlength="100" style="width: 150px;">
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Descripci&oacute;n</b></td>
				        <td>
				        <textarea name="Descripcion" style="width: 400px; height: 60px;"></textarea>
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Nombre (EUS)</b></td>
				        <td style="width: 160px;">
				        <input type="text" name="NombreEu" value="" maxlength="100" style="width: 150px;">
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Descripci&oacute;n (EUS)</b></td>
				        <td>
				        <textarea name="DescripcionEu" style="width: 400px; height: 60px;"></textarea>
				        </td>
				        </tr>
				        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Nombre (EN)</b></td>
                        <td style="width: 160px;">
                        <input type="text" name="NombreEn" value="" maxlength="100" style="width: 150px;">
                        </td>
                        </tr>
                        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Descripci&oacute;n (EN)</b></td>
                        <td>
                        <textarea name="DescripcionEn" style="width: 400px; height: 60px;"></textarea>
                        </td>
                        </tr>
					</table>
				<?php }
			elseif ($_GET['type']=="phrase") {
					?>
					<table class="form-table">
						<tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Categor&iacute;a</b></td>
				        <td>
				        <select name="EntryCategory" style="width: 150px;">
				        	<?php
				        	$cats=get_categories(array('hide_empty' => 0, 'parent' => 1));
							foreach ($cats as $cat) {
								echo '<option value="'.$cat->term_id.'">'. $cat->name . '</option>';
							}
				        	?>
				        </select>
				        </td>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Frase</b></td>
				        <td>
				        <textarea name="Frase" style="width: 400px; height: 60px;"></textarea>
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Frase (EUS)</b></td>
				        <td>
				        <textarea name="FraseEu" style="width: 400px; height: 60px;"></textarea>
				        </td>
				        </tr>
				        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Frase (EN)</b></td>
                        <td>
                        <textarea name="FraseEn" style="width: 400px; height: 60px;"></textarea>
                        </td>
                        </tr>
					</table>
				<?php }
			elseif ($_GET['type']=="cat") {
					?>
					<table class="form-table">
					<tr valign="top">
						<td class="iron-td" style="width: 100px;"><b>Categor&iacute;a</b></td>
				        <td>
				        <select name="EntryCategory" style="width: 150px;">
				        	<?php
				        	$cats=get_categories(array('hide_empty' => 0, 'parent' => 1));
							foreach ($cats as $cat) {
								echo '<option value="'.$cat->term_id.'">'. $cat->name . '</option>';
							}
				        	?>
				        </select>
				        </td>
						</tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Orden</b></td>
				        <td>
				        <input type="text" name="Orden" value="" maxlength="2" style="width: 40px;">
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Imagen 1</b></td>
				        <td>
				        <input id="upload_image_1" type="text" name="Imagen1" maxlength="200" style="width: 250px; font-size: 9px;" value="" />
						<input id="upload_image_button_1" type="button" value="Choose Image" />				        
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Imagen 2</b></td>
				        <td>
				        <input id="upload_image_2" type="text" name="Imagen2" maxlength="200" style="width: 250px; font-size: 9px;" value="" />
						<input id="upload_image_button_2" type="button" value="Choose Image" />
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Imagen 3</b></td>
				        <td>
				        <input id="upload_image_3" type="text" name="Imagen3" maxlength="200" style="width: 250px; font-size: 9px;" value="" />
						<input id="upload_image_button_3" type="button" value="Choose Image" />
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Imagen 4</b></td>
				        <td>
				        <input id="upload_image_4" type="text" name="Imagen4" maxlength="200" style="width: 250px; font-size: 9px;" value="" />
						<input id="upload_image_button_4" type="button" value="Choose Image" />
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>BG Att.</b></td>
				        <td>
				        <input type="text" name="BgAtt" value="" maxlength="100" style="width: 200px;">
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Frase</b></td>
				        <td>
				        <input type="text" name="CategoryPhrase" value="" maxlength="100" style="width: 150px;">
				        </td>
				        </tr>
				        <tr valign="top">
				        <td class="iron-td" style="width: 100px;"><b>Frase (EUS)</b></td>
				        <td>
				        <input type="text" name="CategoryPhraseEu" value="" maxlength="100" style="width: 150px;">
				        </td>
				        </tr>
				        <tr valign="top">
                        <td class="iron-td" style="width: 100px;"><b>Frase (EN)</b></td>
                        <td>
                        <input type="text" name="CategoryPhraseEn" value="" maxlength="100" style="width: 150px;">
                        </td>
                        </tr>
					</table>

				<?php }
				?>

				<p class="submit">				
				<input type="hidden" name="act" value="add">
				<input type="hidden" name="conf" value="true">
				<input type="hidden" name="type" value="<?php echo $GET['type']; ?>">				
				<input type="hidden" name="page" value="<?php echo $cur_menu; ?>">
    			<input type="submit" class="button-primary" value="<?php _e('Guardar') ?>" />
    			</p>

    			</form>

				</fieldset>
			</div>
		<?php }
		else { ?>
			<div id="iron-tunnels">

				<div class="tabber">

				<div class="tabbertab <?php if ($_GET['type']=='entry') echo 'tabbertabdefault'; ?>">
				  <h2>Entradas</h2>

				&middot;&nbsp;<a href="?page=<?php echo $cur_menu; ?>&act=add&type=entry">A&ntilde;adir Entrada</a>

				<div class="ironclear"></div>

				<?php
				global $wpdb;
				$table_name = $wpdb->prefix . "iron_tunnels_entries";

				// Obtain the different item types
				$results = $wpdb->get_results(
				"SELECT * FROM ".$table_name." ORDER BY 1");

				if (sizeof($results) > 0) { ?>

					<div class="tunnels-overflow">
					<table id="iron-tunnels-table">
						<tr>
						<td class="iron-td-mini iron-header"><b>Acciones</b></td>						
						<td class="iron-td-small iron-header"><b>Categor&iacute;a</b></td>
						<td class="iron-td-small iron-header"><b>Usuario</b></td>
						<td class="iron-td-small iron-header"><b>Avatar</b></td>
						<td class="iron-td-normal iron-header"><b>Contenido</b></td>
						<td class="iron-td-normal iron-header"><b>Contenido (EUS)</b></td>
						<td class="iron-td-normal iron-header"><b>Contenido (EN)</b></td>						
						</tr>
						<?php
						foreach ($results as $item_entry) {
							?>
							<tr>
							<td class="iron-td-mini">
							<a href="?page=<?php echo $cur_menu; ?>&act=edit&type=entry&id=<?php echo $item_entry->id; ?>"><img src="<?php echo IRON_TUNNELS_URL.'/images/edit.gif'; ?>" alt="<?php _e( 'Editar', 'buddypress') ?>" title="<?php _e( 'Editar', 'buddypress') ?>"></a>
							<a href="?page=<?php echo $cur_menu; ?>&act=delete&type=entry&id=<?php echo $item_entry->id; ?>" onclick="if(!confirm('Eliminar registro ?')) {return false;}" onclick="if(!confirm(\'Eliminar registro ?\')) {return false;}"><img src="<?php echo IRON_TUNNELS_URL.'/images/delete.gif'; ?>" alt="<?php _e( 'Eliminar', 'buddypress') ?>" title="<?php _e( 'Eliminar', 'buddypress') ?>"></a>
							</td>							
							<td class="iron-td-small"><?php $catdata=get_category($item_entry->entry_category); echo $catdata->name; ?></td>
							<td class="iron-td-small"><?php echo $item_entry->entry_username; ?></td>
							<td class="iron-td-small">
							<?php
							if (!is_array(@get_headers($item_entry->entry_avatar)))
								echo "none";
							else { ?>
								<img border="0" height="32" src="<?php echo $item_entry->entry_avatar; ?>">
							<?php }
							?>
							</td>
							<td class="iron-td-normal"><?php echo $item_entry->entry_content; ?></td>
							<td class="iron-td-normal"><?php echo $item_entry->entry_content_eu; ?></td>
							<td class="iron-td-normal"><?php echo $item_entry->entry_content_en; ?></td>							
							</tr>
						<?php }
						?>
					</table>
					</div>
				<?php }
				else
					echo "No hay entradas creadas !";
				?>				
				</div>

				<div class="tabbertab <?php if ($_GET['type']=='tag') echo 'tabbertabdefault'; ?>">
				<h2>Etiquetas</h2>
					
					&middot;&nbsp;<a href="?page=<?php echo $cur_menu; ?>&act=add&type=tag">A&ntilde;adir Etiqueta</a>

					<div class="ironclear"></div>

					<?php
					global $wpdb;
					$table_name = $wpdb->prefix . "iron_tunnels_tags";

					// Obtain the different item types
					$results = $wpdb->get_results(
					"SELECT * FROM ".$table_name." ORDER BY 1");

					if (sizeof($results) > 0) { ?>
						<div class="tunnels-overflow">
						<table id="iron-tunnels-table">
							<tr>
							<td class="iron-td-mini iron-header"><b>Acciones</b></td>							
							<td class="iron-td-small iron-header"><b>Nombre</b></td>
							<td class="iron-td-small iron-header"><b>Nombre (EUS)</b></td>
							<td class="iron-td-small iron-header"><b>Nombre (EN)</b></td>
							<td class="iron-td-normal iron-header"><b>Descripci&oacute;n</b></td>
							<td class="iron-td-normal iron-header"><b>Descripci&oacute;n (EUS)</b></td>
							<td class="iron-td-normal iron-header"><b>Descripci&oacute;n (EN)</b></td>
							</tr>
							<?php
							foreach ($results as $item_tag) {
								?>
								<tr>
								<td class="iron-td-mini">
								<a href="?page=<?php echo $cur_menu; ?>&act=edit&type=tag&id=<?php echo $item_tag->id; ?>"><img src="<?php echo IRON_TUNNELS_URL.'/images/edit.gif'; ?>" alt="<?php _e( 'Editar', 'buddypress') ?>" title="<?php _e( 'Editar', 'buddypress') ?>"></a>
								<a href="?page=<?php echo $cur_menu; ?>&act=delete&type=tag&id=<?php echo $item_tag->id; ?>" onclick="if(!confirm('Eliminar registro ?')) {return false;}"><img src="<?php echo IRON_TUNNELS_URL.'/images/delete.gif'; ?>" alt="<?php _e( 'Eliminar', 'buddypress') ?>" title="<?php _e( 'Eliminar', 'buddypress') ?>"></a>
								</td>								
								<td class="iron-td-small"><?php echo $item_tag->tag_name; ?></td>
								<td class="iron-td-small"><?php echo $item_tag->tag_name_eu; ?></td>
								<td class="iron-td-small"><?php echo $item_tag->tag_name_en; ?></td>
								<td class="iron-td-normal"><?php echo $item_tag->tag_description; ?></td>
								<td class="iron-td-normal"><?php echo $item_tag->tag_description_eu; ?></td>
								<td class="iron-td-normal"><?php echo $item_tag->tag_description_en; ?></td>
								</tr>
							<?php }
							?>
						</table>
						</div>
					<?php }
					else
						echo "No hay etiquetas creadas !";
					?>					
				</div>

				<div class="tabbertab <?php if ($_GET['type']=='cat') echo 'tabbertabdefault'; ?>">
					<h2>Categor&iacute;as</h2>

					&middot;&nbsp;<a href="?page=<?php echo $cur_menu; ?>&act=add&type=cat">A&ntilde;adir Categor&iacute;a</a>

					<div class="ironclear"></div>

					<?php
					global $wpdb;
					$table_name = $wpdb->prefix . "iron_tunnels_categories";

					// Obtain the different item types
					$results = $wpdb->get_results(
					"SELECT * FROM ".$table_name." ORDER BY 1");

					if (sizeof($results) > 0) { ?>
						<div class="tunnels-overflow">
						<table id="iron-tunnels-table">
							<tr>
							<td class="iron-td-mini iron-header"><b>Acciones</b></td>							
							<td class="iron-td-mini iron-header"><b>Orden</b></td>
							<td class="iron-td-small iron-header"><b>Categor&iacute;a</b></td>
							<td class="iron-td-small iron-header"><b>Categor&iacute;a (EUS)</b></td>
							<td class="iron-td-small iron-header"><b>Categor&iacute;a (EN)</b></td>
							<td class="iron-td-normal iron-header"><b>Frase</b></td>
							<td class="iron-td-normal iron-header"><b>Frase (EUS)</b></td>
							<td class="iron-td-normal iron-header"><b>Frase (EN)</b></td>
							<td class="iron-td-normal iron-header"><b>Im&aacute;genes</b></td>
							<td class="iron-td-normal iron-header"><b>BG Att.</b></td>
							</tr>
							<?php
							foreach ($results as $item_cat) {
								?>
								<tr>
								<td class="iron-td-mini">
								<a href="?page=<?php echo $cur_menu; ?>&act=edit&type=cat&id=<?php echo $item_cat->id; ?>"><img src="<?php echo IRON_TUNNELS_URL.'/images/edit.gif'; ?>" alt="<?php _e( 'Editar', 'buddypress') ?>" title="<?php _e( 'Editar', 'buddypress') ?>"></a>
								<a href="?page=<?php echo $cur_menu; ?>&act=delete&type=cat&id=<?php echo $item_cat->id; ?>" onclick="if(!confirm('Eliminar registro ?')) {return false;}"><img src="<?php echo IRON_TUNNELS_URL.'/images/delete.gif'; ?>" alt="<?php _e( 'Eliminar', 'buddypress') ?>" title="<?php _e( 'Eliminar', 'buddypress') ?>"></a>
								</td>								
								<td class="iron-td-mini"><?php echo $item_cat->category_order; ?></td>
								<td class="iron-td-small"><?php 
								$catdata=get_category($item_cat->category_id); echo $catdata->name; 
								?></td>
								<td class="iron-td-small"><?php echo $item_cat->category_name_eu; ?></td>
								<td class="iron-td-small"><?php echo $item_cat->category_name_en; ?></td>
								<td class="iron-td-normal"><?php echo $item_cat->category_phrase; ?></td>
								<td class="iron-td-normal"><?php echo $item_cat->category_phrase_eu; ?></td>
								<td class="iron-td-normal"><?php echo $item_cat->category_phrase_en; ?></td>
								<td class="iron-td-normal">
								<?php if ($item_cat->image1) { ?>
									<img height="32" src="<?php echo $item_cat->image1; ?>">&nbsp;
								<?php } ?>
								<?php if ($item_cat->image2) { ?>
									<img height="32" src="<?php echo $item_cat->image2; ?>">&nbsp;
								<?php } ?>
								<?php if ($item_cat->image3) { ?>
									<img height="32" src="<?php echo $item_cat->image3; ?>">&nbsp;
								<?php } ?>
								<?php if ($item_cat->image4) { ?>
									<img height="32" src="<?php echo $item_cat->image4; ?>">&nbsp;
								<?php } ?>
								</td>
								<td class="iron-td-normal"><?php echo $item_cat->bg_att; ?></td>
								</tr>
							<?php }
							?>
						</table>
						</div>
					<?php }
					else
						echo "No hay categor&iacute;as creadas !";
					?>
				</div>

				<div class="tabbertab <?php if ($_GET['type']=='phrase') echo 'tabbertabdefault'; ?>">
				<h2>Frases</h2>

					&middot;&nbsp;<a href="?page=<?php echo $cur_menu; ?>&act=add&type=phrase">A&ntilde;adir Frase</a>

					<div class="ironclear"></div>

					<?php
					global $wpdb;
					$table_name = $wpdb->prefix . "iron_tunnels_phrases";

					// Obtain the different item types
					$results = $wpdb->get_results(
					"SELECT * FROM ".$table_name." ORDER BY 1");

					if (sizeof($results) > 0) { ?>
						<div class="tunnels-overflow">
						<table id="iron-tunnels-table">
							<tr>
							<td class="iron-td-mini iron-header"><b>Acciones</b></td>
							<td class="iron-td-small iron-header"><b>Categor&iacute;a</b></td>
							<td class="iron-td-normal iron-header"><b>Frase</b></td>
							<td class="iron-td-normal iron-header"><b>Frase (EUS)</b></td>
							<td class="iron-td-normal iron-header"><b>Frase (EN)</b></td>
							</tr>
							<?php
							foreach ($results as $item_phrase) {
								?>
								<tr>
								<td class="iron-td-mini">
								<a href="?page=<?php echo $cur_menu; ?>&act=edit&type=phrase&id=<?php echo $item_phrase->id; ?>"><img src="<?php echo IRON_TUNNELS_URL.'/images/edit.gif'; ?>" alt="<?php _e( 'Editar', 'buddypress') ?>" title="<?php _e( 'Editar', 'buddypress') ?>"></a>
								<a href="?page=<?php echo $cur_menu; ?>&act=delete&type=phrase&id=<?php echo $item_phrase->id; ?>" onclick="if(!confirm('Eliminar registro ?')) {return false;}"><img src="<?php echo IRON_TUNNELS_URL.'/images/delete.gif'; ?>" alt="<?php _e( 'Eliminar', 'buddypress') ?>" title="<?php _e( 'Eliminar', 'buddypress') ?>"></a>
								</td>								
								<td class="iron-td-small"><?php $catdata=get_category($item_phrase->phrase_category); echo $catdata->name; ?></td>
								<td class="iron-td-normal"><?php echo $item_phrase->phrase_content; ?></td>
								<td class="iron-td-normal"><?php echo $item_phrase->phrase_content_eu; ?></td>
								<td class="iron-td-normal"><?php echo $item_phrase->phrase_content_en; ?></td>
								</tr>
							<?php }
							?>
						</table>
						</div>
					<?php }
					else
						echo "No hay frases creadas !";
					?>
				</div>
				</div>
			</div>

			<?php }
		?>
	</div> <!-- admindiv -->
	<?php
}
?>
