From 38256ac39e1ad1d6cc105a523cac3651c30eedff Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Thu, 2 Oct 2014 13:44:40 -0600 Subject: [PATCH 01/40] Adding new separate init.d scripts Conflicts: Makefile init.d/freeside-queued.init init.d/freeside-xmlrpcd.init --- Makefile | 39 +++++++++- init.d/freeside-prepaidd.init | 131 ++++++++++++++++++++++++++++++++++ init.d/freeside-queued.init | 131 ++++++++++++++++++++++++++++++++++ init.d/freeside-xmlrpcd.init | 131 ++++++++++++++++++++++++++++++++++ 4 files changed, 430 insertions(+), 2 deletions(-) create mode 100644 init.d/freeside-prepaidd.init create mode 100644 init.d/freeside-queued.init create mode 100644 init.d/freeside-xmlrpcd.init diff --git a/Makefile b/Makefile index b2eb8695cf..8c142f4209 100644 --- a/Makefile +++ b/Makefile @@ -46,13 +46,20 @@ FREESIDE_DOCUMENT_ROOT = /var/www/freeside #deb, redhat, fedora, mandrake, suse, others? INIT_FILE = /etc/init.d/freeside +INIT_FILE_QUEUED = /etc/init.d/freeside-queued +INIT_FILE_PREPAIDD = /etc/init.d/freeside-prepaidd +INIT_FILE_XMLRPCD = /etc/init.d/freeside-xmlrpcd #freebsd #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh #deb -INIT_INSTALL = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside defaults 23 01 +#INIT_INSTALL = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside defaults 23 01 #redhat, fedora -#INIT_INSTALL = /sbin/chkconfig freeside on +INIT_INSTALL = /sbin/chkconfig freeside on +INIT_INSTALL_QUEUED = /sbin/chkconfig freeside-queued on +INIT_INSTALL_PREPAIDD = /sbin/chkconfig freeside-prepaidd on +INIT_INSTALL_XMLRPCD = /sbin/chkconfig freeside-xmlrpcd on + #not necessary (freebsd) #INIT_INSTALL = /usr/bin/true @@ -277,6 +284,34 @@ install-init: " ${INIT_FILE} ${INIT_INSTALL} + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-queued.init ${INIT_FILE_QUEUED} + perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_QUEUED} + ${INIT_INSTALL_QUEUED} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-prepaidd.init ${INIT_FILE_PREPAIDD} + perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_PREPAIDD} + ${INIT_INSTALL_PREPAIDD} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-xmlrpcd.init ${INIT_FILE_XMLRPCD} + perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_XMLRPCD} + ${INIT_INSTALL_XMLRPCD} + + install-apache: [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true [ -d ${APACHE_CONF} ] && \ diff --git a/init.d/freeside-prepaidd.init b/init.d/freeside-prepaidd.init new file mode 100644 index 0000000000..daff0cc776 --- /dev/null +++ b/init.d/freeside-prepaidd.init @@ -0,0 +1,131 @@ +#!/bin/bash + +# description: Manage the freeside-prepaidd script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=freeside-prepaidd +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/${SERVICE}.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${QUEUED_USER} ] +then + QUEUED_USER=%%%QUEUED_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + RUNNING=0 + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + scl enable perl516 "${SERVICE} $QUEUED_USER" + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + if ! [ -d /var/run/freeside ] + then + mkdir /var/run/freeside + fi + # Don't need to capture PID. It's handled by the service + # PID=`pgrep -f '^perl.*${SERVICE}'` + # echo $PID > ${PIDFILE} + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + status -p $PIDFILE +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac diff --git a/init.d/freeside-queued.init b/init.d/freeside-queued.init new file mode 100644 index 0000000000..c33bf94094 --- /dev/null +++ b/init.d/freeside-queued.init @@ -0,0 +1,131 @@ +#!/bin/bash + +# description: Manage the freeside-queued script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=freeside-queued +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/${SERVICE}.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${QUEUED_USER} ] +then + QUEUED_USER=%%%QUEUED_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + RUNNING=0 + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + scl enable perl516 "${SERVICE} $QUEUED_USER" + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + if ! [ -d /var/run/freeside ] + then + mkdir /var/run/freeside + fi + # Don't need to capture PID. It's handled by the service + # PID=`pgrep -f '^perl.*${SERVICE}'` + # echo $PID > ${PIDFILE} + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + status -p $PIDFILE +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac diff --git a/init.d/freeside-xmlrpcd.init b/init.d/freeside-xmlrpcd.init new file mode 100644 index 0000000000..105960536e --- /dev/null +++ b/init.d/freeside-xmlrpcd.init @@ -0,0 +1,131 @@ +#!/bin/bash + +# description: Manage the freeside-xmlrpcd script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=freeside-xmlrpcd +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/freeside/xmlrpcd.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${QUEUED_USER} ] +then + QUEUED_USER=%%%QUEUED_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + RUNNING=0 + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + scl enable perl516 "${SERVICE} $QUEUED_USER" + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + if ! [ -d /var/run/freeside ] + then + mkdir /var/run/freeside + fi + # Don't need to capture PID. It's handled by the service + # PID=`pgrep -f '^perl.*${SERVICE}'` + # echo $PID > ${PIDFILE} + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + status -p $PIDFILE +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac From 54d1c8d6200b0bc87367443ccf216fcd3d1fa10b Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Thu, 2 Oct 2014 14:48:42 -0600 Subject: [PATCH 02/40] xmlrpcd should die with myexit() --- FS/bin/freeside-xmlrpcd | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/FS/bin/freeside-xmlrpcd b/FS/bin/freeside-xmlrpcd index 724c5adb39..3d826fc7eb 100644 --- a/FS/bin/freeside-xmlrpcd +++ b/FS/bin/freeside-xmlrpcd @@ -1,6 +1,7 @@ #!/usr/bin/perl use FS::Daemon::Preforking qw( freeside_init1 freeside_init2 daemon_run ); +use FS::Daemon qw( myexit ); use FS::XMLRPC_Lite; #XMLRPC::Lite for XMLRPC::Serializer #and XMLRPC::Transport::HTTP @@ -20,10 +21,15 @@ freeside_init1(ME); freeside_init2(ME); my $conf = new FS::Conf; -die "not running; xmlrpc_api conf option is off\n" - unless $conf->exists('xmlrpc_api'); -die "not running; api_shared_secret conf option is not set\n" - unless $conf->config('api_shared_secret'); +do { + warn "not running; xmlrpc_api conf option is off"; + myexit(); +} unless $conf->exists('xmlrpc_api'); + +do { + warn "not running; api_shared_secret conf option is not set"; + myexit(); +} unless $conf->config('api_shared_secret'); daemon_run( 'port' => 8008, 'handle_request' => sub { From 9c5dcbacde36eeec3935e1d41ca6c7d3e994ff63 Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Fri, 3 Oct 2014 09:28:36 -0600 Subject: [PATCH 03/40] daemon_run should call myexit() before returning to clean up gracefully --- FS/FS/Daemon/Preforking.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/FS/FS/Daemon/Preforking.pm b/FS/FS/Daemon/Preforking.pm index 98b4fa68c9..e37a151dad 100644 --- a/FS/FS/Daemon/Preforking.pm +++ b/FS/FS/Daemon/Preforking.pm @@ -99,6 +99,7 @@ sub daemon_run { server_spawn(MAX_PROCESSES); POE::Kernel->run(); + myexit(); #exit; } From c50751678807490bc32b3a13fd11be2ee0b59f18 Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Mon, 6 Oct 2014 15:55:41 -0600 Subject: [PATCH 04/40] More init scripts and inclusion of them in the root Makefile Conflicts: Makefile --- FS/bin/freeside-cdrd | 6 +- FS/bin/freeside-cdrrewrited | 8 +- Makefile | 21 +++++ init.d/freeside-cdrd.init | 131 +++++++++++++++++++++++++++++++ init.d/freeside-cdrrewrited.init | 131 +++++++++++++++++++++++++++++++ init.d/freeside-prepaidd.init | 2 +- init.d/freeside-queued.init | 2 +- init.d/freeside-xmlrpcd.init | 6 +- 8 files changed, 297 insertions(+), 10 deletions(-) create mode 100644 init.d/freeside-cdrd.init create mode 100644 init.d/freeside-cdrrewrited.init diff --git a/FS/bin/freeside-cdrd b/FS/bin/freeside-cdrd index 45d58789dd..e6376f0934 100644 --- a/FS/bin/freeside-cdrd +++ b/FS/bin/freeside-cdrd @@ -21,8 +21,10 @@ logfile( "%%%FREESIDE_LOG%%%/cdrd-log.". $FS::UID::datasrc ); daemonize2(); -die "not running; no voip_cdr package defs w/ bill_every_call and customer pkgs" - unless _shouldrun(); +do { + warn "not running; no voip_cdr package defs w/ bill_every_call and customer pkgs" + myexit(); +} unless _shouldrun(); #-- diff --git a/FS/bin/freeside-cdrrewrited b/FS/bin/freeside-cdrrewrited index 16f931fbf0..c8f5bcd841 100644 --- a/FS/bin/freeside-cdrrewrited +++ b/FS/bin/freeside-cdrrewrited @@ -24,9 +24,11 @@ daemonize2(); $conf = new FS::Conf; -die "not running; cdr-asterisk_forward_rewrite, cdr-charged_party_rewrite ". - " and cdr-taqua-accountcode_rewrite conf options are all off\n" - unless _shouldrun(); +do { + warn "not running; cdr-asterisk_forward_rewrite, cdr-charged_party_rewrite ". + " and cdr-taqua-accountcode_rewrite conf options are all off\n"; + myexit(); +} unless _shouldrun(); #-- diff --git a/Makefile b/Makefile index 8c142f4209..1927e82838 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,8 @@ INIT_FILE = /etc/init.d/freeside INIT_FILE_QUEUED = /etc/init.d/freeside-queued INIT_FILE_PREPAIDD = /etc/init.d/freeside-prepaidd INIT_FILE_XMLRPCD = /etc/init.d/freeside-xmlrpcd +INIT_FILE_CDRREWRITED = /etc/init.d/freeside-cdrrewrited +INIT_FILE_CDRD = /etc/init.d/freeside-cdrd #freebsd #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh @@ -59,6 +61,8 @@ INIT_INSTALL = /sbin/chkconfig freeside on INIT_INSTALL_QUEUED = /sbin/chkconfig freeside-queued on INIT_INSTALL_PREPAIDD = /sbin/chkconfig freeside-prepaidd on INIT_INSTALL_XMLRPCD = /sbin/chkconfig freeside-xmlrpcd on +INIT_INSTALL_CDRREWRITED = /sbin/chkconfig freeside-cdrrewrited on +INIT_INSTALL_CDRD = /sbin/chkconfig freeside-cdrd on #not necessary (freebsd) #INIT_INSTALL = /usr/bin/true @@ -311,6 +315,23 @@ install-init: " ${INIT_FILE_XMLRPCD} ${INIT_INSTALL_XMLRPCD} + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-cdrrewrited.init ${INIT_FILE_CDRREWRITED} + perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_CDRREWRITED} + ${INIT_INSTALL_CDRREWRITED} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-cdrd.init ${INIT_FILE_CDRD} + perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_CDRD} + ${INIT_INSTALL_CDRD} install-apache: [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true diff --git a/init.d/freeside-cdrd.init b/init.d/freeside-cdrd.init new file mode 100644 index 0000000000..42d3a787e9 --- /dev/null +++ b/init.d/freeside-cdrd.init @@ -0,0 +1,131 @@ +#!/bin/bash + +# description: Manage the freeside-cdrd script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=freeside-cdrd +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/${SERVICE}.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${QUEUED_USER} ] +then + QUEUED_USER=%%%QUEUED_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + RUNNING=0 + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + ${SERVICE} $QUEUED_USER + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + if ! [ -d /var/run/freeside ] + then + mkdir /var/run/freeside + fi + # Don't need to capture PID. It's handled by the service + # PID=`pgrep -f '^perl.*${SERVICE}'` + # echo $PID > ${PIDFILE} + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + status -p $PIDFILE +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac diff --git a/init.d/freeside-cdrrewrited.init b/init.d/freeside-cdrrewrited.init new file mode 100644 index 0000000000..48b078ee4e --- /dev/null +++ b/init.d/freeside-cdrrewrited.init @@ -0,0 +1,131 @@ +#!/bin/bash + +# description: Manage the freeside-cdrrewrited script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=freeside-cdrrewrited +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/${SERVICE}.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${QUEUED_USER} ] +then + QUEUED_USER=%%%QUEUED_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + RUNNING=0 + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + ${SERVICE} $QUEUED_USER + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + if ! [ -d /var/run/freeside ] + then + mkdir /var/run/freeside + fi + # Don't need to capture PID. It's handled by the service + # PID=`pgrep -f '^perl.*${SERVICE}'` + # echo $PID > ${PIDFILE} + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + status -p $PIDFILE +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac diff --git a/init.d/freeside-prepaidd.init b/init.d/freeside-prepaidd.init index daff0cc776..af3d9ebe72 100644 --- a/init.d/freeside-prepaidd.init +++ b/init.d/freeside-prepaidd.init @@ -55,7 +55,7 @@ startfunc() { then action "Already running ${SERVICE} " /bin/false else - scl enable perl516 "${SERVICE} $QUEUED_USER" + ${SERVICE} $QUEUED_USER RETVAL=$? action "Starting ${SERVICE} " /bin/true if [ $RETVAL = 0 ] diff --git a/init.d/freeside-queued.init b/init.d/freeside-queued.init index c33bf94094..e6334c1a33 100644 --- a/init.d/freeside-queued.init +++ b/init.d/freeside-queued.init @@ -55,7 +55,7 @@ startfunc() { then action "Already running ${SERVICE} " /bin/false else - scl enable perl516 "${SERVICE} $QUEUED_USER" + ${SERVICE} $QUEUED_USER RETVAL=$? action "Starting ${SERVICE} " /bin/true if [ $RETVAL = 0 ] diff --git a/init.d/freeside-xmlrpcd.init b/init.d/freeside-xmlrpcd.init index 105960536e..7e42a4a98d 100644 --- a/init.d/freeside-xmlrpcd.init +++ b/init.d/freeside-xmlrpcd.init @@ -23,9 +23,9 @@ then . %%%FREESIDE_DEFAULTS%%% fi -if [ -z ${QUEUED_USER} ] +if [ -z ${API_USER} ] then - QUEUED_USER=%%%QUEUED_USER%%% + API_USER=%%%API_USER%%% fi # 0: program is running or service is OK @@ -55,7 +55,7 @@ startfunc() { then action "Already running ${SERVICE} " /bin/false else - scl enable perl516 "${SERVICE} $QUEUED_USER" + ${SERVICE} $API_USER RETVAL=$? action "Starting ${SERVICE} " /bin/true if [ $RETVAL = 0 ] From 35f29002ec4f832c23d6a83bd49f4f30e14f50a1 Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Thu, 9 Oct 2014 14:12:47 -0600 Subject: [PATCH 05/40] New init scripts, some service tweaks, and Makefile changes to support init scripts. Conflicts: Makefile --- FS/bin/freeside-cdrrated | 6 +- FS/bin/freeside-selfservice-xmlrpcd | 7 +- FS/bin/freeside-sqlradius-radacctd | 10 +- FS/bin/freeside-torrus-srvderive | 6 +- Makefile | 55 ++++++++ init.d/freeside-cdrd.init | 7 - init.d/freeside-cdrrated.init | 124 +++++++++++++++++ init.d/freeside-cdrrewrited.init | 7 - init.d/freeside-init | 2 +- init.d/freeside-prepaidd.init | 7 - init.d/freeside-queued.init | 7 - init.d/freeside-selfservice-server.init | 165 +++++++++++++++++++++++ init.d/freeside-selfservice-xmlrpcd.init | 127 +++++++++++++++++ init.d/freeside-sqlradius-radacctd.init | 124 +++++++++++++++++ init.d/freeside-torrus-srvderive.init | 124 +++++++++++++++++ init.d/freeside-torrus.init | 128 ++++++++++++++++++ init.d/freeside-xmlrpcd.init | 3 - 17 files changed, 867 insertions(+), 42 deletions(-) create mode 100644 init.d/freeside-cdrrated.init create mode 100644 init.d/freeside-selfservice-server.init create mode 100644 init.d/freeside-selfservice-xmlrpcd.init create mode 100644 init.d/freeside-sqlradius-radacctd.init create mode 100644 init.d/freeside-torrus-srvderive.init create mode 100644 init.d/freeside-torrus.init diff --git a/FS/bin/freeside-cdrrated b/FS/bin/freeside-cdrrated index 2966b2e4e6..65dedd1dfd 100644 --- a/FS/bin/freeside-cdrrated +++ b/FS/bin/freeside-cdrrated @@ -22,8 +22,10 @@ daemonize2(); our $conf = new FS::Conf; -die "not running; cdr-prerate conf option is off\n" - unless _shouldrun(); +do { + warn "not running; cdr-prerate conf option is off\n" + myexit(); +} unless _shouldrun(); #-- diff --git a/FS/bin/freeside-selfservice-xmlrpcd b/FS/bin/freeside-selfservice-xmlrpcd index e9df40735a..afedbe0f27 100755 --- a/FS/bin/freeside-selfservice-xmlrpcd +++ b/FS/bin/freeside-selfservice-xmlrpcd @@ -1,6 +1,7 @@ #!/usr/bin/perl use FS::Daemon::Preforking qw( freeside_init1 freeside_init2 daemon_run ); +use FS::Daemon qw( myexit ); use FS::XMLRPC_Lite; #XMLRPC::Lite for XMLRPC::Serializer #and XMLRPC::Transport::HTTP @@ -26,8 +27,10 @@ freeside_init2(ME); FS::ClientAPI::Signup::clear_cache(); my $conf = new FS::Conf; -die "not running; selfservice-xmlrpc conf option is off\n" - unless $conf->exists('selfservice-xmlrpc'); +do { + warn "not running; selfservice-xmlrpc conf option is off\n" + myexit(); +} unless $conf->exists('selfservice-xmlrpc'); daemon_run( 'port' => 8080, 'handle_request' => sub { diff --git a/FS/bin/freeside-sqlradius-radacctd b/FS/bin/freeside-sqlradius-radacctd index 7b2d04dc73..72f19f589f 100644 --- a/FS/bin/freeside-sqlradius-radacctd +++ b/FS/bin/freeside-sqlradius-radacctd @@ -5,7 +5,7 @@ use vars qw( @part_export ); use subs qw(myshutdown); use POSIX qw(:sys_wait_h); #use IO::File; -use FS::Daemon qw(daemonize1 drop_root logfile daemonize2 sigint sigterm); +use FS::Daemon qw(daemonize1 drop_root logfile daemonize2 sigint sigterm myexit); use FS::UID qw(adminsuidsetup); #forksuidsetup driver_name dbh myconnect); use FS::Record qw(qsearch); # qsearchs); use FS::part_export; @@ -32,9 +32,11 @@ daemonize2(); my @part_export = FS::part_export::sqlradius->all_sqlradius_withaccounting(); -die "no sqlradius, sqlradius_withdomain, radiator or phone_sqlradius exports". +do { + warn "no sqlradius, sqlradius_withdomain, radiator or phone_sqlradius exports". " without ignore_accounting" - unless @part_export; + myexit(); +} unless @part_export; while (1) { @@ -89,7 +91,7 @@ sub myshutdown { &reap_kids; } warn "abandoning children" if grep $_->{'_radacct_kid'}, @part_export; - die "exiting"; + myexit(); } sub reap_kids { diff --git a/FS/bin/freeside-torrus-srvderive b/FS/bin/freeside-torrus-srvderive index 5ad23aba45..5e7b811ff7 100644 --- a/FS/bin/freeside-torrus-srvderive +++ b/FS/bin/freeside-torrus-srvderive @@ -29,8 +29,10 @@ daemonize2(); our $conf = new FS::Conf; -die "not running: network_monitoring_system not Torrus_Internal\n" - unless _shouldrun(); +do { + warn "not running: network_monitoring_system not Torrus_Internal\n" + myexit(); +} unless _shouldrun(); #-- diff --git a/Makefile b/Makefile index 1927e82838..8a343f1e1c 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,11 @@ INIT_FILE_PREPAIDD = /etc/init.d/freeside-prepaidd INIT_FILE_XMLRPCD = /etc/init.d/freeside-xmlrpcd INIT_FILE_CDRREWRITED = /etc/init.d/freeside-cdrrewrited INIT_FILE_CDRD = /etc/init.d/freeside-cdrd +INIT_FILE_CDRRATED = /etc/init.d/freeside-cdrrated +INIT_FILE_TORRUS_SRVDERIVE = /etc/init.d/freeside-torrus-srvderive +INIT_FILE_SQLRADIUS_RADACCTD = /etc/init.d/freeside-sqlradius_radacctd +INIT_FILE_TORRUS = /etc/init.d/freeside-torrus +INIT_FILE_SELFSERVICE_XMLRPCD = /etc/init.d/freeside-selfservice-xmlrpcd #freebsd #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh @@ -63,6 +68,10 @@ INIT_INSTALL_PREPAIDD = /sbin/chkconfig freeside-prepaidd on INIT_INSTALL_XMLRPCD = /sbin/chkconfig freeside-xmlrpcd on INIT_INSTALL_CDRREWRITED = /sbin/chkconfig freeside-cdrrewrited on INIT_INSTALL_CDRD = /sbin/chkconfig freeside-cdrd on +INIT_INSTALL_TORRUS_SRVDERIVE = /sbin/chkconfig freeside-torrus-srvderive on +INIT_INSTALL_SQLRADIUS_RADACCTD = /sbin/chkconfig freeside-sqlradius_radacctd on +INIT_INSTALL_TORRUS = /sbin/chkconfig freeside-torrus on +INIT_INSTALL_SELFSERVICE_XMLRPCD = /sbin/chkconfig freeside-selfservice-xmlrpcd on #not necessary (freebsd) #INIT_INSTALL = /usr/bin/true @@ -333,6 +342,52 @@ install-init: " ${INIT_FILE_CDRD} ${INIT_INSTALL_CDRD} + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-cdrrated.init ${INIT_FILE_CDRRATED} + perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_CDRRATED} + ${INIT_INSTALL_CDRRATED} + + [ ${TORRUS_ENABLED} -eq 1 ] && install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus-srvderive.init ${INIT_FILE_TORRUS_SRVDERIVE} + [ ${TORRUS_ENABLED} -eq 1 ] && perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_TORRUS_SRVDERIVE} + [ ${TORRUS_ENABLED} -eq 1 ] && ${INIT_INSTALL_TORRUS_SRVDERIVE} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-sqlradius-radacctd.init ${INIT_FILE_SQLRADIUS_RADACCTD} + perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_SQLRADIUS_RADACCTD} + ${INIT_INSTALL_SQLRADIUS_RADACCTD} + + [ ${TORRUS_ENABLED} -eq 1 ] && install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus.init ${INIT_FILE_TORRUS} + [ ${TORRUS_ENABLED} -eq 1 ] && perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_TORRUS} + [ ${TORRUS_ENABLED} -eq 1 ] && ${INIT_INSTALL_TORRUS} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-selfservice-xmlrpcd.init ${INIT_FILE_SELFSERVICE_XMLRPCD} + perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_SELFSERVICE_XMLRPCD} + ${INIT_INSTALL_SELFSERVICE_XMLRPCD} + + install-apache: [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true [ -d ${APACHE_CONF} ] && \ diff --git a/init.d/freeside-cdrd.init b/init.d/freeside-cdrd.init index 42d3a787e9..7611ca0f0e 100644 --- a/init.d/freeside-cdrd.init +++ b/init.d/freeside-cdrd.init @@ -60,13 +60,6 @@ startfunc() { action "Starting ${SERVICE} " /bin/true if [ $RETVAL = 0 ] then - if ! [ -d /var/run/freeside ] - then - mkdir /var/run/freeside - fi - # Don't need to capture PID. It's handled by the service - # PID=`pgrep -f '^perl.*${SERVICE}'` - # echo $PID > ${PIDFILE} touch ${LOCKFILE} fi return $RETVAL diff --git a/init.d/freeside-cdrrated.init b/init.d/freeside-cdrrated.init new file mode 100644 index 0000000000..a9359a8bc3 --- /dev/null +++ b/init.d/freeside-cdrrated.init @@ -0,0 +1,124 @@ +#!/bin/bash + +# description: Manage the freeside-cdrrated script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=freeside-cdrrated +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/${SERVICE}.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${QUEUED_USER} ] +then + QUEUED_USER=%%%QUEUED_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + RUNNING=0 + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + ${SERVICE} $QUEUED_USER + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + status -p $PIDFILE +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac diff --git a/init.d/freeside-cdrrewrited.init b/init.d/freeside-cdrrewrited.init index 48b078ee4e..6ed92e4e0d 100644 --- a/init.d/freeside-cdrrewrited.init +++ b/init.d/freeside-cdrrewrited.init @@ -60,13 +60,6 @@ startfunc() { action "Starting ${SERVICE} " /bin/true if [ $RETVAL = 0 ] then - if ! [ -d /var/run/freeside ] - then - mkdir /var/run/freeside - fi - # Don't need to capture PID. It's handled by the service - # PID=`pgrep -f '^perl.*${SERVICE}'` - # echo $PID > ${PIDFILE} touch ${LOCKFILE} fi return $RETVAL diff --git a/init.d/freeside-init b/init.d/freeside-init index 92e3fdfe06..44d5dc43d3 100644 --- a/init.d/freeside-init +++ b/init.d/freeside-init @@ -68,7 +68,7 @@ case "$1" in echo -n "Starting freeside-cdrrewrited: " freeside-cdrrewrited $QUEUED_USER - echo "done." + echo "done." echo -n "Starting freeside-cdrd: " freeside-cdrd $QUEUED_USER diff --git a/init.d/freeside-prepaidd.init b/init.d/freeside-prepaidd.init index af3d9ebe72..824ecf65a0 100644 --- a/init.d/freeside-prepaidd.init +++ b/init.d/freeside-prepaidd.init @@ -60,13 +60,6 @@ startfunc() { action "Starting ${SERVICE} " /bin/true if [ $RETVAL = 0 ] then - if ! [ -d /var/run/freeside ] - then - mkdir /var/run/freeside - fi - # Don't need to capture PID. It's handled by the service - # PID=`pgrep -f '^perl.*${SERVICE}'` - # echo $PID > ${PIDFILE} touch ${LOCKFILE} fi return $RETVAL diff --git a/init.d/freeside-queued.init b/init.d/freeside-queued.init index e6334c1a33..2bfbf911ee 100644 --- a/init.d/freeside-queued.init +++ b/init.d/freeside-queued.init @@ -60,13 +60,6 @@ startfunc() { action "Starting ${SERVICE} " /bin/true if [ $RETVAL = 0 ] then - if ! [ -d /var/run/freeside ] - then - mkdir /var/run/freeside - fi - # Don't need to capture PID. It's handled by the service - # PID=`pgrep -f '^perl.*${SERVICE}'` - # echo $PID > ${PIDFILE} touch ${LOCKFILE} fi return $RETVAL diff --git a/init.d/freeside-selfservice-server.init b/init.d/freeside-selfservice-server.init new file mode 100644 index 0000000000..2c4ce1a477 --- /dev/null +++ b/init.d/freeside-selfservice-server.init @@ -0,0 +1,165 @@ +#!/bin/bash + +# description: Manage the freeside-queued script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=freeside-selfservice-server +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/${SERVICE}.USERMACHINE.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${SELFSERVICE_USER} ] +then + SELFSERVICE_USER=%%%SELFSERVICE_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + if [ -f ${LOCKFILE} ] + then + MACH_RUNNING=0 + MACH_DEAD=0 + MACH_STOPPED=0 + # Loop over machines + for MACHINE in $SELFSERVICE_MACHINES + do + USERMACHINE="${SELFSERVICE_USER}.${MACHINE}" + MYPIDFILE=`echo $PIDFILE | sed "s/USERMACHINE/$USERMACHINE/"` + + if [ -f ${MYPIDFILE} ] + then + PID=`cat $MYPIDFILE` + if ps -p ${PID} > /dev/null + then + MACH_RUNNING=$((MACH_RUNNING + 1)) + else + MACH_DEAD=$((MACH_DEAD + 1)) + fi + else + MACH_STOPPED=$((MACH_STOPPED + 1)) + fi + done + + if [ $MACH_DEAD -gt 0 ] + then + return 1 + fi + if [ $MACH_RUNNING -ge 0 -a $MACH_STOPPED -eq 0 ] + then + return 0 + fi + + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + # Loop over machines + STARTERR=0 + for MACHINE in $SELFSERVICE_MACHINES + do + ${SERVICE} $SELFSERVICE_USER $MACHINE + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL != 0 ] + then + STARTERR=1 + fi + done + if [ $STARTERR -eq 0 ] + then + touch ${LOCKFILE} + return 0 + fi + return 1 + fi +} + +stopfunc() { + if statusfunc + then + for MACHINE in $SELFSERVICE_MACHINES + do + USERMACHINE="${SELFSERVICE_USER}.${MACHINE}" + MYPIDFILE=`echo $PIDFILE | sed "s/USERMACHINE/$USERMACHINE/"` + echo -n "Stopping ${SERVICE} service for $MACHINE" + killproc -p ${MYPIDFILE} + echo + done + rm -f ${LOCKFILE} + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + for MACHINE in $SELFSERVICE_MACHINES + do + USERMACHINE="${SELFSERVICE_USER}.${MACHINE}" + MYPIDFILE=`echo $PIDFILE | sed "s/USERMACHINE/$USERMACHINE/"` + status -p $MYPIDFILE + done +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac diff --git a/init.d/freeside-selfservice-xmlrpcd.init b/init.d/freeside-selfservice-xmlrpcd.init new file mode 100644 index 0000000000..03d8156969 --- /dev/null +++ b/init.d/freeside-selfservice-xmlrpcd.init @@ -0,0 +1,127 @@ +#!/bin/bash + +# description: Manage the freeside-selfservice-xmlrpcd script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=freeside-selfservice-xmlrpcd +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/freeside/${SERVICE}.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${QUEUED_USER} ] +then + QUEUED_USER=%%%QUEUED_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + ${SERVICE} $SELFSERVICE_USER + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + if ! [ -d /var/run/freeside ] + then + mkdir /var/run/freeside + fi + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + status -p $PIDFILE +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac diff --git a/init.d/freeside-sqlradius-radacctd.init b/init.d/freeside-sqlradius-radacctd.init new file mode 100644 index 0000000000..df3c95789b --- /dev/null +++ b/init.d/freeside-sqlradius-radacctd.init @@ -0,0 +1,124 @@ +#!/bin/bash + +# description: Manage the freeside-sqlradius-radacctd script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=freeside-sqlradius-radacctd +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/${SERVICE}.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${QUEUED_USER} ] +then + QUEUED_USER=%%%QUEUED_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + RUNNING=0 + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + ${SERVICE} $QUEUED_USER + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + status -p $PIDFILE +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac diff --git a/init.d/freeside-torrus-srvderive.init b/init.d/freeside-torrus-srvderive.init new file mode 100644 index 0000000000..4ed9b97537 --- /dev/null +++ b/init.d/freeside-torrus-srvderive.init @@ -0,0 +1,124 @@ +#!/bin/bash + +# description: Manage the freeside-torrus-srvderive script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=freeside-torrus-srvderive +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/${SERVICE}.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${QUEUED_USER} ] +then + QUEUED_USER=%%%QUEUED_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + RUNNING=0 + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + ${SERVICE} $QUEUED_USER + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + status -p $PIDFILE +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac diff --git a/init.d/freeside-torrus.init b/init.d/freeside-torrus.init new file mode 100644 index 0000000000..0dea661743 --- /dev/null +++ b/init.d/freeside-torrus.init @@ -0,0 +1,128 @@ +#!/bin/bash + +# description: Manage the torrus script service, SYS-V style +# chkconfig: 2345 10 90 + + +ARG1=${1} +SERVICE=torrus +LOCKFILE=/var/lock/subsys/${SERVICE} +PIDFILE=/var/run/torrus/collector.main_0.pid + + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +if [ -z ${QUEUED_USER} ] +then + QUEUED_USER=%%%QUEUED_USER%%% +fi + +# 0: program is running or service is OK +# 1: program is dead and /var/run pid file exists +# 2: program is dead and /var/lock lock file exists +# 3: program is not running +statusfunc() { + RUNNING=0 + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + ${SERVICE} collector --tree=main + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + if ! [ -d /var/run/torrus ] + then + mkdir /var/run/torrus + fi + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +# echo_status function +echo_statusfunc() { + # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile + echo -n $SERVICE + status -p $PIDFILE +} + +# main loop/case statement +# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. +case $ARG1 in + +start) + # if our parameter is 'start' we should run this + startfunc +;; + +stop) + # if our parameter is 'stop' we should run this + stopfunc +;; + +restart) + # if our parameter is 'restart' we should run this + restartfunc +;; + +status) + # display the status of our service using the echo_statusfunc function + echo_statusfunc +;; + +*) + # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 + echo "Syntax Error... usage: $0 (start|stop|restart|status)" + exit 1 +;; + +# close up that case +esac diff --git a/init.d/freeside-xmlrpcd.init b/init.d/freeside-xmlrpcd.init index 7e42a4a98d..97031eca96 100644 --- a/init.d/freeside-xmlrpcd.init +++ b/init.d/freeside-xmlrpcd.init @@ -64,9 +64,6 @@ startfunc() { then mkdir /var/run/freeside fi - # Don't need to capture PID. It's handled by the service - # PID=`pgrep -f '^perl.*${SERVICE}'` - # echo $PID > ${PIDFILE} touch ${LOCKFILE} fi return $RETVAL From 78f97143d03b5282c9829e85679ab67183bafb35 Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Thu, 9 Oct 2014 14:37:16 -0600 Subject: [PATCH 06/40] Added freeside-selfservice-server init bits to Makefile Conflicts: Makefile --- Makefile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Makefile b/Makefile index 8a343f1e1c..561cbdc758 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,7 @@ INIT_FILE_TORRUS_SRVDERIVE = /etc/init.d/freeside-torrus-srvderive INIT_FILE_SQLRADIUS_RADACCTD = /etc/init.d/freeside-sqlradius_radacctd INIT_FILE_TORRUS = /etc/init.d/freeside-torrus INIT_FILE_SELFSERVICE_XMLRPCD = /etc/init.d/freeside-selfservice-xmlrpcd +INIT_FILE_SELFSERVICE_SERVER = /etc/init.d/freeside-selfservice-server #freebsd #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh @@ -72,6 +73,7 @@ INIT_INSTALL_TORRUS_SRVDERIVE = /sbin/chkconfig freeside-torrus-srvderive on INIT_INSTALL_SQLRADIUS_RADACCTD = /sbin/chkconfig freeside-sqlradius_radacctd on INIT_INSTALL_TORRUS = /sbin/chkconfig freeside-torrus on INIT_INSTALL_SELFSERVICE_XMLRPCD = /sbin/chkconfig freeside-selfservice-xmlrpcd on +INIT_INSTALL_SELFSERVICE_SERVER = /sbin/chkconfig freeside-selfservice-server on #not necessary (freebsd) #INIT_INSTALL = /usr/bin/true @@ -387,6 +389,15 @@ install-init: " ${INIT_FILE_SELFSERVICE_XMLRPCD} ${INIT_INSTALL_SELFSERVICE_XMLRPCD} + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-selfservice-server.init ${INIT_FILE_SELFSERVICE_SERVER} + perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_SELFSERVICE_SERVER} + ${INIT_INSTALL_SELFSERVICE_SERVER} + install-apache: [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true From 9133981f6daaaa0220a35d9a8480574c7688959e Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Wed, 15 Oct 2014 10:29:31 -0600 Subject: [PATCH 07/40] Fixed some shell issues within the install-init target Conflicts: Makefile --- Makefile | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 561cbdc758..c01fb08d60 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,11 @@ DB_PASSWORD= DATASOURCE = DBI:${DB_TYPE}:dbname=freeside #changable now (some things which should go to the others still go to CONF) -FREESIDE_CONF = /usr/local/etc/freeside -FREESIDE_LOG = /usr/local/etc/freeside -FREESIDE_LOCK = /usr/local/etc/freeside -FREESIDE_CACHE = /usr/local/etc/freeside -FREESIDE_EXPORT = /usr/local/etc/freeside +FREESIDE_CONF = /opt/etc/freeside +FREESIDE_LOG = /opt/etc/freeside +FREESIDE_LOCK = /opt/etc/freeside +FREESIDE_CACHE = /opt/etc/freeside +FREESIDE_EXPORT = /opt/etc/freeside MASON_HANDLER = ${FREESIDE_CONF}/handler.pl MASONDATA = ${FREESIDE_CACHE}/masondata @@ -53,7 +53,7 @@ INIT_FILE_CDRREWRITED = /etc/init.d/freeside-cdrrewrited INIT_FILE_CDRD = /etc/init.d/freeside-cdrd INIT_FILE_CDRRATED = /etc/init.d/freeside-cdrrated INIT_FILE_TORRUS_SRVDERIVE = /etc/init.d/freeside-torrus-srvderive -INIT_FILE_SQLRADIUS_RADACCTD = /etc/init.d/freeside-sqlradius_radacctd +INIT_FILE_SQLRADIUS_RADACCTD = /etc/init.d/freeside-sqlradius-radacctd INIT_FILE_TORRUS = /etc/init.d/freeside-torrus INIT_FILE_SELFSERVICE_XMLRPCD = /etc/init.d/freeside-selfservice-xmlrpcd INIT_FILE_SELFSERVICE_SERVER = /etc/init.d/freeside-selfservice-server @@ -70,7 +70,7 @@ INIT_INSTALL_XMLRPCD = /sbin/chkconfig freeside-xmlrpcd on INIT_INSTALL_CDRREWRITED = /sbin/chkconfig freeside-cdrrewrited on INIT_INSTALL_CDRD = /sbin/chkconfig freeside-cdrd on INIT_INSTALL_TORRUS_SRVDERIVE = /sbin/chkconfig freeside-torrus-srvderive on -INIT_INSTALL_SQLRADIUS_RADACCTD = /sbin/chkconfig freeside-sqlradius_radacctd on +INIT_INSTALL_SQLRADIUS_RADACCTD = /sbin/chkconfig freeside-sqlradius-radacctd on INIT_INSTALL_TORRUS = /sbin/chkconfig freeside-torrus on INIT_INSTALL_SELFSERVICE_XMLRPCD = /sbin/chkconfig freeside-selfservice-xmlrpcd on INIT_INSTALL_SELFSERVICE_SERVER = /sbin/chkconfig freeside-selfservice-server on @@ -93,7 +93,7 @@ HTTPD_RESTART = /etc/init.d/apache2 restart #(an include directory, not a file, "Include /etc/apache/conf.d" in httpd.conf) #debian unstable/8.0+, apache2.4 -APACHE_CONF = /etc/apache2/conf-available +APACHE_CONF = /etc/httpd/conf.d #deb (3.1+), apache2 #APACHE_CONF = /etc/apache2/conf.d @@ -353,14 +353,17 @@ install-init: " ${INIT_FILE_CDRRATED} ${INIT_INSTALL_CDRRATED} - [ ${TORRUS_ENABLED} -eq 1 ] && install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus-srvderive.init ${INIT_FILE_TORRUS_SRVDERIVE} - [ ${TORRUS_ENABLED} -eq 1 ] && perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_TORRUS_SRVDERIVE} - [ ${TORRUS_ENABLED} -eq 1 ] && ${INIT_INSTALL_TORRUS_SRVDERIVE} + if [ ${TORRUS_ENABLED} -eq 1 ]; then \ + ( install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus-srvderive.init ${INIT_FILE_TORRUS_SRVDERIVE}; \ + perl -p -i -e "\ + s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ + s/%%%API_USER%%%/${API_USER}/g;\ + s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ + s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ + " ${INIT_FILE_TORRUS_SRVDERIVE} ${INIT_FILE_TORRUS}; \ + ${INIT_INSTALL_TORRUS_SRVDERIVE}; \ + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus.init ${INIT_FILE_TORRUS}; \ + ${INIT_INSTALL_TORRUS}); fi install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-sqlradius-radacctd.init ${INIT_FILE_SQLRADIUS_RADACCTD} perl -p -i -e "\ @@ -371,15 +374,6 @@ install-init: " ${INIT_FILE_SQLRADIUS_RADACCTD} ${INIT_INSTALL_SQLRADIUS_RADACCTD} - [ ${TORRUS_ENABLED} -eq 1 ] && install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus.init ${INIT_FILE_TORRUS} - [ ${TORRUS_ENABLED} -eq 1 ] && perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_TORRUS} - [ ${TORRUS_ENABLED} -eq 1 ] && ${INIT_INSTALL_TORRUS} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-selfservice-xmlrpcd.init ${INIT_FILE_SELFSERVICE_XMLRPCD} perl -p -i -e "\ s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ @@ -398,7 +392,6 @@ install-init: " ${INIT_FILE_SELFSERVICE_SERVER} ${INIT_INSTALL_SELFSERVICE_SERVER} - install-apache: [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true [ -d ${APACHE_CONF} ] && \ From dda82f86f47895048b756b50642285bf13f650f4 Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Wed, 15 Oct 2014 14:30:28 -0600 Subject: [PATCH 08/40] Removed old init.d/freeside script and added Debian-style install for init scripts --- Makefile | 22 +++-- init.d/freeside-init | 195 ------------------------------------------- 2 files changed, 10 insertions(+), 207 deletions(-) delete mode 100644 init.d/freeside-init diff --git a/Makefile b/Makefile index c01fb08d60..0e728bc764 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,6 @@ FREESIDE_DOCUMENT_ROOT = /var/www/freeside #FREESIDE_DOCUMENT_ROOT = /usr/local/apache/htdocs/freeside #deb, redhat, fedora, mandrake, suse, others? -INIT_FILE = /etc/init.d/freeside INIT_FILE_QUEUED = /etc/init.d/freeside-queued INIT_FILE_PREPAIDD = /etc/init.d/freeside-prepaidd INIT_FILE_XMLRPCD = /etc/init.d/freeside-xmlrpcd @@ -63,16 +62,25 @@ INIT_FILE_SELFSERVICE_SERVER = /etc/init.d/freeside-selfservice-server #deb #INIT_INSTALL = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside defaults 23 01 #redhat, fedora -INIT_INSTALL = /sbin/chkconfig freeside on +# INIT_INSTALL_QUEUED = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside-queued defaults 23 01 INIT_INSTALL_QUEUED = /sbin/chkconfig freeside-queued on +# INIT_INSTALL_PREPAIDD = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside-prepaidd defaults 23 01 INIT_INSTALL_PREPAIDD = /sbin/chkconfig freeside-prepaidd on +# INIT_INSTALL_XMLRPCD = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside-xmlrpcd defaults 23 01 INIT_INSTALL_XMLRPCD = /sbin/chkconfig freeside-xmlrpcd on +# INIT_INSTALL_CDRREWRITED = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside-cdrrewrited defaults 23 01 INIT_INSTALL_CDRREWRITED = /sbin/chkconfig freeside-cdrrewrited on +# INIT_INSTALL_CDRD = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside-cdrd defaults 23 01 INIT_INSTALL_CDRD = /sbin/chkconfig freeside-cdrd on +# INIT_INSTALL_TORRUS_SRVDERIVE = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside-torrus-srvderive defaults 23 01 INIT_INSTALL_TORRUS_SRVDERIVE = /sbin/chkconfig freeside-torrus-srvderive on +# INIT_INSTALL_SQLRADIUS_RADACCTD = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside-sqlradius-radacctd defaults 23 01 INIT_INSTALL_SQLRADIUS_RADACCTD = /sbin/chkconfig freeside-sqlradius-radacctd on +# INIT_INSTALL_TORRUS = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside-torrus defaults 23 01 INIT_INSTALL_TORRUS = /sbin/chkconfig freeside-torrus on +# INIT_INSTALL_SELFSERVICE_XMLRPCD = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside-selfservice-xmlrpcd defaults 23 01 INIT_INSTALL_SELFSERVICE_XMLRPCD = /sbin/chkconfig freeside-selfservice-xmlrpcd on +# INIT_INSTALL_SELFSERVICE_SERVER = PATH=$PATH:/sbin /usr/sbin/update-rc.d freeside-selfservice-server defaults 23 01 INIT_INSTALL_SELFSERVICE_SERVER = /sbin/chkconfig freeside-selfservice-server on #not necessary (freebsd) @@ -289,16 +297,6 @@ install-texmf: texhash /usr/local/share/texmf install-init: - #[ -e ${INIT_FILE} ] || install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-init ${INIT_FILE} - perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE} - ${INIT_INSTALL} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-queued.init ${INIT_FILE_QUEUED} perl -p -i -e "\ s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ diff --git a/init.d/freeside-init b/init.d/freeside-init deleted file mode 100644 index 44d5dc43d3..0000000000 --- a/init.d/freeside-init +++ /dev/null @@ -1,195 +0,0 @@ -#!/bin/sh -# -# chkconfig: 345 86 16 -# description: Freeside daemons -# -### BEGIN INIT INFO -# Provides: freeside -# Required-Start: $time $remote_fs -# Required-Stop: $remote_fs -# Should-Start: postgresql mysql -# Should-Stop: postgresql mysql -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Start Freeside daemons at boot time -# Description: Enable Freeside daemons -### END INIT INFO - -QUEUED_USER=%%%QUEUED_USER%%% -API_USER=%%%API_USER%%% - -SELFSERVICE_USER=%%%SELFSERVICE_USER%%% -SELFSERVICE_MACHINES="%%%SELFSERVICE_MACHINES%%%" - -IF=eth0 - -#INSTALLSCRIPT/INSTALLSITEBIN from Makefile.PL -PATH="$PATH:/usr/local/bin" -export PATH - -[ -r /etc/default/freeside ] && . /etc/default/freeside - -case "$1" in - start) - # Start daemons. - - for MACHINE in $SELFSERVICE_MACHINES; do - echo -n "Starting freeside-selfservice-server to $MACHINE: " - freeside-selfservice-server $SELFSERVICE_USER $MACHINE - echo "done." - done - - echo -n "Starting freeside-selfservice-xmlrpcd: " - freeside-selfservice-xmlrpcd $SELFSERVICE_USER - echo "done." - - echo -n "Starting freeside-xmlrpcd: " - freeside-xmlrpcd $API_USER - echo "done." - -# echo -n "Starting freeside-jsonrpcd: " -# freeside-jsonrpcd $API_USER -# echo "done." - - echo -n "Starting freeside-queued: " - #perl -MDBIx::Profile /usr/local/bin/freeside-queued $QUEUED_USER - freeside-queued $QUEUED_USER - #export NYTPROF="file=/usr/local/etc/freeside/nytprof.out" - #PERL5OPT="-d:NYTProf" freeside-queued $QUEUED_USER - echo "done." - - echo -n "Starting freeside-sqlradius-radacctd: " - freeside-sqlradius-radacctd $QUEUED_USER - echo "done." - - echo -n "Starting freeside-prepaidd: " - freeside-prepaidd $QUEUED_USER - echo "done." - - echo -n "Starting freeside-cdrrewrited: " - freeside-cdrrewrited $QUEUED_USER - echo "done." - - echo -n "Starting freeside-cdrd: " - freeside-cdrd $QUEUED_USER - echo "done." - - echo -n "Starting freeside-cdrrated: " - freeside-cdrrated $QUEUED_USER - echo "done." - - if [ -e /usr/local/bin/torrus ]; then - echo -n "Starting torrus collector: " - /usr/local/bin/torrus collector --tree=main - echo "done." - fi - - echo -n "Starting freeside-torrus-srvderive: " - freeside-torrus-srvderive $QUEUED_USER - echo "done." - - #ip=`/sbin/ifconfig $IF | grep 'inet addr:' | cut -d: -f2- | cut -d' ' -f1` - #cp /opt/rt3/etc/RT_SiteConfig.pm.ORIG /opt/rt3/etc/RT_SiteConfig.pm - #perl -pi -e "s/localhost/$ip/" /opt/rt3/etc/RT_SiteConfig.pm - - ;; - stop) - # Stop daemons. - echo -n "Stopping freeside-queued: " - [ -e /var/run/freeside-queued.pid ] && kill `cat /var/run/freeside-queued.pid` - #and - sleep 2; - killall freeside-queued - echo "done." - - if [ -e /var/run/freeside-sqlradius-radacctd.pid ]; then - echo -n "Stopping freeside-sqlradius-radacctd: " - kill `cat /var/run/freeside-sqlradius-radacctd.pid` - echo "done." - fi - - if [ -e /var/run/freeside-prepaidd.pid ]; then - echo -n "Stopping freeside-prepaidd: " - kill `cat /var/run/freeside-prepaidd.pid` - echo "done." - fi - - if [ -e /var/run/freeside-cdrd.pid ]; then - echo -n "Stopping freeside-cdrd: " - kill `cat /var/run/freeside-cdrd.pid` - echo "done." - fi - - if [ -e /var/run/freeside-cdrrewrited.pid ]; then - echo -n "Stopping freeside-cdrrewrited: " - kill `cat /var/run/freeside-cdrrewrited.pid` - echo "done." - fi - - if [ -e /var/run/freeside-cdrrated.pid ]; then - echo -n "Stopping freeside-cdrrated: " - kill `cat /var/run/freeside-cdrrated.pid` - echo "done." - fi - - if [ -e /var/run/freeside/torrus-srvderive.pid ]; then - echo -n "Stopping freeside-torrus-srvderive: " - kill `cat /var/run/freeside/torrus-srvderive.pid` - echo "done." - fi - - if [ -e /var/run/torrus/collector.main_?.pid ]; then - echo -n "Stopping torrus collector: " - kill `cat /var/run/torrus/collector.main_?.pid` - echo "done." - fi - - if [ -e /var/run/freeside/xmlrpcd.pid ]; then - echo -n "Stopping freeside-xmlrpcd: " - kill `cat /var/run/freeside/xmlrpcd.pid` - echo "done." - fi - -# if [ -e /var/run/freeside/jsonrpcd.pid ]; then -# echo -n "Stopping freeside-jsonrpcd: " -# kill `cat /var/run/freeside/jsonrpcd.pid` -# echo "done." -# fi - - if [ -e /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid ] - then - echo -n "Stopping (old) freeside-selfservice-server: " - kill `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid` - rm /var/run/freeside-selfservice-server.$SELFSERVICE_USER.pid - echo "done." - fi - - if [ -z "$SELFSERVICE_MACHINES" ]; then SELFSERVICE_MACHINES='localhost'; fi - for MACHINE in $SELFSERVICE_MACHINES; do - if [ -e /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid ] - then - echo -n "Stopping freeside-selfservice-server to $MACHINE: " - kill `cat /var/run/freeside-selfservice-server.$SELFSERVICE_USER.$MACHINE.pid` - echo "done." - fi - done - - if [ -e /var/run/freeside/selfservice-xmlrpcd.pid ]; then - echo -n "Stopping freeside-selfservice-xmlrpcd: " - kill `cat /var/run/freeside/selfservice-xmlrpcd.pid` - echo "done." - fi - - ;; - - restart) - $0 stop - $0 start - ;; - *) - echo "Usage: freeside {start|stop|restart}" - exit 1 -esac - -exit 0 - From dca2be7e136cc8a3afd178d97478c719aa95a742 Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Fri, 5 Dec 2014 09:28:55 -0700 Subject: [PATCH 09/40] Removed RedHat-specific paths. Added variables for lockfile and pidfile paths. Consolidated redundant code in init.d/freeside-functions and reduced cruft in init scripts. Populated defaults file (/etc/sysconfig/freeside) in Makefile. Fixed assumption of collector_main_0 in torrus init script. --- init.d/freeside-functions | 83 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 init.d/freeside-functions diff --git a/init.d/freeside-functions b/init.d/freeside-functions new file mode 100644 index 0000000000..9a86e9c5b8 --- /dev/null +++ b/init.d/freeside-functions @@ -0,0 +1,83 @@ +#!/bin/bash + +# These functions are used by Freeside's init scripts + +if [ -f /etc/rc.d/init.d/functions ] +then + . /etc/init.d/functions +elif [ -f /lib/lsb/init-functions ] +then + . /lib/lsb/init-functions +fi + +if [ -f %%%FREESIDE_DEFAULTS%%% ] +then + . %%%FREESIDE_DEFAULTS%%% +fi + +PATH="%%%FREESIDE_BIN%%%:$PATH" + +statusfunc() { + RUNNING=0 + if [ -f ${LOCKFILE} ] + then + if [ -f ${PIDFILE} ] + then + PIDFILE=`eval ls $PIDFILE 2> /dev/null` + PID=`cat $PIDFILE` + if ps -p ${PID} > /dev/null + then + return 0 + else + return 1 + fi + fi + fi + return 3 +} + +startfunc() { + if statusfunc + then + action "Already running ${SERVICE} " /bin/false + else + eval "${STARTCOMMAND[@]}" + RETVAL=$? + action "Starting ${SERVICE} " /bin/true + if [ $RETVAL = 0 ] + then + touch ${LOCKFILE} + fi + return $RETVAL + fi +} + +stopfunc() { + if statusfunc + then + echo -n "Stopping ${SERVICE} service" + PIDFILE=`eval ls $PIDFILE 2> /dev/null` + killproc -p ${PIDFILE} + rm -f ${LOCKFILE} + echo + else + action "Service not running" /bin/false + fi +} + +restartfunc() { + stopfunc + startfunc +} + +echo_statusfunc() { + echo -n $SERVICE + EVAL_PIDFILE=`eval ls $PIDFILE > /dev/null` + if [ -n "$EVAL_PIDFILE" ] + then + PIDFILE=$EVAL_PIDFILE + fi + status -p $PIDFILE +} + + From 2401f19b0dae0cdc36ad87b3bd9073f2f1f21cec Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 20 Nov 2014 11:42:22 -0800 Subject: [PATCH 10/40] optimize once_percust condition --- FS/FS/part_event/Condition/once_percust.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/FS/FS/part_event/Condition/once_percust.pm b/FS/FS/part_event/Condition/once_percust.pm index 67767f91b5..2773ca0204 100644 --- a/FS/FS/part_event/Condition/once_percust.pm +++ b/FS/FS/part_event/Condition/once_percust.pm @@ -52,13 +52,13 @@ sub condition_sql { my $pkey = $pkey{$table}; - "0 = ( SELECT COUNT(*) FROM cust_event - WHERE cust_event.eventpart = part_event.eventpart - AND cust_event.tablenum IN ( - SELECT $pkey FROM $table AS once_percust - WHERE once_percust.custnum = cust_main.custnum ) - AND status != 'failed' - ) + "NOT EXISTS ( SELECT 1 FROM cust_event + WHERE cust_event.eventpart = part_event.eventpart + AND cust_event.tablenum IN ( + SELECT $pkey FROM $table AS once_percust + WHERE once_percust.custnum = cust_main.custnum ) + AND status != 'failed' + ) "; } From 3c306637fc7dac23b2034e18bef646ab1273ed63 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 20 Nov 2014 11:44:58 -0800 Subject: [PATCH 11/40] optimize --- FS/FS/TicketSystem/RT_External.pm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/FS/FS/TicketSystem/RT_External.pm b/FS/FS/TicketSystem/RT_External.pm index c2aac2db72..9f07732c71 100644 --- a/FS/FS/TicketSystem/RT_External.pm +++ b/FS/FS/TicketSystem/RT_External.pm @@ -175,12 +175,11 @@ sub _from_customer { } else { - $where = - "AND 0 = ( SELECT COUNT(*) FROM ObjectCustomFieldValues - WHERE ObjectId = Tickets.id - AND ObjectType = 'RT::Ticket' - AND $customfield_sql - ) + $where = " AND NOT EXISTS ( SELECT 1 FROM ObjectCustomFieldValues + WHERE ObjectId = Tickets.id + AND ObjectType = 'RT::Ticket' + AND $customfield_sql + ) "; } From e1b43236a571862fed89f784ca913398db52e36a Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 20 Nov 2014 11:48:06 -0800 Subject: [PATCH 12/40] optimize --- FS/FS/cust_main/Billing_Discount.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/FS/FS/cust_main/Billing_Discount.pm b/FS/FS/cust_main/Billing_Discount.pm index 9dda389f6a..d437740e36 100644 --- a/FS/FS/cust_main/Billing_Discount.pm +++ b/FS/FS/cust_main/Billing_Discount.pm @@ -42,11 +42,13 @@ sub _discount_pkgs_and_bill { push @where, "part_pkg.freq = '1'"; push @where, "(cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0)"; push @where, "(cust_pkg.susp IS NULL OR cust_pkg.susp = 0)"; - push @where, "0<(SELECT count(*) FROM part_pkg_discount - WHERE part_pkg.pkgpart = part_pkg_discount.pkgpart)"; + push @where, "EXISTS( SELECT 1 FROM part_pkg_discount + WHERE part_pkg.pkgpart = part_pkg_discount.pkgpart )"; push @where, - "0=(SELECT count(*) FROM cust_bill_pkg_discount - WHERE cust_bill_pkg.billpkgnum = cust_bill_pkg_discount.billpkgnum)"; + "NOT EXISTS ( + SELECT 1 FROM cust_bill_pkg_discount + WHERE cust_bill_pkg.billpkgnum = cust_bill_pkg_discount.billpkgnu: + )"; my $extra_sql = 'WHERE '. join(' AND ', @where); From f4b884b9daa6dafc0e5a3161a2768cd15d507df4 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 20 Nov 2014 11:55:36 -0800 Subject: [PATCH 13/40] optimize --- FS/FS/Cron/notify.pm | 72 ++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/FS/FS/Cron/notify.pm b/FS/FS/Cron/notify.pm index 1859fcaf77..6d70654296 100644 --- a/FS/FS/Cron/notify.pm +++ b/FS/FS/Cron/notify.pm @@ -28,52 +28,52 @@ sub notify_flat_delay { # select * from cust_pkg where my $where_pkg = <<"END"; - where ( cancel is null or cancel = 0 ) - and ( bill > 0 ) - and - 0 < ( select count(*) from part_pkg - where cust_pkg.pkgpart = part_pkg.pkgpart - and part_pkg.plan = 'flat_delayed' - and 0 < ( select count(*) from part_pkg_option - where part_pkg.pkgpart = part_pkg_option.pkgpart - and part_pkg_option.optionname = 'recur_notify' - and CAST( part_pkg_option.optionvalue AS $integer ) > 0 - and 0 <= ( $time - + CAST( part_pkg_option.optionvalue AS $integer ) - * 86400 - - cust_pkg.bill - ) - and ( cust_pkg.expire is null - or cust_pkg.expire > ( $time - + CAST( part_pkg_option.optionvalue AS $integer ) - * 86400 - ) + WHERE ( cancel IS NULL OR cancel = 0 ) + AND ( bill > 0 ) + AND EXISTS ( + SELECT 1 FROM part_pkg + WHERE cust_pkg.pkgpart = part_pkg.pkgpart + AND part_pkg.plan = 'flat_delayed' + AND EXISTS ( SELECT 1 from part_pkg_option + WHERE part_pkg.pkgpart = part_pkg_option.pkgpart + AND part_pkg_option.optionname = 'recur_notify' + AND CAST( part_pkg_option.optionvalue AS $integer ) > 0 + AND 0 <= ( $time + + CAST( part_pkg_option.optionvalue AS $integer ) + * 86400 + - cust_pkg.bill + ) + AND ( cust_pkg.expire is null + OR cust_pkg.expire > ( $time + + CAST( part_pkg_option.optionvalue AS $integer ) + * 86400 + ) END -#/* and ( cust_pkg.adjourn is null -# or cust_pkg.adjourn > $time +#/* and ( cust_pkg.adjourn is null +# or cust_pkg.adjourn > $time #-- Should notify suspended ones + cast(part_pkg_option.optionvalue as $integer) -# * 86400 +# * 86400 #*/ $where_pkg .= <<"END"; - ) - ) - ) - and - 0 = ( select count(*) from cust_pkg_option - where cust_pkg.pkgnum = cust_pkg_option.pkgnum - and cust_pkg_option.optionname = 'impending_recur_notification_sent' - and CAST( cust_pkg_option.optionvalue AS $integer ) = 1 - ) + ) + ) + ) + AND NOT EXISTS ( + SELECT 1 from cust_pkg_option + WHERE cust_pkg.pkgnum = cust_pkg_option.pkgnum + AND cust_pkg_option.optionname = 'impending_recur_notification_sent' + AND CAST( cust_pkg_option.optionvalue AS $integer ) = 1 + ) END if ($opt{a}) { $where_pkg .= < Date: Thu, 20 Nov 2014 11:57:38 -0800 Subject: [PATCH 14/40] optimize --- FS/FS/Misc/prune.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/FS/FS/Misc/prune.pm b/FS/FS/Misc/prune.pm index 3f0c79d000..ce72405785 100644 --- a/FS/FS/Misc/prune.pm +++ b/FS/FS/Misc/prune.pm @@ -44,34 +44,34 @@ sub prune_applications { my $ccr = < Date: Thu, 20 Nov 2014 12:02:08 -0800 Subject: [PATCH 15/40] optimize --- FS/FS/cust_pkg/Search.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/FS/FS/cust_pkg/Search.pm b/FS/FS/cust_pkg/Search.pm index 9cd1ff0632..aacd387a61 100644 --- a/FS/FS/cust_pkg/Search.pm +++ b/FS/FS/cust_pkg/Search.pm @@ -312,10 +312,10 @@ sub search { if (@report_option) { # this will result in the empty set for the dangling comma case as it should push @where, - map{ "0 < ( SELECT count(*) FROM part_pkg_option - WHERE part_pkg_option.pkgpart = part_pkg.pkgpart - AND optionname = 'report_option_$_' - AND optionvalue = '1' )" + map{ "EXISTS ( SELECT 1 FROM part_pkg_option + WHERE part_pkg_option.pkgpart = part_pkg.pkgpart + AND optionname = 'report_option_$_' + AND optionvalue = '1' )" } @report_option; } @@ -331,10 +331,10 @@ sub search { if (@report_option_any) { # this will result in the empty set for the dangling comma case as it should push @where, ' ( '. join(' OR ', - map{ "0 < ( SELECT count(*) FROM part_pkg_option - WHERE part_pkg_option.pkgpart = part_pkg.pkgpart - AND optionname = 'report_option_$_' - AND optionvalue = '1' )" + map{ "EXISTS ( SELECT 1 FROM part_pkg_option + WHERE part_pkg_option.pkgpart = part_pkg.pkgpart + AND optionname = 'report_option_$_' + AND optionvalue = '1' )" } @report_option_any ). ' ) '; } From 937f9a50006eee415dc79ed2972a7297a5fb7d96 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 20 Nov 2014 12:02:14 -0800 Subject: [PATCH 16/40] optimize --- FS/FS/tax_rate.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm index a6da3d1113..ec3bb12b61 100644 --- a/FS/FS/tax_rate.pm +++ b/FS/FS/tax_rate.pm @@ -1366,11 +1366,14 @@ sub _remember_tax_products { my ( $imported, $last, $min_sec ) = _progressbar_foo(); - my $extra_sql = "WHERE taxproductnum IS NOT NULL OR ". - "0 < ( SELECT count(*) from part_pkg_option WHERE ". - " part_pkg_option.pkgpart = part_pkg.pkgpart AND ". - " optionname LIKE 'usage_taxproductnum_%' AND ". - " optionvalue != '' )"; + my $extra_sql = " + WHERE taxproductnum IS NOT NULL + OR EXISTS ( SELECT 1 from part_pkg_option + WHERE part_pkg_option.pkgpart = part_pkg.pkgpart + AND optionname LIKE 'usage_taxproductnum_%' + AND optionvalue != '' + ) + "; my @items = qsearch( { table => 'part_pkg', select => 'DISTINCT pkgpart,taxproductnum', hashref => {}, From 86c7706e58b893a184d291ad8517cb96fab94498 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 27 Nov 2014 20:49:54 -0500 Subject: [PATCH 17/40] Ticket 29048 add accountcodes to cx3 format --- FS/FS/cdr/cx3.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/FS/FS/cdr/cx3.pm b/FS/FS/cdr/cx3.pm index e5b5f0350d..8c848078a1 100644 --- a/FS/FS/cdr/cx3.pm +++ b/FS/FS/cdr/cx3.pm @@ -43,6 +43,7 @@ sub { my ($cdr, $duration) = @_; }, #duration skip(1), # unknown 'disposition', # call status + 'accountcode', # AccountCode ], ); From 7d29b3a70dd1fa4bf8c4805fd3789524bfcb9802 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 2 Dec 2014 15:43:34 -0800 Subject: [PATCH 18/40] when address standardization returns a censustract, don't try to look it up through FFIEC also, #32459 --- httemplate/edit/cust_main/bottomfixup.js | 11 ++-- httemplate/elements/location.html | 52 ++++++++++++------- httemplate/elements/standardize_locations.js | 5 +- .../misc/xmlhttp-address_standardize.html | 4 ++ 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/httemplate/edit/cust_main/bottomfixup.js b/httemplate/edit/cust_main/bottomfixup.js index 8aef1e72c8..6a9deb92a4 100644 --- a/httemplate/edit/cust_main/bottomfixup.js +++ b/httemplate/edit/cust_main/bottomfixup.js @@ -100,14 +100,13 @@ function copyelement(from, to) { //alert(from + " (" + from.type + "): " + to.name + " => " + to.value); } -% # the value in pre+'censustract' is the confirmed censustract; if it's set, -% # and the user hasn't changed it manually, skip this +% # the value in pre+'censustract' is the confirmed censustract (either from +% # the previous saved record, or from address standardization (if the backend +% # supports it), or from an aborted previous submit. only need to reconfirm +% # if it's empty. function confirm_censustract(pre) { var cf = document.CustomerForm; - if ( cf.elements[pre+'censustract'].value == '' || - cf.elements[pre+'enter_censustract'].value != - cf.elements[pre+'censustract'].value ) - { + if ( cf.elements[pre+'censustract'].value == '' ) { var address_info = form_address_info(); address_info[pre+'latitude'] = cf.elements[pre+'latitude'].value; address_info[pre+'longitude'] = cf.elements[pre+'longitude'].value; diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html index 5cdc424a74..214a7d5f2a 100644 --- a/httemplate/elements/location.html +++ b/httemplate/elements/location.html @@ -59,12 +59,7 @@ % } else { - - + <& hidden.html, field => $pre.'locationname', value => $object->get('locationname') &> % } @@ -102,10 +97,7 @@ % } else { # alternate format - +<& hidden.html, field => $pre.'address2', value => $object->get('address2') &> <<%$th%> ALIGN="right">Unit type and #> @@ -227,14 +219,14 @@ % } else { % foreach (qw(latitude longitude)) { - +<& hidden.html, field => $pre.$_, value => $object->get($_) &> % } % } - - - - - +% +% foreach (qw(coord_auto geocode censustract censusyear)) { + <& hidden.html, field => $pre.$_, value => $object->get($_) &> +% } +% % if ( $opt{enable_censustract} ) { Census tract @@ -259,7 +251,7 @@ % } else { - + <& hidden.html, field => $pre.'district', value => $object->get('district') &> % } %# For address standardization: @@ -267,11 +259,11 @@ %# to re-standardize % foreach (qw(address1 city state country zip latitude % longitude censustract district addr_clean) ) { - +<& hidden.html, field => 'old_'.$pre.$_, value => $object->get($_) &> % } %# Placeholders - - +<& hidden.html, field => $pre.'cachenum', value => '' &> +<& hidden.html, field => $pre.'addr_clean', value => '' &> diff --git a/httemplate/elements/standardize_locations.js b/httemplate/elements/standardize_locations.js index a4f13d78db..ff7183b26a 100644 --- a/httemplate/elements/standardize_locations.js +++ b/httemplate/elements/standardize_locations.js @@ -279,10 +279,7 @@ function setselect(el, value) { function confirm_censustract() { % if ( FS::Conf->new->exists('cust_main-require_censustract') ) { var form = document.<% $formname %>; - // this is the existing/confirmed censustract, not the manually entered one - if ( form.elements['censustract'].value == '' || - form.elements['censustract'].value != - form.elements['enter_censustract'].value ) { + if ( form.elements['censustract'].value == '' ) { var address_info = form_address_info(); address_info['latitude'] = form.elements['latitude'].value; address_info['longitude'] = form.elements['longitude'].value; diff --git a/httemplate/misc/xmlhttp-address_standardize.html b/httemplate/misc/xmlhttp-address_standardize.html index 618265364e..d0255a02a7 100644 --- a/httemplate/misc/xmlhttp-address_standardize.html +++ b/httemplate/misc/xmlhttp-address_standardize.html @@ -43,6 +43,10 @@ last if !$all_same; } + $all_same = 0 if ( length( $old{$pre.'censustract'} ) > 0 && + length( $new{$pre.'censustract'} ) > 0 && + $old{$pre.'censustract'} ne $new{$pre.'censustract'} ); + $all_same = 0 if $new{$pre.'error'}; } From 019979c0e5e9db19347777a46fc2f4516f63374d Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 2 Dec 2014 20:08:00 -0800 Subject: [PATCH 19/40] fix censustract lookup for new FFIEC interface, #32459 --- FS/FS/Misc/Geo.pm | 127 +++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 86 deletions(-) diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm index a387aca9d4..dbc383a146 100644 --- a/FS/FS/Misc/Geo.pm +++ b/FS/FS/Misc/Geo.pm @@ -6,8 +6,7 @@ use vars qw( $DEBUG @EXPORT_OK $conf ); use LWP::UserAgent; use HTTP::Request; use HTTP::Request::Common qw( GET POST ); -use HTTP::Cookies; -use HTML::TokeParser; +use JSON; use URI::Escape 3.31; use Data::Dumper; use FS::Conf; @@ -29,7 +28,7 @@ FS::Misc::Geo - routines to fetch geographic information =over 4 -=item get_censustract LOCATION YEAR +=item get_censustract_ffiec LOCATION YEAR Given a location hash (see L) and a census map year, returns a census tract code (consisting of state, county, and tract @@ -41,6 +40,7 @@ sub get_censustract_ffiec { my $class = shift; my $location = shift; my $year = shift; + $year ||= 2013; if ( length($location->{country}) and uc($location->{country}) ne 'US' ) { return ''; @@ -48,102 +48,57 @@ sub get_censustract_ffiec { warn Dumper($location, $year) if $DEBUG; - my $url = 'http://www.ffiec.gov/Geocode/default.aspx'; - - my $return = {}; - my $error = ''; + # the old FFIEC geocoding service was shut down December 1, 2014. + # welcome to the future. + my $url = 'https://geomap.ffiec.gov/FFIECGeocMap/GeocodeMap1.aspx/GetGeocodeData'; + # build the single-line query + my $single_line = join(', ', $location->{address1}, + $location->{city}, + $location->{state} + ); + my $hashref = { sSingleLine => $single_line, iCensusYear => $year }; + my $request = POST( $url, + 'Content-Type' => 'application/json; charset=utf-8', + 'Accept' => 'application/json', + 'Content' => encode_json($hashref) + ); - my $ua = new LWP::UserAgent('cookie_jar' => HTTP::Cookies->new); - my $res = $ua->request( GET( $url ) ); + my $ua = new LWP::UserAgent; + my $res = $ua->request( $request ); warn $res->as_string if $DEBUG > 2; if (!$res->is_success) { - $error = $res->message; - - } else { - - my $content = $res->content; - - my $p = new HTML::TokeParser \$content; - my $viewstate; - my $eventvalidation; - while (my $token = $p->get_tag('input') ) { - if ($token->[1]->{name} eq '__VIEWSTATE') { - $viewstate = $token->[1]->{value}; - } - if ($token->[1]->{name} eq '__EVENTVALIDATION') { - $eventvalidation = $token->[1]->{value}; - } - last if $viewstate && $eventvalidation; - } - - if (!$viewstate or !$eventvalidation ) { - - $error = "either no __VIEWSTATE or __EVENTVALIDATION found"; + die "Census tract lookup error: ".$res->message; - } else { - - my($zip5, $zip4) = split('-',$location->{zip}); - - $year ||= '2013'; - my @ffiec_args = ( - __VIEWSTATE => $viewstate, - __EVENTVALIDATION => $eventvalidation, - __VIEWSTATEENCRYPTED => '', - ddlbYear => $year, - txtAddress => $location->{address1}, - txtCity => $location->{city}, - ddlbState => $location->{state}, - txtZipCode => $zip5, - btnSearch => 'Search', - ); - warn join("\n", @ffiec_args ) - if $DEBUG > 1; - - push @{ $ua->requests_redirectable }, 'POST'; - $res = $ua->request( POST( $url, \@ffiec_args ) ); - warn $res->as_string - if $DEBUG > 2; - - unless ($res->code eq '200') { - - $error = $res->message; - - } else { - - my @id = qw( MSACode StateCode CountyCode TractCode ); - $content = $res->content; - warn $res->content if $DEBUG > 2; - $p = new HTML::TokeParser \$content; - my $prefix = 'UcGeoResult11_lb'; - my $compare = - sub { my $t=shift; scalar( grep { lc($t) eq lc("$prefix$_")} @id ) }; - - while (my $token = $p->get_tag('span') ) { - next unless ( $token->[1]->{id} && &$compare( $token->[1]->{id} ) ); - $token->[1]->{id} =~ /^$prefix(\w+)$/; - $return->{lc($1)} = $p->get_trimmed_text("/span"); - } - - unless ( $return->{tractcode} ) { - warn "$error: $content ". Dumper($return) if $DEBUG; - $error = "No census tract found"; - } - $return->{tractcode} .= ' ' - unless $error || $JSON::VERSION >= 2; #broken JSON 1 workaround + } - } #unless ($res->code eq '200') + local $@; + my $content = eval { decode_json($res->content) }; + die "Census tract JSON error: $@\n" if $@; - } #unless ($viewstate) + if ( !exists $content->{d}->{sStatus} ) { + die "Census tract response is missing a status indicator.\nThis is an FFIEC problem.\n"; + } + if ( $content->{d}->{sStatus} eq 'Y' ) { + # success + # this also contains the (partial) standardized address, correct zip + # code, coordinates, etc., and we could get all of them, but right now + # we only want the census tract + my $tract = join('', $content->{d}->{sStateCode}, + $content->{d}->{sCountyCode}, + $content->{d}->{sTractCode}); + return $tract; - } #unless ($res->code eq '200') + } else { - die "FFIEC Geocoding error: $error\n" if $error; + my $error = $content->{d}->{sMsg} + || 'FFIEC lookup failed, but with no status message.'; + die "$error\n"; - $return->{'statecode'} . $return->{'countycode'} . $return->{'tractcode'}; + } } #sub get_district_methods { From 2b9de94cafad5ea0d439ce9be9d1ca26095154bb Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Wed, 3 Dec 2014 12:41:12 -0500 Subject: [PATCH 20/40] Ticket #31495 Earthlink CDR --- FS/FS/cdr/earthlink.pm | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 FS/FS/cdr/earthlink.pm diff --git a/FS/FS/cdr/earthlink.pm b/FS/FS/cdr/earthlink.pm new file mode 100644 index 0000000000..0421ef9359 --- /dev/null +++ b/FS/FS/cdr/earthlink.pm @@ -0,0 +1,44 @@ +package FS::cdr::earthlink; + +use strict; +use vars qw( @ISA %info $date); +use Time::Local; +use FS::cdr qw(_cdr_date_parser_maker _cdr_min_parser_maker); +use Date::Parse; + +@ISA = qw(FS::cdr); + +%info = ( + 'name' => 'Earthlink', + 'weight' => 120, + 'header' => 1, + 'import_fields' => [ + + 'accountcode', #Account number + skip(2), #SERVICE LOC / BILL NUMBER + sub { my($cdr, $date) = @_; + + }, #date + sub { my($cdr, $time) = @_; + + my $datetime = $date. " ". $time; + $cdr->set('startdate', $datetime ); + }, #time + sub { my($cdr, $src) = @_; + $src =~ s/\D//g; + $cdr->set('src', $src); + }, #ORIG NUMBER + skip(2), #ORIG CITY/ORIGSTATE + sub { my($cdr, $dst) = @_; + $dst =~ s/\D//g; + $cdr->set('dst', $dst); + }, #TERM NUMBER + skip(2), #TERM CITY / TERM STATE + _cdr_min_parser_maker, #MINUTES + ], +); + +sub skip { map {''} (1..$_[0]) } + +1; + From 719a5cbb1d8315f7b1d583e389b6493476dd49a3 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 4 Dec 2014 09:51:07 -0500 Subject: [PATCH 21/40] Ticket #32088 Thinktel integration --- bin/cdr-thinktel.import | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 bin/cdr-thinktel.import diff --git a/bin/cdr-thinktel.import b/bin/cdr-thinktel.import old mode 100644 new mode 100755 index ccbd78c39f..9afd34cc5c --- a/bin/cdr-thinktel.import +++ b/bin/cdr-thinktel.import @@ -52,7 +52,8 @@ $ftp->login($login, $password) warn "Retrieving directory listing\n" if $opt_v; $ftp->cwd('/'); -my @files = $ftp->ls(); +my @files = grep { $_ =~ /MetaSwitch/ } $ftp->ls(); + warn scalar(@files)." CDR files found.\n" if $opt_v; # apply date range if ( $opt_a ) { From 7812b67cc4a83d55958baf1a912385145c03778c Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 27 Nov 2014 17:30:13 -0500 Subject: [PATCH 22/40] Ticket #32382 Vss format fixes --- FS/FS/cdr/vss.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FS/FS/cdr/vss.pm b/FS/FS/cdr/vss.pm index 8b745a8e7a..1597d5bed1 100644 --- a/FS/FS/cdr/vss.pm +++ b/FS/FS/cdr/vss.pm @@ -10,6 +10,8 @@ use FS::cdr qw(_cdr_date_parser_maker); %info = ( 'name' => 'VSS', 'weight' => 120, + 'header' => 1, + 'header' => 1, 'import_fields' => [ From 120092c4bcc1fcf50cda99108e15079fc274d9c0 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 10:35:56 -0800 Subject: [PATCH 23/40] html nits --- httemplate/misc/suspend_cust.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/httemplate/misc/suspend_cust.html b/httemplate/misc/suspend_cust.html index 3a49e136dd..83d974300f 100644 --- a/httemplate/misc/suspend_cust.html +++ b/httemplate/misc/suspend_cust.html @@ -7,8 +7,7 @@

<% mt('Suspend this customer?') |h %> - +
@@ -36,8 +35,7 @@ toggle(false); - +
<& /elements/tr-select-reason.html, 'field' => 'reasonnum', 'reason_class' => 'S', From 3d8d5b98683bab81c8d659856d939a95898b5764 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 10:36:12 -0800 Subject: [PATCH 24/40] contact reports --- httemplate/elements/menu.html | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index b4ecdc490f..03ce201859 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -89,10 +89,16 @@ #XXX Active tickets not assigned to a customer -tie my %report_prospects, 'Tie::IxHash', - 'List prospects' => [ $fsurl. 'search/prospect_main.html', '' ], - 'Advanced prospect reports' => [ $fsurl. 'search/report_prospect_main.html', '' ], -; +tie my %report_prospects, 'Tie::IxHash'; +if ( $curuser->access_right('List prospects') ) { + $report_prospects{'List prospects'} = [ $fsurl. 'search/prospect_main.html', '' ]; + $report_prospects{'Advanced prospect reports'} = [ $fsurl. 'search/report_prospect_main.html', '' ]; +} +$report_prospects{'separator'} = '' + if $curuser->access_right('List prospects') + && $curuser->access_right('List contacts'); +$report_prospects{'Prospect contacts'} = [ $fsurl. 'search/report_contact.html?link=prospect_main', '' ] + if $curuser->access_right('List contacts'); tie my %report_quotations, 'Tie::IxHash', 'List quotations' => [ $fsurl. 'search/quotation.html', '' ], @@ -118,6 +124,10 @@ $report_customers{'Signup date report'} = [ $fsurl. 'graph/report_signupdate.html', 'Signup date report (by date of signup)' ]; $report_customers{'Advanced customer reports'} = [ $fsurl. 'search/report_cust_main.html', 'by status, signup date, agent, etc.' ] if $curuser->access_right('Advanced customer search'); +if ( $curuser->access_right('List contacts') ) { + $report_customers{'separator'} = ''; + $report_customers{'Customer contacts'} = [ $fsurl. 'search/report_contact.html?link=cust_main' ]; +} tie my %report_invoices_open, 'Tie::IxHash', 'All open invoices' => [ $fsurl.'search/cust_bill.html?OPEN_date', 'All invoices with an unpaid balance' ], @@ -399,11 +409,13 @@ tie my %report_menu, 'Tie::IxHash'; $report_menu{'Prospects'} = [ \%report_prospects, 'Prospect reports' ] - if $curuser->access_right('List prospects'); + if $curuser->access_right('List prospects') + || $curuser->access_right('List contacts'); $report_menu{'Quotations'} = [ \%report_quotations, 'Quotation reports' ] if $curuser->access_right('List quotations'); $report_menu{'Customers'} = [ \%report_customers, 'Customer reports' ] - if $curuser->access_right('List customers'); + if $curuser->access_right('List customers') + || $curuser->access_right('List contacts'); $report_menu{'Invoices'} = [ \%report_invoices, 'Invoice reports' ] if $curuser->access_right('List invoices'); $report_menu{'Discounts'} = [ \%report_discounts, 'Discount reports' ] From e74b6ed43bb51af584383567b29da796744ddd5d Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 10:36:58 -0800 Subject: [PATCH 25/40] fix invoice sorting by package category, RT#31272 --- FS/FS/Template_Mixin.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 2fae4643d8..05972c0b76 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -2153,9 +2153,9 @@ sub _items_sections { } else { $section->{'category'} = $sectionname; $section->{'description'} = &{ $escape }($sectionname); - if ( _pkg_category($_) ) { - $section->{'sort_weight'} = _pkg_category($_)->weight; - if ( _pkg_category($_)->condense ) { + if ( _pkg_category($sectionname) ) { + $section->{'sort_weight'} = _pkg_category($sectionname)->weight; + if ( _pkg_category($sectionname)->condense ) { $section = { %$section, $self->_condense_section($opt{format}) }; } } From 6f5de2ceadb172d2a21384f58ccab58be73d1983 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 10:37:14 -0800 Subject: [PATCH 26/40] html nits --- httemplate/misc/cancel_cust.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/httemplate/misc/cancel_cust.html b/httemplate/misc/cancel_cust.html index e4bfdba767..85367026c9 100644 --- a/httemplate/misc/cancel_cust.html +++ b/httemplate/misc/cancel_cust.html @@ -7,8 +7,7 @@

