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/data_checks.inc");
19 include_once($path_to_root . "/admin/db/tags_db.inc");
20 include_once($path_to_root . "/dimensions/includes/dimensions_db.inc");
21 include_once($path_to_root . "/dimensions/includes/dimensions_ui.inc");
24 if (user_use_date_picker())
25 $js .= get_js_date_picker();
26 page(_($help_context = "Dimension Entry"), false, false, "", $js);
28 //---------------------------------------------------------------------------------------
30 if (isset($_GET['trans_no']))
32 $selected_id = $_GET['trans_no'];
34 elseif(isset($_POST['selected_id']))
36 $selected_id = $_POST['selected_id'];
40 //---------------------------------------------------------------------------------------
42 if (isset($_GET['AddedID']))
44 $id = $_GET['AddedID'];
46 display_notification_centered(_("The dimension has been entered."));
51 //---------------------------------------------------------------------------------------
53 if (isset($_GET['UpdatedID']))
55 $id = $_GET['UpdatedID'];
57 display_notification_centered(_("The dimension has been updated."));
61 //---------------------------------------------------------------------------------------
63 if (isset($_GET['DeletedID']))
65 $id = $_GET['DeletedID'];
67 display_notification_centered(_("The dimension has been deleted."));
71 //---------------------------------------------------------------------------------------
73 if (isset($_GET['ClosedID']))
75 $id = $_GET['ClosedID'];
77 display_notification_centered(_("The dimension has been closed. There can be no more changes to it.") . " #$id");
81 //---------------------------------------------------------------------------------------
83 if (isset($_GET['ReopenedID']))
85 $id = $_GET['ReopenedID'];
87 display_notification_centered(_("The dimension has been re-opened. ") . " #$id");
91 //-------------------------------------------------------------------------------------------------
95 global $path_to_root, $id;
97 hyperlink_no_params("", _("Enter a &new dimension"));
98 hyperlink_no_params($path_to_root . "/dimensions/inquiry/search_dimensions.php", _("&Select an existing dimension"));
99 hyperlink_no_params($path_to_root . "/admin/attachments.php?filterType=40&trans_no=$id", _("&Add Attachment"));
101 display_footer_exit();
104 //-------------------------------------------------------------------------------------
106 function can_process()
108 global $selected_id, $Refs;
110 if ($selected_id == -1)
112 if (!check_reference($_POST['ref'], ST_DIMENSION))
119 if (strlen($_POST['name']) == 0)
121 display_error( _("The dimension name must be entered."));
126 if (!is_date($_POST['date_']))
128 display_error( _("The date entered is in an invalid format."));
133 if (!is_date($_POST['due_date']))
135 display_error( _("The required by date entered is in an invalid format."));
136 set_focus('due_date');
143 //-------------------------------------------------------------------------------------
145 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
147 if (!isset($_POST['dimension_tags']))
148 $_POST['dimension_tags'] = array();
153 if ($selected_id == -1)
155 $id = add_dimension($_POST['ref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
156 add_tag_associations($id, $_POST['dimension_tags']);
157 meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
162 update_dimension($selected_id, $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
163 update_tag_associations(TAG_DIMENSION, $selected_id, $_POST['dimension_tags']);
165 meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
170 //--------------------------------------------------------------------------------------
172 if (isset($_POST['delete']))
175 $cancel_delete = false;
177 // can't delete it there are productions or issues
178 if (dimension_has_payments($selected_id) || dimension_has_deposits($selected_id))
180 display_error(_("This dimension cannot be deleted because it has already been processed."));
182 $cancel_delete = true;
185 if ($cancel_delete == false)
186 { //ie not cancelled the delete as a result of above tests
189 delete_dimension($selected_id);
190 delete_tag_associations(TAG_DIMENSION,$selected_id, true);
191 meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
195 //-------------------------------------------------------------------------------------
197 if (isset($_POST['close']))
200 // update the closed flag
201 close_dimension($selected_id);
202 meta_forward($_SERVER['PHP_SELF'], "ClosedID=$selected_id");
205 if (isset($_POST['reopen']))
208 // update the closed flag
209 reopen_dimension($selected_id);
210 meta_forward($_SERVER['PHP_SELF'], "ReopenedID=$selected_id");
212 //-------------------------------------------------------------------------------------
216 start_table(TABLESTYLE2);
218 if ($selected_id != -1)
220 $myrow = get_dimension($selected_id, true);
222 if ($myrow === false)
224 display_error(_("The dimension sent is not valid."));
225 display_footer_exit();
228 // if it's a closed dimension can't edit it
229 //if ($myrow["closed"] == 1)
231 // display_error(_("This dimension is closed and cannot be edited."));
232 // display_footer_exit();
235 $_POST['ref'] = $myrow["reference"];
236 $_POST['closed'] = $myrow["closed"];
237 $_POST['name'] = $myrow["name"];
238 $_POST['type_'] = $myrow["type_"];
239 $_POST['date_'] = sql2date($myrow["date_"]);
240 $_POST['due_date'] = sql2date($myrow["due_date"]);
241 $_POST['memo_'] = get_comments_string(ST_DIMENSION, $selected_id);
243 $tags_result = get_tags_associated_with_record(TAG_DIMENSION, $selected_id);
245 while ($tag = db_fetch($tags_result))
246 $tagids[] = $tag['id'];
247 $_POST['dimension_tags'] = $tagids;
249 hidden('ref', $_POST['ref']);
251 label_row(_("Dimension Reference:"), $_POST['ref']);
253 hidden('selected_id', $selected_id);
257 $_POST['dimension_tags'] = array();
258 ref_row(_("Dimension Reference:"), 'ref', '', $Refs->get_next(ST_DIMENSION), false, ST_DIMENSION);
261 text_row_ex(_("Name") . ":", 'name', 50, 75);
263 $dim = get_company_pref('use_dimension');
265 number_list_row(_("Type"), 'type_', null, 1, $dim);
267 date_row(_("Start Date") . ":", 'date_');
269 date_row(_("Date Required By") . ":", 'due_date', '', null, $SysPrefs->default_dimension_required_by());
271 tag_list_row(_("Tags:"), 'dimension_tags', 5, TAG_DIMENSION, true);
273 textarea_row(_("Memo:"), 'memo_', null, 40, 5);
277 if (isset($_POST['closed']) && $_POST['closed'] == 1)
278 display_note(_("This Dimension is closed."), 0, 0, "class='currentfg'");
280 if ($selected_id != -1)
283 submit_center_first('UPDATE_ITEM', _("Update"), _('Save changes to dimension'), 'default');
284 if ($_POST['closed'] == 1)
285 submit('reopen', _("Re-open This Dimension"), true, _('Mark this dimension as re-opened'), true);
287 submit('close', _("Close This Dimension"), true, _('Mark this dimension as closed'), true);
288 submit_center_last('delete', _("Delete This Dimension"), _('Delete unused dimension'), true);
292 submit_center('ADD_ITEM', _("Add"), true, '', 'default');
296 //--------------------------------------------------------------------------------------------