[freeside-devel] Package Selections for pre14

Stephen Bechard steve at destek.net
Sun Jun 23 20:55:55 PDT 2002


> > On Sun, Jun 23, 2002 at 03:22:00PM -0400, Stephen Bechard wrote:
> > > I have modified the view/cust_main.cgi so that it reads in the
REMOTE_USER
> > > and then builds the list of the available packages that this user can
sell
> > > based on their agent_type and only single svc_acct packages. I also
added
> > > a sort to the packages so they are alphabetically by the pkg name. :)
> >
> > Agents do not correspond to otaker / REMOTE_USER.  Most users use these
> > fields for separate things.
>
> I just presummed that was the correlation, me bad.
>
> > If you want this functionality, it should require a configuration option
> > to turn it on, not be the default.
>
> If I can work in the configuration option and change the code to check
> before building the package list, is this something that could become
> part of the next revision or should I just maintain my own diffs?
>
> I was also thinking of taking this a step further and setting up some
> type of security around the packages that the agents could view, so
> the sales people wouldn't be able to change or view the root and system
> accounts that the server depends on. Would this interest you?
>
> > (Also, use `getotaker', not $cgi->remote_user)
>
> Note taken.

Okay, I have reconfigured the view/cust_main.cgi to use the above mentioned
recommendations, along with the configuration option of remoteuser_security.

Without the file remoteuser_security in the conf directory it should be the
same as before except the list is sorted alphabetically by pkg name.

With the file remoteuser_security in the conf directory the package list
will be restricted to only the packages from the REMOTE_USER agent_type and
sorted alphabetically by pkg name.

Please let me know if this one meets standards before I continue with
modifying the edit/cust_main.cgi, signup.cgi and the config/config-view.cgi
;)

Thanks,
Steve

--- /tarballs/freeside-1.4.0pre14/httemplate/view/cust_main.cgi     Mon Jun
10 15:44:45 2002
+++ /aspdocs/view/cust_main.cgi-without-EFT   Sun Jun 23 23:40:48 2002
@@ -255,18 +255,36 @@
   qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
   '<SELECT NAME="pkgpart"><OPTION> ';

-foreach my $type_pkgs ( qsearch('type_pkgs',{'typenum'=>
$agent->typenum }) ) {
-  my $pkgpart = $type_pkgs->pkgpart;
-#  my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
-#    or do { warn "unknown type_pkgs.pkgpart $pkgpart"; next; };
-  my $part_pkg =
-    qsearchs('part_pkg', { 'pkgpart' => $pkgpart, 'disabled' => '' } )
-    or next;
-  print qq!<OPTION VALUE="$pkgpart">!. $part_pkg->pkg. ' - '.
-        $part_pkg->comment;
-}
+  if ( $conf->exists('remoteuser_security') ) {
+    my $remote_user = FS::UID->getotaker;
+    my $agents_hash = qsearchs( 'agent', { 'agent' => $remote_user } );
+    my $pkgpart;
+    my %typenum;
+    foreach my $agent ( $agents_hash ) {
+      next if $typenum{$agent->typenum}++;
+      foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; }
#5.004_04 workaround
+    }
+    @part_pkg = grep { $pkgpart->{ $_->pkgpart } }
+      qsearch( 'part_pkg', { 'disabled' => '' } );
+  } else {
+    my $agents_hash = qsearchs( 'agent', { 'agent' => $agent->agent } );
+    my $pkgpart;
+    my %typenum;
+    foreach my $agent ( $agents_hash ) {
+      next if $typenum{$agent->typenum}++;
+      foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; }
#5.004_04 workaround
+    }
+    @part_pkg = grep { $pkgpart->{ $_->pkgpart } }
+      qsearch( 'part_pkg', { 'disabled' => '' } );
+  }

+# Resort the @part_pkg alphabetically by pkg name.
+foreach my $part_pkg ( sort { $a->pkg cmp $b->pkg } @part_pkg ) {
+   print qq!<OPTION VALUE="!, $part_pkg->pkgpart, '"';
+   print ">", $part_pkg->pkg, " - ", $part_pkg->comment. "\n";
+}
 print '</SELECT><INPUT TYPE="submit" VALUE="Order Package"><BR>';
+print "</FORM>\n";

 print <<END;
 <SCRIPT>






More information about the freeside-devel mailing list