<?php
/*======================================================================*\
|| #################################################################### ||
|| #              الإهداءات  ehdaa v 3.4                              # ||
|| #              for vBulletin Version 3.5.x                         # ||
|| #              http://7beebi.com    موقع حبيبي                     # ||
|| #              webmaster@7beebi.com                                # ||
|| #################################################################### ||
\*======================================================================*/

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('CVS_REVISION', '$RCSfile: ehdaacp.php,v $ - $Revision: 3.2 $');
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'ehdaacp');

// ################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array();
$specialtemplates = array();
$globaltemplates = array();
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');

// ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminusers'))
{
        print_cp_no_permission();
}

// ############################# LOG ACTION ###############################
log_admin_action(iif($_REQUEST['id'],'do=' . $_REQUEST['do'] . '&id=' . $_REQUEST['id']));

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
print_cp_header($vbphrase['ehdaa']);

if ($_REQUEST['do'] == "manage")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'userid'       => TYPE_INT,
                'limitstart'   => TYPE_INT,
                'limitnumber'  => TYPE_INT,
        ));

        if (empty($vbulletin->GPC['limitstart']))
        {
             $vbulletin->GPC['limitstart'] = 0;
        }
        else
        {
             $vbulletin->GPC['limitstart']--;
        }

        if (empty($vbulletin->GPC['limitnumber']) OR $vbulletin->GPC['limitnumber'] == 0)
        {
            $vbulletin->GPC['limitnumber'] = $vbulletin->options['ehdaa_show'];
        }

        $countehd = $db->query_first("SELECT COUNT(*) AS ehd FROM " . TABLE_PREFIX . "ehdaa");
        $limitfinish = $vbulletin->GPC['limitstart'] + $vbulletin->GPC['limitnumber'];

        $ehdaat = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "ehdaa ORDER BY dateline DESC LIMIT " . $vbulletin->GPC['limitstart'] . ", " . $vbulletin->GPC['limitnumber'] . "");

        print_form_header('ehdaacp','manage');
        print_table_header(construct_phrase(
                        $vbphrase['showing_ehdaa_x_to_y_of_z'],
                        ($vbulletin->GPC['limitstart'] + 1),
                        iif($limitfinish > $countehd['ehd'], $countehd['ehd'], $limitfinish),
                        $countehd['ehd']
                ));

        while ($ehdaa = $db->fetch_array($ehdaat))
        {
               $smiles = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "ehdaa_smilies");
               while ($smile = $db->fetch_array($smiles))
               {
                   $ehdaa['msg'] = str_replace($smile['shortcut_s'], "<img src='../images/ehdaa_smilies/" . $smile['path_smilie'] . "'>", $ehdaa['msg']);
               }

               print_label_row("
               <a href='ehdaacp.php?do=editehdaa&table=ehdaa&id=" . $ehdaa['id'] . "'>" . $vbphrase['edit'] . "</a>
               <a href='ehdaacp.php?do=delehdaa&table=ehdaa&id=" . $ehdaa['id'] . "'>" . $vbphrase['remove'] . "</a>",

               "" . $vbphrase['ehdaa_name'] . " : <a href='user.php?do=edit&userid=" . $ehdaa['userid'] . "'>" . $ehdaa['name'] . "</a>
               <br>
               " . $vbphrase['ehdaa_home'] . " : " . $ehdaa['home'] . "
               <br>
               " . $vbphrase['ehdaa_msg'] . " : " . $ehdaa['msg'] ."
               ");
        }

        if ($vbulletin->GPC['userid'] OR $vbulletin->GPC['userid'] != 0)
        {
            construct_hidden_code('userid', $vbulletin->GPC['userid']);
        }

        construct_hidden_code('limitnumber', $vbulletin->GPC['limitnumber']);

        if ($vbulletin->GPC['limitstart'] == 0 AND $countehd['ehd'] > $vbulletin->GPC['limitnumber'])
        {
            construct_hidden_code('limitstart', $vbulletin->GPC['limitstart'] + $vbulletin->GPC['limitnumber'] + 1);
            print_submit_row($vbphrase['next_page'], 0, 2);
        }
        elseif ($limitfinish < $countehd['ehd'])
        {
            construct_hidden_code('limitstart', $vbulletin->GPC['limitstart'] + $vbulletin->GPC['limitnumber'] + 1);
            print_submit_row($vbphrase['next_page'], 0, 2, $vbphrase['prev_page'], '', true);
        }
        elseif ($limitfinish >= $countehd['ehd'] AND $countehd['ehd'] > $vbulletin->GPC['limitnumber'])
        {
            print_submit_row($vbphrase['first_page'], 0, 2, $vbphrase['prev_page'], '', true);
        }

        print_table_footer();

}
elseif ($_REQUEST['do'] == "delehdaa")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'id'     => TYPE_INT,
                'table'  => TYPE_STR,
        ));

        $ehdaa = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "" . $vbulletin->GPC['table'] . " where id = " . $vbulletin->GPC['id'] . "");

        echo "<p>&nbsp;</p><p>&nbsp;</p>";
        print_form_header("ehdaacp", "killehdaa", 0, 1, '', '75%');
        construct_hidden_code('id', $vbulletin->GPC['id']);
        construct_hidden_code('table', $vbulletin->GPC['table']);
        print_table_header(construct_phrase($vbphrase['confirm_delfile_x'], $ehdaa['id']));
        print_description_row("
        <blockquote><br />
        " . construct_phrase($vbphrase["are_you_sure_want_to_delehdaa_x"], $ehdaa['msg'], $ehdaa['name']) . "
        <br /></blockquote>\n\t");
        print_submit_row($vbphrase['yes'], 0, 2, $vbphrase['no']);
}

