File "gmaccessclass.php"

Full Path: /home/asmplong/www/ancien-site-2019/integ/plugins/system/plugmaccess/gmaccessclass.php
File size: 80.95 KB
MIME-type: text/x-php
Charset: 8 bit

<?php

defined( '_JEXEC' ) or die( 'Restricted access' );


class fonctionGmaccess {

	//gmaccess cette fonction construit le tableau des droits pour le backend
	function gmprocessback ( $acosection, $aco, $aro, $axosection=NULL, $axo=NULL, $name) {
		$db =& JFactory::getDBO();
		
		$parent = fonctionGmaccess::mgparent( $aro );
		$where1 = ($axosection==NULL) ? "" :  "\nAND axosection='".$axosection."'";
		$where2 = ($axo==NULL) ? "" :  "\nAND axo='".$axo."'";
		$db->setQuery("SELECT count(*) FROM #__gm_groupe"
				. "\n LEFT JOIN #__gmacl AS g ON id_groupe = g.aro"
				. "\n WHERE id_groupe = $aro"
				. "\n AND g.aco = '".$aco."'"
				. $where1
				. $where2
				//. "\n AND g.axo = '".$axo."'"
				//. "\n AND g.axosection = '".$axosection."'"
				. "\n AND g.acosection = '".$acosection."'"
				);
    			$total = $db->loadResult();
			
				$test  = $total ? 'checked' : '';
				$gma = fonctionGmaccess::checkgmaccess($acosection,$aco,'users',$parent,$axosection,$axo);
				//$test2  = ($gma && !$total) ? 'disabled' : '';
				$test2  = ($gma && !$total) ? 'disabled' : '';
				if ($test2=='disabled'){
					$img = 'checkedg.gif';
				}else{
					$img 	= $total ? 'checked.gif' : 'non_checked.gif';
				}
			//$task 	= $total ? 'ungmread' : 'gmread';
			$alt 	= JText::_( 'GMA_PCHANGER' );
			$action	= $total ? 'Interdire' : 'Autoriser';
			
			// style="display:none;"
				$href2 = '<img src="images/'. $img .'" border="0" id="i'.$name.'" alt="'.JText::_( 'GMA_PCHANGER' ).'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\''.$name.'\').disabled==false) {document.getElementById(\''.$name.'\').checked = !document.getElementById(\''.$name.'\').checked;if(document.getElementById(\''.$name.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}}" /><input type="checkbox" name="'.$name.'" id="'.$name.'" '.$test2.' class="inputbox" style="display:none;" '.$test.'  value="1" />';
			
		return $href2;
	}
	
	//gmaccess fonction : dtermine la liste des groupes parents pour un groupe donn (+le groupe lui-mme).
	function mgparent( $id ) {
	
		$db =& JFactory::getDBO();
		
		if ($id==0) {
			$gmidfinal = array ($id);
		}elseif ($id==1) {
			$gmidfinal = array (0,$id);
		}else{
			$gmidfinal = array (0,1,$id);
		}
		
		$query = "SELECT id_groupe"
				. "\nFROM #__gm_groupeimbrique"
				. "\nWHERE id_groupeimbrique='".$id."'"
				;
		$db->setQuery( $query );
		//charger le rsultat dans un tableau
		$gmidverif = $db->loadResultArray();
		if ( !is_array($gmidverif) ) {
					$gmidverif = array();
				}
		//ajoute les valeurs  gmidfinal
		$gmidfinal = array_merge ($gmidfinal,$gmidverif);
		$gmidfinal = array_unique ($gmidfinal);
		
		//boucle de recherche des groupes imbriqus
		while ( sizeof($gmidverif) != 0 ) {
			$gmidinitial = $gmidfinal;
			//pour chaque groupe trouv
			foreach ( $gmidverif as $row ) {
				$query2 = "SELECT id_groupe"
				. "\nFROM #__gm_groupeimbrique"
				. "\nWHERE id_groupeimbrique='".$row."'"
				;
				$db->setQuery( $query2 );
				//charger le rsultat dans un tableau
				$gmidtrouve = $db->loadResultArray();
				if ( !is_array($gmidtrouve) ) {
					$gmidtrouve = array();
				}
				$gmidfinal = array_merge ($gmidfinal,$gmidtrouve);
				$gmidfinal = array_unique ($gmidfinal);
			}
			$gmidverif = array_diff ($gmidfinal,$gmidinitial);
		}
		
		//renvoie la valeure textuelle
		$gmidfinal= implode (",",$gmidfinal);
		return $gmidfinal;
			
	}
	
	//gmaccess fonction : dtermine la liste des groupes parents (sans publique et membre) pour un groupe donn (+le groupe lui-mme).
	function mgparent2( $id ) {
		
		$db =& JFactory::getDBO();
		
		
		$gmidfinal = array ($id);
		
		
		$query = "SELECT id_groupe"
				. "\nFROM #__gm_groupeimbrique"
				. "\nWHERE id_groupeimbrique='".$id."'"
				;
		$db->setQuery( $query );
		//charger le rsultat dans un tableau
		$gmidverif = $db->loadResultArray();
		if ( !is_array($gmidverif) ) {
					$gmidverif = array();
				}
		//ajoute les valeurs  gmidfinal
		$gmidfinal = array_merge ($gmidfinal,$gmidverif);
		$gmidfinal = array_unique ($gmidfinal);
		
		//boucle de recherche des groupes imbriqus
		while ( sizeof($gmidverif) != 0 ) {
			$gmidinitial = $gmidfinal;
			//pour chaque groupe trouv
			foreach ( $gmidverif as $row ) {
				$query2 = "SELECT id_groupe"
				. "\nFROM #__gm_groupeimbrique"
				. "\nWHERE id_groupeimbrique='".$row."'"
				;
				$db->setQuery( $query2 );
				//charger le rsultat dans un tableau
				$gmidtrouve = $db->loadResultArray();
				if ( !is_array($gmidtrouve) ) {
					$gmidtrouve = array();
				}
				$gmidfinal = array_merge ($gmidfinal,$gmidtrouve);
				$gmidfinal = array_unique ($gmidfinal);
			}
			$gmidverif = array_diff ($gmidfinal,$gmidinitial);
		}
		
		//renvoie la valeure textuelle
		$gmidfinal= implode (",",$gmidfinal);
		return $gmidfinal;
			
	}

	// fonction qui dtermine si un groupe ou utilisateur ($aro_value = liste de groupes) a un droit (aco) sur un objet donn (axo-section + axo).
	function checkgmaccess( $aco_section_value, $aco_value,
		$aro_section_value, $aro_value, $axo_section_value=NULL, $axo_value=NULL ) {
		
		$db =& JFactory::getDBO();
		
		$where1 = ($axo_section_value==NULL) ? "" :  "\nAND axosection='".$axo_section_value."'";
		$where2 = ($axo_value==NULL) ? "" :  "\nAND axo='".$axo_value."'";
		$query = "SELECT id"
			. "\nFROM #__gmacl"
			. "\nWHERE acosection='".$aco_section_value."'"
			. "\nAND aco='".$aco_value."'"
			. "\nAND arosection='".$aro_section_value."'"
			. "\nAND aro IN ($aro_value)"
			. $where1
			. $where2
			//. "\nAND axosection='".$axo_section_value."'"
			//. "\nAND axo='".$axo_value."'"
			;
		$db->setQuery( $query );
		$gmacl = $db->loadObjectList();
		$nbacl = count( $gmacl );
		if ( !$nbacl ) {
			$acl_result = 0;
		}else{
			$acl_result = 1;
		}
		return $acl_result;
	}
	
	
		// fonction qui dtermine si un groupe ou utilisateur ($aro_value = liste de groupes) a un droit (aco) sur un objet donn ($row).
	function checkallaccess( $aco_section_value, $aco_value,
		$aro_section_value, $aro_value, $id ) {
		
		$db =& JFactory::getDBO();
		
		$row =& JTable::getInstance('content');

		$row->load( $id );
		
		$query = "SELECT id"
			. "\nFROM #__gmacl"
			. "\nWHERE acosection='".$aco_section_value."'"
			. "\nAND aco='".$aco_value."'"
			. "\nAND arosection='".$aro_section_value."'"
			. "\nAND aro IN ($aro_value)"
			. "\nAND axosection='section'"
			. "\nAND axo='".$row->sectionid."'"
			;
		$db->setQuery( $query );
		$gmacl = $db->loadObjectList();
		$nbacl = count( $gmacl );
		$query = "SELECT id"
			. "\nFROM #__gmacl"
			. "\nWHERE acosection='".$aco_section_value."'"
			. "\nAND aco='".$aco_value."'"
			. "\nAND arosection='".$aro_section_value."'"
			. "\nAND aro IN ($aro_value)"
			. "\nAND axosection='category'"
			. "\nAND axo='".$row->catid."'"
			;
		$db->setQuery( $query );
		$gmacl2 = $db->loadObjectList();
		$nbacl2 = count( $gmacl2 );
		$query = "SELECT id"
			. "\nFROM #__gmacl"
			. "\nWHERE acosection='".$aco_section_value."'"
			. "\nAND aco='".$aco_value."'"
			. "\nAND arosection='".$aro_section_value."'"
			. "\nAND aro IN ($aro_value)"
			. "\nAND axosection='item'"
			. "\nAND axo='".$row->id."'"
			;
		$db->setQuery( $query );
		$gmacl3 = $db->loadObjectList();
		$nbacl3 = count( $gmacl3 );
		if ($nbacl || $nbacl2 || $nbacl3 ) {
			$acl_result = 1;
		}else{
			$acl_result = 0;
		}
		return $acl_result;
	}
	
	
	
		//gmaccess pour la construction des listes compatibles gmaccess2 (composants conp gmaccess2)
	function Access2( &$row ) {
		$db =& JFactory::getDBO();

		/* modif gmaccess 
		$query = "SELECT id AS value, name AS text"
		. "\n FROM #__groups"
		. "\n ORDER BY id"
		;*/
		$query = 'SELECT id_groupe AS value, nom_groupe AS text FROM #__gm_groupe ORDER BY id_groupe';
		$db->setQuery( $query );
		$groups = $db->loadObjectList();
		$access = mosHTML::selectList( $groups, 'access', 'class="inputbox" size="3"', 'value', 'text', intval( $row->access ) );

		return $access;
	}
	//Gmaccess cette fonction construit le tableau d'affichage des droits pour un objet donn en fonction de tous les groupes GMAccess
function TabGmaccess( &$row, $axosection, $read, $submit, $editown, $edit, $publishown, $publish, $deleteown, $delete, $right,$groupeid=99999,$ajax=0,$catcomp=0) {

		 /* $lang =& JFactory::getLanguage();
          $langTag = $lang->getTag();

          if (file_exists(JPATH_ADMINISTRATOR.DS.'language'.DS.$langTag.DS.$langTag.'.com_gmaccess.ini')) {
             $fname1 = JPATH_ADMINISTRATOR.DS.'language'.DS.$langTag.DS.$langTag.'.com_gmaccess.ini';
          } else {
             $fname1 = JPATH_ADMINISTRATOR.DS.'language'.DS.'fr-FR'.DS.'fr-FR.com_gmaccess.ini';
          }
		require $fname1;*/
		global $mainframe;
		$db=& JFactory::getDBO();
		$grouperefus = 999999;
		$refus = 0;
		$no=0;
		$i=0;
		$propa='';
				if ($axosection == 'component') {

			$db->setQuery("SELECT count(*) FROM #__gmacl"

				. "\n WHERE acosection = '".$row->option."'"
				. "\n AND aco = 'read'"

				. "\n AND aro != '1'"
				);
    			$totalgmcomp = $db->loadResult();

			$gmgroupea2 = '1';

			$gmacomp2 = fonctionGmaccess::checkgmaccess($row->option,'read','users',$gmgroupea2);
			$gm = ($gmacomp2) ? '' : 'checked';
		} elseif ($axosection == 'componenturl') {
		
			$db->setQuery("SELECT count(*) FROM #__gmacl"
				//modif greg
				. "\n WHERE acosection = '".$row->acosection."'"
				. "\n AND aco = '".$row->aco."'"
				. "\n AND axosection = '".$row->axosection."'"
				. "\n AND axo = '".$row->axo."'"
				. "\n AND aro != '1'"
				);
    			$totalgmcompurl = $db->loadResult();

			$gmgroupea2 = '1';

			$gmacompurl2 = fonctionGmaccess::checkgmaccess4($row->acosection,$row->aco,'users',$gmgroupea2,$row->axosection,$row->axo);
			$gm = ($gmacompurl2) ? '' : 'checked';
				
		} else {
			$gm = ($row->access==3) ? 'checked' : '';
		}
		
		 	$db->setQuery("SELECT *" . "\nFROM #__gm_groupe"  .
        	 "\nORDER BY access_groupe,id_groupe"
       	 	);
   			 $groupes = $db->loadObjectList();
		 	 $db->setQuery("SELECT MAX(id_groupe)" . "\nFROM #__gm_groupe"  .
         	"\nORDER BY access_groupe,id_groupe"
       		 );
   			 $tot = $db->loadResult();
		

		  $retourhtml ='<input type="checkbox" name="access" id="gmread" style="display:none;" class="inputbox"  '.$gm.'  value="3" /><input type="checkbox" name="change" id="change" style="display:none;" class="inputbox" value="1" /><table class="adminlist">';
		if ($edit && !$editown) {
				$retourhtml .='<thead><tr><th >'.JText::_( 'GMA_PGROUPE' ).'</th>';
				if ($read==1) $retourhtml .='<th  style="text-align:center">'.JText::_( 'GMA_PREAD' ).'</th>';
				if ($submit==1) $retourhtml .='<th  style="text-align:center">'.JText::_( 'GMA_PADD' ).'</th>';
				if ($editown==1) $retourhtml .='<th  style="text-align:center">'.JText::_( 'GMA_PEDIT' ).'</th>';
				if ($edit==1) $retourhtml .='<th  style="text-align:center">'.JText::_( 'GMA_PEDIT' ).'</th>';
				if ($publishown==1) $retourhtml .='<th  style="text-align:center">'.JText::_( 'GMA_PPUB' ).'</th>';
				if ($publish==1) $retourhtml .='<th  style="text-align:center">'.JText::_( 'GMA_PPUB' ).'</th>';
				if ($deleteown==1) $retourhtml .='<th  style="text-align:center">'.JText::_( 'GMA_PSUPP' ).'</th>';
				if ($delete==1) $retourhtml .='<th  style="text-align:center">'.JText::_( 'GMA_PSUPP' ).'</th>';
				if ($right==1) $retourhtml .='<th  style="text-align:center">'.JText::_( 'GMA_PRIGHT' ).'</th>';
				$retourhtml .='</tr></thead>';
		}else{

				$retourhtml .='<thead><tr><th class="title">'.JText::_( 'GMA_PGROUPE' ).'</th>';
				if ($read==1) $retourhtml .='<th class="title" style="text-align:center">'.JText::_( 'GMA_PREADS' ).'</th>';
				if ($submit==1) $retourhtml .='<th class="title" style="text-align:center">'.JText::_( 'GMA_PADDS' ).'</th>';
				if ($editown==1) $retourhtml .='<th class="title" style="text-align:center">'.JText::_( 'GMA_PEDITO' ).'</th>';
				if ($edit==1) $retourhtml .='<th class="title" style="text-align:center">'.JText::_( 'GMA_PEDITS' ).'</th>';
				if ($publishown==1) $retourhtml .='<th class="title" style="text-align:center">'.JText::_( 'GMA_PPUBO' ).'</th>';
				if ($publish==1) $retourhtml .='<th class="title" style="text-align:center">'.JText::_( 'GMA_PPUBS' ).'</th>';
				if ($deleteown==1) $retourhtml .='<th class="title" style="text-align:center">'.JText::_( 'GMA_PSUPPO' ).'</th>';
				if ($delete==1) $retourhtml .='<th class="title" style="text-align:center">'.JText::_( 'GMA_PSUPPS' ).'</th>';
				if ($right==1) $retourhtml .='<th class="title" style="text-align:center">'.JText::_( 'GMA_PRIGHTS' ).'</th>';
				$retourhtml .='</tr></thead>';
		}
		foreach ( $groupes as $groupe) {
			
			if ($groupeid==99999 || $groupe->id_groupe==$groupeid) {
				$parent = fonctionGmaccess::mgparent( $groupe->id_groupe );
				$parent2 = fonctionGmaccess::mgparent2( $groupe->id_groupe );
				$retourhtml .='<tr><td style="color:#c64934">'.$groupe->nom_groupe.'</td>';
				if ($read==1) {
					
					//test si item ou category ($gma || $access<=1)
					
					if ($axosection=='item' && $row->catid && $row->sectionid){
						$propa='';
						$gmacat = fonctionGmaccess::checkgmaccess2('com_content','read','users',$parent,'category',$row->catid);
						$gmasec = fonctionGmaccess::checkgmaccess2('com_content','read','users',$parent,'section',$row->sectionid);
						if (!$gmacat || !$gmasec) {
							$refus=1;
						}
					}
					if ($axosection=='category' && $row->section && !$catcomp){	
						$propa='cat';			
						$gmasec = fonctionGmaccess::checkgmaccess2('com_content','read','users',$parent,'section',$row->section);
						if (!$gmasec) {
							$refus=1;
						}
					}
					if ($axosection=='section'){
						$propa='sec';
					}
					if ($axosection=='module'&& $row->module=='mod_mainmenu'){
						$propa='menu';
					}
					if ($axosection=='menu'&& $row->menutype){
						$db->setQuery("SELECT *" . "\nFROM #__modules where module='mod_mainmenu' order by module asc "
						);
   			 			$modules = $db->loadObjectList();
						foreach ($modules as $module) {
						
							$mod_params = new JParameter( $module->params );
							$typemenu = $mod_params->get('menutype', 0);
							

							if ($typemenu==$row->menutype) {
								$i = $module->id;
							}
						}
						$propa='';
						$gmasec = fonctionGmaccess::checkgmaccess2('com_content','read','users',$parent,'module',$i);
						if (!$gmasec) {
							$refus=1;
						}
					}
					if ($axosection=='contact' && $row->catid ){	
						$propa='';			
						$gmasec = fonctionGmaccess::checkgmaccess2('com_content','read','users',$parent,'category',$row->catid);
						if (!$gmasec) {
							$refus=1;
						}
					}
					if ($axosection=='componenturl') {
						$gmacomponent = fonctionGmaccess::checkgmaccess($row->acosection,'read','users',$parent);
						$db->setQuery("SELECT count(*) FROM #__gmacl"
						. "\n WHERE acosection = '".$row->acosection."'"
						. "\n AND aco = 'read'"
						//. "\n AND axosection = 'component'"
						//. "\n AND axo = '".$row->id."'"
						//. "\n AND aro != '1'"
						);
						$totalgmcomp2 = $db->loadResult();
						if (!$gmacomponent && $totalgmcomp2) {
							$refus=1;
						}
					}
					if ($refus) {
						$grouperefus = $groupe->id_groupe;
						$readcheck = '<img src="images/publish_x.png" border="0" alt="'.JText::_( 'GMA_PREFU' ).'" />';
					}else{
						if ($axosection == 'component') {
							if ($gmacomp2) {
									$access = 1;
								}elseif (!$totalgmcomp) {
									$access = 0;
								}else{
									$access = 3;
								}
						} elseif ($axosection == 'componenturl') {
							if ($gmacompurl2) {
									$access = 1;
								}elseif (!$totalgmcompurl) {
									$access = 0;
								}else{
									$access = 3;
								}
								if ($grouperefus >= $access && $grouperefus != 999999) {
									$access = 3;
								}
						
						} else {
							if ($grouperefus < $row->access || $grouperefus == 999999) {
								$access = $row->access;
							}else{
								$access = 3;
							}
						}
							$readcheck 	= fonctionGmaccess::GMProcessing(  $groupe, $tot, $groupe->id_groupe, $axosection , $row->id, 'read', $access );
						
					}
					$retourhtml .='<td style="text-align:center">'.$readcheck.'</td>';
					$refus=0;
				}
				if ($submit==1) {
					if ($groupe->id_groupe) {
					if ($axosection=='item' && $row->catid && $row->sectionid){
						$gmacat = fonctionGmaccess::checkgmaccess3('com_content','submit','users',$parent,'category',$row->catid);
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','submit','users',$parent,'section',$row->sectionid);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','add','users',$parent,'content','all');
						if ($gmacat || $gmasec || $gmall) {
							$no=1;
						}
					}
					if ($axosection=='category' && $row->section){
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','submit','users',$parent,'section',$row->section);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','add','users',$parent,'content','all');
						if ($gmasec || $gmall) {
							$no=1;
						}
					}
					if ($axosection=='section'){
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','add','users',$parent,'content','all');
						if ($gmall) {
							$no=1;
						}
					}
					if (!$no) {
						if ($axosection=='content'){
							$submitcheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , 'all', 'add' );
						}else{
							$submitcheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , $row->id, 'submit' );
						}
					}else{
						$submitcheck = '<img src="images/tick.png" border="0" alt="'.JText::_( 'GMA_PHERIT' ).'" />';
					}
				}else {
					$submitcheck = '<img src="images/publish_x.png" border="0" alt="'.JText::_( 'GMA_PREFUPUB' ).'" />';
				}
					$retourhtml .='<td style="text-align:center">'.$submitcheck.'</td>';
					$no=0;
				}
				if ($editown==1) {
					if ($groupe->id_groupe) {
					if ($axosection=='item' && $row->catid && $row->sectionid){
						$gmacat = fonctionGmaccess::checkgmaccess3('com_content','editown','users',$parent,'category',$row->catid);
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','editown','users',$parent,'section',$row->sectionid);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','editown','users',$parent,'content','all');
						$gmacat2 = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'category',$row->catid);
						$gmasec2 = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'section',$row->sectionid);
						$gmall2 = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'content','all');
						if ($gmacat || $gmasec || $gmall || $gmacat2 || $gmasec2 || $gmall2) {
							$no=1;
						}
					}
					if ($axosection=='category' && $row->section){
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','editown','users',$parent,'section',$row->section);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','editown','users',$parent,'content','all');
						$gmasec2 = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'section',$row->section);
						$gmall2 = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'content','all');
						if ($gmasec || $gmall || $gmasec2 || $gmall2) {
							$no=1;
						}
					}
					if ($axosection=='section'){
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','editown','users',$parent,'content','all');
						$gmall2 = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'content','all');
						if ($gmall || $gmall2) {
							$no=1;
						}
					}
					if (!$no) {
						if ($axosection=='content'){
							$editowncheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , 'all', 'editown' );
						}else{
							$editowncheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , $row->id, 'editown' );
						}
					}else{
						$editowncheck = '<img src="images/tick.png" border="0" alt="'.JText::_( 'GMA_PHERIT' ).'" />';
					}
				}else {
					$editowncheck = '<img src="images/publish_x.png" border="0" alt="'.JText::_( 'GMA_PREFUPUB' ).'" />';
				}
					$retourhtml .='<td style="text-align:center">'.$editowncheck.'</td>';
					$no=0;
				}
				if ($edit==1) {
					if ($groupe->id_groupe) {
					if ($axosection=='item' && $row->catid && $row->sectionid){
						$gmacat = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'category',$row->catid);
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'section',$row->sectionid);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'content','all');
						if ($gmacat || $gmasec || $gmall) {
							$no=1;
						}
					}
					if ($axosection=='category' && $row->section){
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'section',$row->section);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'content','all');
						if ($gmasec || $gmall) {
							$no=1;
						}
					}
					if ($axosection=='section'){
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','edit','users',$parent,'content','all');
						if ($gmall) {
							$no=1;
						}
					}
					if (!$no) {
						if ($axosection=='content'){
							$editcheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , 'all', 'edit' );
						}else{
							$editcheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , $row->id, 'edit' );
						}
					}else{
						$editcheck = '<img src="images/tick.png" border="0" alt="'.JText::_( 'GMA_PHERIT' ).'" />';
					}
				}else {
					$editcheck = '<img src="images/publish_x.png" border="0" alt="'.JText::_( 'GMA_PREFUPUB' ).'" />';
				}
					$retourhtml .='<td style="text-align:center">'.$editcheck.'</td>';
					$no=0;
				}
				if ($publishown==1) {
					if ($groupe->id_groupe) {
					if ($axosection=='item' && $row->catid && $row->sectionid){
						$gmacat = fonctionGmaccess::checkgmaccess3('com_content','publishown','users',$parent,'category',$row->catid);
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','publishown','users',$parent,'section',$row->sectionid);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','publishown','users',$parent,'content','all');
						$gmacat2 = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'category',$row->catid);
						$gmasec2 = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'section',$row->sectionid);
						$gmall2 = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'content','all');
						if ($gmacat || $gmasec || $gmall || $gmacat2 || $gmasec2 || $gmall2) {
							$no=1;
						}
					}
					if ($axosection=='category' && $row->section){
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','publishown','users',$parent,'section',$row->section);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','publishown','users',$parent,'content','all');
						$gmasec2 = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'section',$row->section);
						$gmall2 = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'content','all');
						if ($gmasec || $gmall || $gmasec2 || $gmall2) {
							$no=1;
						}
					}
					if ($axosection=='section'){
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','publishown','users',$parent,'content','all');
						$gmall2 = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'content','all');
						if ($gmall || $gmall2) {
							$no=1;
						}
					}
					if (!$no) {
						if ($axosection=='content'){
							$publishowncheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , 'all', 'publishown' );
						}else{
							$publishowncheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , $row->id, 'publishown' );
						}
					}else{
						$publishowncheck = '<img src="images/tick.png" border="0" alt="'.JText::_( 'GMA_PHERIT' ).'" />';
					}
				}else {
					$publishowncheck = '<img src="images/publish_x.png" border="0" alt="'.JText::_( 'GMA_PREFUPUB' ).'" />';
				}
					$retourhtml .='<td style="text-align:center">'.$publishowncheck.'</td>';
					$no=0;
				}
				if ($publish==1) {
					if ($groupe->id_groupe) {
					if ($axosection=='item' && $row->catid && $row->sectionid){
						$gmacat = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'category',$row->catid);
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'section',$row->sectionid);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'content','all');
						if ($gmacat || $gmasec || $gmall) {
							$no=1;
						}
					}
					if ($axosection=='category' && $row->section){
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'section',$row->section);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'content','all');
						if ($gmasec || $gmall) {
							$no=1;
						}
					}
					if ($axosection=='section'){
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','publish','users',$parent,'content','all');
						if ($gmall) {
							$no=1;
						}
					}
					if (!$no) {
						if ($axosection=='content'){
							$publishcheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , 'all', 'publish' );
						}else{
							$publishcheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , $row->id, 'publish' );
						}
					}else{
						$publishcheck = '<img src="images/tick.png" border="0" alt="'.JText::_( 'GMA_PHERIT' ).'" />';
					}
				}else {
					$publishcheck = '<img src="images/publish_x.png" border="0" alt="'.JText::_( 'GMA_PREFUPUB' ).'" />';
				}
					$retourhtml .='<td style="text-align:center">'.$publishcheck.'</td>';
					$no=0;
				}
				if ($deleteown==1) {
					if ($groupe->id_groupe) {
					if ($axosection=='item' && $row->catid && $row->sectionid){
						$gmacat = fonctionGmaccess::checkgmaccess3('com_content','deleteown','users',$parent,'category',$row->catid);
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','deleteown','users',$parent,'section',$row->sectionid);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','deleteown','users',$parent,'content','all');
						$gmacat2 = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'category',$row->catid);
						$gmasec2 = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'section',$row->sectionid);
						$gmall2 = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'content','all');
						if ($gmacat || $gmasec || $gmall || $gmacat2 || $gmasec2 || $gmall2) {
							$no=1;
						}
					}
					if ($axosection=='category' && $row->section){
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','deleteown','users',$parent,'section',$row->section);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','deleteown','users',$parent,'content','all');
						$gmasec2 = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'section',$row->section);
						$gmall2 = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'content','all');
						if ($gmasec || $gmall || $gmasec2 || $gmall2) {
							$no=1;
						}
					}
					if ($axosection=='section'){
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','deleteown','users',$parent,'content','all');
						$gmall2 = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'content','all');
						if ($gmall || $gmall2) {
							$no=1;
						}
					}
					if (!$no) {
						if ($axosection=='content'){
							$deleteowncheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , 'all', 'deleteown' );
						}else{
							$deleteowncheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , $row->id, 'deleteown' );
						}
					}else{
						$deleteowncheck = '<img src="images/tick.png" border="0" alt="'.JText::_( 'GMA_PHERIT' ).'" />';
					}
				}else {
					$deleteowncheck = '<img src="images/publish_x.png" border="0" alt="'.JText::_( 'GMA_PREFUPUB' ).'" />';
				}
					$retourhtml .='<td style="text-align:center">'.$deleteowncheck.'</td>';
					$no=0;
				}
				if ($delete==1) {
					if ($groupe->id_groupe) {
					if ($axosection=='item' && $row->catid && $row->sectionid){
						$gmacat = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'category',$row->catid);
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'section',$row->sectionid);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'content','all');
						if ($gmacat || $gmasec || $gmall) {
							$no=1;
						}
					}
					if ($axosection=='category' && $row->section){
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'section',$row->section);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'content','all');
						if ($gmasec || $gmall) {
							$no=1;
						}
					}
					if ($axosection=='section'){
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','delete','users',$parent,'content','all');
						if ($gmall) {
							$no=1;
						}
					}
					if (!$no) {
						if ($axosection=='content'){
							$deletecheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , 'all', 'delete' );
						}else{
							$deletecheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , $row->id, 'delete' );
						}
					}else{
						$deletecheck = '<img src="images/tick.png" border="0" alt="'.JText::_( 'GMA_PHERIT' ).'" />';
					}
				}else {
					$deletecheck = '<img src="images/publish_x.png" border="0" alt="'.JText::_( 'GMA_PREFUPUB' ).'" />';
				}
					$retourhtml .='<td style="text-align:center">'.$deletecheck.'</td>';
					$no=0;
				}
				if ($right==1) {
					if ($groupe->id_groupe) {
					if ($axosection=='item' && $row->catid && $row->sectionid){
						$gmacat = fonctionGmaccess::checkgmaccess3('com_content','right','users',$parent,'category',$row->catid);
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','right','users',$parent,'section',$row->sectionid);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','right','users',$parent,'content','all');
						if ($gmacat || $gmasec || $gmall) {
							$no=1;
						}
					}
					if ($axosection=='category' && $row->section){
						$gmasec = fonctionGmaccess::checkgmaccess3('com_content','right','users',$parent,'section',$row->section);
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','right','users',$parent,'content','all');
						if ($gmasec || $gmall) {
							$no=1;
						}
					}
					if ($axosection=='section'){
						$gmall = fonctionGmaccess::checkgmaccess3('com_content','right','users',$parent,'content','all');
						if ($gmall) {
							$no=1;
						}
					}
					if (!$no) {
						if ($axosection=='content'){
							$rightcheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , 'all', 'right' );
						}else{
							$rightcheck 	= fonctionGmaccess::GMProcessing( $groupe, $tot, $groupe->id_groupe, $axosection , $row->id, 'right' );
						}
					}else{
						$rightcheck = '<img src="images/tick.png" border="0" alt="'.JText::_( 'GMA_PHERIT' ).'" />';
					}
				}else {
					$rightcheck = '<img src="images/publish_x.png" border="0" alt="'.JText::_( 'GMA_PREFUPUB' ).'" />';
				}
					$retourhtml .='<td style="text-align:center">'.$rightcheck.'</td>';
					$no=0;
				}
				$retourhtml .='</tr>';
				//inutile $i += 1;
			}
		}
		$retourhtml .='</table>';

		if ($propa && !$ajax) {
			if ($propa=='sec'){
				//JHTML::_('select.booleanlist',  'published', '', $row->published );
				$yes = JHTML::_( 'select.booleanlist', 'propasec', ' onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'propasec1\').checked==1){document.getElementById(\'methode\').style.display = \'block\'; }else{ document.getElementById(\'methode\').style.display = \'none\';}" class="inputbox"', 0 );
			}elseif ($propa=='cat'){
				$yes = JHTML::_( 'select.booleanlist', 'propacat', ' onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'propacat1\').checked==1){document.getElementById(\'methode\').style.display = \'block\'; }else{ document.getElementById(\'methode\').style.display = \'none\';}" class="inputbox"', 0 );			
			}else{
				$yes = JHTML::_( 'select.booleanlist', 'propamenu', ' onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'propamenu1\').checked==1){document.getElementById(\'methode\').style.display = \'block\'; }else{ document.getElementById(\'methode\').style.display = \'none\';}" class="inputbox"', 0 );		
			}
			$retourhtml .=JText::_( 'GMA_PPROPA' ).' : '.$yes;
			$methode =  JHTML::_( 'select.booleanlist', 'methode', 'class="inputbox"', 0 ,JText::_( 'GMA_PABSOLU' ),JText::_( 'GMA_PHIERA' ));
			$retourhtml .='<div id="methode" style="display:none;">'.JText::_( 'GMA_PMETHODE' ).' : '.$methode.'</br>';
			if ($propa=='sec'){
				$retourhtml .=JText::_( 'GMA_PPROPAC' ).' : <input type="checkbox" name="catpropa" id="catpropa" checked  value="1" /> '.JText::_( 'GMA_PPROPCAT' ).'  <input type="checkbox" name="artpropa" id="artpropa" checked  value="1" /> '.JText::_( 'GMA_PPROPART' );
			}
			$retourhtml .='</div></br>';
		}
		return $retourhtml;
	}


	//gmaccess cette fonction construit les cases  cocher et rcupre les valeurs existantes
	function GMProcessing( &$row, $tot, $i, $axosection, $axo, $aco, $access=3 ) {
	
		$db =& JFactory::getDBO();
		
		$public = ($access==0) ? 'checked' : '';
		$membre = ($access==1) ? 'checked' : '';
		$membresta = ($access==0) ? 'disabled' : '';
		if ($access==0) {
			$publicimage =  'checked.gif';
			$membreimage = 'checkedg.gif';
		}
		if ($access==1) {
			$publicimage =  'non_checked.gif';
			$membreimage = 'checked.gif';
		}
		if ($access==3) {
			$publicimage =  'non_checked.gif';
			$membreimage = 'non_checked.gif';
		}
		$enfant = fonctionGmaccess::mgenfant( $row->id_groupe );
		$parent = fonctionGmaccess::mgparent( $row->id_groupe );
		$parent2 = fonctionGmaccess::mgparent2( $row->id_groupe );
		if ($aco=='read') {
			if ($row->id_groupe==0) {

				$href2 = '<img src="images/'. $publicimage .'" border="0" id="publici'.$aco.'" alt="'.JText::_( 'GMA_PCHANGER' ).'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'public'.$aco.'\').disabled==false) {document.getElementById(\'public'.$aco.'\').checked = !document.getElementById(\'public'.$aco.'\').checked;if(document.getElementById(\'public'.$aco.'\').checked==true){this.src =\'images/checked.gif\'}else{if(document.getElementById(\'public'.$aco.'\').disabled==true){ this.src =\'images/checkedg.gif\'}else{this.src =\'images/non_checked.gif\'}}testacl1( \''.$aco.'\','.$tot.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="access" id="public'.$aco.'"  class="inputbox" style="display:none;"  '.$public.'  value="0" />';
			}elseif ($row->id_groupe==1) {

				$href2 = '<img src="images/'. $membreimage .'" border="0" id="membrei'.$aco.'" alt="'.JText::_( 'GMA_PCHANGER' ).'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'membre'.$aco.'\').disabled==false) {document.getElementById(\'membre'.$aco.'\').checked = !document.getElementById(\'membre'.$aco.'\').checked;if(document.getElementById(\'membre'.$aco.'\').checked==true){this.src =\'images/checked.gif\'}else{if(document.getElementById(\'membre'.$aco.'\').disabled==true){ this.src =\'images/checkedg.gif\'}else{this.src =\'images/non_checked.gif\'}}testacl2( \''.$aco.'\','.$tot.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="access" id="membre'.$aco.'"  class="inputbox" style="display:none;" '.$membresta.'  '.$membre.'  value="1" />';
			}else{
				if ($axosection == 'component') {
					$comprow =& JTable::getInstance('component');
					//$row = new mosMambot( $database );
					$comprow->load( $axo );
					$db->setQuery("SELECT count(*) FROM #__gm_groupe"
					. "\n LEFT JOIN #__gmacl AS g ON id_groupe = g.aro"
					. "\n WHERE id_groupe = $row->id_groupe"
					. "\n AND g.acosection = '".$comprow->option."'"
					. "\n AND g.aco = 'read'"
					//. "\n AND g.axosection = '".$axosection."'"
					);
					$total = $db->loadResult();
				} elseif ($axosection == 'componenturl') {
					$query = "SELECT * FROM #__gmaccess WHERE id = ".$axo; 
					$db->setQuery( $query);
	
					$compurl = $db->loadObject();
					$db->setQuery("SELECT count(*) FROM #__gm_groupe"
					. "\n LEFT JOIN #__gmacl AS g ON id_groupe = g.aro"
					. "\n WHERE id_groupe = $row->id_groupe"
					. "\n AND g.acosection = '".$compurl->acosection."'"
					. "\n AND g.aco = '".$compurl->aco."'"
					. "\n AND g.axosection = '".$compurl->axosection."'"
					. "\n AND g.axo = '".$compurl->axo."'"
					);
					$total = $db->loadResult();
				} else {
					$db->setQuery("SELECT count(*) FROM #__gm_groupe"
					. "\n LEFT JOIN #__gmacl AS g ON id_groupe = g.aro"
					. "\n WHERE id_groupe = $row->id_groupe"
					. "\n AND g.aco = '".$aco."'"
					. "\n AND g.axo = '".$axo."'"
					. "\n AND g.axosection = '".$axosection."'"
					);
					$total = $db->loadResult();
				}
				if ($access==3) {
					$test  = $total ? 'checked' : '';
				}else{
					$test  = '';
				}
				//$img 	= $total ? 'checked.gif' : 'non_checked.gif';
				//$task 	= $total ? 'ungmread' : 'gmread';
				$alt 	= JText::_( 'GMA_PCHANGER' );
				$action	= $total ? 'Interdire' : 'Autoriser';
				//$gma = checkgmaccess('action',$aco,'users',$parent2,$axosection,$axo);
				if ($axosection == 'component') {
					$gma = fonctionGmaccess::checkgmaccess($comprow->option,'read','users',$parent2);
				} elseif ($axosection == 'componenturl') {
					$gma = fonctionGmaccess::checkgmaccess4($compurl->acosection,$compurl->aco,'users',$parent2,$compurl->axosection,$compurl->axo);
				} else {
					$gma = fonctionGmaccess::checkgmaccess3('com_content',$aco,'users',$parent2,$axosection,$axo);
				}
				
			
				//$test2  = ($gma && !$total) ? 'disabled' : '';
				$test2  = (($gma || $access<=1) && !$total) ? 'disabled' : '';
				//$test2  = ($gma && !$total) ? 'disabled' : '';
				if ($test2=='disabled'){
					$img = 'checkedg.gif';
				}else{
					$img 	= $total ? 'checked.gif' : 'non_checked.gif';
				}
			$js = fonctionGmaccess::conv_gma($enfant,'id');
	

			$href2 = '<img src="images/'. $img .'" border="0" id="ci'.$aco.$i.'" alt="'. $alt .'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'cb'.$aco.$i.'\').disabled==false) {'.$js.'document.getElementById(\'cb'.$aco.$i.'\').checked = !document.getElementById(\'cb'.$aco.$i.'\').checked;if(document.getElementById(\'cb'.$aco.$i.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}if(document.getElementById(\'cb'.$aco.$i.'\').checked==true) {for ( var j = 0; j <= i; j++ ) {if (document.getElementById(\'cb'.$aco.'\' + id[j])) {document.getElementById(\'cb'.$aco.'\' + id[j]).disabled=true; document.getElementById(\'cb'.$aco.'\' + id[j]).checked=false;}}}else{for ( var j = 0; j <= i; j++ ) {if (document.getElementById(\'cb'.$aco.'\' + id[j])) document.getElementById(\'cb'.$aco.'\' + id[j]).disabled=false;}}testacl3( \''.$aco.'\','.$i.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="'.$aco.$row->id_groupe.'" '.$test2.' id="cb'.$aco.$i.'" class="inputbox" style="display:none;"  '.$test.' value="1" />';
			}
		}elseif ($aco=='edit' OR $aco=='publish' OR $aco=='delete') {
			$db->setQuery("SELECT count(*) FROM #__gm_groupe"
				. "\n LEFT JOIN #__gmacl AS g ON id_groupe = g.aro"
				. "\n WHERE id_groupe = $row->id_groupe"
				. "\n AND g.aco = '".$aco."'"
				. "\n AND g.axo = '".$axo."'"
				. "\n AND g.axosection = '".$axosection."'"
				);
    			$total = $db->loadResult();
			
				$test  = $total ? 'checked' : '';
				$gma = fonctionGmaccess::checkgmaccess3('com_content',$aco,'users',$parent,$axosection,$axo);
				//$test2  = ($gma && !$total) ? 'disabled' : '';
				$test2  = ($gma && !$total) ? 'disabled' : '';
				if ($test2=='disabled'){
					$img = 'checkedg.gif';
				}else{
					$img 	= $total ? 'checked.gif' : 'non_checked.gif';
				}
			
			//$task 	= $total ? 'ungmread' : 'gmread';
			$alt 	= JText::_( 'GMA_PCHANGER' );
			$action	= $total ? 'Interdire' : 'Autoriser';
			
			$js = fonctionGmaccess::conv_gma($enfant,'id');
   			//$js .= "alert(id[0]);";
			if ($row->id_groupe==0) {

				$href2 = '<img src="images/'. $img .'" border="0" id="publici'.$aco.'" alt="'.JText::_( 'GMA_PCHANGER' ).'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'public'.$aco.'\').disabled==false) {document.getElementById(\'public'.$aco.'\').checked = !document.getElementById(\'public'.$aco.'\').checked;if(document.getElementById(\'public'.$aco.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}testacl4( \''.$aco.'\','.$tot.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="'.$aco.$row->id_groupe.'" id="public'.$aco.'" class="inputbox" '.$test2.' style="display:none;" '.$test.'  value="1" />';
			}elseif ($row->id_groupe==1) {

				$href2 = '<img src="images/'. $img .'" border="0" id="membrei'.$aco.'" alt="'.JText::_( 'GMA_PCHANGER' ).'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'membre'.$aco.'\').disabled==false) {document.getElementById(\'membre'.$aco.'\').checked = !document.getElementById(\'membre'.$aco.'\').checked;if(document.getElementById(\'membre'.$aco.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}testacl5( \''.$aco.'\','.$tot.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="'.$aco.$row->id_groupe.'" id="membre'.$aco.'" class="inputbox" '.$test2.' style="display:none;" '.$test.'  value="1" />';
			}else{

				$href2 = '<img src="images/'. $img .'" border="0" id="ci'.$aco.$i.'" alt="'. $alt .'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'cb'.$aco.$i.'\').disabled==false) {'.$js.'document.getElementById(\'cb'.$aco.$i.'\').checked = !document.getElementById(\'cb'.$aco.$i.'\').checked;if(document.getElementById(\'cb'.$aco.$i.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}if(document.getElementById(\'cb'.$aco.$i.'\').checked==true) {for ( var j = 0; j <= i; j++ ) {if (document.getElementById(\'cb'.$aco.'\' + id[j])) {document.getElementById(\'cb'.$aco.'\' + id[j]).disabled=true; document.getElementById(\'cb'.$aco.'\' + id[j]).checked=false;}if (document.getElementById(\'cb'.$aco.'own\' + id[j])) {document.getElementById(\'cb'.$aco.'own\' + id[j]).disabled=true; document.getElementById(\'cb'.$aco.'own\' + id[j]).checked=false;}}}else{for ( var j = 0; j <= i; j++ ) {if (document.getElementById(\'cb'.$aco.'\' + id[j])) document.getElementById(\'cb'.$aco.'\' + id[j]).disabled=false;if (document.getElementById(\'cb'.$aco.'own\' + id[j])) document.getElementById(\'cb'.$aco.'own\' + id[j]).disabled=false;}}testacl6( \''.$aco.'\','.$i.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="'.$aco.$row->id_groupe.'" '.$test2.' id="cb'.$aco.$i.'" class="inputbox" style="display:none;" '.$test.' value="1" />';
			}
	
			
		}elseif ($aco=='editown' OR $aco=='publishown' OR $aco=='deleteown') {
			$db->setQuery("SELECT count(*) FROM #__gm_groupe"
				. "\n LEFT JOIN #__gmacl AS g ON id_groupe = g.aro"
				. "\n WHERE id_groupe = $row->id_groupe"
				. "\n AND g.aco = '".$aco."'"
				. "\n AND g.axo = '".$axo."'"
				. "\n AND g.axosection = '".$axosection."'"
				);
    			$total = $db->loadResult();
			
				$test  = $total ? 'checked' : '';
				$gma = fonctionGmaccess::checkgmaccess3('com_content',$aco,'users',$parent,$axosection,$axo);
				$aco2 = str_replace('own','',$aco);
				$gma2 = fonctionGmaccess::checkgmaccess3('com_content',$aco2,'users',$parent,$axosection,$axo);
				$db->setQuery("SELECT count(*) FROM #__gm_groupe"
				. "\n LEFT JOIN #__gmacl AS g ON id_groupe = g.aro"
				. "\n WHERE id_groupe = $row->id_groupe"
				. "\n AND g.aco = '".$aco2."'"
				. "\n AND g.axo = '".$axo."'"
				. "\n AND g.axosection = '".$axosection."'"
				);
    			$total2 = $db->loadResult();
				$test3  = ($total2 || ($gma && !$total) || $gma2) ? 'disabled' : '';
				$test2  = $total2 ? 'disabled' : '';
				if ($test3=='disabled'){
					$img = 'checkedg.gif';
				}else{
					$img 	= $total ? 'checked.gif' : 'non_checked.gif';
				}
			
			//$task 	= $total ? 'ungmread' : 'gmread';
			$alt 	= JText::_( 'GMA_PCHANGER' );
			$action	= $total ? 'Interdire' : 'Autoriser';
			$js = fonctionGmaccess::conv_gma($enfant,'id');
			if ($row->id_groupe==0) {

				$href2 = '<img src="images/'. $img .'" border="0" id="publici'.$aco.'" alt="'.JText::_( 'GMA_PCHANGER' ).'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'public'.$aco.'\').disabled==false) {document.getElementById(\'public'.$aco.'\').checked = !document.getElementById(\'public'.$aco.'\').checked;if(document.getElementById(\'public'.$aco.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}testacl7( \''.$aco.'\',\''.$aco2.'\','.$tot.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="'.$aco.$row->id_groupe.'" '.$test2.' id="public'.$aco.'" class="inputbox" style="display:none;" '.$test.'  value="1" />';
			}elseif ($row->id_groupe==1) {

				$href2 = '<img src="images/'. $img .'" border="0" id="membrei'.$aco.'" alt="'.JText::_( 'GMA_PCHANGER' ).'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'membre'.$aco.'\').disabled==false) {document.getElementById(\'membre'.$aco.'\').checked = !document.getElementById(\'membre'.$aco.'\').checked;if(document.getElementById(\'membre'.$aco.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}testacl8( \''.$aco.'\',\''.$aco2.'\','.$tot.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="'.$aco.$row->id_groupe.'" '.$test2.' id="membre'.$aco.'" class="inputbox" style="display:none;" '.$test.'  value="1" />';
			}else{

				
				$href2 = '<img src="images/'. $img .'" border="0" id="ci'.$aco.$i.'" alt="'. $alt .'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'cb'.$aco.$i.'\').disabled==false) {'.$js.'document.getElementById(\'cb'.$aco.$i.'\').checked = !document.getElementById(\'cb'.$aco.$i.'\').checked;if(document.getElementById(\'cb'.$aco.$i.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}if(document.getElementById(\'cb'.$aco.$i.'\').checked==true) {for ( var j = 0; j <= i; j++ ) {if (document.getElementById(\'cb'.$aco.'\' + id[j])) {document.getElementById(\'cb'.$aco.'\' + id[j]).disabled=true; document.getElementById(\'cb'.$aco.'\' + id[j]).checked=false;}}}else{for ( var j = 0; j <= i; j++ ) {if (document.getElementById(\'cb'.$aco.'\' + id[j])) document.getElementById(\'cb'.$aco.'\' + id[j]).disabled=false;}}testacl9( \''.$aco.'\','.$i.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="'.$aco.$row->id_groupe.'" '.$test3.' id="cb'.$aco.$i.'" class="inputbox" style="display:none;" '.$test.' value="1" />';

			}
	
			
		}else{
			$db->setQuery("SELECT count(*) FROM #__gm_groupe"
				. "\n LEFT JOIN #__gmacl AS g ON id_groupe = g.aro"
				. "\n WHERE id_groupe = $row->id_groupe"
				. "\n AND g.aco = '".$aco."'"
				
				. "\n AND g.axo = '".$axo."'"
				
				. "\n AND g.axosection = '".$axosection."'"
				);
    			$total = $db->loadResult();
			
				$test  = $total ? 'checked' : '';
				$gma = fonctionGmaccess::checkgmaccess3('com_content',$aco,'users',$parent,$axosection,$axo);
				//$test2  = ($gma && !$total) ? 'disabled' : '';
				$test2  = ($gma && !$total) ? 'disabled' : '';
				if ($test2=='disabled'){
					$img = 'checkedg.gif';
				}else{
					$img 	= $total ? 'checked.gif' : 'non_checked.gif';
				}
			//$task 	= $total ? 'ungmread' : 'gmread';
			$alt 	= JText::_( 'GMA_PCHANGER' );
			$action	= $total ? 'Interdire' : 'Autoriser';
			$js = fonctionGmaccess::conv_gma($enfant,'id');
			if ($row->id_groupe==0) {

				$href2 = '<img src="images/'. $img .'" border="0" id="publici'.$aco.'" alt="'.JText::_( 'GMA_PCHANGER' ).'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'public'.$aco.'\').disabled==false) {document.getElementById(\'public'.$aco.'\').checked = !document.getElementById(\'public'.$aco.'\').checked;if(document.getElementById(\'public'.$aco.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}testacl10( \''.$aco.'\','.$tot.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="'.$aco.$row->id_groupe.'" id="public'.$aco.'" '.$test2.' class="inputbox" style="display:none;" '.$test.'  value="1" />';
			}elseif ($row->id_groupe==1) {

				$href2 = '<img src="images/'. $img .'" border="0" id="membrei'.$aco.'" alt="'.JText::_( 'GMA_PCHANGER' ).'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'membre'.$aco.'\').disabled==false) {document.getElementById(\'membre'.$aco.'\').checked = !document.getElementById(\'membre'.$aco.'\').checked;if(document.getElementById(\'membre'.$aco.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}testacl11( \''.$aco.'\','.$tot.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="'.$aco.$row->id_groupe.'" id="membre'.$aco.'" '.$test2.' class="inputbox" style="display:none;" '.$test.'  value="1" />';
			}else{

				$href2 = '<img src="images/'. $img .'" border="0" id="ci'.$aco.$i.'" alt="'. $alt .'" onclick="document.getElementById(\'change\').checked=true;if (document.getElementById(\'cb'.$aco.$i.'\').disabled==false) {'.$js.'document.getElementById(\'cb'.$aco.$i.'\').checked = !document.getElementById(\'cb'.$aco.$i.'\').checked;if(document.getElementById(\'cb'.$aco.$i.'\').checked==true){this.src =\'images/checked.gif\'}else{this.src =\'images/non_checked.gif\'}if(document.getElementById(\'cb'.$aco.$i.'\').checked==true) {for ( var j = 0; j <= i; j++ ) {if (document.getElementById(\'cb'.$aco.'\' + id[j])) {document.getElementById(\'cb'.$aco.'\' + id[j]).disabled=true; document.getElementById(\'cb'.$aco.'\' + id[j]).checked=false;}}}else{for ( var j = 0; j <= i; j++ ) {if (document.getElementById(\'cb'.$aco.'\' + id[j])){ document.getElementById(\'cb'.$aco.'\' + id[j]).disabled=false;}}}testacl12( \''.$aco.'\','.$i.' );gmimage( '.$tot.' )}" /><input type="checkbox" name="'.$aco.$row->id_groupe.'" '.$test2.' id="cb'.$aco.$i.'" class="inputbox" style="display:none;" '.$test.' value="1" />';
			}
	
			
		}
		/* inutile $href = '
		<a href="javascript: void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''. $task .'\')" title="'. $action .'">
		<img src="images/'. $img .'" border="0" alt="'. $alt .'" onclick="" />
		</a>'
		;*/
		return $href2;
		//return $submit;
		
	}

//gmaccess fonction : dtermine la liste des groupes dont l'utilisateur est membre.
function myaccess( $id ) {
	
	$db =& JFactory::getDBO();
	
	$gmidfinal = array (0,1);
	
	$query = "SELECT id_groupe"
			. "\nFROM #__gm_membre"
			. "\nWHERE id_membre='".$id."'"
			;
	$db->setQuery( $query );
	//charger le rsultat dans un tableau
	$gmidverif = $db->loadResultArray();
	if ( !is_array($gmidverif) ) {
				$gmidverif = array();
			}
	//ajoute les valeurs  gmidfinal
	$gmidfinal = array_merge ($gmidfinal,$gmidverif);
	$gmidfinal = array_unique ($gmidfinal);
	
	//boucle de recherche des groupes imbriqus
	while ( sizeof($gmidverif) != 0 ) {
		$gmidinitial = $gmidfinal;
		//pour chaque groupe trouv
		foreach ( $gmidverif as $row ) {
			$query2 = "SELECT id_groupe"
			. "\nFROM #__gm_groupeimbrique"
			. "\nWHERE id_groupeimbrique='".$row."'"
			;
			$db->setQuery( $query2 );
			//charger le rsultat dans un tableau
			$gmidtrouve = $db->loadResultArray();
			if ( !is_array($gmidtrouve) ) {
				$gmidtrouve = array();
			}
			$gmidfinal = array_merge ($gmidfinal,$gmidtrouve);
			$gmidfinal = array_unique ($gmidfinal);
		}
		$gmidverif = array_diff ($gmidfinal,$gmidinitial);
	}
	
	//renvoie la valeure textuelle
	$gmidfinal= implode (",",$gmidfinal);
	return $gmidfinal;
			
}


//gmaccess fonction : dtermine la liste des groupes enfants pour un groupe donn.
function mgenfant( $id ) {
	
	$db =& JFactory::getDBO();
	
	$gmidfinal = array ();
	
	$query = "SELECT id_groupeimbrique"
			. "\nFROM #__gm_groupeimbrique"
			. "\nWHERE id_groupe='".$id."'"
			;
	$db->setQuery( $query );
	//charger le rsultat dans un tableau
	$gmidverif = $db->loadResultArray();
	if ( !is_array($gmidverif) ) {
				$gmidverif = array();
			}
	//ajoute les valeurs  gmidfinal
	$gmidfinal = array_merge ($gmidfinal,$gmidverif);
	$gmidfinal = array_unique ($gmidfinal);
	
	//boucle de recherche des groupes imbriqus
	while ( sizeof($gmidverif) != 0 ) {
		$gmidinitial = $gmidfinal;
		//pour chaque groupe trouv
		foreach ( $gmidverif as $row ) {
			$query2 = "SELECT id_groupeimbrique"
			. "\nFROM #__gm_groupeimbrique"
			. "\nWHERE id_groupe='".$row."'"
			;
			$db->setQuery( $query2 );
			//charger le rsultat dans un tableau
			$gmidtrouve = $db->loadResultArray();
			if ( !is_array($gmidtrouve) ) {
				$gmidtrouve = array();
			}
			$gmidfinal = array_merge ($gmidfinal,$gmidtrouve);
			$gmidfinal = array_unique ($gmidfinal);
		}
		$gmidverif = array_diff ($gmidfinal,$gmidinitial);
	}
	
	//renvoie la valeure textuelle
	//$gmidfinal= implode (",",$gmidfinal);
	return $gmidfinal;
			
}
//gmaccess fonction : contrle si l'accs d'un objet ($access) est dans la liste des groupes ($myaccess) de l'utilisateur.
function checkaccess ( $access, $myaccess ) {
	$access_array = explode( ",", $myaccess );
	return in_array( $access, $access_array );
}


// fonction qui dtermine si un groupe ou utilisateur ($aro_value = liste de groupes) a un droit (aco) sur un objet donn (axo-section + axo).
function checkgmaccess3( $aco_section_value, $aco_value,
		$aro_section_value, $aro_value, $axo_section_value=NULL, $axo_value=NULL ) {
		$db =& JFactory::getDBO();

		$query = "SELECT id"
			. "\nFROM #__gmacl"
			. "\nWHERE acosection='".$aco_section_value."'"
			. "\nAND aco='".$aco_value."'"
			. "\nAND arosection='".$aro_section_value."'"
			. "\nAND aro IN ($aro_value)"
			.  "\nAND axosection='".$axo_section_value."'"
			.  "\nAND axo='".$axo_value."'"

			//. "\nAND axosection='".$axo_section_value."'"
			//. "\nAND axo='".$axo_value."'"
			;
		$db->setQuery( $query );
		$gmacl = $db->loadObjectList();
		$nbacl = count( $gmacl );
		if ( !$nbacl ) {
			$acl_result = 0;
		}else{
			$acl_result = 1;
		}
		return $acl_result;
	}
	//fin gmaccess
function checkgmaccess4( $aco_section_value, $aco_value,
		$aro_section_value, $aro_value, $axo_section_value='', $axo_value='' ) {
		$db =& JFactory::getDBO();

		$query = "SELECT id"
			. "\nFROM #__gmacl"
			. "\nWHERE acosection='".$aco_section_value."'"
			. "\nAND aco='".$aco_value."'"
			. "\nAND arosection='".$aro_section_value."'"
			. "\nAND aro IN ($aro_value)"
			.  "\nAND axosection='".$axo_section_value."'"
			.  "\nAND axo='".$axo_value."'"

			;
		$db->setQuery( $query );
		$gmacl = $db->loadObjectList();
		$nbacl = count( $gmacl );
		if ( !$nbacl ) {
			$acl_result = 0;
		}else{
			$acl_result = 1;
		}
		return $acl_result;
	}


// fonction qui dtermine si un groupe ou utilisateur ($aro_value = liste de groupes) a un droit (aco) sur un objet donn (axo-section + axo).
function checkgmaccess2( $aco_section_value, $aco_value,
		$aro_section_value, $aro_value, $axo_section_value=NULL, $axo_value=NULL ) {
		$db =& JFactory::getDBO();
		if ($axo_section_value=='item') {
			$table = '#__content';
		}elseif ($axo_section_value=='category') {
			$table = '#__categories';
		}elseif ($axo_section_value=='section') {
			$table = '#__sections';
		
		}elseif ($axo_section_value=='module') {
			$table = '#__modules';
		}elseif ($axo_section_value=='menu') {
			$table = '#__menu';
		}elseif ($axo_section_value=='plugin') {
			$table = '#__plugins';
		}elseif ($axo_section_value=='contact') {
			$table = '#__contact_details';
		}
		$query2 = "SELECT access"
			. "\nFROM ".$table
			. "\nWHERE id='".$axo_value."'"
			;
		$db->setQuery( $query2 );
		$acl = $db->loadResult();
		if ($acl==3) {
			$query = "SELECT id"
			. "\nFROM #__gmacl"
			. "\nWHERE acosection='".$aco_section_value."'"
			. "\nAND aco='".$aco_value."'"
			. "\nAND arosection='".$aro_section_value."'"
			. "\nAND aro IN ($aro_value)"
			. "\nAND axosection='".$axo_section_value."'"
			. "\nAND axo='".$axo_value."'"
			;
			$db->setQuery( $query );
			$gmacl = $db->loadObjectList();
			$nbacl = count( $gmacl );
			if ( !$nbacl ) {
				$acl_result = 0;
			}else{
				$acl_result = 1;
			}
		}else{
			$acl_result = fonctionGmaccess::checkaccess ( $acl, $aro_value );
		}
		
		return $acl_result;
	}
	//fin gmaccess

	//gmaccess cette fonction enregistre les accs dans la base
function savegmaccess( $row, $axosection ) {
		global $mainframe;
		$db =& JFactory::getDBO();
		$db->setQuery ("DELETE FROM #__gmacl WHERE axosection='".$axosection."' AND axo=$row->id");
		$db->query();
		$query = "SELECT id_groupe"
		. "\n FROM #__gm_groupe"
		//. "\n AND access_groupe<>2"
		. "\n ORDER BY id_groupe ASC"
		;
		$db->setQuery( $query );
		$gmaccessgroupe = $db->loadObjectList();
		foreach ($gmaccessgroupe as $gmaccess){
		
			if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'read', 'users', $gmaccess->id_groupe, '".$axosection."', $row->id)");
			$db->query();
			}
			if ( JRequest::getVar('submit'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'submit', 'users', $gmaccess->id_groupe, '".$axosection."', $row->id)");
			$db->query();
			}
			if ( JRequest::getVar('editown'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'editown', 'users', $gmaccess->id_groupe, '".$axosection."', $row->id)");
			$db->query();
			}
			if ( JRequest::getVar('edit'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'edit', 'users', $gmaccess->id_groupe, '".$axosection."', $row->id)");
			$db->query();
			}
			if ( JRequest::getVar('publishown'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'publishown', 'users', $gmaccess->id_groupe, '".$axosection."', $row->id)");
			$db->query();
			}
			if ( JRequest::getVar('publish'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'publish', 'users', $gmaccess->id_groupe, '".$axosection."', $row->id)");
			$db->query();
			}
			if ( JRequest::getVar('deleteown'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'deleteown', 'users', $gmaccess->id_groupe, '".$axosection."', $row->id)");
			$db->query();
			}
			if ( JRequest::getVar('delete'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'delete', 'users', $gmaccess->id_groupe, '".$axosection."', $row->id)");
			$db->query();
			}
			if ( JRequest::getVar('right'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'right', 'users', $gmaccess->id_groupe, '".$axosection."', $row->id)");
			$db->query();
			}
		}
		
		if ($axosection == 'component') {
				$access 	= JRequest::getVar('access', 3);
				if ($access == 1) {
					$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'read', 'users', $access, 'component', $row->id)");
					$db->query();
				}
		}
		$propasec 	= JRequest::getVar('propasec', '');
		$propacat 	= JRequest::getVar('propacat', '');
		$propamenu	= JRequest::getVar('propamenu', '');
		$methode	= JRequest::getVar('methode', '');
		$catpropa	= JRequest::getVar('catpropa', '');
		$artpropa	= JRequest::getVar('artpropa', '');
		if ( $propasec ){
			if ( $catpropa ){
				$query = "SELECT *"
				. "\n FROM #__categories"
				. "\n WHERE section=$row->id"
				. "\n ORDER BY id ASC"
				;
				$db->setQuery( $query );
				$categories = $db->loadObjectList();
				fonctionGmaccess::propagecategorie($row, $categories, $gmaccessgroupe);
			}
			if ( $artpropa ){
				$query = "SELECT *"
				. "\n FROM #__content"
				. "\n WHERE sectionid=$row->id"
				. "\n ORDER BY id ASC"
				;
				$db->setQuery( $query );
				$articles = $db->loadObjectList();
				fonctionGmaccess::propagearticle($row, $articles, $gmaccessgroupe);
			}
			
		}
		if ( $propacat ){
				$query = "SELECT *"
				. "\n FROM #__content"
				. "\n WHERE catid=$row->id"
				. "\n ORDER BY id ASC"
				;
				$db->setQuery( $query );
				$articles = $db->loadObjectList();
				fonctionGmaccess::propagearticle2($row, $articles, $gmaccessgroupe);
		}
		if ( $propamenu ){
				$menu1 =& JTable::getInstance('module');
				
				// load the row from the db table
				$menu1->load( $row->id );
				$params = new JParameter( $menu1->params );
				$type = $params->get('menutype', 0);
				
				$query = "SELECT *"
				. "\n FROM #__menu"
				. "\n WHERE menutype='$type'"
				. "\n ORDER BY id ASC"
				;
				$db->setQuery( $query );
				$menus = $db->loadObjectList();
				fonctionGmaccess::propagemenu($row, $menus, $gmaccessgroupe, $type);
		}
		
		//$test = 'gmaccess OK';
		//return $test;
}
function savegmfrontaccess( $row, $axosection ) {
		global $mainframe;
		$db =& JFactory::getDBO();
		$db->setQuery ("DELETE FROM #__gmacl WHERE axosection='".$axosection."' AND axo=$row");
		$db->query();
		$query = "SELECT id_groupe"
		. "\n FROM #__gm_groupe"
		//. "\n AND access_groupe<>2"
		. "\n ORDER BY id_groupe ASC"
		;
		$db->setQuery( $query );
		$gmaccessgroupe = $db->loadObjectList();
		foreach ($gmaccessgroupe as $gmaccess){
		
			if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'read', 'users', $gmaccess->id_groupe, '".$axosection."', $row)");
			$db->query();
			}
			if ( JRequest::getVar('submit'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'submit', 'users', $gmaccess->id_groupe, '".$axosection."', $row)");
			$db->query();
			}
			if ( JRequest::getVar('editown'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'editown', 'users', $gmaccess->id_groupe, '".$axosection."', $row)");
			$db->query();
			}
			if ( JRequest::getVar('edit'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'edit', 'users', $gmaccess->id_groupe, '".$axosection."', $row)");
			$db->query();
			}
			if ( JRequest::getVar('publishown'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'publishown', 'users', $gmaccess->id_groupe, '".$axosection."', $row)");
			$db->query();
			}
			if ( JRequest::getVar('publish'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'publish', 'users', $gmaccess->id_groupe, '".$axosection."', $row)");
			$db->query();
			}
			if ( JRequest::getVar('deleteown'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'deleteown', 'users', $gmaccess->id_groupe, '".$axosection."', $row)");
			$db->query();
			}
			if ( JRequest::getVar('delete'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'delete', 'users', $gmaccess->id_groupe, '".$axosection."', $row)");
			$db->query();
			}
			if ( JRequest::getVar('right'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'right', 'users', $gmaccess->id_groupe, '".$axosection."', $row)");
			$db->query();
			}
		}
		
}
//gmaccess cette fonction enregistre les accs dans la base
function savegmaccess2( $axosection ) {
		global $mainframe;
		$db =& JFactory::getDBO();
		$db->setQuery ("DELETE FROM #__gmacl WHERE axosection='".$axosection."' AND axo='all' AND acosection='com_content'");
		$db->query();
		$query = "SELECT id_groupe"
		. "\n FROM #__gm_groupe"
		//. "\n AND access_groupe<>2"
		. "\n ORDER BY id_groupe ASC"
		;
		$db->setQuery( $query );
		$gmaccessgroupe = $db->loadObjectList();
		foreach ($gmaccessgroupe as $gmaccess){
		
			
			if ( JRequest::getVar('add'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'add', 'users', $gmaccess->id_groupe, '".$axosection."', 'all')");
			$db->query();
			}
			if ( JRequest::getVar('editown'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'editown', 'users', $gmaccess->id_groupe, '".$axosection."', 'all')");
			$db->query();
			}
			if ( JRequest::getVar('edit'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'edit', 'users', $gmaccess->id_groupe, '".$axosection."', 'all')");
			$db->query();
			}
			if ( JRequest::getVar('publishown'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'publishown', 'users', $gmaccess->id_groupe, '".$axosection."', 'all')");
			$db->query();
			}
			if ( JRequest::getVar('publish'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'publish', 'users', $gmaccess->id_groupe, '".$axosection."', 'all')");
			$db->query();
			}
			if ( JRequest::getVar('deleteown'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'deleteown', 'users', $gmaccess->id_groupe, '".$axosection."', 'all')");
			$db->query();
			}
			if ( JRequest::getVar('delete'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'delete', 'users', $gmaccess->id_groupe, '".$axosection."', 'all')");
			$db->query();
			}
			if ( JRequest::getVar('right'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'right', 'users', $gmaccess->id_groupe, '".$axosection."', 'all')");
			$db->query();
			}
		}

		
		
		//$test = 'gmaccess OK';
		//return $test;
}

function propagecategorie($row, $categories, $gmaccessgroupe) {
	$db=& JFactory::getDBO();
	
	$methode	= JRequest::getVar('methode', '');
	if ($methode==0){//methode hirarchique
		$db->setQuery ("Update #__categories set access=$row->access where section=$row->id AND access<$row->access");
		$db->query();
		foreach ($gmaccessgroupe as $gmaccess){
				if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
					$parent = fonctionGmaccess::mgparent2( $gmaccess->id_groupe );
					foreach ($categories as $category){
						$db->setQuery ("Update #__gmacl set aro=$gmaccess->id_groupe where axosection='category' AND aco='read' AND axo=$category->id AND aro IN ($parent)");
						$db->query();
					}
				}
		}
		
	}elseif ($methode==1){//mthode absolue
		$db->setQuery ("Update #__categories set access=$row->access where section=$row->id");
		$db->query();
		foreach ($categories as $category){
			$db->setQuery ("DELETE FROM #__gmacl WHERE axosection='category' AND aco='read' AND axo=$category->id");
			$db->query();
			foreach ($gmaccessgroupe as $gmaccess){
				if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
					$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'read', 'users', $gmaccess->id_groupe, 'category', $category->id)");
					$db->query();
				}
			}
		}
	}

}
function propagearticle($row, $articles, $gmaccessgroupe) {
	$db=& JFactory::getDBO();
	
	$methode	= JRequest::getVar('methode', '');
	if ($methode==0){//methode hirarchique
		$db->setQuery ("Update #__content set access=$row->access where sectionid=$row->id AND access<$row->access");
		$db->query();
		foreach ($gmaccessgroupe as $gmaccess){
				if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
					$parent = fonctionGmaccess::mgparent2( $gmaccess->id_groupe );
					foreach ($articles as $article){
						$db->setQuery ("Update #__gmacl set aro=$gmaccess->id_groupe where axosection='item' AND aco='read' AND axo=$article->id AND aro IN ($parent)");
						$db->query();
					}
				}
		}
		
	}elseif ($methode==1){//mthode absolue
		$db->setQuery ("Update #__content set access=$row->access where sectionid=$row->id");
		$db->query();
		foreach ($articles as $article){
			$db->setQuery ("DELETE FROM #__gmacl WHERE axosection='item' AND aco='read' AND axo=$article->id");
			$db->query();
			foreach ($gmaccessgroupe as $gmaccess){
				if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
					$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'read', 'users', $gmaccess->id_groupe, 'item', $article->id)");
					$db->query();
				}
			}
		}
	}

}
function propagearticle2($row, $articles, $gmaccessgroupe) {
	$db=& JFactory::getDBO();
	
	$methode	= JRequest::getVar('methode', '');
	if ($methode==0){//methode hirarchique
		$db->setQuery ("Update #__content set access=$row->access where catid=$row->id AND access<$row->access");
		$db->query();
		foreach ($gmaccessgroupe as $gmaccess){
				if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
					$parent = fonctionGmaccess::mgparent2( $gmaccess->id_groupe );
					foreach ($articles as $article){
						$db->setQuery ("Update #__gmacl set aro=$gmaccess->id_groupe where axosection='item' AND aco='read' AND axo=$article->id AND aro IN ($parent)");
						$db->query();
					}
				}
		}
		
	}elseif ($methode==1){//mthode absolue
		$db->setQuery ("Update #__content set access=$row->access where catid=$row->id");
		$db->query();
		foreach ($articles as $article){
			$db->setQuery ("DELETE FROM #__gmacl WHERE axosection='item' AND aco='read' AND axo=$article->id");
			$db->query();
			foreach ($gmaccessgroupe as $gmaccess){
				if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
					$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'read', 'users', $gmaccess->id_groupe, 'item', $article->id)");
					$db->query();
				}
			}
		}
	}

}
function propagemenu($row, $menus, $gmaccessgroupe, $type) {
	$db=& JFactory::getDBO();
	
	$methode	= JRequest::getVar('methode', '');
	if ($methode==0){//methode hirarchique
		$db->setQuery ("Update #__menu set access=$row->access where menutype='$type' AND access<$row->access");
		$db->query();
		foreach ($gmaccessgroupe as $gmaccess){
				if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
					$parent = fonctionGmaccess::mgparent2( $gmaccess->id_groupe );
					foreach ($menus as $menu){
						$db->setQuery ("Update #__gmacl set aro=$gmaccess->id_groupe where axosection='menu' AND aco='read' AND axo=$menu->id AND aro IN ($parent)");
						$db->query();
					}
				}
		}
		
	}elseif ($methode==1){//mthode absolue
		$db->setQuery ("Update #__menu set access=$row->access where menutype='$type'");
		$db->query();
		foreach ($menus as $menu){
			$db->setQuery ("DELETE FROM #__gmacl WHERE axosection='menu' AND aco='read' AND axo=$menu->id");
			$db->query();
			foreach ($gmaccessgroupe as $gmaccess){
				if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
					$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('com_content', 'read', 'users', $gmaccess->id_groupe, 'menu', $menu->id)");
					$db->query();
				}
			}
		}
	}

}
//fonction cre par Rivenbis pour convertir un tableau PHP en tableau javascript
function conv_tabjs($groupe, $nomjs, $prempass=true) {
	$tableau = mgenfant( $groupe );
	
	if($prempass) {
		$taille = count($tableau);
	
		echo "var ".$nomjs." = new Array(".$taille.");\n";
		foreach($tableau as $key => $val) {
			if(is_string($key)) $key = "'".$key."'";
			conv_tabjs($val, $nomjs."[".$key."]", false);
		}
	}
	else {
		if(is_array($tableau)) {
			echo($nomjs." = new Array(".count($tableau).");\n");
			foreach($tableau as $key => $val) {
				if(is_string($key)) $key = "'".$key."'";
				conv_tabjs($val, $nomjs."[".$key."]", false);
			}
		}
		else {
			if(is_string($tableau)) $tableau = "'".addcslashes($tableau,"'")."'";
			echo($nomjs." = ".$tableau.";\n");
		}
	}
}
//fonction gmaccess pour convertir un tableau simple php en tableau javascript
function conv_gma($tableau, $nomjs) {
	
	$js = "var ".$nomjs." = new Array();";
	$i = 0;
	foreach($tableau as $tab) {
		$js .= $nomjs."[".$i."] = ".$tab.";";
		$i++;
	}
	$js .= "i =".$i.";";
	return $js;
}

//classes hackes

	//function access -> 
	
	function accessswitch( $axosection, &$row, $i, $sectiontype='content', $archived = NULL )
	{
		//ajout gmaccess
		$livesite = JURI::base(); 
		JHTML::_('behavior.modal');
		//fin gmaccess
		if ( !$row->access )  {
			$color_access = 'style="color: green;"';
			$task_access = 'accessregistered';
			$groupename = JText::_( 'Public');
		} else if ( $row->access == 1 ) {
			$color_access = 'style="color: red;"';
			$task_access = 'accessspecial';
			$groupename = JText::_( 'Registered');
		} else {
			$color_access = 'style="color: black;"';
			$task_access = 'accesspublic';
			$groupename ='GMAccess';
		}

		if ($archived == -1 || $archived == 1)
		{
			$href = $groupename;
		}
		else
		{
			$href = '
			<a href="javascript:void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''. $task_access .'\')" '. $color_access .'>
			'. $groupename  .'</a>'
			;
			if ($groupename == 'GMAccess' ) {
			
				if ($axosection == 'category') {
					$href .= ' <a href="'.$livesite.'index3.php?option=com_gmaccess&task=front&axosection='.$axosection.'&axo='.$row->id.'&redirection=1&sectiontype='.$sectiontype.'" rel="{handler: \'iframe\', size: {x: 750, y: 520}, onClose: function() {location.reload();}}" class="modal" ><img src="images/security_f2.png" width="16" height="16" border=0></a>';
				} else {
					$href .= ' <a href="'.$livesite.'index3.php?option=com_gmaccess&task=front&axosection='.$axosection.'&axo='.$row->id.'&redirection=1" rel="{handler: \'iframe\', size: {x: 750, y: 520}, onClose: function() {location.reload();}}" class="modal" ><img src="images/security_f2.png" width="16" height="16" border=0></a>';
				}
			}
		}

		return $href;
	}	
