<?php

/**-----------------------------------------------
*
* Rooty, 2018 <rooty@rooty.me>
*
*
* This software is protected by copyright, please
* read the file COPYRIGHT.
* 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. Please
* read the file LICENCE.
*
*Ce fichier contient la classe AddCom
*
* @author Initiance <www.initiance.com|martial@initiance.com>
* @copyright Copyright &copy; 2009-2018, Rooty 
* @since 2004/06/07
* @version 0.3
* @link www.rooty.me
* @package object_coordination
* @subpackage AddCom 
*/
if ( !defined('SYSTEM_IN') )
{
 die("Hacking attempt");
}

/**
* Classe AddNode
*
* classe pour la création d'une nouvelle communauté
* @package object_coordination
* @subpackage AddCom 
*/

Class AddCom extends CoordinationObj
{
/**
* @var tableau
* @access private
*/
var $tabForbidden=array("adminentrynode", "admingroup", "adminnode", "home", "adminobject", "usertemp", "adminuser", "addcom", "installmanager");

/**
* Function permettant d'afficher le formulaire de saisie d'une nouvelle entrée
* @access public
* @return chaine chaine vide
*/
	function actionAdmin($tabPOST="")
	{
		/*Récupération des messages utilisateurs*/
		addMessageFile("user.ini");
		addMessageFile("main.ini");
		addMessageFile("object.ini");
		addMessageFile("adminnode.ini");

		/* gestion du lib en fonction de la langue courante */
		$currentCode=$GLOBALS["SYSTEM_USER_SESSION"]->langue->getCode();
		$defaultCode=$GLOBALS["SYSTEM_DEFAULT_LANGUAGE_CODE"];
		/* fin récupération des codes par défaut */
		
		mxPageTitle("actionAdminAddComTitlePage");
		
		$arrayCallCss = array();
		$arrayCallCss[] = "data/css/bootstrap-datepicker/1.9.0/bootstrap-datepicker3.min.css";
		mxCallCss($arrayCallCss);
		
		$arrayCallJs = array();
		$arrayCallJs[] = "data/javascript/bootstrap-datepicker/1.9.0/bootstrap-datepicker.min.js";
		$arrayCallJs[] = "data/javascript/bootstrap-datepicker/1.9.0/locales/bootstrap-datepicker.".$currentCode.".min.js";
		mxCallJs($arrayCallJs);
		
		$arrayRawJs[] = "\$('.datepicker').datepicker();";
		$arrayRawJs[] = "function imgPicto(){if(document.getElementById){if(document.getElementById(\"fmNodeAdd\")){var obj=document.getElementById(\"template\");document.getElementById(\"pictoObject\").src=\"data/image/icons/node/\"+document.getElementById(\"fmNodeAdd\").iconeN.options[(document.getElementById(\"fmNodeAdd\").iconeN.selectedIndex)].value;}}else if(document.all){if(document.all[\"fmNodeAdd\"]){document.all[\"pictoObject\"].src=\"data/image/icons/node/\"+document.all[\"fmNodeAdd\"].iconeN.options[(document.all[\"fmNodeAdd\"].iconeN.selectedIndex)].value;}}}function Valid_register(the_form,the_field){var objectform = document.forms[the_form];var nbr = objectform.length;var flag = 0;for(z=0 ; z < nbr; z++){if(objectform.elements[z].checked == true && objectform.elements[z].name == the_field){flag=1;}}if(flag == 0){alert('<mx:text id=\"selectbriques\"/>');return false;}objectform.submit();}function imgTemplate(){if(document.getElementById){if(document.getElementById(\"fmNodeAdd\")){var obj=document.getElementById(\"template\");document.getElementById(\"pictoTemplate\").src=\"data/template/\"+obj.options[(obj.selectedIndex)].value+\"/preview.png\";}}else if(document.all){if(document.all[\"fmNodeAdd\"]){var obj=document.all[\"template\"];document.all[\"pictoTemplate\"].src=\"data/template/\"+obj.options[(obj.selectedIndex)].value+\"/preview.png\";}}}imgTemplate();function setSelectOptions(the_form, the_select, do_check){var selectObject = document.forms[the_form].elements[the_select];var selectCount  = selectObject.length;for (var i = 0; i < selectCount; i++){selectObject.options[i].selected = do_check;}return true;}function setCheckOptions(the_form, the_select){var selectObject = document.forms[the_form];var selectCount  = selectObject.length;for (var i = 0; i < selectCount; i++) {if(selectObject.elements[i].name == the_select){if(selectObject.elements[i].checked == true){selectObject.elements[i].checked = false;}else{selectObject.elements[i].checked = true;}}}return true;}";
		mxRawJs($arrayRawJs);
		
		/* On inclus la template (voir package.template.php) */
		WithBlocPath("AddCom", "actionadmin");

		# Affichage de la liste déroulante
		# Détermine le chemin des icônes
		$chemintotal = $GLOBALS['CONF_DATA_PATH']."data/image/icons/node/";

		# Lecture du dossier correspondant aux icônes
		$handle  = @opendir($chemintotal);$i=0;
		while ($file = @readdir($handle))
		{
			if($file !="" && $file !="." && $file !=".." && (substr($file, -3)== "gif" || substr($file,-3)=="jpg" || substr($file,-4)=="jpeg" || substr($file,-3)=="png"))
			{
				$tabIcone[$file]=$file;
			}
		}
		@closedir($handle);
		asort($tabIcone);
		
		# Affichage des champs de formulaire pour l'inscription
		if(!$tabPOST)
		{
			$titre = array(getMessage("mr"),getMessage("mrs"), getMessage("miss"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxSelect("user_title", "user_title", "", $titre, getMessage("user_title"), "", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipSelectTitle"), ENT_QUOTES)."\"");
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_first_name", "text", "user_first_name", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipFirstName"), ENT_QUOTES)."\"", getMessage("user_first_name"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_last_name", "text", "user_last_name", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipLastName"), ENT_QUOTES)."\"", getMessage("user_last_name"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_login", "text", "user_login", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipLogin"), ENT_QUOTES)."\"", getMessage("user_login"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_password", "password", "user_password", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipPassword"), ENT_QUOTES)."\"", getMessage("user_password"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_password2", "password", "user_password2", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipPassword2"), ENT_QUOTES)."\"", getMessage("user_password"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_mail", "text", "user_mail", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipCourriel"), ENT_QUOTES)."\"", getMessage("user_mail"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_birthdate", "text", "user_birthdate", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipBirthDate"), ENT_QUOTES)."\"", getMessage("user_birthdate"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_postal_code", "text", "user_postal_code", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipPostalCode"), ENT_QUOTES)."\"", getMessage("user_postal_code"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_postal_address", "text", "user_postal_address", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipPostalAddress"), ENT_QUOTES)."\"", getMessage("user_postal_address"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_city", "text", "user_city", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipCity"), ENT_QUOTES)."\"", getMessage("user_city"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_state", "text", "user_state", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipState"), ENT_QUOTES)."\"", getMessage("user_state"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_country", "text", "user_country", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipCountry"), ENT_QUOTES)."\"", getMessage("user_country"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_tel", "text", "user_tel", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipTel"), ENT_QUOTES)."\"", getMessage("user_tel"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_fax", "text", "user_fax", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipFax"), ENT_QUOTES)."\"", getMessage("user_fax"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_website", "text", "user_website", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipWebsite"), ENT_QUOTES)."\"", getMessage("user_website"));
// 			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_msn", "text", "user_msn", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipMsn"), ENT_QUOTES)."\"", getMessage("user_msn"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_jabber", "text", "user_jabber", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipJabber"), ENT_QUOTES)."\"", getMessage("user_jabber"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_facebook", "text", "user_facebook", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipFacebook"), ENT_QUOTES)."\"", getMessage("user_facebook"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_mastodon", "text", "user_mastodon", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipMastodon"), ENT_QUOTES)."\"", getMessage("user_mastodon"));
		}
		else // On raffiche les données saisies par l'utilisateur
		{
			$titre = array(getMessage("mr"),getMessage("mrs"), getMessage("miss"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxSelect("user_title", "user_title", $_POST['user_title'], $titre, getMessage("user_title"), "", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipSelectTitle"), ENT_QUOTES)."\"");
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_first_name", "text", "user_first_name", $_POST['user_first_name'], "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipFirstName"), ENT_QUOTES)."\"", getMessage("user_first_name"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_last_name", "text", "user_last_name", $_POST['user_last_name'], "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipLastName"), ENT_QUOTES)."\"", getMessage("user_last_name"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_login", "text", "user_login", $_POST['user_login'], "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipLogin"), ENT_QUOTES)."\"", getMessage("user_login"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_password", "password", "user_password", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipPassword"), ENT_QUOTES)."\"", getMessage("user_password"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_password2", "password", "user_password2", "", "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipPassword2"), ENT_QUOTES)."\"", getMessage("user_password"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_mail", "text", "user_mail", $_POST['user_mail'], "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipCourriel"), ENT_QUOTES)."\"", getMessage("user_mail"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_birthdate", "text", "user_birthdate", "", "class=\"form\" title=\"".htmlspecialchars(getMessage("tipBirthDate"), ENT_QUOTES)."\"", getMessage("user_birthdate"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_postal_code", "text", "user_postal_code", $_POST['user_postal_code'], "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipPostalCode"), ENT_QUOTES)."\"", getMessage("user_postal_code"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_postal_address", "text", "user_postal_address", $_POST['user_postal_address'], "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipPostalAddress"), ENT_QUOTES)."\"", getMessage("user_postal_address"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_city", "text", "user_city", $_POST['user_city'], "class=\"form\" title=\"".htmlspecialchars(getMessage("tipCity"), ENT_QUOTES)."\"", getMessage("user_city"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_state", "text", "user_state", $_POST['user_state'], "class=\"form\" title=\"".htmlspecialchars(getMessage("tipState"), ENT_QUOTES)."\"", getMessage("user_state"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_country", "text", "user_country", $_POST['user_country'], "class=\"form\" required=\"true\" title=\"".htmlspecialchars(getMessage("tipCountry"), ENT_QUOTES)."\"", getMessage("user_country"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_tel", "text", "user_tel", $_POST['user_tel'], "class=\"form\" title=\"".htmlspecialchars(getMessage("tipTel"), ENT_QUOTES)."\"", getMessage("user_tel"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_fax", "text", "user_fax", $_POST['user_fax'], "class=\"form\" title=\"".htmlspecialchars(getMessage("tipFax"), ENT_QUOTES)."\"", getMessage("user_fax"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_website", "text", "user_website", $_POST['user_website'], "class=\"form\" title=\"".htmlspecialchars(getMessage("tipWebsite"), ENT_QUOTES)."\"", getMessage("user_website"));
// 			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_msn", "text", "user_msn", $_POST['user_msn'], "class=\"form\" title=\"".htmlspecialchars(getMessage("tipMsn"), ENT_QUOTES)."\"", getMessage("user_msn"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_jabber", "text", "user_jabber", $_POST['user_jabber'], "class=\"form\" title=\"".htmlspecialchars(getMessage("tipJabber"), ENT_QUOTES)."\"", getMessage("user_jabber"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_facebook", "text", "user_facebook", $_POST['user_facebook'], "class=\"form\" title=\"".htmlspecialchars(getMessage("tipFacebook"), ENT_QUOTES)."\"", getMessage("user_facebook"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("user_mastodon", "text", "user_mastodon", $_POST['user_mastodon'], "class=\"form\" title=\"".htmlspecialchars(getMessage("tipMastodon"), ENT_QUOTES)."\"", getMessage("user_mastodon"));
		}

		/* Récupération de toutes les langues actives */
		$tab=$GLOBALS["SYSTEM_MANAGER"]["LANGUAGE"]->createActiveLanguageList();

		for ($i=0; $i<count($tab);$i++)
		{
			/* récupération de l'image de la langue courante */
			if (file_exists($GLOBALS['CONF_DATA_PATH']."data/image/icons/language/".strtolower($tab[$i]->getCode()).".png"))
			{
				$img=$GLOBALS['CONF_DATA_PATH']."data/image/icons/language/".strtolower($tab[$i]->getCode()).".png";
			}else{
				$img=$GLOBALS['CONF_DATA_PATH']."data/image/icons/language/default.png";
			}
			$GLOBALS["SYSTEM_TEMPLATE"]->MxImage("blocName.pictoLanguage",$img,htmlentitiesconv($tab[$i]->getLibelle($tab[$i]->getCode())));

			if(isset($_POST["nameLanguage".$tab[$i]->getCode()]))
			{
				$nameLanguage = $_POST["nameLanguage".$tab[$i]->getCode()];
			}
			else
			{
				$nameLanguage ="";
			}

			$GLOBALS['SYSTEM_TEMPLATE']->MxText("blocName.txtNodeEntryName", getMessage("txtNodeEntryName"));
	// 		$GLOBALS['SYSTEM_TEMPLATE']->MxAttribut("blocName.nameInput", "nameLanguageA".$tab[$i]->getCode());
			$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("blocName.NodeEntry_name", "text", "nameLanguage".$tab[$i]->getCode(), $nameLanguage, "class=\"form\"", getMessage("txtNodeEntryName"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxAttribut("previewtemplate",getMessage("TxtPreview"));
			$GLOBALS["SYSTEM_TEMPLATE"]->MxBloc("blocName", "loop");
		}
		
		$GLOBALS['SYSTEM_TEMPLATE']->MxSelect("icone", "iconeN", '', $tabIcone, 'Icône de la communauté', '', 'id="iconeN"', "class=\"form\" title=\"".htmlspecialchars(getMessage("txtNodeIcon"), ENT_QUOTES)."\"", getMessage("txtNodeIcon"));
		$GLOBALS["SYSTEM_TEMPLATE"]->MxImage("pictoObject", $GLOBALS['CONF_DATA_PATH']."data/image/icons/node/defaultnode.gif", getMessage("PreviewPicto"));
		
		$GLOBALS['SYSTEM_TEMPLATE']->MxText("txtNodeType", getMessage("txtNodeType"));
		$GLOBALS['SYSTEM_TEMPLATE']->MxText("txtNodeTypereg", getMessage("txtNodeTypereg"));
		$GLOBALS['SYSTEM_TEMPLATE']->MxText("txtNodeDomain", getMessage("txtNodeDomain"));
		
		printTabCommProfiles($selected='', $MxBlocName="COMMPROFILES", $name="NodeEntry_type");
		$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("NodeEntry_typereg", "text", "NodeEntry_typereg","", "class=\"form\"", getMessage("txtNodeTypereg"));
		$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("NodeEntry_domain", "text", "NodeEntry_domain","", "class=\"form\"", getMessage("txtNodeDomain"));

		/* pour chaque classe et en fonction de la langue */
		for ($i=0; $i<count($GLOBALS["SYSTEM_REGISTER"]["COORDINATION_OBJ"]); $i++)
		{
			if (!in_array(strtolower($GLOBALS["SYSTEM_REGISTER"]["COORDINATION_OBJ"][$i]), $this->tabForbidden))
			{
			$value	=$GLOBALS["SYSTEM_REGISTER"]["COORDINATION_OBJ"][$i];
			$name	=getMessage("class".strtolower($GLOBALS["SYSTEM_REGISTER"]["COORDINATION_OBJ"][$i]));
			$name	=( (!isset($name)) || ($name!="") )?$name:$value;

			$GLOBALS['SYSTEM_TEMPLATE']->MxText("actionAdminClass.classValue", $value);
			$GLOBALS['SYSTEM_TEMPLATE']->MxText("actionAdminClass.className", $name);
			//MxCheckerField(string $path, string $type, string $name, string $value, [string $checked], [string $attribut]);
	/*		if (!in_array($GLOBALS["SYSTEM_REGISTER"]["COORDINATION_OBJ"][$i], $this->tabForbidden))
			{*/
				$GLOBALS["SYSTEM_TEMPLATE"]->MxCheckerField("actionAdminClass.classId", "checkbox", "class_id[]", $GLOBALS["SYSTEM_REGISTER"]["COORDINATION_OBJ"][$i], "", "");

	/*		}else{
				$GLOBALS["SYSTEM_TEMPLATE"]->MxCheckerField("actionAdminClass.classId", "checkbox", "class_id[]", $GLOBALS["SYSTEM_REGISTER"]["COORDINATION_OBJ"][$i],"","class='BUTTON'");
			}
	*/
			$GLOBALS['SYSTEM_TEMPLATE']->MxBloc("actionAdminClass", "loop");
			}
		}
			
		/* Affichage des templates */
		# Affichage de la liste déroulante
		# Détermine le chemin des icônes
		$chemintotal = $GLOBALS['SYSTEM_TEMPLATE_PATH'];
		$tabIcone    = array();
		$tabTpl=array();
		# Lecture du dossier correspondant aux icônes
		$handle      = @opendir($chemintotal);
		while ($file = @readdir($handle))
		{
			if (in_array($file, $tabTpl ) || count($tabTpl)==0 )
			{
				if($file !="" && $file !="." && $file !=".." && (strpos(".SVN",$file, 0)===FALSE) && (strpos(".svn",$file, 0)===FALSE) && (strpos(".CVS",$file, 0)===FALSE) && (strpos(".cvs",$file, 0)===FALSE) && (strpos("CACHE",$file, 0)===FALSE) && (strpos("cache",$file, 0)===FALSE)&& is_dir($chemintotal.$file))
				{
					$tabIcone[$file]=$file;
				}
			}
		}
		@closedir($handle);
		asort($tabIcone);
		$GLOBALS['SYSTEM_TEMPLATE']->MxSelect("TEMPLATE_ADMIN", "template", $tabIcone, $tabIcone, "", 7, "", "class=\"form\"");
		/* Fin Affichage des templates */

		$GLOBALS["SYSTEM_TEMPLATE"]->MxFormField("BtnAdd", "button", "boutton", getMessage("BtnAdd"), "class=\"form\"");
		# Récupération des étiquettes du formulaire
		$GLOBALS["SYSTEM_TEMPLATE"]->MxAttribut("urlAction", formatUrl($this->getId(),"AddCom","execAdmin",""));
		return "";
	}

/**
* Function permettant de controler les doublons, d'inscrire dans la bd et redirection avec message
* @access public
* @return chaine chaine vide
*/
function execAdmin()
	{
		/*Récupération des messages utilisateurs*/
		addMessageFile("user.ini");
		addMessageFile("main.ini");
		addMessageFile("object.ini");
		addMessageFile("adminnode.ini");

		/* gestion du lib en fonction de la langue courante */
		$currentCode=$GLOBALS["SYSTEM_USER_SESSION"]->langue->getCode();
		$defaultCode=$GLOBALS["SYSTEM_DEFAULT_LANGUAGE_CODE"];
		/* fin récupération des codes par défaut */

// 		var_dump($_POST);
// 		exit(0);

		$chaine="";
		if($_POST)
		{
			foreach($_POST as $cle=>$val)
			{
// 				echo "cle = ".$cle." val =".$val."<br>";
// 				if($val=="" && ($cle !="user_comment" && $cle !="user_fax" && $cle !="user_organisation" && $cle !="user_country"))
				if($val=="" && ($cle !="NodeEntry_type" && $cle !="NodeEntry_typereg" && $cle !="NodeEntry_domain" && $cle !="user_fax" && $cle !="user_mastodon" && $cle !="user_jabber" && $cle !="user_facebook" && $cle !="user_msn" && $cle !="user_website"))
				{
					$chaine .= getMessage($cle).", ";
// 					var_dump(getMessage($cle));
				}
			}
			if($chaine!="")
			{
				$chaine .= getMessage('obligatory');
			}
		}

		//Si certains champs sont manquants pour l'inscription
		if ($chaine != "")
		{
			$GLOBALS["SYSTEM_CONTROL"]->messageSystem = $chaine;
			$GLOBALS["SYSTEM_TEMPLATE"]->MxBloc("DATA", "modify", $GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."object_coordination/addcom/actionadmin.mxt");
			$GLOBALS["SYSTEM_TEMPLATE"]->WithMxPath("DATA", "relative");
			$this->actionAdmin($_POST);
			return "";
		}

		# Teste si il y a des enregistrements sur MyManager (table temporaire) ou sur la table des comptes
		if (($GLOBALS['SYSTEM_MANAGER']['USER']->checkValid($_POST["user_login"], $_POST["user_password"]) != 0))
        	{
			$GLOBALS["SYSTEM_CONTROL"]->messageSystem = "user_exist";
			$GLOBALS["SYSTEM_TEMPLATE"]->MxBloc("DATA", "modify", $GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."object_coordination/addcom/actionadmin.mxt");
			$GLOBALS["SYSTEM_TEMPLATE"]->WithMxPath("DATA", "relative");
			$this->actionAdmin($_POST);
			return "";
		}
		else
		{
		
			//Vérification que les deux password saisis sont bien les mêmes avant enregistrement de l'utilisateur
			if ($_POST['user_password']<>$_POST['user_password2'])
			{
				$GLOBALS["SYSTEM_CONTROL"]->messageSystem = "PasswordInvalid";
				$GLOBALS["SYSTEM_TEMPLATE"]->MxBloc("DATA", "modify", $GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."object_coordination/addcom/actionadmin.mxt");
				$GLOBALS["SYSTEM_TEMPLATE"]->WithMxPath("DATA", "relative");
				$this->actionAdmin($_POST);
				return "";			
			}		
			else
			{
				//On créé un nouvel objet User pour effectuer l'insertion de chaque champs
				$MyUser=new User();
		
				$MyUser->setTitle($_POST['user_title']);
				$MyUser->setFirstName($_POST['user_first_name']);
				$MyUser->setLastName($_POST['user_last_name']);
				$MyUser->setLogin($_POST['user_login']);
				$MyUser->setPassword($_POST['user_password']);
				$MyUser->setBirthDate($_POST['user_birthdate']);
				$MyUser->setMail($_POST['user_mail']);
				$MyUser->setPostalAddress($_POST['user_postal_address']);
				$MyUser->setPostalCode($_POST['user_postal_code']);
				$MyUser->setCity($_POST['user_city']);
				$MyUser->setState($_POST['user_state']);
				$MyUser->setCountry($_POST['user_country']);
// 				$MyUser->setOrganisation($_POST['user_organisation']);
				$MyUser->setTel($_POST['user_tel']);
				$MyUser->setFax($_POST['user_fax']);
// 				$MyUser->setComment(array($_POST['user_comment']));
				$MyUser->setWebSite($_POST['user_website']);
				$MyUser->setMsn($_POST['user_msn']);
				$MyUser->setJabber($_POST['user_jabber']);
				$MyUser->setFacebook($_POST['user_facebook']);
				$MyUser->setMastodon($_POST['user_mastodon']);
				$MyUser->SetAccountActive(1);
			
				//On enregistre les paramètres
				$MyUser = $GLOBALS["SYSTEM_MANAGER"]["USER"]->saveInstance($MyUser);
			}
			// création du noeud principal+groupe principal
			$Node=new Node();
			$Group=new Group();
			/* Pour le nom de l'objet... */
			reset($_POST);
			while (list($key, $val) = each($_POST)) {
				if (!(strpos($key, "nameLanguage")===false))							// on a trouvé un nom pour une langue
				{
					$tabCodeLangue[]=str_replace("nameLanguage", "",$key);					// on stocke le tableau des codes pour test
					// on ajoute le lib
					$Group->setLibelle(str_replace("nameLanguage", "",$key), $val);
					$Node->setLibelle(str_replace("nameLanguage", "",$key), $val);
				}
			}

			$Node->SetIcone( ((isset($_POST["iconeN"]))?(htmlentitiesconv($_POST["iconeN"])):"") );
			$Node->setCType( ((isset($_POST["NodeEntry_type"])&&$_POST["NodeEntry_type"]!="#")?($_POST["NodeEntry_type"]):"default") );
			$Node->setCTypereg( ((isset($_POST["NodeEntry_typereg"]))?($_POST["NodeEntry_typereg"]):"") );
			$Node->setDomain( ((isset($_POST["NodeEntry_domain"]))?($_POST["NodeEntry_domain"]):"") );
			$Node->SetHasPublic( ((isset($_POST["haspublic"]))?($_POST["haspublic"]):0) );
			$Node->setMailNode( ((isset($_POST["user_mail"]))?($_POST["user_mail"]):"") );
			
			// Récupération de la template!!!
			if (isset($_POST["template"]) && is_array($_POST["template"]))
			{
				$template=$_POST["template"];
				$defaultTemplate=(count($_POST["template"])>0)?$_POST["template"][0]:"default";
			}else{
				$template=array();
				$defaultTemplate="default";
			}

			$Node->setTemplate($defaultTemplate);

			$Node->setIdPere(1);
			$Group->setIdPere(1);
			//On laisse les pictos par défaut
			$Node	=$GLOBALS["SYSTEM_MANAGER"]["NODE"]->insertInstance($Node);
			$Group	=$GLOBALS["SYSTEM_MANAGER"]["GROUP"]->insertInstance($Group);

			/*vérification de l'inexistance du répertoire*/
			if( !is_dir ($GLOBALS['CONF_DATA_PATH']."data/upload/fckeditor/userimages/".$Node->getId()))
			{
				mkdir($GLOBALS['CONF_DATA_PATH']."data/upload/fckeditor/userimages/".$Node->getId(),0775);
			}

			// Création des groupes et des noeuds secondaires
			$NodeUtil	=new Node();
			$NodeAdmin	=new Node();
			$NodeUtil->setIdPere($Node->getId());
			$NodeAdmin->setIdPere($Node->getId());
			$NodeUtil->setTemplate($defaultTemplate);
			$NodeAdmin->setTemplate($defaultTemplate);
			$NodeUtil->setLibelle("FR", "Utilisateur");
			$NodeAdmin->setLibelle("FR", "Administrateur");

			$GroupUtil	=new Group();
			$GroupAdmin	=new Group();
			$GroupUtil->setIdPere($Group->getId());
			$GroupAdmin->setIdPere($Group->getId());
			$GroupUtil->setLibelle("FR", "Utilisateur");
			$GroupAdmin->setLibelle("FR", "Administrateur");

			$NodeUtil=$GLOBALS["SYSTEM_MANAGER"]["NODE"]->insertInstance($NodeUtil);
			$NodeAdmin=$GLOBALS["SYSTEM_MANAGER"]["NODE"]->insertInstance($NodeAdmin);
			$GroupUtil=$GLOBALS["SYSTEM_MANAGER"]["GROUP"]->insertInstance($GroupUtil);
			$GroupAdmin=$GLOBALS["SYSTEM_MANAGER"]["GROUP"]->insertInstance($GroupAdmin);
			
			if( $Node->getHasPublic() )
			{
				$NodePublic	=new Node();
				$NodePublic->setIdPere($Node->getId());
				$NodePublic->setTemplate($defaultTemplate);
				$NodePublic->setLibelle("FR", $Node->getDomain);
				$NodePublic=$GLOBALS["SYSTEM_MANAGER"]["NODE"]->insertInstance($NodePublic);
			}

			$NodeGroupUserAdmin =new NodeGroupUser();
			$NodeGroupUserAdmin->setGroupId($GroupAdmin->getId());
			$NodeGroupUserAdmin->setNodeId($Node->getId());
			$NodeGroupUserAdmin->setUserId(0);
			$NodeGroupUserAdmin=$GLOBALS["SYSTEM_MANAGER"]["NODE_GROUP_USER"]->insertInstance($NodeGroupUserAdmin);

			$NodeGroupUserUtil =new NodeGroupUser();
			$NodeGroupUserUtil->setGroupId($GroupUtil->getId());
			$NodeGroupUserUtil->setNodeId($NodeUtil->getId());
			$NodeGroupUserUtil->setUserId(0);
			$NodeGroupUserUtil=$GLOBALS["SYSTEM_MANAGER"]["NODE_GROUP_USER"]->insertInstance($NodeGroupUserUtil);

			/* On associe l'utilisateur à son groupe... */
			$GroupUser=new GroupUser();
			$GroupUser->setUserId( $MyUser->getId() );
			$GroupUser->setGroupId( $GroupAdmin->getId() );
			$GroupUser=$GLOBALS["SYSTEM_MANAGER"]["GROUP_USER"]->insertInstance($GroupUser);

#-------------------------------------------------------------------------------------------------------------------------------------
			/* Création des objets... */
#-------------------------------------------------------------------------------------------------------------------------------------
			# --> Objet de gestion des Briques
			# ----> Objet en lui mm
			includeDep("adminobject/adminobject.php");
			$Obj=new AdminObject();
			$Obj->setName("FR", "Gérer les outils");
			$Obj->setContentType("AdminObject");
			if (isset($_POST["class_id"]))
			{
				$tabPost=array();
				if ( is_array($_POST["class_id"]) )
				{
					$tabPost=$_POST["class_id"];
				}else{
					$tabPost=array();
				}
				$Obj->setData("tabAllowed", $tabPost);
			}
			else{
				$Obj->setData("tabAllowed", array() );
			}
			$Obj->setData("groupId", $Group->getId() );
			$Obj->setData("template", $template );
			$Obj->setNode( nid() );
			$Obj->setData("nodeId", $Node->getId() );
			$Obj=$GLOBALS["SYSTEM_MANAGER"]["COORDINATION_OBJ"]->insertInstance($Obj);
			# ----> Droits de l'objet
			$Right=new Right();
			$Right->setGroupId( $GroupAdmin->getId() );
			$Right->setNodeId( $NodeAdmin->getId() );
			$Right->setClassName("AdminObject");
			$Right->setMethodName("actionAdmin");
			$Right->setObjectId($Obj->getId());
			$Right=$GLOBALS["SYSTEM_MANAGER"]["RIGHT"]->insertInstance($Right);
#-------------------------------------------------------------------------------------------------------------------------------------
			# --> Objet de gestion des Comptes
			# ----> Objet en lui mm
			includeDep("adminuser/adminuser.php");
			$Obj=new AdminUser();
			$Obj->setName("FR", "Gérer les comptes");
			$Obj->setContentType("AdminUser");
			$Obj->setData("groupId", $Group->getId() );
			$Obj->setNode( nid() );

			$Obj=$GLOBALS["SYSTEM_MANAGER"]["COORDINATION_OBJ"]->insertInstance($Obj);
			# ----> Droits de l'objet
			$Right=new Right();
			$Right->setGroupId( $GroupAdmin->getId() );
			$Right->setNodeId( $NodeAdmin->getId() );
			$Right->setClassName("AdminUser");
			$Right->setMethodName("actionAdmin");
			$Right->setObjectId($Obj->getId());
			$Right=$GLOBALS["SYSTEM_MANAGER"]["RIGHT"]->insertInstance($Right);
#-------------------------------------------------------------------------------------------------------------------------------------
			# --> Objet de gestion des Groupes
			# ----> Objet en lui mm
			includeDep("admingroup/admingroup.php");
			$Obj=new AdminGroup();
			$Obj->setName("FR", "Gérer les groupes");
			$Obj->setContentType("AdminGroup");
			$Obj->setData("groupId", $Group->getId() );
			$Obj->setNode( nid() );

			$Obj=$GLOBALS["SYSTEM_MANAGER"]["COORDINATION_OBJ"]->insertInstance($Obj);
			# ----> Droits de l'objet
			$Right=new Right();
			$Right->setGroupId( $GroupAdmin->getId() );
			$Right->setNodeId( $NodeAdmin->getId() );
			$Right->setClassName("AdminGroup");
			$Right->setMethodName("actionAdmin");
			$Right->setObjectId($Obj->getId());
			$Right=$GLOBALS["SYSTEM_MANAGER"]["RIGHT"]->insertInstance($Right);
#-------------------------------------------------------------------------------------------------------------------------------------
			# --> Objet de gestion des Dossiers
			# ----> Objet en lui mm
			includeDep("adminnode/adminnode.php");
			$Obj=new AdminNode();
			$Obj->setName("FR", "Gérer les espaces");
			$Obj->setContentType("AdminNode");
			$Obj->setData("nodeId", $Node->getId() );
			$Obj->setData("template", $template );
			$Obj->setNode( nid() );

			$Obj=$GLOBALS["SYSTEM_MANAGER"]["COORDINATION_OBJ"]->insertInstance($Obj);
			# ----> Droits de l'objet
			$Right=new Right();
			$Right->setGroupId( $GroupAdmin->getId() );
			$Right->setNodeId( $NodeAdmin->getId() );
			$Right->setClassName("AdminNode");
			$Right->setMethodName("actionAdmin");
			$Right->setObjectId($Obj->getId());
			$Right=$GLOBALS["SYSTEM_MANAGER"]["RIGHT"]->insertInstance($Right);
#-------------------------------------------------------------------------------------------------------------------------------------
			# --> Objet de gestion des Partages de Dossier/
			# ----> Objet en lui mm
			includeDep("adminentrynode/adminentrynode.php");
			$Obj=new AdminEntryNode();
			$Obj->setName("FR", "Gérer les accès");
			$Obj->setContentType("AdminEntryNode");
			$Obj->setData("nodeId", $Node->getId() );
			$Obj->setData("groupId", $Group->getId() );
			$Obj->setNode( nid() );

			$Obj=$GLOBALS["SYSTEM_MANAGER"]["COORDINATION_OBJ"]->insertInstance($Obj);
			# ----> Droits de l'objet
			$Right=new Right();
			$Right->setGroupId( $GroupAdmin->getId() );
			$Right->setNodeId( $NodeAdmin->getId() );
			$Right->setClassName("AdminEntryNode");
			$Right->setMethodName("actionAdmin");
			$Right->setObjectId($Obj->getId());
			$Right=$GLOBALS["SYSTEM_MANAGER"]["RIGHT"]->insertInstance($Right);
#-------------------------------------------------------------------------------------------------------------------------------------
			# --> Objet d'édition du l'outil "Mon Compte"
			# ----> Objet en lui mm
// 			includeDep("usermodif/usermodif.php");
// 			$Obj=new UserModif();
// 			$Obj->setName("FR", "Mon Compte");
// 			$Obj->setContentType("UserModif");
// 			$Obj->setData("nodeId", $Node->getId() );
// 			$Obj->setData("groupId", $Group->getId() );
// 			$Obj->setNode( nid() );
// 
// 			$Obj=$GLOBALS["SYSTEM_MANAGER"]["COORDINATION_OBJ"]->insertInstance($Obj);
// 			# ----> Droits de l'objet
// 			$Right=new Right();
// 			$Right->setGroupId( $GroupAdmin->getId() );
// 			$Right->setNodeId( $NodeAdmin->getId() );
// 			$Right->setClassName("UserModif");
// 			$Right->setMethodName("actionModifier");
// 			$Right->setObjectId($Obj->getId());
// 			$Right=$GLOBALS["SYSTEM_MANAGER"]["RIGHT"]->insertInstance($Right);
#-------------------------------------------------------------------------------------------------------------------------------------
			# --> Objet de gestion des pré-insciptions
			# ----> Objet en lui mm
			includeDep("usertemp/usertemp.php");
			$Obj=new UserTemp();
			$Obj->setName("FR", "Gérer les préinscriptions");
			$Obj->setContentType("UserTemp");
			$Obj->setData("nodeId", $Node->getId() );
			$Obj->setData("groupId", $Group->getId() );
			$Obj->setNode( nid() );

			$Obj=$GLOBALS["SYSTEM_MANAGER"]["COORDINATION_OBJ"]->insertInstance($Obj);
			# ----> Droits de l'objet
			$Right=new Right();
			$Right->setGroupId( $GroupAdmin->getId() );
			$Right->setNodeId( $NodeAdmin->getId() );
			$Right->setClassName("UserTemp");
			$Right->setMethodName("actionManageRegister");
			$Right->setObjectId($Obj->getId());
			$Right=$GLOBALS["SYSTEM_MANAGER"]["RIGHT"]->insertInstance($Right);
#-------------------------------------------------------------------------------------------------------------------------------------
			# --> Objet de gestion des Partages de Dossier/
			# ----> Objet en lui mm
			includeDep("home/home.php");
			$Obj=new Home();
			$Obj->setName("FR", "Accueil");
			$Obj->setContentType("Home");
			$Obj->setNode( $Node->getId() );

			$Obj=$GLOBALS["SYSTEM_MANAGER"]["COORDINATION_OBJ"]->insertInstance($Obj);
			# ----> Droits de l'objet
			$Right=new Right();
			$Right->setGroupId( $GroupAdmin->getId() );
			$Right->setNodeId( $NodeAdmin->getId() );
			$Right->setClassName("Home");
			$Right->setMethodName("actionadmin");
			$Right->setObjectId($Obj->getId());
			$Right=$GLOBALS["SYSTEM_MANAGER"]["RIGHT"]->insertInstance($Right);

			$Right=new Right();
			$Right->setGroupId( $GroupUtil->getId() );
			$Right->setNodeId( $NodeUtil->getId() );
			$Right->setClassName("Home");
			$Right->setMethodName("actionaccueil");
			$Right->setObjectId($Obj->getId());
			$Right=$GLOBALS["SYSTEM_MANAGER"]["RIGHT"]->insertInstance($Right);

			$GLOBALS["SYSTEM_MANAGER"]["TREE_GROUP_CACHE"]->emptyCache();
			$GLOBALS["SYSTEM_MANAGER"]["TREE_NODE_CACHE"]->emptyCache();
			$GLOBALS["SYSTEM_MANAGER"]["LIST_USER_GROUP_CACHE"]->emptyCache();
			$GLOBALS["SYSTEM_MANAGER"]["LIST_USER_NODE_CACHE"]->emptyCache();
			if( DATA_ACCES_CACHE_PERMISSION )
				$GLOBALS["SYSTEM_MANAGER"]["PERMISSION_CACHE"]->emptyCache();

#------------------------------------------------------------------------------------------------------------------------------------
			# Redirection vers le formulaire
			systemRedirect(formatUrl($this->getId(),"AddCom","actionAdmin", "msgSave"));
		}
        return "";
    }
}
?>
