%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/alliance/domains/sedl.alnetis.fr/public_html/inc/classes/
Upload File :
Create Path :
Current File : /home/alliance/domains/sedl.alnetis.fr/public_html/inc/classes/Load.php

<?php

class Load {

	public $codelang;
	public $codelangid;
	public $bd;
	public $lang;
	
	function __construct() {
		
	}
	
	function edit($post){
		if(!isset($post[$this->clef_primaire])){
			return false;
		}
		unset($post['_wysihtml5_mode']);
		//update de la table de base
		$tab_edit=array();
		foreach($this->table as $champ){
			if(isset($post[$champ])){
				$tab_edit[$champ]=$post[$champ];
			}
		}
		if($tab_edit!=null){
			$this->bd->update($this->nom_table,$tab_edit,$this->clef_primaire.'='.$post[$this->clef_primaire]);
		}
		if(isset($this->table_lang)){
			$tablang=$this->lang->getLangs();
			foreach($tablang as $unelang){
				if($this->bd->count("SELECT * FROM ".$this->nom_table."_lang WHERE ".$this->clef_primaire."=".$post[$this->clef_primaire]." AND id_lang=".$unelang)==0){
					$values=array();
					$values['id_lang']=$unelang;
					$values[$this->clef_primaire]=$post[$this->clef_primaire];
					foreach($this->table_lang as $champ){
						$values[$champ]=$post[$champ.'_'.$unelang];
					}
					$this->bd->insert($this->nom_table."_lang", $values);
				}
				else{
					$tab_edit=array();
					foreach($this->table_lang as $champ){
						$tab_edit[$champ]=$post[$champ.'_'.$unelang];
					}
					$this->bd->update($this->nom_table."_lang",$tab_edit,$this->clef_primaire."=".$post[$this->clef_primaire]." AND id_lang=".$unelang);
				}
				
			}
			
			return true;
		}
		
	}
	
	function add($post){
		
		//ajout dans la table de base
		$tab_edit=array();
		
		unset($post['_wysihtml5_mode']);
		foreach($this->table as $champ){
			if(isset($post[$champ])){
				$tab_edit[$champ]=$post[$champ];
			}
		}
		
		if($tab_edit!=null){
			$this->bd->insert($this->nom_table,$tab_edit);
			$post[$this->clef_primaire]=$this->bd->lastId();
		}
		if(isset($this->table_lang)){
			$tablang=$this->lang->getLangs();
			// ajout des traductions
			foreach($tablang as $unelang){
				$values=array();
				$values['id_lang']=$unelang;
				$values[$this->clef_primaire]=$post[$this->clef_primaire];
				foreach($this->table_lang as $champ){
					if(isset($post[$champ.'_'.$unelang])){
						$values[$champ]=$post[$champ.'_'.$unelang];
					}
				}
				$this->bd->insert($this->nom_table."_lang", $values);
				
		
			}
			
		}
		return $post[$this->clef_primaire];
		
	}
	
	function delete($id){
		$this->bd->delete($this->nom_table, $this->clef_primaire."=".$id);
		if(isset($this->table_lang)){
			$this->bd->delete($this->nom_table."_lang", $this->clef_primaire."=".$id);
		}
	}
	
	
	function verifTrad($id){
		$tablang=$this->lang->getTabLang();
		// ajout des traductions
		$trad_valid=array();
		$html='<div class="info_flag_bloc">';
		foreach($tablang as $unelang){
			if($this->bd->count("SELECT * FROM ".$this->nom_table."_lang WHERE ".$this->clef_primaire."=".$id." AND id_lang=".$unelang['id'])==0){
				$trad_valid[$unelang['id']]=0;
				$html.='<div class="info_flag invalide">'.$unelang['code'].'</div>';
			}
			else{
				$valide=$this->bd->select_array("SELECT valide FROM ".$this->nom_table."_lang WHERE ".$this->clef_primaire."=".$id." AND id_lang=".$unelang['id']);
				$trad_valid[$unelang['id']]=$valide['valide'];
				if($valide['valide']==1){
					$html.='<div class="info_flag valide">'.$unelang['code'].'</div>';
				}
				else{
					$html.='<div class="info_flag invalide">'.$unelang['code'].'</div>';
				}
			
			}
		}
		$html.='</div>';
		
		return $html;
	}
	