elseif ($_REQUEST['do'] == "killehdaa")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'id'     => TYPE_INT,
                'table'  => TYPE_STR,
        ));

        $db->query_write("DELETE FROM " . TABLE_PREFIX . "" . $vbulletin->GPC['table'] . " where id = " . $vbulletin->GPC['id'] . "");

        print_cp_message($vbphrase['done_delete_ehdaa'], 'ehdaacp.php?do=manage', 1);
}

elseif ($_REQUEST['do'] == "editehdaa")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'id'     => TYPE_INT,
                'table'  => TYPE_STR,
        ));

        $ehdaa = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "" . $vbulletin->GPC['table'] . " where id = " . $vbulletin->GPC['id'] . "");

        print_form_header('ehdaacp','saveehdaa');
        print_table_header($vbphrase['ehdaa_edit']);
        print_input_row($vbphrase['userid'], 'userid',$ehdaa['userid']);
        print_input_row($vbphrase['username'], 'name',$ehdaa['name']);
        print_input_row($vbphrase['ehdaa_home'], 'home', $ehdaa['home']);
        print_textarea_row($vbphrase['ehdaa_msg'], 'msg', $ehdaa['msg']);
        construct_hidden_code('id', $vbulletin->GPC['id']);
        construct_hidden_code('table', $vbulletin->GPC['table']);
        print_submit_row($vbphrase['save'], 0);
        print_table_footer();
}

elseif ($_REQUEST['do'] == "saveehdaa")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'id'     => TYPE_INT,
                'userid' => TYPE_INT,
                'name'   => TYPE_STR,
                'home'   => TYPE_STR,
                'msg'    => TYPE_STR,
                'table'  => TYPE_STR,
        ));

        $db->query_write("UPDATE " . TABLE_PREFIX . "" . $vbulletin->GPC['table'] . "
        SET  userid = " . $vbulletin->GPC['userid'] . ", name = '" . $vbulletin->GPC['name'] . "', home = '" . $vbulletin->GPC['home'] . "', msg = '" . $vbulletin->GPC['msg'] . "'
        WHERE id = " . $vbulletin->GPC['id'] . "
        ");

        print_cp_message($vbphrase['done_save_ehdaa'], 'ehdaacp.php?do=manage', 1);
}

