/class.xdstable.inc
PHP | 1096 lines | 948 code | 60 blank | 88 comment | 186 complexity | 3aa0d5120c4201877aa3d7a327819cb6 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
- <?php
- /// Gestion d'une source de donnees de type 'table SQL'
- class XDSTable extends XDataSource {
- public $desc = array();
- public $orddesc = array();
- public $published_fields_in_admin=2;
- public $sendacopytofields=array();
- function __construct($boid=0) {
- XLogs::debug(get_class($this).'::construct: start '.$boid);
- $p= new XParam(array(),array());
- parent::__construct($boid);
- $this->title=XDataSource::$_boid[$boid]->MTXT;
- if(!isset(XDataSource::$_boid[$boid]))
- XShell::quit($boid.' unknown table ');
- else {
- $this->translatable = XDataSource::$_boid[$boid]->TRANSLATABLE;
- $this->log = XDataSource::$_boid[$boid]->LOG;
- $this->autotranslate = XDataSource::$_boid[$boid]->AUTO_TRANSLATE;
- }
- $this->_getDesc();
- XLabels::loadLabels('xdatasource');
- $verb='xdatasource('.$this->boid.')';
- XAudit::plusplus($verb);
- XLogs::debug(get_class($this).'::construct: end '.$boid.', '.$this->title);
- }
- /// Initialise les options de la source
- public function initOptions() {
- parent::initOptions();
- $group=XLabels::getSysLabel('xdstable','oidstruct');
- $this->_options->setOpt(XLabels::getSysLabel('xdstable','oidstruct1'),'oidstruct1','field',array('table'=>$this->base,'compulsory'=>false),null,$group);
- $this->_options->setOpt(XLabels::getSysLabel('xdstable','oidstruct2'),'oidstruct2','field',array('table'=>$this->base,'compulsory'=>false),null,$group);
- $this->_options->setOpt(XLabels::getSysLabel('xdstable','oidstruct3'),'oidstruct3','field',array('table'=>$this->base,'compulsory'=>false),null,$group);
- $this->_options->setGroupComment(XLabels::getSysLabel('xdstable','oidstructcomment'),'oidstruct1');
- }
- /// Vide la table
- public function clear($rq=NULL) {
- if(empty($rq) || is_array($rq)) updateQuery('truncate '.$this->base);
- else updateQuery('delete from '.$this->base.' where '.$rq);
- return array('message'=>XLabels::getSysLabel('xdatasource.update_ok'));
- }
- function make_cond($def, $v) {
- $cond='';
- if (!is_array($v)) {
- throw new Exception('Parameter must be an array with an operator (index 0) and values (index 1)');
- }
- $op=$v[0];
- if(is_array($op)){
- $opfield=$op[0];
- $opmultiple=$op[1];
- }else{
- $opfield=$op;
- $opmultiple='or';
- }
- $k=$def->get_field();
- if(count($v)>2) {
- array_shift($v);
- foreach($v as $v1=>&$v2) {
- if($cond!='') $cond.=' '.$opmultiple.' ';
- $cond.=$this->make_cond($def,array($v[0],$v1));
- }
- return '('.$cond.')';
- }
- if(is_array($v[1])) {
- foreach($v[1] as $v1=>$v2) {
- if($cond!='') $cond.=' '.$opmultiple.' ';
- $cond.=$this->make_cond($def,array($v[0],$v2));
- }
- return '('.$cond.')';
- }
- // dans le cas ou le parametre d'un link n'est pas un link on rajoute la table en tete
- if($def->isObjectLink() && !empty($v[1]) && ($v[1]!='NULL') && !Kernel::isAKoid($v[1]) && strstr($v[1],'%')==false) {
- $v[1]=$def->get_target().':'.$v[1];
- }
- // traitement sur oid vide
- if($def->get_fgender()=='Oid' && $opfield=='=' && ($v[1]=='NULL' || empty($v[1])))
- $cond=' ('.$this->base.'.'.$k.'="" or '.$this->base.'.'.$k.' is NULL) ';
- // traitement sur oid non vide
- elseif($def->get_fgender()=='Oid' && $opfield=='!=' && ($v[1]=='NULL' || empty($v[1])))
- $cond=' ('.$this->base.'.'.$k.'!="" and '.$this->base.'.'.$k.' is not NULL) ';
- // traitement des valeurs multiples et operateur =
- elseif($def->get_multivalued() && $def->get_fgender()=='Oid' && $v[0]=='=')
- $cond=' ('.$this->base.'.'.$k.'="'.$v[1].'" or INSTR('.$this->base.'.'.$k.',"||'.$v[1].'||")) ';
- // traitement des valeurs avec operateur ==
- elseif($def->get_fgender()=='Oid' && $v[0]=='==') {
- $v1=$def->get_soid_from_set($v[1]);
- $cond=' ('.$this->base.'.'.$k.'="'.$v1.'" or INSTR('.$this->base.'.'.$k.',"||'.$v1.'||")) ';
- // traitement des valeurs multiples et operateur !==
- } elseif($def->get_multivalued() && $def->get_fgender()=='Oid' && $v[0]=='!==') {
- $v1=$def->get_soid_from_set($v[1]);
- $cond=' (not('.$this->base.'.'.$k.'="'.$v1.'" or INSTR('.$this->base.'.'.$k.',"||'.$v1.'||"))) ';
- // traitement des valeurs non oid
- }else{
- if($v[1][0]=='=') $cond=' '.$this->base.'.'.$k.' '.$opfield.' '.substr($v[1],1).' ';
- else $cond=' '.$this->base.'.'.$k.' '.$opfield.' "'.$v[1].'"';
- }
- return $cond;
- }
- function make_simple_cond($k,$v) {
- $cond='';
- $op=$v[0];
- if(is_array($op)){
- $opfield=$op[0];
- $opmultiple=$op[1];
- }else{
- $opfield=$op;
- $opmultiple='or';
- }
- if(count($v)>2) {
- array_shift($v);
- foreach($v as $v1=>&$v2) {
- if($cond!='') $cond.=' '.$opmultiple.' ';
- $cond.=$this->make_simple_cond($k,array($op,$v2));
- }
- return '('.$cond.')';
- }
- if(is_array($v[1])) {
- foreach($v[1] as $v1=>$v2) {
- if($cond!='') $cond.=' '.$opmultiple.' ';
- $cond.=$this->make_simple_cond($k,array($op,$v2));
- }
- return '('.$cond.')';
- }
- return ' '.$this->base.'.'.$k.' '.$opfield.' "'.$v[1].'" ';
- }
- /// generation d'une condition utilisable sur le container
- function select_query($args=NULL) {
- $params=new XParam($args, array('cond'=>array()));
- $LANG_DATA = XShell::getLangData($params->get('LANG_DATA'));
- $cond = $args['cond'];
- if(empty($cond)) $cond=array();
- $selectedfields = @$args['selectedfields'];
- if(empty($selectedfields)||($selectedfields=='all')) $selectedfields=array('*');
- $where = @$args['where'];
- $tr=$this->getTranslatable();
- if($tr==TZR_LANG_BASEDLANG) {
- $txt="{$this->base}.LANG = '".$LANG_DATA."' ";
- } elseif($tr==TZR_LANG_FREELANG) {
- $txt="{$this->base}.LANG = '".$LANG_DATA."' ";
- } else
- $txt="{$this->base}.LANG = '".TZR_DEFAULT_LANG."' ";
- if(!empty($where)) $txt.=' AND ('.$where.') ';
- $pu=$this->publishedMode($params);
- if($pu=='public') {
- $txt .= " and {$this->base}.PUBLISH = '1' ";
- }
- foreach($cond as $k => $v) {
- $k1 = trim($k);
- if(!empty($this->desc[$k1])) {
- $def = $this->desc[$k1];
- $txt = $txt.' and '.$this->make_cond($def, $v);
- } else {
- $txt = $txt.' and '.$this->make_simple_cond($k1, $v);
- }
- }
- $jointcond = NULL;
- $order=@$args['order'];
- if(!empty($order)) {
- $torder=explode(',',$order);
- $order=array();
- $order=$this->makeOrder($torder,$order,$jointcond);
- if(!empty($order)) $txt.=' order by '.$order;
- }
- if(isset($args['groupby'])) $txt.=' group by '.$args['groupby'];
- if(!empty($jointcond)) $query = 'select '.$this->base.'.* from '.$this->base.' '.$jointcond.' where '.$txt;
- else $query = 'select '.$this->base.'.* from '.$this->base.' where '.$txt;
- return $query;
- }
- function random_select_query($args=NULL) {
- $args['order']='RAND(RAND()*20)';
- return $this->select_query($args);
- }
- function count_query($args=NULL) {
- $params=new XParam($args, array('cond'=>array()));
- $LANG_DATA = XShell::getLangData();
- $cond = $params->get('cond');
- $txt="LANG = '$LANG_DATA' ";
- foreach($cond as $k=>$v) {
- if(!isset($this->desc[$k])) XShell::quit('XDataSource->select_query: field '.$k.' unknown in table '.$this->base);
- $def=&$this->desc[$k];
- if($def->get_multivalued() && ($def->get_fgender() == 'Oid')
- && ($v[0]=='=')) {
- $txt=$txt." and (($k = '$v[1]') or ($k like '%||$v[1]||%'))";
- } else {
- $txt=$txt." and $k $v[0] '$v[1]' ";
- }
- }
- $query = 'select count(KOID) from '.$this->base.' where '.$txt;
- return $query;
- }
- protected function _getDesc($refresh=false) {
- $this->desc = array();
- $this->orddesc = array();
- $orderby=' FORDER ' ;
- $lang = XShell::getLangUser();
- if($lang!=TZR_DEFAULT_LANG) $lang_cond='(MLANG="'.$lang.'" or MLANG="'.TZR_DEFAULT_LANG.'")';
- else $lang_cond="MLANG='".$lang."'";
- $rs=selectQuery('select * from DICT,MSGS where DTAB = "'.$this->base.'" and MTAB="'.$this->base.'"'.
- ' and '.$lang_cond.' and DICT.FIELD=MSGS.FIELD order by FORDER');
- $i=0;
- $ors=array();
- while($rs && $ors=$rs->fetch()) {
- $field = $ors['FIELD'];
- if(empty($this->desc[$field]) || (!empty($this->desc[$field]) && ($ors['MLANG']==$lang))) {
- $o = (object) $ors;
- // si la table n'est pas traduisible, aucun champ ne peut etre traduisible, donc on force cette propriete
- if(empty($this->translatable)) $o->TRANSLATABLE=0;
- $this->desc[$field] = & XFieldDef::objectFactory($o);
- if(!in_array($field, $this->orddesc)) {
- $this->orddesc[$i]=$field;
- $i++;
- }
- }
- }
- $rs->closeCursor();
- }
- /// verification que la table des archive existe et construction si elle n'existe pas.
- protected function checkArchiveTable($createifneeded=true) {
- if(XSystem::tableExists('A_'.$this->base)) return true;
- updateQuery('CREATE TABLE A_'.$this->base.' AS SELECT * FROM '.$this->base);
- return true;
- }
- /// Insere une nouvelle table SQL
- static function procNewSource($ar=NULL) {
- global $XSHELL;
- global $XLANG;
- $error=false;
- $p=new XParam($ar,array('user_base'=>1,'translatable'=>0,'auto_translate'=>0,'publish'=>1,'own'=>1),'local');
- $bname=$p->get('bname');
- $btab=$p->get('btab');
- $user_base=$p->get('user_base');
- $translatable=$p->get('translatable');
- $auto_translate=$p->get('auto_translate');
- $publish=$p->get('publish');
- $own=$p->get('own');
- $bparam=$p->get('bparam');
- $classname=$p->get('classname');
- if(!empty($auto_translate)) $translate=1;
- if(empty($classname)) $classname='XDSTable';
- // Controle des donnees obligatoires
- if(isSQLKeyword($btab)) {
- $message=$btab.' is a SQL keyword';
- $error=true;
- XLogs::notice('xbaseadm',$message);
- } elseif (empty($bname[TZR_DEFAULT_LANG])) {
- $message='Table Name is compulsory in default language ! Try again ...';
- $error=true;
- XLogs::notice('xbaseadm',$message);
- } elseif(empty($btab)) {
- $message='SQL Table Name is compulsory ! Try again ...';
- $error=true;
- XLogs::notice('xbaseadm',$message);
- } elseif(rewriteToAscii($btab,false)!=$btab) {
- $message='SQL Table Name not [A-Za-z0-9_-] checked ! Try again ...';
- $error=true;
- XLogs::notice('xbaseadm',$message);
- } else{
- if(self::createTable($btab,$publish,$own)) {
- $boid=XDataSourceWd::getNewBoid();
- $xml=XOptions::rawToXML($bparam,TZR_ADMINI_CHARSET);
- preparedUpdateQuery('INSERT INTO BASEBASE(BOID,BNAME,BTAB,AUTO_TRANSLATE,TRANSLATABLE,BCLASS,BPARAM) '.
- 'values(?,?,?,?,?,?,?)', array($boid,$bname[TZR_DEFAULT_LANG],$btab,$auto_translate,
- $translatable,$classname,$xml));
- $XLANG->getCodes();
- for($i=0;$i<$XLANG->nbLang;$i++) {
- $code=$XLANG->codes[$i];
- $txt=$bname[$code];
- if($txt!="") preparedUpdateQuery('INSERT INTO AMSG(MOID,MLANG,MTXT) values (?,?,?)',array($boid,$code,$txt));
- }
- $message='New table '.$bname[TZR_DEFAULT_LANG].' ('.$btab.') created.';
- } else {
- $error=true;
- $message='Could not create '.$bname[TZR_DEFAULT_LANG].' ('.$btab.').';
- }
- }
- return array('message'=>$message,'error'=>$error);
- }
- /// Créé une table SQL et son dictionnaire
- static function createTable($table,$valid=true,$own=true) {
- if(XSystem::tableExists($table)) return false;
- $q='CREATE TABLE '.$table.' (KOID varchar(40) DEFAULT \'0\' NOT NULL, LANG char(2) NOT NULL, UPD TIMESTAMP,'.
- ($own ?'OWN varchar(40),':'').
- ($valid?'PUBLISH tinyint(4) default 1,':'').' PRIMARY KEY (KOID, LANG))';
- updateQuery($q);
- if(!XSystem::tableExists($table, true)) return false;
- // Creation du dictionnaire et de msgs
- $order=0;
- updateQuery("INSERT INTO DICT values('$table','UPD','XTimestampDef',0,0,0,0,0,1,0,0,'%','')");
- updateQuery("INSERT INTO MSGS values('$table','UPD','".TZR_DEFAULT_LANG."','".XLabels::getSysLabel('general','last_update','text')."')");
- $order++;
- if($own) {
- updateQuery("INSERT INTO DICT values('$table','OWN','XLinkDef',0,$order,0,1,0,1,0,0,'USERS','')");
- updateQuery("INSERT INTO MSGS values('$table','OWN','".TZR_DEFAULT_LANG."','".XLabels::getSysLabel('general','owner','text')."' )");
- $order++;
- }
- if($valid) {
- updateQuery("INSERT INTO DICT values ('$table','PUBLISH','XBoolDef',0,$order,0,0,0,1,0,0,'%','')");
- updateQuery("INSERT INTO MSGS values ('$table','PUBLISH','".TZR_DEFAULT_LANG."','".XLabels::getSysLabel('general','approved','text')."')");
- $order++;
- }
- return true;
- }
- /// Parcours les champs de la table
- function browseFields($ar=NULL){
- $p=new XParam($ar,NULL);
- $refresh=$p->get('refresh');
- $addOption = substr($p->get('addOption'), 2); //option additionelle prefixée par __
- $this->_getDesc($refresh);
- $groups=array();
- $allOpts = array();
- if(is_array($this->orddesc)) {
- foreach($this->orddesc as $o => $field) {
- $v=&$this->desc[$field];
- $i=array_search($v->fgroup,$groups);
- if($i===false){
- $i=array_push($groups,$v->fgroup)-1;
- }
- $tableGroup[$field]='group_'.$i;
- //option additionelle
- $optUI = '';
- foreach ($v->getOptions('addOptions') as $opt) {
- $allOpts[$opt['field']] = $opt['label'];
- if ($opt['field'] == $addOption) {
- $optUI = $opt['edit'];
- }
- }
- $tableAddOption[$field] = $optUI;
- }
- }
- $result=array();
- $result['tableObject']=$this->desc;
- $result['tableGroup']=$tableGroup;
- $result['groups']=$groups;
- $result['table']=$this->base;
- $result['boid']=$this->boid;
- asort($allOpts);
- $result['allOpts']=$allOpts;
- $result['addOption']=$tableAddOption;
- list($types, $labels)=XFieldDef::getTypes();
- foreach ($types as $i => $type)
- $type_labels[$type] = $labels[$i];
- $result['type_labels']=$type_labels;
- return $result;
- }
- /// Prepare la création d'un nouveau champ
- function newField($ar=NULL) {
- $p=new XParam($ar,NULL);
- $fnumber=$this->newFieldName();
- $types=XFieldDef::getTypes();
- $type=$types[0];
- $type_labels=$types[1];
- $btranslatable=$this->isTranslatable();
- $liste=$this->getBaseList();
- reset($liste);
- $target_key=array(TZR_DEFAULT_TARGET);
- $target_val=array("---");
- foreach($liste as $k=>$my) {
- $my_xst=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$k);
- if($my_xst->isTherePublishedField()) {
- $target_key[]=$k;
- $target_val[]=$my;
- }
- }
- $forder=$this->newFieldOrder();
- $result=array();
- $result['table']=$this->base;
- $result['boid']=$this->boid;
- $result['fnumber']=$fnumber;
- $result['type']=$type;
- $result['type_labels']=$type_labels;
- $result['type_default']='XShortTextDef';
- $result['btranslatable']=$btranslatable;
- $result['target_key']=$target_key;
- $result['target_val']=$target_val;
- $result['forder']=$forder;
- return $result;
- }
- /// Enregistre un nouveau champ
- public function procNewField($ar=NULL) {
- $p=new XParam($ar,NULL);
- $field=$p->get('field');
- $ftype=$p->get('ftype');
- $fcount=$p->get('fcount');
- $forder=$p->get('forder');
- $compulsory=$p->get('compulsory');
- $queryable=$p->get('queryable');
- $browsable=$p->get('browsable');
- $translatable=$p->get('translatable');
- $multivalued=$p->get('multivalued');
- $published=$p->get('published');
- $label=$p->get('label');
- $target=$p->get('target');
- $options=$p->get('options');
- $options=array_stripslashes($options);
- $error=false;
- $table=$this->getTable();
- // Controle des donnees obligatoires
- if(!$this->newFieldDescIsCorrect($field,$ftype,$fcount,$forder,$compulsory,$queryable,$browsable,$translatable,$multivalued,
- $published,$target,$label) ) {
- $message='Incorrect description for field '.$label[TZR_DEFAULT_LANG].' ! Try again.<br/>';
- $error=true;
- }elseif($this->fieldExists($field)){
- $message='Field '.$label[TZR_DEFAULT_LANG].' already exists ! Try again ...<br/>';
- $error=true;
- }else{
- $this->newDesc($field,$ftype,$fcount,$forder,$compulsory,$queryable,$browsable,$translatable,$multivalued,$published,$target,$label,
- $options);
- $this->sql_newFieldDesc($field);
- $this->majUpOtherFieldOrder($field,$forder);
- $this->sql_newField($field);
- $message='Field '.$label[TZR_DEFAULT_LANG].' created<br/>';
- }
- XLogs::update('newfield',NULL,$table.':'.$field.' '.$message);
- $result=array('message'=>$message,'error'=>$error);
- return $result;
- }
- /// Ajoute un champ du desc dans le dictionnaire
- function sql_newFieldDesc($field) {
- if(!is_array($this->desc)) return false;
- if(empty($this->desc[$field])) return false;
- // Insertion dans DICT
- $def=$this->desc[$field];
- $ftype=$def->get_ftype();
- $fcount=$def->get_fcount();
- $forder=$def->get_forder();
- $compulsory=($def->get_compulsory()?"1":"0");
- $queryable=($def->get_queryable()?"1":"0");
- $browsable=$def->get_browsable();
- $translatable=$def->get_translatable();
- $multivalued=$def->get_multivalued();
- $published=$def->get_published();
- $target=$def->get_target();
- $t1=$def->_options->toXML($def);
- $dparam=addslashes($t1);
- updateQuery('INSERT INTO DICT (DTAB,FIELD,FTYPE,FCOUNT,FORDER,COMPULSORY,QUERYABLE,BROWSABLE,TRANSLATABLE,MULTIVALUED,PUBLISHED,'.
- 'TARGET,DPARAM) values ("'.$this->base.'","'.$field.'","'.$ftype.'","'.$fcount.'","'.$forder.'","'.$compulsory.'",'.
- '"'.$queryable.'","'.$browsable.'","'.$translatable.'","'.$multivalued.'","'.$published.'","'.$target.'","'.$dparam.'")');
- // Insertion des labels dans MSGS
- $msg=$def->get_labels();
- foreach($msg as $lg=>$m) {
- updateQuery('INSERT INTO MSGS (MTAB,FIELD,MLANG,MTXT) values ("'.$this->base.'","'.$field.'","'.$lg.'","'.$m.'")');;
- }
- return true;
- }
- /// Ajout du champ dans la table SQL
- function sql_newField($field) {
- if(!is_array($this->desc)) return false;
- if(empty($this->desc[$field])) return false;
- $def=$this->desc[$field];
- $sqltype=$def->sqltype();
- updateQuery('alter table '.$this->base.' add '.$field.' '.$sqltype);
- // Ajoute le champ à la table des archives si elle existe
- if(XSystem::tableExists('A_'.$this->base)) updateQuery('alter table A_'.$this->base.' add '.$field.' '.$sqltype);
- }
- /// Prepare la création / l'édition d'un champ
- public function editField($ar=NULL) {
- GLOBAL $XLANG;
- $p=new XParam($ar,NULL);
- $LANG_USER=XShell::getLangUser();
- $LANG_DATA=XShell::getLangData();
- $field=$p->get("field");
- $XLANG->getCodes();
- if(is_array($XLANG->codes) && is_array($this->desc)) {
- $v=$this->desc[$field];
- // Labels
- $labels=$v->get_labels();
- for($myi=0;$myi<$XLANG->nbLang;$myi++) $fnames[$myi]=$labels[$XLANG->codes[$myi]];
- // Number
- $fnumber=$field;
- // Type
- $types=XFieldDef::getTypes();
- $type=$types[0];// liste des types
- $type_labels=$types[1];// liste des libelles
- foreach($type as $i=>$ft) {
- if($v->get_ftype()==$ft ) $type_selectionFlag[]='selected';
- else $type_selectionFlag[]='';
- }
- $fcount=$v->get_fcount();
- $compulsory=$v->get_compulsory();
- $queryable=$v->get_queryable();
- $browsable=$v->get_browsable();
- $btranslatable=$this->isTranslatable();
- $translatable=$v->get_translatable();
- $multivalued=$v->get_multivalued();
- $published=$v->get_published();
- $liste=$this->getBaseList();
- reset($liste);
- $target_key=array(TZR_DEFAULT_TARGET);
- $target_val=array('---');
- $target_selectionFlag=array('');
- foreach($liste as $k=>$my) {
- $my_xst=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$k);
- if($my_xst->isTherePublishedField()) {
- $target_key[]=$k;
- $target_val[]=$my;
- if($v->get_target()==$k ) $target_selectionFlag[]="selected";
- else $target_selectionFlag[]="";
- }
- }
- $forder=$v->get_forder();
- $opts=$v->getOptions('options');
- $result['options']=$opts;
- }
- $result['table']=$this->base;
- $result['boid']=$this->boid;
- $result['field']=$field;
- $result['fnames']=$fnames;
- $result['fnumber']=$fnumber;
- $result['type_selectionFlag']=$type_selectionFlag;
- $result['type']=$type;
- $result['type_labels']=$type_labels;
- $result['fcount']=$fcount;
- $result['ftype']=$v->get_ftype();
- $result['compulsory']=$compulsory;
- $result['queryable']=$queryable;
- $result['browsable']=$browsable;
- $result['btranslatable']=$btranslatable;
- $result['translatable']=$translatable;
- $result['multivalued']=$multivalued;
- $result['published']=$published;
- $result['target_key']=$target_key;
- $result['target_val']=$target_val;
- $result['target_selectionFlag']=$target_selectionFlag;
- $result['forder']=$forder;
- return $result;
- }
- /// Enregistre les modifications sur un champ
- function procEditField($ar) {
- global $XLANG;
- $XLANG->getCodes();
- $p=new XParam($ar,array('batch'=>'0','options'=>NULL));
- $field=$p->get('field');
- $def=$this->desc[$field];
- // Pour chaque parametre, on verifie si une nouvelle valeur est spécifiée, sinon on garde l'ancienne
- $ftype=$p->get('ftype');
- if(!$ftype) $ftype=$def->get_ftype();
- $fcount=$p->get('fcount');
- if(!$fcount) $fcount=$def->get_fcount();
- $forder=$p->get('forder');
- if(!empty($forder)) {
- $forder = $this->_guessFieldOrder($forder);
- } else {
- $forder = $def->get_forder();
- }
- $compulsory=$p->get('compulsory');
- $compulsory_hid=$p->get('compulsory_HID');
- if(!$compulsory && $compulsory!==false && $compulsory_hid!=2) $compulsory=$def->get_compulsory();
- else $compulsory=($compulsory=='on'?1:0);
- $queryable=$p->get('queryable');
- $queryable_hid=$p->get('queryable_HID');
- if(!$queryable && $queryable!==false && $queryable_hid!=2) $queryable=$def->get_queryable();
- else $queryable=($queryable=='on'?1:0);
- $browsable=$p->get('browsable');
- $browsable_hid=$p->get('browsable_HID');
- if(!$browsable && $browsable!==false && $browsable_hid!=2) $browsable=$def->get_browsable();
- else $browsable=($browsable=='on'?1:0);
- $translatable=$p->get('translatable');
- $translatable_hid=$p->get('translatable_HID');
- if(!$translatable && $translatable!==false && $translatable_hid!=2) $translatable=$def->get_translatable();
- else $translatable=($translatable=='on'?1:0);
- $multivalued=$p->get('multivalued');
- $multivalued_hid=$p->get('multivalued_HID');
- if(!$multivalued && $multivalued!==false && $multivalued_hid!=2) $multivalued=$def->get_multivalued();
- else $multivalued=($multivalued=='on'?1:0);
- $published=$p->get('published');
- $published_hid=$p->get('published_HID');
- if(!$published && $published!==false && $published_hid!=2) $published=$def->get_published();
- else $published=($published=='on'?1:0);
- $label=$p->get('label');
- $target=$p->get('target');
- if(empty($target)) $target=$def->get_target();
- $batch=$p->get('batch');
- $options=$p->get('options');
- $error=false;
- // Remplissage des options non definit
- $def->_options->procDialog($def,$options);
- if(!$this->fieldDescIsCorrect($field,$ftype,$fcount,$forder,$compulsory,$queryable,$browsable,$translatable,$multivalued,$published,
- $target,$label)) {
- $message='Incorrect description ! Try again.<br/>';
- $error=true;
- }else{
- $this->sql_changeFieldDesc($field,$ftype,$fcount,$forder,$compulsory,$queryable,$browsable,$translatable,$multivalued,$published,
- $target,$label,$XLANG->codes,$options);
- $this->majOtherFieldOrder($field,$def->get_forder(),$forder);
- $this->sql_changeField($field,$ftype,$fcount);
- $this->changeDesc($field,$ftype,$fcount,$forder,$compulsory,$queryable,$browsable,$translatable,$multivalued,$published,$target,
- $label);
- $message.='Field '.$field.' modified.<br/>';
- }
- // Convertit les données présentes en base si necessaire
- $this->desc[$field]->convertValues($def->get_ftype());
- // Efface le cache
- XDbIni::clear('modules'.$this->base);
- // efface le cache des chronos
- XDbIni::clear('Chrono%'.$this->base.'%');
- return array('message'=>$message,'error'=>$error);
- }
- /// Modifie un champ du desc dans le dictionnaire
- function sql_changeFieldDesc($field,$ftype,$fcount,$forder,$compulsory,$queryable,$browsable,$translatable,$multivalued,$published,
- $target,$label,$langs,$options=NULL) {
- $def=$this->desc[$field];
- $t1=$def->_options->toXML($def);
- preparedUpdateQuery('UPDATE DICT set FTYPE="'.$ftype.'",FCOUNT='.$fcount.',FORDER='.$forder.',COMPULSORY='.$compulsory.','.
- 'QUERYABLE='.$queryable.',BROWSABLE='.$browsable.',TRANSLATABLE='.$translatable.',MULTIVALUED='.$multivalued.','.
- 'PUBLISHED='.$published.',TARGET="'.$target.'",DPARAM=? where FIELD="'.$field.'" and DTAB="'.$this->base.'"',
- array($t1));
- $oldlabel=$def->get_labels();
- reset($langs);
- while(list($k,$l)=each($langs)) {
- if($label[$l]!=$oldlabel[$l]){
- if($label[$l]!=''){
- if(isset($oldlabel[$l]))
- preparedUpdateQuery('UPDATE MSGS set MTXT=? where MTAB="'.$this->base.'" and FIELD="'.$field.'" and MLANG="'.$l.'"', array($label[$l]));
- else
- preparedUpdateQuery('INSERT INTO MSGS (MTAB,FIELD,MLANG,MTXT) values ("'.$this->base.'","'.$field.'","'.$l.'",?)', array($label[$l]));
- }else{
- updateQuery('DELETE FROM MSGS where MTAB="'.$this->base.'" and FIELD="'.$field.'" and MLANG="'.$l.'"');
- }
- }
- }
- }
- /// Modifie un champ dans la table SQL
- function sql_changeField($field,$ftype,$fcount) {
- $def=$this->desc[$field];
- if($def->get_ftype()!=$ftype || $def->get_fcount()!=$fcount) {
- $t['FTYPE']=$ftype;
- $t['FCOUNT']=$fcount;
- $t['FIELD']='bidon';
- $obj=(object)$t;
- $new=&XFieldDef::objectFactory($obj);
- $new->set_fcount($fcount);
- $sqltype=$new->sqltype();
- updateQuery('alter table '.$this->base.' modify '.$field.' '.$sqltype);
- // Modifie la table des archives si elle existe
- if(XSystem::tableExists('A_'.$this->base)) updateQuery('alter table A_'.$this->base.' modify '.$field.' '.$sqltype);
- }
- }
- /// Suppression d'un champ
- function delField($ar=NULL) {
- $p=new XParam($ar,NULL);
- $field=$p->get('field');
- $message='';
- $error=false;
- if(!$this->deleteIsSafe($message,$field)) {
- $message.='<br/>Field $field not deleted. <br/>';
- $error=true;
- }else{
- $def=$this->desc[$field];
- // Action specifique sur suppression d'un champ, par exemple suppression des fichier
- $def->delfield();
- // Suppression du tuple dans les tables
- updateQuery('DELETE FROM SETS WHERE STAB="'.$this->base.'" AND FIELD="'.$field.'"');
- $this->sql_delFieldDesc($field);
- $this->majDownOtherFieldOrder($field,$def->get_forder());
- $this->sql_delField($field);
- $this->delDesc($field);
- // Suppression des droits sur le champ
- $mods=XModule::modulesUsingTable($this->base,true,false,false);
- if(!empty($mods)) {
- foreach($mods as $moid => $name) {
- updateQuery('delete from ACL4 where AMOID="'.$moid.'" and AKOID="_field-'.$field.'"');
- }
- }
- // Il n'y a plus de champ de description. Suppression des tuples de data dans Txxx et Kernel et les annexes
- if(!count($this->desc)) $this->clear();
- $message.='Field '.$field.' '.XLabels::getSysLabel('general.deleted').'.<br/>';
- }
- XLogs::update('delfield', NULL, $this->base.':'.$field.' '.$message);
- XDbIni::clear('modules'.$this->base);
- return array('message'=>$message,'error'=>$error);
- }
- /// Verifie si un champ peut etre supprimé
- function deleteIsSafe(&$out,$field) {
- // Verifie que ce n'est pas un champ systeme
- if(in_array($field,array('UPD','KOID','LANG'))) {
- $out='Champ obligatoire : impossible de supprimer';
- return false;
- }
- $def=$this->desc[$field];
- $fieldLabel=$def->get_label();
- // Le champ est publié
- if($def->get_published()) {
- // Comptage du nombre de champs published sur la table
- if($this->getPublishedFieldCount()==1) {
- $links=XDSTable::fieldsUsingTable($this->base);
- // Des champs utilisent cette table comme source de données
- if(count($links)) {
- if(count($this->desc)==1) {
- // Le champ est le dernier de la table, il ne peut etre supprimé
- $out.='Field '.$fieldLabel.' ('.$field.') is the only published field !<br/>';
- $out.='No other field can be set published instead ...<br/>';
- $out.='Delete is not safe.<br/>';
- return false;
- }else{
- // Le champ n'est pas le dernier de la table, on met d'office le premier field a published
- $rs=selectQuery('select FIELD from DICT where DTAB="'.$this->base.'" and FORDER!='.$def->get_forder().' order by FORDER');
- if($ors=$rs->fetch()){
- $f=$ors['FIELD'];
- $fdef=$this->desc[$f];
- $fLabel=$fdef->get_label();
- $fdef->set_published(true);
- updateQuery('UPDATE DICT set DTAB="'.$this->base.'" and PUBLISHED=1 where FIELD="'.$f.'"');
- $out.='Field '.$fieldLabel.' ('.$field.') was the only published field !<br/>';
- $out.='Field '.$fLabel.' ('.$f.') is automatically set published instead ...<br/>';
- }
- $out.='Delete is now safe.<br/>';
- }
- }
- }
- }
- return true;
- }
- /// Supprime un champ du desc du dictionnaire
- function sql_delFieldDesc($field) {
- updateQuery('DELETE FROM DICT where FIELD="'.$field.'" and DTAB="'.$this->base.'"');
- updateQuery('DELETE FROM MSGS where MTAB="'.$this->base.'" and FIELD="'.$field.'"');
- updateQuery('DELETE FROM AMSG where MOID LIKE "'.$this->base.':'.$field.':%"');
- }
- // maj des la structure de la table Txxx pour suppression de la colonne Fxxxx
- //
- function sql_delField($field) {
- $def=$this->desc[$field];
- // drop column col_name
- $requete = "alter table " . $this->base . " drop $field";
- updateQuery($requete);
- if(XSystem::tableExists('A_'.$this->base)) {
- $requete = "alter table A_" . $this->base . " drop $field";
- updateQuery($requete);
- }
- }
- /// Met à jour l'ordre des champs dans DICT par le haut
- function majUpOtherFieldOrder($field,$forder) {
- updateQuery('UPDATE DICT SET FORDER=FORDER+1 where DTAB="'.$this->base.'" and FIELD!="'.$field.'" and FORDER>="'.$forder.'"');
- }
- /// Met à jour l'ordre des champs dans DICT par le bas
- function majDownOtherFieldOrder($field,$forder) {
- updateQuery('UPDATE DICT SET FORDER=FORDER-1 where DTAB="'.$this->base.'" and FIELD!="'.$field.'" and FORDER>"'.$forder.'"');
- }
- /// Met à jour l'ordre des champs dans DICT
- function majOtherFieldOrder($field,$oldOrder,$newOrder) {
- // Si augmente, -- sur les order > old et <= new
- if($newOrder>$oldOrder ){
- updateQuery('UPDATE DICT set FORDER=FORDER-1 where DTAB="'.$this->base.'" and FIELD!="'.$field.'" and FORDER>'.$oldOrder.' and '.
- 'FORDER<='.$newOrder);
- }
- // Si diminue, ++ sur les order >= new et < old
- if($newOrder<$oldOrder) {
- updateQuery('UPDATE DICT set FORDER=FORDER+1 where DTAB="'.$this->base.'" and FIELD!="'.$field.'" and FORDER>='.$newOrder.' and '.
- 'FORDER<'.$oldOrder);
- }
- }
- /// Récupère le nombre de champ publié
- function getPublishedFieldCount() {
- $c = 0;
- $requete = "select count(*) from DICT where DTAB='$this->base' and PUBLISHED=".true;
- $rs=selectQueryByNum($requete);
- $ors=array();
- if ( $ors=$rs->fetch() ) $c = $ors[0];
- $rs->closeCursor();
- return $c;
- }
- /// Genere un nouveau nom de table
- static function newTableNumber($prefix='T',$add=0) {
- $tmax=$prefix.'001';
- while(1){
- if(XSystem::tableExists($tmax,true) || XDataSource::sourceExists($tmax)) $tmax++;
- elseif($add){
- $tmax++;
- $add--;
- } else break;
- }
- return $tmax;
- }
- /// Prepare la duplication d'une source
- public function duplicateDataSource($ar=NULL){
- return array('newtable'=>XDSTable::newTableNumber(),'mtxt'=>'- '.$this->getSourceName(),'boid'=>$this->boid);
- }
- /// Duplique la source
- public function procDuplicateDataSource($ar=NULL){
- $p=new XParam($ar,array('tplentry'=>''));
- $tplentry = $p->get('tplentry');
- $bnewtab=$p->get('newtable');
- $bnewoid=XDataSourceWd::getNewBoid();
- $bnewlib=$p->get('mtxt');
- $data=$p->get('data');
- $btab=$this->base;
- $boid=$this->boid;
- if(empty($bnewtab) || (!empty($bnewtab) && XSystem::tableExists($bnewtab))) $bnewtab = XDSTable::newTableNumber();
- if(empty($bnewlib)){
- $ors=selectQueryGetOne('SELECT * FROM AMSG WHERE MOID="'.$boid.'" LIMIT 0,1');
- $bnewlib='- '.$ors['MTXT'];
- }
- // Duplication du dictionnaire
- preparedUpdateQuery("CREATE TEMPORARY TABLE tmpdict AS SELECT * FROM DICT where DTAB=?",array($btab));
- preparedUpdateQuery("UPDATE tmpdict set DTAB=?",array($bnewtab));
- // Duplication du nom de la table et des commentaires de champ
- updateQuery('CREATE TEMPORARY TABLE tmpmsg as select * from AMSG where MOID="'.$boid.'" or MOID REGEXP "^'.$btab.':.+$"');
- preparedUpdateQuery('UPDATE tmpmsg set MOID=?,MTXT=? where MOID=?',array($bnewoid,$bnewlib,$boid));
- updateQuery('UPDATE tmpmsg set MOID=REPLACE(MOID,"'.$btab.'","'.$bnewtab.'") where MOID REGEXP "^'.$btab.':.+$"');
- // Duplications des libelles des champs
- updateQuery("CREATE TEMPORARY TABLE tmpmsgs AS SELECT * FROM MSGS WHERE MTAB='$btab'");
- updateQuery("UPDATE tmpmsgs SET MTAB='".$bnewtab."'");
- updateQuery("CREATE TEMPORARY TABLE tmpsets AS SELECT * FROM SETS WHERE STAB='$btab'");
- updateQuery("UPDATE tmpsets set STAB='".$bnewtab."'");
- // Duplication de l'entree dans basebase
- preparedUpdateQuery('CREATE TEMPORARY TABLE tmpbase AS SELECT * FROM BASEBASE where BOID=?',array($boid));
- updateQuery("UPDATE tmpbase set BTAB='".$bnewtab."',BOID='$bnewoid'");
- // Create de la table
- updateQuery('INSERT INTO DICT select * from tmpdict');
- updateQuery('INSERT INTO AMSG select * from tmpmsg');
- updateQuery('INSERT INTO MSGS select * from tmpmsgs');
- updateQuery("INSERT INTO SETS select SOID, STAB, FIELD, SLANG, STXT, SORDER from tmpsets");
- updateQuery('INSERT INTO BASEBASE select * from tmpbase');
- updateQuery('CREATE TABLE '.$bnewtab.' like '.$btab);
- if($data){
- updateQuery('INSERT INTO '.$bnewtab.' (select * from '.$btab.')');
- updateQuery('UPDATE '.$bnewtab.' SET UPD=UPD,KOID=replace(KOID,"'.$btab.':","'.$bnewtab.':")');
- // copie des donnees
- Global $DATA_DIR;
- XDir::copy($DATA_DIR.$btab, $DATA_DIR.$bnewtab, true);
- }
- updateQuery('DROP TEMPORARY TABLE tmpbase');
- updateQuery('DROP TEMPORARY TABLE tmpdict');
- updateQuery('DROP TEMPORARY TABLE tmpmsg');
- updateQuery('DROP TEMPORARY TABLE tmpmsgs');
- updateQuery('DROP TEMPORARY TABLE tmpsets');
- return array('message'=>'Duplication finished','boid'=>$bnewoid,'table'=>$bnewtab);
- }
- /// Check/repare la source de donnée
- public function chk($ar=NULL) {
- $p=new XParam($ar, array("repair"=>false));
- $repair=$p->get("repair");
- $msg='';
- // Verification des index déjà dans XIntegrity::chkDatabases et mieux fait
- //updateQuery('alter table '.$this->base.' add primary key(KOID,LANG);');
- // Verification des champs
- foreach($this->desc as $k=>$v) {
- if(!fieldExists($this->base, $k)) $msg.=$this->base.':'.$k.' fields exist in catalog not in table<br>';
- else $v->chk($msg);
- }
- // Verification des langues
- $translatable=$this->getTranslatable();
- if(!$translatable) {
- updateQuery('delete from '.$this->base.' where LANG!="'.TZR_DEFAULT_LANG.'"');
- }elseif($translatable!=TZR_LANG_FREELANG) {
- $rs=selectQuery('select * from '.$this->base.' where LANG="'.TZR_DEFAULT_LANG.'"');
- $ors=array();
- while($ors=$rs->fetch()) {
- $oid=$ors['KOID'];
- $this->propagateOnOtherLangs($oid);
- }
- }
- // Verification des donnnees
- $rs=selectQuery('SELECT * FROM '.$this->base);
- $ors=array();
- while($ors=$rs->fetch()) {
- $oid=$ors['KOID'];
- $lang=$ors['LANG'];
- if(empty($GLOBALS['TZR_LANGUAGES'][$lang])) {
- $msg.=$oid.' '.$lang.' '.XLabels::getSysLabel('general.deleted').'<br>';
- updateQuery('delete from '.$this->base.' where LANG="'.$lang.'" and KOID="'.$oid.'"');
- }
- }
- return array('message'=>$msg);
- }
- /// Exporte les champs de la source dans une feuille d'un objet PHPExcel
- function exportSpec(&$sheet){
- $headers=array('table','forder');
- $langs=array_keys($GLOBALS['TZR_LANGUAGES']);
- foreach($langs as $lg) $headers[]='label['.$lg.']';
- $headers=array_merge($headers,array('field','ftype','fcount','compulsory','queryable','translatable','browsable','multivalued','published','target'));
- $rows=array();
- $table=$this->getTable();
- foreach($this->desc as $fn=>&$f){
- $row=array();
- $row['table']=$table;
- $row['forder']=$f->forder;
- $labels=array();
- $rs=&selectQuery('select * from MSGS where MTAB="'.$table.'" and FIELD="'.$fn.'" and MLANG in ("'.implode('","',$langs).'")');
- while($rs && $ors=$rs->fetch()) $labels[$ors['MLANG']]=$ors['MTXT'];
- foreach($langs as $lg) $row['label['.$lg.']']=$labels[$lg];
- $row['field']=$f->field;
- $row['ftype']=$f->ftype;
- $row['fcount']=$f->fcount;
- $row['compulsory']=$f->compulsory;
- $row['queryable']=$f->queryable;
- $row['translatable']=$f->translatable;
- $row['browsable']=$f->browsable;
- $row['multivalued']=$f->multivalued;
- $row['published']=$f->published;
- $row['target']=$f->target;
- if($row['target']=='%') $row['target']='';
- $opts=$f->_options->getAllValues($f, array('for_export' => 1));
- $row=array_merge($row,$opts);
- foreach($opts as $optn=>$opt) if(!in_array($optn,$headers)) $headers[]=$optn;
- $rows[]=$row;
- }
- foreach($headers as $i=>$h) {
- $sheet->setCellValueByColumnAndRow($i, 1, $h);
- }
- $line=1;
- foreach($rows as $row){
- $line++;
- foreach($headers as $i=>$h){
- if(array_key_exists($h,$row)) $sheet->setCellValueByColumnAndRow($i, $line, $row[$h]);
- }
- }
- }
- /// Importe les champs de la source via une feuille d'un objet PHPExcel
- function importSpec(&$sheet,&$log,$param=array()){
- $tables=array();
- $reorder=array();
- $table=$this->getTable();
- $fields=array();
- $prefixSQL=($param['prefixSQL']?$param['prefixSQL']:'');
- $delallfields=$param['delallfields'];
- $delotherfields=$param['delotherfields'];
- $oo=array('compulsory','queryable','browsable','translatable','multivalued','published'); // Champs booleen de base
- // Suppression de tous les champs non systeme
- if(!empty($delallfields)){
- foreach($this->desc as $fn=>&$f){
- if(!$this->sys) $this->delField(array('field'=>$fn,'action'=>'OK'));
- }
- $log.='<dd>Suppression de tous les champs non système de la table.</dd>';
- }
- // Recherche de l'entete
- $col=0;
- $h=$sheet->getCellByColumnAndRow($col,1)->getValue();
- while(!empty($h)) {
- $head[$col]=$h;
- $col++;
- $h=$sheet->getCellByColumnAndRow($col,1)->getValue();
- }
- unset($h);
- $it=$sheet->getRowIterator();
- foreach ($it as $ii) {
- $i=$ii->getRowIndex();
- if($i==1) continue;
- $row=array();
- foreach($head as $j=>$h) {
- $value = $sheet->getCellByColumnAndRow($j,$i)->getValue();
- if($value==='') continue;
- $pos=strpos($h,'[');
- if($pos) $tmp='['.substr($h,0,$pos).']'.substr($h,$pos);
- else $tmp='['.$h.']';
- $tmp=str_replace(array('[',']'),array("['","']"),$tmp);
- utf8_cp1252_replace($value);
- if($value==='_empty_') eval('$row'.$tmp.'="";');
- else eval('$row'.$tmp.'="'.str_replace('"','\\"',trim($value)).'";');
- }
- if(empty($row['field'])){
- $log.='<dd>Ligne '.$i.' : champ manquant</dd>';
- continue;
- }
- if(!empty($row['table']) && $table!=$prefixSQL.$row['table']) {
- continue;
- }
- $field=$row['field'];
- $fields[]=$field;
- // Création du champ si il n'existe pas
- $row['target']=str_replace('tzrprefix_',$prefixSQL,$row['target']);
- if(!fieldExists($table,$field)) {
- foreach($oo as $o)
- if(empty($row[$o])) $row[$o]=0;
- $this->createField($field,'Tmpname',$row['ftype'],$row['fcount'],$row['forder'],$row['compulsory'],$row['queryable'],
- $row['browsable'],$row['translatable'],$row['multivalued'],$row['published'],$row['target']);
- $log.='<dd>Création du champ/Creating field "'.$field.'"</dd>';
- }
- // Traitement pour l'edition des différentes options
- foreach($row['options'] as $n=>$o){
- if($o=='O') $row['options'][$n]=1;
- elseif($o=='N') $row['options'][$n]=0;
- }
- foreach($oo as $o){
- if(!empty($row[$o]) && ($row[$o]==1 || $row[$o]=='O')) $row[$o]='on';
- else $row[$o]='off';
- }
- $row['_todo']='save';
- if(empty($row['label'][TZR_DEFAULT_LANG])){
- $t1=reset($row['label']);
- $row['label'][TZR_DEFAULT_LANG]=$t1;
- }
- $this->procEditField($row);
- $reorder[]=array('table'=>$table,'field'=>$field,'order'=>$row['forder']);
- $log.='<dd>Modification du champ/Updating field "'.$field.'"</dd>';
- }
- // Suppression des champs qui ne sont dans la feuille
- if(!empty($delotherfields)){
- foreach($this->desc as $fn=>&$f){
- if(!in_array($fn,$fields) && !$f->sys){
- $this->delField(array('field'=>$fn,'action'=>'OK'));
- $log.='<dd>Suppression du champ "'.$fn.'"</dd>';
- }
- }
- }
- // Reordonne
- foreach($reorder as $info){
- updateQuery('UPDATE DICT set FORDER='.$info['order'].' where DTAB="'.$info['table'].'" and FIELD="'.$info['field'].'"');
- }
- }
- /// Ensemble d'actions à effectuer après qu'une modification de donnée ait eu lieu
- protected function updateTasks(&$ar,$oid) {
- if(parent::updateTasks($ar,$oid)){
- if($this->base=='LOGS') return true;
- XDbIni::clear('%|'.$this->base.':usedValues:%');
- XDbIni::clear($this->base.'|%:usedValues:%');
- XDbIni::clear($this->base.':usedValues:%');
- }
- return true;
- }
- /// Génère un oid pour la source
- function getNewOID($ar=NULL){
- // Si l'oid doit être généré à partir des infos d'autres champs
- if($this->oidstruct1){
- $p=new XParam($ar);
- $oid=$p->get($this->oidstruct1);
- if($this->oidstruct2) $oid.='-'.$p->get($this->oidstruct2);
- if($this->oidstruct3) $oid.='-'.$p->get($this->oidstruct3);
- if($oid){
- $oid=substr($this->base.':'.rewriteToAscii($oid),0,40);
- $cnt=countSelectQuery('select COUNT(KOID) from '.$this->base.' where KOID="'.$oid.'"');
- if($cnt){
- $i=0;
- do{
- $i++;
- $tmpoid=substr($oid,0,37).'-'.$i;
- $cnt=countSelectQuery('select COUNT(KOID) from '.$this->base.' where KOID="'.$tmpoid.'"');
- }while($cnt>0);
- $oid=$tmpoid;
- }
- return $oid;
- }
- }
- return parent::getNewOID($ar);
- }
- }
- ?>