	function get($id){
		
		$query = "SELECT * FROM ".$this->nom_table." WHERE ".$this->clef_primaire." =".$id;
		$return=$this->bd->select_array($query);
		if(isset($this->table_lang)){
			$query = "SELECT * FROM `".$this->nom_table."_lang` WHERE ".$this->clef_primaire."=".$id;
			$lang_traductions=$this->bd->select_arrays($query);
			foreach($lang_traductions as $lang_traduction){
				foreach($this->table_lang as $unchamp){
					$return[$unchamp][$lang_traduction['id_lang']]=$lang_traduction[$unchamp];
					//$return[$lang_traduction['id_lang']][$unchamp]=$lang_traduction[$unchamp];
				}
			}
		}
		
		return $return;
	}
	function getWithLang($id,$id_lang){
		
		$query = "SELECT * FROM ".$this->nom_table." p LEFT JOIN ".$this->nom_table."_lang l ON l.".$this->clef_primaire."=p.".$this->clef_primaire." WHERE id_lang=".$id_lang." AND p.".$this->clef_primaire." =".$id;
		$return=$this->bd->select_array($query);
		//echo $query;
		return $return;
	}
	
	
	function liste($where=1,$lang=null,$order="",$limit=""){
		if($order!=""){
			$theorder="ORDER BY ".$order;			
		}
		else{
			$theorder="";
		}
		if($lang!=null){
			$query = "SELECT * FROM ".$this->nom_table." p LEFT JOIN ".$this->nom_table."_lang l ON l.".$this->clef_primaire."=p.".$this->clef_primaire." WHERE ".$where." AND id_lang=".$id_lang." ".$theorder;
		}
		else{
			$query = "SELECT * FROM ".$this->nom_table." p WHERE ".$where." ".$theorder;
		}
		if($limit!=""){
			$query.=" LIMIT ".$limit;
		}
		
		
		$return=$this->bd->select_arrays($query);
		//echo $query;
		return $return;

	}
	
	function geneAutoForm($action='add'){
		foreach($this->table_form as $key=>$unchamp){
			if(!isset($unchamp['visible']) || $unchamp['visible']==$action){
				$this->geneUnChamp($key,$unchamp,$action);
			}
		}
	}
	
	function checkRequired($action='add'){
		foreach($this->table_form as $key=>$unchamp){
			if(!isset($unchamp['visible']) || $unchamp['visible']==$action){
				if(isset($unchamp['required']) && $unchamp['required']==true){
					if(!isset($_POST[$key]) || $_POST[$key]==""){
						if(!isset($defchamp['libelle'])){
							$defchamp['libelle']=ucfirst($champ);
						}
						return $defchamp['libelle'].' est obligatoire';
						
					}
				}
			}
		}
		return "ok";
	}
	