elseif ($_REQUEST['do'] == "band")
{
        $ehdaag = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "ehdaa_group_band");

        print_form_header('ehdaacp','addgroup');
        print_table_header($vbphrase['bandgroups'],3);

        $header = array();
        $header[] = $vbphrase['usergroehd'];
        $header[] = $vbphrase['reason'];
        $header[] = "";
        print_cells_row($header, 1, 0, 1);
        $cell = array();

        while ($ehdaagrp = $db->fetch_array($ehdaag))
        {
                $usergbend = $db->query_first("
                SELECT title
                FROM " . TABLE_PREFIX . "usergroup
                WHERE usergroupid = " . $ehdaagrp['usergroupid'] . "
                ");

                $cell[] = "<a href=usergroup.php?do=edit&usergroupid=" . $ehdaagrp['usergroupid'] . " target='_blank'>" . $usergbend['title'] . "</a>";
                $cell[] = $ehdaagrp['msg'];
                $cell[] = "<a href=ehdaacp.php?do=bandeditg&usergroupid=" . $ehdaagrp['usergroupid'] . ">" . $vbphrase['edit'] . "</a>  <a href=ehdaacp.php?do=remove&usergroupid=" . $ehdaagrp['usergroupid'] . ">" . iif($ehdaagrp['usergroupid'] != 1 AND $ehdaagrp['usergroupid'] != 8 AND $ehdaagrp['usergroupid'] != 3, $vbphrase['remove']) . "</a>";
                print_cells_row($cell, 0, 0, 1, 1, 0, 1);
                unset($cell);
                $cell = array();
        }

        print_submit_row($vbphrase['add'], 0, 3);
        print_table_footer();

        $ehdaaus = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "ehdaa_user_band");

        print_form_header('ehdaacp','adduser');
        print_table_header($vbphrase['bandusers'],3);

        $header = array();
        $header[] = $vbphrase['users'];
        $header[] = $vbphrase['reason'];
        $header[] = "";
        print_cells_row($header, 1, 0, 1);
        $cell = array();

        while ($ehdaausr = $db->fetch_array($ehdaaus))
        {
                $userbend = $db->query_first("
                SELECT username
                FROM " . TABLE_PREFIX . "user
                WHERE userid = " . $ehdaausr['userid'] . "
                ");

                $cell[] = "<a href=user.php?do=edit&userid=" . $ehdaausr['userid'] . " target='_blank'>" . $userbend['username'] . "</a>";
                $cell[] = $ehdaausr['msg'];
                $cell[] = "<a href=ehdaacp.php?do=bandeditu&userid=" . $ehdaausr['userid'] . ">" . $vbphrase['edit'] . "</a>  <a href=ehdaacp.php?do=remove&userid=" . $ehdaausr['userid'] . ">" . $vbphrase['remove'] . "</a>";
                print_cells_row($cell, 0, 0, 1, 1, 0, 1);
                unset($cell);
                $cell = array();
        }

        print_submit_row($vbphrase['add'], 0, 3);
        print_table_footer();
}

elseif ($_REQUEST['do'] == "addgroup" OR $_REQUEST['do'] == "bandeditg")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'usergroupid'   => TYPE_INT,
                'do'            => TYPE_STR,
        ));

        if ($_REQUEST['do'] == "bandeditg")
        $group = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "ehdaa_group_band WHERE usergroupid = " . $vbulletin->GPC['usergroupid'] . "");

        print_form_header('ehdaacp','save');
        print_table_header($vbphrase['bandgroup']);
        print_input_row($vbphrase['groupid'], 'usergroupid', $group['usergroupid']);
        print_input_row($vbphrase['reason'], 'reason', '' . $group['msg'] . '');
        construct_hidden_code('what', $vbulletin->GPC['do']);
        construct_hidden_code('id', $vbulletin->GPC['usergroupid']);
        print_submit_row($vbphrase['save'], 0);
        print_table_footer();
}

elseif ($_REQUEST['do'] == "adduser" OR $_REQUEST['do'] == "bandeditu")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'userid' => TYPE_INT,
                'do'     => TYPE_STR,
        ));

        if ($_REQUEST['do'] == "bandeditu")
        $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "ehdaa_user_band WHERE userid = " . $vbulletin->GPC['userid'] . "");

        print_form_header('ehdaacp','save');
        print_table_header($vbphrase['banduser']);
        print_input_row($vbphrase['userid'], 'userid', iif($vbulletin->GPC['userid'], $vbulletin->GPC['userid'], $user['userid']));
        print_input_row($vbphrase['reason'], 'reason', '' . iif($user['msg'] == '', $vbphrase['admin_ehdaa_reason'], $user['msg']) . '');
        construct_hidden_code('what', $vbulletin->GPC['do']);
        construct_hidden_code('id', $vbulletin->GPC['userid']);
        print_submit_row($vbphrase['save'], 0);
        print_table_footer();
}

