1
fatman
block for quickly changing debug mode
  • 2004/1/26 2:54

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


Hi.. I slapped this together because I while I'm working on my own modules I spend a lot of time running into the site prefrences to change the debug mode. I figured it would be handy to have a simple block which provided the option to change debug mode just like the theme's block can be used to change the current theme. The code is below for anyone interested. Should be easy to add into any module of your choice for installation.


add this to the xoops_version.php of your choice.
$modversion['blocks'][5]['file'] = "debug_mode.php";
$modversion['blocks'][5]['name'] = 'Debug Mode';
$modversion['blocks'][5]['description'] = 'pick list to change debug mode';
$modversion['blocks'][5]['show_func'] = "display_debug_options";
$modversion['blocks'][5]['template'] = 'debug_mode.html';

// Change this path depending on which module you incorporate this block into.

$modversion['blocks'][5]['options'] = '/modules/noah/blocks/change_debug_mode.php';


This is debug_mode.php the file which contains the main block function
function display_debug_options($options)
{
 
// could pull this from the database but I'm lazy
 
$debug_modes = array('0|off','1|php debug','2|smarty debug','3|blocks/sql');
    
$block['path'] = $options[0];
    
 
$i 0;
 foreach (  
$debug_modes as $k=>$v  )
 {    
  
$n explode('|'$v);
  
$block['modes'][$i]['value'] = $n[0];
  
$block['modes'][$i]['label'] = $n[1];
  
$i += 1;
 }
    
return 
$block;
}


Here is the file which accepts the post data from the block and updates your sites configs. Note: I was going to use the $xoopsConfig class for this but I'm not really sure how $xoopsConfig works yet so I just stuck with editing xoops_config table directly.

change_debug_mode.php
require('../header.php'); 

// We must always set our main template before including the header 
// I've just used a blank template here but you could
// include one that reported errors if there are any. 
$xoopsOption['template_main'] = 'blank.html'

// Include the page header 
include(XOOPS_ROOT_PATH.'/header.php');

// Assing the message for our blank module
if ( $_POST['debug_modes'] )
{
change_debug_mode($options$_POST['debug_modes']);
}

// Include the page footer 
include(XOOPS_ROOT_PATH.'/footer.php');


// The function which makes the update
function change_debug_mode($options$new_mode='')
{
 global 
$xoopsDB;

 if ( 
$new_mode != '' )
 {    
   
$sql "UPDATE xoops_config SET conf_value = ".$new_mode;
   
$sql .= " WHERE conf_name = 'debug_mode'";
   
$result $xoopsDB->query($sql);
    
   if ( 
$result )
   { 
   
redirect_header(XOOPS_URL2" debug mode updated ");
   }
 }
return;
}


And finally the block template file.
<form action="<{$xoops_url}><{$block.path}>" method="post">
<
select name="debug_modes" onChange="submit();" >
<{foreach 
item=item from=$block.modes }>
<
option value="" selected>Change debug mode</option>
<
option value="<{$item.value}>">
<{
$item.label}></option>
<{/foreach}>
</
select>
</
form>


As you can see this is hack and not really up to par with XOOPS standards, but for quick debugging it works just fine. If anyone knows how to clean this up let me know.

Login

Who's Online

160 user(s) are online (116 user(s) are browsing Support Forums)


Members: 0


Guests: 160


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits