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.

ArtifactHtml::displayCopy()   F
last analyzed

Complexity

Conditions 25
Paths 3120

Size

Total Lines 230
Code Lines 141

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 230
rs 2
cc 25
eloc 141
nc 3120
nop 2

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
//  Parts of code come from bug_util.php (written by Laurent Julliard)
11
//
12
//  Written for Codendi by Stephane Bouhet
13
//
14
require_once('common/tracker/Artifact.class.php');
15
require_once('common/mail/Mail.class.php');
16
require_once('common/reference/ReferenceManager.class.php');
17
require_once('common/rss/RSS.class.php');
18
require_once('common/reference/CrossReferenceFactory.class.php');
19
20
21
class ArtifactHtml extends Artifact {
22
23
        /**
24
         *  ArtifactHtml() - constructor
25
         *
26
         *  Use this constructor if you are modifying an existing artifact
27
         *
28
         *  @param $ArtifactType object
29
         *  @param $artifact_id integer (primary key from database)
30
         *  @return true/false
0 ignored issues
show
Documentation introduced by
The doc-type true/false could not be parsed: Unknown type name "true/false" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
31
         */
32
        function ArtifactHtml(&$ArtifactType,$artifact_id=false) {
33
                return $this->Artifact($ArtifactType,$artifact_id);
34
        }
35
36
        /**
37
         * Display the artifact
38
         *
39
         * @param ro: read only parameter - Display mode or update mode
40
         * @param pv: printer version
41
         *
42
         * @return void
43
         */
44
        function display($ro, $pv, $user_id) {
45
            global $art_field_fact,$art_fieldset_fact,$sys_max_size_attachment,$Language;
46
            $hp = Codendi_HTMLPurifier::instance();
47
            $fields_per_line=2;
48
            // the column number is the number of field per line * 2 (label + value)
49
            // + the number of field per line -1 (a blank column between each pair "label-value" to give more space)
50
            $columns_number = ($fields_per_line * 2) + ($fields_per_line - 1);
51
            $max_size=40;
52
            
53
            $group = $this->ArtifactType->getGroup();
54
            $group_artifact_id = $this->ArtifactType->getID();
55
            $group_id = $group->getGroupId();
56
            $result_fields = $art_field_fact->getAllUsedFields();
57
58
            
59
            $result_fieldsets = $art_fieldset_fact->getAllFieldSetsContainingUsedFields();
60
            $summary          = $this->getValue('summary');
61
            
62
            echo '<div id="tracker_toolbar_specific">';
63
            if ($this->ArtifactType->allowsCopy()) {
64
              echo "<A HREF='?func=copy&aid=".(int)$this->getID()."&group_id=".(int)$group_id."&atid=".(int)$group_artifact_id."'><img src=\"".util_get_image_theme("ic/copy.png")."\" />&nbsp;".$Language->getText('tracker_include_artifact','copy_art')."</A>";
65
            }
66
            echo "&nbsp;&nbsp;<A HREF='?func=detail&aid=".(int)$this->getID()."&group_id=".(int)$group_id."&atid=".(int)$group_artifact_id."&pv=1' target='_blank'><img src='".util_get_image_theme("ic/printer.png")."' border='0'>&nbsp;".$Language->getText('global','printer_version')."</A>";
67
            echo '</div>'.PHP_EOL;
68
            echo '<div id="tracker_toolbar_clear"></div>'.PHP_EOL;
69
            
70
            $artTitle = '[ '. $hp->purify($this->ArtifactType->getItemName(), CODENDI_PURIFIER_CONVERT_HTML);
71
            $field_artifact_id = $result_fields['artifact_id'];
72
            if ($field_artifact_id->userCanRead($group_id, $group_artifact_id, $user_id)) {
73
                $artTitle .= " #". $hp->purify($this->getID(), CODENDI_PURIFIER_CONVERT_HTML) ;
74
            }
75
            $artTitle .= ' ] '.$hp->purify(util_unconvert_htmlspecialchars($summary), CODENDI_PURIFIER_CONVERT_HTML);
76
            
77
            // First display some  internal fields 
78
            echo '
79
            <FORM ACTION="" METHOD="POST" enctype="multipart/form-data" NAME="artifact_form">
80
            <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'. $sys_max_size_attachment.'">';
81
            if ( $ro ) {
82
                echo '<INPUT TYPE="HIDDEN" NAME="func" VALUE="postaddcomment">';
83
            } else {
84
                echo '<INPUT TYPE="HIDDEN" NAME="func" VALUE="postmod">';
85
            }
86
            echo '
87
            <INPUT TYPE="HIDDEN" NAME="artifact_timestamp" VALUE="'.time().'">
88
            <INPUT TYPE="HIDDEN" NAME="group_id" VALUE="'.(int)$group_id.'">
89
            <INPUT TYPE="HIDDEN" NAME="group_artifact_id" VALUE="'.(int)$group_artifact_id.'">
90
            <INPUT TYPE="HIDDEN" NAME="atid" VALUE="'.(int)$group_artifact_id.'">
91
            <INPUT TYPE="HIDDEN" NAME="artifact_id" VALUE="'.(int)$this->getID().'">
92
            <INPUT TYPE="HIDDEN" NAME="aid" VALUE="'.(int)$this->getID().'">';
93
            echo '<TABLE><TR><TD class="artifact">';
94
            
95
            $html = '';
96
            $html .= '<TABLE width="100%"><TR>';
97
            $pm = ProjectManager::instance();
98
            
99
            // Now display the variable part of the field list (depend on the project)
100
            
101
            foreach($result_fieldsets as $fieldset_id => $result_fieldset) {
102
                
103
                // this variable will tell us if we have to display the fieldset or not (if there is at least one field to display or not)
104
                $display_fieldset = false;
105
                
106
                $fieldset_html = '';
107
                
108
                $i = 0;
109
                $fields_in_fieldset = $result_fieldset->getAllUsedFields();
110
                while ( list($key, $field) = each($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...
111
                    if ($field->getName() != 'comment_type_id' && $field->getName() != 'artifact_id') {
112
                        $field_html = $this->_getFieldLabelAndValueForUser($group_id, $group_artifact_id, $field, $user_id, $pv);
113
                        if ($field_html) {
114
                            
115
                            // if the user can read at least one field, we can display the fieldset this field is within
116
                            $display_fieldset = true;
117
                            
118
                            list($sz,) = explode("/",$field->getDisplaySize());
119
                        
120
                            // Details field must be on one row
121
                            if ($sz > $max_size || $field->getName()=='details') {
122
                                $fieldset_html .= "\n<TR>".
123
                                  '<TD align="left" valign="top" width="10%" nowrap="nowrap">'. $field_html['label'] .'</td>'.
124
                                  '<TD valign="top" width="90%" colspan="'.($columns_number-1).'">'. $field_html['value'] .'</TD>'.                     
125
                                  "\n</TR>";
126
                                $i=0;
127
                            } else {
128
                                $fieldset_html .= ($i % $fields_per_line ? '':"\n<TR>");
129
                                $fieldset_html .= '<TD align="left" valign="top" width="10%" nowrap="nowrap">'. $field_html['label'] .'</td>'.
130
                                '<TD width="38%" valign="top">'. $field_html['value'] .'</TD>';
131
                                $i++;
132
                                // if the line is not full, we add a additional column to give more space
133
                                $fieldset_html .= ($i % $fields_per_line) ? '<td class="artifact_spacer" width="4%">&nbsp;</td>':"\n</TR>";
134
                            }
135
                        }
136
                    }
137
                } // while
138
                
139
                // We display the fieldset only if there is at least one field inside that we can display
140
                if ($display_fieldset) {
141
                    //$html .= '<TR><TD COLSPAN="'.(int)$columns_number.'">&nbsp</TD></TR>';
142
                    $html .= '<TR class="boxtitle artifact_fieldset"><TD class="left" COLSPAN="'.(int)$columns_number.'">&nbsp;<span title="'. $hp->purify(SimpleSanitizer::unsanitize($result_fieldset->getDescriptionText()), CODENDI_PURIFIER_CONVERT_HTML) .'">'. $hp->purify(SimpleSanitizer::unsanitize($result_fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</span></TD></TR>';
143
                    $html .= $fieldset_html;
144
                }
145
146
            }
147
            
148
            $html .= '<tr><td><font color="red">*</font>: '.
149
                 $Language->getText('tracker_include_type','fields_requ').
150
                 '</td></tr></TABLE>';
151
			
152
			
153
            
154
            echo $this->_getSection(
155
                'artifact_section_details',
156
                $artTitle,
157
                $html,
158
                true
159
            );
160
			
161
            if (!$ro) {
162
                echo '<div style="text-align:center"><INPUT CLASS="btn btn-primary" TYPE="SUBMIT" NAME="SUBMIT" VALUE="'.$Language->getText('tracker_include_artifact','submit').'"></div>';
163
            }
164
            //
165
            // Followups comments
166
            //
167
            $html = '';
168
            $html .= '<script type="text/javascript">';
169
            $html .= "var tracker_comment_togglers = {};
170
            function tracker_reorder_followups() {
171
                var element = $('artifact_section_followups');
172
                if (element) {
173
                    element.cleanWhitespace();
174
                    var elements = [];
175
                    var len = element.childNodes.length;
176
                    for(var i = len - 1 ; i >= 0 ; --i) {
177
                        elements.push(Element.remove(element.childNodes[i]));
178
                    }
179
                    for(var i = 0 ; i < len ; ++i) {
180
                        element.appendChild(elements[i]);
181
                    }
182
                }
183
            }";
184
            $html .= '</script>';
185
            $html .= '<div>';
186
            if ( !$ro ) {
187
                if (db_numrows($this->ArtifactType->getCannedResponses())) {
188
                    $html .= '<p><b>'.$Language->getText('tracker_include_artifact','use_canned').'</b>&nbsp;';
189
                    $html .= $this->ArtifactType->cannedResponseBox ();
190
                    $html .= '</p>';
191
                }
192
                $field = $art_field_fact->getFieldFromName('comment_type_id');
193
                if ( $field && $field->isUsed() && db_numrows($field->getFieldPredefinedValues($group_artifact_id)) > 1) {
194
                    $field_html = new ArtifactFieldHtml( $field );
195
                    $html .= '<P><B>'.$Language->getText('tracker_include_artifact','comment_type').'</B>'.
196
                    $field_html->fieldBox('',$group_artifact_id,$field->getDefaultValue(),true,$Language->getText('global','none')).'<BR>';
197
                }
198
                $html .= '<b>'.$Language->getText('tracker_include_artifact','add_comment').'</b>';
199
                $html .= '<DIV ID="tracker_artifact_comment_label"></DIV>';
200
                $html .= '<TEXTAREA NAME="comment" id="tracker_artifact_comment" ROWS="10" style="width:700px;" WRAP="SOFT"></TEXTAREA>';
201
            } else {
202
                if ($pv == 0) {
203
                    $html .= '<b>'.$Language->getText('tracker_include_artifact','add_comment').'</b>';
204
                    // Non authenticated user can submit only in text format
205
                    //$html .= '<DIV ID="tracker_artifact_comment_label"></DIV>';
206
                    $html .= '<TEXTAREA NAME="comment" id="tracker_artifact_comment" ROWS="10" style="width:700px" WRAP="SOFT"></TEXTAREA>';
207
                }
208
            }
209
            if (!user_isloggedin() && ($pv == 0)) {
210
                $html .= $Language->getText('tracker_include_artifact','not_logged_in','/account/login.php?return_to='.urlencode($_SERVER['REQUEST_URI']));
211
                $html .= '<br><input type="text" name="email" maxsize="100" size="50"/><p>';
212
            }
213
            $html .= '</div>';
214
            $html .=  $this->showFollowUpComments($group_id,$pv);
215
            
216
            $title  = $Language->getText('tracker_include_artifact','follow_ups').' ';
217
            $title .= '<script type="text/javascript">';
218
            $title .= 'document.write(\'<a href="#reorder" onclick="tracker_reorder_followups();new Ajax.Request(\\\'invert_comments_order.php\\\'); return false;" title="Invert order of the follow-ups">[&darr;&uarr;]</a>\');';
219
            $title .= '</script>';
220
            $title .= ' <a href="/tracker/?func=rss&aid='. (int)$this->getId() .'&atid='. (int)$this->ArtifactType->getID() .'&group_id='. (int)$this->ArtifactType->getGroupId() .'" ';
221
            $hp =& Codendi_HTMLPurifier::instance();
222
            $title .= ' title="'. $hp->purify(util_unconvert_htmlspecialchars($group->getPublicName()).' '.SimpleSanitizer::unsanitize($this->ArtifactType->getName()) .' #'. $this->getId() .' - '. util_unconvert_htmlspecialchars($this->getValue('summary')), CODENDI_PURIFIER_CONVERT_HTML) .' - '. $Language->getText('tracker_include_artifact','follow_ups') .'">';
223
            $title .= '[xml]</a> ';
224
            if ($pv == 0) {
225
                $title .= help_button('tracker-v3.html#comments') .' ';
226
            }
227
            echo $this->_getSection(
228
                'artifact_section_followups',
229
                $title,
230
                $html,
231
                true
232
            );
233
            if (user_get_preference('tracker_comment_invertorder')) {
234
                echo '<script type="text/javascript">tracker_reorder_followups();</script>';
235
            }
236
            
237
            //
238
            // CC List
239
            //
240
            $html = '';
241
            if ($pv == 0) {
242
                $html .= $Language->getText('tracker_include_artifact','fill_cc_list_msg');
243
                $html .= $Language->getText('tracker_include_artifact','fill_cc_list_lbl');
244
                $html .= '<textarea type="text" name="add_cc" id="tracker_cc" rows="2" cols="60" wrap="soft"></textarea>';
245
                $html .= '<B>&nbsp;&nbsp;&nbsp;'.$Language->getText('tracker_include_artifact','fill_cc_list_cmt').":&nbsp</b>";
246
                $html .= '<input type="text" name="cc_comment" size="40" maxlength="255">';
247
            }
248
            $html .= $this->showCCList($group_id,$group_artifact_id, false, $pv);
249
            
250
            echo $this->_getSection(
251
                'artifact_section_cc',
252
                $Language->getText('tracker_include_artifact','cc_list').' '. ($pv == 0 ? help_button('tracker-v3.html#cc-list') : ''),
253
                $html,
254
                db_numrows($this->getCCList()),
255
                db_numrows($this->getCCList()) ? '' : '<div>'. $GLOBALS['Language']->getText('tracker_include_artifact','cc_empty') .'</div>'
256
            );
257
                    
258
            //
259
            // File attachments
260
            //
261
            $html = '';
262
            if ($pv == 0) {
263
                $html .= '<input type="file" name="input_file" size="40">';
264
                $html .= $Language->getText('tracker_include_artifact','upload_file_msg',formatByteToMb($sys_max_size_attachment));
265
266
                $html .= $Language->getText('tracker_include_artifact','upload_file_desc');
267
                $html .= '<input type="text" name="file_description" size="60" maxlength="255">';
268
            }
269
            $html .= $this->showAttachedFiles($group_id,$group_artifact_id, false, $pv);
270
            
271
            echo $this->_getSection(
272
                'artifact_section_attachments',
273
                $Language->getText('tracker_include_artifact','attachment').' '. ($pv == 0 ? help_button('tracker-v3.html#artifact-attachments') : ''),
274
                $html,
275
                db_numrows($this->getAttachedFiles()),
276
                db_numrows($this->getAttachedFiles()) ? '' : '<div>'. $GLOBALS['Language']->getText('tracker_include_artifact','no_file_attached') .'</div>'
277
            );
278
			
279
            //
280
            // Artifact dependencies
281
            //
282
            $html = '<B>'.$Language->getText('tracker_include_artifact','depend_on').'</B><BR><P>';
283
            if ( !$ro ) {
284
                    $html .= '
285
                    <B>'.$Language->getText('tracker_include_artifact','aids').'</B>&nbsp;
286
                    <input type="text" name="artifact_id_dependent" size="20" maxlength="255">
287
                    &nbsp;<span style="color:#666">'.$Language->getText('tracker_include_artifact','fill').'</span><p>';
288
            }
289
            $html .=  $this->showDependencies($group_id,$group_artifact_id, false, $pv);
290
            
291
            $html .= '
292
            <P><B>'.$Language->getText('tracker_include_artifact','dependent_on').'</B><BR>
293
            <P>';
294
            $html .= $this->showInverseDependencies($group_id,$group_artifact_id);
295
            echo $this->_getSection(
296
                'artifact_section_dependencies',
297
                $Language->getText('tracker_include_artifact','dependencies').' '.($pv == 0 ? help_button('tracker-v3.html#artifact-dependencies') : ''),
298
                $html,
299
               (db_numrows($this->getDependencies()) || db_numrows($this->getInverseDependencies())),
300
               (db_numrows($this->getDependencies()) || db_numrows($this->getInverseDependencies())) ? '' : '<div>'. $Language->getText('tracker_include_artifact','dep_list_empty') .'</div>'
301
            );
302
            //
303
            // Artifact Cross References
304
            //
305
            $html='';
306
            $crossref_fact= new CrossReferenceFactory($this->getID(), ReferenceManager::REFERENCE_NATURE_ARTIFACT, $group_id);
307
			$crossref_fact->fetchDatas();
308
            $html.=$crossref_fact->getHTMLDisplayCrossRefs();
309
            echo $this->_getSection(
310
                'artifact_section_references',
311
                $Language->getText('cross_ref_fact_include','references').' '.($pv == 0 ? help_button('tracker-v3.html#artifact-cross-referencing') : ''),
312
                $html,
313
                $crossref_fact->getNbReferences(),
314
                $crossref_fact->getNbReferences() ? '' : '<div>'. $Language->getText('tracker_include_artifact','ref_list_empty') .'</div>'
315
            );
316
            
317
            //
318
            // Artifact permissions
319
            //
320
            if ($this->ArtifactType->userIsAdmin()) {
321
                $checked = '';
322
                if ($this->useArtifactPermissions()) {
323
                    $checked = 'checked="checked"';
324
                }
325
                $html = '';
326
                $html .= '<p>';
327
                $html .= '<label class="checkbox" for="use_artifact_permissions"><input type="hidden" name="use_artifact_permissions_name" value="0" />';
328
                $html .= '<input type="checkbox" name="use_artifact_permissions_name" id="use_artifact_permissions" value="1" '. $checked .' />';
329
                $html .= $GLOBALS['Language']->getText('tracker_include_artifact', 'permissions_label') .'</label>';
330
                $html .= '</p>';
331
                $html .= permission_fetch_selection_field('TRACKER_ARTIFACT_ACCESS', $this->getId(), $group_id);
332
                $html .= '<script type="text/javascript">';
333
                $html .= "
334
                document.observe('dom:loaded', function() {
335
                    if ( ! $('use_artifact_permissions').checked) {
336
                        $('ugroups').disable();
337
                    }
338
                    $('use_artifact_permissions').observe('click', function(evt) {
339
                        if (this.checked) {
340
                            $('ugroups').enable();
341
                        } else {
342
                            $('ugroups').disable();
343
                        }
344
                    });
345
                });
346
                </script>";
347
                echo $this->_getSection(
348
                    'artifact_section_permissions',
349
                    $Language->getText('tracker_include_artifact','permissions').' '.($pv == 0 ? help_button('tracker-v3.html#permissions-on-artifacts') : ''),
350
                    $html,
351
                    $checked,
352
                    ($checked ? '' : $GLOBALS['Language']->getText('tracker_include_artifact', 'permissions_not_restricted'))
353
                );
354
            }
355
            
356
            //
357
            // History
358
            //
359
            $is_there_history = db_numrows($this->getHistory());
360
            echo $this->_getSection(
361
                'artifact_section_history', 
362
                $Language->getText('tracker_include_artifact','change_history').' '.($pv == 0 ? help_button('tracker-v3.html#artifact-history') : ''),
363
                $this->showHistory($group_id,$group_artifact_id),
364
                !$is_there_history
365
            );
366
            
367
            // 
368
            // Final submit button
369
            //
370
            if ( $pv == 0) {
371
                echo '<div style="text-align:center"><INPUT CLASS="btn btn-primary" TYPE="SUBMIT" NAME="SUBMIT" VALUE="'.$Language->getText('tracker_include_artifact','submit').'"></div>';
372
            }
373
            echo '</td></tr>';
374
            echo '</table>';
375
            echo '</form>';
376
            user_set_preference('tracker_'. $this->ArtifactType->getId() .'_artifact_'. $this->getId() .'_last_visit', time());
377
        }
378
        
379
        /**
380
        * _getSection
381
        * 
382
        * Display an html toggable fieldset
383
        *
384
        * @param  title  
385
        * @param  content  
386
        * @param  help  
387
        */
388
        function _getSection($id, $title, $content, $is_open, $alternate_text = '') {
389
            $html =  '<fieldset><legend id="'.$id.'_legend">';
390
            if ($is_open) {
391
                $sign = 'minus';
392
                $display = '';
393
            } else {
394
                $sign = 'plus';
395
                $display = 'display:none;';
396
            }
397
            $html .= $GLOBALS['HTML']->getImage(
398
                'ic/toggle_'. $sign .'.png', 
399
                array(
400
                    'border' => 0, 
401
                    'id'     => $id.'_toggle', 
402
                    'style'  => 'cursor:hand; cursor:pointer', 
403
                    'title'  => $GLOBALS['Language']->getText('tracker_include_artifact', 'toggle')
404
                )
405
            );
406
            $html .= ' '.$title .'</legend><div id="'. $id .'_alternate" style="display:none;"></div>';
407
            $html .= '<script type="text/javascript">';
408
            $html .= "Event.observe($('". $id ."_toggle'), 'click', function (evt) {
409
                var element = $('$id');
410
                if (element) {
411
                    Element.toggle(element);
412
                    Element.toggle($('". $id ."_alternate'));
413
                    
414
                    //replace image
415
                    var src_search = 'toggle_minus';
416
                    var src_replace = 'toggle_plus';
417
                    if ($('". $id ."_toggle').src.match('toggle_plus')) {
418
                        src_search = 'toggle_plus';
419
                        src_replace = 'toggle_minus';
420
                    }
421
                    $('". $id ."_toggle').src = $('". $id ."_toggle').src.replace(src_search, src_replace);
422
                }
423
                Event.stop(evt);
424
                return false;
425
            });
426
            $('". $id ."_alternate').update('". addslashes($alternate_text) ."');
427
            ";
428
            if (!$is_open) {
429
                $html .= "Element.show($('". $id ."_alternate'));";
430
            }
431
            $html .= '</script>';
432
            $html .= '<div id="'. $id .'" style="'. $display .'">'. $content .'</div></fieldset>';
433
            return $html;
434
        }
435
        
436
        
437
        /**
438
         * return a field for the given user.
439
         * 
440
         * @protected
441
        **/
442
        function _getFieldLabelAndValueForUser($group_id, $group_artifact_id, &$field, $user_id, $force_read_only = false) {
443
            $html = false;
444
            if ($field->userCanRead($group_id, $group_artifact_id, $user_id)) {
445
                $read_only =  $force_read_only || !$field->userCanUpdate($group_id, $group_artifact_id, $user_id);
446
                
447
                // For multi select box, we need to retrieve all the values
448
                if ( $field->isMultiSelectBox() ) {
449
                        $field_value = $field->getValues($this->getID());
450
                } else {
451
                        $field_value = $this->getValue($field->getName());
452
                }
453
                
454
                $field_html  = new ArtifactFieldHtml($field);
455
                $label       = $field_html->labelDisplay(false,false,!$read_only);
456
                $label      .= ($field->isEmptyOk() ? '':'<span class="highlight"><big>*</big></b></span>');
457
                
458
                // original submission field must be displayed read-only,
459
                // except for site admin, tracker admin and for the artifact submitter
460
                if ($field->getName()=='details') {
461
                    if (user_is_super_user() || $this->ArtifactType->userIsAdmin() || $this->getSubmittedBy()==$user_id ) {
462
                        // original submission is editable
463
                        $value = $field_html->display($this->ArtifactType->getID(),$field_value,false,false,$read_only);
464
                    } else {
465
                        $value = util_make_links($field_html->display($this->ArtifactType->getID(),$field_value,false,false,true),$group_id, $group_artifact_id);
466
                    }
467
                } else if ($field->getName() == 'submitted_by') {
468
                    $value = util_user_link(user_getname($field_value));
469
                } else if ($field->getName() == 'open_date') {
470
                    $value = format_date($GLOBALS['Language']->getText('system', 'datefmt'),$field_value);
471
                } else if ($field->getName() == 'last_update_date') {
472
                	$value = format_date($GLOBALS['Language']->getText('system', 'datefmt'),$field_value);    
473
                } else {
474
                    $value = $field_html->display($this->ArtifactType->getID(),$field_value,false,false,$read_only);
475
                    if ($read_only) $value = util_make_links($value,$group_id, $group_artifact_id);
476
                }
477
                
478
                $html = array('label' => $label, 'value' => $value);
479
            }
480
            return $html;
481
        }
482
483
    /**
484
     * Display the artifact
485
     *
486
     * @param ro: read only parameter - Display mode or update mode
487
     * @param pv: printer version
488
     *
489
     * @return void
490
     */
491
    function displayCopy($ro,$pv) {
492
        global $art_field_fact,$art_fieldset_fact,$sys_max_size_attachment,$Language;
493
        $hp = Codendi_HTMLPurifier::instance();
494
        $fields_per_line=2;
495
        // the column number is the number of field per line * 2 (label + value)
496
        // + the number of field per line -1 (a blank column between each pair "label-value" to give more space)
497
        $columns_number = ($fields_per_line * 2) + ($fields_per_line - 1);
498
        $max_size=40;
499
          
500
        $group = $this->ArtifactType->getGroup();
501
        $group_artifact_id = $this->ArtifactType->getID();
502
        $group_id = $group->getGroupId();
503
        $result_fields = $art_field_fact->getAllUsedFields();
504
        $result_fieldsets = $art_fieldset_fact->getAllFieldSetsContainingUsedFields();
505
            
506
        
507
        // Display submit informations if any
508
        if ( $this->ArtifactType->getSubmitInstructions() ) {
509
            echo  $hp->purify(util_unconvert_htmlspecialchars($this->ArtifactType->getSubmitInstructions()), CODENDI_PURIFIER_FULL) ;
510
        }
511
        
512
        // Beginning of the submission form with fixed fields
513
        echo '<FORM ACTION="" METHOD="POST" enctype="multipart/form-data" NAME="artifact_form">
514
                <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.$sys_max_size_attachment.'">
515
                <INPUT TYPE="HIDDEN" NAME="func" VALUE="postcopy">
516
                <INPUT TYPE="HIDDEN" NAME="group_id" VALUE="'.(int)$group_id.'">
517
                <INPUT TYPE="HIDDEN" NAME="group_artifact_id" VALUE="'.(int)$group_artifact_id.'">
518
                <INPUT TYPE="HIDDEN" NAME="atid" VALUE="'.(int)$group_artifact_id.'">';
519
        echo '<TABLE><TR><TD class="artifact">';
520
        $summary = $this->getValue('summary');
521
          
522
        echo "<TABLE width='100%'><TR><TD>";
523
        echo "<H2>[ ". $hp->purify($Language->getText('tracker_include_artifact','copy_of',$this->ArtifactType->getItemName()." #".$this->getID())." ] ".$summary, CODENDI_PURIFIER_CONVERT_HTML) ."</H2>";
524
        echo "</TD></TR></TABLE>";
525
          
526
        $html = '';
527
        $pm = ProjectManager::instance();
528
        $html .= '
529
            <table width="100%">
530
              <tr><td colspan="'.(int)$columns_number.'"><B>'.$Language->getText('tracker_include_artifact','group').':</B>&nbsp;'. $hp->purify(util_unconvert_htmlspecialchars($pm->getProject($group_id)->getPublicName()), CODENDI_PURIFIER_CONVERT_HTML) .'</TD></tr>';
531
        
532
        // Now display the variable part of the field list (depend on the project)
533
        
534
        foreach($result_fieldsets as $fieldset_id => $result_fieldset) {
535
                
536
            // this variable will tell us if we have to display the fieldset or not (if there is at least one field to display or not)
537
            $display_fieldset = false;
538
            
539
            $fieldset_html = '';
540
            
541
            $i = 0;
542
            $fields_in_fieldset = $result_fieldset->getAllUsedFields();
543
            
544
            while ( list($key, $field) = each($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...
545
    
546
                $field_html = new ArtifactFieldHtml($field);
547
                //echo $field_html->dumpStandard()."<br>";
548
                    
549
                // if the field is a special field (except summary and details) 
550
                // then skip it.
551
                if ( $field->userCanSubmit($group_id, $group_artifact_id) && (!$field->isSpecial() || $field->getName()=='summary' || $field->getName()=='details' )) {
552
                  
553
                    // display the artifact field
554
                    // if field size is greatest than max_size chars then force it to
555
                    // appear alone on a new line or it won't fit in the page
556
                    
557
                    $display_fieldset = true;
558
                    
559
                    // For multi select box, we need to retrieve all the values
560
                    if ( $field->isMultiSelectBox() ) {
561
                        $field_value = $field->getValues($this->getID());
562
                    } else {
563
                        if ($field->getName()=='summary') {
564
                            $field_value = '['.$Language->getText('tracker_include_artifact','copy').'] '.$this->getValue($field->getName());
565
                        } else {
566
                            $field_value = $this->getValue($field->getName());
567
                        }
568
                    }
569
                          
570
                    list($sz,) = explode("/",$field->getDisplaySize());
571
                    $label = $field_html->labelDisplay(false,false,!$ro);
572
                    $value = $field_html->display($this->ArtifactType->getID(),$field_value,false,false,$ro);
573
                          
574
                    $star = ($field->isEmptyOk() ? '':'<span class="highlight"><big>*</big></b></span>');
575
                          
576
                    // Details field must be on one row
577
                    if ($sz > $max_size || $field->getName()=='details') {
578
                        $fieldset_html .= "\n<TR>".
579
                        '<TD valign="middle">'.$label.$star.'</td>'.
580
                        '<TD valign="middle" colspan="'.($columns_number-1).'">'.
581
                        $value.'</TD>'.                     
582
                        "\n</TR>";
583
                        $i=0;
584
                    } else {
585
                        $fieldset_html .= ($i % $fields_per_line ? '':"\n<TR>");
586
                        $fieldset_html .= '<TD valign="middle">'.$label.$star.'</td>'.
587
                        '<TD valign="middle">'.$value.'</TD>';
588
                        $i++;
589
                        $fieldset_html .= ($i % $fields_per_line ? '<td class="artifact_spacer">&nbsp;</td>':"\n</TR>");
590
                    }
591
                }
592
            } // while
593
            
594
            // We display the fieldset only if there is at least one field inside that we can display
595
            if ($display_fieldset) {
596
                $html .= '<TR><TD COLSPAN="'. (int)$columns_number.'">&nbsp</TD></TR>';
597
                $html .= '<TR class="boxtitle"><TD class="left" COLSPAN="'. (int)$columns_number.'">&nbsp;<span title="'. $hp->purify(SimpleSanitizer::unsanitize($result_fieldset->getDescriptionText()), CODENDI_PURIFIER_CONVERT_HTML) .'">'. $hp->purify(SimpleSanitizer::unsanitize($result_fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</span></TD></TR>';
598
                $html .= $fieldset_html;
599
            }
600
            
601
        }
602
        
603
        $html .= '</TABLE>';
604
        
605
        echo $this->_getSection(
606
            'artifact_section_details',
607
            $Language->getText('tracker_include_artifact','details'),
608
            $html,
609
            true
610
        );
611
        
612
        //
613
        // Followups comments
614
        //
615
        $html = '';
616
        $html .= '<div>';
617
        if ( !$ro ) {
618
            if (db_numrows($this->ArtifactType->getCannedResponses())) {
619
                $html .= '<p><b>'.$Language->getText('tracker_include_artifact','use_canned').'</b>&nbsp;';
620
                $html .= $this->ArtifactType->cannedResponseBox ();
621
                $html .= '</p>';
622
            }
623
            $field = $art_field_fact->getFieldFromName('comment_type_id');
624
            if ( $field && $field->isUsed() && db_numrows($field->getFieldPredefinedValues($group_artifact_id)) > 1) {
625
                $field_html = new ArtifactFieldHtml( $field );
626
                $html .= '<P><B>'.$Language->getText('tracker_include_artifact','comment_type').'</B>'.
627
                $field_html->fieldBox('',$group_artifact_id,$field->getDefaultValue(),true,$Language->getText('global','none')).'<BR>';
628
            }
629
            // This div id used just to show the toggle of html format
630
            $html .= '<DIV ID="follow_up_comment_label"></DIV>';
631
            $html .= '<TEXTAREA NAME="follow_up_comment" id="tracker_artifact_comment" ROWS="10" style="width:700px;" WRAP="SOFT">';
632
            $html .=  $hp->purify($Language->getText('tracker_include_artifact','is_copy',array($this->ArtifactType->getItemName(),$this->ArtifactType->getItemName().' #'.$this->getID())), CODENDI_PURIFIER_CONVERT_HTML) ;
633
            $html .= '</TEXTAREA>';
634
        } else {
635
            if ($pv == 0) {
636
                $html .= '<b>'.$Language->getText('tracker_include_artifact','add_comment').'</b>';
637
                $html .= '<DIV ID="follow_up_comment_label"></DIV>';
638
                $html .= '<TEXTAREA NAME="follow_up_comment" id="tracker_artifact_comment" ROWS="10" style="width:700px;" WRAP="SOFT">'. $hp->purify($Language->getText('tracker_include_artifact','is_copy',array($this->ArtifactType->getItemName(),$this->ArtifactType->getItemName().' #'.$this->getID())), CODENDI_PURIFIER_CONVERT_HTML) .'</TEXTAREA>';
639
            }
640
        }
641
        if (!user_isloggedin() && ($pv == 0)) {
642
            $html .= $Language->getText('tracker_include_artifact','not_logged_in','/account/login.php?return_to='.urlencode($_SERVER['REQUEST_URI']));
643
            $html .= '<br><input type="text" name="email" maxsize="100" size="50"/><p>';
644
        }
645
        $html .= '</div>';
646
        $html .= "<br />";
647
        
648
        $title  = $Language->getText('tracker_include_artifact','follow_ups').' ';
649
        $title .= help_button('tracker-v3.html#comments');
650
        echo $this->_getSection(
651
            'artifact_section_followups',
652
            $title,
653
            $html,
654
            true
655
        );
656
657
        
658
        //
659
        // CC List
660
        //
661
        $html = '';
662
        $html .= $Language->getText('tracker_include_artifact','fill_cc_list_msg');
663
        $html .= $Language->getText('tracker_include_artifact','fill_cc_list_lbl');
664
        $html .= '<textarea type="text" name="add_cc" id="tracker_cc" rows="2" cols="60" wrap="soft"></textarea>';
665
        $html .= '<B>&nbsp;&nbsp;&nbsp;'.$Language->getText('tracker_include_artifact','fill_cc_list_cmt').":&nbsp</b>";
666
        $html .= '<input type="text" name="cc_comment" size="40" maxlength="255">';
667
        
668
        echo $this->_getSection(
669
            'artifact_section_cc',
670
            $Language->getText('tracker_include_artifact','cc_list').' '. help_button('tracker-v3.html#cc-list'),
671
            $html,
672
            true
673
        );
674
                
675
        //
676
        // File attachments
677
        //
678
        $html = '';
679
        $html .= '<input type="file" name="input_file" size="40">';
680
        $html .= $Language->getText('tracker_include_artifact','upload_file_msg',formatByteToMb($sys_max_size_attachment));
681
682
        $html .= $Language->getText('tracker_include_artifact','upload_file_desc');
683
        $html .= '<input type="text" name="file_description" size="60" maxlength="255">';
684
        
685
        echo $this->_getSection(
686
            'artifact_section_attachments',
687
            $Language->getText('tracker_include_artifact','attachment').' '. help_button('tracker-v3.html#artifact-attachments'),
688
            $html,
689
            true
690
        );
691
        
692
        //
693
        // Artifact dependencies
694
        //
695
        $html = '
696
        <P><B>'.$Language->getText('tracker_include_artifact','dependent_on').'</B><BR>
697
        <P>';
698
        if ( !$ro ) {
699
        $html .= '
700
                        <B>'.$Language->getText('tracker_include_artifact','aids').'</B>&nbsp;
701
                        <input type="text" name="artifact_id_dependent" size="20" maxlength="255" value="'. (int)$this->getID().'">
702
                        &nbsp;<span style="color:#666">'.$Language->getText('tracker_include_artifact','fill').'</span><p>';
703
        }
704
        
705
        echo $this->_getSection(
706
            'artifact_section_dependencies',
707
            $Language->getText('tracker_include_artifact','dependencies').' '.help_button('tracker-v3.html#artifact-dependencies'),
708
            $html,
709
            true
710
        );
711
712
        //
713
        // Final submit button
714
        //
715
        echo '<p><B><span class="highlight">'.$Language->getText('tracker_include_artifact','check_already_submitted').'</b></p>';
716
        echo '<div style="text-align:center"><INPUT CLASS="btn btn-primary" TYPE="SUBMIT" NAME="SUBMIT" VALUE="'.$Language->getText('tracker_include_artifact','submit').'"></div>';
717
        echo '</td></tr>';
718
        echo '</table>';
719
        echo '</form>';
720
    }
721
722
	
723
        /**
724
         * Display the history
725
         *
726
         * @param group_id: the group id
727
         * @param group_artifact_id: the artifact type ID
728
         *
729
         * @return void
730
         */
731
        function showHistory ($group_id,$group_artifact_id) {
732
            //
733
                //      show the artifact_history rows that are relevant to this artifact_id, excluding comment (follow-up comments)
734
                //
735
            global $art_field_fact,$sys_lf,$Language;
736
            $result=$this->getHistory();
737
            $rows=db_numrows($result);
738
            $html = '';
739
            $hp = Codendi_HTMLPurifier::instance();
740
            $uh = UserHelper::instance();
741
            $um = UserManager::instance();
742
            if ($rows > 0) {
743
        
744
                        $title_arr=array();
745
                        $title_arr[]=$Language->getText('tracker_include_artifact','field');
746
                        $title_arr[]=$Language->getText('tracker_include_artifact','old_val');
747
                        $title_arr[]=$Language->getText('tracker_include_artifact','new_val');
748
                        $title_arr[]=$Language->getText('tracker_import_utils','date');
749
                        $title_arr[]=$Language->getText('global','by');
750
                
751
                        $html .= html_build_list_table_top ($title_arr);
752
                
753
                        for ($i=0; $i < $rows; $i++) {
754
                            $field_name = db_result($result, $i, 'field_name');
755
                            $value_id_new =  db_result($result, $i, 'new_value');
756
			    //if (preg_match("/^(lbl_)/",$field_name) && preg_match("/(_comment)$/",$field_name) && $value_id_new == "") {
757
			    //    //removed followup comment is not recorded
758
				//    $value_id_old = $Language->getText('tracker_include_artifact','flup_hidden');
759
			    //} else {
760
			          $value_id_old =  db_result($result, $i, 'old_value');
761
                //}
762
                            
763
                            $field = $art_field_fact->getFieldFromName($field_name);
764
                            if ( $field ) {
765
                                if ($field->userCanRead($group_id,$group_artifact_id)) {
766
                                    $html .= "\n".'<TR class="'. util_get_alt_row_color($i) .
767
                                        '"><TD>'. $hp->purify(SimpleSanitizer::unsanitize($field->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</TD><TD>';
768
                        
769
                                    if ($field->isSelectBox()) {
770
                                        // It's a select box look for value in clear
771
                                        $html .= $field->getValue($group_artifact_id, $value_id_old).'</TD><TD>';
772
                                        $html .= $field->getValue($group_artifact_id, $value_id_new);
773
                                    } else if ($field->isDateField()) {
774
                                        // For date fields do some special processing
775
                                        $html .= format_date("Y-m-j",$value_id_old).'</TD><TD>';
776
                                        
777
                                        $html .= format_date("Y-m-j",$value_id_new);
778
779
                                    } else if ($field->isFloat() ) {
780
                                        $html .= number_format($value_id_old,2).'</TD><TD>';
781
                                        $html .= number_format($value_id_new,2);
782
                                    } else {
783
                                        // It's a text zone then display directly
784
                                        $html .=  $hp->purify(util_unconvert_htmlspecialchars($value_id_old), CODENDI_PURIFIER_CONVERT_HTML) .'</TD><TD>';
785
                                        $html .= $hp->purify($value_id_new, CODENDI_PURIFIER_CONVERT_HTML);
786
                                    }
787
                                    
788
                                    $user = $um->getUserByUserName(db_result($result, $i, 'user_name'));
789
                                    $html .= '</TD>'.
790
                                        '<TD>'.format_date($GLOBALS['Language']->getText('system', 'datefmt'),db_result($result, $i, 'date')).'</TD>'.
791
                                        '<TD>'.$uh->getLinkOnUser($user).'</TD></TR>';
792
                                }
793
                            } else {
794
                                $user  = $um->getUserByUserName(db_result($result, $i, 'user_name'));
795
                                $html .= "\n".'<TR class="'. util_get_alt_row_color($i) .
796
                                                    '"><TD>'. $hp->purify(((preg_match("/^(lbl_)/",$field_name) && preg_match("/(_comment)$/",$field_name)) ? "Comment #".((int)substr($field_name,4,-8)) : $field_name), CODENDI_PURIFIER_CONVERT_HTML) .'</TD><TD>';
797
                                $html .=  $hp->purify(util_unconvert_htmlspecialchars($value_id_old), CODENDI_PURIFIER_CONVERT_HTML) .'</TD><TD>';
798
                                $html .=  $hp->purify(util_unconvert_htmlspecialchars($value_id_new), CODENDI_PURIFIER_CONVERT_HTML) ;
799
                                $html .= '</TD>'.
800
                                        '<TD>'.format_date($GLOBALS['Language']->getText('system', 'datefmt'),db_result($result, $i, 'date')).'</TD>'.
801
                                        '<TD>'.$uh->getLinkOnUser($user).'</TD></TR>';
802
                            }
803
                        }
804
                $html .= '</TABLE>';
805
            
806
            } else {
807
                $html .= "\n".$Language->getText('tracker_include_artifact','no_changes').'</H4>';
808
            }
809
            return $html;
810
        }
811
812
        /**
813
         * Display the artifact inverse dependencies list
814
         *
815
         * @param group_id: the group id
816
         * @param group_artifact_id: the artifact type ID
817
         * @param ascii: ascii mode
818
         *
819
         * @return void
820
         */
821
        function showInverseDependencies ($group_id, $group_artifact_id, $ascii=false) {
822
            $hp = Codendi_HTMLPurifier::instance();
823
            global $sys_lf,$Language;
824
        
825
            //
826
            //      format the dependencies list for this artifact
827
            //
828
        
829
            $result=$this->getInverseDependencies();
830
            $rows=db_numrows($result);
831
            $out = '';
832
            
833
            // Nobody in the dependencies list -> return now
834
            if ($rows <= 0) {
835
                        if ($ascii)
836
                            $out = $Language->getText('tracker_include_artifact','no_depend')."$sys_lf";
837
                        else
838
                            $out = '<H4>'.$Language->getText('tracker_include_artifact','no_depend').'</H4>';
839
                        return $out;
840
            }
841
        
842
            // Header first an determine what the print out format is
843
            // based on output type (Ascii, HTML)
844
            if ($ascii) {
845
		$out .= $Language->getText('tracker_include_artifact','dep_list').$sys_lf.str_repeat("*",strlen($Language->getText('tracker_include_artifact','dep_list')))."$sys_lf$sys_lf";
846
                        $fmt = "%-15s | %s (%s)$sys_lf";
847
                        $out .= sprintf($fmt, 
848
                                        $Language->getText('tracker_include_artifact','artifact'), 
849
                                        $Language->getText('tracker_include_artifact','summary'),
850
                                        $Language->getText('global','status')
851
                        );
852
                        $out .= "------------------------------------------------------------------$sys_lf";
853
            } else {    
854
        
855
                        $title_arr=array();
856
                        $title_arr[]=$Language->getText('tracker_include_artifact','artifact');
857
                        $title_arr[]=$Language->getText('tracker_include_artifact','summary');
858
                        $title_arr[]=$Language->getText('global','status');
859
                        $title_arr[]=$Language->getText('tracker_import_admin','tracker');
860
                        $title_arr[]=$Language->getText('tracker_include_artifact','group');
861
                        $out .= html_build_list_table_top ($title_arr);
862
                
863
                        $fmt = "\n".'<TR class="%s"><td>%s</td><td>%s</td><td align="center">%s</td>'.
864
                            '<td align="center">%s</td><td align="center">%s</td></tr>';
865
                }
866
                
867
            // Loop through the denpendencies and format them
868
            for ($i=0; $i < $rows; $i++) {
869
        
870
                        $dependent_on_artifact_id = db_result($result, $i, 'artifact_id');
871
                        $summary = db_result($result, $i, 'summary');
872
                        $status = db_result($result, $i, 'status');
873
                        $tracker_label = db_result($result, $i, 'name');
874
                        $group_label = db_result($result, $i, 'group_name');
875
                
876
                        if ($ascii) {
877
                            $out .= sprintf($fmt, $dependent_on_artifact_id, $summary, $status);
878
                        } else {
879
                
880
                            $out .= sprintf($fmt,
881
                                            util_get_alt_row_color($i),
882
                                            '<a href="/tracker/?func=gotoid&group_id='. (int)$group_id .'&aid='. (int)$dependent_on_artifact_id .'">'. (int)$dependent_on_artifact_id .'</a>',
883
                                             $hp->purify(util_unconvert_htmlspecialchars($summary), CODENDI_PURIFIER_CONVERT_HTML) ,
884
                                             $hp->purify($status, CODENDI_PURIFIER_CONVERT_HTML) ,
885
                                             $hp->purify(SimpleSanitizer::unsanitize($tracker_label), CODENDI_PURIFIER_CONVERT_HTML) ,
886
                                             $hp->purify(util_unconvert_htmlspecialchars($group_label), CODENDI_PURIFIER_CONVERT_HTML) );
887
                        
888
                        } // for
889
            }
890
        
891
            // final touch...
892
            $out .= ($ascii ? "$sys_lf" : "</TABLE>");
893
        
894
            return($out);
895
        
896
        }
897
898
        
899
    function displayAdd($user_id) {
900
        global $art_field_fact,$art_fieldset_fact,$sys_max_size_attachment,$Language;
901
        $hp = Codendi_HTMLPurifier::instance();
902
        
903
        $fields_per_line=2;
904
        // the column number is the number of field per line * 2 (label + value)
905
        // + the number of field per line -1 (a blank column between each pair "label-value" to give more space)
906
        $columns_number = ($fields_per_line * 2) + ($fields_per_line - 1);
907
        $max_size = 40;
908
        
909
        $group = $this->ArtifactType->getGroup();
910
        $group_artifact_id = $this->ArtifactType->getID();
911
        $group_id = $group->getGroupId();
912
        
913
        $result_fieldsets = $art_fieldset_fact->getAllFieldSetsContainingUsedFields();
914
        
915
        // Display submit informations if any
916
        if ( $this->ArtifactType->getSubmitInstructions() ) {
917
            echo  $hp->purify(util_unconvert_htmlspecialchars($this->ArtifactType->getSubmitInstructions()), CODENDI_PURIFIER_FULL) ;
918
        }
919
        
920
        // Beginning of the submission form with fixed fields
921
        echo '<FORM ACTION="" METHOD="POST" enctype="multipart/form-data" NAME="artifact_form">
922
                <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.$sys_max_size_attachment.'">
923
                <INPUT TYPE="HIDDEN" NAME="func" VALUE="postadd">
924
                <INPUT TYPE="HIDDEN" NAME="group_id" VALUE="'.(int)$group_id.'">
925
                <INPUT TYPE="HIDDEN" NAME="atid" VALUE="'.(int)$group_artifact_id.'">';
926
        echo '<TABLE><TR><TD class="artifact">';
927
        $pm = ProjectManager::instance();
928
929
        $html = '';
930
        $html .= '  <TABLE width="100%">
931
                <TR><TD VALIGN="TOP" COLSPAN="'.($columns_number).'">
932
                          <B>'.$Language->getText('tracker_include_artifact','group').':</B>&nbsp;'. $hp->purify(util_unconvert_htmlspecialchars($pm->getProject($group_id)->getPublicName()), CODENDI_PURIFIER_CONVERT_HTML) .'</TD></TR>';
933
        
934
                         
935
                         
936
        // Now display the variable part of the field list (depend on the project)
937
        
938
        foreach($result_fieldsets as $fieldset_id => $result_fieldset) {
939
            
940
            // this variable will tell us if we have to display the fieldset or not (if there is at least one field to display or not)
941
            $display_fieldset = false;
942
            
943
            $fieldset_html = '';
944
            
945
            $i = 0;
946
            $fields_in_fieldset = $result_fieldset->getAllUsedFields();
947
            while ( list($key, $field) = each($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...
948
949
                $field_html = new ArtifactFieldHtml($field);
950
        
951
                // if the field is a special field (except summary and original description)
952
                // or if not used by this project  then skip it. 
953
                // Plus only show fields allowed on the artifact submit_form 
954
                if ( (!$field->isSpecial() || $field->getName()=='summary' || $field->getName()=='details') ) {
955
                    if ($field->userCanSubmit($group_id, $group_artifact_id, $user_id)) {                                    
956
                        // display the artifact field with its default value
957
                        // if field size is greatest than max_size chars then force it to
958
                        // appear alone on a new line or it won't fit in the page
959
    
960
                        // if the user can submit at least one field, we can display the fieldset this field is within
961
                        $display_fieldset = true;
962
                        
963
                        $field_value = $field->getDefaultValue();
964
                        list($sz,) = $field->getGlobalDisplaySize();
965
                        $label = $field_html->labelDisplay(false,false,true);
966
                        $value = $field_html->display($group_artifact_id,$field_value,false,false);
967
                        $star = ($field->isEmptyOk() ? '':'<span class="highlight"><big>*</big></b></span>');
968
    
969
                        if ( ($sz > $max_size) || ($field->getName()=='details') ) {
970
                            $fieldset_html .= "\n<TR>".
971
                            '<TD valign="top"><a class="artifact_field_tooltip" href="#" title="'. $hp->purify(SimpleSanitizer::unsanitize($field->getDescription()), CODENDI_PURIFIER_CONVERT_HTML) .'">'.$label.$star.'</a></td>'.
972
                                '<TD valign="middle" colspan="'.($columns_number-1).'">'.
973
                                $value.'</TD>'.                   
974
                                "\n</TR>";
975
                            $i=0;
976
                        } else {
977
                            $fieldset_html .= ($i % $fields_per_line ? '':"\n<TR>");
978
                            $fieldset_html .= '<TD valign="middle"><a class="artifact_field_tooltip" href="#" title="'. $hp->purify(SimpleSanitizer::unsanitize($field->getDescription()), CODENDI_PURIFIER_CONVERT_HTML) .'">'.$label.$star.'</a></td>'.
979
                                  '<TD valign="middle">'.$value.'</TD>';
980
                            $i++;
981
                            $fieldset_html .= ($i % $fields_per_line ? '<td class="artifact_spacer">&nbsp;</td>':"\n</TR>");
982
                        }
983
                    }
984
                }
985
            } // while
986
            
987
            // We display the fieldset only if there is at least one field inside that we can display
988
            if ($display_fieldset) {
989
                $html .= '<TR><TD COLSPAN="'.(int)$columns_number.'">&nbsp</TD></TR>';
990
                $html .= '<TR class="boxtitle"><TD class="left" COLSPAN="'.(int)$columns_number.'">&nbsp;<span title="'. $hp->purify(SimpleSanitizer::unsanitize($result_fieldset->getDescriptionText()), CODENDI_PURIFIER_CONVERT_HTML) .'">'. $hp->purify(SimpleSanitizer::unsanitize($result_fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) .'</span></TD></TR>';
991
                $html .= $fieldset_html;
992
            }
993
            
994
        }
995
            
996
        $html .= '</TABLE>';
997
        
998
        echo $this->_getSection(
999
            'artifact_section_details',
1000
            $Language->getText('tracker_include_artifact','details'),
1001
            $html,
1002
            true
1003
        );
1004
        
1005
        //
1006
        // CC List
1007
        //
1008
        $html = '';
1009
        $html .= $Language->getText('tracker_include_artifact','fill_cc_list_msg');
1010
        $html .= $Language->getText('tracker_include_artifact','fill_cc_list_lbl');
1011
        $html .= '<textarea type="text" name="add_cc" id="tracker_cc" rows="2" cols="60" wrap="soft"></textarea>';
1012
        $html .= '<B>&nbsp;&nbsp;&nbsp;'.$Language->getText('tracker_include_artifact','fill_cc_list_cmt').":&nbsp</b>";
1013
        $html .= '<input type="text" name="cc_comment" size="40" maxlength="255">';
1014
        
1015
        echo $this->_getSection(
1016
            'artifact_section_cc',
1017
            $Language->getText('tracker_include_artifact','cc_list').' '. help_button('tracker-v3.html#cc-list'),
1018
            $html,
1019
            true
1020
        );
1021
                
1022
        //
1023
        // File attachments
1024
        //
1025
        $html = '';
1026
        $html .= '<input type="file" name="input_file" size="40">';
1027
        $html .= $Language->getText('tracker_include_artifact','upload_file_msg',formatByteToMb($sys_max_size_attachment));
1028
1029
        $html .= $Language->getText('tracker_include_artifact','upload_file_desc');
1030
        $html .= '<input type="text" name="file_description" size="60" maxlength="255">';
1031
        
1032
        echo $this->_getSection(
1033
            'artifact_section_attachments',
1034
            $Language->getText('tracker_include_artifact','attachment').' '. help_button('tracker-v3.html#artifact-attachments'),
1035
            $html,
1036
            true
1037
        );
1038
        
1039
        //
1040
        // Artifact permissions
1041
        //
1042
        if ($this->ArtifactType->userIsAdmin()) {
1043
            $checked = '';
1044
            if ($this->useArtifactPermissions()) {
1045
                $checked = 'checked="checked"';
1046
            }
1047
            $html = '';
1048
            $html .= '<p>';
1049
            $html .= '<label class="checkbox" for="use_artifact_permissions"><input type="hidden" name="use_artifact_permissions_name" value="0" />';
1050
            $html .= '<input type="checkbox" name="use_artifact_permissions_name" id="use_artifact_permissions" value="1" '. $checked .' />';
1051
            $html .= $GLOBALS['Language']->getText('tracker_include_artifact', 'permissions_label') .'</label>';
1052
            $html .= '</p>';
1053
            $html .= permission_fetch_selection_field('TRACKER_ARTIFACT_ACCESS', $this->getId(), $group_id);
1054
            $html .= '<script type="text/javascript">';
1055
            $html .= "
1056
            document.observe('dom:loaded', function() {
1057
                if ( ! $('use_artifact_permissions').checked) {
1058
                    $('ugroups').disable();
1059
                }
1060
                $('use_artifact_permissions').observe('click', function(evt) {
1061
                    if (this.checked) {
1062
                        $('ugroups').enable();
1063
                    } else {
1064
                        $('ugroups').disable();
1065
                    }
1066
                });
1067
            });
1068
            </script>";
1069
            echo $this->_getSection(
1070
                'artifact_section_permissions',
1071
                $Language->getText('tracker_include_artifact','permissions') .' '. help_button('tracker-v3.html#permissions-on-artifacts'),
1072
                $html,
1073
                false,
1074
                $GLOBALS['Language']->getText('tracker_include_artifact', 'permissions_use_default')
1075
            );
1076
        }
1077
        
1078
        //
1079
        // Final submit button
1080
        //
1081
        echo '<p><B><span class="highlight">'.$Language->getText('tracker_include_artifact','check_already_submitted').'</b></p>';
1082
        echo '<div style="text-align:center"><INPUT CLASS="btn btn-primary" TYPE="SUBMIT" NAME="SUBMIT" VALUE="'.$Language->getText('tracker_include_artifact','submit').'"></div>';
1083
        echo '</td></tr>';
1084
        echo '</table>';
1085
        echo '</form>';
1086
    }
1087
1088
    /**
1089
     * Display the follow-up comment update form
1090
     *
1091
     * @param comment_id: id of the follow-up comment
1092
     *
1093
     * @return void
1094
     */
1095
    function displayEditFollowupComment($comment_id) {
1096
        $hp = Codendi_HTMLPurifier::instance();
1097
        $group = $this->ArtifactType->getGroup();
1098
        $group_artifact_id = $this->ArtifactType->getID();
1099
        $group_id = $group->getGroupId();
1100
        $followUp = $this->getFollowUpDetails($comment_id);
1101
        
1102
        $result_fields     = $GLOBALS['art_field_fact']->getAllUsedFields();
1103
        $summary           = $this->getValue('summary');
1104
        $artTitle          = '[ '. $hp->purify($this->ArtifactType->getItemName(), CODENDI_PURIFIER_CONVERT_HTML);
1105
        $field_artifact_id = $result_fields['artifact_id'];
1106
        if ($field_artifact_id->userCanRead($group_id, $group_artifact_id, user_getid())) {
1107
            $artTitle .= " #". $hp->purify($this->getID(), CODENDI_PURIFIER_CONVERT_HTML) ;
1108
        }
1109
        $artTitle .= ' ] '.$hp->purify(util_unconvert_htmlspecialchars($summary), CODENDI_PURIFIER_CONVERT_HTML);
1110
        $link      = '<a href="?func=detail&aid='.$this->getID().'&atid='.$group_artifact_id.'&group_id='.$group_id.'">'.$artTitle.'</a>';
1111
        
1112
        echo '<H2>'.$link.' - '.$GLOBALS['Language']->getText('tracker_edit_comment','upd_followup').' #'.$comment_id.'</H2>';
1113
1114
        echo '<p>'.$GLOBALS['Language']->getText('tracker_edit_comment','upd_followup_details', array(html_time_ago($followUp['date']), UserHelper::instance()->getLinkOnUserFromUserId($followUp['mod_by']))).'</p>';
1115
        
1116
        echo '<FORM ACTION="/tracker/?group_id='.(int)$group_id.'&atid='.(int)$group_artifact_id.'&func=updatecomment" METHOD="post">
1117
        <INPUT TYPE="hidden" NAME="artifact_history_id" VALUE="'.(int)$comment_id.'">
1118
        <INPUT TYPE="hidden" NAME="artifact_id" VALUE="'.(int)$this->getID().'">
1119
        <P><DIV ID="followup_update_label"></DIV><TEXTAREA NAME="followup_update" id="tracker_artifact_comment" ROWS="10" style="width:700px;" WRAP="SOFT">'. $hp->purify(util_unconvert_htmlspecialchars($followUp['new_value']), CODENDI_PURIFIER_CONVERT_HTML) .'</TEXTAREA>
1120
        <P><INPUT CLASS="btn btn-primary" TYPE="submit" VALUE="'. $GLOBALS['Language']->getText('global', 'btn_submit').'">
1121
        </FORM>';
1122
        
1123
        $GLOBALS['Response']->includeFooterJavascriptFile('/scripts/trackerv3_artifact.js');
1124
    }
1125
1126
    /**
1127
     * Output the raw follow-up comment
1128
     *
1129
     * @param Integer $comment_id Id of the follow-up comment
1130
     *
1131
     * @return void
1132
     */
1133
    function displayFollowupComment($comment_id) {
1134
        echo util_unconvert_htmlspecialchars($this->getFollowup($comment_id));
1135
    }
1136
1137
    /**
1138
    * displayRSS
1139
    * 
1140
    * Display the follow-ups of this artifact as a rss feed
1141
    *
1142
    */
1143
    function displayRSS() {
1144
        $uh = UserHelper::instance();
1145
        $hp = Codendi_HTMLPurifier::instance();
1146
        $group = $this->ArtifactType->getGroup();
1147
        $rss = new RSS(array(
1148
            'title'       => $group->getPublicName().' '.$this->ArtifactType->getName() .' #'. $this->getId() .' - '. $this->getValue('summary') .' - '. $GLOBALS['Language']->getText('tracker_include_artifact','follow_ups'),
1149
            'description' => '',
1150
            'link'        => '<![CDATA['.get_server_url() .'/tracker/?atid='. $this->ArtifactType->getID() .'&group_id='. $group->getGroupId() .']]>',
1151
            'language'    => 'en-us',
1152
            'copyright'   => $GLOBALS['Language']->getText('rss','copyright',array($GLOBALS['sys_long_org_name'],$GLOBALS['sys_name'],date('Y',time()))),
1153
            'pubDate'     => gmdate('D, d M Y h:i:s',$this->getLastUpdateDate()).' GMT',
1154
        ));
1155
        $result=$this->getFollowups ();
1156
        for($i=0 ; $i < db_numrows($result) ; $i++) {
1157
            $comment_type = db_result($result, $i, 'comment_type');
1158
            $comment_type_id = db_result($result, $i, 'comment_type_id');
1159
            $comment_id = db_result($result, $i, 'artifact_history_id');
1160
            $field_name = db_result($result, $i, 'field_name');
1161
            $orig_subm = $this->getOriginalCommentSubmitter($comment_id);
1162
            $orig_date = $this->getOriginalCommentDate($comment_id);
1163
            
1164
            if ( ($comment_type_id == 100) ||($comment_type == "") ) {
1165
                $comment_type = '';
1166
            } else {
1167
                $comment_type = '<strong>['.$comment_type.']</strong><br />';
1168
            }
1169
            $rss->addItem(array(
1170
                'title'       => '<![CDATA['.$GLOBALS['Language']->getText('tracker_include_artifact','add_flup_comment') .' #'.$comment_id.']]>',
1171
                'description' => '<![CDATA['.$comment_type . util_make_links(nl2br(db_result($result, $i, 'new_value')),$group->getGroupId(),$this->ArtifactType->getID()).']]>',
1172
                'pubDate'     => gmdate('D, d M Y h:i:s',db_result($orig_date, 0, 'date')).' GMT',
1173
                'dc:creator'  => $hp->purify($uh->getDisplayNameFromUserId(db_result($orig_subm, 0, 'mod_by'))),
1174
                'link'        => '<![CDATA['.get_server_url() .'/tracker/?func=detail&aid='. $this->getId() .'&atid='. $this->ArtifactType->getID() .'&group_id='. $group->getGroupId().'#comment_'.$comment_id.']]>',
1175
                'guid'        => '<![CDATA['.get_server_url() .'/tracker/?func=detail&aid='. $this->getId() .'&atid='. $this->ArtifactType->getID() .'&group_id='. $group->getGroupId().'#comment_'.$comment_id.']]>'
1176
            ));
1177
        }
1178
        $rss->display();
1179
        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method displayRSS() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1180
1181
    }
1182
    
1183
}
1184
1185
?>
1186