elseif ($_REQUEST['do'] == "save")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'usergroupid' => TYPE_INT,
                'userid'      => TYPE_INT,
                'reason'      => TYPE_STR,
                'what'        => TYPE_STR,
                'id'          => TYPE_INT,
        ));

        $find = $db->query_first("SELECT * FROM " . TABLE_PREFIX . iif($vbulletin->GPC['userid'], "ehdaa_user_band WHERE userid = " . $vbulletin->GPC['userid'] . "", "ehdaa_group_band WHERE usergroupid = " . $vbulletin->GPC['usergroupid'] . "") . "");

        if (!$vbulletin->GPC['usergroupid'] AND !$vbulletin->GPC['userid'] OR empty($vbulletin->GPC['reason']) OR $vbulletin->GPC['reason'] == '')
        {
                print_cp_message($vbphrase['what_to_save']);
        }
        elseif ($vbulletin->GPC['what'] == 'bandeditg')
        {
                $db->query_write("UPDATE " . TABLE_PREFIX . "ehdaa_group_band SET usergroupid = " . $vbulletin->GPC['usergroupid'] . ", msg = '" . $vbulletin->GPC['reason'] . "' WHERE usergroupid = " . $vbulletin->GPC['id'] . "");
                print_cp_message(construct_phrase($vbphrase['done_x_update'], $vbphrase['ehgroup']), 'ehdaacp.php?do=band', 1);
        }
        elseif ($vbulletin->GPC['what'] == 'bandeditu')
        {
                $db->query_write("UPDATE " . TABLE_PREFIX . "ehdaa_user_band SET userid = " . $vbulletin->GPC['userid'] . ", msg = '" . $vbulletin->GPC['reason'] . "' WHERE userid = " . $vbulletin->GPC['id'] . "");
                print_cp_message(construct_phrase($vbphrase['done_x_update'], $vbphrase['ehuser']), 'ehdaacp.php?do=band', 1);
        }
        elseif ($vbulletin->GPC['usergroupid'])
        {
                if (!$find['usergroupid'])
                {
                        $db->query_write("INSERT INTO " . TABLE_PREFIX . "ehdaa_group_band(usergroupid,msg) VALUES (" . $vbulletin->GPC['usergroupid'] . ",'" . $vbulletin->GPC['reason'] . "')");
                        print_cp_message(construct_phrase($vbphrase['done_x_add'], $vbphrase['ehgroup']), 'ehdaacp.php?do=band', 1);
                }
                else
                {
                        print_cp_message($vbphrase['duplicate'], 'ehdaacp.php?do=bandeditg&usergroupid=' . $vbulletin->GPC['usergroupid'] . '', 5);
                }
        }
        elseif ($vbulletin->GPC['userid'])
        {
                if (!$find['userid'])
                {
                        $db->query_write("INSERT INTO " . TABLE_PREFIX . "ehdaa_user_band(userid,msg) VALUES (" . $vbulletin->GPC['userid'] . ",'" . $vbulletin->GPC['reason'] . "')");
                        print_cp_message(construct_phrase($vbphrase['done_x_add'], $vbphrase['ehuser']), 'ehdaacp.php?do=band', 1);
                }
                else
                {
                        print_cp_message($vbphrase['duplicate'], 'ehdaacp.php?do=bandeditu&userid=' . $vbulletin->GPC['userid'] . '', 5);
                }
        }
}

elseif ($_REQUEST['do'] == "remove")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'userid'        => TYPE_INT,
                'usergroupid'   => TYPE_INT,
        ));

        $find = $db->query_first("SELECT * FROM " . TABLE_PREFIX . iif($vbulletin->GPC['userid'], "user WHERE userid = " . $vbulletin->GPC['userid'] . "", "usergroup WHERE usergroupid = " . $vbulletin->GPC['usergroupid'] . "") . "");

        echo "<p>&nbsp;</p><p>&nbsp;</p>";
        print_form_header("ehdaacp", "kill", 0, 1, '', '75%');
        construct_hidden_code('userid', $vbulletin->GPC['userid']);
        construct_hidden_code('usergroupid', $vbulletin->GPC['usergroupid']);
        print_table_header(construct_phrase($vbphrase['confirm_unband_x'], $find[iif($vbulletin->GPC['userid'], 'username', 'title')]));
        print_description_row("
        <blockquote><br />
        " . construct_phrase($vbphrase["are_you_sure_want_to_unband_x"], $find[iif($vbulletin->GPC['userid'], 'username', 'title')], $vbulletin->GPC[iif($vbulletin->GPC['userid'], 'userid', 'usergroupid')]) . "
        <br /></blockquote>\n\t");
        print_submit_row($vbphrase['yes'], 0, 2, $vbphrase['no']);
}

