"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"; list($type, $type_id) = split("-",$row['image_name']); $type_id = preg_replace("/^(\d+)\.\S+/","\\1", $type_id); echo "\n"; // name echo "\n"; echo " \n"; //echo " \n"; echo " \n"; echo "\n\n"; // split image name into 'type', 'id' or if null then give drop down list of user and restaurants // maybe change type to an int and create an image_type table... // type // ok, so what goes here if this is a new image since we can't autoincrement? (turn off editability) // echo "\n"; $res = run_query("select name from " . $type . " where id =" . $type_id); $row2 = mysql_fetch_array($res); echo "\n"; //echo " \n"; echo " \n"; // echo " \n"; echo " \n"; echo "\n\n"; // Alt Text echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // Date echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; // caption echo "\n"; echo " \n"; echo " \n"; echo "\n\n"; if (empty($row['restaurant_date_added']) ) { $date = date('Ymd'); echo " \n"; } // submit echo "\n"; echo " \n"; echo " auth["tofu_id"]; echo "\">\n"; echo " \n"; echo " \n"; echo " \n"; echo "\n\n"; echo "
Name:" . $row['image_name'] . "
" . preg_replace("/^(.)(.+)/",strtoupper("\\1") . "\\2" ,$type) . ":" . $type . ": " . $row2[0] . "
Alt Text:
Date of Pic:
Caption:
\n"; echo "
\n"; echo "
\""
\n"; } // load data about in image into a row array function load($id) { if (! is_numeric($id)) { return ''; } $query ="select image.id as image_id, image.name as image_name, image.date as image_date, image.type as image_type, image.caption as image_caption, image.contributor_id as image_contributor_id, image.alt_text as image_alt_text from image where image.id = $id"; $res = run_query($query); return mysql_fetch_array($res); } // show an image by calling longView or compactView function view($view, $id = '') { $query = "select id, contributor_id, name, date, type, caption, alt_text from image "; if ($id) { $query .= "\n where\n id = $id "; } else { $query .= "\n order by name "; } $res = run_query($query); echo "
\n"; while ($row = mysql_fetch_array($res)) { if ($view == 'long') { longView($row); } else { compactView($row); } } echo "
"; } function longView($row) { list($type, $type_id) = split("-",$row['name']); $type_id = preg_replace("/^(\d+)\.\S+/","\\1", $type_id); echo "" . $row[
\n"; echo "

" . $row['caption'] . "

\n"; } function compactView($row) { static $count; if ($count++ < 1) { echo "\n"; echo " ID\n"; echo " NAME\n"; echo " Date\n"; echo " Caption\n"; echo " Alt Text\n"; echo " Type\n"; echo " EDIT\n"; echo "\n"; } echo "\n"; echo " " . $row['id'] . " \n"; echo " " . $row['name'] . " \n"; echo " " . $row['date'] . " \n"; echo " " . $row['caption'] . " \n"; echo " " . $row['alt_text'] . " \n"; echo " " . $row['type'] . " \n"; if (($row['contributor_id'] == $GLOBALS['auth']->auth['tofu_id']) || ($GLOBALS['perm']->have_perm('admin')) ) { echo "Edit\n"; } else { echo " \n"; } echo "\n"; } function addImage() { if (empty($userfile)) { echo "
\n"; echo "\n"; echo "Send this file: \n"; echo "\n
\n"; 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 "
auth tofu_id is -> " . $auth->auth['tofu_id']; echo "
"; } else { $auth->login_if(! $perm->have_perm('user')); $new_id = update($tables); if (! empty($user__id)) { header("Location: http://www.tofuguide.com/" . $GLOBALS['SCRIPT_ NAME'] . "?view=long&id=$user__id"); } else { header("Location: http://www.tofuguide.com/" . $GLOBALS['SCRIPT_ NAME'] . "?view=long&id=$new_id"); } } } else { if (! empty($id)) { $title = "Edit Image #" . $id . " - " . getName('image', $id); } else { // this is an error! } include("header.inc.php3"); edit(load($id)); } } else { if (! empty($id)) { $name = getName('image', $id); } $title = "Images - " . $name; include("header.inc.php3"); view($view,$id,$sort); } footer(); function footer() { if ($GLOBALS['id']) { echo "
All |\n"; } echo "Long | "; echo "Compact\n"; if ($GLOBALS['perm']->have_perm("admin")) { echo "| Add Image
"; } } //--------- main program include("footer.inc.php3"); page_close() ?>