| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532 | 
							- <?php
 
- /**
 
- * Type de champs possibles dans l'application
 
- * @author valentin carruesco
 
- * @category Core
 
- * @license MIT
 
- */
 
- class FieldType{
 
- 	public $label,$slug,$sqlType,$description,$icon,$default,$input;
 
- 	public function toArray(){
 
- 		return json_decode(json_encode($this), true);
 
- 	}
 
- 	public function __toString() {
 
-    		return json_encode($this->toArray());
 
- 	}
 
- 	//traduit une valeur en champ/label/légende HTML en fonction de son type
 
- 	public static function toHtml($field,$types=null,$options = array('allowCustomLabel'=>true)){
 
- 		if(!isset($types)) $types = self::available();
 
- 		if(!isset($field['id'])) $field['id'] = '';
 
- 		$type = isset($field['type']) && isset($types[$field['type']]) ? $types[$field['type']] : $types['text'];
 
- 		$label = '';
 
- 		if(!empty($field['label'])){
 
- 			$label = '<label class="mb-0"';
 
- 			if(!empty($field['id'])) $label .= 'for="'.$field['id'].'"';
 
- 			$label .= '>'.$field['label'].'</label>';
 
- 		}
 
- 		if(!isset($field['attributes'])) $field['attributes'] = array();
 
- 		$field['attributes'] = array_merge($type->default_attributes,$field['attributes']);
 
- 		if(empty($field['value']) && !empty($field['default'])) $field['value'] = $field['default'];
 
- 		if(!empty($field['placeholder'])) $field['attributes']['placeholder'] = $field['placeholder'];
 
- 		if(!empty($field['required'])) $field['attributes']['required'] = $field['required'];
 
- 		$func = $type->onInput;
 
- 		$inputOptions = array_merge(array('type'=>$type,'label'=>$label), $options);
 
- 		$input = $func($field,$inputOptions);
 
- 		return array(
 
- 			'label' => isset($type->customLabel) && $type->customLabel && $options['allowCustomLabel']  ? '' : $label,
 
- 			'legend' => isset($field['legend']) ? $field['legend'] : '',
 
- 			'input' => $input,
 
- 			'data' => $field
 
- 		);
 
- 	}
 
- 	public static function toForm($fields,$types=null){
 
- 		$htmlFields = array();
 
- 		if(!isset($types)) $types = self::available();
 
- 		uasort ($fields,function($a,$b){
 
- 			if(!isset($a['sort'])) $a['sort'] = 100;
 
- 			if(!isset($b['sort'])) $b['sort'] = 100;
 
- 			return $a['sort'] - $b['sort'];
 
- 		});
 
- 		foreach ($fields as $key => $field) {
 
- 			if(!isset($field['id'])) $field['id'] = $key;
 
- 			$htmlFields[] = self::toHtml($field,$types);
 
- 		}
 
- 		return $htmlFields;
 
- 	}
 
- 	//liste des types de champs disponibles
 
- 	public static function available($key=null){
 
- 		$types = array();
 
- 		//Texte
 
- 		$type_text = new self();
 
- 		$type_text->slug = 'text';
 
- 		$type_text->label = 'Texte';
 
- 		$type_text->sqlType = 'string';
 
- 		$type_text->label = 'Texte';
 
- 		$type_text->icon = 'fas fa-font';
 
- 		$type_text->description = 'Texte court mono ligne';
 
- 		$type_text->default = '';
 
- 		$type_text->default_attributes = array(
 
- 			'class'=>'"form-control"',
 
- 			'type'=>'"text"'
 
- 		);
 
- 		$type_text->filter = array(
 
- 			'operators' => array (
 
- 				'like' =>array("view" =>'text'),
 
- 				'not like' =>array("view" =>'text'),
 
- 				'=' =>array("view" =>'text'),
 
- 				'!='  =>array("view" =>'text'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		/* Exemples d'utilisation des méthodes de convertion de types
 
- 		Type        |     BDD        | onLoad     | onRawDisplay       | onHtmlDisplay             | onInput                                                | fromRawDisplay
 
- 		====================================================================================================================================================================
 
- 		Date        |    12345       | d/m/y      | d/m/y              | d/m/y                     | <input data-type="date" ... value="{{onLoad}}">        | 12345
 
- 		User        |    theo.lecoq  | theo.lecoq | Théo Lecoq         | Théo Lecoq                | <input data-type="user" ... value="{{onLoad}}">        | theo.lecoq
 
- 		Dictionary |    6           | 6          | Véhicules > bateau | Véhicules > bateau        | <input data-type="dictionary" ... value="{{onLoad}}"> | 6
 
- 		password    |    ==x$yh..    | toto       | toto               | toto                      | <input data-type="password" ... value="{{onLoad}}">    | ==x$yh..
 
- 		url         |    http://...  | http://... | http://...         | <a href="http://..."></a> | <input data-type="url" ... value="{{onLoad}}">         | http://..
 
- 			onLoad : Utilisé pour converti une valeur de la base en une valeur comprehensible par l'erp et
 
- 			ses composants (pas forcement human readable)
 
- 			onRawDisplay : Valeur human readable brute sans mise en forme ou html, utilisé par exemple dans les export text/ excel
 
- 			fromRawDisplay : utilisé pour convertir la valeur affichée brute en valeur technique BDD  (inverse de onRawDisplay) utilisé apr exemple pour les import depuis excel
 
- 			onHtmlDisplay : Valeur human readable avec mise en forme ou html, utilisé pour affichage sur les pages, un parametre decoration peut être mise a true pour avoir des décoration contextuelles (ex : une icone de calendrier devant la date)
 
- 			onInput : utilisé pour afficher l'input approprié, cette méthode doit s'appuyer sur le onLoad
 
- 			onSave : utilisé pour une transformation de la valeur avant enregistrement en base
 
- 		*/
 
- 		$type_text->onLoad = function($value,$options = array()){
 
- 			return $value;
 
- 		};
 
- 		$type_text->onRawDisplay = function($value,$options = array()){
 
- 			return $value;
 
- 		};
 
- 		$type_text->onHtmlDisplay = function($value,$options = array()){
 
- 			$raw = $options['type']->onRawDisplay;
 
- 			$html = $raw($value,$options);
 
- 			return $html;
 
- 		};
 
- 		$type_text->onInput = function($field=array(),$options=array()){
 
- 			$attributes = array_merge($options['type']->default_attributes,$field['attributes']);
 
- 			if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
 
- 			$html = '';
 
- 			$html.= '<input  value="'.(isset($field['value']) ? str_replace('"','"',$field['value']) : '').'"';
 
- 			foreach ($field['attributes'] as $key => $value) {
 
- 				$html.= ' ';
 
- 				$html.= $key;
 
- 				if(!empty($value) && is_string($value)) $html.= '='.$value;
 
- 				$html.= ' ';
 
- 			}
 
- 			$html.= '>';
 
- 			return $html;
 
- 		};
 
- 		$types[$type_text->slug] = $type_text;
 
- 		//File
 
- 		$type_file = new self();
 
- 		$type_file->slug = 'file';
 
- 		$type_file->label = 'Fichier';
 
- 		$type_file->sqlType = '';
 
- 		$type_file->default_attributes = array_merge($type_text->default_attributes,array(
 
- 			'class'=>'"component-file-default bg-white shadow-sm rounded-sm"',
 
- 			'data-type'=>'"file"',
 
- 			'data-extension'=>'"jpg,png,bmp,jpeg,gif,svg,webp,docx,xlsx,pptx,msg,eml,pdf,zip,doc,xls,ppt,txt,csv,mp3,wav,mp4,avi,flv"',
 
- 			'data-action'=>'{{action}}',
 
- 			'data-id'=>'"'.uniqid(rand(0,100)).'"',
 
- 			'data-data'=> "'{}'",
 
- 		));
 
- 		$type_file->settings = array(
 
- 			'action'=>array('type'=>'text','default'=>"dynamicform_handle_file",'attributes'=> array('class'=>'"form-control hidden"','disabled'=>true)),
 
- 			'extension'=> array('type'=>'text','label'=>'Extensions permises','placeholder'=>'"Séparation par \',\'"','attributes'=> array('class'=>'"form-control"')),
 
- 			'size'=> array('type'=>'integer','label'=>'Taille max (octets)','attributes'=> array('class'=>'"form-control"')),
 
- 			'limit'=> array('type'=>'integer','label'=>'Nombre max de fichiers','attributes'=> array('class'=>'"form-control"')),
 
- 			'storage'=> array('type'=>'filepicker','label'=>'Dossier d\'enregistrement','attributes'=> array('class'=>'"form-control"','data-editable'=>true)),
 
- 			'access'=> array(
 
- 				'type'=>'list',
 
- 				'label'=>'Contrôle des droits et accès à faire sur la section',
 
- 				'values'=>function(){
 
- 					$scopes = array();
 
- 					foreach(Right::availables() as $slug=>$scope)
 
- 						$scopes[$slug] = $scope['label'];
 
- 					return $scopes;
 
- 				},
 
- 				'attributes'=> array('class'=>'"form-control"')
 
- 			),
 
- 			/*'label'=> array('type'=>'text','label'=>'Libellé visible dans la dropzone du composant','placeholder'=>'"Faites glisser vos fichiers ici"','attributes'=> array('class'=>'"form-control"')),
 
- 			'readonly'=> array('type'=>'boolean','label'=>'Lecture seule','attributes'=> array('class'=>'"form-control"')),*/
 
- 		);
 
- 		$type_file->onInput = function($field=array(),$options=array()){
 
- 			$attributes = array_merge($options['type']->default_attributes,$field['attributes']);
 
- 			if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
 
- 			//gestion des scopes, uid et slug si dynamics
 
- 			$data = array();
 
- 			//id entité si présente
 
- 			$data['id'] = isset($field['options']['uid']) ? $field['options']['uid'] : '';
 
- 			//id scope de l'entité si présente
 
- 			$data['scope'] = isset($field['options']['scope']) ? $field['options']['scope'] : '';
 
- 			//slug du composant
 
- 			$data['slug'] = isset($field['slug']) ? $field['slug'] : '';
 
- 			//Gestion des data-data depuis le champ (ex: type image en settings globaux)
 
- 			if(!empty($field['attributes']) && !empty($field['attributes']['data-data'])){
 
- 				$fieldData = json_decode($field['attributes']['data-data'], true);
 
- 				$data = !empty($fieldData) ? json_encode(array_merge($data, $fieldData)) : json_encode($data);
 
- 			}
 
- 			$field['attributes']['data-data'] = $data;
 
- 			$html = '';
 
- 			$html.= '<input ';
 
- 			foreach ($field['attributes'] as $key => $value) {
 
- 				$html.= ' ';
 
- 				$html.= $key;
 
- 				if(!empty($value)) $html.= '='.$value;
 
- 				$html.= ' ';
 
- 			}
 
- 			$html.= '>';
 
- 			return $html;
 
- 		};
 
- 		$type_file->onSave = function($value,$options=array()){
 
- 			$path = $options['options']['scope'].SLASH.$options['options']['uid'];
 
- 			$limit = 1;
 
- 			if(!empty($options['field']->meta)){
 
- 				$meta = json_decode($options['field']->meta,true);
 
- 				if(!empty($meta['limit']) && $meta['limit']>1) $limit =$meta['limit'] ;
 
- 				if(!empty($meta['storage']))
 
- 					$path = template($meta['storage'],$options['options'],true);
 
- 			}
 
- 			File::save_component($options['field']->slug,$path.($limit==1?'':SLASH.$options['field']->slug).SLASH.'{{label}}');
 
- 			return null;
 
- 		};
 
- 		$type_file->onRawDisplay = function($value,$options = array()){
 
- 			$value = '';
 
- 			$meta = json_decode($options['meta'],true);
 
- 			$templateData = array();
 
- 			foreach($options as $key=>$option){
 
- 				if(!is_string($option)) continue;
 
- 				$templateData[$key] = $option;
 
- 			}
 
- 			$path = File::dir().template($meta['storage'],$templateData,true).'/*';
 
- 			foreach (glob($path) as $file) {
 
- 				$filePath = str_replace(File::dir(),'',$file);
 
- 				$value .= PHP_EOL.basename($file).' ('.ROOT_URL.'action.php?action='.$meta['action'].'&type=download&path='.base64_encode($filePath).')';
 
- 			}
 
- 			return $value;
 
- 		};
 
- 		$type_file->onHtmlDisplay = function($value,$options = array()){
 
- 			$html = '';
 
- 			$meta = json_decode($options['meta'],true);
 
- 			$templateData = array();
 
- 			foreach($options as $key=>$option){
 
- 				if(!is_string($option)) continue;
 
- 				$templateData[$key] = $option;
 
- 			}
 
- 			$path = File::dir().template($meta['storage'],$templateData,true).'/*';
 
- 			$html .=  '<ul class="list-group list-group-flush shadow-sm">';
 
- 			foreach (glob($path) as $file) {
 
- 				$filePath = str_replace(File::dir(),'',$file);
 
- 				$html .=  '<li class="list-group-item p-1"><a href="';
 
- 				$html .= 'action.php?action='.$meta['action'].'&type=download&path='.base64_encode($filePath);
 
- 				$html.= '">'.basename($file).'<a></li>';
 
- 			}
 
- 			$html.='</ul>';
 
- 			return $html;
 
- 		};
 
- 		$type_file->icon = 'fas fa-file-upload';
 
- 		$type_file->description = 'Envoi de fichier';
 
- 		$type_file->default = '';
 
- 		$types[$type_file->slug] = $type_file;
 
- 		//Image
 
- 		$type = new self();
 
- 		$type->slug = 'image';
 
- 		$type->label = 'Image';
 
- 		$type->sqlType = '';
 
- 		$type->default_attributes = array_merge($type_text->default_attributes,array(
 
- 			'class'=>'"component-file-cover bg-white shadow-sm rounded-sm"',
 
- 			'data-type'=>'"file"',
 
- 			'data-limit'=>'"1"',
 
- 			'data-extension'=>'"jpg,png,bmp,jpeg,gif,svg,webp"',
 
- 			'data-action'=>'{{action}}',
 
- 			'data-id'=>'"'.uniqid(rand(0,100)).'"',
 
- 			'data-data'=> "'{}'" ,
 
- 		));
 
- 		$type->settings = array(
 
- 			'action'=>array('type'=>'text','default'=>"dynamicform_handle_file",'attributes'=> array('class'=>'"form-control hidden"','disabled'=>true)),
 
- 			'extension'=> array('type'=>'text','label'=>'Extensions permises','placeholder'=>'"Séparation par \',\'"','attributes'=> array('class'=>'"form-control"')),
 
- 			'size'=> array('type'=>'integer','label'=>'Taille max (octets)','attributes'=> array('class'=>'"form-control"')),
 
- 			'storage'=> array('type'=>'filepicker','label'=>'Dossier d\'enregistrement','attributes'=> array('class'=>'"form-control"','data-editable'=>true)),
 
- 			'access'=> array(
 
- 				'type'=>'list',
 
- 				'label'=>'Contrôle des droits et accès à faire sur la section',
 
- 				'values'=>function(){
 
- 					$scopes = array();
 
- 					foreach(Right::availables() as $slug=>$scope)
 
- 						$scopes[$slug] = $scope['label'];
 
- 					return $scopes;
 
- 				},
 
- 				'attributes'=> array('class'=>'"form-control"')
 
- 			),
 
- 			/*'label'=> array('type'=>'text','label'=>'Libellé visible dans la dropzone du composant','placeholder'=>'"Faites glisser vos fichiers ici"','attributes'=> array('class'=>'"form-control"')),
 
- 			'readonly'=> array('type'=>'boolean','label'=>'Lecture seule','attributes'=> array('class'=>'"form-control"')),*/
 
- 		);
 
- 		$type->onInput = $type_file->onInput;
 
- 		$type->onSave = $type_file->onSave;
 
- 		$type->onHtmlDisplay = function($value,$options = array()){
 
- 			$html = '<div class="fieldtype-image-cover">';
 
- 			$meta = json_decode($options['meta'],true);
 
- 			$templateData = array();
 
- 			foreach($options as $key=>$option){
 
- 				if(!is_string($option)) continue;
 
- 				$templateData[$key] = $option;
 
- 			}
 
- 			$path = File::dir().template($meta['storage'],$templateData,true).'/*';
 
- 			$files = glob($path);
 
- 			$file = $files[0];
 
- 			$filePath = str_replace(File::dir(),'',$file);
 
- 			$action = 'action.php?action='.$meta['action'].'&type=download&path='.base64_encode($filePath);
 
- 			$html .= '<img class="shadow-sm rounded-sm" style="max-width: 100px;height: auto;" src="'.$action.'">';
 
- 			if(count($files)>1) $html .= '<span><i class="far fa-file-image"></i> +'.count($files).' </span>';
 
- 			$html .= '</div>';
 
- 			return $html;
 
- 		};
 
- 		$type->onRawDisplay  = $type_file->onRawDisplay;
 
- 		$type->icon = 'far fa-image';
 
- 		$type->description = "Envoi d'image";
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//User
 
- 		$type = new self();
 
- 		$type->slug = 'user';
 
- 		$type->label = 'Utilisateur';
 
- 		$type->sqlType = 'string';
 
- 		$type->default_attributes = array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"user"',
 
- 		));
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'=' =>array("view" =>'user'),
 
- 				'!='  =>array("view" =>'user'),
 
- 				'like' =>array("view" =>'user'),
 
- 				'not like'  =>array("view" =>'user'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->onRawDisplay = function($value,$options = array()){
 
- 			if(empty($value)) return '';
 
- 			$user = User::byLogin($value);
 
- 			return !$user? '':$user->fullName();
 
- 		};
 
- 		$type->onHtmlDisplay = function($value,$options = array()){
 
- 			$raw = $options['type']->onRawDisplay;
 
- 			$html = $raw($value,$options);
 
- 			if(isset($options['decoration']) && $options['decoration']) $html = '<img src="action.php?action=core_account_avatar_download&user='.$value.'&extension=jpg" class="avatar-mini avatar-rounded avatar-login" title="'.$html.'"> '.$html;
 
- 			return $html;
 
- 		};
 
- 		$type->icon = 'fas fa-user';
 
- 		$type->description = 'Autocompletion sur les comptes utilisateurs';
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Firm
 
- 		$type = new self();
 
- 		$type->slug = 'firm';
 
- 		$type->label = 'Etablissement';
 
- 		$type->sqlType = 'string';
 
- 		$type->default_attributes = array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"firm"',
 
- 		));
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'fas fa-building';
 
- 		$type->description = 'Autocompletion sur les établissements';
 
- 		$type->default = '';
 
- 		$type->onRawDisplay  = function($value,$options = array()){
 
- 			if(empty($value) || !is_numeric($value)) return '';
 
- 			$firm = Firm::getById($value);
 
- 			return !$firm? '':$firm->label;
 
- 		};
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'=' =>array("view" =>'firm'),
 
- 				'!='  =>array("view" =>'firm'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$types[$type->slug] = $type;
 
- 		//Rank
 
- 		$type = new self();
 
- 		$type->slug = 'rank';
 
- 		$type->label = 'Rang';
 
- 		$type->sqlType = 'int';
 
- 		$type->default_attributes = array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"user"',
 
- 			'data-types'=>'"rank"',
 
- 		));
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'fas fa-user-lock';
 
- 		$type->description = 'Autocompletion sur les rangs';
 
- 		$type->default = '';
 
- 		$type->onRawDisplay = function($value,$options = array()){
 
- 			if(empty($value) || !is_numeric($value)) return '';
 
- 			$rank = Rank::getById($value);
 
- 			return !$rank? '':$rank->label;
 
- 		};
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'=' =>array("view" =>'rank'),
 
- 				'!='  =>array("view" =>'rank'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$types[$type->slug] = $type;
 
- 		//Textarea
 
- 		$type_longstring = new self();
 
- 		$type_longstring->slug = 'textarea';
 
- 		$type_longstring->label = 'Texte Long';
 
- 		$type_longstring->sqlType = 'longstring';
 
- 		$type_longstring->default_attributes =  $type_text->default_attributes;
 
- 		$type_longstring->onInput  = function($field=array(),$options=array()){
 
- 			$html = '';
 
- 			$html .= '<textarea ';
 
- 			if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
 
- 			foreach ($field['attributes'] as $key=>$attribute) {
 
- 				if( $key=='value' ) continue;
 
- 				$html .= ' '.$key;
 
- 				if(!empty($attribute))
 
- 					$html .= '='.$attribute;
 
- 			}
 
- 			if(isset($field['value']) && is_array($field['value']))
 
- 				$field['value'] = json_encode($field['value']);
 
- 			$html .='>'.(isset($field['value']) && !empty($field['value']) ? (is_callable($field['value']) ? $field['value']() : $field['value']) : '').'</textarea>';
 
- 			return $html ;
 
- 		};
 
- 		$type_longstring->filter = array(
 
- 			'operators' => array (
 
- 				'like' =>array("view" =>'text'),
 
- 				'not like' =>array("view" =>'text'),
 
- 				'=' =>array("view" =>'text'),
 
- 				'!='  =>array("view" =>'text'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$type_longstring->icon = 'fas fa-text-width';
 
- 		$type_longstring->description = 'Texte long multi ligne';
 
- 		$type_longstring->default = '';
 
- 		$types[$type_longstring->slug] = $type_longstring;
 
- 		//Wysiwyg
 
- 		$type = new self();
 
- 		$type->slug = 'wysiwyg';
 
- 		$type->label = 'Texte enrichi';
 
- 		$type->sqlType = 'longstring';
 
- 		$type->default_attributes =  array_merge($type_longstring->default_attributes,array(
 
- 			'data-type'=>'"wysiwyg"',
 
- 			'class'=>'""',
 
- 		));
 
- 		$type->onInput = $type_longstring->onInput;
 
- 		$type->onRawDisplay = function($value,$options = array()){
 
- 			if(empty($value)) return '';
 
- 			return strip_tags($value);
 
- 		};
 
- 		$type->onHtmlDisplay = function($value,$options = array()){
 
- 			$html = html_entity_decode($value);
 
- 			return $html;
 
- 		};
 
- 		$type->filter = $type_longstring->filter;
 
- 		$type->icon = 'fas fa-spell-check';
 
- 		$type->description = 'Texte riche multi ligne';
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Date
 
- 		$type = new self();
 
- 		$type->slug = 'date';
 
- 		$type->label = 'Date';
 
- 		$type->sqlType = 'date';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"date"',
 
- 			'title'=>'"format jj/mm/aaaa"',
 
- 			'placeholder'=>'"JJ/MM/AAAA"',
 
- 		));
 
- 		$type->onLoad  = function($value){
 
- 			return !is_null($value) || is_numeric($value) ? date('d/m/Y',$value) : '';
 
- 		};
 
- 		$type->onSave  = function($value,$options=array()){
 
- 			return !empty($value) ? timestamp_date($value) : null;
 
- 		};
 
- 		$type->onRawDisplay = function($value,$options = array()){
 
- 			$html = !is_null($value) && is_numeric($value) ? date('d/m/Y',$value) : '';
 
- 			return $html;
 
- 		};
 
- 		$type->fromRawDisplay = function($value,$options = array()){
 
- 			return timestamp_date($value);
 
- 		};
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'between' =>array("view" =>'date'),
 
- 				'=' =>array("view" =>'date'),
 
- 				'!='  =>array("view" =>'date'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'far fa-calendar';
 
- 		$type->description = 'Date au format jj/mm/aaaa';
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Tags
 
- 		$type = new self();
 
- 		$type->slug = 'tag';
 
- 		$type->label = 'Etiquettes';
 
- 		$type->sqlType = 'string';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"tag"',
 
- 			'data-multiple'=>'true'
 
- 		));
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'fas fa-tags';
 
- 		$type->description = 'Etiquettes (tags) séparés par virgules, espace ou tabulation';
 
- 		$type->default = '';
 
- 		$type->onHtmlDisplay = function($value,$options = array()){
 
- 			$html = '';
 
- 			$tags = explode(',',$value);
 
- 			$html = '<span class="badge">'.implode('</span><span class="badge">',$tags).'</span>';
 
- 			return $html;
 
- 		};
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'in' =>array("view" =>'tag'),
 
- 				'not in' =>array("view" =>'tag'),
 
- 				'inline-and' =>array("view" =>'tag'),
 
- 				'inline-or' =>array("view" =>'tag'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$type->onSave  = function($value,$options=array()){
 
- 			$value = explode(',',$value);
 
- 			$value = array_filter($value);
 
- 			$value = ','.implode(',',$value).',';
 
- 			if($value==',,') $value = '';
 
- 			return $value;
 
- 		};
 
- 		$types[$type->slug] = $type;
 
- 		//File picker
 
- 		$type = new self();
 
- 		$type->slug = 'filepicker';
 
- 		$type->label = 'Parcourir';
 
- 		$type->sqlType = 'longstring';
 
- 		$type->default_attributes = array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"filepicker"',
 
- 		));
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'far fa-folder-open';
 
- 		$type->description = 'Rechercher dans un dossier';
 
- 		$type->default = '';
 
- 		$type->settings = array(
 
- 			'root'=> array(
 
- 				'type'=>'filepicker',
 
- 				'label'=>'Racine ciblée',
 
- 				'attributes'=> array('class'=>'"form-control"', 'data-root'=>"")
 
- 			)
 
- 		);
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'=' =>array("view" =>'filepicker'),
 
- 				'!='  =>array("view" =>'filepicker'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$types[$type->slug] = $type;
 
- 		//Heure
 
- 		$type = new self();
 
- 		$type->slug = 'hour';
 
- 		$type->label = 'Heure';
 
- 		$type->sqlType = 'string';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"hour"',
 
- 			'title'=>'"format hh:mm"',
 
- 			'placeholder'=>'"13:37"',
 
- 		));
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'far fa-clock';
 
- 		$type->description = 'Combo Heures/minutes';
 
- 		$type->default = '';
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'<' =>array("view" =>'hour'),
 
- 				'>' =>array("view" =>'hour'),
 
- 				'=' =>array("view" =>'hour'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$types[$type->slug] = $type;
 
- 		//Dictionnaire
 
- 		$type_dictionary = new self();
 
- 		$type_dictionary->slug = 'dictionary';
 
- 		$type_dictionary->label = 'Liste configurable';
 
- 		$type_dictionary->sqlType = 'int';
 
- 		$type_dictionary->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"dictionary"',
 
- 			'data-slug'=>'"{{key}}"',
 
- 			'data-depth'=>'"1"',
 
- 			'key'=>'data-disable-label',
 
- 			'data-value'=>'',
 
- 			'class'=>'"form-control select-control"'
 
- 		));
 
- 		$type_dictionary->settings = array(
 
- 			'slug'=> array(
 
- 				'type'=>'dictionary',
 
- 				'label'=>'Liste ciblée',
 
- 				'attributes'=> array(
 
- 					'class'=>'"form-control"',
 
- 					'data-slug'=>"",
 
- 					'data-output'=>"slug"
 
- 				)
 
- 			)
 
- 		);
 
- 		$type_dictionary->onRawDisplay  = function($value,$options = array()){
 
- 			if(empty($value) || !is_numeric($value)) return '';
 
- 			$dictionary = Dictionary::getById($value);
 
- 			return !$dictionary? '':$dictionary->label;
 
- 		};
 
- 		$type_dictionary->fromRawDisplay = function($value,$options = array()){
 
- 			$filters = array('label'=>$value);
 
- 			if(isset($options['parent'])) $filters['parent'] = $options['parent'];
 
- 			$dictionary = Dictionary::load($filters);
 
- 			return !$dictionary ? 0 : $dictionary->id;
 
- 		};
 
- 		$type_dictionary->onInput  = function($field = array(),$options = array()){
 
- 			if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
 
- 			if(isset($field['value'])) $field['attributes']['data-value'] = $field['value'];
 
- 			//gestion des metas de dynamiques fields pour listes simples
 
- 			if(isset($field['attributes']['data-values'])){
 
- 				$field['values'] = $field['attributes']['data-values'];
 
- 				unset($field['attributes']['data-values']);
 
- 			}
 
- 			$html = '';
 
- 			$html .= '<select ';
 
- 			foreach ($field['attributes'] as $key=>$attribute) {
 
- 				$html .= $key;
 
- 				if(!empty($attribute))
 
- 					$html .= '='.$attribute;
 
- 				$html .= ' ';
 
- 			}
 
- 			$html .='>';
 
- 			if(isset($field['values'])){
 
- 				$values = is_callable($field['values']) ? $field['values']() : $field['values'];
 
- 				if(!empty($values) && is_array($values)){
 
- 					foreach($values as $key=>$value){
 
- 						$html .='<option '.(isset($field['value']) && $field['value']==$key?' selected="selected" ':'').' value="'.$key.'">'.$value.'</option>';
 
- 					}
 
- 				}
 
- 			}
 
- 			$html .='</select>';
 
- 			return $html ;
 
- 		};
 
