#! /bin/bash
#------------------------------------------------------------------------------
#see licence at the end
ThisScriptVersion="1.24 - 21-06 2025 rev 0"
GoeVersion="$ThisScriptVersion Last Update : `stat -c %z $0 | cut -d"." -f1`"
Date=`date +%A_%x-%H:%M:%S`
CurrentUser=`whoami`
AllParameters="$*"
UserLogins=""
# ➡️ ⬅️ ⬆️ ⬇️ ↗️ ↘️ ↙️ ↖️ ↕️ ↔️ 🔄 ⤴️ ⤵️ ‼️ ❗️ ✅ 💾 💽 ⏳ 🛠️ 🖥️ ✅❌
#------------------------------------------------------------------------------
##StartConfig
#------------------------------------------------------------------------------
# This part of the file is copied to goe_panel/data/goe.conf
# Edit the default configuration in goe.local.conf to keep modifications
# panel mode is set /usr/local/etc/goe/goe.mode.conf, check goe --mode command
#

#future plans
# base de donnees: bouton snapshot
# base de donnees: db_update devient reformater
# base de donnees: si admin possibilite de reference pour tout le serveur
# service: code update et code upgrade en boutons séparés
# service: bouton bloquer le redémarrage, mode parking
# service: gestion du contrat du service
# service: changement de mot de passe admin global sur les bases
# serveur: gestion du contrat du VDS
# serveur: bouton et formulaire edition des valeurs par defaut DEF_
# serveur: edition des url du service
# serveur: bouton de refresh du proxy
# serveur; bouton installation et mise à jour du systeme et des dépendances

#Site parameters
#---------------
HttpUser="www-data"
TopImage="images/background.gif"
TopLogo="images/top_background.jpg"
TapeImage="<big>💾 </big>"
DiskImage="<big>💽 </big>"
WarnImage="<big>❗️ </big>"
ServiceImage="🖥️ "
SiteCss="goe.css"
SiteRefreshResult="12"
SiteRefreshPeriod="8"
SiteUrl="."
PanelHelp="http://sisalp.fr/index.php/post/Hebergement-OpenERP-et-Tryton-par-SISalp-Le-panneau-d-administration-du-serveur-VDS"
PanelSupport="https://sisalp.fr/index.php/category/A-propos-de-SISalp"
InputStyle="style=\\\"cursor:pointer; width:300px; padding:3px 20px; margin:3px; background-color:#eeeeee; border:solid 1px #999999;\\\""
ServerMenuAvailable="help support options admin_guide contract openservice closeservice monitor mooc services log"


#goe background tasks parameters
#-------------------------------
XoeAuthorizedUser="sisalpuser"
XoeDir="/home/$XoeAuthorizedUser"
GoeDir="$XoeDir/goe.panel"
GoeConfDir="/usr/local/etc/goe"
GoeConf="$GoeConfDir/goe.conf"
GoeLoginConf="$GoeConfDir/goe.login.conf"
GoeModeConf="$GoeConfDir/goe.mode.conf"

Drawings="$GoeDir/draw"
Actions="$GoeDir/action"
Forms="$GoeDir/form"
Results="$GoeDir/result"
GoeData="$GoeDir/data"
XoeLog="/home/$XoeAuthorizedUser/xoe.logs/server.$XoeAuthorizedUser.log"
XoeServicesData="$GoeData/services.data"
GoeUploads="$GoeDir/uploads"
GoeTranslations="en fr"
GoeTranslationFile="$GoeConfDir/goe.translation"
GoeCustomTranslationFile="$GoeConfDir/goe.custom.translation"
GoeCurrentLanguage="$GoeConfDir/goe.language.conf"
PageRefresh="100"
PageKeep="100"
GoeLogDir="/tmp/goe.logs"
GoeLogFile="$GoeLogDir/goe.log"
GoeLog="/dev/null"
GoeLogMode="$GoeLogDir/goe.log.mode"
GoeTemplatesLog="$GoeLogDir/goe.templates.log"
GoeActionsLog="$GoeLogDir/goe.actions.log"
GoeFormsLog="$GoeLogDir/goe.forms.log"
GoeResultsLog="$GoeLogDir/goe.results.log"
DrawingsLog="$GoeLogDir/goe.drawings.log"
GoeDataLog="$GoeLogDir/goe.data.log"
GoeRefreshConfDir="$GoeDir/goe.refresh"
GoeLocalConf="$GoeRefreshConfDir/goe.local.conf"
GoePagesList="$GoeRefreshConfDir/goe.recent_pages.list"
SiteRefreshPeriodFile="$GoeRefreshConfDir/goe.refresh_period.conf"
SiteRefreshModeFile="$GoeRefreshConfDir/goe.refresh_mode.conf"
SiteRefreshCommentFile="$GoeRefreshConfDir/goe.refresh_comment.conf"
GoeLoopStatusFile="$GoeRefreshConfDir/goe.refresh_loop_status.conf"
GoePaceTimeFile="$GoeRefreshConfDir/goe.pace_time.conf"
GoeRatingFile="$GoeRefreshConfDir/goe.rating.conf"
ActivityFile="$GoeRefreshConfDir/goe.activity"
GoeBuzyFlag="$GoeRefreshConfDir/buzy.flag"
GoeActingFlag="$GoeRefreshConfDir/acting"
GoePidFile="$GoeRefreshConfDir/goe.background.pid"
SiteScriptName="index.php"
SiteImages="images"
ImageSource="http://download.sisalp.net/scripts/panel/images/"
GoeDownloadSource="http://download.sisalp.net/scripts/panel/goe"
PanelDownloadSource="http://download.sisalp.net/scripts/panel/panel.panel"
CssDownloadSource="http://download.sisalp.net/scripts/panel/goe.css"
MoocDownloadSource="http://download.sisalp.net/scripts/panel/mooc"
GoeLoopingFlag="/tmp/goe.looping.flag"
LoopStopFlag="/tmp/goe.loop.stop.flag"
#BackgroundMode Auto | Manual
#RefreshMode All | Displayed
RefreshMode="Displayed"
xTimes="5"
Pace="12"
LogTailLength="20"
LogDetailLength="500"
GeneralLogTailLength="60"
GeneralLogDetailLength="500"
MaxPhpUploadSize="50M"
MaxArchiveUploadSize="20971520"

##LocalConfig
#----------------
# This part of the configuration file is also copied to /usr/local/etc/goe/goe.local.conf
# panel mode is set in /usr/local/etc/goe/goe.mode.conf, check goe --mode command
# mode parameters per default
#set_mode	demo|business|education
ServerMode="demo"
#dashboard list Available :  help support options admin_guide contract openservice closeservice monitor mooc services log
ServerMenuEnabled="help support options admin_guide contract openservice closeservice monitor mooc services log"
#show|hide
HelpMode="show"
SupportMode="show"
ServerMenuMode="hide"
AdminGuideMode="hide"
ServerContractMode="hide"
OpenServiceMode="hide"
CloseServiceMode="hide"
SystemInfoMode="hide"
MoocInfoMode="hide"
ServiceDetailsMode="hide"
ServerLogMode="hide"

#default button lists
ServiceButtonsFullList="editservicemenu renew start stop restart newcase company drop newmooc managemooc exam upload installarchive upgrade"
# downgrade"
DatabaseButtonsFullList="editdatabasemenu save snapshot restore clone copy reference delete wipe_out dbupdate"

ServiceButtonsDefaultList="editservicemenu start stop"
DatabaseButtonsDefaultList="editdatabasemenu save"
RestrictedButtonsList="editservicemenu start stop restart - editdatabasemenu save restore"
CustomPageHeaderConf="$GoeConfDir/goe.custom_page_header.conf"
CustomPageFooterConf="$GoeConfDir/goe.custom_page_footer.conf"
WelcomeDatabaseScript="populate_fr.script"

#------------------------------------------------------------------------------
##EndConfig
#------------------------------------------------------------------------------
# Gestion des traductions
#------------------------------------------------------------------------------
#TR T_SiteTitle	Administration panel of your ERP server by SISalp : Panneau d administration de votre serveur ERP par SISalp
#TR T_SiteNameEnterprise	Tryton, Odoo and OpenERP on line : Tryton, Odoo et OpenERP en ligne
#TR T_SiteNameAcademy	ERP Academy : Academie ERP
#TR T_SiteSloganEnterprise	Virtual Dedicated Server<br/>by SISalp : Serveur Virtuel Dedie<br/>par SISalp
#TR T_SiteSloganAcademy	Training center for<br/>technical classes in enterprise management : Cas pedagogiques d apprentissage<br/>des techniques avancees de gestion
#TR T_Page_top	Main menu : Menu principal
#TR T_Page_back	Back to dashboard : Retour au tableau de bord

if [ ! -d $GoeDir ] ; then rm -f $GoeDir ; mkdir -p $GoeDir ; fi
if [ ! -d $GoeConfDir ] ; then rm -f $GoeConfDir ; mkdir -p $GoeConfDir ; fi
if [ -f "$GoeLocalConf" ] ; then . $GoeLocalConf ; fi
if [ -f "$GoeLoginConf" ] ; then . $GoeLoginConf ; fi
if [ -f "$GoeLogMode" ] ; then . $GoeLogMode ; fi
if [ -f "$GoeModeConf" ] ; then . $GoeModeConf ; fi
#------------------------------------------------------------------------------
EXIT ()
#------------------------------------------------------------------------------
{
case "$2" in
0)
	#LOG_MESSAGE $1 -g  --- goe $AllParameters exit OK line $1 in ${FUNCNAME[*]}
	exit 0
	;;
*)
	LOG_MESSAGE $1 -g  !!! goe $AllParameters exit on bad condition line $1 in ${FUNCNAME[*]}
	exit 1
	;;
esac
}
#------------------------------------------------------------------------------
# for xoe evolution xoe main dir changed and goe conf update is complex
#Analyse des parametres d appel
case "$1" in
--*)
	LoginUser="guest"
	;;
*)
	LoginUser="$1"
	shift
	;;
esac
case "$1" in
--*)
	if [ -f $GoeCurrentLanguage ] ; then
		Language=`cat $GoeCurrentLanguage`
	else
		Language="en"
	fi
	;;
*)
	Language="$1"
	echo "$Language" > $GoeCurrentLanguage 
	shift
	;;
esac
Option="$1"
case "$Option" in
--*)
	;;
*)
	Option="--$Option"
	;;
esac
shift
OptionParameters="$*"
ZoneName="$1"
NewMode="$1"
Service="$1"
NumberTimes="$1"
UserName="$1"
CodeAltSource="$*"
SetAuthorizedUser="$1"
SearchString="$*"
ShellCommand="$*"
BlablaVersion="$1"
DashboardOption="$1"
shift
Drawing="$1"
Database="$1"
CommentDatabase=`echo "$Database" | sed s/--/-/g`
Period="$1"
UserPassword="$1"
DashboardValue="$1"
DashboardNewService="$*"
DashboardCloseService="$1"
DashboardList="$*"
shift
Action="$1"
UserRole="$*"
shift
ActionParameters="$*"

#------------------------------------------------------------------------------
LOG_MESSAGE ()
#------------------------------------------------------------------------------
{
#$1 line_number $2 code : 404|500|501|502|-[e][g][x] $3 exit|message
case "$2" in
404)
	Message="404 $HOSTNAME|goe|`date +%H:%M:%S:%3N`|WARNING|$CurrentUser|$$|$1|$Option WARNING : Cannot find page $Drawing. goe $AllParameters --- $*"
	echo "$Message" >> $GoeLog
	#echo "$Message" >> $XoeLog
	#echo "$Message"
	;;
500)
	Message="500 $HOSTNAME|goe|`date +%H:%M:%S:%3N`|ERROR|$CurrentUser|$$|$1|$Option ERROR : Cannot execute action $Action. goe $AllParameters --- $*"
	echo "$Message" >> $GoeLog
	echo "$Message" >> $XoeLog
	#echo "$Message"
	;;
501)
	Message="501 $HOSTNAME|goe|`date +%H:%M:%S:%3N`|WARNING|$CurrentUser|$$|$1|$Option WARNING : System freeze or overloaded goe $AllParameters --- $*"
	echo "$Message" >> $GoeLog
	#echo "$Message" >> $XoeLog
	#echo "$Message"
	;;
502)
	Message="502 $HOSTNAME|goe|`date +%H:%M:%S:%3N`|ERROR|$CurrentUser|$$|$1|$Option ERROR : Access denied to internal resource goe $AllParameters --- $*"
	echo "$Message" >> $GoeLog
	echo "$Message" >> $XoeLog
	#echo "$Message"
	;;
*)
	Message="$HOSTNAME|goe|`date +%H:%M:%S:%3N`|INFO |$CurrentUser|$$|$LoginUser|$LoginRole|$Option	$*"
	;;
esac
case "$2" in
*e*)
	echo "$Message"
	;;
esac
#case "$2" in
#*g*)
echo "$Message" >> $GoeLog
#	;;
#esac
case "$2" in
*x*)
echo "$Message" >> $XoeLog
	;;
esac

case "$3" in
exit)
	exit $2
	;;
esac
}
#end 
#------------------------------------------------------------------------------
WAIT_FOR ()
#------------------------------------------------------------------------------
{
#exemple  WAIT_FOR $LINENO 10 ! -f /tmp/toto  #delay in O.01 s
wf_call="$1"
shift
ttle="$1" #in  s
shift
iwf=0
#for ((i=0;i<$ttle;i=i+1)) ; do
#	if [ $* ] ; then
#		break
#	fi
#	sleep 0.01
#done
if [ $* ] ; then
	echo -n "." > /dev/null
#$GoeBuzyFlag.log
else
	echo -n "!$wf_call-$ttle-$*!" >> $GoeBuzyFlag.log
	for ((iwf=0;iwf<$ttle;iwf=iwf+1)) ; do	sleep 0.01 ; done
fi
#if [ $i -ge $ttle ] ; then
#	echo "$LINENO|$$|$wf_call|WAITFOR|`whoami`| goe was BUZY on `date +%A_%x-%H:%M:%S:%3N` `whoami` WAITFOR $Option too long time ${ttle}0ms waiting condition $*" >> $GoeBuzyFlag.log
#	LOG_MESSAGE "$LINENO 501 exit $cb_call|WAITFOR| too long time ${ttle}0ms waiting condition $*"
#else echo "goe did not wait on `date +%A_%x-%H:%M:%S:%3N` $cb_call|WAIT FOR too long time ${ttle}0ms waiting condition $*" >> $GoeBuzyFlag.log
#fi
}
#end 
#------------------------------------------------------------------------------
CHECK_BUZY ()
#------------------------------------------------------------------------------
{
#il faudrait un vrai semaphore
cb_call="$1"
shift
case "$1" in
set)
	echo "$LINENO|$$|$cb_call|CHECK_BUZY|`whoami`|set I am buzy from now on `date +%A_%x-%H:%M:%S:%3N`" > $GoeBuzyFlag
	echo -n "s"  >> $GoeBuzyFlag.log
	#echo "$LINENO|$$|$cb_call|CHECK_BUZY|`whoami`|set I am buzy from now on `date +%A_%x-%H:%M:%S:%3N`"  >> $GoeBuzyFlag.log
	;;
release)
	
	rm -f $GoeBuzyFlag
	echo -n "r"  >> $GoeBuzyFlag.log
	#echo "$LINENO|$$|$cb_call|CHECK_BUZY|`whoami`|release I am free from now on `date +%A_%x-%H:%M:%S:%3N`" >> $GoeBuzyFlag.log
	;;
*)
	if [ -e $GoeBuzyFlag ] ; then
		echo -n "w"  >> $GoeBuzyFlag.log
		#echo "$LINENO|$$|$cb_call|CHECK_BUZY|`whoami`|check and wait I have to WAIT because goe is buzy on `date +%A_%x-%H:%M:%S:%3N`" >> $GoeBuzyFlag.log
		#WAIT_FOR $LINENO 200 ! -e $GoeBuzyFlag
		sleep 1
		echo -n "m"  >> $GoeBuzyFlag.log
	fi
	#chmod 660 $GoeBuzyFlag.log > /dev/null 2>&1
	;;
esac
}
#end 

#------------------------------------------------------------------------------
CAT ()
#------------------------------------------------------------------------------
{
WAIT_FOR $LINENO 200 -f $1
cat $1
}
#end 
#------------------------------------------------------------------------------
GET_XOE_DATA ()
#------------------------------------------------------------------------------
{
get_xoe_data_service="$1"
LOG_MESSAGE $LINENO -g GET_XOE_DATA $*
if [ ! -f $XoeServicesData ] ; then
	$0 --get_service_data
	LOG_MESSAGE $LINENO -g GET_XOE_DATA Initialize xoe service data
fi
if [ -f $XoeServicesData ] ; then
	. $XoeServicesData
	if [ ! -z "$get_xoe_data_service" ] ; then
		XoeService="$get_xoe_data_service"
		cat $XoeServicesData | grep "^#Service:" | cut -f2- > /tmp/goe.get_xoe_data.$$.sh
		if [ -f /tmp/goe.get_xoe_data.$$.sh ] ; then
			. /tmp/goe.get_xoe_data.$$.sh
			rm -f /tmp/goe.get_xoe_data.$$.sh
		else
			LOG_MESSAGE $LINENO -g GET_XOE_DATA service $get_xoe_data_service is not found in xoe service data
		fi
	fi
fi
}
#end 
#------------------------------------------------------------------------------
GET_ROLE ()
#------------------------------------------------------------------------------
{
#LOG_MESSAGE $LINENO -g GET_ROLE $LoginUser 
case "$LoginUser" in
guest)
	LoginRole="$LoginUser"
	;;
*)
	LoginRole=`echo "$UserLogins" 2>/dev/null | grep "^$LoginUser " | tail -n 1 | cut -d" " -f3`
	if [ -z "$LoginRole" ] ; then
		#login user should be a service in this case
		GET_XOE_DATA $LoginUser
		LoginRole="$XoeLoginRole"
	fi
	;;
esac
#LOG_MESSAGE $LINENO -g GET_ROLE LoginUser $LoginUser LoginRole $LoginRole
}
#end 
#-------------------------------------------------------------------------
NEW_PASSWORD ()
#-------------------------------------------------------------------------
{
case "$1" in
-min)
	pw_letters=(a b c d e f g h i j k m n o p q r s t u v w x y z a b c d e f g h i j k m n o p q r s t u v w x z 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 )
	shift
	;;
-letters)
	pw_letters=(a b c d e f g h i j k m n o p q r s t u v w x y z )
	shift
	;;
*)
	pw_letters=(a b c d e f g h i j k m n o p q r s t u v w x y z A B C D E F G H I J K L M N P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 )
	;;
esac

if [ -z "$1" ] ; then
	pw_nb_digits=12
else
	pw_nb_digits="$*"
fi
pw_range="${#pw_letters[*]}"
NEW_PWD=""
for nb_digit in $pw_nb_digits ; do
	if [ ! -z "$NEW_PWD" ] ; then NEW_PWD="${NEW_PWD}""_" ; fi
	for ((  pw_digit = 1 ;  pw_digit <= $nb_digit ;  pw_digit++  )) ; do
		pw_index="$(($RANDOM%$pw_range))"
		NEW_PWD="${NEW_PWD}""${pw_letters[$pw_index]}"
	done
done
echo "$NEW_PWD"
}
#end 
#------------------------------------------------------------------------------
GET_DATA ()
#------------------------------------------------------------------------------
{
LOG_MESSAGE $LINENO -g GET_DATA $* Mode $ServerMode command $Option $AllParameters
#SECURITE il conviendrait d'initialiser les variables avant de jouer le fichier d'affectations
get_line="$1"
shift
collect_function="$1"
collect_service="$2"
collect_database="$3"
case "$collect_function" in
page)
	#LOG_MESSAGE $LINENO -g Chargement de la liste des services GET_DATA $* Mode $ServerMode command $Option $AllParameters
	#WAIT_FOR $LINENO 190 -f "$GoeData/ServiceList.data"
	#. $GoeData/ServiceList.data
	GET_XOE_DATA
	#LOG_MESSAGE $LINENO -g Liste des services GET_DATA $* Mode $ServerMode command $Option $AllParameters
	;;
contract)
	#LOG_MESSAGE $LINENO -g GET_DATA Chargement des informations de gestion du contrat
	#WAIT_FOR $LINENO 200 -f "$GoeData/contract.data"
	. $GoeData/contract.data
	#LOG_MESSAGE $LINENO -g GET_DATA Informations de gestion du contrat
	;;
admin_guide)
	#LOG_MESSAGE $LINENO -g GET_DATA Chargement des informations d admin du serveur
	#WAIT_FOR $LINENO 200 -f "$GoeData/admin_guide.data"
	. $GoeData/admin_guide.data
	#LOG_MESSAGE $LINENO -g GET_DATA Informations d admin du serveur
	;;
openservice)
	#LOG_MESSAGE $LINENO -g GET_DATA Chargement des informations ouverture de service
	#WAIT_FOR $LINENO 200 -f "$GoeData/openservice.data"
	. $GoeData/openservice.data
	#LOG_MESSAGE $LINENO -g GET_DATA Informations ouverture de service
	;;
closeservice)
	#LOG_MESSAGE $LINENO -g GET_DATA Chargement des informations cloture de service
	#WAIT_FOR $LINENO 200 -f "$GoeData/closeservice.data"
	. $GoeData/closeservice.data
	#LOG_MESSAGE $LINENO -g GET_DATA Informations cloture de service
	;;
system)
	#LOG_MESSAGE $LINENO -g GET_DATA Chargement des informations relatives au systeme
	#WAIT_FOR $LINENO 200 -f "$GoeData/system.data"
	. $GoeData/system.data
	#LOG_MESSAGE $LINENO -g GET_DATA Informations relatives au systeme
	;;
mooc)
	#LOG_MESSAGE $LINENO -g GET_DATA Chargement des informations relatives aux mooc
	#WAIT_FOR $LINENO 120 -f "$GoeData/mooc.data"
	. $GoeData/mooc.data
	#LOG_MESSAGE $LINENO -g GET_DATA Informations relatives aux mooc
	;;
service)
	LOG_MESSAGE $LINENO -g GET_DATA Chargement des donnees du service $Service
	#WAIT_FOR $LINENO 130 -f $GoeData/$Service.service.data
	COLLECT_DATA $LINENO service $Service
	if [ -f $GoeData/$Service.service.data ] ; then
		. $GoeData/$Service.service.data
	fi
	LANGUAGE $LINENO $ServiceLanguage
	LOG_MESSAGE $LINENO -g GET_DATA Donnees du service $Service
	;;
dashboard_menu)
	LOG_MESSAGE $LINENO -g GET_DATA Chargement des donnees de menu du service $Service
	#WAIT_FOR $LINENO 130 -f $GoeData/$Service.dashboard.data

	COLLECT_DATA $LINENO menu $Service
	. $GoeData/$Service.dashboard.data
	LOG_MESSAGE $LINENO -g GET_DATA Donnees de menu du service $Service - $ServiceStatus - $ServiceDoc - $DatabaseNumber
	;;
database)
	LOG_MESSAGE $LINENO -g GET_DATA Chargement des donnees de la base $Database du service $Service
	#WAIT_FOR $LINENO 140 -f $GoeData/$Service.$Database.database.data
	COLLECT_DATA $LINENO database $Service $Database
	if [ -f $GoeData/$Service.$Database.database.data ] ; then
		. $GoeData/$Service.$Database.database.data	
	fi
	LOG_MESSAGE $LINENO -g GET_DATA Donnees de la base $Database du service $Service
	;;
general_log)
	#LOG_MESSAGE $LINENO -g GET_DATA Chargement des donnees du log general
	#WAIT_FOR $LINENO 160 -f $GoeData/general_log.data
	. $GoeData/general_log.data
	#LOG_MESSAGE $LINENO -g GET_DATA Donnees du log general
	;;
esac
}
#end 
#------------------------------------------------------------------------------
ZONE_TO_SERVICE ()
#------------------------------------------------------------------------------
{
LOG_MESSAGE $LINENO -g  ZONE_TO_SERVICE $* zone $ZoneName drawing $DrawingName action and parameters $Action $ActionParameters
TemplateFile="$1"
if [ -z "$TemplateFile" ] ; then
	TemplateFile="$ZoneName"
	LOG_MESSAGE $LINENO -g  ZONE_TO_SERVICE $* Template is defaulted to zone $ZoneName
fi
case "$ZoneName" in
zone.log*|zone.page*|zone.admin_guide|zone.contract|zone.open_service|zone.close_service)
	Service=""
	Database=""
	;;
*)
	case "$TemplateFile" in
	zone*)
		Service=`echo "$TemplateFile" | cut -d. -f2`
		Database=`echo "$TemplateFile" | cut -d. -f3`
		;;
	*.action|*.form|*.result)
		Service=`echo "$TemplateFile" | cut -d. -f1`
		Database=`echo "$TemplateFile" | cut -d. -f2`
		TemplateFile=`echo "$TemplateFile" | cut -d. -f3-`
		TemplateFile="$GoeDir/${TemplateFile##*.}/$TemplateFile"
		;;
	*.draw)
		Service=`echo "$TemplateFile" | cut -d. -f1`
		Database=`echo "$TemplateFile" | cut -d. -f2`
		TemplateFile="$GoeDir/draw/$TemplateFile"
		;;
	esac
	if [ ! -z "$Service" ] ; then
		GET_DATA $LINENO service $Service
	fi
	if [ ! -z "$Database" ] ; then
		GET_DATA $LINENO database $Service $Database
	fi
	LANGUAGE $LINENO $Language
	;;
esac
CommentDatabase=`echo "$Database" | sed s/--/-/g`
LOG_MESSAGE $LINENO -g  ZONE_TO_SERVICE service $Service database $Database templatefile $TemplateFile
}
#end 
#------------------------------------------------------------------------------
DRAWING_TO_SERVICE ()
#------------------------------------------------------------------------------
{
LOG_MESSAGE $LINENO -g  DRAWING_TO_SERVICE $* drawing_name $1
Service=""
Database=""
if [ ! -z "$1" ] ; then
	drawingname="$1"
	case "$drawingname" in
	page.draw|log_detail.draw|admin_guide.draw|contract.draw|open_service.draw|close_service.draw)
		;;
	*.log_detail.draw)
		Service=`basename $drawingname .log_detail.draw`
		;;
	*.detail.draw)
		information=`basename $drawingname .detail.draw`
		case "$information" in
		*.*)
			Service=`echo "$information" | cut -d. -f1`
			Database=`echo "$information" | cut -d. -f2`
			CommentDatabase=`echo "$Database" | sed s/--/-/g`
			;;
		*)
			Service="$information"
			;;
		esac
		;;
	*.draw)
		Service=`basename $drawingname .draw`
		;;
	esac
fi
LOG_MESSAGE $LINENO -g  DRAWING_TO_SERVICE service $Service database $Database drawing_name $drawingname
}
#end 
#------------------------------------------------------------------------------
DRAW ()
#------------------------------------------------------------------------------
{
LOG_MESSAGE $LINENO -g  DRAW $*
DrawingName="$1"
if [ -z "$DrawingName" ] ; then
	DrawingName="page.draw"
fi
if [ ! -e $GoePagesList ] || [ -w $GoePagesList ] ; then
	echo "$DrawingName" >> $GoePagesList
	recentpages=`tail -n $PageKeep $GoePagesList`
	echo "$recentpages" > $GoePagesList
fi
#echo "DRAW write in $GoePagesList `date +'%Hh%Mm%Ss:%3N'` $$ $CurrentUser $Option $DrawingName"  >> $GoeDir/goe.draw.log
case "$DrawingName" in
*.draw)
	if [ -z "$LoginRole" ] ; then
		LOG_MESSAGE $LINENO -g  DRAW refus des demandes sans identifiant utilisateur de role connu
		DrawingName="Access_Denied"
	else
		case "$DrawingName" in
		page*)
			#LOG_MESSAGE $LINENO -g  DRAW Controle des droits sur page.draw
			case "$LoginRole" in
			Admin*|admin*)
				;;
			*)
				LOG_MESSAGE $LINENO -g  DRAW LoginRole $LoginRole Substitution de la page par $LoginUser.draw
				ServiceLandingPage="$LoginUser.draw"
				DrawingName="$ServiceLandingPage"
				echo "$DrawingName" >> $GoePagesList
				;;
			esac
			;;
		*)
			LOG_MESSAGE $LINENO -g  DRAW Controle des droits sur les autres pages
			case "$LoginRole" in
			Admin*|admin*)
				;;
			*)
				LOG_MESSAGE $LINENO -g  DRAW Controle des droits d acces a la page $DrawingName
				case "$DrawingName" in
				*/*|*..*|*'#'*|*'$'*|*'&'*|*';'*|*.draw*.draw)
					# Hacking attempt
					LOG_MESSAGE $LINENO -g  DRAW Tentative de violation de securite par $LoginRole sur la page $DrawingName
					DrawingName="Access_Denied"
					;;
				$LoginRole.*)
					# Authorized
					echo "$DrawingName" >> $GoePagesList
					;;
				*)
					LOG_MESSAGE $LINENO -g  DRAW Refus de l acces demande par $LoginRole a la page $DrawingName
					DrawingName="Access_Denied"
					;;
				esac
				;;
			esac
			;;
		esac

		CHECK_BUZY $LINENO
		WAIT_FOR $LINENO 150 -f "$Drawings/$DrawingName"
		if [ -f "$Drawings/$DrawingName" ] ; then
			cat $Drawings/$DrawingName
		else
			# if not available, content is created on the fly
			if [ -z "$ZoneName" ] ; then
				ZoneName="$DrawingName"
			fi
			LOG_MESSAGE $LINENO -g "Looking for missing page $Drawings/$DrawingName, served in real time by $CurrentUser /usr/local/bin/goe --draw_now $ZoneName $DrawingName"
			case "$CurrentUser" in
			$XoeAuthorizedUser)
				/usr/local/bin/goe --draw_now $ZoneName $DrawingName
				;;
			$HttpUser)
				#sudo su $XoeAuthorizedUser -c "/usr/local/bin/goe --draw_now $ZoneName $DrawingName"
				/usr/local/bin/goe --draw_now $ZoneName $DrawingName
				;;
			root)
				su $XoeAuthorizedUser -c "/usr/local/bin/goe --draw_now $ZoneName $DrawingName"
				;;
			esac
		fi
	fi
	;;
*.action|*.form|*.result)
	TemplateFile="$DrawingName"
	LOG_MESSAGE $LINENO -g "DRAW action $DrawingName"
	ZONE_TO_SERVICE $DrawingName
	CHECK_BUZY $LINENO
	WAIT_FOR $LINENO 100 -f $TemplateFile
	if [ -f "$TemplateFile" ] ; then
		. $TemplateFile
	else
		if [ -f $Drawings/default.detail.draw ] ; then
			LOG_MESSAGE $LINENO -g "looking for template $TemplateFile,  served $Drawings/default.detail.draw instead"
			cat $Drawings/default.detail.draw
		else
			LOG_MESSAGE $LINENO 404 exit "looking for $TemplateFile"
		fi
	fi
	;;
open_service)
	#TR T_Open_service_result	Open new service : Ouverture du nouveau service
	#TR T_Open_service_result_message	Service is going to be configured, set and started : Le service est en cours de configuration, d installation et de demarrage
	#TR T_open_service_result_wait	and will be available soon : et sera bientot disponible

	echo "<zone name=\"zone.open_service_result\">
	<zone_refresh><![CDATA[<meta http-equiv=\"Refresh\" content=\"30;url=../index.php?action=--page zone.open_service open_service.draw\" />]]></zone_refresh>
        <zone_title><![CDATA[<title>$T_Open_service_result</title>]]></zone_title>
        <zone_type>button_result</zone_type>
        <zone_status>ok</zone_status>
	<zone_html><![CDATA[<hr/><br/><br/>$T_Open_service_result_message <br/>$T_open_service_result_wait<br/> ]]></zone_html>
</zone>"
	;;
close_service)
	#TR T_Close_service_result	Close service : Cloture du service
	#TR T_Close_service_result_message	Service is going to be closed and archived : Le service est en cours de cloture et d archivage
	#TR T_close_service_result_wait	and will be deleted from services list soon : et sera bientot supprime de la liste des services
	echo "<zone name=\"zone.toggle_result\">
	<zone_refresh><![CDATA[<meta http-equiv=\"Refresh\" content=\"30;url=../index.php?action=--page zone.close_service close_service.draw\" />]]></zone_refresh>
        <zone_title><![CDATA[<title>$T_Close_service_result</title>]]></zone_title>
        <zone_type>button_result</zone_type>
        <zone_status>ok</zone_status>
	<zone_html><![CDATA[<hr/><br/><br/>$T_Close_service_result_message<br/>$T_close_service_result_wait<br/>]]></zone_html>
</zone>"
	;;
dashboard)
	#goe --page
	#TR T_Toggle	Modification of dashboard display : Modification de l'affichage du tableau de bord
	#TR T_Toggle_return_message	New dashboard format is going to be displayed : Le nouveau format du tableau de bord va etre affiche
	echo "<zone name=\"zone.toggle_result\">
	<zone_refresh><![CDATA[<meta http-equiv=\"Refresh\" content=\"0;url=../index.php\" />]]></zone_refresh>
        <zone_title><![CDATA[<title>$T_Toggle</title>]]></zone_title>
        <zone_type>button_result</zone_type>
        <zone_status>ok</zone_status>
	<zone_html><![CDATA[$BackImage<hr/><br/>$T_Toggle<br/>$T_Toggle_return_message <br/> ]]></zone_html>
</zone>"
	;;
*)
	LOG_MESSAGE $LINENO 404 exit
	;;
esac
}
#end 
#------------------------------------------------------------------------------
RUN_ACTION ()
#------------------------------------------------------------------------------
{
ActionFile="$1"
if [ ! -z "$ActionParameters" ] ; then
	case "$ActionFile" in
	goe)
		$0 $ActionParameters
		;;
	*)
		case "$ActionFile" in
		*.action|*.result|*.form)
			ZONE_TO_SERVICE $ActionFile
			ActionFile="$TemplateFile"
			;;
		esac
		WAIT_FOR $LINENO 100 -x "$ActionFile"
		if [ -x "$ActionFile" ] ; then
			ActionMessage=`$ActionFile --check $ServerMode $ActionParameters`
			case "$ActionMessage" in
			4*|5*)
				ActionResultStatus="fault"
				;;
			*)
				ActionResultStatus="ok"
				CHECK_BUZY $LINENO
				nohup $ActionFile --execute $ServerMode $ActionParameters >> $GoeLog 2>&1 &
				;;
			esac
			LOG_MESSAGE $LINENO -g  Launching action $ActionFile $ActionParameters :: $ActionMessage
		else
			LOG_MESSAGE $LINENO 500 exit "looking for $ActionFile : not found or cannot execute"
		fi
		;;
	esac
else
	LOG_MESSAGE $LINENO -g RUN_ACTION No action parameters found
	ActionResultStatus="ok"
fi
}
#end
#------------------------------------------------------------------------------
TR ()
#------------------------------------------------------------------------------
{
	shift
	if [ ! -z $1 ] ; then
		translator="$1"
		shift
		lang_index="1"
		for tr_lang in $GoeTranslations ; do
			lang_text=`echo "$*" | cut -d: -f$lang_index | sed s/' $'//`
			echo "$translator=\"$lang_text\"" >> $GoeTranslationFile.$tr_lang
			lang_index=$[$lang_index +1]
		done
	fi
}
#end
#------------------------------------------------------------------------------
TRANSLATE ()
#------------------------------------------------------------------------------
{
	new_translation="no"
	for lang in $GoeTranslations ; do
		if [ ! -f $GoeTranslationFile.$lang ] ; then
			rm -f $GoeTranslationFile.*
			new_translation="yes"
			break
		fi
	done
	case "$new_translation" in
	yes)
		old_IFS=$IFS
		IFS=$'\n'
		for TR_line in `cat $0 | grep "#TR " | grep -v "#Not me"` ; do  #Not me
			IFS=$old_IFS
			TR $TR_line
			IFS=$'\n'
		done
		IFS=$old_IFS
		for lang in $GoeTranslations ; do
			mv $GoeTranslationFile.$lang $GoeTranslationFile.$lang.$$.tmp
			sort $GoeTranslationFile.$lang.$$.tmp > $GoeTranslationFile.$lang
			rm -f $GoeTranslationFile.$lang.$$.tmp
			echo "# $Date $GoeVersion $AllParameters" >> $GoeTranslationFile.$lang
			chmod 777 $GoeTranslationFile.$lang
			sudo chown $XoeAuthorizedUser:$HttpUser $GoeTranslationFile.$lang
		done
		;;
	esac
}
#end
#------------------------------------------------------------------------------
CHECK_ACCESS_RIGHTS ()
#------------------------------------------------------------------------------
{
case "$CurrentUser" in
$HttpUser)
	Sudo="/usr/bin/sudo"
	#sudo su $XoeAuthorizedUser -c "$0 $AllParameters"
	#exit 0
	;;
root)
	Sudo=""
	;;
$XoeAuthorizedUser|*)
	Sudo="/usr/bin/sudo"
	;;
esac
case "$CurrentUser" in
root|$XoeAuthorizedUser)
	for directory in $GoeConfDir $GoeDir $Drawings $Actions $Forms $Results $GoeData $GoeLogDir $GoeRefreshConfDir $GoeUploads ; do
		if [ -h $directory ] ; then
			$Sudo rm -f $directory
		fi
		if [ ! -d $directory ] ; then
			$Sudo mkdir -p $directory
		fi
		$Sudo chmod -R 770 $directory > /dev/null 2>&1
		$Sudo chown -R $XoeAuthorizedUser:$HttpUser $directory  > /dev/null 2>&1
	done
	if [ ! -f $GoeLoginConf ] ; then
		echo "UserLogins=\"$UserLogins\"" > $GoeLoginConf
	fi
	if [ ! -f "$ActivityFile" ] ; then
		echo -n "1234567890123456" > $ActivityFile
	fi
	if [ ! -f $GoeActionsLog ] ; then
		echo "Actions log" > $GoeActionsLog
	fi
	if [ ! -f "$GoeLogFile" ] ; then
		echo "Initializing Goe log in $GoeLogFile" > $GoeLogFile
	fi
	if [ ! -f "$GoeBuzyFlag.log" ] ; then
		echo "List of real time conflicts" > $GoeBuzyFlag.log
	fi
	for conffile in $GoeLoginConf $ActivityFile $GoeActionsLog $GoeLogFile $GoeBuzyFlag.log $GoeCurrentLanguage $XoeLog ; do
		if [ -f $conffile ] ; then
			$Sudo chmod 770 $conffile > /dev/null 2>&1
			$Sudo chown $XoeAuthorizedUser:$HttpUser $conffile > /dev/null 2>&1
		fi
	done
	;;
*)
	if [ ! -w "$ActivityFile" ] ; then
		LOG_MESSAGE $LINENO 502 Cannot notify activity in $ActivityFile
	fi
	;;
esac
}
#end
#------------------------------------------------------------------------------
CHECK_ACCESS_RIGHTS
TRANSLATE
#-------------------------------------------------------------------------
PHP_UPLOAD_MAX ()
#-------------------------------------------------------------------------
{
#should check only 1 php7 version is available
	if [ -f /etc/php/7.*/apache2/php.ini ] ; then
		php_config_ini=`ls /etc/php/7.*/apache2/php.ini 2>/dev/null`
		if [ -f $php_config_ini ] && ! cat $php_config_ini | grep "^upload_max_filesize =" > /dev/null 2>&1 ; then
			echo "upload_max_filesize = $MaxPhpUploadSize" >> $php_config_ini
			echo "upload_max_filesize = $MaxPhpUploadSize is set in $php_config_ini"
		fi
	fi
}
#end 
#------------------------------------------------------------------------------
LANGUAGE ()
{
	LOG_MESSAGE $LINENO LANGUAGE $*
	lang_line="$1"
	shift
	new_lang="$1"
	#case "$CurrentLanguage" in
	#None)
	#	LOG_MESSAGE $LINENO -g $Option $lang_line LANGUAGE page language is set to $new_lang
	#	;;
	#esac
	if [ -z "$new_lang" ] ; then
		new_lang="en"
	fi
	case "$new_lang" in
	$CurrentLanguage)
	#	LOG_MESSAGE $LINENO -g $Option $lang_line LANGUAGE language is unchanged $Service
		;;
	*)
		if [ -e $GoeTranslationFile.$new_lang ] ; then
			. $GoeTranslationFile.$new_lang
		else
			LOG_MESSAGE $LINENO -g $Option $lang_line LANGUAGE traduction file $GoeTranslationFile.$new_lang not found
		fi
		if [ -e $GoeCustomTranslationFile.$new_lang ] ; then
			. $GoeCustomTranslationFile.$new_lang
		fi
		CurrentLanguage="$new_lang"
		#LOG_MESSAGE $LINENO -g $Option $lang_line LANGUAGE traduction en $CurrentLanguage $Service
		;;
	esac	
}
CurrentLanguage="None"
LANGUAGE $LINENO $Language
BackImage="<a href=\"$SiteUrl\" title=\"$T_Page_back\"><big>⬅️ </big></a>"
BackToTopImage="<a href=\"$SiteUrl\" title=\"$T_Page_top\"><big>⬆️ </big></a>"
#------------------------------------------------------------------------------
LOG_MESSAGE $LINENO -g  ====Call $0 $AllParameters

GET_ROLE
case "$Option" in
#------------------------------------------------------------------------------
--on_duty)
	echo -n "x" > $ActivityFile
	echo "<!--frontend activity is set in  $ActivityFile -->"
	LOG_MESSAGE $LINENO -g --on_duty frontend activity is set in  $ActivityFile
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--on_click)
	LOG_MESSAGE $LINENO -g action $Action
	RUN_ACTION  $Action
	LOG_MESSAGE $LINENO -g drawing $Drawing
	DRAW $Drawing
	echo -n "x" > $ActivityFile
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--refresh)
	$0 --get_service_data
	$0 --collect
	$0 --draw
	DRAW $Drawing
	echo -n "x" > $ActivityFile
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--page)
	DRAW $Drawing
	echo -n "x" > $ActivityFile
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--config_head_css)
	echo "<link rel=\"stylesheet\" type="text/css" href=\"$SiteCss\" />"
	EXIT $LINENO 0
	;;
--config_head_title)
	echo "<title>$T_SiteTitle</title>"
	EXIT $LINENO 0
	;;
--config_head_refresh)
	if [ -f "$SiteRefreshPeriodFile" ] ; then
		SiteRefreshPeriod=`cat $SiteRefreshPeriodFile`
	fi
	case "$SiteRefreshPeriod" in
	0)
		;;
	*)
		echo "<meta http-equiv=\"Refresh\" content=\"$SiteRefreshPeriod\"/>"
		;;
	esac
	EXIT $LINENO 0
	;;
--config_page_header)
	if [ -f $CustomPageHeaderConf ] ; then
		. $CustomPageHeaderConf
	fi
	case "$ServerMode" in
	demo|education)
		SiteName="$T_SiteNameAcademy"
		SiteSlogan="$T_SiteSloganAcademy"
		;;
	*|*business)
		SiteName="$T_SiteNameEnterprise"
		SiteSlogan="$T_SiteSloganEnterprise"
		;;
	esac
	SiteHeader="<div id=\"top_header\"><a href=\"$SiteUrl\"><div id=\"header\"><h1><span>$SiteName</span></h1><h2>$SiteSlogan</h2></div></a></div>"
	echo "$SiteHeader"
	EXIT $LINENO 0
	;;
--config_welcome_message)
	#TR T_Welcome		Hello,&nbsp; : Bonjour,&nbsp;
	#TR T_DemoMessage	Demonstration Mode - Actions are not executed : Mode Demonstration - Les actions ne sont pas executees
	case "$ServerMode" in
	demo*)
		WelcomeMessage="$T_DemoMessage &nbsp;-&nbsp;$T_Welcome"
		;;
	*)
		WelcomeMessage="$T_Welcome"
		;;
	esac
	echo -n "$WelcomeMessage"
	EXIT $LINENO 0
	;;
--config_page_footer)
	#TR T_Contact_us	CONTACT US : CONTACTEZ NOUS
	SiteFooter="<div id=\"footer\"><div id=\"block_contact_infos\">
<h4>$T_Contact_us</h4>
<strong>SISalp</strong><br/>		
Les Millieres<br/>
74230 SERRAVAL - FRANCE<br/>
Tel: +33 (0)622 616 438<br/>	
<a href=\"http://sisalp.fr\">sisalp.fr</a>
</div></div>"
	if [ -f $CustomPageFooterConf ] ; then
		. $CustomPageFooterConf
	fi
	echo "$SiteFooter"
	EXIT $LINENO 0
	;;
--config_login_form)
	#TR T_User	User : Utilisateur
	#TR T_Password	Password : Mot de passe
	LoginForm="
		<form method=\"post\" action=\".\">
			<label for=\"login\">$T_User</label>&nbsp;<input type=\"text\" name='login' size=\"12\" required >&nbsp;&nbsp;&nbsp;
			<label for=\"pass\">$T_Password</label>&nbsp;<input type=\"password\" name='pass' size=\"12\" required >&nbsp;&nbsp;&nbsp;
			<img src=\"images/fr.jpg\"> <input name=\"language\" type=\"radio\" value=\"fr\" checked=\"yes\">
			<img src=\"images/en.jpg\"> <input name=\"language\" type=\"radio\" value=\"en\">&nbsp;&nbsp;&nbsp;
			<img src=\"images/login.gif\" alt=\"Log me in\" title=\"Log me in\" />&nbsp;&nbsp;&nbsp;
			<input type=\"submit\" name=\"connect\" value=\"Login\">
		</form>"
	echo -n "$LoginForm"
	EXIT $LINENO 0
	;;
--config_denied_message)
	#TR T_Access_denied Access denied. Please try again : Acces refuse. Veuillez essayer de nouveau.

	LOG_MESSAGE $LINENO -g config_denied_message $T_Access_denied $OptionParameters
	DeniedMessage="<p>$T_Access_denied $OptionParameters</p>"
	echo -n "$DeniedMessage"
	EXIT $LINENO 0
	;;
--config_login_footer)
	#TR T_Test_bandwith	Test current bandwidth from server : Testez le debit actuel du serveur
	#TR T_start_test	start test : demarrer le test
	PerformanceScript="<script type=\"text/javascript\">
//<!--
var image = 'images/testimage.jpg';
var size = 620;
var time1 = 0;
var time2 = 0;
function start_test_vitesse()
{
time1 = new Date();
time1 = time1.getTime();
var img = new Image();
img.src = image+'?'+time1;
img.onload=end_test_vitesse;
}
function end_test_vitesse()
{
var time2 = new Date();
time2 = time2.getTime();
var ms = time2-time1;
var vitesse = Math.round(size/ms*800)/100;
document.getElementById('vitesse').value=vitesse+' Mb/s';
}
//-->
</script>"
	LoginFooter="<div id=\"footer\"><div id=\"block_performance\">
$PerformanceScript
$T_Test_bandwith<br/><br/><input type=\"button\" value=\"$T_start_test\" onclick=\"javascript:start_test_vitesse();\" />&nbsp;&nbsp;&nbsp;<input type=\"text\" id=\"vitesse\" size=\"16\" /><br/><br/></div></div> <!-- footer -->"
	echo "$LoginFooter"
	EXIT $LINENO 0
	;;
--config_page_menu)
	#TR T_Help		Help : Aide
	#TR T_Support		Support : Support
	#TR T_Show		✅ : ✅
	#TR T_Hide		❌ : ❌
	#TR T_Show		Add : Ajouter
	#TR T_Hide		Hide : Retirer
	#TR T_SH_Close		Close : Fermer

	#TR T_SH_More		More... : Plus...

	#TR T_SH_admin_guide	Administration guide : Guide d administration
	#TR T_SH_contract	Contract info : Contrat
	#TR T_SH_openservice	Open service : Nouveau service
	#TR T_SH_closeservice	Close service : Cloture de service
	#TR T_SH_monitor	System status : Etat du system
	#TR T_SH_mooc		Mooc courses : Cours mooc
	#TR T_SH_services	Services status : Etat des services
	#TR T_SH_log		Log messages : Messages du serveur
	#TR T_Compose_main_page	Compose this general dashboard : Composer ce tableau de bord
	#TR T_Service_list_title	Go to services detailled information : Acces aux fiches detaillees des services
	

	LOG_MESSAGE $LINENO -g config_page_menu LoginUser $LoginUser LoginPassword $LoginPassword LoginRole $LoginRole
	case "$LoginRole" in
	Admin*|admin*)
		GET_XOE_DATA
		ServicesMenu=`cat $Drawings/menu.draw`
#	SiteMenu="<div id=\"menu\"><a target=\"_blank\" href=\"$PanelHelp\"><div class=\"menu_element\"><div class=\"static\"> $T_Help </div></div></a><a target=\"_blank\" href=\"$PanelSupport\"><div class=\"menu_element\"><div class=\"static\"> $T_Support </div></div></a><a target=\"_blank\" href=\"$PanelSupport\"><div class=\"menu_element\"><div class=\"static\"> $T_Show... </div></div></a> $ServicesMenu"

		for ServerMenuElement in $ServerMenuEnabled ; do
			case "$ServerMenuAvailable" in
			*$ServerMenuElement*)
				;;
			*)
				LOG_MESSAGE $LINENO -g list of enabled server menu contains unavailable item $ServerMenuElement
				ServerMenuMode="hide"
				;;
			esac
		done
		SiteMenu="
<div class=\"menu\">"
		case "$HelpMode" in
		show)
			SiteMenu="$SiteMenu
<a target=\"_blank\" href=\"$PanelHelp\"><div class=\"menu_element\"><div class=\"static\"> $T_Help </div></div></a>"
			;;
		esac
		case "$SupportMode" in
		show)
			SiteMenu="$SiteMenu
<a target=\"_blank\" href=\"$PanelSupport\"><div class=\"menu_element\"><div class=\"static\"> $T_Support </div></div></a>"
			;;
		esac
		case "$AdminGuideMode" in
		show)
			SiteMenu="$SiteMenu
<a target=\"_blank\" href=\"../index.php?action=--page zone.admin_guide admin_guide.draw\" title=\"$T_SH_admin_guide\"><div class=\"menu_element\"><div class=\"static\"> $T_SH_admin_guide </div></div></a>"
			;;
		esac
		case "$ServerContractMode" in
		show)
			SiteMenu="$SiteMenu
<a target=\"_blank\" href=\"../index.php?action=--page zone.contract contract.draw\" title=\"$T_SH_contract\"><div class=\"menu_element\"><div class=\"static\"> $T_SH_contract </div></div></a>"
			;;
		esac
		case "$OpenServiceMode" in
		show)
			SiteMenu="$SiteMenu
<a target=\"_blank\" href=\"../index.php?action=--page zone.open_service open_service.draw\" title=\"$T_SH_openservice\"><div class=\"menu_element\"><div class=\"static\"> $T_SH_openservice </div></div></a>"
			;;
		esac
		case "$CloseServiceMode" in
		show)
			SiteMenu="$SiteMenu
<a target=\"_blank\" href=\"../index.php?action=--page zone.close_service close_service.draw\" title=\"$T_SH_closeservice\"><div class=\"menu_element\"><div class=\"static\"> $T_SH_closeservice </div></div></a>"
			;;
		esac
		case "$SystemInfoMode" in
		show)
			SiteMenu="$SiteMenu
<a href=\"#system_table\" title=\"$T_SH_monitor\"><div class=\"menu_element\"><div class=\"static\"> $T_SH_monitor </div></div></a>"
			;;
		esac
		case "$MoocInfoMode" in
		show)
			SiteMenu="$SiteMenu
<a href=\"#mooc_table\" title=\"$T_SH_mooc\"><div class=\"menu_element\"><div class=\"static\"> $T_SH_mooc </div></div></a>"
			;;
		esac
		case "$ServiceDetailsMode" in
		show)
			SiteMenu="$SiteMenu
<a href=\"#service_status\" title=\"$T_SH_services\"><div class=\"menu_element\"><div class=\"static\"> $T_SH_services </div></div></a>"
			;;
		esac
		case "$ServerLogMode" in
		show)
			SiteMenu="$SiteMenu
<a href=\"#zonelog_tail_map\" title=\"$T_SH_log\"><div class=\"menu_element\"><div class=\"static\"> $T_SH_log </div></div></a>"
			;;
		esac
		case "$ServerMenuMode" in
		show)
			SiteMenu="$SiteMenu
</div>
<div class=\"dashboard_title\">$T_Compose_main_page</div>
<div class=\"menu\">"

			case "$ServerMenuEnabled" in
			*options*)
				SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard options hide\" title=\"$T_SH_Close\"><div class=\"menu_element\"><div class=\"static\"> $T_SH_Close </div></div></a>"
				;;
			esac

			case "$AdminGuideMode" in
			show)
				case "$ServerMenuEnabled" in
				*admin_guide*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard admin_guide hide\" title=\"$T_Hide $T_SH_admin_guide\"><div class=\"menu_element\"><div class=\"static\"> $T_Hide $T_SH_admin_guide </div></div></a>"
					;;
				esac
				;;

			*)
				case "$ServerMenuEnabled" in
				*admin_guide*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard admin_guide show\" title=\"$T_Show $T_SH_admin_guide\"><div class=\"menu_element\"><div class=\"static\"> $T_Show $T_SH_admin_guide </div></div></a>"
					;;
				esac
				;;
			esac
			case "$ServerContractMode" in
			show)
				case "$ServerMenuEnabled" in
				*contract*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard contract hide\" title=\"$T_Hide $T_SH_contract\"><div class=\"menu_element\"><div class=\"static\"> $T_Hide $T_SH_contract </div></div></a>"
					;;
				esac
				;;

			*)
				case "$ServerMenuEnabled" in
				*contract*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard contract show\" title=\"$T_Show $T_SH_contract\"><div class=\"menu_element\"><div class=\"static\"> $T_Show $T_SH_contract </div></div></a>"
					;;
				esac
				;;
			esac
			case "$OpenServiceMode" in
			show)
				case "$ServerMenuEnabled" in
				*openservice*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard openservice hide\" title=\"$T_Hide $T_SH_openservice\"><div class=\"menu_element\"><div class=\"static\"> $T_Hide $T_SH_openservice </div></div></a>"
					;;
				esac
				;;

			*)
				case "$ServerMenuEnabled" in
				*openservice*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard openservice show\" title=\"$T_Show $T_SH_openservice\"><div class=\"menu_element\"><div class=\"static\"> $T_Show $T_SH_openservice </div></div></a>"
					;;
				esac
				;;
			esac
			case "$CloseServiceMode" in
			show)
				case "$ServerMenuEnabled" in
				*closeservice*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard closeservice hide\" title=\"$T_Hide $T_SH_closeservice\"><div class=\"menu_element\"><div class=\"static\"> $T_Hide $T_SH_closeservice </div></div></a>"
					;;
				esac
				;;

			*)
				case "$ServerMenuEnabled" in
				*closeservice*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard closeservice show\" title=\"$T_Show $T_SH_closeservice\"><div class=\"menu_element\"><div class=\"static\"> $T_Show $T_SH_closeservice </div></div></a>"
					;;
				esac
				;;
			esac
			case "$SystemInfoMode" in
			show)
				case "$ServerMenuEnabled" in
				*monitor*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard monitor hide\" title=\"$T_Hide $T_SH_monitor\"><div class=\"menu_element\"><div class=\"static\"> $T_Hide $T_SH_monitor </div></div></a>"
					;;
				esac
				;;
			*)
				case "$ServerMenuEnabled" in
				*monitor*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard monitor show\" title=\"$T_Show $T_SH_monitor\"><div class=\"menu_element\"><div class=\"static\"> $T_Show $T_SH_monitor </div></div></a>"
					;;
				esac
				;;
			esac
			case "$MoocInfoMode" in
			show)
				case "$ServerMenuEnabled" in
				*mooc*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard mooc hide\" title=\"$T_Hide $T_SH_mooc\"><div class=\"menu_element\"><div class=\"static\"> $T_Hide $T_SH_mooc </div></div></a>"
					;;
				esac
				;;
			*)
				case "$ServerMenuEnabled" in
				*mooc*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard mooc show\" title=\"$T_Show $T_SH_mooc\"><div class=\"menu_element\"><div class=\"static\"> $T_Show $T_SH_mooc </div></div></a>"
					;;
				esac
				;;
			esac
			case "$ServiceDetailsMode" in
			show)
				case "$ServerMenuEnabled" in
				*services*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard services hide\" title=\"$T_Hide $T_SH_services\"><div class=\"menu_element\"><div class=\"static\"> $T_Hide $T_SH_services </div></div></a>"
					;;
				esac
				;;
			*)
				case "$ServerMenuEnabled" in
				*services*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard services show\" title=\"$T_Show $T_SH_services\"><div class=\"menu_element\"><div class=\"static\"> $T_Show $T_SH_services </div></div></a>"
					;;
				esac
				;;
			esac
			case "$ServerLogMode" in
			show)
				case "$ServerMenuEnabled" in
				*log*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard log hide\" title=\"$T_Hide $T_SH_log\"><div class=\"menu_element\"><div class=\"static\"> $T_Hide $T_SH_log </div></div></a>"
					;;
				esac
				;;
			*)
				case "$ServerMenuEnabled" in
				*log*)
					SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard log show\" title=\"$T_Show $T_SH_log\"><div class=\"menu_element\"><div class=\"static\"> $T_Show $T_SH_log </div></div></a>"
					;;
				esac
				;;
			esac
			SiteMenu="$SiteMenu
</div>
<div class=\"dashboard_title\">$T_Service_list_title</div>
<div class=\"menu\">
$ServicesMenu"	
			;;
		hide)
			case "$ServerMenuEnabled" in
			*options*)
				SiteMenu="$SiteMenu
<a href=\"../index.php?action=--on_click dashboard_menu dashboard goe --dashboard options show\" title=\"$T_SH_More\"><div class=\"menu_element\"><div class=\"static\"> $T_SH_More </div></div></a>"
				;;
			esac
			SiteMenu="$SiteMenu
</div>
<div class=\"dashboard_title\">$T_Service_list_title</div>
<div class=\"menu\">
$ServicesMenu"
			;;
		esac
		;;
	guest|Guest)
		SiteMenu="<div class=\"menu\">"
		;;
	*)
		SiteMenu="
<div class=\"menu\">"
		case "$ServerMenuEnabled" in
		*help*)
			SiteMenu="$SiteMenu
<a target=\"_blank\" href=\"$PanelHelp\"><div class=\"menu_element\"><div class=\"static\"> $T_Help </div></div></a>"
			;;
		esac
		case "$ServerMenuEnabled" in
		*support*)
			SiteMenu="$SiteMenu
<a target=\"_blank\" href=\"$PanelSupport\"><div class=\"menu_element\"><div class=\"static\"> $T_Support </div></div></a>"
			;;
		esac
		;;
	esac
	echo "$SiteMenu"
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--config_mode)
	echo "$ServerMode"
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--version)
	case "$BlablaVersion" in
	-noblabla)
		echo "<!-- goe version is $ThisScriptVersion -->"
		;;
	*)
		echo "<!-- goe version is $GoeVersion -->"
		;;
	esac
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--clean)
	CHECK_BUZY $LINENO
	rm -f $ActivityFile
	rm -rf $Drawings
	rm -rf $Actions
	rm -rf $Forms
	rm -rf $Results
	rm -rf $GoeData
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
esac

#------------------------------------------------------------------------------
SHAPE_XML_FILE ()
#------------------------------------------------------------------------------
{
#LOG_MESSAGE $LINENO -g  SHAPE_XML_FILE $*

#SHAPE_XML_FILE [comment] -XmlOption XmlZone [XmlFile]
xmlparamaters="$*"
case "$1" in
-*)
	;;
*)
	sxf_comment="$1"
	shift
	;;
esac
XmlOption="$1"
shift
case "$1" in
*/*|./*)
	XmlFile="$1"
	XmlZone="$2"
	;;
*)
	XmlFile="$2"
	XmlZone="$1"
	;;
esac
if [ ! -z "$XmlFile" ] ; then
	case "$XmlOption" in
	-new_page)
		echo "<!-- This file $XmlOption $XmlFile generated for $XmlZone by $0 on $Date mode $ServerMode parameters $sxf_comment -->
	<zone name=\"$XmlZone\">" > $XmlFile
		#echo "Draw $XmlOption $XmlFile for $XmlZone on $Date mode $ServerMode parameters $sxf_comment-$LINENO" >> $DrawingsLog
		
		;;
	-end_page)
		echo " <!-- end \"$XmlZone\" --> </zone>" >> $XmlFile
		;;
	-continue)
		;;
	-init)
		echo "<!-- This file $XmlOption $XmlFile generated for $XmlZone by $0 on $Date mode $ServerMode parameters $sxf_comment -->" > $XmlFile
		#echo "Draw $XmlOption $XmlFile for $XmlZone on $Date mode $ServerMode parameters $sxf_comment-$LINENO" >> $DrawingsLog
		;;
	*)
		LOG_MESSAGE $LINENO -g error $xmlparamaters
		;;
	esac
else
	case "$XmlOption" in
	-new_page)
		echo "<!-- This content $XmlOption online evaluated for $XmlZone on the fly by $0 on $Date mode $ServerMode parameters $sxf_comment -->
	<zone name=\"$XmlZone\">"
		#echo "On the fly $XmlOption evaluated for $XmlZone on $Date mode $ServerMode parameters $sxf_comment-$LINENO" >> $DrawingsLog

		;;
	-end_page)
		echo " <!-- end \"$XmlZone\" --> </zone>"
		;;
	-continue)
		;;
	-init)
		echo "<!-- This content $XmlOption online evaluated for $XmlZone on the fly by $0 on $Date mode $ServerMode parameters $sxf_comment -->"
		#echo "On the fly $XmlOption evaluated for $XmlZone on $Date mode $ServerMode parameters $sxf_comment-$LINENO" >> $DrawingsLog
		;;
	*)
		LOG_MESSAGE $LINENO -g error $xmlparamaters
		;;
	esac
fi
}
#end 
#------------------------------------------------------------------------------

case "$Option" in
#------------------------------------------------------------------------------
--init)
Drawings="$GoeDir/draw"
Actions="$GoeDir/action"
Forms="$GoeDir/form"
Results="$GoeDir/result"
GoeData="$GoeDir/data"
	for context in $Drawings $Actions $Forms $Results $GoeData ; do
		rm -rf $context
	done
	$0 --get_service_data
	$0 --collect All
	$0 --template
	$0 --draw
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--login)
	GET_XOE_DATA
	AuthorizedRole="denied"
	if [ ! -z "$UserPassword" ] ; then
		# check UserName and UserPassword are accepted, if yes print UserRole, else return denied
		GET_XOE_DATA $UserName
		case "$UserName:$UserPassword" in
		$XoeLoginUser:$XoeLoginPassword)
			AuthorizedRole="$XoeLoginRole"
			;;
		guest:*)
			;;
		esac
		if echo "$UserLogins" | grep "^$UserName $UserPassword " > /dev/null 2>&1 ; then
			AuthorizedRole=`echo "$UserLogins" | grep "^$UserName $UserPassword " | tail -n 1 | cut -d" " -f3`
		fi
	fi
	LOG_MESSAGE $LINENO -g check_login $UserName $UserPassword $AuthorizedRole
	echo -n "$AuthorizedRole"
	;;
#------------------------------------------------------------------------------
--login_list)
	GET_XOE_DATA
	echo "<data>"
	for login_service in $ServiceList ; do
		GET_XOE_DATA $login_service
		if [ ! -z $XoeLoginUser ] && [ ! -z $XoeLoginPassword ] &&  [ ! -z $XoeLoginRole ] ; then
			echo "    <user><login>$XoeLoginUser</login><pass>$XoeLoginPassword</pass><role>$XoeLoginRole</role></user>"
		fi
	done
	# adding configured authorized users
	old_IFS=$IFS
	IFS=$'\n'
	for ligne in $UserLogins ; do
		IFS=$old_IFS
		user_name=`echo "$ligne" | cut -d" " -f1`
		user_password=`echo "$ligne" | cut -d" " -f2`
		user_role=`echo "$ligne" | cut -d" " -f3`
		if [ ! -z $user_name ] && [ ! -z $user_password ] &&  [ ! -z $user_role ] ; then
			echo "    <user><login>$user_name</login><pass>$user_password</pass><role>$user_role</role></user>"
		fi
		IFS=$'\n'
	done
	IFS=$old_IFS
	echo "</data>"
	;;
#------------------------------------------------------------------------------
--collect)

#------------------------------------------------------------------------------
COLLECT_DATA ()
#------------------------------------------------------------------------------
{
LOG_MESSAGE $LINENO -g COLLECT_DATA $* Mode $ServerMode on `date +'%Hh%Mm%Ss:%3N'`
collect_call="$1"
shift
collect_function="$1"
collect_service="$2"
collect_database="$3"
#TR T_Running Running : Marche
#TR T_Stopped Stopped : Arret
cd $GoeData

UPDATE_DATA_FILE ()
{
chmod 770 $1.draft >> $GoeDataLog 2>&1
$Sudo chown -R $XoeAuthorizedUser:$HttpUser $1.draft >> $GoeDataLog 2>&1
mv $1.draft $1
echo -n "$2" >> $GoeDataLog
}
SERVICE_STATUS ()
{
	test_running="$1"
	service_mode="$2"
	case "$test_running" in
	RUNNING)

		ServiceRunning="$T_Running"
		ServiceRunningStatus="ok"
		ServiceStatus="ok"
		ServiceStoppedStatus="unknown"
		;;
	*)
		ServiceRunning="$T_Stopped"
		case "$service_mode" in
		Auto)
			ServiceStatus="fault"
			ServiceRunningStatus="fault"
			ServiceStoppedStatus="ok"
			;;
		*)
			ServiceStatus="unknown"
			ServiceRunningStatus="unknown"
			ServiceStoppedStatus="ok"
			;;
		esac
		;;
	esac
	ServiceDoc="$T_Service $collect_service $T_started_in_mode $ServiceMode, $T_is_in_state $ServiceRunning"
}

case "$collect_function" in
page)
	GET_XOE_DATA
	LOG_MESSAGE $LINENO -g COLLECT_DATA get xoe data ServiceList $ServiceList
	;;
contract)
	case "$ServerContractMode" in
	show)
		#TR T_Contract_manager Contract administration : Evolution du contrat
		#TR T_No_Contract	Contract management function is not available : La gestion du contrat n est pas disponible
		#TR T_Link_contract	Contract management page... : Gestion du contrat...
		ContractFile="$XoeDir/xoe.packages/online_documentation/subscription.documentation"
		if [ -f $XoeDir/xoe.packages/online_documentation.custom/subscription.documentation ] ; then
			ContractFile="$XoeDir/xoe.packages/online_documentation.custom/subscription.documentation"
		fi
		ContractTitle="<div class=\\\"page_zone_title\\\">$T_Contract_manager</div>"
		ContractLink="<br/><div class=\\\"link_element\\\"><div class=\\\"static\\\"> $T_Link_contract <br/></div></div><br/>"
		ContractMapContent="
$ContractLink"
		
		if [ -f $ContractFile ] ; then
			ContractZoneContent="$ContractTitle
`cat $ContractFile | sed 's/\"//g' | sed 's/.*/& <br\/>/'`"
		else
			ContractZoneContent="$ContractTitle
Contract mgt"
		fi
		echo "# $GoeData/contract.data generated by $0 on $Date" > contract.data.draft
		echo "ContractMapContent=\"$ContractMapContent\"" >> contract.data.draft
		echo "ContractZoneContent=\"$ContractZoneContent\"" >> contract.data.draft
		UPDATE_DATA_FILE contract.data b
		;;
	esac
	;;
admin_guide)
	case "$AdminGuideMode" in
	show)
		#TR T_Admin_guide Server administration : Administration du serveur
		#TR T_No_Guide	Administration documentation is not available : La documentation d administration n est pas disponible
		#TR T_Link_admin_guide	Administration instructions... : Instructions d administration...
		AdminGuideFile="$XoeDir/xoe.packages/online_documentation/admin_guide.documentation "
		if [ -f $XoeDir/xoe.packages/online_documentation.custom/admin_guide.documentation ] ; then
			AdminGuideFile="$XoeDir/xoe.packages/online_documentation.custom/admin_guide.documentation "
		fi
		AdminGuideTitle="<div class=\\\"page_zone_title\\\">$T_Admin_guide</div>"
		AdminGuideLink="<br/><div class=\\\"link_element\\\"><div class=\\\"static\\\"> $T_Link_admin_guide <br/></div></div><br/>"
		if [ -f $AdminGuideFile ] ; then
			AdminGuideZoneContent="$AdminGuideTitle
`cat $AdminGuideFile | sed 's/\"//g' | sed 's/.*/& <br\/>/'`"
		else
			AdminGuideZoneContent="$AdminGuideTitle
Next : admin guide"
		fi
		echo "# $GoeData/admin_guide.data generated by $0 on $Date" > admin_guide.data.draft
		echo "AdminGuideZoneContent=\"$AdminGuideZoneContent\"" >> admin_guide.data.draft
		UPDATE_DATA_FILE admin_guide.data a
		;;
	esac
	;;
openservice)
	case "$OpenServiceMode" in
	show)
		#TR T_Form_new_service Form_to_create a new service : Formulaire pour creer un nouveau service
		#TR T_Open_Service Open a new service : Ouverture d un nouveau service
		#TR T_No_Open_Service	Open function is not available : L ouverture de service n est pas disponible
		#TR T_Service_prefix	Prefix to the name of new service : Prefixe du nom du service
		#TR T_Warning_new_service If service already exists, this may damage its configuration : Si le service existe deja, sa configuration peut etre endommagee
		#TR T_Link_open	New serviceform... : Nouveau service...
		#TR T_OpenServiceDefaults	These are configured default values : Voici les valeurs par defaut configurees
		#TR T_Dashbord_validate	Validate : Valider
		#TR T_Choose_role	Service role : Utilisation du service
		#TR T_Choose_template	Service model : Model du service
		OpenServiceDocumentationFile="$XoeDir/xoe.packages/online_documentation/open_service.documentation"
		if [ -f $XoeDir/xoe.packages/online_documentation.custom/open_service.documentation ] ; then
			OpenServiceDocumentationFile="$XoeDir/xoe.packages/online_documentation.custom/open_service.documentation"
		fi
		OpenServiceTitle="<div class=\\\"page_zone_title\\\">$T_Open_Service</div>"
		if [ ! -f "$OpenServiceDocumentationFile" ] ; then
			OpenServiceDocumentation="<br/>No documentation<br/>"
		else
			OpenServiceDocumentation="<br/>`cat $OpenServiceDocumentationFile | sed 's/\"//g' | sed 's/.*/& <br\/>/'`"
		fi
		OpenServiceLink="<br/><div class=\\\"link_element\\\"><div class=\\\"static\\\"> $T_Link_open <br/></div></div><br/>"
		OpenServiceDefaultsTitle="$T_OpenServiceDefaults :<br/>-------------------------<br/>"
		OpenServiceDefaults=`cat $XoeServicesData | grep "^DEF_" | sed 's/\"//g' | sed 's/.*/& <br\/>/'`
		if [ ! -z "$DEF_service_trailing_name" ] ; then
			postfix="-$DEF_service_trailing_name"
		fi
		def_prefix=`NEW_PASSWORD -letters 4`

		role_fields=""
		role_select_form=""
		if [ ! -z "$DEF_role" ] ; then
			role_fields="role role_value"
			nb_roles=`echo "$DEF_role" | wc -w`
			case "$nb_roles" in
			1)
				role_select_form="
<input type=\\\"hidden\\\" name=\\\"role\\\" value=\\\"role\\\">
<input type=\\\"hidden\\\" name=\\\"role_value\\\" value=\\\"$DEF_role\\\">"
				;;
			*)
				role_select_form="
<input type=\\\"hidden\\\" name=\\\"role\\\" value=\\\"role\\\">"
				role_select_form="$role_select_form
<tr><td> -----------------------</td></tr>"
				role_choice=" $T_Choose_role :"
				checked="checked"
				for role in $DEF_role ; do
					role_select_form="$role_select_form
<tr><td>$role_choice</td><td><input type=\\\"radio\\\" name=\\\"role_value\\\" value=\\\"$role\\\" $checked > $role</td></tr>"
					role_choice=""
					checked=""
				done	
				;;
			esac
			
		fi
		template_fields=""
		template_select_form=""
		if [ ! -z "$DEF_model" ] ; then
			template_fields="template template_value"
			nb_templates=`echo "$DEF_model" | wc -w`
			case "$nb_templates" in
			1)
				template_select_form="
<input type=\\\"hidden\\\" name=\\\"template\\\" value=\\\"template\\\">
<input type=\\\"hidden\\\" name=\\\"template_value\\\" value=\\\"$DEF_model\\\">"
				;;
			*)
				template_hidden_field="
<input type=\\\"hidden\\\" name=\\\"template\\\" value=\\\"template\\\">"
				template_select_form="$template_hidden_field

<tr><td> -----------------------</td></tr>
<tr><td> $T_Choose_template : </td><td><select name=\\\"template_value\\\" style=\\\"cursor:pointer; width:300px; padding:3px 20px; margin: 3px; background-color: #eeeeee; border:solid 1px #999999;\\\" required>"
				template_choice=" Choose_template :"
				for template in $DEF_model ; do
					template_select_form="$template_select_form
<option value=\\\"$template\\\"> $template</option>"
				done
				template_select_form="$template_select_form
</select></td></tr>"	
				;;
			esac
			
		fi
#		echo "template_fields
#---------------------------------------------------------------
#$template_fields
#---------------------------------------------------------------
#template_select_form
#---------------------------------------------------------------
#$template_select_form
#---------------------------------------------------------------" >> /tmp/xoe.service_full_set.log

		case "$DEF_company" in
		yes)
			fy_month_fields=""
			fy_month_select_form=""
			if [ -z "$DEF_fy_month" ] ; then
				fy_month_fields="fy_month_field fy_month"
				fy_month_select_form="
<tr><td> -----------------------</td></tr>
<input type=\\\"hidden\\\" name=\\\"fy_month_field\\\" value=\\\"fy_month\\\">
<tr><td> $T_Choose_month : </td><td><select name=\\\"fy_month\\\" style=\\\"cursor:pointer; width:300px; padding:3px 20px; margin: 3px; background-color: #eeeeee; border:solid 1px #999999;\\\" required>
<option value=\\\"1\\\"> $T_january</option>
<option value=\\\"2\\\"> $T_february</option>
<option value=\\\"3\\\"> $T_march</option>
<option value=\\\"4\\\"> $T_april</option>
<option value=\\\"5\\\"> $T_may</option>
<option value=\\\"6\\\"> $T_june</option>
<option value=\\\"7\\\"> $T_july</option>
<option value=\\\"8\\\"> $T_august</option>
<option value=\\\"9\\\"> $T_september</option>
<option value=\\\"10\\\"> $T_october</option>
<option value=\\\"11\\\"> $T_november</option>
<option value=\\\"12\\\"> $T_december</option></select></td></tr>"
			fi
			fy_period_fields=""
			fy_period_select_form=""
			if [ -z "$DEF_fy_period" ] ; then
				fy_period_fields="fy_period_field fy_period"
				fy_period_select_form="

<tr><td> -----------------------</td></tr>
<input type=\\\"hidden\\\" name=\\\"fy_period_field\\\" value=\\\"fy_period\\\">
<tr><td> $T_Choose_period :  </td><td><input type=\\\"radio\\\" name=\\\"fy_period\\\" value=\\\"1\\\" checked>  $T_monthly</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"fy_period\\\" value=\\\"3\\\" >  $T_quarterly</td></tr>
<tr><td> -----------------------</td></tr>"
			fi
			company_fields="$fy_month_fields $fy_period_fields company_field company"
			company_form="$fy_month_select__form
$fy_period_select_form
<tr><td> -----------------------</td></tr>
<input type=\\\"hidden\\\" name=\\\"company_field\\\" value=\\\"company\\\">
<tr><td> $T_Company_name : </td><td><input type=\\\"text\\\" name=\\\"company\\\" value=\\\" $T_default_company\\\" style=\\\"cursor:pointer; width:300px; padding:3px 20px; margin: 3px; background-color: #eeeeee; border:solid 1px #999999;\\\" required ></td></tr>"
			;;
		esac

		if [ -z "$DEF_send_mail_to" ] ; then
			send_mail_to_fields="send_mail_to_field send_mail_to"
			send_mail_to_form="
<tr><td> -----------------------</td></tr>
<input type=\\\"hidden\\\" name=\\\"send_mail_to_field\\\" value=\\\"send_mail_to\\\">
<tr><td> $T_Send_mail_to mail : </td><td><input type=\\\"text\\\" name=\\\"send_mail_to\\\" value=\\\" $T_default_send_mail_to\\\" style=\\\"cursor:pointer; width:300px; padding:3px 20px; margin: 3px; background-color: #eeeeee; border:solid 1px #999999;\\\" required ></td></tr>"
		fi
		OpenServiceForm="
<div id=\\\"zonenewservice_form\\\"><div class=\\\"dashboard_form\\\"><form method=POST enctype=\\\"multipart/form-data\\\" action=\\\"index.php?action=--on_click zone.open_service open_service goe --dashboard newservice\\\"> $T_Form_new_service<br/>
 $T_Open_Service<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"prefix $role_fields $template_fields $company_fields\\\">
<br/><br/>
<table>
<tr><td> $T_Service_prefix : </td><td><input type=\\\"text\\\" name=\\\"prefix\\\" value=\\\"$def_prefix\\\" style=\\\"cursor:pointer; width:300px; padding:3px 20px; margin: 3px; background-color: #eeeeee; border:solid 1px #999999;\\\" required >$postfix</td></tr>
$role_select_form
$template_select_form
$company_form
</table>
 $T_Warning :  $T_Warning_new_service.<br/>
<br/><input type=\\\"submit\\\" name =\\\"validate\\\" value=\\\"✅ $T_Dashbord_validate\\\"/></form></div></div>"

		OpenServiceMapContent="
$OpenServiceLink"
		OpenServiceZoneContent="
$OpenServiceTitle
$OpenServiceDocumentation
$OpenServiceForm
<br/><hr/><br/>
$OpenServiceDefaultsTitle
$OpenServiceDefaults
<br/> <br/>"
		echo "# $GoeData/openservice.data generated by $0 on $Date" > openservice.data.draft
		echo "OpenServiceMapContent=\"$OpenServiceMapContent\"" >> openservice.data.draft
		echo "OpenServiceZoneContent=\"$OpenServiceZoneContent\"" >> openservice.data.draft
		UPDATE_DATA_FILE openservice.data o
		;;
	esac
	;;
closeservice)
	case "$CloseServiceMode" in
	show)
		#TR T_Form_close_Service Form to close a service : Formulaire de cloture d un service
		#TR T_Close_Service Close a service : Cloture d un service
		#TR T_No_Close_Service	Close function is not available : La cloture de service n est pas disponible

		#TR T_Service_to_close	Name of service to close : Nom du service a fermer
		#TR T_Warning_close_service All data, database backup, code and configutaion of the service will be archived : Toutes des donnees, sauvegardes de bases, et tous les programmes et parametres seront archives
		#TR T_Link_close	Close service form... : Cloture de service...
		#TR T_CloseServiceDefaults	These are configured default values : Voici les valeurs par defaut configurees
		#TR T_Current_service_list	List of current services : Liste des services

		CloseServiceDocumentationFile="$XoeDir/xoe.packages/online_documentation/close_service.documentation"
		if [ -f $CloseServiceDocumentationFile.custom ] ; then
			CloseServiceDocumentationFile="$XoeDir/xoe.packages/online_documentation.custom/close_service.documentation"
		fi
		CloseServiceTitle="<div class=\\\"page_zone_title\\\">$T_Close_Service</div>"
		if [ ! -f "$CloseServiceDocumentationFile" ] ; then
			CloseServiceDocumentation="<br/>No documentation<br/>"
		else
			CloseServiceDocumentation="<br/>`cat $CloseServiceDocumentationFile | sed 's/\"//g' | sed 's/.*/& <br\/>/'`"
		fi
		CloseServiceLink="<br/><div class=\\\"link_element\\\"><div class=\\\"static\\\"> $T_Link_close <br/></div></div><br/>"
		optionservice=""
		for closeservice in $ServiceList ; do
			optionservice="$optionservice<option value=\\\"$closeservice\\\">$closeservice</option>"

		done
		CloseServiceForm="

<div id=\\\"zonecloseservice_form\\\"><div class=\\\"dashboard_form\\\"><form method=POST enctype=\\\"multipart/form-data\\\" action=\\\"index.php?action=--on_click zone.close_service close_service goe --dashboard cancelservice\\\"> $T_Form_close_Service<br/>
 $T_Close_Service<br/>
 $T_Current_service_list : $ServiceList<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service_name\\\">
<br/>
<table>
<tr><td>$T_Service_to_close : </td><td><select name=\\\"service_name\\\" $InputStyle >$optionservice</select></td></tr>
</table>
 $T_Warning :  $T_Warning_close_service.<br/>
<br/><input type=\\\"submit\\\" name =\\\"validate\\\" value=\\\"✅ $T_Dashbord_validate\\\"/></form></div></div>"
		CloseServiceMapContent="
$CloseServiceLink"

		CloseServiceZoneContent="
$CloseServiceTitle
$CloseServiceDocumentation
$CloseServiceForm"

		echo "# $GoeData/closeservice.data generated by $0 on $Date" > closeservice.data.draft
		echo "CloseServiceMapContent=\"$CloseServiceMapContent\"" >> closeservice.data.draft
		echo "CloseServiceZoneContent=\"$CloseServiceZoneContent\"" >> closeservice.data.draft
		UPDATE_DATA_FILE closeservice.data o

		;;
	esac
	;;
system)
	case "$SystemInfoMode" in
	show)
		BAR_STATUS () { bst="low" ; if [ $1 -gt 75 ] ; then bst="medium" ; fi ; if [ $1 -ge 88 ] ; then bst="high" ; fi ; echo "$bst" ; }
		CPU () { SystemUserCpu="$2" ; SystemNiceCpu="$3" ; SystemSysCpu="$4" ; SystemIdleCpu="$5" ; SystemIowaitCpu="$6" ;  SystemIrqCpu="$7" ;  SystemSoftirqCpu="$8" ; }
		CPU `cat /proc/stat 2>/dev/null | grep -m 1 "^cpu" | xargs`
		NewSystemUsedCpu=`echo "$SystemUserCpu + $SystemNiceCpu + $SystemSysCpu + $SystemIowaitCpu + $SystemIrqCpu + $SystemSoftirqCpu" | bc`
		NewSystemTotalCpu=`echo "$NewSystemUsedCpu + $SystemIdleCpu " | bc `
		if [ -f $GoeData/system_cpu.data ] ; then
			CPU_PREVIOUS () { OldSystemUsedCpu="$1" ; OldSystemTotalCpu="$2" ; }
			CPU_PREVIOUS `cat $GoeData/system_cpu.data | xargs`
		else
			OldSystemUsedCpu=0
			OldSystemTotalCpu=0
		fi
		SystemUsedCpu=`echo "$NewSystemUsedCpu - $OldSystemUsedCpu" | bc `
		SystemTotalCpu=`echo "$NewSystemTotalCpu - $OldSystemTotalCpu" | bc `
		SystemPercentCpu=`echo "$SystemUsedCpu * 100 / $SystemTotalCpu" | bc`
		SystemStatusCpu=`BAR_STATUS $SystemPercentCpu`
		echo "$NewSystemUsedCpu $NewSystemTotalCpu $SystemPercentCpu $OldSystemUsedCpu $OldSystemTotalCpu" > $GoeData/system_cpu.data
		SystemNumberCpu=`cat /proc/cpuinfo | grep -i "^processor" | wc -l`
		MemTotal=`cat /proc/meminfo | grep ^MemTotal: | xargs | cut -d" " -f2`
		MemFree=`cat /proc/meminfo | grep ^MemFree: | xargs | cut -d" " -f2`
		MemAvailable=`cat /proc/meminfo | grep ^MemAvailable: | xargs | cut -d" " -f2`
		MemUsed=`echo "$MemTotal - $MemAvailable" | bc`
		SystemTotalMemory=`echo "$MemTotal / 1024" | bc`
		SystemUsedMemory=`echo "$MemUsed / 1024" | bc`
		SystemPercentMemory=`echo "$SystemUsedMemory * 100 / $SystemTotalMemory" | bc`
		SystemStatusMemory=`BAR_STATUS $SystemPercentMemory`
		SWAP () { SwapTotal="$3" ; SwapUsed="$4" ; }
		SWAP `cat /proc/swaps | grep -v "Filename" | head -n 1 | xargs`
		SystemTotalSwap=`echo "$SwapTotal /1024" | bc`
		SystemUsedSwap=`echo "$SwapUsed /1024" | bc`
		#LOG_MESSAGE $LINENO -g COLLECT_DATA system MemTotal $MemTotal MemAvailable $MemAvailable MemUsed $MemUsed SystemTotalMemory $SystemTotalMemory SystemUsedMemory $SystemUsedMemory SwapTotal $SwapTotal SwapUsed $SwapUsed SystemTotalSwap $SystemTotalSwap SystemUsedSwap $SystemUsedSwap
		case "$SystemTotalSwap" in
		0)
			SystemPercentSwap="0"
			SystemZoneSwap=""
			;;
		*)
			SystemPercentSwap=`echo "$SystemUsedSwap * 100 / $SystemTotalSwap" | bc`
			SystemStatusSwap=`BAR_STATUS $SystemPercentSwap`
			SystemZoneSwap=""
			#SystemZoneSwap="<tr><td width=\\\"100\\\">$T_Swap</td><td class=\\\"bar_$SystemStatusSwap\\\"><div style=\\\"width: $SystemPercentSwap%\\\"></div></td><td>${SystemUsedSwap}/${SystemTotalSwap}M</td></tr>"
			;;
		esac
		TotalWorkingProcess=`ps axo args`
		PostgresProcess=`echo "$TotalWorkingProcess" | grep "^postgres: " | wc -l`
		PostgresConnections=`echo "$PostgresProcess - 3" | bc`
		if [ $PostgresConnections -le 0 ] ; then PostgresConnections="1" ; fi
		MaxPostgresConnections=`cat /etc/postgresql/*/main/postgresql.conf | grep "^max_connections = " | cut -d" " -f3`
		SystemPercentPostgres=`echo "$PostgresConnections * 100 / $MaxPostgresConnections" | bc`
		SystemStatusPostgres=`BAR_STATUS $SystemPercentPostgres`
		DISK ()
{
GB_SystemTotalDisk="$2"
SystemTotalDisk="${GB_SystemTotalDisk}G"
SystemUsedDisk="$3"
MB_SystemUsedDisk="$4"
MB_SystemTotalDisk=`echo "$GB_SystemTotalDisk * 1024" | bc`
SystemPercentDisk=`echo "$MB_SystemUsedDisk * 100 / $MB_SystemTotalDisk" | bc`
}
#end 
		if [ -f /I_AM_$HOSTNAME ] && cat /I_AM_$HOSTNAME | grep -q "^used_disk " ; then
			DISK `cat /I_AM_$HOSTNAME | grep "^used_disk " | xargs`
		else
			DISK used_disk_is_unknown 1 "`cat /I_AM_$HOSTNAME | grep ^used_disk  | xargs`" O
		fi
		SystemStatusDisk=`BAR_STATUS $SystemPercentDisk`
		if [ -f $SiteRefreshCommentFile ] ; then
			RefreshComment=`cat $SiteRefreshCommentFile`
		else
			RefreshComment=""
		fi
		#TR T_Server_status Server status : Etat du serveur
		#TR T_Processor Processor : Processeur
		#TR T_Memory Memory : Memoire
		#TR T_Swap Swap : Virtuelle
		#TR T_Postgresql Connections : Connexions
		#TR T_Disk Disk : Disque
		#TR T_Calculated_on Calculated at : Calcule a
		SystemZoneContent="<![CDATA[<table id=\\\"system_table\\\" class=\\\"graph\\\" cellspacing=\\\"6\\\" cellpadding=\\\"0\\\">
<thead><tr><th colspan=\\\"3\\\">$T_Server_status</th></tr></thead>
<tbody>
<tr><td width=\\\"100\\\">$T_Processor</td><td  class=\\\"bar_$SystemStatusCpu\\\"><div style=\\\"width: $SystemPercentCpu%\\\"></div></td><td>$SystemPercentCpu% / $SystemNumberCpu CPUs</td></tr>
<tr><td width=\\\"100\\\">$T_Memory</td><td class=\\\"bar_$SystemStatusMemory\\\"><div style=\\\"width: $SystemPercentMemory%\\\"></div></td><td>${SystemUsedMemory}/${SystemTotalMemory}M</td></tr>
<tr><td width=\\\"100\\\">$T_Postgresql</td><td class=\\\"bar_$SystemStatusPostgres\\\"><div style=\\\"width: $SystemPercentPostgres%\\\"></div></td><td>$PostgresConnections / $MaxPostgresConnections </td></tr>
<tr><td width=\\\"100\\\">$T_Disk</td><td class=\\\"bar_$SystemStatusDisk\\\"><div style=\\\"width: $SystemPercentDisk%\\\"></div></td><td>$SystemUsedDisk / $SystemTotalDisk </td></tr>
</tbody>
<tfoot><tr><td colspan=\\\"3\\\">$T_Calculated_on `date +%H:%M:%S`. $RefreshComment.</td></tr></tfoot>
</table>]]>"
		echo "SystemPercentCpu=\"$SystemPercentCpu\"" > system.data.draft
		echo "SystemNumberCpu=\"$SystemNumberCpu\"" >> system.data.draft
		echo "SystemUsedMemory=\"$SystemUsedMemory\"" >> system.data.draft
		echo "SystemTotalMemory=\"$SystemTotalMemory\"" >> system.data.draft
		echo "SystemPercentMemory=\"$SystemPercentMemory\"" >> system.data.draft
		echo "SystemUsedSwap=\"$SystemUsedSwap\"" >> system.data.draft
		echo "SystemTotalSwap=\"$SystemTotalSwap\"" >> system.data.draft
		echo "SystemPercentSwap=\"$SystemPercentSwap\"" >> system.data.draft
		echo "PostgresConnections=\"$PostgresConnections\"" >> system.data.draft
		echo "MaxPostgresConnections=\"$MaxPostgresConnections\"" >> system.data.draft
		echo "SystemPercentPostgres=\"$SystemPercentPostgres\"" >> system.data.draft
		echo "SystemUsedDisk=\"$SystemUsedDisk\"" >> system.data.draft
		echo "SystemTotalDisk=\"$SystemTotalDisk\"" >> system.data.draft
		echo "SystemPercentDisk=\"$SystemPercentDisk\"" >> system.data.draft
		echo "SystemZoneContent=\"$SystemZoneContent\"" >> system.data.draft
		UPDATE_DATA_FILE system.data c
		;;
	esac
	;;
mooc)
	case "$MoocInfoMode" in
	show)
		#TR T_Mooc_status Courses status : Cours crees
		#TR T_No_mooc	No courses has been created yet : Aucun cours n'a encore ete cree
		MoocList=""
		if [ -f /usr/local/bin/mooc ] ; then
			MoocList=`/usr/local/bin/mooc --list`
			MoocZoneContent=`/usr/local/bin/mooc --html`
		fi
		echo "MoocList=\"$MoocList\"" > mooc.data.draft
		echo "MoocZoneContent=\"$MoocZoneContent\"" >> mooc.data.draft
		UPDATE_DATA_FILE mooc.data m
		;;
	esac
	;;
service)
	#LOG_MESSAGE $LINENO -g "COLLECT_DATA Acquisition du service $collect_service"
	GET_XOE_DATA $collect_service
	if [ -z "$ServiceLanguage" ] ; then
		ServiceLanguage="$Language"
	fi
	LANGUAGE $LINENO $ServiceLanguage


	#ServiceButtons=`echo "$PanelButtons" | cut -d+ -f2 | cut -d- -f1`
	#echo "ServiceButtons: $ServiceButtons" >> /tmp/ServiceButtons.$collect_service
	#TestRunning=`/usr/local/bin/xoe --watch -up -noblabla $collect_service`

	#SERVICE_STATUS $TestRunning $ServiceMode
	#if [ -f $XoeDir/xoe.services/$collect_service/mode/contract_situation.$collect_service.mode.conf ] ; then
	#	ServiceSituation=`cat $XoeDir/xoe.services/$collect_service/mode/contract_situation.$collect_service.mode.conf`
	#else
	#	ServiceSituation="never"
	#fi
	#case "$ServiceSituation" in
	# installed|validated)
	#	ServiceRenewStatus="ok"
	#	;;
	# alerted)
	# 	ServiceRenewStatus="warning"
	# 	;;
	# never|*)
	# 	ServiceRenewStatus="static"
	# 	;;
	# esac
	# 	

	#TR T_Login_url Url to log in : Url de connexion
	#TR T_Last_connection Last_connection : Derniere connexion
	#TR T_No_login No login since last service restart : Aucune connexion depuis le dernier redemarrage
	#TR T_Connections Connections since last restart : Connexions depuis le dernier redemarrage
	#TR T_Resume Summary : Commentaire
	#TR T_started_in_mode started in mode : demarre en mode
	#TR T_is_in_state is in state : est en etat
	#TR T_Information_on_service Technical information on service : Information technique sur le service
	#TR T_No_action No action recorded : Aucune action enregistree
	#TR T_Lastactions Recorded actions on service : Historique des actions sur le service
	#TR T_No_anomaly No anomaly since last restart : Pas d'anomalie depuis le dernier redemarrage
	#TR T_Anomalies Anomalies since last restart : Anomalies depuis le dernier redemarrage
	#TR T_Configuration_of_service Configuration of service : Configuration du service
	#TR T_Next_to_come Next to come : Bientot disponible
	#TR T_Instructions_of_service Instructions of service : Instructions du service
	#TR T_Compatibility Databases must be compatible with service version : Les bases utilisees doivent etre compatibles avec la version du service
	#TR T_Renew_service Renew service subscription : Reconduire l abonnement au service
	#TR T_Renew_alerted is no longer in use and is going to be canceled : n'est plus utilise et va etre supprime
	#TR T_Start_service Start service : Demarrer le service
	#TR T_Stop_service Stop service : Arreter le service
	#TR T_Restart_service Restart service : Redemarrer le service
	#TR T_Use_a_case Use a case reference on service : Utiliser un cas de reference sur le service
	#TR T_Set_a_company Set a company profile to build new cases on service : Definir un profil de societe pour construire des nouveaux cas sur le service
	#TR T_Drop_doc Drop databases whose name begin with a prefix on service : Supprimer des bases de donnees dont le nom commence par un prefixe sur le service
	#TR T_Service_log Last messages from service : Derniers messages du service
	#TR T_EditServiceMenuDoc Add an remove buttons in this menu : Ajouter ou retirer des boutons de ce menu
	#TR T_New_tab <big><big><big>➡️ </big></big></big>Open under a new thumbnail<br/><br/> : <big><big><big>➡️ </big></big></big>Ouvrir sous un nouvel onglet<br/><br/>
	#TR T_New_Mooc_doc Declare a new course based on a referenced case of service : Declarer un nouveau cours base sur un cas de reference du service
	#TR T_Manage_Mooc_doc Open, close and cancel a course of service : Ouvrir, fermer et supprimer un cours du service
	#TR T_Exam_doc Manage a course for an exam session on service : Gerer un cours pour une session d examen sur le service
	#TR T_Upload_doc Upload a new archive to service : Telecharger une nouvelle archive au service
	#TR T_Installarchive_doc Install a new archive to service : Installer une nouvelle archive au service
	#TR T_Upgrade_doc Upgrade service to a new version : Montee de version du service
	#TR T_Downgrade_doc Reverse back to previous service version : Retour a la version precedente du service


####


	echo "# $GoeData/$collect_service.service.data generated by $0 on $Date
#insérer le fichier summary du service
. /home/sisalpuser/xoe.services/$collect_service/mode/summary.$collect_service.mode.conf
collect_service=\"$collect_service\"
echo \"Parameters \$*\"
echo \"ButtonUploadStatus\"
echo \"Uploadability\"
						case \"\$ServiceRole\" in
						production)
							Uploadability=\"protected\"
							ButtonUploadStatus=\"unknown\"
							;;
						*)
							Uploadability=\"ok\"
							ButtonUploadStatus=\"ok\"
							;;
						esac
echo \"CaseStatus\"
						CaseStatus=\"unknown\"
						if ls $XoeDir/xoe.services/\$collect_service/references/* >/dev/null 2>&1 || ls $XoeDir/xoe.packages/database_models/\$ServiceErpVariant/\$ServiceVersion/* >/dev/null 2>&1 || ls $XoeDir/xoe.packages/database_models.\$ServiceErpVariant/\$ServiceVersion/* >/dev/null 2>&1  || ls $XoeDir/xoe.packages/database_models/\$collect_service/* >/dev/null 2>&1 ; then
							CaseStatus=\"ok\"
						fi
echo \"CompanyStatus\"
						case \"\$ServiceErpName\" in
						tryton)
							CompanyStatus=\"ok\"
							;;
						*)
							CompanyStatus=\"unknown\"
							;;
						esac
echo \"DatabaseList\"
						DatabaseList=\`echo \"\$DatabasePgList
\$ArchiveList\" | sort -u | xargs\`
echo \"Downgradability\"
						if [ ! -e $XoeDir/xoe.services/\$collect_service/upgraded.txt ] ; then
							Downgradability=\"unknown\"
						else
							Downgradability=\"ok\"
						fi
echo \"DropStatus\"
						if echo \"\$AllDatabaseList\" | grep -q \"\$PgService \" ; then
							DropStatus=\"ok\"
						else
							DropStatus=\"unknown\"
						fi
echo \"Installarchiveability\"
echo \"ButtonInstallarchiveStatus\"
						case \"\$ServiceRole\" in
						production)
							Installarchiveability=\"protected\"
							ButtonInstallarchiveStatus=\"unknown\"
							;;
						*)
							echo \"tester si le directory custom est vide\"
							Installarchiveability=\"ok\"
							ButtonInstallarchiveStatus=\"ok\"
							;;
						esac
						if ! ls $XoeDir/xoe.services/\$collect_service/custom/*.tar.gz > /dev/null 2>&1 && ! ls $XoeDir/xoe.services/\$collect_service/custom/*.zip > /dev/null 2>&1 ; then
							Installarchiveability=\"unknown\"
							ButtonInstallarchiveStatus=\"unknown\"
						fi
echo \"MoocServiceList check how to get MoocList\"

						MoocServiceList=\`echo \"\$MoocList\" | grep \"^\$collect_service:\"\`
echo \"MoocStatus\"
						if echo \"\$MoocList\" | grep -q \"^\$collect_service:\" ; then
							MoocStatus=\"ok\"
						else
							MoocStatus=\"unknown\"
						fi
echo \"ServiceButtons\"
						ServiceButtons=\`echo \"\$PanelButtons\" | cut -d+ -f2 | cut -d- -f1\`
echo \"ServiceInformation\"
						if [ -f $XoeDir/xoe.services/\$collect_service/documentation/configuration-\$collect_service.conf ] ; then
							XoeServiceInfo=\"
\$T_Configuration_of_service \$collect_service
------------------------------------------
\`cat $XoeDir/xoe.services/\$collect_service/documentation/configuration-\$collect_service.conf | sed 's/\"//g'\`\"
						else
							XoeServiceInfo=\"
\$T_Configuration_of_service \$collect_service
------------------------------------------
\$T_Next_to_come\"
						fi
						ServiceInformationText=\"\$ServiceDoc
Version \$ServiceVersion
\$XoeServiceInfo
<br/>------------------------------------------\"
						ServiceLogins=\`tac $XoeDir/xoe.services/\$collect_service/log/server_\$collect_service.log | grep \" login \" | sed 's/successful/\<font color=#336633>successful/' | sed 's/bad/\<font color=#7e0021>bad/' | sed 's/.*/& \<\/font>\<br\/>/'\`
						#ServiceLogins=\"\"
						if [ -z \"\$ServiceLogins\" ] ; then
							ServiceLoginsText=\"<br/>------------------------------------------<br/>\$T_No_login<br/>------------------------------------------\"
						else
							ServiceLoginsText=\"<br/>------------------------------------------<br/>\$T_Connections :<br/>------------------------------------------<br/>\$ServiceLogins\"
						fi
						if [ -z \"\$ServiceLastActions\" ] ; then
							ServiceLastActionsTitle=\"\$T_No_action<br/>------------------------------------------<br/>\"
						else
							ServiceLastActionsTitle=\"\$T_Lastactions :<br/>------------------------------------------<br/>\"
						fi
echo \"ServiceLogErrorsTitle\"
						if [ -z \"\$ServiceLogErrors\" ] ; then
							ServiceLogErrorsTitle=\"<br/>\$T_No_anomaly<br/>------------------------------------------<br/>\"
						else
							ServiceLogErrorsTitle=\"<br/>\$T_Anomalies :<br/>-----------------------------------------<br/>\"
						fi
						ServiceInformation=\`echo \"\$ServiceInformationText \$ServiceLoginsText \$ServiceLogErrorsTitle \$ServiceLogErrors\" | sed 's/\"//g' | sed 's/.*/& <br\/>/'\`
echo \"ServiceInformationTitle\"
						ServiceInformationTitle=\"\$T_Information_on_service \$collect_service<br/>--------------------------------<br/>\"
echo \"ServiceInstructions\"
echo \"ServiceInstructionsTitle\"
						if [ -f $XoeDir/xoe.services/\$collect_service/documentation/instructions-\$collect_service.conf.custom ] ; then
							ServiceInstructionsFile=\"$XoeDir/xoe.services/\$collect_service/documentation/instructions-\$collect_service.conf.custom\"
						else
							ServiceInstructionsFile=\"$XoeDir/xoe.services/\$collect_service/documentation/instructions-\$collect_service.conf\"
						fi
						ServiceInstructionsTitle=\"\$T_Instructions_of_service \$collect_service<br/>------------------------------------------<br/>\"
						if [ -f \$ServiceInstructionsFile ] ; then
							ServiceInstructions=\`cat \$ServiceInstructionsFile | sed 's/\"//g' | sed 's/.*/& <br\/>/'\`
						else
							ServiceInstructions=\"\$T_Next_to_come<br/>\"
						fi
echo \"ServiceLastActions\"
echo \"ServiceLastActionsTitle\"
						ServiceLastActions=\`tac $GoeActionsLog | grep \"Action:\$collect_service:\" | sed 's/.*/& <br\/>/'\`
						if [ -z \"\$ServiceLastActions\" ] ; then
							ServiceLastActionsTitle=\"\$T_No_action<br/>------------------------------------------<br/>\"
						else
							ServiceLastActionsTitle=\"\$T_Lastactions :<br/>------------------------------------------<br/>\"
						fi
echo \"ServiceLastLogin\"
						ServiceLastLogin=\"<![CDATA[<p>\$T_Last_connection :<br/>\$ServiceLast</p>]]>\"
						if [ -z \"\$ServiceLast\" ] ; then
							ServiceLastLogin=\"<![CDATA[<p>\$T_No_login</p>]]>\"
						fi
echo \"ServiceLogDetail\"
echo \"ServiceLogTail\"
echo \"ServiceLogTailStatus\"
echo \"ServiceLogTitle\"
						ServiceLogTailText=\`tail -n $LogTailLength $XoeDir/xoe.services/\$collect_service/log/server_\$collect_service.log | grep -v \"INFO:werkzeug\" | tac | grep -v \" 400 -\"$ | grep -v \" 405 -\"$  | sed 's/\\\"/:/g' | sed 's/\\\`/:/g' | sed 's/.*/& <br\/>/'\`
						ServiceLogTitle=\"\$T_Service_log \$collect_service :<br/>------------------------------------------<br/>\"
						ServiceLogTail=\"\$ServiceLogTailText\"
						if [ -f $XoeDir/xoe.services/\$collect_service/log/server_\$collect_service.log ] ; then
							#ServiceLogText=\"\"
							ServiceLogText=\`tail -n $LogDetailLength $XoeDir/xoe.services/\$collect_service/log/server_\$collect_service.log | grep -v \"INFO:werkzeug\" | tac | grep -v \" 400 -\"$ | grep -v \" 405 -\"$  | sed 's/\\\"/:/g' | sed 's/\\\`/:/g' | sed 's/ERROR/<big><strong><font color=#7e0021>ERROR<\/font><\/strong><\/big>/g' | sed 's/WARNG/<font color=#cc6633>WARNG<\/font>/g' | sed 's/WARNING/<font color=#cc6633>WARNING<\/font>/g' | sed 's/.*/& <br\/>/'\`
						else
							ServiceLogText=\"\$T_Next_to_come<br\/>\"
						fi
						ServiceLogDetail=\"\$ServiceLogText\"
						if echo \"\$ServiceLogText\" | grep -qi \"Traceback\|ERROR$\" ; then
							ServiceLogTailStatus=\"fault\"
						else
							if echo \"\$ServiceLogText\" | grep -qi \"WARNING\" ; then
							ServiceLogTailStatus=\"warning\"
							else
								ServiceLogTailStatus=\"ok\"
							fi
						fi
echo \"ServiceLogErrors\"
						ServiceLogErrors=\`tail -n $LogDetailLength $XoeDir/xoe.services/\$collect_service/log/server_\$collect_service.log | tac | grep \"ERROR\|WARNG\| WARNING \" | sed 's/\\\"/:/g' | sed 's/\\\`/:/g' | sed 's/ERROR/<font color=#7e0021>ERROR<\/font>/' | sed 's/WARNG/<font color=#cc6633>WARNG<\/font>/' | sed 's/WARNING/<font color=#cc6633>WARNING<\/font>/' | sed 's/.*/& <br\/>/'\`

echo \"ServiceLoginUrl\"
						http_links=\"\"
						for url in \$ServiceUrl ; do
							http_links=\"\$http_links <br/><a href=\\\"http://\$url\\\" target=\\\"_blank\\\">http://\$url</a>\"
							#http_links=\"http_\"
						done
						ServiceLoginUrl=\"<![CDATA[<p>\$T_Login_url :\$http_links</p>]]>\"

echo \"ServiceRenewStatus\"
						case \"\$ServiceSituation\" in
						installed|validated)
							ServiceRenewStatus=\"static\"
							;;
						napping)
							ServiceRenewStatus=\"warning\"
							;;
						parked|to_be_closed|*)
							ServiceRenewStatus=\"ok\"
							;;
						esac
echo \"ServiceRunning\"
echo \"ServiceStatus\"
						case \"\$TestRunning\" in
						RUNNING)

							ServiceRunning=\"\$T_Running\"
							ServiceRunningStatus=\"ok\"
							ServiceStatus=\"ok\"
							ServiceStoppedStatus=\"unknown\"
							;;
						*)
							ServiceRunning=\"\$T_Stopped\"
							case \"\$ServiceMode\" in
							Auto)
								ServiceStatus=\"fault\"
								ServiceRunningStatus=\"fault\"
								ServiceStoppedStatus=\"ok\"
								;;
							*)
								ServiceStatus=\"unknown\"
								ServiceRunningStatus=\"unknown\"
								ServiceStoppedStatus=\"ok\"
								;;
							esac
							;;
						esac
echo \"ServiceDoc\"
						ServiceDoc=\"\$T_Service \$XOE_CONTRACT \$T_started_in_mode \$ServiceMode, \$T_is_in_state \$ServiceRunning\"
echo \"ServiceResume\"
						ServiceResume=\`echo \"\$T_Resume:
\$ServiceDocumentation
\$ServiceComment\" | sed 's/\\\"//g' | sed 's/.*/& <br\/>/'\`
echo \"ServiceVersionDoc\"
						ServiceVersionDoc=\"\$T_Compatibility \$ServiceVersion\"
echo \"Upgradability\"
						if [ ! -z \"\$ServiceCompatibilityList\" ] ; then
							case \"\$ServiceRole\" in
							production)
								Upgradability=\"unknown\"
								;;
							*)
								Upgradability=\"ok\"
								;;
							esac
						else
							Upgradability=\"unknown\"
						fi
ButtonCompanyDoc=\"\$T_Set_a_company \$collect_service\"
ButtonDowngradeDoc=\"\$T_Downgrade_doc \$collect_service\"
ButtonDropDoc=\"\$T_Drop_doc \$collect_service\"
ButtonEditServiceMenuDoc=\"\$T_EditServiceMenuDoc\"
ButtonExamDoc=\"\$T_Exam_doc \$collect_service\"
ButtonInstallarchiveDoc=\"\$T_Installarchive_doc \$collect_service\"
ButtonManageMoocDoc=\"\$T_Manage_Mooc_doc \$collect_service\"
ButtonNewCaseDoc=\"\$T_Use_a_case \$collect_service\"
ButtonNewMoocDoc=\"\$T_New_Mooc_doc \$collect_service\"
echo \"ButtonRenewDoc\"
						case \"\$ServiceSituation\" in
						alerted)
							ButtonRenewDoc=\"\$collect_service \$T_Renew_alerted\"
							;;
						*)
							ButtonRenewDoc=\"\$T_Renew_service \$collect_service\"
							;;
						esac
ButtonRestartDoc=\"\$T_Restart_service \$collect_service\"
ButtonStartDoc=\"\$T_Start_service \$collect_service\"
ButtonStopDoc=\"\$T_Stop_service \$collect_service\"
ButtonUpgradeDoc=\"\$T_Upgrade_doc \$collect_service\"
ButtonUploadDoc=\"\$T_Upload_doc \$collect_service\"
ButtonRenewStatus=\"\$ServiceRenewStatus\"
ButtonStartStatus=\"\$ServiceStoppedStatus\"
ButtonStopStatus=\"\$ServiceStatus\"
ButtonRestartStatus=\"\$ServiceStatus\"
ButtonNewCaseStatus=\"\$CaseStatus\"
ButtonCompanyStatus=\"\$CompanyStatus\"
ButtonDropStatus=\"\$DropStatus\"
ButtonUpgradeStatus=\"\$Upgradability\"
ButtonDowngradeStatus=\"\$Downgradability\"
ButtonNewMoocStatus=\"\$CaseStatus\"
ButtonManageMoocStatus=\"\$MoocStatus\"
ButtonExamStatus=\"\$MoocStatus\"
ButtonEditServiceMenuStatus=\"static\"

if [ -f \$GoeActingFlag.\$collect_service.flag ] ; then
	#ButtonStartStatus=\"unknown\"
	#ButtonStopStatus=\"unknown\"
	#ButtonRestartStatus=\"unknown\"
	ButtonNewCaseStatus=\"unknown\"
	#ButtonCompanyStatus=\"unknown\"
	ButtonDropStatus=\"unknown\"
	ButtonUpgradeStatus=\"unknown\"
	ButtonDowngradeStatus=\"unknown\"
	ButtonUploadStatus=\"unknown\"
	ButtonInstallarchiveStatus=\"unknown\"
	ButtonNewMoocStatus=\"unknown\"
	ButtonManageMoocStatus=\"unknown\"
	ButtonExamStatus=\"unknown\"
	#ButtonEditServiceMenuStatus=\"unknown\"
fi

###############################################################



echo \"

ServiceButtons : \$ServiceButtons
ServiceStatus : \$ServiceStatus
ServiceDoc : \$ServiceDoc
ServiceErpName : \$ServiceErpName
ServiceErpVariant : \$ServiceErpVariant
ServiceVersion : \$ServiceVersion
ServiceVersionDoc : \$ServiceVersionDoc
ServiceRunningStatus : \$ServiceRunningStatus
ServiceRunning : \$ServiceRunning
ServiceRole : \$ServiceRole
ServiceLanguage : \$ServiceLanguage
ServiceLoginUrl : \$ServiceLoginUrl
ServiceLastLogin : \$ServiceLastLogin
ServiceResume : \$ServiceResume
ServiceRenewStatus : \$ServiceRenewStatus
ServiceStoppedStatus : \$ServiceStoppedStatus
ButtonRenewDoc : \$ButtonRenewDoc
ButtonStartDoc : \$ButtonStartDoc
ButtonStopDoc : \$ButtonStopDoc
ButtonRestartDoc : \$ButtonRestartDoc
ButtonNewCaseDoc : \$ButtonNewCaseDoc
ButtonCompanyDoc : \$ButtonCompanyDoc
CaseStatus : \$CaseStatus
CompanyStatus : \$CompanyStatus
ButtonDropDoc : \$ButtonDropDoc
DropStatus : \$DropStatus
DatabasePgList : \$DatabasePgList
ArchiveList : \$ArchiveList
DatabaseList : \$DatabaseList
DatabaseNumber : \$DatabaseNumber
ButtonNewMoocDoc : \$ButtonNewMoocDoc
ButtonManageMoocDoc : \$ButtonManageMoocDoc
ButtonExamDoc : \$ButtonExamDoc
MoocStatus : \$MoocStatus
MoocServiceList : \$MoocServiceList
Upgradability : \$Upgradability
ButtonUpgradeDoc : \$ButtonUpgradeDoc
ServiceCompatibilityList : \$ServiceCompatibilityList
Downgradability : \$Downgradability
ButtonDowngradeDoc : \$ButtonDowngradeDoc
Uploadability : \$Uploadability
ButtonUploadDoc : \$ButtonUploadDoc
Installarchiveability : \$Installarchiveability
ButtonInstallarchiveDoc : \$ButtonInstallarchiveDoc
ButtonUploadDoc : \$ButtonUploadDoc
ButtonEditServiceMenuDoc : \$ButtonEditServiceMenuDoc

ButtonRenewStatus : \$ServiceRenewStatus
ButtonStartStatus:\$ServiceStoppedStatus
ButtonStopStatus : \$ServiceStatus
ButtonRestartStatus : \$ServiceStatus
ButtonNewCaseStatus : \$CaseStatus
ButtonCompanyStatus : \$CompanyStatus
ButtonDropStatus : \$DropStatus
ButtonUpgradeStatus : \$Upgradability
ButtonDowngradeStatus : \$Downgradability
ButtonUploadStatus : \$ButtonUploadStatus
ButtonInstallarchiveStatus : \$ButtonInstallarchiveStatus
ButtonNewMoocStatus : \$CaseStatus
ButtonManageMoocStatus : \$MoocStatus
ButtonExamStatus : \$MoocStatus
ButtonEditServiceMenuStatus : static

if [ -f $GoeActingFlag.$collect_service.flag ] ; then
	#ButtonStartStatus : unknown
	#ButtonStopStatus : unknown
	#ButtonRestartStatus : unknown
	ButtonNewCaseStatus : unknown
	#ButtonCompanyStatus : unknown
	ButtonDropStatus : unknown
	ButtonUpgradeStatus : unknown
	ButtonDowngradeStatus : unknown
	ButtonUploadStatus : unknown
	ButtonInstallarchiveStatus : unknown
	ButtonNewMoocStatus : unknown
	ButtonManageMoocStatus : unknown
	ButtonExamStatus : unknown
	#ButtonEditServiceMenuStatus : unknown
fi
#--------------------------------Config
ServiceInformationTitle : \$ServiceInformationTitle
ServiceInformation : \$ServiceInformation
ServiceLastActionsTitle : \$ServiceLastActionsTitle
ServiceLastActions : \$ServiceLastActions
ServiceLogErrorsTitle : \$ServiceLogErrorsTitle
ServiceLogErrors : \$ServiceLogErrors
ServiceInstructionsTitle : \$ServiceInstructionsTitle
ServiceInstructions : \$ServiceInstructions
#--------------------------------Log
ServiceLogTailStatus : \$ServiceLogTailStatus
ServiceLogTitle : \$ServiceLogTitle
ServiceLogTail : \$ServiceLogTail
ServiceLogDetail : \$ServiceLogDetail
\" > /tmp/goe.service.test.\$collect_service.result



" > $collect_service.service.data.draft

	UPDATE_DATA_FILE $collect_service.service.data s

#	echo "# $GoeData/$collect_service.dashboard.data generated by $0 on $Date
#ServiceStatus=\"$ServiceStatus\"
#ServiceDoc=\"$ServiceDoc\"
#DatabaseNumber=\"$DatabaseNumber\"
#" > $collect_service.dashboard.data
	. $collect_service.service.data
	#cat -n $collect_service.service.data
	#echo "# $collect_service.service.data generated by $0 on `date`"
	;;
menu)
	LOG_MESSAGE $LINENO -g  "Acquisition du menu du service $collect_service"
	#ServiceMode=`cat /home/sisalpuser/xoe.services/$collect_service/mode/service.$collect_service.mode.conf`
	#TestRunning=`cat /home/sisalpuser/xoe.services/$collect_service/mode/service_running.$collect_service.mode.conf`
	#DatabaseNumber=`cat /home/sisalpuser/xoe.services/$collect_service/mode/database_number.$collect_service.mode.conf`
	#SERVICE_STATUS $TestRunning $ServiceMode

	GET_XOE_DATA $collect_service
	if [ -z "$ServiceLanguage" ] ; then
		ServiceLanguage="$Language"
	fi
	LANGUAGE $LINENO $ServiceLanguage

	#SERVICE_STATUS $TestRunning $ServiceMode



	echo "# $GoeData/$collect_service.dashboard.data generated by $0 on $Date ServiceMode $ServiceMode TestRunning $TestRunning
#insérer le fichier summary du service
. /home/sisalpuser/xoe.services/$collect_service/mode/summary.$collect_service.mode.conf
collect_service=\"$collect_service\"
echo \"Parameters \$*\"
case \"\$TestRunning\" in
RUNNING)
	ServiceStatus=\"ok\"
	;;
*)
	case \"\$ServiceMode\" in
	Auto)
		ServiceStatus=\"fault\"
		;;
	*)
		ServiceStatus=\"unknown\"
		;;
	esac
	;;
esac
ServiceDoc=\"\$T_Service \$XOE_CONTRACT \$T_started_in_mode \$ServiceMode, \$T_is_in_state \$ServiceRunning\"
DatabaseNumber=\"\$DatabaseNumber\"
" > $collect_service.dashboard.data

	#. $collect_service.dashboard.data
	#cat -n $collect_service.service.data
	#echo "# $collect_service.service.data generated by $0 on `date`"
	;;
database)
	LOG_MESSAGE $LINENO -g  "Acquisition de la base $collect_database du service $collect_service"

	GET_XOE_DATA $collect_service

	DatabaseButtons=`echo "$PanelButtons" | cut -d+ -f2 | cut -d- -f2`
	#echo "DatabaseButtons: ==-Enabled buttons $Enabled_Buttons database buttons $DatabaseButtons==" >> /tmp/DatabaseButtons.$collect_service
	if  echo "$DatabasePgList" | grep -q "^$collect_database" ; then
		DbStatus="ok"
		#TR T_is_active is active : est active
		DbDoc="$T_Database $collect_database $T_on_service $collect_service $T_is_active"
	else
		#TR T_is_not_active is not active : n'est pas active
		DbStatus="unknown"
		DbDoc="$T_Database $collect_database $T_on_service $collect_service $T_is_not_active"
	fi
	#TR T_was_saved_on was saved on : a ete archivee le
	ArchiveDir="$XoeDir/xoe.services/$collect_service/database/$collect_database"
	if  [ -d $ArchiveDir ] ; then
		#TR T_Not_saved No archive : Pas de sauvegardes
		#TR T_has_no_archive doesn't have an archive : n'a pas de sauvegarde disponible
		ArchiveDate="$WarnImage<small>$T_Not_saved</small>"
		ArchiveDoc="$T_Database $collect_database $T_on_service $collect_service $T_has_no_archive"
		ArchiveStatus="unknown"
		for archivefile in `ls $ArchiveDir/last-archive_* ` `ls $ArchiveDir/monthly_reference_* ` ; do
			if [ -f "$archivefile" ] ; then
				ArchiveDate=`date --reference=$archivefile +%d/%m/%Y_%H:%M:%S`
				ArchiveDoc="$T_Database $collect_database $T_on_service $collect_service $T_was_saved_on $ArchiveDate"
				ArchiveStatus="ok"
				break
			fi
		done
	else
		#TR T_Never_saved Not saved : N'est pas sauvegardee
		ArchiveDate="$WarnImage<small>$T_Never_saved</small>"
		ArchiveDoc="$T_Database $collect_database $T_on_service $collect_service $T_has_no_archive"
		ArchiveStatus="unknown"
	fi
	DbConf=`echo "$XoeConf" | grep "^database:$collect_service:" | cut -d: -f3 | sort -u | xargs`
	#LOG_MESSAGE $LINENO -g collect database:$collect_service: DbConf $DbConf
	DbInformation=""
	if [ -z "$DbConf" ] ; then
		#TR T_No_Auto_databases No automated operations on databases on service : Pas de traitement automatique programme pour les bases du service
		DbInformation="$T_No_Auto_databases $collect_service
---------------------------------------------------------------------------"
	else
		for DbPrefix in $DbConf ; do
			case "$collect_database" in
			$DbPrefix*)
				#TR T_Auto_database Operations automated on database : Operations automatiques s appliquant a la base de donnees
				DbInformation="$DbInformation
$T_Auto_database $collect_database
---------------------------------------------------------------------------
 `echo "$XoeConf" | grep "^database:$collect_service:$DbPrefix:"`"
				;;
			esac
		done
	fi
	case "$ArchiveStatus" in
	ok)
		#TR T_Archive_list Archive list of database : Liste des sauvegardes de la base de donnees
		DbInformation="$DbInformation
$T_Archive_list $collect_database
---------------------------------------------------------------------------
`ls -lh $ArchiveDir | grep -v key$ | grep -v filestore$`"
		;;
	unknown)
		#TR T_No_archive_available No_archive for database : Pas de sauvegarde disponible de la base de donnees
		DbInformation="$DbInformation
$T_No_archive_available $collect_database
---------------------------------------------------------------------------"
		;;
	esac
	case "$ServiceErpName" in
	tryton)
		ButtonDbUpdateStatus="ok"
		;;
	*)
		ButtonDbUpdateStatus="unknown"
		;;
	esac

	DbInformation=`echo "$DbInformation" | sed 's/.*/& <br\/>/'`
	#TR T_Save_database Save database : Sauvegarder la base de donnees
	#TR T_Snapshot_database	Auto save mode of database : La sauvegarde periodique de la base de donnees
	#TR T_is_on	is activated : est active
	#TR T_can_be_activated	can be activated : peut etre activee
	#TR T_requires_a_working_database	requires a working database : necessite une base de donees active
	ButtonSnapshotDoc="$T_Snapshot_database $collect_database $T_on_service $collect_service"
	case "$DbStatus" in
	ok)
		ButtonSaveDoc="$T_Save_database $collect_database $T_on_service $collect_service"
		ButtonSaveStatus="ok"
		if [ -f /tmp/xoe.snapshot.mode.$collect_service.$collect_database.flag ] ; then
			ButtonSnapshotDoc="$T_Snapshot_database $collect_database $T_on_service $collect_service $T_is_on"
			ButtonSnapshotStatus="unknown"
		else
			ButtonSnapshotDoc="$T_Snapshot_database $collect_database $T_on_service $collect_service $T_can_be_activated"
			ButtonSnapshotStatus="ok"
		fi
		;;
	*)
		ButtonSaveDoc="$T_Save_database $collect_database $T_on_service $collect_service $T_requires_a_working_database"
		ButtonSaveStatus="unknown"
		ButtonSnapshotDoc="$T_Snapshot_database $collect_database $T_on_service $collect_service $T_requires_a_working_database"
		ButtonSnapshotStatus="unknown"
		;;
	esac
	#TR T_Restore_database Restore_database : Restaurer la base de donnees
	ButtonRestoreDoc="$T_Restore_database $collect_database $T_on_service $collect_service"
	#TR T_Clone_database Clone database : Cloner la base de donnees
	#TR T_to_several_copies to several copies : en plusieurs exemplaires
	ButtonCloneDoc="$T_Clone_database $collect_database $T_on_service $collect_service $T_to_several_copies"
	#TR T_Copy_database Copy database : Copier la base de donnees
	#TR T_to_another_service to another service : sur un autre service
	ButtonCopyDoc="$T_Copy_database $collect_database $T_on_service $collect_service $T_to_another_service"
	#TR T_Reference_database Create a reference from database : Creer une reference de la base de donnees
	ButtonReferenceDoc="$T_Reference_database $collect_database $T_on_service $collect_service"
	#TR T_Delete_database Delete database : Suppression de la base de donnees
	ButtonDeleteDoc="$T_Delete_database $collect_database $T_on_service $collect_service"
	#TR T_Delete_archives_of_database Delete archives of database : Effacement des sauvegardes de la base de donnees
	ButtonWipeOutDoc="$T_Delete_archives_of_database $collect_database $T_on_service $collect_service"
	#TR T_Update_database Update database : Mise a jour de la base de donnees
	ButtonDbUpdateDoc="$T_Update_database $collect_database $T_on_service $collect_service"
	#TR T_EditDatabaseMenuDoc Add an remove buttons in this menu : Ajouter ou retirer des boutons de ce menu
	ButtonEditDatabaseMenuDoc="$T_EditDatabaseMenuDoc"

	#TR T_DatabaseLastactions Last recorded actions on this database : Dernieres actions enregistrees sur cette base de donnees
	DatabaseLastActions=`cat $GoeActionsLog | grep "Action:$collect_service:$collect_database:" | tail -n 3 | sed 's/.*/& <br\/>/'`
	if [ -z "$DatabaseLastActions" ] ; then
		DatabaseLastActions="$T_No_action<br/>------------------------------------------<br/>"
	else
		DatabaseLastActions="$T_DatabaseLastactions :<br/>------------------------------------------<br/>
$DatabaseLastActions"
	fi

	echo "# $GoeData/$collect_service.$collect_database.database.data generated by $0 on $Date
DatabaseButtons=\"$DatabaseButtons\"
DbStatus=\"$DbStatus\"
DbDoc=\"$DbDoc\"
DbInformation=\"$DbInformation\"
ArchiveDoc=\"$ArchiveDoc\"
ArchiveStatus=\"$ArchiveStatus\"
ArchiveDate=\"$ArchiveDate\"
ButtonDbUpdateStatus=\"$ButtonDbUpdateStatus\"
ButtonSaveDoc=\"$ButtonSaveDoc\"
ButtonSnapshotDoc=\"$ButtonSnapshotDoc\"
ButtonRestoreDoc=\"$ButtonRestoreDoc\"
ButtonCloneDoc=\"$ButtonCloneDoc\"
ButtonCopyDoc=\"$ButtonCopyDoc\"
ButtonReferenceDoc=\"$ButtonReferenceDoc\"
ButtonDeleteDoc=\"$ButtonDeleteDoc\"
ButtonWipeOutDoc=\"$ButtonWipeOutDoc\"
ButtonDbUpdateDoc=\"$ButtonDbUpdateDoc\"
ButtonEditDatabaseMenuDoc=\"$ButtonEditDatabaseMenuDoc\"
DatabaseLastActions=\"$DatabaseLastActions\"

ButtonSaveStatus=\"$ButtonSaveStatus\"
ButtonSnapshotStatus=\"$ButtonSnapshotStatus\"
ButtonRestoreStatus=\"$ArchiveStatus\"
ButtonCloneStatus=\"$ArchiveStatus\"
ButtonCopyStatus=\"$ArchiveStatus\"
ButtonReferenceStatus=\"$ArchiveStatus\"
ButtonDeleteStatus=\"$DbStatus\"
ButtonWipeOutStatus=\"$ArchiveStatus\"
ButtonEditDatabaseMenuStatus=\"static\"

if [ -f $GoeActingFlag.$collect_service.flag ] ; then
	ButtonSaveStatus=\"unknown\"
	ButtonSnapshotStatus=\"unknown\"
	ButtonRestoreStatus=\"unknown\"
	ButtonCloneStatus=\"unknown\"
	ButtonCopyStatus=\"unknown\"
	ButtonReferenceStatus=\"unknown\"
	ButtonDeleteStatus=\"unknown\"
	ButtonWipeOutStatus=\"unknown\"
	ButtonDbUpdateStatus=\"unknown\"
	#ButtonEditDatabaseMenuStatus=\"unknown\"
fi
" > $collect_service.$collect_database.database.data.draft
	UPDATE_DATA_FILE $collect_service.$collect_database.database.data d
	#LOG_MESSAGE $LINENO -g  "COLLECT_DATA Mise a jour des data de la base $collect_database du service $collect_service UPDATE_DATA_FILE $collect_service.$collect_database.database.data d"
	. $collect_service.$collect_database.database.data
	#cat -n 	$collect_service.$collect_database.database.data
	#echo "# $collect_service.$collect_database.database.data generated by $0 on `date`"
	;;
general_log)
	case "$ServerLogMode" in
	show)
		#LogTailText=`tail -n $GeneralLogTailLength $XoeLog | tac | sed 's/\"/:/g' | sed 's/\`/:/g' | sed 's/.*/& <br\/>/'`
		#TR T_Server_log Server last log : Derniers messages du serveur
		#LogTitle="$T_Server_log :<br/>------------------------------------------<br/>"
		#LogTail="$LogTailText"
		#LogDetailText=`tail -n $GeneralLogDetailLength $XoeLog | tac | sed 's/\"/:/g' | sed 's/\`/:/g' | sed 's/ERROR/<big><strong><font color=#7e0021>ERROR<\/font><\/strong><\/big>/g' | sed 's/WARNG/<font color=#cc6633>WARNG<\/font>/g'  | sed 's/WARNING/<font color=#cc6633>WARNING<\/font>/g' | sed 's/.*/& <br\/>/'`
		#LogDetail="$LogDetailText"
		#if echo "$LogDetailText" | grep -qi "Traceback\|ERROR$" ; then
		#	LogTailStatus="fault"
		#else
		#	if echo "$LogDetailText" | grep -qi "WARNING" ; then
		#	LogTailStatus="warning"
		#	else
		#		LogTailStatus="ok"
		#	fi
		#fi
		echo "# $GoeData/general_log.data generated by $0 on $Date
LogTitle=\"\$T_Server_log :<br/>------------------------------------------<br/>\"
LogTail=\`tail -n $GeneralLogTailLength $XoeLog | tac | sed 's/\"/:/g' | sed 's/\\\`/:/g' | sed 's/.*/& <br\/>/'\`
LogDetail=\`tail -n $GeneralLogDetailLength $XoeLog | tac | sed 's/\"/:/g' | sed 's/\\\`/:/g' | sed 's/ERROR/<big><strong><font color=#7e0021>ERROR<\/font><\/strong><\/big>/g' | sed 's/WARNG/<font color=#cc6633>WARNG<\/font>/g'  | sed 's/WARNING/<font color=#cc6633>WARNING<\/font>/g' | sed 's/.*/& <br\/>/'\`
if echo \"\$LogDetail\" | grep -qi \"Traceback\|ERROR$\" ; then
	LogTailStatus=\"fault\"
else
	if echo \"\$LogDetail\" | grep -qi \"WARNING\" ; then
		LogTailStatus=\"warning\"
	else
		LogTailStatus=\"ok\"
	fi
fi
" > general_log.data.draft
		UPDATE_DATA_FILE general_log.data l
		;;
	esac
	;;
esac
LOG_MESSAGE $LINENO COLLECT_DATA $collect_function collect done on `date +'%Hh%Mm%Ss:%3N'`
}
#end 
#------------------------------------------------------------------------------
#--collect suite et fin
	LOG_MESSAGE $LINENO -g "execution collect $* data for all services"
	echo -n "collect `date +'%Hh%Mm%Ss:%3N'` ...." >> $GoeDataLog
	LOG_MESSAGE $LINENO "New data to be collected -----------begin"
	XoeConf=`cat $XoeDir/xoe.conf/xoe.services.conf | grep -v "^#"`
	AllDatabaseList=`psql -l`
	if [ ! -f $GoePagesList ] ; then
		echo "" >> $GoePagesList
	fi
	PageList=`tail -n $PageRefresh $GoePagesList | sort -u | xargs`
	#PageList=`cat $GoePagesList | xargs`
	#LOG_MESSAGE $LINENO collect PageList $PageList
	case "$Service" in
	All)
		Service=""
		CollectMode="All"
		COLLECT_DATA $LINENO contract
		COLLECT_DATA $LINENO admin_guide
		COLLECT_DATA $LINENO openservice
		COLLECT_DATA $LINENO closeservice
		COLLECT_DATA $LINENO system
		COLLECT_DATA $LINENO mooc
		COLLECT_DATA $LINENO general_log
		;;
	*)
		CollectMode=""
		;;
	esac
	if [ -z "$Service" ] ; then
		COLLECT_DATA $LINENO page
	else
		ServiceList="$Service"
	fi	
	LOG_MESSAGE $LINENO collect ServiceList $ServiceList
	for Service in $ServiceList ; do
		COLLECT_DATA $LINENO menu $Service
		case "$CollectMode:$ServiceDetailsMode:$PageList" in
		*$Service*|*:show:*page*|All:*)
#		*$Service*)
			LOG_MESSAGE $LINENO --collect Service $Service
			COLLECT_DATA $LINENO service $Service
			LOG_MESSAGE $LINENO collect for $Service DatabaseList $DatabaseList
			for Database in $DatabaseList ; do
				LOG_MESSAGE $LINENO --collect Service $Service Database $Database
				COLLECT_DATA $LINENO database $Service $Database
			done
			;;
		esac
	done
	LOG_MESSAGE $LINENO "Last data collected -----------end"
	echo ".... `date +'%Hh%Mm%Ss:%3N'`" >> $GoeDataLog
	;;
#------------------------------------------------------------------------------
--template)

#------------------------------------------------------------------------------
TEMPLATE_ACTION ()
#------------------------------------------------------------------------------
{
LOG_MESSAGE $LINENO -g TEMPLATE_ACTION $* Mode $ServerMode
#TR T_Parameters_are_NOT_valid Sorry, your request cannot be processed. Return code is : Desole, le serveur refuse cette demande d'operation. Sa reponse est
#TR T_Technical_request For your information, the sent request is the following : Pour information, la requete emise est la suivante
#TR T_Acting Previous actiion did not complete yet : Une action precedente est encore en cours d'execution
#TR T_Language	/usr/local/etc/goe/goe.translation.en : /usr/local/etc/goe/goe.translation.fr
#TR T_submitted Action is submitted to server : L action est transmise au serveur
#TR T_completed	Action completed on server : L action a ete executee par le serveur
action_type="$1"
GetValues="#! /bin/bash
# generated by $0 on $Date mode $ServerMode
#-----------------
ACTION_GET_DATA ()
#-----------------
{
cat $XoeServicesData | grep \"^#Service:\$Service:\" | cut -f2- > /tmp/goe.get_xoe_data.\$Service.action.\$\$.sh
. /tmp/goe.get_xoe_data.\$Service.action.\$\$.sh
rm -f /tmp/goe.get_xoe_data.\$Service.action.\$\$.sh
}
#-----------------
ACTION_GET_LANGUAGE ()
#-----------------
{
language=\"\$ServiceLanguage\"
if [ -z \"\$language\" ] ; then
	language=\"en\"
fi
. $GoeTranslationFile.\$language
if [ -e $GoeCustomTranslationFile.\$language ] ; then
	. $GoeCustomTranslationFile.\$language
fi
}
#--------------------
ACTION_MESSAGE ()
#--------------------
{
case \"\$action\" in
--check)
	am_status=\"$T_submitted\"
	;;
--execute)
	am_status=\"$T_completed\"
	;;
esac
case \"\$1\" in
-a)
	shift
	echo \"\`date\`| \$* : \$am_status\" >> $GoeActionsLog
	;;
-e)
	shift
	echo \"ACTION \$LINENO|Error|\`date\`|\$0| \$*\" >> $GoeLog
	echo \"ACTION \$LINENO|Error|\`date\`|\$0| \$*\" >> $XoeLog
	;;
*)
	echo \"ACTION \$LINENO|Messg|\`date\`|\$0| \$*\" >> $GoeLog
	echo \"ACTION \$LINENO|Messg|\`date\`|\$0| \$*\" >> $XoeLog
	;;
esac
}
#--------------------
ACTION_GET_VALUE ()
#--------------------
{
if [ ! -z \"\$1\" ] ; then
	case \"\$1\" in
	*=*)
		echo \"\$*\" | cut -d= -f2
		 ;;
	*)
		echo \"\$*\"
		;;
	esac
fi
}
#--------------------
ACTION_CHECK ()
#--------------------
{
if [ -z \"\$2\" ] ; then
	ACTION_MESSAGE -e \"\$T_Parameters_are_NOT_valid $action_type : Uncorrect or missing \$1 parameter\"
	echo \"401: Action linked to button $action_type, action \$action mode \$mode : Uncorrect or missing \$1 parameter \$0 \$parameters\"
	echo \"....\"
	exit 4
else
	ACTION_MESSAGE  \"Wonderful parameter \$*\"
fi
}
#--------------------
ACTING ()
#--------------------
{
pending_action=\"\$*\"
for ((ia=1;ia<25;ia=ia+1)) ; do
	if [ -f $GoeActingFlag.\$service.flag ] ; then
		on_going_action=\`cat $GoeActingFlag.\$service.flag\`
		case \"\$pending_action\" in
		\$on_going_action)
			#repeated action
			ACTION_MESSAGE  \"repeated action \$pending_action is cancelled\"
			echo \"repeated action \$pending_action is cancelled\" >> $GoeLogDir/acting.\$service.flag.log
			break
			;;
		*)
			#overlapping actions
			ACTION_MESSAGE  \"action \$pending_action is postponed because \$on_going_action is still processing\"
			echo \"action \$pending_action is postponed because \$on_going_action is still processing\" >> $GoeLogDir/acting.\$service.flag.log
			;;
		esac
	else
		echo \"\$pending_action\" > $GoeActingFlag.\$service.flag
		echo \"Starting \$pending_action\" >> $GoeLogDir/acting.\$service.flag.log
		ACTION_MESSAGE  \"Starting \$pending_action\"
		\$pending_action
		rm -f $GoeActingFlag.\$service.flag
		echo \"Completed \$pending_action\" >> $GoeLogDir/acting.\$service.flag.log
		ACTION_MESSAGE  \"Completed \$pending_action\"
		break
	fi
sleep 1
#sleep $i
done
}
#--------------------
ACTION_EXECUTE ()
#--------------------
{
case \"\$action\" in
--check)
	case \"\$mode\" in
	demo*)
		echo \"Simulation of action linked to button \$action_type : \$T_Parameters_are_valid<br/> \$0 \$*\"
		ACTION_MESSAGE \"Info : \`date\` OK : Parameters are valid for Simulation of action $action_type : \$0 \$*\"
		;;
	*)
		echo \"<br/><small>\$T_Technical_request :<br/> \$0 \$*</small>\"
		ACTION_MESSAGE \"Info : \`date\` OK : Parameters are valid for Action $action_type : \$0 \$*\"
		;;
	esac
	;;
--execute)
	case \"\$mode\" in
	demo*)
		ACTION_MESSAGE \"Info : \`date\` Simulate Action $action_type : \$0 \$*\"
		;;
	*)
		ACTION_MESSAGE \"Info : \`date\` Execute Action $action_type : \$0 \$*\"
		ACTING \$*
		;;
	esac
	;;
esac
}
#--------------------
parameters=\"\$*\"
ACTION_MESSAGE ==========Action \$0 call parameters \$*
action=\"\$1\"
shift
#--------------------
mode=\"\$1\"
shift
#--------------------
service=\`ACTION_GET_VALUE \$1\`
shift
#--------------------
actingsignal=\`ACTION_GET_VALUE \$1\`
database=\`ACTION_GET_VALUE \$1\`
dropprefix=\`ACTION_GET_VALUE \$*\`
mooc_name=\`ACTION_GET_VALUE \$1\`
modelversion=\`ACTION_GET_VALUE \$1\`
archive_name=\`ACTION_GET_VALUE \$1\`
menu_name=\`ACTION_GET_VALUE \$1\`
month=\`ACTION_GET_VALUE \$1\`
shift
#--------------------
archive=\`ACTION_GET_VALUE \$1\`
mooc_action=\`ACTION_GET_VALUE \$1\`
exam_action=\`ACTION_GET_VALUE \$1\`
archive_action=\`ACTION_GET_VALUE \$1\`
admin_password=\`ACTION_GET_VALUE \$2\`
cloneprefix=\`ACTION_GET_VALUE \$*\`
copyservice=\`ACTION_GET_VALUE \$1\`
copyprefix=\`ACTION_GET_VALUE \$2\`
mooc_min=\`ACTION_GET_VALUE \$2\`
mooc_max=\`ACTION_GET_VALUE \$3\`
mooc_mail=\`ACTION_GET_VALUE \$4\`
exam_login=\`ACTION_GET_VALUE \$2\`
exam_password=\`ACTION_GET_VALUE \$3\`
menu_content=\`ACTION_GET_VALUE \$*\`
period=\`ACTION_GET_VALUE \$1\`
shift
#--------------------
company=\`ACTION_GET_VALUE \$*\`
#--------------------
ACTION_GET_DATA
ACTION_GET_LANGUAGE
"

case "$action_type" in
#------------
#Service Actions
#------------
button_editservicemenu)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
ACTION_CHECK menu_name \$menu_name
ACTION_CHECK menu_content \$menu_content
ACTION_EXECUTE sudo /usr/local/bin/xoe --config -set -panel \$menu_name \$service editservicemenu \$menu_content
#ACTION_EXECUTE sudo /usr/local/bin/goe --get_service_data
ACTION_MESSAGE -a Action:\$service: $T_Service_menu_action \$service: \$menu_content
exit 0" > $Actions.draft/$action_type.action
	;;
button_renew)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
ACTION_EXECUTE sudo /usr/local/bin/xoe log -last -set \$service today
#ACTION_EXECUTE sudo /usr/local/bin/goe --get_service_data
ACTION_MESSAGE -a Action:\$service: $T_Renew_service
exit 0" > $Actions.draft/$action_type.action
	;;
button_start)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
ACTION_EXECUTE sudo /usr/local/bin/xoe contract -set -situation \$service napping
ACTION_EXECUTE sudo /usr/local/bin/xoe start -force \$service
ACTION_EXECUTE sudo /usr/local/bin/xoe config -set -auto \$service
#ACTION_EXECUTE sudo /usr/local/bin/goe --get_service_data
ACTION_MESSAGE -a Action:\$service: $T_Start_service
exit 0" > $Actions.draft/$action_type.action
	;;
button_stop)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
ACTION_EXECUTE sudo /usr/local/bin/xoe config -set -manual \$service
ACTION_EXECUTE sudo /usr/local/bin/xoe stop \$service
#ACTION_EXECUTE sudo /usr/local/bin/goe --get_service_data
ACTION_MESSAGE -a Action:\$service: $T_Stop_service
exit 0" > $Actions.draft/$action_type.action
	;;
button_restart)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
ACTION_EXECUTE sudo /usr/local/bin/xoe restart \$service
#ACTION_EXECUTE sudo /usr/local/bin/goe --get_service_data
ACTION_MESSAGE -a Action:\$service: $T_Restart_service
exit 0" > $Actions.draft/$action_type.action
	;;
button_newcase)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK database \$database
	ACTION_CHECK archive \$archive
	ACTION_CHECK admin_password \$admin_password
	ACTION_EXECUTE sudo /usr/local/bin/xoe database -restore -force \$service \$database \$archive
	ACTION_EXECUTE sudo /usr/local/bin/xoe database -admin_password \$service \$database \$admin_password
	ACTION_MESSAGE -a Action:\$service: $T_Use_a_case \$database \$archive
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_company_script)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
ACTION_CHECK company \"\$company\"
ACTION_CHECK month \$month
ACTION_CHECK period \$period
echo \"sudo /usr/local/bin/xoe database -script \$service $WelcomeDatabaseScript \$month \$period \$company \" >> /tmp/button_company.log
ACTION_EXECUTE sudo /usr/local/bin/xoe database -script \$service $WelcomeDatabaseScript \$month \$period \"\$company\"
ACTION_MESSAGE -a Action:\$service: $T_Set_a_company \"\$company\"
exit 0" > $Actions.draft/$action_type.action
	;;
button_company)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
ACTION_CHECK company \"\$company\"
ACTION_CHECK month \$month
ACTION_CHECK period \$period

	PROFILE ()
	{
	variable=\"\$1\"
	shift
	ACTION_EXECUTE echo \"#profile:	\$variable=\\\"\$*\"\\\"		>>	/tmp/goe.profile.\$service.\$\$.data
	}
	ACTION_EXECUTE echo \"#sudo /usr/local/bin/xoe database -script \$service $WelcomeDatabaseScript \$month \$period \$company \" > /tmp/goe.profile.\$service.\$\$.data
	PROFILE Country fr
	PROFILE Language fr
	PROFILE ScriptParameters \$month \$period \$company
	PROFILE FirstMonth \$month
	PROFILE Period \$period
	PROFILE MyCompany \$company
	ACTION_EXECUTE sudo /usr/local/bin/xoe database -profile \$service $WelcomeDatabaseScript /tmp/goe.profile.\$service.\$\$.data
echo \"sudo /usr/local/bin/xoe database -profile \$service $WelcomeDatabaseScript /tmp/goe.profile.\$service.\$\$.data \" >> /tmp/button_company.log


#echo \"sudo /usr/local/bin/xoe database -script \$service $WelcomeDatabaseScript \$month \$period \$company \" >> /tmp/button_company.log
ACTION_MESSAGE -a Action:\$service: $T_Set_a_company \"\$company\"
#rm -f /tmp/goe.profile.\$service.\$\$.data
exit 0" > $Actions.draft/$action_type.action
	;;
button_newmooc)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK mooc_name \$mooc_name
	ACTION_CHECK archive \$archive
	ACTION_CHECK mooc_min \$mooc_min
	ACTION_CHECK mooc_max \$mooc_max
	ACTION_CHECK mooc_mail \$mooc_mail
	ACTION_EXECUTE sudo /usr/local/bin/mooc --create \$service \$mooc_name \$archive \$mooc_min \$mooc_max \$mooc_mail
	ACTION_MESSAGE -a Action:\$service: $T_New_Mooc_doc \$mooc_name \$archive \$mooc_min \$mooc_max \$mooc_mail
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_managemooc)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK mooc_name \$mooc_name
	ACTION_CHECK mooc_action \$mooc_action
	ACTION_EXECUTE sudo /usr/local/bin/mooc \$mooc_action \$service \$mooc_name
	ACTION_MESSAGE -a Action:\$service: $T_Manage_Mooc_doc \$mooc_name: \$mooc_action
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_exam)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK mooc_name \$mooc_name
	ACTION_CHECK exam_action \$exam_action
	ACTION_CHECK exam_login \$exam_login
	ACTION_CHECK exam_password \$exam_password
	ACTION_EXECUTE sudo /usr/local/bin/mooc \$exam_action \$service \$mooc_name \$exam_login \$exam_password
	ACTION_MESSAGE -a Action:\$service: $T_Exam_doc \$mooc_name \$exam_action
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_upload)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	#add new archives to service and filter names with spaces
	ACTION_MESSAGE \"U ACTION_EXECUTE sudo /usr/local/bin/goe --shell_move $GoeUploads/\$service $XoeDir/xoe.services/\$service/custom\"
	ACTION_EXECUTE sudo /usr/local/bin/goe --shell_move $GoeUploads/\$service $XoeDir/xoe.services/\$service/custom
	ACTION_MESSAGE -a Action:\$service: $T_Upload_doc
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_installarchive)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK archive_name \$archive_name
	ACTION_CHECK archive_action \$archive_action
	case \"\$archive_action\" in
	--remove)
		ACTION_MESSAGE \"A action \$action mode \$mode service \$service archive_name \$archive_name archive_action \$archive_action \$service ACTION_EXECUTE sudo /usr/local/bin/goe --shell rm \$archive_name\"
		ACTION_EXECUTE sudo /usr/local/bin/goe --shell rm \$archive_name
		ACTION_MESSAGE -a Action:\$service: $T_Installarchive_doc \$service REMOVE \$archive_name
		;;
	--directory)
		ACTION_MESSAGE \"B ACTION_EXECUTE sudo /usr/local/bin/xoe \$archive_action -add-archive \$service \$archive_name\"
		ACTION_EXECUTE sudo /usr/local/bin/xoe \$archive_action -add-archive \$service \$archive_name
		ACTION_MESSAGE -a Action:\$service: $T_Installarchive_doc IMPLEMENT \$archive_name
		;;
	esac
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_upgrade)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK modelversion \$modelversion
	ACTION_EXECUTE sudo /usr/local/bin/xoe config -set -manual \$service
	ACTION_EXECUTE sudo /usr/local/bin/xoe contract -upgrade \$service \$modelversion
	ACTION_EXECUTE sudo /usr/local/bin/xoe config -set -auto \$service
	ACTION_MESSAGE -a Action:\$service: $T_Upgrade_doc \$modelversion
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_downgrade)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_EXECUTE sudo /usr/local/bin/xoe directory -downgrade \$service
	ACTION_MESSAGE -a Action:\$service: $T_Downgrade_doc
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_drop)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK dropprefix \$dropprefix
	ACTION_EXECUTE sudo /usr/local/bin/xoe database -drop -prefix \$service \$dropprefix
	ACTION_MESSAGE -a Action:\$service: $T_Drop_doc \$dropprefix
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;

#-------------
#Database Actions
#-------------
button_editdatabasemenu)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
ACTION_CHECK menu_name \$menu_name
ACTION_CHECK menu_content \$menu_content
ACTION_EXECUTE sudo /usr/local/bin/xoe --config -set -panel \$menu_name \$service editdatabasemenu \$menu_content
#ACTION_EXECUTE sudo /usr/local/bin/goe --get_service_data
ACTION_MESSAGE -a Action:\$service: $T_Database_menu_action \$service: \$menu_content
exit 0" > $Actions.draft/$action_type.action
	;;
button_save)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
ACTION_CHECK database \$database
ACTION_EXECUTE sudo /usr/local/bin/xoe database -save -now \$service \$database
ACTION_MESSAGE -a Action:\$service:\$database: $T_Save_database
exit 0" > $Actions.draft/$action_type.action
	;;
button_snapshot)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
ACTION_CHECK database \$database
ACTION_EXECUTE sudo /usr/local/bin/xoe config -snapshot -on \$service \$database
ACTION_MESSAGE -a Action:\$service:\$database: $T_Snapshot_database
exit 0" > $Actions.draft/$action_type.action
	;;
button_restore)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK database \$database
	ACTION_CHECK archive \$archive
	ACTION_EXECUTE sudo /usr/local/bin/xoe database -restore -force \$service \$database \$archive
	ACTION_MESSAGE -a Action:\$service:\$database: $T_Restore_database \$database \$archive
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_clone)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK database \$database
	ACTION_CHECK cloneprefix \$cloneprefix
	ACTION_EXECUTE sudo /usr/local/bin/xoe database -clone \$service \$database \$cloneprefix
	ACTION_MESSAGE -a Action:\$service:\$database: $T_Clone_database \$cloneprefix
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_copy)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK database \$database
	ACTION_CHECK copyservice \$copyservice
	ACTION_CHECK copyprefix \$copyprefix
	ACTION_EXECUTE sudo /usr/local/bin/xoe database -copy -force \$service \$database \$copyservice \$copyprefix
	ACTION_MESSAGE -a Action:\$service:\$database: $T_Copy_database \$copyservice \$copyprefix
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_reference)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK database \$database
	ACTION_EXECUTE sudo  /usr/local/bin/xoe database -set -reference \$service \$database
	ACTION_MESSAGE -a Action:\$service:\$database: $T_Reference_database $T_on_service \$service
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_delete)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK database \$database
	ACTION_EXECUTE sudo  /usr/local/bin/xoe database -drop -db \$service \$database
	ACTION_MESSAGE -a Action:\$service:\$database: $T_Delete_database
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_wipe_out)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK database \$database
	ACTION_EXECUTE sudo  /usr/local/bin/xoe database -archive -wipe-out \$service \$database
	ACTION_MESSAGE -a Action:\$service:\$database: $T_Delete_archives_of_database
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
button_dbupdate)
	echo "$GetValues
ACTION_CHECK action \$action
ACTION_CHECK mode \$mode
ACTION_CHECK service \$service
case \"\$actingsignal\" in
clear)
	ACTION_EXECUTE sudo rm -f $GoeActingFlag.\$service.flag
	;;
wait)
	;;
*)
	ACTION_CHECK database \$database
	ACTION_EXECUTE sudo  /usr/local/bin/xoe database -update \$service \$database
	ACTION_MESSAGE -a Action:\$service:\$database: $T_Update_database
	;;
esac
exit 0" > $Actions.draft/$action_type.action
	;;
*)
	LOG_MESSAGE $LINENO -g TEMPLATE_ACTION $* Mode $ServerMode ERROR
	;;
esac
chmod 600 $Actions.draft/$action_type.action
}
#end 
#------------------------------------------------------------------------------
TEMPLATE_BUTTON_RESULT ()
#------------------------------------------------------------------------------
{
#LOG_MESSAGE $LINENO -g TEMPLATE_BUTTON_RESULT $*
#TR T_Action_Report_Message Action Report Message : Compte-rendu de l'action
#TR T_Action_return_message Your request is now processing : Votre requete a ete transmise au serveur
#TR T_Parameters_are_valid Thank you for your patience until action menu above is refreshed : Merci de patienter jusqu au reaffichage du menu ci dessus
#TR T_menu_lock_released or lock on menu has been released : ou le blocage des menu a ete leve
button_type="$1"
result_template="$2"
case "$button_type" in
#------------
#Service Results
#------------
button_editservicemenu|button_renew|button_start|button_stop|button_restart|button_newcase|button_company|button_drop|button_newmooc|button_managemooc|button_exam|button_upload|button_installarchive|button_upgrade|button_downgrade)

	ResultGenerics="
#-----------------
SERVICE_RESULT_GET_DATA ()
#-----------------
{
cat $XoeServicesData | grep \"^#Service:\$Service:\" | cut -f2- | grep \"^ServiceLanguage=\"\ > /tmp/goe.get_xoe_data.\$Service.result.\$\$.sh
. /tmp/goe.get_xoe_data.\$Service.result.\$\$.sh
rm -f /tmp/goe.get_xoe_data.\$Service.result.\$\$.sh
}
#-----------------
SERVICE_RESULT_GET_LANGUAGE ()
#-----------------
{
language=\"\$ServiceLanguage\"
if [ -z \"\$language\" ] ; then
	language=\"en\"
fi
. $GoeTranslationFile.\$language
if [ -e $GoeCustomTranslationFile.\$language ] ; then
	. $GoeCustomTranslationFile.\$language
fi
}
#-----------------
SERVICE_RESULT_CAT ()
#-----------------
{
for ((ic=0;ic<50;ic=ic+1)) ; do
	if cat \$1 ; then
		break
	fi
	sleep 0.1
done
}
#-----------------
SERVICE_RESULT_GENERICS ()
#-----------------
{
echo \"
<zone name=\\\"zone.\$Service.${button_type}_result\\\">
	<zone_refresh><![CDATA[<meta http-equiv=\\\"Refresh\\\" content=\\\"$SiteRefreshResult; url=../index.php?action=--page zone.\$Service.map \$Service.detail.draw\\\" />]]></zone_refresh>
	<zone_title><![CDATA[<title>\$*</title>]]></zone_title>
	<zone_type>button_result</zone_type>
	<zone_status>ok</zone_status>
	<zone_html><![CDATA[ \$T_Action_Report_Message<br/>\$T_Action_return_message : \$T_Parameters_are_valid <br/>\$*<br/>\$ActionMessage<br/> ]]></zone_html>\"
}
#-----------------"
	ResultTop="SERVICE_RESULT_TOP_WINDOW ()
#-----------------
{
echo \"<!-- this template generated by $0 on $Date mode $ServerMode -->\"
SERVICE_RESULT_CAT $Drawings/\$Service.menu.draw | sed s:'<zone_status>ok</zone_status>':'<zone_status>unknown</zone_status>':
echo \"<hr/>\"
}
#-----------------"
	ResultBottom="SERVICE_RESULT_BOTTOM ()
#-----------------
{
echo \"<!-- end zone.\$Service.${button_type}_result --> </zone>\"
SERVICE_RESULT_CAT $Drawings/\$Service.info.draw
echo \" <!-- addendum Result -->\"
}
#-----------------
SERVICE_RESULT_GET_DATA
SERVICE_RESULT_GET_LANGUAGE
#-----------------"
	#TR T_Service Service : Le service
	case "$button_type" in
	button_editservicemenu)
		#TR T_Set_service_menu_result Operation is being processed on service : L'operation demandee est en cours sur le service
		ResultTitle="\$T_Set_service_menu_result \$Service"
		;;
	button_renew)
		#TR T_is_renewed_result is renewed for a contractual period : est reconduit pour sa duree contractuelle
		ResultTitle="\$T_Service \$Service \$T_is_renewed_result"
		;;
	button_start)
		#TR T_is_started_result is started : est demarre
		ResultTitle="\$T_Service \$Service \$T_is_started_result"
		;;
	button_stop)
		#TR T_is_stopped_result is stopped : est arrete
		ResultTitle="\$T_Service \$Service \$T_is_stopped_result"
		;;
	button_restart)
		#TR T_is_restarted_result is restarted : est redemarre
		ResultTitle="\$T_Service \$Service \$T_is_restarted_result"
		;;
	button_newcase)
		#TR T_A_new_case_result A new case : Un nouveau cas
		#TR T_is_created_result is created : est cree
		ResultTitle="\$T_A_new_case_result \$T_on_service \$Service \$T_is_created_result \$T_menu_lock_released"
		;;
	button_company)
		#TR T_A_new_company_result A new company profile : Un nouveau profil de societe
		ResultTitle="\$T_A_new_company_result \$T_on_service \$Service \$T_is_created_result"
		;;
	button_drop)
		#TR T_Dropped_result Specified databases are dropped on service : Les bases de donneees specifiees sont supprimees sur le service
		ResultTitle="\$T_Dropped_result \$Service"
		;;
	button_newmooc)
		#TR T_A_new_moo_result A new mooc : Le nouveau cours
		ResultTitle="\$T_A_new_mooc_result \$MoocName \$T_on_service \$Service \$T_is_created_result \$T_menu_lock_released"
		;;
	button_managemooc)
		#TR T_Manage_mooc_result Operation is being processed on service : L'operation demandee est en cours sur le service
		ResultTitle="\$T_Manage_mooc_result \$Service \$T_menu_lock_released"
		;;
	button_exam)
		#TR T_Exam_result Operation is being processed on service : L'operation demandee est en cours sur le service
		ResultTitle="\$T_Exam_result \$Service \$T_menu_lock_released"
		;;
	button_upload)
		#TR T_archive_uploaded_result archive uploaded to : archive telechargee sur le
		ResultTitle="\$T_archive_uploaded_result \$T_Service \$Service  \$T_menu_lock_released"
		;;
	button_installarchive)
		#TR T_archive_operation_result Operation is being processed on service : L'operation demandee est en cours sur le service
		ResultTitle="\$T_Archive_operation_result \$Service \$T_menu_lock_released"
		;;
	button_upgrade)
		#TR T_upgraded_to_new_version_result upgraded to a new version : monte vers une nouvelle version
		ResultTitle="\$T_Service \$Service \$T_is \$T_upgraded_to_new_version_result \$T_menu_lock_released"
		;;
	button_downgrade)
		#TR T_reverted_back_to_previous_version_result reverted back to previous version : a ete retabli dans sa version precedente
		ResultTitle="\$T_Service \$Service \$T_reverted_back_to_previous_version_result \$T_menu_lock_released"
		;;
	esac
	echo "#! /bin/bash
$ResultGenerics
$ResultTop
$ResultBottom
SERVICE_RESULT_TOP_WINDOW
SERVICE_RESULT_GENERICS \"$ResultTitle\"
SERVICE_RESULT_BOTTOM
" > $Results.draft/$result_template
	;;
#-------------
#Database Results
#-------------
button_editdatabasemenu|button_save|button_snapshot|button_restore|button_clone|button_copy|button_reference|button_delete|button_wipe_out|button_dbupdate)
	ResultGenerics="
#-----------------
DATABASE_RESULT_GET_DATA ()
#-----------------
{
cat $XoeServicesData | grep \"^#Service:\$Service:\" | cut -f2- | grep \"^ServiceLanguage=\"\ > /tmp/goe.get_xoe_data.\$Service.db_result.\$\$.sh
. /tmp/goe.get_xoe_data.\$Service.db_result.\$\$.sh
rm -f /tmp/goe.get_xoe_data.\$Service.db_result.\$\$.sh

}
#-----------------
DATABASE_RESULT_GET_LANGUAGE ()
#-----------------
{
language=\"\$ServiceLanguage\"
if [ -z \"\$language\" ] ; then
	language=\"en\"
fi
. $GoeTranslationFile.\$language
if [ -e $GoeCustomTranslationFile.\$language ] ; then
	. $GoeCustomTranslationFile.\$language
fi
}
#-----------------
DATABASE_RESULT_CAT ()
#-----------------
{
for ((ib=0;ib<50;ib=ib+1)) ; do
	if cat \$1 ; then
		break
	fi
	sleep 0.1
done
}
#-----------------
DATABASE_RESULT_GENERICS ()
#-----------------
{
echo \"
<zone name=\\\"zone.\$Service.\$Database.${button_type}_result\\\">
	<zone_refresh><![CDATA[<meta http-equiv=\\\"Refresh\\\" content=\\\"$SiteRefreshResult; url=../index.php?action=--page zone.\$Service.\$Database.map \$Service.\$Database.detail.draw\\\" />]]></zone_refresh>
	<zone_title><![CDATA[<title>\$1</title>]]></zone_title>
	<zone_type>button_result</zone_type>
	<zone_status>ok</zone_status>
	<zone_html><![CDATA[ \$T_Action_Report_Message<br/>\$T_Action_return_message : \$T_Parameters_are_valid <br/>\$*<br/>\$ActionMessage<br/> ]]></zone_html>\"
}
#-----------------"
	ResultTop="DATABASE_RESULT_TOP_WINDOW ()
#-----------------
{
echo \"<!-- this template generated by $0 on $Date mode $ServerMode -->\"
DATABASE_RESULT_CAT $Drawings/\$Service.\$Database.menu.draw | sed s:'<zone_status>ok</zone_status>':'<zone_status>unknown</zone_status>':
}
#-----------------"
	ResultBottom="DATABASE_RESULT_BOTTOM ()
#-----------------
{
echo \"<!-- end zone.\$Service.\$CommentDatabase.${button_type}_result --> </zone>\"
DATABASE_RESULT_CAT $Drawings/\$Service.\$Database.info.draw
echo \"<!-- addendum Result -->\"
}
#-----------------
DATABASE_RESULT_GET_DATA
DATABASE_RESULT_GET_LANGUAGE
#-----------------"
	#TR T_Database		Database : La base de donnees
	#TR T_on_service	on service : du service
	#TR T_of_database	of database : de la base de donnees
	case "$button_type" in
	button_editdatabasemenu)
		#TR T_Set_database_menu Operation is being processed on service : L'operation demandee est en cours sur le service
		ResultTitle="\$T_Set_database_menu \$Service"
		;;
	button_save)
		#TR T_is_saved		is saved : est sauvegardee
		ResultTitle="\$T_Database \$Database \$T_on_service \$Service \$T_is_saved \$T_menu_lock_released"
		;;
	button_snapshot)
		#TR T_is_auto_saved	is periodically saved : est temporairement sauvegardee periodiquement
		ResultTitle="\$T_Database \$Database \$T_on_service \$Service \$T_is_auto_saved \$T_menu_lock_released"
		;;
	button_restore)
		#TR T_Archive		Archive : La sauvegarde
		#TR T_is_restored	is restored : est restauree
		ResultTitle="\$T_Archive \$T_of_database \$Database \$T_on_service \$Service \$T_is_restored \$T_menu_lock_released"
		;;
	button_clone)
		#TR T_is_cloned		is cloned : est clonee
		ResultTitle="\$T_Database \$Database \$T_on_service \$Service \$T_is_cloned \$T_menu_lock_released"
		;;
	button_copy)
		#TR T_is_copied		is copied : est copiee
		ResultTitle="\$T_Database \$Database \$T_on_service \$Service \$T_is_copied \$T_menu_lock_released"
		;;
	button_reference)
		#TR T_is_referenced	is set as reference case : est referencee parmi les cas
		ResultTitle="\$T_Database \$Database \$T_on_service \$Service \$T_is_referenced \$T_menu_lock_released"
		;;
	button_delete)
		#TR T_is_cancelled	is cancelled : est supprimee
		ResultTitle="\$T_Database \$Database \$T_on_service \$Service \$T_is_cancelled \$T_menu_lock_released"
		;;
	button_wipe_out)
		#TR T_All_archives	All archives : Toutes les sauvegardes
		#TR T_are_removed	are removed : sont effacees
		ResultTitle="\$T_All_archives \$T_of_database \$Database \$T_on_service \$Service \$T_are_removed \$T_menu_lock_released"
		;;
	button_dbupdate)
		#TR T_is_updated	is updated : est mise a jour
		ResultTitle="\$T_Database \$Database \$T_on_service \$Service \$T_is_updated \$T_menu_lock_released"
		;;
	esac
	echo "#! /bin/bash
$ResultGenerics
$ResultTop
$ResultBottom
DATABASE_RESULT_TOP_WINDOW
DATABASE_RESULT_GENERICS \"$ResultTitle\"
DATABASE_RESULT_BOTTOM
" > $Results.draft/$result_template
	;;
*)
	LOG_MESSAGE $LINENO -g TEMPLATE_BUTTON_RESULT $* ERROR
	;;
esac
chmod 600 $Results.draft/$result_template
}
#end 
#------------------------------------------------------------------------------
TEMPLATE_BUTTON_FORM ()
#------------------------------------------------------------------------------
{
#LOG_MESSAGE $LINENO -g TEMPLATE_BUTTON_FORM $*
# GET_DATA $LINENO service and eventually GET_DATA $LINENO database is already executed, so all variables are available
		#TR T_Processing	A previous action is still processing or never ended and blocks button : Une precedente action est encore en cours ou ne s est jamais terminee et bloque le bouton

		#TR T_Clear_acting_signal	A processing operation blocks the menu : Une operation inachevee bloque le menu
		#TR T_Acting_wait	Wait until processing action ends : Attendre la fin de l operation en cours
		#TR T_Acting_clear	Unlock menus : Debloquer les menus
		#TR T_Superceed_acting_signal	Concurrent operations on a database may fail : Des operations simultanees sur une base de donnees peuvent echouer
button_type="$1"
form_template="$2"
#pre-created sections of code
case "$button_type" in
#------------
#Service Forms
#------------
#some buttons (start, stop etc..) don't need a form
button_editservicemenu|button_newcase|button_company|button_drop|button_newmooc|button_managemooc|button_exam|button_upload|button_installarchive|button_upgrade|button_downgrade)
	#new case is related to a service, not a database
	FormServiceGenerics="
#-----------------
SERVICE_GET_SERVICE_DATA ()
#-----------------
{
cat $XoeServicesData | grep \"^#Service:\$Service:\" | cut -f2-  > /tmp/goe.get_xoe_data.\$Sservice.form.\$\$.sh
. /tmp/goe.get_xoe_data.\$Sservice.form.\$\$.sh
rm -f /tmp/goe.get_xoe_data.\$Sservice.form.\$\$.sh
erpname=\"\$ServiceErpName\"
erpvariant=\"\$ServiceErpVariant\"
serviceversion=\"\$ServiceVersion\"
}
#-----------------
SERVICE_GET_SERVICE_LANGUAGE ()
#-----------------
{
language=\"\$ServiceLanguage\"
if [ -z \"\$language\" ] ; then
	language=\"en\"
fi
. $GoeTranslationFile.\$language
if [ -e $GoeCustomTranslationFile.\$language ] ; then
	. $GoeCustomTranslationFile.\$language
fi
}
#-----------------
SERVICE_CAT ()
#-----------------
{
for ((isc=0;isc<50;isc=isc+1)) ; do
	if cat \$1 ; then
		break
	fi
	sleep 0.1
done
}
#-----------------
SERVICE_FORM_TOP_WINDOW ()
#-----------------
{
echo \"<!-- this template generated by $0 on $Date mode $ServerMode -->\"
SERVICE_CAT $Drawings/\$Service.menu.draw
}
#-----------------
SERVICE_FORM_GENERICS ()
#-----------------
{
echo \"
<zone name=\\\"zone.\$Service..${button_type}_form\\\">
	<zone_refresh><![CDATA[<meta http-equiv=\\\"Refresh\\\" content=\\\"180; url=../index.php?action=--page zone.\$Service.map \$Service.detail.draw\\\" />]]></zone_refresh>
	<zone_title><![CDATA[<title>\$1</title>]]></zone_title>
	<zone_type>button_form</zone_type>
	<zone_status>ok</zone_status>
	<zone_on_validate>--on_click zone.\$Service..${button_type}_form \$Service..${button_type}.result \$Service..${button_type}.action</zone_on_validate>\"
}
#-----------------
SERVICE_FORM_BOTTOM ()
#-----------------
{
echo \"
<!-- end zone.\$Service.${button_type}.form --> </zone>
<!-- addendum form -->\"
SERVICE_CAT $Drawings/\$Service.info.draw
}
#-----------------
SERVICE_ON_ERROR ()
#-----------------
{
echo \"<!-- this template generated by $0 on $Date mode $ServerMode -->
<zone name=\\\"zone.\$Service.${button_type}_form\\\">
	<zone_refresh><![CDATA[<meta http-equiv=\\\"Refresh\\\" content=\\\"$SiteRefreshResult; url=../index.php?action=--page zone.\$Service.map \$Service.detail.draw\\\" />]]></zone_refresh>
	<zone_title><![CDATA[<title>\$FormTitle</title>]]></zone_title>
	<zone_window>zone-\$Service-detail</zone_window>
	<zone_type>button_form</zone_type>
	<zone_status>fault</zone_status>
	<zone_html><![CDATA[\$1]]></zone_html>\"
}
#-----------------
SERVICE_ON_BUZY ()
#-----------------
{
if [ ! -f $GoeActingFlag.\$Service.flag ] ; then
	Service0nBuzy=\"Available\"
else
	Service0nBuzy=\"Buzy\"
	FormTitle=\"\$T_Processing \$*...\"
	echo \"<!-- this template generated by $0 on $Date mode $ServerMode -->
<zone name=\\\"zone.\$Service.${button_type}.form\\\">
	<zone_refresh><![CDATA[<meta http-equiv=\\\"Refresh\\\" content=\\\"$SiteRefreshResult; url=../index.php?action=--page zone.\$Service.map \$Service.detail.draw\\\" />]]></zone_refresh>
	<zone_title><![CDATA[<title>\$FormTitle</title>]]></zone_title>
	<zone_window>zone-\$Service-detail</zone_window>
	<zone_type>button_form</zone_type>
	<zone_status>fault</zone_status>
	<zone_on_validate>--on_click zone.\$Service.${button_type}_form \$Service..${button_type}.result \$Service..${button_type}.action</zone_on_validate>
	<zone_form><![CDATA[\$FormTitle<br/>
\$T_Service : \$Service<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service actingsignal\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Clear_acting_signal :  </td><td><input type=\\\"radio\\\" name=\\\"actingsignal\\\" value=\\\"wait\\\" checked> \$T_Acting_wait</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"actingsignal\\\" value=\\\"clear\\\" > \$T_Acting_clear</td></tr>
</table>
\$T_Warning : \$T_Superceed_acting_signal.<br/> ]]></zone_form>\"

fi
}
#-----------------
SERVICE_GET_SERVICE_DATA
SERVICE_GET_SERVICE_LANGUAGE
#-----------------"
	FormServiceButtonDescription="SERVICE_GET_DESCRIPTION ()
#-----------------
{
#$ServiceButtonsFullList
Descriptions=\"
renew:	\$T_Renew_service \$Service
start:	\$T_Start_service \$Service
stop:	\$T_Stop_service \$Service
restart:	\$T_Restart_service \$Service
newcase:	\$T_Use_a_case \$Service
company:	\$T_Set_a_company \$Service
drop:	\$T_Drop_doc \$Service
newmooc:	\$T_New_Mooc_doc \$Service
managemooc:	\$T_Manage_Mooc_doc \$Service
exam:		\$T_Exam_doc \$Service
upload:	\$T_Upload_doc \$Service
installarchive:	\$T_Installarchive_doc \$Service
upgrade:	\$T_Upgrade_doc \$Service
downgrade:	\$T_Downgrade_doc \$Service
\"
button_name=\`echo \"\$Descriptions\" | grep \"^\$1:\" | cut -d: -f2-\`
}
#-----------------"
	FormGetReferences="SERVICE_GET_REFERENCES ()
#-----------------
{
case \"\$1\" in
--add)
	shift
	;;
*)
	optionarchive=\"\"
	optionlist=\"\"
	;;
esac
archivedir=\"\$1\"
if [ -d \"\$archivedir\" ] ; then
	ListArchives=\`ls \$archivedir | xargs\`
	for archive in \$ListArchives ; do
		case \"\$archive\" in
		*.gz|*.dump|*.backup|*.profile|*.script|*.sql)
			optionarchive=\"\$optionarchive<option value=\\\"\$archivedir/\$archive\\\">\$archive</option>\"
			optionlist=\"\$optionlist \$archive\"
			;;
		esac
	done
fi
}
#-----------------
SERVICE_GET_PROFILES ()
#-------------------
{
archivedir=\"\$1\"
if [ -d \"\$archivedir\" ] ; then
	ListArchives=\`ls \$archivedir | xargs\`
	echo \"<!--ListArchives \$ListArchives -->\"
	for archive in \$ListArchives ; do
		case \"\$archive\" in
		*.script|*.profile)
			optionarchive=\"\$optionarchive<option value=\\\"\$archivedir/\$archive\\\">\$archive</option>\"
			optionlist=\"\$optionlist \$archive\"
			;;
		esac
	done
fi
}
#-----------------"
	FormGetCustoms="SERVICE_GET_CUSTOMS ()
#-----------------
{
customdir=\"\$1\"
if [ -d \"\$customdir\" ] ; then
	echo \"<!--ListCustoms \$ListCustoms -->\"
	OptionCustoms=\"\"
	ListCustoms=\"\"
	custom_content=\`ls \$customdir\`
	for custom_archive in \$custom_content ; do
		case \"\$custom_archive\" in
		*.tar.gz|*.zip)
			OptionCustoms=\"\$OptionCustoms<option value=\\\"\$customdir/\$custom_archive\\\">\$custom_archive</option>\"
			ListCustoms=\"\$ListCustoms \$custom_archive\"
			;;
		esac
	done
	IFS=\"\$standard_IFS\"
fi
}
#-----------------"
	FormGetGradability="
if [ ! -e \"$XoeDir/xoe.services/\$Service/upgraded.txt\" ] ; then
	Downgradability=\"unknown\"
else
	Downgradability=\"ok\"
fi
optionmodelversion=\"\"
optionlist=\"\"
#if [ -e \"$XoeDir/xoe.services/\$Service/version/compatibility_\$Service.conf\" ] ; then
#	ServiceCompatibilityList=\`cat $XoeDir/xoe.services/\$Service/version/compatibility_\$Service.conf\`
#else
#	ServiceCompatibilityList=\`/usr/local/bin/xoe --contract -compatible \$Service\`
#fi
echo \"<!--ServiceCompatibilityList \$ServiceCompatibilityList -->\"
for modelversion in \$ServiceCompatibilityList ; do
		optionmodelversion=\"\$optionmodelversion<option value=\\\"\$modelversion\\\">\$modelversion</option>\"
		optionlist=\"\$optionlist \$modelversion\"
done
if [ -z \"\$ServiceCompatibilityList\" ] ; then
	Upgradability=\"unknown\"
#else
	#Upgradability=\"ok\"
fi
ServiceRole=\`/usr/local/bin/xoe --config -get -role \$Service | cut -f2\`
case \"\$ServiceRole\" in
production)
	Upgradability=\"protected\"
	;;
free*)
#	Upgradability=\"disallowed\"
	;;
esac"
	;;
#-------------
#Database Forms
#-------------
button_editdatabasemenu|button_restore|button_clone|button_copy|button_reference|button_delete|button_wipe_out|button_dbupdate)
	FormDbGenerics="
#-----------------
DATABASE_GET_SERVICE_DATA ()
#-----------------
{
cat $XoeServicesData | grep \"^#Service:\$Service:\" | cut -f2-  > /tmp/goe.get_xoe_data.database.\$Service.form.\$\$.sh
. /tmp/goe.get_xoe_data.database.\$Service.form.\$\$.sh
rm -f /tmp/goe.get_xoe_data.database.\$Service.form.\$\$.sh
erpname=\"\$ServiceErpName\"
erpvariant=\"\$ServiceErpVariant\"
}
#-----------------
DATABASE_GET_SERVICE_LANGUAGE ()
#-----------------
{
language=\"\$ServiceLanguage\"
if [ -z \"\$language\" ] ; then
	language=\"en\"
fi
. $GoeTranslationFile.\$language
if [ -e $GoeCustomTranslationFile.\$language ] ; then
	. $GoeCustomTranslationFile.\$language
fi
}
#-----------------
DATABASE_CAT ()
#-----------------
{
for ((idc=0;idc<50;idc=idc+1)) ; do
	if cat \$1 ; then
		break
	fi
	sleep 0.1
done
}
#-----------------
DATABASE_FORM_TOP_WINDOW ()
#-----------------
{
echo \"<!-- this template generated by $0 on $Date mode $ServerMode -->\"
DATABASE_CAT $Drawings/\$Service.\$Database.menu.draw
}
#-----------------
DATABASE_FORM_GENERICS ()
#-----------------
{
echo \"
<zone name=\\\"zone.\$Service.\$Database.${button_type}_form\\\">
	<zone_refresh><![CDATA[<meta http-equiv=\\\"Refresh\\\" content=\\\"180; url=../index.php?action=--page zone.\$Service.\$Database.map \$Service.\$Database.detail.draw\\\" />]]></zone_refresh>
	<zone_title><![CDATA[<title>\$1</title>]]></zone_title>
	<zone_type>button_form</zone_type>
	<zone_status>ok</zone_status>
	<zone_on_validate>--on_click zone.\$Service.\$Database.${button_type}_form \$Service.\$Database.${button_type}.result \$Service.\$Database.${button_type}.action</zone_on_validate>\"
}
#-----------------
DATABASE_FORM_BOTTOM ()
#-----------------
{
echo \"
<!-- end zone.\$Service.\$CommentDatabase.${button_type}.form --> </zone>
<!-- addendum form -->\"
DATABASE_CAT $Drawings/\$Service.\$Database.info.draw
}
#-----------------
DATABASE_ON_ERROR ()
#-----------------
{
echo \"<!-- this template generated by $0 on $Date mode $ServerMode -->
<zone name=\\\"zone.\$Service.\$Database.${button_type}.form\\\">
	<zone_refresh><![CDATA[<meta http-equiv=\\\"Refresh\\\" content=\\\"$SiteRefreshResult; url=../index.php?action=--page zone.\$Service.\$Database.map \$Service.\$Database.detail.draw\\\" />]]></zone_refresh>
	<zone_title><![CDATA[<title>\$FormTitle</title>]]></zone_title>
	<zone_type>button_form</zone_type>
	<zone_status>fault</zone_status>
	<zone_html><![CDATA[\$1]]></zone_html>\"
}
#-----------------
DATABASE_ON_BUZY ()
#-----------------
{
if [ ! -f $GoeActingFlag.\$Service.flag ] ; then
	Service0nBuzy=\"Available\"
else
	Service0nBuzy=\"Buzy\"
	FormTitle=\"\$T_Processing \$*...\"
	echo \"<!-- this template generated by $0 on $Date mode $ServerMode -->
<zone name=\\\"zone.\$Service.\$Database.${button_type}_form\\\">
	<zone_refresh><![CDATA[<meta http-equiv=\\\"Refresh\\\" content=\\\"$SiteRefreshResult; url=../index.php?action=--page zone.\$Service.\$Database.map \$Service.\$Database.detail.draw\\\" />]]></zone_refresh>
	<zone_title><![CDATA[<title>\$FormTitle</title>]]></zone_title>
	<zone_window>zone-\$Service-detail</zone_window>
	<zone_type>button_form</zone_type>
	<zone_status>fault</zone_status>
	<zone_on_validate>--on_click zone.\$Service.\$Database.${button_type}_form \$Service.\$Database.${button_type}.result \$Service.\$Database.${button_type}.action</zone_on_validate>
	<zone_form><![CDATA[\$FormTitle<br/>
\$T_Service : \$Service<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service actingsignal\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Clear_acting_signal :  </td><td><input type=\\\"radio\\\" name=\\\"actingsignal\\\" value=\\\"wait\\\" checked> \$T_Acting_wait</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"actingsignal\\\" value=\\\"clear\\\" > \$T_Acting_clear</td></tr>
</table>
\$T_Warning : \$T_Superceed_acting_signal.<br/> ]]></zone_form>\"

fi
}
#-----------------
DATABASE_GET_SERVICE_DATA
DATABASE_GET_SERVICE_LANGUAGE
#-----------------"
	FormDatabaseButtonDescription="DATABASE_GET_DESCRIPTION ()
#-----------------
{
#$DatabaseButtonsFullList
#editdatabasemenu save restore clone copy reference delete wipe_out dbupdate
Descriptions=\"
save:	\$T_Save_database \$T_on_service \$Service
snapshot:	\$T_Snapshot_database  \$T_on_service \$Service
restore:	\$T_Restore_database \$T_on_service \$Service
clone:	\$T_Clone_database \$T_on_service \$Service \$T_to_several_copies
copy:	\$T_Copy_database \$T_on_service \$Service \$T_to_another_service
reference:	\$T_Reference_database \$T_on_service \$Service
delete:	\$T_Delete_database \$T_on_service \$Service
wipe_out:	\$T_Delete_archives_of_database \$T_on_service \$Service
dbupdate:	\$T_Update_database \$T_on_service \$Service
\"
button_name=\`echo \"\$Descriptions\" | grep \"^\$1:\" | cut -d: -f2-\`
}
#-----------------"
	FormGetArchives="DATABASE_GET_ARCHIVES ()
#-----------------
{
archivedir=\"\$1\"
optionarchive=\"\"
optionlist=\"\"
if [ -d \"\$archivedir\" ] ; then
	ListArchives=\`ls \$archivedir | xargs\`
	echo \"<!-- ListArchives \$ListArchives -->\"
	for archive in \$ListArchives ; do
		case \"\$archive\" in
		daily*gz|last-*gz|monthly*gz|reference*gz|snapshot*gz|*gz|daily*sql|last-*sql|monthly*sql|reference*sql|snapshot*sql|*sql|*dump|*backup|*script|*profile)
			optionarchive=\"\$optionarchive<option value=\\\"\$archivedir/\$archive\\\">\$archive</option>\"
			optionlist=\"\$optionlist \$archive\"
			;;
		esac
	done
fi
}
#-----------------"
	FormGetServiceList="DATABASE_GET_SERVICE_LIST ()
#-----------------
{
	optionservice=\"\"
	for copyservice in $ServiceList ; do
		case \"\$copyservice\" in
		\$Service)
			;;
		*)
			optionservice=\"\$optionservice<option value=\\\"\$copyservice\\\">\$copyservice</option>\"
			;;
		esac
	done

}
#-----------------"
	;;
esac
#TR T_of_database of databsae : de la base de donnees
#TR T_on_service on service: du service
#TR T_Warning ‼️ WARNING : ‼️ ATTENTION
case "$button_type" in
#
#----------------------- buttons related to services
#
#------------
#Service Forms
#------------
button_editservicemenu)
	#TR T_Service_menu	Manage menu options of service : Gerez les options de menu sur le service
	#TR T_Service_menu_form	Form to manage your menu options : Formulaire pour gerer vos options de menu
	#TR T_Service_menu_action	Compose service menu : Composez le menu du service
	#TR T_Lost_service_menu Adding functions may increase risk for mistakes : En ajoutant des fonctions, vous augmentez le risque d'erreur
	echo "#! /bin/bash
$FormServiceGenerics
$FormServiceButtonDescription
SERVICE_FORM_TOP_WINDOW
FormTitle=\"\$T_Service_menu \$Service\"
SERVICE_FORM_GENERICS \"\$FormTitle\"
available_menu_list=\`/usr/local/bin/xoe --config -get -panel \$Service | cut -f2- | cut -d+ -f1 | cut -d- -f1 | xargs\`
if [ -z \"\$available_menu_list\" ] ; then
	available_menu_list=\"$ServiceButtonsDefaultList\"
fi
enabled_menu_list=\`/usr/local/bin/xoe --config -get -panel \$Service | cut -f2- | cut -d+ -f2 | cut -d- -f1 | xargs\`
if [ -z \"\$enabled_menu_list\" ] ; then
	enabled_menu_list=\"$ServiceButtonsDefaultList\"
fi
echo \"
<zone_form><![CDATA[\$T_Service_menu_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service menu_name menu_content\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<input type=\\\"hidden\\\" name=\\\"menu_name\\\" value=\\\"-service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Service_menu_action : </td><td></td></tr>\"
for button in \$available_menu_list ; do
	case \"\$button\" in
	editservicemenu)
		;;
	*)
		SERVICE_GET_DESCRIPTION \$button
		case \"\$enabled_menu_list\" in
		*\$button*)
			echo \"<tr><td></td><td><input type=\\\"checkbox\\\" name=\\\"menu_content[]\\\" value=\\\"\$button\\\" checked> \$button_name</td></tr>\"
			;;
		*)
			echo \"<tr><td></td><td><input type=\\\"checkbox\\\" name=\\\"menu_content[]\\\" value=\\\"\$button\\\"> \$button_name</td></tr>\"
			;;
		esac
		;;
	esac
done
echo \"
 </table>    
\$T_Warning : \$T_Lost_service_menu<br/>
]]></zone_form>\"
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_newcase)
	#new case is related to a service, not a database
	#TR T_New_case_set	Creating a new database from a reference case on service : Creer une nouvelle base de donnees depuis un cas reference sur le service
	#TR T_New_case_form	Form to create a new database from a reference case : Formulaire pour creer une nouvelle base de donnees a partir d'un cas reference
	#TR T_Case_list	Compatible cases list : Liste des cas references compatibles
	#TR T_New_database	Name of new database : Nom de la nouvelle base de donnees creee
	#TR T_case_prefix	case_ : cas_
	#TR T_Choose_case	Choose case reference to be used : Choisissez la reference de cas a utiliser
	#TR T_Admin_password	Set administrator's password for the new database : Mot de passe de l'administrateur de la nouvelle base de donnees
	#TR T_Lost_content_new_case		if new database already exists, all current data will be lost definitively : le contenu actuel de la base de donnees creee, si elle existe deja, sera definitivement perdu
	#TR T_No_case	No case reference available to create a new database : Pas de donnees de reference disponibles pour creer une nouvelle base de donnees sur le service

	DefPassword=`NEW_PASSWORD 4 4`
	echo "#! /bin/bash
$FormServiceGenerics
$FormGetReferences
SERVICE_GET_SERVICE_DATA
SERVICE_FORM_TOP_WINDOW

SERVICE_ON_BUZY \$T_New_case
case \"\$Service0nBuzy\" in
Available)
	if [ -d \"$XoeDir/xoe.services/\$Service/references\" ] ; then
		SERVICE_GET_REFERENCES \"$XoeDir/xoe.services/\$Service/references\"
	fi

	if [ -d \"$XoeDir/xoe.services/\$Service/references/\$erpvariant/\$serviceversion\" ] ; then
		SERVICE_GET_REFERENCES --add \"$XoeDir/xoe.services/\$Service/references/\$erpvariant/\$serviceversion\"
	fi
	if [ -d \"$XoeDir/xoe.packages/database_models/\$erpvariant/\$serviceversion\" ] ; then
		SERVICE_GET_REFERENCES --add \"$XoeDir/xoe.packages/database_models/\$erpvariant/\$serviceversion\"
	fi

	if [ -d \"$XoeDir/xoe.packages/database_models.\$erpvariant/\$serviceversion\" ] ; then
		SERVICE_GET_REFERENCES --add \"$XoeDir/xoe.packages/database_models.\$erpvariant/\$serviceversion\"
	fi


	if [ -d \"$XoeDir/xoe.packages/database_models/\$Service\" ] ; then
		SERVICE_GET_REFERENCES --add \"$XoeDir/xoe.packages/database_models/\$Service\"
	fi
	if [ ! -z \"\$optionarchive\" ] ; then
		FormTitle=\"\$T_New_case_set \$Service\"
		SERVICE_FORM_GENERICS \"\$FormTitle\"
		echo \"
	<zone_form><![CDATA[<p>\$T_New_case_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Case_list : \$optionlist<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service database archive admin_password\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_New_database : </td><td><input type=text name=\\\"database\\\" value=\\\"\$T_case_prefix\$Service\\\" $InputStyle required ></td></tr>
<tr><td>\$T_Choose_case : </td><td><select name=\\\"archive\\\" $InputStyle >\$optionarchive</select></td></tr>
<tr><td>\$T_Admin_password : </td><td><input type=text name=\\\"admin_password\\\" value=\\\"admin_${DefPassword}\\\" $InputStyle required ></td></tr>
</table>
\$T_Warning : \$T_Lost_content_new_case.<br/>
</p>]]></zone_form>\"
	else
		FormTitle=\"\$T_No_case \$Service erp \$erpvariant version \$serviceversion\"
		SERVICE_ON_ERROR \"\$FormTitle\"
	fi
	;;
esac
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_company)
	#new company is related to a service, not a database
	#TR T_Company_set	Creating a company profile on service : Creer un profil de societe sur le service
	#TR T_Company_form	Form to create a company profile : Formulaire pour creer un profil de societe
	#TR T_Profil_list	Existing profils : Profils existants
	#TR T_Company_name	Company name : Nom de la societe
	#TR T_Choose_month	First day of fiscal year : Debut de l exercice
	#TR T_Choose_period	Accounting periods : Periodes de comptabilite
	#TR T_default_company	My Company : Ma Societe

	#TR T_Lost_content_company	populate a database from a profil is very long, up to 20mn. Consider restoring a reference database instead if available: peupler une base de donnees a partir d un profile est tres long. jusqu a 20mn. Preferez la restauration d une reference si elle est disponible
	#TR T_No_company	Company profile is not available with Odoo on service : Les profils de societe ne sont pas supportes avec Odoo sur le service
	#TR T_january	January 1st : 1er janvier
	#TR T_february	February 1st : 1er fevrier
	#TR T_march	March 1st : 1er mars
	#TR T_april	April 1st : 1er avril
	#TR T_may	May 1st : 1er mai
	#TR T_june	June 1st : 1er juin
	#TR T_july	July 1st : 1er juillet
	#TR T_august	August 1st : 1er aout
	#TR T_september	September 1st : 1er septembre
	#TR T_october	October 1st : 1er octobre
	#TR T_november	November 1st : 1er novembre
	#TR T_december	December 1st : 1er decembre
	#TR T_monthly	Month : Mois
	#TR T_quarterly	Quarter : Trimestre
	DefPassword=`NEW_PASSWORD 4 4`
	echo "#! /bin/bash
$FormServiceGenerics
$FormGetReferences
SERVICE_GET_SERVICE_DATA

if [ -d \"$XoeDir/xoe.services/\$Service/references\" ] ; then
	SERVICE_GET_PROFILES \"$XoeDir/xoe.services/\$Service/references\"
fi
optionmonth=\"<option value=\\\"1\\\">\$T_january</option>
<option value=\\\"2\\\">\$T_february</option>
<option value=\\\"3\\\">\$T_march</option>
<option value=\\\"4\\\">\$T_april</option>
<option value=\\\"5\\\">\$T_may</option>
<option value=\\\"6\\\">\$T_june</option>
<option value=\\\"7\\\">\$T_july</option>
<option value=\\\"8\\\">\$T_august</option>
<option value=\\\"9\\\">\$T_september</option>
<option value=\\\"10\\\">\$T_october</option>
<option value=\\\"11\\\">\$T_november</option>
<option value=\\\"12\\\">\$T_december</option>\"
SERVICE_FORM_TOP_WINDOW
case \"\$erpname\" in
tryton)
	FormTitle=\"\$T_Company_set \$Service\"
	SERVICE_FORM_GENERICS \"\$FormTitle\"
	echo \"
	<zone_form><![CDATA[<p>\$T_Company_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Profil_list : \$optionlist<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service month period company\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Company_name : </td><td><input type=\\\"text\\\" name=\\\"company\\\" value=\\\"\$T_default_company\\\" $InputStyle required ></td></tr>
<tr><td>\$T_Choose_month : </td><td><select name=\\\"month\\\" $InputStyle required>\$optionmonth</select></td></tr>
<tr><td>\$T_Choose_period :  </td><td><input type=\\\"radio\\\" name=\\\"period\\\" value=\\\"1\\\" checked> \$T_monthly</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"period\\\" value=\\\"3\\\" > \$T_quarterly</td></tr>
</table>
\$T_Warning : \$T_Lost_content_company.<br/>
</p>]]></zone_form>\"
	;;
*)
	FormTitle=\"\$T_No_company \$Service version \$serviceversion\"
	SERVICE_ON_ERROR \"\$FormTitle\"
	;;
esac
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_drop)
	#drop is related to a service, not a database
	#TR T_Drop_set	Drop a set of databases on service : Supprimer un ensemble de bases de donnees sur le service
	#TR T_Drop_form	Form to drop a set of databases whose names begin by a list of prefixes : Formulaire pour supprimer un ensemble de bases de donnees dont les noms commencent par l un des prefixes d'une liste
	#TR T_Prefix_drop	Specify prefixes of databases names to be dropped : Specifiez les prefixes des noms des bases de donnees a supprimer
	#TR T_Lost_content_drop		All data of all databases whose name begin by one of these prefixes of the list will be lost definitively : tous les contenus de toutes les bases de donnees dont le nom commence par l un des prefixes de la liste seront definitivement perdus
	echo "#! /bin/bash
$FormServiceGenerics
SERVICE_FORM_TOP_WINDOW
SERVICE_ON_BUZY \$T_Drop
case \"\$Service0nBuzy\" in
Available)
	FormTitle=\"\$T_Drop_set \$Service\"
	SERVICE_FORM_GENERICS \"\$FormTitle\"
	echo \"
	<zone_form><![CDATA[<p>\$T_Drop_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service dropprefix\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Prefix_drop : </td><td><input type=text name=\\\"dropprefix\\\" value=\\\"clone copy copie case\\\" $InputStyle required ></td></tr>
</table>
\$T_Warning : \$T_Lost_content_drop.<br/>
</p>]]></zone_form>\"
	;;
esac
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_newmooc)
	#new mooc is related to a service, not a database
	#TR T_New_mooc_set	Creating a new course from a reference case on service : Creer un nouveau cours depuis un cas reference sur le service
	#TR T_New_mooc_form	Form to create a new course from a reference case : Formulaire pour creer un nouveau cours a partir d'un cas reference
	#TR T_Case_list Compatible cases list : Liste des cas references compatibles
	#TR T_New_mooc	Name of new course : Nom du nouveau cours cree
	#TR T_mooc_prefix	course_ : cours_
	#TR T_Choose_case	Choose case reference to be used : Choisissez la reference de cas a utiliser
	#TR T_Mooc_Min	Initial training databases creation : Nombre de bases de donnees initialement crees
	#TR T_Mooc_Max	Max training databases capacity : Nombre maximal de bases de donnees des eleves
	#TR T_Mooc_Mail	Teacher's mail address : Adresse mail du maitre
	#TR T_No_reference	No case reference available to create a new course : Pas de donnees de reference disponibles pour creer un nouveau cours sur le service
	echo "#! /bin/bash
$FormServiceGenerics
$FormGetReferences
SERVICE_FORM_TOP_WINDOW
SERVICE_ON_BUZY \$T_Mooc
case \"\$Service0nBuzy\" in
Available)
	SERVICE_GET_SERVICE_DATA

	if [ -d \"$XoeDir/xoe.services/\$Service/references\" ] ; then
		SERVICE_GET_REFERENCES \"$XoeDir/xoe.services/\$Service/references\"
	fi

	if [ -d \"$XoeDir/xoe.services/\$Service/references/\$erpvariant/\$serviceversion\" ] ; then
		SERVICE_GET_REFERENCES --add \"$XoeDir/xoe.services/\$Service/references/\$erpvariant/\$serviceversion\"
	fi
	if [ -d \"$XoeDir/xoe.packages/database_models/\$erpvariant/\$serviceversion\" ] ; then
		SERVICE_GET_REFERENCES --add \"$XoeDir/xoe.packages/database_models/\$erpvariant/\$serviceversion\"
	fi

	if [ -d \"$XoeDir/xoe.packages/database_models.\$erpvariant/\$serviceversion\" ] ; then
		SERVICE_GET_REFERENCES --add \"$XoeDir/xoe.packages/database_models.\$erpvariant/\$serviceversion\"
	fi
	if [ -d \"$XoeDir/xoe.packages/database_models/\$Service\" ] ; then
		SERVICE_GET_REFERENCES --add \"$XoeDir/xoe.packages/database_models/\$Service\"
	fi
	if [ ! -z \"\$optionarchive\" ] ; then
		FormTitle=\"\$T_New_mooc_set \$Service\"
		SERVICE_FORM_GENERICS \"\$FormTitle\"
		echo \"
	<zone_form><![CDATA[<p>\$T_New_mooc_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Case_list : \$optionlist<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service mooc_name archive mooc_min mooc_max mooc_mail\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_New_mooc : </td><td><input type=text name=\\\"mooc_name\\\" value=\\\"\$T_mooc_prefix\$Service\\\" $InputStyle required ></td></tr>
<tr><td>\$T_Choose_case : </td><td><select name=\\\"archive\\\" $InputStyle >\$optionarchive</select></td></tr>
<tr><td>\$T_Mooc_Min :</td><td> <input type=text name=\\\"mooc_min\\\" value=\\\"0\\\" $InputStyle required ></td></tr>
<tr><td>\$T_Mooc_Max :</td><td> <input type=text name=\\\"mooc_max\\\" value=\\\"30\\\" $InputStyle required ></td></tr>
<tr><td>\$T_Mooc_Mail : </td><td><input type=email name=\\\"mooc_mail\\\" $InputStyle required ></td></tr>
</table>
</p>]]></zone_form>\"
	else
		FormTitle=\"\$T_No_reference \$Service erp \$erpvariant version \$serviceversion\"
		SERVICE_ON_ERROR \"\$FormTitle\"
	fi
	;;
esac
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_managemooc)
	#drop is related to a service, not a database
	#TR T_Mooc_mgt	Manage your course on service : Gerez votre cours sur le service
	#TR T_Mooc_mgt_form	Form to manage your courses Open registration, Close registration, Cancel course : Formulaire pour gerer vos cours Ouvrir les inscriptions, Cloturer les inscriptions, Supprimer le cours
	#TR T_Mooc_to_manage	Course name : Nom du cours
	#TR T_Mooc_report	Report and instructions : Rapport et instructions
	#TR T_Mooc_open		Open registration : Ouvrir les inscriptions
	#TR T_Mooc_close	Close registration : Fermer les inscriptions
	#TR T_Mooc_cancel	Cancel course : Supprimer le cours
	#TR T_Mooc_action	Action open,close,cancel : Action ouvrir,fermer,supprimer
	#TR T_Lost_content_mooc Only Open courses are allowed for students registrations : Les etudiants ne peuvent s'incrire que sur les cours Ouverts
	#TR T_Mooc_hide	Hide database names on service : Masquer les noms de bases de donnees du service
	#TR T_Mooc_show	Show database names on service : Afficher les noms des bases de donnees du service
	echo "#! /bin/bash
$FormServiceGenerics
SERVICE_FORM_TOP_WINDOW
SERVICE_ON_BUZY \$T_Managemooc
case \"\$Service0nBuzy\" in
Available)
	FormTitle=\"\$T_Mooc_mgt \$Service\"
	SERVICE_FORM_GENERICS \"\$FormTitle\"
	moocservicelist=\`/usr/local/bin/mooc --list \$Service\`
	moocoptionlist=\"\"
	for moocelement in \$moocservicelist ; do 
		moocoptionlist=\"\$moocoptionlist <option value=\\\"\$moocelement\\\">\$moocelement</option>\"
	done
	echo \"
<zone_form><![CDATA[<p>\$T_Mooc_mgt_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service mooc_name mooc_action\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Mooc_to_manage : </td><td><select name=\\\"mooc_name\\\" $InputStyle required >\$moocoptionlist</select></td></tr>
<tr><td>\$T_Mooc_action : </td><td><input type=\\\"radio\\\" name=\\\"mooc_action\\\" value=\\\"--spool_report\\\" checked> \$T_Mooc_report</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"mooc_action\\\" value=\\\"--open\\\" > \$T_Mooc_open</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"mooc_action\\\" value=\\\"--close\\\" > \$T_Mooc_close</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"mooc_action\\\" value=\\\"--hide_database\\\" > \$T_Mooc_hide \$Service</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"mooc_action\\\" value=\\\"--show_database\\\" > \$T_Mooc_show \$Service</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"mooc_action\\\" value=\\\"--cancel\\\" > \$T_Mooc_cancel</td></tr>
</table>
\$T_Warning : \$T_Lost_content_mooc.<br/>
</p>]]></zone_form>\"
	;;
esac
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_exam)
	#
	#TR T_Exam_title	Manage your exam session on service : Gerez votre session d examen sur le service
	#TR T_Exam_form	Form to manage logins and password during exam sessin : Formulaire pour gerer les identifiants et mots de passe pendant une session d examen
	#TR T_Exam_to_manage	Course name : Nom du cours
	#TR T_Exam_login	Patched Login : Login modifie
	#TR T_Exam_password	Patched password : Mot de passe modifie
	#TR T_Exam_action	patch or restore ids : Modifier ou retablir les identifiants
	#TR T_Exam_patch	Patch ids as follows : Modifier les identifiants avec les valeurs suivantes
	#TR T_Exam_restore	Restore original ids : Retablir les identifiants d origine
	#TR T_Lost_content_exam Ids are modified in all databases declared in that course : Les identifiants sont modifies pour toutes les bases de donnees de ce cours
	DefPassword=`NEW_PASSWORD 4 4`
	echo "#! /bin/bash
$FormServiceGenerics
SERVICE_FORM_TOP_WINDOW
SERVICE_ON_BUZY \$T_Exam
case \"\$Service0nBuzy\" in
Available)
	FormTitle=\"\$T_Exam_title \$Service\"
	SERVICE_FORM_GENERICS \"\$FormTitle\"
	moocservicelist=\`/usr/local/bin/mooc --list \$Service\`
	moocoptionlist=\"\"
	for moocelement in \$moocservicelist ; do 
		moocoptionlist=\"\$moocoptionlist <option value=\\\"\$moocelement\\\">\$moocelement</option>\"
	done
	echo \"
	<zone_form><![CDATA[<p>\$T_Exam_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service mooc_name exam_action exam_login exam_password\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Exam_to_manage : </td><td><select name=\\\"mooc_name\\\" $InputStyle required >\$moocoptionlist</select></td></tr>
<tr><td>\$T_Exam_action : </td><td><input type=\\\"radio\\\" name=\\\"exam_action\\\" value=\\\"--spool_restore_logins\\\" > \$T_Exam_restore</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"exam_action\\\" value=\\\"--spool_replace_logins\\\" checked> \$T_Exam_patch</td></tr>
<tr><td>\$T_Exam_login : </td><td><input type=text name=\\\"exam_login\\\" value=\\\"admin\\\" $InputStyle required ></td></tr>
<tr><td>\$T_Exam_password : </td><td><input type=text name=\\\"exam_password\\\" value=\\\"admin_${DefPassword}\\\" $InputStyle required ></td></tr>
</table>
\$T_Warning : \$T_Lost_content_exam.<br/>
</p>]]></zone_form>\"
	;;
esac
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_upload)
	#TR T_Uploading	Add a archive to service : Ajout d une archive au service
	#TR T_Upload_form	Form to upload a new archive to the service : Formulaire pour telecharger une nouvelle archive au service
	#TR T_No_upload	Adding a new archive to service : L ajout d une archive au service
	#TR T_upload_is_protected	is dangerous. This service should be protected for its production role : est risque. Ce service doit etre protege pour son role en production
	#TR T_upload_is_disallowed	is not permitted : n'est pas autorisee
	#TR T_upload_cannot_be_modified	cannot be uploaded : ne peut pas etre telecharge
	#TR T_Upload_installed_	New archive installed : Nouvelle installation
	#TR T_Lost_content_upload	Only install compatible archives under AGPL, GPL or LGPL. Your service may stop for technical problems or legal reasons. Data may be lost. : N'installez que des archives compatibles sous licence AGPL, GPL ou LGPL. Votre service peut se bloquer pour une cause technique ou etre arrete pour une raison legale. Les donnees risquent d etre perdues.
	#TR T_Upload_validate	Validate this form to move these archives to your service : Validez pour deplacer ces archives vers le service
	#TR T_Upload_after_validate	Then you can install or remove uploaded archives with Archives... button. : Ensuite vous pourrez installer ou supprimer les archives telechargees avec le bouton Archives...
	echo "#! /bin/bash
$FormServiceGenerics
SERVICE_FORM_TOP_WINDOW
SERVICE_ON_BUZY \$T_Upload
case \"\$Service0nBuzy\" in
Available)

	case \"\$Uploadability\" in
	ok|protected)
		uploader=\"<script type=\\\"text/javascript\\\">
// common variables
var iBytesUploaded = 0;
var iBytesTotal = 0;
var iPreviousBytesLoaded = 0;
var iMaxFilesize = $MaxArchiveUploadSize;
var oTimer = 0;
var sResultFileSize = '';

function secondsToTime(secs) { // we will use this function to convert seconds in normal time format
    var hr = Math.floor(secs / 3600);
    var min = Math.floor((secs - (hr * 3600))/60);
    var sec = Math.floor(secs - (hr * 3600) -  (min * 60));

    if (hr < 10) {hr = \\\"0\\\" + hr; }
    if (min < 10) {min = \\\"0\\\" + min;}
    if (sec < 10) {sec = \\\"0\\\" + sec;}
    if (hr) {hr = \\\"00\\\";}
    return hr + ':' + min + ':' + sec;
};

function bytesToSize(bytes) {
    var sizes = ['Bytes', 'KB', 'MB'];
    if (bytes == 0) return 'n/a';
    var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
    return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};

function fileSelected() {

    // hide different warnings
    document.getElementById('upload_response').style.display = 'none';
    document.getElementById('errorextension').style.display = 'none';
    document.getElementById('errortransfer').style.display = 'none';
    document.getElementById('abort').style.display = 'none';
    document.getElementById('warnsize').style.display = 'none';

    // get selected file element
    var oFile = document.getElementById('archive_upload').files[0];

    // filter for image files
    var rFilter = /^(application\\\/tar.gz|application\\\/zip)$/i;
    if (! rFilter.test(oFile.type)) {
        document.getElementById('errorextension').style.display = 'block';
        return;
    }

    // little test for filesize
    if (oFile.size > iMaxFilesize) {
        document.getElementById('warnsize').style.display = 'block';
        return;
    }
}

function startUploading() {
    // cleanup all temp states
    iPreviousBytesLoaded = 0;
    document.getElementById('upload_response').style.display = 'none';
    document.getElementById('errorextension').style.display = 'none';
    document.getElementById('errortransfer').style.display = 'none';
    document.getElementById('abort').style.display = 'none';
    document.getElementById('warnsize').style.display = 'none';
    document.getElementById('progress_percent').innerHTML = '';
    var oProgress = document.getElementById('progress');
    oProgress.style.display = 'block';
    oProgress.style.width = '0px';

    // get form data for POSTing
    //var vFD = document.getElementById('upload_form').getFormData(); // for FF3
    var vFD = new FormData(document.getElementById('upload_form')); 

    // create XMLHttpRequest object, adding few event listeners, and POSTing our data
    var oXHR = new XMLHttpRequest();        
    oXHR.upload.addEventListener('progress', uploadProgress, false);
    oXHR.addEventListener('load', uploadFinish, false);
    oXHR.addEventListener('errorextension', uploadError, false);
    oXHR.addEventListener('abort', uploadAbort, false);
    oXHR.open('POST', 'upload.php');
    oXHR.send(vFD);

    // set inner timer
    oTimer = setInterval(doInnerUpdates, 300);
}

function doInnerUpdates() { // we will use this function to display upload speed
    var iCB = iBytesUploaded;
    var iDiff = iCB - iPreviousBytesLoaded;

    // if nothing new loaded - exit
    if (iDiff == 0)
        return;

    iPreviousBytesLoaded = iCB;
    iDiff = iDiff * 2;
    var iBytesRem = iBytesTotal - iPreviousBytesLoaded;
    var secondsRemaining = iBytesRem / iDiff;

    // update speed info
    var iSpeed = iDiff.toString() + 'B/s';
    if (iDiff > 1024 * 1024) {
        iSpeed = (Math.round(iDiff * 100/(1024*1024))/100).toString() + 'MB/s';
    } else if (iDiff > 1024) {
        iSpeed =  (Math.round(iDiff * 100/1024)/100).toString() + 'KB/s';
    }

    document.getElementById('speed').innerHTML = iSpeed;
    document.getElementById('remaining').innerHTML = '| ' + secondsToTime(secondsRemaining);        
}

function uploadProgress(e) { // upload process in progress
    if (e.lengthComputable) {
        iBytesUploaded = e.loaded;
        iBytesTotal = e.total;
        var iPercentComplete = Math.round(e.loaded * 100 / e.total);
        var iBytesTransfered = bytesToSize(iBytesUploaded);

        document.getElementById('progress_percent').innerHTML = iPercentComplete.toString() + '%';
        document.getElementById('progress').style.width = (iPercentComplete * 5).toString() + 'px';
        document.getElementById('b_transfered').innerHTML = iBytesTransfered;
        if (iPercentComplete == 100) {
            var oUploadResponse = document.getElementById('upload_response');
            oUploadResponse.innerHTML = '<p>Please wait...processing</p>';
            oUploadResponse.style.display = 'block';
        }
    } else {
        document.getElementById('progress').innerHTML = 'unable to compute';
    }
}

function uploadFinish(e) { // upload successfully finished
    var oUploadResponse = document.getElementById('upload_response');
    oUploadResponse.innerHTML = e.target.responseText;
    oUploadResponse.style.display = 'block';

    document.getElementById('progress_percent').innerHTML = '100%';
    document.getElementById('progress').style.width = '500px';
    document.getElementById('filesize').innerHTML = sResultFileSize;
    document.getElementById('remaining').innerHTML = '| 00:00:00';

    clearInterval(oTimer);
}

function uploadError(e) { // upload error
    document.getElementById('errortransfer').style.display = 'block';
    clearInterval(oTimer);
}  

function uploadAbort(e) { // upload abort
    document.getElementById('abort').style.display = 'block';
    clearInterval(oTimer);
}
  </script> 
<div class=\\\"container\\\">
	<div class=\\\"upload_form_cont\\\">
		<form id=\\\"upload_form\\\" enctype=\\\"multipart/form-data\\\" method=\\\"post\\\" action=\\\"upload.php\\\">
		<div>
			<div><label for=\\\"archive_upload\\\">Telecharger l'archive de chaque archive au format .tar.gz ou .zip. Upload a .tar.gz or .zip archive for each archive.</label></div>
			<br/>
			<div>
				<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service archive_upload\\\">
				<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
				<input type=\\\"file\\\" name=\\\"archive_upload\\\" id=\\\"archive_upload\\\" accept=\\\".tar.gz, .zip\\\" onchange=\\\"fileSelected();\\\" />
			</div>
		</div>
		<br/>
		<div>
			<input type=\\\"button\\\" value=\\\"upload\\\" onclick=\\\"startUploading()\\\" />
		</div>
		<div id=\\\"errorextension\\\">Select an archive .tar.gz or .zip</div>
		<div id=\\\"errortransfer\\\">An error occurred while uploading the file</div>
		<div id=\\\"abort\\\">The upload has been canceled by the user or the browser dropped the connection</div>
		<div id=\\\"warnsize\\\">File is too big. It will be rejected.</div>
		<div id=\\\"progress_info\\\">
			<div id=\\\"progress\\\"></div>
			<div id=\\\"progress_percent\\\">&nbsp;</div>
			<div class=\\\"clear_both\\\"></div>
			<div>
				<div id=\\\"speed\\\">&nbsp;</div>
				<div id=\\\"remaining\\\">&nbsp;</div>
				<div id=\\\"b_transfered\\\">&nbsp;</div>
				<div class=\\\"clear_both\\\"></div>
			</div>
			<div id=\\\"upload_response\\\"></div>
		</div>
		</form>
	</div>
</div>
\"
		case \"\$Uploadability\" in
		ok)
			FormTitle=\"\$T_Uploading \$Service\"
			;;
		protected)
			FormTitle=\"\$T_No_upload \$Service \$T_upload_is_protected \"
			;;
		esac
		SERVICE_FORM_GENERICS \"\$FormTitle\"

		echo \"<!-- this template generated by $0 on $Date mode $ServerMode, uploadability is \$Uploadability-->
<!-- upload archives form -->
<zone_html><![CDATA[\$T_Upload_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
<br/><hr/><br/><br/>
\$uploader]]></zone_html>
<!-- validatation form -->
<zone_form><![CDATA[
<br/><hr/><br/>
<br/>\$T_Upload_validate \$Service<br/>
\$T_Upload_after_validate<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
\$T_Warning : \$T_Lost_content_upload.<br/>
<br/>]]></zone_form>\"
		;;
	disallowed)
		FormTitle=\"\$T_No_upload \$Service \$T_upload_is_disallowed, uploadability is \$Uploadability \"
		SERVICE_ON_ERROR \"\$FormTitle\"
		;;
	*)
		FormTitle=\"\$T_No_upload \$Service \$T_upload_cannot_be_modified  uploadability is \$Uploadability\"
		SERVICE_ON_ERROR \"\$FormTitle\"
		;;
	esac
	;;
esac
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_installarchive)
	#drop is related to a service, not a database
	#TR T_Archive_mgt	Manage your custom archives on service : Gerez vos archives specifiques sur le service
	#TR T_Archive_mgt_form	Form to manage your archives Install or remove archive : Formulaire pour gerer vos archives Installer ou Supprimer l archive
	#TR T_Archive_list	Uploaded archives list : Liste des archives telechargees
	#TR T_Archive_to_manage	Archive name : Nom de l archive
	#TR T_Archive_install	Install archive to service (no way back) : Installer l archive sur le service (irreversible)
	#TR T_Archive_remove	Remove archive from specific library : Supprimer l archive de la bibliotheque specifique
	#TR T_Archive_action	Action install, delete : Action effacer ou installer
	#TR T_Lost_content_archive	Only tested archive can preserve your data : N utilisez que des archives testees
	#TR T_Install_failure	No custom archive to install on service : Pas d archive specifique installable sur le service
	echo "#! /bin/bash
$FormServiceGenerics
$FormGetCustoms
SERVICE_GET_CUSTOMS  \"$XoeDir/xoe.services/\$Service/custom\"
SERVICE_FORM_TOP_WINDOW
SERVICE_ON_BUZY \$T_installarchive
case \"\$Service0nBuzy\" in
Available)
	if [ ! -z \"\$ListCustoms\" ] ; then
		FormTitle=\"\$T_Archive_mgt \$Service\"
		SERVICE_FORM_GENERICS \"\$FormTitle\"
		echo \"
	<zone_form><![CDATA[<p>\$T_Archive_mgt_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Archive_list : \$ListCustoms<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service archive_name archive_action\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Archive_to_manage : </td><td><select name=\\\"archive_name\\\" $InputStyle required >\$OptionCustoms</select></td></tr>
<tr><td>\$T_Archive_action</td><td><input type=\\\"radio\\\" name=\\\"archive_action\\\" value=\\\"--remove\\\" checked > \$T_Archive_remove</td></tr>
<tr><td></td><td><input type=\\\"radio\\\" name=\\\"archive_action\\\" value=\\\"--directory\\\" > \$T_Archive_install</td></tr>
</table>
\$T_Warning : \$T_Lost_content_archive.<br/>
</p>]]></zone_form>\"
	else
		FormTitle=\"\$T_Install_failure  \$Service\"
		SERVICE_ON_ERROR \"\$FormTitle\"
	fi
	;;
esac
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_upgrade)
	#TR T_Upgrading	Change	version of service : Changement de version du service
	#TR T_Upgrade_form	Form to install a new version of the service : Formulaire pour installer une nouvelle version du service
	#TR T_No_upgrade	Reinstallation of service : La reinstallation du service
	#TR T_is_protected	is dangerous. This service should be protected for its production role : est risquee. Ce service doit etre protege pour son role en production
	#TR T_is_disallowed	is not permitted : n'est pas autorisee
	#TR T_cannot_be_modified	cannot be modified : ne peut pas etre modifiee
	#TR T_Modelversion	New version installed : Version de la nouvelle installation
	#TR T_Lost_content_upgrade		Odoo/OpenERP only supports minor release updates, Tryton supports some version upgrade. New version must be more recent : Odoo/OpenERP ne supporte que les changements de revision mineurs, Tryton supporte les montees de version mais des operations specifiques peuvent etre necessaires. La nouvelle version doit etre posterieure
	echo "#! /bin/bash
$FormServiceGenerics
SERVICE_FORM_TOP_WINDOW
SERVICE_ON_BUZY \$T_Upgrade
case \"\$Service0nBuzy\" in
Available)
	$FormGetGradability
	case \"\$Upgradability\" in
	ok)
		FormTitle=\"\$T_Upgrading \$Service\"
		SERVICE_FORM_GENERICS \"\$FormTitle\"
		echo \"
	<zone_form><![CDATA[<p>\$T_Upgrade_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
Liste \$ServiceCompatibilityList<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service modelversion\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Modelversion : </td><td><select name=\\\"modelversion\\\" $InputStyle >\$optionmodelversion</select></td></tr>
</table>
\$T_Warning : \$T_Lost_content_upgrade.<br/>
</p>]]></zone_form>\"
		;;
	protected)
		FormTitle=\"\$T_No_upgrade \$Service \$T_is_protected \"
		SERVICE_FORM_GENERICS \"\$FormTitle\"
		echo \"
	<zone_form><![CDATA[<p>\$T_Upgrade_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
Liste \$ServiceCompatibilityList<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service modelversion\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Modelversion : </td><td><select name=\\\"modelversion\\\" $InputStyle >\$optionmodelversion</select></td></tr>
</table>
\$T_Warning : \$T_Lost_content_upgrade.<br/>
</p>]]></zone_form>\"
		;;
	disallowed)
		FormTitle=\"\$T_No_upgrade \$Service \$T_is_disallowed \"
		SERVICE_ON_ERROR \"\$FormTitle\"
		;;
	*)
		FormTitle=\"\$T_No_upgrade \$Service \$T_cannot_be_modified\"
		SERVICE_ON_ERROR \"\$FormTitle\"
		;;
	esac
	;;
esac
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_downgrade)
	#TR T_Downgrading	Reverse last version upgrade of service : Retour a la version precedente du service
	#TR T_Downgrade_form Form to reverse last version upgrade of service : Formulaire pour revenir a la version precedente du service
	#TR T_No_downgrade version of service : La version du service
	#TR T_not_upgraded was not upgraded : n'a pas ete modifiee
	#TR T_Lost_content_downgrade		database contents will be reset to the level before upgrade : les contenus des bases de donnees vont etre reinitialises a ce qu ils etaient avant la montee de version.
	echo "#! /bin/bash
$FormServiceGenerics
SERVICE_FORM_TOP_WINDOW
SERVICE_ON_BUZY \$T_Downgrade
case \"\$Service0nBuzy\" in
Available)
	$FormGetGradability
	case \"\$Downgradability\" in
	ok)
		FormTitle=\"\$T_Downgrading \$Service\"
		SERVICE_FORM_GENERICS \"\$FormTitle\"
		echo \"
	<zone_form><![CDATA[<p>\$T_Downgrade_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
\$T_Warning : \$T_Lost_content_downgrade.<br/>
</p>]]></zone_form>\"
		;;
	*)
		FormTitle=\"\$T_No_downgrade \$Service \$T_not_upgraded\"
		SERVICE_ON_ERROR \"\$FormTitle\"
		;;
	esac
	;;
esac
SERVICE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
#-------------
#Database Menu
#-------------
button_editdatabasemenu)
	#TR T_Database_menu	Manage database operational menu of service : Gerer le menu operationnel des bases de donnees du service
	#TR T_Database_menu_form	Form to manage database operationnal menu : Formulaire pour gerer le menu operationnel des bases de donnees
	#TR T_Database_menu_action	Compose database menu for service : Composez le menu des bases de donnees du service
	#TR T_Database_menu_general	Modifications will apply to all databases of service : Les modifications sont appliquees a toutes les bases du service
	#TR T_Lost_database_menu Adding functions may increase risk for mistakes : En ajoutant des fonctions, vous augmentez le risque d'erreur
	echo "#! /bin/bash
$FormDbGenerics
$FormDatabaseButtonDescription
DATABASE_FORM_TOP_WINDOW
FormTitle=\"\$T_Database_menu \$Service\"
DATABASE_FORM_GENERICS \"\$FormTitle\"
available_menu_list=\`/usr/local/bin/xoe --config -get -panel \$Service | cut -f2- | cut -d+ -f1 | cut -d- -f2 | xargs\`
if [ -z \"\$available_menu_list\" ] ; then
	available_menu_list=\"$DatabaseButtonsDefaultList\"
fi
enabled_menu_list=\`/usr/local/bin/xoe --config -get -panel \$Service | cut -f2- | cut -d+ -f2 | cut -d- -f2 | xargs\`
if [ -z \"\$enabled_menu_list\" ] ; then
	enabled_menu_list=\"$DatabaseButtonsDefaultList\"
fi
echo \"
<zone_form><![CDATA[<p>\$T_Database_menu_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service menu_name menu_content\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<input type=\\\"hidden\\\" name=\\\"menu_name\\\" value=\\\"-database\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Database_menu_action : </td><td></td></tr>\"
for button in \$available_menu_list ; do
	case \"\$button\" in
	editdatabasemenu)
		;;
	*)
		DATABASE_GET_DESCRIPTION \$button
		case \"\$enabled_menu_list\" in
		*\$button*)
			echo \"<tr><td></td><td><input type=\\\"checkbox\\\" name=\\\"menu_content[]\\\" value=\\\"\$button\\\" checked> \$button_name</td></tr>\"
			;;
		*)
			echo \"<tr><td></td><td><input type=\\\"checkbox\\\" name=\\\"menu_content[]\\\" value=\\\"\$button\\\"> \$button_name</td></tr>\"
			;;
		esac
		;;
	esac
done
echo \"
 </table>    
\$T_Warning : \$T_Database_menu_general \$Service. \$T_Lost_database_menu<br/>
</p>]]></zone_form>\"
DATABASE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_restore)
	#TR T_Restoring_an_archive	Restoring an archive : Restaurer une sauvegarde
	#TR T_Restoring_form Form for database restoration : Formulaire de restauration de base de donnees
	#TR T_Liste_of_archives		Liste of archives : Liste des sauvegardes compatibles
	#TR T_Name_of_restored_database	Give a name to the restored database : Donnez un nom a la base de donnees restauree
	#TR T_Database_archive		Choose database archive to be restored : Choisissez les donnees sauvegardees a restaurer

	#TR T_Lost_content_restore	if restored database already exists, all current data will be lost definitively : le contenu actuel de la base de donnees restauree, si elle existe deja, sera definitivement perdu
	#TR T_Restoring_failure		Failure while restoring database : Anomalie lors de la restauration de la base de donnees

	#TR T_No_archive		No valid archive for database : Pas de sauvegarde valide pour la base de donnees
	#TR T_to_be_restored		to be restored on service : a restaurer pour le service
	#TR T_idem			idem : idem
	DatabaseKey=`NEW_PASSWORD -min 4`
	echo "#! /bin/bash
$FormDbGenerics
$FormGetArchives
DATABASE_FORM_TOP_WINDOW
DATABASE_ON_BUZY \$T_Restore
case \"\$Service0nBuzy\" in
Available)
	DATABASE_GET_ARCHIVES \"$XoeDir/xoe.services/\$Service/database/\$Database\"
	if [ ! -z \"\$optionarchive\" ] ; then
		FormTitle=\"\$T_Restoring_an_archive \$T_of_database \$Database \$T_on_service \$Service\"
		DATABASE_FORM_GENERICS \"\$FormTitle\"
		echo \"
	<zone_form><![CDATA[<p>\$T_Restoring_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Liste_of_archives : \$optionlist<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service database archive\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<br/><hr/><br/>
<table>
<tr><td>\$T_Name_of_restored_database : </td><td><input type=text name=\\\"database\\\" value=\\\"\${T_idem}_\${Database}_$DatabaseKey\\\" $InputStyle required ></td></tr>
<tr><td>\$T_Database_archive : </td><td><select name=\\\"archive\\\" $InputStyle >\$optionarchive</select></td></tr>
</table>
\$T_Warning : \$T_Lost_content_restore.<br/>
</p>]]></zone_form>\"
	else
		FormTitle=\"\$T_Restoring_failure \$Database \$T_on_service \$Service\"
		DATABASE_ON_ERROR \"\$T_No_archive \$Database \$T_to_be_restored \$Service\"
	fi
	;;
esac
DATABASE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_clone)
	#TR T_Cloning_database Cloning database : Cloner la base de donnees
	#TR T_Cloning_form Form for database cloning to several copies on the same service : Formulaire de clonage de la base de donnees en plusieurs exemplaires sur le meme service
	#TR T_Prefixes Choose prefixes added to the name of cloned database : Choisissez les prefixes ajoutes au nom de la base de donnees clonee
	#TR T_Lost_contents_clone if created databases already exist, all current data will be lost definitively : le contenu actuel des bases de donnees creees, si elles existent deja, sera definitivement perdu
	#TR T_Cloning failure Failure while cloning database : Anomalie lors du clonage de la base de donnees
	#TR T_save_first first save database to be cloned : vous devez d abord sauvegarder la base de donnees a cloner
	echo "#! /bin/bash
$FormDbGenerics
$FormGetArchives
DATABASE_FORM_TOP_WINDOW
DATABASE_ON_BUZY \$T_Clone
case \"\$Service0nBuzy\" in
Available)
	DATABASE_GET_ARCHIVES \"$XoeDir/xoe.services/\$Service/database/\$Database\"
	if [ ! -z \"\$optionarchive\" ] ; then
		FormTitle=\"\$T_Cloning_database \$Database \$T_on_service \$Service\"
		DATABASE_FORM_GENERICS \"\$FormTitle\"
		echo \"
	<zone_form><![CDATA[<p>\$T_Cloning_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Database : \$Database<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service database cloneprefix\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<input type=\\\"hidden\\\" name=\\\"database\\\" value=\\\"\$Database\\\"><br/>
<br/><hr/><br/>
<table>
<tr><td>\$T_Prefixes : </td><td><input type=text name=\\\"cloneprefix\\\" value=\\\"clone1_ clone2_ clone3_\\\" $InputStyle required ></td></tr>
</table>
\$T_Warning : \$T_Lost_contents_clone.<br/>
</p>]]></zone_form>\"
	else
		FormTitle=\"\$T_Cloning failure \$Database \$T_on_service \$Service\"
		DATABASE_ON_ERROR \"\$T_No_archive \$Database \$T_on_service \$Service, \$T_save_first\"
	fi
	;;
esac
DATABASE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_copy)
	#TR T_Copying_database		Copying database : Copier la base de donnees
	#TR T_from_service		from service : depuis le service
	#TR T_to_another_service	to another service : vers un autre service
	#TR T_Copy_form			Form to copy database to another service : Formulaire pour copier la base de donnees vers un autre service
	#TR T_Target_service		Choose service to which database will be copied : Choisissez le service vers lequel la base de donnees sera copiee
	#TR T_Prefix_copy 		Set prefix added to copied database : Indiquez le prefixe ajoute au nom de la base de donnees copiee
	#TR T_Lost_content_copy		if copied database already exists, all current data will be lost definitively : le contenu actuel de la base de donnees copiee, si elle existe deja, sera definitivement perdu
	#TR T_Copying_failure 		Failure while copying database : Anomalie lors de la copie de la base de donnees
	#TR T_No_target_service 	No other service to copy the database can be copied : Pas d autre service vers lequel copier la base de donnees
	#TR T_Rights_failure		You are not allowed to copy database : Vous n'etes pas authorise a copier la base de donnees
	#TR T_User_rights		You must connect with administration rights to copy a database : Vous devez vous identifier avec des droits d administrateur pour copier la base
	#TR T_You_are 			You are : Vous etes
	echo "#! /bin/bash
$FormDbGenerics
$FormGetArchives
$FormGetServiceList
DATABASE_FORM_TOP_WINDOW
DATABASE_ON_BUZY \$T_Copy
case \"\$Service0nBuzy\" in
Available)
	DATABASE_GET_ARCHIVES \"$XoeDir/xoe.services/\$Service/database/\$Database\"
	case \"\$LoginRole\" in
	admin*|Admin*)
		DATABASE_GET_SERVICE_LIST
		if [ ! -z \"\$optionarchive\" ] ; then
			if [ ! -z \"\$optionservice\" ] ; then
				FormTitle=\"\$T_Copying_database \$Database \$T_from_service \$Service \$T_to_another_service\"
				DATABASE_FORM_GENERICS \"\$FormTitle\"
				echo \"
	<zone_form><![CDATA[<p>\$T_Copy_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Database : \$Database<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service database copyservice copyprefix\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<input type=\\\"hidden\\\" name=\\\"database\\\" value=\\\"\$Database\\\"><br/>
<br/><hr/><br/>
<table>
<tr><td>\$T_Target_service : </td><td><select name=\\\"copyservice\\\" $InputStyle >\$optionservice</select></td></tr>
<tr><td>\$T_Prefix_copy : </td><td><input type=text name=\\\"copyprefix\\\" value=\\\"copie_de_\\\" $InputStyle required ></td></tr>
</table>
\$T_Warning : \$T_Lost_content_copy.<br/>
</p>]]></zone_form>\"
			else
				FormTitle=\"T_Copying_failure \$Database \$T_from_service \$Service\"
				DATABASE_ON_ERROR \"\$T_No_target_service \$Database \$T_on_service \$Service\"
			fi
		else
			FormTitle=\"\$T_Copying_failure \$Database \$T_from_service \$Service\"
			DATABASE_ON_ERROR \"\$T_No_archive \$Database \$T_on_service \$Service, \$T_save_first\"
		fi
		;;
	*)
		FormTitle=\"\$T_Rights_failure \$Database \$T_from_service \$Service\"
		DATABASE_ON_ERROR \"\$T_User_rights \$Database \$T_from_service \$Service. \$T_You_are \$LoginRole\"
		;;
	esac
	;;
esac
DATABASE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_reference)
	#TR T_New_reference	Create a reference from the database : Creer une reference de la base de donnees
	#TR T_New_reference_failure	Failed to create a reference from the database : Echec de la creation d une reference de la base de donnees
	#TR T_New_reference_form	Form to create a reference from this database : Formulaire pour creer une reference de cette base de donnees
	#TR T_Lost_content_reference		Any previous reference of this database will be definitly lost : Toute reference precedente de la base de donnees sera definitivement supprimee
	echo "#! /bin/bash
$FormDbGenerics
$FormGetArchives
DATABASE_FORM_TOP_WINDOW
DATABASE_ON_BUZY \$T_Reference
case \"\$Service0nBuzy\" in
Available)
	DATABASE_GET_ARCHIVES \"$XoeDir/xoe.services/\$Service/database/\$Database\"
	if [ ! -z \"\$optionarchive\" ] ; then
		FormTitle=\"\$T_New_reference \$Database \$T_on_service \$Service\"
		DATABASE_FORM_GENERICS \"\$FormTitle\"
		echo \"
	<zone_form><![CDATA[<p>\$T_New_reference_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Database : \$Database<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service database\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<input type=\\\"hidden\\\" name=\\\"database\\\" value=\\\"\$Database\\\">
<br/><hr/><br/>
\$T_Warning : \$T_Lost_content_reference.<br/>
</p>]]></zone_form>\"
	else
		FormTitle=\"\$T_New_reference_failure \$Database \$T_on_service \$Service\"
		DATABASE_ON_ERROR \"\$T_No_archive \$Database \$T_on_service \$Service, \$T_save_first\"
	fi
	;;
esac
DATABASE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_delete)
	#TR T_Delete_database	Remove database : Supprimer la base de donnees
	#TR T_Delete_form	Form to remove database : Formulaire pour supprimer la base de donnees
	#TR T_Lost_content_delete		All current data will be lost definitively : Le contenu actuel de la base de donnees supprimee sera definitivement perdu
	echo "#! /bin/bash
$FormDbGenerics
DATABASE_FORM_TOP_WINDOW
DATABASE_ON_BUZY \$T_Delete
case \"\$Service0nBuzy\" in
Available)
	FormTitle=\"\$T_Delete_database \$Database \$T_on_service \$Service\"
	DATABASE_FORM_GENERICS \"\$FormTitle\"
	echo \"
	<zone_form><![CDATA[<p>\$T_Delete_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Database : \$Database<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service database\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<input type=\\\"hidden\\\" name=\\\"database\\\" value=\\\"\$Database\\\">
<br/><hr/><br/>
\$T_Warning : \$T_Lost_content_delete.<br/>
</p>]]></zone_form>\"
	;;
esac
DATABASE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_wipe_out)
	#TR T_Wipe_out_archives	Remove all archives of database : Effacer les sauvegardes de la base de donnees
	#TR T_Wipe_out_form	Form to remove all archives of database : Formulaire pour effacer les sauvegardes de la base de donnees
	#TR T_Lost_content_wipe_out		all archives of database will be lost definitively : toutes les archives des sauvegardes de la bases de donnees seront definitivement detruites
	echo "#! /bin/bash
$FormDbGenerics
DATABASE_FORM_TOP_WINDOW
DATABASE_ON_BUZY \$T_Wipe_out
case \"\$Service0nBuzy\" in
Available)
	FormTitle=\"\$T_Wipe_out_archives \$Database du service \$Service\"
	DATABASE_FORM_GENERICS \"\$FormTitle\"
	echo \"
	<zone_form><![CDATA[<p>\$T_Wipe_out_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Database : \$Database<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service database\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<input type=\\\"hidden\\\" name=\\\"database\\\" value=\\\"\$Database\\\">
<br/><hr/><br/>
\$T_Warning : \$T_Lost_content_wipe_out.<br/>
</p>]]></zone_form>\"
	;;
esac
DATABASE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
button_dbupdate)
	#TR T_Db_update_form		Form to update this database : Formulaire pour mettre a jour cette base de donnees
	#TR T_Db_update			Automated version update of database : La montee automatique de version de la base de donnees
	#TR T_is_tryton_only		is only supported on tryton : n est supportee que par tryton

	#TR T_Db_update_failure		failure of automated version update of database : Echec de la montee automatique de version de la base de donnees
	#TR T_Lost_content_dbupdate	In case of failure, content of this database may need restoration : En cas d echec, le contenu de la base de donnees devra peut-etre etre restaure
	#TR T_No_db_update_archive	No valid archive for database : Pas de sauvegarde valide pour la base de donnees
	#TR T_db_update_save_first	first save database before update : vous devez sauvegarder la base de donnees avant mise a jour
	echo "#! /bin/bash
$FormDbGenerics
$FormGetArchives
DATABASE_FORM_TOP_WINDOW
DATABASE_ON_BUZY \$T_DbUpdate
case \"\$Service0nBuzy\" in
Available)
	DATABASE_GET_SERVICE_DATA
	DATABASE_GET_ARCHIVES \"$XoeDir/xoe.services/\$Service/database/\$Database\"
	case \"\$erpname\" in
	tryton)
		if [ ! -z \"\$optionarchive\" ] ; then
			FormTitle=\"\$T_Db_update \$Database \$T_on_service \$Service\"
			DATABASE_FORM_GENERICS \"\$FormTitle\"
			echo \"
<zone_form><![CDATA[<p>\$T_Db_update_form<br/>
\$FormTitle<br/>
\$T_Service : \$Service<br/>
\$T_Database : \$Database<br/>
<input type=\\\"hidden\\\" name=\\\"fields\\\" value=\\\"service database\\\">
<input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"\$Service\\\">
<input type=\\\"hidden\\\" name=\\\"database\\\" value=\\\"\$Database\\\">
<br/><hr/><br/>
\$T_Warning : \$T_Lost_content_dbupdate.<br/>
</p>]]></zone_form>\"
		else
			FormTitle=\"\$T_Cloning failure \$Database \$T_on_service \$Service\"
			DATABASE_ON_ERROR \"\$T_No_db_update_archive \$Database \$T_on_service \$Service, \$T_db_update_save_first\"
		fi
		;;
	*)
		FormTitle=\"\$T_Db_update_failure \$Database \$T_on_service \$Service\"
		DATABASE_ON_ERROR \"\$T_Db_update \$Database \$T_on_service \$Service \$T_is_tryton_only\"
		;;
	esac
	;;
esac
DATABASE_FORM_BOTTOM
" > $Forms.draft/$form_template
	;;
*)
	LOG_MESSAGE $LINENO -g TEMPLATE_BUTTON_FORM $* ERROR
	;;
esac
chmod 600 $Forms.draft/$form_template
}
#end 
#------------------------------------------------------------------------------
#last segment of --template command


	echo -n "New templates for actions, forms and results on `date +'%Hh%Mm%Ss:%3N'`...." >> $GoeTemplatesLog
	if [ -e "$Actions.draft" ] ; then rm -rf $Actions.draft ; fi
	mkdir -p $Actions.draft
	chmod 750 $Actions.draft
	echo "Last actions on $Date" >> $GoeActionsLog
	if [ -e "$Forms.draft" ] ; then rm -rf $Forms.draft ; fi
	mkdir -p $Forms.draft
	chmod 750 $Forms.draft
	echo "Last forms on $Date" >> $GoeFormsLog
	if [ -e "$Results.draft" ] ; then rm -rf $Results.draft ; fi
	mkdir -p $Results.draft
	chmod 750 $Results.draft
	echo "Last results on $Date" >> $GoeResultsLog
	GET_DATA $LINENO page
	XoeDirConf=`cat $XoeDir/xoe.conf/xoe.services.conf | grep "^directory:server:"`

	ActionServiceList="button_editservicemenu button_renew button_start button_stop button_restart button_newcase button_company button_drop button_newmooc button_managemooc button_exam button_upload button_installarchive button_upgrade"
# button_downgrade"
	ButtonFormServiceList="button_editservicemenu button_newcase button_company button_drop button_newmooc button_managemooc button_exam button_upload button_installarchive button_upgrade"
#  button_downgrade"
	ButtonResultServiceList="$ActionServiceList"
	ActionDatabaseList="button_editdatabasemenu button_save button_snapshot button_restore button_clone button_copy button_reference button_delete button_wipe_out button_dbupdate"
	ButtonFormDatabaseList="button_editdatabasemenu button_restore button_clone button_copy button_reference button_delete button_wipe_out button_dbupdate"
	ButtonResultDatabaseList="$ActionDatabaseList"
	ActionList="$ActionServiceList $ActionDatabaseList"
	ButtonFormList="$ButtonFormServiceList $ButtonFormDatabaseList"
	ButtonResultList="$ButtonResultServiceList $ButtonResultDatabaseList"
	CHECK_BUZY $LINENO set
	for action in $ActionList ; do
		TEMPLATE_ACTION $action
	done
	for template in $ButtonFormList ; do
		TEMPLATE_BUTTON_FORM $template ${template}.form
	done
	for template in $ButtonResultList ; do
		TEMPLATE_BUTTON_RESULT $template ${template}.result
	done
	CHECK_BUZY $LINENO set
	for template in  $Actions $Forms $Results ; do
		chmod 750 $template.draft/*
		$Sudo chown -R $XoeAuthorizedUser:$HttpUser $template.draft
		mv $template $template.removed
		mv $template.draft $template
	done
	CHECK_BUZY $LINENO release
	LOG_MESSAGE $LINENO -g --template buttons forms, results and actions have been updated
	rm -rf $Actions.removed
	rm -rf $Forms.removed
	rm -rf $Results.removed
	echo "....`date +'%Hh%Mm%Ss:%3N'`" >> $GoeTemplatesLog
	;;
--draw*)
	PageTop="<![CDATA[$BackToTopImage]]>"
	PageBack1="<![CDATA[<hr/>$BackImage]]>"
	PageBack2="<![CDATA[$BackImage<hr/>]]>"
#------------------------------------------------------------------------------
FILL_DATABASE_MENU ()
#------------------------------------------------------------------------------
{
#LOG_MESSAGE $LINENO -g FILL_DATABASE_MENU $*
button_name="$1"
case "$button_name" in
header)
	DatabaseMenuContent="
<zone name=\"zone.$Service.$Database.detail\">
	<zone_title><![CDATA[<title>$T_Detailled_database $Database $T_on_service $Service</title>]]></zone_title>
	<zone_type>database_detail</zone_type>
<zone name=\"zone.$Service.$Database.buttons\">
	<zone_position>zbuttons</zone_position>"
	;;
editdatabasemenu)
		DatabaseMenuContent="$DatabaseMenuContent
<zone name=\"zone.$Service.$Database.button_editdatabasemenu\">
	<zone_on_click>--page zone.$Service.$Database.button_editdatabasemenu $Service.$Database.button_editdatabasemenu.form</zone_on_click>
	<zone_doc_over>$ButtonEditDatabaseMenuDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonEditDatabaseMenuStatus</zone_status>
	<zone_label>$T_EditDatabaseMenu</zone_label>
<!-- end \"zone.$Service.$CommentDatabase.button_editdatabasemenu\" --> </zone>"
	;;
save)
	DatabaseMenuContent="$DatabaseMenuContent
<zone name=\"zone.$Service.$Database.button_save\">
	<zone_on_click>--on_click zone.$Service.$Database.button_save $Service.$Database.button_save.result $Service.$Database.button_save.action $Service $Database</zone_on_click>
	<zone_doc_over> $ButtonSaveDoc </zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonSaveStatus</zone_status>
	<zone_label>$T_Save</zone_label>
<!-- end \"zone.$Service.$CommentDatabase.button_save\" --> </zone>"
	;;
snapshot)
	DatabaseMenuContent="$DatabaseMenuContent
<zone name=\"zone.$Service.$Database.button_snapshot\">
	<zone_on_click>--on_click zone.$Service.$Database.button_snapshot $Service.$Database.button_snapshot.result $Service.$Database.button_snapshot.action $Service $Database</zone_on_click>
	<zone_doc_over> $ButtonSnapshotDoc </zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonSnapshotStatus</zone_status>
	<zone_label>$T_Snapshot</zone_label>
<!-- end \"zone.$Service.$CommentDatabase.button_snapshot\" --> </zone>"
	;;
restore)
	DatabaseMenuContent="$DatabaseMenuContent
<zone name=\"zone.$Service.$Database.button_restore\">
	<zone_on_click>--page zone.$Service.$Database.button_restore $Service.$Database.button_restore.form</zone_on_click>
	<zone_doc_over> $ButtonRestoreDoc </zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonRestoreStatus</zone_status>
	<zone_label>$T_Restore...</zone_label>
<!-- end \"zone.$Service.$CommentDatabase.button_restore\" --> </zone>"
	;;
clone)
	DatabaseMenuContent="$DatabaseMenuContent
<zone name=\"zone.$Service.$Database.button_clone\">
	<zone_on_click>--page zone.$Service.$Database.button_clone $Service.$Database.button_clone.form</zone_on_click>
	<zone_doc_over>$ButtonCloneDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonCloneStatus</zone_status>
	<zone_label>$T_Clone... </zone_label>
<!-- end \"zone.$Service.$CommentDatabase.button_clone\" --> </zone>"
	;;
copy)
#	case "$LoginRole" in
#	admin*|Admin*)
	DatabaseMenuContent="$DatabaseMenuContent
<zone name=\"zone.$Service.$Database.button_copy\">
	<zone_on_click>--page zone.$Service.$Database.button_copy $Service.$Database.button_copy.form</zone_on_click>
	<zone_doc_over>$ButtonCopyDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonCopyStatus</zone_status>
	<zone_label>$T_Copy...</zone_label> -->
<!-- end \"zone.$Service.$CommentDatabase.button_copy\" --> </zone>"
#		;;
#	esac
	;;
reference)
	DatabaseMenuContent="$DatabaseMenuContent
<zone name=\"zone.$Service.$Database.button_reference\">
	<zone_on_click>--page zone.$Service.$Database.button_reference $Service.$Database.button_reference.form</zone_on_click>
	<zone_doc_over>$ButtonReferenceDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonReferenceStatus</zone_status>
	<zone_label>$T_Reference...</zone_label>
<!-- end \"zone.$Service.$CommentDatabase.button_reference\" --> </zone>"
	;;
delete)
	DatabaseMenuContent="$DatabaseMenuContent
<zone name=\"zone.$Service.$Database.button_delete\">
	<zone_on_click>--page zone.$Service.$Database.button_delete $Service.$Database.button_delete.form</zone_on_click>
	<zone_doc_over>$ButtonDeleteDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonDeleteStatus</zone_status>
	<zone_label>$T_Delete...</zone_label>
<!-- end \"zone.$Service.$CommentDatabase.button_delete\" --> </zone>"
	;;
wipe_out)
	DatabaseMenuContent="$DatabaseMenuContent
<zone name=\"zone.$Service.$Database.button_wipe_out\">
	<zone_on_click>--page zone.$Service.$Database.button_wipe_out $Service.$Database.button_wipe_out.form</zone_on_click>
	<zone_doc_over>$ButtonWipeOutDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonWipeOutStatus</zone_status>
	<zone_label>$T_Wipe_out...</zone_label>
<!-- end \"zone.$Service.$CommentDatabase.button_wipe_out\" --> </zone>"
	;;
dbupdate)
	DatabaseMenuContent="$DatabaseMenuContent
<zone name=\"zone.$Service.$Database.button_dbupdate\">
	<zone_on_click>--page zone.$Service.$Database.button_dbupdate $Service.$Database.button_dbupdate.form</zone_on_click>
	<zone_doc_over>$ButtonDbUpdateDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonDbUpdateStatus</zone_status>
	<zone_label>$T_DbUpdate...</zone_label>
<!-- end \"zone.$Service.$CommentDatabase.button_dbupdate\" --> </zone>"
	;;
end)
	DatabaseMenuContent="$DatabaseMenuContent
<!-- end \"zone.$Service.$CommentDatabase.buttons\" --> </zone>"
	;;
esac
}
#end 
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
FILL_SERVICE_MENU ()
#------------------------------------------------------------------------------
{
#LOG_MESSAGE $LINENO -g FILL_SERVICE_MENU $*
button_name="$1"
case "$button_name" in
header)
	ServiceMenuContent="
<zone name=\"zone.$Service.detail\">
	<zone_title><![CDATA[<title>$T_Detailled_service $Service</title>]]></zone_title>
	<zone_type>service_detail</zone_type>
<zone name=\"zone.$Service.buttons\">
	<zone_position>zbuttons</zone_position>"
	;;
editservicemenu)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_editservicemenu\">
	<zone_on_click>--page zone.$Service..button_editservicemenu $Service..button_editservicemenu.form</zone_on_click>
	<zone_doc_over>$ButtonEditServiceMenuDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonEditServiceMenuStatus</zone_status>
	<zone_label>$T_EditServiceMenu</zone_label>
<!-- end \"zone.$Service..button_editservicemenu\" --> </zone>"
	;;
renew)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_renew\">
	<zone_on_click>--on_click zone.$Service..button_renew $Service..button_renew.result $Service..button_renew.action $Service</zone_on_click>
	<zone_doc_over>$ButtonRenewDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonRenewStatus</zone_status>
	<zone_label>$T_Renew</zone_label>
<!-- end \"zone.$Service..button_renew\" --> </zone>"

	;;
start)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_start\">
	<zone_on_click>--on_click zone.$Service..button_start $Service..button_start.result $Service..button_start.action $Service</zone_on_click>
	<zone_doc_over>$ButtonStartDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonStartStatus</zone_status>
	<zone_label>$T_Start</zone_label>
<!-- end \"zone.$Service..button_start\" --> </zone>"
	;;
stop)
		ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_stop\">
	<zone_on_click>--on_click zone.$Service..button_stop $Service..button_stop.result $Service..button_stop.action $Service</zone_on_click>
	<zone_doc_over>$ButtonStopDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonStopStatus</zone_status>
	<zone_label>$T_Stop</zone_label>
<!-- end \"zone.$Service..button_stop\" --> </zone>"
	;;
restart)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_restart\">
	<zone_on_click>--on_click zone.$Service..button_restart $Service..button_restart.result $Service..button_restart.action $Service</zone_on_click>
	<zone_doc_over>$ButtonRestartDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonRestartStatus</zone_status>
	<zone_label>$T_Restart</zone_label>
<!-- end \"zone.$Service..button_restart\" --> </zone>"
	;;
newcase)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_newcase\">
	<zone_on_click>--page zone.$Service..button_newcase $Service..button_newcase.form</zone_on_click>
	<zone_doc_over>$ButtonNewCaseDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonNewCaseStatus</zone_status>
	<zone_label>$T_New_case...</zone_label>
<!-- end \"zone.$Service..button_newcase\" --> </zone>"
	;;
company)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_company\">
	<zone_on_click>--page zone.$Service..button_company $Service..button_company.form</zone_on_click>
	<zone_doc_over>$ButtonCompanyDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonCompanyStatus</zone_status>
	<zone_label>$T_Company...</zone_label>
<!-- end \"zone.$Service..button_company\" --> </zone>"
	;;
drop)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_drop\">
	<zone_on_click>--page zone.$Service..button_drop $Service..button_drop.form</zone_on_click>
	<zone_doc_over>$ButtonDropDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonDropStatus</zone_status>
	<zone_label>$T_Drop...</zone_label>
<!-- end \"zone.$Service..button_drop\" --> </zone>"
	;;
newmooc)
	# *education|*)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_newmooc\">
	<zone_on_click>--page zone.$Service..button_newmooc $Service..button_newmooc.form</zone_on_click>
	<zone_doc_over>$ButtonNewMoocDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonNewMoocStatus</zone_status>
	<zone_label>$T_Mooc...</zone_label>
<!-- end \"zone.$Service..button_newmooc\" --> </zone>"
	;;
managemooc)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_managemooc\">
	<zone_on_click>--page zone.$Service..button_managemooc $Service..button_managemooc.form</zone_on_click>
	<zone_doc_over>$ButtonManageMoocDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonManageMoocStatus</zone_status>
	<zone_label>$T_Managemooc...</zone_label>
<!-- end \"zone.$Service..button_managemooc\" --> </zone>"
	;;
exam)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_exam\">
	<zone_on_click>--page zone.$Service..button_exam $Service..button_exam.form</zone_on_click>
	<zone_doc_over>$ButtonExamDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonExamStatus</zone_status>
	<zone_label>$T_Exam...</zone_label>
<!-- end \"zone.$Service..button_exam\" --> </zone>"
	;;
upload)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_upload\">
	<zone_on_click>--page zone.$Service..button_upload $Service..button_upload.form</zone_on_click>
	<zone_doc_over>$ButtonUploadDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonUploadStatus</zone_status>
	<zone_label>$T_Upload...</zone_label>
<!-- end \"zone.$Service..button_upload\" --> </zone>"
	;;
installarchive)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_installarchive\">
	<zone_on_click>--page zone.$Service..button_installarchive $Service..button_installarchive.form</zone_on_click>
	<zone_doc_over>$ButtonInstallarchiveDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonInstallarchiveStatus</zone_status>
	<zone_label>$T_installarchive...</zone_label>
<!-- end \"zone.$Service..button_installarchive\" --> </zone>"
	;;
upgrade)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_upgrade\">
	<zone_on_click>--page zone.$Service..button_upgrade $Service..button_upgrade.form</zone_on_click>
	<zone_doc_over>$ButtonUpgradeDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonUpgradeStatus</zone_status>
	<zone_label>$T_Upgrade...</zone_label>
<!-- end \"zone.$Service..button_upgrade\" --> </zone>"
	;;
downgrade)
	ServiceMenuContent="$ServiceMenuContent
<zone name=\"zone.$Service..button_downgrade\">
	<zone_on_click>--page zone.$Service..button_downgrade $Service..button_downgrade.form</zone_on_click>
	<zone_doc_over>$ButtonDowngradeDoc</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>$ButtonDowngradeStatus</zone_status>
	<zone_label>$T_Downgrade...</zone_label>
<!-- end \"zone.$Service..button_downgrade\" --> </zone>"
	;;
end)
		ServiceMenuContent="$ServiceMenuContent
<!-- end \"zone.$Service.buttons\" --> </zone>"
	;;
esac
}
#end 
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
DRAW_DETAIL ()
#------------------------------------------------------------------------------
{
LOG_MESSAGE $LINENO -g DRAW_DETAIL $*
#DRAW_DETAIL comment -init|-new_page dd_detail_type comment file_to_create
dd_call="$1-DRAW_DETAIL"
shift
#$1 is -init or -new_page
dd_init_or_newpage="$1"
shift
dd_detail_type="$1"
shift
dd_file_to_create="$*"
SHAPE_XML_FILE $dd_call-$LINENO $dd_init_or_newpage $dd_file_to_create

case "$dd_detail_type" in
-database_menu)

	#TR T_Detailled_database	Detailled information about database : Information detaillee sur la base de donnees
	#TR T_Save	Save : Sauvegarder
	#TR T_Snapshot	Checkpoints : Points de reprise
	#TR T_Restore	Restore : Restaurer
	#TR T_Clone	Clone : Cloner
	#TR T_Copy	Copy : Copier
	#TR T_Reference	Reference : Reference
	#TR T_Delete	Delete : Supprimer
	#TR T_Wipe_out	Wipe out : Effacer
	#TR T_DbUpdate	Update : Mise a jour
	#TR T_EditDatabaseMenu ✅ / ❌ ... : ✅ / ❌ ...
	#LOG_MESSAGE $LINENO -g DRAW_DETAIL $* DatabaseButtonsFullList $DatabaseButtonsFullList ServiceButtons $ServiceButtons
	FILL_DATABASE_MENU header
	for button in $DatabaseButtonsFullList ; do
		case "$DatabaseButtons" in
		*$button*)
			FILL_DATABASE_MENU $button
			;;
		esac
	done
	FILL_DATABASE_MENU end
	if [ ! -z $XmlFile ] ; then
		echo "$DatabaseMenuContent" >> $XmlFile
	else
		echo "$DatabaseMenuContent"
	fi
	;;
-database)
	#TR T_Database_Info	Information about database : Information sur la base de donnees
	DatabaseDetailContent="
<zone name=\"zone.pageback1.zone\">
	<zone_position>zwide</zone_position>
	<zone_html>$PageBack1</zone_html>
<!-- end \"zone.pageback1.zone\" --> </zone>
<zone name=\"zone.$Service.$Database.map\">
	<zone_position>zwide</zone_position>
<zone name=\"zone.$Service.name\">
	<zone_on_click>--page zone.$Service.map $Service.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_position>zleft</zone_position>
	<zone_type>service_name</zone_type>
	<zone_status>$ServiceStatus</zone_status>
	<zone_label><![CDATA[$ServiceImage $Service]]></zone_label>
<!-- end \"zone.$Service.name\" --> </zone>
<zone name=\"zone.$Service.$Database.name\">
	<zone_position>zcenter</zone_position>
	<zone_type>database</zone_type>
	<zone_status>$DbStatus</zone_status>
	<zone_label><![CDATA[$DiskImage $Database]]></zone_label>
<!-- end \"zone.$Service.$Database.name\" --> </zone>
<zone name=\"zone.$Service.$Database.archive\">
	<zone_position>zright</zone_position>
	<zone_type>archive</zone_type>
	<zone_status>$ArchiveStatus</zone_status>
	<zone_label><![CDATA[$TapeImage $ArchiveDate]]></zone_label>
<!-- end \"zone.$Service.$Database.archive\" --> </zone>
<!-- end \"zone.$Service.$Database.map\" --> </zone>
<zone name=\"zone.$Service.$Database.info\">
	<zone_position>zwide</zone_position>
	<zone_type>database_information</zone_type>
	<zone_html><![CDATA[<p>$T_Database_Info $Database $T_on_service $Service<br/>$DbInformation</p>]]></zone_html>
<!-- end \"zone.$Service.$Database.info\" --> </zone>



<zone name=\"zone.$Service.$Database.lastactions_detail\">
	<zone_position>zlastactions</zone_position>
	<zone_type>database_lastactions</zone_type>
	<zone_html><![CDATA[<p>$DatabaseLastActions</p>]]></zone_html>
<!-- end \"zone.$Service.$Database.lastactions_detail\" --> </zone>



<zone name=\"zone.$Service.$Database.log_tail_map\">
	<zone_position>zlogtail</zone_position>
	<zone_type>service_log</zone_type>
	<zone_window>zone-$Service.$Database.log_tail</zone_window>
	<zone_on_click>--page zone.$Service.$Database.log_tail $Service.log_detail.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_status>$ServiceLogTailStatus</zone_status>
	<zone_html><![CDATA[<p>$ServiceLogTitle $T_New_tab $ServiceLogTail </p>]]></zone_html>
<!-- end \"zone.$Service.$Database.log_tail_map\" --> </zone>
<zone name=\"zone.pageback2.zone\">
	<zone_position>zwide</zone_position>
	<zone_html>$PageBack2</zone_html>
<!-- end \"zone.pageback2.zone\" --> </zone>
<!-- end \"zone.$Service.$Database.detail\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$DatabaseDetailContent" >> $XmlFile
	else
		echo "$DatabaseDetailContent"
	fi
	;;
-database_lastactions)
	DatabaseLastActionsDetailContent="
<zone name=\"zone.$Service.$Database.lastactions_detail\">
	<zone_type>database_lastactions</zone_type>
	<zone_html><![CDATA[<hr/><p>$DatabaseLastActions</p><hr/>]]></zone_html>
<!-- end \"zone.$Service.$Database.lastactions_detail\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$DatabaseLastActionsDetailContent" >> $XmlFile
	else
		echo "$DatabaseLastActionsDetailContent"
	fi
	echo "DRAW_DETAIL $XmlFile on `date +'%Hh%Mm%Ss:%3N'` mode $ServerMode $LINENO" >> $DrawingsLog
	;;
-service_menu)
	#TR T_Detailled_service	Detailled information about service : Information detaillee sur le service
	#TR T_Renew Renew : Prolonger
	#TR T_Start Start : Demarrer
	#TR T_Stop Stop : Arreter
	#TR T_Restart Restart : Redemarrer
	#TR T_New_case New case : Cas
	#TR T_Company Company : Societe
	#TR T_Drop Drop : Supprimer
	#TR T_Mooc New course : Cours
	#TR T_Managemooc Manage courses : Gerer les cours
	#TR T_Exam Exam sessions : Examens
	#TR T_Upload	Upload : Telecharger
	#TR T_installarchive	Archives : Archives
	#TR T_Downgrade Downgrade : Retablir
	#TR T_Upgrade	Reinstall : Reinstaller
	#TR T_EditServiceMenu ✅ / ❌ ... : ✅ / ❌ ...
#ActionList="button_editservicemenu button_renew button_start button_stop button_restart button_newcase button_company button_drop button_newmooc button_managemooc button_exam button_upload button_installarchive button_upgrade button_editdatabasemenu button_save button_snapshot button_restore button_clone button_copy button_reference button_delete button_wipe_out button_dbupdate"
# button_downgrade
	#LOG_MESSAGE $LINENO -g DRAW_DETAIL $* ServiceButtonsFullList $ServiceButtonsFullList ServiceButtons $ServiceButtons
	FILL_SERVICE_MENU header
	for button in $ServiceButtonsFullList ; do
		case "$ServiceButtons" in
		*$button*)
			FILL_SERVICE_MENU $button
			;;
		esac
	done
	FILL_SERVICE_MENU end
	if [ ! -z $XmlFile ] ; then
		echo "$ServiceMenuContent" >> $XmlFile
	else
		echo "$ServiceMenuContent"
	fi
	;;
-service)
	ServiceDetailContent="
<zone name=\"zone.pageback1.zone\">
	<zone_position>zwide</zone_position>
	<zone_html>$PageBack1</zone_html>
<!-- end \"zone.pageback1.zone\" --> </zone>
<zone name=\"zone.$Service.map\">
	<zone_position>zwide</zone_position>
<zone name=\"zone.$Service.name\">
	<zone_on_click>--page zone.$Service.map $Service.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_type>service_name</zone_type>
	<zone_status>$ServiceStatus</zone_status>
	<zone_label><![CDATA[$ServiceImage $Service]]></zone_label>
<!-- end \"zone.$Service.name\" --> </zone>
<zone name=\"zone.$Service.running\">
	<zone_type>service_running</zone_type>
	<zone_status>$ServiceRunningStatus</zone_status>
	<zone_label>$ServiceRunning - role $ServiceRole</zone_label>
<!-- end \"zone.$Service.running\" --> </zone>
<zone name=\"zone.$Service.version\">
	<zone_type>service_version</zone_type>
	<zone_status>$ServiceStatus</zone_status>
	<zone_label>$ServiceErpName - $ServiceVersion</zone_label>
<!-- end \"zone.$Service.version\" --> </zone>
<zone name=\"zone.$Service.url\">
	<zone_type>service_information</zone_type>
	<zone_status>$ServiceRunningStatus</zone_status>
	<zone_html>$ServiceLoginUrl</zone_html>
<!-- end \"zone.$Service.url\" --> </zone>
<zone name=\"zone.$Service.last_login\">
	<zone_type>service_last_login</zone_type>
	<zone_status>$ServiceRunningStatus</zone_status>
	<zone_html>$ServiceLastLogin</zone_html>
<!-- end \"zone.$Service.last_login\" --> </zone>
<zone name=\"zone.$Service.documentation\">
	<zone_type>service_information</zone_type>
	<zone_status>$ServiceRunningStatus</zone_status>
	<zone_html><![CDATA[<p>$ServiceResume</p>]]></zone_html>
<!-- end \"zone.$Service.documentation\" --> </zone>
<!-- end \"zone.$Service.map\" --> </zone>
<zone name=\"zone.$Service.configuration\">
	<zone_position>zinfo</zone_position>
	<zone_type>service_configuration</zone_type>
	<zone_window>zone-$Service.configuration.map</zone_window>
	<zone_on_click>--page zone.$Service.configuration $Service.configuration_detail.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_html><![CDATA[<p>$ServiceInformationTitle $T_New_tab $ServiceInformation </p>]]></zone_html>
<!-- end \"zone.$Service.configuration\" --> </zone>
<zone name=\"zone.$Service.log_tail_map\">
	<zone_position>zlogtail</zone_position>
	<zone_type>service_log</zone_type>
	<zone_window>zone-$Service.log_tail.map</zone_window>
	<zone_on_click>--page zone.$Service.log_tail_map $Service.log_detail.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_status>$ServiceLogTailStatus</zone_status>
	<zone_html><![CDATA[<p>$ServiceLogTitle $T_New_tab $ServiceLogTail </p>]]></zone_html>
<!-- end \"zone.$Service.log_tail_map\" --> </zone>
<zone name=\"zone.pageback2.zone\">
	<zone_position>zwide</zone_position>
	<zone_html>$PageBack2</zone_html>
<!-- end \"zone.pageback2.zone\" --> </zone>
<!-- end \"zone.$Service.detail\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$ServiceDetailContent" >> $XmlFile
	else
		echo "$ServiceDetailContent"
	fi
	;;
-configuration)
	ConfigurationDetailContent="
<zone name=\"zone.$Service.configuration_detail\">
	<zone_type>service_configuration</zone_type>
	<zone_html><![CDATA[<hr/><p>$ServiceInformationTitle  <br/> $ServiceInformation</p><hr/>]]></zone_html>
<!-- end \"zone.$Service.configuration_detail\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$ConfigurationDetailContent" >> $XmlFile
	else
		echo "$ConfigurationDetailContent"
	fi
	echo "DRAW_DETAIL $XmlFile on `date +'%Hh%Mm%Ss:%3N'` mode $ServerMode $LINENO" >> $DrawingsLog
	;;
-instructions)
	InstructionsDetailContent="
<zone name=\"zone.$Service.instructions_detail\">
	<zone_type>service_instructions</zone_type>
	<zone_html><![CDATA[<hr/><p>$ServiceInstructionsTitle <br/> $ServiceInstructions</p><hr/>]]></zone_html>
<!-- end \"zone.$Service.instructions_detail\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$InstructionsDetailContent" >> $XmlFile
	else
		echo "$InstructionsDetailContent"
	fi
	echo "DRAW_DETAIL $XmlFile on `date +'%Hh%Mm%Ss:%3N'` mode $ServerMode $LINENO" >> $DrawingsLog
	;;
-lastactions)
	LastActionsDetailContent="
<zone name=\"zone.$Service.lastactions_detail\">
	<zone_type>service_lastactions</zone_type>
	<zone_html><![CDATA[<hr/><p>$ServiceLastActionsTitle <br/> $ServiceLastActions</p><hr/>]]></zone_html>
<!-- end \"zone.$Service.lastactions_detail\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$LastActionsDetailContent" >> $XmlFile
	else
		echo "$LastActionsDetailContent"
	fi
	echo "DRAW_DETAIL $XmlFile on `date +'%Hh%Mm%Ss:%3N'` mode $ServerMode $LINENO" >> $DrawingsLog
	;;
-anomalies)
	AnomaliesDetailContent="
<zone name=\"zone.$Service.anomalies_detail\">
	<zone_type>service_anomalies</zone_type>
	<zone_html><![CDATA[<hr/><p>$ServiceLogErrorsTitle <br/> $ServiceLogErrors</p><hr/>]]></zone_html>
<!-- end \"zone.$Service.anomalies_detail\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$AnomaliesDetailContent" >> $XmlFile
	else
		echo "$LastActionsDetailContent"
	fi
	echo "DRAW_DETAIL $XmlFile on `date +'%Hh%Mm%Ss:%3N'` mode $ServerMode $LINENO" >> $DrawingsLog
	;;
-log)
	#disabled in service collected data
	LogDetailContent="
<zone name=\"zone.$Service.log_detail\">
	<zone_type>service_log</zone_type>
	<zone_html><![CDATA[<hr/><p>$ServiceLogTitle <br/> $ServiceLogDetail</p><hr/>]]></zone_html>
<!-- end \"zone.$Service.log_detail\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$LogDetailContent" >> $XmlFile
	else
		echo "$LogDetailContent"
	fi
	echo "DRAW_DETAIL $XmlFile on `date +'%Hh%Mm%Ss:%3N'` mode $ServerMode $LINENO" >> $DrawingsLog
	;;
-contract)	
	ContractDetailContent="
<zone name=\"zone.contract\">
	<zone_type>contract</zone_type>
	<zone_html><![CDATA[<hr/><p>$ContractZoneContent</p><hr/>]]></zone_html>
<!-- end \"zone.contract\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$ContractDetailContent" >> $XmlFile
	else
		echo "$ContractDetailContent"
	fi
	;;
-admin_guide)	
	Admin_guideDetailContent="
<zone name=\"zone.admin_guide\">
	<zone_type>admin_guide</zone_type>
	<zone_html><![CDATA[<hr/><p>$AdminGuideZoneContent</p><hr/>]]></zone_html>
<!-- end \"zone.admin_guide\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$Admin_guideDetailContent" >> $XmlFile
	else
		echo "$Admin_guideDetailContent"
	fi
	;;
-open_service)	
	Open_serviceDetailContent="
<zone name=\"zone.open_service\">
        <zone_refresh><![CDATA[<meta http-equiv=\"Refresh\" content=\"600\" />]]></zone_refresh>
	<zone_type>manage_service</zone_type>
	<zone_html><![CDATA[<hr/>$OpenServiceZoneContent<hr/>]]></zone_html>
<!-- end \"zone.open_service\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$Open_serviceDetailContent" >> $XmlFile
	else
		echo "$Open_serviceDetailContent"
	fi
	;;
-close_service)	
	Close_serviceDetailContent="
<zone name=\"zone.close_service\">
        <zone_refresh><![CDATA[<meta http-equiv=\"Refresh\" content=\"600\" />]]></zone_refresh>
	<zone_type>manage_service</zone_type>
	<zone_html><![CDATA[<hr/>$CloseServiceZoneContent<hr/>]]></zone_html>
<!-- end \"zone.close_service\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$Close_serviceDetailContent" >> $XmlFile
	else
		echo "$Close_serviceDetailContent"
	fi
	;;
-general_log)	
	GeneralLogDetailContent="
<zone name=\"zone.log_detail\">
	<zone_type>general_log</zone_type>
	<zone_html><![CDATA[<hr/>$LogTitle $LogDetail<hr/>]]></zone_html>
<!-- end \"zone.log_detail\" --> </zone>"
	if [ ! -z "$XmlFile" ] ; then
		echo "$GeneralLogDetailContent" >> $XmlFile
	else
		echo "$GeneralLogDetailContent"
	fi
	;;
-default)
	#TR T_data_collect Collecting detailled information on the server : Collecte des informations detaillees sur le serveur
	#TR T_Search Searching : Recherche
	#TR T_available available : des actions
	#TR T_actions actions : disponibles
	#TR T_Analysing Analysing server status : Analyse en cours du serveur
	#TR T_Wait Please wait a little more : Merci d'attendre encore quelques secondes


	DefaultDetailContent="<zone name=\"zone.no_service.detail\">
	<zone_title><![CDATA[<title>$T_data_collect</title>]]></zone_title>
	<zone_type>service_detail</zone_type>
<zone name=\"zone.no_service.buttons\">
	<zone_position>zbuttons</zone_position>
<zone name=\"zone.no_service.button\">
	<zone_doc_over>Action</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>unknown</zone_status>
	<zone_label>$T_Search</zone_label>
<!-- end \"zone.no_service.button\" --> </zone>
<zone name=\"zone.no_service.button\">
	<zone_doc_over>Action</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>unknown</zone_status>
	<zone_label>$T_available</zone_label>
<!-- end \"zone.no_service.button\" --> </zone>
<zone name=\"zone.no_service.button\">
	<zone_doc_over>Action</zone_doc_over>
	<zone_position>zbutton</zone_position>
	<zone_type>button</zone_type>
	<zone_status>unknown</zone_status>
	<zone_label>$T_actions...</zone_label>
<!-- end \"zone.no_service.button\" --> </zone>
<!-- end \"zone.no_service.buttons\" --> </zone>
<zone name=\"zone.pageback1.zone\">
	<zone_position>zwide</zone_position>
	<zone_html><![CDATA[<hr/>$BackImage]]></zone_html>
<!-- end \"zone.pageback1.zone\" --> </zone>
<zone name=\"zone.no_service.map\">
	<zone_position>zwide</zone_position>
<zone name=\"zone.no_service.name\">
	<zone_type>service_name</zone_type>
	<zone_status>unknown</zone_status>
	<zone_label><![CDATA[<img src=\"images/disk.png\" alt=\"S \"/> $T_Analysing ...]]></zone_label>
<!-- end \"zone.no_service.name\" --> </zone>
<zone name=\"zone.no_service.running\">
	<zone_type>service_running</zone_type>
	<zone_status>unknown</zone_status>
	<zone_label></zone_label>
<!-- end \"zone.no_service.running\" --> </zone>
<zone name=\"zone.no_service.version\">
	<zone_type>service_version</zone_type>
	<zone_status>unknown</zone_status>
	<zone_label>$T_data_collect. $T_Wait....</zone_label>
<!-- end \"zone.log.zone\" --> </zone>
<!-- end \"zone.no_service.map\" --> </zone>
<zone name=\"zone.pageback2.zone\">
	<zone_position>zwide</zone_position>
	<zone_html><![CDATA[$BackImage<hr/>]]></zone_html>
<!-- end \"zone.pageback2.zone\" --> </zone>
<!-- end \"zone.no_service.detail\" --> </zone>"
	if [ ! -z $XmlFile ] ; then
		echo "$DefaultDetailContent" >> $XmlFile
	else
		echo "$DefaultDetailContent"
	fi
	;;
esac
case "$1" in
-new_page)
	SHAPE_XML_FILE $dd_call-$LINENO -end_page $dd_file_to_create
	;;
esac
}
# end DRAW_DETAIL
#------------------------------------------------------------------------------
DRAW_MAP ()
#------------------------------------------------------------------------------
{
#LOG_MESSAGE $LINENO -g DRAW_MAP $*
SHAPE_XML_FILE DRAW_MAP-$LINENO $1 $4 $3
map_type="$2"
map_file="$3"
case "$map_type" in
-anomalies)
	AnomaliesMapContent="
<zone name=\"zone.$Service.anomalies_map\">
	<zone_window>zone-$Service-anomalies_detail</zone_window>
	<zone_on_click>--page zone.$Service.anomalies_detail $Service.anomalies_detail.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_position>zanomalies</zone_position>
	<zone_type>service_anomalies</zone_type>
	<zone_html><![CDATA[<p>$ServiceLogErrorsTitle $T_New_tab $ServiceLogErrors</p>]]></zone_html>
<!-- end \"zone.$Service.anomalies_map\" --> </zone>"
	echo "$AnomaliesMapContent" >> $map_file
	;;
-database)
	DatabaseMapContent="
<zone name=\"zone.$Service.$Database.map\">
	<zone_on_click>--page zone.$Service.$Database.map $Service.$Database.detail.draw</zone_on_click>
	<zone_doc_over>$DbDoc. $ArchiveDoc</zone_doc_over>
	<zone_position>zdatabase</zone_position>
<zone name=\"zone.$Service.$Database.name\">
	<zone_position>zcenter</zone_position>
	<zone_type>database</zone_type>
	<zone_status>$DbStatus</zone_status>
	<zone_label><![CDATA[$DiskImage $Database]]></zone_label>
<!-- end \"zone.$Service.$CommentDatabase.name\" --> </zone>
<zone name=\"zone.$Service.$Database.archive\">
	<zone_position>zright</zone_position>
	<zone_type>archive</zone_type>
	<zone_status>$ArchiveStatus</zone_status>
	<zone_label><![CDATA[$TapeImage $ArchiveDate]]></zone_label>
<!-- end \"zone.$Service.$Database.archive\" --> </zone>
<!-- end \"zone.$Service.$Database.map\" --> </zone>"
	echo "$DatabaseMapContent" >> $map_file
	;;
-database_lastactions)
	DatabaseLastActionsMapContent="
<zone name=\"zone.$Service.$Database.lastactions_map\">
	<zone_window>zone-$Service-$Database-lastactions_detail</zone_window>
	<zone_on_click>--page zone.$Service.$Database.lastactions_detail $Service.$Database.lastactions_detail.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_position>zlastactions</zone_position>
	<zone_type>database_lastactions</zone_type>
	<zone_html><![CDATA[<p>$DatabaseLastActionsTitle $DatabaseLastActions</p>]]></zone_html>
<!-- end \"zone.$Service.$Database.lastactions_map\" --> </zone>"
	echo "$DatabaseLastActionsMapContent" >> $map_file
	;;
-general_log)
	#TR T_Server_log Server Log : Log general du serveur
	GeneralLogMapContent="
<zone name=\"zone.generallog.zone\">
	<zone_menu><![CDATA[<a href=\"index.php#zone.log_tail_map\"><div class=\"menu_element\"><div class=\"$LogTailStatus\">Log</div></div></a>]]></zone_menu>
	<zone_position>zlog</zone_position>
<zone name=\"zone.log_tail_map\">
	<zone_window>zone-general-log_detail</zone_window>
	<zone_on_click>--page zone.log_tail_map log_detail.draw</zone_on_click>
	<zone_doc_over>$T_Server_log</zone_doc_over>
	<zone_type>general_log</zone_type>
	<zone_status>$LogTailStatus</zone_status>
	<zone_html><![CDATA[<p>$LogTitle $T_New_tab $LogTail</p>]]></zone_html>
<!-- end \"zone.log_tail_map\" --> </zone>
<!-- end \"zone.generallog.zone\" --> </zone>"
	echo "$GeneralLogMapContent" >> $map_file
	;;
-instructions)
	InstructionsMapContent="
<zone name=\"zone.$Service.instructions_map\">
	<zone_window>zone-$Service-instructions_detail</zone_window>
	<zone_on_click>--page zone.$Service.instructions_detail $Service.instructions_detail.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_position>zinstructions</zone_position>
	<zone_type>service_instructions</zone_type>
	<zone_html><![CDATA[<p>$ServiceInstructionsTitle $T_New_tab $ServiceInstructions</p>]]></zone_html>
<!-- end \"zone.$Service.instructions_map\" --> </zone>"
	echo "$InstructionsMapContent" >> $map_file
	;;
-lastactions)
	LastActionsMapContent="
<zone name=\"zone.$Service.lastactions_map\">
	<zone_window>zone-$Service-lastactions_detail</zone_window>
	<zone_on_click>--page zone.$Service.lastactions_detail $Service.lastactions_detail.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_position>zlastactions</zone_position>
	<zone_type>service_lastactions</zone_type>
	<zone_html><![CDATA[<p>$ServiceLastActionsTitle $T_New_tab $ServiceLastActions</p>]]></zone_html>
<!-- end \"zone.$Service.lastactions_map\" --> </zone>"
	echo "$LastActionsMapContent" >> $map_file
	;;
-log)
	LogMapContent="
<zone name=\"zone.$Service.log_detail\">
	<zone_window>zone-$Service-log_detail</zone_window>
	<zone_on_click>--page zone.$Service.log_detail $Service.log_detail.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_position>zlogtail</zone_position>
	<zone_type>service_log</zone_type>
	<zone_status>$ServiceLogTailStatus</zone_status>
	<zone_html><![CDATA[<p>$ServiceLogTitle $T_New_tab $ServiceLogTail </p>]]></zone_html>
<!-- end \"zone.$Service.log_detail\" --> </zone>"
	echo "$LogMapContent" >> $map_file
	;;
-mooc)
	MoocMapContent="
<zone name=\"zone.mooc.zone\">
	<zone_position>zwide</zone_position>
	<zone_html>$MoocZoneContent</zone_html>
<!-- end \"zone.mooc.zone\" --> </zone>"
	echo "$MoocMapContent" >> $map_file
	;;
-page_back_foot)
	PageBackContent="
<zone name=\"zone.pageback2.zone\">
	<zone_position>zwide</zone_position>
	<zone_html>$PageBack2</zone_html>
<!-- end \"zone.pageback2.zone\" --> </zone>"
	echo "$PageBackContent" >> $map_file
	;;
-page_back_head)
	PageBackContent="
<zone name=\"zone.pageback1.zone\">
	<zone_position>zwide</zone_position>
	<zone_html>$PageBack1</zone_html>
<!-- end \"zone.pageback1.zone\" --> </zone>"
	echo "$PageBackContent" >> $map_file
	;;
-page_top)
	PageTopContent="
<zone name=\"zone.pagetop.zone\">
	<zone_position>zwide</zone_position>
	<zone_html>$PageTop</zone_html>
<!-- end \"zone.pagetop.zone\" --> </zone>"
	echo "$PageTopContent" >> $map_file
	;;
-service)
	ServiceMapContent="
<zone name=\"zone.$Service.map\">
	<zone_position>zleft</zone_position>
<zone name=\"zone.$Service.name\">
	<zone_on_click>--page zone.$Service.map $Service.detail.draw</zone_on_click>
	<zone_doc_over>$ServiceDoc</zone_doc_over>
	<zone_type>service_name</zone_type>
	<zone_status>$ServiceStatus</zone_status>
	<zone_label><![CDATA[$ServiceImage $Service]]></zone_label>
<!-- end \"zone.$Service.name\" --> </zone>
<zone name=\"zone.$Service.running\">
	<zone_type>service_running</zone_type>
	<zone_status>$ServiceRunningStatus</zone_status>
	<zone_label>$ServiceRunning - role $ServiceRole</zone_label>
<!-- end \"zone.$Service.running\" --> </zone>
<zone name=\"zone.$Service.version\">
	<zone_type>service_version</zone_type>
	<zone_status>$ServiceStatus</zone_status>
	<zone_label>$ServiceErpName - $ServiceVersion</zone_label>
<!-- end \"zone.$Service.version.zone\" --> </zone>
<zone name=\"zone.$Service.url\">
	<zone_type>service_information</zone_type>
	<zone_status>$ServiceRunningStatus</zone_status>
	<zone_html>$ServiceLoginUrl</zone_html>
<!-- end \"zone.$Service.url\" --> </zone>
<zone name=\"zone.$Service.last_login\">
	<zone_type>service_last_login</zone_type>
	<zone_status>$ServiceRunningStatus</zone_status>
	<zone_html>$ServiceLastLogin</zone_html>
<!-- end \"zone.$Service.last_login\" --> </zone>
<zone name=\"zone.$Service.documentation\">
	<zone_type>service_information</zone_type>
	<zone_status>$ServiceRunningStatus</zone_status>
	<zone_html><![CDATA[<p>$ServiceResume</p>]]></zone_html>
<!-- end \"zone.$Service.documentation\" --> </zone>
<!-- end \"zone.$Service.map\" --> </zone>"
	echo "$ServiceMapContent" >> $map_file
	;;
-system)
	SystemMapContent="
<zone name=\"zone.system.zone\">
	<zone_position>zwide</zone_position>
	<zone_html>$SystemZoneContent</zone_html>
<!-- end \"zone.system.zone\" --> </zone>"
	echo "$SystemMapContent" >> $map_file
	;;
esac
case "$1" in
-new_page)
	SHAPE_XML_FILE DRAW_MAP-$LINENO -end_page $4 $3
	;;
esac
}
#end DRAW_MAP
#------------------------------------------------------------------------------
DRAW_GLOBAL_LOG_ZONE ()
#------------------------------------------------------------------------------
{
#LOG_MESSAGE $LINENO -g DRAW_GLOBAL_LOG_ZONE $*
SHAPE_XML_FILE DRAW_GLOBAL_LOG_ZONE-$LINENO $1 $3 $2
dglz_page_draw="$2"
GET_DATA $LINENO general_log
DRAW_MAP -continue -general_log $dglz_page_draw
DRAW_MAP -continue -page_top $dglz_page_draw
#if [ "${RefreshMode}" = "All" ] || echo " $DisplayedPages" | grep -q " log_detail\." ; then
DRAW_DETAIL DRAW_GLOBAL_LOG_ZONE_$LINENO -init -general_log log_detail $DrawingCurrentDirectory/log_detail.draw
	# creer ServiceLogTailStatus ServiceLogTail Service.log_detail.draw
#fi
case "$1" in
#------------------------------------------------------------------------------
-new_page)
#------------------------------------------------------------------------------
	SHAPE_XML_FILE DRAW_GLOBAL_LOG_ZONE-$LINENO -end_page $3 $2
	;;
esac
}
#end DRAW_GLOBAL_LOG_ZONE
#------------------------------------------------------------------------------
DRAW_DASHBOARD_MENU ()
#------------------------------------------------------------------------------
{
#LOG_MESSAGE $LINENO -g DRAW_DASHBOARD_MENU $*
#TR T_Service_List	Service list : Liste des services
menu_draw="$1"
echo "" > $menu_draw
for Service in $ServiceList ; do
	GET_DATA $LINENO dashboard_menu $Service
	echo "<a href=\"index.php?action=--page zone.${Service}.map ${Service}.draw\" title=\"$ServiceDoc\"><div class=\"menu_element\"><div class=\"$ServiceStatus\">$Service ($DatabaseNumber)</div></div></a>" >> $menu_draw
done
}
#end DRAW_DASHBOARD_MENU
#------------------------------------------------------------------------------
DRAW_SERVICE_ALL_DETAILS ()
#------------------------------------------------------------------------------
{
	dasd_call="$1-DRAW_SERVICE_ALL_DETAILS"
	LOG_MESSAGE $LINENO -g DRAW_SERVICE_ALL_DETAILS $* $Service $DatabaseList

	for Database in $DatabaseList ; do
		GET_DATA $LINENO database $Service $Database
		if [ ${RefreshMode} = "All" ] || echo " $DisplayedPages" | grep -q " $Service.$Database\." ; then
			DRAW_DETAIL $dasd_call-$LINENO -init -database_menu $Service.$Database.menu $DrawingCurrentDirectory/$Service.$Database.menu.draw
			DRAW_DETAIL $dasd_call-$LINENO -init -database $Service.$Database.info $DrawingCurrentDirectory/$Service.$Database.info.draw
			cat $DrawingCurrentDirectory/$Service.$Database.menu.draw > $DrawingCurrentDirectory/$Service.$Database.detail.draw
			cat $DrawingCurrentDirectory/$Service.$Database.info.draw >> $DrawingCurrentDirectory/$Service.$Database.detail.draw
			#echo "Concat to $DrawingCurrentDirectory/$Service.$Database.detail.draw on $Date mode $ServerMode parameters $dasd_call-$LINENO" >> $DrawingsLog
			#echo "$ServiceLogDetail ServiceLogDetail" | tail >> $DrawingsLog
		fi
	done
	if [ ${RefreshMode} = "All" ] || echo " $DisplayedPages" | grep -q " $Service\." ; then
		DRAW_DETAIL $dasd_call-$LINENO -init -log zone.log $DrawingCurrentDirectory/$Service.log_detail.draw
		DRAW_DETAIL $dasd_call-$LINENO -init -instructions zone.instructions $DrawingCurrentDirectory/$Service.instructions_detail.draw
		DRAW_DETAIL $dasd_call-$LINENO -init -lastactions zone.lastactions $DrawingCurrentDirectory/$Service.lastactions_detail.draw
		DRAW_DETAIL $dasd_call-$LINENO -init -anomalies zone.anomalies $DrawingCurrentDirectory/$Service.anomalies_detail.draw
		DRAW_DETAIL $dasd_call-$LINENO -init -configuration zone.configuration $DrawingCurrentDirectory/$Service.configuration_detail.draw
		echo "Draw $DrawingCurrentDirectory/$Service.log_detail.draw on `date +'%Hh%Mm%Ss:%3N'` mode $ServerMode parameters $dasd_call-$LINENO" >> $DrawingsLog
	#	# creer ServiceLogTailStatus ServiceLogTail Service.log_detail.draw
	fi
	if [ ${RefreshMode} = "All" ] || echo " $DisplayedPages" | grep -q " $Service\." ; then
		DRAW_DETAIL $dasd_call-$LINENO -init -service_menu $Service.menu $DrawingCurrentDirectory/$Service.menu.draw
		DRAW_DETAIL $dasd_call-$LINENO -init -service $Service.info $DrawingCurrentDirectory/$Service.info.draw
		cat $DrawingCurrentDirectory/$Service.menu.draw > $DrawingCurrentDirectory/$Service.detail.draw
		cat $DrawingCurrentDirectory/$Service.info.draw >> $DrawingCurrentDirectory/$Service.detail.draw
		echo "Concat to $DrawingCurrentDirectory/$Service.detail.draw on `date +'%Hh%Mm%Ss:%3N'` mode $ServerMode parameters $dsz_call-$LINENO" >> $DrawingsLog
	fi
}
#------------------------------------------------------------------------------
DRAW_SERVICE_ZONE ()
#------------------------------------------------------------------------------
{
#LOG_MESSAGE $LINENO -g DRAW_SERVICE_ZONE $* $Service $DatabaseList
#service pages are refreshed
#DRAW_SERVICE_ZONE comment -new_page|-continue comment target_file
#TR T_Service_Status_Title	Service status : Etat des services
dsz_call="$1-DRAW_SERVICE_ZONE"
shift
dsz_option=$1
dsz_comment="$2"
dsz_page_draw="$3"
SHAPE_XML_FILE $dsz_call-$LINENO $dsz_option $dsz_comment $dsz_page_draw
case "$dsz_option" in
-title)
	echo "
<zone name=\"zone.service_status.zone\">
	<zone_position>zwide</zone_position>
	<zone_html><![CDATA[<div id=\"service_status\" class=\"dashboard_title\">$T_Service_Status_Title</div>]]></zone_html>
<!-- end \"zone.service_status.zone\" --> </zone>
" >> $dsz_page_draw
	;;
-new_page|-continue)
	case "$dsz_option" in
	#------------------------------------------------------------------------------
	-new_page)
	#------------------------------------------------------------------------------
		DRAW_MAP -continue -page_back_head $dsz_page_draw
		;;
	esac
	echo "
<zone name=\"zone.$Service.zone\">
	<zone_position>zwide</zone_position>
" >> $dsz_page_draw

	DRAW_MAP -continue -service $dsz_page_draw
	echo "
<zone name=\"zone.$Service.databases.zone\">
	<zone_position>zdatabases</zone_position>
" >> $dsz_page_draw
	for Database in $DatabaseList ; do
		#LOG_MESSAGE $LINENO -g DRAW_SERVICE_ZONE Database $Database
		GET_DATA $LINENO database $Service $Database
		DRAW_MAP -continue -database $dsz_page_draw
	done
	echo "
<!-- end \"zone.$Service.databases.zone\" --> </zone>
" >> $dsz_page_draw
	case "$dsz_option" in
	#------------------------------------------------------------------------------
	-new_page)
	#------------------------------------------------------------------------------
		DRAW_MAP -continue -instructions $dsz_page_draw
		DRAW_MAP -continue -lastactions $dsz_page_draw
		DRAW_MAP -continue -anomalies $dsz_page_draw
		DRAW_MAP -continue -log $dsz_page_draw
		echo "
<!-- end \"zone.$Service.zone\" --> </zone>
" >> $dsz_page_draw
		DRAW_MAP -continue -page_back_foot $dsz_page_draw
		SHAPE_XML_FILE $dsz_call-$LINENO -end_page $dsz_page_draw $dsz_comment
		;;
	#------------------------------------------------------------------------------
	-continue)
	#------------------------------------------------------------------------------
		DRAW_MAP -continue -page_top $dsz_page_draw
		echo "
<!-- end \"zone.$Service.zone\" --> </zone>
" >> $dsz_page_draw
		;;
	esac
	;;
esac
}
#end DRAW_SERVICE_ZONE
#------------------------------------------------------------------------------	
DRAW_PAGE_ELEMENTS ()
#------------------------------------------------------------------------------
{
case "$ServerContractMode" in
show)
	GET_DATA $LINENO contract
	DRAW_DETAIL DRAW_CONTRACT_ZONE_$LINENO -init -contract contract $DrawingCurrentDirectory/contract.draw
	;;
esac
case "$AdminGuideMode" in
show)
	GET_DATA $LINENO admin_guide
	DRAW_DETAIL DRAW_ADMIN_GUIDE_ZONE_$LINENO -init -admin_guide admin_guide $DrawingCurrentDirectory/admin_guide.draw
	;;
esac
case "$OpenServiceMode" in
show)
	GET_DATA $LINENO openservice
	DRAW_DETAIL DRAW_OPEN_SERVICE_ZONE_$LINENO -init -open_service open_service $DrawingCurrentDirectory/open_service.draw
	;;
esac
case "$CloseServiceMode" in
show)
	GET_DATA $LINENO closeservice
	DRAW_DETAIL DRAW_CLOSE_SERVICE_ZONE_$LINENO -init -close_service close_service $DrawingCurrentDirectory/close_service.draw
	;;
esac

case "$SystemInfoMode" in
show)
	GET_DATA $LINENO system
	DRAW_MAP -continue -system $DrawingCurrentDirectory/page.draw
	;;
esac
case "$MoocInfoMode" in
show)
	GET_DATA $LINENO mooc
	DRAW_MAP -continue -mooc $DrawingCurrentDirectory/page.draw
	;;
esac
}
#------------------------------------------------------------------------------
DRAW_MAIN_PAGE ()
#------------------------------------------------------------------------------
{
LOG_MESSAGE $LINENO -g  DRAW_MAIN_PAGE $DrawingCurrentDirectory/page.draw $*
dmp_call="DRAW_MAIN_PAGE"
SHAPE_XML_FILE $dmp_call-$LINENO -new_page $DrawingCurrentDirectory/page.draw zone.page
GET_DATA $LINENO page
DRAW_DASHBOARD_MENU $Drawings/menu.draw
DRAW_PAGE_ELEMENTS
case "$ServiceDetailsMode" in
show)
	DRAW_SERVICE_ZONE $LINENO -title page.draw $DrawingCurrentDirectory/page.draw
	for Service in $ServiceList ; do
		GET_DATA $LINENO service $Service
		DRAW_SERVICE_ZONE $LINENO -continue page.draw $DrawingCurrentDirectory/page.draw
	done
	;;
hide)
	;;
esac
LANGUAGE $LINENO $Language
for Service in $ServiceList ; do
	LOG_MESSAGE $LINENO -g DRAW_MAIN_PAGE Service $Service
	GET_DATA $LINENO service $Service
	DRAW_SERVICE_ZONE $LINENO -new_page zone.page $DrawingCurrentDirectory/$Service.draw
	DRAW_SERVICE_ALL_DETAILS $LINENO
done
case "$ServerLogMode" in
show)
	DRAW_GLOBAL_LOG_ZONE -continue $DrawingCurrentDirectory/page.draw
	;;
esac
SHAPE_XML_FILE $dmp_call-$LINENO -end_page zone.page $DrawingCurrentDirectory/page.draw
}
#end DRAW_MAIN_PAGE
#------------------------------------------------------------------------------
DRAW_MAIN_PAGE_NOW ()
#------------------------------------------------------------------------------
{
LOG_MESSAGE $LINENO -g  DRAW_MAIN_PAGE_NOW $*

if [ ! -z "$1" ] ; then
	ServiceList="$1"
	GET_DATA $LINENO service $ServiceList
	DRAW_SERVICE_ZONE $LINENO -new_page zone.page $DrawingCurrentDirectory/$Service.draw
	LANGUAGE $LINENO $Language
else
	SHAPE_XML_FILE DRAW_MAIN_PAGE_NOW-$LINENO -new_page zone.page $DrawingCurrentDirectory/page.draw 
	GET_DATA $LINENO page
	DRAW_DASHBOARD_MENU $Drawings/menu.draw
	DRAW_PAGE_ELEMENTS

	case "$ServiceDetailsMode" in
	show)
		DRAW_SERVICE_ZONE $LINENO -title page.draw $DrawingCurrentDirectory/page.draw
		for Service in $ServiceList ; do
			#LOG_MESSAGE $LINENO -g DRAW_MAIN_PAGE_NOW Service $Service
			GET_DATA $LINENO service
			DRAW_SERVICE_ZONE $LINENO -continue page $DrawingCurrentDirectory/page.draw
		done
		;;
	esac

	LANGUAGE $LINENO $Language
	case "$ServerLogMode" in
	show)
		DRAW_GLOBAL_LOG_ZONE -continue $DrawingCurrentDirectory/page.draw
		;;
	esac
	SHAPE_XML_FILE DRAW_MAIN_PAGE_NOW-$LINENO -end_page zone.page $DrawingCurrentDirectory/page.draw
fi
}
#end DRAW_MAIN_PAGE_NOW
#------------------------------------------------------------------------------
DRAW_DEFAULT ()
#------------------------------------------------------------------------------
{
	SHAPE_XML_FILE DRAW_DEFAULT-$LINENO -new_page zone.page $DrawingCurrentDirectory/page.draw

	#TR T_data_collect Collecting detailled information on the server : Collecte des informations detaillees sur le serveur
	#TR T_Search Searching : Recherche
	#TR T_available available : des actions
	#TR T_actions actions : disponibles
	#TR T_Analysing Analysing server status : Analyse en cours du serveur
	#TR T_Wait Please wait a little more : Merci d'attendre encore quelques secondes


	DefaultPageContent="<zone name=\"zone.default\">
	<zone_title><![CDATA[<title>$T_data_collect</title>]]></zone_title>

	<zone_label>$T_data_collect. $T_Wait....</zone_label>
<!-- end \"zone.default\" --> </zone>"

	if [ ! -z $XmlFile ] ; then
		echo "$DefaultPageContent" >> $XmlFile
	else
		echo "$DefaultPageContent"
	fi
	SHAPE_XML_FILE DRAW_MDEFAULT_PAGE-$LINENO -end_page zone.page $DrawingCurrentDirectory/page.draw
}
#end DRAW_DEFAULT
#------------------------------------------------------------------------------
CHECK_XML ()
#------------------------------------------------------------------------------
{
if xmlstarlet --version > /dev/null 2>&1 ; then
	cd $1
	XmlFileList=`ls *.draw`
	for XmlFile in $XmlFileList ; do
		case "$XmlFile" in
		menu.draw|*.menu.draw|*.info.draw)
			;;
		*)
			XmlFileStatus=`xmlstarlet val $XmlFile`
			case "$XmlFileStatus" in
			*invalid)
				LOG_MESSAGE $LINENO -g  XML file $XmlFile is broken $XmlFileStatus
				echo "#file $XmlFile is broken $XmlFileStatus" >> /tmp/goe.broken_xml
				cat $XmlFile >> /tmp/goe.broken_xml
				;;
			esac
			;;
		esac
	done
fi
}
#end CHECK_XML
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
	case "$Option" in
	#------------------------------------------------------------------------------
	--draw)
	#------------------------------------------------------------------------------
		LOG_MESSAGE $LINENO -g execution --draw to draw zone.page page.draw -----------begin
		DrawingCurrentDirectory="$Drawings.draft"
		if [ -d "$DrawingCurrentDirectory" ] ; then  rm -rf $DrawingCurrentDirectory ; fi
		mkdir -p $DrawingCurrentDirectory
		chmod 770 $DrawingCurrentDirectory
		echo "Start drawing batch $Option on `date +'%Hh%Mm%Ss:%3N'`" >> $DrawingsLog
		DRAW_DETAIL draw_$LINENO -init -default default.detail $DrawingCurrentDirectory/default.detail.draw
		DisplayedPages=`tail -n $PageRefresh $GoePagesList | sort -u | xargs`
		if [ -f $SiteRefreshModeFile ] ; then
			RefreshMode=`cat $SiteRefreshModeFile`
		fi
		LOG_MESSAGE $LINENO -g execution --draw, refresh mode is $RefreshMode, recently displayed pages are $DisplayedPages
		DRAW_MAIN_PAGE
		CHECK_XML $DrawingCurrentDirectory
		chmod 770 $DrawingCurrentDirectory/*
		#LOG_MESSAGE $LINENO -g execution --draw `ls -lhR $DrawingCurrentDirectory`
		$Sudo chown $XoeAuthorizedUser:$HttpUser $DrawingCurrentDirectory
		CHECK_BUZY $LINENO set
		#mv $Drawings $Drawings.removed
		mv $DrawingCurrentDirectory/* $Drawings
		CHECK_BUZY $LINENO release
		LOG_MESSAGE $LINENO -g --draw fresh page contents have been updated --------------end

		echo "End drawing batch $Option on `date +'%Hh%Mm%Ss:%3N'`" >> $DrawingsLog
		#rm -rf $Drawings.removed
		#echo ".... `date +'%Hh%Mm%Ss:%3N'`" >> $GoeDir/goe.draw.log
		;;
	#------------------------------------------------------------------------------
	--draw_default)
	#------------------------------------------------------------------------------

		LOG_MESSAGE $LINENO -g execution --draw_default to draw zone.page page.draw default page content -----------begin
		DrawingCurrentDirectory="$Drawings.draft"
		if [ -d "$DrawingCurrentDirectory" ] ; then  rm -rf $DrawingCurrentDirectory ; fi
		mkdir -p $DrawingCurrentDirectory
		echo "Start Default drawing batch $Option on `date +'%Hh%Mm%Ss:%3N'`" >> $DrawingsLog
		DRAW_DEFAULT -init -default $DrawingCurrentDirectory/page.draw
		chmod -R 770 $DrawingCurrentDirectory
		#LOG_MESSAGE $LINENO -g execution --draw_default `ls -lhR $DrawingCurrentDirectory`
		$Sudo chown $XoeAuthorizedUser:$HttpUser $DrawingCurrentDirectory
		CHECK_BUZY $LINENO set
		#mv $Drawings $Drawings.removed
		mv $DrawingCurrentDirectory/* $Drawings
		CHECK_BUZY $LINENO release
		LOG_MESSAGE $LINENO -g --draw_default no activity default page content has been set --------------end
		#rm -rf $Drawings.removed
		echo "End Default drawing batch $Option on `date +'%Hh%Mm%Ss:%3N'`" >> $DrawingsLog
		;;
	#------------------------------------------------------------------------------
	--draw_now)
	#------------------------------------------------------------------------------
		LOG_MESSAGE $LINENO -g --draw_now draw on the fly a missing page with zone $ZoneName and drawing $Drawing -----------begin
		#echo -n "draw_now    `date +'%Hh%Mm%Ss:%3N'` ...." >> $GoeDir/goe.draw.log
		echo "Start drawing on demand $Option $Drawing on `date +'%Hh%Mm%Ss:%3N'`" >> $DrawingsLog
		DrawingCurrentDirectory="$Drawings"
		if [ -f $SiteRefreshModeFile ] ; then
			RefreshMode="Now"
		fi
		DRAWING_TO_SERVICE $Drawing
		LOG_MESSAGE $LINENO -g execution --draw_now Service $Service Database $Database to calculate $Drawing
		case "$Drawing" in
		log_detail.draw)
			#draw global log
			DRAW_DETAIL draw_now_$LINENO -init -general_log general_log
			;;
		*.log_detail.draw|*.instructions_detail.draw|*.configuration_detail.draw)
			#draw service log
			GET_DATA $LINENO service $Service
			DRAW_DETAIL draw_now -init -log zone.log
			DRAW_DETAIL draw_now -init -instructions zone.instructions
			DRAW_DETAIL draw_now -init -lastactions zone.lastactions
			DRAW_DETAIL draw_now -init -anomalies zone.anomalies
			DRAW_DETAIL draw_now -init -configuration zone.configuration
			LANGUAGE $LINENO $Language
			;;
		*detail.draw)
			if [ ! -z "$Database" ] ; then
				LOG_MESSAGE $LINENO -g --draw_now draw page Database $Database
				GET_DATA $LINENO service $Service
				GET_DATA $LINENO database $Service $Database
				DRAW_DETAIL draw_now_$LINENO -init -database_menu $Service.$Database.menu $DrawingCurrentDirectory/$Service.$Database.menu.draw
				DRAW_DETAIL draw_now_$LINENO -init -database $Service.$Database.info $DrawingCurrentDirectory/$Service.$Database.info.draw
				cat $DrawingCurrentDirectory/$Service.$Database.menu.draw > $DrawingCurrentDirectory/$Service.$Database.detail.draw
				cat $DrawingCurrentDirectory/$Service.$Database.info.draw >> $DrawingCurrentDirectory/$Service.$Database.detail.draw
				cat $DrawingCurrentDirectory/$Service.$Database.menu.draw
				cat $DrawingCurrentDirectory/$Service.$Database.info.draw
				LANGUAGE $LINENO $Language
			else
				if [ ! -z "$Service" ] ; then
					LOG_MESSAGE $LINENO -g --draw_now draw page Service $Service
					GET_DATA $LINENO service  $Service
					DRAW_DETAIL draw_now_$LINENO -init -service_menu $Service.menu $DrawingCurrentDirectory/$Service.menu.draw
					DRAW_DETAIL draw_now_$LINENO -init -service $Service.info $DrawingCurrentDirectory/$Service.info.draw
					cat $DrawingCurrentDirectory/$Service.menu.draw > $DrawingCurrentDirectory/$Service.detail.draw
					cat $DrawingCurrentDirectory/$Service.info.draw >> $DrawingCurrentDirectory/$Service.detail.draw
					cat $DrawingCurrentDirectory/$Service.menu.draw
					cat $DrawingCurrentDirectory/$Service.info.draw
					LANGUAGE $LINENO $Language
				else
					if [ -f $DrawingCurrentDirectory/default.detail.draw ] ; then
						cat $DrawingCurrentDirectory/default.detail.draw
						LOG_MESSAGE $LINENO -g "looking for default page $DrawingCurrentDirectory/$DrawingName, serving $DrawingCurrentDirectory/default.detail.draw instead"
					else
						LOG_MESSAGE $LINENO 404 exit "looking for missing $DrawingCurrentDirectory/$DrawingName, and no default page is available"
					fi
				fi
			fi
			;;
		page.draw|log_detail.draw|admin_guide.draw|contract.draw|open_service.draw|close_service.draw)
			#draw all services map
			LOG_MESSAGE $LINENO -g --draw_now zone.page page.draw
			DRAW_MAIN_PAGE_NOW
			$Sudo chown $XoeAuthorizedUser:$HttpUser $DrawingCurrentDirectory/$Service.draw
			cat $DrawingCurrentDirectory/page.draw
			;;
		*.draw)
			#draw service map
			LOG_MESSAGE $LINENO -g --draw_now zone.$Service $Service.draw
			DRAW_MAIN_PAGE_NOW $Service
			$Sudo chown $XoeAuthorizedUser:$HttpUser $DrawingCurrentDirectory/$Service.draw
			cat $DrawingCurrentDirectory/$Service.draw
			;;
		*)
			LOG_MESSAGE $LINENO -g --draw_now unexpected case $Zonename $Drawing
			;;
		esac
		LOG_MESSAGE $LINENO -g --draw_now  missing page have been drawn with zone $ZoneName and drawing $Drawing --------------end
		#echo ".... `date +'%Hh%Mm%Ss:%3N'`" >> $GoeDir/goe.draw.log
		echo "End drawing on demand $Option on `date +'%Hh%Mm%Ss:%3N'`" >> $DrawingsLog
		;;
	esac
	;;

#------------------------------------------------------------------------------
--get_service_data)
#------------------------------------------------------------------------------
	/usr/local/bin/xoe --config -list -data > $XoeServicesData
	/usr/local/bin/xoe --config -list -service
	;;
#------------------------------------------------------------------------------
--background)
#------------------------------------------------------------------------------
	LOG_MESSAGE $LINENO -g "--backgroung Process activation"
	runningprocesses=`ps axo cmd`
	if echo "$runningprocesses" | grep 'goe' | grep -q 'loop' ; then
		LOG_MESSAGE $LINENO -g "--backgroung Process loop is running, consider --loop_stop for a graceful stop"
		echo "Process loop is running, consider --loop_stop for a graceful stop"
		EXIT $LINENO 0
	else
		if [ ! -f $GoeLoopingFlag ] ; then
			rm -rf $GoeDir
			CHECK_ACCESS_RIGHTS
			echo "goe background task started at `date`" > $GoeLoopingFlag
		fi
		rm -f $ActivityFile
		nohup $0 --loop 2>$GoeLog &
		LOG_MESSAGE $LINENO -g "Loop is started --loop, use $0 --loop_stop for a graceful stop"
		echo "Loop is started --loop, use $0 --loop_stop for a graceful stop"
	fi
	;;
#------------------------------------------------------------------------------
--loop)
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
MOOC_EXECUTE ()
#------------------------------------------------------------------------------
{
LOG_MESSAGE $LINENO -g mooc execute mode $ServerMode
if [ -f /usr/local/bin/mooc ] ; then
	/usr/local/bin/mooc --background
fi
}
#end 
#------------------------------------------------------------------------------
LOOP_PARAMETERS ()
#------------------------------------------------------------------------------
{
#echo "backgd  `date +'%Hh%Mm%Ss:%3N'` $NumberTimes" >> $GoeDir/goe.draw.log
if [ -z "$NumberTimes" ] ; then
	NumberTimes="Auto"
fi
rating="is not evaluated"
case "$ServerMode" in
idemdemo*)
	xTimes="0"
	;;
*)
	case "$NumberTimes" in
	x*)
		xTimes=`echo "$NumberTimes" | cut -b2-`
		;;	
	esac
	if [ ! -z "$Period" ] ; then
		Pace="$Period"
	fi
	case "-$xTimes-$Pace-$NumberTimes-" in
	*-Auto*|*-auto*)
		nbdb=`psql -l 2>/dev/null | grep -m 1 "rows" | cut -d"(" -f2 | cut -d" " -f1`
		nb_databases=`echo "$nbdb - 3" | bc`
		GET_XOE_DATA

		rating=`echo "$ServiceNumber * 10 + $nb_databases" | bc`
		echo "$rating" > $GoeRatingFile
		if [ $rating -le 30 ] ; then
			xTimes="5"
			Pace="12"
			echo "15" > $SiteRefreshPeriodFile
			echo "All" > $SiteRefreshModeFile
		else
			if [ $rating -le 36 ] ; then
				xTimes="5"
				Pace="12"
				echo "12" > $SiteRefreshPeriodFile
				echo "All" > $SiteRefreshModeFile
			else
				if [ $rating -le 128 ] ; then
					xTimes="5"
					Pace="16"
					echo "20" > $SiteRefreshPeriodFile
					echo "$RefreshMode" > $SiteRefreshModeFile
				else
					if [ $rating -le 256 ] ; then
						xTimes="5"
						Pace="20"
						echo "20" > $SiteRefreshPeriodFile
						echo "Displayed" > $SiteRefreshModeFile
					else
						if [ $rating -le 384 ] ; then
							xTimes="5"
							Pace="30"
							echo "20" > $SiteRefreshPeriodFile
							echo "Displayed" > $SiteRefreshModeFile
						else
							if [ $rating -le 640 ] ; then
								xTimes="5"
								Pace="30"
								echo "30" > $SiteRefreshPeriodFile
								echo "Displayed" > $SiteRefreshModeFile
							else
								if [ $rating -le 1024 ] ; then
									xTimes="5"
									Pace="30"
									echo "30" > $SiteRefreshPeriodFile
									echo "Displayed" > $SiteRefreshModeFile
								else
									xTimes="5"
									Pace="50"
									echo "30" > $SiteRefreshPeriodFile
									echo "Displayed" > $SiteRefreshModeFile
								fi
							fi
						fi
					fi
				fi
			fi
		fi
		;;
	esac
	;;
esac
echo "$Pace" > $GoePaceTimeFile
#TR T_There_is There is : Il y a
#TR T_There_are There are : Il y a
#TR T_database_over database over : base de donnees sur
#TR T_databases_over databases over : bases de donnees sur
#TR T_service service : service
#TR T_services services : services
#TR T_Delay Delay to next evaluation : Prochain calcul apres
#TR T_Disk_size_eval Disk is evaluated once a day : Le disque est evalue 1 fois par jour
case "$nb_databases"-"$ServiceNumber" in
0-0|0-1|1-0|1-1)
	echo "$T_Disk_size_eval. $T_There_is $nb_databases $T_database_over $ServiceNumber $T_service" > $SiteRefreshCommentFile
	;;
0-*|1-*)
	echo "$T_Disk_size_eval. $T_There_is $nb_databases $T_database_over $ServiceNumber $T_services" > $SiteRefreshCommentFile
	;;
*-0|*-1)
	echo "$T_Disk_size_eval. $T_There_is $nb_databases $T_databases_over $ServiceNumber $T_service" > $SiteRefreshCommentFile
	;;
*)
	echo "$T_Disk_size_eval. $T_There_are $nb_databases $T_databases_over $ServiceNumber $T_services" > $SiteRefreshCommentFile
	;;
esac
LOG_MESSAGE $LINENO -g "LOOP_PARAMETERS rating: $rating, $xTimes x refresh, $Pace s naptime, `cat $SiteRefreshPeriodFile` s display period, refresh mode is `cat $SiteRefreshModeFile`"
}
#end
#------------------------------------------------------------------------------
LOOP_STATUS ()
#------------------------------------------------------------------------------
{
loop_status="$*"
if [ -z "$loop_status" ] ; then
	cat $GoeLoopStatusFile
else
	case `cat $GoeLoopStatusFile` in
	$loop_status)
		LOG_MESSAGE $LINENO -g looping LOOP_STATUS UNCHANGED $loop_status pace $Pace loop $iloop/$xTimes $SinceLoop
		;;
	*)
		echo "$loop_status" > $GoeLoopStatusFile
		LOG_MESSAGE $LINENO -g looping NEW LOOP_STATUS $loop_status pace $Pace loop $iloop/$xTimes $SinceLoop
		;;
	esac
fi
}
#------------------------------------------------------------------------------
LOOP ()
#------------------------------------------------------------------------------
{
#in crontab /usr/loca/bin/goe --bakground x10 6
	if [ ! -e "$ActivityFile" ] ; then
		echo -n "1234567890abcdef" > $ActivityFile
	fi
	some_time=`echo "$Pace - 5" | bc`
	MOOC_EXECUTE
	for (( iloop=1; iloop<=$xTimes; iloop++ )) ; do
		LastTime=`cat $ActivityFile | wc -c`
		SinceLoop="since `echo "$LastTime * $Pace" | bc`s"
		if [ $LastTime -le 12 ] ; then			
			case `LOOP_STATUS` in
			Napping)
				LOOP_STATUS Awakening
				$0 --collect All
				$0 --draw
				echo -n "*" >> $ActivityFile
				;;
			*)
				case "$iloop" in
				1)
					LOOP_STATUS On duty
					$0 --collect
					$0 --draw
					LOG_MESSAGE $LINENO -g collect data and redraw $iloop/$xTimes
					echo -n ";" >> $ActivityFile
					;;
				*)
					if [ $LastTime -le 6 ] ; then
						LOOP_STATUS Hard worker
						$0 --collect
						$0 --draw
						LOG_MESSAGE $LINENO -g collect data and redraw $iloop/$xTimes
						echo -n ":" >> $ActivityFile
					else
						LOOP_STATUS Lazy
						echo -n "," >> $ActivityFile
					fi
					;;
				esac
				;;
			esac
		else
			LOOP_STATUS Napping
			echo -n "." >> $ActivityFile
			echo "Napping" >> $GoePagesList
		fi
		sleep $Pace
	done
}
#------------------------------------------------------------------------------
#--loop
	LOG_MESSAGE $LINENO -g "LOOP_STATUS Starting execution loop forever, use $0 --loop_stop for a graceful stop"
	echo "$$" > $GoePidFile
	chmod 600 $GoePidFile
	LOOP_PARAMETERS
	LOOP_STATUS Awakening
	/usr/local/bin/xoe --config -list -service
	$0 --template
	$0 --collect All
	$0 --draw
	while [ ! -f  $LoopStopFlag ] ; do
		if [ -f "$GoeLogMode" ] ; then . $GoeLogMode ; fi
		LOOP
		sleep 5
	done
	$Sudo rm -f $LoopStopFlag
	rm -f $GoePidFile
	LOG_MESSAGE $LINENO -g "LOOP_STATUS Execution loop is stopped, use $0 --background to restart this loop"
	;;
#------------------------------------------------------------------------------
--loop_status)
#------------------------------------------------------------------------------
	runningprocesses=`ps axo cmd`
	if echo "$runningprocesses" | grep 'goe' | grep -q ' --loop' ; then
		echo "Loop status: loop is looping"
		echo "Refresh Comment	`cat $SiteRefreshCommentFile`"
		echo "At work	 	`cat $GoeLoopStatusFile`"
		echo "Rating		`cat $GoeRatingFile`"
		echo "Refresh Period	`cat $SiteRefreshPeriodFile`s"
		echo "Pace Time		`cat $GoePaceTimeFile`s"
		echo "Refresh Mode	`cat $SiteRefreshModeFile`"
		echo "Activity		`cat $ActivityFile | wc -c` Pace times ago"
		echo "Activity		`cat $ActivityFile`"
	else
		echo "Loop status: no loop is looping"
	fi
	if [ -f $LoopStopFlag ] ; then
		echo "A request for stopping loop has been filed"
	fi
	;;
#------------------------------------------------------------------------------
--loop_stop)
#------------------------------------------------------------------------------
	WORKINGPROCESS=`/bin/ps axo pid,cmd | grep "$0"`
	if echo "$WORKINGPROCESS" | grep -q "loop$" 2>/dev/null ; then 
		echo "Process loop is invited to stop"
		$Sudo echo "please stop looping" >  $LoopStopFlag
		$Sudo chmod 777 $LoopStopFlag
	else
		echo "Process loop is already stopped"
		$Sudo rm -f  $LoopStopFlag
	fi
	;;
#------------------------------------------------------------------------------
--history_forget)
#------------------------------------------------------------------------------
	Resize="$1"
	if [ -z "$Resize" ] ; then
		Resize="$PageKeep"
	fi
	if [ ! -e $GoePagesList ] || [ -w $GoePagesList ] ; then
		echo "$DrawingName" >> $GoePagesList
		recentpages=`tail -n $Resize $GoePagesList`
		echo "$recentpages" > $GoePagesList
	fi
	;;
#------------------------------------------------------------------------------
--new_login)
#------------------------------------------------------------------------------
	case `whoami` in
	root)
		case "$ServerMode" in
		*)
			if [ -z "$UserName" ] ; then
				echo -n "New login : "
				read UserName
			fi
			if echo "$UserLogins" | grep -qm 1 "^$UserName " ; then
				LOG_MESSAGE $LINENO -e $UserName is already declared in configuration
			else
				if [ -f "$XoeServicesData" ] && cat $XoeServicesData 2>/dev/null | grep "^#Service:$UserName:" >/dev/null 2>&1 ; then
					LOG_MESSAGE $LINENO -e $UserName is already declared in $XoeServicesData
				else
					if [ -z "$UserPassword" ] ; then
						echo -n "New password : "
						read UserPassword
					fi
					if [ -z "$UserRole" ] ; then
						echo -n "New role : "
						read UserRole
					fi
					echo "UserLogins=\"$UserLogins
$UserName $UserPassword $UserRole\"" > $GoeLoginConf
					echo "Login $UserName is added to $GoeLoginConf"
				fi
			fi
			;;
		esac
		;;
	*)
		echo "You must be root or use sudo to setup a new login"
		;;
	esac
	;;

#------------------------------------------------------------------------------
--config)
#------------------------------------------------------------------------------
	cd /usr/local
	if [ ! -e etc/goe ] ; then
		mkdir -p etc/goe
	fi
	echo "This is current configuration of goe in $GoeConf : "
	cat $0 2>/dev/null | grep -m 1 -B 200 "^##EndConfig" | grep -A 200 "^##StartConfig"
	if [ ! -f "$GoeLocalConf" ] ; then
		echo "# This is current local configuration of goe in $GoeLocalConf : " > $GoeLocalConf
		echo "# Last Update : `stat -c %z $GoeLocalConf | cut -d"." -f1`" >> $GoeLocalConf
	fi
	echo "#------------------------------------------------------------------------------"
	cat $GoeLocalConf
	chmod 755 $GoeLocalConf
	if [ -f $GoeModeConf ] ; then
		echo "#------------------------------------------------------------------------------"
		echo "# This is current mode configuration of goe in $GoeModeConf"
		cat $GoeModeConf
	fi
	if [ -f $GoeConfDir/goe.local.conf.save ] ; then
		echo "#------------------------------------------------------------------------------"
		echo "# Local configuration of goe is also saved in $GoeConfDir/goe.local.conf.save"
	fi
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--config_save)
#------------------------------------------------------------------------------
	if [ ! -f $GoeLocalConf ] ; then
		echo "#Local configuration of goe"	> $GoeLocalConf
	fi
	cp -a $GoeLocalConf $GoeConfDir/goe.local.conf.save
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--dashboard)
#------------------------------------------------------------------------------	
#toggle parameters options|contract|admin_guide|monitor|mooc|services|log show|hide
#list help support options contract monitor mooc services log
#	echo "$LINENO `date` `whoami` $DashboardOption parameters $0 --dashboard $OptionParameters" >> /tmp/goe.dashboard.service.log 2>&1
				TOGGLE ()
				{
				tog_file="$1"
				shift
				tog_line="$*"
				before_content=`cat $tog_file | grep -v "^$tog_line"`
				echo "$before_content" > $tog_file
				echo "$tog_line" >> $tog_file
				}
	case `whoami` in
	root)
		case "$DashboardValue" in
		show|hide)
			;;
		*)
			DashboardValue="show"
			;;
		esac
		if [ -z "$DashboardList" ] ; then
			DashboardList="help support options admin_guide contract monitor mooc services log"
		fi
		case "$DashboardOption" in
		list)
			TOGGLE $GoeLocalConf "ServerMenuEnabled=\"$DashboardList\""
			TOGGLE $GoeLocalConf "ServerMenuMode=\"hide\""
			;;
		options)
			TOGGLE $GoeLocalConf "ServerMenuMode=\"$DashboardValue\""
			;;
		admin_guide)
			TOGGLE $GoeLocalConf "AdminGuideMode=\"$DashboardValue\""
			;;
		contract)
			TOGGLE $GoeLocalConf "ServerContractMode=\"$DashboardValue\""
			;;
		openservice)
			TOGGLE $GoeLocalConf "OpenServiceMode=\"$DashboardValue\""
			;;
		closeservice)
			TOGGLE $GoeLocalConf "CloseServiceMode=\"$DashboardValue\""
			;;
		monitor)
			TOGGLE $GoeLocalConf "SystemInfoMode=\"$DashboardValue\""
			;;
		mooc)
			TOGGLE $GoeLocalConf "MoocInfoMode=\"$DashboardValue\""
			;;
		services)
			TOGGLE $GoeLocalConf "ServiceDetailsMode=\"$DashboardValue\""
			;;
		log)
			TOGGLE $GoeLocalConf "ServerLogMode=\"$DashboardValue\""
			;;
		newservice)
			nohup /usr/local/bin/xoe --contract -service_full_set $DashboardNewService > /dev/null 2>&1 &
			echo "$LINENO `date` `whoami` /usr/local/bin/xoe --contract -service_full_set $DashboardNewService" >> /tmp/goe.dashboard.service.log
			;;
		cancelservice)
			nohup /usr/local/bin/xoe --contract -cancel -save $DashboardCloseService >> /dev/null 2>&1 &
			echo "$LINENO `date` `whoami` sudo /usr/local/bin/xoe --contract -cancel -save $DashboardCloseService" >> /tmp/goe.dashboard.service.log
			;;
		esac
		;;
	*)
		echo "$LINENO `date` `whoami` You must be root" >> /tmp/goe.dashboard.service.log 2>&1
		;;
	esac
	;;
#------------------------------------------------------------------------------
--log)
#------------------------------------------------------------------------------
	$0 --set_log on
	if [ -z "$SearchString" ] ; then
		cat -n $GoeLogFile
	else
		cat -n $GoeLogFile | grep -i "$SearchString"
	fi
	;;
#------------------------------------------------------------------------------
--live)
#------------------------------------------------------------------------------
	$0 --set_log on
	if [ -z "$SearchString" ] ; then
		tail -f $GoeLogFile
	else
		tail -f $GoeLogFile | grep -i "$SearchString"
	fi
	;;
#------------------------------------------------------------------------------
--message)

	LOG_MESSAGE $LINENO -g $OptionParameters

	;;
#------------------------------------------------------------------------------
--mode)
#------------------------------------------------------------------------------
#echo "New mode $NewMode"
	case "$NewMode" in
	demo|business|education)
		;;
	*)
		echo "Current mode is $ServerMode"
		echo "New mode $NewMode should be in demo|business|education"
		EXIT $LINENO 1
		;;
	esac
	case `whoami` in
	root)
		case "$NewMode" in
		$ServerMode)
			;;
		demo|education)
			echo "
ServerMode=\"$NewMode\""  > $GoeModeConf
			/usr/local/bin/mooc --mode on
			;;
		*|business)
			#echo "mode is written to $GoeModeConf"
			echo "
ServerMode=\"$NewMode\""  > $GoeModeConf
			/usr/local/bin/mooc --mode off
			;;
		esac
		echo "this new setting is kept in $GoeModeConf"
		;;
	esac
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--set_authorized_user)
#------------------------------------------------------------------------------
	if [ -z "$SetAuthorizedUser" ] ; then
		echo -n  "ERP authorized user :  "
		read SetAuthorizedUser
	fi
	case `whoami` in
	root)
		case "$SetAuthorizedUser" in
		$XoeAuthorizedUser)
			;;
		*)
			if [ ! -f $GoeLocalConf ] ; then
				echo "#Local configuration of goe"	> $GoeLocalConf
			fi
			echo "XoeAuthorizedUser=\"$SetAuthorizedUser\""  >> $GoeLocalConf
			echo "this new setting is kept in $GoeLocalConf"
			;;
		esac
		;;
	esac
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--set_log)
#------------------------------------------------------------------------------
	case "$NewMode" in
	on)
		case "$GoeLog" in
		$GoeLogFile)
			;;
		*)
			echo "GoeLog=\"$GoeLogFile\""  > $GoeLogMode
			echo "Log mode is set to on" >> $GoeLogFile
			;;
		esac
		;;
	off)
		case "$GoeLog" in
		/dev/null)
			;;
		*)
			echo "GoeLog=\"/dev/null\""  > $GoeLogMode
			echo "Log mode is set to off" >> $GoeLogFile
			;;
		esac
		;;
	*)
		echo "Log file is $GoeLog"
		echo "Log setting is kept in $GoeLogMode"
		;;
	esac


	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--shell)
#------------------------------------------------------------------------------
	LOG_MESSAGE $LINENO -g execute as `whoami` shell command $ShellCommand
	$ShellCommand
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--shell_move)
#------------------------------------------------------------------------------
	LOG_MESSAGE $LINENO -g move uploaded files as `whoami` from/to $ShellCommand
	origin=`echo "$ShellCommand" | cut -d" " -f1`
	destination=`echo "$ShellCommand" | cut -d" " -f2`
	if [ ! -z "$origin" ] && [ ! -z "$destination" ] ; then
		rm -f $origin/*' '*
		mv $origin/* $destination
	else
		LOG_MESSAGE $LINENO -g move uploaded files as `whoami` from/to are mandatory
	fi
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--install_panel)
#------------------------------------------------------------------------------
	case `whoami` in
	root)

#-------------------------------------------------------------------------
PHP_CAPABILITY ()
#-------------------------------------------------------------------------
{
	if cat /etc/issue | grep -q "10.04\|11.04\|12.04\|14.04\|16.04\|Debian GNU/Linux 7" ; then
		echo "5"
	else
		echo "7"
	fi
}
#end 
#-------------------------------------------------------------------------
INSTALL_PHP_CAPABILITY ()
#-------------------------------------------------------------------------
{
	iphpc_version=`PHP_CAPABILITY`
	apt-get install fontconfig xfonts-75dpi xfonts-base xfonts-encodings xfonts-utils
	case "$iphpc_version" in
	5)
		if ! apt-get install php5 ; then
			echo "Failure during php5 installation."
		fi
		;;
	7)
		if apt-get install php ; then
			
			PHP_UPLOAD_MAX
		else
			echo "Failure during PHP7 installation."
		fi
		;;
	esac
	if ! apt-get install php-xml* ; then
		echo "Failure during PHP-XML installation."
	fi
	LOG_MESSAGE $LINENO -g PHP installed version is $iphpc_version
}
#end 
#-------------------------------------------------------------------------
		if ! apt-get install apache2 ; then
			echo "Failure during Apache2 installation."
		fi
		INSTALL_PHP_CAPABILITY
		goe_location="/`cat /etc/apache2/sites-enabled/*default* | grep DocumentRoot | cut -d/ -f2-`"
		if [ ! -e "$goe_location" ] ; then
			echo "cannot find Apache2 DocumentRoot for $Option option, not done"
			EXIT $LINENO 1
		fi
		if [ -f $goe_location/index.html ] ; then
			mv $goe_location/index.html $goe_location/.index.html.dist
		fi
		# create apache virtualhost
		$0 --update_panel
		su $XoeAuthorizedUser -c '/usr/local/bin/goe --init'

#bug lacommande crontab ne marche pas
		if ! cat /var/spool/cron/crontabs/$XoeAuthorizedUser | grep -q "/usr/local/bin/goe" ; then
			echo "
* * * * *   /usr/local/bin/goe  --background  > /dev/null 2>&1" >> /var/spool/cron/crontabs/$XoeAuthorizedUser
		fi
		# Corriger les droits d'acces
		chmod 600 /var/spool/cron/crontabs/$XoeAuthorizedUser
		chown $XoeAuthorizedUser /var/spool/cron/crontabs/$XoeAuthorizedUser
		chgrp crontab /var/spool/cron/crontabs/$XoeAuthorizedUser
		if [ -f $goe_location/robots.txt ] ; then
			mv $goe_location/robots.txt $goe_location/.robots.txt.dist
		fi
		RobotFileName="$goe_location/robots.txt"
		echo "User-agent: *
Disallow: /" > $RobotFileName
		# add $HttpUser to sudoers
		# ??
		if ! cat /etc/sudoers | grep -q "$HttpUser ALL = NOPASSWD: /usr/local/bin/goe" ; then
			echo "$HttpUser ALL = NOPASSWD: /usr/local/bin/goe" >> /etc/sudoers
		fi
		if ! cat /etc/sudoers | grep -q "$HttpUser ALL = NOPASSWD: /usr/local/bin/xoe" ; then
			echo "$HttpUser ALL = NOPASSWD: /usr/local/bin/xoe" >> /etc/sudoers
		fi
		/etc/init.d/apache2 restart
		$0 --update_mooc
		;;
	*)
		echo "you must be root or sudo to succeed with $Option option"
		;;
	esac
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--update)
#------------------------------------------------------------------------------
	case `whoami` in
	root)
		LOG_MESSAGE $LINENO -g goe $Option Nouvelle version $*
		cd /usr/local/bin
		script_source=`basename $0`
		panel_source=""
		css_source=""
		if [ ! -z "$CodeAltSource" ] ; then
			case "$CodeAltSource" in
			*,*,*)
				download_source=`echo "$CodeAltSource" | cut -d"," -f1`
				panel_source=`echo "$CodeAltSource" | cut -d"," -f2`
				css_source=`echo "$CodeAltSource" | cut -d"," -f3`
				;;
			*,*)
				download_source=`echo "$CodeAltSource" | cut -d"," -f1`
				panel_source=`echo "$CodeAltSource" | cut -d"," -f2`
				;;
			*)
				download_source="$CodeAltSource"
				;;
			esac
		else
			download_source="$GoeDownloadSource"
		fi
		OLDVERSION=`$0 --version -noblabla`
		if wget -q $download_source -O $script_source.new_version ; then
			diff $script_source $script_source.new_version
			mv $script_source rescue.$script_source
			mv $script_source.new_version $script_source
			chmod 755 $script_source
			rm -f $GoeTranslationFile.*
			NEWVERSION=`$0 --version -noblabla`
			case "$NEWVERSION" in
			$OLDVERSION)
				echo "$0 is uptodate `$0 --version`"
				;;
			*)
				echo "$0 downloaded new version from $download_source"
				;;
			esac
			$0 --update_mooc
			$0 --update_panel $panel_source $css_source
			$0 --loop_stop
		else
			echo "$0 could not update $script_source software from $download_source"
		fi
		;;
	*)
		echo "$0 you must be root or sudo to succeed with $Option option"
		;;
	esac
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--update_mooc)
#------------------------------------------------------------------------------
	case `whoami` in
	root)
		LOG_MESSAGE $LINENO -g goe $Option Nouvelle version $*
		cd /usr/local/bin
		download_source="$MoocDownloadSource"
		script_source="mooc"
		if [ ! -f $script_source ] ; then
			if wget -q $download_source -O $script_source.new_version ; then
				diff $script_source $script_source.new_version
				mv $script_source.new_version $script_source
				chmod 755 $script_source
				#first activation checks permissions and configuration
				/usr/local/bin/mooc --version
			else
				echo "could not download $script_source software from $download_source"
			fi
		else
			chmod 755 $script_source
			/usr/local/bin/mooc --update
		fi
		;;
	*)
		echo "you must be root or sudo to succeed with $Option option"
		;;
	esac
	EXIT $LINENO 0
	;;
#------------------------------------------------------------------------------
--update_panel)
#------------------------------------------------------------------------------
	case `whoami` in
	root)
		LOG_MESSAGE $LINENO -g goe $Option Nouvelle version $CodeAltSource
		goe_location="/`cat /etc/apache2/sites-enabled/*default* | grep DocumentRoot | cut -d/ -f2-`"
		if [ ! -e "$goe_location" ] ; then
			echo "cannot find Apache2 DocumentRoot for $Option option, not done"
			EXIT $LINENO 1
		fi
		cd $goe_location
		panel_source="$PanelDownloadSource"
		css_source="$CssDownloadSource"
		if [ ! -z "$CodeAltSource" ] ; then
			case "$CodeAltSource" in
			*,*)
				panel_source=`echo "$CodeAltSource" | cut -d"," -f1`
				css_source=`echo "$CodeAltSource" | cut -d"," -f2`
				;;
			*)
				panel_source="$CodeAltSource"
				;;
			esac
		fi
		if wget -q $panel_source -O $SiteScriptName.new_version ; then
			if [ -f "$SiteScriptName" ] ; then
				diff $SiteScriptName $SiteScriptName.new_version
				mv $SiteScriptName rescue.`basename $SiteScriptName`
			fi
			mv $SiteScriptName.new_version $SiteScriptName
			chown $HttpUser $SiteScriptName
			echo "goe panel is up-to-date"
		else
			echo "Could not update panel software from $PanelDownloadSource"
		fi
		if wget -q $css_source -O $SiteCss.new_version ; then
			if [ -f "$SiteCss" ] ; then
				diff $SiteCss $SiteCss.new_version
				mv $SiteCss rescue.$SiteCss
			fi
			mv $SiteCss.new_version $SiteCss
			chown $HttpUser $SiteCss
			echo "goe panel css is up-to-date"
		else
			echo "Could not update css file from $css_source"
		fi
		rm -rf $SiteImages
		if ! wget -q -r -np -nH -nd -R index.html $ImageSource -P $SiteImages ; then
			echo "Could not update images from $ImageSource"
		fi
		echo "<?php
// php code generated by $0 version $ThisScriptVersion
function bytesToSize1024(\$bytes, \$precision = 2) {
    \$unit = array('B','KB','MB');
    return @round(\$bytes / pow(1024, (\$i = floor(log(\$bytes, 1024)))), \$precision).' '.\$unit[\$i];
}
if (isset(\$_POST['service']))
{
	\$serviceName = \$_POST['service'];
}
\$errorCode = \$_FILES['archive_upload']['error'];
\$fileName = \$_FILES['archive_upload']['name'];
\$fileType = \$_FILES['archive_upload']['type'];
\$fileExtension = pathinfo(\$fileName, PATHINFO_EXTENSION);
\$fileBytes = \$_FILES['archive_upload']['size'];
\$fileSize = bytesToSize1024(\$_FILES['archive_upload']['size'], 1);
\$fileTemp = \$_FILES['archive_upload']['tmp_name'];
\$targetFile = \"$GoeUploads/\$serviceName/\$fileName\";
\$dirService = \"$GoeUploads/\$serviceName\";
\$acceptedExtensions = ['tar.gz','zip'];
//echo \"<p>Your file: \".\$fileName.\" has been successfully received.</p>\";
echo \"<p>Type: \".\$fileType.\"</p>\";
echo \"<p>Size: \".\$fileSize.\"</p>\";
//echo \"<p>file: \".\$fileTemp.\"</p>\";
echo \"<p>copy: \".\$targetFile.\"</p>\";
if(\$errorCode === 1)
{
	echo \"<p>Fichier trop gros, refuse. File is too large, rejected.</p>\";
}
elseif(\$error_Code === 2)
{
	echo \"<p>File error code 2</p>\";
	exit;
}
elseif(\$error_Code === 3)
{
	echo \"<p>File error code 3</p>\";
	exit;
}
elseif(\$error_Code === 4)
{
	echo \"<p>Le fichier est vide -File is empty</p>\";
	exit;
}
elseif(\$fileBytes > $MaxArchiveUploadSize)
{
	echo \"<p>Le fichier est trop gros.The file is too big. Max : $MaxArchiveUploadSize.</p>\";
	exit;
}
elseif(!in_array(\$fileExtension,\$acceptedExtensions))
{
	echo \"<p>Les archives acceptees sont au formats .tar.gz ou .zip, sans espace dans le nom. Accepted archives are .tar.gz or .zip file, no space in name.</p>\";
	exit;
}
if (!is_dir(\$dirService))
	mkdir(\$dirService, 0777);
\$is_uploaded = move_uploaded_file(\$fileTemp, \$targetFile);
if(\$is_uploaded)
{
	echo \"<p>Le fichier \".\$fileName.\" peut etre ajoute a la bibliotheque specifique du service. File \".\$fileName.\" uploaded successfully to specific library of service</p>\";
}
else
{
	echo \"<p>File not uploaded.</p>\";
}
?>
"	> upload.php.new_version
		if [ -f upload.php ] ; then
			diff upload.php upload.php.new_version
			rm upload.php
		fi
		mv upload.php.new_version upload.php
		echo "goe upload.php is up-to-date"
		PHP_UPLOAD_MAX
		if ! cat /etc/sudoers | grep -q "$HttpUser ALL = NOPASSWD: /usr/local/bin/goe" ; then
			echo "$HttpUser ALL = NOPASSWD: /usr/local/bin/goe" >> /etc/sudoers
		fi
		if ! cat /etc/sudoers | grep -q "$HttpUser ALL = NOPASSWD: /usr/local/bin/xoe" ; then
			echo "$HttpUser ALL = NOPASSWD: /usr/local/bin/xoe" >> /etc/sudoers
		fi
		if ! cat /etc/sudoers | grep -q "$HttpUser ALL = NOPASSWD: /usr/local/bin/mooc" ; then
			echo "$HttpUser ALL = NOPASSWD: /usr/local/bin/mooc" >> /etc/sudoers
		fi
		;;
	*)
		echo "you must be root or sudo to succeed with $Option option"
		;;
	esac
	EXIT $LINENO 0
	;;

#------------------------------------------------------------------------------
--css)
#------------------------------------------------------------------------------
	cd $GoeDir
	wget -q $CssDownloadSource -O $GoeDir/copy_of_goe.css
	echo "/* generated by $0 on $Date */"
	cat $GoeDir/copy_of_goe.css
	echo "/* generated by $0 on $Date */"
	;;
#------------------------------------------------------------------------------
--css_check)
#------------------------------------------------------------------------------
	CssContent=`$0 --css`
	PositionList=`cat $0 | grep -v "PositionList=" | grep "<zone_position>" | cut -d">" -f2 | cut -d"<" -f1 | sort -u | xargs`
	echo "List of positions : $PositionList"
	for position in $PositionList ; do
		if ! echo "$CssContent" | grep -q "\.$position" ; then
			echo "Missing css class .$position"
		fi
	done
	StatusList="fault ok unknown warning"
	echo "List of status values : $StatusList"
	for status in $StatusList ; do
		if ! echo "$CssContent" | grep -q "\.$status" ; then
			echo "Missing css class .$status"
		fi
	done
	TypeList=`cat $0 | grep -v "TypeList=" | grep "<zone_type>" | cut -d">" -f2 | cut -d"<" -f1 | sort -u | xargs`
	echo "List of zone types : $TypeList"
	for type in $TypeList ; do
		if ! echo "$CssContent" | grep -q "\.$type" ; then
			echo "Missing css class .$type"
		fi
		for status in $StatusList ; do
			if ! echo "$CssContent" | grep "\.$type" | grep -q "\.$status" ; then
				echo "Defaulted css class .$type .$status"
			fi
		done
	done
	;;
#------------------------------------------------------------------------------
--help)
#------------------------------------------------------------------------------
	echo "goe : application de gestion des services openerp
syntaxe :
goe [login [language]] --command [parameters]
-- are optionnal when login and language are indicated

Command :
--help

--background			#create a loop forever
--collect	All | [zone_name ] | [service_name [database_name]]
--config
--config_denied_message
--config_head_css
--config_head_title
--config_head_refresh
--config_login_form
--config_mode
--config_page_header
--config_page_footer
--config_page_menu
--config_save
--config_welcome_message
--css_check
--css
--dashboard	options|contract|monitor|mooc|services|log [show]|hide
--dashboard	list help support options contract monitor mooc services log
--draw
--draw_now	zone_name drawing_name
--get_service_data
--history_forget	[nb_pages]
--init
--install_panel
--licence
--live		[search_string]
--log		[search_string]
--login		username password # check user is authorized and return user role
--login_list
--loop				#used by --background
--loop_status
--loop_stop			#set an indicator to stop gracefully a --loop at next iteration
--message	message text
--mode		demo|business|education
--move_uploaded	upload_dir custom_dir
--new_login	user_name user_password service_name|admin
--on_click	zone_name new_drawing_name action [action_parameters]
--on_duty
--page		zone_name drawing_name
--refresh	zone_name drawing_name
--set_authorized_user xoe_administration_username
--set_log	on|off


--shell		shell_command_and_parameters
--shell_move	origin_dir destination_dir
--template
--update	[http://alternative_goe_code_source_url [http://alternative_panel_code_source_url]]
--update_panel
--version [-noblabla]

language= fr|en


Configuration adaptation is located in $GoeLocalConf and saved to $GoeConfDir/goe.local.conf.save

--install_panel
--update
--update_mooc
--update_panel


output file format :
<zone name=\"zone_name\" />
	<markup>data</markup>
</zone>
markup is one of
zone name	introduces a nested zone, name is mandatory
these markups relate to the zone they are declared in
zone_doc_over	specifies information showed when mouse is over an active element
zone_form	html form code
zone_html	html content to be added in the page
zone_label	short text of a button
zone_menu	html code of an element added to a gobal menu zone
zone_on_click	action executed in case of click on the zone area
zone_on_validate	action executed when a form is validated

these markups are used to invoke css styles for the content of the zone and are applied in this order :
zone_position	example zcenter, zright, zleft...
zone_type	example service_name, service_running, database...
zone_status	typically ok, fault, warning and unknown

these are used to set up global setting wherever the declaration is :
zone_refresh	superceedes any previous page refreshment instruction
zone_title	superceedes any previous title set for the current window
zone_window	specifies a name of the pop up window
"
$0 --version
	;;
#------------------------------------------------------------------------------
--licence)
#------------------------------------------------------------------------------
	echo "This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Credits
2012-today: goe is an original work from SISalp, http://sisalp.fr"
	;;
#------------------------------------------------------------------------------
--)
#------------------------------------------------------------------------------
	$0 --help | less
	;;

#------------------------------------------------------------------------------
*)
#------------------------------------------------------------------------------
	echo "503 Option $Option is not supported by goe command"
	;;
esac
EXIT $LINENO 0


