/class.xlink2def.inc
PHP | 1346 lines | 1173 code | 67 blank | 106 comment | 383 complexity | 8832a09277f978b3a47c7deaaed31133 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- define('XLINK2DEF_MAXLINKS',3);
- define('XLINK2DEF_MAXPOPUPLINKS',100);
- define('XLINK2DEF_MAXLINKEDFIELD',1);
- @require_once 'pack.autocomplete.inc';
- /// Gestion des champs Lien entre les objets des tables
- class XLink2Def extends XFieldDef {
- public $filter='';
- public $query='';
- public $boxsizxe=6;
- public $usedefault=true;
- public $checkbox=true;
- public $doublebox=false;
- public $checkbox_limit=30;
- public $autocomplete=true;
- public $autocomplete_limit=200;
- public $generate_link = true;
- public $checkbox_cols=3;
- private $_cache=array();
- protected $modsUsingTable=NULL;
- public $query_formats=array('classic','listbox-one','listbox','autocomplete');
- public $advanceeditbatch=true;
- public $display_format='';
- public $linkedfields1=NULL;
- protected $fieldlist=NULL;
-
- function __construct($obj=NULL) {
- parent::__construct($obj);
- }
- function cacheable() { return false; }
- function clearCache(){ $this->_cache=array(); }
- function initOptions() {
- parent::initOptions();
- $this->_options->delOpt('dependency');
- $this->_options->delOpt('aliasmodule');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','sourcemodule'),'sourcemodule','module',array('emptyok'=>true));
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','usedefault'), "usedefault", "boolean", array(),true);
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','filter'), 'filter', 'text',array('rows'=>2,'cols'=>60));
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','query'), 'query', 'text',array('rows'=>2,'cols'=>60));
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','display_format'), 'display_format', 'text');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','checkbox'), 'checkbox', 'boolean');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','checkbox_limit'), 'checkbox_limit', 'text');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','checkbox_cols'), 'checkbox_cols', 'text');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','autocomplete'), 'autocomplete', 'boolean',NULL,true);
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','autocomplete_limit'), 'autocomplete_limit', 'text',NULL,200);
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','doublebox'), 'doublebox', 'boolean',NULL,false);
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','boxsize'), 'boxsize', 'text', NULL, 6);
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','grouplist'), 'grouplist', 'boolean', NULL, false);
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','generate_link'), 'generate_link', 'boolean',NULL, true);
- for($i=1; $i<=XLINK2DEF_MAXLINKEDFIELD; $i++) {
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','linkedfield').' '.$i, 'linkedfields'.$i, 'field', array('table'=>$this->table, 'compulsory'=>false, 'type'=>array('XLink2Def')), '');
- }
- }
- /**
- * Génère le formulaire d'édition des options du champs
- * @see XOptions::getDialog()
- */
- function getOptions($block='opt') {
- return XLinkDef::getOptions($block);
- }
- function get_sqlValue($value) {
- // Fabrique une valeur de colonne pour SQL à partir d'une valeur issue de PHP
- // $value est ici un tableau. 1 seul valeur si champ single value, n valeurs si multi value
- if ( !is_array($value) ) return $value;
- $nb = count($value);
- if ( $nb == 0 ) return '';
- if ( (!$this->get_multivalued()) || ($nb==1) ) {
- return $value;
- }
- else {
- $val = '||';
- for ($i=0;$i<$nb;$i++) {
- $val .= $value[$i] . '||';
- }
- return $val;
- }
- }
- function my_export($value, $options=NULL) {
- return $value;
- }
- function &getValues($filter2, $options=array()) {
- $mod=&$options['mod'];
- $max=$options['max'];
- $lang=XShell::getLangUser();
- $lang_data=XShell::getLangData();
- $result=array();
- if($this->target==TZR_DEFAULT_TARGET || !XDataSource::sourceExists($this->target)) return $result;
- // Liste des champs à recuperer
- list($myliste,$my_flist,$first)=$this->getFieldList($options,false);
- // Création de la requete
- $textfilter2=(count($myliste)>0)?'concat(':'';
- $fromcomp='';
- $i=0;
- foreach($myliste as $fn=>$obj){
- $i++;
- if($filter2){
- if(in_array($obj->get_ftype(),array('XTextDef','XShortTextDef','XRichTextDef')))
- $textfilter2.='ifnull('.$this->target.'.'.$fn.',""),\' \',';
- elseif($obj->isObjectLink() && !empty($obj->target) && $obj->target!='%'){
- $tablealias=$obj->target.'_'.$i;
- $fromcomp.=' left outer join '.$obj->target.' as '.$tablealias.' on '.$tablealias.'.KOID='.$this->target.'.'.$fn.' and '.$tablealias.'.LANG="'.TZR_DEFAULT_LANG.'" ';
- $rslink=&cacheSelectQuery('select * from DICT where PUBLISHED=1 and DTAB="'.$obj->target.'" and FTYPE="XShortTextDef" ORDER BY FORDER');
- while($rslink && ($orslink=$rslink->fetch())) $textfilter2.='ifnull('.$tablealias.'.'.$orslink['FIELD'].',""),\' \',';
- $rslink->CloseCursor();
- }elseif($obj->get_ftype()=='XStringSetDef'){
- $tablealias='SETS_'.$i;
- $fromcomp.=' LEFT OUTER JOIN SETS AS '.$tablealias.' ON '.$tablealias.'.SOID='.$this->target.'.'.$fn.' AND '.
- $tablealias.'.SLANG="'.TZR_DEFAULT_LANG.'" AND '.$tablealias.'.STAB="'.$this->target.'" AND '.$tablealias.'.FIELD="'.$fn.'" ';
- $textfilter2.='IFNULL('.$tablealias.'.STXT,""),\' \',';
- }
- }
- }
- if($textfilter2) $textfilter2 ='('.substr($textfilter2,0,-5).')'.' LIKE "%'.$filter2.'%") AND ';
- $filter=$this->filter;
- if(!empty($options['filter'])) $filter='('.$options['filter'].')';
- if(!empty($filter)) $filter.=' AND ';
- $rs2=selectQuery('select distinct '.$my_flist.' FROM '.$this->target.' '.$fromcomp.
- ' WHERE '.$textfilter2.' '.$filter.' '.$this->target.'.LANG="'.TZR_DEFAULT_LANG.'" '.
- (!empty($myliste)?'order by '.$this->target.'.'.implode(','.$this->target.'.',array_keys($myliste)):''));
- // Generation de la boite de saisie
- $state='ok';
- $tot=0;
- $opts=array('_published'=>'all', '_charset'=>$options['_charset']);
- while($ors2=$rs2->fetch()) {
- if(!empty($max) && $tot>$max){
- $state='toomuch';
- break;
- }
- $my_oid=$ors2['KOID'];
- if(!empty($mod) && $mod->object_sec && Kernel::getTable($my_oid)==$mod->table && !$mod->secure($my_oid,':ro')) continue;
- $result[$my_oid]=trim($this->format_display($myliste,$ors2,$opts,null,'text'));
- $tot++;
- }
- return array('values'=>$result,'state'=>$state);;
- }
- function sqltype() {
- return 'text';
- }
- /**
- * Affichage du champ lien, appel rDisplay sur la cible
- * (traitement multivalue dans xfielddef)
- * ! effet de bord : si l'objet est introuvable, supprime tous les liens vers cet objet
- * sauf si XDbIni[disable_xlinkclean] est positionné à 1
- * @param KOID $value unique dans la table cible ou 'UNPUBLISHED',
- * @param array $options [
- * string _format application/excel, application/prince
- * string _charset charset passé au rDisplay
- * mixed target_fields tableau des champs ramenés ou 'all' (rDisplay selectedfields)
- * boolean nocache n'utilise pas le cache
- * boolean nofollowlinks retourne juste l'oid sans appel au rdisplay
- * ]
- * @return XFieldVal
- */
- function my_display(&$value, &$options) {
- $_format = @$options['_format'];
- $LANG_DATA = XShell::getLangData();
- $lang = XShell::getLangUser();
- $olddisplayformat=NULL;
- // Verifie le cache
- if(isset($this->_cache[$value]) && @$options['nocache']!==true) {
- $r=clone $this->_cache[$value];
- return $r;
- }
- // OID valide
- $r=&$this->_newXFieldVal($options);
- if(empty($value) || strpos($value,'VOID:')) return $r;
- // l'oid sans la cible
- if(!empty($options['nofollowlinks'])) {
- $r->raw=$value;
- $r->html='';
- return $r;
- }
- // Table existe
- $target=Kernel::getTable($value);
- if(!XSystem::tableExists($target)) return $r;
- // Droit sur le module source de données
- if($this->sourcemodule){
- $mod=XModule::objectFactory($this->sourcemodule);
- if($mod->object_sec && !$mod->secure($value,':ro') || !$mod->object_sec && !$mod->secure('',':ro')) return $r;
- }
- $target_ds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$target);
- if(!empty($options['target_options'])) $targetopts=$options['target_options'];
- else $targetopts=array();
- if(!empty($options['_charset'])) $targetopts['_charset']=$options['_charset'];
- else $targetopts['_charset'] = XLang::getCharset();
- // Liste des champs à recuperer
- if(@$options['display_format']){
- $olddisplayformat=$this->display_format;
- $this->display_format=$options['display_format'];
- }
- if(strpos($this->display_format,'%_')!==false){
- preg_match_all('/%_([a-z0-9_]+)/i',$this->display_format,$fmtfields);
- $fmtfields=$fmtfields[1];
- }else{
- $fmtfields=array();
- }
- if(isset($options['target_fields'])) $targetopts['selectedfields']=$options['target_fields'];
- else $targetopts['selectedfields']=$target_ds->getPublished(false);
- $targetopts['selectedfields']=array_merge($fmtfields,$targetopts['selectedfields']);
- // Recupere les champs de l'objet cible
- $values=&$target_ds->rDisplay($value, array(), false, $LANG_DATA, $lang, $targetopts);
- $cnt=count($values['fields_object']);
- if (XShell::admini_mode())
- $cnt = max($cnt, $this->getNbPublishedFields());
- // Si l'oid n'existe plus, on met à jour la table pour supprimer l'oid partout ou il est present et on retourne un objet sans valeur
- if(!is_array($values) && $values!='UNPUBLISHED' && XDbIni::get('disable_xlinkclean','val')!=1) {
- // Si la table est traduisible et qu'on est pas dans la langue par defaut, on verifie si l'oid existe dans au moins une langue
- if($target_ds->isTranslatable() && $LANG_DATA!=TZR_DEFAULT_LANG){
- $nb=countSelectQuery('SELECT count(*) FROM '.$this->target.' WHERE KOID="'.$value.'"');
- if($nb) return $r;
- }
- // Multivalué, traite tous les cas possibles (%||oid||%, oid||% et %||oid)
- $tolog=($target_ds->toLog() && $this->table!='LOGS');
- if($this->multivalued){
- $l=strlen($value);
- // %||oid||%
- if($tolog) {
- $rs=selectQuery('select KOID from '.$this->table.' where '.$this->field.' like "%||'.$value.'||%"');
- while($rs && ($ors=$rs->fetch())) XLogs::update('update',$ors['KOID'],'remove oid '.$value.' from '.$this->field);
- }
- if(!$tolog || $rs->rowCount()>0) {
- updateQuery('update '.$this->table.' set UPD=UPD,'.$this->field.'=REPLACE('.$this->field.',"||'.$value.'||","||") '.
- 'where '.$this->field.' like "%||'.$value.'||%"');
- }
- // oid||%
- if($tolog) {
- $rs=selectQuery('select KOID from '.$this->table.' where '.$this->field.' like "'.$value.'||%"');
- while($rs && ($ors=$rs->fetch())) XLogs::update('update',$ors['KOID'],'remove oid '.$value.' from '.$this->field);
- }
- if(!$tolog || $rs->rowCount()>0) {
- updateQuery('update '.$this->table.' set UPD=UPD,'.$this->field.'=SUBSTR('.$this->field.','.($l+3).') '.
- 'where '.$this->field.' like "'.$value.'||%"');
- }
- // %||oid
- if($tolog) {
- $rs=selectQuery('select KOID from '.$this->table.' where '.$this->field.' like "%||'.$value.'||%"');
- while($rs && ($ors=$rs->fetch())) XLogs::update('update',$ors['KOID'],'remove oid '.$value.' from '.$this->field);
- }
- if(!$tolog || $rs->rowCount()>0) {
- updateQuery('update '.$this->table.' set UPD=UPD,'.$this->field.'=SUBSTR('.$this->field.',1,LENGTH('.$this->field.')-'.($l+2).') '.
- 'where '.$this->field.' like "%||'.$value.'"');
- }
- }
- if($tolog) {
- $rs=selectQuery('select KOID from '.$this->table.' where '.$this->field.'="'.$value.'"');
- while($rs && ($ors=$rs->fetch())) XLogs::update('update',$ors['KOID'],'remove oid '.$value.' from '.$this->field);
- }
- if(!$tolog || $rs->rowCount()>0) updateQuery('update '.$this->table.' set UPD=UPD,'.$this->field.'="" where '.$this->field.'="'.$value.'"');
- $r->raw='';
- return $r;
- }elseif($values=='UNPUBLISHED'){
- $r->raw='';
- return $r;
- }
- // Prepare le html
- $display='';
- if(!empty($this->display_format)){
- if(strpos($this->display_format,'%_')!==false){
- $display=$this->display_format;
- foreach($fmtfields as $f) $display=str_replace('%_'.$f,$values['o'.$f]->html,$display);
- }else{
- $htmls=array();
- foreach($values['fields_object'] as $f) $htmls[]=$f->html;
- $display=@vsprintf($this->display_format,array_pad($htmls,substr_count($this->display_format,'%'),''));
- }
- }
- if(empty($this->display_format) || $display===false){
- for($i=0;$i<$this->getNbPublishedFields();$i++) {
- if(!isset($values['fields_object'][$i])) break;
- if($i==0) $display.=$values['fields_object'][$i]->html;
- else $display.=' '.$values['fields_object'][$i]->html;
- }
- }
- // Ajoute les liens vers l'objet dans le html si necessaire
- $r->html=$display;
- if(XShell::admini_mode() && $this->generate_link){
- if($this->modsUsingTable===NULL){
- if($this->sourcemodule) $this->modsUsingTable=array($mod->_moid=>$mod->modulename);
- else $this->modsUsingTable=XModule::modulesUsingTable($target,false,true,true,true);
- }
- if(!empty($this->modsUsingTable)) {
- $url=$GLOBALS['TZR_SESSION_MANAGER']::admin_url(false,true);
- if($_format!='application/prince' && $_format!='application/excel') {
- if(count($this->modsUsingTable)>1) {
- $mi=0;
- foreach($this->modsUsingTable as $mod=>&$label) {
- $mi++;
- if($mi<=XLINK2DEF_MAXLINKS) {
- if($mi==1) $r->html.=' [';
- else $r->html.='|';
- $r->html.='<a class="cv8-ajaxlink" href="'.$url.'&moid='.$mod.'&function=goto1&oid='.$value.'" title="'.$label.'">'.$mi.'</a>';
- }
- }
- if($mi>0) $r->html.=']';
- } else {
- reset($this->modsUsingTable);
- $v1=each($this->modsUsingTable);
- $r->html='<a class="cv8-ajaxlink" href="'.$url.'&moid='.$v1['key'].'&function=goto1&oid='.$value.'" title="'.$v1['value'].'">'
- .preg_replace('@<a([^>]*)>([^<]*)</a>@i','$2',$r->html).'</a>';
- }
- }
- }
- }
- $r->title=$display;
- $r->link=$values;
- $r->raw=$value;
- $this->_cache[$value]=$r;
- if($olddisplayformat) $this->display_format=$olddisplayformat;
- return $r;
- }
- function my_browse(&$value, &$options) {
- $r= &$this->_newXFieldVal($options);
- if(!empty($options['nofollowlinks'])) {
- $r->raw=$value;
- $r->html='';
- return $r;
- }
- return $this->my_display($value, $options);
- }
- /// mise en forme des valeurs (selon options)
- /// a partir des raw values, formatte le texte pour l'oid associé
- function formatItems(&$value,&$rs, $myliste, $sourcemodule=NULL) {
- // est ce que l'on doit ajouter les groupes de champs
- // la liste est groupée sur le premier champ du lien
- if ($this->grouplist) {
- if (count($myliste) <= 1)
- $this->groupliste == false;
- else {
- $fields = array_keys($myliste);
- $groupField = $fields[0];
- $groupListe[$groupField] = array_shift($myliste);
- }
- }
- $items = array();
- // ???
- $opts=array('_published'=>'all');
- $i=0;
- while($rs && $ors=$rs->fetch()) {
- $i++;
- $koid=$ors['KOID'];
-
- if(isset($sourcemodule) && $sourcemodule->object_sec && !$sourcemodule->secure($koid,':ro')) continue;
-
- if ($this->grouplist && $currentGroup != $ors[$groupField]) {
- $currentGroup = $ors[$groupField];
- $groupLabel = $this->format_display($groupListe,$ors,$opts,null,'text');
- $items[] = array('koid'=>NULL, 'label'=>$grouplabel, 'type'=>'group');
- $i++;
- }
- $display=$this->format_display($myliste,$ors,$opts,null,'text');
- $item = array('koid'=>$koid, 'label'=>$display, 'type'=>'item', 'selected'=>false);
- if((is_array($value) && isset($value[$koid])) || ($koid==$value))
- $item['selected']=true;
- $items[] = $item;
- }
- return $items;
- }
- /// construit la requete de chargement des valeurs
- /// paramètres optionnels : target_fields, filter, _published
- function getRawValues(&$value, &$options){
- $p=new XParam($options,array());
- $lang_data=XShell::getLangData();
- $queryfilter = NULL;
- $queryorder = NULL;
- // cas ou il y a une requete qui donne l'ensemble des valeurs
- if(!empty($this->query)) {
- preg_match('/^SELECT (.+) FROM .+( WHERE (.*))?( ORDER BY .*)?$/Ui', $this->query, $matches);
- if(!isset($options['target_fields']) && $matches[1]!='*') $options['target_fields'] = explode(',', $matches[1]);
- $queryfilter=$matches[3];
- $queryorder=$matches[4];
- }
- // liste des champs à lire
- list($myliste,$my_flist,$first)=$this->getFieldList($options);
- // Construction de la requete
- $dstarget = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->target);
- if (!$dstarget->isTranslatable())
- $lang_data=TZR_DEFAULT_LANG;
- if(!empty($options['filter'])) $filter='('.$options['filter'].')';
- else $filter=$this->filter;
- if(!empty($queryfilter)) {
- if(!empty($filter)) $filter.=' AND ';
- $filter.=$queryfilter;
- }
- if($dstarget->publishedMode($p) == 'public'){
- if(!empty($filter)) $filter .= ' AND ';
- $filter .= ' PUBLISH = 1 ';
- }
- if(!empty($filter)) $filter.=' AND ';
- $maxrecords=max($this->checkbox_limit, $this->autocomplete_limit)+1;
- $rs2=selectQuery('SELECT DISTINCT '.$my_flist.' FROM '.$this->target.' WHERE '.$filter.' LANG="'.$lang_data.'"'.
- ($queryorder?$queryorder:($first?' ORDER BY '.$first:'')).' LIMIT '.$maxrecords);
- return $rs2;
- }
- /// Un champ de type Lien n'est en edit que sur la langue par defaut.
- function my_edit(&$value,&$options) {
- /* controles affichage des valeurs possibles */
- if($this->target==TZR_DEFAULT_TARGET){
- return $this->my_display($value,$options);
- }
- $sourcemodule = NULL;
- if($this->sourcemodule){
- $sourcemodule=XModule::objectFactory($this->sourcemodule);
- if($sourcemodule->object_sec && !$sourcemodule->secure('',':list') || !$sourcemodule->object_sec && !$sourcemodule->secure('',':ro')) return;
- }
- // valeur en retour
- $r=$this->_newXFieldVal($options);
- $r->raw=$value;
- if(!XDataSource::sourceExists($this->target)) {
- $r->html='';
- return $r;
- }
- $format=@$options['fmt'];
- // Noms des champs de formulaire
- if(isset($options['intable'])) {
- $o=$options['intable'];
- $fname=$this->field.'['.$o.']';
- $hiddenname=$this->field.'_HID['.$o.']';
- } elseif(!empty($options['fieldname'])) {
- $fname=$options['fieldname'];
- $hiddenname=$options['fieldname'].'_HID';
- } else {
- $fname=$this->field;
- $hiddenname=$this->field.'_HID';
- }
- // Liste des champs de la cible
- if(isset($options['display_format'])){
- $olddisplayformat=$this->display_format;
- $this->display_format=$options['display_format'];
- }
- list($myliste,$my_flist,$first)=$this->getFieldList($options);
- //
- $rs = $this->getRawValues($value, $options);
- // html du champ selon format de saisie
- $nb=($rs?$rs->rowCount():0);
- // dans cette version, on ne génère que des selects
- $this->checkbox_limit = 0;
- $this->autocomplete_limit = 99999;
- $this->doublebox = false;
- $checkbox=($nb<=$this->checkbox_limit || $format=='checkbox') && $format!='listbox' && $this->checkbox && empty($options['simple']);
- $autocomplete=($nb>=$this->autocomplete_limit && $this->autocomplete);
- $doublebox=($this->multivalued && $this->doublebox && empty($options['simple']));
-
- if($checkbox)$this->getCheckboxes($value,$options,$r,$rs,$fname,$hiddenname,$myliste);
- elseif($autocomplete) $this->getAutocomplete($value,$options,$r,$rs,$fname,$hiddenname,$myliste);
- elseif($doublebox) $this->getDoubleSelect($value,$options,$r,$rs,$fname,$hiddenname,$myliste);
- else $this->getSelect($value,$options,$r,$rs,$fname,$hiddenname,$myliste, $sourcemodule);
- if($olddisplayformat) $this->display_format=$olddisplayformat;
- return $r;
- }
- // Edition du champ sous la forme d'une liste déroulante
- function getSelect(&$value,&$options,&$r,&$rs,$fname,$hiddenname,$myliste, $sourcemodule) {
- $qf=@$options['query_format'];
- $items = $this->formatItems($value, $rs, $myliste, $sourcemodule);
- $r->html = '';
-
- $i = 0;
- // on transforme en options et on ajoute le select ... plus le reste
- foreach($items as $item){
- $i++;
- if ($item['type'] == 'group')
- $r->html .= '<optgroup label="'.$item['label'].'">';
- else{
- $r->html.='<option value="'.$item['koid'].'"'.($item['selected']?' selected' :'').'>'.$item['label'].'</option>';
- $r->collection = $item['label'];
- $r->oidcollection = $item['koid'];
- if ($item['selected']){
- $r->text = $item['label'];
- }
- }
- }
- if($qf){
- // cas des recherches ?
- $labelin=@$options['labelin'];
- $format=@$options['fmt'];
- if(empty($format)) $format=@$options['qfmt'];
- if(empty($format)) $format=$this->query_format;
- if(empty($labelin)) $first='<option value="">----</option>';
- elseif(empty($first) || $format=='listbox') $first='<option value="">'.$this->label.'</option>';
- else{
- $first.='<option value="">'.XLabels::getSysLabel('xfielddef','n/a').'</option>';
- $r->html=str_replace('" selected>','">',$r->html);
- }
- $i++;
- if($i<2 || $format=='listbox-one') $r->html='<select name="'.$fname.'" id="'.$fname.'">'.$first.$r->html.'</select>';
- else $r->html='<select name="'.$fname.'[]" id="'.$fname.'" size="'.min($i,$this->boxsize).'" multiple>'.$first.$r->html.'</select>';
- }else{
- // cas std
- //$r->html = ''; empêche l'édition par lot de fonctionner ??
- $r->varid=XShell::uniqId().$this->table.$this->field;
- if(!$this->compulsory || !$this->usedefault) {
- $r->html='<option value="">----</option>'.$r->html;
- $i++;
- }
- if($this->multivalued) $cplt='name="'.$fname.'[]" size="'.min($i,$this->boxsize).'" multiple';
- else $cplt='name="'.$fname.'"';
- $cplt .= ' data-value="'.(is_array($value)?implode('||', array_keys($value)):$value).'" ';
- $r->html='<select '.$cplt.' id="'.$r->varid.'" onblur="TZR.isIdValid(\''.$r->varid.'\');">'.$r->html.'</select>';
- if($this->compulsory) {
- $r->html.='<script type="text/javascript">TZR.addValidator(["'.$r->varid.'","compselect","'.addslashes($this->label).'","'.XIni::get('error_color').'",'.'"XLinkDef"]);</script>';
- }
- $url=TZR_AJAX8.'?class=xlink2def&function=xlink2def_getValues&_silent=1';
- XLogs::notice(get_class($this), "::(getLinked) recherche des champs liens pour {$this->field}");
- // recherche des paramètres des champs liens (dans cette version : un seul)
- $linkedfields = $this->getLinkedfields();
- if (!empty($linkedfields)){
- $uniqid = XShell::uniqId();
- $revs = array();
- foreach($linkedfields as &$linkedfield){
- $linkedfield->fmoid = $options['fmoid'];
- $linkedfield->url = $url;
- $linkedfield->uniqid = $uniqid;
- $linkedfield->varid = $uniqid.$this->table.$linkedfield->field;
- $linkedfield->table = $this->table;
- XLogs::notice(get_class($this), "(getLinked) {$this->field} <= {$linkedfield->ofield->field}");
- $revs[] = (object)array('ofield'=>$linkedfield->ofield, 'linkedfields'=>$linkedfield->ofield->getLinkedFields($this->field));
- unset($linkedfield->ofield);
- }
- $linkedfields = json_encode($linkedfields);
- $linkdesc = '{field:"'.$fname.'", fmoid:'.$options['fmoid'].', url:"'.$url.'", uniqid:"'.$uniqid.'", varid:"'.$r->varid.'", table:"'.$this->table.'"}, '.$linkedfields.'';
- $r->html.='<script type="text/javascript">TZR.linkedfields.add('.$linkdesc.');</script>';
- // pour chaque champs lié ajout recherche et ajout de la "reciproque"
- $linkedfields2 = array();
- foreach($revs as $rev){
- $ofield = $rev->ofield;
- $ofield->varid = $uniqid.$this->table.$ofield->field;
- $linkedfield2 = $rev->linkedfields[0];
- $linkedfield2->fmoid = $options['fmoid'];
- $linkedfield2->url = $url;
- $linkedfield2->uniqid = $uniqid; // verifier ne sert pas ...
- $linkedfield2->varid = $uniqid.$this->table.$linkedfield2->field;
- $linkedfield2->table = $this->table;
- unset($linkedfield2->ofield);
- $linkedfields2[] = $linkedfield2;
- $linkedfields2 = json_encode($linkedfields2);
- $linkdesc2 = '{field:"'.$ofield->field.'", fmoid:'.$options['fmoid'].', url:"'.$url.'", uniqid:"'.$uniqid.'", varid:"'.$ofield->varid.'", table:"'.$this->table.'"}, '.$linkedfields2.'';
- // echo("<br>{$this->field} => {$linkedfield2->field} $linkdesc2 ");
- $r->html.='<script type="text/javascript">TZR.linkedfields.add('.$linkdesc2.');</script>';
- }
- }
- }
- }
- /// récuperation des paramètres sur les champs liés
- function getLinkedfields($linkedfield=NULL){
- $linkedfields = array();
- if ($linkedfield == NULL)
- $linkedfield = $this->linkedfields1;
- $myds = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->table);
- if (empty($linkedfield) || !$myds->fieldExists($linkedfield))
- return array();
- $fd = $myds->desc[$linkedfield];
- $linkdesc = self::getLinkedFieldDesc($fd, $this->target);
- if ($linkdesc != NULL)
- $linkedfields[] = (object)array('ofield'=>$fd,'field'=>$fd->field, 'query'=>(object)array('queryfield'=>$linkdesc->queryfield));
- else{
- $linkdesc = self::getLinkedFieldDesc($this, $fd->target);
- if ($linkdesc == NULL)
- return array();
- else
- $linkedfields[] = (object)array('ofield'=>$fd, 'field'=>$fd->field, 'query'=>(object)array('table'=>$linkdesc->target, 'queryfield'=>$linkdesc->queryfield));
- }
- return $linkedfields;
- }
- ///
- protected static function getLinkedFieldDesc($fd, $target){
- $linkdesc = NULL;
- if (!empty($fd->target)){
- $ds = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$fd->target);
- $links = $ds->getFieldsList(XFieldDef::getObjectLinkTypes());
- foreach($links as $fn){
- if ($ds->desc[$fn]->target == $target){
- return(object)array('field'=>$fd->field, 'target'=>$fd->target, 'queryfield'=>$fn, 'fieldobject'=>$fd);
- }
- }
- }
- return NULL;
- }
- /// Recherche
- function my_query($value,$options=NULL) {
- $format=@$options['fmt'];
- if(empty($format)) $format=@$options['qfmt'];
- if(empty($format)) $format=$this->query_format;
- $searchmode=@$options['searchmode'];
- $fname=(isset($options['fieldname'])?$options['fieldname']:$this->field);
- $hiddenname=$fname.'_HID';
- $r=$this->_newXFieldVal($options,true);
- $r->raw=$value;
- if($this->target==TZR_DEFAULT_TARGET) {
- $r->html.='<input name="'.$fname.'" size="30" type="text" value="'.$value.'">';
- return $r;
- }
- // Liste des champs de la cible
- if($options['display_format']){
- $olddisplayformat=$this->display_format;
- $this->display_format=$options['display_format'];
- }
- list($myliste,$my_flist,$first)=$this->getFieldList($options);
- $options['query_format']=1;
- if($format=='autocomplete'){
- $this->getAutocomplete($value,$options,$r,$rs,$fname,$hiddenname,$myliste);
- return $r;
- }
- // Construction de la requete
- $filter=array();
- if(!empty($options['filter'])) $filter[]='('.$options['filter'].')';
- elseif(!empty($this->filter)) $filter[]='('.$this->filter.')';
- if(!empty($this->query)) {
- $inclause=array();
- $rs=selectQuery($this->query);
- while($rs && ($ors=$rs->fetch())) $inclause[]="'".$ors['KOID']."'";
- $filter[]='(KOID IN ('.implode(',',$inclause).'))';
- }
- if($searchmode=='simple') {
- $allvalues=array();
- $selectquery=@$options['select'];
- if(!empty($selectquery)) $allvalues=$this->_getUsedValues(NULL,$selectquery);
- else $allvalues=$this->_getUsedValues("LANG='".TZR_DEFAULT_LANG."'");
- $filter[]='(KOID IN ("'.implode('","',array_keys($allvalues)).'"))';
- }
- if(!empty($filter)) $filter=implode(' AND ',$filter).' AND ';
- else $filter='';
- $rs2=cacheSelectQuery("select distinct $my_flist from ".$this->target." where $filter LANG='".TZR_DEFAULT_LANG."'".
- ' '.($first ? "order by $first":""));
- // Format de la saisie
- if($rs2) $nb=$rs2->rowCount();
- if ($nb >= $this->autocomplete_limit && $this->autocomplete && !$this->multivalue) {
- $this->getAutocomplete($value,$options,$r,$rs2,$fname,$hiddenname,$myliste);
- return $r;
- }
- $checkbox=(($nb<=$this->checkbox_limit || $format=='checkbox') && $format!='listbox' && $format!='listbox-one' && $this->checkbox);
- if($this->get_multivalued() && $format!='listbox-one'){
- $varid=$r->varid;
- $op=$options['op'];
- $medit='<input class="radio" type="radio" name="'.$fname.'_op" value="AND" id="'.$varid.'-AND" checked>'.
- '<label for="'.$varid.'-AND">'.XLabels::getSysLabel('xfielddef.xlinkdef_allterms').'</label> '.
- '<input class="radio" type="radio" name="'.$fname.'_op" value="OR" id="'.$varid.'-OR"'.($op=='OR'?' checked':'').'>'.
- '<label for="'.$varid.'-OR">'.XLabels::getSysLabel('xfielddef.xlinkdef_leastaterm').'</label><br>';
- }else{
- $medit='';
- }
- if($checkbox) $this->getCheckboxes($value,$options,$r,$rs2,$fname,$hiddenname,$myliste);
- else $this->getSelect($value,$options,$r,$rs2,$fname,$hiddenname,$myliste);
- $r->html=$medit.$r->html;
- if($olddisplayformat) $this->display_format=$olddisplayformat;
- return $r;
- }
- function my_quickquery($value,$options=NULL) {
- $oldc=$this->checkbox;
- $oldd=$this->doublebox;
- $olda=$this->autocomplete;
- $this->checkbox=false;
- $this->doublebox=false;
- $this->autocomplete=true;
- $ret=$this->query($value, $options);
- $ret->html.='<input type="hidden" value="'.$this->field.'" name="_FIELDS['.$this->field.']">';
- $this->checkbox=$oldc;
- $this->doublebox=$oldd;
- $this->autocomplete=$olda;
- return $ret;
- }
- function post_edit($value,$options,&$computed_fields=NULL){
- $r=$this->_newXFieldVal($options);
- $oid=$options['oid'];
- $ischeckbox=(@$options[$this->field.'_HID']=='checkbox')||(@$options[$this->field.'_FMT']=='checkbox');
- if($ischeckbox) {
- $nvalue=array();
- // Attention éviter les liens vers lui-même
- foreach($value as $soid => $set) {
- if($soid!='Foo' && $soid!=$oid) $nvalue[]=$soid;
- }
- $value=$nvalue;
- }else{
- if(is_array($value)){
- foreach($value as $i=>$foo){
- if(empty($foo)) unset($value[$i]);
- }
- }
- }
- if(!empty($this->exif_source) && empty($value)){
- $value=array();
- $meta=$this->getMetaValue($computed_fields,array('IPTC','EXIF','XMP'),true);
- if(!is_array($meta->raw)) $meta->raw=array($meta->raw);
- $opt=array('srcField'=>$this->flabel);
- if($this->isAutorizedToAdd($options)) $opt['create']=true;
- foreach($meta->raw as $i=>$v){
- if(!is_string($v)) continue;
- $ret=$this->my_import($v,$opt);
- $value[]=$ret['value'][0];
- }
- }
- if($value==$oid) $value=NULL;
- $r->raw=$value;
- // Edition par lot sur champ multivalué
- if(!empty($options['editbatch']) && $this->multivalued){
- $p=new XParam($ar,NULL);
- $op=$p->get($this->field.'_op');
- $old=explode('||',$options['old']->raw);
- if($op=='+') $r->raw=array_unique(array_merge($r->raw,$old));
- elseif($op=='-') $r->raw=array_diff($old,$r->raw);
- }
- // Trace
- $old=@$options['old'];
- if(!empty($old)){
- if(is_array($r->raw)) $v=implode('||',$r->raw);
- else $v=$r->raw;
- $r1=&$this->display($v,$options);
- if($r1->html!=$old->html) $this->trace($options['old'],$r, '['.$old->html.'] -> ['.$r1->html.']');
- }
- return $r;
- }
- /// Autorise l'ajout d'une entrée à la volée
- public function isAutorizedToAdd(&$options){
- if($this->sourcemodule){
- if(empty($this->cache->modules[$this->sourcemodule])){
- $this->cache->modules[$this->sourcemodule]=XModule::objectFactory($this->sourcemodule);
- }
- return $this->cache->modules[$this->sourcemodule]->secure('',':rw');
- }elseif(!empty($options['fmoid'])){
- if(empty($this->cache->modules[$options['fmoid']])){
- $this->cache->modules[$options['fmoid']]=XModule::objectFactory($options['fmoid']);
- }
- return $this->cache->modules[$options['fmoid']]->secure($options['oid'],':rwv');
- }
- return false;
- }
- function post_query(&$o,$options=NULL) {
- $p=new XParam($options,array());
- $ischeckbox=($o->hid=='checkbox') || ($o->fmt=='checkbox');
- if($ischeckbox && is_array($o->value)) {
- $nvalue=array();
- foreach($o->value as $soid => $set) {
- $nvalue[]=$soid;
- }
- $o->value=$nvalue;
- }
- return parent::post_query($o,$options);
- }
- function search($value,$options=NULL){
- if($this->target!='%'){
- if(!is_array($value)) $value=array($value);
- $cond=array();
- $x=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->target);
- if(!empty($options['target_fields'])) $pub=$options['target_fields'];
- else $pub=$x->getPublished(false);
- foreach($value as $v) $cond[]='concat('.implode('," ",',$pub).') like "%'.addslashes($v).'%"';
- if(!empty($cond)) return $this->field.' in (select KOID from '.$this->target.' where '.implode($cond,' or ').')';
- else return '';
- }
- }
- function getNbPublishedFields(){
- if(!XShell::admini_mode()) return 99;
- if($this->target=='%' || empty($this->target)) return 2;
- if(strpos($this->display_format,'%')!==false) return 99;
- if(empty($this->published_fields_in_admin)){
- $tablexset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->target);
- $this->published_fields_in_admin=$tablexset->published_fields_in_admin;
- }
- return $this->published_fields_in_admin;
- }
- /// Formate l'affichage d'un lien
- function format_display(&$myliste,&$ors,&$opt,$nbpublishedfields=NULL,$prop='html'){
- reset($myliste);
- $display='';
- $htmls=array();
- $replace=false;
- if(!empty($this->display_format) && strpos($this->display_format,'%_')!==false){
- $replace=true;
- $display=$this->display_format;
- }
- foreach($myliste as $k=>$f){
- $o=$f->display($ors[$k],$opt);
- $t=$o->$prop;
- if($replace) $display=str_replace('%_'.$k,$t,$display);
- else $htmls[]=$t;
- }
- if(!$replace){
- if(!empty($this->display_format)) $display=@vsprintf($this->display_format,array_pad($htmls,substr_count($this->display_format,'%'),''));
- else $display=implode(' ',$htmls);
- }
- return $display;
- }
- /// Ecriture dans un fichier excel
- function writeXLS(&$xl,$i,$j,&$value,$format=0,&$ss=NULL) {
- $t=str_replace(' ', ' ', $value->toText());
- $t=preg_replace('/\[.*\]/', '', $t);
- convert_charset($t,TZR_INTERNAL_CHARSET,'UTF-8');
- $xl->setCellValueByColumnAndRow($j,$i,$t);
- if(is_array($format)) $xl->getStyleByColumnAndRow($j,$i)->applyFromArray($format);
- }
- /// Sous fonction pour l'import de données vers une table
- /// Options : srcField (string) => champ à utiliser dans la table cible pour creer le lien (si vide la valeur doit etre un oid)
- /// create (true/false) => creation automatique des fiches cible non existante (false par defaut)
- /// separator (string) => séparateur pour des valeurs multiples (| par defaut)
- /// forcekoid (true/false) => force la génération de l'oid à partir de la valeur (false par defaut)
- function my_import($value,&$options){
- $separator=(string)$options['separator'];
- if(empty($separator)) $separator='|';
- $create=(string)$options['create'];
- $forcekoid=(string)$options['forcekoid'];
- $srcField=(string)$options['srcField'];
- $message='';
- if($value!=''){
- if(empty($srcField) && !Kernel::isAMultipleKoid($value)){
- $ors=selectQueryGetOne('select FIELD from DICT where DTAB="'.$this->target.'" and PUBLISHED=1 order by forder limit 1');
- @$srcField=$ors['FIELD'];
- }
- if($srcField){
- $ret=array();
- cp1252_replace($value);
- $valueslist=explode($separator,$value);
- $ret=array();
- foreach($valueslist as $v){
- $v=trim($v);
- if($v!=''){
- $filter=$this->filter;
- if(!empty($options['filter'])) $filter='('.$options['filter'].')';
- if(!empty($filter)) $filter.=' AND ';
- $rs=selectQuery('SELECT KOID FROM '.$this->target.' WHERE '.$filter.' UPPER('.$srcField.')="'.strtoupper(addslashes($v)).'"');
- if($rs && $ors=$rs->fetch()){
- $ret[]=$ors['KOID'];
- }else{ // la target n'existe pas
- if(!empty($create) && $create!='false'){
- $toinsert=array();
- if(!empty($forcekoid) && $forcekoid!='false'){
- $toinsert['newoid']=$this->target.':'.strtoupper(preg_replace('/([^a-z0-9]+)/','',rewriteToAscii($v)));
- }
- $xset=&XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->target);
- $toinsert['tplentry']=TZR_RETURN_DATA;
- $toinsert['PUBLISH']=1;
- $toinsert[$srcField]=$v;
- $mess=$xset->procInput($toinsert);
- $message.=$this->field.' : "'.$v.'" created<br/>';
- $ret[]=$mess['oid'];
- }else{
- $message.='<u>Warning</u> : '.$this->field.' : "'.$v.'" doesn\'t exist<br/>';
- }
- }
- }
- }
- }else{
- $ret=$value;
- }
- }
- return array('message'=>$message,'value'=>$ret);
- }
- /// creation d'un index si c'est un champ mono value
- function chk(&$msg) {
- parent::chk($msg);
- if(!$this->get_multivalued()) {
- // ajout d'un index sur les champs non multivalues
- if (!countSelectQuery('SHOW INDEX FROM '.$this->table.' where Column_name="'.$this->field.'"')) {
- updateQuery('ALTER TABLE '.$this->table.' ADD INDEX '.$this->field.'('.$this->field.'(40))');
- }
- // verification que le champ n'inclue pas de ||
- $rs=selectQuery('SELECT KOID,LANG,'.$this->field.' FROM '.$this->table.' WHERE '.$this->field.' like "%||%"');
- while($rs && ($ors=$rs->fetch())) {
- $oid='';
- $value=$ors[$this->field];
- $values=explode('||',$value);
- foreach($values as $value){
- if(!empty($value) && Kernel::objectExists($value)){
- $oid=$value;
- break;
- }
- }
- updateQuery('UPDATE '.$this->table.' SET UPD=UPD,'.$this->field.'="'.$oid.'" WHERE KOID="'.$ors['KOID'].'" AND LANG="'.$ors['LANG'].'"');
- }
- $rs->closeCursor();
- }
- return true;
- }
- // Edition du champ sous la forme d'une double liste déroulante
- function getDoubleSelect(&$value,&$options,&$r,&$rs,$fname,$hiddenname,$myliste){
- if($this->sourcemodule){
- $mod=XModule::objectFactory($this->sourcemodule);
- if($mod->object_sec && !$mod->secure('',':list') || !$mod->object_sec && !$mod->secure('',':ro')) return;
- }
- $oidcollection=$collection=$opts=array();
- $varid=getUniqID('v');
- $unselectedname=preg_replace('/^([^\[]+)/','$1_unselected',$fname);
- $edit1='<select name="'.$unselectedname.'" size="'.$this->boxsize.'" multiple ondblclick="TZR.doubleAdd('.
- 'this.form.elements[\''.$unselectedname.'\'],this.form.elements[\''.$fname.'[]\'],true)" class="doublebox">';
- $edit2='<select name="'.$fname.'[]" size="'.$this->boxsize.'" multiple id="'.$varid.'" ondblclick="TZR.doubleAdd(this.form.elements[\''.$fname.'[]\'],'.
- 'this.form.elements[\''.$unselectedname.'\'],true)" class="doublebox">';
- $order = 0;
- if ($this->grouplist) { // la liste est groupée sur le premier champ du lien
- if (count($myliste) <= 1)
- $this->groupliste == false;
- else {
- $fields = array_keys($myliste);
- $groupField = $fields[0];
- $groupListe[$groupField] = array_shift($myliste);
- $groupid = 0;
- }
- }
- while($ors=$rs->fetch()) {
- $order++;
- $koid=$ors['KOID'];
- if($mod && $mod->object_sec && !$mod->secure($koid,':ro')) continue;
- $selected=isset($value[$koid]);
- if ($this->grouplist && $currentGroup != $ors[$groupField]) {
- $currentGroup = $ors[$groupField];
- $groupid++;
- $groupLabel = $this->format_display($groupListe,$ors,$opts,null,'text');
- $edit1 .= '<optgroup label="'.$groupLabel.'" id="unselected_'.$fname.'_'.$groupid.'">';
- $edit2 .= '<optgroup label="'.$groupLabel.'" id="'.$fname.'_'.$groupid.'">';
- }
- $display=$this->format_display($myliste,$ors,$opts,null,'text');
- if(!$selected) $edit1.='<option value="'.$koid.'" order="'.$order.'">'.$display.'</option>';
- else $edit2.='<option value="'.$koid.'" order="'.$order.'">'.$display.'</option>';
- if($selected) $r->text.=$display;
- $oidcollection[]=$koid;
- $collection[]=$display;
- }
- $edit1.='</select>';
- $edit2.='</select>';
- $buttons='<input type="button" value=">>" onclick="TZR.doubleAdd(this.form.elements[\''.$unselectedname.'\'],'.
- 'this.form.elements[\''.$fname.'[]\'],true)"><br/>'.
- '<input type="button" value="<<" onclick="TZR.doubleAdd(this.form.elements[\''.$fname.'[]\'],'.
- 'this.form.elements[\''.$unselectedname.'\'],true)">';
- $hidd='<input type="hidden" name="'.$hiddenname.'" value="doublebox"/>';
- $color=XIni::get('error_color');
- if($this->compulsory) $t1="TZR.addValidator(['$varid',/(.+)/,'".addslashes($this->label)."','$color','XLinkDef']);";
- else $t1="TZR.addValidator(['$varid','','".addslashes($this->label)."','$color','XLinkDef']);";
- $js="<script type=\"text/javascript\">if(typeof(TZR)!='undefined') { $t1 }</script>";
- $edit='<table class="doublebox"><tr><td>'.$edit1.'</td><td class="button">'.$buttons.$hidd.'</td><td>'.$edit2.'</td></tr></table>'.$js;
- $r->oidcollection=$oidcollection;
- $r->collection=$collection;
- $r->html=$edit;
- }
- /// Edition du champ sous la forme de boite à cocher (checkbox/radio)
- function getCheckboxes(&$value,&$options,&$r,&$rs,$fname,$hiddenname,$myliste){
- if($this->sourcemodule){
- $mod=XModule::objectFactory($this->sourcemodule);
- if($mod->object_sec && !$mod->secure('',':list') || !$mod->object_sec && !$mod->secure('',':ro')) return;
- }
- $qf=@$options['query_format'];
- if($this->multivalued || ($qf==1)) $typebox='checkbox';
- else $typebox='radio';
- $my_compulsory=($this->compulsory || $options['compulsory']) && !$qf;
- $cols=0;
- $edit='<input type="hidden" name="'.$hiddenname.'" value="'.$typebox.'"/>';
- $edit.='<table class="tzr-checkboxtable">';
- $edit.='<tr>';
- if($typebox!='radio') $edit.='<input type="hidden" name="'.$fname.'[0]" value="Foo"/>';
- if(!$my_compulsory && ($typebox=='radio')) {
- $varid=getUniqID('v');
- $edit.='<td><input type="'.$typebox.'" class="checkbox" name="'.$fname.'" value="" id="'.$varid.'"/>'.
- '<label for="'.$varid.'">'.XLabels::getSysLabel('general','empty_menu').'</label></td>';
- $cols++;
- }
- $listvarid=array();
- $opts=array('_published'=>'all');
- if ($this->grouplist) { // la liste est groupée sur le premier champ du lien
- if (count($myliste) <= 1)
- $this->groupliste == false;
- else {
- $fields = array_keys($myliste);
- $groupField = $fields[0];
- $groupListe[$groupField] = array_shift($myliste);
- }
- }
- if($cols>=$this->checkbox_cols) {
- $edit.='</tr><tr>';
- $cols=0;
- }
- while($ors=$rs->fetch()) {
- $koid=$ors['KOID'];
- if($mod && $mod->object_sec && !$mod->secure($koid,':ro')) continue;
- if ($this->grouplist && $currentGroup != $ors[$groupField]) {
- $currentGroup = $ors[$groupField];
- $edit .= '</td></tr><tr><td colspan="'.$this->checkbox_cols.'">';
- $edit .= $this->format_display($groupListe,$ors,$opts,null,'html');
- $edit .= '</td></tr><tr>';
- $cols=0;
- }
- $edit.='<td>';
- $koid=$ors['KOID'];
- $varid=uniqid('v');
- $listvarid[]=$varid;
- $display=$this->format_display($myliste,$ors,$opts);
- if($this->multivalued || ($qf==1)){
- $checked=isset($value[$koid]);
- }elseif($my_compulsory && empty($value) && $this->usedefault) {
- $checked=true;
- $value=$koid;
- }else{
- $checked=($koid==$value);
- }
- if($typebox=='checkbox')
- $edit.='<input type="checkbox" class="radio" id="'.$varid.'" name="'.$fname.'['.$koid.']" '.($checked?' checked ':'').
- '/> <label for="'.$varid.'">'.$display.'</label></td>';
- else
- $edit.='<input type="radio" class="radio" id="'.$varid.'" name="'.$fname.'" value="'.$koid.'" '.
- ($checked?' checked ':'').'/> <label for="'.$varid.'">'.$display.'</label></td>';
- $cols++;
- if($checked) $r->text.=$display;
- if($cols>=$this->checkbox_cols) {
- $edit.='</tr><tr>';
- $cols=0;
- }
- $oidcollection[]=$koid;
- $collection[]=$display;
- }
- $edit.='</tr></table>';
- if(!empty($my_compulsory) && !empty($listvarid)) {
- $color=XIni::get('error_color');
- $edit.="<script type=\"text/javascript\">if(typeof(TZR)!='undefined') { TZR.addValidator(['".$listvarid[0]."','','".
- addslashes($this->label)."','$color','XLinkDef','',['".implode("','",$listvarid)."']]); }</script>";
- }
- $r->oidcollection=$oidcollection;
- $r->collection=$collection;
- $r->varid=$listvarid[0];
- $r->html=$edit;
- }
- // Edition du champ sous la forme d'une zone d'autocomplétion
- function getAutocomplete(&$value,&$options,&$r,&$rs,$fname,$hiddenname,$myliste){
- if(is_array($value)){
- $v=array_keys($value);
- $v=$v[0];
- }else $v=$value;
- $qf=@$options['query_format'];
- $lang=XShell::getLangUser();
- $lang_data=XShell::getLangData();
- if(isset($options['target_fields'])){
- $fieldslist=implode(',',$options['target_fields']);
- $pubonly=false;
- }else{
- $fieldslist='';
- $pubonly=true;
- }
- if($qf) $varid=$fname.'_id';
- else $varid=getUniqID('v');
- $textid='_INPUT'.$varid;
- $edit=$mborder=$callback=$js=$fmt='';
- if(!$qf && $this->compulsory) {
- $mborder='tzr-input-compulsory';
- if(!$this->multivalued) $fmt=' onblur="TZR.isIdValid(\''.$varid.'\')" ';
- $js='<script type="text/javascript">'.
- 'TZR.addValidator(["'.$varid.'",/.+:.+/,"'.addslashes($this->label).'","'.XIni::get('error_color').'","XLinkDef","'.$textid.'"]);</script>';
- }
- if (XShell::admini_mode() && !$qf && empty($this->filter) && empty($this->query) && !empty($this->sourcemodule) && $this->isAutorizedToAdd($options)){
- $urlnew = $GLOBALS['TZR_SESSION_MANAGER']::admin_url(true,true).'&moid='.$this->sourcemodule.'&function=insert&template=xmodtable/popinsert.html&tplentry=br&tabsmode=1&varid='.$varid;
- $newico = XLabels::getSysLabel('general','new');
- } else {
- $newico = $urlnew = '';
- }
- if(!$qf && $this->multivalued){
- if(is_array($value)) $v=array_keys($value);
- else $v=$value;
- $delico=XLabels::getSysLabel('general','delete');
- $callback=',TZR.autoCompleteMultipleValue';
- $edit.='<input id="'.$varid.'" autocomplete="off" name="foo" value="" type="hidden">';
- $edit.='<input autocomplete="off" id="'.$textid.'" name="_INPUT'.$fname.'" size="30" type="text" '.$fmt.' class="tzr-link '.$mborder.'">';
- if ($urlnew != ''){
- $edit .= '<a href="#" onclick="TZR.openPopup(\''.$urlnew.'\'); return false;">'.$newico.'</a>';
- }
- $edit.='<table id="table'.$varid.'"><tr style="display:none;"><td><a href="#" onclick="TZR.delLine(this);return false;">'.$delico.'</a><input type="hidden" name="'.$fname.'[]" value=""></td><td></td></tr>';
- $r->text='';
- if(!empty($v)){
- if(!is_array($v)) $v=array($v);
- foreach($v as $oid){
- $target=Kernel::getTable($oid);
- if(XSystem::tableExists($target)) {
- $t=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$target);
- $rs2=selectQuery('select * from '.$target.' where KOID="'.$oid.'"');
- $ors2=$rs2->fetch();
- if($ors2) {
- $myopts=array();
- if(!empty($options['_charset'])) $myopts['_charset']=$options['_charset'];
- $display=$this->format_display($myliste,$ors2,$myopts,NULL,'text');
- }
- }
- $display=trim($display);
- $r->text.=$display.' ';
- $edit.='<tr><td><a href="#" onclick="TZR.delLine(this);return false;">'.$delico.'</a><input type="hidden" name="'.$fname.'[]" value="'.$oid.'" '.
- '</td><td>'.$display.'</td></tr>';
- }
- $r->text=substr($r->text,0,-1);
- }
- $edit.='</table>';
- }else{
- $display='';
- if($v){
- $target=Kernel::getTable($v);
- if(XSystem::tableExists($target)) {
- $t=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$target);
- $rs2=selectQuery('select * from '.$target.' where KOID="'.$v.'"');
- $ors2=$rs2->fetch();
- if($ors2) {
- $myopts=array();
- if(!empty($options['_charset'])) $myopts['_charset']=$options['_charset'];
- $display=$this->format_display($myliste,$ors2,$myopts,NULL,'text');
- }
- }
- $display=trim($display);
- }
- $r->text=$display;
- $edit.='<input id="'.$varid.'" autocomplete="off" name="'.$fname.'" value="'.$v.'" type="hidden">';
- $edit.='<input autocomplete="off" id="'.$textid.'" name="_INPUT'.$fname.'" size="30" type="text" value="'.$display.'" '.$fmt.
- ' class="tzr-link '.$mborder.'">';
- if ($urlnew != ''){
- $edit .= '<a href="#" onclick="TZR.openPopup(\''.$urlnew.'\'); return false;">'.$newico.'</a>';
- }
- }
- $url=TZR_AJAX8.'?class=xlink2def&function=xlink2def_autocomplete&_silent=1';
- $edit.='<script type="text/javascript" language="javascript">TZR.addAutoComplete("'.$url.'","'.$varid.'","'.$options['fmoid'].'",'.
- '"'.$this->table.'","'.$this->field.'","'.$fieldslist.'"'.$callback.');</script>'.$js;
- $r->oidcollection=$oidcollection;
- $r->collection=$collection;
- $r->varid=$varid;
- $r->html=$edit;
- }
- /// retourne la liste des champs de la cible à utliser + le premier champ
- function &getFieldList(&$options,$addpublished=true){
- $maxmi=$this->getNbPublishedFields();
- $order='FORDER';
- $sup='';
- $idx='';
- if(strpos($this->display_format,'%_')!==false){
- preg_match_all('/%_([a-z0-9_]+)/i',$this->d…
Large files files are truncated, but you can click here to view the full file