File: dimension_entry.php

package info (click to toggle)
frontaccounting 2.2.10-3.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 6,252 kB
  • sloc: php: 64,938; sql: 3,014; sh: 390; makefile: 38
file content (310 lines) | stat: -rw-r--r-- 8,556 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = 'SA_DIMENSION';
$path_to_root = "..";
include_once($path_to_root . "/includes/session.inc");

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/manufacturing.inc");
include_once($path_to_root . "/includes/data_checks.inc");

include_once($path_to_root . "/admin/db/tags_db.inc");
include_once($path_to_root . "/dimensions/includes/dimensions_db.inc");
include_once($path_to_root . "/dimensions/includes/dimensions_ui.inc");

$js = "";
if ($use_date_picker)
	$js .= get_js_date_picker();
page(_($help_context = "Dimension Entry"), false, false, "", $js);

//---------------------------------------------------------------------------------------

if (isset($_GET['trans_no']))
{
	$selected_id = $_GET['trans_no'];
} 
elseif(isset($_POST['selected_id']))
{
	$selected_id = $_POST['selected_id'];
}
else
	$selected_id = -1;
//---------------------------------------------------------------------------------------

if (isset($_GET['AddedID'])) 
{
	$id = $_GET['AddedID'];

	display_notification_centered(_("The dimension has been entered."));

	safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['UpdatedID'])) 
{
	$id = $_GET['UpdatedID'];

	display_notification_centered(_("The dimension has been updated."));
	safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['DeletedID'])) 
{
	$id = $_GET['DeletedID'];

	display_notification_centered(_("The dimension has been deleted."));
	safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['ClosedID'])) 
{
	$id = $_GET['ClosedID'];

	display_notification_centered(_("The dimension has been closed. There can be no more changes to it.") . " #$id");
	safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['ReopenedID'])) 
{
	$id = $_GET['ReopenedID'];

	display_notification_centered(_("The dimension has been re-opened. ") . " #$id");
	safe_exit();
}

//-------------------------------------------------------------------------------------------------

function safe_exit()
{
	global $path_to_root;

	hyperlink_no_params("", _("Enter a &new dimension"));
	echo "<br>";
	hyperlink_no_params($path_to_root . "/dimensions/inquiry/search_dimensions.php", _("&Select an existing dimension"));

	display_footer_exit();
}

//-------------------------------------------------------------------------------------

function can_process()
{
	global $selected_id, $Refs;

	if ($selected_id == -1) 
	{

    	if (!$Refs->is_valid($_POST['ref'])) 
    	{
    		display_error( _("The dimension reference must be entered."));
			set_focus('ref');
    		return false;
    	}

    	if (!is_new_reference($_POST['ref'], ST_DIMENSION)) 
    	{
    		display_error(_("The entered reference is already in use."));
			set_focus('ref');
    		return false;
    	}
	}

	if (strlen($_POST['name']) == 0) 
	{
		display_error( _("The dimension name must be entered."));
		set_focus('name');
		return false;
	}

	if (!is_date($_POST['date_']))
	{
		display_error( _("The date entered is in an invalid format."));
		set_focus('date_');
		return false;
	}

	if (!is_date($_POST['due_date']))
	{
		display_error( _("The required by date entered is in an invalid format."));
		set_focus('due_date');
		return false;
	}

	return true;
}

//-------------------------------------------------------------------------------------

