<?php
/**
 * @package linea21.core
 * @subpackage theme
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

//////////// Check Inclusion de pages ////////////
if (!class_exists('auth')){
  include_once("../lib/lib_common.php");
  ReloadIndex('admin');
}
////////////

//////////// Check Droits utilisateur ////////////
if (!$l21auth->isSuperAdmin()) ReloadIndex('admin');
////////////

if(isset($_POST['id']))	$id=$_POST['id'];
if(isset($_GET['id']))	$id=$_GET['id'];

if((is_string($id[0]) && $id[0]=='s') || isset($_POST['root'])) {
  $id=str_replace('s' ,'', $id);
  $query=SQL_getoneCompleteSDtheme($id);
  $root = true;
  $mask_mass_del="style=\"visibility:hidden;\"";
  $mask_mass_mod="";
  $mask_del_meth='disabled="disabled"';
  $mask_mod_meth='checked="checked"';
  $form_theme_transfert=-1;
} else {
  $query=SQL_getonetheme($id);
  $root = false;
  $mask_mass_del="style=\"visibility:hidden;\"";
  $mask_mass_mod="style=\"visibility:hidden;\"";
  $mask_del_meth='';
  $mask_mod_meth='';
  $form_theme_transfert=-1;
}



if(isset($_POST['valider'])) {
  if(isset($_POST['root'])) $root = true; else $root = false;
  $integrity=1;

  if(isset($_POST['sup_method'])) {
    $sup_method=$_POST['sup_method'];
    if($sup_method=='delete') {
      $type='MASS_DELETE';
      $mask_mass_del="style=\"visibility:visible;\"";
      $mask_del_meth="checked=\"checked\"";
      $form_theme_transfert=-1;
    }
    if($sup_method=='modify') {
      $type='MASS_MODIFY';
      $mask_mod_meth='checked="checked"';
      $mask_mass_mod="style=\"visibility:visible;\"";
      if($_POST['transfert_theme']==-1) $integrity=_t('theme','sup_notheme');
      else $form_theme_transfert=$_POST['transfert_theme'];
    }
    if($_SESSION['securityaction']!=md5($_POST['securitycode'])) {
      $integrity=_t('security','message');
    }
    if(!is_string($integrity)) {
      $theme_object= new theme;
      if($root == true) $theme_object->SetRoot();
      $link_confirm="confirm.php?rub=".$rub."&todo=".$todo;
      $result=$theme_object->DeleteTheme($id, $sql_object, $type, $form_theme_transfert);
      if(is_numeric($result)) header("Location: ".$link_confirm);
      else  system_error();
    }
  }	else  {
    $integrity=_t('theme','sup_nomethod');
  }

}


include_once("../lib/input_helpers.php");
if($root == true) {
  // select-box des SD thèmes
  $data=$sql_object->DBSelect(SQL_getSDlist4sup($id));
  $select_theme=SDThemeSelectBox($data, "transfert_theme", $form_theme_transfert);
} else {
  $req_list=SQL_getlist4sup($id);
  $data=$sql_object->DBSelect($req_list);
  // select-box des thèmes
  $select_theme=ThemeSelectBox($data, "transfert_theme", $form_theme_transfert);
}



$result1=$sql_object->DBSelect($query);
$theme_name=formatText($result1[0]['theme_name'],'2HTML');

?>
<div id="chemin">
<ul>
	<li><a href="index.php" class="chemin_home"><?php echo _t('way','home') ?></a></li>
	<li><a href="<?php echo $rub_link; ?>" id="chemin_<?php echo $rub; ?>" class="chemin_rub"><?php echo _t('menu','theme')?></a></li>
	<li><span><?php echo formatNavTitle($theme_name); ?></span></li>
</ul>
</div>
<!--end barre haute -->
<?php
include_once(THEME_ADMIN_PATH."quickicons.php");
?>
<div class="contentcontainer"><?php
include_once(override($dir.'/menurub.php', THEME_ADMIN_PATH));
?>
<div id="content">
<?php
if(isset($integrity) && is_string($integrity)) display_errors($integrity);
?> <?php echo "<h2>".formatTitleh2($theme_name)."</h2>"; ?>
<form id="suptheme" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
	<p>
		<input type="radio" name="sup_method" id="sup_method_del" value="delete" onclick="ShowSuppInfo('mass_delete');" <?php echo $mask_del_meth; ?> />
		<label for="sup_method_del" class="autowidth"><?php echo _t('theme','sup_massd'); ?></label>
	</p>
	<p>
		<input type="radio" name="sup_method" id="sup_method_mod" value="modify" onclick="ShowSuppInfo('mass_modify');" <?php echo $mask_mod_meth; ?> />
		<label for="sup_method_mod" class="autowidth"><?php echo _t('theme','sup_massm'); ?></label>
	</p>
	<p id="transfert" <?php echo $mask_mass_mod; ?>>
		<label for="transfert_theme"><?php echo _t('theme','sup_transfert'); ?></label>
		<?php echo $select_theme; ?>
	</p>
	<p>
	<img src="../lib/securitycode.php" alt="<?php echo _t('security','info2'); ?>" id="securityimg" />
		<label for="securitycode" class="autowidth"><?php echo _t('security','info'); ?></label>
		<input type="text" class="shorttextfield" id="securitycode" maxlength="5" name="securitycode" />
	</p>
	<?php
	echo "<div class=\"info\"  id=\"mass_delete\" ".$mask_mass_del.">\n";
	echo "\t"._t('theme','sup_mass_delete')."\n";
	echo "</div>\n";
	echo "<div class=\"info\" id=\"mass_modify\" ".$mask_mass_mod.">\n";
	echo "\t"._t('theme','sup_mass_modify')."\n";
	echo "</div>\n";
	?> 
	<div>
		<?php if($root == true) { ?> 
		<input name="root" type="hidden" id="root" value="1" /> 
		<?php } ?>
		<input name="id" type="hidden" value="<?php echo $id; ?>" />
		<input name="rub" type="hidden" value="<?php echo $rub; ?>" id="rub" />
		<input name="todo" type="hidden" value="<?php echo $todo; ?>" id="todo" />
		<?php echo cancel_button('javascript:history.go(-1);'); ?>
		<input name="valider" type="submit" value="<?php echo _t('btn','valid') ?>" class="button" id="valider" />
	</div>
</form>
</div>
<?php include_once(override($dir.'/help.php', THEME_ADMIN_PATH)); ?>
</div>