source: extensions/NBC_UserAdvManager/trunk/include/functions_UserAdvManager.inc.php @ 3826

Last change on this file since 3826 was 3826, checked in by Eric, 15 years ago
  • Code cleaning : Deletion of old commented parts, PHP 5.3 improvement, HTML compliant for tpl files
  • Implementing a monitoring system for using the mail() function (spy log file)
  • Finalization of listing table of unvalidated registered
  • Preview of upcoming features (coding of management panel)
  • Property svn:eol-style set to LF
File size: 9.0 KB
Line 
1<?php
2include_once (NBC_UserAdvManager_PATH.'include/constants.php');
3load_language('plugin.lang', NBC_UserAdvManager_PATH);
4
5function SendMail2User($typemail, $id, $username, $password, $email, $confirm)
6{
7  global $conf;
8  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
9  include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
10  $infos1_perso = "";
11  $infos2_perso = "";
12
13  switch($typemail)
14  {
15    case 1:
16      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Add of %s', $username));
17      $password = $password <> '' ? $password : l10n('UserAdvManager_empty_pwd');
18     
19      if ( function_exists('get_user_language_desc') and isset($conf_nbc_UserAdvManager[10]) and $conf_nbc_UserAdvManager[10] <> '' )
20        $infos1_perso = get_user_language_desc($conf_nbc_UserAdvManager[10])."\n\n";
21     
22      break;
23     
24    case 2:
25      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', $username));
26      $password = $password <> '' ? $password : l10n('UserAdvManager_empty_pwd');
27
28      break;
29       
30    case 3:
31      $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Update of %s', $username));
32      $password = $password <> '' ? $password : l10n('UserAdvManager_no_update_pwd');
33
34      break;
35  }
36
37  if ( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true' )
38  {
39    $infos1 = array(
40      get_l10n_args('infos_mail %s', $username),
41      get_l10n_args('User: %s', $username),
42      get_l10n_args('Password: %s', $password),
43      get_l10n_args('Email: %s', $email),
44      get_l10n_args('', ''),
45    );
46  }
47
48
49  if ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true' and $confirm)
50  {
51    $infos2 = array
52    (
53      get_l10n_args('Link: %s', AddConfirmMail($id, $email)),
54      get_l10n_args('', ''),
55    );
56
57    if ( function_exists('get_user_language_desc') and isset($conf_nbc_UserAdvManager[11]) and $conf_nbc_UserAdvManager[11] <> '' )
58      $infos2_perso = get_user_language_desc($conf_nbc_UserAdvManager[11])."\n\n";
59  }
60
61  pwg_mail($email, array(
62    'subject' => $subject,
63    'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(),
64  ));
65
66/* ********************** */
67/* Email sending debugger */
68/* This is only to trace  */
69/* the send of emails for */
70/* debugging              */
71/* ********************** */ 
72  MailLog($email,$subject);
73/* ********************** */
74
75}
76
77/* Email sending debugger function */
78function MailLog  ($to, $subject)
79{
80   $fo=fopen (NBC_UserAdvManager_PATH.'admin/maillog.txt','a') ;
81   fwrite($fo,"======================\n") ;
82   fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n");
83   fwrite($fo,$to . "\n" . $subject . "\r\n") ;
84   fclose($fo) ;
85   //return mail ($to,$subject) ;
86}
87
88
89function FindAvailableConfirmMailID()
90{
91  while (true)
92  {
93    $id = generate_key(16);
94    $query = "
95      SELECT COUNT(*)
96      FROM ".USER_CONFIRM_MAIL_TABLE."
97      WHERE id = '".$id."'
98    ;";
99    list($count) = mysql_fetch_row(pwg_query($query));
100
101    if ($count == 0)
102      return $id;
103  }
104}
105
106
107
108function AddConfirmMail($user_id, $email)
109{
110  global $conf;
111  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
112  $Confirm_Mail_ID = FindAvailableConfirmMailID();
113
114  list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
115 
116  if ( isset($Confirm_Mail_ID) )
117  {
118    $query = "
119      SELECT status
120      FROM ".USER_INFOS_TABLE."
121      WHERE user_id = '".$user_id."'
122    ;";
123    list($status) = mysql_fetch_row(pwg_query($query));
124   
125    $query = "
126      INSERT INTO ".USER_CONFIRM_MAIL_TABLE."
127      (id, user_id, mail_address, status, date_check)
128      VALUES
129      ('".$Confirm_Mail_ID."', '".$user_id."', '".$email."', '".$status."', null)
130    ;";
131    pwg_query($query);
132
133    $query = "
134      DELETE FROM ".USER_GROUP_TABLE."
135      WHERE user_id = '".$user_id."'
136      AND (
137        group_id = '".$conf_nbc_UserAdvManager[3]."'
138        OR
139        group_id = '".$conf_nbc_UserAdvManager[4]."'
140      )
141    ;";
142    pwg_query($query);
143
144    if ( !is_admin() and $conf_nbc_UserAdvManager[9] <> -1 )
145    {
146      $query = "
147        UPDATE ".USER_INFOS_TABLE."
148        SET status = '".$conf_nbc_UserAdvManager[9]."'
149        WHERE user_id = '".$user_id."'
150      ;";
151      pwg_query($query);
152    }
153
154    if ( $conf_nbc_UserAdvManager[3] <> -1 )
155    {
156      $query = "
157        INSERT INTO ".USER_GROUP_TABLE."
158        (user_id, group_id)
159        VALUES
160        ('".$user_id."', '".$conf_nbc_UserAdvManager[3]."')
161      ;";
162      pwg_query($query);
163    }
164   
165    return get_absolute_root_url().NBC_UserAdvManager_PATH.'ConfirmMail.php?key='.$Confirm_Mail_ID;
166  }
167}
168
169
170
171function DeleteConfirmMail($user_id)
172{
173  $query = "
174    DELETE FROM ".USER_CONFIRM_MAIL_TABLE."
175    WHERE user_id = '".$user_id."'
176  ;";
177  pwg_query($query);
178}
179
180
181
182function VerifyConfirmMail($id)
183{
184  global $conf;
185
186  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
187 
188  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
189
190  $query = "
191    SELECT COUNT(*)
192    FROM ".USER_CONFIRM_MAIL_TABLE."
193    WHERE id = '".$id."'
194  ;";
195  list($count) = mysql_fetch_row(pwg_query($query));
196
197  if ($count == 1)
198  {
199    $query = "
200      SELECT user_id, status, date_check
201      FROM ".USER_CONFIRM_MAIL_TABLE."
202      WHERE id = '".$id."'
203    ;";
204    $data = mysql_fetch_array(pwg_query($query));
205   
206   
207    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
208    {
209      $query = "
210        SELECT registration_date
211        FROM ".USER_INFOS_TABLE."
212        WHERE user_id = '".$data['user_id']."'
213      ;";
214      list($registration_date) = mysql_fetch_row(pwg_query($query));
215 
216      if (!empty($registration_date))
217      {
218// Time limit process
219      }
220     
221      list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
222 
223      $query = '
224        UPDATE '.USER_CONFIRM_MAIL_TABLE.'
225        SET date_check="'.$dbnow.'"
226        WHERE id = "'.$id.'"
227      ;';
228      pwg_query($query);
229     
230      if ( $conf_nbc_UserAdvManager[3] <> -1 )
231      {
232        $query = "
233          DELETE FROM ".USER_GROUP_TABLE."
234          WHERE user_id = '".$data['user_id']."'
235          AND group_id = '".$conf_nbc_UserAdvManager[3]."'
236        ;";
237        pwg_query($query);
238      }
239   
240      if ( $conf_nbc_UserAdvManager[4] <> -1 )
241      {
242        $query = "
243          DELETE FROM ".USER_GROUP_TABLE."
244          WHERE user_id = '".$data['user_id']."'
245          AND group_id = '".$conf_nbc_UserAdvManager[4]."'
246        ;";
247        pwg_query($query);
248
249        $query = "
250          INSERT INTO ".USER_GROUP_TABLE."
251          (user_id, group_id)
252          VALUES
253          ('".$data['user_id']."', '".$conf_nbc_UserAdvManager[4]."')
254        ;";
255        pwg_query($query);
256      }
257
258      if ( ( $conf_nbc_UserAdvManager[5] <> -1 or isset($data['status']) ) )
259      {
260        $query = "
261          UPDATE ".USER_INFOS_TABLE."
262          SET status = '".(isset($data['status']) ? $data['status'] : $conf_nbc_UserAdvManager[5])."'
263          WHERE user_id = '".$data['user_id']."'
264        ;";
265        pwg_query($query);
266      }
267// Refresh user's category cache
268      invalidate_user_cache();
269 
270      return true;
271    }
272  }
273  else
274    return false;
275 
276}
277
278function NotSensibleSearchUsername($username)
279{
280  global $conf;
281 
282  if ( isset($username) )
283  {
284    $query = "
285      SELECT ".$conf['user_fields']['username']."
286      FROM ".USERS_TABLE."
287      WHERE LOWER(".$conf['user_fields']['username'].") = '".strtolower($username)."'
288    ;";
289    list($username) = mysql_fetch_row(pwg_query($query));
290
291    return isset($username) ? $username : '';
292  }
293}
294
295function SearchMail($email)
296{
297  global $conf, $lang;
298 
299  if ( isset($email) )
300  {
301    $query = "
302      SELECT COUNT(*)
303      FROM ".USERS_TABLE."
304      WHERE ".$conf['user_fields']['email']." = '".$email."'
305    ;";
306    list($nbr_mail) = mysql_fetch_row(pwg_query($query));
307 
308    return isset($nbr_mail) ? $nbr_mail : 0;
309  }
310}
311
312function ValidateUsername($login)
313{
314  global $conf;
315
316  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
317
318  if ( isset($login) and isset($conf_nbc_UserAdvManager[8]) and $conf_nbc_UserAdvManager[8] <> '' )
319  {
320        $pattern = '/'.$conf_nbc_UserAdvManager[8].'/';
321    if ( preg_match($pattern, $login) )
322      return false;
323    else
324      return true;
325  }
326  else
327  {
328    return true;
329  }
330}
331
332
333function ValidateEmailProvider($email)
334{
335  global $conf;
336
337        $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
338        if (isset($conf_nbc_UserAdvManager[12]))
339        {
340                $ncsemail = strtolower($email);
341                $conf_nbc_MailExclusion = preg_split('/,/',$conf_nbc_UserAdvManager[13]);
342                for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
343                        {
344                                $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
345                                if (preg_match($pattern, $ncsemail))
346                                        return false;
347                                else
348                                        return true;
349                        }
350        }
351}
352?>
Note: See TracBrowser for help on using the repository browser.