Sponsorenverwaltung - Team StarCraft e.V.
 All Data Structures Files Functions Variables
sponsors_deleted.php
Go to the documentation of this file.
1 <?php
2  /**
3  * @file sponsors_deleted.php
4  *
5  * @brief This file handles the permanent deletion of sponsors and sponsorcars
6  *
7  * @details
8  * This script presents a view of all deleted sponsors in the backup-tables as well
9  * as an overview of still existing sponsor were some sponsorcars were deleted.
10  * The root-user/main-administrator has the posibility to clear those backups
11  * from the corresponding tables.
12  *
13  * This file needs the template templates/sponsors_deleted.tpl to be present to work.
14  * Furthermore it needs the common.php and the functions_sponsoring.php in the
15  * directory /inc to work properly. To get to know more about their dependencies
16  * check the description of the corresponding files.
17  *
18  * This file can handle the following inputs:
19  * - $_GET: tab [ 1 | 2 ] to determine which view the user came from
20  * - $_POST: action and actionCars as POST-arrays with the sponsorcar ids as keys
21  * and the actions as values [ 0 -> do nothing | 1 -> restore (not implemented) |
22  * 2 -> delete]
23  * For more detailed informations please consider studying the sponsors_deleted.tpl.
24  *
25  * This file depends on inc/common.php and inc/templates/sponsors_deleted.tpl.
26  *
27  * @copyright (c) 2013, Team StarCraft e.V.
28  * @version 1.0.0
29  * @author Alexander Vorndran
30  * @author Daniel Seichter
31  * @author Florian Wirthmüller
32  * @date 02.07.2013
33  */
34 
35  //! constant for doing nothing on the data also used in sponsors_deleted.tpl
36  define('ACTION_NOTHING',0);
37 
38  //! constant for doing restore operation on the data also used in sponsors_deleted.tpl
39  define('ACTION_RESTORE',1);
40 
41  //! constant for doing delete operation on the data also used in sponsors_deleted.tpl
42  define('ACTION_DELETE', 2);
43 
44  /// @cond MAINPART
45  // include
46  include("inc/common.php");
47 
48 
49  // Usercake
50  if(!accessGranted($_SERVER['PHP_SELF'])) {
51  if (isUserLoggedIn()) {
52  exitWithErrorTemplate(array('Die angeforderte Seite ist gesperrt.'));
53  }
54  else {
55  exitWithErrorTemplateAndRedirect(array('Die angeforderte Seite ist gesperrt oder geschützt.'), 'login.php', 2);
56  }
57  }
58 
59 
60  // only allow access if the user is root-user/main-administrator
61  if(isUserRoot()) {
62 
63  // send the user back to the section he came from
64  if(!empty($_GET['tab']) && is_numeric($_GET['tab'])) {
65  $tab = ($_GET['tab']==2)? 2 : 1;
66  $smarty->assign('selectedTab',$tab);
67  } else {
68  // if there are no infos available send him to the deleted sponsor view
69  $smarty->assign('selectedTab',1);
70  }
71 
72  if(!empty($_POST)) {
73  // the user has marked some sponsors to be restored
74  if(!empty($_POST['action'])) {
75  $actions = $_POST['action'];
76  if(is_array($actions)) {
77  $deletions = 0;
78  foreach ($actions as $sponsorId => $action) {
79  switch ($action) {
80  case ACTION_DELETE:
81  // the user wants to delete a sponsor permanently
82  if(($deletions += deleteSponsorPermanently($sponsorId))===FALSE) {
83  exitWithErrorTemplateAndRedirect(array('Löschen fehlgeschlagen'), "sponsors_deleted.php?sort=1&dir=0", 2);
84  } else {
85  $successes[] = 'Die ausgewählten Sponsoren-Backup-Einträge wurden entfernt.';
86  }
87  break;
88  case ACTION_RESTORE:
89  break;
90  case ACTION_NOTHING:
91  default:
92  break;
93  }
94  }
95  }
96  }
97 
98  if(!empty($_POST['actionCars'])) {
99  $actions = $_POST['actionCars'];
100  if(is_array($actions)) {
101  $deletions = 0;
102  foreach ($actions as $carId => $action) {
103  switch ($action) {
104  case ACTION_DELETE:
105  // the user wants to delete a sponsorcar permanently
106  if(($deletions += deleteSponsorCarPermanently(NULL, $carId))===FALSE) {
107  exitWithErrorTemplateAndRedirect(array('Löschen fehlgeschlagen'), "sponsors_deleted.php?sort=1&dir=0", 2);
108  } else {
109  $successes[] = 'Die ausgewählten Sponsorenfahrzeug-Backup-Einträge wurden entfernt.';
110  }
111  break;
112  case ACTION_RESTORE:
113  break;
114  case ACTION_NOTHING:
115  default:
116  break;
117  }
118  }
119  }
120  }
121  }
122 
123  // fetch a list of all deleted sponsors
124  $deletedSponsors = fetchAllDeletedSponsors();
125 
126  // fetch a list of all sponsors with deleted cars
127  $sponsorsWithDeletedCars = fetchAllSponsorsWithDeletedCars();
128  if(!empty($sponsorsWithDeletedCars)) {
129  foreach ($sponsorsWithDeletedCars as &$sponsorWithDeletedCars) {
130  $sponsorWithDeletedCars['cars'] = fetchDeletedSponsorCars($sponsorWithDeletedCars['id'],TRUE);
131  }
132 
133  }
134 
135  // assign it to smarty
136  $smarty->assign('deletedSponsors',$deletedSponsors);
137  $smarty->assign('sponsorsWithDeletedCars',$sponsorsWithDeletedCars);
138 
139  displayTemplateWithErrorsAndSuccesses("Verwaltung gelöschter Daten", 'sponsors_deleted.tpl');
140  } else {
141  exitWithErrorTemplateAndRedirect(array('Kein Zugriff!'), "home.php", 2);
142  }
143  /// @endcond
144 ?>