<% mt('Permanently delete all services and cancel this customer?') |h %> -

+
@@ -44,8 +43,7 @@ <% mt($ban) |h %> % } - +
<& /elements/tr-select-reason.html, 'field' => 'reasonnum', 'reason_class' => 'C', From e9968f2f6eae6d0022b959f1c0b434618f0b16d4 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 10:50:40 -0800 Subject: [PATCH 27/40] eliminiate spurious warnings: Argument "" isn't numeric in addition (+) --- FS/FS/Template_Mixin.pm | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index 05972c0b76..b153d3114d 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -703,10 +703,10 @@ sub print_generic { # cares about application dates. We want to know the sum of all # _top-level transactions_ dated before the last invoice. my @sql = ( - 'SELECT SUM(charged) FROM cust_bill WHERE _date <= ? AND custnum = ?', - 'SELECT -1*SUM(amount) FROM cust_credit WHERE _date <= ? AND custnum = ?', - 'SELECT -1*SUM(paid) FROM cust_pay WHERE _date <= ? AND custnum = ?', - 'SELECT SUM(refund) FROM cust_refund WHERE _date <= ? AND custnum = ?', + "SELECT COALESCE( SUM(charged), 0 ) FROM cust_bill", + "SELECT -1 * COALESCE( SUM(amount), 0 ) FROM cust_credit", + "SELECT -1 * COALESCE( SUM(paid), 0 ) FROM cust_pay", + "SELECT COALESCE( SUM(refund), 0 ) FROM cust_refund", ); # the customer's current balance immediately after generating the last @@ -714,13 +714,11 @@ sub print_generic { my $last_bill_balance = $last_bill->charged; foreach (@sql) { - #warn "$_\n"; my $delta = FS::Record->scalar_sql( - $_, + "$_ WHERE _date <= ? AND custnum = ?", $last_bill->_date - 1, $self->custnum, ); - #warn "$delta\n"; $last_bill_balance += $delta; } @@ -2729,7 +2727,7 @@ sub _items_cust_bill_pkg { 'pkgnum' => $cust_bill_pkg->pkgpart, #so it displays in Ref 'description' => $description, 'amount' => sprintf("%.2f", $cust_bill_pkg->setup), - 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitsetup), + 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitsetup), 'quantity' => $cust_bill_pkg->quantity, 'preref_html' => ( $opt{preref_callback} ? &{ $opt{preref_callback} }( $cust_bill_pkg ) @@ -2742,9 +2740,9 @@ sub _items_cust_bill_pkg { 'pkgnum' => $cust_bill_pkg->pkgpart, #so it displays in Ref 'description' => "$desc (". $cust_bill_pkg->part_pkg->freq_pretty.")", 'amount' => sprintf("%.2f", $cust_bill_pkg->recur), - 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitrecur), + 'unit_amount' => sprintf("%.2f", $cust_bill_pkg->unitrecur), 'quantity' => $cust_bill_pkg->quantity, - 'preref_html' => ( $opt{preref_callback} + 'preref_html' => ( $opt{preref_callback} ? &{ $opt{preref_callback} }( $cust_bill_pkg ) : '' ), From c5a36fcd6a60edc180e210b625ab80c97d1b7d82 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Thu, 4 Dec 2014 12:58:51 -0800 Subject: [PATCH 28/40] fix census tract format, #32499, etc. --- FS/FS/Report/FCC_477.pm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/FS/FS/Report/FCC_477.pm b/FS/FS/Report/FCC_477.pm index f5d6a06ecc..20d402d7d1 100644 --- a/FS/FS/Report/FCC_477.pm +++ b/FS/FS/Report/FCC_477.pm @@ -355,8 +355,10 @@ sub fbs_sql { my $agentnum = $opt{agentnum}; my $q = $opt{ignore_quantity} ? '1' : 'COALESCE(cust_pkg.quantity, 1)'; + my $censustract = "replace(cust_location.censustract, '.', '')"; + my @select = ( - 'cust_location.censustract', + "$censustract AS censustract", 'technology', 'broadband_downstream', 'broadband_upstream', @@ -381,8 +383,7 @@ sub fbs_sql { is_fixed_broadband() ); push @where, "cust_main.agentnum = $agentnum" if $agentnum; - my $group_by = 'cust_location.censustract, technology, '. - 'broadband_downstream, broadband_upstream '; + my $group_by = "$censustract, technology, broadband_downstream, broadband_upstream "; my $order_by = $group_by; "SELECT ".join(', ', @select) . " @@ -400,9 +401,10 @@ sub fvs_sql { my $date = $opt{date} || time; my $agentnum = $opt{agentnum}; my $q = $opt{ignore_quantity} ? '1' : 'COALESCE(cust_pkg.quantity, 1)'; + my $censustract = "replace(cust_location.censustract, '.', '')"; my @select = ( - 'cust_location.censustract', + "$censustract AS censustract", # VoIP indicator (0 for non-VoIP, 1 for VoIP) 'COALESCE(is_voip, 0)', # number of lines/subscriptions @@ -426,7 +428,7 @@ sub fvs_sql { "(is_voip = 1 OR is_phone = 1)", ); push @where, "cust_main.agentnum = $agentnum" if $agentnum; - my $group_by = 'cust_location.censustract, COALESCE(is_voip, 0)'; + my $group_by = "$censustract, COALESCE(is_voip, 0)"; my $order_by = $group_by; "SELECT ".join(', ', @select) . " From bd3255b502749bacb02f37eb2995da7b0b9337b1 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 14:47:49 -0800 Subject: [PATCH 29/40] backdate credits, RT#32320 --- FS/FS/AccessRight.pm | 2 ++ FS/FS/access_right.pm | 1 + httemplate/edit/cust_credit.cgi | 20 +++++++++---- httemplate/edit/cust_pay.cgi | 39 +++++++++---------------- httemplate/edit/process/cust_credit.cgi | 15 ++++++++-- httemplate/elements/tr-fixed-date.html | 10 +++++-- 6 files changed, 52 insertions(+), 35 deletions(-) diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index 92cede6a5b..4a1f89aa0e 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -217,6 +217,7 @@ tie my %rights, 'Tie::IxHash', ### 'Customer credit and refund rights' => [ 'Post credit', + { rightname=>'Backdate credit', desc=>'Enable credits to be posted for days other than today.' }, 'Credit line items', #NEWNEWNEW 'Apply credit', #NEWNEW { rightname=>'Unapply credit', desc=>'Enable "unapplication" of unclosed credits.' }, #aka unapplycredits @@ -444,6 +445,7 @@ sub default_superuser_rights { 'Credit card void', 'Echeck void', 'Void invoices',#people are overusing this when credits are more appropriate + 'Backdate credit', ); no warnings 'uninitialized'; diff --git a/FS/FS/access_right.pm b/FS/FS/access_right.pm index ee0c494ae3..e5a5781a94 100644 --- a/FS/FS/access_right.pm +++ b/FS/FS/access_right.pm @@ -249,6 +249,7 @@ sub _upgrade_data { # class method 'Edit package definition costs' => 'View package definition costs', 'List prospects' => 'List contacts', 'List customers' => 'List contacts', + 'Backdate payment' => 'Backdate credit', ); # foreach my $old_acl ( keys %onetime ) { diff --git a/httemplate/edit/cust_credit.cgi b/httemplate/edit/cust_credit.cgi index 29801efefa..18416c5fbc 100755 --- a/httemplate/edit/cust_credit.cgi +++ b/httemplate/edit/cust_credit.cgi @@ -6,15 +6,25 @@ - <% ntable("#cccccc", 2) %> - - - - +% my %date_args = ( +% 'name' => '_date', +% 'label' => emt('Date'), +% 'value' => $_date, +% 'format' => $date_format. ' %r', +% ); +% if ( $FS::CurrentUser::CurrentUser->access_right('Backdate credit') ) { + + <& /elements/tr-input-date-field.html, \%date_args &> + +% } else { + + <& /elements/tr-fixed-date.html, \%date_args &> + +% } diff --git a/httemplate/edit/cust_pay.cgi b/httemplate/edit/cust_pay.cgi index ec7391b20e..888335fbb5 100755 --- a/httemplate/edit/cust_pay.cgi +++ b/httemplate/edit/cust_pay.cgi @@ -23,37 +23,26 @@ <% mt('Payment') |h %> <% ntable("#cccccc", 2) %> +% my %date_args = ( +% 'name' => '_date', +% 'label' => emt('Date'), +% 'value' => $_date, +% 'format' => $date_format. ' %r', +% 'colspan' => 2, +% ); % if ( $FS::CurrentUser::CurrentUser->access_right('Backdate payment') ) { - - - - - -% } -% else { - - - - + <& /elements/tr-input-date-field.html, \%date_args &> + +% } else { + + <& /elements/tr-fixed-date.html, \%date_args &> + % } - - + % if ( $conf->exists('part_pkg-term_discounts') ) { diff --git a/httemplate/edit/process/cust_credit.cgi b/httemplate/edit/process/cust_credit.cgi index e442d7fa65..39c6f19972 100755 --- a/httemplate/edit/process/cust_credit.cgi +++ b/httemplate/edit/process/cust_credit.cgi @@ -42,11 +42,20 @@ if (!$reasonnum) { } $cgi->param('reasonnum', $reasonnum) unless $error; +my $_date; +if ( $FS::CurrentUser::CurrentUser->access_right('Backdate credit') ) { + $_date = parse_datetime($cgi->param('_date')); +} +else { + $_date = time; +} + +my @fields = grep { $_ ne '_date' } fields('cust_credit'); + unless ($error) { my $new = new FS::cust_credit ( { - map { - $_, scalar($cgi->param($_)); - } fields('cust_credit') + _date => $_date, + map { $_ => scalar($cgi->param($_)) } @fields } ); $error = $new->insert; } diff --git a/httemplate/elements/tr-fixed-date.html b/httemplate/elements/tr-fixed-date.html index 716e5ceb82..ef599796de 100644 --- a/httemplate/elements/tr-fixed-date.html +++ b/httemplate/elements/tr-fixed-date.html @@ -1,12 +1,18 @@ <% include('tr-fixed.html', %opt ) %> <%init> -my %opt = @_; +my %opt; +if ( ref($_[0]) ) { + my $hashref = shift; + %opt = %$hashref; +} else { + %opt = @_; +} my $value = $opt{'curr_value'} || $opt{'value'}; my $conf = new FS::Conf; -my $date_format = $conf->config('date_format') || '%m/%d/%Y'; +my $date_format = $opt{'format'} || $conf->config('date_format') || '%m/%d/%Y'; $opt{'formatted_value'} = time2str($date_format, $value); From 3e931f2fc016908e10e0f6ebba0b3d79e4a99d99 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 16:09:10 -0800 Subject: [PATCH 30/40] fix to be how we always search for un-disabled things, RT#32230 --- FS/FS/part_export/send_email.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/FS/FS/part_export/send_email.pm b/FS/FS/part_export/send_email.pm index 3e51422609..537a562bb2 100644 --- a/FS/FS/part_export/send_email.pm +++ b/FS/FS/part_export/send_email.pm @@ -17,13 +17,13 @@ my %template_select = ( $templates{$_[0]}; }, option_values => sub { - %templates = (0 => '', + %templates = ( + 0 => '', map { $_->msgnum, $_->msgname } - qsearch({ table => 'msg_template', - hashref => { disabled => { 'op' => '!=', - 'value' => 1 }}, - order_by => 'ORDER BY msgnum ASC' - }) + qsearch({ table => 'msg_template', + hashref => { disabled => '', }, + order_by => 'ORDER BY msgnum ASC' + }) ); sort keys (%templates); }, From 6059c343049d586aaccf0d11be2ca4b9c6d3c824 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Fri, 5 Dec 2014 09:53:02 -0500 Subject: [PATCH 31/40] Fix incorrectly uploaded code for vss 32382 --- FS/FS/cdr/vss.pm | 3 --- 1 file changed, 3 deletions(-) diff --git a/FS/FS/cdr/vss.pm b/FS/FS/cdr/vss.pm index 1597d5bed1..6fc647aad3 100644 --- a/FS/FS/cdr/vss.pm +++ b/FS/FS/cdr/vss.pm @@ -10,8 +10,6 @@ use FS::cdr qw(_cdr_date_parser_maker); %info = ( 'name' => 'VSS', 'weight' => 120, - 'header' => 1, - 'header' => 1, 'import_fields' => [ @@ -34,4 +32,3 @@ use FS::cdr qw(_cdr_date_parser_maker); sub skip { map {''} (1..$_[0]) } 1; - From 6331777c7fdc4438576631626a151a7b8da9d98d Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Fri, 5 Dec 2014 08:07:28 -0800 Subject: [PATCH 32/40] fix invoice viewing --- FS/FS/Template_Mixin.pm | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index b153d3114d..346e78167c 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -702,12 +702,13 @@ sub print_generic { # "balance_date_range" unfortunately is unsuitable for this, since it # cares about application dates. We want to know the sum of all # _top-level transactions_ dated before the last invoice. - my @sql = ( - "SELECT COALESCE( SUM(charged), 0 ) FROM cust_bill", - "SELECT -1 * COALESCE( SUM(amount), 0 ) FROM cust_credit", - "SELECT -1 * COALESCE( SUM(paid), 0 ) FROM cust_pay", - "SELECT COALESCE( SUM(refund), 0 ) FROM cust_refund", - ); + my @sql = + map "$_ WHERE _date <= ? AND custnum = ?", ( + "SELECT COALESCE( SUM(charged), 0 ) FROM cust_bill", + "SELECT -1 * COALESCE( SUM(amount), 0 ) FROM cust_credit", + "SELECT -1 * COALESCE( SUM(paid), 0 ) FROM cust_pay", + "SELECT COALESCE( SUM(refund), 0 ) FROM cust_refund", + ); # the customer's current balance immediately after generating the last # bill @@ -715,7 +716,7 @@ sub print_generic { my $last_bill_balance = $last_bill->charged; foreach (@sql) { my $delta = FS::Record->scalar_sql( - "$_ WHERE _date <= ? AND custnum = ?", + $_, $last_bill->_date - 1, $self->custnum, ); @@ -737,13 +738,11 @@ sub print_generic { # to immediately before this one my $before_this_bill_balance = 0; foreach (@sql) { - #warn "$_\n"; my $delta = FS::Record->scalar_sql( $_, $self->_date - 1, $self->custnum, ); - #warn "$delta\n"; $before_this_bill_balance += $delta; } $invoice_data{'balance_adjustments'} = From 3491239ea755e0b358f52c215b1e13ba8a319097 Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Fri, 5 Dec 2014 09:46:38 -0700 Subject: [PATCH 33/40] Modifications to Makefile and init scripts detailed in previous commit msg. --- Makefile | 111 ++++++----------------- init.d/freeside-cdrd.init | 89 ++---------------- init.d/freeside-cdrrated.init | 89 ++---------------- init.d/freeside-cdrrewrited.init | 88 ++---------------- init.d/freeside-prepaidd.init | 89 ++---------------- init.d/freeside-queued.init | 89 ++---------------- init.d/freeside-selfservice-server.init | 26 +----- init.d/freeside-selfservice-xmlrpcd.init | 92 ++----------------- init.d/freeside-sqlradius-radacctd.init | 89 ++---------------- init.d/freeside-torrus-srvderive.init | 89 ++---------------- init.d/freeside-torrus.init | 91 ++----------------- init.d/freeside-xmlrpcd.init | 92 ++----------------- 12 files changed, 115 insertions(+), 919 deletions(-) diff --git a/Makefile b/Makefile index 43cb0148f9..142aab3ded 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,13 @@ FREESIDE_DOCUMENT_ROOT = /var/www/freeside #apache #FREESIDE_DOCUMENT_ROOT = /usr/local/apache/htdocs/freeside + +# /etc/default/freeside on Debian/Ubuntu +FREESIDE_DEFAULTS = /etc/sysconfig/freeside +FREESIDE_BIN = /usr/bin +LOCKFILE_DIR = /var/lock/subsys +PIDFILE_DIR = /var/run + #deb, redhat, fedora, mandrake, suse, others? INIT_FILE_QUEUED = /etc/init.d/freeside-queued INIT_FILE_PREPAIDD = /etc/init.d/freeside-prepaidd @@ -56,6 +63,7 @@ INIT_FILE_SQLRADIUS_RADACCTD = /etc/init.d/freeside-sqlradius-radacctd INIT_FILE_TORRUS = /etc/init.d/freeside-torrus INIT_FILE_SELFSERVICE_XMLRPCD = /etc/init.d/freeside-selfservice-xmlrpcd INIT_FILE_SELFSERVICE_SERVER = /etc/init.d/freeside-selfservice-server +INIT_FILE_FUNCTIONS = /etc/init.d/freeside-functions #freebsd #INIT_FILE = /usr/local/etc/rc.d/011.freeside.sh @@ -107,8 +115,6 @@ APACHE_CONF = /etc/httpd/conf.d INSSERV_OVERRIDE = /etc/insserv/overrides -FREESIDE_RESTART = ${INIT_FILE} restart - #deb, redhat, fedora, mandrake, suse, others? INSTALLGROUP = root #freebsd, openbsd @@ -298,98 +304,42 @@ install-texmf: install-init: install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-queued.init ${INIT_FILE_QUEUED} - perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_QUEUED} - ${INIT_INSTALL_QUEUED} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-prepaidd.init ${INIT_FILE_PREPAIDD} - perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_PREPAIDD} - ${INIT_INSTALL_PREPAIDD} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-xmlrpcd.init ${INIT_FILE_XMLRPCD} - perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_XMLRPCD} - ${INIT_INSTALL_XMLRPCD} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-cdrrewrited.init ${INIT_FILE_CDRREWRITED} - perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_CDRREWRITED} - ${INIT_INSTALL_CDRREWRITED} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-cdrd.init ${INIT_FILE_CDRD} - perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_CDRD} - ${INIT_INSTALL_CDRD} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-cdrrated.init ${INIT_FILE_CDRRATED} - perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_CDRRATED} - ${INIT_INSTALL_CDRRATED} + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-selfservice-xmlrpcd.init ${INIT_FILE_SELFSERVICE_XMLRPCD} + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-selfservice-server.init ${INIT_FILE_SELFSERVICE_SERVER} + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-sqlradius-radacctd.init ${INIT_FILE_SQLRADIUS_RADACCTD} + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-functions ${INIT_FILE_FUNCTIONS} + if [ ${TORRUS_ENABLED} -eq 1 ]; then \ ( install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus-srvderive.init ${INIT_FILE_TORRUS_SRVDERIVE}; \ - perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_TORRUS_SRVDERIVE} ${INIT_FILE_TORRUS}; \ - ${INIT_INSTALL_TORRUS_SRVDERIVE}; \ - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus.init ${INIT_FILE_TORRUS}; \ - ${INIT_INSTALL_TORRUS}); fi + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus.init ${INIT_FILE_TORRUS}; \ + $INIT_INSTALL_TORRUS; \ + $INIT_INSTALL_TORRUS_SRVDERIVE;); fi - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-sqlradius-radacctd.init ${INIT_FILE_SQLRADIUS_RADACCTD} perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_SQLRADIUS_RADACCTD} - ${INIT_INSTALL_SQLRADIUS_RADACCTD} + s/%%%FREESIDE_DEFAULTS%%%/${FREESIDE_DEFAULTS}/g;\ + s/%%%FREESIDE_BIN%%%/${FREESIDE_BIN}/g;\ + " init.d/freeside-functions - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-selfservice-xmlrpcd.init ${INIT_FILE_SELFSERVICE_XMLRPCD} - perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_SELFSERVICE_XMLRPCD} + ${INIT_INSTALL_QUEUED} + ${INIT_INSTALL_PREPAIDD} + ${INIT_INSTALL_XMLRPCD} + ${INIT_INSTALL_CDRREWRITED} + ${INIT_INSTALL_CDRD} + ${INIT_INSTALL_CDRRATED} + ${INIT_INSTALL_SQLRADIUS_RADACCTD} ${INIT_INSTALL_SELFSERVICE_XMLRPCD} - - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-selfservice-server.init ${INIT_FILE_SELFSERVICE_SERVER} - perl -p -i -e "\ - s/%%%QUEUED_USER%%%/${QUEUED_USER}/g;\ - s/%%%API_USER%%%/${API_USER}/g;\ - s/%%%SELFSERVICE_USER%%%/${SELFSERVICE_USER}/g;\ - s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\ - " ${INIT_FILE_SELFSERVICE_SERVER} ${INIT_INSTALL_SELFSERVICE_SERVER} + /bin/echo -e "#!/bin/bash\n\nLOCKFILE_DIR=${LOCKFILE_DIR}\nPIDFILE_DIR=${PIDFILE_DIR}" > ${FREESIDE_DEFAULTS} + /bin/echo -e "QUEUED_USER=${QUEUED_USER}\nAPI_USER=${API_USER}" >> ${FREESIDE_DEFAULTS} + /bin/echo -e "SELFSERVICE_USER=${SELFSERVICE_USER}\nSELFSERVICE_MACHINES=${SELFSERVICE_MACHINES}" >> ${FREESIDE_DEFAULTS} + install-apache: [ -e ${APACHE_CONF}/freeside-base.conf ] && rm ${APACHE_CONF}/freeside-base.conf || true [ -d ${APACHE_CONF} ] && \ @@ -435,7 +385,6 @@ install: install-perl-modules install-docs install-init install-apache install-r deploy: install ${HTTPD_RESTART} - ${FREESIDE_RESTART} dev: dev-perl-modules dev-docs diff --git a/init.d/freeside-cdrd.init b/init.d/freeside-cdrd.init index 7611ca0f0e..3e72afdf90 100644 --- a/init.d/freeside-cdrd.init +++ b/init.d/freeside-cdrd.init @@ -6,92 +6,19 @@ ARG1=${1} SERVICE=freeside-cdrd -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/${SERVICE}.pid - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] -then - . /lib/lsb/init-functions -fi - -if [ -f %%%FREESIDE_DEFAULTS%%% ] -then - . %%%FREESIDE_DEFAULTS%%% -fi - -if [ -z ${QUEUED_USER} ] +if [ -f /etc/rc.d/init.d/freeside-functions ] then - QUEUED_USER=%%%QUEUED_USER%%% + . /etc/rc.d/init.d/freeside-functions +else + echo "ERROR: freeside-functions could not be sourced." + exit 1 fi -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running -statusfunc() { - RUNNING=0 - if [ -f ${LOCKFILE} ] - then - if [ -f ${PIDFILE} ] - then - PID=`cat $PIDFILE` - if ps -p ${PID} > /dev/null - then - return 0 - else - return 1 - fi - fi - fi - return 3 -} - -startfunc() { - if statusfunc - then - action "Already running ${SERVICE} " /bin/false - else - ${SERVICE} $QUEUED_USER - RETVAL=$? - action "Starting ${SERVICE} " /bin/true - if [ $RETVAL = 0 ] - then - touch ${LOCKFILE} - fi - return $RETVAL - fi -} - -stopfunc() { - if statusfunc - then - echo -n "Stopping ${SERVICE} service" - killproc -p ${PIDFILE} - rm -f ${LOCKFILE} - echo - else - action "Service not running" /bin/false - fi -} - -restartfunc() { - stopfunc - startfunc -} - -# echo_status function -echo_statusfunc() { - # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile - echo -n $SERVICE - status -p $PIDFILE -} +STARTCOMMAND=($SERVICE $QUEUED_USER) +LOCKFILE=${LOCKFILE_DIR}/${SERVICE} +PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) diff --git a/init.d/freeside-cdrrated.init b/init.d/freeside-cdrrated.init index a9359a8bc3..659d6a36a1 100644 --- a/init.d/freeside-cdrrated.init +++ b/init.d/freeside-cdrrated.init @@ -6,92 +6,19 @@ ARG1=${1} SERVICE=freeside-cdrrated -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/${SERVICE}.pid - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] -then - . /lib/lsb/init-functions -fi - -if [ -f %%%FREESIDE_DEFAULTS%%% ] -then - . %%%FREESIDE_DEFAULTS%%% -fi - -if [ -z ${QUEUED_USER} ] +if [ -f /etc/rc.d/init.d/freeside-functions ] then - QUEUED_USER=%%%QUEUED_USER%%% + . /etc/rc.d/init.d/freeside-functions +else + echo "ERROR: freeside-functions could not be sourced." + exit 1 fi -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running -statusfunc() { - RUNNING=0 - if [ -f ${LOCKFILE} ] - then - if [ -f ${PIDFILE} ] - then - PID=`cat $PIDFILE` - if ps -p ${PID} > /dev/null - then - return 0 - else - return 1 - fi - fi - fi - return 3 -} - -startfunc() { - if statusfunc - then - action "Already running ${SERVICE} " /bin/false - else - ${SERVICE} $QUEUED_USER - RETVAL=$? - action "Starting ${SERVICE} " /bin/true - if [ $RETVAL = 0 ] - then - touch ${LOCKFILE} - fi - return $RETVAL - fi -} - -stopfunc() { - if statusfunc - then - echo -n "Stopping ${SERVICE} service" - killproc -p ${PIDFILE} - rm -f ${LOCKFILE} - echo - else - action "Service not running" /bin/false - fi -} - -restartfunc() { - stopfunc - startfunc -} - -# echo_status function -echo_statusfunc() { - # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile - echo -n $SERVICE - status -p $PIDFILE -} +STARTCOMMAND=($SERVICE $QUEUED_USER) +LOCKFILE=${LOCKFILE_DIR}/${SERVICE} +PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) diff --git a/init.d/freeside-cdrrewrited.init b/init.d/freeside-cdrrewrited.init index 6ed92e4e0d..f39757fa09 100644 --- a/init.d/freeside-cdrrewrited.init +++ b/init.d/freeside-cdrrewrited.init @@ -6,92 +6,20 @@ ARG1=${1} SERVICE=freeside-cdrrewrited -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/${SERVICE}.pid - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] -then - . /lib/lsb/init-functions -fi - -if [ -f %%%FREESIDE_DEFAULTS%%% ] -then - . %%%FREESIDE_DEFAULTS%%% -fi - -if [ -z ${QUEUED_USER} ] +if [ -f /etc/rc.d/init.d/freeside-functions ] then - QUEUED_USER=%%%QUEUED_USER%%% + . /etc/rc.d/init.d/freeside-functions +else + echo "ERROR: freeside-functions could not be sourced." + exit 1 fi -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running -statusfunc() { - RUNNING=0 - if [ -f ${LOCKFILE} ] - then - if [ -f ${PIDFILE} ] - then - PID=`cat $PIDFILE` - if ps -p ${PID} > /dev/null - then - return 0 - else - return 1 - fi - fi - fi - return 3 -} - -startfunc() { - if statusfunc - then - action "Already running ${SERVICE} " /bin/false - else - ${SERVICE} $QUEUED_USER - RETVAL=$? - action "Starting ${SERVICE} " /bin/true - if [ $RETVAL = 0 ] - then - touch ${LOCKFILE} - fi - return $RETVAL - fi -} - -stopfunc() { - if statusfunc - then - echo -n "Stopping ${SERVICE} service" - killproc -p ${PIDFILE} - rm -f ${LOCKFILE} - echo - else - action "Service not running" /bin/false - fi -} - -restartfunc() { - stopfunc - startfunc -} +STARTCOMMAND=($SERVICE $QUEUED_USER) +LOCKFILE=${LOCKFILE_DIR}/${SERVICE} +PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid -# echo_status function -echo_statusfunc() { - # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile - echo -n $SERVICE - status -p $PIDFILE -} -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) diff --git a/init.d/freeside-prepaidd.init b/init.d/freeside-prepaidd.init index 824ecf65a0..638eaafc10 100644 --- a/init.d/freeside-prepaidd.init +++ b/init.d/freeside-prepaidd.init @@ -6,92 +6,19 @@ ARG1=${1} SERVICE=freeside-prepaidd -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/${SERVICE}.pid - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] -then - . /lib/lsb/init-functions -fi - -if [ -f %%%FREESIDE_DEFAULTS%%% ] -then - . %%%FREESIDE_DEFAULTS%%% -fi - -if [ -z ${QUEUED_USER} ] +if [ -f /etc/rc.d/init.d/freeside-functions ] then - QUEUED_USER=%%%QUEUED_USER%%% + . /etc/rc.d/init.d/freeside-functions +else + echo "ERROR: freeside-functions could not be sourced." + exit 1 fi -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running -statusfunc() { - RUNNING=0 - if [ -f ${LOCKFILE} ] - then - if [ -f ${PIDFILE} ] - then - PID=`cat $PIDFILE` - if ps -p ${PID} > /dev/null - then - return 0 - else - return 1 - fi - fi - fi - return 3 -} - -startfunc() { - if statusfunc - then - action "Already running ${SERVICE} " /bin/false - else - ${SERVICE} $QUEUED_USER - RETVAL=$? - action "Starting ${SERVICE} " /bin/true - if [ $RETVAL = 0 ] - then - touch ${LOCKFILE} - fi - return $RETVAL - fi -} - -stopfunc() { - if statusfunc - then - echo -n "Stopping ${SERVICE} service" - killproc -p ${PIDFILE} - rm -f ${LOCKFILE} - echo - else - action "Service not running" /bin/false - fi -} - -restartfunc() { - stopfunc - startfunc -} - -# echo_status function -echo_statusfunc() { - # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile - echo -n $SERVICE - status -p $PIDFILE -} +STARTCOMMAND=($SERVICE $QUEUED_USER) +LOCKFILE=${LOCKFILE_DIR}/${SERVICE} +PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) diff --git a/init.d/freeside-queued.init b/init.d/freeside-queued.init index 2bfbf911ee..d1503d8489 100644 --- a/init.d/freeside-queued.init +++ b/init.d/freeside-queued.init @@ -6,92 +6,19 @@ ARG1=${1} SERVICE=freeside-queued -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/${SERVICE}.pid - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] -then - . /lib/lsb/init-functions -fi - -if [ -f %%%FREESIDE_DEFAULTS%%% ] -then - . %%%FREESIDE_DEFAULTS%%% -fi - -if [ -z ${QUEUED_USER} ] +if [ -f /etc/rc.d/init.d/freeside-functions ] then - QUEUED_USER=%%%QUEUED_USER%%% + . /etc/rc.d/init.d/freeside-functions +else + echo "ERROR: freeside-functions could not be sourced." + exit 1 fi -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running -statusfunc() { - RUNNING=0 - if [ -f ${LOCKFILE} ] - then - if [ -f ${PIDFILE} ] - then - PID=`cat $PIDFILE` - if ps -p ${PID} > /dev/null - then - return 0 - else - return 1 - fi - fi - fi - return 3 -} - -startfunc() { - if statusfunc - then - action "Already running ${SERVICE} " /bin/false - else - ${SERVICE} $QUEUED_USER - RETVAL=$? - action "Starting ${SERVICE} " /bin/true - if [ $RETVAL = 0 ] - then - touch ${LOCKFILE} - fi - return $RETVAL - fi -} - -stopfunc() { - if statusfunc - then - echo -n "Stopping ${SERVICE} service" - killproc -p ${PIDFILE} - rm -f ${LOCKFILE} - echo - else - action "Service not running" /bin/false - fi -} - -restartfunc() { - stopfunc - startfunc -} - -# echo_status function -echo_statusfunc() { - # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile - echo -n $SERVICE - status -p $PIDFILE -} +STARTCOMMAND=($SERVICE $QUEUED_USER) +LOCKFILE=${LOCKFILE_DIR}/${SERVICE} +PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) diff --git a/init.d/freeside-selfservice-server.init b/init.d/freeside-selfservice-server.init index 2c4ce1a477..af42a7fa55 100644 --- a/init.d/freeside-selfservice-server.init +++ b/init.d/freeside-selfservice-server.init @@ -6,32 +6,18 @@ ARG1=${1} SERVICE=freeside-selfservice-server -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/${SERVICE}.USERMACHINE.pid - - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] -then - . /lib/lsb/init-functions -fi if [ -f %%%FREESIDE_DEFAULTS%%% ] then . %%%FREESIDE_DEFAULTS%%% +else + echo "ERROR: freeside defaults could not be sourced." + exit 1 fi -if [ -z ${SELFSERVICE_USER} ] -then - SELFSERVICE_USER=%%%SELFSERVICE_USER%%% -fi +LOCKFILE=$LOCKFILE_DIR/$SERVICE +PIDFILE=$PIDFILE_DIR/${SERVICE}.USERMACHINE.pid -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running statusfunc() { if [ -f ${LOCKFILE} ] then @@ -131,8 +117,6 @@ echo_statusfunc() { done } -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) diff --git a/init.d/freeside-selfservice-xmlrpcd.init b/init.d/freeside-selfservice-xmlrpcd.init index 03d8156969..03a352eb34 100644 --- a/init.d/freeside-selfservice-xmlrpcd.init +++ b/init.d/freeside-selfservice-xmlrpcd.init @@ -6,95 +6,19 @@ ARG1=${1} SERVICE=freeside-selfservice-xmlrpcd -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/freeside/${SERVICE}.pid - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] -then - . /lib/lsb/init-functions -fi - -if [ -f %%%FREESIDE_DEFAULTS%%% ] -then - . %%%FREESIDE_DEFAULTS%%% -fi - -if [ -z ${QUEUED_USER} ] +if [ -f /etc/rc.d/init.d/freeside-functions ] then - QUEUED_USER=%%%QUEUED_USER%%% + . /etc/rc.d/init.d/freeside-functions +else + echo "ERROR: freeside-functions could not be sourced." + exit 1 fi -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running -statusfunc() { - if [ -f ${LOCKFILE} ] - then - if [ -f ${PIDFILE} ] - then - PID=`cat $PIDFILE` - if ps -p ${PID} > /dev/null - then - return 0 - else - return 1 - fi - fi - fi - return 3 -} - -startfunc() { - if statusfunc - then - action "Already running ${SERVICE} " /bin/false - else - ${SERVICE} $SELFSERVICE_USER - RETVAL=$? - action "Starting ${SERVICE} " /bin/true - if [ $RETVAL = 0 ] - then - if ! [ -d /var/run/freeside ] - then - mkdir /var/run/freeside - fi - touch ${LOCKFILE} - fi - return $RETVAL - fi -} - -stopfunc() { - if statusfunc - then - echo -n "Stopping ${SERVICE} service" - killproc -p ${PIDFILE} - rm -f ${LOCKFILE} - echo - else - action "Service not running" /bin/false - fi -} - -restartfunc() { - stopfunc - startfunc -} - -# echo_status function -echo_statusfunc() { - # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile - echo -n $SERVICE - status -p $PIDFILE -} +STARTCOMMAND=($SERVICE $SELFSERVICE_USER) +LOCKFILE=${LOCKFILE_DIR}/${SERVICE} +PIDFILE=${PIDFILE_DIR}/freeside/${SERVICE}.pid -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) diff --git a/init.d/freeside-sqlradius-radacctd.init b/init.d/freeside-sqlradius-radacctd.init index df3c95789b..066d9e683c 100644 --- a/init.d/freeside-sqlradius-radacctd.init +++ b/init.d/freeside-sqlradius-radacctd.init @@ -6,92 +6,19 @@ ARG1=${1} SERVICE=freeside-sqlradius-radacctd -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/${SERVICE}.pid - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] -then - . /lib/lsb/init-functions -fi - -if [ -f %%%FREESIDE_DEFAULTS%%% ] -then - . %%%FREESIDE_DEFAULTS%%% -fi - -if [ -z ${QUEUED_USER} ] +if [ -f /etc/rc.d/init.d/freeside-functions ] then - QUEUED_USER=%%%QUEUED_USER%%% + . /etc/rc.d/init.d/freeside-functions +else + echo "ERROR: freeside-functions could not be sourced." + exit 1 fi -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running -statusfunc() { - RUNNING=0 - if [ -f ${LOCKFILE} ] - then - if [ -f ${PIDFILE} ] - then - PID=`cat $PIDFILE` - if ps -p ${PID} > /dev/null - then - return 0 - else - return 1 - fi - fi - fi - return 3 -} - -startfunc() { - if statusfunc - then - action "Already running ${SERVICE} " /bin/false - else - ${SERVICE} $QUEUED_USER - RETVAL=$? - action "Starting ${SERVICE} " /bin/true - if [ $RETVAL = 0 ] - then - touch ${LOCKFILE} - fi - return $RETVAL - fi -} - -stopfunc() { - if statusfunc - then - echo -n "Stopping ${SERVICE} service" - killproc -p ${PIDFILE} - rm -f ${LOCKFILE} - echo - else - action "Service not running" /bin/false - fi -} - -restartfunc() { - stopfunc - startfunc -} - -# echo_status function -echo_statusfunc() { - # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile - echo -n $SERVICE - status -p $PIDFILE -} +STARTCOMMAND=($SERVICE $QUEUED_USER) +LOCKFILE=${LOCKFILE_DIR}/${SERVICE} +PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) diff --git a/init.d/freeside-torrus-srvderive.init b/init.d/freeside-torrus-srvderive.init index 4ed9b97537..cb096202c7 100644 --- a/init.d/freeside-torrus-srvderive.init +++ b/init.d/freeside-torrus-srvderive.init @@ -6,92 +6,19 @@ ARG1=${1} SERVICE=freeside-torrus-srvderive -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/${SERVICE}.pid - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] -then - . /lib/lsb/init-functions -fi - -if [ -f %%%FREESIDE_DEFAULTS%%% ] -then - . %%%FREESIDE_DEFAULTS%%% -fi - -if [ -z ${QUEUED_USER} ] +if [ -f /etc/rc.d/init.d/freeside-functions ] then - QUEUED_USER=%%%QUEUED_USER%%% + . /etc/rc.d/init.d/freeside-functions +else + echo "ERROR: freeside-functions could not be sourced." + exit 1 fi -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running -statusfunc() { - RUNNING=0 - if [ -f ${LOCKFILE} ] - then - if [ -f ${PIDFILE} ] - then - PID=`cat $PIDFILE` - if ps -p ${PID} > /dev/null - then - return 0 - else - return 1 - fi - fi - fi - return 3 -} - -startfunc() { - if statusfunc - then - action "Already running ${SERVICE} " /bin/false - else - ${SERVICE} $QUEUED_USER - RETVAL=$? - action "Starting ${SERVICE} " /bin/true - if [ $RETVAL = 0 ] - then - touch ${LOCKFILE} - fi - return $RETVAL - fi -} - -stopfunc() { - if statusfunc - then - echo -n "Stopping ${SERVICE} service" - killproc -p ${PIDFILE} - rm -f ${LOCKFILE} - echo - else - action "Service not running" /bin/false - fi -} - -restartfunc() { - stopfunc - startfunc -} - -# echo_status function -echo_statusfunc() { - # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile - echo -n $SERVICE - status -p $PIDFILE -} +STARTCOMMAND=($SERVICE $QUEUED_USER) +LOCKFILE=${LOCKFILE_DIR}/${SERVICE} +PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) diff --git a/init.d/freeside-torrus.init b/init.d/freeside-torrus.init index 0dea661743..d06051c902 100644 --- a/init.d/freeside-torrus.init +++ b/init.d/freeside-torrus.init @@ -6,96 +6,21 @@ ARG1=${1} SERVICE=torrus -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/torrus/collector.main_0.pid - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] +if [ -f /etc/rc.d/init.d/freeside-functions ] then - . /lib/lsb/init-functions -fi - -if [ -f %%%FREESIDE_DEFAULTS%%% ] -then - . %%%FREESIDE_DEFAULTS%%% -fi - -if [ -z ${QUEUED_USER} ] + . /etc/rc.d/init.d/freeside-functions +else then - QUEUED_USER=%%%QUEUED_USER%%% + echo "ERROR: freeside-functions could not be sourced." + exit 1 fi -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running -statusfunc() { - RUNNING=0 - if [ -f ${LOCKFILE} ] - then - if [ -f ${PIDFILE} ] - then - PID=`cat $PIDFILE` - if ps -p ${PID} > /dev/null - then - return 0 - else - return 1 - fi - fi - fi - return 3 -} - -startfunc() { - if statusfunc - then - action "Already running ${SERVICE} " /bin/false - else - ${SERVICE} collector --tree=main - RETVAL=$? - action "Starting ${SERVICE} " /bin/true - if [ $RETVAL = 0 ] - then - if ! [ -d /var/run/torrus ] - then - mkdir /var/run/torrus - fi - touch ${LOCKFILE} - fi - return $RETVAL - fi -} - -stopfunc() { - if statusfunc - then - echo -n "Stopping ${SERVICE} service" - killproc -p ${PIDFILE} - rm -f ${LOCKFILE} - echo - else - action "Service not running" /bin/false - fi -} - -restartfunc() { - stopfunc - startfunc -} +LOCKFILE=${LOCKFILE_DIR}/${SERVICE} +PIDFILE=${PIDFILE_DIR}/torrus/collector.main_?.pid +STARTCOMMAND=(${SERVICE} collector --tree=main) -# echo_status function -echo_statusfunc() { - # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile - echo -n $SERVICE - status -p $PIDFILE -} -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) diff --git a/init.d/freeside-xmlrpcd.init b/init.d/freeside-xmlrpcd.init index 97031eca96..4ad8fa8316 100644 --- a/init.d/freeside-xmlrpcd.init +++ b/init.d/freeside-xmlrpcd.init @@ -6,96 +6,20 @@ ARG1=${1} SERVICE=freeside-xmlrpcd -LOCKFILE=/var/lock/subsys/${SERVICE} -PIDFILE=/var/run/freeside/xmlrpcd.pid - -if [ -f /etc/rc.d/init.d/functions ] -then - . /etc/init.d/functions -elif [ -f /lib/lsb/init-functions ] -then - . /lib/lsb/init-functions -fi - -if [ -f %%%FREESIDE_DEFAULTS%%% ] -then - . %%%FREESIDE_DEFAULTS%%% -fi - -if [ -z ${API_USER} ] +if [ -f /etc/rc.d/init.d/freeside-functions ] then - API_USER=%%%API_USER%%% + . /etc/rc.d/init.d/freeside-functions +else + echo "ERROR: freeside-functions could not be sourced." + exit 1 fi -# 0: program is running or service is OK -# 1: program is dead and /var/run pid file exists -# 2: program is dead and /var/lock lock file exists -# 3: program is not running -statusfunc() { - RUNNING=0 - if [ -f ${LOCKFILE} ] - then - if [ -f ${PIDFILE} ] - then - PID=`cat $PIDFILE` - if ps -p ${PID} > /dev/null - then - return 0 - else - return 1 - fi - fi - fi - return 3 -} - -startfunc() { - if statusfunc - then - action "Already running ${SERVICE} " /bin/false - else - ${SERVICE} $API_USER - RETVAL=$? - action "Starting ${SERVICE} " /bin/true - if [ $RETVAL = 0 ] - then - if ! [ -d /var/run/freeside ] - then - mkdir /var/run/freeside - fi - touch ${LOCKFILE} - fi - return $RETVAL - fi -} - -stopfunc() { - if statusfunc - then - echo -n "Stopping ${SERVICE} service" - killproc -p ${PIDFILE} - rm -f ${LOCKFILE} - echo - else - action "Service not running" /bin/false - fi -} - -restartfunc() { - stopfunc - startfunc -} +STARTCOMMAND=($SERVICE $API_USER) +LOCKFILE=${LOCKFILE_DIR}/${SERVICE} +PIDFILE=${PIDFILE_DIR}/freeside/${SERVICE}.pid -# echo_status function -echo_statusfunc() { - # we need a way of displaying the status to the end user if called with the parameter status. This status function will check for pid or lockfile - echo -n $SERVICE - status -p $PIDFILE -} -# main loop/case statement -# The main loop is done with a case statment, and we no longer call $0 directly, which saves shell instances and makes our scripts more efficent. case $ARG1 in start) From 68a4a8ed72873b51b8c6059e6371031b6903e2bc Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Tue, 16 Dec 2014 14:01:34 -0700 Subject: [PATCH 34/40] Consolidated init.d scripts into a template. Added code to Makefile to generate individual scripts from template. Restored original paths in Makefile. --- Makefile | 97 +++++++++++++++---- init.d/freeside-cdrrated.init | 51 ---------- init.d/freeside-cdrrewrited.init | 52 ---------- init.d/freeside-prepaidd.init | 51 ---------- init.d/freeside-queued.init | 51 ---------- init.d/freeside-selfservice-xmlrpcd.init | 51 ---------- ...ide-cdrd.init => freeside-service.init.in} | 12 +-- init.d/freeside-sqlradius-radacctd.init | 51 ---------- init.d/freeside-torrus-srvderive.init | 51 ---------- init.d/freeside-torrus.init | 53 ---------- init.d/freeside-xmlrpcd.init | 52 ---------- 11 files changed, 85 insertions(+), 487 deletions(-) delete mode 100644 init.d/freeside-cdrrated.init delete mode 100644 init.d/freeside-cdrrewrited.init delete mode 100644 init.d/freeside-prepaidd.init delete mode 100644 init.d/freeside-queued.init delete mode 100644 init.d/freeside-selfservice-xmlrpcd.init rename init.d/{freeside-cdrd.init => freeside-service.init.in} (75%) delete mode 100644 init.d/freeside-sqlradius-radacctd.init delete mode 100644 init.d/freeside-torrus-srvderive.init delete mode 100644 init.d/freeside-torrus.init delete mode 100644 init.d/freeside-xmlrpcd.init diff --git a/Makefile b/Makefile index 142aab3ded..6e34355fef 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,11 @@ DB_PASSWORD= DATASOURCE = DBI:${DB_TYPE}:dbname=freeside #changable now (some things which should go to the others still go to CONF) -FREESIDE_CONF = /opt/etc/freeside -FREESIDE_LOG = /opt/etc/freeside -FREESIDE_LOCK = /opt/etc/freeside -FREESIDE_CACHE = /opt/etc/freeside -FREESIDE_EXPORT = /opt/etc/freeside +FREESIDE_CONF = /usr/local/etc/freeside +FREESIDE_LOG = /usr/local/etc/freeside +FREESIDE_LOCK = /usr/local/etc/freeside +FREESIDE_CACHE = /usr/local/etc/freeside +FREESIDE_EXPORT = /usr/local/etc/freeside MASON_HANDLER = ${FREESIDE_CONF}/handler.pl MASONDATA = ${FREESIDE_CACHE}/masondata @@ -109,9 +109,11 @@ HTTPD_RESTART = /etc/init.d/apache2 restart #(an include directory, not a file, "Include /etc/apache/conf.d" in httpd.conf) #debian unstable/8.0+, apache2.4 -APACHE_CONF = /etc/httpd/conf.d +APACHE_CONF = /etc/apache2/conf-available #deb (3.1+), apache2 #APACHE_CONF = /etc/apache2/conf.d +# RHEL and derivatives +#APACHE_CONF = /etc/httpd/conf.d INSSERV_OVERRIDE = /etc/insserv/overrides @@ -303,23 +305,82 @@ install-texmf: texhash /usr/local/share/texmf install-init: - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-queued.init ${INIT_FILE_QUEUED} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-prepaidd.init ${INIT_FILE_PREPAIDD} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-xmlrpcd.init ${INIT_FILE_XMLRPCD} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-cdrrewrited.init ${INIT_FILE_CDRREWRITED} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-cdrd.init ${INIT_FILE_CDRD} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-cdrrated.init ${INIT_FILE_CDRRATED} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-selfservice-xmlrpcd.init ${INIT_FILE_SELFSERVICE_XMLRPCD} + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-service.init.in ${INIT_FILE_QUEUED} + perl -p -i -e "\ + s|%%%SERVICE%%%|freeside-queued|g;\ + s|%%%STARTCOMMAND%%%|\${SERVICE} \${QUEUED_USER}|g;\ + s|%%%PIDFILE%%%|\${PIDFILE_DIR}/\${SERVICE}.pid|g;\ + " ${INIT_FILE_QUEUED} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-service.init.in ${INIT_FILE_PREPAIDD} + perl -p -i -e "\ + s|%%%SERVICE%%%|freeside-prepaidd|g;\ + s|%%%STARTCOMMAND%%%|\${SERVICE} \${QUEUED_USER}|g;\ + s|%%%PIDFILE%%%|\${PIDFILE_DIR}/\${SERVICE}.pid|g;\ + " ${INIT_FILE_PREPAIDD} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-service.init.in ${INIT_FILE_XMLRPCD} + perl -p -i -e "\ + s|%%%SERVICE%%%|freeside-xmlrpcd|g;\ + s|%%%STARTCOMMAND%%%|\${SERVICE} \${API_USER}|g;\ + s|%%%PIDFILE%%%|\${PIDFILE_DIR}/freeside/\${SERVICE}.pid|g;\ + " ${INIT_FILE_XMLRPCD} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-service.init.in ${INIT_FILE_CDRREWRITED} + perl -p -i -e "\ + s|%%%SERVICE%%%|freeside-cdrrewrited|g;\ + s|%%%STARTCOMMAND%%%|\${SERVICE} \${QUEUED_USER}|g;\ + s|%%%PIDFILE%%%|\${PIDFILE_DIR}/\${SERVICE}.pid|g;\ + " ${INIT_FILE_CDRREWRITED} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-service.init.in ${INIT_FILE_CDRD} + perl -p -i -e "\ + s|%%%SERVICE%%%|freeside-cdrd|g;\ + s|%%%STARTCOMMAND%%%|\${SERVICE} \${QUEUED_USER}|g;\ + s|%%%PIDFILE%%%|\${PIDFILE_DIR}/\${SERVICE}.pid|g;\ + " ${INIT_FILE_CDRREWRITED} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-service.init.in ${INIT_FILE_CDRRATED} + perl -p -i -e "\ + s|%%%SERVICE%%%|freeside-cdrated|g;\ + s|%%%STARTCOMMAND%%%|\${SERVICE} \${QUEUED_USER}|g;\ + s|%%%PIDFILE%%%|\${PIDFILE_DIR}/\${SERVICE}.pid|g;\ + " ${INIT_FILE_CDRRATED} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-service.init.in ${INIT_FILE_SELFSERVICE_XMLRPCD} + perl -p -i -e "\ + s|%%%SERVICE%%%|freeside-selfservice-xmlrpcd|g;\ + s|%%%STARTCOMMAND%%%|\${SERVICE} \${SELFSERVICE_USER}|g;\ + s|%%%PIDFILE%%%|\${PIDFILE_DIR}/\${SERVICE}.pid|g;\ + " ${INIT_FILE_SELFSERVICE_XMLRPCD} + + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-service.init.in ${INIT_FILE_SQLRADIUS_RADACCTD} + perl -p -i -e "\ + s|%%%SERVICE%%%|freeside-sqlradius-radacctd|g;\ + s|%%%STARTCOMMAND%%%|\${SERVICE} \${QUEUED_USER}|g;\ + s|%%%PIDFILE%%%|\${PIDFILE_DIR}/\${SERVICE}.pid|g;\ + " ${INIT_FILE_SQLRADIUS_RADACCTD} + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-selfservice-server.init ${INIT_FILE_SELFSERVICE_SERVER} - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-sqlradius-radacctd.init ${INIT_FILE_SQLRADIUS_RADACCTD} install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-functions ${INIT_FILE_FUNCTIONS} - + if [ ${TORRUS_ENABLED} -eq 1 ]; then \ - ( install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus-srvderive.init ${INIT_FILE_TORRUS_SRVDERIVE}; \ - install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-torrus.init ${INIT_FILE_TORRUS}; \ + ( install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-service.init.in ${INIT_FILE_TORRUS_SRVDERIVE}; \ + install -o root -g ${INSTALLGROUP} -m 711 init.d/freeside-service.init.in ${INIT_FILE_TORRUS}; \ + perl -p -i -e "\ + s|%%%SERVICE%%%|torrus|g;\ + s|%%%STARTCOMMAND%%%|\${SERVICE} collector --tree=main|g;\ + s|%%%PIDFILE%%%|\${PIDFILE_DIR}/torrus/collector.main_?.pid|g;\ + " ${INIT_FILE_TORRUS}; \ + perl -p -i -e "\ + s|%%%SERVICE%%%|freeside-torrus-srvderive|g;\ + s|%%%STARTCOMMAND%%%|\${SERVICE} \${QUEUED_USER}|g;\ + s|%%%PIDFILE%%%|\${PIDFILE_DIR}/\${SERVICE}.pid|g;\ + " ${INIT_FILE_TORRUS_SRVDERIVE}; \ $INIT_INSTALL_TORRUS; \ - $INIT_INSTALL_TORRUS_SRVDERIVE;); fi + $INIT_INSTALL_TORRUS_SRVDERIVE;\ + ); fi perl -p -i -e "\ s/%%%FREESIDE_DEFAULTS%%%/${FREESIDE_DEFAULTS}/g;\ diff --git a/init.d/freeside-cdrrated.init b/init.d/freeside-cdrrated.init deleted file mode 100644 index 659d6a36a1..0000000000 --- a/init.d/freeside-cdrrated.init +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -# description: Manage the freeside-cdrrated script service, SYS-V style -# chkconfig: 2345 10 90 - - -ARG1=${1} -SERVICE=freeside-cdrrated - -if [ -f /etc/rc.d/init.d/freeside-functions ] -then - . /etc/rc.d/init.d/freeside-functions -else - echo "ERROR: freeside-functions could not be sourced." - exit 1 -fi - -STARTCOMMAND=($SERVICE $QUEUED_USER) -LOCKFILE=${LOCKFILE_DIR}/${SERVICE} -PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid - -case $ARG1 in - -start) - # if our parameter is 'start' we should run this - startfunc -;; - -stop) - # if our parameter is 'stop' we should run this - stopfunc -;; - -restart) - # if our parameter is 'restart' we should run this - restartfunc -;; - -status) - # display the status of our service using the echo_statusfunc function - echo_statusfunc -;; - -*) - # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 - echo "Syntax Error... usage: $0 (start|stop|restart|status)" - exit 1 -;; - -# close up that case -esac diff --git a/init.d/freeside-cdrrewrited.init b/init.d/freeside-cdrrewrited.init deleted file mode 100644 index f39757fa09..0000000000 --- a/init.d/freeside-cdrrewrited.init +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -# description: Manage the freeside-cdrrewrited script service, SYS-V style -# chkconfig: 2345 10 90 - - -ARG1=${1} -SERVICE=freeside-cdrrewrited - -if [ -f /etc/rc.d/init.d/freeside-functions ] -then - . /etc/rc.d/init.d/freeside-functions -else - echo "ERROR: freeside-functions could not be sourced." - exit 1 -fi - -STARTCOMMAND=($SERVICE $QUEUED_USER) -LOCKFILE=${LOCKFILE_DIR}/${SERVICE} -PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid - - -case $ARG1 in - -start) - # if our parameter is 'start' we should run this - startfunc -;; - -stop) - # if our parameter is 'stop' we should run this - stopfunc -;; - -restart) - # if our parameter is 'restart' we should run this - restartfunc -;; - -status) - # display the status of our service using the echo_statusfunc function - echo_statusfunc -;; - -*) - # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 - echo "Syntax Error... usage: $0 (start|stop|restart|status)" - exit 1 -;; - -# close up that case -esac diff --git a/init.d/freeside-prepaidd.init b/init.d/freeside-prepaidd.init deleted file mode 100644 index 638eaafc10..0000000000 --- a/init.d/freeside-prepaidd.init +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -# description: Manage the freeside-prepaidd script service, SYS-V style -# chkconfig: 2345 10 90 - - -ARG1=${1} -SERVICE=freeside-prepaidd - -if [ -f /etc/rc.d/init.d/freeside-functions ] -then - . /etc/rc.d/init.d/freeside-functions -else - echo "ERROR: freeside-functions could not be sourced." - exit 1 -fi - -STARTCOMMAND=($SERVICE $QUEUED_USER) -LOCKFILE=${LOCKFILE_DIR}/${SERVICE} -PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid - -case $ARG1 in - -start) - # if our parameter is 'start' we should run this - startfunc -;; - -stop) - # if our parameter is 'stop' we should run this - stopfunc -;; - -restart) - # if our parameter is 'restart' we should run this - restartfunc -;; - -status) - # display the status of our service using the echo_statusfunc function - echo_statusfunc -;; - -*) - # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 - echo "Syntax Error... usage: $0 (start|stop|restart|status)" - exit 1 -;; - -# close up that case -esac diff --git a/init.d/freeside-queued.init b/init.d/freeside-queued.init deleted file mode 100644 index d1503d8489..0000000000 --- a/init.d/freeside-queued.init +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -# description: Manage the freeside-queued script service, SYS-V style -# chkconfig: 2345 10 90 - - -ARG1=${1} -SERVICE=freeside-queued - -if [ -f /etc/rc.d/init.d/freeside-functions ] -then - . /etc/rc.d/init.d/freeside-functions -else - echo "ERROR: freeside-functions could not be sourced." - exit 1 -fi - -STARTCOMMAND=($SERVICE $QUEUED_USER) -LOCKFILE=${LOCKFILE_DIR}/${SERVICE} -PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid - -case $ARG1 in - -start) - # if our parameter is 'start' we should run this - startfunc -;; - -stop) - # if our parameter is 'stop' we should run this - stopfunc -;; - -restart) - # if our parameter is 'restart' we should run this - restartfunc -;; - -status) - # display the status of our service using the echo_statusfunc function - echo_statusfunc -;; - -*) - # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 - echo "Syntax Error... usage: $0 (start|stop|restart|status)" - exit 1 -;; - -# close up that case -esac diff --git a/init.d/freeside-selfservice-xmlrpcd.init b/init.d/freeside-selfservice-xmlrpcd.init deleted file mode 100644 index 03a352eb34..0000000000 --- a/init.d/freeside-selfservice-xmlrpcd.init +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -# description: Manage the freeside-selfservice-xmlrpcd script service, SYS-V style -# chkconfig: 2345 10 90 - - -ARG1=${1} -SERVICE=freeside-selfservice-xmlrpcd - -if [ -f /etc/rc.d/init.d/freeside-functions ] -then - . /etc/rc.d/init.d/freeside-functions -else - echo "ERROR: freeside-functions could not be sourced." - exit 1 -fi - -STARTCOMMAND=($SERVICE $SELFSERVICE_USER) -LOCKFILE=${LOCKFILE_DIR}/${SERVICE} -PIDFILE=${PIDFILE_DIR}/freeside/${SERVICE}.pid - -case $ARG1 in - -start) - # if our parameter is 'start' we should run this - startfunc -;; - -stop) - # if our parameter is 'stop' we should run this - stopfunc -;; - -restart) - # if our parameter is 'restart' we should run this - restartfunc -;; - -status) - # display the status of our service using the echo_statusfunc function - echo_statusfunc -;; - -*) - # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 - echo "Syntax Error... usage: $0 (start|stop|restart|status)" - exit 1 -;; - -# close up that case -esac diff --git a/init.d/freeside-cdrd.init b/init.d/freeside-service.init.in similarity index 75% rename from init.d/freeside-cdrd.init rename to init.d/freeside-service.init.in index 3e72afdf90..a4d5505376 100644 --- a/init.d/freeside-cdrd.init +++ b/init.d/freeside-service.init.in @@ -1,23 +1,23 @@ #!/bin/bash -# description: Manage the freeside-cdrd script service, SYS-V style +# description: Manage the %%%SERVICE%%% script service, SYS-V style # chkconfig: 2345 10 90 ARG1=${1} -SERVICE=freeside-cdrd +SERVICE=%%%SERVICE%%%% -if [ -f /etc/rc.d/init.d/freeside-functions ] +if [ -f /etc/init.d/freeside-functions ] then - . /etc/rc.d/init.d/freeside-functions + . /etc/init.d/freeside-functions else echo "ERROR: freeside-functions could not be sourced." exit 1 fi -STARTCOMMAND=($SERVICE $QUEUED_USER) +STARTCOMMAND=(%%%STARTCOMMAND%%%) LOCKFILE=${LOCKFILE_DIR}/${SERVICE} -PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid +PIDFILE=%%%PIDFILE%%% case $ARG1 in diff --git a/init.d/freeside-sqlradius-radacctd.init b/init.d/freeside-sqlradius-radacctd.init deleted file mode 100644 index 066d9e683c..0000000000 --- a/init.d/freeside-sqlradius-radacctd.init +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -# description: Manage the freeside-sqlradius-radacctd script service, SYS-V style -# chkconfig: 2345 10 90 - - -ARG1=${1} -SERVICE=freeside-sqlradius-radacctd - -if [ -f /etc/rc.d/init.d/freeside-functions ] -then - . /etc/rc.d/init.d/freeside-functions -else - echo "ERROR: freeside-functions could not be sourced." - exit 1 -fi - -STARTCOMMAND=($SERVICE $QUEUED_USER) -LOCKFILE=${LOCKFILE_DIR}/${SERVICE} -PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid - -case $ARG1 in - -start) - # if our parameter is 'start' we should run this - startfunc -;; - -stop) - # if our parameter is 'stop' we should run this - stopfunc -;; - -restart) - # if our parameter is 'restart' we should run this - restartfunc -;; - -status) - # display the status of our service using the echo_statusfunc function - echo_statusfunc -;; - -*) - # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 - echo "Syntax Error... usage: $0 (start|stop|restart|status)" - exit 1 -;; - -# close up that case -esac diff --git a/init.d/freeside-torrus-srvderive.init b/init.d/freeside-torrus-srvderive.init deleted file mode 100644 index cb096202c7..0000000000 --- a/init.d/freeside-torrus-srvderive.init +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -# description: Manage the freeside-torrus-srvderive script service, SYS-V style -# chkconfig: 2345 10 90 - - -ARG1=${1} -SERVICE=freeside-torrus-srvderive - -if [ -f /etc/rc.d/init.d/freeside-functions ] -then - . /etc/rc.d/init.d/freeside-functions -else - echo "ERROR: freeside-functions could not be sourced." - exit 1 -fi - -STARTCOMMAND=($SERVICE $QUEUED_USER) -LOCKFILE=${LOCKFILE_DIR}/${SERVICE} -PIDFILE=${PIDFILE_DIR}/${SERVICE}.pid - -case $ARG1 in - -start) - # if our parameter is 'start' we should run this - startfunc -;; - -stop) - # if our parameter is 'stop' we should run this - stopfunc -;; - -restart) - # if our parameter is 'restart' we should run this - restartfunc -;; - -status) - # display the status of our service using the echo_statusfunc function - echo_statusfunc -;; - -*) - # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 - echo "Syntax Error... usage: $0 (start|stop|restart|status)" - exit 1 -;; - -# close up that case -esac diff --git a/init.d/freeside-torrus.init b/init.d/freeside-torrus.init deleted file mode 100644 index d06051c902..0000000000 --- a/init.d/freeside-torrus.init +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -# description: Manage the torrus script service, SYS-V style -# chkconfig: 2345 10 90 - - -ARG1=${1} -SERVICE=torrus - -if [ -f /etc/rc.d/init.d/freeside-functions ] -then - . /etc/rc.d/init.d/freeside-functions -else -then - echo "ERROR: freeside-functions could not be sourced." - exit 1 -fi - -LOCKFILE=${LOCKFILE_DIR}/${SERVICE} -PIDFILE=${PIDFILE_DIR}/torrus/collector.main_?.pid -STARTCOMMAND=(${SERVICE} collector --tree=main) - - -case $ARG1 in - -start) - # if our parameter is 'start' we should run this - startfunc -;; - -stop) - # if our parameter is 'stop' we should run this - stopfunc -;; - -restart) - # if our parameter is 'restart' we should run this - restartfunc -;; - -status) - # display the status of our service using the echo_statusfunc function - echo_statusfunc -;; - -*) - # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 - echo "Syntax Error... usage: $0 (start|stop|restart|status)" - exit 1 -;; - -# close up that case -esac diff --git a/init.d/freeside-xmlrpcd.init b/init.d/freeside-xmlrpcd.init deleted file mode 100644 index 4ad8fa8316..0000000000 --- a/init.d/freeside-xmlrpcd.init +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -# description: Manage the freeside-xmlrpcd script service, SYS-V style -# chkconfig: 2345 10 90 - - -ARG1=${1} -SERVICE=freeside-xmlrpcd - -if [ -f /etc/rc.d/init.d/freeside-functions ] -then - . /etc/rc.d/init.d/freeside-functions -else - echo "ERROR: freeside-functions could not be sourced." - exit 1 -fi - -STARTCOMMAND=($SERVICE $API_USER) -LOCKFILE=${LOCKFILE_DIR}/${SERVICE} -PIDFILE=${PIDFILE_DIR}/freeside/${SERVICE}.pid - - -case $ARG1 in - -start) - # if our parameter is 'start' we should run this - startfunc -;; - -stop) - # if our parameter is 'stop' we should run this - stopfunc -;; - -restart) - # if our parameter is 'restart' we should run this - restartfunc -;; - -status) - # display the status of our service using the echo_statusfunc function - echo_statusfunc -;; - -*) - # catchall case statement... if we get a parameter that we don't understand show the syntax and exit with and error code of >0 - echo "Syntax Error... usage: $0 (start|stop|restart|status)" - exit 1 -;; - -# close up that case -esac From 675c9ac668e661b042d32e52461d9c5a9a61354b Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Mon, 15 Dec 2014 22:16:20 -0800 Subject: [PATCH 35/40] fix "too much recursion" calendar javascript error --- httemplate/elements/calendar.js | 2 ++ httemplate/elements/calendar_stripped.js | 15 +-------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/httemplate/elements/calendar.js b/httemplate/elements/calendar.js index f5c74f608d..ccc963d8ad 100644 --- a/httemplate/elements/calendar.js +++ b/httemplate/elements/calendar.js @@ -1790,6 +1790,7 @@ Date.prototype.print = function (str) { return str; }; +if ( !Date.prototype.__msh_oldSetFullYear ) { Date.prototype.__msh_oldSetFullYear = Date.prototype.setFullYear; Date.prototype.setFullYear = function(y) { var d = new Date(this); @@ -1798,6 +1799,7 @@ Date.prototype.setFullYear = function(y) { this.setDate(28); this.__msh_oldSetFullYear(y); }; +} // END: DATE OBJECT PATCHES diff --git a/httemplate/elements/calendar_stripped.js b/httemplate/elements/calendar_stripped.js index 4fe03f1ea9..d2d1e0cb12 100644 --- a/httemplate/elements/calendar_stripped.js +++ b/httemplate/elements/calendar_stripped.js @@ -1,14 +1 @@ -/* Copyright Mihai Bazon, 2002-2005 | www.bazon.net/mishoo - * ----------------------------------------------------------- - * - * The DHTML Calendar, version 1.0 "It is happening again" - * - * Details and latest version at: - * www.dynarch.com/projects/calendar - * - * This script is developed by Dynarch.com. Visit us at www.dynarch.com. - * - * This script is distributed under the GNU Lesser General Public License. - * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html - */ - Calendar=function(firstDayOfWeek,dateStr,onSelected,onClose){this.activeDiv=null;this.currentDateEl=null;this.getDateStatus=null;this.getDateToolTip=null;this.getDateText=null;this.timeout=null;this.onSelected=onSelected||null;this.onClose=onClose||null;this.dragging=false;this.hidden=false;this.minYear=1970;this.maxYear=2050;this.dateFormat=Calendar._TT["DEF_DATE_FORMAT"];this.ttDateFormat=Calendar._TT["TT_DATE_FORMAT"];this.isPopup=true;this.weekNumbers=true;this.firstDayOfWeek=typeof firstDayOfWeek=="number"?firstDayOfWeek:Calendar._FD;this.showsOtherMonths=false;this.dateStr=dateStr;this.ar_days=null;this.showsTime=false;this.time24=true;this.yearStep=2;this.hiliteToday=true;this.multiple=null;this.table=null;this.element=null;this.tbody=null;this.firstdayname=null;this.monthsCombo=null;this.yearsCombo=null;this.hilitedMonth=null;this.activeMonth=null;this.hilitedYear=null;this.activeYear=null;this.dateClicked=false;if(typeof Calendar._SDN=="undefined"){if(typeof Calendar._SDN_len=="undefined")Calendar._SDN_len=3;var ar=new Array();for(var i=8;i>0;){ar[--i]=Calendar._DN[i].substr(0,Calendar._SDN_len);}Calendar._SDN=ar;if(typeof Calendar._SMN_len=="undefined")Calendar._SMN_len=3;ar=new Array();for(var i=12;i>0;){ar[--i]=Calendar._MN[i].substr(0,Calendar._SMN_len);}Calendar._SMN=ar;}};Calendar._C=null;Calendar.is_ie=(/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent));Calendar.is_ie5=(Calendar.is_ie&&/msie 5\.0/i.test(navigator.userAgent));Calendar.is_opera=/opera/i.test(navigator.userAgent);Calendar.is_khtml=/Konqueror|Safari|KHTML/i.test(navigator.userAgent);Calendar.getAbsolutePos=function(el){var SL=0,ST=0;var is_div=/^div$/i.test(el.tagName);if(is_div&&el.scrollLeft)SL=el.scrollLeft;if(is_div&&el.scrollTop)ST=el.scrollTop;var r={x:el.offsetLeft-SL,y:el.offsetTop-ST};if(el.offsetParent){var tmp=this.getAbsolutePos(el.offsetParent);r.x+=tmp.x;r.y+=tmp.y;}return r;};Calendar.isRelated=function(el,evt){var related=evt.relatedTarget;if(!related){var type=evt.type;if(type=="mouseover"){related=evt.fromElement;}else if(type=="mouseout"){related=evt.toElement;}}while(related){if(related==el){return true;}related=related.parentNode;}return false;};Calendar.removeClass=function(el,className){if(!(el&&el.className)){return;}var cls=el.className.split(" ");var ar=new Array();for(var i=cls.length;i>0;){if(cls[--i]!=className){ar[ar.length]=cls[i];}}el.className=ar.join(" ");};Calendar.addClass=function(el,className){Calendar.removeClass(el,className);el.className+=" "+className;};Calendar.getElement=function(ev){var f=Calendar.is_ie?window.event.srcElement:ev.currentTarget;while(f.nodeType!=1||/^div$/i.test(f.tagName))f=f.parentNode;return f;};Calendar.getTargetElement=function(ev){var f=Calendar.is_ie?window.event.srcElement:ev.target;while(f.nodeType!=1)f=f.parentNode;return f;};Calendar.stopEvent=function(ev){ev||(ev=window.event);if(Calendar.is_ie){ev.cancelBubble=true;ev.returnValue=false;}else{ev.preventDefault();ev.stopPropagation();}return false;};Calendar.addEvent=function(el,evname,func){if(el.attachEvent){el.attachEvent("on"+evname,func);}else if(el.addEventListener){el.addEventListener(evname,func,true);}else{el["on"+evname]=func;}};Calendar.removeEvent=function(el,evname,func){if(el.detachEvent){el.detachEvent("on"+evname,func);}else if(el.removeEventListener){el.removeEventListener(evname,func,true);}else{el["on"+evname]=null;}};Calendar.createElement=function(type,parent){var el=null;if(document.createElementNS){el=document.createElementNS("http://www.w3.org/1999/xhtml",type);}else{el=document.createElement(type);}if(typeof parent!="undefined"){parent.appendChild(el);}return el;};Calendar._add_evs=function(el){with(Calendar){addEvent(el,"mouseover",dayMouseOver);addEvent(el,"mousedown",dayMouseDown);addEvent(el,"mouseout",dayMouseOut);if(is_ie){addEvent(el,"dblclick",dayMouseDblClick);el.setAttribute("unselectable",true);}}};Calendar.findMonth=function(el){if(typeof el.month!="undefined"){return el;}else if(typeof el.parentNode.month!="undefined"){return el.parentNode;}return null;};Calendar.findYear=function(el){if(typeof el.year!="undefined"){return el;}else if(typeof el.parentNode.year!="undefined"){return el.parentNode;}return null;};Calendar.showMonthsCombo=function(){var cal=Calendar._C;if(!cal){return false;}var cal=cal;var cd=cal.activeDiv;var mc=cal.monthsCombo;if(cal.hilitedMonth){Calendar.removeClass(cal.hilitedMonth,"hilite");}if(cal.activeMonth){Calendar.removeClass(cal.activeMonth,"active");}var mon=cal.monthsCombo.getElementsByTagName("div")[cal.date.getMonth()];Calendar.addClass(mon,"active");cal.activeMonth=mon;var s=mc.style;s.display="block";if(cd.navtype<0)s.left=cd.offsetLeft+"px";else{var mcw=mc.offsetWidth;if(typeof mcw=="undefined")mcw=50;s.left=(cd.offsetLeft+cd.offsetWidth-mcw)+"px";}s.top=(cd.offsetTop+cd.offsetHeight)+"px";};Calendar.showYearsCombo=function(fwd){var cal=Calendar._C;if(!cal){return false;}var cal=cal;var cd=cal.activeDiv;var yc=cal.yearsCombo;if(cal.hilitedYear){Calendar.removeClass(cal.hilitedYear,"hilite");}if(cal.activeYear){Calendar.removeClass(cal.activeYear,"active");}cal.activeYear=null;var Y=cal.date.getFullYear()+(fwd?1:-1);var yr=yc.firstChild;var show=false;for(var i=12;i>0;--i){if(Y>=cal.minYear&&Y<=cal.maxYear){yr.innerHTML=Y;yr.year=Y;yr.style.display="block";show=true;}else{yr.style.display="none";}yr=yr.nextSibling;Y+=fwd?cal.yearStep:-cal.yearStep;}if(show){var s=yc.style;s.display="block";if(cd.navtype<0)s.left=cd.offsetLeft+"px";else{var ycw=yc.offsetWidth;if(typeof ycw=="undefined")ycw=50;s.left=(cd.offsetLeft+cd.offsetWidth-ycw)+"px";}s.top=(cd.offsetTop+cd.offsetHeight)+"px";}};Calendar.tableMouseUp=function(ev){var cal=Calendar._C;if(!cal){return false;}if(cal.timeout){clearTimeout(cal.timeout);}var el=cal.activeDiv;if(!el){return false;}var target=Calendar.getTargetElement(ev);ev||(ev=window.event);Calendar.removeClass(el,"active");if(target==el||target.parentNode==el){Calendar.cellClick(el,ev);}var mon=Calendar.findMonth(target);var date=null;if(mon){date=new Date(cal.date);if(mon.month!=date.getMonth()){date.setMonth(mon.month);cal.setDate(date);cal.dateClicked=false;cal.callHandler();}}else{var year=Calendar.findYear(target);if(year){date=new Date(cal.date);if(year.year!=date.getFullYear()){date.setFullYear(year.year);cal.setDate(date);cal.dateClicked=false;cal.callHandler();}}}with(Calendar){removeEvent(document,"mouseup",tableMouseUp);removeEvent(document,"mouseover",tableMouseOver);removeEvent(document,"mousemove",tableMouseOver);cal._hideCombos();_C=null;return stopEvent(ev);}};Calendar.tableMouseOver=function(ev){var cal=Calendar._C;if(!cal){return;}var el=cal.activeDiv;var target=Calendar.getTargetElement(ev);if(target==el||target.parentNode==el){Calendar.addClass(el,"hilite active");Calendar.addClass(el.parentNode,"rowhilite");}else{if(typeof el.navtype=="undefined"||(el.navtype!=50&&(el.navtype==0||Math.abs(el.navtype)>2)))Calendar.removeClass(el,"active");Calendar.removeClass(el,"hilite");Calendar.removeClass(el.parentNode,"rowhilite");}ev||(ev=window.event);if(el.navtype==50&&target!=el){var pos=Calendar.getAbsolutePos(el);var w=el.offsetWidth;var x=ev.clientX;var dx;var decrease=true;if(x>pos.x+w){dx=x-pos.x-w;decrease=false;}else dx=pos.x-x;if(dx<0)dx=0;var range=el._range;var current=el._current;var count=Math.floor(dx/10)%range.length;for(var i=range.length;--i>=0;)if(range[i]==current)break;while(count-->0)if(decrease){if(--i<0)i=range.length-1;}else if(++i>=range.length)i=0;var newval=range[i];el.innerHTML=newval;cal.onUpdateTime();}var mon=Calendar.findMonth(target);if(mon){if(mon.month!=cal.date.getMonth()){if(cal.hilitedMonth){Calendar.removeClass(cal.hilitedMonth,"hilite");}Calendar.addClass(mon,"hilite");cal.hilitedMonth=mon;}else if(cal.hilitedMonth){Calendar.removeClass(cal.hilitedMonth,"hilite");}}else{if(cal.hilitedMonth){Calendar.removeClass(cal.hilitedMonth,"hilite");}var year=Calendar.findYear(target);if(year){if(year.year!=cal.date.getFullYear()){if(cal.hilitedYear){Calendar.removeClass(cal.hilitedYear,"hilite");}Calendar.addClass(year,"hilite");cal.hilitedYear=year;}else if(cal.hilitedYear){Calendar.removeClass(cal.hilitedYear,"hilite");}}else if(cal.hilitedYear){Calendar.removeClass(cal.hilitedYear,"hilite");}}return Calendar.stopEvent(ev);};Calendar.tableMouseDown=function(ev){if(Calendar.getTargetElement(ev)==Calendar.getElement(ev)){return Calendar.stopEvent(ev);}};Calendar.calDragIt=function(ev){var cal=Calendar._C;if(!(cal&&cal.dragging)){return false;}var posX;var posY;if(Calendar.is_ie){posY=window.event.clientY+document.body.scrollTop;posX=window.event.clientX+document.body.scrollLeft;}else{posX=ev.pageX;posY=ev.pageY;}cal.hideShowCovered();var st=cal.element.style;st.left=(posX-cal.xOffs)+"px";st.top=(posY-cal.yOffs)+"px";return Calendar.stopEvent(ev);};Calendar.calDragEnd=function(ev){var cal=Calendar._C;if(!cal){return false;}cal.dragging=false;with(Calendar){removeEvent(document,"mousemove",calDragIt);removeEvent(document,"mouseup",calDragEnd);tableMouseUp(ev);}cal.hideShowCovered();};Calendar.dayMouseDown=function(ev){var el=Calendar.getElement(ev);if(el.disabled){return false;}var cal=el.calendar;cal.activeDiv=el;Calendar._C=cal;if(el.navtype!=300)with(Calendar){if(el.navtype==50){el._current=el.innerHTML;addEvent(document,"mousemove",tableMouseOver);}else addEvent(document,Calendar.is_ie5?"mousemove":"mouseover",tableMouseOver);addClass(el,"hilite active");addEvent(document,"mouseup",tableMouseUp);}else if(cal.isPopup){cal._dragStart(ev);}if(el.navtype==-1||el.navtype==1){if(cal.timeout)clearTimeout(cal.timeout);cal.timeout=setTimeout("Calendar.showMonthsCombo()",250);}else if(el.navtype==-2||el.navtype==2){if(cal.timeout)clearTimeout(cal.timeout);cal.timeout=setTimeout((el.navtype>0)?"Calendar.showYearsCombo(true)":"Calendar.showYearsCombo(false)",250);}else{cal.timeout=null;}return Calendar.stopEvent(ev);};Calendar.dayMouseDblClick=function(ev){Calendar.cellClick(Calendar.getElement(ev),ev||window.event);if(Calendar.is_ie){document.selection.empty();}};Calendar.dayMouseOver=function(ev){var el=Calendar.getElement(ev);if(Calendar.isRelated(el,ev)||Calendar._C||el.disabled){return false;}if(el.ttip){if(el.ttip.substr(0,1)=="_"){el.ttip=el.caldate.print(el.calendar.ttDateFormat)+el.ttip.substr(1);}el.calendar.tooltips.innerHTML=el.ttip;}if(el.navtype!=300){Calendar.addClass(el,"hilite");if(el.caldate){Calendar.addClass(el.parentNode,"rowhilite");}}return Calendar.stopEvent(ev);};Calendar.dayMouseOut=function(ev){with(Calendar){var el=getElement(ev);if(isRelated(el,ev)||_C||el.disabled)return false;removeClass(el,"hilite");if(el.caldate)removeClass(el.parentNode,"rowhilite");if(el.calendar)el.calendar.tooltips.innerHTML=_TT["SEL_DATE"];return stopEvent(ev);}};Calendar.cellClick=function(el,ev){var cal=el.calendar;var closing=false;var newdate=false;var date=null;if(typeof el.navtype=="undefined"){if(cal.currentDateEl){Calendar.removeClass(cal.currentDateEl,"selected");Calendar.addClass(el,"selected");closing=(cal.currentDateEl==el);if(!closing){cal.currentDateEl=el;}}cal.date.setDateOnly(el.caldate);date=cal.date;var other_month=!(cal.dateClicked=!el.otherMonth);if(!other_month&&!cal.currentDateEl)cal._toggleMultipleDate(new Date(date));else newdate=!el.disabled;if(other_month)cal._init(cal.firstDayOfWeek,date);}else{if(el.navtype==200){Calendar.removeClass(el,"hilite");cal.callCloseHandler();return;}date=new Date(cal.date);if(el.navtype==0)date.setDateOnly(new Date());cal.dateClicked=false;var year=date.getFullYear();var mon=date.getMonth();function setMonth(m){var day=date.getDate();var max=date.getMonthDays(m);if(day>max){date.setDate(max);}date.setMonth(m);};switch(el.navtype){case 400:Calendar.removeClass(el,"hilite");var text=Calendar._TT["ABOUT"];if(typeof text!="undefined"){text+=cal.showsTime?Calendar._TT["ABOUT_TIME"]:"";}else{text="Help and about box text is not translated into this language.\n"+"If you know this language and you feel generous please update\n"+"the corresponding file in \"lang\" subdir to match calendar-en.js\n"+"and send it back to to get it into the distribution ;-)\n\n"+"Thank you!\n"+"http://dynarch.com/mishoo/calendar.epl\n";}alert(text);return;case-2:if(year>cal.minYear){date.setFullYear(year-1);}break;case-1:if(mon>0){setMonth(mon-1);}else if(year-->cal.minYear){date.setFullYear(year);setMonth(11);}break;case 1:if(mon<11){setMonth(mon+1);}else if(year=0;)if(range[i]==current)break;if(ev&&ev.shiftKey){if(--i<0)i=range.length-1;}else if(++i>=range.length)i=0;var newval=range[i];el.innerHTML=newval;cal.onUpdateTime();return;case 0:if((typeof cal.getDateStatus=="function")&&cal.getDateStatus(date,date.getFullYear(),date.getMonth(),date.getDate())){return false;}break;}if(!date.equalsTo(cal.date)){cal.setDate(date);newdate=true;}else if(el.navtype==0)newdate=closing=true;}if(newdate){ev&&cal.callHandler();}if(closing){Calendar.removeClass(el,"hilite");ev&&cal.callCloseHandler();}};Calendar.prototype.create=function(_par){var parent=null;if(!_par){parent=document.getElementsByTagName("body")[0];this.isPopup=true;}else{parent=_par;this.isPopup=false;}this.date=this.dateStr?new Date(this.dateStr):new Date();var table=Calendar.createElement("table");this.table=table;table.cellSpacing=0;table.cellPadding=0;table.calendar=this;Calendar.addEvent(table,"mousedown",Calendar.tableMouseDown);var div=Calendar.createElement("div");this.element=div;div.className="calendar";if(this.isPopup){div.style.position="absolute";div.style.display="none";}div.appendChild(table);var thead=Calendar.createElement("thead",table);var cell=null;var row=null;var cal=this;var hh=function(text,cs,navtype){cell=Calendar.createElement("td",row);cell.colSpan=cs;cell.className="button";if(navtype!=0&&Math.abs(navtype)<=2)cell.className+=" nav";Calendar._add_evs(cell);cell.calendar=cal;cell.navtype=navtype;cell.innerHTML="
"+text+"
";return cell;};row=Calendar.createElement("tr",thead);var title_length=6;(this.isPopup)&&--title_length;(this.weekNumbers)&&++title_length;hh("?",1,400).ttip=Calendar._TT["INFO"];this.title=hh("",title_length,300);this.title.className="title";if(this.isPopup){this.title.ttip=Calendar._TT["DRAG_TO_MOVE"];this.title.style.cursor="move";hh("×",1,200).ttip=Calendar._TT["CLOSE"];}row=Calendar.createElement("tr",thead);row.className="headrow";this._nav_py=hh("«",1,-2);this._nav_py.ttip=Calendar._TT["PREV_YEAR"];this._nav_pm=hh("‹",1,-1);this._nav_pm.ttip=Calendar._TT["PREV_MONTH"];this._nav_now=hh(Calendar._TT["TODAY"],this.weekNumbers?4:3,0);this._nav_now.ttip=Calendar._TT["GO_TODAY"];this._nav_nm=hh("›",1,1);this._nav_nm.ttip=Calendar._TT["NEXT_MONTH"];this._nav_ny=hh("»",1,2);this._nav_ny.ttip=Calendar._TT["NEXT_YEAR"];row=Calendar.createElement("tr",thead);row.className="daynames";if(this.weekNumbers){cell=Calendar.createElement("td",row);cell.className="name wn";cell.innerHTML=Calendar._TT["WK"];}for(var i=7;i>0;--i){cell=Calendar.createElement("td",row);if(!i){cell.navtype=100;cell.calendar=this;Calendar._add_evs(cell);}}this.firstdayname=(this.weekNumbers)?row.firstChild.nextSibling:row.firstChild;this._displayWeekdays();var tbody=Calendar.createElement("tbody",table);this.tbody=tbody;for(i=6;i>0;--i){row=Calendar.createElement("tr",tbody);if(this.weekNumbers){cell=Calendar.createElement("td",row);}for(var j=7;j>0;--j){cell=Calendar.createElement("td",row);cell.calendar=this;Calendar._add_evs(cell);}}if(this.showsTime){row=Calendar.createElement("tr",tbody);row.className="time";cell=Calendar.createElement("td",row);cell.className="time";cell.colSpan=2;cell.innerHTML=Calendar._TT["TIME"]||" ";cell=Calendar.createElement("td",row);cell.className="time";cell.colSpan=this.weekNumbers?4:3;(function(){function makeTimePart(className,init,range_start,range_end){var part=Calendar.createElement("span",cell);part.className=className;part.innerHTML=init;part.calendar=cal;part.ttip=Calendar._TT["TIME_PART"];part.navtype=50;part._range=[];if(typeof range_start!="number")part._range=range_start;else{for(var i=range_start;i<=range_end;++i){var txt;if(i<10&&range_end>=10)txt='0'+i;else txt=''+i;part._range[part._range.length]=txt;}}Calendar._add_evs(part);return part;};var hrs=cal.date.getHours();var mins=cal.date.getMinutes();var t12=!cal.time24;var pm=(hrs>12);if(t12&&pm)hrs-=12;var H=makeTimePart("hour",hrs,t12?1:0,t12?12:23);var span=Calendar.createElement("span",cell);span.innerHTML=":";span.className="colon";var M=makeTimePart("minute",mins,0,59);var AP=null;cell=Calendar.createElement("td",row);cell.className="time";cell.colSpan=2;if(t12)AP=makeTimePart("ampm",pm?"pm":"am",["am","pm"]);else cell.innerHTML=" ";cal.onSetTime=function(){var pm,hrs=this.date.getHours(),mins=this.date.getMinutes();if(t12){pm=(hrs>=12);if(pm)hrs-=12;if(hrs==0)hrs=12;AP.innerHTML=pm?"pm":"am";}H.innerHTML=(hrs<10)?("0"+hrs):hrs;M.innerHTML=(mins<10)?("0"+mins):mins;};cal.onUpdateTime=function(){var date=this.date;var h=parseInt(H.innerHTML,10);if(t12){if(/pm/i.test(AP.innerHTML)&&h<12)h+=12;else if(/am/i.test(AP.innerHTML)&&h==12)h=0;}var d=date.getDate();var m=date.getMonth();var y=date.getFullYear();date.setHours(h);date.setMinutes(parseInt(M.innerHTML,10));date.setFullYear(y);date.setMonth(m);date.setDate(d);this.dateClicked=false;this.callHandler();};})();}else{this.onSetTime=this.onUpdateTime=function(){};}var tfoot=Calendar.createElement("tfoot",table);row=Calendar.createElement("tr",tfoot);row.className="footrow";cell=hh(Calendar._TT["SEL_DATE"],this.weekNumbers?8:7,300);cell.className="ttip";if(this.isPopup){cell.ttip=Calendar._TT["DRAG_TO_MOVE"];cell.style.cursor="move";}this.tooltips=cell;div=Calendar.createElement("div",this.element);this.monthsCombo=div;div.className="combo";for(i=0;i0;--i){var yr=Calendar.createElement("div");yr.className=Calendar.is_ie?"label-IEfix":"label";div.appendChild(yr);}this._init(this.firstDayOfWeek,this.date);parent.appendChild(this.element);};Calendar._keyEvent=function(ev){var cal=window._dynarch_popupCalendar;if(!cal||cal.multiple)return false;(Calendar.is_ie)&&(ev=window.event);var act=(Calendar.is_ie||ev.type=="keypress"),K=ev.keyCode;if(ev.ctrlKey){switch(K){case 37:act&&Calendar.cellClick(cal._nav_pm);break;case 38:act&&Calendar.cellClick(cal._nav_py);break;case 39:act&&Calendar.cellClick(cal._nav_nm);break;case 40:act&&Calendar.cellClick(cal._nav_ny);break;default:return false;}}else switch(K){case 32:Calendar.cellClick(cal._nav_now);break;case 27:act&&cal.callCloseHandler();break;case 37:case 38:case 39:case 40:if(act){var prev,x,y,ne,el,step;prev=K==37||K==38;step=(K==37||K==39)?1:7;function setVars(){el=cal.currentDateEl;var p=el.pos;x=p&15;y=p>>4;ne=cal.ar_days[y][x];};setVars();function prevMonth(){var date=new Date(cal.date);date.setDate(date.getDate()-step);cal.setDate(date);};function nextMonth(){var date=new Date(cal.date);date.setDate(date.getDate()+step);cal.setDate(date);};while(1){switch(K){case 37:if(--x>=0)ne=cal.ar_days[y][x];else{x=6;K=38;continue;}break;case 38:if(--y>=0)ne=cal.ar_days[y][x];else{prevMonth();setVars();}break;case 39:if(++x<7)ne=cal.ar_days[y][x];else{x=0;K=40;continue;}break;case 40:if(++ythis.maxYear){year=this.maxYear;date.setFullYear(year);}this.firstDayOfWeek=firstDayOfWeek;this.date=new Date(date);var month=date.getMonth();var mday=date.getDate();var no_days=date.getMonthDays();date.setDate(1);var day1=(date.getDay()-this.firstDayOfWeek)%7;if(day1<0)day1+=7;date.setDate(-day1);date.setDate(date.getDate()+1);var row=this.tbody.firstChild;var MN=Calendar._SMN[month];var ar_days=this.ar_days=new Array();var weekend=Calendar._TT["WEEKEND"];var dates=this.multiple?(this.datesCells={}):null;for(var i=0;i<6;++i,row=row.nextSibling){var cell=row.firstChild;if(this.weekNumbers){cell.className="day wn";cell.innerHTML=date.getWeekNumber();cell=cell.nextSibling;}row.className="daysrow";var hasdays=false,iday,dpos=ar_days[i]=[];for(var j=0;j<7;++j,cell=cell.nextSibling,date.setDate(iday+1)){iday=date.getDate();var wday=date.getDay();cell.className="day";cell.pos=i<<4|j;dpos[j]=cell;var current_month=(date.getMonth()==month);if(!current_month){if(this.showsOtherMonths){cell.className+=" othermonth";cell.otherMonth=true;}else{cell.className="emptycell";cell.innerHTML=" ";cell.disabled=true;continue;}}else{cell.otherMonth=false;hasdays=true;}cell.disabled=false;cell.innerHTML=this.getDateText?this.getDateText(date,iday):iday;if(dates)dates[date.print("%Y%m%d")]=cell;if(this.getDateStatus){var status=this.getDateStatus(date,year,month,iday);if(this.getDateToolTip){var toolTip=this.getDateToolTip(date,year,month,iday);if(toolTip)cell.title=toolTip;}if(status===true){cell.className+=" disabled";cell.disabled=true;}else{if(/disabled/i.test(status))cell.disabled=true;cell.className+=" "+status;}}if(!cell.disabled){cell.caldate=new Date(date);cell.ttip="_";if(!this.multiple&¤t_month&&iday==mday&&this.hiliteToday){cell.className+=" selected";this.currentDateEl=cell;}if(date.getFullYear()==TY&&date.getMonth()==TM&&iday==TD){cell.className+=" today";cell.ttip+=Calendar._TT["PART_TODAY"];}if(weekend.indexOf(wday.toString())!=-1)cell.className+=cell.otherMonth?" oweekend":" weekend";}}if(!(hasdays||this.showsOtherMonths))row.className="emptyrow";}this.title.innerHTML=Calendar._MN[month]+", "+year;this.onSetTime();this.table.style.visibility="visible";this._initMultipleDates();};Calendar.prototype._initMultipleDates=function(){if(this.multiple){for(var i in this.multiple){var cell=this.datesCells[i];var d=this.multiple[i];if(!d)continue;if(cell)cell.className+=" selected";}}};Calendar.prototype._toggleMultipleDate=function(date){if(this.multiple){var ds=date.print("%Y%m%d");var cell=this.datesCells[ds];if(cell){var d=this.multiple[ds];if(!d){Calendar.addClass(cell,"selected");this.multiple[ds]=date;}else{Calendar.removeClass(cell,"selected");delete this.multiple[ds];}}}};Calendar.prototype.setDateToolTipHandler=function(unaryFunction){this.getDateToolTip=unaryFunction;};Calendar.prototype.setDate=function(date){if(!date.equalsTo(this.date)){this._init(this.firstDayOfWeek,date);}};Calendar.prototype.refresh=function(){this._init(this.firstDayOfWeek,this.date);};Calendar.prototype.setFirstDayOfWeek=function(firstDayOfWeek){this._init(firstDayOfWeek,this.date);this._displayWeekdays();};Calendar.prototype.setDateStatusHandler=Calendar.prototype.setDisabledHandler=function(unaryFunction){this.getDateStatus=unaryFunction;};Calendar.prototype.setRange=function(a,z){this.minYear=a;this.maxYear=z;};Calendar.prototype.callHandler=function(){if(this.onSelected){this.onSelected(this,this.date.print(this.dateFormat));}};Calendar.prototype.callCloseHandler=function(){if(this.onClose){this.onClose(this);}this.hideShowCovered();};Calendar.prototype.destroy=function(){var el=this.element.parentNode;el.removeChild(this.element);Calendar._C=null;window._dynarch_popupCalendar=null;};Calendar.prototype.reparent=function(new_parent){var el=this.element;el.parentNode.removeChild(el);new_parent.appendChild(el);};Calendar._checkCalendar=function(ev){var calendar=window._dynarch_popupCalendar;if(!calendar){return false;}var el=Calendar.is_ie?Calendar.getElement(ev):Calendar.getTargetElement(ev);for(;el!=null&&el!=calendar.element;el=el.parentNode);if(el==null){window._dynarch_popupCalendar.callCloseHandler();return Calendar.stopEvent(ev);}};Calendar.prototype.show=function(){var rows=this.table.getElementsByTagName("tr");for(var i=rows.length;i>0;){var row=rows[--i];Calendar.removeClass(row,"rowhilite");var cells=row.getElementsByTagName("td");for(var j=cells.length;j>0;){var cell=cells[--j];Calendar.removeClass(cell,"hilite");Calendar.removeClass(cell,"active");}}this.element.style.display="block";this.hidden=false;if(this.isPopup){window._dynarch_popupCalendar=this;Calendar.addEvent(document,"keydown",Calendar._keyEvent);Calendar.addEvent(document,"keypress",Calendar._keyEvent);Calendar.addEvent(document,"mousedown",Calendar._checkCalendar);}this.hideShowCovered();};Calendar.prototype.hide=function(){if(this.isPopup){Calendar.removeEvent(document,"keydown",Calendar._keyEvent);Calendar.removeEvent(document,"keypress",Calendar._keyEvent);Calendar.removeEvent(document,"mousedown",Calendar._checkCalendar);}this.element.style.display="none";this.hidden=true;this.hideShowCovered();};Calendar.prototype.showAt=function(x,y){var s=this.element.style;s.left=x+"px";s.top=y+"px";this.show();};Calendar.prototype.showAtElement=function(el,opts){var self=this;var p=Calendar.getAbsolutePos(el);if(!opts||typeof opts!="string"){this.showAt(p.x,p.y+el.offsetHeight);return true;}function fixPosition(box){if(box.x<0)box.x=0;if(box.y<0)box.y=0;var cp=document.createElement("div");var s=cp.style;s.position="absolute";s.right=s.bottom=s.width=s.height="0px";document.body.appendChild(cp);var br=Calendar.getAbsolutePos(cp);document.body.removeChild(cp);if(Calendar.is_ie){br.y+=document.body.scrollTop;br.x+=document.body.scrollLeft;}else{br.y+=window.scrollY;br.x+=window.scrollX;}var tmp=box.x+box.width-br.x;if(tmp>0)box.x-=tmp;tmp=box.y+box.height-br.y;if(tmp>0)box.y-=tmp;};this.element.style.display="block";Calendar.continuation_for_the_fucking_khtml_browser=function(){var w=self.element.offsetWidth;var h=self.element.offsetHeight;self.element.style.display="none";var valign=opts.substr(0,1);var halign="l";if(opts.length>1){halign=opts.substr(1,1);}switch(valign){case "T":p.y-=h;break;case "B":p.y+=el.offsetHeight;break;case "C":p.y+=(el.offsetHeight-h)/2;break;case "t":p.y+=el.offsetHeight-h;break;case "b":break;}switch(halign){case "L":p.x-=w;break;case "R":p.x+=el.offsetWidth;break;case "C":p.x+=(el.offsetWidth-w)/2;break;case "l":p.x+=el.offsetWidth-w;break;case "r":break;}p.width=w;p.height=h+40;self.monthsCombo.style.display="none";fixPosition(p);self.showAt(p.x,p.y);};if(Calendar.is_khtml)setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()",10);else Calendar.continuation_for_the_fucking_khtml_browser();};Calendar.prototype.setDateFormat=function(str){this.dateFormat=str;};Calendar.prototype.setTtDateFormat=function(str){this.ttDateFormat=str;};Calendar.prototype.parseDate=function(str,fmt){if(!fmt)fmt=this.dateFormat;this.setDate(Date.parseDate(str,fmt));};Calendar.prototype.hideShowCovered=function(){if(!Calendar.is_ie&&!Calendar.is_opera)return;function getVisib(obj){var value=obj.style.visibility;if(!value){if(document.defaultView&&typeof(document.defaultView.getComputedStyle)=="function"){if(!Calendar.is_khtml)value=document.defaultView. getComputedStyle(obj,"").getPropertyValue("visibility");else value='';}else if(obj.currentStyle){value=obj.currentStyle.visibility;}else value='';}return value;};var tags=new Array("applet","iframe","select");var el=this.element;var p=Calendar.getAbsolutePos(el);var EX1=p.x;var EX2=el.offsetWidth+EX1;var EY1=p.y;var EY2=el.offsetHeight+EY1;for(var k=tags.length;k>0;){var ar=document.getElementsByTagName(tags[--k]);var cc=null;for(var i=ar.length;i>0;){cc=ar[--i];p=Calendar.getAbsolutePos(cc);var CX1=p.x;var CX2=cc.offsetWidth+CX1;var CY1=p.y;var CY2=cc.offsetHeight+CY1;if(this.hidden||(CX1>EX2)||(CX2EY2)||(CY229)?1900:2000);break;case "%b":case "%B":for(j=0;j<12;++j){if(Calendar._MN[j].substr(0,a[i].length).toLowerCase()==a[i].toLowerCase()){m=j;break;}}break;case "%H":case "%I":case "%k":case "%l":hr=parseInt(a[i],10);break;case "%P":case "%p":if(/pm/i.test(a[i])&&hr<12)hr+=12;else if(/am/i.test(a[i])&&hr>=12)hr-=12;break;case "%M":min=parseInt(a[i],10);break;}}if(isNaN(y))y=today.getFullYear();if(isNaN(m))m=today.getMonth();if(isNaN(d))d=today.getDate();if(isNaN(hr))hr=today.getHours();if(isNaN(min))min=today.getMinutes();if(y!=0&&m!=-1&&d!=0)return new Date(y,m,d,hr,min,0);y=0;m=-1;d=0;for(i=0;i31&&y==0){y=parseInt(a[i],10);(y<100)&&(y+=(y>29)?1900:2000);}else if(d==0){d=a[i];}}if(y==0)y=today.getFullYear();if(m!=-1&&d!=0)return new Date(y,m,d,hr,min,0);return today;};Date.prototype.getMonthDays=function(month){var year=this.getFullYear();if(typeof month=="undefined"){month=this.getMonth();}if(((0==(year%4))&&((0!=(year%100))||(0==(year%400))))&&month==1){return 29;}else{return Date._MD[month];}};Date.prototype.getDayOfYear=function(){var now=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0);var then=new Date(this.getFullYear(),0,0,0,0,0);var time=now-then;return Math.floor(time/Date.DAY);};Date.prototype.getWeekNumber=function(){var d=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0);var DoW=d.getDay();d.setDate(d.getDate()-(DoW+6)%7+3);var ms=d.valueOf();d.setMonth(0);d.setDate(4);return Math.round((ms-d.valueOf())/(7*864e5))+1;};Date.prototype.equalsTo=function(date){return((this.getFullYear()==date.getFullYear())&&(this.getMonth()==date.getMonth())&&(this.getDate()==date.getDate())&&(this.getHours()==date.getHours())&&(this.getMinutes()==date.getMinutes()));};Date.prototype.setDateOnly=function(date){var tmp=new Date(date);this.setDate(1);this.setFullYear(tmp.getFullYear());this.setMonth(tmp.getMonth());this.setDate(tmp.getDate());};Date.prototype.print=function(str){var m=this.getMonth();var d=this.getDate();var y=this.getFullYear();var wn=this.getWeekNumber();var w=this.getDay();var s={};var hr=this.getHours();var pm=(hr>=12);var ir=(pm)?(hr-12):hr;var dy=this.getDayOfYear();if(ir==0)ir=12;var min=this.getMinutes();var sec=this.getSeconds();s["%a"]=Calendar._SDN[w];s["%A"]=Calendar._DN[w];s["%b"]=Calendar._SMN[m];s["%B"]=Calendar._MN[m];s["%C"]=1+Math.floor(y/100);s["%d"]=(d<10)?("0"+d):d;s["%e"]=d;s["%H"]=(hr<10)?("0"+hr):hr;s["%I"]=(ir<10)?("0"+ir):ir;s["%j"]=(dy<100)?((dy<10)?("00"+dy):("0"+dy)):dy;s["%k"]=hr;s["%l"]=ir;s["%m"]=(m<9)?("0"+(1+m)):(1+m);s["%M"]=(min<10)?("0"+min):min;s["%n"]="\n";s["%p"]=pm?"PM":"AM";s["%P"]=pm?"pm":"am";s["%s"]=Math.floor(this.getTime()/1000);s["%S"]=(sec<10)?("0"+sec):sec;s["%t"]="\t";s["%U"]=s["%W"]=s["%V"]=(wn<10)?("0"+wn):wn;s["%u"]=w+1;s["%w"]=w;s["%y"]=(''+y).substr(2,2);s["%Y"]=y;s["%%"]="%";var re=/%./g;if(!Calendar.is_ie5&&!Calendar.is_khtml)return str.replace(re,function(par){return s[par]||par;});var a=str.match(re);for(var i=0;i0;)ar[--i]=Calendar._DN[i].substr(0,Calendar._SDN_len);Calendar._SDN=ar,"undefined"==typeof Calendar._SMN_len&&(Calendar._SMN_len=3),ar=new Array;for(var i=12;i>0;)ar[--i]=Calendar._MN[i].substr(0,Calendar._SMN_len);Calendar._SMN=ar}},Calendar._C=null,Calendar.is_ie=/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent),Calendar.is_ie5=Calendar.is_ie&&/msie 5\.0/i.test(navigator.userAgent),Calendar.is_opera=/opera/i.test(navigator.userAgent),Calendar.is_khtml=/Konqueror|Safari|KHTML/i.test(navigator.userAgent),Calendar.getAbsolutePos=function(el){var SL=0,ST=0,is_div=/^div$/i.test(el.tagName);is_div&&el.scrollLeft&&(SL=el.scrollLeft),is_div&&el.scrollTop&&(ST=el.scrollTop);var r={x:el.offsetLeft-SL,y:el.offsetTop-ST};if(el.offsetParent){var tmp=this.getAbsolutePos(el.offsetParent);r.x+=tmp.x,r.y+=tmp.y}return r},Calendar.isRelated=function(el,evt){var related=evt.relatedTarget;if(!related){var type=evt.type;"mouseover"==type?related=evt.fromElement:"mouseout"==type&&(related=evt.toElement)}for(;related;){if(related==el)return!0;related=related.parentNode}return!1},Calendar.removeClass=function(el,className){if(el&&el.className){for(var cls=el.className.split(" "),ar=new Array,i=cls.length;i>0;)cls[--i]!=className&&(ar[ar.length]=cls[i]);el.className=ar.join(" ")}},Calendar.addClass=function(el,className){Calendar.removeClass(el,className),el.className+=" "+className},Calendar.getElement=function(ev){for(var f=Calendar.is_ie?window.event.srcElement:ev.currentTarget;1!=f.nodeType||/^div$/i.test(f.tagName);)f=f.parentNode;return f},Calendar.getTargetElement=function(ev){for(var f=Calendar.is_ie?window.event.srcElement:ev.target;1!=f.nodeType;)f=f.parentNode;return f},Calendar.stopEvent=function(ev){return ev||(ev=window.event),Calendar.is_ie?(ev.cancelBubble=!0,ev.returnValue=!1):(ev.preventDefault(),ev.stopPropagation()),!1},Calendar.addEvent=function(el,evname,func){el.attachEvent?el.attachEvent("on"+evname,func):el.addEventListener?el.addEventListener(evname,func,!0):el["on"+evname]=func},Calendar.removeEvent=function(el,evname,func){el.detachEvent?el.detachEvent("on"+evname,func):el.removeEventListener?el.removeEventListener(evname,func,!0):el["on"+evname]=null},Calendar.createElement=function(type,parent){var el=null;return el=document.createElementNS?document.createElementNS("http://www.w3.org/1999/xhtml",type):document.createElement(type),"undefined"!=typeof parent&&parent.appendChild(el),el},Calendar._add_evs=function(el){with(Calendar)addEvent(el,"mouseover",dayMouseOver),addEvent(el,"mousedown",dayMouseDown),addEvent(el,"mouseout",dayMouseOut),is_ie&&(addEvent(el,"dblclick",dayMouseDblClick),el.setAttribute("unselectable",!0))},Calendar.findMonth=function(el){return"undefined"!=typeof el.month?el:"undefined"!=typeof el.parentNode.month?el.parentNode:null},Calendar.findYear=function(el){return"undefined"!=typeof el.year?el:"undefined"!=typeof el.parentNode.year?el.parentNode:null},Calendar.showMonthsCombo=function(){var cal=Calendar._C;if(!cal)return!1;var cal=cal,cd=cal.activeDiv,mc=cal.monthsCombo;cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite"),cal.activeMonth&&Calendar.removeClass(cal.activeMonth,"active");var mon=cal.monthsCombo.getElementsByTagName("div")[cal.date.getMonth()];Calendar.addClass(mon,"active"),cal.activeMonth=mon;var s=mc.style;if(s.display="block",cd.navtype<0)s.left=cd.offsetLeft+"px";else{var mcw=mc.offsetWidth;"undefined"==typeof mcw&&(mcw=50),s.left=cd.offsetLeft+cd.offsetWidth-mcw+"px"}s.top=cd.offsetTop+cd.offsetHeight+"px"},Calendar.showYearsCombo=function(fwd){var cal=Calendar._C;if(!cal)return!1;var cal=cal,cd=cal.activeDiv,yc=cal.yearsCombo;cal.hilitedYear&&Calendar.removeClass(cal.hilitedYear,"hilite"),cal.activeYear&&Calendar.removeClass(cal.activeYear,"active"),cal.activeYear=null;for(var Y=cal.date.getFullYear()+(fwd?1:-1),yr=yc.firstChild,show=!1,i=12;i>0;--i)Y>=cal.minYear&&Y<=cal.maxYear?(yr.innerHTML=Y,yr.year=Y,yr.style.display="block",show=!0):yr.style.display="none",yr=yr.nextSibling,Y+=fwd?cal.yearStep:-cal.yearStep;if(show){var s=yc.style;if(s.display="block",cd.navtype<0)s.left=cd.offsetLeft+"px";else{var ycw=yc.offsetWidth;"undefined"==typeof ycw&&(ycw=50),s.left=cd.offsetLeft+cd.offsetWidth-ycw+"px"}s.top=cd.offsetTop+cd.offsetHeight+"px"}},Calendar.tableMouseUp=function(ev){var cal=Calendar._C;if(!cal)return!1;cal.timeout&&clearTimeout(cal.timeout);var el=cal.activeDiv;if(!el)return!1;var target=Calendar.getTargetElement(ev);ev||(ev=window.event),Calendar.removeClass(el,"active"),(target==el||target.parentNode==el)&&Calendar.cellClick(el,ev);var mon=Calendar.findMonth(target),date=null;if(mon)date=new Date(cal.date),mon.month!=date.getMonth()&&(date.setMonth(mon.month),cal.setDate(date),cal.dateClicked=!1,cal.callHandler());else{var year=Calendar.findYear(target);year&&(date=new Date(cal.date),year.year!=date.getFullYear()&&(date.setFullYear(year.year),cal.setDate(date),cal.dateClicked=!1,cal.callHandler()))}with(Calendar)return removeEvent(document,"mouseup",tableMouseUp),removeEvent(document,"mouseover",tableMouseOver),removeEvent(document,"mousemove",tableMouseOver),cal._hideCombos(),_C=null,stopEvent(ev)},Calendar.tableMouseOver=function(ev){var cal=Calendar._C;if(cal){var el=cal.activeDiv,target=Calendar.getTargetElement(ev);if(target==el||target.parentNode==el?(Calendar.addClass(el,"hilite active"),Calendar.addClass(el.parentNode,"rowhilite")):(("undefined"==typeof el.navtype||50!=el.navtype&&(0==el.navtype||Math.abs(el.navtype)>2))&&Calendar.removeClass(el,"active"),Calendar.removeClass(el,"hilite"),Calendar.removeClass(el.parentNode,"rowhilite")),ev||(ev=window.event),50==el.navtype&&target!=el){var dx,pos=Calendar.getAbsolutePos(el),w=el.offsetWidth,x=ev.clientX,decrease=!0;x>pos.x+w?(dx=x-pos.x-w,decrease=!1):dx=pos.x-x,0>dx&&(dx=0);for(var range=el._range,current=el._current,count=Math.floor(dx/10)%range.length,i=range.length;--i>=0&&range[i]!=current;);for(;count-->0;)decrease?--i<0&&(i=range.length-1):++i>=range.length&&(i=0);var newval=range[i];el.innerHTML=newval,cal.onUpdateTime()}var mon=Calendar.findMonth(target);if(mon)mon.month!=cal.date.getMonth()?(cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite"),Calendar.addClass(mon,"hilite"),cal.hilitedMonth=mon):cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite");else{cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite");var year=Calendar.findYear(target);year&&year.year!=cal.date.getFullYear()?(cal.hilitedYear&&Calendar.removeClass(cal.hilitedYear,"hilite"),Calendar.addClass(year,"hilite"),cal.hilitedYear=year):cal.hilitedYear&&Calendar.removeClass(cal.hilitedYear,"hilite")}return Calendar.stopEvent(ev)}},Calendar.tableMouseDown=function(ev){return Calendar.getTargetElement(ev)==Calendar.getElement(ev)?Calendar.stopEvent(ev):void 0},Calendar.calDragIt=function(ev){var cal=Calendar._C;if(!cal||!cal.dragging)return!1;var posX,posY;Calendar.is_ie?(posY=window.event.clientY+document.body.scrollTop,posX=window.event.clientX+document.body.scrollLeft):(posX=ev.pageX,posY=ev.pageY),cal.hideShowCovered();var st=cal.element.style;return st.left=posX-cal.xOffs+"px",st.top=posY-cal.yOffs+"px",Calendar.stopEvent(ev)},Calendar.calDragEnd=function(ev){var cal=Calendar._C;if(!cal)return!1;with(cal.dragging=!1,Calendar)removeEvent(document,"mousemove",calDragIt),removeEvent(document,"mouseup",calDragEnd),tableMouseUp(ev);cal.hideShowCovered()},Calendar.dayMouseDown=function(ev){var el=Calendar.getElement(ev);if(el.disabled)return!1;var cal=el.calendar;if(cal.activeDiv=el,Calendar._C=cal,300!=el.navtype)with(Calendar)50==el.navtype?(el._current=el.innerHTML,addEvent(document,"mousemove",tableMouseOver)):addEvent(document,Calendar.is_ie5?"mousemove":"mouseover",tableMouseOver),addClass(el,"hilite active"),addEvent(document,"mouseup",tableMouseUp);else cal.isPopup&&cal._dragStart(ev);return-1==el.navtype||1==el.navtype?(cal.timeout&&clearTimeout(cal.timeout),cal.timeout=setTimeout("Calendar.showMonthsCombo()",250)):-2==el.navtype||2==el.navtype?(cal.timeout&&clearTimeout(cal.timeout),cal.timeout=setTimeout(el.navtype>0?"Calendar.showYearsCombo(true)":"Calendar.showYearsCombo(false)",250)):cal.timeout=null,Calendar.stopEvent(ev)},Calendar.dayMouseDblClick=function(ev){Calendar.cellClick(Calendar.getElement(ev),ev||window.event),Calendar.is_ie&&document.selection.empty()},Calendar.dayMouseOver=function(ev){var el=Calendar.getElement(ev);return Calendar.isRelated(el,ev)||Calendar._C||el.disabled?!1:(el.ttip&&("_"==el.ttip.substr(0,1)&&(el.ttip=el.caldate.print(el.calendar.ttDateFormat)+el.ttip.substr(1)),el.calendar.tooltips.innerHTML=el.ttip),300!=el.navtype&&(Calendar.addClass(el,"hilite"),el.caldate&&Calendar.addClass(el.parentNode,"rowhilite")),Calendar.stopEvent(ev))},Calendar.dayMouseOut=function(ev){with(Calendar){var el=getElement(ev);return isRelated(el,ev)||_C||el.disabled?!1:(removeClass(el,"hilite"),el.caldate&&removeClass(el.parentNode,"rowhilite"),el.calendar&&(el.calendar.tooltips.innerHTML=_TT.SEL_DATE),stopEvent(ev))}},Calendar.cellClick=function(el,ev){function setMonth(m){var day=date.getDate(),max=date.getMonthDays(m);day>max&&date.setDate(max),date.setMonth(m)}var cal=el.calendar,closing=!1,newdate=!1,date=null;if("undefined"==typeof el.navtype){cal.currentDateEl&&(Calendar.removeClass(cal.currentDateEl,"selected"),Calendar.addClass(el,"selected"),closing=cal.currentDateEl==el,closing||(cal.currentDateEl=el)),cal.date.setDateOnly(el.caldate),date=cal.date;var other_month=!(cal.dateClicked=!el.otherMonth);other_month||cal.currentDateEl?newdate=!el.disabled:cal._toggleMultipleDate(new Date(date)),other_month&&cal._init(cal.firstDayOfWeek,date)}else{if(200==el.navtype)return Calendar.removeClass(el,"hilite"),void cal.callCloseHandler();date=new Date(cal.date),0==el.navtype&&date.setDateOnly(new Date),cal.dateClicked=!1;var year=date.getFullYear(),mon=date.getMonth();switch(el.navtype){case 400:Calendar.removeClass(el,"hilite");var text=Calendar._TT.ABOUT;return"undefined"!=typeof text?text+=cal.showsTime?Calendar._TT.ABOUT_TIME:"":text='Help and about box text is not translated into this language.\nIf you know this language and you feel generous please update\nthe corresponding file in "lang" subdir to match calendar-en.js\nand send it back to to get it into the distribution ;-)\n\nThank you!\nhttp://dynarch.com/mishoo/calendar.epl\n',void alert(text);case-2:year>cal.minYear&&date.setFullYear(year-1);break;case-1:mon>0?setMonth(mon-1):year-->cal.minYear&&(date.setFullYear(year),setMonth(11));break;case 1:11>mon?setMonth(mon+1):year=0&&range[i]!=current;);ev&&ev.shiftKey?--i<0&&(i=range.length-1):++i>=range.length&&(i=0);var newval=range[i];return el.innerHTML=newval,void cal.onUpdateTime();case 0:if("function"==typeof cal.getDateStatus&&cal.getDateStatus(date,date.getFullYear(),date.getMonth(),date.getDate()))return!1}date.equalsTo(cal.date)?0==el.navtype&&(newdate=closing=!0):(cal.setDate(date),newdate=!0)}newdate&&ev&&cal.callHandler(),closing&&(Calendar.removeClass(el,"hilite"),ev&&cal.callCloseHandler())},Calendar.prototype.create=function(_par){var parent=null;_par?(parent=_par,this.isPopup=!1):(parent=document.getElementsByTagName("body")[0],this.isPopup=!0),this.date=this.dateStr?new Date(this.dateStr):new Date;var table=Calendar.createElement("table");this.table=table,table.cellSpacing=0,table.cellPadding=0,table.calendar=this,Calendar.addEvent(table,"mousedown",Calendar.tableMouseDown);var div=Calendar.createElement("div");this.element=div,div.className="calendar",this.isPopup&&(div.style.position="absolute",div.style.display="none"),div.appendChild(table);var thead=Calendar.createElement("thead",table),cell=null,row=null,cal=this,hh=function(text,cs,navtype){return cell=Calendar.createElement("td",row),cell.colSpan=cs,cell.className="button",0!=navtype&&Math.abs(navtype)<=2&&(cell.className+=" nav"),Calendar._add_evs(cell),cell.calendar=cal,cell.navtype=navtype,cell.innerHTML="
"+text+"
",cell};row=Calendar.createElement("tr",thead);var title_length=6;this.isPopup&&--title_length,this.weekNumbers&&++title_length,hh("?",1,400).ttip=Calendar._TT.INFO,this.title=hh("",title_length,300),this.title.className="title",this.isPopup&&(this.title.ttip=Calendar._TT.DRAG_TO_MOVE,this.title.style.cursor="move",hh("×",1,200).ttip=Calendar._TT.CLOSE),row=Calendar.createElement("tr",thead),row.className="headrow",this._nav_py=hh("«",1,-2),this._nav_py.ttip=Calendar._TT.PREV_YEAR,this._nav_pm=hh("‹",1,-1),this._nav_pm.ttip=Calendar._TT.PREV_MONTH,this._nav_now=hh(Calendar._TT.TODAY,this.weekNumbers?4:3,0),this._nav_now.ttip=Calendar._TT.GO_TODAY,this._nav_nm=hh("›",1,1),this._nav_nm.ttip=Calendar._TT.NEXT_MONTH,this._nav_ny=hh("»",1,2),this._nav_ny.ttip=Calendar._TT.NEXT_YEAR,row=Calendar.createElement("tr",thead),row.className="daynames",this.weekNumbers&&(cell=Calendar.createElement("td",row),cell.className="name wn",cell.innerHTML=Calendar._TT.WK);for(var i=7;i>0;--i)cell=Calendar.createElement("td",row),i||(cell.navtype=100,cell.calendar=this,Calendar._add_evs(cell));this.firstdayname=this.weekNumbers?row.firstChild.nextSibling:row.firstChild,this._displayWeekdays();var tbody=Calendar.createElement("tbody",table);for(this.tbody=tbody,i=6;i>0;--i){row=Calendar.createElement("tr",tbody),this.weekNumbers&&(cell=Calendar.createElement("td",row));for(var j=7;j>0;--j)cell=Calendar.createElement("td",row),cell.calendar=this,Calendar._add_evs(cell)}this.showsTime?(row=Calendar.createElement("tr",tbody),row.className="time",cell=Calendar.createElement("td",row),cell.className="time",cell.colSpan=2,cell.innerHTML=Calendar._TT.TIME||" ",cell=Calendar.createElement("td",row),cell.className="time",cell.colSpan=this.weekNumbers?4:3,function(){function makeTimePart(className,init,range_start,range_end){var part=Calendar.createElement("span",cell);if(part.className=className,part.innerHTML=init,part.calendar=cal,part.ttip=Calendar._TT.TIME_PART,part.navtype=50,part._range=[],"number"!=typeof range_start)part._range=range_start;else for(var i=range_start;range_end>=i;++i){var txt;txt=10>i&&range_end>=10?"0"+i:""+i,part._range[part._range.length]=txt}return Calendar._add_evs(part),part}var hrs=cal.date.getHours(),mins=cal.date.getMinutes(),t12=!cal.time24,pm=hrs>12;t12&&pm&&(hrs-=12);var H=makeTimePart("hour",hrs,t12?1:0,t12?12:23),span=Calendar.createElement("span",cell);span.innerHTML=":",span.className="colon";var M=makeTimePart("minute",mins,0,59),AP=null;cell=Calendar.createElement("td",row),cell.className="time",cell.colSpan=2,t12?AP=makeTimePart("ampm",pm?"pm":"am",["am","pm"]):cell.innerHTML=" ",cal.onSetTime=function(){var pm,hrs=this.date.getHours(),mins=this.date.getMinutes();t12&&(pm=hrs>=12,pm&&(hrs-=12),0==hrs&&(hrs=12),AP.innerHTML=pm?"pm":"am"),H.innerHTML=10>hrs?"0"+hrs:hrs,M.innerHTML=10>mins?"0"+mins:mins},cal.onUpdateTime=function(){var date=this.date,h=parseInt(H.innerHTML,10);t12&&(/pm/i.test(AP.innerHTML)&&12>h?h+=12:/am/i.test(AP.innerHTML)&&12==h&&(h=0));var d=date.getDate(),m=date.getMonth(),y=date.getFullYear();date.setHours(h),date.setMinutes(parseInt(M.innerHTML,10)),date.setFullYear(y),date.setMonth(m),date.setDate(d),this.dateClicked=!1,this.callHandler()}}()):this.onSetTime=this.onUpdateTime=function(){};var tfoot=Calendar.createElement("tfoot",table);for(row=Calendar.createElement("tr",tfoot),row.className="footrow",cell=hh(Calendar._TT.SEL_DATE,this.weekNumbers?8:7,300),cell.className="ttip",this.isPopup&&(cell.ttip=Calendar._TT.DRAG_TO_MOVE,cell.style.cursor="move"),this.tooltips=cell,div=Calendar.createElement("div",this.element),this.monthsCombo=div,div.className="combo",i=0;i0;--i){var yr=Calendar.createElement("div");yr.className=Calendar.is_ie?"label-IEfix":"label",div.appendChild(yr)}this._init(this.firstDayOfWeek,this.date),parent.appendChild(this.element)},Calendar._keyEvent=function(ev){function setVars(){el=cal.currentDateEl;var p=el.pos;x=15&p,y=p>>4,ne=cal.ar_days[y][x]}function prevMonth(){var date=new Date(cal.date);date.setDate(date.getDate()-step),cal.setDate(date)}function nextMonth(){var date=new Date(cal.date);date.setDate(date.getDate()+step),cal.setDate(date)}var cal=window._dynarch_popupCalendar;if(!cal||cal.multiple)return!1;Calendar.is_ie&&(ev=window.event);var act=Calendar.is_ie||"keypress"==ev.type,K=ev.keyCode;if(ev.ctrlKey)switch(K){case 37:act&&Calendar.cellClick(cal._nav_pm);break;case 38:act&&Calendar.cellClick(cal._nav_py);break;case 39:act&&Calendar.cellClick(cal._nav_nm);break;case 40:act&&Calendar.cellClick(cal._nav_ny);break;default:return!1}else switch(K){case 32:Calendar.cellClick(cal._nav_now);break;case 27:act&&cal.callCloseHandler();break;case 37:case 38:case 39:case 40:if(act){var prev,x,y,ne,el,step;for(prev=37==K||38==K,step=37==K||39==K?1:7,setVars();;){switch(K){case 37:if(!(--x>=0)){x=6,K=38;continue}ne=cal.ar_days[y][x];break;case 38:--y>=0?ne=cal.ar_days[y][x]:(prevMonth(),setVars());break;case 39:if(!(++x<7)){x=0,K=40;continue}ne=cal.ar_days[y][x];break;case 40:++ythis.maxYear&&(year=this.maxYear,date.setFullYear(year)),this.firstDayOfWeek=firstDayOfWeek,this.date=new Date(date);{var month=date.getMonth(),mday=date.getDate();date.getMonthDays()}date.setDate(1);var day1=(date.getDay()-this.firstDayOfWeek)%7;0>day1&&(day1+=7),date.setDate(-day1),date.setDate(date.getDate()+1);for(var row=this.tbody.firstChild,ar_days=(Calendar._SMN[month],this.ar_days=new Array),weekend=Calendar._TT.WEEKEND,dates=this.multiple?this.datesCells={}:null,i=0;6>i;++i,row=row.nextSibling){var cell=row.firstChild;this.weekNumbers&&(cell.className="day wn",cell.innerHTML=date.getWeekNumber(),cell=cell.nextSibling),row.className="daysrow";for(var iday,hasdays=!1,dpos=ar_days[i]=[],j=0;7>j;++j,cell=cell.nextSibling,date.setDate(iday+1)){iday=date.getDate();var wday=date.getDay();cell.className="day",cell.pos=i<<4|j,dpos[j]=cell;var current_month=date.getMonth()==month;if(current_month)cell.otherMonth=!1,hasdays=!0;else{if(!this.showsOtherMonths){cell.className="emptycell",cell.innerHTML=" ",cell.disabled=!0;continue}cell.className+=" othermonth",cell.otherMonth=!0}if(cell.disabled=!1,cell.innerHTML=this.getDateText?this.getDateText(date,iday):iday,dates&&(dates[date.print("%Y%m%d")]=cell),this.getDateStatus){var status=this.getDateStatus(date,year,month,iday);if(this.getDateToolTip){var toolTip=this.getDateToolTip(date,year,month,iday);toolTip&&(cell.title=toolTip)}status===!0?(cell.className+=" disabled",cell.disabled=!0):(/disabled/i.test(status)&&(cell.disabled=!0),cell.className+=" "+status)}cell.disabled||(cell.caldate=new Date(date),cell.ttip="_",!this.multiple&¤t_month&&iday==mday&&this.hiliteToday&&(cell.className+=" selected",this.currentDateEl=cell),date.getFullYear()==TY&&date.getMonth()==TM&&iday==TD&&(cell.className+=" today",cell.ttip+=Calendar._TT.PART_TODAY),-1!=weekend.indexOf(wday.toString())&&(cell.className+=cell.otherMonth?" oweekend":" weekend"))}hasdays||this.showsOtherMonths||(row.className="emptyrow")}this.title.innerHTML=Calendar._MN[month]+", "+year,this.onSetTime(),this.table.style.visibility="visible",this._initMultipleDates()},Calendar.prototype._initMultipleDates=function(){if(this.multiple)for(var i in this.multiple){var cell=this.datesCells[i],d=this.multiple[i];d&&cell&&(cell.className+=" selected")}},Calendar.prototype._toggleMultipleDate=function(date){if(this.multiple){var ds=date.print("%Y%m%d"),cell=this.datesCells[ds];if(cell){var d=this.multiple[ds];d?(Calendar.removeClass(cell,"selected"),delete this.multiple[ds]):(Calendar.addClass(cell,"selected"),this.multiple[ds]=date)}}},Calendar.prototype.setDateToolTipHandler=function(unaryFunction){this.getDateToolTip=unaryFunction},Calendar.prototype.setDate=function(date){date.equalsTo(this.date)||this._init(this.firstDayOfWeek,date)},Calendar.prototype.refresh=function(){this._init(this.firstDayOfWeek,this.date)},Calendar.prototype.setFirstDayOfWeek=function(firstDayOfWeek){this._init(firstDayOfWeek,this.date),this._displayWeekdays()},Calendar.prototype.setDateStatusHandler=Calendar.prototype.setDisabledHandler=function(unaryFunction){this.getDateStatus=unaryFunction},Calendar.prototype.setRange=function(a,z){this.minYear=a,this.maxYear=z},Calendar.prototype.callHandler=function(){this.onSelected&&this.onSelected(this,this.date.print(this.dateFormat))},Calendar.prototype.callCloseHandler=function(){this.onClose&&this.onClose(this),this.hideShowCovered()},Calendar.prototype.destroy=function(){var el=this.element.parentNode;el.removeChild(this.element),Calendar._C=null,window._dynarch_popupCalendar=null},Calendar.prototype.reparent=function(new_parent){var el=this.element;el.parentNode.removeChild(el),new_parent.appendChild(el)},Calendar._checkCalendar=function(ev){var calendar=window._dynarch_popupCalendar;if(!calendar)return!1;for(var el=Calendar.is_ie?Calendar.getElement(ev):Calendar.getTargetElement(ev);null!=el&&el!=calendar.element;el=el.parentNode);return null==el?(window._dynarch_popupCalendar.callCloseHandler(),Calendar.stopEvent(ev)):void 0},Calendar.prototype.show=function(){for(var rows=this.table.getElementsByTagName("tr"),i=rows.length;i>0;){var row=rows[--i];Calendar.removeClass(row,"rowhilite");for(var cells=row.getElementsByTagName("td"),j=cells.length;j>0;){var cell=cells[--j];Calendar.removeClass(cell,"hilite"),Calendar.removeClass(cell,"active")}}this.element.style.display="block",this.hidden=!1,this.isPopup&&(window._dynarch_popupCalendar=this,Calendar.addEvent(document,"keydown",Calendar._keyEvent),Calendar.addEvent(document,"keypress",Calendar._keyEvent),Calendar.addEvent(document,"mousedown",Calendar._checkCalendar)),this.hideShowCovered()},Calendar.prototype.hide=function(){this.isPopup&&(Calendar.removeEvent(document,"keydown",Calendar._keyEvent),Calendar.removeEvent(document,"keypress",Calendar._keyEvent),Calendar.removeEvent(document,"mousedown",Calendar._checkCalendar)),this.element.style.display="none",this.hidden=!0,this.hideShowCovered()},Calendar.prototype.showAt=function(x,y){var s=this.element.style;s.left=x+"px",s.top=y+"px",this.show()},Calendar.prototype.showAtElement=function(el,opts){function fixPosition(box){box.x<0&&(box.x=0),box.y<0&&(box.y=0);var cp=document.createElement("div"),s=cp.style;s.position="absolute",s.right=s.bottom=s.width=s.height="0px",document.body.appendChild(cp);var br=Calendar.getAbsolutePos(cp);document.body.removeChild(cp),Calendar.is_ie?(br.y+=document.body.scrollTop,br.x+=document.body.scrollLeft):(br.y+=window.scrollY,br.x+=window.scrollX);var tmp=box.x+box.width-br.x;tmp>0&&(box.x-=tmp),tmp=box.y+box.height-br.y,tmp>0&&(box.y-=tmp)}var self=this,p=Calendar.getAbsolutePos(el);return opts&&"string"==typeof opts?(this.element.style.display="block",Calendar.continuation_for_the_fucking_khtml_browser=function(){var w=self.element.offsetWidth,h=self.element.offsetHeight;self.element.style.display="none";var valign=opts.substr(0,1),halign="l";switch(opts.length>1&&(halign=opts.substr(1,1)),valign){case"T":p.y-=h;break;case"B":p.y+=el.offsetHeight;break;case"C":p.y+=(el.offsetHeight-h)/2;break;case"t":p.y+=el.offsetHeight-h;break;case"b":}switch(halign){case"L":p.x-=w;break;case"R":p.x+=el.offsetWidth;break;case"C":p.x+=(el.offsetWidth-w)/2;break;case"l":p.x+=el.offsetWidth-w;break;case"r":}p.width=w,p.height=h+40,self.monthsCombo.style.display="none",fixPosition(p),self.showAt(p.x,p.y)},void(Calendar.is_khtml?setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()",10):Calendar.continuation_for_the_fucking_khtml_browser())):(this.showAt(p.x,p.y+el.offsetHeight),!0)},Calendar.prototype.setDateFormat=function(str){this.dateFormat=str},Calendar.prototype.setTtDateFormat=function(str){this.ttDateFormat=str},Calendar.prototype.parseDate=function(str,fmt){fmt||(fmt=this.dateFormat),this.setDate(Date.parseDate(str,fmt))},Calendar.prototype.hideShowCovered=function(){function getVisib(obj){var value=obj.style.visibility;return value||(value=document.defaultView&&"function"==typeof document.defaultView.getComputedStyle?Calendar.is_khtml?"":document.defaultView.getComputedStyle(obj,"").getPropertyValue("visibility"):obj.currentStyle?obj.currentStyle.visibility:""),value}if(Calendar.is_ie||Calendar.is_opera)for(var tags=new Array("applet","iframe","select"),el=this.element,p=Calendar.getAbsolutePos(el),EX1=p.x,EX2=el.offsetWidth+EX1,EY1=p.y,EY2=el.offsetHeight+EY1,k=tags.length;k>0;)for(var ar=document.getElementsByTagName(tags[--k]),cc=null,i=ar.length;i>0;){cc=ar[--i],p=Calendar.getAbsolutePos(cc);var CX1=p.x,CX2=cc.offsetWidth+CX1,CY1=p.y,CY2=cc.offsetHeight+CY1;this.hidden||CX1>EX2||EX1>CX2||CY1>EY2||EY1>CY2?(cc.__msh_save_visibility||(cc.__msh_save_visibility=getVisib(cc)),cc.style.visibility=cc.__msh_save_visibility):(cc.__msh_save_visibility||(cc.__msh_save_visibility=getVisib(cc)),cc.style.visibility="hidden")}},Calendar.prototype._displayWeekdays=function(){for(var fdow=this.firstDayOfWeek,cell=this.firstdayname,weekend=Calendar._TT.WEEKEND,i=0;7>i;++i){cell.className="day name";var realday=(i+fdow)%7;i&&(cell.ttip=Calendar._TT.DAY_FIRST.replace("%s",Calendar._DN[realday]),cell.navtype=100,cell.calendar=this,cell.fdow=realday,Calendar._add_evs(cell)),-1!=weekend.indexOf(realday.toString())&&Calendar.addClass(cell,"weekend"),cell.innerHTML=Calendar._SDN[(i+fdow)%7],cell=cell.nextSibling}},Calendar.prototype._hideCombos=function(){this.monthsCombo.style.display="none",this.yearsCombo.style.display="none"},Calendar.prototype._dragStart=function(ev){if(!this.dragging){this.dragging=!0;var posX,posY;Calendar.is_ie?(posY=window.event.clientY+document.body.scrollTop,posX=window.event.clientX+document.body.scrollLeft):(posY=ev.clientY+window.scrollY,posX=ev.clientX+window.scrollX);var st=this.element.style;with(this.xOffs=posX-parseInt(st.left),this.yOffs=posY-parseInt(st.top),Calendar)addEvent(document,"mousemove",calDragIt),addEvent(document,"mouseup",calDragEnd)}},Date._MD=new Array(31,28,31,30,31,30,31,31,30,31,30,31),Date.SECOND=1e3,Date.MINUTE=60*Date.SECOND,Date.HOUR=60*Date.MINUTE,Date.DAY=24*Date.HOUR,Date.WEEK=7*Date.DAY,Date.parseDate=function(str,fmt){var today=new Date,y=0,m=-1,d=0,a=str.split(/\W+/),b=fmt.match(/%./g),i=0,j=0,hr=0,min=0;for(i=0;iy&&(y+=y>29?1900:2e3);break;case"%b":case"%B":for(j=0;12>j;++j)if(Calendar._MN[j].substr(0,a[i].length).toLowerCase()==a[i].toLowerCase()){m=j;break}break;case"%H":case"%I":case"%k":case"%l":hr=parseInt(a[i],10);break;case"%P":case"%p":/pm/i.test(a[i])&&12>hr?hr+=12:/am/i.test(a[i])&&hr>=12&&(hr-=12);break;case"%M":min=parseInt(a[i],10)}if(isNaN(y)&&(y=today.getFullYear()),isNaN(m)&&(m=today.getMonth()),isNaN(d)&&(d=today.getDate()),isNaN(hr)&&(hr=today.getHours()),isNaN(min)&&(min=today.getMinutes()),0!=y&&-1!=m&&0!=d)return new Date(y,m,d,hr,min,0);for(y=0,m=-1,d=0,i=0;ij;++j)if(Calendar._MN[j].substr(0,a[i].length).toLowerCase()==a[i].toLowerCase()){t=j;break}-1!=t&&(-1!=m&&(d=m+1),m=t)}else parseInt(a[i],10)<=12&&-1==m?m=a[i]-1:parseInt(a[i],10)>31&&0==y?(y=parseInt(a[i],10),100>y&&(y+=y>29?1900:2e3)):0==d&&(d=a[i]);return 0==y&&(y=today.getFullYear()),-1!=m&&0!=d?new Date(y,m,d,hr,min,0):today},Date.prototype.getMonthDays=function(month){var year=this.getFullYear();return"undefined"==typeof month&&(month=this.getMonth()),0!=year%4||0==year%100&&0!=year%400||1!=month?Date._MD[month]:29},Date.prototype.getDayOfYear=function(){var now=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0),then=new Date(this.getFullYear(),0,0,0,0,0),time=now-then;return Math.floor(time/Date.DAY)},Date.prototype.getWeekNumber=function(){var d=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0),DoW=d.getDay();d.setDate(d.getDate()-(DoW+6)%7+3);var ms=d.valueOf();return d.setMonth(0),d.setDate(4),Math.round((ms-d.valueOf())/6048e5)+1},Date.prototype.equalsTo=function(date){return this.getFullYear()==date.getFullYear()&&this.getMonth()==date.getMonth()&&this.getDate()==date.getDate()&&this.getHours()==date.getHours()&&this.getMinutes()==date.getMinutes()},Date.prototype.setDateOnly=function(date){var tmp=new Date(date);this.setDate(1),this.setFullYear(tmp.getFullYear()),this.setMonth(tmp.getMonth()),this.setDate(tmp.getDate())},Date.prototype.print=function(str){var m=this.getMonth(),d=this.getDate(),y=this.getFullYear(),wn=this.getWeekNumber(),w=this.getDay(),s={},hr=this.getHours(),pm=hr>=12,ir=pm?hr-12:hr,dy=this.getDayOfYear();0==ir&&(ir=12);var min=this.getMinutes(),sec=this.getSeconds();s["%a"]=Calendar._SDN[w],s["%A"]=Calendar._DN[w],s["%b"]=Calendar._SMN[m],s["%B"]=Calendar._MN[m],s["%C"]=1+Math.floor(y/100),s["%d"]=10>d?"0"+d:d,s["%e"]=d,s["%H"]=10>hr?"0"+hr:hr,s["%I"]=10>ir?"0"+ir:ir,s["%j"]=100>dy?10>dy?"00"+dy:"0"+dy:dy,s["%k"]=hr,s["%l"]=ir,s["%m"]=9>m?"0"+(1+m):1+m,s["%M"]=10>min?"0"+min:min,s["%n"]="\n",s["%p"]=pm?"PM":"AM",s["%P"]=pm?"pm":"am",s["%s"]=Math.floor(this.getTime()/1e3),s["%S"]=10>sec?"0"+sec:sec,s["%t"]=" ",s["%U"]=s["%W"]=s["%V"]=10>wn?"0"+wn:wn,s["%u"]=w+1,s["%w"]=w,s["%y"]=(""+y).substr(2,2),s["%Y"]=y,s["%%"]="%";var re=/%./g;if(!Calendar.is_ie5&&!Calendar.is_khtml)return str.replace(re,function(par){return s[par]||par});for(var a=str.match(re),i=0;i Date: Mon, 15 Dec 2014 14:57:10 -0500 Subject: [PATCH 36/40] Debian packages 2916 missing texmf --- debian/rules | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/debian/rules b/debian/rules index 07d3914662..e640398e4e 100755 --- a/debian/rules +++ b/debian/rules @@ -160,6 +160,11 @@ install-stamp: build-stamp # Install interfaces $(MAKE) -e DESTDIR=$(TMP)-webui install-docs + + # Install tex + install -D -o freeside -m 444 etc/longtable.sty \ + $(TMP)-lib/usr/local/share/texmf/tex/latex/longtable.sty + texhash $(TMP)-lib/usr/local/share/texmf # Create Apache configurations install -d $(APACHE_CONF) From f3bbc6cdb668231a3649f98091fe851046ad8094 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Mon, 15 Dec 2014 22:46:40 -0800 Subject: [PATCH 37/40] fix time in payment and credit back-dating, RT#32320 --- httemplate/elements/calendar.js | 19 ++++++++++++++++++- httemplate/elements/calendar_stripped.js | 3 ++- httemplate/elements/input-date-field.html | 5 +++++ httemplate/elements/tr-input-date-field.html | 11 +++++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/httemplate/elements/calendar.js b/httemplate/elements/calendar.js index ccc963d8ad..80c6d1f679 100644 --- a/httemplate/elements/calendar.js +++ b/httemplate/elements/calendar.js @@ -1635,6 +1635,17 @@ Date.parseDate = function(str, fmt) { case "%M": min = parseInt(a[i], 10); break; + + case "%r": + hr = parseInt(a[i], 10); + min = parseInt(a[++i], 10); + var sec = parseInt(a[++i], 10); + if (/pm/i.test(a[++i]) && hr < 12) + hr += 12; + else if (/am/i.test(a[i]) && hr >= 12) + hr -= 12; + break; + } } if (isNaN(y)) y = today.getFullYear(); @@ -1759,7 +1770,13 @@ Date.prototype.print = function (str) { s["%n"] = "\n"; // a newline character s["%p"] = pm ? "PM" : "AM"; s["%P"] = pm ? "pm" : "am"; - // FIXME: %r : the time in am/pm notation %I:%M:%S %p + + // %r : the time in am/pm notation %I:%M:%S %p + s["%r"] = ( (ir < 10) ? ("0" + ir ) : ir ) + ':' + + ( (min < 10) ? ("0" + min) : min ) + ':' + + ( (sec < 10) ? ("0" + sec) : sec ) + ' ' + + (pm ? "PM" : "AM" ); + // FIXME: %R : the time in 24-hour notation %H:%M s["%s"] = Math.floor(this.getTime() / 1000); s["%S"] = (sec < 10) ? ("0" + sec) : sec; // seconds, range 00 to 59 diff --git a/httemplate/elements/calendar_stripped.js b/httemplate/elements/calendar_stripped.js index d2d1e0cb12..ab6512251c 100644 --- a/httemplate/elements/calendar_stripped.js +++ b/httemplate/elements/calendar_stripped.js @@ -1 +1,2 @@ -Calendar=function(firstDayOfWeek,dateStr,onSelected,onClose){if(this.activeDiv=null,this.currentDateEl=null,this.getDateStatus=null,this.getDateToolTip=null,this.getDateText=null,this.timeout=null,this.onSelected=onSelected||null,this.onClose=onClose||null,this.dragging=!1,this.hidden=!1,this.minYear=1970,this.maxYear=2050,this.dateFormat=Calendar._TT.DEF_DATE_FORMAT,this.ttDateFormat=Calendar._TT.TT_DATE_FORMAT,this.isPopup=!0,this.weekNumbers=!0,this.firstDayOfWeek="number"==typeof firstDayOfWeek?firstDayOfWeek:Calendar._FD,this.showsOtherMonths=!1,this.dateStr=dateStr,this.ar_days=null,this.showsTime=!1,this.time24=!0,this.yearStep=2,this.hiliteToday=!0,this.multiple=null,this.table=null,this.element=null,this.tbody=null,this.firstdayname=null,this.monthsCombo=null,this.yearsCombo=null,this.hilitedMonth=null,this.activeMonth=null,this.hilitedYear=null,this.activeYear=null,this.dateClicked=!1,"undefined"==typeof Calendar._SDN){"undefined"==typeof Calendar._SDN_len&&(Calendar._SDN_len=3);for(var ar=new Array,i=8;i>0;)ar[--i]=Calendar._DN[i].substr(0,Calendar._SDN_len);Calendar._SDN=ar,"undefined"==typeof Calendar._SMN_len&&(Calendar._SMN_len=3),ar=new Array;for(var i=12;i>0;)ar[--i]=Calendar._MN[i].substr(0,Calendar._SMN_len);Calendar._SMN=ar}},Calendar._C=null,Calendar.is_ie=/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent),Calendar.is_ie5=Calendar.is_ie&&/msie 5\.0/i.test(navigator.userAgent),Calendar.is_opera=/opera/i.test(navigator.userAgent),Calendar.is_khtml=/Konqueror|Safari|KHTML/i.test(navigator.userAgent),Calendar.getAbsolutePos=function(el){var SL=0,ST=0,is_div=/^div$/i.test(el.tagName);is_div&&el.scrollLeft&&(SL=el.scrollLeft),is_div&&el.scrollTop&&(ST=el.scrollTop);var r={x:el.offsetLeft-SL,y:el.offsetTop-ST};if(el.offsetParent){var tmp=this.getAbsolutePos(el.offsetParent);r.x+=tmp.x,r.y+=tmp.y}return r},Calendar.isRelated=function(el,evt){var related=evt.relatedTarget;if(!related){var type=evt.type;"mouseover"==type?related=evt.fromElement:"mouseout"==type&&(related=evt.toElement)}for(;related;){if(related==el)return!0;related=related.parentNode}return!1},Calendar.removeClass=function(el,className){if(el&&el.className){for(var cls=el.className.split(" "),ar=new Array,i=cls.length;i>0;)cls[--i]!=className&&(ar[ar.length]=cls[i]);el.className=ar.join(" ")}},Calendar.addClass=function(el,className){Calendar.removeClass(el,className),el.className+=" "+className},Calendar.getElement=function(ev){for(var f=Calendar.is_ie?window.event.srcElement:ev.currentTarget;1!=f.nodeType||/^div$/i.test(f.tagName);)f=f.parentNode;return f},Calendar.getTargetElement=function(ev){for(var f=Calendar.is_ie?window.event.srcElement:ev.target;1!=f.nodeType;)f=f.parentNode;return f},Calendar.stopEvent=function(ev){return ev||(ev=window.event),Calendar.is_ie?(ev.cancelBubble=!0,ev.returnValue=!1):(ev.preventDefault(),ev.stopPropagation()),!1},Calendar.addEvent=function(el,evname,func){el.attachEvent?el.attachEvent("on"+evname,func):el.addEventListener?el.addEventListener(evname,func,!0):el["on"+evname]=func},Calendar.removeEvent=function(el,evname,func){el.detachEvent?el.detachEvent("on"+evname,func):el.removeEventListener?el.removeEventListener(evname,func,!0):el["on"+evname]=null},Calendar.createElement=function(type,parent){var el=null;return el=document.createElementNS?document.createElementNS("http://www.w3.org/1999/xhtml",type):document.createElement(type),"undefined"!=typeof parent&&parent.appendChild(el),el},Calendar._add_evs=function(el){with(Calendar)addEvent(el,"mouseover",dayMouseOver),addEvent(el,"mousedown",dayMouseDown),addEvent(el,"mouseout",dayMouseOut),is_ie&&(addEvent(el,"dblclick",dayMouseDblClick),el.setAttribute("unselectable",!0))},Calendar.findMonth=function(el){return"undefined"!=typeof el.month?el:"undefined"!=typeof el.parentNode.month?el.parentNode:null},Calendar.findYear=function(el){return"undefined"!=typeof el.year?el:"undefined"!=typeof el.parentNode.year?el.parentNode:null},Calendar.showMonthsCombo=function(){var cal=Calendar._C;if(!cal)return!1;var cal=cal,cd=cal.activeDiv,mc=cal.monthsCombo;cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite"),cal.activeMonth&&Calendar.removeClass(cal.activeMonth,"active");var mon=cal.monthsCombo.getElementsByTagName("div")[cal.date.getMonth()];Calendar.addClass(mon,"active"),cal.activeMonth=mon;var s=mc.style;if(s.display="block",cd.navtype<0)s.left=cd.offsetLeft+"px";else{var mcw=mc.offsetWidth;"undefined"==typeof mcw&&(mcw=50),s.left=cd.offsetLeft+cd.offsetWidth-mcw+"px"}s.top=cd.offsetTop+cd.offsetHeight+"px"},Calendar.showYearsCombo=function(fwd){var cal=Calendar._C;if(!cal)return!1;var cal=cal,cd=cal.activeDiv,yc=cal.yearsCombo;cal.hilitedYear&&Calendar.removeClass(cal.hilitedYear,"hilite"),cal.activeYear&&Calendar.removeClass(cal.activeYear,"active"),cal.activeYear=null;for(var Y=cal.date.getFullYear()+(fwd?1:-1),yr=yc.firstChild,show=!1,i=12;i>0;--i)Y>=cal.minYear&&Y<=cal.maxYear?(yr.innerHTML=Y,yr.year=Y,yr.style.display="block",show=!0):yr.style.display="none",yr=yr.nextSibling,Y+=fwd?cal.yearStep:-cal.yearStep;if(show){var s=yc.style;if(s.display="block",cd.navtype<0)s.left=cd.offsetLeft+"px";else{var ycw=yc.offsetWidth;"undefined"==typeof ycw&&(ycw=50),s.left=cd.offsetLeft+cd.offsetWidth-ycw+"px"}s.top=cd.offsetTop+cd.offsetHeight+"px"}},Calendar.tableMouseUp=function(ev){var cal=Calendar._C;if(!cal)return!1;cal.timeout&&clearTimeout(cal.timeout);var el=cal.activeDiv;if(!el)return!1;var target=Calendar.getTargetElement(ev);ev||(ev=window.event),Calendar.removeClass(el,"active"),(target==el||target.parentNode==el)&&Calendar.cellClick(el,ev);var mon=Calendar.findMonth(target),date=null;if(mon)date=new Date(cal.date),mon.month!=date.getMonth()&&(date.setMonth(mon.month),cal.setDate(date),cal.dateClicked=!1,cal.callHandler());else{var year=Calendar.findYear(target);year&&(date=new Date(cal.date),year.year!=date.getFullYear()&&(date.setFullYear(year.year),cal.setDate(date),cal.dateClicked=!1,cal.callHandler()))}with(Calendar)return removeEvent(document,"mouseup",tableMouseUp),removeEvent(document,"mouseover",tableMouseOver),removeEvent(document,"mousemove",tableMouseOver),cal._hideCombos(),_C=null,stopEvent(ev)},Calendar.tableMouseOver=function(ev){var cal=Calendar._C;if(cal){var el=cal.activeDiv,target=Calendar.getTargetElement(ev);if(target==el||target.parentNode==el?(Calendar.addClass(el,"hilite active"),Calendar.addClass(el.parentNode,"rowhilite")):(("undefined"==typeof el.navtype||50!=el.navtype&&(0==el.navtype||Math.abs(el.navtype)>2))&&Calendar.removeClass(el,"active"),Calendar.removeClass(el,"hilite"),Calendar.removeClass(el.parentNode,"rowhilite")),ev||(ev=window.event),50==el.navtype&&target!=el){var dx,pos=Calendar.getAbsolutePos(el),w=el.offsetWidth,x=ev.clientX,decrease=!0;x>pos.x+w?(dx=x-pos.x-w,decrease=!1):dx=pos.x-x,0>dx&&(dx=0);for(var range=el._range,current=el._current,count=Math.floor(dx/10)%range.length,i=range.length;--i>=0&&range[i]!=current;);for(;count-->0;)decrease?--i<0&&(i=range.length-1):++i>=range.length&&(i=0);var newval=range[i];el.innerHTML=newval,cal.onUpdateTime()}var mon=Calendar.findMonth(target);if(mon)mon.month!=cal.date.getMonth()?(cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite"),Calendar.addClass(mon,"hilite"),cal.hilitedMonth=mon):cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite");else{cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite");var year=Calendar.findYear(target);year&&year.year!=cal.date.getFullYear()?(cal.hilitedYear&&Calendar.removeClass(cal.hilitedYear,"hilite"),Calendar.addClass(year,"hilite"),cal.hilitedYear=year):cal.hilitedYear&&Calendar.removeClass(cal.hilitedYear,"hilite")}return Calendar.stopEvent(ev)}},Calendar.tableMouseDown=function(ev){return Calendar.getTargetElement(ev)==Calendar.getElement(ev)?Calendar.stopEvent(ev):void 0},Calendar.calDragIt=function(ev){var cal=Calendar._C;if(!cal||!cal.dragging)return!1;var posX,posY;Calendar.is_ie?(posY=window.event.clientY+document.body.scrollTop,posX=window.event.clientX+document.body.scrollLeft):(posX=ev.pageX,posY=ev.pageY),cal.hideShowCovered();var st=cal.element.style;return st.left=posX-cal.xOffs+"px",st.top=posY-cal.yOffs+"px",Calendar.stopEvent(ev)},Calendar.calDragEnd=function(ev){var cal=Calendar._C;if(!cal)return!1;with(cal.dragging=!1,Calendar)removeEvent(document,"mousemove",calDragIt),removeEvent(document,"mouseup",calDragEnd),tableMouseUp(ev);cal.hideShowCovered()},Calendar.dayMouseDown=function(ev){var el=Calendar.getElement(ev);if(el.disabled)return!1;var cal=el.calendar;if(cal.activeDiv=el,Calendar._C=cal,300!=el.navtype)with(Calendar)50==el.navtype?(el._current=el.innerHTML,addEvent(document,"mousemove",tableMouseOver)):addEvent(document,Calendar.is_ie5?"mousemove":"mouseover",tableMouseOver),addClass(el,"hilite active"),addEvent(document,"mouseup",tableMouseUp);else cal.isPopup&&cal._dragStart(ev);return-1==el.navtype||1==el.navtype?(cal.timeout&&clearTimeout(cal.timeout),cal.timeout=setTimeout("Calendar.showMonthsCombo()",250)):-2==el.navtype||2==el.navtype?(cal.timeout&&clearTimeout(cal.timeout),cal.timeout=setTimeout(el.navtype>0?"Calendar.showYearsCombo(true)":"Calendar.showYearsCombo(false)",250)):cal.timeout=null,Calendar.stopEvent(ev)},Calendar.dayMouseDblClick=function(ev){Calendar.cellClick(Calendar.getElement(ev),ev||window.event),Calendar.is_ie&&document.selection.empty()},Calendar.dayMouseOver=function(ev){var el=Calendar.getElement(ev);return Calendar.isRelated(el,ev)||Calendar._C||el.disabled?!1:(el.ttip&&("_"==el.ttip.substr(0,1)&&(el.ttip=el.caldate.print(el.calendar.ttDateFormat)+el.ttip.substr(1)),el.calendar.tooltips.innerHTML=el.ttip),300!=el.navtype&&(Calendar.addClass(el,"hilite"),el.caldate&&Calendar.addClass(el.parentNode,"rowhilite")),Calendar.stopEvent(ev))},Calendar.dayMouseOut=function(ev){with(Calendar){var el=getElement(ev);return isRelated(el,ev)||_C||el.disabled?!1:(removeClass(el,"hilite"),el.caldate&&removeClass(el.parentNode,"rowhilite"),el.calendar&&(el.calendar.tooltips.innerHTML=_TT.SEL_DATE),stopEvent(ev))}},Calendar.cellClick=function(el,ev){function setMonth(m){var day=date.getDate(),max=date.getMonthDays(m);day>max&&date.setDate(max),date.setMonth(m)}var cal=el.calendar,closing=!1,newdate=!1,date=null;if("undefined"==typeof el.navtype){cal.currentDateEl&&(Calendar.removeClass(cal.currentDateEl,"selected"),Calendar.addClass(el,"selected"),closing=cal.currentDateEl==el,closing||(cal.currentDateEl=el)),cal.date.setDateOnly(el.caldate),date=cal.date;var other_month=!(cal.dateClicked=!el.otherMonth);other_month||cal.currentDateEl?newdate=!el.disabled:cal._toggleMultipleDate(new Date(date)),other_month&&cal._init(cal.firstDayOfWeek,date)}else{if(200==el.navtype)return Calendar.removeClass(el,"hilite"),void cal.callCloseHandler();date=new Date(cal.date),0==el.navtype&&date.setDateOnly(new Date),cal.dateClicked=!1;var year=date.getFullYear(),mon=date.getMonth();switch(el.navtype){case 400:Calendar.removeClass(el,"hilite");var text=Calendar._TT.ABOUT;return"undefined"!=typeof text?text+=cal.showsTime?Calendar._TT.ABOUT_TIME:"":text='Help and about box text is not translated into this language.\nIf you know this language and you feel generous please update\nthe corresponding file in "lang" subdir to match calendar-en.js\nand send it back to to get it into the distribution ;-)\n\nThank you!\nhttp://dynarch.com/mishoo/calendar.epl\n',void alert(text);case-2:year>cal.minYear&&date.setFullYear(year-1);break;case-1:mon>0?setMonth(mon-1):year-->cal.minYear&&(date.setFullYear(year),setMonth(11));break;case 1:11>mon?setMonth(mon+1):year=0&&range[i]!=current;);ev&&ev.shiftKey?--i<0&&(i=range.length-1):++i>=range.length&&(i=0);var newval=range[i];return el.innerHTML=newval,void cal.onUpdateTime();case 0:if("function"==typeof cal.getDateStatus&&cal.getDateStatus(date,date.getFullYear(),date.getMonth(),date.getDate()))return!1}date.equalsTo(cal.date)?0==el.navtype&&(newdate=closing=!0):(cal.setDate(date),newdate=!0)}newdate&&ev&&cal.callHandler(),closing&&(Calendar.removeClass(el,"hilite"),ev&&cal.callCloseHandler())},Calendar.prototype.create=function(_par){var parent=null;_par?(parent=_par,this.isPopup=!1):(parent=document.getElementsByTagName("body")[0],this.isPopup=!0),this.date=this.dateStr?new Date(this.dateStr):new Date;var table=Calendar.createElement("table");this.table=table,table.cellSpacing=0,table.cellPadding=0,table.calendar=this,Calendar.addEvent(table,"mousedown",Calendar.tableMouseDown);var div=Calendar.createElement("div");this.element=div,div.className="calendar",this.isPopup&&(div.style.position="absolute",div.style.display="none"),div.appendChild(table);var thead=Calendar.createElement("thead",table),cell=null,row=null,cal=this,hh=function(text,cs,navtype){return cell=Calendar.createElement("td",row),cell.colSpan=cs,cell.className="button",0!=navtype&&Math.abs(navtype)<=2&&(cell.className+=" nav"),Calendar._add_evs(cell),cell.calendar=cal,cell.navtype=navtype,cell.innerHTML="
"+text+"
",cell};row=Calendar.createElement("tr",thead);var title_length=6;this.isPopup&&--title_length,this.weekNumbers&&++title_length,hh("?",1,400).ttip=Calendar._TT.INFO,this.title=hh("",title_length,300),this.title.className="title",this.isPopup&&(this.title.ttip=Calendar._TT.DRAG_TO_MOVE,this.title.style.cursor="move",hh("×",1,200).ttip=Calendar._TT.CLOSE),row=Calendar.createElement("tr",thead),row.className="headrow",this._nav_py=hh("«",1,-2),this._nav_py.ttip=Calendar._TT.PREV_YEAR,this._nav_pm=hh("‹",1,-1),this._nav_pm.ttip=Calendar._TT.PREV_MONTH,this._nav_now=hh(Calendar._TT.TODAY,this.weekNumbers?4:3,0),this._nav_now.ttip=Calendar._TT.GO_TODAY,this._nav_nm=hh("›",1,1),this._nav_nm.ttip=Calendar._TT.NEXT_MONTH,this._nav_ny=hh("»",1,2),this._nav_ny.ttip=Calendar._TT.NEXT_YEAR,row=Calendar.createElement("tr",thead),row.className="daynames",this.weekNumbers&&(cell=Calendar.createElement("td",row),cell.className="name wn",cell.innerHTML=Calendar._TT.WK);for(var i=7;i>0;--i)cell=Calendar.createElement("td",row),i||(cell.navtype=100,cell.calendar=this,Calendar._add_evs(cell));this.firstdayname=this.weekNumbers?row.firstChild.nextSibling:row.firstChild,this._displayWeekdays();var tbody=Calendar.createElement("tbody",table);for(this.tbody=tbody,i=6;i>0;--i){row=Calendar.createElement("tr",tbody),this.weekNumbers&&(cell=Calendar.createElement("td",row));for(var j=7;j>0;--j)cell=Calendar.createElement("td",row),cell.calendar=this,Calendar._add_evs(cell)}this.showsTime?(row=Calendar.createElement("tr",tbody),row.className="time",cell=Calendar.createElement("td",row),cell.className="time",cell.colSpan=2,cell.innerHTML=Calendar._TT.TIME||" ",cell=Calendar.createElement("td",row),cell.className="time",cell.colSpan=this.weekNumbers?4:3,function(){function makeTimePart(className,init,range_start,range_end){var part=Calendar.createElement("span",cell);if(part.className=className,part.innerHTML=init,part.calendar=cal,part.ttip=Calendar._TT.TIME_PART,part.navtype=50,part._range=[],"number"!=typeof range_start)part._range=range_start;else for(var i=range_start;range_end>=i;++i){var txt;txt=10>i&&range_end>=10?"0"+i:""+i,part._range[part._range.length]=txt}return Calendar._add_evs(part),part}var hrs=cal.date.getHours(),mins=cal.date.getMinutes(),t12=!cal.time24,pm=hrs>12;t12&&pm&&(hrs-=12);var H=makeTimePart("hour",hrs,t12?1:0,t12?12:23),span=Calendar.createElement("span",cell);span.innerHTML=":",span.className="colon";var M=makeTimePart("minute",mins,0,59),AP=null;cell=Calendar.createElement("td",row),cell.className="time",cell.colSpan=2,t12?AP=makeTimePart("ampm",pm?"pm":"am",["am","pm"]):cell.innerHTML=" ",cal.onSetTime=function(){var pm,hrs=this.date.getHours(),mins=this.date.getMinutes();t12&&(pm=hrs>=12,pm&&(hrs-=12),0==hrs&&(hrs=12),AP.innerHTML=pm?"pm":"am"),H.innerHTML=10>hrs?"0"+hrs:hrs,M.innerHTML=10>mins?"0"+mins:mins},cal.onUpdateTime=function(){var date=this.date,h=parseInt(H.innerHTML,10);t12&&(/pm/i.test(AP.innerHTML)&&12>h?h+=12:/am/i.test(AP.innerHTML)&&12==h&&(h=0));var d=date.getDate(),m=date.getMonth(),y=date.getFullYear();date.setHours(h),date.setMinutes(parseInt(M.innerHTML,10)),date.setFullYear(y),date.setMonth(m),date.setDate(d),this.dateClicked=!1,this.callHandler()}}()):this.onSetTime=this.onUpdateTime=function(){};var tfoot=Calendar.createElement("tfoot",table);for(row=Calendar.createElement("tr",tfoot),row.className="footrow",cell=hh(Calendar._TT.SEL_DATE,this.weekNumbers?8:7,300),cell.className="ttip",this.isPopup&&(cell.ttip=Calendar._TT.DRAG_TO_MOVE,cell.style.cursor="move"),this.tooltips=cell,div=Calendar.createElement("div",this.element),this.monthsCombo=div,div.className="combo",i=0;i0;--i){var yr=Calendar.createElement("div");yr.className=Calendar.is_ie?"label-IEfix":"label",div.appendChild(yr)}this._init(this.firstDayOfWeek,this.date),parent.appendChild(this.element)},Calendar._keyEvent=function(ev){function setVars(){el=cal.currentDateEl;var p=el.pos;x=15&p,y=p>>4,ne=cal.ar_days[y][x]}function prevMonth(){var date=new Date(cal.date);date.setDate(date.getDate()-step),cal.setDate(date)}function nextMonth(){var date=new Date(cal.date);date.setDate(date.getDate()+step),cal.setDate(date)}var cal=window._dynarch_popupCalendar;if(!cal||cal.multiple)return!1;Calendar.is_ie&&(ev=window.event);var act=Calendar.is_ie||"keypress"==ev.type,K=ev.keyCode;if(ev.ctrlKey)switch(K){case 37:act&&Calendar.cellClick(cal._nav_pm);break;case 38:act&&Calendar.cellClick(cal._nav_py);break;case 39:act&&Calendar.cellClick(cal._nav_nm);break;case 40:act&&Calendar.cellClick(cal._nav_ny);break;default:return!1}else switch(K){case 32:Calendar.cellClick(cal._nav_now);break;case 27:act&&cal.callCloseHandler();break;case 37:case 38:case 39:case 40:if(act){var prev,x,y,ne,el,step;for(prev=37==K||38==K,step=37==K||39==K?1:7,setVars();;){switch(K){case 37:if(!(--x>=0)){x=6,K=38;continue}ne=cal.ar_days[y][x];break;case 38:--y>=0?ne=cal.ar_days[y][x]:(prevMonth(),setVars());break;case 39:if(!(++x<7)){x=0,K=40;continue}ne=cal.ar_days[y][x];break;case 40:++ythis.maxYear&&(year=this.maxYear,date.setFullYear(year)),this.firstDayOfWeek=firstDayOfWeek,this.date=new Date(date);{var month=date.getMonth(),mday=date.getDate();date.getMonthDays()}date.setDate(1);var day1=(date.getDay()-this.firstDayOfWeek)%7;0>day1&&(day1+=7),date.setDate(-day1),date.setDate(date.getDate()+1);for(var row=this.tbody.firstChild,ar_days=(Calendar._SMN[month],this.ar_days=new Array),weekend=Calendar._TT.WEEKEND,dates=this.multiple?this.datesCells={}:null,i=0;6>i;++i,row=row.nextSibling){var cell=row.firstChild;this.weekNumbers&&(cell.className="day wn",cell.innerHTML=date.getWeekNumber(),cell=cell.nextSibling),row.className="daysrow";for(var iday,hasdays=!1,dpos=ar_days[i]=[],j=0;7>j;++j,cell=cell.nextSibling,date.setDate(iday+1)){iday=date.getDate();var wday=date.getDay();cell.className="day",cell.pos=i<<4|j,dpos[j]=cell;var current_month=date.getMonth()==month;if(current_month)cell.otherMonth=!1,hasdays=!0;else{if(!this.showsOtherMonths){cell.className="emptycell",cell.innerHTML=" ",cell.disabled=!0;continue}cell.className+=" othermonth",cell.otherMonth=!0}if(cell.disabled=!1,cell.innerHTML=this.getDateText?this.getDateText(date,iday):iday,dates&&(dates[date.print("%Y%m%d")]=cell),this.getDateStatus){var status=this.getDateStatus(date,year,month,iday);if(this.getDateToolTip){var toolTip=this.getDateToolTip(date,year,month,iday);toolTip&&(cell.title=toolTip)}status===!0?(cell.className+=" disabled",cell.disabled=!0):(/disabled/i.test(status)&&(cell.disabled=!0),cell.className+=" "+status)}cell.disabled||(cell.caldate=new Date(date),cell.ttip="_",!this.multiple&¤t_month&&iday==mday&&this.hiliteToday&&(cell.className+=" selected",this.currentDateEl=cell),date.getFullYear()==TY&&date.getMonth()==TM&&iday==TD&&(cell.className+=" today",cell.ttip+=Calendar._TT.PART_TODAY),-1!=weekend.indexOf(wday.toString())&&(cell.className+=cell.otherMonth?" oweekend":" weekend"))}hasdays||this.showsOtherMonths||(row.className="emptyrow")}this.title.innerHTML=Calendar._MN[month]+", "+year,this.onSetTime(),this.table.style.visibility="visible",this._initMultipleDates()},Calendar.prototype._initMultipleDates=function(){if(this.multiple)for(var i in this.multiple){var cell=this.datesCells[i],d=this.multiple[i];d&&cell&&(cell.className+=" selected")}},Calendar.prototype._toggleMultipleDate=function(date){if(this.multiple){var ds=date.print("%Y%m%d"),cell=this.datesCells[ds];if(cell){var d=this.multiple[ds];d?(Calendar.removeClass(cell,"selected"),delete this.multiple[ds]):(Calendar.addClass(cell,"selected"),this.multiple[ds]=date)}}},Calendar.prototype.setDateToolTipHandler=function(unaryFunction){this.getDateToolTip=unaryFunction},Calendar.prototype.setDate=function(date){date.equalsTo(this.date)||this._init(this.firstDayOfWeek,date)},Calendar.prototype.refresh=function(){this._init(this.firstDayOfWeek,this.date)},Calendar.prototype.setFirstDayOfWeek=function(firstDayOfWeek){this._init(firstDayOfWeek,this.date),this._displayWeekdays()},Calendar.prototype.setDateStatusHandler=Calendar.prototype.setDisabledHandler=function(unaryFunction){this.getDateStatus=unaryFunction},Calendar.prototype.setRange=function(a,z){this.minYear=a,this.maxYear=z},Calendar.prototype.callHandler=function(){this.onSelected&&this.onSelected(this,this.date.print(this.dateFormat))},Calendar.prototype.callCloseHandler=function(){this.onClose&&this.onClose(this),this.hideShowCovered()},Calendar.prototype.destroy=function(){var el=this.element.parentNode;el.removeChild(this.element),Calendar._C=null,window._dynarch_popupCalendar=null},Calendar.prototype.reparent=function(new_parent){var el=this.element;el.parentNode.removeChild(el),new_parent.appendChild(el)},Calendar._checkCalendar=function(ev){var calendar=window._dynarch_popupCalendar;if(!calendar)return!1;for(var el=Calendar.is_ie?Calendar.getElement(ev):Calendar.getTargetElement(ev);null!=el&&el!=calendar.element;el=el.parentNode);return null==el?(window._dynarch_popupCalendar.callCloseHandler(),Calendar.stopEvent(ev)):void 0},Calendar.prototype.show=function(){for(var rows=this.table.getElementsByTagName("tr"),i=rows.length;i>0;){var row=rows[--i];Calendar.removeClass(row,"rowhilite");for(var cells=row.getElementsByTagName("td"),j=cells.length;j>0;){var cell=cells[--j];Calendar.removeClass(cell,"hilite"),Calendar.removeClass(cell,"active")}}this.element.style.display="block",this.hidden=!1,this.isPopup&&(window._dynarch_popupCalendar=this,Calendar.addEvent(document,"keydown",Calendar._keyEvent),Calendar.addEvent(document,"keypress",Calendar._keyEvent),Calendar.addEvent(document,"mousedown",Calendar._checkCalendar)),this.hideShowCovered()},Calendar.prototype.hide=function(){this.isPopup&&(Calendar.removeEvent(document,"keydown",Calendar._keyEvent),Calendar.removeEvent(document,"keypress",Calendar._keyEvent),Calendar.removeEvent(document,"mousedown",Calendar._checkCalendar)),this.element.style.display="none",this.hidden=!0,this.hideShowCovered()},Calendar.prototype.showAt=function(x,y){var s=this.element.style;s.left=x+"px",s.top=y+"px",this.show()},Calendar.prototype.showAtElement=function(el,opts){function fixPosition(box){box.x<0&&(box.x=0),box.y<0&&(box.y=0);var cp=document.createElement("div"),s=cp.style;s.position="absolute",s.right=s.bottom=s.width=s.height="0px",document.body.appendChild(cp);var br=Calendar.getAbsolutePos(cp);document.body.removeChild(cp),Calendar.is_ie?(br.y+=document.body.scrollTop,br.x+=document.body.scrollLeft):(br.y+=window.scrollY,br.x+=window.scrollX);var tmp=box.x+box.width-br.x;tmp>0&&(box.x-=tmp),tmp=box.y+box.height-br.y,tmp>0&&(box.y-=tmp)}var self=this,p=Calendar.getAbsolutePos(el);return opts&&"string"==typeof opts?(this.element.style.display="block",Calendar.continuation_for_the_fucking_khtml_browser=function(){var w=self.element.offsetWidth,h=self.element.offsetHeight;self.element.style.display="none";var valign=opts.substr(0,1),halign="l";switch(opts.length>1&&(halign=opts.substr(1,1)),valign){case"T":p.y-=h;break;case"B":p.y+=el.offsetHeight;break;case"C":p.y+=(el.offsetHeight-h)/2;break;case"t":p.y+=el.offsetHeight-h;break;case"b":}switch(halign){case"L":p.x-=w;break;case"R":p.x+=el.offsetWidth;break;case"C":p.x+=(el.offsetWidth-w)/2;break;case"l":p.x+=el.offsetWidth-w;break;case"r":}p.width=w,p.height=h+40,self.monthsCombo.style.display="none",fixPosition(p),self.showAt(p.x,p.y)},void(Calendar.is_khtml?setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()",10):Calendar.continuation_for_the_fucking_khtml_browser())):(this.showAt(p.x,p.y+el.offsetHeight),!0)},Calendar.prototype.setDateFormat=function(str){this.dateFormat=str},Calendar.prototype.setTtDateFormat=function(str){this.ttDateFormat=str},Calendar.prototype.parseDate=function(str,fmt){fmt||(fmt=this.dateFormat),this.setDate(Date.parseDate(str,fmt))},Calendar.prototype.hideShowCovered=function(){function getVisib(obj){var value=obj.style.visibility;return value||(value=document.defaultView&&"function"==typeof document.defaultView.getComputedStyle?Calendar.is_khtml?"":document.defaultView.getComputedStyle(obj,"").getPropertyValue("visibility"):obj.currentStyle?obj.currentStyle.visibility:""),value}if(Calendar.is_ie||Calendar.is_opera)for(var tags=new Array("applet","iframe","select"),el=this.element,p=Calendar.getAbsolutePos(el),EX1=p.x,EX2=el.offsetWidth+EX1,EY1=p.y,EY2=el.offsetHeight+EY1,k=tags.length;k>0;)for(var ar=document.getElementsByTagName(tags[--k]),cc=null,i=ar.length;i>0;){cc=ar[--i],p=Calendar.getAbsolutePos(cc);var CX1=p.x,CX2=cc.offsetWidth+CX1,CY1=p.y,CY2=cc.offsetHeight+CY1;this.hidden||CX1>EX2||EX1>CX2||CY1>EY2||EY1>CY2?(cc.__msh_save_visibility||(cc.__msh_save_visibility=getVisib(cc)),cc.style.visibility=cc.__msh_save_visibility):(cc.__msh_save_visibility||(cc.__msh_save_visibility=getVisib(cc)),cc.style.visibility="hidden")}},Calendar.prototype._displayWeekdays=function(){for(var fdow=this.firstDayOfWeek,cell=this.firstdayname,weekend=Calendar._TT.WEEKEND,i=0;7>i;++i){cell.className="day name";var realday=(i+fdow)%7;i&&(cell.ttip=Calendar._TT.DAY_FIRST.replace("%s",Calendar._DN[realday]),cell.navtype=100,cell.calendar=this,cell.fdow=realday,Calendar._add_evs(cell)),-1!=weekend.indexOf(realday.toString())&&Calendar.addClass(cell,"weekend"),cell.innerHTML=Calendar._SDN[(i+fdow)%7],cell=cell.nextSibling}},Calendar.prototype._hideCombos=function(){this.monthsCombo.style.display="none",this.yearsCombo.style.display="none"},Calendar.prototype._dragStart=function(ev){if(!this.dragging){this.dragging=!0;var posX,posY;Calendar.is_ie?(posY=window.event.clientY+document.body.scrollTop,posX=window.event.clientX+document.body.scrollLeft):(posY=ev.clientY+window.scrollY,posX=ev.clientX+window.scrollX);var st=this.element.style;with(this.xOffs=posX-parseInt(st.left),this.yOffs=posY-parseInt(st.top),Calendar)addEvent(document,"mousemove",calDragIt),addEvent(document,"mouseup",calDragEnd)}},Date._MD=new Array(31,28,31,30,31,30,31,31,30,31,30,31),Date.SECOND=1e3,Date.MINUTE=60*Date.SECOND,Date.HOUR=60*Date.MINUTE,Date.DAY=24*Date.HOUR,Date.WEEK=7*Date.DAY,Date.parseDate=function(str,fmt){var today=new Date,y=0,m=-1,d=0,a=str.split(/\W+/),b=fmt.match(/%./g),i=0,j=0,hr=0,min=0;for(i=0;iy&&(y+=y>29?1900:2e3);break;case"%b":case"%B":for(j=0;12>j;++j)if(Calendar._MN[j].substr(0,a[i].length).toLowerCase()==a[i].toLowerCase()){m=j;break}break;case"%H":case"%I":case"%k":case"%l":hr=parseInt(a[i],10);break;case"%P":case"%p":/pm/i.test(a[i])&&12>hr?hr+=12:/am/i.test(a[i])&&hr>=12&&(hr-=12);break;case"%M":min=parseInt(a[i],10)}if(isNaN(y)&&(y=today.getFullYear()),isNaN(m)&&(m=today.getMonth()),isNaN(d)&&(d=today.getDate()),isNaN(hr)&&(hr=today.getHours()),isNaN(min)&&(min=today.getMinutes()),0!=y&&-1!=m&&0!=d)return new Date(y,m,d,hr,min,0);for(y=0,m=-1,d=0,i=0;ij;++j)if(Calendar._MN[j].substr(0,a[i].length).toLowerCase()==a[i].toLowerCase()){t=j;break}-1!=t&&(-1!=m&&(d=m+1),m=t)}else parseInt(a[i],10)<=12&&-1==m?m=a[i]-1:parseInt(a[i],10)>31&&0==y?(y=parseInt(a[i],10),100>y&&(y+=y>29?1900:2e3)):0==d&&(d=a[i]);return 0==y&&(y=today.getFullYear()),-1!=m&&0!=d?new Date(y,m,d,hr,min,0):today},Date.prototype.getMonthDays=function(month){var year=this.getFullYear();return"undefined"==typeof month&&(month=this.getMonth()),0!=year%4||0==year%100&&0!=year%400||1!=month?Date._MD[month]:29},Date.prototype.getDayOfYear=function(){var now=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0),then=new Date(this.getFullYear(),0,0,0,0,0),time=now-then;return Math.floor(time/Date.DAY)},Date.prototype.getWeekNumber=function(){var d=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0),DoW=d.getDay();d.setDate(d.getDate()-(DoW+6)%7+3);var ms=d.valueOf();return d.setMonth(0),d.setDate(4),Math.round((ms-d.valueOf())/6048e5)+1},Date.prototype.equalsTo=function(date){return this.getFullYear()==date.getFullYear()&&this.getMonth()==date.getMonth()&&this.getDate()==date.getDate()&&this.getHours()==date.getHours()&&this.getMinutes()==date.getMinutes()},Date.prototype.setDateOnly=function(date){var tmp=new Date(date);this.setDate(1),this.setFullYear(tmp.getFullYear()),this.setMonth(tmp.getMonth()),this.setDate(tmp.getDate())},Date.prototype.print=function(str){var m=this.getMonth(),d=this.getDate(),y=this.getFullYear(),wn=this.getWeekNumber(),w=this.getDay(),s={},hr=this.getHours(),pm=hr>=12,ir=pm?hr-12:hr,dy=this.getDayOfYear();0==ir&&(ir=12);var min=this.getMinutes(),sec=this.getSeconds();s["%a"]=Calendar._SDN[w],s["%A"]=Calendar._DN[w],s["%b"]=Calendar._SMN[m],s["%B"]=Calendar._MN[m],s["%C"]=1+Math.floor(y/100),s["%d"]=10>d?"0"+d:d,s["%e"]=d,s["%H"]=10>hr?"0"+hr:hr,s["%I"]=10>ir?"0"+ir:ir,s["%j"]=100>dy?10>dy?"00"+dy:"0"+dy:dy,s["%k"]=hr,s["%l"]=ir,s["%m"]=9>m?"0"+(1+m):1+m,s["%M"]=10>min?"0"+min:min,s["%n"]="\n",s["%p"]=pm?"PM":"AM",s["%P"]=pm?"pm":"am",s["%s"]=Math.floor(this.getTime()/1e3),s["%S"]=10>sec?"0"+sec:sec,s["%t"]=" ",s["%U"]=s["%W"]=s["%V"]=10>wn?"0"+wn:wn,s["%u"]=w+1,s["%w"]=w,s["%y"]=(""+y).substr(2,2),s["%Y"]=y,s["%%"]="%";var re=/%./g;if(!Calendar.is_ie5&&!Calendar.is_khtml)return str.replace(re,function(par){return s[par]||par});for(var a=str.match(re),i=0;i0;)ar[--i]=Calendar._DN[i].substr(0,Calendar._SDN_len);Calendar._SDN=ar,"undefined"==typeof Calendar._SMN_len&&(Calendar._SMN_len=3),ar=new Array;for(var i=12;i>0;)ar[--i]=Calendar._MN[i].substr(0,Calendar._SMN_len);Calendar._SMN=ar}},Calendar._C=null,Calendar.is_ie=/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent),Calendar.is_ie5=Calendar.is_ie&&/msie 5\.0/i.test(navigator.userAgent),Calendar.is_opera=/opera/i.test(navigator.userAgent),Calendar.is_khtml=/Konqueror|Safari|KHTML/i.test(navigator.userAgent),Calendar.getAbsolutePos=function(el){var SL=0,ST=0,is_div=/^div$/i.test(el.tagName);is_div&&el.scrollLeft&&(SL=el.scrollLeft),is_div&&el.scrollTop&&(ST=el.scrollTop);var r={x:el.offsetLeft-SL,y:el.offsetTop-ST};if(el.offsetParent){var tmp=this.getAbsolutePos(el.offsetParent);r.x+=tmp.x,r.y+=tmp.y}return r},Calendar.isRelated=function(el,evt){var related=evt.relatedTarget;if(!related){var type=evt.type;"mouseover"==type?related=evt.fromElement:"mouseout"==type&&(related=evt.toElement)}for(;related;){if(related==el)return!0;related=related.parentNode}return!1},Calendar.removeClass=function(el,className){if(el&&el.className){for(var cls=el.className.split(" "),ar=new Array,i=cls.length;i>0;)cls[--i]!=className&&(ar[ar.length]=cls[i]);el.className=ar.join(" ")}},Calendar.addClass=function(el,className){Calendar.removeClass(el,className),el.className+=" "+className},Calendar.getElement=function(ev){for(var f=Calendar.is_ie?window.event.srcElement:ev.currentTarget;1!=f.nodeType||/^div$/i.test(f.tagName);)f=f.parentNode;return f},Calendar.getTargetElement=function(ev){for(var f=Calendar.is_ie?window.event.srcElement:ev.target;1!=f.nodeType;)f=f.parentNode;return f},Calendar.stopEvent=function(ev){return ev||(ev=window.event),Calendar.is_ie?(ev.cancelBubble=!0,ev.returnValue=!1):(ev.preventDefault(),ev.stopPropagation()),!1},Calendar.addEvent=function(el,evname,func){el.attachEvent?el.attachEvent("on"+evname,func):el.addEventListener?el.addEventListener(evname,func,!0):el["on"+evname]=func},Calendar.removeEvent=function(el,evname,func){el.detachEvent?el.detachEvent("on"+evname,func):el.removeEventListener?el.removeEventListener(evname,func,!0):el["on"+evname]=null},Calendar.createElement=function(type,parent){var el=null;return el=document.createElementNS?document.createElementNS("http://www.w3.org/1999/xhtml",type):document.createElement(type),"undefined"!=typeof parent&&parent.appendChild(el),el},Calendar._add_evs=function(el){with(Calendar)addEvent(el,"mouseover",dayMouseOver),addEvent(el,"mousedown",dayMouseDown),addEvent(el,"mouseout",dayMouseOut),is_ie&&(addEvent(el,"dblclick",dayMouseDblClick),el.setAttribute("unselectable",!0))},Calendar.findMonth=function(el){return"undefined"!=typeof el.month?el:"undefined"!=typeof el.parentNode.month?el.parentNode:null},Calendar.findYear=function(el){return"undefined"!=typeof el.year?el:"undefined"!=typeof el.parentNode.year?el.parentNode:null},Calendar.showMonthsCombo=function(){var cal=Calendar._C;if(!cal)return!1;var cal=cal,cd=cal.activeDiv,mc=cal.monthsCombo;cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite"),cal.activeMonth&&Calendar.removeClass(cal.activeMonth,"active");var mon=cal.monthsCombo.getElementsByTagName("div")[cal.date.getMonth()];Calendar.addClass(mon,"active"),cal.activeMonth=mon;var s=mc.style;if(s.display="block",cd.navtype<0)s.left=cd.offsetLeft+"px";else{var mcw=mc.offsetWidth;"undefined"==typeof mcw&&(mcw=50),s.left=cd.offsetLeft+cd.offsetWidth-mcw+"px"}s.top=cd.offsetTop+cd.offsetHeight+"px"},Calendar.showYearsCombo=function(fwd){var cal=Calendar._C;if(!cal)return!1;var cal=cal,cd=cal.activeDiv,yc=cal.yearsCombo;cal.hilitedYear&&Calendar.removeClass(cal.hilitedYear,"hilite"),cal.activeYear&&Calendar.removeClass(cal.activeYear,"active"),cal.activeYear=null;for(var Y=cal.date.getFullYear()+(fwd?1:-1),yr=yc.firstChild,show=!1,i=12;i>0;--i)Y>=cal.minYear&&Y<=cal.maxYear?(yr.innerHTML=Y,yr.year=Y,yr.style.display="block",show=!0):yr.style.display="none",yr=yr.nextSibling,Y+=fwd?cal.yearStep:-cal.yearStep;if(show){var s=yc.style;if(s.display="block",cd.navtype<0)s.left=cd.offsetLeft+"px";else{var ycw=yc.offsetWidth;"undefined"==typeof ycw&&(ycw=50),s.left=cd.offsetLeft+cd.offsetWidth-ycw+"px"}s.top=cd.offsetTop+cd.offsetHeight+"px"}},Calendar.tableMouseUp=function(ev){var cal=Calendar._C;if(!cal)return!1;cal.timeout&&clearTimeout(cal.timeout);var el=cal.activeDiv;if(!el)return!1;var target=Calendar.getTargetElement(ev);ev||(ev=window.event),Calendar.removeClass(el,"active"),(target==el||target.parentNode==el)&&Calendar.cellClick(el,ev);var mon=Calendar.findMonth(target),date=null;if(mon)date=new Date(cal.date),mon.month!=date.getMonth()&&(date.setMonth(mon.month),cal.setDate(date),cal.dateClicked=!1,cal.callHandler());else{var year=Calendar.findYear(target);year&&(date=new Date(cal.date),year.year!=date.getFullYear()&&(date.setFullYear(year.year),cal.setDate(date),cal.dateClicked=!1,cal.callHandler()))}with(Calendar)return removeEvent(document,"mouseup",tableMouseUp),removeEvent(document,"mouseover",tableMouseOver),removeEvent(document,"mousemove",tableMouseOver),cal._hideCombos(),_C=null,stopEvent(ev)},Calendar.tableMouseOver=function(ev){var cal=Calendar._C;if(cal){var el=cal.activeDiv,target=Calendar.getTargetElement(ev);if(target==el||target.parentNode==el?(Calendar.addClass(el,"hilite active"),Calendar.addClass(el.parentNode,"rowhilite")):(("undefined"==typeof el.navtype||50!=el.navtype&&(0==el.navtype||Math.abs(el.navtype)>2))&&Calendar.removeClass(el,"active"),Calendar.removeClass(el,"hilite"),Calendar.removeClass(el.parentNode,"rowhilite")),ev||(ev=window.event),50==el.navtype&&target!=el){var dx,pos=Calendar.getAbsolutePos(el),w=el.offsetWidth,x=ev.clientX,decrease=!0;x>pos.x+w?(dx=x-pos.x-w,decrease=!1):dx=pos.x-x,0>dx&&(dx=0);for(var range=el._range,current=el._current,count=Math.floor(dx/10)%range.length,i=range.length;--i>=0&&range[i]!=current;);for(;count-->0;)decrease?--i<0&&(i=range.length-1):++i>=range.length&&(i=0);var newval=range[i];el.innerHTML=newval,cal.onUpdateTime()}var mon=Calendar.findMonth(target);if(mon)mon.month!=cal.date.getMonth()?(cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite"),Calendar.addClass(mon,"hilite"),cal.hilitedMonth=mon):cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite");else{cal.hilitedMonth&&Calendar.removeClass(cal.hilitedMonth,"hilite");var year=Calendar.findYear(target);year&&year.year!=cal.date.getFullYear()?(cal.hilitedYear&&Calendar.removeClass(cal.hilitedYear,"hilite"),Calendar.addClass(year,"hilite"),cal.hilitedYear=year):cal.hilitedYear&&Calendar.removeClass(cal.hilitedYear,"hilite")}return Calendar.stopEvent(ev)}},Calendar.tableMouseDown=function(ev){return Calendar.getTargetElement(ev)==Calendar.getElement(ev)?Calendar.stopEvent(ev):void 0},Calendar.calDragIt=function(ev){var cal=Calendar._C;if(!cal||!cal.dragging)return!1;var posX,posY;Calendar.is_ie?(posY=window.event.clientY+document.body.scrollTop,posX=window.event.clientX+document.body.scrollLeft):(posX=ev.pageX,posY=ev.pageY),cal.hideShowCovered();var st=cal.element.style;return st.left=posX-cal.xOffs+"px",st.top=posY-cal.yOffs+"px",Calendar.stopEvent(ev)},Calendar.calDragEnd=function(ev){var cal=Calendar._C;if(!cal)return!1;with(cal.dragging=!1,Calendar)removeEvent(document,"mousemove",calDragIt),removeEvent(document,"mouseup",calDragEnd),tableMouseUp(ev);cal.hideShowCovered()},Calendar.dayMouseDown=function(ev){var el=Calendar.getElement(ev);if(el.disabled)return!1;var cal=el.calendar;if(cal.activeDiv=el,Calendar._C=cal,300!=el.navtype)with(Calendar)50==el.navtype?(el._current=el.innerHTML,addEvent(document,"mousemove",tableMouseOver)):addEvent(document,Calendar.is_ie5?"mousemove":"mouseover",tableMouseOver),addClass(el,"hilite active"),addEvent(document,"mouseup",tableMouseUp);else cal.isPopup&&cal._dragStart(ev);return-1==el.navtype||1==el.navtype?(cal.timeout&&clearTimeout(cal.timeout),cal.timeout=setTimeout("Calendar.showMonthsCombo()",250)):-2==el.navtype||2==el.navtype?(cal.timeout&&clearTimeout(cal.timeout),cal.timeout=setTimeout(el.navtype>0?"Calendar.showYearsCombo(true)":"Calendar.showYearsCombo(false)",250)):cal.timeout=null,Calendar.stopEvent(ev)},Calendar.dayMouseDblClick=function(ev){Calendar.cellClick(Calendar.getElement(ev),ev||window.event),Calendar.is_ie&&document.selection.empty()},Calendar.dayMouseOver=function(ev){var el=Calendar.getElement(ev);return Calendar.isRelated(el,ev)||Calendar._C||el.disabled?!1:(el.ttip&&("_"==el.ttip.substr(0,1)&&(el.ttip=el.caldate.print(el.calendar.ttDateFormat)+el.ttip.substr(1)),el.calendar.tooltips.innerHTML=el.ttip),300!=el.navtype&&(Calendar.addClass(el,"hilite"),el.caldate&&Calendar.addClass(el.parentNode,"rowhilite")),Calendar.stopEvent(ev))},Calendar.dayMouseOut=function(ev){with(Calendar){var el=getElement(ev);return isRelated(el,ev)||_C||el.disabled?!1:(removeClass(el,"hilite"),el.caldate&&removeClass(el.parentNode,"rowhilite"),el.calendar&&(el.calendar.tooltips.innerHTML=_TT.SEL_DATE),stopEvent(ev))}},Calendar.cellClick=function(el,ev){function setMonth(m){var day=date.getDate(),max=date.getMonthDays(m);day>max&&date.setDate(max),date.setMonth(m)}var cal=el.calendar,closing=!1,newdate=!1,date=null;if("undefined"==typeof el.navtype){cal.currentDateEl&&(Calendar.removeClass(cal.currentDateEl,"selected"),Calendar.addClass(el,"selected"),closing=cal.currentDateEl==el,closing||(cal.currentDateEl=el)),cal.date.setDateOnly(el.caldate),date=cal.date;var other_month=!(cal.dateClicked=!el.otherMonth);other_month||cal.currentDateEl?newdate=!el.disabled:cal._toggleMultipleDate(new Date(date)),other_month&&cal._init(cal.firstDayOfWeek,date)}else{if(200==el.navtype)return Calendar.removeClass(el,"hilite"),void cal.callCloseHandler();date=new Date(cal.date),0==el.navtype&&date.setDateOnly(new Date),cal.dateClicked=!1;var year=date.getFullYear(),mon=date.getMonth();switch(el.navtype){case 400:Calendar.removeClass(el,"hilite");var text=Calendar._TT.ABOUT;return"undefined"!=typeof text?text+=cal.showsTime?Calendar._TT.ABOUT_TIME:"":text='Help and about box text is not translated into this language.\nIf you know this language and you feel generous please update\nthe corresponding file in "lang" subdir to match calendar-en.js\nand send it back to to get it into the distribution ;-)\n\nThank you!\nhttp://dynarch.com/mishoo/calendar.epl\n',void alert(text);case-2:year>cal.minYear&&date.setFullYear(year-1);break;case-1:mon>0?setMonth(mon-1):year-->cal.minYear&&(date.setFullYear(year),setMonth(11));break;case 1:11>mon?setMonth(mon+1):year=0&&range[i]!=current;);ev&&ev.shiftKey?--i<0&&(i=range.length-1):++i>=range.length&&(i=0);var newval=range[i];return el.innerHTML=newval,void cal.onUpdateTime();case 0:if("function"==typeof cal.getDateStatus&&cal.getDateStatus(date,date.getFullYear(),date.getMonth(),date.getDate()))return!1}date.equalsTo(cal.date)?0==el.navtype&&(newdate=closing=!0):(cal.setDate(date),newdate=!0)}newdate&&ev&&cal.callHandler(),closing&&(Calendar.removeClass(el,"hilite"),ev&&cal.callCloseHandler())},Calendar.prototype.create=function(_par){var parent=null;_par?(parent=_par,this.isPopup=!1):(parent=document.getElementsByTagName("body")[0],this.isPopup=!0),this.date=this.dateStr?new Date(this.dateStr):new Date;var table=Calendar.createElement("table");this.table=table,table.cellSpacing=0,table.cellPadding=0,table.calendar=this,Calendar.addEvent(table,"mousedown",Calendar.tableMouseDown);var div=Calendar.createElement("div");this.element=div,div.className="calendar",this.isPopup&&(div.style.position="absolute",div.style.display="none"),div.appendChild(table);var thead=Calendar.createElement("thead",table),cell=null,row=null,cal=this,hh=function(text,cs,navtype){return cell=Calendar.createElement("td",row),cell.colSpan=cs,cell.className="button",0!=navtype&&Math.abs(navtype)<=2&&(cell.className+=" nav"),Calendar._add_evs(cell),cell.calendar=cal,cell.navtype=navtype,cell.innerHTML="
"+text+"
",cell};row=Calendar.createElement("tr",thead);var title_length=6;this.isPopup&&--title_length,this.weekNumbers&&++title_length,hh("?",1,400).ttip=Calendar._TT.INFO,this.title=hh("",title_length,300),this.title.className="title",this.isPopup&&(this.title.ttip=Calendar._TT.DRAG_TO_MOVE,this.title.style.cursor="move",hh("×",1,200).ttip=Calendar._TT.CLOSE),row=Calendar.createElement("tr",thead),row.className="headrow",this._nav_py=hh("«",1,-2),this._nav_py.ttip=Calendar._TT.PREV_YEAR,this._nav_pm=hh("‹",1,-1),this._nav_pm.ttip=Calendar._TT.PREV_MONTH,this._nav_now=hh(Calendar._TT.TODAY,this.weekNumbers?4:3,0),this._nav_now.ttip=Calendar._TT.GO_TODAY,this._nav_nm=hh("›",1,1),this._nav_nm.ttip=Calendar._TT.NEXT_MONTH,this._nav_ny=hh("»",1,2),this._nav_ny.ttip=Calendar._TT.NEXT_YEAR,row=Calendar.createElement("tr",thead),row.className="daynames",this.weekNumbers&&(cell=Calendar.createElement("td",row),cell.className="name wn",cell.innerHTML=Calendar._TT.WK);for(var i=7;i>0;--i)cell=Calendar.createElement("td",row),i||(cell.navtype=100,cell.calendar=this,Calendar._add_evs(cell));this.firstdayname=this.weekNumbers?row.firstChild.nextSibling:row.firstChild,this._displayWeekdays();var tbody=Calendar.createElement("tbody",table);for(this.tbody=tbody,i=6;i>0;--i){row=Calendar.createElement("tr",tbody),this.weekNumbers&&(cell=Calendar.createElement("td",row));for(var j=7;j>0;--j)cell=Calendar.createElement("td",row),cell.calendar=this,Calendar._add_evs(cell)}this.showsTime?(row=Calendar.createElement("tr",tbody),row.className="time",cell=Calendar.createElement("td",row),cell.className="time",cell.colSpan=2,cell.innerHTML=Calendar._TT.TIME||" ",cell=Calendar.createElement("td",row),cell.className="time",cell.colSpan=this.weekNumbers?4:3,function(){function makeTimePart(className,init,range_start,range_end){var part=Calendar.createElement("span",cell);if(part.className=className,part.innerHTML=init,part.calendar=cal,part.ttip=Calendar._TT.TIME_PART,part.navtype=50,part._range=[],"number"!=typeof range_start)part._range=range_start;else for(var i=range_start;range_end>=i;++i){var txt;txt=10>i&&range_end>=10?"0"+i:""+i,part._range[part._range.length]=txt}return Calendar._add_evs(part),part}var hrs=cal.date.getHours(),mins=cal.date.getMinutes(),t12=!cal.time24,pm=hrs>12;t12&&pm&&(hrs-=12);var H=makeTimePart("hour",hrs,t12?1:0,t12?12:23),span=Calendar.createElement("span",cell);span.innerHTML=":",span.className="colon";var M=makeTimePart("minute",mins,0,59),AP=null;cell=Calendar.createElement("td",row),cell.className="time",cell.colSpan=2,t12?AP=makeTimePart("ampm",pm?"pm":"am",["am","pm"]):cell.innerHTML=" ",cal.onSetTime=function(){var pm,hrs=this.date.getHours(),mins=this.date.getMinutes();t12&&(pm=hrs>=12,pm&&(hrs-=12),0==hrs&&(hrs=12),AP.innerHTML=pm?"pm":"am"),H.innerHTML=10>hrs?"0"+hrs:hrs,M.innerHTML=10>mins?"0"+mins:mins},cal.onUpdateTime=function(){var date=this.date,h=parseInt(H.innerHTML,10);t12&&(/pm/i.test(AP.innerHTML)&&12>h?h+=12:/am/i.test(AP.innerHTML)&&12==h&&(h=0));var d=date.getDate(),m=date.getMonth(),y=date.getFullYear();date.setHours(h),date.setMinutes(parseInt(M.innerHTML,10)),date.setFullYear(y),date.setMonth(m),date.setDate(d),this.dateClicked=!1,this.callHandler()}}()):this.onSetTime=this.onUpdateTime=function(){};var tfoot=Calendar.createElement("tfoot",table);for(row=Calendar.createElement("tr",tfoot),row.className="footrow",cell=hh(Calendar._TT.SEL_DATE,this.weekNumbers?8:7,300),cell.className="ttip",this.isPopup&&(cell.ttip=Calendar._TT.DRAG_TO_MOVE,cell.style.cursor="move"),this.tooltips=cell,div=Calendar.createElement("div",this.element),this.monthsCombo=div,div.className="combo",i=0;i0;--i){var yr=Calendar.createElement("div");yr.className=Calendar.is_ie?"label-IEfix":"label",div.appendChild(yr)}this._init(this.firstDayOfWeek,this.date),parent.appendChild(this.element)},Calendar._keyEvent=function(ev){function setVars(){el=cal.currentDateEl;var p=el.pos;x=15&p,y=p>>4,ne=cal.ar_days[y][x]}function prevMonth(){var date=new Date(cal.date);date.setDate(date.getDate()-step),cal.setDate(date)}function nextMonth(){var date=new Date(cal.date);date.setDate(date.getDate()+step),cal.setDate(date)}var cal=window._dynarch_popupCalendar;if(!cal||cal.multiple)return!1;Calendar.is_ie&&(ev=window.event);var act=Calendar.is_ie||"keypress"==ev.type,K=ev.keyCode;if(ev.ctrlKey)switch(K){case 37:act&&Calendar.cellClick(cal._nav_pm);break;case 38:act&&Calendar.cellClick(cal._nav_py);break;case 39:act&&Calendar.cellClick(cal._nav_nm);break;case 40:act&&Calendar.cellClick(cal._nav_ny);break;default:return!1}else switch(K){case 32:Calendar.cellClick(cal._nav_now);break;case 27:act&&cal.callCloseHandler();break;case 37:case 38:case 39:case 40:if(act){var prev,x,y,ne,el,step;for(prev=37==K||38==K,step=37==K||39==K?1:7,setVars();;){switch(K){case 37:if(!(--x>=0)){x=6,K=38;continue}ne=cal.ar_days[y][x];break;case 38:--y>=0?ne=cal.ar_days[y][x]:(prevMonth(),setVars());break;case 39:if(!(++x<7)){x=0,K=40;continue}ne=cal.ar_days[y][x];break;case 40:++ythis.maxYear&&(year=this.maxYear,date.setFullYear(year)),this.firstDayOfWeek=firstDayOfWeek,this.date=new Date(date);{var month=date.getMonth(),mday=date.getDate();date.getMonthDays()}date.setDate(1);var day1=(date.getDay()-this.firstDayOfWeek)%7;0>day1&&(day1+=7),date.setDate(-day1),date.setDate(date.getDate()+1);for(var row=this.tbody.firstChild,ar_days=(Calendar._SMN[month],this.ar_days=new Array),weekend=Calendar._TT.WEEKEND,dates=this.multiple?this.datesCells={}:null,i=0;6>i;++i,row=row.nextSibling){var cell=row.firstChild;this.weekNumbers&&(cell.className="day wn",cell.innerHTML=date.getWeekNumber(),cell=cell.nextSibling),row.className="daysrow";for(var iday,hasdays=!1,dpos=ar_days[i]=[],j=0;7>j;++j,cell=cell.nextSibling,date.setDate(iday+1)){iday=date.getDate();var wday=date.getDay();cell.className="day",cell.pos=i<<4|j,dpos[j]=cell;var current_month=date.getMonth()==month;if(current_month)cell.otherMonth=!1,hasdays=!0;else{if(!this.showsOtherMonths){cell.className="emptycell",cell.innerHTML=" ",cell.disabled=!0;continue}cell.className+=" othermonth",cell.otherMonth=!0}if(cell.disabled=!1,cell.innerHTML=this.getDateText?this.getDateText(date,iday):iday,dates&&(dates[date.print("%Y%m%d")]=cell),this.getDateStatus){var status=this.getDateStatus(date,year,month,iday);if(this.getDateToolTip){var toolTip=this.getDateToolTip(date,year,month,iday);toolTip&&(cell.title=toolTip)}status===!0?(cell.className+=" disabled",cell.disabled=!0):(/disabled/i.test(status)&&(cell.disabled=!0),cell.className+=" "+status)}cell.disabled||(cell.caldate=new Date(date),cell.ttip="_",!this.multiple&¤t_month&&iday==mday&&this.hiliteToday&&(cell.className+=" selected",this.currentDateEl=cell),date.getFullYear()==TY&&date.getMonth()==TM&&iday==TD&&(cell.className+=" today",cell.ttip+=Calendar._TT.PART_TODAY),-1!=weekend.indexOf(wday.toString())&&(cell.className+=cell.otherMonth?" oweekend":" weekend"))}hasdays||this.showsOtherMonths||(row.className="emptyrow")}this.title.innerHTML=Calendar._MN[month]+", "+year,this.onSetTime(),this.table.style.visibility="visible",this._initMultipleDates()},Calendar.prototype._initMultipleDates=function(){if(this.multiple)for(var i in this.multiple){var cell=this.datesCells[i],d=this.multiple[i];d&&cell&&(cell.className+=" selected")}},Calendar.prototype._toggleMultipleDate=function(date){if(this.multiple){var ds=date.print("%Y%m%d"),cell=this.datesCells[ds];if(cell){var d=this.multiple[ds];d?(Calendar.removeClass(cell,"selected"),delete this.multiple[ds]):(Calendar.addClass(cell,"selected"),this.multiple[ds]=date)}}},Calendar.prototype.setDateToolTipHandler=function(unaryFunction){this.getDateToolTip=unaryFunction},Calendar.prototype.setDate=function(date){date.equalsTo(this.date)||this._init(this.firstDayOfWeek,date)},Calendar.prototype.refresh=function(){this._init(this.firstDayOfWeek,this.date)},Calendar.prototype.setFirstDayOfWeek=function(firstDayOfWeek){this._init(firstDayOfWeek,this.date),this._displayWeekdays()},Calendar.prototype.setDateStatusHandler=Calendar.prototype.setDisabledHandler=function(unaryFunction){this.getDateStatus=unaryFunction},Calendar.prototype.setRange=function(a,z){this.minYear=a,this.maxYear=z},Calendar.prototype.callHandler=function(){this.onSelected&&this.onSelected(this,this.date.print(this.dateFormat))},Calendar.prototype.callCloseHandler=function(){this.onClose&&this.onClose(this),this.hideShowCovered()},Calendar.prototype.destroy=function(){var el=this.element.parentNode;el.removeChild(this.element),Calendar._C=null,window._dynarch_popupCalendar=null},Calendar.prototype.reparent=function(new_parent){var el=this.element;el.parentNode.removeChild(el),new_parent.appendChild(el)},Calendar._checkCalendar=function(ev){var calendar=window._dynarch_popupCalendar;if(!calendar)return!1;for(var el=Calendar.is_ie?Calendar.getElement(ev):Calendar.getTargetElement(ev);null!=el&&el!=calendar.element;el=el.parentNode);return null==el?(window._dynarch_popupCalendar.callCloseHandler(),Calendar.stopEvent(ev)):void 0},Calendar.prototype.show=function(){for(var rows=this.table.getElementsByTagName("tr"),i=rows.length;i>0;){var row=rows[--i];Calendar.removeClass(row,"rowhilite");for(var cells=row.getElementsByTagName("td"),j=cells.length;j>0;){var cell=cells[--j];Calendar.removeClass(cell,"hilite"),Calendar.removeClass(cell,"active")}}this.element.style.display="block",this.hidden=!1,this.isPopup&&(window._dynarch_popupCalendar=this,Calendar.addEvent(document,"keydown",Calendar._keyEvent),Calendar.addEvent(document,"keypress",Calendar._keyEvent),Calendar.addEvent(document,"mousedown",Calendar._checkCalendar)),this.hideShowCovered()},Calendar.prototype.hide=function(){this.isPopup&&(Calendar.removeEvent(document,"keydown",Calendar._keyEvent),Calendar.removeEvent(document,"keypress",Calendar._keyEvent),Calendar.removeEvent(document,"mousedown",Calendar._checkCalendar)),this.element.style.display="none",this.hidden=!0,this.hideShowCovered()},Calendar.prototype.showAt=function(x,y){var s=this.element.style;s.left=x+"px",s.top=y+"px",this.show()},Calendar.prototype.showAtElement=function(el,opts){function fixPosition(box){box.x<0&&(box.x=0),box.y<0&&(box.y=0);var cp=document.createElement("div"),s=cp.style;s.position="absolute",s.right=s.bottom=s.width=s.height="0px",document.body.appendChild(cp);var br=Calendar.getAbsolutePos(cp);document.body.removeChild(cp),Calendar.is_ie?(br.y+=document.body.scrollTop,br.x+=document.body.scrollLeft):(br.y+=window.scrollY,br.x+=window.scrollX);var tmp=box.x+box.width-br.x;tmp>0&&(box.x-=tmp),tmp=box.y+box.height-br.y,tmp>0&&(box.y-=tmp)}var self=this,p=Calendar.getAbsolutePos(el);return opts&&"string"==typeof opts?(this.element.style.display="block",Calendar.continuation_for_the_fucking_khtml_browser=function(){var w=self.element.offsetWidth,h=self.element.offsetHeight;self.element.style.display="none";var valign=opts.substr(0,1),halign="l";switch(opts.length>1&&(halign=opts.substr(1,1)),valign){case"T":p.y-=h;break;case"B":p.y+=el.offsetHeight;break;case"C":p.y+=(el.offsetHeight-h)/2;break;case"t":p.y+=el.offsetHeight-h;break;case"b":}switch(halign){case"L":p.x-=w;break;case"R":p.x+=el.offsetWidth;break;case"C":p.x+=(el.offsetWidth-w)/2;break;case"l":p.x+=el.offsetWidth-w;break;case"r":}p.width=w,p.height=h+40,self.monthsCombo.style.display="none",fixPosition(p),self.showAt(p.x,p.y)},void(Calendar.is_khtml?setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()",10):Calendar.continuation_for_the_fucking_khtml_browser())):(this.showAt(p.x,p.y+el.offsetHeight),!0)},Calendar.prototype.setDateFormat=function(str){this.dateFormat=str},Calendar.prototype.setTtDateFormat=function(str){this.ttDateFormat=str},Calendar.prototype.parseDate=function(str,fmt){fmt||(fmt=this.dateFormat),this.setDate(Date.parseDate(str,fmt))},Calendar.prototype.hideShowCovered=function(){function getVisib(obj){var value=obj.style.visibility;return value||(value=document.defaultView&&"function"==typeof document.defaultView.getComputedStyle?Calendar.is_khtml?"":document.defaultView.getComputedStyle(obj,"").getPropertyValue("visibility"):obj.currentStyle?obj.currentStyle.visibility:""),value}if(Calendar.is_ie||Calendar.is_opera)for(var tags=new Array("applet","iframe","select"),el=this.element,p=Calendar.getAbsolutePos(el),EX1=p.x,EX2=el.offsetWidth+EX1,EY1=p.y,EY2=el.offsetHeight+EY1,k=tags.length;k>0;)for(var ar=document.getElementsByTagName(tags[--k]),cc=null,i=ar.length;i>0;){cc=ar[--i],p=Calendar.getAbsolutePos(cc);var CX1=p.x,CX2=cc.offsetWidth+CX1,CY1=p.y,CY2=cc.offsetHeight+CY1;this.hidden||CX1>EX2||EX1>CX2||CY1>EY2||EY1>CY2?(cc.__msh_save_visibility||(cc.__msh_save_visibility=getVisib(cc)),cc.style.visibility=cc.__msh_save_visibility):(cc.__msh_save_visibility||(cc.__msh_save_visibility=getVisib(cc)),cc.style.visibility="hidden")}},Calendar.prototype._displayWeekdays=function(){for(var fdow=this.firstDayOfWeek,cell=this.firstdayname,weekend=Calendar._TT.WEEKEND,i=0;7>i;++i){cell.className="day name";var realday=(i+fdow)%7;i&&(cell.ttip=Calendar._TT.DAY_FIRST.replace("%s",Calendar._DN[realday]),cell.navtype=100,cell.calendar=this,cell.fdow=realday,Calendar._add_evs(cell)),-1!=weekend.indexOf(realday.toString())&&Calendar.addClass(cell,"weekend"),cell.innerHTML=Calendar._SDN[(i+fdow)%7],cell=cell.nextSibling}},Calendar.prototype._hideCombos=function(){this.monthsCombo.style.display="none",this.yearsCombo.style.display="none"},Calendar.prototype._dragStart=function(ev){if(!this.dragging){this.dragging=!0;var posX,posY;Calendar.is_ie?(posY=window.event.clientY+document.body.scrollTop,posX=window.event.clientX+document.body.scrollLeft):(posY=ev.clientY+window.scrollY,posX=ev.clientX+window.scrollX);var st=this.element.style;with(this.xOffs=posX-parseInt(st.left),this.yOffs=posY-parseInt(st.top),Calendar)addEvent(document,"mousemove",calDragIt),addEvent(document,"mouseup",calDragEnd)}},Date._MD=new Array(31,28,31,30,31,30,31,31,30,31,30,31),Date.SECOND=1e3,Date.MINUTE=60*Date.SECOND,Date.HOUR=60*Date.MINUTE,Date.DAY=24*Date.HOUR,Date.WEEK=7*Date.DAY,Date.parseDate=function(str,fmt){var today=new Date,y=0,m=-1,d=0,a=str.split(/\W+/),b=fmt.match(/%./g),i=0,j=0,hr=0,min=0;for(i=0;iy&&(y+=y>29?1900:2e3);break;case"%b":case"%B":for(j=0;12>j;++j)if(Calendar._MN[j].substr(0,a[i].length).toLowerCase()==a[i].toLowerCase()){m=j;break}break;case"%H":case"%I":case"%k":case"%l":hr=parseInt(a[i],10);break;case"%P":case"%p":/pm/i.test(a[i])&&12>hr?hr+=12:/am/i.test(a[i])&&hr>=12&&(hr-=12);break;case"%M":min=parseInt(a[i],10);break;case"%r":hr=parseInt(a[i],10),min=parseInt(a[++i],10);{parseInt(a[++i],10)}/pm/i.test(a[++i])&&12>hr?hr+=12:/am/i.test(a[i])&&hr>=12&&(hr-=12)}if(isNaN(y)&&(y=today.getFullYear()),isNaN(m)&&(m=today.getMonth()),isNaN(d)&&(d=today.getDate()),isNaN(hr)&&(hr=today.getHours()),isNaN(min)&&(min=today.getMinutes()),0!=y&&-1!=m&&0!=d)return new Date(y,m,d,hr,min,0);for(y=0,m=-1,d=0,i=0;ij;++j)if(Calendar._MN[j].substr(0,a[i].length).toLowerCase()==a[i].toLowerCase()){t=j;break}-1!=t&&(-1!=m&&(d=m+1),m=t)}else parseInt(a[i],10)<=12&&-1==m?m=a[i]-1:parseInt(a[i],10)>31&&0==y?(y=parseInt(a[i],10),100>y&&(y+=y>29?1900:2e3)):0==d&&(d=a[i]);return 0==y&&(y=today.getFullYear()),-1!=m&&0!=d?new Date(y,m,d,hr,min,0):today},Date.prototype.getMonthDays=function(month){var year=this.getFullYear();return"undefined"==typeof month&&(month=this.getMonth()),0!=year%4||0==year%100&&0!=year%400||1!=month?Date._MD[month]:29},Date.prototype.getDayOfYear=function(){var now=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0),then=new Date(this.getFullYear(),0,0,0,0,0),time=now-then;return Math.floor(time/Date.DAY)},Date.prototype.getWeekNumber=function(){var d=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0),DoW=d.getDay();d.setDate(d.getDate()-(DoW+6)%7+3);var ms=d.valueOf();return d.setMonth(0),d.setDate(4),Math.round((ms-d.valueOf())/6048e5)+1},Date.prototype.equalsTo=function(date){return this.getFullYear()==date.getFullYear()&&this.getMonth()==date.getMonth()&&this.getDate()==date.getDate()&&this.getHours()==date.getHours()&&this.getMinutes()==date.getMinutes()},Date.prototype.setDateOnly=function(date){var tmp=new Date(date);this.setDate(1),this.setFullYear(tmp.getFullYear()),this.setMonth(tmp.getMonth()),this.setDate(tmp.getDate())},Date.prototype.print=function(str){var m=this.getMonth(),d=this.getDate(),y=this.getFullYear(),wn=this.getWeekNumber(),w=this.getDay(),s={},hr=this.getHours(),pm=hr>=12,ir=pm?hr-12:hr,dy=this.getDayOfYear();0==ir&&(ir=12);var min=this.getMinutes(),sec=this.getSeconds();s["%a"]=Calendar._SDN[w],s["%A"]=Calendar._DN[w],s["%b"]=Calendar._SMN[m],s["%B"]=Calendar._MN[m],s["%C"]=1+Math.floor(y/100),s["%d"]=10>d?"0"+d:d,s["%e"]=d,s["%H"]=10>hr?"0"+hr:hr,s["%I"]=10>ir?"0"+ir:ir,s["%j"]=100>dy?10>dy?"00"+dy:"0"+dy:dy,s["%k"]=hr,s["%l"]=ir,s["%m"]=9>m?"0"+(1+m):1+m,s["%M"]=10>min?"0"+min:min,s["%n"]="\n",s["%p"]=pm?"PM":"AM",s["%P"]=pm?"pm":"am",s["%r"]=(10>ir?"0"+ir:ir)+":"+(10>min?"0"+min:min)+":"+(10>sec?"0"+sec:sec)+" "+(pm?"PM":"AM"),s["%s"]=Math.floor(this.getTime()/1e3),s["%S"]=10>sec?"0"+sec:sec,s["%t"]=" ",s["%U"]=s["%W"]=s["%V"]=10>wn?"0"+wn:wn,s["%u"]=w+1,s["%w"]=w,s["%y"]=(""+y).substr(2,2),s["%Y"]=y,s["%%"]="%";var re=/%./g;if(!Calendar.is_ie5&&!Calendar.is_khtml)return str.replace(re,function(par){return s[par]||par});for(var a=str.match(re),i=0;i", button: "<% $name %>_button", align: "BR" +% if ( $format =~ /\%r/ ) { + , + showsTime: true, + timeFormat: 12 +% } }); diff --git a/httemplate/elements/tr-input-date-field.html b/httemplate/elements/tr-input-date-field.html index 40162f0fda..ff9855184e 100644 --- a/httemplate/elements/tr-input-date-field.html +++ b/httemplate/elements/tr-input-date-field.html @@ -26,7 +26,7 @@
- @@ -38,12 +38,17 @@ ifFormat: "<% $format %>", button: "<% $name %>_button", align: "BR" +% if ( $format =~ /\%r/ ) { + , + showsTime: true, + timeFormat: 12 +% } }); <%init> -my($name, $value, $label, $format, $usedatetime, $noinit); +my($name, $value, $label, $format, $usedatetime, $noinit, $colspan); if ( ref($_[0]) ) { my $opt = shift; $name = $opt->{'name'}; @@ -52,8 +57,10 @@ $format = $opt->{'format'}; $usedatetime = $opt->{'usedatetime'}; $noinit = $opt->{'noinit'}; + $colspan = $opt->{'colspan'} || 1; } else { ($name, $value, $label, $format, $usedatetime) = @_; + $colspan = 1; } my $conf = new FS::Conf; From 47ab01c6685124959c80283cdb348b605f330ac7 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Tue, 16 Dec 2014 10:25:06 -0500 Subject: [PATCH 38/40] Ticket 29048 3CX CDR format changes --- FS/FS/cdr/cx3.pm | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/FS/FS/cdr/cx3.pm b/FS/FS/cdr/cx3.pm index 8c848078a1..a1e2e93c4c 100644 --- a/FS/FS/cdr/cx3.pm +++ b/FS/FS/cdr/cx3.pm @@ -10,40 +10,33 @@ use Date::Parse; %info = ( 'name' => '3CX', 'weight' => 120, - 'header' => 1, 'import_fields' => [ -sub { - my ($cdr, $data, $conf, $param) = @_; - $param->{skiprow} = 1 unless $data =~ 'CallDetail'; # skip non-detail records + sub { + my ($cdr, $data, $conf, $param) = @_; + $param->{skiprow} = 1 unless $data =~ /Call\s/ ; # skip non-detail records }, # record type - skip(2), # unknown, callid ( not unique ) - 'src', # source - 'dst', # destination -sub { my ($cdr, $calldate, $param) = @_; - - if ($calldate =~ /^(\d{2})\/(\d{2})\/(\d{4})\s*(\d{2}):(\d{2}):(\d{2})$/){ + skip(1), # unknown, callid ( not unique ) + sub { my ($cdr, $duration) = @_; + + my ($hour,$min,$sec) = split(/:/,$duration); + $sec = sprintf ("%.0f", $sec); + $sec += $min * 60; + $sec += $hour * 60 * 60; + $cdr->set('billsec', $sec); + + }, # duration + skip(1), + sub { my ($cdr, $calldate, $param) = @_; $cdr->set('calldate', $calldate); - my $tmp_date = "$2/$1/$3 $4:$5:$6"; - - $tmp_date = str2time($tmp_date); - $cdr->set('startdate', $tmp_date); - } }, #date -sub { my ($cdr, $duration) = @_; - - my ($hour,$min,$sec) = split(/:/,$duration); - $sec += $min * 60; - $sec += $hour * 60 * 60; - $sec = sprintf ("%.0f", $sec); - $cdr->set('billsec', $sec); - -}, #duration - skip(1), # unknown - 'disposition', # call status + skip(4), 'accountcode', # AccountCode + skip(6), + 'src', # source + 'dst', # destination ], ); From b82cb3b3b433115b6fb0757f135ece8b50dcbbf0 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Tue, 16 Dec 2014 11:28:45 -0500 Subject: [PATCH 39/40] Ticket 31993 different trans codes for business and personal --- FS/FS/Conf.pm | 2 +- FS/FS/pay_batch/eft_canada.pm | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index c88d3e7a4d..90b11a0474 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -3855,7 +3855,7 @@ and customer address. Include units.', { 'key' => 'batchconfig-eft_canada', 'section' => 'billing', - 'description' => 'Configuration for EFT Canada batching, four lines: 1. SFTP username, 2. SFTP password, 3. Transaction code, 4. Number of days to delay process date. If you are using separate per-agent batches (batch-spoolagent), you must set this option separately for each agent, as the global setting will be ignored.', + 'description' => 'Configuration for EFT Canada batching, five lines: 1. SFTP username, 2. SFTP password, 3. Business transaction code, 4. Personal transaction code, 5. Number of days to delay process date. If you are using separate per-agent batches (batch-spoolagent), you must set this option separately for each agent, as the global setting will be ignored.', 'type' => 'textarea', 'per_agent' => 1, }, diff --git a/FS/FS/pay_batch/eft_canada.pm b/FS/FS/pay_batch/eft_canada.pm index 0c093214ad..ab9e6a3b6d 100644 --- a/FS/FS/pay_batch/eft_canada.pm +++ b/FS/FS/pay_batch/eft_canada.pm @@ -15,7 +15,7 @@ $name = 'eft_canada'; %import_info = ( filetype => 'NONE' ); # see FS/bin/freeside-eftca-download -my ($trans_code, $process_date); +my ($business_trans_code, $personal_trans_code, $trans_code, $process_date); #ref http://gocanada.about.com/od/canadatravelplanner/a/canada_holidays.htm my %holiday_yearly = ( @@ -66,7 +66,8 @@ my %holiday = ( @config = $conf->config('batchconfig-eft_canada'); } # SFTP login, password, trans code, delay time - ($trans_code) = $config[2]; + ($business_trans_code) = $config[2]; + ($personal_trans_code) = $config[3]; $process_date = time2str('%D', process_date($conf, $agentnum)); }, @@ -82,12 +83,14 @@ my %holiday = ( my $company = sprintf('%.64s', $cust_pay_batch->cust_main->company); if ( $company ) { push @fields, 'Business'; - push @fields, $company, '' + push @fields, $company, ''; + $trans_code = $business_trans_code; } else { push @fields, 'Personal'; push @fields, map { sprintf('%.64s', $_) } $cust_pay_batch->first, $cust_pay_batch->last; + $trans_code = $personal_trans_code; } my ($account, $aba) = split('@', $cust_pay_batch->payinfo); my($bankno, $branch); From ae0d0e98d4b8076001aa34882fa1cdc75077af82 Mon Sep 17 00:00:00 2001 From: "Doran L. Barton" Date: Tue, 16 Dec 2014 15:44:18 -0700 Subject: [PATCH 40/40] Fixed typos in freeside-service.init.in and Makefile --- Makefile | 4 ++-- init.d/freeside-service.init.in | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6e34355fef..cb77ccf17b 100644 --- a/Makefile +++ b/Makefile @@ -383,8 +383,8 @@ install-init: ); fi perl -p -i -e "\ - s/%%%FREESIDE_DEFAULTS%%%/${FREESIDE_DEFAULTS}/g;\ - s/%%%FREESIDE_BIN%%%/${FREESIDE_BIN}/g;\ + s|%%%FREESIDE_DEFAULTS%%%|${FREESIDE_DEFAULTS}|g;\ + s|%%%FREESIDE_BIN%%%|${FREESIDE_BIN}|g;\ " init.d/freeside-functions ${INIT_INSTALL_QUEUED} diff --git a/init.d/freeside-service.init.in b/init.d/freeside-service.init.in index a4d5505376..c9d10544ae 100644 --- a/init.d/freeside-service.init.in +++ b/init.d/freeside-service.init.in @@ -5,7 +5,7 @@ ARG1=${1} -SERVICE=%%%SERVICE%%%% +SERVICE=%%%SERVICE%%% if [ -f /etc/init.d/freeside-functions ] then
<% mt('Date') |h %><% time2str($date_format, $_date) %>
<% mt('Amount') |h %>
<% mt('Date') |h %> - - -
<% mt('Date') |h %> - <% time2str($date_format.' %r',$_date) %> -
<% mt('Amount') |h %><% $money_char %> <% mt('by') |h %> <% mt(FS::payby->payname($payby)) |h %><% $money_char |h %> <% mt('by') |h %> <% mt(FS::payby->payname($payby)) |h %>
<% $label %> + >