	function geneUnChamp($champ,$defchamp,$action){
		// preparation du champ
		if(!isset($defchamp['type'])){
			$defchamp['type']="text";
		}
		if(!isset($defchamp['libelle'])){
			$defchamp['libelle']=ucfirst($champ);
		}
		if(!isset($defchamp['placeholder'])){
			$defchamp['placeholder']='';
		}
		if(!isset($defchamp['class'])){
			$defchamp['class']='';
		}
		if(!isset($_POST[$champ])){
			$value='';
		}
		else{
			$value=$_POST[$champ];
		}
		if(!isset($defchamp['required']) || $defchamp['required']==false){
			$required='';
			$label_required="";
		}
		else{
			$required='required="required"';
			$label_required="*";
		}
		if(isset($defchamp['info'])){
			$info="<small><i>".$defchamp['info']."</i></small>";
		}
		else{
			$info="";
		}
		
		// affichage
		switch($defchamp['type']){
			case "text":
				echo '<div class="form-group">
					<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
					<input type="text" class="form-control" id="'.$champ.'" name="'.$champ.'" placeholder="'.$defchamp['placeholder'].'" value="'.htmlentities($value).'" '.$required.'>'.$info.'
				</div>';
				break;
			case "hidden":
				echo '<input type="hidden" class="form-control" id="'.$champ.'" name="'.$champ.'" value="'.$defchamp['value_default'].'" >';
				break;
			case "number":
				if(isset($_POST[$champ])){
					echo '<div class="form-group">
						<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
						<input type="number" step="1" class="form-control" id="'.$champ.'" name="'.$champ.'" placeholder="'.$defchamp['placeholder'].'" value="'.$value.'" '.$required.'>'.$info.'
					</div>';
				}
				else{
					echo '<div class="form-group">
						<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
						<input type="number" step="1" class="form-control" id="'.$champ.'" name="'.$champ.'" placeholder="'.$defchamp['placeholder'].'" value="'.$defchamp['value_default'].'" '.$required.'>'.$info.'
					</div>';
				}
				break;
			case "numberfloat":
				if(isset($_POST[$champ])){
					echo '<div class="form-group">
						<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
						<input type="number" step="0.1" class="form-control" id="'.$champ.'" name="'.$champ.'" placeholder="'.$defchamp['placeholder'].'" value="'.$value.'" '.$required.'>'.$info.'
					</div>';
				}
				else{
					echo '<div class="form-group">
						<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
						<input type="number" step="1" class="form-control" id="'.$champ.'" name="'.$champ.'" placeholder="'.$defchamp['placeholder'].'" value="'.$defchamp['value_default'].'" '.$required.'>'.$info.'
					</div>';
				}
				break;
			case "email":
				echo '<div class="form-group">
					<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
					<input type="email" class="form-control" id="'.$champ.'" name="'.$champ.'" placeholder="'.$defchamp['placeholder'].'" value="'.$value.'" '.$required.'>'.$info.'
				</div>';
				break;
			case "date":
				if(isset($_POST[$champ])){
					echo '<div class="form-group">
						<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
						<input type="text" class="form-control datepicker" id="'.$champ.'" name="'.$champ.'" placeholder="'.$defchamp['placeholder'].'" value="'.$value.'" '.$required.'>'.$info.'
					</div>';
					break;
				}
				else{
					echo '<div class="form-group">
						<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
						<input type="text" class="form-control datepicker" id="'.$champ.'" name="'.$champ.'" placeholder="'.$defchamp['placeholder'].'" value="'.$defchamp['value_default'].'" '.$required.'>'.$info.'
					</div>';
					break;
				}
			case "password":
				if($action=="add"){
					echo '<div class="form-group">
						<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
						<input type="password" autocomplete="new-password" class="form-control" id="'.$champ.'" name="'.$champ.'" placeholder="'.$defchamp['placeholder'].'" value="" '.$required.'>'.$info.'
					</div>';
				}
				else{
					echo '<div class="form-group">
						<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
						<input type="password" autocomplete="new-password" class="form-control" id="'.$champ.'" name="'.$champ.'" placeholder="'.$defchamp['placeholder'].'" value="" >'.$info.'
					</div>';
				}
				break;
			case "textarea":
				echo '<div class="form-group">
					<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
					<textarea class="form-control '.$defchamp['class'].'" id="'.$champ.'" name="'.$champ.'" '.$required.'>'.$value.'</textarea>'.$info.'
				</div>';
				break;
			case "radio":
				echo '<div class="form-group">
					<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
					<div class="input-group">';
						foreach($defchamp['values'] as $key=>$unevalue){
							if((isset($_POST[$champ]) && $_POST[$champ]==$key) || (!isset($_POST[$champ]) && isset($defchamp['value_default']) && $defchamp['value_default']==$key)){
								echo '<label class="radio-inline"><input id="'.$champ.$key.'" type="radio" name="'.$champ.'" value="'.$key.'" checked="checked" > '.$unevalue.'</label>&nbsp;';
							}
							else{
								echo '<label class="radio-inline"><input id="'.$champ.$key.'" type="radio" name="'.$champ.'" value="'.$key.'" > '.$unevalue.'</label>&nbsp;';
							}
						}
				echo '</div>'.$info.'
				</div>';
				break;
			case "select":
				echo '<div class="form-group">
					<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
					<div class="input-group">
						<select class="form-control" name="'.$champ.'" id="'.$champ.'">';
						foreach($defchamp['values'] as $key=>$unevalue){
							if((isset($_POST[$champ]) && $_POST[$champ]==$key) || (!isset($_POST[$champ]) && isset($defchamp['value_default']) && $defchamp['value_default']==$key)){
								echo '<option value="'.$key.'" selected="selected">'.$unevalue.'</option>';
							}
							else{
								echo '<option value="'.$key.'">'.$unevalue.'</option>';
							}
						}
				echo '	</select>
					</div>'.$info.'
				</div>';
				break;
				
			case "photo":
				$return='
					<div class="form-group">
						<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
						<input type="file" class="form-control" id="'.$champ.'" name="'.$champ.'" >'.$info.'
					</div>';
					if(isset($value) && $value!=""){
						$return.='<img style="max-height:200px" src="up_fichier/'.$value.'" alt="photo" />';
					}
					$return.='</p>';
				echo $return;
				break;	
					
			case "file":		
				echo '<div class="form-group">
						<label for="'.$champ.'">'.$defchamp['libelle'].' '.$label_required.'</label>
						<input type="file" class="form-control" id="'.$champ.'" name="'.$champ.'" >'.$info.'
					</div>';
					if(isset($value) && $value!=""){
						echo '<p><i><a target="_blank" style="text-decoration:underline" href="up_fichier/'.$value.'">'.$value.'</a></i></p>';
					}
					break;
			case "html":
				echo $defchamp['libelle'];
		}
		
	}
	
