<?php
 function return_img_etat($r){
	if  ($r =='true')  $etat="check_on.png";
	elseif ($r =='false') $etat="check_off.png";
	else $etat="check_wait.png";
	return "<img class='vue_rapid' src='template/".TEMPLATE_ADMIN."/img/$etat' />";
}
function on_off_module($nom_entree,$etat,$type_s=false){
	if(DEBUG)if(!tep_not_null($etat)) print "function on_off_module var absente";
	if (!etat_files(ADD_PATH_ADMIN.TBL_SYS_CONFIG_MODULES_INC)) print "<p class='erreur'>".ERROR.THE_FILES.DOES_NOT_EXIST." ". WRITE_NOT_POSSIBLE."</p>";
			 $query =' SET etat = \''.$etat.'\''
			 .' WHERE id = '.$nom_entree;
	$s= sql ('UPDATE',ADD_PATH_ADMIN.TBL_SYS_CONFIG_MODULES_INC,'_PX_config_module',$query,'');
	if (!$type_s) return $s;
	else print $s;
}
function control_module_dep ($nom_module,$t_dep,$t_conflit ){
	global $t_dep,$t_conflit;
	include (ADD_PATH_ADMIN.TBL_DEP_MODULES_INC);
	include (ADD_PATH_ADMIN.TBL_LIB_INTERNE_INC);
	$dep=(isset($dep) && is_array($dep))?$dep : array();
	$lib_i=(isset($lib_i) && is_array($lib_i))?$lib_i : array();
	$dep=array_merge($dep,$lib_i);
	if (isset($dep[$nom_module])) {
		while ($r=each($dep[$nom_module])){
		## verif dependance + conflit
			if (eregi("(dep_).*",$r['key'])) {
 				##verif presence deja incluonce ni dans dep ni conflit
				if ( (!in_array($r['value'],$t_dep))/*AND (!in_array($r['value'],$t_conflit)) */) {
					if (isset($dep[$r['value']])) control_module_dep ($r['value'],$t_dep,$t_conflit );
					else array_push($t_dep,$r['value']);
				}
			}
			elseif (eregi("(conflit_).*",$r['key'])) {
				if ( (!in_array($r['value'],$t_conflit)) ) array_push($t_conflit,$r['value']);
			}
		}
		array_push($t_dep,$nom_module);
	}
}
function tabl_dep($nom_module){
	global $t_dep,$t_conflit;
	$t_dep=$t_conflit=$dep=array();
	control_module_dep ($nom_module,$t_dep,$t_conflit );
	$s= '<p>'.DEPENDANCE.'</p>';
	if (count($t_dep)>0){
		$s.= '<ul style=\'color:green;\'>';
		while ($r = each($t_dep))
			$s .= '<li>'.$r['value'].'</li>';
		$s .=  '</ul>';
	} else $s .=  '<p>Null</p>';
	$s.= '<p>'.CONFLIT.'</p>';
	if (count($t_conflit)>0){
		$s .=  '<ul style=\'color:red;\'>';
		while ($r = each($t_conflit))
			$s .=  '<li>'.$r['value'].'</li>';
		$s .=  '</ul>';
	} else $s .=  '<p>Null</p>';
	return $s;
}

## retourn la version du module quelque soit sa libarire
function detect_version($name_module){
	$file='/version.inc';
	if (file_exists(ADD_PATH_ADMIN.CHEM_MODULES.$name_module.$file)) @include(ADD_PATH_ADMIN.CHEM_MODULES.$name_module.$file);
	elseif (file_exists(CHEM_MODULES.$name_module.$file)) @include(CHEM_MODULES.$name_module.$file);
	elseif (file_exists(ADD_PATH_ADMIN.'lib_ext/'.$name_module.$file)) @include(ADD_PATH_ADMIN.'lib_ext/'.$name_module.$file);
	if (!empty($MODULE_VERSION)) return $MODULE_VERSION;
	else return false;
}


