3 if(count($_POST) == 0) {
4 $Bug = $Author = $Body = $rev = $Subject = $State = $Project = $Category = '';
6 $Subject = $bug_details->get('Subject');
7 $Subject = substr($Subject, 0, ($pos = strpos($Subject, "\n"))?
$pos+
1:strlen($Subject));
8 $Author = $bug_details->get('Author');
9 $Body = $Subject.strip_tags($bug_details->get('Body'));
10 $Rev = $bug_details->get('revision');
11 $State = $bug_details->get('State');
12 $Project = $bug_details->get('Project');
13 $Category = $bug_details->get('Category');
15 $head = $edit?
"Editing Bug Number $id":'Add a Bug';
16 $icon = shrink_get_icon($State);
21 <h4
><span
class="<?=$State?>"><?
=$icon?
></span
> <?
=$head?
></h4
>
24 <div
class="metaList">
27 shrink_show_projects($Project, $count = 5);
31 <span
class="new_type">
32 <a href
="#" id
="new_project_link" onClick
="toggleNew('project')">New Project
</a
>
33 <input style
="display:none" type
="text" name
="new_project" value
="" id
="new_project">
43 <div
class="metaList">
46 shrink_show_categories($Category, $count = 5);
50 <span
class="new_type">
51 <a href
="#" id
="new_category_link" onClick
="toggleNew('category')">New Type
</a
>
52 <input style
="display:none" type
="text" name
="new_category" value
="" id
="new_category">
59 <!-- <input type
="text" name
="Subject" value
="<?=$Subject?$Subject:'Bug title';?>"> -->
60 <div id
="help">The first line becomes the Bug
's title. You can use <a href="http://daringfireball.net/projects/markdown/" title="Markdown Homepage" target="_new">Markdown</a></div>
61 <textarea id="BugBody" name="Body" cols="50" rows="16"><?=$Body?$Body:'Bug description
';?></textarea>
62 <div id="AuthorContainer">
63 <span id="by">by:</span>
66 <input type="hidden" id="Author" name="Author" value="<?=$Author?$Author:'Your Name
or Email
';?>" onFocus="<?=$edit?'':'this
.value
=\'\';'?>">
68 <input type="text" id="Author" name="Author" value="<?=$Author?$Author:'Your Name
or Email
';?>" onFocus="<?=$edit?'':'this
.value
=\'\';'?>">
71 <input type="hidden" name="Project" id="Project" value="<?=$Project?>">
72 <input type="hidden" name="Category" id="Category" value="<?=$Category?>">
78 <input type="hidden" name="id" value="<?=$id?>">
79 <input type="hidden" name="rev" value="<?=$Rev?>">
83 <input type="submit" value="<?=$edit?'Save Changes
':'Add Bug
';?>">
88 $quickAction = ($bug_details->get('State
') == 'Closed
')?'Open
':'Close
';
90 <a href="?action=<?=$quickAction?>&id=<?=$id?>"><?=$quickAction?> this Bug</a>
99 function var_register_post($name)
101 if(isset($_POST[$name])) {
102 return strip_tags(htmlspecialchars($_POST[$name]));
108 function shrink_extract_subject($s)
112 if(!$pos = strpos($s, "\n")) {
116 if(isset($s[$pos+2]) && $s[$pos+2] == "\n") {// catch empty newlines
120 return substr($s, 0, $pos + $offset);
123 function shrink_extract_meta($Subject)
126 preg_match('/\
[([^\s
]*)\s?
([^\
]]*)\
]/', $Subject, $matches);
127 return array($matches[1], $matches[2]);
131 $id = var_register_post('id
');
132 $revision = var_register_post('rev
');
133 $Body = var_register_post('Body
');
134 $Project = var_register_post('Project
');
135 $Category = var_register_post('Category
');
137 $Subject = shrink_extract_subject(strip_tags($Body));
138 $Body = (str_replace(strip_tags($Subject), '', $Body));
140 if(($new_project = var_register_post('new_project
')) && ($new_project != '')) {
141 $Project = $new_project;
144 if(($new_category = var_register_post('new_category
')) && ($new_category != '')) {
145 $Category = $new_category;
148 shrink_save_meta($Project, $Category);
150 $bug_details = new CouchDocument;
151 $bug_details->id = $id;
152 $bug_details->set('Subject
', $Subject);
153 $bug_details->set('Body
', $Body);
155 $bug_details->set('CreationDate
', date('Y
-m
-d
:H
:i
:s
'));
157 $bug_details->set('Author
', var_register_post('Author
'));
160 $bug_details->set('Project
', ($Project));
161 $bug_details->set('Category
', ($Category));
163 $state = var_register_post('State
');
164 $bug_details->set('State
', empty($state)?'Open
':$state);
166 if(!$couch->save($bug_details, $id, $revision)) {
167 //if revision conflict, show diff:
168 if($couch->lastStatusCode == 409) {
169 $lastRev = $couch->get($id, $options = array("rev" => $revision));
170 $currRev = $couch->get($id);
171 //generalize diff, file_put.., tmpfile
172 file_put_contents('/tmp
/bs_diff_1
', $lastRev->get('Body
'));
173 file_put_contents('/tmp
/bs_diff_2
', $currRev->get('Body
'));
174 $diff = `/usr/bin/diff -u /tmp/bs_diff_1 /tmp/bs_diff_2`;
175 if(strlen($diff) > 0) {
176 ?><h3>There was a revision conflict. See below for a diff. Save anyway?</h3><?
177 echo '<pre id
="diff">'.( nl2br($diff) ). '</pre
>';
180 echo 'Failed to save your changes
, sorry
!';
183 // header('Location
: index
.php
');
184 $action = ''; //unset action