Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / member / what-nickname.php
index 490ab2a768c4e73f083b935732e5c4452a92f37b..ba66cb970da059a4378feacbb67aeb1098b6bb32 100644 (file)
@@ -1,19 +1,23 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 06/19/2004 *
- * ================                             Last change: 07/24/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 06/19/2004 *
+ * ===================                          Last change: 07/24/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-nickname.php                                *
  * -------------------------------------------------------------------- *
- * Short description : Nickname instead of the ID                       *
+ * Short description : Nickname instead of the id                       *
  * -------------------------------------------------------------------- *
- * Kurzbeschreibung  : Nickname anstelle der ID                         *
+ * Kurzbeschreibung  : Nickname anstelle der id                         *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
 
 // Some security stuff...
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-} elseif (!IS_MEMBER()) {
-       LOAD_URL("modules.php?module=index");
-} elseif ((!EXT_IS_ACTIVE("nickname")) && (!IS_ADMIN())) {
-       addFatalMessage(EXTENSION_PROBLEM_EXT_INACTIVE, "nickname");
-       return;
+       exit();
+} elseif (!isMember()) {
+       redirectToIndexMemberOnlyModule();
 }
 
 // Add description as navigation point
-ADD_DESCR("member", __FILE__);
-$VALID = false;
+addYouAreHereLink('member', __FILE__);
 
-if (isset($_POST['ok'])) {
+if ((!isExtensionActive('nickname')) && (!isAdmin())) {
+       displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=nickname%}');
+       return;
+} // END - if
+
+$isValid = FALSE;
+
+if (isFormSent()) {
        // Nickname was submitted so let's check if it is not already in use
-       if (!empty($_POST['nickname'])) {
+       if (isPostRequestElementSet('nickname')) {
                // Check if nickname is valid
-               $PATTERN = "[".__NICKNAME_PATTERN."]{".__NICKNAME_LENGTH.",}";
-               if (ereg($PATTERN, $_POST['nickname'], $array)) {
+               if (preg_match('/[' . getConfig('nickname_pattern') . ']{' . getConfig('nickname_len') . ',}/', postRequestElement('nickname'), $array)) {
                        // Entered nickname is valid?
-                       if ($array[0] == $_POST['nickname']) $VALID = true;
+                       $isValid = (($array[0] == postRequestElement('nickname')) && (isNicknameUsed(postRequestElement('nickname'))));
                } // END - if
        } // END - if
 } // END - if
 
-if ($VALID) {
-       // Look for nickname in database (we only need just one entry so don't worry about the "LIMIT 1" !
-       $result = SQL_QUERY_ESC("SELECT userid FROM `"._MYSQL_PREFIX."_user_data` WHERE nickname='%s' AND userid != '%s' LIMIT 1",
-               array($_POST['nickname'], $GLOBALS['userid']), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 0) {
+if ($isValid === TRUE) {
+       // Nickname already in use which is the default
+       $content = '{--MEMBER_NICKNAME_ALREADY_IN_USE--}';
+
+       // Look for nickname in database (we only need just one entry so don't worry about the "LIMIT 1" !)
+       $result = sqlQueryEscaped("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `nickname`='%s' AND `userid` != %s LIMIT 1",
+               array(
+                       postRequestElement('nickname'),
+                       getMemberId()
+               ), __FILE__, __LINE__);
+
+       // Is it not in use?
+       if (ifSqlHasZeroNumRows($result)) {
+               // Prepare array
+               $filterData = array(
+                       'history_subject' => 'NICKNAME_CHANGED',
+                       'history_userid'  => getMemberId(),
+                       'history_value'   => postRequestElement('nickname')
+               );
+
+               // Run filter chain
+               runFilterChain('add_history_entry', $filterData);
+
                // Nickname not in use, so set it now
-               SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET nickname='%s' WHERE userid=%s LIMIT 1",
-                       array($_POST['nickname'], $GLOBALS['userid']), __FILE__, __LINE__);
-               $content = NICKNAME_SAVED;
-       } else {
-               // Free result
-               SQL_FREERESULT($result);
+               sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `nickname`='%s' WHERE `userid`=%s LIMIT 1",
+                       array(
+                               postRequestElement('nickname'),
+                               getMemberId()
+                       ), __FILE__, __LINE__);
 
-               // Nickname already in use!
-               $content = NICKNAME_ALREADY_IN_USE;
-       }
+               // Change message
+               $content = '{--MEMBER_NICKNAME_SAVED--}';
+       } // END - if
+
+       // Free result
+       sqlFreeResult($result);
 
        // Load template
-       LOAD_TEMPLATE("admin_settings_saved", false, $content);
+       displayMessage($content);
 } else {
-       // Load current nickname
-       define('__NICKNAME', NICKNAME_GET_NICK($GLOBALS['userid']));
-
-       // Do we have already submit the form?
-       if (!empty($_POST['nickname'])) {
-               OUTPUT_HTML("<STRONG class=\"member_failed\">".NICKNAME_IS_INVALID."</STRONG><P></P>");
+       // Is there already submit the form?
+       if (isPostRequestElementSet('nickname')) {
+               displayErrorMessage('{--MEMBER_NICKNAME_IS_INVALID--}');
        } // END - if
 
        // Load Template
-       LOAD_TEMPLATE("member_nickname_form");
+       loadTemplate('member_nickname_form');
 }
 
-//
+// [EOF]
 ?>