/[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.1 - (hide annotations)
Sat Nov 22 18:36:38 2003 UTC (20 years, 9 months ago) by udo
Branch: MAIN
initial commit

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     * $Id: EditPageForm.php,v 1.3 2003/11/14 18:04:13 udo Exp $
15     */
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     if (is_array($this->_set_items[$key])) {
133     $show_element = $value . $this->_show_lang . "s";
134     $set_element = $value . $this->_set_lang . "u";
135    
136     if ((strlen($this->_set_items[$key]['lvalue']) < 40) && (strlen($this->_show_items[$key]['lvalue']) < 40)) {
137     $this->add_element( new FEText($show_element, true, 40, 60));
138     $this->add_element( new FEText($set_element, true, 40, 60));
139     } else{
140     $this->add_element( new FETextArea($show_element, true, 10, 40));
141     $this->add_element( new FETextArea($set_element, true, 10, 40));
142    
143     }
144     $myElement = &$this->get_element($show_element);
145     $myElement->set_attribute("readonly");
146     }
147     }
148     }
149    
150     function form_init_data() {
151    
152    
153     foreach($this->_show_items as $key => $value) {
154     if (is_array($value)) {
155     $show_element = $value['lkey'] . $this->_show_lang . "s";
156     $set_element = $value['lkey'] . $this->_set_lang . "u";
157    
158     $this->set_element_value($show_element, $this->_show_items[$key]['lvalue']);
159     $this->set_element_value($set_element, $this->_set_items[$key]['lvalue']);
160    
161     $myElement = &$this->get_element($show_element);
162     $myElement->set_label_text($value['lkey']);
163     $myElement->set_required(false);
164    
165     $myElement = &$this->get_element($set_element);
166     $myElement->set_label_text($value['lkey']);
167     $myElement->set_required(false);
168     }
169     }
170     }
171    
172     function form_content() {
173    
174     $table = &html_table(600, 0, 2);
175     switch ($this->_show_lang) {
176     case 'de':
177     $showLanguange = " german";
178     break;
179     case 'en':
180     $showLanguange = " english";
181     break;
182     case 'tr':
183     $showLanguange = " turkish";
184     break;
185     }
186     switch ($this->_set_lang) {
187     case 'de':
188     $setLanguange = " german";
189     break;
190     case 'en':
191     $setLanguange = " english";
192     break;
193     case 'tr':
194     $setLanguange = " turkish";
195     break;
196     }
197     $table->add_row("translate from" . $showLanguange, "translate to" . $setLanguange );
198     $all_elements_translated = 0;
199    
200     foreach($this->_show_items as $key => $value) {
201     if (is_array($value)) {
202     $all_elements_translated++;
203     $show_element = $value['lkey'] . $this->_show_lang . "s";
204     $set_element = $value['lkey'] . $this->_set_lang . "u";
205    
206     $inner_table_left = &html_table();
207     $inner_table_left->add_row($this->element_label($show_element));
208     $inner_table_left->add_row($this->element_form($show_element));
209     $inner_table_right = &html_table();
210     $inner_table_right->add_row($this->element_label($set_element));
211     $inner_table_right->add_row($this->element_form($set_element));
212    
213     $table->add_row($inner_table_left, $inner_table_right );
214     }
215     }
216     if ($all_elements_translated == 0) {
217     $table = &html_table(600, 0, 2);
218     if (count($this->_set_items)>0) {$table->add_row("all items are translated!");}
219     else {$table->add_row("no items found");}
220     }
221     $this->add_form_block("", $table );
222     }
223    
224     function form_action() {
225     $data = array();
226    
227     foreach ($this->_set_items as $key=>$value) {
228     if (is_array($value)) {
229     array_push($data, $this->_set_items[$key]);
230     }
231     }
232    
233     //$this->_options['data_locator_meta']['action'] = "write";
234     //$this->_options['data_locator_meta']['data'] = $data;
235     //$error = $this->data_prefetch();
236    
237     }
238     function form_backend_validation() {
239     $this->set_action("Confirm");
240     return TRUE;
241     }
242     function confirm_action() {
243     return TRUE;
244     }
245     }
246    
247    
248     ?>

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