[vhffs-dev] [1052] Administrator can now change type of users (admin, moderator, normal ).

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1052
Author:   beuss
Date:     2007-11-01 10:29:27 +0000 (Thu, 01 Nov 2007)

Log Message:
-----------
Administrator can now change type of users (admin, moderator, normal).

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Main.pm
    trunk/vhffs-api/src/Vhffs/User.pm
    trunk/vhffs-panel/templates/Makefile.am
    trunk/vhffs-panel/templates/user/prefs.tmpl
    trunk/vhffs-panel/user/prefs.pl

Added Paths:
-----------
    trunk/vhffs-panel/templates/user/admin.tmpl


Modified: trunk/vhffs-api/src/Vhffs/Panel/Main.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Main.pm	2007-11-01 08:14:02 UTC (rev 1051)
+++ trunk/vhffs-api/src/Vhffs/Panel/Main.pm	2007-11-01 10:29:27 UTC (rev 1052)
@@ -252,7 +252,7 @@
 	my @files = readdir( DIR );
 	foreach( @files )
 	{
-		next if( /\./);
+		next if( /^\./);
 		if( -d $dir."/".$_ )
 		{
 			push @langs , $_;

Modified: trunk/vhffs-api/src/Vhffs/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/User.pm	2007-11-01 08:14:02 UTC (rev 1051)
+++ trunk/vhffs-api/src/Vhffs/User.pm	2007-11-01 10:29:27 UTC (rev 1052)
@@ -667,6 +667,10 @@
 	}
 }
 
+sub get_permissions {
+    my $self = shift;
+    return $self->{admin};
+}
 
 sub get_name_by_uid
 {   

Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am	2007-11-01 08:14:02 UTC (rev 1051)
+++ trunk/vhffs-panel/templates/Makefile.am	2007-11-01 10:29:27 UTC (rev 1052)
@@ -105,6 +105,7 @@
 	git/create.tmpl \
 	git/prefs.tmpl \
 	git/user_part.tmpl \
+	user/admin.tmpl \
 	user/create_complete.tmpl \
 	user/create.tmpl \
 	user/mailuserspam.tmpl \

Added: trunk/vhffs-panel/templates/user/admin.tmpl
===================================================================
--- trunk/vhffs-panel/templates/user/admin.tmpl	                        (rev 0)
+++ trunk/vhffs-panel/templates/user/admin.tmpl	2007-11-01 10:29:27 UTC (rev 1052)
@@ -0,0 +1,12 @@
+<h2><TMPL_I18N KEY="User's Permissions"></h2>
+<form method="post" action="#">
+    <input type="hidden" name="name" value="<TMPL_VAR NAME="VALUE_USERNAME">"/>
+    <p><label for="user_permissions"><TMPL_I18N KEY="User's permissions">:</label>
+    <select name="permissions" id="user_permissions">
+        <option value="<TMPL_VAR NAME="USER_NORMAL">" <TMPL_IF EXPR="PERMISSIONS == USER_NORMAL">selected="selected"</TMPL_IF>><TMPL_I18N KEY="Normal"></option>
+        <option value="<TMPL_VAR NAME="USER_MODERATOR">" <TMPL_IF EXPR="PERMISSIONS == USER_MODERATOR">selected="selected"</TMPL_IF>><TMPL_I18N KEY="Moderator"></option>
+        <option value="<TMPL_VAR NAME="USER_ADMIN">" <TMPL_IF EXPR="PERMISSIONS == USER_ADMIN">selected="selected"</TMPL_IF>><TMPL_I18N KEY="Administrator"></option>
+    </select>
+    </p>
+    <p><input type="submit" name="update_permissions_submit" value="<TMPL_I18N KEY="Update Permissions">"/></p>
+</form>

Modified: trunk/vhffs-panel/templates/user/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/user/prefs.tmpl	2007-11-01 08:14:02 UTC (rev 1051)
+++ trunk/vhffs-panel/templates/user/prefs.tmpl	2007-11-01 10:29:27 UTC (rev 1052)
@@ -53,25 +53,25 @@
 				<p>
 					<label for="LANG"><tmpl_var name="TEXT_LANG"> :</label>
 					<select name="LANG" id="LANG">
-						<tmpl_var name="LANG_LIST">
+						<tmpl_var escape=0 name="LANG_LIST">
 					</select>
 				</p>
 
 				<p>
 					<label for="THEME"><tmpl_var name="TEXT_THEME"> :</label>
 					<select name="THEME" id="THEME">
-						<tmpl_var name="THEME_LIST">
+						<tmpl_var escape=0 name="THEME_LIST">
 					</select>
 				</p>
 
 				<p>
 					<label for="SHELL"><tmpl_var name="TEXT_SHELL"> :</label>
 					<select name="SHELL" id="SHELL">
-						<tmpl_var name="SHELL_LIST">
+						<tmpl_var escape=0 name="SHELL_LIST">
 					</select>
 				</p>
 				
-				<tmpl_var name="MAILUSER">
+				<tmpl_var escape=0 name="MAILUSER">
 				
 				<p class="button" id="buttonModify">
 					<tmpl_if name="HELP_URL">
@@ -83,7 +83,7 @@
 				<input type="hidden" name="name" value="<tmpl_var name="VALUE_USERNAME">" />
 			</form>
 
-			<tmpl_var name="AVATAR">
+			<tmpl_var escape=0 name="AVATAR">
 			
 			<h2><tmpl_var name="TEXT_DELETE_USER"></h2>
 			
@@ -113,4 +113,7 @@
                                 
 			</form>
 
-			<tmpl_var escape=0 name="ADMIN_PART">
+<TMPL_IF NAME="ADMIN">
+    <TMPL_VAR ESCAPE=0 NAME="ADMIN_PART">
+    <TMPL_INCLUDE NAME="admin.tmpl">
+</TMPL_IF>

Modified: trunk/vhffs-panel/user/prefs.pl
===================================================================
--- trunk/vhffs-panel/user/prefs.pl	2007-11-01 08:14:02 UTC (rev 1051)
+++ trunk/vhffs-panel/user/prefs.pl	2007-11-01 10:29:27 UTC (rev 1052)
@@ -45,6 +45,7 @@
 use Vhffs::Panel::Main;
 use Vhffs::Panel::User;
 use Vhffs::Panel::Object;
+use Vhffs::Panel::Template;
 use Vhffs::Services::MailUser;
 
 my $panel = new Vhffs::Panel::Main();
@@ -83,11 +84,7 @@
 }
 else
 {
-
-	my $submitted = defined($cgi->param('prefs_submit'));
-
-	if($submitted) {
-
+	if(defined $cgi->param('prefs_submit')) {
 		my $mail = $cgi->param( 'MAIL' );
 		my $firstname = Encode::decode_utf8( $cgi->param( 'FIRSTNAME' ) );
 		my $lastname = Encode::decode_utf8( $cgi->param( 'LASTNAME' ) );
@@ -292,11 +289,13 @@
 				}
 			}
 		}
