home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / progs / ite / ite10d1.exe / DATA.Z / SMUADMIN.JFM < prev    next >
Encoding:
Text File  |  1996-09-07  |  19.1 KB  |  647 lines

  1. /****************************************************************************\
  2. *                                                                            *
  3. * SmUAdmin.jfm  --  Security User Administration Form                        *
  4. *                                                                            *
  5. * This form is part of the security administration prebuilt business         *
  6. * solution. This is the user adminstration form. It allows you to define     *
  7. * new groups and update existing users. This form is called from the         *
  8. * SmAdmin form.                                                              *
  9. *                                                                            *
  10. * Dependencies:  secur21.gif                                                 *
  11. *                                                                            *
  12. * Updated 9/3/96 by IntraBuilder Samples Group                               *
  13. * $Revision:   1.5  $                                                        *
  14. *                                                                            *
  15. * Copyright (c) 1996, Borland International, Inc. All rights reserved.       *
  16. *                                                                            *
  17. \****************************************************************************/
  18. #include "security.h"
  19. // {End Header} Do not remove this comment//
  20. // Generated on 09/03/96
  21. //
  22. var f = new smuadminForm();
  23. f.open();
  24. class smuadminForm extends SecurityForm from "SMADMIN.JCF" {
  25.    _sys.scripts.load(_sys.env.home() + "APPS\\SHARED\\CONTROLS.CC")
  26.    with (this) {
  27.       height = 24.9412;
  28.       left = 7.5;
  29.       top = 0.4118;
  30.       width = 81.8333;
  31.       title = "User Administration";
  32.       onServerLoad = class::Form_onServerLoad;
  33.    }
  34.  
  35.  
  36.    with (this.rule1 = new Rule(this)){
  37.       left = 2;
  38.       top = 7;
  39.       size = 2;
  40.       right = 76;
  41.       pageno = 0;
  42.    }
  43.  
  44.  
  45.    with (this.rule2 = new Rule(this)){
  46.       left = 2;
  47.       top = 26;
  48.       size = 2;
  49.       right = 76;
  50.       pageno = 0;
  51.    }
  52.  
  53.  
  54.    with (this.actionHTML = new HTML(this)){
  55.       height = 2;
  56.       left = 22;
  57.       top = 3;
  58.       width = 54;
  59.       color = "400040";
  60.       text = "Update Existing User";
  61.    }
  62.  
  63.  
  64.    with (this.saveButton = new Button(this)){
  65.       left = 52;
  66.       top = 8;
  67.       width = 24;
  68.       text = "Save";
  69.       onServerClick = class::saveButton_onServerClick;
  70.    }
  71.  
  72.  
  73.    with (this.backButton = new Button(this)){
  74.       left = 52;
  75.       top = 9;
  76.       width = 24;
  77.       text = "Back";
  78.       onServerClick = class::backButton_onServerClick;
  79.    }
  80.  
  81.  
  82.    with (this.userHTML = new HTML(this)){
  83.       height = 1;
  84.       left = 2;
  85.       top = 10;
  86.       width = 24;
  87.       color = "400040";
  88.       fontBold = false;
  89.       text = "User Name";
  90.    }
  91.  
  92.  
  93.    with (this.usernameHTML = new HTML(this)){
  94.       height = 1;
  95.       left = 28;
  96.       top = 10;
  97.       width = 22;
  98.       color = "black";
  99.       fontBold = false;
  100.       text = "username";
  101.    }
  102.  
  103.  
  104.    with (this.usernameText = new Text(this)){
  105.       visible = false;
  106.       left = 28;
  107.       top = 10;
  108.       width = 22;
  109.       value = "username";
  110.    }
  111.  
  112.  
  113.    with (this.createHTML = new HTML(this)){
  114.       height = 1;
  115.       left = 2;
  116.       top = 8;
  117.       width = 24;
  118.       color = "400040";
  119.       fontBold = false;
  120.       text = "Created";
  121.    }
  122.  
  123.  
  124.    with (this.createdHTML = new HTML(this)){
  125.       height = 1;
  126.       left = 28;
  127.       top = 8;
  128.       width = 22;
  129.       color = "black";
  130.       fontBold = false;
  131.       text = "  /  /       :  :  ";
  132.    }
  133.  
  134.  
  135.    with (this.lastloginHTML = new HTML(this)){
  136.       height = 1;
  137.       left = 2;
  138.       top = 9;
  139.       width = 24;
  140.       color = "400040";
  141.       fontBold = false;
  142.       text = "Last Login";
  143.    }
  144.  
  145.  
  146.    with (this.loginHTML = new HTML(this)){
  147.       height = 1;
  148.       left = 28;
  149.       top = 9;
  150.       width = 22;
  151.       color = "black";
  152.       fontBold = false;
  153.       text = "  /  /        :  :  ";
  154.    }
  155.  
  156.  
  157.    with (this.descriptionHTML = new HTML(this)){
  158.       height = 1;
  159.       left = 2;
  160.       top = 11;
  161.       width = 24;
  162.       color = "400040";
  163.       fontBold = false;
  164.       text = "Description";
  165.    }
  166.  
  167.  
  168.    with (this.descriptionText = new Text(this)){
  169.       left = 28;
  170.       top = 11;
  171.       width = 48;
  172.       value = "description";
  173.    }
  174.  
  175.  
  176.    with (this.disableCheck = new CheckBox(this)){
  177.       height = 1;
  178.       left = 2;
  179.       top = 12;
  180.       width = 24;
  181.       text = "Account Disabled";
  182.       fontBold = false;
  183.       checked = false;
  184.    }
  185.  
  186.  
  187.    with (this.passwordHTML = new HTML(this)){
  188.       height = 1;
  189.       left = 28;
  190.       top = 12;
  191.       width = 22;
  192.       color = "400040";
  193.       fontBold = false;
  194.       text = "Password";
  195.    }
  196.  
  197.  
  198.    with (this.passwordText = new Password(this)){
  199.       left = 52;
  200.       top = 12;
  201.       width = 24;
  202.       value = "";
  203.    }
  204.  
  205.  
  206.    with (this.lockoutCheck = new CheckBox(this)){
  207.       height = 1;
  208.       left = 2;
  209.       top = 13;
  210.       width = 24;
  211.       text = "Account Locked Out";
  212.       fontBold = false;
  213.       checked = false;
  214.    }
  215.  
  216.  
  217.    with (this.confirmHTML = new HTML(this)){
  218.       height = 1;
  219.       left = 28;
  220.       top = 13;
  221.       width = 22;
  222.       color = "400040";
  223.       fontBold = false;
  224.       text = "Confirm Password";
  225.    }
  226.  
  227.  
  228.    with (this.confirmText = new Password(this)){
  229.       left = 52;
  230.       top = 13;
  231.       width = 24;
  232.       value = "";
  233.    }
  234.  
  235.  
  236.    with (this.inGroupHTML = new HTML(this)){
  237.       height = 1;
  238.       left = 2;
  239.       top = 15;
  240.       width = 24;
  241.       color = "400040";
  242.       fontBold = false;
  243.       text = "Member of Group";
  244.    }
  245.  
  246.  
  247.    with (this.outGroupHTML = new HTML(this)){
  248.       height = 1;
  249.       left = 52;
  250.       top = 15;
  251.       width = 24;
  252.       color = "400040";
  253.       fontBold = false;
  254.       text = "Not Member of Group";
  255.    }
  256.  
  257.  
  258.    with (this.inGroupSelect = new ListBox(this)){
  259.       height = 4;
  260.       left = 2;
  261.       top = 16;
  262.       width = 24;
  263.    }
  264.  
  265.  
  266.    with (this.addGroupButton = new Button(this)){
  267.       left = 28;
  268.       top = 17;
  269.       width = 22;
  270.       text = "Add Group";
  271.       onServerClick = class::addGroupButton_onServerClick;
  272.    }
  273.  
  274.  
  275.    with (this.removeGroupButton = new Button(this)){
  276.       left = 28;
  277.       top = 18;
  278.       width = 22;
  279.       text = "Remove Group";
  280.       onServerClick = class::removeGroupButton_onServerClick;
  281.    }
  282.  
  283.  
  284.    with (this.outGroupSelect = new ListBox(this)){
  285.       height = 4;
  286.       left = 52;
  287.       top = 16;
  288.       width = 24;
  289.    }
  290.  
  291.  
  292.    with (this.inResourceHTML = new HTML(this)){
  293.       height = 1;
  294.       left = 2;
  295.       top = 20;
  296.       width = 24;
  297.       color = "400040";
  298.       fontBold = false;
  299.       text = "May Access Resource";
  300.    }
  301.  
  302.  
  303.    with (this.outResourceHTML = new HTML(this)){
  304.       height = 1;
  305.       left = 52;
  306.       top = 20;
  307.       width = 24;
  308.       color = "400040";
  309.       fontBold = false;
  310.       text = "May Not Access Resource";
  311.    }
  312.  
  313.  
  314.    with (this.inResourceSelect = new ListBox(this)){
  315.       height = 4;
  316.       left = 2;
  317.       top = 21;
  318.       width = 24;
  319.    }
  320.  
  321.  
  322.    with (this.addResourceButton = new Button(this)){
  323.       left = 28;
  324.       top = 22;
  325.       width = 22;
  326.       text = "Add Resource";
  327.       onServerClick = class::addResourceButton_onServerClick;
  328.    }
  329.  
  330.  
  331.    with (this.removeResourceButton = new Button(this)){
  332.       left = 28;
  333.       top = 23;
  334.       width = 22;
  335.       text = "Remove Resource";
  336.       onServerClick = class::removeResourceButton_onServerCli;
  337.    }
  338.  
  339.  
  340.    with (this.outResourceSelect = new ListBox(this)){
  341.       height = 4;
  342.       left = 52;
  343.       top = 21;
  344.       width = 24;
  345.    }
  346.  
  347.  
  348.    with (this.errorHTML = new HTML(this)){
  349.       height = 4;
  350.       left = 2;
  351.       top = 8;
  352.       width = 74;
  353.       color = "400040";
  354.       text = "Error loading user administration form. Notify system administrator.";
  355.       pageno = 2;
  356.    }
  357.  
  358.  
  359.    with (this.backButton2 = new Button(this)){
  360.       left = 2;
  361.       top = 14;
  362.       width = 20;
  363.       text = "Back";
  364.       pageno = 2;
  365.       onServerClick = {;this.form.pageno = 1};
  366.    }
  367.  
  368.  
  369.    with (this.GeneratedHTML1 = new GeneratedHTML(this)){
  370.       height = 1;
  371.       left = 2;
  372.       top = 27;
  373.       width = 74;
  374.       pageno = 0;
  375.    }
  376.  
  377.  
  378.    function Form_onServerLoad()
  379.    {
  380.       try {
  381.          // 
  382.          // make sure that all the custom properties are set
  383.          //
  384.          var x = this.copyEntity?1:0;
  385.          var x = this.entity.name;
  386.          var x = this.security._admin;
  387.          var x = this.callingForm.title;
  388.          //
  389.          // set the action text
  390.          //
  391.          this.createNew = true;
  392.          if (this.entity.name == null)
  393.             this.actionHTML.text = "Create New User";
  394.          else if (this.copyEntity)
  395.             this.actionHTML.text = ("Copy " + this.entity.name + " To New User");
  396.          else {
  397.             this.createNew = false;
  398.             this.actionHTML.text = "Update Existing User";
  399.          }
  400.          //
  401.          // set the control values on this form
  402.          //
  403.          if ((this.entity.name == null) || (this.copyEntity)) {
  404.             this.usernameText.value = new StringEx().replicate(" ",20);
  405.             this.usernameText.visible = true;
  406.             this.usernameHTML.visible = false;
  407.          }
  408.          else {
  409.             this.usernameHTML.text = this.entity.name;
  410.             this.usernameHTML.visible = true;
  411.             this.usernameText.visible = false;
  412.          }
  413.          this.createdHTML.text = (this.entity.created == null) ?
  414.                                   "(new user)" : ("" + this.entity.created);
  415.          this.loginHTML.text = (this.entity.login == null) ?
  416.                                 "(no prior login)" : ("" + this.entity.login);
  417.          this.descriptionText.value = (this.entity.description == null) ?
  418.                                        new StringEx().replicate(" ",80) : 
  419.                                        this.entity.description;
  420.          this.disableCheck.checked = this.entity.disabled;
  421.          this.lockoutCheck.checked = this.entity.lockout;
  422.          this.passwordText.value = "";
  423.          this.confirmText.value  = "";
  424.          // create arrays for the select controls
  425.          this.inGroup     = new Array();
  426.          this.outGroup    = new Array();
  427.          this.inResource  = new Array();
  428.          this.outResource = new Array();
  429.          // save original groups/resources for use in save
  430.          this.inGroupStart    = new Array();
  431.          this.inResourceStart = new Array();
  432.          var entity = "";
  433.          // build group lists
  434.          if (this.entity.name == null)
  435.             var inGroup = new AssocArray();
  436.          else
  437.             var inGroup = this.security.getAllGroups(this.entity.name, SM_ENTITY_USER);
  438.          var outGroup = this.security.getAllGroups();
  439.          // add all in groups to list
  440.          for (var i = 0; i<inGroup.count(); i++) {
  441.             entity = (i==0) ? inGroup.firstKey : inGroup.nextKey(entity);
  442.             this.inGroup.add(entity);
  443.             this.inGroupStart.add(entity);
  444.          }
  445.          this.inGroup.sort();
  446.          this.inGroupSelect.options = 'array this.inGroup';
  447.          // add groups to out list if they are not in in list
  448.          for (i = 0; i<outGroup.count(); i++) {
  449.             entity = (i==0) ? outGroup.firstKey : outGroup.nextKey(entity);
  450.             if (!inGroup.isKey(entity))
  451.                this.outGroup.add(entity);
  452.          }
  453.          this.outGroup.sort();
  454.          this.outGroupSelect.options = 'array this.outGroup';
  455.          // build resource lists
  456.          if (this.createNew)
  457.             var inResource = new AssocArray();
  458.          else
  459.             var inResource = this.security.getAllResources(this.entity.name, SM_ENTITY_USER);
  460.          var outResource = this.security.getAllResources();
  461.          // add all in resources to list
  462.          for (var i = 0; i<inResource.count(); i++) {
  463.             entity = (i==0) ? inResource.firstKey : inResource.nextKey(entity);
  464.             this.inResource.add(entity);
  465.             this.inResourceStart.add(entity);
  466.          }
  467.          this.inResource.sort();
  468.          this.inResourceSelect.options = 'array this.inResource';
  469.          // add resources to out list if they are not in in list
  470.          for (i = 0; i<outResource.count(); i++) {
  471.             entity = (i==0) ? outResource.firstKey : outResource.nextKey(entity);
  472.             if (!inResource.isKey(entity))
  473.                this.outResource.add(entity);
  474.          }
  475.          this.outResource.sort();
  476.          this.outResourceSelect.options = 'array this.outResource';
  477.       }
  478.       catch (Exception e) {
  479.          form.errorHTML.text = "Error loading user: " + e.message + " (" + e.code + ")";
  480.          this.pageno = 2;
  481.       }
  482.    }
  483.  
  484.    function saveButton_onServerClick()
  485.    {
  486.       var form = this.form;
  487.       try {
  488.          // have an exception ready
  489.          var error = new Exception();
  490.          error.message = "";
  491.          error.code = 0;
  492.          //
  493.          //  set the properties of the entity object
  494.          //
  495.          //  user name
  496.          if (form.createNew) {
  497.             var name = new StringEx(form.usernameText.value);
  498.             name.string = name.leftTrim();
  499.             name.string = name.rightTrim();
  500.             if (name.length == 0) {
  501.                error.message = "User name may not be blank";
  502.                throw error;
  503.             }
  504.             else
  505.                form.entity.name = name;
  506.          }
  507.          // password
  508.          if (form.passwordText.value != form.confirmText.value) {
  509.             error.message = "Password and confirmation do not match";
  510.             throw error;
  511.          }
  512.          if (form.passwordText.value == "")
  513.             form.entity.password = null;
  514.          else
  515.             form.entity.password = form.passwordText.value;
  516.          // description
  517.          form.entity.description = form.descriptionText.value;
  518.          // disabled and lockout
  519.          form.entity.disabled = form.disableCheck.checked;
  520.          form.entity.lockout  = form.lockoutCheck.checked;
  521.          //
  522.          //  call create/update with entity object
  523.          //
  524.          if (form.createNew)
  525.             form.security.createUser(form.entity);
  526.          else
  527.             form.security.updateUser(form.entity);
  528.          //
  529.          //  assign group membership
  530.          //
  531.          for (var i = 0; i<form.inGroup.length; i++) {
  532.             if ((form.createNew) || (form.inGroupStart.scan(form.inGroup[i]) < 0))
  533.                form.security.assignGroupUser(form.inGroup[i],form.entity.name);
  534.          }
  535.          //
  536.          //  assign resource privileges
  537.          //
  538.          for (var i = 0; i<form.inResource.length; i++) {
  539.             if ((form.createNew) || (form.inResourceStart.scan(form.inResource[i]) < 0))
  540.                form.security.assignResourceUser(form.inResource[i],form.entity.name);
  541.          }
  542.          //
  543.          //  remove group memberships for existing users only
  544.          //
  545.          if (!form.createNew) {
  546.             for (var i = 0; i<form.inGroupStart.length; i++) {
  547.                if (form.inGroup.scan(form.inGroupStart[i]) < 0)
  548.                   form.security.unassignGroupUser(form.inGroupStart[i],form.entity.name);
  549.             }
  550.          }
  551.          //
  552.          //  remove resource privileges for existing users only
  553.          //
  554.          if (!form.createNew) {
  555.             for (var i = 0; i<form.inResourceStart.length; i++) {
  556.                if (form.inResource.scan(form.inResourceStart[i]) < 0)
  557.                   form.security.unassignResourceUser(form.inResourceStart[i],form.entity.name);
  558.             }
  559.          }
  560.          //
  561.          //  Successful change, no longer in createNew mode
  562.          //
  563.          if (form.createNew) {
  564.             form.createNew = false;
  565.             form.actionHTML.text = "Update Existing User";
  566.             form.usernameHTML.text = form.entity.name;
  567.             form.usernameHTML.visible = true;
  568.             form.usernameText.visible = false;
  569.          }
  570.          //
  571.          // current inXxxxx arrays become the inXxxxxStart arrays
  572.          //
  573.          form.inGroupStart    = new Array();
  574.          form.inResourceStart = new Array();
  575.          for (var i = 0; i<form.inGroup.length; i++)
  576.             form.inGroupStart.add(form.inGroup[i]);
  577.          for (var i = 0; i<form.inResource.length; i++)
  578.             form.inResourceStart.add(form.inResource[i]);
  579.       }
  580.       catch (Exception e) {
  581.          form.errorHTML.text = "Error saving user: " + e.message + " (" + e.code + ")";
  582.          form.pageno = 2;
  583.       }
  584.    }
  585.  
  586.    function backButton_onServerClick()
  587.    {
  588.       try {
  589.          this.form.callingForm.open();
  590.          this.form.close();
  591.       }
  592.       catch (Exception e) {
  593.          this.form.errorHTML.text = "Unable to return to calling form.";
  594.          this.form.pageno = 2;
  595.       }
  596.    }
  597.  
  598.    function addGroupButton_onServerClick()
  599.    {
  600.       if ((this.form.outGroupSelect.value.length > 0) && (this.form.outGroup.scan(this.form.outGroupSelect.value) >= 0)) {
  601.          this.form.inGroup.add(this.form.outGroupSelect.value);
  602.          this.form.inGroup.sort();
  603.          this.form.inGroupSelect.options = "array this.form.inGroup";
  604.          this.form.outGroup.delete(this.form.outGroup.scan(this.form.outGroupSelect.value));
  605.          this.form.outGroup.length -= 1;
  606.          this.form.outGroupSelect.options = "array this.form.outGroup";
  607.       }
  608.    }
  609.  
  610.    function removeGroupButton_onServerClick()
  611.    {
  612.       if ((this.form.inGroupSelect.value.length > 0) && (this.form.inGroup.scan(this.form.inGroupSelect.value) >= 0)) {
  613.          this.form.outGroup.add(this.form.inGroupSelect.value);
  614.          this.form.outGroup.sort();
  615.          this.form.outGroupSelect.options = "array this.form.outGroup";
  616.          this.form.inGroup.delete(this.form.inGroup.scan(this.form.inGroupSelect.value));
  617.          this.form.inGroup.length -= 1;
  618.          this.form.inGroupSelect.options  = "array this.form.inGroup";
  619.       }
  620.    }
  621.  
  622.    function addResourceButton_onServerClick()
  623.    {
  624.       if ((this.form.outResourceSelect.value.length > 0) && (this.form.outResource.scan(this.form.outResourceSelect.value) >= 0)) {
  625.          this.form.inResource.add(this.form.outResourceSelect.value);
  626.          this.form.inResource.sort();
  627.          this.form.inResourceSelect.options = "array this.form.inResource";
  628.          this.form.outResource.delete(this.form.outResource.scan(this.form.outResourceSelect.value));
  629.          this.form.outResource.length -= 1;
  630.          this.form.outResourceSelect.options = "array this.form.outResource";
  631.       }
  632.    }
  633.  
  634.    function removeResourceButton_onServerClick()
  635.    {
  636.       if ((this.form.inResourceSelect.value.length > 0) && (this.form.inResource.scan(this.form.inResourceSelect.value) >= 0)) {
  637.          this.form.outResource.add(this.form.inResourceSelect.value);
  638.          this.form.outResource.sort();
  639.          this.form.outResourceSelect.options = "array this.form.outResource";
  640.          this.form.inResource.delete(this.form.inResource.scan(this.form.inResourceSelect.value));
  641.          this.form.inResource.length -= 1;
  642.          this.form.inResourceSelect.options  = "array this.form.inResource";
  643.       }
  644.    }
  645.  
  646. }
  647.