Geeklog-Plugins / messenger

The Geeklog Messenger Plugin (messenger)
GNU General Public License v2.0
2 stars 0 forks source link

Error in new user registration #4

Closed hirorongl closed 4 years ago

hirorongl commented 4 years ago
  1. Login as admin

  2. Admin Block Menu > Users > Users

    https://domain.name/admin/user.php

    "Create New" Click

  3. A PHP error has occurred:

E_USER_ERROR(256) - 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 @ /var/www/clients/client0/web2/private/gl2/system/databases/mysqli.class.php line 468

20200509222947

hirorongl commented 4 years ago

version Geeklog: 2.2.1sr1 Messenger: 1.9.4

eSilverStrike commented 4 years ago

To fix v1.9.4 for this issue replace the functions plugin_profilevariablesedit_messenger and plugin_profileextrassave_messenger with the following code in funcitons.inc. I had to add some extra checks in these funcitons to make sure they where on the usersettings.php form and not the User Admin form.

// Adds privacy options to user settings page under Privacy
function plugin_profilevariablesedit_messenger($uid, &$template)
{
    global $_TABLES, $LANG_MSG, $CONF_MSG;

    // Remember edit can happen by User for User Settings and edit/new by Admin on User Admin form
    // Messenger plugin privacy fields do not display on the Admin User form, only the User Settings form
    // Check for Privacy Title field which is present in privacyblock.thtml to confirm we are on usersettings page and privacyblock is being used.
    // Could have used basename($_SERVER['SCRIPT_FILENAME']) but this function gets called for the preview as well on usersettings.php which does not display the privacy settings so the Privacy Block is not set
    if (!empty($template->get_var('lang_privacy_title'))) {
        // Note: This should never happen (a user not existing) since privacy settings only display on the user settings form so the user must exist
        if ($uid > 1) {
            if (DB_count($_TABLES['messenger_userinfo'],"uid", $uid) == 0)  {
               DB_save ($_TABLES['messenger_userinfo'], "uid, broadcasts, notifications, sitepreference","'$uid','{$CONF_MSG['USER_PMBLOCK']}','{$CONF_MSG['USER_NOTIFY']}','{$CONF_MSG['USER_INBOX']}'");
            }

            $result = DB_query ("SELECT broadcasts, notifications, sitepreference FROM {$_TABLES['messenger_userinfo']} WHERE uid = $uid");
            list ($option1,$option2,$option3) = DB_fetchArray ($result);
        } else {
            $option1 = $CONF_MSG['USER_PMBLOCK'];
            $option2 = $CONF_MSG['USER_NOTIFY'];
            $option3 = $CONF_MSG['USER_INBOX'];
        }

        $template->set_var ('lang_field', $LANG_MSG['lang_broadcasts']);
        $template->set_var ('lang_field_text', $LANG_MSG['help_broadcasts']);
        $template->set_var('fieldname', 'messenger_broadcasts');
        $template->set_var('fieldvalue', '1');
        if ($option1) {
            $template->set_var('fieldchecked', 'checked="checked"');
        } else {
            $template->set_var('fieldchecked', '');
        }
        $template->parse('extra_privacy_fields', 'extra_privacy_field', true);

        $template->set_var ('lang_field', $LANG_MSG['lang_notifications']);
        $template->set_var ('lang_field_text', $LANG_MSG['help_notifications']);
        $template->set_var('fieldname', 'messenger_notifications');
        $template->set_var('fieldvalue', '1');
        if ($option2) {
            $template->set_var('fieldchecked', 'checked="checked"');
        } else {
            $template->set_var('fieldchecked', '');
        }
        $template->parse('extra_privacy_fields', 'extra_privacy_field', true);

        $template->set_var ('lang_field', $LANG_MSG['lang_sitenotifications']);
        $template->set_var ('lang_field_text', $LANG_MSG['help_sitenotifications']);
        $template->set_var('fieldname', 'messenger_sitepreference');
        $template->set_var('fieldvalue', '1');
        if ($option3) {
            $template->set_var('fieldchecked', 'checked="checked"');
        } else {
            $template->set_var('fieldchecked', '');
        }

        $template->parse('extra_privacy_fields', 'extra_privacy_field', true);
    }
}

function plugin_profileextrassave_messenger($uid = '')
{
    global $_USER, $_TABLES;

    if (empty($uid)) {
        $uid = $_USER['uid'];
    }

    // Make sure post variables are set. Remember edit can happen by User for User Settings and edit/new by Admin on User Admin form
    // Messenger plugin privacy fields do not display on the Admin User form, only the user settings form
    // Cannot check isset($_POST['messenger_broadcasts']) since checkboxs if not checked do not get returned and we need to know that info
    if ($uid > 1 && basename($_SERVER['SCRIPT_FILENAME']) == 'usersettings.php') {
        $broadcasts = (int) Input::fPost('messenger_broadcasts', 0);
        $notifications = (int) Input::fPost('messenger_notifications', 0);
        $sitepreference = (int) Input::fPost('messenger_sitepreference', 0);

        DB_save($_TABLES['messenger_userinfo'], "uid, broadcasts, notifications, sitepreference", "'$uid', $broadcasts, $notifications, $sitepreference");
    }
}