'; $sUploadDir = '../gallery_images/'. $_SESSION[ 'secure_user_session' ] . '/'; $_SESSION[ 'upload_dir' ] = $sUploadDir; if( !file_exists( $sUploadDir ) ) { //print 'debug1
'; system( 'mkdir ' . $sUploadDir ); } if( strlen( $_GET[ 'title' ] ) > 0 or strlen( $_POST[ 'title' ] ) > 0 ) { if( strlen( $_POST[ 'title' ] ) > 0 ) { $sTitle = $_POST[ 'title' ]; } else { $sTitle = $_GET[ 'title' ]; } $_SESSION[ 'upload_sub_dir' ] = $sUploadDir . strtolower( str_replace(" ", "_", $sTitle ) ) . '/'; $_SESSION[ 'gallery_dir' ] = $_SESSION[ 'upload_sub_dir' ]; //print $_SESSION[ 'upload_sub_dir' ] . '
'; } //print 'debug1
'; //print 'insert_gallery: ' . $_GET[ 'insert_gallery' ] . '
'; if( $_POST[ 'insert_gallery' ] ) { //print 'secure_user_session: ' . $_SESSION[ 'secure_user_session' ] . '
'; //print 'secure_user_id: ' . $_SESSION[ 'secure_user_id' ] . '
'; $query = " insert into galleries " . " ( " . " secure_user_id " . " ) " . " values " . " ( " . $_SESSION[ 'secure_user_id' ] . //$_SESSION[ 'secure_user_id' ] . " ) "; //print 'query: ' . $query . '
'; $result = mysql_query($query) or die("Query failed"); $iGalleryID = mysql_insert_id(); $sDefaultBGColor = 'ffffff'; $sDefaultFontColor = '000000'; $iDefaultFrameHeight = 600; $iDefaultFrameWidth = 600; $iDefaultMaxThumbDim = 100; $iDefaultMaxFullDim = 600; $query = " insert into gallery_attribute " . " ( " . " gallery_id, " . " bg_color, " . " font_color, " . " frame_height, " . " frame_width, " . " title, " . " max_thumb_dim, " . " max_full_dim " . " ) " . " values " . " ( " . $iGalleryID . ", " . "'" . $sDefaultBGColor . "', " . "'" . $sDefaultFontColor . "', " . $iDefaultFrameHeight . ", " . $iDefaultFrameWidth . ", " . "'" . $_POST[ 'title' ] . "', " . $iDefaultMaxThumbDim . ", " . $iDefaultMaxFullDim . " " . " ) "; //print 'query: ' . $query . '
'; $result = mysql_query($query) or die("Query failed"); $sTitle = strtolower( str_replace(" ", "_", $_POST[ 'title' ] ) ); $sCommandString = 'mkdir ' . $sUploadDir . $sTitle; //print getcwd() . '
'; //print $sCommandString; system( $sCommandString ); //print '

'; } if( $_POST[ 'update_gallery' ] ) { $sQuery = " select * " . " from gallery_attribute ga " . " where ga.attribute_id = " . $_POST[ 'attribute_id' ]; $result = mysql_query($sQuery) or die("Query failed"); //alert( 'debug1' ); if( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) { //alert( 'debug2' ); if( $row[ 'title' ] != $_POST[ 'title' ] ) { $sCommand = 'mv ' . $sUploadDir . strtolower( str_replace(" ", "_", $row[ 'title' ]) ) . '/ ' . $_SESSION[ 'upload_sub_dir' ]; //alert( $sCommand ); //$sMessage = exec( $sCommand ); //print $sMessage . '
'; system( $sCommand ); } } $query = " update gallery_attribute set " . " title = '" . $_POST[ 'title' ] . "'," . " bg_color = '" . $_POST[ 'bg_color' ] . "'," . " font_color = '" . $_POST[ 'font_color' ] . "'," . " frame_height = '" . $_POST[ 'frame_height' ] . "', " . " frame_width = '" . $_POST[ 'frame_width' ] . "', " . " max_thumb_dim = '" . $_POST[ 'max_thumb_dim' ] . "', " . " max_full_dim = '" . $_POST[ 'max_full_dim' ] . "'" . " where attribute_id = " . $_POST[ 'attribute_id' ]; //print 'query: ' . $query . '
'; $result = mysql_query($query) or die("Query failed"); //print '

