Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
/*************************
3
  Coppermine Photo Gallery
4
  ************************
5
  Copyright (c) 2003-2005 Coppermine Dev Team
6
  v1.1 originaly written by Gregory DEMAR
7
 
8
  This program is free software; you can redistribute it and/or modify
9
  it under the terms of the GNU General Public License as published by
10
  the Free Software Foundation; either version 2 of the License, or
11
  (at your option) any later version.
12
  ********************************************
13
  Coppermine version: 1.3.3
14
  $Source: /cvsroot/coppermine/stable/searchnew.php,v $
15
  $Revision: 1.10 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:11 $
18
**********************************************/
19
 
20
define('IN_COPPERMINE', true);
21
define('SEARCHNEW_PHP', true);
22
 
23
require('include/init.inc.php');
24
 
25
if (!GALLERY_ADMIN_MODE) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
26
 
27
/**
28
 * Local functions definition
29
 */
30
 
31
/**
32
 * albumselect()
33
 *
34
 * return the HTML code for a listbox with name $id that contains the list
35
 * of all albums
36
 *
37
 * @param string $id the name of the listbox
38
 * @return the HTML code
39
 */
40
function albumselect($id = "album")
41
{
42
    global $CONFIG, $lang_search_new_php;
43
    static $select = "";
44
 
45
    if ($select == "") {
46
        $result = db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = 0 ORDER BY title");
47
        $rowset = db_fetch_rowset($result);
48
        mysql_free_result($result);
49
 
50
        $result = db_query("SELECT DISTINCT a.aid as aid, a.title as title, c.name as cname FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" . FIRST_USER_CAT . "' ORDER BY cname,title");
51
        while ($row = mysql_fetch_array($result)) {
52
            $row['title'] = $row['cname'] . " - " . $row['title'];
53
            $rowset[] = $row;
54
        }
55
        mysql_free_result($result);
56
 
57
        if (defined('UDB_INTEGRATION')) {
58
            $sql = udb_get_admin_album_list();
59
        } else {
60
            $sql = "SELECT aid, CONCAT('(', user_name, ') ', title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_USERS']} AS u ON category = (" . FIRST_USER_CAT . " + user_id) " . "ORDER BY title";
61
        }
62
        $result = db_query($sql);
63
        while ($row = mysql_fetch_array($result)) $rowset[] = $row;
64
        mysql_free_result($result);
65
 
66
        $select = '<option value="0">' . $lang_search_new_php['select_album'] . '</option>\n';
67
 
68
        foreach ($rowset as $row) {
69
            $select .= "<option value=\"" . $row["aid"] . "\">" . $row["title"] . "</option>\n";
70
        }
71
    }
72
 
73
    return "\n<select name=\"$id\" class=\"listbox\">\n$select</select>\n";
74
}
75
 
76
/**
77
 * dirheader()
78
 *
79
 * return the HTML code for the row to be displayed when we start a new
80
 * directory
81
 *
82
 * @param  $dir the directory
83
 * @param  $dirid the name of the listbox that will list the albums
84
 * @return the HTML code
85
 */
86
function dirheader($dir, $dirid)
87
{
88
    global $CONFIG, $lang_search_new_php;
89
    $warning = '';
90
 
91
    if (!is_writable($CONFIG['fullpath'] . $dir))
92
        $warning = "<tr><td class=\"tableh2\" valign=\"middle\" colspan=\"3\">\n" . "<b>{$lang_search_new_php['warning']}</b>: {$lang_search_new_php['change_perm']}</td></tr>\n";
93
    return "<tr><td class=\"tableh2\" valign=\"middle\" colspan=\"3\">\n" .
94
    sprintf($lang_search_new_php['target_album'], $dir, albumselect($dirid)) . "</td></tr>\n" . $warning;
95
}
96
 
97
/**
98
 * picrow()
99
 *
100
 * return the HTML code for a row to be displayed for an image
101
 * the row contains a checkbox, the image name, a thumbnail
102
 *
103
 * @param  $picfile the full path of the file that contains the picture
104
 * @param  $picid the name of the check box
105
 * @return the HTML code
106
 */
107
function picrow($picfile, $picid, $albid)
108
{
109
    global $CONFIG, $expic_array;
110
 
111
    $encoded_picfile = base64_encode($picfile);
112
    $picname = $CONFIG['fullpath'] . $picfile;
113
    $pic_url = urlencode($picfile);
114
    $pic_fname = basename($picfile);
115
    $pic_dirname = dirname($picname);
116
 
117
    $thumb_file = dirname($picname) . '/' . $CONFIG['thumb_pfx'] . $pic_fname;
118
    if (file_exists($thumb_file)) {
119
        $thumb_info = getimagesize($picname);
120
        $thumb_size = compute_img_size($thumb_info[0], $thumb_info[1], 48);
121
        $img = '<img src="' . path2url($thumb_file) . '" ' . $thumb_size['geom'] . ' class="thumbnail" border="0" />';
122
    } elseif (is_image($picname)) {
123
        $img = '<img src="showthumb.php?picfile=' . $pic_url . '&size=48" class="thumbnail" border="0">';
124
    } else {
125
        $file['filepath'] = $pic_dirname.'/'; //substr($picname,0,strrpos($picname,'/'))
126
        $file['filename'] = $pic_fname;
127
        $filepathname = get_pic_url($file,'thumb');
128
        //$mime_content = get_type($picname);
129
        //$extension = file_exists("images/thumb_{$mime_content['extension']}.jpg") ? $mime_content['extension']:$mime_content['content'];
130
        //$img = '<img src="images/thumb_'.$extension.'.jpg" class="thumbnail" width="48" border="0">';
131
        $img = '<img src="'.$filepathname.'" class="thumbnail" width="48" border="0">';
132
    }
133
 
134
    if (filesize($picname) && is_readable($picname)) {
135
        //$fullimagesize = getimagesize($picname); COMMENTED OUT FOR VIDEO SUPPORT
136
        $winsizeX = ($fullimagesize[0] + 16);
137
        $winsizeY = ($fullimagesize[1] + 16);
138
 
139
        //$checked = isset($expic_array[$picfile]) || !$fullimagesize ? '' : 'checked';
140
 
141
        $checked = isset($expic_array[$picfile]) ? '' : 'checked';
142
 
143
        return <<<EOT
144
        <tr>
145
                <td class="tableb" valign="middle">
146
                        <input name="pics[]" id="picselector" type="checkbox" value="$picid" $checked />
147
                        <input name="album_lb_id_$picid" type="hidden" value="$albid" />
148
                        <input name="picfile_$picid" type="hidden" value="$encoded_picfile" />
149
                </td>
150
                <td class="tableb" valign="middle" width="100%">
151
                        <a href="javascript:;" onClick= "MM_openBrWindow('displayimage.php?&fullsize=1&picfile=$pic_url', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width=$winsizeX, height=$winsizeY')">$pic_fname</a>
152
                </td>
153
                <td class="tableb" valign="middle" align="center">
154
                        <a href="javascript:;" onClick= "MM_openBrWindow('displayimage.php?&fullsize=1&picfile=$pic_url', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width=$winsizeX, height=$winsizeY')"><img src="images/spacer.gif" width="1" height="48" alt="" border="0" />$img<br /></a>
155
                </td>
156
        </tr>
157
EOT;
158
    } else {
159
        $winsizeX = (300);
160
        $winsizeY = (300);
161
        return <<<EOT
162
        <tr>
163
                <td class="tableb" valign="middle">
164
                        &nbsp;
165
                </td>
166
                <td class="tableb" valign="middle" width="100%">
167
                        <i>$pic_fname</i>
168
                </td>
169
                <td class="tableb" valign="middle" align="center">
170
                        <a href="javascript:;" onClick= "MM_openBrWindow('displayimage.php?&fullsize=1&picfile=$pic_url', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width=$winsizeX, height=$winsizeY')"><img src="showthumb.php?picfile=$pic_url&size=48" class="thumbnail" border="0" /><br /></a>
171
                </td>
172
        </tr>
173
EOT;
174
    }
175
}
176
 
177
/**
178
 * getfoldercontent()
179
 *
180
 * return the files and directories of a folder in two arrays
181
 *
182
 * @param  $folder the folder to read
183
 * @param  $dir_array the array that will contain name of sub-dir
184
 * @param  $pic_array the array that will contain name of picture
185
 * @param  $expic_array an array that contains pictures already in db
186
 * @return
187
 */