	function geneSelect($champ,$values,$selected="",$value="",$libelle="",$label=""){
		$html='<div class="form-group">
			<label for="'.$champ.'">'.$label.'</label>
			<select id="'.$champ.'" name="'.$champ.'" class="form-control">';
				foreach($values as $unevalue){
					if($unevalue[$value]==$selected){
						$html.='<option value="'.$unevalue[$value].'">'.$unevalue[$libelle].'</option>';
					}
					else{
						$html.='<option selected="selected" value="'.$unevalue[$value].'">'.$unevalue[$libelle].'</option>';
					}
				}
		$html.='</select>
		</div>';
		return $html;
	}
	/*
	function geneAutoField($html_field,$default_lang,$values,$default_value=""){
		
		$html='<div class="translatable">';
		$langs=$this->lang->getLangs();
		foreach($langs as $unelang){
			$html.='<div class="lang_'.$unelang.'"';
			if($default_lang!=$unelang){
				//$html.=' style="display:none"';
			}
			$html.=' >';
			if(!isset($values[$unelang])){
				$values[$unelang]="";
			}
			if($default_value!="" && $values[$unelang]==$default_value){
				$html.=str_replace(array("[LANG]","[VALUE]","[CHECKED]"),array($unelang,$values[$unelang],'checked="checked"'),$html_field);
			}
			else{
				$html.=str_replace(array("[LANG]","[VALUE]","[CHECKED]"),array($unelang,$values[$unelang],''),$html_field);
			}
		
			$html.='</div>';
		}
		
		$html.='</div>';
		return $html;
	}
	*/
	
	
}

?>

Zerion Mini Shell 1.0