Ignore:
Timestamp:
Sep 17, 2009, 9:41:40 PM (15 years ago)
Author:
Eric
Message:

2.11 branch finalization :

  • Code cleaning
  • Templates improvement
  • Language files updates
  • Plugin history and version set
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/NBC_UserAdvManager/trunk/include/functions_UserAdvManager.inc.php

    r3845 r3858  
    33load_language('plugin.lang', NBC_UserAdvManager_PATH);
    44
     5/* Function called from main.inc.php to send validation email */
    56function SendMail2User($typemail, $id, $username, $password, $email, $confirm)
    67{
     
    7273/* debugging              */
    7374/* ********************** */ 
    74   MailLog($email,$subject);
     75//  MailLog($email,$subject);
    7576/* ********************** */
    76 
    77 }
     77}
     78
    7879
    7980/* Email sending debugger function */
    80 function MailLog  ($to, $subject)
    81 {
    82    $fo=fopen (NBC_UserAdvManager_PATH.'admin/maillog.txt','a') ;
    83    fwrite($fo,"======================\n") ;
    84    fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n");
    85    fwrite($fo,$to . "\n" . $subject . "\r\n") ;
    86    fclose($fo) ;
     81//function MailLog  ($to, $subject)
     82//{
     83//   $fo=fopen (NBC_UserAdvManager_PATH.'admin/maillog.txt','a') ;
     84//   fwrite($fo,"======================\n") ;
     85//   fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n");
     86//   fwrite($fo,$to . "\n" . $subject . "\r\n") ;
     87//   fclose($fo) ;
    8788   //return mail ($to,$subject) ;
    88 }
    89 
    90 
     89//}
     90
     91
     92/* Function called from UserAdvManager_admin.php to resend validation email with or without new validation key */
    9193function ResendMail2User($typemail, $user_id, $username, $email, $confirm)
    9294{
     
    137139/* debugging              */
    138140/* ********************** */ 
    139   MailLog($email,$subject);
     141//  MailLog($email,$subject);
    140142/* ********************** */
    141 
    142 }
    143 
    144 
     143}
     144
     145
     146/* Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation */
    145147function FindAvailableConfirmMailID()
    146148{
     
    161163
    162164
    163 
     165/* Function called from functions SendMail2User to process unvalidated users and generate validation key link */
    164166function AddConfirmMail($user_id, $email)
    165167{
     
    170172  list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
    171173 
    172   if ( isset($Confirm_Mail_ID) )
     174  if (isset($Confirm_Mail_ID))
    173175  {
    174176    $query = "
     
    192194      AND (
    193195        group_id = '".$conf_nbc_UserAdvManager[3]."'
    194         OR
     196                        OR
    195197        group_id = '".$conf_nbc_UserAdvManager[4]."'
    196198      )
     
    198200    pwg_query($query);
    199201
    200     if ( !is_admin() and $conf_nbc_UserAdvManager[9] <> -1 )
     202    if (!is_admin() and $conf_nbc_UserAdvManager[9] <> -1)
    201203    {
    202204      $query = "
     
    224226
    225227
     228/* Function called from UserAdvManager_admin.php to reset validation key */
    226229function ResetConfirmMail($user_id)
    227230{
     
    232235  list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
    233236 
    234   if ( isset($Confirm_Mail_ID) )
     237  if (isset($Confirm_Mail_ID))
    235238  {
    236239    $query = "
     
    253256
    254257
     258/* Function called from main.inc.php - Triggered on user deletion */
    255259function DeleteConfirmMail($user_id)
    256260{
     
    263267
    264268
    265 
     269/* Function called from ConfirmMail.php to verify validation key used by user according time limit */
    266270function VerifyConfirmMail($id)
    267271{
     
    302306      if (!empty($registration_date))
    303307      {
    304                 // Verify Confirmmail with time limit ON
    305                 if (isset ($conf_nbc_UserAdvManager_ConfirmMail[1]))
    306                 {
    307                         // dates formating and compare
    308                         $today = date("d-m-Y"); // Get today's date
    309                         list($day, $month, $year) = explode('-', $today); // explode date of today                                               
    310                         $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
     308                                // Verify Confirmmail with time limit ON
     309                                if (isset ($conf_nbc_UserAdvManager_ConfirmMail[1]))
     310                                {
     311                                        // dates formating and compare
     312                                        $today = date("d-m-Y"); // Get today's date
     313                                        list($day, $month, $year) = explode('-', $today); // explode date of today                                               
     314                                        $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp
    311315                       
    312                         list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
    313                         list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
    314                         $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
     316                                list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date
     317                                        list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date
     318                                        $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp
    315319                       
    316                         $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
    317                         $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
    318 
    319                         // Condition with the value set for time limit
    320                         if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the set limit
    321                         {
    322                                 list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
    323 
    324                                 $query = '
    325                                         UPDATE '.USER_CONFIRM_MAIL_TABLE.'
    326                                         SET date_check="'.$dbnow.'"
    327                                         WHERE id = "'.$id.'"
     320                                        $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps     
     321                                        $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days
     322
     323                                        // Condition with the value set for time limit
     324                                        if ($deltadays <= $conf_nbc_UserAdvManager_ConfirmMail[1]) // If Nb of days is less than the limit set
     325                                        {
     326                                                list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
     327
     328                                                $query = '
     329                                                        UPDATE '.USER_CONFIRM_MAIL_TABLE.'
     330                                                        SET date_check="'.$dbnow.'"
     331                                                        WHERE id = "'.$id.'"
     332                                                ;';
     333                                                pwg_query($query);
     334     
     335                                                if ($conf_nbc_UserAdvManager[3] <> -1)
     336                                                {
     337                                                        $query = "
     338                                                                DELETE FROM ".USER_GROUP_TABLE."
     339                                                                WHERE user_id = '".$data['user_id']."'
     340                                                                AND group_id = '".$conf_nbc_UserAdvManager[3]."'
     341                                                        ;";
     342                                                        pwg_query($query);
     343                                                }
     344           
     345                                                if ($conf_nbc_UserAdvManager[4] <> -1) // Change user's group
     346                                                {
     347                                                        $query = "
     348                                                                DELETE FROM ".USER_GROUP_TABLE."
     349                                                                WHERE user_id = '".$data['user_id']."'
     350                                                                AND group_id = '".$conf_nbc_UserAdvManager[4]."'
     351                                                        ;";
     352                                                        pwg_query($query);
     353       
     354                                                        $query = "
     355                                                                INSERT INTO ".USER_GROUP_TABLE."
     356                                                                        (user_id, group_id)
     357                                                                VALUES
     358                                                                        ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
     359                                                                ;";
     360                                                        pwg_query($query);
     361                                                }
     362
     363                                                if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']))) // Change user's status
     364                                                {
     365                                                        $query = "
     366                                                                UPDATE ".USER_INFOS_TABLE."
     367                                                                SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
     368                                                                WHERE user_id = '".$data['user_id']."'
     369                                                        ;";
     370                                                        pwg_query($query);
     371                                                }
     372                                                // Refresh user's category cache
     373                                                invalidate_user_cache();
     374 
     375                                                return true;
     376                                        }
     377                                        elseif ($deltadays > $conf_nbc_UserAdvManager_ConfirmMail[1]) // If timelimit exeeds
     378                                        {
     379                                                return false;
     380                                        }
     381                                }
     382                                // Verify Confirmmail with time limit OFF
     383                                else
     384                                {
     385                                        list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
     386
     387                                        $query = '
     388                                                UPDATE '.USER_CONFIRM_MAIL_TABLE.'
     389                                                SET date_check="'.$dbnow.'"
     390                                                WHERE id = "'.$id.'"
    328391                                        ;';
    329                                 pwg_query($query);
    330      
    331                                 if ( $conf_nbc_UserAdvManager[3] <> -1 )
    332                                 {
    333                                         $query = "
    334                                                 DELETE FROM ".USER_GROUP_TABLE."
    335                                                 WHERE user_id = '".$data['user_id']."'
    336                                                 AND group_id = '".$conf_nbc_UserAdvManager[3]."'
     392                                        pwg_query($query);
     393     
     394                                        if ($conf_nbc_UserAdvManager[3] <> -1)
     395                                        {
     396                                                $query = "
     397                                                        DELETE FROM ".USER_GROUP_TABLE."
     398                                                        WHERE user_id = '".$data['user_id']."'
     399                                                        AND group_id = '".$conf_nbc_UserAdvManager[3]."'
    337400                                                ;";
    338                                         pwg_query($query);
     401                                                pwg_query($query);
     402                                        }
     403   
     404                                        if ($conf_nbc_UserAdvManager[4] <> -1)
     405                                        {
     406                                                $query = "
     407                                                        DELETE FROM ".USER_GROUP_TABLE."
     408                                                        WHERE user_id = '".$data['user_id']."'
     409                                                        AND group_id = '".$conf_nbc_UserAdvManager[4]."'
     410                                                ;";
     411                                                pwg_query($query);
     412
     413                                                $query = "
     414                                                        INSERT INTO ".USER_GROUP_TABLE."
     415                                                                (user_id, group_id)
     416                                                        VALUES
     417                                                                ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
     418                                                ;";
     419                                                pwg_query($query);
     420                                        }
     421
     422                                        if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status'])))
     423                                        {
     424                                                $query = "
     425                                                        UPDATE ".USER_INFOS_TABLE."
     426                                                        SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
     427                                                        WHERE user_id = '".$data['user_id']."'
     428                                                ;";
     429                                                pwg_query($query);
     430                                        }
     431                                        // Refresh user's category cache
     432                                        invalidate_user_cache();
     433 
     434                                        return true;
    339435                                }
    340            
    341                                 if ( $conf_nbc_UserAdvManager[4] <> -1 ) // Change user's group
    342                                 {
    343                                         $query = "
    344                                                 DELETE FROM ".USER_GROUP_TABLE."
    345                                                 WHERE user_id = '".$data['user_id']."'
    346                                                 AND group_id = '".$conf_nbc_UserAdvManager[4]."'
    347                                                 ;";
    348                                         pwg_query($query);
    349        
    350                                         $query = "
    351                                                 INSERT INTO ".USER_GROUP_TABLE."
    352                                                         (user_id, group_id)
    353                                                 VALUES
    354                                                         ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
    355                                                 ;";
    356                                         pwg_query($query);
    357                                 }
    358 
    359                                 if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']))) // Change user's status
    360                                 {
    361                                         $query = "
    362                                                 UPDATE ".USER_INFOS_TABLE."
    363                                                 SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
    364                                                 WHERE user_id = '".$data['user_id']."'
    365                                                 ;";
    366                                         pwg_query($query);
    367                                 }
    368                         // Refresh user's category cache
    369                                 invalidate_user_cache();
    370  
    371                                 return true;
    372                         }
    373                         elseif ($deltadays > $conf_nbc_UserAdvManager_ConfirmMail[1]) // If timelimit exeeds
    374                         {
    375                                 return false;
    376436                        }
    377437                }
    378                 // Verify Confirmmail with time limit OFF
    379                 else
    380                 {
     438        }
     439  else
     440    return false;
     441}
     442
     443/* Function called from UserAdvManager_admin.php to force users validation by admin */
     444function ForceValidation($id)
     445{
     446  global $conf;
     447
     448  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     449 
     450  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
     451       
     452  $query = "
     453    SELECT COUNT(*)
     454    FROM ".USER_CONFIRM_MAIL_TABLE."
     455    WHERE user_id = '".$id."'
     456  ;";
     457  list($count) = mysql_fetch_row(pwg_query($query));
     458
     459  if ($count == 1)
     460  {
     461    $query = "
     462      SELECT user_id, status, date_check
     463      FROM ".USER_CONFIRM_MAIL_TABLE."
     464      WHERE user_id = '".$id."'
     465    ;";
     466    $data = mysql_fetch_array(pwg_query($query));
     467
     468    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
     469    {     
    381470                        list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
    382471
    383                         $query = '
    384                                 UPDATE '.USER_CONFIRM_MAIL_TABLE.'
    385                                 SET date_check="'.$dbnow.'"
    386                                 WHERE id = "'.$id.'"
    387                                 ;';
     472                        $query = "
     473                                UPDATE ".USER_CONFIRM_MAIL_TABLE."
     474                                SET date_check='".$dbnow."'
     475                                WHERE user_id = '".$data['user_id']."'
     476                        ;";
    388477                        pwg_query($query);
    389       
    390                         if ( $conf_nbc_UserAdvManager[3] <> -1 )
     478             
     479                        if ($conf_nbc_UserAdvManager[3] <> -1)
    391480                        {
    392481                                $query = "
     
    394483                                        WHERE user_id = '".$data['user_id']."'
    395484                                        AND group_id = '".$conf_nbc_UserAdvManager[3]."'
    396                                         ;";
     485                                ;";
    397486                                pwg_query($query);
    398487                        }
    399    
    400                         if ( $conf_nbc_UserAdvManager[4] <> -1 )
     488 
     489                        if ($conf_nbc_UserAdvManager[4] <> -1)
    401490                        {
    402491                                $query = "
     
    404493                                        WHERE user_id = '".$data['user_id']."'
    405494                                        AND group_id = '".$conf_nbc_UserAdvManager[4]."'
    406                                         ;";
     495                                ;";
    407496                                pwg_query($query);
    408 
     497       
    409498                                $query = "
    410499                                        INSERT INTO ".USER_GROUP_TABLE."
     
    412501                                        VALUES
    413502                                                ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
    414                                         ;";
     503                                ;";
    415504                                pwg_query($query);
    416505                        }
    417506
    418                         if ( ( $conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']) ) )
     507                        if (($conf_nbc_UserAdvManager[5] <> -1 or isset($data['status'])))
    419508                        {
    420509                                $query = "
     
    422511                                        SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
    423512                                        WHERE user_id = '".$data['user_id']."'
    424                                         ;";
     513                                ;";
    425514                                pwg_query($query);
    426515                        }
    427 // Refresh user's category cache
     516                        // Refresh user's category cache
    428517                        invalidate_user_cache();
    429  
    430518                        return true;
    431519                }
    432       }
    433     }
    434   }
    435   else
    436     return false;
    437 }
    438 
    439 
     520        }
     521}
     522
     523/* Function called from main.inc.php - Get username case insensitive */
    440524function NotSensibleSearchUsername($username)
    441525{
    442526  global $conf;
    443527 
    444   if ( isset($username) )
     528  if (isset($username))
    445529  {
    446530    $query = "
     
    456540
    457541
     542/* Obsolete function - Check for single email in database */
    458543function SearchMail($email)
    459544{
    460545  global $conf, $lang;
    461546 
    462   if ( isset($email) )
     547  if (isset($email))
    463548  {
    464549    $query = "
     
    473558}
    474559
     560
     561/* Function called from main.inc.php - Check if username matches forbidden caracters */
    475562function ValidateUsername($login)
    476563{
     
    479566  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
    480567
    481   if ( isset($login) and isset($conf_nbc_UserAdvManager[8]) and $conf_nbc_UserAdvManager[8] <> '' )
     568  if (isset($login) and isset($conf_nbc_UserAdvManager[8]) and $conf_nbc_UserAdvManager[8] <> '')
    482569  {
    483570        $pattern = '/'.$conf_nbc_UserAdvManager[8].'/';
     
    494581
    495582
     583/* Obsolete function - Check for no forbidden email provider */
     584/* This don't work on function call */
    496585function ValidateEmailProvider($email)
    497586{
     
    515604
    516605
     606/* Function called from UserAdvManager.php - Get unvalidated users according time limit */
    517607function get_unvalid_user_list()
    518608{
     
    520610         
    521611        /* Get ConfirmMail configuration */
    522     $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
     612        $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
    523613         
    524614        /* Get UserAdvManager configuration */
    525615        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); 
    526616 
    527     $users = array();
     617  $users = array();
    528618   
    529619        /* search users depending expiration date */
    530     $query = '
    531         SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
    532                                                                                         u.'.$conf['user_fields']['username'].' AS username,
    533                       u.'.$conf['user_fields']['email'].' AS email,
    534                       ui.status,
    535                       ui.adviser,
    536                       ui.enabled_high,
    537                       ui.level,
    538                       ui.registration_date,
    539                       ug.group_id
    540                         FROM '.USERS_TABLE.' AS u
    541                         INNER JOIN '.USER_INFOS_TABLE.' AS ui
    542                                 ON u.'.$conf['user_fields']['id'].' = ui.user_id
    543                 INNER JOIN '.USER_GROUP_TABLE.' AS ug
    544         ON u.'.$conf['user_fields']['id'].' = ug.user_id
    545         WHERE u.'.$conf['user_fields']['id'].' >= 0
    546         AND ug.group_id = "'.$conf_nbc_UserAdvManager[3].'"
    547         AND TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'"
    548         ORDER BY id ASC
    549                 ;';
     620  $query = '
     621        SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
     622                                                                                u.'.$conf['user_fields']['username'].' AS username,
     623                    u.'.$conf['user_fields']['email'].' AS email,
     624                    ui.status,
     625                    ui.adviser,
     626                    ui.enabled_high,
     627                    ui.level,
     628                    ui.registration_date,
     629                    ug.group_id
     630                FROM '.USERS_TABLE.' AS u
     631                INNER JOIN '.USER_INFOS_TABLE.' AS ui
     632                        ON u.'.$conf['user_fields']['id'].' = ui.user_id
     633                INNER JOIN '.USER_GROUP_TABLE.' AS ug
     634        ON u.'.$conf['user_fields']['id'].' = ug.user_id
     635        WHERE u.'.$conf['user_fields']['id'].' >= 0
     636        AND ug.group_id = "'.$conf_nbc_UserAdvManager[3].'"
     637      AND TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_nbc_UserAdvManager_ConfirmMail[1].'"
     638                ORDER BY id ASC
     639        ;';
    550640
    551641        $result = pwg_query($query);
    552642     
    553     while ($row = mysql_fetch_array($result))
    554         {
    555         $user = $row;
    556         $user['groups'] = array();
    557 
    558         array_push($users, $user);
     643  while ($row = mysql_fetch_array($result))
     644  {
     645        $user = $row;
     646    $user['groups'] = array();
     647
     648    array_push($users, $user);
    559649        }
    560650
    561651        /* add group lists */
    562     $user_ids = array();
    563     foreach ($users as $i => $user)
    564     {
    565         $user_ids[$i] = $user['id'];
     652  $user_ids = array();
     653  foreach ($users as $i => $user)
     654  {
     655        $user_ids[$i] = $user['id'];
    566656        }
    567657       
    568658        $user_nums = array_flip($user_ids);
    569659
    570     if (count($user_ids) > 0)
    571     {
    572         $query = '
    573                 SELECT user_id, group_id
     660  if (count($user_ids) > 0)
     661  {
     662        $query = '
     663        SELECT user_id, group_id
    574664                        FROM '.USER_GROUP_TABLE.'
    575             WHERE user_id IN ('.implode(',', $user_ids).')
    576             ;';
     665      WHERE user_id IN ('.implode(',', $user_ids).')
     666                ;';
    577667       
    578668                $result = pwg_query($query);
    579669       
    580         while ($row = mysql_fetch_array($result))
    581         {
    582                 array_push(
    583                 $users[$user_nums[$row['user_id']]]['groups'],
    584                 $row['group_id']
    585                 );
    586          }
     670    while ($row = mysql_fetch_array($result))
     671    {
     672        array_push(
     673        $users[$user_nums[$row['user_id']]]['groups'],
     674        $row['group_id']
     675                        );
     676                }
    587677        }
    588678
    589 return $users;
     679        return $users;
    590680}
    591681?>
Note: See TracChangeset for help on using the changeset viewer.