PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/class.xfielddef.inc

https://github.com/jcplat/console-seolan
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
  1. <?php
  2. // nom de la classe, type de la donnee, fcount personnalisable, utilise le target, absent de toutes listes, absent en mode simplifié
  3. $_FTYPE['XChronoDef'] = array('XChronoDef', 'Data', false,false,false,true);
  4. $_FTYPE['XBoolDef'] = array('XBoolDef', 'Oid', false,false,false,false);
  5. $_FTYPE['XColorDef'] = array('XColorDef', 'Data', false,false,false,false);
  6. $_FTYPE['XDateDef'] = array('XDateDef', 'Data', false,false,false,false);
  7. $_FTYPE['XTimeDef'] = array('XTimeDef', 'Data', false,false,false,true);
  8. $_FTYPE['XUrlDef'] = array('XUrlDef', 'Data', false,false,false,false);
  9. $_FTYPE['XLinkDef'] = array('XLinkDef', 'Oid', false,true,false,true);
  10. $_FTYPE['XThesaurusDef'] = array('XThesaurusDef', 'Oid', false,true,false,true);
  11. $_FTYPE['XPasswdDef'] = array('XPasswdDef', 'Data', true,false,false,true);
  12. $_FTYPE['XStringSetDef']= array('XStringSetDef', 'Oid', false,false,false,false);
  13. $_FTYPE['XFileDef'] = array('XFileDef', 'Data', false,false,false,false);
  14. $_FTYPE['XFolderDef'] = array('XFolderDef', 'Data', false,false,false,true);
  15. $_FTYPE['XDocumentDef'] = array('XDocumentDef', 'Oid', false,false,false,true);
  16. $_FTYPE['XExtImageDef'] = array('XExtImageDef', 'Data', false,false,false,true);
  17. $_FTYPE['XImageDef'] = array('XImageDef', 'Data', false,false,false,false);
  18. $_FTYPE['XDateTimeDef'] = array('XDateTimeDef', 'Data', false,false,false,true);
  19. $_FTYPE['XTimestampDef'] = array('XTimestampDef', 'Data', false,false,false,true);
  20. $_FTYPE['XOrderDef'] = array('XOrderDef', 'Data', false,false,false,false);
  21. $_FTYPE['XRealDef'] = array('XRealDef', 'Data', true,true,false,false);
  22. $_FTYPE['XTextDef'] = array('XTextDef', 'Data', true,false,false,false);
  23. $_FTYPE['XExprDef'] = array('XExprDef', 'Data', true,false,false,false);
  24. $_FTYPE['XShortTextDef'] = array('XShortTextDef', 'Data', true,false,false,false);
  25. $_FTYPE['XRichTextDef'] = array('XRichTextDef', 'Data', true,false,false,false);
  26. $_FTYPE['XBaseDef'] = array('XBaseDef', 'Data', true,false,false,true);
  27. $_FTYPE['XTableDef'] = array('XTableDef', 'Data', true,false,false,true);
  28. $_FTYPE['XQueryDef'] = array('XQueryDef', 'Data', false,false,false,true);
  29. $_FTYPE['XModuleDef'] = array('XModuleDef', 'Oid', false,false,false,true);
  30. $_FTYPE['XGeodesicCoordinatesDef'] = array('XGeodesicCoordinatesDef', 'Data', false,false,false,false);
  31. $_FTYPE['XTableFieldDef'] = array('XTableFieldDef', 'Oid', false,true,false,true);
  32. $_FTYPE['XEvalDef'] = array('XEvalDef', 'Data', false, false, false, true);
  33. $_FTYPE['XOptionsDef'] = array('XOptionsDef', 'Data', false, false, false, true);
  34. $_FTYPE['XLink2Def'] = array('XLink2Def', 'Oid', false,true,false,true);
  35. $_FTYPE['XGmapPointDef'] = array('XGmapPointDef', 'Data', false, false, false, false);
  36. class XFieldVal {
  37. public $raw=NULL;
  38. public $field=NULL;
  39. public $table=NULL;
  40. public $html='';
  41. public $filename=NULL;
  42. public $fielddef=NULL;
  43. public $trace=NULL;
  44. public $title=NULL;
  45. public $html_default=NULL;
  46. public $_cache=array();
  47. function __construct() {
  48. $this->raw='';
  49. }
  50. /// Appel une fonction du xfielddef
  51. public function __call($f,$param){
  52. array_unshift($param, $this);
  53. return call_user_func_array(array($this->fielddef,$f),$param);
  54. }
  55. /// Retourne une propriété encore non definie
  56. public function __get($name){
  57. if($name=='text') return $this->fielddef->toText($this);
  58. return false;
  59. }
  60. }
  61. class XFieldQuery {
  62. public $op=NULL;
  63. public $value=NULL;
  64. public $fmt=NULL;
  65. public $hid=NULL;
  66. public $par=NULL;
  67. public $quote="'";
  68. function __construct() {
  69. }
  70. /// Appel une fonction du xfielddef
  71. public function __call($f,$param){
  72. array_unshift($param, $this);
  73. return call_user_func_array(array($this->fielddef,$f),$param);
  74. }
  75. }
  76. $_MIMES=array('application/pdf'=>array('application/pdf','xpdf', 'pdftotext <src> <dst>'));
  77. /// Classe mere de toutes les classes gerant des champs
  78. /**
  79. Cette classe decrit l'interface de toutes les classes de
  80. manipulation des donnees atomiques. Elle inclut l'affichage,
  81. l'edition, la mise a jour d'un champ. Chaque type de donnees est
  82. manipule par une classe specifiques.
  83. */
  84. abstract class XFieldDef {
  85. const QUERY_FORMAT='query';
  86. const QUICKQUERY_FORMAT='quick';
  87. public $exif_source='';
  88. public $_options=NULL;
  89. public $readonly=false;
  90. public $aliasmodule=NULL;
  91. public $query_format='classic';
  92. public $default='';
  93. public $indexable = false;
  94. public $onlyqueryable=false;
  95. public $advanceeditbatch=false;
  96. public $edit_format=NULL;
  97. public $label=NULL;
  98. public $align = 'left';
  99. public static function objectFactory($obj) {
  100. if(!isset($obj->DPARAM)) $obj->DPARAM=NULL;
  101. $ftype = $obj->FTYPE;
  102. $classname = XFieldDef::_getClass($ftype);
  103. if(class_exists($classname)) $c1=new $classname($obj);
  104. else XLogs::critical("XFielddef::objectFactory ",$classname." unknown");
  105. return $c1;
  106. }
  107. public static function objectFactory2($table, $field) {
  108. $rs=selectQuery("select * from DICT,MSGS where DTAB = '".$table."' and MTAB=DTAB ".
  109. " and (MLANG='$lang' or MLANG='".TZR_DEFAULT_LANG.
  110. "') and DICT.FIELD=MSGS.FIELD and DICT.FIELD='$field' order by FORDER");
  111. if ($o = $rs->fetch(PDO::FETCH_OBJ)) {
  112. $field = XFieldDef::objectFactory($o);
  113. }
  114. return $field;
  115. }
  116. /// creation d'un champ en memoire a partir de son type, son nom et sa taille
  117. public static function objectFactory3($type, $name, $count) {
  118. $t['FTYPE']=$type;
  119. $t['FCOUNT']=$count;
  120. $r['FIELD']=$name;
  121. return XFieldDef::objectFactory($obj);
  122. }
  123. public function trace($old, $r, $msg='') {
  124. if(!empty($msg)) {
  125. $r->trace[$this->field]=$msg;
  126. } elseif(is_object($r) && is_object($old)){
  127. $newv=$r->raw;
  128. if($newv!=$old->raw) $r->trace[$this->field]='['.$old->raw.'] -> ['.$newv.']';
  129. }
  130. }
  131. public function chk($message) {
  132. }
  133. public static function typeExists($t) {
  134. return is_subclass_of($t,'XFieldDef');
  135. }
  136. public static function getGender($t) {
  137. if(!class_exists($t)) return false;
  138. return $GLOBALS['_FTYPE'][$t][1];
  139. }
  140. public static function getUseTarget($t) {
  141. if(!class_exists($t)) return false;
  142. return $GLOBALS['_FTYPE'][$t][3];
  143. }
  144. public static function getFCount($t) {
  145. if(!class_exists($t)) return false;
  146. return $GLOBALS['_FTYPE'][$t][2];
  147. }
  148. public static function _getClass($t) {
  149. if(!class_exists($t)) return false;
  150. return $GLOBALS['_FTYPE'][$t][0];
  151. }
  152. public static function getTypes() {
  153. global $_FTYPE;
  154. $ty=array();
  155. $la=array();
  156. foreach($_FTYPE as $t => $label) {
  157. if(empty($label[4])) {
  158. $ty[]=$t;
  159. $la[]=XLabels::getSysLabel('xfielddef',$t);
  160. }
  161. }
  162. array_multisort($la, $ty);
  163. return array($ty, $la);
  164. }
  165. /**
  166. * Renvoie les types de champs "lien vers un objet"
  167. * @return Array Liste des types de champs "lien vers un objet"
  168. */
  169. public static function getObjectLinkTypes() {
  170. global $_FTYPE;
  171. $link_types = array();
  172. foreach($_FTYPE as $type => $params) {
  173. if (self::isObjectLink($type)) {
  174. $link_types[] = $type;
  175. }
  176. }
  177. return $link_types;
  178. }
  179. /**
  180. * Teste si le type du champ correspond à un "lien vers un objet"
  181. * @param string $type Type de champ à renseigner dans un contexte static
  182. * @return boolean Vrai si le type correspond à un "lien vers un objet"
  183. */
  184. function isObjectLink($type = null) {
  185. if (empty($type) && isset($this)) $type = $this->ftype;
  186. return self::getGender($type) == 'Oid' && self::getUseTarget($type);
  187. }
  188. function __construct($obj=NULL) {
  189. if(empty($obj)) {
  190. $obj=(object)array('FIELD'=>'anonymous','FTYPE'=>get_class($this),
  191. 'COMPULSORY'=>0,'TRANSLATABLE'=>0, 'FCOUNT'=>20, 'FORDER'=>0, 'QUERYABLE'=>1, 'MULTIVALUED'=>0,
  192. 'BROWSABLE'=>1, 'DTAB'=>'%', 'PUBLISHED'=>1, 'TARGET'=>'%', 'DPARAM'=>NULL);
  193. }
  194. bugWarning('XFieldDef::__construct: bad parameter', !empty($obj), true);
  195. $field = @$obj->FIELD;
  196. $ftype = @$obj->FTYPE;
  197. $table = @$obj->DTAB;
  198. $this->_options = new XOptions();
  199. $this->ftype = $ftype;
  200. $this->field = $field;
  201. $this->table = $table;
  202. $this->sys = $this->_sysField();
  203. $this->fcount = @$obj->FCOUNT;
  204. $this->forder = @$obj->FORDER;
  205. $this->compulsory = @$obj->COMPULSORY;
  206. $this->queryable = @$obj->QUERYABLE;
  207. $this->browsable = @$obj->BROWSABLE;
  208. $this->translatable = @$obj->TRANSLATABLE;
  209. $this->multivalued = @$obj->MULTIVALUED;
  210. $this->published = @$obj->PUBLISHED;
  211. $this->target = @$obj->TARGET;
  212. $this->initOptions();
  213. $this->setOptions(@$obj->DPARAM);
  214. $this->readonly = $this->readonly||$this->_sysRO();
  215. if(!empty($obj->MTXT)) $this->label = $obj->MTXT;
  216. elseif(!empty($obj->LABEL)) $this->label = $obj->LABEL;
  217. else $this->label=$field;
  218. if(!empty($this->aliasmodule)) {
  219. if(!XAlias::registered($this->aliasmodule)) {
  220. XAlias::register($this->aliasmodule);
  221. }
  222. }
  223. }
  224. /// creation d'une valeur prete a etre retournee
  225. function _newXFieldVal(&$option, $genid=false) {
  226. $r= new XFieldVal();
  227. $r->field=$this->field;
  228. $r->table=$this->table;
  229. $r->sys=$this->sys;
  230. $r->readonly=$this->readonly;
  231. $r->fielddef=$this;
  232. $r->filename=NULL;
  233. $r->catalog=NULL;
  234. if($genid) $r->varid=getUniqID('v'.$r->field);
  235. return $r;
  236. }
  237. /// creation d'une valeur prete a etre retournee pour la recherche
  238. function _newXFieldQuery($option=NULL, $genid=false) {
  239. $r=new XFieldQuery();
  240. $r->field=$this->field;
  241. $r->table=$this->table;
  242. $r->sys=$this->sys;
  243. $r->readonly=$this->readonly;
  244. $r->fielddef=$this;
  245. if($genid) $r->varid=getUniqID('q'.$r->field);
  246. return $r;
  247. }
  248. protected function initOptions() {
  249. $helpgroup=XLabels::getSysLabel('general','help','text');
  250. $querygroup=XLabels::getSysLabel('general','query','text');
  251. $this->_options->setId($this->table.':'.$this->field);
  252. $this->_options->setOpt(XLabels::getSysLabel('xfielddef.readonly'), 'readonly', 'boolean');
  253. $this->_options->setOpt(XLabels::getSysLabel('general','comment','text'), 'comment', 'ttext', array('rows'=>2, 'cols'=>60),NULL, $helpgroup);
  254. $this->_options->setOpt(XLabels::getSysLabel('general','comment','text').' Backoffice', 'acomment', 'ttext', array('rows'=>2, 'cols'=>60), NULL,
  255. $helpgroup);
  256. $this->_options->setOpt(XLabels::getSysLabel('general','group'), 'fgroup', 'ttext');
  257. $this->_options->setOpt(XLabels::getSysLabel('xfielddef','default'),'default','text');
  258. $this->_options->setOpt(XLabels::getSysLabel('xdatasource','aliasmodule'),'aliasmodule','module',array('toid'=>4,'emptyok'=>true));
  259. $this->_options->setOpt(XLabels::getSysLabel('xfielddef.meta_source'),'exif_source','text',array('rows'=>3,'cols'=>40));
  260. if(!empty($this->query_formats)){
  261. $class=strtolower(get_class($this));
  262. $labels=array();
  263. foreach($this->query_formats as $qf){
  264. $tt='qf-'.$class.'-'.$qf;
  265. $label=XLabels::getSysLabel('xfielddef',$tt);
  266. if($tt==$label) $label=XLabels::getSysLabel('xfielddef','qf-'.$qf);
  267. $labels[]=$label;
  268. }
  269. $this->_options->setOpt(XLabels::getSysLabel('xfielddef','query_formats'), 'query_format', 'list',
  270. array('values'=>$this->query_formats,'labels'=>$labels),NULL,$querygroup);
  271. }
  272. $this->_options->setOpt('Dependance', 'dependency', 'dependency');
  273. $this->_options->setOpt(XLabels::getSysLabel('xfielddef.indexable'), 'indexable', 'boolean', NULL, false,$querygroup);
  274. }
  275. function get_sqlValue($value) {
  276. // Fabrique une valeur de colonne pour SQL a partir d'une valeur issue de PHP
  277. return $value; // Dans la majorite des cas.
  278. }
  279. public function hasExternals() { return false; }
  280. public function externals() { return NULL; }
  281. public function set_target($t) { $this->target=$t;}
  282. public function get_target() { return $this->target;}
  283. public function set_readonly($t) { $this->readonly=$t;}
  284. public function use_fcount() { return $GLOBALS['_FTYPE'][$this->ftype][2];}
  285. public function get_readonly() { return $this->readonly;}
  286. public function get_fcount() { return $this->fcount;}
  287. public function set_fcount($p) { $this->fcount=$p;}
  288. public function get_ftype() { return $this->ftype; }
  289. public function set_ftype($p) { $this->ftype=$p; }
  290. public function set_forder($p) { $this->forder=$p;}
  291. public function get_forder() { return $this->forder;}
  292. public function get_use_target() { return $GLOBALS['_FTYPE'][$this->ftype][3];}
  293. public function get_fgender() { return $GLOBALS['_FTYPE'][$this->ftype][1]; }
  294. public function get_field() { return $this->field; }
  295. public function set_field($p) { $this->field=$p; }
  296. public function get_compulsory() { return $this->compulsory; }
  297. public function set_compulsory($p) { $this->compulsory=$p; }
  298. public function get_queryable() { return $this->queryable; }
  299. public function set_queryable($p) { $this->queryable=$p; }
  300. public function get_browsable() { return $this->browsable; }
  301. public function set_browsable($p) { $this->browsable=$p; }
  302. public function get_translatable() { return $this->translatable; }
  303. public function set_translatable($p) { $this->translatable=$p; }
  304. public function get_multivalued() { return $this->multivalued; }
  305. public function set_multivalued($p) { $this->multivalued=$p; }
  306. public function get_published() { return $this->published; }
  307. public function set_published($p) { $this->published=$p; }
  308. private function _sysField() { return in_array($this->field, array('UPD','PUBLISH','PRIV','OWN','PRP','CREAD')); }
  309. private function _sysRO() { return in_array($this->field, array('UPD','OWN','CREAD')); }
  310. public function sysField() { return $this->sys; }
  311. public function get_options() { return $this->_options->getView();}
  312. public function is_summable() { return false; }
  313. function getOptions($block='opt') {
  314. return $this->_options->getDialog($this, array(),$block);
  315. }
  316. function serializeOptions() {
  317. return $this->_options->serialize($this);
  318. }
  319. function setOptions($dparam) {
  320. if(empty($dparam)) $dparam=array();
  321. if(is_array($dparam)) $this->_options->setValues($this, $dparam);
  322. elseif(substr($dparam, 0, 2)=='a:') $this->_options->setValues($this, unserialize($dparam));
  323. elseif(substr($dparam, 0, 5)=='<?xml') $this->_options->fromXML($this,$dparam);
  324. else $this->_options->setValues($this);
  325. }
  326. public function cacheable() { return true; }
  327. function get_label() {
  328. return $this->label;
  329. }
  330. /// rend les libelles d'un champ dans toutes les langies
  331. function get_labels() {
  332. if(isset($this->labels)) return $this->labels;
  333. $rs=selectQuery("select MSGS.* from MSGS where MTAB='".$this->table."' and FIELD='".$this->field."'");
  334. $r=array();
  335. $ors=array();
  336. while($ors=$rs->fetch()) {
  337. $r[$ors['MLANG']]=$ors['MTXT'];
  338. }
  339. $rs->closeCursor();
  340. $this->labels = $r;
  341. return $r;
  342. }
  343. /// rend la valeur d'une option, avec toutes les lkangues s'il s'agit d'un libelle
  344. function get_option($o) {
  345. $txts=XLabels::getAMsg($this->_options->id.':'.$o,NULL,false);
  346. return $txts;
  347. }
  348. function set_label($v) { die('XFieldDef::get_labels'); }
  349. function set_labels($vs) {
  350. unset($this->labels);
  351. while ( list($codeLang,$v) = each($vs) ) {
  352. if ( $v != '' ) $this->labels[$codeLang] = $v;
  353. }
  354. $lg = XShell::getLangUser();
  355. $this->label=$this->labels[$lg];
  356. }
  357. // renvoie un label html - usage formulaire FO
  358. // ajoute la classe "tzr-label-compulsory"
  359. // et le marqueur $compulsory_mark aux champs obligatoires
  360. function get_htmllabel($compulsory_mark = '*') {
  361. if ($this->compulsory)
  362. $label = '<label for="'.$this->field.'" class="tzr-label-compulsory">'.$this->label.' '.$compulsory_mark.'</label>';
  363. else
  364. $label = '<label for="'.$this->field.'">'.$this->label.'</label>';
  365. if ($this->comment)
  366. $label .= '<div class="cv8d-comment" >'.$this->comment.'</div>';
  367. return $label;
  368. }
  369. function get_browse_query($value) {
  370. if($this->multivalued) {
  371. $globdisp='';
  372. $machaine = $value;
  373. $val = explode('||',trim($machaine));
  374. $count = count($val);
  375. $cond = '';
  376. for($i=0;$i<$count; $i++) {
  377. if($val[$i]!='') {
  378. if($cond!='') $cond=$cond.' or ';
  379. $cond = $cond." KOID='$val[$i]' ";
  380. }
  381. }
  382. $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->target);
  383. $query=$xst->select_query(array()).' and ('.$cond.')';
  384. return $query;
  385. }
  386. }
  387. function raw_oids($value,$options=NULL) {
  388. $r=array();
  389. if($this->multivalued) {
  390. $globdisp='';
  391. $machaine = $value;
  392. $val = explode('||',trim($machaine));
  393. $count = count($val);
  394. for($i=0;$i<$count; $i++) {
  395. if($val[$i]!='') {
  396. $r[] = $val[$i];
  397. }
  398. }
  399. } else {
  400. $pos = strstr($value[0],'||');
  401. if($pos!='') {
  402. $val = explode('||',trim($value[0]));
  403. $count = count($val);
  404. for($i=0;$i<$count; $i++) {
  405. if($val[$i]!='') {
  406. $r[] = $val[$i];
  407. }
  408. }
  409. } else {
  410. $r[]=$value;
  411. }
  412. }
  413. return $r;
  414. }
  415. function export($value,$options=NULL) {
  416. $format=$options['format'];
  417. if(!isset($format)) $format='xml';
  418. $func='export_'.$format;
  419. return $this->$func($value,$options);
  420. }
  421. function export_xml($value,$options) {
  422. $labels=$options['labels'];
  423. $txt='';
  424. $lang = $GLOBALS['LANG_DATA'];
  425. foreach($value as $k => $v) {
  426. if(($v!='')) {
  427. $val = $this->my_export(array($v),$options);
  428. $l=htmlspecialchars($this->label);
  429. $l=str_replace(' ','_',$l);
  430. $txt.="<$l>$val</$l>\n";
  431. }
  432. }
  433. return $txt;
  434. }
  435. function &multi_oid_display($value, $options=NULL) {
  436. $r = $this->_newXFieldVal($options);
  437. $r->raw=$value;
  438. $machaine = $value;
  439. $val = explode('||',trim($machaine));
  440. $count = count($val);
  441. if($count>0) {
  442. $r->collection = array();
  443. $r->oidcollection=array();
  444. }
  445. for($i=0;$i<$count; $i++) {
  446. if(($val[$i]!='') && ($val[$i]!='Foo')) {
  447. $value = $val[$i];
  448. $o=$this->my_display($value, $options);
  449. if(is_object($o) && !empty($o->raw)) {
  450. $r->collection[] = $o;
  451. $r->oidcollection[] = $val[$i];
  452. if(($r->html!='') && (strlen($o->html)>0)) $r->html.='<br/>'.$o->html;
  453. else $r->html.=$o->html;
  454. }
  455. }
  456. }
  457. $r->text=strip_tags(str_replace(array('<br>','<br/>'),', ',$r->html));
  458. $o1=$r;
  459. return $o1;
  460. }
  461. function &multi_data_display(&$value,&$options) {
  462. $r = $this->_newXFieldVal($options);
  463. $separator=$this->separator;
  464. $r->raw=$value;
  465. $val = preg_split('@['.$separator.']@',trim($r->raw));
  466. for($i=0; $i<count($val); $i++) {
  467. if($val[$i]!='') {
  468. $value = trim($val[$i]);
  469. $o=&$this->my_display($value, $options);
  470. if(is_object($o) && isset($o->raw)) {
  471. $r->collection[] = $o;
  472. if(($r->html!='')&&(strlen($o->html)>0)) $r->html .= $this->separator[0].' '.$o->html;
  473. else $r->html .= $o->html;
  474. }
  475. }
  476. }
  477. return $r;
  478. }
  479. function display(&$value,&$options) {
  480. if(!empty($options['value'])) $value=$options['value'];
  481. if($this->multivalued && ($this->get_fgender()=='Oid')) {
  482. $o = & $this->multi_oid_display($value,$options);
  483. } elseif($this->multivalued) {
  484. $o = & $this->multi_data_display($value,$options);
  485. } else {
  486. $o= & $this->my_display($value, $options);
  487. }
  488. if(@$options['_format']=='xhtml') {
  489. $o->xhtml = '<'.$this->field.'>'.$o->html.'</'.$this->field.'>';
  490. }
  491. return $o;
  492. }
  493. function browse(&$value,&$options) {
  494. $r = $this->_newXFieldVal($options);
  495. if($this->multivalued && ($this->get_fgender()=='Oid')) {
  496. $r->raw=$value;
  497. $machaine = $value;
  498. $val = explode('||',trim($machaine));
  499. $count = count($val);
  500. if($count>0) {
  501. $r->collection = array();
  502. $r->oidcollection=array();
  503. }
  504. for($i=0;$i<$count; $i++) {
  505. if($val[$i]!='') {
  506. $value1 = $val[$i];
  507. $o=$this->my_browse($value1, $options);
  508. if(is_object($o) && isset($o->raw)) {
  509. $r->collection[] = $o;
  510. $r->oidcollection[] = $value1;
  511. if(!empty($r->html)&&!empty($o->html)) $r->html .= '<br/>'.$o->html;
  512. else $r->html .= $o->html;
  513. }
  514. }
  515. }
  516. $r->text=strip_tags(str_replace('<br/>',', ',$r->html));
  517. $o=$r;
  518. } elseif($this->multivalued) {
  519. $separator=$this->separator;
  520. $r->raw=$value;
  521. $val = preg_split('@['.$separator.']@',trim($r->raw));
  522. $count = count($val);
  523. if($count>0) {
  524. for($i=0;$i<$count; $i++) {
  525. if($val[$i]!='') {
  526. $value1 = trim($val[$i]);
  527. $o=&$this->my_browse($value1, $options);
  528. if(is_object($o) && isset($o->raw)) {
  529. $r->collection[] = $o;
  530. if(($r->html!='')&&(strlen($o->html)>0)) $r->html .= $separator[0].' '.$o->html;
  531. else $r->html .= $o->html;
  532. }
  533. }
  534. }
  535. }
  536. $o=& $r;
  537. } else {
  538. $o= & $this->my_browse($value, $options);
  539. }
  540. return $o;
  541. }
  542. function &edit(&$value,&$options=array(),$fields_complement=null) {
  543. $lang_user = XShell::getLangUser();
  544. if(!empty($options['value'])) $value=$options['value'];
  545. if((!XShell::isRoot() && ($this->readonly || @$options['readonly'])) || @$options['readonly']==2) {
  546. $r=$this->display($value,$options);
  547. return $r;
  548. }
  549. if($this->multivalued && ($this->get_fgender()=='Oid')) {
  550. $val = explode('||',trim($value));
  551. $count = count($val);
  552. $value=array();
  553. for($i=0;$i<$count;$i++) {
  554. if($val[$i]!='') {
  555. $value[$val[$i]]=1;
  556. }
  557. }
  558. } elseif (strpos($value,'||')!==false && ($this->get_fgender()=='Oid') ) {
  559. $val = explode('||',trim($value));
  560. $count = count($val);
  561. unset($value);
  562. $stop=0;
  563. for($i=0;($i<$count) && ($stop!=1); $i++) {
  564. if(trim($val[$i])!='') {
  565. $value=$val[$i];
  566. $stop=1;
  567. }
  568. }
  569. }
  570. $r=$this->my_edit($value,$options,$fields_complement);
  571. if(empty($r->varid)) $r->varid=getUniqID('v'.$r->field);
  572. if($this->multivalued && $this->advanceeditbatch && !empty($options['editbatch'])){
  573. $id=getUniqID('v'.$r->field);
  574. $r->html= '<input id="'.$id.'-1" class="radio" type="radio" name="'.$this->field.'_op" value="+" checked>'.
  575. '<label class="tzr-st-label" for="'.$id.'-1">'.XLabels::getSysLabel('xfielddef','editbatch_add').'</label> '.
  576. '<input id="'.$id.'-2" class="radio" type="radio" name="'.$this->field.'_op" value="=">'.
  577. '<label class="tzr-st-label" for="'.$id.'-2">'.XLabels::getSysLabel('xfielddef','editbatch_replace').'</label> '.
  578. '<input id="'.$id.'-3" class="radio" type="radio" name="'.$this->field.'_op" value="-">'.
  579. '<label class="tzr-st-label" for="'.$id.'-3">'.XLabels::getSysLabel('xfielddef','editbatch_remove').'</label><br>'.
  580. $r->html;
  581. }
  582. if(!empty($this->dependency['f'])){
  583. $r->html.='<script type="text/javascript">';
  584. foreach($this->dependency['dval'] as $i=>$foo){
  585. $r->html.='TZR.addDependency("'.$this->ftype.'","'.$this->dependency['f'].'","'.$this->field.'","'.$this->dependency['dval'][$i].
  586. '","'.$this->dependency['val'][$i].'","'.$this->dependency['op'][$i].'","'.$this->dependency['style'][$i].'",'.
  587. '"'.$this->dependency['nochange'][$i].'");'."\n";
  588. }
  589. $r->html.='</script>';
  590. }
  591. $r->edit=true;
  592. if($this->compulsory) $this->indicator=' *';
  593. else $this->indicator='';
  594. return $r;
  595. }
  596. /// Recupere la liste des valeurs presente dans une table pour un filtre donné
  597. public function _getUsedValues($filter=NULL,$select=NULL,$options=array(),$cache=true) {
  598. $this->_getUsedValuesParams($filter,$select,$options,$cachename);
  599. if($cache) $values=&XDbIni::get($cachename,'val');
  600. else $values=NULL;
  601. if(!$values || $values['f']!=$filter || $values['s']!=$select){
  602. $rs=&cacheSelectQuery($select);
  603. $values=array();
  604. $separator=!empty($this->separator)?$this->separator:'||';
  605. while($rs && $ors=$rs->fetch()) {
  606. if($this->multivalued){
  607. $tmpvalues=explode($separator,$ors[$this->field]);
  608. foreach($tmpvalues as $i=>$value) {
  609. if(!empty($value) && empty($values[$value])) $values[$value]=true;
  610. }
  611. }else{
  612. if(!empty($ors[$this->field]) && empty($values[$ors[$this->field]])) $values[$ors[$this->field]]=true;
  613. }
  614. }
  615. if ($rs) $rs->closeCursor();
  616. $values=array('f'=>$filter,'s'=>$select,'v'=>$values);
  617. if($cache) XDbIni::set($cachename,$values);
  618. }
  619. return $values['v'];
  620. }
  621. /// Met on forme les parametres utilisés pour récupérer les valeurs utilisées
  622. public function _getUsedValuesParams(&$filter,&$select,&$options,&$cachename) {
  623. $lang_data = TZR_DEFAULT_LANG;
  624. if (!empty($this->table)) {
  625. $xst = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->table);
  626. if (is_object($xst) && $xst->isTranslatable()) {
  627. $lang_data = XShell::getLangData();
  628. }
  629. }
  630. // on ne prend pas les valeurs vides d'autant plus quelles sont supprimees ensuite
  631. $filter = (empty($filter) ? '' : "($filter) AND ") . '('.$this->field.' != \'\')';
  632. if(!empty($this->table) && !$select){
  633. $where=$filter;
  634. if(!empty($options['fmoid'])){
  635. $mod=XModule::objectFactory($options['fmoid']);
  636. $modfilter=$mod->getUsedValuesFilter();
  637. if($modfilter) $where.=' AND '.$mod->getUsedValuesFilter();
  638. }
  639. $where.=' AND LANG="'.$lang_data.'"';
  640. $select='SELECT DISTINCT '.$this->field.' FROM '.$this->table.' WHERE '.$where;
  641. if(!empty($options['order'])) $select.=' ORDER BY '.$options['order'];
  642. if(!empty($options['limit'])) $select.=' LIMIT '.$options['limit'];
  643. }
  644. $code=md5($filter.'-'.$select);
  645. if($this->target==TZR_DEFAULT_TARGET)
  646. $cachename=$this->table.':usedValues:'.$this->field.':'.$lang.':'.$code;
  647. else
  648. $cachename=$this->table.'|'.$this->target.':usedValues:'.$this->field.':'.$lang.':'.$code;
  649. }
  650. function quickquery($value,$ar=NULL) {
  651. if(empty($ar['query_format'])) $ar['query_format']=XFieldDef::QUICKQUERY_FORMAT;
  652. return $this->my_quickquery($value,$ar);
  653. }
  654. function my_quickquery($value,$ar=NULL) {
  655. return $this->_newXFieldVal($ar);
  656. }
  657. function query($value,$ar=NULL) {
  658. if(is_array($value) && !in_array('Foo',$value) && $this->get_fgender()=='Oid') {
  659. foreach($value as $i => $val1) {
  660. if(!empty($val1)) {
  661. $va[$val1]=1;
  662. }
  663. }
  664. $value=$va;
  665. } elseif(!is_array($value)) {
  666. if($this->multivalued || @$ar['query_format']) {
  667. if($value!='Foo') {
  668. $val = explode('||',trim($value));
  669. unset($value);
  670. $value=array();
  671. foreach($val as $i => $val1) {
  672. if(!empty($val1)) {
  673. $value[$val1]=1;
  674. }
  675. }
  676. }
  677. } elseif (strstr($value,'||')!='') {
  678. $val = explode('||',trim($value));
  679. $count = count($val);
  680. unset($value);
  681. $stop=0;
  682. for($i=0;($i<$count) && ($stop!=1); $i++) {
  683. if(trim($val[$i])!='') {
  684. $value=$val[$i];
  685. $stop=1;
  686. }
  687. }
  688. }
  689. }
  690. if(empty($ar['query_format'])) $ar['query_format']=XFieldDef::QUERY_FORMAT;
  691. $r=$this->my_query($value,$ar);
  692. return $r;
  693. }
  694. /// Equivalent de query, mais prepare en plus les options sur le format de champs de recherche
  695. function pquery($value,$ar=NULL) {
  696. $qfmt=$ar['qfmt'];
  697. if($ar['notapplyqfmt']) unset($ar['qfmt']);
  698. $r=$this->query($value,$ar);
  699. if(empty($this->query_formats)) return $r;
  700. $fname=(isset($ar['fieldname'])?$ar['fieldname']:$this->field);
  701. $formats='<select name="options['.$fname.'][qfmt]">';
  702. $class=strtolower(get_class($this));
  703. foreach($this->query_formats as $qf){
  704. $label=XLabels::getSysLabel('xfielddef','qf-'.$class.'-'.$qf);
  705. if(empty($label)) $label=XLabels::getSysLabel('xfielddef','qf-'.$qf);
  706. $formats.='<option value="'.$qf.'"'.($qf==$qfmt?'selected':'').'>'.$label.'</option>';
  707. }
  708. $formats.='</select>';
  709. $r->query_formats=$formats;
  710. return $r;
  711. }
  712. // action a effectuer apres edition et avant stockage des donnees
  713. // on rend un tableau de valeur traitees
  714. function post_edit($value,$options=NULL,&$fields_complement=NULL) {
  715. $r=$this->_newXFieldVal($options);
  716. $langdata=XShell::getLangData();
  717. $hidden=$options[$this->field.'_HID'];
  718. $r->raw=$value;
  719. $this->trace(@$options['old'],$r);
  720. return $r;
  721. }
  722. // action effectuée apres une soumission de recherche
  723. // on rend un tableau de valeur traitees
  724. function post_query(&$o,$ar) {
  725. $v1=$o->value;
  726. $v1op=$o->op;
  727. $k=$this->field;
  728. $k1=$this->table.'.'.$this->field;
  729. $quotes=$o->quote;
  730. $o->rq='';
  731. // cas d'une formule
  732. if(!empty($v1) && is_string($v1) && ($v1[0]=='=')) {
  733. $quotes='';
  734. $v1=substr($v1,1);
  735. }
  736. // cas d'un oid sans le prefixe table
  737. if (!is_array($v1) && !empty($v1) && !Kernel::isAKoid($v1) && $this->isObjectLink()) {
  738. $v1=$this->target.':'.$v1;
  739. }
  740. // cas ou la valeur est un tableau et que le champ est multivalue
  741. if($this->get_multivalued() && is_array($v1) && !empty($v1)) {
  742. if($v1op!='OR') $v1op='AND';
  743. $rq=array();
  744. foreach($v1 as $i=>$v){
  745. $o1=clone($o);
  746. $o1->rq='';
  747. $o1->value=$v;
  748. $this->post_query($o1,$ar);
  749. if(!empty($o1->rq)) $rq[]=$o1->rq;
  750. }
  751. if(empty($rq)) $o->rq=NULL;
  752. else $o->rq='('.implode($v1op,$rq).')';
  753. }
  754. // cas ou la valeur multiple est un tableau et le champ n'est pas multivalue
  755. elseif(!$this->get_multivalued() && is_array($v1) && !empty($v1)) {
  756. $count=count($v1);
  757. $rq='(';
  758. for($i=0;$i<$count;$i++) {
  759. $o1=clone($o);
  760. $o1->rq='';
  761. $o1->value=$v1[$i];
  762. $this->post_query($o1,$ar);
  763. //dans l cas d'un recherche ne contenant pas les valeur le separateur est un AND
  764. $sep = 'OR';
  765. if($o1->op == "!=") $sep = 'AND';
  766. if(!empty($o1->rq)) {
  767. if($rq=='(') $rq.=$o1->rq;
  768. else $rq.=' '.$sep.' '.$o1->rq;
  769. }
  770. }
  771. $rq.=')';
  772. if($rq=='()')
  773. $o->rq=NULL;
  774. else
  775. $o->rq=$rq;
  776. }
  777. // traitement de tous les cas possible
  778. elseif(is_string($v1) && $v1op=='$') {
  779. $v1=$GLOBALS['TZR_DB']->quote(".*$v1\$");
  780. $o->rq="($k1 rlike $v1)";
  781. }
  782. elseif(is_string($v1) && $v1op=='^') {
  783. $v1=$GLOBALS['TZR_DB']->quote("^$v1.*");
  784. $o->rq =" ($k1 rlike $v1)";
  785. }
  786. elseif($v1op=='is empty') {
  787. $o->rq = " (($k1 is NULL) or ($k1 ='')) ";
  788. }
  789. elseif(is_array($v1) && !empty($v1) && $this->get_multivalued() && ($this->get_fgender()=='Oid')) {
  790. // traitement du multivalue avec separateur ||
  791. $count = count($v1);
  792. for($j=0;$j<$count; $j++) {
  793. if(!empty($v1[$j])) {
  794. $o->rq=" (($k1 = '".$v1[$j]."') OR INSTR(".$k1.", '||".$v1[$j]."||') or (".
  795. $k1."='".$v1[$j]."'))";
  796. if(($j!=0) && ($j!=($count-1))) $o->rq.='AND';
  797. }
  798. }
  799. if(!empty($o->rq)) $o->rq='('.$o->rq.')';
  800. }
  801. elseif(!empty($v1) && ($this->get_fgender()=='Oid') && (strstr($v1,'||')!=false)) {
  802. // traitement du multivalue avec separateur ||
  803. $v1=explode('||',$v1);
  804. $count = count($v1);
  805. for($j=0;$j<$count; $j++) {
  806. if(!empty($v1[$j])) {
  807. $o->rq=" (($k1 = '".$v1[$j]."') OR INSTR(".$k1.",'||".$v1[$j]."||'))";
  808. if(($j!=0) && ($j!=($count-1))) $o->rq.='AND';
  809. }
  810. }
  811. if(!empty($o->rq)) $o->rq='('.$o->rq.')';
  812. }
  813. elseif(is_array($v1) && ($this->get_fgender()=='Oid')) {
  814. // traitement du multivalue avec separateur ||
  815. $count = count($v1);
  816. for($j=0;$j<$count; $j++) {
  817. if(!empty($v1[$j])) {
  818. $o->rq.=' ('.$k1." like '".$v1[$j]."') ";
  819. if(($j!=0) && ($j!=($count-1))) $o->rq.='AND';
  820. }
  821. }
  822. if(!empty($o->rq)) $o->rq='('.$o->rq.')';
  823. }
  824. elseif(!empty($v1) && ($this->get_fgender()=='Oid')) {
  825. if($this->get_multivalued()) {
  826. $o->rq="( ($k1='$v1') OR instr(".$k1.", '||".$v1."||'))";
  827. } else
  828. $o->rq=' ('.$k1." = '".$v1."')";
  829. } elseif (!empty($v1) && !empty($v1op) && (is_string($v1) || is_numeric($v1))) {
  830. if(!empty($quotes)) $v1=$GLOBALS['TZR_DB']->quote($v1);
  831. $o->rq=' ('.$k1." $v1op $v1)";
  832. } elseif (!empty($v1) && !is_array($v1)) {
  833. if(empty($quotes)) {
  834. $o->rq=" (".$k1." like $v1)";
  835. } else {
  836. $v1=$GLOBALS['TZR_DB']->quote("%$v1%");
  837. $o->rq=' ('.$k1." like $v1) ";
  838. }
  839. }
  840. }
  841. // rend une expression pour requêtage
  842. //
  843. // action a effectuer apres edition et duplication d'une donnee
  844. function post_edit_dup($value,$options) {
  845. $p = new XParam($options,array());
  846. $oidsrc=$p->get('oidsrc');
  847. $options['oid']=$oidsrc;
  848. $r1= $this->post_edit($value,$options);
  849. return $r1->raw;
  850. }
  851. function sqltype() {
  852. return NULL;
  853. }
  854. function sqlfields() {
  855. return $this->field;
  856. }
  857. function sqlsumfunction() {
  858. return 'SUM('.$this->field.')';
  859. }
  860. function delfield() {
  861. return true;
  862. }
  863. function delete($value,$oid) {
  864. return 1;
  865. }
  866. function my_display(&$value,&$options) {
  867. return $this->_newXFieldVal($options);
  868. }
  869. /// Ecriture dans un fichier excel
  870. function writeXLS(&$xl,$i,$j,&$value,$format=0,&$ss) {
  871. if (is_object($value)){
  872. $v=$value->toText();
  873. if(empty($v)) $v=$value->raw;
  874. } else {
  875. $v = '';
  876. }
  877. convert_charset($v,TZR_INTERNAL_CHARSET,'UTF-8');
  878. $xl->setCellValueExplicit(PHPExcel_Cell::stringFromColumnIndex($j) . $i, $v);
  879. if(is_array($format)) $xl->getStyleByColumnAndRow($j,$i)->applyFromArray($format);
  880. }
  881. // Ecriture dans un csv
  882. function writeCSV(&$o,$textsep){
  883. if (is_object($o)){
  884. $value=str_replace(array($textsep,"\x0d"),array($textsep.$textsep,""),$o->toText());
  885. } else {
  886. $value = '';
  887. }
  888. $ret=$textsep.$value.$textsep;
  889. return $ret;
  890. }
  891. /// Import de données vers une table
  892. function import($value,$options=NULL) {
  893. $value=trim($value);
  894. $defaultvalue=(string)$options->default[0];
  895. // conversion eventuelle de format
  896. if(!empty($options->format) && !empty($value)) {
  897. $value=$this->convert($value,(string)$options->format['source'],(string)$options->format['destination']);
  898. }
  899. if(empty($value) && !empty($defaultvalue)) $value=$defaultvalue;
  900. $ret=$this->my_import($value,$options);
  901. return array('message'=>$ret['message'],'value'=>$ret['value']);
  902. }
  903. /// Sous fonction redefinie pour chaque type de champ pour l'import de données vers une table
  904. function my_import($value,&$options){
  905. $typefield=(string)$options['type'];
  906. return array('message'=>'','value'=>$value);
  907. }
  908. function my_browse(&$value, &$options) {
  909. return $this->my_display($value, $options);
  910. }
  911. function my_export($value) {
  912. return '';
  913. }
  914. function my_edit($value, $options=NULL){
  915. $r = $this->_newXFieldVal($options,true);
  916. $r->value = $value;
  917. return $r;
  918. }
  919. function my_query($value,$options=NULL){
  920. return $this->_newXFieldVal($options);
  921. }
  922. function filename($value) {
  923. return NULL;
  924. }
  925. function default_value() {
  926. return $this->default;
  927. }
  928. function search($value,$options=NULL) {
  929. $rq='';
  930. if(is_array($value)) {
  931. foreach($value as $i => $v) {
  932. if($rq!='') $rq .=' OR ';
  933. $rq .= $this->my_search($v,$options);
  934. }
  935. } else {
  936. $rq .= $this->my_search($value,$options);
  937. }
  938. return $rq;
  939. }
  940. function my_search($value,$options) {
  941. return $this->field.' like "%'.$value.'%" ';
  942. }
  943. function convert($value, $src, $dst) {
  944. return $value;
  945. }
  946. // generation d'une url complete et partielle pour la consultation d'un fichier
  947. //
  948. protected function getDownloader($short_filename, $mime='application/x-octet-stream',
  949. $originalname=NULL, $title=NULL, $moid=NULL) {
  950. if(empty($title)) $title=$originalname;
  951. $mimelabel=XLabels::getSysLabel('mime',$mime, 'both', 'mime', 'unknown/unknown');
  952. if(empty($mimelabel)) $mimelabel=XLabels::getSysLabel('mime','unknown/unknown');
  953. if(!empty($mimelabel)) $mimelabel.=' ';
  954. $originalname=removeaccents($originalname);
  955. $url=TZR_DOWNLOADER.'?filename='.$short_filename.'&amp;mime='.$mime.
  956. '&amp;originalname='.rawurlencode(preg_replace('/([^A-Za-z0-9\._-]+)/','_',$originalname)).(empty($moid)?'':'&amp;moid='.$moid).($this->gzipped==1?'&amp;gzip=1':'');
  957. $fullurl='<a bt-xpath="'.TZR_AJAX8.'?class=xfiledef&amp;function=xfiledef_getfilesize&amp;file='.$short_filename.'&amp;_='.XShell::uniqid().'" class="tzr-hottip-c tzr-file" href="'.$url.'">'.$mimelabel.$title.'</a>';
  958. return array($url, $fullurl);
  959. }
  960. /// Convertit le contenu de la base de données suite à un changement de format du champ
  961. public function convertValues($oldftype){
  962. return;
  963. }
  964. /// Assigne les metas à partir de la valeur du champ
  965. function setMetaFromValue($metaanalyser,&$r,$filter=array('IPTC','XMP'),$prop='text'){
  966. $isok=array();
  967. $metas=explode("\n",$this->exif_source);
  968. foreach($metas as &$meta){
  969. $list=explode('.',$meta);
  970. if(count($list)<2) continue;
  971. if(count($list)<3) array_unshift($list,'IPTC');
  972. if($list[0]=='XMP' && in_array('XMP',$filter) && !in_array('XMP',$isok)){
  973. if($this->multivalued){
  974. $v=array();
  975. foreach($r->collection as $i=>&$c) $v[]=$c->$prop;
  976. $metaanalyser->setXMPProperty($list[2],$v,@$list[3]);
  977. }else{
  978. $metaanalyser->setXMPProperty($list[2],$r->$prop,@$list[3]);
  979. }
  980. $isok[]='XMP';
  981. }
  982. if($list[0]=='IPTC' && in_array('IPTC',$filter) && !in_array('IPTC',$isok)){
  983. $metaanalyser->setIPTCProperty($list[2],$r->$prop);
  984. $isok[]='IPTC';
  985. }
  986. }
  987. }
  988. /// Recupere la valeur d'un champ depuis les meta d'un champ fichier
  989. function getMetaValue(&$computed_fields,$filter=array('IPTC','EXIF','XMP'),$getall=false){
  990. $value='';
  991. $metas=explode("\n",$this->exif_source);
  992. foreach($metas as &$meta){
  993. $list=explode('.',$meta);
  994. if(count($list)<2) continue;
  995. if(count($list)<3) array_unshift($list,'IPTC');
  996. if(!is_object(@$computed_fields[$list[1]])) return;
  997. if(in_array('IPTC',$filter) && $list[0]=='IPTC'){
  998. $value=$computed_fields[$list[1]]->getIPTC($list[2]);
  999. if(!empty($value)) break;
  1000. }elseif(in_array('EXIF',$filter) && $list[0]=='EXIF'){
  1001. $value=$computed_fields[$list[1]]->getEXIF($list[2]);
  1002. if(!empty($value)) break;
  1003. }elseif(in_array('XMP',$filter) && $list[0]=='XMP'){
  1004. $value=$computed_fields[$list[1]]->getXMP($list[2]);
  1005. if(!$getall) $value=(is_object($value)?$value->text:NULL);
  1006. if(!empty($value)) break;
  1007. }
  1008. }
  1009. return $value;
  1010. }
  1011. /// Recupere le type du champ dans un webservice (name : type xml, descr : description du type pour l'ajour d'une type complexe)
  1012. function getSoapType(){
  1013. return array('name'=>'xsd:string');
  1014. }
  1015. /// Recupere la valeur formattée pour le service SOAP
  1016. function getSoapValue($r){
  1017. return $r->raw;
  1018. }
  1019. /// Retourne une chaine de caractere decrivant la recherche en cours sur le champ
  1020. function getQueryText($o){
  1021. if(is_array($o->value)){
  1022. $vals=array();
  1023. foreach($o->value as $v){
  1024. $d=$this->my_display($v);
  1025. $vals[]=$d->text;
  1026. }
  1027. if($o->op=='OR') $sep=' '.strtolower(XLabels::getSysLabel('general','or','text')).' ';
  1028. else $sep=' '.strtolower(XLabels::getSysLabel('general','and','text')).' ';
  1029. $ret.=implode($sep,$vals);
  1030. }else{
  1031. $d=$this->my_display($o->value);
  1032. $ret=$this->getQueryTextOp($o->op,true);
  1033. $ret.=$d->text;
  1034. }
  1035. return $ret;
  1036. }
  1037. function getQueryTextOp($op,$addscape=false){
  1038. $ret='';
  1039. if(!empty($op)){
  1040. switch($op){
  1041. case '>':
  1042. $ret=XLabels::getSysLabel('xfielddef','more_than','text').' ';
  1043. break;
  1044. case '>=':
  1045. $ret=XLabels::getSysLabel('xfielddef','upper_than','text').' ';
  1046. break;
  1047. case '<=':
  1048. $ret=XLabels::getSysLabel('xfielddef','lower_than','text').' ';
  1049. break;
  1050. case '$':
  1051. $ret=XLabels::getSysLabel('xfielddef','query_ending_with','text').' ';
  1052. break;
  1053. case '^':
  1054. $ret=XLabels::getSysLabel('xfielddef','query_beginning_with','text').' ';
  1055. break;
  1056. case '!=':
  1057. $ret=XLabels::getSysLabel('xfielddef','query_different','text').' ';
  1058. break;
  1059. case 'is empty':
  1060. $ret=XLabels::getSysLabel('xfielddef','is_empty','text').' ';
  1061. break;
  1062. }
  1063. }
  1064. if($addscape && $ret) $ret.=' ';
  1065. return $ret;
  1066. }
  1067. /// Recupere le texte d'une valeur
  1068. public function &toText($r) {
  1069. if(!property_exists($r, 'text') || $r->text===NULL) $r->text=getTextFromHTML($r->html);
  1070. return $r->text;
  1071. }
  1072. /**
  1073. * Function isEmpty
  1074. * @return true si le champ n'est pas remplit
  1075. */
  1076. public function isEmpty($r){
  1077. if(property_exists($r, 'raw')) return empty($r->raw);
  1078. else return true;
  1079. }
  1080. }
  1081. ?>