/class.xthesaurusdef.inc
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
- <?php
- class XThesaurusDef extends XLinkDef{
- public $query_formats=array('classic');
- public $quickadd=true;
- public $flabel=NULL;
- public $fparent=NULL;
- public $indexable=NULL;
- function __construct($ar=NULL){
- parent::__construct($ar);
- }
- function initOptions() {
- XFieldDef::initOptions();
- $this->_options->delOpt('aliasmodule');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','sourcemodule'),'sourcemodule','module',array('emptyok'=>true));
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','xthesaurus_label'),"flabel","field",
- array('table'=>$this->target,'compulsory'=>false,'type'=>'XShortTextDef'));
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','xthesaurus_parent'),"fparent","field",
- array('table'=>$this->target,'compulsory'=>true,'type'=>XFieldDef::getObjectLinkTypes()));
- $this->_options->setOpt('Optimiser en fonction du champ',"optimizewith","field",
- array('table'=>$this->table,'compulsory'=>false,'type'=>array('XLinkDef', 'XThesaurusDef', 'XShortTextDef')));
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef','xthesaurus_quickadd'),"quickadd","boolean");
- $querygroup=XLabels::getSysLabel('general','query','text');
- $this->_options->setOpt(XLabels::getSysLabel('xfielddef.indexable'), 'indexable', 'boolean', NULL, true, $querygroup);
- }
- /// Recupere la liste des ascendants d'un oid
- function &getParents($value,$options,$gethtml=true){
- $lang_data=XShell::getLangData();
- $parents=array();
- if($gethtml) list($myliste,$my_flist,$first)=$this->getFieldList($options);
- if(empty($value)) return array();
- elseif(!is_array($value)) $v=array($value);
- else $v=$value;
- do{
- $rs=selectQuery('SELECT * FROM '.$this->target.' WHERE KOID IN ("'.implode('","',$v).'") AND LANG="'.$lang_data.'"');
- $v=array();
- while($rs && $ors=$rs->fetch()){
- $parents[$ors['KOID']]=($gethtml?$this->format_display($myliste,$ors,$p1):true);
- $v[]=$ors[$this->fparent];
- }
- }while(!empty($v));
- $parents=array_reverse($parents);
- return $parents;
- }
-
- /// Recupere la liste des descendants d'un ou pls oid
- function &getSons($value,$options,$gethtml=true){
- $lang_data=XShell::getLangData();
- $sons=array();
- if($gethtml) list($myliste,$my_flist,$first)=$this->getFieldList($options);
- if(empty($value)) return array();
- elseif(!is_array($value)) $v=array($value);
- else $v=$value;
- do{
- $rs=selectQuery('SELECT * FROM '.$this->target.' WHERE '.$this->fparent.' IN ("'.implode('","',$v).'") AND LANG="'.$lang_data.'"');
- $v=array();
- while($rs && $ors=$rs->fetch()){
- $sons[$ors['KOID']]=($gethtml?$this->format_display($myliste,$ors,$p1):true);
- $v[]=$ors['KOID'];
- }
- }while(!empty($v));
- return $sons;
- }
- function my_display($value,&$options){
- static $cache=array();
- $this->modsUsingTable=0;
- if($this->target==TZR_DEFAULT_TARGET || !XDataSource::sourceExists($this->target) || empty($this->fparent)) {
- $r=$this->_newXFieldVal($options);
- $r->html='';
- return $r;
- }
- $r=parent::my_display($value,$options);
- if(!empty($r->raw)){
- $r->html=@$cache[$r->raw];
- if($r->html===null){
- $parents=$this->getParents($value,$options);
- $parents[$r->raw]=$r->title;
- $cache[$r->raw]=$r->html=implode(' > ',$parents);
- }
- }
- return $r;
- }
- function my_import($value,&$options){
- if(empty($options['srcField'])){
- $options['srcField']=$this->flabel;
- }
- return parent::my_import($value,$options);
- }
- function my_edit($value,&$options,$fields_complement){
- $lang_data=XShell::getLangData();
- $r=$this->_newXFieldVal($options);
- $r->raw=$value;
- if($this->target==TZR_DEFAULT_TARGET || !XDataSource::sourceExists($this->target) || empty($this->fparent)) {
- $r->html='';
- return $r;
- }
- if($this->sourcemodule){
- $mod=&XModule::objectFactory(array('moid'=>$this->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
- if($mod->object_sec && !$mod->secure('',':list') || !$mod->object_sec && !$mod->secure('',':ro')) return $r;
- }
- if(isset($options['intable'])) {
- $o=$options['intable'];
- $fname=$this->field.'['.$o.']';
- $hiddenname=$this->field.'_HID['.$o.']';
- } elseif(!empty($options['fieldname'])) {
- $fname=$options['fieldname'];
- $hiddenname=$options['fieldname'].'_HID';
- } else {
- $fname=$this->field;
- $hiddenname=$this->field.'_HID';
- }
- // Liste des champs de la cible
- list($myliste,$my_flist,$first)=$this->getFieldList($options);
- // Ligne de base
- $varid=uniqid('v');
- $delico=XLabels::getSysLabel('general','delete');
- $edit='<div id="div'.$varid.'">';
- if($this->get_multivalued() && $options['query_format']){
- $edit.='<input class="radio" type="radio" name="'.$fname.'_op" value="AND" id="'.$varid.'-AND"'.((empty($options['op']) || $options['op']=='AND')?' checked':'').'>'.
- '<label for="'.$varid.'-AND">'.XLabels::getSysLabel('xfielddef.xlinkdef_allterms').'</label><br>'.
- '<input class="radio" type="radio" name="'.$fname.'_op" value="OR" id="'.$varid.'-OR"'.($options['op']=='OR'?' checked':'').'>'.
- '<label for="'.$varid.'-OR">'.XLabels::getSysLabel('xfielddef.xlinkdef_leastaterm').'</label><br>'.
- '<input class="radio" type="radio" name="'.$fname.'_op" value="NONE" id="'.$varid.'-NONE"'.($options['op']=='NONE'?' checked':'').'>'.
- '<label for="'.$varid.'-NONE">'.XLabels::getSysLabel('xfielddef.xlinkdef_noterm').'</label><br>';
- }
- $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>';
- // Affiche les valeurs en cours
- if(!empty($value)){
- if(!is_array($value)) $value=array($value=>'1');
- $rs=selectQuery('SELECT DISTINCT '.$my_flist.' FROM '.$this->target.' WHERE KOID IN ("'.implode('","',array_keys($value)).'") '.
- 'AND LANG="'.$lang_data.'"'.($first?' ORDER BY '.$first:''));
- while($ors=$rs->fetch()){
- if($mod && $mod->object_sec && !$mod->secure($ors['KOID'],':ro')) continue;
- $parents=$this->getParents($ors['KOID'],$options);
- $parents[$ors['KOID']]=$this->format_display($myliste,$ors,$p1);
- $display=implode(' > ',$parents);
- $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>';
- }
- }
- $edit.='</table>';
- // Ajout d'un input d'autompletion pour une saisie directe
- $edit.='<input autocomplete="off" id="_INPUT'.$varid.'" size="30" type="text" value="" class="tzr-link">';
- $url=TZR_AJAX8.'?class=xthesaurusdef&function=xthesaurusdef_autocomplete&_silent=1&query_format='.$options['query_format'];
- $edit.='<script type="text/javascript" language="javascript">TZR.addAutoComplete("'.$url.'","'.$varid.'","'.$options['fmoid'].'",'.
- '"'.$this->table.'","'.$this->field.'","",TZR.autocompleteThesaurus);</script>';
-
- // calcul de l'arbo
- if ($options['query_format'] == XFieldDef::QUICKQUERY_FORMAT) {
- $rw = 0;
- $quickquery = 1;
- $tree = array('htmlFiltered' => '', 'html' => '
- <ul class="simpleTree quickquery treefiltered">
- <li class="root close" onclick="TZR.thesaurusClick(\''.$varid.'\', event)">
- <span><span>'.$this->label.'</span></span>
- <ul style="display:none" id="top'.$varid.'"></ul>
- </li>
- <li class="fin_float"></li>
- </ul>
- ');
- } else {
- $rw = $this->isAutorizedToAdd($options);
- $quickquery = 0;
- $tree = $this->getTree($value, $options, $varid, $mod, $rw, $fields_complement);
- }
- $edit.='<div id="treecontainer'.$varid.'" class="thesaurustree">'.$tree['htmlFiltered'].$tree['html'].'</div>';
- $edit.='<script type="text/javascript">
- 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.'"});';
- if ($this->optimizewith)
- $edit.='TZR.activeThesaurus("'.$varid.'","'.$this->optimizewith.'");';
- if($this->compulsory){
- $color=XIni::get('error_color');
- $edit.='TZR.addValidator(["'.$varid.'","","'.addslashes($this->label).'","'.$color.'","XThesaurusDef"]);';
- }
- $edit.='</script></div>';
- $r->varid=$varid;
- $r->html=$edit;
- return $r;
- }
- /// Calcule le menu
- function getTree($value, $options, $varid, $mod=null, $rw, $fields_complement=array()) {
- $lang_data = XShell::getLangData();
- $stmt = selectQuery('select distinct '.$this->fparent.', KOID, '.$this->flabel.' from '.$this->target.' where LANG="'.$lang_data.'" order by '.$this->flabel);
- if (!$stmt)
- return;
- $items = $stmt->fetchAll(PDO::FETCH_GROUP);
- $nbItems = $stmt->rowCount();
- $used_values=null;
- // dans le cas d'une contrainte
- if ($this->optimizewith) {
- if (is_array($fields_complement[$this->optimizewith])) // champ multivalué déjà my_edité
- $filteringValues = array_keys($fields_complement[$this->optimizewith]);
- else
- $filteringValues = preg_split('/\|\|/', $fields_complement[$this->optimizewith], 0, PREG_SPLIT_NO_EMPTY);
- if (!empty($filteringValues)) {
- foreach ($filteringValues as $filteringValue)
- $_filter[] = 'instr('.$this->optimizewith.', "'.$filteringValue.'")';
- $filter = '(' . implode(' or ', $_filter) . ')';
- $used_values = $this->_getUsedValues($filter, null, $options);
- }
- }
- // calcul des droits du module source
- if ($mod && $mod->object_sec) {
- $modLevels = $GLOBALS['XUSER']->getObjectAccess($mod, XShell::getLangData());
- $_secObjects = $GLOBALS['XUSER']::getObjectsWithSec($mod, XUser::get_current_user_uid());
- $rights = $GLOBALS['XUSER']->getObjectsAccess($mod, XShell::getLangData(), $_secObjects);
- foreach ($_secObjects as $i => $oid)
- $secObjects[$oid] = $rights[$i];
- $secObjects['default'] = $modLevels[0];
- } else
- $secObjects = null;
- $options['withSiblings'] = XShell::admini_mode() && !@$options['quickquery'];
- $tree = $this->_getTree(@$options['top'], $items, $secObjects, $value, $used_values, $options, $varid);
- // html de l'arbo
- if (@$options['top'])
- return array('html' => $this->_makeHtml($tree, $varid, 20));
- if (!$options['justFiltered'])
- $htmlFull = $this->_makeHtml($tree, $varid, ($nbItems > 500) ? 1 : 10);
- if ($this->optimizewith)
- $_htmlFiltered = $this->_makeHtmlFiltered($tree, $varid, 10);//$options['justFiltered'] ? 10 : 0);
- if ($this->optimizewith) {
- $htmlFiltered = '
- <ul class="simpleTree treefiltered" '.($_htmlFiltered ? '' : ' style="display:none"').'>
- <li class="root close" onclick="TZR.thesaurusClick(\''.$varid.'\', event)">
- <span><span>'.$this->label.' - '.XLabels::getSysLabel('xfielddef','filtered').'</span></span>
- <ul style="display:none" id="topfiltered'.$varid.'">'.
- $_htmlFiltered . '
- </ul>
- </li>
- <li class="fin_float"></li>
- </ul>';
- }
- if (@$options['quickquery']) {
- $html = $htmlFull;
- } elseif (!$options['justFiltered']) {
- $html = '
- <ul class="simpleTree full">
- <li class="root close" onclick="TZR.thesaurusClick(\''.$varid.'\', event)">
- <span><span>'.$this->label.'</span></span>
- <ul style="display:none" id="top'.$varid.'">'.
- $htmlFull . '
- </ul>
- </li>
- <li class="fin_float"></li>
- </ul>';
- }
- return array('html' => $html, 'htmlFiltered' => $htmlFiltered);
- }
- /// Construit l'arborescence
- private function _getTree($oid, &$items, $secObjects, $value, $used_values, $options) {
- foreach ($items[$oid] as $i => $item) {
- $item_oid = $item['KOID'];
- // Filtre sur les droits du module source
- if ($secObjects && isset($secObjects[$item_oid]) && !isset($secObjects[$item_oid]['ro']))
- continue;
- // les items dans le nom commencent par un . sont cachés
- if (substr($item[$this->flabel],0,1)=='.')
- continue;
- $item['selected'] = isset($value[$item_oid]);
- $item['active'] = $item['selected'] || isset($used_values[$item_oid]);
- if (isset($items[$item_oid])){
- $item['subtree'] = $this->_getTree($item_oid, $items, $secObjects, $value, $used_values, $options);
- $item['active'] |= $item['subtree']['active'];
- }
- // prendre les fils des noeuds selectionnés
- if ($item['selected'] && $item['subtree'] && !$item['subtree']['active']) {
- $item['subtree']['getAll'] = true;
- }
- $tree['items'][] = $item;
- if ($item['active'])
- $tree['activeItems'][] = $item;
- // prendre les freres des feuilles actives
- if ($options['withSiblings'] && $item['active'] && !isset($item['subtree'])) {
- $tree['getAll'] = true;
- }
- $tree['active'] |= $item['active'];
- }
- $tree['oid'] = $oid;
- return $tree;
- }
- /// Génère le html
- private function _makeHtml(&$tree, $varid, $depth=0) {
- if (empty($tree) || !$depth)
- return '';
- $html = '';
- $last = count($tree['items']) -1;
- foreach ($tree['items'] as $i => &$item) {
- $html .= ' <li class="line"> </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>';
- if (isset($item['subtree'])) {
- $html .= '<ul style="display:none">'.$this->_makeHtml($item['subtree'], $varid, $depth-1).'</ul>';
- }
- $html .= '</li>';
- }
- unset($item);
- $html .= '<li class="line-last"> </li>';
- return $html;
- }
- /// Génère le html des entrées filtrées
- private function _makeHtmlFiltered($tree, $varid, $depth=0) {
- if (empty($tree))
- return '';
- $last = count($tree['activeItems']) -1;
- foreach ($tree['activeItems'] as $i => $item) {
- if ($item['subtree']) {
- if ($item['subtree']['getAll'])
- $subHtml = $this->_makeHtml($item['subtree'], $varid, $depth-1);
- else
- $subHtml = $this->_makeHtmlFiltered($item['subtree'], $varid, $depth-1);
- } else
- $subHtml = '';
- $html .= ' <li class="line"> </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>';
- if ($item['subtree']) {
- $html .= '<ul style="display:none">'.($depth>0 ? $subHtml :'').'</ul>';
- }
- $html .= '</li>';
- }
- if ($html)
- return $html . '<li class="line-last"> </li>';
- else
- return '';
- }
- /// Retourn vrai si l'utilisateur peut créer de nouveau mots clé à la volée
- function isAutorizedToAdd(&$options){
- if(!empty($options['query_format']) || empty($this->flabel) || !$this->quickadd) return false;
- return parent::isAutorizedToAdd($options);
- }
- function my_quickquery($value,$options=NULL) {
- $r=$this->my_query($value,$options);
- $r->html.='<input type="hidden" value="'.$this->field.'" name="_FIELDS['.$this->field.']">';
- return $r;
- }
- function my_query($value,&$options){
- $fname=(isset($options['fieldname'])?$options['fieldname']:$this->field);
- $hiddenname=$fname.'_HID';
- $options['fieldname']=$fname;
- if(is_array($value)){
- $keys=array_keys($value);
- if(!Kernel::isAKoid($keys[0])) $value=array_flip($value);
- }
- if ($this->optimizewith) {
- foreach ($options['fields_complement']['_FIELDS'] as $id => $fieldname)
- if ($fieldname == $this->optimizewith) {
- $idx = $id;
- break;
- }
- if ($idx)
- $optimizeValues = @array_filter($options['fields_complement'][$idx]);
- }
- return $this->my_edit($value,$options, array($this->optimizewith => $optimizeValues));
- }
- function post_query(&$o,$options){
- if(is_array($o->value)){
- $v1op=$o->op;
- if($v1op!='OR' && $v1op!='NONE') $v1op='AND';
- $rq=array();
- foreach($o->value as $v){
- if(empty($v)) continue;
- $oids=$this->getSons($v,$options,false);
- $oids[$v]='';
- $rq2=array();
- foreach($oids as $oid=>$foo){
- $tmp=(object)array('op'=>'OR','value'=>$oid);
- parent::post_query($tmp,$options);
- $rq2[]=$tmp->rq;
- }
- $rq[]='('.implode('OR',$rq2).')';
- }
- if (empty($rq))
- $o->rq='';
- elseif ($v1op == 'NONE')
- $o->rq='(!'.implode(' AND !',$rq).')';
- else
- $o->rq='('.implode($v1op,$rq).')';
- return $o;
- }
- return parent::post_query($o,$options);
- }
- }
- function xthesaurusdef_loadtree() {
- activeSec();
- $moid=$_REQUEST['moid'];
- $table=$_REQUEST['table'];
- $field=$_REQUEST['field'];
- if(empty($moid) || empty($table) || empty($field)) die();
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
- $ofield=$xds->getField($field);
- if($ofield->sourcemodule){
- $smod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
- $ok=$smod->secure('',':ro');
- }else{
- $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure('',':list');
- }
- if(!$ok) die('');
- $value = array_flip($_REQUEST['value']);
- $fields_complement = array($ofield->optimizewith => array_flip($_REQUEST['filter']));
- $options=array('fmoid'=>$moid, 'justFiltered' => (@$_REQUEST['justfiltered'] && @$_REQUEST['filter']));
- $rw = $ofield->isAutorizedToAdd($options);
- $options['top'] = $_REQUEST['top'];
- $options['quickquery'] = @$_REQUEST['quickquery'];
- $tree=$ofield->getTree($value,$options,$_REQUEST['varid'],$smod,$rw,$fields_complement);
- if ($options['justFiltered'])
- die($tree['htmlFiltered']);
- else
- die($tree['html']);
- }
- function xthesaurusdef_delvalue(){
- activeSec();
- $moid=$_REQUEST['moid'];
- $table=$_REQUEST['table'];
- $field=$_REQUEST['field'];
- $oid=$_REQUEST['oid'];
- if(empty($moid) || empty($table) || empty($field) || empty($oid)) die();
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
- $ofield=$xds->getField($field);
- if($ofield->sourcemodule){
- $mod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure($oid,':rw');
- }else{
- $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure('',':rwv');
- }
- if(!$ok) die(json_encode(''));
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ofield->target);
- $rs=selectQuery('select KOID from '.$ofield->target.' where KOID="'.$oid.'" or '.$ofield->fparent.'="'.$oid.'"');
- while($rs && $ors=$rs->fetch()) $xds->del(array('oid'=>$ors['KOID'],'tplentry'=>TZR_RETURN_DATA));
- die('ok');
- }
- function xthesaurusdef_editvalue(){
- activeSec();
- $moid=$_REQUEST['moid'];
- $table=$_REQUEST['table'];
- $field=$_REQUEST['field'];
- $oid=$_REQUEST['oid'];
- $value=$_REQUEST['value'];
- if(empty($moid) || empty($table) || empty($field) || empty($oid)) die();
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
- $ofield=$xds->getField($field);
- if($ofield->sourcemodule){
- $mod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure($oid,':rw');
- }else{
- $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure('',':rwv');
- }
- if(!$ok) die();
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ofield->target);
- $xds->procEdit(array('oid'=>$oid,$ofield->flabel=>$value,'tplentry'=>TZR_RETURN_DATA));
- die('ok');
- }
- function xthesaurusdef_addvalue(){
- activeSec();
- $moid=$_REQUEST['moid'];
- $table=$_REQUEST['table'];
- $field=$_REQUEST['field'];
- $parentoid=$_REQUEST['parentoid'];
- $value=$_REQUEST['value'];
- if(empty($moid) || empty($table) || empty($field) || empty($value)) die();
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
- $ofield=$xds->getField($field);
- if($ofield->sourcemodule){
- $mod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure('',':rw');
- }else{
- $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure('',':rwv');
- }
- if(!$ok) die();
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ofield->target);
- $ret=$xds->procInput(array($ofield->fparent=>$parentoid,$ofield->flabel=>$value,'tplentry'=>TZR_RETURN_DATA));
- die($ret['oid']);
- }
- function xthesaurusdef_copyvalue(){
- activeSec();
- $moid=$_REQUEST['moid'];
- $table=$_REQUEST['table'];
- $field=$_REQUEST['field'];
- $parentoid=$_REQUEST['parentoid'];
- $value=$_REQUEST['value'];
- if(empty($moid) || empty($table) || empty($field) || empty($value)) die();
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
- $ofield=$xds->getField($field);
- if($ofield->sourcemodule){
- $mod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure($value,':rw');
- }else{
- $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure('',':rwv');
- }
- if(!$ok) die();
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ofield->target);
- $ret=$xds->duplicate(array('oid'=>$value));
- updateQuery('update '.$ofield->target.' set '.$ofield->fparent.'="'.$parentoid.'" where KOID="'.$ret.'"');
- die($ret);
- }
- function xthesaurusdef_cutvalue(){
- activeSec();
- $moid=$_REQUEST['moid'];
- $table=$_REQUEST['table'];
- $field=$_REQUEST['field'];
- $parentoid=$_REQUEST['parentoid'];
- $value=$_REQUEST['value'];
- if(empty($moid) || empty($table) || empty($field) || empty($value)) die();
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
- $ofield=$xds->getField($field);
- if($ofield->sourcemodule){
- $mod=&XModule::objectFactory(array('moid'=>$ofield->sourcemodule,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure($value,':rw');
- }else{
- $mod=&XModule::objectFactory(array('moid'=>$moid,'tplentry'=>TZR_RETURN_DATA));
- $ok=$mod->secure('',':rwv');
- }
- if(!$ok) die();
- $xds=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ofield->target);
- updateQuery('update '.$ofield->target.' set '.$ofield->fparent.'="'.$parentoid.'" where KOID="'.$value.'"');
- die($value);
- }
- function xthesaurusdef_autocomplete() {
- require_once('class.xlinkdef.inc');
- $r=&xlinkdef_autocomplete(true);
- $ofield=$r['field'];
- $suggestions=$r['suggestions'];
- foreach($suggestions as $koid=>$value){
- $parents=$ofield->getParents($koid);
- $parents[$koid]=$value;
- echo implode(' > ',$parents)."|$koid\n";
- }
- if(count($suggestions)==0) echo XLabels::getSysLabel('xfielddef','no_result')."\n";
- elseif($ret['state']=='toomuch') echo (XLabels::getSysLabel('xfielddef','too_many_results'))."\n";
- return null;
- }
- ?>