2005-01-10 22:24:15 +00:00
< ? php
2004-12-11 22:33:01 +00:00
/*******************************************************************/
2005-01-10 22:15:44 +00:00
/* this script expects appId and optionally versionId as arguments */
2004-12-11 22:33:01 +00:00
/* OR */
/* cmd and imageId */
/*******************************************************************/
2004-12-25 20:08:00 +00:00
/*
2004-12-27 23:54:55 +00:00
* application environment
2004-12-25 20:08:00 +00:00
*/
2004-03-15 16:22:00 +00:00
include ( " path.php " );
require ( BASE . " include/ " . " incl.php " );
2004-11-17 22:57:20 +00:00
require ( BASE . " include/ " . " application.php " );
2004-12-25 20:08:00 +00:00
2004-12-14 02:26:38 +00:00
if ( $_REQUEST [ 'cmd' ])
2004-03-15 16:22:00 +00:00
{
2004-11-17 22:57:20 +00:00
//process screenshot upload
2004-12-14 02:26:38 +00:00
if ( $_REQUEST [ 'cmd' ] == " screenshot_upload " )
2004-12-18 06:06:46 +00:00
{
2004-12-19 19:30:27 +00:00
if ( havepriv ( " admin " ) ||
2004-12-23 01:13:26 +00:00
( loggedin () && $_SESSION [ 'current' ] -> is_maintainer ( $_REQUEST [ 'appId' ],
$_REQUEST [ 'versionId' ])))
{
$str_query = " INSERT INTO appData VALUES (null, " . $_REQUEST [ 'appId' ] . " , " . $_REQUEST [ 'versionId' ] .
" , 'image', ' " . addslashes ( $_REQUEST [ 'screenshot_desc' ]) . " ', '') " ;
2004-11-17 22:57:20 +00:00
2004-12-23 01:13:26 +00:00
if ( debugging ()) addmsg ( " <p align=center><b>query:</b> $str_query </p> " , " green " );
2004-12-11 22:33:01 +00:00
2005-01-10 22:24:15 +00:00
if ( query_appdb ( $str_query ))
2004-12-11 22:33:01 +00:00
{
2004-12-23 01:13:26 +00:00
$int_id = mysql_insert_id ();
if ( ! copy ( $_FILES [ 'imagefile' ][ 'tmp_name' ], " data/screenshots/ " . $int_id ))
2004-12-18 06:06:46 +00:00
{
2004-12-23 01:13:26 +00:00
// whoops, copy failed. do something
errorpage ( " debug: copy failed; ( " . $_FILES [ 'imagefile' ][ 'tmp_name' ] . " ; " . $_FILES [ 'imagefile' ][ 'name' ]);
$str_query = " DELETE FROM appData WHERE id = ' " . $int_id . " ' " ;
2005-01-10 22:24:15 +00:00
query_appdb ( $str_query );
2004-12-23 01:13:26 +00:00
exit ;
} else
{
// we have to update the entry now that we know it's name
$str_query = " UPDATE appData SET url = ' " . $int_id . " ' WHERE id = ' " . $int_id . " ' " ;
2005-01-10 22:24:15 +00:00
if ( query_appdb ( $str_query ))
2004-12-23 01:13:26 +00:00
{
//success
$email = getNotifyEmailAddressList ( $_REQUEST [ 'appId' ], $_REQUEST [ 'versionId' ]);
if ( $email )
{
$fullAppName = " Application: " . lookupAppName ( $_REQUEST [ 'appId' ]) . " Version: " . lookupVersionName ( $_REQUEST [ 'appId' ], $_REQUEST [ 'versionId' ]);
$ms .= APPDB_ROOT . " screenshots.php?appId= " . $_REQUEST [ 'appId' ] . " &versionId= " . $_REQUEST [ 'versionId' ] . " \n " ;
$ms .= " \n " ;
2005-01-10 22:54:04 +00:00
$ms .= $_SESSION [ 'current' ] -> realname . " added screenshot " . $_REQUEST [ 'screenshot_desc' ] . " to " . $fullAppName . " \n " ;
2004-12-23 01:13:26 +00:00
$ms .= " \n " ;
$ms .= STANDARD_NOTIFY_FOOTER ;
2004-12-18 06:06:46 +00:00
2004-12-23 01:13:26 +00:00
mail ( stripslashes ( $email ), " [AppDB] " . $fullAppName , $ms );
} else
{
$email = " no one " ;
}
addmsg ( " mesage sent to: " . $email , " green " );
2004-12-18 06:06:46 +00:00
2004-12-23 01:13:26 +00:00
addmsg ( " The image was successfully added into the database " , " green " );
redirect ( apidb_fullurl ( " screenshots.php?appId= " . $_REQUEST [ 'appId' ] . " &versionId= " . $_REQUEST [ 'versionId' ]));
}
else
{
//error
2004-12-29 20:21:31 +00:00
$statusMessage = " <p><b>Database Error!<br /> " . mysql_error () . " </b></p> \n " ;
2004-12-23 01:13:26 +00:00
addmsg ( $statusMessage , " red " );
}
}
2004-12-18 06:06:46 +00:00
}
} else // we are a normal user or an anonymous and submitted a screenshot
{
2004-12-23 01:13:26 +00:00
$str_query = " INSERT INTO appDataQueue VALUES (null, " . $_REQUEST [ 'appId' ] . " , " . $_REQUEST [ 'versionId' ] .
" , 'image', ' " . addslashes ( $_REQUEST [ 'screenshot_desc' ]) . " ', '',' " . $_SESSION [ 'current' ] -> userid .
" ', NOW()) " ;
2004-12-11 22:33:01 +00:00
2004-12-18 06:06:46 +00:00
if ( debugging ()) addmsg ( " <p align=center><b>query:</b> $str_query </p> " , " green " );
2005-01-10 22:24:15 +00:00
if ( query_appdb ( $str_query ))
2004-12-18 06:06:46 +00:00
{
2004-12-23 01:13:26 +00:00
$int_queueId = mysql_insert_id ();
if ( ! copy ( $_FILES [ 'imagefile' ][ 'tmp_name' ], " data/queued/screenshots/ " . $int_queueId ))
2004-12-18 06:06:46 +00:00
{
2004-12-23 01:13:26 +00:00
// whoops, copy failed. do something
errorpage ( " debug: copy failed; ( " . $_FILES [ 'imagefile' ][ 'tmp_name' ] . " ; " . $_FILES [ 'imagefile' ][ 'name' ]);
$str_query = " DELETE FROM appDataQueue WHERE queueId = ' " . $int_queueId . " ' " ;
2005-01-10 22:24:15 +00:00
query_appdb ( $str_query );
2004-12-23 01:13:26 +00:00
exit ;
} else
{
2005-01-10 22:15:44 +00:00
// we have to update the queued entry now that we know its name
2004-12-23 01:13:26 +00:00
$str_query = " UPDATE appDataQueue SET url = ' " . $int_queueId . " ' WHERE queueId = ' " . $int_queueId . " ' " ;
2005-01-10 22:24:15 +00:00
if ( query_appdb ( $str_query ))
2004-12-23 01:13:26 +00:00
{
//success
$email = getNotifyEmailAddressList ( $_REQUEST [ 'appId' ], $_REQUEST [ 'versionId' ]);
if ( $email )
{
$fullAppName = " Application: " . lookupAppName ( $_REQUEST [ 'appId' ]) . " Version: " . lookupVersionName ( $_REQUEST [ 'appId' ], $_REQUEST [ 'versionId' ]);
$ms .= APPDB_ROOT . " admin/adminAppDataQueue.php?queueId= " . mysql_insert_id () . " \n " ;
$ms .= " \n " ;
2005-01-10 22:54:04 +00:00
$ms .= ( $_SESSION [ 'current' ] -> realname ? $_SESSION [ 'current' ] -> realname : " an anonymous user " ) . " submitted a screenshot " . $_REQUEST [ 'screenshot_desc' ] . " for " . $fullAppName . " \n " ;
2004-12-23 01:13:26 +00:00
$ms .= " \n " ;
$ms .= STANDARD_NOTIFY_FOOTER ;
2004-12-18 06:06:46 +00:00
2004-12-23 01:13:26 +00:00
mail ( stripslashes ( $email ), " [AppDB] " . $fullAppName , $ms );
} else
{
$email = " no one " ;
}
addmsg ( " mesage sent to: " . $email , " green " );
2004-12-18 06:06:46 +00:00
2004-12-23 01:13:26 +00:00
addmsg ( " The image you submitted will be added to the database database after being reviewed " , " green " );
redirect ( apidb_fullurl ( " screenshots.php?appId= " . $_REQUEST [ 'appId' ] . " &versionId= " . $_REQUEST [ 'versionId' ]));
}
else
{
//error
2004-12-29 20:21:31 +00:00
$statusMessage = " <p><b>Database Error!<br /> " . mysql_error () . " </b></p> \n " ;
2004-12-23 01:13:26 +00:00
addmsg ( $statusMessage , " red " );
}
}
2004-12-18 06:06:46 +00:00
}
2004-12-11 22:33:01 +00:00
}
2004-12-18 06:06:46 +00:00
} elseif ( $_REQUEST [ 'cmd' ] == " delete " )
2004-12-11 22:33:01 +00:00
{
2004-12-19 19:30:27 +00:00
if ( havepriv ( " admin " ) ||
$_SESSION [ 'current' ] -> is_maintainer ( $_REQUEST [ 'appId' ],
$_REQUEST [ 'versionId' ]))
2004-12-18 06:06:46 +00:00
{
2005-01-10 22:24:15 +00:00
$result = query_appdb ( " DELETE FROM appData WHERE id = " . $_REQUEST [ 'imageId' ]);
2004-12-11 22:33:01 +00:00
if ( $result )
2004-12-18 06:06:46 +00:00
{
$email = getNotifyEmailAddressList ( $_REQUEST [ 'appId' ], $_REQUEST [ 'versionId' ]);
if ( $email )
2004-11-17 22:57:20 +00:00
{
2004-12-18 06:06:46 +00:00
$fullAppName = " Application: " . lookupAppName ( $_REQUEST [ 'appId' ]) . " Version: " . lookupVersionName ( $_REQUEST [ 'appId' ], $_REQUEST [ 'versionId' ]);
$ms .= APPDB_ROOT . " screenshots.php?appId= " . $_REQUEST [ 'appId' ] . " &versionId= " . $_REQUEST [ 'versionId' ] . " \n " ;
$ms .= " \n " ;
2005-01-10 22:54:04 +00:00
$ms .= ( $_SESSION [ 'current' ] -> realname ? $_SESSION [ 'current' ] -> realname : " Anonymous " ) . " deleted screenshot from " . $fullAppName . " \n " ;
2004-12-18 06:06:46 +00:00
$ms .= " \n " ;
$ms .= STANDARD_NOTIFY_FOOTER ;
2004-11-17 22:57:20 +00:00
2004-12-18 06:06:46 +00:00
mail ( stripslashes ( $email ), " [AppDB] " . $fullAppName , $ms );
2004-11-17 22:57:20 +00:00
} else
{
2004-12-18 06:06:46 +00:00
$email = " no one " ;
2004-11-17 22:57:20 +00:00
}
2004-12-18 06:06:46 +00:00
addmsg ( " mesage sent to: " . $email , " green " );
addmsg ( " Image deleted " , " green " );
redirect ( apidb_fullurl ( " screenshots.php?appId= " . $_REQUEST [ 'appId' ] . " &versionId= " . $_REQUEST [ 'versionId' ]));
} else
{
addmsg ( " Failed to delete image: " . mysql_error (), " red " );
redirect ( apidb_fullurl ( " screenshots.php?appId= " . $_REQUEST [ 'appId' ] . " &versionId= " . $_REQUEST [ 'versionId' ]));
2004-12-11 22:33:01 +00:00
}
2004-12-18 06:06:46 +00:00
}
}
2004-03-15 16:22:00 +00:00
exit ;
}
2004-12-18 06:06:46 +00:00
// we didn't issue any command
2004-12-11 22:33:01 +00:00
if ( $_REQUEST [ 'versionId' ])
2005-01-10 22:24:15 +00:00
$result = query_appdb ( " SELECT * FROM appData WHERE type = 'image' AND appId = " . $_REQUEST [ 'appId' ] . " AND versionId = " . $_REQUEST [ 'versionId' ]);
2004-12-11 22:33:01 +00:00
else
2005-01-10 22:24:15 +00:00
$result = query_appdb ( " SELECT * FROM appData WHERE type = 'image' AND appId = " . $_REQUEST [ 'appId' ] . " ORDER BY versionId " );
2004-12-11 22:33:01 +00:00
2004-12-18 06:06:46 +00:00
$app = new Application ( $_REQUEST [ 'appId' ]);
apidb_header ( " Screenshots " );
if ( $result && mysql_num_rows ( $result ))
2004-03-15 16:22:00 +00:00
{
2004-12-18 06:06:46 +00:00
echo html_frame_start ( " Screenshot Gallery for " . $app -> data -> appName , 500 );
2004-11-17 22:57:20 +00:00
2004-12-18 06:06:46 +00:00
// display thumbnails
$c = 1 ;
echo " <div align=center><table><tr> \n " ;
while ( $ob = mysql_fetch_object ( $result ))
{
if ( ! $_REQUEST [ 'versionId' ] && $ob -> versionId != $currentVersionId )
2004-11-17 22:57:20 +00:00
{
2004-12-18 06:06:46 +00:00
if ( $currentVersionId )
2004-12-11 22:33:01 +00:00
{
2004-12-18 06:06:46 +00:00
echo " </tr></table></div> \n " ;
echo html_frame_end ();
$c = 1 ;
2004-12-11 22:33:01 +00:00
}
2004-12-18 06:06:46 +00:00
$currentVersionId = $ob -> versionId ;
echo html_frame_start ( " Version " . lookupVersionName ( $_REQUEST [ 'appId' ], $currentVersionId ));
echo " <div align=center><table><tr> \n " ;
}
// set img tag
$imgSRC = '<img src="appimage.php?imageId=' . $ob -> id . '&width=128&height=128" border=0 alt="' . $ob -> description . '">' ;
// get image size
$size = getimagesize ( " data/screenshots/ " . $ob -> url );
2004-12-11 22:33:01 +00:00
2004-12-18 06:06:46 +00:00
// generate random tag for popup window
$randName = generate_passwd ( 5 );
2004-12-11 22:33:01 +00:00
2004-12-18 06:06:46 +00:00
// set image link based on user pref
$img = '<a href="javascript:openWin(\'appimage.php?imageId=' . $ob -> id . '\',\'' . $randName . '\',' . $size [ 0 ] . ',' . $size [ 1 ] . ');">' . $imgSRC . '</a>' ;
if ( loggedin ())
{
if ( $_SESSION [ 'current' ] -> getpref ( " window:screenshot " ) == " no " )
2004-12-11 22:33:01 +00:00
{
2004-12-18 06:06:46 +00:00
$img = '<a href="appimage.php?imageId=' . $ob -> id . '">' . $imgSRC . '</a>' ;
2004-12-11 22:33:01 +00:00
}
2004-12-18 06:06:46 +00:00
}
2004-12-11 22:33:01 +00:00
2004-12-18 06:06:46 +00:00
// display image
echo " <td> \n " ;
echo html_frame_start ( substr ( stripslashes ( $ob -> description ), 0 , 20 ), 128 , " " , 0 );
echo $img ;
2004-12-11 22:33:01 +00:00
2004-12-18 06:06:46 +00:00
//show admin delete link
2004-12-19 19:30:27 +00:00
if ( loggedin () && ( havepriv ( " admin " ) ||
$_SESSION [ 'current' ] -> is_maintainer ( $_REQUEST [ 'appId' ],
$_REQUEST [ 'versionId' ])))
2004-12-18 06:06:46 +00:00
{
echo " <div align=center>[<a href='screenshots.php?cmd=delete&imageId= $ob->id &appId= " . $_REQUEST [ 'appId' ] . " &versionId= " . $_REQUEST [ 'versionId' ] . " '>Delete Image</a>]</div> " ;
}
2004-12-11 22:33:01 +00:00
2004-12-18 06:06:46 +00:00
echo html_frame_end ( " " );
echo " </td> \n " ;
2004-12-11 22:33:01 +00:00
2004-12-18 06:06:46 +00:00
// end row if counter of 3
if ( $c % 3 == 0 ) echo " </tr><tr> \n " ;
2004-03-15 16:22:00 +00:00
2004-12-18 06:06:46 +00:00
$c ++ ;
2004-11-17 22:57:20 +00:00
}
2004-12-29 20:21:31 +00:00
echo " </tr></table></div><br /> \n " ;
2004-12-18 06:06:46 +00:00
echo html_frame_end ( " Click thumbnail to view image in new window. " );
} else {
echo " <p align= \" center \" >There are currently no screenshot for the selected version of this application. " ;
echo " <br />Please consider submitting a screenshot for the selected version yourself.</p> " ;
}
if ( $_REQUEST [ 'versionId' ])
{
//image upload box
echo '<form enctype="multipart/form-data" action="screenshots.php" name=imageForm method="post">' , " \n " ;
echo html_frame_start ( " Upload Screenshot " , " 400 " , " " , 0 );
echo '<table border=0 cellpadding=6 cellspacing=0 width="100%">' , " \n " ;
2004-11-17 22:57:20 +00:00
2004-12-18 06:06:46 +00:00
echo '<tr><td class=color1>Image</td><td class=color0><input name="imagefile" type="file"></td></tr>' , " \n " ;
echo '<tr><td class=color1>Description</td><td class=color0><input type="text" name="screenshot_desc"></td></tr>' , " \n " ;
2004-11-17 22:57:20 +00:00
2004-12-18 06:06:46 +00:00
echo '<tr><td colspan=2 align=center class=color3><input type="submit" value="Send File"></td></tr>' , " \n " ;
2004-11-17 22:57:20 +00:00
2004-12-18 06:06:46 +00:00
echo '</table>' , " \n " ;
echo html_frame_end ();
echo '<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />' , " \n " ;
echo '<input type="hidden" name="cmd" value="screenshot_upload" />' , " \n " ;
echo '<input type="hidden" name="appId" value="' . $_REQUEST [ 'appId' ] . '" />' , " \n " ;
echo '<input type="hidden" name="versionId" value="' . $_REQUEST [ 'versionId' ] . '"></form />' , " \n " ;
2004-03-15 16:22:00 +00:00
}
2004-12-18 06:06:46 +00:00
echo html_back_link ( 1 );
apidb_footer ();
2004-03-15 16:22:00 +00:00
?>