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';
14 include_once($path_to_root . "/includes/session.inc");
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");
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");
26 $js .= get_js_date_picker();
27 page(_($help_context = "Dimension Entry"), false, false, "", $js);
29 //---------------------------------------------------------------------------------------
31 if (isset($_GET['trans_no']))
33 $selected_id = $_GET['trans_no'];
35 elseif(isset($_POST['selected_id']))
37 $selected_id = $_POST['selected_id'];
41 //---------------------------------------------------------------------------------------
43 if (isset($_GET['AddedID']))
45 $id = $_GET['AddedID'];
47 display_notification_centered(_("The dimension has been entered."));
52 //---------------------------------------------------------------------------------------
54 if (isset($_GET['UpdatedID']))
56 $id = $_GET['UpdatedID'];
58 display_notification_centered(_("The dimension has been updated."));
62 //---------------------------------------------------------------------------------------
64 if (isset($_GET['DeletedID']))
66 $id = $_GET['DeletedID'];
68 display_notification_centered(_("The dimension has been deleted."));
72 //---------------------------------------------------------------------------------------
74 if (isset($_GET['ClosedID']))
76 $id = $_GET['ClosedID'];
78 display_notification_centered(_("The dimension has been closed. There can be no more changes to it.") . " #$id");
82 //---------------------------------------------------------------------------------------
84 if (isset($_GET['ReopenedID']))
86 $id = $_GET['ReopenedID'];
88 display_notification_centered(_("The dimension has been re-opened. ") . " #$id");
92 //-------------------------------------------------------------------------------------------------
98 hyperlink_no_params("", _("Enter a &new dimension"));
100 hyperlink_no_params($path_to_root . "/dimensions/inquiry/search_dimensions.php", _("&Select an existing dimension"));
102 display_footer_exit();
105 //-------------------------------------------------------------------------------------
107 function can_process()
109 global $selected_id, $Refs;
111 if ($selected_id == -1)
114 if (!$Refs->is_valid($_POST['ref']))
116 display_error( _("The dimension reference must be entered."));
121 if (!is_new_reference($_POST['ref'], ST_DIMENSION))
123 display_error(_("The entered reference is already in use."));
129 if (strlen($_POST['name']) == 0)
131 display_error( _("The dimension name must be entered."));
136 if (!is_date($_POST['date_']))
138 display_error( _("The date entered is in an invalid format."));
143 if (!is_date($_POST['due_date']))
145 display_error( _("The required by date entered is in an invalid format."));
146 set_focus('due_date');
153 //-------------------------------------------------------------------------------------
155 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
157 if (!isset($_POST['dimension_tags']))
158 $_POST['dimension_tags'] = array();
163 if ($selected_id == -1)
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");
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']);
175 meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
180 //--------------------------------------------------------------------------------------
182 if (isset($_POST['delete']))
185 $cancel_delete = false;
187 // can't delete it there are productions or issues
188 if (dimension_has_payments($selected_id) || dimension_has_deposits($selected_id))
190 display_error(_("This dimension cannot be deleted because it has already been processed."));
192 $cancel_delete = true;
195 if ($cancel_delete == false)
196 { //ie not cancelled the delete as a result of above tests
199 delete_dimension($selected_id);
200 delete_tag_associations(TAG_DIMENSION,$selected_id, true);
201 meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
205 //-------------------------------------------------------------------------------------
207 if (isset($_POST['close']))
210 // update the closed flag
211 close_dimension($selected_id);
212 meta_forward($_SERVER['PHP_SELF'], "ClosedID=$selected_id");
215 if (isset($_POST['reopen']))
218 // update the closed flag
219 reopen_dimension($selected_id);
220 meta_forward($_SERVER['PHP_SELF'], "ReopenedID=$selected_id");
222 //-------------------------------------------------------------------------------------
226 start_table(TABLESTYLE2);
228 if ($selected_id != -1)
230 $myrow = get_dimension($selected_id);
232 if (strlen($myrow[0]) == 0)
234 display_error(_("The dimension sent is not valid."));
235 display_footer_exit();
238 // if it's a closed dimension can't edit it
239 //if ($myrow["closed"] == 1)
241 // display_error(_("This dimension is closed and cannot be edited."));
242 // display_footer_exit();
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);
253 $tags_result = get_tags_associated_with_record(TAG_DIMENSION, $selected_id);
255 while ($tag = db_fetch($tags_result))
256 $tagids[] = $tag['id'];
257 $_POST['dimension_tags'] = $tagids;
259 hidden('ref', $_POST['ref']);
261 label_row(_("Dimension Reference:"), $_POST['ref']);
263 hidden('selected_id', $selected_id);
267 $_POST['dimension_tags'] = array();
268 ref_row(_("Dimension Reference:"), 'ref', '', $Refs->get_next(ST_DIMENSION));
271 text_row_ex(_("Name") . ":", 'name', 50, 75);
273 $dim = get_company_pref('use_dimension');
275 number_list_row(_("Type"), 'type_', null, 1, $dim);
277 date_row(_("Start Date") . ":", 'date_');
279 date_row(_("Date Required By") . ":", 'due_date', '', null, $SysPrefs->default_dimension_required_by());
281 tag_list_row(_("Tags:"), 'dimension_tags', 5, TAG_DIMENSION, true);
283 textarea_row(_("Memo:"), 'memo_', null, 40, 5);
287 if (isset($_POST['closed']) && $_POST['closed'] == 1)
288 display_note(_("This Dimension is closed."), 0, 0, "class='currentfg'");
290 if ($selected_id != -1)
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);
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);
302 submit_center('ADD_ITEM', _("Add"), true, '', 'default');
306 //--------------------------------------------------------------------------------------------