Help Desk Software & Beyond
May 23, 2012, 05:50:36 AM *
Welcome, Guest. Please login or register.
To post messages you need to register. We apologize for inconvenience, but this is to prevent spam.
Registration is instant (no email verification) and we do not ask for any personal information.

Login with username, password and session length
News: Welcome to Help Desk Software forum!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [REQ] how can I make a page whose content depends on the user logged in?  (Read 1952 times)
TroubleTicketUser4499
Jr. Member
**

Karma: 5
Posts: 59


View Profile
« on: June 27, 2008, 03:24:44 PM »

I want to add a control component, like a checkbox, to the ticket page, which is only displayed for specific users.  I could make the checkbox value as a cutom column in the ticket table.  That's fine.  I know displaying/hiding a component can be done in javascript, but i'd like to do it on the server-side. 

Say, if user A is logged in, he can see the checkbox; otherwise, it is not drawn to the page.  The trick here is this custom field is on a page that interacts with the message table.  First, I have to display the custom field, belonging to the ticket table, on a page meant for inserting data into the message table.  The question is what's the best way to  do this?  Maybe I create a button that calls the ticketed command...if I click on the hyperlink for the ID column on the help desk page, it brings up a popup window which allows the user to modify the ticket info, i.e. name, email, subject, etectera.  So, maybe I can borrow this code and somehow make use of it to change the value of the custom field (which is a checkbox in this example).  Or, am I thinking too hard about this?  That's why I ask:  Perhaps there is a simpler solution I haven't thought of...

Thank you very much.
« Last Edit: June 27, 2008, 03:25:56 PM by sparky672 » Logged
Sparky
Moderator
Hero Member
*****

Karma: 83
Posts: 2,228


stop pushing all those buttons


View Profile
« Reply #1 on: June 27, 2008, 03:35:14 PM »

If you want something to show up on the Ticket page (page for an individual Ticket?), you put a new macro in the ticket subroutine in the TTXTicket.pm module.

The contents of the new macro is your HTML for the checkbox.

Quote
$data->{MY_MACRO} = HTML code to make the proper checkbox;

And execute the macro depending upon logic that determines if this is the correct user.

Quote
if (boolean to check if user is correct) {
  $data->{MY_MACRO} = my html stuff;
}

Of course, you'll need to put this in your template wherever you want the checkbox...

Quote
(%MY_MACRO%)

Most everything is already in this subroutine, you just need to find it, copy it, and modify it to suit your needs.
« Last Edit: June 27, 2008, 07:28:06 PM by sparky672 » Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
Sparky
Moderator
Hero Member
*****

Karma: 83
Posts: 2,228


stop pushing all those buttons


View Profile
« Reply #2 on: June 27, 2008, 03:38:25 PM »

Getting the checkbox to change the proper data in the table is a whole other matter.

Maybe you should just put the checkbox in the ticketed popup.  That's what ticketed is there for.

TTXTickEd.pm
Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
TroubleTicketUser4499
Jr. Member
**

Karma: 5
Posts: 59


View Profile
« Reply #3 on: June 27, 2008, 04:22:39 PM »

Yea, I'd like to.  But this component's purpose fits more with the message.  Prolly, as a last resort, I'd add the custom macro to the update ticket popup. I think I'll try that idea of borrowing some of the code from the update ticket page and see what happens.

Edit: You know what, you're right, it's easier to do what you suggested.  1-2-3 and done with it, right?  Now the only thing is the custom field I created is a listbox, not a checkbox, because setup.cgi doesn' thave the option of creating checkboxes, only item, text, and list.  I suppose that's fine, then.  But is there a way I can choose a default value for the custom field if nothing is selected?  Like if a listbox has the option of 1, 2, and 3, I can have it default to 1.  Also, how can I prevent the custom field from showing up in the newticket page?  Like this:

if($query->param('cmd') eq 'newticket') {
//hide custom field c4
}
« Last Edit: June 27, 2008, 04:30:51 PM by TroubleTicketUser4499 » Logged
Sparky
Moderator
Hero Member
*****

Karma: 83
Posts: 2,228


stop pushing all those buttons


View Profile
« Reply #4 on: June 27, 2008, 06:23:42 PM »

Quote
Now the only thing is the custom field I created is a listbox, not a checkbox, because setup.cgi doesn' thave the option of creating checkboxes, only item, text, and list.

TTX doesn't care how it gets an input and neither does the <form>, so since you're programming this field's HTML from scratch, just do a checkbox like you want.

Quote
Also, how can I prevent the custom field from showing up in the newticket page?  Like this:

if($query->param('cmd') eq 'newticket') {
//hide custom field c4
}

No.  Just do this.  Read both posts...

http://forum.unitedwebcoders.com/index.php/topic,738.0.html
Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
TroubleTicketUser4499
Jr. Member
**

Karma: 5
Posts: 59


View Profile
« Reply #5 on: June 27, 2008, 09:28:36 PM »

Quote
Now the only thing is the custom field I created is a listbox, not a checkbox, because setup.cgi doesn' thave the option of creating checkboxes, only item, text, and list.

TTX doesn't care how it gets an input and neither does the <form>, so since you're programming this field's HTML from scratch, just do a checkbox like you want.

Quote
Also, how can I prevent the custom field from showing up in the newticket page?  Like this:

if($query->param('cmd') eq 'newticket') {
//hide custom field c4
}

No.  Just do this.  Read both posts...

http://forum.unitedwebcoders.com/index.php/topic,738.0.html

Right.  Thank you.  Before you posted this, I actually figured out an alternative way in the modules.  But this is a worthy method I will attempt to employ if the opportunity rises again (and it will).  The only thing I haven't been able to figure out is how to hide/display fields based on the user and password.  It works when you pass in the values to the querystring.  But when the user normally logs in, their saved as -- I think -- cookies.  Maybe session variables.  Either way, I'm not sure how to modify the ttxticked.pm module.  This is what I currently have modified:

TTXTicked.pm, around line 225

