Changed context help organization to enable use of central, multilanguage wiki.
[fa-stable.git] / dimensions / dimension_entry.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_DIMENSION';
13 $path_to_root = "..";
14 include_once($path_to_root . "/includes/session.inc");
15
16 include_once($path_to_root . "/includes/date_functions.inc");
17 include_once($path_to_root . "/includes/manufacturing.inc");
18 include_once($path_to_root . "/includes/data_checks.inc");
19
20 include_once($path_to_root . "/admin/db/tags_db.inc");
21 include_once($path_to_root . "/dimensions/includes/dimensions_db.inc");
22 include_once($path_to_root . "/dimensions/includes/dimensions_ui.inc");
23
24 $js = "";
25 if ($use_date_picker)
26         $js .= get_js_date_picker();
27 page(_($help_context = "Dimension Entry"), false, false, "", $js);
28
29 //---------------------------------------------------------------------------------------
30
31 if (isset($_GET['trans_no']))
32 {
33         $selected_id = $_GET['trans_no'];
34
35 elseif(isset($_POST['selected_id']))
36 {
37         $selected_id = $_POST['selected_id'];
38 }
39 else
40         $selected_id = -1;
41 //---------------------------------------------------------------------------------------
42
43 if (isset($_GET['AddedID'])) 
44 {
45         $id = $_GET['AddedID'];
46
47         display_notification_centered(_("The dimension has been entered."));
48
49         safe_exit();
50 }
51
52 //---------------------------------------------------------------------------------------
53
54 if (isset($_GET['UpdatedID'])) 
55 {
56         $id = $_GET['UpdatedID'];
57
58         display_notification_centered(_("The dimension has been updated."));
59         safe_exit();
60 }
61
62 //---------------------------------------------------------------------------------------
63
64 if (isset($_GET['DeletedID'])) 
65 {
66         $id = $_GET['DeletedID'];
67
68         display_notification_centered(_("The dimension has been deleted."));
69         safe_exit();
70 }
71
72 //---------------------------------------------------------------------------------------
73
74 if (isset($_GET['ClosedID'])) 
75 {
76         $id = $_GET['ClosedID'];
77
78         display_notification_centered(_("The dimension has been closed. There can be no more changes to it.") . " #$id");
79         safe_exit();
80 }
81
82 //---------------------------------------------------------------------------------------
83
84 if (isset($_GET['ReopenedID'])) 
85 {
86         $id = $_GET['ReopenedID'];
87
88         display_notification_centered(_("The dimension has been re-opened. ") . " #$id");
89         safe_exit();
90 }
91
92 //-------------------------------------------------------------------------------------------------
93
94 function safe_exit()
95 {
96         global $path_to_root;
97
98         hyperlink_no_params("", _("Enter a &new dimension"));
99         echo "<br>";
100         hyperlink_no_params($path_to_root . "/dimensions/inquiry/search_dimensions.php", _("&Select an existing dimension"));
101
102         display_footer_exit();
103 }
104
105 //-------------------------------------------------------------------------------------
106
107 function can_process()
108 {
109         global $selected_id, $Refs;
110
111         if ($selected_id == -1) 
112         {
113
114         if (!$Refs->is_valid($_POST['ref'])) 
115         {
116                 display_error( _("The dimension reference must be entered."));
117                         set_focus('ref');
118                 return false;
119         }
120
121         if (!is_new_reference($_POST['ref'], ST_DIMENSION)) 
122         {
123                 display_error(_("The entered reference is already in use."));
124                         set_focus('ref');
125                 return false;
126         }
127         }
128
129         if (strlen($_POST['name']) == 0) 
130         {
131                 display_error( _("The dimension name must be entered."));
132                 set_focus('name');
133                 return false;
134         }
135
136         if (!is_date($_POST['date_']))
137         {
138                 display_error( _("The date entered is in an invalid format."));
139                 set_focus('date_');
140                 return false;
141         }
142
143         if (!is_date($_POST['due_date']))
144         {
145                 display_error( _("The required by date entered is in an invalid format."));
146                 set_focus('due_date');
147                 return false;
148         }
149
150         return true;
151 }
152
153 //-------------------------------------------------------------------------------------
154
155 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) 
156 {
157         if (!isset($_POST['dimension_tags']))
158                 $_POST['dimension_tags'] = array();
159                 
160         if (can_process()) 
161         {
162
163                 if ($selected_id == -1) 
164                 {
165                         $id = add_dimension($_POST['ref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
166                         add_tag_associations($id, $_POST['dimension_tags']);
167                         meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
168                 } 
169                 else 
170                 {
171
172                         update_dimension($selected_id, $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
173                         update_tag_associations(TAG_DIMENSION, $selected_id, $_POST['dimension_tags']);
174
175                         meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
176                 }
177         }
178 }
179
180 //--------------------------------------------------------------------------------------
181
182 if (isset($_POST['delete'])) 
183 {
184
185         $cancel_delete = false;
186
187         // can't delete it there are productions or issues
188         if (dimension_has_payments($selected_id) || dimension_has_deposits($selected_id))
189         {
190                 display_error(_("This dimension cannot be deleted because it has already been processed."));
191                 set_focus('ref');
192                 $cancel_delete = true;
193         }
194
195         if ($cancel_delete == false) 
196         { //ie not cancelled the delete as a result of above tests
197
198                 // delete
199                 delete_dimension($selected_id);
200                 delete_tag_associations(TAG_DIMENSION,$selected_id, true);
201                 meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
202         }
203 }
204
205 //-------------------------------------------------------------------------------------
206
207 if (isset($_POST['close'])) 
208 {
209
210         // update the closed flag
211         close_dimension($selected_id);
212         meta_forward($_SERVER['PHP_SELF'], "ClosedID=$selected_id");
213 }
214
215 if (isset($_POST['reopen'])) 
216 {
217
218         // update the closed flag
219         reopen_dimension($selected_id);
220         meta_forward($_SERVER['PHP_SELF'], "ReopenedID=$selected_id");
221 }
222 //-------------------------------------------------------------------------------------
223
224 start_form();
225
226 start_table($table_style2);
227
228 if ($selected_id != -1)
229 {
230         $myrow = get_dimension($selected_id);
231
232         if (strlen($myrow[0]) == 0) 
233         {
234                 display_error(_("The dimension sent is not valid."));
235                 display_footer_exit();
236         }
237
238         // if it's a closed dimension can't edit it
239         //if ($myrow["closed"] == 1) 
240         //{
241         //      display_error(_("This dimension is closed and cannot be edited."));
242         //      display_footer_exit();
243         //}
244
245         $_POST['ref'] = $myrow["reference"];
246         $_POST['closed'] = $myrow["closed"];
247         $_POST['name'] = $myrow["name"];
248         $_POST['type_'] = $myrow["type_"];
249         $_POST['date_'] = sql2date($myrow["date_"]);
250         $_POST['due_date'] = sql2date($myrow["due_date"]);
251         $_POST['memo_'] = get_comments_string(ST_DIMENSION, $selected_id);
252         
253         $tags_result = get_tags_associated_with_record(TAG_DIMENSION, $selected_id);
254         $tagids = array();
255         while ($tag = db_fetch($tags_result)) 
256                 $tagids[] = $tag['id'];
257         $_POST['dimension_tags'] = $tagids;     
258
259         hidden('ref', $_POST['ref']);
260
261         label_row(_("Dimension Reference:"), $_POST['ref']);
262
263         hidden('selected_id', $selected_id);
264
265 else 
266 {
267         $_POST['dimension_tags'] = array();
268         ref_row(_("Dimension Reference:"), 'ref', '', $Refs->get_next(ST_DIMENSION));
269 }
270
271 text_row_ex(_("Name") . ":", 'name', 50, 75);
272
273 $dim = get_company_pref('use_dimension');
274
275 number_list_row(_("Type"), 'type_', null, 1, $dim);
276
277 date_row(_("Start Date") . ":", 'date_');
278
279 date_row(_("Date Required By") . ":", 'due_date', '', null, $SysPrefs->default_dimension_required_by());
280
281 tag_list_row(_("Tags:"), 'dimension_tags', 5, TAG_DIMENSION, true);
282
283 textarea_row(_("Memo:"), 'memo_', null, 40, 5);
284
285 end_table(1);
286
287 if (isset($_POST['closed']) && $_POST['closed'] == 1)
288         display_note(_("This Dimension is closed."), 0, 0, "class='currentfg'");
289
290 if ($selected_id != -1) 
291 {
292         echo "<br>";
293         submit_center_first('UPDATE_ITEM', _("Update"), _('Save changes to dimension'), 'default');
294         if ($_POST['closed'] == 1)
295                 submit('reopen', _("Re-open This Dimension"), true, _('Mark this dimension as re-opened'), true);
296         else    
297                 submit('close', _("Close This Dimension"), true, _('Mark this dimension as closed'), true);
298         submit_center_last('delete', _("Delete This Dimension"), _('Delete unused dimension'), true);
299 }
300 else
301 {
302         submit_center('ADD_ITEM', _("Add"), true, '', 'default');
303 }
304 end_form();
305
306 //--------------------------------------------------------------------------------------------
307
308 end_page();
309
310 ?>