Você saberia me dizer como resolver este erro?
Obrigado
- Fórum WMO
- → Viewing Profile: Posts: WhiteBear
Community Stats
- Group Usuários
- Active Posts 8
- Profile Views 2547
- Member Title Novato no fórum
- Age Age Unknown
- Birthday Birthday Unknown
-
Sexo
Não informado
1
Neutral
User Tools
Friends
WhiteBear hasn't added any friends yet.
Latest Visitors
-
Guest
04/11/2007, 01:10
Posts I've Made
In Topic: Alguem Aqui Já Configurou O Perl Desk?
26/07/2004, 18:40
In Topic: Alguem Aqui Já Configurou O Perl Desk?
24/07/2004, 18:15
Módulo instalado, o erro mudou mande um e-mail para testando@aidi.com.br.
Abraços,
WhiteBear
Abraços,
WhiteBear
In Topic: Alguem Aqui Já Configurou O Perl Desk?
24/07/2004, 06:07
Amigo Stone Rock,
Me desculpe a minha ausência, mas estava com trabalho demaisalguns problemas e não tinha como responder e postar novas mensagens. me desculpe.
Bem o: CGI::Application eu intalei com o comando abaixo
perl -MCPAN -e 'install CGI::Application'
mas o File::Spec não consegui deu erro
root@server [/]# perl -MCPAN -e 'install File::Spec'
Can't locate object method "install" via package "File::Spec" at -e line 1.
Qual outro procedimento para instalar o File::Spec.
Obrigado,
WhiteBear
Me desculpe a minha ausência, mas estava com trabalho demaisalguns problemas e não tinha como responder e postar novas mensagens. me desculpe.
Bem o: CGI::Application eu intalei com o comando abaixo
perl -MCPAN -e 'install CGI::Application'
mas o File::Spec não consegui deu erro
root@server [/]# perl -MCPAN -e 'install File::Spec'
Can't locate object method "install" via package "File::Spec" at -e line 1.
Qual outro procedimento para instalar o File::Spec.
Obrigado,
WhiteBear
In Topic: Alguem Aqui Já Configurou O Perl Desk?
14/07/2004, 18:13
A linha 593 começa com:
$sender->MailMsg({
to => $contact{To},
subject => $contact{'Subject'},
msg => $contact{'Body'}});
$sender->Close;
$sender->MailMsg({
to => $contact{To},
subject => $contact{'Subject'},
msg => $contact{'Body'}});
$sender->Close;
In Topic: Alguem Aqui Já Configurou O Perl Desk?
14/07/2004, 18:12
O arquivo APP.pm tem o conteudo abaixo:
package PerlDesk::App;
use strict;
use vars qw(@ISA $VERSION %LANG $dbhost $dbname $dbuser $dbpass $errstr $db_backup_dir $perlDesk_version $enablemail $install %file_types);
use Carp;
use CGI::Application;eval{
require PerlDesk::App::License;};if ( my $error = $@ ) {die 'You have no license for using PerlDesk!';}
use File::Spec;
BEGIN {
$ENV{PDESK_INSTDIR} ||= File::Spec->curdir();
my $path = File::Spec->catfile($ENV{PDESK_INSTDIR}, 'include', 'conf.cgi');
require $path
}
@ISA = ('CGI::Application');
($VERSION) = '2.0' =~ m/Revision:\s*(\S+)/;
sub log {
my $self = shift;
my ($call_id, $user, $action) = @_;
unless ( $call_id && $user && $action ) {
die "PerlDesk::App->log(): usage error"
}
my ($hdtime, $timenow) = $self->get_time();
require PerlDesk::Log;
my $l = new PerlDesk::Log();
$l->cid( $call_id );
$l->user( $user );
$l->date( $hdtime);
$l->action( $action );
return $l->save();
}
sub accepted_file_types{
return \%file_types;
}
sub get_version{
return $perlDesk_version;
}
sub get_db_version{
my $self = shift;
my $settings_db = 0;
my $statement = 'SHOW TABLES';
my $sth = $self->dbh()->prepare($statement) or die print "Couldn't prepare statement: $DBI::errstr; stopped";
$sth->execute() or die print "Couldn't execute statement: $DBI::errstr; stopped";
while(my ($temp) = $sth->fetchrow_array()){
chomp $temp;
if (($temp eq 'perlDesk_settings')or($temp eq 'perldesk_settings')){
$settings_db = 1;
last;
}
}
if($settings_db){
my $statement = 'SELECT * FROM perlDesk_settings';
my $sth = $self->dbh()->prepare($statement) or die print "Couldn't prepare statement: $DBI::errstr; stopped";
$sth->execute() or die print "Couldn't execute statement: $DBI::errstr; stopped";
while( my $ref = $sth->fetchrow_hashref ) {
if($ref->{'setting'} eq 'db_version'){
return $ref->{'value'};
}
}
}
return 0;
}
sub errstr {
my $class = shift;
if ( @_ ) {
$errstr = (join '', @_)
}
eval "require HTML::Template";
if ( $@ ) {
return $errstr
}
my $tmpl = HTML::Template->new(
filename => 'error.tmpl',
die_on_bad_params => 0 );
$tmpl->param(
ERROR => $errstr,
ERRSTR => $errstr
);
return $tmpl->output()
}
sub get_vars {
my $self = shift;
my $q = $self->query();
my %global = ();
unless(($self->get_version() > $self->get_db_version())or($q->param('db_vers') > $self->get_db_version()))
{
my $statement = 'SELECT * FROM perlDesk_settings';
my $sth = $self->dbh()->prepare($statement) or die print "Couldn't prepare statement: $DBI::errstr; stopped";
$sth->execute() or die print "Couldn't execute statement: $DBI::errstr; stopped";
while( my $ref = $sth->fetchrow_hashref ) {
my $setting = $ref->{'setting'};
$global{$setting} = $ref->{'value'};
}
}
$global{'db_backup_dir'} = $db_backup_dir;
$global{'enablemail'} = $enablemail;
#$global{'imgbase'} .= get_current_theme();
return %global
}
sub get_setting_2 {
my ($self, $field) = @_;
unless ( defined $field ) {
confess "get_setting_2(): usage error"
}
my $dbh = $self->dbh();
return $dbh->selectrow_array(
'SELECT value FROM perlDesk_settings_extra WHERE setting=?',
undef, $field )
}
sub check_staff_num(@_){
my ($self, $field) = @_;
return PerlDesk::App::License::check_staff_num($self, $field);
}
sub is_ok(@_){
return PerlDesk::App::License::finding(@_);
}
sub get_setting {
my ($self, $field) = @_;
unless ( defined $field ) {
confess "get_setting(): usage error"
}
my $dbh = $self->dbh();
return $dbh->selectrow_array(
'SELECT value FROM perlDesk_settings WHERE setting=?',
undef, $field )
}
sub languages {
my @languages = ();
require "include/conf.cgi";
return @languages
}
sub LANG {
my $self = shift;
my $cgi = $self->query();
my %global = $self->get_vars();
my $lang = $cgi->param('lang') || $global{language} || 'en';
unless ( $lang ) {
die "couldn't detect a default language to use"
}
my $path = $ENV{PDESK_INSTDIR} || File::Spec->curdir();
$path = File::Spec->catfile($path, 'include', 'lang', "$lang.inc");
do $path;
return %LANG
}
sub teardown {
my $self = shift;
}
sub session {
my $self = shift;
if ( $self->param('SESSION_OBJ') ) {
return $self->param('SESSION_OBJ')
}
require CGI::Session;
require File::Spec;
my $session = new CGI::Session(undef, $self->query, {Directory=>File::Spec->tmpdir});
unless ( defined $session ) {
die CGI::Session->error()
}
$self->param('SESSION_OBJ', $session);
return $session
}
sub load_tmpl {
my ($self, $file, $vars) = @_;
$vars ||= {};
my $q = $self->query();
$vars->{'app.version'} = $self->VERSION();
while ( my ($k, $v) = each %ENV ) {
$vars->{'env.' . $k} = $v
}
for my $param ( $q->param ) {
$vars->{'cgi.' . $param} = $q->param($param)
}
my %global = $self->get_vars();
$vars->{lang} = $q->param('lang') || $global{'language'};
while ( my ($k, $v) = each %global ) {
if($k ne 'imgbase'){
$vars->{'cfg.' . $k} = $v;
}
else{$vars->{'cfg.' . $k} = $ENV{HTML_IMAGES_ROOT};}
}
my %LANG = $self->LANG();
while ( my ($k, $v) = each %LANG ) {
$vars->{'lang.' . $k} = $v
}
if ( $self->UNIVERSAL::can('profile_hash') ) {
my $profile = $self->profile_hash() || {};
while ( my ($k, $v) = each %$profile ) {
$vars->{'profile.' . $k} = $v
}
}
if ( $self->UNIVERSAL::can('check_user') ) {
$vars->{logged_in} = $self->check_user
}
require HTML::Template;
my $tpl = undef;
if ( ref $file eq 'SCALAR' ) {
$tpl = new HTML::Template(
scalarref => $file,
die_on_bad_params => 0,
global_vars => 1,
vanguard_compatibility_mode => 1,
loop_context_vars => 1);
} else {
$tpl = new HTML::Template(
filename => $file,
die_on_bad_params => 0,
global_vars => 1,
vanguard_compatibility_mode => 1,
loop_context_vars => 1);
}
$tpl->param( %$vars );
return $tpl->output
}
sub dbh {
my $self = shift;
if ( ref($self) && defined($self->param('DBH_OBJ')) ) {
return $self->param('DBH_OBJ')
}
require DBI;
my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost", $dbuser, $dbpass, {RaiseError=>1});
if ( ref $self ) {
$self->param('DBH_OBJ', $dbh)
}
return $dbh
}
# to be accessed by both App/Staff.pm and App/Admin.pm
sub contacts {
my $self = shift;
my $staff = $self->check_user();
unless ( defined $staff ) {
return $self->login()
}
require PerlDesk::Contact;
my @contacts = PerlDesk::Contact->load({staff=>$staff->id});
my @list = ();
while ( my $contact = shift @contacts ) {
push @list, $contact->columns
}
my %tmpl_vars = (
contacts => \@list
);
return $self->build_default_page('contacts.tmpl', \%tmpl_vars)
}
sub edit_contact {
my $self = shift;
my $staff = $self->check_user();
unless ( defined $staff ) {
return $self->login()
}
require PerlDesk::Contact;
my $q = $self->query();
my $contact_id = $q->param('id');
my $contact = undef;
if ( $contact_id ) {
$contact = PerlDesk::Contact->load($contact_id);
unless ( defined $contact ) {
return $self->errstr("Couldn't load the object")
}
unless ( $contact->staff eq $staff ) {
return $self->errstr("This contact doesnt' belong to you!")
}
} else {
$contact = new PerlDesk::Contact();
}
return $self->build_default_page('edit_contact.tmpl', $contact->columns)
}
sub email_webmaster
{
my $self = shift;
my $q = $self->query();
my $error = $q->param('error');
my %global = $self->get_vars();
my $body = qq|
Dear Administrator
$ENV{'REMOTE_ADDR'} has reported the following error:
$error
URL: $ENV{HTTP_REFERER}
|;
$self->email(
To => $global{adminemail},
From => $global{adminemail},
Subject => "perlDesk Error Report",
Body => $body);
return $self->errstr("Thank you, error reported to webmaster")
}
sub save_contact {
my $self = shift;
my $staff = $self->check_user();
unless ( defined $staff ) {
return $self->login()
}
require PerlDesk::Contact;
my $q = $self->query();
my $contact_id = $q->param('id');
my $contact = undef;
if ( $contact_id ) {
$contact = PerlDesk::Contact->load($contact_id);
unless ( defined $contact ) {
return $self->errstr("Couldn't load the Contact")
}
unless ( $contact->staff eq $staff ) {
return $self->errstr("This contact doesn't belong to you.")
}
} else {
$contact = new PerlDesk::Contact(staff=>$staff->id)
}
my $name = $q->param('name');
my $email = $q->param('email');
my $url = $q->param('url');
my $phone = $q->param('phone');
my $company = $q->param('company');
my $address = $q->param('address') || "Unknown";
unless ( $name && $email ) {
return $self->errstr("At least contact's Name and Email address should be provided")
}
$contact->name($name);
$contact->email($email);
$contact->url($url);
$contact->phone($phone);
$contact->address($address);
$contact->company($company);
my $new_contact_id = $contact->save();
unless ( $new_contact_id ) {
return $self->errstr("Couldn't store contact details: " . $contact->errstr)
}
return $self->redirect("$ENV{SCRIPT_NAME}?do=contacts;id=$new_contact_id")
}
sub delete_contact {
my $self = shift;
my $staff = $self->check_user();
unless ( $staff ) {
return $self->login()
}
require PerlDesk::Contact;
my $q = $self->query();
for my $id ( $q->param('id') ) {
my $contact = PerlDesk::Contact->load($id) or next;
unless ( $contact->remove() ) {
return $self->errstr("Couldn't delete a contact: " . $contact->errstr)
}
}
return $self->redirect($ENV{HTTP_REFERER}, "Contact(s) have been deleted succcessfully!")
}
# Format the code used in the desk
sub pdcode {
my ($self, $text) = @_;
unless ( defined $text ) {
die "pdcose(): usage error"
}
$text =~ s/\[b\]/<b>/gi;
$text =~ s/\[\/b\]/<\/b>/gi;
$text =~ s/\[i\]/<i>/gi;
$text =~ s/\[\/i\]/<\/i>/gi;
return $text
}
sub error {
my ($class, $message) = @_;
$message =~ s/\n/<br \/>/g;
return $message
}
sub get_time {
my $self = shift;
no strict 'vars';
my %global = $self->get_vars();
$global{'timeoffset'} = "0" if !$global{'timeoffset'};
my $timeoffset = $global{'timeoffset'};
my @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
my @months = ('January','February','March','April','May','June','July','August','September','October','November','December');
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time + (3600*$timeoffset));
$hour = "0$hour" if ($hour < 10);
$min = "0$min" if ($min < 10);
$sec = "0$sec" if ($sec < 10);
if ($hour >= 12) {
$variable = "P.M.";
} else {
$variable = "A.M."
}
if ($hour == 0) { $hour = 12 }
if ($hour > 12) { $hour -= 12 }
$year = 1900 + $year;
if ($mday eq "1") { $hy = "st"}
elsif ($mday eq "21") { $hy = "st"
} elsif ($mday eq "31") { $hy = "st";
} elsif ($mday eq "2") { $hy = "nd";
} elsif ($mday eq "22") { $hy = "nd";
} elsif ($mday eq "3") { $hy = "rd";
} elsif ($mday eq "23") { $hy = "rd";
} else { $hy = "th"; }
$day = $days[$wday];
$month = $months[$mon];
$month_no = ++$mon;
$date = "$mday$hy";
$date_no = $mday;
$time = "$hour:$min:$sec $variable";
$time_sv = "$hour:$min $variable";
$time_var = "$hour:$min:$sec";
$time_sec = "$hour:$min";
# TIME FORMAT IN PERLDESK
my $hdtime = "$date_no-$month_no-$year-$time_sec";
my $timenow = "$time ($date_no/$month_no/$year)";
if ( wantarray() ) {
return ($hdtime, $timenow)
}
return $hdtime
}
sub email {
my $self = shift;
return unless $enablemail;
my %contact = @_;
my %global = $self->get_vars();
my $dbh = $self->dbh();
chomp $contact{'To'};
my $em_header = $self->get_setting_2("em_header");
my $em_footer = $self->get_setting_2("em_footer");
$contact{'Body'} = qq|$em_header $contact{Body} \n\n $em_footer|;
my $sth = $dbh->prepare('SELECT * FROM perlDesk_em_forwarders WHERE address = ?');
$sth->execute( $contact{To} ) or die "Couldn't execute statement: $DBI::errstr; stopped";
my $skip_send = ($sth->rows > 0);
return if $skip_send;
if ($self->get_setting_2("use_smtp")) {
eval "require Mail::Sender";
if ( $@ ) {
die "To send emails through SMTP you need Mail::Sender module available"
}
my $smtp_address = $self->get_setting_2("smtp_address");
my $smtp_port = $self->get_setting_2("smtp_port");
my $sender = Mail::Sender->new({
smtp => $smtp_address,
replyto => $contact{'From'},
from => $contact{'From'} });
$sender->MailMsg({
to => $contact{To},
subject => $contact{'Subject'},
msg => $contact{'Body'}});
$sender->Close;
} else {
open (MAIL, "|$global{sendmail} -t -oi") or die "Unable to send mail: $!";
print MAIL "To: $contact{To}\n";
print MAIL "Cc: $contact{Cc}\n" if $contact{'Cc'};
print MAIL "From: $contact{From}\n";
print MAIL "Subject: $contact{Subject}\n\n";
print MAIL "$contact{Body}\n";
close(MAIL) or croak "couldn't send the message: $!"
}
}
sub notify_techs {
my $self = shift;
my %details = @_;
my %global = $self->get_vars();
my $dbh = $self->dbh();
my ($category) = $dbh->selectrow_array('SELECT category FROM perlDesk_calls WHERE id = ?',
undef, $details{tid} );
my $statement = qq|
SELECT * FROM perlDesk_staff
WHERE access LIKE "%$category::%" OR access LIKE "%GLOB::%" OR access="admin"|;
my $sth = $dbh->prepare( $statement );
$sth->execute() or die "Couldn't execute statement: $DBI::errstr; stopped";
while(my $ref = $sth->fetchrow_hashref()) {
$ref->{notify} or next;
my $body = "There is a new help desk response made by $details{name} in request $details{tid}\n";
$body .= "\nCall Details\n";
$body .= "-------------------------------------\n";
$body .= "\tResponse by......: $details{name} \n";
$body .= "\tTime.............: $details{time} \n";
$body .= "\t$details{note} \n";
$body .= "-------------------------------------\n";
$body .= "\n\nThank You.";
$self->email(
To => $ref->{email},
From => $global{adminemail},
Subject => "Help Desk User Response",
Body => $body)
}
}
sub dump {
my $self = shift;
require Data::Dumper;
my $d = Data::Dumper->new([$self], [ref $self]);
return $d->Dump()
}
sub select_options{
my $self = shift;
my @arr = @_;
my $temp;
if(ref $arr[0] eq 'ARRAY'){
my @arr2 = @{$arr[0]};
for(my $i=0; $i<=$#arr2; $i++){
my $user_view;
if(ref $arr[3]){
$user_view = $arr[3]->[$i];}
else{
$user_view = $i;
}
$user_view = sprintf($arr[4],$user_view) if($arr[4]);
$temp .="<Option value=$arr2[$i]>$user_view\n";
}
}
else{
for(my $i=$arr[0]; $i<=$arr[1]; $i++){
my $user_view;
if(ref $arr[3]){
$user_view = $arr[3]->[$i];}
else{
$user_view = $i;
}
$user_view = sprintf($arr[4],$user_view) if($arr[4]);
$temp .="<Option value=$i>$user_view\n";
}
}
$temp =~s /(value=$arr[2])/$1 SELECTED/i;
return $temp;
}
sub lang_parse
{
if ($_ =~ /\%*\%/)
{
s/\%(\S+)\%/$LANG{$1}/g;
}
}
sub user_logged_mysqltime{
my $self = shift;
my $user = @_;
my $dbh = $self->dbh();
my $statement = qq|SELECT MAX(id) FROM perlDesk_accesslog WHERE user = "$user"|;
my $sth = $dbh->prepare($statement)or return $self->errstr("Couldn't prepare statement: $DBI::errstr: stopped");
$sth->execute() or return $self->errstr("Couldn't execute statement: $DBI::errstr: stopped");
my $log_time_id = $sth->fetchrow_array();
my $statement = qq|SELECT time FROM perlDesk_accesslog WHERE id = "$log_time_id"|;
my $sth = $dbh->prepare($statement)or return $self->errstr("Couldn't prepare statement: $DBI::errstr: stopped");
$sth->execute() or return $self->errstr("Couldn't execute statement: $DBI::errstr: stopped");
return $sth->fetchrow_array();
}
sub mytime2unix{
my $self = shift;
my $mytime = shift;
my $dbh = $self->dbh();
my $statement = "SELECT UNIX_TIMESTAMP('$mytime') as unixtime";
#die $statement;
my $sth = $dbh->prepare($statement)or return $self->errstr("Couldn't prepare statement: $DBI::errstr: stopped");
$sth->execute() or return $self->errstr("Couldn't execute statement: $DBI::errstr: stopped");
my $ref = $sth->fetchrow_hashref();
return $ref->{'unixtime'};
}
sub pDesktime2mysql{
my $self = shift;
my $pDtime = shift;
my @arr = split /-/, $pDtime;
return $arr[2].'-'.$arr[1].'-'.$arr[0].' '.$arr[3];
}
sub pDesktime2unix{
my $self = shift;
my $pDtime = shift;
return $self->mytime2unix($self->pDesktime2mysql($pDtime));
}
sub date_diff{
my $self = shift;
my $diff = shift;
my $separator = ' ';
my ($tday, $thour, $tmin, $tsec);
my $tmp = int($diff) % 86400;
my $days = int((int($diff) - $tmp)/86400);
$tday = 's' if ($days>1);
$tday = $days.' day'.$tday.$separator if ($days);
$diff = $tmp;
$tmp = int($diff) % 3600;
my $hours = int((int($diff) - $tmp)/3600);
$thour = 's' if ($hours>1);
$thour = $hours.' hour'.$thour.$separator if ($days)or($hours);
$diff = $tmp;
$tmp = int($diff) % 60;
my $mins = int((int($diff) - $tmp)/60);
$tmin = 's' if ($mins>1);
$tmin = $mins.' min'.$tmin.$separator if ($days)or($hours)or($mins);
my $secs = $tmp;
$tsec = 's' if ($secs>1);
$tsec = $secs.' sec'.$tsec.$separator if ($days)or($hours)or($mins)or($secs);
return $tday.$thour.$tmin.$tsec;
}
1;
package PerlDesk::App;
use strict;
use vars qw(@ISA $VERSION %LANG $dbhost $dbname $dbuser $dbpass $errstr $db_backup_dir $perlDesk_version $enablemail $install %file_types);
use Carp;
use CGI::Application;eval{
require PerlDesk::App::License;};if ( my $error = $@ ) {die 'You have no license for using PerlDesk!';}
use File::Spec;
BEGIN {
$ENV{PDESK_INSTDIR} ||= File::Spec->curdir();
my $path = File::Spec->catfile($ENV{PDESK_INSTDIR}, 'include', 'conf.cgi');
require $path
}
@ISA = ('CGI::Application');
($VERSION) = '2.0' =~ m/Revision:\s*(\S+)/;
sub log {
my $self = shift;
my ($call_id, $user, $action) = @_;
unless ( $call_id && $user && $action ) {
die "PerlDesk::App->log(): usage error"
}
my ($hdtime, $timenow) = $self->get_time();
require PerlDesk::Log;
my $l = new PerlDesk::Log();
$l->cid( $call_id );
$l->user( $user );
$l->date( $hdtime);
$l->action( $action );
return $l->save();
}
sub accepted_file_types{
return \%file_types;
}
sub get_version{
return $perlDesk_version;
}
sub get_db_version{
my $self = shift;
my $settings_db = 0;
my $statement = 'SHOW TABLES';
my $sth = $self->dbh()->prepare($statement) or die print "Couldn't prepare statement: $DBI::errstr; stopped";
$sth->execute() or die print "Couldn't execute statement: $DBI::errstr; stopped";
while(my ($temp) = $sth->fetchrow_array()){
chomp $temp;
if (($temp eq 'perlDesk_settings')or($temp eq 'perldesk_settings')){
$settings_db = 1;
last;
}
}
if($settings_db){
my $statement = 'SELECT * FROM perlDesk_settings';
my $sth = $self->dbh()->prepare($statement) or die print "Couldn't prepare statement: $DBI::errstr; stopped";
$sth->execute() or die print "Couldn't execute statement: $DBI::errstr; stopped";
while( my $ref = $sth->fetchrow_hashref ) {
if($ref->{'setting'} eq 'db_version'){
return $ref->{'value'};
}
}
}
return 0;
}
sub errstr {
my $class = shift;
if ( @_ ) {
$errstr = (join '', @_)
}
eval "require HTML::Template";
if ( $@ ) {
return $errstr
}
my $tmpl = HTML::Template->new(
filename => 'error.tmpl',
die_on_bad_params => 0 );
$tmpl->param(
ERROR => $errstr,
ERRSTR => $errstr
);
return $tmpl->output()
}
sub get_vars {
my $self = shift;
my $q = $self->query();
my %global = ();
unless(($self->get_version() > $self->get_db_version())or($q->param('db_vers') > $self->get_db_version()))
{
my $statement = 'SELECT * FROM perlDesk_settings';
my $sth = $self->dbh()->prepare($statement) or die print "Couldn't prepare statement: $DBI::errstr; stopped";
$sth->execute() or die print "Couldn't execute statement: $DBI::errstr; stopped";
while( my $ref = $sth->fetchrow_hashref ) {
my $setting = $ref->{'setting'};
$global{$setting} = $ref->{'value'};
}
}
$global{'db_backup_dir'} = $db_backup_dir;
$global{'enablemail'} = $enablemail;
#$global{'imgbase'} .= get_current_theme();
return %global
}
sub get_setting_2 {
my ($self, $field) = @_;
unless ( defined $field ) {
confess "get_setting_2(): usage error"
}
my $dbh = $self->dbh();
return $dbh->selectrow_array(
'SELECT value FROM perlDesk_settings_extra WHERE setting=?',
undef, $field )
}
sub check_staff_num(@_){
my ($self, $field) = @_;
return PerlDesk::App::License::check_staff_num($self, $field);
}
sub is_ok(@_){
return PerlDesk::App::License::finding(@_);
}
sub get_setting {
my ($self, $field) = @_;
unless ( defined $field ) {
confess "get_setting(): usage error"
}
my $dbh = $self->dbh();
return $dbh->selectrow_array(
'SELECT value FROM perlDesk_settings WHERE setting=?',
undef, $field )
}
sub languages {
my @languages = ();
require "include/conf.cgi";
return @languages
}
sub LANG {
my $self = shift;
my $cgi = $self->query();
my %global = $self->get_vars();
my $lang = $cgi->param('lang') || $global{language} || 'en';
unless ( $lang ) {
die "couldn't detect a default language to use"
}
my $path = $ENV{PDESK_INSTDIR} || File::Spec->curdir();
$path = File::Spec->catfile($path, 'include', 'lang', "$lang.inc");
do $path;
return %LANG
}
sub teardown {
my $self = shift;
}
sub session {
my $self = shift;
if ( $self->param('SESSION_OBJ') ) {
return $self->param('SESSION_OBJ')
}
require CGI::Session;
require File::Spec;
my $session = new CGI::Session(undef, $self->query, {Directory=>File::Spec->tmpdir});
unless ( defined $session ) {
die CGI::Session->error()
}
$self->param('SESSION_OBJ', $session);
return $session
}
sub load_tmpl {
my ($self, $file, $vars) = @_;
$vars ||= {};
my $q = $self->query();
$vars->{'app.version'} = $self->VERSION();
while ( my ($k, $v) = each %ENV ) {
$vars->{'env.' . $k} = $v
}
for my $param ( $q->param ) {
$vars->{'cgi.' . $param} = $q->param($param)
}
my %global = $self->get_vars();
$vars->{lang} = $q->param('lang') || $global{'language'};
while ( my ($k, $v) = each %global ) {
if($k ne 'imgbase'){
$vars->{'cfg.' . $k} = $v;
}
else{$vars->{'cfg.' . $k} = $ENV{HTML_IMAGES_ROOT};}
}
my %LANG = $self->LANG();
while ( my ($k, $v) = each %LANG ) {
$vars->{'lang.' . $k} = $v
}
if ( $self->UNIVERSAL::can('profile_hash') ) {
my $profile = $self->profile_hash() || {};
while ( my ($k, $v) = each %$profile ) {
$vars->{'profile.' . $k} = $v
}
}
if ( $self->UNIVERSAL::can('check_user') ) {
$vars->{logged_in} = $self->check_user
}
require HTML::Template;
my $tpl = undef;
if ( ref $file eq 'SCALAR' ) {
$tpl = new HTML::Template(
scalarref => $file,
die_on_bad_params => 0,
global_vars => 1,
vanguard_compatibility_mode => 1,
loop_context_vars => 1);
} else {
$tpl = new HTML::Template(
filename => $file,
die_on_bad_params => 0,
global_vars => 1,
vanguard_compatibility_mode => 1,
loop_context_vars => 1);
}
$tpl->param( %$vars );
return $tpl->output
}
sub dbh {
my $self = shift;
if ( ref($self) && defined($self->param('DBH_OBJ')) ) {
return $self->param('DBH_OBJ')
}
require DBI;
my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost", $dbuser, $dbpass, {RaiseError=>1});
if ( ref $self ) {
$self->param('DBH_OBJ', $dbh)
}
return $dbh
}
# to be accessed by both App/Staff.pm and App/Admin.pm
sub contacts {
my $self = shift;
my $staff = $self->check_user();
unless ( defined $staff ) {
return $self->login()
}
require PerlDesk::Contact;
my @contacts = PerlDesk::Contact->load({staff=>$staff->id});
my @list = ();
while ( my $contact = shift @contacts ) {
push @list, $contact->columns
}
my %tmpl_vars = (
contacts => \@list
);
return $self->build_default_page('contacts.tmpl', \%tmpl_vars)
}
sub edit_contact {
my $self = shift;
my $staff = $self->check_user();
unless ( defined $staff ) {
return $self->login()
}
require PerlDesk::Contact;
my $q = $self->query();
my $contact_id = $q->param('id');
my $contact = undef;
if ( $contact_id ) {
$contact = PerlDesk::Contact->load($contact_id);
unless ( defined $contact ) {
return $self->errstr("Couldn't load the object")
}
unless ( $contact->staff eq $staff ) {
return $self->errstr("This contact doesnt' belong to you!")
}
} else {
$contact = new PerlDesk::Contact();
}
return $self->build_default_page('edit_contact.tmpl', $contact->columns)
}
sub email_webmaster
{
my $self = shift;
my $q = $self->query();
my $error = $q->param('error');
my %global = $self->get_vars();
my $body = qq|
Dear Administrator
$ENV{'REMOTE_ADDR'} has reported the following error:
$error
URL: $ENV{HTTP_REFERER}
|;
$self->email(
To => $global{adminemail},
From => $global{adminemail},
Subject => "perlDesk Error Report",
Body => $body);
return $self->errstr("Thank you, error reported to webmaster")
}
sub save_contact {
my $self = shift;
my $staff = $self->check_user();
unless ( defined $staff ) {
return $self->login()
}
require PerlDesk::Contact;
my $q = $self->query();
my $contact_id = $q->param('id');
my $contact = undef;
if ( $contact_id ) {
$contact = PerlDesk::Contact->load($contact_id);
unless ( defined $contact ) {
return $self->errstr("Couldn't load the Contact")
}
unless ( $contact->staff eq $staff ) {
return $self->errstr("This contact doesn't belong to you.")
}
} else {
$contact = new PerlDesk::Contact(staff=>$staff->id)
}
my $name = $q->param('name');
my $email = $q->param('email');
my $url = $q->param('url');
my $phone = $q->param('phone');
my $company = $q->param('company');
my $address = $q->param('address') || "Unknown";
unless ( $name && $email ) {
return $self->errstr("At least contact's Name and Email address should be provided")
}
$contact->name($name);
$contact->email($email);
$contact->url($url);
$contact->phone($phone);
$contact->address($address);
$contact->company($company);
my $new_contact_id = $contact->save();
unless ( $new_contact_id ) {
return $self->errstr("Couldn't store contact details: " . $contact->errstr)
}
return $self->redirect("$ENV{SCRIPT_NAME}?do=contacts;id=$new_contact_id")
}
sub delete_contact {
my $self = shift;
my $staff = $self->check_user();
unless ( $staff ) {
return $self->login()
}
require PerlDesk::Contact;
my $q = $self->query();
for my $id ( $q->param('id') ) {
my $contact = PerlDesk::Contact->load($id) or next;
unless ( $contact->remove() ) {
return $self->errstr("Couldn't delete a contact: " . $contact->errstr)
}
}
return $self->redirect($ENV{HTTP_REFERER}, "Contact(s) have been deleted succcessfully!")
}
# Format the code used in the desk
sub pdcode {
my ($self, $text) = @_;
unless ( defined $text ) {
die "pdcose(): usage error"
}
$text =~ s/\[b\]/<b>/gi;
$text =~ s/\[\/b\]/<\/b>/gi;
$text =~ s/\[i\]/<i>/gi;
$text =~ s/\[\/i\]/<\/i>/gi;
return $text
}
sub error {
my ($class, $message) = @_;
$message =~ s/\n/<br \/>/g;
return $message
}
sub get_time {
my $self = shift;
no strict 'vars';
my %global = $self->get_vars();
$global{'timeoffset'} = "0" if !$global{'timeoffset'};
my $timeoffset = $global{'timeoffset'};
my @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
my @months = ('January','February','March','April','May','June','July','August','September','October','November','December');
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time + (3600*$timeoffset));
$hour = "0$hour" if ($hour < 10);
$min = "0$min" if ($min < 10);
$sec = "0$sec" if ($sec < 10);
if ($hour >= 12) {
$variable = "P.M.";
} else {
$variable = "A.M."
}
if ($hour == 0) { $hour = 12 }
if ($hour > 12) { $hour -= 12 }
$year = 1900 + $year;
if ($mday eq "1") { $hy = "st"}
elsif ($mday eq "21") { $hy = "st"
} elsif ($mday eq "31") { $hy = "st";
} elsif ($mday eq "2") { $hy = "nd";
} elsif ($mday eq "22") { $hy = "nd";
} elsif ($mday eq "3") { $hy = "rd";
} elsif ($mday eq "23") { $hy = "rd";
} else { $hy = "th"; }
$day = $days[$wday];
$month = $months[$mon];
$month_no = ++$mon;
$date = "$mday$hy";
$date_no = $mday;
$time = "$hour:$min:$sec $variable";
$time_sv = "$hour:$min $variable";
$time_var = "$hour:$min:$sec";
$time_sec = "$hour:$min";
# TIME FORMAT IN PERLDESK
my $hdtime = "$date_no-$month_no-$year-$time_sec";
my $timenow = "$time ($date_no/$month_no/$year)";
if ( wantarray() ) {
return ($hdtime, $timenow)
}
return $hdtime
}
sub email {
my $self = shift;
return unless $enablemail;
my %contact = @_;
my %global = $self->get_vars();
my $dbh = $self->dbh();
chomp $contact{'To'};
my $em_header = $self->get_setting_2("em_header");
my $em_footer = $self->get_setting_2("em_footer");
$contact{'Body'} = qq|$em_header $contact{Body} \n\n $em_footer|;
my $sth = $dbh->prepare('SELECT * FROM perlDesk_em_forwarders WHERE address = ?');
$sth->execute( $contact{To} ) or die "Couldn't execute statement: $DBI::errstr; stopped";
my $skip_send = ($sth->rows > 0);
return if $skip_send;
if ($self->get_setting_2("use_smtp")) {
eval "require Mail::Sender";
if ( $@ ) {
die "To send emails through SMTP you need Mail::Sender module available"
}
my $smtp_address = $self->get_setting_2("smtp_address");
my $smtp_port = $self->get_setting_2("smtp_port");
my $sender = Mail::Sender->new({
smtp => $smtp_address,
replyto => $contact{'From'},
from => $contact{'From'} });
$sender->MailMsg({
to => $contact{To},
subject => $contact{'Subject'},
msg => $contact{'Body'}});
$sender->Close;
} else {
open (MAIL, "|$global{sendmail} -t -oi") or die "Unable to send mail: $!";
print MAIL "To: $contact{To}\n";
print MAIL "Cc: $contact{Cc}\n" if $contact{'Cc'};
print MAIL "From: $contact{From}\n";
print MAIL "Subject: $contact{Subject}\n\n";
print MAIL "$contact{Body}\n";
close(MAIL) or croak "couldn't send the message: $!"
}
}
sub notify_techs {
my $self = shift;
my %details = @_;
my %global = $self->get_vars();
my $dbh = $self->dbh();
my ($category) = $dbh->selectrow_array('SELECT category FROM perlDesk_calls WHERE id = ?',
undef, $details{tid} );
my $statement = qq|
SELECT * FROM perlDesk_staff
WHERE access LIKE "%$category::%" OR access LIKE "%GLOB::%" OR access="admin"|;
my $sth = $dbh->prepare( $statement );
$sth->execute() or die "Couldn't execute statement: $DBI::errstr; stopped";
while(my $ref = $sth->fetchrow_hashref()) {
$ref->{notify} or next;
my $body = "There is a new help desk response made by $details{name} in request $details{tid}\n";
$body .= "\nCall Details\n";
$body .= "-------------------------------------\n";
$body .= "\tResponse by......: $details{name} \n";
$body .= "\tTime.............: $details{time} \n";
$body .= "\t$details{note} \n";
$body .= "-------------------------------------\n";
$body .= "\n\nThank You.";
$self->email(
To => $ref->{email},
From => $global{adminemail},
Subject => "Help Desk User Response",
Body => $body)
}
}
sub dump {
my $self = shift;
require Data::Dumper;
my $d = Data::Dumper->new([$self], [ref $self]);
return $d->Dump()
}
sub select_options{
my $self = shift;
my @arr = @_;
my $temp;
if(ref $arr[0] eq 'ARRAY'){
my @arr2 = @{$arr[0]};
for(my $i=0; $i<=$#arr2; $i++){
my $user_view;
if(ref $arr[3]){
$user_view = $arr[3]->[$i];}
else{
$user_view = $i;
}
$user_view = sprintf($arr[4],$user_view) if($arr[4]);
$temp .="<Option value=$arr2[$i]>$user_view\n";
}
}
else{
for(my $i=$arr[0]; $i<=$arr[1]; $i++){
my $user_view;
if(ref $arr[3]){
$user_view = $arr[3]->[$i];}
else{
$user_view = $i;
}
$user_view = sprintf($arr[4],$user_view) if($arr[4]);
$temp .="<Option value=$i>$user_view\n";
}
}
$temp =~s /(value=$arr[2])/$1 SELECTED/i;
return $temp;
}
sub lang_parse
{
if ($_ =~ /\%*\%/)
{
s/\%(\S+)\%/$LANG{$1}/g;
}
}
sub user_logged_mysqltime{
my $self = shift;
my $user = @_;
my $dbh = $self->dbh();
my $statement = qq|SELECT MAX(id) FROM perlDesk_accesslog WHERE user = "$user"|;
my $sth = $dbh->prepare($statement)or return $self->errstr("Couldn't prepare statement: $DBI::errstr: stopped");
$sth->execute() or return $self->errstr("Couldn't execute statement: $DBI::errstr: stopped");
my $log_time_id = $sth->fetchrow_array();
my $statement = qq|SELECT time FROM perlDesk_accesslog WHERE id = "$log_time_id"|;
my $sth = $dbh->prepare($statement)or return $self->errstr("Couldn't prepare statement: $DBI::errstr: stopped");
$sth->execute() or return $self->errstr("Couldn't execute statement: $DBI::errstr: stopped");
return $sth->fetchrow_array();
}
sub mytime2unix{
my $self = shift;
my $mytime = shift;
my $dbh = $self->dbh();
my $statement = "SELECT UNIX_TIMESTAMP('$mytime') as unixtime";
#die $statement;
my $sth = $dbh->prepare($statement)or return $self->errstr("Couldn't prepare statement: $DBI::errstr: stopped");
$sth->execute() or return $self->errstr("Couldn't execute statement: $DBI::errstr: stopped");
my $ref = $sth->fetchrow_hashref();
return $ref->{'unixtime'};
}
sub pDesktime2mysql{
my $self = shift;
my $pDtime = shift;
my @arr = split /-/, $pDtime;
return $arr[2].'-'.$arr[1].'-'.$arr[0].' '.$arr[3];
}
sub pDesktime2unix{
my $self = shift;
my $pDtime = shift;
return $self->mytime2unix($self->pDesktime2mysql($pDtime));
}
sub date_diff{
my $self = shift;
my $diff = shift;
my $separator = ' ';
my ($tday, $thour, $tmin, $tsec);
my $tmp = int($diff) % 86400;
my $days = int((int($diff) - $tmp)/86400);
$tday = 's' if ($days>1);
$tday = $days.' day'.$tday.$separator if ($days);
$diff = $tmp;
$tmp = int($diff) % 3600;
my $hours = int((int($diff) - $tmp)/3600);
$thour = 's' if ($hours>1);
$thour = $hours.' hour'.$thour.$separator if ($days)or($hours);
$diff = $tmp;
$tmp = int($diff) % 60;
my $mins = int((int($diff) - $tmp)/60);
$tmin = 's' if ($mins>1);
$tmin = $mins.' min'.$tmin.$separator if ($days)or($hours)or($mins);
my $secs = $tmp;
$tsec = 's' if ($secs>1);
$tsec = $secs.' sec'.$tsec.$separator if ($days)or($hours)or($mins)or($secs);
return $tday.$thour.$tmin.$tsec;
}
1;
- Fórum WMO
- → Viewing Profile: Posts: WhiteBear
- Privacy Policy
- Regras ·