'; } if( $_POST[ 'command' ] == 'insert' ) { //print 'debug1
'; if( strlen( $_FILES['image_file']['name'] ) > 0 ) { //print 'debug2
'; $sTmpFile = $_FILES['image_file']['tmp_name']; $sOrigFileName = $_FILES['image_file']['name']; $sFileName = strtolower( str_replace(" ", "_", $sOrigFileName) ); $sFileSuffix = strtolower( substr( $sFileName, 0, strpos( $sFileName, ".") ) ); $sNewFileName = $sFileSuffix . '.jpg'; //$sNewTmpFile = $_SESSION[ 'upload_sub_dir' ] . '../../tmp/' . $sNewFileName; //$sNewTmpFile = '../gallery_images/tmp/' . $sNewFileName; $sNewTmpFile = '/home/darwinsw/public_html_subdomain/gallery_images/tmp/' . $sNewFileName; $sCommand = 'cp ' . $sTmpFile . ' ' . $sNewTmpFile; //system( $sCommand ); $sMessage = exec( $sCommand ); //alert('sMessage: ' . $sMessage . '
'); //print $sTmpFile . '
'; //print $sNewTmpFile . '
'; $i = 0; while( file_exists( $sUploadDir . 'sm_' . $sNewFileName ) ) { //print 'debug
'; $sNewFileName = $sFileSuffix . '_' . $i . '.jpg'; $i++; } $sSmFileName = 'sm_' . $sNewFileName; $sLgFileName = 'lg_' . $sNewFileName; $sFileExt = strtolower( substr( strrchr( $sOrigFileName, "."), 1 ) ); $sLabel1 = $_POST[ 'label1' ]; $sLabel2 = $_POST[ 'label2' ]; $sLabel3 = $_POST[ 'label3' ]; $cartHtml = $_POST[ 'cart_html' ]; $sQuery = "select * from gallery1 where gallery_id = " . $_SESSION[ 'gallery_id' ]; $result = mysql_query($sQuery) or die("Query failed"); $iOrder = mysql_num_rows( $result ); //print 'file_name: ' . $sFileName . '

'; //print 'sFileExt: ' . $sFileExt . '

'; if( $sFileExt == 'jpg' or $sFileExt == 'jpeg' or $sFileExt == 'gif' or $sFileExt == 'eps' or $sFileExt == 'psd' or $sFileExt == 'bmp' or $sFileExt == 'tif' or $sFileExt == 'svg' or $sFileExt == 'png' or $sFileExt == 'ai' ) { //print 'debug3
'; //print 'tmp_filename: ' . $sNewTmpFile . '
'; //print 'sm_filename: ' . $_SESSION[ 'upload_sub_dir' ] . $sSmFileName . '
'; //print $_SESSION[ 'upload_sub_dir' ] . '
'; //system( 'cp ' . $sNewTmpFile . ' ' . $sUploadDir . $sOrigFileName ); //system( '/usr/bin/convert -flatten ' . $sNewTmpFile . ' ' . $sUploadDir . $sNewFileName ); //system( '/usr/bin/convert ' . $sNewTmpFile . ' ' . $sNewFileName ); ///usr/bin/convert -size 120x120 cockatoo.jpg -resize 120x120 +profile "*" thumbnail.jpg $sConvertString = '/usr/bin/convert -flatten -size ' . $_POST[ 'max_thumb_dim' ] . 'x' . $_POST[ 'max_thumb_dim' ] . ' ' . $sNewTmpFile . ' -resize ' . $_POST[ 'max_thumb_dim' ] . 'x' . $_POST[ 'max_thumb_dim' ] . ' +profile "*" ' . $_SESSION[ 'upload_sub_dir' ] . $sSmFileName; system( $sConvertString ); //$sMessage = exec( 'pwd' ); //print $sMessage . '
'; //print $sMessage . $sConvertString; $sConvertString = '/usr/bin/convert -flatten -size ' . $_POST[ 'max_full_dim' ] . 'x' . $_POST[ 'max_full_dim' ] . ' ' . $sNewTmpFile . ' -quality 75 ' . ' -resize ' . $_POST[ 'max_full_dim' ] . 'x' . $_POST[ 'max_full_dim' ] . ' +profile "*" ' . $_SESSION[ 'upload_sub_dir' ] . $sLgFileName; system( $sConvertString ); /* $sConvertString = '/usr/bin/convert ' . $sNewTmpFile . ' ' . '../gallery_images/tmp/' . $sLgFileName; */ //alert( getcwd() ); //system( '/usr/bin/convert ../gallery_images/rosewilde@woodicing.com/renee_holder/lg_test1b.jpg ../gallery_images/rosewilde@woodicing.com/renee_holder/lg_test1b.png' ); //$sMessage = exec( 'pwd' ); //alert( $sMessage ); //alert( $sNewTmpFile ); //system( 'cp ' . $sNewTmpFile . ' ' . $_SESSION[ 'upload_sub_dir' ] . $sLgFileName . '1' ); //system( 'touch ' . $_SESSION[ 'upload_sub_dir' ] . $sLgFileName . '2' ); //alert( $sConvertString ); //print $sConvertString; //system( 'rm ' . ' ' . $sNewTmpFile ); /* print '

