/class.xdatasource.inc
PHP | 3190 lines | 2684 code | 219 blank | 287 comment | 733 complexity | 3681a96257cee3e37f34c19afd9aa61d MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /// Classe de base pour la gestion des sources de donnees
- class XDataSource implements XModuleContainerInterface {
- static $_sources;
- protected $base = NULL;
- protected $boid = NULL;
- protected $title=NULL;
- protected $translatable=false;
- protected $log=1;
- public $desc = array();
- public $orddesc = array();
- private static $_factory=array();
- private static $_factory_by_sourcepath=array();
- protected static $_basebase=NULL;
- protected static $_boid=array();
- public $published_fields_in_admin=2;
- public $sendacopytofields=array();
- /// construction d'une source de donnee avec un nom de table (legacy) ou un boid
- function __construct($boid=0) {
- XDataSource::preLoadBaseBase();
- if(!empty($boid)) {
- $this->boid=$boid;
- $this->base=XDataSource::$_boid[$boid]->BTAB;
- $this->initOptions();
- $param=XOptions::rawFromXML(XDataSource::$_boid[$this->boid]->BPARAM);
- $this->_options->setValues($this,$param);
- } else {
- XLogs::critical('XDataSource::construct', '<'.$boid.'> is empty');
- return NULL;
- }
- }
- /// Initialise les options de la source
- public function initOptions() {
- if(empty($this->_options)) $this->_options=new XOptions();
- $this->_options->setId($this->boid);
- }
- /// Supprime le cache des datasources
- static public function clearCache(){
- XDataSource::preLoadBaseBase(true);
- XDataSource::$_factory=array();
- XDataSource::$_factory_by_sourcepath=array();
- }
- /// chargement en mémoire de la liste des tables et les libellés associés
- static function preLoadBaseBase($refresh=false) {
- if(empty(XDataSource::$_basebase) || $refresh) {
- XLogs::debug('XShell::loadBaseBase: start');
- $lang = XShell::getLangUser();
- $rs=selectQueryGetAll('select BASEBASE.*,AMSG.* from BASEBASE,AMSG where BASEBASE.BOID=AMSG.MOID and MLANG="'.$lang.'" AND MTXT != ""');
- XDataSource::$_basebase=array();
- XDataSource::$_boid=array();
- foreach($rs as $idx => $o1) {
- XDataSource::$_basebase[$o1['BTAB']]=(object)$o1;
- XDataSource::$_boid[$o1['BOID']]=&XDataSource::$_basebase[$o1['BTAB']];
- }
- // Chargement des tables qui ne sont pas traduites
- if($lang!=TZR_DEFAULT_LANG) {
- $rs=selectQuery('select BASEBASE.*,AMSG.* from BASEBASE,AMSG where BASEBASE.BOID=AMSG.MOID and MLANG="'.TZR_DEFAULT_LANG.'"');
- $ors=array();
- while($ors=$rs->fetch() ) {
- if(empty(XDataSource::$_basebase[$ors['BTAB']])) {
- XDataSource::$_basebase[$ors['BTAB']]=(object)$ors;
- XDataSource::$_boid[$ors['BOID']]=&XDataSource::$_basebase[$ors['BTAB']];
- }
- }
- $rs->closeCursor();
- }
- XLogs::debug('XShell::loadBaseBase: end');
- }
- }
- /// Creation d'un objet de type xdatasource via le boid
- public static function objectFactory8($boid) {
- XLogs::debug('XDataSource::objectfactory8 boid='.$boid);
- if(!preg_match('/^[0-9a-f]+$/',$boid)) securityWarning('XDataSource::objectFactory8: Trying to get unauthorized <'.$boid.'>');
- XDataSource::preLoadBaseBase();
- if(empty(XDataSource::$_boid[$boid])) XDataSource::preLoadBaseBase(true);
- $c=XDataSource::$_boid[$boid]->BCLASS;
- if(!class_exists($c)) {
- XLogs::notice('XDataSource::objectfactory8','class '.$c.' doesn\'t exist');
- $c='XDSTable';
- }
- if(empty(XDataSource::$_factory[$boid])) {
- XLogs::debug($c.'::objectFactory8 creating '.$boid);
- XDataSource::$_factory[$boid]=new $c($boid);
- }
- return XDataSource::$_factory[$boid];
- }
- /// Creation d'un objet de type xdatasource via ses caratéristiques
- /// Ex de sourcepath : BCLASS=XDSTable&SPECS=_MLOGS pour recuperer la source de type XDSTable sur la table _MLOGS
- public static function objectFactoryHelper8($sourcepath) {
- XLogs::debug('XDataSource::objectfactoryHelper8 source='.$sourcepath);
- if(isset(XDataSource::$_factory_by_sourcepath[$sourcepath]))
- return XDataSource::$_factory_by_sourcepath[$sourcepath];
- XDataSource::preLoadBaseBase();
- parse_str($sourcepath,$output);
- $c=@$output['BCLASS'];
- $specs=@$output['SPECS'];
- if(Kernel::isAKoid($specs)) $specs=Kernel::getTable($specs);
- $boid=XDataSource::getBoidFromSpecs($c, $specs);
- if(empty($boid)) return NULL;
- return XDataSource::$_factory_by_sourcepath[$sourcepath] = XDataSource::objectFactory8($boid);
- }
- static function getBoidFromSpecs($class, $spec) {
- if(empty(XDataSource::$_basebase[$spec])) XDataSource::preLoadBaseBase(true);
- if(empty(XDataSource::$_basebase[$spec])) return NULL;
- return XDataSource::$_basebase[$spec]->BOID;
- }
- static function sysTable($table) {
- return in_array($table,array('USERS','GRP','TEMPLATES','LOGS','TASKS','LETTERS','REPLI','JOURNAL','OPTS','_MLOGS','_MLOGSD'));
- }
- static function notToReplicate($table) {
- return in_array($table,array('TASKS','REPLI','JOURNAL'));
- }
- static function tablesLogStatus() {
- XDataSource::preLoadBaseBase(true);
- $tablesLogStatus = array();
- foreach (XDataSource::$_basebase as $tableName => $tableObject)
- $tablesLogStatus[$tableName] = ($tableObject->LOG == 1 && $tableName != 'LOGS');
- return $tablesLogStatus;
- }
- public function &actionlist1() {
- $actions = array();
- $this->_actionlist($actions);
- return $actions;
- }
- // rend la liste des champs browsables
- //
- function browsableFields($selectedfields=NULL) {
- $fields=array();
- foreach($this->desc as $k => &$v) {
- if($v->get_browsable() || ($selectedfields=='all')) {
- $fields[]=$k;
- }
- }
- return $fields;
- }
- /// Transforme le résultat d'un formulaire en object requête
- function captureQuery($ar=NULL) {
- $p=new XParam($ar, array());
- $options=$p->get('options');
- $_FIELDS=$p->get('_FIELDS');
- $st=array();
- $st['_date']=mktime();
- $st['_table']=$this->base;
- $st['options']=$p->get('options');
- $st['oids']=$p->get('oids');
- $st['operator']=$p->get('operator');
- $st['_select']=$p->get('_select');
- $st['pagesize']=$p->get('pagesize');
- $st['order']=array();
- if(!empty($_FIELDS)) {
- $st['_querymode']='query2';
- $st['_FIELDS']=$_FIELDS;
- }else{
- $st['_FIELDS']=array();
- foreach($this->desc as $k=>&$v) $_FIELDS[$k]=$k;
- }
- foreach($_FIELDS as $field=>$k) {
- $v=&$this->desc[$k];
- if(is_object($v)) {
- if(!$v->get_queryable()) continue;
- $v1=$p->get($field);
- $st[$field]=$v1;
- $st[$field.'_op']=$p->get($field.'_op');
- $st[$field.'_HID']=$p->get($field.'_HID');
- $st[$field.'_FMT']=$p->get($field.'_FMT');
- $st[$field.'_PAR']=$p->get($field.'_PAR');
- $st[$field.'_empty']=$p->get($field.'_empty');
- }
- }
- $order=$p->get('order');
- $_order=$p->get('_order');
- if(is_array($order)) {
- foreach($order as $i=>$f) {
- if(!empty($f)) $st['order'][]=trim($order[$i].' '.$_order[$i]);
- }
- }
- return $st;
- }
- /// prend en entrée une requête stockée ($qinit) et génére les paramètres d'entrée
- public function prepareQuery(&$qinit, $storedname=NULL) {
- // table dans laquelle se trouvenet les donnees
- if(!empty($storedname)) {
- $rs=& selectQuery("select * from QUERIES where KOID = '$storedname' and LANG='".TZR_DEFAULT_LANG."'");
- $ors=array();
- if($ors=$rs->fetch()) {
- // fusion du contenu de la recherche sauevardee et de la recherche en cours.
- // on prend en priorite le contenu de la requete sauvegardee, qinit sinon
- $q1 = unserialize(stripslashes($ors['query']));
- $q2=$q1;
- foreach($qinit as $k=>$v) {
- if(!empty($qinit[$k])) $q2[$k]=$v;
- }
- $qinit=$q2;
- }
- }
- $selectedfields=array();
- $r=NULL;
- $r['operator']=@$qinit['operator'];
- if(empty($r['operator'])) $r['operator']='and';
- $parametrized=false;
- $labelin=@$qinit['labelin'];
- if(is_array($qinit)) {
- foreach($this->desc as $k => &$v) {
- if(!empty($qinit[$k.'_PAR'])) {
- $parametrized=true;
- $selectedfields[]=$k;
- unset($qinit[$k]);
- unset($qinit[$k.'_op']);
- unset($qinit[$k.'_HID']);
- unset($qinit[$k.'_PAR']);
- unset($qinit[$k.'_FMT']);
- if(!empty($labelin)) $qinit['options'][$k]['labelin']=true;
- }
- }
- if(!empty($selectedfields)) {
- $r=$this->query(array('tplentry'=>TZR_RETURN_DATA,'selectedfields'=>$selectedfields,
- 'searchmode'=>'simple','_preparedquery'=>$qinit, 'fmoid' => $qinit['fmoid']));
- }
- }
- $r['parametrized']=$parametrized;
- return $r;
- }
- /// rend vrai si la base existe
- public static function sourceExists($t) {
- XDataSource::preLoadBaseBase();
- return isset( XDataSource::$_basebase[$t] );
- }
- /// rend le libelle de la table
- public function getLabel() {
- return $this->title;
- }
- /// Rend la table de la source
- public function getTable() {
- return $this->base;
- }
- /// Rend le boid de la source
- function getBoid(){
- return $this->boid;
- }
- /// Rend le nom de la source
- function getSourceName(){
- return XDataSource::$_boid[$this->boid]->MTXT;
- }
- /// Rend un propriété d'une source via la BOID
- static function getBoidProp($boid,$prop){
- return XDataSource::$_boid[$boid]->$prop;
- }
- /// Rend un propriété d'une source via le nom de la table
- static function getTableProp($table,$prop) {
- return XDataSource::$_basebase[$table]->$prop;
- }
- public function &getPublished($field=true) {
- $links=array();
- foreach($this->desc as $i => &$v) {
- if(is_object($v)) {
- $f=$v->get_field();
- if($v->get_published()){
- if($field) $links[]=$f;
- else $links[]=$i;
- }
- }
- }
- return $links;
- }
- public function isTranslatable() {
- return ($this->translatable>0);
- }
- public function getTranslatable() {
- return $this->translatable;
- }
- public function toLog() {
- return ($this->base!='LOGS' && $this->log==1);
- }
- public function getAutoTranslate() {
- return $this->autotranslate;
- }
- /// genere les traductions dans toutes les langues
- function autoTranslate() {
- if($this->isTranslatable()) {
- $xk=new Kernel;
- $requete='select distinct KOID from '.$this->base.' where LANG="'.TZR_DEFAULT_LANG.'"';
- $rs=selectQuery($requete);
- while($rs && ($ors=$rs->fetch())) {
- $koid=$ors['KOID'];
- $xk->data_autoTranslate($koid);
- }
- $rs->closeCursor();
- }else{
- updateQuery('delete from '.$this->base.' where LANG!="'.TZR_DEFAULT_LANG.'"');
- }
- }
- public static function &getBaseList($myselfIncluded=true,$refresh=false) {
- XDataSource::preLoadBaseBase($refresh);
- $liste = array();
- foreach(XDataSource::$_basebase as $b=>&$o) {
- $liste[$b]=$o->MTXT;
- }
- asort($liste);
- return $liste;
- }
- public static function &getBaseList8($myself=true){
- XDataSource::preLoadBaseBase();
- $liste=array();
- foreach(XDataSource::$_boid as $b=>&$o){
- if($myself || (!$myself && (empty($this) || $this->boid!=$b)))
- $liste[$b]=$o->MTXT;
- }
- asort($liste);
- return $liste;
- }
- /// Créer une boite de selection de champ
- function fieldSelector($ar=NULL) {
- $p=new XParam($ar, array('tplentry'=>'','compulsory'=>true,'filter'=>array()));
- $tplentry=$p->get('tplentry');
- $fieldname=$p->get('fieldname');
- $value=$p->get('value');
- $type=$p->get('type');
- if(!is_array($type) && !empty($type)) $type=array($type);
- $compulsory=$p->get('compulsory');
- $multivalued=$p->get('multivalued');
- $filter=$p->get('filter','local');
- if($multivalued) $retval='<select name="'.$fieldname.'[]" size="6" multiple>';
- else $retval='<select name="'.$fieldname.'">';
- if(!$compulsory) $retval.='<option value="">----</option>';
- foreach($this->desc as $k => &$v) {
- if(empty($type) || in_array($v->get_ftype(),$type)){
- $ok=true;
- foreach($filter as $prop=>$val){
- if(is_array($val)){
- if(!eval('return (\''.$val[1].'\''.$val[0].'\''.$v->$prop.'\');' ) ){
- $ok=false;
- break;
- }
- }else{
- if($v->$prop!=$val){
- $ok=false;
- break;
- }
- }
- }
- if($ok) $retval.='<option value="'.$k.'" '.(isset($value) && ($value==$k || is_array($value) && in_array($k,$value))?'selected':'')." >". $v->get_label().'</option>';
- }
- }
- $retval.='</select>';
- return $retval;
- }
- function order_selector($ar=NULL) {
- $p = new XParam($ar, array('tplentry'=>'','compulsory'=>true,'random'=>true,'multiple'=>false));
- $tplentry = $p->get('tplentry');
- $LANG_USER = XShell::getLangUser();
- $LANG_DATA = XShell::getLangData();
- $fieldname=$p->get('fieldname');
- $value=$p->get('value');
- if(isset($value) && !is_array($value)) $value=array($value);
- $random=$p->get('random');
- $compulsory=$p->get('compulsory');
- $multiple=$p->get('multiple');
- $retval='<select name="'.$fieldname.'"'.($multiple?' multiple size="6"':'').'>';
- if(!$compulsory) $retval.='<option value="">---</option>';
- if($random) $retval.='<option value="RAND()">'.XLabels::getSysLabel('xdatasource.random').'</option>';
- foreach($this->desc as $k => $v) {
- $retval.='<option value="'.$k.'" '.(isset($value) && in_array($k,$value)?'selected':'').
- ' >'. $v->get_label().'</option>';
- }
- $retval.='</select>';
- return $retval;
- }
- /// rend le descriptif d'un champ
- public function getField($f) {
- return $this->desc[$f];
- }
- /// Rend la liste des champs de la table filtres par type et par propriétés
- public function &getFieldsList($type=NULL,$browsable=false,$published=false,$queryable=false,$compulsory=false,$translatable=false,
- $multivalued=false,$fields=null,$op='AND') {
- if(!is_array($fields) || empty($fields)) $fields=$this->orddesc;
- $list=array();
- $checktype=is_array($type) && !empty($type);
- foreach($fields as $i=>$f) {
- if(empty($this->desc[$f])) continue;
- $v=&$this->desc[$f];
- if($op=='AND' && (!$checktype || in_array($v->get_ftype(),$type)) && (!$browsable || $v->get_browsable()) && (!$published || $v->get_published()) && (!$queryable || $v->get_queryable()) && (!$compulsory || $v->get_compulsory()) && (!$translatable || $v->get_translatable()) && (!$multivalued || $v->get_multivalued()))
- $list[]=$f;
- elseif($op=='OR' && (($checktype && in_array($v->get_ftype(),$type)) || ($browsable && $v->get_browsable()) || ($published && $v->get_published()) || ($queryable && $v->get_queryable()) || ($compulsory && $v->get_compulsory()) || ($translatable && $v->get_translatable()) || ($multivalued && $v->get_multivalued())))
- $list[]=$f;
- }
- return $list;
- }
- /// Rend les champs indexables
- function getIndexablesFields($fields=NULL){
- if(!is_array($fields) || empty($fields)) $fields=$this->orddesc;
- $list=array();
- foreach($fields as $i=>$f) {
- if(!isset($this->desc[$f])) continue;
- if (isset($this->desc[$f]->indexable) && $this->desc[$f]->indexable == 1)
- $list[] = $f;
- }
- return $list;
- }
- /// Rend le nombre de champ non traduisible
- function getNonTranslatableFieldCount() {
- if (!isset($this->_NonTranslatableFieldCount))
- $this->_NonTranslatableFieldCount = countSelectQuery("select count(*) from DICT where DTAB='$this->base' and TRANSLATABLE!=1");
- return $this->_NonTranslatableFieldCount;
- }
- /// Fabrique une condition pour une recherche
- function make_cond($def, $v){
- return '';
- }
- function make_simple_cond($k, $v) {
- return '';
- }
- /// generation d'une condition utilisable sur le container
- function select_query($args=NULL) {
- return '';
- }
- /// Retourne une requete pour retourner des objets aléatoires
- function random_select_query($args=NULL) {
- return '';
- }
- /// Retourne une requete pour compter des objects
- function count_query($args=NULL) {
- return '';
- }
- // Fonction reservee a la creation d'une data pour la langue par defaut.
- // La creation d'une data dans tout autre code langue se fait par Kernel::data_edit() et Kernel::proc_data_edit()
- // apres avoir cree une data en l'initialisant avec la data correspondante dans le code langue par defaut.
- //
- public function input($ar=NULL) {
- $p = new XParam($ar, array( 'tplentry'=>$this->base,'hiddenfields'=>array(),'options'=>array(),'fieldssec'=>array()));
- $tplentry = $p->get('tplentry');
- $options = $p->get('options');
- $translatable= $this->getTranslatable();
- $fieldssec=$p->get('fieldssec','local');
- $module_filter=$p->get('module_filter','local');
- $moid=$p->get('fmoid','local');
- $selectedfields=$p->get('selectedfields');
- $editbatch=$p->get('editbatch');
- if(empty($selectedfields) || (is_string($selectedfields) && ($selectedfields=='all'))) $all=true;
- else $all=false;
- if(empty($selectedfields)) $selectedfields=array();
- $lang=XShell::getLangData($p->get('LANG_DATA'));
- if(($translatable!=3) && $this->isTranslatable() && ($lang!=TZR_DEFAULT_LANG)) {
- if($tplentry!=TZR_RETURN_DATA)
- XShell::redirect2error(array('message'=>'Security violation'));
- return;
- }
- $LANG_USER = XShell::getLangUser();
- $myi=0;
- $ofieldvalue=array();
- $osysvalue=array();
- foreach($this->orddesc as $i => $k) {
- if(!empty($fieldssec[$k]) && $fieldssec[$k]!='rw') continue;
- if(!($all || in_array($k,$selectedfields))) continue;
- $v=&$this->desc[$k];
- $options[$k]['fmoid']=$moid;
- $options[$k]['editbatch']=$editbatch;
- $options[$k]['module_filter']=$module_filter;
- if(!$v->sys) {
- $ofieldvalue[$myi]=$v->edit($v->default_value(),$options[$k]);
- $result['o'.$k]=$ofieldvalue[$myi];
- $myi++;
- } else {
- $value=$v->edit($v->default_value(),$options[$k]);
- $osysvalue[]=$value;
- if($k=='PUBLISH' || $k=='PRP') $result['o'.$k]=$value;
- }
- }
- $result['fields_object']= $ofieldvalue;
- $result['sysfields_object']= $osysvalue;
- $result['newoid']=$this->getNewOID($ar);
- $result['tablelabel']=$this->getLabel();
- // recherche des groupes de champs
- $groups=array();
- foreach($this->orddesc as $foo => $k) {
- if(!empty($fieldssec[$k]) && $fieldssec[$k]!='rw') continue;
- if(!($all || in_array($k,$selectedfields))) continue;
- $v=&$this->desc[$k];
- if(!$v->sysField()) {
- if(empty($v->fgroup)) $v->fgroup='General';
- if(!empty($v->fgroup)) {
- $groups[$v->fgroup][]=&$result['o'.$k];
- }
- }
- }
- ksort($groups);
- if(count($groups)>1) $result['_groups']=$groups;
- // Information sur le caractere 'translatable' ou non de toute la table
- $result['translatable'] = $this->isTranslatable();
- return XShell::toScreen1($tplentry, $result);
- }
- /// génération de l'écran de recherche
- public function query($ar=NULL) {
- $p = new XParam($ar, array( 'tplentry'=>$this->base,'selectedfields'=>'','searchmode'=>'advanced','querymode'=>'query',
- 'operator'=>'AND','genoptions'=>array(),'fieldssec'=>array()));
- $LANG_USER = XShell::getLangUser();
- $LANG_DATA = XShell::getLangData();
- $tplentry = $p->get('tplentry');
- $fieldssec=$p->get('fieldssec','local');
- $module_filter=$p->get('module_filter','local');
- $fmoid = $p->get('fmoid','local');
- $persistent=$p->get('_persistent');
- $selectedfields=$p->get('selectedfields');
- if(empty($selectedfields) || (is_string($selectedfields) && ($selectedfields=='all'))) $all=true;
- else $all=false;
- if(empty($selectedfields)) $selectedfields=array();
- $genoptions=array();
- $selectquery='';
- // on a une requete preparee qui contraint le formulaire
- $preparedquery=$p->get('_preparedquery');
- if(!empty($preparedquery)) {
- $preparedquery['getselectonly']=true;
- $preparedquery['_options']=array('local'=>1);
- // on construit la requete sql contraignante
- $selectquery=self::procQuery($preparedquery);
- if (isset($preparedquery['options']))
- $genoptions=$preparedquery['options'];
- elseif (isset($preparedquery['genoptions']))
- $genoptions=$preparedquery['genoptions'];
- }
- if ($p->is_set('options'))
- $genoptions=array_merge($genoptions,$p->get('options'));
- elseif ($p->is_set('genoptions'))
- $genoptions=array_merge($genoptions,$p->get('genoptions'));
- $searchmode=$p->get('searchmode');
- $mode=$p->get('querymode');
- $myi=0;
- $result=array();
- foreach($this->orddesc as $field){
- if(!empty($fieldssec[$field]) && $fieldssec[$field]=='none') continue;
- $v=&$this->desc[$field];
- if(!($v->get_queryable() && ($all || in_array($field,$selectedfields)))) continue;
- if(!$persistent){
- if(!empty($genoptions[$field]['value'])) {
- $initval=$genoptions[$field]['value'];
- if(!is_array($initval)) $initval=array($initval);
- } else {
- $initval=$p->get($field);
- if(!is_array($initval)){
- $initval=trim($initval);
- if(!empty($initval)) $initval=array($initval);
- }
- }
- }else{
- $initval=null;
- }
- if(!empty($genoptions[$field])) $opts1=$genoptions[$field];
- else $opts1=array();
- $opts1['searchmode']=$searchmode;
- // requete contrainte
- $opts1['select']=$selectquery;
- $opts1['fmoid']=$fmoid;
- $opts1['module_filter']=$module_filter;
- if(empty($opts1['op'])) $opts1['op']=$p->get($field.'_op');
- if($mode=='query2') $opts1['fieldname']='fieldxidxid';
- if($mode=='pquery') $ofieldvalue[$myi]=$v->pquery($initval, $opts1);
- else $ofieldvalue[$myi]=$v->query($initval, $opts1);
- if($mode=='query2') $ofieldvalue[$myi]->html.='<input type="hidden" name="_FIELDS[fieldxidxid]" value="'.$field.'">';
- $result['o'.$field]=&$ofieldvalue[$myi];
- $fieldpar[$myi]=@$genoptions[$field]['par'];
- $fieldname[$myi]=$v->get_label();
- $myi++;
- }
- if($mode=='query2') array_multisort($fieldname,SORT_STRING,$fieldpar,$ofieldvalue);
- $result['operator']=$p->get('operator');
- $result['fields_object']=&$ofieldvalue;
- $result['fields_par']=$fieldpar;
- return XShell::toScreen1($tplentry, $result);
- }
- /// Génération de l'écran de recherche rapide
- public function quickquery($ar=NULL) {
- $p=new XParam($ar,array('tplentry'=>$this->base,'selectedfields'=>'','genoptions'=>array()));
- $tplentry=$p->get('tplentry');
- $fields=$p->get('selectedfields');
- $fmoid=$p->get('fmoid','local');
- $persistent=$p->get('_persistent');
- if(!empty($fields) && is_array($fields)) $selectedfields=$fields;
- else $selectedfields=self::browsableFields($fields);
- $genoptions=$p->get('genoptions');
- if($p->is_set('options')) $genoptions=$p->get('options');
- $myi=0;
- $result=array();
- $ofieldvalue=array();
- $fieldpar=array();
- foreach($this->orddesc as $i => $field){
- $v=$this->desc[$field];
- if($v->get_queryable() && in_array($field,$selectedfields)) {
- $fieldname[$myi]=$v->get_label();
- if(!$persistent){
- if(!empty($genoptions[$field]['value'])) {
- $initval=$genoptions[$field]['value'];
- if(!is_array($initval)) $initval=array($initval);
- } else {
- $initval=$p->get($field);
- if(!is_array($initval)){
- $initval=trim($initval);
- if(!empty($initval)) $initval=array($initval);
- }
- }
- }else{
- $initval=NULL;
- }
- if(empty($genoptions[$field])) $genoptions[$field]=array();
- $genoptions[$field]['fmoid']=$fmoid;
- $genoptions[$field]['op']=$p->get($field.'_op');
- $genoptions[$field]['fields_complement'] = $ar;
- $ofieldvalue[$myi]=$v->quickquery($initval, $genoptions[$field]);
- $result['o'.$field]=$ofieldvalue[$myi];
- $ftable['o'.$field]=$ofieldvalue[$myi];
- $fieldpar[$myi]=@$genoptions[$field]['par'];
- $myi++;
- }
- }
- $result['operator']=$p->get('operator');
- $result['fields_object']=$ofieldvalue;
- $result['fields_par']=$fieldpar;
- if(!empty($ftable)) $result['fields_ftable']=$ftable;
- return XShell::toScreen1($tplentry,$result);
- }
- /// Verifie si l'oid peut etre traité par la source
- function checkOID($oid,&$ar,$f,$return=false){
- if(Kernel::getTable($oid)!=$this->base){
- if($return) return false;
- else securityWarning('XDataSource::'.$f.': Trying to use '.$oid.' with wrong XDataSource <'.$this->base.'>');
- }
- return true;
- }
- /// Génère un oid pour la source
- function getNewOID($ar=NULL){
- return self::getNewBasicOID($this->base);
- }
- /// Génère un oid au format par defaut pour une table donnée (généré à partir du timestamp avec les µs et d'un nombre aléatoire, chacun converti en base 36)
- static function getNewBasicOID($t){
- $addr=str_replace('.','', base_convert(microtime(true),10,36));
- $addr.=base_convert(rand(1,32000),10,36);
- $newoid=substr($t.':'.$addr,0,40);
- /* on verifie si le koid n'existe pas deja */
- $cnt=countSelectQuery('select COUNT(KOID) from '.$t.' where KOID="'.$newoid.'"');
- if(!$cnt) return $newoid;
- else return self::getNewBasicOID($t);
- }
- /// Génère un oid au format spécifique pour une table donnée (simple raccourci pour ne pas instancier soit meme la source pour générer un oid)
- static function getNewSpecificOID($t,$ar=NULL){
- $xset=XDataSource::objectFactoryHelper8('SPECS='.$t);
- return $xset->getNewOID($ar);
- }
- /// Generation d'un ecran d'edition
- function edit($ar=NULL) {
- $p=new XParam($ar,array('tplentry'=>$this->base,'options'=>array(),'selectedfields'=>array(),'fieldssec'=>array(),'accesslog'=>0));
- $accesslog=$p->get('accesslog');
- $tplentry = $p->get('tplentry');
- $fieldssec = $p->get('fieldssec','local');
- $moid=$p->get('fmoid','local');
- $oid=$p->get('oid');
- XLogs::debug('XDataSource::edit('.$oid.')');
- $this->checkOID($oid,$ar,'edit');
- $options=$p->get('options');
- if(!empty($GLOBALS['XLOCK'])) {
- $mode=$p->get('_mode');
- if($mode=='lock') {
- $GLOBALS['XLOCK']->lock($oid, TZR_DEFAULT_LANG, XUser::get_current_user_uid());
- $GLOBALS['XLOCK']->initLocks();
- }
- }
- $selectedfields=$p->get('selectedfields');
- if(!is_array($selectedfields)) {
- unset($selectedfields);
- $selectedfields=array();
- }
- $translatable=$this->getTranslatable();
- $LANG_DATA=$p->get('LANG_DATA');
- if(!$translatable) $LANG_DATA=TZR_DEFAULT_LANG;
- else $LANG_DATA=XShell::getLangData($LANG_DATA,true);
- $LANG_TRAD = XShell::getLangTrad($p->get('LANG_TRAD'));
- $LANG_USER = XShell::getLangUser();
- if(($translatable!=TZR_LANG_FREELANG) && !empty($LANG_TRAD) && ($LANG_TRAD!=$LANG_DATA)) {
- $ar1=$ar;
- $ar1['LANG_DATA']=$LANG_TRAD;
- $ar1['tplentry']=TZR_RETURN_DATA;
- $result=array();
- $result['d']=self::display($ar1);
- }
- $rs=selectQuery('select * from '.$this->base.
- " where KOID='$oid' and LANG='$LANG_DATA'");
- // si on ne trouve pas dans la langue en cours on regarde dans la langue de base
- if(!$ors=$rs->fetch()) {
- $rs->closeCursor();
- $rs=selectQuery('select * from '.$this->base.
- " where KOID='$oid' and LANG='".TZR_DEFAULT_LANG."'");
- $ors=$rs->fetch();
- }
- $rs->closeCursor();
- $myi=0;
- foreach($this->desc as $k=>$v) {
- if(!empty($selectedfields) && !in_array($k, $selectedfields)) continue;
- $options[$k]['oid']=$oid;
- $options[$k]['fmoid']=$moid;
- if(empty($fieldssec[$k]) || $fieldssec[$k]=='rw') $f='edit';
- elseif($fieldssec[$k]=='ro') $f='display';
- else continue;
- if($LANG_DATA!=TZR_DEFAULT_LANG && $translatable!=TZR_LANG_FREELANG && !$v->get_translatable() && $this->isTranslatable()) $f='display';
- $ofieldvalue[$myi]=&$v->$f($ors[$k],$options[$k],$ors);
- $fieldequiv[$myi] = $k;
- $result['o'.$k]=&$ofieldvalue[$myi];
- $myi++;
- }
- $rs->closeCursor();
- $result['oid']= $oid;
- $result['fields_object']=&$ofieldvalue;
- $result['tablelabel']=$this->getLabel();
- if(!empty($GLOBALS['XLOCK'])) {
- $result['_lock']=$GLOBALS['XLOCK']->locked($oid, TZR_DEFAULT_LANG);
- if(!empty($result['_lock'])) {
- $result['_lock_editable']=(empty($result['_lock'])||
- (XUser::get_current_user_uid()==$result['_lock']['OWN']));
- }
- }
- // recherche des groupes de champs
- $groups=array();
- foreach($fieldequiv as $foo => $k) {
- $v=&$this->desc[$k];
- if(!$v->sysField()) {
- if(empty($v->fgroup)) $v->fgroup='General';
- if(!empty($v->fgroup)) {
- $groups[$v->fgroup][]=&$result['o'.$k];
- }
- }
- }
- ksort($groups);
- if(count($groups)>1) $result['_groups']=$groups;
- // Log
- if($accesslog) XLogs::uniqueUpdate('access',$oid);
- // Information sur le caractere 'translatable' ou non de toute la table
- $result['translatable'] = $this->isTranslatable();
- return XShell::toScreen1($tplentry,$result);
- }
- /// publication d'une donnée (oid) ou d'un ensemble de données (_selected)
- public function publish($ar) {
- $p=new XParam($ar, array('value'=>1, '_selected'=>NULL,'key'=>true));
- $oid=$p->get('oid');
- $value=$p->get('value');
- $lang=$p->get('LANG_DATA');
- $sel = $p->get('_selected');
- $key=$p->get('key');
- if(is_array($sel) && !$key) $sel=array_flip($sel);
- if(empty($sel) && !empty($oid)) $sel=array($oid=>$value);
- // traitement de la valeur pour se ramener à 1 (oui) ou 2 (non)
- if(empty($value)) $value=2;
- if(empty($sel)) return;
- foreach($sel as $oid => $val) {
- if(Kernel::objectExists($oid)) {
- $this->procEdit(array('oid'=>$oid, 'LANG_DATA'=>$lang, 'PUBLISH'=>$value, '_options'=>array('local'=>true)));
- }
- }
- }
- /// Affichage d'un objet
- public function &display($ar) {
- $p=new XParam($ar,array('tplentry'=>$this->base,'_lastupdate'=>XShell::admini_mode(),'genempty'=>1,'selectedfields'=>array(),
- 'fieldssec'=>array(),'accesslog'=>0,'tlink'=>false));
- $tplentry = $p->get('tplentry');
- $fallback = $p->get('fallback');
- $publishedonly = $p->get('_publishedonly');
- $selectedfields=$p->get('selectedfields');
- if(!is_array($selectedfields)) {
- unset($selectedfields);
- $selectedfields=array();
- }
- $genempty = $p->get('genempty');
- $moid = $p->get('fmoid','local');
- $fieldssec = $p->get('fieldssec','local');
- $archive = $p->get('_archive');
- $accesslog=$p->get('accesslog');
- $tlink=$p->get('tlink');
- // dans le cas ou la data d'archive est codee en 9999-99-99 99:99:99
- // on enleve tous les caracteres non chiffres
- if(!empty($archive) && !preg_match('/^([0-9]+)$/',$archive)) $archive=preg_replace('/([^0-9])/','',$archive);
- $charset = $p->get('_charset');
- $table = $this->base;
- $filter='';
- $_filter = $p->get('_filter', 'local');
- if (!empty($_filter))
- $filter = ' AND '.$_filter;
- if(!empty($archive)) {
- $table='A_'.$this->base;
- $filter=" AND UPD='$archive'";
- }
- $LANG_USER = XShell::getLangUser();
- $LANG_DATA = XShell::getLangData($p->get('LANG_DATA','local'));
- if(!$this->isTranslatable()) $LANG_DATA=TZR_DEFAULT_LANG;
- $LANG_TRAD = XShell::getLangTrad($p->get('LANG_TRAD'));
- $oid = $p->get('oid');
- if(empty($oid)) {
- $r= 'XDataSource::display: no oid';
- return $r;
- }
- $this->checkOID($oid,$ar,'display');
- XLogs::debug('XDataSource::display('.$oid.')');
- $options = $p->get('options');
- $_format=$p->get('_format');
- $_options = $p->get('_options');
- $lastupdate = $p->get('_lastupdate');
- $genpublishtag= @$_options['genpublishtag'];
- $error = @$_options['error'];
- $published=$this->publishedMode($p);
- if(!isset($genpublishtag)) $genpublishtag=true;
- XAudit::plusplus('display('.$table.')');
- // Recherche de l'objet en base et génération d'une erreur si introuvable
- $rs=selectQuery('SELECT * FROM '.$table.' WHERE KOID="'.$oid.'" AND LANG="'.$LANG_DATA.'" '.$filter);
- if(!$ors=$rs->fetch()) {
- if($this->isTranslatable() || $fallback) {
- $rs->closeCursor();
- $rs=selectQuery('SELECT * FROM '.$table.' WHERE KOID="'.$oid.'" AND LANG="'.$LANG_TRAD.'" '.$filter);
- if(!$ors=$rs->fetch()) {
- if($error=='return') return $r='XDataSource('.$table.')->display: could not find object with oid='.$oid.' and lang='.$LANG_DATA.'<br/>';
- else XShell::quit('XDataSource('.$table.')->display: could not find object with oid='.$oid.' and lang='.$LANG_DATA.'<br/>');
- }
- } else {
- if($error=='return') return $r='XDataSource('.$table.')->display: could not find object with oid='.$oid.' and lang='.$LANG_DATA.'<br/>';
- else XShell::quit('XDataSource('.$table.')->display: could not find object with oid='.$oid.' and lang='.$LANG_DATA.'<br/>');
- }
- }
- $rs->closeCursor();
- // Fiche non publié
- if($published=='public' && $ors['PUBLISH']!=1) {
- if($error=='return') return $r='XDataSource('.$table.')->display: data '.$oid.' has not been published has public<br/>';
- else XShell::quit('XDataSource('.$table.')->display: data '.$oid.' has not been published has public<br/>');
- }
- $result=array();
- // Si on est dans l'admin, vérification de la génération du champ publié ou non
- if($genpublishtag && XShell::admini_mode() && ($published=='marked')) {
- $mark=$ors['PUBLISH'];
- if($mark=='1') $pubval='checked';
- else $pubval='';
- $result['_PUBLISH_tag']='<input type="checkbox" class="checkbox" name="_PUBLISH['.$oid.']" '.$pubval.'/>';
- $result['_PUBLISH_tag'].='<input type="hidden" name="_PUBLISH_H['.$oid.']" value="'.$mark.'"/>';
- }
- // Display sur chaque champ
- $result['fields_object']=array();
- $result['link']='';
- if($tlink) $result['tlink']='';
- foreach($this->desc as $k => &$v) {
- if((!empty($selectedfields) && !in_array($k, $selectedfields)) || (!empty($fieldssec[$k]) && $fieldssec[$k]=='none')) continue;
- if(($v->get_published() && $publishedonly) || !isset($publishedonly)) {
- $val=$ors[$k];
- // Calcul des options d'affichage
- $opt=@$options[$k];
- if(!empty($moid)) $opt['fmoid']=$moid;
- if($published=='marked' && $ors['PUBLISH']=='2') $opt['_published']=false;
- else $opt['_published']=true;
- if(!empty($archive)) $opt['_archive']=$archive;
- if(!empty($charset)) $opt['_charset']=$charset;
- $opt['_format']=$_format;
- // Nouvel objet d'affichage
- $o=&$v->display($val,$opt);
- $result['o'.$k]=$o;
- // Construction de fields_object et du lien avec les champs publié
- if($genempty || $o->html!='') {
- $result['fields_object'][]=$o;
- if($v->get_published()) {
- if(!empty($result['link'])) $result['link'].=' ';
- $result['link'].=$o->html;
- if($tlink){
- if(!empty($result['tlink'])) $result['tlink'].=' ';
- $result['tlink'].=$o->text;
- }
- }
- }
- }
- }
- $result['oid']= $oid;
- // Information sur le caractere 'translatable' ou non de toute la table
- $result['translatable']=$this->isTranslatable();
- if($result['translatable'] && isset($LANG_TRAD)) {
- $cnt=countSelectQuery("select COUNT(KOID) from $table where KOID='$oid' and LANG='$LANG_TRAD' $filter");
- if($cnt<=0) $result['_translation_ok']='0';
- else $result['_translation_ok']='1';
- }
- // information sur la langue générée
- $result['_lang_data']=$LANG_DATA;
- if(!empty($LANG_TRAD) && ($LANG_TRAD!=$LANG_DATA)) {
- $ar['tplentry']=TZR_RETURN_DATA;
- $ar['LANG_DATA']=$LANG_TRAD;
- $r2=self::display($ar);
- $result['d']=$r2;
- }
- // Etat du verouillage de la fiche
- if(!empty($GLOBALS['XLOCK'])) {
- $result['_lock']=$GLOBALS['XLOCK']->locked($oid,$LANG_DATA);
- $result['_lock_user'] = $GLOBALS['XLOCK']->getUser($oid,$LANG_DATA);
- $result['_lock_editable']=(empty($result['_lock']) || (XUser::get_current_user_uid()==$result['_lock']['OWN']));
- }
- // Derniere mise à jour
- if(!empty($lastupdate)) $result['lst_upd']=XLogs::getLastUpdate($oid,(!empty($result['oUPD'])?$result['oUPD']->raw:NULL));
- // Recherche des groupes de champs
- $groups=array();
- foreach($this->orddesc as $foo => $k) {
- $v=&$this->desc[$k];
- if(!$v->sysField()) {
- if(empty($v->fgroup)) $v->fgroup='General';
- if(!empty($v->fgroup) && !empty($result['o'.$k])) $groups[$v->fgroup][]=&$result['o'.$k];
- }
- }
- ksort($groups);
- if(count($groups)>1) $result['_groups']=$groups;
- // Log
- if($accesslog) XLogs::uniqueUpdate('access',$oid);
- return XShell::toScreen1($tplentry,$result);
- }
- /// affichage d'une objet
- public function &display2($ar) {
- $p = new XParam($ar, array('_lastupdate'=>XShell::admini_mode(),
- 'genempty'=>1));
- $publishedonly = $p->get('_publishedonly');
- $genempty = $p->get('genempty');
- $archive = $p->get('_archive');
- // dans le cas ou la data d'archive est codee en 9999-99-99 99:99:99
- // on enleve tous les caracteres non chiffres
- if(!empty($archive) && !preg_match('/^([0-9]+)$/',$archive)) $archive=preg_replace('/([^0-9]+)/','',$archive);
- $charset = $p->get('_charset');
- $table = $this->base;
- $filter='';
- if(!empty($archive)) {
- $table='A_'.$this->base;
- $filter=" AND UPD='$archive' ";
- }
- $LANG_USER = XShell::getLangUser();
- $LANG_DATA = XShell::getLangData($p->get('LANG_DATA','local'));
- if(!$this->isTranslatable()) $LANG_DATA=TZR_DEFAULT_LANG;
- $oid = $p->get('oid');
- XLogs::debug('XDataSource::display2('.$oid.')');
- $r=array();
- if(empty($oid)) return $r;
- $this->checkOID($oid,$ar,'display2');
- $options = $p->get('options');
- $_format=$p->get('_format');
- $_options = $p->get('_options');
- $lastupdate = $p->get('_lastupdate');
- $genpublishtag=@$_options['genpublishtag'];
- $published=$this->publishedMode($p);
- if(!isset($genpublishtag)) $genpublishtag=true;
- $verb='display2('.$table.')';
- XAudit::plusplus($verb);
- $rs=selectQuery("SELECT * FROM $table WHERE KOID='$oid' AND LANG='$LANG_DATA' $filter");
- if(!$ors=$rs->fetch()) {
- return $r;
- }
- $rs->closeCursor();
- if(($published=='public') && ($ors['PUBLISH']!=1)) {
- return $r;
- }
- $result=array();
- // si on est dans l'admin, vérification de la génération du champ publié ou non
- if($genpublishtag && XShell::admini_mode() && ($published=='marked')) {
- $mark=$ors['PUBLISH'];
- if($mark=='1') $pubval='checked';
- else $pubval='';
- $result['_PUBLISH_tag']='<input type="checkbox" class="checkbox" name="_PUBLISH['.$oid.']" '.$pubval.'/>';
- $result['_PUBLISH_tag'].='<input type="hidden" name="_PUBLISH_H['.$oid.']" value="'.$mark.'"/>';
- }
- $myi=0;
- $link='';
- $tlink='';
- foreach($this->desc as $k => &$v) {
- if(($v->get_published() && $publishedonly)||!isset($publishedonly)) {
- $val = $ors[$k];
- // calcul des options d'affichage
- $opt = $options[$k];
- if(($published=='marked') && ($ors['PUBLISH']=='2'))
- $opt['_published']=false;
- else
- $opt['_published']=true;
- if(!empty($archive))
- $opt['_archive']=$archive;
- $opt['_format']=$_format;
- if(!empty($charset)) {
- $opt['_charset']=$charset;
- }
- // nouvel objet d'affichage
- $o=&$v->display($val,$opt);
- $result['o'.$k]=$o;
- if($genempty || ($o->html!='')) {
- $result['fields_object'][$myi]=$o;
- $result[$k]=$o->html;
- $result['fields_field'][$myi]=$k;
- $myi++;
- if($v->get_published()) {
- if(!empty($link)) {
- $link.=' ';
- $tlink.=' ';
- }
- $link.=$o->html;
- $tlink.=$o->text;
- }
- }
- }
- }
- $result['link']=$link;
- $result['tlink']=$tlink;
- $result['oid']= $oid;
- if(!empty($lastupdate)) {
- $result['lst_upd']=XLogs::getLastUpdate($oid);
- }
- XLogs::debug('XDataSource::display2: end '.$oid);
- return $result;
- }
- public function &rDisplayText($oid, $LANG_DATA='', $LANG_USER='', $opts=array()) {
- if(empty($LANG_USER)) $LANG_USER=XShell::getLangUser();
- if(empty($LANG_DATA)) $LANG_DATA=XShell::getLangData();
- $fallback = true;
- $table = $this->base;
- $charset=@$opts['_charset'];
- $_format=@$opts['_format'];
- $fmoid=@$opts['fmoid'];
- $selectedfields=@$opts['selectedfields'];
- if(!$this->isTranslatable()) $LANG_DATA=TZR_DEFAULT_LANG;
- $verb='rDisplayText('.$table.')';
- XAudit::plusplus($verb);
- if(is_array($oid)) {
- $ors=$oid;
- $oid=$ors['KOID'];
- } else {
- $p=new XParam(array(),NULL);
- $rs=&selectQuery('SELECT * FROM '.$table.' WHERE KOID="'.$oid.'" AND LANG="'.$LANG_DATA.'"');
- if(!$ors=$rs->fetch()) {
- $ret='XDataSource('.$table.')::rDisplayText: could not find object with oid='.$oid.' and lang='.$LANG_DATA.'<br/>';
- XLogs::critical('rDisplayText',$ret);
- return $ret;
- }elseif($this->publishedMode($p)=='public' && array_key_exists('PUBLISH',$ors) && $ors['PUBLISH']!=1){
- XLogs::critical('rDisplayText', 'XDataSource('.$table.')::rDisplayText: Unpublished object with oid='.$oid.' and lang='.$LANG_DATA);
- return $ret='UNPUBLISHED';
- }
- $rs->closeCursor();
- }
- $result=array();
- $myi=0;
- $tlink='';
- foreach($this->desc as $k => &$v) {
- if($selectedfields == 'all' || $v->get_published() || (!empty($selectedfields) && in_array($k,$selectedfields))) {
- $val = $ors[$k];
- // calcul des options d'affichage
- if(isset($options[$k])) $opt = $options[$k];
- else $opt=array();
- if(!empty($fmoid)) $opt['fmoid']=$fmoid;
- $opt['_published']=true;
- $opt['_format']=$_format;
- if(!empty($charset)) {
- $opt['_charset']=$charset;
- }
- // nouvel objet d'affichage
- $o=&$v->display($val,$opt);
- if(!empty($tlink)) $tlink.=" ";
- $tlink.=$o->toText();
- }
- }
- $result['link']=$tlink;
- $result['oid']= $oid;
- return $result;
- }
- /**
- * generation d'infos d'affichage simplifiees a partir d'un oid
- * utilisé en particulier pour le display des champs liens
- * @param KOID $oid
- * @param PDO_STATEMENT $ors si renseigné écrase l'oid par $ors['KOID'], (utilisé ?)
- * @param bool $publishedonly retourner uniquement les champs publiés
- * @param string $LANG_DATA
- * @param string $LANG_USER
- * @param $opts [ tableau d'options indirectes
- * selectedfields : tableau des champs sql à calculer (ou 'all')
- * ...
- * ]
- * @return array [
- * array fields_object : array of XFieldVal Object, integer key
- * XFieldVal Object ofield : pour chaque champ retourné
- * string link : représentation html
- * KOID oid
- * bool translatable
- * ]
- */
- public function &rDisplay($oid,$ors=array(),$publishedonly=false,$LANG_DATA='',$LANG_USER='',$opts=array()) {
- if(empty($LANG_USER)) $LANG_USER=XShell::getLangUser();
- if(empty($LANG_DATA)) $LANG_DATA=XShell::getLangData();
- $table=$this->base;
- $charset=@$opts['_charset'];
- $_format=@$opts['_format'];
- $fmoid=@$opts['fmoid'];
- $lastupdate=@$opts['_lastupdate'];
- $selectedfields=@$opts['selectedfields'];
- if(!$this->isTranslatable()) $LANG_DATA=TZR_DEFAULT_LANG;
- XLogs::debug('XDataSource::rDisplay('.$oid.')');
- XAudit::plusplus('rDisplay('.$table.')');
- if(!empty($ors)) {
- $oid=$ors['KOID'];
- } else {
- $ar=array();
- $p=new XParam($ar,NULL);
- $rs=selectQuery('SELECT * FROM '.$table.' WHERE KOID="'.$oid.'" AND LANG="'.$LANG_DATA.'"');
- if(!$rs || !$ors=$rs->fetch()){
- $ret='XDataSource('.$table.')::rDisplay: could not find object with oid='.$oid.' and lang='.$LANG_DATA.'<br/>';
- XLogs::critical('rDisplay',$ret);
- return $ret;
- }elseif($this->publishedMode($p)=='public' && array_key_exists('PUBLISH',$ors) && $ors['PUBLISH']!=1){
- XLogs::critical('rDisplay', 'XDataSource('.$table.')::rDisplay: Unpublished object with oid='.$oid.' and lang='.$LANG_DATA);
- return $ret='UNPUBLISHED';
- }
- $rs->closeCursor();
- }
- $link='';
- $result=array('fields_object'=>array());
- foreach($this->desc as $k => &$v) {
- if($selectedfields == 'all' || (($v->get_published() && $publishedonly) || !$publishedonly) && (empty($selectedfields) || in_array($k,$selectedfields))) {
- $val = $ors[$k];
- // calcul des options d'affichage
- if(isset($opts[$k])) $opt = $opts[$k];
- else $opt=array();
- if(!empty($fmoid)) $opt['fmoid']=$fmoid;
- if (empty($opt['selectedfields']))
- $opt['_published']=true;
- $opt['_format']=$_format;
- if(!empty($charset)) $opt['_charset']=$charset;
- // Nouvel objet d'affichage
- $o=&$v->display($val,$opt);
- $result['o'.$k]=$o;
- $result['fields_object'][]=$o;
- if($v->get_published()) {
- if(!empty($link)) $link.=' ';
- $link.=$o->html;
- }
- }
- }
- $result['link']=$link;
- $result['oid']=$oid;
- // Derniere mise à jour
- if(!empty($lastupdate)) $result['lst_upd']=XLogs::getLastUpdate($oid,$result['oUPD']->raw);
- // Information sur le caractere 'translatable' ou non de toute la table
- $result['translatable']=$this->isTranslatable();
- return $result;
- }
- /// Affichage d'une donnee dont l'oid est $oid, via la methode rdisplay
- public static function objectDisplayHelper($oid) {
- $x=XDataSource::objectFactoryHelper8('SPECS='.$oid);
- if(!empty($x) && Kernel::objectExists($oid)) return $x->display(array('oid'=>$oid));
- else return NULL;
- }
- /****m* XDataSource/fdisplay
- * NAME
- * XDataSource::fdisplay - affichage detaille d'un champ
- * DESCRIPTION
- * Permet d'afficher le contenu detaille d'un champ, fonction utilisée
- * principalement pour l'affichage detaille.
- ****/
- public function fdisplay($ar) {
- $p = new XParam($ar, array('tplentry'=>$this->base,
- // liste des champs qui seront affichés sur des liens
- // si on ne veut pas prendre les published par defaut
- 'genempty'=>1));
- $tplentry = $p->get('tplentry');
- $field = $p->get('field');
- $LANG_USER = XShell::getLangUser();
- $LANG_DATA = XShell::getLangData($p->get('LANG_DATA'));
- if(!$this->isTranslatable()) $LANG_DATA=TZR_DEFAULT_LANG;
- $verb='fdisplay('.$this->base.')';
- XAudit::plusplus($verb);
- $ar['tplentry']=TZR_RETURN_DATA;
- $r=self::display($ar);
- XShell::toScreen2($tplentry, 'field', $r['o'.$field]);
- }
- /*****
- Fonction : XDataSource::gen_random_display_mask()
- Description : Display d'1 tuple pris aléatoirement.
- *****/
- function gen_random_display_mask($ar=NULL) {
- $query = $this->random_select_query($ar);
- $rs=selectQuery($query);
- $ors=array();
- if ( $ors=$rs->fetch()) $oid = $ors['KOID'];
- $ar['oid'] = $oid;
- $this->display($ar);
- $rs->closeCursor();
- }
- // Fonction reservee a la creation d'une data pour la langue par defaut.
- // La creation d'une data dans tout autre code langue se fait par Kernel::data_edit() et Kernel::proc_data_edit()
- // apres avoir cree une data en l'initialisant avec la data correspondante dans le code langue par defaut.
- //
- public function procInput($ar=NULL) {
- $this->preUpdateTasks($ar);
- $p=new XParam($ar, array('tplentry'=>$this->base,'_inputs'=>array(),'options'=>array()));
- $tplentry = $p->get('tplentry');
- $j=$p->get('_nojournal');
- $journal=empty($j);
- $moid=$p->get('fmoid','local');
- $nolog=$p->get('_nolog','local');
- $all=$p->get('_allfields');
- $fieldssec=$p->get('fieldssec','local');
- $delayed=$p->get('_delayed');
- if(!empty($delayed)) $delayed='LOW_PRIORITY ';
- else $delayed='';
- $options=$p->get('options');
- // Si option est un champ
- if(is_string($options)) $options=array();
- $unique=$p->get('_unique');
- $updateifexists = $p->get('_updateifexists');
- $unique_val = array();
- $insert = true;
- $jn='';
- // Nouvel oid puisqu'on cree une nouvelle data en langue par defaut
- $oid=$p->get('newoid'); // permet d'imposer le KOID
- if(!empty($oid) && empty($updateifexists)) {
- $cnt=countSelectQuery("select COUNT(KOID) from {$this->base} where KOID='$oid' limit 1");
- if($cnt) {
- XLogs::notice('XDataSource::procInput', $oid.' already exist');
- return array('error'=>true,'message'=>$oid.' already exist');
- }
- }
- if(empty($oid)) $oid=$this->getNewOID($ar);
- else $this->checkOID($oid,$ar,'procInput');
- // traitement des langues
- $translatable = $this->getTranslatable();
- if(!$this->isTranslatable()) $lang=TZR_DEFAULT_LANG;
- elseif($translatable==3)
- $lang=XShell::getLangData($p->get('LANG_DATA'));
- else {
- $lang=XShell::getLangData($p->get('LANG_DATA'));
- if($lang!=TZR_DEFAULT_LANG) return array('error'=>true,'message'=>'Lang error');
- }
- $query = $jn."INSERT {$delayed}INTO ".$this->base.'(';
- $fields='KOID,LANG';
- $values="'$oid','".$lang."'";
- $nottorepeat=array('UPD');
- if($this->fieldExists('OWN') && !$p->get('OWN')) {
- $fields.=',OWN';
- $values.=",'".XUser::get_current_user_uid()."'";
- $nottorepeat[]='OWN';
- }
- if($this->fieldExists('CREAD')) {
- $fields.=',CREAD';
- $values.=",'".date('Y-m-d H:i:s')."'";
- $nottorepeat[]='CREAD';
- }
- if($this->fieldExists('PUBLISH') && !$p->is_set('PUBLISH')) {
- $fields.=',PUBLISH';
- $values.=",'2'";
- $nottorepeat[]='PUBLISH';
- }
- $inputs=$p->get('_inputs','local');
- $inputvalues=array();
- foreach($this->desc as $k => &$v) {
- if(!empty($fieldssec[$k]) && $fieldssec[$k]!='rw') continue;
- if(($p->is_set($k) || $p->is_set($k.'_HID') || !empty($all)) && !in_array($k, $nottorepeat)) {
- $value = $p->get($k);
- $value_hid = $p->get($k.'_HID');
- // traitement en post edit dans les cas simples
- if(!is_object($v)) XShell::quit(array('message'=>'XDataSource::procInput: '.$this->base.':'.$k.' is not a valid field'));
- $options[$k]['oid']=$oid;
- $options[$k][$k.'_HID']=$value_hid;
- $options[$k][$k.'_title']=$p->get($k.'_title');
- $options[$k]['fmoid']=$moid;
- $r1=$v->post_edit($value,$options[$k],$inputs);
- $inputs[$k]=$r1;
- $nvalue=$r1->raw;
- $fields .= ','.$k;
- if(!empty($unique) && in_array($k, $unique)) $unique_val[]="$k like '$nvalue'";
- // cas ou on garde la valeur
- $value=$nvalue;
- if(is_array($value) && (count($value)>1)) {
- $finalval='||';
- foreach($value as $o1=>$o2)
- $finalval.=$o2.'||';
- $values.=",'".$finalval."'";
- } elseif(is_array($value)) {
- list($o1,$o2)=each($value);
- $values.=',?';
- $inputvalues[]=$o2;
- } …
Large files files are truncated, but you can click here to view the full file