6 include_once($path_to_root . "/includes/session.inc");
8 page(_("Dimension Entry"));
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");
14 include_once($path_to_root . "/dimensions/includes/dimensions_db.inc");
15 include_once($path_to_root . "/dimensions/includes/dimensions_ui.inc");
17 //---------------------------------------------------------------------------------------
19 if (isset($_GET['trans_no']))
21 $selected_id = $_GET['trans_no'];
23 elseif(isset($_POST['selected_id']))
25 $selected_id = $_POST['selected_id'];
29 //---------------------------------------------------------------------------------------
31 if (isset($_GET['AddedID']))
33 $id = $_GET['AddedID'];
35 display_notification_centered(_("The dimension has been entered."));
40 //---------------------------------------------------------------------------------------
42 if (isset($_GET['UpdatedID']))
44 $id = $_GET['UpdatedID'];
46 display_notification_centered(_("The dimension has been updated."));
50 //---------------------------------------------------------------------------------------
52 if (isset($_GET['DeletedID']))
54 $id = $_GET['DeletedID'];
56 display_notification_centered(_("The dimension has been deleted."));
60 //---------------------------------------------------------------------------------------
62 if (isset($_GET['ClosedID']))
64 $id = $_GET['ClosedID'];
66 display_notification_centered(_("The dimension has been closed. There can be no more changes to it.") . " #$id");
70 //-------------------------------------------------------------------------------------------------
76 hyperlink_no_params("", _("Enter a new dimension"));
78 hyperlink_no_params($path_to_root . "/dimensions/inquiry/search_dimensions.php", _("Select an existing dimension"));
86 //-------------------------------------------------------------------------------------
88 function can_process()
92 if ($selected_id == -1)
95 if (!references::is_valid($_POST['ref']))
97 display_error( _("The dimension reference must be entered."));
101 if (!is_new_reference($_POST['ref'], systypes::dimension()))
103 display_error(_("The entered reference is already in use."));
108 if (strlen($_POST['name']) == 0)
110 display_error( _("The dimension name must be entered."));
114 if (!is_date($_POST['date_']))
116 display_error( _("The date entered is in an invalid format."));
120 if (!is_date($_POST['due_date']))
122 display_error( _("The required by date entered is in an invalid format."));
129 //-------------------------------------------------------------------------------------
131 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
137 if ($selected_id == -1)
140 $id = add_dimension($_POST['ref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
142 meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
147 update_dimension($selected_id, $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
149 meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
154 //--------------------------------------------------------------------------------------
156 if (isset($_POST['delete']))
159 $cancel_delete = false;
161 // can't delete it there are productions or issues
162 if (dimension_has_payments($selected_id) || dimension_has_deposits($selected_id))
164 display_error(_("This dimension cannot be deleted because it has already been processed."));
165 $cancel_delete = true;
168 if ($cancel_delete == false)
169 { //ie not cancelled the delete as a result of above tests
172 delete_dimension($selected_id);
173 meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
177 //-------------------------------------------------------------------------------------
179 if (isset($_POST['close']))
182 // update the closed flag
183 close_dimension($selected_id);
184 meta_forward($_SERVER['PHP_SELF'], "ClosedID=$selected_id");
187 //-------------------------------------------------------------------------------------
191 start_table($table_style2);
193 if ($selected_id != -1)
195 $myrow = get_dimension($selected_id);
197 if (strlen($myrow[0]) == 0)
199 display_error(_("The dimension sent is not valid."));
203 // if it's a closed dimension can't edit it
204 if ($myrow["closed"] == 1)
206 display_error(_("This dimension is closed and cannot be edited."));
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);
218 hidden('ref', $_POST['ref']);
220 label_row(_("Dimension Reference:"), $_POST['ref']);
222 hidden('selected_id', $selected_id);
226 ref_row(_("Dimension Reference:"), 'ref', references::get_next(systypes::dimension()));
229 text_row_ex(_("Name") . ":", 'name', 50, 75);
231 $dim = get_company_pref('use_dimension');
233 number_list_row(_("Type"), 'type_', null, 1, $dim);
235 date_row(_("Start Date") . ":", 'date_');
237 date_row(_("Date Required By") . ":", 'due_date', null, sys_prefs::default_dimension_required_by());
239 textarea_row(_("Memo:"), 'memo_', null, 40, 5);
243 submit_add_or_update_center($selected_id == -1);
245 if ($selected_id != -1)
249 submit_center_first('close', _("Close This Dimension"));
250 submit_center_last('delete', _("Delete This Dimension"));
255 //--------------------------------------------------------------------------------------------