188
function getfoldercontent($folder, &$dir_array, &$pic_array, &$expic_array)
189
{
190
    global $CONFIG;
191
    $dir = opendir($CONFIG['fullpath'] . $folder);
192
    while ($file = readdir($dir)) {
193
        if (is_dir($CONFIG['fullpath'] . $folder . $file)) {
194
            if ($file != "." && $file != "..")
195
                $dir_array[] = $file;
196
        }
197
        if (is_file($CONFIG['fullpath'] . $folder . $file)) {
198
            if (strncmp($file, $CONFIG['thumb_pfx'], strlen($CONFIG['thumb_pfx'])) != 0 && strncmp($file, $CONFIG['normal_pfx'], strlen($CONFIG['normal_pfx'])) != 0 && $file != 'index.html')
199
                $pic_array[] = $file;
200
        }
201
    }
202
    closedir($dir);
203
 
204
    natcasesort($dir_array);
205
    natcasesort($pic_array);
206
}
207
 
208
function display_dir_tree($folder, $ident)
209
{
210
    global $CONFIG, $PHP_SELF, $lang_search_new_php;
211
    $dir_path = $CONFIG['fullpath'] . $folder;
212
 
213
 
214
    if (!is_readable($dir_path)) return;
215
 
216
    $dir = opendir($dir_path);
217
    while ($file = readdir($dir)) {
218
        //if (is_dir($CONFIG['fullpath'] . $folder . $file) && $file != "." && $file != "..") { // removed by following line for 'do not show folders with dots': gaugau 03-11-02
219
        if (is_dir($CONFIG['fullpath'] . $folder . $file) && substr($file,0,1) != "." && strpos($file,"'") == FALSE && $file != substr($CONFIG['userpics'],0,strlen($CONFIG['userpics'])-1)  && $file != "edit" ) {
220
            $start_target = $folder . $file;
221
            $dir_path = $CONFIG['fullpath'] . $folder . $file;
222
 
223
            $warnings = '';
224
            if (!is_writable($dir_path)) $warnings .= $lang_search_new_php['dir_ro'];
225
            if (!is_readable($dir_path)) $warnings .= $lang_search_new_php['dir_cant_read'];
226
 
227
            if ($warnings) $warnings = '&nbsp;&nbsp;&nbsp;<b>' . $warnings . '<b>';
228
 
229
            echo <<<EOT
230
                        <tr>
231
                                <td class="tableb">
232
                                        $ident<img src="images/folder.gif" alt="" />&nbsp;<a href= "$PHP_SELF?startdir=$start_target">$file</a>$warnings
233
                                </td>
234
                        </tr>
235
EOT;
236
            display_dir_tree($folder . $file . '/', $ident . '&nbsp;&nbsp;&nbsp;&nbsp;');
237
        }
238
    }
239
    closedir($dir);
240
}
241
 
242
/**
243
 * getallpicindb()
244
 *
245
 * Fill an array where keys are the full path of all images in the picture table
246
 *
247
 * @param  $pic_array the array to be filled
248
 * @return
249
 */
250
function getallpicindb(&$pic_array, $startdir)
251
{
252
    global $CONFIG;
253
 
254
    $sql = "SELECT filepath, filename " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE filepath LIKE '$startdir%'";
255
    $result = db_query($sql);
256
    while ($row = mysql_fetch_array($result)) {
257
        $pic_file = $row['filepath'] . $row['filename'];
258
        $pic_array[$pic_file] = 1;
259
    }
260
    mysql_free_result($result);
261
}
262
 
263
/**
264
 * getallalbumsindb()
265
 *
266
 * Fill an array with all albums where keys are aid of albums and values are
267
 * album title
268
 *
269
 * @param  $album_array the array to be filled
270
 * @return
271
 */
272
function getallalbumsindb(&$album_array)
273
{
274
    global $CONFIG;
275
 
276
    $sql = "SELECT aid, title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "WHERE 1";
277
    $result = db_query($sql);
278
 
279
    while ($row = mysql_fetch_array($result)) {
280
        $album_array[$row['aid']] = $row['title'];
281
    }
282
    mysql_free_result($result);
283
}
284
 
