source: trunk/admin/include/c13y_internal.class.php @ 26998

Last change on this file since 26998 was 26461, checked in by mistic100, 10 years ago

Update headers to 2014. Happy new year!!

  • Property svn:eol-style set to LF
File size: 7.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24class c13y_internal
25{
26  function c13y_internal()
27  {
28    add_event_handler('list_check_integrity', array(&$this, 'c13y_version'));
29    add_event_handler('list_check_integrity', array(&$this, 'c13y_exif'));
30    add_event_handler('list_check_integrity', array(&$this, 'c13y_user'));
31  }
32
33  /**
34   * Check version
35   *
36   * @param c13y object
37   * @return void
38   */
39  function c13y_version($c13y)
40  {
41    global $conf;
42
43    $check_list = array();
44
45    $check_list[] = array(
46        'type' => 'PHP',
47        'current' => phpversion(),
48        'required' => REQUIRED_PHP_VERSION,
49        );
50
51    $check_list[] = array(
52        'type' => 'MySQL',
53        'current' => pwg_get_db_version(), 
54        'required' => REQUIRED_MYSQL_VERSION,
55        );
56
57    foreach ($check_list as $elem)
58    {
59      if (version_compare($elem['current'], $elem['required'], '<'))
60      {
61        $c13y->add_anomaly(
62          sprintf(l10n('The version of %s [%s] installed is not compatible with the version required [%s]'), $elem['type'], $elem['current'], $elem['required']),
63          null,
64          null,
65          l10n('You need to upgrade your system to take full advantage of the application else the application will not work correctly, or not at all')
66          .'<br>'.
67          $c13y->get_htlm_links_more_info());
68      }
69    }
70  }
71
72  /**
73   * Check exif
74   *
75   * @param c13y object
76   * @return void
77   */
78  function c13y_exif($c13y)
79  {
80    global $conf;
81
82    foreach (array('show_exif', 'use_exif') as $value)
83    {
84      if (($conf[$value]) and (!function_exists('read_exif_data')))
85      {
86        $c13y->add_anomaly(
87          sprintf(l10n('%s value is not correct file because exif are not supported'), '$conf[\''.$value.'\']'),
88          null,
89          null,
90          sprintf(l10n('%s must be to set to false in your local/config/config.inc.php file'), '$conf[\''.$value.'\']')
91          .'<br>'.
92          $c13y->get_htlm_links_more_info());
93      }
94    }
95  }
96
97  /**
98   * Check user
99   *
100   * @param c13y object
101   * @return void
102   */
103  function c13y_user($c13y)
104  {
105    global $conf;
106
107    $c13y_users = array();
108    $c13y_users[$conf['guest_id']] = array(
109      'status' => 'guest',
110      'l10n_non_existent' => 'Main "guest" user does not exist',
111      'l10n_bad_status' => 'Main "guest" user status is incorrect');
112
113    if ($conf['guest_id'] != $conf['default_user_id'])
114    {
115      $c13y_users[$conf['default_user_id']] = array(
116        'password' => null,
117        'l10n_non_existent' => 'Default user does not exist');
118    }
119
120    $c13y_users[$conf['webmaster_id']] = array(
121      'status' => 'webmaster',
122      'l10n_non_existent' => 'Main "webmaster" user does not exist',
123      'l10n_bad_status' => 'Main "webmaster" user status is incorrect');
124
125      $query = '
126  select u.'.$conf['user_fields']['id'].' as id, ui.status
127  from '.USERS_TABLE.' as u
128    left join '.USER_INFOS_TABLE.' as ui
129        on u.'.$conf['user_fields']['id'].' = ui.user_id
130  where
131    u.'.$conf['user_fields']['id'].' in ('.implode(',', array_keys($c13y_users)).')
132  ;';
133
134
135    $status = array();
136
137    $result = pwg_query($query);
138    while ($row = pwg_db_fetch_assoc($result))
139    {
140      $status[$row['id']] = $row['status'];
141    }
142
143    foreach ($c13y_users as $id => $data)
144    {
145      if (!array_key_exists($id, $status))
146      {
147        $c13y->add_anomaly(l10n($data['l10n_non_existent']), 'c13y_correction_user',
148          array('id' => $id, 'action' => 'creation'));
149      }
150      else
151      if (!empty($data['status']) and $status[$id] != $data['status'])
152      {
153        $c13y->add_anomaly(l10n($data['l10n_bad_status']), 'c13y_correction_user',
154          array('id' => $id, 'action' => 'status'));
155      }
156    }
157  }
158
159  /**
160   * Do correction user
161   *
162   * @param user_id, action
163   * @return boolean true if ok else false
164   */
165  function c13y_correction_user($id, $action)
166  {
167    global $conf, $page;
168
169    $result = false;
170
171    if (!empty($id))
172    {
173      switch ($action)
174      {
175        case 'creation':
176          if ($id == $conf['guest_id'])
177          {
178            $name = 'guest';
179            $password = null;
180          }
181          else if  ($id == $conf['default_user_id'])
182          {
183            $name = 'guest';
184            $password = null;
185          }
186          else if  ($id == $conf['webmaster_id'])
187          {
188            $name = 'webmaster';
189            $password = generate_key(6);
190          }
191
192          if (isset($name))
193          {
194            $name_ok = false;
195            while (!$name_ok)
196            {
197              $name_ok = (get_userid($name) === false);
198              if (!$name_ok)
199              {
200                $name .= generate_key(1);
201              }
202            }
203
204            $inserts = array(
205              array(
206                'id'       => $id,
207                'username' => addslashes($name),
208                'password' => $password
209                ),
210              );
211            mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts);
212
213            create_user_infos($id);
214
215            $page['infos'][] = sprintf(l10n('User "%s" created with "%s" like password'), $name, $password);
216
217            $result = true;
218          }
219          break;
220        case 'status':
221          if ($id == $conf['guest_id'])
222          {
223            $status = 'guest';
224          }
225          else if  ($id == $conf['default_user_id'])
226          {
227            $status = 'guest';
228          }
229          else if  ($id == $conf['webmaster_id'])
230          {
231            $status = 'webmaster';
232          }
233
234          if (isset($status))
235          {
236            $updates = array(
237              array(
238                'user_id' => $id,
239                'status'  => $status
240                ),
241              );
242            mass_updates(USER_INFOS_TABLE,
243              array('primary' => array('user_id'),'update' => array('status')),
244              $updates);
245
246            $page['infos'][] = sprintf(l10n('Status of user "%s" updated'), get_username($id));
247
248            $result = true;
249          }
250          break;
251      }
252    }
253
254    return $result;
255  }
256}
257
258?>
Note: See TracBrowser for help on using the repository browser.