elseif ($_REQUEST['do'] == "kill")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'userid'        => TYPE_INT,
                'usergroupid'   => TYPE_INT,
        ));

        if ($vbulletin->GPC['userid'])
        {
                $db->query_write("DELETE FROM " . TABLE_PREFIX . "ehdaa_user_band WHERE userid = " . $vbulletin->GPC['userid'] . "");
                print_cp_message(construct_phrase($vbphrase['done_x_removed'], $vbphrase['ehuser']), 'ehdaacp.php?do=band', 1);
        }
        elseif ($vbulletin->GPC['usergroupid'])
        {
                $db->query_write("DELETE FROM " . TABLE_PREFIX . "ehdaa_group_band WHERE usergroupid = " . $vbulletin->GPC['usergroupid'] . "");
                print_cp_message(construct_phrase($vbphrase['done_x_removed'], $vbphrase['ehgroup']), 'ehdaacp.php?do=band', 1);
        }
}

elseif ($_REQUEST['do'] == "icons")
{
        $ehdaa_smilies = $db->query("SELECT * FROM " . TABLE_PREFIX . "ehdaa_smilies ORDER BY id");

        print_form_header('ehdaacp','iconadd');
        print_table_header($vbphrase['smilies'], 3);

        $header = array();
        $header[] = $vbphrase['icon'];
        $header[] = $vbphrase['shortcut'];
        $header[] = "";
        print_cells_row($header, 1, 0, 1);
        $cell = array();

        while ($smilie = $db->fetch_array($ehdaa_smilies))
        {
           $cell[] = "<img src=../images/ehdaa_smilies/" . $smilie['path_smilie'] . " border=0>";
           $cell[] = $smilie['shortcut_s'];
           $cell[] = "<a href=ehdaacp.php?do=iconedit&id=" . $smilie['id'] . ">" . $vbphrase['edit'] . "</a>  <a href=ehdaacp.php?do=iconremove&id=" . $smilie['id'] . ">" . $vbphrase['remove'] . "</a>";
           print_cells_row($cell, 0, 0, 1, 1, 0, 1);
           unset($cell);
           $cell = array();
        }

        print_submit_row($vbphrase['add'], 0, 3);
        print_table_footer();
}

elseif ($_REQUEST['do'] == "iconremove")
{
        $vbulletin->input->clean_gpc('r', 'id', TYPE_INT);

        $find = $db->query_first("SELECT * FROM " . TABLE_PREFIX . " ehdaa_smilies WHERE id = " . $vbulletin->GPC['id'] . "");

        echo "<p>&nbsp;</p><p>&nbsp;</p>";
        print_form_header("ehdaacp", "iconkill", 0, 1, '', '75%');
        construct_hidden_code('id', $vbulletin->GPC['id']);
        print_table_header(construct_phrase($vbphrase['confirm_delicon_x'], $find['path_smilie']));
        print_description_row("
        <blockquote><br />
        " . construct_phrase($vbphrase["are_you_sure_want_to_delicon_x"], $find['path_smilie'], $find['shortcut_s']) . "
        <br /></blockquote>\n\t");
        print_submit_row($vbphrase['yes'], 0, 2, $vbphrase['no']);
}

elseif ($_REQUEST['do'] == "iconkill")
{
        $vbulletin->input->clean_gpc('r', 'id', TYPE_INT);
        $db->query_write("DELETE FROM " . TABLE_PREFIX . "ehdaa_smilies WHERE id = " . $vbulletin->GPC['id'] . "");
        print_cp_message($vbphrase['done_delicon_removed'], 'ehdaacp.php?do=icons', 1);

}

elseif ($_REQUEST['do'] == "iconedit" OR $_REQUEST['do'] == "iconadd")
{
        $vbulletin->input->clean_gpc('r', 'id', TYPE_INT);

        if ($vbulletin->GPC['id'])
        $smilie = $db->query_first("SELECT * FROM " . TABLE_PREFIX . " ehdaa_smilies WHERE id = " . $vbulletin->GPC['id'] . "");

        print_form_header('ehdaacp','iconsave');
        print_table_header(iif($vbulletin->GPC['id'], $vbphrase['icon_edit'], $vbphrase['icon_add']));
        print_input_row($vbphrase['icon'], 'path_smilie',$smilie['path_smilie']);
        print_input_row($vbphrase['shortcut'], 'shortcut_s',iif($vbulletin->GPC['id'], $smilie['shortcut_s'],'^^'));
        construct_hidden_code('id', $vbulletin->GPC['id']);
        construct_hidden_code('what', $_REQUEST['do']);
        print_submit_row($vbphrase['save'], 0);
        print_table_footer();
}

elseif ($_REQUEST['do'] == "iconsave")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'id'          => TYPE_INT,
                'path_smilie' => TYPE_STR,
                'shortcut_s'  => TYPE_STR,
                'what'        => TYPE_STR,
        ));

        if(!$vbulletin->GPC['id'])
        $find = $db->query_first("SELECT * FROM " . TABLE_PREFIX . " ehdaa_smilies WHERE shortcut_s = '" . $vbulletin->GPC['shortcut_s'] . "'");

        if (!$vbulletin->GPC['path_smilie'] OR empty($vbulletin->GPC['shortcut_s']) OR $vbulletin->GPC['shortcut_s'] == '')
        {
                print_cp_message($vbphrase['what_to_save']);
        }
        elseif ($vbulletin->GPC['what'] == 'iconedit')
        {
                $db->query_write("UPDATE " . TABLE_PREFIX . "ehdaa_smilies SET path_smilie = '" . $vbulletin->GPC['path_smilie'] . "', shortcut_s = '" . $vbulletin->GPC['shortcut_s'] . "' WHERE id = " . $vbulletin->GPC['id'] . "");
                print_cp_message(construct_phrase($vbphrase['done_x_update'], $vbphrase['icon']), 'ehdaacp.php?do=icons', 1);
        }
        elseif (!$vbulletin->GPC['id'])
        {
                if (!$find['shortcut_s'])
                {
                        $db->query_write("INSERT INTO " . TABLE_PREFIX . "ehdaa_smilies(path_smilie,shortcut_s) VALUES ('" . $vbulletin->GPC['path_smilie'] . "','" . $vbulletin->GPC['shortcut_s'] . "')");
                        print_cp_message($vbphrase['done_icon_add'], 'ehdaacp.php?do=icons', 1);
                }
                else
                {
                        print_cp_message($vbphrase['duplicate'], 'ehdaacp.php?do=iconedit&id=' . $find['id'] . '', 5);
                }
        }
}

