###################################################################################
#                                                                                 #
#                   PerlDesk - Customer Help Desk Software                        #
#                                                                                 #
###################################################################################
#                                                                                 #
#     Author: John Bennett	                                                  #
#      Email: j.bennett@perldesk.com                                              #
#        Web: http://www.perldesk.com                                             #
#   Filename: conf.pl                                                             #
#    Details: The main config file                                                #
#    Release: 1.5.5                                                               #
#                                                                                 #
###################################################################################
# Please direct bug reports,suggestions or feedback to the perldesk forums.       #
# www.perldesk.com/board                                                          #
#                                                                                 #
# PerlDesk is free for both commercial and non-commercial use providing that the  #
# copyright headers remain intact and the links remain on the html pages.         #
# Re-distribution of this script without prior consent is strictly prohibited.    # 
#                                                                                 #
###################################################################################
# Please see the README/INSTALL files if you have any problems with this software #                                                            
###################################################################################
# DATABASE SETTINGS

  $dbhost   = "localhost";
  $dbname   = "agenda_rvtdesk";
  $dbuser   = "agenda";
  $dbpass   = "gnd658";

  $ticketad = 'support@neikos.eu';


# by Ago
# Controlla l'IP di accesso al sistema e invia un email
# al'amministratore nel caso di un accesso 'strano'.
sub identity_control() {
	my $loginstring = "@_";

	@IPs = ('93.51.103.178', '79.10.195.33', '151.93.68.77', '10.10.10.([0-9]+)', '10.10.20.([0-9]+)');
	$userIP = $ENV{'REMOTE_ADDR'};

	$found = 0;
	foreach $IP (@IPs) {
		if ($userIP =~ m/^($IP)$/) {
			$found = 1;
		}
	} 
	
	if ($found == 0) {			
		($sec,$min,$ore,$giom,$mese,$anno,$gios,$gioa,$oraleg) = localtime(time);
		$anno = $anno + 1900;
		$mese = $mese + 1;
		
		$message = "agenda.neikos.it\n".$ore.":".$min." ".$giom."/".$mese."/".$anno."\n\nLogin da un indirizzo IP sconosciuto.\nNome utente: " . $loginstring . "\nIndirizzo IP: " . $userIP;		
	
		open(MAIL, "|$global{'sendmail'} -t") || print "Unable to send mail: $!";
			print MAIL "To: staff\@neikos.eu \n"; 
			print MAIL "From: $global{'adminemail'}\n";
			print MAIL "Subject: agenda.neikos.it - Ticket - $loginstring - login da un indirizzo IP sconosciuto\n\n";
			print MAIL "$message\n";
			print MAIL "\n\nThank You.\n";
		close(MAIL); 	
	}
}
# fine modifica email - by Ago


# This address will act as the center point for email 
# control on perldesk. You can still setup multiple email
# addresses, but this will be the address which handles 
# reply emails and email notifications.


### THATS ALL - YOU MUST NOW RUN INSTALL.CGI / UGRADE.CGI

  $enablemail  = 1;
 

sub die_nice 
  {
      my $error = "@_";
        print "Content-type: text/html\n\n";
        print qq|
                   <html><head><title>$global{'title'}: Error</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
                   </head><body bgcolor="#FFFFFF"><p>&nbsp;</p><table width="496" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td colspan="3"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>$global{'title'}: 
                   <font color="#990000"> Error</font></b></font></td></tr><tr><td colspan="3" height="11">&nbsp;</td></tr><tr><td colspan="3" height="6"><font face="Courier New, Courier, mono" size="2">$error</font></td></tr><tr> <td colspan="3" height="2">&nbsp;</td></tr><tr> <td colspan="3" height="40"> <table width="60%" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td width="50%"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="javascript:history.back(1)">BACK</a></font></b></td><td width="50%"><div align="right"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="$template{'mainfile'}?do=login">LOGIN</a></font></b></div></td></tr></table></td></tr></table><p align="center">&nbsp;</p></body></html>
                |;
        exit; 
  }


 sub email 
  {
     my %contact = @_;
     if ($enablemail == "1")
      {
        open(MAIL, "|$global{'sendmail'} -t") || die "Unable to send mail: $!";
              print MAIL "To: $contact{'To'}\n";
              print MAIL "From: $contact{'From'}\n";
              print MAIL "Subject: $contact{'Subject'}\n\n";
              print MAIL "$contact{'Body'}\n";
        close(MAIL);
      }
 }