285
/**
286
 * CPGscandir() //renamed because php5 has same function as scandir()
287
 *
288
 * recursive function that scan a directory, create the HTML code for each
289
 * picture and add new pictures in an array
290
 *
291
 * @param  $dir the directory to be scanned
292
 * @param  $expic_array the array that contains pictures already in DB
293
 * @param  $newpic_array the array that contains new pictures found
294
 * @return
295
 */
296
function CPGscandir($dir, &$expic_array)
297
{
298
        $dir = str_replace(".","" ,$dir);
299
    static $dir_id = 0;
300
    static $count = 0;
301
    static $pic_id = 0;
302
 
303
    $pic_array = array();
304
    $dir_array = array();
305
 
306
    getfoldercontent($dir, $dir_array, $pic_array, $expic_array);
307
 
308
    if (count($pic_array) > 0) {
309
        $dir_id_str = sprintf("d%04d", $dir_id++);
310
        echo dirheader($dir, $dir_id_str);
311
        foreach ($pic_array as $picture) {
312
            $count++;
313
            $pic_id_str = sprintf("i%04d", $pic_id++);
314
            echo picrow($dir . $picture, $pic_id_str, $dir_id_str);
315
        }
316
    }
317
    if (count($dir_array) > 0) {
318
        foreach ($dir_array as $directory) {
319
            if (substr($directory,0,1) != ".") // added do not show folders with dots: gaugau 03-11-02
320
            CPGscandir($dir . $directory . '/', $expic_array);
321
        }
322
    }
323
    return $count;
324
}
325
 
326
/**
327
 * Main code
328
 */
329
 
330
$album_array = array();
331
getallalbumsindb($album_array);
332
// We need at least one album
333
if (!count($album_array)) cpg_die(ERROR, $lang_search_new_php['need_one_album'], __FILE__, __LINE__);
334
 