- 		$type_dictionary->icon = 'fas fa-list-ol';
 
- 		$type_dictionary->description = 'Liste de sélection configurable récursive';
 
- 		$type_dictionary->default = '';
 
- 		$type_dictionary->filter = array(
 
- 			'attributes' => array(
 
- 				'data-display'=>'"dropdown"',
 
- 				'data-slug'=>'"{{slug}}"',
 
- 				'data-depth'=>'"{{depth}}"',
 
- 				'data-value-selector'=>'".filter-value:last-child"'
 
- 			),
 
- 			'operators' => array(
 
- 				'in' =>array(
 
- 					"view" => "checkbox-list",
 
- 					"value-separator" => ","
 
- 				),
 
- 				'not in' =>array(
 
- 					"view" => "checkbox-list",
 
- 					"value-separator" => ","
 
- 				),
 
- 				'=' =>array("view" =>'dictionary'),
 
- 				'!=' =>array("view" =>'dictionary'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$types[$type_dictionary->slug] = $type_dictionary;
 
- 		//Table JSON clé / valeur
 
- 		$type = new self();
 
- 		$type->slug = 'jsontable';
 
- 		$type->label = 'Table clé/valeur';
 
- 		$type->sqlType = 'longstring';
 
- 		$type->default_attributes = array(
 
- 			'type'=>'"text"',
 
- 			'data-type'=>'"jsontable"',
 
- 			'data-format'=>'"key-value"',
 
- 		);
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'fas fa-table';
 
- 		$type->description = 'Table clé/valeur enregistré en JSON';
 
- 		$type->default = '';
 
- 		$type->onRawDisplay  = function($value){
 
- 			$stream = '';
 
- 			$table = json_decode($value,true);
 
- 			if(!is_array($table)) return '';
 
- 			foreach($table as $key=>$value){
 
- 				$stream .= ''.$key.' : '.$value.',';
 
- 			}
 
- 			return $stream;
 
- 		};
 
- 		$type->onHtmlDisplay  = function($value){
 
- 			$html = '<ul class="list-group">';
 
- 			$table = json_decode($value,true);
 
- 			if(!is_array($table)) return '';
 
- 			foreach($table as $key=>$value){
 
- 				$html .= '<li class="list-group-item p-1"><strong>'.$key.'</strong> : '.$value.'</li>';
 
- 			}
 
- 			$html .= '</ul>';
 
- 			return $html;
 
- 		};
 
- 		$types[$type->slug] = $type;
 
- 		//Liste
 
- 		$type_list = new self();
 
- 		$type_list->slug = 'list';
 
- 		$type_list->label = 'Liste classique';
 
- 		$type_list->sqlType = 'string';
 
- 		$type_list->default_attributes = array_merge($type_text->default_attributes,array(
 
- 			'class'=>'"form-control select-control"'
 
- 		));
 
- 		$type_list->filter = array(
 
- 			'attributes' => array(
 
- 				'data-values'=>'"{{filterTypeValue}}"',
 
- 			),
 
- 			'operators' => array(
 
- 				'in' =>array(
 
- 					"view" => "checkbox-list",
 
- 					"value-separator" => ",",
 
- 				),
 
- 				'not in' =>array(
 
- 					"view" => "checkbox-list",
 
- 					"value-separator" => ",",
 
- 				),
 
- 				'inline-and' =>array(
 
- 					"view" => "checkbox-list",
 
- 					"value-separator" => ",",
 
- 				),
 
- 				'inline-or' =>array(
 
- 					"view" => "checkbox-list",
 
- 					"value-separator" => ",",
 
- 				),
 
- 				'=' =>array("view" =>'list'),
 
- 				'!=' =>array("view" =>'list'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$type_list->onInput = $type_dictionary->onInput;
 
- 		$type_list->onRawDisplay  = function($value,$options = array()){
 
- 			if(!isset($options['meta'])) return '';
 
- 			$list = json_decode($options['meta'],true);
 
- 			return isset($list['values']) && isset($list['values'][$value]) ? $list['values'][$value] : '';
 
- 		};
 
- 		$type_list->icon = 'fas fa-list-ol';
 
- 		$type_list->description = 'Liste de sélection classique';
 
- 		$type_list->default = '';
 
- 		$type_list->settings = array(
 
- 			'values'=> array(
 
- 				'type'=>'jsontable',
 
- 				'label'=>'Valeurs possibles',
 
- 				'attributes'=> array(
 
- 					'data-columns' => '\'{"key":"Clé","value":"Valeur"}\'',
 
- 					'data-format' => '"key-value"'
 
- 				))
 
- 		);
 
- 		$types[$type_list->slug] = $type_list;
 
- 		//Checkbox list
 
- 		$type_checkbox = new self();
 
- 		$type_checkbox->slug = 'checkbox-list';
 
- 		$type_checkbox->label = 'Liste de cases à cocher';
 
- 		$type_checkbox->sqlType = 'longtext';
 
- 		$type_checkbox->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"checkbox-list"',
 
- 			'data-slug'=>'"{{key}}"',
 
- 			'data-display'=>'"dropdown"',
 
- 			'value'=>'"{{value}}"',
 
- 			'class'=>'"form-control"'
 
- 		));
 
- 		$type_checkbox->settings = array(
 
- 			'slug'=> array(
 
- 				'type'=>'dictionary',
 
- 				'label'=>'Liste ciblée',
 
- 				'attributes'=> array(
 
- 					'class'=>'"form-control"',
 
- 					'data-slug'=>"",
 
- 					'data-output'=>"slug",
 
- 					'data-format'=>"slug"
 
- 				)
 
- 			),
 
- 			'values'=> array(
 
- 				'type'=>'jsontable',
 
- 				'label'=>'Valeurs possibles',
 
- 				'attributes'=> array(
 
- 					'data-columns' => '\'{"key":"Clé","value":"Valeur"}\'',
 
- 					'data-format' => '"key-value"'
 
- 				)),
 
- 			'operator-delete'=> array(
 
- 				'type'=>'text',
 
- 				'value'=>'["in","not in"]',
 
- 				'attributes'=> array(
 
- 					'class' => '"hidden"',
 
- 				))
 
- 		);
 
- 		$type_checkbox->filter = array(
 
- 			'attributes' => array(
 
- 				'data-display'=>'"dropdown"',
 
- 				'data-slug'=>'"{{slug}}"',
 
- 				'data-depth'=>'"{{depth}}"',
 
- 				//'data-display'=>'"{{display}}"',
 
- 				'data-values'=>'"{{filterTypeValue}}"',
 
- 				'data-multi-level-select'=>'"{{multiLevelSelect}}"',
 
- 			),
 
- 			'operators' => array(
 
- 				'in' =>array(
 
- 					"view" => "checkbox-list",
 
- 					"value-separator" => ","
 
- 				),
 
- 				'not in' =>array(
 
- 					"view" => "checkbox-list",
 
- 					"value-separator" => ","
 
- 				),
 
- 				'inline-and' =>array(
 
- 					"view" => "checkbox-list"
 
- 				),
 
- 				'inline-or' =>array(
 
- 					"view" => "checkbox-list"
 
- 				),
 
- 				'=' =>array("view" =>'dictionary'),
 
- 				'!=' =>array("view" =>'dictionary'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$type_checkbox->onInput  = function($field=array(),$options=array()){
 
- 			$attributes = array_merge($options['type']->default_attributes,$field['attributes']);
 
- 			if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
 
- 			$html = '';
 
- 			$html.= '<input  value="'.(isset($field['value']) ? str_replace('"','"',$field['value']) : '').'"';
 
- 			foreach ($field['attributes'] as $key => $value) {
 
- 				$html.= ' ';
 
- 				$html.= $key;
 
- 				if(!empty($value)) $html.= '='.(is_string($value)?$value:"'".json_encode($value)."'");
 
- 				$html.= ' ';
 
- 			}
 
- 			$html.= '>';
 
- 			return $html;
 
- 		};
 
- 		$type_checkbox->onSave  = function($value,$options=array()){
 
- 			$value = explode(',',$value);
 
- 			$value = array_filter($value);
 
- 			$value = ','.implode(',',$value).',';
 
- 			if($value==',,') $value = '';
 
- 			return $value;
 
- 		};
 
- 		$type_checkbox->onLoad  = function($value){
 
- 			$value = explode(',',$value);
 
- 			$value = array_filter($value);
 
- 			$value = implode(',',$value);
 
- 			return $value;
 
- 		};
 
- 		$type_checkbox->onRawDisplay  = function($value,$field) use($type_checkbox){
 
- 			$onLoad = 	$type_checkbox->onLoad;
 
- 			$value = $onLoad($value);
 
- 			$values = explode(',',$value);
 
- 			if(count($values)==0) return '';
 
- 			$results = array();
 
- 			//dictionary
 
- 			$ids = array();
 
- 			foreach($values as $i=>$id){
 
- 				if(empty($id) || !is_numeric($id)) continue;
 
- 				unset($values[$i]);
 
- 				$ids[] = $id ;
 
- 			}
 
- 			if(count($ids)!=0){
 
- 				$dictionnaries = Dictionary::loadAll(array('id:IN'=>$ids));
 
- 				foreach($dictionnaries as $dictionary){
 
- 					$results[] = $dictionary->label;
 
- 				}
 
- 			}
 
- 			//valeur en dur
 
- 			if(!empty($field['meta'])){
 
- 				$meta = json_decode($field['meta'],true);
 
- 				if(!empty($meta['values'])){
 
- 					$availableValues = $meta['values'];
 
- 					foreach($values as $id){
 
- 						if(isset($availableValues[$id])) $results[] = $availableValues[$id];
 
- 					}
 
- 				}
 
- 			};
 
- 			$value = implode(',',$results);
 
- 			return $value;
 
- 		};
 
- 		$type_checkbox->onHtmlDisplay  = function($value,$field) use($type_checkbox){
 
- 			$onRawDisplay = $type_checkbox->onRawDisplay;
 
- 			$value = explode(',',$onRawDisplay($value,$field));
 
- 			$value = array_filter($value);
 
- 			$value = '<span class="badge badge-secondary">'.implode('</span> <span class="badge badge-secondary">',$value).'</span>';
 
- 			return $value;
 
- 		};
 
- 		$type_checkbox->fromRawDisplay = function($value,$options = array()){
 
- 			$filters = array('label'=>$value);
 
- 			if(isset($options['parent'])) $filters['parent'] = $options['parent'];
 
- 			$dictionary = Dictionary::load($filters);
 
- 			return !$dictionary ? 0 : $dictionary->id;
 
- 		};
 
- 		$type_checkbox->icon = 'fas fa-list';
 
- 		$type_checkbox->description = 'Liste de cases à cocher configurable';
 
- 		$type_checkbox->default = '';
 
- 		$types[$type_checkbox->slug] = $type_checkbox;
 
- 		//Entier
 
- 		$type = new self();
 
- 		$type->slug = 'integer';
 
- 		$type->label = 'Nombre Entier';
 
- 		$type->sqlType = 'int';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'type'=>'"number"',
 
- 		));
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'fas fa-sort-numeric-down';
 
- 		$type->description = 'Nombre entier';
 
- 		$type->onSave  = function($value,$options=array()){
 
- 			$value = trim($value);
 
- 			if(!empty($value) && !is_numeric($value)) throw new Exception("Ce champ ne doit contenir que des chiffres et être entier");
 
- 			return $value;
 
- 		};
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'in' => array(
 
- 					"view" =>'tag',
 
- 					"value-separator" => ","
 
- 				),
 
- 				'not in' => array(
 
- 					"view" =>'tag',
 
- 					"value-separator" => ","
 
- 				),
 
- 				'<' => array("view" =>'decimal'),
 
- 				'>' => array("view" =>'decimal'),
 
- 				'=' => array("view" =>'decimal'),
 
- 				'!=' => array("view" =>'decimal'),
 
- 				'between' => array("view" =>'decimal'),
 
- 				'null' => array(),
 
- 				'not null' => array()
 
- 			)
 
- 		);
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Flottant
 
- 		$type = new self();
 
- 		$type->slug = 'decimal';
 
- 		$type->label = 'Décimal';
 
- 		$type->sqlType = 'decimal';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"decimal"'
 
- 		));
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'fas fa-sort-numeric-down';
 
- 		$type->description = 'Nombre décimal';
 
- 		$type->onSave  = function($value,$options=array()){
 
- 			$value = trim(str_replace(',', '.', $value));
 
- 			if(!empty($value) && !is_numeric($value)) throw new Exception("Ce champ ne doit contenir que des chiffres");
 
- 			return $value;
 
- 		};
 
- 		$type->filter = array(
 
- 			'operators' => array(
 
- 				'in' => array(
 
- 					"view" =>'tag',
 
- 					"value-separator" => ","
 
- 				),
 
- 				'not in' => array(
 
- 					"view" =>'tag',
 
- 					"value-separator" => ","
 
- 				),
 
- 				'<' => array("view" =>'decimal'),
 
- 				'>' => array("view" =>'decimal'),
 
- 				'=' => array("view" =>'decimal'),
 
- 				'!=' => array("view" =>'decimal'),
 
- 				'between' => array("view" =>'decimal'),
 
- 				'null' => array(),
 
- 				'not null' => array()
 
- 			)
 
- 		);
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Adresse
 
- 		$type = new self();
 
- 		$type->slug = 'address';
 
- 		$type->label = 'Adresse';
 
- 		$type->sqlType = 'longstring';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"location"',
 
- 		));
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'fas fa-street-view';
 
