Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
piwik_useradmin.php
Go to the documentation of this file.
1 <?php
2 /*
3  $Id: piwik_userlist.php, author: François Serman <fser>
4  ----------------------------------------------------------------------
5  AlternC - Web Hosting System
6  Copyright (C) 2002 by the AlternC Development Team.
7  http://alternc.org/
8  ----------------------------------------------------------------------
9  Based on:
10  Valentin Lacambre's web hosting softwares: http://altern.org/
11  ----------------------------------------------------------------------
12  LICENSE
13 
14  This program is free software; you can redistribute it and/or
15  modify it under the terms of the GNU General Public License (GPL)
16  as published by the Free Software Foundation; either version 2
17  of the License, or (at your option) any later version.
18 
19  This program is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  GNU General Public License for more details.
23 
24  To read the license please visit http://www.gnu.org/copyleft/gpl.html
25  ----------------------------------------------------------------------
26  Purpose of file: Admin piwik users right for piwik sites
27  ----------------------------------------------------------------------
28 */
29 
30 require_once("../class/config.php");
31 include_once("head.php");
32 
33 $fields = array (
34  "user_name" => array ("request", "string", FALSE),
35  "site_id" => array ("post", "integer", -1),
36  "right" => array ("post", "string", FALSE),
37 );
39 
40 if ($user_name === FALSE)
41 {
42  $error = _('No piwik user specified');
43 }
44 else
45 {
46  // Add a user to a piwik website
47  if ($site_id != -1 && $right !== FALSE) {
48  $db->query("SELECT COUNT(*) AS ok FROM piwik_sites WHERE uid='$cuid' AND piwik_id='$site_id'");
49  $db->next_record();
50  if ($db->f('ok')!=1)
51  {
52  $error = _("You don't own this piwik website");
53  }
54  else
55  {
56  $db->query("SELECT COUNT(*) AS ok FROM piwik_users WHERE uid='$cuid' AND login='$user_name'");
57  $db->next_record();
58  if ($db->f('ok')!=1)
59  {
60  $error = _("You don't own this piwik user");
61  }
62  else
63  {
64  $piwik_rights = array("noaccess", "view", "admin");
65  if (in_array($right, $piwik_rights))
66  {
67  $api_data = $piwik->site_set_user_right($site_id, $user_name, $right);
68  if ($api_data === FALSE)
69  echo $error;
70  else
71  __('success');
72  }
73  else
74  {
75  $error = _("This right does not exist");
76  }
77  }
78  }
79  }
80 
81  $user_piwik_sites = array();
82  $db->query("SELECT piwik_id FROM piwik_sites WHERE uid='$cuid'");
83  while ($db->next_record())
84  array_push($user_piwik_sites, $db->f('piwik_id'));
85  // Weird behaviour of php: array_push products an array such as:
86  // array_push(array(1,2,3) , 4) produces
87  // array(0 => 1, 1 => 2, 2 => 3, 3 => 4)
88  // So for further comparison, we need to exchange keys and values
90 
91  $user_piwik_users = array();
92  $db->query("SELECT login FROM piwik_users WHERE uid='$cuid'");
93  while ($db->next_record())
94  array_push ($user_piwik_users, $db->f('login'));
95  // Swap keys and values, see user_piwik_sites
97 }
98 
99 
100 if (isset($error) && $error) {
101  echo "<p class=\"alert alert-danger\">$error</p>";
102  exit;
103 }
104 ?>
105 <h3><?php printf('%s "%s"', _("Rights for user"), $user_name); ?></h3>
106 <?php
107 $raw_sites = $piwik->get_site_list();
108 $piwik_sites = array();
109 foreach ($raw_sites AS $site) {
110  $piwik_sites[ $site->idsite ] = array('name' => $site->name, 'url' => $site->main_url);
111 }
112 
113 $raw_access = $piwik->get_site_access($user_name);
114 
115 $piwik_user_sites = array_intersect_ukey($piwik_sites, $user_piwik_sites, "strcmp");
117 
118 echo '<ul>';
119 foreach ($raw_access AS $access)
120 {
121  unset($available_user_sites[ $access->site ]);
122  printf("<li>%s -> %s</li>\n", $piwik_sites[ $access->site ]['name'], $access->access);
123 }
124 echo '</ul>';
126 {
127 ?>
128 <h3><?php printf('%s "%s"', _("Add rights to user"), $user_name); ?></h3>
129 <ul>
130 <?php
131 foreach ($available_user_sites AS $current_id_site => $available_user_site)
132 {
133  printf('<li>%s <form method="post"><input type="hidden" name="site_id" value="%d">
134 <select name="right">
135  <option value="noaccess">%s</option>
136  <option value="view">%s</option>
137  <option value="admin">%s</option>
138 </select>
139 <input type="submit" name="add" value="ajouter" class="inb" /></form></li>', $available_user_site['name'], $current_id_site, _("noacces"), _("view"), _("admin"));
140 }
141 ?>
142 </li>
143 <?php
144 }
145 include_once("foot.php"); ?>