Updated copyright year.
[mailer.git] / inc / modules / member / what-mydata.php
index e88a8f85532dd0ff6746fe30d7ee0f0b7ed75c06..27ec77bc17e048f7f5d9202f6d3b70304c6e63e1 100644 (file)
  * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
  * $Author::                                                          $ *
- * Needs to be in all Files and every File needs "svn propset           *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2016 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')) {
-       die();
+       exit();
 } elseif (!isMember()) {
        redirectToIndexMemberOnlyModule();
 }
 
 // Add description as navigation point
-addMenuDescription('member', __FILE__);
+addYouAreHereLink('member', __FILE__);
 
 if ((!isExtensionActive('mydata')) && (!isAdmin())) {
-       loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('mydata'));
+       displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=mydata%}');
        return;
 } // END - if
 
 // Add userid
-$content = array(
-       'userid' => getMemberId()
-);
+$content = array();
 
 // Init variable to prevent notices
-$URL = '';
+$url = '';
 
 // Detect what the member wants to do
 $mode = 'show'; // Show his data
-if (isPostRequestElementSet('save'))   $mode = 'save';   // Save entered data
-if (isPostRequestElementSet('edit'))   $mode = 'edit';   // Edit data
-if (isPostRequestElementSet('notify')) $mode = 'notify'; // Switch off notification
+if (isFormSent('save'))   $mode = 'save';   // Save entered data
+if (isFormSent('edit'))   $mode = 'edit';   // Edit data
+if (isFormSent('notify')) $mode = 'notify'; // Switch off notification
 
 switch ($mode) {
        case 'show': // Show his data
@@ -71,24 +68,21 @@ switch ($mode) {
                $content = merge_array($content, getUserDataArray());
 
                // Translate some things
-               $content['gender']      = translateGender($content['gender']);
                $content['last_update'] = generateDateTime($content['last_update'], 0);
 
                // How far is last change on his profile away from now?
-               if ((($content['last_update'] + getConfig('profile_lock')) > time()) && (!isAdmin()) && (getConfig('profile_lock') > 0)) {
+               if ((($content['last_update'] + getProfileLock()) > time()) && (!isAdmin()) && (getProfileLock() > 0)) {
                        // You cannot change your account
-                       $content['change'] = loadTemplate('admin_settings_saved', true, '<div class="member_failed">' . getMaskedMessage('MEMBER_PROFILE_LOCKED', generateDateTime($content['last_update'] + getConfig('profile_lock'), 0)) . '</div>');
+                       $content['change'] = returnMessage('<div class="notice">{%message,MEMBER_PROFILE_LOCKED=' . generateDateTime($content['last_update'] + getProfileLock(), 0) . '%}</div>');
                } else {
                        // He is allowed to change his profile
-                       $content['change'] = loadTemplate('member_mydata_button', true);
+                       $content['change'] = loadTemplate('member_mydata_button', TRUE);
                }
 
-               if (strlen($content['birth_day'])   == 1) $content['birth_day']   = '0' . $content['birth_day'];
-               if (strlen($content['birth_month']) == 1) $content['birth_month'] = '0' . $content['birth_month'];
-
+               // @TODO Move this to a function (for better EL code)
                switch (getLanguage()) {
-                       case 'de': $content['dob'] = $content['birth_day']   . '.' . $content['birth_month'] . '.' . $content['birth_year']; break;
-                       default  : $content['dob'] = $content['birth_month'] . '-' . $content['birth_day']   . '-' . $content['birth_year']; break;
+                       case 'de': $content['dob'] = '{%pipe,padLeftZero=' . $content['birth_day']   . '%}.{%pipe,padLeftZero=' . $content['birth_month'] . '%}.' . $content['birth_year']; break;
+                       default  : $content['dob'] = '{%pipe,padLeftZero=' . $content['birth_month'] . '%}-{%pipe,padLeftZero=' . $content['birth_day']   . '%}-' . $content['birth_year']; break;
                } // END - switch
 
                if (isExtensionActive('country')) {
@@ -97,94 +91,120 @@ switch ($mode) {
                } // END - if
 
                // Load template
-               loadTemplate('member_mydata_overview', false, $content);
+               loadTemplate('member_mydata_overview', FALSE, $content);
                break;
 
        case 'edit': // Edit data
-               if (isExtensionActive('country', true)) {
-                       // New way                          0          1            2             3         4       5       6           7            8              9          10         11               12            13
-                       $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `street_nr`, `country_code`, `zip`, `city`, `email`, `birth_day`, `birth_month`, `birth_year`, `gender`, `max_mails`, `receive_mails`, `last_update`
+               if (isExtensionActive('country', TRUE)) {
+                       // New way
+                       $result = sqlQueryEscaped('SELECT
+       `surname`,
+       `family`,
+       `street_nr`,
+       `country_code`,
+       `zip`,
+       `city`,
+       `email`,
+       `birth_day`,
+       `birth_month`,
+       `birth_year`,
+       `gender`,
+       `max_mails`,
+       `receive_mails`,
+       `last_update`
 FROM
        `{?_MYSQL_PREFIX?}_user_data`
 WHERE
        `userid`=%s
-LIMIT 1",
+LIMIT 1',
                        array(getMemberId()), __FILE__, __LINE__);
                } else {
-                       // Old way                          0          1            2          3       4       5       6           7            8              9          10         11               12            13
-                       $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `street_nr`, `country`, `zip`, `city`, `email`, `birth_day`, `birth_month`, `birth_year`, `gender`, `max_mails`, `receive_mails`, `last_update`
+                       // Old way
+                       $result = sqlQueryEscaped('SELECT
+       `surname`,
+       `family`,
+       `street_nr`,
+       `country`,
+       `zip`,
+       `city`,
+       `email`,
+       `birth_day`,
+       `birth_month`,
+       `birth_year`,
+       `gender`,
+       `max_mails`,
+       `receive_mails`,
+       `last_update`
 FROM
        `{?_MYSQL_PREFIX?}_user_data`
 WHERE
        `userid`=%s
-LIMIT 1",
+LIMIT 1',
                                array(getMemberId()), __FILE__, __LINE__);
                }
 
                // Get line
-               $content = merge_array($content, SQL_FETCHARRAY($result, 0, false));
+               $content = merge_array($content, sqlFetchArray($result));
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
-               $content['update_check'] = $content['last_update'] + getConfig('profile_lock');
+               $content['update_check'] = $content['last_update'] + getProfileLock();
 
                // How far is last change on his profile away from now?
-               if (($content['update_check'] > time()) && (!isAdmin()) && (getConfig('profile_lock') > 0)) {
-                       $content['update_check'] = getMaskedMessage('MEMBER_PROFILE_LOCKED', generateDateTime($content['update_check'] + getConfig('profile_lock'), 0));
+               if (($content['update_check'] > time()) && (!isAdmin()) && (getProfileLock() > 0)) {
+                       // Profile is locked, so output propper message
+                       $content['update_check'] = '{%message,MEMBER_PROFILE_LOCKED=' . generateDateTime($content['update_check'] + getProfileLock(), '0') . '%}';
 
                        // You cannot change your account
-                       loadTemplate('admin_settings_saved', false, $content['update_check']);
+                       displayMessage($content['update_check']);
                } else {
-                       // He is allowed to change his profile
-                       foreach (array('gender_m','gender_f','gender_c') as $entry) {
-                               $content[$entry] = '';
-                       } // END - foreach
-
-                       $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
+                       // Init elements
                        $content['dob'] = '';
 
                        switch (getLanguage()) {
                                case 'de': // German date format
                                        // Day
-                                       $content['dob'] .= addSelectionBox('day', $content['birth_day']);
+                                       $content['dob'] .= addSelectionBox('da', $content['birth_day']);
 
                                        // Month
-                                       $content['dob'] .= addSelectionBox('month', $content['birth_month']);
+                                       $content['dob'] .= addSelectionBox('mo', $content['birth_month']);
 
                                        // Year
-                                       $content['dob'] .= addSelectionBox('year', $content['birth_year']);
+                                       $content['dob'] .= addSelectionBox('ye', $content['birth_year']);
                                        break;
 
                                default: // Default is the US date format... :)
                                        // Month
-                                       $content['dob'] .= addSelectionBox('month', $content['birth_month']);
+                                       $content['dob'] .= addSelectionBox('mo', $content['birth_month']);
 
                                        // Day
-                                       $content['dob'] .= addSelectionBox('day', $content['birth_day']);
+                                       $content['dob'] .= addSelectionBox('da', $content['birth_day']);
 
                                        // Year
-                                       $content['dob'] .= addSelectionBox('year', $content['birth_year']);
+                                       $content['dob'] .= addSelectionBox('ye', $content['birth_year']);
                                        break;
                        } // END - if
 
-                       $content['max_receive_list'] = addMaxReceiveList('member', $content['max_mails'], true);
+                       $content['max_receive_list'] = addMaxReceiveList('member', $content['max_mails']);
 
                        if (isExtensionActive('country')) {
-                               // Generate selection box
-                               $OUT  = "<select name=\"country_code\" class=\"member_select\" size=\"1\">\n";
-                               $whereStatement = "WHERE `is_active`='Y'";
+                               // Init WHERE statement
+                               $whereStatement = " WHERE `is_active`='Y'";
                                if (isAdmin()) $whereStatement = '';
-                               $OUT .= generateOptionList('countries', 'id', 'descr', $content['country_code'], 'code', $whereStatement);
-                               $OUT .= "</select>";
+
+                               // Generate selection box
+                               $OUT  = '<select name="country_code" class="form_select" size="1">';
+                               $OUT .= generateOptions('countries', 'id', 'descr', $content['country_code'], 'code', $whereStatement);
+                               $OUT .= '</select>';
                                $content['country'] = $OUT;
                        } else {
                                // Ouput default input box
-                               $content['country'] = '<input type="text" name="cntry" class="member_normal" size="2" maxlength="3" value="' . $content['country'] . '" />';
+                               $content['country'] = '<input type="text" name="cntry" class="form_field" size="2" maxlength="3" value="' . $content['country'] . '" />';
                        }
 
                        // Load template
-                       loadTemplate('member_mydata_edit', false, $content);
+                       loadTemplate('member_mydata_edit', FALSE, $content);
                }
                break;
 
@@ -193,53 +213,78 @@ LIMIT 1",
                $content = merge_array($content, getUserDataArray());
 
                // Calculate time to check
-               $content['update_check'] = $content['last_update'] + getConfig('profile_lock');
+               $content['update_check'] = $content['last_update'] + getProfileLock();
 
                // How far is last change on his profile away from now?
-               if (($content['update_check'] > time()) && (!isAdmin()) && (getConfig('profile_lock') > 0)) {
-                       $content['update_check'] = generateDateTime($content['update_check'] + getConfig('profile_lock'), 0);
-
+               if (($content['update_check'] > time()) && (!isAdmin()) && (getProfileLock() > 0)) {
                        // You cannot change your account
-                       loadTemplate('admin_settings_saved', false, $content['update_check']);
+                       $content['update_check'] = generateDateTime($content['update_check'] + getProfileLock(), 0);
+
+                       displayMessage($content['update_check']);
                } elseif ((!isEmailValid(postRequestElement('email'))) && (!isAdmin())) {
                        // Invalid email address!
-                       loadTemplate('admin_settings_saved', false, getMessage('INVALID_EMAIL_ENTERED'));
+                       displayMessage('{--INVALID_EMAIL_ENTERED--}');
+               } elseif ((isExtensionInstalledAndNewer('other', '0.3.0')) && (isCheckDoubleEmailEnabled()) && (!isAdmin()) && (isEmailTaken(postRequestElement('email')))) {
+                       // Email address is already registered
+                       displayMessage('{--MEMBER_EMAIL_IS_ALREADY_REGISTERED--}');
                } else {
                        // Generate hash
-                       $hash = generateHash(postRequestElement('pass1'), substr($content['password'], 0, -40));
-                       if ((($hash == $content['password']) || (postRequestElement('pass1') == postRequestElement('pass2'))) && (isPostRequestElementSet('pass1'))) {
+                       $hash = generateHash(postRequestElement('password1'), substr($content['password'], 0, -40));
+                       if ((($hash == $content['password']) || (postRequestElement('password1') == postRequestElement('password2'))) && (isPostRequestElementSet('password1'))) {
                                // Only on simple changes normal mode is active = no email or password changed
                                $mode = 'normal';
                                $AND = '';
 
                                // Did the user changed the password?
                                if ($hash != $content['password']) {
-                                       $AND = ", `password`='" . $hash . "'";
-                                       $mode = 'pass';
+                                       // Yes
+                                       $AND = ",`password`='" . $hash . "'";
+                                       $mode = 'password';
                                } // END - if
 
-                               // Or did he changed his password?
+                               // Or did he changed his email address?
                                if (postRequestElement('email') != $content['email']) {
-                                       // Jupp
+                                       // Yes, but is it maybe blacklisted?
+                                       $filterData = array(
+                                               'init_done'   => TRUE,
+                                               'post_data'   => postRequestArray(),
+                                               'blacklisted' => '',
+                                               'message'     => '{--PRE_UPDATE_USER_DATA_FAILED--}',
+                                       );
+                                       $filterData = runFilterChain('pre_update_user_data', $filterData);
+
+                                       // Is it blacklisted?
+                                       if ($filterData['init_done'] === FALSE) {
+                                               // Found something blacklisted
+                                               displayMessage($filterData['message']);
+                                               return;
+                                       } // END - if
+
                                        if ($mode == 'normal') {
                                                $mode = 'email';
                                        } else {
                                                $mode .= ';email';
                                        }
-                                       setRequestPostElement('old_email', $content['email']);
+                                       setPostRequestElement('old_email', $content['email']);
                                } // END - if
 
                                // Update member's profile
                                if (isExtensionActive('country')) {
                                        // New way
-                                       SQL_QUERY_ESC("UPDATE
+                                       sqlQueryEscaped("UPDATE
        `{?_MYSQL_PREFIX?}_user_data`
 SET
-       `gender`='%s', `surname`='%s', `family`='%s',
+       `gender`='%s',
+       `surname`='%s',
+       `family`='%s',
        `street_nr`='%s',
-       `country_code`=%s, `zip`=%s, `city`='%s',
+       `country_code`=%s,
+       `zip`=%s,
+       `city`='%s',
        `email`='%s',
-       `birth_day`=%s, `birth_month`=%s, `birth_year`=%s,
+       `birth_day`=%s,
+       `birth_month`=%s,
+       `birth_year`=%s,
        `max_mails`='%s',
        `last_update`=UNIX_TIMESTAMP()".$AND.",
        `notified`='N',
@@ -264,14 +309,20 @@ LIMIT 1",
                                                ), __FILE__, __LINE__);
                                } else {
                                        // Old way
-                                       SQL_QUERY_ESC("UPDATE
+                                       sqlQueryEscaped("UPDATE
        `{?_MYSQL_PREFIX?}_user_data`
 SET
-       `gender`='%s', `surname`='%s', `family`='%s',
+       `gender`='%s',
+       `surname`='%s',
+       `family`='%s',
        `street_nr`='%s',
-       `country`='%s', `zip`=%s, `city`='%s',
+       `country`='%s',
+       `zip`=%s,
+       `city`='%s',
        `email`='%s',
-       `birth_day`=%s, `birth_month`=%s, `birth_year`=%s,
+       `birth_day`=%s,
+       `birth_month`=%s,
+       `birth_year`=%s,
        `max_mails`='%s',
        `last_update`=UNIX_TIMESTAMP()".$AND.",
        `notified`='N',
@@ -297,7 +348,7 @@ LIMIT 1",
                                }
 
                                // Did something change?
-                               if (SQL_AFFECTEDROWS() == 1) {
+                               if (!ifSqlHasZeroAffectedRows()) {
                                        // Get all modes ...
                                        $modes = explode(';', $mode);
 
@@ -305,25 +356,25 @@ LIMIT 1",
                                        sendModeMails ('mydata', $modes);
                                } else {
                                        // Something went wrong
-                                       loadTemplate('admin_settings_saved', false, getMessage('MEMBER_UPDATE_FAILED'));
+                                       displayMessage('{--MEMBER_UPDATE_FAILED--}');
                                }
                        } else {
                                // Entered wrong pass for updating profile
-                               loadTemplate('admin_settings_saved', false, getMessage('MEBER_UPDATE_PWD_WRONG'));
+                               displayMessage('{--MEMBER_UPDATE_WRONG_PASSWORD--}');
                        }
                }
                break;
 
        case 'notify': // Switch off notfication
-               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `notified`='N', `last_update`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1",
+               sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `notified`='N',`last_update`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1",
                        array(getMemberId()), __FILE__, __LINE__);
-               $URL = 'modules.php?module=login&amp;what=welcome&amp;code=' . urlencode(getMessage('PROFILE_UPDATED'));
+               $url = 'modules.php?module=login&amp;what=mydata&amp;code=' . getCode('PROFILE_UPDATED');
                break;
 } // END - switch
 
-if (!empty($URL)) {
+if (!empty($url)) {
        // Load generated URL
-       redirectToUrl($URL);
+       redirectToUrl($url);
 } // END - if
 
 // [EOF]