MyBB Community Forums

Full Version: need some help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am working on making a admin module. i need some help with it. I did make a thread about it before but no one seems to want to help with it. 



so how do we go about making a admin module?


i am unsure of the functions inside the files. and mybb does not like to apparantly go into details about how to make things out of  their functions nor give a detail list of their functions. 




<?php
/**
 * MyBB 1.8
 * Copyright 2014 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybb.com
 * License: http://www.mybb.com/about/license
 *
 */

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}



$page->extra_header .= "<!-- Latest compiled and minified CSS -->
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css' integrity='sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7' crossorigin='anonymous'>

<!-- Optional theme -->
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css' integrity='sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r' crossorigin='anonymous'>

<!-- Latest compiled and minified JavaScript -->
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js' integrity='sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS' crossorigin='anonymous'></script>";
$page->output_header();


$sub_tabs['dashboard'] = array(
'title' => "hi",
'link' => "index.php",
'description' => $lang->dashboard_description
);

$sub_tabs['version_check'] = array(
'title' => $lang->version_check,
'link' => "index.php?module=home&amp;action=version_check",
'description' => $lang->version_check_description
);

switch($mybb->input['action'])
{
default:
echo"
<div class='contianer'>
<div class='row'>
<div class='col-lg-12'>
<div class='page-header'>
<h1>Manage <small> Memos </small></h1> <div class='pull-right'><a href='index.php?module=memos-memo&action=add' class='btn btn-primary'>Add memo</a></div>
</div>
<table class='table table-striped'>
<thead>
<tr>
<th class='text-center'>title</th>
<th class='text-center'>Option</th>
</tr>
</thead>
<tbody>";
$query = $db->write_query("SELECT * FROM ".TABLE_PREFIX."test");
if($query->num_rows != 0)
{
while($result = $db->fetch_array($query))
{
echo"<tr>
<td class='text-center'>$result[title]</td>
<td class='text-center'><a href='?module=memos-memo&action=edit&id=$result[id]'>Edit</a> || <a href='?module=memos-memo&action=delete&id=$result[id]'>Delete</a></td>
</tr>";
}
}else
{
echo"<tr>
<td colspan='2' class='text-center bg-danger text-info'>Sorry nothing found</td>
</tr>";
}
echo"
</tbody>
</table>
</div>
</div>
</div>";
break;
case'add';
if($mybb->request_method != "post")
{
echo"<form action='' method='post'>
<div class='form-group'>
<label>Title:</label>
<input type='text' class='form-control' name='title' />
</div>
<div class='form-group'>
<label>message:</label>
<textarea class='form-control' rows='10' cols='50' name='message'></textarea>
</div>
<div class='form-group'>
<input type='submit' name='save' value='save' class='btn btn-success'/>
</div>";
echo '<input type="hidden" name="my_post_key" value="'.$mybb->post_code.'" />';
echo"
</form>
";
}else
{
$test = $db->escape_string($mybb->input['title']);
$message = $db->escape_string($mybb->input['message']);
$query = $db->insert_query('test',array('title'=>$test,'message'=>$message));
if($db->dberror == '')
{
echo "success: $title <br/> $message";
}else
{
echo $db->dberror;
}


}
break;
case'edit';
$id = $mybb->input['id'];
if($mybb->request_method != "post")
{


$query = $db->write_query("SELECT title, message FROM ".TABLE_PREFIX."test WHERE id='$id'");

$row = $db->fetch_array($query);
echo"<form action='' method='post'>
<div class='form-group'>
<label>Title:</label>
<input type='text' class='form-control' name='title' value='$row[title]'/>
</div>
<div class='form-group'>
<label>message:</label>
<textarea class='form-control' rows='10' cols='50' name='message'>$row[message]</textarea>
</div>
<div class='form-group'>
<input type='submit' name='save' value='save' class='btn btn-success'/>
</div>";
echo '<input type="hidden" name="my_post_key" value="'.$mybb->post_code.'" />';
echo"
</form>
";


}else
{
$test = $db->escape_string($mybb->input['title']);
$message = $db->escape_string($mybb->input['message']);
$query = $db->update_query('test',array('title'=>$test,'message'=>$message),"id = '".$id."'");
if($db->dberror == '')
{
echo "success: $title <br/> ".strip_tags($message)."";
}else
{
echo $db->dberror;
}


}

break;
case'delete';
$db->delete_query('test',"id='".$mybb->input['id']."'");
break;
}


$page->output_footer();



this is the file so far. i got the module_meta part done. that was easy. its the actual file. (as you can see I went to php developer ways of doing it. )