- 		$type->description = 'Adresse postale';
 
- 		$type->default = '';
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'like' => array("view" =>'text'),
 
- 				'=' => array("view" =>'text'),
 
- 				'!=' => array("view" =>'text'),
 
- 				'null' => array(),
 
- 				'not null' => array()
 
- 			)
 
- 		);
 
- 		$types[$type->slug] = $type;
 
- 		//Password
 
- 		$type = new self();
 
- 		$type->slug = 'password';
 
- 		$type->label = 'Mot de passe';
 
- 		$type->sqlType = 'string';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"password"',
 
- 			'autocomplete'=>'"new-password"',
 
- 		));
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->onSave  = function($value,$options=array()){
 
- 			return encrypt($value);
 
- 		};
 
- 		$type->onLoad  = function($value){
 
- 			$value = decrypt($value);
 
- 			return $value === false ? '' : $value;
 
- 		};
 
- 		$type->onRawDisplay = function($value,$options = array()){
 
- 			$value = decrypt($value);
 
- 			return $value === false ? '' : $value;
 
- 		};
 
- 		$type->icon = 'fas fa-unlock-alt';
 
- 		$type->description = 'Mot de passe caché';
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Couleur
 
- 		$type = new self();
 
- 		$type->slug = 'color';
 
- 		$type->label = 'Couleur';
 
