ARSperl

 view release on metacpan or  search on metacpan

example/WhoUsesIt.pl  view on Meta::CPAN

#

use ARS;
require 'getopts.pl';  # a standard perl module

$pname = $0;
$pname =~ s/.*\///g;

Getopts('s:a:f:m:e:p:M:Dhv');

$debug = $opt_D;
($server, $username, $password) = @ARGV;

$SCHEMA = defined($opt_s)?$opt_s:".*";

if($debug) {
    print STDERR "a: ".(defined($opt_a)?"$opt_a":"undef")."\n";
    print STDERR "f: ".(defined($opt_f)?"$opt_f":"undef")."\n";
    print STDERR "m: ".(defined($opt_m)?"$opt_m":"undef")."\n";
    print STDERR "e: ".(defined($opt_e)?"$opt_e":"undef")."\n";
    print STDERR "p: ".(defined($opt_p)?"$opt_p":"undef")."\n";
    print STDERR "s: ".(defined($opt_p)?"$opt_s":"undef")."\n";
    print STDERR "M: ".(defined($opt_M)?"$opt_M":"undef")."\n";
    print STDERR "d: ".(defined($opt_d)?"defined":"undef")."\n";
    print STDERR "v: ".(defined($opt_v)?"defined":"undef")."\n";
    print STDERR "h: ".(defined($opt_h)?"defined":"undef")."\n";
}

if((!defined($opt_a) &&
    !defined($opt_f) &&
    !defined($opt_m) &&
    !defined($opt_p) &&
    !defined($opt_M) &&
    !defined($opt_e)) ||
   defined($opt_h)) {
    Usage();
    exit 0;
}

if($username eq "") {
    print "Username: ";
    chomp($username = <STDIN>);
    if($username eq "") {
	print "Goodbye.\n";
	exit 0;
    }
}

if($password eq "") {
    print "Password: ";
    system 'stty', '-echo';
    chomp($password = <STDIN>);
    system 'stty', 'echo';
    print "\n";
}

($ctrl = ars_Login($server, $username, $password)) || 
    die "couldn't allocate control structure";

(@schemas = ars_GetListSchema($ctrl)) ||
    die "can't read schema list: $ars_errstr";

if($opt_M) {
    # fine any menu that uses this file as it's
    # source of menu items.

    print "Menus that use the file \"$opt_M\"... (this may take a minute or so to do)\n";

    @menus = ars_GetListCharMenu($ctrl, 0);
    if($#menus != -1) {
	foreach $menu (@menus) {
	    print "Searching: $menu\n" if $debug;
	    ($menuDef = ars_GetCharMenu($ctrl, $menu)) ||
		die "ars_GetCharMenu: $ars_errstr";
	    #next unless ($menu eq "PT-Assignees");
	    #use Data::Dumper; print Dumper($menuDef); exit 0;
	    # 3 is legacy. 
	    if( ($menuDef->{menuType} == 3) || ($menuDef->{menuType} =~ /format_quotes/i) ) {
		print "\tIs type File (points to ".qq{"$menuDef->{menuFile}{filename}"}.")\n" if $debug;
		if ($menuDef->{menuFile}{filename} =~ /$opt_M/) {
		    $users{$menu} = $1;
		}
	    }
	}
	foreach (sort keys %users) {
	    print "\t$_\n";
	}
    } else {
	print "No menu's available!\n$ars_errstr\n";
    }

} elsif($opt_a) {
    # find any schema that uses this active link.

    print "Searching for Active Link \"$opt_a\" in Schema \"$SCHEMA\"...\n";

    foreach $schema (@schemas) {
	if($schema =~ /$SCHEMA/) {
	    print "Searching schema $schema..\n" if $debug;
	    @alinks = ars_GetListActiveLink($ctrl, $schema);
	    foreach $link (@alinks) {
		if($link =~ /$opt_a/) {
		    $users{$schema} .= "$link,";
		}
	    }
	}
    }

    foreach $schema (sort keys %users) {
	print "\t$schema\n";
	foreach $link (split(/,/, substr($users{$schema}, 0, length($users{$schema})-1))) {
	    print "\t\t$link\n";
	}
    }

} elsif($opt_f) {
    # find any schema that uses this filter.

    print "Searching for Filter \"$opt_f\" in Schema \"$SCHEMA\" ...\n";

    foreach $schema (@schemas) {
	if($schema =~ /$SCHEMA/) {
	    @filters = ars_GetListFilter($ctrl, $schema);
	    foreach $filter (@filters) {
		if($filter =~ /^$opt_f$/) {
		    $users{$schema} .= "$filter,";
		}
	    }
	}
    }

    foreach $schema (sort keys %users) {
	print "\t$schema\n";
	foreach $filter (split(/,/, substr($users{$schema}, 0, length($users{$schema})-1))) {
	    print "\t\t$filter\n";
	}
    }

} elsif($opt_m) {
    # find any schema that uses this menu.
    # this particular routine will take longer, because we
    # need to open each schema, and then retrieve all field
    # definitions and finally flip thru each field and see
    # what menus (if any) are attached. 

    print "Searching for Menu \"$opt_m\" in schema \"$opt_s\"...\n";
    print "(this may take some time)\n";

    foreach $schema (@schemas) {



( run in 0.820 second using v1.01-cache-2.11-cpan-39bf76dae61 )