-	} # if($submitted)
+	} elsif(defined $cgi->param('update_permissions_submit')) {
+        update_permissions();
+    }
 
 	$panel->set_title( gettext("User Preferences") );
 
-	$template = new HTML::Template( filename => $templatedir."/panel/user/prefs.tmpl" );
+	$template = new Vhffs::Panel::Template( filename => $templatedir."/panel/user/prefs.tmpl" );
 
 	$template->param( TEXT_USERNAME => gettext("Username") );
 	$template->param( TEXT_MAIL => gettext("mail") );
@@ -362,7 +361,7 @@
 	# languages
 	my @langs = Vhffs::Panel::Main::list_languages( $vhffs );
 	my $curlang = Vhffs::Panel::User::get_lang( $userp );
-	my $langlist;
+	my $langlist = '';
 	foreach( @langs ) {
 		if($curlang ne $_) {
 			$langlist .= "<option value=\"".$_."\">".$_."</option>\n";
@@ -444,9 +443,36 @@
 		$template->param( MAILUSER => $subtemplate->output );
 	}
 
-	my $adminpart = Vhffs::Panel::Object::admin_part( $panel, $userp );
-	$template->param( ADMIN_PART => $adminpart->output ) if( defined $adminpart );
+    if($user->is_admin) {
+    	my $adminpart = Vhffs::Panel::Object::admin_part( $panel, $userp );
+    	$template->param( ADMIN_PART => $adminpart->output ) if( defined $adminpart );
+        $template->param( ADMIN => 1 );
+        $template->param( PERMISSIONS => $userp->get_permissions );
+        $template->param( USER_NORMAL => Vhffs::Constants::USER_NORMAL );
+        $template->param( USER_MODERATOR => Vhffs::Constants::USER_MODERATOR );
+        $template->param( USER_ADMIN => Vhffs::Constants::USER_ADMIN );
+    }
 }
 
 $panel->build( $template );
 $panel->display;
+
+sub update_permissions {
+    unless( $user->is_admin ) {
+        $panel->add_error( gettext('Only administrators can do this') );
+        return;
+    }
+
+    my $permissions = $cgi->param('permissions');
+    unless(defined $permissions) {
+        $panel->add_error( gettext('CGI Error') );
+        return;
+    }
+
+    $userp->set_admin($permissions);
+    if($userp->commit < 0) {
+        $panel->add_error( gettext('Unable to update user, please try again later') );
+    } else {
+        $panel->add_info( gettext('User sucessfuly updated') );
+    }
+}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/