sub pdcode {

  # Format the code used in the desk

      my $text = "@_";

         $text =~ s/\[b\]/<b>/gi;
         $text =~ s/\[\/b\]/<\/b>/gi;
         $text =~ s/\[i\]/<i>/gi;
         $text =~ s/\[\/i\]/<\/i>/gi;

  return $text;  

}



 sub script_error {

  my $error = "@_";

  print "Content-type: text/html\n\n";
 
  print qq~<html><head><title>PerlDesk Error</title>
           <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
           </head><body bgcolor="#FFFFFF"><p>&nbsp;</p><table width="600" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td colspan="3"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>PerlDesk: <font color="#990000">Script Error</font></b></font></td>
           </tr><tr> <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr> <td colspan="3"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Perldesk was unable to launch due to the following errors:</font></td>
           </tr><tr><td colspan="3" height="40"><font face="Courier New, Courier, mono" size="2"><br>$error<br><br><br><Br><div align=center>[ <a href="http://perldesk.com/board">Support Board</a> | <a href="http://perldesk.com">PerlDesk Site</a> ]</font></td></tr></table><p align="center">&nbsp;</p></body></html>
          ~;

 exit;

 }









sub notify_techs 
 {

    my %details = @_;

   $statement = 'SELECT * FROM `calls` WHERE id = ?'; 
   $sth = $dbh->prepare($statement) or die print "Couldn't prepare statement: $DBI::errstr; stopped";
   $sth->execute( $details{'tid'} ) or die print "Couldn't execute statement: $DBI::errstr; stopped";
      $number=0;
          while(my $ref = $sth->fetchrow_hashref()) 
            {	
	       		$category    =  $ref->{'category'};
            }

   $statement = qq|SELECT * FROM staff WHERE access LIKE "%$category::%" OR access LIKE "%GLOB::%" OR access="admin"|;
        $sth = $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->{'notify'}) {
           if ($enablemail) {
			open(MAIL, "|$global{'sendmail'} -t") || print "Unable to send mail: $!";
				print MAIL "To: $ref->{'email'}\n";
				print MAIL "From: $global{'adminemail'}\n";
				print MAIL "Subject: Help Desk User Response\n\n";
				print MAIL "There is a new help desk response made by '$details{'name'}' in request $details{'tid'}\n";
				print MAIL "\nCall Details\n";
				print MAIL "---------------------------------------\n";
				print MAIL "\tResponse by......: $details{'name'}  \n";
				print MAIL "\tTime.............: $details{'time'}  \n"; 
				print MAIL "\t$details{'note'}                     \n";
				print MAIL "---------------------------------------\n";
				print MAIL "\n\nThank You.";
			close(MAIL); 
		} }
	}
            $sth->finish;
}




$cdomain = "";

# This will set the domain for the cookies, please leave 
# the period (.) at the start of your domain. Excluding
# any sub-domains or 'www' pre-fixes.




@languages = ("en", "sw", "no", "es", "fr", "gm");

# en -> English
# sw -> Swedish
# es -> Spanish
# no -> Norweigan


%langdetails = 
  (
       en     =>   "English",
       sw     =>   "Swedish",
       no     =>   "Norwegian",
       es     =>   "Spanish",
       fr     =>   "French",
       gm     =>   "German"
  );

# You can leave the above as it is, unless you need to 
# remove or add any languages - in which case you must 
# edit both @languages and %langdetails

$enablelang = 1;   

# Enable multi-languages/translation,



###############################################################
# GLOBAL DATE AND TIME


sub get_time {

   $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');
	($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

       $hdtime  = "$date_no-$month_no-$year-$time_sec";
       $timenow = "$time ($date_no/$month_no/$year)";

}






1;
