[Linpha-cvs] SF.net SVN: linpha: [4552] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <fan...@us...> - 2006-04-28 22:27:52
|
Revision: 4552 Author: fangehrn Date: 2006-04-28 12:08:11 -0700 (Fri, 28 Apr 2006) ViewCVS: http://svn.sourceforge.net/linpha/?rev=4552&view=rev Log Message: ----------- * filemanager: implemeting move, copy, change permissions, upload @todo make upload more secure Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/install/sql/sql.data.php trunk/linpha2/lib/classes/linpha.filesys.class.php trunk/linpha2/lib/classes/linpha.import.class.php trunk/linpha2/lib/modules/module.filemanager.php Added Paths: ----------- trunk/linpha2/templates/default/css/filemanager.css trunk/linpha2/templates/default/filemanager.html.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2006-04-26 21:54:14 UTC (rev 4551) +++ trunk/linpha2/ChangeLog 2006-04-28 19:08:11 UTC (rev 4552) @@ -1,3 +1,7 @@ +2006-04-28 flo + * filemanager: implemeting move, copy, change permissions, upload + @todo make upload more secure + 2006-04-26 flo * filemanager: implementing rename, delete, create folder Modified: trunk/linpha2/install/sql/sql.data.php =================================================================== --- trunk/linpha2/install/sql/sql.data.php 2006-04-26 21:54:14 UTC (rev 4551) +++ trunk/linpha2/install/sql/sql.data.php 2006-04-28 19:08:11 UTC (rev 4552) @@ -64,7 +64,8 @@ 'sys_user_autologin' => '1', - 'plugins_filemanager_enable' => '0' + 'plugins_filemanager_enable' => '0', + 'plugins_filemanager_nruploads' => '5' ); /** Modified: trunk/linpha2/lib/classes/linpha.filesys.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.filesys.class.php 2006-04-26 21:54:14 UTC (rev 4551) +++ trunk/linpha2/lib/classes/linpha.filesys.class.php 2006-04-28 19:08:11 UTC (rev 4552) @@ -47,66 +47,36 @@ } /** -* copy recursive - same as "cp -R" -*/ -function copy_r($source,$dest) + * delete recurisvely - same as "rm -rf" + * @todo should we really have such a dangerous function in linpha? + */ +function rm_rf($path,$followLinks=false) { - if( !is_dir($source) ) + if( is_file($path) ) { - if( is_file($source) ) - { - @copy($source,$dest); - return 1; - } - else - { - return 0; - } + @unlink( $path ); + return true; } - if (!is_dir($dest)) { - mkdir_p($dest); - } - $h=@dir($source); - while (@($entry=$h->read()) !== false) + else { - if (($entry!=".")&&($entry!="..")) + $dir = opendir($path) ; + while (false !== ($entry = readdir($dir))) { - if (is_dir("$source/$entry")&&$dest!=="$source/$entry") + if ( is_file( "$path/$entry" ) || ((!$followLinks) && is_link("$path/$entry")) ) { - copy_r("$source/$entry","$dest/$entry"); + @unlink( "$path/$entry" ); } - else + elseif ( is_dir( "$path/$entry" ) && $entry!='.' && $entry!='..' ) { - @copy("$source/$entry","$dest/$entry"); + LinFilesys::rm_rf( "$path/$entry" ); } } + closedir($dir) ; + return @rmdir($path); } - $h->close(); - return 1; } /** - * delete directory recurisvely - same as "rm -rf" - */ -function rm_rf($path,$followLinks=false) -{ - $dir = opendir($path) ; - while (false !== ($entry = readdir($dir))) - { - if ( is_file( "$path/$entry" ) || ((!$followLinks) && is_link("$path/$entry")) ) - { - @unlink( "$path/$entry" ); - } - elseif ( is_dir( "$path/$entry" ) && $entry!='.' && $entry!='..' ) - { - rm_rf( "$path/$entry" ); - } - } - closedir($dir) ; - return @rmdir($path); -} - -/** * realpath() doesnt work somtimes if path is absolute * linRealpath takes care of this */ Modified: trunk/linpha2/lib/classes/linpha.import.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.import.class.php 2006-04-26 21:54:14 UTC (rev 4551) +++ trunk/linpha2/lib/classes/linpha.import.class.php 2006-04-28 19:08:11 UTC (rev 4552) @@ -264,8 +264,10 @@ } /** - * update entry (check md5sum and file_type) - * the file_type changes if a file changes to readable + * update entry "detect file changes"(check md5sum and file_type) + * this has nothing todo with the updateDir() method + * + * (the file_type changes if a file changes to readable) */ function updateEntry( $id , $dirname , $filename ) { @@ -308,6 +310,9 @@ * if the md5sum changes, update the md5sum in linpha_stats, linpha_meta_data * occurs while rotating images, or if LinImport detects a change of the file * (for example: image has been edited with an external program) + * + * @todo if the file changed, it is best to re-index image + * -> delete/update exif/iptc/xmp data! */ function updateMd5sum( $id, $old_md5sum, $new_md5sum ) { Modified: trunk/linpha2/lib/modules/module.filemanager.php =================================================================== --- trunk/linpha2/lib/modules/module.filemanager.php 2006-04-26 21:54:14 UTC (rev 4551) +++ trunk/linpha2/lib/modules/module.filemanager.php 2006-04-28 19:08:11 UTC (rev 4552) @@ -38,6 +38,11 @@ /** * init stuff */ + /** + * some double used i18n entries + */ + $str_checkpermissions = "Check the permissions in the linpha albums folder. (This means NOT the write permissions page in the admin section)"; + if(!isset($_GET['id'])) { $parent_id = 0; @@ -59,6 +64,20 @@ } else { $uid = 0; } + + /** + * upload stuff + */ + include_once(LINPHA_DIR.'/lib/classes/archiver.class.php'); + $apps = new Archive_Applications(); + $apps->searchApps(); + + $appselect = '<option value="-">'. i18n("Extract Archive With"). '</option>'; + foreach($apps->found_apps AS $key=>$value) + { + $value = $key.' (.'.$apps->apps[$key]['file_ext'].')'; + $appselect .= '<option value="'.$key.'">'.$value.'</option>'; + } /** * check global permission @@ -88,21 +107,23 @@ $isWriteAble = false; } +ob_start(); + /** * parsing POST data */ -if(isset($_POST['cmd'])) +if(isset($_REQUEST['cmd'])) { try { - switch($_POST['cmd']) + switch($_REQUEST['cmd']) { case 'file_action': - if(!isset($_POST['checkedfiles'])) + if(!isset($_REQUEST['checkedfiles'])) { throw new Exception(i18n("No Files Selected")); } - if(!isset($_POST['file_action'])) + if(!isset($_REQUEST['file_action'])) { throw new Exception(i18n("No Action Selected")); } @@ -110,32 +131,53 @@ ?> <form method="POST" action="<?php echo LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; ?>"> <?php - switch($_POST['file_action']) + switch($_REQUEST['file_action']) { case 'rename': $data = $GLOBALS['linpha']->db->GetRow("SELECT name, parent_id FROM ".PREFIX."photos " . - "WHERE id = '".LinSql::linAddslashes($_POST['checkedfiles'][0])."'"); + "WHERE id = '".LinSql::linAddslashes($_REQUEST['checkedfiles'][0])."'"); echo '<b>'.i18n("Rename File/Folder").':</b><br />'; ?> <input type="text" name="new_name" value="<?php echo $data['name']; ?>" style="width: 300px;" /> - <input type="hidden" name="file_id" value="<?php echo $_POST['checkedfiles'][0]; ?>" /> + <input type="hidden" name="file_id" value="<?php echo $_REQUEST['checkedfiles'][0]; ?>" /> <?php break; case 'move': case 'copy': + if( $_REQUEST['file_action'] == 'move') + { + echo i18n("Move These Files/Folders"); + } + elseif( $_REQUEST['file_action'] == 'copy') + { + echo i18n("Copy These Files/Folders"); + } + echo ':<br />'; + + foreach($_REQUEST['checkedfiles'] AS $value) + { + $data = $GLOBALS['linpha']->db->GetRow("SELECT name FROM ".PREFIX."photos " . + "WHERE id = '".LinSql::linAddslashes($value)."'"); + echo $data['name'].', '; + } + echo '<br /><br />'; + echo i18n("To").':'; + echo '<br />'; ?> - <select> - <option value=""></option> - <option value=""></option> - <option value=""></option> + <select name="movecopy_to"> + <option value="0">/</option> + <?php + buildAlbumSelect( $with_all_albs_entry=false ); + ?> </selet> + <input type="hidden" name="checkedfiles" value="<?php echo implode(';',$_REQUEST['checkedfiles']); ?>" /> <?php break; case 'delete': echo i18n("Delete All The Following Files/Folders including contensts:").'<br />'; - foreach($_POST['checkedfiles'] AS $value) + foreach($_REQUEST['checkedfiles'] AS $value) { $data = $GLOBALS['linpha']->db->GetRow("SELECT name FROM ".PREFIX."photos " . "WHERE id = '".LinSql::linAddslashes($value)."'"); @@ -144,13 +186,59 @@ echo '<br /><br />'; echo i18n("Really Sure?"); ?> - <input type="hidden" name="checkedfiles" value="<?php echo implode(';',$_POST['checkedfiles']); ?>" /> + <input type="hidden" name="checkedfiles" value="<?php echo implode(';',$_REQUEST['checkedfiles']); ?>" /> <?php break; + case 'changeperm': + $full_filename = LinSql::getFullImagePath( $_REQUEST['checkedfiles'][0]); + $perm = getReadableFileperms($full_filename); + + (substr($perm, 1, 1)!="-" ? $ur = 1 : ''); + (substr($perm, 2, 1)!="-" ? $uw = 1 : ''); + (substr($perm, 3, 1)!="-" ? $ux = 1 : ''); + (substr($perm, 4, 1)!="-" ? $gr = 1 : ''); + (substr($perm, 5, 1)!="-" ? $gw = 1 : ''); + (substr($perm, 6, 1)!="-" ? $gx = 1 : ''); + (substr($perm, 7, 1)!="-" ? $or = 1 : ''); + (substr($perm, 8, 1)!="-" ? $ow = 1 : ''); + (substr($perm, 9, 1)!="-" ? $ox = 1 : ''); + + echo i18n("Change Permission Of:").' '.$full_filename; + ?> + <br /> + <table border="1" cellpadding="0" cellspacing="0"> + <tr> + <td width="100"> </td> + <td class='admintable' width="75"><?php echo i18n("Read"); ?></td> + <td class='admintable' width="75"><?php echo i18n("Write"); ?></td> + <td class='admintable' width="75"><?php echo i18n("Execute"); ?></td> + </tr> + <tr> + <td class='admintable'><?php echo i18n("Owner"); ?></td> + <td><input name="ur" type="checkbox" value="4"<?=(isset($ur) ? ' checked' : '')?>></td> + <td><input name="uw" type="checkbox" value="2"<?=(isset($uw) ? ' checked' : '')?>></td> + <td><input name="ux" type="checkbox" value="1"<?=(isset($ux) ? ' checked' : '')?>></td> + </tr> + <tr> + <td class='admintable'><?php echo i18n("Group"); ?></td> + <td><input name="gr" type="checkbox" value="4"<?=(isset($gr) ? ' checked' : '')?>></td> + <td><input name="gw" type="checkbox" value="2"<?=(isset($gw) ? ' checked' : '')?>></td> + <td><input name="gx" type="checkbox" value="1"<?=(isset($gx) ? ' checked' : '')?>></td> + </tr> + <tr> + <td class='admintable'><?php echo i18n("All Others"); ?></td> + <td><input name="or" type="checkbox" value="4"<?=(isset($or) ? ' checked' : '')?>></td> + <td><input name="ow" type="checkbox" value="2"<?=(isset($ow) ? ' checked' : '')?>></td> + <td><input name="ox" type="checkbox" value="1"<?=(isset($ox) ? ' checked' : '')?>></td> + </tr> + </table> + <input type="hidden" name="file_id" value="<?php echo $_REQUEST['checkedfiles'][0]; ?>" /> + <?php + break; } ?> <input type="hidden" name="cmd" value="do_file_action" /> - <input type="hidden" name="file_action" value="<?php echo $_POST['file_action']; ?>" /> + <input type="hidden" name="file_action" value="<?php echo $_REQUEST['file_action']; ?>" /> <input type="submit" name="submit" value="<?php echo i18n("Submit"); ?>" /> </form> <hr /><br /> @@ -194,14 +282,116 @@ else { linSysLog(i18n(sprintf(i18n("Error While Renaming File/Folder \"%s\" to \"%s\"!"),$full_filename,$parent_dirname.'/'.$new_name)).'<br />'); - linSysLog(i18n("Check the permissions in the linpha albums folder. (This means NOT the write permissions page in the admin section)").'<br />'); + linSysLog(i18n($str_checkpermissions).'<br />'); } break; case 'move': - break; - case 'copy': + /** + * check write permission of target folder + * AND it will also check if it is a valid id (?) + */ + if( ! $GLOBALS['linpha']->sql->photoIsAllowed( $_POST['movecopy_to'], 'write') ) + { + throw new Exception(i18n("You don't have permissions to this folder!")); + } + + /** + * get target name + */ + $full_destparentname = LinSql::getFullImagePath( $_POST['movecopy_to'] ); + + /** + * go through each folder + */ + $checkedfiles = explode(';',$_POST['checkedfiles']); + foreach($checkedfiles AS $value) + { + /** + * get full source name + */ + $full_sourcename = LinSql::getFullImagePath( $value ); + + if( nameAlreadyExists( basename($full_sourcename), $_POST['movecopy_to'] )) + { + throw new Exception(i18n("A File/Folder with the same name already exists!")); + } + + /** + * move + */ + if( $_POST['file_action'] == 'move') + { + /** + * check write permission of parent source folder + */ + $data = $GLOBALS['linpha']->db->GetRow("SELECT parent_id FROM ".PREFIX."photos " . + "WHERE id = '".LinSql::linAddslashes($value)."'"); + if($_POST['file_action'] == 'move') + { + if( ! $GLOBALS['linpha']->sql->photoIsAllowed( $data['parent_id'], 'write') ) + { + throw new Exception(i18n("You don't have permissions to this folder!")); + } + } + + if( rename($full_sourcename, $full_destparentname.'/'.basename($full_sourcename) ) ) + { + $GLOBALS['linpha']->db->Execute("UPDATE ".PREFIX."photos " . + "SET parent_id = '".LinSql::linAddslashes($_POST['movecopy_to'])."' " . + "WHERE id = '".LinSql::linAddslashes($value)."'"); + + linSysLog( + sprintf( + i18n("Successfully Moved \"%s\" to \"%s\"!"), + $full_sourcename, + $full_destparentname.'/'.basename($full_sourcename) + ) . "<br />" + ); + } + else + { + linSysLog(i18n(sprintf(i18n("Error While Moving Files/Folders \"%s\" to \"%s\"!"),$full_sourcename,$full_destparentname.'/'.basename($full_sourcename))).'<br />'); + linSysLog(i18n($str_checkpermissions).'<br />'); + } + } + /** + * copy + */ + elseif( $_POST['file_action'] == 'copy') + { + /** + * check read permission of source folder (not parent! ...) and content + */ + if( ! $GLOBALS['linpha']->sql->photoIsAllowed( $value, 'read') ) + { + throw new Exception(i18n("You don't have permissions to this folder!")); + } + + if( is_writable($full_destparentname) ) + { + /** + * copy files/folders (only which we have read permission) + */ + copy_r( $value, $full_sourcename, $full_destparentname); + + linSysLog( + sprintf( + i18n("Successfully Copied \"%s\" to \"%s\"!"), + $full_sourcename, + $full_destparentname.'/'.basename($full_sourcename) + ) . "<br />" + ); + } + else + { + linSysLog(i18n(sprintf(i18n("Error While Copying Files/Folders \"%s\" to \"%s\"!"),$full_sourcename,$full_destparentname.'/'.basename($full_sourcename))).'<br />'); + linSysLog(i18n($str_checkpermissions).'<br />'); + } + } + } + break; case 'delete': @@ -229,8 +419,8 @@ } else { - linSysLog(i18n("Error While Deleting Folder")." \"".$full_filename."\"".'<br />'); - linSysLog(i18n("Check the permissions in the linpha albums folder. (This means NOT the write permissions page in the admin section)").'<br />'); + linSysLog(i18n("Error While Deleting Files/Folders")." \"".$full_filename."\"".'<br />'); + linSysLog(i18n($str_checkpermissions).'<br />'); } } break; @@ -239,42 +429,170 @@ /** * check write permission of parent folder */ - if( ! $GLOBALS['linpha']->sql->photoIsAllowed( $_POST['file_id'], 'write') ) + if( ! $GLOBALS['linpha']->sql->photoIsAllowed( $_GET['id'], 'write') ) { throw new Exception(i18n("You don't have permissions to this folder!")); } $new_name = removeUnWantedChars( $_POST['folder_name'] ); - if( nameAlreadyExists( $new_name, $_POST['file_id'] )) + if( nameAlreadyExists( $new_name, $_GET['id'] )) { throw new Exception(i18n("A File/Folder with the same name already exists!")); } - $full_filename = LinSql::getFullImagePath( $_POST['file_id'] ); + $full_filename = LinSql::getFullImagePath( $_GET['id'] ); if( @mkdir( $full_filename .'/'. $new_name )) { linSysLog(i18n("Folder Created Successfully!").'<br />'); - linSysLog(i18n("You may now want to start the Import to make your changes appear").'<br />'); + + if( ! $linpha->sql->config->value['sys_import_autoimport'] ) + { + linSysLog(i18n("Autoimport is disabled, you need now to start the manual import to make your changes appear, but you maybe don't have permissions to do that...").'<br />'); + } } else { linSysLog(i18n("Error While Creating Folder")." \"".$new_name."\"".'<br />'); - linSysLog(i18n("Check the permissions in the linpha albums folder. (This means NOT the write permissions page in the admin section)").'<br />'); + linSysLog(i18n($str_checkpermissions).'<br />'); } break; + case 'changeperm': + $full_filename = LinSql::getFullImagePath( $_POST['file_id'] ); + + isset($_POST['ur']) ? $ur = $_POST['ur'] : $ur = 0; + isset($_POST['uw']) ? $uw = $_POST['uw'] : $uw = 0; + isset($_POST['ux']) ? $ux = $_POST['ux'] : $ux = 0; + isset($_POST['gr']) ? $gr = $_POST['gr'] : $gr = 0; + isset($_POST['gw']) ? $gw = $_POST['gw'] : $gw = 0; + isset($_POST['gx']) ? $gx = $_POST['gx'] : $gx = 0; + isset($_POST['or']) ? $or = $_POST['or'] : $or = 0; + isset($_POST['ow']) ? $ow = $_POST['ow'] : $ow = 0; + isset($_POST['ox']) ? $ox = $_POST['ox'] : $ox = 0; + + $u = $ur+$uw+$ux; + $g = $gr+$gw+$gx; + $o = $or+$ow+$ox; + + $mode = $u.$g.$o; + + if(@chmod($full_filename,intval($mode,8))) + { + linSysLog(i18n("Permissions Changed Successfully!").'<br />'); + } + else + { + linSysLog(i18n("Error While Changing Permissions!").'<br />'); + linSysLog(i18n($str_checkpermissions).'<br />'); + } + break; + } // end switch($_POST['file_action']) + break; // end case 'do_file_action': + + case 'upload': + $targetdir = LinSql::getFullImagePath( $_GET['id'] ); + + for($i = 0; $i < $GLOBALS['linpha']->sql->config->value['plugins_filemanager_nruploads']; $i++ ) + { + if( isset( $_FILES[ 'file' . $i ] ) && !empty( $_FILES[ 'file' . $i]['name'] ) ) // need empty check because it file$i exists in PHP 4.1 + { + $thisfile = $_FILES[ 'file' . $i ]; + $failed = 0; + + if (isset($thisfile['error']) && $thisfile['error'] != 0 ) // ['error'] was added in PHP 4.2.0 + { + switch ( $thisfile['error'] ) + { + case 1: + echo sprintf(i18n("Error: The uploaded file %s exceeds the upload_max_filesize directive in php.ini - %s"), $thisfile['name'], ini_get('upload_max_filesize') ); + //linpha_log('filemanager','error', + // 'User '.$_SESSION['user_name'].": upload failed for(".$thisfile['name'].") message: (".STR_FILE_UPLOAD_ERROR_FILE_EXCEEDS_INI_SIZE.")"); + break; + case 2: + echo sprintf(i18n("Error: size of uploaded file %s exceeds the HTML FORM settings"), $thisfile['name'] ); + //linpha_log('filemanager','error', + // 'User '.$_SESSION['user_name'].": upload failed for(".$thisfile['name'].") message: (".STR_FILE_UPLOAD_ERROR_FILE_EXCEEDS_FORM_SIZE.")"); + break; + case 3: + echo sprintf(i18n("Error: The uploaded file %s was only partially uploaded"), $thisfile['name'] ); + //linpha_log('filemanager','error', + // 'User '.$_SESSION['user_name'].": upload failed for(".$thisfile['name'].") message: (".STR_FILE_UPLOAD_ERROR_FILE_PARTIAL.")"); + break; + } + } + else + { + if ( !move_uploaded_file( $thisfile['tmp_name'], $targetdir . '/' . $thisfile['name']) ) + { + $failed = 1; + } + + if ( $_POST[ 'app' . $i ] != '-' ) // extracting selected + { + $command = $apps->apps[$_POST['app'.$i]]['command_extract']; + $apps->searchApp($_POST['app'.$i]); + + $executable = $apps->found_apps[$_POST['app'.$i]].$apps->apps[$_POST['app'.$i]]['executable_extract']; + + $command = str_replace('{executable}',$executable,$command); + $command = str_replace('{archive_name}',linEscapeString($thisfile['name']),$command); + + $oldpwd = getcwd(); + if ( !chdir( $targetdir ) ) { + $failed = 2; + } + else + { + exec( $command, $output, $return_value ); + chdir( $oldpwd ); + + + echo '<textarea cols="80" rows="4"">' . + $command . "\n". + implode( "\n", $output ) . + '</textarea><br />'; + + unset($output); + + if (!unlink( $targetdir . '/' . $thisfile['name'] )) { + $failed = 3; + } + } + } + + switch ($failed) + { + case 0: + //linpha_log('filemanager','notice', + // 'User '.$_SESSION['user_name'].": uploaded file (".$thisfile['tmp_name']." ".$targetdir.'/'.$thisfile['name'].")"); + + break; + case 1: + echo sprintf( i18n("Error: Unable to move file %s to directory %s"), $thisfile[ 'name' ], $targetdir ); + //linpha_log('filemanager','error', + // 'User '.$_SESSION['user_name'].": upload failed for(".$thisfile['name'].") message: (".STR_FILE_UPLOAD_ERROR.")"); + break; + case 2: + echo sprintf( i18n("Error: Unable to switch (chdir) to %s directory. File being processed: %s"), $targetdir, $thisfile[ 'name' ] ); + //linpha_log('filemanager','error', + // 'User '.$_SESSION['user_name'].": upload chdir failed for(".$thisfile['name'].") message: (".STR_FILE_UPLOAD_CHDIR_ERROR.")"); + break; + case 3: + echo sprintf( i18n("Error: Unable to delete %s after processing."), $targetdir . '/' . $thisfile['name'] ); break; + //linpha_log('filemanager','error', + // 'User '.$_SESSION['user_name'].": upload unlink for(".$thisfile['name'].") message: (".STR_FILE_UPLOAD_UNLINK_ERROR.")"); + break; + } + } + } } - break; - case 'upload': - - break; } } catch(Exception $error) { - echo "Error: ".$error -> getMessage(); + echo "Error: ".$error -> getMessage().'<br /><br />'; } /** @@ -284,12 +602,38 @@ { echo $GLOBALS['linpha']->template->output['sys_log']; echo '<hr />'; + unset($GLOBALS['linpha']->template->output['sys_log']); } } + +/** + * do import + */ + if( $linpha->sql->config->value['sys_import_autoimport'] ) + { + /** + * empty syslog + */ + unset($GLOBALS['linpha']->template->output['sys_log']); + + LinImport::updateDir( $parent_id, $recursive = false, $dryrun = false ); + + /** + * print Syslog + */ + if( isset($GLOBALS['linpha']->template->output['sys_log']) ) + { + echo i18n("LinPHA Import:").'<br />'; + echo $GLOBALS['linpha']->template->output['sys_log']; + echo '<hr />'; + unset($GLOBALS['linpha']->template->output['sys_log']); + } + } ?> <form method="POST" action="<?php echo LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; ?>"> -<table border="1"> +<div id="filemanager"> +<table> <tr> <td> </td> <td width="500"> </td> @@ -301,9 +645,9 @@ <?php if($parent_id != 0) { + echo i18n("Current Folder:").' / '.implode(' / ',LinSql::getFullFilenameFromId( $parent_id )).'<br />'; + $data = $GLOBALS['linpha']->db->GetRow("SELECT name, parent_id FROM ".PREFIX."photos WHERE id = '".LinSql::linAddslashes($parent_id)."'"); - - echo i18n("Current Folder:").' '.$data['name'].'<br />'; ?> <tr> <td> </td> @@ -374,7 +718,7 @@ if($uid == $filestat['uid']) { - $file_permissions = '<a href="'.LINPHA_DIR.'/?cat=filemanager&cmd=change_perm_form">'. $perm . '</a>'; + $file_permissions = '<a href="'.LINPHA_DIR.'/?cat=filemanager&cmd=file_action&file_action=changeperm&checkedfiles[]='.$data['id'].'">'. $perm . '</a>'; } else { @@ -385,8 +729,21 @@ ?> <tr> <td> - <?php if($isWriteAble) { ?> - <input type="checkbox" name="checkedfiles[]" value="<?php echo $data['id']; ?>" /> + <?php + if($isWriteAble) + { + if( isset($_REQUEST['checkedfiles']) + && is_array($_REQUEST['checkedfiles']) + && in_array($data['id'], $_REQUEST['checkedfiles']) ) + { + $str_checked = ' checked="checked"'; + } + else + { + $str_checked = ''; + } + ?> + <input type="checkbox" name="checkedfiles[]" value="<?php echo $data['id']; ?>"<?php echo $str_checked; ?> /> <?php } else { ?> <?php } ?> @@ -412,38 +769,93 @@ } ?> </table> -<input type="radio" id="file_rename" name="file_action" value="rename" checked="checked" /><label for="file_rename"> <?php echo i18n("Rename"); ?></label> -<input type="radio" id="file_move" name="file_action" value="move" /><label for="file_move"> <?php echo i18n("Move"); ?></label> -<input type="radio" id="file_copy" name="file_action" value="copy" /><label for="file_copy"> <?php echo i18n("Copy"); ?></label> -<input type="radio" id="file_delete" name="file_action" value="delete" /><label for="file_delete"> <?php echo i18n("Delete"); ?></label> + +<?php +/** + * set checked radio buttons + */ + $array_values = Array('rename','move','copy','delete'); + foreach($array_values AS $value) + { + if(isset($_POST['file_action']) && $_POST['file_action'] == $value) + { + $arr_checked[$value] = ' checked="checked"'; + $somtething_checked = true; + } + else + { + $arr_checked[$value] = ''; + } + } + + /** + * default checked + */ + if(!isset($something_checked)) + { + $arr_checked['rename'] = ' checked="checked"'; + } + +if($isWriteAble) +{ +?> +<input type="radio" id="file_rename" name="file_action" value="rename"<?php echo $arr_checked['rename']; ?> /><label for="file_rename"> <?php echo i18n("Rename"); ?></label> +<input type="radio" id="file_move" name="file_action" value="move"<?php echo $arr_checked['move']; ?> /><label for="file_move"> <?php echo i18n("Move"); ?></label> +<input type="radio" id="file_copy" name="file_action" value="copy"<?php echo $arr_checked['copy']; ?> /><label for="file_copy"> <?php echo i18n("Copy"); ?></label> +<input type="radio" id="file_delete" name="file_action" value="delete"<?php echo $arr_checked['delete']; ?> /><label for="file_delete"> <?php echo i18n("Delete"); ?></label> <input type="hidden" name="cmd" value="file_action" /> <input type="submit" name="submit" value="<?php echo i18n("Submit"); ?>" /> </form> - <br /><br /> <form method="POST" action="<?php echo LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; ?>"> <input type="text" name="folder_name" value="" /> -<input type="hidden" name="file_id" value="<?php echo $parent_id; ?>" /> <input type="hidden" name="cmd" value="do_file_action" /> <input type="hidden" name="file_action" value="create_folder" /> <input type="submit" name="submit" value="<?php echo i18n("Create Folder"); ?>" /> </form> <br /><br /> -<form method="POST" action="<?php echo LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; ?>"> -<input type="file" name="uploadfile0" value="" /><br /> -<input type="file" name="uploadfile1" value="" /><br /> -<input type="file" name="uploadfile2" value="" /><br /> -<input type="file" name="uploadfile3" value="" /><br /> -<input type="file" name="uploadfile4" value="" /><br /> +<h2><?php echo i18n("Upload Files"); ?></h2> +<form method="POST" enctype="multipart/form-data" action="<?php echo LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; ?>"> +<?php echo i18n("Choose files you would like to upload. Choose desired action to accomplish upon succesful upload.").'<br />'; ?> +<?php echo i18n("Allowed filesize (each file!) maximum currently set in php.ini is:").' '.ini_get('upload_max_filesize').'<br />'; ?> +<br /> +<?php echo i18n("Note: You don't have to upload your images through this form. You can use whatever you want (ftp,scp,nfs,local,...). Just copy them to the albums folder."); ?> +<br /> +<?php +$max_uploads = 5; +for($i = 0; $i < $GLOBALS['linpha']->sql->config->value['plugins_filemanager_nruploads']; $i++) +{ + echo '<input type="file" name="file'.$i.'" value="" /> '; + echo '<select name="app'.$i.'">'.$appselect.'</select><br />'; +} +?> + <input type="hidden" name="cmd" value="upload" /> <input type="submit" name="submit" value="<?php echo i18n("Upload Files"); ?>"/> </form> +<?php +} +?> +</div> + <?php +$linpha->template->output['filemanager'] = ob_get_clean(); +?> +<?php +$linpha->template->setModuleName('filemanager'); +$linpha->template->URL_full = LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; +$linpha->template->output['title'] = i18n("Filemanager"); +include_once(LINPHA_DIR.'/templates/'.$linpha->template->template_name.'/global.html.php'); +exit(); +?> + + +<?php /** * found on http://ch.php.net/manual/en/function.fileperms.php */ @@ -571,4 +983,37 @@ return true; } } + +/** + * recursively copy files/folders + * check read permission of source folder + * -> check each subentry! + */ +function copy_r( $source_id, $source, $dest ) +{ + if( $GLOBALS['linpha']->sql->photoIsAllowed( $source_id, 'read' ) ) + { + $data = $GLOBALS['linpha']->db->GetRow("SELECT img_type FROM ".PREFIX."photos " . + "WHERE id = '".LinSql::linAddslashes($source_id)."'"); + + if($data['img_type']!=0) + { + @copy( $source, $dest.'/'.basename($source)); + } + else + { + mkdir( $dest.'/'.basename($source) ); + + $query = $GLOBALS['linpha']->db->Execute("SELECT id, name, img_type FROM ".PREFIX."photos " . + "WHERE parent_id = '".LinSql::linAddslashes($source_id)."'"); + while($data = $query->FetchRow()) + { + if( file_exists($source.'/'.$data['name'] ) ) + { + copy_r( $data['id'], $source.'/'.$data['name'], $dest.'/'.basename($source) ); + } + } + } + } +} ?> \ No newline at end of file Added: trunk/linpha2/templates/default/css/filemanager.css =================================================================== --- trunk/linpha2/templates/default/css/filemanager.css (rev 0) +++ trunk/linpha2/templates/default/css/filemanager.css 2006-04-28 19:08:11 UTC (rev 4552) @@ -0,0 +1,10 @@ +#filemanager table +{ + border-collapse:collapse; +} + +#filemanager td +{ + border:1px solid black; + padding:5px; +} \ No newline at end of file Added: trunk/linpha2/templates/default/filemanager.html.php =================================================================== --- trunk/linpha2/templates/default/filemanager.html.php (rev 0) +++ trunk/linpha2/templates/default/filemanager.html.php 2006-04-28 19:08:11 UTC (rev 4552) @@ -0,0 +1,19 @@ +<div id="divmain"> + <div class="roundtop"> + <img src="<?php echo LINPHA_DIR.'/templates/'.$GLOBALS['linpha']->template->template_name.'/images/tl.gif'; ?>" alt="" width="15" height="15" class="corner" style="display: none" /> + </div> + + <div id="main"> + + +<?php +echo $GLOBALS['linpha']->template->output['filemanager']; +?> + + + </div> + + <div class="roundbottom"> + <img src="<?php echo LINPHA_DIR.'/templates/'.$GLOBALS['linpha']->template->template_name.'/images/bl.gif'; ?>" alt="" width="15" height="15" class="corner" style="display: none" /> + </div> +</div> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |