Fork me on GitHub

permissions and menu options??  Bottom

  • Hey all back once agian for some advise, so here's the deal I am writing a module that will track network changes and what I want to accomplish is being able to have permissions for a set of categories in a dropdown menu. This would be like how in PostCalendar I can have multiple categories and lock certain users into one category or give them access to many, and when they view the calendar the drop down menu only shows them the categories they have permissions to view. I have taken a look at the code for PostCalendar and to be honest it doesn't make a whole lot of sense to me so I was hoping maybe one of you could help explain how I could accomplish this.



    Thanks all
    -SUNADMN
  • For the drop-down, if you're looping through an array of options to populate it, you can use the security check (in an IF statement) so that if they don't have permission, then it moves on to the next iteration in the loop, without outputting the one they aren't allowed to see. Hope that helps.
  • Yeah that helps a lot do you know of a good example of that I might be able to look at for a vantage point on this???



    Thanks
    -SUNADMN
  • I'll take a look and see what I can turn up.
  • I assume you're using an array...can you give me some info on the array? Such as the $varName of the array...as well as the permission schema for the module...and I can probably write one in just a few mins...
  • I dont have anything written as of yet I am more working on the theory right this sec so I can decide where I need to go with design. The security would be setup like so:

    module::category categoryname:: add|read|none

    the idea is to have it when a user attempts to ADD an item to the system they have a drop down menu with the given categories they can add to does that make sense??


    Thanks
    -SUNADMN
  • Yes, that makes sense. I've run into a bit of a time-sink at the moment, but will post back later.
  • Sorry for the delay.

    I may have the permissions schema incorrect, but this should give you a start. I put it into a whole function to give you an idea of the context. There might be an easier/better way to do this, but this is how I approach it.

    Code

    function MyMod_make_menu()
    {
      $output = new pnHTML();

      // Security check
      // NO NEED TO GO ON IF NO OVERVIEW PERMISSION
      if (!pnSecAuthAction(0, 'MyMod::Category', "$catName::", ACCESS_OVERVIEW))
      {
        $output->Text(_MYMOD_NOAUTH);
        return $output->GetOutput();
      }

      // START A FORM
      $output->FormStart(pnModURL('MyMod', 'user', 'someFunc'));

      // BUILD ALL THE POSSIBLE OPTIONS
      $options[] = array('id' => '0',   'name' => _MYMOD_OPTION_01);
      $options[] = array('id' => '1',   'name' => _MYMOD_OPTION_02);
      $options[] = array('id' => '2',   'name' => _MYMOD_OPTION_03);

      // LOOP THROUGH ALL OPTIONS
      foreach($options as $option)
      {
        // CHECK IF USER ALLOWED TO ADD
        if (pnSecAuthAction(0, "MyMod::Category", "$catName::", ACCESS_ADD))
        {
          // RE-ASSIGN ALLOWED OPTIONS ONLY, IE. POPULATE THE MENU
          $showopt[] = $option;
        }
      }

      // OUTPUT THE DROP-DOWN
      $output->FormSelectMultiple('MyMenu',$showopt,0,1);
     
      // SUBMIT BUTTON
      $output->FormSubmit(_MYMOD_SUBMIT);

      // END FORM
      $output->FormEnd();

      // RETURN
      return $output->GetOutput();
    }
  • Thanks so much I will put this to use and see what I can figure out thanks again.


    -SUNADMN

This list is based on users active over the last 60 minutes.