'; print system( 'ls -al ' . $_SESSION[ 'upload_sub_dir' ] ); print '

'; */ $sQuery = " INSERT INTO gallery1 ( picture_id, gallery_id, name, label1, label2, label3, cart_html, file_type, title, order_by ) VALUES ( ''," . $_SESSION[ 'gallery_id' ] . "," . "'" . $sNewFileName . "', " . "'" . $sLabel1 . "'," . "'" . $sLabel2 . "'," . "'" . $sLabel3 . "'," . "'" . $cartHtml . "', '', ''," . $iOrder . " " . " )"; //print $sQuery; mysql_query($sQuery) or die (mysql_error()); } else { alert( 'There is a problem with the website. Please notify kevin@darwinsweb.com.' ); } } } //print 'debug2
'; //print 'command: ' . $_GET[ 'command' ] . '
'; if( $_GET[ 'command' ] == 'delete' and $_POST[ 'insert_gallery' ] != 'true' ) { $sQuery = "delete from gallery1 where gallery_id = " . $_GET[ 'gallery_id' ]; //print '
' . $sQuery . '
'; $result = mysql_query($sQuery) or die("Delete pictures query failed."); $sQuery = "delete from galleries where gallery_id = " . $_GET[ 'gallery_id' ]; //print '
' . $sQuery . '
'; $result = mysql_query($sQuery) or die("Delete gallery query failed."); //print 'upload_sub_dir: ' . $_GET[ 'upload_sub_dir' ]; //alert ( 'executing delete gallery' ); system( 'rm -rf ' . $_GET[ 'upload_sub_dir' ] ); } //print 'size of label1: ' . sizeof($_POST[ 'label1' ]) . '

'; //print 'size of label3: ' . sizeof($_POST[ 'label3' ]) . '

'; if( $_POST[ 'command' ] == 'update' || $_GET[ 'command' ] == 'update' or $_POST[ 'command' ] == 'update_order' || $_GET[ 'command' ] == 'update_order' ) { //print 'debug-2
'; if( strlen( $_POST[ 'gallery_id' ] > 0 ) || strlen( $_GET[ 'gallery_id' ] ) > 0 ) { //print 'debug-1
'; $iRow = 0; $iDeletePicture = 0; $sQuery = "select * from gallery1 where gallery_id = " . $_SESSION[ 'gallery_id' ] . " order by order_by"; $result = mysql_query($sQuery) or die("Query failed"); while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) { if( $_POST[ 'command' ] == 'update' || $_GET[ 'command' ] == 'update' ) { //print 'delete_picture: ' . $_POST[ 'delete_picture' ][$iDeletePicture] . '
'; //print 'picture_id: ' . $row["picture_id"] . '
'; if( $_POST[ 'delete_picture' ][$iDeletePicture] == $row["picture_id"] ) { $sDeleteQuery = "delete from gallery1 where picture_id = " . $_POST[ 'delete_picture' ][$iDeletePicture]; //print '
' . $sDeleteQuery . '
'; $updateResult = mysql_query($sDeleteQuery) or die("Delete picture query failed."); $iDeletePicture++; //alert( 'deleting picture' ); system( 'rm ' . $_SESSION[ 'upload_sub_dir' ] . 'sm_' . $row[ 'name' ] ); system( 'rm ' . $_SESSION[ 'upload_sub_dir' ] . 'lg_' . $row[ 'name' ] ); $sUpdateQuery = "update gallery1 set order_by = order_by - 1 where order_by > " . $row[ 'order_by' ] . " and gallery_id = " . $_SESSION[ 'gallery_id' ]; /* $nextOrderBy = $row[ 'order_by' ] + 1; $sUpdateQuery = " update gallery1 set order_by = order_by - 1 where order_by = " . $nextOrderBy . " and gallery_id = " . $_SESSION[ 'gallery_id' ]; */ //print $sUpdateQuery . '