//function qui renvoi la liste des objets sur lequel un utilisateur  un droit 
function checkgmdroit( $aco_section_value, $aco_value, $aro_section_value, $aro_value, $axo_section_value=NULL ) {
		
		$db =& JFactory::getDBO();
		$checkfinal = array (0);
		$query = "SELECT axo"
			. "\n FROM #__gmacl"
			. "\n WHERE acosection = '".$aco_section_value."'"
			. "\n AND aco = '".$aco_value."'"
			. "\n AND arosection='".$aro_section_value."'"
			. "\n AND aro IN ($aro_value)"
			. "\n AND axosection = '".$axo_section_value."'"
			;
			$db->setQuery( $query );
			$check = $db->loadResultArray();
			if ( is_array( $check ) && count( $check ) > 0 ){
				$checkfinal = array_merge ($checkfinal,$check);
			}
			$checkfinal = array_unique ($checkfinal);
			$checkfinal= implode (",",$checkfinal);
			return $checkfinal;
		
}	
	function GMAccessList( &$user ) {
		$db 		=& JFactory::getDBO();
		
		$id = $user->get('id');
		if ($id) {
				$query = "SELECT id_groupe"
						. "\nFROM #__gm_membre"
						. "\nWHERE id_membre=$id"
						;
				$db->setQuery( $query );
				//charger le rsultat dans un tableau
				$gmarray = $db->loadResultArray();
		} else {
			$gmarray = "";
		}
		$query = "SELECT id_groupe AS value, nom_groupe AS text"
		. "\n FROM #__gm_groupe"
		. "\nWHERE id_groupe<>0"
		. "\n AND id_groupe<>1"
		. "\n AND access_groupe<>2"
		. "\n ORDER BY nom_groupe ASC"
		;
		$db->setQuery( $query );
		$groupes = $db->loadObjectList();
		$gmaccess	= JHTML::_('select.genericlist',   $groupes, 'gmaccess[]', 'class="inputbox" size="10" multiple="multiple"', 'value', 'text', $gmarray );
		return $gmaccess;
	}
	
		function checkgmcomp( $aco_section_value, $aco_value,
		$aro_section_value, $aro_value, $axo_section_value='', $axo_value='' ) {
		
		$db =& JFactory::getDBO();
		
		//$where1 = ($axo_section_value==NULL) ? "" :  "\nAND axosection='".$axo_section_value."'";
		//$where2 = ($axo_value==NULL) ? "" :  "\nAND axo='".$axo_value."'";
		$query = "SELECT id"
			. "\nFROM #__gmacl"
			. "\nWHERE acosection='".$aco_section_value."'"
			. "\nAND aco='".$aco_value."'"
			. "\nAND arosection='".$aro_section_value."'"
			. "\nAND axosection='".$axo_section_value."'"
			. "\nAND axo='".$axo_value."'"
			//. $where1
			//. $where2
			;
		$db->setQuery( $query );
		$gmacl = $db->loadObjectList();
		$nbacl = count( $gmacl );
		if ( !$nbacl ) {
			$acl_result = 1;
		}else{
			$acl_result = 0;
		}
		return $acl_result;
	}
	//mod greg
	function savegmaccesscomponent( $row) {
		global $mainframe;
		$db =& JFactory::getDBO();
		$db->setQuery ("DELETE FROM #__gmacl WHERE acosection='".$row->option."' AND aco='read'");
		$db->query();
		$query = "SELECT id_groupe"
		. "\n FROM #__gm_groupe"
		//. "\n AND access_groupe<>2"
		. "\n ORDER BY id_groupe ASC"
		;
		$db->setQuery( $query );
		$gmaccessgroupe = $db->loadObjectList();
		foreach ($gmaccessgroupe as $gmaccess){
		
			if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('".$row->option."', 'read', 'users', $gmaccess->id_groupe, '', '')");
			$db->query();
			}
			
		}
		
	
				$access 	= JRequest::getVar('access', 3);
				if ($access == 1) {
					$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('".$row->option."', 'read', 'users', $access, '', '')");
					$db->query();
				}


	}
	function savegmaccesscomponenturl( $row) {
		global $mainframe;
		$db =& JFactory::getDBO();
		$db->setQuery ("DELETE FROM #__gmacl WHERE acosection='".$row->acosection."' AND aco='".$row->aco."' AND axosection='".$row->axosection."' AND axo='".$row->axo."'");
		$db->query();
		$query = "SELECT id_groupe"
		. "\n FROM #__gm_groupe"
		//. "\n AND access_groupe<>2"
		. "\n ORDER BY id_groupe ASC"
		;
		$db->setQuery( $query );
		$gmaccessgroupe = $db->loadObjectList();
		foreach ($gmaccessgroupe as $gmaccess){
		
			if ( JRequest::getVar('read'.$gmaccess->id_groupe, '')){
			$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('".$row->acosection."', '".$row->aco."', 'users', $gmaccess->id_groupe, '".$row->axosection."', '".$row->axo."')");
			$db->query();
			}
			
		}
		
	
				$access 	= JRequest::getVar('access', 3);
				if ($access == 1) {
					$db->setQuery ("INSERT into #__gmacl (acosection, aco, arosection, aro, axosection, axo) values ('".$row->acosection."', '".$row->aco."', 'users', $access, '".$row->axosection."', '".$row->axo."')");
					$db->query();
				}


	}
//fin de class
}



?>