View source
<?php
include_once drupal_get_path('module', 'module_builder') . '/module_builder.components.inc';
function module_builder_home() {
$items = array();
$new = l('New module!', 'admin/build/module_builder/new', array(
'html' => TRUE,
));
$query = db_query("SELECT name, mid FROM {module_builder_basic}");
while ($result = db_fetch_array($query)) {
$items[] = l($result['name'], 'admin/build/module_builder/edit/' . $result['mid']);
}
if (!count($items)) {
$output = '<br /><h3>' . $new . '</h3>';
}
else {
$items[] = '<strong>' . $new . '</strong>';
$output = theme('item_list', $items);
}
return $output;
}
function module_builder_build_new() {
$form = array();
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#description' => t('The title of the module (not the machine-readable name).'),
'#size' => 40,
'#maxlength' => 255,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function module_builder_build_new_submit($form, &$form_state) {
$save = (object) array(
'name' => $form_state['values']['title'],
);
drupal_write_record('module_builder_basic', $save);
$prepared_form_values = array(
'values' => array(
'mid' => $save->mid,
'type' => 'edit',
'name' => $save->name,
),
);
module_builder_default_submit(array(), $prepared_form_values);
$form_state['redirect'] = 'admin/build/module_builder/edit/' . $save->mid;
}
function module_builder_delete_form(&$form_state, $values, $module) {
return confirm_form(array(), t('Are you sure you want to delete the module %module?', array(
'%module' => $module->name,
)), 'admin/build/module_builder/edit/' . $module->mid);
}
function module_builder_delete_form_submit($form, &$form_state) {
db_query('DELETE FROM {module_builder_data} WHERE mid = %d', $form_state['values']['mid']);
db_query('DELETE FROM {module_builder_basic} WHERE mid = %d', $form_state['values']['mid']);
$form_state['redirect'] = 'admin/build/module_builder';
}