1<?php
2
3require_once(realpath(dirname(__FILE__)).'/../../../inc/init.php');
4
5// POST Sent by the edited array
6
7//    * &row_id=row_id: The project + id attribute of the row, it may be useful to set this to the record ID you are editing
8//    * &field=field: The id attribute of the header cell of the column of the edited cell, it may be useful to set this to the field name you are editing
9//    * &value=xxxxxx: The rest of the POST body is the serialised form. The default name of the field is 'value'.
10
11global $ID;
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13
14if (auth_quickaclcheck($ID) < AUTH_ADMIN) {
15    die;
16}
17
18function emailForChange($email, $id,$project,$field, $oldvalue,$value)
19{
20        global $conf;
21        if (mail_isvalid($email)) {
22
23
24            if ($conf['plugin']['dokumicrobugtracker']['email_subject_template']== '')
25               {$conf['plugin']['dokumicrobugtracker']['email_subject_template'] = "The bug report @ID@ in the project @PROJECT@ changed";}
26            if ($conf['plugin']['dokumicrobugtracker']['email_body_template']== '')
27                {$conf['plugin']['dokumicrobugtracker']['email_body_template'] = "Hi, \n\nYou receive this bug change notification as you report the bug #@ID@ in the project '@PROJECT@'.\n\n--------------------------------------------------------------------------------\n\nWhat : @FIELD@\n\nRemoved: @OLDVALUE@\n\nAdded: @VALUE@";}
28
29            $subject = $conf['plugin']['dokumicrobugtracker']['email_subject_template'];
30            $body = $conf['plugin']['dokumicrobugtracker']['email_body_template'];
31
32            $body =  str_replace('\n', "\n", $body);
33            foreach (array('ID' => $id,
34                           'PROJECT' => $project,
35                           'FIELD' => $field,
36                           'OLDVALUE' => $oldvalue,
37                           'VALUE'  => $value,) as $var => $val) {
38                    $body = str_replace('@' . $var . '@', $val, $body);
39                    $subject = str_replace('@' . $var . '@', $val, $subject);
40                }
41
42            $from= $conf['plugin']['dokumicrobugtracker']['email_address'];
43
44            $to=$email;
45
46            mail_send($to, $subject, $body, $from, $cc='', $bcc='', $headers=null, $params=null);
47        }
48}
49
50function metaFN2($id,$ext){    global $conf;    $id = cleanID($id);    $id = str_replace(':','/',$id);    $fn = $conf['metadir'].'/'.utf8_encodeFN($id).$ext;    return $fn;}
51
52$exploded = explode(' ',htmlspecialchars(stripslashes($_POST['row_id'])));
53$project = $exploded[0];
54$id_bug = intval($exploded[1]);
55
56// get bugs file contents
57$pfile = metaFN2(md5($project), '.bugs');
58if (@file_exists($pfile))
59    {$bugs  = unserialize(@file_get_contents($pfile));}
60else
61    {$bugs = array();}
62
63
64$field = strtolower(htmlspecialchars($_POST['field']));
65$value = htmlspecialchars(stripslashes($_POST['value']));
66
67
68if (($field == 'status') || ($field == 'severity') || ($field == 'version') || ($field == 'description')|| ($field == 'resolution') || ($field == 'delete') && (auth_isadmin()==1))
69    {
70        if ($field == 'delete')
71            {unset($bugs[$id_bug]);echo 'Deleted : ' . $id_bug;}
72    else
73        {
74        emailForChange($bugs[$id_bug]['author'],$id_bug, $project, $field, $bugs[$id_bug][$field], $value);
75        $bugs[$id_bug][$field]=$value;
76        }
77    }
78
79// Save bugs file contents
80$fh = fopen($pfile, 'w');
81fwrite($fh, serialize($bugs));
82fclose($fh);
83
84	echo $_POST['value'];
85?>
86