/[cvs]/nfo/php/libs/org.netfrag.patches/phphtmllib/forms/EditPageForm.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.patches/phphtmllib/forms/EditPageForm.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Mon Dec 1 23:34:35 2003 UTC (20 years, 8 months ago) by udo
Branch: MAIN
Changes since 1.1: +46 -28 lines
bugfix

1 udo 1.1 <?
2     /**
3     * This file contains the EditPageForm child class.
4     *
5     *
6     * @package org.netfrag.patches
7     * @name EditPageForm
8     *
9     */
10    
11     /**
12     * Cvs-Log
13     *
14 udo 1.2 * $Id: EditPageForm.php,v 1.1 2003/11/22 18:36:38 udo Exp $
15 udo 1.1 */
16     // this is an abstract form-class to edit LangText - content.
17     class EditPageForm extends EditDataItem {
18    
19     // _show_lang is the language to be shown readonly
20     var $_show_lang;
21     // _set_lang is the language to be entered and updated in the Langtext-table
22     var $_set_lang;
23     // _show_items are the items that will be shown
24     var $_show_items = array();
25     // _set_items are the items, that will maybe be changed an updated
26     var $_set_items = array();
27     // undone is true, if the user selected to show untranslated items only
28     var $_undone;
29     // all LangText - entries that contain the string _sql_key will be selected.
30     // this is passed dependent on which topic is selected in the page_news - class
31     var $_sql_key;
32    
33     function EditPageForm($title, $width, $whichKey, $show_lang, $set_lang, $undone, $options) {
34     $this->_show_lang = $show_lang;
35     $this->_set_lang = $set_lang;
36     $this->_sql_key = $whichKey;
37     $this->_undone = $undone;
38     $parent = get_parent_class($this);
39     $this->$parent($title, $options);
40     }
41    
42     function form_init_elements() {
43    
44     // hidden element for page control
45     $this->add_hidden_element( 't', 'News' );
46    
47     // used_keys are all lkeys, that contain the _sql_key
48     $used_keys = array();
49    
50     // the _datasource->result - object is parsed and the matching items are
51     // written into the arrays
52     foreach($this->_datasource->_result as $key => $value) {
53     if (strstr ( $value['lkey'], $this->_sql_key)) {
54     if (!in_array($value['lkey'], $used_keys)) {array_push($used_keys, $value['lkey']);}
55     if ($value['lcountrykey'] == $this->_show_lang) {array_push($this->_show_items, $value);}
56     if ($value['lcountrykey'] == $this->_set_lang) {array_push($this->_set_items, $value);}
57     }
58     }
59    
60     // this function is needed, because _set_items and _show_items may contain a
61     // different amount of entries.
62     // the follogwing is all about sorting the both arrays in a way, that the same
63     // entries have the same key and filling up entries, if theres an entry missing because
64     // its not yet translated.
65     function get_nested_array_by_lkey($whichArray=array(), $whichKey) {
66     foreach ($whichArray as $key=>$value) {
67     if ($value['lkey'] == $whichKey) {return $value;}
68     }
69     }
70    
71    
72     // this is needed for sorting
73     $tmp_array = array();
74     $larger = array();
75     // this is needed because the arrays may have to be filled with an array
76     $empty_array = array("lvalue" => "", "lkey" => "", "lcountrykey" => "", "guid" => "" );
77    
78     // the smaller array is backuped in tmp_array and then killed.
79     // the larger array is parsed an doing this we reset the smaller array form the
80     // backup in the right order. if there is an entry missing in the smaller
81     // array this key will not be filled here.
82     if (count($this->_set_items) > count($this->_show_items)) {
83     $larger = $this->_set_items;
84     $tmp_array = $this->_show_items;
85     $this->_show_items = array();
86     foreach ($this->_set_items as $key=>$value) {
87     $this->_show_items[$key] = get_nested_array_by_lkey($tmp_array, $value['lkey']);
88     }
89     } else if (count($this->_set_items) < count($this->_show_items)) {
90     $larger = $this->_show_items;
91     $tmp_array = $this->_set_items;
92     $this->_set_items = array();
93     foreach ($this->_show_items as $key=>$value) {
94     $this->_set_items[$key] = get_nested_array_by_lkey($tmp_array, $value['lkey']);
95     }
96     } else {
97     $larger = $this->_show_items;
98     }
99    
100     // both arrays are parsed and missing entries (without a key) are filled
101     // with the empty_array. missing lkeys are filled with the lkey from used_keys,
102     // so that now every key of the arrays has matching entries. this is important,
103     // because otherwise the empty fields could not be named.
104    
105     foreach ($used_keys as $key => $value) {
106     if (!is_array(get_nested_array_by_lkey($this->_set_items, $value))) {
107     $this->_set_items[$key] = $empty_array;
108     $this->_set_items[$key]['lkey'] = $value;
109     }
110     if (!is_array(get_nested_array_by_lkey($this->_show_items, $value))) {
111     $this->_show_items[$key] = $empty_array;
112     $this->_show_items[$key]['lkey'] = $value;
113     }
114     }
115    
116    
117     // is _undone is selected, that means that the user only wants to see the items that
118     // are not yet translated, every entry, that has lvalues in both arrays, is marked.
119     if ($this->_undone == "yes") {
120     foreach ($used_keys as $key => $value) {
121     if ((strlen($this->_set_items[$key]['lvalue']) > 0) && (strlen($this->_show_items[$key]['lvalue']) > 0)) {
122     $this->_set_items[$key] = "kickedMarkerXXX";
123     $this->_show_items[$key] = "kickedMarkerXXX";
124     }
125     }
126     }
127    
128    
129     // the elements of the form are created
130     foreach($used_keys as $key => $value) {
131     // if the entry == kickedMarkerXXX, $value will be no array
132 udo 1.2 if ($this->_set_items[$key] != "kickedMarkerXXX") {
133     $show_el = $value . $this->_show_lang . "s";
134     $set_el = $value . $this->_set_lang . "u";
135    
136     print "array_show_el: " .$show_el. "<br>";
137     print "array_set_el: " .$set_el. "<br>";
138 udo 1.1
139     if ((strlen($this->_set_items[$key]['lvalue']) < 40) && (strlen($this->_show_items[$key]['lvalue']) < 40)) {
140 udo 1.2 $this->add_element( new FEText($show_el, true, 40, 60));
141     $this->add_element( new FEText($set_el, true, 40, 60));
142 udo 1.1 } else{
143 udo 1.2 $this->add_element( new FETextArea($show_el, true, 10, 40));
144     $this->add_element( new FETextArea($set_el, true, 10, 40));
145 udo 1.1
146     }
147 udo 1.2 // $myElement = &$this->get_element($show_el);
148     // $myElement->set_attribute("readonly");
149     } else {
150     print "no_show_el: " .$key. "<br>";
151     print "no_set_el: " .$key. "<br>";
152     }
153 udo 1.1 }
154 udo 1.2
155 udo 1.1 }
156    
157     function form_init_data() {
158 udo 1.2
159 udo 1.1 foreach($this->_show_items as $key => $value) {
160     if (is_array($value)) {
161 udo 1.2 $show_el = $value['lkey'] . $this->_show_lang . "s";
162     $set_el = $value['lkey'] . $this->_set_lang . "u";
163    
164     if (!empty($this->_show_items[$key]['lvalue'])) {
165     //print "show_item: " .$key. "<br>";
166     $this->set_element_value($show_el, $this->_show_items[$key]['lvalue']);
167     } else {
168     //print "empty_show_item: " .$key. "<br>";
169     $this->set_element_value($show_el, "xxx");
170     }
171     if (!empty($this->_set_items[$key]['lvalue'])) {
172     //print "set_item: " . $key . "<br>";
173     $this->set_element_value($set_el, $this->_set_items[$key]['lvalue']);
174     } else {
175     //print "empty_set_item: " .$key. "<br>";
176     $this->set_element_value($set_el, "xxx");
177     }
178 udo 1.1
179 udo 1.2 /* $myElement = &$this->get_element($show_el);
180 udo 1.1 $myElement->set_label_text($value['lkey']);
181     $myElement->set_required(false);
182    
183 udo 1.2 $myElement = &$this->get_element($set_el);
184 udo 1.1 $myElement->set_label_text($value['lkey']);
185 udo 1.2 $myElement->set_required(false);*/
186 udo 1.1 }
187     }
188     }
189    
190     function form_content() {
191    
192     $table = &html_table(600, 0, 2);
193     switch ($this->_show_lang) {
194     case 'de':
195     $showLanguange = " german";
196     break;
197     case 'en':
198     $showLanguange = " english";
199     break;
200     case 'tr':
201     $showLanguange = " turkish";
202     break;
203     }
204     switch ($this->_set_lang) {
205     case 'de':
206     $setLanguange = " german";
207     break;
208     case 'en':
209     $setLanguange = " english";
210     break;
211     case 'tr':
212     $setLanguange = " turkish";
213     break;
214     }
215     $table->add_row("translate from" . $showLanguange, "translate to" . $setLanguange );
216     $all_elements_translated = 0;
217    
218     foreach($this->_show_items as $key => $value) {
219     if (is_array($value)) {
220     $all_elements_translated++;
221 udo 1.2 $show_el = $value['lkey'] . $this->_show_lang . "s";
222     $set_el = $value['lkey'] . $this->_set_lang . "u";
223 udo 1.1
224     $inner_table_left = &html_table();
225 udo 1.2 // $inner_table_left->add_row($this->element_label($show_el));
226     $inner_table_left->add_row($this->element_form($show_el));
227 udo 1.1 $inner_table_right = &html_table();
228 udo 1.2 // $inner_table_right->add_row($this->element_label($set_el));
229     $inner_table_right->add_row($this->element_form($set_el));
230 udo 1.1
231     $table->add_row($inner_table_left, $inner_table_right );
232     }
233     }
234     if ($all_elements_translated == 0) {
235     $table = &html_table(600, 0, 2);
236     if (count($this->_set_items)>0) {$table->add_row("all items are translated!");}
237     else {$table->add_row("no items found");}
238     }
239     $this->add_form_block("", $table );
240     }
241    
242     function form_action() {
243     $data = array();
244    
245     foreach ($this->_set_items as $key=>$value) {
246     if (is_array($value)) {
247     array_push($data, $this->_set_items[$key]);
248     }
249     }
250    
251     //$this->_options['data_locator_meta']['action'] = "write";
252     //$this->_options['data_locator_meta']['data'] = $data;
253     //$error = $this->data_prefetch();
254    
255     }
256     function form_backend_validation() {
257     $this->set_action("Confirm");
258     return TRUE;
259     }
260     function confirm_action() {
261     return TRUE;
262     }
263     }
264    
265    
266 udo 1.2 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed