source: extensions/Prune_History/admin/PH_admin.php @ 24623

Last change on this file since 24623 was 21100, checked in by Eric, 12 years ago

Next version will be 1.1.0 :

  • Compliance with Piwigo 2.5
  • Code refactory : Change config variables to assoc array and $_POST vars control before writing conf in database - Thx to flop25 for his advices ;-)
  • Bug fixed : Unable to restore an history backup file
  • Property svn:eol-style set to LF
File size: 6.1 KB
Line 
1<?php
2
3global $lang, $conf, $errors;
4
5if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
6// +-----------------------------------------------------------------------+
7// | Check Access and exit when user status is not ok                      |
8// +-----------------------------------------------------------------------+
9check_status(ACCESS_ADMINISTRATOR);
10
11if(!defined('PH_PATH'))
12{
13  define('PH_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
14}
15
16load_language('plugin.lang', PH_PATH);
17
18$page['global'] = array();
19$range = array();
20$dump_download = '';
21
22
23// +-------------------------------------------------------------------+
24// |                      Get plugin version and name                  |
25// +-------------------------------------------------------------------+
26$plugin =  PHInfos(PH_PATH);
27$version = $plugin['version'];
28$name = $plugin['name'];
29
30
31// +-----------------------------------------------------------------------+
32// |                      Saving new configuration                         |
33// +-----------------------------------------------------------------------+
34if (isset($_POST['submit']) and isset($_POST['PH_AutoPrune']) and isset($_POST['PH_Range_Value']) and isset($_POST['PH_Range']))
35{
36
37  $newconf_PH['PHVersion'] = $version;
38  $newconf_PH['AUTOPRUNE'] = (isset($_POST['PH_AutoPrune']) ? $_POST['PH_AutoPrune'] : 'false');
39  $newconf_PH['RANGEVALUE'] = (isset($_POST['PH_Range_Value']) ? $_POST['PH_Range_Value'] : '0');
40  $newconf_PH['RANGE'] = (isset($_POST['PH_Range']) ? $_POST['PH_Range'] : '0');
41
42  $conf['PruneHistory'] = serialize($newconf_PH);
43
44  conf_update_param('PruneHistory', pwg_db_real_escape_string($conf['PruneHistory']));
45
46  array_push($page['infos'], l10n('PH_save_config'));
47}
48
49
50// +--------------------------------------------------------------------+
51// |                     Saving history tables                          |
52// +--------------------------------------------------------------------+
53if (isset($_POST['save']))
54{
55  $dump_download = (isset($_POST['dump_download'])) ? 'true' : 'false';
56   
57  if(PH_dump($dump_download) and $dump_download == 'false')
58  {
59    array_push($page['infos'], l10n('PH_Dump_OK'));
60  }
61  else
62  {
63    array_push($page['errors'], l10n('PH_Dump_NOK'));
64  }
65}
66
67
68// +--------------------------------------------------------------------+
69// |             Restoring backed up history tables                     |
70// +--------------------------------------------------------------------+
71if (isset($_POST['restore']))
72{
73  $Backup_File = PH_PATH.'/include/backup/PH_Historybackup.sql';
74
75  if (file_exists($Backup_File) and $file = file($Backup_File, FILE_IGNORE_NEW_LINES) and !empty($file))
76  {
77    // Check backup file version
78    // -------------------------
79    if ($file[0] == "-- ".$version." --")
80    {
81      $restore = PH_Restore_backup_file();
82      if(empty($restore))
83      {
84        array_push($page['infos'], l10n('PH_Restoration_OK'));
85      }
86      else
87      {
88        array_push($page['errors'], l10n('PH_Restoration_NOK'));
89      }
90    }
91    else array_push($page['errors'], l10n('PH_Bad_version_backup'));
92  }
93  else
94  {
95    array_push($page['errors'], l10n('PH_No_Backup_File'));
96  }
97}
98
99
100// +--------------------------------------------------------------------+
101// |                      Manual prune settings                         |
102// +--------------------------------------------------------------------+
103$conf_PH = unserialize($conf['PruneHistory']);
104
105// Manual prune
106if (isset($_POST['prune']))
107{
108  // Starting range date
109  if (!empty($_POST['start_year']))
110  {
111    $range['date-after'] = sprintf(
112      '%d-%02d-%02d',
113      $_POST['start_year'],
114      $_POST['start_month'],
115      $_POST['start_day']
116      );
117  }
118
119  // Ending range date
120  if (!empty($_POST['end_year']))
121  {
122    $range['date-before'] = sprintf(
123      '%d-%02d-%02d',
124      $_POST['end_year'],
125      $_POST['end_month'],
126      $_POST['end_day']
127      );
128  }
129
130  // Prune action on ranged dates
131  if (history_prune($range['date-after'],$range['date-before']))
132  {
133    array_push($page['infos'], l10n('PH_Prune_Done')); 
134  }
135  else array_push($page['errors'], l10n('PH_Prune_Error'));
136}
137else
138{
139  // by default, the selected date have to be the current date
140  $_POST['start_year']  = $_POST['end_year']  = date('Y');
141  $_POST['start_month'] = $_POST['end_month'] = date('n');
142  $_POST['start_day']   = $_POST['end_day']   = date('j');
143}
144
145
146// +-----------------------------------------------------------------------+
147// |                           templates init                              |
148// +-----------------------------------------------------------------------+
149$month_list = $lang['month'];
150$month_list[0]='------------';
151ksort($month_list);
152
153$range_list = $lang['range'];
154$range_list[0]='------------';
155ksort($range_list);
156
157$template->assign(
158  array(
159    'PH_PATH'                    => PH_PATH,
160    'PWG_ROOT_PATH'              => PHPWG_ROOT_PATH,
161    'PH_NAME'                    => $name,
162    'PH_VERSION'                 => $version,
163    'PH_DUMP_DOWNLOAD'           => $dump_download,
164                'PH_AUTOPRUNE_TRUE'          => $conf_PH['AUTOPRUNE']=='true' ? 'checked="checked"' : '' ,
165                'PH_AUTOPRUNE_FALSE'         => $conf_PH['AUTOPRUNE']=='false' ? 'checked="checked"' : '' ,
166    'PH_RANGE_VALUE'             => $conf_PH['RANGEVALUE'],
167    'PH_RANGE_SELECTED'          => $conf_PH['RANGE'],
168    'range_list'                 => $range_list,
169    'month_list'                 => $month_list,
170    'START_DAY_SELECTED'         => @$_POST['start_day'],
171    'START_MONTH_SELECTED'       => @$_POST['start_month'],
172    'START_YEAR'                 => @$_POST['start_year'],
173    'END_DAY_SELECTED'           => @$_POST['end_day'],
174    'END_MONTH_SELECTED'         => @$_POST['end_month'],
175    'END_YEAR'                   => @$_POST['end_year'],
176  )
177);
178
179
180// +-----------------------------------------------------------------------+
181// |                           templates display                           |
182// +-----------------------------------------------------------------------+
183$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/PH_admin.tpl');
184$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
185?>
Note: See TracBrowser for help on using the repository browser.