'; $updateResult = mysql_query($sUpdateQuery) or die("Update picture order query failed when deleting picture."); } /* print 'iRow: ' . $iRow . '
'; print 'picture_id: ' . $row[ "picture_id" ] . '
'; print 'label1: ' . $_POST[ 'label1' ][ $iRow ] . '
'; print 'label2: ' . $_POST[ 'label2' ][ $iRow ] . '
'; print 'label3: ' . $_POST[ 'label3' ][ $iRow ] . '
'; print 'cart_html: ' . $_POST[ 'cart_html' ][ $iRow ] . '
'; */ if( $_POST[ 'label1' ][ $iRow ] != $row[ "label1" ] or $_POST[ 'label2' ][ $iRow ] != $row[ "label2" ] or $_POST[ 'label3' ][ $iRow ] != $row[ "label3" ] or $_POST[ 'cart_html' ][ $iRow ] != $row[ "cart_html" ] ) { $sQuery = " update gallery1 set label1 = '" . $_POST[ 'label1' ][ $iRow ] . "', label2 = '" . $_POST[ 'label2' ][ $iRow ] . "', label3 = '" . $_POST[ 'label3' ][ $iRow ] . "', cart_html = '" . $_POST[ 'cart_html' ][ $iRow ] . "' where picture_id = " . $row[ "picture_id" ]; //print '
' . $sQuery . '
'; $updateResult = mysql_query($sQuery) or die("Update picture query failed."); } } //print 'debug1
'; //print 'direction: ' . $_GET[ 'direction' ] . '
'; if( $_POST[ 'command' ] == 'update_order' || $_GET[ 'command' ] == 'update_order' ) { if( strlen( $_GET[ 'direction' ] ) > 0 ) { //print 'debug2
'; $iIndex = -1; if( $_GET[ 'direction' ] == 'back' ) { if( $_GET[ 'order_by' ] == 0 ) { if( $iRow == 0 ) { $iIndex = $_GET[ 'rows' ] - 1; } else { $iIndex = $iRow - 1; } } else { if( $iRow == ( $_GET[ 'order_by' ] - 1 ) ) { $iIndex = $_GET[ 'order_by' ]; } else if( $iRow == ( $_GET[ 'order_by' ] ) ) { $iIndex = $_GET[ 'order_by' ] - 1; } } } else { if( $_GET[ 'order_by' ] == ( $_GET[ 'rows' ] - 1 ) ) { if( $iRow == ( $_GET[ 'rows' ] - 1 ) ) { $iIndex = 0; } else { $iIndex = $iRow + 1; } } else { if( $iRow == ( $_GET[ 'order_by' ] + 1 ) ) { $iIndex = $_GET[ 'order_by' ]; } else if( $iRow == ( $_GET[ 'order_by' ] ) ) { $iIndex = $_GET[ 'order_by' ] + 1; } } } //print 'picture_id: ' . $row[ 'picture_id' ] . '
'; //print 'order_by: ' . $row[ 'order_by' ] . '
'; //print 'iRow: ' . $iRow . '
'; //print 'iIndex: ' . $iIndex . '

'; if( $iIndex >= 0 ) { $negIndex = -1 * $iIndex; $sUpdateQuery = " update gallery1 set order_by = '" . $negIndex . "' where gallery_id = " . $_SESSION[ 'gallery_id' ] . " and order_by = " . $iIndex; //print $sUpdateQuery . '

'; $updateResult = mysql_query($sUpdateQuery) or die("Temporary update picture order query failed."); $sUpdateQuery = "update gallery1 set order_by = '" . $iIndex . "' where picture_id = " . $row[ "picture_id" ]; //print $sUpdateQuery . '

'; $updateResult = mysql_query($sUpdateQuery) or die("Update picture order query failed."); } } } $iRow++; } } } ?>