]> git.pld-linux.org Git - packages/eventum.git/blob - eventum-order.patch
- adjust to fit
[packages/eventum.git] / eventum-order.patch
1 --- eventum/ajax/order.php      2008-10-15 01:46:20.000000000 +0300
2 +++ eventum-new/ajax/order.php  2008-10-15 02:02:25.000000000 +0300
3 @@ -0,0 +1,72 @@
4 +<?
5 +require_once(dirname(__FILE__) . '/../init.php');
6 +require_once(APP_INC_PATH . "class.auth.php");
7 +require_once(APP_INC_PATH . "class.issue.php");
8 +
9 +// check login
10 +if (!Auth::hasValidCookie(APP_COOKIE)) {
11 +       exit;
12 +}
13 +
14 +
15 +
16 +if (!isset($_POST['before']) || !isset($_POST['after'])) {
17 +       exit;
18 +}
19 +
20 +$before = Misc::explode_url($_POST['before']);
21 +$after = Misc::explode_url($_POST['after']);
22 +
23 +$before = $before['issue_list_table'];
24 +$after = $after['issue_list_table'];
25 +
26 +
27 +$before = array_slice($before, 2, count($before)-3);
28 +$after = array_slice($after, 2, count($after)-3);
29 +
30 +if (count($before) != count($after) or count($before) < 1) {
31 +       exit;
32 +}
33 +
34 +$usr_id = Auth::getUserID();
35 +
36 +$order = Issue::getIssueOrderByUser($usr_id);
37 +
38 +if (!count($order)) {
39 +    // no prev order list
40 +    exit;
41 +}
42 +
43 +$after_filterd = array();
44 +$before_filterd = array();
45 +
46 +// remove issues that are not assigned to me
47 +foreach ($after as $id) {
48 +    if (isset($order[$id])) {
49 +        $after_filterd[] = $id;
50 +    }
51 +}
52 +foreach ($before as $id) {
53 +    if (isset($order[$id])) {
54 +        $before_filterd[] = $id;
55 +    }
56 +}
57 +
58 +foreach ($after_filterd as $key => $nID) {
59 +    if ($nID != $before_filterd[$key]) {
60 +        if ($nID) {
61 +            $stmt = "UPDATE
62 +                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
63 +                     SET
64 +                        isu_order = " . $order[$before_filterd[$key]] . "
65 +                     WHERE
66 +                        isu_iss_id = $nID AND
67 +                        isu_usr_id = $usr_id";
68 +            $res = $GLOBALS["db_api"]->dbh->query($stmt);
69 +            if (PEAR::isError($res)) {
70 +                Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
71 +                die('update failed');
72 +            }
73 +        }
74 +    }
75 +}
76 \ No newline at end of file
77 --- eventum/ajax/update.php     2008-10-15 01:46:20.000000000 +0300
78 +++ eventum-new/ajax/update.php 2008-10-15 02:02:25.000000000 +0300
79 @@ -0,0 +1,30 @@
80 +<?
81 +require_once(dirname(__FILE__) . '/../init.php');
82 +require_once(APP_INC_PATH . "class.auth.php");
83 +require_once(APP_INC_PATH . "class.issue.php");
84 +
85 +// check login
86 +if (!Auth::hasValidCookie(APP_COOKIE)) {
87 +    exit;
88 +}
89 +
90 +if (!is_numeric($_POST['issueID'])) {
91 +    exit;
92 +}
93 +
94 +switch ($_POST['fieldName']) {
95 +  case 'expected_resolution_date':
96 +    $day = (int)$_POST['day'];
97 +    $month = (int)$_POST['month'];
98 +    $year = (int)$_POST['year'];
99 +    if (Issue::updateField($_POST['issueID'], $_POST['fieldName'], sprintf('%04d-%02d-%02d', $year, $month, $day)) !== -1) {
100 +        echo Date_API::getSimpleDate(sprintf('%04d-%02d-%02d', $year, $month, $day), false);
101 +    } else {
102 +        echo 'update failed';
103 +    }
104 +    exit;
105 +  break;
106 +  default:
107 +      die('object type not supported');
108 +  break;
109 +}
110 --- eventum/include/class.display_column.php    2008-10-15 01:46:20.000000000 +0300
111 +++ eventum-new/include/class.display_column.php        2008-10-15 02:02:25.000000000 +0300
112 @@ -229,7 +229,10 @@
113                  ),
114                  "iss_expected_resolution_date"  =>  array(
115                      "title" =>  ev_gettext("Expected Resolution Date")
116 -                )
117 +                ),
118 +                "isu_order" => array(
119 +                    "title" => ev_gettext("Order")
120 +                ),
121              )
122          );
123          return $columns[$page];
124 --- eventum/include/class.issue.php     2008-10-15 01:46:20.000000000 +0300
125 +++ eventum-new/include/class.issue.php 2008-10-15 02:02:25.000000000 +0300
126 @@ -1356,6 +1356,7 @@
127              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
128              return -1;
129          } else {
130 +            Issue::moveOrderForAllUsers($issue_id, 1000);
131              $prj_id = Issue::getProjectID($issue_id);
132  
133              // record the change
134 @@ -1659,6 +1660,176 @@
135          }
136      }
137  
138 +    /**
139 +     * Method used to update the a single detail field of a specific issue.
140 +     *
141 +     * @param integer $issue_id
142 +     * @param string $field_name
143 +     * @param string $field_value
144 +     * @param string $field_type string or integer (for escape)
145 +     * @return integer 1 on success, -1 otherwise
146 +     */
147 +    function updateField($issue_id, $field_name, $filed_value) {
148 +
149 +        $issue_id = Misc::escapeInteger($issue_id);
150 +
151 +        $usr_id = Auth::getUserID();
152 +        $prj_id = Issue::getProjectID($issue_id);
153 +
154 +        // get all of the 'current' information of this issue
155 +        $current = Issue::getDetails($issue_id);
156 +
157 +        $stmt = "UPDATE
158 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue
159 +                 SET
160 +                    iss_updated_date='" . Date_API::getCurrentDateGMT() . "',
161 +                    iss_last_public_action_date='" . Date_API::getCurrentDateGMT() . "',
162 +                    iss_last_public_action_type='updated'";
163 +
164 +        switch ($field_name) {
165 +            case 'category':
166 +                $stmt .= ", iss_prc_id = " . Misc::escapeInteger($filed_value);
167 +            break;
168 +            case 'release':
169 +                $stmt .= ", iss_pre_id = " . Misc::escapeInteger($filed_value);
170 +            break;
171 +            case 'expected_resolution_date':
172 +                $stmt .= ", iss_expected_resolution_date = '" . Misc::escapeString($filed_value) . "'";
173 +            break;
174 +            case 'release':
175 +                $stmt .= ", iss_pre_id = " . Misc::escapeInteger($filed_value);
176 +            break;
177 +            case 'priority':
178 +                $stmt .= ", iss_pri_id = " . Misc::escapeInteger($filed_value);
179 +            break;
180 +            case 'status':
181 +                $stmt .= ", iss_sta_id = " . Misc::escapeInteger($filed_value);
182 +            break;
183 +            case 'resolution':
184 +                $stmt .= ", iss_res_id = " . Misc::escapeInteger($filed_value);
185 +            break;
186 +            case 'summary':
187 +                $stmt .= ", iss_summary = '" . Misc::escapeString($filed_value) . "'";
188 +            break;
189 +            case 'description':
190 +                $stmt .= ", iss_description = '" . Misc::escapeString($filed_value) . "'";
191 +            break;
192 +            case 'estimated_dev_time':
193 +                $stmt .= ", iss_dev_time = '" . Misc::escapeString($filed_value) . "'";
194 +            break;
195 +            case 'percent_complete':
196 +                $stmt .= ", iss_percent_complete = '" . Misc::escapeString($filed_value) . "'";
197 +            break;
198 +            case 'trigger_reminders':
199 +                $stmt .= ", iss_trigger_reminders = " . Misc::escapeInteger($filed_value);
200 +            break;
201 +            case 'group':
202 +                $stmt .= ", iss_grp_id = " . Misc::escapeInteger($filed_value);
203 +            break;
204 +            case 'private':
205 +                $stmt .= ", iss_private = " . Misc::escapeInteger($filed_value);
206 +            break;
207 +            default:
208 +                Error_Handler::logError("Unknown field name $field_name", __FILE__, __LINE__);
209 +                return -1;
210 +            break;
211 +        }
212 +
213 +        $stmt .= "
214 +                 WHERE
215 +                    iss_id=$issue_id";
216 +
217 +        $res = $GLOBALS["db_api"]->dbh->query($stmt);
218 +        if (PEAR::isError($res)) {
219 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
220 +            return -1;
221 +        } else {
222 +            $new = array(
223 +                'category' => $current['iss_prc_id'],
224 +                'release' => $current['iss_pre_id'],
225 +                'expected_resolution_date' => $current['iss_expected_resolution_date'],
226 +                'release' => $current['iss_pre_id'],
227 +                'priority' => $current['iss_pri_id'],
228 +                'status' => $current['iss_sta_id'],
229 +                'resolution' => $current['iss_res_id'],
230 +                'summary' => $current['iss_summary'],
231 +                'description' => $current['iss_description'],
232 +                'estimated_dev_time' => $current['iss_dev_time'],
233 +                'percent_complete' => $current['iss_percent_complete'],
234 +                'trigger_reminders' => $current['iss_trigger_reminders'],
235 +                'group' => $current['iss_grp_id'],
236 +                'iss_private' => $current['private']
237 +            );
238 +            $new[$field_name] = $filed_value;
239 +
240 +            // add change to the history (only for changes on specific fields?)
241 +            $updated_fields = array();
242 +            if ($field_name == 'expected_resolution_date' && $current["iss_expected_resolution_date"] != $filed_value) {
243 +                $updated_fields["Expected Resolution Date"] = History::formatChanges($current["iss_expected_resolution_date"], $filed_value);
244 +            }
245 +            if ($field_name == 'category' && $current["iss_prc_id"] != $filed_value) {
246 +                $updated_fields["Category"] = History::formatChanges(Category::getTitle($current["iss_prc_id"]), Category::getTitle($filed_value));
247 +            }
248 +            if ($field_name == 'release' && $current["iss_pre_id"] != $filed_value) {
249 +                $updated_fields["Release"] = History::formatChanges(Release::getTitle($current["iss_pre_id"]), Release::getTitle($filed_value));
250 +            }
251 +            if ($field_name == 'priority' && $current["iss_pri_id"] != $filed_value) {
252 +                $updated_fields["Priority"] = History::formatChanges(Priority::getTitle($current["iss_pri_id"]), Priority::getTitle($filed_value));
253 +                Workflow::handlePriorityChange($prj_id, $issue_id, $usr_id, $current, $new);
254 +            }
255 +            if ($field_name == 'status' && $current["iss_sta_id"] != $filed_value) {
256 +                // clear out the last-triggered-reminder flag when changing the status of an issue
257 +                Reminder_Action::clearLastTriggered($issue_id);
258 +
259 +                // if old status was closed and new status is not, clear closed data from issue.
260 +                $old_status_details = Status::getDetails($current['iss_sta_id']);
261 +                if ($old_status_details['sta_is_closed'] == 1) {
262 +                    $new_status_details = Status::getDetails($filed_value);
263 +                    if ($new_status_details['sta_is_closed'] != 1) {
264 +                        Issue::clearClosed($issue_id);
265 +                    }
266 +                }
267 +                $updated_fields["Status"] = History::formatChanges(Status::getStatusTitle($current["iss_sta_id"]), Status::getStatusTitle($filed_value));
268 +            }
269 +            if ($field_name == 'resolution' && $current["iss_res_id"] != $filed_value) {
270 +                $updated_fields["Resolution"] = History::formatChanges(Resolution::getTitle($current["iss_res_id"]), Resolution::getTitle($filed_value));
271 +            }
272 +            if ($field_name == 'estimated_dev_time' && $current["iss_dev_time"] != $filed_value) {
273 +                $updated_fields["Estimated Dev. Time"] = History::formatChanges(Misc::getFormattedTime(($current["iss_dev_time"]*60)), Misc::getFormattedTime(($filed_value*60)));
274 +            }
275 +            if ($field_name == 'summary' && $current["iss_summary"] != $filed_value) {
276 +                $updated_fields["Summary"] = '';
277 +            }
278 +            if ($field_name == 'description' && $current["iss_description"] != $filed_value) {
279 +                $updated_fields["Description"] = '';
280 +            }
281 +            if ($field_name == 'private' && ($filed_value != $current['iss_private'])) {
282 +                $updated_fields["Private"] = History::formatChanges(Misc::getBooleanDisplayValue($current['iss_private']), Misc::getBooleanDisplayValue($filed_value));
283 +            }
284 +            if (count($updated_fields) > 0) {
285 +                // log the changes
286 +                $changes = '';
287 +                $i = 0;
288 +                foreach ($updated_fields as $key => $value) {
289 +                    if ($i > 0) {
290 +                        $changes .= "; ";
291 +                    }
292 +                    if (($key != "Summary") && ($key != "Description")) {
293 +                        $changes .= "$key: $value";
294 +                    } else {
295 +                        $changes .= "$key";
296 +                    }
297 +                    $i++;
298 +                }
299 +
300 +                History::add($issue_id, $usr_id, History::getTypeID('issue_updated'), "Issue updated ($changes) by " . User::getFullName($usr_id));
301 +                // send notifications for the issue being updated
302 +                Notification::notifyIssueUpdated($issue_id, $current, $new);
303 +            }
304 +        }
305 +        return 1;
306 +    }
307 +
308  
309      /**
310       * Move the issue to a new project
311 @@ -1820,16 +1991,33 @@
312      {
313          $issue_id = Misc::escapeInteger($issue_id);
314          $assignee_usr_id = Misc::escapeInteger($assignee_usr_id);
315 +        $order = 1;
316 +        // move all orders down to free "order space" for this new association
317 +        $stmt = "UPDATE 
318 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
319 +                 SET
320 +                    isu_order = isu_order + 1
321 +                 WHERE
322 +                    isu_usr_id = $assignee_usr_id AND
323 +                    isu_order >= $order";
324 +        $res = $GLOBALS["db_api"]->dbh->query($stmt);
325 +        if (PEAR::isError($res)) {
326 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
327 +            return -1;
328 +        }
329 +        // insert the new association
330          $stmt = "INSERT INTO
331                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
332                   (
333                      isu_iss_id,
334                      isu_usr_id,
335 -                    isu_assigned_date
336 +                    isu_assigned_date,
337 +                    isu_order
338                   ) VALUES (
339                      $issue_id,
340                      $assignee_usr_id,
341 -                    '" . Date_API::getCurrentDateGMT() . "'
342 +                    '" . Date_API::getCurrentDateGMT() . "',
343 +                    $order
344                   )";
345          $res = $GLOBALS["db_api"]->dbh->query($stmt);
346          if (PEAR::isError($res)) {
347 @@ -1844,6 +2032,78 @@
348          }
349      }
350  
351 +    /**
352 +     * Method used to get the order list to be rearranged
353 +     * 
354 +     * @access  private
355 +     * @param   string $issue_id The issue ID or a comma seperated list of IDs already prepared for giving to mysql
356 +     * @param   string $usr_id The user to remove. When not specified, all users are taken as to be removed for that issue
357 +     * @return  mixed delete order list to be rearranged. Used as a parameter to the method of rearranging the order.
358 +     */
359 +    function getDeleteUserAssociationOrderList($issue_id, $usr_id = "")
360 +    {
361 +        // find all affected associantion orders
362 +        $stmt = "SELECT isu_usr_id, isu_order FROM
363 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
364 +                 WHERE
365 +                 isu_iss_id IN ($issue_id)";
366 +        if ($usr_id !== FALSE) {
367 +            $stmt.= " AND isu_usr_id IN ($usr_id)";
368 +        }
369 +        $stmt.= "ORDER BY isu_order";
370 +        $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
371 +        if (PEAR::isError($res)) {
372 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
373 +            return -1;
374 +        } else {
375 +            $deleted_orders = array();
376 +            foreach ($res as $row) {
377 +                if (empty($deleted_orders[$row['isu_usr_id']])) {
378 +                    $deleted_orders[$row['isu_usr_id']] = array();
379 +                }
380 +                $deleted_orders[$row['isu_usr_id']] [] = $row['isu_order'];
381 +            }
382 +            return $deleted_orders;
383 +        }
384 +    }
385 +
386 +    /**
387 +     *
388 +     * Method used to rearrange order list in the db according to known deleted records
389 +     *
390 +     * @access  private
391 +     * @param   mixed  deleteorder list
392 +     * @return void
393 +     */
394 +    function rearrangeDeleteUserAssociationOrderList($delete_order_list)
395 +    {
396 +        if (empty($delete_order_list) || (!is_array($delete_order_list))) {
397 +            return -1;
398 +        }
399 +        foreach ($delete_order_list as $isu_usr_id => $orders) {
400 +            for ($i = 0; $i < count($orders); $i++) { // traverse all deleted orders
401 +                // move the orders after them up to take the "order space" of the deleted records
402 +                $stmt = "UPDATE
403 +                            " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
404 +                         SET
405 +                            isu_order = isu_order - " . ($i+1) . "
406 +                         WHERE
407 +                            isu_usr_id = $isu_usr_id AND
408 +                            isu_order > " . $orders[$i];
409 +                if ($i < count($orders) - 1) {
410 +                    $stmt.=  " AND
411 +                            isu_order < " . $orders[$i+1];
412 +                }
413 +                $res = $GLOBALS["db_api"]->dbh->query($stmt);
414 +                if (PEAR::isError($res)) {
415 +                    Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
416 +                    return -1;
417 +                }
418 +            }
419 +        }
420 +        return 1;
421 +    }
422 +
423  
424      /**
425       * Method used to delete all user assignments for a specific issue.
426 @@ -1859,6 +2119,7 @@
427          if (is_array($issue_id)) {
428              $issue_id = implode(", ", $issue_id);
429          }
430 +        $deleted_order_list = Issue::getDeleteUserAssociationOrderList($issue_id);
431          $stmt = "DELETE FROM
432                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
433                   WHERE
434 @@ -1871,6 +2132,7 @@
435              if ($usr_id) {
436                  History::add($issue_id, $usr_id, History::getTypeID('user_all_unassociated'), 'Issue assignments removed by ' . User::getFullName($usr_id));
437              }
438 +            Issue::rearrangeDeleteUserAsssociationOrderList($deleted_order_list);
439              return 1;
440          }
441      }
442 @@ -1889,6 +2151,7 @@
443      {
444          $issue_id = Misc::escapeInteger($issue_id);
445          $usr_id = Misc::escapeInteger($usr_id);
446 +        $delete_order_list = Issue::getDeleteUserAssociationOrderList($issue_id, $usr_id);
447          $stmt = "DELETE FROM
448                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
449                   WHERE
450 @@ -1903,6 +2166,7 @@
451                  History::add($issue_id, Auth::getUserID(), History::getTypeID('user_unassociated'),
452                      User::getFullName($usr_id) . ' removed from issue by ' . User::getFullName(Auth::getUserID()));
453              }
454 +            Issue::rearrangeDeleteUserAssociationOrderList($delete_order_list);
455              return 1;
456          }
457      }
458 @@ -2379,6 +2643,11 @@
459      {
460          $sort_by = Issue::getParam('sort_by');
461          $sort_order = Issue::getParam('sort_order');
462 +        $users = Issue::getParam('users');
463 +        if (empty($users) && ($sort_by == 'isu_order')) { // Sorting by isu_order is impossible when no user specified
464 +            unset($sort_by);
465 +            unset($sort_order);
466 +        }
467          $rows = Issue::getParam('rows');
468          $hide_closed = Issue::getParam('hide_closed');
469          if ($hide_closed === '') {
470 @@ -2483,6 +2752,7 @@
471              "last_action_date" => "desc",
472              "usr_full_name" => "asc",
473              "iss_expected_resolution_date" => "desc",
474 +            "isu_order" => "desc",
475          );
476  
477          foreach ($custom_fields as $fld_id => $fld_name) {
478 @@ -3275,6 +3545,8 @@
479          $ids = implode(", ", $ids);
480          $stmt = "SELECT
481                      isu_iss_id,
482 +                    isu_order,
483 +                    isu_usr_id,
484                      usr_full_name
485                   FROM
486                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,
487 @@ -3286,6 +3558,7 @@
488          if (PEAR::isError($res)) {
489              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
490          } else {
491 +            // gather names of the users assigned to each issue
492              $t = array();
493              for ($i = 0; $i < count($res); $i++) {
494                  if (!empty($t[$res[$i]['isu_iss_id']])) {
495 @@ -3294,9 +3567,18 @@
496                      $t[$res[$i]['isu_iss_id']] = $res[$i]['usr_full_name'];
497                  }
498              }
499 +            // gather orders
500 +            $o = array();
501 +            for ($i = 0; $i < count($res); $i++) {
502 +                if (empty($o[$res[$i]['isu_iss_id']])) {
503 +                    $o[$res[$i]['isu_iss_id']] = array();
504 +                }
505 +                $o[$res[$i]['isu_iss_id']][$res[$i]['isu_usr_id']] = $res[$i]['isu_order'];
506 +            }
507              // now populate the $result variable again
508              for ($i = 0; $i < count($result); $i++) {
509                  @$result[$i]['assigned_users'] = $t[$result[$i]['iss_id']];
510 +                @$result[$i]['assigned_users_order'] = $o[$result[$i]['iss_id']];
511              }
512          }
513      }
514 @@ -4264,6 +4546,7 @@
515              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
516              return -1;
517          }
518 +        Issue::moveOrderForAllUsers($issue_id, 1);
519      }
520  
521  
522 @@ -4322,8 +4605,127 @@
523          }
524          return $returns[$msg_id];
525      }
526 +
527 +    /**
528 +     * Reorders user's issues as requested by user
529 +     * @access public
530 +     * @param $usr_id User to be reordered
531 +     * @param $issue_id Issue or array of issues to be moved
532 +     * @param $neworder The new order of the issues
533 +     * @return void
534 +     */
535 +    function reorderUserIssues($usr_id, $issue_id, $neworder)
536 +    {
537 +        if (!isset($usr_id) || !isset($issue_id) || !isset($neworder)) {
538 +            return false;
539 +        }
540 +        if (!is_numeric($usr_id) || !is_numeric($neworder)) {
541 +            return false;
542 +        }
543 +        $usr_id = Misc::escapeInteger($usr_id);
544 +        $issue_id = Misc::escapeInteger($issue_id);
545 +        $neworder = Misc::escapeInteger($neworder);
546 +        if (is_array($issue_id)) {
547 +            $issue_count = count($issue_id);
548 +            $issue_id_str = implode(", ", $issue_id);
549 +        } else {
550 +            $issue_count = 1;
551 +            $issue_id_str = $issue_id;
552 +            $issue_id = array($issue_id);
553 +        }
554 +        // do a nasty pretending to be deleting stuff so that reordering happens as if these elements were deleted
555 +        $orderlist = Issue::getDeleteUserAssociationOrderList($issue_id_str, $usr_id);
556 +        Issue::rearrangeDeleteUserAssociationOrderList($orderlist);
557 +        // move down the orders to free the "order space" needed
558 +        $stmt = "UPDATE 
559 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
560 +                 SET
561 +                    isu_order = isu_order + $issue_count
562 +                 WHERE
563 +                    isu_usr_id = $usr_id AND
564 +                    isu_order >= $neworder";
565 +        $res = $GLOBALS["db_api"]->dbh->query($stmt);
566 +        if (PEAR::isError($res)) {
567 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
568 +            return -1;
569 +        }
570 +        //update the order for the issues being moved
571 +        $i = 0;
572 +        foreach ($issue_id as $iss_id) {
573 +            $stmt = "UPDATE
574 +                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
575 +                     SET
576 +                        isu_order = " . ($neworder + $i) . "
577 +                     WHERE
578 +                        isu_usr_id = $usr_id AND
579 +                        isu_iss_id = $iss_id";
580 +            $res = $GLOBALS["db_api"]->dbh->query($stmt);
581 +            if (PEAR::isError($res)) {
582 +                Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
583 +                return -1;
584 +            }
585 +            $i++;
586 +        }
587 +    }
588 +
589 +
590 +    /**
591 +     * Get users issue order list
592 +     * @access public
593 +     * @param $user_id User
594 +     * @param $order_list Order of the issues
595 +     * @return void
596 +     */
597 +    function getIssueOrderByUser($usr_id) {
598 +
599 +        if (!is_numeric($usr_id)) {
600 +            return false;
601 +        }
602 +
603 +        $stmt = "SELECT
604 +                    isu_iss_id, isu_order
605 +                FROM
606 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
607 +                WHERE
608 +                    isu_usr_id = " . $usr_id ;
609 +
610 +        $order_list = array();
611 +
612 +        $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
613 +
614 +        if (PEAR::isError($res)) {
615 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
616 +            return array();
617 +        } else {
618 +            foreach ($res as $row) {
619 +                $order_list[$row["isu_iss_id"]] = $row["isu_order"];
620 +            }
621 +        }
622 +        return $order_list;
623 +    }
624 +
625 +    function moveOrderForAllUsers($issue_id, $neworder)
626 +    {
627 +        // Move the issue to the top priority for the ppl it's assigned to
628 +        $stmt = "SELECT isu_usr_id FROM
629 +                    "  . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
630 +                 WHERE
631 +                    isu_iss_id = " . Misc::escapeInteger($issue_id);
632 +        $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
633 +        if (PEAR::isError($res)) {
634 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
635 +            return -1;
636 +        }
637 +        foreach ($res as $row) {
638 +            Issue::reorderUserIssues($row["isu_usr_id"], $issue_id, $neworder);
639 +        }
640 +    }
641 +    
642  }
643  
644 +
645 +
646 +
647  // benchmarking the included file (aka setup time)
648  if (APP_BENCHMARK) {
649      $GLOBALS['bench']->setMarker('Included Issue Class');
650 --- eventum/include/class.misc.php      2008-10-15 01:46:20.000000000 +0300
651 +++ eventum-new/include/class.misc.php  2008-10-15 02:02:25.000000000 +0300
652 @@ -744,6 +744,45 @@
653      {
654          return self::$messages;
655      }
656 +
657 +    /**
658 +     * Parse url query string to php array
659 +     *
660 +     * @access  public
661 +     * @link http://php.net/manual/en/function.parse-str.php#79154
662 +     * @param   string $str The url that will be exploded
663 +     * @return  array The variables from url
664 +     */
665 +    function explode_url($str) {
666 +        $return = array();
667 +        // Separate all name-value pairs
668 +        $pairs = explode('&', $str);
669 +        foreach($pairs as $pair) {
670 +            // Pull out the names and the values
671 +            list($name, $value) = explode('=', $pair, 2);
672 +            // Decode the variable name and look for arrays
673 +            list($name, $index) = split('[][]', urldecode($name));
674 +            // Arrays
675 +            if(isset($index)) {
676 +                // Declare or add to the global array defined by $name
677 +                if(!isset($return[$name])) {
678 +                    $return[$name] = array();
679 +                }
680 +                // Associative array
681 +                if(strlen($index) > 0) {
682 +                    $return[$name][$index] = addslashes(urldecode($value));
683 +                } else {
684 +                    // Ordered array
685 +                    array_push($return[$name], addslashes(urldecode($value)));
686 +                }
687 +                // Variables
688 +            } else {
689 +                // Declare or overwrite the global variable defined by $name
690 +                $return[$name] = addslashes(urldecode($value));
691 +            }
692 +        }
693 +            return $return;
694 +    }
695  }
696  
697  // benchmarking the included file (aka setup time)
698 --- eventum-r3749/js/global.js~ 2008-10-15 02:03:48.000000000 +0300
699 +++ eventum-r3749/js/global.js  2008-10-15 02:06:00.000000000 +0300
700 @@ -799,4 +799,39 @@
701                 });
702      });
703  });
704 +
705 +$(document).ready(function() {
706 +    // dialog type calender isn't working in Konqueror beacuse it's not a supported browser for either jQuery or jQuery UI
707 +    // http://groups.google.com/group/jquery-ui/browse_thread/thread/ea61238c34cb5f33/046837b02fb90b5c
708 +    if (navigator.appName != 'Konqueror') {
709 +        $(".inline_date_pick").click(function() {
710 +        var masterObj = this;
711 +        var masterObjPos = $(masterObj).offset();
712 +        // offset gives uses top and left but datepicker needs pageX and pageY
713 +        var masterObjPos = {pageX: masterObjPos.left, pageY: masterObjPos.top};
714 +        $(this).datepicker(
715 +            // we use dialog type calender so we won't haveto have a hidden element on the page
716 +            'dialog',
717 +            // selected date
718 +            masterObj.innerHTML,
719 +            // onclick handler
720 +            function (date, dteObj) {
721 +                fieldName = masterObj.id.substr(0,masterObj.id.indexOf('|'));
722 +                issueID = masterObj.id.substr(masterObj.id.indexOf('|')+1);
723 +                $.post("/ajax/update.php", {fieldName: fieldName, issueID: issueID, day: dteObj.selectedDay, month: (dteObj.selectedMonth+1), year: dteObj.selectedYear}, function(data) {
724 +                    if (data.length > 0) {
725 +                        masterObj.innerHTML = data;
726 +                    }
727 +                }, "text");
728 +            },
729 +            // config
730 +            {dateFormat: 'dd M yy', duration: ""},
731 +            // position of the datepicker calender - taken from div's offset
732 +            masterObjPos
733 +        );
734 +        return false;
735 +        });
736 +    }
737 +});
738 +
739  //-->
740 --- eventum/list.php    2008-10-15 01:46:20.000000000 +0300
741 +++ eventum-new/list.php        2008-10-15 02:02:25.000000000 +0300
742 @@ -67,6 +67,11 @@
743              $profile['sort_by'] . "&sort_order=" . $profile['sort_order']);
744  }
745  
746 +@$reorder_usr_id = $_REQUEST["reorder_user"];
747 +@$reorder_issue_id = $_REQUEST["reorder_source"];
748 +@$reorder_neworder = $_REQUEST["reorder_neworder"];
749 +Issue::reorderUserIssues($reorder_usr_id, $reorder_issue_id, $reorder_neworder);
750 +
751  $options = Issue::saveSearchParams();
752  $tpl->assign("options", $options);
753  $tpl->assign("sorting", Issue::getSortingInfo($options));
754 @@ -90,6 +95,21 @@
755  }
756  $assign_options += $users;
757  
758 +// get the isu_order (assignated users) ordering user
759 +if (!empty($options["users"])) {
760 +    if ($options["users"] == -2) {
761 +        $isu_order_user = $usr_id;
762 +    } else
763 +    if ($options["users"] > 0) {
764 +        $isu_order_user = $options["users"];
765 +    } else {
766 +        unset($isu_order_user);
767 +    }
768 +} else {
769 +    unset($isu_order_user);
770 +}
771 +$tpl->assign("isu_order_user", $isu_order_user);
772 +
773  $list = Issue::getListing($prj_id, $options, $pagerRow, $rows);
774  $tpl->assign("list", $list["list"]);
775  $tpl->assign("list_info", $list["info"]);
776 --- eventum/templates/list.tpl.html     2008-10-15 01:46:20.000000000 +0300
777 +++ eventum-new/templates/list.tpl.html 2008-10-15 02:02:25.000000000 +0300
778 @@ -89,6 +89,28 @@
779      f.target = '_popup';
780      f.submit();
781  }
782 +function reorderBulk(order_user, neworder)
783 +{
784 +    url = page_url + "?";
785 +    url += "reorder_user=" + order_user;
786 +
787 +    items = document.getElementsByName("item[]");
788 +    checkedcount = 0;
789 +    for (var i = 0; i < items.length; i++) {
790 +      if (items[i].checked) {
791 +        url += "&reorder_source[" + checkedcount + "]=" + items[i].value;
792 +        checkedcount++;
793 +      }
794 +    }
795 +    if (checkedcount == 0) {
796 +        alert('{/literal}{t escape=js}Please choose which issues to move to the new place.{/t}{literal}');
797 +        return false;
798 +    }
799 +
800 +    url += "&reorder_neworder=" + neworder;
801 +    
802 +    window.location.href = url;
803 +}
804  function hideClosed(f)
805  {
806      if (f.hide_closed.checked) {
807 @@ -150,6 +172,13 @@
808          f.go.disabled = true;
809      }
810  }
811 +function updateCustomFields(issue_id)
812 +{
813 +    var features = 'width=560,height=460,top=30,left=30,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no';
814 +    var customWin = window.open('custom_fields.php?issue_id=' + issue_id, '_custom_fields', features);
815 +    customWin.focus();
816 +    return false;
817 +}
818  //-->
819  </script>
820  {/literal}
821 @@ -166,11 +195,11 @@
822    <input type="hidden" name="cat" value="bulk_update">
823    <tr>
824      <td>
825 -      <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0">
826 -        <tr>
827 +      <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0" id="issue_list_table">
828 +        <tr class="nodrag">
829            <td colspan="{$col_count}" class="default">
830              <table width="100%" cellspacing="0" cellpadding="0" border="0">
831 -              <tr>
832 +              <tr class="nodrag">
833                  <td class="default">
834                    <b>{t}Search Results{/t} ({$list_info.total_rows} {t}issues found{/t}{if $list_info.end_offset > 0}, {math equation="x + 1" x=$list_info.start_offset} - {$list_info.end_offset} {t}shown{/t}{/if})</b>
835                    {include file="help_link.tpl.html" topic="list"}
836 @@ -190,7 +219,7 @@
837              </table>
838            </td>
839          </tr>
840 -        <tr bgcolor="{$cell_color}">
841 +        <tr bgcolor="{$cell_color}" class="nodrag">
842            {if $current_role > $roles.developer}
843            <td width="1%">
844              <input type="button" value="{t}All{/t}" class="shortcut" onClick="javascript:toggleSelectAll(this.form, 'item[]');toggleBulkUpdate();">
845 @@ -205,7 +234,7 @@
846                    {if $sorting.images[$fld_name_id] != ""}<a title="{t}sort by{/t} {$fld_title|escape:"html"}" href="{$sorting.links[$fld_name_id]}" class="white_link"><img border="0" src="{$sorting.images[$fld_name_id]}"></a>{/if}
847                  </td>
848                {/foreach}
849 -          {else}
850 +          {elseif $field_name != 'isu_order' || $isu_order_user}
851            <td align="{$column.align|default:'center'}" class="default_white" nowrap {if $column.width != ''}width="{$column.width}"{/if}>
852              {if $field_name == 'iss_summary'}
853              <table cellspacing="0" cellpadding="1" width="100%">
854 @@ -221,6 +250,9 @@
855              </table>
856              {elseif $sorting.links[$field_name] != ''}
857                <a title="{t}sort by{/t} {$column.title}" href="{$sorting.links[$field_name]}" class="white_link">{$column.title}</a>
858 +              {if $field_name == 'isu_order'}
859 +                 <br>{$users[$isu_order_user]}
860 +              {/if}
861                {if $sorting.images[$field_name] != ""}<a title="{t}sort by{/t} {$column.title}" href="{$sorting.links[$field_name]}" class="white_link"><img border="0" src="{$sorting.images[$field_name]}"></a>{/if}
862              {else}
863                {$column.title}
864 @@ -229,19 +261,20 @@
865            {/if}
866            {/foreach}
867          </tr>
868 +        <tbody>
869          {section name="i" loop=$list}
870 -        <tr {if $current_role >= $roles.developer AND $list[i].iqu_status > 0}style="text-decoration: line-through;"{/if}>
871 +        <tr {if $current_role >= $roles.developer AND $list[i].iqu_status > 0}style="text-decoration: line-through;"{/if} id="{$list[i].iss_id}" {if !$list[i].assigned_users_order[$current_user_id]}class="nodrag"{/if}>
872            {if $current_role > $roles.developer}
873            <td bgcolor="{$list[i].status_color}" width="1%" class="default" align="center"><input type="checkbox" name="item[]" value="{$list[i].iss_id}" onchange="toggleBulkUpdate();"></td>
874            {/if}
875            {foreach from=$columns item=column key=field_name}
876            {if $field_name == 'custom_fields'}
877              {foreach from=$list[i].custom_field key=fld_id item=fld_value}
878 -                <td bgcolor="{$list[i].status_color}" align="{$column.align|default:'center'}" class="default">
879 -                  {$fld_value|formatCustomValue:$fld_id:$list[i].iss_id}
880 +                <td bgcolor="{$list[i].status_color}" align="{$column.align|default:'center'}" class="default custom_field" onclick="return updateCustomFields({$list[i].iss_id});">
881 +                    {$fld_value|formatCustomValue:$fld_id:$list[i].iss_id}
882                  </td>
883                {/foreach}
884 -          {else}
885 +          {elseif $field_name != 'isu_order' || $isu_order_user}
886            <td bgcolor="{$list[i].status_color}" align="{$column.align|default:'center'}" class="default">
887              {if $field_name == 'iss_id'}
888                <a href="view.php?id={$list[i].iss_id}" class="link" title="{t}view issue details{/t}">{$list[i].iss_id}</a>
889 @@ -276,7 +309,7 @@
890              {elseif $field_name == 'iss_percent_complete'}
891                {$list[i].iss_percent_complete|escape:"html"}%
892              {elseif $field_name == 'iss_expected_resolution_date'}
893 -              {$list[i].iss_expected_resolution_date|escape:"html"}
894 +              <div class="inline_date_pick" id="expected_resolution_date|{$list[i].iss_id}">{$list[i].iss_expected_resolution_date|escape:"html"}&nbsp;</div>
895              {elseif $field_name == 'iss_summary'}
896                <a href="view.php?id={$list[i].iss_id}" class="link" title="{t}view issue details{/t}">{$list[i].iss_summary|escape:"html"}</a>
897                {if $list[i].redeemed}
898 @@ -285,6 +318,10 @@
899                {if $list[i].iss_private == 1}
900                    <b>[Private]</b>
901                {/if}
902 +            {elseif $field_name == 'isu_order'}
903 +              {if $list[i].assigned_users_order[$current_user_id]}
904 +                <img src="{$rel_url}images/updown.gif" alt="move">
905 +              {/if}
906              {/if}
907            </td>
908            {/if}
909 @@ -297,10 +334,11 @@
910            </td>
911          </tr>
912          {/section}
913 -        <tr bgcolor="{$cell_color}">
914 +       </tbody>
915 +        <tr bgcolor="{$cell_color}" class="nodrag">
916            <td colspan="{$col_count}">
917              <table width="100%" cellspacing="0" cellpadding="0">
918 -              <tr>
919 +              <tr class="nodrag">
920                  <td width="30%" nowrap>
921                    {if $current_role > $roles.developer}
922                    <input type="button" value="{t}All{/t}" class="shortcut" onClick="javascript:toggleSelectAll(this.form, 'item[]');">
923 @@ -352,6 +390,29 @@
924    </form>
925  </table>
926  <br />
927 -
928 +<script type="text/javascript">
929 +{*
930 + * Order issues by drag and drop:
931 + * only if sorted by order and viewing your own issues
932 + *}
933 +{if $options.sort_by == "isu_order" and $current_user_id == $isu_order_user}
934 +{literal}
935 +var before = ''; // make it global variable
936 +$('#issue_list_table').tableDnD({
937 +    onDragClass: "tDnD_whileDrag",
938 +    onDragStart: function(table, row) {
939 +        before = $.tableDnD.serialize('id');
940 +    },
941 +    onDrop: function(table, row) {
942 +        $.post("/ajax/order.php", {before: before, after: $.tableDnD.serialize('id')}, function(data) {
943 +                if (data.length > 0) {
944 +                alert(data);
945 +            }
946 +        }, "text");
947 +    }
948 +});
949 +{/literal}
950 +{/if}
951 +</script>
952  {include file="app_info.tpl.html"}
953 -{include file="footer.tpl.html"}
954 +{include file="footer.tpl.html"}
955 \ No newline at end of file
This page took 0.119156 seconds and 4 git commands to generate.