C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\4images\admin\checkimages.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: checkimages.php                                      *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.1                                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/

define('IN_CP', 1);
define('ROOT_PATH', './../');
require(
'admin_global.php');

include(
ROOT_PATH.'includes/search_utils.php');

if (
$action == "") {
  
$action = "checkimages";
}

show_admin_header();

if (
$action == "savenewimages") {
  @include(
ROOT_PATH."includes/db_field_definitions.php");

  
$date = time();
  
$error = array();
  
$num_newimages = $HTTP_POST_VARS['num_newimages'];
  
$detailed = $HTTP_POST_VARS['detailed'];

  for (
$i = 1; $i <= $num_newimages; $i++) {
    
$addimage = (isset($HTTP_POST_VARS['addimage_'.$i]) && $HTTP_POST_VARS['addimage_'.$i] == 1) ? 1 : 0;
    if (
$addimage) {
      
$image_name = trim($HTTP_POST_VARS['image_name_'.$i]);
      
$cat_id = intval($HTTP_POST_VARS['cat_id_'.$i]);
      
$image_download_url = (isset($HTTP_POST_VARS['image_download_url_'.$i])) ? trim($HTTP_POST_VARS['image_download_url_'.$i]) : "";

      if (
$image_name == "") {
        
$error['image_name_'.$i] = 1;
      }
      if (
$cat_id == 0) {
        
$error['cat_id_'.$i] = 1;
      }
      if (
$image_download_url != "" && !is_remote($image_download_url) && !is_local_file($image_download_url)) {
        
$error['image_download_url_'.$i] = 1;
      }

      if (!empty(
$additional_image_fields)) {
        foreach (
$additional_image_fields as $key => $val) {
          if (isset(
$HTTP_POST_VARS[$key.'_'.$i]) && intval($val[2]) == 1 && trim($HTTP_POST_VARS[$key.'_'.$i]) == "") {
            
$error[$key.'_'.$i] = 1;
          }
        }
      }
    }
  }
  if (empty(
$error)) {
    
$log = array();
    for (
$i = 1; $i <= $num_newimages; $i++) {
      
$addimage = (isset($HTTP_POST_VARS['addimage_'.$i]) && $HTTP_POST_VARS['addimage_'.$i] == 1) ? 1 : 0;
      if (
$addimage) {
        
$image_media_file = trim($HTTP_POST_VARS['image_media_file_'.$i]);
        
$image_thumb_file = trim($HTTP_POST_VARS['image_thumb_file_'.$i]);
        
$image_name = trim($HTTP_POST_VARS['image_name_'.$i]);

        
$cat_id = intval($HTTP_POST_VARS['cat_id_'.$i]);
        
$old_cat_id = intval($HTTP_POST_VARS['old_cat_id_'.$i]);

        
$user_id = (isset($HTTP_POST_VARS['user_id_'.$i]) && intval($HTTP_POST_VARS['user_id_'.$i]) != 0) ? intval($HTTP_POST_VARS['user_id_'.$i]) : $user_info['user_id'];

        
$image_description = (isset($HTTP_POST_VARS['image_description_'.$i])) ? trim($HTTP_POST_VARS['image_description_'.$i]) : "";
        
$image_date = (!isset($HTTP_POST_VARS['image_date_'.$i])) ? time() : ((trim($HTTP_POST_VARS['image_date_'.$i] != "")) ? "UNIX_TIMESTAMP('".trim($HTTP_POST_VARS['image_date_'.$i])."')" : time());
        
$image_download_url = (isset($HTTP_POST_VARS['image_download_url_'.$i])) ? trim($HTTP_POST_VARS['image_download_url_'.$i]) : "";

        if (isset(
$HTTP_POST_VARS['image_keywords_'.$i])) {
          
$image_keywords = trim($HTTP_POST_VARS['image_keywords_'.$i]);
          
$image_keywords = preg_replace("/[\n\r]/is", " ", $image_keywords);
          
$image_keywords = str_replace(","," ",$image_keywords);
          
$image_keywords = ereg_replace("( ){2,}", " ", $image_keywords);
        }
        else {
          
$image_keywords = "";
        }
        
$image_active = intval($HTTP_POST_VARS['image_active_'.$i]);
        
$image_allow_comments = intval($HTTP_POST_VARS['image_allow_comments_'.$i]);

        
$additional_field_sql = "";
        
$additional_value_sql = "";
        if (!empty(
$additional_image_fields)) {
          
$table_fields = $site_db->get_table_fields(IMAGES_TABLE);
          foreach (
$additional_image_fields as $key => $val) {
            if (isset(
$HTTP_POST_VARS[$key.'_'.$i]) && isset($table_fields[$key])) {
              
$additional_field_sql .= ", $key";
              
$additional_value_sql .= ", '".un_htmlspecialchars(trim($HTTP_POST_VARS[$key.'_'.$i]))."'";
            }
          }
        }

        if (
$cat_id != $old_cat_id) {
          
$image_media_file = copy_media($image_media_file, $old_cat_id, $cat_id);
          
$image_thumb_file = copy_thumbnail($image_media_file, $image_thumb_file, $old_cat_id, $cat_id);
        }

        
$sql = "INSERT INTO ".IMAGES_TABLE."
                (cat_id, user_id, image_name, image_description, image_keywords, image_date, image_active, image_media_file, image_thumb_file, image_download_url, image_allow_comments"
.$additional_field_sql.")
                VALUES
                (
$cat_id, $user_id, '$image_name', '$image_description', '$image_keywords', $image_date, $image_active, '$image_media_file', '$image_thumb_file', '$image_download_url', $image_allow_comments".$additional_value_sql.")";
        
$result = $site_db->query($sql);
        
$image_id = $site_db->get_insert_id();

        if (
$result) {
          
$search_words = array();
          foreach (
$search_match_fields as $image_column => $match_column) {
            if (isset(
$HTTP_POST_VARS[$image_column.'_'.$i])) {
              
$search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column.'_'.$i]);
            }
          }
          
add_searchwords($image_id, $search_words);
          
$log[] = $lang['image_add_success'].": <b>".stripslashes($image_name)."</b> ($image_media_file)";
        }
        else {
          
$log[] = $lang['image_add_error'].": <b>$image_media_file</b>";
        }
      }
    }

    
show_table_header($lang['nav_images_check'], 1);
    echo 
"<tr>\n<td class=\"tablerow\">\n";
    echo 
"<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr><td>&nbsp;</td><td>\n";
    if (!empty(
$log)) {
      foreach (
$log as $val) {
        echo 
$val."<br />";
      }
    }
    else {
      echo 
$lang['no_newimages_added'];
    }
    echo 
"</td>\n</tr>\n</table>\n";
    echo 
"</td>\n</tr>\n";
    
show_table_footer();
  }
  else {
    
$msg = sprintf("<span class=\"marktext\">%s</span>", $lang['lostfield_error']);
    
$action = "checkimages";
  }
}

