diff --git a/codepot/etc/codepot.mysql b/codepot/etc/codepot.mysql index d74846a0..4de94d55 100644 --- a/codepot/etc/codepot.mysql +++ b/codepot/etc/codepot.mysql @@ -19,7 +19,7 @@ CREATE TABLE project ( id VARCHAR(32) PRIMARY KEY, name VARCHAR(255) UNIQUE NOT NULL, summary VARCHAR(255) NOT NULL, - description TEXT NOT NULL, + description TEXT NOT NULL, commitable CHAR(1) NOT NULL DEFAULT 'Y', public CHAR(1) NOT NULL DEFAULT 'Y', codecharset VARCHAR(32), @@ -44,6 +44,7 @@ CREATE TABLE wiki ( projectid VARCHAR(32) NOT NULL, name VARCHAR(255) NOT NULL, text TEXT NOT NULL, + type CHAR(1) NOT NULL DEFAULT 'C', columns INT NOT NULL DEFAULT 1, createdon DATETIME NOT NULL, @@ -108,7 +109,9 @@ CREATE TABLE issue_file_list ( description VARCHAR(255) NOT NULL, createdon DATETIME NOT NULL, + updatedon DATETIME NOT NULL, createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL, UNIQUE KEY issue_file_list_id (projectid, issueid, filename), UNIQUE KEY (encname), @@ -142,22 +145,24 @@ CREATE TABLE issue_change ( ) charset=utf8 engine=InnoDB; -CREATE TABLE issue_change_attachment ( +CREATE TABLE issue_change_file_list ( projectid VARCHAR(32) NOT NULL, issueid BIGINT NOT NULL, issuesno BIGINT NOT NULL, - name VARCHAR(255) NOT NULL, + filename VARCHAR(255) NOT NULL, encname VARCHAR(255) NOT NULL, createdon DATETIME NOT NULL, + updatedon DATETIME NOT NULL, createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL, - UNIQUE KEY issue_change_attachment_id (projectid, issueid, name), + UNIQUE KEY issue_change_file_list_id (projectid, issueid, name), - CONSTRAINT issue_change_attachment_projectid FOREIGN KEY (projectid) REFERENCES project(id) + CONSTRAINT issue_change_file_list_projectid FOREIGN KEY (projectid) REFERENCES project(id) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT issue_change_attachment_issueidsno FOREIGN KEY (projectid,issueid,issuesno) REFERENCES issue_change(projectid,id,sno) + CONSTRAINT issue_change_file_list_issueidsno FOREIGN KEY (projectid,issueid,issuesno) REFERENCES issue_change(projectid,id,sno) ON DELETE RESTRICT ON UPDATE CASCADE ) charset=utf8 engine=InnoDB; @@ -167,10 +172,10 @@ CREATE TABLE file ( tag VARCHAR(54) NOT NULL, description TEXT NOT NULL, - createdon DATETIME NOT NULL, - updatedon DATETIME NOT NULL, - createdby VARCHAR(32) NOT NULL, - updatedby VARCHAR(32) NOT NULL, + createdon DATETIME NOT NULL, + updatedon DATETIME NOT NULL, + createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL, UNIQUE KEY file_id (projectid, name), INDEX file_tagged_name (projectid, tag, name), @@ -187,10 +192,10 @@ CREATE TABLE file_list ( md5sum CHAR(32) NOT NULL, description VARCHAR(255) NOT NULL, - createdon DATETIME NOT NULL, - updatedon DATETIME NOT NULL, - createdby VARCHAR(32) NOT NULL, - updatedby VARCHAR(32) NOT NULL, + createdon DATETIME NOT NULL, + updatedon DATETIME NOT NULL, + createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL, INDEX file_list_id (projectid, name), UNIQUE KEY file_list_fileid (projectid, filename), diff --git a/codepot/etc/codepot.oracle b/codepot/etc/codepot.oracle index 37c083d8..c5da429f 100644 --- a/codepot/etc/codepot.oracle +++ b/codepot/etc/codepot.oracle @@ -62,6 +62,7 @@ CREATE TABLE "cpot_wiki" ( "projectid" VARCHAR(32) NOT NULL, "name" VARCHAR(255) NOT NULL, "text" CLOB NOT NULL, + "type" CHAR(1) DEFAULT 'C' NOT NULL, "columns" INT DEFAULT 1 NOT NULL, "createdon" TIMESTAMP NOT NULL, "updatedon" TIMESTAMP NOT NULL, @@ -111,11 +112,13 @@ CREATE TABLE "cpot_issue_file_list" ( "md5sum" CHAR(32) NOT NULL, "description" CLOB NOT NULL, "createdon" TIMESTAMP NOT NULL, + "updatedon" TIMESTAMP NOT NULL, "createdby" VARCHAR(32) NOT NULL, + "updatedby" VARCHAR(32) NOT NULL, UNIQUE ("projectid", "issueid", "filename"), UNIQUE ("encname"), - CONSTRAINT issue_attachment_projectid FOREIGN KEY ("projectid") REFERENCES "cpot_project"("id"), - CONSTRAINT issue_attachment_issueid FOREIGN KEY ("projectid","issueid") REFERENCES "cpot_issue"("projectid","id") + CONSTRAINT issue_file_list_projectid FOREIGN KEY ("projectid") REFERENCES "cpot_project"("id"), + CONSTRAINT issue_file_list_issueid FOREIGN KEY ("projectid","issueid") REFERENCES "cpot_issue"("projectid","id") ); CREATE TABLE "cpot_issue_change" ( @@ -135,17 +138,19 @@ CREATE TABLE "cpot_issue_change" ( CREATE INDEX cpot_issue_change_index_1 ON "cpot_issue_change"("projectid", "id", "updatedon"); -CREATE TABLE "cpot_issue_change_attachment" ( +CREATE TABLE "cpot_issue_change_file_list" ( "projectid" VARCHAR(32) NOT NULL, "issueid" NUMBER(20,0) NOT NULL, "issuesno" NUMBER(20,0) NOT NULL, - "name" VARCHAR(255) NOT NULL, + "filename" VARCHAR(255) NOT NULL, "encname" VARCHAR(255) NOT NULL, "createdon" TIMESTAMP NOT NULL, + "updatedon" TIMESTAMP NOT NULL, "createdby" VARCHAR(32) NOT NULL, + "updatedby" VARCHAR(32) NOT NULL, UNIQUE ("projectid", "issueid", "name"), - CONSTRAINT issue_change_attachment_c1 FOREIGN KEY ("projectid") REFERENCES "cpot_project"("id"), - CONSTRAINT issue_change_attachment_c2 FOREIGN KEY ("projectid","issueid","issuesno") REFERENCES "cpot_issue_change"("projectid","id","sno") + CONSTRAINT issue_change_file_list_c1 FOREIGN KEY ("projectid") REFERENCES "cpot_project"("id"), + CONSTRAINT issue_change_file_list_c2 FOREIGN KEY ("projectid","issueid","issuesno") REFERENCES "cpot_issue_change"("projectid","id","sno") ); CREATE TABLE "cpot_file" ( diff --git a/codepot/etc/codepot.pgsql b/codepot/etc/codepot.pgsql index 866ba030..3b308bf5 100644 --- a/codepot/etc/codepot.pgsql +++ b/codepot/etc/codepot.pgsql @@ -60,6 +60,7 @@ CREATE TABLE wiki ( projectid VARCHAR(32) NOT NULL, name VARCHAR(255) NOT NULL, text TEXT NOT NULL, + type CHAR(1) NOT NULL DEFAULT 'C', columns INT NOT NULL DEFAULT 1, createdon TIMESTAMP NOT NULL, @@ -117,24 +118,6 @@ CREATE INDEX issue_index_1 ON issue(projectid, status, type, summary); CREATE INDEX issue_index_2 ON issue(projectid, summary); -CREATE TABLE issue_attachment ( - projectid VARCHAR(32) NOT NULL, - issueid BIGINT NOT NULL, - name VARCHAR(255) NOT NULL, - encname VARCHAR(255) NOT NULL, - - createdon TIMESTAMP NOT NULL, - createdby VARCHAR(32) NOT NULL, - - UNIQUE (projectid, issueid, name), - - CONSTRAINT issue_attachment_projectid FOREIGN KEY (projectid) REFERENCES project(id) - ON DELETE RESTRICT ON UPDATE CASCADE, - - CONSTRAINT issue_attachment_issueid FOREIGN KEY (projectid,issueid) REFERENCES issue(projectid,id) - ON DELETE RESTRICT ON UPDATE CASCADE -); - CREATE TABLE issue_file_list ( projectid VARCHAR(32) NOT NULL, issueid BIGINT NOT NULL, @@ -143,8 +126,10 @@ CREATE TABLE issue_file_list ( md5sum CHAR(32) NOT NULL, description VARCHAR(255) NOT NULL, - createdon DATETIME NOT NULL, - createdby VARCHAR(32) NOT NULL, + createdon TIMESTAMP NOT NULL, + updatedon TIMESTAMP NOT NULL, + createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL, UNIQUE (projectid, issueid, filename), UNIQUE (encname), @@ -179,22 +164,24 @@ CREATE TABLE issue_change ( CREATE INDEX issue_change_index_1 ON issue_change(projectid, id, updatedon); -CREATE TABLE issue_change_attachment ( +CREATE TABLE issue_change_file_list ( projectid VARCHAR(32) NOT NULL, issueid BIGINT NOT NULL, issuesno BIGINT NOT NULL, - name VARCHAR(255) NOT NULL, + filename VARCHAR(255) NOT NULL, encname VARCHAR(255) NOT NULL, createdon TIMESTAMP NOT NULL, + updatedon TIMESTAMP NOT NULL, createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL, UNIQUE (projectid, issueid, name), - CONSTRAINT issue_change_attachment_projectid FOREIGN KEY (projectid) REFERENCES project(id) + CONSTRAINT issue_change_file_list_projectid FOREIGN KEY (projectid) REFERENCES project(id) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT issue_change_attachment_issueidsno FOREIGN KEY (projectid,issueid,issuesno) REFERENCES issue_change(projectid,id,sno) + CONSTRAINT issue_change_file_list_issueidsno FOREIGN KEY (projectid,issueid,issuesno) REFERENCES issue_change(projectid,id,sno) ON DELETE RESTRICT ON UPDATE CASCADE ); diff --git a/codepot/src/codepot/controllers/wiki.php b/codepot/src/codepot/controllers/wiki.php index 17095ece..eeaeddc1 100644 --- a/codepot/src/codepot/controllers/wiki.php +++ b/codepot/src/codepot/controllers/wiki.php @@ -266,7 +266,7 @@ class Wiki extends Controller { $atpos = strpos ($att, '@'); if ($atpos === FALSE) continue; - + $attinfo['name'] = $this->converter->HexToAscii( substr ($att, 0, $atpos)); $attinfo['encname'] = $this->converter->HexToAscii( @@ -554,7 +554,7 @@ class Wiki extends Controller } } - function _upload_attachments ($id) + private function _upload_attachments ($id) { $attno = 0; $count = count($_FILES); @@ -869,4 +869,159 @@ class Wiki extends Controller $this->_handle_issue_file ($login, $projectid, $issueid, $filename); } + + /////////////////////////////////////////////////////////////////// + + function xhr_edit ($projectid = '') + { + $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('WikiModel', 'wikis'); + $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 + { + $wiki = new stdClass(); + $wiki->projectid = $projectid; + $wiki->name = $this->input->post('wiki_name'); + $wiki->text = $this->input->post('wiki_text'); + $wiki->type = $this->input->post('wiki_type'); + + $wiki->original_name = $this->input->post('wiki_original_name'); + $wiki_file_count = $this->input->post('wiki_file_count'); + + if ($wiki->name === FALSE || ($wiki->name = trim($wiki->name)) == '') + { + $status = 'error - empty name'; + } + else if (strpbrk ($wiki->name, ':#[]|') !== FALSE) + { + $status = 'error - disallowed characters in name'; + } + else if ($wiki->text === FALSE || ($wiki->text = trim($wiki->text)) == '') + { + $status = 'error - empty text'; + } + else + { + if ($wiki_file_count === FALSE || $wiki_file_count <= 0) $wiki_file_count = 0; + + if ($wiki->original_name === FALSE) $wiki->original_name = ''; + else $wiki->original_name = trim($wiki->original_name); + + $status = ''; + $attached_files = array (); + for ($i = 0; $i < $wiki_file_count; $i++) + { + $fid = "wiki_file_{$i}"; + if (array_key_exists($fid, $_FILES) && $_FILES[$fid]['name'] != '') + { + if (strpos($_FILES[$fid]['name'], ':') !== FALSE || + strpos($_FILES[$fid]['name'], '/') !== FALSE) + { + // prevents these letters for wiki creole + $status = "error - colon or slash not allowed - {$_FILES[$fid]['name']}"; + break; + } + + array_push ($attached_files, array ('fid' => $fid, 'name' => $_FILES[$fid]['name'])); + } + } + + if ($status == '') + { + if ($this->wikis->editWithFiles ($login['id'], $wiki, $attached_files, $this->upload) === FALSE) + { + $status = 'error - ' . $this->wikis->getErrorMessage(); + } + else + { + $status = 'ok'; + } + } + } + } + } + + print $status; + } + + function xhr_delete ($projectid = '', $wikiname = '') + { + $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('WikiModel', 'wikis'); + + $login = $this->login->getUser (); + + if ($login['id'] == '') + { + $status = 'error - anonymous user'; + } + else + { + $wikiname = $this->converter->HexToAscii ($wikiname); + + $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 + { + $post_delete_confirm = $this->input->post('wiki_delete_confirm'); + + if ($post_delete_confirm !== FALSE && $post_delete_confirm == 'Y') + { + $wiki = new stdClass(); + $wiki->projectid = $projectid; + $wiki->name = $wikiname; + if ($this->wikis->delete ($login['id'], $wiki) === FALSE) + { + $status = 'error - ' . $this->wikis->getErrorMessage(); + } + else + { + $status = 'ok'; + } + } + else + { + $status = 'error - not confirmed'; + } + } + } + + print $status; + } } diff --git a/codepot/src/codepot/language/english/common_lang.php b/codepot/src/codepot/language/english/common_lang.php index c45c88f4..8893136d 100644 --- a/codepot/src/codepot/language/english/common_lang.php +++ b/codepot/src/codepot/language/english/common_lang.php @@ -33,6 +33,7 @@ $lang['Edit'] = 'Edit'; $lang['Empty file'] = 'Empty file'; $lang['Enstyle'] = 'Enstyle'; $lang['Error'] = 'Error'; +$lang['Exit'] = 'Exit'; $lang['Failure'] = 'Failure'; $lang['File'] = 'File'; $lang['Files'] = 'Files'; diff --git a/codepot/src/codepot/language/indonesian/common_lang.php b/codepot/src/codepot/language/indonesian/common_lang.php index 94b79561..612d4d63 100644 --- a/codepot/src/codepot/language/indonesian/common_lang.php +++ b/codepot/src/codepot/language/indonesian/common_lang.php @@ -33,6 +33,7 @@ $lang['Edit'] = 'Rubah'; $lang['Empty file'] = 'Empty file'; $lang['Enstyle'] = 'Enstyle'; $lang['Error'] = 'Error'; +$lang['Exit'] = 'Exit'; $lang['Failure'] = 'Failure'; $lang['File'] = 'File'; $lang['Files'] = 'File'; diff --git a/codepot/src/codepot/language/korean/common_lang.php b/codepot/src/codepot/language/korean/common_lang.php index 5a59ec8f..c6fd2f75 100644 --- a/codepot/src/codepot/language/korean/common_lang.php +++ b/codepot/src/codepot/language/korean/common_lang.php @@ -33,6 +33,7 @@ $lang['Edit'] = '수정'; $lang['Empty file'] = '빈파일'; $lang['Enstyle'] = '모양새내기'; $lang['Error'] = '오류'; +$lang['Exit'] = '종료'; $lang['Failure'] = '실패'; $lang['File'] = '파일'; $lang['Files'] = '파일'; diff --git a/codepot/src/codepot/models/issuemodel.php b/codepot/src/codepot/models/issuemodel.php index e3c5ab1c..ec59bacf 100644 --- a/codepot/src/codepot/models/issuemodel.php +++ b/codepot/src/codepot/models/issuemodel.php @@ -475,6 +475,7 @@ class IssueModel extends Model $maxid = (empty($result) || $result[0] == NULL)? 0: $result[0]->maxid; $newid = $maxid + 1; + $now = codepot_nowtodbdate(); $this->db->set ('projectid', $issue->projectid); $this->db->set ('id', $newid); @@ -484,8 +485,8 @@ class IssueModel extends Model $this->db->set ('status', $issue->status); $this->db->set ('owner', $issue->owner); $this->db->set ('priority', $issue->priority); - $this->db->set ('createdon', codepot_nowtodbdate()); - $this->db->set ('updatedon', codepot_nowtodbdate()); + $this->db->set ('createdon', $now); + $this->db->set ('updatedon', $now); $this->db->set ('createdby', $userid); $this->db->set ('updatedby', $userid); $this->db->insert ('issue'); @@ -504,7 +505,7 @@ class IssueModel extends Model $this->db->set ('owner', $issue->owner); $this->db->set ('comment', ''); $this->db->set ('priority', $issue->priority); - $this->db->set ('updatedon', codepot_nowtodbdate()); + $this->db->set ('updatedon', $now); $this->db->set ('updatedby', $userid); $this->db->insert ('issue_change'); if ($this->db->trans_status() === FALSE) @@ -552,6 +553,10 @@ class IssueModel extends Model $this->db->set ('encname', $ud['file_name']); $this->db->set ('description', $f['desc']); $this->db->set ('md5sum', $md5sum); + $this->db->set ('createdon', $now); + $this->db->set ('createdby', $userid); + $this->db->set ('updatedon', $now); + $this->db->set ('updatedby', $userid); $this->db->insert ('issue_file_list'); if ($this->db->trans_status() === FALSE) { @@ -562,7 +567,7 @@ class IssueModel extends Model } } - $this->db->set ('createdon', codepot_nowtodbdate()); + $this->db->set ('createdon', $now); $this->db->set ('type', 'issue'); $this->db->set ('action', 'create'); $this->db->set ('projectid', $issue->projectid); @@ -732,6 +737,8 @@ class IssueModel extends Model { $this->db->trans_begin (); // manual transaction. not using trans_start(). + $now = codepot_nowtodbdate(); + $config['allowed_types'] = '*'; $config['upload_path'] = CODEPOT_ISSUE_FILE_DIR; $config['max_size'] = CODEPOT_MAX_UPLOAD_SIZE; @@ -771,6 +778,12 @@ class IssueModel extends Model $this->db->set ('md5sum', $md5sum); $this->db->set ('description', $f['desc']); + + $this->db->set ('createdon', $now); + $this->db->set ('createdby', $userid); + $this->db->set ('updatedon', $now); + $this->db->set ('updatedby', $userid); + $this->db->insert ('issue_file_list'); if ($this->db->trans_status() === FALSE) { @@ -781,7 +794,7 @@ class IssueModel extends Model } } - $this->db->set ('createdon', codepot_nowtodbdate()); + $this->db->set ('createdon', $now); $this->db->set ('type', 'issue'); $this->db->set ('action', 'update'); $this->db->set ('projectid', $projectid); @@ -814,6 +827,8 @@ class IssueModel extends Model { $this->db->trans_begin (); // manual transaction. not using trans_start(). + $now = codepot_nowtodbdate(); + $kill_files = array(); $file_count = count($edit_files); for ($i = 0; $i < $file_count; $i++) @@ -861,6 +876,8 @@ class IssueModel extends Model $this->db->where ('issueid', $issueid); $this->db->where ('filename', $f['name']); $this->db->set ('description', $f['desc']); + $this->db->set ('updatedon', $now); + $this->db->set ('updatedby', $userid); $this->db->update ('issue_file_list'); if ($this->db->trans_status() === FALSE) { diff --git a/codepot/src/codepot/models/wikimodel.php b/codepot/src/codepot/models/wikimodel.php index ba367764..83f775f0 100644 --- a/codepot/src/codepot/models/wikimodel.php +++ b/codepot/src/codepot/models/wikimodel.php @@ -2,6 +2,18 @@ class WikiModel extends Model { + protected $errmsg = ''; + + function capture_error ($errno, $errmsg) + { + $this->errmsg = $errmsg; + } + + function getErrorMessage () + { + return $this->errmsg; + } + function WikiModel () { parent::Model (); @@ -280,18 +292,30 @@ class WikiModel extends Model return TRUE; } - function delete ($userid, $wiki) + private function _delete_wiki ($userid, $wiki) { // TODO: check if userid can do this.. - $this->db->trans_start (); + $this->db->trans_begin (); $this->db->where ('projectid', $wiki->projectid); $this->db->where ('wikiname', $wiki->name); $this->db->delete ('wiki_attachment'); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + } $this->db->where ('projectid', $wiki->projectid); $this->db->where ('name', $wiki->name); $this->db->delete ('wiki'); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + } $this->db->set ('createdon', codepot_nowtodbdate()); $this->db->set ('type', 'wiki'); @@ -299,12 +323,142 @@ class WikiModel extends Model $this->db->set ('projectid', $wiki->projectid); $this->db->set ('userid', $userid); $this->db->set ('message', $wiki->name); - $this->db->insert ('log'); - $this->db->trans_complete (); - return $this->db->trans_status(); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + } + + $this->db->trans_commit (); + return TRUE; } + function delete ($userid, $wiki) + { + set_error_handler (array ($this, 'capture_error')); + $errmsg = ''; + $x = $this->_delete_wiki ($userid, $wiki); + restore_error_handler (); + return $x; + } + /////////////////////////////////////////////////////////////////// + + private function _edit_wiki ($userid, $wiki, $attached_files, $uploader) + { + $this->db->trans_begin (); // manual transaction. not using trans_start(). + + $now = codepot_dbdatetodispdate(); + $is_create = empty($wiki->original_name); + + if ($is_create) + { + $this->db->set ('projectid', $wiki->projectid);; + $this->db->set ('name', $wiki->name); + $this->db->set ('text', $wiki->text); + $this->db->set ('type', $wiki->type); + $this->db->set ('createdon', $now); + $this->db->set ('updatedon', $now); + $this->db->set ('createdby', $userid); + $this->db->set ('updatedby', $userid); + $this->db->insert ('wiki'); + } + else + { + $this->db->where ('projectid', $wiki->projectid);; + $this->db->where ('name', $wiki->original_name); + $this->db->set ('name', $wiki->name); + $this->db->set ('text', $wiki->text); + $this->db->set ('type', $wiki->type); + $this->db->set ('updatedon', $now); + $this->db->set ('updatedby', $userid); + $this->db->update ('wiki'); + } + + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + } + + $config['allowed_types'] = '*'; + $config['upload_path'] = CODEPOT_ATTACHMENT_DIR; + $config['max_size'] = CODEPOT_MAX_UPLOAD_SIZE; + $config['encrypt_name'] = TRUE; + $config['overwrite'] = FALSE; + $config['remove_spaces'] = FALSE; + $uploader->initialize ($config); + + $ok_files = array(); + $file_count = count($attached_files); + for ($i = 0; $i < $file_count; $i++) + { + $f = $attached_files[$i]; + if (!$uploader->do_upload($f['fid'])) + { + $this->errmsg = "Failed to upload {$f['name']}"; + $this->db->trans_rollback (); + $this->delete_all_files ($ok_files); + return FALSE; + } + + $ud = $uploader->data(); + array_push ($ok_files, $ud['full_path']); + + /*$md5sum = @md5_file ($ud['full_path']); + if ($md5sum === FALSE) + { + $this->db->trans_rollback (); + $this->delete_all_files ($ok_files); + return FALSE; + }*/ + + $this->db->set ('projectid', $wiki->projectid); + $this->db->set ('wikiname', $wiki->name); + $this->db->set ('name', $f['name']); + $this->db->set ('encname', $ud['file_name']); + /*$this->db->set ('md5sum', $md5sum);*/ + $this->db->set ('createdon', $now); + $this->db->set ('createdby', $userid); + $this->db->insert ('wiki_attachment'); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + $this->delete_all_files ($ok_files); + return FALSE; + } + } + + $this->db->set ('createdon', $now); + $this->db->set ('type', 'wiki'); + $this->db->set ('action', ($is_create? 'create': 'update')); + $this->db->set ('projectid', $wiki->projectid); + $this->db->set ('userid', $userid); + $this->db->set ('message', $wiki->name); + $this->db->insert ('log'); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + $this->delete_all_files ($ok_files); + return FALSE; + } + + $this->db->trans_commit (); + return $newid; + } + + function editWithFiles ($userid, $wiki, $attached_files, $uploader) + { + set_error_handler (array ($this, 'capture_error')); + $errmsg = ''; + $x = $this->_edit_wiki ($userid, $wiki, $attached_files, $uploader); + restore_error_handler (); + return $x; + } } ?> diff --git a/codepot/src/codepot/views/file_show.php b/codepot/src/codepot/views/file_show.php index 3cc24fd8..3e1e9205 100644 --- a/codepot/src/codepot/views/file_show.php +++ b/codepot/src/codepot/views/file_show.php @@ -227,7 +227,7 @@ $(function () { if (data == 'ok') { // refresh the page to the head revision - $(location).attr ('href', codepot_merge_path('', 'id}/"; ?>' + codepot_ascii_to_hex(new_name))); + $(location).attr ('href', codepot_merge_path('', 'id}/"; ?>' + codepot_string_to_hex(new_name))); } else { diff --git a/codepot/src/codepot/views/wiki_edit.php b/codepot/src/codepot/views/wiki_edit.php index 6b4674ab..e20eea50 100644 --- a/codepot/src/codepot/views/wiki_edit.php +++ b/codepot/src/codepot/views/wiki_edit.php @@ -30,15 +30,15 @@ $hex_wikiname = $this->converter->AsciiToHex ($wiki->name); function render_wiki(input_text) { - var column_count = $("#wiki_edit_mainarea_text_column_count").val(); + var column_count = $("#wiki_edit_text_column_count").val(); var x_column_count = parseInt (column_count); if (isNaN(x_column_count) || x_column_count < 1) x_column_count = 1; else if (x_column_count > 9) x_column_count = 9; // sync this max value with wiki_show. TODO: put this into codepot.ini column_count = x_column_count.toString(); - $("#wiki_edit_mainarea_text_column_count").val(column_count); + $("#wiki_edit_text_column_count").val(column_count); - $("#wiki_edit_mainarea_text_preview").css ({ + $("#wiki_edit_text_preview").css ({ "-moz-column-count": column_count, "-webkit-column-count": column_count, "column-count": column_count @@ -46,7 +46,7 @@ function render_wiki(input_text) creole_render_wiki_with_input_text ( input_text, - "wiki_edit_mainarea_text_preview", + "wiki_edit_text_preview", "/wiki/show/id?>/", "/wiki/attachment/id?>//" ); @@ -69,9 +69,9 @@ $(function () { } ); - $("#wiki_edit_mainarea_text_preview_button").button().click( + $("#wiki_edit_text_preview_button").button().click( function () { - render_wiki ($("#wiki_edit_mainarea_text").val()); + render_wiki ($("#wiki_edit_text_area").val()); return false; } ); @@ -123,7 +123,7 @@ $this->load->view (
' + codepot_htmlspecialchars(data) + '', "lang->line('Error')?>"); + } + }, + + error: function (jqXHR, textStatus, errorThrown) { + work_in_progress = false; + show_in_progress_message (null, null); + var errmsg = ''; + if (errmsg == '' && errorThrown != null) errmsg = errorThrown; + if (errmsg == '' && textStatus != null) errmsg = textStatus; + if (errmsg == '') errmsg = 'Unknown error'; + show_alert ('Failed - ' + errmsg, "lang->line('Error')?>"); + } + }); + } + else + { + show_alert ('
NOT SUPPORTED', "lang->line('Error')?>"); + } + + return false; + }); + + $("#wiki_edit_exit_button").button().click (function() { + if (wiki_original_name == '') + $(location).attr ('href', codepot_merge_path('', 'id}"; ?>')); + else + $(location).attr ('href', codepot_merge_path('', 'id}/"; ?>' + codepot_string_to_hex(wiki_original_name))); return false; }); @@ -177,12 +287,11 @@ $this->load->view (