Rev 229 Rev 240
1 <?php 1 <?php
2   2  
3 //permissions bit flags 3 //permissions bit flags
4 define("SG_GRP_READ", 1); 4 define("SG_GRP_READ", 1);
5 define("SG_GRP_EDIT", 2); 5 define("SG_GRP_EDIT", 2);
6 define("SG_GRP_ADD", 4); 6 define("SG_GRP_ADD", 4);
7 define("SG_GRP_DELETE", 8); 7 define("SG_GRP_DELETE", 8);
8 define("SG_WLD_READ", 16); 8 define("SG_WLD_READ", 16);
9 define("SG_WLD_EDIT", 32); 9 define("SG_WLD_EDIT", 32);
10 define("SG_WLD_ADD", 64); 10 define("SG_WLD_ADD", 64);
11 define("SG_WLD_DELETE", 128); 11 define("SG_WLD_DELETE", 128);
12   12  
13   13  
14 function getGallery($path) 14 function getGallery($path)
15 { 15 {
16 $gal = new sgGallery('.'); 16 $gal = new sgGallery('.');
17   17  
18 $fp = @fopen($path."/metadata.csv","r"); 18 $fp = @fopen($path."/metadata.csv","r");
19 if($fp) { 19 if($fp) {
20   20  
21 while($temp[] = fgetcsv($fp,2048)); 21 while($temp[] = fgetcsv($fp,2048));
22 fclose($fp); 22 fclose($fp);
23 23
24 @list( 24 @list(
25 $gal->filename, 25 $gal->filename,
26 , 26 ,
27 $gal->owner, 27 $gal->owner,
28 $gal->groups, 28 $gal->groups,
29 $gal->permissions, 29 $gal->permissions,
30 $gal->categories, 30 $gal->categories,
31 $gal->name, 31 $gal->name,
32 $gal->artist, 32 $gal->artist,
33 $gal->email, 33 $gal->email,
34 $gal->copyright, 34 $gal->copyright,
35 $gal->desc, 35 $gal->desc,
36 $gal->summary, 36 $gal->summary,
37 $gal->date 37 $gal->date
38 ) = $temp[1]; 38 ) = $temp[1];
39 39
40 40
41 for($i=0;$i<count($temp)-3;$i++) { 41 for($i=0;$i<count($temp)-3;$i++) {
42 $gal->images[$i] = new sgImage(); 42 $gal->images[$i] = new sgImage();
43 list( 43 list(
44 $gal->images[$i]->filename, 44 $gal->images[$i]->filename,
45 $gal->images[$i]->thumbnail, 45 $gal->images[$i]->thumbnail,
46 $gal->images[$i]->owner, 46 $gal->images[$i]->owner,
47 $gal->images[$i]->groups, 47 $gal->images[$i]->groups,
48 $gal->images[$i]->permissions, 48 $gal->images[$i]->permissions,
49 $gal->images[$i]->categories, 49 $gal->images[$i]->categories,
50 $gal->images[$i]->name, 50 $gal->images[$i]->name,
51 $gal->images[$i]->artist, 51 $gal->images[$i]->artist,
52 $gal->images[$i]->email, 52 $gal->images[$i]->email,
53 $gal->images[$i]->copyright, 53 $gal->images[$i]->copyright,
54 $gal->images[$i]->desc, 54 $gal->images[$i]->desc,
55 $gal->images[$i]->location, 55 $gal->images[$i]->location,
56 $gal->images[$i]->date, 56 $gal->images[$i]->date,
57 $gal->images[$i]->camera, 57 $gal->images[$i]->camera,
58 $gal->images[$i]->lens, 58 $gal->images[$i]->lens,
59 $gal->images[$i]->film, 59 $gal->images[$i]->film,
60 $gal->images[$i]->darkroom, 60 $gal->images[$i]->darkroom,
61 $gal->images[$i]->digital 61 $gal->images[$i]->digital
62 ) = $temp[$i+2]; 62 ) = $temp[$i+2];
63 63
64 //don't get image size and type 64 //don't get image size and type
65 65
66 } 66 }
67 67
68 } else { 68 } else {
69 //selected gallery does not exist or no metadata 69 //selected gallery does not exist or no metadata
70 return null; 70 return null;
71 } 71 }
72 72
73 return $gal; 73 return $gal;
74 } 74 }
75   75  
76 function putGallery($gallery, $path) { 76 function putGallery($gallery, $path) {
77 77
78 //backup data file 78 //backup data file
79 copy($path."/metadata.csv", $path."/metadata.bak"); 79 copy($path."/metadata.csv", $path."/metadata.bak");
80 $fp = fopen($path."/metadata.csv","w"); 80 $fp = fopen($path."/metadata.csv","w");
81 81
82 if(!$fp) return false; 82 if(!$fp) return false;
83 83
84 $success = true; 84 $success = true;
85   85  
86 $success &= (bool) fwrite($fp,"filename,thumbnail,owner,group(s),permissions,catergories,image name,artist name,artist email,copyright,image description,image location,date taken,camera info,lens info,film info,darkroom manipulation,digital manipulation"); 86 $success &= (bool) fwrite($fp,"filename,thumbnail,owner,group(s),permissions,catergories,image name,artist name,artist email,copyright,image description,image location,date taken,camera info,lens info,film info,darkroom manipulation,digital manipulation");
87 $success &= (bool) fwrite($fp,"\n\"". 87 $success &= (bool) fwrite($fp,"\n\"".
88 $gallery->filename."\",,". 88 $gallery->filename."\",,".
89 $gallery->owner.",". 89 $gallery->owner.",".
90 $gallery->groups.",". 90 $gallery->groups.",".
91 $gallery->permissions.",". 91 $gallery->permissions.",".
92 $gallery->categories.',"'. 92 $gallery->categories.',"'.
93 str_replace('"','""',$gallery->name).'","'. 93 str_replace('"','""',$gallery->name).'","'.
94 str_replace('"','""',$gallery->artist).'","'. 94 str_replace('"','""',$gallery->artist).'","'.
95 str_replace('"','""',$gallery->email).'","'. 95 str_replace('"','""',$gallery->email).'","'.
96 str_replace('"','""',$gallery->copyright).'","'. 96 str_replace('"','""',$gallery->copyright).'","'.
97 str_replace('"','""',$gallery->desc).'","'. 97 str_replace('"','""',$gallery->desc).'","'.
98 str_replace('"','""',$gallery->summary).'","'. 98 str_replace('"','""',$gallery->summary).'","'.
99 str_replace('"','""',$gallery->date).'"' 99 str_replace('"','""',$gallery->date).'"'
100 ); 100 );
101 101
102 for($i=0;$i<count($gallery->images);$i++) 102 for($i=0;$i<count($gallery->images);$i++)
103 $success &= (bool) fwrite($fp,"\n\"". 103 $success &= (bool) fwrite($fp,"\n\"".
104 $gallery->images[$i]->filename."\",". 104 $gallery->images[$i]->filename."\",".
105 $gallery->images[$i]->thumbnail.",". 105 $gallery->images[$i]->thumbnail.",".
106 $gallery->images[$i]->owner.",". 106 $gallery->images[$i]->owner.",".
107 $gallery->images[$i]->groups.",". 107 $gallery->images[$i]->groups.",".
108 $gallery->images[$i]->permissions.",". 108 $gallery->images[$i]->permissions.",".
109 $gallery->images[$i]->categories.',"'. 109 $gallery->images[$i]->categories.',"'.
110 str_replace('"','""',$gallery->images[$i]->name).'","'. 110 str_replace('"','""',$gallery->images[$i]->name).'","'.
111 str_replace('"','""',$gallery->images[$i]->artist).'","'. 111 str_replace('"','""',$gallery->images[$i]->artist).'","'.
112 str_replace('"','""',$gallery->images[$i]->email).'","'. 112 str_replace('"','""',$gallery->images[$i]->email).'","'.
113 str_replace('"','""',$gallery->images[$i]->copyright).'","'. 113 str_replace('"','""',$gallery->images[$i]->copyright).'","'.
114 str_replace('"','""',$gallery->images[$i]->desc).'","'. 114 str_replace('"','""',$gallery->images[$i]->desc).'","'.
115 str_replace('"','""',$gallery->images[$i]->location).'","'. 115 str_replace('"','""',$gallery->images[$i]->location).'","'.
116 str_replace('"','""',$gallery->images[$i]->date).'","'. 116 str_replace('"','""',$gallery->images[$i]->date).'","'.
117 str_replace('"','""',$gallery->images[$i]->camera).'","'. 117 str_replace('"','""',$gallery->images[$i]->camera).'","'.
118 str_replace('"','""',$gallery->images[$i]->lens).'","'. 118 str_replace('"','""',$gallery->images[$i]->lens).'","'.
119 str_replace('"','""',$gallery->images[$i]->film).'","'. 119 str_replace('"','""',$gallery->images[$i]->film).'","'.
120 str_replace('"','""',$gallery->images[$i]->darkroom).'","'. 120 str_replace('"','""',$gallery->images[$i]->darkroom).'","'.
121 str_replace('"','""',$gallery->images[$i]->digital).'"' 121 str_replace('"','""',$gallery->images[$i]->digital).'"'
122 ); 122 );
123 $success &= (bool) fclose($fp); 123 $success &= (bool) fclose($fp);
124   124  
125 return $success; 125 return $success;
126 } 126 }
127   127  
128 function setPerms($obj) { 128 function setPerms($obj) {
129 $obj->permissions = 0; 129 $obj->permissions = 0;
130 if(!empty($_POST["sgGrpRead"])) $obj->permissions |= SG_GRP_READ; 130 if(!empty($_POST["sgGrpRead"])) $obj->permissions |= SG_GRP_READ;
131 if(!empty($_POST["sgGrpEdit"])) $obj->permissions |= SG_GRP_EDIT; 131 if(!empty($_POST["sgGrpEdit"])) $obj->permissions |= SG_GRP_EDIT;
132 if(!empty($_POST["sgGrpAdd"])) $obj->permissions |= SG_GRP_ADD; 132 if(!empty($_POST["sgGrpAdd"])) $obj->permissions |= SG_GRP_ADD;
133 if(!empty($_POST["sgGrpDelete"])) $obj->permissions |= SG_GRP_DELETE; 133 if(!empty($_POST["sgGrpDelete"])) $obj->permissions |= SG_GRP_DELETE;
134 if(!empty($_POST["sgWldRead"])) $obj->permissions |= SG_WLD_READ; 134 if(!empty($_POST["sgWldRead"])) $obj->permissions |= SG_WLD_READ;
135 if(!empty($_POST["sgWldEdit"])) $obj->permissions |= SG_WLD_EDIT; 135 if(!empty($_POST["sgWldEdit"])) $obj->permissions |= SG_WLD_EDIT;
136 if(!empty($_POST["sgWldAdd"])) $obj->permissions |= SG_WLD_ADD; 136 if(!empty($_POST["sgWldAdd"])) $obj->permissions |= SG_WLD_ADD;
137 if(!empty($_POST["sgWldDelete"])) $obj->permissions |= SG_WLD_DELETE; 137 if(!empty($_POST["sgWldDelete"])) $obj->permissions |= SG_WLD_DELETE;
138 138
139 $obj->groups = $_REQUEST["sgGroups"]; 139 $obj->groups = $_REQUEST["sgGroups"];
140 $obj->owner = $_REQUEST["sgOwner"]; 140 $obj->owner = $_REQUEST["sgOwner"];
141 141
142 return $obj; 142 return $obj;
143 } 143 }
144   144  
145   145  
146 function convertDirectory ($path) 146 function convertDirectory ($path)
147 { 147 {
148 if (is_dir($path)) { 148 if (is_dir($path)) {
149 $gallery = getGallery($path); 149 $gallery = getGallery($path);
150 echo "<ul><li>Checking $path<br />\n"; 150 echo "<ul><li>Checking $path<br />\n";
151 if($gallery) { 151 if($gallery) {
152 if($gallery->summary != "" && empty($_REQUEST["convertOverwrite"])) 152 if($gallery->summary != "" && empty($_REQUEST["convertOverwrite"]))
153 echo "Did NOT overwrite non-empty summary in $path<br />\n"; 153 echo "Did NOT overwrite non-empty summary in $path<br />\n";
154 else { 154 else {
155 if($_REQUEST["convertType"]!='none') 155 if($_REQUEST["convertType"]!='none')
156 $gallery->summary = $gallery->desc; 156 $gallery->summary = $gallery->desc;
157 if($_REQUEST["convertType"]=='move') 157 if($_REQUEST["convertType"]=='move')
158 $gallery->desc = ""; 158 $gallery->desc = "";
159 } 159 }
160   160  
161 $gallery = setPerms($gallery); 161 $gallery = setPerms($gallery);
162 162
163 for($i=0; $i<count($gallery->images); $i++) 163 for($i=0; $i<count($gallery->images); $i++)
164 $gallery->images[$i] = setPerms($gallery->images[$i]); 164 $gallery->images[$i] = setPerms($gallery->images[$i]);
165 165
166 if(putGallery($gallery,$path)) 166 if(putGallery($gallery,$path))
167 echo "Successfully converted $path<br />\n"; 167 echo "Successfully converted $path<br />\n";
168 else 168 else
169 echo "Problem saving data file for $path<br />\n"; 169 echo "Problem saving data file for $path<br />\n";
170 } else 170 } else
171 echo "Skipping $path<br />\n"; 171 echo "Skipping $path<br />\n";
172 $d = dir($path); 172 $d = dir($path);
173 while (($file = $d->read()) !== false) { 173 while (($file = $d->read()) !== false) {
174 if ($file == '.' || $file == '..') continue; 174 if ($file == '.' || $file == '..') continue;
175 $path = $d->path."/".$file; 175 $path = $d->path."/".$file;
176 if (is_dir($path)) { 176 if (is_dir($path)) {
177 convertDirectory($path); 177 convertDirectory($path);
178 } 178 }
179 } 179 }
180 echo "</li></ul>\n"; 180 echo "</li></ul>\n";
181 } 181 }
182 } 182 }
183   183  
184 ?> 184 ?>
185 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 185 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
186 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 186 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
187   187  
188 <html xmlns="http://www.w3.org/1999/xhtml"> 188 <html xmlns="http://www.w3.org/1999/xhtml">
189 <head> 189 <head>
190 <title>database converter</title> 190 <title>database converter</title>
191 <link rel="stylesheet" type="text/css" href="tools.css" /> 191 <link rel="stylesheet" type="text/css" href="tools.css" />
192 </head> 192 </head>
193   193  
194 <body> 194 <body>
195   195  
196 <h1>database converter</h1> 196 <h1>database converter</h1>
197   197  
198 <?php 198 <?php
199 if(isset($_REQUEST["convertType"])) { 199 if(isset($_REQUEST["convertType"])) {
200   200  
201 include "../includes/config.class.php"; 201 include "../includes/config.class.php";
202 include "../includes/gallery.class.php"; 202 include "../includes/gallery.class.php";
203 include "../includes/image.class.php"; 203 include "../includes/image.class.php";
204 $config = new sgConfig("../singapore.ini"); 204 $config = new sgConfig("../singapore.ini");
205 205
206 $config->base_path = "../"; 206 $config->base_path = "../";
207 207
208 //echo "<ul>\n"; 208 //echo "<ul>\n";
209 convertDirectory($config->base_path.$config->pathto_galleries); 209 convertDirectory($config->base_path.$config->pathto_galleries);
210 //echo "</ul>\n"; 210 //echo "</ul>\n";
211 211
212 echo "<p>All operations complete.</p>\n"; 212 echo "<p>All operations complete.</p>\n";
213   213  
214 } else { ?> 214 } else { ?>
215 <p>This will convert all your metadata files from singapore 0.9.6, 0.9.7, 0.9.8 or 0.9.9 to 0.9.10.</p> 215 <p>This will convert all your metadata files from singapore 0.9.6, 0.9.7, 0.9.8 or 0.9.9 to 0.9.10.</p>
216   216  
217 <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> 217 <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
218 <h3>summary field</h3> 218 <h3>summary field</h3>
219 <p>There is a new gallery summary field that is displayed instead of the 219 <p>There is a new gallery summary field that is displayed instead of the
220 description in the parent gallery. You can choose to either copy or move the 220 description in the parent gallery. You can choose to either copy or move the
221 old description field to the summary field or leave both untouched:</p> 221 old description field to the summary field or leave both untouched:</p>
222   222  
223 <p><input type="radio" class="radio" name="convertType" value="copy" checked="true" /> Copy<br /> 223 <p><input type="radio" class="radio" name="convertType" value="copy" checked="true" /> Copy<br />
224 <input type="radio" class="radio" name="convertType" value="move" /> Move<br /> 224 <input type="radio" class="radio" name="convertType" value="move" /> Move<br />
225 <input type="radio" class="radio" name="convertType" value="none" /> Neither<br /> 225 <input type="radio" class="radio" name="convertType" value="none" /> Neither<br />
226   226  
227 <p>By default only empty summary fields will be written to. Check this option to 227 <p>By default only empty summary fields will be written to. Check this option to
228 allow the summary field to be overwritten <input type="checkbox" class="checkbox" name="convertOverwrite" /></p> 228 allow the summary field to be overwritten <input type="checkbox" class="checkbox" name="convertOverwrite" /></p>
229   229  
230 <h3>permissions</h3> 230 <h3>permissions</h3>
231   231  
232 <p>This version introduces multiple authorised users and image &amp; gallery 232 <p>This version introduces multiple authorised users and image &amp; gallery
233 permissions. Please choose the default permissions that you would like all 233 permissions. Please choose the default permissions that you would like all
234 objects to be set to. The default permissions selected below are recommended as 234 objects to be set to. The default permissions selected below are recommended as
235 they will make all images &amp; galleries readable by everyone but only 235 they will make all images &amp; galleries readable by everyone but only
236 modifiable by administrators. See the readme for more information on the 236 modifiable by administrators. See the readme for more information on the
237 permissions model used by singapore.</p> 237 permissions model used by singapore.</p>
238 <table> 238 <table>
239 <tr> 239 <tr>
240 <td>Owner</td> 240 <td>Owner</td>
241 <td><input type="text" name="sgOwner" value="__nobody__" /></td> 241 <td><input type="text" name="sgOwner" value="__nobody__" /></td>
242 </tr> 242 </tr>
243 <tr> 243 <tr>
244 <td>Groups</td> 244 <td>Groups</td>
245 <td><input type="text" name="sgGroups" value="" /></td> 245 <td><input type="text" name="sgGroups" value="" /></td>
246 </tr> 246 </tr>
247 <tr> 247 <tr>
248 <td>Group permissions</td> 248 <td>Group permissions</td>
249 <td><div class="inputbox"> 249 <td><div class="inputbox">
250 <input type="checkbox" class="checkbox" name="sgGrpRead" checked="true"/> Read 250 <input type="checkbox" class="checkbox" name="sgGrpRead" checked="true"/> Read
251 <input type="checkbox" class="checkbox" name="sgGrpEdit" /> Edit 251 <input type="checkbox" class="checkbox" name="sgGrpEdit" /> Edit
252 <input type="checkbox" class="checkbox" name="sgGrpAdd" /> Add 252 <input type="checkbox" class="checkbox" name="sgGrpAdd" /> Add
253 <input type="checkbox" class="checkbox" name="sgGrpDelete" /> Delete 253 <input type="checkbox" class="checkbox" name="sgGrpDelete" /> Delete
254 </div></td> 254 </div></td>
255 </tr> 255 </tr>
256 <tr> 256 <tr>
257 <td>World permissions</td> 257 <td>World permissions</td>
258 <td><div class="inputbox"> 258 <td><div class="inputbox">
259 <input type="checkbox" class="checkbox" name="sgWldRead" checked="true"/> Read 259 <input type="checkbox" class="checkbox" name="sgWldRead" checked="true"/> Read
260 <input type="checkbox" class="checkbox" name="sgWldEdit" /> Edit 260 <input type="checkbox" class="checkbox" name="sgWldEdit" /> Edit
261 <input type="checkbox" class="checkbox" name="sgWldAdd" /> Add 261 <input type="checkbox" class="checkbox" name="sgWldAdd" /> Add
262 <input type="checkbox" class="checkbox" name="sgWldDelete" /> Delete 262 <input type="checkbox" class="checkbox" name="sgWldDelete" /> Delete
263 </div></td> 263 </div></td>
264 </tr> 264 </tr>
265 </table> 265 </table>
266   266  
267   267  
268 <p>Please note that while the script will create backups of your metadata files 268 <p>Please note that while the script will create backups of your metadata files
269 it is highly recommended that you create your own backups for added security.</p> 269 it is highly recommended that you create your own backups for added security.</p>
270   270  
271 <input type="submit" class="button" value="Go" /></p> 271 <input type="submit" class="button" value="Go" /></p>
272 </form> 272 </form>
273 <?php } ?> 273 <?php } ?>
274   274  
275 <p><a href="index.html">Return</a> to tools.</p> 275 <p><a href="index.html">Return</a> to tools.</p>
276   276  
277 </body> 277 </body>
278 </html> 278 </html>