Sponsorenverwaltung - Team StarCraft e.V.
 All Data Structures Files Functions Variables
sites.php
Go to the documentation of this file.
1 <?php
2 
3  /**
4  * @file sites.php
5  *
6  * @brief Script for site-access-controll configuration
7  *
8  * @details
9  * This file provides administrators with the capablities to change the access
10  * level for any site under access controll. This are all pages containing the
11  * if(!accessGranted(...))[...]-check in their source code. New pages in the
12  * root directory are automatically added to the overview if you call this script.
13  *
14  * This file depends on inc/common.php and inc/templates/sites.tpl and inc/tempates/site.tpl.
15  *
16  * @copyright (c) 2013, Team StarCraft e.V.
17  * @version 1.0.0
18  * @author Daniel Seichter
19  * @author Alexander Vorndran
20  * @date 02.07.2013
21  */
22 
23  /// @cond MAINPART
24  // include
25  include("inc/common.php");
26 
27 
28  if(!accessGranted($_SERVER['PHP_SELF'])) {
29  if(isUserLoggedIn()) {
30  exitWithErrorTemplate(array('Die angeforderte Seite ist gesperrt.'));
31  } else {
32  exitWithErrorTemplateAndRedirect(array('Die angeforderte Seite ist gesperrt oder geschützt.'), 'login.php', 2);
33  }
34  };
35 
36 
37  if(isset($_GET['id']) && ctype_digit($_GET['id'])) {
38  if(isUserAdministrator()) {
39  // show details of the selected user
40  if(!pageIdExists($_GET['id'])) {
41  // if the user doesn't exist redirect to the overview page
42  header("Location: sites.php");
43  die();
44  }
45 
46  $pageId = $_GET['id'];
47 
48  // if the form was posted
49  if(!empty($_POST)) {
50  // Fetch page details
51  $pageDetails = fetchPageDetails($pageId);
52  if(isset($_POST['state'])) {
53  $state = trim($_POST['state']);
54  if($state === "lock") {
55  $state = PAGE_LOCK;
56  } else if($state === "public") {
57  $state = PAGE_PUBLIC;
58  } else if($state === "private") {
59  $state = PAGE_PRIVATE;
60  }
61  if($state <> $pageDetails['state']) {
62  if(updatePageState($pageId, $state) > 0) {
63  $successes[] = "Zugriffsrecht erfolgreich geändert.";
64  } else {
65  $errors[] = "Fehler beim Ändern der Zugriffsrechte.";
66  }
67  }
68  }
69  }
70 
71  // Fetch page details
72  $pageDetails = fetchPageDetails($pageId);
73 
74  // Prepare details for display
75  $displayDetails[] = array('desc' => 'Seitentitel', 'value' => $pageDetails['page'], 'readonly' => true);
76 
77  // run template
78  $smarty->assign('pageName', $pageDetails['page']);
79  $smarty->assign('pageId', $pageId);
80  $smarty->assign('displayDetails', $displayDetails);
81  $smarty->assign('state', $pageDetails['state']);
82  displayTemplateWithErrorsAndSuccesses("Seitendetails: '" . $pageDetails['page'] . "'", 'site.tpl');
83  } else {
84  header("Location: sites.php");
85  die();
86  }
87  } else {
88  // Retrieve list of pages in root folder
89  $pages = getPageFiles();
90  // Retrieve list of pages in pages table
91  $dbpages = fetchAllPages();
92  $creations = array();
93  $deletions = array();
94 
95  foreach ($pages as $page) {
96  // Check if any pages exist which are not in DB
97  if(!isset($dbpages[$page])) {
98  $creations[] = $page;
99  }
100  }
101 
102  // Enter new pages in DB if found
103  if(count($creations) > 0) {
104  createPages($creations);
105  }
106 
107  if(count($dbpages) > 0) {
108 
109  foreach ($dbpages as $page) {
110  // Check if DB contains pages that don't exist
111  if(!isset($pages[$page['page']])) {
112  $deletions[] = $page['id'];
113  }
114  }
115  };
116 
117  // Delete pages from DB if not found
118  if(count($deletions) > 0) {
119  deletePages($deletions);
120  }
121 
122  // load pages from the database
123  $dbpages = fetchAllPages();
124  $pageDisplay = array();
125 
126  foreach ($dbpages as $page) {
127 
128  $hasAccess['admin'] = true;
129  if($page['state'] == PAGE_PUBLIC) {
130  $public = true;
131  $hasAccess['user'] = true;
132  } else {
133  $public = false;
134  if($page['state'] == PAGE_PRIVATE) {
135  $hasAccess['user'] = true;
136  } else {
137  $hasAccess['user'] = false;
138  }
139  }
140 
141  if(isUserAdministrator()) {
142  $pageDisplay[] = array('id' => $page['id'], 'name' => $page['page'],
143  'user' => $hasAccess['user'], 'admin' => $hasAccess['admin'],
144  'public' => $public, 'secured' => hasSecurityHeader($page['page']));
145  } else {
146  $pageDisplay[] = array('name' => $page['page'],
147  'user' => $hasAccess['user'], 'public' => $public);
148  }
149  };
150 
151  // run template
152  $smarty->assign('pages', $pageDisplay);
153  displayTemplateWithErrorsAndSuccesses('Seitenübersicht', 'sites.tpl');
154  };
155  /// @endcond
156 ?>