/class.xfielddef.inc
PHP | 1133 lines | 1028 code | 47 blank | 58 comment | 243 complexity | 1f8db97a9ff47e1eefb20d4e1db56e8a MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
- <?php
- // nom de la classe, type de la donnee, fcount personnalisable, utilise le target, absent de toutes listes, absent en mode simplifié
- $_FTYPE['XChronoDef'] = array('XChronoDef', 'Data', false,false,false,true);
- $_FTYPE['XBoolDef'] = array('XBoolDef', 'Oid', false,false,false,false);
- $_FTYPE['XColorDef'] = array('XColorDef', 'Data', false,false,false,false);
- $_FTYPE['XDateDef'] = array('XDateDef', 'Data', false,false,false,false);
- $_FTYPE['XTimeDef'] = array('XTimeDef', 'Data', false,false,false,true);
- $_FTYPE['XUrlDef'] = array('XUrlDef', 'Data', false,false,false,false);
- $_FTYPE['XLinkDef'] = array('XLinkDef', 'Oid', false,true,false,true);
- $_FTYPE['XThesaurusDef'] = array('XThesaurusDef', 'Oid', false,true,false,true);
- $_FTYPE['XPasswdDef'] = array('XPasswdDef', 'Data', true,false,false,true);
- $_FTYPE['XStringSetDef']= array('XStringSetDef', 'Oid', false,false,false,false);
- $_FTYPE['XFileDef'] = array('XFileDef', 'Data', false,false,false,false);
- $_FTYPE['XFolderDef'] = array('XFolderDef', 'Data', false,false,false,true);
- $_FTYPE['XDocumentDef'] = array('XDocumentDef', 'Oid', false,false,false,true);
- $_FTYPE['XExtImageDef'] = array('XExtImageDef', 'Data', false,false,false,true);
- $_FTYPE['XImageDef'] = array('XImageDef', 'Data', false,false,false,false);
- $_FTYPE['XDateTimeDef'] = array('XDateTimeDef', 'Data', false,false,false,true);
- $_FTYPE['XTimestampDef'] = array('XTimestampDef', 'Data', false,false,false,true);
- $_FTYPE['XOrderDef'] = array('XOrderDef', 'Data', false,false,false,false);
- $_FTYPE['XRealDef'] = array('XRealDef', 'Data', true,true,false,false);
- $_FTYPE['XTextDef'] = array('XTextDef', 'Data', true,false,false,false);
- $_FTYPE['XExprDef'] = array('XExprDef', 'Data', true,false,false,false);
- $_FTYPE['XShortTextDef'] = array('XShortTextDef', 'Data', true,false,false,false);
- $_FTYPE['XRichTextDef'] = array('XRichTextDef', 'Data', true,false,false,false);
- $_FTYPE['XBaseDef'] = array('XBaseDef', 'Data', true,false,false,true);
- $_FTYPE['XTableDef'] = array('XTableDef', 'Data', true,false,false,true);
- $_FTYPE['XQueryDef'] = array('XQueryDef', 'Data', false,false,false,true);
- $_FTYPE['XModuleDef'] = array('XModuleDef', 'Oid', false,false,false,true);
- $_FTYPE['XGeodesicCoordinatesDef'] = array('XGeodesicCoordinatesDef', 'Data', false,false,false,false);
- $_FTYPE['XTableFieldDef'] = array('XTableFieldDef', 'Oid', false,true,false,true);
- $_FTYPE['XEvalDef'] = array('XEvalDef', 'Data', false, false, false, true);
- $_FTYPE['XOptionsDef'] = array('XOptionsDef', 'Data', false, false, false, true);
- $_FTYPE['XLink2Def'] = array('XLink2Def', 'Oid', false,true,false,true);
- $_FTYPE['XGmapPointDef'] = array('XGmapPointDef', 'Data', false, false, false, false);
- class XFieldVal {
- public $raw=NULL;
- public $field=NULL;
- public $table=NULL;
- public $html='';
- public $filename=NULL;
- public $fielddef=NULL;
- public $trace=NULL;
- public $title=NULL;
- public $html_default=NULL;
- public $_cache=array();
- function __construct() {
- $this->raw='';
- }
- /// Appel une fonction du xfielddef
- public function __call($f,$param){
- array_unshift($param, $this);
- return call_user_func_array(array($this->fielddef,$f),$param);
- }
- /// Retourne une propriété encore non definie
- public function __get($name){
- if($name=='text') return $this->fielddef->toText($this);
- return false;
- }
- }
- class XFieldQuery {
- public $op=NULL;
- public $value=NULL;
- public $fmt=NULL;
- public $hid=NULL;
- public $par=NULL;
- public $quote="'";
- function __construct() {
- }
- /// Appel une fonction du xfielddef
- public function __call($f,$param){
- array_unshift($param, $this);
- return call_user_func_array(array($this->fielddef,$f),$param);
- }
- }
- $_MIMES=array('application/pdf'=>array('application/pdf','xpdf', 'pdftotext <src> <dst>'));
- /// Classe mere de toutes les classes gerant des champs
- /**
- Cette classe decrit l'interface de toutes les classes de
- manipulation des donnees atomiques. Elle inclut l'affichage,
- l'edition, la mise a jour d'un champ. Chaque type de donnees est
- manipule par une classe specifiques.
- */
- abstract class XFieldDef {
- const QUERY_FORMAT='query';
- const QUICKQUERY_FORMAT='quick';
- public $exif_source='';
- public $_options=NULL;
- public $readonly=false;
- public $aliasmodule=NULL;
- public $query_format='classic';
- public $default='';
- public $indexable = false;
- public $onlyqueryable=false;
- public $advanceeditbatch=false;
- public $edit_format=NULL;
- public $label=NULL;
- public $align = 'left';
- public static function objectFactory($obj) {
- if(!isset($obj->DPARAM)) $obj->DPARAM=NULL;
- $ftype = $obj->FTYPE;
- $classname = XFieldDef::_getClass($ftype);
- if(class_exists($classname)) $c1=new $classname($obj);
- else XLogs::critical("XFielddef::objectFactory ",$classname." unknown");
- return $c1;
- }
- public static function objectFactory2($table, $field) {
- $rs=selectQuery("select * from DICT,MSGS where DTAB = '".$table."' and MTAB=DTAB ".
- " and (MLANG='$lang' or MLANG='".TZR_DEFAULT_LANG.
- "') and DICT.FIELD=MSGS.FIELD and DICT.FIELD='$field' order by FORDER");
- if ($o = $rs->fetch(PDO::FETCH_OBJ)) {
- $field = XFieldDef::objectFactory($o);
- }
- return $field;
- }
- /// creation d'un champ en memoire a partir de son type, son nom et sa taille
- public static function objectFactory3($type, $name, $count) {
- $t['FTYPE']=$type;
- $t['FCOUNT']=$count;
- $r['FIELD']=$name;
- return XFieldDef::objectFactory($obj);
- }
- public function trace($old, $r, $msg='') {
- if(!empty($msg)) {
- $r->trace[$this->field]=$msg;
- } elseif(is_object($r) && is_object($old)){
- $newv=$r->raw;
- if($newv!=$old->raw) $r->trace[$this->field]='['.$old->raw.'] -> ['.$newv.']';
- }
- }
- public function chk($message) {
- }
- public static function typeExists($t) {
- return is_subclass_of($t,'XFieldDef');
- }
- public static function getGender($t) {
- if(!class_exists($t)) return false;
- return $GLOBALS['_FTYPE'][$t][1];
- }
- public static function getUseTarget($t) {
- if(!class_exists($t)) return false;
- return $GLOBALS['_FTYPE'][$t][3];
- }
- public static function getFCount($t) {
- if(!class_exists($t)) return false;
- return $GLOBALS['_FTYPE'][$t][2];
- }
- public static function _getClass($t) {
- if(!class_exists($t)) return false;
- return $GLOBALS['_FTYPE'][$t][0];
- }
- public static function getTypes() {
- global $_FTYPE;
- $ty=array();
- $la=array();
- foreach($_FTYPE as $t => $label) {
- if(empty($label[4])) {
- $ty[]=$t;
- $la[]=XLabels::getSysLabel('xfielddef',$t);
- }
- }
- array_multisort($la, $ty);
- return array($ty, $la);
- }
-
- /**
- * Renvoie les types de champs "lien vers un objet"
- * @return Array Liste des types de champs "lien vers un objet"
- */
- public static function getObjectLinkTypes() {
- global $_FTYPE;
- $link_types = array();
- foreach($_FTYPE as $type => $params) {
- if (self::isObjectLink($type)) {
- $link_types[] = $type;
- }
- }
- return $link_types;
- }
- /**
- * Teste si le type du champ correspond à un "lien vers un objet"
- * @param string $type Type de champ à renseigner dans un contexte static
- * @return boolean Vrai si le type correspond à un "lien vers un objet"
- */
- function isObjectLink($type = null) {
- if (empty($type) && isset($this)) $type = $this->ftype;
- return self::getGender($type) == 'Oid' && self::getUseTarget($type);
- }
- function __construct($obj=NULL) {
- if(empty($obj)) {
- $obj=(object)array('FIELD'=>'anonymous','FTYPE'=>get_class($this),
- 'COMPULSORY'=>0,'TRANSLATABLE'=>0, 'FCOUNT'=>20, 'FORDER'=>0, 'QUERYABLE'=>1, 'MULTIVALUED'=>0,
- 'BROWSABLE'=>1, 'DTAB'=>'%', 'PUBLISHED'=>1, 'TARGET'=>'%', 'DPARAM'=>NULL);
- }
- bugWarning('XFieldDef::__construct: bad parameter', !empty($obj), true);
- $field = @$obj->FIELD;
- $ftype = @$obj->FTYPE;
- $table = @$obj->DTAB;
- $this->_options = new XOptions();
- $this->ftype = $ftype;
- $this->field = $field;
- $this->table = $table;
- $this->sys = $this->_sysField();
- $this->fcount = @$obj->FCOUNT;
- $this->forder = @$obj->FORDER;
- $this->compulsory = @$obj->COMPULSORY;
- $this->queryable = @$obj->QUERYABLE;
- $this->browsable = @$obj->BROWSABLE;
- $this->translatable = @$obj->TRANSLATABLE;
- $this->multivalued = @$obj->MULTIVALUED;
- $this->published = @$obj->PUBLISHED;
- $this->target = @$obj->TARGET;
- $this->initOptions();
- $this->setOptions(@$obj->DPARAM);
- $this->readonly = $this->readonly||$this->_sysRO();
- if(!empty($obj->MTXT)) $this->label = $obj->MTXT;
- elseif(!empty($obj->LABEL)) $this->label = $obj->LABEL;
- else $this->label=$field;
- if(!empty($this->aliasmodule)) {
- if(!XAlias::registered($this->aliasmodule)) {
- XAlias::register($this->aliasmodule);
- }
- }
- }
- /// creation d'une valeur prete a etre retournee
- function _newXFieldVal(&$option, $genid=false) {
- $r= new XFieldVal();
- $r->field=$this->field;
- $r->table=$this->table;
- $r->sys=$this->sys;
- $r->readonly=$this->readonly;
- $r->fielddef=$this;
- $r->filename=NULL;
- $r->catalog=NULL;
- if($genid) $r->varid=getUniqID('v'.$r->field);
- return $r;
- }
- /// creation d'une valeur prete a etre retournee pour la recherche
- function _newXFieldQuery($option=NULL, $genid=false) {
- $r=new XFieldQuery();
- $r->field=$this->field;
- $r->table=$this->table;
- $r->sys=$this->sys;
- $r->readonly=$this->readonly;
- $r->fielddef=$this;
- if($genid) $r->varid=getUniqID('q'.$r->field);
- return $r;
- }
- protected function initOptions() {
- $helpgroup=XLabels::getSysLabel('general','help','text');
- $querygroup=XLabels::getSysLabel('general','query','text');
- $this->_options->setId($this->table.':'.$this->field);
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef.readonly'), 'readonly', 'boolean');
- $this->_options->setOpt(XLabels::getSysLabel('general','comment','text'), 'comment', 'ttext', array('rows'=>2, 'cols'=>60),NULL, $helpgroup);
- $this->_options->setOpt(XLabels::getSysLabel('general','comment','text').' Backoffice', 'acomment', 'ttext', array('rows'=>2, 'cols'=>60), NULL,
- $helpgroup);
- $this->_options->setOpt(XLabels::getSysLabel('general','group'), 'fgroup', 'ttext');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','default'),'default','text');
- $this->_options->setOpt(XLabels::getSysLabel('xdatasource','aliasmodule'),'aliasmodule','module',array('toid'=>4,'emptyok'=>true));
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef.meta_source'),'exif_source','text',array('rows'=>3,'cols'=>40));
- if(!empty($this->query_formats)){
- $class=strtolower(get_class($this));
- $labels=array();
- foreach($this->query_formats as $qf){
- $tt='qf-'.$class.'-'.$qf;
- $label=XLabels::getSysLabel('xfielddef',$tt);
- if($tt==$label) $label=XLabels::getSysLabel('xfielddef','qf-'.$qf);
- $labels[]=$label;
- }
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','query_formats'), 'query_format', 'list',
- array('values'=>$this->query_formats,'labels'=>$labels),NULL,$querygroup);
- }
- $this->_options->setOpt('Dependance', 'dependency', 'dependency');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef.indexable'), 'indexable', 'boolean', NULL, false,$querygroup);
- }
- function get_sqlValue($value) {
- // Fabrique une valeur de colonne pour SQL a partir d'une valeur issue de PHP
- return $value; // Dans la majorite des cas.
- }
- public function hasExternals() { return false; }
- public function externals() { return NULL; }
- public function set_target($t) { $this->target=$t;}
- public function get_target() { return $this->target;}
- public function set_readonly($t) { $this->readonly=$t;}
- public function use_fcount() { return $GLOBALS['_FTYPE'][$this->ftype][2];}
- public function get_readonly() { return $this->readonly;}
- public function get_fcount() { return $this->fcount;}
- public function set_fcount($p) { $this->fcount=$p;}
- public function get_ftype() { return $this->ftype; }
- public function set_ftype($p) { $this->ftype=$p; }
- public function set_forder($p) { $this->forder=$p;}
- public function get_forder() { return $this->forder;}
- public function get_use_target() { return $GLOBALS['_FTYPE'][$this->ftype][3];}
- public function get_fgender() { return $GLOBALS['_FTYPE'][$this->ftype][1]; }
- public function get_field() { return $this->field; }
- public function set_field($p) { $this->field=$p; }
- public function get_compulsory() { return $this->compulsory; }
- public function set_compulsory($p) { $this->compulsory=$p; }
- public function get_queryable() { return $this->queryable; }
- public function set_queryable($p) { $this->queryable=$p; }
- public function get_browsable() { return $this->browsable; }
- public function set_browsable($p) { $this->browsable=$p; }
- public function get_translatable() { return $this->translatable; }
- public function set_translatable($p) { $this->translatable=$p; }
- public function get_multivalued() { return $this->multivalued; }
- public function set_multivalued($p) { $this->multivalued=$p; }
- public function get_published() { return $this->published; }
- public function set_published($p) { $this->published=$p; }
- private function _sysField() { return in_array($this->field, array('UPD','PUBLISH','PRIV','OWN','PRP','CREAD')); }
- private function _sysRO() { return in_array($this->field, array('UPD','OWN','CREAD')); }
- public function sysField() { return $this->sys; }
- public function get_options() { return $this->_options->getView();}
- public function is_summable() { return false; }
- function getOptions($block='opt') {
- return $this->_options->getDialog($this, array(),$block);
- }
- function serializeOptions() {
- return $this->_options->serialize($this);
- }
- function setOptions($dparam) {
- if(empty($dparam)) $dparam=array();
- if(is_array($dparam)) $this->_options->setValues($this, $dparam);
- elseif(substr($dparam, 0, 2)=='a:') $this->_options->setValues($this, unserialize($dparam));
- elseif(substr($dparam, 0, 5)=='<?xml') $this->_options->fromXML($this,$dparam);
- else $this->_options->setValues($this);
- }
- public function cacheable() { return true; }
- function get_label() {
- return $this->label;
- }
- /// rend les libelles d'un champ dans toutes les langies
- function get_labels() {
- if(isset($this->labels)) return $this->labels;
- $rs=selectQuery("select MSGS.* from MSGS where MTAB='".$this->table."' and FIELD='".$this->field."'");
- $r=array();
- $ors=array();
- while($ors=$rs->fetch()) {
- $r[$ors['MLANG']]=$ors['MTXT'];
- }
- $rs->closeCursor();
- $this->labels = $r;
- return $r;
- }
- /// rend la valeur d'une option, avec toutes les lkangues s'il s'agit d'un libelle
- function get_option($o) {
- $txts=XLabels::getAMsg($this->_options->id.':'.$o,NULL,false);
- return $txts;
- }
- function set_label($v) { die('XFieldDef::get_labels'); }
- function set_labels($vs) {
- unset($this->labels);
- while ( list($codeLang,$v) = each($vs) ) {
- if ( $v != '' ) $this->labels[$codeLang] = $v;
- }
- $lg = XShell::getLangUser();
- $this->label=$this->labels[$lg];
- }
- // renvoie un label html - usage formulaire FO
- // ajoute la classe "tzr-label-compulsory"
- // et le marqueur $compulsory_mark aux champs obligatoires
- function get_htmllabel($compulsory_mark = '*') {
- if ($this->compulsory)
- $label = '<label for="'.$this->field.'" class="tzr-label-compulsory">'.$this->label.' '.$compulsory_mark.'</label>';
- else
- $label = '<label for="'.$this->field.'">'.$this->label.'</label>';
- if ($this->comment)
- $label .= '<div class="cv8d-comment" >'.$this->comment.'</div>';
- return $label;
- }
- function get_browse_query($value) {
- if($this->multivalued) {
- $globdisp='';
- $machaine = $value;
- $val = explode('||',trim($machaine));
- $count = count($val);
- $cond = '';
- for($i=0;$i<$count; $i++) {
- if($val[$i]!='') {
- if($cond!='') $cond=$cond.' or ';
- $cond = $cond." KOID='$val[$i]' ";
- }
- }
- $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->target);
- $query=$xst->select_query(array()).' and ('.$cond.')';
- return $query;
- }
- }
- function raw_oids($value,$options=NULL) {
- $r=array();
- if($this->multivalued) {
- $globdisp='';
- $machaine = $value;
- $val = explode('||',trim($machaine));
- $count = count($val);
- for($i=0;$i<$count; $i++) {
- if($val[$i]!='') {
- $r[] = $val[$i];
- }
- }
- } else {
- $pos = strstr($value[0],'||');
- if($pos!='') {
- $val = explode('||',trim($value[0]));
- $count = count($val);
- for($i=0;$i<$count; $i++) {
- if($val[$i]!='') {
- $r[] = $val[$i];
- }
- }
- } else {
- $r[]=$value;
- }
- }
- return $r;
- }
- function export($value,$options=NULL) {
- $format=$options['format'];
- if(!isset($format)) $format='xml';
- $func='export_'.$format;
- return $this->$func($value,$options);
- }
- function export_xml($value,$options) {
- $labels=$options['labels'];
- $txt='';
- $lang = $GLOBALS['LANG_DATA'];
- foreach($value as $k => $v) {
- if(($v!='')) {
- $val = $this->my_export(array($v),$options);
- $l=htmlspecialchars($this->label);
- $l=str_replace(' ','_',$l);
- $txt.="<$l>$val</$l>\n";
- }
- }
- return $txt;
- }
- function &multi_oid_display($value, $options=NULL) {
- $r = $this->_newXFieldVal($options);
- $r->raw=$value;
- $machaine = $value;
- $val = explode('||',trim($machaine));
- $count = count($val);
- if($count>0) {
- $r->collection = array();
- $r->oidcollection=array();
- }
- for($i=0;$i<$count; $i++) {
- if(($val[$i]!='') && ($val[$i]!='Foo')) {
- $value = $val[$i];
- $o=$this->my_display($value, $options);
- if(is_object($o) && !empty($o->raw)) {
- $r->collection[] = $o;
- $r->oidcollection[] = $val[$i];
- if(($r->html!='') && (strlen($o->html)>0)) $r->html.='<br/>'.$o->html;
- else $r->html.=$o->html;
- }
- }
- }
- $r->text=strip_tags(str_replace(array('<br>','<br/>'),', ',$r->html));
- $o1=$r;
- return $o1;
- }
- function &multi_data_display(&$value,&$options) {
- $r = $this->_newXFieldVal($options);
- $separator=$this->separator;
- $r->raw=$value;
- $val = preg_split('@['.$separator.']@',trim($r->raw));
- for($i=0; $i<count($val); $i++) {
- if($val[$i]!='') {
- $value = trim($val[$i]);
- $o=&$this->my_display($value, $options);
- if(is_object($o) && isset($o->raw)) {
- $r->collection[] = $o;
- if(($r->html!='')&&(strlen($o->html)>0)) $r->html .= $this->separator[0].' '.$o->html;
- else $r->html .= $o->html;
- }
- }
- }
- return $r;
- }
- function display(&$value,&$options) {
- if(!empty($options['value'])) $value=$options['value'];
- if($this->multivalued && ($this->get_fgender()=='Oid')) {
- $o = & $this->multi_oid_display($value,$options);
- } elseif($this->multivalued) {
- $o = & $this->multi_data_display($value,$options);
- } else {
- $o= & $this->my_display($value, $options);
- }
- if(@$options['_format']=='xhtml') {
- $o->xhtml = '<'.$this->field.'>'.$o->html.'</'.$this->field.'>';
- }
- return $o;
- }
- function browse(&$value,&$options) {
- $r = $this->_newXFieldVal($options);
- if($this->multivalued && ($this->get_fgender()=='Oid')) {
- $r->raw=$value;
- $machaine = $value;
- $val = explode('||',trim($machaine));
- $count = count($val);
- if($count>0) {
- $r->collection = array();
- $r->oidcollection=array();
- }
- for($i=0;$i<$count; $i++) {
- if($val[$i]!='') {
- $value1 = $val[$i];
- $o=$this->my_browse($value1, $options);
- if(is_object($o) && isset($o->raw)) {
- $r->collection[] = $o;
- $r->oidcollection[] = $value1;
- if(!empty($r->html)&&!empty($o->html)) $r->html .= '<br/>'.$o->html;
- else $r->html .= $o->html;
- }
- }
- }
- $r->text=strip_tags(str_replace('<br/>',', ',$r->html));
- $o=$r;
- } elseif($this->multivalued) {
- $separator=$this->separator;
- $r->raw=$value;
- $val = preg_split('@['.$separator.']@',trim($r->raw));
- $count = count($val);
- if($count>0) {
- for($i=0;$i<$count; $i++) {
- if($val[$i]!='') {
- $value1 = trim($val[$i]);
- $o=&$this->my_browse($value1, $options);
- if(is_object($o) && isset($o->raw)) {
- $r->collection[] = $o;
- if(($r->html!='')&&(strlen($o->html)>0)) $r->html .= $separator[0].' '.$o->html;
- else $r->html .= $o->html;
- }
- }
- }
- }
- $o=& $r;
- } else {
- $o= & $this->my_browse($value, $options);
- }
- return $o;
- }
- function &edit(&$value,&$options=array(),$fields_complement=null) {
- $lang_user = XShell::getLangUser();
- if(!empty($options['value'])) $value=$options['value'];
- if((!XShell::isRoot() && ($this->readonly || @$options['readonly'])) || @$options['readonly']==2) {
- $r=$this->display($value,$options);
- return $r;
- }
- if($this->multivalued && ($this->get_fgender()=='Oid')) {
- $val = explode('||',trim($value));
- $count = count($val);
- $value=array();
- for($i=0;$i<$count;$i++) {
- if($val[$i]!='') {
- $value[$val[$i]]=1;
- }
- }
- } elseif (strpos($value,'||')!==false && ($this->get_fgender()=='Oid') ) {
- $val = explode('||',trim($value));
- $count = count($val);
- unset($value);
- $stop=0;
- for($i=0;($i<$count) && ($stop!=1); $i++) {
- if(trim($val[$i])!='') {
- $value=$val[$i];
- $stop=1;
- }
- }
- }
- $r=$this->my_edit($value,$options,$fields_complement);
- if(empty($r->varid)) $r->varid=getUniqID('v'.$r->field);
- if($this->multivalued && $this->advanceeditbatch && !empty($options['editbatch'])){
- $id=getUniqID('v'.$r->field);
- $r->html= '<input id="'.$id.'-1" class="radio" type="radio" name="'.$this->field.'_op" value="+" checked>'.
- '<label class="tzr-st-label" for="'.$id.'-1">'.XLabels::getSysLabel('xfielddef','editbatch_add').'</label> '.
- '<input id="'.$id.'-2" class="radio" type="radio" name="'.$this->field.'_op" value="=">'.
- '<label class="tzr-st-label" for="'.$id.'-2">'.XLabels::getSysLabel('xfielddef','editbatch_replace').'</label> '.
- '<input id="'.$id.'-3" class="radio" type="radio" name="'.$this->field.'_op" value="-">'.
- '<label class="tzr-st-label" for="'.$id.'-3">'.XLabels::getSysLabel('xfielddef','editbatch_remove').'</label><br>'.
- $r->html;
- }
- if(!empty($this->dependency['f'])){
- $r->html.='<script type="text/javascript">';
- foreach($this->dependency['dval'] as $i=>$foo){
- $r->html.='TZR.addDependency("'.$this->ftype.'","'.$this->dependency['f'].'","'.$this->field.'","'.$this->dependency['dval'][$i].
- '","'.$this->dependency['val'][$i].'","'.$this->dependency['op'][$i].'","'.$this->dependency['style'][$i].'",'.
- '"'.$this->dependency['nochange'][$i].'");'."\n";
- }
- $r->html.='</script>';
- }
- $r->edit=true;
- if($this->compulsory) $this->indicator=' *';
- else $this->indicator='';
- return $r;
- }
- /// Recupere la liste des valeurs presente dans une table pour un filtre donné
- public function _getUsedValues($filter=NULL,$select=NULL,$options=array(),$cache=true) {
- $this->_getUsedValuesParams($filter,$select,$options,$cachename);
- if($cache) $values=&XDbIni::get($cachename,'val');
- else $values=NULL;
- if(!$values || $values['f']!=$filter || $values['s']!=$select){
- $rs=&cacheSelectQuery($select);
- $values=array();
- $separator=!empty($this->separator)?$this->separator:'||';
- while($rs && $ors=$rs->fetch()) {
- if($this->multivalued){
- $tmpvalues=explode($separator,$ors[$this->field]);
- foreach($tmpvalues as $i=>$value) {
- if(!empty($value) && empty($values[$value])) $values[$value]=true;
- }
- }else{
- if(!empty($ors[$this->field]) && empty($values[$ors[$this->field]])) $values[$ors[$this->field]]=true;
- }
- }
- if ($rs) $rs->closeCursor();
- $values=array('f'=>$filter,'s'=>$select,'v'=>$values);
- if($cache) XDbIni::set($cachename,$values);
- }
- return $values['v'];
- }
- /// Met on forme les parametres utilisés pour récupérer les valeurs utilisées
- public function _getUsedValuesParams(&$filter,&$select,&$options,&$cachename) {
- $lang_data = TZR_DEFAULT_LANG;
- if (!empty($this->table)) {
- $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->table);
- if (is_object($xst) && $xst->isTranslatable()) {
- $lang_data = XShell::getLangData();
- }
- }
- // on ne prend pas les valeurs vides d'autant plus quelles sont supprimees ensuite
- $filter = (empty($filter) ? '' : "($filter) AND ") . '('.$this->field.' != \'\')';
- if(!empty($this->table) && !$select){
- $where=$filter;
- if(!empty($options['fmoid'])){
- $mod=XModule::objectFactory($options['fmoid']);
- $modfilter=$mod->getUsedValuesFilter();
- if($modfilter) $where.=' AND '.$mod->getUsedValuesFilter();
- }
- $where.=' AND LANG="'.$lang_data.'"';
- $select='SELECT DISTINCT '.$this->field.' FROM '.$this->table.' WHERE '.$where;
- if(!empty($options['order'])) $select.=' ORDER BY '.$options['order'];
- if(!empty($options['limit'])) $select.=' LIMIT '.$options['limit'];
- }
- $code=md5($filter.'-'.$select);
- if($this->target==TZR_DEFAULT_TARGET)
- $cachename=$this->table.':usedValues:'.$this->field.':'.$lang.':'.$code;
- else
- $cachename=$this->table.'|'.$this->target.':usedValues:'.$this->field.':'.$lang.':'.$code;
-
- }
- function quickquery($value,$ar=NULL) {
- if(empty($ar['query_format'])) $ar['query_format']=XFieldDef::QUICKQUERY_FORMAT;
- return $this->my_quickquery($value,$ar);
- }
- function my_quickquery($value,$ar=NULL) {
- return $this->_newXFieldVal($ar);
- }
- function query($value,$ar=NULL) {
- if(is_array($value) && !in_array('Foo',$value) && $this->get_fgender()=='Oid') {
- foreach($value as $i => $val1) {
- if(!empty($val1)) {
- $va[$val1]=1;
- }
- }
- $value=$va;
- } elseif(!is_array($value)) {
- if($this->multivalued || @$ar['query_format']) {
- if($value!='Foo') {
- $val = explode('||',trim($value));
- unset($value);
- $value=array();
- foreach($val as $i => $val1) {
- if(!empty($val1)) {
- $value[$val1]=1;
- }
- }
- }
- } elseif (strstr($value,'||')!='') {
- $val = explode('||',trim($value));
- $count = count($val);
- unset($value);
- $stop=0;
- for($i=0;($i<$count) && ($stop!=1); $i++) {
- if(trim($val[$i])!='') {
- $value=$val[$i];
- $stop=1;
- }
- }
- }
- }
- if(empty($ar['query_format'])) $ar['query_format']=XFieldDef::QUERY_FORMAT;
- $r=$this->my_query($value,$ar);
- return $r;
- }
- /// Equivalent de query, mais prepare en plus les options sur le format de champs de recherche
- function pquery($value,$ar=NULL) {
- $qfmt=$ar['qfmt'];
- if($ar['notapplyqfmt']) unset($ar['qfmt']);
- $r=$this->query($value,$ar);
- if(empty($this->query_formats)) return $r;
- $fname=(isset($ar['fieldname'])?$ar['fieldname']:$this->field);
- $formats='<select name="options['.$fname.'][qfmt]">';
- $class=strtolower(get_class($this));
- foreach($this->query_formats as $qf){
- $label=XLabels::getSysLabel('xfielddef','qf-'.$class.'-'.$qf);
- if(empty($label)) $label=XLabels::getSysLabel('xfielddef','qf-'.$qf);
- $formats.='<option value="'.$qf.'"'.($qf==$qfmt?'selected':'').'>'.$label.'</option>';
- }
- $formats.='</select>';
- $r->query_formats=$formats;
- return $r;
- }
- // action a effectuer apres edition et avant stockage des donnees
- // on rend un tableau de valeur traitees
- function post_edit($value,$options=NULL,&$fields_complement=NULL) {
- $r=$this->_newXFieldVal($options);
- $langdata=XShell::getLangData();
- $hidden=$options[$this->field.'_HID'];
- $r->raw=$value;
- $this->trace(@$options['old'],$r);
- return $r;
- }
- // action effectuée apres une soumission de recherche
- // on rend un tableau de valeur traitees
- function post_query(&$o,$ar) {
- $v1=$o->value;
- $v1op=$o->op;
- $k=$this->field;
- $k1=$this->table.'.'.$this->field;
- $quotes=$o->quote;
- $o->rq='';
- // cas d'une formule
- if(!empty($v1) && is_string($v1) && ($v1[0]=='=')) {
- $quotes='';
- $v1=substr($v1,1);
- }
- // cas d'un oid sans le prefixe table
- if (!is_array($v1) && !empty($v1) && !Kernel::isAKoid($v1) && $this->isObjectLink()) {
- $v1=$this->target.':'.$v1;
- }
- // cas ou la valeur est un tableau et que le champ est multivalue
- if($this->get_multivalued() && is_array($v1) && !empty($v1)) {
- if($v1op!='OR') $v1op='AND';
- $rq=array();
- foreach($v1 as $i=>$v){
- $o1=clone($o);
- $o1->rq='';
- $o1->value=$v;
- $this->post_query($o1,$ar);
- if(!empty($o1->rq)) $rq[]=$o1->rq;
- }
- if(empty($rq)) $o->rq=NULL;
- else $o->rq='('.implode($v1op,$rq).')';
- }
- // cas ou la valeur multiple est un tableau et le champ n'est pas multivalue
- elseif(!$this->get_multivalued() && is_array($v1) && !empty($v1)) {
- $count=count($v1);
- $rq='(';
- for($i=0;$i<$count;$i++) {
- $o1=clone($o);
- $o1->rq='';
- $o1->value=$v1[$i];
- $this->post_query($o1,$ar);
- //dans l cas d'un recherche ne contenant pas les valeur le separateur est un AND
- $sep = 'OR';
- if($o1->op == "!=") $sep = 'AND';
- if(!empty($o1->rq)) {
- if($rq=='(') $rq.=$o1->rq;
- else $rq.=' '.$sep.' '.$o1->rq;
- }
- }
- $rq.=')';
- if($rq=='()')
- $o->rq=NULL;
- else
- $o->rq=$rq;
- }
- // traitement de tous les cas possible
- elseif(is_string($v1) && $v1op=='$') {
- $v1=$GLOBALS['TZR_DB']->quote(".*$v1\$");
- $o->rq="($k1 rlike $v1)";
- }
- elseif(is_string($v1) && $v1op=='^') {
- $v1=$GLOBALS['TZR_DB']->quote("^$v1.*");
- $o->rq =" ($k1 rlike $v1)";
- }
- elseif($v1op=='is empty') {
- $o->rq = " (($k1 is NULL) or ($k1 ='')) ";
- }
- elseif(is_array($v1) && !empty($v1) && $this->get_multivalued() && ($this->get_fgender()=='Oid')) {
- // traitement du multivalue avec separateur ||
- $count = count($v1);
- for($j=0;$j<$count; $j++) {
- if(!empty($v1[$j])) {
- $o->rq=" (($k1 = '".$v1[$j]."') OR INSTR(".$k1.", '||".$v1[$j]."||') or (".
- $k1."='".$v1[$j]."'))";
- if(($j!=0) && ($j!=($count-1))) $o->rq.='AND';
- }
- }
- if(!empty($o->rq)) $o->rq='('.$o->rq.')';
- }
- elseif(!empty($v1) && ($this->get_fgender()=='Oid') && (strstr($v1,'||')!=false)) {
- // traitement du multivalue avec separateur ||
- $v1=explode('||',$v1);
- $count = count($v1);
- for($j=0;$j<$count; $j++) {
- if(!empty($v1[$j])) {
- $o->rq=" (($k1 = '".$v1[$j]."') OR INSTR(".$k1.",'||".$v1[$j]."||'))";
- if(($j!=0) && ($j!=($count-1))) $o->rq.='AND';
- }
- }
- if(!empty($o->rq)) $o->rq='('.$o->rq.')';
- }
- elseif(is_array($v1) && ($this->get_fgender()=='Oid')) {
- // traitement du multivalue avec separateur ||
- $count = count($v1);
- for($j=0;$j<$count; $j++) {
- if(!empty($v1[$j])) {
- $o->rq.=' ('.$k1." like '".$v1[$j]."') ";
- if(($j!=0) && ($j!=($count-1))) $o->rq.='AND';
- }
- }
- if(!empty($o->rq)) $o->rq='('.$o->rq.')';
- }
- elseif(!empty($v1) && ($this->get_fgender()=='Oid')) {
- if($this->get_multivalued()) {
- $o->rq="( ($k1='$v1') OR instr(".$k1.", '||".$v1."||'))";
- } else
- $o->rq=' ('.$k1." = '".$v1."')";
- } elseif (!empty($v1) && !empty($v1op) && (is_string($v1) || is_numeric($v1))) {
- if(!empty($quotes)) $v1=$GLOBALS['TZR_DB']->quote($v1);
- $o->rq=' ('.$k1." $v1op $v1)";
- } elseif (!empty($v1) && !is_array($v1)) {
- if(empty($quotes)) {
- $o->rq=" (".$k1." like $v1)";
- } else {
- $v1=$GLOBALS['TZR_DB']->quote("%$v1%");
- $o->rq=' ('.$k1." like $v1) ";
- }
- }
- }
- // rend une expression pour requêtage
- //
- // action a effectuer apres edition et duplication d'une donnee
- function post_edit_dup($value,$options) {
- $p = new XParam($options,array());
- $oidsrc=$p->get('oidsrc');
- $options['oid']=$oidsrc;
- $r1= $this->post_edit($value,$options);
- return $r1->raw;
- }
- function sqltype() {
- return NULL;
- }
- function sqlfields() {
- return $this->field;
- }
- function sqlsumfunction() {
- return 'SUM('.$this->field.')';
- }
- function delfield() {
- return true;
- }
- function delete($value,$oid) {
- return 1;
- }
- function my_display(&$value,&$options) {
- return $this->_newXFieldVal($options);
- }
- /// Ecriture dans un fichier excel
- function writeXLS(&$xl,$i,$j,&$value,$format=0,&$ss) {
- if (is_object($value)){
- $v=$value->toText();
- if(empty($v)) $v=$value->raw;
- } else {
- $v = '';
- }
- convert_charset($v,TZR_INTERNAL_CHARSET,'UTF-8');
- $xl->setCellValueExplicit(PHPExcel_Cell::stringFromColumnIndex($j) . $i, $v);
- if(is_array($format)) $xl->getStyleByColumnAndRow($j,$i)->applyFromArray($format);
- }
- // Ecriture dans un csv
- function writeCSV(&$o,$textsep){
- if (is_object($o)){
- $value=str_replace(array($textsep,"\x0d"),array($textsep.$textsep,""),$o->toText());
- } else {
- $value = '';
- }
- $ret=$textsep.$value.$textsep;
- return $ret;
- }
- /// Import de données vers une table
- function import($value,$options=NULL) {
- $value=trim($value);
- $defaultvalue=(string)$options->default[0];
- // conversion eventuelle de format
- if(!empty($options->format) && !empty($value)) {
- $value=$this->convert($value,(string)$options->format['source'],(string)$options->format['destination']);
- }
- if(empty($value) && !empty($defaultvalue)) $value=$defaultvalue;
- $ret=$this->my_import($value,$options);
- return array('message'=>$ret['message'],'value'=>$ret['value']);
- }
- /// Sous fonction redefinie pour chaque type de champ pour l'import de données vers une table
- function my_import($value,&$options){
- $typefield=(string)$options['type'];
- return array('message'=>'','value'=>$value);
- }
- function my_browse(&$value, &$options) {
- return $this->my_display($value, $options);
- }
- function my_export($value) {
- return '';
- }
- function my_edit($value, $options=NULL){
- $r = $this->_newXFieldVal($options,true);
- $r->value = $value;
- return $r;
- }
- function my_query($value,$options=NULL){
- return $this->_newXFieldVal($options);
- }
- function filename($value) {
- return NULL;
- }
- function default_value() {
- return $this->default;
- }
- function search($value,$options=NULL) {
- $rq='';
- if(is_array($value)) {
- foreach($value as $i => $v) {
- if($rq!='') $rq .=' OR ';
- $rq .= $this->my_search($v,$options);
- }
- } else {
- $rq .= $this->my_search($value,$options);
- }
- return $rq;
- }
- function my_search($value,$options) {
- return $this->field.' like "%'.$value.'%" ';
- }
- function convert($value, $src, $dst) {
- return $value;
- }
- // generation d'une url complete et partielle pour la consultation d'un fichier
- //
- protected function getDownloader($short_filename, $mime='application/x-octet-stream',
- $originalname=NULL, $title=NULL, $moid=NULL) {
- if(empty($title)) $title=$originalname;
- $mimelabel=XLabels::getSysLabel('mime',$mime, 'both', 'mime', 'unknown/unknown');
- if(empty($mimelabel)) $mimelabel=XLabels::getSysLabel('mime','unknown/unknown');
- if(!empty($mimelabel)) $mimelabel.=' ';
- $originalname=removeaccents($originalname);
- $url=TZR_DOWNLOADER.'?filename='.$short_filename.'&mime='.$mime.
- '&originalname='.rawurlencode(preg_replace('/([^A-Za-z0-9\._-]+)/','_',$originalname)).(empty($moid)?'':'&moid='.$moid).($this->gzipped==1?'&gzip=1':'');
- $fullurl='<a bt-xpath="'.TZR_AJAX8.'?class=xfiledef&function=xfiledef_getfilesize&file='.$short_filename.'&_='.XShell::uniqid().'" class="tzr-hottip-c tzr-file" href="'.$url.'">'.$mimelabel.$title.'</a>';
- return array($url, $fullurl);
- }
- /// Convertit le contenu de la base de données suite à un changement de format du champ
- public function convertValues($oldftype){
- return;
- }
- /// Assigne les metas à partir de la valeur du champ
- function setMetaFromValue($metaanalyser,&$r,$filter=array('IPTC','XMP'),$prop='text'){
- $isok=array();
- $metas=explode("\n",$this->exif_source);
- foreach($metas as &$meta){
- $list=explode('.',$meta);
- if(count($list)<2) continue;
- if(count($list)<3) array_unshift($list,'IPTC');
- if($list[0]=='XMP' && in_array('XMP',$filter) && !in_array('XMP',$isok)){
- if($this->multivalued){
- $v=array();
- foreach($r->collection as $i=>&$c) $v[]=$c->$prop;
- $metaanalyser->setXMPProperty($list[2],$v,@$list[3]);
- }else{
- $metaanalyser->setXMPProperty($list[2],$r->$prop,@$list[3]);
- }
- $isok[]='XMP';
- }
- if($list[0]=='IPTC' && in_array('IPTC',$filter) && !in_array('IPTC',$isok)){
- $metaanalyser->setIPTCProperty($list[2],$r->$prop);
- $isok[]='IPTC';
- }
- }
- }
- /// Recupere la valeur d'un champ depuis les meta d'un champ fichier
- function getMetaValue(&$computed_fields,$filter=array('IPTC','EXIF','XMP'),$getall=false){
- $value='';
- $metas=explode("\n",$this->exif_source);
- foreach($metas as &$meta){
- $list=explode('.',$meta);
- if(count($list)<2) continue;
- if(count($list)<3) array_unshift($list,'IPTC');
- if(!is_object(@$computed_fields[$list[1]])) return;
- if(in_array('IPTC',$filter) && $list[0]=='IPTC'){
- $value=$computed_fields[$list[1]]->getIPTC($list[2]);
- if(!empty($value)) break;
- }elseif(in_array('EXIF',$filter) && $list[0]=='EXIF'){
- $value=$computed_fields[$list[1]]->getEXIF($list[2]);
- if(!empty($value)) break;
- }elseif(in_array('XMP',$filter) && $list[0]=='XMP'){
- $value=$computed_fields[$list[1]]->getXMP($list[2]);
- if(!$getall) $value=(is_object($value)?$value->text:NULL);
- if(!empty($value)) break;
- }
- }
- return $value;
- }
- /// Recupere le type du champ dans un webservice (name : type xml, descr : description du type pour l'ajour d'une type complexe)
- function getSoapType(){
- return array('name'=>'xsd:string');
- }
- /// Recupere la valeur formattée pour le service SOAP
- function getSoapValue($r){
- return $r->raw;
- }
- /// Retourne une chaine de caractere decrivant la recherche en cours sur le champ
- function getQueryText($o){
- if(is_array($o->value)){
- $vals=array();
- foreach($o->value as $v){
- $d=$this->my_display($v);
- $vals[]=$d->text;
- }
- if($o->op=='OR') $sep=' '.strtolower(XLabels::getSysLabel('general','or','text')).' ';
- else $sep=' '.strtolower(XLabels::getSysLabel('general','and','text')).' ';
- $ret.=implode($sep,$vals);
- }else{
- $d=$this->my_display($o->value);
- $ret=$this->getQueryTextOp($o->op,true);
- $ret.=$d->text;
- }
- return $ret;
- }
- function getQueryTextOp($op,$addscape=false){
- $ret='';
- if(!empty($op)){
- switch($op){
- case '>':
- $ret=XLabels::getSysLabel('xfielddef','more_than','text').' ';
- break;
- case '>=':
- $ret=XLabels::getSysLabel('xfielddef','upper_than','text').' ';
- break;
- case '<=':
- $ret=XLabels::getSysLabel('xfielddef','lower_than','text').' ';
- break;
- case '$':
- $ret=XLabels::getSysLabel('xfielddef','query_ending_with','text').' ';
- break;
- case '^':
- $ret=XLabels::getSysLabel('xfielddef','query_beginning_with','text').' ';
- break;
- case '!=':
- $ret=XLabels::getSysLabel('xfielddef','query_different','text').' ';
- break;
- case 'is empty':
- $ret=XLabels::getSysLabel('xfielddef','is_empty','text').' ';
- break;
- }
- }
- if($addscape && $ret) $ret.=' ';
- return $ret;
- }
- /// Recupere le texte d'une valeur
- public function &toText($r) {
- if(!property_exists($r, 'text') || $r->text===NULL) $r->text=getTextFromHTML($r->html);
- return $r->text;
- }
-
- /**
- * Function isEmpty
- * @return true si le champ n'est pas remplit
- */
- public function isEmpty($r){
- if(property_exists($r, 'raw')) return empty($r->raw);
- else return true;
- }
- }
- ?>