<?php
function module_helper_admin($module_title = 'Module helper', $module_path = 'admin/settings/module_helper') {
$module_name = str_replace(' ', '_', drupal_strtolower($module_title));
$module_id = str_replace('_', '-', $module_name);
$module_info = unserialize( db_result( db_query("SELECT info FROM {system} WHERE type='module' AND status=1 AND name='%s'", $module_name)) );
$output = '<div id="'. $module_id .'-admin">';
$output .= '<p>'. t($module_info['description']) .'</p>';
$output .= '<p>'. t("Below is a list of enabled '@module_title' sub-modules:", array('@module_title' => $module_title)) .'</p>';
$no_configuration = FALSE;
$result = db_query("SELECT * FROM {system} WHERE type='module' AND status=1 AND name LIKE '%s' ORDER BY name", $module_name .'_%');
$output .= '<dl>';
while ($data = db_fetch_array($result)) {
if (!module_helper_is_user_administer($data['name'])) {
continue;
}
$info = unserialize($data['info']);
$settings_path = $module_path . str_replace($module_name .'_', '/', $data['name']);
$demo_path = $settings_path .'/demo';
$output .= '<dt>';
if (module_helper_settings_exist($settings_path)) {
$output .= l($info['name'], $settings_path);
}
else {
$output .= $info['name'] .' <strong>*</strong>';
$no_configuration = TRUE;
}
$output .= '</dt>';
if ($info['description']) {
$output .= '<dd>'. $info['description'] .'</dd>';
}
}
$output .= '</dl>';
if ($no_configuration == TRUE) {
$output .= '<p><strong>*</strong><em> ';
$output .= t('This module does not require configuration. This module either adds additional inputs, items, and/or settings to <a href="@menus">menus</a>, <a href="@nodes">nodes</a>, and/or <a href="@blocks">blocks</a>.', array('@menus' => url('admin/build/menu'), '@nodes' => url('node/add'), '@blocks' => url('admin/build/block')));
$output .= '</em></p>';
}
$output .= '</div>';
return $output;
}
function module_helper_settings_exist($module_path) {
return db_result(db_query("SELECT path FROM {menu_router} WHERE path='%s'", $module_path)) ? TRUE : FALSE;
}
function module_helper_is_user_administer($module_name) {
$hook = $module_name .'_perm';
if (!function_exists($hook)) {
return FALSE;
}
$perm = $hook();
$administer_perm = NULL;
foreach($perm as $value) {
if (stripos($value, 'administer') !== FALSE) {
$administer_perm = $value;
break;
}
}
return ( $administer_perm != NUL)? user_access($administer_perm) : FALSE;
}