Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
piwik_sitelist.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: listing of piwik site, and manage associated credentials
27  ----------------------------------------------------------------------
28 */
29 
30 require_once("../class/config.php");
31 include_once("head.php");
32 include_once("piwik_utils.php");
33 
34 $fields = array (
35  "site_id" => array ("request", "integer", -1), // alternc ID of the piwik site
36  "right" => array ("post", "array", FALSE), // array of rights associated foreach user of $site_id
37 );
39 
40 /* Get once alternc users and sites */
41 $piwik_alternc_users = $piwik->get_alternc_users();
42 $piwik_alternc_sites = $piwik->get_alternc_sites();
43 
44 /* Form was submitted, need to deal with work to do. */
45 if ($right !== FALSE) {
46  // Should this stay here, or in the API?
47  if (!in_array($site_id, $piwik_alternc_sites))
48  $error = _("You don't own this piwik site!");
49  else {
50  /* Foreach row of right, extract user, and selected credential */
51  foreach ($right AS $user => $cred)
52  {
53  /* Ensures that the user is legitimate for that user */
54  /* If not, we just break the loop, and set error message */
55  if (!in_array($user, $piwik_alternc_users)) {
56  $error = sprintf('%s "%s"', _('You dont own user'), $user);
57  break;
58  }
59 
60  /* Ok, current user has right to manage this piwik user. Update rights. */
61  printf ("%s -> %s<br />\n", $user, $cred);
62  if (!$piwik->site_set_user_right($site_id, $user, $cred)) {
63  $error = $err->errstr();
64  break;
65  }
66  }
67  }
68 }
69 
70 /* If something went wrong, display error message, but continue with the page rendering */
71 if (isset($error) && $error) {
72  echo "<p class=\"alert alert-danger\">$error</p>";
73 }
74 
75 /* Does current user still has quota ? */
76 if ($quota->cancreate("piwik")) {
77  $quotapiwik=$quota->getquota('piwik');
78 
79  /* If quota are still available, display form to let user add a new site */
80  if ($quotapiwik['u']>0) {
81 
82 ?>
83 <h3><?php __("Add a new website");?></h3>
84 <form method="post" action="piwik_addsites.php" id="main" name="addsites" >
85  <input type="text" class="int" name="site_urls" size="50" id="site_name" maxlength="255" value="" placeholder="<?php __("URL of the website")?>"/>
86  <input type="submit" name="submit" class="inb" value="<?php __("Create"); ?>" />
87 </form>
88 
89 <br/>
90 <hr/>
91 <?php
92  } // quotapiwik > 0
93 } // cancreate piwik
94 
95 
96 
97 /* In that part, we'll manage the rights associated to a selected piwik site. */
98 /* The output is the following: */
99 /* [ site [v]] */
100 /* - user1 no access () view () admin () */
101 /* - user2 no access () view () admin () */
102 /* [ submit ] */
103 
104 ?>
105 
106 <h3><?php __("Existing Piwik monitored websites"); ?></h3>
107 <?php
108 
109 /* Get the list of piwik sites for current user */
110 $sitelist = $piwik->site_list();
111 
112 /* If user didn't add a website, just do nothing but display there's no site */
113 if (empty($sitelist)){
114  __("No existing Piwik websites");
115 } else {
116 /* Otherwize, display the html form, [ sitename, url, javascript code ] */
117 ?>
118 
119 <table class="tlist">
120  <tr><th/><th><?php __("Site name");?></th><th align=center><?php __("Site url"); ?></th><th>Javascript Code</th></tr>
121 <?php
122 
123 $col=1;
124 foreach ($sitelist as $site ){
125  $col=3-$col;
126  ?>
127  <tr class="lst_clic<?php echo $col; ?>">
128  <td><div class="ina"><a href="/piwik_site_dodel.php?siteid=<?php echo $site->id; ?>"><img src="images/delete.png" alt="<?php __("Delete"); ?>" /><?php __("Delete"); ?></a></div></td>
129  <td align=right><?php echo $site->name ?></td>
130  <td><?php echo $site->main_url ?></td>
131  <td><textarea><?php echo $piwik->site_js_tag($site->id); ?></textarea></td>
132  </tr>
133  <?php
134 } // foreach sitelist
135 
136 
137 
138 /* We'll now manage credentials for piwik sites */
139 /* We first create a select item to choose the piwik site to administrate */
140 /* Then we display a list of users, and associated rights. */
141 /* To achieve this, we select all piwik users available for current alternc user */
142 /* If a piwik user has no rights on that site, its rights are set to "noaccess" */
143 ?>
144 </table>
145 
146 
147 <h3><?php __("Credentials management"); ?></h3>
148 
149 <form method="get">
150 <select name="site_id">
151 
152 <?php
153  foreach ($sitelist as $site)
154  printf ('<option value="%d"%s>%s</option>', $site->id, ($site->id == $site_id) ? ' selected ' : '', $site->name);
155 ?>
156 
157 </select>&nbsp;
158 <input type="submit" class="inb" value="ok" />
159 </form>
160 
161 <?php
162  // If a site was selected
163  if ($site_id != -1 && in_array($site_id, $piwik_alternc_sites)) {
164  echo '<form method="post">';
165  echo '<dl>';
166  foreach ($piwik->get_users_access_from_site($site_id) AS $piwik_user => $cred) {
167  printf("<dt>%s:</dt>\n\t<dd>%s</dd>\n", $piwik_user, piwik_right_widget('right', $piwik_user, $cred));
168  }
169  echo '</dl>';
170  echo '<input type="submit" name="valid" class="inb" value="' , _("submit"), '" />';
171  echo '</form>';
172  }
173 } // empty userlist
174 ?>
175 
176 <?php include_once("foot.php"); ?>