foreach my $id (sort keys %cflds) {
    if ($cflds{$id} eq 'Custom column' && $query->{login} eq 'name' && $query->{passwd} eq 'password') {
      next;
    }
...

, where 'Custom column' is the custom field name, 'name' is the userid, and 'password' is the password.  Right now, they are static.  The main issue is how do I retrieve the login and password that's stored in the header, so that I can use them in a comparison, to determine if the user has the right to see this field.  My goal is to do it on the server-side, as handling these issues on the client-side are likely more of a security risk.  Maybe there's a command in perl that could retrive this information; i'll have to look it up...
Logged
Sparky
Moderator
Hero Member
*****

Karma: 83
Posts: 2,228


stop pushing all those buttons


View Profile
« Reply #6 on: June 27, 2008, 11:11:29 PM »


TTXTicked.pm, around line 225

foreach my $id (sort keys %cflds) {
    if ($cflds{$id} eq 'Custom column' && $query->{login} eq 'name' && $query->{passwd} eq 'password') {
      next;
    }
...

, where 'Custom column' is the custom field name, 'name' is the userid, and 'password' is the password.  Right now, they are static.  The main issue is how do I retrieve the login and password that's stored in the header, so that I can use them in a comparison, to determine if the user has the right to see this field.  My goal is to do it on the server-side, as handling these issues on the client-side are likely more of a security risk.  Maybe there's a command in perl that could retrive this information; i'll have to look it up...


Some issues-

1.  $query->{login}... the stuff beginning with "$query" is the stuff coming in just when a form or URL is submitted.  Unless your Operator is submitting his login info as part of your code's execution, that will never work.

2.  Session ID numbers are optionally stored in cookies to keep the Operators logged in.  In the sid directory, there are Session ID files where the corresponding user's name and preferences are stored for that session.  No passwords.

3.  There's no name & password stored in any header.  The only place where passwords are stored is in the users.cgi file.  Once the TTX login routine is complete, there isn't a variable where you can retrieve the password (You'd have to access the users.cgi file again to do that) .... and there's really no point to it.    Besides, you only want to see if the correct user is already logged in... why on Earth would you need to check his password again when that was already performed once upon login?

4.  The "logged in as" message is displayed by the (%LOGGEDAS%) macro on the in the header.shtml file.

(%LOGGEDAS%) comes from ttx.cgi, where the variables containing the user's first & last names are used.

$data{LOGGEDAS} = TTXDictionary::translate('Logged as').' '.$u->{fname}.' '.$u->{lname};

But that's only the name as found in ttx.cgi.  It's a different variable name in TTXTickEd.pm ....

5.  There's a "$user" variable in the ticked subroutine already.  I suggest experimenting with that.
« Last Edit: June 27, 2008, 11:14:26 PM by sparky672 » Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
webcarvallo
Newbie
*

Karma: 1
Posts: 15


View Profile
« Reply #7 on: October 06, 2011, 05:06:04 PM »

Hi.
I'm working on a similar approach. 
My installation is rev. 2.24.431, using groups module and Mysql module over a Linux server.

What I need is to get different "newticket" template depending on who's logged in.
At my application, tickets can only be submitted by an registered user (i.e. an operator belonging to certain group).   
Therefore, when people enters URL  www.mysite.com/cgi-bin/ttx.cgi , application asks logon user/password, then sends user to a modified "newticket" that has a menu to manually select the corersponding newticket form temnplate I need to be filled for user.
But this is confusing to users as they can create mistaken tickets (using another newticket form).

My goal is to send user directly to the corresponding newticket template after he(she) logged in.

Sparky said that we can use "styles" function to get my needs.   I understand. 
I created 10 subfolders below templates folder (named "g1" to "g10") an its respective different newticket on each one, so now if type like this URL:  www.mysite.com/cgi-bin/ttx.cgi?style=g1    or ?style=g2 ... ?style=g10   I got displayed directly the correct newticket form.

BUT... I cannot get this automated yet.  I was trying using some code like this above in ttx.cgi   to get automatic direction to proper "page" using styles function, but it donīt works (Internal server error):

Original code in black;  my added code in BLUE:


#================================================================== loadtemplate

sub loadtemplate {
  my ($t, $style);
  if ($query->param('cmd') eq 'newticket' && $query->param('form') ne undef) {
    my @parts = split(/\/|\\/, $query->param('form'));
    $t = pop @parts;
    $t .= '.html';
  }
  if ($t eq undef) {
    $t = $cmddef->{$query->param('cmd')}->{template};
    $t = $query->param('cmd').".html" if $t eq undef;
  }
  my $fn = $cfg->get('basedir')."/templates";
  if ($query->param('style') ne undef) {
    my @parts = split(/\/|\\/, $query->param('style'));
    $style = pop @parts;
  }
my $operador = $cfg->get('_USER')->get('login');
 if ($operador eq 'arojas') {
        $style = 'g8';
}
 elsif ($operador eq 'avidal') {
        $style = 'g12';
}
 elsif ($operador eq 'avsapostventa') {
        $style = 'g7';
}
 elsif ($operador eq 'cvallejos') {
        $style = 'g9';
}
 elsif ($operador eq 'cvargas') {
        $style = 'g7';
}
 elsif ($operador eq 'hmeyer') {
        $style = 'g3';
}
 elsif ($operador eq 'jaroca') {
        $style = 'g9';
}
 elsif ($operador eq 'jrodriguez') {
        $style = 'g11';
}
 elsif ($operador eq 'kcarreņo') {
        $style = 'g2';
}
 elsif ($operador eq 'mdelgado') {
        $style = 'g5';
}
 elsif ($operador eq 'mzamora') {
        $style = 'g6';
}
 elsif ($operador eq 'soryan') {
        $style = 'g12';
  } else { }


  my $template;
  if ($t ne '#') {
    if ($style ne undef) {
      if ((! -f "$fn/$style/$t" || !open(TMPL, "$fn/$style/$t")) &&
          (! -f "$fn/$t" || !open(TMPL, "$fn/$t"))) {
        fatalerror("Missing template $t");
      }
    } elsif (! -f "$fn/$t" || !open(TMPL, "$fn/$t")) {
      fatalerror("Missing template $t");
    }
    my @buff = <TMPL>;
    close TMPL;
    $template = join('', @buff);
  } else {
    my @action_path = split(/::/, $cmddef->{$query->param('cmd')}->{action});
    pop @action_path;
    my $module = join("::", @action_path);
    if ($module eq undef) {
      fatalerror("No module defined for embedded template");
    }
    eval "use $module";
    fatalerror("Unable to load module $module<br><br>$@<br><br>SD:".scriptdir()) if $@;
    {
      no strict 'refs';
      my $tmplcmd = $module.'::xtemplate';
      eval '$template = ($tmplcmd)->($cfg, $query, \%data)';
      fatalerror("Failed to load embedded template, $@") if $@ ne undef;
    }
  }
  if (!($cmddef->{$query->param('cmd')}->{noheader} || $query->param('noheader'))) {
    if (($style ne undef && open(TMPL, "$fn/$style/header.shtml")) || open(TMPL, "$fn/header.shtml")) {
      my @hdr = <TMPL>;
      close TMPL;
      $template = join('', @hdr) . $template;
    }
    if (($style ne undef && open(TMPL, "$fn/$style/footer.shtml")) || open(TMPL, "$fn/footer.shtml")) {
      my @ftr = <TMPL>;
      close TMPL;
      $template .= join('', @ftr);
    }
}
  return $template;
}
#======================================================================= command


I will really aprecciate some help; my doubts are:

1) Is ttx.cgi  and -loadtemplate- subroutine the right place to modify to get my goal?

2) Are Iīm using the correct code to get userid?     my $operador = $cfg->get('_USER')->get('login');

3) Are there some code errors such colons, semi colons, parenthesis, apostrophes, etc  that might cause server error?


Expecting your help, nice people...

PD: Sorry my bad english, I'm spanish mothertongue.

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1 RC3 | SMF © 2001-2006, Lewis Media Valid XHTML 1.0! Valid CSS!
Page created in 0.037 seconds with 22 queries.