- 		$type->sqlType = 'string';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"color"',
 
- 		));
 
- 		$type->onHtmlDisplay  = function($value,$options = array()){
 
- 			if(empty($value)){
 
- 				$html = '<span class="fa-stack">
 
- 					<i class="far fa-circle fa-stack-1x"></i>
 
- 					<i class="fas fa-slash text-danger fa-stack-1x"></i>
 
- 				</span>';
 
- 			}else{
 
- 				$html = '<i class="fas fa-circle" style="color:'.$value.'"></i>';
 
- 			}
 
- 			return $html;
 
- 		};
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'=' => array("view" =>'text'),
 
- 				'!=' => array("view" =>'text'),
 
- 				'null' => array(),
 
- 				'not null' => array()
 
- 			)
 
- 		);
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'fas fa-palette';
 
- 		$type->description = 'Couleur';
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Icône
 
- 		$type = new self();
 
- 		$type->slug = 'icon';
 
- 		$type->label = 'Icône';
 
- 		$type->sqlType = 'string';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"icon"',
 
- 		));
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->onHtmlDisplay  = function($value,$options = array()){
 
- 			$html = '<i class="'.$value.'"></i>';
 
- 			return $html;
 
- 		};
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'=' => array("view" =>'icon'),
 
- 				'!=' => array("view" =>'icon'),
 
