"Tofu_Session", "auth" => "Tofu_Default_Auth", "perm" => "Tofu_Perm", "user" => "Tofu_User")); //$auth->login_if(! $perm->have_perm('user')); // login if not authenticated as a user function edit($row) { echo "
\n"; echo "" . $row['caption'] . "
\n"; } function compactView($row) { static $count; if ($count++ < 1) { echo "At the moment you can only upload a .jpg "; echo "no larger than " . $GLOBALS[cfgImg]['max_size'] . " bytes.
"; } } function saveImage($type, $type_id) { if ($GLOBALS['userfile_size'] > $GLOBALS[cfgImg]['max_size']) { echo "Your image is too big. Sorry."; } else { // um, need mime logic to deduce the file extension $ext = $GLOBALS['userfile_type']; if (eregi("^image", $ext)) { // it is an image $ext = ereg_replace("^image/","",$ext); // come back here and fix this $ext = 'jpg'; } else { // it is not an image echo "Your file is not an image. Sorry."; } // reading the whole file may be slow $fin = fopen($GLOBALS['userfile'], 'r'); #$file_out = '/home/dale/www/admin.tofuguide.com/upload/' . $type . '-' . $type_id . '.jpg'; $file_out = '/home/dale/www/admin.tofuguide.com/upload/' . $type . '-' . $type_id . '.' . $ext; $fout = @fopen($file_out, 'w'); if (! $fout) { // problem writing file echo "Problem writing file to server!"; $msg = "ERROR failed to write $type image from " . $GLOBALS['auth']->auth['uname'] . " @ " . $GLOBALS['REMOTE_HOST'] . " in\n\t $file_out " . $userfile_type; mail('webmaster@tofuguide.com', 'ERROR TofuGuide image', $msg); return; } $file_content = fread( $fin, filesize( $GLOBALS['userfile'] ) ); fputs($fout,$file_content,strlen($file_content)); // probably bad to read the whole file copy("/home/dale/www/www.tofuguide.com/image/image-pending.jpg", "/home/dale/www/www.tofuguide.com/image/" . $type . '-' . $type_id . '.jpg'); $msg = "New $type image from " . $GLOBALS['auth']->auth['uname'] . " @ " . $GLOBALS['REMOTE_HOST'] . " in\n\t $file_out " . $userfile_type; mail('webmaster@tofuguide.com', 'new TofuGuide image', $msg); // first check to see if an image already exists for this type_id $sql = "select image_id from " . $type . "_image where " . $type . "_id = " . $type_id; $res = run_query($sql); $row = mysql_fetch_array($res); if ($row['image_id']) { echo "Image #" . $row['image_id'] . " already exists."; } else { //echo "image type is " . $image_type; $sql = "insert into image (name, type) values ('" . $type . "-" . $type_id . ".jpg', '" . $type . "')"; $res = run_query($sql); $image_id = mysql_insert_id(); $sql = "insert into " . $type . "_image (image_id, " . $type . "_id) values ($image_id, $type_id)"; $res = run_query($sql); $mode = 'edit'; return $image_id; } } } //--------------- main program include("lib.tofuguide.php3"); include("db.inc.php3"); $tables = parse_tables(); if ($mode == 'add') { // add the image and the glue record, then call edit to add captions // must have type (user, restaurant) and id $title = "Add Image"; include("header.inc.php3"); addImage($type, $type_id); } else if ($mode == 'save') { $id = saveImage($type, $type_id); $title = "Save and Edit Image"; include("header.inc.php3"); if (! empty($id)) { echo "Your image has been queued for approval. Please add a caption if appropriate.
\n"; edit(load($id)); } } else if ($mode == 'edit') { $auth->login_if(! $perm->have_perm('user')); if ($submit == 'Update') { if (($tables['image']['contributor_id'] != $auth->auth['tofu_id']) && (! $GLOBALS['perm'] ->have_perm('admin')) ) { include("header.inc.php3"); echo "You don't have permission to do this!"; echo "tables image contributor_id is -> ". $tables['image']['contributor_id']; echo "