elseif ($_REQUEST['do'] == "words")
{
        $words = $db->query("SELECT * FROM " . TABLE_PREFIX . "ehdaa_words ORDER BY id");

        print_form_header('ehdaacp','wordadd');
        print_table_header($vbphrase['words_f'], 3);

        $header = array();
        $header[] = $vbphrase['word'];
        $header[] = $vbphrase['replace'];
        $header[] = "";
        print_cells_row($header, 1, 0, 1);
        $cell = array();

        while ($word = $db->fetch_array($words))
        {
           $cell[] = $word['findw'];
           $cell[] = $word['replacew'];
           $cell[] = "<a href=ehdaacp.php?do=wordedit&id=" . $word['id'] . ">" . $vbphrase['edit'] . "</a>  <a href=ehdaacp.php?do=wordremove&id=" . $word['id'] . ">" . $vbphrase['remove'] . "</a>";
           print_cells_row($cell, 0, 0, 1, 1, 0, 1);
           unset($cell);
           $cell = array();
        }

        print_submit_row($vbphrase['add'], 0, 3);
        print_table_footer();
}

elseif ($_REQUEST['do'] == "wordremove")
{
        $vbulletin->input->clean_gpc('r', 'id', TYPE_INT);

        $find = $db->query_first("SELECT * FROM " . TABLE_PREFIX . " ehdaa_words WHERE id = " . $vbulletin->GPC['id'] . "");

        echo "<p>&nbsp;</p><p>&nbsp;</p>";
        print_form_header("ehdaacp", "wordkill", 0, 1, '', '75%');
        construct_hidden_code('id', $vbulletin->GPC['id']);
        print_table_header(construct_phrase($vbphrase['confirm_delword_x'], $find['findw']));
        print_description_row("
        <blockquote><br />
        " . construct_phrase($vbphrase["are_you_sure_want_to_delword_x"], $find['findw'], $find['replacew']) . "
        <br /></blockquote>\n\t");
        print_submit_row($vbphrase['yes'], 0, 2, $vbphrase['no']);
}

elseif ($_REQUEST['do'] == "wordkill")
{
        $vbulletin->input->clean_gpc('r', 'id', TYPE_INT);
        $db->query_write("DELETE FROM " . TABLE_PREFIX . "ehdaa_words WHERE id = " . $vbulletin->GPC['id'] . "");
        print_cp_message($vbphrase['done_delword_removed'], 'ehdaacp.php?do=words', 1);

}

elseif ($_REQUEST['do'] == "wordedit" OR $_REQUEST['do'] == "wordadd")
{
        $vbulletin->input->clean_gpc('r', 'id', TYPE_INT);

        if ($vbulletin->GPC['id'])
        $word = $db->query_first("SELECT * FROM " . TABLE_PREFIX . " ehdaa_words WHERE id = " . $vbulletin->GPC['id'] . "");

        print_form_header('ehdaacp','wordsave');
        print_table_header(iif($vbulletin->GPC['id'], $vbphrase['word_edit'], $vbphrase['word_add']));
        print_input_row($vbphrase['word'], 'findw', $word['findw']);
        print_input_row($vbphrase['replace'], 'replacew',iif($vbulletin->GPC['id'], $word['replacew'],'*****'));
        construct_hidden_code('id', $vbulletin->GPC['id']);
        construct_hidden_code('what', $_REQUEST['do']);
        print_submit_row($vbphrase['save'], 0);
        print_table_footer();
}

elseif ($_REQUEST['do'] == "wordsave")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'id'        => TYPE_INT,
                'findw'     => TYPE_STR,
                'replacew'  => TYPE_STR,
                'what'      => TYPE_STR,
        ));

        if(!$vbulletin->GPC['id'])
        $find = $db->query_first("SELECT * FROM " . TABLE_PREFIX . " ehdaa_words WHERE findw = '" . $vbulletin->GPC['findw'] . "'");

        if (!$vbulletin->GPC['findw'] OR empty($vbulletin->GPC['replacew']) OR $vbulletin->GPC['replacew'] == '')
        {
                print_cp_message($vbphrase['what_to_save']);
        }
        elseif ($vbulletin->GPC['what'] == 'wordedit')
        {
                $db->query_write("UPDATE " . TABLE_PREFIX . "ehdaa_words SET findw = '" . $vbulletin->GPC['findw'] . "', replacew = '" . $vbulletin->GPC['replacew'] . "' WHERE id = " . $vbulletin->GPC['id'] . "");
                print_cp_message(construct_phrase($vbphrase['done_x_update'], $vbphrase['word']), 'ehdaacp.php?do=words', 1);
        }
        elseif (!$vbulletin->GPC['id'])
        {
                if (!$find['findw'])
                {
                        $db->query_write("INSERT INTO " . TABLE_PREFIX . "ehdaa_words(findw,replacew) VALUES ('" . $vbulletin->GPC['findw'] . "','" . $vbulletin->GPC['replacew'] . "')");
                        print_cp_message($vbphrase['done_word_add'], 'ehdaacp.php?do=words', 1);
                }
                else
                {
                        print_cp_message($vbphrase['duplicate'], 'ehdaacp.php?do=wordedit&id=' . $find['id'] . '', 5);
                }
        }
}