- 				'null' => array(),
 
- 				'not null' => array()
 
- 			)
 
- 		);
 
- 		$type->icon = 'fas fa-icons';
 
- 		$type->description = 'Icône d\'illustration';
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Prix
 
- 		$type = new self();
 
- 		$type->slug = 'price';
 
- 		$type->label = 'Prix';
 
- 		$type->sqlType = 'decimal';
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'fas fa-euro-sign';
 
- 		$type->description = 'Devis monetaire';
 
- 		$type->default = '';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"price"',
 
- 			'step'=>'"0.01"',
 
- 			'type'=>'number'
 
- 		));
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'=' => array("view" =>'price'),
 
- 				'!=' => array("view" =>'price'),
 
- 				'<' => array("view" =>'price'),
 
- 				'>' => array("view" =>'price'),
 
- 				'between' =>array("view" =>'price'),
 
- 				'in' => array(
 
- 					"view" =>'tag',
 
- 					"value-separator" => ","
 
- 				),
 
- 				'not in' => array(
 
- 					"view" =>'tag',
 
- 					"value-separator" => ","
 
- 				),
 
- 				'null' => array(),
 
- 				'not null' => array()
 
- 			)
 
- 		);
 
- 		$type->onSave  = function($value,$options=array()){
 
- 			$value = trim(str_replace(',', '.', $value));
 
- 			if(!empty($value) && !is_numeric($value)) throw new Exception("Le prix ne doit contenir que des chiffres");
 
- 			return $value;
 
- 		};
 
- 		$types[$type->slug] = $type;
 
- 		//Choix
 
- 		$type = new self();
 
- 		$type->slug = 'choice';
 
- 		$type->label = 'Choix';
 
- 		$type->customLabel = false;
 
- 		$type->sqlType = 'longstring';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"choice"',
 
- 			'class'=>''
 
- 		));
 
- 		$type->filter = array(
 
- 			'attributes' => array('data-values'=>'"{{filterTypeValue}}"'),
 
- 			'operators' => array (
 
- 				'=' => array("view" =>'choice'),
 
- 				'!=' => array("view" =>'choice'),
 
- 				'null' => array(),
 
- 				'not null' => array()
 
- 			)
 
- 		);
 
- 		$type->settings = array(
 
- 			'values'=> array(
 
- 				'type'=>'jsontable',
 
- 				'label'=>'Options possibles',
 
- 				'attributes'=> array(
 
- 					'data-columns' => '\'{"key":"Clé","value":"Valeur"}\'',
 
- 					'data-format' => '"key-value"'
 
- 				))
 
- 		);
 
