Mailing List CGatePro@mail.stalker.com Message #100283
From: Nicolas Hatier <nicolas.hatier@niversoft.com>
Subject: Re: CLI.pm to switch user to default skin
Date: Mon, 21 Jun 2010 15:23:57 -0400
To: CommuniGate Pro Discussions <CGatePro@mail.stalker.com>
In the latest CGP version the SetWebUser has been renamed SETACCOUNTPREFS - not sure if CLI.pm followed. Anyway the old name should still work.

I think you should try with UpdateAccountPrefs. This way you don't have to rewrite everything, and even read the actual settings:

Set:
UpdateAccountPrefs("$userName\@wheatonma.edu", {"SkinName"=>"Lookout_3.6.9b"}) or die "Can't update accounts prefs for $userName";

Restore default:
UpdateAccountPrefs("$userName\@wheatonma.edu", {"SkinName"=>"default"}) or die "Can't update accounts prefs for $userName";

In Perl, use the "or" operator instead of the || when you do control-flow operations. The || operator has a precedence and could produce side-effect. Not in this particular case, but keeping this habit will avoid you problems in the future. Keep the || operator for logical operations.

Nicolas



On 2010-06-21 14:59, Brian Gibson wrote:
Okay, I think I have it... and it seems to work fine, can anyone see an issue with just deleting the SkinName option which is what I am doing? I think that is how it works anyway (if you hard code a skin it adds the SkinName option to the person's settings file). Here is the code if anyone needs it.

----------------------------------------------------------
  my $webSettings = $cli->GetWebUser("$userName\@wheatonma.edu") || die "Can't get Web settings for $userName:" . $cli->getErrMessage;

  ## If this person is using the Lookout skin we save all of their web settings and exclude
  ## the SkinName option

  if (@$webSettings{SkinName} eq "Lookout_3.6.9b") {

    ## Remove the "SkinName" key/value pair.

    delete @$webSettings{'SkinName'};

    $cli->SetWebUser("$userName\@wheatonma.edu", $webSettings ) || die "Can't set Web settings for $userName:" . $cli->getErrMessage;

  } ## If this person has the skin set....
---------------------------------------------------------------








On 6/21/2010 2:13 PM, Brian Gibson wrote:
I think I have an idea how to do what I asked, I think I need to re-write the user's web settings and leave out the SkinName key/value pair. Here is what I tried but I've run into some formatting issues.

------------------------------------------------------------------------

  ## Clear out the object that will hold the user's new web settings....
  $new_web_settings = "";

 ## Get the user's current web settings
  my $webSettings = $cli->GetWebUser("$userName\@wheatonma.edu") || die "Can't get Web settings for $userName:" . $cli->getErrMessage;

  ## If this person is using the Lookout skin we save all of their web settings to a new object and exclude
  ## the SkinName option

  if (@$webSettings{SkinName} eq "Lookout_3.6.9b") {

    ## Now we go through each of the settings

    foreach (keys %$webSettings) {

        if ($_ ne "SkinName") {

            ## We save this attribute to the new object that will hold the new web settings.

            @$new_web_settings{$_} = @$webSettings{$_};

        } ## End of "If this setting is not the SkinName setting...."

    } ## End of "for all of the web settings for this person..."

    ## Save the new web settings for this user (that has the SkinName excluded).
    $cli->SetWebUser("$userName\@wheatonma.edu", $new_web_settings ) || die "Can't set Web settings for $userName:" . $cli->getErrMessage;

  } ## If this person has the Lookout skin hard coded....

------------------------------------------------------------------------

I guess I do not know how to format the dictionary 'thingy' that holds the new data to write because I get this error message

Can't set Web settings for bgibson:failed to read dictionary: no leading '{' at F:\scripts\change_to_default_skin.pl line 94, <GEN0> line 355.

Any help would be greatly appreciated :-)













On 6/21/2010 11:58 AM, Brian Gibson wrote:
Hi everyone,

I can use the Perl CLI.pm to switch a user's skin to name a specific one but how do I do the same to set a user's skin back to the default (without hardcoding the name of the default)?

Here is what I use to set a named skin


----------------------------------------------------------------------------
my $webSettings = $cli->GetWebUser("$userName\@wheatonma.edu") || die "Can't get Web settings for $userName:" . $cli->getErrMessage;

@$webSettings{SkinName} = "Lookout_3.6.9b";

$cli->SetWebUser("$userName\@wheatonma.edu", $webSettings ) || die "Can't set Web settings for $userName:" . $cli->getErrMessage;

-----------------------------------------------------------------------------


I have tried setting the SkinName to "" but it ends up taking the "Basic" skin.

Any suggestions would be greatly appreciated :-)

Thanks - Brian




--

Nicolas Hatier, ing. <nicolas.hatier@niversoft.com>
Niversoft idées logicielles - http://www.niversoft.com

Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster