Initial commit
[clearscm.git] / cc / msl / streams.php
1 <?php
2 ////////////////////////////////////////////////////////////////////////////////
3 //
4 // File:        streams.php
5 // Revision:    1.1.1.1
6 // Description: Library to interface to Clearcase streams
7 // Author:      Andrew@DeFaria.com
8 // Created:     Wed Jul  5 10:14:02 PDT 2006
9 // Modified:    2007/05/17 07:45:48
10 // Language:    PHP
11 //
12 // (c) Copyright 2006, Andrew@DeFaria.com, all rights reserved.
13 //
14 ////////////////////////////////////////////////////////////////////////////////
15 $version        = "1.0";
16 $pvob           = "/vobs/ilm_pvob";
17 $cleartool      = "/opt/rational/clearcase/bin/cleartool";
18
19 function debug ($msg) {
20   print "<b><font color=red>DEBUG:</font></b> $msg<br>\n";
21 } // debug
22
23 function error ($msg) {
24   print "<b><font color=red>ERROR:</font></b> $msg<br>\n";
25   exit (1);
26 } // error
27
28 function get_streams () {
29   global $pvob;
30   global $cleartool;
31
32   $cmd = "$cleartool lsstream -s -invob $pvob";
33
34   exec ($cmd, $output, $status);
35
36   if ($status != 0) {
37     print "Unable to execute command \"$cmd\" (Status: $status)<br>";
38     exit (1);
39   } // if
40
41   return $output;
42 } // get_streams
43
44 function get_usernames () {
45   $cmd = "ypcat passwd";
46
47   exec ($cmd, $lines, $status);
48
49   if ($status != 0) {
50     print "Unable to execute command \"$cmd\" (Status: $status)<br>";
51     exit (1);
52   } // if
53
54   $users = array ();
55
56   foreach ($lines as $line) {
57     $fields = explode (":", $line);
58     $users {$fields [0]} = $fields [4];
59   } // foreach
60
61   return $users;
62 } // get_usernames
63
64 function get_users () {
65   $cmd = "ypcat passwd";
66
67   exec ($cmd, $lines, $status);
68
69   if ($status != 0) {
70     print "Unable to execute command \"$cmd\" (Status: $status)<br>";
71     exit (1);
72   } // if
73
74   $users = array ();
75
76   foreach ($lines as $line) {
77     $fields = explode (":", $line);
78     array_push ($users, $fields [0]);
79   } // foreach
80
81   return $users;
82 } // get_users
83
84 function get_nusers ($stream) {
85   global $cleartool;
86   global $pvob;
87
88   $cmd = "$cleartool lslock stream:$stream@$pvob";
89
90   exec ($cmd, $output, $status);
91
92   if ($status != 0) {
93     print "Stream: $stream not found";
94     exit (1);
95   } else {
96     if (count ($output) == 0) {
97       return;
98     } // if 
99   } // if
100
101   $nusers = array ();
102
103   foreach ($output as $line) {
104     if (preg_match ("/\"Locked except for users: (.*)\"/", $line, $matches)) {
105       $nusers = split (" ", $matches [1]);
106     } // if
107   } // foreach
108
109   return $nusers;
110 } // get_nusers
111
112 function is_member ($new_item, $array) {
113   if (empty ($new_item) || empty ($array)) {
114     return 0;
115   } // if
116
117   foreach ($array as $item) {
118     if ($new_item == $item) {
119       return 1;
120     } // if
121   } // foreach
122
123   return 0;
124 } // is_member
125
126 function remove_from_array ($removed_item, $array) {
127   $new_array = array ();
128
129   foreach ($array as $item) {
130     if ($removed_item != $item) {
131       array_push ($new_array, $item);
132     } // if
133   } // foreach
134
135   return $new_array;
136 } // remove_from_array
137
138 function chnusers ($stream, $users) {
139   $nusers = "";
140
141   foreach ($users as $user) {
142     if (empty ($nusers)) {
143       $nusers .= $user;
144     } else {
145       $nusers .= ",$user";
146     } // if
147   } // foreach
148
149   $current_nusers = get_nusers ($stream);
150
151   if (count ($current_nusers) == 0 || count ($users) == 0) {
152     $cmd = "./chnusers $stream $nusers";
153   } else {
154     $cmd = "./chnusers $stream $nusers replace";
155   } // if
156
157   exec ($cmd, $output, $status);
158
159   return $status;
160 } // chnusers
161
162 function copyright ($start_year = "", $version = "") {
163   $today        = getdate ();
164   $current_year = $today ["year"];
165
166   $this_file = $_SERVER['PHP_SELF'];
167
168   // Handle user home web pages
169   if (preg_match ("/\/\~/", $this_file)) {
170     $this_file= preg_replace ("/\/\~(\w+)\/(\s*)/", "/home/$1/web$2/", $this_file);
171   } else {
172     $this_file = "/var/devenv/tiburon/" . $this_file;
173   } // if
174
175   $mod_time  = date ("F d Y @ g:i a", filemtime ($this_file));
176
177   print <<<END
178 <div class="copyright">
179 Last modified: $mod_time<br>
180 Copyright &copy; 
181 END;
182
183   if ($start_year != "") {
184     print "$start_year-";
185   } // if
186
187 print <<<END
188 $current_year <a href="http://www.hp.com/go/ilm">HP/Information Lifecycle Management Solutions</a><br>
189 All rights reserved (
190 END;
191
192 print basename ($_SERVER ["PHP_SELF"], ".php");
193
194 if ($version != "") {
195   print " V$version";
196 } // if
197
198 print ")\n</div>\n";
199 } // copyright