GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

displayPermissionsFieldsTracker()   F
last analyzed

Complexity

Conditions 55
Paths 1512

Size

Total Lines 250
Code Lines 163

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 250
rs 2
cc 55
eloc 163
nc 1512
nop 3

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
//
3
// Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4
//
5
// 
6
//
7
//
8
//	Originally by to the SourceForge Team,1999-2000
9
//
10
//  Written for Codendi by Stephane Bouhet
11
//
12
13
require_once('common/tracker/ArtifactType.class.php');
14
require_once('HTML_Graphs.php');
15
require_once('www/project/admin/ugroup_utils.php');
16
require_once('common/tracker/ArtifactGlobalNotificationFactory.class.php');
17
18
19
class ArtifactTypeHtml extends ArtifactType {
20
21
    var $FIELD_VALUE_STATUS_HIDDEN    = 'H';
22
    var $FIELD_VALUE_STATUS_PERMANENT = 'P';
23
    
24
	/**
25
	 *  ArtifactType() - constructor
26
	 *
27
	 *  @param $Group object
28
	 *  @param $artifact_type_id - the id # assigned to this artifact type in the db
29
	 */
30
	function ArtifactTypeHtml(&$Group,$artifact_type_id=false, $arr=false) {
31
		return $this->ArtifactType($Group,$artifact_type_id,$arr);
32
	}
33
34
    /**
35
     *  Display the header menu for this artifact type
36
     *
37
     *  @param params: array of parameters used to display the header
38
     *
39
     *  @return void
40
     */
41
    function header($params) {
42
        global $Language;
43
        $group_id= $this->Group->getID();
44
        $hp = Codendi_HTMLPurifier::instance();
45
46
        $GLOBALS['HTML']->includeJavascriptFile("/scripts/scriptaculous/scriptaculous.js");
47
        $GLOBALS['HTML']->includeJavascriptFile("/scripts/fieldDependencies.js");
48
        $GLOBALS['HTML']->includeJavascriptFile("/scripts/fieldEditor.js");
49
        $GLOBALS['HTML']->includeCalendarScripts();
50
        
51
        //required by new site_project_header
52
        $params['group']=$group_id;
53
        $params['toptab']='tracker';
54
        $params['tabtext']=$this->getName();
55
56
        site_project_header($params);
57
        if (!isset($params['pv']) || $params['pv'] == 0) {
58
            echo '<div id="tracker_toolbar_generic">'.$Language->getText('tracker_import_admin','tracker').' <a href="/tracker/?group_id='.(int)$group_id.'&atid='.(int)$this->getID().'"><span id="tracker_toolbar_tracker_name">'. $hp->purify(SimpleSanitizer::unsanitize($this->getName()), CODENDI_PURIFIER_CONVERT_HTML) .'</span></a> | ';
59
60
            echo '<a href="/tracker/?func=add&group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'">'.$Language->getText('tracker_include_type','submit_new', $hp->purify($this->getCapsItemName(), CODENDI_PURIFIER_CONVERT_HTML) ).'</a>';
61
            echo ' | <a href="/tracker/?func=browse&set=my&group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'">'.$Language->getText('tracker_include_type','my', $hp->purify($this->getCapsItemName(), CODENDI_PURIFIER_CONVERT_HTML) ).'s </a>';
62
            echo ' | <a href="/tracker/?func=browse&set=open&group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'">'.$Language->getText('tracker_include_type','open', $hp->purify($this->getCapsItemName(), CODENDI_PURIFIER_CONVERT_HTML) ).'s </a>';
63
            if ($this->userIsAdmin()) {
64
                echo ' | <a href="/tracker/?func=masschange&group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'">'.$Language->getText('tracker_index','mass_change').' </a>';
65
                echo ' | <a href="/tracker/?func=import&group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'">'.$Language->getText('tracker_import_admin','import').' </a>';
66
            }
67
            echo ' | <a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='.(int)$this->getID().'">'.$Language->getText('tracker_include_type','admin').'</a>';
68
            if ($params['help']) {
69
                echo ' | '.help_button($params['help'],false,$Language->getText('global','help'));
70
            }
71
72
            echo '</div>'.PHP_EOL;
73
        }
74
    }
75
76
	/**
77
	 *  Display the footer for this artifact type
78
	 *
79
	 *  @param params: array of parameters used to display the header
80
	 * 
81
	 *  @return void
82
	 */
83
	function footer($params) {
84
		site_project_footer($params);
85
	}
86
87
	/**
88
	 *  Display the admin header menu for this artifact type
89
	 *
90
	 *  @param params: array of parameters used to display the header
91
	 * 
92
	 *  @return void
93
	 */
94
	function adminHeader($params) {
95
	  global $Language;
96
97
		$group_id= $this->Group->getID();
98
99
        $GLOBALS['HTML']->includeJavascriptFile("/scripts/scriptaculous/scriptaculous.js");
100
        $GLOBALS['HTML']->includeJavascriptFile("/scripts/fieldDependencies.js");
101
        $GLOBALS['HTML']->includeCalendarScripts();
102
103
		//required by new site_project_header
104
		$params['group']=$group_id;
105
		$params['toptab']='tracker';
106
		$params['tabtext']=$this->getName();
107
108
		site_project_header($params);
109
110
		echo '<strong><a href="/tracker/admin/?group_id='.(int)$group_id.'">'.$Language->getText('tracker_index','admin_all_trackers').'</a>';
111
		echo ' | <a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'">'.$Language->getText('tracker_include_type','admin').'</a>';
112
		echo ' | <a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'&func=editoptions">'.$Language->getText('tracker_include_type','settings').'</a>';
113
		echo ' | <a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'&func=permissions">'.$Language->getText('tracker_include_type','permissions').'</a>';
114
        echo ' | <a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'&func=fieldsets">'.$Language->getText('tracker_include_type','fieldsets').'</a>';
115
		echo ' | <a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'&func=field_usage">'.$Language->getText('tracker_include_type','field_usage').'</a>';
116
		echo ' | <a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'&func=field_values">'.$Language->getText('tracker_include_type','field_values').'</a>';
117
		echo ' | <a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'&func=field_dependencies">'.$Language->getText('tracker_include_type','field_dependencies').'</a>';
118
		echo ' | <a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'&func=canned">'.$Language->getText('tracker_include_type','canned_resp').'</a>';
119
		echo ' | <a href="/tracker/admin/?func=report&group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'">'.$Language->getText('tracker_include_type','reports').'</a>';
120
121
        $em =& EventManager::instance();
122
        $em->processEvent('tracker_graphic_report_admin_header',null);
123
        		echo ' | <a href="/tracker/admin/?func=notification&group_id='.(int)$group_id.'&atid='. (int)$this->getID() .'&func=notification">'.$Language->getText('tracker_include_type','mail_notif').'</a>';
124
                echo ' | '.help_button($params['help'],false,$Language->getText('global','help'));
125
		echo '</strong><hr>';
126
	}
127
128
	/**
129
	 *  Display the admin header menu for artifact type
130
	 *
131
	 *  @param params: array of parameters used to display the header
132
	 * 
133
	 *  @return void
134
	 */
135
	function adminTrackersHeader($params) {
136
	  global $Language;
137
138
		$group_id= $this->Group->getID();
139
140
		//required by new site_project_header
141
		$params['group']=$group_id;
142
		$params['toptab']='tracker';
143
		$params['tabtext']=$this->getName();
144
145
		site_project_header($params);
146
147
		echo '<strong><a href="/tracker/admin/?group_id='.(int)$group_id.'">'.$Language->getText('tracker_index','admin_all_trackers').'</a>';
148
		echo ' | <a href="/tracker/admin/?group_id='.(int)$group_id.'&func=create">'.$Language->getText('tracker_index','create_new_tracker').'</a>';
149
		if ($params['help']) {
150
		    echo ' | '.help_button($params['help'],false,$Language->getText('global','help'));
151
		}
152
		echo '</strong><hr>';
153
	}
154
155
	/**
156
	 *  Display a select box for the canned responses
157
	 *
158
	 *  @param name: the select box name
159
	 *  @param checked: the default value
160
	 *  @param show_100: add the 100 value
161
	 *  @param text_100: the 100 label
162
	 * 
163
	 *  @return void
164
	 */
165
	function cannedResponseBox ($name='canned_response',$checked='xzxz') {
166
		return html_build_select_box ($this->getCannedResponses(),$name,$checked);
167
	}
168
	
169
	/**
170
	 *  Display the different options and the trackers lists
171
	 *
172
	 *  @return void
173
	 */
174
	function displayPendingTrackers() {
175
        $hp = Codendi_HTMLPurifier::instance();
176
		global $atf,$Language;
177
		
178
179
		echo '<form name="cal">';
180
		// Get the artfact type list
181
		$at_arr = $atf->getPendingArtifactTypes();
182
		echo '<H2>'.$Language->getText('tracker_include_type','pending_removal').'</H2>';
183
		if (!$at_arr) {
184
			echo '<h3>'.$Language->getText('tracker_include_type','no_pending').'</h3>';
185
		} else {
186
		    echo '<H3>'.$Language->getText('tracker_include_type','pending_deletion').'</H3>';
187
188
			$title_arr=array();
189
			$title_arr[]=$Language->getText('tracker_include_report','id');
190
			$title_arr[]=$Language->getText('global','Project');
191
			$title_arr[]=$Language->getText('tracker_import_admin','tracker');
192
			$title_arr[]=$Language->getText('tracker_include_type','deletion_date');
193
			$title_arr[]=$Language->getText('tracker_include_type','delay');
194
			$title_arr[]=$Language->getText('tracker_include_type','restore');
195
			$title_arr[]=$Language->getText('tracker_include_canned','delete');
196
			echo html_build_list_table_top ($title_arr);
197
		
198
			$fmt = "\n".'<TR class="%s"><td>%s</td><td>%s</td><td>%s</td><td>%s</td>'.
199
			    '<td align="center">%s</td><td align="center">%s</td><td align="center">%s</td></tr>';
200
			$i=0;
201
			while ($arr = db_fetch_array($at_arr)) {
202
			    echo sprintf($fmt,
203
					    util_get_alt_row_color($i),
204
					    $hp->purify($arr['group_artifact_id'], CODENDI_PURIFIER_CONVERT_HTML) ,
205
					    $hp->purify($arr['project_name'], CODENDI_PURIFIER_CONVERT_HTML) ,
206
					    $hp->purify(SimpleSanitizer::unsanitize($arr['name']), CODENDI_PURIFIER_CONVERT_HTML) ,
207
                        $GLOBALS['HTML']->getDatePicker("delay_date_".$i, "delay_date", date("Y-m-d",$arr['deletion_date'])),
208
					    '<a href="javascript: var delay = document.cal.delay_date.value; document.location=\'/tracker/admin/restore.php?func=delay&group_id='.$arr['group_id'].'&atid='.$arr['group_artifact_id'].'&delay_date=\'+delay;"><img src="'.util_get_image_theme("ic/save16b.png").'" border="0" onClick="return confirm(\''.$Language->getText('tracker_include_type','delay_deletion').'\')"></a>',
209
					    '<a href="/tracker/admin/restore.php?func=restore&group_id='.(int)$arr['group_id']."&atid=".(int)$arr['group_artifact_id'].'"><img src="'.util_get_image_theme("ic/convert.png").'" border="0" onClick="return confirm(\''.$Language->getText('tracker_include_type','restore_tracker').'\')"></a>',
210
					    '<a href="/tracker/admin/restore.php?func=delete&group_id='.(int)$arr['group_id']."&atid=".(int)$arr['group_artifact_id'].'"><img src="'.util_get_image_theme("ic/trash.png").'" border="0" onClick="return confirm(\''.$Language->getText('tracker_include_type','warning').'\')"></a>' );
211
			$i++;
212
			}
213
		    // final touch...
214
		    echo "</TABLE></form>";
215
		}
216
	}
217
	
218
	/**
219
	 *  Display the different options and the trackers lists
220
	 *
221
	 *  @return void
222
	 */
223
	function displayAdminTrackers() {
224
        $hp = Codendi_HTMLPurifier::instance();
225
		global $atf,$Language;
226
				
227
		// Get the artfact type list
228
		$at_arr = $atf->getArtifactTypes();
229
		
230
		if (!$at_arr || count($at_arr) < 1) {
231
		    echo '<h2>'.$Language->getText('tracker_index','no_accessible_trackers_hdr').'</h2>';
232
		    echo '<p>'.$Language->getText('tracker_index','no_accessible_trackers_msg').'</p>';
233
		} else {
234
		    echo '<H2>'.$Language->getText('tracker_admin_trackers','all_admin').'</H2>';
235
			echo '<H3><a href="/tracker/admin/?group_id='.(int)$this->Group->getID().'&func=create">'.$Language->getText('tracker_index','create_new_tracker').'</a></H3>';
236
			echo $Language->getText('tracker_include_type','create_from_scratch');
237
			echo '<H3>'.$Language->getText('tracker_include_type','manage').'</H3>';
238
			echo $Language->getText('tracker_include_type','admin_or_del').'<p>';
239
240
			$title_arr=array();
241
			$title_arr[]=$Language->getText('tracker_include_report','id');
242
			$title_arr[]=$Language->getText('tracker_import_admin','tracker');
243
			$title_arr[]=$Language->getText('tracker_include_artifact','desc');
244
                        if ($this->Group->isTemplate()) 
245
			        $title_arr[]=$Language->getText('tracker_include_type','instantiate').'?';
246
			$title_arr[]=$Language->getText('tracker_include_canned','delete');
247
			echo html_build_list_table_top ($title_arr);
248
		
249
                        if ($this->Group->isTemplate()) {
250
                            // Add an additional column 'Instantiate for new projects'
251
			    $fmt = "\n".'<TR class="%s"><td>%s</td><td>%s</td><td>%s</td><td align="center">%s</td>'.
252
			    '<td align="center">%s</td></tr>';
253
                        } else {
254
			    $fmt = "\n".'<TR class="%s"><td>%s</td><td>%s</td><td>%s</td>'.
255
			    '<td align="center">%s</td></tr>';
256
                        }
257
			for ($i = 0; $i < count($at_arr); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
258
                            if ($this->Group->isTemplate()) {
259
			       echo sprintf($fmt,
260
					    util_get_alt_row_color($i),
261
					    "<a href=\"/tracker/admin/?group_id=".(int)$this->Group->getID()."&atid=".(int)$at_arr[$i]->getID()."\">". $hp->purify($at_arr[$i]->getID(), CODENDI_PURIFIER_CONVERT_HTML) ."</a>",
262
					    $hp->purify(SimpleSanitizer::unsanitize($at_arr[$i]->getName()), CODENDI_PURIFIER_CONVERT_HTML) ,
263
					    $hp->purify(SimpleSanitizer::unsanitize($at_arr[$i]->getDescription()), CODENDI_PURIFIER_BASIC, $at_arr[$i]->getGroupId()) .'&nbsp;',
264
                                            ($at_arr[$i]->isInstantiatedForNewProjects()?'Yes':'No'),
265
					    "<a href=\"/tracker/admin/?func=delete_tracker&group_id=".(int)$this->Group->getID()."&atid=".(int)$at_arr[$i]->getID()."\"><img src=\"".util_get_image_theme("ic/trash.png")."\" border=\"0\" onClick=\"return confirm('".$Language->getText('tracker_include_type','warning')."')\"></a>" );
266
267
			    } else {
268
                                echo sprintf($fmt,
269
					    util_get_alt_row_color($i),
270
					    "<a href=\"/tracker/admin/?group_id=".(int)$this->Group->getID()."&atid=".(int)$at_arr[$i]->getID()."\">". $hp->purify($at_arr[$i]->getID(), CODENDI_PURIFIER_CONVERT_HTML) ."</a>",
271
					    $hp->purify(SimpleSanitizer::unsanitize($at_arr[$i]->getName()), CODENDI_PURIFIER_CONVERT_HTML) ,
272
					    $hp->purify(SimpleSanitizer::unsanitize($at_arr[$i]->getDescription()), CODENDI_PURIFIER_BASIC, $at_arr[$i]->getGroupId()) .'&nbsp;',
273
					    "<a href=\"/tracker/admin/?func=delete_tracker&group_id=".(int)$this->Group->getID()."&atid=".(int)$at_arr[$i]->getID()."\"><img src=\"".util_get_image_theme("ic/trash.png")."\" border=\"0\" onClick=\"return confirm('".$Language->getText('tracker_include_type','warning')."')\"></a>" );
274
                            }
275
			}
276
		    // final touch...
277
		    echo "</TABLE>";
278
		}
279
	}
280
	
281
	/**
282
	 *  Display the different options for administrate a tracker
283
	 *
284
	 *  @return void
285
	 */
286
	function displayAdminTracker($group_id,$atid) {
287
	  global $Language;
288
      $hp = Codendi_HTMLPurifier::instance();
289
	    echo '<H2>'.$Language->getText('tracker_import_admin','tracker').' \'<a href="/tracker/?group_id='.(int)$group_id.'&atid='.(int)$atid.'&func=browse">'.$hp->purify(SimpleSanitizer::unsanitize($this->getName()), CODENDI_PURIFIER_CONVERT_HTML).'</a>\''.$Language->getText('tracker_include_type','administration').'</H2>';
290
291
	    if ( $this->userIsAdmin() ) {
292
			echo '<H3><a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='.(int)$atid.'&func=editoptions">'.$Language->getText('tracker_include_type','settings').'</a></H3>';
293
			echo $Language->getText('tracker_include_type','define_title');
294
            echo '<H3><a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='.(int)$atid.'&func=permissions">'.$Language->getText('tracker_include_type','manage_permissions').'</a></H3>';
295
            echo $Language->getText('tracker_include_type','define_manage_permissions');
296
            echo '<H3><a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='.(int)$atid.'&func=fieldsets">'.$Language->getText('tracker_include_type','manage_fieldsets').'</a></H3>';
297
            echo $Language->getText('tracker_include_type','define_manage_fieldsets');
298
			echo '<H3><a href="/tracker/admin/?func=field_usage&group_id='.(int)$group_id.'&atid='.(int)$atid.'">'.$Language->getText('tracker_include_type','mng_field_usage').'</a></H3>';
299
			echo $Language->getText('tracker_include_type','define_use');
300
			echo '<H3><a href="/tracker/admin/?func=field_values&group_id='.(int)$group_id.'&atid='.(int)$atid.'">'.$Language->getText('tracker_include_type','mng_field_values').'</a></H3>';
301
			echo $Language->getText('tracker_include_type','define_values');
302
			echo '<H3><a href="/tracker/admin/?func=field_dependencies&group_id='.(int)$group_id.'&atid='.(int)$atid.'">'.$Language->getText('tracker_include_type','mng_field_dependencies').'</a></H3>';
303
			echo $Language->getText('tracker_include_type','define_field_dependencies');
304
			echo '<H3><a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='.(int)$atid.'&func=canned">'.$Language->getText('tracker_include_type','mng_response').'</a></H3>';
305
			echo $Language->getText('tracker_include_type','add_del_resp');
306
		}
307
308
		echo '<H3><a href="/tracker/admin/?func=report&group_id='.(int)$group_id.'&atid='.(int)$atid.'">'.$Language->getText('tracker_include_type','mng_reports').'</a></H3>';
309
		echo $Language->getText('tracker_include_type','define_reports');
310
		$em =& EventManager::instance();
311
        $em->processEvent('tracker_graphic_report_add_link',null);					
312
		echo '<H3><a href="/tracker/admin?func=notification&group_id='.(int)$group_id.'&atid='.(int)$atid.'">'.$Language->getText('tracker_include_type','mail_notif').'</a></H3>';
313
		echo $Language->getText('tracker_include_type','define_notif');
314
315
	}
316
317
        /**
318
         * Display Menu for permissions
319
         */
320
        function displayPermissionsGeneralMenu() {
321
            $this->displayAdminTitle($GLOBALS['Language']->getText('tracker_include_type','manage_permissions_title'));
322
            $permissions = array(
323
                                 array(
324
                                       'link' => '/tracker/admin/?group_id='.(int)$this->getGroupID().'&atid='.(int)$this->getID().'&func=permissions&perm_type=tracker',
325
                                       'name' => $GLOBALS['Language']->getText('tracker_include_type','manage_tracker_permissions'),
326
                                       'desc' => $GLOBALS['Language']->getText('tracker_include_type','define_manage_tracker_permissions')
327
                                       ),
328
                                 array(
329
                                       'link' => '/tracker/admin/?group_id='.(int)$this->getGroupID().'&atid='.(int)$this->getID().'&func=permissions&perm_type=fields',
330
                                       'name' => $GLOBALS['Language']->getText('tracker_include_type','manage_fields_tracker_permissions'),
331
                                       'desc' => $GLOBALS['Language']->getText('tracker_include_type','define_manage_fields_tracker_permissions')
332
                                       )
333
                                 );
334
            $this->_displayAdminMenu($permissions);
335
336
        }
337
338
        /**
339
         * Display the title of a tracker administration page
340
         * @protected
341
         */
342
        function displayAdminTitle($title) {
343
            $hp = Codendi_HTMLPurifier::instance();
344
            echo '<H2>',
345
                $GLOBALS['Language']->getText('tracker_import_admin','tracker'),
346
                ' \'<a href="/tracker/admin/?group_id=',(int)$this->getGroupID(),'&atid=',(int)$this->getID(),'">',
347
                 $hp->purify(SimpleSanitizer::unsanitize($this->getName()), CODENDI_PURIFIER_CONVERT_HTML) ,
348
                '</a>\'',
349
                $title,
350
                '</H2>';
351
        }
352
353
        /**
354
         * Display the items of the menu and their description
355
         * @params array the items, each item is ['link', 'name', 'desc']. 
356
         * Only name is mandatory (else the item is not displayed.
357
         * @protected
358
         */
359
        function _displayAdminMenu($items) {
360
            $hp = Codendi_HTMLPurifier::instance();
361
            $html = '';
362
            foreach($items as $item) {
363
                if (isset($item['name'])) {
364
                    $html .= '<H3>';
365
                    $name =  $hp->purify($item['name'], CODENDI_PURIFIER_CONVERT_HTML) ;
366
                    if (isset($item['link'])) {
367
                        $html .= '<a href="'.$item['link'].'">';
368
                        $html .= $name;
369
                        $html .= '</a>';
370
                    } else {
371
                        $html .= $name;
372
                    }
373
                    $html .= '</h3>';
374
                    if (isset($item['desc'])) {
375
                        $html .=  $hp->purify($item['desc'], CODENDI_PURIFIER_BASIC, $this->getGroupId()) ;
376
                    }
377
                }
378
            }
379
            echo $html;
380
        }
381
 
382
        /**
383
         * Display the permissions for the fields of this tracker
384
         * @param array the informations about ugroups ands their permissions :
385
         *              ugroups_permissions[field_id]['field'] = ['name', 'id', 'link']
386
         *                                           ['ugroups'][ugroup_id]['ugroup'] = ['name', 'id', 'link']
387
         *                                                           isset(['permissions'][PERMISSION_TYPE]) = true if ugroup has this permissions for the Field
388
         */
389
        function displayPermissionsFieldsTracker($ugroups_permissions, $group_first, $selected_id = false) {
390
            $hp = Codendi_HTMLPurifier::instance();
391
            $this->displayAdminTitle($GLOBALS['Language']->getText('tracker_include_type','manage_fields_tracker_permissions_title'));
392
393
            $submit_permission = 'TRACKER_FIELD_SUBMIT';
394
            $read_permission   = 'TRACKER_FIELD_READ';
395
            $update_permission = 'TRACKER_FIELD_UPDATE';
396
            $none = 'TRACKER_NONE';
397
            $attributes_for_selected = "selected='selected' style='background:#EEE;'"; //TODO: put style in stylesheet
398
 
399
            $html = '';
400
401
            //form
402
            $url_action_without_group_first = "?group_id=".(int)$this->getGroupID().'&atid='.(int)$this->getID()."&func=permissions&perm_type=fields";
403
            $url_action_with_group_first    = $url_action_without_group_first."&group_first=".($group_first?1:0);
404
405
            //The change form
406
            $group_first_value = ($group_first?1:0);
407
            $group_id          = (int)$this->getGroupID();
408
            $atid              = (int)$this->getID();
409
            $html .= <<<EOS
410
                <script type="text/javascript">
411
                <!--
412
                function changeFirstPartId(wanted) {
413
                   document.form_tracker_permissions_change.selected_id.value = wanted;
414
                   document.form_tracker_permissions_change.submit();
415
                }
416
                //-->
417
                </script>
418
                <form name="form_tracker_permissions_change" action="$url_action_with_group_first" method="get">
419
                      <input type="hidden" name="group_id" value="$group_id" />
420
                      <input type="hidden" name="atid" value="$atid" />
421
                      <input type="hidden" name="func" value="permissions" />
422
                      <input type="hidden" name="perm_type" value="fields" />
423
                      <input type="hidden" name="group_first" value="$group_first_value" />
424
                      <input type="hidden" name="selected_id" value="" />
425
                </form>
426
EOS;
427
428
            //We remove the pseudo field "comment_type"
429
            $comment_type_field_id = false;
430
            reset($ugroups_permissions);
431
            while((list($key,$value) = each($ugroups_permissions)) && !$comment_type_field_id) {
432
                if ($value['field']['shortname'] === "comment_type_id") {
433
                    $comment_type_field_id = $key;
434
                }
435
            }
436
            if ($comment_type_field_id) {
437
                unset($ugroups_permissions[$comment_type_field_id]);
438
            }
439
            if ($group_first) {
440
                //We reorganize the associative array
441
                $tablo = $ugroups_permissions;
442
                $ugroups_permissions = array();
443
                foreach($tablo as $key_field => $value_field) {
444
                    foreach($value_field['ugroups'] as $key_ugroup => $value_ugroup) {
445
                        if (!isset($ugroups_permissions[$key_ugroup])) {
446
                            $ugroups_permissions[$key_ugroup] = array(
447
                                                                      'values'              => $value_ugroup['ugroup'],
448
                                                                      'related_parts'       => array(),
449
                                                                      'tracker_permissions' => $value_ugroup['tracker_permissions']
450
                                                                      );
451
452
                        }
453
                        $ugroups_permissions[$key_ugroup]['related_parts'][$key_field] = array(
454
                                                                                        'values'       => $value_field['field'],
455
                                                                                        'permissions' => $value_ugroup['permissions']
456
                                                                                        );
457
                    }
458
                }
459
                ksort($ugroups_permissions);
460
                $header = array(
461
                                $GLOBALS['Language']->getText('tracker_admin_permissions', 'ugroup'), 
462
                                $GLOBALS['Language']->getText('tracker_include_report', 'field_label'),
463
                                $GLOBALS['Language']->getText('tracker_admin_permissions', $submit_permission),
464
                                $GLOBALS['Language']->getText('tracker_admin_permissions', 'permissions')) ;
465
            } else {
466
                foreach($ugroups_permissions as $key_field => $value_field) {
467
                    $ugroups_permissions[$key_field]['values']        =& $ugroups_permissions[$key_field]['field'];
468
                    $ugroups_permissions[$key_field]['related_parts'] =& $ugroups_permissions[$key_field]['ugroups'];
469
                    foreach($value_field['ugroups'] as $key_ugroup => $value_ugroup) {
470
                        $ugroups_permissions[$key_field]['related_parts'][$key_ugroup]['values'] =& $ugroups_permissions[$key_field]['related_parts'][$key_ugroup]['ugroup'];
471
                    }
472
                    ksort($ugroups_permissions[$key_field]['related_parts']);
473
                    reset($ugroups_permissions[$key_field]['related_parts']);
474
                }
475
                $header = array(
476
                               $GLOBALS['Language']->getText('tracker_include_report', 'field_label'), 
477
                               $GLOBALS['Language']->getText('tracker_admin_permissions', 'ugroup'), 
478
                               $GLOBALS['Language']->getText('tracker_admin_permissions', $submit_permission),
479
                               $GLOBALS['Language']->getText('tracker_admin_permissions', 'permissions')) ;
480
            }
481
            reset($ugroups_permissions);
482
            list($key, $value) = each($ugroups_permissions);
0 ignored issues
show
Unused Code introduced by
The assignment to $value is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
483
484
485
            //header
486
            if (($group_first && count($ugroups_permissions) < 1) || (!$group_first && count($ugroups_permissions[$key]['related_parts']) < 1)) {
487
                $html .= $GLOBALS['Language']->getText('tracker_admin_permissions', 'fields_no_ugroups');
488
            } else {
489
                
490
                //The permission form
491
                $html .= "<form name='form_tracker_permissions' action='".$url_action_with_group_first."' method='post'>";
492
                $html .= "<div>";
493
                $html .= '<input type="hidden" name="selected_id" value="'.($selected_id?(int)$selected_id:"false").'" />';
494
                //intro
495
                $html .= $GLOBALS['Language']->getText('tracker_admin_permissions', 'fields_tracker_intro');
496
                
497
                //We display 'group_first' or 'field_first'
498
                if ($group_first) {
499
                    $html .= $GLOBALS['Language']->getText('tracker_admin_permissions', 
500
                                                           'fields_tracker_toggle_field', 
501
                                                           $url_action_without_group_first."&group_first=0");
502
                } else {
503
                    $html .= $GLOBALS['Language']->getText('tracker_admin_permissions', 
504
                                                           'fields_tracker_toggle_group', 
505
                                                           $url_action_without_group_first."&group_first=1");
506
                }
507
508
                $html .= html_build_list_table_top($header);
509
                
510
                //body
511
                $i = 0;
512
                $a_star_is_displayed = false;
513
                
514
                //The select box for the ugroups or fields (depending $group_first)
515
                $html .= "\n<tr class='". util_get_alt_row_color($i++)."'>";
516
                $html .= "<td rowspan='".(count($ugroups_permissions[$key]['related_parts'])+1)."' style='vertical-align:top;'>";
517
                $html .= "<select onchange=\"changeFirstPartId(this.options[this.selectedIndex].value);\">";
518
                foreach($ugroups_permissions as $part_permissions) {
519
                    if ($selected_id === false) {
520
                        $selected_id = $part_permissions['values']['id'];
521
                    }                   
522
                    $html .= "<option value='".(int)$part_permissions['values']['id']."' ";
523
                    if ($part_permissions['values']['id'] === $selected_id) {
524
                        $first_part    = $part_permissions['values'];
525
                        $related_parts = $part_permissions['related_parts'];
526
                        $html .= $attributes_for_selected;
527
                    }
528
                    $html .= " >";
529
                    $html .= $part_permissions['values']['name'];
530
                    if ($group_first) {
531
                        if (isset($part_permissions['tracker_permissions'])
532
                        && count($part_permissions['tracker_permissions']) === 0) {
533
                            $html .= " *";
534
                            $a_star_is_displayed = true;
535
                        }
536
                    }
537
                    $html .= "</option>";
538
                }
539
                $html .= "</select>";
540
                $html .= "</td>";
541
                $is_first = true;
542
                
543
                //The permissions for the current item (field or ugroup, depending $group_id)
544
                foreach($related_parts as $ugroup_permissions) {
545
                    $second_part = $ugroup_permissions['values'];
546
                    $permissions = $ugroup_permissions['permissions'];
547
                    
548
                    
549
                    //The group
550
                    if (!$is_first) {
551
                        $html .= "\n<tr class='". util_get_alt_row_color($i++)."'>";
552
                    } else {
553
                        $is_first = false;
554
                    }
555
                    $html .= '<td>';
556
                    
557
                    $name = "<a href='".$url_action_without_group_first."&selected_id=".(int)$second_part['id']."&group_first=".($group_first?0:1)."'>";
558
                    $name .=  $hp->purify($second_part['name'], $group_first ? CODENDI_PURIFIER_DISABLED : CODENDI_PURIFIER_BASIC ) ;
559
                    $name .= "</a>";
560
                    if (!$group_first && isset($ugroup_permissions['tracker_permissions']) && count($ugroup_permissions['tracker_permissions']) === 0) {
561
                        $name = "<span >".$name." *</span>"; //TODO css
562
                        $a_star_is_displayed = true;
563
                    }
564
                    $html .= $name;
565
                    
566
                    $html .= '</td>';
567
                    
568
                    //The permissions
569
                    {
570
                        //Submit permission
571
                        $html .= "<td style='text-align:center;'>";
572
                        if ($group_first) {
573
                            $name_of_variable = "permissions[".(int)$second_part['id']."][".(int)$first_part['id']."]";
574
                        } else {
575
                            $name_of_variable = "permissions[".(int)$first_part['id']."][".(int)$second_part['id']."]";
576
                        }
577
                        $html .= "<input type='hidden' name='".$name_of_variable."[submit]' value='off'/>";
578
                        
579
                        $can_submit_or_update = (($group_first 
580
                                                   && $second_part['shortname'] !== "artifact_id"
581
                                                   && $second_part['shortname'] !== "submitted_by"
582
                                                   && $second_part['shortname'] !== "open_date"
583
                                                   && $second_part['shortname'] !== "last_update_date")
584
                                                  ||
585
                                                  (!$group_first 
586
                                                   && $first_part['shortname'] !== "artifact_id"
587
                                                   && $first_part['shortname'] !== "submitted_by"
588
                                                   && $first_part['shortname'] !== "open_date"
589
                                                   && $first_part['shortname'] !== "last_update_date"));
590
                        
591
                        $can_submit = $can_submit_or_update; //(And add here those who can only be submitted)
592
593
                        $can_update = $can_submit_or_update &&  (($group_first && $first_part['id'] > 2)
594
								 ||
595
								 (!$group_first && $second_part['id'] > 2));
596
597
                        $html .= "<input type='checkbox' name=\"".$name_of_variable.'[submit]"  '.
598
                            (isset($permissions[$submit_permission])?"checked='checked'":"")." ".($can_submit?"":"disabled='disabled'")." /> ";
599
                        $html .= "</td><td>";
600
                        
601
                        
602
                        //Other permissions (R/W)
603
                        $html .= "<select name='".$name_of_variable."[others]' >";
604
                        $html .= "<option value='100' ".(!isset($permissions[$read_permission]) && !isset($permissions[$update_permission])?$attributes_for_selected:"")." >".$GLOBALS['Language']->getText('tracker_admin_permissions', $none)."</option>";
605
                        $html .= "<option value='0' ".(isset($permissions[$read_permission]) && !isset($permissions[$update_permission])?$attributes_for_selected:"")." >".$GLOBALS['Language']->getText('tracker_admin_permissions', $read_permission)."</option>";
606
                        
607
                        if ($can_update) {
608
                            $html .= "<option value='1' ".(isset($permissions[$update_permission])?$attributes_for_selected:"")." >".$GLOBALS['Language']->getText('tracker_admin_permissions', $update_permission)."</option>";
609
                        }
610
                        $html .= "</select>";
611
                        
612
                    }
613
                    $html .= "</td>";
614
                    $html .= "</tr>\n";
615
                }
616
                
617
                //end of table
618
                $html .= "</table>";
619
                if ($a_star_is_displayed) {
620
                    $html .= $GLOBALS['Language']->getText('tracker_admin_permissions', 'ug_may_have_no_access',"/tracker/admin/?group_id=".(int)$this->getGroupID()."&atid=".(int)$this->getID()."&func=permissions&perm_type=tracker");
621
                }
622
                $html .= "<input type='submit' name='update' value=\"".$GLOBALS['Language']->getText('project_admin_permissions','submit_perm')."\" />";
623
                //{{{20050602 NTY: removed. what is default permissions ???
624
                //$html .= "<input type='submit' name='reset' value=\"".$GLOBALS['Language']->getText('project_admin_permissions','reset_to_def')."\" />";
625
                //}}}
626
            }
627
            $html .= "</div></form>";
628
            $html .= "<p>";
629
            $html .= $GLOBALS['Language']->getText('project_admin_permissions',
630
                                                   'admins_create_modify_ug',
631
                                                   array(
632
                                                         "/project/admin/editugroup.php?func=create&group_id=".(int)$this->getGroupID(),
633
                                                         "/project/admin/ugroup.php?group_id=".(int)$this->getGroupID()
634
                                                         )
635
                                                   );
636
            $html .= "</p>";
637
            print $html;
638
        }
639
640
        /**
641
         * Display the permissions for this tracker
642
         * @param array the informations about ugroups ands their permissions :
643
         *              ugroups_permissions[i]['ugroup'] = ['name', 'id', 'link']
644
         *                              isset(['permissions'][PERMISSION_TYPE]) = true if ugroup has this permissions for the artifactType
645
         */
646
        function displayPermissionsTracker($ugroups_permissions) {
647
            $hp = Codendi_HTMLPurifier::instance();
648
            $this->displayAdminTitle($GLOBALS['Language']->getText('tracker_include_type','manage_tracker_permissions_title'));
649
            $full_permission      = 'TRACKER_ACCESS_FULL';
650
            $assignee_permission  = 'TRACKER_ACCESS_ASSIGNEE';
651
            $submitter_permission = 'TRACKER_ACCESS_SUBMITTER';
652
            $none                 = 'TRACKER_NONE';
653
654
            $html = '';
655
656
            //form
657
            $html .= "<form name='form_tracker_permissions' action='?group_id=".(int)$this->getGroupID().'&atid='.(int)$this->getID()."&func=permissions&perm_type=tracker' method='post'>";
658
            $html .= "<div>";
659
660
            //intro
661
            $html .= $GLOBALS['Language']->getText('tracker_admin_permissions', 'tracker_intro');
662
663
            //header
664
            $html .= html_build_list_table_top(array(
665
                                                     $GLOBALS['Language']->getText('tracker_admin_permissions', 'ugroup'), 
666
                                                     $GLOBALS['Language']->getText('tracker_admin_permissions', 'permissions')));
667
668
            //body
669
            ksort($ugroups_permissions);
670
            reset($ugroups_permissions);
671
            $i = 0;
672
            foreach($ugroups_permissions as $ugroup_permissions) {
673
                $ugroup      = $ugroup_permissions['ugroup'];
674
                $permissions = $ugroup_permissions['permissions'];
675
                
676
                $html .= '<tr class="'. util_get_alt_row_color($i++).'">';
677
                $html .= '<td>';
678
                $name  =  $hp->purify($ugroup['name'], CODENDI_PURIFIER_CONVERT_HTML) ;
679
                if (isset($ugroup['link'])) {
680
                    $html .= "<a href='".$ugroup['link']."'>";
681
                    $html .= $name;
682
                    $html .= "</a>";
683
                } else {
684
                    $html .= $name;
685
                }
686
                $html .= '</td>';
687
                $html .= "<td>";
688
689
                $html .="<select name='permissions_".$ugroup['id']."' >";
690
                $attributes_for_selected = "selected='selected' style='background:#EEE;'"; //TODO: put style in stylesheet
691
                $html .= "<option value='100' ".(count($permissions) == 0?$attributes_for_selected:"")." >".$GLOBALS['Language']->getText('tracker_admin_permissions', $none)."</option>";
692
                $html .= "<option value='0' ".(isset($permissions[$full_permission])?$attributes_for_selected:"")." >".$GLOBALS['Language']->getText('tracker_admin_permissions', $full_permission)."</option>";
693
                
694
                //We don't show specific access permissions for anonymous users and registered
695
                if ($ugroup['id'] != $GLOBALS['UGROUP_ANONYMOUS'] && $ugroup['id'] != $GLOBALS['UGROUP_REGISTERED']) {
696
                    $html .= "<option value='1' ".(isset($permissions[$assignee_permission]) && !isset($permissions[$submitter_permission])?$attributes_for_selected:"")." >".$GLOBALS['Language']->getText('tracker_admin_permissions', $assignee_permission)."</option>";
697
                    $html .= "<option value='2' ".(!isset($permissions[$assignee_permission]) && isset($permissions[$submitter_permission])?$attributes_for_selected:"")." >".$GLOBALS['Language']->getText('tracker_admin_permissions', $submitter_permission)."</option>";
698
                    $html .= "<option value='3' ".(isset($permissions[$assignee_permission]) && isset($permissions[$submitter_permission])?$attributes_for_selected:"")." >".$GLOBALS['Language']->getText('tracker_admin_permissions', $assignee_permission."_AND_".$submitter_permission)."</option>";
699
                }
700
                $html .= '</select></td>';
701
                $html .= '</tr>';
702
            }
703
            //end of table
704
            $html .= "</table>";
705
            $html .= "<input type='submit' name='update' value=\"".$GLOBALS['Language']->getText('project_admin_permissions','submit_perm')."\" />";
706
            //{{{20050602 NTY: removed. what is default permissions ???
707
            //$html .= "<input type='submit' name='reset' value=\"".$GLOBALS['Language']->getText('project_admin_permissions','reset_to_def')."\" />";
708
            //}}}
709
            $html .= "</div></form>";
710
            $html .= "<p>";
711
            $html .= $GLOBALS['Language']->getText('project_admin_permissions',
712
                                                   'admins_create_modify_ug',
713
                                                   array(
714
                                                         "/project/admin/editugroup.php?func=create&group_id=".(int)$this->getGroupID(),
715
                                                         "/project/admin/ugroup.php?group_id=".(int)$this->getGroupID()
716
                                                         )
717
                                                   );
718
            $html .= "</p>";
719
            print $html;
720
            
721
        }
722
	/**
723
	 *  Display the select box with the permissions values
724
	 *
725
	 *  @return void
726
	 */
727
	function displayPermValues($i,$perm_level) {
728
	  global $Language;
729
730
		$out = '<FONT size="-1"><SELECT name="user_name['.$i.']">';
731
		$out .= '<OPTION value="0"'.(($perm_level==0)?" selected":"").'>'.$Language->getText('global','none');
732
		$out .= '<OPTION value="1"'.(($perm_level==1)?" selected":"").'>'.$Language->getText('project_admin_userperms','tech_only');
733
		$out .= '<OPTION value="2"'.(($perm_level==2)?" selected":"").'>'.$Language->getText('project_admin_userperms','tech&admin');
734
		$out .= '<OPTION value="3"'.(($perm_level==3)?" selected":"").'>'.$Language->getText('project_admin_userperms','admin_only');
735
		$out .= '</SELECT></FONT>';
736
		
737
		return $out;
738
	}
739
740
	/**
741
	 *  Display the users permissions for this tracker
742
	 *
743
	 *  @return void
744
	 */
745
	function displayUsersPerm() {
746
		
747
	  global $Language;
748
749
	    $result=$this->getUsersPerm($this->getID());
750
	    $rows=db_numrows($result);
751
	
752
	    if ($rows > 0) {
753
	
754
			$title_arr=array();
755
			$title_arr[]=$Language->getText('tracker_include_type','user');
756
			$title_arr[]=$Language->getText('tracker_include_type','perm');
757
			$title_arr[]=$Language->getText('tracker_include_canned','delete');
758
					
759
			echo html_build_list_table_top ($title_arr);
760
		
761
			for ($i=0; $i < $rows; $i++) {
762
				$user_id = db_result($result, $i, 'user_id');
763
			    $user_name = db_result($result, $i, 'user_name');
764
			    $perm_level =  db_result($result, $i, 'perm_level');
765
		
766
			    echo '<TR class="'. util_get_alt_row_color($i).'">'.
767
			    	 '<TD>'.util_user_link($user_name).'</TD>';
768
				echo '<TD align="center">'.$this->displayPermValues($i,$perm_level).'</TD>';
769
				echo '<TD align="center"><a href="/tracker/admin/?group_id='.(int)$this->Group->getID().'&atid='.(int)$this->getID().'&func=deleteuser&user_id='.(int)$user_id.'"><img src="'.util_get_image_theme("ic/trash.png").'" border="0" onClick="return confirm(\''.$Language->getText('tracker_include_type','del_user').'\')"></a></TD>';
770
				echo '</TR>';
771
			}
772
			echo '</TABLE>';
773
		} else {
774
			echo '<H3>'.$Language->getText('tracker_include_type','no_user').'</H3>';
775
		}
776
		
777
	}
778
	
779
	
780
	/**
781
	 *  Display the differents options for this tracker
782
	 *
783
	 *  @return void
784
	 */
785
	function displayOptions($group_id,$atid) {
786
        $hp = Codendi_HTMLPurifier::instance();
787
	  global $Language;
788
789
		echo '<H2>'.$Language->getText('tracker_import_admin','tracker').' \'<a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='.(int)$atid.'">'. $hp->purify(SimpleSanitizer::unsanitize($this->getName()), CODENDI_PURIFIER_CONVERT_HTML) .'</a>\' - '.$Language->getText('tracker_include_type','settings').'</H2>';
790
		echo '<form name="form1" >
791
		  <input type="hidden" name="update" value="1">
792
		  <input type="hidden" name="group_id" value="'.(int)$group_id.'">
793
		  <input type="hidden" name="atid" value="'.(int)$atid.'">
794
		  <input type="hidden" name="func" value="editoptions">
795
		  <table width="100%" border="0" cellpadding="5">
796
		    <tr> 
797
		      <td width="21%"><b>'.$Language->getText('tracker_include_artifact','name').'</b> <font color="red">*</font>:</td>
798
		      <td width="79%"> 
799
              <input type="text" name="name" value="'. $hp->purify(SimpleSanitizer::unsanitize($this->getName()), CODENDI_PURIFIER_CONVERT_HTML) .'">
800
		      </td>
801
		    </tr>
802
		    <tr> 
803
		      <td width="21%"><b>'.$Language->getText('tracker_include_artifact','desc').'</b>: <font color="red">*</font></td>
804
		      <td width="79%"> 
805
		        <textarea name="description" rows="3" cols="50">'. $hp->purify(SimpleSanitizer::unsanitize($this->getDescription()), CODENDI_PURIFIER_CONVERT_HTML) .'</textarea>
806
		      </td>
807
		    </tr>
808
		    <tr> 
809
		      <td width="21%"><b>'.$Language->getText('tracker_include_type','short_name').'</b>: <font color="red">*</font></td>
810
		      <td width="79%"> 
811
		        <input type="text" name="itemname" value="'. $hp->purify($this->getItemName(), CODENDI_PURIFIER_CONVERT_HTML) .'">
812
		      </td>
813
		    </tr>
814
		    <tr> 
815
		      <td width="21%"><b>'.$Language->getText('tracker_include_type','allow_copy').'</b></td>
816
		      <td width="79%">';
817
		if ( $this->allowsCopy() ) {
818
			echo '<input type="checkbox" name="allow_copy" value="1" checked>';
819
		} else {
820
			echo '<input type="checkbox" name="allow_copy" value="1">';
821
		}
822
		echo '	
823
		      </td>
824
		    </tr>';
825
826
		if ( $this->Group->isTemplate() ) { // Template group
827
		echo '	
828
		    <tr> 
829
		      <td width="21%"><b>'.$Language->getText('tracker_include_type','instantiate').':</b></td>
830
		      <td width="79%">';
831
		if ( $this->isInstantiatedForNewProjects() ) {
832
			echo '<input type="checkbox" name="instantiate_for_new_projects" value="1" checked>';
833
		} else {
834
			echo '<input type="checkbox" name="instantiate_for_new_projects" value="1">';
835
		}
836
		echo '	
837
		      </td>
838
		    </tr>';
839
                } else {
840
                    echo '<input type="hidden" name="instantiate_for_new_projects" value="0">';
841
                }
842
		echo '	
843
		    <tr> 
844
		      <td width="21%">'.$Language->getText('tracker_include_type','submit_instr').'</td>
845
		      <td width="79%"> 
846
		        <textarea name="submit_instructions" rows="3" cols="50">'. $hp->purify($this->getSubmitInstructions(), CODENDI_PURIFIER_CONVERT_HTML) .'</textarea>
847
		      </td>
848
		    </tr>
849
		    <tr> 
850
		      <td width="21%">'.$Language->getText('tracker_include_type','browse_instr').'</td>
851
		      <td width="79%"> 
852
		        <textarea name="browse_instructions" rows="3" cols="50">'. $hp->purify($this->getBrowseInstructions(), CODENDI_PURIFIER_CONVERT_HTML) .'</textarea>
853
		      </td>
854
		    </tr>
855
		  </table>
856
		  <p align="center"><input type="submit" value="'.$Language->getText('global','btn_submit').'"></p>
857
		</form>';
858
	}
859
860
861
	/**
862
	 *  Display a select box for the tracker list for a group
863
	 *
864
	 *  @param group_id: the project id
865
	 *  @param name: the select box name
866
	 *  @param checked: the default value
867
	 * 
868
	 *  @return void
869
	 */
870
	function trackersSelectBox ($group_id,$name,$checked='xzxz') {
871
		global $atf;
872
        $hp = Codendi_HTMLPurifier::instance();
873
                $tracker_names = array();
874
                $tracker_ids   = array();
875
                $trackers_array = $atf->getArtifactTypesFromId($group_id);
876
                if ( $trackers_array !== false) {                    
877
                    foreach($trackers_array as $tracker) {
878
                        $tracker_names[] =  $hp->purify(SimpleSanitizer::unsanitize($tracker->getName()), CODENDI_PURIFIER_CONVERT_HTML) ;
879
                        $tracker_ids[] = $tracker->getId();
880
                    }
881
                }
882
		
883
		return html_build_select_box_from_arrays($tracker_ids,$tracker_names, $name,$checked);
0 ignored issues
show
Deprecated Code introduced by
The function html_build_select_box_from_arrays() has been deprecated with message: This function miss some purifications voluntary. Please, DO NOT USE it anymore !

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
884
	}
885
886
	/**
887
	 *  Display the create tracker form
888
	 *
889
	 *  @param group_id: the group id
890
	 *  @param codendi_template: the artifact type id chosen for a Codendi template
891
	 *  @param group_id_template: the group id chosen for an existing tracker
892
	 *  @param atid_template: the artifact type id chosen for an existing tracker
893
	 *  @param name: the name chosen
894
	 *  @param description: the description chosen
895
	 *  @param itemname: the short name chosen
896
	 *
897
	 *  @return void
898
	 */
899
	function displayCreateTracker($group_id,$codendi_template,$group_id_template,$atid_template,$name,$description,$itemname) {
900
	  global $Language;
901
        $hp = Codendi_HTMLPurifier::instance();
902
		echo '<script language="JavaScript">
903
		      function trimStr(value) {
904
		      	trimValue = "";
905
		      	for(i=0;i<value.length;i++) {
906
		      		if ( value.charAt(i) != " " ) {
907
		      			trimValue = trimValue + value.charAt(i);
908
		      		}
909
		      	}
910
		      	return trimValue;
911
		      }
912
		    
913
			  function onChangeGroup() {
914
			  	document.form_create.func.value = "create";
915
			  	document.form_create.submit();
916
			  }
917
			  
918
			  function checkValues() {
919
			  	if ( trimStr(document.form_create.name.value) == "" ) {
920
		  			document.form_create.feedback.value = "'.$Language->getText('tracker_include_type','fill_name').'";
921
		  			return false;
922
				}
923
			  	if ( trimStr(document.form_create.description.value) == "" ) {
924
		  			document.form_create.feedback.value = "'.$Language->getText('tracker_include_type','fill_desc').'";
925
		  			return false;
926
				}
927
			  	if ( trimStr(document.form_create.itemname.value) == "" ) {
928
		  			document.form_create.feedback.value = "'.$Language->getText('tracker_include_type','fill_short').'";
929
		  			return false;
930
				}
931
	  			return true;
932
				
933
			  }
934
			
935
			  function onSubmitCreateTemplate() {
936
			  	if ( checkValues() ) {
937
			  		if ( (document.form_create.group_id_template.value == "")||(document.form_create.atid_template.value == "") ) {
938
			  			document.form_create.feedback.value = "'.$Language->getText('tracker_include_type','choose_proj').'";
939
					  	document.form_create.func.value = "create";
940
			  		}
941
			  		document.form_create.atid_chosen.value = document.form_create.atid_template.value;
942
			  		document.form_create.group_id_chosen.value = document.form_create.group_id_template.value;
943
				} else {
944
				  	document.form_create.func.value = "create";
945
				}
946
			  	document.form_create.submit();
947
			  }
948
949
			  function onSubmitCreateCodendiTemplate() {
950
			  	if ( checkValues() ) {
951
                    if ( document.form_create.codendi_template.value == 100 ) {
952
			  			document.form_create.feedback.value = "'.$Language->getText('tracker_include_type','choose_tmpl').'";
953
					  	document.form_create.func.value = "create";
954
			  		}
955
			  		document.form_create.atid_chosen.value = document.form_create.codendi_template.value;
956
			  		document.form_create.group_id_chosen.value = 100;
957
				} else {
958
				  	document.form_create.func.value = "create";
959
				}
960
			  	document.form_create.submit();
961
			  }
962
963
			  function showGroupSelection() {
964
			  	win=window.open("","group_id_selection","height=210,width=480,toolbar=no,location=no,resizable=yes,left=200,top=200");
965
				win.location = "/tracker/group_selection.php?opener_form=form_create&opener_field=group_id_template&filter=member";
966
			  }
967
968
			  function showTrackerSelection() {
969
			  	if ( document.form_create.group_id_template.value == "" ) {
970
			  		alert("'.$Language->getText('tracker_include_type','select_proj').'");
971
			  		return;
972
			  	}
973
			  	win=window.open("","artifact_group_id_selection","height=45,width=400,toolbar=no,location=no,resizable=yes,left=200,top=200");
974
				win.location = "/tracker/tracker_selection.php?group_id=" + document.form_create.group_id_template.value + "&opener_form=form_create&opener_field=atid_template";
975
			  }
976
977
			  </script>
978
			 ';
979
		echo $Language->getText('tracker_include_type','create_tracker');
980
		echo '<form name="form_create" >
981
		  <input type="hidden" name="group_id" value="'.(int)$group_id.'">
982
		  <input type="hidden" name="func" value="docreate">
983
		  <input type="hidden" name="atid_chosen" value="">
984
		  <input type="hidden" name="group_id_chosen" value="">
985
		  <input type="hidden" name="feedback" value="">
986
		  <table width="100%" border="0" cellpadding="5">
987
		    <tr> 
988
		      <td width="21%"><b>'.$Language->getText('tracker_include_artifact','name').'</b>: <font color="red">*</font></td>
989
		      <td width="79%"> 
990
		        <input type="text" name="name" value="'. $hp->purify($name, CODENDI_PURIFIER_CONVERT_HTML) .'">
991
		      </td>
992
		    </tr>
993
		    <tr> 
994
		      <td width="21%"><b>'.$Language->getText('tracker_include_artifact','desc').'</b>: <font color="red">*</font></td>
995
		      <td width="79%"> 
996
		        <textarea name="description" rows="3" cols="50">'. $hp->purify($description, CODENDI_PURIFIER_CONVERT_HTML) .'</textarea>
997
		      </td>
998
		    </tr>
999
		    <tr> 
1000
		      <td width="21%"><b>'.$Language->getText('tracker_include_type','short_name').'</b>: <font color="red">*</font></td>
1001
		      <td width="79%"> 
1002
		        <input type="text" name="itemname" value="'. $hp->purify($itemname, CODENDI_PURIFIER_CONVERT_HTML) .'">
1003
		      </td>
1004
		    </tr>
1005
                    <tr><td colspan=2><i>'.$Language->getText('tracker_include_type','avoid_spaces').'</i></td></tr>';
1006
		echo '</table>';
1007
		echo '<p>'.$Language->getText('tracker_include_type','choose_creation').'</p>';
1008
		echo '<table>
1009
			  <tr valign="top">
1010
			     <td width="300"><li><b>'.$Language->getText('tracker_include_type','from_tmpl').'</b></li></td>
1011
			     <td colspan="2">';
1012
        echo $this->trackersSelectBox(100,"codendi_template",$codendi_template);
1013
        echo '	 &nbsp;<input type="button" name="CreateCodendiTemplate" value="'.$Language->getText('global','btn_create').'" onClick="onSubmitCreateCodendiTemplate()"><br><br></td>
1014
			  <tr valign="top">    
1015
			     <td width="300"><li>'.$Language->getText('tracker_include_type','from_exist').'</li></td>
1016
			     
1017
			     <td>
1018
			     	<table>
1019
			     	  <tr>
1020
			     	  	<td>'.$Language->getText('tracker_include_type','proj_id').'</td>
1021
			     		<td><input name="group_id_template" value="'. $hp->purify($group_id_template, CODENDI_PURIFIER_CONVERT_HTML) .'"><a href="javascript:showGroupSelection()"><img src="'.util_get_image_theme("button_choose.png").'" align="absmiddle" border="0"></a></td>
1022
			     	  </tr>
1023
			     	  <tr>
1024
				        <td>'.$Language->getText('tracker_include_type','tracker_id').'</td>
1025
			     		<td><input name="atid_template" value="'. $hp->purify($atid_template, CODENDI_PURIFIER_CONVERT_HTML) .'"><a href="javascript:showTrackerSelection()"><img src="'.util_get_image_theme("button_choose.png").'" align="absmiddle" border="0"></a></td>
1026
					  <tr>
1027
					</table>
1028
				 </td>			     		
1029
		         <td><input type="button" name="CreateTemplate" value="'.$Language->getText('global','btn_create').'" onClick="onSubmitCreateTemplate()"></td>
1030
		      <tr>';
1031
1032
	    echo '</form>
1033
			  </table>';
1034
		
1035
	}
1036
1037
	/**
1038
	 *  Display the field usage list
1039
	 *
1040
	 *  @return void
1041
	 */
1042
	function displayFieldUsageList() {
1043
		global $ath,$art_field_fact,$art_fieldset_fact,$Language;
1044
		$hp = Codendi_HTMLPurifier::instance();
1045
		echo '<h3>'.$Language->getText('tracker_include_type','list_all_fields').'</h3>';
1046
		echo '<p>'.$Language->getText('tracker_include_report','mod');
1047
		
1048
		
1049
		// Show all the fields currently available in the system
1050
		$i=0;
1051
		$title_arr=array();
1052
		$title_arr[]=$Language->getText('tracker_include_report','field_label');
1053
		$title_arr[]=$Language->getText('tracker_include_type','type');
1054
		$title_arr[]=$Language->getText('tracker_include_artifact','desc');
1055
        $title_arr[]=$Language->getText('tracker_include_type','fieldset');
1056
		$title_arr[]=$Language->getText('tracker_include_type','rank_in_fieldset');
1057
		$title_arr[]=$Language->getText('global','status');
1058
		$title_arr[]=$Language->getText('tracker_include_canned','delete');
1059
		
1060
		echo html_build_list_table_top ($title_arr);
1061
		
1062
		// Build HTML ouput for  Used fields
1063
		$iu=0;
1064
		$fieldsets_with_used_fields = $art_fieldset_fact->getAllFieldSetsContainingUsedFields();
1065
        $fieldsets_with_unused_fields = $art_fieldset_fact->getAllFieldSetsContainingUnusedFields();
1066
        
1067
        $html = "";
1068
		$tracker_url = '?group_id='.(int)$this->Group->getID().'&atid='.(int)$this->getID();
1069
        
1070
        while (list($fieldset_id, $fieldset) = each($fieldsets_with_used_fields)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldset_id is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1071
            $used_fields_in_fieldset = $fieldset->getAllUsedFields();
1072
            // separation between fieldsets
1073
            $html .= '<tr class="fieldset_separator"><td colspan="7">'. $hp->purify(SimpleSanitizer::unsanitize($fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</td></tr>';
1074
            while (list($key, $field) = each($used_fields_in_fieldset) ) {
0 ignored issues
show
Unused Code introduced by
The assignment to $key is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1075
                $rank = ($field->getPlace()?$field->getPlace():"-");
1076
                $status = ($field->getUseIt()?$Language->getText('tracker_include_type','used'):$Language->getText('tracker_include_type','unused'));
1077
                
1078
                $html .= '<TR class="'.util_get_alt_row_color($iu) .'">';
1079
                $html .= '<TD><A HREF="'.$tracker_url.'&func=display_field_update&field_id='.(int)$field->getID().'">'.
1080
                $hp->purify(SimpleSanitizer::unsanitize($field->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</A></td>'.
1081
                "\n<td>". $hp->purify($field->getLabelFieldType(), CODENDI_PURIFIER_CONVERT_HTML) .'</td>'.
1082
                "\n<td>". $hp->purify(SimpleSanitizer::unsanitize($field->getDescription()), CODENDI_PURIFIER_BASIC, $this->getGroupId()) .'</td>'.
1083
                "\n<td><a href=\"".$tracker_url."&func=display_fieldset_update&fieldset_id=".(int)$fieldset->getID()."\">". $hp->purify(SimpleSanitizer::unsanitize($fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</td>'.
1084
                "\n<td align =\"center\">". $hp->purify($rank, CODENDI_PURIFIER_CONVERT_HTML) .'</td>'.
1085
                "\n<td align =\"center\">". $hp->purify($status, CODENDI_PURIFIER_CONVERT_HTML) .'</td>';
1086
                if ( $field->isStandardField() ) {
1087
                    // For standard, we can't delete them - Only unused them
1088
                    $html .= "\n<td align =\"center\">-</td>";
1089
                } else {
1090
                    $html .= "\n<td align =\"center\"><a href=\"/tracker/admin/?func=field_delete&group_id=".(int)$this->Group->getID()."&atid=".(int)$this->getID()."&field_id=".(int)$field->getID()."\"><img src=\"".util_get_image_theme("ic/trash.png")."\" border=\"0\" onClick=\"return confirm('".$Language->getText('tracker_include_type','warning_loose_data')."')\"></a></td>";
1091
                }
1092
            
1093
                $html .= "<TR>";
1094
                                        
1095
                $iu++;
1096
            }
1097
        }
1098
        // Now print the HTML table (for used fields)
1099
		if ($iu == 0) {
1100
		    echo '<tr><td colspan="7"><center><b>'.$Language->getText('tracker_include_type','no_field_in_use').'</b></center></tr>'.$html;  
1101
		} else {
1102
		    echo '<tr><td colspan="7"><center><b>'.$Language->getText('tracker_include_type','used_field').'</b></center></tr>'.$html;  
1103
		}
1104
        
1105
        $html = '';
1106
        
1107
        while (list($fieldset_id, $fieldset) = each($fieldsets_with_unused_fields)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldset_id is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1108
            $unused_fields_in_fieldset = $fieldset->getAllUnusedFields();
1109
            // separation between fieldsets
1110
            $html .= '<tr class="fieldset_separator"><td colspan="7">'. $hp->purify(SimpleSanitizer::unsanitize($fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</td></tr>';
1111
            while (list($key, $field) = each($unused_fields_in_fieldset) ) {
0 ignored issues
show
Unused Code introduced by
The assignment to $key is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1112
                $rank = ($field->getPlace()?$field->getPlace():"-");
1113
                $status = ($field->getUseIt()?$Language->getText('tracker_include_type','used'):$Language->getText('tracker_include_type','unused'));
1114
                
1115
                $html .= '<TR class="'.util_get_alt_row_color($iu) .'">';
1116
                $html .= '<TD><A HREF="'.$tracker_url.'&func=display_field_update&field_id='.(int)$field->getID().'">'.
1117
                $hp->purify(SimpleSanitizer::unsanitize($field->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</A></td>'.
1118
                "\n<td>". $hp->purify($field->getLabelFieldType(), CODENDI_PURIFIER_CONVERT_HTML) .'</td>'.
1119
                "\n<td>". $hp->purify(SimpleSanitizer::unsanitize($field->getDescription()), CODENDI_PURIFIER_BASIC, $this->getGroupId()) .'</td>'.
1120
                "\n<td><a href=\"".$tracker_url."&func=display_fieldset_update&fieldset_id=".(int)$fieldset->getID()."\">". $hp->purify(SimpleSanitizer::unsanitize($fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</td>'.
1121
                "\n<td align =\"center\">". $hp->purify($rank, CODENDI_PURIFIER_CONVERT_HTML) .'</td>'.
1122
                "\n<td align =\"center\">". $hp->purify($status, CODENDI_PURIFIER_CONVERT_HTML) .'</td>';
1123
                if ( $field->isStandardField() ) {
1124
                    // For standard, we can't delete them - Only unused them
1125
                    $html .= "\n<td align =\"center\">-</td>";
1126
                } else {
1127
                    $html .= "\n<td align =\"center\"><a href=\"/tracker/admin/?func=field_delete&group_id=".(int)$this->Group->getID()."&atid=".(int)$this->getID()."&field_id=".(int)$field->getID()."\"><img src=\"".util_get_image_theme("ic/trash.png")."\" border=\"0\" onClick=\"return confirm('".$Language->getText('tracker_include_type','warning_loose_data')."')\"></a></td>";
1128
                }
1129
            
1130
                $html .= "<TR>";
1131
                                        
1132
                $iu++;
1133
                
1134
            }
1135
        }
1136
        // Now print the HTML table (for unused fields)
1137
		if ($iu == 0) {
1138
		    echo '<tr><td colspan="7"><center><b>'.$Language->getText('tracker_include_type','no_unused_field').'</b></center></tr>'.$html;  
1139
		} else {
1140
		    echo '<tr><td colspan="7"><center><b>'.$Language->getText('tracker_include_type','unused_field').'</b></center></tr>'.$html;  
1141
		}
1142
1143
		echo '</TABLE>';
1144
		echo '<hr>';
1145
		
1146
	}
1147
	
1148
	/**
1149
	 *  Display the field type select box
1150
	 *
1151
	 *  @param data_type: the field data type (string, int, flat or date)
1152
	 *  @param display_type: the field display type (select box, text field, ...)
1153
	 *  @param form_name: the HTTP form name
1154
	 *
1155
	 *  @return void
1156
	 */
1157
	function displayFieldType($data_type,$display_type,$form_name) {
1158
	  global $Language;
1159
		
1160
		$af = new ArtifactField();
1161
		
1162
		echo '<script language="JavaScript">
1163
1164
			  function onChangeFieldType(form) {
1165
			  		switch ( form.field_type.value ) {
1166
			  		// Select Box
1167
			  		case "1":
1168
			  			form.data_type.value = '.(int)$af->DATATYPE_INT.';
1169
					  	form.display_type.value = "SB";
1170
					  	form.display_size.value = "N/A";
1171
					  	break;
1172
			  		// Multi Select Box
1173
			  		case "2":
1174
			  			form.data_type.value = '.(int)$af->DATATYPE_INT.';
1175
					  	form.display_type.value = "MB";
1176
					  	form.display_size.value = "N/A";
1177
					  	break;
1178
			  		// TextField
1179
			  		case "3":
1180
			  			form.data_type.value = '.(int)$af->DATATYPE_TEXT.';
1181
					  	form.display_type.value = "TF";
1182
					  	form.display_size.value = "N/A";
1183
					  	break;
1184
			  		// TextArea
1185
			  		case "4":
1186
			  			form.data_type.value = '.(int)$af->DATATYPE_TEXT.';
1187
					  	form.display_type.value = "TA";
1188
					  	form.display_size.value = "60/7";
1189
					  	break;
1190
			  		// DateField
1191
			  		case "5":
1192
			  			form.data_type.value = '.(int)$af->DATATYPE_DATE.';
1193
					  	form.display_type.value = "DF";
1194
					  	form.display_size.value = "N/A";
1195
					  	break;
1196
			  		// FloatField
1197
			  		case "6":
1198
			  			form.data_type.value = '.(int)$af->DATATYPE_FLOAT.';
1199
					  	form.display_type.value = "TF";
1200
					  	form.display_size.value = "N/A";
1201
					  	break;
1202
			  		// IntegerField
1203
			  		case "7":
1204
			  			form.data_type.value = '.(int)$af->DATATYPE_INT.';
1205
					  	form.display_type.value = "TF";
1206
					  	form.display_size.value = "N/A";
1207
					  	break;
1208
					default:
1209
						alert("Unknow field type!");
1210
						break;
1211
			  		}
1212
			  }
1213
1214
			  </script>
1215
			 ';
1216
1217
        echo '<select name="field_type" onChange="onChangeFieldType('.$form_name.')">';
1218
		if ( $data_type&&$display_type ) {
1219
			$selected = "";
1220
			if ( ($data_type == $af->DATATYPE_INT || $data_type == $af->DATATYPE_USER)
1221
				 &&($display_type == "SB") ) 
1222
				$selected = " selected";
1223
			echo '<option value="1"'.$selected.'>'.$Language->getText('tracker_include_type','sb').'</option>';
1224
			
1225
			$selected = "";
1226
			if ( ($data_type == $af->DATATYPE_INT || $data_type == $af->DATATYPE_USER)
1227
				 &&($display_type == "MB") ) 
1228
				$selected = " selected";
1229
			echo '<option value="2"'.$selected.'>'.$Language->getText('tracker_include_type','mb').'</option>';
1230
			
1231
			$selected = "";
1232
			if ( ($data_type == $af->DATATYPE_TEXT)
1233
				 &&($display_type == "TF") ) 
1234
				$selected = " selected";
1235
			echo '<option value="3"'.$selected.'>'.$Language->getText('tracker_include_type','tf').'</option>';
1236
			
1237
			$selected = "";
1238
			if ( ($data_type == $af->DATATYPE_TEXT)
1239
				 &&($display_type == "TA") ) 
1240
				$selected = " selected";
1241
			echo '<option value="4"'.$selected.'>'.$Language->getText('tracker_include_type','ta').'</option>';
1242
1243
			$selected = "";
1244
			if ( ($data_type == $af->DATATYPE_DATE)
1245
				 &&($display_type == "DF") ) 
1246
				$selected = " selected";
1247
			echo '<option value="5"'.$selected.'>'.$Language->getText('tracker_include_type','df').'</option>';
1248
1249
			$selected = "";
1250
			if ( ($data_type == $af->DATATYPE_FLOAT)
1251
				 &&($display_type == "TF") ) {
1252
				$selected = " selected";
1253
			}
1254
			echo '<option value="6"'.$selected.'>'.$Language->getText('tracker_include_type','ff').'</option>';
1255
1256
			$selected = "";
1257
			if ( ($data_type == $af->DATATYPE_INT)
1258
				 &&($display_type == "TF") ) 
1259
				$selected = " selected";
1260
			echo '<option value="7"'.$selected.'>'.$Language->getText('tracker_include_type','if').'</option>';
1261
1262
		} else {
1263
			echo '
1264
			<option value="1">'.$Language->getText('tracker_include_type','sb').'</option>
1265
			<option value="2">'.$Language->getText('tracker_include_type','mb').'</option>
1266
			<option value="3">'.$Language->getText('tracker_include_type','tf').'</option>
1267
			<option value="4">'.$Language->getText('tracker_include_type','ta').'</option>
1268
			<option value="5">'.$Language->getText('tracker_include_type','df').'</option>
1269
			<option value="6">'.$Language->getText('tracker_include_type','ff').'</option>
1270
			<option value="7">'.$Language->getText('tracker_include_type','if').'</option>';
1271
		}
1272
        echo '</select>';
1273
	}
1274
1275
	/**
1276
	 *  Display the field usage add or update form
1277
	 *
1278
	 *  @param func: field_create or field_update
1279
	 *  @param field_id: the field id
1280
	 *  @param field_name: the field name
1281
	 *  @param description: the field description
1282
	 *  @param label: the field label
1283
	 *  @param data_type: the field data type (string, int, flat or date)
1284
	 *  @param default_value: the default value
1285
	 *  @param display_type: the field display type (select box, text field, ...)
1286
	 *  @param display_size: the field display size
1287
	 *  @param rank_on_screen: rank on screen
1288
	 *  @param empty_ok: allow empty fill
1289
	 *  @param keep_history: keep in the history
1290
	 *  @param special: is the field has special process
1291
	 *  @param use_it: this field is used or not
1292
	 *  @param show_use: boolean - display the checkbox for using or not this field
1293
     *  @param fieldset_id: int - the field set id that the field belong to
1294
	 *
1295
	 *  @return void
1296
	 */
1297
	function displayFieldUsageForm($func="field_create",$field_id=false,$field_name=false,$description=false,$label=false,$data_type=false,$default_value=false,$display_type=false,
1298
								   $display_size=false,$rank_on_screen=false,
1299
								   $empty_ok=false,$keep_history=false,$special=false,$use_it=false,$show_use=false, $fieldset_id=false) {
1300
		global $art_field_fact,$Language;
1301
		$hp = Codendi_HTMLPurifier::instance();
1302
		$field = $art_field_fact->getFieldFromId($field_id);
1303
1304
		$af = new ArtifactField();
1305
1306
		if ( $func == "field_create" ) {
1307
			echo '<h3>'.$Language->getText('tracker_include_type','create_field').'</h3>';
1308
			echo '
1309
			  <form name="form_create" method="/tracker/admin/index.php">
1310
			  <input type="hidden" name="func" value="'. $hp->purify($func, CODENDI_PURIFIER_CONVERT_HTML) .'">
1311
			  <input type="hidden" name="group_id" value="'.(int)$this->Group->getID().'">
1312
			  <input type="hidden" name="atid" value="'.(int)$this->getID().'">
1313
			  <input type="hidden" name="field_id" value="">
1314
			  <input type="hidden" name="field_name" value="">
1315
			  <input type="hidden" name="data_type" value="'.(int)$af->DATATYPE_INT.'">
1316
			  <input type="hidden" name="display_type" value="SB">';
1317
		} else {
1318
			echo "<h3>".$Language->getText('tracker_include_type','upd_label', $hp->purify(SimpleSanitizer::unsanitize($label), CODENDI_PURIFIER_CONVERT_HTML) )."</h3>";
1319
			echo '
1320
			  <form name="form_create" method="/tracker/admin/index.php">
1321
			  <input type="hidden" name="func" value="'. $hp->purify($func, CODENDI_PURIFIER_CONVERT_HTML) .'">
1322
			  <input type="hidden" name="group_id" value="'.(int)$this->Group->getID().'">
1323
			  <input type="hidden" name="atid" value="'.(int)$this->getID().'">
1324
			  <input type="hidden" name="field_id" value="'.(int)$field_id.'">
1325
			  <input type="hidden" name="field_name" value="'. $hp->purify(SimpleSanitizer::unsanitize($field_name), CODENDI_PURIFIER_CONVERT_HTML) .'">
1326
			  <input type="hidden" name="data_type" value="'. $hp->purify($data_type, CODENDI_PURIFIER_CONVERT_HTML) .'">
1327
			  <input type="hidden" name="display_type" value="'. $hp->purify($display_type, CODENDI_PURIFIER_CONVERT_HTML) .'">';
1328
		}
1329
		
1330
		if ( $field && $field->isStandardField() ) {
1331
			echo '<p><i>'.$Language->getText('tracker_include_type','imp_note', $hp->purify(SimpleSanitizer::unsanitize($field->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) ).'</i></p>';
1332
		}
1333
	
1334
		echo '
1335
		  <b>'.$Language->getText('tracker_include_type','field_ident').'</b> ';
1336
		echo  help_button('tracker-v3.html#field-usage-management');
1337
		echo '
1338
                              <p>'.$Language->getText('tracker_include_report','field_label').': <font color="red">*</font> ';
1339
		      
1340
		if ( $label ) {
1341
			echo '<input type="text" name="label" size="30" maxlength="40" value="'. $hp->purify(SimpleSanitizer::unsanitize($label), CODENDI_PURIFIER_CONVERT_HTML) .'">';
1342
		} else {
1343
			echo '<input type="text" name="label" size="30" maxlength="40">';
1344
		}
1345
		
1346
		echo '<p>'.$Language->getText('tracker_include_artifact','desc').': ';
1347
		            
1348
		echo '<input type=text name="description" size="70" maxlength="255" value="'. $hp->purify(SimpleSanitizer::unsanitize($description), CODENDI_PURIFIER_CONVERT_HTML) .'">';
1349
1350
		
1351
		echo '
1352
		  <p>'.$Language->getText('tracker_include_type','field_type').': <font color="red">*</font>&nbsp;';
1353
		
1354
1355
		//be more conservative for semi-standard fields like assigned_to ...
1356
		if ( $field && 
1357
		     !user_is_super_user() &&
1358
		     ($field->isStandardField() ||
1359
		      $field->getName() == "assigned_to" ||
1360
		      $field->getName() == "multi_assigned_to")) {
1361
			echo $field->getLabelFieldType();
1362
		} else {
1363
			$this->displayFieldType($data_type,$display_type,"form_create");
1364
		}
1365
		
1366
		echo '			
1367
		  <p><b>'.$Language->getText('tracker_include_type','display_info').' </b>';
1368
		echo  help_button('tracker-v3.html#field-usage-management');
1369
		echo'
1370
                                <table width="100%" border="0" cellpadding="5" cellspacing="0">
1371
		    <tr> 
1372
		      <td colspan="2">'.$Language->getText('tracker_include_type','display_size').':&nbsp;';
1373
		      
1374
		if ( $display_size ) {
1375
		  echo '<input type="text" name="display_size" size="7" maxlength="7" value="'. $hp->purify($display_size, CODENDI_PURIFIER_CONVERT_HTML) .'">';
1376
		} else {
1377
		  echo '<input type="text" name="display_size" size="7" maxlength="7" value="N/A">';
1378
		}
1379
			    
1380
	    echo '
1381
		      </td>
1382
            </tr>
1383
            <tr>
1384
              <td width="30%" >'.$Language->getText('tracker_include_type','fieldset').':&nbsp';
1385
              $this->displayFieldSetDropDownList($this->getID(), $fieldset_id);
1386
        echo '</td>
1387
		      <td>'.$Language->getText('tracker_include_type','rank_screen').':&nbsp;';
1388
		      
1389
		if ( $rank_on_screen ) {
1390
	        echo '<input type="text" name="rank_on_screen" size="5" maxlength="5" value="'. $hp->purify($rank_on_screen, CODENDI_PURIFIER_CONVERT_HTML) .'">';
1391
	    } else {
1392
	        echo '<input type="text" name="rank_on_screen" size="5" maxlength="5">';
1393
	    }
1394
	    
1395
	    echo '
1396
		      </td>
1397
		    </tr>
1398
		  </table>
1399
		  <b>'.$Language->getText('tracker_include_type','misc').'</b>
1400
		  <table width="100%" border="0" cellpadding="5" cellspacing="0">
1401
		    <tr> 
1402
		      <td width="30%">'.$Language->getText('tracker_include_type','allow_empty').': ';
1403
		
1404
	    if ( $field && $field->isStandardField() && !user_is_super_user()) {
1405
			if ( $empty_ok ) {
1406
				echo $Language->getText('global','yes');
1407
			    echo '<input type="hidden" name="empty_ok" value="1">';
1408
			} else {
1409
				echo $Language->getText('global','no');
1410
			    echo '<input type="hidden" name="empty_ok" value="0">';
1411
			}
1412
		} else {
1413
			if ( $empty_ok ) {
1414
				echo '<input type="checkbox" name="empty_ok" value="1" checked>';
1415
			} else {
1416
				echo '<input type="checkbox" name="empty_ok" value="1">';
1417
			}
1418
		}
1419
				
1420
		echo '
1421
		        </td><td>'.$Language->getText('tracker_include_type','keep_change_history').': ';
1422
		
1423
		if ( !$this->userIsAdmin()) {
1424
			if ( $keep_history ) {
1425
				echo $Language->getText('global','yes');
1426
			    echo '<input type="hidden" name="keep_history" value="1">';
1427
			} else {
1428
				echo $Language->getText('global','no');
1429
			    echo '<input type="hidden" name="keep_history" value="0">';
1430
			}
1431
		} else {
1432
			if ( $keep_history ) {
1433
				echo '<input type="checkbox" name="keep_history" value="1" checked>';
1434
			} else {
1435
				echo '<input type="checkbox" name="keep_history" value="1">';
1436
			}
1437
		}
1438
				
1439
		echo '
1440
		      </td></tr>';
1441
		      
1442
		if ( $show_use ) {
1443
		    echo  '
1444
		      <tr><td>';
1445
			echo $Language->getText('tracker_include_type','use_field').': ';
1446
			if ( $use_it == 1 ) {
1447
			  //be more conservative for semi-special fields like assigned_to ...
1448
			  if ( $field && $field->isSpecial() && ($field->getName() != "comment_type_id") && !user_is_super_user()) {
1449
			    echo $Language->getText('global','yes').'<input type="hidden" name="use_it" value="1">';
1450
			  } else {
1451
			    echo '<input type="checkbox" name="use_it" value="1" checked>';
1452
			  }
1453
			} else {
1454
			  if ( $field && $field->isSpecial() && ($field->getName() != "comment_type_id") && !user_is_super_user()) {
1455
			    echo $Language->getText('global','no').'<input type="hidden" name="use_it" value="0">';
1456
			  } else {
1457
			    echo '<input type="checkbox" name="use_it" value="1">';
1458
			  }
1459
			}
1460
                        echo '
1461
                      </td><td><a href="/tracker/admin/?group_id='.(int)$this->Group->getID().'&atid='.(int)$this->getID().'&func=permissions&perm_type=fields&selected_id='.(int)$field_id.'&group_first=0">'.$Language->getText('tracker_include_type','edit_field_perm').'</a>';
1462
1463
		    echo  '
1464
		      </td></tr>';
1465
		} else {
1466
			echo '<input type="hidden" name="use_it" value="1">';
1467
		}
1468
1469
		if ( $special ) {
1470
			echo '<input type="hidden" name="special" value="1">';
1471
		} else {
1472
			echo '<input type="hidden" name="special" value="0">';
1473
		}
1474
		
1475
		echo '
1476
		  </table><p>';
1477
		  
1478
		if ( $func == "field_create" ) {
1479
			echo '<input type="submit" name="Submit" value="'.$Language->getText('global','btn_create').'">';
1480
		} else {
1481
			echo '<input type="submit" name="Submit" value="'.$Language->getText('global','btn_update').'">';
1482
		}
1483
		
1484
		echo '    
1485
		  </p>
1486
		</form>
1487
		<p><font color="red">*</font>: '.$Language->getText('tracker_include_type','fields_requ').'</p>';
1488
		
1489
	}
1490
1491
	/**
1492
	 *  Display the field values list for editing the values
1493
	 *
1494
	 *  @return void
1495
	 */
1496
	function displayFieldValuesEditList() {
1497
        $hp = Codendi_HTMLPurifier::instance();
1498
		global $ath,$art_field_fact,$art_fieldset_fact,$Language;
1499
		
1500
		echo '<p>'.$Language->getText('tracker_include_report','mod');
1501
		
1502
		
1503
		// Show all the fields currently available in the system
1504
		$i=0;
1505
		$title_arr=array();
1506
		$title_arr[]=$Language->getText('tracker_include_report','field_label');
1507
		$title_arr[]=$Language->getText('tracker_include_artifact','desc');
1508
        $title_arr[]=$Language->getText('tracker_include_type','fieldset');
1509
		
1510
		echo html_build_list_table_top ($title_arr);
1511
		
1512
		// Build HTML ouput for  Used fields
1513
		$iu=0;
1514
		//$fields = $art_field_fact->getAllUsedFields();
1515
        $fieldsets = $art_fieldset_fact->getAllFieldSetsContainingUsedFields();
1516
		$html = "";
1517
		while (list($fieldset_id, $fieldset) = each($fieldsets)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldset_id is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1518
            
1519
            $html .= '<tr class="fieldset_separator"><td colspan="3">'. $hp->purify(SimpleSanitizer::unsanitize($fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</td></tr>';
1520
            
1521
            $fields = $fieldset->getAllUsedFields();
1522
            while (list($field_name,$field) = each($fields)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $field_name is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1523
            
1524
              // Special case for special fields (excluded comment_type_id)
1525
              if ( (($field->getName() != "comment_type_id")&&($field->isSpecial())) ||
1526
                   (($field->getName() == "status_id") && !user_is_super_user()) ) {
1527
                continue;
1528
              }
1529
                
1530
                $html .= '<TR class="'. 
1531
                    util_get_alt_row_color($iu) .'">';
1532
            
1533
                $html .= '<TD><A HREF="?group_id='.(int)$this->Group->getID()."&atid=".(int)$this->getID().
1534
                '&func=display_field_values&field_id='.(int)$field->getID().'">'.
1535
                $hp->purify(SimpleSanitizer::unsanitize($field->getLabel()), CODENDI_PURIFIER_CONVERT_HTML).'</A></td>'.
1536
                "\n<td>". $hp->purify(SimpleSanitizer::unsanitize($field->getDescription()), CODENDI_PURIFIER_BASIC, $this->getGroupId()) .'</td>';
1537
                
1538
                $html .= '<td>'. $hp->purify(SimpleSanitizer::unsanitize($fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</td>';
1539
            
1540
                $html .= "<TR>";
1541
    
1542
                $iu++;
1543
            }
1544
		}
1545
		// Now print the HTML table
1546
		if ($iu == 0) {
1547
		    echo '<tr><td colspan="4"><center><b>'.$Language->getText('tracker_include_type','no_used_field').'</b></center></tr>';
1548
		} else {
1549
			echo $html;
1550
		}
1551
1552
		echo '</TABLE>';
1553
		echo '<hr>';
1554
		
1555
	}
1556
1557
	/**
1558
	 *  Display the value function form
1559
	 *
1560
	 *  @param field_id: the field id to edit
1561
	 *  @param value_function: the value function to bind to
1562
	 *  @param or_label: display an additionnal label to display "Or ..."
1563
	 *
1564
	 *  @return void
1565
	 */
1566
	function displayValueFunctionForm($field_id,$value_function,$or_label="") {
1567
        $hp = Codendi_HTMLPurifier::instance();
1568
	  global $Language;
1569
	    if ( $or_label ) {
1570
	    	echo '<h3>'. $hp->purify($or_label, CODENDI_PURIFIER_CONVERT_HTML) .' '.$Language->getText('tracker_include_type','bind_to_list').' ';
1571
	    } else {
1572
	    	echo '<h3>'.$Language->getText('tracker_include_type','bind_to_list').' ';
1573
	    }
1574
	    echo  help_button('tracker-v3.html#binding-a-field-to-a-list-of-values').'</h3>';
1575
	
1576
1577
	    echo '
1578
	      <FORM ACTION="" METHOD="POST">
1579
	      <INPUT TYPE="HIDDEN" NAME="func" VALUE="update_binding">
1580
	      <INPUT TYPE="HIDDEN" NAME="field_id" VALUE="'.(int)$field_id.'">
1581
	      <INPUT TYPE="HIDDEN" NAME="group_id" VALUE="'.(int)$this->Group->getID().'">
1582
	      <INPUT TYPE="HIDDEN" NAME="atid" VALUE="'.(int)$this->getID().'">
1583
	      '.$Language->getText('tracker_include_type','bind_to').': &nbsp; 
1584
	      <select multiple name="value_function[]">
1585
	          <option value="">'.$Language->getText('global','none').'</option>';
1586
1587
	
1588
	    $selected = "";
1589
	    if ( $value_function && in_array("artifact_submitters",$value_function)) {
1590
	      $selected = " selected";
1591
	    }
1592
	    echo '<option value="artifact_submitters"'.$selected.'>'.$Language->getText('tracker_include_type','submitters').'</option>';
1593
	    
1594
	    $selected = "";
1595
	    $ugroup_res = ugroup_db_get_ugroup($GLOBALS['UGROUP_PROJECT_MEMBERS']);
1596
	    $name = util_translate_name_ugroup(db_result($ugroup_res, 0, 'name'));
1597
	    if ( $value_function && in_array("group_members",$value_function)) {
1598
	      $selected = " selected";
1599
	    }
1600
	    echo '<option value="group_members"'.$selected.'>'. $hp->purify($name, CODENDI_PURIFIER_CONVERT_HTML) .'</option>';
1601
	    
1602
	    $selected = "";
1603
	    $ugroup_res = ugroup_db_get_ugroup($GLOBALS['UGROUP_PROJECT_ADMIN']);
1604
	    $name = util_translate_name_ugroup(db_result($ugroup_res, 0, 'name'));
1605
	    if ( $value_function && in_array("group_admins",$value_function)) {
1606
	      $selected = " selected";
1607
	    }
1608
	    echo '<option value="group_admins"'.$selected.'>'. $hp->purify($name, CODENDI_PURIFIER_CONVERT_HTML) .'</option>';
1609
	    
1610
	    $selected = "";
1611
	    $ugroup_res = ugroup_db_get_ugroup($GLOBALS['UGROUP_TRACKER_ADMIN']);
1612
	    $name = util_translate_name_ugroup(db_result($ugroup_res, 0, 'name'));
1613
	    if ( $value_function && in_array("tracker_admins",$value_function)) {
1614
	      $selected = " selected";
1615
	    }
1616
	    echo '<option value="tracker_admins"'.$selected.'>'. $hp->purify($name, CODENDI_PURIFIER_CONVERT_HTML) .'</option>';
1617
	    
1618
	    
1619
	    $ugroup_res = ugroup_db_get_existing_ugroups(100);
0 ignored issues
show
Deprecated Code introduced by
The function ugroup_db_get_existing_ugroups() has been deprecated with message: Use UGroupManager::getExistingUgroups() instead

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
1620
	    $rows = db_numrows($ugroup_res);
1621
	    for($i=0;$i<$rows;$i++) {
1622
	      $ug = db_result($ugroup_res, $i,'ugroup_id');
1623
	      $selected = "";
1624
	      if (($ug == $GLOBALS['UGROUP_NONE']) || 
1625
		  ($ug == $GLOBALS['UGROUP_ANONYMOUS']) || 
1626
		  ($ug == $GLOBALS['UGROUP_PROJECT_MEMBERS']) || 
1627
		  ($ug == $GLOBALS['UGROUP_PROJECT_ADMIN']) || 
1628
		  ($ug == $GLOBALS['UGROUP_TRACKER_ADMIN'])) { continue; }
1629
	      
1630
	      $ugr="ugroup_".$ug;
1631
	      if ( $value_function && in_array($ugr,$value_function)) {
1632
		$selected = " selected";
1633
	      }
1634
	      echo '<option value="'.$ugr.'"'.$selected.'>'. $hp->purify(util_translate_name_ugroup(db_result($ugroup_res, $i, 'name')), CODENDI_PURIFIER_CONVERT_HTML) .'</option>';	      
1635
	    }
1636
	    
1637
	    if ($this->Group->getID() != 100) {
1638
	      $ugroup_res = ugroup_db_get_existing_ugroups($this->Group->getID());
0 ignored issues
show
Deprecated Code introduced by
The function ugroup_db_get_existing_ugroups() has been deprecated with message: Use UGroupManager::getExistingUgroups() instead

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
1639
	      $rows = db_numrows($ugroup_res);
1640
	      for($i=0;$i<$rows;$i++) {
1641
		$selected = "";
1642
		$ug = db_result($ugroup_res, $i,'ugroup_id');
1643
		$ugr="ugroup_".$ug;
1644
	        if ( $value_function && in_array($ugr,$value_function)) {
1645
		    $selected = " selected";
1646
	        }
1647
		echo '<option value="'.$ugr.'"'.$selected.'>'. $hp->purify(util_translate_name_ugroup(db_result($ugroup_res, $i, 'name')), CODENDI_PURIFIER_CONVERT_HTML) .'</option>';
1648
	      }
1649
	    }
1650
	    echo '
1651
		        </select>
1652
	      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="'.$Language->getText('tracker_include_type','bind').'">
1653
	      </FORM>';
1654
	    
1655
	}
1656
	
1657
	/**
1658
	 *  Display the field value form
1659
	 *
1660
	 *  @param $func: value_create or value_update
1661
	 *  @param field_id: the field id to edit
1662
	 *  @param value_id: the value id
1663
	 *  @param value: the value 
1664
	 *  @param order_id: rank
1665
	 *  @param status: the field value status (Visible or Hidden)
1666
	 *  @param description: the field value description
1667
	 *
1668
	 *  @return void
1669
	 */
1670
	function displayFieldValueForm($func,$field_id,$value_id=false,$value=false,$order_id=false,$status=false,$description=false) {
1671
		global $Language;
1672
		$hp = Codendi_HTMLPurifier::instance();
1673
        
1674
		if ( $func == "value_create" ) {
1675
			echo '<h3>'.$Language->getText('tracker_include_type','create_value').' '.help_button('tracker-v3.html#creating-a-tracker-field-value').'</h3>';
1676
		} else {
1677
			echo '<h3>'.$Language->getText('tracker_include_type','update_value').' '.help_button('tracker-v3.html#creating-a-tracker-field-value').'</h3>';
1678
		}
1679
					
1680
		echo '
1681
	      <FORM ACTION="" METHOD="POST">
1682
	      <INPUT TYPE="HIDDEN" NAME="func" VALUE="'. $hp->purify($func, CODENDI_PURIFIER_CONVERT_HTML) .'">
1683
	      <INPUT TYPE="HIDDEN" NAME="field_id" VALUE="'.(int)$field_id.'">
1684
	      <INPUT TYPE="HIDDEN" NAME="group_id" VALUE="'.(int)$this->Group->getID().'">
1685
	      <INPUT TYPE="HIDDEN" NAME="atid" VALUE="'.(int)$this->getID().'">';
1686
1687
		if ( $status == "P" ) {
1688
			echo '<p><i>'.$Language->getText('tracker_include_type','note_standard').'</i></p>';
1689
		}
1690
1691
		if ( $func == "value_create" ) {
1692
		    if ( $value_id ) {
1693
		      	echo '<INPUT TYPE="hidden" NAME="value_id" VALUE="'.(int)$value_id.'">';
1694
		    } else {
1695
		      	echo '<INPUT TYPE="hidden" NAME="value_id" VALUE="">';
1696
		    }
1697
		} else {
1698
	      	echo '<INPUT TYPE="hidden" NAME="value_id" VALUE="'.(int)$value_id.'">';
1699
		}
1700
1701
	    echo '  
1702
		  <table width="100%" border="0" cellpadding="5" cellspacing="0">
1703
		    <tr> 
1704
		      <td width="45%">Value: <font color="red">*</font>&nbsp;';
1705
1706
	    if ( $value ) {
1707
	      	echo '<INPUT TYPE="TEXT" NAME="value" VALUE="'. $hp->purify(SimpleSanitizer::unsanitize($value), CODENDI_PURIFIER_CONVERT_HTML) .'" SIZE="30" MAXLENGTH="60">';
1708
	    } else {
1709
	      	echo '<INPUT TYPE="TEXT" NAME="value" VALUE="" SIZE="30" MAXLENGTH="60">';
1710
	    }
1711
	    
1712
	    echo '
1713
	    	  </td>
1714
		      <td width="25%">Rank:&nbsp;';
1715
	      
1716
	    if ( $order_id ) {
1717
	    	echo '<INPUT TYPE="TEXT" NAME="order_id" VALUE="'. $hp->purify($order_id, CODENDI_PURIFIER_CONVERT_HTML) .'" SIZE="6" MAXLENGTH="6">';
1718
		} else {
1719
	    	echo '<INPUT TYPE="TEXT" NAME="order_id" VALUE="" SIZE="6" MAXLENGTH="6">';
1720
		}
1721
	    
1722
	    echo '</td>
1723
		      <td width="30%">';
1724
	       
1725
		if ( $func == "value_update" ) {
1726
			if (( $status == "P" ) && ( $this->Group->getID() != 100 ) ) {
1727
                            // Can't change 'Permanent' status unless you're working on the tracker templates (group 100)
1728
                            echo $Language->getText('global','status').': '.$Language->getText('tracker_include_type','permanent');
1729
                            echo '<input type="hidden" name="status" value="P">';
1730
			} else {
1731
				echo $Language->getText('global','status').':&nbsp;
1732
				<select name="status">';
1733
				if ( $status ) {
1734
					$selected = "";
1735
					if ( $status == "A" ) 
1736
						$selected = " selected";
1737
					echo '<option value="A"'.$selected.'>'.$Language->getText('tracker_include_type','active').'</option>';
1738
		
1739
					$selected = "";
1740
					if ( $status == $this->FIELD_VALUE_STATUS_HIDDEN ) 
1741
						$selected = " selected";
1742
					echo '<option value="'.$this->FIELD_VALUE_STATUS_HIDDEN.'"'.$selected.'>'.$Language->getText('tracker_include_type','hidden').'</option>';
1743
1744
                                        if ($this->Group->getID() == 100 ) {
1745
                                            $selected = "";
1746
                                            if ( $status == $this->FIELD_VALUE_STATUS_PERMANENT  ) 
1747
						$selected = " selected";
1748
                                            echo '<option value="'.$this->FIELD_VALUE_STATUS_PERMANENT.'"'.$selected.'>'.$Language->getText('tracker_include_type','permanent').'</option>';
1749
                                        }
1750
		
1751
				} else {
1752
					echo '				
1753
				          <option value="A" selected>'.$Language->getText('tracker_include_type','active').'</option>
1754
				          <option value="H">'.$Language->getText('tracker_include_type','hidden').'</option>;';
1755
                                        if ($this->Group->getID() == 100 ) {
1756
                                            echo '				
1757
				          <option value="P">'.$Language->getText('tracker_include_type','permanent').'</option>';
1758
                                        }
1759
				}
1760
				echo '
1761
				</select> ';
1762
			}
1763
		} else {
1764
			echo '&nbsp;</td>';
1765
		}
1766
	
1767
		     
1768
		echo '
1769
		  </tr>
1770
		  <tr>
1771
		     <td colspan="4">'.$Language->getText('tracker_include_artifact','desc').':<BR>';
1772
	     
1773
	    if ( $description ) {
1774
	    	echo '<textarea name="description" rows="2" cols="65">'. $hp->purify(SimpleSanitizer::unsanitize($description), CODENDI_PURIFIER_CONVERT_HTML) .'</textarea>';
1775
	   	} else {
1776
	    	echo '<textarea name="description" rows="2" cols="65"></textarea>';
1777
		}
1778
	
1779
		echo '</td>
1780
			</tr>
1781
			</table>
1782
			<p>';
1783
	      
1784
		if ( $func == "value_create" ) {
1785
			echo '<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="'.$Language->getText('global','btn_create').'">';
1786
		} else {
1787
			echo '<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="'.$Language->getText('global','btn_update').'">';
1788
		}
1789
1790
		echo '    
1791
		  </p>
1792
		</form>
1793
		<p><font color="red">*</font>: '.$Language->getText('tracker_include_type','fields_requ').'</p>';
1794
	}
1795
	
1796
	/**
1797
	 *  Display the field values list for a field
1798
	 *
1799
	 *  @param field_id: the field id
1800
	 *
1801
	 *  @return void
1802
	 */
1803
	function displayFieldValuesList($field_id) {
1804
		global $ath,$art_field_fact,$Language;
1805
		$hp = Codendi_HTMLPurifier::instance();
1806
		
1807
		$field = $art_field_fact->getFieldFromId($field_id);
1808
		if ( !$field ) {
1809
			return;
1810
		}
1811
1812
		$values = $field->getFieldValues ($this->getID(), array('A','P'));
1813
		$rows = db_numrows($values);
1814
		
1815
		if (!$values || ($rows == 0)) {
1816
		    echo "\n<H3>".$Language->getText('tracker_include_type','no_values')."</H3>";
1817
		    return;
1818
		} else {
1819
		    echo '<h3>'.$Language->getText('tracker_include_type','exist_values').'</h3>';
1820
		    echo '<p>'.$Language->getText('tracker_include_report','mod');
1821
		}
1822
1823
		
1824
		// Show all the fields currently available in the system
1825
		$i=0;
1826
		$title_arr=array();
1827
		if ( $field->getName() == "severity" ) {
1828
			$title_arr[]=$Language->getText('tracker_include_report','id');
1829
		}
1830
		$title_arr[]=$Language->getText('tracker_include_type','value_label');
1831
		$title_arr[]=$Language->getText('tracker_include_artifact','desc');
1832
		$title_arr[]=$Language->getText('tracker_include_type','rank');
1833
		$title_arr[]=$Language->getText('global','status');
1834
		$title_arr[]=$Language->getText('tracker_include_canned','delete');
1835
		
1836
		echo html_build_list_table_top ($title_arr);
1837
		
1838
		// Build HTML ouput for  Used fields
1839
		$iu=0;
1840
		$html = "";
1841
1842
		while ($row = db_fetch_array($values)) {
1843
		
1844
		    $rank = $row['order_id']?$row['order_id']:"-";
1845
		    $status = $this->getLabelValueStatus($row['status']);
1846
		
1847
			$html .= '<TR class="'. 
1848
			    util_get_alt_row_color($iu) .'">';
1849
		
1850
			if ( $field->getName() == "severity" ) {
1851
				$html .= '<TD align="center">'. $hp->purify($row['value_id'], CODENDI_PURIFIER_CONVERT_HTML) .'</TD>';
1852
			}
1853
                        $html .= '<TD>';
1854
                        if ( $row['value_id'] != 100 ) { # Can't edit 'None'
1855
                            $html.='<A HREF="?group_id='.(int)$this->Group->getID()."&atid=".(int)$this->getID().
1856
                            '&func=display_field_value&field_id='.(int)$field->getID().'&value_id='.(int)$row['value_id'].'">';
1857
                        }
1858
			$html .= $hp->purify(SimpleSanitizer::unsanitize($row['value']), CODENDI_PURIFIER_CONVERT_HTML);
1859
                        if ( $row['value_id'] != 100 ) { # Can't edit 'None'
1860
                            $html .= '</A>';
1861
                        }
1862
			$html .= "</td>\n<td>". $hp->purify(SimpleSanitizer::unsanitize($row['description']), CODENDI_PURIFIER_BASIC, $this->getGroupId()) .'</td>'.
1863
			"\n<td align =\"center\">". $hp->purify($rank, CODENDI_PURIFIER_CONVERT_HTML) .'</td>'.
1864
			"\n<td align =\"center\">". $hp->purify($status, CODENDI_PURIFIER_CONVERT_HTML) .'</td>';
1865
			
1866
			if (( $row['status'] == "P" || $field->getName() == "severity" )
1867
                            &&(!user_is_super_user())){
1868
				// Unable to delete Permanent values, except for values in the tracker templates (for Codendi admins)
1869
		    	$html .= "\n<td align =\"center\">-</td>";
1870
			} else {
1871
		    	$html .= "\n<td align =\"center\"><a href=\"/tracker/admin/?func=value_delete&group_id=".(int)$this->Group->getID()."&atid=".(int)$this->getID()."&field_id=".(int)$field->getID()."&value_id=".(int)$row['value_id']."\"><img src=\"".util_get_image_theme("ic/trash.png")."\" border=\"0\" onClick=\"return confirm('".$Language->getText('tracker_include_type','del_value')."')\"></a></td>";
1872
		    }
1873
		
1874
			$html .= "<TR>";
1875
					    			
1876
			$iu++;
1877
		}
1878
		
1879
		// Now print the HTML table
1880
		if ($iu == 0) {
1881
		    echo '<tr><td colspan="4"><center><b>'.$Language->getText('tracker_include_type','no_active_val').'</b></center></tr>'.$html;  
1882
		} else {
1883
		    echo '<tr><td colspan="4"><center><b>'.$Language->getText('tracker_include_type','active_val').'</b></center></tr>'.$html;  
1884
		}
1885
1886
		// Build HTML ouput for Unused fields
1887
		$iu=0;
1888
		$values = $field->getFieldValues ($this->getID(), array('H'));
1889
		$html = "";
1890
		
1891
		while ($row = db_fetch_array($values)) {
1892
		
1893
		    $rank = $row['order_id']?$row['order_id']:"-";
1894
		    $status = $this->getLabelValueStatus($row['status']);
1895
		
1896
			$html .= '<TR class="'. 
1897
			    util_get_alt_row_color($iu) .'">';
1898
		
1899
			if ( $field->getName() == "severity" ) {
1900
				$html .= '<TD align="center">'.(int)$row['value_id'].'</TD>';
1901
			}
1902
1903
		    $html .= '<TD><A HREF="?group_id='.(int)$this->Group->getID()."&atid=".(int)$this->getID().
1904
			'&func=display_field_value&field_id='.(int)$field->getID().'&value_id='.(int)$row['value_id'].'">'.
1905
			$row['value'].'</A></td>'.
1906
			"\n<td>". $hp->purify($row['description'], CODENDI_PURIFIER_BASIC, $this->getGroupId()) .'</td>'.
1907
			"\n<td align =\"center\">". $hp->purify($rank, CODENDI_PURIFIER_CONVERT_HTML) .'</td>'.
1908
			"\n<td align =\"center\">". $hp->purify($status, CODENDI_PURIFIER_CONVERT_HTML) .'</td>';
1909
1910
			if ( $row['status'] == "P" || $field->getName() == "severity" ) {
1911
				// Unable to delete Permanent values
1912
		    	$html .= "\n<td align =\"center\">-</td>";
1913
			} else {
1914
		    	$html .= "\n<td align =\"center\"><a href=\"/tracker/admin/?func=value_delete&group_id=".(int)$this->Group->getID()."&atid=".(int)$this->getID()."&field_id=".(int)$field->getID()."&value_id=".(int)$row['value_id']."\"><img src=\"".util_get_image_theme("ic/trash.png")."\" border=\"0\" onClick=\"return confirm('".$Language->getText('tracker_include_type','del_value')."')\"></a>";
1915
		    }
1916
		
1917
			$html .= "<TR>";
1918
					    			
1919
			$iu++;
1920
		}
1921
		
1922
		// Now print the HTML table
1923
		if ($iu == 0) {
1924
		    echo '<tr><td colspan="4"><center><b>'.$Language->getText('tracker_include_type','no_hidden_val').'</b></center></tr>'.$html;
1925
		} else {
1926
		    echo '<tr><td colspan="4"><center><b>'.$Language->getText('tracker_include_type','hidden_val').'</b></center></tr>'.$html;  
1927
		}
1928
1929
		echo '</TABLE>';
1930
		echo '<hr>';
1931
		
1932
	}
1933
1934
1935
	/* 
1936
	 *
1937
	 * displayNotificationForm
1938
	 *
1939
	 * return void
1940
	 *
1941
	 *
1942
	 * "
1943
	 */
1944
	
1945
	function displayNotificationForm($user_id) {
1946
	  global $Language;
1947
      $hp = Codendi_HTMLPurifier::instance();
1948
		// By default it's all 'yes'
1949
		for ($i=0; $i<$this->num_roles; $i++) {
1950
		    $role_label = $this->arr_roles[$i]['role_label'];
1951
		    for ($j=0; $j<$this->num_events; $j++) {
1952
				$event_label = $this->arr_events[$j]['event_label'];
1953
				$arr_notif[$role_label][$event_label] = 1;
1954
				//echo "[$role_label][$event_label] = 1<br>";
1955
		    }
1956
		}
1957
		
1958
		$res_notif = $this->getNotificationWithLabels($user_id);
1959
		while ($arr = db_fetch_array($res_notif)) {
1960
		    $arr_notif[$arr['role_label']][$arr['event_label']] = $arr['notify'];
1961
		}
1962
		
1963
		$group = $this->getGroup();
1964
		$group_artifact_id = $this->getID();
1965
		$group_id = $group->getGroupId();
1966
1967
		echo '<H2>'.$Language->getText('tracker_import_admin','tracker').' \'<a href="/tracker/admin/?group_id='.(int)$group_id.'&atid='.$group_artifact_id.'">'. $hp->purify(SimpleSanitizer::unsanitize($this->getName()), CODENDI_PURIFIER_CONVERT_HTML) .'</a>\' - '.$Language->getText('tracker_include_type','mail_notif').'</h2>';
1968
		// Build Wachees UI
1969
		$res = $this->getWatchees($user_id);
1970
		$arr_watchees = array();
1971
		while ($row_watchee = db_fetch_array($res)) {
1972
		    $arr_watchees[] = user_getname($row_watchee['watchee_id']);
1973
		}
1974
		$watchees = join(',',$arr_watchees);
1975
		
1976
		echo '
1977
		<FORM action="/tracker/admin" method="get">
1978
		<INPUT type="hidden" name="func" value="notification">
1979
		<INPUT type="hidden" name="atid" value="'.(int)$this->getID().'">
1980
		<INPUT type="hidden" name="group_id" value="'.(int)$group_id.'">';
1981
		
1982
		if ($this->userIsAdmin()) {
1983
	    	echo '<h3><a name="ToggleEmailNotification"></a>'.$Language->getText('tracker_include_type','toggle_notification').' '.
1984
			help_button('tracker-v3.html#email-notification-settings').'</h3>';
1985
			echo '
1986
			<P>'.$Language->getText('tracker_include_type','toggle_notif_note').'<BR>
1987
			<BR><INPUT TYPE="checkbox" NAME="stop_notification" VALUE="1" '.(($this->getStopNotification())?'CHECKED':'').'> '.$Language->getText('tracker_include_type','stop_notification');     
1988
		} else if ($this->getStopNotification()) {
1989
		    echo '<h3><a name="ToggleEmailNotification"></a>'.$Language->getText('tracker_include_type','notification_suspended').' '.
1990
			help_button('tracker-v3.html#email-notification-settings').'</h3>';
1991
			echo '
1992
			<P><b>'.$Language->getText('tracker_include_type','toggle_notif_warn').'</b><BR>';
1993
		}
1994
		
1995
		echo '<h3><a name="GlobalEmailNotification"></a>'.$Language->getText('tracker_include_type','global_mail_notif').' '.
1996
		help_button('tracker-v3.html#email-notification-settings').'</h3>';
1997
		
1998
        $agnf = new ArtifactGlobalNotificationFactory();
1999
        $notifs = $agnf->getGlobalNotificationsForTracker($this->getID());
2000
		if ($this->userIsAdmin()) {
2001
		    echo '<p>'. $Language->getText('tracker_include_type','admin_note') .'</p>';
2002
            if (count($notifs)) {
2003
                echo '<div id="global_notifs">';
2004
                foreach($notifs as $key => $nop) {
2005
                    echo '<div>';
2006
                    echo '<a href="?func=notification&amp;group_id='. (int)$group_id .'&amp;atid='. (int)$this->getId() .'&amp;action=remove_global&amp;global_notification_id='. (int)$notifs[$key]->getId() .'">'. $GLOBALS['Response']->getimage('ic/trash.png') .'</a> &nbsp;';
2007
                    //addresses
2008
                    echo '<input type="text" name="global_notification['. (int)$notifs[$key]->getId() .'][addresses]" value="'.  $hp->purify($notifs[$key]->getAddresses(), CODENDI_PURIFIER_CONVERT_HTML)  .'" size="55" />';
2009
                    //all_updates
2010
                    echo '&nbsp;&nbsp;&nbsp;'. $Language->getText('tracker_include_type','send_all') .' ';
2011
                    echo '<input type="hidden" name="global_notification['. (int)$notifs[$key]->getId() .'][all_updates]" value="0" />';
2012
                    echo '<input type="checkbox" name="global_notification['. (int)$notifs[$key]->getId() .'][all_updates]" value="1" '. (($notifs[$key]->isAllUpdates())?'checked="checked"':'') .' />';
2013
                    //check_permissions
2014
                    echo '&nbsp;&nbsp;&nbsp;'. $Language->getText('tracker_include_type','check_perms') .' ';
2015
                    echo '<input type="hidden" name="global_notification['. (int)$notifs[$key]->getId() .'][check_permissions]" value="0" />';
2016
                    echo '<input type="checkbox" name="global_notification['. (int)$notifs[$key]->getId() .'][check_permissions]" value="1" '. (($notifs[$key]->isCheckPermissions())?'checked="checked"':'') .' />';
2017
                    
2018
                    echo '</div>';
2019
                }
2020
                echo '</div>';
2021
            }
2022
            echo '<p><a href="?func=notification&amp;group_id='. (int)$group_id .'&amp;atid='. (int)$this->getId() .'&amp;action=add_global" id="add_global">'. $Language->getText('tracker_include_type','add') .'</a></p>';
2023
            echo '<script type="text/javascript">'."
2024
            document.observe('dom:loaded', function() {
2025
                $('add_global').observe('click', function (evt) {
2026
                    var self = arguments.callee;
2027
                    if (!self.counter) {
2028
                        self.counter = 0;
2029
                    }
2030
                    var number = self.counter++;
2031
                    
2032
                    var div = new Element('div');
2033
                    div.insert('<a href=\"#\" onclick=\"this.parentNode.remove(); return false;\">". $GLOBALS['Response']->getimage('ic/trash.png') ."</a> &nbsp;'+
2034
                               //addresses
2035
                               '<input type=\"text\" name=\"add_global_notification['+number+'][addresses]\" size=\"55\" />'+
2036
                               //all_updates
2037
                               '&nbsp;&nbsp;&nbsp;". addslashes($Language->getText('tracker_include_type','send_all')) ." '+
2038
                               '<input type=\"hidden\" name=\"add_global_notification['+number+'][all_updates]\" value=\"0\" />'+
2039
                               '<input type=\"checkbox\" name=\"add_global_notification['+number+'][all_updates]\" value=\"1\" />'+
2040
                               //check_permissions
2041
                               '&nbsp;&nbsp;&nbsp;". addslashes($Language->getText('tracker_include_type','check_perms')) ." '+
2042
                               '<input type=\"hidden\" name=\"add_global_notification['+number+'][check_permissions]\" value=\"0\" />'+
2043
                               '<input type=\"checkbox\" name=\"add_global_notification['+number+'][check_permissions]\" value=\"1\" checked=\"checked\" />'
2044
                    );
2045
                    
2046
                    Element.insert($('global_notifs'), div);
2047
                    
2048
                    Event.stop(evt);
2049
                    return false;
2050
                });
2051
            });
2052
            </script>";
2053
		} else {
2054
            $ok = false;
2055
            if (count($notifs)) {
2056
                reset($notifs);
2057
                while(!$ok && (list($id,) = each($notifs))) {
2058
                    $ok = $notifs[$id]->getAddresses();
2059
                }
2060
            }
2061
            if ($ok) {
2062
                echo $Language->getText('tracker_include_type','admin_conf');
2063
                foreach($notifs as $key => $nop) {
2064
                    if ($notifs[$key]->getAddresses()) {
2065
                        echo '<div>'. $notifs[$key]->getAddresses() .'&nbsp;&nbsp;&nbsp; ';
2066
                        echo $Language->getText('tracker_include_type','send_all_or_not',($notifs[$key]->isAllUpdates()?$Language->getText('global','yes'):$Language->getText('global','no')));
2067
                        echo '</div>';
2068
                    }
2069
                }
2070
            } else {
2071
				echo $Language->getText('tracker_include_type','admin_not_conf');
2072
            }
2073
		}
2074
		 
2075
		
2076
		echo '<h3>'.$Language->getText('tracker_include_type','perso_mail_notif').'</h3>';
2077
		  
2078
		if ($this->userIsAdmin()) {
2079
		    // To watch other users you must have at least admin rights on the tracker
2080
		    echo'
2081
		<h4>'.$Language->getText('tracker_include_type','users_to_watch').' '.
2082
		help_button('tracker-v3.html#tracker-watchers').'</h4>
2083
		<P>'.$Language->getText('tracker_include_type','backup_person').'
2084
		<p><INPUT TYPE="TEXT" NAME="watchees" VALUE="'. $hp->purify($watchees, CODENDI_PURIFIER_CONVERT_HTML) .'" SIZE="55" MAXLENGTH="255"><br></p>
2085
		';
2086
		
2087
		    $res = $this->getWatchers($user_id);
2088
		    $arr_watchers = array();
2089
		    $watchers="";
2090
                    while ($row_watcher = db_fetch_array($res)) {
2091
				$watcher_name = user_getname($row_watcher['user_id']);
2092
				$watchers .= '<a href="/users/'.urlencode($watcher_name).'">'. $hp->purify($watcher_name, CODENDI_PURIFIER_CONVERT_HTML) .'</a>,';
2093
		    }
2094
		    $watchers = substr($watchers,0,-1); // remove extra comma at the end
2095
		    
2096
		    if ($watchers) {
2097
				echo "<p>".$Language->getText('tracker_include_type','watchers', $hp->purify($watchers, CODENDI_PURIFIER_CONVERT_HTML) );
2098
		    } else {
2099
				echo "<p>".$Language->getText('tracker_include_type','no_watcher');
2100
		    }
2101
		    echo '<br><br>';
2102
		}
2103
		
2104
		// Build Role/Event table 
2105
		// Rk: Can't use html_build_list_table_top because of the specific layout
2106
		echo '<h4>'.$Language->getText('tracker_include_type','event_settings').' '.
2107
		help_button('tracker-v3.html#event-role-based-notification-settings').'</h4>
2108
		              <P>'.$Language->getText('tracker_include_type','tune_settings');
2109
		
2110
		echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2111
		<table BORDER="0" CELLSPACING="1" CELLPADDING="2" class="small">
2112
		<tr class="boxtitle">
2113
		    <td colspan="'.(int)$this->num_roles.'" align="center" width="50%"><b>'.$Language->getText('tracker_include_type','role_is').'</b></td>
2114
		    <td rowspan="2" width="50%"><b>&nbsp;&nbsp;&nbsp;'.$Language->getText('tracker_include_type','notify_me').'</b></td>
2115
		</tr>';
2116
		
2117
		for ($i=0; $i<$this->num_roles; $i++) {
2118
		    echo '<td align="center" width="10%"><b>'.$Language->getText('tracker_common_types',$this->arr_roles[$i]['short_description_msg'])."</b></td>\n";
2119
		}
2120
		echo "</tr>\n";
2121
		
2122
		for ($j=0; $j<$this->num_events; $j++) {
2123
		    $event_id = $this->arr_events[$j]['event_id'];
2124
		    $event_label = $this->arr_events[$j]['event_label'];
2125
		    echo "<tr class=\"".util_get_alt_row_color($j)."\">\n";
2126
		    for ($i=0; $i<$this->num_roles; $i++) {
2127
				$role_id = $this->arr_roles[$i]['role_id'];
2128
				$role_label = $this->arr_roles[$i]['role_label'];
2129
				$cbox_name = 'cb_'.$role_id.'_'.$event_id;
2130
				//echo "<BR>$role_label $role_id $event_label $event_id ".$arr_notif['$role_label']['$event_label'];
2131
				if ( (($event_label == 'NEW_ARTIFACT') && ($role_label != 'ASSIGNEE') && ($role_label != 'SUBMITTER')) ||
2132
					(($event_label == 'ROLE_CHANGE') && ($role_label != 'ASSIGNEE') && ($role_label != 'CC')) ) {
2133
				    // if the user is not a member then the ASSIGNEE column cannot
2134
				    // be set. If it's not an assignee or a submitter the new_artifact event is meaningless
2135
				    echo '   <td align="center"><input type="hidden" name="'.$cbox_name.'" value="1">-</td>'."\n";
2136
				} else {
2137
				    echo '   <td align="center"><input type="checkbox" name="'.$cbox_name.'" value="1" '.
2138
					($arr_notif[$role_label][$event_label] ? 'checked':'')."></td>\n";
2139
				}
2140
		    }
2141
		    echo '   <td>&nbsp;&nbsp;&nbsp;'.$Language->getText('tracker_common_types',$this->arr_events[$j]['description_msg'])."</td>\n";
2142
		    echo "</tr>\n";
2143
		}
2144
		
2145
		echo "</table>\n";
2146
		
2147
		$em = EventManager::instance();
2148
		$em->processEvent('artifact_type_html_display_notification_form', array('at' => $this, 'group_id' => $group_id, 'art_field_fact' => $GLOBALS['art_field_fact']));
2149
		
2150
		echo '<P align="center"><INPUT type="submit" name="submit" value="'.$Language->getText('tracker_include_artifact','submit').'">
2151
		</FORM>';
2152
			
2153
		
2154
	}
2155
2156
	/**
2157
	 *  Display the default value form
2158
	 *
2159
	 *  @param field_id: the field id to edit
2160
	 *  @param default_value: the default value
2161
	 *
2162
	 *  @return void
2163
	 */
2164
	function displayDefaultValueForm($field_id,$default_value) {
2165
		global $ath,$art_field_fact,$Language;
2166
		$hp = Codendi_HTMLPurifier::instance();
2167
		$field = $art_field_fact->getFieldFromId($field_id);
2168
		if ( !$field ) {
2169
			return;
2170
		}
2171
2172
		echo '<h3>'.$Language->getText('tracker_include_type','def_default').' '.help_button('tracker-v3.html#field-values-management').'</h3>';
2173
					
2174
		echo '
2175
	      <FORM ACTION="" METHOD="POST" name="artifact_form">
2176
	      <INPUT TYPE="HIDDEN" NAME="func" VALUE="update_default_value">
2177
	      <INPUT TYPE="HIDDEN" NAME="field_id" VALUE="'.(int)$field_id.'">
2178
	      <INPUT TYPE="HIDDEN" NAME="group_id" VALUE="'.(int)$this->Group->getID().'">
2179
	      <INPUT TYPE="HIDDEN" NAME="atid" VALUE="'.(int)$this->getID().'">';
2180
2181
		if ( $field->isSelectBox() || $field->isMultiSelectBox() ) {
2182
			echo $Language->getText('tracker_include_type','val').': ';
2183
			echo html_build_select_box ($field->getFieldValues($this->getID(),array('A','P')),"default_value",$default_value);
2184
		} else if ( $field->isDateField() ) {
2185
            echo '<input type="radio" name="default_date_type" value="current_date"'.($default_value==""?" checked=\"checked\"":"").'>'.$Language->getText('tracker_include_type','current_date').'</input><br />';
2186
            echo '<input type="radio" name="default_date_type" value="selected_date"'.($default_value!=""?" checked=\"checked\"":"").'>'.$Language->getText('tracker_include_type','date_value').'</input> ';
2187
            echo $GLOBALS['HTML']->getDatePicker("default_value_id", "default_value", ($default_value?format_date("Y-m-j",$default_value,''):''));
2188
            echo '<br />';
2189
		} else if($field->isTextArea()){
2190
			echo $Language->getText('tracker_include_type','val').': ';
2191
			echo '<BR><TEXTAREA NAME="default_value" wrap="virtual" cols="90" rows="12" >'.$hp->purify($default_value, CODENDI_PURIFIER_CONVERT_HTML).' </TEXTAREA></BR>';
2192
		}else {
2193
	      	echo $Language->getText('tracker_include_type','val').': <INPUT TYPE="text" NAME="default_value" VALUE="'. $hp->purify($default_value, CODENDI_PURIFIER_CONVERT_HTML) .'">';
2194
		}
2195
2196
		echo '
2197
		<INPUT type="submit" name="submit" value="'.$Language->getText('global','btn_update').'">
2198
		</form>';
2199
	}
2200
2201
	/**
2202
	 *  Display the default value form for fields having a value function (e.g. group_members, artifact_submitters)
2203
	 *
2204
	 *  @param field_id: the field id to edit
2205
	 *  @param default_value: the default value
2206
	 *  @param show_none,text_none,show_any,text_any,show_value: values used by html_build_select_box function
2207
	 *
2208
	 *  @return void
2209
	 */
2210
	function displayDefaultValueFunctionForm($field_id,$default_value,$show_none=true,$text_none=false,$show_any=false,$text_any=false,$show_value=false) {
2211
		global $ath,$art_field_fact,$Language;
2212
		
2213
		if (!$text_any) $text_any=$Language->getText('global','any');
2214
		if (!$text_none) $text_none=$Language->getText('global','none');
2215
2216
		$field = $art_field_fact->getFieldFromId($field_id);
2217
		if ( !$field ) {
2218
			return;
2219
		}
2220
2221
		echo '<h3>'.$Language->getText('tracker_include_type','def_default').' '.help_button('tracker-v3.html#field-values-management').'</h3>';
2222
					
2223
		echo '
2224
	      <FORM ACTION="" METHOD="POST" name="artifact_form">
2225
	      <INPUT TYPE="HIDDEN" NAME="func" VALUE="update_default_value">
2226
	      <INPUT TYPE="HIDDEN" NAME="field_id" VALUE="'.(int)$field_id.'">
2227
	      <INPUT TYPE="HIDDEN" NAME="group_id" VALUE="'.(int)$this->Group->getID().'">
2228
	      <INPUT TYPE="HIDDEN" NAME="atid" VALUE="'.(int)$this->getID().'">';
2229
2230
		//new stuff by MLS
2231
		$field_value = $field->getDefaultValue();
2232
		$predefinedValues = $field->getFieldPredefinedValues($this->getID());
2233
	
2234
		if ( $field->isSelectBox()) {
2235
			echo html_build_select_box ($predefinedValues,"default_value",$default_value);
2236
	   	} else if ($field->isMultiSelectBox() ) {
2237
			echo html_build_multiple_select_box($predefinedValues,"default_value[]",$default_value,
2238
							($field->getDisplaySize()!=""?$field->getDisplaySize():"6"),
2239
							$show_none,$text_none,$show_any,$text_any,false,'',$show_value);
2240
		} else {
2241
			echo 'Why are we in this case ??';
2242
		}
2243
2244
		echo '
2245
		 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <INPUT type="submit" name="submit" value="'.$Language->getText('global','btn_update').'">
2246
		</form><hr>';
2247
	}
2248
2249
	/**
2250
	 *  Get tha label for a code status
2251
	 *
2252
	 *  @param status: the code status
2253
	 *
2254
	 *  @return string
2255
	 */
2256
	function getLabelValueStatus($status) {
2257
	  global $Language;
2258
2259
		switch ( $status ) {
2260
		case "P":
2261
			return $Language->getText('tracker_include_type','permanent');
2262
		case "A":
2263
			return $Language->getText('tracker_include_type','active');
2264
		case "H":
2265
			return $Language->getText('tracker_include_type','hidden');
2266
		default:
2267
			return $Language->getText('tracker_include_type','unknown_stat').":".$status;
2268
		}
2269
	}
2270
2271
2272
	/**
2273
         * Display the artifact to do mass changes
2274
         *
2275
         * @param ro: read only parameter - Display mode or update mode
2276
         * @param pv: printer version
2277
	 * @param query: only in the case of func=masschange, the query that retrieves all the artifacts to be changed
2278
	 * @param $mass_change_ids[]: only in the case of func=masschange_selected, an array containing all the artifact ids to be changed
2279
         *
2280
         * @return void
2281
         */
2282
        function displayMassChange($ro, $mass_change_ids=null,$query=null,$art_report_html=null, $advsrch=0) {
2283
            global $art_field_fact,$sys_max_size_attachment,$Language;
2284
            $hp = Codendi_HTMLPurifier::instance();
2285
            $fields_per_line=2;
2286
            $max_size=40;
2287
            
2288
            $group = $this->getGroup();
2289
            $atid = $this->getID();
2290
            $group_id = $group->getGroupId();
2291
2292
	    if ($query) {
2293
		$art_report_html->getQueryElements($query,$advsrch,$from,$where);
0 ignored issues
show
Bug introduced by
The variable $from does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $where does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
2294
	  	$sql = "select distinct a.artifact_id ".$from." ".$where;
2295
	  	$result = db_query($sql);
2296
		while ($row = db_fetch_array($result)) {
2297
			$mass_change_ids[] = $row['artifact_id'];
2298
		}
2299
	    }
2300
            
2301
	    //if ($mass_change_ids) {
2302
            	echo '<H2>'.$Language->getText('tracker_include_type','changing_items',count($mass_change_ids)).' </H2>';
2303
		reset($mass_change_ids);
2304
		while ( list($key, $val) = each($mass_change_ids)) {
2305
            $url = '/tracker/?func=detail&group_id='. (int)$group_id .'&aid='. (int)$val .'&atid='. (int)$atid;
2306
			if ($key == 0) echo '<a href="'. $url .'">'. $hp->purify($this->getItemName(), CODENDI_PURIFIER_CONVERT_HTML) .' #'. (int)$val .'</a>';
2307
			if ($key > 0) echo ', <a href="'. $url .'"> #'. (int)$val .'</a>';
2308
			if ($key == 100) {echo ", .."; break;}
2309
		}
2310
2311
2312
		echo '
2313
	    <br><br>';
2314
                echo '
2315
            <FORM ACTION="?" METHOD="POST" enctype="multipart/form-data" NAME="masschange_form">
2316
            <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.$sys_max_size_attachment.'">
2317
            <INPUT TYPE="HIDDEN" NAME="func" VALUE="postmasschange">
2318
            <INPUT TYPE="HIDDEN" NAME="group_id" VALUE="'.(int)$group_id.'">
2319
            <INPUT TYPE="HIDDEN" NAME="atid" VALUE="'.(int)$atid.'">';
2320
		reset($mass_change_ids);
2321
		while (list(,$val) = each($mass_change_ids)) {
2322
			echo '
2323
	    <INPUT TYPE="HIDDEN" NAME="mass_change_ids[]" VALUE="'. $hp->purify($val, CODENDI_PURIFIER_CONVERT_HTML) .'">';	
2324
		}
2325
2326
2327
                echo '
2328
            <TABLE cellpadding="0">';
2329
2330
		//first special case for submitted_by
2331
		$field = $art_field_fact->getFieldFromName('submitted_by');
2332
		$field_html = new ArtifactFieldHtml($field);
2333
		$field_value = $Language->getText('global','unchanged');
2334
                                
2335
                list($sz,) = explode("/",$field->getDisplaySize());
2336
                $label = $field_html->labelDisplay(false,false,!$ro);
2337
                // original submission field must be displayed read-only
2338
                $value = $field_html->display($this->getID(),$field_value,false,false,$ro,false,false,$Language->getText('global','none'),false,'Any',true,$Language->getText('global','unchanged'));
2339
2340
                echo "\n<TR>";
2341
                echo '
2342
	    <TD valign="top">'.$label.'&nbsp;</TD>
2343
            <TD valign="top">'.$value.'&nbsp;</TD>
2344
            <TD colspan="2"><FONT SIZE="-1"><INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="'.$Language->getText('tracker_include_type','submit_mass_change').'"></TD>';
2345
            	echo '
2346
            </TR>
2347
            <TR><TD COLSPAN="'.($fields_per_line*2).'">&nbsp</TD></TR>';
2348
        
2349
        
2350
                // Now display the variable part of the field list (depend on the project)
2351
        
2352
		$i = 0;            
2353
            	$result_fields = $art_field_fact->getAllUsedFields();
2354
        	while ( list($key, $field) = each($result_fields) ) {
0 ignored issues
show
Unused Code introduced by
The assignment to $key is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
2355
                
2356
                	$field_html = new ArtifactFieldHtml($field);
2357
                
2358
                        // if the field is a special field (except summary and details) 
2359
                        // then skip it.
2360
                        if ( !$field->isSpecial() && $field->getName()!='summary' && $field->getName()!='details') {
2361
                                           
2362
                                // display the artifact field
2363
                                // if field size is greatest than max_size chars then force it to
2364
                                // appear alone on a new line or it won't fit in the page
2365
                                
2366
                                $field_value = $Language->getText('global','unchanged');
2367
                                
2368
                                list($sz,) = explode("/",$field->getDisplaySize());
2369
                                $label = $field_html->labelDisplay(false,false,!$ro);
2370
                                $value = $field_html->display($this->getID(),$field_value,false,false,$ro,false,false,$Language->getText('global','none'),false,$Language->getText('global','any'),true,$Language->getText('global','unchanged'));
2371
2372
                                        
2373
                                // Details field must be on one row
2374
                                if ($sz > $max_size) {
2375
                                        echo "\n<TR>".
2376
                                          '<TD valign="top">'.$label.'</td>'.
2377
                                          '<TD valign="top" colspan="'.(2*$fields_per_line-1).'">'.
2378
                                          $value.'</TD>'.                     
2379
                                          "\n</TR>";
2380
                                        $i=0;
2381
                                } else {
2382
                                        echo ($i % $fields_per_line ? '':"\n<TR>");
2383
                                        echo '<TD valign="top">'.$label.'</td>'.
2384
                                          '<TD valign="top">'.$value.'</TD>';
2385
                                        $i++;
2386
                                        echo ($i % $fields_per_line ? '':"\n</TR>");
2387
                                }
2388
                        }
2389
                } // while
2390
                          
2391
2392
		echo '
2393
	    </TABLE>
2394
	    <table cellspacing="0">';
2395
2396
		//
2397
                // Followups comments
2398
                //
2399
                echo '
2400
	    <TR><TD colspan="2" align="top"><HR></td></TR>
2401
	    <TR><TD>
2402
            <h3>'.$Language->getText('tracker_include_artifact','follow_ups').' '.help_button('tracker-v3.html#comments').'</h3></td>
2403
            <TD>
2404
            <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="'.$Language->getText('tracker_include_type','submit_mass_change').'">
2405
            </td></tr>';
2406
2407
                echo '
2408
            <tr><TD colspan="2" align="top">
2409
            <B>'.$Language->getText('tracker_include_artifact','use_canned').'</B>&nbsp;';
2410
                        
2411
                echo $this->cannedResponseBox ();
2412
                        
2413
                echo '
2414
            &nbsp;&nbsp;&nbsp;<A HREF="/tracker/admin/?func=canned&atid='.(int)$atid.'&group_id='.(int)$group_id.'&create_canned=1">'.$Language->getText('tracker_include_artifact','define_canned').'</A>
2415
            </TD></TR>';
2416
                        
2417
                echo '
2418
            <TR><TD colspan="2">';
2419
                        
2420
                $field = $art_field_fact->getFieldFromName('comment_type_id');
2421
                if ( $field ) {
2422
                     $field_html = new ArtifactFieldHtml( $field );
2423
                     echo '<P><B>'.$Language->getText('tracker_include_artifact','comment_type').'</B>'.
2424
                          $field_html->fieldBox('',$atid,$field->getDefaultValue(),true,$Language->getText('global','none')).'<BR>';
2425
                }
2426
                // This div id used just to show the toggle of html format
2427
                echo '<DIV ID="tracker_artifact_comment_label"></DIV>';
2428
                echo '<TEXTAREA NAME="comment" id="tracker_artifact_comment" ROWS="10" style="width:700px;" WRAP="SOFT"></TEXTAREA><p>';
2429
                                
2430
        
2431
                echo '</td></tr>';
2432
                
2433
                //
2434
                // CC List
2435
                //
2436
                echo '          
2437
                <TR><TD colspan="2"><hr></td></tr>
2438
                
2439
                <TR><TD colspan="2">
2440
                <h3>'.$Language->getText('tracker_include_artifact','cc_list').' '.help_button('tracker-v3.html#cc-list').'</h3>';
2441
                
2442
                if ( !$ro ) {
2443
                    echo '
2444
                                '.$Language->getText('tracker_include_artifact','fill_cc_list_msg');
2445
                    echo $Language->getText('tracker_include_artifact','fill_cc_list_lbl');
2446
                    echo '<input type="text" name="add_cc" id="tracker_cc" size="30">';
2447
                    echo $Language->getText('tracker_include_artifact','fill_cc_list_cmt');
2448
                    echo '<input type="text" name="cc_comment" size="40" maxlength="255">';
2449
                }
2450
                
2451
	
2452
		
2453
		echo $this->showCCList($mass_change_ids);
2454
2455
2456
                echo '</TD></TR>';
2457
                        
2458
                //
2459
                // File attachments
2460
                //
2461
                echo '
2462
                <TR><TD colspan="2"><hr></td></tr>
2463
                <TR><TD colspan="2">
2464
                <h3>'.$Language->getText('tracker_include_artifact','attachment').' '.help_button('tracker-v3.html#artifact-attachments').'</h3>';
2465
                
2466
                echo $Language->getText('tracker_include_artifact','upload_checkbox');
2467
		echo ' <input type="checkbox" name="add_file" VALUE="1">';
2468
                echo $Language->getText('tracker_include_artifact','upload_file_lbl');
2469
                echo '<input type="file" name="input_file" size="40">';
2470
                echo $Language->getText('tracker_include_artifact','upload_file_msg',formatByteToMb($sys_max_size_attachment));
2471
2472
                echo $Language->getText('tracker_include_artifact','upload_file_desc');
2473
		echo '<input type="text" name="file_description" size="60" maxlength="255">';
2474
                                
2475
		reset($mass_change_ids);
2476
                echo $this->showAttachedFiles($mass_change_ids);
2477
                echo '</TD></TR>';
2478
2479
                //
2480
                // Artifact dependencies
2481
                //
2482
                echo '
2483
                <TR><TD colspan="2"><hr></td></tr>
2484
                <TR ><TD colspan="2">';
2485
                
2486
                echo '<h3>'.$Language->getText('tracker_include_artifact','dependencies').' '.help_button('tracker-v3.html#artifact-dependencies').'</h3>
2487
                <B>'.$Language->getText('tracker_include_artifact','dependent_on').'</B><BR>
2488
                <P>';
2489
                if ( !$ro ) {
2490
                        echo '
2491
                        <B>'.$Language->getText('tracker_include_artifact','aids').'</B>&nbsp;
2492
                        <input type="text" name="artifact_id_dependent" size="20" maxlength="255">
2493
                        &nbsp;<i>'.$Language->getText('tracker_include_artifact','fill').'</i><p>';
2494
                }
2495
		echo $this->showDependencies($mass_change_ids);
2496
2497
                echo '</TD></TR>';
2498
                
2499
                //
2500
                // Artifact permissions
2501
                //
2502
                if ($this->userIsAdmin()) {
2503
                    echo '
2504
                    <TR><TD colspan="2"><hr></td></tr>
2505
                    <TR ><TD colspan="2">';
2506
                    
2507
                    echo '<h3>'. $Language->getText('tracker_include_artifact','permissions') .' '. help_button('tracker-v3.html#permissions-on-artifacts') .'</h3>';
2508
                    echo '<input type="hidden" name="change_permissions" value="0" />';
2509
                    echo '<input type="checkbox" name="change_permissions" value="1" id="change_permissions" />';
2510
                    echo '<label for="change_permissions">'. $GLOBALS['Language']->getText('tracker_include_type', 'mass_change_permissions') .'</label>';
2511
                    echo '<blockquote>';
2512
                    $checked = '';
2513
                    $html = '';
2514
                    $html .= '<p>';
2515
                    $html .= '<label class="checkbox" for="use_artifact_permissions">';
2516
                    $html .= '<input type="hidden" name="use_artifact_permissions_name" value="0" />';
2517
                    $html .= '<input type="checkbox" name="use_artifact_permissions_name" id="use_artifact_permissions" value="1" '. $checked .' />';
2518
                    $html .= ''. $GLOBALS['Language']->getText('tracker_include_artifact', 'permissions_label') .'</label>';
2519
                    $html .= '</p>';
2520
                    $html .= permission_fetch_selection_field('TRACKER_ARTIFACT_ACCESS', 0, $group_id);
2521
                    $html .= '<script type="text/javascript">';
2522
                    $html .= "
2523
                    document.observe('dom:loaded', function() {
2524
                        //init
2525
                        if ( ! $('use_artifact_permissions')|| ! $('use_artifact_permissions').checked ) {
2526
                            $('ugroups').disable();
2527
                        }
2528
                        if ( ! $('change_permissions').checked) {
2529
                            $('use_artifact_permissions').disable();
2530
                        }
2531
                        
2532
                        //event handlers
2533
                        $('change_permissions').observe('change', function(evt) {
2534
                            if (this.checked) {
2535
                                $('use_artifact_permissions').enable();
2536
                                if ($('use_artifact_permissions').checked) {
2537
                                    $('ugroups').enable();
2538
                                }
2539
                            } else {
2540
                                $('use_artifact_permissions').disable();
2541
                                $('ugroups').disable();
2542
                            }
2543
                        });
2544
                        
2545
                        $('use_artifact_permissions').observe('change', function(evt) {
2546
                            if (this.checked) {
2547
                                $('ugroups').enable();
2548
                            } else {
2549
                                $('ugroups').disable();
2550
                            }
2551
                        });
2552
                    });
2553
                    </script>";
2554
                    echo $html;
2555
                    echo '</blockquote>';
2556
                    echo '</TD></TR>';
2557
                }
2558
                
2559
        	echo '<TR><TD colspan="2"><hr></td></tr>';                        
2560
		echo '</TD></TR>                
2561
                        <TR><TD colspan="2" ALIGN="center">
2562
                                <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="'.$Language->getText('tracker_include_type','submit_mass_change').'">
2563
                                </FORM>
2564
                        </TD></TR>';
2565
                
2566
                echo '</table>';
2567
                
2568
2569
	}
2570
2571
2572
	/**
2573
	* Show all the cc addresses of all the artifacts in $change_ids
2574
	* @param group_id: the group id
2575
        * @param group_artifact_id: the artifact type ID
2576
	* @param change_ids: all the ids of the artifacts affected
2577
	*/
2578
	function showCCList($change_ids) {
2579
        $hp = Codendi_HTMLPurifier::instance();
2580
	  global $Language;
2581
		$out = "";
2582
			
2583
		$result = $this->getCC($change_ids);			
2584
		
2585
		if (db_numrows($result) > 0) {
2586
			$title_arr=array();
2587
                        $title_arr[]=$Language->getText('tracker_include_artifact','cc_address');
2588
                        $title_arr[]=$Language->getText('tracker_include_type','occurrence');
2589
                        $title_arr[]=$Language->getText('tracker_include_canned','delete');
2590
                        $out .= html_build_list_table_top ($title_arr);
2591
                
2592
                        $fmt = "\n".'<TR class="%s"><td>%s</td><td align="center">%s</td><td align="center">%s</td></tr>';				
2593
2594
			
2595
			// Loop through the cc and format them
2596
			$email = "";
2597
			$row_color = 0;
2598
			$i = 0;
2599
            		while ($row = db_fetch_array($result)) {
2600
				if ($row['email'] != $email) {
2601
					if ($email != "") {
2602
						$html_delete = '
2603
		<INPUT TYPE="CHECKBOX" NAME="delete_cc[]" VALUE="'. $hp->purify($delete_ids, CODENDI_PURIFIER_CONVERT_HTML) .'">';
2604
						$out .= sprintf($fmt,
2605
                                        		util_get_alt_row_color($row_color),
2606
                                        		$href_cc,
2607
							$i,
2608
                                        		$html_delete);
2609
						$row_color++;
2610
						$i = 0;	
2611
					}
2612
					$email = $row['email'];
2613
					$res_username = user_get_result_set_from_unix($email);
2614
                        		if ($res_username && (db_numrows($res_username) == 1))
2615
                            			$href_cc = util_user_link($email);
2616
                        		else
2617
                            			$href_cc = "<a href=\"mailto:".util_normalize_email($email)."\">". $hp->purify($email, CODENDI_PURIFIER_CONVERT_HTML) .'</a>';
2618
					$delete_ids = $row['artifact_cc_id'];
2619
				} else {
2620
					$delete_ids .= ",".$row['artifact_cc_id'];
2621
				}
2622
				$i++;
2623
			}
2624
			$html_delete = '
2625
		<INPUT TYPE="CHECKBOX" NAME="delete_cc[]" VALUE="'.$delete_ids.'">';
2626
			$out .= sprintf($fmt,
2627
                                        util_get_alt_row_color($row_color),
2628
                                        $href_cc,
2629
					$i,
2630
                                        $html_delete);	
2631
			$out .= "</TABLE>";
2632
            	}
2633
        
2634
            	return($out);
2635
	}
2636
2637
	/**
2638
	* Display the list of attached files of all the artifacts in $change_ids
2639
	* @param group_id: the group id
2640
        * @param group_artifact_id: the artifact type ID
2641
	* @param change_ids: all the ids of the artifacts affected
2642
	*/
2643
	function showAttachedFiles($change_ids) {
2644
	  global $Language;
2645
      $hp = Codendi_HTMLPurifier::instance();
2646
		$out = "";
2647
		$result = $this->getAttachedFiles($change_ids);		
2648
	
2649
		if (db_numrows($result) > 0) {
2650
			$title_arr=array();
2651
                	$title_arr[]=$Language->getText('tracker_include_artifact','name');
2652
                	$title_arr[]=$Language->getText('tracker_include_artifact','size_kb');
2653
                	$title_arr[]=$Language->getText('tracker_include_type','occurrence');
2654
            		$title_arr[]=$Language->getText('tracker_include_canned','delete');
2655
        
2656
                	$out .= html_build_list_table_top ($title_arr);
2657
2658
			$fmt = '<TR class="%s"><td>%s</td><td align="center">%s</td><td align="center">%s</td><td align="center">%s</td></tr>';
2659
2660
			// Loop throuh the attached files and format them
2661
			$i = 0;
2662
			$rowcolor = 0;
2663
			$filename = "";
2664
			$filesize = -1;
2665
			while ($row = db_fetch_array($result)) {
2666
				if ($row['filename'] != $filename || $row['filesize'] != $filesize) {
2667
					if ($filename != "") {
2668
						$html_delete = '
2669
	<INPUT TYPE="CHECKBOX" NAME="delete_attached[]" VALUE="'. $hp->purify($delete_ids, CODENDI_PURIFIER_CONVERT_HTML) .'">';
2670
						$out .= sprintf($fmt,
2671
                                            		util_get_alt_row_color($rowcolor),
2672
                                            		 $hp->purify($filename, CODENDI_PURIFIER_CONVERT_HTML) ,
2673
                                            		intval($filesize/1024),
2674
							$i,
2675
                                            		$html_delete);
2676
						$i = 0;	
2677
						$rowcolor++;
2678
					}
2679
					$delete_ids = $row['id'];
2680
					$filename = $row['filename'];
2681
					$filesize = $row['filesize'];	
2682
				} else {
2683
					$delete_ids .= ",".$row['id'];						
2684
				}
2685
				$i++;
2686
			}
2687
			$html_delete = '
2688
	<INPUT TYPE="CHECKBOX" NAME="delete_attached[]" VALUE="'. $hp->purify($delete_ids, CODENDI_PURIFIER_CONVERT_HTML) .'">';
2689
			$out .= sprintf($fmt,
2690
                                        util_get_alt_row_color($rowcolor),
2691
                                         $hp->purify($filename, CODENDI_PURIFIER_CONVERT_HTML) ,
2692
                                        intval($filesize/1024),
2693
					$i,
2694
                                        $html_delete);	
2695
			$out .= "</TABLE>";	
2696
		}
2697
		return $out;
2698
2699
	}
2700
2701
	/**
2702
         * Display the artifact dependencies list for all artifacts in change_ids 
2703
         *
2704
         * @param change_ids: the artifacts for that we search dependencies
2705
         * @return string
2706
         */
2707
        function showDependencies ($change_ids) {
2708
	  global $Language;
2709
            $hp = Codendi_HTMLPurifier::instance();
2710
            $result=$this->getDependencies($change_ids);
2711
            $rows=db_numrows($result);
2712
            $out = '';
2713
            // Nobody in the dependencies list -> return now
2714
            if ($rows > 0) {
2715
            	$title_arr=array();
2716
              	$title_arr[]=$Language->getText('tracker_include_artifact','artifact');
2717
                $title_arr[]=$Language->getText('tracker_include_artifact','summary');
2718
                $title_arr[]=$Language->getText('tracker_import_admin','tracker');
2719
                $title_arr[]=$Language->getText('tracker_include_artifact','group');
2720
                $title_arr[]=$Language->getText('tracker_include_type','occurrence');
2721
                $title_arr[]=$Language->getText('tracker_include_canned','delete');
2722
                $out .= html_build_list_table_top ($title_arr);
2723
                
2724
                $fmt = "\n".'<TR class="%s"><td>%s</td><td>%s</td><td align="center">%s</td>'.
2725
                            '<td align="center">%s</td><td align="center">%s</td><td align="center">%s</td></tr>';
2726
                
2727
            	// Loop through the denpendencies and format them
2728
		$occ = 0;
2729
		$dependent_on_artifact_id = -1;
2730
		$row_color = 0;
2731
            	for ($i=0; $i < $rows; $i++) {
2732
        		if ($dependent_on_artifact_id != db_result($result, $i, 'is_dependent_on_artifact_id')) {
2733
				if ($dependent_on_artifact_id != -1) {
2734
					$html_delete = '
2735
	<INPUT TYPE="CHECKBOX" NAME="delete_depend[]" VALUE="'. $hp->purify($depend_ids, CODENDI_PURIFIER_CONVERT_HTML) .'">';
2736
					$out .= sprintf($fmt,
2737
                                            	util_get_alt_row_color($row_color),
2738
                                            	'<a href="/tracker/?func=gotoid&group_id='. (int)$group_id .'&aid='. (int)$dependent_on_artifact_id .'">'.  $hp->purify($dependent_on_artifact_id, CODENDI_PURIFIER_CONVERT_HTML)  ."</a>",
2739
                                            	 $hp->purify(util_unconvert_htmlspecialchars($summary), CODENDI_PURIFIER_BASIC, $this->getGroupId()) ,
2740
                                            	 $hp->purify($tracker_label, CODENDI_PURIFIER_CONVERT_HTML) ,
2741
                                            	 $hp->purify($group_label, CODENDI_PURIFIER_CONVERT_HTML) ,
2742
						$occ,
2743
                                            	$html_delete);
2744
					$row_color++;
2745
					$occ = 0;	
2746
				}
2747
                $dependent_on_artifact_id = db_result($result, $i, 'is_dependent_on_artifact_id');
2748
                $summary                  = db_result($result, $i, 'summary');
2749
                $tracker_label            = db_result($result, $i, 'name');
2750
                $group_label              = db_result($result, $i, 'group_name');
2751
                $group_id                 = db_result($result, $i, 'group_id');
2752
				$depend_ids               = db_result($result, $i, 'artifact_depend_id');
2753
			} else {
2754
				$depend_ids .= ",".db_result($result, $i, 'artifact_depend_id');
2755
			}
2756
			$occ++;
2757
                } // for
2758
		$html_delete = '
2759
	<INPUT TYPE="CHECKBOX" NAME="delete_depend[]" VALUE="'.$depend_ids.'">';
2760
		$out .= sprintf($fmt,
2761
                                util_get_alt_row_color($row_color),
2762
                                '<a href="/tracker/?func=gotoid&group_id='. (int)$group_id .'&aid='. (int)$dependent_on_artifact_id .'">'.  $hp->purify($dependent_on_artifact_id, CODENDI_PURIFIER_CONVERT_HTML)  ."</a>",
2763
                                 $hp->purify(util_unconvert_htmlspecialchars($summary), CODENDI_PURIFIER_BASIC, $this->getGroupId()) ,
2764
                                 $hp->purify($tracker_label, CODENDI_PURIFIER_CONVERT_HTML) ,
2765
                                 $hp->purify($group_label, CODENDI_PURIFIER_CONVERT_HTML) ,
2766
				$occ,
2767
                                $html_delete);
2768
        
2769
            	// final touch...
2770
            	$out .= "</TABLE>";
2771
            }
2772
        
2773
            return($out);
2774
        }
2775
2776
2777
2778
2779
	/**
2780
	 *  Display the fieldset creation or update form
2781
	 *
2782
	 *  @param string $func fieldset_create or fieldset_update
2783
	 *  @param int $fieldset_id the fieldset id
2784
	 *  @param string $fieldset_name the fieldset name
2785
	 *  @param string $description: the fieldset description
0 ignored issues
show
Documentation introduced by
There is no parameter named $description:. Did you maybe mean $description?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
2786
	 *  @param int $rank rank on screen
2787
	 *
2788
	 *  @return void
2789
	 */
2790
    function displayFieldSetCreateForm($func="fieldset_create",$fieldset_id=false,$fieldset_name=false,$description=false,$rank=false) {
2791
        global $art_fieldset_fact,$Language;
2792
        $hp = Codendi_HTMLPurifier::instance();
2793
        $fieldset = $art_fieldset_fact->getFieldSetById($fieldset_id);
2794
2795
        $afs = new ArtifactFieldSet();
2796
2797
        if ( $func == "fieldset_create" ) {
2798
            echo '<h3>'.$Language->getText('tracker_include_type','create_fieldset').'</h3>';
2799
            echo '
2800
              <form name="form_create" method="/tracker/admin/index.php">
2801
              <input type="hidden" name="func" value="'.$func.'">
2802
              <input type="hidden" name="group_id" value="'.(int)$this->Group->getID().'">
2803
              <input type="hidden" name="atid" value="'.(int)$this->getID().'">
2804
              <input type="hidden" name="fieldset_id" value="">
2805
              <input type="hidden" name="fieldset_name" value="">
2806
              <input type="hidden" name="description" value="">
2807
              <input type="hidden" name="rank" value="">';
2808
        } else {
2809
            echo "<h3>".$Language->getText('tracker_include_type','update_fieldset',$fieldset_name)."</h3>";
2810
            echo '
2811
              <form name="form_create" method="/tracker/admin/index.php">
2812
              <input type="hidden" name="func" value="'. $hp->purify($func, CODENDI_PURIFIER_CONVERT_HTML) .'">
2813
              <input type="hidden" name="group_id" value="'.$this->Group->getID().'">
2814
              <input type="hidden" name="atid" value="'.(int)$this->getID().'">
2815
              <input type="hidden" name="fieldset_id" value="'.(int)$fieldset_id.'">
2816
              <input type="hidden" name="fieldset_name" value="'. $hp->purify(SimpleSanitizer::unsanitize($fieldset_name), CODENDI_PURIFIER_CONVERT_HTML) .'">
2817
              <input type="hidden" name="description" value="'. $hp->purify(SimpleSanitizer::unsanitize($description), CODENDI_PURIFIER_CONVERT_HTML) .'">
2818
              <input type="hidden" name="rank" value="'. $hp->purify($rank, CODENDI_PURIFIER_CONVERT_HTML) .'">';
2819
        }
2820
        echo '<fieldset>';
2821
        echo '<legend>'.$Language->getText('tracker_include_type','fieldset_ident').'</legend>';
2822
        echo '<p>';
2823
        echo '<label for="name">'.$Language->getText('tracker_include_type','fieldset_name').': <font color="red">*</font></label> ';
2824
        echo '<input type="text" name="name" id="name" value="'. $hp->purify(SimpleSanitizer::unsanitize($fieldset_name?$fieldset_name:""), CODENDI_PURIFIER_CONVERT_HTML) .'" size="30" maxlength="40" />';
2825
        echo '</p>';
2826
        echo '<p>';
2827
        echo '<label for="description">'.$Language->getText('tracker_include_type','fieldset_desc').':</label>';
2828
        echo '<input type="text" name="description" id="description" value="'. $hp->purify(SimpleSanitizer::unsanitize($description?$description:""), CODENDI_PURIFIER_CONVERT_HTML) .'" size="70" maxlength="255" />';
2829
        echo '</p>';
2830
        echo '</fieldset>';
2831
        echo '<fieldset>';
2832
        echo '<legend>'.$Language->getText('tracker_include_type','fieldset_display').'</legend>';
2833
        echo '<p>';
2834
        echo '<label for="rank">'.$Language->getText('tracker_include_type','rank_screen').':</label>';
2835
        echo '<input type="text" name="rank" id="rank" value="'. $hp->purify(($rank?$rank:""), CODENDI_PURIFIER_CONVERT_HTML) .'" size="5" maxlength="5" />';
2836
        echo '</p>';
2837
        echo '</fieldset>';
2838
2839
        if ( $func == "fieldset_create" ) {
2840
            echo '<input type="submit" name="Submit" value="'.$Language->getText('global','btn_create').'">';
2841
        } else {
2842
            echo '<input type="submit" name="Submit" value="'.$Language->getText('global','btn_update').'">';
2843
        }
2844
2845
        echo '</form>';
2846
        echo '<p><font color="red">*</font>: '.$Language->getText('tracker_include_type','fields_requ').'</p>';
2847
2848
    }
2849
2850
    /**
2851
     *  Display the field sets list
2852
     *
2853
     *  @return void
2854
     */
2855
    function displayFieldSetList() {
2856
        global $ath,$art_fieldset_fact,$Language;
2857
        $hp = Codendi_HTMLPurifier::instance();
2858
        echo '<h3>'.$Language->getText('tracker_include_type','list_all_fieldsets').'</h3>';
2859
        echo '<p>'.$Language->getText('tracker_include_report','mod');
2860
        
2861
        
2862
        // Show all the fields currently available in the system
2863
        $i=0;
2864
        $title_arr=array();
2865
        $title_arr[]=$Language->getText('tracker_include_type','fieldset_name');
2866
        $title_arr[]=$Language->getText('tracker_include_artifact','desc');
2867
        $title_arr[]=$Language->getText('tracker_include_type','fields_inside');
2868
        $title_arr[]=$Language->getText('tracker_include_type','rank_screen');
2869
        $title_arr[]=$Language->getText('tracker_include_canned','delete');
2870
        
2871
        echo html_build_list_table_top ($title_arr);
2872
        
2873
        // Build HTML ouput for  Used fields
2874
        $iu=0;
2875
        $fieldsets = $art_fieldset_fact->getAllFieldSets();
2876
        $html = "";
2877
        
2878
        foreach ($fieldsets as $fieldset) {
2879
            
2880
            $rank = ($fieldset->getRank())?$fieldset->getRank():"-";
2881
            
2882
            $html .= '<tr class="'.util_get_alt_row_color($iu) .'">';
2883
            $html .= '<td><a href="?group_id='.(int)$this->Group->getID()."&atid=".(int)$this->getID().'&func=display_fieldset_update&fieldset_id='.(int)$fieldset->getID().'">'. $hp->purify(SimpleSanitizer::unsanitize($fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</A></td>';
2884
            $html .= '<td>'. $hp->purify(SimpleSanitizer::unsanitize($fieldset->getDescriptionText()), CODENDI_PURIFIER_BASIC, $this->getGroupId()) .'</td>';
2885
            $html .= '<td>';
2886
            $fields_contained = $fieldset->getArtifactFields();
2887
            if (count($fields_contained) > 0) {
2888
                $html .= '<ul>';
2889
                foreach($fields_contained as $field_contained) {
2890
                    $link_field_usage = '/tracker/admin/?func=display_field_update&group_id='.(int)$this->Group->getID().'&atid='.(int)$this->getID().'&field_id='.(int)$field_contained->getID();
2891
                    $html .= '<li>';
2892
                    if ($field_contained->getUseIt()) {
2893
                        $html .= '<strong><a href="'.$link_field_usage.'">'. $hp->purify(SimpleSanitizer::unsanitize($field_contained->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</a></strong>';
2894
                    } else {
2895
                        $html .= '<em><a href="'.$link_field_usage.'">'. $hp->purify(SimpleSanitizer::unsanitize($field_contained->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</a></em>';
2896
                    }
2897
                    $html .= '</li>';
2898
                }
2899
                $html .= '</ul>';
2900
            } else {
2901
                $html .= '- - -'; // $Language-> getText('tracker_include_type','empty_fieldset');
2902
            }
2903
            $html .= '</td>';
2904
            $html .= '<td align="center">'. $hp->purify($rank, CODENDI_PURIFIER_CONVERT_HTML) .'</td>';
2905
            $html .= '<td align="center">';
2906
            // Only possible to delete empty field sets (containing no fields inside)
2907
            if (count($fields_contained) <= 0) {
2908
                $html .= '<a href="/tracker/admin/?func=fieldset_delete&group_id='.(int)$this->Group->getID().'&atid='.(int)$this->getID().'&fieldset_id='.(int)$fieldset->getID().'"><img src="'.util_get_image_theme("ic/trash.png").'" border="0" onClick="return confirm(\''.$Language->getText('tracker_include_type','warning_delete_fieldset').'\')"></a>';
2909
            }
2910
            $html .= '</td>';
2911
            $html .= '</tr>';
2912
                                    
2913
            $iu++;
2914
        }
2915
        echo $html;
2916
        echo '</table>';
2917
        echo '<hr>';
2918
        
2919
    }
2920
    
2921
    /**
2922
     * Display the dropdownlist (select list) of all available fieldsets of the tracker $artifact_group_id
2923
     *
2924
     * @param int $artifact_group_id the tracker id
2925
     * @param int $selected_field_set_id the id of the fieldset that must be selected, or false if no default fieldset is selected
0 ignored issues
show
Documentation introduced by
There is no parameter named $selected_field_set_id. Did you maybe mean $selected_fieldset_id?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
2926
     */
2927
    function displayFieldSetDropDownList($artifact_group_id, $selected_fieldset_id = false) {
2928
        $hp = Codendi_HTMLPurifier::instance();
2929
        global $ath,$art_fieldset_fact;
2930
        
2931
        $fieldsets = $art_fieldset_fact->getArtifactFieldSetsFromId($artifact_group_id);
2932
        
2933
        $html = '<select name="field_set_id">';
2934
        foreach($fieldsets as $fieldset) {
2935
            $html .= '<option value="'.$fieldset->getID().'"';
2936
            if ($fieldset->getID() === $selected_fieldset_id) {
2937
                $html .= ' selected="selected"';
2938
            }
2939
            $html .= '>'. $hp->purify(SimpleSanitizer::unsanitize($fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</option>';
2940
        }
2941
        
2942
        $html .= '</select>';
2943
        echo $html;
2944
    }
2945
2946
2947
2948
}
2949
2950
?>
2951