/ui/php/backup/backup_index.php

https://github.com/goldoraf/OBM · PHP · 222 lines · 130 code · 30 blank · 62 comment · 31 complexity · 61b00893ad8a895cc42d4cc519a61d9d MD5 · raw file

  1. <?php
  2. /*
  3. +-------------------------------------------------------------------------+
  4. | Copyright (c) 1997-2009 OBM.org project members team |
  5. | |
  6. | This program is free software; you can redistribute it and/or |
  7. | modify it under the terms of the GNU General Public License |
  8. | as published by the Free Software Foundation; version 2 |
  9. | of the License. |
  10. | |
  11. | This program is distributed in the hope that it will be useful, |
  12. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  13. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  14. | GNU General Public License for more details. |
  15. +-------------------------------------------------------------------------+
  16. | http://www.obm.org |
  17. +-------------------------------------------------------------------------+
  18. */
  19. ?>
  20. <?php
  21. ///////////////////////////////////////////////////////////////////////////////
  22. // OBM - File : backup_index.php //
  23. // - Desc : Backup Index File //
  24. // 2005-08-22 Aliacom - Pierre Baudracco //
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // $Id$
  27. ///////////////////////////////////////////////////////////////////////////////
  28. // Actions -- Parameter
  29. // - index (default) -- search fields -- show the backup list
  30. // - search -- search fields -- show the backup list
  31. // - new -- -- New backup form
  32. // - insert -- -- create a new backup
  33. // - check_delete -- $backup_id -- Check if a backup can be deleted
  34. // - delete -- $backup_id -- Delete a backup (if ok)
  35. // - restore -- $backup_id -- Restore a backup
  36. ///////////////////////////////////////////////////////////////////////////////
  37. $path = '..';
  38. $module = 'backup';
  39. $obminclude = getenv('OBM_INCLUDE_VAR');
  40. if ($obminclude == '') $obminclude = 'obminclude';
  41. include("$obminclude/global.inc");
  42. $params = get_param_backup();
  43. page_open(array('sess' => 'OBM_Session', 'auth' => $auth_class_name, 'perm' => 'OBM_Perm'));
  44. include("$obminclude/global_pref.inc");
  45. require('backup_query.inc');
  46. require('backup_display.inc');
  47. get_backup_action();
  48. $perm->check_permissions($module, $action);
  49. page_close();
  50. ///////////////////////////////////////////////////////////////////////////////
  51. // Main Program //
  52. ///////////////////////////////////////////////////////////////////////////////
  53. // Check that the Backup directory is ok
  54. if (substr($cbackup_root, strlen($cbackup_root)-1 ) != '/') {
  55. $backup_path = $cbackup_root . '/';
  56. } else {
  57. $backup_path = $cbackup_root;
  58. }
  59. if (! file_exists($backup_path)) {
  60. $display['msg'] = display_err_msg($l_err_backup_dir_not_exist);
  61. } else if (! is_writable($backup_path)) {
  62. $display['msg'] = display_err_msg($l_err_backup_dir_not_writable);
  63. } else if ($action == 'index') {
  64. ///////////////////////////////////////////////////////////////////////////////
  65. $display['search'] = dis_backup_search_form($params);
  66. if ($_SESSION['set_display'] == 'yes') {
  67. $display['result'] = dis_backup_search_list($params);
  68. } else {
  69. $display['msg'] .= display_info_msg($l_no_display);
  70. }
  71. } elseif ($action == 'search') {
  72. ///////////////////////////////////////////////////////////////////////////////
  73. $display['search'] = dis_backup_search_form($params);
  74. $display['result'] = dis_backup_search_list($params);
  75. } elseif ($action == 'new') {
  76. ///////////////////////////////////////////////////////////////////////////////
  77. $display['detail'] = dis_backup_form($params);
  78. } elseif ($action == 'insert') {
  79. ///////////////////////////////////////////////////////////////////////////////
  80. $ret = run_query_backup_create();
  81. if ($ret) {
  82. $display['msg'] .= display_ok_msg("$l_backup : $l_insert_ok");
  83. } else {
  84. $display['msg'] .= display_err_msg("$l_backup : $l_insert_error $err[msg]");
  85. }
  86. dis_backup_index();
  87. } elseif ($action == 'restore') {
  88. ///////////////////////////////////////////////////////////////////////////////
  89. $ret = run_query_backup_restore($params['filename']);
  90. if ($ret) {
  91. $display['msg'] .= display_ok_msg("$l_backup : $l_restore_ok");
  92. } else {
  93. $display['msg'] .= display_err_msg("$l_backup : $l_restore_error $err[msg]");
  94. }
  95. dis_backup_index();
  96. } elseif ($action == 'check_delete') {
  97. ///////////////////////////////////////////////////////////////////////////////
  98. if (check_backup_can_delete($params['filename'])) {
  99. $display['msg'] .= display_info_msg($err['msg']);
  100. $display['detail'] = dis_can_delete_backup($params['filename']);
  101. } else {
  102. $display['msg'] .= display_warn_msg($err['msg']);
  103. $display['detail'] = dis_backup_index($params);
  104. }
  105. } elseif ($action == 'delete') {
  106. ///////////////////////////////////////////////////////////////////////////////
  107. if (check_backup_can_delete($params['filename'])) {
  108. $retour = run_query_backup_delete($params['filename']);
  109. if ($retour) {
  110. $display['msg'] .= display_ok_msg("$l_backup : $l_delete_ok");
  111. } else {
  112. $display['msg'] .= display_err_msg("$l_backup : $err[msg] : $l_delete_error");
  113. }
  114. dis_backup_index($params);
  115. } else {
  116. $display['msg'] .= display_warn_msg("$err[msg] $l_cant_delete");
  117. dis_backup_index($params);
  118. }
  119. }
  120. ///////////////////////////////////////////////////////////////////////////////
  121. // Display
  122. ///////////////////////////////////////////////////////////////////////////////
  123. $display['head'] = display_head($l_backup);
  124. if (! $params['popup']) {
  125. $display['header'] = display_menu($module);
  126. }
  127. $display['end'] = display_end();
  128. display_page($display);
  129. ///////////////////////////////////////////////////////////////////////////////
  130. // Stores Backup parameters transmited in $params hash
  131. // returns : $params hash with parameters set
  132. ///////////////////////////////////////////////////////////////////////////////
  133. function get_param_backup() {
  134. // Get global params
  135. $params = get_global_params('Backup');
  136. return $params;
  137. }
  138. ///////////////////////////////////////////////////////////////////////////////
  139. // Backup Action
  140. ///////////////////////////////////////////////////////////////////////////////
  141. function get_backup_action() {
  142. global $$params, $actions, $path;
  143. global $l_header_list, $l_header_find, $l_header_new, $l_header_delete;
  144. global $cright_read, $cright_write, $cright_read_admin, $cright_write_admin;
  145. // Index
  146. $actions['backup']['index'] = array (
  147. 'Name' => $l_header_list,
  148. 'Url' => "$path/backup/backup_index.php?action=index",
  149. 'Right' => $cright_read_admin,
  150. 'Condition'=> array ('all')
  151. );
  152. // Search
  153. $actions['backup']['search'] = array (
  154. 'Url' => "$path/backup/backup_index.php?action=search",
  155. 'Right' => $cright_read_admin,
  156. 'Condition'=> array ('None')
  157. );
  158. // New
  159. $actions['backup']['new'] = array (
  160. 'Name' => $l_header_new,
  161. 'Url' => "$path/backup/backup_index.php?action=new",
  162. 'Right' => $cright_write,
  163. 'Condition'=> array ('search','index','insert','check_delete', 'delete')
  164. );
  165. // CheckDelete
  166. $actions['backup']['check_delete'] = array (
  167. 'Url' => "$path/backup/backup_index.php?action=check_delete&amp;backup_id=".$backup['filename'],
  168. 'Right' => $cright_write,
  169. 'Privacy' => true,
  170. 'Condition'=> array ('None')
  171. );
  172. // Delete
  173. $actions['backup']['delete'] = array (
  174. 'Url' => "$path/backup/backup_index.php?action=delete",
  175. 'Right' => $cright_write,
  176. 'Privacy' => true,
  177. 'Condition'=> array ('None')
  178. );
  179. // Insert
  180. $actions['backup']['insert'] = array (
  181. 'Url' => "$path/backup/backup_index.php?action=insert",
  182. 'Right' => $cright_write,
  183. 'Condition'=> array ('None')
  184. );
  185. // Restore
  186. $actions['backup']['restore'] = array (
  187. 'Url' => "$path/backup/backup_index.php?action=restore",
  188. 'Right' => $cright_write,
  189. 'Condition'=> array ('None')
  190. );
  191. }
  192. ?>