34d4d8d74105e2f908c6131fa630134f8581538d
[Pman.Core] / DataObjects / Core_templatestr.php
1 <?php
2 /**
3  * Table Definition for core_templatestr
4  *
5  *
6  * The idea here is that it contains all the strings in the templates with a language '' (empty)
7  * , it then generates a matching set of strings
8  * 
9  */
10 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
11
12 class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject 
13 {
14     ###START_AUTOCODE
15     /* the code below is auto generated do not remove the above tag */
16
17     public $__table = 'core_templatestr';         // table name
18     public $id;                              // int(11)  not_null primary_key auto_increment
19     public $template_id;                           // string(64)  not_null
20     public $txt;                    // datetime(19)  multiple_key binary
21     public $updated;                        // blob(65535)  blob
22     public $src_id;                          // int(11)  not_null
23     public $lang;    // text  NOT NULL;
24     public $mdsum;    // text  NOT NULL;
25     public $active;
26     public $on_table;
27     public $on_id;
28     public $on_col;
29  
30     /* the code above is auto generated do not remove the tag below */
31     ###END_AUTOCODE
32     
33     function beforeInsert($q,$roo)
34     {
35         if(!empty($q['_rescan'])){
36             $this->syncLang($q['_rescan']);
37             $roo->jok('OK');
38         }
39     }
40     
41     
42     function applyFilters($q, $au, $roo)
43     {
44         if (!empty($q['_tree'])) {
45             $this->applyFiltersTree($q,$roo);
46         }
47         
48         if(!empty($q['on_table']) && (empty($q['template_id']) || !is_numeric($q['template_id']))){
49             $this->template_id = 0;
50              $this->whereAdd("  join_src_id_id.txt != ''");
51         }
52         if (!empty($q['_search_txt'])) {
53             $str = $this->escape($q['_search_txt']);
54             $this->whereAdd("core_templatestr.txt like '%{$str}%' OR join_src_id_id.txt like '%{$str}%'");
55             
56         }
57     }
58     function translateTableCol($obj, $col, $lang)
59     {
60         $cts = DB_DataObject::factory('core_templatestr');
61         $cts->lang = $lang;
62         $cts->on_table = $obj->tableName();
63         $cts->on_id = $obj->pid();
64         $cc = clone($cts);
65         if(!$cts->find(true)){
66             return $obj->$col;
67         }
68         
69         
70         if(empty($cts->txt)){
71             return $obj->$col;
72         }
73             
74         return $cts->txt;
75     }
76     /**
77      *
78      * insert the origanal table text
79      * 
80      * @param type $roo
81      * @param type $obj
82      * @param type $chg
83      * @return type 
84      */
85     function onTableChange($roo, $obj, $chg)
86     {
87         
88         $ff = HTML_FlexyFramework::get()->Pman_Core;
89             
90         if(empty($ff['DataObjects_Core_templatestr']['tables'])){
91             return;
92         }
93         $tn = $obj->tableName();
94         if(empty($ff['DataObjects_Core_templatestr']['tables'][$tn])){
95             return;
96         }
97         $cols = $ff['DataObjects_Core_templatestr']['tables'][$tn];
98
99         foreach($cols as $c) {
100
101             // skip if empty string
102             if(empty($obj->$c)) {
103                 continue;
104             }
105             
106             if(strpos($c, ',') !== false) {
107                 $arr = explode(',', $c);
108                 $c = $arr[0];
109                 $cond = $arr[1];
110
111                 $ar = explode('=', $cond);
112                 $key = $ar[0];
113
114                 // skip if condition not fulfilled
115                 if($obj->{$ar[0]} != $ar[1]) {
116                     continue;
117                 }
118             }
119
120             $x = $this->factory($this->tableName());
121             $x->on_id = $obj->pid();
122             $x->on_table = $tn;
123             $x->on_col = $c;
124             $x->lang = ''; /// eg. base language..
125             $up = $x->find(true);
126
127             // skip when no change
128             if($up && $x->txt == $obj->$c) {
129                 continue;
130             }
131
132             $x->active = 1;
133             $x->src_id = 0;
134             $x->txt = $obj->$c;
135             $x->mdsum = md5($obj->$c);
136             $x->template_id = 0;
137             $x->updated = date('Y-m-d H:i:s', strtotime("NOW"));
138             $up ? $x->update() : $x->insert();
139         }
140
141         // if(count($unused)) {
142         //     $t = DB_DataObject::factory($this->tableName());
143         //     // deactivate the parent data
144         //     $t->query("UPDATE core_templatestr
145         //               SET active = 0 WHERE id in (" . implode(',' ,$unused) . ")
146         //              ");
147
148         //     // deactivate the child data
149         //     $t->query("UPDATE  core_templatestr 
150         //     SET active = 0
151         //     WHERE
152         //         src_id IN (". implode(',' , $unused) . ")
153         //         AND
154         //         lang != ''
155         //      ");
156         // }
157
158         // if(count($used)) {
159         //     $t = DB_DataObject::factory($this->tableName());
160         //     // activate the aprent data
161         //     $t->query("UPDATE core_templatestr
162         //         SET active = 1 WHERE id in (" . implode(',' ,$active) . ")
163         //     ");
164         //     // deactivate the child data
165         //     $t->query("UPDATE  core_templatestr 
166         //     SET active = 1
167         //       WHERE
168         //          src_id IN (". implode(',' ,$active) . ")
169         //         AND
170         //         lang != ''
171         //     ");
172         // }
173         
174         
175     }
176
177     function syncTableWords()
178     {
179         $ff = HTML_FlexyFramework::get()->Pman_Core;
180             
181         if(empty($ff['DataObjects_Core_templatestr']['tables'])){
182             return;
183         }
184
185         $tables = array();
186         foreach($ff['DataObjects_Core_templatestr']['tables'] as $table => $cols) {
187             $tables[]
188         }
189
190         $cts = DB_DataObject::factory($this->tableName());
191         $cts->whereAdd('on_table != ""');
192         $old = clone($cts);
193         $cur = $cts->fetchAll();
194
195         foreach($cur as $ts) {
196             var_dump($ts->on_table);
197             var_dump($ts->on_col);
198         }
199         die('b');
200     }
201     
202     
203     function applyFiltersTree($q,$roo)
204     {
205         if (empty($q['node'])) {
206             $roo->jerr("invalid node");
207         }
208         switch(true) {
209             
210             case ($q['node'] == 'transtree'):
211             case ($q['node'] == 'langlist'):
212                // DB_DataObject::debugLevel(1);
213                 $x = DB_Dataobject::Factory($this->tableName());
214                 $x->selectAdd();
215                 $x->selectAdd('distinct(lang) as lang');
216                 
217                 $x->selectAdd("i18n_translate('l', lang, 'en') as lang_name");
218                 $x->whereAdd("lang != ''");
219                 $ret= array();
220                 foreach( $x->fetchAll() as $l) {
221                     $ret[] = array(
222                         'text'=>$l->lang_name,
223                         'id' => $q['node'] == 'langlist' ? $l->lang : 'lang:'.$l->lang ,
224                         'language' => true
225                     );
226                 }
227                 if (empty($ret)) {
228                     $ret[] = array(
229                         'text'=>'English',
230                         'id' => 'lang:en',
231                         'language' => true
232                     );
233                 }
234                 $roo->jdata($ret);
235             
236             case  preg_match('/^lang:/', $q['node']):
237                 
238                 $lang = preg_replace('/^lang:/', '', $q['node']);
239                 $ret= array();  
240                 $x = DB_DataObject::factory('core_templatestr');
241                 $x->autoJoin();
242                 $x->selectAdd();
243                 $x->selectAdd('distinct(view_name) as view_name');
244                 $x->lang = $lang;
245                 $x->whereAdd('join_template_id_id.is_deleted = 0');
246                 $x->orderBy('view_name DESC');
247                 $x->find();
248                 while($x->fetch()) {
249                     $ret[] = array( 
250                         'text'=> $x->view_name,
251                         'id' => 'view:'. $lang .':'.  $x->view_name,
252                         'leaf' => false
253                     );
254                 }
255
256                 $ff = HTML_FlexyFramework::get()->Pman_Core;
257
258                 if(!empty($ff['DataObjects_Core_templatestr']['tables'])){
259                     foreach($ff['DataObjects_Core_templatestr']['tables'] as $table=>$v){
260                         $ret[] = array(
261                             'text'=> $table,
262                             'on_table' => $table,
263                             'id' => 'table:'. $lang .':'. $table,
264                             'leaf' => true
265                         );
266                     }
267                 }
268                 
269                  
270                 $roo->jdata($ret);
271                 
272                 break;
273                 
274                 
275             case  preg_match('/^view:/', $q['node']):
276                 
277                
278                 $bits= explode(":",preg_replace('/^view:/', '', $q['node']));
279                 
280                 $x = DB_DataObject::factory($this->tableName());
281                 $x->autoJoin();
282                 $x->selectAdd();
283                 $x->selectAdd('distinct(core_templatestr.template_id) as template_id');
284                 $x->whereAdd("join_template_id_id.view_name = '{$x->escape($bits[1])}'");
285                 $x->whereAdd('join_template_id_id.is_deleted = 0');
286                 $x->lang = $bits[0];
287                 $ids = $x->fetchAll('template_id');
288                 
289                 $ret= array();
290                 //add the table type lists
291                 /*
292                 $ff = HTML_FlexyFramework::get()->Pman_Core;
293                 
294                 
295 //                $x->orderBy('template ASC');
296 //                $x->whereAdd("lang != ''");
297                 */
298                 //below are old code
299                 $xx = DB_Dataobject::Factory('core_template');
300                 $xx->whereAddIn('id', $ids, 'int');
301                 $xx->selectAdd();
302                 $xx->selectAdd("
303                                
304                     id, concat(  template) as template_name
305                 ");
306                 $xx->orderBy('template_name ASC');
307                 
308                 foreach( $xx->fetchAll('id', 'template_name') as $l =>$n) {
309                     $ret[] = array(
310                         'text'=> $n,
311                         'id' => $l,
312                         'leaf' => true
313                     );
314                 }
315                 
316                 $roo->jdata($ret);
317                  break;
318         }
319                 
320         
321         
322     }
323     
324     
325     /**
326      *
327      * 
328      * @param object $tmpl core_template data object
329      * @param array $words array of words 
330      */ 
331     function syncTemplateWords($tmpl, $keyvalue = false)
332     {
333         
334         $words = $tmpl->words;
335         // mapping for template : 
336         //tablename => $n (templatename) 
337         //tableid => $k (key value)
338         //colname => $n (templatename) 
339         // mdsum => md5(sum)
340         //
341         //print_r($words);exit;
342         // grab original
343         $tt = DB_DataObject::factory($this->tableName());
344  
345         $t = clone($tt);
346         $t->template_id = $tmpl->id;
347         $t->whereAdd("lang = ''");
348         
349         
350         // we have a situation where old md sums where created..
351         
352         
353         
354         $cur = $t->fetchAll('mdsum', 'id'); 
355         
356         
357         
358         
359         
360         
361         
362         // now loop through current..
363         $cwords = array();// not in used??
364         $active = array();
365 //        echo "sync Template Words... \n";
366 //        print_r($words);
367         
368         foreach($words as $k=>$v) {
369             
370             
371             $v = trim($v);
372
373             // skip empty words
374             if(empty($v)) {
375                 continue;
376             }
377             
378             $md = $keyvalue ? $k : md5($v);
379             
380             // check to see if there are more that one versions of that md5
381             
382             
383             if (!isset($cur[$md])) {
384                 // create a record for it..
385                 $t = DB_DataObject::factory($this->tableName());
386                 $t->setFrom(array(
387                     'txt' => $v,
388                     'lang' => '',// by default should a english 
389                     'updated' => date('Y-m-d H:i:s', strtotime("YESTERDAY")),
390                     'template_id'=>$tmpl->id,
391                     'mdsum' => $md,
392                     'src_id' => 0,
393                     'active' => 1,
394                 ));
395                 $active[] =  $t->insert();
396                 continue;
397             }  
398             $cur[$md] = $this->checkDupes($tmpl->id, '',  $cur[$md] , $md);
399             
400             $active[] = $cur[$md];
401             
402             // we have it already? - 
403             $t = DB_DataObject::factory($this->tableName());
404             $t->query("UPDATE {$this->tableName()}
405                         SET active= 1
406                         WHERE
407                         id = ".$cur[$md]);
408             unset($cur[$md]);
409             
410         }
411         // delete unused.
412         
413         
414         
415
416         $deactive = array();
417         if (count(array_values($cur))) {// de-active unused
418
419             $t = DB_DataObject::factory($this->tableName());
420 //            echo "de-active current?? \n";
421 //            print_r($cur);
422 //            echo "\n";
423             $deactive = array_values($cur);
424             $t->query("UPDATE core_templatestr
425                       SET active = 0 WHERE id in (" . implode(',' ,$deactive) . ")
426                      ");
427         }
428         
429         // delete all the items that are not relivant.
430         // clear orphaned chidren - it just blanks out the src id, so they can be used as suggestions..?
431         // this does not help - as it just puts random strings in there.. - with no reference to the original text..
432         $t = DB_DataObject::factory($this->tableName());
433     
434         // this will active the child data
435         if (empty($active)) {// set the active array to empty
436             $active = array(-1);
437         }
438         $t->query("UPDATE  core_templatestr 
439                 SET active = 1
440                   WHERE
441                      src_id IN (". implode(',' ,$active) . ")
442                     AND
443                     template_id = {$tmpl->id}
444         ");
445         //deactive the child data
446         if (empty($deactive)) {
447             $deactive = array(-1);
448         }
449         $t->query("UPDATE  core_templatestr 
450                 SET active = 0
451                   WHERE
452                     src_id IN (". implode(',' ,$deactive) . ")
453                     AND
454                     template_id = {$tmpl->id}
455                     AND
456                     lang != ''
457         ");
458     }
459     
460     function checkDupes($tid, $lang, $id, $mdsum) {
461         
462         $t = DB_DataObject::factory($this->tableName());
463         $t->template_id = $tid;
464         $t->mdsum = $mdsum;
465         $t->whereAdd("lang = '{$lang}'");
466         if ($t->count() == 1) {
467             return $id; // only got one ... no issues..
468         }
469         
470         //echo "GOT DUPES : $id, $lang, $id , $mdsum\n";
471         
472         //DB_DataObject::debugLevel(1);
473         // find out if any of them have got translations.
474         $ids = $t->fetchAll('id');
475         
476         
477         $t = DB_DataObject::factory($this->tableName());
478         $t->whereAddIn('src_id', $ids, 'int');
479         $t->whereAdd("txt != ''");
480         $t->orderBy('updated DESC');
481         if ($t->count()) {
482             $t->limit(1);
483             // do any translations exist?
484             $t->find(true);
485             $id = $t->src_id;
486         }
487         
488         
489         // delete all the others...
490         $t = DB_DataObject::factory($this->tableName());
491         $t->whereAddIn('src_id', $ids, 'int');
492         $t->whereAdd("src_id != $id");
493         $t->find();
494         while($t->fetch()) {
495             $tt = clone($t);
496             $tt->mdsum = $t->mdsum . '-bad-'. $t->id;
497             $tt->update($t);
498         }
499         $t = DB_DataObject::factory($this->tableName());
500         $t->whereAddIn('id', $ids, 'int');
501         $t->whereAdd("id != $id");
502         $t->find();
503         while($t->fetch()) {
504             $tt = clone($t);
505             $tt->mdsum = $t->mdsum . '-bad-'. $t->id;
506             $tt->update($t);
507         }
508         // this is done by calling code 
509         //$t = DB_DataObject::factory($this->tableName());
510         //$t->query("update core_templatestr set active= 1 where src_id = $id");
511         
512         
513         
514        //exit;
515         return $id;
516     
517                
518          
519     }
520     
521     function syncLang($lang)
522     {
523         // bugs with our old code...
524 //        die('in?');
525         $tn = $this->tableName();
526         $t = DB_DataObject::factory($tn);
527         $t->query("DELETE FROM {$tn} WHERE lang !='' AND src_id = 0 AND on_table  = ''");
528         
529         // find all the id's from lang that have not been generated..
530         
531         
532         static $id_tmp = false;
533         
534         if ($id_tmp == false) {
535             //find the origanal 
536             $t = DB_DataObject::factory($tn);
537             $t->whereAdd("lang = ''");
538             $t->active = 1;
539             
540             //old code, this did not support the on_table
541     //        $id_tmp = $t->fetchAll('id','template_id');
542     //        $ids = array_keys($id_tmp);
543             $id_tmp = array();
544             //new code for support the sync tables 
545             foreach($t->fetchAll() as $ori){
546                 $id_tmp[$ori->id] = $ori;
547             }
548         }
549         $ids = array_keys($id_tmp);
550         
551         // matching by language:
552         $t = DB_DataObject::factory($tn);
553         $t->whereAddIn('src_id', $ids , 'int');
554         $t->lang = $lang;
555         //$t->active = 1;
556         $got = $t->fetchAll('src_id');
557         $missing = array_diff($ids, $got);
558         
559         if (empty($missing)) {
560             return;
561         }
562         $t = DB_DataObject::factory($tn);
563         $q = "CREATE TEMPORARY TABLE core_templatestr_insert SELECT
564             id as src_id,
565             '' as txt,
566             '$lang' as lang,
567             NOW() as updated,
568             template_id,
569             on_table,
570             on_id,
571             on_col,
572             1 as active
573             FROM core_templatestr
574             WHERE
575             id IN (". implode(',', $missing) . ")
576         ";
577         //echo $q; exit;
578         DB_DataObject::factory($tn)->query($q);
579         $q = "INSERT INTO $tn (src_id, txt, lang, updated, template_id, on_table,on_id, on_col, active) SELECT * FROM core_templatestr_insert";
580         DB_DataObject::factory($tn)->query($q);
581         $q = "DROP TEMPORARY TABLE core_templatestr_insert";
582         DB_DataObject::factory($tn)->query($q);
583             
584       
585         
586     }
587     
588     // called from flexy to translate a string.
589     
590     
591     function translateFlexyString($flexy, $string)
592     {
593          $debug = false;;
594         //if (!empty($_REQUEST['_debug'])) { $debug= true; }
595         
596         // using $flexy->currentTemplate -> find the template we are looking at..
597         // then find the string for $flexy->options['locale']
598         //DB_DataObject::debugLevel(1);
599         if ($debug) { var_dump($string); }
600         
601         static $cache = array(); // cache of templates..
602         
603         $ff = HTML_FlexyFramework::get();
604         $view_name = isset($ff->Pman_Core['view_name']) ? $ff->Pman_Core['view_name'] : false;
605         if (empty($view_name)) {
606             $pg = HTML_FlexyFramework::get()->page;
607             if (isset($pg->templateViewName)) {
608                 $view_name = $pg->templateViewName;
609             }
610             
611         }
612         
613         
614         
615         if ($debug) { var_dump(array('view_name'=> $view_name)); }
616         
617         $tempdir = '';
618         foreach($flexy->options['templateDir'] as $td) {
619             if (substr($flexy->currentTemplate, 0, strlen($td)) == $td) {
620                 $tempdir = $td;
621                 break;
622             }
623         }
624         
625         
626         $tmpname = substr($flexy->currentTemplate, strlen($td) +1);
627         
628          
629         if (isset($cache[$tmpname]) && $cache[$tmpname] === false) {
630             if ($debug) { echo "from cache no match - $string\n"; }
631             return $string;
632         }
633         
634         if (!isset($cache[$tmpname])) {
635                 
636             
637             
638             $tmpl = DB_DataObject::factory('core_template');
639             if ($view_name !== false) {
640                 $tmpl->view_name = $view_name;
641             }
642             if(!$tmpl->get('template', $tmpname)){
643                 // strip of site prefix if set...
644                  
645                 $tmpl = DB_DataObject::factory('core_template');
646                 if(!$tmpl->get('template', $tmpname)){
647                     //var_dump("no template? {$tmpname} or {$relpath}" );
648                     $cache[$tmpname] = false;
649                     if ($debug) { echo "no template found - no match - $string\n"; }
650                     return $string;
651                 }
652             }
653             $cache[$tmpname] = $tmpl;
654         } else {
655             $tmpl = $cache[$tmpname] ;
656         }
657         
658         
659     
660         //get original template id
661         /*
662         $orig = DB_DataObject::factory($this->tableName());
663         $orig->lang = '';
664         $orig->template_id = $tmpl->id;
665         $orig->active = 1;
666         
667         $cache[$tmpname]->words = 
668         
669         if(!$orig->get( 'mdsum' , md5(trim($string)))){
670              //var_dump('no text? '. $string);
671             if ($debug) { echo "no original string found tplid: {$tmpl->id}\n"; }
672             return false;
673         }
674         */
675         
676         if (empty($cache[$tmpname]->translations)) {
677         
678             //find out the text by language
679             //DB_DataObject::DebugLevel(1);
680             $x = DB_DataObject::factory($this->tableName());
681             $x->lang = $flexy->options['locale'];
682             $x->template_id = $tmpl->id;
683             $x->autoJoin();
684             $cache[$tmpname]->translations = $x->fetchAll('src_id_mdsum', 'txt');
685             if (empty($cache[$tmpname]->translations)) {
686                 $cache[$tmpname]->translations = true;
687             }
688             //var_Dump($cache[$tmpname]->translations);
689         }
690         
691         
692         if ($cache[$tmpname]->translations === true) {
693             return $string;
694         }
695         //var_dump("Checking: " . md5(trim($string)));
696         
697         if (!empty($cache[$tmpname]->translations [md5(trim($string))])){
698            // var_dump("RETURNING: ". $cache[$tmpname]->translations [md5(trim($string))]);
699             return $cache[$tmpname]->translations [md5(trim($string))];
700         }
701         return $string;
702         
703     }
704     
705     
706     function translateChanged($flexy)
707     {
708         
709         $date = $this->lastUpdated($flexy);
710         if ($date === false) {
711             return false;
712         }
713         $utime = file_exists($flexy->compiledTemplate) ?  filemtime( $flexy->compiledTemplate) : 0;
714         return strtotime($date) >  $utime;
715     }
716     
717     // determine if a complied template need recompling
718     
719     function lastUpdated($flexy)
720     {
721         //return true;
722         // var_dump('check changed?');
723         //DB_DataObject::debugLevel(1);
724         //var_Dump(array($flexy->options['templateDir'][0], $flexy->currentTemplate));
725         
726         //var_dump($flexy->compiledTemplate);
727         $utime = file_exists($flexy->compiledTemplate) ?  filemtime( $flexy->compiledTemplate) : 0;
728         
729        
730         static $cache = array(); // cache of templates..
731         
732         $ff = HTML_FlexyFramework::get();
733         $view_name = isset($ff->Pman_Core['view_name']) ? $ff->Pman_Core['view_name'] : false;
734         
735         // find which of the template directories was actually used for the template.
736         
737         $tempdir = '';
738         foreach($flexy->options['templateDir'] as $td) {
739             if (substr($flexy->currentTemplate, 0, strlen($td)) == $td) {
740                 $tempdir = $td;
741                 break;
742             }
743         }
744         
745         
746         $tmpname = substr($flexy->currentTemplate, strlen($td) +1);
747         
748         // we do not have any record of this template..
749         if (isset($cache[$tmpname]) && $cache[$tmpname] === false) {
750             return false;
751         }
752         
753         if (!isset($cache[$tmpname])) {
754                 
755             
756             
757             $tmpl = DB_DataObject::factory('core_template');
758             if ($view_name !== false) {
759                 $tmpl->view_name = $view_name;
760             }
761             if(!$tmpl->get('template', $tmpname)){
762                 // strip of site prefix if set...
763                  
764                 $tmpl = DB_DataObject::factory('core_template');
765                 if(!$tmpl->get('template', $tmpname)){
766                     //var_dump("no template? {$tmpname} or {$relpath}" );
767                     $cache[$tmpname] = false;
768                     return false;
769                 }
770             }
771             $cache[$tmpname] = $tmpl;
772         } else {
773             $tmpl = $cache[$tmpname] ;
774         }
775           
776          
777         
778         $x = DB_DataObject::factory($this->tableName());
779         $x->lang = $flexy->options['locale'];
780         $x->active = 1;
781         $x->template_id = $tmpl->id;
782         //$x->whereAdd("updated > '". date('Y-m-d H:i:s', $utime)."'");
783         if ($x->count() < 1) {
784             return false; // we don't have any record of it.
785         }
786         $x->selectAdd();
787         $x->selectAdd('max(updated) as max_updated');
788         $x->find(true);
789         return $x->max_updated;
790         
791         
792     }
793     
794     function toRooArray($req) {
795         $ret = $this->toArray();
796
797         if (empty($req['csvCols'])) {
798             return $ret;
799         }
800
801         // for download
802
803         // translations for table columns
804         if(!empty($ret['on_table']) && !empty($ret['on_id']) && !empty($ret['on_col'])) {
805             $ret['template_id_view_name'] = 'database';
806             $ret['template_id_template'] = $ret['on_table'] . ':' . $ret['on_col'];
807         }
808
809         return $ret;
810     }
811
812     function postListFilter($ar, $au, $req)
813     {
814         if (empty($req['csvCols'])) {
815             return $ar;
816         }
817
818         // for download
819
820         $ret = array();
821
822         foreach($ar as $v) {
823             if(empty($v['on_table']) || empty($v['on_id']) || empty($v['on_col'])) {
824                 $ret[] = $v;
825                 continue;
826             }
827
828             // translations for table columns
829             // avoid duplicate (same src_id_mdsum, same on_table, same on_col, but different on_id)
830
831             $key = $v['on_table'] . ':' . $v['on_col'] . ':' . $v['src_id_mdsum'];
832
833             if(!empty($ret[$key])) {
834                 continue;
835             }
836
837             $ret[$key] = $v;
838         }
839
840         $ret = array_values($ret);
841         
842         return $ret;
843
844     }
845 }