6 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/manufacturing.inc");
10 include_once($path_to_root . "/includes/data_checks.inc");
12 include_once($path_to_root . "/dimensions/includes/dimensions_db.inc");
13 include_once($path_to_root . "/dimensions/includes/dimensions_ui.inc");
17 $js .= get_js_date_picker();
18 page(_("Dimension Entry"), false, false, "", $js);
20 //---------------------------------------------------------------------------------------
22 if (isset($_GET['trans_no']))
24 $selected_id = $_GET['trans_no'];
26 elseif(isset($_POST['selected_id']))
28 $selected_id = $_POST['selected_id'];
32 //---------------------------------------------------------------------------------------
34 if (isset($_GET['AddedID']))
36 $id = $_GET['AddedID'];
38 display_notification_centered(_("The dimension has been entered."));
43 //---------------------------------------------------------------------------------------
45 if (isset($_GET['UpdatedID']))
47 $id = $_GET['UpdatedID'];
49 display_notification_centered(_("The dimension has been updated."));
53 //---------------------------------------------------------------------------------------
55 if (isset($_GET['DeletedID']))
57 $id = $_GET['DeletedID'];
59 display_notification_centered(_("The dimension has been deleted."));
63 //---------------------------------------------------------------------------------------
65 if (isset($_GET['ClosedID']))
67 $id = $_GET['ClosedID'];
69 display_notification_centered(_("The dimension has been closed. There can be no more changes to it.") . " #$id");
73 //-------------------------------------------------------------------------------------------------
79 hyperlink_no_params("", _("Enter a new dimension"));
81 hyperlink_no_params($path_to_root . "/dimensions/inquiry/search_dimensions.php", _("Select an existing dimension"));
89 //-------------------------------------------------------------------------------------
91 function can_process()
95 if ($selected_id == -1)
98 if (!references::is_valid($_POST['ref']))
100 display_error( _("The dimension reference must be entered."));
104 if (!is_new_reference($_POST['ref'], systypes::dimension()))
106 display_error(_("The entered reference is already in use."));
111 if (strlen($_POST['name']) == 0)
113 display_error( _("The dimension name must be entered."));
117 if (!is_date($_POST['date_']))
119 display_error( _("The date entered is in an invalid format."));
123 if (!is_date($_POST['due_date']))
125 display_error( _("The required by date entered is in an invalid format."));
132 //-------------------------------------------------------------------------------------
134 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
140 if ($selected_id == -1)
143 $id = add_dimension($_POST['ref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
145 meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
150 update_dimension($selected_id, $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
152 meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
157 //--------------------------------------------------------------------------------------
159 if (isset($_POST['delete']))
162 $cancel_delete = false;
164 // can't delete it there are productions or issues
165 if (dimension_has_payments($selected_id) || dimension_has_deposits($selected_id))
167 display_error(_("This dimension cannot be deleted because it has already been processed."));
168 $cancel_delete = true;
171 if ($cancel_delete == false)
172 { //ie not cancelled the delete as a result of above tests
175 delete_dimension($selected_id);
176 meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
180 //-------------------------------------------------------------------------------------
182 if (isset($_POST['close']))
185 // update the closed flag
186 close_dimension($selected_id);
187 meta_forward($_SERVER['PHP_SELF'], "ClosedID=$selected_id");
190 //-------------------------------------------------------------------------------------
194 start_table($table_style2);
196 if ($selected_id != -1)
198 $myrow = get_dimension($selected_id);
200 if (strlen($myrow[0]) == 0)
202 display_error(_("The dimension sent is not valid."));
206 // if it's a closed dimension can't edit it
207 if ($myrow["closed"] == 1)
209 display_error(_("This dimension is closed and cannot be edited."));
213 $_POST['ref'] = $myrow["reference"];
214 $_POST['closed'] = $myrow["closed"];
215 $_POST['name'] = $myrow["name"];
216 $_POST['type_'] = $myrow["type_"];
217 $_POST['date_'] = sql2date($myrow["date_"]);
218 $_POST['due_date'] = sql2date($myrow["due_date"]);
219 $_POST['memo_'] = get_comments_string(systypes::dimension(), $selected_id);
221 hidden('ref', $_POST['ref']);
223 label_row(_("Dimension Reference:"), $_POST['ref']);
225 hidden('selected_id', $selected_id);
229 ref_row(_("Dimension Reference:"), 'ref', references::get_next(systypes::dimension()));
232 text_row_ex(_("Name") . ":", 'name', 50, 75);
234 $dim = get_company_pref('use_dimension');
236 number_list_row(_("Type"), 'type_', null, 1, $dim);
238 date_row(_("Start Date") . ":", 'date_');
240 date_row(_("Date Required By") . ":", 'due_date', null, sys_prefs::default_dimension_required_by());
242 textarea_row(_("Memo:"), 'memo_', null, 40, 5);
246 submit_add_or_update_center($selected_id == -1);
248 if ($selected_id != -1)
252 submit_center_first('close', _("Close This Dimension"));
253 submit_center_last('delete', _("Delete This Dimension"));
258 //--------------------------------------------------------------------------------------------