PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/class.xthesaurusdef.inc

https://github.com/jcplat/console-seolan
PHP | 548 lines | 509 code | 20 blank | 19 comment | 127 complexity | fb377be301cb1d553995c53ec2cab67d MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. class XThesaurusDef extends XLinkDef{
  3. public $query_formats=array('classic');
  4. public $quickadd=true;
  5. public $flabel=NULL;
  6. public $fparent=NULL;
  7. public $indexable=NULL;
  8. function __construct($ar=NULL){
  9. parent::__construct($ar);
  10. }
  11. function initOptions() {
  12. XFieldDef::initOptions();
  13. $this->_options->delOpt('aliasmodule');
  14. $this->_options->setOpt(XLabels::getSysLabel('xfielddef','sourcemodule'),'sourcemodule','module',array('emptyok'=>true));
  15. $this->_options->setOpt(XLabels::getSysLabel('xfielddef','xthesaurus_label'),"flabel","field",
  16. array('table'=>$this->target,'compulsory'=>false,'type'=>'XShortTextDef'));
  17. $this->_options->setOpt(XLabels::getSysLabel('xfielddef','xthesaurus_parent'),"fparent","field",
  18. array('table'=>$this->target,'compulsory'=>true,'type'=>XFieldDef::getObjectLinkTypes()));
  19. $this->_options->setOpt('Optimiser en fonction du champ',"optimizewith","field",
  20. array('table'=>$this->table,'compulsory'=>false,'type'=>array('XLinkDef', 'XThesaurusDef', 'XShortTextDef')));
  21. $this->_options->setOpt(XLabels::getSysLabel('xfielddef','xthesaurus_quickadd'),"quickadd","boolean");
  22. $querygroup=XLabels::getSysLabel('general','query','text');
  23. $this->_options->setOpt(XLabels::getSysLabel('xfielddef.indexable'), 'indexable', 'boolean', NULL, true, $querygroup);
  24. }
  25. /// Recupere la liste des ascendants d'un oid
  26. function &getParents($value,$options,$gethtml=true){
  27. $lang_data=XShell::getLangData();
  28. $parents=array();
  29. if($gethtml) list($myliste,$my_flist,$first)=$this->getFieldList($options);
  30. if(empty($value)) return array();
  31. elseif(!is_array($value)) $v=array($value);
  32. else $v=$value;
  33. do{
  34. $rs=selectQuery('SELECT * FROM '.$this->target.' WHERE KOID IN ("'.implode('","',$v).'") AND LANG="'.$lang_data.'"');
  35. $v=array();
  36. while($rs && $ors=$rs->fetch()){
  37. $parents[$ors['KOID']]=($gethtml?$this->format_display($myliste,$ors,$p1):true);
  38. $v[]=$ors[$this->fparent];
  39. }
  40. }while(!empty($v));
  41. $parents=array_reverse($parents);
  42. return $parents;
  43. }
  44. /// Recupere la liste des descendants d'un ou pls oid
  45. function &getSons($value,$options,$gethtml=true){
  46. $lang_data=XShell::getLangData();
  47. $sons=array();
  48. if($gethtml) list($myliste,$my_flist,$first)=$this->getFieldList($options);
  49. if(empty($value)) return array();
  50. elseif(!is_array($value)) $v=array($value);
  51. else $v=$value;
  52. do{
  53. $rs=selectQuery('SELECT * FROM '.$this->target.' WHERE '.$this->fparent.' IN ("'.implode('","',$v).'") AND LANG="'.$lang_data.'"');
  54. $v=array();
  55. while($rs && $ors=$rs->fetch()){
  56. $sons[$ors['KOID']]=($gethtml?$this->format_display($myliste,$ors,$p1):true);
  57. $v[]=$ors['KOID'];
  58. }
  59. }while(!empty($v));
  60. return $sons;
  61. }
  62. function my_display($value,&$options){
  63. static $cache=array();
  64. $this->modsUsingTable=0;
  65. if($this->target==TZR_DEFAULT_TARGET || !XDataSource::sourceExists($this->target) || empty($this->fparent)) {
  66. $r=$this->_newXFieldVal($options);
  67. $r->html='';
  68. return $r;
  69. }
  70. $r=parent::my_display($value,$options);
  71. if(!empty($r->raw)){
  72. $r->html=@$cache[$r->raw];
  73. if($r->html===null){
  74. $parents=$this->getParents($value,$options);
  75. $parents[$r->raw]=$r->title;
  76. $cache[$r->raw]=$r->html=implode(' > ',$parents);
  77. }
  78. }
  79. return $r;
  80. }
  81. function my_import($value,&$options){
  82. if(empty($options['srcField'])){
  83. $options['srcField']=$this->flabel;
  84. }
  85. return parent::my_import($value,$options);
  86. }
  87. function my_edit($value,&$options,$fields_complement){
  88. $lang_data=XShell::getLangData();
  89. $r=$this->_newXFieldVal($options);
  90. $r->raw=$value;
  91. if($this->target==TZR_DEFAULT_TARGET || !XDataSource::sourceExists($this->target) || empty($this->fparent)) {
  92. $r->html='';
  93. return $r;
  94. }
  95. if($this->sourcemodule){
  96. $mod=&XModule::objectFactory(array('moid'=>$this->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
  97. if($mod->object_sec && !$mod->secure('',':list') || !$mod->object_sec && !$mod->secure('',':ro')) return $r;
  98. }
  99. if(isset($options['intable'])) {
  100. $o=$options['intable'];
  101. $fname=$this->field.'['.$o.']';
  102. $hiddenname=$this->field.'_HID['.$o.']';
  103. } elseif(!empty($options['fieldname'])) {
  104. $fname=$options['fieldname'];
  105. $hiddenname=$options['fieldname'].'_HID';
  106. } else {
  107. $fname=$this->field;
  108. $hiddenname=$this->field.'_HID';
  109. }
  110. // Liste des champs de la cible
  111. list($myliste,$my_flist,$first)=$this->getFieldList($options);
  112. // Ligne de base
  113. $varid=uniqid('v');
  114. $delico=XLabels::getSysLabel('general','delete');
  115. $edit='<div id="div'.$varid.'">';
  116. if($this->get_multivalued() && $options['query_format']){
  117. $edit.='<input class="radio" type="radio" name="'.$fname.'_op" value="AND" id="'.$varid.'-AND"'.((empty($options['op']) || $options['op']=='AND')?' checked':'').'>'.
  118. '<label for="'.$varid.'-AND">'.XLabels::getSysLabel('xfielddef.xlinkdef_allterms').'</label><br>'.
  119. '<input class="radio" type="radio" name="'.$fname.'_op" value="OR" id="'.$varid.'-OR"'.($options['op']=='OR'?' checked':'').'>'.
  120. '<label for="'.$varid.'-OR">'.XLabels::getSysLabel('xfielddef.xlinkdef_leastaterm').'</label><br>'.
  121. '<input class="radio" type="radio" name="'.$fname.'_op" value="NONE" id="'.$varid.'-NONE"'.($options['op']=='NONE'?' checked':'').'>'.
  122. '<label for="'.$varid.'-NONE">'.XLabels::getSysLabel('xfielddef.xlinkdef_noterm').'</label><br>';
  123. }
  124. $edit.='<table id="table'.$varid.'"><tr style="display:none;"><td><a href="#" onclick="TZR.removeThesaurusValue(\''.$varid.'\',this);return false;">'.$delico.'</a><input type="hidden" name="'.$fname.'[]" value=""></td><td></td></tr>';
  125. // Affiche les valeurs en cours
  126. if(!empty($value)){
  127. if(!is_array($value)) $value=array($value=>'1');
  128. $rs=selectQuery('SELECT DISTINCT '.$my_flist.' FROM '.$this->target.' WHERE KOID IN ("'.implode('","',array_keys($value)).'") '.
  129. 'AND LANG="'.$lang_data.'"'.($first?' ORDER BY '.$first:''));
  130. while($ors=$rs->fetch()){
  131. if($mod && $mod->object_sec && !$mod->secure($ors['KOID'],':ro')) continue;
  132. $parents=$this->getParents($ors['KOID'],$options);
  133. $parents[$ors['KOID']]=$this->format_display($myliste,$ors,$p1);
  134. $display=implode(' > ',$parents);
  135. $edit.='<tr><td><a href="#" onclick="TZR.removeThesaurusValue(\''.$varid.'\',\''.$ors['KOID'].'\');return false;">'.$delico.'</a><input type="hidden" name="'.$fname.'[]" value="'.$ors['KOID'].'"></td><td>'.$display.'</td></tr>';
  136. }
  137. }
  138. $edit.='</table>';
  139. // Ajout d'un input d'autompletion pour une saisie directe
  140. $edit.='<input autocomplete="off" id="_INPUT'.$varid.'" size="30" type="text" value="" class="tzr-link">';
  141. $url=TZR_AJAX8.'?class=xthesaurusdef&function=xthesaurusdef_autocomplete&_silent=1&query_format='.$options['query_format'];
  142. $edit.='<script type="text/javascript" language="javascript">TZR.addAutoComplete("'.$url.'","'.$varid.'","'.$options['fmoid'].'",'.
  143. '"'.$this->table.'","'.$this->field.'","",TZR.autocompleteThesaurus);</script>';
  144. // calcul de l'arbo
  145. if ($options['query_format'] == XFieldDef::QUICKQUERY_FORMAT) {
  146. $rw = 0;
  147. $quickquery = 1;
  148. $tree = array('htmlFiltered' => '', 'html' => '
  149. <ul class="simpleTree quickquery treefiltered">
  150. <li class="root close" onclick="TZR.thesaurusClick(\''.$varid.'\', event)">
  151. <span><span>'.$this->label.'</span></span>
  152. <ul style="display:none" id="top'.$varid.'"></ul>
  153. </li>
  154. <li class="fin_float"></li>
  155. </ul>
  156. ');
  157. } else {
  158. $rw = $this->isAutorizedToAdd($options);
  159. $quickquery = 0;
  160. $tree = $this->getTree($value, $options, $varid, $mod, $rw, $fields_complement);
  161. }
  162. $edit.='<div id="treecontainer'.$varid.'" class="thesaurustree">'.$tree['htmlFiltered'].$tree['html'].'</div>';
  163. $edit.='<script type="text/javascript">
  164. jQuery("#treecontainer'.$varid.'").data({varid:"'.$varid.'", moid:"'.$options['fmoid'].'", xtable:"'.$this->table.'", field:"'.$this->field.'", rw:'.(int)$rw.',optimizewith:"'.$this->optimizewith.'",optimizevalues:"'.implode(' ',$fields_complement[$this->optimizewith]).'",quickquery:'.$quickquery.', reloadUrl:"'.TZR_AJAX8.'?class=xthesaurusdef&function=xthesaurusdef_loadtree&moid='.$options['fmoid'].'&table='.$this->table.'&field='.$this->field.'&varid='.$varid.'"});';
  165. if ($this->optimizewith)
  166. $edit.='TZR.activeThesaurus("'.$varid.'","'.$this->optimizewith.'");';
  167. if($this->compulsory){
  168. $color=XIni::get('error_color');
  169. $edit.='TZR.addValidator(["'.$varid.'","","'.addslashes($this->label).'","'.$color.'","XThesaurusDef"]);';
  170. }
  171. $edit.='</script></div>';
  172. $r->varid=$varid;
  173. $r->html=$edit;
  174. return $r;
  175. }
  176. /// Calcule le menu
  177. function getTree($value, $options, $varid, $mod=null, $rw, $fields_complement=array()) {
  178. $lang_data = XShell::getLangData();
  179. $stmt = selectQuery('select distinct '.$this->fparent.', KOID, '.$this->flabel.' from '.$this->target.' where LANG="'.$lang_data.'" order by '.$this->flabel);
  180. if (!$stmt)
  181. return;
  182. $items = $stmt->fetchAll(PDO::FETCH_GROUP);
  183. $nbItems = $stmt->rowCount();
  184. $used_values=null;
  185. // dans le cas d'une contrainte
  186. if ($this->optimizewith) {
  187. if (is_array($fields_complement[$this->optimizewith])) // champ multivalué déjà my_edité
  188. $filteringValues = array_keys($fields_complement[$this->optimizewith]);
  189. else
  190. $filteringValues = preg_split('/\|\|/', $fields_complement[$this->optimizewith], 0, PREG_SPLIT_NO_EMPTY);
  191. if (!empty($filteringValues)) {
  192. foreach ($filteringValues as $filteringValue)
  193. $_filter[] = 'instr('.$this->optimizewith.', "'.$filteringValue.'")';
  194. $filter = '(' . implode(' or ', $_filter) . ')';
  195. $used_values = $this->_getUsedValues($filter, null, $options);
  196. }
  197. }
  198. // calcul des droits du module source
  199. if ($mod && $mod->object_sec) {
  200. $modLevels = $GLOBALS['XUSER']->getObjectAccess($mod, XShell::getLangData());
  201. $_secObjects = $GLOBALS['XUSER']::getObjectsWithSec($mod, XUser::get_current_user_uid());
  202. $rights = $GLOBALS['XUSER']->getObjectsAccess($mod, XShell::getLangData(), $_secObjects);
  203. foreach ($_secObjects as $i => $oid)
  204. $secObjects[$oid] = $rights[$i];
  205. $secObjects['default'] = $modLevels[0];
  206. } else
  207. $secObjects = null;
  208. $options['withSiblings'] = XShell::admini_mode() && !@$options['quickquery'];
  209. $tree = $this->_getTree(@$options['top'], $items, $secObjects, $value, $used_values, $options, $varid);
  210. // html de l'arbo
  211. if (@$options['top'])
  212. return array('html' => $this->_makeHtml($tree, $varid, 20));
  213. if (!$options['justFiltered'])
  214. $htmlFull = $this->_makeHtml($tree, $varid, ($nbItems > 500) ? 1 : 10);
  215. if ($this->optimizewith)
  216. $_htmlFiltered = $this->_makeHtmlFiltered($tree, $varid, 10);//$options['justFiltered'] ? 10 : 0);
  217. if ($this->optimizewith) {
  218. $htmlFiltered = '
  219. <ul class="simpleTree treefiltered" '.($_htmlFiltered ? '' : ' style="display:none"').'>
  220. <li class="root close" onclick="TZR.thesaurusClick(\''.$varid.'\', event)">
  221. <span><span>'.$this->label.' - '.XLabels::getSysLabel('xfielddef','filtered').'</span></span>
  222. <ul style="display:none" id="topfiltered'.$varid.'">'.
  223. $_htmlFiltered . '
  224. </ul>
  225. </li>
  226. <li class="fin_float"></li>
  227. </ul>';
  228. }
  229. if (@$options['quickquery']) {
  230. $html = $htmlFull;
  231. } elseif (!$options['justFiltered']) {
  232. $html = '
  233. <ul class="simpleTree full">
  234. <li class="root close" onclick="TZR.thesaurusClick(\''.$varid.'\', event)">
  235. <span><span>'.$this->label.'</span></span>
  236. <ul style="display:none" id="top'.$varid.'">'.
  237. $htmlFull . '
  238. </ul>
  239. </li>
  240. <li class="fin_float"></li>
  241. </ul>';
  242. }
  243. return array('html' => $html, 'htmlFiltered' => $htmlFiltered);
  244. }
  245. /// Construit l'arborescence
  246. private function _getTree($oid, &$items, $secObjects, $value, $used_values, $options) {
  247. foreach ($items[$oid] as $i => $item) {
  248. $item_oid = $item['KOID'];
  249. // Filtre sur les droits du module source
  250. if ($secObjects && isset($secObjects[$item_oid]) && !isset($secObjects[$item_oid]['ro']))
  251. continue;
  252. // les items dans le nom commencent par un . sont cachés
  253. if (substr($item[$this->flabel],0,1)=='.')
  254. continue;
  255. $item['selected'] = isset($value[$item_oid]);
  256. $item['active'] = $item['selected'] || isset($used_values[$item_oid]);
  257. if (isset($items[$item_oid])){
  258. $item['subtree'] = $this->_getTree($item_oid, $items, $secObjects, $value, $used_values, $options);
  259. $item['active'] |= $item['subtree']['active'];
  260. }
  261. // prendre les fils des noeuds selectionnés
  262. if ($item['selected'] && $item['subtree'] && !$item['subtree']['active']) {
  263. $item['subtree']['getAll'] = true;
  264. }
  265. $tree['items'][] = $item;
  266. if ($item['active'])
  267. $tree['activeItems'][] = $item;
  268. // prendre les freres des feuilles actives
  269. if ($options['withSiblings'] && $item['active'] && !isset($item['subtree'])) {
  270. $tree['getAll'] = true;
  271. }
  272. $tree['active'] |= $item['active'];
  273. }
  274. $tree['oid'] = $oid;
  275. return $tree;
  276. }
  277. /// Génère le html
  278. private function _makeHtml(&$tree, $varid, $depth=0) {
  279. if (empty($tree) || !$depth)
  280. return '';
  281. $html = '';
  282. $last = count($tree['items']) -1;
  283. foreach ($tree['items'] as $i => &$item) {
  284. $html .= ' <li class="line">&nbsp;</li><li tzroid="'.$item['KOID'].'" class="'.(isset($item['subtree']) ? 'folder close' : 'doc').($i == $last?' last':'').'"><div style="position:absolute;"><div class="ico"></div></div><img class="trigger" src="/tzr/templates/ico/jtree/spacer.gif" border="0" style="float:left;_float:none"><span class="text"><span'.($item['selected'] ? ' class="selected"' : '').'>'.$item[$this->flabel].'</span></span>';
  285. if (isset($item['subtree'])) {
  286. $html .= '<ul style="display:none">'.$this->_makeHtml($item['subtree'], $varid, $depth-1).'</ul>';
  287. }
  288. $html .= '</li>';
  289. }
  290. unset($item);
  291. $html .= '<li class="line-last">&nbsp;</li>';
  292. return $html;
  293. }
  294. /// Génère le html des entrées filtrées
  295. private function _makeHtmlFiltered($tree, $varid, $depth=0) {
  296. if (empty($tree))
  297. return '';
  298. $last = count($tree['activeItems']) -1;
  299. foreach ($tree['activeItems'] as $i => $item) {
  300. if ($item['subtree']) {
  301. if ($item['subtree']['getAll'])
  302. $subHtml = $this->_makeHtml($item['subtree'], $varid, $depth-1);
  303. else
  304. $subHtml = $this->_makeHtmlFiltered($item['subtree'], $varid, $depth-1);
  305. } else
  306. $subHtml = '';
  307. $html .= ' <li class="line">&nbsp;</li><li tzroid="'.$item['KOID'].'" class="'.($item['subtree']['activeItems'] ? 'folder close' : 'doc').($i == $last?' last':'').'"><div style="position:absolute;"><div class="ico"></div></div><img class="trigger" src="/tzr/templates/ico/jtree/spacer.gif" border="0" style="float:left;_float:none"><span class="text"><span'.($item['selected'] ? ' class="selected"' : '').'>'.$item[$this->flabel].'</span></span>';
  308. if ($item['subtree']) {
  309. $html .= '<ul style="display:none">'.($depth>0 ? $subHtml :'').'</ul>';
  310. }
  311. $html .= '</li>';
  312. }
  313. if ($html)
  314. return $html . '<li class="line-last">&nbsp;</li>';
  315. else
  316. return '';
  317. }
  318. /// Retourn vrai si l'utilisateur peut créer de nouveau mots clé à la volée
  319. function isAutorizedToAdd(&$options){
  320. if(!empty($options['query_format']) || empty($this->flabel) || !$this->quickadd) return false;
  321. return parent::isAutorizedToAdd($options);
  322. }
  323. function my_quickquery($value,$options=NULL) {
  324. $r=$this->my_query($value,$options);
  325. $r->html.='<input type="hidden" value="'.$this->field.'" name="_FIELDS['.$this->field.']">';
  326. return $r;
  327. }
  328. function my_query($value,&$options){
  329. $fname=(isset($options['fieldname'])?$options['fieldname']:$this->field);
  330. $hiddenname=$fname.'_HID';
  331. $options['fieldname']=$fname;
  332. if(is_array($value)){
  333. $keys=array_keys($value);
  334. if(!Kernel::isAKoid($keys[0])) $value=array_flip($value);
  335. }
  336. if ($this->optimizewith) {
  337. foreach ($options['fields_complement']['_FIELDS'] as $id => $fieldname)
  338. if ($fieldname == $this->optimizewith) {
  339. $idx = $id;
  340. break;
  341. }
  342. if ($idx)
  343. $optimizeValues = @array_filter($options['fields_complement'][$idx]);
  344. }
  345. return $this->my_edit($value,$options, array($this->optimizewith => $optimizeValues));
  346. }
  347. function post_query(&$o,$options){
  348. if(is_array($o->value)){
  349. $v1op=$o->op;
  350. if($v1op!='OR' && $v1op!='NONE') $v1op='AND';
  351. $rq=array();
  352. foreach($o->value as $v){
  353. if(empty($v)) continue;
  354. $oids=$this->getSons($v,$options,false);
  355. $oids[$v]='';
  356. $rq2=array();
  357. foreach($oids as $oid=>$foo){
  358. $tmp=(object)array('op'=>'OR','value'=>$oid);
  359. parent::post_query($tmp,$options);
  360. $rq2[]=$tmp->rq;
  361. }
  362. $rq[]='('.implode('OR',$rq2).')';
  363. }
  364. if (empty($rq))
  365. $o->rq='';
  366. elseif ($v1op == 'NONE')
  367. $o->rq='(!'.implode(' AND !',$rq).')';
  368. else
  369. $o->rq='('.implode($v1op,$rq).')';
  370. return $o;
  371. }
  372. return parent::post_query($o,$options);
  373. }
  374. }
  375. function xthesaurusdef_loadtree() {
  376. activeSec();
  377. $moid=$_REQUEST['moid'];
  378. $table=$_REQUEST['table'];
  379. $field=$_REQUEST['field'];
  380. if(empty($moid) || empty($table) || empty($field)) die();
  381. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  382. $ofield=$xds->getField($field);
  383. if($ofield->sourcemodule){
  384. $smod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
  385. $ok=$smod->secure('',':ro');
  386. }else{
  387. $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
  388. $ok=$mod->secure('',':list');
  389. }
  390. if(!$ok) die('');
  391. $value = array_flip($_REQUEST['value']);
  392. $fields_complement = array($ofield->optimizewith => array_flip($_REQUEST['filter']));
  393. $options=array('fmoid'=>$moid, 'justFiltered' => (@$_REQUEST['justfiltered'] && @$_REQUEST['filter']));
  394. $rw = $ofield->isAutorizedToAdd($options);
  395. $options['top'] = $_REQUEST['top'];
  396. $options['quickquery'] = @$_REQUEST['quickquery'];
  397. $tree=$ofield->getTree($value,$options,$_REQUEST['varid'],$smod,$rw,$fields_complement);
  398. if ($options['justFiltered'])
  399. die($tree['htmlFiltered']);
  400. else
  401. die($tree['html']);
  402. }
  403. function xthesaurusdef_delvalue(){
  404. activeSec();
  405. $moid=$_REQUEST['moid'];
  406. $table=$_REQUEST['table'];
  407. $field=$_REQUEST['field'];
  408. $oid=$_REQUEST['oid'];
  409. if(empty($moid) || empty($table) || empty($field) || empty($oid)) die();
  410. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  411. $ofield=$xds->getField($field);
  412. if($ofield->sourcemodule){
  413. $mod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
  414. $ok=$mod->secure($oid,':rw');
  415. }else{
  416. $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
  417. $ok=$mod->secure('',':rwv');
  418. }
  419. if(!$ok) die(json_encode(''));
  420. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ofield->target);
  421. $rs=selectQuery('select KOID from '.$ofield->target.' where KOID="'.$oid.'" or '.$ofield->fparent.'="'.$oid.'"');
  422. while($rs && $ors=$rs->fetch()) $xds->del(array('oid'=>$ors['KOID'],'tplentry'=>TZR_RETURN_DATA));
  423. die('ok');
  424. }
  425. function xthesaurusdef_editvalue(){
  426. activeSec();
  427. $moid=$_REQUEST['moid'];
  428. $table=$_REQUEST['table'];
  429. $field=$_REQUEST['field'];
  430. $oid=$_REQUEST['oid'];
  431. $value=$_REQUEST['value'];
  432. if(empty($moid) || empty($table) || empty($field) || empty($oid)) die();
  433. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  434. $ofield=$xds->getField($field);
  435. if($ofield->sourcemodule){
  436. $mod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
  437. $ok=$mod->secure($oid,':rw');
  438. }else{
  439. $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
  440. $ok=$mod->secure('',':rwv');
  441. }
  442. if(!$ok) die();
  443. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ofield->target);
  444. $xds->procEdit(array('oid'=>$oid,$ofield->flabel=>$value,'tplentry'=>TZR_RETURN_DATA));
  445. die('ok');
  446. }
  447. function xthesaurusdef_addvalue(){
  448. activeSec();
  449. $moid=$_REQUEST['moid'];
  450. $table=$_REQUEST['table'];
  451. $field=$_REQUEST['field'];
  452. $parentoid=$_REQUEST['parentoid'];
  453. $value=$_REQUEST['value'];
  454. if(empty($moid) || empty($table) || empty($field) || empty($value)) die();
  455. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  456. $ofield=$xds->getField($field);
  457. if($ofield->sourcemodule){
  458. $mod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
  459. $ok=$mod->secure('',':rw');
  460. }else{
  461. $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
  462. $ok=$mod->secure('',':rwv');
  463. }
  464. if(!$ok) die();
  465. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ofield->target);
  466. $ret=$xds->procInput(array($ofield->fparent=>$parentoid,$ofield->flabel=>$value,'tplentry'=>TZR_RETURN_DATA));
  467. die($ret['oid']);
  468. }
  469. function xthesaurusdef_copyvalue(){
  470. activeSec();
  471. $moid=$_REQUEST['moid'];
  472. $table=$_REQUEST['table'];
  473. $field=$_REQUEST['field'];
  474. $parentoid=$_REQUEST['parentoid'];
  475. $value=$_REQUEST['value'];
  476. if(empty($moid) || empty($table) || empty($field) || empty($value)) die();
  477. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  478. $ofield=$xds->getField($field);
  479. if($ofield->sourcemodule){
  480. $mod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
  481. $ok=$mod->secure($value,':rw');
  482. }else{
  483. $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
  484. $ok=$mod->secure('',':rwv');
  485. }
  486. if(!$ok) die();
  487. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ofield->target);
  488. $ret=$xds->duplicate(array('oid'=>$value));
  489. updateQuery('update '.$ofield->target.' set '.$ofield->fparent.'="'.$parentoid.'" where KOID="'.$ret.'"');
  490. die($ret);
  491. }
  492. function xthesaurusdef_cutvalue(){
  493. activeSec();
  494. $moid=$_REQUEST['moid'];
  495. $table=$_REQUEST['table'];
  496. $field=$_REQUEST['field'];
  497. $parentoid=$_REQUEST['parentoid'];
  498. $value=$_REQUEST['value'];
  499. if(empty($moid) || empty($table) || empty($field) || empty($value)) die();
  500. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  501. $ofield=$xds->getField($field);
  502. if($ofield->sourcemodule){
  503. $mod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
  504. $ok=$mod->secure($value,':rw');
  505. }else{
  506. $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
  507. $ok=$mod->secure('',':rwv');
  508. }
  509. if(!$ok) die();
  510. $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ofield->target);
  511. updateQuery('update '.$ofield->target.' set '.$ofield->fparent.'="'.$parentoid.'" where KOID="'.$value.'"');
  512. die($value);
  513. }
  514. function xthesaurusdef_autocomplete() {
  515. require_once('class.xlinkdef.inc');
  516. $r=&xlinkdef_autocomplete(true);
  517. $ofield=$r['field'];
  518. $suggestions=$r['suggestions'];
  519. foreach($suggestions as $koid=>$value){
  520. $parents=$ofield->getParents($koid);
  521. $parents[$koid]=$value;
  522. echo implode(' > ',$parents)."|$koid\n";
  523. }
  524. if(count($suggestions)==0) echo XLabels::getSysLabel('xfielddef','no_result')."\n";
  525. elseif($ret['state']=='toomuch') echo (XLabels::getSysLabel('xfielddef','too_many_results'))."\n";
  526. return null;
  527. }
  528. ?>