335
if (isset($HTTP_POST_VARS['insert'])) {
336
    if (!isset($HTTP_POST_VARS['pics'])) cpg_die(ERROR, $lang_search_new_php['no_pic_to_add'], __FILE__, __LINE__);
337
 
338
    pageheader($lang_search_new_php['page_title']);
339
    starttable("100%");
340
    echo <<<EOT
341
        <tr>
342
                <td colspan="4" class="tableh1"><h2>{$lang_search_new_php['insert']}</h2></td>
343
        </tr>
344
        <tr>
345
                <td class="tableh2" valign="middle" align="center"><b>{$lang_search_new_php['folder']}</b></td>
346
                <td class="tableh2" valign="middle" align="center"><b>{$lang_search_new_php['image']}</b></td>
347
                <td class="tableh2" valign="middle" align="center"><b>{$lang_search_new_php['album']}</b></td>
348
                <td class="tableh2" valign="middle" align="center"><b>{$lang_search_new_php['result']}</b></td>
349
        </tr>
350
EOT;
351
 
352
    $count = 0;
353
    foreach ($HTTP_POST_VARS['pics'] as $pic_id) {
354
        $album_lb_id = $HTTP_POST_VARS['album_lb_id_' . $pic_id];
355
        $album_id = $HTTP_POST_VARS[$album_lb_id];
356
 
357
        $pic_file = base64_decode($HTTP_POST_VARS['picfile_' . $pic_id]);
358
        $dir_name = dirname($pic_file) . "/";
359
        $file_name = basename($pic_file);
360
 
361
        if ($album_id) {
362
            // To avoid problems with PHP scripts max execution time limit, each picture is
363
            // added individually using a separate script that returns an image
364
            $status = "<a href=\"addpic.php?aid=$album_id&pic_file=" . ($HTTP_POST_VARS['picfile_' . $pic_id]) . "&reload=" . uniqid('') . "\"><img src=\"addpic.php?aid=$album_id&pic_file=" . ($HTTP_POST_VARS['picfile_' . $pic_id]) . "&reload=" . uniqid('') . "\" class=\"thumbnail\" border=\"0\" width=\"24\" height=\"24\" alt=\"\" /><br /></a>";
365
            $album_name = $album_array[$album_id];
366
        } else {
367
            $album_name = $lang_search_new_php['no_album'];
368
            $status = "<img src=\"images/up_na.gif\" alt=\"" . $lang_search_new_php['no_album'] . "\" class=\"thumbnail\" border=\"0\" width=\"24\" height=\"24\" /><br />";
369
        }
370
        echo "<tr>\n";
371
        echo "<td class=\"tableb\" valign=\"middle\" align=\"left\">$dir_name</td>\n";
372
        echo "<td class=\"tableb\" valign=\"middle\" align=\"left\">$file_name</td>\n";
373
        echo "<td class=\"tableb\" valign=\"middle\" align=\"left\">$album_name</td>\n";
374
        echo "<td class=\"tableb\" valign=\"middle\" align=\"center\">$status</td>\n";
375
        echo "</tr>\n";
376
        $count++;
377
        flush();
378
    }
379
    echo <<<EOT
380
        <tr>
381
                <td class="tableh2" colspan="4">
382
                        <b>{$lang_search_new_php['be_patient']}</b>
383
                </td>
384
        </tr>
385
        <tr>
386
                <td class="tableb" colspan="4">
387
                        {$lang_search_new_php['notes']}
388
                </td>
389
        </tr>
390
 
391
EOT;
392
    endtable();
393
    pagefooter();
394
    ob_end_flush();
395
} elseif (isset($HTTP_GET_VARS['startdir'])) {
396
    pageheader($lang_search_new_php['page_title']);
397
    starttable("100%");
398
    echo <<<EOT
399
        <form method="post" action="$PHP_SELF?insert=1" name="selectPics">
400
        <tr>
401
                <td colspan="3" class="tableh1"><h2>{$lang_search_new_php['list_new_pic']}</h2></td>
402
        </tr>
403
 
404
EOT;
405
    $expic_array = array();
406
    $check_all = $lang_search_new_php['check_all'];
407
    $uncheck_all = $lang_search_new_php['uncheck_all'];
408
    // added below table, JavaScript and additional check/uncheck options: gaugau 03-11-02
409
 
410
    getallpicindb($expic_array, $HTTP_GET_VARS['startdir']);
411
    if (CPGscandir($HTTP_GET_VARS['startdir'] . '/', $expic_array)) {
412
 
413
        echo <<<EOT
414
        <tr>
415
                <td colspan="3" align="center" class="tablef">
416
                                <script language="javascript" type="text/javascript">
417
                                <!--
418
                                function checkAll(field)
419
                                {
420
                                for (i = 0; i < field.length; i++)
421
                                  field[i].checked = true ;
422
                                }
423
 
424
                                function uncheckAll(field)
425
                                {
426
                                for (i = 0; i < field.length; i++)
427
                                  field[i].checked = false ;
428
                                }
429
                                -->
430
                                </script>
431
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
432
                        <tr>
433
                        <td align="left">
434
                        <input type="button" name="CheckAll" class="button" value="$check_all" onClick="checkAll(document.selectPics.picselector)">
435
                        <input type="button" name="UnCheckAll" class="button" value="$uncheck_all" onClick="uncheckAll(document.selectPics.picselector)">
436
                        </td>
437
                        <td align="center">
438
                        <input type="submit" class="button" name="insert" value="{$lang_search_new_php['insert_selected']}">
439
                        </td>
440
                        </tr>
441
                        </table>
442
                </td>
443
        </tr>
444
        </form>
445
 
446
EOT;
447
    } else {
448
        echo <<<EOT
449
        <tr>
450
                <td colspan="3" align="center" class="tableb">
451
                        <br /><br />
452
                        <b>{$lang_search_new_php['no_pic_found']}</b>
453
                        <br /><br /><br />
454
                </td>
455
        </tr>
456
        </form>
457
 
458
EOT;
459
    }
460
    endtable();
461
    pagefooter();
462
    ob_end_flush();
463
} else {
464
    pageheader($lang_search_new_php['page_title']);
465
    starttable(-1, $lang_search_new_php['select_dir']);
466
    display_dir_tree('', '');
467
    echo <<<EOT
468
        <tr>
469
                <td class="tablef">
470
                        <b>{$lang_search_new_php['select_dir_msg']}</b>
471
                </td>
472
        </tr>
473
 
474
EOT;
475
    endtable();
476
    pagefooter();
477
    ob_end_flush();
478
}
479
 
480
?>