source: trunk/include/functions_notification.inc.php @ 1070

Last change on this file since 1070 was 1070, checked in by rub, 18 years ago

Step 1 improvement issue 0000301:

o Change status of table #_user_infos
o Don't send password to webmaster, guest, generic

Next Step:

o Functions Check of status
o Restricted Access for user generic

File size: 6.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-11-26 21:15:50 +0100 (sam., 26 nov. 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 958 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28
29/**
30 * Extract news fonctions of feed.php
31 */
32
33// +-----------------------------------------------------------------------+
34// |                               functions                               |
35// +-----------------------------------------------------------------------+
36
37/**
38 * new comments between two dates, according to authorized categories
39 *
40 * @param string start (mysql datetime format)
41 * @param string end (mysql datetime format)
42 * @param string forbidden categories (comma separated)
43 * @return array comment ids
44 */
45function new_comments($start, $end)
46{
47  global $user;
48 
49  $query = '
50SELECT DISTINCT c.id AS comment_id
51  FROM '.COMMENTS_TABLE.' AS c
52     , '.IMAGE_CATEGORY_TABLE.' AS ic
53  WHERE c.image_id = ic.image_id
54    AND c.validation_date > \''.$start.'\'
55    AND c.validation_date <= \''.$end.'\'
56    AND category_id NOT IN ('.$user['forbidden_categories'].')
57;';
58  return array_from_query($query, 'comment_id');
59}
60
61/**
62 * unvalidated at a precise date
63 *
64 * Comments that are registered and not validated yet on a precise date
65 *
66 * @param string date (mysql datetime format)
67 * @return array comment ids
68 */
69function unvalidated_comments($date)
70{
71  $query = '
72SELECT DISTINCT id
73  FROM '.COMMENTS_TABLE.'
74  WHERE date <= \''.$date.'\'
75    AND (validated = \'false\'
76         OR validation_date > \''.$date.'\')
77;';
78  return array_from_query($query, 'id');
79}
80
81/**
82 * new elements between two dates, according to authorized categories
83 *
84 * @param string start (mysql datetime format)
85 * @param string end (mysql datetime format)
86 * @param string forbidden categories (comma separated)
87 * @return array element ids
88 */
89function new_elements($start, $end)
90{
91  global $user;
92 
93  $query = '
94SELECT DISTINCT image_id
95  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
96  WHERE date_available > \''.$start.'\'
97    AND date_available <= \''.$end.'\'
98    AND category_id NOT IN ('.$user['forbidden_categories'].')
99;';
100  return array_from_query($query, 'image_id');
101}
102
103/**
104 * updated categories between two dates, according to authorized categories
105 *
106 * @param string start (mysql datetime format)
107 * @param string end (mysql datetime format)
108 * @param string forbidden categories (comma separated)
109 * @return array element ids
110 */
111function updated_categories($start, $end)
112{
113  global $user;
114 
115  $query = '
116SELECT DISTINCT category_id
117  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
118  WHERE date_available > \''.$start.'\'
119    AND date_available <= \''.$end.'\'
120    AND category_id NOT IN ('.$user['forbidden_categories'].')
121;';
122  return array_from_query($query, 'category_id');
123}
124
125/**
126 * new registered users between two dates
127 *
128 * @param string start (mysql datetime format)
129 * @param string end (mysql datetime format)
130 * @return array user ids
131 */
132function new_users($start, $end)
133{
134  $query = '
135SELECT user_id
136  FROM '.USER_INFOS_TABLE.'
137  WHERE registration_date > \''.$start.'\'
138    AND registration_date <= \''.$end.'\'
139;';
140  return array_from_query($query, 'user_id');
141}
142
143/**
144 * currently waiting pictures
145 *
146 * @return array waiting ids
147 */
148function waiting_elements()
149{
150  $query = '
151SELECT id
152  FROM '.WAITING_TABLE.'
153  WHERE validated = \'false\'
154;';
155
156  return array_from_query($query, 'id');
157}
158
159/**
160 * What's new between two dates ?
161 *
162 * Informations : number of new comments, number of new elements, number of
163 * updated categories. Administrators are also informed about : number of
164 * unvalidated comments, number of new users (TODO : number of unvalidated
165 * elements)
166 *
167 * @param string start date (mysql datetime format)
168 * @param string end date (mysql datetime format)
169 */
170function news($start, $end)
171{
172  global $user;
173
174  $news = array();
175 
176  $nb_new_comments = count(new_comments($start, $end));
177  if ($nb_new_comments > 0)
178  {
179    array_push($news, sprintf(l10n('%d new comments'), $nb_new_comments));
180  }
181
182  $nb_new_elements = count(new_elements($start, $end));
183  if ($nb_new_elements > 0)
184  {
185    array_push($news, sprintf(l10n('%d new elements'), $nb_new_elements));
186  }
187
188  $nb_updated_categories = count(updated_categories($start, $end));
189  if ($nb_updated_categories > 0)
190  {
191    array_push($news, sprintf(l10n('%d categories updated'),
192                              $nb_updated_categories));
193  }
194 
195  if (is_admin())
196  {
197    $nb_unvalidated_comments = count(unvalidated_comments($end));
198    if ($nb_unvalidated_comments > 0)
199    {
200      array_push($news, sprintf(l10n('%d comments to validate'),
201                                $nb_unvalidated_comments));
202    }
203
204    $nb_new_users = count(new_users($start, $end));
205    if ($nb_new_users > 0)
206    {
207      array_push($news, sprintf(l10n('%d new users'), $nb_new_users));
208    }
209
210    $nb_waiting_elements = count(waiting_elements());
211    if ($nb_waiting_elements > 0)
212    {
213      array_push(
214        $news,
215        sprintf(
216          l10n('%d waiting elements'),
217          $nb_waiting_elements
218          )
219        );
220    }
221  }
222
223  return $news;
224}
225
226?>
Note: See TracBrowser for help on using the repository browser.