root/alternc/tags/0.9.6.3/quota_init

Revision 1798, 1.5 kB (checked in by nahuel, 1 year ago)

Comme php5 peut etre installé, nous utilisons le lien php qui pointe soit vers php5 soit vers php4 ( soit php6 ? ).
close: #1042

Line 
1 #!/usr/bin/php -q
2 <?php
3
4 /*
5  This script create a quota entry for each existing user.
6  and set the default quota to the specified value.
7  (this script may be used when installing / upgrading an AlternC module)
8
9  $argv[1] = The named quota to create
10  $argv[2] = The default quota value for each user.
11 */
12
13 if ($argc!=3) {
14     echo "Usage : ".$argv[0]." <quota name> <quota value>
15  Create a quota entry for each existing user and set the default quota to the
16  specified value.
17 ";
18     return 1;
19 }
20
21 $name=$argv[1];
22 $quota=$argv[2];
23
24 include("/var/alternc/bureau/class/local.php");
25
26 if (!mysql_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD)) {
27     echo "Cannot connect to Mysql !\n";
28     return 1;
29 }
30
31 if (!mysql_select_db($L_MYSQL_DATABASE)) {
32     echo "Cannot connect to Mysql database $L_MYSQL_DATABASE !\n";
33     return 1;
34 }
35
36 $r=mysql_query("DELETE FROM defquotas WHERE quota='$name';");
37 if (mysql_errno()) {
38     echo "Mysql Error : ".mysql_error()."\n";
39     return 1;
40 }
41
42 $r=mysql_query("INSERT INTO defquotas (quota,value) VALUES ('$name','$quota');");
43 if (mysql_errno()) {
44     echo "Mysql Error : ".mysql_error()."\n";
45     return 1;
46 }
47
48 $r=mysql_query("SELECT uid FROM membres;");
49 if (mysql_errno()) {
50         echo "Mysql Error : ".mysql_error()."\n";
51         return 1;
52 }
53 while ($c=mysql_fetch_array($r)) {
54     $s=mysql_query("SELECT name FROM quotas WHERE uid='$c[uid]' AND name='$name';");
55     if (!mysql_num_rows($s)) {
56         mysql_query("INSERT INTO quotas (uid,name,total,used) VALUES ('$c[uid]','$name','$value',0);");
57     }
58 }
59
60 return 0;
61
62 ?>
63
Note: See TracBrowser for help on using the browser.