]> git.sur5r.net Git - openldap/blob - contrib/php3-tool/include/preferences.inc
11ca8f04f00854f272939ed449863748c462d3d3
[openldap] / contrib / php3-tool / include / preferences.inc
1 <?
2 class preferences {
3         var $name;
4         var $sections = array();
5         var $base_dn;
6         var $host;
7         var $attribute_names = array();
8
9         cfunction getSection($s) {
10         ////    echo "getSection(".$s.")<br>";
11                 $sect = array();
12                 for ($i=0; $i<count($this->sections); $i++) {
13                         $sect = $this->sections[$i];
14         //              echo $sect[0]."<br>";
15                         if ($sect[0] == $s) {
16         //                      echo "Found ".$sect[0]."<br>";
17                                 return $sect[1];
18                         }       
19                 }
20         //      echo "Didn't find ".$s."<br>";
21         }
22         cfunction get($s) {
23                 $class = explode(".", $s);
24                 $sect = $this->getSection($class[0]);
25                 $values = array();
26                 $values = $sect[1];
27                 for ($i=0; $i<count($sect); $i++) {
28                         $values = $sect[$i];
29         //              echo $values[0]."<br>";
30                         if ($values[0] == $class[1]) {
31         //                      echo "Found ".$values[0]."<br>";
32                                 return $values[1];
33                         }
34                 }
35         //      echo "Didn't find ".$class[1]."<br>";
36         }
37         cfunction getName($s) {
38                 $n = trim(strtok($s, "{"));
39                 return $n;
40         }
41         cfunction getBody($s) {
42                 $i = strpos($s, "{") + 1;
43                 $j = strpos($s, "}") - 1;
44                 $tok = substr($s, $i, $j-$i);
45                 return $tok;
46         }
47         cfunction getValues($b) {
48                 $t = '" ","\" ","\n"';
49                 $av_pairs = array();
50                 $pairs = array();
51                 $av_pair = array();
52                 $pairs = explode(";", $b);
53                 for ($i=0; $i<count($pairs)-1; $i++) {
54                         $av_pair = explode(":", $pairs[$i]);
55                         $av_pair[0] = trim($av_pair[0]);
56                         $av_pair[1] = trim($this->stripString($av_pair[1], $t));
57         //              echo "<li>".$av_pair[0].":".$av_pair[1];
58                         $av_pairs[$i] = $av_pair;
59                 }
60                 return $av_pairs;
61         }
62         cfunction getStatements($s) {
63                 $i = 0;
64                 $end = strpos($s, "}");
65                 while($end != FALSE) {
66                         $tok = substr($s, 0, $end+1);
67                         $s = substr($s, $end+1, strlen($s));
68         //              echo "<ul>";
69                         $this->sections[$i] = $this->getStatement($tok);
70         //              echo "</ul>\n";
71                         $end = strpos($s, "}");
72                         $i++;
73                 }
74         //      echo count($this->sections)." sections<br>";
75         }
76         cfunction getStatement($s) {
77                 $values[0] = $this->getName($s);
78 //              echo "<li>Name ".$values[0];
79                 $body = $this->getBody($s);
80 //              echo "<li>Values<ul>";
81                 $values[1] = $this->getValues($body);
82 //              echo "</ul></li>";
83                 return $values;
84         }
85         cfunction loadPreferences() {
86                 if (count($preferences) != 0) {
87                         echo "I have got ".count($this->sections)." preferences here<br>\n";
88                 }
89                 else {
90                         $fp = fopen("php3tool.conf", "r");
91                         $i = 0;
92                         $string = "";
93                         while (!feof($fp)) {
94                                 $string .= fgets($fp, 80);
95                         }
96                         fclose($fp);
97                         $this->getStatements($string);
98                 }
99                 $this->loadAttributeNames($this->get("PATH.attributes"));
100         }
101
102         cfunction loadAttributeNames($s = "at.conf") {
103         //      global $attribute_names;
104                 if (count($this->attribute_names) != 0) {
105                         //This is bullshit here..how do we make php3
106                         //preserve an array in memory between re-loads?
107                         //And no, I'm not going to send it every time
108                         //I make a subsequent request..
109                         //If we don't fix these things it won't run
110                         //on anything smaller than a StarFire 10000
111                         //EVEN THOUGH this stuff is suprisingly fast.
112                         echo "I have got attribute_names here<br>\n";
113                 }
114                 else {
115                         //echo "I dont have attribute_names here<br>\n";
116                         $fp = fopen($s, "r");
117                         $i = 0;
118                         while (!feof($fp)) {
119                                 $string = "";
120                                 $foo = "";
121                                 $string = fgets($fp, 80);
122                                 $foo = strtok($string, ",");
123                                 $this->attribute_names[$i][0] = $foo;
124                                 $foo = strtok(",");
125                                 $this->attribute_names[$i][1] = $foo;
126                                 $foo = strtok("\n");
127                                 $this->attribute_names[$i][2] = $foo;
128                                 $i++;
129                         }
130                 }
131         //      echo "Hello world:<b>".count($this->attribute_names)."</b>\n";
132         //      for ($i=0; $i<count($this->attribute_names)-1; $i++) {
133         //              echo $this->attribute_names[$i][0]." - <strong>".$this->attribute_names[$i][1]."</strong> - ".$this->attribute_names[$i][2]."<br>\n";
134         //      }       
135                 return $this->attribute_names;
136         }
137
138         cfunction stripString($string, $tokens) {
139                 $s = $string;
140                 for ($i=0; $i<count($tokens); $i++) {
141                         $result = "";
142                         $tok = strtok($s, $tokens[$i]);
143                         while($tok) {
144                                 $result .= $tok;
145                         //      echo "result = ".$result."\n";
146                                 $tok = strtok($tokens[$i]);
147                         }
148                         $s = $result;
149                 //      echo "s = ".$s."\n";
150                 }
151         //      echo "result = ".$result."\n";
152                 return $result;
153         }
154 }
155 ?>