elseif ($_REQUEST['do'] == "waiting")
{
        $vbulletin->input->clean_array_gpc('r', array
        (
                'userid'       => TYPE_INT,
                'limitstart'   => TYPE_INT,
                'limitnumber'  => TYPE_INT,
        ));

        if (empty($vbulletin->GPC['limitstart']))
        {
             $vbulletin->GPC['limitstart'] = 0;
        }
        else
        {
             $vbulletin->GPC['limitstart']--;
        }

        if (empty($vbulletin->GPC['limitnumber']) OR $vbulletin->GPC['limitnumber'] == 0)
        {
            $vbulletin->GPC['limitnumber'] = $vbulletin->options['ehdaa_show'];
        }

        $countehd = $db->query_first("SELECT COUNT(*) AS ehd FROM " . TABLE_PREFIX . "ehdaa_w");
        $limitfinish = $vbulletin->GPC['limitstart'] + $vbulletin->GPC['limitnumber'];

        $ehdaat = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "ehdaa_w ORDER BY dateline DESC LIMIT " . $vbulletin->GPC['limitstart'] . ", " . $vbulletin->GPC['limitnumber'] . "");

        print_form_header('ehdaacp','waiting');
        print_table_header(construct_phrase(
                        $vbphrase['showing_ehdaaw_x_to_y_of_z'],
                        ($vbulletin->GPC['limitstart'] + 1),
                        iif($limitfinish > $countehd['ehd'], $countehd['ehd'], $limitfinish),
                        $countehd['ehd']
                ));

        while ($ehdaa = $db->fetch_array($ehdaat))
        {
               $smiles = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "ehdaa_smilies");
               while ($smile = $db->fetch_array($smiles))
               {
                   $ehdaa['msg'] = str_replace($smile['shortcut_s'], "<img src='../images/ehdaa_smilies/" . $smile['path_smilie'] . "'>", $ehdaa['msg']);
               }

               print_label_row("
               <a href='ehdaacp.php?do=acceptehdaa&id=" . $ehdaa['id'] . "'>" . $vbphrase['accept'] . "</a>
               <a href='ehdaacp.php?do=editehdaa&table=ehdaa_w&id=" . $ehdaa['id'] . "'>" . $vbphrase['edit'] . "</a>
               <a href='ehdaacp.php?do=delehdaa&table=ehdaa_w&id=" . $ehdaa['id'] . "'>" . $vbphrase['remove'] . "</a>",

               "" . $vbphrase['ehdaa_name'] . " : <a href='user.php?do=edit&userid=" . $ehdaa['userid'] . "'>" . $ehdaa['name'] . "</a>
               <br>
               " . $vbphrase['ehdaa_home'] . " : " . $ehdaa['home'] . "
               <br>
               " . $vbphrase['ehdaa_msg'] . " : " . $ehdaa['msg'] ."
               ");
        }

        if ($vbulletin->GPC['userid'] OR $vbulletin->GPC['userid'] != 0)
        {
            construct_hidden_code('userid', $vbulletin->GPC['userid']);
        }

        construct_hidden_code('limitnumber', $vbulletin->GPC['limitnumber']);

        if ($vbulletin->GPC['limitstart'] == 0 AND $countehd['ehd'] > $vbulletin->GPC['limitnumber'])
        {
            construct_hidden_code('limitstart', $vbulletin->GPC['limitstart'] + $vbulletin->GPC['limitnumber'] + 1);
            print_submit_row($vbphrase['next_page'], 0, 2);
        }
        elseif ($limitfinish < $countehd['ehd'])
        {
            construct_hidden_code('limitstart', $vbulletin->GPC['limitstart'] + $vbulletin->GPC['limitnumber'] + 1);
            print_submit_row($vbphrase['next_page'], 0, 2, $vbphrase['prev_page'], '', true);
        }
        elseif ($limitfinish >= $countehd['ehd'] AND $countehd['ehd'] > $vbulletin->GPC['limitnumber'])
        {
            print_submit_row($vbphrase['first_page'], 0, 2, $vbphrase['prev_page'], '', true);
        }

        print_table_footer();
}

