Commit a1e23ec9f0690b4e0552822d0caf89b241a63eb1
1 parent
a1a0a11b
KTS-2129
"Add get_document_type_metadata() to webservice" Fixed. Also added links as KTS-2130. Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6852 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
685 additions
and
472 deletions
ktapi/KTAPIConstants.inc.php
| 1 | <? | 1 | <? |
| 2 | /** | 2 | /** |
| 3 | * $Id$ | 3 | * $Id$ |
| 4 | - * | 4 | + * |
| 5 | * The contents of this file are subject to the KnowledgeTree Public | 5 | * The contents of this file are subject to the KnowledgeTree Public |
| 6 | * License Version 1.1.2 ("License"); You may not use this file except in | 6 | * License Version 1.1.2 ("License"); You may not use this file except in |
| 7 | * compliance with the License. You may obtain a copy of the License at | 7 | * compliance with the License. You may obtain a copy of the License at |
| 8 | * http://www.knowledgetree.com/KPL | 8 | * http://www.knowledgetree.com/KPL |
| 9 | - * | 9 | + * |
| 10 | * Software distributed under the License is distributed on an "AS IS" | 10 | * Software distributed under the License is distributed on an "AS IS" |
| 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing rights and | 12 | * See the License for the specific language governing rights and |
| @@ -17,9 +17,9 @@ | @@ -17,9 +17,9 @@ | ||
| 17 | * (ii) the KnowledgeTree copyright notice | 17 | * (ii) the KnowledgeTree copyright notice |
| 18 | * in the same form as they appear in the distribution. See the License for | 18 | * in the same form as they appear in the distribution. See the License for |
| 19 | * requirements. | 19 | * requirements. |
| 20 | - * | 20 | + * |
| 21 | * The Original Code is: KnowledgeTree Open Source | 21 | * The Original Code is: KnowledgeTree Open Source |
| 22 | - * | 22 | + * |
| 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software | 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software |
| 24 | * (Pty) Ltd, trading as KnowledgeTree. | 24 | * (Pty) Ltd, trading as KnowledgeTree. |
| 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright |
| @@ -31,8 +31,8 @@ | @@ -31,8 +31,8 @@ | ||
| 31 | 31 | ||
| 32 | // Generic error messages used in the API. There may be some others specific to functionality | 32 | // Generic error messages used in the API. There may be some others specific to functionality |
| 33 | // directly in the code. | 33 | // directly in the code. |
| 34 | -// TODO: Check that they are all relevant. | ||
| 35 | - | 34 | +// TODO: Check that they are all relevant. |
| 35 | + | ||
| 36 | define('KTAPI_ERROR_SESSION_INVALID', 'The session could not be resolved.'); | 36 | define('KTAPI_ERROR_SESSION_INVALID', 'The session could not be resolved.'); |
| 37 | define('KTAPI_ERROR_PERMISSION_INVALID', 'The permission could not be resolved.'); | 37 | define('KTAPI_ERROR_PERMISSION_INVALID', 'The permission could not be resolved.'); |
| 38 | define('KTAPI_ERROR_FOLDER_INVALID', 'The folder could not be resolved.'); | 38 | define('KTAPI_ERROR_FOLDER_INVALID', 'The folder could not be resolved.'); |
| @@ -46,6 +46,7 @@ define('KTAPI_ERROR_DOCUMENT_CHECKED_OUT', 'The document is checked out.'); | @@ -46,6 +46,7 @@ define('KTAPI_ERROR_DOCUMENT_CHECKED_OUT', 'The document is checked out.'); | ||
| 46 | define('KTAPI_ERROR_DOCUMENT_NOT_CHECKED_OUT', 'The document is not checked out.'); | 46 | define('KTAPI_ERROR_DOCUMENT_NOT_CHECKED_OUT', 'The document is not checked out.'); |
| 47 | define('KTAPI_ERROR_WORKFLOW_INVALID', 'The workflow could not be resolved.'); | 47 | define('KTAPI_ERROR_WORKFLOW_INVALID', 'The workflow could not be resolved.'); |
| 48 | define('KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS', 'The workflow is not in progress.'); | 48 | define('KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS', 'The workflow is not in progress.'); |
| 49 | +define('KTAPI_ERROR_DOCUMENT_LINK_TYPE_INVALID','The link type could not be resolved.'); | ||
| 49 | 50 | ||
| 50 | // Mapping of permissions to actions. | 51 | // Mapping of permissions to actions. |
| 51 | // TODO: Check that they are all correct. | 52 | // TODO: Check that they are all correct. |
| @@ -53,7 +54,7 @@ define('KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS', 'The workflow is not in progress | @@ -53,7 +54,7 @@ define('KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS', 'The workflow is not in progress | ||
| 53 | // As the permissions are currently associated with actions which are quite closely linked | 54 | // As the permissions are currently associated with actions which are quite closely linked |
| 54 | // to the web interface, it is not the nicest way to do things. They should be associated at | 55 | // to the web interface, it is not the nicest way to do things. They should be associated at |
| 55 | // a lower level, such as in the api. probably, better, would be at some stage to assocate | 56 | // a lower level, such as in the api. probably, better, would be at some stage to assocate |
| 56 | -// the permissions to the action/transaction in the database so administrators can really customise | 57 | +// the permissions to the action/transaction in the database so administrators can really customise |
| 57 | // as required. | 58 | // as required. |
| 58 | 59 | ||
| 59 | define('KTAPI_PERMISSION_DELETE', 'ktcore.permissions.delete'); | 60 | define('KTAPI_PERMISSION_DELETE', 'ktcore.permissions.delete'); |
ktapi/KTAPIDocument.inc.php
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | * License Version 1.1.2 ("License"); You may not use this file except in | 6 | * License Version 1.1.2 ("License"); You may not use this file except in |
| 7 | * compliance with the License. You may obtain a copy of the License at | 7 | * compliance with the License. You may obtain a copy of the License at |
| 8 | * http://www.knowledgetree.com/KPL | 8 | * http://www.knowledgetree.com/KPL |
| 9 | - * | 9 | + * |
| 10 | * Software distributed under the License is distributed on an "AS IS" | 10 | * Software distributed under the License is distributed on an "AS IS" |
| 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing rights and | 12 | * See the License for the specific language governing rights and |
| @@ -17,9 +17,9 @@ | @@ -17,9 +17,9 @@ | ||
| 17 | * (ii) the KnowledgeTree copyright notice | 17 | * (ii) the KnowledgeTree copyright notice |
| 18 | * in the same form as they appear in the distribution. See the License for | 18 | * in the same form as they appear in the distribution. See the License for |
| 19 | * requirements. | 19 | * requirements. |
| 20 | - * | 20 | + * |
| 21 | * The Original Code is: KnowledgeTree Open Source | 21 | * The Original Code is: KnowledgeTree Open Source |
| 22 | - * | 22 | + * |
| 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software | 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software |
| 24 | * (Pty) Ltd, trading as KnowledgeTree. | 24 | * (Pty) Ltd, trading as KnowledgeTree. |
| 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright |
| @@ -29,14 +29,14 @@ | @@ -29,14 +29,14 @@ | ||
| 29 | * | 29 | * |
| 30 | */ | 30 | */ |
| 31 | 31 | ||
| 32 | -class KTAPI_Document extends KTAPI_FolderItem | 32 | +class KTAPI_Document extends KTAPI_FolderItem |
| 33 | { | 33 | { |
| 34 | /** | 34 | /** |
| 35 | * This is a reference to the internal document object. | 35 | * This is a reference to the internal document object. |
| 36 | * | 36 | * |
| 37 | * @var Document | 37 | * @var Document |
| 38 | */ | 38 | */ |
| 39 | - var $document; | 39 | + var $document; |
| 40 | /** | 40 | /** |
| 41 | * This is the id of the document. | 41 | * This is the id of the document. |
| 42 | * | 42 | * |
| @@ -49,16 +49,16 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -49,16 +49,16 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 49 | * @var KTAPI_Folder | 49 | * @var KTAPI_Folder |
| 50 | */ | 50 | */ |
| 51 | var $ktapi_folder; | 51 | var $ktapi_folder; |
| 52 | - | 52 | + |
| 53 | function get_documentid() | 53 | function get_documentid() |
| 54 | { | 54 | { |
| 55 | return $this->documentid; | 55 | return $this->documentid; |
| 56 | - } | ||
| 57 | - | 56 | + } |
| 57 | + | ||
| 58 | /** | 58 | /** |
| 59 | * This is used to get a document based on document id. | 59 | * This is used to get a document based on document id. |
| 60 | * | 60 | * |
| 61 | - * @static | 61 | + * @static |
| 62 | * @access public | 62 | * @access public |
| 63 | * @param KTAPI $ktapi | 63 | * @param KTAPI $ktapi |
| 64 | * @param int $documentid | 64 | * @param int $documentid |
| @@ -69,42 +69,42 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -69,42 +69,42 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 69 | assert(!is_null($ktapi)); | 69 | assert(!is_null($ktapi)); |
| 70 | assert(is_a($ktapi, 'KTAPI')); | 70 | assert(is_a($ktapi, 'KTAPI')); |
| 71 | assert(is_numeric($documentid)); | 71 | assert(is_numeric($documentid)); |
| 72 | - | 72 | + |
| 73 | $documentid += 0; | 73 | $documentid += 0; |
| 74 | - | 74 | + |
| 75 | $document = &Document::get($documentid); | 75 | $document = &Document::get($documentid); |
| 76 | if (is_null($document) || PEAR::isError($document)) | 76 | if (is_null($document) || PEAR::isError($document)) |
| 77 | { | 77 | { |
| 78 | return new KTAPI_Error(KTAPI_ERROR_DOCUMENT_INVALID,$document ); | 78 | return new KTAPI_Error(KTAPI_ERROR_DOCUMENT_INVALID,$document ); |
| 79 | } | 79 | } |
| 80 | - | 80 | + |
| 81 | $user = $ktapi->can_user_access_object_requiring_permission($document, KTAPI_PERMISSION_READ); | 81 | $user = $ktapi->can_user_access_object_requiring_permission($document, KTAPI_PERMISSION_READ); |
| 82 | - | 82 | + |
| 83 | if (is_null($user) || PEAR::isError($user)) | 83 | if (is_null($user) || PEAR::isError($user)) |
| 84 | { | 84 | { |
| 85 | return $user; | 85 | return $user; |
| 86 | - } | ||
| 87 | - | 86 | + } |
| 87 | + | ||
| 88 | $folderid = $document->getParentID(); | 88 | $folderid = $document->getParentID(); |
| 89 | 89 | ||
| 90 | if (!is_null($folderid)) | 90 | if (!is_null($folderid)) |
| 91 | { | 91 | { |
| 92 | $ktapi_folder = &KTAPI_Folder::get($ktapi, $folderid); | 92 | $ktapi_folder = &KTAPI_Folder::get($ktapi, $folderid); |
| 93 | } | 93 | } |
| 94 | - else | 94 | + else |
| 95 | { | 95 | { |
| 96 | $ktapi_folder = null; | 96 | $ktapi_folder = null; |
| 97 | } | 97 | } |
| 98 | // We don't do any checks on this folder as it could possibly be deleted, and is not required right now. | 98 | // We don't do any checks on this folder as it could possibly be deleted, and is not required right now. |
| 99 | 99 | ||
| 100 | return new KTAPI_Document($ktapi, $ktapi_folder, $document); | 100 | return new KTAPI_Document($ktapi, $ktapi_folder, $document); |
| 101 | - } | ||
| 102 | - | 101 | + } |
| 102 | + | ||
| 103 | function is_deleted() | 103 | function is_deleted() |
| 104 | { | 104 | { |
| 105 | return ($this->document->getStatusID() == 3); | 105 | return ($this->document->getStatusID() == 3); |
| 106 | } | 106 | } |
| 107 | - | 107 | + |
| 108 | /** | 108 | /** |
| 109 | * This is the constructor for the KTAPI_Folder. | 109 | * This is the constructor for the KTAPI_Folder. |
| 110 | * | 110 | * |
| @@ -112,18 +112,18 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -112,18 +112,18 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 112 | * @param KTAPI $ktapi | 112 | * @param KTAPI $ktapi |
| 113 | * @param Document $document | 113 | * @param Document $document |
| 114 | * @return KTAPI_Document | 114 | * @return KTAPI_Document |
| 115 | - */ | 115 | + */ |
| 116 | function KTAPI_Document(&$ktapi, &$ktapi_folder, &$document) | 116 | function KTAPI_Document(&$ktapi, &$ktapi_folder, &$document) |
| 117 | { | 117 | { |
| 118 | assert(is_a($ktapi,'KTAPI')); | 118 | assert(is_a($ktapi,'KTAPI')); |
| 119 | assert(is_null($ktapi_folder) || is_a($ktapi_folder,'KTAPI_Folder')); | 119 | assert(is_null($ktapi_folder) || is_a($ktapi_folder,'KTAPI_Folder')); |
| 120 | - | 120 | + |
| 121 | $this->ktapi = &$ktapi; | 121 | $this->ktapi = &$ktapi; |
| 122 | $this->ktapi_folder = &$ktapi_folder; | 122 | $this->ktapi_folder = &$ktapi_folder; |
| 123 | $this->document = &$document; | 123 | $this->document = &$document; |
| 124 | $this->documentid = $document->getId(); | 124 | $this->documentid = $document->getId(); |
| 125 | } | 125 | } |
| 126 | - | 126 | + |
| 127 | /** | 127 | /** |
| 128 | * This checks a document into the repository | 128 | * This checks a document into the repository |
| 129 | * | 129 | * |
| @@ -131,21 +131,21 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -131,21 +131,21 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 131 | * @param string $reason | 131 | * @param string $reason |
| 132 | * @param string $tempfilename | 132 | * @param string $tempfilename |
| 133 | * @param bool $major_update | 133 | * @param bool $major_update |
| 134 | - */ | 134 | + */ |
| 135 | function checkin($filename, $reason, $tempfilename, $major_update=false) | 135 | function checkin($filename, $reason, $tempfilename, $major_update=false) |
| 136 | - { | 136 | + { |
| 137 | if (!is_file($tempfilename)) | 137 | if (!is_file($tempfilename)) |
| 138 | { | 138 | { |
| 139 | return new PEAR_Error('File does not exist.'); | 139 | return new PEAR_Error('File does not exist.'); |
| 140 | } | 140 | } |
| 141 | - | 141 | + |
| 142 | $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); | 142 | $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); |
| 143 | - | 143 | + |
| 144 | if (PEAR::isError($user)) | 144 | if (PEAR::isError($user)) |
| 145 | { | 145 | { |
| 146 | return $user; | 146 | return $user; |
| 147 | } | 147 | } |
| 148 | - | 148 | + |
| 149 | if (!$this->document->getIsCheckedOut()) | 149 | if (!$this->document->getIsCheckedOut()) |
| 150 | { | 150 | { |
| 151 | return new PEAR_Error(KTAPI_ERROR_DOCUMENT_NOT_CHECKED_OUT); | 151 | return new PEAR_Error(KTAPI_ERROR_DOCUMENT_NOT_CHECKED_OUT); |
| @@ -168,23 +168,63 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -168,23 +168,63 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 168 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$result); | 168 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$result); |
| 169 | } | 169 | } |
| 170 | DBUtil::commit(); | 170 | DBUtil::commit(); |
| 171 | - | 171 | + |
| 172 | $tempfilename=addslashes($tempfilename); | 172 | $tempfilename=addslashes($tempfilename); |
| 173 | $sql = "DELETE FROM uploaded_files WHERE tempfilename='$tempfilename'"; | 173 | $sql = "DELETE FROM uploaded_files WHERE tempfilename='$tempfilename'"; |
| 174 | - $result = DBUtil::runQuery($sql); | 174 | + $result = DBUtil::runQuery($sql); |
| 175 | if (PEAR::isError($result)) | 175 | if (PEAR::isError($result)) |
| 176 | { | 176 | { |
| 177 | return $result; | 177 | return $result; |
| 178 | - } | ||
| 179 | - | 178 | + } |
| 179 | + | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + /** | ||
| 183 | + * Link a document to another | ||
| 184 | + * | ||
| 185 | + * @param KTAPI_Document $document | ||
| 186 | + */ | ||
| 187 | + function link_document($document, $type) | ||
| 188 | + { | ||
| 189 | + $typeid = $this->ktapi->get_link_type_id($type); | ||
| 190 | + if (PEAR::isError($typeid)) | ||
| 191 | + { | ||
| 192 | + return $result; | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + $link = new DocumentLink($this->get_documentid(), $document->get_documentid(), $typeid ); | ||
| 196 | + $created = $link->create(); | ||
| 197 | + if ($created === false || PEAR::isError($created)) | ||
| 198 | + { | ||
| 199 | + return new PEAR_Error(_kt('Could not create link')); | ||
| 200 | + } | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + /** | ||
| 204 | + * Unlink a document to another | ||
| 205 | + * | ||
| 206 | + * @param KTAPI_Document $document | ||
| 207 | + */ | ||
| 208 | + function unlink_document($document) | ||
| 209 | + { | ||
| 210 | + $sql = "DELETE FROM document_link WHERE parent_document_id=$this->documentid AND child_document_id=$document->documentid"; | ||
| 211 | + $result = DBUtil::runQuery($sql); | ||
| 212 | + if (empty($result) || PEAR::isError($created)) | ||
| 213 | + { | ||
| 214 | + return new PEAR_Error(_kt('Could not remove link')); | ||
| 215 | + } | ||
| 180 | } | 216 | } |
| 181 | - | ||
| 182 | - | 217 | + |
| 218 | + | ||
| 219 | + /** | ||
| 220 | + * | ||
| 221 | + * @return boolean | ||
| 222 | + */ | ||
| 183 | function is_checked_out() | 223 | function is_checked_out() |
| 184 | { | 224 | { |
| 185 | - return ($this->document->getIsCheckedOut()); | 225 | + return ($this->document->getIsCheckedOut()); |
| 186 | } | 226 | } |
| 187 | - | 227 | + |
| 188 | /** | 228 | /** |
| 189 | * This reverses the checkout process. | 229 | * This reverses the checkout process. |
| 190 | * | 230 | * |
| @@ -193,7 +233,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -193,7 +233,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 193 | function undo_checkout($reason) | 233 | function undo_checkout($reason) |
| 194 | { | 234 | { |
| 195 | $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); | 235 | $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); |
| 196 | - | 236 | + |
| 197 | if (PEAR::isError($user)) | 237 | if (PEAR::isError($user)) |
| 198 | { | 238 | { |
| 199 | return $user; | 239 | return $user; |
| @@ -214,9 +254,9 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -214,9 +254,9 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 214 | DBUtil::rollback(); | 254 | DBUtil::rollback(); |
| 215 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res); | 255 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res); |
| 216 | } | 256 | } |
| 217 | - | 257 | + |
| 218 | $oDocumentTransaction = & new DocumentTransaction($this->document, $reason, 'ktcore.transactions.force_checkin'); | 258 | $oDocumentTransaction = & new DocumentTransaction($this->document, $reason, 'ktcore.transactions.force_checkin'); |
| 219 | - | 259 | + |
| 220 | $res = $oDocumentTransaction->create(); | 260 | $res = $oDocumentTransaction->create(); |
| 221 | if (($res === false) || PEAR::isError($res)) { | 261 | if (($res === false) || PEAR::isError($res)) { |
| 222 | DBUtil::rollback(); | 262 | DBUtil::rollback(); |
| @@ -225,6 +265,63 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -225,6 +265,63 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 225 | DBUtil::commit(); | 265 | DBUtil::commit(); |
| 226 | } | 266 | } |
| 227 | 267 | ||
| 268 | + function get_linked_documents() | ||
| 269 | + { | ||
| 270 | + $sql = " | ||
| 271 | + SELECT | ||
| 272 | + dl.child_document_id as document_id, | ||
| 273 | + dmv.name as title, | ||
| 274 | + dcv.size, | ||
| 275 | + w.name as workflow, | ||
| 276 | + ws.name as workflow_state, | ||
| 277 | + dlt.name as link_type | ||
| 278 | + FROM | ||
| 279 | + document_link dl | ||
| 280 | + INNER JOIN document_link_types dlt ON dl.link_type_id=dlt.id | ||
| 281 | + INNER JOIN documents d ON dl.child_document_id=d.id | ||
| 282 | + INNER JOIN document_metadata_version dmv ON d.metadata_version_id=dmv.id | ||
| 283 | + INNER JOIN document_content_version dcv ON dmv.content_version_id=dcv.id | ||
| 284 | + LEFT OUTER JOIN workflow_documents wd ON d.id=wd.document_id | ||
| 285 | + LEFT OUTER JOIN workflows w ON w.id=wd.workflow_id | ||
| 286 | + LEFT OUTER JOIN workflow_states ws ON wd.state_id=ws.id | ||
| 287 | + WHERE | ||
| 288 | + dl.parent_document_id=$this->documentid | ||
| 289 | + | ||
| 290 | + "; | ||
| 291 | + $rows = DBUtil::getResultArray($sql); | ||
| 292 | + if (PEAR::isError($rows)) | ||
| 293 | + { | ||
| 294 | + return $rows; | ||
| 295 | + } | ||
| 296 | + $result=array(); | ||
| 297 | + $read_permission = &KTPermission::getByName(KTAPI_PERMISSION_READ); | ||
| 298 | + $user = $this->ktapi->get_user(); | ||
| 299 | + | ||
| 300 | + foreach($rows as $row) | ||
| 301 | + { | ||
| 302 | + $document = Document::get($row['document_id']); | ||
| 303 | + if (PEAR::isError($document) || is_null($document)) | ||
| 304 | + { | ||
| 305 | + continue; | ||
| 306 | + } | ||
| 307 | + if(!KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $document)) | ||
| 308 | + { | ||
| 309 | + continue; | ||
| 310 | + } | ||
| 311 | + $result[] = array( | ||
| 312 | + 'document_id'=>(int)$row['document_id'], | ||
| 313 | + 'title'=> $row['title'], | ||
| 314 | + 'size'=>(int)$row['size'], | ||
| 315 | + 'workflow'=>$row['workflow'], | ||
| 316 | + 'workflow_state'=>$row['workflow_state'], | ||
| 317 | + 'link_type'=>$row['link_type'], | ||
| 318 | + ); | ||
| 319 | + } | ||
| 320 | + | ||
| 321 | + return $result; | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + | ||
| 228 | /** | 325 | /** |
| 229 | * This returns a URL to the file that can be downloaded. | 326 | * This returns a URL to the file that can be downloaded. |
| 230 | * | 327 | * |
| @@ -238,7 +335,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -238,7 +335,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 238 | { | 335 | { |
| 239 | return $user; | 336 | return $user; |
| 240 | } | 337 | } |
| 241 | - | 338 | + |
| 242 | if ($this->document->getIsCheckedOut()) | 339 | if ($this->document->getIsCheckedOut()) |
| 243 | { | 340 | { |
| 244 | return new PEAR_Error(KTAPI_ERROR_DOCUMENT_CHECKED_OUT); | 341 | return new PEAR_Error(KTAPI_ERROR_DOCUMENT_CHECKED_OUT); |
| @@ -254,7 +351,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -254,7 +351,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 254 | 351 | ||
| 255 | DBUtil::commit(); | 352 | DBUtil::commit(); |
| 256 | } | 353 | } |
| 257 | - | 354 | + |
| 258 | /** | 355 | /** |
| 259 | * This deletes a document from the folder. | 356 | * This deletes a document from the folder. |
| 260 | * | 357 | * |
| @@ -284,12 +381,12 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -284,12 +381,12 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 284 | 381 | ||
| 285 | DBUtil::commit(); | 382 | DBUtil::commit(); |
| 286 | } | 383 | } |
| 287 | - | 384 | + |
| 288 | /** | 385 | /** |
| 289 | * This changes the owner of the file. | 386 | * This changes the owner of the file. |
| 290 | * | 387 | * |
| 291 | * @param string $ktapi_newuser | 388 | * @param string $ktapi_newuser |
| 292 | - */ | 389 | + */ |
| 293 | function change_owner($newusername, $reason='Changing of owner.') | 390 | function change_owner($newusername, $reason='Changing of owner.') |
| 294 | { | 391 | { |
| 295 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_CHANGE_OWNERSHIP); | 392 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_CHANGE_OWNERSHIP); |
| @@ -297,46 +394,46 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -297,46 +394,46 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 297 | if (PEAR::isError($user)) | 394 | if (PEAR::isError($user)) |
| 298 | { | 395 | { |
| 299 | return $user; | 396 | return $user; |
| 300 | - } | ||
| 301 | - | 397 | + } |
| 398 | + | ||
| 302 | DBUtil::startTransaction(); | 399 | DBUtil::startTransaction(); |
| 303 | - | 400 | + |
| 304 | $user = &User::getByUserName($newusername); | 401 | $user = &User::getByUserName($newusername); |
| 305 | if (is_null($user) || PEAR::isError($user)) | 402 | if (is_null($user) || PEAR::isError($user)) |
| 306 | { | 403 | { |
| 307 | return new KTAPI_Error('User could not be found',$user); | 404 | return new KTAPI_Error('User could not be found',$user); |
| 308 | } | 405 | } |
| 309 | - | 406 | + |
| 310 | $newuserid = $user->getId(); | 407 | $newuserid = $user->getId(); |
| 311 | - | 408 | + |
| 312 | $this->document->setOwnerID($newuserid); | 409 | $this->document->setOwnerID($newuserid); |
| 313 | - | 410 | + |
| 314 | $res = $this->document->update(); | 411 | $res = $this->document->update(); |
| 315 | - | ||
| 316 | - if (PEAR::isError($res)) | 412 | + |
| 413 | + if (PEAR::isError($res)) | ||
| 317 | { | 414 | { |
| 318 | DBUtil::rollback(); | 415 | DBUtil::rollback(); |
| 319 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR ,$res ); | 416 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR ,$res ); |
| 320 | } | 417 | } |
| 321 | - | 418 | + |
| 322 | $res = KTPermissionUtil::updatePermissionLookup($this->document); | 419 | $res = KTPermissionUtil::updatePermissionLookup($this->document); |
| 323 | - if (PEAR::isError($res)) | 420 | + if (PEAR::isError($res)) |
| 324 | { | 421 | { |
| 325 | DBUtil::rollback(); | 422 | DBUtil::rollback(); |
| 326 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); | 423 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); |
| 327 | } | 424 | } |
| 328 | - | 425 | + |
| 329 | $oDocumentTransaction = & new DocumentTransaction($this->document, $reason, 'ktcore.transactions.permissions_change'); | 426 | $oDocumentTransaction = & new DocumentTransaction($this->document, $reason, 'ktcore.transactions.permissions_change'); |
| 330 | - | 427 | + |
| 331 | $res = $oDocumentTransaction->create(); | 428 | $res = $oDocumentTransaction->create(); |
| 332 | if (($res === false) || PEAR::isError($res)) { | 429 | if (($res === false) || PEAR::isError($res)) { |
| 333 | DBUtil::rollback(); | 430 | DBUtil::rollback(); |
| 334 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); | 431 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); |
| 335 | } | 432 | } |
| 336 | - | 433 | + |
| 337 | DBUtil::commit(); | 434 | DBUtil::commit(); |
| 338 | - } | ||
| 339 | - | 435 | + } |
| 436 | + | ||
| 340 | /** | 437 | /** |
| 341 | * This copies the document to another folder. | 438 | * This copies the document to another folder. |
| 342 | * | 439 | * |
| @@ -349,7 +446,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -349,7 +446,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 349 | { | 446 | { |
| 350 | assert(!is_null($ktapi_target_folder)); | 447 | assert(!is_null($ktapi_target_folder)); |
| 351 | assert(is_a($ktapi_target_folder,'KTAPI_Folder')); | 448 | assert(is_a($ktapi_target_folder,'KTAPI_Folder')); |
| 352 | - | 449 | + |
| 353 | if (empty($newname)) | 450 | if (empty($newname)) |
| 354 | { | 451 | { |
| 355 | $newname=null; | 452 | $newname=null; |
| @@ -358,7 +455,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -358,7 +455,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 358 | { | 455 | { |
| 359 | $newfilename=null; | 456 | $newfilename=null; |
| 360 | } | 457 | } |
| 361 | - | 458 | + |
| 362 | $user = $this->ktapi->get_user(); | 459 | $user = $this->ktapi->get_user(); |
| 363 | 460 | ||
| 364 | if ($this->document->getIsCheckedOut()) | 461 | if ($this->document->getIsCheckedOut()) |
| @@ -367,7 +464,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -367,7 +464,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 367 | } | 464 | } |
| 368 | 465 | ||
| 369 | $target_folder = &$ktapi_target_folder->get_folder(); | 466 | $target_folder = &$ktapi_target_folder->get_folder(); |
| 370 | - | 467 | + |
| 371 | $result = $this->can_user_access_object_requiring_permission( $target_folder, KTAPI_PERMISSION_WRITE); | 468 | $result = $this->can_user_access_object_requiring_permission( $target_folder, KTAPI_PERMISSION_WRITE); |
| 372 | 469 | ||
| 373 | if (PEAR::isError($result)) | 470 | if (PEAR::isError($result)) |
| @@ -377,51 +474,51 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -377,51 +474,51 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 377 | 474 | ||
| 378 | $name = $this->document->getName(); | 475 | $name = $this->document->getName(); |
| 379 | $clash = KTDocumentUtil::nameExists($target_folder, $name); | 476 | $clash = KTDocumentUtil::nameExists($target_folder, $name); |
| 380 | - if ($clash && !is_null($newname)) | ||
| 381 | - { | 477 | + if ($clash && !is_null($newname)) |
| 478 | + { | ||
| 382 | $name = $newname; | 479 | $name = $newname; |
| 383 | $clash = KTDocumentUtil::nameExists($target_folder, $name); | 480 | $clash = KTDocumentUtil::nameExists($target_folder, $name); |
| 384 | } | 481 | } |
| 385 | - if ($clash) | 482 | + if ($clash) |
| 386 | { | 483 | { |
| 387 | return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.'); | 484 | return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.'); |
| 388 | } | 485 | } |
| 389 | - | 486 | + |
| 390 | $filename=$this->document->getFilename(); | 487 | $filename=$this->document->getFilename(); |
| 391 | $clash = KTDocumentUtil::fileExists($target_folder, $filename); | 488 | $clash = KTDocumentUtil::fileExists($target_folder, $filename); |
| 392 | 489 | ||
| 393 | - if ($clash && !is_null($newname)) | 490 | + if ($clash && !is_null($newname)) |
| 394 | { | 491 | { |
| 395 | $filename = $newfilename; | 492 | $filename = $newfilename; |
| 396 | $clash = KTDocumentUtil::fileExists($target_folder, $filename); | 493 | $clash = KTDocumentUtil::fileExists($target_folder, $filename); |
| 397 | } | 494 | } |
| 398 | - if ($clash) | 495 | + if ($clash) |
| 399 | { | 496 | { |
| 400 | return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.'); | 497 | return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.'); |
| 401 | } | 498 | } |
| 402 | - | 499 | + |
| 403 | DBUtil::startTransaction(); | 500 | DBUtil::startTransaction(); |
| 404 | - | 501 | + |
| 405 | $new_document = KTDocumentUtil::copy($this->document, $target_folder, $reason); | 502 | $new_document = KTDocumentUtil::copy($this->document, $target_folder, $reason); |
| 406 | - if (PEAR::isError($new_document)) | 503 | + if (PEAR::isError($new_document)) |
| 407 | { | 504 | { |
| 408 | DBUtil::rollback(); | 505 | DBUtil::rollback(); |
| 409 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$new_document ); | 506 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$new_document ); |
| 410 | } | 507 | } |
| 411 | - | 508 | + |
| 412 | $new_document->setName($name); | 509 | $new_document->setName($name); |
| 413 | $new_document->setFilename($filename); | 510 | $new_document->setFilename($filename); |
| 414 | - | 511 | + |
| 415 | $res = $new_document->update(); | 512 | $res = $new_document->update(); |
| 416 | - | ||
| 417 | - if (PEAR::isError($res)) | 513 | + |
| 514 | + if (PEAR::isError($res)) | ||
| 418 | { | 515 | { |
| 419 | DBUtil::rollback(); | 516 | DBUtil::rollback(); |
| 420 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); | 517 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); |
| 421 | } | 518 | } |
| 422 | 519 | ||
| 423 | DBUtil::commit(); | 520 | DBUtil::commit(); |
| 424 | - | 521 | + |
| 425 | // FIXME do we need to refactor all trigger usage into the util function? | 522 | // FIXME do we need to refactor all trigger usage into the util function? |
| 426 | $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | 523 | $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); |
| 427 | $aTriggers = $oKTTriggerRegistry->getTriggers('copyDocument', 'postValidate'); | 524 | $aTriggers = $oKTTriggerRegistry->getTriggers('copyDocument', 'postValidate'); |
| @@ -437,7 +534,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -437,7 +534,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 437 | $ret = $oTrigger->postValidate(); | 534 | $ret = $oTrigger->postValidate(); |
| 438 | } | 535 | } |
| 439 | } | 536 | } |
| 440 | - | 537 | + |
| 441 | /** | 538 | /** |
| 442 | * This moves the document to another folder. | 539 | * This moves the document to another folder. |
| 443 | * | 540 | * |
| @@ -450,7 +547,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -450,7 +547,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 450 | { | 547 | { |
| 451 | assert(!is_null($ktapi_target_folder)); | 548 | assert(!is_null($ktapi_target_folder)); |
| 452 | assert(is_a($ktapi_target_folder,'KTAPI_Folder')); | 549 | assert(is_a($ktapi_target_folder,'KTAPI_Folder')); |
| 453 | - | 550 | + |
| 454 | if (empty($newname)) | 551 | if (empty($newname)) |
| 455 | { | 552 | { |
| 456 | $newname=null; | 553 | $newname=null; |
| @@ -458,8 +555,8 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -458,8 +555,8 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 458 | if (empty($newfilename)) | 555 | if (empty($newfilename)) |
| 459 | { | 556 | { |
| 460 | $newfilename=null; | 557 | $newfilename=null; |
| 461 | - } | ||
| 462 | - | 558 | + } |
| 559 | + | ||
| 463 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_DOCUMENT_MOVE); | 560 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_DOCUMENT_MOVE); |
| 464 | 561 | ||
| 465 | if (PEAR::isError($user)) | 562 | if (PEAR::isError($user)) |
| @@ -473,14 +570,14 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -473,14 +570,14 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 473 | } | 570 | } |
| 474 | 571 | ||
| 475 | $target_folder = $ktapi_target_folder->get_folder(); | 572 | $target_folder = $ktapi_target_folder->get_folder(); |
| 476 | - | 573 | + |
| 477 | $result= $this->can_user_access_object_requiring_permission( $target_folder, KTAPI_PERMISSION_WRITE); | 574 | $result= $this->can_user_access_object_requiring_permission( $target_folder, KTAPI_PERMISSION_WRITE); |
| 478 | 575 | ||
| 479 | if (PEAR::isError($result)) | 576 | if (PEAR::isError($result)) |
| 480 | { | 577 | { |
| 481 | return $result; | 578 | return $result; |
| 482 | } | 579 | } |
| 483 | - | 580 | + |
| 484 | if (!KTDocumentUtil::canBeMoved($this->document)) | 581 | if (!KTDocumentUtil::canBeMoved($this->document)) |
| 485 | { | 582 | { |
| 486 | return new PEAR_Error('Document cannot be moved.'); | 583 | return new PEAR_Error('Document cannot be moved.'); |
| @@ -488,52 +585,52 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -488,52 +585,52 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 488 | 585 | ||
| 489 | $name = $this->document->getName(); | 586 | $name = $this->document->getName(); |
| 490 | $clash = KTDocumentUtil::nameExists($target_folder, $name); | 587 | $clash = KTDocumentUtil::nameExists($target_folder, $name); |
| 491 | - if ($clash && !is_null($newname)) | ||
| 492 | - { | 588 | + if ($clash && !is_null($newname)) |
| 589 | + { | ||
| 493 | $name = $newname; | 590 | $name = $newname; |
| 494 | $clash = KTDocumentUtil::nameExists($target_folder, $name); | 591 | $clash = KTDocumentUtil::nameExists($target_folder, $name); |
| 495 | } | 592 | } |
| 496 | - if ($clash) | 593 | + if ($clash) |
| 497 | { | 594 | { |
| 498 | return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the moved document.'); | 595 | return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the moved document.'); |
| 499 | } | 596 | } |
| 500 | - | 597 | + |
| 501 | $filename=$this->document->getFilename(); | 598 | $filename=$this->document->getFilename(); |
| 502 | $clash = KTDocumentUtil::fileExists($target_folder, $filename); | 599 | $clash = KTDocumentUtil::fileExists($target_folder, $filename); |
| 503 | 600 | ||
| 504 | - if ($clash && !is_null($newname)) | 601 | + if ($clash && !is_null($newname)) |
| 505 | { | 602 | { |
| 506 | $filename = $newfilename; | 603 | $filename = $newfilename; |
| 507 | $clash = KTDocumentUtil::fileExists($target_folder, $filename); | 604 | $clash = KTDocumentUtil::fileExists($target_folder, $filename); |
| 508 | } | 605 | } |
| 509 | - if ($clash) | 606 | + if ($clash) |
| 510 | { | 607 | { |
| 511 | return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the moved document.'); | 608 | return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the moved document.'); |
| 512 | } | 609 | } |
| 513 | - | 610 | + |
| 514 | DBUtil::startTransaction(); | 611 | DBUtil::startTransaction(); |
| 515 | - | 612 | + |
| 516 | $res = KTDocumentUtil::move($this->document, $target_folder, $user, $reason); | 613 | $res = KTDocumentUtil::move($this->document, $target_folder, $user, $reason); |
| 517 | - if (PEAR::isError($res)) | 614 | + if (PEAR::isError($res)) |
| 518 | { | 615 | { |
| 519 | DBUtil::rollback(); | 616 | DBUtil::rollback(); |
| 520 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res ); | 617 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res ); |
| 521 | } | 618 | } |
| 522 | - | 619 | + |
| 523 | $this->document->setName($name); | 620 | $this->document->setName($name); |
| 524 | $this->document->setFilename($filename); | 621 | $this->document->setFilename($filename); |
| 525 | - | 622 | + |
| 526 | $res = $this->document->update(); | 623 | $res = $this->document->update(); |
| 527 | - | ||
| 528 | - if (PEAR::isError($res)) | 624 | + |
| 625 | + if (PEAR::isError($res)) | ||
| 529 | { | 626 | { |
| 530 | DBUtil::rollback(); | 627 | DBUtil::rollback(); |
| 531 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); | 628 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); |
| 532 | } | 629 | } |
| 533 | 630 | ||
| 534 | DBUtil::commit(); | 631 | DBUtil::commit(); |
| 535 | - } | ||
| 536 | - | 632 | + } |
| 633 | + | ||
| 537 | /** | 634 | /** |
| 538 | * This changes the filename of the document. | 635 | * This changes the filename of the document. |
| 539 | * | 636 | * |
| @@ -547,17 +644,17 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -547,17 +644,17 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 547 | { | 644 | { |
| 548 | return $user; | 645 | return $user; |
| 549 | } | 646 | } |
| 550 | - | 647 | + |
| 551 | DBUtil::startTransaction(); | 648 | DBUtil::startTransaction(); |
| 552 | $res = KTDocumentUtil::rename($this->document, $newname, $user); | 649 | $res = KTDocumentUtil::rename($this->document, $newname, $user); |
| 553 | - if (PEAR::isError($res)) | 650 | + if (PEAR::isError($res)) |
| 554 | { | 651 | { |
| 555 | DBUtil::rollback(); | 652 | DBUtil::rollback(); |
| 556 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); | 653 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); |
| 557 | } | 654 | } |
| 558 | DBUtil::commit(); | 655 | DBUtil::commit(); |
| 559 | } | 656 | } |
| 560 | - | 657 | + |
| 561 | /** | 658 | /** |
| 562 | * This changes the document type of the document. | 659 | * This changes the document type of the document. |
| 563 | * | 660 | * |
| @@ -571,9 +668,9 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -571,9 +668,9 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 571 | { | 668 | { |
| 572 | return $user; | 669 | return $user; |
| 573 | } | 670 | } |
| 574 | - | ||
| 575 | - $doctypeid = KTAPI::get_documenttypeid($documenttype); | ||
| 576 | - | 671 | + |
| 672 | + $doctypeid = KTAPI::get_documenttypeid($documenttype); | ||
| 673 | + | ||
| 577 | if ($this->document->getDocumentTypeId() != $doctypeid) | 674 | if ($this->document->getDocumentTypeId() != $doctypeid) |
| 578 | { | 675 | { |
| 579 | DBUtil::startTransaction(); | 676 | DBUtil::startTransaction(); |
| @@ -587,8 +684,8 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -587,8 +684,8 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 587 | } | 684 | } |
| 588 | DBUtil::commit(); | 685 | DBUtil::commit(); |
| 589 | } | 686 | } |
| 590 | - } | ||
| 591 | - | 687 | + } |
| 688 | + | ||
| 592 | /** | 689 | /** |
| 593 | * This changes the title of the document. | 690 | * This changes the title of the document. |
| 594 | * | 691 | * |
| @@ -602,7 +699,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -602,7 +699,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 602 | { | 699 | { |
| 603 | return $user; | 700 | return $user; |
| 604 | } | 701 | } |
| 605 | - | 702 | + |
| 606 | if ($this->document->getName() != $newname) | 703 | if ($this->document->getName() != $newname) |
| 607 | { | 704 | { |
| 608 | 705 | ||
| @@ -618,7 +715,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -618,7 +715,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 618 | DBUtil::commit(); | 715 | DBUtil::commit(); |
| 619 | } | 716 | } |
| 620 | } | 717 | } |
| 621 | - | 718 | + |
| 622 | /** | 719 | /** |
| 623 | * This flags the document as 'archived'. | 720 | * This flags the document as 'archived'. |
| 624 | * | 721 | * |
| @@ -633,8 +730,8 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -633,8 +730,8 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 633 | return $user; | 730 | return $user; |
| 634 | } | 731 | } |
| 635 | 732 | ||
| 636 | - list($permission, $user) = $perm_and_user; | ||
| 637 | - | 733 | + list($permission, $user) = $perm_and_user; |
| 734 | + | ||
| 638 | DBUtil::startTransaction(); | 735 | DBUtil::startTransaction(); |
| 639 | $this->document->setStatusID(ARCHIVED); | 736 | $this->document->setStatusID(ARCHIVED); |
| 640 | $res = $this->document->update(); | 737 | $res = $this->document->update(); |
| @@ -642,15 +739,15 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -642,15 +739,15 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 642 | DBUtil::rollback(); | 739 | DBUtil::rollback(); |
| 643 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res); | 740 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res); |
| 644 | } | 741 | } |
| 645 | - | 742 | + |
| 646 | $oDocumentTransaction = & new DocumentTransaction($this->document, sprintf(_kt('Document archived: %s'), $reason), 'ktcore.transactions.update'); | 743 | $oDocumentTransaction = & new DocumentTransaction($this->document, sprintf(_kt('Document archived: %s'), $reason), 'ktcore.transactions.update'); |
| 647 | $oDocumentTransaction->create(); | 744 | $oDocumentTransaction->create(); |
| 648 | - | 745 | + |
| 649 | DBUtil::commit(); | 746 | DBUtil::commit(); |
| 650 | 747 | ||
| 651 | $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | 748 | $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); |
| 652 | $aTriggers = $oKTTriggerRegistry->getTriggers('archive', 'postValidate'); | 749 | $aTriggers = $oKTTriggerRegistry->getTriggers('archive', 'postValidate'); |
| 653 | - foreach ($aTriggers as $aTrigger) | 750 | + foreach ($aTriggers as $aTrigger) |
| 654 | { | 751 | { |
| 655 | $sTrigger = $aTrigger[0]; | 752 | $sTrigger = $aTrigger[0]; |
| 656 | $oTrigger = new $sTrigger; | 753 | $oTrigger = new $sTrigger; |
| @@ -659,9 +756,9 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -659,9 +756,9 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 659 | ); | 756 | ); |
| 660 | $oTrigger->setInfo($aInfo); | 757 | $oTrigger->setInfo($aInfo); |
| 661 | $ret = $oTrigger->postValidate(); | 758 | $ret = $oTrigger->postValidate(); |
| 662 | - } | ||
| 663 | - } | ||
| 664 | - | 759 | + } |
| 760 | + } | ||
| 761 | + | ||
| 665 | /** | 762 | /** |
| 666 | * This starts a workflow on a document. | 763 | * This starts a workflow on a document. |
| 667 | * | 764 | * |
| @@ -675,20 +772,20 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -675,20 +772,20 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 675 | { | 772 | { |
| 676 | return $user; | 773 | return $user; |
| 677 | } | 774 | } |
| 678 | - | 775 | + |
| 679 | $workflowid = $this->document->getWorkflowId(); | 776 | $workflowid = $this->document->getWorkflowId(); |
| 680 | - | 777 | + |
| 681 | if (!empty($workflowid)) | 778 | if (!empty($workflowid)) |
| 682 | { | 779 | { |
| 683 | return new PEAR_Error('A workflow is already defined.'); | 780 | return new PEAR_Error('A workflow is already defined.'); |
| 684 | } | 781 | } |
| 685 | - | 782 | + |
| 686 | $workflow = KTWorkflow::getByName($workflow); | 783 | $workflow = KTWorkflow::getByName($workflow); |
| 687 | if (is_null($workflow) || PEAR::isError($workflow)) | 784 | if (is_null($workflow) || PEAR::isError($workflow)) |
| 688 | { | 785 | { |
| 689 | return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $workflow); | 786 | return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $workflow); |
| 690 | } | 787 | } |
| 691 | - | 788 | + |
| 692 | DBUtil::startTransaction(); | 789 | DBUtil::startTransaction(); |
| 693 | $result = KTWorkflowUtil::startWorkflowOnDocument($workflow, $this->document); | 790 | $result = KTWorkflowUtil::startWorkflowOnDocument($workflow, $this->document); |
| 694 | if (is_null($result) || PEAR::isError($result)) | 791 | if (is_null($result) || PEAR::isError($result)) |
| @@ -698,7 +795,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -698,7 +795,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 698 | } | 795 | } |
| 699 | DBUtil::commit(); | 796 | DBUtil::commit(); |
| 700 | } | 797 | } |
| 701 | - | 798 | + |
| 702 | /** | 799 | /** |
| 703 | * This deletes the workflow on the document. | 800 | * This deletes the workflow on the document. |
| 704 | * | 801 | * |
| @@ -711,13 +808,13 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -711,13 +808,13 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 711 | { | 808 | { |
| 712 | return $user; | 809 | return $user; |
| 713 | } | 810 | } |
| 714 | - | 811 | + |
| 715 | $workflowid=$this->document->getWorkflowId(); | 812 | $workflowid=$this->document->getWorkflowId(); |
| 716 | if (!empty($workflowid)) | 813 | if (!empty($workflowid)) |
| 717 | { | 814 | { |
| 718 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); | 815 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); |
| 719 | } | 816 | } |
| 720 | - | 817 | + |
| 721 | DBUtil::startTransaction(); | 818 | DBUtil::startTransaction(); |
| 722 | $result = KTWorkflowUtil::startWorkflowOnDocument(null, $this->document); | 819 | $result = KTWorkflowUtil::startWorkflowOnDocument(null, $this->document); |
| 723 | if (is_null($result) || PEAR::isError($result)) | 820 | if (is_null($result) || PEAR::isError($result)) |
| @@ -727,7 +824,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -727,7 +824,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 727 | } | 824 | } |
| 728 | DBUtil::commit(); | 825 | DBUtil::commit(); |
| 729 | } | 826 | } |
| 730 | - | 827 | + |
| 731 | /** | 828 | /** |
| 732 | * This performs a transition on the workflow | 829 | * This performs a transition on the workflow |
| 733 | * | 830 | * |
| @@ -742,19 +839,19 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -742,19 +839,19 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 742 | { | 839 | { |
| 743 | return $user; | 840 | return $user; |
| 744 | } | 841 | } |
| 745 | - | 842 | + |
| 746 | $workflowid=$this->document->getWorkflowId(); | 843 | $workflowid=$this->document->getWorkflowId(); |
| 747 | if (empty($workflowid)) | 844 | if (empty($workflowid)) |
| 748 | { | 845 | { |
| 749 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); | 846 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); |
| 750 | - } | ||
| 751 | - | 847 | + } |
| 848 | + | ||
| 752 | $transition = &KTWorkflowTransition::getByName($transition); | 849 | $transition = &KTWorkflowTransition::getByName($transition); |
| 753 | if (is_null($transition) || PEAR::isError($transition)) | 850 | if (is_null($transition) || PEAR::isError($transition)) |
| 754 | { | 851 | { |
| 755 | return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $transition); | 852 | return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $transition); |
| 756 | } | 853 | } |
| 757 | - | 854 | + |
| 758 | DBUtil::startTransaction(); | 855 | DBUtil::startTransaction(); |
| 759 | $result = KTWorkflowUtil::performTransitionOnDocument($transition, $this->document, $user, $reason); | 856 | $result = KTWorkflowUtil::performTransitionOnDocument($transition, $this->document, $user, $reason); |
| 760 | if (is_null($result) || PEAR::isError($result)) | 857 | if (is_null($result) || PEAR::isError($result)) |
| @@ -762,11 +859,11 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -762,11 +859,11 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 762 | DBUtil::rollback(); | 859 | DBUtil::rollback(); |
| 763 | return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $transition); | 860 | return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $transition); |
| 764 | } | 861 | } |
| 765 | - DBUtil::commit(); | ||
| 766 | - } | ||
| 767 | - | ||
| 768 | - | ||
| 769 | - | 862 | + DBUtil::commit(); |
| 863 | + } | ||
| 864 | + | ||
| 865 | + | ||
| 866 | + | ||
| 770 | /** | 867 | /** |
| 771 | * This returns all metadata for the document. | 868 | * This returns all metadata for the document. |
| 772 | * | 869 | * |
| @@ -776,31 +873,31 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -776,31 +873,31 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 776 | { | 873 | { |
| 777 | $doctypeid = $this->document->getDocumentTypeID(); | 874 | $doctypeid = $this->document->getDocumentTypeID(); |
| 778 | $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->document, $doctypeid); | 875 | $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->document, $doctypeid); |
| 779 | - | 876 | + |
| 780 | $results = array(); | 877 | $results = array(); |
| 781 | - | ||
| 782 | - foreach ($fieldsets as $fieldset) | 878 | + |
| 879 | + foreach ($fieldsets as $fieldset) | ||
| 783 | { | 880 | { |
| 784 | if ($fieldset->getIsConditional()) { /* this is not implemented...*/ continue; } | 881 | if ($fieldset->getIsConditional()) { /* this is not implemented...*/ continue; } |
| 785 | - | 882 | + |
| 786 | $fields = $fieldset->getFields(); | 883 | $fields = $fieldset->getFields(); |
| 787 | $result = array('fieldset' => $fieldset->getName(), | 884 | $result = array('fieldset' => $fieldset->getName(), |
| 788 | 'description' => $fieldset->getDescription()); | 885 | 'description' => $fieldset->getDescription()); |
| 789 | - | 886 | + |
| 790 | $fieldsresult = array(); | 887 | $fieldsresult = array(); |
| 791 | - | ||
| 792 | - foreach ($fields as $field) | ||
| 793 | - { | 888 | + |
| 889 | + foreach ($fields as $field) | ||
| 890 | + { | ||
| 794 | $value = 'n/a'; | 891 | $value = 'n/a'; |
| 795 | - | 892 | + |
| 796 | $fieldvalue = DocumentFieldLink::getByDocumentAndField($this->document, $field); | 893 | $fieldvalue = DocumentFieldLink::getByDocumentAndField($this->document, $field); |
| 797 | - if (!is_null($fieldvalue) && (!PEAR::isError($fieldvalue))) | 894 | + if (!is_null($fieldvalue) && (!PEAR::isError($fieldvalue))) |
| 798 | { | 895 | { |
| 799 | $value = $fieldvalue->getValue(); | 896 | $value = $fieldvalue->getValue(); |
| 800 | } | 897 | } |
| 801 | - | 898 | + |
| 802 | $controltype = 'string'; | 899 | $controltype = 'string'; |
| 803 | - if ($field->getHasLookup()) | 900 | + if ($field->getHasLookup()) |
| 804 | { | 901 | { |
| 805 | $controltype = 'lookup'; | 902 | $controltype = 'lookup'; |
| 806 | if ($field->getHasLookupTree()) | 903 | if ($field->getHasLookupTree()) |
| @@ -808,11 +905,11 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -808,11 +905,11 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 808 | $controltype = 'tree'; | 905 | $controltype = 'tree'; |
| 809 | } | 906 | } |
| 810 | } | 907 | } |
| 811 | - | 908 | + |
| 812 | switch ($controltype) | 909 | switch ($controltype) |
| 813 | { | 910 | { |
| 814 | case 'lookup': | 911 | case 'lookup': |
| 815 | - $selection = KTAPI::get_metadata_lookup($field->getId()); | 912 | + $selection = KTAPI::get_metadata_lookup($field->getId()); |
| 816 | break; | 913 | break; |
| 817 | case 'tree': | 914 | case 'tree': |
| 818 | $selection = KTAPI::get_metadata_tree($field->getId()); | 915 | $selection = KTAPI::get_metadata_tree($field->getId()); |
| @@ -821,7 +918,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -821,7 +918,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 821 | $selection= array(); | 918 | $selection= array(); |
| 822 | } | 919 | } |
| 823 | 920 | ||
| 824 | - | 921 | + |
| 825 | $fieldsresult[] = array( | 922 | $fieldsresult[] = array( |
| 826 | 'name' => $field->getName(), | 923 | 'name' => $field->getName(), |
| 827 | 'required' => $field->getIsMandatory(), | 924 | 'required' => $field->getIsMandatory(), |
| @@ -829,27 +926,27 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -829,27 +926,27 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 829 | 'description' => $field->getDescription(), | 926 | 'description' => $field->getDescription(), |
| 830 | 'control_type' => $controltype, | 927 | 'control_type' => $controltype, |
| 831 | 'selection' => $selection | 928 | 'selection' => $selection |
| 832 | - | 929 | + |
| 833 | ); | 930 | ); |
| 834 | - | 931 | + |
| 835 | } | 932 | } |
| 836 | $result['fields'] = $fieldsresult; | 933 | $result['fields'] = $fieldsresult; |
| 837 | - $results [] = $result; | ||
| 838 | - } | ||
| 839 | - | 934 | + $results [] = $result; |
| 935 | + } | ||
| 936 | + | ||
| 840 | return $results; | 937 | return $results; |
| 841 | } | 938 | } |
| 842 | - | 939 | + |
| 843 | /** | 940 | /** |
| 844 | * This updates the metadata on the file. This includes the 'title'. | 941 | * This updates the metadata on the file. This includes the 'title'. |
| 845 | * | 942 | * |
| 846 | * @param array This is an array containing the metadata to be associated with the file. | 943 | * @param array This is an array containing the metadata to be associated with the file. |
| 847 | */ | 944 | */ |
| 848 | function update_metadata($metadata) | 945 | function update_metadata($metadata) |
| 849 | - { | 946 | + { |
| 850 | global $default; | 947 | global $default; |
| 851 | $packed = array(); | 948 | $packed = array(); |
| 852 | - | 949 | + |
| 853 | foreach($metadata as $fieldset_metadata) | 950 | foreach($metadata as $fieldset_metadata) |
| 854 | { | 951 | { |
| 855 | if (is_array($fieldset_metadata)) | 952 | if (is_array($fieldset_metadata)) |
| @@ -875,7 +972,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -875,7 +972,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 875 | // exit graciously | 972 | // exit graciously |
| 876 | continue; | 973 | continue; |
| 877 | } | 974 | } |
| 878 | - | 975 | + |
| 879 | foreach($fields as $fieldinfo) | 976 | foreach($fields as $fieldinfo) |
| 880 | { | 977 | { |
| 881 | if (is_array($fieldinfo)) | 978 | if (is_array($fieldinfo)) |
| @@ -901,27 +998,27 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -901,27 +998,27 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 901 | // exit graciously | 998 | // exit graciously |
| 902 | continue; | 999 | continue; |
| 903 | } | 1000 | } |
| 904 | - | 1001 | + |
| 905 | $packed[] = array($field, $value); | 1002 | $packed[] = array($field, $value); |
| 906 | - } | 1003 | + } |
| 907 | } | 1004 | } |
| 908 | - | 1005 | + |
| 909 | DBUtil::startTransaction(); | 1006 | DBUtil::startTransaction(); |
| 910 | $result = KTDocumentUtil::saveMetadata($this->document, $packed); | 1007 | $result = KTDocumentUtil::saveMetadata($this->document, $packed); |
| 911 | - | 1008 | + |
| 912 | if (is_null($result)) | 1009 | if (is_null($result)) |
| 913 | { | 1010 | { |
| 914 | DBUtil::rollback(); | 1011 | DBUtil::rollback(); |
| 915 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR); | 1012 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR); |
| 916 | } | 1013 | } |
| 917 | - if (PEAR::isError($result)) | 1014 | + if (PEAR::isError($result)) |
| 918 | { | 1015 | { |
| 919 | DBUtil::rollback(); | 1016 | DBUtil::rollback(); |
| 920 | - return new KTAPI_Error(sprintf(_kt("Unexpected validation failure: %s."), $result->getMessage())); | 1017 | + return new KTAPI_Error(sprintf(_kt("Unexpected validation failure: %s."), $result->getMessage())); |
| 921 | } | 1018 | } |
| 922 | DBUtil::commit(); | 1019 | DBUtil::commit(); |
| 923 | } | 1020 | } |
| 924 | - | 1021 | + |
| 925 | 1022 | ||
| 926 | /** | 1023 | /** |
| 927 | * This returns a workflow transition | 1024 | * This returns a workflow transition |
| @@ -941,10 +1038,10 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -941,10 +1038,10 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 941 | if (empty($workflowid)) | 1038 | if (empty($workflowid)) |
| 942 | { | 1039 | { |
| 943 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); | 1040 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); |
| 944 | - } | ||
| 945 | - | 1041 | + } |
| 1042 | + | ||
| 946 | $result = array(); | 1043 | $result = array(); |
| 947 | - | 1044 | + |
| 948 | $transitions = KTWorkflowUtil::getTransitionsForDocumentUser($this->document, $user); | 1045 | $transitions = KTWorkflowUtil::getTransitionsForDocumentUser($this->document, $user); |
| 949 | if (is_null($transitions) || PEAR::isError($transitions)) | 1046 | if (is_null($transitions) || PEAR::isError($transitions)) |
| 950 | { | 1047 | { |
| @@ -954,10 +1051,10 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -954,10 +1051,10 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 954 | { | 1051 | { |
| 955 | $result[] = $transition->getName(); | 1052 | $result[] = $transition->getName(); |
| 956 | } | 1053 | } |
| 957 | - | ||
| 958 | - return $result; | 1054 | + |
| 1055 | + return $result; | ||
| 959 | } | 1056 | } |
| 960 | - | 1057 | + |
| 961 | /** | 1058 | /** |
| 962 | * This returns the current workflow state | 1059 | * This returns the current workflow state |
| 963 | * | 1060 | * |
| @@ -976,27 +1073,27 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -976,27 +1073,27 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 976 | if (empty($workflowid)) | 1073 | if (empty($workflowid)) |
| 977 | { | 1074 | { |
| 978 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); | 1075 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); |
| 979 | - } | ||
| 980 | - | 1076 | + } |
| 1077 | + | ||
| 981 | $result = array(); | 1078 | $result = array(); |
| 982 | - | 1079 | + |
| 983 | $state = KTWorkflowUtil::getWorkflowStateForDocument($this->document); | 1080 | $state = KTWorkflowUtil::getWorkflowStateForDocument($this->document); |
| 984 | if (is_null($state) || PEAR::isError($state)) | 1081 | if (is_null($state) || PEAR::isError($state)) |
| 985 | { | 1082 | { |
| 986 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_INVALID); | 1083 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_INVALID); |
| 987 | } | 1084 | } |
| 988 | - | 1085 | + |
| 989 | $statename = $state->getName(); | 1086 | $statename = $state->getName(); |
| 990 | - | ||
| 991 | - return $statename; | ||
| 992 | - | 1087 | + |
| 1088 | + return $statename; | ||
| 1089 | + | ||
| 993 | } | 1090 | } |
| 994 | - | 1091 | + |
| 995 | /** | 1092 | /** |
| 996 | * This returns detailed information on the document. | 1093 | * This returns detailed information on the document. |
| 997 | * | 1094 | * |
| 998 | * @return array | 1095 | * @return array |
| 999 | - */ | 1096 | + */ |
| 1000 | function get_detail() | 1097 | function get_detail() |
| 1001 | { | 1098 | { |
| 1002 | $detail = array(); | 1099 | $detail = array(); |
| @@ -1011,12 +1108,12 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1011,12 +1108,12 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1011 | 1108 | ||
| 1012 | $documenttype=$documenttype->getName(); | 1109 | $documenttype=$documenttype->getName(); |
| 1013 | } | 1110 | } |
| 1014 | - else | 1111 | + else |
| 1015 | { | 1112 | { |
| 1016 | $documenttype = '* unknown *'; | 1113 | $documenttype = '* unknown *'; |
| 1017 | } | 1114 | } |
| 1018 | $detail['document_type'] = $documenttype; | 1115 | $detail['document_type'] = $documenttype; |
| 1019 | - | 1116 | + |
| 1020 | $detail['version'] = $document->getVersion(); | 1117 | $detail['version'] = $document->getVersion(); |
| 1021 | $detail['filename'] = $document->getFilename(); | 1118 | $detail['filename'] = $document->getFilename(); |
| 1022 | 1119 | ||
| @@ -1028,7 +1125,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1028,7 +1125,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1028 | $user = User::get($userid); | 1125 | $user = User::get($userid); |
| 1029 | $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName(); | 1126 | $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName(); |
| 1030 | } | 1127 | } |
| 1031 | - else | 1128 | + else |
| 1032 | { | 1129 | { |
| 1033 | $username='n/a'; | 1130 | $username='n/a'; |
| 1034 | } | 1131 | } |
| @@ -1039,9 +1136,9 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1039,9 +1136,9 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1039 | if (is_numeric($userid)) | 1136 | if (is_numeric($userid)) |
| 1040 | { | 1137 | { |
| 1041 | $user = User::get($userid); | 1138 | $user = User::get($userid); |
| 1042 | - $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName(); | 1139 | + $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName(); |
| 1043 | } | 1140 | } |
| 1044 | - else | 1141 | + else |
| 1045 | { | 1142 | { |
| 1046 | $username='n/a'; | 1143 | $username='n/a'; |
| 1047 | } | 1144 | } |
| @@ -1055,7 +1152,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1055,7 +1152,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1055 | $workflow = KTWorkflow::get($workflowid); | 1152 | $workflow = KTWorkflow::get($workflowid); |
| 1056 | $workflowname=(is_null($workflow) || PEAR::isError($workflow))?'* unknown *':$workflow->getName(); | 1153 | $workflowname=(is_null($workflow) || PEAR::isError($workflow))?'* unknown *':$workflow->getName(); |
| 1057 | } | 1154 | } |
| 1058 | - else | 1155 | + else |
| 1059 | { | 1156 | { |
| 1060 | $workflowname='n/a'; | 1157 | $workflowname='n/a'; |
| 1061 | } | 1158 | } |
| @@ -1067,57 +1164,57 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1067,57 +1164,57 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1067 | $state = KTWorkflowState::get($stateid); | 1164 | $state = KTWorkflowState::get($stateid); |
| 1068 | $workflowstate=(is_null($state) || PEAR::isError($state))?'* unknown *':$state->getName(); | 1165 | $workflowstate=(is_null($state) || PEAR::isError($state))?'* unknown *':$state->getName(); |
| 1069 | } | 1166 | } |
| 1070 | - else | 1167 | + else |
| 1071 | { | 1168 | { |
| 1072 | $workflowstate = 'n/a'; | 1169 | $workflowstate = 'n/a'; |
| 1073 | } | 1170 | } |
| 1074 | $detail['workflow_state']=$workflowstate; | 1171 | $detail['workflow_state']=$workflowstate; |
| 1075 | 1172 | ||
| 1076 | $userid = $document->getCheckedOutUserID(); | 1173 | $userid = $document->getCheckedOutUserID(); |
| 1077 | - | 1174 | + |
| 1078 | if (is_numeric($userid)) | 1175 | if (is_numeric($userid)) |
| 1079 | { | 1176 | { |
| 1080 | $user = User::get($userid); | 1177 | $user = User::get($userid); |
| 1081 | $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName(); | 1178 | $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName(); |
| 1082 | } | 1179 | } |
| 1083 | - else | 1180 | + else |
| 1084 | { | 1181 | { |
| 1085 | $username = 'n/a'; | 1182 | $username = 'n/a'; |
| 1086 | } | 1183 | } |
| 1087 | $detail['checkout_by'] = $username; | 1184 | $detail['checkout_by'] = $username; |
| 1088 | - | 1185 | + |
| 1089 | $detail['full_path'] = $this->ktapi_folder->get_full_path() . '/' . $this->get_title(); | 1186 | $detail['full_path'] = $this->ktapi_folder->get_full_path() . '/' . $this->get_title(); |
| 1090 | - | 1187 | + |
| 1091 | return $detail; | 1188 | return $detail; |
| 1092 | } | 1189 | } |
| 1093 | - | 1190 | + |
| 1094 | function get_title() | 1191 | function get_title() |
| 1095 | { | 1192 | { |
| 1096 | return $this->document->getDescription(); | 1193 | return $this->document->getDescription(); |
| 1097 | } | 1194 | } |
| 1098 | - | 1195 | + |
| 1099 | /** | 1196 | /** |
| 1100 | * This does a download of a version of the document. | 1197 | * This does a download of a version of the document. |
| 1101 | * | 1198 | * |
| 1102 | * @param string $version | 1199 | * @param string $version |
| 1103 | */ | 1200 | */ |
| 1104 | function download($version=null) | 1201 | function download($version=null) |
| 1105 | - { | 1202 | + { |
| 1106 | $storage =& KTStorageManagerUtil::getSingleton(); | 1203 | $storage =& KTStorageManagerUtil::getSingleton(); |
| 1107 | $options = array(); | 1204 | $options = array(); |
| 1108 | - | ||
| 1109 | - | 1205 | + |
| 1206 | + | ||
| 1110 | $oDocumentTransaction = & new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions); | 1207 | $oDocumentTransaction = & new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions); |
| 1111 | $oDocumentTransaction->create(); | 1208 | $oDocumentTransaction->create(); |
| 1112 | } | 1209 | } |
| 1113 | - | 1210 | + |
| 1114 | /** | 1211 | /** |
| 1115 | * This returns the transaction history for the document. | 1212 | * This returns the transaction history for the document. |
| 1116 | * | 1213 | * |
| 1117 | * @return array | 1214 | * @return array |
| 1118 | */ | 1215 | */ |
| 1119 | function get_transaction_history() | 1216 | function get_transaction_history() |
| 1120 | - { | 1217 | + { |
| 1121 | $sQuery = 'SELECT DTT.name AS transaction_name, U.name AS username, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime ' . | 1218 | $sQuery = 'SELECT DTT.name AS transaction_name, U.name AS username, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime ' . |
| 1122 | 'FROM ' . KTUtil::getTableName('document_transactions') . ' AS DT INNER JOIN ' . KTUtil::getTableName('users') . ' AS U ON DT.user_id = U.id ' . | 1219 | 'FROM ' . KTUtil::getTableName('document_transactions') . ' AS DT INNER JOIN ' . KTUtil::getTableName('users') . ' AS U ON DT.user_id = U.id ' . |
| 1123 | 'INNER JOIN ' . KTUtil::getTableName('transaction_types') . ' AS DTT ON DTT.namespace = DT.transaction_namespace ' . | 1220 | 'INNER JOIN ' . KTUtil::getTableName('transaction_types') . ' AS DTT ON DTT.namespace = DT.transaction_namespace ' . |
| @@ -1125,14 +1222,14 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1125,14 +1222,14 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1125 | $aParams = array($this->documentid); | 1222 | $aParams = array($this->documentid); |
| 1126 | 1223 | ||
| 1127 | $transactions = DBUtil::getResultArray(array($sQuery, $aParams)); | 1224 | $transactions = DBUtil::getResultArray(array($sQuery, $aParams)); |
| 1128 | - if (is_null($transactions) || PEAR::isError($transactions)) | 1225 | + if (is_null($transactions) || PEAR::isError($transactions)) |
| 1129 | { | 1226 | { |
| 1130 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $transactions ); | 1227 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $transactions ); |
| 1131 | } | 1228 | } |
| 1132 | 1229 | ||
| 1133 | return $transactions; | 1230 | return $transactions; |
| 1134 | } | 1231 | } |
| 1135 | - | 1232 | + |
| 1136 | /** | 1233 | /** |
| 1137 | * This returns the version history on the document. | 1234 | * This returns the version history on the document. |
| 1138 | * | 1235 | * |
| @@ -1141,21 +1238,21 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1141,21 +1238,21 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1141 | function get_version_history() | 1238 | function get_version_history() |
| 1142 | { | 1239 | { |
| 1143 | $metadata_versions = KTDocumentMetadataVersion::getByDocument($this->document); | 1240 | $metadata_versions = KTDocumentMetadataVersion::getByDocument($this->document); |
| 1144 | - | 1241 | + |
| 1145 | $versions = array(); | 1242 | $versions = array(); |
| 1146 | - foreach ($metadata_versions as $version) | 1243 | + foreach ($metadata_versions as $version) |
| 1147 | { | 1244 | { |
| 1148 | $document = &Document::get($this->documentid, $version->getId()); | 1245 | $document = &Document::get($this->documentid, $version->getId()); |
| 1149 | - | 1246 | + |
| 1150 | $version = array(); | 1247 | $version = array(); |
| 1151 | - | ||
| 1152 | - $userid = $document->getModifiedUserId(); | ||
| 1153 | - $user = User::get($userid); | ||
| 1154 | - | 1248 | + |
| 1249 | + $userid = $document->getModifiedUserId(); | ||
| 1250 | + $user = User::get($userid); | ||
| 1251 | + | ||
| 1155 | $version['user'] = $user->getName(); | 1252 | $version['user'] = $user->getName(); |
| 1156 | $version['metadata_version'] = $document->getMetadataVersion(); | 1253 | $version['metadata_version'] = $document->getMetadataVersion(); |
| 1157 | $version['content_version'] = $document->getVersion(); | 1254 | $version['content_version'] = $document->getVersion(); |
| 1158 | - | 1255 | + |
| 1159 | $versions[] = $version; | 1256 | $versions[] = $version; |
| 1160 | } | 1257 | } |
| 1161 | return $versions; | 1258 | return $versions; |
| @@ -1173,22 +1270,22 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1173,22 +1270,22 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1173 | return new PEAR_Error('You should not purge this'); | 1270 | return new PEAR_Error('You should not purge this'); |
| 1174 | } | 1271 | } |
| 1175 | DBUtil::startTransaction(); | 1272 | DBUtil::startTransaction(); |
| 1176 | - | 1273 | + |
| 1177 | $transaction = & new DocumentTransaction($this->document, "Document expunged", 'ktcore.transactions.expunge'); | 1274 | $transaction = & new DocumentTransaction($this->document, "Document expunged", 'ktcore.transactions.expunge'); |
| 1178 | - | 1275 | + |
| 1179 | $transaction->create(); | 1276 | $transaction->create(); |
| 1180 | - | 1277 | + |
| 1181 | $this->document->delete(); | 1278 | $this->document->delete(); |
| 1182 | - | ||
| 1183 | - $this->document->cleanupDocumentData($this->documentid); | ||
| 1184 | - | 1279 | + |
| 1280 | + $this->document->cleanupDocumentData($this->documentid); | ||
| 1281 | + | ||
| 1185 | $storage =& KTStorageManagerUtil::getSingleton(); | 1282 | $storage =& KTStorageManagerUtil::getSingleton(); |
| 1186 | - | 1283 | + |
| 1187 | $result= $storage->expunge($this->document); | 1284 | $result= $storage->expunge($this->document); |
| 1188 | 1285 | ||
| 1189 | DBUtil::commit(); | 1286 | DBUtil::commit(); |
| 1190 | } | 1287 | } |
| 1191 | - | 1288 | + |
| 1192 | /** | 1289 | /** |
| 1193 | * This expunges a document from the system. | 1290 | * This expunges a document from the system. |
| 1194 | * | 1291 | * |
| @@ -1197,28 +1294,28 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1197,28 +1294,28 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1197 | function restore() | 1294 | function restore() |
| 1198 | { | 1295 | { |
| 1199 | DBUtil::startTransaction(); | 1296 | DBUtil::startTransaction(); |
| 1200 | - | 1297 | + |
| 1201 | $storage =& KTStorageManagerUtil::getSingleton(); | 1298 | $storage =& KTStorageManagerUtil::getSingleton(); |
| 1202 | - | 1299 | + |
| 1203 | $folder = Folder::get($this->document->getRestoreFolderId()); | 1300 | $folder = Folder::get($this->document->getRestoreFolderId()); |
| 1204 | - if (PEAR::isError($folder)) | 1301 | + if (PEAR::isError($folder)) |
| 1205 | { | 1302 | { |
| 1206 | $this->document->setFolderId(1); | 1303 | $this->document->setFolderId(1); |
| 1207 | $folder = Folder::get(1); | 1304 | $folder = Folder::get(1); |
| 1208 | } | 1305 | } |
| 1209 | - else | 1306 | + else |
| 1210 | { | 1307 | { |
| 1211 | $this->document->setFolderId($this->document->getRestoreFolderId()); | 1308 | $this->document->setFolderId($this->document->getRestoreFolderId()); |
| 1212 | } | 1309 | } |
| 1213 | 1310 | ||
| 1214 | $storage->restore($this->document); | 1311 | $storage->restore($this->document); |
| 1215 | - | 1312 | + |
| 1216 | $this->document->setStatusId(LIVE); | 1313 | $this->document->setStatusId(LIVE); |
| 1217 | $this->document->setPermissionObjectId($folder->getPermissionObjectId()); | 1314 | $this->document->setPermissionObjectId($folder->getPermissionObjectId()); |
| 1218 | $res = $this->document->update(); | 1315 | $res = $this->document->update(); |
| 1219 | 1316 | ||
| 1220 | $res = KTPermissionUtil::updatePermissionLookup($this->document); | 1317 | $res = KTPermissionUtil::updatePermissionLookup($this->document); |
| 1221 | - | 1318 | + |
| 1222 | $user = $this->ktapi->get_user(); | 1319 | $user = $this->ktapi->get_user(); |
| 1223 | 1320 | ||
| 1224 | $oTransaction = new DocumentTransaction($this->document, 'Restored from deleted state by ' . $user->getName(), 'ktcore.transactions.update'); | 1321 | $oTransaction = new DocumentTransaction($this->document, 'Restored from deleted state by ' . $user->getName(), 'ktcore.transactions.update'); |
ktapi/KTAPIFolder.inc.php
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | * License Version 1.1.2 ("License"); You may not use this file except in | 6 | * License Version 1.1.2 ("License"); You may not use this file except in |
| 7 | * compliance with the License. You may obtain a copy of the License at | 7 | * compliance with the License. You may obtain a copy of the License at |
| 8 | * http://www.knowledgetree.com/KPL | 8 | * http://www.knowledgetree.com/KPL |
| 9 | - * | 9 | + * |
| 10 | * Software distributed under the License is distributed on an "AS IS" | 10 | * Software distributed under the License is distributed on an "AS IS" |
| 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing rights and | 12 | * See the License for the specific language governing rights and |
| @@ -17,9 +17,9 @@ | @@ -17,9 +17,9 @@ | ||
| 17 | * (ii) the KnowledgeTree copyright notice | 17 | * (ii) the KnowledgeTree copyright notice |
| 18 | * in the same form as they appear in the distribution. See the License for | 18 | * in the same form as they appear in the distribution. See the License for |
| 19 | * requirements. | 19 | * requirements. |
| 20 | - * | 20 | + * |
| 21 | * The Original Code is: KnowledgeTree Open Source | 21 | * The Original Code is: KnowledgeTree Open Source |
| 22 | - * | 22 | + * |
| 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software | 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software |
| 24 | * (Pty) Ltd, trading as KnowledgeTree. | 24 | * (Pty) Ltd, trading as KnowledgeTree. |
| 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright |
| @@ -30,7 +30,7 @@ | @@ -30,7 +30,7 @@ | ||
| 30 | */ | 30 | */ |
| 31 | 31 | ||
| 32 | class KTAPI_Folder extends KTAPI_FolderItem | 32 | class KTAPI_Folder extends KTAPI_FolderItem |
| 33 | -{ | 33 | +{ |
| 34 | /** | 34 | /** |
| 35 | * This is a reference to a base Folder object. | 35 | * This is a reference to a base Folder object. |
| 36 | * | 36 | * |
| @@ -38,7 +38,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -38,7 +38,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 38 | * @var Folder | 38 | * @var Folder |
| 39 | */ | 39 | */ |
| 40 | var $folder; | 40 | var $folder; |
| 41 | - | 41 | + |
| 42 | /** | 42 | /** |
| 43 | * This is the id of the folder on the database. | 43 | * This is the id of the folder on the database. |
| 44 | * | 44 | * |
| @@ -60,25 +60,25 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -60,25 +60,25 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 60 | assert(!is_null($ktapi)); | 60 | assert(!is_null($ktapi)); |
| 61 | assert(is_a($ktapi, 'KTAPI')); | 61 | assert(is_a($ktapi, 'KTAPI')); |
| 62 | assert(is_numeric($folderid)); | 62 | assert(is_numeric($folderid)); |
| 63 | - | 63 | + |
| 64 | $folderid += 0; | 64 | $folderid += 0; |
| 65 | - | 65 | + |
| 66 | $folder = &Folder::get($folderid); | 66 | $folder = &Folder::get($folderid); |
| 67 | if (is_null($folder) || PEAR::isError($folder)) | 67 | if (is_null($folder) || PEAR::isError($folder)) |
| 68 | { | 68 | { |
| 69 | return new KTAPI_Error(KTAPI_ERROR_FOLDER_INVALID,$folder); | 69 | return new KTAPI_Error(KTAPI_ERROR_FOLDER_INVALID,$folder); |
| 70 | } | 70 | } |
| 71 | - | 71 | + |
| 72 | $user = $ktapi->can_user_access_object_requiring_permission($folder, KTAPI_PERMISSION_READ); | 72 | $user = $ktapi->can_user_access_object_requiring_permission($folder, KTAPI_PERMISSION_READ); |
| 73 | - | 73 | + |
| 74 | if (is_null($user) || PEAR::isError($user)) | 74 | if (is_null($user) || PEAR::isError($user)) |
| 75 | { | 75 | { |
| 76 | return $user; | 76 | return $user; |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | - return new KTAPI_Folder($ktapi, $folder); | ||
| 80 | - } | ||
| 81 | - | 79 | + return new KTAPI_Folder($ktapi, $folder); |
| 80 | + } | ||
| 81 | + | ||
| 82 | /** | 82 | /** |
| 83 | * This is the constructor for the KTAPI_Folder. | 83 | * This is the constructor for the KTAPI_Folder. |
| 84 | * | 84 | * |
| @@ -90,27 +90,27 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -90,27 +90,27 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 90 | function KTAPI_Folder(&$ktapi, &$folder) | 90 | function KTAPI_Folder(&$ktapi, &$folder) |
| 91 | { | 91 | { |
| 92 | $this->ktapi = &$ktapi; | 92 | $this->ktapi = &$ktapi; |
| 93 | - $this->folder = &$folder; | 93 | + $this->folder = &$folder; |
| 94 | $this->folderid = $folder->getId(); | 94 | $this->folderid = $folder->getId(); |
| 95 | } | 95 | } |
| 96 | - | 96 | + |
| 97 | /** | 97 | /** |
| 98 | * This returns a reference to the internal folder object. | 98 | * This returns a reference to the internal folder object. |
| 99 | * | 99 | * |
| 100 | * @access protected | 100 | * @access protected |
| 101 | * @return Folder | 101 | * @return Folder |
| 102 | - */ | 102 | + */ |
| 103 | function &get_folder() | 103 | function &get_folder() |
| 104 | { | 104 | { |
| 105 | return $this->folder; | 105 | return $this->folder; |
| 106 | } | 106 | } |
| 107 | - | ||
| 108 | - | 107 | + |
| 108 | + | ||
| 109 | /** | 109 | /** |
| 110 | * This returns detailed information on the document. | 110 | * This returns detailed information on the document. |
| 111 | * | 111 | * |
| 112 | * @return array | 112 | * @return array |
| 113 | - */ | 113 | + */ |
| 114 | function get_detail() | 114 | function get_detail() |
| 115 | { | 115 | { |
| 116 | $detail = array( | 116 | $detail = array( |
| @@ -119,21 +119,21 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -119,21 +119,21 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 119 | 'parent_id'=>(int) $this->get_parent_folder_id(), | 119 | 'parent_id'=>(int) $this->get_parent_folder_id(), |
| 120 | 'full_path'=>$this->get_full_path(), | 120 | 'full_path'=>$this->get_full_path(), |
| 121 | ); | 121 | ); |
| 122 | - | 122 | + |
| 123 | return $detail; | 123 | return $detail; |
| 124 | } | 124 | } |
| 125 | - | 125 | + |
| 126 | function get_parent_folder_id() | 126 | function get_parent_folder_id() |
| 127 | { | 127 | { |
| 128 | return (int) $this->folder->getParentID(); | 128 | return (int) $this->folder->getParentID(); |
| 129 | } | 129 | } |
| 130 | - | 130 | + |
| 131 | function get_folder_name() | 131 | function get_folder_name() |
| 132 | { | 132 | { |
| 133 | return $this->folder->getFolderName($this->folderid); | 133 | return $this->folder->getFolderName($this->folderid); |
| 134 | } | 134 | } |
| 135 | - | ||
| 136 | - | 135 | + |
| 136 | + | ||
| 137 | /** | 137 | /** |
| 138 | * This returns the folderid. | 138 | * This returns the folderid. |
| 139 | * | 139 | * |
| @@ -143,14 +143,14 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -143,14 +143,14 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 143 | { | 143 | { |
| 144 | return (int) $this->folderid; | 144 | return (int) $this->folderid; |
| 145 | } | 145 | } |
| 146 | - | 146 | + |
| 147 | /** | 147 | /** |
| 148 | * This can resolve a folder relative to the current directy by name | 148 | * This can resolve a folder relative to the current directy by name |
| 149 | * | 149 | * |
| 150 | * @access public | 150 | * @access public |
| 151 | * @param string $foldername | 151 | * @param string $foldername |
| 152 | * @return KTAPI_Folder | 152 | * @return KTAPI_Folder |
| 153 | - */ | 153 | + */ |
| 154 | function &get_folder_by_name($foldername) | 154 | function &get_folder_by_name($foldername) |
| 155 | { | 155 | { |
| 156 | $foldername=trim($foldername); | 156 | $foldername=trim($foldername); |
| @@ -158,9 +158,9 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -158,9 +158,9 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 158 | { | 158 | { |
| 159 | return new PEAR_Error('A valid folder name must be specified.'); | 159 | return new PEAR_Error('A valid folder name must be specified.'); |
| 160 | } | 160 | } |
| 161 | - | 161 | + |
| 162 | $split = explode('/', $foldername); | 162 | $split = explode('/', $foldername); |
| 163 | - | 163 | + |
| 164 | $folderid=$this->folderid; | 164 | $folderid=$this->folderid; |
| 165 | foreach($split as $foldername) | 165 | foreach($split as $foldername) |
| 166 | { | 166 | { |
| @@ -174,19 +174,19 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -174,19 +174,19 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 174 | { | 174 | { |
| 175 | return new KTAPI_Error(KTAPI_ERROR_FOLDER_INVALID,$row); | 175 | return new KTAPI_Error(KTAPI_ERROR_FOLDER_INVALID,$row); |
| 176 | } | 176 | } |
| 177 | - $folderid = $row['id']; | 177 | + $folderid = $row['id']; |
| 178 | } | 178 | } |
| 179 | - | ||
| 180 | - return KTAPI_Folder::get($this->ktapi, $folderid); | 179 | + |
| 180 | + return KTAPI_Folder::get($this->ktapi, $folderid); | ||
| 181 | } | 181 | } |
| 182 | - | 182 | + |
| 183 | function get_full_path() | 183 | function get_full_path() |
| 184 | { | 184 | { |
| 185 | $path = $this->folder->getFullPath() . '/' . $this->folder->getName(); | 185 | $path = $this->folder->getFullPath() . '/' . $this->folder->getName(); |
| 186 | - | 186 | + |
| 187 | return $path; | 187 | return $path; |
| 188 | } | 188 | } |
| 189 | - | 189 | + |
| 190 | /** | 190 | /** |
| 191 | * This gets a document by filename or name. | 191 | * This gets a document by filename or name. |
| 192 | * | 192 | * |
| @@ -194,7 +194,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -194,7 +194,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 194 | * @param string $documentname | 194 | * @param string $documentname |
| 195 | * @param string $function | 195 | * @param string $function |
| 196 | * @return KTAPI_Document | 196 | * @return KTAPI_Document |
| 197 | - */ | 197 | + */ |
| 198 | function &_get_document_by_name($documentname, $function='getByNameAndFolder') | 198 | function &_get_document_by_name($documentname, $function='getByNameAndFolder') |
| 199 | { | 199 | { |
| 200 | $documentname=trim($documentname); | 200 | $documentname=trim($documentname); |
| @@ -202,68 +202,68 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -202,68 +202,68 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 202 | { | 202 | { |
| 203 | return new PEAR_Error('A valid document name must be specified.'); | 203 | return new PEAR_Error('A valid document name must be specified.'); |
| 204 | } | 204 | } |
| 205 | - | 205 | + |
| 206 | $foldername = dirname($documentname); | 206 | $foldername = dirname($documentname); |
| 207 | $documentname = basename($documentname); | 207 | $documentname = basename($documentname); |
| 208 | - | 208 | + |
| 209 | $ktapi_folder = $this; | 209 | $ktapi_folder = $this; |
| 210 | - | 210 | + |
| 211 | if (!empty($foldername) && ($foldername != '.')) | 211 | if (!empty($foldername) && ($foldername != '.')) |
| 212 | { | 212 | { |
| 213 | $ktapi_folder = $this->get_folder_by_name($foldername); | 213 | $ktapi_folder = $this->get_folder_by_name($foldername); |
| 214 | } | 214 | } |
| 215 | - | 215 | + |
| 216 | if (is_null($ktapi_folder) || PEAR::isError($ktapi_folder)) | 216 | if (is_null($ktapi_folder) || PEAR::isError($ktapi_folder)) |
| 217 | { | 217 | { |
| 218 | return new KTAPI_Error(KTAPI_ERROR_FOLDER_INVALID, $ktapi_folder); | 218 | return new KTAPI_Error(KTAPI_ERROR_FOLDER_INVALID, $ktapi_folder); |
| 219 | } | 219 | } |
| 220 | - | 220 | + |
| 221 | //$folder = $ktapi_folder->get_folder(); | 221 | //$folder = $ktapi_folder->get_folder(); |
| 222 | $folderid = $ktapi_folder->folderid; | 222 | $folderid = $ktapi_folder->folderid; |
| 223 | - | ||
| 224 | - $document = Document::$function($documentname, $folderid); | 223 | + |
| 224 | + $document = Document::$function($documentname, $folderid); | ||
| 225 | if (is_null($document) || PEAR::isError($document)) | 225 | if (is_null($document) || PEAR::isError($document)) |
| 226 | { | 226 | { |
| 227 | return new KTAPI_Error(KTAPI_ERROR_DOCUMENT_INVALID, $document); | 227 | return new KTAPI_Error(KTAPI_ERROR_DOCUMENT_INVALID, $document); |
| 228 | } | 228 | } |
| 229 | - | ||
| 230 | - $user = $this->can_user_access_object_requiring_permission($document, KTAPI_PERMISSION_READ); | 229 | + |
| 230 | + $user = $this->can_user_access_object_requiring_permission($document, KTAPI_PERMISSION_READ); | ||
| 231 | if (PEAR::isError($user)) | 231 | if (PEAR::isError($user)) |
| 232 | { | 232 | { |
| 233 | return $user; | 233 | return $user; |
| 234 | } | 234 | } |
| 235 | - | 235 | + |
| 236 | return new KTAPI_Document($this->ktapi, $ktapi_folder, $document); | 236 | return new KTAPI_Document($this->ktapi, $ktapi_folder, $document); |
| 237 | } | 237 | } |
| 238 | - | 238 | + |
| 239 | /** | 239 | /** |
| 240 | * This can resolve a document relative to the current directy by name. | 240 | * This can resolve a document relative to the current directy by name. |
| 241 | * | 241 | * |
| 242 | * @access public | 242 | * @access public |
| 243 | * @param string $documentname | 243 | * @param string $documentname |
| 244 | * @return KTAPI_Document | 244 | * @return KTAPI_Document |
| 245 | - */ | 245 | + */ |
| 246 | function &get_document_by_name($documentname) | 246 | function &get_document_by_name($documentname) |
| 247 | { | 247 | { |
| 248 | return $this->_get_document_by_name($documentname,'getByNameAndFolder'); | 248 | return $this->_get_document_by_name($documentname,'getByNameAndFolder'); |
| 249 | } | 249 | } |
| 250 | - | 250 | + |
| 251 | /** | 251 | /** |
| 252 | * This can resolve a document relative to the current directy by filename . | 252 | * This can resolve a document relative to the current directy by filename . |
| 253 | * | 253 | * |
| 254 | * @access public | 254 | * @access public |
| 255 | * @param string $documentname | 255 | * @param string $documentname |
| 256 | * @return KTAPI_Document | 256 | * @return KTAPI_Document |
| 257 | - */ | 257 | + */ |
| 258 | function &get_document_by_filename($documentname) | 258 | function &get_document_by_filename($documentname) |
| 259 | { | 259 | { |
| 260 | return $this->_get_document_by_name($documentname,'getByFilenameAndFolder'); | 260 | return $this->_get_document_by_name($documentname,'getByFilenameAndFolder'); |
| 261 | - } | ||
| 262 | - | 261 | + } |
| 262 | + | ||
| 263 | function _resolve_user($userid) | 263 | function _resolve_user($userid) |
| 264 | { | 264 | { |
| 265 | $user=null; | 265 | $user=null; |
| 266 | - | 266 | + |
| 267 | if (!is_null($userid)) | 267 | if (!is_null($userid)) |
| 268 | { | 268 | { |
| 269 | $user=User::get($userid); | 269 | $user=User::get($userid); |
| @@ -274,24 +274,24 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -274,24 +274,24 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 274 | } | 274 | } |
| 275 | return $user; | 275 | return $user; |
| 276 | } | 276 | } |
| 277 | - | ||
| 278 | - | 277 | + |
| 278 | + | ||
| 279 | function get_listing($depth=1, $what='DF') | 279 | function get_listing($depth=1, $what='DF') |
| 280 | - { | ||
| 281 | - if ($depth < 1) | 280 | + { |
| 281 | + if ($depth < 1) | ||
| 282 | { | 282 | { |
| 283 | return array(); | 283 | return array(); |
| 284 | } | 284 | } |
| 285 | - | 285 | + |
| 286 | $what = strtoupper($what); | 286 | $what = strtoupper($what); |
| 287 | - $read_permission = &KTPermission::getByName(KTAPI_PERMISSION_READ); | 287 | + $read_permission = &KTPermission::getByName(KTAPI_PERMISSION_READ); |
| 288 | $folder_permission = &KTPermission::getByName(KTAPI_PERMISSION_VIEW_FOLDER); | 288 | $folder_permission = &KTPermission::getByName(KTAPI_PERMISSION_VIEW_FOLDER); |
| 289 | - | ||
| 290 | - | 289 | + |
| 290 | + | ||
| 291 | $user = $this->ktapi->get_user(); | 291 | $user = $this->ktapi->get_user(); |
| 292 | 292 | ||
| 293 | $contents = array(); | 293 | $contents = array(); |
| 294 | - | 294 | + |
| 295 | if (strpos($what,'F') !== false) | 295 | if (strpos($what,'F') !== false) |
| 296 | { | 296 | { |
| 297 | $folder_children = Folder::getList(array('parent_id = ?', $this->folderid)); | 297 | $folder_children = Folder::getList(array('parent_id = ?', $this->folderid)); |
| @@ -369,7 +369,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -369,7 +369,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 369 | $mimeinfo=$mime_cache[$mimetypeid]; | 369 | $mimeinfo=$mime_cache[$mimetypeid]; |
| 370 | 370 | ||
| 371 | $workflow = KTWorkflowUtil::getWorkflowForDocument($document); | 371 | $workflow = KTWorkflowUtil::getWorkflowForDocument($document); |
| 372 | - | 372 | + |
| 373 | if (!is_null($workflow) && !PEAR::isError($workflow)) | 373 | if (!is_null($workflow) && !PEAR::isError($workflow)) |
| 374 | { | 374 | { |
| 375 | $workflow=$workflow->getHumanName(); | 375 | $workflow=$workflow->getHumanName(); |
| @@ -384,13 +384,13 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -384,13 +384,13 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 384 | $state='n/a'; | 384 | $state='n/a'; |
| 385 | } | 385 | } |
| 386 | } | 386 | } |
| 387 | - else | 387 | + else |
| 388 | { | 388 | { |
| 389 | $workflow='n/a'; | 389 | $workflow='n/a'; |
| 390 | $state='n/a'; | 390 | $state='n/a'; |
| 391 | } | 391 | } |
| 392 | - | ||
| 393 | - | 392 | + |
| 393 | + | ||
| 394 | $contents[] = array( | 394 | $contents[] = array( |
| 395 | 'id' => (int) $document->getId(), | 395 | 'id' => (int) $document->getId(), |
| 396 | 'item_type'=>'D', | 396 | 'item_type'=>'D', |
| @@ -414,10 +414,10 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -414,10 +414,10 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 414 | } | 414 | } |
| 415 | 415 | ||
| 416 | } | 416 | } |
| 417 | - | ||
| 418 | - return $contents; | 417 | + |
| 418 | + return $contents; | ||
| 419 | } | 419 | } |
| 420 | - | 420 | + |
| 421 | /** | 421 | /** |
| 422 | * This adds a document to the current folder. | 422 | * This adds a document to the current folder. |
| 423 | * | 423 | * |
| @@ -427,20 +427,20 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -427,20 +427,20 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 427 | * @param string $documenttype This is the name or id of the document type. It first looks by name, then by id. | 427 | * @param string $documenttype This is the name or id of the document type. It first looks by name, then by id. |
| 428 | * @param string $tempfilename This is a reference to the file that is accessible locally on the file system. | 428 | * @param string $tempfilename This is a reference to the file that is accessible locally on the file system. |
| 429 | * @return KTAPI_Document | 429 | * @return KTAPI_Document |
| 430 | - */ | 430 | + */ |
| 431 | function &add_document($title, $filename, $documenttype, $tempfilename) | 431 | function &add_document($title, $filename, $documenttype, $tempfilename) |
| 432 | { | 432 | { |
| 433 | if (!is_file($tempfilename)) | 433 | if (!is_file($tempfilename)) |
| 434 | { | 434 | { |
| 435 | return new PEAR_Error('File does not exist.'); | 435 | return new PEAR_Error('File does not exist.'); |
| 436 | } | 436 | } |
| 437 | - | ||
| 438 | - $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); | 437 | + |
| 438 | + $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); | ||
| 439 | if (PEAR::isError($user)) | 439 | if (PEAR::isError($user)) |
| 440 | { | 440 | { |
| 441 | return $user; | 441 | return $user; |
| 442 | } | 442 | } |
| 443 | - | 443 | + |
| 444 | $filename = basename($filename); | 444 | $filename = basename($filename); |
| 445 | $documenttypeid = KTAPI::get_documenttypeid($documenttype); | 445 | $documenttypeid = KTAPI::get_documenttypeid($documenttype); |
| 446 | 446 | ||
| @@ -449,7 +449,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -449,7 +449,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 449 | 'novalidate' => true, | 449 | 'novalidate' => true, |
| 450 | 'documenttype' => DocumentType::get($documenttypeid), | 450 | 'documenttype' => DocumentType::get($documenttypeid), |
| 451 | 'description' => $title, | 451 | 'description' => $title, |
| 452 | - 'metadata'=>array(), | 452 | + 'metadata'=>array(), |
| 453 | 'cleanup_initial_file' => true | 453 | 'cleanup_initial_file' => true |
| 454 | ); | 454 | ); |
| 455 | 455 | ||
| @@ -462,10 +462,10 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -462,10 +462,10 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 462 | return new PEAR_Error(KTAPI_ERROR_INTERNAL_ERROR . ' : ' . $document->getMessage()); | 462 | return new PEAR_Error(KTAPI_ERROR_INTERNAL_ERROR . ' : ' . $document->getMessage()); |
| 463 | } | 463 | } |
| 464 | DBUtil::commit(); | 464 | DBUtil::commit(); |
| 465 | - | 465 | + |
| 466 | $tempfilename=addslashes($tempfilename); | 466 | $tempfilename=addslashes($tempfilename); |
| 467 | $sql = "DELETE FROM uploaded_files WHERE tempfilename='$tempfilename'"; | 467 | $sql = "DELETE FROM uploaded_files WHERE tempfilename='$tempfilename'"; |
| 468 | - $result = DBUtil::runQuery($sql); | 468 | + $result = DBUtil::runQuery($sql); |
| 469 | if (PEAR::isError($result)) | 469 | if (PEAR::isError($result)) |
| 470 | { | 470 | { |
| 471 | return $result; | 471 | return $result; |
| @@ -473,26 +473,26 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -473,26 +473,26 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 473 | 473 | ||
| 474 | return new KTAPI_Document($this->ktapi, $this, $document); | 474 | return new KTAPI_Document($this->ktapi, $this, $document); |
| 475 | } | 475 | } |
| 476 | - | 476 | + |
| 477 | /** | 477 | /** |
| 478 | * This adds a subfolder folder to the current folder. | 478 | * This adds a subfolder folder to the current folder. |
| 479 | * | 479 | * |
| 480 | * @access public | 480 | * @access public |
| 481 | * @param string $foldername | 481 | * @param string $foldername |
| 482 | * @return KTAPI_Folder | 482 | * @return KTAPI_Folder |
| 483 | - */ | 483 | + */ |
| 484 | function &add_folder($foldername) | 484 | function &add_folder($foldername) |
| 485 | { | 485 | { |
| 486 | $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_ADD_FOLDER); | 486 | $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_ADD_FOLDER); |
| 487 | - | 487 | + |
| 488 | if (PEAR::isError($user)) | 488 | if (PEAR::isError($user)) |
| 489 | { | 489 | { |
| 490 | return $user; | 490 | return $user; |
| 491 | - } | ||
| 492 | - | 491 | + } |
| 492 | + | ||
| 493 | DBUtil::startTransaction(); | 493 | DBUtil::startTransaction(); |
| 494 | $result = KTFolderUtil::add($this->folder, $foldername, $user); | 494 | $result = KTFolderUtil::add($this->folder, $foldername, $user); |
| 495 | - | 495 | + |
| 496 | if (PEAR::isError($result)) | 496 | if (PEAR::isError($result)) |
| 497 | { | 497 | { |
| 498 | DBUtil::rollback(); | 498 | DBUtil::rollback(); |
| @@ -500,10 +500,10 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -500,10 +500,10 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 500 | } | 500 | } |
| 501 | DBUtil::commit(); | 501 | DBUtil::commit(); |
| 502 | $folderid = $result->getId(); | 502 | $folderid = $result->getId(); |
| 503 | - | 503 | + |
| 504 | return $this->ktapi->get_folder_by_id($folderid); | 504 | return $this->ktapi->get_folder_by_id($folderid); |
| 505 | } | 505 | } |
| 506 | - | 506 | + |
| 507 | /** | 507 | /** |
| 508 | * This deletes the current folder. | 508 | * This deletes the current folder. |
| 509 | * | 509 | * |
| @@ -515,13 +515,13 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -515,13 +515,13 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 515 | if (PEAR::isError($user)) | 515 | if (PEAR::isError($user)) |
| 516 | { | 516 | { |
| 517 | return $user; | 517 | return $user; |
| 518 | - } | ||
| 519 | - | 518 | + } |
| 519 | + | ||
| 520 | if ($this->folderid == 1) | 520 | if ($this->folderid == 1) |
| 521 | { | 521 | { |
| 522 | return new PEAR_Error('Cannot delete root folder!'); | 522 | return new PEAR_Error('Cannot delete root folder!'); |
| 523 | - } | ||
| 524 | - | 523 | + } |
| 524 | + | ||
| 525 | DBUtil::startTransaction(); | 525 | DBUtil::startTransaction(); |
| 526 | $result = KTFolderUtil::delete($this->folder, $user, $reason); | 526 | $result = KTFolderUtil::delete($this->folder, $user, $reason); |
| 527 | 527 | ||
| @@ -539,13 +539,13 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -539,13 +539,13 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 539 | * @param string $newname | 539 | * @param string $newname |
| 540 | */ | 540 | */ |
| 541 | function rename($newname) | 541 | function rename($newname) |
| 542 | - { | 542 | + { |
| 543 | $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_RENAME_FOLDER); | 543 | $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_RENAME_FOLDER); |
| 544 | if (PEAR::isError($user)) | 544 | if (PEAR::isError($user)) |
| 545 | { | 545 | { |
| 546 | return $user; | 546 | return $user; |
| 547 | - } | ||
| 548 | - | 547 | + } |
| 548 | + | ||
| 549 | DBUtil::startTransaction(); | 549 | DBUtil::startTransaction(); |
| 550 | $result = KTFolderUtil::rename($this->folder, $newname, $user); | 550 | $result = KTFolderUtil::rename($this->folder, $newname, $user); |
| 551 | 551 | ||
| @@ -556,7 +556,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -556,7 +556,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 556 | } | 556 | } |
| 557 | DBUtil::commit(); | 557 | DBUtil::commit(); |
| 558 | } | 558 | } |
| 559 | - | 559 | + |
| 560 | /** | 560 | /** |
| 561 | * This moves the folder to another location. | 561 | * This moves the folder to another location. |
| 562 | * | 562 | * |
| @@ -567,12 +567,12 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -567,12 +567,12 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 567 | { | 567 | { |
| 568 | assert(!is_null($ktapi_target_folder)); | 568 | assert(!is_null($ktapi_target_folder)); |
| 569 | assert(is_a($ktapi_target_folder,'KTAPI_Folder')); | 569 | assert(is_a($ktapi_target_folder,'KTAPI_Folder')); |
| 570 | - | 570 | + |
| 571 | $user = $this->ktapi->get_user(); | 571 | $user = $this->ktapi->get_user(); |
| 572 | - | 572 | + |
| 573 | $target_folder = $ktapi_target_folder->get_folder(); | 573 | $target_folder = $ktapi_target_folder->get_folder(); |
| 574 | 574 | ||
| 575 | - $result = $this->can_user_access_object_requiring_permission($target_folder, KTAPI_PERMISSION_WRITE); | 575 | + $result = $this->can_user_access_object_requiring_permission($target_folder, KTAPI_PERMISSION_WRITE); |
| 576 | if (PEAR::isError($result)) | 576 | if (PEAR::isError($result)) |
| 577 | { | 577 | { |
| 578 | return $result; | 578 | return $result; |
| @@ -588,7 +588,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -588,7 +588,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 588 | } | 588 | } |
| 589 | DBUtil::commit(); | 589 | DBUtil::commit(); |
| 590 | } | 590 | } |
| 591 | - | 591 | + |
| 592 | /** | 592 | /** |
| 593 | * This copies a folder to another location. | 593 | * This copies a folder to another location. |
| 594 | * | 594 | * |
| @@ -599,18 +599,18 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -599,18 +599,18 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 599 | { | 599 | { |
| 600 | assert(!is_null($ktapi_target_folder)); | 600 | assert(!is_null($ktapi_target_folder)); |
| 601 | assert(is_a($ktapi_target_folder,'KTAPI_Folder')); | 601 | assert(is_a($ktapi_target_folder,'KTAPI_Folder')); |
| 602 | - | 602 | + |
| 603 | $user = $this->ktapi->get_user(); | 603 | $user = $this->ktapi->get_user(); |
| 604 | - | 604 | + |
| 605 | $target_folder = $ktapi_target_folder->get_folder(); | 605 | $target_folder = $ktapi_target_folder->get_folder(); |
| 606 | 606 | ||
| 607 | $result =$this->can_user_access_object_requiring_permission($target_folder, KTAPI_PERMISSION_WRITE); | 607 | $result =$this->can_user_access_object_requiring_permission($target_folder, KTAPI_PERMISSION_WRITE); |
| 608 | - | 608 | + |
| 609 | if (PEAR::isError($result)) | 609 | if (PEAR::isError($result)) |
| 610 | { | 610 | { |
| 611 | return $result; | 611 | return $result; |
| 612 | - } | ||
| 613 | - | 612 | + } |
| 613 | + | ||
| 614 | DBUtil::startTransaction(); | 614 | DBUtil::startTransaction(); |
| 615 | $result = KTFolderUtil::copy($this->folder, $target_folder, $user, $reason); | 615 | $result = KTFolderUtil::copy($this->folder, $target_folder, $user, $reason); |
| 616 | 616 | ||
| @@ -621,7 +621,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -621,7 +621,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 621 | } | 621 | } |
| 622 | DBUtil::commit(); | 622 | DBUtil::commit(); |
| 623 | } | 623 | } |
| 624 | - | 624 | + |
| 625 | /** | 625 | /** |
| 626 | * This returns all permissions linked to the folder. | 626 | * This returns all permissions linked to the folder. |
| 627 | * | 627 | * |
| @@ -630,7 +630,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -630,7 +630,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 630 | */ | 630 | */ |
| 631 | function get_permissions() | 631 | function get_permissions() |
| 632 | { | 632 | { |
| 633 | - return new PEAR_Error('TODO'); | 633 | + return new PEAR_Error('TODO'); |
| 634 | } | 634 | } |
| 635 | 635 | ||
| 636 | /** | 636 | /** |
| @@ -641,7 +641,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -641,7 +641,7 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 641 | */ | 641 | */ |
| 642 | function get_transaction_history() | 642 | function get_transaction_history() |
| 643 | { | 643 | { |
| 644 | - return new PEAR_Error('TODO'); | 644 | + return new PEAR_Error('TODO'); |
| 645 | } | 645 | } |
| 646 | } | 646 | } |
| 647 | 647 |
ktapi/KTAPISession.inc.php
| 1 | <? | 1 | <? |
| 2 | /** | 2 | /** |
| 3 | * $Id$ | 3 | * $Id$ |
| 4 | - * | 4 | + * |
| 5 | * The contents of this file are subject to the KnowledgeTree Public | 5 | * The contents of this file are subject to the KnowledgeTree Public |
| 6 | * License Version 1.1.2 ("License"); You may not use this file except in | 6 | * License Version 1.1.2 ("License"); You may not use this file except in |
| 7 | * compliance with the License. You may obtain a copy of the License at | 7 | * compliance with the License. You may obtain a copy of the License at |
| 8 | * http://www.knowledgetree.com/KPL | 8 | * http://www.knowledgetree.com/KPL |
| 9 | - * | 9 | + * |
| 10 | * Software distributed under the License is distributed on an "AS IS" | 10 | * Software distributed under the License is distributed on an "AS IS" |
| 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing rights and | 12 | * See the License for the specific language governing rights and |
| @@ -17,9 +17,9 @@ | @@ -17,9 +17,9 @@ | ||
| 17 | * (ii) the KnowledgeTree copyright notice | 17 | * (ii) the KnowledgeTree copyright notice |
| 18 | * in the same form as they appear in the distribution. See the License for | 18 | * in the same form as they appear in the distribution. See the License for |
| 19 | * requirements. | 19 | * requirements. |
| 20 | - * | 20 | + * |
| 21 | * The Original Code is: KnowledgeTree Open Source | 21 | * The Original Code is: KnowledgeTree Open Source |
| 22 | - * | 22 | + * |
| 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software | 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software |
| 24 | * (Pty) Ltd, trading as KnowledgeTree. | 24 | * (Pty) Ltd, trading as KnowledgeTree. |
| 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright |
| @@ -29,26 +29,26 @@ | @@ -29,26 +29,26 @@ | ||
| 29 | * | 29 | * |
| 30 | */ | 30 | */ |
| 31 | 31 | ||
| 32 | -class KTAPI_Session | 32 | +class KTAPI_Session |
| 33 | { | 33 | { |
| 34 | var $ktapi; | 34 | var $ktapi; |
| 35 | var $user = null; | 35 | var $user = null; |
| 36 | var $session = ''; | 36 | var $session = ''; |
| 37 | var $sessionid = -1; | 37 | var $sessionid = -1; |
| 38 | var $active; | 38 | var $active; |
| 39 | - | 39 | + |
| 40 | function KTAPI_Session(&$ktapi, &$user) | 40 | function KTAPI_Session(&$ktapi, &$user) |
| 41 | { | 41 | { |
| 42 | assert(!is_null($ktapi)); | 42 | assert(!is_null($ktapi)); |
| 43 | assert(is_a($ktapi,'KTAPI')); | 43 | assert(is_a($ktapi,'KTAPI')); |
| 44 | assert(!is_null($user)); | 44 | assert(!is_null($user)); |
| 45 | - assert(is_a($user,'User')); | ||
| 46 | - | 45 | + assert(is_a($user,'User')); |
| 46 | + | ||
| 47 | $this->ktapi=&$ktapi; | 47 | $this->ktapi=&$ktapi; |
| 48 | $this->user=&$user; | 48 | $this->user=&$user; |
| 49 | $this->active = false; | 49 | $this->active = false; |
| 50 | } | 50 | } |
| 51 | - | 51 | + |
| 52 | /** | 52 | /** |
| 53 | * return the session string | 53 | * return the session string |
| 54 | * | 54 | * |
| @@ -58,17 +58,17 @@ class KTAPI_Session | @@ -58,17 +58,17 @@ class KTAPI_Session | ||
| 58 | { | 58 | { |
| 59 | die('get_session() should be overloaded!'); | 59 | die('get_session() should be overloaded!'); |
| 60 | } | 60 | } |
| 61 | - | 61 | + |
| 62 | /** | 62 | /** |
| 63 | - * Return the session id | ||
| 64 | - * | 63 | + * Return the session id |
| 64 | + * | ||
| 65 | * @return int | 65 | * @return int |
| 66 | */ | 66 | */ |
| 67 | function get_sessionid() | 67 | function get_sessionid() |
| 68 | { | 68 | { |
| 69 | die('get_sessionid() should be overloaded!'); | 69 | die('get_sessionid() should be overloaded!'); |
| 70 | } | 70 | } |
| 71 | - | 71 | + |
| 72 | /** | 72 | /** |
| 73 | * Return the user | 73 | * Return the user |
| 74 | * | 74 | * |
| @@ -78,29 +78,28 @@ class KTAPI_Session | @@ -78,29 +78,28 @@ class KTAPI_Session | ||
| 78 | { | 78 | { |
| 79 | return $this->user; | 79 | return $this->user; |
| 80 | } | 80 | } |
| 81 | - | 81 | + |
| 82 | function logout() | 82 | function logout() |
| 83 | { | 83 | { |
| 84 | $this->active=false; | 84 | $this->active=false; |
| 85 | // don't need to do anything really | 85 | // don't need to do anything really |
| 86 | } | 86 | } |
| 87 | - | 87 | + |
| 88 | function is_active() | 88 | function is_active() |
| 89 | { | 89 | { |
| 90 | return $this->active; | 90 | return $this->active; |
| 91 | } | 91 | } |
| 92 | - | ||
| 93 | -} | ||
| 94 | 92 | ||
| 93 | +} | ||
| 95 | 94 | ||
| 96 | -class KTAPI_UserSession extends KTAPI_Session | 95 | +class KTAPI_UserSession extends KTAPI_Session |
| 97 | { | 96 | { |
| 98 | var $ip = null; | 97 | var $ip = null; |
| 99 | - | 98 | + |
| 100 | function KTAPI_UserSession(&$ktapi, &$user, $session, $sessionid, $ip) | 99 | function KTAPI_UserSession(&$ktapi, &$user, $session, $sessionid, $ip) |
| 101 | { | 100 | { |
| 102 | parent::KTAPI_Session($ktapi, $user); | 101 | parent::KTAPI_Session($ktapi, $user); |
| 103 | - | 102 | + |
| 104 | $this->ktapi = &$ktapi; | 103 | $this->ktapi = &$ktapi; |
| 105 | $this->user = &$user; | 104 | $this->user = &$user; |
| 106 | $this->session = $session; | 105 | $this->session = $session; |
| @@ -109,10 +108,10 @@ class KTAPI_UserSession extends KTAPI_Session | @@ -109,10 +108,10 @@ class KTAPI_UserSession extends KTAPI_Session | ||
| 109 | 108 | ||
| 110 | // TODO: get documenttransaction to not look at the session variable! | 109 | // TODO: get documenttransaction to not look at the session variable! |
| 111 | $_SESSION["userID"] = $user->getId(); | 110 | $_SESSION["userID"] = $user->getId(); |
| 112 | - $_SESSION["sessionID"] = $this->sessionid; | ||
| 113 | - $this->active = true; | 111 | + $_SESSION["sessionID"] = $this->sessionid; |
| 112 | + $this->active = true; | ||
| 114 | } | 113 | } |
| 115 | - | 114 | + |
| 116 | /** | 115 | /** |
| 117 | * This returns the session string | 116 | * This returns the session string |
| 118 | * | 117 | * |
| @@ -122,7 +121,7 @@ class KTAPI_UserSession extends KTAPI_Session | @@ -122,7 +121,7 @@ class KTAPI_UserSession extends KTAPI_Session | ||
| 122 | { | 121 | { |
| 123 | return $this->session; | 122 | return $this->session; |
| 124 | } | 123 | } |
| 125 | - | 124 | + |
| 126 | /** | 125 | /** |
| 127 | * This returns the sessionid in the database. | 126 | * This returns the sessionid in the database. |
| 128 | * | 127 | * |
| @@ -132,7 +131,7 @@ class KTAPI_UserSession extends KTAPI_Session | @@ -132,7 +131,7 @@ class KTAPI_UserSession extends KTAPI_Session | ||
| 132 | { | 131 | { |
| 133 | return $this->sessionid; | 132 | return $this->sessionid; |
| 134 | } | 133 | } |
| 135 | - | 134 | + |
| 136 | /** | 135 | /** |
| 137 | * This resolves the user's ip | 136 | * This resolves the user's ip |
| 138 | * | 137 | * |
| @@ -141,38 +140,38 @@ class KTAPI_UserSession extends KTAPI_Session | @@ -141,38 +140,38 @@ class KTAPI_UserSession extends KTAPI_Session | ||
| 141 | */ | 140 | */ |
| 142 | function resolveIP() | 141 | function resolveIP() |
| 143 | { | 142 | { |
| 144 | - if (getenv("REMOTE_ADDR")) | 143 | + if (getenv("REMOTE_ADDR")) |
| 145 | { | 144 | { |
| 146 | $ip = getenv("REMOTE_ADDR"); | 145 | $ip = getenv("REMOTE_ADDR"); |
| 147 | - } | ||
| 148 | - elseif (getenv("HTTP_X_FORWARDED_FOR")) | 146 | + } |
| 147 | + elseif (getenv("HTTP_X_FORWARDED_FOR")) | ||
| 149 | { | 148 | { |
| 150 | $forwardedip = getenv("HTTP_X_FORWARDED_FOR"); | 149 | $forwardedip = getenv("HTTP_X_FORWARDED_FOR"); |
| 151 | list($ip,$ip2,$ip3,$ip4)= split (",", $forwardedip); | 150 | list($ip,$ip2,$ip3,$ip4)= split (",", $forwardedip); |
| 152 | - } | ||
| 153 | - elseif (getenv("HTTP_CLIENT_IP")) | 151 | + } |
| 152 | + elseif (getenv("HTTP_CLIENT_IP")) | ||
| 154 | { | 153 | { |
| 155 | $ip = getenv("HTTP_CLIENT_IP"); | 154 | $ip = getenv("HTTP_CLIENT_IP"); |
| 156 | } | 155 | } |
| 157 | - | 156 | + |
| 158 | if ($ip == '') | 157 | if ($ip == '') |
| 159 | { | 158 | { |
| 160 | $ip = '127.0.0.1'; | 159 | $ip = '127.0.0.1'; |
| 161 | } | 160 | } |
| 162 | - | 161 | + |
| 163 | return $ip; | 162 | return $ip; |
| 164 | } | 163 | } |
| 165 | - | 164 | + |
| 166 | /** | 165 | /** |
| 167 | * | 166 | * |
| 168 | * @access protected | 167 | * @access protected |
| 169 | - * @static | 168 | + * @static |
| 170 | * @param User $user | 169 | * @param User $user |
| 171 | */ | 170 | */ |
| 172 | function _check_session(&$user) | 171 | function _check_session(&$user) |
| 173 | - { | 172 | + { |
| 174 | $user_id = $user->getId(); | 173 | $user_id = $user->getId(); |
| 175 | - | 174 | + |
| 176 | $sql = "SELECT count(*) >= u.max_sessions as over_limit FROM active_sessions ass INNER JOIN users u ON ass.user_id=u.id WHERE ass.user_id = $user_id"; | 175 | $sql = "SELECT count(*) >= u.max_sessions as over_limit FROM active_sessions ass INNER JOIN users u ON ass.user_id=u.id WHERE ass.user_id = $user_id"; |
| 177 | $row = DBUtil::getOneResult($sql); | 176 | $row = DBUtil::getOneResult($sql); |
| 178 | if (PEAR::isError($row)) | 177 | if (PEAR::isError($row)) |
| @@ -182,14 +181,14 @@ class KTAPI_UserSession extends KTAPI_Session | @@ -182,14 +181,14 @@ class KTAPI_UserSession extends KTAPI_Session | ||
| 182 | if (is_null($row)) | 181 | if (is_null($row)) |
| 183 | { | 182 | { |
| 184 | return new PEAR_Error('No record found for user?'); | 183 | return new PEAR_Error('No record found for user?'); |
| 185 | - } | 184 | + } |
| 186 | if ($row['over_limit'] == 1) | 185 | if ($row['over_limit'] == 1) |
| 187 | { | 186 | { |
| 188 | return new PEAR_Error('Session limit exceeded. Logout of any active sessions.'); | 187 | return new PEAR_Error('Session limit exceeded. Logout of any active sessions.'); |
| 189 | } | 188 | } |
| 190 | - | 189 | + |
| 191 | $session = session_id(); | 190 | $session = session_id(); |
| 192 | - | 191 | + |
| 193 | $sessionid = DBUtil::autoInsert('active_sessions', | 192 | $sessionid = DBUtil::autoInsert('active_sessions', |
| 194 | array( | 193 | array( |
| 195 | 'user_id' => $user_id, | 194 | 'user_id' => $user_id, |
| @@ -201,32 +200,32 @@ class KTAPI_UserSession extends KTAPI_Session | @@ -201,32 +200,32 @@ class KTAPI_UserSession extends KTAPI_Session | ||
| 201 | { | 200 | { |
| 202 | return $sessionid; | 201 | return $sessionid; |
| 203 | } | 202 | } |
| 204 | - | 203 | + |
| 205 | return array($session,$sessionid); | 204 | return array($session,$sessionid); |
| 206 | } | 205 | } |
| 207 | - | ||
| 208 | - | 206 | + |
| 207 | + | ||
| 209 | /** | 208 | /** |
| 210 | * This returns a session object based on authentication credentials. | 209 | * This returns a session object based on authentication credentials. |
| 211 | * | 210 | * |
| 212 | * @access public | 211 | * @access public |
| 213 | - * @static | 212 | + * @static |
| 214 | * @param string $username | 213 | * @param string $username |
| 215 | * @param string $password | 214 | * @param string $password |
| 216 | * @return KTAPI_Session | 215 | * @return KTAPI_Session |
| 217 | */ | 216 | */ |
| 218 | function &start_session(&$ktapi, $username, $password, $ip=null) | 217 | function &start_session(&$ktapi, $username, $password, $ip=null) |
| 219 | - { | 218 | + { |
| 220 | $this->active=false; | 219 | $this->active=false; |
| 221 | - if ( empty($username) ) | 220 | + if ( empty($username) ) |
| 222 | { | 221 | { |
| 223 | return new PEAR_Error(_kt('The username is empty.')); | 222 | return new PEAR_Error(_kt('The username is empty.')); |
| 224 | } | 223 | } |
| 225 | 224 | ||
| 226 | $user =& User::getByUsername($username); | 225 | $user =& User::getByUsername($username); |
| 227 | - if (PEAR::isError($user) || ($user === false)) | 226 | + if (PEAR::isError($user) || ($user === false)) |
| 228 | { | 227 | { |
| 229 | - return new KTAPI_Error(_kt("The user '$username' cound not be found."),$user); | 228 | + return new KTAPI_Error(_kt("The user '$username' cound not be found."),$user); |
| 230 | } | 229 | } |
| 231 | 230 | ||
| 232 | if ( empty($password) ) | 231 | if ( empty($password) ) |
| @@ -240,24 +239,24 @@ class KTAPI_UserSession extends KTAPI_Session | @@ -240,24 +239,24 @@ class KTAPI_UserSession extends KTAPI_Session | ||
| 240 | { | 239 | { |
| 241 | return new KTAPI_Error(_kt("The password is invalid."),$authenticated); | 240 | return new KTAPI_Error(_kt("The password is invalid."),$authenticated); |
| 242 | } | 241 | } |
| 243 | - | 242 | + |
| 244 | if (is_null($ip)) | 243 | if (is_null($ip)) |
| 245 | { | 244 | { |
| 246 | $ip = '127.0.0.1'; | 245 | $ip = '127.0.0.1'; |
| 247 | //$ip = KTAPI_Session::resolveIP(); | 246 | //$ip = KTAPI_Session::resolveIP(); |
| 248 | } | 247 | } |
| 249 | - | 248 | + |
| 250 | list($session,$sessionid) = KTAPI_UserSession::_check_session($user); | 249 | list($session,$sessionid) = KTAPI_UserSession::_check_session($user); |
| 251 | if (PEAR::isError($sessionid)) | 250 | if (PEAR::isError($sessionid)) |
| 252 | { | 251 | { |
| 253 | return $sessionid; | 252 | return $sessionid; |
| 254 | } | 253 | } |
| 255 | - | ||
| 256 | - $session = &new KTAPI_UserSession($ktapi, $user, $session, $sessionid, $ip); | ||
| 257 | - | 254 | + |
| 255 | + $session = &new KTAPI_UserSession($ktapi, $user, $session, $sessionid, $ip); | ||
| 256 | + | ||
| 258 | return $session; | 257 | return $session; |
| 259 | - } | ||
| 260 | - | 258 | + } |
| 259 | + | ||
| 261 | /** | 260 | /** |
| 262 | * This returns an active session. | 261 | * This returns an active session. |
| 263 | * | 262 | * |
| @@ -267,42 +266,42 @@ class KTAPI_UserSession extends KTAPI_Session | @@ -267,42 +266,42 @@ class KTAPI_UserSession extends KTAPI_Session | ||
| 267 | * @return KTAPI_Session | 266 | * @return KTAPI_Session |
| 268 | */ | 267 | */ |
| 269 | function &get_active_session(&$ktapi, $session, $ip) | 268 | function &get_active_session(&$ktapi, $session, $ip) |
| 270 | - { | 269 | + { |
| 271 | $sql = "SELECT id, user_id FROM active_sessions WHERE session_id='$session'"; | 270 | $sql = "SELECT id, user_id FROM active_sessions WHERE session_id='$session'"; |
| 272 | if (!empty($ip)) | 271 | if (!empty($ip)) |
| 273 | { | 272 | { |
| 274 | $sql .= " AND ip='$ip'"; | 273 | $sql .= " AND ip='$ip'"; |
| 275 | - } | ||
| 276 | - | 274 | + } |
| 275 | + | ||
| 277 | $row = DBUtil::getOneResult($sql); | 276 | $row = DBUtil::getOneResult($sql); |
| 278 | if (is_null($row) || PEAR::isError($row)) | 277 | if (is_null($row) || PEAR::isError($row)) |
| 279 | { | 278 | { |
| 280 | return new KTAPI_Error(KTAPI_ERROR_SESSION_INVALID, $row); | 279 | return new KTAPI_Error(KTAPI_ERROR_SESSION_INVALID, $row); |
| 281 | } | 280 | } |
| 282 | - | 281 | + |
| 283 | $sessionid = $row['id']; | 282 | $sessionid = $row['id']; |
| 284 | $userid = $row['user_id']; | 283 | $userid = $row['user_id']; |
| 285 | - | 284 | + |
| 286 | $user = &User::get($userid); | 285 | $user = &User::get($userid); |
| 287 | if (is_null($user) || PEAR::isError($user)) | 286 | if (is_null($user) || PEAR::isError($user)) |
| 288 | { | 287 | { |
| 289 | return new KTAPI_Error(KTAPI_ERROR_USER_INVALID, $user); | 288 | return new KTAPI_Error(KTAPI_ERROR_USER_INVALID, $user); |
| 290 | } | 289 | } |
| 291 | - | ||
| 292 | 290 | ||
| 293 | - | 291 | + |
| 292 | + | ||
| 294 | $now=date('Y-m-d H:i:s'); | 293 | $now=date('Y-m-d H:i:s'); |
| 295 | $sql = "UPDATE active_sessions SET last_used='$now' WHERE id=$sessionid"; | 294 | $sql = "UPDATE active_sessions SET last_used='$now' WHERE id=$sessionid"; |
| 296 | DBUtil::runQuery($sql); | 295 | DBUtil::runQuery($sql); |
| 297 | - | ||
| 298 | - | 296 | + |
| 297 | + | ||
| 299 | if ($user->isAnonymous()) | 298 | if ($user->isAnonymous()) |
| 300 | - $session = &new KTAPI_AnonymousSession($ktapi, $user, $session, $sessionid, $ip); | 299 | + $session = &new KTAPI_AnonymousSession($ktapi, $user, $session, $sessionid, $ip); |
| 301 | else | 300 | else |
| 302 | - $session = &new KTAPI_UserSession($ktapi, $user, $session, $sessionid, $ip); | 301 | + $session = &new KTAPI_UserSession($ktapi, $user, $session, $sessionid, $ip); |
| 303 | return $session; | 302 | return $session; |
| 304 | } | 303 | } |
| 305 | - | 304 | + |
| 306 | /** | 305 | /** |
| 307 | * This closes the current session. | 306 | * This closes the current session. |
| 308 | * | 307 | * |
| @@ -315,19 +314,19 @@ class KTAPI_UserSession extends KTAPI_Session | @@ -315,19 +314,19 @@ class KTAPI_UserSession extends KTAPI_Session | ||
| 315 | { | 314 | { |
| 316 | return $result; | 315 | return $result; |
| 317 | } | 316 | } |
| 318 | - | 317 | + |
| 319 | $this->user = null; | 318 | $this->user = null; |
| 320 | $this->session = ''; | 319 | $this->session = ''; |
| 321 | $this->sessionid = -1; | 320 | $this->sessionid = -1; |
| 322 | $this->active=false; | 321 | $this->active=false; |
| 323 | } | 322 | } |
| 324 | - | 323 | + |
| 325 | } | 324 | } |
| 326 | 325 | ||
| 327 | -class KTAPI_AnonymousSession extends KTAPI_UserSession | 326 | +class KTAPI_AnonymousSession extends KTAPI_UserSession |
| 328 | { | 327 | { |
| 329 | function &start_session(&$ktapi, $ip=null) | 328 | function &start_session(&$ktapi, $ip=null) |
| 330 | - { | 329 | + { |
| 331 | $user =& User::get(-2); | 330 | $user =& User::get(-2); |
| 332 | if (is_null($user) || PEAR::isError($user) || ($user === false) || !$user->isAnonymous()) | 331 | if (is_null($user) || PEAR::isError($user) || ($user === false) || !$user->isAnonymous()) |
| 333 | { | 332 | { |
| @@ -355,16 +354,14 @@ class KTAPI_AnonymousSession extends KTAPI_UserSession | @@ -355,16 +354,14 @@ class KTAPI_AnonymousSession extends KTAPI_UserSession | ||
| 355 | { | 354 | { |
| 356 | return $sessionid; | 355 | return $sessionid; |
| 357 | } | 356 | } |
| 358 | - | ||
| 359 | - $session = &new KTAPI_AnonymousSession($ktapi, $user, $session, $sessionid, $ip); | ||
| 360 | - | 357 | + |
| 358 | + $session = &new KTAPI_AnonymousSession($ktapi, $user, $session, $sessionid, $ip); | ||
| 359 | + | ||
| 361 | return $session; | 360 | return $session; |
| 362 | } | 361 | } |
| 363 | } | 362 | } |
| 364 | 363 | ||
| 365 | - | ||
| 366 | - | ||
| 367 | -class KTAPI_SystemSession extends KTAPI_Session | 364 | +class KTAPI_SystemSession extends KTAPI_Session |
| 368 | { | 365 | { |
| 369 | function KTAPI_SystemSession(&$ktapi, &$user) | 366 | function KTAPI_SystemSession(&$ktapi, &$user) |
| 370 | { | 367 | { |
ktapi/ktapi.inc.php
| 1 | <? | 1 | <? |
| 2 | /** | 2 | /** |
| 3 | * $Id$ | 3 | * $Id$ |
| 4 | - * | 4 | + * |
| 5 | * Implements a cleaner wrapper API for KnowledgeTree. | 5 | * Implements a cleaner wrapper API for KnowledgeTree. |
| 6 | * | 6 | * |
| 7 | * The contents of this file are subject to the KnowledgeTree Public | 7 | * The contents of this file are subject to the KnowledgeTree Public |
| 8 | * License Version 1.1.2 ("License"); You may not use this file except in | 8 | * License Version 1.1.2 ("License"); You may not use this file except in |
| 9 | * compliance with the License. You may obtain a copy of the License at | 9 | * compliance with the License. You may obtain a copy of the License at |
| 10 | * http://www.knowledgetree.com/KPL | 10 | * http://www.knowledgetree.com/KPL |
| 11 | - * | 11 | + * |
| 12 | * Software distributed under the License is distributed on an "AS IS" | 12 | * Software distributed under the License is distributed on an "AS IS" |
| 13 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | 13 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing rights and | 14 | * See the License for the specific language governing rights and |
| @@ -19,9 +19,9 @@ | @@ -19,9 +19,9 @@ | ||
| 19 | * (ii) the KnowledgeTree copyright notice | 19 | * (ii) the KnowledgeTree copyright notice |
| 20 | * in the same form as they appear in the distribution. See the License for | 20 | * in the same form as they appear in the distribution. See the License for |
| 21 | * requirements. | 21 | * requirements. |
| 22 | - * | 22 | + * |
| 23 | * The Original Code is: KnowledgeTree Open Source | 23 | * The Original Code is: KnowledgeTree Open Source |
| 24 | - * | 24 | + * |
| 25 | * The Initial Developer of the Original Code is The Jam Warehouse Software | 25 | * The Initial Developer of the Original Code is The Jam Warehouse Software |
| 26 | * (Pty) Ltd, trading as KnowledgeTree. | 26 | * (Pty) Ltd, trading as KnowledgeTree. |
| 27 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | 27 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright |
| @@ -42,7 +42,7 @@ require_once(KTAPI_DIR .'/KTAPIConstants.inc.php'); | @@ -42,7 +42,7 @@ require_once(KTAPI_DIR .'/KTAPIConstants.inc.php'); | ||
| 42 | require_once(KTAPI_DIR .'/KTAPISession.inc.php'); | 42 | require_once(KTAPI_DIR .'/KTAPISession.inc.php'); |
| 43 | require_once(KTAPI_DIR .'/KTAPIFolder.inc.php'); | 43 | require_once(KTAPI_DIR .'/KTAPIFolder.inc.php'); |
| 44 | require_once(KTAPI_DIR .'/KTAPIDocument.inc.php'); | 44 | require_once(KTAPI_DIR .'/KTAPIDocument.inc.php'); |
| 45 | - | 45 | + |
| 46 | class KTAPI_FolderItem | 46 | class KTAPI_FolderItem |
| 47 | { | 47 | { |
| 48 | /** | 48 | /** |
| @@ -51,10 +51,10 @@ class KTAPI_FolderItem | @@ -51,10 +51,10 @@ class KTAPI_FolderItem | ||
| 51 | * @access protected | 51 | * @access protected |
| 52 | * @var KTAPI | 52 | * @var KTAPI |
| 53 | */ | 53 | */ |
| 54 | - var $ktapi; | ||
| 55 | - | 54 | + var $ktapi; |
| 55 | + | ||
| 56 | function &can_user_access_object_requiring_permission(&$object, $permission) | 56 | function &can_user_access_object_requiring_permission(&$object, $permission) |
| 57 | - { | 57 | + { |
| 58 | return $this->ktapi->can_user_access_object_requiring_permission($object, $permission); | 58 | return $this->ktapi->can_user_access_object_requiring_permission($object, $permission); |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| @@ -67,7 +67,7 @@ class KTAPI_Error extends PEAR_Error | @@ -67,7 +67,7 @@ class KTAPI_Error extends PEAR_Error | ||
| 67 | { | 67 | { |
| 68 | parent::PEAR_Error($msg . ' - ' . $obj->getMessage()); | 68 | parent::PEAR_Error($msg . ' - ' . $obj->getMessage()); |
| 69 | } | 69 | } |
| 70 | - else | 70 | + else |
| 71 | { | 71 | { |
| 72 | parent::PEAR_Error($msg); | 72 | parent::PEAR_Error($msg); |
| 73 | } | 73 | } |
| @@ -83,18 +83,18 @@ class KTAPI | @@ -83,18 +83,18 @@ class KTAPI | ||
| 83 | * @var KTAPI_Session | 83 | * @var KTAPI_Session |
| 84 | */ | 84 | */ |
| 85 | var $session = null; | 85 | var $session = null; |
| 86 | - | 86 | + |
| 87 | /** | 87 | /** |
| 88 | * This returns the current session. | 88 | * This returns the current session. |
| 89 | * | 89 | * |
| 90 | * @access public | 90 | * @access public |
| 91 | * @return KTAPI_Session | 91 | * @return KTAPI_Session |
| 92 | - */ | 92 | + */ |
| 93 | function &get_session() | 93 | function &get_session() |
| 94 | { | 94 | { |
| 95 | return $this->session; | 95 | return $this->session; |
| 96 | } | 96 | } |
| 97 | - | 97 | + |
| 98 | /** | 98 | /** |
| 99 | * This returns the session user. | 99 | * This returns the session user. |
| 100 | * | 100 | * |
| @@ -102,22 +102,22 @@ class KTAPI | @@ -102,22 +102,22 @@ class KTAPI | ||
| 102 | * @return User | 102 | * @return User |
| 103 | */ | 103 | */ |
| 104 | function & get_user() | 104 | function & get_user() |
| 105 | - { | 105 | + { |
| 106 | $ktapi_session = $this->get_session(); | 106 | $ktapi_session = $this->get_session(); |
| 107 | if (is_null($ktapi_session) || PEAR::isError($ktapi_session)) | 107 | if (is_null($ktapi_session) || PEAR::isError($ktapi_session)) |
| 108 | { | 108 | { |
| 109 | return new PEAR_Error(KTAPI_ERROR_SESSION_INVALID); | 109 | return new PEAR_Error(KTAPI_ERROR_SESSION_INVALID); |
| 110 | } | 110 | } |
| 111 | - | 111 | + |
| 112 | $user = $ktapi_session->get_user(); | 112 | $user = $ktapi_session->get_user(); |
| 113 | if (is_null($user) || PEAR::isError($user)) | 113 | if (is_null($user) || PEAR::isError($user)) |
| 114 | { | 114 | { |
| 115 | return new PEAR_Error(KTAPI_ERROR_USER_INVALID); | 115 | return new PEAR_Error(KTAPI_ERROR_USER_INVALID); |
| 116 | - } | ||
| 117 | - | 116 | + } |
| 117 | + | ||
| 118 | return $user; | 118 | return $user; |
| 119 | } | 119 | } |
| 120 | - | 120 | + |
| 121 | /** | 121 | /** |
| 122 | * This returns a permission. | 122 | * This returns a permission. |
| 123 | * | 123 | * |
| @@ -127,16 +127,16 @@ class KTAPI | @@ -127,16 +127,16 @@ class KTAPI | ||
| 127 | * @return KTPermission | 127 | * @return KTPermission |
| 128 | */ | 128 | */ |
| 129 | function &get_permission($permission) | 129 | function &get_permission($permission) |
| 130 | - { | 130 | + { |
| 131 | $permission = & KTPermission::getByName($permission); | 131 | $permission = & KTPermission::getByName($permission); |
| 132 | if (is_null($permission) || PEAR::isError($permission)) | 132 | if (is_null($permission) || PEAR::isError($permission)) |
| 133 | { | 133 | { |
| 134 | return new PEAR_Error(KTAPI_ERROR_PERMISSION_INVALID); | 134 | return new PEAR_Error(KTAPI_ERROR_PERMISSION_INVALID); |
| 135 | } | 135 | } |
| 136 | - | ||
| 137 | - return $permission; | 136 | + |
| 137 | + return $permission; | ||
| 138 | } | 138 | } |
| 139 | - | 139 | + |
| 140 | /** | 140 | /** |
| 141 | * This checks if a user can access an object with a certain permission. | 141 | * This checks if a user can access an object with a certain permission. |
| 142 | * | 142 | * |
| @@ -148,34 +148,34 @@ class KTAPI | @@ -148,34 +148,34 @@ class KTAPI | ||
| 148 | function can_user_access_object_requiring_permission(&$object, $permission) | 148 | function can_user_access_object_requiring_permission(&$object, $permission) |
| 149 | { | 149 | { |
| 150 | assert(!is_null($object)); | 150 | assert(!is_null($object)); |
| 151 | - assert(is_a($object,'DocumentProxy') || is_a($object,'FolderProxy') || is_a($object,'Document') || is_a($object,'Folder')); | ||
| 152 | - | 151 | + assert(is_a($object,'DocumentProxy') || is_a($object,'FolderProxy') || is_a($object,'Document') || is_a($object,'Folder')); |
| 152 | + | ||
| 153 | $permission = &KTAPI::get_permission($permission); | 153 | $permission = &KTAPI::get_permission($permission); |
| 154 | if (is_null($permission) || PEAR::isError($permission)) | 154 | if (is_null($permission) || PEAR::isError($permission)) |
| 155 | { | 155 | { |
| 156 | return $permission; | 156 | return $permission; |
| 157 | } | 157 | } |
| 158 | - | 158 | + |
| 159 | $user = &KTAPI::get_user(); | 159 | $user = &KTAPI::get_user(); |
| 160 | if (is_null($user) || PEAR::isError($user)) | 160 | if (is_null($user) || PEAR::isError($user)) |
| 161 | { | 161 | { |
| 162 | return $user; | 162 | return $user; |
| 163 | - } | 163 | + } |
| 164 | 164 | ||
| 165 | - if (!KTPermissionUtil::userHasPermissionOnItem($user, $permission, $object)) | 165 | + if (!KTPermissionUtil::userHasPermissionOnItem($user, $permission, $object)) |
| 166 | { | 166 | { |
| 167 | return new PEAR_Error(KTAPI_ERROR_INSUFFICIENT_PERMISSIONS); | 167 | return new PEAR_Error(KTAPI_ERROR_INSUFFICIENT_PERMISSIONS); |
| 168 | } | 168 | } |
| 169 | - | ||
| 170 | - return $user; | 169 | + |
| 170 | + return $user; | ||
| 171 | } | 171 | } |
| 172 | - | 172 | + |
| 173 | /** | 173 | /** |
| 174 | * This returns a session object based on a session string. | 174 | * This returns a session object based on a session string. |
| 175 | * | 175 | * |
| 176 | * @access public | 176 | * @access public |
| 177 | * @param string $session | 177 | * @param string $session |
| 178 | - * @return KTAPI_Session | 178 | + * @return KTAPI_Session |
| 179 | */ | 179 | */ |
| 180 | function & get_active_session($session, $ip=null) | 180 | function & get_active_session($session, $ip=null) |
| 181 | { | 181 | { |
| @@ -183,33 +183,33 @@ class KTAPI | @@ -183,33 +183,33 @@ class KTAPI | ||
| 183 | { | 183 | { |
| 184 | return new PEAR_Error('A session is currently active.'); | 184 | return new PEAR_Error('A session is currently active.'); |
| 185 | } | 185 | } |
| 186 | - | 186 | + |
| 187 | $session = &KTAPI_UserSession::get_active_session($this, $session, $ip); | 187 | $session = &KTAPI_UserSession::get_active_session($this, $session, $ip); |
| 188 | - | 188 | + |
| 189 | if (is_null($session) || PEAR::isError($session)) | 189 | if (is_null($session) || PEAR::isError($session)) |
| 190 | { | 190 | { |
| 191 | return new PEAR_Error('Session is invalid'); | 191 | return new PEAR_Error('Session is invalid'); |
| 192 | } | 192 | } |
| 193 | - | 193 | + |
| 194 | $this->session = &$session; | 194 | $this->session = &$session; |
| 195 | return $session; | 195 | return $session; |
| 196 | } | 196 | } |
| 197 | - | 197 | + |
| 198 | /** | 198 | /** |
| 199 | * This returns a session object based on authentication credentials. | 199 | * This returns a session object based on authentication credentials. |
| 200 | * | 200 | * |
| 201 | * @access public | 201 | * @access public |
| 202 | * @param string $username | 202 | * @param string $username |
| 203 | * @param string $password | 203 | * @param string $password |
| 204 | - * @return KTAPI_Session | 204 | + * @return KTAPI_Session |
| 205 | */ | 205 | */ |
| 206 | function & start_session($username, $password, $ip=null) | 206 | function & start_session($username, $password, $ip=null) |
| 207 | - { | 207 | + { |
| 208 | if (!is_null($this->session)) | 208 | if (!is_null($this->session)) |
| 209 | { | 209 | { |
| 210 | return new PEAR_Error('A session is currently active.'); | 210 | return new PEAR_Error('A session is currently active.'); |
| 211 | } | 211 | } |
| 212 | - | 212 | + |
| 213 | $session = &KTAPI_UserSession::start_session($this, $username, $password, $ip); | 213 | $session = &KTAPI_UserSession::start_session($this, $username, $password, $ip); |
| 214 | if (is_null($session)) | 214 | if (is_null($session)) |
| 215 | { | 215 | { |
| @@ -220,23 +220,23 @@ class KTAPI | @@ -220,23 +220,23 @@ class KTAPI | ||
| 220 | return new PEAR_Error('Session is invalid. ' . $session->getMessage()); | 220 | return new PEAR_Error('Session is invalid. ' . $session->getMessage()); |
| 221 | } | 221 | } |
| 222 | $this->session = &$session; | 222 | $this->session = &$session; |
| 223 | - | 223 | + |
| 224 | return $session; | 224 | return $session; |
| 225 | } | 225 | } |
| 226 | - | ||
| 227 | - | 226 | + |
| 227 | + | ||
| 228 | function & start_system_session() | 228 | function & start_system_session() |
| 229 | { | 229 | { |
| 230 | $user = User::get(1); | 230 | $user = User::get(1); |
| 231 | - | 231 | + |
| 232 | $session = & new KTAPI_SystemSession($this, $user); | 232 | $session = & new KTAPI_SystemSession($this, $user); |
| 233 | $this->session = &$session; | 233 | $this->session = &$session; |
| 234 | - | 234 | + |
| 235 | return $session; | 235 | return $session; |
| 236 | } | 236 | } |
| 237 | - | ||
| 238 | - | ||
| 239 | - | 237 | + |
| 238 | + | ||
| 239 | + | ||
| 240 | /** | 240 | /** |
| 241 | * Starts an anonymous session. | 241 | * Starts an anonymous session. |
| 242 | * | 242 | * |
| @@ -249,7 +249,7 @@ class KTAPI | @@ -249,7 +249,7 @@ class KTAPI | ||
| 249 | { | 249 | { |
| 250 | return new PEAR_Error('A session is currently active.'); | 250 | return new PEAR_Error('A session is currently active.'); |
| 251 | } | 251 | } |
| 252 | - | 252 | + |
| 253 | $session = &KTAPI_AnonymousSession::start_session($this, $ip); | 253 | $session = &KTAPI_AnonymousSession::start_session($this, $ip); |
| 254 | if (is_null($session)) | 254 | if (is_null($session)) |
| 255 | { | 255 | { |
| @@ -260,11 +260,11 @@ class KTAPI | @@ -260,11 +260,11 @@ class KTAPI | ||
| 260 | return new PEAR_Error('Session is invalid. ' . $session->getMessage()); | 260 | return new PEAR_Error('Session is invalid. ' . $session->getMessage()); |
| 261 | } | 261 | } |
| 262 | $this->session = &$session; | 262 | $this->session = &$session; |
| 263 | - | 263 | + |
| 264 | return $session; | 264 | return $session; |
| 265 | } | 265 | } |
| 266 | - | ||
| 267 | - | 266 | + |
| 267 | + | ||
| 268 | /** | 268 | /** |
| 269 | * Obtains the root folder. | 269 | * Obtains the root folder. |
| 270 | * | 270 | * |
| @@ -275,7 +275,7 @@ class KTAPI | @@ -275,7 +275,7 @@ class KTAPI | ||
| 275 | { | 275 | { |
| 276 | return $this->get_folder_by_id(1); | 276 | return $this->get_folder_by_id(1); |
| 277 | } | 277 | } |
| 278 | - | 278 | + |
| 279 | /** | 279 | /** |
| 280 | * Obtains the folder using a folder id. | 280 | * Obtains the folder using a folder id. |
| 281 | * | 281 | * |
| @@ -287,12 +287,12 @@ class KTAPI | @@ -287,12 +287,12 @@ class KTAPI | ||
| 287 | { | 287 | { |
| 288 | if (is_null($this->session)) | 288 | if (is_null($this->session)) |
| 289 | { | 289 | { |
| 290 | - return new PEAR_Error('A session is not active'); | 290 | + return new PEAR_Error('A session is not active'); |
| 291 | } | 291 | } |
| 292 | - | 292 | + |
| 293 | return KTAPI_Folder::get($this, $folderid); | 293 | return KTAPI_Folder::get($this, $folderid); |
| 294 | } | 294 | } |
| 295 | - | 295 | + |
| 296 | /** | 296 | /** |
| 297 | * This returns a refererence to a document based on document id. | 297 | * This returns a refererence to a document based on document id. |
| 298 | * | 298 | * |
| @@ -301,10 +301,10 @@ class KTAPI | @@ -301,10 +301,10 @@ class KTAPI | ||
| 301 | * @return KTAPI_Document | 301 | * @return KTAPI_Document |
| 302 | */ | 302 | */ |
| 303 | function &get_document_by_id($documentid) | 303 | function &get_document_by_id($documentid) |
| 304 | - { | 304 | + { |
| 305 | return KTAPI_Document::get($this, $documentid); | 305 | return KTAPI_Document::get($this, $documentid); |
| 306 | } | 306 | } |
| 307 | - | 307 | + |
| 308 | /** | 308 | /** |
| 309 | * This returns a document type id based on the name. | 309 | * This returns a document type id based on the name. |
| 310 | * | 310 | * |
| @@ -324,7 +324,19 @@ class KTAPI | @@ -324,7 +324,19 @@ class KTAPI | ||
| 324 | list($documenttypeid) = $row['id']; | 324 | list($documenttypeid) = $row['id']; |
| 325 | return $documenttypeid; | 325 | return $documenttypeid; |
| 326 | } | 326 | } |
| 327 | - | 327 | + |
| 328 | + function get_link_type_id($linktype) | ||
| 329 | + { | ||
| 330 | + $sql = "SELECT id FROM document_link_types WHERE name='$linktype'"; | ||
| 331 | + $row = DBUtil::getOneResult($sql); | ||
| 332 | + if (is_null($row) || PEAR::isError($row)) | ||
| 333 | + { | ||
| 334 | + return new PEAR_Error(KTAPI_ERROR_DOCUMENT_LINK_TYPE_INVALID); | ||
| 335 | + } | ||
| 336 | + list($typeid) = $row['id']; | ||
| 337 | + return $typeid; | ||
| 338 | + } | ||
| 339 | + | ||
| 328 | /** | 340 | /** |
| 329 | * Returns an array of document types. | 341 | * Returns an array of document types. |
| 330 | * | 342 | * |
| @@ -340,16 +352,122 @@ class KTAPI | @@ -340,16 +352,122 @@ class KTAPI | ||
| 340 | { | 352 | { |
| 341 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $rows); | 353 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $rows); |
| 342 | } | 354 | } |
| 343 | - | 355 | + |
| 344 | $result = array(); | 356 | $result = array(); |
| 345 | foreach($rows as $row) | 357 | foreach($rows as $row) |
| 346 | { | 358 | { |
| 347 | $result[] = $row['name']; | 359 | $result[] = $row['name']; |
| 348 | } | 360 | } |
| 349 | 361 | ||
| 350 | - return $result; | 362 | + return $result; |
| 363 | + } | ||
| 364 | + | ||
| 365 | + function get_document_link_types() | ||
| 366 | + { | ||
| 367 | + $sql = "SELECT name FROM document_link_types order by name"; | ||
| 368 | + $rows = DBUtil::getResultArray($sql); | ||
| 369 | + if (is_null($rows) || PEAR::isError($rows)) | ||
| 370 | + { | ||
| 371 | + return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $rows); | ||
| 372 | + } | ||
| 373 | + | ||
| 374 | + $result = array(); | ||
| 375 | + foreach($rows as $row) | ||
| 376 | + { | ||
| 377 | + $result[] = $row['name']; | ||
| 378 | + } | ||
| 379 | + | ||
| 380 | + return $result; | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | + function get_document_type_metadata($document_type='Default') | ||
| 384 | + { | ||
| 385 | + // now get document type specifc ids | ||
| 386 | + $typeid =$this->get_documenttypeid($document_type); | ||
| 387 | + if (PEAR::isError($typeid)) | ||
| 388 | + { | ||
| 389 | + $response['message'] = $typeid->getMessage(); | ||
| 390 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_metadata_response", $response); | ||
| 391 | + } | ||
| 392 | + | ||
| 393 | + $doctype_ids = KTFieldset::getForDocumentType($typeid, array('ids' => false)); | ||
| 394 | + if (PEAR::isError($doctype_ids)) | ||
| 395 | + { | ||
| 396 | + $response['message'] = $generic_ids->getMessage(); | ||
| 397 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_metadata_response", $response); | ||
| 398 | + } | ||
| 399 | + | ||
| 400 | + // first get generic ids | ||
| 401 | + $generic_ids = KTFieldset::getGenericFieldsets(array('ids' => false)); | ||
| 402 | + if (PEAR::isError($generic_ids)) | ||
| 403 | + { | ||
| 404 | + $response['message'] = $generic_ids->getMessage(); | ||
| 405 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_metadata_response", $response); | ||
| 406 | + } | ||
| 407 | + | ||
| 408 | + // lets merge the results | ||
| 409 | + $fieldsets = kt_array_merge($generic_ids, $doctype_ids); | ||
| 410 | + | ||
| 411 | + $results = array(); | ||
| 412 | + | ||
| 413 | + foreach ($fieldsets as $fieldset) | ||
| 414 | + { | ||
| 415 | + if ($fieldset->getIsConditional()) { /* this is not implemented...*/ continue; } | ||
| 416 | + | ||
| 417 | + $fields = $fieldset->getFields(); | ||
| 418 | + $result = array( | ||
| 419 | + 'fieldset' => $fieldset->getName(), | ||
| 420 | + 'description' => $fieldset->getDescription() | ||
| 421 | + ); | ||
| 422 | + | ||
| 423 | + $fieldsresult = array(); | ||
| 424 | + | ||
| 425 | + foreach ($fields as $field) | ||
| 426 | + { | ||
| 427 | + $value = 'n/a'; | ||
| 428 | + | ||
| 429 | + | ||
| 430 | + $controltype = 'string'; | ||
| 431 | + if ($field->getHasLookup()) | ||
| 432 | + { | ||
| 433 | + $controltype = 'lookup'; | ||
| 434 | + if ($field->getHasLookupTree()) | ||
| 435 | + { | ||
| 436 | + $controltype = 'tree'; | ||
| 437 | + } | ||
| 438 | + } | ||
| 439 | + | ||
| 440 | + switch ($controltype) | ||
| 441 | + { | ||
| 442 | + case 'lookup': | ||
| 443 | + $selection = KTAPI::get_metadata_lookup($field->getId()); | ||
| 444 | + break; | ||
| 445 | + case 'tree': | ||
| 446 | + $selection = KTAPI::get_metadata_tree($field->getId()); | ||
| 447 | + break; | ||
| 448 | + default: | ||
| 449 | + $selection= array(); | ||
| 450 | + } | ||
| 451 | + | ||
| 452 | + | ||
| 453 | + $fieldsresult[] = array( | ||
| 454 | + 'name' => $field->getName(), | ||
| 455 | + 'required' => $field->getIsMandatory(), | ||
| 456 | + 'value' => $value, | ||
| 457 | + 'description' => $field->getDescription(), | ||
| 458 | + 'control_type' => $controltype, | ||
| 459 | + 'selection' => $selection | ||
| 460 | + ); | ||
| 461 | + } | ||
| 462 | + $result['fields'] = $fieldsresult; | ||
| 463 | + $results [] = $result; | ||
| 464 | + } | ||
| 465 | + | ||
| 466 | + return $results; | ||
| 351 | } | 467 | } |
| 352 | - | 468 | + |
| 469 | + | ||
| 470 | + | ||
| 353 | /** | 471 | /** |
| 354 | * Returns an array of username/name combinations. | 472 | * Returns an array of username/name combinations. |
| 355 | * | 473 | * |
| @@ -366,8 +484,8 @@ class KTAPI | @@ -366,8 +484,8 @@ class KTAPI | ||
| 366 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $rows); | 484 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $rows); |
| 367 | } | 485 | } |
| 368 | return $rows; | 486 | return $rows; |
| 369 | - } | ||
| 370 | - | 487 | + } |
| 488 | + | ||
| 371 | /** | 489 | /** |
| 372 | * This returns an array for a lookup. | 490 | * This returns an array for a lookup. |
| 373 | * | 491 | * |
| @@ -388,10 +506,10 @@ class KTAPI | @@ -388,10 +506,10 @@ class KTAPI | ||
| 388 | foreach($rows as $row) | 506 | foreach($rows as $row) |
| 389 | { | 507 | { |
| 390 | $results[] = $row['name']; | 508 | $results[] = $row['name']; |
| 391 | - } | 509 | + } |
| 392 | return $results; | 510 | return $results; |
| 393 | } | 511 | } |
| 394 | - | 512 | + |
| 395 | /** | 513 | /** |
| 396 | * This returns a metadata tree. | 514 | * This returns a metadata tree. |
| 397 | * | 515 | * |
| @@ -421,7 +539,7 @@ class KTAPI | @@ -421,7 +539,7 @@ class KTAPI | ||
| 421 | } | 539 | } |
| 422 | return $results;*/ | 540 | return $results;*/ |
| 423 | } | 541 | } |
| 424 | - | 542 | + |
| 425 | /** | 543 | /** |
| 426 | * This returns a metadata tree. | 544 | * This returns a metadata tree. |
| 427 | * | 545 | * |
| @@ -432,13 +550,13 @@ class KTAPI | @@ -432,13 +550,13 @@ class KTAPI | ||
| 432 | */ | 550 | */ |
| 433 | function get_metadata_tree($fieldid) | 551 | function get_metadata_tree($fieldid) |
| 434 | { | 552 | { |
| 435 | - return KTAPI::_load_metadata_tree($fieldid); | ||
| 436 | - } | ||
| 437 | - | 553 | + return KTAPI::_load_metadata_tree($fieldid); |
| 554 | + } | ||
| 555 | + | ||
| 438 | /** | 556 | /** |
| 439 | * Returns a list of workflows that are active. | 557 | * Returns a list of workflows that are active. |
| 440 | * | 558 | * |
| 441 | - * @static | 559 | + * @static |
| 442 | * @access public | 560 | * @access public |
| 443 | * @return array | 561 | * @return array |
| 444 | */ | 562 | */ |
| @@ -457,7 +575,7 @@ class KTAPI | @@ -457,7 +575,7 @@ class KTAPI | ||
| 457 | } | 575 | } |
| 458 | return $results; | 576 | return $results; |
| 459 | } | 577 | } |
| 460 | - | 578 | + |
| 461 | } | 579 | } |
| 462 | 580 | ||
| 463 | ?> | 581 | ?> |
| 464 | \ No newline at end of file | 582 | \ No newline at end of file |