Automad
 All Classes Functions Variables Pages
users.php
1 <?php
2 /*
3  * ....
4  * .: '':.
5  * :::: ':..
6  * ::. ''..
7  * .:'.. ..':.:::' . :. '':.
8  * :. '' '' '. ::::.. ..:
9  * ::::. ..':.. .'''::::: .
10  * :::::::.. '..:::: :. :::: :
11  * ::'':::::::. ':::.'':.:::: :
12  * :.. ''::::::....': '':: :
13  * :::::. '::::: : .. '' .
14  * .''::::::::... ':::.'' ..'' :.''''.
15  * :..:::''::::: :::::...:'' :..:
16  * ::::::. ':::: :::::::: ..:: .
17  * ::::::::.:::: :::::::: :'':.:: .''
18  * ::: '::::::::.' ''::::: :.' '': :
19  * ::: :::::::::..' :::: ::...' .
20  * ::: .:::::::::: :::: :::: .:'
21  * '::' ''::::::: :::: : :: :
22  * ':::: :::: :'' .:
23  * :::: :::: ..''
24  * :::: ..:::: .:''
25  * '''' '''''
26  *
27  *
28  * AUTOMAD
29  *
30  * Copyright (c) 2014 by Marc Anton Dahmen
31  * http://marcdahmen.de
32  *
33  * Licensed under the MIT license.
34  * http://automad.org/license
35  */
36 
37 
38 defined('AUTOMAD') or die('Direct access not permitted!');
39 
40 
41 /*
42  * List of registered users with the option to delete selected.
43  */
44 
45 
46 $output = array();
47 
48 
49 $accounts = $this->accountsGetArray();
50 
51 
52 // Delete selected users.
53 if (isset($_POST['delete'])) {
54 
55  // Only delete users from list, if accounts.txt is writable.
56  // It is important, to verify write access here, to make sure that all accounts stored in account.txt are also returned in the HTML.
57  // Otherwise, they would be deleted from the array without actually being deleted from the file, in case accounts.txt is write protected.
58  // So it is not enough to just check, if file_put_contents was successful, because that would be simply too late.
59  if (is_writable(AM_FILE_ACCOUNTS)) {
60 
61  $deleted = array();
62 
63  foreach ($_POST['delete'] as $userToDelete) {
64 
65  if (isset($accounts[$userToDelete])) {
66 
67  unset($accounts[$userToDelete]);
68  $deleted[] = $userToDelete;
69 
70  }
71 
72  }
73 
74  // Write array with all accounts back to file.
75  if ($this->accountsSaveArray($accounts)) {
76  $output['success'] = $this->tb['success_remove'] . ' <strong>' . implode(', ', $deleted) . '</strong>';
77  }
78 
79  } else {
80 
81  $output['error'] = $this->tb['error_permission'] . '<p>' . AM_FILE_ACCOUNTS . '</p>';
82 
83  }
84 
85 }
86 
87 
88 ob_start();
89 
90 
91 ?>
92 
93  <div class="modal-body">
94  <?php foreach ($accounts as $user => $hash) { ?>
95  <div class="box">
96  <div class="row">
97  <div class="col-xs-10"><h4><span class="glyphicon glyphicon-user"></span> <?php echo $user; ?></h4></div>
98  <div class="col-xs-2">
99  <?php if ($user != $this->user()) { ?>
100  <div class="pull-right btn-group" data-toggle="buttons">
101  <label class="btn btn-default btn-xs">
102  <input type="checkbox" name="delete[]" value="<?php echo $user; ?>"><span class="glyphicon glyphicon-ok"></span>
103  </label>
104  </div>
105  <?php } ?>
106  </div>
107  </div>
108  </div>
109  <?php } ?>
110  </div>
111 
112  <div class="modal-footer">
113  <div class="btn-group btn-group-justified">
114  <div class="btn-group">
115  <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> <?php echo $this->tb['btn_close']; ?></button>
116  </div>
117  <div class="btn-group">
118  <button type="submit" class="btn btn-danger" data-loading-text="<?php echo $this->tb['btn_loading']; ?>"><span class="glyphicon glyphicon-trash"></span> <?php echo $this->tb['btn_remove_selected']; ?></button>
119  </div>
120  </div>
121  </div>
122 
123 <?php
124 
125 
126 $output['html'] = ob_get_contents();
127 ob_end_clean();
128 
129 
130 echo json_encode($output);
131 
132 
133 ?>