diff --git a/codepot/src/codepot/controllers/file.php b/codepot/src/codepot/controllers/file.php index 2cab968d..a56d5461 100644 --- a/codepot/src/codepot/controllers/file.php +++ b/codepot/src/codepot/controllers/file.php @@ -379,7 +379,7 @@ class File extends Controller { $status = 'error - no name'; } - else if ($post_new_description === FALSE || ($post_new_description = $post_new_description) == '') + else if ($post_new_description === FALSE || ($post_new_description = trim($post_new_description)) == '') { $status = 'error - no description'; } diff --git a/codepot/src/codepot/controllers/issue.php b/codepot/src/codepot/controllers/issue.php index a382bb56..5b8b887f 100644 --- a/codepot/src/codepot/controllers/issue.php +++ b/codepot/src/codepot/controllers/issue.php @@ -575,9 +575,9 @@ class Issue extends Controller } else if ($issue->summary === FALSE || ($issue->summary = trim($issue->summary)) == '') { - $status = 'error - no name'; + $status = 'error - no summary'; } - else if ($issue->description === FALSE || ($issue->description = $issue->description) == '') + else if ($issue->description === FALSE || ($issue->description = trim($issue->description)) == '') { $status = 'error - no description'; } @@ -624,4 +624,216 @@ class Issue extends Controller print $status; } + + function xhr_update ($projectid = '') + { + $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('IssueModel', 'issues'); + $this->load->library ('upload'); + + $login = $this->login->getUser (); + $revision_saved = -1; + + if ($login['id'] == '') + { + $status = 'error - anonymous user'; + } + else + { + $project = $this->projects->get ($projectid); + if ($project === FALSE) + { + $status = "error - failed to get the project {$projectid}"; + } + else if ($project === NULL) + { + $status = "error - no such project {$projectid}"; + } + else if (!$login['sysadmin?'] && + $this->projects->projectHasMember($projectid, $login['id']) === FALSE) + { + $status = "error - not a member {$login['id']}"; + } + else + { + $issue = new stdClass(); + $issue->projectid = $projectid; + $issue->id = $this->input->post('issue_edit_id'); + $issue->summary = $this->input->post('issue_edit_summary'); + $issue->description = $this->input->post('issue_edit_description'); + //$issue->type = $this->input->post('issue_edit_type'); + + if ($issue->id === FALSE || ($issue->id = trim($issue->id)) == '') + { + $status = 'error - no ID'; + } + else if ($issue->summary === FALSE || ($issue->summary = trim($issue->summary)) == '') + { + $status = 'error - no summary'; + } + else if ($issue->description === FALSE || ($issue->description = trim($issue->description)) == '') + { + $status = 'error - no description'; + } + else + { + $status = ''; + + if ($status == '') + { + if ($this->issues->update_summary_and_description ($login['id'], $issue) === FALSE) + { + $status = 'error - ' . $this->issues->getErrorMessage(); + } + else + { + $status = 'ok'; + } + } + } + } + } + + print $status; + } + + private function _handle_file ($login, $projectid, $issueid, $filename) + { + $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('IssueModel', 'issues'); + + $data['login'] = $login; + + $project = $this->projects->get ($projectid); + if ($project === FALSE) + { + $data['message'] = 'DATABASE ERROR'; + $this->load->view ($this->VIEW_ERROR, $data); + } + else if ($project === NULL) + { + $data['message'] = + $this->lang->line('MSG_NO_SUCH_PROJECT') . + " - {$projectid}"; + $this->load->view ($this->VIEW_ERROR, $data); + } + else + { + if ($project->public !== 'Y' && $login['id'] == '') + { + // non-public projects require sign-in. + redirect ("main/signin/" . $this->converter->AsciiTohex(current_url())); + } + + $att = $this->issues->getFile ($login['id'], $project, $issueid, $filename); + if ($att === FALSE) + { + $data['project'] = $project; + $data['message'] = 'DATABASE ERROR'; + $this->load->view ($this->VIEW_ERROR, $data); + } + else if ($att === NULL) + { + $data['project'] = $project; + $data['message'] = sprintf ( + $this->lang->line('ISSUE_MSG_NO_SUCH_FILE'), $filename); + $this->load->view ($this->VIEW_ERROR, $data); + } + else + { + $path = CODEPOT_ISSUE_FILE_DIR . "/{$att->encname}"; + + $stat = @stat($path); + if ($stat === FALSE) + { + $data['project'] = $project; + $data['message'] = sprintf ( + $this->lang->line('issue_MSG_FAILED_TO_READ_FILE'), $filename); + $this->load->view ($this->VIEW_ERROR, $data); + return; + } + + $etag = sprintf ('%x-%x-%x-%x', $stat['dev'], $stat['ino'], $stat['size'], $stat['mtime']); + $lastmod = gmdate ('D, d M Y H:i:s', $stat['mtime']); + + header ('Last-Modified: ' . $lastmod . ' GMT'); + header ('Etag: ' . $etag); + + if ((isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) || + (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $stat['mtime'])) + { + header('Not Modified', true, 304); + flush (); + return; + } + + header ('Content-Type: ' . mime_content_type($path)); + header ('Content-Length: ' . $stat['size']); + header ('Content-Disposition: inline; filename=' . $filename); + flush (); + + $x = @readfile($path); + if ($x === FALSE) + { + $data['project'] = $project; + $data['message'] = sprintf ( + $this->lang->line('ISSUE_MSG_FAILED_TO_READ_FILE'), $filename); + $this->load->view ($this->VIEW_ERROR, $data); + } + } + } + } + + function file ($projectid = '', $issueid = '', $filename = '') + { + $login = $this->login->getUser (); + if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') + redirect ("main/signin/" . $this->converter->AsciiTohex(current_url())); + + if ($issueid == '' || $filename == '') + { + $data['login'] = $login; + $data['message'] = 'INVALID PARAMETERS'; + $this->load->view ($this->VIEW_ERROR, $data); + return; + } + + $filename = $this->converter->HexToAscii ($filename); + + $part = explode (':', $filename); + if (count($part) == 3) + { + if ($part[0] != '') $projectid = $part[0]; + if ($part[1] != '') $issueid = $part[1]; + if ($part[2] != '') $filename = $part[2]; + } + + $this->_handle_file ($login, $projectid, $issueid, $filename); + } + + + function file0 ($projectid = '', $target = '') + { + //$target => projectid:issueid:filename + + $login = $this->login->getUser (); + if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') + redirect ("main/signin/" . $this->converter->AsciiTohex(current_url())); + + if ($target == '') + { + $data['login'] = $login; + $data['message'] = 'INVALID PARAMETERS'; + $this->load->view ($this->VIEW_ERROR, $data); + return; + } + + $target = $this->converter->HexToAscii ($target); + $part = explode (':', $target); + if (count($part) == 3) + { + if ($part[0] == '') $part[0] = $projectid; + $this->_handle_attachment ($login, $part[0], $part[1], $part[2]); + } + } } diff --git a/codepot/src/codepot/controllers/wiki.php b/codepot/src/codepot/controllers/wiki.php index e77f4e55..6343d2dd 100644 --- a/codepot/src/codepot/controllers/wiki.php +++ b/codepot/src/codepot/controllers/wiki.php @@ -229,7 +229,7 @@ class Wiki extends Controller $this->_handle_attachment ($login, $projectid, $wikiname, $name); } - function _handle_attachment ($login, $projectid, $wikiname, $name) + private function _handle_attachment ($login, $projectid, $wikiname, $name) { $this->load->model ('ProjectModel', 'projects'); $this->load->model ('WikiModel', 'wikis'); diff --git a/codepot/src/codepot/models/issuemodel.php b/codepot/src/codepot/models/issuemodel.php index c6a44951..a7460643 100644 --- a/codepot/src/codepot/models/issuemodel.php +++ b/codepot/src/codepot/models/issuemodel.php @@ -22,34 +22,49 @@ class IssueModel extends Model function get ($userid, $project, $id) { - $this->db->trans_start (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). + $this->db->where ('projectid', $project->id); $this->db->where ('id', $id); $query = $this->db->get ('issue'); if ($this->db->trans_status() === FALSE) { - $this->db->trans_complete (); + $this->db->trans_rollback (); return FALSE; } $result = $query->result (); if (empty($result)) { - $this->db->trans_complete (); + $this->db->trans_commit (); return NULL; } + $this->db->where ('projectid', $project->id); + $this->db->where ('issueid', $id); + $query = $this->db->get ('issue_file_list'); + if ($this->db->trans_status() === FALSE) + { + $this->db->trans_rollback (); + return FALSE; + } + $files = $query->result(); + $this->db->where ('projectid', $project->id); $this->db->where ('id', $id); $this->db->order_by ('sno', 'asc'); $query = $this->db->get ('issue_change'); - - $this->db->trans_complete (); - if ($this->db->trans_status() === FALSE) return FALSE; - + if ($this->db->trans_status() === FALSE) + { + $this->db->trans_rollback (); + return FALSE; + } $changes = $query->result(); + $this->db->trans_commit (); + $result[0]->changes = $changes; + $result[0]->files = $files; return $result[0]; } @@ -145,6 +160,25 @@ class IssueModel extends Model return $query->result (); } + function getFile ($userid, $project, $issueid, $filename) + { + $this->db->trans_start (); + + $this->db->select ('filename,encname,md5sum,description,createdon,createdby'); + $this->db->where ('projectid', $project->id); + $this->db->where ('issueid', $issueid); + $this->db->where ('filename', $filename); + + $query = $this->db->get ('issue_file_list'); + $this->db->trans_complete (); + + if ($this->db->trans_status() === FALSE) return FALSE; + $result = $query->result (); + if (empty($result)) return NULL; + + return $result[0]; + } + function create ($userid, $issue) { // TODO: check if userid can do this.. @@ -554,6 +588,32 @@ class IssueModel extends Model restore_error_handler (); return $x; } + + function update_summary_and_description ($userid, $issue) + { + // TODO: check if userid can do this.. + $this->db->trans_start (); + $this->db->where ('projectid', $issue->projectid); + $this->db->where ('id', $issue->id); + $this->db->set ('summary', $issue->summary); + $this->db->set ('description', $issue->description); + $this->db->set ('updatedon', date('Y-m-d H:i:s')); + $this->db->set ('updatedby', $userid); + $this->db->update ('issue'); + + $this->db->set ('createdon', date('Y-m-d H:i:s')); + $this->db->set ('type', 'issue'); + $this->db->set ('action', 'update'); + $this->db->set ('projectid', $issue->projectid); + $this->db->set ('userid', $userid); + $this->db->set ('message', $issue->id); + $this->db->insert ('log'); + + $this->db->trans_complete (); + if ($this->db->trans_status() === FALSE) return FALSE; + + return $issue->id; + } } ?> diff --git a/codepot/src/codepot/views/issue_home.php b/codepot/src/codepot/views/issue_home.php index a02ba245..5e2ceb16 100644 --- a/codepot/src/codepot/views/issue_home.php +++ b/codepot/src/codepot/views/issue_home.php @@ -58,14 +58,14 @@ function render_wiki(input_text) creole_render_wiki_with_input_text ( input_text, "issue_home_mainarea_new_description_preview", - "/wiki/show/id?>/", - "/wiki/attachment0/id?>/" + "/issue/show/id?>/", + "/issue/file0/id?>/" ); prettyPrint (); } -var import_in_progress = false; +var work_in_progress = false; var populated_file_obj = []; var populated_file_max = 0; @@ -137,12 +137,12 @@ $(function () { buttons: { 'lang->line('OK')?>': function () { - if (import_in_progress) return; + if (work_in_progress) return; if (!!window.FormData) { // FormData is supported - import_in_progress = true; + work_in_progress = true; var form_data = new FormData(); @@ -178,7 +178,7 @@ $(function () { cache: false, success: function (data, textStatus, jqXHR) { - import_in_progress = false; + work_in_progress = false; $('#issue_home_mainarea_new_form').dialog('enable'); $('#issue_home_mainarea_new_form').dialog('close'); if (data == 'ok') @@ -193,7 +193,7 @@ $(function () { }, error: function (jqXHR, textStatus, errorThrown) { - import_in_progress = false; + work_in_progress = false; $('#issue_home_mainarea_new_form').dialog('enable'); $('#issue_home_mainarea_new_form').dialog('close'); var errmsg = ''; @@ -210,14 +210,14 @@ $(function () { } }, 'lang->line('Cancel')?>': function () { - if (import_in_progress) return; + if (work_in_progress) return; $('#issue_home_mainarea_new_form').dialog('close'); } }, beforeClose: function() { // if importing is in progress, prevent dialog closing - return !import_in_progress; + return !work_in_progress; } } ); @@ -380,7 +380,7 @@ else