source: branches/2.0/plugins/admin_advices/admin_advices.php @ 2796

Last change on this file since 2796 was 2796, checked in by vdigital, 16 years ago

Error in French advice...

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 Piwigo 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
24add_event_handler('loc_end_page_header', 'set_admin_advice_add_css' );
25// pour faciliter le debug :o)
26ini_set('error_reporting', E_ALL);
27ini_set('display_errors', true);
28// Add a XHTML tag in HEAD section
29function set_admin_advice_add_css()
30{
31  global $template, $page;
32  if ( isset($page['body_id']) and $page['body_id']=='theAdminPage'
33    and $page['page'] == 'intro'
34    )
35  {// This Plugin works only on the Admin page
36    $template->append(
37      'head_elements',
38      '<link rel="stylesheet" type="text/css" '
39                    . 'href="'.PHPWG_PLUGINS_PATH.'admin_advices/default-layout.css">'
40     );
41    add_event_handler('loc_begin_page_tail', 'set_admin_advice' );
42  }
43}
44
45// Build an advice on the Admin Intro page
46function set_admin_advice()
47{
48  global $page, $user, $template, $conf, $prefixeTable, $lang;
49  $my_path = dirname(__FILE__).'/';
50
51//  Include language advices
52  foreach ($conf as $key => $value)
53  {
54    if ( is_string($value) )
55    {
56      $bool = ($value == 'false') ? false : $value;
57      $bool = ($value == 'true') ? true : $bool;
58      $conf[$key] = $bool;
59    }
60  }
61  $adv = array();
62  ini_set('error_reporting', E_ALL);
63  ini_set('display_errors', true);
64
65  include_once( $my_path."adv_set.php" );
66
67  $cases = range(0,count($lang['Adv_case'])-1);
68  srand ((double) microtime() * 10000000);
69  shuffle($cases);
70
71
72  $cond = false; 
73  foreach ($cases as $id)
74  {
75    if (!isset($adv['c'][$id])) $adv['c'][$id] = true;
76    if (!isset($adv['n'][$id])) $adv['c'][$id] = false;
77    if (!isset($lang['Adv_case'][$id])) $adv['c'][$id] = false;
78    $cond = $adv['c'][$id];
79    if ($cond) break;
80  }
81  $confk = $adv['n'][$id];
82  if (substr($confk,0,2) == '**') $confk = substr($confk,2);
83   else $confk = '$conf[' . "'$confk']";
84  $advice_text = (isset($adv['v'][$id])) ? $adv['v'][$id] : '';
85  $more = $lang['Adv_case'][$id];
86
87  $template->set_filenames(array(
88    'admin_advice' => $my_path.'admin_advices.tpl')
89    );
90
91// Mysql status
92  $result = pwg_query('SHOW TABLE STATUS ;');
93  $pwgspacef = $spacef = $pwgsize = $size = 0; 
94  $len = strlen($prefixeTable);
95  $check = array();
96  while ($row = mysql_fetch_array($result))
97  {
98    $size += ($row['Data_length'] + $row['Index_length']);
99    $spacef += $row['Data_free'];
100    if ( substr( $row['Name'], 0, $len ) == $prefixeTable ) { 
101      $pwgsize += ($row['Data_length'] + $row['Index_length']);
102      $pwgspacef += $row['Data_free'];
103      $check[] = (string) $row['Check_time'];
104    }
105  }
106  $size .= ' bytes';
107  $pwgsize .= ' bytes';
108  $spacef .= ' bytes';
109  $pwgspacef .= ' bytes';
110  if ($size > 1024) $size = round($size / 1024, 1) . ' Kb';
111  if ($size > 1024) $size = round($size / 1024, 1) . ' Mb';
112  if ($pwgsize > 1024) $pwgsize = round($pwgsize / 1024, 1) . ' Kb';
113  if ($pwgsize > 1024) $pwgsize = round($pwgsize / 1024, 1) . ' Mb';
114  if ($spacef > 1024) $spacef = round($spacef / 1024, 1) . ' Kb';
115  if ($spacef > 1024) $spacef = round($spacef / 1024, 1) . ' Mb';
116  if ($pwgspacef > 1024) $pwgspacef = round($pwgspacef / 1024, 1) . ' Kb';
117  if ($pwgspacef > 1024) $pwgspacef = round($pwgspacef / 1024, 1) . ' Mb';
118  $check = array_flip(array_flip($check));
119  rsort($check);
120  $end = end($check);
121  $prev = prev($check);
122  $first = $check[0];
123  $checkon = '';
124  if (empty($end)) $end = $prev;
125  if ($end == $first) $checkon .= 'Last table check on: %s';
126  else $checkon .= 'Most recent table check on: %s - oldest: %s';
127  $checkon = sprintf($checkon, $first, $end);
128  $template->assign(
129    array(
130      'prefixTable' => $prefixeTable,
131      'pwgsize' => $pwgsize,
132      'size' => $size,
133      'checked_tables' => $checkon,
134      'pwgspacef' => $pwgspacef,
135      'spacef' => $spacef,
136      'U_maintenance' => get_root_url()
137        . 'admin.php?page=maintenance&amp;action=database',
138      )
139    );
140
141//  If there is an advice
142  if ( $cond )
143  {
144
145// Random Thumbnail
146    $query = '
147SELECT *
148FROM '.IMAGES_TABLE.'
149ORDER BY RAND(NOW())
150LIMIT 0, 1
151;';
152    $result = pwg_query($query);
153    $row = mysql_fetch_assoc($result);
154    if ( is_array($row) )
155    {
156      $url_modify = get_root_url().'admin.php?page=picture_modify'
157                  .'&amp;image_id='.$row['id'];
158      $query = '
159SELECT * FROM '.IMAGE_TAG_TABLE.'
160WHERE image_id =  ' . $row['id'] .'
161;';
162      $tag_count = mysql_num_rows(mysql_query($query));
163      $template->assign('thumbnail',
164         array(
165           'IMAGE'              => get_thumbnail_url($row),
166           'IMAGE_ALT'          => $row['file'],
167           'IMAGE_TITLE'        => $row['name'],
168           'METADATA'           => (empty($row['date_metadata_update'])) ?
169                                   'un' : '',
170           'NAME'               => (empty($row['name'])) ?
171                                   'un' : '',
172           'COMMENT'            => (empty($row['comment'])) ?
173                                   'un' : '',
174           'AUTHOR'             => (empty($row['author'])) ?
175                                   'un' : '',
176           'CREATE_DATE'        => (empty($row['date_creation'])) ?
177                                   'un' : '',
178           'TAGS'               => ($tag_count == 0) ?
179                                   'un' : '',
180           'NUM_TAGS'           => $tag_count,
181           'U_MODIFY'           => $url_modify,
182         )
183       );
184    }
185    //$advice_text = array_shift($adv);
186    $template->assign(
187      array(
188        'ADVICE_ABOUT' => $confk,
189        'ADVICE_TEXT'  => $advice_text,
190         )
191      );
192  $template->assign('More', $more );
193  $template->pparse('admin_advice');
194  } 
195}
196?>
Note: See TracBrowser for help on using the repository browser.