*** empty log message ***
[fa-stable.git] / dimensions / dimension_entry.php
1 <?php
2
3
4 $page_security = 10;
5 $path_to_root="..";
6 include_once($path_to_root . "/includes/session.inc");
7
8 page(_("Dimension Entry"));
9
10 include_once($path_to_root . "/includes/date_functions.inc");
11 include_once($path_to_root . "/includes/manufacturing.inc");
12 include_once($path_to_root . "/includes/data_checks.inc");
13
14 include_once($path_to_root . "/dimensions/includes/dimensions_db.inc");
15 include_once($path_to_root . "/dimensions/includes/dimensions_ui.inc");
16
17 //---------------------------------------------------------------------------------------
18
19 if (isset($_GET['trans_no']))
20 {
21         $selected_id = $_GET['trans_no'];
22
23 elseif(isset($_POST['selected_id']))
24 {
25         $selected_id = $_POST['selected_id'];
26 }
27 else
28         $selected_id = -1;
29 //---------------------------------------------------------------------------------------
30
31 if (isset($_GET['AddedID'])) 
32 {
33         $id = $_GET['AddedID'];
34
35         display_notification_centered(_("The dimension has been entered."));
36
37         safe_exit();
38 }
39
40 //---------------------------------------------------------------------------------------
41
42 if (isset($_GET['UpdatedID'])) 
43 {
44         $id = $_GET['UpdatedID'];
45
46         display_notification_centered(_("The dimension has been updated."));
47         safe_exit();
48 }
49
50 //---------------------------------------------------------------------------------------
51
52 if (isset($_GET['DeletedID'])) 
53 {
54         $id = $_GET['DeletedID'];
55
56         display_notification_centered(_("The dimension has been deleted."));
57         safe_exit();
58 }
59
60 //---------------------------------------------------------------------------------------
61
62 if (isset($_GET['ClosedID'])) 
63 {
64         $id = $_GET['ClosedID'];
65
66         display_notification_centered(_("The dimension has been closed. There can be no more changes to it.") . " #$id");
67         safe_exit();
68 }
69
70 //-------------------------------------------------------------------------------------------------
71
72 function safe_exit()
73 {
74         global $path_to_root;
75
76         hyperlink_no_params("", _("Enter a new dimension"));
77         echo "<br>";
78         hyperlink_no_params($path_to_root . "/dimensions/inquiry/search_dimensions.php", _("Select an existing dimension"));
79         echo "<br><br>";
80
81         end_page();
82
83         exit;
84 }
85
86 //-------------------------------------------------------------------------------------
87
88 function can_process()
89 {
90         global $selected_id;
91
92         if ($selected_id == -1) 
93         {
94
95         if (!references::is_valid($_POST['ref'])) 
96         {
97                 display_error( _("The dimension reference must be entered."));
98                 return false;
99         }
100
101         if (!is_new_reference($_POST['ref'], systypes::dimension())) 
102         {
103                 display_error(_("The entered reference is already in use."));
104                 return false;
105         }
106         }
107
108         if (strlen($_POST['name']) == 0) 
109         {
110                 display_error( _("The dimension name must be entered."));
111                 return false;
112         }
113
114         if (!is_date($_POST['date_']))
115         {
116                 display_error( _("The date entered is in an invalid format."));
117                 return false;
118         }
119
120         if (!is_date($_POST['due_date']))
121         {
122                 display_error( _("The required by date entered is in an invalid format."));
123                 return false;
124         }
125
126         return true;
127 }
128
129 //-------------------------------------------------------------------------------------
130
131 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) 
132 {
133
134         if (can_process()) 
135         {
136
137                 if ($selected_id == -1) 
138                 {
139
140                         $id = add_dimension($_POST['ref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
141
142                         meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
143                 } 
144                 else 
145                 {
146
147                         update_dimension($selected_id, $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
148
149                         meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
150                 }
151         }
152 }
153
154 //--------------------------------------------------------------------------------------
155
156 if (isset($_POST['delete'])) 
157 {
158
159         $cancel_delete = false;
160
161         // can't delete it there are productions or issues
162         if (dimension_has_payments($selected_id) || dimension_has_deposits($selected_id))
163         {
164                 display_error(_("This dimension cannot be deleted because it has already been processed."));
165                 $cancel_delete = true;
166         }
167
168         if ($cancel_delete == false) 
169         { //ie not cancelled the delete as a result of above tests
170
171                 // delete
172                 delete_dimension($selected_id);
173                 meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
174         }
175 }
176
177 //-------------------------------------------------------------------------------------
178
179 if (isset($_POST['close'])) 
180 {
181
182         // update the closed flag
183         close_dimension($selected_id);
184         meta_forward($_SERVER['PHP_SELF'], "ClosedID=$selected_id");
185 }
186
187 //-------------------------------------------------------------------------------------
188
189 start_form();
190
191 start_table($table_style2);
192
193 if ($selected_id != -1)
194 {
195         $myrow = get_dimension($selected_id);
196
197         if (strlen($myrow[0]) == 0) 
198         {
199                 display_error(_("The dimension sent is not valid."));
200                 exit;
201         }
202
203         // if it's a closed dimension can't edit it
204         if ($myrow["closed"] == 1) 
205         {
206                 display_error(_("This dimension is closed and cannot be edited."));
207                 exit;
208         }
209
210         $_POST['ref'] = $myrow["reference"];
211         $_POST['closed'] = $myrow["closed"];
212         $_POST['name'] = $myrow["name"];
213         $_POST['type_'] = $myrow["type_"];
214         $_POST['date_'] = sql2date($myrow["date_"]);
215         $_POST['due_date'] = sql2date($myrow["due_date"]);
216         $_POST['memo_'] = get_comments_string(systypes::dimension(), $selected_id);
217
218         hidden('ref', $_POST['ref']);
219
220         label_row(_("Dimension Reference:"), $_POST['ref']);
221
222         hidden('selected_id', $selected_id);
223
224 else 
225 {
226         ref_row(_("Dimension Reference:"), 'ref', references::get_next(systypes::dimension()));
227 }
228
229 text_row_ex(_("Name") . ":", 'name', 50, 75);
230
231 $dim = get_company_pref('use_dimension');
232
233 number_list_row(_("Type"), 'type_', null, 1, $dim);
234
235 date_row(_("Start Date") . ":", 'date_');
236
237 date_row(_("Date Required By") . ":", 'due_date', null, sys_prefs::default_dimension_required_by());
238
239 textarea_row(_("Memo:"), 'memo_', null, 40, 5);
240
241 end_table(1);
242
243 submit_add_or_update_center($selected_id == -1);
244
245 if ($selected_id != -1) 
246 {
247         echo "<br>";
248
249         submit_center_first('close', _("Close This Dimension"));
250         submit_center_last('delete', _("Delete This Dimension"));
251 }
252
253 end_form();
254
255 //--------------------------------------------------------------------------------------------
256
257 end_page();
258
259 ?>