File: ArtifactTypeHtml.class

package info (click to toggle)
gforge 4.5.14-22etch13
  • links: PTS
  • area: main
  • in suites: etch
  • size: 13,004 kB
  • ctags: 11,918
  • sloc: php: 36,047; sql: 29,050; sh: 10,538; perl: 6,496; xml: 3,810; makefile: 341; python: 263; ansic: 256
file content (432 lines) | stat: -rw-r--r-- 15,108 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<?php
/**
  *
  * SourceForge Generic Tracker facility
  *
  * SourceForge: Breaking Down the Barriers to Open Source Development
  * Copyright 1999-2001 (c) VA Linux Systems
  * http://sourceforge.net
  *
  * @version   $Id: ArtifactTypeHtml.class 4525 2005-07-21 21:37:47Z tperdue $
  *
  */


require_once('common/tracker/ArtifactType.class');
require_once('common/tracker/ArtifactExtraField.class');
require_once('common/tracker/ArtifactExtraFieldElement.class');

class ArtifactTypeHtml extends ArtifactType {

	/**
	 *  ArtifactType() - constructor
	 *
	 *  @param $Group object
	 *  @param $artifact_type_id - the id # assigned to this artifact type in the db
	 */
	function ArtifactTypeHtml(&$Group,$artifact_type_id=false, $arr=false) {
		return $this->ArtifactType($Group,$artifact_type_id,$arr);
	}

	function header($params) {
		global $DOCUMENT_ROOT, $HTML, $Language, $sys_use_tracker;
		if (!$sys_use_tracker) {
			exit_disabled();
		}
		$group_id= $this->Group->getID();

		//required by new site_project_header
		$params['group']=$group_id;
		$params['toptab']='tracker';
		$params['tabtext']=$this->getName();

		site_project_header($params);

		$labels = array();
		$links  = array();

		$labels[] = $this->getName().': '.$Language->getText('tracker_artifacttype','browse');
		$links[]  = '/tracker/?func=browse&group_id='.$group_id.'&atid='. $this->getID();
		$labels[] = $Language->getText('tracker_artifacttype','csv');
		$links[]  = '/tracker/?func=downloadcsv&group_id='.$group_id.'&atid='. $this->getID();
		if ($this->allowsAnon() || session_loggedin()) {
			$labels[] = $Language->getText('tracker_artifacttype','submit_new');
			$links[]  = '/tracker/?func=add&group_id='.$group_id.'&atid='. $this->getID();
		}

		if (session_loggedin()) {
			$labels[] = $Language->getText('tracker_artifacttype','reporting');
			$links[]  = '/tracker/reporting/?group_id='.$group_id.'&atid='. $this->getID();
			if ($this->isMonitoring()) {
				$labels[] = $Language->getText('tracker_monitor','monitorstop');
			} else {
				$labels[] = $Language->getText('tracker_monitor','monitor');
			}
			$links[]  = '/tracker/?group_id='.$group_id.'&atid='. $this->getID().'&func=monitor';

			if ($this->userIsAdmin()) {
				$labels[] = $Language->getText('tracker_artifacttype','admin');
				$links[]  = '/tracker/admin/?group_id='.$group_id.'&atid='.$this->getID();
			}
		}

		echo $HTML->subMenu($labels,$links);
	}

	function footer($params) {
		site_project_footer($params);
	}

	function adminHeader($params) {
		global $Language,$HTML;
		echo $this->header($params);
		$group_id= $this->Group->getID();

		$links_arr[]='/tracker/admin/?group_id='.$group_id;
		$title_arr[]=$Language->getText('tracker_admin','add_artifact_types');

		$links_arr[]='/tracker/admin/?group_id='.$group_id.'&atid='.$this->getID().'&update_type=1';
		$title_arr[]=$Language->getText('tracker_admin','update_artifact_types');

		$links_arr[]='/tracker/admin/?group_id='.$group_id.'&atid='.$this->getID().'&add_extrafield=1';
		$title_arr[]=$Language->getText('tracker_admin','manage_extrafield');

		$links_arr[]='/tracker/admin/?group_id='.$group_id.'&atid='.$this->getID().'&clone_tracker=1';
		$title_arr[]=$Language->getText('tracker_admin','clone_tracker');

		$links_arr[]='/tracker/admin/?group_id='.$group_id.'&atid='.$this->getID().'&add_canned=1';
		$title_arr[]=$Language->getText('tracker_admin','add_canned');

		$links_arr[]='/tracker/admin/?group_id='.$group_id.'&atid='.$this->getID().'&delete=1';
		$title_arr[]=$Language->getText('tracker_admin','delete');

		echo $HTML->printSubMenu($title_arr,$links_arr);
	}

	function adminFooter($params) {
		echo $this->footer($params);
	}

	function renderExtraFields($selected=array(),$show_100=false,$text_100='none',$show_any=false,$text_any='Any',$filter='',$status_show_100=false,$mode='') {
		$efarr = $this->getExtraFields($filter);
		//each two columns, we'll reset this and start a new row

//TODO - add code for "display only" such as mod-limited and detail.php pages
		$template = $this->getRenderHTML($filter);

		if ($mode=='QUERY') {
			$keys=array_keys($efarr);
			for ($k=0; $k<count($keys); $k++) {
				$i=$keys[$k];
				$efarr[$i]['field_type'] = ARTIFACT_EXTRAFIELDTYPE_MULTISELECT;
			}
		}
		$keys=array_keys($efarr);
		for ($k=0; $k<count($keys); $k++) {
			$i=$keys[$k];
			if ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_SELECT) {
				$str = $this->renderSelect($efarr[$i]['extra_field_id'],$selected[$efarr[$i]['extra_field_id']],$show_100,$text_100,$show_any,$text_any);

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) {

				$str = $this->renderCheckbox($efarr[$i]['extra_field_id'],$selected[$efarr[$i]['extra_field_id']],$show_100,$text_100);

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_RADIO) {

				$str = $this->renderRadio($efarr[$i]['extra_field_id'],$selected[$efarr[$i]['extra_field_id']],$show_100,$text_100,$show_any,$text_any);

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_TEXT) {

				$str = $this->renderTextField($efarr[$i]['extra_field_id'],$selected[$efarr[$i]['extra_field_id']],$efarr[$i]['attribute1'],$efarr[$i]['attribute2']);

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_TEXTAREA) {

				$str = $this->renderTextArea($efarr[$i]['extra_field_id'],$selected[$efarr[$i]['extra_field_id']],$efarr[$i]['attribute1'],$efarr[$i]['attribute2']);

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT) {

				$str = $this->renderMultiSelectBox ($efarr[$i]['extra_field_id'],$selected[$efarr[$i]['extra_field_id']],$show_100,$text_100);

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_STATUS) {

				$str = $this->renderSelect($efarr[$i]['extra_field_id'],$selected[$efarr[$i]['extra_field_id']],$status_show_100,$text_100,$show_any,$text_any);

			}
			$template = str_replace('<!--'.$efarr[$i]['field_name'].'-->',$str,$template);
		}
		echo $template;
	}

	/**
	 *	getRenderHTML
	 *
	 *	@return	string	HTML template.
	 */
	function getRenderHTML($filter='') {
		return (($this->data_array['custom_renderer']) ? $this->data_array['custom_renderer'] : $this->generateRenderHTML($filter) );
	}

	/**
	 *	generateRenderHTML
	 *
	 *	@return	string	HTML template.
	 */
	function generateRenderHTML($filter='') {
		$efarr =& $this->getExtraFields($filter);
		//each two columns, we'll reset this and start a new row

		$return .= '
			<!-- Start Extra Fields Rendering -->
			<!-- COLUMN NAMES MUST BE PRESERVED EXACTLY, INCLUDING CASE! -->
			<tr>';
		$col_count=0;

		$keys=array_keys($efarr);
		$count=count($keys);
		for ($k=0; $k<$count; $k++) {
			$i=$keys[$k];

			if ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_SELECT) {

				$return .= '
					<td width="50%" valign="top"><strong>'.$efarr[$i]['field_name'].':<br /></strong><!--'.$efarr[$i]['field_name'].'--></td>';

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) {

				$return .= '
					<td width="50%" valign="top"><strong>'.$efarr[$i]['field_name'].':<br /></strong><!--'.$efarr[$i]['field_name'].'--></td>';

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_RADIO) {

				$return .= '
					<td width="50%" valign="top"><strong>'.$efarr[$i]['field_name'].':<br /></strong><!--'.$efarr[$i]['field_name'].'--></td>';

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_TEXT) {

				//text fields might be really wide, so need a row to themselves.
				if (($col_count == 1) && ($efarr[$i]['attribute1'] > 30)) {
					$colspan=2;
					$return .= '
					<td>&nbsp;</td>
			</tr>
			<tr>';
				} else {
					$colspan=1;
				}
				$return .= '
					<td width="'.(50*$colspan).'%" colspan="'.$colspan.'" valign="top"><strong>'.$efarr[$i]['field_name'].'</strong>:<br /><!--'.$efarr[$i]['field_name'].'--></td>';

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_TEXTAREA) {

				//text areas might be really wide, so need a row to themselves.
				if (($col_count == 1) && ($efarr[$i]['attribute2'] > 30)) {
					$colspan=2;
					$return .= '
					<td>&nbsp;</td>
			</tr>
			<tr>';
				} else {
					$colspan=1;
				}
				$return .= '
					<td width="'.(50*$colspan).'%" colspan="'.$colspan.'" valign="top"><strong>'.$efarr[$i]['field_name'].'</strong>:<br /><!--'.$efarr[$i]['field_name'].'--></td>';

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_MULTISELECT) {

				$return .= '
					<td width="50%" valign="top"><strong>'.$efarr[$i]['field_name'].'</strong>:<br /><!--'.$efarr[$i]['field_name'].'--></td>';

			} elseif ($efarr[$i]['field_type'] == ARTIFACT_EXTRAFIELDTYPE_STATUS) {

				$return .= '
					<td width="50%" valign="top"><strong>'.$efarr[$i]['field_name'].'</strong>:<br /><!--'.$efarr[$i]['field_name'].'--></td>';

			}
			$col_count++;
			//we've done two columns - if there are more to do, start a new row
			if (($col_count == 2) && ($k != $count-1)) {
				$col_count = 0;
				$return .= '
			</tr>
			<tr>';
			}
		}
		if ($col_count == 1) {
			$return .= '
					<td>&nbsp;</td>';
		}
		$return .= '
			</tr>
			<!-- End Extra Fields Rendering -->';
		return $return;
	}

	/**
	 *	renderSelect - this function builds pop up
	 *	box with choices.
	 *	
	 *	@param		int 	The ID of this field.
	 *	@param 		string	The item that should be checked
	 *	@param		string	Whether to show the '100 row'
	 *	@param		string	What to call the '100 row'
	 *	@return		box and choices	
	 */	
	function renderSelect ($extra_field_id,$checked='xzxz',$show_100=false,$text_100='none',$show_any=false,$text_any='Any') {
		global $Language;
		if ($text_100 == 'none'){
			$text_100=$Language->getText('tracker_artifacttype','none');
		}
		$arr =& $this->getExtraFieldElements($extra_field_id);
		for ($i=0; $i<count($arr); $i++) {
			$keys[$i]=$arr[$i]['element_id'];
			$vals[$i]=$arr[$i]['element_name'];
		}
		return html_build_select_box_from_arrays ($keys,$vals,'extra_fields['.$extra_field_id.']',$checked,$show_100,$text_100,$show_any,$text_any);
	}

	/**
	 *	renderRadio - this function builds radio buttons.
	 *	
	 *	@param		int 	The ID of this field.
	 *	@param 		string	The item that should be checked
	 *	@param		string	Whether to show the '100 row'
	 *	@param		string	What to call the '100 row'
	 *	@return		radio buttons
	 */	
	function renderRadio ($extra_field_id,$checked='xzxz',$show_100=false,$text_100='none',$show_any=false,$text_any='Any') {
		$arr =& $this->getExtraFieldElements($extra_field_id);
		for ($i=0; $i<count($arr); $i++) {
			$keys[$i]=$arr[$i]['element_id'];
			$vals[$i]=$arr[$i]['element_name'];
		}
		return html_build_radio_buttons_from_arrays ($keys,$vals,'extra_fields['.$extra_field_id.']',$checked,$show_100,$text_100,$show_any,$text_any);
	}

	/**
	 *	renderCheckbox - this function builds checkboxes.
	 *	
	 *	@param		int 	The ID of this field.
	 *	@param 		array	The items that should be checked
	 *	@param		string	Whether to show the '100 row'
	 *	@param		string	What to call the '100 row'
	 *	@return		radio buttons
	 */	
	function renderCheckbox ($extra_field_id,$checked=array(),$show_100=false,$text_100='none') {
		global $Language;
		if ($text_100 == 'none'){
			$text_100=$Language->getText('tracker_artifacttype','none');
		}
		if (!$checked || !is_array($checked)) {
			$checked=array();
		}
		$arr =& $this->getExtraFieldElements($extra_field_id);
		if ($show_100) {
			$return .= '
				<input type="checkbox" name="extra_fields['.$extra_field_id.'][]" value="100" '.
			((in_array(100,$checked)) ? 'CHECKED' : '').'>'.$text_100.'<br />';
		}
		for ($i=0; $i<count($arr); $i++) {
			$return .= '
				<input type="checkbox" name="extra_fields['.$extra_field_id.'][]" value="'.$arr[$i]['element_id'].'" '.
			((in_array($arr[$i]['element_id'],$checked)) ? 'CHECKED' : '').'>&nbsp;'.$arr[$i]['element_name'].'<br />';
		}
		return $return;
	}

	/**
	 *	renderMultiSelectBox - this function builds checkboxes.
	 *	
	 *	@param		int 	The ID of this field.
	 *	@param 		array	The items that should be checked
	 *	@param		string	Whether to show the '100 row'
	 *	@param		string	What to call the '100 row'
	 *	@return		radio multiselectbox
	 */	
	function renderMultiSelectBox ($extra_field_id,$checked=array(),$show_100=false,$text_100='none') {
		global $Language;
		$arr =& $this->getExtraFieldElements($extra_field_id);
		if (!$checked) {
			$checked=array();
		}
		if (!is_array($checked)) {
			$checked = explode(',',$checked);
		}	
		$keys=array();
		$vals=array();
		$arr =& $this->getExtraFieldElements($extra_field_id);
		for ($i=0; $i<count($arr); $i++) {
			$keys[]=$arr[$i]['element_id'];
			$vals[]=$arr[$i]['element_name'];
		}
		return html_build_multiple_select_box_from_arrays($keys,$vals,"extra_fields[$extra_field_id][]",$checked,15,$show_100,$text_100);
	}

	/**
	 *	renderTextField - this function builds a text field.
	 *	
	 *	@param		int 	The ID of this field.
	 *	@param 		string	The data for this field.
	 *	@return		text area and data.
	 */	
	function renderTextField ($extra_field_id,$contents,$size,$maxlength) {
		return '
			<input type="text" name="extra_fields['.$extra_field_id.']" value="'.$contents.'" size="'.$size.'" maxlength="'.$maxlength.'">';
	}

	/**
	 *	renderTextArea - this function builds a text area.
	 *	
	 *	@param		int 	The ID of this field.
	 *	@param 		string	The data for this field.
	 *	@return		text area and data.
	 */	
	function renderTextArea ($extra_field_id,$contents,$rows,$cols) {
		return '
			<textarea name="extra_fields['.$extra_field_id.']" rows="'.$rows.'" cols="'.$cols.'">'.$contents.'</textarea>';
	}

	function technicianBox ($name='assigned_to[]',$checked='xzxz',$show_100=true,$text_100='none',$extra_id='-1',$extra_name='',$multiple=false) {
		global $Language;
		if ($text_100=='none'){
			$text_100=$Language->getText('tracker_artifacttype','nobody');
		}
		$result = $this->getTechnicians();
		//	this was a bad hack to allow you to mass-update to unassigned, which is ID=100, which 
		//	conflicted with the "No Change" ID of 100.
		$ids =& util_result_column_to_array($result,0);
		$names =& util_result_column_to_array($result,1);
		if ($extra_id != '-1') {
			$ids[]=$extra_id;
			$names[]=$extra_name;
		}
			
		if ($multiple) {
			if (!is_array($checked)) {
				$checked = explode(',',$checked);
			}
			return html_build_multiple_select_box_from_arrays ($ids,$names,$name,$checked,15,$show_100,$text_100);
		} else {
			return html_build_select_box_from_arrays ($ids,$names,$name,$checked,$show_100,$text_100);
		}
	}

	function cannedResponseBox ($name='canned_response',$checked='xzxz') {
		return html_build_select_box ($this->getCannedResponses(),$name,$checked);
	}

	/**
	 *	statusBox - show the statuses - automatically shows the "custom statuses" if they exist
	 *
	 *	
	 */
	function statusBox ($name='status_id',$checked='xzxz',$show_100=false,$text_100='none') {
		global $Language;
		if ($text_100=='none'){
			$text_100=$Language->getText('tracker_artifacttype','none');
		}
		return html_build_select_box($this->getStatuses(),$name,$checked,$show_100,$text_100);
	}

}

?>