if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) 
{
	if (!isset($_POST['dimension_tags']))
		$_POST['dimension_tags'] = array();
		
	if (can_process()) 
	{

		if ($selected_id == -1) 
		{
			$id = add_dimension($_POST['ref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
			add_tag_associations($id, $_POST['dimension_tags']);
			meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
		} 
		else 
		{

			update_dimension($selected_id, $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
			update_tag_associations(TAG_DIMENSION, $selected_id, $_POST['dimension_tags']);

			meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
		}
	}
}

//--------------------------------------------------------------------------------------

if (isset($_POST['delete'])) 
{

	$cancel_delete = false;

	// can't delete it there are productions or issues
	if (dimension_has_payments($selected_id) || dimension_has_deposits($selected_id))
	{
		display_error(_("This dimension cannot be deleted because it has already been processed."));
		set_focus('ref');
		$cancel_delete = true;
	}

	if ($cancel_delete == false) 
	{ //ie not cancelled the delete as a result of above tests

		// delete
		delete_dimension($selected_id);
		delete_tag_associations(TAG_DIMENSION,$selected_id, true);
		meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
	}
}

//-------------------------------------------------------------------------------------

if (isset($_POST['close'])) 
{

	// update the closed flag
	close_dimension($selected_id);
	meta_forward($_SERVER['PHP_SELF'], "ClosedID=$selected_id");
}

if (isset($_POST['reopen'])) 
{

	// update the closed flag
	reopen_dimension($selected_id);
	meta_forward($_SERVER['PHP_SELF'], "ReopenedID=$selected_id");
}
//-------------------------------------------------------------------------------------

start_form();

start_table($table_style2);

if ($selected_id != -1)
{
	$myrow = get_dimension($selected_id);

	if (strlen($myrow[0]) == 0) 
	{
		display_error(_("The dimension sent is not valid."));
		display_footer_exit();
	}

	// if it's a closed dimension can't edit it
	//if ($myrow["closed"] == 1) 
	//{
	//	display_error(_("This dimension is closed and cannot be edited."));
	//	display_footer_exit();
	//}

	$_POST['ref'] = $myrow["reference"];
	$_POST['closed'] = $myrow["closed"];
	$_POST['name'] = $myrow["name"];
	$_POST['type_'] = $myrow["type_"];
	$_POST['date_'] = sql2date($myrow["date_"]);
	$_POST['due_date'] = sql2date($myrow["due_date"]);
	$_POST['memo_'] = get_comments_string(ST_DIMENSION, $selected_id);
	
 	$tags_result = get_tags_associated_with_record(TAG_DIMENSION, $selected_id);
 	$tagids = array();
 	while ($tag = db_fetch($tags_result)) 
 	 	$tagids[] = $tag['id'];
 	$_POST['dimension_tags'] = $tagids;	

	hidden('ref', $_POST['ref']);

	label_row(_("Dimension Reference:"), $_POST['ref']);

	hidden('selected_id', $selected_id);
} 
else 
{
	$_POST['dimension_tags'] = array();
	ref_row(_("Dimension Reference:"), 'ref', '', $Refs->get_next(ST_DIMENSION));
}

text_row_ex(_("Name") . ":", 'name', 50, 75);

$dim = get_company_pref('use_dimension');

number_list_row(_("Type"), 'type_', null, 1, $dim);

date_row(_("Start Date") . ":", 'date_');

date_row(_("Date Required By") . ":", 'due_date', '', null, $SysPrefs->default_dimension_required_by());

tag_list_row(_("Tags:"), 'dimension_tags', 5, TAG_DIMENSION, true);

textarea_row(_("Memo:"), 'memo_', null, 40, 5);

end_table(1);

if (isset($_POST['closed']) && $_POST['closed'] == 1)
	display_note(_("This Dimension is closed."), 0, 0, "class='currentfg'");

if ($selected_id != -1) 
{
	echo "<br>";
	submit_center_first('UPDATE_ITEM', _("Update"), _('Save changes to dimension'), 'default');
	if ($_POST['closed'] == 1)
		submit('reopen', _("Re-open This Dimension"), true, _('Mark this dimension as re-opened'), true);
	else	
		submit('close', _("Close This Dimension"), true, _('Mark this dimension as closed'), true);
	submit_center_last('delete', _("Delete This Dimension"), _('Delete unused dimension'), true);
}
else
{
	submit_center('ADD_ITEM', _("Add"), true, '', 'default');
}
end_form();

//--------------------------------------------------------------------------------------------

end_page();

?>