<?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: ehdaamd.php,v $ - $Revision: 3.4 $');
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'ehdaamd');

// ################### 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_moderate(0, 'caneditsigs'))
{
        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('ehdaamd','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='ehdaamd.php?do=editehdaa&table=ehdaa&id=" . $ehdaa['id'] . "'>" . $vbphrase['edit'] . "</a>
               <a href='ehdaamd.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("ehdaamd", "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'], 'ehdaamd.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('ehdaamd','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'], 'ehdaamd.php?do=manage', 1);
}

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

        print_form_header('ehdaamd','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=ehdaamd.php?do=bandeditg&usergroupid=" . $ehdaagrp['usergroupid'] . ">" . $vbphrase['edit'] . "</a>  <a href=ehdaamd.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('ehdaamd','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=ehdaamd.php?do=bandeditu&userid=" . $ehdaausr['userid'] . ">" . $vbphrase['edit'] . "</a>  <a href=ehdaamd.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'] == "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('ehdaamd','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='ehdaamd.php?do=acceptehdaa&id=" . $ehdaa['id'] . "'>" . $vbphrase['accept'] . "</a>
               <a href='ehdaamd.php?do=editehdaa&table=ehdaa_w&id=" . $ehdaa['id'] . "'>" . $vbphrase['edit'] . "</a>
               <a href='ehdaamd.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'], 'ehdaamd.php?do=manage', 1);
}

elseif ($_REQUEST['do'] == "delete")
{
        echo "<p>&nbsp;</p><p>&nbsp;</p>";
        print_form_header("ehdaamd", "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();
?>