[Linpha-cvs] SF.net SVN: linpha: [4548] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <fan...@us...> - 2006-04-25 22:05:55
|
Revision: 4548 Author: fangehrn Date: 2006-04-25 15:05:37 -0700 (Tue, 25 Apr 2006) ViewCVS: http://svn.sourceforge.net/linpha/?rev=4548&view=rev Log Message: ----------- Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/admin/permissions.php trunk/linpha2/install/sql/sql.data.php trunk/linpha2/lib/classes/linpha.sql.class.php trunk/linpha2/lib/modules/module.filemanager.php Added Paths: ----------- trunk/linpha2/admin/permissions_readwrite.php Removed Paths: ------------- trunk/linpha2/admin/permissions_read.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2006-04-24 21:02:12 UTC (rev 4547) +++ trunk/linpha2/ChangeLog 2006-04-25 22:05:37 UTC (rev 4548) @@ -1,3 +1,6 @@ +2006-04-25 flo + * filemanager: implementing read/write + 2006-04-24 flo * created import/index/create thumbnail/re-create-scripts in admin-import section * created a filemanager layout Modified: trunk/linpha2/admin/permissions.php =================================================================== --- trunk/linpha2/admin/permissions.php 2006-04-24 21:02:12 UTC (rev 4547) +++ trunk/linpha2/admin/permissions.php 2006-04-25 22:05:37 UTC (rev 4548) @@ -24,18 +24,20 @@ case 'users': include_once('./permissions_users.php'); break; + case 'groups': include_once('./permissions_groups.php'); break; + case 'usergroup': include_once('./permissions_usergroup.php'); break; + case 'view': - include_once('./permissions_read.php'); - break; case 'write': - include_once('./permissions_write.php'); + include_once('./permissions_readwrite.php'); break; + case 'basket': case 'metadata': case 'others': Deleted: trunk/linpha2/admin/permissions_read.php =================================================================== --- trunk/linpha2/admin/permissions_read.php 2006-04-24 21:02:12 UTC (rev 4547) +++ trunk/linpha2/admin/permissions_read.php 2006-04-25 22:05:37 UTC (rev 4548) @@ -1,312 +0,0 @@ -<?php -if(!defined('LINPHA_DIR')) { exit(1); } - -include_once(LINPHA_DIR.'/lib/adodb/tohtml.inc.php'); - - -/** - * save POST data - */ -if(isset($_POST['cmd']) && $_POST['cmd'] == 'save_permissions') -{ - /** - * insert or update - */ - $query = $linpha->db->Execute("SELECT id FROM ".PREFIX."permissions " . - "WHERE photos_id = '".LinSql::linAddslashes($_POST['photo_id'])."'"); - - /** - * if inherit is selected, delete if an entry exists - * and only if the photo_id != 0, because we can't delete - * the top permission entry!! - */ - if(isset($_POST['inherit'])) - { - if( ! $query->EOF && $_POST['photo_id'] != 0) - { - $linpha->db->Execute("DELETE FROM ".PREFIX."permissions " . - "WHERE photos_id = '".LinSql::linAddslashes($_POST['photo_id'])."'"); - } - } - else - { - if(isset($_POST['group'])) - { - if(in_array('public',$_POST['group'])) - { - $str_groups = 'public'; - } - else - { - $str_groups = implode(';',$_POST['group']); - } - } - else - { - /** - * no group selected - * -> only admin has permissions - */ - $str_groups = ''; - } - - if( ! $query->EOF ) - { - $linpha->db->Execute("UPDATE ".PREFIX."permissions SET permission = ';".LinSql::linAddslashes($str_groups).";' " . - "WHERE photos_id = '".LinSql::linAddslashes($_POST['photo_id'])."'"); - } - else - { - $linpha->db->Execute("INSERT into ".PREFIX."permissions (photos_id, perm_type, permission) VALUES (" . - "'".LinSql::linAddslashes($_POST['photo_id'])."', 'read'," . - "';".LinSql::linAddslashes($str_groups).";' )"); - } - } -} - -/** - * set parameters - */ - if(isset($_GET['parent_id']) && $_GET['parent_id'] != 0) - { - $parent_id = $_GET['parent_id']; - $view_mode = 'files'; - - $array = $GLOBALS['linpha']->sql->getFullFilenameFromId( LinSql::linAddslashes($parent_id) ); - - $parent_name = '<b>'.implode('/',$array).'</b>'; - $recursive = false; - } - else - { - $parent_id = 0; - $view_mode = 'folders'; - $parent_name = 'Top directory (default permission)'; - $recursive = true; - } - -/** - * get groups - */ - $array_groups = Array(); - $query = $GLOBALS['linpha']->db->Execute("SELECT id, group_name FROM ".PREFIX."groups WHERE group_name <> 'admin'"); - while($data = $query->FetchRow(ADODB_FETCH_NUM)) - { - $array_groups[$data[0]] = $data[1]; - } - -/** - * show edit/add permission dialog - */ -if(isset($_GET['cmd']) AND isset($_GET['id'])) -{ - $checked = ''; - $array_perms = array(); - - /** - * check wether add or edit (insert or update) - */ - $query = $linpha->db->Execute("SELECT id FROM ".PREFIX."permissions " . - "WHERE photos_id = '".LinSql::linAddslashes($_GET['id'])."'"); - - if( ! $query->EOF ) - { - list($stage, $perm) = $GLOBALS['linpha']->sql->getPerm( $_GET['id'] ); - $array_perms = explode(';',$perm); - - if(in_array('public',$array_perms)) - { - $checked = ' checked="checked"'; - } - } - - $query = $GLOBALS['linpha']->db->Execute("SELECT name FROM ".PREFIX."photos " . - "WHERE id = '".LinSql::linAddslashes($_GET['id'])."'"); - $data = $query->FetchRow(ADODB_FETCH_NUM); - ?> - <form name="permission" method="POST" action="<?php echo LINPHA_DIR.'/admin/?cat=permissions_view&parent_id='.$parent_id; ?>"> - <h3>Change/Add permissions of folder/file "<?php echo $data[0]; ?>"</h3> - - <?php - /** - * top folder can't be inherit - * -> make sure we cannot delete this entry! - */ - if($_GET['id'] != 0) - { - ?> - <input type="checkbox" name="inherit" value="1" />inherit from parent<br /> - <?php - } - ?> - - <input type="checkbox" name="admin" value="1" checked="checked" disabled="disabled"/>admin<br /> - <input type="checkbox" name="group[]" value="public"<?php echo $checked; ?> />public<br /> - - <?php - foreach($array_groups AS $key=>$value) - { - if(in_array($key,$array_perms)) - { - $checked = ' checked="checked"'; - } - else - { - $checked = ''; - } - - echo '<input type="checkbox" name="group[]" value="'.$key.'"'.$checked.' />'.$value.'<br />'; - } - ?> - <input type="hidden" name="photo_id" value="<?php echo $_GET['id']; ?>" /> - <input type="hidden" name="parent_id" value="<?php echo $parent_id; ?>" /> - <input type="hidden" name="cmd" value="save_permissions" /> - <input type="submit" name="submit" value="save" /> - <a href="<?php echo LINPHA_DIR.'/admin/?cat=permissions_view&parent_id='.$parent_id; ?>">cancel</a> - </form> - <br /><br /> - <?php -} - -/** - * print permissions - */ - list($stage, $perm) = $GLOBALS['linpha']->sql->getPerm( $parent_id ); - ?> - Current directoy: <?php echo $parent_name; ?> - <?php - if(isset($_GET['parent_id']) && $_GET['parent_id'] != 0) - { - echo ' (<a href="'.LINPHA_DIR.'/admin/?cat=permissions_view&parent_id=0">Show all folders</a>)'; - } - ?> - <br /> - Permission set: <b><?php echo get_readable_perms($perm); ?></b> - (<a href="<?php echo LINPHA_DIR.'/admin/?cat=permissions_view&parent_id='.$parent_id.'&cmd=edit&id='.$parent_id; ?>">change</a>) - <br /><br /> - <table border='1'> - <tr> - <td width='200'>Name</td> - <td width='200'>Permission set</td> - <td width='200'>Permission inherited</td> - <td width='200'>Modifications</td> - </tr> - <?php - print_dir_perms_entry( $parent_id , $recursive , $stage=0); - ?> - </table> - </form> - - <?php -/** - * print the permission entries - */ -function print_dir_perms_entry( $parent_id , $recursive , $stage) -{ - $query = $GLOBALS['linpha']->db->Execute("SELECT id, name, img_type FROM ".PREFIX."photos WHERE parent_id = '".$parent_id."'"); - while( $data = $query->FetchRow() ) - { - list($i, $perm) = $GLOBALS['linpha']->sql->getPerm( $data['id'] ); - - /** - * exclude files - */ - if($data['img_type'] == 0 // show folders - || $GLOBALS['view_mode']=='files' // show files if we not on top - || ( $data['img_type'] != 0 && $i == 0 ) ) // show files which have permissions explicitly set (not inherited) - { - echo '<tr><td>'; - echo str_repeat(' >',$stage).' '; - if($data['img_type']==0) - { - echo '<a href="'.LINPHA_DIR.'/admin/?cat=permissions_view&parent_id='.$data['id'].'">'.$data['name'].'</a>'; - } - else - { - echo $data['name']; - } - echo '</td><td>'; - - if($i == 0) - { - echo get_readable_perms($perm); - } - else - { - echo ' '; - } - - - echo '</td><td>'; - - if($i != 0) - { - echo get_readable_perms($perm); - } - else - { - echo ' '; - } - - echo '</td><td>'; - - if($i != 0) - { - echo '<a href="'.LINPHA_DIR.'/admin/?cat=permissions_view&parent_id='.$GLOBALS['parent_id'].'&cmd=edit&id='.$data['id'].'">add</a>'; - } - else - { - echo '<a href="'.LINPHA_DIR.'/admin/?cat=permissions_view&parent_id='.$GLOBALS['parent_id'].'&cmd=edit&id='.$data['id'].'">change</a>'; - } - echo '</td></tr>'; - - if($recursive && $data['img_type'] == "0") - { - print_dir_perms_entry( $data['id'] , true , $stage+1 ); - } - } - } -} // end function print_dir_perms_entry - - -/** - * functions - */ - - -/** - * convert - * ';1;2;' -> 'friends, another group, ' - * and ';public;' -> 'public' - * and '' -> 'admin' - * and ';' -> 'admin' - * and ';;' -> 'admin' - */ -function get_readable_perms( $perm ) -{ - global $array_groups; - - $array = explodeAndSlice(';',$perm); - - $str = ''; - foreach($array AS $value) - { - if($value == 'public') - { - $str .= 'public'; - } - elseif(isset($array_groups[$value])) - { - $str .= $array_groups[$value].', '; - } - } - - if(empty($str)) - { - $str = 'admin'; - } - return $str; -} - - -?> \ No newline at end of file Copied: trunk/linpha2/admin/permissions_readwrite.php (from rev 4545, trunk/linpha2/admin/permissions_read.php) =================================================================== --- trunk/linpha2/admin/permissions_readwrite.php (rev 0) +++ trunk/linpha2/admin/permissions_readwrite.php 2006-04-25 22:05:37 UTC (rev 4548) @@ -0,0 +1,348 @@ +<?php +if(!defined('LINPHA_DIR')) { exit(1); } + +if($cat2 == 'view') +{ + $sql_perm_type = 'read'; +} +elseif($cat2 == 'write') +{ + $sql_perm_type = 'write'; + + ?> + <br /><hr /><br /> + <form method="POST" action="<?php echo LINPHA_DIR.'/admin/?cat=permissions_'.$cat2; ?>"> + <?php + if(isset($_POST['cmd']) && $_POST['cmd']=='saveconfig') + { + saveConfig( + Array( + 'plugins_filemanager_enable' + ) + ); + } + + + printAdminConfig('radio',i18n("Enable Filemanager For Non-Admin Users"),'plugins_filemanager_enable'); + + ?> + <input type="hidden" name="cmd" value="saveconfig" /> + <input type="submit" name="submit" value="<?php echo i18n("Submit"); ?>" /> + </form> + <br /><hr /><br /> + <?php + + if(! $GLOBALS['linpha']->sql->config->value['plugins_filemanager_enable']) + { + exit(); + } +} + +/** + * save POST data + */ +if(isset($_POST['cmd']) && $_POST['cmd'] == 'save_permissions') +{ + /** + * insert or update + */ + $query = $linpha->db->Execute("SELECT id FROM ".PREFIX."permissions " . + "WHERE photos_id = '".LinSql::linAddslashes($_POST['photo_id'])."' AND perm_type = '".$sql_perm_type."'"); + + /** + * if inherit is selected, delete if an entry exists + * and only if the photo_id != 0, because we can't delete + * the top permission entry!! + */ + if(isset($_POST['inherit'])) + { + if( ! $query->EOF && $_POST['photo_id'] != 0) + { + $linpha->db->Execute("DELETE FROM ".PREFIX."permissions " . + "WHERE photos_id = '".LinSql::linAddslashes($_POST['photo_id'])."' " . + "AND perm_type = '".$sql_perm_type."'"); + } + } + else + { + if(isset($_POST['group'])) + { + if(in_array('public',$_POST['group'])) + { + $str_groups = 'public'; + } + else + { + $str_groups = implode(';',$_POST['group']); + } + } + else + { + /** + * no group selected + * -> only admin has permissions + */ + $str_groups = ''; + } + + if( ! $query->EOF ) + { + $linpha->db->Execute("UPDATE ".PREFIX."permissions SET permission = ';".LinSql::linAddslashes($str_groups).";' " . + "WHERE photos_id = '".LinSql::linAddslashes($_POST['photo_id'])."' AND perm_type = '".$sql_perm_type."'"); + } + else + { + $linpha->db->Execute("INSERT into ".PREFIX."permissions (photos_id, perm_type, permission) VALUES (" . + "'".LinSql::linAddslashes($_POST['photo_id'])."', '".$sql_perm_type."'," . + "';".LinSql::linAddslashes($str_groups).";' )"); + } + } +} + +/** + * set parameters + */ + if(isset($_GET['parent_id']) && $_GET['parent_id'] != 0) + { + $parent_id = $_GET['parent_id']; + $view_mode = 'files'; + + $array = $GLOBALS['linpha']->sql->getFullFilenameFromId( LinSql::linAddslashes($parent_id) ); + + $parent_name = '<b>'.implode('/',$array).'</b>'; + $recursive = false; + } + else + { + $parent_id = 0; + $view_mode = 'folders'; + $parent_name = 'Top directory (default permission)'; + $recursive = true; + } + +/** + * get groups + */ + $array_groups = Array(); + $query = $GLOBALS['linpha']->db->Execute("SELECT id, group_name FROM ".PREFIX."groups WHERE group_name <> 'admin'"); + while($data = $query->FetchRow(ADODB_FETCH_NUM)) + { + $array_groups[$data[0]] = $data[1]; + } + +/** + * show edit/add permission dialog + */ +if(isset($_GET['cmd']) AND isset($_GET['id'])) +{ + $checked = ''; + $array_perms = array(); + + /** + * check wether add or edit (insert or update) + */ + $query = $linpha->db->Execute("SELECT id FROM ".PREFIX."permissions " . + "WHERE photos_id = '".LinSql::linAddslashes($_GET['id'])."' AND perm_type = '".$sql_perm_type."'"); + + if( ! $query->EOF ) + { + list($stage, $perm) = $GLOBALS['linpha']->sql->getPerm( $_GET['id'], $sql_perm_type ); + $array_perms = explode(';',$perm); + + if(in_array('public',$array_perms)) + { + $checked = ' checked="checked"'; + } + } + + $query = $GLOBALS['linpha']->db->Execute("SELECT name FROM ".PREFIX."photos " . + "WHERE id = '".LinSql::linAddslashes($_GET['id'])."'"); + $data = $query->FetchRow(ADODB_FETCH_NUM); + ?> + <form name="permission" method="POST" action="<?php echo LINPHA_DIR.'/admin/?cat=permissions_'.$cat2.'&parent_id='.$parent_id; ?>"> + <h3><?php echo i18n("Change/Add permissions of folder/file"); ?> "<?php echo $data[0]; ?>"</h3> + + <?php + /** + * top folder can't be inherit + * -> make sure we cannot delete this entry! + */ + if($_GET['id'] != 0) + { + ?> + <input type="checkbox" id="group_inherit" name="inherit" value="1" /><label for="group_inherit"> <?php echo i18n("Inherit From Parent"); ?></label><br /> + <?php + } + ?> + + <input type="checkbox" id="group_admin" name="admin" value="1" checked="checked" disabled="disabled"/><label for="group_admin"> admin</label><br /> + <input type="checkbox" id="group_public" name="group[]" value="public"<?php echo $checked; ?> /><label for="group_public"> public</label><br /> + + <?php + foreach($array_groups AS $key=>$value) + { + if(in_array($key,$array_perms)) + { + $checked = ' checked="checked"'; + } + else + { + $checked = ''; + } + + echo '<input type="checkbox" id="group_'.$key.'" name="group[]" value="'.$key.'"'.$checked.' /><label for="group_'.$key.'"> '.$value.'</a><br />'; + } + ?> + <input type="hidden" name="photo_id" value="<?php echo $_GET['id']; ?>" /> + <input type="hidden" name="parent_id" value="<?php echo $parent_id; ?>" /> + <input type="hidden" name="cmd" value="save_permissions" /> + <input type="submit" name="submit" value="save" /> + <a href="<?php echo LINPHA_DIR.'/admin/?cat=permissions_'.$cat2.'&parent_id='.$parent_id; ?>">cancel</a> + </form> + <br /><br /> + <?php +} + + +/** + * print permissions + */ + list($stage, $perm) = $GLOBALS['linpha']->sql->getPerm( $parent_id, $sql_perm_type ); + ?> + Current directoy: <?php echo $parent_name; ?> + <?php + if(isset($_GET['parent_id']) && $_GET['parent_id'] != 0) + { + echo ' (<a href="'.LINPHA_DIR.'/admin/?cat=permissions_'.$cat2.'&parent_id=0">Show all folders</a>)'; + } + ?> + <br /> + <?php echo i18n("Permission Set"); ?>: <b><?php echo getReadablePerms($perm); ?></b> + (<a href="<?php echo LINPHA_DIR.'/admin/?cat=permissions_'.$cat2.'&parent_id='.$parent_id.'&cmd=edit&id='.$parent_id; ?>">change</a>) + <br /><br /> + <table border='1'> + <tr> + <td width='200'><?php echo i18n("Name"); ?></td> + <td width='200'><?php echo i18n("Permission Set"); ?></td> + <td width='200'><?php echo i18n("Permission Inherited"); ?></td> + <td width='200'><?php echo i18n("Modifications"); ?></td> + </tr> + <?php + printDirPermsEntry( $parent_id , $recursive , $stage=0); + ?> + </table> + </form> + + <?php +/** + * print the permission entries + */ +function printDirPermsEntry( $parent_id , $recursive , $stage) +{ + $query = $GLOBALS['linpha']->db->Execute("SELECT id, name, img_type FROM ".PREFIX."photos WHERE parent_id = '".$parent_id."'"); + while( $data = $query->FetchRow() ) + { + list($i, $perm) = $GLOBALS['linpha']->sql->getPerm( $data['id'], $GLOBALS['sql_perm_type'] ); + + /** + * exclude files + */ + if($data['img_type'] == 0 // show folders + || ($GLOBALS['view_mode']=='files' && $GLOBALS['cat2']=='read') // show files if we not on top (and it doesnt make sense to give write permissions to the file itself) + || ( $data['img_type'] != 0 && $i == 0 ) ) // show files which have permissions explicitly set (not inherited) + { + echo '<tr><td>'; + echo str_repeat(' >',$stage).' '; + if($data['img_type']==0) + { + echo '<a href="'.LINPHA_DIR.'/admin/?cat=permissions_'.$GLOBALS['cat2'].'&parent_id='.$data['id'].'">'.$data['name'].'</a>'; + } + else + { + echo $data['name']; + } + echo '</td><td>'; + + if($i == 0) + { + echo getReadablePerms($perm); + } + else + { + echo ' '; + } + + + echo '</td><td>'; + + if($i != 0) + { + echo getReadablePerms($perm); + } + else + { + echo ' '; + } + + echo '</td><td>'; + + if($i != 0) + { + echo '<a href="'.LINPHA_DIR.'/admin/?cat=permissions_'.$GLOBALS['cat2'].'&parent_id='.$GLOBALS['parent_id'].'&cmd=edit&id='.$data['id'].'">add</a>'; + } + else + { + echo '<a href="'.LINPHA_DIR.'/admin/?cat=permissions_'.$GLOBALS['cat2'].'&parent_id='.$GLOBALS['parent_id'].'&cmd=edit&id='.$data['id'].'">change</a>'; + } + echo '</td></tr>'; + + if($recursive && $data['img_type'] == "0") + { + printDirPermsEntry( $data['id'] , true , $stage+1 ); + } + } + } +} // end function printDirPermsEntry + + +/** + * functions + */ + + +/** + * convert + * ';1;2;' -> 'friends, another group, ' + * and ';public;' -> 'public' + * and '' -> 'admin' + * and ';' -> 'admin' + * and ';;' -> 'admin' + */ +function getReadablePerms( $perm ) +{ + global $array_groups; + + $array = explodeAndSlice(';',$perm); + + $str = ''; + foreach($array AS $value) + { + if($value == 'public') + { + $str .= 'public'; + } + elseif(isset($array_groups[$value])) + { + $str .= $array_groups[$value].', '; + } + } + + if(empty($str)) + { + $str = 'admin'; + } + return $str; +} + + +?> \ No newline at end of file Modified: trunk/linpha2/install/sql/sql.data.php =================================================================== --- trunk/linpha2/install/sql/sql.data.php 2006-04-24 21:02:12 UTC (rev 4547) +++ trunk/linpha2/install/sql/sql.data.php 2006-04-25 22:05:37 UTC (rev 4548) @@ -62,7 +62,9 @@ 'sys_style_image_size' => '700', 'sys_style_image_nrprevnextthumbs' => '3', - 'sys_user_autologin' => '1' + 'sys_user_autologin' => '1', + + 'plugins_filemanager_enable' => '0' ); /** @@ -84,7 +86,10 @@ */ $sql_queries[] = "INSERT INTO ".PREFIX."permissions (photos_id, perm_type, permission) " . "VALUES (0, 'read', ';public;')"; +$sql_queries[] = "INSERT INTO ".PREFIX."permissions (photos_id, perm_type, permission) " . + "VALUES (0, 'write', ';;')"; + $sql_queries[] = "INSERT INTO ".PREFIX."permissions (perm_type, permission) " . "VALUES ('basket_print', '')"; $sql_queries[] = "INSERT INTO ".PREFIX."permissions (perm_type, permission) " . Modified: trunk/linpha2/lib/classes/linpha.sql.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.sql.class.php 2006-04-24 21:02:12 UTC (rev 4547) +++ trunk/linpha2/lib/classes/linpha.sql.class.php 2006-04-25 22:05:37 UTC (rev 4548) @@ -378,25 +378,26 @@ * @param photo id * @return array array(stage, permission) stage=0 if permission is not inherited */ -function getPerm( $photos_id ) +function getPerm( $photos_id, $perm_type ) { /** * special behaviour for top permission * the top permission is only for inheritation * for example: - * top perm = ;admin; + * top perm = ;admin; * perm folder1 = ;public; * perm folder2 = ;admin; - * users must be able to see folder1 + * users must be able to see folder1 */ - if($photos_id == 0) + if($photos_id == 0 && $perm_type == 'read') { return array(0, ';public;'); } for($i = 0 ; true ; $i++) { - $data = $GLOBALS['linpha']->db->GetRow("SELECT permission FROM ".PREFIX."permissions WHERE perm_type = 'read' " . + $data = $GLOBALS['linpha']->db->GetRow("SELECT permission FROM ".PREFIX."permissions " . + "WHERE perm_type = '".LinSql::linAddslashes($perm_type)."' " . "AND photos_id = '".linSql::linAddslashes($photos_id)."'"); if( isset( $data[0] ) && !empty( $data[0] ) ) @@ -425,7 +426,7 @@ /** * returns true if we're allowed to see this photo */ -function photoIsAllowed( $photo_id ) +function photoIsAllowed( $photo_id, $sql_perm_type = 'read' ) { /** * admin sees always all photos @@ -435,7 +436,7 @@ return true; } - list($stage,$perm) = LinSql::getPerm( $photo_id ); + list($stage,$perm) = LinSql::getPerm( $photo_id, $sql_perm_type ); $array_photo_perm = explodeAndSlice(';',$perm); foreach($array_photo_perm AS $value) Modified: trunk/linpha2/lib/modules/module.filemanager.php =================================================================== --- trunk/linpha2/lib/modules/module.filemanager.php 2006-04-24 21:02:12 UTC (rev 4547) +++ trunk/linpha2/lib/modules/module.filemanager.php 2006-04-25 22:05:37 UTC (rev 4548) @@ -19,39 +19,155 @@ */ /** - * Albums view related methods and functions + * Filemanager * @package Modules */ + +/** + * Short Permission Description + * If a user has write permission to folder A, it means that + * he can upload images to this folder, rename content, delete content + * But he cannot rename or delete the folder itself + * + * + * it doesnt make sense to give write permissions to the file itself + */ + if(!defined('LINPHA_DIR')) { exit(1); } -if(!isset($_GET['id'])) +/** + * init stuff + */ + if(!isset($_GET['id'])) + { + $parent_id = 0; + } + else + { + $parent_id = $_GET['id']; + } + + + $i = 0; + $sum['size'] = 0; + $sum['files'] = 0; + + $use_posix = checkPosix(); + + if($use_posix) { + $uid = @posix_getuid(); // get user id of current process + } else { + $uid = 0; + } + +/** + * check global permission + */ + if(! $GLOBALS['linpha']->sql->config->value['plugins_filemanager_enable'] + && !$GLOBALS['linpha']->sql->isAdmin()) + { + echo i18n("No Access!"); + exit(); + } + + if( ! $GLOBALS['linpha']->sql->photoIsAllowed( $parent_id, 'read' ) ) + { + echo i18n("No Access!"); + exit(); + } + + /** + * use this for child object + */ + if( $GLOBALS['linpha']->sql->photoIsAllowed( $parent_id, 'write' ) ) + { + $isWriteAble = true; + } + else + { + $isWriteAble = false; + } + +/** + * parsing POST data + */ +if(isset($_POST['cmd'])) { - $parent_id = 0; -} -else -{ - $parent_id = $_GET['id']; -} + switch($_POST['cmd']) + { + case 'file_action': + ?> + <form method="POST" action="<?php echo LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; ?>"> + <?php + switch($_POST['file_action']) + { + case 'rename': + ?> + <input type="text" name="do_rename" value="" /> + <?php + break; + case 'move': + case 'copy': + ?> + <select> + <option value=""></option> + <option value=""></option> + <option value=""></option> + </selet> + <?php + break; + case 'delete': + echo i18n("Really Sure?"); + break; + } + ?> + <input type="hidden" name="cmd" value="do_file_action" /> + <input type="hidden" name="file_action" value="<?php echo $_POST['file_action']; ?>" /> + <input type="submit" name="submit" value="<?php echo i18n("Submit"); ?>" /> + </form> + <?php + break; + case 'do_file_action': + switch($_POST['file_action']) + { + case 'rename': + break; -$i = 0; -$sum['size'] = 0; -$sum['files'] = 0; + case 'move': + break; -$use_posix = checkPosix(); + case 'copy': + break; -if($use_posix) { - $uid = @posix_getuid(); // get user id of current process -} else { - $uid = 0; -} + case 'delete': + break; + } + break; + case 'create_folder': + break; + case 'do_create_folder': + + break; + case 'upload': + + break; + } +} ?> +<form method="POST" action="<?php echo LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; ?>"> <table border="1"> + <tr> + <td> </td> + <td width="500"> </td> + <td width="100"> </td> + <td width="150"> </td> + <td width="100"> </td> + </tr> - <?php if($parent_id != 0) { @@ -73,110 +189,116 @@ while($data = $query->FetchRow()) { /** - * set file informations + * check read permission */ - $full_filename = LinSql::getFullImagePath( $data['id'] ); - $filestat = stat($full_filename); - - /** - * size and nr files - */ - if( $data['img_type'] != 0 && $data['img_type'] != 9999999 ) - { - $sum['size'] += $filestat['size']; - $sum['files']++; - } - - /** - * owner and group name - */ - if($use_posix) { - $owner_info = @posix_getpwuid($filestat['uid']); // use @ because check_posix() can return true even if it fails... - $group_info = @posix_getgrgid($filestat['gid']); - } else { - $owner_info['name'] = ''; - $group_info['name'] = ''; - } - - /** - * file permissions - */ - if(getOS() == 'win') + if( $GLOBALS['linpha']->sql->photoIsAllowed( $data['id'], 'read' ) ) { - $file_permissions = - '[' . - (is_readable($full_filename) ? '<font color="green">r</font>' : ' ') . - (is_writable($full_filename) ? '<font color="red">w</font>' : ' ') . - (function_exists('is_executable') ? - (is_executable($full_filename) ? '<font color="blue">x</font>' : ' ') - : - ' ' - ) . - ']'; - } else { - $perm = '['.getReadableFileperms($full_filename).']'; - - $perm = str_replace('r','<font color="green">r</font>',$perm); - $perm = str_replace('w','<font color="red">w</font>',$perm); - $perm = str_replace('x','<font color="blue">x</font>',$perm); - - if($uid == $filestat['uid']) - { - $file_permissions = '<a href="'.LINPHA_DIR.'/?cat=filemanager&cmd=change_perm_form">'. $perm . '</a>'; + /** + * set file informations + */ + $full_filename = LinSql::getFullImagePath( $data['id'] ); + $filestat = stat($full_filename); + + /** + * size and nr files + */ + if( $data['img_type'] != 0 && $data['img_type'] != 9999999 ) + { + $sum['size'] += $filestat['size']; + $sum['files']++; + } + + /** + * owner and group name + */ + if($use_posix) { + $owner_info = @posix_getpwuid($filestat['uid']); // use @ because check_posix() can return true even if it fails... + $group_info = @posix_getgrgid($filestat['gid']); + } else { + $owner_info['name'] = ''; + $group_info['name'] = ''; } - else + + /** + * file permissions + */ + if(getOS() == 'win') { - $file_permissions = $perm; + $file_permissions = + '[' . + (is_readable($full_filename) ? '<font color="green">r</font>' : ' ') . + (is_writable($full_filename) ? '<font color="red">w</font>' : ' ') . + (function_exists('is_executable') ? + (is_executable($full_filename) ? '<font color="blue">x</font>' : ' ') + : + ' ' + ) . + ']'; + } else { + $perm = '['.getReadableFileperms($full_filename).']'; + + $perm = str_replace('r','<font color="green">r</font>',$perm); + $perm = str_replace('w','<font color="red">w</font>',$perm); + $perm = str_replace('x','<font color="blue">x</font>',$perm); + + if($uid == $filestat['uid']) + { + $file_permissions = '<a href="'.LINPHA_DIR.'/?cat=filemanager&cmd=change_perm_form">'. $perm . '</a>'; + } + else + { + $file_permissions = $perm; + } } + + ?> + <tr> + <td> + <?php if($isWriteAble) { ?> + <input type="checkbox" name="checkedfiles[<?php echo $data['id']; ?>]" value="value" /> + <?php } else { ?> + + <?php } ?> + </td> + <td> + <?php + if($data['img_type']==0) + { + echo '<a href="'.LINPHA_DIR.'/?cat=filemanager&id='.$data['id'].'">'.$data['name'].'</a>'; + } + else + { + echo $data['name']; + } + ?> + </td> + <td align="right"><?php echo ($data['img_type']==0 OR $data['img_type']==9999999) ? ' ' : niceFilesize($filestat['size'],1); ?></td> + <td align="center"><?php echo strftime("%x %X",$filestat['mtime']); ?></td> + <td align="center" title="<?php echo $owner_info['name'].' '.$group_info['name']; ?>"><?php echo $file_permissions; ?></td> + </tr> + <?php } - - - - - - - - - ?> - <tr> - <td><input type="checkbox" name="checkedfiles[<?php echo $data['id']; ?>]" value="value" /></td> - <td width="500"> - <?php - if($data['img_type']==0) - { - echo '<a href="'.LINPHA_DIR.'/?cat=filemanager&id='.$data['id'].'">'.$data['name'].'</a>'; - } - else - { - echo $data['name']; - } - ?> - </td> - <td width="100" align="right"><?php echo ($data['img_type']==0 OR $data['img_type']==9999999) ? ' ' : niceFilesize($filestat['size'],1); ?></td> - <td width="150" align="center"><?php echo strftime("%x %X",$filestat['mtime']); ?></td> - <td width="100" align="center" title="<?php echo $owner_info['name'].' '.$group_info['name']; ?>"><?php echo $file_permissions; ?></td> - </tr> - <?php } ?> </table> -<input type="radio" name="file_action" value="rename" /><label for=""><?php echo ' '.i18n("Rename"); ?></label> -<input type="radio" name="file_action" value="rename" /><label for=""><?php echo ' '.i18n("Move"); ?></label> -<input type="radio" name="file_action" value="rename" /><label for=""><?php echo ' '.i18n("Copy"); ?></label> -<input type="radio" name="file_action" value="rename" /><label for=""><?php echo ' '.i18n("Delete"); ?></label> -<input type="submit" name="submit" value="<?php echo i18n("Submit"); ?>"/> +<input type="radio" id="file_rename" name="file_action" value="rename" /><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> +<input type="hidden" name="cmd" value="file_action" /> +<input type="submit" name="submit" value="<?php echo i18n("Submit"); ?>" /> </form> <br /><br /> -<form action="<?php echo LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; ?>"> +<form method="POST" action="<?php echo LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; ?>"> <input type="text" name="createfolder" value="" /> -<input type="hidden" name="cmd" value="createfolder" /> -<input type="submit" name="submit" value="<?php echo i18n("Create Folder"); ?>"/> +<input type="hidden" name="cmd" value="create_folder" /> +<input type="submit" name="submit" value="<?php echo i18n("Create Folder"); ?>" /> </form> <br /><br /> -<form action="<?php echo LINPHA_DIR.'/?cat=filemanager&id='.$parent_id; ?>"> +<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 /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |