fnLoggedInReq($guid); $thisUser -> fnUpdateLastRequest($guid); //init page object $thisPage = new Page(); //css files in header... $thisPage->cssIncludes = "styles/imgareaselect-animated.css"; //javascript files in header... $thisPage->scriptsInHeader = "bt_v15/bt_scripts/cpv15.js, scripts/jquery-1.3.2.min.js, scripts/jquery.imgareaselect.pack.js"; //onLoad... $thisPage->customBody = "onload=\"init();\""; //form does uploads... $thisPage->formEncType = "multipart/form-data"; //vars... $dtNow = fnMySqlNow(); $strMessage = ""; $bolDone = false; $bolPassed = true; $bolDeleted = false; $bolIsUploaded = false; $appGuid = fnGetReqVal("appGuid", "", $myRequestVars); $command = fnGetReqVal("command", "", $myRequestVars); $iconUrl = fnGetReqVal("iconUrl", "", $myRequestVars); $large_image_location = fnGetReqVal("large_image_location", "", $myRequestVars); $small_image_location = fnGetReqVal("small_image_location", "", $myRequestVars); $large_imageURL = fnGetReqVal("large_imageURL", "", $myRequestVars); $small_imageURL = fnGetReqVal("small_imageURL", "", $myRequestVars); $imgGuid = fnGetReqVal("imgGuid", strtoupper(fnCreateGuid()), $myRequestVars); $upload_dir = APP_PHYSICAL_PATH . APP_DATA_DIRECTORY . "/temp"; $upload_path = $upload_dir . "/"; $large_image_prefix = "icon_full_"; $small_image_prefix = "icon_crop_"; $large_image_name = $large_image_prefix . $imgGuid; $small_image_name = $small_image_prefix . $imgGuid; $max_width = "700"; $small_width = "72"; $small_height = "72"; $allowed_image_types = array('image/pjpeg'=>"jpg",'image/jpeg'=>"jpg",'image/jpg'=>"jpg", 'image/png'=>"png", 'image/x-png'=>"png"); $allowed_image_ext = array_unique($allowed_image_types); $image_ext = ""; foreach ($allowed_image_ext as $mime_type => $ext) { $image_ext .= strtoupper($ext) . " "; } //app object... if($appGuid == ""){ echo "invalid request (4)"; exit(); }else{ //app object... $objApp = new App($appGuid); $thisPage->pageTitle = $objApp->infoArray["name"] . " Control Panel"; //make sure user can manage this app... $objApp->fnCanManageApp($thisUser->infoArray["guid"], $thisUser->infoArray["userType"], $appGuid, $objApp->infoArray["ownerGuid"]); } //app name... $appName = $objApp->infoArray["name"]; //////////////////////////////////////////////////////////////////////////////////// //image functions //image height function getHeight($image){ $size = getimagesize($image); $height = $size[1]; return $height; } //image width function getWidth($image) { $size = getimagesize($image); $width = $size[0]; return $width; } //large image upload if(strtoupper($command) == "UPLOAD_LARGE"){ //Get the file information $userfile_name = $_FILES['image']['name']; $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $userfile_type = $_FILES['image']['type']; $filename = basename($_FILES['image']['name']); $file_ext = strtolower(substr($filename, strrpos($filename, '.') + 1)); //only process if the file is acceptable and below the allowed limit if((!empty($_FILES["image"])) && ($_FILES['image']['error'] == 0)) { foreach ($allowed_image_types as $mime_type => $ext) { //loop through the specified image types and if they match the extension if($file_ext == $ext && $userfile_type == $mime_type){ $strMessage = ""; break; }else{ $strMessage = "
Only .JPG or .PNG images are allowed. This message means you tried to upload an image that "; $strMessage .= "was not an acceptable format. Tip: Replace .jpeg file extensions with .jpg before uploading. "; } } //if file size if($bolPassed){ //check if the file size is above the allowed limit if ($userfile_size > APP_MAX_UPLOAD_SIZE) { $bolPassed = false; $strMessage .= "
Uploaded file is too large. Max allowed: " . fnFormatBytes(APP_MAX_UPLOAD_SIZE); } }//bolPassed }else{ $strMessage .= "
Please select an image to upload"; } //Everything is ok, so we can upload the image. if (strlen($strMessage) == 0){ if (isset($_FILES['image']['name'])){ //this file could now have an unknown file extension (we hope it's one of the ones set above!) $large_image_location = $upload_path . $large_image_name . "." . $file_ext; $large_imageURL = fnGetSecureURL(APP_URL) . APP_DATA_DIRECTORY . "/temp/" . $large_image_name . "." . $file_ext; $small_image_location = $upload_path . $small_image_name . "." . $file_ext; $small_imageURL = fnGetSecureURL(APP_URL) . APP_DATA_DIRECTORY . "/temp/" . $small_image_name . "." . $file_ext; //save image then make sure it is large enough if(move_uploaded_file($userfile_tmp, $large_image_location)){ chmod($large_image_location, 0755); $bolPassed = true; $width = getWidth($large_image_location); $height = getHeight($large_image_location); }else{ $bolPassed = false; $strMessage .= "
The image you uploaded could not be saved. Please contact a system administrator. "; } //still good? if($bolPassed){ if($width < $small_width || $height < $small_height){ $bolPassed = false; $strMessage .= "
The image you uploaded is too small. Choose an image that is at least "; $strMessage .= $small_width . " x " . $small_height; } } if($bolPassed){ //figure out scale for new image $scale = 1; if ($width > $max_width){ $scale = $max_width / $width; } //make sure scaled is still large enough $newImageWidth = ceil($width * $scale); $newImageHeight = ceil($height * $scale); if($newImageWidth < $small_width || $newImageHeight < $small_height){ $bolPassed = false; $strMessage .= "
The image you uploaded is too small. Choose an image that is at least "; $strMessage .= $small_width . " x " . $small_height; } //still passed?0 if($bolPassed){ //scale the image if it is greater than the width set above if ($width > $max_width){ $scale = $max_width / $width; $bolDidResize = resizeImage($large_image_location, $width, $height, $scale); }else{ $scale = 1; $bolDidResize = resizeImage($large_image_location, $width, $height, $scale); } //delete the thumbnail file so the user can create a new one if($small_image_location != ""){ if(file_exists($small_image_location)){ @unlink($small_image_location); } } //thumb == "" //resizeImage may return error if(!$bolDidResize){ $bolPassed = false; $strMessage .= "
There was an error processing the image you uploaded? The file size may be too large? Please try again. Select a smaller image if you continue to have problems."; }else{ //flag as uploaded $bolIsUploaded = true; $bolDone = false; } }//if bolPassed }//if bolPased } //have file name } //message == "" } //end large image upload //small image upload, after crop. if(strtoupper($command) == "UPLOAD_SMALL"){ //new coordinates to crop the image. $x1 = $_POST["x1"]; $y1 = $_POST["y1"]; $x2 = $_POST["x2"]; $y2 = $_POST["y2"]; $w = $_POST["w"]; $h = $_POST["h"]; //scale the image to the small_width set above $scale = $small_width / $w; $cropped = resizeThumbnailImage($small_image_location, $large_image_location, $w, $h, $x1, $y1, $scale); //if cropped was successful if($cropped){ //update app details... $objApp = new App($appGuid); //extension... $file_ext = strtolower(substr($small_image_location, strrpos($small_image_location, '.') + 1)); //complete path to image $imgUrl = APP_URL . APP_DATA_DIRECTORY . "/applications/" . $appGuid . "/images/" . $imgGuid . "_icon." . $file_ext; $small_imageURL = fnGetSecureURL(APP_URL) . APP_DATA_DIRECTORY . "/applications/" . $appGuid . "/images/" . $imgGuid . "_icon." . $file_ext; $imgName = basename($imgUrl); //move selected image to this app's image directory $moveFromPath = $small_image_location; $moveToPath = APP_PHYSICAL_PATH . APP_DATA_DIRECTORY . "/applications/" . $appGuid . "/images/" . $imgName; if(is_file($moveFromPath)){ //remove previously uploaded image $dir = APP_PHYSICAL_PATH . APP_DATA_DIRECTORY . "/applications/" . $appGuid . "/images"; if(is_dir($dir)){ //if(!$dh = @opendir($dir)) return; if($handle = opendir($dir)){ while(false !== ($fileObj = readdir($handle))) { if(strlen($fileObj) > 5){ if(strrpos($fileObj,"_icon") > 0){ @unlink($dir . "/" . $fileObj); }//is image the icon } }//while }else{ $bolPassed = false; $strMessage .= "
There was a problem opening the image directory for this app?"; }//handle }else{ $bolPassed = false; $strMessage .= "
This app does not have an image directory?"; }//isDir }else{ $bolPassed = false; $strMessage .= "
There was a problem saving your uploaded image?"; } //still good? if($bolPassed){ //copy the newly selected image to the directory we just emptied. if(copy($moveFromPath, $moveToPath)){ //because we moved it, set it's owner if(chmod($moveToPath, 0755)){ //update the app data $objApp->infoArray['iconUrl'] = $imgUrl; $objApp->infoArray['iconName'] = $imgName; $objApp->infoArray['modifiedUTC'] = $dtNow; $objApp->fnUpdate(); //flag as done $bolDone = true; }else{ $bolPassed = false; $strMessage .= "
There was a problem configuring the uploaded image?"; } }else{ $bolPassed = false; $strMessage .= "
There was a problem copying the new image?"; } }//bolPassed }else{ $bolPassed = false; $strMessage .= "
There was a problem saving the resized image?"; }//objApp } //UPLOAD_SMALL //load vals $appName = $objApp->infoArray['name']; $iconUrl = $objApp->infoArray['iconUrl']; //validate icon url... if($iconUrl == ""){ $iconUrl = APP_URL . "/images/default_app_icon.png"; } $iconUrl = fnGetSecureURL($iconUrl); //if we have a large image location, set image_preview url to this $image_preview_url = $iconUrl; if($bolDone){ $image_preview_url = $imgUrl; }else{ if(is_file($large_image_location) && $strMessage == ""){ $image_preview_url = $large_imageURL; } } $image_preview_url = fnGetSecureURL($image_preview_url); //print html... echo $thisPage->fnGetPageHeaders(); echo $thisPage->fnGetBodyStart(); echo $thisPage->fnGetTopNavBar($thisUser->infoArray['guid']); ?>
Application Home   |   fnGetControlPanelLinks("application", $appGuid, "inline", ""); ?>
Manage Icon for
Use the crop-tool to select the portion of the image you want to keep. You can resize the crop-tool by dragging the tiny arrows diagonally upwards or downwards. If the image you uploaded is exactly 72 x 72, you may not see the handles...in this case simply click the image to select it. Click Save when done.

preview
Choose a .JPG or .PNG image to upload. After uploading the image, you'll be asked to "crop" the image to 72 x 72 pixels. If you upload an image that is exactly 72 x 72 (because you created it in an image editor first), click it to "select it" before clicking the "Save" button.
Icon Updated Successfully. Upload another image (overwrite the one you just uploaded) or click done.
sample screen
app icon
 
fnGetBottomNavBar();?>
fnGetBodyEnd(); ?>