if (
$action == "checkimages") {
  
$cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : 0;
  
$detailed_checked = (isset($HTTP_POST_VARS['detailed']) && $HTTP_POST_VARS['detailed'] == 1) ? " checked=\"checked\"" : "";
  
$num_newimages = (isset($HTTP_POST_VARS['num_newimages'])) ? intval($HTTP_POST_VARS['num_newimages']) : 30;
  if (
$num_newimages == "" || !$num_newimages) {
    
$num_newimages = 30;
  }
  
show_form_header("checkimages.php", "checkimages");
  
show_table_header($lang['nav_images_check'], 2);
  
$desc = get_category_dropdown($cat_id, 0, 4);
  
$desc .= "&nbsp;&nbsp;&nbsp;&nbsp;".$lang['num_newimages_desc']."<input type=\"text\" name=\"num_newimages\" value=\"".$num_newimages."\" size=\"5\">";
  
$desc .= "&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"checkbox\" name=\"detailed\" value=\"1\"".$detailed_checked.">".$lang['detailed_version'];
  
show_custom_row($desc, "<input type=\"submit\" value=\"".$lang['nav_images_check']."\" class=\"button\">");
  
show_table_footer();
  echo 
"</form>";
}

if (isset(
$HTTP_POST_VARS['action']) && $action == "checkimages") {
  if (isset(
$HTTP_POST_VARS['detailed']) && $HTTP_POST_VARS['detailed'] == 1) {
    
$detailed = 1;
    
$colspan = 2;
  }
  else {
    
$detailed = 0;
    
$colspan = 6;
  }

  
$cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : 0;
  
$cat_path = ($cat_id == 0) ? "" : "/".$cat_id;

  
$handle = opendir(MEDIA_PATH.$cat_path);
  
$image_list_all = array();
  while (
$file = @readdir($handle)) {
    if (
$file != "." && $file != "..") {
      if (
check_media_type($file)) {
        
$image_list_all[] = $file;
      }
    }
  }
  
sort($image_list_all);

  
$where_sql = ($cat_id != 0) ? "WHERE cat_id = $cat_id" : "";
  
$sql = "SELECT image_media_file
          FROM "
.IMAGES_TABLE."
          
$where_sql
          ORDER BY image_media_file"
;
  
$result = $site_db->query($sql);

  
$image_list_sql = array();
  while (
$row = $site_db->fetch_array($result)) {
    
$image_list_sql[] = $row['image_media_file'];
  }
  
sort($image_list_sql);

  
$image_list = array();
  
$image_counter = 0;
  for (
$i = 0; $i < count($image_list_all); $i++) {
    if (!
in_array($image_list_all[$i], $image_list_sql)) {
      
$image_list[] = $image_list_all[$i];
      
$image_counter++;
    }
    if (
$image_counter == $num_newimages) {
      break;
    }
  }
  
sort($image_list);

  
$num_all_newimages = sizeof($image_list);

  if (
$num_newimages > $num_all_newimages) {
    
$num_newimages = $num_all_newimages;
  }

  if (
$msg != "") {
    
printf("<b>%s</b>\n", $msg);
  }

  
printf ("<p>%s</p>\n", preg_replace("/".$site_template->start."num_all_newimages".$site_template->end."/siU", $num_all_newimages, $lang['checkimages_note']));

  
show_form_header("checkimages.php", "savenewimages", "form");
  
show_hidden_input("cat_id", $cat_id);
  
show_table_header($lang['nav_images_check'], $colspan);

  if (
$num_all_newimages) {
    
show_description_row("<input name=\"allbox\" type=\"checkbox\" onClick=\"CheckAll();\" checked=\"checked\" /> <b>".$lang['check_all']."</b>", $colspan);
  }
  else {
    
show_description_row($lang['no_newimages'], $colspan);
  }

  for (
$i = 1; $i <= $num_newimages; $i++) {
    
//Check Image
    
$file_type = get_file_extension($image_list[$i-1]);
    
$image_name = get_file_name($image_list[$i-1]);

    
$thumb_file = 0;
    if (
file_exists(THUMB_PATH.$cat_path."/".$image_name.".jpg")) {
      
$thumb_file = $image_name.".jpg";
    }
    elseif (
file_exists(THUMB_PATH.$cat_path."/".$image_name.".JPG")) {
      
$thumb_file = $image_name.".JPG";
    }
    elseif (
file_exists(THUMB_PATH.$cat_path."/".$image_name.".jpeg")) {
      
$thumb_file = $image_name.".jpeg";
    }
    elseif (
file_exists(THUMB_PATH.$cat_path."/".$image_name.".JPEG")) {
      
$thumb_file = $image_name.".JPEG";
    }
    elseif (
file_exists(THUMB_PATH.$cat_path."/".$image_name.".gif")) {
      
$thumb_file = $image_name.".gif";
    }
    elseif (
file_exists(THUMB_PATH.$cat_path."/".$image_name.".GIF")) {
      
$thumb_file = $image_name.".GIF";
    }
    elseif (
file_exists(THUMB_PATH.$cat_path."/".$image_name.".png")) {
      
$thumb_file = $image_name.".png";
    }
    elseif (
file_exists(THUMB_PATH.$cat_path."/".$image_name.".PNG")) {
      
$thumb_file = $image_name.".PNG";
    }

    
$checked = (isset($HTTP_POST_VARS['image_name_'.$i]) && (!isset($HTTP_POST_VARS['addimage_'.$i]) || $HTTP_POST_VARS['addimage_'.$i] != 1)) ? "" : " checked=\"checked\"";

    if (
$detailed) {
      
show_table_separator("<input type=\"checkbox\" name=\"addimage_".$i."\" value=\"1\"".$checked." /> ".$image_list[$i-1], 2);
      if (
$file_type == "gif" || $file_type == "jpg"  || $file_type == "png") {
        
$file_src = MEDIA_PATH.$cat_path."/".$image_list[$i-1];
        
show_image_row($lang['image'], $file_src, 1);
      }
      else {
        
show_image_row($lang['image'], ICON_PATH."/".$file_type.".gif", 1);
      }
      
show_hidden_input("image_media_file_".$i, $image_list[$i-1]);

      if (
$thumb_file) {
        
show_image_row($lang['thumb'], THUMB_PATH.$cat_path."/".$thumb_file, 1, "", 50);
        
show_hidden_input("image_thumb_file_".$i, $thumb_file);
      }
      else {
        
show_custom_row($lang['thumb'], $lang['no_thumb_newimages_ext']);
        
show_hidden_input("image_thumb_file_".$i, "");
      }
      
show_input_row($lang['field_download_url'].$lang['download_url_desc'], "image_download_url_".$i, "", $textinput_size);

      
$image_name = (isset($error['image_name_'.$i])) ? $HTTP_POST_VARS['image_name_'.$i] : str_replace("_"," ", $image_name);
      
$title = $lang['field_image_name'].((isset($file_src)) ? get_iptc_insert_link($file_src, "object_name", "image_name_".$i, 0) : "");
      
show_input_row($title, "image_name_".$i, $image_name, $textinput_size);

      
$title = $lang['field_description_ext'].((isset($file_src)) ? get_iptc_insert_link($file_src, "caption", "image_description_".$i) : "");
      
show_textarea_row($title, "image_description_".$i, "", $textarea_size);

      
$title = $lang['field_keywords_ext'].((isset($file_src)) ? get_iptc_insert_link($file_src, "keyword", "image_keywords_".$i) : "");
      
show_textarea_row($title, "image_keywords_".$i, "", $textarea_size);

      
show_cat_select_row($lang['field_category'], $cat_id, 3, $i);
      
show_user_select_row($lang['user'], $user_info['user_id'], $i);

      
$date = date("Y-m-d H:i:s", time());
      
$title = $lang['field_date'].$lang['date_desc'].$lang['date_format'].((isset($file_src)) ? get_iptc_insert_link($file_src, "date_created", "image_date_".$i, 0) : "");
      
show_input_row($title, "image_date_".$i, $date, $textinput_size);

      
show_hidden_input("old_cat_id_".$i, $cat_id);
      
show_radio_row($lang['field_free'], "image_active_".$i, 1);
      
show_radio_row($lang['field_allow_comments'], "image_allow_comments_".$i, 1);
      
show_additional_fields("image", array(), IMAGES_TABLE, $i);
    }
    else {
      echo 
"<tr class=".get_row_bg().">\n";
      echo 
"<td><input type=\"checkbox\" name=\"addimage_".$i."\" value=\"1\"$checked></td>\n";
      
$link = "<a href=\"".MEDIA_PATH.$cat_path."/".$image_list[$i-1]."\" target=\"_blank\">".$image_list[$i-1]."</a>";
      
show_hidden_input("image_media_file_".$i, $image_list[$i-1]);
      if (
$thumb_file) {
        
$thumb_status = $lang['thumb_newimages_exists'];
        
show_hidden_input("image_thumb_file_".$i, $thumb_file);
      }
      else {
        
$thumb_status = $lang['no_thumb_newimages'];
        
show_hidden_input("image_thumb_file_".$i, "");
      }
      echo 
"<td><b>".$link."</b><br />-&raquo; ".$thumb_status."</td>\n";


      if (isset(
$error['image_name_'.$i])) {
        
$lang['field_image_name'] = sprintf("<span class=\"marktext\">%s</span>", $lang['field_image_name']);
        
$image_name = $HTTP_POST_VARS['image_name_'.$i];
      }
      else {
        
$image_name = str_replace("_"," ", $image_name);
      }
      echo 
"<td>".$lang['field_image_name'].":<br /><input type=\"text\" name=\"image_name_".$i."\" value=\"".$image_name."\">\n";
      if (isset(
$error['cat_id_'.$i])) {
        
$lang['field_category'] = sprintf("<span class=\"marktext\">%s</span>", $lang['field_category']);
      }
      
$cat_id = (isset($HTTP_POST_VARS['cat_id_'.$i])) ? intval($HTTP_POST_VARS['cat_id_'.$i]) : $cat_id;
      echo 
"<td>".$lang['field_category'].":<br />".get_category_dropdown($cat_id, 0, 3, $i)."</td>\n";
      
show_hidden_input("old_cat_id_".$i, $cat_id);

      echo 
"<td>".$lang['field_free'].":<br />";
      if (isset(
$HTTP_POST_VARS['image_active_'.$i]) && $HTTP_POST_VARS['image_active_'.$i] == 0) {
        
$c1 = "";
        
$c2 = " checked=\"checked\"";
      }
      else {
        
$c1 = " checked=\"checked\"";
        
$c2 = "";
      }
      echo 
"<input type=\"radio\" name=\"image_active_".$i."\" value=\"1\"".$c1."> ".$lang['yes']."&nbsp;&nbsp;&nbsp;\n";
      echo 
"<input type=\"radio\" name=\"image_active_".$i."\" value=\"0\"".$c2."> ".$lang['no']." ";
      echo 
"</td>\n";

      echo 
"<td>".$lang['field_allow_comments'].":<br />";
      if (isset(
$HTTP_POST_VARS['image_allow_comments_'.$i]) && $HTTP_POST_VARS['image_allow_comments_'.$i] == 0) {
        
$c1 = "";
        
$c2 = " checked=\"checked\"";
      }
      else {
        
$c1 = " checked=\"checked\"";
        
$c2 = "";
      }
      echo 
"<input type=\"radio\" name=\"image_allow_comments_".$i."\" value=\"1\"".$c1."> ".$lang['yes']."&nbsp;&nbsp;&nbsp;\n";
      echo 
"<input type=\"radio\" name=\"image_allow_comments_".$i."\" value=\"0\"".$c2."> ".$lang['no']." ";
      echo 
"</td>\n";
      echo 
"</tr>\n";
    }
  }
  if (
$num_all_newimages) {
    
show_hidden_input("num_newimages", $num_newimages);
    
show_hidden_input("detailed", $detailed);
    
show_form_footer($lang['add'], $lang['reset'], $colspan);
  }
  else {
    
show_table_footer();
  }
}
show_admin_footer();
?>