- 		$type->onInput  = function($field=array(),$options=array()){
 
- 			$attributes = array_merge($options['type']->default_attributes,$field['attributes']);
 
- 			if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
 
- 			$html = '';
 
- 			$html.= '<input  value="'.(isset($field['value']) ? str_replace('"','"',$field['value']) : '').'" data-values="'.(isset($field['values']) ? htmlspecialchars(json_encode($field['values']), ENT_QUOTES, 'UTF-8') : '').'"';
 
- 			foreach ($field['attributes'] as $key => $value) {
 
- 				$html.= ' ';
 
- 				$html.= $key;
 
- 				if(!empty($value)) $html.= '='.(is_string($value)?$value:"'".json_encode($value)."'");
 
- 				$html.= ' ';
 
- 			}
 
- 			$html.= '>';
 
- 			return $html;
 
- 		};
 
- 		$type->onRawDisplay = function($value,$options = array()){
 
- 			if(isset($options['meta'])){
 
- 				$meta = is_string($options['meta']) ? json_decode($options['meta'],true) : $options['meta'];
 
- 				if(isset($meta['values']) && isset($meta['values'][$value])){
 
- 					$value = $meta['values'][$value];
 
- 				}
 
- 			}
 
- 			return $value;
 
- 		};
 
- 		$type->onHtmlDisplay  = $type->onRawDisplay;
 
- 		$type->icon = 'far fa-dot-circle';
 
- 		$type->description = 'Choix unique';
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Booléen
 
- 		$type = new self();
 
- 		$type->slug = 'boolean';
 
- 		$type->label = 'Vrai ou Faux';
 
- 		$type->customLabel = true;
 
- 		$type->sqlType = 'boolean';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"checkbox"',
 
- 			'class'=>'',
 
- 			'type'=>'"checkbox"'
 
- 		));
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'=' => array("view" =>'boolean'),
 
- 				'null' => array(),
 
- 				'not null' => array()
 
- 			)
 
- 		);
 
- 		$type->onRawDisplay = function($value,$options = array()){
 
- 			return $value ? 'VRAI' : 'FAUX';
 
- 		};
 
- 		$type->onHtmlDisplay  = function($value,$options = array()){
 
- 			$html = $value ? '<i class="fas fa-check text-success"></i>' : '<i class="fas fa-times text-danger"></i>' ;
 
- 			return $html;
 
- 		};
 
- 		$type->onInput = function($field=array(),$option=array()){
 
- 			$html = '';
 
- 			$html.= '<div><label><input id="'.(isset($field['id'])?$field['id']:'').'" ';
 
- 			if(isset($field['value']) && $field['value'] == 1){
 
- 				$field['attributes']['checked'] = '"checked"';
 
- 			}
 
- 			foreach ($field['attributes'] as $key => $value) {
 
- 				$html.= ' ';
 
- 				$html.= $key;
 
- 				if(!empty($value)) $html.= '='.$value;
 
- 				$html.= ' ';
 
- 			}
 
- 			$html.= '>';
 
- 			if(!empty($field['label']) && $option['allowCustomLabel']) $html.= ' '.$field['label'];
 
- 			$html.= '</label></div>';
 
- 			return $html;
 
- 		};
 
- 		$type->icon = 'far fa-check-square';
 
- 		$type->description = 'Vrai ou Faux';
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Url
 
- 		$type = new self();
 
- 		$type->slug = 'url';
 
- 		$type->label = 'Adresse web';
 
- 		$type->sqlType = 'string';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"url"',
 
- 		));
 
- 		$type->onSave  = function($value,$options=array()){
 
- 			if(!empty($value) &&  !filter_var($value, FILTER_VALIDATE_URL) ) throw new Exception("Mauvais format d'adresse web");
 
- 			return $value;
 
- 		};
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->onHtmlDisplay  = function($value,$options = array()){
 
- 			if(empty($value)) return $value;
 
- 			$html = '<a href="'.$value.'">';
 
- 			$html .= $value;
 
- 			$html.= '</a>';
 
- 			return $html;
 
- 		};
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'=' => array("view" =>'url'),
 
- 				'!=' => array("view" =>'url'),
 
- 				'like' => array("view" =>'text'),
 
- 				'not like' => array("view" =>'text'),
 
- 				'null' => array(),
 
- 				'not null' => array()
 
- 			)
 
- 		);
 
- 		$type->icon = 'fas fa-globe';
 
- 		$type->description = 'Adresse Url (web)';
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Mail
 
- 		$type = new self();
 
- 		$type->slug = 'mail';
 
- 		$type->label = 'E-mail';
 
- 		$type->sqlType = 'string';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"mail"',
 
- 			'type'=>'"mail"',
 
- 			'pattern'=>'".+@.+"'
 
- 		));
 
- 		$type->onSave  = function($value,$options=array()){
 
- 			if(!empty($value) && !check_mail($value)) throw new Exception("Mauvais format d'e-mail");
 
- 			return $value;
 
- 		};
 
- 		$type->onHtmlDisplay  = function($value,$options = array()){
 
- 			$html = '<a href="mailto:'.$value.'">';
 
- 			$html .= $value;
 
- 			$html.= '</a>';
 
- 			return $html;
 
- 		};
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'=' => array("view" =>'mail'),
 
- 				'!='  => array("view" =>'mail'),
 
- 				'like'  => array("view" =>'text'),
 
- 				'not like'  => array("view" =>'text'),
 
- 				'null' => array(),
 
- 				'not null' => array()
 
- 			)
 
- 		);
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'far fa-envelope-open';
 
- 		$type->description = 'E-mail';
 
- 		$type->default = '';
 
- 		$types[$type->slug] = $type;
 
- 		//Téléphone
 
- 		$type = new self();
 
- 		$type->slug = 'phone';
 
- 		$type->label = 'Téléphone';
 
- 		$type->sqlType = 'string';
 
- 		$type->default_attributes =  array_merge($type_text->default_attributes,array(
 
- 			'data-type'=>'"phone"'
 
- 		));
 
- 		$type->onSave  = function($value,$options=array()){
 
- 			if(!empty($value) && !check_phone_number($value)) throw new Exception("Mauvais format de téléphone");
 
- 			$value = normalize_phone_number($value);
 
- 			return $value;
 
- 		};
 
- 		$type->onInput  = $type_text->onInput;
 
- 		$type->icon = 'fas fa-mobile-alt';
 
- 		$type->description = 'N° Téléphone';
 
- 		$type->default = '';
 
- 		$type->filter = array(
 
- 			'operators' => array (
 
- 				'like' =>array("view" =>'text'),
 
- 				'not like' =>array("view" =>'text'),
 
- 				'=' =>array("view" =>'phone'),
 
- 				'!='  =>array("view" =>'phone'),
 
- 				'null' =>array(),
 
- 				'not null' =>array()
 
- 			)
 
- 		);
 
- 		$types[$type->slug] = $type;
 
- 		Plugin::callHook('field_types',array(&$types));
 
- 		if(isset($key)) return isset($types[$key])? $types[$key] : $types['text'];
 
- 		return $types;
 
- 	}
 
- }
 
- ?>
 
 
  |