elseif ($_REQUEST['do'] == "acceptehdaa")
{
        $vbulletin->input->clean_gpc('r', 'id', TYPE_INT);

        $ehdaatw = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "ehdaa_w WHERE id = " . $vbulletin->GPC['id'] . "");

        $db->query_write("
        INSERT INTO " . TABLE_PREFIX . "ehdaa
        (userid, name, home, msg, dateline)
        VALUES
        (" . $ehdaatw['userid'] . ", '" . $ehdaatw['name'] . "', '" . $ehdaatw['home'] . "', '" . $ehdaatw['msg'] . "', " . $ehdaatw['dateline'] . ")
        ");

        $db->query_write("DELETE FROM " . TABLE_PREFIX . "ehdaa_w WHERE id = " . $vbulletin->GPC['id'] . "");

        print_cp_message($vbphrase['done_accept_ehdaa'], 'ehdaacp.php?do=manage', 1);
}

elseif ($_REQUEST['do'] == "delete")
{
        echo "<p>&nbsp;</p><p>&nbsp;</p>";
        print_form_header("ehdaacp", "delallehdaa", 0, 1, '', '75%');
        print_table_header($vbphrase['confirm_dellall_ehdaa']);
        print_description_row("
        <blockquote><br />
        " . $vbphrase["are_you_sure_want_to_dellall_ehdaa_x"] . "
        <br /></blockquote>\n\t");
        print_submit_row($vbphrase['yes'], 0, 2, $vbphrase['no']);
}

elseif ($_REQUEST['do'] == "delallehdaa")
{
        $db->query_write("DELETE FROM " . TABLE_PREFIX . "ehdaa");
        $db->query_write("DELETE FROM " . TABLE_PREFIX . "ehdaa_w");
        print_cp_message($vbphrase['done_dellall_ehdaa'], 'index.php', 1);
}

print_cp_footer();
?>