* @copyright 2017 MyAAC
* @version 0.3.0
* @link http://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Commands';
if($config['otserv_version'] == TFS_03):
?>
List of all your commands, you can check in game, by writing - /commands.
render('error_box.html.twig', array('errors' => $errors));
}
echo $twig->render('commands.form.html.twig', array(
'link' => getPageLink('commands', ($action == 'edit' ? 'edit' : 'add')),
'action' => $action,
'id' => isset($id) ? $id : null,
'vdarkborder' => $config['vdarkborder'],
'darkborder' => $config['darkborder'],
'words' => isset($words) ? $words : null,
'description' => isset($description) ? $description : null
));
}
$commands =
$db->query('SELECT `id`, `words`, `description`' .
($canEdit ? ', `hidden`, `ordering`' : '') .
' FROM `' . TABLE_PREFIX . 'commands`' .
(!$canEdit ? ' WHERE `hidden` != 1' : '') .
' ORDER BY `ordering`;');
$last = $commands->rowCount();
echo $twig->render('commands.html.twig', array(
'commands' => $commands,
'last' => $last,
'canEdit' => $canEdit,
'vdarkborder' => $config['vdarkborder']
));
class Commands
{
static public function add($words, $description, &$errors)
{
global $db;
if(isset($words[0]) && isset($description[0]))
{
$query = $db->select(TABLE_PREFIX . 'commands', array('words' => $words));
if($query === false)
{
$query =
$db->query(
'SELECT ' . $db->fieldName('ordering') .
' FROM ' . $db->tableName(TABLE_PREFIX . 'commands') .
' ORDER BY ' . $db->fieldName('ordering') . ' DESC LIMIT 1'
);
$ordering = 0;
if($query->rowCount() > 0) {
$query = $query->fetch();
$ordering = $query['ordering'] + 1;
}
$db->insert(TABLE_PREFIX . 'commands', array('words' => $words, 'description' => $description, 'ordering' => $ordering));
}
else
$errors[] = 'Command with this words already exists.';
}
else
$errors[] = 'Please fill all inputs.';
return !count($errors);
}
static public function get($id) {
global $db;
return $db->select(TABLE_PREFIX . 'commands', array('id' => $id));
}
static public function update($id, $words, $description) {
global $db;
$db->update(TABLE_PREFIX . 'commands', array('words' => $words, 'description' => $description), array('id' => $id));
}
static public function delete($id, &$errors)
{
global $db;
if(isset($id))
{
if(self::get($id) !== false)
$db->delete(TABLE_PREFIX . 'commands', array('id' => $id));
else
$errors[] = 'Command with id ' . $id . ' does not exists.';
}
else
$errors[] = 'id not set';
return !count($errors);
}
static public function toggleHidden($id, &$errors)
{
global $db;
if(isset($id))
{
$query = self::get($id);
if($query !== false)
$db->update(TABLE_PREFIX . 'commands', array('hidden' => ($query['hidden'] == 1 ? 0 : 1)), array('id' => $id));
else
$errors[] = 'Command with id ' . $id . ' does not exists.';
}
else
$errors[] = 'id not set';
return !count($errors);
}
static public function move($id, $i, &$errors)
{
global $db;
$query = self::get($id);
if($query !== false)
{
$ordering = $query['ordering'] + $i;
$old_record = $db->select(TABLE_PREFIX . 'commands', array('ordering' => $ordering));
if($old_record !== false)
$db->update(TABLE_PREFIX . 'commands', array('ordering' => $query['ordering']), array('ordering' => $ordering));
$db->update(TABLE_PREFIX . 'commands', array('ordering' => $ordering), array('id' => $id));
}
else
$errors[] = 'Command with id ' . $id . ' does not exists.';
return !count($errors);
}
}
?>