/* affiachge principal list etat des extentions  */
function list_etat_module(){
	include('config/sys_uninstall.php');

	$form_lg_tabl="<tr><td>%1\$s</td><td>%2\$s</td><td>%3\$s</td><td>%4\$s</td><td>%5\$s</td><td>%6\$s</td><td>%7\$s</td></tr>";
	$form_lg_th="<tr height=20><th>%1\$s</td><th>%2\$s</th><th>%3\$s</td><th>%4\$s</td><th>%5\$s</td><th>%6\$s</td><th>%7\$s</td></tr>";
	$format_entete="<table><tbody>".sprintf($form_lg_th,NAME_MODULE,VERSION_MODULE,ETAT_MODULE,MODULE_EDIT_CONFIG,NOTE,'','')."%1\$s</tbody></table>";

	$file_conf = array();$s='';
	$nom=NewFct('cstr_liste',ADD_PATH_ADMIN."include/modules/") ;
	$file_conf=array_merge($file_conf,$nom);
	$nom=NewFct('cstr_liste',ADD_PATH_ADMIN."ext/") ;
	$file_conf=array_merge($file_conf,$nom);
	while ($row =@each($file_conf) ){
		$r=@constant(strtoupper("PX_CONFIG_MODULE_".strtoupper($row['value'])));
		if ( !isset($_PX_uninstall[$row['value']])) {
			$form_activ=ALERT_NO_IN_UNINSTALL;
			$form_edit='';
			$form_uninstall='';
		}elseif (empty($r)) {
			$form_activ=form_rapid ("config_modules.php","mod=".$row['value']."&amp;conf=sys&amp;var=install","post","POST",false,"  class=\"vue_rapid\" onsubmit= \" "
				.ajax_droit_confirm(TITRE_CONFIRM.CONFIRM_INSTALL_MODULE." ".$row['value'],"include/modules/update_auto/lib.update_auto.inc", "install_module","   \'".$row['value']."\',\'".$_PX_uninstall[$row['value']]."\',false , true ","config_modules.php", NEXT)
				."\" ".Toolip(FOR_SYNHRO_UNINSTALL_OK)."",BT_ADD_MODULE_CONFIG,array("menu_key"=>"%11\$s") );
			$form_edit='';
			$form_uninstall='';
		} elseif($r !='false') {
			$form_activ=form_rapid ("config_modules.php","mod=".$row['value']."&amp;conf=sys&amp;var=false","post","POST",false,"  class=\"vue_rapid\" onsubmit= \" "
				.ajax_droit_confirm(TITRE_CONFIRM.CONFIRM_OFF_MODULE." ".$row['value'],"include/lib/lib.config_modules.php", "on_off_module","   \'".$row['value']."\', \'false\', true ","config_modules.php", RETOUR)
				."\"",BT_DESACTIVER,array("menu_key"=>"%11\$s") );
			$form_edit= (file_exists(ADD_PATH_ADMIN.$_PX_uninstall[$row['value']].$row['value']."/admin/form_edit_config.php"))? form_rapid ("config_modules.php","mod=".$row['value']."&amp;conf=mod","post","POST",false,"  class=\"vue_rapid\"  onsubmit=\" "
				.ajax_forms(ADD_PATH_ADMIN.$_PX_uninstall[$row['value']].$row['value']."/admin/form_edit_config.php", "form_edit_config", " 'true'","config_modules.php","","","'txt_base'",NEXT)
				."\"",BT_EDITER,array("menu_key"=>"%11\$s") ) : '';
			$form_uninstall=form_rapid ("config_modules.php","mod=".$row['value']."&amp;conf=sys&amp;var=uninstall","post","POST",false,"  class=\"vue_rapid\" onsubmit= \" "
				.ajax_droit_confirm(TITRE_CONFIRM.CONFIRM_UNINSTALL_MODULE." ".$row['value'],"include/module/update_auto/lib_update_auto.inc", "uninstall_module","   \'".$row['value']."\', true ","config_modules.php", NEXT)
				."\"",BT_DEL_MODULE_CONFIG,array("menu_key"=>"%11\$s") );

		 } elseif($r !='true') { // inactif
			$form_activ=form_rapid ("config_modules.php","mod=".$row['value']."&amp;conf=sys&amp;var=true","post","POST",false,"  class=\"vue_rapid\" onsubmit= \" "
				.ajax_droit_confirm(TITRE_CONFIRM.CONFIRM_ON_MODULE." ".$row['value'],"include/lib/lib.config_modules.php", "on_off_module","   \'".$row['value']."\', \'true\', true ","config_modules.php", NEXT)
				."\"",BT_ACTIVER,array("menu_key"=>"%11\$s") );
			$form_edit= (file_exists(ADD_PATH_ADMIN.$_PX_uninstall[$row['value']].$row['value']."/admin/form_edit_config.php")) ? $form_edit=form_rapid ("config_modules.php","mod=".$row['value']."&amp;conf=mod","post","POST",false,"  class=\"vue_rapid\" onsubmit=\" "
				.ajax_forms(ADD_PATH_ADMIN.$_PX_uninstall[$row['value']].$row['value']."/admin/form_edit_config.php", "form_edit_config", " 'true'","config_modules.php","","","'txt_base'",NEXT)
				."\"",BT_EDITER,array("menu_key"=>"%11\$s") ) : '';
			$form_uninstall=form_rapid ("config_modules.php","mod=".$row['value']."&amp;conf=sys&amp;var=uninstall","post","POST",false,"  class=\"vue_rapid\" onsubmit= \" "
				.ajax_droit_confirm(TITRE_CONFIRM.CONFIRM_UNINSTALL_MODULE." ".$row['value'],"include/module/update_auto/lib_update_auto.inc", "uninstall_module","   \'".$row['value']."\', true ","config_modules.php", NEXT)
				."\"",BT_DEL_MODULE_CONFIG,array("menu_key"=>"%11\$s") );
		 }
		 else $form_activ=$form_edit=$form_uninstall='';

		 ## liens vers le wiki
		if (eregi('^admin/',@$_PX_uninstall[$row['value']])) $type='admin';
		elseif (eregi('ext/$',@$_PX_uninstall[$row['value']])) $type='ext';
		else $type='public';
		$url=eregi_replace('feed.php','doku.php?id=start:modules:list:paquet:'.$type.':'.$row['value'],URL_MISSOL_RSS_WIKI);
		$note =create_link_popup_wiki($url,NOTICE_WIKI_LINK_POPUP,false);
		 if (file_exists(ADD_PATH_ADMIN."include/modules/".$row['value']."/language/"._USER_PERSO__PREF_LANGUAGE."_usage.inc"))
			$note.="<a href='#' Onclick=\""
					."montre('form_ajax');montre('backgd'); upload_ajax('form_ajax_txt','".ADD_PATH_ADMIN."include/modules/".$row['value']."/language/"._USER_PERSO__PREF_LANGUAGE."_usage.inc',' usage','',''); add_close('config_modules.php','Close', '' )"
				  ."\" >Note/details</a>";
		## Detection module actif est desactive si necessaire
		  if ( (defined('BACKUP'))AND (_USER_PERSO__GRP<=1) ) {	$zip="<a href='#' Onclick=\""
					."montre('form_ajax');montre('backgd'); upload_ajax('form_ajax_txt','include/modules/backup/functions.inc',' zip_module','".$row['value']."',''); add_close('config_modules.php','Close', '' )"
				  ."\" >Zip</a>";
		}else $zip='';

		$s .=sprintf($form_lg_tabl,$row['value'],detect_version($row['value']),$form_activ.return_img_etat($r),$form_edit."<a href=\"#\" style=\"float:right\" ".Toolip(tabl_dep($row['value'])).">".DEPENDANCE."</a>",$note,$zip,$form_uninstall);
	}
	printf($format_entete,$s);

}

?>
